Lines Matching full:queue

56 	struct nvmet_tcp_queue		*queue;  member
158 static inline u16 nvmet_tcp_cmd_tag(struct nvmet_tcp_queue *queue, in nvmet_tcp_cmd_tag() argument
161 if (unlikely(!queue->nr_cmds)) { in nvmet_tcp_cmd_tag()
166 return cmd - queue->cmds; in nvmet_tcp_cmd_tag()
194 nvmet_tcp_get_cmd(struct nvmet_tcp_queue *queue) in nvmet_tcp_get_cmd() argument
198 cmd = list_first_entry_or_null(&queue->free_list, in nvmet_tcp_get_cmd()
214 if (unlikely(cmd == &cmd->queue->connect)) in nvmet_tcp_put_cmd()
217 list_add_tail(&cmd->entry, &cmd->queue->free_list); in nvmet_tcp_put_cmd()
220 static inline int queue_cpu(struct nvmet_tcp_queue *queue) in queue_cpu() argument
222 return queue->sock->sk->sk_incoming_cpu; in queue_cpu()
225 static inline u8 nvmet_tcp_hdgst_len(struct nvmet_tcp_queue *queue) in nvmet_tcp_hdgst_len() argument
227 return queue->hdr_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvmet_tcp_hdgst_len()
230 static inline u8 nvmet_tcp_ddgst_len(struct nvmet_tcp_queue *queue) in nvmet_tcp_ddgst_len() argument
232 return queue->data_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvmet_tcp_ddgst_len()
245 static int nvmet_tcp_verify_hdgst(struct nvmet_tcp_queue *queue, in nvmet_tcp_verify_hdgst() argument
253 pr_err("queue %d: header digest enabled but no header digest\n", in nvmet_tcp_verify_hdgst()
254 queue->idx); in nvmet_tcp_verify_hdgst()
259 nvmet_tcp_hdgst(queue->rcv_hash, pdu, len); in nvmet_tcp_verify_hdgst()
262 pr_err("queue %d: header digest error: recv %#x expected %#x\n", in nvmet_tcp_verify_hdgst()
263 queue->idx, le32_to_cpu(recv_digest), in nvmet_tcp_verify_hdgst()
271 static int nvmet_tcp_check_ddgst(struct nvmet_tcp_queue *queue, void *pdu) in nvmet_tcp_check_ddgst() argument
274 u8 digest_len = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_check_ddgst()
281 pr_err("queue %d: data digest flag is cleared\n", queue->idx); in nvmet_tcp_check_ddgst()
327 static void nvmet_tcp_fatal_error(struct nvmet_tcp_queue *queue) in nvmet_tcp_fatal_error() argument
329 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_fatal_error()
330 if (queue->nvme_sq.ctrl) in nvmet_tcp_fatal_error()
331 nvmet_ctrl_fatal_error(queue->nvme_sq.ctrl); in nvmet_tcp_fatal_error()
333 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_fatal_error()
336 static void nvmet_tcp_socket_error(struct nvmet_tcp_queue *queue, int status) in nvmet_tcp_socket_error() argument
339 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_socket_error()
341 nvmet_tcp_fatal_error(queue); in nvmet_tcp_socket_error()
392 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_c2h_data_pdu() local
393 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_c2h_data_pdu()
394 u8 ddgst = nvmet_tcp_ddgst_len(cmd->queue); in nvmet_setup_c2h_data_pdu()
400 pdu->hdr.flags = NVME_TCP_F_DATA_LAST | (queue->nvme_sq.sqhd_disabled ? in nvmet_setup_c2h_data_pdu()
411 if (queue->data_digest) { in nvmet_setup_c2h_data_pdu()
413 nvmet_tcp_ddgst(queue->snd_hash, cmd); in nvmet_setup_c2h_data_pdu()
416 if (cmd->queue->hdr_digest) { in nvmet_setup_c2h_data_pdu()
418 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_c2h_data_pdu()
425 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_r2t_pdu() local
426 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_r2t_pdu()
438 pdu->ttag = nvmet_tcp_cmd_tag(cmd->queue, cmd); in nvmet_setup_r2t_pdu()
441 if (cmd->queue->hdr_digest) { in nvmet_setup_r2t_pdu()
443 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_r2t_pdu()
450 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_response_pdu() local
451 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_response_pdu()
461 if (cmd->queue->hdr_digest) { in nvmet_setup_response_pdu()
463 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_response_pdu()
467 static void nvmet_tcp_process_resp_list(struct nvmet_tcp_queue *queue) in nvmet_tcp_process_resp_list() argument
472 for (node = llist_del_all(&queue->resp_list); node; node = node->next) { in nvmet_tcp_process_resp_list()
474 list_add(&cmd->entry, &queue->resp_send_list); in nvmet_tcp_process_resp_list()
475 queue->send_list_len++; in nvmet_tcp_process_resp_list()
479 static struct nvmet_tcp_cmd *nvmet_tcp_fetch_cmd(struct nvmet_tcp_queue *queue) in nvmet_tcp_fetch_cmd() argument
481 queue->snd_cmd = list_first_entry_or_null(&queue->resp_send_list, in nvmet_tcp_fetch_cmd()
483 if (!queue->snd_cmd) { in nvmet_tcp_fetch_cmd()
484 nvmet_tcp_process_resp_list(queue); in nvmet_tcp_fetch_cmd()
485 queue->snd_cmd = in nvmet_tcp_fetch_cmd()
486 list_first_entry_or_null(&queue->resp_send_list, in nvmet_tcp_fetch_cmd()
488 if (unlikely(!queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
492 list_del_init(&queue->snd_cmd->entry); in nvmet_tcp_fetch_cmd()
493 queue->send_list_len--; in nvmet_tcp_fetch_cmd()
495 if (nvmet_tcp_need_data_out(queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
496 nvmet_setup_c2h_data_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
497 else if (nvmet_tcp_need_data_in(queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
498 nvmet_setup_r2t_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
500 nvmet_setup_response_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
502 return queue->snd_cmd; in nvmet_tcp_fetch_cmd()
509 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_queue_response() local
511 llist_add(&cmd->lentry, &queue->resp_list); in nvmet_tcp_queue_response()
512 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &cmd->queue->io_work); in nvmet_tcp_queue_response()
517 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_data_pdu()
521 ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->data_pdu), in nvmet_try_send_data_pdu()
540 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_try_send_data() local
548 if ((!last_in_batch && cmd->queue->send_list_len) || in nvmet_try_send_data()
550 queue->data_digest || !queue->nvme_sq.sqhd_disabled) in nvmet_try_send_data()
553 ret = kernel_sendpage(cmd->queue->sock, page, cmd->offset, in nvmet_try_send_data()
568 if (queue->data_digest) { in nvmet_try_send_data()
572 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_data()
573 cmd->queue->snd_cmd = NULL; in nvmet_try_send_data()
580 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_data()
592 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_response()
597 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_response()
602 ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->rsp_pdu), in nvmet_try_send_response()
614 cmd->queue->snd_cmd = NULL; in nvmet_try_send_response()
621 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_r2t()
626 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_r2t()
631 ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->r2t_pdu), in nvmet_try_send_r2t()
641 cmd->queue->snd_cmd = NULL; in nvmet_try_send_r2t()
647 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_try_send_ddgst() local
655 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_ddgst()
660 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvmet_try_send_ddgst()
666 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_ddgst()
667 cmd->queue->snd_cmd = NULL; in nvmet_try_send_ddgst()
675 static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_send_one() argument
678 struct nvmet_tcp_cmd *cmd = queue->snd_cmd; in nvmet_tcp_try_send_one()
681 if (!cmd || queue->state == NVMET_TCP_Q_DISCONNECTING) { in nvmet_tcp_try_send_one()
682 cmd = nvmet_tcp_fetch_cmd(queue); in nvmet_tcp_try_send_one()
724 static int nvmet_tcp_try_send(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_send() argument
730 ret = nvmet_tcp_try_send_one(queue, i == budget - 1); in nvmet_tcp_try_send()
732 nvmet_tcp_socket_error(queue, ret); in nvmet_tcp_try_send()
743 static void nvmet_prepare_receive_pdu(struct nvmet_tcp_queue *queue) in nvmet_prepare_receive_pdu() argument
745 queue->offset = 0; in nvmet_prepare_receive_pdu()
746 queue->left = sizeof(struct nvme_tcp_hdr); in nvmet_prepare_receive_pdu()
747 queue->cmd = NULL; in nvmet_prepare_receive_pdu()
748 queue->rcv_state = NVMET_TCP_RECV_PDU; in nvmet_prepare_receive_pdu()
751 static void nvmet_tcp_free_crypto(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_crypto() argument
753 struct crypto_ahash *tfm = crypto_ahash_reqtfm(queue->rcv_hash); in nvmet_tcp_free_crypto()
755 ahash_request_free(queue->rcv_hash); in nvmet_tcp_free_crypto()
756 ahash_request_free(queue->snd_hash); in nvmet_tcp_free_crypto()
760 static int nvmet_tcp_alloc_crypto(struct nvmet_tcp_queue *queue) in nvmet_tcp_alloc_crypto() argument
768 queue->snd_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvmet_tcp_alloc_crypto()
769 if (!queue->snd_hash) in nvmet_tcp_alloc_crypto()
771 ahash_request_set_callback(queue->snd_hash, 0, NULL, NULL); in nvmet_tcp_alloc_crypto()
773 queue->rcv_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvmet_tcp_alloc_crypto()
774 if (!queue->rcv_hash) in nvmet_tcp_alloc_crypto()
776 ahash_request_set_callback(queue->rcv_hash, 0, NULL, NULL); in nvmet_tcp_alloc_crypto()
780 ahash_request_free(queue->snd_hash); in nvmet_tcp_alloc_crypto()
787 static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue) in nvmet_tcp_handle_icreq() argument
789 struct nvme_tcp_icreq_pdu *icreq = &queue->pdu.icreq; in nvmet_tcp_handle_icreq()
790 struct nvme_tcp_icresp_pdu *icresp = &queue->pdu.icresp; in nvmet_tcp_handle_icreq()
798 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_icreq()
802 pr_err("queue %d: bad pfv %d\n", queue->idx, icreq->pfv); in nvmet_tcp_handle_icreq()
807 pr_err("queue %d: unsupported hpda %d\n", queue->idx, in nvmet_tcp_handle_icreq()
812 queue->hdr_digest = !!(icreq->digest & NVME_TCP_HDR_DIGEST_ENABLE); in nvmet_tcp_handle_icreq()
813 queue->data_digest = !!(icreq->digest & NVME_TCP_DATA_DIGEST_ENABLE); in nvmet_tcp_handle_icreq()
814 if (queue->hdr_digest || queue->data_digest) { in nvmet_tcp_handle_icreq()
815 ret = nvmet_tcp_alloc_crypto(queue); in nvmet_tcp_handle_icreq()
828 if (queue->hdr_digest) in nvmet_tcp_handle_icreq()
830 if (queue->data_digest) in nvmet_tcp_handle_icreq()
835 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvmet_tcp_handle_icreq()
839 queue->state = NVMET_TCP_Q_LIVE; in nvmet_tcp_handle_icreq()
840 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_handle_icreq()
843 if (queue->hdr_digest || queue->data_digest) in nvmet_tcp_handle_icreq()
844 nvmet_tcp_free_crypto(queue); in nvmet_tcp_handle_icreq()
848 static void nvmet_tcp_handle_req_failure(struct nvmet_tcp_queue *queue, in nvmet_tcp_handle_req_failure() argument
856 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_handle_req_failure()
862 pr_err("queue %d: failed to map data\n", queue->idx); in nvmet_tcp_handle_req_failure()
863 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_req_failure()
867 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_handle_req_failure()
872 static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_handle_h2c_data_pdu() argument
874 struct nvme_tcp_data_pdu *data = &queue->pdu.data; in nvmet_tcp_handle_h2c_data_pdu()
877 if (likely(queue->nr_cmds)) in nvmet_tcp_handle_h2c_data_pdu()
878 cmd = &queue->cmds[data->ttag]; in nvmet_tcp_handle_h2c_data_pdu()
880 cmd = &queue->connect; in nvmet_tcp_handle_h2c_data_pdu()
895 queue->cmd = cmd; in nvmet_tcp_handle_h2c_data_pdu()
896 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_handle_h2c_data_pdu()
901 static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_done_recv_pdu() argument
903 struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr; in nvmet_tcp_done_recv_pdu()
904 struct nvme_command *nvme_cmd = &queue->pdu.cmd.cmd; in nvmet_tcp_done_recv_pdu()
908 if (unlikely(queue->state == NVMET_TCP_Q_CONNECTING)) { in nvmet_tcp_done_recv_pdu()
912 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
915 return nvmet_tcp_handle_icreq(queue); in nvmet_tcp_done_recv_pdu()
919 ret = nvmet_tcp_handle_h2c_data_pdu(queue); in nvmet_tcp_done_recv_pdu()
925 queue->cmd = nvmet_tcp_get_cmd(queue); in nvmet_tcp_done_recv_pdu()
926 if (unlikely(!queue->cmd)) { in nvmet_tcp_done_recv_pdu()
928 pr_err("queue %d: out of commands (%d) send_list_len: %d, opcode: %d", in nvmet_tcp_done_recv_pdu()
929 queue->idx, queue->nr_cmds, queue->send_list_len, in nvmet_tcp_done_recv_pdu()
931 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
935 req = &queue->cmd->req; in nvmet_tcp_done_recv_pdu()
938 if (unlikely(!nvmet_req_init(req, &queue->nvme_cq, in nvmet_tcp_done_recv_pdu()
939 &queue->nvme_sq, &nvmet_tcp_ops))) { in nvmet_tcp_done_recv_pdu()
945 nvmet_tcp_handle_req_failure(queue, queue->cmd, req); in nvmet_tcp_done_recv_pdu()
949 ret = nvmet_tcp_map_data(queue->cmd); in nvmet_tcp_done_recv_pdu()
951 pr_err("queue %d: failed to map data\n", queue->idx); in nvmet_tcp_done_recv_pdu()
952 if (nvmet_tcp_has_inline_data(queue->cmd)) in nvmet_tcp_done_recv_pdu()
953 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
960 if (nvmet_tcp_need_data_in(queue->cmd)) { in nvmet_tcp_done_recv_pdu()
961 if (nvmet_tcp_has_inline_data(queue->cmd)) { in nvmet_tcp_done_recv_pdu()
962 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_done_recv_pdu()
963 nvmet_tcp_map_pdu_iovec(queue->cmd); in nvmet_tcp_done_recv_pdu()
967 nvmet_tcp_queue_response(&queue->cmd->req); in nvmet_tcp_done_recv_pdu()
971 queue->cmd->req.execute(&queue->cmd->req); in nvmet_tcp_done_recv_pdu()
973 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_done_recv_pdu()
1005 static int nvmet_tcp_try_recv_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_pdu() argument
1007 struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr; in nvmet_tcp_try_recv_pdu()
1013 iov.iov_base = (void *)&queue->pdu + queue->offset; in nvmet_tcp_try_recv_pdu()
1014 iov.iov_len = queue->left; in nvmet_tcp_try_recv_pdu()
1015 len = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvmet_tcp_try_recv_pdu()
1020 queue->offset += len; in nvmet_tcp_try_recv_pdu()
1021 queue->left -= len; in nvmet_tcp_try_recv_pdu()
1022 if (queue->left) in nvmet_tcp_try_recv_pdu()
1025 if (queue->offset == sizeof(struct nvme_tcp_hdr)) { in nvmet_tcp_try_recv_pdu()
1026 u8 hdgst = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_try_recv_pdu()
1030 nvmet_tcp_fatal_error(queue); in nvmet_tcp_try_recv_pdu()
1039 queue->left = hdr->hlen - queue->offset + hdgst; in nvmet_tcp_try_recv_pdu()
1043 if (queue->hdr_digest && in nvmet_tcp_try_recv_pdu()
1044 nvmet_tcp_verify_hdgst(queue, &queue->pdu, queue->offset)) { in nvmet_tcp_try_recv_pdu()
1045 nvmet_tcp_fatal_error(queue); /* fatal */ in nvmet_tcp_try_recv_pdu()
1049 if (queue->data_digest && in nvmet_tcp_try_recv_pdu()
1050 nvmet_tcp_check_ddgst(queue, &queue->pdu)) { in nvmet_tcp_try_recv_pdu()
1051 nvmet_tcp_fatal_error(queue); /* fatal */ in nvmet_tcp_try_recv_pdu()
1055 return nvmet_tcp_done_recv_pdu(queue); in nvmet_tcp_try_recv_pdu()
1060 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_prep_recv_ddgst() local
1062 nvmet_tcp_ddgst(queue->rcv_hash, cmd); in nvmet_tcp_prep_recv_ddgst()
1063 queue->offset = 0; in nvmet_tcp_prep_recv_ddgst()
1064 queue->left = NVME_TCP_DIGEST_LENGTH; in nvmet_tcp_prep_recv_ddgst()
1065 queue->rcv_state = NVMET_TCP_RECV_DDGST; in nvmet_tcp_prep_recv_ddgst()
1068 static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_data() argument
1070 struct nvmet_tcp_cmd *cmd = queue->cmd; in nvmet_tcp_try_recv_data()
1074 ret = sock_recvmsg(cmd->queue->sock, &cmd->recv_msg, in nvmet_tcp_try_recv_data()
1087 if (queue->data_digest) { in nvmet_tcp_try_recv_data()
1094 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_try_recv_data()
1098 static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_ddgst() argument
1100 struct nvmet_tcp_cmd *cmd = queue->cmd; in nvmet_tcp_try_recv_ddgst()
1104 .iov_base = (void *)&cmd->recv_ddgst + queue->offset, in nvmet_tcp_try_recv_ddgst()
1105 .iov_len = queue->left in nvmet_tcp_try_recv_ddgst()
1108 ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvmet_tcp_try_recv_ddgst()
1113 queue->offset += ret; in nvmet_tcp_try_recv_ddgst()
1114 queue->left -= ret; in nvmet_tcp_try_recv_ddgst()
1115 if (queue->left) in nvmet_tcp_try_recv_ddgst()
1118 if (queue->data_digest && cmd->exp_ddgst != cmd->recv_ddgst) { in nvmet_tcp_try_recv_ddgst()
1119 pr_err("queue %d: cmd %d pdu (%d) data digest error: recv %#x expected %#x\n", in nvmet_tcp_try_recv_ddgst()
1120 queue->idx, cmd->req.cmd->common.command_id, in nvmet_tcp_try_recv_ddgst()
1121 queue->pdu.cmd.hdr.type, le32_to_cpu(cmd->recv_ddgst), in nvmet_tcp_try_recv_ddgst()
1124 nvmet_tcp_fatal_error(queue); in nvmet_tcp_try_recv_ddgst()
1134 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_try_recv_ddgst()
1138 static int nvmet_tcp_try_recv_one(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_one() argument
1142 if (unlikely(queue->rcv_state == NVMET_TCP_RECV_ERR)) in nvmet_tcp_try_recv_one()
1145 if (queue->rcv_state == NVMET_TCP_RECV_PDU) { in nvmet_tcp_try_recv_one()
1146 result = nvmet_tcp_try_recv_pdu(queue); in nvmet_tcp_try_recv_one()
1151 if (queue->rcv_state == NVMET_TCP_RECV_DATA) { in nvmet_tcp_try_recv_one()
1152 result = nvmet_tcp_try_recv_data(queue); in nvmet_tcp_try_recv_one()
1157 if (queue->rcv_state == NVMET_TCP_RECV_DDGST) { in nvmet_tcp_try_recv_one()
1158 result = nvmet_tcp_try_recv_ddgst(queue); in nvmet_tcp_try_recv_one()
1172 static int nvmet_tcp_try_recv(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_recv() argument
1178 ret = nvmet_tcp_try_recv_one(queue); in nvmet_tcp_try_recv()
1180 nvmet_tcp_socket_error(queue, ret); in nvmet_tcp_try_recv()
1191 static void nvmet_tcp_schedule_release_queue(struct nvmet_tcp_queue *queue) in nvmet_tcp_schedule_release_queue() argument
1193 spin_lock(&queue->state_lock); in nvmet_tcp_schedule_release_queue()
1194 if (queue->state != NVMET_TCP_Q_DISCONNECTING) { in nvmet_tcp_schedule_release_queue()
1195 queue->state = NVMET_TCP_Q_DISCONNECTING; in nvmet_tcp_schedule_release_queue()
1196 schedule_work(&queue->release_work); in nvmet_tcp_schedule_release_queue()
1198 spin_unlock(&queue->state_lock); in nvmet_tcp_schedule_release_queue()
1203 struct nvmet_tcp_queue *queue = in nvmet_tcp_io_work() local
1211 ret = nvmet_tcp_try_recv(queue, NVMET_TCP_RECV_BUDGET, &ops); in nvmet_tcp_io_work()
1217 ret = nvmet_tcp_try_send(queue, NVMET_TCP_SEND_BUDGET, &ops); in nvmet_tcp_io_work()
1229 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_io_work()
1232 static int nvmet_tcp_alloc_cmd(struct nvmet_tcp_queue *queue, in nvmet_tcp_alloc_cmd() argument
1235 u8 hdgst = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_alloc_cmd()
1237 c->queue = queue; in nvmet_tcp_alloc_cmd()
1238 c->req.port = queue->port->nport; in nvmet_tcp_alloc_cmd()
1240 c->cmd_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1246 c->rsp_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1252 c->data_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1257 c->r2t_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1264 list_add_tail(&c->entry, &queue->free_list); in nvmet_tcp_alloc_cmd()
1284 static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_alloc_cmds() argument
1287 int i, ret = -EINVAL, nr_cmds = queue->nr_cmds; in nvmet_tcp_alloc_cmds()
1294 ret = nvmet_tcp_alloc_cmd(queue, cmds + i); in nvmet_tcp_alloc_cmds()
1299 queue->cmds = cmds; in nvmet_tcp_alloc_cmds()
1310 static void nvmet_tcp_free_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_cmds() argument
1312 struct nvmet_tcp_cmd *cmds = queue->cmds; in nvmet_tcp_free_cmds()
1315 for (i = 0; i < queue->nr_cmds; i++) in nvmet_tcp_free_cmds()
1318 nvmet_tcp_free_cmd(&queue->connect); in nvmet_tcp_free_cmds()
1322 static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue) in nvmet_tcp_restore_socket_callbacks() argument
1324 struct socket *sock = queue->sock; in nvmet_tcp_restore_socket_callbacks()
1327 sock->sk->sk_data_ready = queue->data_ready; in nvmet_tcp_restore_socket_callbacks()
1328 sock->sk->sk_state_change = queue->state_change; in nvmet_tcp_restore_socket_callbacks()
1329 sock->sk->sk_write_space = queue->write_space; in nvmet_tcp_restore_socket_callbacks()
1342 static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_uninit_data_in_cmds() argument
1344 struct nvmet_tcp_cmd *cmd = queue->cmds; in nvmet_tcp_uninit_data_in_cmds()
1347 for (i = 0; i < queue->nr_cmds; i++, cmd++) { in nvmet_tcp_uninit_data_in_cmds()
1352 if (!queue->nr_cmds && nvmet_tcp_need_data_in(&queue->connect)) { in nvmet_tcp_uninit_data_in_cmds()
1354 nvmet_tcp_finish_cmd(&queue->connect); in nvmet_tcp_uninit_data_in_cmds()
1360 struct nvmet_tcp_queue *queue = in nvmet_tcp_release_queue_work() local
1364 list_del_init(&queue->queue_list); in nvmet_tcp_release_queue_work()
1367 nvmet_tcp_restore_socket_callbacks(queue); in nvmet_tcp_release_queue_work()
1368 flush_work(&queue->io_work); in nvmet_tcp_release_queue_work()
1370 nvmet_tcp_uninit_data_in_cmds(queue); in nvmet_tcp_release_queue_work()
1371 nvmet_sq_destroy(&queue->nvme_sq); in nvmet_tcp_release_queue_work()
1372 cancel_work_sync(&queue->io_work); in nvmet_tcp_release_queue_work()
1373 sock_release(queue->sock); in nvmet_tcp_release_queue_work()
1374 nvmet_tcp_free_cmds(queue); in nvmet_tcp_release_queue_work()
1375 if (queue->hdr_digest || queue->data_digest) in nvmet_tcp_release_queue_work()
1376 nvmet_tcp_free_crypto(queue); in nvmet_tcp_release_queue_work()
1377 ida_simple_remove(&nvmet_tcp_queue_ida, queue->idx); in nvmet_tcp_release_queue_work()
1379 kfree(queue); in nvmet_tcp_release_queue_work()
1384 struct nvmet_tcp_queue *queue; in nvmet_tcp_data_ready() local
1387 queue = sk->sk_user_data; in nvmet_tcp_data_ready()
1388 if (likely(queue)) in nvmet_tcp_data_ready()
1389 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_data_ready()
1395 struct nvmet_tcp_queue *queue; in nvmet_tcp_write_space() local
1398 queue = sk->sk_user_data; in nvmet_tcp_write_space()
1399 if (unlikely(!queue)) in nvmet_tcp_write_space()
1402 if (unlikely(queue->state == NVMET_TCP_Q_CONNECTING)) { in nvmet_tcp_write_space()
1403 queue->write_space(sk); in nvmet_tcp_write_space()
1409 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_write_space()
1417 struct nvmet_tcp_queue *queue; in nvmet_tcp_state_change() local
1420 queue = sk->sk_user_data; in nvmet_tcp_state_change()
1421 if (!queue) in nvmet_tcp_state_change()
1430 nvmet_tcp_schedule_release_queue(queue); in nvmet_tcp_state_change()
1433 pr_warn("queue %d unhandled state %d\n", in nvmet_tcp_state_change()
1434 queue->idx, sk->sk_state); in nvmet_tcp_state_change()
1440 static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) in nvmet_tcp_set_queue_sock() argument
1442 struct socket *sock = queue->sock; in nvmet_tcp_set_queue_sock()
1447 (struct sockaddr *)&queue->sockaddr); in nvmet_tcp_set_queue_sock()
1452 (struct sockaddr *)&queue->sockaddr_peer); in nvmet_tcp_set_queue_sock()
1457 * Cleanup whatever is sitting in the TCP transmit queue on socket in nvmet_tcp_set_queue_sock()
1471 sock->sk->sk_user_data = queue; in nvmet_tcp_set_queue_sock()
1472 queue->data_ready = sock->sk->sk_data_ready; in nvmet_tcp_set_queue_sock()
1474 queue->state_change = sock->sk->sk_state_change; in nvmet_tcp_set_queue_sock()
1476 queue->write_space = sock->sk->sk_write_space; in nvmet_tcp_set_queue_sock()
1486 struct nvmet_tcp_queue *queue; in nvmet_tcp_alloc_queue() local
1489 queue = kzalloc(sizeof(*queue), GFP_KERNEL); in nvmet_tcp_alloc_queue()
1490 if (!queue) in nvmet_tcp_alloc_queue()
1493 INIT_WORK(&queue->release_work, nvmet_tcp_release_queue_work); in nvmet_tcp_alloc_queue()
1494 INIT_WORK(&queue->io_work, nvmet_tcp_io_work); in nvmet_tcp_alloc_queue()
1495 queue->sock = newsock; in nvmet_tcp_alloc_queue()
1496 queue->port = port; in nvmet_tcp_alloc_queue()
1497 queue->nr_cmds = 0; in nvmet_tcp_alloc_queue()
1498 spin_lock_init(&queue->state_lock); in nvmet_tcp_alloc_queue()
1499 queue->state = NVMET_TCP_Q_CONNECTING; in nvmet_tcp_alloc_queue()
1500 INIT_LIST_HEAD(&queue->free_list); in nvmet_tcp_alloc_queue()
1501 init_llist_head(&queue->resp_list); in nvmet_tcp_alloc_queue()
1502 INIT_LIST_HEAD(&queue->resp_send_list); in nvmet_tcp_alloc_queue()
1504 queue->idx = ida_simple_get(&nvmet_tcp_queue_ida, 0, 0, GFP_KERNEL); in nvmet_tcp_alloc_queue()
1505 if (queue->idx < 0) { in nvmet_tcp_alloc_queue()
1506 ret = queue->idx; in nvmet_tcp_alloc_queue()
1510 ret = nvmet_tcp_alloc_cmd(queue, &queue->connect); in nvmet_tcp_alloc_queue()
1514 ret = nvmet_sq_init(&queue->nvme_sq); in nvmet_tcp_alloc_queue()
1518 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_alloc_queue()
1521 list_add_tail(&queue->queue_list, &nvmet_tcp_queue_list); in nvmet_tcp_alloc_queue()
1524 ret = nvmet_tcp_set_queue_sock(queue); in nvmet_tcp_alloc_queue()
1528 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_alloc_queue()
1533 list_del_init(&queue->queue_list); in nvmet_tcp_alloc_queue()
1535 nvmet_sq_destroy(&queue->nvme_sq); in nvmet_tcp_alloc_queue()
1537 nvmet_tcp_free_cmd(&queue->connect); in nvmet_tcp_alloc_queue()
1539 ida_simple_remove(&nvmet_tcp_queue_ida, queue->idx); in nvmet_tcp_alloc_queue()
1541 kfree(queue); in nvmet_tcp_alloc_queue()
1561 pr_err("failed to allocate queue\n"); in nvmet_tcp_accept_work()
1676 struct nvmet_tcp_queue *queue; in nvmet_tcp_delete_ctrl() local
1679 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_delete_ctrl()
1680 if (queue->nvme_sq.ctrl == ctrl) in nvmet_tcp_delete_ctrl()
1681 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_delete_ctrl()
1687 struct nvmet_tcp_queue *queue = in nvmet_tcp_install_queue() local
1695 queue->nr_cmds = sq->size * 2; in nvmet_tcp_install_queue()
1696 if (nvmet_tcp_alloc_cmds(queue)) in nvmet_tcp_install_queue()
1709 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_disc_port_addr() local
1711 sprintf(traddr, "%pISc", (struct sockaddr *)&queue->sockaddr); in nvmet_tcp_disc_port_addr()
1749 struct nvmet_tcp_queue *queue; in nvmet_tcp_exit() local
1755 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_exit()
1756 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_exit()