Lines Matching refs:queue

81 	struct nvme_tcp_queue	*queue;  member
179 static int nvme_tcp_try_send(struct nvme_tcp_queue *queue);
186 static inline int nvme_tcp_queue_id(struct nvme_tcp_queue *queue) in nvme_tcp_queue_id() argument
188 return queue - queue->ctrl->queues; in nvme_tcp_queue_id()
191 static inline struct blk_mq_tags *nvme_tcp_tagset(struct nvme_tcp_queue *queue) in nvme_tcp_tagset() argument
193 u32 queue_idx = nvme_tcp_queue_id(queue); in nvme_tcp_tagset()
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()
200 static inline u8 nvme_tcp_hdgst_len(struct nvme_tcp_queue *queue) in nvme_tcp_hdgst_len() argument
202 return queue->hdr_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvme_tcp_hdgst_len()
205 static inline u8 nvme_tcp_ddgst_len(struct nvme_tcp_queue *queue) in nvme_tcp_ddgst_len() argument
207 return queue->data_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvme_tcp_ddgst_len()
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()
308 static inline void nvme_tcp_send_all(struct nvme_tcp_queue *queue) in nvme_tcp_send_all() argument
314 ret = nvme_tcp_try_send(queue); in nvme_tcp_send_all()
318 static inline bool nvme_tcp_queue_more(struct nvme_tcp_queue *queue) in nvme_tcp_queue_more() argument
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() local
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()
340 nvme_tcp_send_all(queue); in nvme_tcp_queue_request()
341 mutex_unlock(&queue->send_mutex); in nvme_tcp_queue_request()
344 if (last && nvme_tcp_queue_more(queue)) in nvme_tcp_queue_request()
345 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_queue_request()
348 static void nvme_tcp_process_req_list(struct nvme_tcp_queue *queue) in nvme_tcp_process_req_list() argument
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()
360 nvme_tcp_fetch_request(struct nvme_tcp_queue *queue) in nvme_tcp_fetch_request() argument
364 req = list_first_entry_or_null(&queue->send_list, in nvme_tcp_fetch_request()
367 nvme_tcp_process_req_list(queue); in nvme_tcp_fetch_request()
368 req = list_first_entry_or_null(&queue->send_list, in nvme_tcp_fetch_request()
406 static int nvme_tcp_verify_hdgst(struct nvme_tcp_queue *queue, in nvme_tcp_verify_hdgst() argument
414 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_verify_hdgst()
416 nvme_tcp_queue_id(queue)); in nvme_tcp_verify_hdgst()
421 nvme_tcp_hdgst(queue->rcv_hash, pdu, pdu_len); in nvme_tcp_verify_hdgst()
424 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_verify_hdgst()
433 static int nvme_tcp_check_ddgst(struct nvme_tcp_queue *queue, void *pdu) in nvme_tcp_check_ddgst() argument
436 u8 digest_len = nvme_tcp_hdgst_len(queue); in nvme_tcp_check_ddgst()
443 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_check_ddgst()
445 nvme_tcp_queue_id(queue)); in nvme_tcp_check_ddgst()
448 crypto_ahash_init(queue->rcv_hash); in nvme_tcp_check_ddgst()
469 struct nvme_tcp_queue *queue = &ctrl->queues[queue_idx]; in nvme_tcp_init_request() local
470 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_init_request()
472 req->pdu = page_frag_alloc(&queue->pf_cache, in nvme_tcp_init_request()
479 req->queue = queue; in nvme_tcp_init_request()
490 struct nvme_tcp_queue *queue = &ctrl->queues[hctx_idx + 1]; in nvme_tcp_init_hctx() local
492 hctx->driver_data = queue; in nvme_tcp_init_hctx()
500 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_init_admin_hctx() local
502 hctx->driver_data = queue; in nvme_tcp_init_admin_hctx()
507 nvme_tcp_recv_state(struct nvme_tcp_queue *queue) in nvme_tcp_recv_state() argument
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()
514 static void nvme_tcp_init_recv_ctx(struct nvme_tcp_queue *queue) in nvme_tcp_init_recv_ctx() argument
516 queue->pdu_remaining = sizeof(struct nvme_tcp_rsp_pdu) + in nvme_tcp_init_recv_ctx()
517 nvme_tcp_hdgst_len(queue); 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()
532 static int nvme_tcp_process_nvme_cqe(struct nvme_tcp_queue *queue, in nvme_tcp_process_nvme_cqe() argument
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()
553 queue->nr_cqe++; in nvme_tcp_process_nvme_cqe()
558 static int nvme_tcp_handle_c2h_data(struct nvme_tcp_queue *queue, in nvme_tcp_handle_c2h_data() argument
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()
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()
578 queue->data_remaining = le32_to_cpu(pdu->data_length); 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()
592 static int nvme_tcp_handle_comp(struct nvme_tcp_queue *queue, in nvme_tcp_handle_comp() argument
604 if (unlikely(nvme_is_aen_req(nvme_tcp_queue_id(queue), in nvme_tcp_handle_comp()
606 nvme_complete_async_event(&queue->ctrl->ctrl, cqe->status, in nvme_tcp_handle_comp()
609 ret = nvme_tcp_process_nvme_cqe(queue, cqe); in nvme_tcp_handle_comp()
617 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_setup_h2c_data_pdu() local
620 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_setup_h2c_data_pdu()
621 u8 ddgst = nvme_tcp_ddgst_len(queue); in nvme_tcp_setup_h2c_data_pdu()
625 req->pdu_len = min(req->h2cdata_left, queue->maxh2cdata); in nvme_tcp_setup_h2c_data_pdu()
634 if (queue->hdr_digest) in nvme_tcp_setup_h2c_data_pdu()
636 if (queue->data_digest) in nvme_tcp_setup_h2c_data_pdu()
648 static int nvme_tcp_handle_r2t(struct nvme_tcp_queue *queue, in nvme_tcp_handle_r2t() argument
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()
666 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
673 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
680 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
697 static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb, 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()
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()
733 return nvme_tcp_handle_c2h_data(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
735 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_recv_pdu()
736 return nvme_tcp_handle_comp(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
738 nvme_tcp_init_recv_ctx(queue); 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()
755 static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, 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()
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()
781 nvme_tcp_init_recv_ctx(queue); 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()
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()
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()
817 queue->nr_cqe++; in nvme_tcp_recv_data()
819 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_recv_data()
826 static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue, 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()
842 if (queue->ddgst_remaining) in nvme_tcp_recv_ddgst()
845 if (queue->recv_ddgst != queue->exp_ddgst) { in nvme_tcp_recv_ddgst()
846 struct request *rq = nvme_cid_to_rq(nvme_tcp_tagset(queue), 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()
859 struct request *rq = nvme_cid_to_rq(nvme_tcp_tagset(queue), in nvme_tcp_recv_ddgst()
864 queue->nr_cqe++; in nvme_tcp_recv_ddgst()
867 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_recv_ddgst()
874 struct nvme_tcp_queue *queue = desc->arg.data; in nvme_tcp_recv_skb() local
879 switch (nvme_tcp_recv_state(queue)) { 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()
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()
906 struct nvme_tcp_queue *queue; in nvme_tcp_data_ready() local
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()
918 struct nvme_tcp_queue *queue; in nvme_tcp_write_space() local
921 queue = sk->sk_user_data; in nvme_tcp_write_space()
922 if (likely(queue && sk_stream_is_writeable(sk))) { in nvme_tcp_write_space()
924 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_write_space()
931 struct nvme_tcp_queue *queue; in nvme_tcp_state_change() local
934 queue = sk->sk_user_data; in nvme_tcp_state_change()
935 if (!queue) 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()
957 static inline void nvme_tcp_done_send_req(struct nvme_tcp_queue *queue) in nvme_tcp_done_send_req() argument
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() local
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()
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()
1027 nvme_tcp_done_send_req(queue); in nvme_tcp_try_send_data()
1037 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_cmd_pdu() local
1040 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_try_send_cmd_pdu()
1045 if (inline_data || nvme_tcp_queue_more(queue)) in nvme_tcp_try_send_cmd_pdu()
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()
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()
1065 nvme_tcp_done_send_req(queue); in nvme_tcp_try_send_cmd_pdu()
1076 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_data_pdu() local
1078 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_try_send_data_pdu()
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()
1086 ret = kernel_sendpage(queue->sock, virt_to_page(pdu), 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()
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()
1110 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_ddgst() local
1120 if (nvme_tcp_queue_more(queue)) in nvme_tcp_try_send_ddgst()
1125 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvme_tcp_try_send_ddgst()
1133 nvme_tcp_done_send_req(queue); in nvme_tcp_try_send_ddgst()
1141 static int nvme_tcp_try_send(struct nvme_tcp_queue *queue) in nvme_tcp_try_send() argument
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()
1181 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_try_send()
1183 nvme_tcp_fail_request(queue->request); in nvme_tcp_try_send()
1184 nvme_tcp_done_send_req(queue); in nvme_tcp_try_send()
1191 static int nvme_tcp_try_recv(struct nvme_tcp_queue *queue) in nvme_tcp_try_recv() argument
1193 struct socket *sock = queue->sock; in nvme_tcp_try_recv()
1198 rd_desc.arg.data = queue; in nvme_tcp_try_recv()
1201 queue->nr_cqe = 0; in nvme_tcp_try_recv()
1209 struct nvme_tcp_queue *queue = in nvme_tcp_io_work() local
1217 if (mutex_trylock(&queue->send_mutex)) { in nvme_tcp_io_work()
1218 result = nvme_tcp_try_send(queue); in nvme_tcp_io_work()
1219 mutex_unlock(&queue->send_mutex); in nvme_tcp_io_work()
1226 result = nvme_tcp_try_recv(queue); 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()
1240 static void nvme_tcp_free_crypto(struct nvme_tcp_queue *queue) in nvme_tcp_free_crypto() argument
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()
1249 static int nvme_tcp_alloc_crypto(struct nvme_tcp_queue *queue) in nvme_tcp_alloc_crypto() argument
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()
1284 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_alloc_async_req() local
1286 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_alloc_async_req()
1288 async->pdu = page_frag_alloc(&queue->pf_cache, in nvme_tcp_alloc_async_req()
1294 async->queue = &ctrl->queues[0]; in nvme_tcp_alloc_async_req()
1302 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_free_queue() local
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()
1309 nvme_tcp_free_crypto(queue); 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()
1326 static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) in nvme_tcp_init_connection() argument
1353 if (queue->hdr_digest) in nvme_tcp_init_connection()
1355 if (queue->data_digest) 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()
1375 nvme_tcp_queue_id(queue), icresp->hdr.type); in nvme_tcp_init_connection()
1381 nvme_tcp_queue_id(queue), icresp->hdr.plen); in nvme_tcp_init_connection()
1387 nvme_tcp_queue_id(queue), icresp->pfv); 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()
1395 nvme_tcp_queue_id(queue), in nvme_tcp_init_connection()
1396 queue->data_digest ? "enabled" : "disabled", 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()
1405 nvme_tcp_queue_id(queue), in nvme_tcp_init_connection()
1406 queue->hdr_digest ? "enabled" : "disabled", in nvme_tcp_init_connection()
1413 nvme_tcp_queue_id(queue), icresp->cpda); in nvme_tcp_init_connection()
1420 nvme_tcp_queue_id(queue), maxh2cdata); in nvme_tcp_init_connection()
1423 queue->maxh2cdata = maxh2cdata; in nvme_tcp_init_connection()
1433 static bool nvme_tcp_admin_queue(struct nvme_tcp_queue *queue) in nvme_tcp_admin_queue() argument
1435 return nvme_tcp_queue_id(queue) == 0; in nvme_tcp_admin_queue()
1438 static bool nvme_tcp_default_queue(struct nvme_tcp_queue *queue) in nvme_tcp_default_queue() argument
1440 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_default_queue()
1441 int qid = nvme_tcp_queue_id(queue); in nvme_tcp_default_queue()
1443 return !nvme_tcp_admin_queue(queue) && in nvme_tcp_default_queue()
1447 static bool nvme_tcp_read_queue(struct nvme_tcp_queue *queue) in nvme_tcp_read_queue() argument
1449 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_read_queue()
1450 int qid = nvme_tcp_queue_id(queue); in nvme_tcp_read_queue()
1452 return !nvme_tcp_admin_queue(queue) && in nvme_tcp_read_queue()
1453 !nvme_tcp_default_queue(queue) && in nvme_tcp_read_queue()
1458 static bool nvme_tcp_poll_queue(struct nvme_tcp_queue *queue) in nvme_tcp_poll_queue() argument
1460 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_poll_queue()
1461 int qid = nvme_tcp_queue_id(queue); in nvme_tcp_poll_queue()
1463 return !nvme_tcp_admin_queue(queue) && in nvme_tcp_poll_queue()
1464 !nvme_tcp_default_queue(queue) && in nvme_tcp_poll_queue()
1465 !nvme_tcp_read_queue(queue) && in nvme_tcp_poll_queue()
1471 static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue) in nvme_tcp_set_queue_io_cpu() argument
1473 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_set_queue_io_cpu()
1474 int qid = nvme_tcp_queue_id(queue); in nvme_tcp_set_queue_io_cpu()
1477 if (nvme_tcp_default_queue(queue)) in nvme_tcp_set_queue_io_cpu()
1479 else if (nvme_tcp_read_queue(queue)) in nvme_tcp_set_queue_io_cpu()
1481 else if (nvme_tcp_poll_queue(queue)) 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()
1490 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_alloc_queue() local
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()
1507 IPPROTO_TCP, &queue->sock); 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()
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()
1540 nvme_tcp_set_queue_io_cpu(queue); 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()
1549 ret = kernel_bind(queue->sock, (struct sockaddr *)&ctrl->src_addr, in nvme_tcp_alloc_queue()
1563 ret = sock_setsockopt(queue->sock, SOL_SOCKET, SO_BINDTODEVICE, 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()
1576 ret = nvme_tcp_alloc_crypto(queue); in nvme_tcp_alloc_queue()
1585 nvme_tcp_hdgst_len(queue); 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()
1593 nvme_tcp_queue_id(queue)); in nvme_tcp_alloc_queue()
1595 ret = kernel_connect(queue->sock, (struct sockaddr *)&ctrl->addr, in nvme_tcp_alloc_queue()
1603 ret = nvme_tcp_init_connection(queue); 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()
1609 nvme_tcp_init_recv_ctx(queue); 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()
1632 nvme_tcp_free_crypto(queue); 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()
1642 static void nvme_tcp_restore_sock_calls(struct nvme_tcp_queue *queue) in nvme_tcp_restore_sock_calls() argument
1644 struct socket *sock = queue->sock; 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()
1654 static void __nvme_tcp_stop_queue(struct nvme_tcp_queue *queue) in __nvme_tcp_stop_queue() argument
1656 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in __nvme_tcp_stop_queue()
1657 nvme_tcp_restore_sock_calls(queue); in __nvme_tcp_stop_queue()
1658 cancel_work_sync(&queue->io_work); in __nvme_tcp_stop_queue()
1664 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_stop_queue() local
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()
1671 __nvme_tcp_stop_queue(queue); in nvme_tcp_stop_queue()
1672 mutex_unlock(&queue->queue_lock); in nvme_tcp_stop_queue()
2224 static void nvme_tcp_set_sg_inline(struct nvme_tcp_queue *queue, in nvme_tcp_set_sg_inline() argument
2229 sg->addr = cpu_to_le64(queue->ctrl->ctrl.icdoff); in nvme_tcp_set_sg_inline()
2248 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_submit_async_event() local
2251 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_submit_async_event()
2255 if (queue->hdr_digest) in nvme_tcp_submit_async_event()
2276 struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl; in nvme_tcp_complete_timed_out()
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()
2290 nvme_tcp_queue_id(req->queue), rq->tag, pdu->hdr.type); in nvme_tcp_timeout()
2318 static blk_status_t nvme_tcp_map_data(struct nvme_tcp_queue *queue, in nvme_tcp_map_data() argument
2331 nvme_tcp_set_sg_inline(queue, c, req->data_len); in nvme_tcp_map_data()
2343 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_setup_cmd_pdu() local
2344 u8 hdgst = nvme_tcp_hdgst_len(queue), ddgst = 0; in nvme_tcp_setup_cmd_pdu()
2370 if (queue->hdr_digest) in nvme_tcp_setup_cmd_pdu()
2372 if (queue->data_digest && req->pdu_len) { in nvme_tcp_setup_cmd_pdu()
2374 ddgst = nvme_tcp_ddgst_len(queue); in nvme_tcp_setup_cmd_pdu()
2381 ret = nvme_tcp_map_data(queue, rq); 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() local
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() local
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()
2469 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_poll() local
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()
2478 nvme_tcp_try_recv(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()
2485 struct nvme_tcp_queue *queue = &to_tcp_ctrl(ctrl)->queues[0]; in nvme_tcp_get_address() local
2491 ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src_addr); in nvme_tcp_get_address()