1313#include <linux/mutex.h>
1414#include <linux/kobject.h>
1515#include <linux/slab.h>
16+ #include <linux/blk-mq-pci.h>
1617#include <scsi/scsi_tcq.h>
1718#include <scsi/scsicam.h>
1819#include <scsi/scsi_transport.h>
@@ -254,6 +255,7 @@ static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
254255static void qla2x00_clear_drv_active (struct qla_hw_data * );
255256static void qla2x00_free_device (scsi_qla_host_t * );
256257static void qla83xx_disable_laser (scsi_qla_host_t * vha );
258+ static int qla2xxx_map_queues (struct Scsi_Host * shost );
257259
258260struct scsi_host_template qla2xxx_driver_template = {
259261 .module = THIS_MODULE ,
@@ -273,6 +275,7 @@ struct scsi_host_template qla2xxx_driver_template = {
273275 .scan_finished = qla2xxx_scan_finished ,
274276 .scan_start = qla2xxx_scan_start ,
275277 .change_queue_depth = scsi_change_queue_depth ,
278+ .map_queues = qla2xxx_map_queues ,
276279 .this_id = -1 ,
277280 .cmd_per_lun = 3 ,
278281 .use_clustering = ENABLE_CLUSTERING ,
@@ -738,16 +741,26 @@ qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
738741 struct scsi_qla_host * base_vha = pci_get_drvdata (ha -> pdev );
739742 srb_t * sp ;
740743 int rval ;
741- struct qla_qpair * qpair ;
744+ struct qla_qpair * qpair = NULL ;
745+ uint32_t tag ;
746+ uint16_t hwq ;
742747
743748 if (unlikely (test_bit (UNLOADING , & base_vha -> dpc_flags ))) {
744749 cmd -> result = DID_NO_CONNECT << 16 ;
745750 goto qc24_fail_command ;
746751 }
747752
748- if (vha -> vp_idx && vha -> qpair ) {
749- qpair = vha -> qpair ;
750- return qla2xxx_mqueuecommand (host , cmd , qpair );
753+ if (ha -> mqenable ) {
754+ if (shost_use_blk_mq (vha -> host )) {
755+ tag = blk_mq_unique_tag (cmd -> request );
756+ hwq = blk_mq_unique_tag_to_hwq (tag );
757+ qpair = ha -> queue_pair_map [hwq ];
758+ } else if (vha -> vp_idx && vha -> qpair ) {
759+ qpair = vha -> qpair ;
760+ }
761+
762+ if (qpair )
763+ return qla2xxx_mqueuecommand (host , cmd , qpair );
751764 }
752765
753766 if (ha -> flags .eeh_busy ) {
@@ -2509,6 +2522,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
25092522 uint16_t req_length = 0 , rsp_length = 0 ;
25102523 struct req_que * req = NULL ;
25112524 struct rsp_que * rsp = NULL ;
2525+ int i ;
25122526
25132527 bars = pci_select_bars (pdev , IORESOURCE_MEM | IORESOURCE_IO );
25142528 sht = & qla2xxx_driver_template ;
@@ -2874,6 +2888,16 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
28742888 goto probe_init_failed ;
28752889 }
28762890
2891+ if (ha -> mqenable && shost_use_blk_mq (host )) {
2892+ /* number of hardware queues supported by blk/scsi-mq*/
2893+ host -> nr_hw_queues = ha -> max_qpairs ;
2894+
2895+ ql_dbg (ql_dbg_init , base_vha , 0x0192 ,
2896+ "blk/scsi-mq enabled, HW queues = %d.\n" , host -> nr_hw_queues );
2897+ } else
2898+ ql_dbg (ql_dbg_init , base_vha , 0x0193 ,
2899+ "blk/scsi-mq disabled.\n" );
2900+
28772901 qlt_probe_one_stage1 (base_vha , ha );
28782902
28792903 pci_save_state (pdev );
@@ -2965,8 +2989,14 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
29652989 host -> can_queue , base_vha -> req ,
29662990 base_vha -> mgmt_svr_loop_id , host -> sg_tablesize );
29672991
2968- if (ha -> mqenable )
2992+ if (ha -> mqenable ) {
29692993 ha -> wq = alloc_workqueue ("qla2xxx_wq" , WQ_MEM_RECLAIM , 1 );
2994+ /* Create start of day qpairs for Block MQ */
2995+ if (shost_use_blk_mq (host )) {
2996+ for (i = 0 ; i < ha -> max_qpairs ; i ++ )
2997+ qla2xxx_create_qpair (base_vha , 5 , 0 );
2998+ }
2999+ }
29703000
29713001 if (ha -> flags .running_gold_fw )
29723002 goto skip_dpc ;
@@ -6109,6 +6139,13 @@ qla83xx_disable_laser(scsi_qla_host_t *vha)
61096139 qla83xx_wr_reg (vha , reg , data );
61106140}
61116141
6142+ static int qla2xxx_map_queues (struct Scsi_Host * shost )
6143+ {
6144+ scsi_qla_host_t * vha = (scsi_qla_host_t * )shost -> hostdata ;
6145+
6146+ return blk_mq_pci_map_queues (& shost -> tag_set , vha -> hw -> pdev );
6147+ }
6148+
61126149static const struct pci_error_handlers qla2xxx_err_handler = {
61136150 .error_detected = qla2xxx_pci_error_detected ,
61146151 .mmio_enabled = qla2xxx_pci_mmio_enabled ,
0 commit comments