2 * NVMe over Fabrics RDMA host code.
3 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/err.h>
19 #include <linux/string.h>
20 #include <linux/atomic.h>
21 #include <linux/blk-mq.h>
22 #include <linux/types.h>
23 #include <linux/list.h>
24 #include <linux/mutex.h>
25 #include <linux/scatterlist.h>
26 #include <linux/nvme.h>
27 #include <asm/unaligned.h>
29 #include <rdma/ib_verbs.h>
30 #include <rdma/rdma_cm.h>
31 #include <linux/nvme-rdma.h>
37 #define NVME_RDMA_CONNECT_TIMEOUT_MS 1000 /* 1 second */
39 #define NVME_RDMA_MAX_SEGMENT_SIZE 0xffffff /* 24-bit SGL field */
41 #define NVME_RDMA_MAX_SEGMENTS 256
43 #define NVME_RDMA_MAX_INLINE_SEGMENTS 1
46 * We handle AEN commands ourselves and don't even let the
47 * block layer know about them.
49 #define NVME_RDMA_NR_AEN_COMMANDS 1
50 #define NVME_RDMA_AQ_BLKMQ_DEPTH \
51 (NVMF_AQ_DEPTH - NVME_RDMA_NR_AEN_COMMANDS)
53 struct nvme_rdma_device
{
54 struct ib_device
*dev
;
57 struct list_head entry
;
66 struct nvme_rdma_queue
;
67 struct nvme_rdma_request
{
68 struct nvme_request req
;
70 struct nvme_rdma_qe sqe
;
71 struct ib_sge sge
[1 + NVME_RDMA_MAX_INLINE_SEGMENTS
];
75 struct ib_reg_wr reg_wr
;
76 struct ib_cqe reg_cqe
;
77 struct nvme_rdma_queue
*queue
;
78 struct sg_table sg_table
;
79 struct scatterlist first_sgl
[];
82 enum nvme_rdma_queue_flags
{
83 NVME_RDMA_Q_CONNECTED
= (1 << 0),
84 NVME_RDMA_IB_QUEUE_ALLOCATED
= (1 << 1),
85 NVME_RDMA_Q_DELETING
= (1 << 2),
86 NVME_RDMA_Q_LIVE
= (1 << 3),
89 struct nvme_rdma_queue
{
90 struct nvme_rdma_qe
*rsp_ring
;
93 size_t cmnd_capsule_len
;
94 struct nvme_rdma_ctrl
*ctrl
;
95 struct nvme_rdma_device
*device
;
100 struct rdma_cm_id
*cm_id
;
102 struct completion cm_done
;
105 struct nvme_rdma_ctrl
{
106 /* read and written in the hot path */
109 /* read only in the hot path */
110 struct nvme_rdma_queue
*queues
;
113 /* other member variables */
114 struct blk_mq_tag_set tag_set
;
115 struct work_struct delete_work
;
116 struct work_struct reset_work
;
117 struct work_struct err_work
;
119 struct nvme_rdma_qe async_event_sqe
;
122 struct delayed_work reconnect_work
;
124 struct list_head list
;
126 struct blk_mq_tag_set admin_tag_set
;
127 struct nvme_rdma_device
*device
;
133 struct sockaddr addr
;
134 struct sockaddr_in addr_in
;
137 struct sockaddr src_addr
;
138 struct sockaddr_in src_addr_in
;
141 struct nvme_ctrl ctrl
;
144 static inline struct nvme_rdma_ctrl
*to_rdma_ctrl(struct nvme_ctrl
*ctrl
)
146 return container_of(ctrl
, struct nvme_rdma_ctrl
, ctrl
);
149 static LIST_HEAD(device_list
);
150 static DEFINE_MUTEX(device_list_mutex
);
152 static LIST_HEAD(nvme_rdma_ctrl_list
);
153 static DEFINE_MUTEX(nvme_rdma_ctrl_mutex
);
155 static struct workqueue_struct
*nvme_rdma_wq
;
158 * Disabling this option makes small I/O goes faster, but is fundamentally
159 * unsafe. With it turned off we will have to register a global rkey that
160 * allows read and write access to all physical memory.
162 static bool register_always
= true;
163 module_param(register_always
, bool, 0444);
164 MODULE_PARM_DESC(register_always
,
165 "Use memory registration even for contiguous memory regions");
167 static int nvme_rdma_cm_handler(struct rdma_cm_id
*cm_id
,
168 struct rdma_cm_event
*event
);
169 static void nvme_rdma_recv_done(struct ib_cq
*cq
, struct ib_wc
*wc
);
171 /* XXX: really should move to a generic header sooner or later.. */
172 static inline void put_unaligned_le24(u32 val
, u8
*p
)
179 static inline int nvme_rdma_queue_idx(struct nvme_rdma_queue
*queue
)
181 return queue
- queue
->ctrl
->queues
;
184 static inline size_t nvme_rdma_inline_data_size(struct nvme_rdma_queue
*queue
)
186 return queue
->cmnd_capsule_len
- sizeof(struct nvme_command
);
189 static void nvme_rdma_free_qe(struct ib_device
*ibdev
, struct nvme_rdma_qe
*qe
,
190 size_t capsule_size
, enum dma_data_direction dir
)
192 ib_dma_unmap_single(ibdev
, qe
->dma
, capsule_size
, dir
);
196 static int nvme_rdma_alloc_qe(struct ib_device
*ibdev
, struct nvme_rdma_qe
*qe
,
197 size_t capsule_size
, enum dma_data_direction dir
)
199 qe
->data
= kzalloc(capsule_size
, GFP_KERNEL
);
203 qe
->dma
= ib_dma_map_single(ibdev
, qe
->data
, capsule_size
, dir
);
204 if (ib_dma_mapping_error(ibdev
, qe
->dma
)) {
212 static void nvme_rdma_free_ring(struct ib_device
*ibdev
,
213 struct nvme_rdma_qe
*ring
, size_t ib_queue_size
,
214 size_t capsule_size
, enum dma_data_direction dir
)
218 for (i
= 0; i
< ib_queue_size
; i
++)
219 nvme_rdma_free_qe(ibdev
, &ring
[i
], capsule_size
, dir
);
223 static struct nvme_rdma_qe
*nvme_rdma_alloc_ring(struct ib_device
*ibdev
,
224 size_t ib_queue_size
, size_t capsule_size
,
225 enum dma_data_direction dir
)
227 struct nvme_rdma_qe
*ring
;
230 ring
= kcalloc(ib_queue_size
, sizeof(struct nvme_rdma_qe
), GFP_KERNEL
);
234 for (i
= 0; i
< ib_queue_size
; i
++) {
235 if (nvme_rdma_alloc_qe(ibdev
, &ring
[i
], capsule_size
, dir
))
242 nvme_rdma_free_ring(ibdev
, ring
, i
, capsule_size
, dir
);
246 static void nvme_rdma_qp_event(struct ib_event
*event
, void *context
)
248 pr_debug("QP event %s (%d)\n",
249 ib_event_msg(event
->event
), event
->event
);
253 static int nvme_rdma_wait_for_cm(struct nvme_rdma_queue
*queue
)
255 wait_for_completion_interruptible_timeout(&queue
->cm_done
,
256 msecs_to_jiffies(NVME_RDMA_CONNECT_TIMEOUT_MS
) + 1);
257 return queue
->cm_error
;
260 static int nvme_rdma_create_qp(struct nvme_rdma_queue
*queue
, const int factor
)
262 struct nvme_rdma_device
*dev
= queue
->device
;
263 struct ib_qp_init_attr init_attr
;
266 memset(&init_attr
, 0, sizeof(init_attr
));
267 init_attr
.event_handler
= nvme_rdma_qp_event
;
269 init_attr
.cap
.max_send_wr
= factor
* queue
->queue_size
+ 1;
271 init_attr
.cap
.max_recv_wr
= queue
->queue_size
+ 1;
272 init_attr
.cap
.max_recv_sge
= 1;
273 init_attr
.cap
.max_send_sge
= 1 + NVME_RDMA_MAX_INLINE_SEGMENTS
;
274 init_attr
.sq_sig_type
= IB_SIGNAL_REQ_WR
;
275 init_attr
.qp_type
= IB_QPT_RC
;
276 init_attr
.send_cq
= queue
->ib_cq
;
277 init_attr
.recv_cq
= queue
->ib_cq
;
279 ret
= rdma_create_qp(queue
->cm_id
, dev
->pd
, &init_attr
);
281 queue
->qp
= queue
->cm_id
->qp
;
285 static int nvme_rdma_reinit_request(void *data
, struct request
*rq
)
287 struct nvme_rdma_ctrl
*ctrl
= data
;
288 struct nvme_rdma_device
*dev
= ctrl
->device
;
289 struct nvme_rdma_request
*req
= blk_mq_rq_to_pdu(rq
);
292 if (!req
->mr
->need_inval
)
295 ib_dereg_mr(req
->mr
);
297 req
->mr
= ib_alloc_mr(dev
->pd
, IB_MR_TYPE_MEM_REG
,
299 if (IS_ERR(req
->mr
)) {
300 ret
= PTR_ERR(req
->mr
);
305 req
->mr
->need_inval
= false;
311 static void __nvme_rdma_exit_request(struct nvme_rdma_ctrl
*ctrl
,
312 struct request
*rq
, unsigned int queue_idx
)
314 struct nvme_rdma_request
*req
= blk_mq_rq_to_pdu(rq
);
315 struct nvme_rdma_queue
*queue
= &ctrl
->queues
[queue_idx
];
316 struct nvme_rdma_device
*dev
= queue
->device
;
319 ib_dereg_mr(req
->mr
);
321 nvme_rdma_free_qe(dev
->dev
, &req
->sqe
, sizeof(struct nvme_command
),
325 static void nvme_rdma_exit_request(void *data
, struct request
*rq
,
326 unsigned int hctx_idx
, unsigned int rq_idx
)
328 return __nvme_rdma_exit_request(data
, rq
, hctx_idx
+ 1);
331 static void nvme_rdma_exit_admin_request(void *data
, struct request
*rq
,
332 unsigned int hctx_idx
, unsigned int rq_idx
)
334 return __nvme_rdma_exit_request(data
, rq
, 0);
337 static int __nvme_rdma_init_request(struct nvme_rdma_ctrl
*ctrl
,
338 struct request
*rq
, unsigned int queue_idx
)
340 struct nvme_rdma_request
*req
= blk_mq_rq_to_pdu(rq
);
341 struct nvme_rdma_queue
*queue
= &ctrl
->queues
[queue_idx
];
342 struct nvme_rdma_device
*dev
= queue
->device
;
343 struct ib_device
*ibdev
= dev
->dev
;
346 BUG_ON(queue_idx
>= ctrl
->queue_count
);
348 ret
= nvme_rdma_alloc_qe(ibdev
, &req
->sqe
, sizeof(struct nvme_command
),
353 req
->mr
= ib_alloc_mr(dev
->pd
, IB_MR_TYPE_MEM_REG
,
355 if (IS_ERR(req
->mr
)) {
356 ret
= PTR_ERR(req
->mr
);
365 nvme_rdma_free_qe(dev
->dev
, &req
->sqe
, sizeof(struct nvme_command
),
370 static int nvme_rdma_init_request(void *data
, struct request
*rq
,
371 unsigned int hctx_idx
, unsigned int rq_idx
,
372 unsigned int numa_node
)
374 return __nvme_rdma_init_request(data
, rq
, hctx_idx
+ 1);
377 static int nvme_rdma_init_admin_request(void *data
, struct request
*rq
,
378 unsigned int hctx_idx
, unsigned int rq_idx
,
379 unsigned int numa_node
)
381 return __nvme_rdma_init_request(data
, rq
, 0);
384 static int nvme_rdma_init_hctx(struct blk_mq_hw_ctx
*hctx
, void *data
,
385 unsigned int hctx_idx
)
387 struct nvme_rdma_ctrl
*ctrl
= data
;
388 struct nvme_rdma_queue
*queue
= &ctrl
->queues
[hctx_idx
+ 1];
390 BUG_ON(hctx_idx
>= ctrl
->queue_count
);
392 hctx
->driver_data
= queue
;
396 static int nvme_rdma_init_admin_hctx(struct blk_mq_hw_ctx
*hctx
, void *data
,
397 unsigned int hctx_idx
)
399 struct nvme_rdma_ctrl
*ctrl
= data
;
400 struct nvme_rdma_queue
*queue
= &ctrl
->queues
[0];
402 BUG_ON(hctx_idx
!= 0);
404 hctx
->driver_data
= queue
;
408 static void nvme_rdma_free_dev(struct kref
*ref
)
410 struct nvme_rdma_device
*ndev
=
411 container_of(ref
, struct nvme_rdma_device
, ref
);
413 mutex_lock(&device_list_mutex
);
414 list_del(&ndev
->entry
);
415 mutex_unlock(&device_list_mutex
);
417 ib_dealloc_pd(ndev
->pd
);
421 static void nvme_rdma_dev_put(struct nvme_rdma_device
*dev
)
423 kref_put(&dev
->ref
, nvme_rdma_free_dev
);
426 static int nvme_rdma_dev_get(struct nvme_rdma_device
*dev
)
428 return kref_get_unless_zero(&dev
->ref
);
431 static struct nvme_rdma_device
*
432 nvme_rdma_find_get_device(struct rdma_cm_id
*cm_id
)
434 struct nvme_rdma_device
*ndev
;
436 mutex_lock(&device_list_mutex
);
437 list_for_each_entry(ndev
, &device_list
, entry
) {
438 if (ndev
->dev
->node_guid
== cm_id
->device
->node_guid
&&
439 nvme_rdma_dev_get(ndev
))
443 ndev
= kzalloc(sizeof(*ndev
), GFP_KERNEL
);
447 ndev
->dev
= cm_id
->device
;
448 kref_init(&ndev
->ref
);
450 ndev
->pd
= ib_alloc_pd(ndev
->dev
,
451 register_always
? 0 : IB_PD_UNSAFE_GLOBAL_RKEY
);
452 if (IS_ERR(ndev
->pd
))
455 if (!(ndev
->dev
->attrs
.device_cap_flags
&
456 IB_DEVICE_MEM_MGT_EXTENSIONS
)) {
457 dev_err(&ndev
->dev
->dev
,
458 "Memory registrations not supported.\n");
462 list_add(&ndev
->entry
, &device_list
);
464 mutex_unlock(&device_list_mutex
);
468 ib_dealloc_pd(ndev
->pd
);
472 mutex_unlock(&device_list_mutex
);
476 static void nvme_rdma_destroy_queue_ib(struct nvme_rdma_queue
*queue
)
478 struct nvme_rdma_device
*dev
;
479 struct ib_device
*ibdev
;
481 if (!test_and_clear_bit(NVME_RDMA_IB_QUEUE_ALLOCATED
, &queue
->flags
))
486 rdma_destroy_qp(queue
->cm_id
);
487 ib_free_cq(queue
->ib_cq
);
489 nvme_rdma_free_ring(ibdev
, queue
->rsp_ring
, queue
->queue_size
,
490 sizeof(struct nvme_completion
), DMA_FROM_DEVICE
);
492 nvme_rdma_dev_put(dev
);
495 static int nvme_rdma_create_queue_ib(struct nvme_rdma_queue
*queue
,
496 struct nvme_rdma_device
*dev
)
498 struct ib_device
*ibdev
= dev
->dev
;
499 const int send_wr_factor
= 3; /* MR, SEND, INV */
500 const int cq_factor
= send_wr_factor
+ 1; /* + RECV */
501 int comp_vector
, idx
= nvme_rdma_queue_idx(queue
);
508 * The admin queue is barely used once the controller is live, so don't
509 * bother to spread it out.
514 comp_vector
= idx
% ibdev
->num_comp_vectors
;
517 /* +1 for ib_stop_cq */
518 queue
->ib_cq
= ib_alloc_cq(dev
->dev
, queue
,
519 cq_factor
* queue
->queue_size
+ 1, comp_vector
,
521 if (IS_ERR(queue
->ib_cq
)) {
522 ret
= PTR_ERR(queue
->ib_cq
);
526 ret
= nvme_rdma_create_qp(queue
, send_wr_factor
);
528 goto out_destroy_ib_cq
;
530 queue
->rsp_ring
= nvme_rdma_alloc_ring(ibdev
, queue
->queue_size
,
531 sizeof(struct nvme_completion
), DMA_FROM_DEVICE
);
532 if (!queue
->rsp_ring
) {
536 set_bit(NVME_RDMA_IB_QUEUE_ALLOCATED
, &queue
->flags
);
541 ib_destroy_qp(queue
->qp
);
543 ib_free_cq(queue
->ib_cq
);
548 static int nvme_rdma_init_queue(struct nvme_rdma_ctrl
*ctrl
,
549 int idx
, size_t queue_size
)
551 struct nvme_rdma_queue
*queue
;
552 struct sockaddr
*src_addr
= NULL
;
555 queue
= &ctrl
->queues
[idx
];
557 init_completion(&queue
->cm_done
);
560 queue
->cmnd_capsule_len
= ctrl
->ctrl
.ioccsz
* 16;
562 queue
->cmnd_capsule_len
= sizeof(struct nvme_command
);
564 queue
->queue_size
= queue_size
;
566 queue
->cm_id
= rdma_create_id(&init_net
, nvme_rdma_cm_handler
, queue
,
567 RDMA_PS_TCP
, IB_QPT_RC
);
568 if (IS_ERR(queue
->cm_id
)) {
569 dev_info(ctrl
->ctrl
.device
,
570 "failed to create CM ID: %ld\n", PTR_ERR(queue
->cm_id
));
571 return PTR_ERR(queue
->cm_id
);
574 queue
->cm_error
= -ETIMEDOUT
;
575 if (ctrl
->ctrl
.opts
->mask
& NVMF_OPT_HOST_TRADDR
)
576 src_addr
= &ctrl
->src_addr
;
578 ret
= rdma_resolve_addr(queue
->cm_id
, src_addr
, &ctrl
->addr
,
579 NVME_RDMA_CONNECT_TIMEOUT_MS
);
581 dev_info(ctrl
->ctrl
.device
,
582 "rdma_resolve_addr failed (%d).\n", ret
);
583 goto out_destroy_cm_id
;
586 ret
= nvme_rdma_wait_for_cm(queue
);
588 dev_info(ctrl
->ctrl
.device
,
589 "rdma_resolve_addr wait failed (%d).\n", ret
);
590 goto out_destroy_cm_id
;
593 clear_bit(NVME_RDMA_Q_DELETING
, &queue
->flags
);
594 set_bit(NVME_RDMA_Q_CONNECTED
, &queue
->flags
);
599 nvme_rdma_destroy_queue_ib(queue
);
600 rdma_destroy_id(queue
->cm_id
);
604 static void nvme_rdma_stop_queue(struct nvme_rdma_queue
*queue
)
606 rdma_disconnect(queue
->cm_id
);
607 ib_drain_qp(queue
->qp
);
610 static void nvme_rdma_free_queue(struct nvme_rdma_queue
*queue
)
612 nvme_rdma_destroy_queue_ib(queue
);
613 rdma_destroy_id(queue
->cm_id
);
616 static void nvme_rdma_stop_and_free_queue(struct nvme_rdma_queue
*queue
)
618 if (test_and_set_bit(NVME_RDMA_Q_DELETING
, &queue
->flags
))
620 nvme_rdma_stop_queue(queue
);
621 nvme_rdma_free_queue(queue
);
624 static void nvme_rdma_free_io_queues(struct nvme_rdma_ctrl
*ctrl
)
628 for (i
= 1; i
< ctrl
->queue_count
; i
++)
629 nvme_rdma_stop_and_free_queue(&ctrl
->queues
[i
]);
632 static int nvme_rdma_connect_io_queues(struct nvme_rdma_ctrl
*ctrl
)
636 for (i
= 1; i
< ctrl
->queue_count
; i
++) {
637 ret
= nvmf_connect_io_queue(&ctrl
->ctrl
, i
);
639 dev_info(ctrl
->ctrl
.device
,
640 "failed to connect i/o queue: %d\n", ret
);
641 goto out_free_queues
;
643 set_bit(NVME_RDMA_Q_LIVE
, &ctrl
->queues
[i
].flags
);
649 nvme_rdma_free_io_queues(ctrl
);
653 static int nvme_rdma_init_io_queues(struct nvme_rdma_ctrl
*ctrl
)
657 for (i
= 1; i
< ctrl
->queue_count
; i
++) {
658 ret
= nvme_rdma_init_queue(ctrl
, i
,
659 ctrl
->ctrl
.opts
->queue_size
);
661 dev_info(ctrl
->ctrl
.device
,
662 "failed to initialize i/o queue: %d\n", ret
);
663 goto out_free_queues
;
670 for (i
--; i
>= 1; i
--)
671 nvme_rdma_stop_and_free_queue(&ctrl
->queues
[i
]);
676 static void nvme_rdma_destroy_admin_queue(struct nvme_rdma_ctrl
*ctrl
)
678 nvme_rdma_free_qe(ctrl
->queues
[0].device
->dev
, &ctrl
->async_event_sqe
,
679 sizeof(struct nvme_command
), DMA_TO_DEVICE
);
680 nvme_rdma_stop_and_free_queue(&ctrl
->queues
[0]);
681 blk_cleanup_queue(ctrl
->ctrl
.admin_q
);
682 blk_mq_free_tag_set(&ctrl
->admin_tag_set
);
683 nvme_rdma_dev_put(ctrl
->device
);
686 static void nvme_rdma_free_ctrl(struct nvme_ctrl
*nctrl
)
688 struct nvme_rdma_ctrl
*ctrl
= to_rdma_ctrl(nctrl
);
690 if (list_empty(&ctrl
->list
))
693 mutex_lock(&nvme_rdma_ctrl_mutex
);
694 list_del(&ctrl
->list
);
695 mutex_unlock(&nvme_rdma_ctrl_mutex
);
698 nvmf_free_options(nctrl
->opts
);
703 static void nvme_rdma_reconnect_ctrl_work(struct work_struct
*work
)
705 struct nvme_rdma_ctrl
*ctrl
= container_of(to_delayed_work(work
),
706 struct nvme_rdma_ctrl
, reconnect_work
);
710 if (ctrl
->queue_count
> 1) {
711 nvme_rdma_free_io_queues(ctrl
);
713 ret
= blk_mq_reinit_tagset(&ctrl
->tag_set
);
718 nvme_rdma_stop_and_free_queue(&ctrl
->queues
[0]);
720 ret
= blk_mq_reinit_tagset(&ctrl
->admin_tag_set
);
724 ret
= nvme_rdma_init_queue(ctrl
, 0, NVMF_AQ_DEPTH
);
728 blk_mq_start_stopped_hw_queues(ctrl
->ctrl
.admin_q
, true);
730 ret
= nvmf_connect_admin_queue(&ctrl
->ctrl
);
734 set_bit(NVME_RDMA_Q_LIVE
, &ctrl
->queues
[0].flags
);
736 ret
= nvme_enable_ctrl(&ctrl
->ctrl
, ctrl
->cap
);
740 nvme_start_keep_alive(&ctrl
->ctrl
);
742 if (ctrl
->queue_count
> 1) {
743 ret
= nvme_rdma_init_io_queues(ctrl
);
747 ret
= nvme_rdma_connect_io_queues(ctrl
);
752 changed
= nvme_change_ctrl_state(&ctrl
->ctrl
, NVME_CTRL_LIVE
);
753 WARN_ON_ONCE(!changed
);
755 if (ctrl
->queue_count
> 1) {
756 nvme_start_queues(&ctrl
->ctrl
);
757 nvme_queue_scan(&ctrl
->ctrl
);
758 nvme_queue_async_events(&ctrl
->ctrl
);
761 dev_info(ctrl
->ctrl
.device
, "Successfully reconnected\n");
766 blk_mq_stop_hw_queues(ctrl
->ctrl
.admin_q
);
768 /* Make sure we are not resetting/deleting */
769 if (ctrl
->ctrl
.state
== NVME_CTRL_RECONNECTING
) {
770 dev_info(ctrl
->ctrl
.device
,
771 "Failed reconnect attempt, requeueing...\n");
772 queue_delayed_work(nvme_rdma_wq
, &ctrl
->reconnect_work
,
773 ctrl
->reconnect_delay
* HZ
);
777 static void nvme_rdma_error_recovery_work(struct work_struct
*work
)
779 struct nvme_rdma_ctrl
*ctrl
= container_of(work
,
780 struct nvme_rdma_ctrl
, err_work
);
783 nvme_stop_keep_alive(&ctrl
->ctrl
);
785 for (i
= 0; i
< ctrl
->queue_count
; i
++) {
786 clear_bit(NVME_RDMA_Q_CONNECTED
, &ctrl
->queues
[i
].flags
);
787 clear_bit(NVME_RDMA_Q_LIVE
, &ctrl
->queues
[i
].flags
);
790 if (ctrl
->queue_count
> 1)
791 nvme_stop_queues(&ctrl
->ctrl
);
792 blk_mq_stop_hw_queues(ctrl
->ctrl
.admin_q
);
794 /* We must take care of fastfail/requeue all our inflight requests */
795 if (ctrl
->queue_count
> 1)
796 blk_mq_tagset_busy_iter(&ctrl
->tag_set
,
797 nvme_cancel_request
, &ctrl
->ctrl
);
798 blk_mq_tagset_busy_iter(&ctrl
->admin_tag_set
,
799 nvme_cancel_request
, &ctrl
->ctrl
);
801 dev_info(ctrl
->ctrl
.device
, "reconnecting in %d seconds\n",
802 ctrl
->reconnect_delay
);
804 queue_delayed_work(nvme_rdma_wq
, &ctrl
->reconnect_work
,
805 ctrl
->reconnect_delay
* HZ
);
808 static void nvme_rdma_error_recovery(struct nvme_rdma_ctrl
*ctrl
)
810 if (!nvme_change_ctrl_state(&ctrl
->ctrl
, NVME_CTRL_RECONNECTING
))
813 queue_work(nvme_rdma_wq
, &ctrl
->err_work
);
816 static void nvme_rdma_wr_error(struct ib_cq
*cq
, struct ib_wc
*wc
,
819 struct nvme_rdma_queue
*queue
= cq
->cq_context
;
820 struct nvme_rdma_ctrl
*ctrl
= queue
->ctrl
;
822 if (ctrl
->ctrl
.state
== NVME_CTRL_LIVE
)
823 dev_info(ctrl
->ctrl
.device
,
824 "%s for CQE 0x%p failed with status %s (%d)\n",
826 ib_wc_status_msg(wc
->status
), wc
->status
);
827 nvme_rdma_error_recovery(ctrl
);
830 static void nvme_rdma_memreg_done(struct ib_cq
*cq
, struct ib_wc
*wc
)
832 if (unlikely(wc
->status
!= IB_WC_SUCCESS
))
833 nvme_rdma_wr_error(cq
, wc
, "MEMREG");
836 static void nvme_rdma_inv_rkey_done(struct ib_cq
*cq
, struct ib_wc
*wc
)
838 if (unlikely(wc
->status
!= IB_WC_SUCCESS
))
839 nvme_rdma_wr_error(cq
, wc
, "LOCAL_INV");
842 static int nvme_rdma_inv_rkey(struct nvme_rdma_queue
*queue
,
843 struct nvme_rdma_request
*req
)
845 struct ib_send_wr
*bad_wr
;
846 struct ib_send_wr wr
= {
847 .opcode
= IB_WR_LOCAL_INV
,
851 .ex
.invalidate_rkey
= req
->mr
->rkey
,
854 req
->reg_cqe
.done
= nvme_rdma_inv_rkey_done
;
855 wr
.wr_cqe
= &req
->reg_cqe
;
857 return ib_post_send(queue
->qp
, &wr
, &bad_wr
);
860 static void nvme_rdma_unmap_data(struct nvme_rdma_queue
*queue
,
863 struct nvme_rdma_request
*req
= blk_mq_rq_to_pdu(rq
);
864 struct nvme_rdma_ctrl
*ctrl
= queue
->ctrl
;
865 struct nvme_rdma_device
*dev
= queue
->device
;
866 struct ib_device
*ibdev
= dev
->dev
;
869 if (!blk_rq_bytes(rq
))
872 if (req
->mr
->need_inval
) {
873 res
= nvme_rdma_inv_rkey(queue
, req
);
875 dev_err(ctrl
->ctrl
.device
,
876 "Queueing INV WR for rkey %#x failed (%d)\n",
878 nvme_rdma_error_recovery(queue
->ctrl
);
882 ib_dma_unmap_sg(ibdev
, req
->sg_table
.sgl
,
883 req
->nents
, rq_data_dir(rq
) ==
884 WRITE
? DMA_TO_DEVICE
: DMA_FROM_DEVICE
);
886 nvme_cleanup_cmd(rq
);
887 sg_free_table_chained(&req
->sg_table
, true);
890 static int nvme_rdma_set_sg_null(struct nvme_command
*c
)
892 struct nvme_keyed_sgl_desc
*sg
= &c
->common
.dptr
.ksgl
;
895 put_unaligned_le24(0, sg
->length
);
896 put_unaligned_le32(0, sg
->key
);
897 sg
->type
= NVME_KEY_SGL_FMT_DATA_DESC
<< 4;
901 static int nvme_rdma_map_sg_inline(struct nvme_rdma_queue
*queue
,
902 struct nvme_rdma_request
*req
, struct nvme_command
*c
)
904 struct nvme_sgl_desc
*sg
= &c
->common
.dptr
.sgl
;
906 req
->sge
[1].addr
= sg_dma_address(req
->sg_table
.sgl
);
907 req
->sge
[1].length
= sg_dma_len(req
->sg_table
.sgl
);
908 req
->sge
[1].lkey
= queue
->device
->pd
->local_dma_lkey
;
910 sg
->addr
= cpu_to_le64(queue
->ctrl
->ctrl
.icdoff
);
911 sg
->length
= cpu_to_le32(sg_dma_len(req
->sg_table
.sgl
));
912 sg
->type
= (NVME_SGL_FMT_DATA_DESC
<< 4) | NVME_SGL_FMT_OFFSET
;
914 req
->inline_data
= true;
919 static int nvme_rdma_map_sg_single(struct nvme_rdma_queue
*queue
,
920 struct nvme_rdma_request
*req
, struct nvme_command
*c
)
922 struct nvme_keyed_sgl_desc
*sg
= &c
->common
.dptr
.ksgl
;
924 sg
->addr
= cpu_to_le64(sg_dma_address(req
->sg_table
.sgl
));
925 put_unaligned_le24(sg_dma_len(req
->sg_table
.sgl
), sg
->length
);
926 put_unaligned_le32(queue
->device
->pd
->unsafe_global_rkey
, sg
->key
);
927 sg
->type
= NVME_KEY_SGL_FMT_DATA_DESC
<< 4;
931 static int nvme_rdma_map_sg_fr(struct nvme_rdma_queue
*queue
,
932 struct nvme_rdma_request
*req
, struct nvme_command
*c
,
935 struct nvme_keyed_sgl_desc
*sg
= &c
->common
.dptr
.ksgl
;
938 nr
= ib_map_mr_sg(req
->mr
, req
->sg_table
.sgl
, count
, NULL
, PAGE_SIZE
);
945 ib_update_fast_reg_key(req
->mr
, ib_inc_rkey(req
->mr
->rkey
));
947 req
->reg_cqe
.done
= nvme_rdma_memreg_done
;
948 memset(&req
->reg_wr
, 0, sizeof(req
->reg_wr
));
949 req
->reg_wr
.wr
.opcode
= IB_WR_REG_MR
;
950 req
->reg_wr
.wr
.wr_cqe
= &req
->reg_cqe
;
951 req
->reg_wr
.wr
.num_sge
= 0;
952 req
->reg_wr
.mr
= req
->mr
;
953 req
->reg_wr
.key
= req
->mr
->rkey
;
954 req
->reg_wr
.access
= IB_ACCESS_LOCAL_WRITE
|
955 IB_ACCESS_REMOTE_READ
|
956 IB_ACCESS_REMOTE_WRITE
;
958 req
->mr
->need_inval
= true;
960 sg
->addr
= cpu_to_le64(req
->mr
->iova
);
961 put_unaligned_le24(req
->mr
->length
, sg
->length
);
962 put_unaligned_le32(req
->mr
->rkey
, sg
->key
);
963 sg
->type
= (NVME_KEY_SGL_FMT_DATA_DESC
<< 4) |
964 NVME_SGL_FMT_INVALIDATE
;
969 static int nvme_rdma_map_data(struct nvme_rdma_queue
*queue
,
970 struct request
*rq
, struct nvme_command
*c
)
972 struct nvme_rdma_request
*req
= blk_mq_rq_to_pdu(rq
);
973 struct nvme_rdma_device
*dev
= queue
->device
;
974 struct ib_device
*ibdev
= dev
->dev
;
978 req
->inline_data
= false;
979 req
->mr
->need_inval
= false;
981 c
->common
.flags
|= NVME_CMD_SGL_METABUF
;
983 if (!blk_rq_bytes(rq
))
984 return nvme_rdma_set_sg_null(c
);
986 req
->sg_table
.sgl
= req
->first_sgl
;
987 ret
= sg_alloc_table_chained(&req
->sg_table
,
988 blk_rq_nr_phys_segments(rq
), req
->sg_table
.sgl
);
992 req
->nents
= blk_rq_map_sg(rq
->q
, rq
, req
->sg_table
.sgl
);
994 count
= ib_dma_map_sg(ibdev
, req
->sg_table
.sgl
, req
->nents
,
995 rq_data_dir(rq
) == WRITE
? DMA_TO_DEVICE
: DMA_FROM_DEVICE
);
996 if (unlikely(count
<= 0)) {
997 sg_free_table_chained(&req
->sg_table
, true);
1002 if (rq_data_dir(rq
) == WRITE
&& nvme_rdma_queue_idx(queue
) &&
1003 blk_rq_payload_bytes(rq
) <=
1004 nvme_rdma_inline_data_size(queue
))
1005 return nvme_rdma_map_sg_inline(queue
, req
, c
);
1007 if (dev
->pd
->flags
& IB_PD_UNSAFE_GLOBAL_RKEY
)
1008 return nvme_rdma_map_sg_single(queue
, req
, c
);
1011 return nvme_rdma_map_sg_fr(queue
, req
, c
, count
);
1014 static void nvme_rdma_send_done(struct ib_cq
*cq
, struct ib_wc
*wc
)
1016 if (unlikely(wc
->status
!= IB_WC_SUCCESS
))
1017 nvme_rdma_wr_error(cq
, wc
, "SEND");
1020 static int nvme_rdma_post_send(struct nvme_rdma_queue
*queue
,
1021 struct nvme_rdma_qe
*qe
, struct ib_sge
*sge
, u32 num_sge
,
1022 struct ib_send_wr
*first
, bool flush
)
1024 struct ib_send_wr wr
, *bad_wr
;
1027 sge
->addr
= qe
->dma
;
1028 sge
->length
= sizeof(struct nvme_command
),
1029 sge
->lkey
= queue
->device
->pd
->local_dma_lkey
;
1031 qe
->cqe
.done
= nvme_rdma_send_done
;
1034 wr
.wr_cqe
= &qe
->cqe
;
1036 wr
.num_sge
= num_sge
;
1037 wr
.opcode
= IB_WR_SEND
;
1041 * Unsignalled send completions are another giant desaster in the
1042 * IB Verbs spec: If we don't regularly post signalled sends
1043 * the send queue will fill up and only a QP reset will rescue us.
1044 * Would have been way to obvious to handle this in hardware or
1045 * at least the RDMA stack..
1047 * This messy and racy code sniplet is copy and pasted from the iSER
1048 * initiator, and the magic '32' comes from there as well.
1050 * Always signal the flushes. The magic request used for the flush
1051 * sequencer is not allocated in our driver's tagset and it's
1052 * triggered to be freed by blk_cleanup_queue(). So we need to
1053 * always mark it as signaled to ensure that the "wr_cqe", which is
1054 * embedded in request's payload, is not freed when __ib_process_cq()
1055 * calls wr_cqe->done().
1057 if ((++queue
->sig_count
% 32) == 0 || flush
)
1058 wr
.send_flags
|= IB_SEND_SIGNALED
;
1065 ret
= ib_post_send(queue
->qp
, first
, &bad_wr
);
1067 dev_err(queue
->ctrl
->ctrl
.device
,
1068 "%s failed with error code %d\n", __func__
, ret
);
1073 static int nvme_rdma_post_recv(struct nvme_rdma_queue
*queue
,
1074 struct nvme_rdma_qe
*qe
)
1076 struct ib_recv_wr wr
, *bad_wr
;
1080 list
.addr
= qe
->dma
;
1081 list
.length
= sizeof(struct nvme_completion
);
1082 list
.lkey
= queue
->device
->pd
->local_dma_lkey
;
1084 qe
->cqe
.done
= nvme_rdma_recv_done
;
1087 wr
.wr_cqe
= &qe
->cqe
;
1091 ret
= ib_post_recv(queue
->qp
, &wr
, &bad_wr
);
1093 dev_err(queue
->ctrl
->ctrl
.device
,
1094 "%s failed with error code %d\n", __func__
, ret
);
1099 static struct blk_mq_tags
*nvme_rdma_tagset(struct nvme_rdma_queue
*queue
)
1101 u32 queue_idx
= nvme_rdma_queue_idx(queue
);
1104 return queue
->ctrl
->admin_tag_set
.tags
[queue_idx
];
1105 return queue
->ctrl
->tag_set
.tags
[queue_idx
- 1];
1108 static void nvme_rdma_submit_async_event(struct nvme_ctrl
*arg
, int aer_idx
)
1110 struct nvme_rdma_ctrl
*ctrl
= to_rdma_ctrl(arg
);
1111 struct nvme_rdma_queue
*queue
= &ctrl
->queues
[0];
1112 struct ib_device
*dev
= queue
->device
->dev
;
1113 struct nvme_rdma_qe
*sqe
= &ctrl
->async_event_sqe
;
1114 struct nvme_command
*cmd
= sqe
->data
;
1118 if (WARN_ON_ONCE(aer_idx
!= 0))
1121 ib_dma_sync_single_for_cpu(dev
, sqe
->dma
, sizeof(*cmd
), DMA_TO_DEVICE
);
1123 memset(cmd
, 0, sizeof(*cmd
));
1124 cmd
->common
.opcode
= nvme_admin_async_event
;
1125 cmd
->common
.command_id
= NVME_RDMA_AQ_BLKMQ_DEPTH
;
1126 cmd
->common
.flags
|= NVME_CMD_SGL_METABUF
;
1127 nvme_rdma_set_sg_null(cmd
);
1129 ib_dma_sync_single_for_device(dev
, sqe
->dma
, sizeof(*cmd
),
1132 ret
= nvme_rdma_post_send(queue
, sqe
, &sge
, 1, NULL
, false);
1136 static int nvme_rdma_process_nvme_rsp(struct nvme_rdma_queue
*queue
,
1137 struct nvme_completion
*cqe
, struct ib_wc
*wc
, int tag
)
1140 struct nvme_rdma_request
*req
;
1143 rq
= blk_mq_tag_to_rq(nvme_rdma_tagset(queue
), cqe
->command_id
);
1145 dev_err(queue
->ctrl
->ctrl
.device
,
1146 "tag 0x%x on QP %#x not found\n",
1147 cqe
->command_id
, queue
->qp
->qp_num
);
1148 nvme_rdma_error_recovery(queue
->ctrl
);
1151 req
= blk_mq_rq_to_pdu(rq
);
1156 if ((wc
->wc_flags
& IB_WC_WITH_INVALIDATE
) &&
1157 wc
->ex
.invalidate_rkey
== req
->mr
->rkey
)
1158 req
->mr
->need_inval
= false;
1160 req
->req
.result
= cqe
->result
;
1161 blk_mq_complete_request(rq
, le16_to_cpu(cqe
->status
) >> 1);
1165 static int __nvme_rdma_recv_done(struct ib_cq
*cq
, struct ib_wc
*wc
, int tag
)
1167 struct nvme_rdma_qe
*qe
=
1168 container_of(wc
->wr_cqe
, struct nvme_rdma_qe
, cqe
);
1169 struct nvme_rdma_queue
*queue
= cq
->cq_context
;
1170 struct ib_device
*ibdev
= queue
->device
->dev
;
1171 struct nvme_completion
*cqe
= qe
->data
;
1172 const size_t len
= sizeof(struct nvme_completion
);
1175 if (unlikely(wc
->status
!= IB_WC_SUCCESS
)) {
1176 nvme_rdma_wr_error(cq
, wc
, "RECV");
1180 ib_dma_sync_single_for_cpu(ibdev
, qe
->dma
, len
, DMA_FROM_DEVICE
);
1182 * AEN requests are special as they don't time out and can
1183 * survive any kind of queue freeze and often don't respond to
1184 * aborts. We don't even bother to allocate a struct request
1185 * for them but rather special case them here.
1187 if (unlikely(nvme_rdma_queue_idx(queue
) == 0 &&
1188 cqe
->command_id
>= NVME_RDMA_AQ_BLKMQ_DEPTH
))
1189 nvme_complete_async_event(&queue
->ctrl
->ctrl
, cqe
->status
,
1192 ret
= nvme_rdma_process_nvme_rsp(queue
, cqe
, wc
, tag
);
1193 ib_dma_sync_single_for_device(ibdev
, qe
->dma
, len
, DMA_FROM_DEVICE
);
1195 nvme_rdma_post_recv(queue
, qe
);
1199 static void nvme_rdma_recv_done(struct ib_cq
*cq
, struct ib_wc
*wc
)
1201 __nvme_rdma_recv_done(cq
, wc
, -1);
1204 static int nvme_rdma_conn_established(struct nvme_rdma_queue
*queue
)
1208 for (i
= 0; i
< queue
->queue_size
; i
++) {
1209 ret
= nvme_rdma_post_recv(queue
, &queue
->rsp_ring
[i
]);
1211 goto out_destroy_queue_ib
;
1216 out_destroy_queue_ib
:
1217 nvme_rdma_destroy_queue_ib(queue
);
1221 static int nvme_rdma_conn_rejected(struct nvme_rdma_queue
*queue
,
1222 struct rdma_cm_event
*ev
)
1224 struct rdma_cm_id
*cm_id
= queue
->cm_id
;
1225 int status
= ev
->status
;
1226 const char *rej_msg
;
1227 const struct nvme_rdma_cm_rej
*rej_data
;
1230 rej_msg
= rdma_reject_msg(cm_id
, status
);
1231 rej_data
= rdma_consumer_reject_data(cm_id
, ev
, &rej_data_len
);
1233 if (rej_data
&& rej_data_len
>= sizeof(u16
)) {
1234 u16 sts
= le16_to_cpu(rej_data
->sts
);
1236 dev_err(queue
->ctrl
->ctrl
.device
,
1237 "Connect rejected: status %d (%s) nvme status %d (%s).\n",
1238 status
, rej_msg
, sts
, nvme_rdma_cm_msg(sts
));
1240 dev_err(queue
->ctrl
->ctrl
.device
,
1241 "Connect rejected: status %d (%s).\n", status
, rej_msg
);
1247 static int nvme_rdma_addr_resolved(struct nvme_rdma_queue
*queue
)
1249 struct nvme_rdma_device
*dev
;
1252 dev
= nvme_rdma_find_get_device(queue
->cm_id
);
1254 dev_err(queue
->cm_id
->device
->dev
.parent
,
1255 "no client data found!\n");
1256 return -ECONNREFUSED
;
1259 ret
= nvme_rdma_create_queue_ib(queue
, dev
);
1261 nvme_rdma_dev_put(dev
);
1265 ret
= rdma_resolve_route(queue
->cm_id
, NVME_RDMA_CONNECT_TIMEOUT_MS
);
1267 dev_err(queue
->ctrl
->ctrl
.device
,
1268 "rdma_resolve_route failed (%d).\n",
1270 goto out_destroy_queue
;
1276 nvme_rdma_destroy_queue_ib(queue
);
1281 static int nvme_rdma_route_resolved(struct nvme_rdma_queue
*queue
)
1283 struct nvme_rdma_ctrl
*ctrl
= queue
->ctrl
;
1284 struct rdma_conn_param param
= { };
1285 struct nvme_rdma_cm_req priv
= { };
1288 param
.qp_num
= queue
->qp
->qp_num
;
1289 param
.flow_control
= 1;
1291 param
.responder_resources
= queue
->device
->dev
->attrs
.max_qp_rd_atom
;
1292 /* maximum retry count */
1293 param
.retry_count
= 7;
1294 param
.rnr_retry_count
= 7;
1295 param
.private_data
= &priv
;
1296 param
.private_data_len
= sizeof(priv
);
1298 priv
.recfmt
= cpu_to_le16(NVME_RDMA_CM_FMT_1_0
);
1299 priv
.qid
= cpu_to_le16(nvme_rdma_queue_idx(queue
));
1301 * set the admin queue depth to the minimum size
1302 * specified by the Fabrics standard.
1304 if (priv
.qid
== 0) {
1305 priv
.hrqsize
= cpu_to_le16(NVMF_AQ_DEPTH
);
1306 priv
.hsqsize
= cpu_to_le16(NVMF_AQ_DEPTH
- 1);
1309 * current interpretation of the fabrics spec
1310 * is at minimum you make hrqsize sqsize+1, or a
1311 * 1's based representation of sqsize.
1313 priv
.hrqsize
= cpu_to_le16(queue
->queue_size
);
1314 priv
.hsqsize
= cpu_to_le16(queue
->ctrl
->ctrl
.sqsize
);
1317 ret
= rdma_connect(queue
->cm_id
, ¶m
);
1319 dev_err(ctrl
->ctrl
.device
,
1320 "rdma_connect failed (%d).\n", ret
);
1321 goto out_destroy_queue_ib
;
1326 out_destroy_queue_ib
:
1327 nvme_rdma_destroy_queue_ib(queue
);
1331 static int nvme_rdma_cm_handler(struct rdma_cm_id
*cm_id
,
1332 struct rdma_cm_event
*ev
)
1334 struct nvme_rdma_queue
*queue
= cm_id
->context
;
1337 dev_dbg(queue
->ctrl
->ctrl
.device
, "%s (%d): status %d id %p\n",
1338 rdma_event_msg(ev
->event
), ev
->event
,
1341 switch (ev
->event
) {
1342 case RDMA_CM_EVENT_ADDR_RESOLVED
:
1343 cm_error
= nvme_rdma_addr_resolved(queue
);
1345 case RDMA_CM_EVENT_ROUTE_RESOLVED
:
1346 cm_error
= nvme_rdma_route_resolved(queue
);
1348 case RDMA_CM_EVENT_ESTABLISHED
:
1349 queue
->cm_error
= nvme_rdma_conn_established(queue
);
1350 /* complete cm_done regardless of success/failure */
1351 complete(&queue
->cm_done
);
1353 case RDMA_CM_EVENT_REJECTED
:
1354 cm_error
= nvme_rdma_conn_rejected(queue
, ev
);
1356 case RDMA_CM_EVENT_ADDR_ERROR
:
1357 case RDMA_CM_EVENT_ROUTE_ERROR
:
1358 case RDMA_CM_EVENT_CONNECT_ERROR
:
1359 case RDMA_CM_EVENT_UNREACHABLE
:
1360 dev_dbg(queue
->ctrl
->ctrl
.device
,
1361 "CM error event %d\n", ev
->event
);
1362 cm_error
= -ECONNRESET
;
1364 case RDMA_CM_EVENT_DISCONNECTED
:
1365 case RDMA_CM_EVENT_ADDR_CHANGE
:
1366 case RDMA_CM_EVENT_TIMEWAIT_EXIT
:
1367 dev_dbg(queue
->ctrl
->ctrl
.device
,
1368 "disconnect received - connection closed\n");
1369 nvme_rdma_error_recovery(queue
->ctrl
);
1371 case RDMA_CM_EVENT_DEVICE_REMOVAL
:
1372 /* device removal is handled via the ib_client API */
1375 dev_err(queue
->ctrl
->ctrl
.device
,
1376 "Unexpected RDMA CM event (%d)\n", ev
->event
);
1377 nvme_rdma_error_recovery(queue
->ctrl
);
1382 queue
->cm_error
= cm_error
;
1383 complete(&queue
->cm_done
);
1389 static enum blk_eh_timer_return
1390 nvme_rdma_timeout(struct request
*rq
, bool reserved
)
1392 struct nvme_rdma_request
*req
= blk_mq_rq_to_pdu(rq
);
1394 /* queue error recovery */
1395 nvme_rdma_error_recovery(req
->queue
->ctrl
);
1397 /* fail with DNR on cmd timeout */
1398 rq
->errors
= NVME_SC_ABORT_REQ
| NVME_SC_DNR
;
1400 return BLK_EH_HANDLED
;
1404 * We cannot accept any other command until the Connect command has completed.
1406 static inline bool nvme_rdma_queue_is_ready(struct nvme_rdma_queue
*queue
,
1409 if (unlikely(!test_bit(NVME_RDMA_Q_LIVE
, &queue
->flags
))) {
1410 struct nvme_command
*cmd
= nvme_req(rq
)->cmd
;
1412 if (!blk_rq_is_passthrough(rq
) ||
1413 cmd
->common
.opcode
!= nvme_fabrics_command
||
1414 cmd
->fabrics
.fctype
!= nvme_fabrics_type_connect
)
1421 static int nvme_rdma_queue_rq(struct blk_mq_hw_ctx
*hctx
,
1422 const struct blk_mq_queue_data
*bd
)
1424 struct nvme_ns
*ns
= hctx
->queue
->queuedata
;
1425 struct nvme_rdma_queue
*queue
= hctx
->driver_data
;
1426 struct request
*rq
= bd
->rq
;
1427 struct nvme_rdma_request
*req
= blk_mq_rq_to_pdu(rq
);
1428 struct nvme_rdma_qe
*sqe
= &req
->sqe
;
1429 struct nvme_command
*c
= sqe
->data
;
1431 struct ib_device
*dev
;
1434 WARN_ON_ONCE(rq
->tag
< 0);
1436 if (!nvme_rdma_queue_is_ready(queue
, rq
))
1437 return BLK_MQ_RQ_QUEUE_BUSY
;
1439 dev
= queue
->device
->dev
;
1440 ib_dma_sync_single_for_cpu(dev
, sqe
->dma
,
1441 sizeof(struct nvme_command
), DMA_TO_DEVICE
);
1443 ret
= nvme_setup_cmd(ns
, rq
, c
);
1444 if (ret
!= BLK_MQ_RQ_QUEUE_OK
)
1447 blk_mq_start_request(rq
);
1449 ret
= nvme_rdma_map_data(queue
, rq
, c
);
1451 dev_err(queue
->ctrl
->ctrl
.device
,
1452 "Failed to map data (%d)\n", ret
);
1453 nvme_cleanup_cmd(rq
);
1457 ib_dma_sync_single_for_device(dev
, sqe
->dma
,
1458 sizeof(struct nvme_command
), DMA_TO_DEVICE
);
1460 if (req_op(rq
) == REQ_OP_FLUSH
)
1462 ret
= nvme_rdma_post_send(queue
, sqe
, req
->sge
, req
->num_sge
,
1463 req
->mr
->need_inval
? &req
->reg_wr
.wr
: NULL
, flush
);
1465 nvme_rdma_unmap_data(queue
, rq
);
1469 return BLK_MQ_RQ_QUEUE_OK
;
1471 return (ret
== -ENOMEM
|| ret
== -EAGAIN
) ?
1472 BLK_MQ_RQ_QUEUE_BUSY
: BLK_MQ_RQ_QUEUE_ERROR
;
1475 static int nvme_rdma_poll(struct blk_mq_hw_ctx
*hctx
, unsigned int tag
)
1477 struct nvme_rdma_queue
*queue
= hctx
->driver_data
;
1478 struct ib_cq
*cq
= queue
->ib_cq
;
1482 ib_req_notify_cq(cq
, IB_CQ_NEXT_COMP
);
1483 while (ib_poll_cq(cq
, 1, &wc
) > 0) {
1484 struct ib_cqe
*cqe
= wc
.wr_cqe
;
1487 if (cqe
->done
== nvme_rdma_recv_done
)
1488 found
|= __nvme_rdma_recv_done(cq
, &wc
, tag
);
1497 static void nvme_rdma_complete_rq(struct request
*rq
)
1499 struct nvme_rdma_request
*req
= blk_mq_rq_to_pdu(rq
);
1500 struct nvme_rdma_queue
*queue
= req
->queue
;
1503 nvme_rdma_unmap_data(queue
, rq
);
1505 if (unlikely(rq
->errors
)) {
1506 if (nvme_req_needs_retry(rq
, rq
->errors
)) {
1507 nvme_requeue_req(rq
);
1511 if (blk_rq_is_passthrough(rq
))
1514 error
= nvme_error_status(rq
->errors
);
1517 blk_mq_end_request(rq
, error
);
1520 static struct blk_mq_ops nvme_rdma_mq_ops
= {
1521 .queue_rq
= nvme_rdma_queue_rq
,
1522 .complete
= nvme_rdma_complete_rq
,
1523 .init_request
= nvme_rdma_init_request
,
1524 .exit_request
= nvme_rdma_exit_request
,
1525 .reinit_request
= nvme_rdma_reinit_request
,
1526 .init_hctx
= nvme_rdma_init_hctx
,
1527 .poll
= nvme_rdma_poll
,
1528 .timeout
= nvme_rdma_timeout
,
1531 static struct blk_mq_ops nvme_rdma_admin_mq_ops
= {
1532 .queue_rq
= nvme_rdma_queue_rq
,
1533 .complete
= nvme_rdma_complete_rq
,
1534 .init_request
= nvme_rdma_init_admin_request
,
1535 .exit_request
= nvme_rdma_exit_admin_request
,
1536 .reinit_request
= nvme_rdma_reinit_request
,
1537 .init_hctx
= nvme_rdma_init_admin_hctx
,
1538 .timeout
= nvme_rdma_timeout
,
1541 static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl
*ctrl
)
1545 error
= nvme_rdma_init_queue(ctrl
, 0, NVMF_AQ_DEPTH
);
1549 ctrl
->device
= ctrl
->queues
[0].device
;
1552 * We need a reference on the device as long as the tag_set is alive,
1553 * as the MRs in the request structures need a valid ib_device.
1556 if (!nvme_rdma_dev_get(ctrl
->device
))
1557 goto out_free_queue
;
1559 ctrl
->max_fr_pages
= min_t(u32
, NVME_RDMA_MAX_SEGMENTS
,
1560 ctrl
->device
->dev
->attrs
.max_fast_reg_page_list_len
);
1562 memset(&ctrl
->admin_tag_set
, 0, sizeof(ctrl
->admin_tag_set
));
1563 ctrl
->admin_tag_set
.ops
= &nvme_rdma_admin_mq_ops
;
1564 ctrl
->admin_tag_set
.queue_depth
= NVME_RDMA_AQ_BLKMQ_DEPTH
;
1565 ctrl
->admin_tag_set
.reserved_tags
= 2; /* connect + keep-alive */
1566 ctrl
->admin_tag_set
.numa_node
= NUMA_NO_NODE
;
1567 ctrl
->admin_tag_set
.cmd_size
= sizeof(struct nvme_rdma_request
) +
1568 SG_CHUNK_SIZE
* sizeof(struct scatterlist
);
1569 ctrl
->admin_tag_set
.driver_data
= ctrl
;
1570 ctrl
->admin_tag_set
.nr_hw_queues
= 1;
1571 ctrl
->admin_tag_set
.timeout
= ADMIN_TIMEOUT
;
1573 error
= blk_mq_alloc_tag_set(&ctrl
->admin_tag_set
);
1577 ctrl
->ctrl
.admin_q
= blk_mq_init_queue(&ctrl
->admin_tag_set
);
1578 if (IS_ERR(ctrl
->ctrl
.admin_q
)) {
1579 error
= PTR_ERR(ctrl
->ctrl
.admin_q
);
1580 goto out_free_tagset
;
1583 error
= nvmf_connect_admin_queue(&ctrl
->ctrl
);
1585 goto out_cleanup_queue
;
1587 set_bit(NVME_RDMA_Q_LIVE
, &ctrl
->queues
[0].flags
);
1589 error
= nvmf_reg_read64(&ctrl
->ctrl
, NVME_REG_CAP
, &ctrl
->cap
);
1591 dev_err(ctrl
->ctrl
.device
,
1592 "prop_get NVME_REG_CAP failed\n");
1593 goto out_cleanup_queue
;
1597 min_t(int, NVME_CAP_MQES(ctrl
->cap
) + 1, ctrl
->ctrl
.sqsize
);
1599 error
= nvme_enable_ctrl(&ctrl
->ctrl
, ctrl
->cap
);
1601 goto out_cleanup_queue
;
1603 ctrl
->ctrl
.max_hw_sectors
=
1604 (ctrl
->max_fr_pages
- 1) << (PAGE_SHIFT
- 9);
1606 error
= nvme_init_identify(&ctrl
->ctrl
);
1608 goto out_cleanup_queue
;
1610 error
= nvme_rdma_alloc_qe(ctrl
->queues
[0].device
->dev
,
1611 &ctrl
->async_event_sqe
, sizeof(struct nvme_command
),
1614 goto out_cleanup_queue
;
1616 nvme_start_keep_alive(&ctrl
->ctrl
);
1621 blk_cleanup_queue(ctrl
->ctrl
.admin_q
);
1623 /* disconnect and drain the queue before freeing the tagset */
1624 nvme_rdma_stop_queue(&ctrl
->queues
[0]);
1625 blk_mq_free_tag_set(&ctrl
->admin_tag_set
);
1627 nvme_rdma_dev_put(ctrl
->device
);
1629 nvme_rdma_free_queue(&ctrl
->queues
[0]);
1633 static void nvme_rdma_shutdown_ctrl(struct nvme_rdma_ctrl
*ctrl
)
1635 nvme_stop_keep_alive(&ctrl
->ctrl
);
1636 cancel_work_sync(&ctrl
->err_work
);
1637 cancel_delayed_work_sync(&ctrl
->reconnect_work
);
1639 if (ctrl
->queue_count
> 1) {
1640 nvme_stop_queues(&ctrl
->ctrl
);
1641 blk_mq_tagset_busy_iter(&ctrl
->tag_set
,
1642 nvme_cancel_request
, &ctrl
->ctrl
);
1643 nvme_rdma_free_io_queues(ctrl
);
1646 if (test_bit(NVME_RDMA_Q_CONNECTED
, &ctrl
->queues
[0].flags
))
1647 nvme_shutdown_ctrl(&ctrl
->ctrl
);
1649 blk_mq_stop_hw_queues(ctrl
->ctrl
.admin_q
);
1650 blk_mq_tagset_busy_iter(&ctrl
->admin_tag_set
,
1651 nvme_cancel_request
, &ctrl
->ctrl
);
1652 nvme_rdma_destroy_admin_queue(ctrl
);
1655 static void __nvme_rdma_remove_ctrl(struct nvme_rdma_ctrl
*ctrl
, bool shutdown
)
1657 nvme_uninit_ctrl(&ctrl
->ctrl
);
1659 nvme_rdma_shutdown_ctrl(ctrl
);
1661 if (ctrl
->ctrl
.tagset
) {
1662 blk_cleanup_queue(ctrl
->ctrl
.connect_q
);
1663 blk_mq_free_tag_set(&ctrl
->tag_set
);
1664 nvme_rdma_dev_put(ctrl
->device
);
1667 nvme_put_ctrl(&ctrl
->ctrl
);
1670 static void nvme_rdma_del_ctrl_work(struct work_struct
*work
)
1672 struct nvme_rdma_ctrl
*ctrl
= container_of(work
,
1673 struct nvme_rdma_ctrl
, delete_work
);
1675 __nvme_rdma_remove_ctrl(ctrl
, true);
1678 static int __nvme_rdma_del_ctrl(struct nvme_rdma_ctrl
*ctrl
)
1680 if (!nvme_change_ctrl_state(&ctrl
->ctrl
, NVME_CTRL_DELETING
))
1683 if (!queue_work(nvme_rdma_wq
, &ctrl
->delete_work
))
1689 static int nvme_rdma_del_ctrl(struct nvme_ctrl
*nctrl
)
1691 struct nvme_rdma_ctrl
*ctrl
= to_rdma_ctrl(nctrl
);
1695 * Keep a reference until all work is flushed since
1696 * __nvme_rdma_del_ctrl can free the ctrl mem
1698 if (!kref_get_unless_zero(&ctrl
->ctrl
.kref
))
1700 ret
= __nvme_rdma_del_ctrl(ctrl
);
1702 flush_work(&ctrl
->delete_work
);
1703 nvme_put_ctrl(&ctrl
->ctrl
);
1707 static void nvme_rdma_remove_ctrl_work(struct work_struct
*work
)
1709 struct nvme_rdma_ctrl
*ctrl
= container_of(work
,
1710 struct nvme_rdma_ctrl
, delete_work
);
1712 __nvme_rdma_remove_ctrl(ctrl
, false);
1715 static void nvme_rdma_reset_ctrl_work(struct work_struct
*work
)
1717 struct nvme_rdma_ctrl
*ctrl
= container_of(work
,
1718 struct nvme_rdma_ctrl
, reset_work
);
1722 nvme_rdma_shutdown_ctrl(ctrl
);
1724 ret
= nvme_rdma_configure_admin_queue(ctrl
);
1726 /* ctrl is already shutdown, just remove the ctrl */
1727 INIT_WORK(&ctrl
->delete_work
, nvme_rdma_remove_ctrl_work
);
1731 if (ctrl
->queue_count
> 1) {
1732 ret
= blk_mq_reinit_tagset(&ctrl
->tag_set
);
1736 ret
= nvme_rdma_init_io_queues(ctrl
);
1740 ret
= nvme_rdma_connect_io_queues(ctrl
);
1745 changed
= nvme_change_ctrl_state(&ctrl
->ctrl
, NVME_CTRL_LIVE
);
1746 WARN_ON_ONCE(!changed
);
1748 if (ctrl
->queue_count
> 1) {
1749 nvme_start_queues(&ctrl
->ctrl
);
1750 nvme_queue_scan(&ctrl
->ctrl
);
1751 nvme_queue_async_events(&ctrl
->ctrl
);
1757 /* Deleting this dead controller... */
1758 dev_warn(ctrl
->ctrl
.device
, "Removing after reset failure\n");
1759 WARN_ON(!queue_work(nvme_rdma_wq
, &ctrl
->delete_work
));
1762 static int nvme_rdma_reset_ctrl(struct nvme_ctrl
*nctrl
)
1764 struct nvme_rdma_ctrl
*ctrl
= to_rdma_ctrl(nctrl
);
1766 if (!nvme_change_ctrl_state(&ctrl
->ctrl
, NVME_CTRL_RESETTING
))
1769 if (!queue_work(nvme_rdma_wq
, &ctrl
->reset_work
))
1772 flush_work(&ctrl
->reset_work
);
1777 static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops
= {
1779 .module
= THIS_MODULE
,
1781 .reg_read32
= nvmf_reg_read32
,
1782 .reg_read64
= nvmf_reg_read64
,
1783 .reg_write32
= nvmf_reg_write32
,
1784 .reset_ctrl
= nvme_rdma_reset_ctrl
,
1785 .free_ctrl
= nvme_rdma_free_ctrl
,
1786 .submit_async_event
= nvme_rdma_submit_async_event
,
1787 .delete_ctrl
= nvme_rdma_del_ctrl
,
1788 .get_subsysnqn
= nvmf_get_subsysnqn
,
1789 .get_address
= nvmf_get_address
,
1792 static int nvme_rdma_create_io_queues(struct nvme_rdma_ctrl
*ctrl
)
1794 struct nvmf_ctrl_options
*opts
= ctrl
->ctrl
.opts
;
1797 ret
= nvme_set_queue_count(&ctrl
->ctrl
, &opts
->nr_io_queues
);
1801 ctrl
->queue_count
= opts
->nr_io_queues
+ 1;
1802 if (ctrl
->queue_count
< 2)
1805 dev_info(ctrl
->ctrl
.device
,
1806 "creating %d I/O queues.\n", opts
->nr_io_queues
);
1808 ret
= nvme_rdma_init_io_queues(ctrl
);
1813 * We need a reference on the device as long as the tag_set is alive,
1814 * as the MRs in the request structures need a valid ib_device.
1817 if (!nvme_rdma_dev_get(ctrl
->device
))
1818 goto out_free_io_queues
;
1820 memset(&ctrl
->tag_set
, 0, sizeof(ctrl
->tag_set
));
1821 ctrl
->tag_set
.ops
= &nvme_rdma_mq_ops
;
1822 ctrl
->tag_set
.queue_depth
= ctrl
->ctrl
.opts
->queue_size
;
1823 ctrl
->tag_set
.reserved_tags
= 1; /* fabric connect */
1824 ctrl
->tag_set
.numa_node
= NUMA_NO_NODE
;
1825 ctrl
->tag_set
.flags
= BLK_MQ_F_SHOULD_MERGE
;
1826 ctrl
->tag_set
.cmd_size
= sizeof(struct nvme_rdma_request
) +
1827 SG_CHUNK_SIZE
* sizeof(struct scatterlist
);
1828 ctrl
->tag_set
.driver_data
= ctrl
;
1829 ctrl
->tag_set
.nr_hw_queues
= ctrl
->queue_count
- 1;
1830 ctrl
->tag_set
.timeout
= NVME_IO_TIMEOUT
;
1832 ret
= blk_mq_alloc_tag_set(&ctrl
->tag_set
);
1835 ctrl
->ctrl
.tagset
= &ctrl
->tag_set
;
1837 ctrl
->ctrl
.connect_q
= blk_mq_init_queue(&ctrl
->tag_set
);
1838 if (IS_ERR(ctrl
->ctrl
.connect_q
)) {
1839 ret
= PTR_ERR(ctrl
->ctrl
.connect_q
);
1840 goto out_free_tag_set
;
1843 ret
= nvme_rdma_connect_io_queues(ctrl
);
1845 goto out_cleanup_connect_q
;
1849 out_cleanup_connect_q
:
1850 blk_cleanup_queue(ctrl
->ctrl
.connect_q
);
1852 blk_mq_free_tag_set(&ctrl
->tag_set
);
1854 nvme_rdma_dev_put(ctrl
->device
);
1856 nvme_rdma_free_io_queues(ctrl
);
1860 static int nvme_rdma_parse_ipaddr(struct sockaddr_in
*in_addr
, char *p
)
1862 u8
*addr
= (u8
*)&in_addr
->sin_addr
.s_addr
;
1863 size_t buflen
= strlen(p
);
1865 /* XXX: handle IPv6 addresses */
1867 if (buflen
> INET_ADDRSTRLEN
)
1869 if (in4_pton(p
, buflen
, addr
, '\0', NULL
) == 0)
1871 in_addr
->sin_family
= AF_INET
;
1875 static struct nvme_ctrl
*nvme_rdma_create_ctrl(struct device
*dev
,
1876 struct nvmf_ctrl_options
*opts
)
1878 struct nvme_rdma_ctrl
*ctrl
;
1882 ctrl
= kzalloc(sizeof(*ctrl
), GFP_KERNEL
);
1884 return ERR_PTR(-ENOMEM
);
1885 ctrl
->ctrl
.opts
= opts
;
1886 INIT_LIST_HEAD(&ctrl
->list
);
1888 ret
= nvme_rdma_parse_ipaddr(&ctrl
->addr_in
, opts
->traddr
);
1890 pr_err("malformed IP address passed: %s\n", opts
->traddr
);
1894 if (opts
->mask
& NVMF_OPT_HOST_TRADDR
) {
1895 ret
= nvme_rdma_parse_ipaddr(&ctrl
->src_addr_in
,
1898 pr_err("malformed src IP address passed: %s\n",
1904 if (opts
->mask
& NVMF_OPT_TRSVCID
) {
1907 ret
= kstrtou16(opts
->trsvcid
, 0, &port
);
1911 ctrl
->addr_in
.sin_port
= cpu_to_be16(port
);
1913 ctrl
->addr_in
.sin_port
= cpu_to_be16(NVME_RDMA_IP_PORT
);
1916 ret
= nvme_init_ctrl(&ctrl
->ctrl
, dev
, &nvme_rdma_ctrl_ops
,
1917 0 /* no quirks, we're perfect! */);
1921 ctrl
->reconnect_delay
= opts
->reconnect_delay
;
1922 INIT_DELAYED_WORK(&ctrl
->reconnect_work
,
1923 nvme_rdma_reconnect_ctrl_work
);
1924 INIT_WORK(&ctrl
->err_work
, nvme_rdma_error_recovery_work
);
1925 INIT_WORK(&ctrl
->delete_work
, nvme_rdma_del_ctrl_work
);
1926 INIT_WORK(&ctrl
->reset_work
, nvme_rdma_reset_ctrl_work
);
1927 spin_lock_init(&ctrl
->lock
);
1929 ctrl
->queue_count
= opts
->nr_io_queues
+ 1; /* +1 for admin queue */
1930 ctrl
->ctrl
.sqsize
= opts
->queue_size
- 1;
1931 ctrl
->ctrl
.kato
= opts
->kato
;
1934 ctrl
->queues
= kcalloc(ctrl
->queue_count
, sizeof(*ctrl
->queues
),
1937 goto out_uninit_ctrl
;
1939 ret
= nvme_rdma_configure_admin_queue(ctrl
);
1941 goto out_kfree_queues
;
1943 /* sanity check icdoff */
1944 if (ctrl
->ctrl
.icdoff
) {
1945 dev_err(ctrl
->ctrl
.device
, "icdoff is not supported!\n");
1946 goto out_remove_admin_queue
;
1949 /* sanity check keyed sgls */
1950 if (!(ctrl
->ctrl
.sgls
& (1 << 20))) {
1951 dev_err(ctrl
->ctrl
.device
, "Mandatory keyed sgls are not support\n");
1952 goto out_remove_admin_queue
;
1955 if (opts
->queue_size
> ctrl
->ctrl
.maxcmd
) {
1956 /* warn if maxcmd is lower than queue_size */
1957 dev_warn(ctrl
->ctrl
.device
,
1958 "queue_size %zu > ctrl maxcmd %u, clamping down\n",
1959 opts
->queue_size
, ctrl
->ctrl
.maxcmd
);
1960 opts
->queue_size
= ctrl
->ctrl
.maxcmd
;
1963 if (opts
->queue_size
> ctrl
->ctrl
.sqsize
+ 1) {
1964 /* warn if sqsize is lower than queue_size */
1965 dev_warn(ctrl
->ctrl
.device
,
1966 "queue_size %zu > ctrl sqsize %u, clamping down\n",
1967 opts
->queue_size
, ctrl
->ctrl
.sqsize
+ 1);
1968 opts
->queue_size
= ctrl
->ctrl
.sqsize
+ 1;
1971 if (opts
->nr_io_queues
) {
1972 ret
= nvme_rdma_create_io_queues(ctrl
);
1974 goto out_remove_admin_queue
;
1977 changed
= nvme_change_ctrl_state(&ctrl
->ctrl
, NVME_CTRL_LIVE
);
1978 WARN_ON_ONCE(!changed
);
1980 dev_info(ctrl
->ctrl
.device
, "new ctrl: NQN \"%s\", addr %pISp\n",
1981 ctrl
->ctrl
.opts
->subsysnqn
, &ctrl
->addr
);
1983 kref_get(&ctrl
->ctrl
.kref
);
1985 mutex_lock(&nvme_rdma_ctrl_mutex
);
1986 list_add_tail(&ctrl
->list
, &nvme_rdma_ctrl_list
);
1987 mutex_unlock(&nvme_rdma_ctrl_mutex
);
1989 if (opts
->nr_io_queues
) {
1990 nvme_queue_scan(&ctrl
->ctrl
);
1991 nvme_queue_async_events(&ctrl
->ctrl
);
1996 out_remove_admin_queue
:
1997 nvme_stop_keep_alive(&ctrl
->ctrl
);
1998 nvme_rdma_destroy_admin_queue(ctrl
);
2000 kfree(ctrl
->queues
);
2002 nvme_uninit_ctrl(&ctrl
->ctrl
);
2003 nvme_put_ctrl(&ctrl
->ctrl
);
2006 return ERR_PTR(ret
);
2009 return ERR_PTR(ret
);
2012 static struct nvmf_transport_ops nvme_rdma_transport
= {
2014 .required_opts
= NVMF_OPT_TRADDR
,
2015 .allowed_opts
= NVMF_OPT_TRSVCID
| NVMF_OPT_RECONNECT_DELAY
|
2016 NVMF_OPT_HOST_TRADDR
,
2017 .create_ctrl
= nvme_rdma_create_ctrl
,
2020 static void nvme_rdma_add_one(struct ib_device
*ib_device
)
2024 static void nvme_rdma_remove_one(struct ib_device
*ib_device
, void *client_data
)
2026 struct nvme_rdma_ctrl
*ctrl
;
2028 /* Delete all controllers using this device */
2029 mutex_lock(&nvme_rdma_ctrl_mutex
);
2030 list_for_each_entry(ctrl
, &nvme_rdma_ctrl_list
, list
) {
2031 if (ctrl
->device
->dev
!= ib_device
)
2033 dev_info(ctrl
->ctrl
.device
,
2034 "Removing ctrl: NQN \"%s\", addr %pISp\n",
2035 ctrl
->ctrl
.opts
->subsysnqn
, &ctrl
->addr
);
2036 __nvme_rdma_del_ctrl(ctrl
);
2038 mutex_unlock(&nvme_rdma_ctrl_mutex
);
2040 flush_workqueue(nvme_rdma_wq
);
2043 static struct ib_client nvme_rdma_ib_client
= {
2044 .name
= "nvme_rdma",
2045 .add
= nvme_rdma_add_one
,
2046 .remove
= nvme_rdma_remove_one
2049 static int __init
nvme_rdma_init_module(void)
2053 nvme_rdma_wq
= create_workqueue("nvme_rdma_wq");
2057 ret
= ib_register_client(&nvme_rdma_ib_client
);
2059 destroy_workqueue(nvme_rdma_wq
);
2063 return nvmf_register_transport(&nvme_rdma_transport
);
2066 static void __exit
nvme_rdma_cleanup_module(void)
2068 nvmf_unregister_transport(&nvme_rdma_transport
);
2069 ib_unregister_client(&nvme_rdma_ib_client
);
2070 destroy_workqueue(nvme_rdma_wq
);
2073 module_init(nvme_rdma_init_module
);
2074 module_exit(nvme_rdma_cleanup_module
);
2076 MODULE_LICENSE("GPL v2");