All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-ide@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 03/28] mspro_block: convert to blk-mq
Date: Thu, 25 Oct 2018 15:10:14 -0600	[thread overview]
Message-ID: <20181025211039.11559-4-axboe@kernel.dk> (raw)
In-Reply-To: <20181025211039.11559-1-axboe@kernel.dk>

Straight forward conversion, there's room for improvement.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 drivers/memstick/core/mspro_block.c | 121 +++++++++++++++-------------
 1 file changed, 66 insertions(+), 55 deletions(-)

diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 0cd30dcb6801..aba50ec98b4d 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -12,7 +12,7 @@
  *
  */
 
-#include <linux/blkdev.h>
+#include <linux/blk-mq.h>
 #include <linux/idr.h>
 #include <linux/hdreg.h>
 #include <linux/kthread.h>
@@ -142,6 +142,7 @@ struct mspro_block_data {
 	struct gendisk        *disk;
 	struct request_queue  *queue;
 	struct request        *block_req;
+	struct blk_mq_tag_set tag_set;
 	spinlock_t            q_lock;
 
 	unsigned short        page_size;
@@ -152,7 +153,6 @@ struct mspro_block_data {
 	unsigned char         system;
 	unsigned char         read_only:1,
 			      eject:1,
-			      has_request:1,
 			      data_dir:1,
 			      active:1;
 	unsigned char         transfer_cmd;
@@ -694,13 +694,12 @@ static void h_mspro_block_setup_cmd(struct memstick_dev *card, u64 offset,
 
 /*** Data transfer ***/
 
-static int mspro_block_issue_req(struct memstick_dev *card, int chunk)
+static int mspro_block_issue_req(struct memstick_dev *card, bool chunk)
 {
 	struct mspro_block_data *msb = memstick_get_drvdata(card);
 	u64 t_off;
 	unsigned int count;
 
-try_again:
 	while (chunk) {
 		msb->current_page = 0;
 		msb->current_seg = 0;
@@ -709,9 +708,17 @@ static int mspro_block_issue_req(struct memstick_dev *card, int chunk)
 					       msb->req_sg);
 
 		if (!msb->seg_count) {
-			chunk = __blk_end_request_cur(msb->block_req,
-					BLK_STS_RESOURCE);
-			continue;
+			unsigned int bytes = blk_rq_cur_bytes(msb->block_req);
+
+			chunk = blk_update_request(msb->block_req,
+							BLK_STS_RESOURCE,
+							bytes);
+			if (chunk)
+				continue;
+			__blk_mq_end_request(msb->block_req,
+						BLK_STS_RESOURCE);
+			msb->block_req = NULL;
+			break;
 		}
 
 		t_off = blk_rq_pos(msb->block_req);
@@ -729,30 +736,22 @@ static int mspro_block_issue_req(struct memstick_dev *card, int chunk)
 		return 0;
 	}
 
-	dev_dbg(&card->dev, "blk_fetch\n");
-	msb->block_req = blk_fetch_request(msb->queue);
-	if (!msb->block_req) {
-		dev_dbg(&card->dev, "issue end\n");
-		return -EAGAIN;
-	}
-
-	dev_dbg(&card->dev, "trying again\n");
-	chunk = 1;
-	goto try_again;
+	return 1;
 }
 
 static int mspro_block_complete_req(struct memstick_dev *card, int error)
 {
 	struct mspro_block_data *msb = memstick_get_drvdata(card);
-	int chunk, cnt;
+	int cnt;
+	bool chunk;
 	unsigned int t_len = 0;
 	unsigned long flags;
 
 	spin_lock_irqsave(&msb->q_lock, flags);
-	dev_dbg(&card->dev, "complete %d, %d\n", msb->has_request ? 1 : 0,
+	dev_dbg(&card->dev, "complete %d, %d\n", msb->block_req ? 1 : 0,
 		error);
 
-	if (msb->has_request) {
+	if (msb->block_req) {
 		/* Nothing to do - not really an error */
 		if (error == -EAGAIN)
 			error = 0;
@@ -777,15 +776,17 @@ static int mspro_block_complete_req(struct memstick_dev *card, int error)
 		if (error && !t_len)
 			t_len = blk_rq_cur_bytes(msb->block_req);
 
-		chunk = __blk_end_request(msb->block_req,
+		chunk = blk_update_request(msb->block_req,
 				errno_to_blk_status(error), t_len);
-
-		error = mspro_block_issue_req(card, chunk);
-
-		if (!error)
-			goto out;
-		else
-			msb->has_request = 0;
+		if (chunk) {
+			error = mspro_block_issue_req(card, chunk);
+			if (!error)
+				goto out;
+		} else {
+			__blk_mq_end_request(msb->block_req,
+						errno_to_blk_status(error));
+			msb->block_req = NULL;
+		}
 	} else {
 		if (!error)
 			error = -EAGAIN;
@@ -806,8 +807,8 @@ static void mspro_block_stop(struct memstick_dev *card)
 
 	while (1) {
 		spin_lock_irqsave(&msb->q_lock, flags);
-		if (!msb->has_request) {
-			blk_stop_queue(msb->queue);
+		if (!msb->block_req) {
+			blk_mq_stop_hw_queues(msb->queue);
 			rc = 1;
 		}
 		spin_unlock_irqrestore(&msb->q_lock, flags);
@@ -822,32 +823,37 @@ static void mspro_block_stop(struct memstick_dev *card)
 static void mspro_block_start(struct memstick_dev *card)
 {
 	struct mspro_block_data *msb = memstick_get_drvdata(card);
-	unsigned long flags;
 
-	spin_lock_irqsave(&msb->q_lock, flags);
-	blk_start_queue(msb->queue);
-	spin_unlock_irqrestore(&msb->q_lock, flags);
+	blk_mq_start_hw_queues(msb->queue);
 }
 
-static void mspro_block_submit_req(struct request_queue *q)
+static blk_status_t mspro_queue_rq(struct blk_mq_hw_ctx *hctx,
+				   const struct blk_mq_queue_data *bd)
 {
-	struct memstick_dev *card = q->queuedata;
+	struct memstick_dev *card = hctx->queue->queuedata;
 	struct mspro_block_data *msb = memstick_get_drvdata(card);
-	struct request *req = NULL;
 
-	if (msb->has_request)
-		return;
+	spin_lock_irq(&msb->q_lock);
 
-	if (msb->eject) {
-		while ((req = blk_fetch_request(q)) != NULL)
-			__blk_end_request_all(req, BLK_STS_IOERR);
+	if (msb->block_req) {
+		spin_unlock_irq(&msb->q_lock);
+		return BLK_STS_DEV_RESOURCE;
+	}
 
-		return;
+	if (msb->eject) {
+		spin_unlock_irq(&msb->q_lock);
+		blk_mq_start_request(bd->rq);
+		return BLK_STS_IOERR;
 	}
 
-	msb->has_request = 1;
-	if (mspro_block_issue_req(card, 0))
-		msb->has_request = 0;
+	msb->block_req = bd->rq;
+	blk_mq_start_request(bd->rq);
+
+	if (mspro_block_issue_req(card, true))
+		msb->block_req = NULL;
+
+	spin_unlock_irq(&msb->q_lock);
+	return BLK_STS_OK;
 }
 
 /*** Initialization ***/
@@ -1167,6 +1173,10 @@ static int mspro_block_init_card(struct memstick_dev *card)
 
 }
 
+static const struct blk_mq_ops mspro_mq_ops = {
+	.queue_rq	= mspro_queue_rq,
+};
+
 static int mspro_block_init_disk(struct memstick_dev *card)
 {
 	struct mspro_block_data *msb = memstick_get_drvdata(card);
@@ -1206,9 +1216,11 @@ static int mspro_block_init_disk(struct memstick_dev *card)
 		goto out_release_id;
 	}
 
-	msb->queue = blk_init_queue(mspro_block_submit_req, &msb->q_lock);
-	if (!msb->queue) {
-		rc = -ENOMEM;
+	msb->queue = blk_mq_init_sq_queue(&msb->tag_set, &mspro_mq_ops, 2,
+						BLK_MQ_F_SHOULD_MERGE);
+	if (IS_ERR(msb->queue)) {
+		rc = PTR_ERR(msb->queue);
+		msb->queue = NULL;
 		goto out_put_disk;
 	}
 
@@ -1318,13 +1330,14 @@ static void mspro_block_remove(struct memstick_dev *card)
 
 	spin_lock_irqsave(&msb->q_lock, flags);
 	msb->eject = 1;
-	blk_start_queue(msb->queue);
 	spin_unlock_irqrestore(&msb->q_lock, flags);
+	blk_mq_start_hw_queues(msb->queue);
 
 	del_gendisk(msb->disk);
 	dev_dbg(&card->dev, "mspro block remove\n");
 
 	blk_cleanup_queue(msb->queue);
+	blk_mq_free_tag_set(&msb->tag_set);
 	msb->queue = NULL;
 
 	sysfs_remove_group(&card->dev.kobj, &msb->attr_group);
@@ -1344,8 +1357,9 @@ static int mspro_block_suspend(struct memstick_dev *card, pm_message_t state)
 	struct mspro_block_data *msb = memstick_get_drvdata(card);
 	unsigned long flags;
 
+	blk_mq_stop_hw_queues(msb->queue);
+
 	spin_lock_irqsave(&msb->q_lock, flags);
-	blk_stop_queue(msb->queue);
 	msb->active = 0;
 	spin_unlock_irqrestore(&msb->q_lock, flags);
 
@@ -1355,7 +1369,6 @@ static int mspro_block_suspend(struct memstick_dev *card, pm_message_t state)
 static int mspro_block_resume(struct memstick_dev *card)
 {
 	struct mspro_block_data *msb = memstick_get_drvdata(card);
-	unsigned long flags;
 	int rc = 0;
 
 #ifdef CONFIG_MEMSTICK_UNSAFE_RESUME
@@ -1401,9 +1414,7 @@ static int mspro_block_resume(struct memstick_dev *card)
 
 #endif /* CONFIG_MEMSTICK_UNSAFE_RESUME */
 
-	spin_lock_irqsave(&msb->q_lock, flags);
-	blk_start_queue(msb->queue);
-	spin_unlock_irqrestore(&msb->q_lock, flags);
+	blk_mq_start_hw_queues(msb->queue);
 	return rc;
 }
 
-- 
2.17.1

  parent reply	other threads:[~2018-10-25 21:10 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-25 21:10 [PATCHSET 0/28] blk-mq driver conversions and legacy path removal Jens Axboe
2018-10-25 21:10 ` [PATCH 01/28] sunvdc: convert to blk-mq Jens Axboe
2018-10-27 10:42   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 02/28] ms_block: " Jens Axboe
2018-10-27 10:43   ` Hannes Reinecke
2018-10-25 21:10 ` Jens Axboe [this message]
2018-10-27 10:44   ` [PATCH 03/28] mspro_block: " Hannes Reinecke
2018-10-25 21:10 ` [PATCH 04/28] ide: " Jens Axboe
2018-10-27 10:51   ` Hannes Reinecke
2018-10-27 16:51     ` Jens Axboe
2018-10-25 21:10 ` [PATCH 05/28] IB/srp: remove old request_fn_active check Jens Axboe
2018-10-25 21:23   ` Bart Van Assche
2018-10-25 21:24     ` Jens Axboe
2018-10-26  7:08   ` Hannes Reinecke
2018-10-26 14:32     ` Jens Axboe
2018-10-26 15:03       ` Bart Van Assche
2018-10-25 21:10 ` [PATCH 06/28] blk-mq: remove the request_list usage Jens Axboe
2018-10-27 10:52   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 07/28] blk-mq: remove legacy check in queue blk_freeze_queue() Jens Axboe
2018-10-27 10:52   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 08/28] scsi: kill off the legacy IO path Jens Axboe
2018-10-25 21:36   ` Bart Van Assche
2018-10-25 22:18     ` Jens Axboe
2018-10-25 22:44       ` Madhani, Himanshu
2018-10-25 23:00         ` Jens Axboe
2018-10-25 23:06           ` Madhani, Himanshu
2018-10-29  6:48   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 09/28] dm: remove " Jens Axboe
2018-10-29  6:53   ` Hannes Reinecke
2018-10-29 14:17     ` Jens Axboe
2018-10-25 21:10 ` [PATCH 10/28] dasd: remove dead code Jens Axboe
2018-10-29  6:54   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 11/28] bsg: pass in desired timeout handler Jens Axboe
2018-10-28 15:53   ` Christoph Hellwig
2018-10-28 23:05     ` Jens Axboe
2018-10-29  6:55   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 12/28] bsg: provide bsg_remove_queue() helper Jens Axboe
2018-10-28 15:53   ` Christoph Hellwig
2018-10-29  6:55   ` Hannes Reinecke
2018-10-29 10:16   ` Johannes Thumshirn
2018-10-29 14:15     ` Jens Axboe
2018-10-25 21:10 ` [PATCH 13/28] bsg: convert to use blk-mq Jens Axboe
2018-10-28 16:07   ` Christoph Hellwig
2018-10-28 23:25     ` Jens Axboe
2018-10-29  6:57   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 14/28] block: remove blk_complete_request() Jens Axboe
2018-10-29  6:59   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 15/28] blk-wbt: kill check for legacy queue type Jens Axboe
2018-10-29  6:59   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 16/28] blk-cgroup: remove legacy queue bypassing Jens Axboe
2018-10-29  7:00   ` Hannes Reinecke
2018-10-29 11:00   ` Johannes Thumshirn
2018-10-29 14:23     ` Jens Axboe
2018-10-29 14:25       ` Johannes Thumshirn
2018-10-29 14:59         ` Jens Axboe
2018-10-25 21:10 ` [PATCH 17/28] block: remove legacy rq tagging Jens Axboe
2018-10-29  7:01   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 18/28] block: remove non mq parts from the flush code Jens Axboe
2018-10-29  7:02   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 19/28] block: remove legacy IO schedulers Jens Axboe
2018-10-25 21:10 ` [PATCH 20/28] block: remove dead elevator code Jens Axboe
2018-10-25 21:10 ` [PATCH 21/28] block: remove __blk_put_request() Jens Axboe
2018-10-29  7:03   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 22/28] block: kill legacy parts of timeout handling Jens Axboe
2018-10-29  7:04   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 23/28] block: kill lld busy Jens Axboe
2018-10-25 21:42   ` Bart Van Assche
2018-10-25 22:18     ` Jens Axboe
2018-10-29  7:10   ` Hannes Reinecke
2018-10-29 14:25     ` Jens Axboe
2018-10-29 15:51       ` Mike Snitzer
2018-10-29 16:26         ` Jens Axboe
2018-10-25 21:10 ` [PATCH 24/28] block: remove request_list code Jens Axboe
2018-10-29  7:10   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 25/28] block: kill request slab cache Jens Axboe
2018-10-29  7:11   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 26/28] block: remove req_no_special_merge() from merging code Jens Axboe
2018-10-29  7:12   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 27/28] blk-merge: kill dead queue lock held check Jens Axboe
2018-10-29  7:12   ` Hannes Reinecke
2018-10-25 21:10 ` [PATCH 28/28] block: get rid of blk_queued_rq() Jens Axboe
2018-10-29  7:12   ` Hannes Reinecke
2018-10-25 23:09 ` [PATCHSET 0/28] blk-mq driver conversions and legacy path removal Bart Van Assche
2018-10-25 23:11   ` Jens Axboe
2018-10-29 12:00 ` Ming Lei
2018-10-29 14:50   ` Jens Axboe
2018-10-29 15:04     ` Jens Axboe
2018-10-30  9:41       ` Ming Lei
2018-10-30 14:13         ` Jens Axboe
2018-10-29 15:05     ` Ming Lei

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=20181025211039.11559-4-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.