Lines Matching refs:queue
82 struct nvme_tcp_queue *queue; member
180 static int nvme_tcp_try_send(struct nvme_tcp_queue *queue);
187 static inline int nvme_tcp_queue_id(struct nvme_tcp_queue *queue) in nvme_tcp_queue_id() argument
189 return queue - queue->ctrl->queues; in nvme_tcp_queue_id()
192 static inline struct blk_mq_tags *nvme_tcp_tagset(struct nvme_tcp_queue *queue) in nvme_tcp_tagset() argument
194 u32 queue_idx = nvme_tcp_queue_id(queue); in nvme_tcp_tagset()
197 return queue->ctrl->admin_tag_set.tags[queue_idx]; in nvme_tcp_tagset()
198 return queue->ctrl->tag_set.tags[queue_idx - 1]; in nvme_tcp_tagset()
201 static inline u8 nvme_tcp_hdgst_len(struct nvme_tcp_queue *queue) in nvme_tcp_hdgst_len() argument
203 return queue->hdr_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvme_tcp_hdgst_len()
206 static inline u8 nvme_tcp_ddgst_len(struct nvme_tcp_queue *queue) in nvme_tcp_ddgst_len() argument
208 return queue->data_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvme_tcp_ddgst_len()
227 return req->queue->cmnd_capsule_len - sizeof(struct nvme_command); in nvme_tcp_inline_data_size()
232 return req == &req->queue->ctrl->async_req; in nvme_tcp_async_req()
321 static inline void nvme_tcp_send_all(struct nvme_tcp_queue *queue) in nvme_tcp_send_all() argument
327 ret = nvme_tcp_try_send(queue); in nvme_tcp_send_all()
331 static inline bool nvme_tcp_queue_more(struct nvme_tcp_queue *queue) in nvme_tcp_queue_more() argument
333 return !list_empty(&queue->send_list) || in nvme_tcp_queue_more()
334 !llist_empty(&queue->req_list); in nvme_tcp_queue_more()
340 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_queue_request() local
343 empty = llist_add(&req->lentry, &queue->req_list) && in nvme_tcp_queue_request()
344 list_empty(&queue->send_list) && !queue->request; in nvme_tcp_queue_request()
351 if (queue->io_cpu == raw_smp_processor_id() && in nvme_tcp_queue_request()
352 sync && empty && mutex_trylock(&queue->send_mutex)) { in nvme_tcp_queue_request()
353 nvme_tcp_send_all(queue); in nvme_tcp_queue_request()
354 mutex_unlock(&queue->send_mutex); in nvme_tcp_queue_request()
357 if (last && nvme_tcp_queue_more(queue)) in nvme_tcp_queue_request()
358 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_queue_request()
361 static void nvme_tcp_process_req_list(struct nvme_tcp_queue *queue) in nvme_tcp_process_req_list() argument
366 for (node = llist_del_all(&queue->req_list); node; node = node->next) { in nvme_tcp_process_req_list()
368 list_add(&req->entry, &queue->send_list); in nvme_tcp_process_req_list()
373 nvme_tcp_fetch_request(struct nvme_tcp_queue *queue) in nvme_tcp_fetch_request() argument
377 req = list_first_entry_or_null(&queue->send_list, in nvme_tcp_fetch_request()
380 nvme_tcp_process_req_list(queue); in nvme_tcp_fetch_request()
381 req = list_first_entry_or_null(&queue->send_list, in nvme_tcp_fetch_request()
419 static int nvme_tcp_verify_hdgst(struct nvme_tcp_queue *queue, in nvme_tcp_verify_hdgst() argument
427 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_verify_hdgst()
429 nvme_tcp_queue_id(queue)); in nvme_tcp_verify_hdgst()
434 nvme_tcp_hdgst(queue->rcv_hash, pdu, pdu_len); in nvme_tcp_verify_hdgst()
437 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_verify_hdgst()
446 static int nvme_tcp_check_ddgst(struct nvme_tcp_queue *queue, void *pdu) in nvme_tcp_check_ddgst() argument
449 u8 digest_len = nvme_tcp_hdgst_len(queue); in nvme_tcp_check_ddgst()
456 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_check_ddgst()
458 nvme_tcp_queue_id(queue)); in nvme_tcp_check_ddgst()
461 crypto_ahash_init(queue->rcv_hash); in nvme_tcp_check_ddgst()
482 struct nvme_tcp_queue *queue = &ctrl->queues[queue_idx]; in nvme_tcp_init_request() local
483 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_init_request()
485 req->pdu = page_frag_alloc(&queue->pf_cache, in nvme_tcp_init_request()
492 req->queue = queue; in nvme_tcp_init_request()
503 struct nvme_tcp_queue *queue = &ctrl->queues[hctx_idx + 1]; in nvme_tcp_init_hctx() local
505 hctx->driver_data = queue; in nvme_tcp_init_hctx()
513 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_init_admin_hctx() local
515 hctx->driver_data = queue; in nvme_tcp_init_admin_hctx()
520 nvme_tcp_recv_state(struct nvme_tcp_queue *queue) in nvme_tcp_recv_state() argument
522 return (queue->pdu_remaining) ? NVME_TCP_RECV_PDU : in nvme_tcp_recv_state()
523 (queue->ddgst_remaining) ? NVME_TCP_RECV_DDGST : in nvme_tcp_recv_state()
527 static void nvme_tcp_init_recv_ctx(struct nvme_tcp_queue *queue) in nvme_tcp_init_recv_ctx() argument
529 queue->pdu_remaining = sizeof(struct nvme_tcp_rsp_pdu) + in nvme_tcp_init_recv_ctx()
530 nvme_tcp_hdgst_len(queue); in nvme_tcp_init_recv_ctx()
531 queue->pdu_offset = 0; in nvme_tcp_init_recv_ctx()
532 queue->data_remaining = -1; in nvme_tcp_init_recv_ctx()
533 queue->ddgst_remaining = 0; in nvme_tcp_init_recv_ctx()
545 static int nvme_tcp_process_nvme_cqe(struct nvme_tcp_queue *queue, in nvme_tcp_process_nvme_cqe() argument
551 rq = nvme_find_rq(nvme_tcp_tagset(queue), cqe->command_id); in nvme_tcp_process_nvme_cqe()
553 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_process_nvme_cqe()
555 cqe->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_process_nvme_cqe()
556 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_process_nvme_cqe()
566 queue->nr_cqe++; in nvme_tcp_process_nvme_cqe()
571 static int nvme_tcp_handle_c2h_data(struct nvme_tcp_queue *queue, in nvme_tcp_handle_c2h_data() argument
576 rq = nvme_find_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_handle_c2h_data()
578 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
580 pdu->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_handle_c2h_data()
585 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
587 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_handle_c2h_data()
591 queue->data_remaining = le32_to_cpu(pdu->data_length); in nvme_tcp_handle_c2h_data()
595 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_c2h_data()
597 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_handle_c2h_data()
598 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_handle_c2h_data()
605 static int nvme_tcp_handle_comp(struct nvme_tcp_queue *queue, in nvme_tcp_handle_comp() argument
617 if (unlikely(nvme_is_aen_req(nvme_tcp_queue_id(queue), in nvme_tcp_handle_comp()
619 nvme_complete_async_event(&queue->ctrl->ctrl, cqe->status, in nvme_tcp_handle_comp()
622 ret = nvme_tcp_process_nvme_cqe(queue, cqe); in nvme_tcp_handle_comp()
630 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_setup_h2c_data_pdu() local
633 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_setup_h2c_data_pdu()
634 u8 ddgst = nvme_tcp_ddgst_len(queue); in nvme_tcp_setup_h2c_data_pdu()
638 req->pdu_len = min(req->h2cdata_left, queue->maxh2cdata); in nvme_tcp_setup_h2c_data_pdu()
647 if (queue->hdr_digest) in nvme_tcp_setup_h2c_data_pdu()
649 if (queue->data_digest) in nvme_tcp_setup_h2c_data_pdu()
661 static int nvme_tcp_handle_r2t(struct nvme_tcp_queue *queue, in nvme_tcp_handle_r2t() argument
669 rq = nvme_find_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_handle_r2t()
671 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
673 pdu->command_id, nvme_tcp_queue_id(queue)); in nvme_tcp_handle_r2t()
679 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
686 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
693 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_handle_r2t()
710 static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb, in nvme_tcp_recv_pdu() argument
714 char *pdu = queue->pdu; in nvme_tcp_recv_pdu()
715 size_t rcv_len = min_t(size_t, *len, queue->pdu_remaining); in nvme_tcp_recv_pdu()
719 &pdu[queue->pdu_offset], rcv_len); in nvme_tcp_recv_pdu()
723 queue->pdu_remaining -= rcv_len; in nvme_tcp_recv_pdu()
724 queue->pdu_offset += rcv_len; in nvme_tcp_recv_pdu()
727 if (queue->pdu_remaining) in nvme_tcp_recv_pdu()
730 hdr = queue->pdu; in nvme_tcp_recv_pdu()
731 if (queue->hdr_digest) { in nvme_tcp_recv_pdu()
732 ret = nvme_tcp_verify_hdgst(queue, queue->pdu, hdr->hlen); in nvme_tcp_recv_pdu()
738 if (queue->data_digest) { in nvme_tcp_recv_pdu()
739 ret = nvme_tcp_check_ddgst(queue, queue->pdu); in nvme_tcp_recv_pdu()
746 return nvme_tcp_handle_c2h_data(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
748 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_recv_pdu()
749 return nvme_tcp_handle_comp(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
751 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_recv_pdu()
752 return nvme_tcp_handle_r2t(queue, (void *)queue->pdu); in nvme_tcp_recv_pdu()
754 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_pdu()
768 static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, in nvme_tcp_recv_data() argument
771 struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu; in nvme_tcp_recv_data()
773 nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id); in nvme_tcp_recv_data()
779 recv_len = min_t(size_t, *len, queue->data_remaining); in nvme_tcp_recv_data()
791 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_data()
793 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_recv_data()
794 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_recv_data()
804 if (queue->data_digest) in nvme_tcp_recv_data()
806 &req->iter, recv_len, queue->rcv_hash); in nvme_tcp_recv_data()
811 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_data()
813 nvme_tcp_queue_id(queue), rq->tag); in nvme_tcp_recv_data()
819 queue->data_remaining -= recv_len; in nvme_tcp_recv_data()
822 if (!queue->data_remaining) { in nvme_tcp_recv_data()
823 if (queue->data_digest) { in nvme_tcp_recv_data()
824 nvme_tcp_ddgst_final(queue->rcv_hash, &queue->exp_ddgst); in nvme_tcp_recv_data()
825 queue->ddgst_remaining = NVME_TCP_DIGEST_LENGTH; in nvme_tcp_recv_data()
830 queue->nr_cqe++; in nvme_tcp_recv_data()
832 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_recv_data()
839 static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue, in nvme_tcp_recv_ddgst() argument
842 struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu; in nvme_tcp_recv_ddgst()
843 char *ddgst = (char *)&queue->recv_ddgst; in nvme_tcp_recv_ddgst()
844 size_t recv_len = min_t(size_t, *len, queue->ddgst_remaining); in nvme_tcp_recv_ddgst()
845 off_t off = NVME_TCP_DIGEST_LENGTH - queue->ddgst_remaining; in nvme_tcp_recv_ddgst()
852 queue->ddgst_remaining -= recv_len; in nvme_tcp_recv_ddgst()
855 if (queue->ddgst_remaining) in nvme_tcp_recv_ddgst()
858 if (queue->recv_ddgst != 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()
865 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_ddgst()
867 le32_to_cpu(queue->recv_ddgst), in nvme_tcp_recv_ddgst()
868 le32_to_cpu(queue->exp_ddgst)); in nvme_tcp_recv_ddgst()
872 struct request *rq = nvme_cid_to_rq(nvme_tcp_tagset(queue), in nvme_tcp_recv_ddgst()
877 queue->nr_cqe++; in nvme_tcp_recv_ddgst()
880 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_recv_ddgst()
887 struct nvme_tcp_queue *queue = desc->arg.data; in nvme_tcp_recv_skb() local
891 if (unlikely(!queue->rd_enabled)) in nvme_tcp_recv_skb()
895 switch (nvme_tcp_recv_state(queue)) { in nvme_tcp_recv_skb()
897 result = nvme_tcp_recv_pdu(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
900 result = nvme_tcp_recv_data(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
903 result = nvme_tcp_recv_ddgst(queue, skb, &offset, &len); in nvme_tcp_recv_skb()
909 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_recv_skb()
911 queue->rd_enabled = false; in nvme_tcp_recv_skb()
912 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_recv_skb()
922 struct nvme_tcp_queue *queue; in nvme_tcp_data_ready() local
927 queue = sk->sk_user_data; in nvme_tcp_data_ready()
928 if (likely(queue && queue->rd_enabled) && in nvme_tcp_data_ready()
929 !test_bit(NVME_TCP_Q_POLLING, &queue->flags)) in nvme_tcp_data_ready()
930 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_data_ready()
936 struct nvme_tcp_queue *queue; in nvme_tcp_write_space() local
939 queue = sk->sk_user_data; in nvme_tcp_write_space()
940 if (likely(queue && sk_stream_is_writeable(sk))) { in nvme_tcp_write_space()
942 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_write_space()
949 struct nvme_tcp_queue *queue; in nvme_tcp_state_change() local
952 queue = sk->sk_user_data; in nvme_tcp_state_change()
953 if (!queue) in nvme_tcp_state_change()
962 nvme_tcp_error_recovery(&queue->ctrl->ctrl); in nvme_tcp_state_change()
965 dev_info(queue->ctrl->ctrl.device, in nvme_tcp_state_change()
967 nvme_tcp_queue_id(queue), sk->sk_state); in nvme_tcp_state_change()
970 queue->state_change(sk); in nvme_tcp_state_change()
975 static inline void nvme_tcp_done_send_req(struct nvme_tcp_queue *queue) in nvme_tcp_done_send_req() argument
977 queue->request = NULL; in nvme_tcp_done_send_req()
985 nvme_complete_async_event(&req->queue->ctrl->ctrl, in nvme_tcp_fail_request()
995 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_data() local
1011 if (last && !queue->data_digest && !nvme_tcp_queue_more(queue)) in nvme_tcp_try_send_data()
1021 ret = sock_sendmsg(queue->sock, &msg); in nvme_tcp_try_send_data()
1025 if (queue->data_digest) in nvme_tcp_try_send_data()
1026 nvme_tcp_ddgst_update(queue->snd_hash, page, in nvme_tcp_try_send_data()
1039 if (queue->data_digest) { in nvme_tcp_try_send_data()
1040 nvme_tcp_ddgst_final(queue->snd_hash, in nvme_tcp_try_send_data()
1048 nvme_tcp_done_send_req(queue); in nvme_tcp_try_send_data()
1058 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_cmd_pdu() local
1063 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_try_send_cmd_pdu()
1067 if (inline_data || nvme_tcp_queue_more(queue)) in nvme_tcp_try_send_cmd_pdu()
1072 if (queue->hdr_digest && !req->offset) in nvme_tcp_try_send_cmd_pdu()
1073 nvme_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvme_tcp_try_send_cmd_pdu()
1077 ret = sock_sendmsg(queue->sock, &msg); in nvme_tcp_try_send_cmd_pdu()
1085 if (queue->data_digest) in nvme_tcp_try_send_cmd_pdu()
1086 crypto_ahash_init(queue->snd_hash); in nvme_tcp_try_send_cmd_pdu()
1088 nvme_tcp_done_send_req(queue); in nvme_tcp_try_send_cmd_pdu()
1099 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_data_pdu() local
1103 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_try_send_data_pdu()
1107 if (queue->hdr_digest && !req->offset) in nvme_tcp_try_send_data_pdu()
1108 nvme_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvme_tcp_try_send_data_pdu()
1115 ret = sock_sendmsg(queue->sock, &msg); in nvme_tcp_try_send_data_pdu()
1122 if (queue->data_digest) in nvme_tcp_try_send_data_pdu()
1123 crypto_ahash_init(queue->snd_hash); in nvme_tcp_try_send_data_pdu()
1133 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_try_send_ddgst() local
1143 if (nvme_tcp_queue_more(queue)) in nvme_tcp_try_send_ddgst()
1148 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvme_tcp_try_send_ddgst()
1156 nvme_tcp_done_send_req(queue); in nvme_tcp_try_send_ddgst()
1164 static int nvme_tcp_try_send(struct nvme_tcp_queue *queue) in nvme_tcp_try_send() argument
1170 if (!queue->request) { in nvme_tcp_try_send()
1171 queue->request = nvme_tcp_fetch_request(queue); in nvme_tcp_try_send()
1172 if (!queue->request) in nvme_tcp_try_send()
1175 req = queue->request; in nvme_tcp_try_send()
1204 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_try_send()
1206 nvme_tcp_fail_request(queue->request); in nvme_tcp_try_send()
1207 nvme_tcp_done_send_req(queue); in nvme_tcp_try_send()
1214 static int nvme_tcp_try_recv(struct nvme_tcp_queue *queue) in nvme_tcp_try_recv() argument
1216 struct socket *sock = queue->sock; in nvme_tcp_try_recv()
1221 rd_desc.arg.data = queue; in nvme_tcp_try_recv()
1224 queue->nr_cqe = 0; in nvme_tcp_try_recv()
1232 struct nvme_tcp_queue *queue = in nvme_tcp_io_work() local
1240 if (mutex_trylock(&queue->send_mutex)) { in nvme_tcp_io_work()
1241 result = nvme_tcp_try_send(queue); in nvme_tcp_io_work()
1242 mutex_unlock(&queue->send_mutex); in nvme_tcp_io_work()
1249 result = nvme_tcp_try_recv(queue); in nvme_tcp_io_work()
1255 if (!pending || !queue->rd_enabled) in nvme_tcp_io_work()
1260 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_io_work()
1263 static void nvme_tcp_free_crypto(struct nvme_tcp_queue *queue) in nvme_tcp_free_crypto() argument
1265 struct crypto_ahash *tfm = crypto_ahash_reqtfm(queue->rcv_hash); in nvme_tcp_free_crypto()
1267 ahash_request_free(queue->rcv_hash); in nvme_tcp_free_crypto()
1268 ahash_request_free(queue->snd_hash); in nvme_tcp_free_crypto()
1272 static int nvme_tcp_alloc_crypto(struct nvme_tcp_queue *queue) in nvme_tcp_alloc_crypto() argument
1280 queue->snd_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvme_tcp_alloc_crypto()
1281 if (!queue->snd_hash) in nvme_tcp_alloc_crypto()
1283 ahash_request_set_callback(queue->snd_hash, 0, NULL, NULL); in nvme_tcp_alloc_crypto()
1285 queue->rcv_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvme_tcp_alloc_crypto()
1286 if (!queue->rcv_hash) in nvme_tcp_alloc_crypto()
1288 ahash_request_set_callback(queue->rcv_hash, 0, NULL, NULL); in nvme_tcp_alloc_crypto()
1292 ahash_request_free(queue->snd_hash); in nvme_tcp_alloc_crypto()
1307 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_alloc_async_req() local
1309 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_alloc_async_req()
1311 async->pdu = page_frag_alloc(&queue->pf_cache, in nvme_tcp_alloc_async_req()
1317 async->queue = &ctrl->queues[0]; in nvme_tcp_alloc_async_req()
1325 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_free_queue() local
1328 if (!test_and_clear_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) in nvme_tcp_free_queue()
1331 if (queue->hdr_digest || queue->data_digest) in nvme_tcp_free_queue()
1332 nvme_tcp_free_crypto(queue); in nvme_tcp_free_queue()
1334 if (queue->pf_cache.va) { in nvme_tcp_free_queue()
1335 page = virt_to_head_page(queue->pf_cache.va); in nvme_tcp_free_queue()
1336 __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); in nvme_tcp_free_queue()
1337 queue->pf_cache.va = NULL; in nvme_tcp_free_queue()
1341 sock_release(queue->sock); in nvme_tcp_free_queue()
1344 kfree(queue->pdu); in nvme_tcp_free_queue()
1345 mutex_destroy(&queue->send_mutex); in nvme_tcp_free_queue()
1346 mutex_destroy(&queue->queue_lock); in nvme_tcp_free_queue()
1349 static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue) in nvme_tcp_init_connection() argument
1376 if (queue->hdr_digest) in nvme_tcp_init_connection()
1378 if (queue->data_digest) in nvme_tcp_init_connection()
1383 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvme_tcp_init_connection()
1390 ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvme_tcp_init_connection()
1398 nvme_tcp_queue_id(queue), icresp->hdr.type); in nvme_tcp_init_connection()
1404 nvme_tcp_queue_id(queue), icresp->hdr.plen); in nvme_tcp_init_connection()
1410 nvme_tcp_queue_id(queue), icresp->pfv); in nvme_tcp_init_connection()
1415 if ((queue->data_digest && !ctrl_ddgst) || in nvme_tcp_init_connection()
1416 (!queue->data_digest && ctrl_ddgst)) { in nvme_tcp_init_connection()
1418 nvme_tcp_queue_id(queue), in nvme_tcp_init_connection()
1419 queue->data_digest ? "enabled" : "disabled", in nvme_tcp_init_connection()
1425 if ((queue->hdr_digest && !ctrl_hdgst) || in nvme_tcp_init_connection()
1426 (!queue->hdr_digest && ctrl_hdgst)) { in nvme_tcp_init_connection()
1428 nvme_tcp_queue_id(queue), in nvme_tcp_init_connection()
1429 queue->hdr_digest ? "enabled" : "disabled", in nvme_tcp_init_connection()
1436 nvme_tcp_queue_id(queue), icresp->cpda); in nvme_tcp_init_connection()
1443 nvme_tcp_queue_id(queue), maxh2cdata); in nvme_tcp_init_connection()
1446 queue->maxh2cdata = maxh2cdata; in nvme_tcp_init_connection()
1456 static bool nvme_tcp_admin_queue(struct nvme_tcp_queue *queue) in nvme_tcp_admin_queue() argument
1458 return nvme_tcp_queue_id(queue) == 0; in nvme_tcp_admin_queue()
1461 static bool nvme_tcp_default_queue(struct nvme_tcp_queue *queue) in nvme_tcp_default_queue() argument
1463 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_default_queue()
1464 int qid = nvme_tcp_queue_id(queue); in nvme_tcp_default_queue()
1466 return !nvme_tcp_admin_queue(queue) && in nvme_tcp_default_queue()
1470 static bool nvme_tcp_read_queue(struct nvme_tcp_queue *queue) in nvme_tcp_read_queue() argument
1472 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_read_queue()
1473 int qid = nvme_tcp_queue_id(queue); in nvme_tcp_read_queue()
1475 return !nvme_tcp_admin_queue(queue) && in nvme_tcp_read_queue()
1476 !nvme_tcp_default_queue(queue) && in nvme_tcp_read_queue()
1481 static bool nvme_tcp_poll_queue(struct nvme_tcp_queue *queue) in nvme_tcp_poll_queue() argument
1483 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_poll_queue()
1484 int qid = nvme_tcp_queue_id(queue); in nvme_tcp_poll_queue()
1486 return !nvme_tcp_admin_queue(queue) && in nvme_tcp_poll_queue()
1487 !nvme_tcp_default_queue(queue) && in nvme_tcp_poll_queue()
1488 !nvme_tcp_read_queue(queue) && in nvme_tcp_poll_queue()
1494 static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue) in nvme_tcp_set_queue_io_cpu() argument
1496 struct nvme_tcp_ctrl *ctrl = queue->ctrl; in nvme_tcp_set_queue_io_cpu()
1497 int qid = nvme_tcp_queue_id(queue); in nvme_tcp_set_queue_io_cpu()
1500 if (nvme_tcp_default_queue(queue)) in nvme_tcp_set_queue_io_cpu()
1502 else if (nvme_tcp_read_queue(queue)) in nvme_tcp_set_queue_io_cpu()
1504 else if (nvme_tcp_poll_queue(queue)) in nvme_tcp_set_queue_io_cpu()
1507 queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false); in nvme_tcp_set_queue_io_cpu()
1513 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_alloc_queue() local
1516 mutex_init(&queue->queue_lock); in nvme_tcp_alloc_queue()
1517 queue->ctrl = ctrl; in nvme_tcp_alloc_queue()
1518 init_llist_head(&queue->req_list); in nvme_tcp_alloc_queue()
1519 INIT_LIST_HEAD(&queue->send_list); in nvme_tcp_alloc_queue()
1520 mutex_init(&queue->send_mutex); in nvme_tcp_alloc_queue()
1521 INIT_WORK(&queue->io_work, nvme_tcp_io_work); in nvme_tcp_alloc_queue()
1524 queue->cmnd_capsule_len = nctrl->ioccsz * 16; in nvme_tcp_alloc_queue()
1526 queue->cmnd_capsule_len = sizeof(struct nvme_command) + in nvme_tcp_alloc_queue()
1530 IPPROTO_TCP, &queue->sock); in nvme_tcp_alloc_queue()
1537 nvme_tcp_reclassify_socket(queue->sock); in nvme_tcp_alloc_queue()
1540 tcp_sock_set_syncnt(queue->sock->sk, 1); in nvme_tcp_alloc_queue()
1543 tcp_sock_set_nodelay(queue->sock->sk); in nvme_tcp_alloc_queue()
1550 sock_no_linger(queue->sock->sk); in nvme_tcp_alloc_queue()
1553 sock_set_priority(queue->sock->sk, so_priority); in nvme_tcp_alloc_queue()
1557 ip_sock_set_tos(queue->sock->sk, nctrl->opts->tos); in nvme_tcp_alloc_queue()
1560 queue->sock->sk->sk_rcvtimeo = 10 * HZ; in nvme_tcp_alloc_queue()
1562 queue->sock->sk->sk_allocation = GFP_ATOMIC; in nvme_tcp_alloc_queue()
1563 queue->sock->sk->sk_use_task_frag = false; in nvme_tcp_alloc_queue()
1564 nvme_tcp_set_queue_io_cpu(queue); in nvme_tcp_alloc_queue()
1565 queue->request = NULL; in nvme_tcp_alloc_queue()
1566 queue->data_remaining = 0; in nvme_tcp_alloc_queue()
1567 queue->ddgst_remaining = 0; in nvme_tcp_alloc_queue()
1568 queue->pdu_remaining = 0; in nvme_tcp_alloc_queue()
1569 queue->pdu_offset = 0; in nvme_tcp_alloc_queue()
1570 sk_set_memalloc(queue->sock->sk); in nvme_tcp_alloc_queue()
1573 ret = kernel_bind(queue->sock, (struct sockaddr *)&ctrl->src_addr, in nvme_tcp_alloc_queue()
1587 ret = sock_setsockopt(queue->sock, SOL_SOCKET, SO_BINDTODEVICE, in nvme_tcp_alloc_queue()
1597 queue->hdr_digest = nctrl->opts->hdr_digest; in nvme_tcp_alloc_queue()
1598 queue->data_digest = nctrl->opts->data_digest; in nvme_tcp_alloc_queue()
1599 if (queue->hdr_digest || queue->data_digest) { in nvme_tcp_alloc_queue()
1600 ret = nvme_tcp_alloc_crypto(queue); in nvme_tcp_alloc_queue()
1609 nvme_tcp_hdgst_len(queue); in nvme_tcp_alloc_queue()
1610 queue->pdu = kmalloc(rcv_pdu_size, GFP_KERNEL); in nvme_tcp_alloc_queue()
1611 if (!queue->pdu) { in nvme_tcp_alloc_queue()
1617 nvme_tcp_queue_id(queue)); in nvme_tcp_alloc_queue()
1619 ret = kernel_connect(queue->sock, (struct sockaddr *)&ctrl->addr, in nvme_tcp_alloc_queue()
1627 ret = nvme_tcp_init_connection(queue); in nvme_tcp_alloc_queue()
1631 set_bit(NVME_TCP_Q_ALLOCATED, &queue->flags); in nvme_tcp_alloc_queue()
1636 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvme_tcp_alloc_queue()
1638 kfree(queue->pdu); in nvme_tcp_alloc_queue()
1640 if (queue->hdr_digest || queue->data_digest) in nvme_tcp_alloc_queue()
1641 nvme_tcp_free_crypto(queue); in nvme_tcp_alloc_queue()
1643 sock_release(queue->sock); in nvme_tcp_alloc_queue()
1644 queue->sock = NULL; in nvme_tcp_alloc_queue()
1646 mutex_destroy(&queue->send_mutex); in nvme_tcp_alloc_queue()
1647 mutex_destroy(&queue->queue_lock); in nvme_tcp_alloc_queue()
1651 static void nvme_tcp_restore_sock_ops(struct nvme_tcp_queue *queue) in nvme_tcp_restore_sock_ops() argument
1653 struct socket *sock = queue->sock; in nvme_tcp_restore_sock_ops()
1657 sock->sk->sk_data_ready = queue->data_ready; in nvme_tcp_restore_sock_ops()
1658 sock->sk->sk_state_change = queue->state_change; in nvme_tcp_restore_sock_ops()
1659 sock->sk->sk_write_space = queue->write_space; in nvme_tcp_restore_sock_ops()
1663 static void __nvme_tcp_stop_queue(struct nvme_tcp_queue *queue) in __nvme_tcp_stop_queue() argument
1665 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in __nvme_tcp_stop_queue()
1666 nvme_tcp_restore_sock_ops(queue); in __nvme_tcp_stop_queue()
1667 cancel_work_sync(&queue->io_work); in __nvme_tcp_stop_queue()
1673 struct nvme_tcp_queue *queue = &ctrl->queues[qid]; in nvme_tcp_stop_queue() local
1675 if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) in nvme_tcp_stop_queue()
1678 mutex_lock(&queue->queue_lock); in nvme_tcp_stop_queue()
1679 if (test_and_clear_bit(NVME_TCP_Q_LIVE, &queue->flags)) in nvme_tcp_stop_queue()
1680 __nvme_tcp_stop_queue(queue); in nvme_tcp_stop_queue()
1681 mutex_unlock(&queue->queue_lock); in nvme_tcp_stop_queue()
1684 static void nvme_tcp_setup_sock_ops(struct nvme_tcp_queue *queue) in nvme_tcp_setup_sock_ops() argument
1686 write_lock_bh(&queue->sock->sk->sk_callback_lock); in nvme_tcp_setup_sock_ops()
1687 queue->sock->sk->sk_user_data = queue; in nvme_tcp_setup_sock_ops()
1688 queue->state_change = queue->sock->sk->sk_state_change; in nvme_tcp_setup_sock_ops()
1689 queue->data_ready = queue->sock->sk->sk_data_ready; in nvme_tcp_setup_sock_ops()
1690 queue->write_space = queue->sock->sk->sk_write_space; in nvme_tcp_setup_sock_ops()
1691 queue->sock->sk->sk_data_ready = nvme_tcp_data_ready; in nvme_tcp_setup_sock_ops()
1692 queue->sock->sk->sk_state_change = nvme_tcp_state_change; in nvme_tcp_setup_sock_ops()
1693 queue->sock->sk->sk_write_space = nvme_tcp_write_space; in nvme_tcp_setup_sock_ops()
1695 queue->sock->sk->sk_ll_usec = 1; in nvme_tcp_setup_sock_ops()
1697 write_unlock_bh(&queue->sock->sk->sk_callback_lock); in nvme_tcp_setup_sock_ops()
1703 struct nvme_tcp_queue *queue = &ctrl->queues[idx]; in nvme_tcp_start_queue() local
1706 queue->rd_enabled = true; in nvme_tcp_start_queue()
1707 nvme_tcp_init_recv_ctx(queue); in nvme_tcp_start_queue()
1708 nvme_tcp_setup_sock_ops(queue); in nvme_tcp_start_queue()
1716 set_bit(NVME_TCP_Q_LIVE, &queue->flags); in nvme_tcp_start_queue()
1718 if (test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) in nvme_tcp_start_queue()
1719 __nvme_tcp_stop_queue(queue); in nvme_tcp_start_queue()
2213 static void nvme_tcp_set_sg_inline(struct nvme_tcp_queue *queue, in nvme_tcp_set_sg_inline() argument
2218 sg->addr = cpu_to_le64(queue->ctrl->ctrl.icdoff); in nvme_tcp_set_sg_inline()
2237 struct nvme_tcp_queue *queue = &ctrl->queues[0]; in nvme_tcp_submit_async_event() local
2240 u8 hdgst = nvme_tcp_hdgst_len(queue); in nvme_tcp_submit_async_event()
2244 if (queue->hdr_digest) in nvme_tcp_submit_async_event()
2265 struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl; in nvme_tcp_complete_timed_out()
2267 nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue)); in nvme_tcp_complete_timed_out()
2274 struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl; in nvme_tcp_timeout()
2277 int qid = nvme_tcp_queue_id(req->queue); in nvme_tcp_timeout()
2281 nvme_tcp_queue_id(req->queue), nvme_cid(rq), pdu->hdr.type, in nvme_tcp_timeout()
2310 static blk_status_t nvme_tcp_map_data(struct nvme_tcp_queue *queue, in nvme_tcp_map_data() argument
2323 nvme_tcp_set_sg_inline(queue, c, req->data_len); in nvme_tcp_map_data()
2335 struct nvme_tcp_queue *queue = req->queue; in nvme_tcp_setup_cmd_pdu() local
2336 u8 hdgst = nvme_tcp_hdgst_len(queue), ddgst = 0; in nvme_tcp_setup_cmd_pdu()
2362 if (queue->hdr_digest) in nvme_tcp_setup_cmd_pdu()
2364 if (queue->data_digest && req->pdu_len) { in nvme_tcp_setup_cmd_pdu()
2366 ddgst = nvme_tcp_ddgst_len(queue); in nvme_tcp_setup_cmd_pdu()
2373 ret = nvme_tcp_map_data(queue, rq); in nvme_tcp_setup_cmd_pdu()
2376 dev_err(queue->ctrl->ctrl.device, in nvme_tcp_setup_cmd_pdu()
2386 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_commit_rqs() local
2388 if (!llist_empty(&queue->req_list)) in nvme_tcp_commit_rqs()
2389 queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work); in nvme_tcp_commit_rqs()
2395 struct nvme_ns *ns = hctx->queue->queuedata; in nvme_tcp_queue_rq()
2396 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_queue_rq() local
2399 bool queue_ready = test_bit(NVME_TCP_Q_LIVE, &queue->flags); in nvme_tcp_queue_rq()
2402 if (!nvme_check_ready(&queue->ctrl->ctrl, rq, queue_ready)) in nvme_tcp_queue_rq()
2403 return nvme_fail_nonready_command(&queue->ctrl->ctrl, rq); in nvme_tcp_queue_rq()
2425 struct nvme_tcp_queue *queue = hctx->driver_data; in nvme_tcp_poll() local
2426 struct sock *sk = queue->sock->sk; in nvme_tcp_poll()
2428 if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags)) in nvme_tcp_poll()
2431 set_bit(NVME_TCP_Q_POLLING, &queue->flags); in nvme_tcp_poll()
2434 nvme_tcp_try_recv(queue); in nvme_tcp_poll()
2435 clear_bit(NVME_TCP_Q_POLLING, &queue->flags); in nvme_tcp_poll()
2436 return queue->nr_cqe; in nvme_tcp_poll()
2441 struct nvme_tcp_queue *queue = &to_tcp_ctrl(ctrl)->queues[0]; in nvme_tcp_get_address() local
2447 mutex_lock(&queue->queue_lock); in nvme_tcp_get_address()
2449 if (!test_bit(NVME_TCP_Q_LIVE, &queue->flags)) in nvme_tcp_get_address()
2451 ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src_addr); in nvme_tcp_get_address()
2459 mutex_unlock(&queue->queue_lock); in nvme_tcp_get_address()