From patchwork Tue Oct 25 10:18: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: 10680 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp908585wru; Tue, 25 Oct 2022 02:54:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5laMVpTAcJ+fjOTjnWiIp7+ggusCacb3rxBHD+mRwDOVUOcDaYTrCylZh+m58dKq+nf6Gm X-Received: by 2002:a17:90a:6045:b0:212:fe9a:5792 with SMTP id h5-20020a17090a604500b00212fe9a5792mr13486069pjm.178.1666691672463; Tue, 25 Oct 2022 02:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666691672; cv=none; d=google.com; s=arc-20160816; b=Zsd8iy3VRtXYIdzNb5VqnjycMYtz4Lope4fu3Bp3cE34t9B4hGpKi8sO2NixAXnilQ u+Tpq1wQPoKzMSDYyTZ1Zr/swkFLUmYdu+U8f4oq0K5Axt0K4zjL3RFdKyVkx8QoTK+g 821z4XFDeuGXTgdzcepv2ysAgkxAfmRdKpuSdNXwuYkZ3TGu4mFudK9hU+uN4syKR+Iy hY2uiCeJE0QyQIreRfjY9qRnykd1dqQe4oJDRsPvfHHvGACbuvTo2/7XpJpGIoF+8Cxa mip/hiwJMIq3gMYOl2gbFIw8K8rkr4YRESgj1YxXT4UGTV5+t7olymPjbOCfaxzzWvgR uoXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Lo6zYqPhMQ07Vpmhe8dtf/zkjp5cO9c5LB7JbQ3L0G8=; b=JMRquwuwYd1kW+YtfpwazkYduxIac22k6QtLdctRPRhvd7/RDhHIIsGyYYWUIuncF7 uPQpbVvtdm/yaEVY2rLelP3MBO5N2c30MpnM3fTQINrxK+st3uNqmdS7PINSpZaCWN14 0ql80njUKq2SHPs7AHORWOi+SWknRN7P7znuXWukN3GqtldrHGC8c2ERCL6JvYQQu+JW W7nnHYRfYksWCQzfYaBfZW4tc0nu+gFJJF8yJLI8Lm3ov1hpQqQ3mE3bCUhi3GbEuH0y oVHQ219UmW7prxXu+RRDsHWnEXsQAJQyW5qR+YRLhbONvcLQmms3+bFBXU+aI4g4a1wR hwaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p21-20020a631e55000000b00439ae523fd2si2635637pgm.289.2022.10.25.02.54.18; Tue, 25 Oct 2022 02:54:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231591AbiJYJxX (ORCPT + 99 others); Tue, 25 Oct 2022 05:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231946AbiJYJvj (ORCPT ); Tue, 25 Oct 2022 05:51:39 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E8F516CA5A; Tue, 25 Oct 2022 02:49:13 -0700 (PDT) Received: from frapeml100001.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4MxRrj0JLXz686Kq; Tue, 25 Oct 2022 17:45:41 +0800 (CST) Received: from lhrpeml500003.china.huawei.com (7.191.162.67) by frapeml100001.china.huawei.com (7.182.85.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 11:49:10 +0200 Received: from localhost.localdomain (10.69.192.58) by lhrpeml500003.china.huawei.com (7.191.162.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 25 Oct 2022 10:49:06 +0100 From: John Garry To: , , , , , , , , , CC: , , , , , John Garry Subject: [PATCH RFC v3 18/22] scsi: libsas: Queue SMP commands as requests Date: Tue, 25 Oct 2022 18:18:12 +0800 Message-ID: <1666693096-180008-19-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1666693096-180008-1-git-send-email-john.garry@huawei.com> References: <1666693096-180008-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To lhrpeml500003.china.huawei.com (7.191.162.67) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747652887225550063?= X-GMAIL-MSGID: =?utf-8?q?1747652887225550063?= Send SMP commands through the block layer so that each command gets a unique tag associated. 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 | 23 ++++++++--------------- drivers/scsi/libsas/sas_init.c | 3 +++ drivers/scsi/libsas/sas_internal.h | 3 +++ drivers/scsi/libsas/sas_scsi_host.c | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c index e7cb95683522..cc41127ea5cc 100644 --- a/drivers/scsi/libsas/sas_expander.c +++ b/drivers/scsi/libsas/sas_expander.c @@ -43,34 +43,27 @@ static int smp_execute_task_sg(struct domain_device *dev, pm_runtime_get_sync(ha->dev); mutex_lock(&dev->ex_dev.cmd_mutex); for (retry = 0; retry < 3; retry++) { + struct request *rq; + if (test_bit(SAS_DEV_GONE, &dev->state)) { res = -ECOMM; break; } - task = sas_alloc_slow_task(GFP_KERNEL); + task = sas_alloc_slow_task_rq(dev, GFP_KERNEL); if (!task) { res = -ENOMEM; break; } - task->dev = dev; + + rq = scsi_cmd_to_rq(task->uldd_task); + rq->timeout = SMP_TIMEOUT*HZ; + 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->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_sync(&task->slow_task->timer); - pr_notice("executing SMP task failed:%d\n", res); - break; - } + blk_execute_rq_nowait(rq, true); wait_for_completion(&task->slow_task->completion); res = -ECOMM; diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c index 90e63ff5e966..5f9e71a54799 100644 --- a/drivers/scsi/libsas/sas_init.c +++ b/drivers/scsi/libsas/sas_init.c @@ -84,6 +84,7 @@ struct sas_task *sas_alloc_slow_task_rq(struct domain_device *device, gfp_t flag return NULL; task->dev = device; + task->task_done = sas_task_complete_internal; rq = scsi_alloc_request(sdev->request_queue, REQ_OP_DRV_IN, BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT); @@ -95,6 +96,8 @@ struct sas_task *sas_alloc_slow_task_rq(struct domain_device *device, gfp_t flag scmd = blk_mq_rq_to_pdu(rq); task->uldd_task = scmd; + + rq->end_io = sas_blk_end_sync_rq; rq->end_io_data = task; return task; diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h index f5ae4de382f7..9b58948c57c2 100644 --- a/drivers/scsi/libsas/sas_internal.h +++ b/drivers/scsi/libsas/sas_internal.h @@ -104,6 +104,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); +enum rq_end_io_ret 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 b7d1994a8f1b..2c734a87bb7c 100644 --- a/drivers/scsi/libsas/sas_scsi_host.c +++ b/drivers/scsi/libsas/sas_scsi_host.c @@ -913,6 +913,13 @@ void sas_task_internal_done(struct sas_task *task) complete(&task->slow_task->completion); } +void sas_task_complete_internal(struct sas_task *task) +{ + struct scsi_cmnd *scmd = task->uldd_task; + + scsi_done(scmd); +} + void sas_task_internal_timedout(struct timer_list *t) { struct sas_task_slow *slow = from_timer(slow, t, timer); @@ -952,6 +959,15 @@ EXPORT_SYMBOL_GPL(sas_internal_timeout); #define TASK_TIMEOUT (20 * HZ) #define TASK_RETRY 3 +enum rq_end_io_ret sas_blk_end_sync_rq(struct request *rq, blk_status_t error) +{ + struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq); + struct sas_task *task = TO_SAS_TASK(scmd); + complete(&task->slow_task->completion); + + return RQ_END_IO_NONE; +} + static int sas_execute_internal_abort(struct domain_device *device, enum sas_internal_abort type, u16 tag, unsigned int qid, void *data)