From: John Garry <john.garry@huawei.com>
To: <axboe@kernel.dk>, <damien.lemoal@opensource.wdc.com>,
<bvanassche@acm.org>, <jejb@linux.ibm.com>,
<martin.petersen@oracle.com>, <hch@lst.de>, <ming.lei@redhat.com>,
<hare@suse.de>
Cc: <chenxiang66@hisilicon.com>, <linux-block@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-ide@vger.kernel.org>,
<linux-scsi@vger.kernel.org>, <dm-devel@redhat.com>,
<beanhuo@micron.com>, John Garry <john.garry@huawei.com>
Subject: [PATCH 04/11] scsi: libsas: Send SMP commands through the block layer
Date: Tue, 22 Mar 2022 18:39:38 +0800 [thread overview]
Message-ID: <1647945585-197349-5-git-send-email-john.garry@huawei.com> (raw)
In-Reply-To: <1647945585-197349-1-git-send-email-john.garry@huawei.com>
Send SMP commands through the block layer so that each command gets a
unique tag associated.
We can now also take advantage of the block layer request timeout handling.
Signed-off-by: John Garry <john.garry@huawei.com>
---
drivers/scsi/libsas/sas_expander.c | 38 +++++++++++++++------
drivers/scsi/libsas/sas_internal.h | 1 +
drivers/scsi/libsas/sas_scsi_host.c | 53 +++++++++++++++++++++++++++++
3 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 260e735d06fa..bd25b00912ac 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -39,10 +39,19 @@ 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 Scsi_Host *shost = ha->core.shost;
+ struct request_queue *request_queue;
+ struct request *rq;
+
+ request_queue = sas_alloc_request_queue(shost);
+ if (IS_ERR(request_queue))
+ return PTR_ERR(request_queue);
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;
@@ -53,26 +62,30 @@ static int smp_execute_task_sg(struct domain_device *dev,
res = -ENOMEM;
break;
}
+
+ rq = scsi_alloc_request(request_queue, REQ_OP_DRV_IN, 0);
+ if (IS_ERR(rq)) {
+ res = PTR_ERR(rq);
+ break;
+ }
+
+ scmd = blk_mq_rq_to_pdu(rq);
+ scmd->submitter = SUBMITTED_BY_SCSI_CUSTOM_OPS;
+ ASSIGN_SAS_TASK(scmd, task);
+
task->dev = dev;
+ task->uldd_task = scmd;
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);
+ rq->timeout = SMP_TIMEOUT*HZ;
- 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;
- }
+ blk_execute_rq_nowait(rq, true, NULL);
wait_for_completion(&task->slow_task->completion);
+ __blk_mq_end_request(rq, BLK_STS_OK);
res = -ECOMM;
if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
pr_notice("smp task timed out or aborted\n");
@@ -117,6 +130,9 @@ static int smp_execute_task_sg(struct domain_device *dev,
BUG_ON(retry == 3 && task != NULL);
sas_free_task(task);
+
+ blk_cleanup_queue(request_queue);
+
return res;
}
diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
index 13d0ffaada93..ca2bace16953 100644
--- a/drivers/scsi/libsas/sas_internal.h
+++ b/drivers/scsi/libsas/sas_internal.h
@@ -95,6 +95,7 @@ extern const work_func_t sas_port_event_fns[PORT_NUM_EVENTS];
void sas_task_internal_done(struct sas_task *task);
void sas_task_internal_timedout(struct timer_list *t);
+struct request_queue *sas_alloc_request_queue(struct Scsi_Host *shost);
int sas_execute_tmf(struct domain_device *device, void *parameter,
int para_len, int force_phy_id,
struct sas_tmf_task *tmf);
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 9c82e5dc4fcc..91133ad37ae8 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -920,6 +920,59 @@ void sas_task_internal_timedout(struct timer_list *t)
#define TASK_TIMEOUT (20 * HZ)
#define TASK_RETRY 3
+static enum blk_eh_timer_return sas_task_timedout(struct request *rq, bool resv)
+{
+ struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
+ struct sas_task *task = TO_SAS_TASK(scmd);
+ bool is_completed = true;
+ unsigned long flags;
+
+ spin_lock_irqsave(&task->task_state_lock, flags);
+ if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
+ task->task_state_flags |= SAS_TASK_STATE_ABORTED;
+ is_completed = false;
+ }
+ spin_unlock_irqrestore(&task->task_state_lock, flags);
+
+ if (!is_completed)
+ complete(&task->slow_task->completion);
+ return BLK_EH_DONE;
+}
+
+static blk_status_t sas_exec_rq(struct blk_mq_hw_ctx *hctx,
+ const struct blk_mq_queue_data *bd)
+{
+ struct request *rq = bd->rq;
+ struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
+ struct sas_task *task = (struct sas_task *)scmd->host_scribble;
+ struct domain_device *device = task->dev;
+ struct sas_ha_struct *ha = device->port->ha;
+ struct sas_internal *i = to_sas_internal(ha->core.shost->transportt);
+ int res;
+
+ blk_mq_start_request(bd->rq);
+
+ res = i->dft->lldd_execute_task(task, GFP_KERNEL);
+ if (res) {
+ pr_notice("executing task proto 0x%x failed:%d\n", task->task_proto, res);
+ task->task_status.resp = SAS_TASK_UNDELIVERED;
+ task->task_status.stat = SAS_DEVICE_UNKNOWN;
+ complete(&task->slow_task->completion);
+ }
+
+ return BLK_STS_OK;
+}
+
+static const struct blk_mq_ops sas_blk_mq_ops = {
+ .queue_rq = sas_exec_rq,
+ .timeout = sas_task_timedout,
+};
+
+struct request_queue *sas_alloc_request_queue(struct Scsi_Host *shost)
+{
+ return blk_mq_init_queue_ops(&shost->tag_set, &sas_blk_mq_ops);
+}
+
static int sas_execute_internal_abort(struct domain_device *device,
enum sas_internal_abort type, u16 tag,
unsigned int qid, void *data)
--
2.26.2
next prev parent reply other threads:[~2022-03-22 10:46 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-22 10:39 [PATCH RFC 00/11] blk-mq/libata/scsi: SCSI driver tagging improvements John Garry
2022-03-22 10:39 ` [PATCH 01/11] blk-mq: Add blk_mq_init_queue_ops() John Garry
2022-03-22 11:18 ` Christoph Hellwig
2022-03-22 11:33 ` John Garry
2022-03-22 12:16 ` Hannes Reinecke
2022-03-22 12:30 ` John Garry
2022-03-22 14:03 ` Hannes Reinecke
2022-03-22 15:17 ` John Garry
2022-03-22 15:31 ` Hannes Reinecke
2022-03-23 2:57 ` Bart Van Assche
2022-03-23 9:01 ` John Garry
2022-03-22 10:39 ` [PATCH 02/11] scsi: core: Add SUBMITTED_BY_SCSI_CUSTOM_OPS John Garry
2022-03-22 11:20 ` Christoph Hellwig
2022-03-22 10:39 ` [PATCH 03/11] libata: Send internal commands through the block layer John Garry
2022-03-22 11:20 ` Christoph Hellwig
2022-03-22 11:36 ` John Garry
2022-04-07 14:32 ` John Garry
2022-03-22 10:39 ` John Garry [this message]
2022-03-22 11:23 ` [PATCH 04/11] scsi: libsas: Send SMP " Christoph Hellwig
2022-03-22 14:37 ` John Garry
2022-03-22 10:39 ` [PATCH 05/11] scsi: libsas: Send TMF " John Garry
2022-03-22 10:39 ` [PATCH 06/11] scsi: core: Add scsi_alloc_request_hwq() John Garry
2022-03-22 10:39 ` [PATCH 07/11] scsi: libsas: Send internal abort commands through the block layer John Garry
2022-03-22 10:39 ` [PATCH 08/11] scsi: libsas: Change ATA support to deal with each qc having a SCSI command John Garry
2022-03-22 10:39 ` [PATCH 09/11] scsi: libsas: Add sas_task_to_unique_tag() John Garry
2022-03-22 10:39 ` [PATCH 10/11] scsi: libsas: Add sas_task_to_hwq() John Garry
2022-03-22 10:39 ` [PATCH 11/11] scsi: hisi_sas: Remove private tag management John Garry
2022-03-22 11:30 ` [PATCH RFC 00/11] blk-mq/libata/scsi: SCSI driver tagging improvements Hannes Reinecke
2022-03-22 12:17 ` John Garry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1647945585-197349-5-git-send-email-john.garry@huawei.com \
--to=john.garry@huawei.com \
--cc=axboe@kernel.dk \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=chenxiang66@hisilicon.com \
--cc=damien.lemoal@opensource.wdc.com \
--cc=dm-devel@redhat.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jejb@linux.ibm.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ming.lei@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®