Lines Matching +full:wakeup +full:- +full:rtt +full:- +full:timer
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * (c) Copyright 2007-2013 Datera, Inc.
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
72 if (!strcmp(tiqn->tiqn, buf)) { in iscsit_get_tiqn_for_login()
74 spin_lock(&tiqn->tiqn_state_lock); in iscsit_get_tiqn_for_login()
75 if (tiqn->tiqn_state == TIQN_STATE_ACTIVE) { in iscsit_get_tiqn_for_login()
76 tiqn->tiqn_access_count++; in iscsit_get_tiqn_for_login()
77 spin_unlock(&tiqn->tiqn_state_lock); in iscsit_get_tiqn_for_login()
81 spin_unlock(&tiqn->tiqn_state_lock); in iscsit_get_tiqn_for_login()
91 spin_lock(&tiqn->tiqn_state_lock); in iscsit_set_tiqn_shutdown()
92 if (tiqn->tiqn_state == TIQN_STATE_ACTIVE) { in iscsit_set_tiqn_shutdown()
93 tiqn->tiqn_state = TIQN_STATE_SHUTDOWN; in iscsit_set_tiqn_shutdown()
94 spin_unlock(&tiqn->tiqn_state_lock); in iscsit_set_tiqn_shutdown()
97 spin_unlock(&tiqn->tiqn_state_lock); in iscsit_set_tiqn_shutdown()
99 return -1; in iscsit_set_tiqn_shutdown()
104 spin_lock(&tiqn->tiqn_state_lock); in iscsit_put_tiqn_for_login()
105 tiqn->tiqn_access_count--; in iscsit_put_tiqn_for_login()
106 spin_unlock(&tiqn->tiqn_state_lock); in iscsit_put_tiqn_for_login()
121 return ERR_PTR(-EINVAL); in iscsit_add_tiqn()
126 return ERR_PTR(-ENOMEM); in iscsit_add_tiqn()
128 sprintf(tiqn->tiqn, "%s", buf); in iscsit_add_tiqn()
129 INIT_LIST_HEAD(&tiqn->tiqn_list); in iscsit_add_tiqn()
130 INIT_LIST_HEAD(&tiqn->tiqn_tpg_list); in iscsit_add_tiqn()
131 spin_lock_init(&tiqn->tiqn_state_lock); in iscsit_add_tiqn()
132 spin_lock_init(&tiqn->tiqn_tpg_lock); in iscsit_add_tiqn()
133 spin_lock_init(&tiqn->sess_err_stats.lock); in iscsit_add_tiqn()
134 spin_lock_init(&tiqn->login_stats.lock); in iscsit_add_tiqn()
135 spin_lock_init(&tiqn->logout_stats.lock); in iscsit_add_tiqn()
137 tiqn->tiqn_state = TIQN_STATE_ACTIVE; in iscsit_add_tiqn()
144 pr_err("idr_alloc() failed for tiqn->tiqn_index\n"); in iscsit_add_tiqn()
150 tiqn->tiqn_index = ret; in iscsit_add_tiqn()
151 list_add_tail(&tiqn->tiqn_list, &g_tiqn_list); in iscsit_add_tiqn()
156 pr_debug("CORE[0] - Added iSCSI Target IQN: %s\n", tiqn->tiqn); in iscsit_add_tiqn()
167 spin_lock(&tiqn->tiqn_state_lock); in iscsit_wait_for_tiqn()
168 while (tiqn->tiqn_access_count != 0) { in iscsit_wait_for_tiqn()
169 spin_unlock(&tiqn->tiqn_state_lock); in iscsit_wait_for_tiqn()
171 spin_lock(&tiqn->tiqn_state_lock); in iscsit_wait_for_tiqn()
173 spin_unlock(&tiqn->tiqn_state_lock); in iscsit_wait_for_tiqn()
179 * iscsit_set_tiqn_shutdown sets tiqn->tiqn_state = TIQN_STATE_SHUTDOWN in iscsit_del_tiqn()
180 * while holding tiqn->tiqn_state_lock. This means that all subsequent in iscsit_del_tiqn()
192 list_del(&tiqn->tiqn_list); in iscsit_del_tiqn()
193 idr_remove(&tiqn_idr, tiqn->tiqn_index); in iscsit_del_tiqn()
196 pr_debug("CORE[0] - Deleted iSCSI Target IQN: %s\n", in iscsit_del_tiqn()
197 tiqn->tiqn); in iscsit_del_tiqn()
207 spin_lock_bh(&np->np_thread_lock); in iscsit_access_np()
208 if (np->np_thread_state != ISCSI_NP_THREAD_ACTIVE) { in iscsit_access_np()
209 spin_unlock_bh(&np->np_thread_lock); in iscsit_access_np()
210 return -1; in iscsit_access_np()
212 spin_unlock_bh(&np->np_thread_lock); in iscsit_access_np()
216 spin_lock_bh(&tpg->tpg_state_lock); in iscsit_access_np()
217 if (tpg->tpg_state != TPG_STATE_ACTIVE) { in iscsit_access_np()
218 spin_unlock_bh(&tpg->tpg_state_lock); in iscsit_access_np()
219 return -1; in iscsit_access_np()
221 spin_unlock_bh(&tpg->tpg_state_lock); in iscsit_access_np()
226 ret = down_interruptible(&tpg->np_login_sem); in iscsit_access_np()
228 return -1; in iscsit_access_np()
230 spin_lock_bh(&tpg->tpg_state_lock); in iscsit_access_np()
231 if (tpg->tpg_state != TPG_STATE_ACTIVE) { in iscsit_access_np()
232 spin_unlock_bh(&tpg->tpg_state_lock); in iscsit_access_np()
233 up(&tpg->np_login_sem); in iscsit_access_np()
234 return -1; in iscsit_access_np()
236 spin_unlock_bh(&tpg->tpg_state_lock); in iscsit_access_np()
246 complete(&tpg_np->tpg_np_comp); in iscsit_login_kref_put()
252 struct iscsi_tiqn *tiqn = tpg->tpg_tiqn; in iscsit_deaccess_np()
254 up(&tpg->np_login_sem); in iscsit_deaccess_np()
257 kref_put(&tpg_np->tpg_np_kref, iscsit_login_kref_put); in iscsit_deaccess_np()
275 if (sockaddr->ss_family == AF_INET6) { in iscsit_check_np_match()
277 sock_in6_e = (struct sockaddr_in6 *)&np->np_sockaddr; in iscsit_check_np_match()
279 if (!memcmp(&sock_in6->sin6_addr.in6_u, in iscsit_check_np_match()
280 &sock_in6_e->sin6_addr.in6_u, in iscsit_check_np_match()
284 port = ntohs(sock_in6->sin6_port); in iscsit_check_np_match()
285 port_e = ntohs(sock_in6_e->sin6_port); in iscsit_check_np_match()
288 sock_in_e = (struct sockaddr_in *)&np->np_sockaddr; in iscsit_check_np_match()
290 if (sock_in->sin_addr.s_addr == sock_in_e->sin_addr.s_addr) in iscsit_check_np_match()
293 port = ntohs(sock_in->sin_port); in iscsit_check_np_match()
294 port_e = ntohs(sock_in_e->sin_port); in iscsit_check_np_match()
298 (np->np_network_transport == network_transport)) in iscsit_check_np_match()
314 spin_lock_bh(&np->np_thread_lock); in iscsit_get_np()
315 if (np->np_thread_state != ISCSI_NP_THREAD_ACTIVE) { in iscsit_get_np()
316 spin_unlock_bh(&np->np_thread_lock); in iscsit_get_np()
327 np->np_exports++; in iscsit_get_np()
328 spin_unlock_bh(&np->np_thread_lock); in iscsit_get_np()
331 spin_unlock_bh(&np->np_thread_lock); in iscsit_get_np()
358 return ERR_PTR(-ENOMEM); in iscsit_add_np()
361 np->np_flags |= NPF_IP_NETWORK; in iscsit_add_np()
362 np->np_network_transport = network_transport; in iscsit_add_np()
363 spin_lock_init(&np->np_thread_lock); in iscsit_add_np()
364 init_completion(&np->np_restart_comp); in iscsit_add_np()
365 INIT_LIST_HEAD(&np->np_list); in iscsit_add_np()
374 np->np_thread = kthread_run(iscsi_target_login_thread, np, "iscsi_np"); in iscsit_add_np()
375 if (IS_ERR(np->np_thread)) { in iscsit_add_np()
377 ret = PTR_ERR(np->np_thread); in iscsit_add_np()
386 * active. We don't need to hold np->np_thread_lock at this in iscsit_add_np()
389 np->np_exports = 1; in iscsit_add_np()
390 np->np_thread_state = ISCSI_NP_THREAD_ACTIVE; in iscsit_add_np()
392 list_add_tail(&np->np_list, &g_np_list); in iscsit_add_np()
395 pr_debug("CORE[0] - Added Network Portal: %pISpc on %s\n", in iscsit_add_np()
396 &np->np_sockaddr, np->np_transport->name); in iscsit_add_np()
407 spin_lock_bh(&np->np_thread_lock); in iscsit_reset_np_thread()
408 if (np->np_thread_state == ISCSI_NP_THREAD_INACTIVE) { in iscsit_reset_np_thread()
409 spin_unlock_bh(&np->np_thread_lock); in iscsit_reset_np_thread()
412 np->np_thread_state = ISCSI_NP_THREAD_RESET; in iscsit_reset_np_thread()
413 atomic_inc(&np->np_reset_count); in iscsit_reset_np_thread()
415 if (np->np_thread) { in iscsit_reset_np_thread()
416 spin_unlock_bh(&np->np_thread_lock); in iscsit_reset_np_thread()
417 send_sig(SIGINT, np->np_thread, 1); in iscsit_reset_np_thread()
418 wait_for_completion(&np->np_restart_comp); in iscsit_reset_np_thread()
419 spin_lock_bh(&np->np_thread_lock); in iscsit_reset_np_thread()
421 spin_unlock_bh(&np->np_thread_lock); in iscsit_reset_np_thread()
424 kref_put(&tpg_np->tpg_np_kref, iscsit_login_kref_put); in iscsit_reset_np_thread()
426 wait_for_completion(&tpg_np->tpg_np_comp); in iscsit_reset_np_thread()
434 if (np->np_socket) in iscsit_free_np()
435 sock_release(np->np_socket); in iscsit_free_np()
440 spin_lock_bh(&np->np_thread_lock); in iscsit_del_np()
441 np->np_exports--; in iscsit_del_np()
442 if (np->np_exports) { in iscsit_del_np()
443 np->enabled = true; in iscsit_del_np()
444 spin_unlock_bh(&np->np_thread_lock); in iscsit_del_np()
447 np->np_thread_state = ISCSI_NP_THREAD_SHUTDOWN; in iscsit_del_np()
448 spin_unlock_bh(&np->np_thread_lock); in iscsit_del_np()
450 if (np->np_thread) { in iscsit_del_np()
452 * We need to send the signal to wakeup Linux/Net in iscsit_del_np()
455 send_sig(SIGINT, np->np_thread, 1); in iscsit_del_np()
456 kthread_stop(np->np_thread); in iscsit_del_np()
457 np->np_thread = NULL; in iscsit_del_np()
460 np->np_transport->iscsit_free_np(np); in iscsit_del_np()
463 list_del(&np->np_list); in iscsit_del_np()
466 pr_debug("CORE[0] - Removed Network Portal: %pISpc on %s\n", in iscsit_del_np()
467 &np->np_sockaddr, np->np_transport->name); in iscsit_del_np()
469 iscsit_put_transport(np->np_transport); in iscsit_del_np()
478 return iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); in iscsit_queue_rsp()
484 spin_lock_bh(&conn->cmd_lock); in iscsit_aborted_task()
485 if (!list_empty(&cmd->i_conn_node)) in iscsit_aborted_task()
486 list_del_init(&cmd->i_conn_node); in iscsit_aborted_task()
487 spin_unlock_bh(&conn->cmd_lock); in iscsit_aborted_task()
501 struct iscsi_hdr *hdr = (struct iscsi_hdr *)cmd->pdu; in iscsit_xmit_nondatain_pdu()
506 iov = &cmd->iov_misc[0]; in iscsit_xmit_nondatain_pdu()
507 iov[niov].iov_base = cmd->pdu; in iscsit_xmit_nondatain_pdu()
510 if (conn->conn_ops->HeaderDigest) { in iscsit_xmit_nondatain_pdu()
511 u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; in iscsit_xmit_nondatain_pdu()
519 hdr->opcode, *header_digest); in iscsit_xmit_nondatain_pdu()
523 u32 padding = ((-data_buf_len) & 3); in iscsit_xmit_nondatain_pdu()
530 iov[niov].iov_base = &cmd->pad_bytes; in iscsit_xmit_nondatain_pdu()
537 if (conn->conn_ops->DataDigest) { in iscsit_xmit_nondatain_pdu()
538 cmd->data_crc = iscsit_crc_buf(data_buf, data_buf_len, in iscsit_xmit_nondatain_pdu()
540 &cmd->pad_bytes); in iscsit_xmit_nondatain_pdu()
541 iov[niov].iov_base = &cmd->data_crc; in iscsit_xmit_nondatain_pdu()
546 data_buf_len, hdr->opcode, cmd->data_crc); in iscsit_xmit_nondatain_pdu()
550 cmd->iov_misc_count = niov; in iscsit_xmit_nondatain_pdu()
551 cmd->tx_size = tx_size; in iscsit_xmit_nondatain_pdu()
575 iov = &cmd->iov_data[0]; in iscsit_xmit_datain_pdu()
576 iov[iov_count].iov_base = cmd->pdu; in iscsit_xmit_datain_pdu()
580 if (conn->conn_ops->HeaderDigest) { in iscsit_xmit_datain_pdu()
581 u32 *header_digest = (u32 *)&cmd->pdu[ISCSI_HDR_LEN]; in iscsit_xmit_datain_pdu()
583 *header_digest = iscsit_crc_buf(cmd->pdu, ISCSI_HDR_LEN, 0, in iscsit_xmit_datain_pdu()
592 iov_ret = iscsit_map_iovec(cmd, &cmd->iov_data[iov_count], in iscsit_xmit_datain_pdu()
593 cmd->orig_iov_data_count - (iov_count + 2), in iscsit_xmit_datain_pdu()
594 datain->offset, datain->length); in iscsit_xmit_datain_pdu()
596 return -1; in iscsit_xmit_datain_pdu()
599 tx_size += datain->length; in iscsit_xmit_datain_pdu()
601 cmd->padding = ((-datain->length) & 3); in iscsit_xmit_datain_pdu()
602 if (cmd->padding) { in iscsit_xmit_datain_pdu()
603 iov[iov_count].iov_base = cmd->pad_bytes; in iscsit_xmit_datain_pdu()
604 iov[iov_count++].iov_len = cmd->padding; in iscsit_xmit_datain_pdu()
605 tx_size += cmd->padding; in iscsit_xmit_datain_pdu()
607 pr_debug("Attaching %u padding bytes\n", cmd->padding); in iscsit_xmit_datain_pdu()
610 if (conn->conn_ops->DataDigest) { in iscsit_xmit_datain_pdu()
611 cmd->data_crc = iscsit_crc_sglist(cmd, datain->length, in iscsit_xmit_datain_pdu()
612 cmd->padding, cmd->pad_bytes); in iscsit_xmit_datain_pdu()
613 iov[iov_count].iov_base = &cmd->data_crc; in iscsit_xmit_datain_pdu()
618 datain->length + cmd->padding, cmd->data_crc); in iscsit_xmit_datain_pdu()
621 cmd->iov_data_count = iov_count; in iscsit_xmit_datain_pdu()
622 cmd->tx_size = tx_size; in iscsit_xmit_datain_pdu()
676 pr_debug("iSCSI-Target "ISCSIT_VERSION"\n"); in iscsi_target_init_module()
679 return -1; in iscsi_target_init_module()
681 spin_lock_init(&iscsit_global->ts_bitmap_lock); in iscsi_target_init_module()
690 iscsit_global->ts_bitmap = vzalloc(size); in iscsi_target_init_module()
691 if (!iscsit_global->ts_bitmap) in iscsi_target_init_module()
694 if (!zalloc_cpumask_var(&iscsit_global->allowed_cpumask, GFP_KERNEL)) { in iscsi_target_init_module()
695 pr_err("Unable to allocate iscsit_global->allowed_cpumask\n"); in iscsi_target_init_module()
698 cpumask_setall(iscsit_global->allowed_cpumask); in iscsi_target_init_module()
752 free_cpumask_var(iscsit_global->allowed_cpumask); in iscsi_target_init_module()
754 vfree(iscsit_global->ts_bitmap); in iscsi_target_init_module()
757 if (iscsit_global->discovery_tpg) in iscsi_target_init_module()
758 iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1); in iscsi_target_init_module()
762 return -ENOMEM; in iscsi_target_init_module()
777 if (iscsit_global->discovery_tpg) in iscsi_target_cleanup_module()
778 iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1); in iscsi_target_cleanup_module()
782 free_cpumask_var(iscsit_global->allowed_cpumask); in iscsi_target_cleanup_module()
783 vfree(iscsit_global->ts_bitmap); in iscsi_target_cleanup_module()
796 return -1; in iscsit_add_reject()
798 cmd->iscsi_opcode = ISCSI_OP_REJECT; in iscsit_add_reject()
799 cmd->reject_reason = reason; in iscsit_add_reject()
801 cmd->buf_ptr = kmemdup(buf, ISCSI_HDR_LEN, GFP_KERNEL); in iscsit_add_reject()
802 if (!cmd->buf_ptr) { in iscsit_add_reject()
803 pr_err("Unable to allocate memory for cmd->buf_ptr\n"); in iscsit_add_reject()
805 return -1; in iscsit_add_reject()
808 spin_lock_bh(&conn->cmd_lock); in iscsit_add_reject()
809 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); in iscsit_add_reject()
810 spin_unlock_bh(&conn->cmd_lock); in iscsit_add_reject()
812 cmd->i_state = ISTATE_SEND_REJECT; in iscsit_add_reject()
813 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); in iscsit_add_reject()
815 return -1; in iscsit_add_reject()
826 const bool do_put = cmd->se_cmd.se_tfo != NULL; in iscsit_add_reject_from_cmd()
828 if (!cmd->conn) { in iscsit_add_reject_from_cmd()
829 pr_err("cmd->conn is NULL for ITT: 0x%08x\n", in iscsit_add_reject_from_cmd()
830 cmd->init_task_tag); in iscsit_add_reject_from_cmd()
831 return -1; in iscsit_add_reject_from_cmd()
833 conn = cmd->conn; in iscsit_add_reject_from_cmd()
835 cmd->iscsi_opcode = ISCSI_OP_REJECT; in iscsit_add_reject_from_cmd()
836 cmd->reject_reason = reason; in iscsit_add_reject_from_cmd()
838 cmd->buf_ptr = kmemdup(buf, ISCSI_HDR_LEN, GFP_KERNEL); in iscsit_add_reject_from_cmd()
839 if (!cmd->buf_ptr) { in iscsit_add_reject_from_cmd()
840 pr_err("Unable to allocate memory for cmd->buf_ptr\n"); in iscsit_add_reject_from_cmd()
842 return -1; in iscsit_add_reject_from_cmd()
846 spin_lock_bh(&conn->cmd_lock); in iscsit_add_reject_from_cmd()
847 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); in iscsit_add_reject_from_cmd()
848 spin_unlock_bh(&conn->cmd_lock); in iscsit_add_reject_from_cmd()
851 cmd->i_state = ISTATE_SEND_REJECT; in iscsit_add_reject_from_cmd()
852 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); in iscsit_add_reject_from_cmd()
859 target_put_sess_cmd(&cmd->se_cmd); in iscsit_add_reject_from_cmd()
861 return -1; in iscsit_add_reject_from_cmd()
895 if (ent >= cmd->se_cmd.t_data_nents) { in iscsit_map_iovec()
896 pr_err("Initial page entry out-of-bounds\n"); in iscsit_map_iovec()
900 sg = &cmd->se_cmd.t_data_sg[ent]; in iscsit_map_iovec()
903 cmd->first_data_sg = sg; in iscsit_map_iovec()
904 cmd->first_data_sg_off = page_off; in iscsit_map_iovec()
912 cur_len = min_t(u32, data_length, sg->length - page_off); in iscsit_map_iovec()
914 iov[i].iov_base = kmap(sg_page(sg)) + sg->offset + page_off; in iscsit_map_iovec()
917 data_length -= cur_len; in iscsit_map_iovec()
923 cmd->kmapped_nents = i; in iscsit_map_iovec()
928 pr_err("offset %d + length %d overflow; %d/%d; sg-list:\n", in iscsit_map_iovec()
930 for_each_sg(cmd->se_cmd.t_data_sg, sg, in iscsit_map_iovec()
931 cmd->se_cmd.t_data_nents, i) { in iscsit_map_iovec()
933 i, sg->offset, sg->length); in iscsit_map_iovec()
935 return -1; in iscsit_map_iovec()
943 sg = cmd->first_data_sg; in iscsit_unmap_iovec()
945 for (i = 0; i < cmd->kmapped_nents; i++) in iscsit_unmap_iovec()
954 conn->exp_statsn = exp_statsn; in iscsit_ack_from_expstatsn()
956 if (conn->sess->sess_ops->RDMAExtensions) in iscsit_ack_from_expstatsn()
959 spin_lock_bh(&conn->cmd_lock); in iscsit_ack_from_expstatsn()
960 list_for_each_entry_safe(cmd, cmd_p, &conn->conn_cmd_list, i_conn_node) { in iscsit_ack_from_expstatsn()
961 spin_lock(&cmd->istate_lock); in iscsit_ack_from_expstatsn()
962 if ((cmd->i_state == ISTATE_SENT_STATUS) && in iscsit_ack_from_expstatsn()
963 iscsi_sna_lt(cmd->stat_sn, exp_statsn)) { in iscsit_ack_from_expstatsn()
964 cmd->i_state = ISTATE_REMOVE; in iscsit_ack_from_expstatsn()
965 spin_unlock(&cmd->istate_lock); in iscsit_ack_from_expstatsn()
966 list_move_tail(&cmd->i_conn_node, &ack_list); in iscsit_ack_from_expstatsn()
969 spin_unlock(&cmd->istate_lock); in iscsit_ack_from_expstatsn()
971 spin_unlock_bh(&conn->cmd_lock); in iscsit_ack_from_expstatsn()
974 list_del_init(&cmd->i_conn_node); in iscsit_ack_from_expstatsn()
981 u32 iov_count = max(1UL, DIV_ROUND_UP(cmd->se_cmd.data_length, PAGE_SIZE)); in iscsit_allocate_iovecs()
984 cmd->iov_data = kcalloc(iov_count, sizeof(*cmd->iov_data), GFP_KERNEL); in iscsit_allocate_iovecs()
985 if (!cmd->iov_data) in iscsit_allocate_iovecs()
986 return -ENOMEM; in iscsit_allocate_iovecs()
988 cmd->orig_iov_data_count = iov_count; in iscsit_allocate_iovecs()
1002 atomic_long_inc(&conn->sess->cmd_pdus); in iscsit_setup_scsi_cmd()
1005 payload_length = ntoh24(hdr->dlength); in iscsit_setup_scsi_cmd()
1009 if (!(hdr->flags & ISCSI_FLAG_CMD_WRITE) && in iscsit_setup_scsi_cmd()
1010 !(hdr->flags & ISCSI_FLAG_CMD_FINAL)) { in iscsit_setup_scsi_cmd()
1017 if (((hdr->flags & ISCSI_FLAG_CMD_READ) || in iscsit_setup_scsi_cmd()
1018 (hdr->flags & ISCSI_FLAG_CMD_WRITE)) && !hdr->data_length) { in iscsit_setup_scsi_cmd()
1020 * From RFC-3720 Section 10.3.1: in iscsit_setup_scsi_cmd()
1027 * to avoid any confusion with ->data_direction. in iscsit_setup_scsi_cmd()
1029 hdr->flags &= ~ISCSI_FLAG_CMD_READ; in iscsit_setup_scsi_cmd()
1030 hdr->flags &= ~ISCSI_FLAG_CMD_WRITE; in iscsit_setup_scsi_cmd()
1034 " CDB: 0x%02x, Fixing up flags\n", hdr->cdb[0]); in iscsit_setup_scsi_cmd()
1037 if (!(hdr->flags & ISCSI_FLAG_CMD_READ) && in iscsit_setup_scsi_cmd()
1038 !(hdr->flags & ISCSI_FLAG_CMD_WRITE) && (hdr->data_length != 0)) { in iscsit_setup_scsi_cmd()
1046 if ((hdr->flags & ISCSI_FLAG_CMD_READ) && in iscsit_setup_scsi_cmd()
1047 (hdr->flags & ISCSI_FLAG_CMD_WRITE)) { in iscsit_setup_scsi_cmd()
1053 if (hdr->opcode & ISCSI_OP_IMMEDIATE) { in iscsit_setup_scsi_cmd()
1060 if (payload_length && !conn->sess->sess_ops->ImmediateData) { in iscsit_setup_scsi_cmd()
1067 if ((be32_to_cpu(hdr->data_length) == payload_length) && in iscsit_setup_scsi_cmd()
1068 (!(hdr->flags & ISCSI_FLAG_CMD_FINAL))) { in iscsit_setup_scsi_cmd()
1076 if (payload_length > be32_to_cpu(hdr->data_length)) { in iscsit_setup_scsi_cmd()
1079 hdr->data_length); in iscsit_setup_scsi_cmd()
1084 if (payload_length > conn->conn_ops->MaxXmitDataSegmentLength) { in iscsit_setup_scsi_cmd()
1087 payload_length, conn->conn_ops->MaxXmitDataSegmentLength); in iscsit_setup_scsi_cmd()
1092 if (payload_length > conn->sess->sess_ops->FirstBurstLength) { in iscsit_setup_scsi_cmd()
1095 payload_length, conn->sess->sess_ops->FirstBurstLength); in iscsit_setup_scsi_cmd()
1100 cdb = hdr->cdb; in iscsit_setup_scsi_cmd()
1102 if (hdr->hlength) { in iscsit_setup_scsi_cmd()
1104 if (ecdb_ahdr->ahstype != ISCSI_AHSTYPE_CDB) { in iscsit_setup_scsi_cmd()
1106 ecdb_ahdr->ahstype); in iscsit_setup_scsi_cmd()
1111 cdb = kmalloc(be16_to_cpu(ecdb_ahdr->ahslength) + 15, in iscsit_setup_scsi_cmd()
1116 memcpy(cdb, hdr->cdb, ISCSI_CDB_SIZE); in iscsit_setup_scsi_cmd()
1117 memcpy(cdb + ISCSI_CDB_SIZE, ecdb_ahdr->ecdb, in iscsit_setup_scsi_cmd()
1118 be16_to_cpu(ecdb_ahdr->ahslength) - 1); in iscsit_setup_scsi_cmd()
1121 data_direction = (hdr->flags & ISCSI_FLAG_CMD_WRITE) ? DMA_TO_DEVICE : in iscsit_setup_scsi_cmd()
1122 (hdr->flags & ISCSI_FLAG_CMD_READ) ? DMA_FROM_DEVICE : in iscsit_setup_scsi_cmd()
1125 cmd->data_direction = data_direction; in iscsit_setup_scsi_cmd()
1126 iscsi_task_attr = hdr->flags & ISCSI_FLAG_CMD_ATTR_MASK; in iscsit_setup_scsi_cmd()
1145 cmd->iscsi_opcode = ISCSI_OP_SCSI_CMD; in iscsit_setup_scsi_cmd()
1146 cmd->i_state = ISTATE_NEW_CMD; in iscsit_setup_scsi_cmd()
1147 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0); in iscsit_setup_scsi_cmd()
1148 cmd->immediate_data = (payload_length) ? 1 : 0; in iscsit_setup_scsi_cmd()
1149 cmd->unsolicited_data = ((!(hdr->flags & ISCSI_FLAG_CMD_FINAL) && in iscsit_setup_scsi_cmd()
1150 (hdr->flags & ISCSI_FLAG_CMD_WRITE)) ? 1 : 0); in iscsit_setup_scsi_cmd()
1151 if (cmd->unsolicited_data) in iscsit_setup_scsi_cmd()
1152 cmd->cmd_flags |= ICF_NON_IMMEDIATE_UNSOLICITED_DATA; in iscsit_setup_scsi_cmd()
1154 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; in iscsit_setup_scsi_cmd()
1155 if (hdr->flags & ISCSI_FLAG_CMD_READ) in iscsit_setup_scsi_cmd()
1156 cmd->targ_xfer_tag = session_get_next_ttt(conn->sess); in iscsit_setup_scsi_cmd()
1158 cmd->targ_xfer_tag = 0xFFFFFFFF; in iscsit_setup_scsi_cmd()
1159 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); in iscsit_setup_scsi_cmd()
1160 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn); in iscsit_setup_scsi_cmd()
1161 cmd->first_burst_len = payload_length; in iscsit_setup_scsi_cmd()
1163 if (!conn->sess->sess_ops->RDMAExtensions && in iscsit_setup_scsi_cmd()
1164 cmd->data_direction == DMA_FROM_DEVICE) { in iscsit_setup_scsi_cmd()
1169 if (cdb != hdr->cdb) in iscsit_setup_scsi_cmd()
1181 __target_init_cmd(&cmd->se_cmd, &iscsi_ops, in iscsit_setup_scsi_cmd()
1182 conn->sess->se_sess, be32_to_cpu(hdr->data_length), in iscsit_setup_scsi_cmd()
1183 cmd->data_direction, sam_task_attr, in iscsit_setup_scsi_cmd()
1184 cmd->sense_buffer + 2, scsilun_to_int(&hdr->lun), in iscsit_setup_scsi_cmd()
1185 conn->cmd_cnt); in iscsit_setup_scsi_cmd()
1188 " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt, in iscsit_setup_scsi_cmd()
1189 hdr->cmdsn, be32_to_cpu(hdr->data_length), payload_length, in iscsit_setup_scsi_cmd()
1190 conn->cid); in iscsit_setup_scsi_cmd()
1192 target_get_sess_cmd(&cmd->se_cmd, true); in iscsit_setup_scsi_cmd()
1194 cmd->se_cmd.tag = (__force u32)cmd->init_task_tag; in iscsit_setup_scsi_cmd()
1195 cmd->sense_reason = target_cmd_init_cdb(&cmd->se_cmd, cdb, in iscsit_setup_scsi_cmd()
1198 if (cdb != hdr->cdb) in iscsit_setup_scsi_cmd()
1201 if (cmd->sense_reason) { in iscsit_setup_scsi_cmd()
1202 if (cmd->sense_reason == TCM_OUT_OF_RESOURCES) { in iscsit_setup_scsi_cmd()
1210 cmd->sense_reason = transport_lookup_cmd_lun(&cmd->se_cmd); in iscsit_setup_scsi_cmd()
1211 if (cmd->sense_reason) in iscsit_setup_scsi_cmd()
1214 cmd->sense_reason = target_cmd_parse_cdb(&cmd->se_cmd); in iscsit_setup_scsi_cmd()
1215 if (cmd->sense_reason) in iscsit_setup_scsi_cmd()
1224 spin_lock_bh(&conn->cmd_lock); in iscsit_setup_scsi_cmd()
1225 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); in iscsit_setup_scsi_cmd()
1226 spin_unlock_bh(&conn->cmd_lock); in iscsit_setup_scsi_cmd()
1235 spin_lock_bh(&cmd->dataout_timeout_lock); in iscsit_set_unsolicited_dataout()
1236 iscsit_start_dataout_timer(cmd, cmd->conn); in iscsit_set_unsolicited_dataout()
1237 spin_unlock_bh(&cmd->dataout_timeout_lock); in iscsit_set_unsolicited_dataout()
1255 if (!cmd->immediate_data) { in iscsit_process_scsi_cmd()
1257 (unsigned char *)hdr, hdr->cmdsn); in iscsit_process_scsi_cmd()
1259 return -1; in iscsit_process_scsi_cmd()
1261 target_put_sess_cmd(&cmd->se_cmd); in iscsit_process_scsi_cmd()
1266 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn)); in iscsit_process_scsi_cmd()
1271 if (!cmd->immediate_data) { in iscsit_process_scsi_cmd()
1272 if (!cmd->sense_reason && cmd->unsolicited_data) in iscsit_process_scsi_cmd()
1274 if (!cmd->sense_reason) in iscsit_process_scsi_cmd()
1277 target_put_sess_cmd(&cmd->se_cmd); in iscsit_process_scsi_cmd()
1286 if (cmd->sense_reason) in iscsit_process_scsi_cmd()
1292 cmd->sense_reason = transport_generic_new_cmd(&cmd->se_cmd); in iscsit_process_scsi_cmd()
1293 if (cmd->sense_reason) in iscsit_process_scsi_cmd()
1311 u32 length = min(cmd->se_cmd.data_length - cmd->write_data_done, in iscsit_get_immediate_data()
1312 cmd->first_burst_len); in iscsit_get_immediate_data()
1314 pr_debug("Dumping min(%d - %d, %d) = %d bytes of immediate data\n", in iscsit_get_immediate_data()
1315 cmd->se_cmd.data_length, cmd->write_data_done, in iscsit_get_immediate_data()
1316 cmd->first_burst_len, length); in iscsit_get_immediate_data()
1317 rc = iscsit_dump_data_payload(cmd->conn, length, 1); in iscsit_get_immediate_data()
1323 cmd->first_burst_len); in iscsit_get_immediate_data()
1332 cmdsn_ret = iscsit_sequence_cmd(cmd->conn, cmd, in iscsit_get_immediate_data()
1333 (unsigned char *)hdr, hdr->cmdsn); in iscsit_get_immediate_data()
1335 return -1; in iscsit_get_immediate_data()
1337 if (cmd->sense_reason || cmdsn_ret == CMDSN_LOWER_THAN_EXP) { in iscsit_get_immediate_data()
1338 target_put_sess_cmd(&cmd->se_cmd); in iscsit_get_immediate_data()
1341 } else if (cmd->unsolicited_data) in iscsit_get_immediate_data()
1356 cmd->i_state = ISTATE_REMOVE; in iscsit_get_immediate_data()
1357 iscsit_add_cmd_to_immediate_queue(cmd, cmd->conn, cmd->i_state); in iscsit_get_immediate_data()
1359 return -1; in iscsit_get_immediate_data()
1383 immed_data = cmd->immediate_data; in iscsit_handle_scsi_cmd()
1400 struct scatterlist *sg = cmd->first_data_sg; in iscsit_crc_sglist()
1401 unsigned int page_off = cmd->first_data_sg_off; in iscsit_crc_sglist()
1405 u32 cur_len = min_t(u32, data_length, sg->length - page_off); in iscsit_crc_sglist()
1408 virt = kmap_local_page(sg_page(sg)) + sg->offset + page_off; in iscsit_crc_sglist()
1416 data_length -= cur_len; in iscsit_crc_sglist()
1448 atomic_long_add(payload_length, &conn->sess->rx_data_octets); in __iscsit_check_dataout_hdr()
1452 hdr->itt, hdr->ttt, hdr->datasn, ntohl(hdr->offset), in __iscsit_check_dataout_hdr()
1453 payload_length, conn->cid); in __iscsit_check_dataout_hdr()
1455 if (cmd->cmd_flags & ICF_GOT_LAST_DATAOUT) { in __iscsit_check_dataout_hdr()
1458 cmd->init_task_tag); in __iscsit_check_dataout_hdr()
1462 if (cmd->data_direction != DMA_TO_DEVICE) { in __iscsit_check_dataout_hdr()
1464 " NON-WRITE command.\n", cmd->init_task_tag); in __iscsit_check_dataout_hdr()
1467 se_cmd = &cmd->se_cmd; in __iscsit_check_dataout_hdr()
1470 if ((be32_to_cpu(hdr->offset) + payload_length) > cmd->se_cmd.data_length) { in __iscsit_check_dataout_hdr()
1472 be32_to_cpu(hdr->offset), payload_length, in __iscsit_check_dataout_hdr()
1473 cmd->se_cmd.data_length); in __iscsit_check_dataout_hdr()
1477 if (cmd->unsolicited_data) { in __iscsit_check_dataout_hdr()
1480 if (conn->sess->sess_ops->InitialR2T) { in __iscsit_check_dataout_hdr()
1483 transport_send_check_condition_and_sense(&cmd->se_cmd, in __iscsit_check_dataout_hdr()
1485 return -1; in __iscsit_check_dataout_hdr()
1494 WARN_ON(se_cmd->t_state != TRANSPORT_WRITE_PENDING); in __iscsit_check_dataout_hdr()
1495 if (!(se_cmd->se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE)) in __iscsit_check_dataout_hdr()
1504 if (hdr->flags & ISCSI_FLAG_CMD_FINAL) in __iscsit_check_dataout_hdr()
1520 if (se_cmd->transport_state & CMD_T_ABORTED) { in __iscsit_check_dataout_hdr()
1521 if (hdr->flags & ISCSI_FLAG_CMD_FINAL && in __iscsit_check_dataout_hdr()
1522 --cmd->outstanding_r2ts < 1) in __iscsit_check_dataout_hdr()
1530 * within-command recovery checks before receiving the payload. in __iscsit_check_dataout_hdr()
1536 return -1; in __iscsit_check_dataout_hdr()
1548 u32 payload_length = ntoh24(hdr->dlength); in iscsit_check_dataout_hdr()
1557 if (payload_length > conn->conn_ops->MaxXmitDataSegmentLength) { in iscsit_check_dataout_hdr()
1560 conn->conn_ops->MaxXmitDataSegmentLength); in iscsit_check_dataout_hdr()
1564 cmd = iscsit_find_cmd_from_itt_or_dump(conn, hdr->itt, payload_length); in iscsit_check_dataout_hdr()
1586 payload_length = min_t(u32, cmd->se_cmd.data_length, in iscsit_get_dataout()
1587 ntoh24(hdr->dlength)); in iscsit_get_dataout()
1589 iov = &cmd->iov_data[0]; in iscsit_get_dataout()
1591 iov_ret = iscsit_map_iovec(cmd, iov, cmd->orig_iov_data_count - 2, in iscsit_get_dataout()
1592 be32_to_cpu(hdr->offset), payload_length); in iscsit_get_dataout()
1594 return -1; in iscsit_get_dataout()
1598 padding = ((-payload_length) & 3); in iscsit_get_dataout()
1600 iov[iov_count].iov_base = cmd->pad_bytes; in iscsit_get_dataout()
1606 if (conn->conn_ops->DataDigest) { in iscsit_get_dataout()
1612 WARN_ON_ONCE(iov_count > cmd->orig_iov_data_count); in iscsit_get_dataout()
1613 rx_got = rx_data(conn, &cmd->iov_data[0], iov_count, rx_size); in iscsit_get_dataout()
1618 return -1; in iscsit_get_dataout()
1620 if (conn->conn_ops->DataDigest) { in iscsit_get_dataout()
1624 cmd->pad_bytes); in iscsit_get_dataout()
1629 hdr->itt, hdr->offset, payload_length, in iscsit_get_dataout()
1630 hdr->datasn, checksum, data_crc); in iscsit_get_dataout()
1646 struct iscsit_conn *conn = cmd->conn; in iscsit_check_dataout_payload()
1650 * within-command recovery. in iscsit_check_dataout_payload()
1657 conn->conn_transport->iscsit_get_dataout(conn, cmd, false); in iscsit_check_dataout_payload()
1663 spin_lock_bh(&cmd->istate_lock); in iscsit_check_dataout_payload()
1664 ooo_cmdsn = (cmd->cmd_flags & ICF_OOO_CMDSN); in iscsit_check_dataout_payload()
1665 cmd->cmd_flags |= ICF_GOT_LAST_DATAOUT; in iscsit_check_dataout_payload()
1666 cmd->i_state = ISTATE_RECEIVED_LAST_DATAOUT; in iscsit_check_dataout_payload()
1667 spin_unlock_bh(&cmd->istate_lock); in iscsit_check_dataout_payload()
1672 target_execute_cmd(&cmd->se_cmd); in iscsit_check_dataout_payload()
1675 return -1; in iscsit_check_dataout_payload()
1706 u32 payload_length = ntoh24(hdr->dlength); in iscsit_setup_nop_out()
1708 if (!(hdr->flags & ISCSI_FLAG_CMD_FINAL)) { in iscsit_setup_nop_out()
1718 if (hdr->itt == RESERVED_ITT && !(hdr->opcode & ISCSI_OP_IMMEDIATE)) { in iscsit_setup_nop_out()
1729 if (payload_length > conn->conn_ops->MaxXmitDataSegmentLength) { in iscsit_setup_nop_out()
1733 conn->conn_ops->MaxXmitDataSegmentLength); in iscsit_setup_nop_out()
1744 hdr->itt == RESERVED_ITT ? "Response" : "Request", in iscsit_setup_nop_out()
1745 hdr->itt, hdr->ttt, hdr->cmdsn, hdr->exp_statsn, in iscsit_setup_nop_out()
1754 if (hdr->ttt == cpu_to_be32(0xFFFFFFFF)) { in iscsit_setup_nop_out()
1755 cmd->iscsi_opcode = ISCSI_OP_NOOP_OUT; in iscsit_setup_nop_out()
1756 cmd->i_state = ISTATE_SEND_NOPIN; in iscsit_setup_nop_out()
1757 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? in iscsit_setup_nop_out()
1759 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; in iscsit_setup_nop_out()
1760 cmd->targ_xfer_tag = 0xFFFFFFFF; in iscsit_setup_nop_out()
1761 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); in iscsit_setup_nop_out()
1762 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn); in iscsit_setup_nop_out()
1763 cmd->data_direction = DMA_NONE; in iscsit_setup_nop_out()
1778 if (hdr->itt != RESERVED_ITT) { in iscsit_process_nop_out()
1783 spin_lock_bh(&conn->cmd_lock); in iscsit_process_nop_out()
1784 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); in iscsit_process_nop_out()
1785 spin_unlock_bh(&conn->cmd_lock); in iscsit_process_nop_out()
1787 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn)); in iscsit_process_nop_out()
1789 if (hdr->opcode & ISCSI_OP_IMMEDIATE) { in iscsit_process_nop_out()
1791 cmd->i_state); in iscsit_process_nop_out()
1796 (unsigned char *)hdr, hdr->cmdsn); in iscsit_process_nop_out()
1800 return -1; in iscsit_process_nop_out()
1807 if (hdr->ttt != cpu_to_be32(0xFFFFFFFF)) { in iscsit_process_nop_out()
1808 cmd_p = iscsit_find_cmd_from_ttt(conn, be32_to_cpu(hdr->ttt)); in iscsit_process_nop_out()
1810 return -EINVAL; in iscsit_process_nop_out()
1814 cmd_p->i_state = ISTATE_REMOVE; in iscsit_process_nop_out()
1815 iscsit_add_cmd_to_immediate_queue(cmd_p, conn, cmd_p->i_state); in iscsit_process_nop_out()
1838 u32 payload_length = ntoh24(hdr->dlength); in iscsit_handle_nop_out()
1845 * Handle NOP-OUT payload for traditional iSCSI sockets in iscsit_handle_nop_out()
1847 if (payload_length && hdr->ttt == cpu_to_be32(0xFFFFFFFF)) { in iscsit_handle_nop_out()
1853 ret = -1; in iscsit_handle_nop_out()
1857 iov = &cmd->iov_misc[0]; in iscsit_handle_nop_out()
1861 padding = ((-payload_length) & 3); in iscsit_handle_nop_out()
1865 iov[niov].iov_base = &cmd->pad_bytes; in iscsit_handle_nop_out()
1869 if (conn->conn_ops->DataDigest) { in iscsit_handle_nop_out()
1875 WARN_ON_ONCE(niov > ARRAY_SIZE(cmd->iov_misc)); in iscsit_handle_nop_out()
1876 rx_got = rx_data(conn, &cmd->iov_misc[0], niov, rx_size); in iscsit_handle_nop_out()
1878 ret = -1; in iscsit_handle_nop_out()
1882 if (conn->conn_ops->DataDigest) { in iscsit_handle_nop_out()
1884 padding, cmd->pad_bytes); in iscsit_handle_nop_out()
1889 if (!conn->sess->sess_ops->ErrorRecoveryLevel) { in iscsit_handle_nop_out()
1893 ret = -1; in iscsit_handle_nop_out()
1902 " DataCRC error.\n", hdr->cmdsn); in iscsit_handle_nop_out()
1915 * Attach ping data to struct iscsit_cmd->buf_ptr. in iscsit_handle_nop_out()
1917 cmd->buf_ptr = ping_data; in iscsit_handle_nop_out()
1918 cmd->buf_ptr_size = payload_length; in iscsit_handle_nop_out()
1967 hdr->flags &= ~ISCSI_FLAG_CMD_FINAL; in iscsit_handle_task_mgt_cmd()
1968 function = hdr->flags; in iscsit_handle_task_mgt_cmd()
1972 " 0x%08x, CID: %hu\n", hdr->itt, hdr->cmdsn, function, in iscsit_handle_task_mgt_cmd()
1973 hdr->rtt, hdr->refcmdsn, conn->cid); in iscsit_handle_task_mgt_cmd()
1977 hdr->rtt != RESERVED_ITT)) { in iscsit_handle_task_mgt_cmd()
1979 hdr->rtt = RESERVED_ITT; in iscsit_handle_task_mgt_cmd()
1983 !(hdr->opcode & ISCSI_OP_IMMEDIATE)) { in iscsit_handle_task_mgt_cmd()
1991 be32_to_cpu(hdr->refcmdsn) != ISCSI_RESERVED_TAG) in iscsit_handle_task_mgt_cmd()
1992 hdr->refcmdsn = cpu_to_be32(ISCSI_RESERVED_TAG); in iscsit_handle_task_mgt_cmd()
1994 cmd->data_direction = DMA_NONE; in iscsit_handle_task_mgt_cmd()
1995 cmd->tmr_req = kzalloc(sizeof(*cmd->tmr_req), GFP_KERNEL); in iscsit_handle_task_mgt_cmd()
1996 if (!cmd->tmr_req) { in iscsit_handle_task_mgt_cmd()
2002 __target_init_cmd(&cmd->se_cmd, &iscsi_ops, in iscsit_handle_task_mgt_cmd()
2003 conn->sess->se_sess, 0, DMA_NONE, in iscsit_handle_task_mgt_cmd()
2004 TCM_SIMPLE_TAG, cmd->sense_buffer + 2, in iscsit_handle_task_mgt_cmd()
2005 scsilun_to_int(&hdr->lun), in iscsit_handle_task_mgt_cmd()
2006 conn->cmd_cnt); in iscsit_handle_task_mgt_cmd()
2008 target_get_sess_cmd(&cmd->se_cmd, true); in iscsit_handle_task_mgt_cmd()
2012 * LIO-Target $FABRIC_MOD in iscsit_handle_task_mgt_cmd()
2023 ret = core_tmr_alloc_req(&cmd->se_cmd, cmd->tmr_req, tcm_function, in iscsit_handle_task_mgt_cmd()
2029 cmd->tmr_req->se_tmr_req = cmd->se_cmd.se_tmr_req; in iscsit_handle_task_mgt_cmd()
2031 cmd->iscsi_opcode = ISCSI_OP_SCSI_TMFUNC; in iscsit_handle_task_mgt_cmd()
2032 cmd->i_state = ISTATE_SEND_TASKMGTRSP; in iscsit_handle_task_mgt_cmd()
2033 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0); in iscsit_handle_task_mgt_cmd()
2034 cmd->init_task_tag = hdr->itt; in iscsit_handle_task_mgt_cmd()
2035 cmd->targ_xfer_tag = 0xFFFFFFFF; in iscsit_handle_task_mgt_cmd()
2036 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); in iscsit_handle_task_mgt_cmd()
2037 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn); in iscsit_handle_task_mgt_cmd()
2038 se_tmr = cmd->se_cmd.se_tmr_req; in iscsit_handle_task_mgt_cmd()
2039 tmr_req = cmd->tmr_req; in iscsit_handle_task_mgt_cmd()
2044 ret = transport_lookup_tmr_lun(&cmd->se_cmd); in iscsit_handle_task_mgt_cmd()
2046 se_tmr->response = ISCSI_TMF_RSP_NO_LUN; in iscsit_handle_task_mgt_cmd()
2053 se_tmr->response = iscsit_tmr_abort_task(cmd, buf); in iscsit_handle_task_mgt_cmd()
2054 if (se_tmr->response) in iscsit_handle_task_mgt_cmd()
2064 se_tmr->response = ISCSI_TMF_RSP_AUTH_FAILED; in iscsit_handle_task_mgt_cmd()
2070 se_tmr->response = ISCSI_TMF_RSP_AUTH_FAILED; in iscsit_handle_task_mgt_cmd()
2075 se_tmr->response = iscsit_tmr_task_reassign(cmd, buf); in iscsit_handle_task_mgt_cmd()
2080 if (se_tmr->response) in iscsit_handle_task_mgt_cmd()
2090 se_tmr->response = ISCSI_TMF_RSP_NOT_SUPPORTED; in iscsit_handle_task_mgt_cmd()
2095 (se_tmr->response == ISCSI_TMF_RSP_COMPLETE)) in iscsit_handle_task_mgt_cmd()
2096 se_tmr->call_transport = 1; in iscsit_handle_task_mgt_cmd()
2098 spin_lock_bh(&conn->cmd_lock); in iscsit_handle_task_mgt_cmd()
2099 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); in iscsit_handle_task_mgt_cmd()
2100 spin_unlock_bh(&conn->cmd_lock); in iscsit_handle_task_mgt_cmd()
2102 if (!(hdr->opcode & ISCSI_OP_IMMEDIATE)) { in iscsit_handle_task_mgt_cmd()
2103 int cmdsn_ret = iscsit_sequence_cmd(conn, cmd, buf, hdr->cmdsn); in iscsit_handle_task_mgt_cmd()
2107 target_put_sess_cmd(&cmd->se_cmd); in iscsit_handle_task_mgt_cmd()
2110 return -1; in iscsit_handle_task_mgt_cmd()
2113 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn)); in iscsit_handle_task_mgt_cmd()
2115 if (out_of_order_cmdsn || !(hdr->opcode & ISCSI_OP_IMMEDIATE)) in iscsit_handle_task_mgt_cmd()
2120 if (se_tmr->call_transport) in iscsit_handle_task_mgt_cmd()
2121 return transport_generic_handle_tmr(&cmd->se_cmd); in iscsit_handle_task_mgt_cmd()
2131 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); in iscsit_handle_task_mgt_cmd()
2132 target_put_sess_cmd(&cmd->se_cmd); in iscsit_handle_task_mgt_cmd()
2142 u32 payload_length = ntoh24(hdr->dlength); in iscsit_setup_text_cmd()
2144 if (payload_length > conn->conn_ops->MaxXmitDataSegmentLength) { in iscsit_setup_text_cmd()
2147 payload_length, conn->conn_ops->MaxXmitDataSegmentLength); in iscsit_setup_text_cmd()
2152 if (!(hdr->flags & ISCSI_FLAG_CMD_FINAL) || in iscsit_setup_text_cmd()
2153 (hdr->flags & ISCSI_FLAG_TEXT_CONTINUE)) { in iscsit_setup_text_cmd()
2160 " ExpStatSN: 0x%08x, Length: %u\n", hdr->itt, hdr->cmdsn, in iscsit_setup_text_cmd()
2161 hdr->exp_statsn, payload_length); in iscsit_setup_text_cmd()
2163 cmd->iscsi_opcode = ISCSI_OP_TEXT; in iscsit_setup_text_cmd()
2164 cmd->i_state = ISTATE_SEND_TEXTRSP; in iscsit_setup_text_cmd()
2165 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0); in iscsit_setup_text_cmd()
2166 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; in iscsit_setup_text_cmd()
2167 cmd->targ_xfer_tag = 0xFFFFFFFF; in iscsit_setup_text_cmd()
2168 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); in iscsit_setup_text_cmd()
2169 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn); in iscsit_setup_text_cmd()
2170 cmd->data_direction = DMA_NONE; in iscsit_setup_text_cmd()
2171 kfree(cmd->text_in_ptr); in iscsit_setup_text_cmd()
2172 cmd->text_in_ptr = NULL; in iscsit_setup_text_cmd()
2182 unsigned char *text_in = cmd->text_in_ptr, *text_ptr; in iscsit_process_text_cmd()
2186 cmd->targ_xfer_tag = be32_to_cpu(hdr->ttt); in iscsit_process_text_cmd()
2187 if (cmd->targ_xfer_tag == 0xFFFFFFFF) { in iscsit_process_text_cmd()
2203 cmd->cmd_flags |= ICF_SENDTARGETS_ALL; in iscsit_process_text_cmd()
2206 cmd->cmd_flags |= ICF_SENDTARGETS_SINGLE; in iscsit_process_text_cmd()
2213 spin_lock_bh(&conn->cmd_lock); in iscsit_process_text_cmd()
2214 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); in iscsit_process_text_cmd()
2215 spin_unlock_bh(&conn->cmd_lock); in iscsit_process_text_cmd()
2218 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn)); in iscsit_process_text_cmd()
2220 if (!(hdr->opcode & ISCSI_OP_IMMEDIATE)) { in iscsit_process_text_cmd()
2222 (unsigned char *)hdr, hdr->cmdsn); in iscsit_process_text_cmd()
2224 return -1; in iscsit_process_text_cmd()
2243 u32 payload_length = ntoh24(hdr->dlength); in iscsit_handle_text_cmd()
2262 cmd->text_in_ptr = text_in; in iscsit_handle_text_cmd()
2268 padding = rx_size - payload_length; in iscsit_handle_text_cmd()
2272 if (conn->conn_ops->DataDigest) { in iscsit_handle_text_cmd()
2283 if (conn->conn_ops->DataDigest) { in iscsit_handle_text_cmd()
2289 if (!conn->sess->sess_ops->ErrorRecoveryLevel) { in iscsit_handle_text_cmd()
2301 " DataCRC error.\n", hdr->cmdsn); in iscsit_handle_text_cmd()
2311 text_in[payload_length - 1] = '\0'; in iscsit_handle_text_cmd()
2319 kfree(cmd->text_in_ptr); in iscsit_handle_text_cmd()
2320 cmd->text_in_ptr = NULL; in iscsit_handle_text_cmd()
2327 struct iscsit_session *sess = conn->sess; in iscsit_logout_closesession()
2330 " for SID: %u.\n", conn->cid, conn->sess->sid); in iscsit_logout_closesession()
2332 atomic_set(&sess->session_logout, 1); in iscsit_logout_closesession()
2333 atomic_set(&conn->conn_logout_remove, 1); in iscsit_logout_closesession()
2334 conn->conn_logout_reason = ISCSI_LOGOUT_REASON_CLOSE_SESSION; in iscsit_logout_closesession()
2339 spin_lock_bh(&sess->conn_lock); in iscsit_logout_closesession()
2340 list_for_each_entry(conn_p, &sess->sess_conn_list, conn_list) { in iscsit_logout_closesession()
2341 if (conn_p->conn_state != TARG_CONN_STATE_LOGGED_IN) in iscsit_logout_closesession()
2345 conn_p->conn_state = TARG_CONN_STATE_IN_LOGOUT; in iscsit_logout_closesession()
2347 spin_unlock_bh(&sess->conn_lock); in iscsit_logout_closesession()
2349 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); in iscsit_logout_closesession()
2357 struct iscsit_session *sess = conn->sess; in iscsit_logout_closeconnection()
2360 " %hu on CID: %hu.\n", cmd->logout_cid, conn->cid); in iscsit_logout_closeconnection()
2366 if (conn->cid == cmd->logout_cid) { in iscsit_logout_closeconnection()
2367 spin_lock_bh(&conn->state_lock); in iscsit_logout_closeconnection()
2369 conn->conn_state = TARG_CONN_STATE_IN_LOGOUT; in iscsit_logout_closeconnection()
2371 atomic_set(&conn->conn_logout_remove, 1); in iscsit_logout_closeconnection()
2372 conn->conn_logout_reason = ISCSI_LOGOUT_REASON_CLOSE_CONNECTION; in iscsit_logout_closeconnection()
2375 spin_unlock_bh(&conn->state_lock); in iscsit_logout_closeconnection()
2386 cmd->logout_cid); in iscsit_logout_closeconnection()
2388 cmd->logout_response = ISCSI_LOGOUT_CID_NOT_FOUND; in iscsit_logout_closeconnection()
2390 cmd->i_state); in iscsit_logout_closeconnection()
2397 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); in iscsit_logout_closeconnection()
2404 struct iscsit_session *sess = conn->sess; in iscsit_logout_removeconnforrecovery()
2407 " CID: %hu on CID: %hu.\n", cmd->logout_cid, conn->cid); in iscsit_logout_removeconnforrecovery()
2409 if (sess->sess_ops->ErrorRecoveryLevel != 2) { in iscsit_logout_removeconnforrecovery()
2412 cmd->logout_response = ISCSI_LOGOUT_RECOVERY_UNSUPPORTED; in iscsit_logout_removeconnforrecovery()
2413 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); in iscsit_logout_removeconnforrecovery()
2417 if (conn->cid == cmd->logout_cid) { in iscsit_logout_removeconnforrecovery()
2420 cmd->logout_cid, conn->cid); in iscsit_logout_removeconnforrecovery()
2421 cmd->logout_response = ISCSI_LOGOUT_CLEANUP_FAILED; in iscsit_logout_removeconnforrecovery()
2422 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); in iscsit_logout_removeconnforrecovery()
2426 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); in iscsit_logout_removeconnforrecovery()
2441 reason_code = (hdr->flags & 0x7f); in iscsit_handle_logout_cmd()
2444 spin_lock(&tiqn->logout_stats.lock); in iscsit_handle_logout_cmd()
2446 tiqn->logout_stats.normal_logouts++; in iscsit_handle_logout_cmd()
2448 tiqn->logout_stats.abnormal_logouts++; in iscsit_handle_logout_cmd()
2449 spin_unlock(&tiqn->logout_stats.lock); in iscsit_handle_logout_cmd()
2454 hdr->itt, hdr->cmdsn, hdr->exp_statsn, reason_code, in iscsit_handle_logout_cmd()
2455 hdr->cid, conn->cid); in iscsit_handle_logout_cmd()
2457 if (conn->conn_state != TARG_CONN_STATE_LOGGED_IN) { in iscsit_handle_logout_cmd()
2464 cmd->iscsi_opcode = ISCSI_OP_LOGOUT; in iscsit_handle_logout_cmd()
2465 cmd->i_state = ISTATE_SEND_LOGOUTRSP; in iscsit_handle_logout_cmd()
2466 cmd->immediate_cmd = ((hdr->opcode & ISCSI_OP_IMMEDIATE) ? 1 : 0); in iscsit_handle_logout_cmd()
2467 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; in iscsit_handle_logout_cmd()
2468 cmd->targ_xfer_tag = 0xFFFFFFFF; in iscsit_handle_logout_cmd()
2469 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); in iscsit_handle_logout_cmd()
2470 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn); in iscsit_handle_logout_cmd()
2471 cmd->logout_cid = be16_to_cpu(hdr->cid); in iscsit_handle_logout_cmd()
2472 cmd->logout_reason = reason_code; in iscsit_handle_logout_cmd()
2473 cmd->data_direction = DMA_NONE; in iscsit_handle_logout_cmd()
2481 be16_to_cpu(hdr->cid) == conn->cid)) in iscsit_handle_logout_cmd()
2484 spin_lock_bh(&conn->cmd_lock); in iscsit_handle_logout_cmd()
2485 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); in iscsit_handle_logout_cmd()
2486 spin_unlock_bh(&conn->cmd_lock); in iscsit_handle_logout_cmd()
2489 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn)); in iscsit_handle_logout_cmd()
2493 * Non-Immediate Logout Commands are executed in CmdSN order. in iscsit_handle_logout_cmd()
2495 if (cmd->immediate_cmd) { in iscsit_handle_logout_cmd()
2501 cmdsn_ret = iscsit_sequence_cmd(conn, cmd, buf, hdr->cmdsn); in iscsit_handle_logout_cmd()
2505 return -1; in iscsit_handle_logout_cmd()
2519 hdr->flags &= ~ISCSI_FLAG_CMD_FINAL; in iscsit_handle_snack()
2523 " CID: %hu\n", hdr->itt, hdr->exp_statsn, hdr->flags, in iscsit_handle_snack()
2524 hdr->begrun, hdr->runlength, conn->cid); in iscsit_handle_snack()
2526 if (!conn->sess->sess_ops->ErrorRecoveryLevel) { in iscsit_handle_snack()
2536 switch (hdr->flags & ISCSI_FLAG_SNACK_TYPE_MASK) { in iscsit_handle_snack()
2539 hdr->itt, in iscsit_handle_snack()
2540 be32_to_cpu(hdr->ttt), in iscsit_handle_snack()
2541 be32_to_cpu(hdr->begrun), in iscsit_handle_snack()
2542 be32_to_cpu(hdr->runlength)); in iscsit_handle_snack()
2544 return iscsit_handle_status_snack(conn, hdr->itt, in iscsit_handle_snack()
2545 be32_to_cpu(hdr->ttt), in iscsit_handle_snack()
2546 be32_to_cpu(hdr->begrun), be32_to_cpu(hdr->runlength)); in iscsit_handle_snack()
2548 return iscsit_handle_data_ack(conn, be32_to_cpu(hdr->ttt), in iscsit_handle_snack()
2549 be32_to_cpu(hdr->begrun), in iscsit_handle_snack()
2550 be32_to_cpu(hdr->runlength)); in iscsit_handle_snack()
2552 /* FIXME: Support R-Data SNACK */ in iscsit_handle_snack()
2553 pr_err("R-Data SNACK Not Supported.\n"); in iscsit_handle_snack()
2558 " error.\n", hdr->flags & 0x0f); in iscsit_handle_snack()
2569 if ((conn->sock->sk->sk_shutdown & SEND_SHUTDOWN) || in iscsit_rx_thread_wait_for_tcp()
2570 (conn->sock->sk->sk_shutdown & RCV_SHUTDOWN)) { in iscsit_rx_thread_wait_for_tcp()
2572 &conn->rx_half_close_comp, in iscsit_rx_thread_wait_for_tcp()
2584 struct iscsit_conn *conn = cmd->conn; in iscsit_handle_immediate_data()
2588 BUG_ON(cmd->write_data_done > cmd->se_cmd.data_length); in iscsit_handle_immediate_data()
2589 rx_size = min(cmd->se_cmd.data_length - cmd->write_data_done, length); in iscsit_handle_immediate_data()
2590 iov_ret = iscsit_map_iovec(cmd, cmd->iov_data, in iscsit_handle_immediate_data()
2591 cmd->orig_iov_data_count - 2, in iscsit_handle_immediate_data()
2592 cmd->write_data_done, rx_size); in iscsit_handle_immediate_data()
2597 iov = &cmd->iov_data[0]; in iscsit_handle_immediate_data()
2603 overflow_buf = kmalloc(length - rx_size, GFP_KERNEL); in iscsit_handle_immediate_data()
2608 cmd->overflow_buf = overflow_buf; in iscsit_handle_immediate_data()
2610 iov[iov_count].iov_len = length - rx_size; in iscsit_handle_immediate_data()
2615 padding = ((-length) & 3); in iscsit_handle_immediate_data()
2617 iov[iov_count].iov_base = cmd->pad_bytes; in iscsit_handle_immediate_data()
2622 if (conn->conn_ops->DataDigest) { in iscsit_handle_immediate_data()
2628 WARN_ON_ONCE(iov_count > cmd->orig_iov_data_count); in iscsit_handle_immediate_data()
2629 rx_got = rx_data(conn, &cmd->iov_data[0], iov_count, rx_size); in iscsit_handle_immediate_data()
2638 if (conn->conn_ops->DataDigest) { in iscsit_handle_immediate_data()
2642 cmd->pad_bytes); in iscsit_handle_immediate_data()
2648 if (!conn->sess->sess_ops->ErrorRecoveryLevel) { in iscsit_handle_immediate_data()
2669 cmd->write_data_done += length; in iscsit_handle_immediate_data()
2671 if (cmd->write_data_done == cmd->se_cmd.data_length) { in iscsit_handle_immediate_data()
2672 spin_lock_bh(&cmd->istate_lock); in iscsit_handle_immediate_data()
2673 cmd->cmd_flags |= ICF_GOT_LAST_DATAOUT; in iscsit_handle_immediate_data()
2674 cmd->i_state = ISTATE_RECEIVED_LAST_DATAOUT; in iscsit_handle_immediate_data()
2675 spin_unlock_bh(&cmd->istate_lock); in iscsit_handle_immediate_data()
2689 lockdep_assert_held(&conn->sess->conn_lock); in iscsit_build_conn_drop_async_message()
2695 list_for_each_entry(conn_p, &conn->sess->sess_conn_list, conn_list) { in iscsit_build_conn_drop_async_message()
2696 if (conn_p->conn_state == TARG_CONN_STATE_LOGGED_IN) { in iscsit_build_conn_drop_async_message()
2712 cmd->logout_cid = conn->cid; in iscsit_build_conn_drop_async_message()
2713 cmd->iscsi_opcode = ISCSI_OP_ASYNC_EVENT; in iscsit_build_conn_drop_async_message()
2714 cmd->i_state = ISTATE_SEND_ASYNCMSG; in iscsit_build_conn_drop_async_message()
2716 spin_lock_bh(&conn_p->cmd_lock); in iscsit_build_conn_drop_async_message()
2717 list_add_tail(&cmd->i_conn_node, &conn_p->conn_cmd_list); in iscsit_build_conn_drop_async_message()
2718 spin_unlock_bh(&conn_p->cmd_lock); in iscsit_build_conn_drop_async_message()
2720 iscsit_add_cmd_to_response_queue(cmd, conn_p, cmd->i_state); in iscsit_build_conn_drop_async_message()
2730 cmd->iscsi_opcode = ISCSI_OP_ASYNC_EVENT; in iscsit_send_conn_drop_async_message()
2732 hdr = (struct iscsi_async *) cmd->pdu; in iscsit_send_conn_drop_async_message()
2733 hdr->opcode = ISCSI_OP_ASYNC_EVENT; in iscsit_send_conn_drop_async_message()
2734 hdr->flags = ISCSI_FLAG_CMD_FINAL; in iscsit_send_conn_drop_async_message()
2735 cmd->init_task_tag = RESERVED_ITT; in iscsit_send_conn_drop_async_message()
2736 cmd->targ_xfer_tag = 0xFFFFFFFF; in iscsit_send_conn_drop_async_message()
2737 put_unaligned_be64(0xFFFFFFFFFFFFFFFFULL, &hdr->rsvd4[0]); in iscsit_send_conn_drop_async_message()
2738 cmd->stat_sn = conn->stat_sn++; in iscsit_send_conn_drop_async_message()
2739 hdr->statsn = cpu_to_be32(cmd->stat_sn); in iscsit_send_conn_drop_async_message()
2740 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_send_conn_drop_async_message()
2741 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_send_conn_drop_async_message()
2742 hdr->async_event = ISCSI_ASYNC_MSG_DROPPING_CONNECTION; in iscsit_send_conn_drop_async_message()
2743 hdr->param1 = cpu_to_be16(cmd->logout_cid); in iscsit_send_conn_drop_async_message()
2744 hdr->param2 = cpu_to_be16(conn->sess->sess_ops->DefaultTime2Wait); in iscsit_send_conn_drop_async_message()
2745 hdr->param3 = cpu_to_be16(conn->sess->sess_ops->DefaultTime2Retain); in iscsit_send_conn_drop_async_message()
2748 " 0x%08x, for CID: %hu on CID: %hu\n", cmd->stat_sn, in iscsit_send_conn_drop_async_message()
2749 cmd->logout_cid, conn->cid); in iscsit_send_conn_drop_async_message()
2751 return conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, NULL, 0); in iscsit_send_conn_drop_async_message()
2756 if ((conn->sock->sk->sk_shutdown & SEND_SHUTDOWN) || in iscsit_tx_thread_wait_for_tcp()
2757 (conn->sock->sk->sk_shutdown & RCV_SHUTDOWN)) { in iscsit_tx_thread_wait_for_tcp()
2759 &conn->tx_half_close_comp, in iscsit_tx_thread_wait_for_tcp()
2769 hdr->opcode = ISCSI_OP_SCSI_DATA_IN; in iscsit_build_datain_pdu()
2770 hdr->flags = datain->flags; in iscsit_build_datain_pdu()
2771 if (hdr->flags & ISCSI_FLAG_DATA_STATUS) { in iscsit_build_datain_pdu()
2772 if (cmd->se_cmd.se_cmd_flags & SCF_OVERFLOW_BIT) { in iscsit_build_datain_pdu()
2773 hdr->flags |= ISCSI_FLAG_DATA_OVERFLOW; in iscsit_build_datain_pdu()
2774 hdr->residual_count = cpu_to_be32(cmd->se_cmd.residual_count); in iscsit_build_datain_pdu()
2775 } else if (cmd->se_cmd.se_cmd_flags & SCF_UNDERFLOW_BIT) { in iscsit_build_datain_pdu()
2776 hdr->flags |= ISCSI_FLAG_DATA_UNDERFLOW; in iscsit_build_datain_pdu()
2777 hdr->residual_count = cpu_to_be32(cmd->se_cmd.residual_count); in iscsit_build_datain_pdu()
2780 hton24(hdr->dlength, datain->length); in iscsit_build_datain_pdu()
2781 if (hdr->flags & ISCSI_FLAG_DATA_ACK) in iscsit_build_datain_pdu()
2782 int_to_scsilun(cmd->se_cmd.orig_fe_lun, in iscsit_build_datain_pdu()
2783 (struct scsi_lun *)&hdr->lun); in iscsit_build_datain_pdu()
2785 put_unaligned_le64(0xFFFFFFFFFFFFFFFFULL, &hdr->lun); in iscsit_build_datain_pdu()
2787 hdr->itt = cmd->init_task_tag; in iscsit_build_datain_pdu()
2789 if (hdr->flags & ISCSI_FLAG_DATA_ACK) in iscsit_build_datain_pdu()
2790 hdr->ttt = cpu_to_be32(cmd->targ_xfer_tag); in iscsit_build_datain_pdu()
2792 hdr->ttt = cpu_to_be32(0xFFFFFFFF); in iscsit_build_datain_pdu()
2794 hdr->statsn = cpu_to_be32(cmd->stat_sn); in iscsit_build_datain_pdu()
2796 hdr->statsn = cpu_to_be32(0xFFFFFFFF); in iscsit_build_datain_pdu()
2798 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_build_datain_pdu()
2799 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_build_datain_pdu()
2800 hdr->datasn = cpu_to_be32(datain->data_sn); in iscsit_build_datain_pdu()
2801 hdr->offset = cpu_to_be32(datain->offset); in iscsit_build_datain_pdu()
2805 cmd->init_task_tag, ntohl(hdr->statsn), ntohl(hdr->datasn), in iscsit_build_datain_pdu()
2806 ntohl(hdr->offset), datain->length, conn->cid); in iscsit_build_datain_pdu()
2812 struct iscsi_data_rsp *hdr = (struct iscsi_data_rsp *)&cmd->pdu[0]; in iscsit_send_datain()
2822 cmd->init_task_tag); in iscsit_send_datain()
2823 return -1; in iscsit_send_datain()
2828 if ((datain.offset + datain.length) > cmd->se_cmd.data_length) { in iscsit_send_datain()
2830 " datain.length: %u exceeds cmd->data_length: %u\n", in iscsit_send_datain()
2831 cmd->init_task_tag, datain.offset, datain.length, in iscsit_send_datain()
2832 cmd->se_cmd.data_length); in iscsit_send_datain()
2833 return -1; in iscsit_send_datain()
2836 atomic_long_add(datain.length, &conn->sess->tx_data_octets); in iscsit_send_datain()
2842 (cmd->se_cmd.se_cmd_flags & SCF_TRANSPORT_TASK_SENSE)) in iscsit_send_datain()
2845 if ((dr->dr_complete == DATAIN_COMPLETE_NORMAL) || in iscsit_send_datain()
2846 (dr->dr_complete == DATAIN_COMPLETE_CONNECTION_RECOVERY)) { in iscsit_send_datain()
2847 iscsit_increment_maxcmdsn(cmd, conn->sess); in iscsit_send_datain()
2848 cmd->stat_sn = conn->stat_sn++; in iscsit_send_datain()
2850 } else if (dr->dr_complete == in iscsit_send_datain()
2857 ret = conn->conn_transport->iscsit_xmit_pdu(conn, cmd, dr, &datain, 0); in iscsit_send_datain()
2861 if (dr->dr_complete) { in iscsit_send_datain()
2862 eodr = (cmd->se_cmd.se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) ? in iscsit_send_datain()
2876 struct iscsit_session *sess = conn->sess; in iscsit_build_logout_rsp()
2882 switch (cmd->logout_reason) { in iscsit_build_logout_rsp()
2886 cmd->logout_response = ISCSI_LOGOUT_SUCCESS; in iscsit_build_logout_rsp()
2889 if (cmd->logout_response == ISCSI_LOGOUT_CID_NOT_FOUND) in iscsit_build_logout_rsp()
2893 * a matching logout CID -> local CID, the reference in iscsit_build_logout_rsp()
2899 * on, the connection responding to cmd->logout_cid in iscsit_build_logout_rsp()
2904 " successful.\n", cmd->logout_cid, conn->cid); in iscsit_build_logout_rsp()
2905 cmd->logout_response = ISCSI_LOGOUT_SUCCESS; in iscsit_build_logout_rsp()
2908 if ((cmd->logout_response == ISCSI_LOGOUT_RECOVERY_UNSUPPORTED) || in iscsit_build_logout_rsp()
2909 (cmd->logout_response == ISCSI_LOGOUT_CLEANUP_FAILED)) in iscsit_build_logout_rsp()
2916 cmd->logout_cid); in iscsit_build_logout_rsp()
2923 conn->sess, cmd->logout_cid); in iscsit_build_logout_rsp()
2927 cmd->logout_cid); in iscsit_build_logout_rsp()
2928 cmd->logout_response = ISCSI_LOGOUT_CID_NOT_FOUND; in iscsit_build_logout_rsp()
2932 iscsit_discard_cr_cmds_by_expstatsn(cr, cmd->exp_stat_sn); in iscsit_build_logout_rsp()
2936 cmd->logout_cid, conn->cid); in iscsit_build_logout_rsp()
2937 cmd->logout_response = ISCSI_LOGOUT_SUCCESS; in iscsit_build_logout_rsp()
2940 pr_err("Unknown cmd->logout_reason: 0x%02x\n", in iscsit_build_logout_rsp()
2941 cmd->logout_reason); in iscsit_build_logout_rsp()
2942 return -1; in iscsit_build_logout_rsp()
2945 hdr->opcode = ISCSI_OP_LOGOUT_RSP; in iscsit_build_logout_rsp()
2946 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsit_build_logout_rsp()
2947 hdr->response = cmd->logout_response; in iscsit_build_logout_rsp()
2948 hdr->itt = cmd->init_task_tag; in iscsit_build_logout_rsp()
2949 cmd->stat_sn = conn->stat_sn++; in iscsit_build_logout_rsp()
2950 hdr->statsn = cpu_to_be32(cmd->stat_sn); in iscsit_build_logout_rsp()
2952 iscsit_increment_maxcmdsn(cmd, conn->sess); in iscsit_build_logout_rsp()
2953 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_build_logout_rsp()
2954 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_build_logout_rsp()
2958 cmd->init_task_tag, cmd->stat_sn, hdr->response, in iscsit_build_logout_rsp()
2959 cmd->logout_cid, conn->cid); in iscsit_build_logout_rsp()
2971 (struct iscsi_logout_rsp *)&cmd->pdu[0]); in iscsit_send_logout()
2975 return conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, NULL, 0); in iscsit_send_logout()
2982 hdr->opcode = ISCSI_OP_NOOP_IN; in iscsit_build_nopin_rsp()
2983 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsit_build_nopin_rsp()
2984 hton24(hdr->dlength, cmd->buf_ptr_size); in iscsit_build_nopin_rsp()
2986 put_unaligned_le64(0xFFFFFFFFFFFFFFFFULL, &hdr->lun); in iscsit_build_nopin_rsp()
2987 hdr->itt = cmd->init_task_tag; in iscsit_build_nopin_rsp()
2988 hdr->ttt = cpu_to_be32(cmd->targ_xfer_tag); in iscsit_build_nopin_rsp()
2989 cmd->stat_sn = (nopout_response) ? conn->stat_sn++ : in iscsit_build_nopin_rsp()
2990 conn->stat_sn; in iscsit_build_nopin_rsp()
2991 hdr->statsn = cpu_to_be32(cmd->stat_sn); in iscsit_build_nopin_rsp()
2994 iscsit_increment_maxcmdsn(cmd, conn->sess); in iscsit_build_nopin_rsp()
2996 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_build_nopin_rsp()
2997 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_build_nopin_rsp()
3001 "Solicited" : "Unsolicited", cmd->init_task_tag, in iscsit_build_nopin_rsp()
3002 cmd->targ_xfer_tag, cmd->stat_sn, cmd->buf_ptr_size); in iscsit_build_nopin_rsp()
3014 struct iscsi_nopin *hdr = (struct iscsi_nopin *)&cmd->pdu[0]; in iscsit_send_unsolicited_nopin()
3020 " 0x%08x CID: %hu\n", hdr->ttt, cmd->stat_sn, conn->cid); in iscsit_send_unsolicited_nopin()
3022 ret = conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, NULL, 0); in iscsit_send_unsolicited_nopin()
3026 spin_lock_bh(&cmd->istate_lock); in iscsit_send_unsolicited_nopin()
3027 cmd->i_state = want_response ? in iscsit_send_unsolicited_nopin()
3029 spin_unlock_bh(&cmd->istate_lock); in iscsit_send_unsolicited_nopin()
3037 struct iscsi_nopin *hdr = (struct iscsi_nopin *)&cmd->pdu[0]; in iscsit_send_nopin()
3042 * NOPOUT Ping Data is attached to struct iscsit_cmd->buf_ptr. in iscsit_send_nopin()
3043 * NOPOUT DataSegmentLength is at struct iscsit_cmd->buf_ptr_size. in iscsit_send_nopin()
3045 pr_debug("Echoing back %u bytes of ping data.\n", cmd->buf_ptr_size); in iscsit_send_nopin()
3047 return conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, in iscsit_send_nopin()
3048 cmd->buf_ptr, in iscsit_send_nopin()
3049 cmd->buf_ptr_size); in iscsit_send_nopin()
3062 return -1; in iscsit_send_r2t()
3064 hdr = (struct iscsi_r2t_rsp *) cmd->pdu; in iscsit_send_r2t()
3066 hdr->opcode = ISCSI_OP_R2T; in iscsit_send_r2t()
3067 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsit_send_r2t()
3068 int_to_scsilun(cmd->se_cmd.orig_fe_lun, in iscsit_send_r2t()
3069 (struct scsi_lun *)&hdr->lun); in iscsit_send_r2t()
3070 hdr->itt = cmd->init_task_tag; in iscsit_send_r2t()
3071 if (conn->conn_transport->iscsit_get_r2t_ttt) in iscsit_send_r2t()
3072 conn->conn_transport->iscsit_get_r2t_ttt(conn, cmd, r2t); in iscsit_send_r2t()
3074 r2t->targ_xfer_tag = session_get_next_ttt(conn->sess); in iscsit_send_r2t()
3075 hdr->ttt = cpu_to_be32(r2t->targ_xfer_tag); in iscsit_send_r2t()
3076 hdr->statsn = cpu_to_be32(conn->stat_sn); in iscsit_send_r2t()
3077 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_send_r2t()
3078 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_send_r2t()
3079 hdr->r2tsn = cpu_to_be32(r2t->r2t_sn); in iscsit_send_r2t()
3080 hdr->data_offset = cpu_to_be32(r2t->offset); in iscsit_send_r2t()
3081 hdr->data_length = cpu_to_be32(r2t->xfer_len); in iscsit_send_r2t()
3085 (!r2t->recovery_r2t) ? "" : "Recovery ", cmd->init_task_tag, in iscsit_send_r2t()
3086 r2t->targ_xfer_tag, ntohl(hdr->statsn), r2t->r2t_sn, in iscsit_send_r2t()
3087 r2t->offset, r2t->xfer_len, conn->cid); in iscsit_send_r2t()
3089 spin_lock_bh(&cmd->r2t_lock); in iscsit_send_r2t()
3090 r2t->sent_r2t = 1; in iscsit_send_r2t()
3091 spin_unlock_bh(&cmd->r2t_lock); in iscsit_send_r2t()
3093 ret = conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, NULL, 0); in iscsit_send_r2t()
3098 spin_lock_bh(&cmd->dataout_timeout_lock); in iscsit_send_r2t()
3100 spin_unlock_bh(&cmd->dataout_timeout_lock); in iscsit_send_r2t()
3117 spin_lock_bh(&cmd->r2t_lock); in iscsit_build_r2ts_for_cmd()
3118 if (cmd->cmd_flags & ICF_SENT_LAST_R2T) { in iscsit_build_r2ts_for_cmd()
3119 spin_unlock_bh(&cmd->r2t_lock); in iscsit_build_r2ts_for_cmd()
3123 if (conn->sess->sess_ops->DataSequenceInOrder && in iscsit_build_r2ts_for_cmd()
3125 cmd->r2t_offset = max(cmd->r2t_offset, cmd->write_data_done); in iscsit_build_r2ts_for_cmd()
3127 while (cmd->outstanding_r2ts < conn->sess->sess_ops->MaxOutstandingR2T) { in iscsit_build_r2ts_for_cmd()
3128 if (conn->sess->sess_ops->DataSequenceInOrder) { in iscsit_build_r2ts_for_cmd()
3129 offset = cmd->r2t_offset; in iscsit_build_r2ts_for_cmd()
3133 conn->sess->sess_ops->MaxBurstLength - in iscsit_build_r2ts_for_cmd()
3134 cmd->next_burst_len; in iscsit_build_r2ts_for_cmd()
3136 if (new_data_end > cmd->se_cmd.data_length) in iscsit_build_r2ts_for_cmd()
3137 xfer_len = cmd->se_cmd.data_length - offset; in iscsit_build_r2ts_for_cmd()
3140 conn->sess->sess_ops->MaxBurstLength - in iscsit_build_r2ts_for_cmd()
3141 cmd->next_burst_len; in iscsit_build_r2ts_for_cmd()
3144 conn->sess->sess_ops->MaxBurstLength; in iscsit_build_r2ts_for_cmd()
3146 if (new_data_end > cmd->se_cmd.data_length) in iscsit_build_r2ts_for_cmd()
3147 xfer_len = cmd->se_cmd.data_length - offset; in iscsit_build_r2ts_for_cmd()
3149 xfer_len = conn->sess->sess_ops->MaxBurstLength; in iscsit_build_r2ts_for_cmd()
3153 cmd->cmd_flags |= ICF_SENT_LAST_R2T; in iscsit_build_r2ts_for_cmd()
3157 cmd->r2t_offset += xfer_len; in iscsit_build_r2ts_for_cmd()
3159 if (cmd->r2t_offset == cmd->se_cmd.data_length) in iscsit_build_r2ts_for_cmd()
3160 cmd->cmd_flags |= ICF_SENT_LAST_R2T; in iscsit_build_r2ts_for_cmd()
3166 spin_unlock_bh(&cmd->r2t_lock); in iscsit_build_r2ts_for_cmd()
3167 return -1; in iscsit_build_r2ts_for_cmd()
3170 offset = seq->offset; in iscsit_build_r2ts_for_cmd()
3171 xfer_len = seq->xfer_len; in iscsit_build_r2ts_for_cmd()
3173 if (cmd->seq_send_order == cmd->seq_count) in iscsit_build_r2ts_for_cmd()
3174 cmd->cmd_flags |= ICF_SENT_LAST_R2T; in iscsit_build_r2ts_for_cmd()
3176 cmd->outstanding_r2ts++; in iscsit_build_r2ts_for_cmd()
3180 spin_unlock_bh(&cmd->r2t_lock); in iscsit_build_r2ts_for_cmd()
3181 return -1; in iscsit_build_r2ts_for_cmd()
3184 if (cmd->cmd_flags & ICF_SENT_LAST_R2T) in iscsit_build_r2ts_for_cmd()
3187 spin_unlock_bh(&cmd->r2t_lock); in iscsit_build_r2ts_for_cmd()
3197 cmd->stat_sn = conn->stat_sn++; in iscsit_build_rsp_pdu()
3199 atomic_long_inc(&conn->sess->rsp_pdus); in iscsit_build_rsp_pdu()
3202 hdr->opcode = ISCSI_OP_SCSI_CMD_RSP; in iscsit_build_rsp_pdu()
3203 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsit_build_rsp_pdu()
3204 if (cmd->se_cmd.se_cmd_flags & SCF_OVERFLOW_BIT) { in iscsit_build_rsp_pdu()
3205 hdr->flags |= ISCSI_FLAG_CMD_OVERFLOW; in iscsit_build_rsp_pdu()
3206 hdr->residual_count = cpu_to_be32(cmd->se_cmd.residual_count); in iscsit_build_rsp_pdu()
3207 } else if (cmd->se_cmd.se_cmd_flags & SCF_UNDERFLOW_BIT) { in iscsit_build_rsp_pdu()
3208 hdr->flags |= ISCSI_FLAG_CMD_UNDERFLOW; in iscsit_build_rsp_pdu()
3209 hdr->residual_count = cpu_to_be32(cmd->se_cmd.residual_count); in iscsit_build_rsp_pdu()
3211 hdr->response = cmd->iscsi_response; in iscsit_build_rsp_pdu()
3212 hdr->cmd_status = cmd->se_cmd.scsi_status; in iscsit_build_rsp_pdu()
3213 hdr->itt = cmd->init_task_tag; in iscsit_build_rsp_pdu()
3214 hdr->statsn = cpu_to_be32(cmd->stat_sn); in iscsit_build_rsp_pdu()
3216 iscsit_increment_maxcmdsn(cmd, conn->sess); in iscsit_build_rsp_pdu()
3217 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_build_rsp_pdu()
3218 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_build_rsp_pdu()
3222 cmd->init_task_tag, cmd->stat_sn, cmd->se_cmd.scsi_status, in iscsit_build_rsp_pdu()
3223 cmd->se_cmd.scsi_status, conn->cid); in iscsit_build_rsp_pdu()
3229 struct iscsi_scsi_rsp *hdr = (struct iscsi_scsi_rsp *)&cmd->pdu[0]; in iscsit_send_response()
3230 bool inc_stat_sn = (cmd->i_state == ISTATE_SEND_STATUS); in iscsit_send_response()
3239 if (cmd->se_cmd.sense_buffer && in iscsit_send_response()
3240 ((cmd->se_cmd.se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) || in iscsit_send_response()
3241 (cmd->se_cmd.se_cmd_flags & SCF_EMULATED_TASK_SENSE))) { in iscsit_send_response()
3242 put_unaligned_be16(cmd->se_cmd.scsi_sense_length, cmd->sense_buffer); in iscsit_send_response()
3243 cmd->se_cmd.scsi_sense_length += sizeof (__be16); in iscsit_send_response()
3245 padding = -(cmd->se_cmd.scsi_sense_length) & 3; in iscsit_send_response()
3246 hton24(hdr->dlength, (u32)cmd->se_cmd.scsi_sense_length); in iscsit_send_response()
3247 data_buf = cmd->sense_buffer; in iscsit_send_response()
3248 data_buf_len = cmd->se_cmd.scsi_sense_length + padding; in iscsit_send_response()
3251 memset(cmd->sense_buffer + in iscsit_send_response()
3252 cmd->se_cmd.scsi_sense_length, 0, padding); in iscsit_send_response()
3259 cmd->se_cmd.scsi_sense_length); in iscsit_send_response()
3262 return conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, data_buf, in iscsit_send_response()
3268 switch (se_tmr->response) { in iscsit_convert_tcm_tmr_rsp()
3287 struct se_tmr_req *se_tmr = cmd->se_cmd.se_tmr_req; in iscsit_build_task_mgt_rsp()
3289 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP; in iscsit_build_task_mgt_rsp()
3290 hdr->flags = ISCSI_FLAG_CMD_FINAL; in iscsit_build_task_mgt_rsp()
3291 hdr->response = iscsit_convert_tcm_tmr_rsp(se_tmr); in iscsit_build_task_mgt_rsp()
3292 hdr->itt = cmd->init_task_tag; in iscsit_build_task_mgt_rsp()
3293 cmd->stat_sn = conn->stat_sn++; in iscsit_build_task_mgt_rsp()
3294 hdr->statsn = cpu_to_be32(cmd->stat_sn); in iscsit_build_task_mgt_rsp()
3296 iscsit_increment_maxcmdsn(cmd, conn->sess); in iscsit_build_task_mgt_rsp()
3297 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_build_task_mgt_rsp()
3298 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_build_task_mgt_rsp()
3302 cmd->init_task_tag, cmd->stat_sn, hdr->response, conn->cid); in iscsit_build_task_mgt_rsp()
3309 struct iscsi_tm_rsp *hdr = (struct iscsi_tm_rsp *)&cmd->pdu[0]; in iscsit_send_task_mgt_rsp()
3313 return conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, NULL, 0); in iscsit_send_task_mgt_rsp()
3324 struct iscsit_conn *conn = cmd->conn; in iscsit_build_sendtargets_response()
3331 unsigned char *text_in = cmd->text_in_ptr, *text_ptr = NULL; in iscsit_build_sendtargets_response()
3334 buffer_len = min(conn->conn_ops->MaxRecvDataSegmentLength, in iscsit_build_sendtargets_response()
3339 return -ENOMEM; in iscsit_build_sendtargets_response()
3345 if (cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) { in iscsit_build_sendtargets_response()
3351 return -EINVAL; in iscsit_build_sendtargets_response()
3361 if ((cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) && in iscsit_build_sendtargets_response()
3362 strcmp(tiqn->tiqn, text_ptr)) { in iscsit_build_sendtargets_response()
3368 spin_lock(&tiqn->tiqn_tpg_lock); in iscsit_build_sendtargets_response()
3369 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) { in iscsit_build_sendtargets_response()
3376 if ((tpg->tpg_attrib.generate_node_acls == 0) && in iscsit_build_sendtargets_response()
3377 (tpg->tpg_attrib.demo_mode_discovery == 0) && in iscsit_build_sendtargets_response()
3378 (!target_tpg_has_node_acl(&tpg->tpg_se_tpg, in iscsit_build_sendtargets_response()
3379 cmd->conn->sess->sess_ops->InitiatorName))) { in iscsit_build_sendtargets_response()
3383 spin_lock(&tpg->tpg_state_lock); in iscsit_build_sendtargets_response()
3384 active = (tpg->tpg_state == TPG_STATE_ACTIVE); in iscsit_build_sendtargets_response()
3385 spin_unlock(&tpg->tpg_state_lock); in iscsit_build_sendtargets_response()
3387 if (!active && tpg->tpg_attrib.tpg_enabled_sendtargets) in iscsit_build_sendtargets_response()
3390 spin_lock(&tpg->tpg_np_lock); in iscsit_build_sendtargets_response()
3391 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, in iscsit_build_sendtargets_response()
3393 struct iscsi_np *np = tpg_np->tpg_np; in iscsit_build_sendtargets_response()
3396 if (np->np_network_transport != network_transport) in iscsit_build_sendtargets_response()
3401 tiqn->tiqn); in iscsit_build_sendtargets_response()
3405 spin_unlock(&tpg->tpg_np_lock); in iscsit_build_sendtargets_response()
3406 spin_unlock(&tiqn->tiqn_tpg_lock); in iscsit_build_sendtargets_response()
3412 skip_bytes -= len; in iscsit_build_sendtargets_response()
3422 if (inet_addr_is_any((struct sockaddr *)&np->np_sockaddr)) in iscsit_build_sendtargets_response()
3423 sockaddr = &conn->local_sockaddr; in iscsit_build_sendtargets_response()
3425 sockaddr = &np->np_sockaddr; in iscsit_build_sendtargets_response()
3430 tpg->tpgt); in iscsit_build_sendtargets_response()
3434 spin_unlock(&tpg->tpg_np_lock); in iscsit_build_sendtargets_response()
3435 spin_unlock(&tiqn->tiqn_tpg_lock); in iscsit_build_sendtargets_response()
3441 skip_bytes -= len; in iscsit_build_sendtargets_response()
3449 spin_unlock(&tpg->tpg_np_lock); in iscsit_build_sendtargets_response()
3451 spin_unlock(&tiqn->tiqn_tpg_lock); in iscsit_build_sendtargets_response()
3458 if (cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) in iscsit_build_sendtargets_response()
3463 cmd->buf_ptr = payload; in iscsit_build_sendtargets_response()
3477 cmd->read_data_done, in iscsit_build_text_rsp()
3483 hdr->flags = ISCSI_FLAG_CMD_FINAL; in iscsit_build_text_rsp()
3485 hdr->flags = ISCSI_FLAG_TEXT_CONTINUE; in iscsit_build_text_rsp()
3486 cmd->read_data_done += text_length; in iscsit_build_text_rsp()
3487 if (cmd->targ_xfer_tag == 0xFFFFFFFF) in iscsit_build_text_rsp()
3488 cmd->targ_xfer_tag = session_get_next_ttt(conn->sess); in iscsit_build_text_rsp()
3490 hdr->opcode = ISCSI_OP_TEXT_RSP; in iscsit_build_text_rsp()
3491 padding = ((-text_length) & 3); in iscsit_build_text_rsp()
3492 hton24(hdr->dlength, text_length); in iscsit_build_text_rsp()
3493 hdr->itt = cmd->init_task_tag; in iscsit_build_text_rsp()
3494 hdr->ttt = cpu_to_be32(cmd->targ_xfer_tag); in iscsit_build_text_rsp()
3495 cmd->stat_sn = conn->stat_sn++; in iscsit_build_text_rsp()
3496 hdr->statsn = cpu_to_be32(cmd->stat_sn); in iscsit_build_text_rsp()
3498 iscsit_increment_maxcmdsn(cmd, conn->sess); in iscsit_build_text_rsp()
3500 * Reset maxcmdsn_inc in multi-part text payload exchanges to in iscsit_build_text_rsp()
3504 cmd->maxcmdsn_inc = 0; in iscsit_build_text_rsp()
3505 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_build_text_rsp()
3506 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_build_text_rsp()
3509 " Length: %u, CID: %hu F: %d C: %d\n", cmd->init_task_tag, in iscsit_build_text_rsp()
3510 cmd->targ_xfer_tag, cmd->stat_sn, text_length, conn->cid, in iscsit_build_text_rsp()
3511 !!(hdr->flags & ISCSI_FLAG_CMD_FINAL), in iscsit_build_text_rsp()
3512 !!(hdr->flags & ISCSI_FLAG_TEXT_CONTINUE)); in iscsit_build_text_rsp()
3522 struct iscsi_text_rsp *hdr = (struct iscsi_text_rsp *)cmd->pdu; in iscsit_send_text_rsp()
3526 conn->conn_transport->transport_type); in iscsit_send_text_rsp()
3530 return conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, in iscsit_send_text_rsp()
3531 cmd->buf_ptr, in iscsit_send_text_rsp()
3539 hdr->opcode = ISCSI_OP_REJECT; in iscsit_build_reject()
3540 hdr->reason = cmd->reject_reason; in iscsit_build_reject()
3541 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsit_build_reject()
3542 hton24(hdr->dlength, ISCSI_HDR_LEN); in iscsit_build_reject()
3543 hdr->ffffffff = cpu_to_be32(0xffffffff); in iscsit_build_reject()
3544 cmd->stat_sn = conn->stat_sn++; in iscsit_build_reject()
3545 hdr->statsn = cpu_to_be32(cmd->stat_sn); in iscsit_build_reject()
3546 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); in iscsit_build_reject()
3547 hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); in iscsit_build_reject()
3556 struct iscsi_reject *hdr = (struct iscsi_reject *)&cmd->pdu[0]; in iscsit_send_reject()
3561 " CID: %hu\n", ntohl(hdr->statsn), hdr->reason, conn->cid); in iscsit_send_reject()
3563 return conn->conn_transport->iscsit_xmit_pdu(conn, cmd, NULL, in iscsit_send_reject()
3564 cmd->buf_ptr, in iscsit_send_reject()
3574 * bitmap_id is assigned from iscsit_global->ts_bitmap from in iscsit_thread_get_cpumask()
3582 ord = conn->bitmap_id % cpumask_weight(cpu_online_mask); in iscsit_thread_get_cpumask()
3584 if (ord-- == 0) { in iscsit_thread_get_cpumask()
3585 cpumask_set_cpu(cpu, conn->conn_cpumask); in iscsit_thread_get_cpumask()
3590 cpumask_and(conn_allowed_cpumask, iscsit_global->allowed_cpumask, in iscsit_thread_get_cpumask()
3593 cpumask_clear(conn->conn_cpumask); in iscsit_thread_get_cpumask()
3594 ord = conn->bitmap_id % cpumask_weight(conn_allowed_cpumask); in iscsit_thread_get_cpumask()
3596 if (ord-- == 0) { in iscsit_thread_get_cpumask()
3597 cpumask_set_cpu(cpu, conn->conn_cpumask); in iscsit_thread_get_cpumask()
3608 cpumask_setall(conn->conn_cpumask); in iscsit_thread_get_cpumask()
3614 * If iscsit_global->allowed_cpumask modified, reschedule iSCSI in iscsit_thread_reschedule()
3615 * connection's RX/TX threads update conn->allowed_cpumask. in iscsit_thread_reschedule()
3617 if (!cpumask_equal(iscsit_global->allowed_cpumask, in iscsit_thread_reschedule()
3618 conn->allowed_cpumask)) { in iscsit_thread_reschedule()
3620 conn->conn_tx_reset_cpumask = 1; in iscsit_thread_reschedule()
3621 conn->conn_rx_reset_cpumask = 1; in iscsit_thread_reschedule()
3622 cpumask_copy(conn->allowed_cpumask, in iscsit_thread_reschedule()
3623 iscsit_global->allowed_cpumask); in iscsit_thread_reschedule()
3647 if (!conn->conn_tx_reset_cpumask) in iscsit_thread_check_cpumask()
3650 if (!conn->conn_rx_reset_cpumask) in iscsit_thread_check_cpumask()
3659 set_cpus_allowed_ptr(p, conn->conn_cpumask); in iscsit_thread_check_cpumask()
3661 conn->conn_tx_reset_cpumask = 0; in iscsit_thread_check_cpumask()
3663 conn->conn_rx_reset_cpumask = 0; in iscsit_thread_check_cpumask()
3679 spin_lock_bh(&conn->cmd_lock); in iscsit_immediate_queue()
3680 list_del_init(&cmd->i_conn_node); in iscsit_immediate_queue()
3681 spin_unlock_bh(&conn->cmd_lock); in iscsit_immediate_queue()
3699 cmd->iscsi_opcode, cmd->init_task_tag, state, in iscsit_immediate_queue()
3700 conn->cid); in iscsit_immediate_queue()
3707 return -1; in iscsit_immediate_queue()
3714 struct iscsit_transport *t = conn->conn_transport; in iscsit_handle_immediate_queue()
3721 atomic_set(&conn->check_immediate_queue, 0); in iscsit_handle_immediate_queue()
3722 cmd = qr->cmd; in iscsit_handle_immediate_queue()
3723 state = qr->state; in iscsit_handle_immediate_queue()
3726 ret = t->iscsit_immediate_queue(conn, cmd, state); in iscsit_handle_immediate_queue()
3750 spin_lock_bh(&cmd->istate_lock); in iscsit_response_queue()
3751 cmd->i_state = ISTATE_SENT_STATUS; in iscsit_response_queue()
3752 spin_unlock_bh(&cmd->istate_lock); in iscsit_response_queue()
3754 if (atomic_read(&conn->check_immediate_queue)) in iscsit_response_queue()
3761 spin_lock_bh(&cmd->istate_lock); in iscsit_response_queue()
3762 cmd->i_state = ISTATE_SEND_STATUS; in iscsit_response_queue()
3763 spin_unlock_bh(&cmd->istate_lock); in iscsit_response_queue()
3792 iscsit_fall_back_to_erl0(conn->sess); in iscsit_response_queue()
3800 cmd->iscsi_opcode, cmd->init_task_tag, in iscsit_response_queue()
3801 state, conn->cid); in iscsit_response_queue()
3810 return -ECONNRESET; in iscsit_response_queue()
3819 spin_lock_bh(&cmd->istate_lock); in iscsit_response_queue()
3820 cmd->i_state = ISTATE_SENT_STATUS; in iscsit_response_queue()
3821 spin_unlock_bh(&cmd->istate_lock); in iscsit_response_queue()
3826 cmd->iscsi_opcode, cmd->init_task_tag, in iscsit_response_queue()
3827 cmd->i_state, conn->cid); in iscsit_response_queue()
3831 if (atomic_read(&conn->check_immediate_queue)) in iscsit_response_queue()
3837 return -1; in iscsit_response_queue()
3843 struct iscsit_transport *t = conn->conn_transport; in iscsit_handle_response_queue()
3850 cmd = qr->cmd; in iscsit_handle_response_queue()
3851 state = qr->state; in iscsit_handle_response_queue()
3854 ret = t->iscsit_response_queue(conn, cmd, state); in iscsit_handle_response_queue()
3881 wait_event_interruptible(conn->queues_wq, in iscsi_target_tx_thread()
3895 } else if (ret == -ECONNRESET) { in iscsi_target_tx_thread()
3905 * Avoid the normal connection failure code-path if this connection in iscsi_target_tx_thread()
3909 if (conn->conn_state != TARG_CONN_STATE_IN_LOGIN) in iscsi_target_tx_thread()
3926 switch (hdr->opcode & ISCSI_OPCODE_MASK) { in iscsi_target_rx_opcode()
3939 if (hdr->ttt == cpu_to_be32(0xFFFFFFFF)) { in iscsi_target_rx_opcode()
3954 if (hdr->ttt != cpu_to_be32(0xFFFFFFFF)) { in iscsi_target_rx_opcode()
3955 cmd = iscsit_find_cmd_from_itt(conn, hdr->itt); in iscsi_target_rx_opcode()
3973 wait_for_completion_timeout(&conn->conn_logout_comp, in iscsi_target_rx_opcode()
3980 pr_err("Got unknown iSCSI OpCode: 0x%02x\n", hdr->opcode); in iscsi_target_rx_opcode()
3981 if (!conn->sess->sess_ops->ErrorRecoveryLevel) { in iscsi_target_rx_opcode()
3984 return -1; in iscsi_target_rx_opcode()
3988 ret = -1; in iscsi_target_rx_opcode()
4001 spin_lock_bh(&conn->state_lock); in iscsi_target_check_conn_state()
4002 ret = (conn->conn_state != TARG_CONN_STATE_LOGGED_IN); in iscsi_target_check_conn_state()
4003 spin_unlock_bh(&conn->state_lock); in iscsi_target_check_conn_state()
4039 if (hdr->hlength) { in iscsit_get_rx_pdu()
4040 iov.iov_len = hdr->hlength * 4; in iscsit_get_rx_pdu()
4057 if (conn->conn_ops->HeaderDigest) { in iscsit_get_rx_pdu()
4078 atomic_long_inc(&conn->sess->conn_digest_errors); in iscsit_get_rx_pdu()
4085 if (conn->conn_state == TARG_CONN_STATE_IN_LOGOUT) in iscsit_get_rx_pdu()
4090 if (conn->sess->sess_ops->SessionType && in iscsit_get_rx_pdu()
4123 rc = wait_for_completion_interruptible(&conn->rx_login_comp); in iscsi_target_rx_thread()
4127 if (!conn->conn_transport->iscsit_get_rx_pdu) in iscsi_target_rx_thread()
4130 conn->conn_transport->iscsit_get_rx_pdu(conn); in iscsi_target_rx_thread()
4133 atomic_set(&conn->transport_failed, 1); in iscsi_target_rx_thread()
4150 struct iscsit_session *sess = conn->sess; in iscsit_release_commands_from_conn()
4154 * has been reset -> returned sleeping pre-handler state. in iscsit_release_commands_from_conn()
4156 spin_lock_bh(&conn->cmd_lock); in iscsit_release_commands_from_conn()
4157 list_splice_init(&conn->conn_cmd_list, &tmp_list); in iscsit_release_commands_from_conn()
4160 struct se_cmd *se_cmd = &cmd->se_cmd; in iscsit_release_commands_from_conn()
4162 if (!se_cmd->se_tfo) in iscsit_release_commands_from_conn()
4165 spin_lock_irq(&se_cmd->t_state_lock); in iscsit_release_commands_from_conn()
4166 if (se_cmd->transport_state & CMD_T_ABORTED) { in iscsit_release_commands_from_conn()
4167 if (!(se_cmd->transport_state & CMD_T_TAS)) in iscsit_release_commands_from_conn()
4173 list_move_tail(&cmd->i_conn_node, in iscsit_release_commands_from_conn()
4174 &conn->conn_cmd_list); in iscsit_release_commands_from_conn()
4176 se_cmd->transport_state |= CMD_T_FABRIC_STOP; in iscsit_release_commands_from_conn()
4179 if (cmd->se_cmd.t_state == TRANSPORT_WRITE_PENDING) { in iscsit_release_commands_from_conn()
4184 spin_unlock_irq(&se_cmd->t_state_lock); in iscsit_release_commands_from_conn()
4185 target_complete_cmd(&cmd->se_cmd, SAM_STAT_TASK_ABORTED); in iscsit_release_commands_from_conn()
4188 spin_unlock_irq(&se_cmd->t_state_lock); in iscsit_release_commands_from_conn()
4190 spin_unlock_bh(&conn->cmd_lock); in iscsit_release_commands_from_conn()
4193 list_del_init(&cmd->i_conn_node); in iscsit_release_commands_from_conn()
4205 if (!conn->conn_transport->iscsit_wait_conn) { in iscsit_release_commands_from_conn()
4206 target_stop_cmd_counter(conn->cmd_cnt); in iscsit_release_commands_from_conn()
4207 target_wait_for_cmds(conn->cmd_cnt); in iscsit_release_commands_from_conn()
4216 spin_lock_bh(&conn->cmd_lock); in iscsit_stop_timers_for_cmds()
4217 list_for_each_entry(cmd, &conn->conn_cmd_list, i_conn_node) { in iscsit_stop_timers_for_cmds()
4218 if (cmd->data_direction == DMA_TO_DEVICE) in iscsit_stop_timers_for_cmds()
4221 spin_unlock_bh(&conn->cmd_lock); in iscsit_stop_timers_for_cmds()
4227 int conn_logout = (conn->conn_state == TARG_CONN_STATE_IN_LOGOUT); in iscsit_close_connection()
4228 struct iscsit_session *sess = conn->sess; in iscsit_close_connection()
4231 " %u\n", conn->cid, sess->sid); in iscsit_close_connection()
4238 * However for iser-target, isert_wait4logout() is using conn_logout_comp in iscsit_close_connection()
4241 * and to avoid iscsit_conn pointer dereference in iser-target code. in iscsit_close_connection()
4243 if (!conn->conn_transport->rdma_shutdown) in iscsit_close_connection()
4244 complete(&conn->conn_logout_comp); in iscsit_close_connection()
4246 if (!strcmp(current->comm, ISCSI_RX_THREAD_NAME)) { in iscsit_close_connection()
4247 if (conn->tx_thread && in iscsit_close_connection()
4248 cmpxchg(&conn->tx_thread_active, true, false)) { in iscsit_close_connection()
4249 send_sig(SIGINT, conn->tx_thread, 1); in iscsit_close_connection()
4250 kthread_stop(conn->tx_thread); in iscsit_close_connection()
4252 } else if (!strcmp(current->comm, ISCSI_TX_THREAD_NAME)) { in iscsit_close_connection()
4253 if (conn->rx_thread && in iscsit_close_connection()
4254 cmpxchg(&conn->rx_thread_active, true, false)) { in iscsit_close_connection()
4255 send_sig(SIGINT, conn->rx_thread, 1); in iscsit_close_connection()
4256 kthread_stop(conn->rx_thread); in iscsit_close_connection()
4260 spin_lock(&iscsit_global->ts_bitmap_lock); in iscsit_close_connection()
4261 bitmap_release_region(iscsit_global->ts_bitmap, conn->bitmap_id, in iscsit_close_connection()
4263 spin_unlock(&iscsit_global->ts_bitmap_lock); in iscsit_close_connection()
4269 if (conn->conn_transport->iscsit_wait_conn) in iscsit_close_connection()
4270 conn->conn_transport->iscsit_wait_conn(conn); in iscsit_close_connection()
4281 if (atomic_read(&conn->connection_recovery)) { in iscsit_close_connection()
4295 if (atomic_read(&conn->conn_logout_remove)) { in iscsit_close_connection()
4296 if (conn->conn_logout_reason == ISCSI_LOGOUT_REASON_CLOSE_SESSION) { in iscsit_close_connection()
4300 if (conn->conn_logout_reason == ISCSI_LOGOUT_REASON_CLOSE_CONNECTION) in iscsit_close_connection()
4303 atomic_set(&conn->conn_logout_remove, 0); in iscsit_close_connection()
4304 atomic_set(&sess->session_reinstatement, 0); in iscsit_close_connection()
4305 atomic_set(&sess->session_fall_back_to_erl0, 1); in iscsit_close_connection()
4308 spin_lock_bh(&sess->conn_lock); in iscsit_close_connection()
4309 list_del(&conn->conn_list); in iscsit_close_connection()
4316 if (atomic_read(&conn->connection_recovery)) in iscsit_close_connection()
4319 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4326 spin_lock_bh(&conn->state_lock); in iscsit_close_connection()
4327 if (atomic_read(&conn->sleep_on_conn_wait_comp)) { in iscsit_close_connection()
4328 spin_unlock_bh(&conn->state_lock); in iscsit_close_connection()
4329 complete(&conn->conn_wait_comp); in iscsit_close_connection()
4330 wait_for_completion(&conn->conn_post_wait_comp); in iscsit_close_connection()
4331 spin_lock_bh(&conn->state_lock); in iscsit_close_connection()
4340 if (atomic_read(&conn->connection_wait_rcfr)) { in iscsit_close_connection()
4341 spin_unlock_bh(&conn->state_lock); in iscsit_close_connection()
4342 complete(&conn->conn_wait_rcfr_comp); in iscsit_close_connection()
4343 wait_for_completion(&conn->conn_post_wait_comp); in iscsit_close_connection()
4344 spin_lock_bh(&conn->state_lock); in iscsit_close_connection()
4346 atomic_set(&conn->connection_reinstatement, 1); in iscsit_close_connection()
4347 spin_unlock_bh(&conn->state_lock); in iscsit_close_connection()
4355 if (conn->sock) in iscsit_close_connection()
4356 sock_release(conn->sock); in iscsit_close_connection()
4358 if (conn->conn_transport->iscsit_free_conn) in iscsit_close_connection()
4359 conn->conn_transport->iscsit_free_conn(conn); in iscsit_close_connection()
4362 conn->conn_state = TARG_CONN_STATE_FREE; in iscsit_close_connection()
4365 spin_lock_bh(&sess->conn_lock); in iscsit_close_connection()
4366 atomic_dec(&sess->nconn); in iscsit_close_connection()
4368 " %s\n", atomic_read(&sess->nconn), in iscsit_close_connection()
4369 sess->sess_ops->InitiatorName); in iscsit_close_connection()
4374 if ((sess->sess_ops->ErrorRecoveryLevel != 2) && !conn_logout && in iscsit_close_connection()
4375 !atomic_read(&sess->session_logout)) in iscsit_close_connection()
4376 atomic_set(&sess->session_fall_back_to_erl0, 1); in iscsit_close_connection()
4384 if (atomic_read(&sess->nconn)) { in iscsit_close_connection()
4385 if (!atomic_read(&sess->session_reinstatement) && in iscsit_close_connection()
4386 !atomic_read(&sess->session_fall_back_to_erl0)) { in iscsit_close_connection()
4387 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4390 if (!atomic_read(&sess->session_stop_active)) { in iscsit_close_connection()
4391 atomic_set(&sess->session_stop_active, 1); in iscsit_close_connection()
4392 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4396 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4413 if (!atomic_read(&sess->session_reinstatement) && in iscsit_close_connection()
4414 atomic_read(&sess->session_fall_back_to_erl0)) { in iscsit_close_connection()
4415 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4416 complete_all(&sess->session_wait_comp); in iscsit_close_connection()
4420 } else if (atomic_read(&sess->session_logout)) { in iscsit_close_connection()
4422 sess->session_state = TARG_SESS_STATE_FREE; in iscsit_close_connection()
4424 if (atomic_read(&sess->session_close)) { in iscsit_close_connection()
4425 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4426 complete_all(&sess->session_wait_comp); in iscsit_close_connection()
4429 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4435 sess->session_state = TARG_SESS_STATE_FAILED; in iscsit_close_connection()
4437 if (!atomic_read(&sess->session_continuation)) in iscsit_close_connection()
4440 if (atomic_read(&sess->session_close)) { in iscsit_close_connection()
4441 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4442 complete_all(&sess->session_wait_comp); in iscsit_close_connection()
4445 spin_unlock_bh(&sess->conn_lock); in iscsit_close_connection()
4458 struct iscsi_portal_group *tpg = sess->tpg; in iscsit_close_session()
4459 struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; in iscsit_close_session()
4461 if (atomic_read(&sess->nconn)) { in iscsit_close_session()
4463 " to %s\n", atomic_read(&sess->nconn), in iscsit_close_session()
4464 sess->sess_ops->InitiatorName); in iscsit_close_session()
4468 spin_lock_bh(&se_tpg->session_lock); in iscsit_close_session()
4469 atomic_set(&sess->session_logout, 1); in iscsit_close_session()
4470 atomic_set(&sess->session_reinstatement, 1); in iscsit_close_session()
4472 spin_unlock_bh(&se_tpg->session_lock); in iscsit_close_session()
4474 if (sess->sess_ops->ErrorRecoveryLevel == 2) in iscsit_close_session()
4479 * struct se_node_acl->nacl_sess pointer now as a iscsi_np process context in iscsit_close_session()
4484 transport_deregister_session_configfs(sess->se_sess); in iscsit_close_session()
4490 * restart the timer and exit. in iscsit_close_session()
4493 atomic_set(&sess->session_logout, 0); in iscsit_close_session()
4498 transport_deregister_session(sess->se_sess); in iscsit_close_session()
4502 spin_lock_bh(&se_tpg->session_lock); in iscsit_close_session()
4504 sess->session_state = TARG_SESS_STATE_FREE; in iscsit_close_session()
4506 sess->sess_ops->InitiatorName); in iscsit_close_session()
4507 tpg->nsessions--; in iscsit_close_session()
4508 if (tpg->tpg_tiqn) in iscsit_close_session()
4509 tpg->tpg_tiqn->tiqn_nsessions--; in iscsit_close_session()
4512 " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions); in iscsit_close_session()
4514 ida_free(&sess_ida, sess->session_index); in iscsit_close_session()
4515 kfree(sess->sess_ops); in iscsit_close_session()
4516 sess->sess_ops = NULL; in iscsit_close_session()
4517 spin_unlock_bh(&se_tpg->session_lock); in iscsit_close_session()
4526 struct iscsit_session *sess = conn->sess; in iscsit_logout_post_handler_closesession()
4533 * Since iser-target invokes this logic from it's own workqueue, in iscsit_logout_post_handler_closesession()
4537 if (!conn->conn_transport->rdma_shutdown) { in iscsit_logout_post_handler_closesession()
4538 sleep = cmpxchg(&conn->tx_thread_active, true, false); in iscsit_logout_post_handler_closesession()
4543 atomic_set(&conn->conn_logout_remove, 0); in iscsit_logout_post_handler_closesession()
4544 complete(&conn->conn_logout_comp); in iscsit_logout_post_handler_closesession()
4547 atomic_set(&sess->session_close, 1); in iscsit_logout_post_handler_closesession()
4557 if (!conn->conn_transport->rdma_shutdown) { in iscsit_logout_post_handler_samecid()
4558 sleep = cmpxchg(&conn->tx_thread_active, true, false); in iscsit_logout_post_handler_samecid()
4563 atomic_set(&conn->conn_logout_remove, 0); in iscsit_logout_post_handler_samecid()
4564 complete(&conn->conn_logout_comp); in iscsit_logout_post_handler_samecid()
4575 struct iscsit_session *sess = conn->sess; in iscsit_logout_post_handler_diffcid()
4581 spin_lock_bh(&sess->conn_lock); in iscsit_logout_post_handler_diffcid()
4582 list_for_each_entry(l_conn, &sess->sess_conn_list, conn_list) { in iscsit_logout_post_handler_diffcid()
4583 if (l_conn->cid == cid) { in iscsit_logout_post_handler_diffcid()
4589 spin_unlock_bh(&sess->conn_lock); in iscsit_logout_post_handler_diffcid()
4594 if (l_conn->sock) in iscsit_logout_post_handler_diffcid()
4595 l_conn->sock->ops->shutdown(l_conn->sock, RCV_SHUTDOWN); in iscsit_logout_post_handler_diffcid()
4597 spin_lock_bh(&l_conn->state_lock); in iscsit_logout_post_handler_diffcid()
4599 l_conn->conn_state = TARG_CONN_STATE_IN_LOGOUT; in iscsit_logout_post_handler_diffcid()
4600 spin_unlock_bh(&l_conn->state_lock); in iscsit_logout_post_handler_diffcid()
4615 switch (cmd->logout_reason) { in iscsit_logout_post_handler()
4617 switch (cmd->logout_response) { in iscsit_logout_post_handler()
4626 if (conn->cid == cmd->logout_cid) { in iscsit_logout_post_handler()
4627 switch (cmd->logout_response) { in iscsit_logout_post_handler()
4635 switch (cmd->logout_response) { in iscsit_logout_post_handler()
4638 cmd->logout_cid); in iscsit_logout_post_handler()
4649 switch (cmd->logout_response) { in iscsit_logout_post_handler()
4672 u16 conn_count = atomic_read(&sess->nconn); in iscsit_stop_session()
4676 spin_lock_bh(&sess->conn_lock); in iscsit_stop_session()
4679 list_for_each_entry_safe(conn, conn_tmp, &sess->sess_conn_list, in iscsit_stop_session()
4684 if (list_is_last(&conn->conn_list, &sess->sess_conn_list)) { in iscsit_stop_session()
4692 spin_unlock_bh(&sess->conn_lock); in iscsit_stop_session()
4694 spin_lock_bh(&sess->conn_lock); in iscsit_stop_session()
4699 conn_count--; in iscsit_stop_session()
4702 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) in iscsit_stop_session()
4706 if (session_sleep && atomic_read(&sess->nconn)) { in iscsit_stop_session()
4707 spin_unlock_bh(&sess->conn_lock); in iscsit_stop_session()
4708 wait_for_completion(&sess->session_wait_comp); in iscsit_stop_session()
4710 spin_unlock_bh(&sess->conn_lock); in iscsit_stop_session()
4716 struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; in iscsit_release_sessions_for_tpg()
4721 spin_lock_bh(&se_tpg->session_lock); in iscsit_release_sessions_for_tpg()
4722 if (tpg->nsessions && !force) { in iscsit_release_sessions_for_tpg()
4723 spin_unlock_bh(&se_tpg->session_lock); in iscsit_release_sessions_for_tpg()
4724 return -1; in iscsit_release_sessions_for_tpg()
4727 list_for_each_entry_safe(se_sess, se_sess_tmp, &se_tpg->tpg_sess_list, in iscsit_release_sessions_for_tpg()
4729 sess = (struct iscsit_session *)se_sess->fabric_sess_ptr; in iscsit_release_sessions_for_tpg()
4731 spin_lock(&sess->conn_lock); in iscsit_release_sessions_for_tpg()
4732 if (atomic_read(&sess->session_fall_back_to_erl0) || in iscsit_release_sessions_for_tpg()
4733 atomic_read(&sess->session_logout) || in iscsit_release_sessions_for_tpg()
4734 atomic_read(&sess->session_close) || in iscsit_release_sessions_for_tpg()
4735 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { in iscsit_release_sessions_for_tpg()
4736 spin_unlock(&sess->conn_lock); in iscsit_release_sessions_for_tpg()
4740 atomic_set(&sess->session_reinstatement, 1); in iscsit_release_sessions_for_tpg()
4741 atomic_set(&sess->session_fall_back_to_erl0, 1); in iscsit_release_sessions_for_tpg()
4742 atomic_set(&sess->session_close, 1); in iscsit_release_sessions_for_tpg()
4743 spin_unlock(&sess->conn_lock); in iscsit_release_sessions_for_tpg()
4745 list_move_tail(&se_sess->sess_list, &free_list); in iscsit_release_sessions_for_tpg()
4747 spin_unlock_bh(&se_tpg->session_lock); in iscsit_release_sessions_for_tpg()
4750 sess = (struct iscsit_session *)se_sess->fabric_sess_ptr; in iscsit_release_sessions_for_tpg()
4752 list_del_init(&se_sess->sess_list); in iscsit_release_sessions_for_tpg()
4759 " Group: %hu\n", session_count, tpg->tpgt); in iscsit_release_sessions_for_tpg()
4763 MODULE_DESCRIPTION("iSCSI-Target Driver for mainline target infrastructure");
4765 MODULE_AUTHOR("nab@Linux-iSCSI.org");