Linux block layer
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Damien Le Moal <Damien.LeMoal@wdc.com>,
	Akhil Bhansali <Akhil.Bhansali@wdc.com>,
	Bart Van Assche <bart.vanassche@wdc.com>,
	Hannes Reinecke <hare@suse.de>,
	Johannes Thumshirn <jthumshirn@suse.de>
Subject: [PATCH 45/55] skd: Introduce skd_process_request()
Date: Thu, 17 Aug 2017 13:13:28 -0700	[thread overview]
Message-ID: <20170817201338.16537-46-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20170817201338.16537-1-bart.vanassche@wdc.com>

The only functional change in this patch is that the skd_fitmsg_context
in which requests are accumulated is changed from a local variable into
a member of struct skd_device. This patch will make the blk-mq conversion
easier.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/block/skd_main.c | 237 ++++++++++++++++++++++++-----------------------
 1 file changed, 119 insertions(+), 118 deletions(-)

diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index 4b92d711d2d3..1d10373b0da3 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -232,6 +232,7 @@ struct skd_device {
 	spinlock_t lock;
 	struct gendisk *disk;
 	struct request_queue *queue;
+	struct skd_fitmsg_context *skmsg;
 	struct device *class_dev;
 	int gendisk_on;
 	int sync_done;
@@ -492,23 +493,128 @@ static bool skd_fail_all(struct request_queue *q)
 	}
 }
 
