Commit e3896d77 authored by Omar Sandoval's avatar Omar Sandoval Committed by Jens Axboe

swim: convert to blk-mq

The only interesting thing here is that there may be two floppies (i.e.,
request queues) sharing the same controller, so we use the global struct
swim_priv->lock to check whether the controller is busy. Compile-tested
only.
Tested-by: default avatarFinn Thain <fthain@telegraphics.com.au>
Acked-by: default avatarLaurent Vivier <lvivier@redhat.com>
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 1448a2a5
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/fd.h> #include <linux/fd.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/blkdev.h> #include <linux/blk-mq.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/hdreg.h> #include <linux/hdreg.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -190,6 +190,7 @@ struct floppy_state { ...@@ -190,6 +190,7 @@ struct floppy_state {
int ref_count; int ref_count;
struct gendisk *disk; struct gendisk *disk;
struct blk_mq_tag_set tag_set;
/* parent controller */ /* parent controller */
...@@ -211,7 +212,6 @@ enum head { ...@@ -211,7 +212,6 @@ enum head {
struct swim_priv { struct swim_priv {
struct swim __iomem *base; struct swim __iomem *base;
spinlock_t lock; spinlock_t lock;
int fdc_queue;
int floppy_count; int floppy_count;
struct floppy_state unit[FD_MAX_UNIT]; struct floppy_state unit[FD_MAX_UNIT];
}; };
...@@ -525,58 +525,36 @@ static blk_status_t floppy_read_sectors(struct floppy_state *fs, ...@@ -525,58 +525,36 @@ static blk_status_t floppy_read_sectors(struct floppy_state *fs,
return 0; return 0;
} }
static struct request *swim_next_request(struct swim_priv *swd) static blk_status_t swim_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{ {
struct request_queue *q; struct floppy_state *fs = hctx->queue->queuedata;
struct request *rq; struct swim_priv *swd = fs->swd;
int old_pos = swd->fdc_queue; struct request *req = bd->rq;
blk_status_t err;
do { if (!spin_trylock_irq(&swd->lock))
q = swd->unit[swd->fdc_queue].disk->queue; return BLK_STS_DEV_RESOURCE;
if (++swd->fdc_queue == swd->floppy_count)
swd->fdc_queue = 0;
if (q) {
rq = blk_fetch_request(q);
if (rq)
return rq;
}
} while (swd->fdc_queue != old_pos);
return NULL; blk_mq_start_request(req);
}
static void do_fd_request(struct request_queue *q) if (!fs->disk_in || rq_data_dir(req) == WRITE) {
{ err = BLK_STS_IOERR;
struct swim_priv *swd = q->queuedata; goto out;
struct request *req; }
struct floppy_state *fs;
req = swim_next_request(swd); do {
while (req) { err = floppy_read_sectors(fs, blk_rq_pos(req),
blk_status_t err = BLK_STS_IOERR; blk_rq_cur_sectors(req),
bio_data(req->bio));
} while (blk_update_request(req, err, blk_rq_cur_bytes(req)));
__blk_mq_end_request(req, err);
fs = req->rq_disk->private_data; err = BLK_STS_OK;
if (blk_rq_pos(req) >= fs->total_secs) out:
goto done; spin_unlock_irq(&swd->lock);
if (!fs->disk_in) return err;
goto done;
if (rq_data_dir(req) == WRITE && fs->write_protected)
goto done;
switch (rq_data_dir(req)) {
case WRITE:
/* NOT IMPLEMENTED */
break;
case READ:
err = floppy_read_sectors(fs, blk_rq_pos(req),
blk_rq_cur_sectors(req),
bio_data(req->bio));
break;
}
done:
if (!__blk_end_request_cur(req, err))
req = swim_next_request(swd);
}
} }
static struct floppy_struct floppy_type[4] = { static struct floppy_struct floppy_type[4] = {
...@@ -823,6 +801,10 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location) ...@@ -823,6 +801,10 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location)
return 0; return 0;
} }
static const struct blk_mq_ops swim_mq_ops = {
.queue_rq = swim_queue_rq,
};
static int swim_floppy_init(struct swim_priv *swd) static int swim_floppy_init(struct swim_priv *swd)
{ {
int err; int err;
...@@ -852,20 +834,25 @@ static int swim_floppy_init(struct swim_priv *swd) ...@@ -852,20 +834,25 @@ static int swim_floppy_init(struct swim_priv *swd)
spin_lock_init(&swd->lock); spin_lock_init(&swd->lock);
for (drive = 0; drive < swd->floppy_count; drive++) { for (drive = 0; drive < swd->floppy_count; drive++) {
struct request_queue *q;
swd->unit[drive].disk = alloc_disk(1); swd->unit[drive].disk = alloc_disk(1);
if (swd->unit[drive].disk == NULL) { if (swd->unit[drive].disk == NULL) {
err = -ENOMEM; err = -ENOMEM;
goto exit_put_disks; goto exit_put_disks;
} }
swd->unit[drive].disk->queue = blk_init_queue(do_fd_request,
&swd->lock); q = blk_mq_init_sq_queue(&swd->unit[drive].tag_set, &swim_mq_ops,
if (!swd->unit[drive].disk->queue) { 2, BLK_MQ_F_SHOULD_MERGE);
err = -ENOMEM; if (IS_ERR(q)) {
err = PTR_ERR(q);
goto exit_put_disks; goto exit_put_disks;
} }
swd->unit[drive].disk->queue = q;
blk_queue_bounce_limit(swd->unit[drive].disk->queue, blk_queue_bounce_limit(swd->unit[drive].disk->queue,
BLK_BOUNCE_HIGH); BLK_BOUNCE_HIGH);
swd->unit[drive].disk->queue->queuedata = swd; swd->unit[drive].disk->queue->queuedata = &swd->unit[drive];
swd->unit[drive].swd = swd; swd->unit[drive].swd = swd;
} }
...@@ -895,6 +882,7 @@ static int swim_floppy_init(struct swim_priv *swd) ...@@ -895,6 +882,7 @@ static int swim_floppy_init(struct swim_priv *swd)
blk_cleanup_queue(disk->queue); blk_cleanup_queue(disk->queue);
disk->queue = NULL; disk->queue = NULL;
} }
blk_mq_free_tag_set(&swd->unit[drive].tag_set);
put_disk(disk); put_disk(disk);
} }
} while (drive--); } while (drive--);
...@@ -970,6 +958,7 @@ static int swim_remove(struct platform_device *dev) ...@@ -970,6 +958,7 @@ static int swim_remove(struct platform_device *dev)
for (drive = 0; drive < swd->floppy_count; drive++) { for (drive = 0; drive < swd->floppy_count; drive++) {
del_gendisk(swd->unit[drive].disk); del_gendisk(swd->unit[drive].disk);
blk_cleanup_queue(swd->unit[drive].disk->queue); blk_cleanup_queue(swd->unit[drive].disk->queue);
blk_mq_free_tag_set(&swd->unit[drive].tag_set);
put_disk(swd->unit[drive].disk); put_disk(swd->unit[drive].disk);
} }
......
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