hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/block/paride/pf.c
....@@ -152,7 +152,7 @@
152152 #include <linux/hdreg.h>
153153 #include <linux/cdrom.h>
154154 #include <linux/spinlock.h>
155
-#include <linux/blkdev.h>
155
+#include <linux/blk-mq.h>
156156 #include <linux/blkpg.h>
157157 #include <linux/mutex.h>
158158 #include <linux/uaccess.h>
....@@ -206,7 +206,8 @@
206206 #define ATAPI_WRITE_10 0x2a
207207
208208 static int pf_open(struct block_device *bdev, fmode_t mode);
209
-static void do_pf_request(struct request_queue * q);
209
+static blk_status_t pf_queue_rq(struct blk_mq_hw_ctx *hctx,
210
+ const struct blk_mq_queue_data *bd);
210211 static int pf_ioctl(struct block_device *bdev, fmode_t mode,
211212 unsigned int cmd, unsigned long arg);
212213 static int pf_getgeo(struct block_device *bdev, struct hd_geometry *geo);
....@@ -238,6 +239,8 @@
238239 int present; /* device present ? */
239240 char name[PF_NAMELEN]; /* pf0, pf1, ... */
240241 struct gendisk *disk;
242
+ struct blk_mq_tag_set tag_set;
243
+ struct list_head rq_list;
241244 };
242245
243246 static struct pf_unit units[PF_UNITS];
....@@ -273,8 +276,13 @@
273276 .open = pf_open,
274277 .release = pf_release,
275278 .ioctl = pf_ioctl,
279
+ .compat_ioctl = pf_ioctl,
276280 .getgeo = pf_getgeo,
277281 .check_events = pf_check_events,
282
+};
283
+
284
+static const struct blk_mq_ops pf_mq_ops = {
285
+ .queue_rq = pf_queue_rq,
278286 };
279287
280288 static void __init pf_init_units(void)
....@@ -284,14 +292,22 @@
284292
285293 pf_drive_count = 0;
286294 for (unit = 0, pf = units; unit < PF_UNITS; unit++, pf++) {
287
- struct gendisk *disk = alloc_disk(1);
295
+ struct gendisk *disk;
296
+
297
+ disk = alloc_disk(1);
288298 if (!disk)
289299 continue;
290
- disk->queue = blk_init_queue(do_pf_request, &pf_spin_lock);
291
- if (!disk->queue) {
300
+
301
+ disk->queue = blk_mq_init_sq_queue(&pf->tag_set, &pf_mq_ops,
302
+ 1, BLK_MQ_F_SHOULD_MERGE);
303
+ if (IS_ERR(disk->queue)) {
304
+ disk->queue = NULL;
292305 put_disk(disk);
293
- return;
306
+ continue;
294307 }
308
+
309
+ INIT_LIST_HEAD(&pf->rq_list);
310
+ disk->queue->queuedata = pf;
295311 blk_queue_max_segments(disk->queue, cluster);
296312 blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH);
297313 pf->disk = disk;
....@@ -304,6 +320,7 @@
304320 disk->first_minor = unit;
305321 strcpy(disk->disk_name, pf->name);
306322 disk->fops = &pf_fops;
323
+ disk->events = DISK_EVENT_MEDIA_CHANGE;
307324 if (!(*drives[unit])[D_PRT])
308325 pf_drive_count++;
309326 }
....@@ -746,8 +763,14 @@
746763 return 0;
747764
748765 printk("%s: No ATAPI disk detected\n", name);
749
- for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++)
766
+ for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
767
+ if (!pf->disk)
768
+ continue;
769
+ blk_cleanup_queue(pf->disk->queue);
770
+ pf->disk->queue = NULL;
771
+ blk_mq_free_tag_set(&pf->tag_set);
750772 put_disk(pf->disk);
773
+ }
751774 pi_unregister_driver(par_drv);
752775 return -1;
753776 }
....@@ -784,18 +807,18 @@
784807 static int set_next_request(void)
785808 {
786809 struct pf_unit *pf;
787
- struct request_queue *q;
788810 int old_pos = pf_queue;
789811
790812 do {
791813 pf = &units[pf_queue];
792
- q = pf->present ? pf->disk->queue : NULL;
793814 if (++pf_queue == PF_UNITS)
794815 pf_queue = 0;
795
- if (q) {
796
- pf_req = blk_fetch_request(q);
797
- if (pf_req)
798
- break;
816
+ if (pf->present && !list_empty(&pf->rq_list)) {
817
+ pf_req = list_first_entry(&pf->rq_list, struct request,
818
+ queuelist);
819
+ list_del_init(&pf_req->queuelist);
820
+ blk_mq_start_request(pf_req);
821
+ break;
799822 }
800823 } while (pf_queue != old_pos);
801824
....@@ -804,8 +827,12 @@
804827
805828 static void pf_end_request(blk_status_t err)
806829 {
807
- if (pf_req && !__blk_end_request_cur(pf_req, err))
830
+ if (!pf_req)
831
+ return;
832
+ if (!blk_update_request(pf_req, err, blk_rq_cur_bytes(pf_req))) {
833
+ __blk_mq_end_request(pf_req, err);
808834 pf_req = NULL;
835
+ }
809836 }
810837
811838 static void pf_request(void)
....@@ -842,9 +869,17 @@
842869 }
843870 }
844871
845
-static void do_pf_request(struct request_queue *q)
872
+static blk_status_t pf_queue_rq(struct blk_mq_hw_ctx *hctx,
873
+ const struct blk_mq_queue_data *bd)
846874 {
875
+ struct pf_unit *pf = hctx->queue->queuedata;
876
+
877
+ spin_lock_irq(&pf_spin_lock);
878
+ list_add_tail(&bd->rq->queuelist, &pf->rq_list);
847879 pf_request();
880
+ spin_unlock_irq(&pf_spin_lock);
881
+
882
+ return BLK_STS_OK;
848883 }
849884
850885 static int pf_next_buf(void)
....@@ -998,8 +1033,13 @@
9981033 pf_busy = 0;
9991034
10001035 if (register_blkdev(major, name)) {
1001
- for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++)
1036
+ for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
1037
+ if (!pf->disk)
1038
+ continue;
1039
+ blk_cleanup_queue(pf->disk->queue);
1040
+ blk_mq_free_tag_set(&pf->tag_set);
10021041 put_disk(pf->disk);
1042
+ }
10031043 return -EBUSY;
10041044 }
10051045
....@@ -1020,12 +1060,18 @@
10201060 int unit;
10211061 unregister_blkdev(major, name);
10221062 for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
1023
- if (!pf->present)
1063
+ if (!pf->disk)
10241064 continue;
1025
- del_gendisk(pf->disk);
1065
+
1066
+ if (pf->present)
1067
+ del_gendisk(pf->disk);
1068
+
10261069 blk_cleanup_queue(pf->disk->queue);
1070
+ blk_mq_free_tag_set(&pf->tag_set);
10271071 put_disk(pf->disk);
1028
- pi_release(pf->pi);
1072
+
1073
+ if (pf->present)
1074
+ pi_release(pf->pi);
10291075 }
10301076 }
10311077