-static void skd_request_fn(struct request_queue *q)
+static void skd_process_request(struct request *req)
 {
+	struct request_queue *const q = req->q;
 	struct skd_device *skdev = q->queuedata;
-	struct skd_fitmsg_context *skmsg = NULL;
-	struct fit_msg_hdr *fmh = NULL;
-	struct skd_request_context *skreq;
-	struct request *req = NULL;
+	struct skd_fitmsg_context *skmsg;
+	struct fit_msg_hdr *fmh;
+	const u32 tag = blk_mq_unique_tag(req);
+	struct skd_request_context *const skreq = &skdev->skreq_table[tag];
 	struct skd_scsi_request *scsi_req;
 	unsigned long io_flags;
 	u32 lba;
 	u32 count;
 	int data_dir;
 	__be64 be_dmaa;
-	u64 cmdctxt;
 	u32 timo_slot;
 	int flush, fua;
-	u32 tag;
+
+	WARN_ONCE(tag >= skd_max_queue_depth, "%#x > %#x (nr_requests = %lu)\n",
+		  tag, skd_max_queue_depth, q->nr_requests);
+
+	SKD_ASSERT(skreq->state == SKD_REQ_STATE_IDLE);
+
+	flush = fua = 0;
+
+	lba = (u32)blk_rq_pos(req);
+	count = blk_rq_sectors(req);
+	data_dir = rq_data_dir(req);
+	io_flags = req->cmd_flags;
+
+	if (req_op(req) == REQ_OP_FLUSH)
+		flush++;
+
+	if (io_flags & REQ_FUA)
+		fua++;
+
+	dev_dbg(&skdev->pdev->dev,
+		"new req=%p lba=%u(0x%x) count=%u(0x%x) dir=%d\n", req, lba,
+		lba, count, count, data_dir);
+
+	skreq->id = tag + SKD_ID_RW_REQUEST;
+	skreq->flush_cmd = 0;
+	skreq->n_sg = 0;
+	skreq->sg_byte_count = 0;
+
+	skreq->req = req;
+	skreq->fitmsg_id = 0;
+
+	skreq->data_dir = data_dir == READ ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+
+	if (req->bio && !skd_preop_sg_list(skdev, skreq)) {
+		dev_dbg(&skdev->pdev->dev, "error Out\n");
+		skd_end_request(skdev, skreq->req, BLK_STS_RESOURCE);
+		return;
+	}
+
+	/* Either a FIT msg is in progress or we have to start one. */
+	skmsg = skdev->skmsg;
+	if (!skmsg) {
+		skmsg = &skdev->skmsg_table[tag];
+		skdev->skmsg = skmsg;
+
+		/* Initialize the FIT msg header */
+		fmh = &skmsg->msg_buf->fmh;
+		memset(fmh, 0, sizeof(*fmh));
+		fmh->protocol_id = FIT_PROTOCOL_ID_SOFIT;
+		skmsg->length = sizeof(*fmh);
+	} else {
+		fmh = &skmsg->msg_buf->fmh;
+	}
+
+	skreq->fitmsg_id = skmsg->id;
+
+	scsi_req = &skmsg->msg_buf->scsi[fmh->num_protocol_cmds_coalesced];
+	memset(scsi_req, 0, sizeof(*scsi_req));
+
+	be_dmaa = cpu_to_be64(skreq->sksg_dma_address);
+
+	scsi_req->hdr.tag = skreq->id;
+	scsi_req->hdr.sg_list_dma_address = be_dmaa;
+
+	if (flush == SKD_FLUSH_ZERO_SIZE_FIRST) {
+		skd_prep_zerosize_flush_cdb(scsi_req, skreq);
+		SKD_ASSERT(skreq->flush_cmd == 1);
+	} else {
+		skd_prep_rw_cdb(scsi_req, data_dir, lba, count);
+	}
+
+	if (fua)
+		scsi_req->cdb[1] |= SKD_FUA_NV;
+
+	scsi_req->hdr.sg_list_len_bytes = cpu_to_be32(skreq->sg_byte_count);
+
+	/* Complete resource allocations. */
+	skreq->state = SKD_REQ_STATE_BUSY;
+
+	skmsg->length += sizeof(struct skd_scsi_request);
+	fmh->num_protocol_cmds_coalesced++;
+
+	/*
+	 * Update the active request counts.
+	 * Capture the timeout timestamp.
+	 */
+	skreq->timeout_stamp = atomic_read(&skdev->timeout_stamp);
+	timo_slot = skreq->timeout_stamp & SKD_TIMEOUT_SLOT_MASK;
+	atomic_inc(&skdev->timeout_slot[timo_slot]);
+	atomic_inc(&skdev->in_flight);
+	dev_dbg(&skdev->pdev->dev, "req=0x%x busy=%d\n", skreq->id,
+		atomic_read(&skdev->in_flight));
+
+	/*
+	 * If the FIT msg buffer is full send it.
+	 */
+	if (fmh->num_protocol_cmds_coalesced >= skd_max_req_per_msg) {
+		skd_send_fitmsg(skdev, skmsg);
+		skdev->skmsg = NULL;
+	}
+}
+
+static void skd_request_fn(struct request_queue *q)
+{
+	struct skd_device *skdev = q->queuedata;
+	struct request *req;
 
 	if (skdev->state != SKD_DRVR_STATE_ONLINE) {
 		if (skd_fail_all(q))
@@ -533,30 +639,12 @@ static void skd_request_fn(struct request_queue *q)
 	 *  - There are no more FIT msg buffers
 	 */
 	for (;; ) {
-
-		flush = fua = 0;
-
 		req = blk_peek_request(q);
 
 		/* Are there any native requests to start? */
 		if (req == NULL)
 			break;
 
-		lba = (u32)blk_rq_pos(req);
-		count = blk_rq_sectors(req);
-		data_dir = rq_data_dir(req);
-		io_flags = req->cmd_flags;
-
-		if (req_op(req) == REQ_OP_FLUSH)
-			flush++;
-
-		if (io_flags & REQ_FUA)
-			fua++;
-
-		dev_dbg(&skdev->pdev->dev,
-			"new req=%p lba=%u(0x%x) count=%u(0x%x) dir=%d\n",
-			req, lba, lba, count, count, data_dir);
-
 		/* At this point we know there is a request */
 
 		/* Are too many requets already in progress? */
@@ -576,103 +664,16 @@ static void skd_request_fn(struct request_queue *q)
 		 * available but is still at the head of the free list.
 		 */
 		WARN_ON_ONCE(blk_queue_start_tag(q, req));
-
-		tag = blk_mq_unique_tag(req);
-		WARN_ONCE(tag >= skd_max_queue_depth,
-			  "%#x > %#x (nr_requests = %lu)\n", tag,
-			  skd_max_queue_depth, q->nr_requests);
-
-		skreq = &skdev->skreq_table[tag];
-		SKD_ASSERT(skreq->state == SKD_REQ_STATE_IDLE);
-		SKD_ASSERT((skreq->id & SKD_ID_INCR) == 0);
-
-		skreq->id = tag + SKD_ID_RW_REQUEST;
-		skreq->flush_cmd = 0;
-		skreq->n_sg = 0;
-		skreq->sg_byte_count = 0;
-
-		skreq->req = req;
-		skreq->fitmsg_id = 0;
-
-		skreq->data_dir = data_dir == READ ? DMA_FROM_DEVICE :
-			DMA_TO_DEVICE;
-
-		if (req->bio && !skd_preop_sg_list(skdev, skreq)) {
-			dev_dbg(&skdev->pdev->dev, "error Out\n");
-			skd_end_request(skdev, skreq->req, BLK_STS_RESOURCE);
-			continue;
-		}
-
-		/* Either a FIT msg is in progress or we have to start one. */
-		if (skmsg == NULL) {
-			skmsg = &skdev->skmsg_table[tag];
-
-			/* Initialize the FIT msg header */
-			fmh = &skmsg->msg_buf->fmh;
-			memset(fmh, 0, sizeof(*fmh));
-			fmh->protocol_id = FIT_PROTOCOL_ID_SOFIT;
-			skmsg->length = sizeof(*fmh);
-		}
-
-		skreq->fitmsg_id = skmsg->id;
-
-		scsi_req =
-			&skmsg->msg_buf->scsi[fmh->num_protocol_cmds_coalesced];
-		memset(scsi_req, 0, sizeof(*scsi_req));
-
-		be_dmaa = cpu_to_be64(skreq->sksg_dma_address);
-		cmdctxt = skreq->id + SKD_ID_INCR;
-
-		scsi_req->hdr.tag = cmdctxt;
-		scsi_req->hdr.sg_list_dma_address = be_dmaa;
-
-		if (flush == SKD_FLUSH_ZERO_SIZE_FIRST) {
-			skd_prep_zerosize_flush_cdb(scsi_req, skreq);
-			SKD_ASSERT(skreq->flush_cmd == 1);
-		} else {
-			skd_prep_rw_cdb(scsi_req, data_dir, lba, count);
-		}
-
-		if (fua)
-			scsi_req->cdb[1] |= SKD_FUA_NV;
-
-		scsi_req->hdr.sg_list_len_bytes =
-			cpu_to_be32(skreq->sg_byte_count);
-
-		/* Complete resource allocations. */
-		skreq->state = SKD_REQ_STATE_BUSY;
-		skreq->id += SKD_ID_INCR;
-
-		skmsg->length += sizeof(struct skd_scsi_request);
-		fmh->num_protocol_cmds_coalesced++;
-
-		/*
-		 * Update the active request counts.
-		 * Capture the timeout timestamp.
-		 */
-		skreq->timeout_stamp = atomic_read(&skdev->timeout_stamp);
-		timo_slot = skreq->timeout_stamp & SKD_TIMEOUT_SLOT_MASK;
-		atomic_inc(&skdev->timeout_slot[timo_slot]);
-		atomic_inc(&skdev->in_flight);
-		dev_dbg(&skdev->pdev->dev, "req=0x%x busy=%d\n", skreq->id,
-			atomic_read(&skdev->in_flight));
-
-		/*
-		 * If the FIT msg buffer is full send it.
-		 */
-		if (fmh->num_protocol_cmds_coalesced >= skd_max_req_per_msg) {
-			skd_send_fitmsg(skdev, skmsg);
-			skmsg = NULL;
-			fmh = NULL;
-		}
+		skd_process_request(req);
 	}
 
 	/* If the FIT msg buffer is not empty send what we got. */
-	if (skmsg) {
+	if (skdev->skmsg) {
+		struct fit_msg_hdr *fmh = &skdev->skmsg->msg_buf->fmh;
+
 		WARN_ON_ONCE(!fmh->num_protocol_cmds_coalesced);
-		skd_send_fitmsg(skdev, skmsg);
-		skmsg = NULL;
-		fmh = NULL;
+		skd_send_fitmsg(skdev, skdev->skmsg);
+		skdev->skmsg = NULL;
 	}
 
 	/*
-- 
2.14.0

  parent reply	other threads:[~2017-08-17 20:13 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-17 20:12 [PATCH 00/55] Convert skd driver to blk-mq Bart Van Assche
2017-08-17 20:12 ` [PATCH 01/55] block: Relax a check in blk_start_queue() Bart Van Assche
2017-08-17 20:12 ` [PATCH 02/55] skd: Avoid that module unloading triggers a use-after-free Bart Van Assche
2017-08-17 20:12 ` [PATCH 03/55] skd: Submit requests to firmware before triggering the doorbell Bart Van Assche
2017-08-17 20:12 ` [PATCH 04/55] skd: Switch to GPLv2 Bart Van Assche
2017-08-17 20:12 ` [PATCH 05/55] skd: Update maintainer information Bart Van Assche
2017-08-17 20:12 ` [PATCH 06/55] skd: Remove unneeded #include directives Bart Van Assche
2017-08-17 20:12 ` [PATCH 07/55] skd: Remove ESXi code Bart Van Assche
2017-08-17 20:12 ` [PATCH 08/55] skd: Remove unnecessary blank lines Bart Van Assche
2017-08-17 20:12 ` [PATCH 09/55] skd: Avoid that gcc 7 warns about fall-through when building with W=1 Bart Van Assche
2017-08-17 20:12 ` [PATCH 10/55] skd: Fix spelling in a source code comment Bart Van Assche
2017-08-17 20:12 ` [PATCH 11/55] skd: Fix a function name in a comment Bart Van Assche
2017-08-17 20:12 ` [PATCH 12/55] skd: Remove set-but-not-used local variables Bart Van Assche
2017-08-17 20:12 ` [PATCH 13/55] skd: Remove a set-but-not-used variable from struct skd_device Bart Van Assche
2017-08-17 20:12 ` [PATCH 14/55] skd: Remove useless barrier() calls Bart Van Assche
2017-08-17 20:12 ` [PATCH 15/55] skd: Switch from the pr_*() to the dev_*() logging functions Bart Van Assche
2017-08-17 20:12 ` [PATCH 16/55] skd: Fix endianness annotations Bart Van Assche
2017-08-17 20:13 ` [PATCH 17/55] skd: Document locking assumptions Bart Van Assche
2017-08-17 20:13 ` [PATCH 18/55] skd: Introduce the symbolic constant SKD_MAX_REQ_PER_MSG Bart Van Assche
2017-08-17 20:13 ` [PATCH 19/55] skd: Introduce SKD_SKCOMP_SIZE Bart Van Assche
2017-08-17 20:13 ` [PATCH 20/55] skd: Fix size argument in skd_free_skcomp() Bart Van Assche
2017-08-17 20:13 ` [PATCH 21/55] skd: Reorder the code in skd_process_request() Bart Van Assche
2017-08-17 20:13 ` [PATCH 22/55] skd: Simplify the code for deciding whether or not to send a FIT msg Bart Van Assche
2017-08-17 20:13 ` [PATCH 23/55] skd: Simplify the code for allocating DMA message buffers Bart Van Assche
2017-08-17 20:13 ` [PATCH 24/55] skd: Use a structure instead of hardcoding structure offsets Bart Van Assche
2017-08-17 20:13 ` [PATCH 25/55] skd: Check structure sizes at build time Bart Van Assche
2017-08-17 20:13 ` [PATCH 26/55] skd: Use __packed only when needed Bart Van Assche
2017-08-17 20:13 ` [PATCH 27/55] skd: Make the skd_isr() code more brief Bart Van Assche
2017-08-17 20:13 ` [PATCH 28/55] skd: Use ARRAY_SIZE() where appropriate Bart Van Assche
2017-08-17 20:13 ` [PATCH 29/55] skd: Simplify the code for handling data direction Bart Van Assche
2017-08-17 20:13 ` [PATCH 30/55] skd: Remove superfluous initializations from skd_isr_completion_posted() Bart Van Assche
2017-08-17 20:13 ` [PATCH 31/55] skd: Drop second argument of skd_recover_requests() Bart Van Assche
2017-08-17 20:13 ` [PATCH 32/55] skd: Use for_each_sg() Bart Van Assche
2017-08-17 20:13 ` [PATCH 33/55] skd: Remove a redundant init_timer() call Bart Van Assche
2017-08-17 20:13 ` [PATCH 34/55] skd: Remove superfluous occurrences of the 'volatile' keyword Bart Van Assche
2017-08-17 20:13 ` [PATCH 35/55] skd: Use kcalloc() instead of kzalloc() with multiply Bart Van Assche
2017-08-17 20:13 ` [PATCH 36/55] skb: Use symbolic names for SCSI opcodes Bart Van Assche
2017-08-17 20:13 ` [PATCH 37/55] skd: Move a function definition Bart Van Assche
2017-08-17 20:13 ` [PATCH 38/55] skd: Rework request failing code path Bart Van Assche
2017-08-17 20:13 ` [PATCH 39/55] skd: Convert explicit skd_request_fn() calls Bart Van Assche
2017-08-17 20:13 ` [PATCH 40/55] skd: Remove SG IO support Bart Van Assche
2017-08-17 20:13 ` [PATCH 41/55] skd: Remove dead code Bart Van Assche
2017-08-17 20:13 ` [PATCH 42/55] skd: Initialize skd_special_context.req.n_sg to one Bart Van Assche
2017-08-17 20:13 ` [PATCH 43/55] skd: Enable request tags for the block layer queue Bart Van Assche
2017-08-17 20:13 ` [PATCH 44/55] skd: Convert several per-device scalar variables into atomics Bart Van Assche
2017-08-17 20:13 ` Bart Van Assche [this message]
2017-08-17 20:13 ` [PATCH 46/55] skd: Split skd_recover_requests() Bart Van Assche
2017-08-17 20:13 ` [PATCH 47/55] skd: Move skd_free_sg_list() up Bart Van Assche
2017-08-17 20:13 ` [PATCH 48/55] skd: Coalesce struct request and struct skd_request_context Bart Van Assche
2017-08-17 20:13 ` [PATCH 49/55] skd: Convert to blk-mq Bart Van Assche
2017-08-17 20:13 ` [PATCH 50/55] skd: Switch to block layer timeout mechanism Bart Van Assche
2017-08-17 20:13 ` [PATCH 51/55] skd: Remove skd_device.in_flight Bart Van Assche
2017-08-17 20:13 ` [PATCH 52/55] skd: Reduce memory usage Bart Van Assche
2017-08-17 20:13 ` [PATCH 53/55] skd: Remove several local variables Bart Van Assche
2017-08-17 20:13 ` [PATCH 54/55] skd: Optimize locking Bart Van Assche
2017-08-17 20:13 ` [PATCH 55/55] skd: Bump driver version Bart Van Assche
2017-08-17 20:45   ` Jens Axboe
2017-08-17 20:44 ` [PATCH 00/55] Convert skd driver to blk-mq Jens Axboe
2017-08-18 14:46 ` Jens Axboe
2017-08-18 15:05   ` Bart Van Assche

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=20170817201338.16537-46-bart.vanassche@wdc.com \
    --to=bart.vanassche@wdc.com \
    --cc=Akhil.Bhansali@wdc.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jthumshirn@suse.de \
    --cc=linux-block@vger.kernel.org \
    /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