From patchwork Thu Jun 9 10:29:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 12875210 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D614DCCA47E for ; Thu, 9 Jun 2022 10:37:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243132AbiFIKhD (ORCPT ); Thu, 9 Jun 2022 06:37:03 -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 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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; };