Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp293698iol; Thu, 9 Jun 2022 04:08:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybVozHSB+JEtlssf95jrDt1k9w4TibdPAPLq7g+dQccSU2UesBMKvP6Zja9K6jIMzkCNr4 X-Received: by 2002:a17:902:f70a:b0:153:88c7:774 with SMTP id h10-20020a170902f70a00b0015388c70774mr38780272plo.166.1654772881459; Thu, 09 Jun 2022 04:08:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654772881; cv=none; d=google.com; s=arc-20160816; b=UAYyR9VECz01re6d5SoHfOqHY/Wag3TWkOOC2SO9qP9ulmgn6pLL+mzoL1Uv6cJ9le EQebYu/d7AzV/7R281xlqXPZehfEYYcyMPIFGi5Vx/wvyqkzE2jr/+rvU8pi+mn6QnjG 9enjLyesCAP3tmPxpRfl6UrO3md6xn+Ax7lwQJbODQrNOW4fZprdVi+5GLi3ADq761w1 0DFvN/G1fhkP6KVBgwKfDLnbPQlIuz7CBkDiOJAi4Jwzilm/j0nathKzEReMEIt84Rer bfpJ/AW4W9yaga2Ya0YIAypkM0Q5XBja9RDp6EY0nBPf9HcBAl71wHB+Q6qhrmfAeh8O hBHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=10YNNhN2+79+ZY8FhgRppNiubR6e41g6BMR4GQKykC0=; b=o+4LREqhJ6DikHPT0nP2bYpjxcNpXuE/xazMrFgxpnf0+N+wx7/ZSF/acxBYv/okGB YzzO78+Pis5NnuAppHHLAwyVymclfF7q497IVBNVX+xwvIHXYz6WziWMqneMxU4RKNES whAMYoz0i3sycdJaRQyCA3E+sNG5maUoUL3lCJa/Po/YeHMD9lplmldLdPpPjZTRqrwd suRWHSKGoT3gKFj4IYSNx3k50FpGRs9gTl6kFGpkRefGfXO4Smg7P1QBZqK9uoj/CYQa BcyMm5S0KSKCCIZdSYyN/iLOgsAkpCpqOpSLEkmLF5tikkNLVZ5Ag7j0+t4wbO6jRtjP E0LQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp12-20020a170902e78c00b0015d1f88d9b9si29724035plb.458.2022.06.09.04.07.45; Thu, 09 Jun 2022 04:08:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242751AbiFIKhG (ORCPT + 99 others); Thu, 9 Jun 2022 06:37:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242914AbiFIKgt (ORCPT ); Thu, 9 Jun 2022 06:36:49 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73AA3213A2B; Thu, 9 Jun 2022 03:36:18 -0700 (PDT) Received: from fraeml713-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgQf4zxwz68967; Thu, 9 Jun 2022 18:32:42 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml713-chm.china.huawei.com (10.206.15.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 9 Jun 2022 12:36:16 +0200 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 9 Jun 2022 11:36:13 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 06/18] libata-scsi: Add ata_scsi_queue_internal() Date: Thu, 9 Jun 2022 18:29:07 +0800 Message-ID: <1654770559-101375-7-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1654770559-101375-1-git-send-email-john.garry@huawei.com> References: <1654770559-101375-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a function to handle queued ATA internal SCSI cmnds - does much the same as ata_exec_internal_sg() does (which will be fixed up later to actually queue internal cmnds through this function). Signed-off-by: John Garry --- drivers/ata/libata-scsi.c | 47 ++++++++++++++++++++++++++++++++++++++- include/linux/libata.h | 6 +++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 42cecf95a4e5..baac35dd17ca 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3963,6 +3963,49 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) return NULL; } +static unsigned int ata_scsi_queue_internal(struct scsi_cmnd *scmd, + struct ata_device *dev) +{ + struct ata_link *link = dev->link; + struct ata_port *ap = link->ap; + struct ata_queued_cmd *qc; + + /* no internal command while frozen */ + if (ap->pflags & ATA_PFLAG_FROZEN) + goto did_err; + + /* initialize internal qc */ + qc = __ata_qc_from_tag(ap, ATA_TAG_INTERNAL); + link->preempted_tag = link->active_tag; + link->preempted_sactive = link->sactive; + ap->preempted_qc_active = ap->qc_active; + ap->preempted_nr_active_links = ap->nr_active_links; + link->active_tag = ATA_TAG_POISON; + link->sactive = 0; + ap->qc_active = 0; + ap->nr_active_links = 0; + + if (qc->dma_dir != DMA_NONE) { + int n_elem; + + n_elem = 1; + qc->n_elem = n_elem; + qc->sg = scsi_sglist(scmd); + qc->nbytes = qc->sg->length; + ata_sg_init(qc, qc->sg, n_elem); + } + + scmd->submitter = SUBMITTED_BY_BLOCK_LAYER; + + ata_qc_issue(qc); + + return 0; +did_err: + scmd->result = (DID_ERROR << 16); + scsi_done(scmd); + return 0; +} + int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev) { u8 scsi_op = scmd->cmnd[0]; @@ -3971,7 +4014,9 @@ int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev) if (unlikely(!scmd->cmd_len)) goto bad_cdb_len; - if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { + if (scsi_is_reserved_cmd(scmd)) { + return ata_scsi_queue_internal(scmd, dev); + } else if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { if (unlikely(scmd->cmd_len > dev->cdb_len)) goto bad_cdb_len; diff --git a/include/linux/libata.h b/include/linux/libata.h index 732de9014626..43f4bcfe9a5f 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -767,7 +767,9 @@ struct ata_link { struct device tdev; unsigned int active_tag; /* active tag on this link */ + unsigned int preempted_tag; u32 sactive; /* active NCQ commands */ + u32 preempted_sactive; unsigned int flags; /* ATA_LFLAG_xxx */ @@ -861,6 +863,10 @@ struct ata_port { #ifdef CONFIG_ATA_ACPI struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */ #endif + + u64 preempted_qc_active; + int preempted_nr_active_links; + /* owned by EH */ u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned; }; -- 2.26.2