Commit 8ccb8cb1 authored by Omar Sandoval's avatar Omar Sandoval Committed by Jens Axboe

swim3: convert to blk-mq

Pretty simple conversion. grab_drive() could probably be replaced by
some freeze/quiesce incantation, but I left it alone, and just used
freeze/quiesce for eject. Compile-tested only.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarOmar Sandoval <osandov@fb.com>

Converted to blk_mq_init_sq_queue().
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent dbaa54b6
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/fd.h> #include <linux/fd.h>
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include <linux/blkdev.h> #include <linux/blk-mq.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -206,6 +206,7 @@ struct floppy_state { ...@@ -206,6 +206,7 @@ struct floppy_state {
char dbdma_cmd_space[5 * sizeof(struct dbdma_cmd)]; char dbdma_cmd_space[5 * sizeof(struct dbdma_cmd)];
int index; int index;
struct request *cur_req; struct request *cur_req;
struct blk_mq_tag_set tag_set;
}; };
#define swim3_err(fmt, arg...) dev_err(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg) #define swim3_err(fmt, arg...) dev_err(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
...@@ -260,16 +261,15 @@ static int floppy_revalidate(struct gendisk *disk); ...@@ -260,16 +261,15 @@ static int floppy_revalidate(struct gendisk *disk);
static bool swim3_end_request(struct floppy_state *fs, blk_status_t err, unsigned int nr_bytes) static bool swim3_end_request(struct floppy_state *fs, blk_status_t err, unsigned int nr_bytes)
{ {
struct request *req = fs->cur_req; struct request *req = fs->cur_req;
int rc;
swim3_dbg(" end request, err=%d nr_bytes=%d, cur_req=%p\n", swim3_dbg(" end request, err=%d nr_bytes=%d, cur_req=%p\n",
err, nr_bytes, req); err, nr_bytes, req);
if (err) if (err)
nr_bytes = blk_rq_cur_bytes(req); nr_bytes = blk_rq_cur_bytes(req);
rc = __blk_end_request(req, err, nr_bytes); if (blk_update_request(req, err, nr_bytes))
if (rc)
return true; return true;
__blk_mq_end_request(req, err);
fs->cur_req = NULL; fs->cur_req = NULL;
return false; return false;
} }
...@@ -309,86 +309,58 @@ static int swim3_readbit(struct floppy_state *fs, int bit) ...@@ -309,86 +309,58 @@ static int swim3_readbit(struct floppy_state *fs, int bit)
return (stat & DATA) == 0; return (stat & DATA) == 0;
} }
static void start_request(struct floppy_state *fs) static blk_status_t swim3_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{ {
struct request *req; struct floppy_state *fs = hctx->queue->queuedata;
struct request *req = bd->rq;
unsigned long x; unsigned long x;
swim3_dbg("start request, initial state=%d\n", fs->state); spin_lock_irq(&swim3_lock);
if (fs->cur_req || fs->state != idle) {
if (fs->state == idle && fs->wanted) { spin_unlock_irq(&swim3_lock);
fs->state = available; return BLK_STS_DEV_RESOURCE;
wake_up(&fs->wait);
return;
} }
while (fs->state == idle) { blk_mq_start_request(req);
swim3_dbg("start request, idle loop, cur_req=%p\n", fs->cur_req); fs->cur_req = req;
if (!fs->cur_req) { if (fs->mdev->media_bay &&
fs->cur_req = blk_fetch_request(disks[fs->index]->queue); check_media_bay(fs->mdev->media_bay) != MB_FD) {
swim3_dbg(" fetched request %p\n", fs->cur_req); swim3_dbg("%s", " media bay absent, dropping req\n");
if (!fs->cur_req) swim3_end_request(fs, BLK_STS_IOERR, 0);
break; goto out;
} }
req = fs->cur_req; if (fs->ejected) {
swim3_dbg("%s", " disk ejected\n");
if (fs->mdev->media_bay && swim3_end_request(fs, BLK_STS_IOERR, 0);
check_media_bay(fs->mdev->media_bay) != MB_FD) { goto out;
swim3_dbg("%s", " media bay absent, dropping req\n"); }
swim3_end_request(fs, BLK_STS_IOERR, 0); if (rq_data_dir(req) == WRITE) {
continue; if (fs->write_prot < 0)
} fs->write_prot = swim3_readbit(fs, WRITE_PROT);
if (fs->write_prot) {
#if 0 /* This is really too verbose */ swim3_dbg("%s", " try to write, disk write protected\n");
swim3_dbg("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n",
req->rq_disk->disk_name, req->cmd,
(long)blk_rq_pos(req), blk_rq_sectors(req),
bio_data(req->bio));
swim3_dbg(" current_nr_sectors=%u\n",
blk_rq_cur_sectors(req));
#endif
if (blk_rq_pos(req) >= fs->total_secs) {
swim3_dbg(" pos out of bounds (%ld, max is %ld)\n",
(long)blk_rq_pos(req), (long)fs->total_secs);
swim3_end_request(fs, BLK_STS_IOERR, 0);
continue;
}
if (fs->ejected) {
swim3_dbg("%s", " disk ejected\n");
swim3_end_request(fs, BLK_STS_IOERR, 0); swim3_end_request(fs, BLK_STS_IOERR, 0);
continue; goto out;
}
if (rq_data_dir(req) == WRITE) {
if (fs->write_prot < 0)
fs->write_prot = swim3_readbit(fs, WRITE_PROT);
if (fs->write_prot) {
swim3_dbg("%s", " try to write, disk write protected\n");
swim3_end_request(fs, BLK_STS_IOERR, 0);
continue;
}
} }
/* Do not remove the cast. blk_rq_pos(req) is now a
* sector_t and can be 64 bits, but it will never go
* past 32 bits for this driver anyway, so we can
* safely cast it down and not have to do a 64/32
* division
*/
fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl;
x = ((long)blk_rq_pos(req)) % fs->secpercyl;
fs->head = x / fs->secpertrack;
fs->req_sector = x % fs->secpertrack + 1;
fs->state = do_transfer;
fs->retries = 0;
act(fs);
} }
}
static void do_fd_request(struct request_queue * q) /*
{ * Do not remove the cast. blk_rq_pos(req) is now a sector_t and can be
start_request(q->queuedata); * 64 bits, but it will never go past 32 bits for this driver anyway, so
* we can safely cast it down and not have to do a 64/32 division
*/
fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl;
x = ((long)blk_rq_pos(req)) % fs->secpercyl;
fs->head = x / fs->secpertrack;
fs->req_sector = x % fs->secpertrack + 1;
fs->state = do_transfer;
fs->retries = 0;
act(fs);
out:
spin_unlock_irq(&swim3_lock);
return BLK_STS_OK;
} }
static void set_timeout(struct floppy_state *fs, int nticks, static void set_timeout(struct floppy_state *fs, int nticks,
...@@ -585,7 +557,6 @@ static void scan_timeout(struct timer_list *t) ...@@ -585,7 +557,6 @@ static void scan_timeout(struct timer_list *t)
if (fs->retries > 5) { if (fs->retries > 5) {
swim3_end_request(fs, BLK_STS_IOERR, 0); swim3_end_request(fs, BLK_STS_IOERR, 0);
fs->state = idle; fs->state = idle;
start_request(fs);
} else { } else {
fs->state = jogging; fs->state = jogging;
act(fs); act(fs);
...@@ -609,7 +580,6 @@ static void seek_timeout(struct timer_list *t) ...@@ -609,7 +580,6 @@ static void seek_timeout(struct timer_list *t)
swim3_err("%s", "Seek timeout\n"); swim3_err("%s", "Seek timeout\n");
swim3_end_request(fs, BLK_STS_IOERR, 0); swim3_end_request(fs, BLK_STS_IOERR, 0);
fs->state = idle; fs->state = idle;
start_request(fs);
spin_unlock_irqrestore(&swim3_lock, flags); spin_unlock_irqrestore(&swim3_lock, flags);
} }
...@@ -638,7 +608,6 @@ static void settle_timeout(struct timer_list *t) ...@@ -638,7 +608,6 @@ static void settle_timeout(struct timer_list *t)
swim3_err("%s", "Seek settle timeout\n"); swim3_err("%s", "Seek settle timeout\n");
swim3_end_request(fs, BLK_STS_IOERR, 0); swim3_end_request(fs, BLK_STS_IOERR, 0);
fs->state = idle; fs->state = idle;
start_request(fs);
unlock: unlock:
spin_unlock_irqrestore(&swim3_lock, flags); spin_unlock_irqrestore(&swim3_lock, flags);
} }
...@@ -667,7 +636,6 @@ static void xfer_timeout(struct timer_list *t) ...@@ -667,7 +636,6 @@ static void xfer_timeout(struct timer_list *t)
(long)blk_rq_pos(fs->cur_req)); (long)blk_rq_pos(fs->cur_req));
swim3_end_request(fs, BLK_STS_IOERR, 0); swim3_end_request(fs, BLK_STS_IOERR, 0);
fs->state = idle; fs->state = idle;
start_request(fs);
spin_unlock_irqrestore(&swim3_lock, flags); spin_unlock_irqrestore(&swim3_lock, flags);
} }
...@@ -704,7 +672,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id) ...@@ -704,7 +672,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
if (fs->retries > 5) { if (fs->retries > 5) {
swim3_end_request(fs, BLK_STS_IOERR, 0); swim3_end_request(fs, BLK_STS_IOERR, 0);
fs->state = idle; fs->state = idle;
start_request(fs);
} else { } else {
fs->state = jogging; fs->state = jogging;
act(fs); act(fs);
...@@ -796,7 +763,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id) ...@@ -796,7 +763,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
fs->state, rq_data_dir(req), intr, err); fs->state, rq_data_dir(req), intr, err);
swim3_end_request(fs, BLK_STS_IOERR, 0); swim3_end_request(fs, BLK_STS_IOERR, 0);
fs->state = idle; fs->state = idle;
start_request(fs);
break; break;
} }
fs->retries = 0; fs->retries = 0;
...@@ -813,8 +779,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id) ...@@ -813,8 +779,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
} else } else
fs->state = idle; fs->state = idle;
} }
if (fs->state == idle)
start_request(fs);
break; break;
default: default:
swim3_err("Don't know what to do in state %d\n", fs->state); swim3_err("Don't know what to do in state %d\n", fs->state);
...@@ -862,14 +826,19 @@ static int grab_drive(struct floppy_state *fs, enum swim_state state, ...@@ -862,14 +826,19 @@ static int grab_drive(struct floppy_state *fs, enum swim_state state,
static void release_drive(struct floppy_state *fs) static void release_drive(struct floppy_state *fs)
{ {
struct request_queue *q = disks[fs->index]->queue;
unsigned long flags; unsigned long flags;
swim3_dbg("%s", "-> release drive\n"); swim3_dbg("%s", "-> release drive\n");
spin_lock_irqsave(&swim3_lock, flags); spin_lock_irqsave(&swim3_lock, flags);
fs->state = idle; fs->state = idle;
start_request(fs);
spin_unlock_irqrestore(&swim3_lock, flags); spin_unlock_irqrestore(&swim3_lock, flags);
blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);
blk_mq_unquiesce_queue(q);
blk_mq_unfreeze_queue(q);
} }
static int fd_eject(struct floppy_state *fs) static int fd_eject(struct floppy_state *fs)
...@@ -1089,6 +1058,10 @@ static const struct block_device_operations floppy_fops = { ...@@ -1089,6 +1058,10 @@ static const struct block_device_operations floppy_fops = {
.revalidate_disk= floppy_revalidate, .revalidate_disk= floppy_revalidate,
}; };
static const struct blk_mq_ops swim3_mq_ops = {
.queue_rq = swim3_queue_rq,
};
static void swim3_mb_event(struct macio_dev* mdev, int mb_state) static void swim3_mb_event(struct macio_dev* mdev, int mb_state)
{ {
struct floppy_state *fs = macio_get_drvdata(mdev); struct floppy_state *fs = macio_get_drvdata(mdev);
...@@ -1222,9 +1195,12 @@ static int swim3_attach(struct macio_dev *mdev, ...@@ -1222,9 +1195,12 @@ static int swim3_attach(struct macio_dev *mdev,
rc = -ENOMEM; rc = -ENOMEM;
goto out_unregister; goto out_unregister;
} }
disk->queue = blk_init_queue(do_fd_request, &swim3_lock);
if (disk->queue == NULL) { disk->queue = blk_mq_init_sq_queue(&fs->tag_set, &swim3_mq_ops, 2,
rc = -ENOMEM; BLK_MQ_F_SHOULD_MERGE);
if (IS_ERR(disk->queue)) {
rc = PTR_ERR(disk->queue);
disk->queue = NULL;
goto out_put_disk; goto out_put_disk;
} }
blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH); blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH);
...@@ -1249,6 +1225,7 @@ static int swim3_attach(struct macio_dev *mdev, ...@@ -1249,6 +1225,7 @@ static int swim3_attach(struct macio_dev *mdev,
out_cleanup_queue: out_cleanup_queue:
blk_cleanup_queue(disk->queue); blk_cleanup_queue(disk->queue);
disk->queue = NULL; disk->queue = NULL;
blk_mq_free_tag_set(&fs->tag_set);
out_put_disk: out_put_disk:
put_disk(disk); put_disk(disk);
out_unregister: out_unregister:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment