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()
365 static void nvmet_tcp_fatal_error(struct nvmet_tcp_queue *queue) in nvmet_tcp_fatal_error() argument
367 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_fatal_error()
368 if (queue->nvme_sq.ctrl) in nvmet_tcp_fatal_error()
369 nvmet_ctrl_fatal_error(queue->nvme_sq.ctrl); in nvmet_tcp_fatal_error()
371 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_fatal_error()
374 static void nvmet_tcp_socket_error(struct nvmet_tcp_queue *queue, int status) in nvmet_tcp_socket_error() argument
376 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_socket_error()
378 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_socket_error()
380 nvmet_tcp_fatal_error(queue); in nvmet_tcp_socket_error()
431 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_c2h_data_pdu() local
432 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_c2h_data_pdu()
433 u8 ddgst = nvmet_tcp_ddgst_len(cmd->queue); in nvmet_setup_c2h_data_pdu()
439 pdu->hdr.flags = NVME_TCP_F_DATA_LAST | (queue->nvme_sq.sqhd_disabled ? in nvmet_setup_c2h_data_pdu()
450 if (queue->data_digest) { in nvmet_setup_c2h_data_pdu()
452 nvmet_tcp_calc_ddgst(queue->snd_hash, cmd); in nvmet_setup_c2h_data_pdu()
455 if (cmd->queue->hdr_digest) { in nvmet_setup_c2h_data_pdu()
457 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_c2h_data_pdu()
464 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_r2t_pdu() local
465 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_r2t_pdu()
477 pdu->ttag = nvmet_tcp_cmd_tag(cmd->queue, cmd); in nvmet_setup_r2t_pdu()
480 if (cmd->queue->hdr_digest) { in nvmet_setup_r2t_pdu()
482 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_r2t_pdu()
489 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_setup_response_pdu() local
490 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_setup_response_pdu()
500 if (cmd->queue->hdr_digest) { in nvmet_setup_response_pdu()
502 nvmet_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); in nvmet_setup_response_pdu()
506 static void nvmet_tcp_process_resp_list(struct nvmet_tcp_queue *queue) in nvmet_tcp_process_resp_list() argument
511 for (node = llist_del_all(&queue->resp_list); node; node = node->next) { in nvmet_tcp_process_resp_list()
513 list_add(&cmd->entry, &queue->resp_send_list); in nvmet_tcp_process_resp_list()
514 queue->send_list_len++; in nvmet_tcp_process_resp_list()
518 static struct nvmet_tcp_cmd *nvmet_tcp_fetch_cmd(struct nvmet_tcp_queue *queue) in nvmet_tcp_fetch_cmd() argument
520 queue->snd_cmd = list_first_entry_or_null(&queue->resp_send_list, in nvmet_tcp_fetch_cmd()
522 if (!queue->snd_cmd) { in nvmet_tcp_fetch_cmd()
523 nvmet_tcp_process_resp_list(queue); in nvmet_tcp_fetch_cmd()
524 queue->snd_cmd = in nvmet_tcp_fetch_cmd()
525 list_first_entry_or_null(&queue->resp_send_list, in nvmet_tcp_fetch_cmd()
527 if (unlikely(!queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
531 list_del_init(&queue->snd_cmd->entry); in nvmet_tcp_fetch_cmd()
532 queue->send_list_len--; in nvmet_tcp_fetch_cmd()
534 if (nvmet_tcp_need_data_out(queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
535 nvmet_setup_c2h_data_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
536 else if (nvmet_tcp_need_data_in(queue->snd_cmd)) in nvmet_tcp_fetch_cmd()
537 nvmet_setup_r2t_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
539 nvmet_setup_response_pdu(queue->snd_cmd); in nvmet_tcp_fetch_cmd()
541 return queue->snd_cmd; in nvmet_tcp_fetch_cmd()
548 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_queue_response() local
552 if (unlikely(cmd == queue->cmd)) { in nvmet_tcp_queue_response()
561 if (queue->rcv_state == NVMET_TCP_RECV_PDU && in nvmet_tcp_queue_response()
567 llist_add(&cmd->lentry, &queue->resp_list); in nvmet_tcp_queue_response()
568 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &cmd->queue->io_work); in nvmet_tcp_queue_response()
585 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_data_pdu()
591 ret = sock_sendmsg(cmd->queue->sock, &msg); in nvmet_try_send_data_pdu()
608 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_try_send_data() local
619 if ((!last_in_batch && cmd->queue->send_list_len) || in nvmet_try_send_data()
621 queue->data_digest || !queue->nvme_sq.sqhd_disabled) in nvmet_try_send_data()
626 ret = sock_sendmsg(cmd->queue->sock, &msg); in nvmet_try_send_data()
640 if (queue->data_digest) { in nvmet_try_send_data()
644 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_data()
645 cmd->queue->snd_cmd = NULL; in nvmet_try_send_data()
652 if (queue->nvme_sq.sqhd_disabled) in nvmet_try_send_data()
664 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_response()
668 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_response()
675 ret = sock_sendmsg(cmd->queue->sock, &msg); in nvmet_try_send_response()
685 cmd->queue->snd_cmd = NULL; in nvmet_try_send_response()
694 u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); in nvmet_try_send_r2t()
698 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_r2t()
705 ret = sock_sendmsg(cmd->queue->sock, &msg); in nvmet_try_send_r2t()
714 cmd->queue->snd_cmd = NULL; in nvmet_try_send_r2t()
720 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_try_send_ddgst() local
729 if (!last_in_batch && cmd->queue->send_list_len) in nvmet_try_send_ddgst()
734 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvmet_try_send_ddgst()
744 if (queue->nvme_sq.sqhd_disabled) { in nvmet_try_send_ddgst()
745 cmd->queue->snd_cmd = NULL; in nvmet_try_send_ddgst()
753 static int nvmet_tcp_try_send_one(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_send_one() argument
756 struct nvmet_tcp_cmd *cmd = queue->snd_cmd; in nvmet_tcp_try_send_one()
759 if (!cmd || queue->state == NVMET_TCP_Q_DISCONNECTING) { in nvmet_tcp_try_send_one()
760 cmd = nvmet_tcp_fetch_cmd(queue); in nvmet_tcp_try_send_one()
802 static int nvmet_tcp_try_send(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_send() argument
808 ret = nvmet_tcp_try_send_one(queue, i == budget - 1); in nvmet_tcp_try_send()
810 nvmet_tcp_socket_error(queue, ret); in nvmet_tcp_try_send()
821 static void nvmet_prepare_receive_pdu(struct nvmet_tcp_queue *queue) in nvmet_prepare_receive_pdu() argument
823 queue->offset = 0; in nvmet_prepare_receive_pdu()
824 queue->left = sizeof(struct nvme_tcp_hdr); in nvmet_prepare_receive_pdu()
825 queue->cmd = NULL; in nvmet_prepare_receive_pdu()
826 queue->rcv_state = NVMET_TCP_RECV_PDU; in nvmet_prepare_receive_pdu()
829 static void nvmet_tcp_free_crypto(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_crypto() argument
831 struct crypto_ahash *tfm = crypto_ahash_reqtfm(queue->rcv_hash); in nvmet_tcp_free_crypto()
833 ahash_request_free(queue->rcv_hash); in nvmet_tcp_free_crypto()
834 ahash_request_free(queue->snd_hash); in nvmet_tcp_free_crypto()
838 static int nvmet_tcp_alloc_crypto(struct nvmet_tcp_queue *queue) in nvmet_tcp_alloc_crypto() argument
846 queue->snd_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvmet_tcp_alloc_crypto()
847 if (!queue->snd_hash) in nvmet_tcp_alloc_crypto()
849 ahash_request_set_callback(queue->snd_hash, 0, NULL, NULL); in nvmet_tcp_alloc_crypto()
851 queue->rcv_hash = ahash_request_alloc(tfm, GFP_KERNEL); in nvmet_tcp_alloc_crypto()
852 if (!queue->rcv_hash) in nvmet_tcp_alloc_crypto()
854 ahash_request_set_callback(queue->rcv_hash, 0, NULL, NULL); in nvmet_tcp_alloc_crypto()
858 ahash_request_free(queue->snd_hash); in nvmet_tcp_alloc_crypto()
865 static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue) in nvmet_tcp_handle_icreq() argument
867 struct nvme_tcp_icreq_pdu *icreq = &queue->pdu.icreq; in nvmet_tcp_handle_icreq()
868 struct nvme_tcp_icresp_pdu *icresp = &queue->pdu.icresp; in nvmet_tcp_handle_icreq()
876 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_icreq()
880 pr_err("queue %d: bad pfv %d\n", queue->idx, icreq->pfv); in nvmet_tcp_handle_icreq()
885 pr_err("queue %d: unsupported hpda %d\n", queue->idx, in nvmet_tcp_handle_icreq()
890 queue->hdr_digest = !!(icreq->digest & NVME_TCP_HDR_DIGEST_ENABLE); in nvmet_tcp_handle_icreq()
891 queue->data_digest = !!(icreq->digest & NVME_TCP_DATA_DIGEST_ENABLE); in nvmet_tcp_handle_icreq()
892 if (queue->hdr_digest || queue->data_digest) { in nvmet_tcp_handle_icreq()
893 ret = nvmet_tcp_alloc_crypto(queue); in nvmet_tcp_handle_icreq()
906 if (queue->hdr_digest) in nvmet_tcp_handle_icreq()
908 if (queue->data_digest) in nvmet_tcp_handle_icreq()
913 ret = kernel_sendmsg(queue->sock, &msg, &iov, 1, iov.iov_len); in nvmet_tcp_handle_icreq()
917 queue->state = NVMET_TCP_Q_LIVE; in nvmet_tcp_handle_icreq()
918 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_handle_icreq()
922 static void nvmet_tcp_handle_req_failure(struct nvmet_tcp_queue *queue, in nvmet_tcp_handle_req_failure() argument
937 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_handle_req_failure()
943 pr_err("queue %d: failed to map data\n", queue->idx); in nvmet_tcp_handle_req_failure()
944 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_req_failure()
948 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_handle_req_failure()
953 static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_handle_h2c_data_pdu() argument
955 struct nvme_tcp_data_pdu *data = &queue->pdu.data; in nvmet_tcp_handle_h2c_data_pdu()
959 if (likely(queue->nr_cmds)) { in nvmet_tcp_handle_h2c_data_pdu()
960 if (unlikely(data->ttag >= queue->nr_cmds)) { in nvmet_tcp_handle_h2c_data_pdu()
962 queue->idx, data->ttag, queue->nr_cmds); in nvmet_tcp_handle_h2c_data_pdu()
963 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_h2c_data_pdu()
966 cmd = &queue->cmds[data->ttag]; in nvmet_tcp_handle_h2c_data_pdu()
968 cmd = &queue->connect; in nvmet_tcp_handle_h2c_data_pdu()
976 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_h2c_data_pdu()
981 nvmet_tcp_hdgst_len(queue) - in nvmet_tcp_handle_h2c_data_pdu()
982 nvmet_tcp_ddgst_len(queue) - in nvmet_tcp_handle_h2c_data_pdu()
991 nvmet_tcp_fatal_error(queue); in nvmet_tcp_handle_h2c_data_pdu()
996 queue->cmd = cmd; in nvmet_tcp_handle_h2c_data_pdu()
997 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_handle_h2c_data_pdu()
1002 static int nvmet_tcp_done_recv_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_done_recv_pdu() argument
1004 struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr; in nvmet_tcp_done_recv_pdu()
1005 struct nvme_command *nvme_cmd = &queue->pdu.cmd.cmd; in nvmet_tcp_done_recv_pdu()
1009 if (unlikely(queue->state == NVMET_TCP_Q_CONNECTING)) { in nvmet_tcp_done_recv_pdu()
1013 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1016 return nvmet_tcp_handle_icreq(queue); in nvmet_tcp_done_recv_pdu()
1021 queue->idx, queue->state); in nvmet_tcp_done_recv_pdu()
1022 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1027 ret = nvmet_tcp_handle_h2c_data_pdu(queue); in nvmet_tcp_done_recv_pdu()
1033 queue->cmd = nvmet_tcp_get_cmd(queue); in nvmet_tcp_done_recv_pdu()
1034 if (unlikely(!queue->cmd)) { in nvmet_tcp_done_recv_pdu()
1037 queue->idx, queue->nr_cmds, queue->send_list_len, in nvmet_tcp_done_recv_pdu()
1039 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1043 req = &queue->cmd->req; in nvmet_tcp_done_recv_pdu()
1046 if (unlikely(!nvmet_req_init(req, &queue->nvme_cq, in nvmet_tcp_done_recv_pdu()
1047 &queue->nvme_sq, &nvmet_tcp_ops))) { in nvmet_tcp_done_recv_pdu()
1053 nvmet_tcp_handle_req_failure(queue, queue->cmd, req); in nvmet_tcp_done_recv_pdu()
1057 ret = nvmet_tcp_map_data(queue->cmd); in nvmet_tcp_done_recv_pdu()
1059 pr_err("queue %d: failed to map data\n", queue->idx); in nvmet_tcp_done_recv_pdu()
1060 if (nvmet_tcp_has_inline_data(queue->cmd)) in nvmet_tcp_done_recv_pdu()
1061 nvmet_tcp_fatal_error(queue); in nvmet_tcp_done_recv_pdu()
1068 if (nvmet_tcp_need_data_in(queue->cmd)) { in nvmet_tcp_done_recv_pdu()
1069 if (nvmet_tcp_has_inline_data(queue->cmd)) { in nvmet_tcp_done_recv_pdu()
1070 queue->rcv_state = NVMET_TCP_RECV_DATA; in nvmet_tcp_done_recv_pdu()
1071 nvmet_tcp_build_pdu_iovec(queue->cmd); in nvmet_tcp_done_recv_pdu()
1075 nvmet_tcp_queue_response(&queue->cmd->req); in nvmet_tcp_done_recv_pdu()
1079 queue->cmd->req.execute(&queue->cmd->req); in nvmet_tcp_done_recv_pdu()
1081 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_done_recv_pdu()
1113 static int nvmet_tcp_try_recv_pdu(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_pdu() argument
1115 struct nvme_tcp_hdr *hdr = &queue->pdu.cmd.hdr; in nvmet_tcp_try_recv_pdu()
1121 iov.iov_base = (void *)&queue->pdu + queue->offset; in nvmet_tcp_try_recv_pdu()
1122 iov.iov_len = queue->left; in nvmet_tcp_try_recv_pdu()
1123 len = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvmet_tcp_try_recv_pdu()
1128 queue->offset += len; in nvmet_tcp_try_recv_pdu()
1129 queue->left -= len; in nvmet_tcp_try_recv_pdu()
1130 if (queue->left) in nvmet_tcp_try_recv_pdu()
1133 if (queue->offset == sizeof(struct nvme_tcp_hdr)) { in nvmet_tcp_try_recv_pdu()
1134 u8 hdgst = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_try_recv_pdu()
1138 nvmet_tcp_fatal_error(queue); in nvmet_tcp_try_recv_pdu()
1147 queue->left = hdr->hlen - queue->offset + hdgst; in nvmet_tcp_try_recv_pdu()
1151 if (queue->hdr_digest && in nvmet_tcp_try_recv_pdu()
1152 nvmet_tcp_verify_hdgst(queue, &queue->pdu, hdr->hlen)) { in nvmet_tcp_try_recv_pdu()
1153 nvmet_tcp_fatal_error(queue); /* fatal */ in nvmet_tcp_try_recv_pdu()
1157 if (queue->data_digest && in nvmet_tcp_try_recv_pdu()
1158 nvmet_tcp_check_ddgst(queue, &queue->pdu)) { in nvmet_tcp_try_recv_pdu()
1159 nvmet_tcp_fatal_error(queue); /* fatal */ in nvmet_tcp_try_recv_pdu()
1163 return nvmet_tcp_done_recv_pdu(queue); in nvmet_tcp_try_recv_pdu()
1168 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_prep_recv_ddgst() local
1170 nvmet_tcp_calc_ddgst(queue->rcv_hash, cmd); in nvmet_tcp_prep_recv_ddgst()
1171 queue->offset = 0; in nvmet_tcp_prep_recv_ddgst()
1172 queue->left = NVME_TCP_DIGEST_LENGTH; in nvmet_tcp_prep_recv_ddgst()
1173 queue->rcv_state = NVMET_TCP_RECV_DDGST; in nvmet_tcp_prep_recv_ddgst()
1176 static int nvmet_tcp_try_recv_data(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_data() argument
1178 struct nvmet_tcp_cmd *cmd = queue->cmd; in nvmet_tcp_try_recv_data()
1182 ret = sock_recvmsg(cmd->queue->sock, &cmd->recv_msg, in nvmet_tcp_try_recv_data()
1191 if (queue->data_digest) { in nvmet_tcp_try_recv_data()
1199 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_try_recv_data()
1203 static int nvmet_tcp_try_recv_ddgst(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_ddgst() argument
1205 struct nvmet_tcp_cmd *cmd = queue->cmd; in nvmet_tcp_try_recv_ddgst()
1209 .iov_base = (void *)&cmd->recv_ddgst + queue->offset, in nvmet_tcp_try_recv_ddgst()
1210 .iov_len = queue->left in nvmet_tcp_try_recv_ddgst()
1213 ret = kernel_recvmsg(queue->sock, &msg, &iov, 1, in nvmet_tcp_try_recv_ddgst()
1218 queue->offset += ret; in nvmet_tcp_try_recv_ddgst()
1219 queue->left -= ret; in nvmet_tcp_try_recv_ddgst()
1220 if (queue->left) in nvmet_tcp_try_recv_ddgst()
1223 if (queue->data_digest && cmd->exp_ddgst != cmd->recv_ddgst) { in nvmet_tcp_try_recv_ddgst()
1225 queue->idx, cmd->req.cmd->common.command_id, in nvmet_tcp_try_recv_ddgst()
1226 queue->pdu.cmd.hdr.type, le32_to_cpu(cmd->recv_ddgst), in nvmet_tcp_try_recv_ddgst()
1230 nvmet_tcp_fatal_error(queue); in nvmet_tcp_try_recv_ddgst()
1240 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_try_recv_ddgst()
1244 static int nvmet_tcp_try_recv_one(struct nvmet_tcp_queue *queue) in nvmet_tcp_try_recv_one() argument
1248 if (unlikely(queue->rcv_state == NVMET_TCP_RECV_ERR)) in nvmet_tcp_try_recv_one()
1251 if (queue->rcv_state == NVMET_TCP_RECV_PDU) { in nvmet_tcp_try_recv_one()
1252 result = nvmet_tcp_try_recv_pdu(queue); in nvmet_tcp_try_recv_one()
1257 if (queue->rcv_state == NVMET_TCP_RECV_DATA) { in nvmet_tcp_try_recv_one()
1258 result = nvmet_tcp_try_recv_data(queue); in nvmet_tcp_try_recv_one()
1263 if (queue->rcv_state == NVMET_TCP_RECV_DDGST) { in nvmet_tcp_try_recv_one()
1264 result = nvmet_tcp_try_recv_ddgst(queue); in nvmet_tcp_try_recv_one()
1278 static int nvmet_tcp_try_recv(struct nvmet_tcp_queue *queue, in nvmet_tcp_try_recv() argument
1284 ret = nvmet_tcp_try_recv_one(queue); in nvmet_tcp_try_recv()
1286 nvmet_tcp_socket_error(queue, ret); in nvmet_tcp_try_recv()
1297 static void nvmet_tcp_schedule_release_queue(struct nvmet_tcp_queue *queue) in nvmet_tcp_schedule_release_queue() argument
1299 spin_lock(&queue->state_lock); in nvmet_tcp_schedule_release_queue()
1300 if (queue->state != NVMET_TCP_Q_DISCONNECTING) { in nvmet_tcp_schedule_release_queue()
1301 queue->state = NVMET_TCP_Q_DISCONNECTING; in nvmet_tcp_schedule_release_queue()
1302 queue_work(nvmet_wq, &queue->release_work); in nvmet_tcp_schedule_release_queue()
1304 spin_unlock(&queue->state_lock); in nvmet_tcp_schedule_release_queue()
1307 static inline void nvmet_tcp_arm_queue_deadline(struct nvmet_tcp_queue *queue) in nvmet_tcp_arm_queue_deadline() argument
1309 queue->poll_end = jiffies + usecs_to_jiffies(idle_poll_period_usecs); in nvmet_tcp_arm_queue_deadline()
1312 static bool nvmet_tcp_check_queue_deadline(struct nvmet_tcp_queue *queue, in nvmet_tcp_check_queue_deadline() argument
1319 nvmet_tcp_arm_queue_deadline(queue); in nvmet_tcp_check_queue_deadline()
1321 return !time_after(jiffies, queue->poll_end); in nvmet_tcp_check_queue_deadline()
1326 struct nvmet_tcp_queue *queue = in nvmet_tcp_io_work() local
1334 ret = nvmet_tcp_try_recv(queue, NVMET_TCP_RECV_BUDGET, &ops); in nvmet_tcp_io_work()
1340 ret = nvmet_tcp_try_send(queue, NVMET_TCP_SEND_BUDGET, &ops); in nvmet_tcp_io_work()
1352 if (nvmet_tcp_check_queue_deadline(queue, ops) || pending) in nvmet_tcp_io_work()
1353 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_io_work()
1356 static int nvmet_tcp_alloc_cmd(struct nvmet_tcp_queue *queue, in nvmet_tcp_alloc_cmd() argument
1359 u8 hdgst = nvmet_tcp_hdgst_len(queue); in nvmet_tcp_alloc_cmd()
1361 c->queue = queue; in nvmet_tcp_alloc_cmd()
1362 c->req.port = queue->port->nport; in nvmet_tcp_alloc_cmd()
1364 c->cmd_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1370 c->rsp_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1376 c->data_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1381 c->r2t_pdu = page_frag_alloc(&queue->pf_cache, in nvmet_tcp_alloc_cmd()
1388 list_add_tail(&c->entry, &queue->free_list); in nvmet_tcp_alloc_cmd()
1408 static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_alloc_cmds() argument
1411 int i, ret = -EINVAL, nr_cmds = queue->nr_cmds; in nvmet_tcp_alloc_cmds()
1418 ret = nvmet_tcp_alloc_cmd(queue, cmds + i); in nvmet_tcp_alloc_cmds()
1423 queue->cmds = cmds; in nvmet_tcp_alloc_cmds()
1434 static void nvmet_tcp_free_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_cmds() argument
1436 struct nvmet_tcp_cmd *cmds = queue->cmds; in nvmet_tcp_free_cmds()
1439 for (i = 0; i < queue->nr_cmds; i++) in nvmet_tcp_free_cmds()
1442 nvmet_tcp_free_cmd(&queue->connect); in nvmet_tcp_free_cmds()
1446 static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue) in nvmet_tcp_restore_socket_callbacks() argument
1448 struct socket *sock = queue->sock; in nvmet_tcp_restore_socket_callbacks()
1451 sock->sk->sk_data_ready = queue->data_ready; in nvmet_tcp_restore_socket_callbacks()
1452 sock->sk->sk_state_change = queue->state_change; in nvmet_tcp_restore_socket_callbacks()
1453 sock->sk->sk_write_space = queue->write_space; in nvmet_tcp_restore_socket_callbacks()
1458 static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue) in nvmet_tcp_uninit_data_in_cmds() argument
1460 struct nvmet_tcp_cmd *cmd = queue->cmds; in nvmet_tcp_uninit_data_in_cmds()
1463 for (i = 0; i < queue->nr_cmds; i++, cmd++) { in nvmet_tcp_uninit_data_in_cmds()
1468 if (!queue->nr_cmds && nvmet_tcp_need_data_in(&queue->connect)) { in nvmet_tcp_uninit_data_in_cmds()
1470 nvmet_req_uninit(&queue->connect.req); in nvmet_tcp_uninit_data_in_cmds()
1474 static void nvmet_tcp_free_cmd_data_in_buffers(struct nvmet_tcp_queue *queue) in nvmet_tcp_free_cmd_data_in_buffers() argument
1476 struct nvmet_tcp_cmd *cmd = queue->cmds; in nvmet_tcp_free_cmd_data_in_buffers()
1479 for (i = 0; i < queue->nr_cmds; i++, cmd++) { in nvmet_tcp_free_cmd_data_in_buffers()
1484 if (!queue->nr_cmds && nvmet_tcp_need_data_in(&queue->connect)) in nvmet_tcp_free_cmd_data_in_buffers()
1485 nvmet_tcp_free_cmd_buffers(&queue->connect); in nvmet_tcp_free_cmd_data_in_buffers()
1491 struct nvmet_tcp_queue *queue = in nvmet_tcp_release_queue_work() local
1495 list_del_init(&queue->queue_list); in nvmet_tcp_release_queue_work()
1498 nvmet_tcp_restore_socket_callbacks(queue); in nvmet_tcp_release_queue_work()
1499 cancel_work_sync(&queue->io_work); in nvmet_tcp_release_queue_work()
1501 queue->rcv_state = NVMET_TCP_RECV_ERR; in nvmet_tcp_release_queue_work()
1503 nvmet_tcp_uninit_data_in_cmds(queue); in nvmet_tcp_release_queue_work()
1504 nvmet_sq_destroy(&queue->nvme_sq); in nvmet_tcp_release_queue_work()
1505 cancel_work_sync(&queue->io_work); in nvmet_tcp_release_queue_work()
1506 nvmet_tcp_free_cmd_data_in_buffers(queue); in nvmet_tcp_release_queue_work()
1507 sock_release(queue->sock); in nvmet_tcp_release_queue_work()
1508 nvmet_tcp_free_cmds(queue); in nvmet_tcp_release_queue_work()
1509 if (queue->hdr_digest || queue->data_digest) in nvmet_tcp_release_queue_work()
1510 nvmet_tcp_free_crypto(queue); in nvmet_tcp_release_queue_work()
1511 ida_free(&nvmet_tcp_queue_ida, queue->idx); in nvmet_tcp_release_queue_work()
1513 page = virt_to_head_page(queue->pf_cache.va); in nvmet_tcp_release_queue_work()
1514 __page_frag_cache_drain(page, queue->pf_cache.pagecnt_bias); in nvmet_tcp_release_queue_work()
1515 kfree(queue); in nvmet_tcp_release_queue_work()
1520 struct nvmet_tcp_queue *queue; in nvmet_tcp_data_ready() local
1525 queue = sk->sk_user_data; in nvmet_tcp_data_ready()
1526 if (likely(queue)) in nvmet_tcp_data_ready()
1527 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_data_ready()
1533 struct nvmet_tcp_queue *queue; in nvmet_tcp_write_space() local
1536 queue = sk->sk_user_data; in nvmet_tcp_write_space()
1537 if (unlikely(!queue)) in nvmet_tcp_write_space()
1540 if (unlikely(queue->state == NVMET_TCP_Q_CONNECTING)) { in nvmet_tcp_write_space()
1541 queue->write_space(sk); in nvmet_tcp_write_space()
1547 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_write_space()
1555 struct nvmet_tcp_queue *queue; in nvmet_tcp_state_change() local
1558 queue = sk->sk_user_data; in nvmet_tcp_state_change()
1559 if (!queue) in nvmet_tcp_state_change()
1570 nvmet_tcp_schedule_release_queue(queue); in nvmet_tcp_state_change()
1574 queue->idx, sk->sk_state); in nvmet_tcp_state_change()
1580 static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue) in nvmet_tcp_set_queue_sock() argument
1582 struct socket *sock = queue->sock; in nvmet_tcp_set_queue_sock()
1587 (struct sockaddr *)&queue->sockaddr); in nvmet_tcp_set_queue_sock()
1592 (struct sockaddr *)&queue->sockaddr_peer); in nvmet_tcp_set_queue_sock()
1619 sock->sk->sk_user_data = queue; in nvmet_tcp_set_queue_sock()
1620 queue->data_ready = sock->sk->sk_data_ready; in nvmet_tcp_set_queue_sock()
1622 queue->state_change = sock->sk->sk_state_change; in nvmet_tcp_set_queue_sock()
1624 queue->write_space = sock->sk->sk_write_space; in nvmet_tcp_set_queue_sock()
1627 nvmet_tcp_arm_queue_deadline(queue); in nvmet_tcp_set_queue_sock()
1628 queue_work_on(queue_cpu(queue), nvmet_tcp_wq, &queue->io_work); in nvmet_tcp_set_queue_sock()
1638 struct nvmet_tcp_queue *queue; in nvmet_tcp_alloc_queue() local
1641 queue = kzalloc(sizeof(*queue), GFP_KERNEL); in nvmet_tcp_alloc_queue()
1642 if (!queue) in nvmet_tcp_alloc_queue()
1645 INIT_WORK(&queue->release_work, nvmet_tcp_release_queue_work); in nvmet_tcp_alloc_queue()
1646 INIT_WORK(&queue->io_work, nvmet_tcp_io_work); in nvmet_tcp_alloc_queue()
1647 queue->sock = newsock; in nvmet_tcp_alloc_queue()
1648 queue->port = port; in nvmet_tcp_alloc_queue()
1649 queue->nr_cmds = 0; in nvmet_tcp_alloc_queue()
1650 spin_lock_init(&queue->state_lock); in nvmet_tcp_alloc_queue()
1651 queue->state = NVMET_TCP_Q_CONNECTING; in nvmet_tcp_alloc_queue()
1652 INIT_LIST_HEAD(&queue->free_list); in nvmet_tcp_alloc_queue()
1653 init_llist_head(&queue->resp_list); in nvmet_tcp_alloc_queue()
1654 INIT_LIST_HEAD(&queue->resp_send_list); in nvmet_tcp_alloc_queue()
1656 queue->idx = ida_alloc(&nvmet_tcp_queue_ida, GFP_KERNEL); in nvmet_tcp_alloc_queue()
1657 if (queue->idx < 0) { in nvmet_tcp_alloc_queue()
1658 ret = queue->idx; in nvmet_tcp_alloc_queue()
1662 ret = nvmet_tcp_alloc_cmd(queue, &queue->connect); in nvmet_tcp_alloc_queue()
1666 ret = nvmet_sq_init(&queue->nvme_sq); in nvmet_tcp_alloc_queue()
1670 nvmet_prepare_receive_pdu(queue); in nvmet_tcp_alloc_queue()
1673 list_add_tail(&queue->queue_list, &nvmet_tcp_queue_list); in nvmet_tcp_alloc_queue()
1676 ret = nvmet_tcp_set_queue_sock(queue); in nvmet_tcp_alloc_queue()
1683 list_del_init(&queue->queue_list); in nvmet_tcp_alloc_queue()
1685 nvmet_sq_destroy(&queue->nvme_sq); in nvmet_tcp_alloc_queue()
1687 nvmet_tcp_free_cmd(&queue->connect); in nvmet_tcp_alloc_queue()
1689 ida_free(&nvmet_tcp_queue_ida, queue->idx); in nvmet_tcp_alloc_queue()
1691 kfree(queue); in nvmet_tcp_alloc_queue()
1814 struct nvmet_tcp_queue *queue; in nvmet_tcp_destroy_port_queues() local
1817 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_destroy_port_queues()
1818 if (queue->port == port) in nvmet_tcp_destroy_port_queues()
1819 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_destroy_port_queues()
1844 struct nvmet_tcp_queue *queue; in nvmet_tcp_delete_ctrl() local
1847 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_delete_ctrl()
1848 if (queue->nvme_sq.ctrl == ctrl) in nvmet_tcp_delete_ctrl()
1849 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_delete_ctrl()
1855 struct nvmet_tcp_queue *queue = in nvmet_tcp_install_queue() local
1863 queue->nr_cmds = sq->size * 2; in nvmet_tcp_install_queue()
1864 if (nvmet_tcp_alloc_cmds(queue)) in nvmet_tcp_install_queue()
1877 struct nvmet_tcp_queue *queue = cmd->queue; in nvmet_tcp_disc_port_addr() local
1879 sprintf(traddr, "%pISc", (struct sockaddr *)&queue->sockaddr); in nvmet_tcp_disc_port_addr()
1918 struct nvmet_tcp_queue *queue; in nvmet_tcp_exit() local
1924 list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list) in nvmet_tcp_exit()
1925 kernel_sock_shutdown(queue->sock, SHUT_RDWR); in nvmet_tcp_exit()