Lines Matching +full:wire +full:- +full:sized

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>
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()
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()
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()
534 "failed to initialize MR pool sized %d for QID %d\n", 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()
545 "failed to initialize PI MR pool sized %d for QID %d\n", 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 & (1 << 2))) { 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 & (1 << 20)) 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()
1094 nvme_quiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1095 blk_sync_queue(ctrl->ctrl.admin_q); in nvme_rdma_setup_ctrl()
1096 nvme_rdma_stop_queue(&ctrl->queues[0]); in nvme_rdma_setup_ctrl()
1097 nvme_cancel_admin_tagset(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1099 nvme_remove_admin_tag_set(&ctrl->ctrl); in nvme_rdma_setup_ctrl()
1110 ++ctrl->ctrl.nr_reconnects; in nvme_rdma_reconnect_ctrl_work()
1116 dev_info(ctrl->ctrl.device, "Successfully reconnected (%d attempts)\n", in nvme_rdma_reconnect_ctrl_work()
1117 ctrl->ctrl.nr_reconnects); in nvme_rdma_reconnect_ctrl_work()
1119 ctrl->ctrl.nr_reconnects = 0; in nvme_rdma_reconnect_ctrl_work()
1124 dev_info(ctrl->ctrl.device, "Failed reconnect attempt %d/%d\n", in nvme_rdma_reconnect_ctrl_work()
1125 ctrl->ctrl.nr_reconnects, ctrl->ctrl.opts->max_reconnects); in nvme_rdma_reconnect_ctrl_work()
1134 nvme_stop_keep_alive(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1135 flush_work(&ctrl->ctrl.async_event_work); in nvme_rdma_error_recovery_work()
1137 nvme_unquiesce_io_queues(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1139 nvme_unquiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1140 nvme_auth_stop(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1142 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { in nvme_rdma_error_recovery_work()
1144 enum nvme_ctrl_state state = nvme_ctrl_state(&ctrl->ctrl); in nvme_rdma_error_recovery_work()
1156 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_RESETTING)) in nvme_rdma_error_recovery()
1159 dev_warn(ctrl->ctrl.device, "starting error recovery\n"); in nvme_rdma_error_recovery()
1160 queue_work(nvme_reset_wq, &ctrl->err_work); in nvme_rdma_error_recovery()
1167 if (!refcount_dec_and_test(&req->ref)) in nvme_rdma_end_request()
1169 if (!nvme_try_complete_req(rq, req->status, req->result)) in nvme_rdma_end_request()
1176 struct nvme_rdma_queue *queue = wc->qp->qp_context; in nvme_rdma_wr_error()
1177 struct nvme_rdma_ctrl *ctrl = queue->ctrl; in nvme_rdma_wr_error()
1179 if (nvme_ctrl_state(&ctrl->ctrl) == NVME_CTRL_LIVE) in nvme_rdma_wr_error()
1180 dev_info(ctrl->ctrl.device, in nvme_rdma_wr_error()
1182 op, wc->wr_cqe, in nvme_rdma_wr_error()
1183 ib_wc_status_msg(wc->status), wc->status); in nvme_rdma_wr_error()
1189 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_memreg_done()
1196 container_of(wc->wr_cqe, struct nvme_rdma_request, reg_cqe); in nvme_rdma_inv_rkey_done()
1198 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_inv_rkey_done()
1212 .ex.invalidate_rkey = req->mr->rkey, in nvme_rdma_inv_rkey()
1215 req->reg_cqe.done = nvme_rdma_inv_rkey_done; in nvme_rdma_inv_rkey()
1216 wr.wr_cqe = &req->reg_cqe; in nvme_rdma_inv_rkey()
1218 return ib_post_send(queue->qp, &wr, NULL); in nvme_rdma_inv_rkey()
1226 ib_dma_unmap_sg(ibdev, req->metadata_sgl->sg_table.sgl, in nvme_rdma_dma_unmap_req()
1227 req->metadata_sgl->nents, rq_dma_dir(rq)); in nvme_rdma_dma_unmap_req()
1228 sg_free_table_chained(&req->metadata_sgl->sg_table, in nvme_rdma_dma_unmap_req()
1232 ib_dma_unmap_sg(ibdev, req->data_sgl.sg_table.sgl, req->data_sgl.nents, in nvme_rdma_dma_unmap_req()
1234 sg_free_table_chained(&req->data_sgl.sg_table, NVME_INLINE_SG_CNT); in nvme_rdma_dma_unmap_req()
1241 struct nvme_rdma_device *dev = queue->device; in nvme_rdma_unmap_data()
1242 struct ib_device *ibdev = dev->dev; in nvme_rdma_unmap_data()
1243 struct list_head *pool = &queue->qp->rdma_mrs; in nvme_rdma_unmap_data()
1248 if (req->use_sig_mr) in nvme_rdma_unmap_data()
1249 pool = &queue->qp->sig_mrs; in nvme_rdma_unmap_data()
1251 if (req->mr) { in nvme_rdma_unmap_data()
1252 ib_mr_pool_put(queue->qp, pool, req->mr); in nvme_rdma_unmap_data()
1253 req->mr = NULL; in nvme_rdma_unmap_data()
1261 struct nvme_keyed_sgl_desc *sg = &c->common.dptr.ksgl; in nvme_rdma_set_sg_null()
1263 sg->addr = 0; in nvme_rdma_set_sg_null()
1264 put_unaligned_le24(0, sg->length); in nvme_rdma_set_sg_null()
1265 put_unaligned_le32(0, sg->key); in nvme_rdma_set_sg_null()
1266 sg->type = NVME_KEY_SGL_FMT_DATA_DESC << 4; in nvme_rdma_set_sg_null()
1274 struct nvme_sgl_desc *sg = &c->common.dptr.sgl; in nvme_rdma_map_sg_inline()
1275 struct ib_sge *sge = &req->sge[1]; in nvme_rdma_map_sg_inline()
1280 for_each_sg(req->data_sgl.sg_table.sgl, sgl, count, i) { in nvme_rdma_map_sg_inline()
1281 sge->addr = sg_dma_address(sgl); in nvme_rdma_map_sg_inline()
1282 sge->length = sg_dma_len(sgl); in nvme_rdma_map_sg_inline()
1283 sge->lkey = queue->device->pd->local_dma_lkey; in nvme_rdma_map_sg_inline()
1284 len += sge->length; in nvme_rdma_map_sg_inline()
1288 sg->addr = cpu_to_le64(queue->ctrl->ctrl.icdoff); in nvme_rdma_map_sg_inline()
1289 sg->length = cpu_to_le32(len); in nvme_rdma_map_sg_inline()
1290 sg->type = (NVME_SGL_FMT_DATA_DESC << 4) | NVME_SGL_FMT_OFFSET; in nvme_rdma_map_sg_inline()
1292 req->num_sge += count; in nvme_rdma_map_sg_inline()
1299 struct nvme_keyed_sgl_desc *sg = &c->common.dptr.ksgl; in nvme_rdma_map_sg_single()
1301 sg->addr = cpu_to_le64(sg_dma_address(req->data_sgl.sg_table.sgl)); in nvme_rdma_map_sg_single()
1302 put_unaligned_le24(sg_dma_len(req->data_sgl.sg_table.sgl), sg->length); in nvme_rdma_map_sg_single()
1303 put_unaligned_le32(queue->device->pd->unsafe_global_rkey, sg->key); in nvme_rdma_map_sg_single()
1304 sg->type = NVME_KEY_SGL_FMT_DATA_DESC << 4; in nvme_rdma_map_sg_single()
1312 struct nvme_keyed_sgl_desc *sg = &c->common.dptr.ksgl; in nvme_rdma_map_sg_fr()
1315 req->mr = ib_mr_pool_get(queue->qp, &queue->qp->rdma_mrs); in nvme_rdma_map_sg_fr()
1316 if (WARN_ON_ONCE(!req->mr)) in nvme_rdma_map_sg_fr()
1317 return -EAGAIN; in nvme_rdma_map_sg_fr()
1323 nr = ib_map_mr_sg(req->mr, req->data_sgl.sg_table.sgl, count, NULL, in nvme_rdma_map_sg_fr()
1326 ib_mr_pool_put(queue->qp, &queue->qp->rdma_mrs, req->mr); in nvme_rdma_map_sg_fr()
1327 req->mr = NULL; in nvme_rdma_map_sg_fr()
1330 return -EINVAL; in nvme_rdma_map_sg_fr()
1333 ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey)); in nvme_rdma_map_sg_fr()
1335 req->reg_cqe.done = nvme_rdma_memreg_done; in nvme_rdma_map_sg_fr()
1336 memset(&req->reg_wr, 0, sizeof(req->reg_wr)); in nvme_rdma_map_sg_fr()
1337 req->reg_wr.wr.opcode = IB_WR_REG_MR; in nvme_rdma_map_sg_fr()
1338 req->reg_wr.wr.wr_cqe = &req->reg_cqe; in nvme_rdma_map_sg_fr()
1339 req->reg_wr.wr.num_sge = 0; in nvme_rdma_map_sg_fr()
1340 req->reg_wr.mr = req->mr; in nvme_rdma_map_sg_fr()
1341 req->reg_wr.key = req->mr->rkey; in nvme_rdma_map_sg_fr()
1342 req->reg_wr.access = IB_ACCESS_LOCAL_WRITE | in nvme_rdma_map_sg_fr()
1346 sg->addr = cpu_to_le64(req->mr->iova); in nvme_rdma_map_sg_fr()
1347 put_unaligned_le24(req->mr->length, sg->length); in nvme_rdma_map_sg_fr()
1348 put_unaligned_le32(req->mr->rkey, sg->key); in nvme_rdma_map_sg_fr()
1349 sg->type = (NVME_KEY_SGL_FMT_DATA_DESC << 4) | in nvme_rdma_map_sg_fr()
1359 domain->sig_type = IB_SIG_TYPE_T10_DIF; in nvme_rdma_set_sig_domain()
1360 domain->sig.dif.bg_type = IB_T10DIF_CRC; in nvme_rdma_set_sig_domain()
1361 domain->sig.dif.pi_interval = 1 << bi->interval_exp; in nvme_rdma_set_sig_domain()
1362 domain->sig.dif.ref_tag = le32_to_cpu(cmd->rw.reftag); in nvme_rdma_set_sig_domain()
1364 domain->sig.dif.ref_remap = true; in nvme_rdma_set_sig_domain()
1366 domain->sig.dif.app_tag = le16_to_cpu(cmd->rw.lbat); in nvme_rdma_set_sig_domain()
1367 domain->sig.dif.apptag_check_mask = le16_to_cpu(cmd->rw.lbatm); in nvme_rdma_set_sig_domain()
1368 domain->sig.dif.app_escape = true; in nvme_rdma_set_sig_domain()
1370 domain->sig.dif.ref_escape = true; in nvme_rdma_set_sig_domain()
1377 u16 control = le16_to_cpu(cmd->rw.control); in nvme_rdma_set_sig_attrs()
1382 sig_attrs->mem.sig_type = IB_SIG_TYPE_NONE; in nvme_rdma_set_sig_attrs()
1383 nvme_rdma_set_sig_domain(bi, cmd, &sig_attrs->wire, control, in nvme_rdma_set_sig_attrs()
1387 cmd->rw.control = cpu_to_le16(control); in nvme_rdma_set_sig_attrs()
1389 /* for WRITE_PASS/READ_PASS both wire/memory domains exist */ in nvme_rdma_set_sig_attrs()
1390 nvme_rdma_set_sig_domain(bi, cmd, &sig_attrs->wire, control, in nvme_rdma_set_sig_attrs()
1392 nvme_rdma_set_sig_domain(bi, cmd, &sig_attrs->mem, control, in nvme_rdma_set_sig_attrs()
1400 if (le16_to_cpu(cmd->rw.control) & NVME_RW_PRINFO_PRCHK_REF) in nvme_rdma_set_prot_checks()
1402 if (le16_to_cpu(cmd->rw.control) & NVME_RW_PRINFO_PRCHK_GUARD) in nvme_rdma_set_prot_checks()
1408 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_sig_done()
1416 struct nvme_rdma_sgl *sgl = &req->data_sgl; in nvme_rdma_map_sg_pi()
1417 struct ib_reg_wr *wr = &req->reg_wr; in nvme_rdma_map_sg_pi()
1419 struct nvme_ns *ns = rq->q->queuedata; in nvme_rdma_map_sg_pi()
1420 struct bio *bio = rq->bio; in nvme_rdma_map_sg_pi()
1421 struct nvme_keyed_sgl_desc *sg = &c->common.dptr.ksgl; in nvme_rdma_map_sg_pi()
1422 struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); in nvme_rdma_map_sg_pi()
1426 req->mr = ib_mr_pool_get(queue->qp, &queue->qp->sig_mrs); in nvme_rdma_map_sg_pi()
1427 if (WARN_ON_ONCE(!req->mr)) in nvme_rdma_map_sg_pi()
1428 return -EAGAIN; in nvme_rdma_map_sg_pi()
1430 nr = ib_map_mr_sg_pi(req->mr, sgl->sg_table.sgl, count, NULL, in nvme_rdma_map_sg_pi()
1431 req->metadata_sgl->sg_table.sgl, pi_count, NULL, in nvme_rdma_map_sg_pi()
1436 nvme_rdma_set_sig_attrs(bi, c, req->mr->sig_attrs, ns->head->pi_type); in nvme_rdma_map_sg_pi()
1437 nvme_rdma_set_prot_checks(c, &req->mr->sig_attrs->check_mask); in nvme_rdma_map_sg_pi()
1439 ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey)); in nvme_rdma_map_sg_pi()
1441 req->reg_cqe.done = nvme_rdma_sig_done; in nvme_rdma_map_sg_pi()
1443 wr->wr.opcode = IB_WR_REG_MR_INTEGRITY; in nvme_rdma_map_sg_pi()
1444 wr->wr.wr_cqe = &req->reg_cqe; in nvme_rdma_map_sg_pi()
1445 wr->wr.num_sge = 0; in nvme_rdma_map_sg_pi()
1446 wr->wr.send_flags = 0; in nvme_rdma_map_sg_pi()
1447 wr->mr = req->mr; in nvme_rdma_map_sg_pi()
1448 wr->key = req->mr->rkey; in nvme_rdma_map_sg_pi()
1449 wr->access = IB_ACCESS_LOCAL_WRITE | in nvme_rdma_map_sg_pi()
1453 sg->addr = cpu_to_le64(req->mr->iova); in nvme_rdma_map_sg_pi()
1454 xfer_len = req->mr->length; in nvme_rdma_map_sg_pi()
1457 xfer_len += (xfer_len >> bi->interval_exp) * ns->head->pi_size; in nvme_rdma_map_sg_pi()
1458 put_unaligned_le24(xfer_len, sg->length); in nvme_rdma_map_sg_pi()
1459 put_unaligned_le32(req->mr->rkey, sg->key); in nvme_rdma_map_sg_pi()
1460 sg->type = NVME_KEY_SGL_FMT_DATA_DESC << 4; in nvme_rdma_map_sg_pi()
1465 ib_mr_pool_put(queue->qp, &queue->qp->sig_mrs, req->mr); in nvme_rdma_map_sg_pi()
1466 req->mr = NULL; in nvme_rdma_map_sg_pi()
1469 return -EINVAL; in nvme_rdma_map_sg_pi()
1478 req->data_sgl.sg_table.sgl = (struct scatterlist *)(req + 1); in nvme_rdma_dma_map_req()
1479 ret = sg_alloc_table_chained(&req->data_sgl.sg_table, in nvme_rdma_dma_map_req()
1480 blk_rq_nr_phys_segments(rq), req->data_sgl.sg_table.sgl, in nvme_rdma_dma_map_req()
1483 return -ENOMEM; in nvme_rdma_dma_map_req()
1485 req->data_sgl.nents = blk_rq_map_sg(rq->q, rq, in nvme_rdma_dma_map_req()
1486 req->data_sgl.sg_table.sgl); in nvme_rdma_dma_map_req()
1488 *count = ib_dma_map_sg(ibdev, req->data_sgl.sg_table.sgl, in nvme_rdma_dma_map_req()
1489 req->data_sgl.nents, rq_dma_dir(rq)); in nvme_rdma_dma_map_req()
1491 ret = -EIO; in nvme_rdma_dma_map_req()
1496 req->metadata_sgl->sg_table.sgl = in nvme_rdma_dma_map_req()
1497 (struct scatterlist *)(req->metadata_sgl + 1); in nvme_rdma_dma_map_req()
1498 ret = sg_alloc_table_chained(&req->metadata_sgl->sg_table, in nvme_rdma_dma_map_req()
1499 rq->nr_integrity_segments, in nvme_rdma_dma_map_req()
1500 req->metadata_sgl->sg_table.sgl, in nvme_rdma_dma_map_req()
1503 ret = -ENOMEM; in nvme_rdma_dma_map_req()
1507 req->metadata_sgl->nents = blk_rq_map_integrity_sg(rq, in nvme_rdma_dma_map_req()
1508 req->metadata_sgl->sg_table.sgl); in nvme_rdma_dma_map_req()
1510 req->metadata_sgl->sg_table.sgl, in nvme_rdma_dma_map_req()
1511 req->metadata_sgl->nents, in nvme_rdma_dma_map_req()
1514 ret = -EIO; in nvme_rdma_dma_map_req()
1522 sg_free_table_chained(&req->metadata_sgl->sg_table, in nvme_rdma_dma_map_req()
1525 ib_dma_unmap_sg(ibdev, req->data_sgl.sg_table.sgl, req->data_sgl.nents, in nvme_rdma_dma_map_req()
1528 sg_free_table_chained(&req->data_sgl.sg_table, NVME_INLINE_SG_CNT); in nvme_rdma_dma_map_req()
1536 struct nvme_rdma_device *dev = queue->device; in nvme_rdma_map_data()
1537 struct ib_device *ibdev = dev->dev; in nvme_rdma_map_data()
1541 req->num_sge = 1; in nvme_rdma_map_data()
1542 refcount_set(&req->ref, 2); /* send and recv completions */ in nvme_rdma_map_data()
1544 c->common.flags |= NVME_CMD_SGL_METABUF; in nvme_rdma_map_data()
1553 if (req->use_sig_mr) { in nvme_rdma_map_data()
1558 if (count <= dev->num_inline_segments) { in nvme_rdma_map_data()
1560 queue->ctrl->use_inline_data && in nvme_rdma_map_data()
1567 if (count == 1 && dev->pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY) { in nvme_rdma_map_data()
1588 container_of(wc->wr_cqe, struct nvme_rdma_qe, cqe); in nvme_rdma_send_done()
1592 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_send_done()
1605 sge->addr = qe->dma; in nvme_rdma_post_send()
1606 sge->length = sizeof(struct nvme_command); in nvme_rdma_post_send()
1607 sge->lkey = queue->device->pd->local_dma_lkey; in nvme_rdma_post_send()
1610 wr.wr_cqe = &qe->cqe; in nvme_rdma_post_send()
1617 first->next = &wr; in nvme_rdma_post_send()
1621 ret = ib_post_send(queue->qp, first, NULL); in nvme_rdma_post_send()
1623 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_post_send()
1636 list.addr = qe->dma; in nvme_rdma_post_recv()
1638 list.lkey = queue->device->pd->local_dma_lkey; in nvme_rdma_post_recv()
1640 qe->cqe.done = nvme_rdma_recv_done; in nvme_rdma_post_recv()
1643 wr.wr_cqe = &qe->cqe; in nvme_rdma_post_recv()
1647 ret = ib_post_recv(queue->qp, &wr, NULL); in nvme_rdma_post_recv()
1649 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_post_recv()
1660 return queue->ctrl->admin_tag_set.tags[queue_idx]; in nvme_rdma_tagset()
1661 return queue->ctrl->tag_set.tags[queue_idx - 1]; in nvme_rdma_tagset()
1666 if (unlikely(wc->status != IB_WC_SUCCESS)) in nvme_rdma_async_done()
1673 struct nvme_rdma_queue *queue = &ctrl->queues[0]; in nvme_rdma_submit_async_event()
1674 struct ib_device *dev = queue->device->dev; in nvme_rdma_submit_async_event()
1675 struct nvme_rdma_qe *sqe = &ctrl->async_event_sqe; in nvme_rdma_submit_async_event()
1676 struct nvme_command *cmd = sqe->data; in nvme_rdma_submit_async_event()
1680 ib_dma_sync_single_for_cpu(dev, sqe->dma, sizeof(*cmd), DMA_TO_DEVICE); in nvme_rdma_submit_async_event()
1683 cmd->common.opcode = nvme_admin_async_event; in nvme_rdma_submit_async_event()
1684 cmd->common.command_id = NVME_AQ_BLK_MQ_DEPTH; in nvme_rdma_submit_async_event()
1685 cmd->common.flags |= NVME_CMD_SGL_METABUF; in nvme_rdma_submit_async_event()
1688 sqe->cqe.done = nvme_rdma_async_done; in nvme_rdma_submit_async_event()
1690 ib_dma_sync_single_for_device(dev, sqe->dma, sizeof(*cmd), in nvme_rdma_submit_async_event()
1703 rq = nvme_find_rq(nvme_rdma_tagset(queue), cqe->command_id); in nvme_rdma_process_nvme_rsp()
1705 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_process_nvme_rsp()
1707 cqe->command_id, queue->qp->qp_num); in nvme_rdma_process_nvme_rsp()
1708 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_process_nvme_rsp()
1713 req->status = cqe->status; in nvme_rdma_process_nvme_rsp()
1714 req->result = cqe->result; in nvme_rdma_process_nvme_rsp()
1716 if (wc->wc_flags & IB_WC_WITH_INVALIDATE) { in nvme_rdma_process_nvme_rsp()
1717 if (unlikely(!req->mr || in nvme_rdma_process_nvme_rsp()
1718 wc->ex.invalidate_rkey != req->mr->rkey)) { in nvme_rdma_process_nvme_rsp()
1719 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_process_nvme_rsp()
1721 req->mr ? req->mr->rkey : 0); in nvme_rdma_process_nvme_rsp()
1722 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_process_nvme_rsp()
1724 } else if (req->mr) { in nvme_rdma_process_nvme_rsp()
1729 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_process_nvme_rsp()
1731 req->mr->rkey, ret); in nvme_rdma_process_nvme_rsp()
1732 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_process_nvme_rsp()
1744 container_of(wc->wr_cqe, struct nvme_rdma_qe, cqe); in nvme_rdma_recv_done()
1745 struct nvme_rdma_queue *queue = wc->qp->qp_context; in nvme_rdma_recv_done()
1746 struct ib_device *ibdev = queue->device->dev; in nvme_rdma_recv_done()
1747 struct nvme_completion *cqe = qe->data; in nvme_rdma_recv_done()
1750 if (unlikely(wc->status != IB_WC_SUCCESS)) { in nvme_rdma_recv_done()
1756 if (unlikely(wc->byte_len < len)) { in nvme_rdma_recv_done()
1757 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_recv_done()
1758 "Unexpected nvme completion length(%d)\n", wc->byte_len); in nvme_rdma_recv_done()
1759 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_recv_done()
1763 ib_dma_sync_single_for_cpu(ibdev, qe->dma, len, DMA_FROM_DEVICE); in nvme_rdma_recv_done()
1771 cqe->command_id))) in nvme_rdma_recv_done()
1772 nvme_complete_async_event(&queue->ctrl->ctrl, cqe->status, in nvme_rdma_recv_done()
1773 &cqe->result); in nvme_rdma_recv_done()
1776 ib_dma_sync_single_for_device(ibdev, qe->dma, len, DMA_FROM_DEVICE); in nvme_rdma_recv_done()
1785 for (i = 0; i < queue->queue_size; i++) { in nvme_rdma_conn_established()
1786 ret = nvme_rdma_post_recv(queue, &queue->rsp_ring[i]); in nvme_rdma_conn_established()
1797 struct rdma_cm_id *cm_id = queue->cm_id; in nvme_rdma_conn_rejected()
1798 int status = ev->status; in nvme_rdma_conn_rejected()
1807 u16 sts = le16_to_cpu(rej_data->sts); in nvme_rdma_conn_rejected()
1809 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_conn_rejected()
1813 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_conn_rejected()
1817 return -ECONNRESET; in nvme_rdma_conn_rejected()
1822 struct nvme_ctrl *ctrl = &queue->ctrl->ctrl; in nvme_rdma_addr_resolved()
1829 if (ctrl->opts->tos >= 0) in nvme_rdma_addr_resolved()
1830 rdma_set_service_type(queue->cm_id, ctrl->opts->tos); in nvme_rdma_addr_resolved()
1831 ret = rdma_resolve_route(queue->cm_id, NVME_RDMA_CM_TIMEOUT_MS); in nvme_rdma_addr_resolved()
1833 dev_err(ctrl->device, "rdma_resolve_route failed (%d).\n", in nvme_rdma_addr_resolved()
1834 queue->cm_error); in nvme_rdma_addr_resolved()
1847 struct nvme_rdma_ctrl *ctrl = queue->ctrl; in nvme_rdma_route_resolved()
1852 param.qp_num = queue->qp->qp_num; in nvme_rdma_route_resolved()
1855 param.responder_resources = queue->device->dev->attrs.max_qp_rd_atom; in nvme_rdma_route_resolved()
1870 priv.hsqsize = cpu_to_le16(NVME_AQ_DEPTH - 1); in nvme_rdma_route_resolved()
1877 priv.hrqsize = cpu_to_le16(queue->queue_size); in nvme_rdma_route_resolved()
1878 priv.hsqsize = cpu_to_le16(queue->ctrl->ctrl.sqsize); in nvme_rdma_route_resolved()
1880 priv.cntlid = cpu_to_le16(ctrl->ctrl.cntlid); in nvme_rdma_route_resolved()
1883 ret = rdma_connect_locked(queue->cm_id, &param); in nvme_rdma_route_resolved()
1885 dev_err(ctrl->ctrl.device, in nvme_rdma_route_resolved()
1896 struct nvme_rdma_queue *queue = cm_id->context; in nvme_rdma_cm_handler()
1899 dev_dbg(queue->ctrl->ctrl.device, "%s (%d): status %d id %p\n", in nvme_rdma_cm_handler()
1900 rdma_event_msg(ev->event), ev->event, in nvme_rdma_cm_handler()
1901 ev->status, cm_id); in nvme_rdma_cm_handler()
1903 switch (ev->event) { in nvme_rdma_cm_handler()
1911 queue->cm_error = nvme_rdma_conn_established(queue); in nvme_rdma_cm_handler()
1913 complete(&queue->cm_done); in nvme_rdma_cm_handler()
1922 dev_dbg(queue->ctrl->ctrl.device, in nvme_rdma_cm_handler()
1923 "CM error event %d\n", ev->event); in nvme_rdma_cm_handler()
1924 cm_error = -ECONNRESET; in nvme_rdma_cm_handler()
1929 dev_dbg(queue->ctrl->ctrl.device, in nvme_rdma_cm_handler()
1930 "disconnect received - connection closed\n"); in nvme_rdma_cm_handler()
1931 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_cm_handler()
1937 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_cm_handler()
1938 "Unexpected RDMA CM event (%d)\n", ev->event); in nvme_rdma_cm_handler()
1939 nvme_rdma_error_recovery(queue->ctrl); in nvme_rdma_cm_handler()
1944 queue->cm_error = cm_error; in nvme_rdma_cm_handler()
1945 complete(&queue->cm_done); in nvme_rdma_cm_handler()
1954 struct nvme_rdma_queue *queue = req->queue; in nvme_rdma_complete_timed_out()
1963 struct nvme_rdma_queue *queue = req->queue; in nvme_rdma_timeout()
1964 struct nvme_rdma_ctrl *ctrl = queue->ctrl; in nvme_rdma_timeout()
1965 struct nvme_command *cmd = req->req.cmd; in nvme_rdma_timeout()
1968 dev_warn(ctrl->ctrl.device, in nvme_rdma_timeout()
1970 rq->tag, nvme_cid(rq), cmd->common.opcode, in nvme_rdma_timeout()
1973 if (nvme_ctrl_state(&ctrl->ctrl) != NVME_CTRL_LIVE) { in nvme_rdma_timeout()
1978 * - ctrl disable/shutdown fabrics requests in nvme_rdma_timeout()
1979 * - connect requests in nvme_rdma_timeout()
1980 * - initialization admin requests in nvme_rdma_timeout()
1981 * - I/O requests that entered after unquiescing and in nvme_rdma_timeout()
2002 struct nvme_ns *ns = hctx->queue->queuedata; in nvme_rdma_queue_rq()
2003 struct nvme_rdma_queue *queue = hctx->driver_data; in nvme_rdma_queue_rq()
2004 struct request *rq = bd->rq; in nvme_rdma_queue_rq()
2006 struct nvme_rdma_qe *sqe = &req->sqe; in nvme_rdma_queue_rq()
2007 struct nvme_command *c = nvme_req(rq)->cmd; in nvme_rdma_queue_rq()
2009 bool queue_ready = test_bit(NVME_RDMA_Q_LIVE, &queue->flags); in nvme_rdma_queue_rq()
2013 WARN_ON_ONCE(rq->tag < 0); in nvme_rdma_queue_rq()
2015 if (!nvme_check_ready(&queue->ctrl->ctrl, rq, queue_ready)) in nvme_rdma_queue_rq()
2016 return nvme_fail_nonready_command(&queue->ctrl->ctrl, rq); in nvme_rdma_queue_rq()
2018 dev = queue->device->dev; in nvme_rdma_queue_rq()
2020 req->sqe.dma = ib_dma_map_single(dev, req->sqe.data, in nvme_rdma_queue_rq()
2023 err = ib_dma_mapping_error(dev, req->sqe.dma); in nvme_rdma_queue_rq()
2027 ib_dma_sync_single_for_cpu(dev, sqe->dma, in nvme_rdma_queue_rq()
2037 queue->pi_support && in nvme_rdma_queue_rq()
2038 (c->common.opcode == nvme_cmd_write || in nvme_rdma_queue_rq()
2039 c->common.opcode == nvme_cmd_read) && in nvme_rdma_queue_rq()
2040 nvme_ns_has_pi(ns->head)) in nvme_rdma_queue_rq()
2041 req->use_sig_mr = true; in nvme_rdma_queue_rq()
2043 req->use_sig_mr = false; in nvme_rdma_queue_rq()
2047 dev_err(queue->ctrl->ctrl.device, in nvme_rdma_queue_rq()
2052 sqe->cqe.done = nvme_rdma_send_done; in nvme_rdma_queue_rq()
2054 ib_dma_sync_single_for_device(dev, sqe->dma, in nvme_rdma_queue_rq()
2057 err = nvme_rdma_post_send(queue, sqe, req->sge, req->num_sge, in nvme_rdma_queue_rq()
2058 req->mr ? &req->reg_wr.wr : NULL); in nvme_rdma_queue_rq()
2067 if (err == -EIO) in nvme_rdma_queue_rq()
2069 else if (err == -ENOMEM || err == -EAGAIN) in nvme_rdma_queue_rq()
2075 ib_dma_unmap_single(dev, req->sqe.dma, sizeof(struct nvme_command), in nvme_rdma_queue_rq()
2082 struct nvme_rdma_queue *queue = hctx->driver_data; in nvme_rdma_poll()
2084 return ib_process_cq_direct(queue->ib_cq, -1); in nvme_rdma_poll()
2093 ret = ib_check_mr_status(req->mr, IB_MR_CHECK_SIG_STATUS, &mr_status); in nvme_rdma_check_pi_status()
2096 nvme_req(rq)->status = NVME_SC_INVALID_PI; in nvme_rdma_check_pi_status()
2103 nvme_req(rq)->status = NVME_SC_GUARD_CHECK; in nvme_rdma_check_pi_status()
2106 nvme_req(rq)->status = NVME_SC_REFTAG_CHECK; in nvme_rdma_check_pi_status()
2109 nvme_req(rq)->status = NVME_SC_APPTAG_CHECK; in nvme_rdma_check_pi_status()
2121 struct nvme_rdma_queue *queue = req->queue; in nvme_rdma_complete_rq()
2122 struct ib_device *ibdev = queue->device->dev; in nvme_rdma_complete_rq()
2124 if (req->use_sig_mr) in nvme_rdma_complete_rq()
2128 ib_dma_unmap_single(ibdev, req->sqe.dma, sizeof(struct nvme_command), in nvme_rdma_complete_rq()
2135 struct nvme_rdma_ctrl *ctrl = to_rdma_ctrl(set->driver_data); in nvme_rdma_map_queues()
2137 nvmf_map_queues(set, &ctrl->ctrl, ctrl->io_queues); in nvme_rdma_map_queues()
2163 nvme_quiesce_admin_queue(&ctrl->ctrl); in nvme_rdma_shutdown_ctrl()
2164 nvme_disable_ctrl(&ctrl->ctrl, shutdown); in nvme_rdma_shutdown_ctrl()
2179 nvme_stop_ctrl(&ctrl->ctrl); in nvme_rdma_reset_ctrl_work()
2182 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { in nvme_rdma_reset_ctrl_work()
2195 ++ctrl->ctrl.nr_reconnects; in nvme_rdma_reset_ctrl_work()
2234 found = nvmf_ip_options_match(&ctrl->ctrl, opts); in nvme_rdma_existing_controller()
2251 return ERR_PTR(-ENOMEM); in nvme_rdma_alloc_ctrl()
2252 ctrl->ctrl.opts = opts; in nvme_rdma_alloc_ctrl()
2253 INIT_LIST_HEAD(&ctrl->list); in nvme_rdma_alloc_ctrl()
2255 if (!(opts->mask & NVMF_OPT_TRSVCID)) { in nvme_rdma_alloc_ctrl()
2256 opts->trsvcid = in nvme_rdma_alloc_ctrl()
2258 if (!opts->trsvcid) { in nvme_rdma_alloc_ctrl()
2259 ret = -ENOMEM; in nvme_rdma_alloc_ctrl()
2262 opts->mask |= NVMF_OPT_TRSVCID; in nvme_rdma_alloc_ctrl()
2266 opts->traddr, opts->trsvcid, &ctrl->addr); in nvme_rdma_alloc_ctrl()
2269 opts->traddr, opts->trsvcid); in nvme_rdma_alloc_ctrl()
2273 if (opts->mask & NVMF_OPT_HOST_TRADDR) { in nvme_rdma_alloc_ctrl()
2275 opts->host_traddr, NULL, &ctrl->src_addr); in nvme_rdma_alloc_ctrl()
2278 opts->host_traddr); in nvme_rdma_alloc_ctrl()
2283 if (!opts->duplicate_connect && nvme_rdma_existing_controller(opts)) { in nvme_rdma_alloc_ctrl()
2284 ret = -EALREADY; in nvme_rdma_alloc_ctrl()
2288 INIT_DELAYED_WORK(&ctrl->reconnect_work, in nvme_rdma_alloc_ctrl()
2290 INIT_WORK(&ctrl->err_work, nvme_rdma_error_recovery_work); in nvme_rdma_alloc_ctrl()
2291 INIT_WORK(&ctrl->ctrl.reset_work, nvme_rdma_reset_ctrl_work); in nvme_rdma_alloc_ctrl()
2293 ctrl->ctrl.queue_count = opts->nr_io_queues + opts->nr_write_queues + in nvme_rdma_alloc_ctrl()
2294 opts->nr_poll_queues + 1; in nvme_rdma_alloc_ctrl()
2295 ctrl->ctrl.sqsize = opts->queue_size - 1; in nvme_rdma_alloc_ctrl()
2296 ctrl->ctrl.kato = opts->kato; in nvme_rdma_alloc_ctrl()
2298 ret = -ENOMEM; in nvme_rdma_alloc_ctrl()
2299 ctrl->queues = kcalloc(ctrl->ctrl.queue_count, sizeof(*ctrl->queues), in nvme_rdma_alloc_ctrl()
2301 if (!ctrl->queues) in nvme_rdma_alloc_ctrl()
2304 ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, in nvme_rdma_alloc_ctrl()
2312 kfree(ctrl->queues); in nvme_rdma_alloc_ctrl()
2329 ret = nvme_add_ctrl(&ctrl->ctrl); in nvme_rdma_create_ctrl()
2333 changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING); in nvme_rdma_create_ctrl()
2340 dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISpcs, hostnqn: %s\n", in nvme_rdma_create_ctrl()
2341 nvmf_ctrl_subsysnqn(&ctrl->ctrl), &ctrl->addr, opts->host->nqn); in nvme_rdma_create_ctrl()
2344 list_add_tail(&ctrl->list, &nvme_rdma_ctrl_list); in nvme_rdma_create_ctrl()
2347 return &ctrl->ctrl; in nvme_rdma_create_ctrl()
2350 nvme_uninit_ctrl(&ctrl->ctrl); in nvme_rdma_create_ctrl()
2352 nvme_put_ctrl(&ctrl->ctrl); in nvme_rdma_create_ctrl()
2354 ret = -EIO; in nvme_rdma_create_ctrl()
2377 if (ndev->dev == ib_device) { in nvme_rdma_remove_one()
2390 if (ctrl->device->dev != ib_device) in nvme_rdma_remove_one()
2392 nvme_delete_ctrl(&ctrl->ctrl); in nvme_rdma_remove_one()
2432 nvme_delete_ctrl(&ctrl->ctrl); in nvme_rdma_cleanup_module()