From patchwork Thu Jun 9 10:29:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580550 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 EB7C7CCA47E for ; Thu, 9 Jun 2022 10:36:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241277AbiFIKgL (ORCPT ); Thu, 9 Jun 2022 06:36:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239865AbiFIKgD (ORCPT ); Thu, 9 Jun 2022 06:36:03 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E593A1C4715; Thu, 9 Jun 2022 03:36:01 -0700 (PDT) Received: from fraeml736-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgNw0PSvz689Nq; Thu, 9 Jun 2022 18:31:12 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml736-chm.china.huawei.com (10.206.15.217) 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:35:59 +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:35:56 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 01/18] blk-mq: Add a flag for reserved requests Date: Thu, 9 Jun 2022 18:29:02 +0800 Message-ID: <1654770559-101375-2-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 flag for reserved requests so that drivers may know this for any special handling. The 'reserved' argument in blk_mq_ops.timeout callback could now be replaced by using this flag. Signed-off-by: John Garry Reviewed-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- block/blk-mq.c | 6 ++++++ include/linux/blk-mq.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index e9bf950983c7..23f2eafb09ca 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -474,6 +474,9 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) if (!(data->rq_flags & RQF_ELV)) blk_mq_tag_busy(data->hctx); + if (data->flags & BLK_MQ_REQ_RESERVED) + data->rq_flags |= RQF_RESV; + /* * Try batched alloc if we want more than 1 tag. */ @@ -586,6 +589,9 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, else data.rq_flags |= RQF_ELV; + if (flags & BLK_MQ_REQ_RESERVED) + data.rq_flags |= RQF_RESV; + ret = -EWOULDBLOCK; tag = blk_mq_get_tag(&data); if (tag == BLK_MQ_NO_TAG) diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index e2d9daf7e8dd..6d81fe10e850 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -57,6 +57,7 @@ typedef __u32 __bitwise req_flags_t; #define RQF_TIMED_OUT ((__force req_flags_t)(1 << 21)) /* queue has elevator attached */ #define RQF_ELV ((__force req_flags_t)(1 << 22)) +#define RQF_RESV ((__force req_flags_t)(1 << 23)) /* flags that prevent us from merging requests: */ #define RQF_NOMERGE_FLAGS \ @@ -823,6 +824,11 @@ static inline bool blk_mq_need_time_stamp(struct request *rq) return (rq->rq_flags & (RQF_IO_STAT | RQF_STATS | RQF_ELV)); } +static inline bool blk_mq_is_reserved_rq(struct request *rq) +{ + return rq->rq_flags & RQF_RESV; +} + /* * Batched completions only work when there is no I/O error and no special * ->end_io handler. From patchwork Thu Jun 9 10:29:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 581385 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 13183CCA480 for ; Thu, 9 Jun 2022 10:36:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239968AbiFIKgM (ORCPT ); Thu, 9 Jun 2022 06:36:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240164AbiFIKgH (ORCPT ); Thu, 9 Jun 2022 06:36:07 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D29320FC7E; Thu, 9 Jun 2022 03:36:04 -0700 (PDT) Received: from fraeml737-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgT147GPz6885p; Thu, 9 Jun 2022 18:34:45 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml737-chm.china.huawei.com (10.206.15.218) 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:03 +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:35:59 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 02/18] scsi: core: Resurrect scsi_{get, free}_host_dev() Date: Thu, 9 Jun 2022 18:29:03 +0800 Message-ID: <1654770559-101375-3-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 This reverts commit 6bd49b1a8d43ec118c55f3aaa7577729b52bde15. Signed-off-by: John Garry --- drivers/scsi/scsi_scan.c | 57 ++++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_host.h | 10 +++++++ 2 files changed, 67 insertions(+) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 91ac901a6682..925fe63fa370 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -1978,3 +1978,60 @@ void scsi_forget_host(struct Scsi_Host *shost) spin_unlock_irqrestore(shost->host_lock, flags); } +/** + * scsi_get_host_dev - Create a scsi_device that points to the host adapter itself + * @shost: Host that needs a scsi_device + * + * Lock status: None assumed. + * + * Returns: The scsi_device or NULL + * + * Notes: + * Attach a single scsi_device to the Scsi_Host - this should + * be made to look like a "pseudo-device" that points to the + * HA itself. + * + * Note - this device is not accessible from any high-level + * drivers (including generics), which is probably not + * optimal. We can add hooks later to attach. + */ +struct scsi_device *scsi_get_host_dev(struct Scsi_Host *shost) +{ + struct scsi_device *sdev = NULL; + struct scsi_target *starget; + + mutex_lock(&shost->scan_mutex); + if (!scsi_host_scan_allowed(shost)) + goto out; + starget = scsi_alloc_target(&shost->shost_gendev, 0, shost->this_id); + if (!starget) + goto out; + + sdev = scsi_alloc_sdev(starget, 0, NULL); + if (sdev) + sdev->borken = 0; + else + scsi_target_reap(starget); + put_device(&starget->dev); + out: + mutex_unlock(&shost->scan_mutex); + return sdev; +} +EXPORT_SYMBOL(scsi_get_host_dev); + +/** + * scsi_free_host_dev - Free a scsi_device that points to the host adapter itself + * @sdev: Host device to be freed + * + * Lock status: None assumed. + * + * Returns: Nothing + */ +void scsi_free_host_dev(struct scsi_device *sdev) +{ + BUG_ON(sdev->id != sdev->host->this_id); + + __scsi_remove_device(sdev); +} +EXPORT_SYMBOL(scsi_free_host_dev); + diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 667d889b92b5..59aef1f178f5 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -790,6 +790,16 @@ void scsi_host_busy_iter(struct Scsi_Host *, struct class_container; +/* + * These two functions are used to allocate and free a pseudo device + * which will connect to the host adapter itself rather than any + * physical device. You must deallocate when you are done with the + * thing. This physical pseudo-device isn't real and won't be available + * from any high-level drivers. + */ +extern void scsi_free_host_dev(struct scsi_device *); +extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *); + /* * DIF defines the exchange of protection information between * initiator and SBC block device. From patchwork Thu Jun 9 10:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580549 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 830A9CCA47E for ; Thu, 9 Jun 2022 10:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242518AbiFIKg2 (ORCPT ); Thu, 9 Jun 2022 06:36:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240784AbiFIKgK (ORCPT ); Thu, 9 Jun 2022 06:36:10 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37370212D91; Thu, 9 Jun 2022 03:36:08 -0700 (PDT) Received: from fraeml735-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgT46dzzz689N6; Thu, 9 Jun 2022 18:34:48 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml735-chm.china.huawei.com (10.206.15.216) 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:06 +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:02 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 03/18] scsi: core: Implement reserved command handling Date: Thu, 9 Jun 2022 18:29:04 +0800 Message-ID: <1654770559-101375-4-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 From: Hannes Reinecke Quite some drivers are using management commands internally, which typically use the same hardware tag pool (ie they are being allocated from the same hardware resources) as the 'normal' I/O commands. These commands are set aside before allocating the block-mq tag bitmap, so they'll never show up as busy in the tag map. The block-layer, OTOH, already has 'reserved_tags' to handle precisely this situation. So this patch adds a new field 'nr_reserved_cmds' to the SCSI host template to instruct the block layer to set aside a tag space for these management commands by using reserved tags. Signed-off-by: Hannes Reinecke Signed-off-by: John Garry --- drivers/scsi/hosts.c | 3 +++ drivers/scsi/scsi_lib.c | 6 +++++- include/scsi/scsi_host.h | 22 +++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 8352f90d997d..27296addaf63 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -474,6 +474,9 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize) if (sht->virt_boundary_mask) shost->virt_boundary_mask = sht->virt_boundary_mask; + if (sht->nr_reserved_cmds) + shost->nr_reserved_cmds = sht->nr_reserved_cmds; + device_initialize(&shost->shost_gendev); dev_set_name(&shost->shost_gendev, "host%d", shost->host_no); shost->shost_gendev.bus = &scsi_bus_type; diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 6ffc9e4258a8..f6e53c6d913c 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1974,8 +1974,12 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) else tag_set->ops = &scsi_mq_ops_no_commit; tag_set->nr_hw_queues = shost->nr_hw_queues ? : 1; + tag_set->nr_maps = shost->nr_maps ? : 1; - tag_set->queue_depth = shost->can_queue; + tag_set->queue_depth = + shost->can_queue + shost->nr_reserved_cmds; + tag_set->reserved_tags = shost->nr_reserved_cmds; + tag_set->cmd_size = cmd_size; tag_set->numa_node = dev_to_node(shost->dma_dev); tag_set->flags = BLK_MQ_F_SHOULD_MERGE; diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 59aef1f178f5..149dcbd4125e 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -366,10 +366,19 @@ struct scsi_host_template { /* * This determines if we will use a non-interrupt driven * or an interrupt driven scheme. It is set to the maximum number - * of simultaneous commands a single hw queue in HBA will accept. + * of simultaneous commands a single hw queue in HBA will accept + * excluding internal commands. */ int can_queue; + /* + * This determines how many commands the HBA will set aside + * for internal commands. This number will be added to + * @can_queue to calcumate the maximum number of simultaneous + * commands sent to the host. + */ + int nr_reserved_cmds; + /* * In many instances, especially where disconnect / reconnect are * supported, our host also has an ID on the SCSI bus. If this is @@ -602,6 +611,11 @@ struct Scsi_Host { unsigned short max_cmd_len; int this_id; + + /* + * Number of commands this host can handle at the same time. + * This excludes reserved commands as specified by nr_reserved_cmds. + */ int can_queue; short cmd_per_lun; short unsigned int sg_tablesize; @@ -620,6 +634,12 @@ struct Scsi_Host { */ unsigned nr_hw_queues; unsigned nr_maps; + + /* + * Number of reserved commands to allocate, if any. + */ + unsigned nr_reserved_cmds; + unsigned active_mode:2; /* From patchwork Thu Jun 9 10:29:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 581384 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 59A51CCA47E for ; Thu, 9 Jun 2022 10:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242930AbiFIKgt (ORCPT ); Thu, 9 Jun 2022 06:36:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242304AbiFIKgO (ORCPT ); Thu, 9 Jun 2022 06:36:14 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D9522109F9; Thu, 9 Jun 2022 03:36:11 -0700 (PDT) Received: from fraeml734-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgP55ZrNz6813w; Thu, 9 Jun 2022 18:31:21 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml734-chm.china.huawei.com (10.206.15.215) 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:09 +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:06 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 04/18] scsi: core: Add support to send reserved commands Date: Thu, 9 Jun 2022 18:29:05 +0800 Message-ID: <1654770559-101375-5-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 method to queue reserved commands. TODO: - fix timeout handler to call into reserved commands - We don't clear host_scribble for libata qc, but we should be able to drop this if we store libata qc in the scsi cmnd priv_data Signed-off-by: John Garry --- drivers/scsi/hosts.c | 6 ++++++ drivers/scsi/scsi_lib.c | 32 ++++++++++++++++++++++++++++++++ include/scsi/scsi_cmnd.h | 5 +++++ include/scsi/scsi_host.h | 1 + 4 files changed, 44 insertions(+) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 27296addaf63..5c9b05a8fec8 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -221,6 +221,12 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, goto fail; } + if (shost->nr_reserved_cmds && !sht->reserved_queuecommand) { + shost_printk(KERN_ERR, shost, + "nr_reserved_cmds set but no method to queue\n"); + goto fail; + } + /* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */ shost->cmd_per_lun = min_t(int, shost->cmd_per_lun, shost->can_queue); diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index f6e53c6d913c..8c8b4c6767d9 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1422,6 +1422,16 @@ static void scsi_complete(struct request *rq) struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); enum scsi_disposition disposition; + if (scsi_is_reserved_cmd(cmd)) { + struct scsi_device *sdev = cmd->device; + + scsi_mq_uninit_cmd(cmd); + scsi_device_unbusy(sdev, cmd); + __blk_mq_end_request(rq, 0); + + return; + } + INIT_LIST_HEAD(&cmd->eh_entry); atomic_inc(&cmd->device->iodone_cnt); @@ -1706,6 +1716,28 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, WARN_ON_ONCE(cmd->budget_token < 0); + if (scsi_is_reserved_cmd(cmd)) { + unsigned char *host_scribble = cmd->host_scribble; + + if (!(req->rq_flags & RQF_DONTPREP)) { + ret = scsi_prepare_cmd(req); + if (ret != BLK_STS_OK) { + + goto out_dec_host_busy; + } + + req->rq_flags |= RQF_DONTPREP; + } else { + clear_bit(SCMD_STATE_COMPLETE, &cmd->state); + } + + cmd->host_scribble = host_scribble; + + blk_mq_start_request(req); + + return shost->hostt->reserved_queuecommand(shost, cmd); + } + /* * If the device is not in running state we will reject some or all * commands. diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 1e80e70dfa92..e47df5836070 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -152,6 +152,11 @@ static inline void *scsi_cmd_priv(struct scsi_cmnd *cmd) return cmd + 1; } +static inline bool scsi_is_reserved_cmd(struct scsi_cmnd *cmd) +{ + return blk_mq_is_reserved_rq(scsi_cmd_to_rq(cmd)); +} + void scsi_done(struct scsi_cmnd *cmd); void scsi_done_direct(struct scsi_cmnd *cmd); diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 149dcbd4125e..88c8504395c8 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -73,6 +73,7 @@ struct scsi_host_template { * STATUS: REQUIRED */ int (* queuecommand)(struct Scsi_Host *, struct scsi_cmnd *); + int (* reserved_queuecommand)(struct Scsi_Host *, struct scsi_cmnd *); /* * The commit_rqs function is used to trigger a hardware From patchwork Thu Jun 9 10:29:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580546 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 003C3CCA47E for ; Thu, 9 Jun 2022 10:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243021AbiFIKhM (ORCPT ); Thu, 9 Jun 2022 06:37:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242791AbiFIKg3 (ORCPT ); Thu, 9 Jun 2022 06:36:29 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B9ED213AC4; Thu, 9 Jun 2022 03:36:14 -0700 (PDT) Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgQb0tMMz67ycH; Thu, 9 Jun 2022 18:32:39 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml714-chm.china.huawei.com (10.206.15.33) 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:12 +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:09 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 05/18] scsi: core: Allocate SCSI host sdev when required Date: Thu, 9 Jun 2022 18:29:06 +0800 Message-ID: <1654770559-101375-6-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 When the shost supports reserved commands then allocate the SCSI host sdev. As noted later, we need to use this for libata internal commands. Signed-off-by: John Garry --- drivers/scsi/hosts.c | 5 +++++ include/scsi/scsi_host.h | 1 + 2 files changed, 6 insertions(+) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 5c9b05a8fec8..67930a61b222 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -298,6 +298,8 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, scsi_proc_host_add(shost); scsi_autopm_put_host(shost); + if (shost->nr_reserved_cmds) + shost->sdev = scsi_get_host_dev(shost); // TODO: Add error handling return error; /* @@ -360,6 +362,9 @@ static void scsi_host_dev_release(struct device *dev) if (shost->shost_state != SHOST_CREATED) put_device(parent); + if (shost->sdev) + scsi_free_host_dev(shost->sdev); + kfree(shost); } diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 88c8504395c8..2e14d65b7444 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -566,6 +566,7 @@ struct Scsi_Host { wait_queue_head_t host_wait; struct scsi_host_template *hostt; struct scsi_transport_template *transportt; + struct scsi_device *sdev; /* Area to keep a shared tag map */ struct blk_mq_tag_set tag_set; 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: 581383 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; }; From patchwork Thu Jun 9 10:29:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580548 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 E727AC433EF for ; Thu, 9 Jun 2022 10:36:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242966AbiFIKg4 (ORCPT ); Thu, 9 Jun 2022 06:36:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242960AbiFIKgu (ORCPT ); Thu, 9 Jun 2022 06:36:50 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0126214812; Thu, 9 Jun 2022 03:36:21 -0700 (PDT) Received: from fraeml715-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgTL0SD0z67LRs; Thu, 9 Jun 2022 18:35:02 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml715-chm.china.huawei.com (10.206.15.34) 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:19 +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:16 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 07/18] libata-scsi: Add ata_internal_queuecommand() Date: Thu, 9 Jun 2022 18:29:08 +0800 Message-ID: <1654770559-101375-8-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 callback to queue reserved commands - call it "internal" as this is what libata uses. Also add it to the base ATA SHT, and set nr_reserved_cmds = 1, which matches tag ATA_TAG_INTERNAL. Signed-off-by: John Garry --- drivers/ata/libata-scsi.c | 14 ++++++++++++++ include/linux/libata.h | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index baac35dd17ca..b2702ab0183b 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1114,6 +1114,20 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev) return 0; } +int ata_internal_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmd) +{ + struct ata_port *ap; + int res; + + ap = ata_shost_to_port(shost); + spin_lock_irq(ap->lock); + res = ata_sas_queuecmd(scmd, ap); + spin_unlock_irq(ap->lock); + + return res; +} +EXPORT_SYMBOL_GPL(ata_internal_queuecommand); + /** * ata_scsi_slave_config - Set SCSI device attributes * @sdev: SCSI device to examine diff --git a/include/linux/libata.h b/include/linux/libata.h index 43f4bcfe9a5f..5fa6f56bba81 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1141,6 +1141,8 @@ extern int ata_std_bios_param(struct scsi_device *sdev, sector_t capacity, int geom[]); extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev); extern int ata_scsi_slave_config(struct scsi_device *sdev); +extern int ata_internal_queuecommand(struct Scsi_Host *shost, + struct scsi_cmnd *scmd); extern void ata_scsi_slave_destroy(struct scsi_device *sdev); extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth); @@ -1390,7 +1392,9 @@ extern const struct attribute_group *ata_common_sdev_groups[]; .proc_name = drv_name, \ .slave_destroy = ata_scsi_slave_destroy, \ .bios_param = ata_std_bios_param, \ - .unlock_native_capacity = ata_scsi_unlock_native_capacity + .unlock_native_capacity = ata_scsi_unlock_native_capacity,\ + .nr_reserved_cmds = 1,\ + .reserved_queuecommand = ata_internal_queuecommand #define ATA_SUBBASE_SHT(drv_name) \ __ATA_BASE_SHT(drv_name), \ From patchwork Thu Jun 9 10:29:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 581382 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 7B625CCA47F for ; Thu, 9 Jun 2022 10:37:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243061AbiFIKhK (ORCPT ); Thu, 9 Jun 2022 06:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243056AbiFIKgw (ORCPT ); Thu, 9 Jun 2022 06:36:52 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 407EF215649; Thu, 9 Jun 2022 03:36:25 -0700 (PDT) Received: from fraeml710-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgPM0jHwz6GCX1; Thu, 9 Jun 2022 18:31:35 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml710-chm.china.huawei.com (10.206.15.59) 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:23 +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:19 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 08/18] libata: Queue ATA internal commands as requests Date: Thu, 9 Jun 2022 18:29:09 +0800 Message-ID: <1654770559-101375-9-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 Follow the normal path for requests and queue through the block layer. We hold the qc pointer in the scmd host scribble, which is less than ideal. In future we can hold the ata_queued_cmd in the scmd priv_data, allowing for easy lookup. We need to use the shost sdev to queue these requests. That is because we initially do not have the target disk scsi_device allocated yet when queueing internal commands. This is less than ideal, and makes it hard for libsas to know when queueing an internal command whether it is a ATA internal command or not. Also make ata_exec_internal_sg() static - there are no users outside libata-core.c Signed-off-by: John Garry --- drivers/ata/libata-core.c | 137 +++++++++++++++++++++----------------- drivers/ata/libata-sata.c | 5 +- drivers/ata/libata.h | 4 -- 3 files changed, 80 insertions(+), 66 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 40e816419f48..6b1aaeccb253 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1438,9 +1438,18 @@ unsigned long ata_id_xfermask(const u16 *id) } EXPORT_SYMBOL_GPL(ata_id_xfermask); -static void ata_qc_complete_internal(struct ata_queued_cmd *qc) +void ata_qc_complete_internal(struct ata_queued_cmd *qc) { - struct completion *waiting = qc->private_data; + struct scsi_cmnd *scmd = qc->scsicmd; + + scsi_done(scmd); +} + +static void ata_internal_end_rq(struct request *rq, blk_status_t error) +{ + struct completion *waiting = rq->end_io_data; + + rq->end_io_data = (void *)(uintptr_t)error; complete(waiting); } @@ -1467,52 +1476,74 @@ static void ata_qc_complete_internal(struct ata_queued_cmd *qc) * RETURNS: * Zero on success, AC_ERR_* mask on failure */ -unsigned ata_exec_internal_sg(struct ata_device *dev, +static unsigned ata_exec_internal_sg(struct ata_device *dev, struct ata_taskfile *tf, const u8 *cdb, - int dma_dir, struct scatterlist *sgl, - unsigned int n_elem, unsigned long timeout) + int dma_dir, void *buf, unsigned int buflen, + unsigned long timeout) { struct ata_link *link = dev->link; struct ata_port *ap = link->ap; + struct Scsi_Host *scsi_host = ap->scsi_host; + struct scsi_device *sdev = scsi_host->sdev; u8 command = tf->command; int auto_timeout = 0; struct ata_queued_cmd *qc; - unsigned int preempted_tag; - u32 preempted_sactive; - u64 preempted_qc_active; - int preempted_nr_active_links; DECLARE_COMPLETION_ONSTACK(wait); unsigned long flags; unsigned int err_mask; + struct scsi_cmnd *scmd; + struct request *req; int rc; - spin_lock_irqsave(ap->lock, flags); + /* + * We only support a single reserved command, so this guarantees + * serialization. However the code already assumed that (we are + * serialized here per-port). + */ + req = scsi_alloc_request(sdev->request_queue, + dma_dir == DMA_TO_DEVICE ? + REQ_OP_DRV_OUT : REQ_OP_DRV_IN, + BLK_MQ_REQ_RESERVED); + if (IS_ERR(req)) + return AC_ERR_OTHER; - /* no internal command while frozen */ - if (ap->pflags & ATA_PFLAG_FROZEN) { - spin_unlock_irqrestore(ap->lock, flags); - return AC_ERR_SYSTEM; + + if (!timeout) { + if (ata_probe_timeout) + timeout = ata_probe_timeout * 1000; + else { + timeout = ata_internal_cmd_timeout(dev, command); + auto_timeout = 1; + } } - /* initialize internal qc */ + scmd = blk_mq_rq_to_pdu(req); + scmd->allowed = 0; + req->timeout = timeout; + //TODO: Hook up timeout handler + req->rq_flags |= RQF_QUIET; + scmd->device = sdev; qc = __ata_qc_from_tag(ap, ATA_TAG_INTERNAL); + /* Do this until we can hold ata_queued_cmd in the SCMD priv data */ + scmd->host_scribble = (unsigned char *)qc; + + if (buflen) { + int ret = blk_rq_map_kern(sdev->request_queue, req, + buf, buflen, GFP_NOIO); + if (ret) { + blk_mq_free_request(req); + return AC_ERR_OTHER; + } + } + qc->tag = ATA_TAG_INTERNAL; qc->hw_tag = 0; - qc->scsicmd = NULL; + qc->scsicmd = scmd; qc->ap = ap; qc->dev = dev; ata_qc_reinit(qc); - preempted_tag = link->active_tag; - preempted_sactive = link->sactive; - preempted_qc_active = ap->qc_active; - 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; - /* prepare & issue qc */ qc->tf = *tf; if (cdb) @@ -1525,32 +1556,14 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, qc->flags |= ATA_QCFLAG_RESULT_TF; qc->dma_dir = dma_dir; - if (dma_dir != DMA_NONE) { - unsigned int i, buflen = 0; - struct scatterlist *sg; - - for_each_sg(sgl, sg, n_elem, i) - buflen += sg->length; - - ata_sg_init(qc, sgl, n_elem); - qc->nbytes = buflen; - } - qc->private_data = &wait; + qc->private_data = ap; qc->complete_fn = ata_qc_complete_internal; - ata_qc_issue(qc); - - spin_unlock_irqrestore(ap->lock, flags); + req->end_io_data = &wait; + req->end_io = ata_internal_end_rq; - if (!timeout) { - if (ata_probe_timeout) - timeout = ata_probe_timeout * 1000; - else { - timeout = ata_internal_cmd_timeout(dev, command); - auto_timeout = 1; - } - } + blk_execute_rq_nowait(req, true); if (ap->ops->error_handler) ata_eh_release(ap); @@ -1610,13 +1623,15 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, err_mask = qc->err_mask; ata_qc_free(qc); - link->active_tag = preempted_tag; - link->sactive = preempted_sactive; - ap->qc_active = preempted_qc_active; - ap->nr_active_links = preempted_nr_active_links; + link->active_tag = link->preempted_tag; + link->sactive = link->preempted_sactive; + ap->qc_active = ap->preempted_qc_active; + ap->nr_active_links = ap->preempted_nr_active_links; spin_unlock_irqrestore(ap->lock, flags); + blk_mq_free_request(req); + if ((err_mask & AC_ERR_TIMEOUT) && auto_timeout) ata_internal_cmd_timed_out(dev, command); @@ -1647,18 +1662,20 @@ unsigned ata_exec_internal(struct ata_device *dev, int dma_dir, void *buf, unsigned int buflen, unsigned long timeout) { - struct scatterlist *psg = NULL, sg; - unsigned int n_elem = 0; + /* buf may not be aligned, so copy to/from an aligned buffer */ + void *tmpbuf = kmemdup(buf, buflen, GFP_KERNEL); + unsigned res; - if (dma_dir != DMA_NONE) { - WARN_ON(!buf); - sg_init_one(&sg, buf, buflen); - psg = &sg; - n_elem++; - } + if (!tmpbuf) + return AC_ERR_OTHER; - return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem, + res = ata_exec_internal_sg(dev, tf, cdb, dma_dir, tmpbuf, buflen, timeout); + + memcpy(buf, tmpbuf, buflen); + kfree(tmpbuf); + + return res; } /** diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 7a5fe41aa5ae..3cecc45d54ab 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1258,9 +1258,10 @@ int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap) { int rc = 0; - if (likely(ata_dev_enabled(ap->link.device))) + if (likely(ata_dev_enabled(ap->link.device)) || + scsi_is_reserved_cmd(cmd)) { rc = __ata_scsi_queuecmd(cmd, ap->link.device); - else { + } else { cmd->result = (DID_BAD_TARGET << 16); scsi_done(cmd); } diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 926a7f41303d..1446a482835d 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -53,10 +53,6 @@ extern unsigned ata_exec_internal(struct ata_device *dev, struct ata_taskfile *tf, const u8 *cdb, int dma_dir, void *buf, unsigned int buflen, unsigned long timeout); -extern unsigned ata_exec_internal_sg(struct ata_device *dev, - struct ata_taskfile *tf, const u8 *cdb, - int dma_dir, struct scatterlist *sg, - unsigned int n_elem, unsigned long timeout); extern int ata_wait_ready(struct ata_link *link, unsigned long deadline, int (*check_ready)(struct ata_link *link)); extern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class, From patchwork Thu Jun 9 10:29:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580547 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 9AA50C43334 for ; Thu, 9 Jun 2022 10:37:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242163AbiFIKhG (ORCPT ); Thu, 9 Jun 2022 06:37:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243075AbiFIKgx (ORCPT ); Thu, 9 Jun 2022 06:36:53 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2565B215A42; Thu, 9 Jun 2022 03:36:28 -0700 (PDT) Received: from fraeml712-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgQr35Vbz67sRl; Thu, 9 Jun 2022 18:32:52 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml712-chm.china.huawei.com (10.206.15.61) 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:26 +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:22 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 09/18] scsi: ipr: Support reserved commands Date: Thu, 9 Jun 2022 18:29:10 +0800 Message-ID: <1654770559-101375-10-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 Support a single reserved command for ATA internal commands. We also add SHT reserved_queuecommand callback to support queueing those internal commands. Signed-off-by: John Garry --- drivers/scsi/ipr.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c index 256ec6d08c16..4f4cf39cd2bc 100644 --- a/drivers/scsi/ipr.c +++ b/drivers/scsi/ipr.c @@ -6740,6 +6740,19 @@ static const char *ipr_ioa_info(struct Scsi_Host *host) return buffer; } +static int ipr_reserved_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmd) +{ + struct ata_queued_cmd *qc = (struct ata_queued_cmd *)scmd->host_scribble; + struct ata_port *ap = qc->ap; + int ret; + + /* We're only going to be seeing ATA internal commands */ + spin_lock_irq(ap->lock); + ret = ata_sas_queuecmd(scmd, ap); + spin_unlock_irq(ap->lock); + return ret; +} + static struct scsi_host_template driver_template = { .module = THIS_MODULE, .name = "IPR", @@ -6749,6 +6762,7 @@ static struct scsi_host_template driver_template = { .compat_ioctl = ipr_ioctl, #endif .queuecommand = ipr_queuecommand, + .reserved_queuecommand = ipr_reserved_queuecommand, .dma_need_drain = ata_scsi_dma_need_drain, .eh_abort_handler = ipr_eh_abort, .eh_device_reset_handler = ipr_eh_dev_reset, @@ -9991,7 +10005,8 @@ static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg, host->unique_id = host->host_no; host->max_cmd_len = IPR_MAX_CDB_LEN; - host->can_queue = ioa_cfg->max_cmds; + host->can_queue = ioa_cfg->max_cmds - 1; + host->nr_reserved_cmds = 1; pci_set_drvdata(pdev, ioa_cfg); for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) { From patchwork Thu Jun 9 10:29:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 581381 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 B77F2CCA47E for ; Thu, 9 Jun 2022 10:37:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243171AbiFIKhS (ORCPT ); Thu, 9 Jun 2022 06:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243090AbiFIKgx (ORCPT ); Thu, 9 Jun 2022 06:36:53 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D3DD215659; Thu, 9 Jun 2022 03:36:31 -0700 (PDT) Received: from fraeml711-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgTW6TRpz67bS0; Thu, 9 Jun 2022 18:35:11 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml711-chm.china.huawei.com (10.206.15.60) 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:29 +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:26 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 10/18] libata/scsi: libsas: Add sas_queuecommand_internal() Date: Thu, 9 Jun 2022 18:29:11 +0800 Message-ID: <1654770559-101375-11-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 callback for sht reserved_queuecommand callback. We need to add libata helper ata_is_scmd_ata_internal() as it is difficult to know whether the request should be queued as an ATA internal command. We will store the sas_task in the scsi_cmnd payload also in future. Signed-off-by: John Garry --- drivers/ata/libata-core.c | 8 ++++++++ drivers/scsi/libsas/sas_scsi_host.c | 21 +++++++++++++++++++++ include/linux/libata.h | 1 + include/scsi/libsas.h | 8 ++++++++ 4 files changed, 38 insertions(+) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 6b1aaeccb253..a9645951a0f0 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -1454,6 +1454,14 @@ static void ata_internal_end_rq(struct request *rq, blk_status_t error) complete(waiting); } +bool ata_is_scmd_ata_internal(struct scsi_cmnd *scmd) +{ + struct request *rq = scsi_cmd_to_rq(scmd); + + return rq->end_io == ata_internal_end_rq; +} +EXPORT_SYMBOL_GPL(ata_is_scmd_ata_internal); + /** * ata_exec_internal_sg - execute libata internal command * @dev: Device to which the command is sent diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 9c82e5dc4fcc..42279a6d6b06 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -158,6 +158,27 @@ static struct sas_task *sas_create_task(struct scsi_cmnd *cmd, return task; } +int sas_queuecommand_internal(struct Scsi_Host *shost, struct scsi_cmnd *cmnd) +{ + struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); + struct sas_internal *i = to_sas_internal(ha->core.shost->transportt); + struct request *rq = scsi_cmd_to_rq(cmnd); + + if (ata_is_scmd_ata_internal(cmnd)) { + struct ata_queued_cmd *qc = (struct ata_queued_cmd *)cmnd->host_scribble; + struct ata_port *ap = qc->ap; + int res; + + spin_lock_irq(ap->lock); + res = ata_sas_queuecmd(cmnd, ap); + spin_unlock_irq(ap->lock); + return res; + } + + return i->dft->lldd_execute_task(sas_rq_to_task(rq), GFP_KERNEL); +} +EXPORT_SYMBOL_GPL(sas_queuecommand_internal); + int sas_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) { struct sas_internal *i = to_sas_internal(host->transportt); diff --git a/include/linux/libata.h b/include/linux/libata.h index 5fa6f56bba81..6cb7a5bcb308 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1238,6 +1238,7 @@ extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *); extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap); extern void ata_tf_to_fis(const struct ata_taskfile *tf, u8 pmp, int is_cmd, u8 *fis); +extern bool ata_is_scmd_ata_internal(struct scsi_cmnd *scmd); extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf); extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active); extern bool sata_lpm_ignore_phy_events(struct ata_link *link); diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index ff04eb6d250b..261169ffdca6 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h @@ -725,6 +725,7 @@ int sas_discover_sata(struct domain_device *); int sas_discover_end_dev(struct domain_device *); void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *); +int sas_queuecommand_internal(struct Scsi_Host *shost, struct scsi_cmnd *cmnd); void sas_init_dev(struct domain_device *); @@ -756,4 +757,11 @@ void sas_notify_port_event(struct asd_sas_phy *phy, enum port_event event, void sas_notify_phy_event(struct asd_sas_phy *phy, enum phy_event event, gfp_t gfp_flags); +static inline struct sas_task *sas_rq_to_task(struct request *rq) +{ + struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq); + + return (struct sas_task *)(scmd + 1); +} + #endif /* _SASLIB_H_ */ From patchwork Thu Jun 9 10:29:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 581379 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 31223CCA473 for ; Thu, 9 Jun 2022 10:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242955AbiFIKhf (ORCPT ); Thu, 9 Jun 2022 06:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243105AbiFIKg6 (ORCPT ); Thu, 9 Jun 2022 06:36:58 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1111215E6A; Thu, 9 Jun 2022 03:36:34 -0700 (PDT) Received: from fraeml709-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgPX5R5Bz689NW; Thu, 9 Jun 2022 18:31:44 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml709-chm.china.huawei.com (10.206.15.37) 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:32 +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:29 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 11/18] scsi: libsas: Don't attempt to find scsi host rphy in slave alloc Date: Thu, 9 Jun 2022 18:29:12 +0800 Message-ID: <1654770559-101375-12-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 It doesn't have one. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 12 ++++++++++-- drivers/scsi/libsas/sas_scsi_host.c | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 764e859d0106..0219ccac9062 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -756,14 +756,22 @@ static int hisi_sas_init_device(struct domain_device *device) int hisi_sas_slave_alloc(struct scsi_device *sdev) { - struct domain_device *ddev = sdev_to_domain_dev(sdev); - struct hisi_sas_device *sas_dev = ddev->lldd_dev; + struct scsi_target *starget = sdev->sdev_target; + struct device *parent = starget->dev.parent; + struct hisi_sas_device *sas_dev; + struct domain_device *ddev; int rc; + if (scsi_is_host_device(parent)) + return 0; + rc = sas_slave_alloc(sdev); if (rc) return rc; + ddev = sdev_to_domain_dev(sdev); + sas_dev = ddev->lldd_dev; + rc = hisi_sas_init_device(ddev); if (rc) return rc; diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 42279a6d6b06..532e734c1fb6 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -847,8 +847,15 @@ struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy) int sas_target_alloc(struct scsi_target *starget) { - struct sas_rphy *rphy = dev_to_rphy(starget->dev.parent); - struct domain_device *found_dev = sas_find_dev_by_rphy(rphy); + struct device *parent = starget->dev.parent; + struct sas_rphy *rphy; + struct domain_device *found_dev; + + if (scsi_is_host_device(parent)) + return 0; + + rphy = dev_to_rphy(parent); + found_dev = sas_find_dev_by_rphy(rphy); if (!found_dev) return -ENODEV; @@ -1252,6 +1259,12 @@ EXPORT_SYMBOL_GPL(sas_task_abort); int sas_slave_alloc(struct scsi_device *sdev) { + struct scsi_target *starget = sdev->sdev_target; + struct device *parent = starget->dev.parent; + + if (scsi_is_host_device(parent)) + return 0; + if (dev_is_sata(sdev_to_domain_dev(sdev)) && sdev->lun) return -ENXIO; From patchwork Thu Jun 9 10:29:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580544 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 078BEC433EF for ; Thu, 9 Jun 2022 10:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242949AbiFIKhd (ORCPT ); Thu, 9 Jun 2022 06:37:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242983AbiFIKhC (ORCPT ); Thu, 9 Jun 2022 06:37:02 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A720E2162A2; Thu, 9 Jun 2022 03:36:37 -0700 (PDT) Received: from fraeml707-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgR16xfvz67xvP; Thu, 9 Jun 2022 18:33:01 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml707-chm.china.huawei.com (10.206.15.35) 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:35 +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:32 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 12/18] scsi: libsas drivers: Prepare for reserved commands Date: Thu, 9 Jun 2022 18:29:13 +0800 Message-ID: <1654770559-101375-13-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 Set the various LLDD fields to be able to use reserved commands. I have only done this for hisi sas v2 HW, but all others need this treatment. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 5 +++-- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 3 +++ drivers/scsi/libsas/sas_init.c | 5 +++++ include/scsi/libsas.h | 8 ++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 0219ccac9062..2c5c6301f224 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -2427,8 +2427,9 @@ int hisi_sas_probe(struct platform_device *pdev, shost->max_channel = 1; shost->max_cmd_len = 16; if (hisi_hba->hw->slot_index_alloc) { - shost->can_queue = HISI_SAS_MAX_COMMANDS; - shost->cmd_per_lun = HISI_SAS_MAX_COMMANDS; + shost->can_queue = HISI_SAS_UNRESERVED_IPTT; + shost->nr_reserved_cmds = HISI_SAS_RESERVED_IPTT; + shost->cmd_per_lun = HISI_SAS_UNRESERVED_IPTT; } else { shost->can_queue = HISI_SAS_UNRESERVED_IPTT; shost->cmd_per_lun = HISI_SAS_UNRESERVED_IPTT; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index 455d49299ddf..a1e60d2ef070 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -3564,6 +3564,7 @@ static struct scsi_host_template sht_v2_hw = { .proc_name = DRV_NAME, .module = THIS_MODULE, .queuecommand = sas_queuecommand, + .reserved_queuecommand = sas_queuecommand_internal, .dma_need_drain = ata_scsi_dma_need_drain, .target_alloc = sas_target_alloc, .slave_configure = hisi_sas_slave_configure, @@ -3586,6 +3587,8 @@ static struct scsi_host_template sht_v2_hw = { .host_reset = hisi_sas_host_reset, .map_queues = map_queues_v2_hw, .host_tagset = 1, + .cmd_size = sizeof(struct sas_task), + .init_cmd_priv = sas_init_priv_cmd, }; static const struct hisi_sas_hw hisi_sas_v2_hw = { diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c index dc35f0f8eae3..b0921fbc35b1 100644 --- a/drivers/scsi/libsas/sas_init.c +++ b/drivers/scsi/libsas/sas_init.c @@ -93,6 +93,11 @@ void sas_hash_addr(u8 *hashed, const u8 *sas_addr) hashed[2] = r & 0xFF; } +int sas_init_priv_cmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd) +{ + return 0; +} + int sas_register_ha(struct sas_ha_struct *sas_ha) { char name[64]; diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index 261169ffdca6..92fc3e5ef297 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h @@ -693,6 +693,8 @@ extern void sas_resume_ha(struct sas_ha_struct *sas_ha); extern void sas_resume_ha_no_sync(struct sas_ha_struct *sas_ha); extern void sas_suspend_ha(struct sas_ha_struct *sas_ha); +extern int sas_init_priv_cmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd); + int sas_set_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates); int sas_phy_reset(struct sas_phy *phy, int hard_reset); int sas_phy_enable(struct sas_phy *phy, int enable); @@ -764,4 +766,10 @@ static inline struct sas_task *sas_rq_to_task(struct request *rq) return (struct sas_task *)(scmd + 1); } +static inline struct scsi_cmnd *sas_scmd_from_task(void *task) +{ + struct scsi_cmnd *scmd = task - sizeof(*scmd); + + return scmd; +} #endif /* _SASLIB_H_ */ From patchwork Thu Jun 9 10:29:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 581380 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 4C599C433EF for ; Thu, 9 Jun 2022 10:37:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243257AbiFIKh3 (ORCPT ); Thu, 9 Jun 2022 06:37:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243144AbiFIKhD (ORCPT ); Thu, 9 Jun 2022 06:37:03 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7F9521683A; Thu, 9 Jun 2022 03:36:40 -0700 (PDT) Received: from fraeml708-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgPg0Wz3z67dbJ; Thu, 9 Jun 2022 18:31:51 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml708-chm.china.huawei.com (10.206.15.36) 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:39 +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:35 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 13/18] scsi: libsas: Allocate SCSI commands for tasks Date: Thu, 9 Jun 2022 18:29:14 +0800 Message-ID: <1654770559-101375-14-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 Allocate a SCSI command for a SAS task. The next step will be to send tasks same as we do for other requests - through the block layer. Signed-off-by: John Garry --- drivers/scsi/libsas/sas_ata.c | 17 +++++--- drivers/scsi/libsas/sas_expander.c | 11 +++++- drivers/scsi/libsas/sas_init.c | 60 +++++++++++++++-------------- drivers/scsi/libsas/sas_scsi_host.c | 17 ++++---- include/scsi/libsas.h | 17 +++++++- 5 files changed, 77 insertions(+), 45 deletions(-) diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index d35c9296f738..66534332e9ac 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -72,7 +72,8 @@ static enum ata_completion_errors sas_to_ata_err(struct task_status_struct *ts) static void sas_ata_task_done(struct sas_task *task) { - struct ata_queued_cmd *qc = task->uldd_task; + struct scsi_cmnd *scmd = sas_scmd_from_task(task); + struct ata_queued_cmd *qc = TO_SAS_TASK(scmd); struct domain_device *dev = task->dev; struct task_status_struct *stat = &task->task_status; struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf; @@ -149,7 +150,9 @@ static void sas_ata_task_done(struct sas_task *task) spin_unlock_irqrestore(ap->lock, flags); qc_already_gone: - sas_free_task(task); + /* We rely on libata internal command to do this for us */ + if (!ata_is_scmd_ata_internal(scmd)) + sas_free_task(task); } static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) @@ -164,6 +167,7 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) struct sas_ha_struct *sas_ha = dev->port->ha; struct Scsi_Host *host = sas_ha->core.shost; struct sas_internal *i = to_sas_internal(host->transportt); + struct scsi_cmnd *scmd; /* TODO: we should try to remove that unlock */ spin_unlock(ap->lock); @@ -172,9 +176,9 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) if (test_bit(SAS_DEV_GONE, &dev->state)) goto out; - task = sas_alloc_task(GFP_ATOMIC); - if (!task) - goto out; + scmd = qc->scsicmd; + task = sas_scmd_to_task(scmd); + task->dev = dev; task->task_proto = SAS_PROTOCOL_STP; task->task_done = sas_ata_task_done; @@ -596,7 +600,8 @@ int sas_ata_init(struct domain_device *found_dev) void sas_ata_task_abort(struct sas_task *task) { - struct ata_queued_cmd *qc = task->uldd_task; + struct scsi_cmnd *scmd = sas_scmd_from_task(task); + struct ata_queued_cmd *qc = TO_SAS_TASK(scmd); struct completion *waiting; /* Bounce SCSI-initiated commands to the SCSI EH */ diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index 260e735d06fa..b833de062f88 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -39,20 +39,29 @@ static int smp_execute_task_sg(struct domain_device *dev, struct sas_internal *i = to_sas_internal(dev->port->ha->core.shost->transportt); struct sas_ha_struct *ha = dev->port->ha; + struct request *rq; pm_runtime_get_sync(ha->dev); mutex_lock(&dev->ex_dev.cmd_mutex); for (retry = 0; retry < 3; retry++) { + struct scsi_cmnd *scmd; + if (test_bit(SAS_DEV_GONE, &dev->state)) { res = -ECOMM; break; } - task = sas_alloc_slow_task(GFP_KERNEL); + task = sas_alloc_slow_task(dev->port->ha, GFP_KERNEL); if (!task) { res = -ENOMEM; break; } + + rq = sas_rq_from_task(task); + + scmd = blk_mq_rq_to_pdu(rq); + ASSIGN_SAS_TASK(scmd, task); + task->dev = dev; task->task_proto = dev->tproto; task->smp_task.smp_req = *req; diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c index b0921fbc35b1..8d03b8abcaa3 100644 --- a/drivers/scsi/libsas/sas_init.c +++ b/drivers/scsi/libsas/sas_init.c @@ -21,30 +21,31 @@ #include "scsi_sas_internal.h" -static struct kmem_cache *sas_task_cache; static struct kmem_cache *sas_event_cache; -struct sas_task *sas_alloc_task(gfp_t flags) +struct sas_task *sas_alloc_slow_task(struct sas_ha_struct *sas_ha, gfp_t flags) { - struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags); + struct request *rq; + struct sas_task *task; + struct sas_task_slow *slow; + struct Scsi_Host *shost = sas_ha->core.shost; + struct scsi_cmnd *scmd; + struct scsi_device *sdev; - if (task) { - spin_lock_init(&task->task_state_lock); - task->task_state_flags = SAS_TASK_STATE_PENDING; - } + sdev = shost->sdev; - return task; -} -EXPORT_SYMBOL_GPL(sas_alloc_task); + rq = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, + BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT); -struct sas_task *sas_alloc_slow_task(gfp_t flags) -{ - struct sas_task *task = sas_alloc_task(flags); - struct sas_task_slow *slow = kmalloc(sizeof(*slow), flags); + if (IS_ERR(rq)) + return NULL; + + scmd = blk_mq_rq_to_pdu(rq); + task = sas_rq_to_task(rq); + + slow = kmalloc(sizeof(*slow), flags); if (!task || !slow) { - if (task) - kmem_cache_free(sas_task_cache, task); kfree(slow); return NULL; } @@ -53,17 +54,19 @@ struct sas_task *sas_alloc_slow_task(gfp_t flags) slow->task = task; timer_setup(&slow->timer, NULL, 0); init_completion(&slow->completion); - + scmd->host_scribble = NULL; return task; } EXPORT_SYMBOL_GPL(sas_alloc_slow_task); void sas_free_task(struct sas_task *task) { - if (task) { - kfree(task->slow_task); - kmem_cache_free(sas_task_cache, task); - } + struct request *rq = sas_rq_from_task(task); + + kfree(task->slow_task); + + if (blk_mq_is_reserved_rq(rq)) + blk_mq_free_request(rq); } EXPORT_SYMBOL_GPL(sas_free_task); @@ -95,6 +98,13 @@ void sas_hash_addr(u8 *hashed, const u8 *sas_addr) int sas_init_priv_cmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd) { + struct sas_task *task = sas_scmd_to_task(cmd); + + memset(task, 0, sizeof(*task)); + spin_lock_init(&task->task_state_lock); + task->task_state_flags = SAS_TASK_STATE_PENDING; + cmd->submitter = SUBMITTED_BY_BLOCK_LAYER; + return 0; } @@ -685,24 +695,18 @@ void sas_free_event(struct asd_sas_event *event) static int __init sas_class_init(void) { - sas_task_cache = KMEM_CACHE(sas_task, SLAB_HWCACHE_ALIGN); - if (!sas_task_cache) - goto out; - sas_event_cache = KMEM_CACHE(asd_sas_event, SLAB_HWCACHE_ALIGN); if (!sas_event_cache) goto free_task_kmem; return 0; free_task_kmem: - kmem_cache_destroy(sas_task_cache); -out: + return -ENOMEM; } static void __exit sas_class_exit(void) { - kmem_cache_destroy(sas_task_cache); kmem_cache_destroy(sas_event_cache); } diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 532e734c1fb6..3abb1d622a32 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -98,7 +98,7 @@ static void sas_end_task(struct scsi_cmnd *sc, struct sas_task *task) static void sas_scsi_task_done(struct sas_task *task) { - struct scsi_cmnd *sc = task->uldd_task; + struct scsi_cmnd *sc = sas_scmd_from_task(task); struct domain_device *dev = task->dev; struct sas_ha_struct *ha = dev->port->ha; unsigned long flags; @@ -130,13 +130,12 @@ static struct sas_task *sas_create_task(struct scsi_cmnd *cmd, struct domain_device *dev, gfp_t gfp_flags) { - struct sas_task *task = sas_alloc_task(gfp_flags); + struct sas_task *task = sas_scmd_to_task(cmd); struct scsi_lun lun; if (!task) return NULL; - task->uldd_task = cmd; ASSIGN_SAS_TASK(cmd, task); task->dev = dev; @@ -958,7 +957,7 @@ static int sas_execute_internal_abort(struct domain_device *device, int res, retry; for (retry = 0; retry < TASK_RETRY; retry++) { - task = sas_alloc_slow_task(GFP_KERNEL); + task = sas_alloc_slow_task(ha, GFP_KERNEL); if (!task) return -ENOMEM; @@ -1044,10 +1043,12 @@ int sas_execute_tmf(struct domain_device *device, void *parameter, struct sas_task *task; struct sas_internal *i = to_sas_internal(device->port->ha->core.shost->transportt); + struct sas_ha_struct *ha = device->port->ha; int res, retry; + for (retry = 0; retry < TASK_RETRY; retry++) { - task = sas_alloc_slow_task(GFP_KERNEL); + task = sas_alloc_slow_task(ha, GFP_KERNEL); if (!task) return -ENOMEM; @@ -1204,7 +1205,7 @@ int sas_query_task(struct sas_task *task, u16 tag) .tmf = TMF_QUERY_TASK, .tag_of_task_to_be_managed = tag, }; - struct scsi_cmnd *cmnd = task->uldd_task; + struct scsi_cmnd *cmnd = sas_scmd_from_task(task); struct domain_device *dev = task->dev; struct scsi_lun lun; @@ -1220,7 +1221,7 @@ int sas_abort_task(struct sas_task *task, u16 tag) .tmf = TMF_ABORT_TASK, .tag_of_task_to_be_managed = tag, }; - struct scsi_cmnd *cmnd = task->uldd_task; + struct scsi_cmnd *cmnd = sas_scmd_from_task(task); struct domain_device *dev = task->dev; struct scsi_lun lun; @@ -1236,7 +1237,7 @@ EXPORT_SYMBOL_GPL(sas_abort_task); */ void sas_task_abort(struct sas_task *task) { - struct scsi_cmnd *sc = task->uldd_task; + struct scsi_cmnd *sc = sas_scmd_from_task(task); /* Escape for libsas internal commands */ if (!sc) { diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index 92fc3e5ef297..024b4c4eec3b 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h @@ -639,8 +639,7 @@ struct sas_task_slow { #define SAS_TASK_STATE_ABORTED 4 #define SAS_TASK_NEED_DEV_RESET 8 -extern struct sas_task *sas_alloc_task(gfp_t flags); -extern struct sas_task *sas_alloc_slow_task(gfp_t flags); +extern struct sas_task *sas_alloc_slow_task(struct sas_ha_struct *, gfp_t flags); extern void sas_free_task(struct sas_task *task); static inline bool sas_is_internal_abort(struct sas_task *task) @@ -766,10 +765,24 @@ static inline struct sas_task *sas_rq_to_task(struct request *rq) return (struct sas_task *)(scmd + 1); } +static inline struct request *sas_rq_from_task(void *task) +{ + struct scsi_cmnd *scmd = task - sizeof(*scmd); + + return blk_mq_rq_from_pdu(scmd); +} + static inline struct scsi_cmnd *sas_scmd_from_task(void *task) { struct scsi_cmnd *scmd = task - sizeof(*scmd); return scmd; } + +static inline struct sas_task *sas_scmd_to_task(struct scsi_cmnd *scmd) +{ + struct request *rq = blk_mq_rq_from_pdu(scmd); + return sas_rq_to_task(rq); +} + #endif /* _SASLIB_H_ */ From patchwork Thu Jun 9 10:29:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580545 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 21412CCA480 for ; Thu, 9 Jun 2022 10:37:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243153AbiFIKh0 (ORCPT ); Thu, 9 Jun 2022 06:37:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243156AbiFIKhD (ORCPT ); Thu, 9 Jun 2022 06:37:03 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B1DA217601; Thu, 9 Jun 2022 03:36:44 -0700 (PDT) Received: from fraeml706-chm.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgR84zmYz67yc5; Thu, 9 Jun 2022 18:33:08 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml706-chm.china.huawei.com (10.206.15.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Thu, 9 Jun 2022 12:36:42 +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:39 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 14/18] scsi: libsas: Queue SMP commands as requests Date: Thu, 9 Jun 2022 18:29:15 +0800 Message-ID: <1654770559-101375-15-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 Send SMP commands through the block layer so that each command gets a unique tag associated. In future we can now also take advantage of the block layer request timeout handling. Function sas_task_complete_internal() is what the LLDD calls to signal that the CQ is complete and this calls into the SCSI midlayer. And then sas_blk_end_sync_rq() is called when the request completes. Signed-off-by: John Garry --- drivers/scsi/libsas/sas_expander.c | 13 +++---------- drivers/scsi/libsas/sas_internal.h | 3 +++ drivers/scsi/libsas/sas_scsi_host.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index b833de062f88..d0bf63286b7d 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -66,20 +66,13 @@ static int smp_execute_task_sg(struct domain_device *dev, task->task_proto = dev->tproto; task->smp_task.smp_req = *req; task->smp_task.smp_resp = *resp; - - task->task_done = sas_task_internal_done; + task->task_done = sas_task_complete_internal; task->slow_task->timer.function = sas_task_internal_timedout; task->slow_task->timer.expires = jiffies + SMP_TIMEOUT*HZ; add_timer(&task->slow_task->timer); - - res = i->dft->lldd_execute_task(task, GFP_KERNEL); - - if (res) { - del_timer(&task->slow_task->timer); - pr_notice("executing SMP task failed:%d\n", res); - break; - } + rq->end_io = sas_blk_end_sync_rq; + blk_execute_rq_nowait(rq, true); wait_for_completion(&task->slow_task->completion); res = -ECOMM; diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h index 13d0ffaada93..52cfa75d432b 100644 --- a/drivers/scsi/libsas/sas_internal.h +++ b/drivers/scsi/libsas/sas_internal.h @@ -99,6 +99,9 @@ int sas_execute_tmf(struct domain_device *device, void *parameter, int para_len, int force_phy_id, struct sas_tmf_task *tmf); +void sas_task_complete_internal(struct sas_task *task); +void sas_blk_end_sync_rq(struct request *rq, blk_status_t error); + #ifdef CONFIG_SCSI_SAS_HOST_SMP extern void sas_smp_host_handler(struct bsg_job *job, struct Scsi_Host *shost); #else diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 3abb1d622a32..f0566f4512b2 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -926,6 +926,16 @@ void sas_task_internal_done(struct sas_task *task) complete(&task->slow_task->completion); } +void sas_task_complete_internal(struct sas_task *task) +{ + struct request *rq = sas_rq_from_task(task); + struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq); + + del_timer(&task->slow_task->timer); + + scsi_done(scmd); +} + void sas_task_internal_timedout(struct timer_list *t) { struct sas_task_slow *slow = from_timer(slow, t, timer); @@ -947,6 +957,12 @@ void sas_task_internal_timedout(struct timer_list *t) #define TASK_TIMEOUT (20 * HZ) #define TASK_RETRY 3 +void sas_blk_end_sync_rq(struct request *rq, blk_status_t error) +{ + struct sas_task *task = sas_rq_to_task(rq); + complete(&task->slow_task->completion); +} + static int sas_execute_internal_abort(struct domain_device *device, enum sas_internal_abort type, u16 tag, unsigned int qid, void *data) From patchwork Thu Jun 9 10:29:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580543 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 9F44ECCA47E for ; Thu, 9 Jun 2022 10:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243296AbiFIKiH (ORCPT ); Thu, 9 Jun 2022 06:38:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243062AbiFIKhM (ORCPT ); Thu, 9 Jun 2022 06:37:12 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59AD2178B4; Thu, 9 Jun 2022 03:36:47 -0700 (PDT) Received: from fraeml705-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgTr1tZMz67cT1; Thu, 9 Jun 2022 18:35:28 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml705-chm.china.huawei.com (10.206.15.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Thu, 9 Jun 2022 12:36:45 +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:42 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 15/18] scsi: libsas: Queue TMF commands as requests Date: Thu, 9 Jun 2022 18:29:16 +0800 Message-ID: <1654770559-101375-16-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 Like what we did with SMP commands, send TMF commands through the block layer. In future we can now also take advantage of the block layer request timeout handling. Signed-off-by: John Garry --- drivers/scsi/libsas/sas_scsi_host.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index f0566f4512b2..520c301e4319 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -1059,18 +1059,27 @@ int sas_execute_tmf(struct domain_device *device, void *parameter, struct sas_task *task; struct sas_internal *i = to_sas_internal(device->port->ha->core.shost->transportt); - struct sas_ha_struct *ha = device->port->ha; int res, retry; - + struct request *rq; + struct sas_ha_struct *ha = device->port->ha; for (retry = 0; retry < TASK_RETRY; retry++) { + struct scsi_cmnd *scmd; + task = sas_alloc_slow_task(ha, GFP_KERNEL); - if (!task) - return -ENOMEM; + if (!task) { + res = -ENOMEM; + break; + } task->dev = device; task->task_proto = device->tproto; + rq = sas_rq_from_task(task); + + scmd = blk_mq_rq_to_pdu(rq); + ASSIGN_SAS_TASK(scmd, task); + if (dev_is_sata(device)) { task->ata_task.device_control_reg_update = 1; if (force_phy_id >= 0) { @@ -1082,20 +1091,15 @@ int sas_execute_tmf(struct domain_device *device, void *parameter, memcpy(&task->ssp_task, parameter, para_len); } - task->task_done = sas_task_internal_done; + task->task_done = sas_task_complete_internal; task->tmf = tmf; task->slow_task->timer.function = sas_task_internal_timedout; task->slow_task->timer.expires = jiffies + TASK_TIMEOUT; add_timer(&task->slow_task->timer); - res = i->dft->lldd_execute_task(task, GFP_KERNEL); - if (res) { - del_timer_sync(&task->slow_task->timer); - pr_err("executing TMF task failed %016llx (%d)\n", - SAS_ADDR(device->sas_addr), res); - break; - } + rq->end_io = sas_blk_end_sync_rq; + blk_execute_rq_nowait(rq, true); wait_for_completion(&task->slow_task->completion); From patchwork Thu Jun 9 10:29:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 581378 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 12190C43334 for ; Thu, 9 Jun 2022 10:38:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243335AbiFIKiI (ORCPT ); Thu, 9 Jun 2022 06:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243077AbiFIKhQ (ORCPT ); Thu, 9 Jun 2022 06:37:16 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C44D8211133; Thu, 9 Jun 2022 03:36:50 -0700 (PDT) Received: from fraeml704-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgRH0tBwz67ycH; Thu, 9 Jun 2022 18:33:15 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml704-chm.china.huawei.com (10.206.15.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Thu, 9 Jun 2022 12:36:48 +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:45 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 16/18] scsi: core: Add scsi_alloc_request_hwq() Date: Thu, 9 Jun 2022 18:29:17 +0800 Message-ID: <1654770559-101375-17-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 variant of scsi_alloc_request() which allocates a request for a specific hw queue. Signed-off-by: John Garry --- drivers/scsi/scsi_lib.c | 12 ++++++++++++ include/scsi/scsi_cmnd.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 8c8b4c6767d9..443afaf52c14 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1137,6 +1137,18 @@ struct request *scsi_alloc_request(struct request_queue *q, } EXPORT_SYMBOL_GPL(scsi_alloc_request); +struct request *scsi_alloc_request_hwq(struct request_queue *q, + unsigned int op, blk_mq_req_flags_t flags, unsigned int hwq) +{ + struct request *rq; + + rq = blk_mq_alloc_request_hctx(q, op, flags, hwq); + if (!IS_ERR(rq)) + scsi_initialize_rq(rq); + return rq; +} +EXPORT_SYMBOL_GPL(scsi_alloc_request_hwq); + /* * Only called when the request isn't completed by SCSI, and not freed by * SCSI diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index e47df5836070..e69bb6baad47 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -394,4 +394,7 @@ extern void scsi_build_sense(struct scsi_cmnd *scmd, int desc, struct request *scsi_alloc_request(struct request_queue *q, unsigned int op, blk_mq_req_flags_t flags); +struct request *scsi_alloc_request_hwq(struct request_queue *q, + unsigned int op, blk_mq_req_flags_t flags, unsigned int hwq); + #endif /* _SCSI_SCSI_CMND_H */ From patchwork Thu Jun 9 10:29:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 580542 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 EBA0FCCA473 for ; Thu, 9 Jun 2022 10:38:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243353AbiFIKiJ (ORCPT ); Thu, 9 Jun 2022 06:38:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243175AbiFIKhT (ORCPT ); Thu, 9 Jun 2022 06:37:19 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C5072132AB; Thu, 9 Jun 2022 03:36:54 -0700 (PDT) Received: from fraeml703-chm.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgRL3bLtz67ClN; Thu, 9 Jun 2022 18:33:18 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml703-chm.china.huawei.com (10.206.15.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Thu, 9 Jun 2022 12:36:51 +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:48 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 17/18] scsi: libsas: Queue internal abort commands as requests Date: Thu, 9 Jun 2022 18:29:18 +0800 Message-ID: <1654770559-101375-18-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 Like what we did for SMP commands, send internal abort commands through the block layer. In future we can now also take advantage of the block layer request timeout handling. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 4 +--- drivers/scsi/libsas/sas_init.c | 19 ++++++++++++++---- drivers/scsi/libsas/sas_internal.h | 3 +++ drivers/scsi/libsas/sas_scsi_host.c | 28 +++++++++++++++------------ include/scsi/libsas.h | 16 ++++++++++++++- 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 2c5c6301f224..50ca7d63ab58 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -554,13 +554,11 @@ static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) if (test_bit(HISI_SAS_HW_FAULT_BIT, &hisi_hba->flags)) return -EIO; - hisi_hba = dev_to_hisi_hba(device); - if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) return -EINVAL; port = to_hisi_sas_port(sas_port); - dq = &hisi_hba->dq[task->abort_task.qid]; + dq = &hisi_hba->dq[sas_task_to_hwq(task)]; break; default: dev_err(hisi_hba->dev, "task prep: unknown/unsupported proto (0x%x)\n", diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c index 8d03b8abcaa3..1224ad2b44ce 100644 --- a/drivers/scsi/libsas/sas_init.c +++ b/drivers/scsi/libsas/sas_init.c @@ -23,7 +23,8 @@ static struct kmem_cache *sas_event_cache; -struct sas_task *sas_alloc_slow_task(struct sas_ha_struct *sas_ha, gfp_t flags) +struct sas_task *sas_alloc_slow_task_qid(struct sas_ha_struct *sas_ha, + gfp_t flags, unsigned int qid) { struct request *rq; struct sas_task *task; @@ -34,9 +35,14 @@ struct sas_task *sas_alloc_slow_task(struct sas_ha_struct *sas_ha, gfp_t flags) sdev = shost->sdev; - rq = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, - BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT); - + if (qid == -1U) { + rq = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, + BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT); + } else { + rq = scsi_alloc_request_hwq(sdev->request_queue, REQ_OP_DRV_IN, + BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT, + qid); + } if (IS_ERR(rq)) return NULL; @@ -57,6 +63,11 @@ struct sas_task *sas_alloc_slow_task(struct sas_ha_struct *sas_ha, gfp_t flags) scmd->host_scribble = NULL; return task; } + +struct sas_task *sas_alloc_slow_task(struct sas_ha_struct *sas_ha, gfp_t flags) +{ + return sas_alloc_slow_task_qid(sas_ha, flags, -1U); +} EXPORT_SYMBOL_GPL(sas_alloc_slow_task); void sas_free_task(struct sas_task *task) diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h index 52cfa75d432b..eb70cc0d04fe 100644 --- a/drivers/scsi/libsas/sas_internal.h +++ b/drivers/scsi/libsas/sas_internal.h @@ -102,6 +102,9 @@ int sas_execute_tmf(struct domain_device *device, void *parameter, void sas_task_complete_internal(struct sas_task *task); void sas_blk_end_sync_rq(struct request *rq, blk_status_t error); +struct sas_task *sas_alloc_slow_task_qid(struct sas_ha_struct *sas_ha, + gfp_t flags, unsigned int qid); + #ifdef CONFIG_SCSI_SAS_HOST_SMP extern void sas_smp_host_handler(struct bsg_job *job, struct Scsi_Host *shost); #else diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c index 520c301e4319..3c62a104f049 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -973,28 +973,32 @@ static int sas_execute_internal_abort(struct domain_device *device, int res, retry; for (retry = 0; retry < TASK_RETRY; retry++) { - task = sas_alloc_slow_task(ha, GFP_KERNEL); - if (!task) - return -ENOMEM; + struct scsi_cmnd *scmd; + struct request *rq; + + task = sas_alloc_slow_task_qid(ha, GFP_KERNEL, qid); + if (!task) { + res = -ENOMEM; + break; + } task->dev = device; task->task_proto = SAS_PROTOCOL_INTERNAL_ABORT; - task->task_done = sas_task_internal_done; + task->task_done = sas_task_complete_internal; task->slow_task->timer.function = sas_task_internal_timedout; task->slow_task->timer.expires = jiffies + TASK_TIMEOUT; add_timer(&task->slow_task->timer); task->abort_task.tag = tag; task->abort_task.type = type; - task->abort_task.qid = qid; - res = i->dft->lldd_execute_task(task, GFP_KERNEL); - if (res) { - del_timer_sync(&task->slow_task->timer); - pr_err("Executing internal abort failed %016llx (%d)\n", - SAS_ADDR(device->sas_addr), res); - break; - } + rq = sas_rq_from_task(task); + + scmd = blk_mq_rq_to_pdu(rq); + ASSIGN_SAS_TASK(scmd, task); + + rq->end_io = sas_blk_end_sync_rq; + blk_execute_rq_nowait(rq, true); wait_for_completion(&task->slow_task->completion); res = TMF_RESP_FUNC_FAILED; diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index 024b4c4eec3b..62acbc8a46fd 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h @@ -565,7 +565,6 @@ enum sas_internal_abort { struct sas_internal_abort_task { enum sas_internal_abort type; - unsigned int qid; u16 tag; }; @@ -785,4 +784,19 @@ static inline struct sas_task *sas_scmd_to_task(struct scsi_cmnd *scmd) return sas_rq_to_task(rq); } +static inline u32 sas_task_to_rq_unique_tag(struct sas_task *task) +{ + struct request *rq = sas_rq_from_task(task); + + return blk_mq_unique_tag(rq); +} + +static inline unsigned int sas_task_to_hwq(struct sas_task *task) +{ + u32 unique = sas_task_to_rq_unique_tag(task); + + return blk_mq_unique_tag_to_hwq(unique); +} + + #endif /* _SASLIB_H_ */ From patchwork Thu Jun 9 10:29:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 581377 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 9A38FCCA473 for ; Thu, 9 Jun 2022 10:38:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243125AbiFIKiV (ORCPT ); Thu, 9 Jun 2022 06:38:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243194AbiFIKhT (ORCPT ); Thu, 9 Jun 2022 06:37:19 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57262213ADC; Thu, 9 Jun 2022 03:36:57 -0700 (PDT) Received: from fraeml702-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LJgPz3D4hz683T0; Thu, 9 Jun 2022 18:32:07 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml702-chm.china.huawei.com (10.206.15.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.24; Thu, 9 Jun 2022 12:36:55 +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:51 +0100 From: John Garry To: , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v2 18/18] scsi: libsas drivers: Remove private tag management Date: Thu, 9 Jun 2022 18:29:19 +0800 Message-ID: <1654770559-101375-19-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 Now every sas_task which the driver sees has a SCSI command and also request associated, so drop the internal tag management. For now we are only fixing up hisi_sas v2 HW, but all others need this. Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_main.c | 74 +++----------------------- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 3 +- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 3 +- drivers/scsi/libsas/sas_ata.c | 5 +- include/scsi/libsas.h | 8 ++- 5 files changed, 19 insertions(+), 74 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index 50ca7d63ab58..e487a6e6fe7e 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -169,41 +169,6 @@ static void hisi_sas_slot_index_free(struct hisi_hba *hisi_hba, int slot_idx) } } -static void hisi_sas_slot_index_set(struct hisi_hba *hisi_hba, int slot_idx) -{ - void *bitmap = hisi_hba->slot_index_tags; - - __set_bit(slot_idx, bitmap); -} - -static int hisi_sas_slot_index_alloc(struct hisi_hba *hisi_hba, - struct scsi_cmnd *scsi_cmnd) -{ - int index; - void *bitmap = hisi_hba->slot_index_tags; - - if (scsi_cmnd) - return scsi_cmd_to_rq(scsi_cmnd)->tag; - - spin_lock(&hisi_hba->lock); - index = find_next_zero_bit(bitmap, hisi_hba->slot_index_count, - hisi_hba->last_slot_index + 1); - if (index >= hisi_hba->slot_index_count) { - index = find_next_zero_bit(bitmap, - hisi_hba->slot_index_count, - HISI_SAS_UNRESERVED_IPTT); - if (index >= hisi_hba->slot_index_count) { - spin_unlock(&hisi_hba->lock); - return -SAS_QUEUE_FULL; - } - } - hisi_sas_slot_index_set(hisi_hba, index); - hisi_hba->last_slot_index = index; - spin_unlock(&hisi_hba->lock); - - return index; -} - void hisi_sas_slot_task_free(struct hisi_hba *hisi_hba, struct sas_task *task, struct hisi_sas_slot *slot) { @@ -458,18 +423,17 @@ void hisi_sas_task_deliver(struct hisi_hba *hisi_hba, static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) { int n_elem = 0, n_elem_dif = 0, n_elem_req = 0; + struct scsi_cmnd *scmd = sas_scmd_from_task(task); struct domain_device *device = task->dev; struct asd_sas_port *sas_port = device->port; struct hisi_sas_device *sas_dev = device->lldd_dev; bool internal_abort = sas_is_internal_abort(task); - struct scsi_cmnd *scmd = NULL; struct hisi_sas_dq *dq = NULL; struct hisi_sas_port *port; struct hisi_hba *hisi_hba; struct hisi_sas_slot *slot; struct device *dev; int rc; - if (!sas_port) { struct task_status_struct *ts = &task->task_status; @@ -487,6 +451,8 @@ static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) hisi_hba = dev_to_hisi_hba(device); dev = hisi_hba->dev; + dq = &hisi_hba->dq[sas_task_to_hwq(task)]; + switch (task->task_proto) { case SAS_PROTOCOL_SSP: case SAS_PROTOCOL_SMP: @@ -521,31 +487,6 @@ static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) return -ECOMM; } - if (task->uldd_task) { - struct ata_queued_cmd *qc; - - if (dev_is_sata(device)) { - qc = task->uldd_task; - scmd = qc->scsicmd; - } else { - scmd = task->uldd_task; - } - } - - if (scmd) { - unsigned int dq_index; - u32 blk_tag; - - blk_tag = blk_mq_unique_tag(scsi_cmd_to_rq(scmd)); - dq_index = blk_mq_unique_tag_to_hwq(blk_tag); - dq = &hisi_hba->dq[dq_index]; - } else { - struct Scsi_Host *shost = hisi_hba->shost; - struct blk_mq_queue_map *qmap = &shost->tag_set.map[HCTX_TYPE_DEFAULT]; - int queue = qmap->mq_map[raw_smp_processor_id()]; - - dq = &hisi_hba->dq[queue]; - } break; case SAS_PROTOCOL_INTERNAL_ABORT: if (!hisi_hba->hw->prep_abort) @@ -556,9 +497,6 @@ static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) if (unlikely(test_bit(HISI_SAS_REJECT_CMD_BIT, &hisi_hba->flags))) return -EINVAL; - - port = to_hisi_sas_port(sas_port); - dq = &hisi_hba->dq[sas_task_to_hwq(task)]; break; default: dev_err(hisi_hba->dev, "task prep: unknown/unsupported proto (0x%x)\n", @@ -577,10 +515,12 @@ static int hisi_sas_queue_command(struct sas_task *task, gfp_t gfp_flags) goto err_out_dma_unmap; } - if (!internal_abort && hisi_hba->hw->slot_index_alloc) + if (scsi_is_reserved_cmd(scmd)) + rc = sas_task_to_unique_tag(task); + else if (hisi_hba->hw->slot_index_alloc) rc = hisi_hba->hw->slot_index_alloc(hisi_hba, device); else - rc = hisi_sas_slot_index_alloc(hisi_hba, scmd); + rc = sas_task_to_unique_tag(task); if (rc < 0) goto err_out_dif_dma_unmap; diff --git a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c index a1e60d2ef070..c2af2adf75c3 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v2_hw.c @@ -2493,6 +2493,7 @@ static void prep_ata_v2_hw(struct hisi_hba *hisi_hba, struct hisi_sas_port *port = to_hisi_sas_port(sas_port); struct sas_ata_task *ata_task = &task->ata_task; struct sas_tmf_task *tmf = slot->tmf; + struct scsi_cmnd *scmd = sas_scmd_from_task(task); u8 *buf_cmd; int has_data = 0, hdr_tag = 0; u32 dw0, dw1 = 0, dw2 = 0; @@ -2538,7 +2539,7 @@ static void prep_ata_v2_hw(struct hisi_hba *hisi_hba, /* dw2 */ if (task->ata_task.use_ncq) { - struct ata_queued_cmd *qc = task->uldd_task; + struct ata_queued_cmd *qc = (struct ata_queued_cmd *)scmd->host_scribble; hdr_tag = qc->tag; task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3); diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 7d819fc0395e..6a76cc2e34af 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -1382,6 +1382,7 @@ static void prep_ata_v3_hw(struct hisi_hba *hisi_hba, struct hisi_sas_cmd_hdr *hdr = slot->cmd_hdr; struct asd_sas_port *sas_port = device->port; struct hisi_sas_port *port = to_hisi_sas_port(sas_port); + struct scsi_cmnd *scmd = sas_scmd_from_task(task); u8 *buf_cmd; int has_data = 0, hdr_tag = 0; u32 dw1 = 0, dw2 = 0; @@ -1421,7 +1422,7 @@ static void prep_ata_v3_hw(struct hisi_hba *hisi_hba, /* dw2 */ if (task->ata_task.use_ncq) { - struct ata_queued_cmd *qc = task->uldd_task; + struct ata_queued_cmd *qc = (struct ata_queued_cmd *)scmd->host_scribble; hdr_tag = qc->tag; task->ata_task.fis.sector_count |= (u8) (hdr_tag << 3); diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index 66534332e9ac..6ebcabdf0c01 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -188,7 +188,6 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) qc->tf.nsect = 0; ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, (u8 *)&task->ata_task.fis); - task->uldd_task = qc; if (ata_is_atapi(qc->tf.protocol)) { memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len); task->total_xfer_len = qc->nbytes; @@ -211,8 +210,7 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc) task->ata_task.use_ncq = ata_is_ncq(qc->tf.protocol); task->ata_task.dma_xfer = ata_is_dma(qc->tf.protocol); - if (qc->scsicmd) - ASSIGN_SAS_TASK(qc->scsicmd, task); + ASSIGN_SAS_TASK(qc->scsicmd, qc); ret = i->dft->lldd_execute_task(task, GFP_ATOMIC); if (ret) { @@ -473,7 +471,6 @@ static void sas_ata_post_internal(struct ata_queued_cmd *qc) qc->lldd_task = NULL; if (!task) return; - task->uldd_task = NULL; sas_ata_internal_abort(task); } } diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h index 62acbc8a46fd..3dd4d9c47b2b 100644 --- a/include/scsi/libsas.h +++ b/include/scsi/libsas.h @@ -619,7 +619,6 @@ struct sas_task { void (*task_done)(struct sas_task *); void *lldd_task; /* for use by LLDDs */ - void *uldd_task; struct sas_task_slow *slow_task; struct sas_tmf_task *tmf; }; @@ -798,5 +797,12 @@ static inline unsigned int sas_task_to_hwq(struct sas_task *task) return blk_mq_unique_tag_to_hwq(unique); } +static inline unsigned int sas_task_to_unique_tag(struct sas_task *task) +{ + u32 unique = sas_task_to_rq_unique_tag(task); + + return blk_mq_unique_tag_to_tag(unique); + +} #endif /* _SASLIB_H_ */