Lines Matching refs:queue
94 struct nvmet_tcp_queue *queue; member
197 static inline u16 nvmet_tcp_cmd_tag(struct nvmet_tcp_queue *queue, in nvmet_tcp_cmd_tag() argument
200 if (unlikely(!queue->nr_cmds)) { in nvmet_tcp_cmd_tag()
205 return cmd - queue->cmds; in nvmet_tcp_cmd_tag()
233 nvmet_tcp_get_cmd(struct nvmet_tcp_queue *queue) in nvmet_tcp_get_cmd() argument
237 cmd = list_first_entry_or_null(&queue->free_list, in nvmet_tcp_get_cmd()
253 if (unlikely(cmd == &cmd->queue->connect)) in nvmet_tcp_put_cmd()
256 list_add_tail(&cmd->entry, &cmd->queue->free_list); in nvmet_tcp_put_cmd()
259 static inline int queue_cpu(struct nvmet_tcp_queue *queue) in queue_cpu() argument
261 return queue->sock->sk->sk_incoming_cpu; in queue_cpu()
264 static inline u8 nvmet_tcp_hdgst_len(struct nvmet_tcp_queue *queue) in nvmet_tcp_hdgst_len() argument
266 return queue->hdr_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvmet_tcp_hdgst_len()
269 static inline u8 nvmet_tcp_ddgst_len(struct nvmet_tcp_queue *queue) in nvmet_tcp_ddgst_len() argument
271 return queue->data_digest ? NVME_TCP_DIGEST_LENGTH : 0; in nvmet_tcp_ddgst_len()
284 static int nvmet_tcp_verify_hdgst(struct nvmet_tcp_queue *queue, in nvmet_tcp_verify_hdgst() argument
293 queue->idx); in nvmet_tcp_verify_hdgst()
298 nvmet_tcp_hdgst(queue->rcv_hash, pdu, len); in nvmet_tcp_verify_hdgst()
302 queue->idx, le32_to_cpu(recv_digest), in nvmet_tcp_verify_hdgst()
310 static int nvmet_tcp_check_ddgst(struct nvmet_tcp_queue *queue, void *pdu) in nvmet_tcp_check_ddgst() argument
313 u8 digest_len = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_check_ddgst()
320 pr_err("queue %d: data digest flag is cleared\n", queue->idx); in nvmet_tcp_check_ddgst()
366 static void nvmet_tcp_fatal_error(struct nvmet_tcp_queue *queue) in nvmet_tcp_fatal_error() argument
368 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_fatal_error()
369 if (queue->nvme_sq.ctrl) in nvmet_tcp_fatal_error()
370 nvmet_ctrl_fatal_error(queue->nvme_sq.ctrl); in nvmet_tcp_fatal_error()
372 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_fatal_error()
375 static void nvmet_tcp_socket_error(struct nvmet_tcp_queue *queue, int status) in nvmet_tcp_socket_error() argument
377 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_socket_error()
379 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_socket_error()
381 nvmet_tcp_fatal_error(queue); in nvmet_tcp_socket_error()
432 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_c2h_data_pdu() local
433 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_c2h_data_pdu()
434 u8 ddgst = nvmet_tcp_ddgst_len(cmd->queue); in nvmet_setup_c2h_data_pdu()
440 pdu->hdr.flags = NVME_TCP_F_DATA_LAST | (queue->nvme_sq.sqhd_disabled ? in nvmet_setup_c2h_data_pdu()
451 if (queue->data_digest) { in nvmet_setup_c2h_data_pdu()
453 nvmet_tcp_calc_ddgst(queue->snd_hash, cmd); in nvmet_setup_c2h_data_pdu()
456 if (cmd->queue->hdr_digest) { in nvmet_setup_c2h_data_pdu()
458 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_c2h_data_pdu()
465 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_r2t_pdu() local
466 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_r2t_pdu()
478 pdu->ttag = nvmet_tcp_cmd_tag(cmd->queue, cmd); in nvmet_setup_r2t_pdu()
481 if (cmd->queue->hdr_digest) { in nvmet_setup_r2t_pdu()
483 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_r2t_pdu()
490 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_response_pdu() local
491 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_response_pdu()
501 if (cmd->queue->hdr_digest) { in nvmet_setup_response_pdu()
503 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_response_pdu()
507 static void nvmet_tcp_process_resp_list(struct nvmet_tcp_queue *queue) in nvmet_tcp_process_resp_list() argument
512 for (node = llist_del_all(&queue->resp_list); node; node = node->next) { in nvmet_tcp_process_resp_list()
514 list_add(&cmd->entry, &queue->resp_send_list); in nvmet_tcp_process_resp_list()
515 queue->send_list_len++; in nvmet_tcp_process_resp_list()
519 static struct nvmet_tcp_cmd *nvmet_tcp_fetch_cmd(struct nvmet_tcp_queue *queue) in nvmet_tcp_fetch_cmd() argument
521 queue->snd_cmd = list_first_entry_or_null(&queue->resp_send_list, in nvmet_tcp_fetch_cmd()
523 if (!queue->snd_cmd) { in nvmet_tcp_fetch_cmd()
524 nvmet_tcp_process_resp_list(queue); in nvmet_tcp_fetch_cmd()
525 queue->snd_cmd = in nvmet_tcp_fetch_cmd()
526 list_first_entry_or_null(&queue->resp_send_list, in nvmet_tcp_fetch_cmd()
528 if (unlikely(!queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
532 list_del_init(&queue->snd_cmd->entry); in nvmet_tcp_fetch_cmd()
533 queue->send_list_len--; in nvmet_tcp_fetch_cmd()
535 if (nvmet_tcp_need_data_out(queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
536 nvmet_setup_c2h_data_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
537 else if (nvmet_tcp_need_data_in(queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
538 nvmet_setup_r2t_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
540 nvmet_setup_response_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
542 return queue->snd_cmd; in nvmet_tcp_fetch_cmd()
549 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_queue_response() local
553 if (unlikely(cmd == queue->cmd)) { in nvmet_tcp_queue_response()
562 if (queue->rcv_state == NVMET_TCP_RECV_PDU && in nvmet_tcp_queue_response()
568 llist_add(&cmd->lentry, &queue->resp_list); in nvmet_tcp_queue_response()
569 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &cmd->queue->io_work); in nvmet_tcp_queue_response()
586 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_data_pdu()
592 ret = sock_sendmsg(cmd->queue->sock, &msg); in nvmet_try_send_data_pdu()
609 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_try_send_data() local
620 if ((!last_in_batch && cmd->queue->send_list_len) || in nvmet_try_send_data()
622 queue->data_digest || !queue->nvme_sq.sqhd_disabled) in nvmet_try_send_data()
627 ret = sock_sendmsg(cmd->queue->sock, &msg); in nvmet_try_send_data()
641 if (queue->data_digest) { in nvmet_try_send_data()
645 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_data()
646 cmd->queue->snd_cmd = NULL; in nvmet_try_send_data()
653 if (queue->nvme_sq.sqhd_disabled) in nvmet_try_send_data()
665 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_response()
669 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_response()
676 ret = sock_sendmsg(cmd->queue->sock, &msg); in nvmet_try_send_response()
686 cmd->queue->snd_cmd = NULL; in nvmet_try_send_response()
695 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_r2t()
699 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_r2t()
706 ret = sock_sendmsg(cmd->queue->sock, &msg); in nvmet_try_send_r2t()
715 cmd->queue->snd_cmd = NULL; in nvmet_try_send_r2t()
721 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_try_send_ddgst() local
730 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_ddgst()
735 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvmet_try_send_ddgst()
745 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_ddgst()
746 cmd->queue->snd_cmd = NULL; in nvmet_try_send_ddgst()
754 static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_send_one() argument
757 struct nvmet_tcp_cmd *cmd = queue->snd_cmd; in nvmet_tcp_try_send_one()
760 if (!cmd || queue->state == NVMET_TCP_Q_DISCONNECTING) { in nvmet_tcp_try_send_one()
761 cmd = nvmet_tcp_fetch_cmd(queue); in nvmet_tcp_try_send_one()
803 static int nvmet_tcp_try_send(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_send() argument
809 ret = nvmet_tcp_try_send_one(queue, i == budget - 1); in nvmet_tcp_try_send()
811 nvmet_tcp_socket_error(queue, ret); in nvmet_tcp_try_send()
822 static void nvmet_prepare_receive_pdu(struct nvmet_tcp_queue *queue) in nvmet_prepare_receive_pdu() argument
824 queue->offset = 0; in nvmet_prepare_receive_pdu()
825 queue->left = sizeof(struct nvme_tcp_hdr); in nvmet_prepare_receive_pdu()
826 queue->cmd = NULL; in nvmet_prepare_receive_pdu()
827 queue->rcv_state = NVMET_TCP_RECV_PDU; in nvmet_prepare_receive_pdu()
830 static void nvmet_tcp_free_crypto(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_crypto() argument
832 struct crypto_ahash *tfm = crypto_ahash_reqtfm(queue->rcv_hash); in nvmet_tcp_free_crypto()
834 ahash_request_free(queue->rcv_hash); in nvmet_tcp_free_crypto()
835 ahash_request_free(queue->snd_hash); in nvmet_tcp_free_crypto()
839 static int nvmet_tcp_alloc_crypto(struct nvmet_tcp_queue *queue) in nvmet_tcp_alloc_crypto() argument
847 queue->snd_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvmet_tcp_alloc_crypto()
848 if (!queue->snd_hash) in nvmet_tcp_alloc_crypto()
850 ahash_request_set_callback(queue->snd_hash, 0, NULL, NULL); in nvmet_tcp_alloc_crypto()
852 queue->rcv_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvmet_tcp_alloc_crypto()
853 if (!queue->rcv_hash) in nvmet_tcp_alloc_crypto()
855 ahash_request_set_callback(queue->rcv_hash, 0, NULL, NULL); in nvmet_tcp_alloc_crypto()
859 ahash_request_free(queue->snd_hash); in nvmet_tcp_alloc_crypto()
866 static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue) in nvmet_tcp_handle_icreq() argument
868 struct nvme_tcp_icreq_pdu *icreq = &queue->pdu.icreq; in nvmet_tcp_handle_icreq()
869 struct nvme_tcp_icresp_pdu *icresp = &queue->pdu.icresp; in nvmet_tcp_handle_icreq()
877 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_icreq()
882 pr_err("queue %d: bad pfv %d\n", queue->idx, icreq->pfv); in nvmet_tcp_handle_icreq()
887 pr_err("queue %d: unsupported hpda %d\n", queue->idx, in nvmet_tcp_handle_icreq()
892 queue->hdr_digest = !!(icreq->digest & NVME_TCP_HDR_DIGEST_ENABLE); in nvmet_tcp_handle_icreq()
893 queue->data_digest = !!(icreq->digest & NVME_TCP_DATA_DIGEST_ENABLE); in nvmet_tcp_handle_icreq()
894 if (queue->hdr_digest || queue->data_digest) { in nvmet_tcp_handle_icreq()
895 ret = nvmet_tcp_alloc_crypto(queue); in nvmet_tcp_handle_icreq()
908 if (queue->hdr_digest) in nvmet_tcp_handle_icreq()
910 if (queue->data_digest) in nvmet_tcp_handle_icreq()
915 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvmet_tcp_handle_icreq()
919 queue->state = NVMET_TCP_Q_LIVE; in nvmet_tcp_handle_icreq()
920 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_handle_icreq()
924 static void nvmet_tcp_handle_req_failure(struct nvmet_tcp_queue *queue, in nvmet_tcp_handle_req_failure() argument
939 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_handle_req_failure()
945 pr_err("queue %d: failed to map data\n", queue->idx); in nvmet_tcp_handle_req_failure()
946 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_req_failure()
950 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_handle_req_failure()
955 static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_handle_h2c_data_pdu() argument
957 struct nvme_tcp_data_pdu *data = &queue->pdu.data; in nvmet_tcp_handle_h2c_data_pdu()
961 if (likely(queue->nr_cmds)) { in nvmet_tcp_handle_h2c_data_pdu()
962 if (unlikely(data->ttag >= queue->nr_cmds)) { in nvmet_tcp_handle_h2c_data_pdu()
964 queue->idx, data->ttag, queue->nr_cmds); in nvmet_tcp_handle_h2c_data_pdu()
965 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_h2c_data_pdu()
968 cmd = &queue->cmds[data->ttag]; in nvmet_tcp_handle_h2c_data_pdu()
970 cmd = &queue->connect; in nvmet_tcp_handle_h2c_data_pdu()
978 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_h2c_data_pdu()
983 nvmet_tcp_hdgst_len(queue) - in nvmet_tcp_handle_h2c_data_pdu()
984 nvmet_tcp_ddgst_len(queue) - in nvmet_tcp_handle_h2c_data_pdu()
993 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_h2c_data_pdu()
998 queue->cmd = cmd; in nvmet_tcp_handle_h2c_data_pdu()
999 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_handle_h2c_data_pdu()
1004 static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_done_recv_pdu() argument
1006 struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr; in nvmet_tcp_done_recv_pdu()
1007 struct nvme_command *nvme_cmd = &queue->pdu.cmd.cmd; in nvmet_tcp_done_recv_pdu()
1011 if (unlikely(queue->state == NVMET_TCP_Q_CONNECTING)) { in nvmet_tcp_done_recv_pdu()
1015 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1018 return nvmet_tcp_handle_icreq(queue); in nvmet_tcp_done_recv_pdu()
1023 queue->idx, queue->state); in nvmet_tcp_done_recv_pdu()
1024 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1029 ret = nvmet_tcp_handle_h2c_data_pdu(queue); in nvmet_tcp_done_recv_pdu()
1035 queue->cmd = nvmet_tcp_get_cmd(queue); in nvmet_tcp_done_recv_pdu()
1036 if (unlikely(!queue->cmd)) { in nvmet_tcp_done_recv_pdu()
1039 queue->idx, queue->nr_cmds, queue->send_list_len, in nvmet_tcp_done_recv_pdu()
1041 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1045 req = &queue->cmd->req; in nvmet_tcp_done_recv_pdu()
1048 if (unlikely(!nvmet_req_init(req, &queue->nvme_cq, in nvmet_tcp_done_recv_pdu()
1049 &queue->nvme_sq, &nvmet_tcp_ops))) { in nvmet_tcp_done_recv_pdu()
1055 nvmet_tcp_handle_req_failure(queue, queue->cmd, req); in nvmet_tcp_done_recv_pdu()
1059 ret = nvmet_tcp_map_data(queue->cmd); in nvmet_tcp_done_recv_pdu()
1061 pr_err("queue %d: failed to map data\n", queue->idx); in nvmet_tcp_done_recv_pdu()
1062 if (nvmet_tcp_has_inline_data(queue->cmd)) in nvmet_tcp_done_recv_pdu()
1063 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1070 if (nvmet_tcp_need_data_in(queue->cmd)) { in nvmet_tcp_done_recv_pdu()
1071 if (nvmet_tcp_has_inline_data(queue->cmd)) { in nvmet_tcp_done_recv_pdu()
1072 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_done_recv_pdu()
1073 nvmet_tcp_build_pdu_iovec(queue->cmd); in nvmet_tcp_done_recv_pdu()
1077 nvmet_tcp_queue_response(&queue->cmd->req); in nvmet_tcp_done_recv_pdu()
1081 queue->cmd->req.execute(&queue->cmd->req); in nvmet_tcp_done_recv_pdu()
1083 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_done_recv_pdu()
1115 static int nvmet_tcp_try_recv_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_pdu() argument
1117 struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr; in nvmet_tcp_try_recv_pdu()
1123 iov.iov_base = (void *)&queue->pdu + queue->offset; in nvmet_tcp_try_recv_pdu()
1124 iov.iov_len = queue->left; in nvmet_tcp_try_recv_pdu()
1125 len = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvmet_tcp_try_recv_pdu()
1130 queue->offset += len; in nvmet_tcp_try_recv_pdu()
1131 queue->left -= len; in nvmet_tcp_try_recv_pdu()
1132 if (queue->left) in nvmet_tcp_try_recv_pdu()
1135 if (queue->offset == sizeof(struct nvme_tcp_hdr)) { in nvmet_tcp_try_recv_pdu()
1136 u8 hdgst = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_try_recv_pdu()
1140 nvmet_tcp_fatal_error(queue); in nvmet_tcp_try_recv_pdu()
1149 queue->left = hdr->hlen - queue->offset + hdgst; in nvmet_tcp_try_recv_pdu()
1153 if (queue->hdr_digest && in nvmet_tcp_try_recv_pdu()
1154 nvmet_tcp_verify_hdgst(queue, &queue->pdu, hdr->hlen)) { in nvmet_tcp_try_recv_pdu()
1155 nvmet_tcp_fatal_error(queue); /* fatal */ in nvmet_tcp_try_recv_pdu()
1159 if (queue->data_digest && in nvmet_tcp_try_recv_pdu()
1160 nvmet_tcp_check_ddgst(queue, &queue->pdu)) { in nvmet_tcp_try_recv_pdu()
1161 nvmet_tcp_fatal_error(queue); /* fatal */ in nvmet_tcp_try_recv_pdu()
1165 return nvmet_tcp_done_recv_pdu(queue); in nvmet_tcp_try_recv_pdu()
1170 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_prep_recv_ddgst() local
1172 nvmet_tcp_calc_ddgst(queue->rcv_hash, cmd); in nvmet_tcp_prep_recv_ddgst()
1173 queue->offset = 0; in nvmet_tcp_prep_recv_ddgst()
1174 queue->left = NVME_TCP_DIGEST_LENGTH; in nvmet_tcp_prep_recv_ddgst()
1175 queue->rcv_state = NVMET_TCP_RECV_DDGST; in nvmet_tcp_prep_recv_ddgst()
1178 static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_data() argument
1180 struct nvmet_tcp_cmd *cmd = queue->cmd; in nvmet_tcp_try_recv_data()
1184 ret = sock_recvmsg(cmd->queue->sock, &cmd->recv_msg, in nvmet_tcp_try_recv_data()
1193 if (queue->data_digest) { in nvmet_tcp_try_recv_data()
1201 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_try_recv_data()
1205 static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_ddgst() argument
1207 struct nvmet_tcp_cmd *cmd = queue->cmd; in nvmet_tcp_try_recv_ddgst()
1211 .iov_base = (void *)&cmd->recv_ddgst + queue->offset, in nvmet_tcp_try_recv_ddgst()
1212 .iov_len = queue->left in nvmet_tcp_try_recv_ddgst()
1215 ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvmet_tcp_try_recv_ddgst()
1220 queue->offset += ret; in nvmet_tcp_try_recv_ddgst()
1221 queue->left -= ret; in nvmet_tcp_try_recv_ddgst()
1222 if (queue->left) in nvmet_tcp_try_recv_ddgst()
1225 if (queue->data_digest && cmd->exp_ddgst != cmd->recv_ddgst) { in nvmet_tcp_try_recv_ddgst()
1227 queue->idx, cmd->req.cmd->common.command_id, in nvmet_tcp_try_recv_ddgst()
1228 queue->pdu.cmd.hdr.type, le32_to_cpu(cmd->recv_ddgst), in nvmet_tcp_try_recv_ddgst()
1232 nvmet_tcp_fatal_error(queue); in nvmet_tcp_try_recv_ddgst()
1242 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_try_recv_ddgst()
1246 static int nvmet_tcp_try_recv_one(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_one() argument
1250 if (unlikely(queue->rcv_state == NVMET_TCP_RECV_ERR)) in nvmet_tcp_try_recv_one()
1253 if (queue->rcv_state == NVMET_TCP_RECV_PDU) { in nvmet_tcp_try_recv_one()
1254 result = nvmet_tcp_try_recv_pdu(queue); in nvmet_tcp_try_recv_one()
1259 if (queue->rcv_state == NVMET_TCP_RECV_DATA) { in nvmet_tcp_try_recv_one()
1260 result = nvmet_tcp_try_recv_data(queue); in nvmet_tcp_try_recv_one()
1265 if (queue->rcv_state == NVMET_TCP_RECV_DDGST) { in nvmet_tcp_try_recv_one()
1266 result = nvmet_tcp_try_recv_ddgst(queue); in nvmet_tcp_try_recv_one()
1280 static int nvmet_tcp_try_recv(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_recv() argument
1286 ret = nvmet_tcp_try_recv_one(queue); in nvmet_tcp_try_recv()
1288 nvmet_tcp_socket_error(queue, ret); in nvmet_tcp_try_recv()
1299 static void nvmet_tcp_schedule_release_queue(struct nvmet_tcp_queue *queue) in nvmet_tcp_schedule_release_queue() argument
1301 spin_lock(&queue->state_lock); in nvmet_tcp_schedule_release_queue()
1302 if (queue->state != NVMET_TCP_Q_DISCONNECTING) { in nvmet_tcp_schedule_release_queue()
1303 queue->state = NVMET_TCP_Q_DISCONNECTING; in nvmet_tcp_schedule_release_queue()
1304 queue_work(nvmet_wq, &queue->release_work); in nvmet_tcp_schedule_release_queue()
1306 spin_unlock(&queue->state_lock); in nvmet_tcp_schedule_release_queue()
1309 static inline void nvmet_tcp_arm_queue_deadline(struct nvmet_tcp_queue *queue) in nvmet_tcp_arm_queue_deadline() argument
1311 queue->poll_end = jiffies + usecs_to_jiffies(idle_poll_period_usecs); in nvmet_tcp_arm_queue_deadline()
1314 static bool nvmet_tcp_check_queue_deadline(struct nvmet_tcp_queue *queue, in nvmet_tcp_check_queue_deadline() argument
1321 nvmet_tcp_arm_queue_deadline(queue); in nvmet_tcp_check_queue_deadline()
1323 return !time_after(jiffies, queue->poll_end); in nvmet_tcp_check_queue_deadline()
1328 struct nvmet_tcp_queue *queue = in nvmet_tcp_io_work() local
1336 ret = nvmet_tcp_try_recv(queue, NVMET_TCP_RECV_BUDGET, &ops); in nvmet_tcp_io_work()
1342 ret = nvmet_tcp_try_send(queue, NVMET_TCP_SEND_BUDGET, &ops); in nvmet_tcp_io_work()
1354 if (nvmet_tcp_check_queue_deadline(queue, ops) || pending) in nvmet_tcp_io_work()
1355 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_io_work()
1358 static int nvmet_tcp_alloc_cmd(struct nvmet_tcp_queue *queue, in nvmet_tcp_alloc_cmd() argument
1361 u8 hdgst = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_alloc_cmd()
1363 c->queue = queue; in nvmet_tcp_alloc_cmd()
1364 c->req.port = queue->port->nport; in nvmet_tcp_alloc_cmd()
1366 c->cmd_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1372 c->rsp_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1378 c->data_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1383 c->r2t_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1390 list_add_tail(&c->entry, &queue->free_list); in nvmet_tcp_alloc_cmd()
1410 static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_alloc_cmds() argument
1413 int i, ret = -EINVAL, nr_cmds = queue->nr_cmds; in nvmet_tcp_alloc_cmds()
1420 ret = nvmet_tcp_alloc_cmd(queue, cmds + i); in nvmet_tcp_alloc_cmds()
1425 queue->cmds = cmds; in nvmet_tcp_alloc_cmds()
1436 static void nvmet_tcp_free_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_cmds() argument
1438 struct nvmet_tcp_cmd *cmds = queue->cmds; in nvmet_tcp_free_cmds()
1441 for (i = 0; i < queue->nr_cmds; i++) in nvmet_tcp_free_cmds()
1444 nvmet_tcp_free_cmd(&queue->connect); in nvmet_tcp_free_cmds()
1448 static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue) in nvmet_tcp_restore_socket_callbacks() argument
1450 struct socket *sock = queue->sock; in nvmet_tcp_restore_socket_callbacks()
1453 sock->sk->sk_data_ready = queue->data_ready; in nvmet_tcp_restore_socket_callbacks()
1454 sock->sk->sk_state_change = queue->state_change; in nvmet_tcp_restore_socket_callbacks()
1455 sock->sk->sk_write_space = queue->write_space; in nvmet_tcp_restore_socket_callbacks()
1460 static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_uninit_data_in_cmds() argument
1462 struct nvmet_tcp_cmd *cmd = queue->cmds; in nvmet_tcp_uninit_data_in_cmds()
1465 for (i = 0; i < queue->nr_cmds; i++, cmd++) { in nvmet_tcp_uninit_data_in_cmds()
1470 if (!queue->nr_cmds && nvmet_tcp_need_data_in(&queue->connect)) { in nvmet_tcp_uninit_data_in_cmds()
1472 nvmet_req_uninit(&queue->connect.req); in nvmet_tcp_uninit_data_in_cmds()
1476 static void nvmet_tcp_free_cmd_data_in_buffers(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_cmd_data_in_buffers() argument
1478 struct nvmet_tcp_cmd *cmd = queue->cmds; in nvmet_tcp_free_cmd_data_in_buffers()
1481 for (i = 0; i < queue->nr_cmds; i++, cmd++) in nvmet_tcp_free_cmd_data_in_buffers()
1483 nvmet_tcp_free_cmd_buffers(&queue->connect); in nvmet_tcp_free_cmd_data_in_buffers()
1489 struct nvmet_tcp_queue *queue = in nvmet_tcp_release_queue_work() local
1493 list_del_init(&queue->queue_list); in nvmet_tcp_release_queue_work()
1496 nvmet_tcp_restore_socket_callbacks(queue); in nvmet_tcp_release_queue_work()
1497 cancel_work_sync(&queue->io_work); in nvmet_tcp_release_queue_work()
1499 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_release_queue_work()
1501 nvmet_tcp_uninit_data_in_cmds(queue); in nvmet_tcp_release_queue_work()
1502 nvmet_sq_destroy(&queue->nvme_sq); in nvmet_tcp_release_queue_work()
1503 cancel_work_sync(&queue->io_work); in nvmet_tcp_release_queue_work()
1504 nvmet_tcp_free_cmd_data_in_buffers(queue); in nvmet_tcp_release_queue_work()
1505 sock_release(queue->sock); in nvmet_tcp_release_queue_work()
1506 nvmet_tcp_free_cmds(queue); in nvmet_tcp_release_queue_work()
1507 if (queue->hdr_digest || queue->data_digest) in nvmet_tcp_release_queue_work()
1508 nvmet_tcp_free_crypto(queue); in nvmet_tcp_release_queue_work()
1509 ida_free(&nvmet_tcp_queue_ida, queue->idx); in nvmet_tcp_release_queue_work()
1511 page = virt_to_head_page(queue->pf_cache.va); in nvmet_tcp_release_queue_work()
1512 __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); in nvmet_tcp_release_queue_work()
1513 kfree(queue); in nvmet_tcp_release_queue_work()
1518 struct nvmet_tcp_queue *queue; in nvmet_tcp_data_ready() local
1523 queue = sk->sk_user_data; in nvmet_tcp_data_ready()
1524 if (likely(queue)) in nvmet_tcp_data_ready()
1525 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_data_ready()
1531 struct nvmet_tcp_queue *queue; in nvmet_tcp_write_space() local
1534 queue = sk->sk_user_data; in nvmet_tcp_write_space()
1535 if (unlikely(!queue)) in nvmet_tcp_write_space()
1538 if (unlikely(queue->state == NVMET_TCP_Q_CONNECTING)) { in nvmet_tcp_write_space()
1539 queue->write_space(sk); in nvmet_tcp_write_space()
1545 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_write_space()
1553 struct nvmet_tcp_queue *queue; in nvmet_tcp_state_change() local
1556 queue = sk->sk_user_data; in nvmet_tcp_state_change()
1557 if (!queue) in nvmet_tcp_state_change()
1568 nvmet_tcp_schedule_release_queue(queue); in nvmet_tcp_state_change()
1572 queue->idx, sk->sk_state); in nvmet_tcp_state_change()
1578 static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) in nvmet_tcp_set_queue_sock() argument
1580 struct socket *sock = queue->sock; in nvmet_tcp_set_queue_sock()
1585 (struct sockaddr *)&queue->sockaddr); in nvmet_tcp_set_queue_sock()
1590 (struct sockaddr *)&queue->sockaddr_peer); in nvmet_tcp_set_queue_sock()
1617 sock->sk->sk_user_data = queue; in nvmet_tcp_set_queue_sock()
1618 queue->data_ready = sock->sk->sk_data_ready; in nvmet_tcp_set_queue_sock()
1620 queue->state_change = sock->sk->sk_state_change; in nvmet_tcp_set_queue_sock()
1622 queue->write_space = sock->sk->sk_write_space; in nvmet_tcp_set_queue_sock()
1625 nvmet_tcp_arm_queue_deadline(queue); in nvmet_tcp_set_queue_sock()
1626 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_set_queue_sock()
1636 struct nvmet_tcp_queue *queue; in nvmet_tcp_alloc_queue() local
1639 queue = kzalloc(sizeof(*queue), GFP_KERNEL); in nvmet_tcp_alloc_queue()
1640 if (!queue) in nvmet_tcp_alloc_queue()
1643 INIT_WORK(&queue->release_work, nvmet_tcp_release_queue_work); in nvmet_tcp_alloc_queue()
1644 INIT_WORK(&queue->io_work, nvmet_tcp_io_work); in nvmet_tcp_alloc_queue()
1645 queue->sock = newsock; in nvmet_tcp_alloc_queue()
1646 queue->port = port; in nvmet_tcp_alloc_queue()
1647 queue->nr_cmds = 0; in nvmet_tcp_alloc_queue()
1648 spin_lock_init(&queue->state_lock); in nvmet_tcp_alloc_queue()
1649 queue->state = NVMET_TCP_Q_CONNECTING; in nvmet_tcp_alloc_queue()
1650 INIT_LIST_HEAD(&queue->free_list); in nvmet_tcp_alloc_queue()
1651 init_llist_head(&queue->resp_list); in nvmet_tcp_alloc_queue()
1652 INIT_LIST_HEAD(&queue->resp_send_list); in nvmet_tcp_alloc_queue()
1654 queue->idx = ida_alloc(&nvmet_tcp_queue_ida, GFP_KERNEL); in nvmet_tcp_alloc_queue()
1655 if (queue->idx < 0) { in nvmet_tcp_alloc_queue()
1656 ret = queue->idx; in nvmet_tcp_alloc_queue()
1660 ret = nvmet_tcp_alloc_cmd(queue, &queue->connect); in nvmet_tcp_alloc_queue()
1664 ret = nvmet_sq_init(&queue->nvme_sq); in nvmet_tcp_alloc_queue()
1668 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_alloc_queue()
1671 list_add_tail(&queue->queue_list, &nvmet_tcp_queue_list); in nvmet_tcp_alloc_queue()
1674 ret = nvmet_tcp_set_queue_sock(queue); in nvmet_tcp_alloc_queue()
1681 list_del_init(&queue->queue_list); in nvmet_tcp_alloc_queue()
1683 nvmet_sq_destroy(&queue->nvme_sq); in nvmet_tcp_alloc_queue()
1685 nvmet_tcp_free_cmd(&queue->connect); in nvmet_tcp_alloc_queue()
1687 ida_free(&nvmet_tcp_queue_ida, queue->idx); in nvmet_tcp_alloc_queue()
1689 kfree(queue); in nvmet_tcp_alloc_queue()
1812 struct nvmet_tcp_queue *queue; in nvmet_tcp_destroy_port_queues() local
1815 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_destroy_port_queues()
1816 if (queue->port == port) in nvmet_tcp_destroy_port_queues()
1817 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_destroy_port_queues()
1842 struct nvmet_tcp_queue *queue; in nvmet_tcp_delete_ctrl() local
1845 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_delete_ctrl()
1846 if (queue->nvme_sq.ctrl == ctrl) in nvmet_tcp_delete_ctrl()
1847 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_delete_ctrl()
1853 struct nvmet_tcp_queue *queue = in nvmet_tcp_install_queue() local
1861 queue->nr_cmds = sq->size * 2; in nvmet_tcp_install_queue()
1862 if (nvmet_tcp_alloc_cmds(queue)) in nvmet_tcp_install_queue()
1875 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_disc_port_addr() local
1877 sprintf(traddr, "%pISc", (struct sockaddr *)&queue->sockaddr); in nvmet_tcp_disc_port_addr()
1916 struct nvmet_tcp_queue *queue; in nvmet_tcp_exit() local
1922 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_exit()
1923 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_exit()