12
12
#include <linux/pci.h>
13
13
#include <linux/skbuff.h>
14
14
#include <linux/interrupt.h>
15
+ #include <linux/irq.h>
15
16
#include <linux/spinlock.h>
16
17
#include <linux/workqueue.h>
17
18
#include <linux/if_ether.h>
19
+ #include <linux/blk-mq-pci.h>
18
20
#include <scsi/fc/fc_fip.h>
19
21
#include <scsi/scsi_host.h>
20
22
#include <scsi/scsi_transport.h>
@@ -114,6 +116,7 @@ static const struct scsi_host_template fnic_host_template = {
114
116
.shost_groups = fnic_host_groups ,
115
117
.track_queue_depth = 1 ,
116
118
.cmd_size = sizeof (struct fnic_cmd_priv ),
119
+ .map_queues = fnic_mq_map_queues_cpus ,
117
120
};
118
121
119
122
static void
@@ -390,7 +393,7 @@ static int fnic_notify_set(struct fnic *fnic)
390
393
err = vnic_dev_notify_set (fnic -> vdev , -1 );
391
394
break ;
392
395
case VNIC_DEV_INTR_MODE_MSIX :
393
- err = vnic_dev_notify_set (fnic -> vdev , FNIC_MSIX_ERR_NOTIFY );
396
+ err = vnic_dev_notify_set (fnic -> vdev , fnic -> wq_copy_count + fnic -> copy_wq_base );
394
397
break ;
395
398
default :
396
399
shost_printk (KERN_ERR , fnic -> lport -> host ,
@@ -563,11 +566,6 @@ static int fnic_scsi_drv_init(struct fnic *fnic)
563
566
host -> max_cmd_len = FCOE_MAX_CMD_LEN ;
564
567
565
568
host -> nr_hw_queues = fnic -> wq_copy_count ;
566
- if (host -> nr_hw_queues > 1 )
567
- shost_printk (KERN_ERR , host ,
568
- "fnic: blk-mq is not supported" );
569
-
570
- host -> nr_hw_queues = fnic -> wq_copy_count = 1 ;
571
569
572
570
shost_printk (KERN_INFO , host ,
573
571
"fnic: can_queue: %d max_lun: %llu" ,
@@ -580,6 +578,32 @@ static int fnic_scsi_drv_init(struct fnic *fnic)
580
578
return 0 ;
581
579
}
582
580
581
+ void fnic_mq_map_queues_cpus (struct Scsi_Host * host )
582
+ {
583
+ struct fc_lport * lp = shost_priv (host );
584
+ struct fnic * fnic = lport_priv (lp );
585
+ struct pci_dev * l_pdev = fnic -> pdev ;
586
+ int intr_mode = fnic -> config .intr_mode ;
587
+ struct blk_mq_queue_map * qmap = & host -> tag_set .map [HCTX_TYPE_DEFAULT ];
588
+
589
+ if (intr_mode == VNIC_DEV_INTR_MODE_MSI || intr_mode == VNIC_DEV_INTR_MODE_INTX ) {
590
+ FNIC_MAIN_DBG (KERN_ERR , fnic -> lport -> host , fnic -> fnic_num ,
591
+ "intr_mode is not msix\n" );
592
+ return ;
593
+ }
594
+
595
+ FNIC_MAIN_DBG (KERN_INFO , fnic -> lport -> host , fnic -> fnic_num ,
596
+ "qmap->nr_queues: %d\n" , qmap -> nr_queues );
597
+
598
+ if (l_pdev == NULL ) {
599
+ FNIC_MAIN_DBG (KERN_ERR , fnic -> lport -> host , fnic -> fnic_num ,
600
+ "l_pdev is null\n" );
601
+ return ;
602
+ }
603
+
604
+ blk_mq_pci_map_queues (qmap , l_pdev , FNIC_PCI_OFFSET );
605
+ }
606
+
583
607
static int fnic_probe (struct pci_dev * pdev , const struct pci_device_id * ent )
584
608
{
585
609
struct Scsi_Host * host ;
@@ -590,6 +614,7 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
590
614
int fnic_id = 0 ;
591
615
int i ;
592
616
unsigned long flags ;
617
+ int hwq ;
593
618
594
619
/*
595
620
* Allocate SCSI Host and set up association between host,
@@ -613,8 +638,8 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
613
638
}
614
639
fnic -> lport = lp ;
615
640
fnic -> ctlr .lp = lp ;
616
-
617
641
fnic -> link_events = 0 ;
642
+ fnic -> pdev = pdev ;
618
643
619
644
snprintf (fnic -> name , sizeof (fnic -> name ) - 1 , "%s%d" , DRV_NAME ,
620
645
host -> host_no );
@@ -623,11 +648,6 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
623
648
fnic -> fnic_num = fnic_id ;
624
649
fnic_stats_debugfs_init (fnic );
625
650
626
- /* Setup PCI resources */
627
- pci_set_drvdata (pdev , fnic );
628
-
629
- fnic -> pdev = pdev ;
630
-
631
651
err = pci_enable_device (pdev );
632
652
if (err ) {
633
653
shost_printk (KERN_ERR , fnic -> lport -> host ,
@@ -729,7 +749,8 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
729
749
goto err_out_dev_close ;
730
750
}
731
751
732
- fnic_scsi_drv_init (fnic );
752
+ /* Setup PCI resources */
753
+ pci_set_drvdata (pdev , fnic );
733
754
734
755
fnic_get_res_counts (fnic );
735
756
@@ -749,6 +770,16 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
749
770
goto err_out_clear_intr ;
750
771
}
751
772
773
+ fnic_scsi_drv_init (fnic );
774
+
775
+ for (hwq = 0 ; hwq < fnic -> wq_copy_count ; hwq ++ ) {
776
+ fnic -> sw_copy_wq [hwq ].ioreq_table_size = fnic -> fnic_max_tag_id ;
777
+ fnic -> sw_copy_wq [hwq ].io_req_table =
778
+ kzalloc ((fnic -> sw_copy_wq [hwq ].ioreq_table_size + 1 ) *
779
+ sizeof (struct fnic_io_req * ), GFP_KERNEL );
780
+ }
781
+ shost_printk (KERN_INFO , fnic -> lport -> host , "fnic copy wqs: %d, Q0 ioreq table size: %d\n" ,
782
+ fnic -> wq_copy_count , fnic -> sw_copy_wq [0 ].ioreq_table_size );
752
783
753
784
/* initialize all fnic locks */
754
785
spin_lock_init (& fnic -> fnic_lock );
@@ -835,16 +866,32 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
835
866
836
867
/* allocate RQ buffers and post them to RQ*/
837
868
for (i = 0 ; i < fnic -> rq_count ; i ++ ) {
838
- vnic_rq_enable (& fnic -> rq [i ]);
839
869
err = vnic_rq_fill (& fnic -> rq [i ], fnic_alloc_rq_frame );
840
870
if (err ) {
841
871
shost_printk (KERN_ERR , fnic -> lport -> host ,
842
872
"fnic_alloc_rq_frame can't alloc "
843
873
"frame\n" );
844
- goto err_out_free_rq_buf ;
874
+ goto err_out_rq_buf ;
845
875
}
846
876
}
847
877
878
+ /* Enable all queues */
879
+ for (i = 0 ; i < fnic -> raw_wq_count ; i ++ )
880
+ vnic_wq_enable (& fnic -> wq [i ]);
881
+ for (i = 0 ; i < fnic -> rq_count ; i ++ ) {
882
+ if (!ioread32 (& fnic -> rq [i ].ctrl -> enable ))
883
+ vnic_rq_enable (& fnic -> rq [i ]);
884
+ }
885
+ for (i = 0 ; i < fnic -> wq_copy_count ; i ++ )
886
+ vnic_wq_copy_enable (& fnic -> hw_copy_wq [i ]);
887
+
888
+ err = fnic_request_intr (fnic );
889
+ if (err ) {
890
+ shost_printk (KERN_ERR , fnic -> lport -> host ,
891
+ "Unable to request irq.\n" );
892
+ goto err_out_request_intr ;
893
+ }
894
+
848
895
/*
849
896
* Initialization done with PCI system, hardware, firmware.
850
897
* Add host to SCSI
@@ -853,9 +900,10 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
853
900
if (err ) {
854
901
shost_printk (KERN_ERR , fnic -> lport -> host ,
855
902
"fnic: scsi_add_host failed...exiting\n" );
856
- goto err_out_free_rq_buf ;
903
+ goto err_out_scsi_add_host ;
857
904
}
858
905
906
+
859
907
/* Start local port initiatialization */
860
908
861
909
lp -> link_up = 0 ;
@@ -879,7 +927,7 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
879
927
if (!fc_exch_mgr_alloc (lp , FC_CLASS_3 , FCPIO_HOST_EXCH_RANGE_START ,
880
928
FCPIO_HOST_EXCH_RANGE_END , NULL )) {
881
929
err = - ENOMEM ;
882
- goto err_out_remove_scsi_host ;
930
+ goto err_out_fc_exch_mgr_alloc ;
883
931
}
884
932
885
933
fc_lport_init_stats (lp );
@@ -907,21 +955,8 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
907
955
skb_queue_head_init (& fnic -> frame_queue );
908
956
skb_queue_head_init (& fnic -> tx_queue );
909
957
910
- /* Enable all queues */
911
- for (i = 0 ; i < fnic -> raw_wq_count ; i ++ )
912
- vnic_wq_enable (& fnic -> wq [i ]);
913
- for (i = 0 ; i < fnic -> wq_copy_count ; i ++ )
914
- vnic_wq_copy_enable (& fnic -> hw_copy_wq [i ]);
915
-
916
958
fc_fabric_login (lp );
917
959
918
- err = fnic_request_intr (fnic );
919
- if (err ) {
920
- shost_printk (KERN_ERR , fnic -> lport -> host ,
921
- "Unable to request irq.\n" );
922
- goto err_out_free_exch_mgr ;
923
- }
924
-
925
960
vnic_dev_enable (fnic -> vdev );
926
961
927
962
for (i = 0 ; i < fnic -> intr_count ; i ++ )
@@ -933,12 +968,15 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
933
968
934
969
err_out_free_exch_mgr :
935
970
fc_exch_mgr_free (lp );
936
- err_out_remove_scsi_host :
971
+ err_out_fc_exch_mgr_alloc :
937
972
fc_remove_host (lp -> host );
938
973
scsi_remove_host (lp -> host );
939
- err_out_free_rq_buf :
974
+ err_out_scsi_add_host :
975
+ fnic_free_intr (fnic );
976
+ err_out_request_intr :
940
977
for (i = 0 ; i < fnic -> rq_count ; i ++ )
941
978
vnic_rq_clean (& fnic -> rq [i ], fnic_free_rq_buf );
979
+ err_out_rq_buf :
942
980
vnic_dev_notify_unset (fnic -> vdev );
943
981
err_out_free_max_pool :
944
982
mempool_destroy (fnic -> io_sgl_pool [FNIC_SGL_CACHE_MAX ]);
@@ -947,6 +985,8 @@ static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
947
985
err_out_free_ioreq_pool :
948
986
mempool_destroy (fnic -> io_req_pool );
949
987
err_out_free_resources :
988
+ for (hwq = 0 ; hwq < fnic -> wq_copy_count ; hwq ++ )
989
+ kfree (fnic -> sw_copy_wq [hwq ].io_req_table );
950
990
fnic_free_vnic_resources (fnic );
951
991
err_out_clear_intr :
952
992
fnic_clear_intr_mode (fnic );
@@ -975,6 +1015,7 @@ static void fnic_remove(struct pci_dev *pdev)
975
1015
struct fnic * fnic = pci_get_drvdata (pdev );
976
1016
struct fc_lport * lp = fnic -> lport ;
977
1017
unsigned long flags ;
1018
+ int hwq ;
978
1019
979
1020
/*
980
1021
* Mark state so that the workqueue thread stops forwarding
@@ -1035,6 +1076,8 @@ static void fnic_remove(struct pci_dev *pdev)
1035
1076
1036
1077
fc_remove_host (fnic -> lport -> host );
1037
1078
scsi_remove_host (fnic -> lport -> host );
1079
+ for (hwq = 0 ; hwq < fnic -> wq_copy_count ; hwq ++ )
1080
+ kfree (fnic -> sw_copy_wq [hwq ].io_req_table );
1038
1081
fc_exch_mgr_free (fnic -> lport );
1039
1082
vnic_dev_notify_unset (fnic -> vdev );
1040
1083
fnic_free_intr (fnic );
0 commit comments