Lines Matching +full:ctrl +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0
12 #include <linux/nvme-tcp.h>
13 #include <linux/nvme-keyring.h>
19 #include <linux/blk-mq.h>
31 * A non-zero value being sufficient to indicate general consideration of any
45 MODULE_PARM_DESC(wq_unbound, "Use unbound workqueue for nvme-tcp IO context (default false)");
59 * sk_lock -> mmap_lock (page fault) -> fs locks -> sk_lock
60 * because dependencies are tracked for both nvme-tcp and user contexts. Using
61 * a separate class prevents lockdep from conflating nvme-tcp socket use with
62 * user-space socket API use.
69 struct sock *sk = sock->sk; in nvme_tcp_reclassify_socket()
74 switch (sk->sk_family) { in nvme_tcp_reclassify_socket()
76 sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME", in nvme_tcp_reclassify_socket()
78 "sk_lock-AF_INET-NVME", in nvme_tcp_reclassify_socket()
82 sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME", in nvme_tcp_reclassify_socket()
84 "sk_lock-AF_INET6-NVME", in nvme_tcp_reclassify_socket()
162 struct nvme_tcp_ctrl *ctrl; member
192 struct nvme_ctrl ctrl; member
207 static inline struct nvme_tcp_ctrl *to_tcp_ctrl(struct nvme_ctrl *ctrl) in to_tcp_ctrl() argument
209 return container_of(ctrl, struct nvme_tcp_ctrl, ctrl); in to_tcp_ctrl()
214 return queue - queue->ctrl->queues; in nvme_tcp_queue_id()
225 return queue->tls_enabled; in nvme_tcp_queue_tls()
231 static inline bool nvme_tcp_tls_configured(struct nvme_ctrl *ctrl) in nvme_tcp_tls_configured() argument
236 return ctrl->opts->tls; in nvme_tcp_tls_configured()
244 return queue->ctrl->admin_tag_set.tags[queue_idx]; in nvme_tcp_tagset()
245 return queue->ctrl->tag_set.tags[queue_idx - 1]; in nvme_tcp_tagset()
250 return queue->hdr_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvme_tcp_hdgst_len()
255 return queue->data_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvme_tcp_ddgst_len()
260 return req->pdu; in nvme_tcp_req_cmd_pdu()
266 return req->pdu + sizeof(struct nvme_tcp_cmd_pdu) - in nvme_tcp_req_data_pdu()
272 if (nvme_is_fabrics(req->req.cmd)) in nvme_tcp_inline_data_size()
274 return req->queue->cmnd_capsule_len - sizeof(struct nvme_command); in nvme_tcp_inline_data_size()
279 return req == &req->queue->ctrl->async_req; in nvme_tcp_async_req()
291 return rq_data_dir(rq) == WRITE && req->data_len && in nvme_tcp_has_inline_data()
292 req->data_len <= nvme_tcp_inline_data_size(req); in nvme_tcp_has_inline_data()
297 return req->iter.bvec->bv_page; in nvme_tcp_req_cur_page()
302 return req->iter.bvec->bv_offset + req->iter.iov_offset; in nvme_tcp_req_cur_offset()
307 return min_t(size_t, iov_iter_single_seg_count(&req->iter), in nvme_tcp_req_cur_length()
308 req->pdu_len - req->pdu_sent); in nvme_tcp_req_cur_length()
314 req->pdu_len - req->pdu_sent : 0; in nvme_tcp_pdu_data_left()
318 int len) in nvme_tcp_pdu_last_send() argument
320 return nvme_tcp_pdu_data_left(req) <= len; in nvme_tcp_pdu_last_send()
332 if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) { in nvme_tcp_init_iter()
333 vec = &rq->special_vec; in nvme_tcp_init_iter()
338 struct bio *bio = req->curr_bio; in nvme_tcp_init_iter()
342 vec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); in nvme_tcp_init_iter()
347 size = bio->bi_iter.bi_size; in nvme_tcp_init_iter()
348 offset = bio->bi_iter.bi_bvec_done; in nvme_tcp_init_iter()
351 iov_iter_bvec(&req->iter, dir, vec, nr_bvec, size); in nvme_tcp_init_iter()
352 req->iter.iov_offset = offset; in nvme_tcp_init_iter()
356 int len) in nvme_tcp_advance_req() argument
358 req->data_sent += len; in nvme_tcp_advance_req()
359 req->pdu_sent += len; in nvme_tcp_advance_req()
360 iov_iter_advance(&req->iter, len); in nvme_tcp_advance_req()
361 if (!iov_iter_count(&req->iter) && in nvme_tcp_advance_req()
362 req->data_sent < req->data_len) { in nvme_tcp_advance_req()
363 req->curr_bio = req->curr_bio->bi_next; in nvme_tcp_advance_req()
380 return !list_empty(&queue->send_list) || in nvme_tcp_queue_has_pending()
381 !llist_empty(&queue->req_list); in nvme_tcp_queue_has_pending()
393 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_queue_request()
396 empty = llist_add(&req->lentry, &queue->req_list) && in nvme_tcp_queue_request()
397 list_empty(&queue->send_list) && !queue->request; in nvme_tcp_queue_request()
404 if (queue->io_cpu == raw_smp_processor_id() && in nvme_tcp_queue_request()
405 sync && empty && mutex_trylock(&queue->send_mutex)) { in nvme_tcp_queue_request()
407 mutex_unlock(&queue->send_mutex); in nvme_tcp_queue_request()
411 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_queue_request()
419 for (node = llist_del_all(&queue->req_list); node; node = node->next) { in nvme_tcp_process_req_list()
421 list_add(&req->entry, &queue->send_list); in nvme_tcp_process_req_list()
430 req = list_first_entry_or_null(&queue->send_list, in nvme_tcp_fetch_request()
434 req = list_first_entry_or_null(&queue->send_list, in nvme_tcp_fetch_request()
440 list_del(&req->entry); in nvme_tcp_fetch_request()
452 struct page *page, off_t off, size_t len) in nvme_tcp_ddgst_update() argument
457 sg_set_page(&sg, page, len, off); in nvme_tcp_ddgst_update()
458 ahash_request_set_crypt(hash, &sg, NULL, len); in nvme_tcp_ddgst_update()
463 void *pdu, size_t len) in nvme_tcp_hdgst() argument
467 sg_init_one(&sg, pdu, len); in nvme_tcp_hdgst()
468 ahash_request_set_crypt(hash, &sg, pdu + len, len); in nvme_tcp_hdgst()
479 if (unlikely(!(hdr->flags & NVME_TCP_F_HDGST))) { in nvme_tcp_verify_hdgst()
480 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_verify_hdgst()
483 return -EPROTO; in nvme_tcp_verify_hdgst()
486 recv_digest = *(__le32 *)(pdu + hdr->hlen); in nvme_tcp_verify_hdgst()
487 nvme_tcp_hdgst(queue->rcv_hash, pdu, pdu_len); in nvme_tcp_verify_hdgst()
488 exp_digest = *(__le32 *)(pdu + hdr->hlen); in nvme_tcp_verify_hdgst()
490 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_verify_hdgst()
493 return -EIO; in nvme_tcp_verify_hdgst()
503 u32 len; in nvme_tcp_check_ddgst() local
505 len = le32_to_cpu(hdr->plen) - hdr->hlen - in nvme_tcp_check_ddgst()
506 ((hdr->flags & NVME_TCP_F_HDGST) ? digest_len : 0); in nvme_tcp_check_ddgst()
508 if (unlikely(len && !(hdr->flags & NVME_TCP_F_DDGST))) { in nvme_tcp_check_ddgst()
509 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_check_ddgst()
512 return -EPROTO; in nvme_tcp_check_ddgst()
514 crypto_ahash_init(queue->rcv_hash); in nvme_tcp_check_ddgst()
524 page_frag_free(req->pdu); in nvme_tcp_exit_request()
531 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(set->driver_data); in nvme_tcp_init_request() local
534 int queue_idx = (set == &ctrl->tag_set) ? hctx_idx + 1 : 0; in nvme_tcp_init_request()
535 struct nvme_tcp_queue *queue = &ctrl->queues[queue_idx]; in nvme_tcp_init_request()
538 req->pdu = page_frag_alloc(&queue->pf_cache, in nvme_tcp_init_request()
541 if (!req->pdu) in nvme_tcp_init_request()
542 return -ENOMEM; in nvme_tcp_init_request()
544 pdu = req->pdu; in nvme_tcp_init_request()
545 req->queue = queue; in nvme_tcp_init_request()
546 nvme_req(rq)->ctrl = &ctrl->ctrl; in nvme_tcp_init_request()
547 nvme_req(rq)->cmd = &pdu->cmd; in nvme_tcp_init_request()
555 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(data); in nvme_tcp_init_hctx() local
556 struct nvme_tcp_queue *queue = &ctrl->queues[hctx_idx + 1]; in nvme_tcp_init_hctx()
558 hctx->driver_data = queue; in nvme_tcp_init_hctx()
565 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(data); in nvme_tcp_init_admin_hctx() local
566 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_init_admin_hctx()
568 hctx->driver_data = queue; in nvme_tcp_init_admin_hctx()
575 return (queue->pdu_remaining) ? NVME_TCP_RECV_PDU : in nvme_tcp_recv_state()
576 (queue->ddgst_remaining) ? NVME_TCP_RECV_DDGST : in nvme_tcp_recv_state()
582 queue->pdu_remaining = sizeof(struct nvme_tcp_rsp_pdu) + in nvme_tcp_init_recv_ctx()
584 queue->pdu_offset = 0; in nvme_tcp_init_recv_ctx()
585 queue->data_remaining = -1; in nvme_tcp_init_recv_ctx()
586 queue->ddgst_remaining = 0; in nvme_tcp_init_recv_ctx()
589 static void nvme_tcp_error_recovery(struct nvme_ctrl *ctrl) in nvme_tcp_error_recovery() argument
591 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) in nvme_tcp_error_recovery()
594 dev_warn(ctrl->device, "starting error recovery\n"); in nvme_tcp_error_recovery()
595 queue_work(nvme_reset_wq, &to_tcp_ctrl(ctrl)->err_work); in nvme_tcp_error_recovery()
604 rq = nvme_find_rq(nvme_tcp_tagset(queue), cqe->command_id); in nvme_tcp_process_nvme_cqe()
606 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_process_nvme_cqe()
608 cqe->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_process_nvme_cqe()
609 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_process_nvme_cqe()
610 return -EINVAL; in nvme_tcp_process_nvme_cqe()
614 if (req->status == cpu_to_le16(NVME_SC_SUCCESS)) in nvme_tcp_process_nvme_cqe()
615 req->status = cqe->status; in nvme_tcp_process_nvme_cqe()
617 if (!nvme_try_complete_req(rq, req->status, cqe->result)) in nvme_tcp_process_nvme_cqe()
619 queue->nr_cqe++; in nvme_tcp_process_nvme_cqe()
629 rq = nvme_find_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_handle_c2h_data()
631 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
633 pdu->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_handle_c2h_data()
634 return -ENOENT; in nvme_tcp_handle_c2h_data()
638 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
640 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_handle_c2h_data()
641 return -EIO; in nvme_tcp_handle_c2h_data()
644 queue->data_remaining = le32_to_cpu(pdu->data_length); in nvme_tcp_handle_c2h_data()
646 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS && in nvme_tcp_handle_c2h_data()
647 unlikely(!(pdu->hdr.flags & NVME_TCP_F_DATA_LAST))) { in nvme_tcp_handle_c2h_data()
648 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
650 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_handle_c2h_data()
651 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_handle_c2h_data()
652 return -EPROTO; in nvme_tcp_handle_c2h_data()
661 struct nvme_completion *cqe = &pdu->cqe; in nvme_tcp_handle_comp()
671 cqe->command_id))) in nvme_tcp_handle_comp()
672 nvme_complete_async_event(&queue->ctrl->ctrl, cqe->status, in nvme_tcp_handle_comp()
673 &cqe->result); in nvme_tcp_handle_comp()
683 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_setup_h2c_data_pdu()
685 u32 h2cdata_sent = req->pdu_len; in nvme_tcp_setup_h2c_data_pdu()
689 req->state = NVME_TCP_SEND_H2C_PDU; in nvme_tcp_setup_h2c_data_pdu()
690 req->offset = 0; in nvme_tcp_setup_h2c_data_pdu()
691 req->pdu_len = min(req->h2cdata_left, queue->maxh2cdata); in nvme_tcp_setup_h2c_data_pdu()
692 req->pdu_sent = 0; in nvme_tcp_setup_h2c_data_pdu()
693 req->h2cdata_left -= req->pdu_len; in nvme_tcp_setup_h2c_data_pdu()
694 req->h2cdata_offset += h2cdata_sent; in nvme_tcp_setup_h2c_data_pdu()
697 data->hdr.type = nvme_tcp_h2c_data; in nvme_tcp_setup_h2c_data_pdu()
698 if (!req->h2cdata_left) in nvme_tcp_setup_h2c_data_pdu()
699 data->hdr.flags = NVME_TCP_F_DATA_LAST; in nvme_tcp_setup_h2c_data_pdu()
700 if (queue->hdr_digest) in nvme_tcp_setup_h2c_data_pdu()
701 data->hdr.flags |= NVME_TCP_F_HDGST; in nvme_tcp_setup_h2c_data_pdu()
702 if (queue->data_digest) in nvme_tcp_setup_h2c_data_pdu()
703 data->hdr.flags |= NVME_TCP_F_DDGST; in nvme_tcp_setup_h2c_data_pdu()
704 data->hdr.hlen = sizeof(*data); in nvme_tcp_setup_h2c_data_pdu()
705 data->hdr.pdo = data->hdr.hlen + hdgst; in nvme_tcp_setup_h2c_data_pdu()
706 data->hdr.plen = in nvme_tcp_setup_h2c_data_pdu()
707 cpu_to_le32(data->hdr.hlen + hdgst + req->pdu_len + ddgst); in nvme_tcp_setup_h2c_data_pdu()
708 data->ttag = req->ttag; in nvme_tcp_setup_h2c_data_pdu()
709 data->command_id = nvme_cid(rq); in nvme_tcp_setup_h2c_data_pdu()
710 data->data_offset = cpu_to_le32(req->h2cdata_offset); in nvme_tcp_setup_h2c_data_pdu()
711 data->data_length = cpu_to_le32(req->pdu_len); in nvme_tcp_setup_h2c_data_pdu()
719 u32 r2t_length = le32_to_cpu(pdu->r2t_length); in nvme_tcp_handle_r2t()
720 u32 r2t_offset = le32_to_cpu(pdu->r2t_offset); in nvme_tcp_handle_r2t()
722 rq = nvme_find_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_handle_r2t()
724 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
726 pdu->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_handle_r2t()
727 return -ENOENT; in nvme_tcp_handle_r2t()
732 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
733 "req %d r2t len is %u, probably a bug...\n", in nvme_tcp_handle_r2t()
734 rq->tag, r2t_length); in nvme_tcp_handle_r2t()
735 return -EPROTO; in nvme_tcp_handle_r2t()
738 if (unlikely(req->data_sent + r2t_length > req->data_len)) { in nvme_tcp_handle_r2t()
739 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
740 "req %d r2t len %u exceeded data len %u (%zu sent)\n", in nvme_tcp_handle_r2t()
741 rq->tag, r2t_length, req->data_len, req->data_sent); in nvme_tcp_handle_r2t()
742 return -EPROTO; in nvme_tcp_handle_r2t()
745 if (unlikely(r2t_offset < req->data_sent)) { in nvme_tcp_handle_r2t()
746 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
748 rq->tag, r2t_offset, req->data_sent); in nvme_tcp_handle_r2t()
749 return -EPROTO; in nvme_tcp_handle_r2t()
752 req->pdu_len = 0; in nvme_tcp_handle_r2t()
753 req->h2cdata_left = r2t_length; in nvme_tcp_handle_r2t()
754 req->h2cdata_offset = r2t_offset; in nvme_tcp_handle_r2t()
755 req->ttag = pdu->ttag; in nvme_tcp_handle_r2t()
764 unsigned int *offset, size_t *len) in nvme_tcp_recv_pdu() argument
767 char *pdu = queue->pdu; in nvme_tcp_recv_pdu()
768 size_t rcv_len = min_t(size_t, *len, queue->pdu_remaining); in nvme_tcp_recv_pdu()
772 &pdu[queue->pdu_offset], rcv_len); in nvme_tcp_recv_pdu()
776 queue->pdu_remaining -= rcv_len; in nvme_tcp_recv_pdu()
777 queue->pdu_offset += rcv_len; in nvme_tcp_recv_pdu()
779 *len -= rcv_len; in nvme_tcp_recv_pdu()
780 if (queue->pdu_remaining) in nvme_tcp_recv_pdu()
783 hdr = queue->pdu; in nvme_tcp_recv_pdu()
784 if (queue->hdr_digest) { in nvme_tcp_recv_pdu()
785 ret = nvme_tcp_verify_hdgst(queue, queue->pdu, hdr->hlen); in nvme_tcp_recv_pdu()
791 if (queue->data_digest) { in nvme_tcp_recv_pdu()
792 ret = nvme_tcp_check_ddgst(queue, queue->pdu); in nvme_tcp_recv_pdu()
797 switch (hdr->type) { in nvme_tcp_recv_pdu()
799 return nvme_tcp_handle_c2h_data(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
802 return nvme_tcp_handle_comp(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
805 return nvme_tcp_handle_r2t(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
807 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_pdu()
808 "unsupported pdu type (%d)\n", hdr->type); in nvme_tcp_recv_pdu()
809 return -EINVAL; in nvme_tcp_recv_pdu()
822 unsigned int *offset, size_t *len) in nvme_tcp_recv_data() argument
824 struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu; in nvme_tcp_recv_data()
826 nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_recv_data()
832 recv_len = min_t(size_t, *len, queue->data_remaining); in nvme_tcp_recv_data()
836 if (!iov_iter_count(&req->iter)) { in nvme_tcp_recv_data()
837 req->curr_bio = req->curr_bio->bi_next; in nvme_tcp_recv_data()
843 if (!req->curr_bio) { in nvme_tcp_recv_data()
844 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_data()
846 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_recv_data()
848 return -EIO; in nvme_tcp_recv_data()
855 iov_iter_count(&req->iter)); in nvme_tcp_recv_data()
857 if (queue->data_digest) in nvme_tcp_recv_data()
859 &req->iter, recv_len, queue->rcv_hash); in nvme_tcp_recv_data()
862 &req->iter, recv_len); in nvme_tcp_recv_data()
864 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_data()
866 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_recv_data()
870 *len -= recv_len; in nvme_tcp_recv_data()
872 queue->data_remaining -= recv_len; in nvme_tcp_recv_data()
875 if (!queue->data_remaining) { in nvme_tcp_recv_data()
876 if (queue->data_digest) { in nvme_tcp_recv_data()
877 nvme_tcp_ddgst_final(queue->rcv_hash, &queue->exp_ddgst); in nvme_tcp_recv_data()
878 queue->ddgst_remaining = NVME_TCP_DIGEST_LENGTH; in nvme_tcp_recv_data()
880 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) { in nvme_tcp_recv_data()
882 le16_to_cpu(req->status)); in nvme_tcp_recv_data()
883 queue->nr_cqe++; in nvme_tcp_recv_data()
893 struct sk_buff *skb, unsigned int *offset, size_t *len) in nvme_tcp_recv_ddgst() argument
895 struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu; in nvme_tcp_recv_ddgst()
896 char *ddgst = (char *)&queue->recv_ddgst; in nvme_tcp_recv_ddgst()
897 size_t recv_len = min_t(size_t, *len, queue->ddgst_remaining); in nvme_tcp_recv_ddgst()
898 off_t off = NVME_TCP_DIGEST_LENGTH - queue->ddgst_remaining; in nvme_tcp_recv_ddgst()
905 queue->ddgst_remaining -= recv_len; in nvme_tcp_recv_ddgst()
907 *len -= recv_len; in nvme_tcp_recv_ddgst()
908 if (queue->ddgst_remaining) in nvme_tcp_recv_ddgst()
911 if (queue->recv_ddgst != queue->exp_ddgst) { in nvme_tcp_recv_ddgst()
913 pdu->command_id); in nvme_tcp_recv_ddgst()
916 req->status = cpu_to_le16(NVME_SC_DATA_XFER_ERROR); in nvme_tcp_recv_ddgst()
918 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_ddgst()
920 le32_to_cpu(queue->recv_ddgst), in nvme_tcp_recv_ddgst()
921 le32_to_cpu(queue->exp_ddgst)); in nvme_tcp_recv_ddgst()
924 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) { in nvme_tcp_recv_ddgst()
926 pdu->command_id); in nvme_tcp_recv_ddgst()
929 nvme_tcp_end_request(rq, le16_to_cpu(req->status)); in nvme_tcp_recv_ddgst()
930 queue->nr_cqe++; in nvme_tcp_recv_ddgst()
938 unsigned int offset, size_t len) in nvme_tcp_recv_skb() argument
940 struct nvme_tcp_queue *queue = desc->arg.data; in nvme_tcp_recv_skb()
941 size_t consumed = len; in nvme_tcp_recv_skb()
944 if (unlikely(!queue->rd_enabled)) in nvme_tcp_recv_skb()
945 return -EFAULT; in nvme_tcp_recv_skb()
947 while (len) { in nvme_tcp_recv_skb()
950 result = nvme_tcp_recv_pdu(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
953 result = nvme_tcp_recv_data(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
956 result = nvme_tcp_recv_ddgst(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
959 result = -EFAULT; in nvme_tcp_recv_skb()
962 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_skb()
964 queue->rd_enabled = false; in nvme_tcp_recv_skb()
965 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_recv_skb()
979 read_lock_bh(&sk->sk_callback_lock); in nvme_tcp_data_ready()
980 queue = sk->sk_user_data; in nvme_tcp_data_ready()
981 if (likely(queue && queue->rd_enabled) && in nvme_tcp_data_ready()
982 !test_bit(NVME_TCP_Q_POLLING, &queue->flags)) in nvme_tcp_data_ready()
983 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_data_ready()
984 read_unlock_bh(&sk->sk_callback_lock); in nvme_tcp_data_ready()
991 read_lock_bh(&sk->sk_callback_lock); in nvme_tcp_write_space()
992 queue = sk->sk_user_data; in nvme_tcp_write_space()
994 clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); in nvme_tcp_write_space()
995 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_write_space()
997 read_unlock_bh(&sk->sk_callback_lock); in nvme_tcp_write_space()
1004 read_lock_bh(&sk->sk_callback_lock); in nvme_tcp_state_change()
1005 queue = sk->sk_user_data; in nvme_tcp_state_change()
1009 switch (sk->sk_state) { in nvme_tcp_state_change()
1015 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_state_change()
1018 dev_info(queue->ctrl->ctrl.device, in nvme_tcp_state_change()
1020 nvme_tcp_queue_id(queue), sk->sk_state); in nvme_tcp_state_change()
1023 queue->state_change(sk); in nvme_tcp_state_change()
1025 read_unlock_bh(&sk->sk_callback_lock); in nvme_tcp_state_change()
1030 queue->request = NULL; in nvme_tcp_done_send_req()
1038 nvme_complete_async_event(&req->queue->ctrl->ctrl, in nvme_tcp_fail_request()
1048 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_data()
1049 int req_data_len = req->data_len; in nvme_tcp_try_send_data()
1050 u32 h2cdata_left = req->h2cdata_left; in nvme_tcp_try_send_data()
1059 size_t len = nvme_tcp_req_cur_length(req); in nvme_tcp_try_send_data() local
1060 bool last = nvme_tcp_pdu_last_send(req, len); in nvme_tcp_try_send_data()
1061 int req_data_sent = req->data_sent; in nvme_tcp_try_send_data()
1064 if (last && !queue->data_digest && !nvme_tcp_queue_more(queue)) in nvme_tcp_try_send_data()
1069 if (!sendpages_ok(page, len, offset)) in nvme_tcp_try_send_data()
1072 bvec_set_page(&bvec, page, len, offset); in nvme_tcp_try_send_data()
1073 iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len); in nvme_tcp_try_send_data()
1074 ret = sock_sendmsg(queue->sock, &msg); in nvme_tcp_try_send_data()
1078 if (queue->data_digest) in nvme_tcp_try_send_data()
1079 nvme_tcp_ddgst_update(queue->snd_hash, page, in nvme_tcp_try_send_data()
1091 if (last && ret == len) { in nvme_tcp_try_send_data()
1092 if (queue->data_digest) { in nvme_tcp_try_send_data()
1093 nvme_tcp_ddgst_final(queue->snd_hash, in nvme_tcp_try_send_data()
1094 &req->ddgst); in nvme_tcp_try_send_data()
1095 req->state = NVME_TCP_SEND_DDGST; in nvme_tcp_try_send_data()
1096 req->offset = 0; in nvme_tcp_try_send_data()
1106 return -EAGAIN; in nvme_tcp_try_send_data()
1111 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_cmd_pdu()
1117 int len = sizeof(*pdu) + hdgst - req->offset; in nvme_tcp_try_send_cmd_pdu() local
1125 if (queue->hdr_digest && !req->offset) in nvme_tcp_try_send_cmd_pdu()
1126 nvme_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvme_tcp_try_send_cmd_pdu()
1128 bvec_set_virt(&bvec, (void *)pdu + req->offset, len); in nvme_tcp_try_send_cmd_pdu()
1129 iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len); in nvme_tcp_try_send_cmd_pdu()
1130 ret = sock_sendmsg(queue->sock, &msg); in nvme_tcp_try_send_cmd_pdu()
1134 len -= ret; in nvme_tcp_try_send_cmd_pdu()
1135 if (!len) { in nvme_tcp_try_send_cmd_pdu()
1137 req->state = NVME_TCP_SEND_DATA; in nvme_tcp_try_send_cmd_pdu()
1138 if (queue->data_digest) in nvme_tcp_try_send_cmd_pdu()
1139 crypto_ahash_init(queue->snd_hash); in nvme_tcp_try_send_cmd_pdu()
1145 req->offset += ret; in nvme_tcp_try_send_cmd_pdu()
1147 return -EAGAIN; in nvme_tcp_try_send_cmd_pdu()
1152 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_data_pdu()
1157 int len = sizeof(*pdu) - req->offset + hdgst; in nvme_tcp_try_send_data_pdu() local
1160 if (queue->hdr_digest && !req->offset) in nvme_tcp_try_send_data_pdu()
1161 nvme_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvme_tcp_try_send_data_pdu()
1163 if (!req->h2cdata_left) in nvme_tcp_try_send_data_pdu()
1166 bvec_set_virt(&bvec, (void *)pdu + req->offset, len); in nvme_tcp_try_send_data_pdu()
1167 iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len); in nvme_tcp_try_send_data_pdu()
1168 ret = sock_sendmsg(queue->sock, &msg); in nvme_tcp_try_send_data_pdu()
1172 len -= ret; in nvme_tcp_try_send_data_pdu()
1173 if (!len) { in nvme_tcp_try_send_data_pdu()
1174 req->state = NVME_TCP_SEND_DATA; in nvme_tcp_try_send_data_pdu()
1175 if (queue->data_digest) in nvme_tcp_try_send_data_pdu()
1176 crypto_ahash_init(queue->snd_hash); in nvme_tcp_try_send_data_pdu()
1179 req->offset += ret; in nvme_tcp_try_send_data_pdu()
1181 return -EAGAIN; in nvme_tcp_try_send_data_pdu()
1186 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_ddgst()
1187 size_t offset = req->offset; in nvme_tcp_try_send_ddgst()
1188 u32 h2cdata_left = req->h2cdata_left; in nvme_tcp_try_send_ddgst()
1192 .iov_base = (u8 *)&req->ddgst + req->offset, in nvme_tcp_try_send_ddgst()
1193 .iov_len = NVME_TCP_DIGEST_LENGTH - req->offset in nvme_tcp_try_send_ddgst()
1201 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvme_tcp_try_send_ddgst()
1213 req->offset += ret; in nvme_tcp_try_send_ddgst()
1214 return -EAGAIN; in nvme_tcp_try_send_ddgst()
1223 if (!queue->request) { in nvme_tcp_try_send()
1224 queue->request = nvme_tcp_fetch_request(queue); in nvme_tcp_try_send()
1225 if (!queue->request) in nvme_tcp_try_send()
1228 req = queue->request; in nvme_tcp_try_send()
1231 if (req->state == NVME_TCP_SEND_CMD_PDU) { in nvme_tcp_try_send()
1239 if (req->state == NVME_TCP_SEND_H2C_PDU) { in nvme_tcp_try_send()
1245 if (req->state == NVME_TCP_SEND_DATA) { in nvme_tcp_try_send()
1251 if (req->state == NVME_TCP_SEND_DDGST) in nvme_tcp_try_send()
1254 if (ret == -EAGAIN) { in nvme_tcp_try_send()
1257 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_try_send()
1259 nvme_tcp_fail_request(queue->request); in nvme_tcp_try_send()
1269 struct socket *sock = queue->sock; in nvme_tcp_try_recv()
1270 struct sock *sk = sock->sk; in nvme_tcp_try_recv()
1277 queue->nr_cqe = 0; in nvme_tcp_try_recv()
1278 consumed = sock->ops->read_sock(sk, &rd_desc, nvme_tcp_recv_skb); in nvme_tcp_try_recv()
1293 if (mutex_trylock(&queue->send_mutex)) { in nvme_tcp_io_work()
1295 mutex_unlock(&queue->send_mutex); in nvme_tcp_io_work()
1308 if (!pending || !queue->rd_enabled) in nvme_tcp_io_work()
1313 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_io_work()
1318 struct crypto_ahash *tfm = crypto_ahash_reqtfm(queue->rcv_hash); in nvme_tcp_free_crypto()
1320 ahash_request_free(queue->rcv_hash); in nvme_tcp_free_crypto()
1321 ahash_request_free(queue->snd_hash); in nvme_tcp_free_crypto()
1333 queue->snd_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvme_tcp_alloc_crypto()
1334 if (!queue->snd_hash) in nvme_tcp_alloc_crypto()
1336 ahash_request_set_callback(queue->snd_hash, 0, NULL, NULL); in nvme_tcp_alloc_crypto()
1338 queue->rcv_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvme_tcp_alloc_crypto()
1339 if (!queue->rcv_hash) in nvme_tcp_alloc_crypto()
1341 ahash_request_set_callback(queue->rcv_hash, 0, NULL, NULL); in nvme_tcp_alloc_crypto()
1345 ahash_request_free(queue->snd_hash); in nvme_tcp_alloc_crypto()
1348 return -ENOMEM; in nvme_tcp_alloc_crypto()
1351 static void nvme_tcp_free_async_req(struct nvme_tcp_ctrl *ctrl) in nvme_tcp_free_async_req() argument
1353 struct nvme_tcp_request *async = &ctrl->async_req; in nvme_tcp_free_async_req()
1355 page_frag_free(async->pdu); in nvme_tcp_free_async_req()
1358 static int nvme_tcp_alloc_async_req(struct nvme_tcp_ctrl *ctrl) in nvme_tcp_alloc_async_req() argument
1360 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_alloc_async_req()
1361 struct nvme_tcp_request *async = &ctrl->async_req; in nvme_tcp_alloc_async_req()
1364 async->pdu = page_frag_alloc(&queue->pf_cache, in nvme_tcp_alloc_async_req()
1367 if (!async->pdu) in nvme_tcp_alloc_async_req()
1368 return -ENOMEM; in nvme_tcp_alloc_async_req()
1370 async->queue = &ctrl->queues[0]; in nvme_tcp_alloc_async_req()
1376 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_free_queue() local
1377 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_free_queue()
1380 if (!test_and_clear_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) in nvme_tcp_free_queue()
1383 if (queue->hdr_digest || queue->data_digest) in nvme_tcp_free_queue()
1386 page_frag_cache_drain(&queue->pf_cache); in nvme_tcp_free_queue()
1389 /* ->sock will be released by fput() */ in nvme_tcp_free_queue()
1390 fput(queue->sock->file); in nvme_tcp_free_queue()
1391 queue->sock = NULL; in nvme_tcp_free_queue()
1394 kfree(queue->pdu); in nvme_tcp_free_queue()
1395 mutex_destroy(&queue->send_mutex); in nvme_tcp_free_queue()
1396 mutex_destroy(&queue->queue_lock); in nvme_tcp_free_queue()
1413 return -ENOMEM; in nvme_tcp_init_connection()
1417 ret = -ENOMEM; in nvme_tcp_init_connection()
1421 icreq->hdr.type = nvme_tcp_icreq; in nvme_tcp_init_connection()
1422 icreq->hdr.hlen = sizeof(*icreq); in nvme_tcp_init_connection()
1423 icreq->hdr.pdo = 0; in nvme_tcp_init_connection()
1424 icreq->hdr.plen = cpu_to_le32(icreq->hdr.hlen); in nvme_tcp_init_connection()
1425 icreq->pfv = cpu_to_le16(NVME_TCP_PFV_1_0); in nvme_tcp_init_connection()
1426 icreq->maxr2t = 0; /* single inflight r2t supported */ in nvme_tcp_init_connection()
1427 icreq->hpda = 0; /* no alignment constraint */ in nvme_tcp_init_connection()
1428 if (queue->hdr_digest) in nvme_tcp_init_connection()
1429 icreq->digest |= NVME_TCP_HDR_DIGEST_ENABLE; in nvme_tcp_init_connection()
1430 if (queue->data_digest) in nvme_tcp_init_connection()
1431 icreq->digest |= NVME_TCP_DATA_DIGEST_ENABLE; in nvme_tcp_init_connection()
1435 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvme_tcp_init_connection()
1449 ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvme_tcp_init_connection()
1456 ret = -ENOTCONN; in nvme_tcp_init_connection()
1458 ctype = tls_get_record_type(queue->sock->sk, in nvme_tcp_init_connection()
1466 ret = -EINVAL; in nvme_tcp_init_connection()
1467 if (icresp->hdr.type != nvme_tcp_icresp) { in nvme_tcp_init_connection()
1469 nvme_tcp_queue_id(queue), icresp->hdr.type); in nvme_tcp_init_connection()
1473 if (le32_to_cpu(icresp->hdr.plen) != sizeof(*icresp)) { in nvme_tcp_init_connection()
1475 nvme_tcp_queue_id(queue), icresp->hdr.plen); in nvme_tcp_init_connection()
1479 if (icresp->pfv != NVME_TCP_PFV_1_0) { in nvme_tcp_init_connection()
1481 nvme_tcp_queue_id(queue), icresp->pfv); in nvme_tcp_init_connection()
1485 ctrl_ddgst = !!(icresp->digest & NVME_TCP_DATA_DIGEST_ENABLE); in nvme_tcp_init_connection()
1486 if ((queue->data_digest && !ctrl_ddgst) || in nvme_tcp_init_connection()
1487 (!queue->data_digest && ctrl_ddgst)) { in nvme_tcp_init_connection()
1488 pr_err("queue %d: data digest mismatch host: %s ctrl: %s\n", in nvme_tcp_init_connection()
1490 queue->data_digest ? "enabled" : "disabled", in nvme_tcp_init_connection()
1495 ctrl_hdgst = !!(icresp->digest & NVME_TCP_HDR_DIGEST_ENABLE); in nvme_tcp_init_connection()
1496 if ((queue->hdr_digest && !ctrl_hdgst) || in nvme_tcp_init_connection()
1497 (!queue->hdr_digest && ctrl_hdgst)) { in nvme_tcp_init_connection()
1498 pr_err("queue %d: header digest mismatch host: %s ctrl: %s\n", in nvme_tcp_init_connection()
1500 queue->hdr_digest ? "enabled" : "disabled", in nvme_tcp_init_connection()
1505 if (icresp->cpda != 0) { in nvme_tcp_init_connection()
1507 nvme_tcp_queue_id(queue), icresp->cpda); in nvme_tcp_init_connection()
1511 maxh2cdata = le32_to_cpu(icresp->maxdata); in nvme_tcp_init_connection()
1517 queue->maxh2cdata = maxh2cdata; in nvme_tcp_init_connection()
1534 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_default_queue() local
1538 qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT]; in nvme_tcp_default_queue()
1543 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_read_queue() local
1548 qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] + in nvme_tcp_read_queue()
1549 ctrl->io_queues[HCTX_TYPE_READ]; in nvme_tcp_read_queue()
1554 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_poll_queue() local
1560 qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] + in nvme_tcp_poll_queue()
1561 ctrl->io_queues[HCTX_TYPE_READ] + in nvme_tcp_poll_queue()
1562 ctrl->io_queues[HCTX_TYPE_POLL]; in nvme_tcp_poll_queue()
1567 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_set_queue_io_cpu() local
1572 n = qid - 1; in nvme_tcp_set_queue_io_cpu()
1574 n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] - 1; in nvme_tcp_set_queue_io_cpu()
1576 n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] - in nvme_tcp_set_queue_io_cpu()
1577 ctrl->io_queues[HCTX_TYPE_READ] - 1; in nvme_tcp_set_queue_io_cpu()
1579 queue->io_cpu = WORK_CPU_UNBOUND; in nvme_tcp_set_queue_io_cpu()
1581 queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false); in nvme_tcp_set_queue_io_cpu()
1587 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_tls_done() local
1591 dev_dbg(ctrl->ctrl.device, "queue %d: TLS handshake done, key %x, status %d\n", in nvme_tcp_tls_done()
1595 queue->tls_err = -status; in nvme_tcp_tls_done()
1601 dev_warn(ctrl->ctrl.device, "queue %d: Invalid key %x\n", in nvme_tcp_tls_done()
1603 queue->tls_err = -ENOKEY; in nvme_tcp_tls_done()
1605 queue->tls_enabled = true; in nvme_tcp_tls_done()
1607 ctrl->ctrl.tls_pskid = key_serial(tls_key); in nvme_tcp_tls_done()
1609 queue->tls_err = 0; in nvme_tcp_tls_done()
1613 complete(&queue->tls_complete); in nvme_tcp_tls_done()
1626 dev_dbg(nctrl->device, "queue %d: start TLS with key %x\n", in nvme_tcp_start_tls()
1629 args.ta_sock = queue->sock; in nvme_tcp_start_tls()
1634 if (nctrl->opts->keyring) in nvme_tcp_start_tls()
1635 keyring = key_serial(nctrl->opts->keyring); in nvme_tcp_start_tls()
1638 queue->tls_err = -EOPNOTSUPP; in nvme_tcp_start_tls()
1639 init_completion(&queue->tls_complete); in nvme_tcp_start_tls()
1642 dev_err(nctrl->device, "queue %d: failed to start TLS: %d\n", in nvme_tcp_start_tls()
1646 ret = wait_for_completion_interruptible_timeout(&queue->tls_complete, tmo); in nvme_tcp_start_tls()
1649 ret = -ETIMEDOUT; in nvme_tcp_start_tls()
1651 dev_err(nctrl->device, in nvme_tcp_start_tls()
1654 tls_handshake_cancel(queue->sock->sk); in nvme_tcp_start_tls()
1656 dev_dbg(nctrl->device, in nvme_tcp_start_tls()
1658 qid, queue->tls_err); in nvme_tcp_start_tls()
1659 ret = queue->tls_err; in nvme_tcp_start_tls()
1667 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_alloc_queue() local
1668 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_alloc_queue()
1672 mutex_init(&queue->queue_lock); in nvme_tcp_alloc_queue()
1673 queue->ctrl = ctrl; in nvme_tcp_alloc_queue()
1674 init_llist_head(&queue->req_list); in nvme_tcp_alloc_queue()
1675 INIT_LIST_HEAD(&queue->send_list); in nvme_tcp_alloc_queue()
1676 mutex_init(&queue->send_mutex); in nvme_tcp_alloc_queue()
1677 INIT_WORK(&queue->io_work, nvme_tcp_io_work); in nvme_tcp_alloc_queue()
1680 queue->cmnd_capsule_len = nctrl->ioccsz * 16; in nvme_tcp_alloc_queue()
1682 queue->cmnd_capsule_len = sizeof(struct nvme_command) + in nvme_tcp_alloc_queue()
1685 ret = sock_create(ctrl->addr.ss_family, SOCK_STREAM, in nvme_tcp_alloc_queue()
1686 IPPROTO_TCP, &queue->sock); in nvme_tcp_alloc_queue()
1688 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1693 sock_file = sock_alloc_file(queue->sock, O_CLOEXEC, NULL); in nvme_tcp_alloc_queue()
1698 nvme_tcp_reclassify_socket(queue->sock); in nvme_tcp_alloc_queue()
1701 tcp_sock_set_syncnt(queue->sock->sk, 1); in nvme_tcp_alloc_queue()
1704 tcp_sock_set_nodelay(queue->sock->sk); in nvme_tcp_alloc_queue()
1711 sock_no_linger(queue->sock->sk); in nvme_tcp_alloc_queue()
1714 sock_set_priority(queue->sock->sk, so_priority); in nvme_tcp_alloc_queue()
1717 if (nctrl->opts->tos >= 0) in nvme_tcp_alloc_queue()
1718 ip_sock_set_tos(queue->sock->sk, nctrl->opts->tos); in nvme_tcp_alloc_queue()
1721 queue->sock->sk->sk_rcvtimeo = 10 * HZ; in nvme_tcp_alloc_queue()
1723 queue->sock->sk->sk_allocation = GFP_ATOMIC; in nvme_tcp_alloc_queue()
1724 queue->sock->sk->sk_use_task_frag = false; in nvme_tcp_alloc_queue()
1726 queue->request = NULL; in nvme_tcp_alloc_queue()
1727 queue->data_remaining = 0; in nvme_tcp_alloc_queue()
1728 queue->ddgst_remaining = 0; in nvme_tcp_alloc_queue()
1729 queue->pdu_remaining = 0; in nvme_tcp_alloc_queue()
1730 queue->pdu_offset = 0; in nvme_tcp_alloc_queue()
1731 sk_set_memalloc(queue->sock->sk); in nvme_tcp_alloc_queue()
1733 if (nctrl->opts->mask & NVMF_OPT_HOST_TRADDR) { in nvme_tcp_alloc_queue()
1734 ret = kernel_bind(queue->sock, (struct sockaddr *)&ctrl->src_addr, in nvme_tcp_alloc_queue()
1735 sizeof(ctrl->src_addr)); in nvme_tcp_alloc_queue()
1737 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1744 if (nctrl->opts->mask & NVMF_OPT_HOST_IFACE) { in nvme_tcp_alloc_queue()
1745 char *iface = nctrl->opts->host_iface; in nvme_tcp_alloc_queue()
1748 ret = sock_setsockopt(queue->sock, SOL_SOCKET, SO_BINDTODEVICE, in nvme_tcp_alloc_queue()
1751 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1758 queue->hdr_digest = nctrl->opts->hdr_digest; in nvme_tcp_alloc_queue()
1759 queue->data_digest = nctrl->opts->data_digest; in nvme_tcp_alloc_queue()
1760 if (queue->hdr_digest || queue->data_digest) { in nvme_tcp_alloc_queue()
1763 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1771 queue->pdu = kmalloc(rcv_pdu_size, GFP_KERNEL); in nvme_tcp_alloc_queue()
1772 if (!queue->pdu) { in nvme_tcp_alloc_queue()
1773 ret = -ENOMEM; in nvme_tcp_alloc_queue()
1777 dev_dbg(nctrl->device, "connecting queue %d\n", in nvme_tcp_alloc_queue()
1780 ret = kernel_connect(queue->sock, (struct sockaddr *)&ctrl->addr, in nvme_tcp_alloc_queue()
1781 sizeof(ctrl->addr), 0); in nvme_tcp_alloc_queue()
1783 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1799 set_bit(NVME_TCP_Q_ALLOCATED, &queue->flags); in nvme_tcp_alloc_queue()
1804 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvme_tcp_alloc_queue()
1806 kfree(queue->pdu); in nvme_tcp_alloc_queue()
1808 if (queue->hdr_digest || queue->data_digest) in nvme_tcp_alloc_queue()
1811 /* ->sock will be released by fput() */ in nvme_tcp_alloc_queue()
1812 fput(queue->sock->file); in nvme_tcp_alloc_queue()
1813 queue->sock = NULL; in nvme_tcp_alloc_queue()
1815 mutex_destroy(&queue->send_mutex); in nvme_tcp_alloc_queue()
1816 mutex_destroy(&queue->queue_lock); in nvme_tcp_alloc_queue()
1822 struct socket *sock = queue->sock; in nvme_tcp_restore_sock_ops()
1824 write_lock_bh(&sock->sk->sk_callback_lock); in nvme_tcp_restore_sock_ops()
1825 sock->sk->sk_user_data = NULL; in nvme_tcp_restore_sock_ops()
1826 sock->sk->sk_data_ready = queue->data_ready; in nvme_tcp_restore_sock_ops()
1827 sock->sk->sk_state_change = queue->state_change; in nvme_tcp_restore_sock_ops()
1828 sock->sk->sk_write_space = queue->write_space; in nvme_tcp_restore_sock_ops()
1829 write_unlock_bh(&sock->sk->sk_callback_lock); in nvme_tcp_restore_sock_ops()
1834 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in __nvme_tcp_stop_queue()
1836 cancel_work_sync(&queue->io_work); in __nvme_tcp_stop_queue()
1841 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_stop_queue() local
1842 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_stop_queue()
1844 if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) in nvme_tcp_stop_queue()
1847 mutex_lock(&queue->queue_lock); in nvme_tcp_stop_queue()
1848 if (test_and_clear_bit(NVME_TCP_Q_LIVE, &queue->flags)) in nvme_tcp_stop_queue()
1851 queue->tls_enabled = false; in nvme_tcp_stop_queue()
1852 mutex_unlock(&queue->queue_lock); in nvme_tcp_stop_queue()
1857 write_lock_bh(&queue->sock->sk->sk_callback_lock); in nvme_tcp_setup_sock_ops()
1858 queue->sock->sk->sk_user_data = queue; in nvme_tcp_setup_sock_ops()
1859 queue->state_change = queue->sock->sk->sk_state_change; in nvme_tcp_setup_sock_ops()
1860 queue->data_ready = queue->sock->sk->sk_data_ready; in nvme_tcp_setup_sock_ops()
1861 queue->write_space = queue->sock->sk->sk_write_space; in nvme_tcp_setup_sock_ops()
1862 queue->sock->sk->sk_data_ready = nvme_tcp_data_ready; in nvme_tcp_setup_sock_ops()
1863 queue->sock->sk->sk_state_change = nvme_tcp_state_change; in nvme_tcp_setup_sock_ops()
1864 queue->sock->sk->sk_write_space = nvme_tcp_write_space; in nvme_tcp_setup_sock_ops()
1866 queue->sock->sk->sk_ll_usec = 1; in nvme_tcp_setup_sock_ops()
1868 write_unlock_bh(&queue->sock->sk->sk_callback_lock); in nvme_tcp_setup_sock_ops()
1873 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_start_queue() local
1874 struct nvme_tcp_queue *queue = &ctrl->queues[idx]; in nvme_tcp_start_queue()
1877 queue->rd_enabled = true; in nvme_tcp_start_queue()
1887 set_bit(NVME_TCP_Q_LIVE, &queue->flags); in nvme_tcp_start_queue()
1889 if (test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) in nvme_tcp_start_queue()
1891 dev_err(nctrl->device, in nvme_tcp_start_queue()
1897 static void nvme_tcp_free_admin_queue(struct nvme_ctrl *ctrl) in nvme_tcp_free_admin_queue() argument
1899 if (to_tcp_ctrl(ctrl)->async_req.pdu) { in nvme_tcp_free_admin_queue()
1900 cancel_work_sync(&ctrl->async_event_work); in nvme_tcp_free_admin_queue()
1901 nvme_tcp_free_async_req(to_tcp_ctrl(ctrl)); in nvme_tcp_free_admin_queue()
1902 to_tcp_ctrl(ctrl)->async_req.pdu = NULL; in nvme_tcp_free_admin_queue()
1905 nvme_tcp_free_queue(ctrl, 0); in nvme_tcp_free_admin_queue()
1908 static void nvme_tcp_free_io_queues(struct nvme_ctrl *ctrl) in nvme_tcp_free_io_queues() argument
1912 for (i = 1; i < ctrl->queue_count; i++) in nvme_tcp_free_io_queues()
1913 nvme_tcp_free_queue(ctrl, i); in nvme_tcp_free_io_queues()
1916 static void nvme_tcp_stop_io_queues(struct nvme_ctrl *ctrl) in nvme_tcp_stop_io_queues() argument
1920 for (i = 1; i < ctrl->queue_count; i++) in nvme_tcp_stop_io_queues()
1921 nvme_tcp_stop_queue(ctrl, i); in nvme_tcp_stop_io_queues()
1924 static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl, in nvme_tcp_start_io_queues() argument
1930 ret = nvme_tcp_start_queue(ctrl, i); in nvme_tcp_start_io_queues()
1938 for (i--; i >= first; i--) in nvme_tcp_start_io_queues()
1939 nvme_tcp_stop_queue(ctrl, i); in nvme_tcp_start_io_queues()
1943 static int nvme_tcp_alloc_admin_queue(struct nvme_ctrl *ctrl) in nvme_tcp_alloc_admin_queue() argument
1948 if (nvme_tcp_tls_configured(ctrl)) { in nvme_tcp_alloc_admin_queue()
1949 if (ctrl->opts->tls_key) in nvme_tcp_alloc_admin_queue()
1950 pskid = key_serial(ctrl->opts->tls_key); in nvme_tcp_alloc_admin_queue()
1952 pskid = nvme_tls_psk_default(ctrl->opts->keyring, in nvme_tcp_alloc_admin_queue()
1953 ctrl->opts->host->nqn, in nvme_tcp_alloc_admin_queue()
1954 ctrl->opts->subsysnqn); in nvme_tcp_alloc_admin_queue()
1956 dev_err(ctrl->device, "no valid PSK found\n"); in nvme_tcp_alloc_admin_queue()
1957 return -ENOKEY; in nvme_tcp_alloc_admin_queue()
1962 ret = nvme_tcp_alloc_queue(ctrl, 0, pskid); in nvme_tcp_alloc_admin_queue()
1966 ret = nvme_tcp_alloc_async_req(to_tcp_ctrl(ctrl)); in nvme_tcp_alloc_admin_queue()
1973 nvme_tcp_free_queue(ctrl, 0); in nvme_tcp_alloc_admin_queue()
1977 static int __nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) in __nvme_tcp_alloc_io_queues() argument
1981 if (nvme_tcp_tls_configured(ctrl) && !ctrl->tls_pskid) { in __nvme_tcp_alloc_io_queues()
1982 dev_err(ctrl->device, "no PSK negotiated\n"); in __nvme_tcp_alloc_io_queues()
1983 return -ENOKEY; in __nvme_tcp_alloc_io_queues()
1986 for (i = 1; i < ctrl->queue_count; i++) { in __nvme_tcp_alloc_io_queues()
1987 ret = nvme_tcp_alloc_queue(ctrl, i, in __nvme_tcp_alloc_io_queues()
1988 ctrl->tls_pskid); in __nvme_tcp_alloc_io_queues()
1996 for (i--; i >= 1; i--) in __nvme_tcp_alloc_io_queues()
1997 nvme_tcp_free_queue(ctrl, i); in __nvme_tcp_alloc_io_queues()
2002 static int nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) in nvme_tcp_alloc_io_queues() argument
2007 nr_io_queues = nvmf_nr_io_queues(ctrl->opts); in nvme_tcp_alloc_io_queues()
2008 ret = nvme_set_queue_count(ctrl, &nr_io_queues); in nvme_tcp_alloc_io_queues()
2013 dev_err(ctrl->device, in nvme_tcp_alloc_io_queues()
2015 return -ENOMEM; in nvme_tcp_alloc_io_queues()
2018 ctrl->queue_count = nr_io_queues + 1; in nvme_tcp_alloc_io_queues()
2019 dev_info(ctrl->device, in nvme_tcp_alloc_io_queues()
2022 nvmf_set_io_queues(ctrl->opts, nr_io_queues, in nvme_tcp_alloc_io_queues()
2023 to_tcp_ctrl(ctrl)->io_queues); in nvme_tcp_alloc_io_queues()
2024 return __nvme_tcp_alloc_io_queues(ctrl); in nvme_tcp_alloc_io_queues()
2027 static void nvme_tcp_destroy_io_queues(struct nvme_ctrl *ctrl, bool remove) in nvme_tcp_destroy_io_queues() argument
2029 nvme_tcp_stop_io_queues(ctrl); in nvme_tcp_destroy_io_queues()
2031 nvme_remove_io_tag_set(ctrl); in nvme_tcp_destroy_io_queues()
2032 nvme_tcp_free_io_queues(ctrl); in nvme_tcp_destroy_io_queues()
2035 static int nvme_tcp_configure_io_queues(struct nvme_ctrl *ctrl, bool new) in nvme_tcp_configure_io_queues() argument
2039 ret = nvme_tcp_alloc_io_queues(ctrl); in nvme_tcp_configure_io_queues()
2044 ret = nvme_alloc_io_tag_set(ctrl, &to_tcp_ctrl(ctrl)->tag_set, in nvme_tcp_configure_io_queues()
2046 ctrl->opts->nr_poll_queues ? HCTX_MAX_TYPES : 2, in nvme_tcp_configure_io_queues()
2057 nr_queues = min(ctrl->tagset->nr_hw_queues + 1, ctrl->queue_count); in nvme_tcp_configure_io_queues()
2058 ret = nvme_tcp_start_io_queues(ctrl, 1, nr_queues); in nvme_tcp_configure_io_queues()
2063 nvme_start_freeze(ctrl); in nvme_tcp_configure_io_queues()
2064 nvme_unquiesce_io_queues(ctrl); in nvme_tcp_configure_io_queues()
2065 if (!nvme_wait_freeze_timeout(ctrl, NVME_IO_TIMEOUT)) { in nvme_tcp_configure_io_queues()
2071 ret = -ENODEV; in nvme_tcp_configure_io_queues()
2072 nvme_unfreeze(ctrl); in nvme_tcp_configure_io_queues()
2075 blk_mq_update_nr_hw_queues(ctrl->tagset, in nvme_tcp_configure_io_queues()
2076 ctrl->queue_count - 1); in nvme_tcp_configure_io_queues()
2077 nvme_unfreeze(ctrl); in nvme_tcp_configure_io_queues()
2084 ret = nvme_tcp_start_io_queues(ctrl, nr_queues, in nvme_tcp_configure_io_queues()
2085 ctrl->tagset->nr_hw_queues + 1); in nvme_tcp_configure_io_queues()
2092 nvme_quiesce_io_queues(ctrl); in nvme_tcp_configure_io_queues()
2093 nvme_sync_io_queues(ctrl); in nvme_tcp_configure_io_queues()
2094 nvme_tcp_stop_io_queues(ctrl); in nvme_tcp_configure_io_queues()
2096 nvme_cancel_tagset(ctrl); in nvme_tcp_configure_io_queues()
2098 nvme_remove_io_tag_set(ctrl); in nvme_tcp_configure_io_queues()
2100 nvme_tcp_free_io_queues(ctrl); in nvme_tcp_configure_io_queues()
2104 static void nvme_tcp_destroy_admin_queue(struct nvme_ctrl *ctrl, bool remove) in nvme_tcp_destroy_admin_queue() argument
2106 nvme_tcp_stop_queue(ctrl, 0); in nvme_tcp_destroy_admin_queue()
2108 nvme_remove_admin_tag_set(ctrl); in nvme_tcp_destroy_admin_queue()
2109 nvme_tcp_free_admin_queue(ctrl); in nvme_tcp_destroy_admin_queue()
2112 static int nvme_tcp_configure_admin_queue(struct nvme_ctrl *ctrl, bool new) in nvme_tcp_configure_admin_queue() argument
2116 error = nvme_tcp_alloc_admin_queue(ctrl); in nvme_tcp_configure_admin_queue()
2121 error = nvme_alloc_admin_tag_set(ctrl, in nvme_tcp_configure_admin_queue()
2122 &to_tcp_ctrl(ctrl)->admin_tag_set, in nvme_tcp_configure_admin_queue()
2129 error = nvme_tcp_start_queue(ctrl, 0); in nvme_tcp_configure_admin_queue()
2133 error = nvme_enable_ctrl(ctrl); in nvme_tcp_configure_admin_queue()
2137 nvme_unquiesce_admin_queue(ctrl); in nvme_tcp_configure_admin_queue()
2139 error = nvme_init_ctrl_finish(ctrl, false); in nvme_tcp_configure_admin_queue()
2146 nvme_quiesce_admin_queue(ctrl); in nvme_tcp_configure_admin_queue()
2147 blk_sync_queue(ctrl->admin_q); in nvme_tcp_configure_admin_queue()
2149 nvme_tcp_stop_queue(ctrl, 0); in nvme_tcp_configure_admin_queue()
2150 nvme_cancel_admin_tagset(ctrl); in nvme_tcp_configure_admin_queue()
2153 nvme_remove_admin_tag_set(ctrl); in nvme_tcp_configure_admin_queue()
2155 nvme_tcp_free_admin_queue(ctrl); in nvme_tcp_configure_admin_queue()
2159 static void nvme_tcp_teardown_admin_queue(struct nvme_ctrl *ctrl, in nvme_tcp_teardown_admin_queue() argument
2162 nvme_quiesce_admin_queue(ctrl); in nvme_tcp_teardown_admin_queue()
2163 blk_sync_queue(ctrl->admin_q); in nvme_tcp_teardown_admin_queue()
2164 nvme_tcp_stop_queue(ctrl, 0); in nvme_tcp_teardown_admin_queue()
2165 nvme_cancel_admin_tagset(ctrl); in nvme_tcp_teardown_admin_queue()
2167 nvme_unquiesce_admin_queue(ctrl); in nvme_tcp_teardown_admin_queue()
2168 nvme_tcp_destroy_admin_queue(ctrl, remove); in nvme_tcp_teardown_admin_queue()
2169 if (ctrl->tls_pskid) { in nvme_tcp_teardown_admin_queue()
2170 dev_dbg(ctrl->device, "Wipe negotiated TLS_PSK %08x\n", in nvme_tcp_teardown_admin_queue()
2171 ctrl->tls_pskid); in nvme_tcp_teardown_admin_queue()
2172 ctrl->tls_pskid = 0; in nvme_tcp_teardown_admin_queue()
2176 static void nvme_tcp_teardown_io_queues(struct nvme_ctrl *ctrl, in nvme_tcp_teardown_io_queues() argument
2179 if (ctrl->queue_count <= 1) in nvme_tcp_teardown_io_queues()
2181 nvme_quiesce_admin_queue(ctrl); in nvme_tcp_teardown_io_queues()
2182 nvme_quiesce_io_queues(ctrl); in nvme_tcp_teardown_io_queues()
2183 nvme_sync_io_queues(ctrl); in nvme_tcp_teardown_io_queues()
2184 nvme_tcp_stop_io_queues(ctrl); in nvme_tcp_teardown_io_queues()
2185 nvme_cancel_tagset(ctrl); in nvme_tcp_teardown_io_queues()
2187 nvme_unquiesce_io_queues(ctrl); in nvme_tcp_teardown_io_queues()
2188 nvme_tcp_destroy_io_queues(ctrl, remove); in nvme_tcp_teardown_io_queues()
2191 static void nvme_tcp_reconnect_or_remove(struct nvme_ctrl *ctrl, in nvme_tcp_reconnect_or_remove() argument
2194 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_tcp_reconnect_or_remove()
2202 if (nvmf_should_reconnect(ctrl, status)) { in nvme_tcp_reconnect_or_remove()
2203 dev_info(ctrl->device, "Reconnecting in %d seconds...\n", in nvme_tcp_reconnect_or_remove()
2204 ctrl->opts->reconnect_delay); in nvme_tcp_reconnect_or_remove()
2205 queue_delayed_work(nvme_wq, &to_tcp_ctrl(ctrl)->connect_work, in nvme_tcp_reconnect_or_remove()
2206 ctrl->opts->reconnect_delay * HZ); in nvme_tcp_reconnect_or_remove()
2208 dev_info(ctrl->device, "Removing controller (%d)...\n", in nvme_tcp_reconnect_or_remove()
2210 nvme_delete_ctrl(ctrl); in nvme_tcp_reconnect_or_remove()
2214 static int nvme_tcp_setup_ctrl(struct nvme_ctrl *ctrl, bool new) in nvme_tcp_setup_ctrl() argument
2216 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_tcp_setup_ctrl()
2219 ret = nvme_tcp_configure_admin_queue(ctrl, new); in nvme_tcp_setup_ctrl()
2223 if (ctrl->icdoff) { in nvme_tcp_setup_ctrl()
2224 ret = -EOPNOTSUPP; in nvme_tcp_setup_ctrl()
2225 dev_err(ctrl->device, "icdoff is not supported!\n"); in nvme_tcp_setup_ctrl()
2229 if (!nvme_ctrl_sgl_supported(ctrl)) { in nvme_tcp_setup_ctrl()
2230 ret = -EOPNOTSUPP; in nvme_tcp_setup_ctrl()
2231 dev_err(ctrl->device, "Mandatory sgls are not supported!\n"); in nvme_tcp_setup_ctrl()
2235 if (opts->queue_size > ctrl->sqsize + 1) in nvme_tcp_setup_ctrl()
2236 dev_warn(ctrl->device, in nvme_tcp_setup_ctrl()
2237 "queue_size %zu > ctrl sqsize %u, clamping down\n", in nvme_tcp_setup_ctrl()
2238 opts->queue_size, ctrl->sqsize + 1); in nvme_tcp_setup_ctrl()
2240 if (ctrl->sqsize + 1 > ctrl->maxcmd) { in nvme_tcp_setup_ctrl()
2241 dev_warn(ctrl->device, in nvme_tcp_setup_ctrl()
2242 "sqsize %u > ctrl maxcmd %u, clamping down\n", in nvme_tcp_setup_ctrl()
2243 ctrl->sqsize + 1, ctrl->maxcmd); in nvme_tcp_setup_ctrl()
2244 ctrl->sqsize = ctrl->maxcmd - 1; in nvme_tcp_setup_ctrl()
2247 if (ctrl->queue_count > 1) { in nvme_tcp_setup_ctrl()
2248 ret = nvme_tcp_configure_io_queues(ctrl, new); in nvme_tcp_setup_ctrl()
2253 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) { in nvme_tcp_setup_ctrl()
2255 * state change failure is ok if we started ctrl delete, in nvme_tcp_setup_ctrl()
2259 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_tcp_setup_ctrl()
2264 ret = -EINVAL; in nvme_tcp_setup_ctrl()
2268 nvme_start_ctrl(ctrl); in nvme_tcp_setup_ctrl()
2272 if (ctrl->queue_count > 1) { in nvme_tcp_setup_ctrl()
2273 nvme_quiesce_io_queues(ctrl); in nvme_tcp_setup_ctrl()
2274 nvme_sync_io_queues(ctrl); in nvme_tcp_setup_ctrl()
2275 nvme_tcp_stop_io_queues(ctrl); in nvme_tcp_setup_ctrl()
2276 nvme_cancel_tagset(ctrl); in nvme_tcp_setup_ctrl()
2277 nvme_tcp_destroy_io_queues(ctrl, new); in nvme_tcp_setup_ctrl()
2280 nvme_stop_keep_alive(ctrl); in nvme_tcp_setup_ctrl()
2281 nvme_tcp_teardown_admin_queue(ctrl, false); in nvme_tcp_setup_ctrl()
2289 struct nvme_ctrl *ctrl = &tcp_ctrl->ctrl; in nvme_tcp_reconnect_ctrl_work() local
2292 ++ctrl->nr_reconnects; in nvme_tcp_reconnect_ctrl_work()
2294 ret = nvme_tcp_setup_ctrl(ctrl, false); in nvme_tcp_reconnect_ctrl_work()
2298 dev_info(ctrl->device, "Successfully reconnected (attempt %d/%d)\n", in nvme_tcp_reconnect_ctrl_work()
2299 ctrl->nr_reconnects, ctrl->opts->max_reconnects); in nvme_tcp_reconnect_ctrl_work()
2301 ctrl->nr_reconnects = 0; in nvme_tcp_reconnect_ctrl_work()
2306 dev_info(ctrl->device, "Failed reconnect attempt %d/%d\n", in nvme_tcp_reconnect_ctrl_work()
2307 ctrl->nr_reconnects, ctrl->opts->max_reconnects); in nvme_tcp_reconnect_ctrl_work()
2308 nvme_tcp_reconnect_or_remove(ctrl, ret); in nvme_tcp_reconnect_ctrl_work()
2315 struct nvme_ctrl *ctrl = &tcp_ctrl->ctrl; in nvme_tcp_error_recovery_work() local
2317 nvme_stop_keep_alive(ctrl); in nvme_tcp_error_recovery_work()
2318 flush_work(&ctrl->async_event_work); in nvme_tcp_error_recovery_work()
2319 nvme_tcp_teardown_io_queues(ctrl, false); in nvme_tcp_error_recovery_work()
2321 nvme_unquiesce_io_queues(ctrl); in nvme_tcp_error_recovery_work()
2322 nvme_tcp_teardown_admin_queue(ctrl, false); in nvme_tcp_error_recovery_work()
2323 nvme_unquiesce_admin_queue(ctrl); in nvme_tcp_error_recovery_work()
2324 nvme_auth_stop(ctrl); in nvme_tcp_error_recovery_work()
2326 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING)) { in nvme_tcp_error_recovery_work()
2327 /* state change failure is ok if we started ctrl delete */ in nvme_tcp_error_recovery_work()
2328 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_tcp_error_recovery_work()
2335 nvme_tcp_reconnect_or_remove(ctrl, 0); in nvme_tcp_error_recovery_work()
2338 static void nvme_tcp_teardown_ctrl(struct nvme_ctrl *ctrl, bool shutdown) in nvme_tcp_teardown_ctrl() argument
2340 nvme_tcp_teardown_io_queues(ctrl, shutdown); in nvme_tcp_teardown_ctrl()
2341 nvme_quiesce_admin_queue(ctrl); in nvme_tcp_teardown_ctrl()
2342 nvme_disable_ctrl(ctrl, shutdown); in nvme_tcp_teardown_ctrl()
2343 nvme_tcp_teardown_admin_queue(ctrl, shutdown); in nvme_tcp_teardown_ctrl()
2346 static void nvme_tcp_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_tcp_delete_ctrl() argument
2348 nvme_tcp_teardown_ctrl(ctrl, true); in nvme_tcp_delete_ctrl()
2353 struct nvme_ctrl *ctrl = in nvme_reset_ctrl_work() local
2357 nvme_stop_ctrl(ctrl); in nvme_reset_ctrl_work()
2358 nvme_tcp_teardown_ctrl(ctrl, false); in nvme_reset_ctrl_work()
2360 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING)) { in nvme_reset_ctrl_work()
2361 /* state change failure is ok if we started ctrl delete */ in nvme_reset_ctrl_work()
2362 enum nvme_ctrl_state state = nvme_ctrl_state(ctrl); in nvme_reset_ctrl_work()
2369 ret = nvme_tcp_setup_ctrl(ctrl, false); in nvme_reset_ctrl_work()
2376 ++ctrl->nr_reconnects; in nvme_reset_ctrl_work()
2377 nvme_tcp_reconnect_or_remove(ctrl, ret); in nvme_reset_ctrl_work()
2380 static void nvme_tcp_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_tcp_stop_ctrl() argument
2382 flush_work(&to_tcp_ctrl(ctrl)->err_work); in nvme_tcp_stop_ctrl()
2383 cancel_delayed_work_sync(&to_tcp_ctrl(ctrl)->connect_work); in nvme_tcp_stop_ctrl()
2388 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_free_ctrl() local
2390 if (list_empty(&ctrl->list)) in nvme_tcp_free_ctrl()
2394 list_del(&ctrl->list); in nvme_tcp_free_ctrl()
2397 nvmf_free_options(nctrl->opts); in nvme_tcp_free_ctrl()
2399 kfree(ctrl->queues); in nvme_tcp_free_ctrl()
2400 kfree(ctrl); in nvme_tcp_free_ctrl()
2405 struct nvme_sgl_desc *sg = &c->common.dptr.sgl; in nvme_tcp_set_sg_null()
2407 sg->addr = 0; in nvme_tcp_set_sg_null()
2408 sg->length = 0; in nvme_tcp_set_sg_null()
2409 sg->type = (NVME_TRANSPORT_SGL_DATA_DESC << 4) | in nvme_tcp_set_sg_null()
2416 struct nvme_sgl_desc *sg = &c->common.dptr.sgl; in nvme_tcp_set_sg_inline()
2418 sg->addr = cpu_to_le64(queue->ctrl->ctrl.icdoff); in nvme_tcp_set_sg_inline()
2419 sg->length = cpu_to_le32(data_len); in nvme_tcp_set_sg_inline()
2420 sg->type = (NVME_SGL_FMT_DATA_DESC << 4) | NVME_SGL_FMT_OFFSET; in nvme_tcp_set_sg_inline()
2426 struct nvme_sgl_desc *sg = &c->common.dptr.sgl; in nvme_tcp_set_sg_host_data()
2428 sg->addr = 0; in nvme_tcp_set_sg_host_data()
2429 sg->length = cpu_to_le32(data_len); in nvme_tcp_set_sg_host_data()
2430 sg->type = (NVME_TRANSPORT_SGL_DATA_DESC << 4) | in nvme_tcp_set_sg_host_data()
2436 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(arg); in nvme_tcp_submit_async_event() local
2437 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_submit_async_event()
2438 struct nvme_tcp_cmd_pdu *pdu = ctrl->async_req.pdu; in nvme_tcp_submit_async_event()
2439 struct nvme_command *cmd = &pdu->cmd; in nvme_tcp_submit_async_event()
2443 pdu->hdr.type = nvme_tcp_cmd; in nvme_tcp_submit_async_event()
2444 if (queue->hdr_digest) in nvme_tcp_submit_async_event()
2445 pdu->hdr.flags |= NVME_TCP_F_HDGST; in nvme_tcp_submit_async_event()
2446 pdu->hdr.hlen = sizeof(*pdu); in nvme_tcp_submit_async_event()
2447 pdu->hdr.plen = cpu_to_le32(pdu->hdr.hlen + hdgst); in nvme_tcp_submit_async_event()
2449 cmd->common.opcode = nvme_admin_async_event; in nvme_tcp_submit_async_event()
2450 cmd->common.command_id = NVME_AQ_BLK_MQ_DEPTH; in nvme_tcp_submit_async_event()
2451 cmd->common.flags |= NVME_CMD_SGL_METABUF; in nvme_tcp_submit_async_event()
2454 ctrl->async_req.state = NVME_TCP_SEND_CMD_PDU; in nvme_tcp_submit_async_event()
2455 ctrl->async_req.offset = 0; in nvme_tcp_submit_async_event()
2456 ctrl->async_req.curr_bio = NULL; in nvme_tcp_submit_async_event()
2457 ctrl->async_req.data_len = 0; in nvme_tcp_submit_async_event()
2459 nvme_tcp_queue_request(&ctrl->async_req, true, true); in nvme_tcp_submit_async_event()
2465 struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl; in nvme_tcp_complete_timed_out() local
2467 nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue)); in nvme_tcp_complete_timed_out()
2474 struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl; in nvme_tcp_timeout() local
2476 struct nvme_command *cmd = &pdu->cmd; in nvme_tcp_timeout()
2477 int qid = nvme_tcp_queue_id(req->queue); in nvme_tcp_timeout()
2479 dev_warn(ctrl->device, in nvme_tcp_timeout()
2481 rq->tag, nvme_cid(rq), pdu->hdr.type, cmd->common.opcode, in nvme_tcp_timeout()
2484 if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE) { in nvme_tcp_timeout()
2489 * - ctrl disable/shutdown fabrics requests in nvme_tcp_timeout()
2490 * - connect requests in nvme_tcp_timeout()
2491 * - initialization admin requests in nvme_tcp_timeout()
2492 * - I/O requests that entered after unquiescing and in nvme_tcp_timeout()
2506 nvme_tcp_error_recovery(ctrl); in nvme_tcp_timeout()
2515 struct nvme_command *c = &pdu->cmd; in nvme_tcp_map_data()
2517 c->common.flags |= NVME_CMD_SGL_METABUF; in nvme_tcp_map_data()
2522 req->data_len <= nvme_tcp_inline_data_size(req)) in nvme_tcp_map_data()
2523 nvme_tcp_set_sg_inline(queue, c, req->data_len); in nvme_tcp_map_data()
2525 nvme_tcp_set_sg_host_data(c, req->data_len); in nvme_tcp_map_data()
2535 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_setup_cmd_pdu()
2543 req->state = NVME_TCP_SEND_CMD_PDU; in nvme_tcp_setup_cmd_pdu()
2544 req->status = cpu_to_le16(NVME_SC_SUCCESS); in nvme_tcp_setup_cmd_pdu()
2545 req->offset = 0; in nvme_tcp_setup_cmd_pdu()
2546 req->data_sent = 0; in nvme_tcp_setup_cmd_pdu()
2547 req->pdu_len = 0; in nvme_tcp_setup_cmd_pdu()
2548 req->pdu_sent = 0; in nvme_tcp_setup_cmd_pdu()
2549 req->h2cdata_left = 0; in nvme_tcp_setup_cmd_pdu()
2550 req->data_len = blk_rq_nr_phys_segments(rq) ? in nvme_tcp_setup_cmd_pdu()
2552 req->curr_bio = rq->bio; in nvme_tcp_setup_cmd_pdu()
2553 if (req->curr_bio && req->data_len) in nvme_tcp_setup_cmd_pdu()
2557 req->data_len <= nvme_tcp_inline_data_size(req)) in nvme_tcp_setup_cmd_pdu()
2558 req->pdu_len = req->data_len; in nvme_tcp_setup_cmd_pdu()
2560 pdu->hdr.type = nvme_tcp_cmd; in nvme_tcp_setup_cmd_pdu()
2561 pdu->hdr.flags = 0; in nvme_tcp_setup_cmd_pdu()
2562 if (queue->hdr_digest) in nvme_tcp_setup_cmd_pdu()
2563 pdu->hdr.flags |= NVME_TCP_F_HDGST; in nvme_tcp_setup_cmd_pdu()
2564 if (queue->data_digest && req->pdu_len) { in nvme_tcp_setup_cmd_pdu()
2565 pdu->hdr.flags |= NVME_TCP_F_DDGST; in nvme_tcp_setup_cmd_pdu()
2568 pdu->hdr.hlen = sizeof(*pdu); in nvme_tcp_setup_cmd_pdu()
2569 pdu->hdr.pdo = req->pdu_len ? pdu->hdr.hlen + hdgst : 0; in nvme_tcp_setup_cmd_pdu()
2570 pdu->hdr.plen = in nvme_tcp_setup_cmd_pdu()
2571 cpu_to_le32(pdu->hdr.hlen + hdgst + req->pdu_len + ddgst); in nvme_tcp_setup_cmd_pdu()
2576 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_setup_cmd_pdu()
2586 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_commit_rqs()
2588 if (!llist_empty(&queue->req_list)) in nvme_tcp_commit_rqs()
2589 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_commit_rqs()
2595 struct nvme_ns *ns = hctx->queue->queuedata; in nvme_tcp_queue_rq()
2596 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_queue_rq()
2597 struct request *rq = bd->rq; in nvme_tcp_queue_rq()
2599 bool queue_ready = test_bit(NVME_TCP_Q_LIVE, &queue->flags); in nvme_tcp_queue_rq()
2602 if (!nvme_check_ready(&queue->ctrl->ctrl, rq, queue_ready)) in nvme_tcp_queue_rq()
2603 return nvme_fail_nonready_command(&queue->ctrl->ctrl, rq); in nvme_tcp_queue_rq()
2611 nvme_tcp_queue_request(req, true, bd->last); in nvme_tcp_queue_rq()
2618 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(set->driver_data); in nvme_tcp_map_queues() local
2620 nvmf_map_queues(set, &ctrl->ctrl, ctrl->io_queues); in nvme_tcp_map_queues()
2625 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_poll()
2626 struct sock *sk = queue->sock->sk; in nvme_tcp_poll()
2628 if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags)) in nvme_tcp_poll()
2631 set_bit(NVME_TCP_Q_POLLING, &queue->flags); in nvme_tcp_poll()
2632 if (sk_can_busy_loop(sk) && skb_queue_empty_lockless(&sk->sk_receive_queue)) in nvme_tcp_poll()
2635 clear_bit(NVME_TCP_Q_POLLING, &queue->flags); in nvme_tcp_poll()
2636 return queue->nr_cqe; in nvme_tcp_poll()
2639 static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) in nvme_tcp_get_address() argument
2641 struct nvme_tcp_queue *queue = &to_tcp_ctrl(ctrl)->queues[0]; in nvme_tcp_get_address()
2643 int ret, len; in nvme_tcp_get_address() local
2645 len = nvmf_get_address(ctrl, buf, size); in nvme_tcp_get_address()
2647 if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags)) in nvme_tcp_get_address()
2648 return len; in nvme_tcp_get_address()
2650 mutex_lock(&queue->queue_lock); in nvme_tcp_get_address()
2652 ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src_addr); in nvme_tcp_get_address()
2654 if (len > 0) in nvme_tcp_get_address()
2655 len--; /* strip trailing newline */ in nvme_tcp_get_address()
2656 len += scnprintf(buf + len, size - len, "%ssrc_addr=%pISc\n", in nvme_tcp_get_address()
2657 (len) ? "," : "", &src_addr); in nvme_tcp_get_address()
2660 mutex_unlock(&queue->queue_lock); in nvme_tcp_get_address()
2662 return len; in nvme_tcp_get_address()
2704 struct nvme_tcp_ctrl *ctrl; in nvme_tcp_existing_controller() local
2708 list_for_each_entry(ctrl, &nvme_tcp_ctrl_list, list) { in nvme_tcp_existing_controller()
2709 found = nvmf_ip_options_match(&ctrl->ctrl, opts); in nvme_tcp_existing_controller()
2721 struct nvme_tcp_ctrl *ctrl; in nvme_tcp_alloc_ctrl() local
2724 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); in nvme_tcp_alloc_ctrl()
2725 if (!ctrl) in nvme_tcp_alloc_ctrl()
2726 return ERR_PTR(-ENOMEM); in nvme_tcp_alloc_ctrl()
2728 INIT_LIST_HEAD(&ctrl->list); in nvme_tcp_alloc_ctrl()
2729 ctrl->ctrl.opts = opts; in nvme_tcp_alloc_ctrl()
2730 ctrl->ctrl.queue_count = opts->nr_io_queues + opts->nr_write_queues + in nvme_tcp_alloc_ctrl()
2731 opts->nr_poll_queues + 1; in nvme_tcp_alloc_ctrl()
2732 ctrl->ctrl.sqsize = opts->queue_size - 1; in nvme_tcp_alloc_ctrl()
2733 ctrl->ctrl.kato = opts->kato; in nvme_tcp_alloc_ctrl()
2735 INIT_DELAYED_WORK(&ctrl->connect_work, in nvme_tcp_alloc_ctrl()
2737 INIT_WORK(&ctrl->err_work, nvme_tcp_error_recovery_work); in nvme_tcp_alloc_ctrl()
2738 INIT_WORK(&ctrl->ctrl.reset_work, nvme_reset_ctrl_work); in nvme_tcp_alloc_ctrl()
2740 if (!(opts->mask & NVMF_OPT_TRSVCID)) { in nvme_tcp_alloc_ctrl()
2741 opts->trsvcid = in nvme_tcp_alloc_ctrl()
2743 if (!opts->trsvcid) { in nvme_tcp_alloc_ctrl()
2744 ret = -ENOMEM; in nvme_tcp_alloc_ctrl()
2747 opts->mask |= NVMF_OPT_TRSVCID; in nvme_tcp_alloc_ctrl()
2751 opts->traddr, opts->trsvcid, &ctrl->addr); in nvme_tcp_alloc_ctrl()
2754 opts->traddr, opts->trsvcid); in nvme_tcp_alloc_ctrl()
2758 if (opts->mask & NVMF_OPT_HOST_TRADDR) { in nvme_tcp_alloc_ctrl()
2760 opts->host_traddr, NULL, &ctrl->src_addr); in nvme_tcp_alloc_ctrl()
2763 opts->host_traddr); in nvme_tcp_alloc_ctrl()
2768 if (opts->mask & NVMF_OPT_HOST_IFACE) { in nvme_tcp_alloc_ctrl()
2769 if (!__dev_get_by_name(&init_net, opts->host_iface)) { in nvme_tcp_alloc_ctrl()
2771 opts->host_iface); in nvme_tcp_alloc_ctrl()
2772 ret = -ENODEV; in nvme_tcp_alloc_ctrl()
2777 if (!opts->duplicate_connect && nvme_tcp_existing_controller(opts)) { in nvme_tcp_alloc_ctrl()
2778 ret = -EALREADY; in nvme_tcp_alloc_ctrl()
2782 ctrl->queues = kcalloc(ctrl->ctrl.queue_count, sizeof(*ctrl->queues), in nvme_tcp_alloc_ctrl()
2784 if (!ctrl->queues) { in nvme_tcp_alloc_ctrl()
2785 ret = -ENOMEM; in nvme_tcp_alloc_ctrl()
2789 ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_tcp_ctrl_ops, 0); in nvme_tcp_alloc_ctrl()
2793 return ctrl; in nvme_tcp_alloc_ctrl()
2795 kfree(ctrl->queues); in nvme_tcp_alloc_ctrl()
2797 kfree(ctrl); in nvme_tcp_alloc_ctrl()
2804 struct nvme_tcp_ctrl *ctrl; in nvme_tcp_create_ctrl() local
2807 ctrl = nvme_tcp_alloc_ctrl(dev, opts); in nvme_tcp_create_ctrl()
2808 if (IS_ERR(ctrl)) in nvme_tcp_create_ctrl()
2809 return ERR_CAST(ctrl); in nvme_tcp_create_ctrl()
2811 ret = nvme_add_ctrl(&ctrl->ctrl); in nvme_tcp_create_ctrl()
2815 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { in nvme_tcp_create_ctrl()
2817 ret = -EINTR; in nvme_tcp_create_ctrl()
2821 ret = nvme_tcp_setup_ctrl(&ctrl->ctrl, true); in nvme_tcp_create_ctrl()
2825 dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISp, hostnqn: %s\n", in nvme_tcp_create_ctrl()
2826 nvmf_ctrl_subsysnqn(&ctrl->ctrl), &ctrl->addr, opts->host->nqn); in nvme_tcp_create_ctrl()
2829 list_add_tail(&ctrl->list, &nvme_tcp_ctrl_list); in nvme_tcp_create_ctrl()
2832 return &ctrl->ctrl; in nvme_tcp_create_ctrl()
2835 nvme_uninit_ctrl(&ctrl->ctrl); in nvme_tcp_create_ctrl()
2837 nvme_put_ctrl(&ctrl->ctrl); in nvme_tcp_create_ctrl()
2839 ret = -EIO; in nvme_tcp_create_ctrl()
2874 return -ENOMEM; in nvme_tcp_init_module()
2882 struct nvme_tcp_ctrl *ctrl; in nvme_tcp_cleanup_module() local
2887 list_for_each_entry(ctrl, &nvme_tcp_ctrl_list, list) in nvme_tcp_cleanup_module()
2888 nvme_delete_ctrl(&ctrl->ctrl); in nvme_tcp_cleanup_module()