16
16
#include <linux/pci.h>
17
17
#include <linux/slab.h>
18
18
#include <linux/spinlock.h>
19
- #include <linux/blkdev .h>
19
+ #include <linux/blk-mq .h>
20
20
#include <linux/sched.h>
21
21
#include <linux/interrupt.h>
22
22
#include <linux/compiler.h>
@@ -244,6 +244,7 @@ struct carm_port {
244
244
unsigned int port_no ;
245
245
struct gendisk * disk ;
246
246
struct carm_host * host ;
247
+ struct blk_mq_tag_set tag_set ;
247
248
248
249
/* attached device characteristics */
249
250
u64 capacity ;
@@ -279,6 +280,7 @@ struct carm_host {
279
280
unsigned int state ;
280
281
u32 fw_ver ;
281
282
283
+ struct blk_mq_tag_set tag_set ;
282
284
struct request_queue * oob_q ;
283
285
unsigned int n_oob ;
284
286
@@ -750,7 +752,7 @@ static inline void carm_end_request_queued(struct carm_host *host,
750
752
struct request * req = crq -> rq ;
751
753
int rc ;
752
754
753
- __blk_end_request_all (req , error );
755
+ blk_mq_end_request (req , error );
754
756
755
757
rc = carm_put_request (host , crq );
756
758
assert (rc == 0 );
@@ -760,7 +762,7 @@ static inline void carm_push_q (struct carm_host *host, struct request_queue *q)
760
762
{
761
763
unsigned int idx = host -> wait_q_prod % CARM_MAX_WAIT_Q ;
762
764
763
- blk_stop_queue (q );
765
+ blk_mq_stop_hw_queues (q );
764
766
VPRINTK ("STOPPED QUEUE %p\n" , q );
765
767
766
768
host -> wait_q [idx ] = q ;
@@ -785,7 +787,7 @@ static inline void carm_round_robin(struct carm_host *host)
785
787
{
786
788
struct request_queue * q = carm_pop_q (host );
787
789
if (q ) {
788
- blk_start_queue (q );
790
+ blk_mq_start_hw_queues (q );
789
791
VPRINTK ("STARTED QUEUE %p\n" , q );
790
792
}
791
793
}
@@ -802,62 +804,62 @@ static inline void carm_end_rq(struct carm_host *host, struct carm_request *crq,
802
804
}
803
805
}
804
806
805
- static void carm_oob_rq_fn (struct request_queue * q )
807
+ static blk_status_t carm_oob_queue_rq (struct blk_mq_hw_ctx * hctx ,
808
+ const struct blk_mq_queue_data * bd )
806
809
{
810
+ struct request_queue * q = hctx -> queue ;
807
811
struct carm_host * host = q -> queuedata ;
808
812
struct carm_request * crq ;
809
- struct request * rq ;
810
813
int rc ;
811
814
812
- while (1 ) {
813
- DPRINTK ("get req\n" );
814
- rq = blk_fetch_request (q );
815
- if (!rq )
816
- break ;
815
+ blk_mq_start_request (bd -> rq );
817
816
818
- crq = rq -> special ;
819
- assert (crq != NULL );
820
- assert (crq -> rq == rq );
817
+ spin_lock_irq (& host -> lock );
821
818
822
- crq -> n_elem = 0 ;
819
+ crq = bd -> rq -> special ;
820
+ assert (crq != NULL );
821
+ assert (crq -> rq == bd -> rq );
823
822
824
- DPRINTK ("send req\n" );
825
- rc = carm_send_msg (host , crq );
826
- if (rc ) {
827
- blk_requeue_request (q , rq );
828
- carm_push_q (host , q );
829
- return ; /* call us again later, eventually */
830
- }
823
+ crq -> n_elem = 0 ;
824
+
825
+ DPRINTK ("send req\n" );
826
+ rc = carm_send_msg (host , crq );
827
+ if (rc ) {
828
+ carm_push_q (host , q );
829
+ spin_unlock_irq (& host -> lock );
830
+ return BLK_STS_DEV_RESOURCE ;
831
831
}
832
+
833
+ spin_unlock_irq (& host -> lock );
834
+ return BLK_STS_OK ;
832
835
}
833
836
834
- static void carm_rq_fn (struct request_queue * q )
837
+ static blk_status_t carm_queue_rq (struct blk_mq_hw_ctx * hctx ,
838
+ const struct blk_mq_queue_data * bd )
835
839
{
840
+ struct request_queue * q = hctx -> queue ;
836
841
struct carm_port * port = q -> queuedata ;
837
842
struct carm_host * host = port -> host ;
838
843
struct carm_msg_rw * msg ;
839
844
struct carm_request * crq ;
840
- struct request * rq ;
845
+ struct request * rq = bd -> rq ;
841
846
struct scatterlist * sg ;
842
847
int writing = 0 , pci_dir , i , n_elem , rc ;
843
848
u32 tmp ;
844
849
unsigned int msg_size ;
845
850
846
- queue_one_request :
847
- VPRINTK ("get req\n" );
848
- rq = blk_peek_request (q );
849
- if (!rq )
850
- return ;
851
+ blk_mq_start_request (rq );
852
+
853
+ spin_lock_irq (& host -> lock );
851
854
852
855
crq = carm_get_request (host );
853
856
if (!crq ) {
854
857
carm_push_q (host , q );
855
- return ; /* call us again later, eventually */
858
+ spin_unlock_irq (& host -> lock );
859
+ return BLK_STS_DEV_RESOURCE ;
856
860
}
857
861
crq -> rq = rq ;
858
862
859
- blk_start_request (rq );
860
-
861
863
if (rq_data_dir (rq ) == WRITE ) {
862
864
writing = 1 ;
863
865
pci_dir = PCI_DMA_TODEVICE ;
@@ -869,15 +871,19 @@ static void carm_rq_fn(struct request_queue *q)
869
871
sg = & crq -> sg [0 ];
870
872
n_elem = blk_rq_map_sg (q , rq , sg );
871
873
if (n_elem <= 0 ) {
874
+ /* request with no s/g entries? */
872
875
carm_end_rq (host , crq , BLK_STS_IOERR );
873
- return ; /* request with no s/g entries? */
876
+ spin_unlock_irq (& host -> lock );
877
+ return BLK_STS_IOERR ;
874
878
}
875
879
876
880
/* map scatterlist to PCI bus addresses */
877
881
n_elem = pci_map_sg (host -> pdev , sg , n_elem , pci_dir );
878
882
if (n_elem <= 0 ) {
883
+ /* request with no s/g entries? */
879
884
carm_end_rq (host , crq , BLK_STS_IOERR );
880
- return ; /* request with no s/g entries? */
885
+ spin_unlock_irq (& host -> lock );
886
+ return BLK_STS_IOERR ;
881
887
}
882
888
crq -> n_elem = n_elem ;
883
889
crq -> port = port ;
@@ -927,12 +933,13 @@ static void carm_rq_fn(struct request_queue *q)
927
933
rc = carm_send_msg (host , crq );
928
934
if (rc ) {
929
935
carm_put_request (host , crq );
930
- blk_requeue_request (q , rq );
931
936
carm_push_q (host , q );
932
- return ; /* call us again later, eventually */
937
+ spin_unlock_irq (& host -> lock );
938
+ return BLK_STS_DEV_RESOURCE ;
933
939
}
934
940
935
- goto queue_one_request ;
941
+ spin_unlock_irq (& host -> lock );
942
+ return BLK_STS_OK ;
936
943
}
937
944
938
945
static void carm_handle_array_info (struct carm_host * host ,
@@ -1485,6 +1492,14 @@ static int carm_init_host(struct carm_host *host)
1485
1492
return 0 ;
1486
1493
}
1487
1494
1495
+ static const struct blk_mq_ops carm_oob_mq_ops = {
1496
+ .queue_rq = carm_oob_queue_rq ,
1497
+ };
1498
+
1499
+ static const struct blk_mq_ops carm_mq_ops = {
1500
+ .queue_rq = carm_queue_rq ,
1501
+ };
1502
+
1488
1503
static int carm_init_disks (struct carm_host * host )
1489
1504
{
1490
1505
unsigned int i ;
@@ -1513,9 +1528,10 @@ static int carm_init_disks(struct carm_host *host)
1513
1528
disk -> fops = & carm_bd_ops ;
1514
1529
disk -> private_data = port ;
1515
1530
1516
- q = blk_init_queue (carm_rq_fn , & host -> lock );
1517
- if (!q ) {
1518
- rc = - ENOMEM ;
1531
+ q = blk_mq_init_sq_queue (& port -> tag_set , & carm_mq_ops ,
1532
+ max_queue , BLK_MQ_F_SHOULD_MERGE );
1533
+ if (IS_ERR (q )) {
1534
+ rc = PTR_ERR (q );
1519
1535
break ;
1520
1536
}
1521
1537
disk -> queue = q ;
@@ -1533,14 +1549,18 @@ static void carm_free_disks(struct carm_host *host)
1533
1549
unsigned int i ;
1534
1550
1535
1551
for (i = 0 ; i < CARM_MAX_PORTS ; i ++ ) {
1536
- struct gendisk * disk = host -> port [i ].disk ;
1552
+ struct carm_port * port = & host -> port [i ];
1553
+ struct gendisk * disk = port -> disk ;
1554
+
1537
1555
if (disk ) {
1538
1556
struct request_queue * q = disk -> queue ;
1539
1557
1540
1558
if (disk -> flags & GENHD_FL_UP )
1541
1559
del_gendisk (disk );
1542
- if (q )
1560
+ if (q ) {
1561
+ blk_mq_free_tag_set (& port -> tag_set );
1543
1562
blk_cleanup_queue (q );
1563
+ }
1544
1564
put_disk (disk );
1545
1565
}
1546
1566
}
@@ -1636,11 +1656,12 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1636
1656
goto err_out_iounmap ;
1637
1657
}
1638
1658
1639
- q = blk_init_queue (carm_oob_rq_fn , & host -> lock );
1640
- if (!q ) {
1659
+ q = blk_mq_init_sq_queue (& host -> tag_set , & carm_oob_mq_ops , 1 ,
1660
+ BLK_MQ_F_NO_SCHED );
1661
+ if (IS_ERR (q )) {
1641
1662
printk (KERN_ERR DRV_NAME "(%s): OOB queue alloc failure\n" ,
1642
1663
pci_name (pdev ));
1643
- rc = - ENOMEM ;
1664
+ rc = PTR_ERR ( q ) ;
1644
1665
goto err_out_pci_free ;
1645
1666
}
1646
1667
host -> oob_q = q ;
@@ -1705,6 +1726,7 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1705
1726
else if (host -> major == 161 )
1706
1727
clear_bit (1 , & carm_major_alloc );
1707
1728
blk_cleanup_queue (host -> oob_q );
1729
+ blk_mq_free_tag_set (& host -> tag_set );
1708
1730
err_out_pci_free :
1709
1731
pci_free_consistent (pdev , CARM_SHM_SIZE , host -> shm , host -> shm_dma );
1710
1732
err_out_iounmap :
@@ -1736,6 +1758,7 @@ static void carm_remove_one (struct pci_dev *pdev)
1736
1758
else if (host -> major == 161 )
1737
1759
clear_bit (1 , & carm_major_alloc );
1738
1760
blk_cleanup_queue (host -> oob_q );
1761
+ blk_mq_free_tag_set (& host -> tag_set );
1739
1762
pci_free_consistent (pdev , CARM_SHM_SIZE , host -> shm , host -> shm_dma );
1740
1763
iounmap (host -> mmio );
1741
1764
kfree (host );
0 commit comments