Lines Matching refs:queue

66 	struct nvmet_tcp_queue		*queue;  member
169 static inline u16 nvmet_tcp_cmd_tag(struct nvmet_tcp_queue *queue, in nvmet_tcp_cmd_tag() argument
172 if (unlikely(!queue->nr_cmds)) { in nvmet_tcp_cmd_tag()
177 return cmd - queue->cmds; in nvmet_tcp_cmd_tag()
205 nvmet_tcp_get_cmd(struct nvmet_tcp_queue *queue) in nvmet_tcp_get_cmd() argument
209 cmd = list_first_entry_or_null(&queue->free_list, in nvmet_tcp_get_cmd()
225 if (unlikely(cmd == &cmd->queue->connect)) in nvmet_tcp_put_cmd()
228 list_add_tail(&cmd->entry, &cmd->queue->free_list); in nvmet_tcp_put_cmd()
231 static inline int queue_cpu(struct nvmet_tcp_queue *queue) in queue_cpu() argument
233 return queue->sock->sk->sk_incoming_cpu; in queue_cpu()
236 static inline u8 nvmet_tcp_hdgst_len(struct nvmet_tcp_queue *queue) in nvmet_tcp_hdgst_len() argument
238 return queue->hdr_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvmet_tcp_hdgst_len()
241 static inline u8 nvmet_tcp_ddgst_len(struct nvmet_tcp_queue *queue) in nvmet_tcp_ddgst_len() argument
243 return queue->data_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvmet_tcp_ddgst_len()
256 static int nvmet_tcp_verify_hdgst(struct nvmet_tcp_queue *queue, in nvmet_tcp_verify_hdgst() argument
265 queue->idx); in nvmet_tcp_verify_hdgst()
270 nvmet_tcp_hdgst(queue->rcv_hash, pdu, len); in nvmet_tcp_verify_hdgst()
274 queue->idx, le32_to_cpu(recv_digest), in nvmet_tcp_verify_hdgst()
282 static int nvmet_tcp_check_ddgst(struct nvmet_tcp_queue *queue, void *pdu) in nvmet_tcp_check_ddgst() argument
285 u8 digest_len = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_check_ddgst()
292 pr_err("queue %d: data digest flag is cleared\n", queue->idx); in nvmet_tcp_check_ddgst()
338 static void nvmet_tcp_fatal_error(struct nvmet_tcp_queue *queue) in nvmet_tcp_fatal_error() argument
340 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_fatal_error()
341 if (queue->nvme_sq.ctrl) in nvmet_tcp_fatal_error()
342 nvmet_ctrl_fatal_error(queue->nvme_sq.ctrl); in nvmet_tcp_fatal_error()
344 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_fatal_error()
347 static void nvmet_tcp_socket_error(struct nvmet_tcp_queue *queue, int status) in nvmet_tcp_socket_error() argument
350 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_socket_error()
352 nvmet_tcp_fatal_error(queue); in nvmet_tcp_socket_error()
403 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_c2h_data_pdu() local
404 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_c2h_data_pdu()
405 u8 ddgst = nvmet_tcp_ddgst_len(cmd->queue); in nvmet_setup_c2h_data_pdu()
411 pdu->hdr.flags = NVME_TCP_F_DATA_LAST | (queue->nvme_sq.sqhd_disabled ? in nvmet_setup_c2h_data_pdu()
422 if (queue->data_digest) { in nvmet_setup_c2h_data_pdu()
424 nvmet_tcp_calc_ddgst(queue->snd_hash, cmd); in nvmet_setup_c2h_data_pdu()
427 if (cmd->queue->hdr_digest) { in nvmet_setup_c2h_data_pdu()
429 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_c2h_data_pdu()
436 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_r2t_pdu() local
437 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_r2t_pdu()
449 pdu->ttag = nvmet_tcp_cmd_tag(cmd->queue, cmd); in nvmet_setup_r2t_pdu()
452 if (cmd->queue->hdr_digest) { in nvmet_setup_r2t_pdu()
454 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_r2t_pdu()
461 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_response_pdu() local
462 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_response_pdu()
472 if (cmd->queue->hdr_digest) { in nvmet_setup_response_pdu()
474 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_response_pdu()
478 static void nvmet_tcp_process_resp_list(struct nvmet_tcp_queue *queue) in nvmet_tcp_process_resp_list() argument
483 for (node = llist_del_all(&queue->resp_list); node; node = node->next) { in nvmet_tcp_process_resp_list()
485 list_add(&cmd->entry, &queue->resp_send_list); in nvmet_tcp_process_resp_list()
486 queue->send_list_len++; in nvmet_tcp_process_resp_list()
490 static struct nvmet_tcp_cmd *nvmet_tcp_fetch_cmd(struct nvmet_tcp_queue *queue) in nvmet_tcp_fetch_cmd() argument
492 queue->snd_cmd = list_first_entry_or_null(&queue->resp_send_list, in nvmet_tcp_fetch_cmd()
494 if (!queue->snd_cmd) { in nvmet_tcp_fetch_cmd()
495 nvmet_tcp_process_resp_list(queue); in nvmet_tcp_fetch_cmd()
496 queue->snd_cmd = in nvmet_tcp_fetch_cmd()
497 list_first_entry_or_null(&queue->resp_send_list, in nvmet_tcp_fetch_cmd()
499 if (unlikely(!queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
503 list_del_init(&queue->snd_cmd->entry); in nvmet_tcp_fetch_cmd()
504 queue->send_list_len--; in nvmet_tcp_fetch_cmd()
506 if (nvmet_tcp_need_data_out(queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
507 nvmet_setup_c2h_data_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
508 else if (nvmet_tcp_need_data_in(queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
509 nvmet_setup_r2t_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
511 nvmet_setup_response_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
513 return queue->snd_cmd; in nvmet_tcp_fetch_cmd()
520 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_queue_response() local
524 if (unlikely(cmd == queue->cmd)) { in nvmet_tcp_queue_response()
533 if (queue->rcv_state == NVMET_TCP_RECV_PDU && in nvmet_tcp_queue_response()
539 llist_add(&cmd->lentry, &queue->resp_list); in nvmet_tcp_queue_response()
540 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &cmd->queue->io_work); in nvmet_tcp_queue_response()
553 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_data_pdu()
557 ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->data_pdu), in nvmet_try_send_data_pdu()
576 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_try_send_data() local
584 if ((!last_in_batch && cmd->queue->send_list_len) || in nvmet_try_send_data()
586 queue->data_digest || !queue->nvme_sq.sqhd_disabled) in nvmet_try_send_data()
589 ret = kernel_sendpage(cmd->queue->sock, page, cmd->offset, in nvmet_try_send_data()
604 if (queue->data_digest) { in nvmet_try_send_data()
608 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_data()
609 cmd->queue->snd_cmd = NULL; in nvmet_try_send_data()
616 if (queue->nvme_sq.sqhd_disabled) in nvmet_try_send_data()
626 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_response()
631 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_response()
636 ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->rsp_pdu), in nvmet_try_send_response()
647 cmd->queue->snd_cmd = NULL; in nvmet_try_send_response()
654 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_r2t()
659 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_r2t()
664 ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->r2t_pdu), in nvmet_try_send_r2t()
674 cmd->queue->snd_cmd = NULL; in nvmet_try_send_r2t()
680 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_try_send_ddgst() local
689 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_ddgst()
694 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvmet_try_send_ddgst()
704 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_ddgst()
705 cmd->queue->snd_cmd = NULL; in nvmet_try_send_ddgst()
713 static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_send_one() argument
716 struct nvmet_tcp_cmd *cmd = queue->snd_cmd; in nvmet_tcp_try_send_one()
719 if (!cmd || queue->state == NVMET_TCP_Q_DISCONNECTING) { in nvmet_tcp_try_send_one()
720 cmd = nvmet_tcp_fetch_cmd(queue); in nvmet_tcp_try_send_one()
762 static int nvmet_tcp_try_send(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_send() argument
768 ret = nvmet_tcp_try_send_one(queue, i == budget - 1); in nvmet_tcp_try_send()
770 nvmet_tcp_socket_error(queue, ret); in nvmet_tcp_try_send()
781 static void nvmet_prepare_receive_pdu(struct nvmet_tcp_queue *queue) in nvmet_prepare_receive_pdu() argument
783 queue->offset = 0; in nvmet_prepare_receive_pdu()
784 queue->left = sizeof(struct nvme_tcp_hdr); in nvmet_prepare_receive_pdu()
785 queue->cmd = NULL; in nvmet_prepare_receive_pdu()
786 queue->rcv_state = NVMET_TCP_RECV_PDU; in nvmet_prepare_receive_pdu()
789 static void nvmet_tcp_free_crypto(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_crypto() argument
791 struct crypto_ahash *tfm = crypto_ahash_reqtfm(queue->rcv_hash); in nvmet_tcp_free_crypto()
793 ahash_request_free(queue->rcv_hash); in nvmet_tcp_free_crypto()
794 ahash_request_free(queue->snd_hash); in nvmet_tcp_free_crypto()
798 static int nvmet_tcp_alloc_crypto(struct nvmet_tcp_queue *queue) in nvmet_tcp_alloc_crypto() argument
806 queue->snd_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvmet_tcp_alloc_crypto()
807 if (!queue->snd_hash) in nvmet_tcp_alloc_crypto()
809 ahash_request_set_callback(queue->snd_hash, 0, NULL, NULL); in nvmet_tcp_alloc_crypto()
811 queue->rcv_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvmet_tcp_alloc_crypto()
812 if (!queue->rcv_hash) in nvmet_tcp_alloc_crypto()
814 ahash_request_set_callback(queue->rcv_hash, 0, NULL, NULL); in nvmet_tcp_alloc_crypto()
818 ahash_request_free(queue->snd_hash); in nvmet_tcp_alloc_crypto()
825 static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue) in nvmet_tcp_handle_icreq() argument
827 struct nvme_tcp_icreq_pdu *icreq = &queue->pdu.icreq; in nvmet_tcp_handle_icreq()
828 struct nvme_tcp_icresp_pdu *icresp = &queue->pdu.icresp; in nvmet_tcp_handle_icreq()
836 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_icreq()
840 pr_err("queue %d: bad pfv %d\n", queue->idx, icreq->pfv); in nvmet_tcp_handle_icreq()
845 pr_err("queue %d: unsupported hpda %d\n", queue->idx, in nvmet_tcp_handle_icreq()
850 queue->hdr_digest = !!(icreq->digest & NVME_TCP_HDR_DIGEST_ENABLE); in nvmet_tcp_handle_icreq()
851 queue->data_digest = !!(icreq->digest & NVME_TCP_DATA_DIGEST_ENABLE); in nvmet_tcp_handle_icreq()
852 if (queue->hdr_digest || queue->data_digest) { in nvmet_tcp_handle_icreq()
853 ret = nvmet_tcp_alloc_crypto(queue); in nvmet_tcp_handle_icreq()
866 if (queue->hdr_digest) in nvmet_tcp_handle_icreq()
868 if (queue->data_digest) in nvmet_tcp_handle_icreq()
873 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvmet_tcp_handle_icreq()
877 queue->state = NVMET_TCP_Q_LIVE; in nvmet_tcp_handle_icreq()
878 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_handle_icreq()
881 if (queue->hdr_digest || queue->data_digest) in nvmet_tcp_handle_icreq()
882 nvmet_tcp_free_crypto(queue); in nvmet_tcp_handle_icreq()
886 static void nvmet_tcp_handle_req_failure(struct nvmet_tcp_queue *queue, in nvmet_tcp_handle_req_failure() argument
901 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_handle_req_failure()
907 pr_err("queue %d: failed to map data\n", queue->idx); in nvmet_tcp_handle_req_failure()
908 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_req_failure()
912 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_handle_req_failure()
917 static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_handle_h2c_data_pdu() argument
919 struct nvme_tcp_data_pdu *data = &queue->pdu.data; in nvmet_tcp_handle_h2c_data_pdu()
922 if (likely(queue->nr_cmds)) { in nvmet_tcp_handle_h2c_data_pdu()
923 if (unlikely(data->ttag >= queue->nr_cmds)) { in nvmet_tcp_handle_h2c_data_pdu()
925 queue->idx, data->ttag, queue->nr_cmds); in nvmet_tcp_handle_h2c_data_pdu()
926 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_h2c_data_pdu()
929 cmd = &queue->cmds[data->ttag]; in nvmet_tcp_handle_h2c_data_pdu()
931 cmd = &queue->connect; in nvmet_tcp_handle_h2c_data_pdu()
947 queue->cmd = cmd; in nvmet_tcp_handle_h2c_data_pdu()
948 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_handle_h2c_data_pdu()
953 static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_done_recv_pdu() argument
955 struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr; in nvmet_tcp_done_recv_pdu()
956 struct nvme_command *nvme_cmd = &queue->pdu.cmd.cmd; in nvmet_tcp_done_recv_pdu()
960 if (unlikely(queue->state == NVMET_TCP_Q_CONNECTING)) { in nvmet_tcp_done_recv_pdu()
964 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
967 return nvmet_tcp_handle_icreq(queue); in nvmet_tcp_done_recv_pdu()
972 queue->idx, queue->state); in nvmet_tcp_done_recv_pdu()
973 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
978 ret = nvmet_tcp_handle_h2c_data_pdu(queue); in nvmet_tcp_done_recv_pdu()
984 queue->cmd = nvmet_tcp_get_cmd(queue); in nvmet_tcp_done_recv_pdu()
985 if (unlikely(!queue->cmd)) { in nvmet_tcp_done_recv_pdu()
988 queue->idx, queue->nr_cmds, queue->send_list_len, in nvmet_tcp_done_recv_pdu()
990 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
994 req = &queue->cmd->req; in nvmet_tcp_done_recv_pdu()
997 if (unlikely(!nvmet_req_init(req, &queue->nvme_cq, in nvmet_tcp_done_recv_pdu()
998 &queue->nvme_sq, &nvmet_tcp_ops))) { in nvmet_tcp_done_recv_pdu()
1004 nvmet_tcp_handle_req_failure(queue, queue->cmd, req); in nvmet_tcp_done_recv_pdu()
1008 ret = nvmet_tcp_map_data(queue->cmd); in nvmet_tcp_done_recv_pdu()
1010 pr_err("queue %d: failed to map data\n", queue->idx); in nvmet_tcp_done_recv_pdu()
1011 if (nvmet_tcp_has_inline_data(queue->cmd)) in nvmet_tcp_done_recv_pdu()
1012 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1019 if (nvmet_tcp_need_data_in(queue->cmd)) { in nvmet_tcp_done_recv_pdu()
1020 if (nvmet_tcp_has_inline_data(queue->cmd)) { in nvmet_tcp_done_recv_pdu()
1021 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_done_recv_pdu()
1022 nvmet_tcp_build_pdu_iovec(queue->cmd); in nvmet_tcp_done_recv_pdu()
1026 nvmet_tcp_queue_response(&queue->cmd->req); in nvmet_tcp_done_recv_pdu()
1030 queue->cmd->req.execute(&queue->cmd->req); in nvmet_tcp_done_recv_pdu()
1032 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_done_recv_pdu()
1064 static int nvmet_tcp_try_recv_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_pdu() argument
1066 struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr; in nvmet_tcp_try_recv_pdu()
1072 iov.iov_base = (void *)&queue->pdu + queue->offset; in nvmet_tcp_try_recv_pdu()
1073 iov.iov_len = queue->left; in nvmet_tcp_try_recv_pdu()
1074 len = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvmet_tcp_try_recv_pdu()
1079 queue->offset += len; in nvmet_tcp_try_recv_pdu()
1080 queue->left -= len; in nvmet_tcp_try_recv_pdu()
1081 if (queue->left) in nvmet_tcp_try_recv_pdu()
1084 if (queue->offset == sizeof(struct nvme_tcp_hdr)) { in nvmet_tcp_try_recv_pdu()
1085 u8 hdgst = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_try_recv_pdu()
1089 nvmet_tcp_fatal_error(queue); in nvmet_tcp_try_recv_pdu()
1098 queue->left = hdr->hlen - queue->offset + hdgst; in nvmet_tcp_try_recv_pdu()
1102 if (queue->hdr_digest && in nvmet_tcp_try_recv_pdu()
1103 nvmet_tcp_verify_hdgst(queue, &queue->pdu, hdr->hlen)) { in nvmet_tcp_try_recv_pdu()
1104 nvmet_tcp_fatal_error(queue); /* fatal */ in nvmet_tcp_try_recv_pdu()
1108 if (queue->data_digest && in nvmet_tcp_try_recv_pdu()
1109 nvmet_tcp_check_ddgst(queue, &queue->pdu)) { in nvmet_tcp_try_recv_pdu()
1110 nvmet_tcp_fatal_error(queue); /* fatal */ in nvmet_tcp_try_recv_pdu()
1114 return nvmet_tcp_done_recv_pdu(queue); in nvmet_tcp_try_recv_pdu()
1119 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_prep_recv_ddgst() local
1121 nvmet_tcp_calc_ddgst(queue->rcv_hash, cmd); in nvmet_tcp_prep_recv_ddgst()
1122 queue->offset = 0; in nvmet_tcp_prep_recv_ddgst()
1123 queue->left = NVME_TCP_DIGEST_LENGTH; in nvmet_tcp_prep_recv_ddgst()
1124 queue->rcv_state = NVMET_TCP_RECV_DDGST; in nvmet_tcp_prep_recv_ddgst()
1127 static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_data() argument
1129 struct nvmet_tcp_cmd *cmd = queue->cmd; in nvmet_tcp_try_recv_data()
1133 ret = sock_recvmsg(cmd->queue->sock, &cmd->recv_msg, in nvmet_tcp_try_recv_data()
1142 if (queue->data_digest) { in nvmet_tcp_try_recv_data()
1150 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_try_recv_data()
1154 static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_ddgst() argument
1156 struct nvmet_tcp_cmd *cmd = queue->cmd; in nvmet_tcp_try_recv_ddgst()
1160 .iov_base = (void *)&cmd->recv_ddgst + queue->offset, in nvmet_tcp_try_recv_ddgst()
1161 .iov_len = queue->left in nvmet_tcp_try_recv_ddgst()
1164 ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvmet_tcp_try_recv_ddgst()
1169 queue->offset += ret; in nvmet_tcp_try_recv_ddgst()
1170 queue->left -= ret; in nvmet_tcp_try_recv_ddgst()
1171 if (queue->left) in nvmet_tcp_try_recv_ddgst()
1174 if (queue->data_digest && cmd->exp_ddgst != cmd->recv_ddgst) { in nvmet_tcp_try_recv_ddgst()
1176 queue->idx, cmd->req.cmd->common.command_id, in nvmet_tcp_try_recv_ddgst()
1177 queue->pdu.cmd.hdr.type, le32_to_cpu(cmd->recv_ddgst), in nvmet_tcp_try_recv_ddgst()
1181 nvmet_tcp_fatal_error(queue); in nvmet_tcp_try_recv_ddgst()
1191 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_try_recv_ddgst()
1195 static int nvmet_tcp_try_recv_one(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_one() argument
1199 if (unlikely(queue->rcv_state == NVMET_TCP_RECV_ERR)) in nvmet_tcp_try_recv_one()
1202 if (queue->rcv_state == NVMET_TCP_RECV_PDU) { in nvmet_tcp_try_recv_one()
1203 result = nvmet_tcp_try_recv_pdu(queue); in nvmet_tcp_try_recv_one()
1208 if (queue->rcv_state == NVMET_TCP_RECV_DATA) { in nvmet_tcp_try_recv_one()
1209 result = nvmet_tcp_try_recv_data(queue); in nvmet_tcp_try_recv_one()
1214 if (queue->rcv_state == NVMET_TCP_RECV_DDGST) { in nvmet_tcp_try_recv_one()
1215 result = nvmet_tcp_try_recv_ddgst(queue); in nvmet_tcp_try_recv_one()
1229 static int nvmet_tcp_try_recv(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_recv() argument
1235 ret = nvmet_tcp_try_recv_one(queue); in nvmet_tcp_try_recv()
1237 nvmet_tcp_socket_error(queue, ret); in nvmet_tcp_try_recv()
1248 static void nvmet_tcp_schedule_release_queue(struct nvmet_tcp_queue *queue) in nvmet_tcp_schedule_release_queue() argument
1250 spin_lock(&queue->state_lock); in nvmet_tcp_schedule_release_queue()
1251 if (queue->state != NVMET_TCP_Q_DISCONNECTING) { in nvmet_tcp_schedule_release_queue()
1252 queue->state = NVMET_TCP_Q_DISCONNECTING; in nvmet_tcp_schedule_release_queue()
1253 queue_work(nvmet_wq, &queue->release_work); in nvmet_tcp_schedule_release_queue()
1255 spin_unlock(&queue->state_lock); in nvmet_tcp_schedule_release_queue()
1258 static inline void nvmet_tcp_arm_queue_deadline(struct nvmet_tcp_queue *queue) in nvmet_tcp_arm_queue_deadline() argument
1260 queue->poll_end = jiffies + usecs_to_jiffies(idle_poll_period_usecs); in nvmet_tcp_arm_queue_deadline()
1263 static bool nvmet_tcp_check_queue_deadline(struct nvmet_tcp_queue *queue, in nvmet_tcp_check_queue_deadline() argument
1270 nvmet_tcp_arm_queue_deadline(queue); in nvmet_tcp_check_queue_deadline()
1272 return !time_after(jiffies, queue->poll_end); in nvmet_tcp_check_queue_deadline()
1277 struct nvmet_tcp_queue *queue = in nvmet_tcp_io_work() local
1285 ret = nvmet_tcp_try_recv(queue, NVMET_TCP_RECV_BUDGET, &ops); in nvmet_tcp_io_work()
1291 ret = nvmet_tcp_try_send(queue, NVMET_TCP_SEND_BUDGET, &ops); in nvmet_tcp_io_work()
1303 if (nvmet_tcp_check_queue_deadline(queue, ops) || pending) in nvmet_tcp_io_work()
1304 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_io_work()
1307 static int nvmet_tcp_alloc_cmd(struct nvmet_tcp_queue *queue, in nvmet_tcp_alloc_cmd() argument
1310 u8 hdgst = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_alloc_cmd()
1312 c->queue = queue; in nvmet_tcp_alloc_cmd()
1313 c->req.port = queue->port->nport; in nvmet_tcp_alloc_cmd()
1315 c->cmd_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1321 c->rsp_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1327 c->data_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1332 c->r2t_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1339 list_add_tail(&c->entry, &queue->free_list); in nvmet_tcp_alloc_cmd()
1359 static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_alloc_cmds() argument
1362 int i, ret = -EINVAL, nr_cmds = queue->nr_cmds; in nvmet_tcp_alloc_cmds()
1369 ret = nvmet_tcp_alloc_cmd(queue, cmds + i); in nvmet_tcp_alloc_cmds()
1374 queue->cmds = cmds; in nvmet_tcp_alloc_cmds()
1385 static void nvmet_tcp_free_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_cmds() argument
1387 struct nvmet_tcp_cmd *cmds = queue->cmds; in nvmet_tcp_free_cmds()
1390 for (i = 0; i < queue->nr_cmds; i++) in nvmet_tcp_free_cmds()
1393 nvmet_tcp_free_cmd(&queue->connect); in nvmet_tcp_free_cmds()
1397 static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue) in nvmet_tcp_restore_socket_callbacks() argument
1399 struct socket *sock = queue->sock; in nvmet_tcp_restore_socket_callbacks()
1402 sock->sk->sk_data_ready = queue->data_ready; in nvmet_tcp_restore_socket_callbacks()
1403 sock->sk->sk_state_change = queue->state_change; in nvmet_tcp_restore_socket_callbacks()
1404 sock->sk->sk_write_space = queue->write_space; in nvmet_tcp_restore_socket_callbacks()
1409 static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_uninit_data_in_cmds() argument
1411 struct nvmet_tcp_cmd *cmd = queue->cmds; in nvmet_tcp_uninit_data_in_cmds()
1414 for (i = 0; i < queue->nr_cmds; i++, cmd++) { in nvmet_tcp_uninit_data_in_cmds()
1419 if (!queue->nr_cmds && nvmet_tcp_need_data_in(&queue->connect)) { in nvmet_tcp_uninit_data_in_cmds()
1421 nvmet_req_uninit(&queue->connect.req); in nvmet_tcp_uninit_data_in_cmds()
1425 static void nvmet_tcp_free_cmd_data_in_buffers(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_cmd_data_in_buffers() argument
1427 struct nvmet_tcp_cmd *cmd = queue->cmds; in nvmet_tcp_free_cmd_data_in_buffers()
1430 for (i = 0; i < queue->nr_cmds; i++, cmd++) { in nvmet_tcp_free_cmd_data_in_buffers()
1435 if (!queue->nr_cmds && nvmet_tcp_need_data_in(&queue->connect)) in nvmet_tcp_free_cmd_data_in_buffers()
1436 nvmet_tcp_free_cmd_buffers(&queue->connect); in nvmet_tcp_free_cmd_data_in_buffers()
1442 struct nvmet_tcp_queue *queue = in nvmet_tcp_release_queue_work() local
1446 list_del_init(&queue->queue_list); in nvmet_tcp_release_queue_work()
1449 nvmet_tcp_restore_socket_callbacks(queue); in nvmet_tcp_release_queue_work()
1450 cancel_work_sync(&queue->io_work); in nvmet_tcp_release_queue_work()
1452 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_release_queue_work()
1454 nvmet_tcp_uninit_data_in_cmds(queue); in nvmet_tcp_release_queue_work()
1455 nvmet_sq_destroy(&queue->nvme_sq); in nvmet_tcp_release_queue_work()
1456 cancel_work_sync(&queue->io_work); in nvmet_tcp_release_queue_work()
1457 nvmet_tcp_free_cmd_data_in_buffers(queue); in nvmet_tcp_release_queue_work()
1458 sock_release(queue->sock); in nvmet_tcp_release_queue_work()
1459 nvmet_tcp_free_cmds(queue); in nvmet_tcp_release_queue_work()
1460 if (queue->hdr_digest || queue->data_digest) in nvmet_tcp_release_queue_work()
1461 nvmet_tcp_free_crypto(queue); in nvmet_tcp_release_queue_work()
1462 ida_free(&nvmet_tcp_queue_ida, queue->idx); in nvmet_tcp_release_queue_work()
1464 page = virt_to_head_page(queue->pf_cache.va); in nvmet_tcp_release_queue_work()
1465 __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); in nvmet_tcp_release_queue_work()
1466 kfree(queue); in nvmet_tcp_release_queue_work()
1471 struct nvmet_tcp_queue *queue; in nvmet_tcp_data_ready() local
1474 queue = sk->sk_user_data; in nvmet_tcp_data_ready()
1475 if (likely(queue)) in nvmet_tcp_data_ready()
1476 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_data_ready()
1482 struct nvmet_tcp_queue *queue; in nvmet_tcp_write_space() local
1485 queue = sk->sk_user_data; in nvmet_tcp_write_space()
1486 if (unlikely(!queue)) in nvmet_tcp_write_space()
1489 if (unlikely(queue->state == NVMET_TCP_Q_CONNECTING)) { in nvmet_tcp_write_space()
1490 queue->write_space(sk); in nvmet_tcp_write_space()
1496 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_write_space()
1504 struct nvmet_tcp_queue *queue; in nvmet_tcp_state_change() local
1507 queue = sk->sk_user_data; in nvmet_tcp_state_change()
1508 if (!queue) in nvmet_tcp_state_change()
1519 nvmet_tcp_schedule_release_queue(queue); in nvmet_tcp_state_change()
1523 queue->idx, sk->sk_state); in nvmet_tcp_state_change()
1529 static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) in nvmet_tcp_set_queue_sock() argument
1531 struct socket *sock = queue->sock; in nvmet_tcp_set_queue_sock()
1536 (struct sockaddr *)&queue->sockaddr); in nvmet_tcp_set_queue_sock()
1541 (struct sockaddr *)&queue->sockaddr_peer); in nvmet_tcp_set_queue_sock()
1568 sock->sk->sk_user_data = queue; in nvmet_tcp_set_queue_sock()
1569 queue->data_ready = sock->sk->sk_data_ready; in nvmet_tcp_set_queue_sock()
1571 queue->state_change = sock->sk->sk_state_change; in nvmet_tcp_set_queue_sock()
1573 queue->write_space = sock->sk->sk_write_space; in nvmet_tcp_set_queue_sock()
1576 nvmet_tcp_arm_queue_deadline(queue); in nvmet_tcp_set_queue_sock()
1577 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_set_queue_sock()
1587 struct nvmet_tcp_queue *queue; in nvmet_tcp_alloc_queue() local
1590 queue = kzalloc(sizeof(*queue), GFP_KERNEL); in nvmet_tcp_alloc_queue()
1591 if (!queue) in nvmet_tcp_alloc_queue()
1594 INIT_WORK(&queue->release_work, nvmet_tcp_release_queue_work); in nvmet_tcp_alloc_queue()
1595 INIT_WORK(&queue->io_work, nvmet_tcp_io_work); in nvmet_tcp_alloc_queue()
1596 queue->sock = newsock; in nvmet_tcp_alloc_queue()
1597 queue->port = port; in nvmet_tcp_alloc_queue()
1598 queue->nr_cmds = 0; in nvmet_tcp_alloc_queue()
1599 spin_lock_init(&queue->state_lock); in nvmet_tcp_alloc_queue()
1600 queue->state = NVMET_TCP_Q_CONNECTING; in nvmet_tcp_alloc_queue()
1601 INIT_LIST_HEAD(&queue->free_list); in nvmet_tcp_alloc_queue()
1602 init_llist_head(&queue->resp_list); in nvmet_tcp_alloc_queue()
1603 INIT_LIST_HEAD(&queue->resp_send_list); in nvmet_tcp_alloc_queue()
1605 queue->idx = ida_alloc(&nvmet_tcp_queue_ida, GFP_KERNEL); in nvmet_tcp_alloc_queue()
1606 if (queue->idx < 0) { in nvmet_tcp_alloc_queue()
1607 ret = queue->idx; in nvmet_tcp_alloc_queue()
1611 ret = nvmet_tcp_alloc_cmd(queue, &queue->connect); in nvmet_tcp_alloc_queue()
1615 ret = nvmet_sq_init(&queue->nvme_sq); in nvmet_tcp_alloc_queue()
1619 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_alloc_queue()
1622 list_add_tail(&queue->queue_list, &nvmet_tcp_queue_list); in nvmet_tcp_alloc_queue()
1625 ret = nvmet_tcp_set_queue_sock(queue); in nvmet_tcp_alloc_queue()
1632 list_del_init(&queue->queue_list); in nvmet_tcp_alloc_queue()
1634 nvmet_sq_destroy(&queue->nvme_sq); in nvmet_tcp_alloc_queue()
1636 nvmet_tcp_free_cmd(&queue->connect); in nvmet_tcp_alloc_queue()
1638 ida_free(&nvmet_tcp_queue_ida, queue->idx); in nvmet_tcp_alloc_queue()
1640 kfree(queue); in nvmet_tcp_alloc_queue()
1761 struct nvmet_tcp_queue *queue; in nvmet_tcp_destroy_port_queues() local
1764 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_destroy_port_queues()
1765 if (queue->port == port) in nvmet_tcp_destroy_port_queues()
1766 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_destroy_port_queues()
1791 struct nvmet_tcp_queue *queue; in nvmet_tcp_delete_ctrl() local
1794 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_delete_ctrl()
1795 if (queue->nvme_sq.ctrl == ctrl) in nvmet_tcp_delete_ctrl()
1796 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_delete_ctrl()
1802 struct nvmet_tcp_queue *queue = in nvmet_tcp_install_queue() local
1810 queue->nr_cmds = sq->size * 2; in nvmet_tcp_install_queue()
1811 if (nvmet_tcp_alloc_cmds(queue)) in nvmet_tcp_install_queue()
1824 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_disc_port_addr() local
1826 sprintf(traddr, "%pISc", (struct sockaddr *)&queue->sockaddr); in nvmet_tcp_disc_port_addr()
1865 struct nvmet_tcp_queue *queue; in nvmet_tcp_exit() local
1871 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_exit()
1872 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_exit()