Lines Matching +full:ctrl +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/nvme-tcp.h>
14 #include <linux/blk-mq.h>
25 * A non-zero value being sufficient to indicate general consideration of any
35 * sk_lock -> mmap_lock (page fault) -> fs locks -> sk_lock
36 * because dependencies are tracked for both nvme-tcp and user contexts. Using
37 * a separate class prevents lockdep from conflating nvme-tcp socket use with
38 * user-space socket API use.
45 struct sock *sk = sock->sk; in nvme_tcp_reclassify_socket()
50 switch (sk->sk_family) { in nvme_tcp_reclassify_socket()
52 sock_lock_init_class_and_name(sk, "slock-AF_INET-NVME", in nvme_tcp_reclassify_socket()
54 "sk_lock-AF_INET-NVME", in nvme_tcp_reclassify_socket()
58 sock_lock_init_class_and_name(sk, "slock-AF_INET6-NVME", in nvme_tcp_reclassify_socket()
60 "sk_lock-AF_INET6-NVME", in nvme_tcp_reclassify_socket()
138 struct nvme_tcp_ctrl *ctrl; member
166 struct nvme_ctrl ctrl; member
181 static inline struct nvme_tcp_ctrl *to_tcp_ctrl(struct nvme_ctrl *ctrl) in to_tcp_ctrl() argument
183 return container_of(ctrl, struct nvme_tcp_ctrl, ctrl); in to_tcp_ctrl()
188 return queue - queue->ctrl->queues; in nvme_tcp_queue_id()
196 return queue->ctrl->admin_tag_set.tags[queue_idx]; in nvme_tcp_tagset()
197 return queue->ctrl->tag_set.tags[queue_idx - 1]; in nvme_tcp_tagset()
202 return queue->hdr_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvme_tcp_hdgst_len()
207 return queue->data_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvme_tcp_ddgst_len()
212 if (nvme_is_fabrics(req->req.cmd)) in nvme_tcp_inline_data_size()
214 return req->queue->cmnd_capsule_len - sizeof(struct nvme_command); in nvme_tcp_inline_data_size()
219 return req == &req->queue->ctrl->async_req; in nvme_tcp_async_req()
231 return rq_data_dir(rq) == WRITE && req->data_len && in nvme_tcp_has_inline_data()
232 req->data_len <= nvme_tcp_inline_data_size(req); in nvme_tcp_has_inline_data()
237 return req->iter.bvec->bv_page; in nvme_tcp_req_cur_page()
242 return req->iter.bvec->bv_offset + req->iter.iov_offset; in nvme_tcp_req_cur_offset()
247 return min_t(size_t, iov_iter_single_seg_count(&req->iter), in nvme_tcp_req_cur_length()
248 req->pdu_len - req->pdu_sent); in nvme_tcp_req_cur_length()
254 req->pdu_len - req->pdu_sent : 0; in nvme_tcp_pdu_data_left()
258 int len) in nvme_tcp_pdu_last_send() argument
260 return nvme_tcp_pdu_data_left(req) <= len; in nvme_tcp_pdu_last_send()
272 if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) { in nvme_tcp_init_iter()
273 vec = &rq->special_vec; in nvme_tcp_init_iter()
278 struct bio *bio = req->curr_bio; in nvme_tcp_init_iter()
282 vec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); in nvme_tcp_init_iter()
287 size = bio->bi_iter.bi_size; in nvme_tcp_init_iter()
288 offset = bio->bi_iter.bi_bvec_done; in nvme_tcp_init_iter()
291 iov_iter_bvec(&req->iter, dir, vec, nr_bvec, size); in nvme_tcp_init_iter()
292 req->iter.iov_offset = offset; in nvme_tcp_init_iter()
296 int len) in nvme_tcp_advance_req() argument
298 req->data_sent += len; in nvme_tcp_advance_req()
299 req->pdu_sent += len; in nvme_tcp_advance_req()
300 iov_iter_advance(&req->iter, len); in nvme_tcp_advance_req()
301 if (!iov_iter_count(&req->iter) && in nvme_tcp_advance_req()
302 req->data_sent < req->data_len) { in nvme_tcp_advance_req()
303 req->curr_bio = req->curr_bio->bi_next; in nvme_tcp_advance_req()
320 return !list_empty(&queue->send_list) || in nvme_tcp_queue_more()
321 !llist_empty(&queue->req_list); in nvme_tcp_queue_more()
327 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_queue_request()
330 empty = llist_add(&req->lentry, &queue->req_list) && in nvme_tcp_queue_request()
331 list_empty(&queue->send_list) && !queue->request; in nvme_tcp_queue_request()
338 if (queue->io_cpu == raw_smp_processor_id() && in nvme_tcp_queue_request()
339 sync && empty && mutex_trylock(&queue->send_mutex)) { in nvme_tcp_queue_request()
341 mutex_unlock(&queue->send_mutex); in nvme_tcp_queue_request()
345 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_queue_request()
353 for (node = llist_del_all(&queue->req_list); node; node = node->next) { in nvme_tcp_process_req_list()
355 list_add(&req->entry, &queue->send_list); in nvme_tcp_process_req_list()
364 req = list_first_entry_or_null(&queue->send_list, in nvme_tcp_fetch_request()
368 req = list_first_entry_or_null(&queue->send_list, in nvme_tcp_fetch_request()
374 list_del(&req->entry); in nvme_tcp_fetch_request()
386 struct page *page, off_t off, size_t len) in nvme_tcp_ddgst_update() argument
391 sg_set_page(&sg, page, len, off); in nvme_tcp_ddgst_update()
392 ahash_request_set_crypt(hash, &sg, NULL, len); in nvme_tcp_ddgst_update()
397 void *pdu, size_t len) in nvme_tcp_hdgst() argument
401 sg_init_one(&sg, pdu, len); in nvme_tcp_hdgst()
402 ahash_request_set_crypt(hash, &sg, pdu + len, len); in nvme_tcp_hdgst()
413 if (unlikely(!(hdr->flags & NVME_TCP_F_HDGST))) { in nvme_tcp_verify_hdgst()
414 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_verify_hdgst()
417 return -EPROTO; in nvme_tcp_verify_hdgst()
420 recv_digest = *(__le32 *)(pdu + hdr->hlen); in nvme_tcp_verify_hdgst()
421 nvme_tcp_hdgst(queue->rcv_hash, pdu, pdu_len); in nvme_tcp_verify_hdgst()
422 exp_digest = *(__le32 *)(pdu + hdr->hlen); in nvme_tcp_verify_hdgst()
424 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_verify_hdgst()
427 return -EIO; in nvme_tcp_verify_hdgst()
437 u32 len; in nvme_tcp_check_ddgst() local
439 len = le32_to_cpu(hdr->plen) - hdr->hlen - in nvme_tcp_check_ddgst()
440 ((hdr->flags & NVME_TCP_F_HDGST) ? digest_len : 0); in nvme_tcp_check_ddgst()
442 if (unlikely(len && !(hdr->flags & NVME_TCP_F_DDGST))) { in nvme_tcp_check_ddgst()
443 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_check_ddgst()
446 return -EPROTO; in nvme_tcp_check_ddgst()
448 crypto_ahash_init(queue->rcv_hash); in nvme_tcp_check_ddgst()
458 page_frag_free(req->pdu); in nvme_tcp_exit_request()
465 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(set->driver_data); in nvme_tcp_init_request() local
468 int queue_idx = (set == &ctrl->tag_set) ? hctx_idx + 1 : 0; in nvme_tcp_init_request()
469 struct nvme_tcp_queue *queue = &ctrl->queues[queue_idx]; in nvme_tcp_init_request()
472 req->pdu = page_frag_alloc(&queue->pf_cache, in nvme_tcp_init_request()
475 if (!req->pdu) in nvme_tcp_init_request()
476 return -ENOMEM; in nvme_tcp_init_request()
478 pdu = req->pdu; in nvme_tcp_init_request()
479 req->queue = queue; in nvme_tcp_init_request()
480 nvme_req(rq)->ctrl = &ctrl->ctrl; in nvme_tcp_init_request()
481 nvme_req(rq)->cmd = &pdu->cmd; in nvme_tcp_init_request()
489 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(data); in nvme_tcp_init_hctx() local
490 struct nvme_tcp_queue *queue = &ctrl->queues[hctx_idx + 1]; in nvme_tcp_init_hctx()
492 hctx->driver_data = queue; in nvme_tcp_init_hctx()
499 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(data); in nvme_tcp_init_admin_hctx() local
500 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_init_admin_hctx()
502 hctx->driver_data = queue; in nvme_tcp_init_admin_hctx()
509 return (queue->pdu_remaining) ? NVME_TCP_RECV_PDU : in nvme_tcp_recv_state()
510 (queue->ddgst_remaining) ? NVME_TCP_RECV_DDGST : in nvme_tcp_recv_state()
516 queue->pdu_remaining = sizeof(struct nvme_tcp_rsp_pdu) + in nvme_tcp_init_recv_ctx()
518 queue->pdu_offset = 0; in nvme_tcp_init_recv_ctx()
519 queue->data_remaining = -1; in nvme_tcp_init_recv_ctx()
520 queue->ddgst_remaining = 0; in nvme_tcp_init_recv_ctx()
523 static void nvme_tcp_error_recovery(struct nvme_ctrl *ctrl) in nvme_tcp_error_recovery() argument
525 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING)) in nvme_tcp_error_recovery()
528 dev_warn(ctrl->device, "starting error recovery\n"); in nvme_tcp_error_recovery()
529 queue_work(nvme_reset_wq, &to_tcp_ctrl(ctrl)->err_work); in nvme_tcp_error_recovery()
538 rq = nvme_find_rq(nvme_tcp_tagset(queue), cqe->command_id); in nvme_tcp_process_nvme_cqe()
540 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_process_nvme_cqe()
542 cqe->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_process_nvme_cqe()
543 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_process_nvme_cqe()
544 return -EINVAL; in nvme_tcp_process_nvme_cqe()
548 if (req->status == cpu_to_le16(NVME_SC_SUCCESS)) in nvme_tcp_process_nvme_cqe()
549 req->status = cqe->status; in nvme_tcp_process_nvme_cqe()
551 if (!nvme_try_complete_req(rq, req->status, cqe->result)) in nvme_tcp_process_nvme_cqe()
553 queue->nr_cqe++; in nvme_tcp_process_nvme_cqe()
563 rq = nvme_find_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_handle_c2h_data()
565 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
567 pdu->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_handle_c2h_data()
568 return -ENOENT; in nvme_tcp_handle_c2h_data()
572 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
574 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_handle_c2h_data()
575 return -EIO; in nvme_tcp_handle_c2h_data()
578 queue->data_remaining = le32_to_cpu(pdu->data_length); in nvme_tcp_handle_c2h_data()
580 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS && in nvme_tcp_handle_c2h_data()
581 unlikely(!(pdu->hdr.flags & NVME_TCP_F_DATA_LAST))) { in nvme_tcp_handle_c2h_data()
582 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
584 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_handle_c2h_data()
585 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_handle_c2h_data()
586 return -EPROTO; in nvme_tcp_handle_c2h_data()
595 struct nvme_completion *cqe = &pdu->cqe; in nvme_tcp_handle_comp()
605 cqe->command_id))) in nvme_tcp_handle_comp()
606 nvme_complete_async_event(&queue->ctrl->ctrl, cqe->status, in nvme_tcp_handle_comp()
607 &cqe->result); in nvme_tcp_handle_comp()
616 struct nvme_tcp_data_pdu *data = req->pdu; in nvme_tcp_setup_h2c_data_pdu()
617 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_setup_h2c_data_pdu()
619 u32 h2cdata_sent = req->pdu_len; in nvme_tcp_setup_h2c_data_pdu()
623 req->state = NVME_TCP_SEND_H2C_PDU; in nvme_tcp_setup_h2c_data_pdu()
624 req->offset = 0; in nvme_tcp_setup_h2c_data_pdu()
625 req->pdu_len = min(req->h2cdata_left, queue->maxh2cdata); in nvme_tcp_setup_h2c_data_pdu()
626 req->pdu_sent = 0; in nvme_tcp_setup_h2c_data_pdu()
627 req->h2cdata_left -= req->pdu_len; in nvme_tcp_setup_h2c_data_pdu()
628 req->h2cdata_offset += h2cdata_sent; in nvme_tcp_setup_h2c_data_pdu()
631 data->hdr.type = nvme_tcp_h2c_data; in nvme_tcp_setup_h2c_data_pdu()
632 if (!req->h2cdata_left) in nvme_tcp_setup_h2c_data_pdu()
633 data->hdr.flags = NVME_TCP_F_DATA_LAST; in nvme_tcp_setup_h2c_data_pdu()
634 if (queue->hdr_digest) in nvme_tcp_setup_h2c_data_pdu()
635 data->hdr.flags |= NVME_TCP_F_HDGST; in nvme_tcp_setup_h2c_data_pdu()
636 if (queue->data_digest) in nvme_tcp_setup_h2c_data_pdu()
637 data->hdr.flags |= NVME_TCP_F_DDGST; in nvme_tcp_setup_h2c_data_pdu()
638 data->hdr.hlen = sizeof(*data); in nvme_tcp_setup_h2c_data_pdu()
639 data->hdr.pdo = data->hdr.hlen + hdgst; in nvme_tcp_setup_h2c_data_pdu()
640 data->hdr.plen = in nvme_tcp_setup_h2c_data_pdu()
641 cpu_to_le32(data->hdr.hlen + hdgst + req->pdu_len + ddgst); in nvme_tcp_setup_h2c_data_pdu()
642 data->ttag = req->ttag; in nvme_tcp_setup_h2c_data_pdu()
643 data->command_id = nvme_cid(rq); in nvme_tcp_setup_h2c_data_pdu()
644 data->data_offset = cpu_to_le32(req->h2cdata_offset); in nvme_tcp_setup_h2c_data_pdu()
645 data->data_length = cpu_to_le32(req->pdu_len); in nvme_tcp_setup_h2c_data_pdu()
653 u32 r2t_length = le32_to_cpu(pdu->r2t_length); in nvme_tcp_handle_r2t()
654 u32 r2t_offset = le32_to_cpu(pdu->r2t_offset); in nvme_tcp_handle_r2t()
656 rq = nvme_find_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_handle_r2t()
658 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
660 pdu->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_handle_r2t()
661 return -ENOENT; in nvme_tcp_handle_r2t()
666 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
667 "req %d r2t len is %u, probably a bug...\n", in nvme_tcp_handle_r2t()
668 rq->tag, r2t_length); in nvme_tcp_handle_r2t()
669 return -EPROTO; in nvme_tcp_handle_r2t()
672 if (unlikely(req->data_sent + r2t_length > req->data_len)) { in nvme_tcp_handle_r2t()
673 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
674 "req %d r2t len %u exceeded data len %u (%zu sent)\n", in nvme_tcp_handle_r2t()
675 rq->tag, r2t_length, req->data_len, req->data_sent); in nvme_tcp_handle_r2t()
676 return -EPROTO; in nvme_tcp_handle_r2t()
679 if (unlikely(r2t_offset < req->data_sent)) { in nvme_tcp_handle_r2t()
680 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
682 rq->tag, r2t_offset, req->data_sent); in nvme_tcp_handle_r2t()
683 return -EPROTO; in nvme_tcp_handle_r2t()
686 req->pdu_len = 0; in nvme_tcp_handle_r2t()
687 req->h2cdata_left = r2t_length; in nvme_tcp_handle_r2t()
688 req->h2cdata_offset = r2t_offset; in nvme_tcp_handle_r2t()
689 req->ttag = pdu->ttag; in nvme_tcp_handle_r2t()
698 unsigned int *offset, size_t *len) in nvme_tcp_recv_pdu() argument
701 char *pdu = queue->pdu; in nvme_tcp_recv_pdu()
702 size_t rcv_len = min_t(size_t, *len, queue->pdu_remaining); in nvme_tcp_recv_pdu()
706 &pdu[queue->pdu_offset], rcv_len); in nvme_tcp_recv_pdu()
710 queue->pdu_remaining -= rcv_len; in nvme_tcp_recv_pdu()
711 queue->pdu_offset += rcv_len; in nvme_tcp_recv_pdu()
713 *len -= rcv_len; in nvme_tcp_recv_pdu()
714 if (queue->pdu_remaining) in nvme_tcp_recv_pdu()
717 hdr = queue->pdu; in nvme_tcp_recv_pdu()
718 if (queue->hdr_digest) { in nvme_tcp_recv_pdu()
719 ret = nvme_tcp_verify_hdgst(queue, queue->pdu, hdr->hlen); in nvme_tcp_recv_pdu()
725 if (queue->data_digest) { in nvme_tcp_recv_pdu()
726 ret = nvme_tcp_check_ddgst(queue, queue->pdu); in nvme_tcp_recv_pdu()
731 switch (hdr->type) { in nvme_tcp_recv_pdu()
733 return nvme_tcp_handle_c2h_data(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
736 return nvme_tcp_handle_comp(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
739 return nvme_tcp_handle_r2t(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
741 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_pdu()
742 "unsupported pdu type (%d)\n", hdr->type); in nvme_tcp_recv_pdu()
743 return -EINVAL; in nvme_tcp_recv_pdu()
756 unsigned int *offset, size_t *len) in nvme_tcp_recv_data() argument
758 struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu; in nvme_tcp_recv_data()
760 nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_recv_data()
766 recv_len = min_t(size_t, *len, queue->data_remaining); in nvme_tcp_recv_data()
770 if (!iov_iter_count(&req->iter)) { in nvme_tcp_recv_data()
771 req->curr_bio = req->curr_bio->bi_next; in nvme_tcp_recv_data()
777 if (!req->curr_bio) { in nvme_tcp_recv_data()
778 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_data()
780 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_recv_data()
782 return -EIO; in nvme_tcp_recv_data()
789 iov_iter_count(&req->iter)); in nvme_tcp_recv_data()
791 if (queue->data_digest) in nvme_tcp_recv_data()
793 &req->iter, recv_len, queue->rcv_hash); in nvme_tcp_recv_data()
796 &req->iter, recv_len); in nvme_tcp_recv_data()
798 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_data()
800 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_recv_data()
804 *len -= recv_len; in nvme_tcp_recv_data()
806 queue->data_remaining -= recv_len; in nvme_tcp_recv_data()
809 if (!queue->data_remaining) { in nvme_tcp_recv_data()
810 if (queue->data_digest) { in nvme_tcp_recv_data()
811 nvme_tcp_ddgst_final(queue->rcv_hash, &queue->exp_ddgst); in nvme_tcp_recv_data()
812 queue->ddgst_remaining = NVME_TCP_DIGEST_LENGTH; in nvme_tcp_recv_data()
814 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) { in nvme_tcp_recv_data()
816 le16_to_cpu(req->status)); in nvme_tcp_recv_data()
817 queue->nr_cqe++; in nvme_tcp_recv_data()
827 struct sk_buff *skb, unsigned int *offset, size_t *len) in nvme_tcp_recv_ddgst() argument
829 struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu; in nvme_tcp_recv_ddgst()
830 char *ddgst = (char *)&queue->recv_ddgst; in nvme_tcp_recv_ddgst()
831 size_t recv_len = min_t(size_t, *len, queue->ddgst_remaining); in nvme_tcp_recv_ddgst()
832 off_t off = NVME_TCP_DIGEST_LENGTH - queue->ddgst_remaining; in nvme_tcp_recv_ddgst()
839 queue->ddgst_remaining -= recv_len; in nvme_tcp_recv_ddgst()
841 *len -= recv_len; in nvme_tcp_recv_ddgst()
842 if (queue->ddgst_remaining) in nvme_tcp_recv_ddgst()
845 if (queue->recv_ddgst != queue->exp_ddgst) { in nvme_tcp_recv_ddgst()
847 pdu->command_id); in nvme_tcp_recv_ddgst()
850 req->status = cpu_to_le16(NVME_SC_DATA_XFER_ERROR); in nvme_tcp_recv_ddgst()
852 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_ddgst()
854 le32_to_cpu(queue->recv_ddgst), in nvme_tcp_recv_ddgst()
855 le32_to_cpu(queue->exp_ddgst)); in nvme_tcp_recv_ddgst()
858 if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) { in nvme_tcp_recv_ddgst()
860 pdu->command_id); in nvme_tcp_recv_ddgst()
863 nvme_tcp_end_request(rq, le16_to_cpu(req->status)); in nvme_tcp_recv_ddgst()
864 queue->nr_cqe++; in nvme_tcp_recv_ddgst()
872 unsigned int offset, size_t len) in nvme_tcp_recv_skb() argument
874 struct nvme_tcp_queue *queue = desc->arg.data; in nvme_tcp_recv_skb()
875 size_t consumed = len; in nvme_tcp_recv_skb()
878 while (len) { in nvme_tcp_recv_skb()
881 result = nvme_tcp_recv_pdu(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
884 result = nvme_tcp_recv_data(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
887 result = nvme_tcp_recv_ddgst(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
890 result = -EFAULT; in nvme_tcp_recv_skb()
893 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_skb()
895 queue->rd_enabled = false; in nvme_tcp_recv_skb()
896 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_recv_skb()
908 read_lock_bh(&sk->sk_callback_lock); in nvme_tcp_data_ready()
909 queue = sk->sk_user_data; in nvme_tcp_data_ready()
910 if (likely(queue && queue->rd_enabled) && in nvme_tcp_data_ready()
911 !test_bit(NVME_TCP_Q_POLLING, &queue->flags)) in nvme_tcp_data_ready()
912 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_data_ready()
913 read_unlock_bh(&sk->sk_callback_lock); in nvme_tcp_data_ready()
920 read_lock_bh(&sk->sk_callback_lock); in nvme_tcp_write_space()
921 queue = sk->sk_user_data; in nvme_tcp_write_space()
923 clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags); in nvme_tcp_write_space()
924 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_write_space()
926 read_unlock_bh(&sk->sk_callback_lock); in nvme_tcp_write_space()
933 read_lock_bh(&sk->sk_callback_lock); in nvme_tcp_state_change()
934 queue = sk->sk_user_data; in nvme_tcp_state_change()
938 switch (sk->sk_state) { in nvme_tcp_state_change()
944 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_state_change()
947 dev_info(queue->ctrl->ctrl.device, in nvme_tcp_state_change()
949 nvme_tcp_queue_id(queue), sk->sk_state); in nvme_tcp_state_change()
952 queue->state_change(sk); in nvme_tcp_state_change()
954 read_unlock_bh(&sk->sk_callback_lock); in nvme_tcp_state_change()
959 queue->request = NULL; in nvme_tcp_done_send_req()
967 nvme_complete_async_event(&req->queue->ctrl->ctrl, in nvme_tcp_fail_request()
977 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_data()
978 int req_data_len = req->data_len; in nvme_tcp_try_send_data()
979 u32 h2cdata_left = req->h2cdata_left; in nvme_tcp_try_send_data()
984 size_t len = nvme_tcp_req_cur_length(req); in nvme_tcp_try_send_data() local
985 bool last = nvme_tcp_pdu_last_send(req, len); in nvme_tcp_try_send_data()
986 int req_data_sent = req->data_sent; in nvme_tcp_try_send_data()
989 if (last && !queue->data_digest && !nvme_tcp_queue_more(queue)) in nvme_tcp_try_send_data()
995 ret = kernel_sendpage(queue->sock, page, offset, len, in nvme_tcp_try_send_data()
998 ret = sock_no_sendpage(queue->sock, page, offset, len, in nvme_tcp_try_send_data()
1004 if (queue->data_digest) in nvme_tcp_try_send_data()
1005 nvme_tcp_ddgst_update(queue->snd_hash, page, in nvme_tcp_try_send_data()
1017 if (last && ret == len) { in nvme_tcp_try_send_data()
1018 if (queue->data_digest) { in nvme_tcp_try_send_data()
1019 nvme_tcp_ddgst_final(queue->snd_hash, in nvme_tcp_try_send_data()
1020 &req->ddgst); in nvme_tcp_try_send_data()
1021 req->state = NVME_TCP_SEND_DDGST; in nvme_tcp_try_send_data()
1022 req->offset = 0; in nvme_tcp_try_send_data()
1032 return -EAGAIN; in nvme_tcp_try_send_data()
1037 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_cmd_pdu()
1038 struct nvme_tcp_cmd_pdu *pdu = req->pdu; in nvme_tcp_try_send_cmd_pdu()
1041 int len = sizeof(*pdu) + hdgst - req->offset; in nvme_tcp_try_send_cmd_pdu() local
1050 if (queue->hdr_digest && !req->offset) in nvme_tcp_try_send_cmd_pdu()
1051 nvme_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvme_tcp_try_send_cmd_pdu()
1053 ret = kernel_sendpage(queue->sock, virt_to_page(pdu), in nvme_tcp_try_send_cmd_pdu()
1054 offset_in_page(pdu) + req->offset, len, flags); in nvme_tcp_try_send_cmd_pdu()
1058 len -= ret; in nvme_tcp_try_send_cmd_pdu()
1059 if (!len) { in nvme_tcp_try_send_cmd_pdu()
1061 req->state = NVME_TCP_SEND_DATA; in nvme_tcp_try_send_cmd_pdu()
1062 if (queue->data_digest) in nvme_tcp_try_send_cmd_pdu()
1063 crypto_ahash_init(queue->snd_hash); in nvme_tcp_try_send_cmd_pdu()
1069 req->offset += ret; in nvme_tcp_try_send_cmd_pdu()
1071 return -EAGAIN; in nvme_tcp_try_send_cmd_pdu()
1076 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_data_pdu()
1077 struct nvme_tcp_data_pdu *pdu = req->pdu; in nvme_tcp_try_send_data_pdu()
1079 int len = sizeof(*pdu) - req->offset + hdgst; in nvme_tcp_try_send_data_pdu() local
1082 if (queue->hdr_digest && !req->offset) in nvme_tcp_try_send_data_pdu()
1083 nvme_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvme_tcp_try_send_data_pdu()
1085 if (!req->h2cdata_left) in nvme_tcp_try_send_data_pdu()
1086 ret = kernel_sendpage(queue->sock, virt_to_page(pdu), in nvme_tcp_try_send_data_pdu()
1087 offset_in_page(pdu) + req->offset, len, in nvme_tcp_try_send_data_pdu()
1090 ret = sock_no_sendpage(queue->sock, virt_to_page(pdu), in nvme_tcp_try_send_data_pdu()
1091 offset_in_page(pdu) + req->offset, len, in nvme_tcp_try_send_data_pdu()
1096 len -= ret; in nvme_tcp_try_send_data_pdu()
1097 if (!len) { in nvme_tcp_try_send_data_pdu()
1098 req->state = NVME_TCP_SEND_DATA; in nvme_tcp_try_send_data_pdu()
1099 if (queue->data_digest) in nvme_tcp_try_send_data_pdu()
1100 crypto_ahash_init(queue->snd_hash); in nvme_tcp_try_send_data_pdu()
1103 req->offset += ret; in nvme_tcp_try_send_data_pdu()
1105 return -EAGAIN; in nvme_tcp_try_send_data_pdu()
1110 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_ddgst()
1111 size_t offset = req->offset; in nvme_tcp_try_send_ddgst()
1112 u32 h2cdata_left = req->h2cdata_left; in nvme_tcp_try_send_ddgst()
1116 .iov_base = (u8 *)&req->ddgst + req->offset, in nvme_tcp_try_send_ddgst()
1117 .iov_len = NVME_TCP_DIGEST_LENGTH - req->offset in nvme_tcp_try_send_ddgst()
1125 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvme_tcp_try_send_ddgst()
1137 req->offset += ret; in nvme_tcp_try_send_ddgst()
1138 return -EAGAIN; in nvme_tcp_try_send_ddgst()
1147 if (!queue->request) { in nvme_tcp_try_send()
1148 queue->request = nvme_tcp_fetch_request(queue); in nvme_tcp_try_send()
1149 if (!queue->request) in nvme_tcp_try_send()
1152 req = queue->request; in nvme_tcp_try_send()
1155 if (req->state == NVME_TCP_SEND_CMD_PDU) { in nvme_tcp_try_send()
1163 if (req->state == NVME_TCP_SEND_H2C_PDU) { in nvme_tcp_try_send()
1169 if (req->state == NVME_TCP_SEND_DATA) { in nvme_tcp_try_send()
1175 if (req->state == NVME_TCP_SEND_DDGST) in nvme_tcp_try_send()
1178 if (ret == -EAGAIN) { in nvme_tcp_try_send()
1181 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_try_send()
1183 nvme_tcp_fail_request(queue->request); in nvme_tcp_try_send()
1193 struct socket *sock = queue->sock; in nvme_tcp_try_recv()
1194 struct sock *sk = sock->sk; in nvme_tcp_try_recv()
1201 queue->nr_cqe = 0; in nvme_tcp_try_recv()
1202 consumed = sock->ops->read_sock(sk, &rd_desc, nvme_tcp_recv_skb); in nvme_tcp_try_recv()
1217 if (mutex_trylock(&queue->send_mutex)) { in nvme_tcp_io_work()
1219 mutex_unlock(&queue->send_mutex); in nvme_tcp_io_work()
1232 if (!pending || !queue->rd_enabled) in nvme_tcp_io_work()
1237 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_io_work()
1242 struct crypto_ahash *tfm = crypto_ahash_reqtfm(queue->rcv_hash); in nvme_tcp_free_crypto()
1244 ahash_request_free(queue->rcv_hash); in nvme_tcp_free_crypto()
1245 ahash_request_free(queue->snd_hash); in nvme_tcp_free_crypto()
1257 queue->snd_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvme_tcp_alloc_crypto()
1258 if (!queue->snd_hash) in nvme_tcp_alloc_crypto()
1260 ahash_request_set_callback(queue->snd_hash, 0, NULL, NULL); in nvme_tcp_alloc_crypto()
1262 queue->rcv_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvme_tcp_alloc_crypto()
1263 if (!queue->rcv_hash) in nvme_tcp_alloc_crypto()
1265 ahash_request_set_callback(queue->rcv_hash, 0, NULL, NULL); in nvme_tcp_alloc_crypto()
1269 ahash_request_free(queue->snd_hash); in nvme_tcp_alloc_crypto()
1272 return -ENOMEM; in nvme_tcp_alloc_crypto()
1275 static void nvme_tcp_free_async_req(struct nvme_tcp_ctrl *ctrl) in nvme_tcp_free_async_req() argument
1277 struct nvme_tcp_request *async = &ctrl->async_req; in nvme_tcp_free_async_req()
1279 page_frag_free(async->pdu); in nvme_tcp_free_async_req()
1282 static int nvme_tcp_alloc_async_req(struct nvme_tcp_ctrl *ctrl) in nvme_tcp_alloc_async_req() argument
1284 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_alloc_async_req()
1285 struct nvme_tcp_request *async = &ctrl->async_req; in nvme_tcp_alloc_async_req()
1288 async->pdu = page_frag_alloc(&queue->pf_cache, in nvme_tcp_alloc_async_req()
1291 if (!async->pdu) in nvme_tcp_alloc_async_req()
1292 return -ENOMEM; in nvme_tcp_alloc_async_req()
1294 async->queue = &ctrl->queues[0]; in nvme_tcp_alloc_async_req()
1301 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_free_queue() local
1302 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_free_queue()
1305 if (!test_and_clear_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) in nvme_tcp_free_queue()
1308 if (queue->hdr_digest || queue->data_digest) in nvme_tcp_free_queue()
1311 if (queue->pf_cache.va) { in nvme_tcp_free_queue()
1312 page = virt_to_head_page(queue->pf_cache.va); in nvme_tcp_free_queue()
1313 __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); in nvme_tcp_free_queue()
1314 queue->pf_cache.va = NULL; in nvme_tcp_free_queue()
1318 sock_release(queue->sock); in nvme_tcp_free_queue()
1321 kfree(queue->pdu); in nvme_tcp_free_queue()
1322 mutex_destroy(&queue->send_mutex); in nvme_tcp_free_queue()
1323 mutex_destroy(&queue->queue_lock); in nvme_tcp_free_queue()
1338 return -ENOMEM; in nvme_tcp_init_connection()
1342 ret = -ENOMEM; in nvme_tcp_init_connection()
1346 icreq->hdr.type = nvme_tcp_icreq; in nvme_tcp_init_connection()
1347 icreq->hdr.hlen = sizeof(*icreq); in nvme_tcp_init_connection()
1348 icreq->hdr.pdo = 0; in nvme_tcp_init_connection()
1349 icreq->hdr.plen = cpu_to_le32(icreq->hdr.hlen); in nvme_tcp_init_connection()
1350 icreq->pfv = cpu_to_le16(NVME_TCP_PFV_1_0); in nvme_tcp_init_connection()
1351 icreq->maxr2t = 0; /* single inflight r2t supported */ in nvme_tcp_init_connection()
1352 icreq->hpda = 0; /* no alignment constraint */ in nvme_tcp_init_connection()
1353 if (queue->hdr_digest) in nvme_tcp_init_connection()
1354 icreq->digest |= NVME_TCP_HDR_DIGEST_ENABLE; in nvme_tcp_init_connection()
1355 if (queue->data_digest) in nvme_tcp_init_connection()
1356 icreq->digest |= NVME_TCP_DATA_DIGEST_ENABLE; in nvme_tcp_init_connection()
1360 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvme_tcp_init_connection()
1367 ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvme_tcp_init_connection()
1372 ret = -EINVAL; in nvme_tcp_init_connection()
1373 if (icresp->hdr.type != nvme_tcp_icresp) { in nvme_tcp_init_connection()
1375 nvme_tcp_queue_id(queue), icresp->hdr.type); in nvme_tcp_init_connection()
1379 if (le32_to_cpu(icresp->hdr.plen) != sizeof(*icresp)) { in nvme_tcp_init_connection()
1381 nvme_tcp_queue_id(queue), icresp->hdr.plen); in nvme_tcp_init_connection()
1385 if (icresp->pfv != NVME_TCP_PFV_1_0) { in nvme_tcp_init_connection()
1387 nvme_tcp_queue_id(queue), icresp->pfv); in nvme_tcp_init_connection()
1391 ctrl_ddgst = !!(icresp->digest & NVME_TCP_DATA_DIGEST_ENABLE); in nvme_tcp_init_connection()
1392 if ((queue->data_digest && !ctrl_ddgst) || in nvme_tcp_init_connection()
1393 (!queue->data_digest && ctrl_ddgst)) { in nvme_tcp_init_connection()
1394 pr_err("queue %d: data digest mismatch host: %s ctrl: %s\n", in nvme_tcp_init_connection()
1396 queue->data_digest ? "enabled" : "disabled", in nvme_tcp_init_connection()
1401 ctrl_hdgst = !!(icresp->digest & NVME_TCP_HDR_DIGEST_ENABLE); in nvme_tcp_init_connection()
1402 if ((queue->hdr_digest && !ctrl_hdgst) || in nvme_tcp_init_connection()
1403 (!queue->hdr_digest && ctrl_hdgst)) { in nvme_tcp_init_connection()
1404 pr_err("queue %d: header digest mismatch host: %s ctrl: %s\n", in nvme_tcp_init_connection()
1406 queue->hdr_digest ? "enabled" : "disabled", in nvme_tcp_init_connection()
1411 if (icresp->cpda != 0) { in nvme_tcp_init_connection()
1413 nvme_tcp_queue_id(queue), icresp->cpda); in nvme_tcp_init_connection()
1417 maxh2cdata = le32_to_cpu(icresp->maxdata); in nvme_tcp_init_connection()
1423 queue->maxh2cdata = maxh2cdata; in nvme_tcp_init_connection()
1440 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_default_queue() local
1444 qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT]; in nvme_tcp_default_queue()
1449 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_read_queue() local
1454 qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] + in nvme_tcp_read_queue()
1455 ctrl->io_queues[HCTX_TYPE_READ]; in nvme_tcp_read_queue()
1460 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_poll_queue() local
1466 qid < 1 + ctrl->io_queues[HCTX_TYPE_DEFAULT] + in nvme_tcp_poll_queue()
1467 ctrl->io_queues[HCTX_TYPE_READ] + in nvme_tcp_poll_queue()
1468 ctrl->io_queues[HCTX_TYPE_POLL]; in nvme_tcp_poll_queue()
1473 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_set_queue_io_cpu() local
1478 n = qid - 1; in nvme_tcp_set_queue_io_cpu()
1480 n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] - 1; in nvme_tcp_set_queue_io_cpu()
1482 n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] - in nvme_tcp_set_queue_io_cpu()
1483 ctrl->io_queues[HCTX_TYPE_READ] - 1; in nvme_tcp_set_queue_io_cpu()
1484 queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false); in nvme_tcp_set_queue_io_cpu()
1489 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_alloc_queue() local
1490 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_alloc_queue()
1493 mutex_init(&queue->queue_lock); in nvme_tcp_alloc_queue()
1494 queue->ctrl = ctrl; in nvme_tcp_alloc_queue()
1495 init_llist_head(&queue->req_list); in nvme_tcp_alloc_queue()
1496 INIT_LIST_HEAD(&queue->send_list); in nvme_tcp_alloc_queue()
1497 mutex_init(&queue->send_mutex); in nvme_tcp_alloc_queue()
1498 INIT_WORK(&queue->io_work, nvme_tcp_io_work); in nvme_tcp_alloc_queue()
1501 queue->cmnd_capsule_len = nctrl->ioccsz * 16; in nvme_tcp_alloc_queue()
1503 queue->cmnd_capsule_len = sizeof(struct nvme_command) + in nvme_tcp_alloc_queue()
1506 ret = sock_create(ctrl->addr.ss_family, SOCK_STREAM, in nvme_tcp_alloc_queue()
1507 IPPROTO_TCP, &queue->sock); in nvme_tcp_alloc_queue()
1509 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1514 nvme_tcp_reclassify_socket(queue->sock); in nvme_tcp_alloc_queue()
1517 tcp_sock_set_syncnt(queue->sock->sk, 1); in nvme_tcp_alloc_queue()
1520 tcp_sock_set_nodelay(queue->sock->sk); in nvme_tcp_alloc_queue()
1527 sock_no_linger(queue->sock->sk); in nvme_tcp_alloc_queue()
1530 sock_set_priority(queue->sock->sk, so_priority); in nvme_tcp_alloc_queue()
1533 if (nctrl->opts->tos >= 0) in nvme_tcp_alloc_queue()
1534 ip_sock_set_tos(queue->sock->sk, nctrl->opts->tos); in nvme_tcp_alloc_queue()
1537 queue->sock->sk->sk_rcvtimeo = 10 * HZ; in nvme_tcp_alloc_queue()
1539 queue->sock->sk->sk_allocation = GFP_ATOMIC; in nvme_tcp_alloc_queue()
1541 queue->request = NULL; in nvme_tcp_alloc_queue()
1542 queue->data_remaining = 0; in nvme_tcp_alloc_queue()
1543 queue->ddgst_remaining = 0; in nvme_tcp_alloc_queue()
1544 queue->pdu_remaining = 0; in nvme_tcp_alloc_queue()
1545 queue->pdu_offset = 0; in nvme_tcp_alloc_queue()
1546 sk_set_memalloc(queue->sock->sk); in nvme_tcp_alloc_queue()
1548 if (nctrl->opts->mask & NVMF_OPT_HOST_TRADDR) { in nvme_tcp_alloc_queue()
1549 ret = kernel_bind(queue->sock, (struct sockaddr *)&ctrl->src_addr, in nvme_tcp_alloc_queue()
1550 sizeof(ctrl->src_addr)); in nvme_tcp_alloc_queue()
1552 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1559 if (nctrl->opts->mask & NVMF_OPT_HOST_IFACE) { in nvme_tcp_alloc_queue()
1560 char *iface = nctrl->opts->host_iface; in nvme_tcp_alloc_queue()
1563 ret = sock_setsockopt(queue->sock, SOL_SOCKET, SO_BINDTODEVICE, in nvme_tcp_alloc_queue()
1566 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1573 queue->hdr_digest = nctrl->opts->hdr_digest; in nvme_tcp_alloc_queue()
1574 queue->data_digest = nctrl->opts->data_digest; in nvme_tcp_alloc_queue()
1575 if (queue->hdr_digest || queue->data_digest) { in nvme_tcp_alloc_queue()
1578 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1586 queue->pdu = kmalloc(rcv_pdu_size, GFP_KERNEL); in nvme_tcp_alloc_queue()
1587 if (!queue->pdu) { in nvme_tcp_alloc_queue()
1588 ret = -ENOMEM; in nvme_tcp_alloc_queue()
1592 dev_dbg(nctrl->device, "connecting queue %d\n", in nvme_tcp_alloc_queue()
1595 ret = kernel_connect(queue->sock, (struct sockaddr *)&ctrl->addr, in nvme_tcp_alloc_queue()
1596 sizeof(ctrl->addr), 0); in nvme_tcp_alloc_queue()
1598 dev_err(nctrl->device, in nvme_tcp_alloc_queue()
1607 queue->rd_enabled = true; in nvme_tcp_alloc_queue()
1608 set_bit(NVME_TCP_Q_ALLOCATED, &queue->flags); in nvme_tcp_alloc_queue()
1611 write_lock_bh(&queue->sock->sk->sk_callback_lock); in nvme_tcp_alloc_queue()
1612 queue->sock->sk->sk_user_data = queue; in nvme_tcp_alloc_queue()
1613 queue->state_change = queue->sock->sk->sk_state_change; in nvme_tcp_alloc_queue()
1614 queue->data_ready = queue->sock->sk->sk_data_ready; in nvme_tcp_alloc_queue()
1615 queue->write_space = queue->sock->sk->sk_write_space; in nvme_tcp_alloc_queue()
1616 queue->sock->sk->sk_data_ready = nvme_tcp_data_ready; in nvme_tcp_alloc_queue()
1617 queue->sock->sk->sk_state_change = nvme_tcp_state_change; in nvme_tcp_alloc_queue()
1618 queue->sock->sk->sk_write_space = nvme_tcp_write_space; in nvme_tcp_alloc_queue()
1620 queue->sock->sk->sk_ll_usec = 1; in nvme_tcp_alloc_queue()
1622 write_unlock_bh(&queue->sock->sk->sk_callback_lock); in nvme_tcp_alloc_queue()
1627 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvme_tcp_alloc_queue()
1629 kfree(queue->pdu); in nvme_tcp_alloc_queue()
1631 if (queue->hdr_digest || queue->data_digest) in nvme_tcp_alloc_queue()
1634 sock_release(queue->sock); in nvme_tcp_alloc_queue()
1635 queue->sock = NULL; in nvme_tcp_alloc_queue()
1637 mutex_destroy(&queue->send_mutex); in nvme_tcp_alloc_queue()
1638 mutex_destroy(&queue->queue_lock); in nvme_tcp_alloc_queue()
1644 struct socket *sock = queue->sock; in nvme_tcp_restore_sock_calls()
1646 write_lock_bh(&sock->sk->sk_callback_lock); in nvme_tcp_restore_sock_calls()
1647 sock->sk->sk_user_data = NULL; in nvme_tcp_restore_sock_calls()
1648 sock->sk->sk_data_ready = queue->data_ready; in nvme_tcp_restore_sock_calls()
1649 sock->sk->sk_state_change = queue->state_change; in nvme_tcp_restore_sock_calls()
1650 sock->sk->sk_write_space = queue->write_space; in nvme_tcp_restore_sock_calls()
1651 write_unlock_bh(&sock->sk->sk_callback_lock); in nvme_tcp_restore_sock_calls()
1656 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in __nvme_tcp_stop_queue()
1658 cancel_work_sync(&queue->io_work); in __nvme_tcp_stop_queue()
1663 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_stop_queue() local
1664 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_stop_queue()
1666 if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) in nvme_tcp_stop_queue()
1669 mutex_lock(&queue->queue_lock); in nvme_tcp_stop_queue()
1670 if (test_and_clear_bit(NVME_TCP_Q_LIVE, &queue->flags)) in nvme_tcp_stop_queue()
1672 mutex_unlock(&queue->queue_lock); in nvme_tcp_stop_queue()
1677 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_start_queue() local
1686 set_bit(NVME_TCP_Q_LIVE, &ctrl->queues[idx].flags); in nvme_tcp_start_queue()
1688 if (test_bit(NVME_TCP_Q_ALLOCATED, &ctrl->queues[idx].flags)) in nvme_tcp_start_queue()
1689 __nvme_tcp_stop_queue(&ctrl->queues[idx]); in nvme_tcp_start_queue()
1690 dev_err(nctrl->device, in nvme_tcp_start_queue()
1696 static void nvme_tcp_free_admin_queue(struct nvme_ctrl *ctrl) in nvme_tcp_free_admin_queue() argument
1698 if (to_tcp_ctrl(ctrl)->async_req.pdu) { in nvme_tcp_free_admin_queue()
1699 cancel_work_sync(&ctrl->async_event_work); in nvme_tcp_free_admin_queue()
1700 nvme_tcp_free_async_req(to_tcp_ctrl(ctrl)); in nvme_tcp_free_admin_queue()
1701 to_tcp_ctrl(ctrl)->async_req.pdu = NULL; in nvme_tcp_free_admin_queue()
1704 nvme_tcp_free_queue(ctrl, 0); in nvme_tcp_free_admin_queue()
1707 static void nvme_tcp_free_io_queues(struct nvme_ctrl *ctrl) in nvme_tcp_free_io_queues() argument
1711 for (i = 1; i < ctrl->queue_count; i++) in nvme_tcp_free_io_queues()
1712 nvme_tcp_free_queue(ctrl, i); in nvme_tcp_free_io_queues()
1715 static void nvme_tcp_stop_io_queues(struct nvme_ctrl *ctrl) in nvme_tcp_stop_io_queues() argument
1719 for (i = 1; i < ctrl->queue_count; i++) in nvme_tcp_stop_io_queues()
1720 nvme_tcp_stop_queue(ctrl, i); in nvme_tcp_stop_io_queues()
1723 static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl, in nvme_tcp_start_io_queues() argument
1729 ret = nvme_tcp_start_queue(ctrl, i); in nvme_tcp_start_io_queues()
1737 for (i--; i >= first; i--) in nvme_tcp_start_io_queues()
1738 nvme_tcp_stop_queue(ctrl, i); in nvme_tcp_start_io_queues()
1742 static int nvme_tcp_alloc_admin_queue(struct nvme_ctrl *ctrl) in nvme_tcp_alloc_admin_queue() argument
1746 ret = nvme_tcp_alloc_queue(ctrl, 0); in nvme_tcp_alloc_admin_queue()
1750 ret = nvme_tcp_alloc_async_req(to_tcp_ctrl(ctrl)); in nvme_tcp_alloc_admin_queue()
1757 nvme_tcp_free_queue(ctrl, 0); in nvme_tcp_alloc_admin_queue()
1761 static int __nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) in __nvme_tcp_alloc_io_queues() argument
1765 for (i = 1; i < ctrl->queue_count; i++) { in __nvme_tcp_alloc_io_queues()
1766 ret = nvme_tcp_alloc_queue(ctrl, i); in __nvme_tcp_alloc_io_queues()
1774 for (i--; i >= 1; i--) in __nvme_tcp_alloc_io_queues()
1775 nvme_tcp_free_queue(ctrl, i); in __nvme_tcp_alloc_io_queues()
1780 static unsigned int nvme_tcp_nr_io_queues(struct nvme_ctrl *ctrl) in nvme_tcp_nr_io_queues() argument
1784 nr_io_queues = min(ctrl->opts->nr_io_queues, num_online_cpus()); in nvme_tcp_nr_io_queues()
1785 nr_io_queues += min(ctrl->opts->nr_write_queues, num_online_cpus()); in nvme_tcp_nr_io_queues()
1786 nr_io_queues += min(ctrl->opts->nr_poll_queues, num_online_cpus()); in nvme_tcp_nr_io_queues()
1794 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_set_io_queues() local
1795 struct nvmf_ctrl_options *opts = nctrl->opts; in nvme_tcp_set_io_queues()
1797 if (opts->nr_write_queues && opts->nr_io_queues < nr_io_queues) { in nvme_tcp_set_io_queues()
1803 ctrl->io_queues[HCTX_TYPE_READ] = opts->nr_io_queues; in nvme_tcp_set_io_queues()
1804 nr_io_queues -= ctrl->io_queues[HCTX_TYPE_READ]; in nvme_tcp_set_io_queues()
1805 ctrl->io_queues[HCTX_TYPE_DEFAULT] = in nvme_tcp_set_io_queues()
1806 min(opts->nr_write_queues, nr_io_queues); in nvme_tcp_set_io_queues()
1807 nr_io_queues -= ctrl->io_queues[HCTX_TYPE_DEFAULT]; in nvme_tcp_set_io_queues()
1814 ctrl->io_queues[HCTX_TYPE_DEFAULT] = in nvme_tcp_set_io_queues()
1815 min(opts->nr_io_queues, nr_io_queues); in nvme_tcp_set_io_queues()
1816 nr_io_queues -= ctrl->io_queues[HCTX_TYPE_DEFAULT]; in nvme_tcp_set_io_queues()
1819 if (opts->nr_poll_queues && nr_io_queues) { in nvme_tcp_set_io_queues()
1821 ctrl->io_queues[HCTX_TYPE_POLL] = in nvme_tcp_set_io_queues()
1822 min(opts->nr_poll_queues, nr_io_queues); in nvme_tcp_set_io_queues()
1826 static int nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl) in nvme_tcp_alloc_io_queues() argument
1831 nr_io_queues = nvme_tcp_nr_io_queues(ctrl); in nvme_tcp_alloc_io_queues()
1832 ret = nvme_set_queue_count(ctrl, &nr_io_queues); in nvme_tcp_alloc_io_queues()
1837 dev_err(ctrl->device, in nvme_tcp_alloc_io_queues()
1839 return -ENOMEM; in nvme_tcp_alloc_io_queues()
1842 ctrl->queue_count = nr_io_queues + 1; in nvme_tcp_alloc_io_queues()
1843 dev_info(ctrl->device, in nvme_tcp_alloc_io_queues()
1846 nvme_tcp_set_io_queues(ctrl, nr_io_queues); in nvme_tcp_alloc_io_queues()
1848 return __nvme_tcp_alloc_io_queues(ctrl); in nvme_tcp_alloc_io_queues()
1851 static void nvme_tcp_destroy_io_queues(struct nvme_ctrl *ctrl, bool remove) in nvme_tcp_destroy_io_queues() argument
1853 nvme_tcp_stop_io_queues(ctrl); in nvme_tcp_destroy_io_queues()
1855 nvme_remove_io_tag_set(ctrl); in nvme_tcp_destroy_io_queues()
1856 nvme_tcp_free_io_queues(ctrl); in nvme_tcp_destroy_io_queues()
1859 static int nvme_tcp_configure_io_queues(struct nvme_ctrl *ctrl, bool new) in nvme_tcp_configure_io_queues() argument
1863 ret = nvme_tcp_alloc_io_queues(ctrl); in nvme_tcp_configure_io_queues()
1868 ret = nvme_alloc_io_tag_set(ctrl, &to_tcp_ctrl(ctrl)->tag_set, in nvme_tcp_configure_io_queues()
1881 nr_queues = min(ctrl->tagset->nr_hw_queues + 1, ctrl->queue_count); in nvme_tcp_configure_io_queues()
1882 ret = nvme_tcp_start_io_queues(ctrl, 1, nr_queues); in nvme_tcp_configure_io_queues()
1887 nvme_start_queues(ctrl); in nvme_tcp_configure_io_queues()
1888 if (!nvme_wait_freeze_timeout(ctrl, NVME_IO_TIMEOUT)) { in nvme_tcp_configure_io_queues()
1894 ret = -ENODEV; in nvme_tcp_configure_io_queues()
1897 blk_mq_update_nr_hw_queues(ctrl->tagset, in nvme_tcp_configure_io_queues()
1898 ctrl->queue_count - 1); in nvme_tcp_configure_io_queues()
1899 nvme_unfreeze(ctrl); in nvme_tcp_configure_io_queues()
1906 ret = nvme_tcp_start_io_queues(ctrl, nr_queues, in nvme_tcp_configure_io_queues()
1907 ctrl->tagset->nr_hw_queues + 1); in nvme_tcp_configure_io_queues()
1914 nvme_stop_queues(ctrl); in nvme_tcp_configure_io_queues()
1915 nvme_sync_io_queues(ctrl); in nvme_tcp_configure_io_queues()
1916 nvme_tcp_stop_io_queues(ctrl); in nvme_tcp_configure_io_queues()
1918 nvme_cancel_tagset(ctrl); in nvme_tcp_configure_io_queues()
1920 nvme_remove_io_tag_set(ctrl); in nvme_tcp_configure_io_queues()
1922 nvme_tcp_free_io_queues(ctrl); in nvme_tcp_configure_io_queues()
1926 static void nvme_tcp_destroy_admin_queue(struct nvme_ctrl *ctrl, bool remove) in nvme_tcp_destroy_admin_queue() argument
1928 nvme_tcp_stop_queue(ctrl, 0); in nvme_tcp_destroy_admin_queue()
1930 nvme_remove_admin_tag_set(ctrl); in nvme_tcp_destroy_admin_queue()
1931 nvme_tcp_free_admin_queue(ctrl); in nvme_tcp_destroy_admin_queue()
1934 static int nvme_tcp_configure_admin_queue(struct nvme_ctrl *ctrl, bool new) in nvme_tcp_configure_admin_queue() argument
1938 error = nvme_tcp_alloc_admin_queue(ctrl); in nvme_tcp_configure_admin_queue()
1943 error = nvme_alloc_admin_tag_set(ctrl, in nvme_tcp_configure_admin_queue()
1944 &to_tcp_ctrl(ctrl)->admin_tag_set, in nvme_tcp_configure_admin_queue()
1951 error = nvme_tcp_start_queue(ctrl, 0); in nvme_tcp_configure_admin_queue()
1955 error = nvme_enable_ctrl(ctrl); in nvme_tcp_configure_admin_queue()
1959 nvme_start_admin_queue(ctrl); in nvme_tcp_configure_admin_queue()
1961 error = nvme_init_ctrl_finish(ctrl); in nvme_tcp_configure_admin_queue()
1968 nvme_stop_admin_queue(ctrl); in nvme_tcp_configure_admin_queue()
1969 blk_sync_queue(ctrl->admin_q); in nvme_tcp_configure_admin_queue()
1971 nvme_tcp_stop_queue(ctrl, 0); in nvme_tcp_configure_admin_queue()
1972 nvme_cancel_admin_tagset(ctrl); in nvme_tcp_configure_admin_queue()
1975 nvme_remove_admin_tag_set(ctrl); in nvme_tcp_configure_admin_queue()
1977 nvme_tcp_free_admin_queue(ctrl); in nvme_tcp_configure_admin_queue()
1981 static void nvme_tcp_teardown_admin_queue(struct nvme_ctrl *ctrl, in nvme_tcp_teardown_admin_queue() argument
1984 nvme_stop_admin_queue(ctrl); in nvme_tcp_teardown_admin_queue()
1985 blk_sync_queue(ctrl->admin_q); in nvme_tcp_teardown_admin_queue()
1986 nvme_tcp_stop_queue(ctrl, 0); in nvme_tcp_teardown_admin_queue()
1987 nvme_cancel_admin_tagset(ctrl); in nvme_tcp_teardown_admin_queue()
1989 nvme_start_admin_queue(ctrl); in nvme_tcp_teardown_admin_queue()
1990 nvme_tcp_destroy_admin_queue(ctrl, remove); in nvme_tcp_teardown_admin_queue()
1993 static void nvme_tcp_teardown_io_queues(struct nvme_ctrl *ctrl, in nvme_tcp_teardown_io_queues() argument
1996 if (ctrl->queue_count <= 1) in nvme_tcp_teardown_io_queues()
1998 nvme_stop_admin_queue(ctrl); in nvme_tcp_teardown_io_queues()
1999 nvme_start_freeze(ctrl); in nvme_tcp_teardown_io_queues()
2000 nvme_stop_queues(ctrl); in nvme_tcp_teardown_io_queues()
2001 nvme_sync_io_queues(ctrl); in nvme_tcp_teardown_io_queues()
2002 nvme_tcp_stop_io_queues(ctrl); in nvme_tcp_teardown_io_queues()
2003 nvme_cancel_tagset(ctrl); in nvme_tcp_teardown_io_queues()
2005 nvme_start_queues(ctrl); in nvme_tcp_teardown_io_queues()
2006 nvme_tcp_destroy_io_queues(ctrl, remove); in nvme_tcp_teardown_io_queues()
2009 static void nvme_tcp_reconnect_or_remove(struct nvme_ctrl *ctrl) in nvme_tcp_reconnect_or_remove() argument
2012 if (ctrl->state != NVME_CTRL_CONNECTING) { in nvme_tcp_reconnect_or_remove()
2013 WARN_ON_ONCE(ctrl->state == NVME_CTRL_NEW || in nvme_tcp_reconnect_or_remove()
2014 ctrl->state == NVME_CTRL_LIVE); in nvme_tcp_reconnect_or_remove()
2018 if (nvmf_should_reconnect(ctrl)) { in nvme_tcp_reconnect_or_remove()
2019 dev_info(ctrl->device, "Reconnecting in %d seconds...\n", in nvme_tcp_reconnect_or_remove()
2020 ctrl->opts->reconnect_delay); in nvme_tcp_reconnect_or_remove()
2021 queue_delayed_work(nvme_wq, &to_tcp_ctrl(ctrl)->connect_work, in nvme_tcp_reconnect_or_remove()
2022 ctrl->opts->reconnect_delay * HZ); in nvme_tcp_reconnect_or_remove()
2024 dev_info(ctrl->device, "Removing controller...\n"); in nvme_tcp_reconnect_or_remove()
2025 nvme_delete_ctrl(ctrl); in nvme_tcp_reconnect_or_remove()
2029 static int nvme_tcp_setup_ctrl(struct nvme_ctrl *ctrl, bool new) in nvme_tcp_setup_ctrl() argument
2031 struct nvmf_ctrl_options *opts = ctrl->opts; in nvme_tcp_setup_ctrl()
2034 ret = nvme_tcp_configure_admin_queue(ctrl, new); in nvme_tcp_setup_ctrl()
2038 if (ctrl->icdoff) { in nvme_tcp_setup_ctrl()
2039 ret = -EOPNOTSUPP; in nvme_tcp_setup_ctrl()
2040 dev_err(ctrl->device, "icdoff is not supported!\n"); in nvme_tcp_setup_ctrl()
2044 if (!nvme_ctrl_sgl_supported(ctrl)) { in nvme_tcp_setup_ctrl()
2045 ret = -EOPNOTSUPP; in nvme_tcp_setup_ctrl()
2046 dev_err(ctrl->device, "Mandatory sgls are not supported!\n"); in nvme_tcp_setup_ctrl()
2050 if (opts->queue_size > ctrl->sqsize + 1) in nvme_tcp_setup_ctrl()
2051 dev_warn(ctrl->device, in nvme_tcp_setup_ctrl()
2052 "queue_size %zu > ctrl sqsize %u, clamping down\n", in nvme_tcp_setup_ctrl()
2053 opts->queue_size, ctrl->sqsize + 1); in nvme_tcp_setup_ctrl()
2055 if (ctrl->sqsize + 1 > ctrl->maxcmd) { in nvme_tcp_setup_ctrl()
2056 dev_warn(ctrl->device, in nvme_tcp_setup_ctrl()
2057 "sqsize %u > ctrl maxcmd %u, clamping down\n", in nvme_tcp_setup_ctrl()
2058 ctrl->sqsize + 1, ctrl->maxcmd); in nvme_tcp_setup_ctrl()
2059 ctrl->sqsize = ctrl->maxcmd - 1; in nvme_tcp_setup_ctrl()
2062 if (ctrl->queue_count > 1) { in nvme_tcp_setup_ctrl()
2063 ret = nvme_tcp_configure_io_queues(ctrl, new); in nvme_tcp_setup_ctrl()
2068 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) { in nvme_tcp_setup_ctrl()
2070 * state change failure is ok if we started ctrl delete, in nvme_tcp_setup_ctrl()
2074 WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING && in nvme_tcp_setup_ctrl()
2075 ctrl->state != NVME_CTRL_DELETING_NOIO); in nvme_tcp_setup_ctrl()
2077 ret = -EINVAL; in nvme_tcp_setup_ctrl()
2081 nvme_start_ctrl(ctrl); in nvme_tcp_setup_ctrl()
2085 if (ctrl->queue_count > 1) { in nvme_tcp_setup_ctrl()
2086 nvme_stop_queues(ctrl); in nvme_tcp_setup_ctrl()
2087 nvme_sync_io_queues(ctrl); in nvme_tcp_setup_ctrl()
2088 nvme_tcp_stop_io_queues(ctrl); in nvme_tcp_setup_ctrl()
2089 nvme_cancel_tagset(ctrl); in nvme_tcp_setup_ctrl()
2090 nvme_tcp_destroy_io_queues(ctrl, new); in nvme_tcp_setup_ctrl()
2093 nvme_stop_admin_queue(ctrl); in nvme_tcp_setup_ctrl()
2094 blk_sync_queue(ctrl->admin_q); in nvme_tcp_setup_ctrl()
2095 nvme_tcp_stop_queue(ctrl, 0); in nvme_tcp_setup_ctrl()
2096 nvme_cancel_admin_tagset(ctrl); in nvme_tcp_setup_ctrl()
2097 nvme_tcp_destroy_admin_queue(ctrl, new); in nvme_tcp_setup_ctrl()
2105 struct nvme_ctrl *ctrl = &tcp_ctrl->ctrl; in nvme_tcp_reconnect_ctrl_work() local
2107 ++ctrl->nr_reconnects; in nvme_tcp_reconnect_ctrl_work()
2109 if (nvme_tcp_setup_ctrl(ctrl, false)) in nvme_tcp_reconnect_ctrl_work()
2112 dev_info(ctrl->device, "Successfully reconnected (%d attempt)\n", in nvme_tcp_reconnect_ctrl_work()
2113 ctrl->nr_reconnects); in nvme_tcp_reconnect_ctrl_work()
2115 ctrl->nr_reconnects = 0; in nvme_tcp_reconnect_ctrl_work()
2120 dev_info(ctrl->device, "Failed reconnect attempt %d\n", in nvme_tcp_reconnect_ctrl_work()
2121 ctrl->nr_reconnects); in nvme_tcp_reconnect_ctrl_work()
2122 nvme_tcp_reconnect_or_remove(ctrl); in nvme_tcp_reconnect_ctrl_work()
2129 struct nvme_ctrl *ctrl = &tcp_ctrl->ctrl; in nvme_tcp_error_recovery_work() local
2131 nvme_auth_stop(ctrl); in nvme_tcp_error_recovery_work()
2132 nvme_stop_keep_alive(ctrl); in nvme_tcp_error_recovery_work()
2133 flush_work(&ctrl->async_event_work); in nvme_tcp_error_recovery_work()
2134 nvme_tcp_teardown_io_queues(ctrl, false); in nvme_tcp_error_recovery_work()
2136 nvme_start_queues(ctrl); in nvme_tcp_error_recovery_work()
2137 nvme_tcp_teardown_admin_queue(ctrl, false); in nvme_tcp_error_recovery_work()
2138 nvme_start_admin_queue(ctrl); in nvme_tcp_error_recovery_work()
2140 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING)) { in nvme_tcp_error_recovery_work()
2141 /* state change failure is ok if we started ctrl delete */ in nvme_tcp_error_recovery_work()
2142 WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING && in nvme_tcp_error_recovery_work()
2143 ctrl->state != NVME_CTRL_DELETING_NOIO); in nvme_tcp_error_recovery_work()
2147 nvme_tcp_reconnect_or_remove(ctrl); in nvme_tcp_error_recovery_work()
2150 static void nvme_tcp_teardown_ctrl(struct nvme_ctrl *ctrl, bool shutdown) in nvme_tcp_teardown_ctrl() argument
2152 nvme_tcp_teardown_io_queues(ctrl, shutdown); in nvme_tcp_teardown_ctrl()
2153 nvme_stop_admin_queue(ctrl); in nvme_tcp_teardown_ctrl()
2155 nvme_shutdown_ctrl(ctrl); in nvme_tcp_teardown_ctrl()
2157 nvme_disable_ctrl(ctrl); in nvme_tcp_teardown_ctrl()
2158 nvme_tcp_teardown_admin_queue(ctrl, shutdown); in nvme_tcp_teardown_ctrl()
2161 static void nvme_tcp_delete_ctrl(struct nvme_ctrl *ctrl) in nvme_tcp_delete_ctrl() argument
2163 nvme_tcp_teardown_ctrl(ctrl, true); in nvme_tcp_delete_ctrl()
2168 struct nvme_ctrl *ctrl = in nvme_reset_ctrl_work() local
2171 nvme_stop_ctrl(ctrl); in nvme_reset_ctrl_work()
2172 nvme_tcp_teardown_ctrl(ctrl, false); in nvme_reset_ctrl_work()
2174 if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_CONNECTING)) { in nvme_reset_ctrl_work()
2175 /* state change failure is ok if we started ctrl delete */ in nvme_reset_ctrl_work()
2176 WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING && in nvme_reset_ctrl_work()
2177 ctrl->state != NVME_CTRL_DELETING_NOIO); in nvme_reset_ctrl_work()
2181 if (nvme_tcp_setup_ctrl(ctrl, false)) in nvme_reset_ctrl_work()
2187 ++ctrl->nr_reconnects; in nvme_reset_ctrl_work()
2188 nvme_tcp_reconnect_or_remove(ctrl); in nvme_reset_ctrl_work()
2191 static void nvme_tcp_stop_ctrl(struct nvme_ctrl *ctrl) in nvme_tcp_stop_ctrl() argument
2193 flush_work(&to_tcp_ctrl(ctrl)->err_work); in nvme_tcp_stop_ctrl()
2194 cancel_delayed_work_sync(&to_tcp_ctrl(ctrl)->connect_work); in nvme_tcp_stop_ctrl()
2199 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); in nvme_tcp_free_ctrl() local
2201 if (list_empty(&ctrl->list)) in nvme_tcp_free_ctrl()
2205 list_del(&ctrl->list); in nvme_tcp_free_ctrl()
2208 nvmf_free_options(nctrl->opts); in nvme_tcp_free_ctrl()
2210 kfree(ctrl->queues); in nvme_tcp_free_ctrl()
2211 kfree(ctrl); in nvme_tcp_free_ctrl()
2216 struct nvme_sgl_desc *sg = &c->common.dptr.sgl; in nvme_tcp_set_sg_null()
2218 sg->addr = 0; in nvme_tcp_set_sg_null()
2219 sg->length = 0; in nvme_tcp_set_sg_null()
2220 sg->type = (NVME_TRANSPORT_SGL_DATA_DESC << 4) | in nvme_tcp_set_sg_null()
2227 struct nvme_sgl_desc *sg = &c->common.dptr.sgl; in nvme_tcp_set_sg_inline()
2229 sg->addr = cpu_to_le64(queue->ctrl->ctrl.icdoff); in nvme_tcp_set_sg_inline()
2230 sg->length = cpu_to_le32(data_len); in nvme_tcp_set_sg_inline()
2231 sg->type = (NVME_SGL_FMT_DATA_DESC << 4) | NVME_SGL_FMT_OFFSET; in nvme_tcp_set_sg_inline()
2237 struct nvme_sgl_desc *sg = &c->common.dptr.sgl; in nvme_tcp_set_sg_host_data()
2239 sg->addr = 0; in nvme_tcp_set_sg_host_data()
2240 sg->length = cpu_to_le32(data_len); in nvme_tcp_set_sg_host_data()
2241 sg->type = (NVME_TRANSPORT_SGL_DATA_DESC << 4) | in nvme_tcp_set_sg_host_data()
2247 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(arg); in nvme_tcp_submit_async_event() local
2248 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_submit_async_event()
2249 struct nvme_tcp_cmd_pdu *pdu = ctrl->async_req.pdu; in nvme_tcp_submit_async_event()
2250 struct nvme_command *cmd = &pdu->cmd; in nvme_tcp_submit_async_event()
2254 pdu->hdr.type = nvme_tcp_cmd; in nvme_tcp_submit_async_event()
2255 if (queue->hdr_digest) in nvme_tcp_submit_async_event()
2256 pdu->hdr.flags |= NVME_TCP_F_HDGST; in nvme_tcp_submit_async_event()
2257 pdu->hdr.hlen = sizeof(*pdu); in nvme_tcp_submit_async_event()
2258 pdu->hdr.plen = cpu_to_le32(pdu->hdr.hlen + hdgst); in nvme_tcp_submit_async_event()
2260 cmd->common.opcode = nvme_admin_async_event; in nvme_tcp_submit_async_event()
2261 cmd->common.command_id = NVME_AQ_BLK_MQ_DEPTH; in nvme_tcp_submit_async_event()
2262 cmd->common.flags |= NVME_CMD_SGL_METABUF; in nvme_tcp_submit_async_event()
2265 ctrl->async_req.state = NVME_TCP_SEND_CMD_PDU; in nvme_tcp_submit_async_event()
2266 ctrl->async_req.offset = 0; in nvme_tcp_submit_async_event()
2267 ctrl->async_req.curr_bio = NULL; in nvme_tcp_submit_async_event()
2268 ctrl->async_req.data_len = 0; in nvme_tcp_submit_async_event()
2270 nvme_tcp_queue_request(&ctrl->async_req, true, true); in nvme_tcp_submit_async_event()
2276 struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl; in nvme_tcp_complete_timed_out() local
2278 nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue)); in nvme_tcp_complete_timed_out()
2285 struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl; in nvme_tcp_timeout() local
2286 struct nvme_tcp_cmd_pdu *pdu = req->pdu; in nvme_tcp_timeout()
2288 dev_warn(ctrl->device, in nvme_tcp_timeout()
2290 nvme_tcp_queue_id(req->queue), rq->tag, pdu->hdr.type); in nvme_tcp_timeout()
2292 if (ctrl->state != NVME_CTRL_LIVE) { in nvme_tcp_timeout()
2297 * - ctrl disable/shutdown fabrics requests in nvme_tcp_timeout()
2298 * - connect requests in nvme_tcp_timeout()
2299 * - initialization admin requests in nvme_tcp_timeout()
2300 * - I/O requests that entered after unquiescing and in nvme_tcp_timeout()
2314 nvme_tcp_error_recovery(ctrl); in nvme_tcp_timeout()
2322 struct nvme_tcp_cmd_pdu *pdu = req->pdu; in nvme_tcp_map_data()
2323 struct nvme_command *c = &pdu->cmd; in nvme_tcp_map_data()
2325 c->common.flags |= NVME_CMD_SGL_METABUF; in nvme_tcp_map_data()
2330 req->data_len <= nvme_tcp_inline_data_size(req)) in nvme_tcp_map_data()
2331 nvme_tcp_set_sg_inline(queue, c, req->data_len); in nvme_tcp_map_data()
2333 nvme_tcp_set_sg_host_data(c, req->data_len); in nvme_tcp_map_data()
2342 struct nvme_tcp_cmd_pdu *pdu = req->pdu; in nvme_tcp_setup_cmd_pdu()
2343 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_setup_cmd_pdu()
2351 req->state = NVME_TCP_SEND_CMD_PDU; in nvme_tcp_setup_cmd_pdu()
2352 req->status = cpu_to_le16(NVME_SC_SUCCESS); in nvme_tcp_setup_cmd_pdu()
2353 req->offset = 0; in nvme_tcp_setup_cmd_pdu()
2354 req->data_sent = 0; in nvme_tcp_setup_cmd_pdu()
2355 req->pdu_len = 0; in nvme_tcp_setup_cmd_pdu()
2356 req->pdu_sent = 0; in nvme_tcp_setup_cmd_pdu()
2357 req->h2cdata_left = 0; in nvme_tcp_setup_cmd_pdu()
2358 req->data_len = blk_rq_nr_phys_segments(rq) ? in nvme_tcp_setup_cmd_pdu()
2360 req->curr_bio = rq->bio; in nvme_tcp_setup_cmd_pdu()
2361 if (req->curr_bio && req->data_len) in nvme_tcp_setup_cmd_pdu()
2365 req->data_len <= nvme_tcp_inline_data_size(req)) in nvme_tcp_setup_cmd_pdu()
2366 req->pdu_len = req->data_len; in nvme_tcp_setup_cmd_pdu()
2368 pdu->hdr.type = nvme_tcp_cmd; in nvme_tcp_setup_cmd_pdu()
2369 pdu->hdr.flags = 0; in nvme_tcp_setup_cmd_pdu()
2370 if (queue->hdr_digest) in nvme_tcp_setup_cmd_pdu()
2371 pdu->hdr.flags |= NVME_TCP_F_HDGST; in nvme_tcp_setup_cmd_pdu()
2372 if (queue->data_digest && req->pdu_len) { in nvme_tcp_setup_cmd_pdu()
2373 pdu->hdr.flags |= NVME_TCP_F_DDGST; in nvme_tcp_setup_cmd_pdu()
2376 pdu->hdr.hlen = sizeof(*pdu); in nvme_tcp_setup_cmd_pdu()
2377 pdu->hdr.pdo = req->pdu_len ? pdu->hdr.hlen + hdgst : 0; in nvme_tcp_setup_cmd_pdu()
2378 pdu->hdr.plen = in nvme_tcp_setup_cmd_pdu()
2379 cpu_to_le32(pdu->hdr.hlen + hdgst + req->pdu_len + ddgst); in nvme_tcp_setup_cmd_pdu()
2384 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_setup_cmd_pdu()
2394 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_commit_rqs()
2396 if (!llist_empty(&queue->req_list)) in nvme_tcp_commit_rqs()
2397 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_commit_rqs()
2403 struct nvme_ns *ns = hctx->queue->queuedata; in nvme_tcp_queue_rq()
2404 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_queue_rq()
2405 struct request *rq = bd->rq; in nvme_tcp_queue_rq()
2407 bool queue_ready = test_bit(NVME_TCP_Q_LIVE, &queue->flags); in nvme_tcp_queue_rq()
2410 if (!nvme_check_ready(&queue->ctrl->ctrl, rq, queue_ready)) in nvme_tcp_queue_rq()
2411 return nvme_fail_nonready_command(&queue->ctrl->ctrl, rq); in nvme_tcp_queue_rq()
2419 nvme_tcp_queue_request(req, true, bd->last); in nvme_tcp_queue_rq()
2426 struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(set->driver_data); in nvme_tcp_map_queues() local
2427 struct nvmf_ctrl_options *opts = ctrl->ctrl.opts; in nvme_tcp_map_queues()
2429 if (opts->nr_write_queues && ctrl->io_queues[HCTX_TYPE_READ]) { in nvme_tcp_map_queues()
2431 set->map[HCTX_TYPE_DEFAULT].nr_queues = in nvme_tcp_map_queues()
2432 ctrl->io_queues[HCTX_TYPE_DEFAULT]; in nvme_tcp_map_queues()
2433 set->map[HCTX_TYPE_DEFAULT].queue_offset = 0; in nvme_tcp_map_queues()
2434 set->map[HCTX_TYPE_READ].nr_queues = in nvme_tcp_map_queues()
2435 ctrl->io_queues[HCTX_TYPE_READ]; in nvme_tcp_map_queues()
2436 set->map[HCTX_TYPE_READ].queue_offset = in nvme_tcp_map_queues()
2437 ctrl->io_queues[HCTX_TYPE_DEFAULT]; in nvme_tcp_map_queues()
2440 set->map[HCTX_TYPE_DEFAULT].nr_queues = in nvme_tcp_map_queues()
2441 ctrl->io_queues[HCTX_TYPE_DEFAULT]; in nvme_tcp_map_queues()
2442 set->map[HCTX_TYPE_DEFAULT].queue_offset = 0; in nvme_tcp_map_queues()
2443 set->map[HCTX_TYPE_READ].nr_queues = in nvme_tcp_map_queues()
2444 ctrl->io_queues[HCTX_TYPE_DEFAULT]; in nvme_tcp_map_queues()
2445 set->map[HCTX_TYPE_READ].queue_offset = 0; in nvme_tcp_map_queues()
2447 blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]); in nvme_tcp_map_queues()
2448 blk_mq_map_queues(&set->map[HCTX_TYPE_READ]); in nvme_tcp_map_queues()
2450 if (opts->nr_poll_queues && ctrl->io_queues[HCTX_TYPE_POLL]) { in nvme_tcp_map_queues()
2452 set->map[HCTX_TYPE_POLL].nr_queues = in nvme_tcp_map_queues()
2453 ctrl->io_queues[HCTX_TYPE_POLL]; in nvme_tcp_map_queues()
2454 set->map[HCTX_TYPE_POLL].queue_offset = in nvme_tcp_map_queues()
2455 ctrl->io_queues[HCTX_TYPE_DEFAULT] + in nvme_tcp_map_queues()
2456 ctrl->io_queues[HCTX_TYPE_READ]; in nvme_tcp_map_queues()
2457 blk_mq_map_queues(&set->map[HCTX_TYPE_POLL]); in nvme_tcp_map_queues()
2460 dev_info(ctrl->ctrl.device, in nvme_tcp_map_queues()
2462 ctrl->io_queues[HCTX_TYPE_DEFAULT], in nvme_tcp_map_queues()
2463 ctrl->io_queues[HCTX_TYPE_READ], in nvme_tcp_map_queues()
2464 ctrl->io_queues[HCTX_TYPE_POLL]); in nvme_tcp_map_queues()
2469 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_poll()
2470 struct sock *sk = queue->sock->sk; in nvme_tcp_poll()
2472 if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags)) in nvme_tcp_poll()
2475 set_bit(NVME_TCP_Q_POLLING, &queue->flags); in nvme_tcp_poll()
2476 if (sk_can_busy_loop(sk) && skb_queue_empty_lockless(&sk->sk_receive_queue)) in nvme_tcp_poll()
2479 clear_bit(NVME_TCP_Q_POLLING, &queue->flags); in nvme_tcp_poll()
2480 return queue->nr_cqe; in nvme_tcp_poll()
2483 static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) in nvme_tcp_get_address() argument
2485 struct nvme_tcp_queue *queue = &to_tcp_ctrl(ctrl)->queues[0]; in nvme_tcp_get_address()
2487 int ret, len; in nvme_tcp_get_address() local
2489 len = nvmf_get_address(ctrl, buf, size); in nvme_tcp_get_address()
2491 ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src_addr); in nvme_tcp_get_address()
2493 if (len > 0) in nvme_tcp_get_address()
2494 len--; /* strip trailing newline */ in nvme_tcp_get_address()
2495 len += scnprintf(buf + len, size - len, "%ssrc_addr=%pISc\n", in nvme_tcp_get_address()
2496 (len) ? "," : "", &src_addr); in nvme_tcp_get_address()
2499 return len; in nvme_tcp_get_address()
2540 struct nvme_tcp_ctrl *ctrl; in nvme_tcp_existing_controller() local
2544 list_for_each_entry(ctrl, &nvme_tcp_ctrl_list, list) { in nvme_tcp_existing_controller()
2545 found = nvmf_ip_options_match(&ctrl->ctrl, opts); in nvme_tcp_existing_controller()
2557 struct nvme_tcp_ctrl *ctrl; in nvme_tcp_create_ctrl() local
2560 ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); in nvme_tcp_create_ctrl()
2561 if (!ctrl) in nvme_tcp_create_ctrl()
2562 return ERR_PTR(-ENOMEM); in nvme_tcp_create_ctrl()
2564 INIT_LIST_HEAD(&ctrl->list); in nvme_tcp_create_ctrl()
2565 ctrl->ctrl.opts = opts; in nvme_tcp_create_ctrl()
2566 ctrl->ctrl.queue_count = opts->nr_io_queues + opts->nr_write_queues + in nvme_tcp_create_ctrl()
2567 opts->nr_poll_queues + 1; in nvme_tcp_create_ctrl()
2568 ctrl->ctrl.sqsize = opts->queue_size - 1; in nvme_tcp_create_ctrl()
2569 ctrl->ctrl.kato = opts->kato; in nvme_tcp_create_ctrl()
2571 INIT_DELAYED_WORK(&ctrl->connect_work, in nvme_tcp_create_ctrl()
2573 INIT_WORK(&ctrl->err_work, nvme_tcp_error_recovery_work); in nvme_tcp_create_ctrl()
2574 INIT_WORK(&ctrl->ctrl.reset_work, nvme_reset_ctrl_work); in nvme_tcp_create_ctrl()
2576 if (!(opts->mask & NVMF_OPT_TRSVCID)) { in nvme_tcp_create_ctrl()
2577 opts->trsvcid = in nvme_tcp_create_ctrl()
2579 if (!opts->trsvcid) { in nvme_tcp_create_ctrl()
2580 ret = -ENOMEM; in nvme_tcp_create_ctrl()
2583 opts->mask |= NVMF_OPT_TRSVCID; in nvme_tcp_create_ctrl()
2587 opts->traddr, opts->trsvcid, &ctrl->addr); in nvme_tcp_create_ctrl()
2590 opts->traddr, opts->trsvcid); in nvme_tcp_create_ctrl()
2594 if (opts->mask & NVMF_OPT_HOST_TRADDR) { in nvme_tcp_create_ctrl()
2596 opts->host_traddr, NULL, &ctrl->src_addr); in nvme_tcp_create_ctrl()
2599 opts->host_traddr); in nvme_tcp_create_ctrl()
2604 if (opts->mask & NVMF_OPT_HOST_IFACE) { in nvme_tcp_create_ctrl()
2605 if (!__dev_get_by_name(&init_net, opts->host_iface)) { in nvme_tcp_create_ctrl()
2607 opts->host_iface); in nvme_tcp_create_ctrl()
2608 ret = -ENODEV; in nvme_tcp_create_ctrl()
2613 if (!opts->duplicate_connect && nvme_tcp_existing_controller(opts)) { in nvme_tcp_create_ctrl()
2614 ret = -EALREADY; in nvme_tcp_create_ctrl()
2618 ctrl->queues = kcalloc(ctrl->ctrl.queue_count, sizeof(*ctrl->queues), in nvme_tcp_create_ctrl()
2620 if (!ctrl->queues) { in nvme_tcp_create_ctrl()
2621 ret = -ENOMEM; in nvme_tcp_create_ctrl()
2625 ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_tcp_ctrl_ops, 0); in nvme_tcp_create_ctrl()
2629 if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) { in nvme_tcp_create_ctrl()
2631 ret = -EINTR; in nvme_tcp_create_ctrl()
2635 ret = nvme_tcp_setup_ctrl(&ctrl->ctrl, true); in nvme_tcp_create_ctrl()
2639 dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISp\n", in nvme_tcp_create_ctrl()
2640 nvmf_ctrl_subsysnqn(&ctrl->ctrl), &ctrl->addr); in nvme_tcp_create_ctrl()
2643 list_add_tail(&ctrl->list, &nvme_tcp_ctrl_list); in nvme_tcp_create_ctrl()
2646 return &ctrl->ctrl; in nvme_tcp_create_ctrl()
2649 nvme_uninit_ctrl(&ctrl->ctrl); in nvme_tcp_create_ctrl()
2650 nvme_put_ctrl(&ctrl->ctrl); in nvme_tcp_create_ctrl()
2652 ret = -EIO; in nvme_tcp_create_ctrl()
2655 kfree(ctrl->queues); in nvme_tcp_create_ctrl()
2657 kfree(ctrl); in nvme_tcp_create_ctrl()
2678 return -ENOMEM; in nvme_tcp_init_module()
2686 struct nvme_tcp_ctrl *ctrl; in nvme_tcp_cleanup_module() local
2691 list_for_each_entry(ctrl, &nvme_tcp_ctrl_list, list) in nvme_tcp_cleanup_module()
2692 nvme_delete_ctrl(&ctrl->ctrl); in nvme_tcp_cleanup_module()