Lines Matching +full:no +full:- +full:memory +full:- +full:wc

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
14 #include <linux/blk-mq.h>
15 #include <linux/blk-integrity.h>
25 #include <linux/nvme-rdma.h>
144 * allows read and write access to all physical memory.
149 "Use memory registration even for contiguous memory regions");
153 static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc);
161 return queue - queue->ctrl->queues; in nvme_rdma_queue_idx()
167 queue->ctrl->io_queues[HCTX_TYPE_DEFAULT] + in nvme_rdma_poll_queue()
168 queue->ctrl->io_queues[HCTX_TYPE_READ]; in nvme_rdma_poll_queue()
173 return queue->cmnd_capsule_len - sizeof(struct nvme_command); in nvme_rdma_inline_data_size()
179 ib_dma_unmap_single(ibdev, qe->dma, capsule_size, dir); in nvme_rdma_free_qe()
180 kfree(qe->data); in nvme_rdma_free_qe()
186 qe->data = kzalloc(capsule_size, GFP_KERNEL); in nvme_rdma_alloc_qe()
187 if (!qe->data) in nvme_rdma_alloc_qe()
188 return -ENOMEM; in nvme_rdma_alloc_qe()
190 qe->dma = ib_dma_map_single(ibdev, qe->data, capsule_size, dir); in nvme_rdma_alloc_qe()
191 if (ib_dma_mapping_error(ibdev, qe->dma)) { in nvme_rdma_alloc_qe()
192 kfree(qe->data); in nvme_rdma_alloc_qe()
193 qe->data = NULL; in nvme_rdma_alloc_qe()
194 return -ENOMEM; in nvme_rdma_alloc_qe()
225 * will issue error recovery and queue re-creation. in nvme_rdma_alloc_ring()
242 ib_event_msg(event->event), event->event); in nvme_rdma_qp_event()
250 ret = wait_for_completion_interruptible(&queue->cm_done); in nvme_rdma_wait_for_cm()
253 WARN_ON_ONCE(queue->cm_error > 0); in nvme_rdma_wait_for_cm()
254 return queue->cm_error; in nvme_rdma_wait_for_cm()
259 struct nvme_rdma_device *dev = queue->device; in nvme_rdma_create_qp()
266 init_attr.cap.max_send_wr = factor * queue->queue_size + 1; in nvme_rdma_create_qp()
268 init_attr.cap.max_recv_wr = queue->queue_size + 1; in nvme_rdma_create_qp()
270 init_attr.cap.max_send_sge = 1 + dev->num_inline_segments; in nvme_rdma_create_qp()
273 init_attr.send_cq = queue->ib_cq; in nvme_rdma_create_qp()
274 init_attr.recv_cq = queue->ib_cq; in nvme_rdma_create_qp()
275 if (queue->pi_support) in nvme_rdma_create_qp()
279 ret = rdma_create_qp(queue->cm_id, dev->pd, &init_attr); in nvme_rdma_create_qp()
281 queue->qp = queue->cm_id->qp; in nvme_rdma_create_qp()
290 kfree(req->sqe.data); in nvme_rdma_exit_request()
297 struct nvme_rdma_ctrl *ctrl = to_rdma_ctrl(set->driver_data); in nvme_rdma_init_request()
299 int queue_idx = (set == &ctrl->tag_set) ? hctx_idx + 1 : 0; in nvme_rdma_init_request()
300 struct nvme_rdma_queue *queue = &ctrl->queues[queue_idx]; in nvme_rdma_init_request()
302 nvme_req(rq)->ctrl = &ctrl->ctrl; in nvme_rdma_init_request()
303 req->sqe.data = kzalloc(sizeof(struct nvme_command), GFP_KERNEL); in nvme_rdma_init_request()
304 if (!req->sqe.data) in nvme_rdma_init_request()
305 return -ENOMEM; in nvme_rdma_init_request()
308 if (queue->pi_support) in nvme_rdma_init_request()
309 req->metadata_sgl = (void *)nvme_req(rq) + in nvme_rdma_init_request()
313 req->queue = queue; in nvme_rdma_init_request()
314 nvme_req(rq)->cmd = req->sqe.data; in nvme_rdma_init_request()
323 struct nvme_rdma_queue *queue = &ctrl->queues[hctx_idx + 1]; in nvme_rdma_init_hctx()
325 BUG_ON(hctx_idx >= ctrl->ctrl.queue_count); in nvme_rdma_init_hctx()
327 hctx->driver_data = queue; in nvme_rdma_init_hctx()
335 struct nvme_rdma_queue *queue = &ctrl->queues[0]; in nvme_rdma_init_admin_hctx()
339 hctx->driver_data = queue; in nvme_rdma_init_admin_hctx()
349 list_del(&ndev->entry); in nvme_rdma_free_dev()
352 ib_dealloc_pd(ndev->pd); in nvme_rdma_free_dev()
358 kref_put(&dev->ref, nvme_rdma_free_dev); in nvme_rdma_dev_put()
363 return kref_get_unless_zero(&dev->ref); in nvme_rdma_dev_get()
373 if (ndev->dev->node_guid == cm_id->device->node_guid && in nvme_rdma_find_get_device()
382 ndev->dev = cm_id->device; in nvme_rdma_find_get_device()
383 kref_init(&ndev->ref); in nvme_rdma_find_get_device()
385 ndev->pd = ib_alloc_pd(ndev->dev, in nvme_rdma_find_get_device()
387 if (IS_ERR(ndev->pd)) in nvme_rdma_find_get_device()
390 if (!(ndev->dev->attrs.device_cap_flags & in nvme_rdma_find_get_device()
392 dev_err(&ndev->dev->dev, in nvme_rdma_find_get_device()
393 "Memory registrations not supported.\n"); in nvme_rdma_find_get_device()
397 ndev->num_inline_segments = min(NVME_RDMA_MAX_INLINE_SEGMENTS, in nvme_rdma_find_get_device()
398 ndev->dev->attrs.max_send_sge - 1); in nvme_rdma_find_get_device()
399 list_add(&ndev->entry, &device_list); in nvme_rdma_find_get_device()
405 ib_dealloc_pd(ndev->pd); in nvme_rdma_find_get_device()
416 ib_free_cq(queue->ib_cq); in nvme_rdma_free_cq()
418 ib_cq_pool_put(queue->ib_cq, queue->cq_size); in nvme_rdma_free_cq()
426 if (!test_and_clear_bit(NVME_RDMA_Q_TR_READY, &queue->flags)) in nvme_rdma_destroy_queue_ib()
429 dev = queue->device; in nvme_rdma_destroy_queue_ib()
430 ibdev = dev->dev; in nvme_rdma_destroy_queue_ib()
432 if (queue->pi_support) in nvme_rdma_destroy_queue_ib()
433 ib_mr_pool_destroy(queue->qp, &queue->qp->sig_mrs); in nvme_rdma_destroy_queue_ib()
434 ib_mr_pool_destroy(queue->qp, &queue->qp->rdma_mrs); in nvme_rdma_destroy_queue_ib()
441 ib_destroy_qp(queue->qp); in nvme_rdma_destroy_queue_ib()
444 nvme_rdma_free_ring(ibdev, queue->rsp_ring, queue->queue_size, in nvme_rdma_destroy_queue_ib()
455 max_page_list_len = ibdev->attrs.max_pi_fast_reg_page_list_len; in nvme_rdma_get_max_fr_pages()
457 max_page_list_len = ibdev->attrs.max_fast_reg_page_list_len; in nvme_rdma_get_max_fr_pages()
459 return min_t(u32, NVME_RDMA_MAX_SEGMENTS, max_page_list_len - 1); in nvme_rdma_get_max_fr_pages()
471 comp_vector = (idx == 0 ? idx : idx - 1) % ibdev->num_comp_vectors; in nvme_rdma_create_cq()
475 queue->ib_cq = ib_alloc_cq(ibdev, queue, queue->cq_size, in nvme_rdma_create_cq()
478 queue->ib_cq = ib_cq_pool_get(ibdev, queue->cq_size, in nvme_rdma_create_cq()
481 if (IS_ERR(queue->ib_cq)) { in nvme_rdma_create_cq()
482 ret = PTR_ERR(queue->ib_cq); in nvme_rdma_create_cq()
496 queue->device = nvme_rdma_find_get_device(queue->cm_id); in nvme_rdma_create_queue_ib()
497 if (!queue->device) { in nvme_rdma_create_queue_ib()
498 dev_err(queue->cm_id->device->dev.parent, in nvme_rdma_create_queue_ib()
499 "no client data found!\n"); in nvme_rdma_create_queue_ib()
500 return -ECONNREFUSED; in nvme_rdma_create_queue_ib()
502 ibdev = queue->device->dev; in nvme_rdma_create_queue_ib()
505 queue->cq_size = cq_factor * queue->queue_size + 1; in nvme_rdma_create_queue_ib()
515 queue->rsp_ring = nvme_rdma_alloc_ring(ibdev, queue->queue_size, in nvme_rdma_create_queue_ib()
517 if (!queue->rsp_ring) { in nvme_rdma_create_queue_ib()
518 ret = -ENOMEM; in nvme_rdma_create_queue_ib()
527 pages_per_mr = nvme_rdma_get_max_fr_pages(ibdev, queue->pi_support) + 1; in nvme_rdma_create_queue_ib()
528 ret = ib_mr_pool_init(queue->qp, &queue->qp->rdma_mrs, in nvme_rdma_create_queue_ib()
529 queue->queue_size, in nvme_rdma_create_queue_ib()
533 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_create_queue_ib()
535 queue->queue_size, nvme_rdma_queue_idx(queue)); in nvme_rdma_create_queue_ib()
539 if (queue->pi_support) { in nvme_rdma_create_queue_ib()
540 ret = ib_mr_pool_init(queue->qp, &queue->qp->sig_mrs, in nvme_rdma_create_queue_ib()
541 queue->queue_size, IB_MR_TYPE_INTEGRITY, in nvme_rdma_create_queue_ib()
544 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_create_queue_ib()
546 queue->queue_size, nvme_rdma_queue_idx(queue)); in nvme_rdma_create_queue_ib()
551 set_bit(NVME_RDMA_Q_TR_READY, &queue->flags); in nvme_rdma_create_queue_ib()
556 ib_mr_pool_destroy(queue->qp, &queue->qp->rdma_mrs); in nvme_rdma_create_queue_ib()
558 nvme_rdma_free_ring(ibdev, queue->rsp_ring, queue->queue_size, in nvme_rdma_create_queue_ib()
561 rdma_destroy_qp(queue->cm_id); in nvme_rdma_create_queue_ib()
565 nvme_rdma_dev_put(queue->device); in nvme_rdma_create_queue_ib()
576 queue = &ctrl->queues[idx]; in nvme_rdma_alloc_queue()
577 mutex_init(&queue->queue_lock); in nvme_rdma_alloc_queue()
578 queue->ctrl = ctrl; in nvme_rdma_alloc_queue()
579 if (idx && ctrl->ctrl.max_integrity_segments) in nvme_rdma_alloc_queue()
580 queue->pi_support = true; in nvme_rdma_alloc_queue()
582 queue->pi_support = false; in nvme_rdma_alloc_queue()
583 init_completion(&queue->cm_done); in nvme_rdma_alloc_queue()
586 queue->cmnd_capsule_len = ctrl->ctrl.ioccsz * 16; in nvme_rdma_alloc_queue()
588 queue->cmnd_capsule_len = sizeof(struct nvme_command); in nvme_rdma_alloc_queue()
590 queue->queue_size = queue_size; in nvme_rdma_alloc_queue()
592 queue->cm_id = rdma_create_id(&init_net, nvme_rdma_cm_handler, queue, in nvme_rdma_alloc_queue()
594 if (IS_ERR(queue->cm_id)) { in nvme_rdma_alloc_queue()
595 dev_info(ctrl->ctrl.device, in nvme_rdma_alloc_queue()
596 "failed to create CM ID: %ld\n", PTR_ERR(queue->cm_id)); in nvme_rdma_alloc_queue()
597 ret = PTR_ERR(queue->cm_id); in nvme_rdma_alloc_queue()
601 if (ctrl->ctrl.opts->mask & NVMF_OPT_HOST_TRADDR) in nvme_rdma_alloc_queue()
602 src_addr = (struct sockaddr *)&ctrl->src_addr; in nvme_rdma_alloc_queue()
604 queue->cm_error = -ETIMEDOUT; in nvme_rdma_alloc_queue()
605 ret = rdma_resolve_addr(queue->cm_id, src_addr, in nvme_rdma_alloc_queue()
606 (struct sockaddr *)&ctrl->addr, in nvme_rdma_alloc_queue()
609 dev_info(ctrl->ctrl.device, in nvme_rdma_alloc_queue()
616 dev_info(ctrl->ctrl.device, in nvme_rdma_alloc_queue()
621 set_bit(NVME_RDMA_Q_ALLOCATED, &queue->flags); in nvme_rdma_alloc_queue()
626 rdma_destroy_id(queue->cm_id); in nvme_rdma_alloc_queue()
629 mutex_destroy(&queue->queue_lock); in nvme_rdma_alloc_queue()
635 rdma_disconnect(queue->cm_id); in __nvme_rdma_stop_queue()
636 ib_drain_qp(queue->qp); in __nvme_rdma_stop_queue()
641 if (!test_bit(NVME_RDMA_Q_ALLOCATED, &queue->flags)) in nvme_rdma_stop_queue()
644 mutex_lock(&queue->queue_lock); in nvme_rdma_stop_queue()
645 if (test_and_clear_bit(NVME_RDMA_Q_LIVE, &queue->flags)) in nvme_rdma_stop_queue()
647 mutex_unlock(&queue->queue_lock); in nvme_rdma_stop_queue()
652 if (!test_and_clear_bit(NVME_RDMA_Q_ALLOCATED, &queue->flags)) in nvme_rdma_free_queue()
655 rdma_destroy_id(queue->cm_id); in nvme_rdma_free_queue()
657 mutex_destroy(&queue->queue_lock); in nvme_rdma_free_queue()
664 for (i = 1; i < ctrl->ctrl.queue_count; i++) in nvme_rdma_free_io_queues()
665 nvme_rdma_free_queue(&ctrl->queues[i]); in nvme_rdma_free_io_queues()
672 for (i = 1; i < ctrl->ctrl.queue_count; i++) in nvme_rdma_stop_io_queues()
673 nvme_rdma_stop_queue(&ctrl->queues[i]); in nvme_rdma_stop_io_queues()
678 struct nvme_rdma_queue *queue = &ctrl->queues[idx]; in nvme_rdma_start_queue()
682 ret = nvmf_connect_io_queue(&ctrl->ctrl, idx); in nvme_rdma_start_queue()
684 ret = nvmf_connect_admin_queue(&ctrl->ctrl); in nvme_rdma_start_queue()
687 set_bit(NVME_RDMA_Q_LIVE, &queue->flags); in nvme_rdma_start_queue()
689 if (test_bit(NVME_RDMA_Q_ALLOCATED, &queue->flags)) in nvme_rdma_start_queue()
691 dev_info(ctrl->ctrl.device, in nvme_rdma_start_queue()
711 for (i--; i >= first; i--) in nvme_rdma_start_io_queues()
712 nvme_rdma_stop_queue(&ctrl->queues[i]); in nvme_rdma_start_io_queues()
718 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts; in nvme_rdma_alloc_io_queues()
723 ret = nvme_set_queue_count(&ctrl->ctrl, &nr_io_queues); in nvme_rdma_alloc_io_queues()
728 dev_err(ctrl->ctrl.device, in nvme_rdma_alloc_io_queues()
730 return -ENOMEM; in nvme_rdma_alloc_io_queues()
733 ctrl->ctrl.queue_count = nr_io_queues + 1; in nvme_rdma_alloc_io_queues()
734 dev_info(ctrl->ctrl.device, in nvme_rdma_alloc_io_queues()
737 nvmf_set_io_queues(opts, nr_io_queues, ctrl->io_queues); in nvme_rdma_alloc_io_queues()
738 for (i = 1; i < ctrl->ctrl.queue_count; i++) { in nvme_rdma_alloc_io_queues()
740 ctrl->ctrl.sqsize + 1); in nvme_rdma_alloc_io_queues()
748 for (i--; i >= 1; i--) in nvme_rdma_alloc_io_queues()
749 nvme_rdma_free_queue(&ctrl->queues[i]); in nvme_rdma_alloc_io_queues()
759 if (ctrl->max_integrity_segments) in nvme_rdma_alloc_tag_set()
763 return nvme_alloc_io_tag_set(ctrl, &to_rdma_ctrl(ctrl)->tag_set, in nvme_rdma_alloc_tag_set()
765 ctrl->opts->nr_poll_queues ? HCTX_MAX_TYPES : 2, in nvme_rdma_alloc_tag_set()
771 if (ctrl->async_event_sqe.data) { in nvme_rdma_destroy_admin_queue()
772 cancel_work_sync(&ctrl->ctrl.async_event_work); in nvme_rdma_destroy_admin_queue()
773 nvme_rdma_free_qe(ctrl->device->dev, &ctrl->async_event_sqe, in nvme_rdma_destroy_admin_queue()
775 ctrl->async_event_sqe.data = NULL; in nvme_rdma_destroy_admin_queue()
777 nvme_rdma_free_queue(&ctrl->queues[0]); in nvme_rdma_destroy_admin_queue()
790 ctrl->device = ctrl->queues[0].device; in nvme_rdma_configure_admin_queue()
791 ctrl->ctrl.numa_node = ibdev_to_node(ctrl->device->dev); in nvme_rdma_configure_admin_queue()
793 /* T10-PI support */ in nvme_rdma_configure_admin_queue()
794 if (ctrl->device->dev->attrs.kernel_cap_flags & in nvme_rdma_configure_admin_queue()
798 ctrl->max_fr_pages = nvme_rdma_get_max_fr_pages(ctrl->device->dev, in nvme_rdma_configure_admin_queue()
804 * error recovery and queue re-creation. in nvme_rdma_configure_admin_queue()
806 error = nvme_rdma_alloc_qe(ctrl->device->dev, &ctrl->async_event_sqe, in nvme_rdma_configure_admin_queue()
812 error = nvme_alloc_admin_tag_set(&ctrl->ctrl, in nvme_rdma_configure_admin_queue()
813 &ctrl->admin_tag_set, &nvme_rdma_admin_mq_ops, in nvme_rdma_configure_admin_queue()
825 error = nvme_enable_ctrl(&ctrl->ctrl); in nvme_rdma_configure_admin_queue()
829 ctrl->ctrl.max_segments = ctrl->max_fr_pages; in nvme_rdma_configure_admin_queue()
830 ctrl->ctrl.max_hw_sectors = ctrl->max_fr_pages << (ilog2(SZ_4K) - 9); in nvme_rdma_configure_admin_queue()
832 ctrl->ctrl.max_integrity_segments = ctrl->max_fr_pages; in nvme_rdma_configure_admin_queue()
834 ctrl->ctrl.max_integrity_segments = 0; in nvme_rdma_configure_admin_queue()
836 nvme_unquiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_configure_admin_queue()
838 error = nvme_init_ctrl_finish(&ctrl->ctrl, false); in nvme_rdma_configure_admin_queue()
845 nvme_quiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_configure_admin_queue()
846 blk_sync_queue(ctrl->ctrl.admin_q); in nvme_rdma_configure_admin_queue()
848 nvme_rdma_stop_queue(&ctrl->queues[0]); in nvme_rdma_configure_admin_queue()
849 nvme_cancel_admin_tagset(&ctrl->ctrl); in nvme_rdma_configure_admin_queue()
852 nvme_remove_admin_tag_set(&ctrl->ctrl); in nvme_rdma_configure_admin_queue()
854 if (ctrl->async_event_sqe.data) { in nvme_rdma_configure_admin_queue()
855 nvme_rdma_free_qe(ctrl->device->dev, &ctrl->async_event_sqe, in nvme_rdma_configure_admin_queue()
857 ctrl->async_event_sqe.data = NULL; in nvme_rdma_configure_admin_queue()
860 nvme_rdma_free_queue(&ctrl->queues[0]); in nvme_rdma_configure_admin_queue()
873 ret = nvme_rdma_alloc_tag_set(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
883 nr_queues = min(ctrl->tag_set.nr_hw_queues + 1, ctrl->ctrl.queue_count); in nvme_rdma_configure_io_queues()
889 nvme_start_freeze(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
890 nvme_unquiesce_io_queues(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
891 if (!nvme_wait_freeze_timeout(&ctrl->ctrl, NVME_IO_TIMEOUT)) { in nvme_rdma_configure_io_queues()
897 ret = -ENODEV; in nvme_rdma_configure_io_queues()
898 nvme_unfreeze(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
901 blk_mq_update_nr_hw_queues(ctrl->ctrl.tagset, in nvme_rdma_configure_io_queues()
902 ctrl->ctrl.queue_count - 1); in nvme_rdma_configure_io_queues()
903 nvme_unfreeze(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
911 ctrl->tag_set.nr_hw_queues + 1); in nvme_rdma_configure_io_queues()
918 nvme_quiesce_io_queues(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
919 nvme_sync_io_queues(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
922 nvme_cancel_tagset(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
924 nvme_remove_io_tag_set(&ctrl->ctrl); in nvme_rdma_configure_io_queues()
933 nvme_quiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_teardown_admin_queue()
934 blk_sync_queue(ctrl->ctrl.admin_q); in nvme_rdma_teardown_admin_queue()
935 nvme_rdma_stop_queue(&ctrl->queues[0]); in nvme_rdma_teardown_admin_queue()
936 nvme_cancel_admin_tagset(&ctrl->ctrl); in nvme_rdma_teardown_admin_queue()
938 nvme_unquiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_teardown_admin_queue()
939 nvme_remove_admin_tag_set(&ctrl->ctrl); in nvme_rdma_teardown_admin_queue()
947 if (ctrl->ctrl.queue_count > 1) { in nvme_rdma_teardown_io_queues()
948 nvme_quiesce_io_queues(&ctrl->ctrl); in nvme_rdma_teardown_io_queues()
949 nvme_sync_io_queues(&ctrl->ctrl); in nvme_rdma_teardown_io_queues()
951 nvme_cancel_tagset(&ctrl->ctrl); in nvme_rdma_teardown_io_queues()
953 nvme_unquiesce_io_queues(&ctrl->ctrl); in nvme_rdma_teardown_io_queues()
954 nvme_remove_io_tag_set(&ctrl->ctrl); in nvme_rdma_teardown_io_queues()
964 flush_work(&ctrl->err_work); in nvme_rdma_stop_ctrl()
965 cancel_delayed_work_sync(&ctrl->reconnect_work); in nvme_rdma_stop_ctrl()
972 if (list_empty(&ctrl->list)) in nvme_rdma_free_ctrl()
976 list_del(&ctrl->list); in nvme_rdma_free_ctrl()
979 nvmf_free_options(nctrl->opts); in nvme_rdma_free_ctrl()
981 kfree(ctrl->queues); in nvme_rdma_free_ctrl()
988 enum nvme_ctrl_state state = nvme_ctrl_state(&ctrl->ctrl); in nvme_rdma_reconnect_or_remove()
996 if (nvmf_should_reconnect(&ctrl->ctrl, status)) { in nvme_rdma_reconnect_or_remove()
997 dev_info(ctrl->ctrl.device, "Reconnecting in %d seconds...\n", in nvme_rdma_reconnect_or_remove()
998 ctrl->ctrl.opts->reconnect_delay); in nvme_rdma_reconnect_or_remove()
999 queue_delayed_work(nvme_wq, &ctrl->reconnect_work, in nvme_rdma_reconnect_or_remove()
1000 ctrl->ctrl.opts->reconnect_delay * HZ); in nvme_rdma_reconnect_or_remove()
1002 nvme_delete_ctrl(&ctrl->ctrl); in nvme_rdma_reconnect_or_remove()
1016 if (ctrl->ctrl.icdoff) { in nvme_rdma_setup_ctrl()
1017 ret = -EOPNOTSUPP; in nvme_rdma_setup_ctrl()
1018 dev_err(ctrl->ctrl.device, "icdoff is not supported!\n"); in nvme_rdma_setup_ctrl()
1022 if (!(ctrl->ctrl.sgls & NVME_CTRL_SGLS_KSDBDS)) { in nvme_rdma_setup_ctrl()
1023 ret = -EOPNOTSUPP; in nvme_rdma_setup_ctrl()
1024 dev_err(ctrl->ctrl.device, in nvme_rdma_setup_ctrl()
1029 if (ctrl->ctrl.opts->queue_size > ctrl->ctrl.sqsize + 1) { in nvme_rdma_setup_ctrl()
1030 dev_warn(ctrl->ctrl.device, in nvme_rdma_setup_ctrl()
1032 ctrl->ctrl.opts->queue_size, ctrl->ctrl.sqsize + 1); in nvme_rdma_setup_ctrl()
1035 if (ctrl->ctrl.max_integrity_segments) in nvme_rdma_setup_ctrl()
1040 if (ctrl->ctrl.sqsize + 1 > max_queue_size) { in nvme_rdma_setup_ctrl()
1041 dev_warn(ctrl->ctrl.device, in nvme_rdma_setup_ctrl()
1043 ctrl->ctrl.sqsize + 1, max_queue_size); in nvme_rdma_setup_ctrl()
1044 ctrl->ctrl.sqsize = max_queue_size - 1; in nvme_rdma_setup_ctrl()
1047 if (ctrl->ctrl.sqsize + 1 > ctrl->ctrl.maxcmd) { in nvme_rdma_setup_ctrl()
1048 dev_warn(ctrl->ctrl.device, in nvme_rdma_setup_ctrl()
1050 ctrl->ctrl.sqsize + 1, ctrl->ctrl.maxcmd); in nvme_rdma_setup_ctrl()
1051 ctrl->ctrl.sqsize = ctrl->ctrl.maxcmd - 1; in nvme_rdma_setup_ctrl()
1054 if (ctrl->ctrl.sgls & NVME_CTRL_SGLS_SAOS) in nvme_rdma_setup_ctrl()
1055 ctrl->use_inline_data = true; in nvme_rdma_setup_ctrl()
1057 if (ctrl->ctrl.queue_count > 1) { in nvme_rdma_setup_ctrl()
1063 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE); in nvme_rdma_setup_ctrl()
1070 enum nvme_ctrl_state state = nvme_ctrl_state(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1075 ret = -EINVAL; in nvme_rdma_setup_ctrl()
1079 nvme_start_ctrl(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1083 if (ctrl->ctrl.queue_count > 1) { in nvme_rdma_setup_ctrl()
1084 nvme_quiesce_io_queues(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1085 nvme_sync_io_queues(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1087 nvme_cancel_tagset(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1089 nvme_remove_io_tag_set(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1093 nvme_stop_keep_alive(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1104 ++ctrl->ctrl.nr_reconnects; in nvme_rdma_reconnect_ctrl_work()
1110 dev_info(ctrl->ctrl.device, "Successfully reconnected (%d attempts)\n", in nvme_rdma_reconnect_ctrl_work()
1111 ctrl->ctrl.nr_reconnects); in nvme_rdma_reconnect_ctrl_work()
1113 ctrl->ctrl.nr_reconnects = 0; in nvme_rdma_reconnect_ctrl_work()
1118 dev_info(ctrl->ctrl.device, "Failed reconnect attempt %d/%d\n", in nvme_rdma_reconnect_ctrl_work()
1119 ctrl->ctrl.nr_reconnects, ctrl->ctrl.opts->max_reconnects); in nvme_rdma_reconnect_ctrl_work()
1128 nvme_stop_keep_alive(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1129 flush_work(&ctrl->ctrl.async_event_work); in nvme_rdma_error_recovery_work()
1131 nvme_unquiesce_io_queues(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1133 nvme_unquiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1134 nvme_auth_stop(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1136 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { in nvme_rdma_error_recovery_work()
1138 enum nvme_ctrl_state state = nvme_ctrl_state(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1150 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RESETTING)) in nvme_rdma_error_recovery()
1153 dev_warn(ctrl->ctrl.device, "starting error recovery\n"); in nvme_rdma_error_recovery()
1154 queue_work(nvme_reset_wq, &ctrl->err_work); in nvme_rdma_error_recovery()
1161 if (!refcount_dec_and_test(&req->ref)) in nvme_rdma_end_request()
1163 if (!nvme_try_complete_req(rq, req->status, req->result)) in nvme_rdma_end_request()
1167 static void nvme_rdma_wr_error(struct ib_cq *cq, struct ib_wc *wc, in nvme_rdma_wr_error() argument
1170 struct nvme_rdma_queue *queue = wc->qp->qp_context; in nvme_rdma_wr_error()
1171 struct nvme_rdma_ctrl *ctrl = queue->ctrl; in nvme_rdma_wr_error()
1173 if (nvme_ctrl_state(&ctrl->ctrl) == NVME_CTRL_LIVE) in nvme_rdma_wr_error()
1174 dev_info(ctrl->ctrl.device, in nvme_rdma_wr_error()
1176 op, wc->wr_cqe, in nvme_rdma_wr_error()
1177 ib_wc_status_msg(wc->status), wc->status); in nvme_rdma_wr_error()
1181 static void nvme_rdma_memreg_done(struct ib_cq *cq, struct ib_wc *wc) in nvme_rdma_memreg_done() argument
1183 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_memreg_done()
1184 nvme_rdma_wr_error(cq, wc, "MEMREG"); in nvme_rdma_memreg_done()
1187 static void nvme_rdma_inv_rkey_done(struct ib_cq *cq, struct ib_wc *wc) in nvme_rdma_inv_rkey_done() argument
1190 container_of(wc->wr_cqe, struct nvme_rdma_request, reg_cqe); in nvme_rdma_inv_rkey_done()
1192 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_inv_rkey_done()
1193 nvme_rdma_wr_error(cq, wc, "LOCAL_INV"); in nvme_rdma_inv_rkey_done()
1206 .ex.invalidate_rkey = req->mr->rkey, in nvme_rdma_inv_rkey()
1209 req->reg_cqe.done = nvme_rdma_inv_rkey_done; in nvme_rdma_inv_rkey()
1210 wr.wr_cqe = &req->reg_cqe; in nvme_rdma_inv_rkey()
1212 return ib_post_send(queue->qp, &wr, NULL); in nvme_rdma_inv_rkey()
1220 ib_dma_unmap_sg(ibdev, req->metadata_sgl->sg_table.sgl, in nvme_rdma_dma_unmap_req()
1221 req->metadata_sgl->nents, rq_dma_dir(rq)); in nvme_rdma_dma_unmap_req()
1222 sg_free_table_chained(&req->metadata_sgl->sg_table, in nvme_rdma_dma_unmap_req()
1226 ib_dma_unmap_sg(ibdev, req->data_sgl.sg_table.sgl, req->data_sgl.nents, in nvme_rdma_dma_unmap_req()
1228 sg_free_table_chained(&req->data_sgl.sg_table, NVME_INLINE_SG_CNT); in nvme_rdma_dma_unmap_req()
1235 struct nvme_rdma_device *dev = queue->device; in nvme_rdma_unmap_data()
1236 struct ib_device *ibdev = dev->dev; in nvme_rdma_unmap_data()
1237 struct list_head *pool = &queue->qp->rdma_mrs; in nvme_rdma_unmap_data()
1242 if (req->use_sig_mr) in nvme_rdma_unmap_data()
1243 pool = &queue->qp->sig_mrs; in nvme_rdma_unmap_data()
1245 if (req->mr) { in nvme_rdma_unmap_data()
1246 ib_mr_pool_put(queue->qp, pool, req->mr); in nvme_rdma_unmap_data()
1247 req->mr = NULL; in nvme_rdma_unmap_data()
1255 struct nvme_keyed_sgl_desc *sg = &c->common.dptr.ksgl; in nvme_rdma_set_sg_null()
1257 sg->addr = 0; in nvme_rdma_set_sg_null()
1258 put_unaligned_le24(0, sg->length); in nvme_rdma_set_sg_null()
1259 put_unaligned_le32(0, sg->key); in nvme_rdma_set_sg_null()
1260 sg->type = NVME_KEY_SGL_FMT_DATA_DESC << 4; in nvme_rdma_set_sg_null()
1268 struct nvme_sgl_desc *sg = &c->common.dptr.sgl; in nvme_rdma_map_sg_inline()
1269 struct ib_sge *sge = &req->sge[1]; in nvme_rdma_map_sg_inline()
1274 for_each_sg(req->data_sgl.sg_table.sgl, sgl, count, i) { in nvme_rdma_map_sg_inline()
1275 sge->addr = sg_dma_address(sgl); in nvme_rdma_map_sg_inline()
1276 sge->length = sg_dma_len(sgl); in nvme_rdma_map_sg_inline()
1277 sge->lkey = queue->device->pd->local_dma_lkey; in nvme_rdma_map_sg_inline()
1278 len += sge->length; in nvme_rdma_map_sg_inline()
1282 sg->addr = cpu_to_le64(queue->ctrl->ctrl.icdoff); in nvme_rdma_map_sg_inline()
1283 sg->length = cpu_to_le32(len); in nvme_rdma_map_sg_inline()
1284 sg->type = (NVME_SGL_FMT_DATA_DESC << 4) | NVME_SGL_FMT_OFFSET; in nvme_rdma_map_sg_inline()
1286 req->num_sge += count; in nvme_rdma_map_sg_inline()
1293 struct nvme_keyed_sgl_desc *sg = &c->common.dptr.ksgl; in nvme_rdma_map_sg_single()
1295 sg->addr = cpu_to_le64(sg_dma_address(req->data_sgl.sg_table.sgl)); in nvme_rdma_map_sg_single()
1296 put_unaligned_le24(sg_dma_len(req->data_sgl.sg_table.sgl), sg->length); in nvme_rdma_map_sg_single()
1297 put_unaligned_le32(queue->device->pd->unsafe_global_rkey, sg->key); in nvme_rdma_map_sg_single()
1298 sg->type = NVME_KEY_SGL_FMT_DATA_DESC << 4; in nvme_rdma_map_sg_single()
1306 struct nvme_keyed_sgl_desc *sg = &c->common.dptr.ksgl; in nvme_rdma_map_sg_fr()
1309 req->mr = ib_mr_pool_get(queue->qp, &queue->qp->rdma_mrs); in nvme_rdma_map_sg_fr()
1310 if (WARN_ON_ONCE(!req->mr)) in nvme_rdma_map_sg_fr()
1311 return -EAGAIN; in nvme_rdma_map_sg_fr()
1317 nr = ib_map_mr_sg(req->mr, req->data_sgl.sg_table.sgl, count, NULL, in nvme_rdma_map_sg_fr()
1320 ib_mr_pool_put(queue->qp, &queue->qp->rdma_mrs, req->mr); in nvme_rdma_map_sg_fr()
1321 req->mr = NULL; in nvme_rdma_map_sg_fr()
1324 return -EINVAL; in nvme_rdma_map_sg_fr()
1327 ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey)); in nvme_rdma_map_sg_fr()
1329 req->reg_cqe.done = nvme_rdma_memreg_done; in nvme_rdma_map_sg_fr()
1330 memset(&req->reg_wr, 0, sizeof(req->reg_wr)); in nvme_rdma_map_sg_fr()
1331 req->reg_wr.wr.opcode = IB_WR_REG_MR; in nvme_rdma_map_sg_fr()
1332 req->reg_wr.wr.wr_cqe = &req->reg_cqe; in nvme_rdma_map_sg_fr()
1333 req->reg_wr.wr.num_sge = 0; in nvme_rdma_map_sg_fr()
1334 req->reg_wr.mr = req->mr; in nvme_rdma_map_sg_fr()
1335 req->reg_wr.key = req->mr->rkey; in nvme_rdma_map_sg_fr()
1336 req->reg_wr.access = IB_ACCESS_LOCAL_WRITE | in nvme_rdma_map_sg_fr()
1340 sg->addr = cpu_to_le64(req->mr->iova); in nvme_rdma_map_sg_fr()
1341 put_unaligned_le24(req->mr->length, sg->length); in nvme_rdma_map_sg_fr()
1342 put_unaligned_le32(req->mr->rkey, sg->key); in nvme_rdma_map_sg_fr()
1343 sg->type = (NVME_KEY_SGL_FMT_DATA_DESC << 4) | in nvme_rdma_map_sg_fr()
1353 domain->sig_type = IB_SIG_TYPE_T10_DIF; in nvme_rdma_set_sig_domain()
1354 domain->sig.dif.bg_type = IB_T10DIF_CRC; in nvme_rdma_set_sig_domain()
1355 domain->sig.dif.pi_interval = 1 << bi->interval_exp; in nvme_rdma_set_sig_domain()
1356 domain->sig.dif.ref_tag = le32_to_cpu(cmd->rw.reftag); in nvme_rdma_set_sig_domain()
1358 domain->sig.dif.ref_remap = true; in nvme_rdma_set_sig_domain()
1360 domain->sig.dif.app_tag = le16_to_cpu(cmd->rw.lbat); in nvme_rdma_set_sig_domain()
1361 domain->sig.dif.apptag_check_mask = le16_to_cpu(cmd->rw.lbatm); in nvme_rdma_set_sig_domain()
1362 domain->sig.dif.app_escape = true; in nvme_rdma_set_sig_domain()
1364 domain->sig.dif.ref_escape = true; in nvme_rdma_set_sig_domain()
1371 u16 control = le16_to_cpu(cmd->rw.control); in nvme_rdma_set_sig_attrs()
1375 /* for WRITE_INSERT/READ_STRIP no memory domain */ in nvme_rdma_set_sig_attrs()
1376 sig_attrs->mem.sig_type = IB_SIG_TYPE_NONE; in nvme_rdma_set_sig_attrs()
1377 nvme_rdma_set_sig_domain(bi, cmd, &sig_attrs->wire, control, in nvme_rdma_set_sig_attrs()
1381 cmd->rw.control = cpu_to_le16(control); in nvme_rdma_set_sig_attrs()
1383 /* for WRITE_PASS/READ_PASS both wire/memory domains exist */ in nvme_rdma_set_sig_attrs()
1384 nvme_rdma_set_sig_domain(bi, cmd, &sig_attrs->wire, control, in nvme_rdma_set_sig_attrs()
1386 nvme_rdma_set_sig_domain(bi, cmd, &sig_attrs->mem, control, in nvme_rdma_set_sig_attrs()
1394 if (le16_to_cpu(cmd->rw.control) & NVME_RW_PRINFO_PRCHK_REF) in nvme_rdma_set_prot_checks()
1396 if (le16_to_cpu(cmd->rw.control) & NVME_RW_PRINFO_PRCHK_GUARD) in nvme_rdma_set_prot_checks()
1400 static void nvme_rdma_sig_done(struct ib_cq *cq, struct ib_wc *wc) in nvme_rdma_sig_done() argument
1402 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_sig_done()
1403 nvme_rdma_wr_error(cq, wc, "SIG"); in nvme_rdma_sig_done()
1410 struct nvme_rdma_sgl *sgl = &req->data_sgl; in nvme_rdma_map_sg_pi()
1411 struct ib_reg_wr *wr = &req->reg_wr; in nvme_rdma_map_sg_pi()
1413 struct nvme_ns *ns = rq->q->queuedata; in nvme_rdma_map_sg_pi()
1414 struct bio *bio = rq->bio; in nvme_rdma_map_sg_pi()
1415 struct nvme_keyed_sgl_desc *sg = &c->common.dptr.ksgl; in nvme_rdma_map_sg_pi()
1416 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); in nvme_rdma_map_sg_pi()
1420 req->mr = ib_mr_pool_get(queue->qp, &queue->qp->sig_mrs); in nvme_rdma_map_sg_pi()
1421 if (WARN_ON_ONCE(!req->mr)) in nvme_rdma_map_sg_pi()
1422 return -EAGAIN; in nvme_rdma_map_sg_pi()
1424 nr = ib_map_mr_sg_pi(req->mr, sgl->sg_table.sgl, count, NULL, in nvme_rdma_map_sg_pi()
1425 req->metadata_sgl->sg_table.sgl, pi_count, NULL, in nvme_rdma_map_sg_pi()
1430 nvme_rdma_set_sig_attrs(bi, c, req->mr->sig_attrs, ns->head->pi_type); in nvme_rdma_map_sg_pi()
1431 nvme_rdma_set_prot_checks(c, &req->mr->sig_attrs->check_mask); in nvme_rdma_map_sg_pi()
1433 ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey)); in nvme_rdma_map_sg_pi()
1435 req->reg_cqe.done = nvme_rdma_sig_done; in nvme_rdma_map_sg_pi()
1437 wr->wr.opcode = IB_WR_REG_MR_INTEGRITY; in nvme_rdma_map_sg_pi()
1438 wr->wr.wr_cqe = &req->reg_cqe; in nvme_rdma_map_sg_pi()
1439 wr->wr.num_sge = 0; in nvme_rdma_map_sg_pi()
1440 wr->wr.send_flags = 0; in nvme_rdma_map_sg_pi()
1441 wr->mr = req->mr; in nvme_rdma_map_sg_pi()
1442 wr->key = req->mr->rkey; in nvme_rdma_map_sg_pi()
1443 wr->access = IB_ACCESS_LOCAL_WRITE | in nvme_rdma_map_sg_pi()
1447 sg->addr = cpu_to_le64(req->mr->iova); in nvme_rdma_map_sg_pi()
1448 xfer_len = req->mr->length; in nvme_rdma_map_sg_pi()
1451 xfer_len += (xfer_len >> bi->interval_exp) * ns->head->pi_size; in nvme_rdma_map_sg_pi()
1452 put_unaligned_le24(xfer_len, sg->length); in nvme_rdma_map_sg_pi()
1453 put_unaligned_le32(req->mr->rkey, sg->key); in nvme_rdma_map_sg_pi()
1454 sg->type = NVME_KEY_SGL_FMT_DATA_DESC << 4; in nvme_rdma_map_sg_pi()
1459 ib_mr_pool_put(queue->qp, &queue->qp->sig_mrs, req->mr); in nvme_rdma_map_sg_pi()
1460 req->mr = NULL; in nvme_rdma_map_sg_pi()
1463 return -EINVAL; in nvme_rdma_map_sg_pi()
1472 req->data_sgl.sg_table.sgl = (struct scatterlist *)(req + 1); in nvme_rdma_dma_map_req()
1473 ret = sg_alloc_table_chained(&req->data_sgl.sg_table, in nvme_rdma_dma_map_req()
1474 blk_rq_nr_phys_segments(rq), req->data_sgl.sg_table.sgl, in nvme_rdma_dma_map_req()
1477 return -ENOMEM; in nvme_rdma_dma_map_req()
1479 req->data_sgl.nents = blk_rq_map_sg(rq->q, rq, in nvme_rdma_dma_map_req()
1480 req->data_sgl.sg_table.sgl); in nvme_rdma_dma_map_req()
1482 *count = ib_dma_map_sg(ibdev, req->data_sgl.sg_table.sgl, in nvme_rdma_dma_map_req()
1483 req->data_sgl.nents, rq_dma_dir(rq)); in nvme_rdma_dma_map_req()
1485 ret = -EIO; in nvme_rdma_dma_map_req()
1490 req->metadata_sgl->sg_table.sgl = in nvme_rdma_dma_map_req()
1491 (struct scatterlist *)(req->metadata_sgl + 1); in nvme_rdma_dma_map_req()
1492 ret = sg_alloc_table_chained(&req->metadata_sgl->sg_table, in nvme_rdma_dma_map_req()
1493 rq->nr_integrity_segments, in nvme_rdma_dma_map_req()
1494 req->metadata_sgl->sg_table.sgl, in nvme_rdma_dma_map_req()
1497 ret = -ENOMEM; in nvme_rdma_dma_map_req()
1501 req->metadata_sgl->nents = blk_rq_map_integrity_sg(rq, in nvme_rdma_dma_map_req()
1502 req->metadata_sgl->sg_table.sgl); in nvme_rdma_dma_map_req()
1504 req->metadata_sgl->sg_table.sgl, in nvme_rdma_dma_map_req()
1505 req->metadata_sgl->nents, in nvme_rdma_dma_map_req()
1508 ret = -EIO; in nvme_rdma_dma_map_req()
1516 sg_free_table_chained(&req->metadata_sgl->sg_table, in nvme_rdma_dma_map_req()
1519 ib_dma_unmap_sg(ibdev, req->data_sgl.sg_table.sgl, req->data_sgl.nents, in nvme_rdma_dma_map_req()
1522 sg_free_table_chained(&req->data_sgl.sg_table, NVME_INLINE_SG_CNT); in nvme_rdma_dma_map_req()
1530 struct nvme_rdma_device *dev = queue->device; in nvme_rdma_map_data()
1531 struct ib_device *ibdev = dev->dev; in nvme_rdma_map_data()
1535 req->num_sge = 1; in nvme_rdma_map_data()
1536 refcount_set(&req->ref, 2); /* send and recv completions */ in nvme_rdma_map_data()
1538 c->common.flags |= NVME_CMD_SGL_METABUF; in nvme_rdma_map_data()
1547 if (req->use_sig_mr) { in nvme_rdma_map_data()
1552 if (count <= dev->num_inline_segments) { in nvme_rdma_map_data()
1554 queue->ctrl->use_inline_data && in nvme_rdma_map_data()
1561 if (count == 1 && dev->pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY) { in nvme_rdma_map_data()
1579 static void nvme_rdma_send_done(struct ib_cq *cq, struct ib_wc *wc) in nvme_rdma_send_done() argument
1582 container_of(wc->wr_cqe, struct nvme_rdma_qe, cqe); in nvme_rdma_send_done()
1586 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_send_done()
1587 nvme_rdma_wr_error(cq, wc, "SEND"); in nvme_rdma_send_done()
1599 sge->addr = qe->dma; in nvme_rdma_post_send()
1600 sge->length = sizeof(struct nvme_command); in nvme_rdma_post_send()
1601 sge->lkey = queue->device->pd->local_dma_lkey; in nvme_rdma_post_send()
1604 wr.wr_cqe = &qe->cqe; in nvme_rdma_post_send()
1611 first->next = &wr; in nvme_rdma_post_send()
1615 ret = ib_post_send(queue->qp, first, NULL); in nvme_rdma_post_send()
1617 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_post_send()
1630 list.addr = qe->dma; in nvme_rdma_post_recv()
1632 list.lkey = queue->device->pd->local_dma_lkey; in nvme_rdma_post_recv()
1634 qe->cqe.done = nvme_rdma_recv_done; in nvme_rdma_post_recv()
1637 wr.wr_cqe = &qe->cqe; in nvme_rdma_post_recv()
1641 ret = ib_post_recv(queue->qp, &wr, NULL); in nvme_rdma_post_recv()
1643 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_post_recv()
1654 return queue->ctrl->admin_tag_set.tags[queue_idx]; in nvme_rdma_tagset()
1655 return queue->ctrl->tag_set.tags[queue_idx - 1]; in nvme_rdma_tagset()
1658 static void nvme_rdma_async_done(struct ib_cq *cq, struct ib_wc *wc) in nvme_rdma_async_done() argument
1660 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_async_done()
1661 nvme_rdma_wr_error(cq, wc, "ASYNC"); in nvme_rdma_async_done()
1667 struct nvme_rdma_queue *queue = &ctrl->queues[0]; in nvme_rdma_submit_async_event()
1668 struct ib_device *dev = queue->device->dev; in nvme_rdma_submit_async_event()
1669 struct nvme_rdma_qe *sqe = &ctrl->async_event_sqe; in nvme_rdma_submit_async_event()
1670 struct nvme_command *cmd = sqe->data; in nvme_rdma_submit_async_event()
1674 ib_dma_sync_single_for_cpu(dev, sqe->dma, sizeof(*cmd), DMA_TO_DEVICE); in nvme_rdma_submit_async_event()
1677 cmd->common.opcode = nvme_admin_async_event; in nvme_rdma_submit_async_event()
1678 cmd->common.command_id = NVME_AQ_BLK_MQ_DEPTH; in nvme_rdma_submit_async_event()
1679 cmd->common.flags |= NVME_CMD_SGL_METABUF; in nvme_rdma_submit_async_event()
1682 sqe->cqe.done = nvme_rdma_async_done; in nvme_rdma_submit_async_event()
1684 ib_dma_sync_single_for_device(dev, sqe->dma, sizeof(*cmd), in nvme_rdma_submit_async_event()
1692 struct nvme_completion *cqe, struct ib_wc *wc) in nvme_rdma_process_nvme_rsp() argument
1697 rq = nvme_find_rq(nvme_rdma_tagset(queue), cqe->command_id); in nvme_rdma_process_nvme_rsp()
1699 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_process_nvme_rsp()
1701 cqe->command_id, queue->qp->qp_num); in nvme_rdma_process_nvme_rsp()
1702 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_process_nvme_rsp()
1707 req->status = cqe->status; in nvme_rdma_process_nvme_rsp()
1708 req->result = cqe->result; in nvme_rdma_process_nvme_rsp()
1710 if (wc->wc_flags & IB_WC_WITH_INVALIDATE) { in nvme_rdma_process_nvme_rsp()
1711 if (unlikely(!req->mr || in nvme_rdma_process_nvme_rsp()
1712 wc->ex.invalidate_rkey != req->mr->rkey)) { in nvme_rdma_process_nvme_rsp()
1713 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_process_nvme_rsp()
1715 req->mr ? req->mr->rkey : 0); in nvme_rdma_process_nvme_rsp()
1716 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_process_nvme_rsp()
1718 } else if (req->mr) { in nvme_rdma_process_nvme_rsp()
1723 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_process_nvme_rsp()
1725 req->mr->rkey, ret); in nvme_rdma_process_nvme_rsp()
1726 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_process_nvme_rsp()
1735 static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc) in nvme_rdma_recv_done() argument
1738 container_of(wc->wr_cqe, struct nvme_rdma_qe, cqe); in nvme_rdma_recv_done()
1739 struct nvme_rdma_queue *queue = wc->qp->qp_context; in nvme_rdma_recv_done()
1740 struct ib_device *ibdev = queue->device->dev; in nvme_rdma_recv_done()
1741 struct nvme_completion *cqe = qe->data; in nvme_rdma_recv_done()
1744 if (unlikely(wc->status != IB_WC_SUCCESS)) { in nvme_rdma_recv_done()
1745 nvme_rdma_wr_error(cq, wc, "RECV"); in nvme_rdma_recv_done()
1750 if (unlikely(wc->byte_len < len)) { in nvme_rdma_recv_done()
1751 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_recv_done()
1752 "Unexpected nvme completion length(%d)\n", wc->byte_len); in nvme_rdma_recv_done()
1753 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_recv_done()
1757 ib_dma_sync_single_for_cpu(ibdev, qe->dma, len, DMA_FROM_DEVICE); in nvme_rdma_recv_done()
1765 cqe->command_id))) in nvme_rdma_recv_done()
1766 nvme_complete_async_event(&queue->ctrl->ctrl, cqe->status, in nvme_rdma_recv_done()
1767 &cqe->result); in nvme_rdma_recv_done()
1769 nvme_rdma_process_nvme_rsp(queue, cqe, wc); in nvme_rdma_recv_done()
1770 ib_dma_sync_single_for_device(ibdev, qe->dma, len, DMA_FROM_DEVICE); in nvme_rdma_recv_done()
1779 for (i = 0; i < queue->queue_size; i++) { in nvme_rdma_conn_established()
1780 ret = nvme_rdma_post_recv(queue, &queue->rsp_ring[i]); in nvme_rdma_conn_established()
1791 struct rdma_cm_id *cm_id = queue->cm_id; in nvme_rdma_conn_rejected()
1792 int status = ev->status; in nvme_rdma_conn_rejected()
1801 u16 sts = le16_to_cpu(rej_data->sts); in nvme_rdma_conn_rejected()
1803 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_conn_rejected()
1807 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_conn_rejected()
1811 return -ECONNRESET; in nvme_rdma_conn_rejected()
1816 struct nvme_ctrl *ctrl = &queue->ctrl->ctrl; in nvme_rdma_addr_resolved()
1823 if (ctrl->opts->tos >= 0) in nvme_rdma_addr_resolved()
1824 rdma_set_service_type(queue->cm_id, ctrl->opts->tos); in nvme_rdma_addr_resolved()
1825 ret = rdma_resolve_route(queue->cm_id, NVME_RDMA_CM_TIMEOUT_MS); in nvme_rdma_addr_resolved()
1827 dev_err(ctrl->device, "rdma_resolve_route failed (%d).\n", in nvme_rdma_addr_resolved()
1828 queue->cm_error); in nvme_rdma_addr_resolved()
1841 struct nvme_rdma_ctrl *ctrl = queue->ctrl; in nvme_rdma_route_resolved()
1846 param.qp_num = queue->qp->qp_num; in nvme_rdma_route_resolved()
1849 param.responder_resources = queue->device->dev->attrs.max_qp_rd_atom; in nvme_rdma_route_resolved()
1864 priv.hsqsize = cpu_to_le16(NVME_AQ_DEPTH - 1); in nvme_rdma_route_resolved()
1871 priv.hrqsize = cpu_to_le16(queue->queue_size); in nvme_rdma_route_resolved()
1872 priv.hsqsize = cpu_to_le16(queue->ctrl->ctrl.sqsize); in nvme_rdma_route_resolved()
1874 priv.cntlid = cpu_to_le16(ctrl->ctrl.cntlid); in nvme_rdma_route_resolved()
1877 ret = rdma_connect_locked(queue->cm_id, &param); in nvme_rdma_route_resolved()
1879 dev_err(ctrl->ctrl.device, in nvme_rdma_route_resolved()
1890 struct nvme_rdma_queue *queue = cm_id->context; in nvme_rdma_cm_handler()
1893 dev_dbg(queue->ctrl->ctrl.device, "%s (%d): status %d id %p\n", in nvme_rdma_cm_handler()
1894 rdma_event_msg(ev->event), ev->event, in nvme_rdma_cm_handler()
1895 ev->status, cm_id); in nvme_rdma_cm_handler()
1897 switch (ev->event) { in nvme_rdma_cm_handler()
1905 queue->cm_error = nvme_rdma_conn_established(queue); in nvme_rdma_cm_handler()
1907 complete(&queue->cm_done); in nvme_rdma_cm_handler()
1916 dev_dbg(queue->ctrl->ctrl.device, in nvme_rdma_cm_handler()
1917 "CM error event %d\n", ev->event); in nvme_rdma_cm_handler()
1918 cm_error = -ECONNRESET; in nvme_rdma_cm_handler()
1923 dev_dbg(queue->ctrl->ctrl.device, in nvme_rdma_cm_handler()
1924 "disconnect received - connection closed\n"); in nvme_rdma_cm_handler()
1925 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_cm_handler()
1931 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_cm_handler()
1932 "Unexpected RDMA CM event (%d)\n", ev->event); in nvme_rdma_cm_handler()
1933 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_cm_handler()
1938 queue->cm_error = cm_error; in nvme_rdma_cm_handler()
1939 complete(&queue->cm_done); in nvme_rdma_cm_handler()
1948 struct nvme_rdma_queue *queue = req->queue; in nvme_rdma_complete_timed_out()
1957 struct nvme_rdma_queue *queue = req->queue; in nvme_rdma_timeout()
1958 struct nvme_rdma_ctrl *ctrl = queue->ctrl; in nvme_rdma_timeout()
1959 struct nvme_command *cmd = req->req.cmd; in nvme_rdma_timeout()
1962 dev_warn(ctrl->ctrl.device, in nvme_rdma_timeout()
1964 rq->tag, nvme_cid(rq), cmd->common.opcode, in nvme_rdma_timeout()
1967 if (nvme_ctrl_state(&ctrl->ctrl) != NVME_CTRL_LIVE) { in nvme_rdma_timeout()
1972 * - ctrl disable/shutdown fabrics requests in nvme_rdma_timeout()
1973 * - connect requests in nvme_rdma_timeout()
1974 * - initialization admin requests in nvme_rdma_timeout()
1975 * - I/O requests that entered after unquiescing and in nvme_rdma_timeout()
1996 struct nvme_ns *ns = hctx->queue->queuedata; in nvme_rdma_queue_rq()
1997 struct nvme_rdma_queue *queue = hctx->driver_data; in nvme_rdma_queue_rq()
1998 struct request *rq = bd->rq; in nvme_rdma_queue_rq()
2000 struct nvme_rdma_qe *sqe = &req->sqe; in nvme_rdma_queue_rq()
2001 struct nvme_command *c = nvme_req(rq)->cmd; in nvme_rdma_queue_rq()
2003 bool queue_ready = test_bit(NVME_RDMA_Q_LIVE, &queue->flags); in nvme_rdma_queue_rq()
2007 WARN_ON_ONCE(rq->tag < 0); in nvme_rdma_queue_rq()
2009 if (!nvme_check_ready(&queue->ctrl->ctrl, rq, queue_ready)) in nvme_rdma_queue_rq()
2010 return nvme_fail_nonready_command(&queue->ctrl->ctrl, rq); in nvme_rdma_queue_rq()
2012 dev = queue->device->dev; in nvme_rdma_queue_rq()
2014 req->sqe.dma = ib_dma_map_single(dev, req->sqe.data, in nvme_rdma_queue_rq()
2017 err = ib_dma_mapping_error(dev, req->sqe.dma); in nvme_rdma_queue_rq()
2021 ib_dma_sync_single_for_cpu(dev, sqe->dma, in nvme_rdma_queue_rq()
2031 queue->pi_support && in nvme_rdma_queue_rq()
2032 (c->common.opcode == nvme_cmd_write || in nvme_rdma_queue_rq()
2033 c->common.opcode == nvme_cmd_read) && in nvme_rdma_queue_rq()
2034 nvme_ns_has_pi(ns->head)) in nvme_rdma_queue_rq()
2035 req->use_sig_mr = true; in nvme_rdma_queue_rq()
2037 req->use_sig_mr = false; in nvme_rdma_queue_rq()
2041 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_queue_rq()
2046 sqe->cqe.done = nvme_rdma_send_done; in nvme_rdma_queue_rq()
2048 ib_dma_sync_single_for_device(dev, sqe->dma, in nvme_rdma_queue_rq()
2051 err = nvme_rdma_post_send(queue, sqe, req->sge, req->num_sge, in nvme_rdma_queue_rq()
2052 req->mr ? &req->reg_wr.wr : NULL); in nvme_rdma_queue_rq()
2061 if (err == -EIO) in nvme_rdma_queue_rq()
2063 else if (err == -ENOMEM || err == -EAGAIN) in nvme_rdma_queue_rq()
2069 ib_dma_unmap_single(dev, req->sqe.dma, sizeof(struct nvme_command), in nvme_rdma_queue_rq()
2076 struct nvme_rdma_queue *queue = hctx->driver_data; in nvme_rdma_poll()
2078 return ib_process_cq_direct(queue->ib_cq, -1); in nvme_rdma_poll()
2087 ret = ib_check_mr_status(req->mr, IB_MR_CHECK_SIG_STATUS, &mr_status); in nvme_rdma_check_pi_status()
2090 nvme_req(rq)->status = NVME_SC_INVALID_PI; in nvme_rdma_check_pi_status()
2097 nvme_req(rq)->status = NVME_SC_GUARD_CHECK; in nvme_rdma_check_pi_status()
2100 nvme_req(rq)->status = NVME_SC_REFTAG_CHECK; in nvme_rdma_check_pi_status()
2103 nvme_req(rq)->status = NVME_SC_APPTAG_CHECK; in nvme_rdma_check_pi_status()
2115 struct nvme_rdma_queue *queue = req->queue; in nvme_rdma_complete_rq()
2116 struct ib_device *ibdev = queue->device->dev; in nvme_rdma_complete_rq()
2118 if (req->use_sig_mr) in nvme_rdma_complete_rq()
2122 ib_dma_unmap_single(ibdev, req->sqe.dma, sizeof(struct nvme_command), in nvme_rdma_complete_rq()
2129 struct nvme_rdma_ctrl *ctrl = to_rdma_ctrl(set->driver_data); in nvme_rdma_map_queues()
2131 nvmf_map_queues(set, &ctrl->ctrl, ctrl->io_queues); in nvme_rdma_map_queues()
2157 nvme_quiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_shutdown_ctrl()
2158 nvme_disable_ctrl(&ctrl->ctrl, shutdown); in nvme_rdma_shutdown_ctrl()
2173 nvme_stop_ctrl(&ctrl->ctrl); in nvme_rdma_reset_ctrl_work()
2176 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { in nvme_rdma_reset_ctrl_work()
2189 ++ctrl->ctrl.nr_reconnects; in nvme_rdma_reset_ctrl_work()
2214 * existing controller with all the other parameters the same and no
2228 found = nvmf_ip_options_match(&ctrl->ctrl, opts); in nvme_rdma_existing_controller()
2245 return ERR_PTR(-ENOMEM); in nvme_rdma_alloc_ctrl()
2246 ctrl->ctrl.opts = opts; in nvme_rdma_alloc_ctrl()
2247 INIT_LIST_HEAD(&ctrl->list); in nvme_rdma_alloc_ctrl()
2249 if (!(opts->mask & NVMF_OPT_TRSVCID)) { in nvme_rdma_alloc_ctrl()
2250 opts->trsvcid = in nvme_rdma_alloc_ctrl()
2252 if (!opts->trsvcid) { in nvme_rdma_alloc_ctrl()
2253 ret = -ENOMEM; in nvme_rdma_alloc_ctrl()
2256 opts->mask |= NVMF_OPT_TRSVCID; in nvme_rdma_alloc_ctrl()
2260 opts->traddr, opts->trsvcid, &ctrl->addr); in nvme_rdma_alloc_ctrl()
2263 opts->traddr, opts->trsvcid); in nvme_rdma_alloc_ctrl()
2267 if (opts->mask & NVMF_OPT_HOST_TRADDR) { in nvme_rdma_alloc_ctrl()
2269 opts->host_traddr, NULL, &ctrl->src_addr); in nvme_rdma_alloc_ctrl()
2272 opts->host_traddr); in nvme_rdma_alloc_ctrl()
2277 if (!opts->duplicate_connect && nvme_rdma_existing_controller(opts)) { in nvme_rdma_alloc_ctrl()
2278 ret = -EALREADY; in nvme_rdma_alloc_ctrl()
2282 INIT_DELAYED_WORK(&ctrl->reconnect_work, in nvme_rdma_alloc_ctrl()
2284 INIT_WORK(&ctrl->err_work, nvme_rdma_error_recovery_work); in nvme_rdma_alloc_ctrl()
2285 INIT_WORK(&ctrl->ctrl.reset_work, nvme_rdma_reset_ctrl_work); in nvme_rdma_alloc_ctrl()
2287 ctrl->ctrl.queue_count = opts->nr_io_queues + opts->nr_write_queues + in nvme_rdma_alloc_ctrl()
2288 opts->nr_poll_queues + 1; in nvme_rdma_alloc_ctrl()
2289 ctrl->ctrl.sqsize = opts->queue_size - 1; in nvme_rdma_alloc_ctrl()
2290 ctrl->ctrl.kato = opts->kato; in nvme_rdma_alloc_ctrl()
2292 ret = -ENOMEM; in nvme_rdma_alloc_ctrl()
2293 ctrl->queues = kcalloc(ctrl->ctrl.queue_count, sizeof(*ctrl->queues), in nvme_rdma_alloc_ctrl()
2295 if (!ctrl->queues) in nvme_rdma_alloc_ctrl()
2298 ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, in nvme_rdma_alloc_ctrl()
2299 0 /* no quirks, we're perfect! */); in nvme_rdma_alloc_ctrl()
2306 kfree(ctrl->queues); in nvme_rdma_alloc_ctrl()
2323 ret = nvme_add_ctrl(&ctrl->ctrl); in nvme_rdma_create_ctrl()
2327 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING); in nvme_rdma_create_ctrl()
2334 dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISpcs, hostnqn: %s\n", in nvme_rdma_create_ctrl()
2335 nvmf_ctrl_subsysnqn(&ctrl->ctrl), &ctrl->addr, opts->host->nqn); in nvme_rdma_create_ctrl()
2338 list_add_tail(&ctrl->list, &nvme_rdma_ctrl_list); in nvme_rdma_create_ctrl()
2341 return &ctrl->ctrl; in nvme_rdma_create_ctrl()
2344 nvme_uninit_ctrl(&ctrl->ctrl); in nvme_rdma_create_ctrl()
2346 nvme_put_ctrl(&ctrl->ctrl); in nvme_rdma_create_ctrl()
2348 ret = -EIO; in nvme_rdma_create_ctrl()
2371 if (ndev->dev == ib_device) { in nvme_rdma_remove_one()
2384 if (ctrl->device->dev != ib_device) in nvme_rdma_remove_one()
2386 nvme_delete_ctrl(&ctrl->ctrl); in nvme_rdma_remove_one()
2426 nvme_delete_ctrl(&ctrl->ctrl); in nvme_rdma_cleanup_module()