@@ -560,12 +560,6 @@ static void nvme_rdma_free_queue(struct nvme_rdma_queue *queue)
560560 if (!test_and_clear_bit (NVME_RDMA_Q_ALLOCATED , & queue -> flags ))
561561 return ;
562562
563- if (nvme_rdma_queue_idx (queue ) == 0 ) {
564- nvme_rdma_free_qe (queue -> device -> dev ,
565- & queue -> ctrl -> async_event_sqe ,
566- sizeof (struct nvme_command ), DMA_TO_DEVICE );
567- }
568-
569563 nvme_rdma_destroy_queue_ib (queue );
570564 rdma_destroy_id (queue -> cm_id );
571565}
@@ -698,7 +692,7 @@ static struct blk_mq_tag_set *nvme_rdma_alloc_tagset(struct nvme_ctrl *nctrl,
698692 set = & ctrl -> tag_set ;
699693 memset (set , 0 , sizeof (* set ));
700694 set -> ops = & nvme_rdma_mq_ops ;
701- set -> queue_depth = nctrl -> opts -> queue_size ;
695+ set -> queue_depth = nctrl -> sqsize + 1 ;
702696 set -> reserved_tags = 1 ; /* fabric connect */
703697 set -> numa_node = NUMA_NO_NODE ;
704698 set -> flags = BLK_MQ_F_SHOULD_MERGE ;
@@ -734,11 +728,12 @@ static struct blk_mq_tag_set *nvme_rdma_alloc_tagset(struct nvme_ctrl *nctrl,
734728static void nvme_rdma_destroy_admin_queue (struct nvme_rdma_ctrl * ctrl ,
735729 bool remove )
736730{
737- nvme_rdma_stop_queue (& ctrl -> queues [0 ]);
738731 if (remove ) {
739732 blk_cleanup_queue (ctrl -> ctrl .admin_q );
740733 nvme_rdma_free_tagset (& ctrl -> ctrl , ctrl -> ctrl .admin_tagset );
741734 }
735+ nvme_rdma_free_qe (ctrl -> device -> dev , & ctrl -> async_event_sqe ,
736+ sizeof (struct nvme_command ), DMA_TO_DEVICE );
742737 nvme_rdma_free_queue (& ctrl -> queues [0 ]);
743738}
744739
@@ -755,11 +750,16 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl,
755750
756751 ctrl -> max_fr_pages = nvme_rdma_get_max_fr_pages (ctrl -> device -> dev );
757752
753+ error = nvme_rdma_alloc_qe (ctrl -> device -> dev , & ctrl -> async_event_sqe ,
754+ sizeof (struct nvme_command ), DMA_TO_DEVICE );
755+ if (error )
756+ goto out_free_queue ;
757+
758758 if (new ) {
759759 ctrl -> ctrl .admin_tagset = nvme_rdma_alloc_tagset (& ctrl -> ctrl , true);
760760 if (IS_ERR (ctrl -> ctrl .admin_tagset )) {
761761 error = PTR_ERR (ctrl -> ctrl .admin_tagset );
762- goto out_free_queue ;
762+ goto out_free_async_qe ;
763763 }
764764
765765 ctrl -> ctrl .admin_q = blk_mq_init_queue (& ctrl -> admin_tag_set );
@@ -795,12 +795,6 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl,
795795 if (error )
796796 goto out_stop_queue ;
797797
798- error = nvme_rdma_alloc_qe (ctrl -> queues [0 ].device -> dev ,
799- & ctrl -> async_event_sqe , sizeof (struct nvme_command ),
800- DMA_TO_DEVICE );
801- if (error )
802- goto out_stop_queue ;
803-
804798 return 0 ;
805799
806800out_stop_queue :
@@ -811,6 +805,9 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl,
811805out_free_tagset :
812806 if (new )
813807 nvme_rdma_free_tagset (& ctrl -> ctrl , ctrl -> ctrl .admin_tagset );
808+ out_free_async_qe :
809+ nvme_rdma_free_qe (ctrl -> device -> dev , & ctrl -> async_event_sqe ,
810+ sizeof (struct nvme_command ), DMA_TO_DEVICE );
814811out_free_queue :
815812 nvme_rdma_free_queue (& ctrl -> queues [0 ]);
816813 return error ;
@@ -819,7 +816,6 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl,
819816static void nvme_rdma_destroy_io_queues (struct nvme_rdma_ctrl * ctrl ,
820817 bool remove )
821818{
822- nvme_rdma_stop_io_queues (ctrl );
823819 if (remove ) {
824820 blk_cleanup_queue (ctrl -> ctrl .connect_q );
825821 nvme_rdma_free_tagset (& ctrl -> ctrl , ctrl -> ctrl .tagset );
@@ -888,9 +884,9 @@ static void nvme_rdma_free_ctrl(struct nvme_ctrl *nctrl)
888884 list_del (& ctrl -> list );
889885 mutex_unlock (& nvme_rdma_ctrl_mutex );
890886
891- kfree (ctrl -> queues );
892887 nvmf_free_options (nctrl -> opts );
893888free_ctrl :
889+ kfree (ctrl -> queues );
894890 kfree (ctrl );
895891}
896892
@@ -949,6 +945,7 @@ static void nvme_rdma_reconnect_ctrl_work(struct work_struct *work)
949945 return ;
950946
951947destroy_admin :
948+ nvme_rdma_stop_queue (& ctrl -> queues [0 ]);
952949 nvme_rdma_destroy_admin_queue (ctrl , false);
953950requeue :
954951 dev_info (ctrl -> ctrl .device , "Failed reconnect attempt %d\n" ,
@@ -965,12 +962,14 @@ static void nvme_rdma_error_recovery_work(struct work_struct *work)
965962
966963 if (ctrl -> ctrl .queue_count > 1 ) {
967964 nvme_stop_queues (& ctrl -> ctrl );
965+ nvme_rdma_stop_io_queues (ctrl );
968966 blk_mq_tagset_busy_iter (& ctrl -> tag_set ,
969967 nvme_cancel_request , & ctrl -> ctrl );
970968 nvme_rdma_destroy_io_queues (ctrl , false);
971969 }
972970
973971 blk_mq_quiesce_queue (ctrl -> ctrl .admin_q );
972+ nvme_rdma_stop_queue (& ctrl -> queues [0 ]);
974973 blk_mq_tagset_busy_iter (& ctrl -> admin_tag_set ,
975974 nvme_cancel_request , & ctrl -> ctrl );
976975 nvme_rdma_destroy_admin_queue (ctrl , false);
@@ -1736,6 +1735,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown)
17361735{
17371736 if (ctrl -> ctrl .queue_count > 1 ) {
17381737 nvme_stop_queues (& ctrl -> ctrl );
1738+ nvme_rdma_stop_io_queues (ctrl );
17391739 blk_mq_tagset_busy_iter (& ctrl -> tag_set ,
17401740 nvme_cancel_request , & ctrl -> ctrl );
17411741 nvme_rdma_destroy_io_queues (ctrl , shutdown );
@@ -1747,6 +1747,7 @@ static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl *ctrl, bool shutdown)
17471747 nvme_disable_ctrl (& ctrl -> ctrl , ctrl -> ctrl .cap );
17481748
17491749 blk_mq_quiesce_queue (ctrl -> ctrl .admin_q );
1750+ nvme_rdma_stop_queue (& ctrl -> queues [0 ]);
17501751 blk_mq_tagset_busy_iter (& ctrl -> admin_tag_set ,
17511752 nvme_cancel_request , & ctrl -> ctrl );
17521753 blk_mq_unquiesce_queue (ctrl -> ctrl .admin_q );
@@ -1932,11 +1933,6 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
19321933 goto out_free_ctrl ;
19331934 }
19341935
1935- ret = nvme_init_ctrl (& ctrl -> ctrl , dev , & nvme_rdma_ctrl_ops ,
1936- 0 /* no quirks, we're perfect! */ );
1937- if (ret )
1938- goto out_free_ctrl ;
1939-
19401936 INIT_DELAYED_WORK (& ctrl -> reconnect_work ,
19411937 nvme_rdma_reconnect_ctrl_work );
19421938 INIT_WORK (& ctrl -> err_work , nvme_rdma_error_recovery_work );
@@ -1950,14 +1946,19 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
19501946 ctrl -> queues = kcalloc (ctrl -> ctrl .queue_count , sizeof (* ctrl -> queues ),
19511947 GFP_KERNEL );
19521948 if (!ctrl -> queues )
1953- goto out_uninit_ctrl ;
1949+ goto out_free_ctrl ;
1950+
1951+ ret = nvme_init_ctrl (& ctrl -> ctrl , dev , & nvme_rdma_ctrl_ops ,
1952+ 0 /* no quirks, we're perfect! */ );
1953+ if (ret )
1954+ goto out_kfree_queues ;
19541955
19551956 changed = nvme_change_ctrl_state (& ctrl -> ctrl , NVME_CTRL_CONNECTING );
19561957 WARN_ON_ONCE (!changed );
19571958
19581959 ret = nvme_rdma_configure_admin_queue (ctrl , true);
19591960 if (ret )
1960- goto out_kfree_queues ;
1961+ goto out_uninit_ctrl ;
19611962
19621963 /* sanity check icdoff */
19631964 if (ctrl -> ctrl .icdoff ) {
@@ -1974,20 +1975,19 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
19741975 goto out_remove_admin_queue ;
19751976 }
19761977
1977- if (opts -> queue_size > ctrl -> ctrl .maxcmd ) {
1978- /* warn if maxcmd is lower than queue_size */
1979- dev_warn (ctrl -> ctrl .device ,
1980- "queue_size %zu > ctrl maxcmd %u, clamping down\n" ,
1981- opts -> queue_size , ctrl -> ctrl .maxcmd );
1982- opts -> queue_size = ctrl -> ctrl .maxcmd ;
1983- }
1984-
1978+ /* only warn if argument is too large here, will clamp later */
19851979 if (opts -> queue_size > ctrl -> ctrl .sqsize + 1 ) {
1986- /* warn if sqsize is lower than queue_size */
19871980 dev_warn (ctrl -> ctrl .device ,
19881981 "queue_size %zu > ctrl sqsize %u, clamping down\n" ,
19891982 opts -> queue_size , ctrl -> ctrl .sqsize + 1 );
1990- opts -> queue_size = ctrl -> ctrl .sqsize + 1 ;
1983+ }
1984+
1985+ /* warn if maxcmd is lower than sqsize+1 */
1986+ if (ctrl -> ctrl .sqsize + 1 > ctrl -> ctrl .maxcmd ) {
1987+ dev_warn (ctrl -> ctrl .device ,
1988+ "sqsize %u > ctrl maxcmd %u, clamping down\n" ,
1989+ ctrl -> ctrl .sqsize + 1 , ctrl -> ctrl .maxcmd );
1990+ ctrl -> ctrl .sqsize = ctrl -> ctrl .maxcmd - 1 ;
19911991 }
19921992
19931993 if (opts -> nr_io_queues ) {
@@ -2013,15 +2013,16 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
20132013 return & ctrl -> ctrl ;
20142014
20152015out_remove_admin_queue :
2016+ nvme_rdma_stop_queue (& ctrl -> queues [0 ]);
20162017 nvme_rdma_destroy_admin_queue (ctrl , true);
2017- out_kfree_queues :
2018- kfree (ctrl -> queues );
20192018out_uninit_ctrl :
20202019 nvme_uninit_ctrl (& ctrl -> ctrl );
20212020 nvme_put_ctrl (& ctrl -> ctrl );
20222021 if (ret > 0 )
20232022 ret = - EIO ;
20242023 return ERR_PTR (ret );
2024+ out_kfree_queues :
2025+ kfree (ctrl -> queues );
20252026out_free_ctrl :
20262027 kfree (ctrl );
20272028 return ERR_PTR (ret );
0 commit comments