Lines Matching +full:mc +full:- +full:sid
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>
43 lockdep_assert_held(&cmd->r2t_lock); in iscsit_add_r2t_to_list()
50 return -1; in iscsit_add_r2t_to_list()
52 INIT_LIST_HEAD(&r2t->r2t_list); in iscsit_add_r2t_to_list()
54 r2t->recovery_r2t = recovery; in iscsit_add_r2t_to_list()
55 r2t->r2t_sn = (!r2t_sn) ? cmd->r2t_sn++ : r2t_sn; in iscsit_add_r2t_to_list()
56 r2t->offset = offset; in iscsit_add_r2t_to_list()
57 r2t->xfer_len = xfer_len; in iscsit_add_r2t_to_list()
58 list_add_tail(&r2t->r2t_list, &cmd->cmd_r2t_list); in iscsit_add_r2t_to_list()
59 spin_unlock_bh(&cmd->r2t_lock); in iscsit_add_r2t_to_list()
61 iscsit_add_cmd_to_immediate_queue(cmd, cmd->conn, ISTATE_SEND_R2T); in iscsit_add_r2t_to_list()
63 spin_lock_bh(&cmd->r2t_lock); in iscsit_add_r2t_to_list()
74 spin_lock_bh(&cmd->r2t_lock); in iscsit_get_r2t_for_eos()
75 list_for_each_entry(r2t, &cmd->cmd_r2t_list, r2t_list) { in iscsit_get_r2t_for_eos()
76 if ((r2t->offset <= offset) && in iscsit_get_r2t_for_eos()
77 (r2t->offset + r2t->xfer_len) >= (offset + length)) { in iscsit_get_r2t_for_eos()
78 spin_unlock_bh(&cmd->r2t_lock); in iscsit_get_r2t_for_eos()
82 spin_unlock_bh(&cmd->r2t_lock); in iscsit_get_r2t_for_eos()
93 spin_lock_bh(&cmd->r2t_lock); in iscsit_get_r2t_from_list()
94 list_for_each_entry(r2t, &cmd->cmd_r2t_list, r2t_list) { in iscsit_get_r2t_from_list()
95 if (!r2t->sent_r2t) { in iscsit_get_r2t_from_list()
96 spin_unlock_bh(&cmd->r2t_lock); in iscsit_get_r2t_from_list()
100 spin_unlock_bh(&cmd->r2t_lock); in iscsit_get_r2t_from_list()
103 " 0x%08x.\n", cmd->init_task_tag); in iscsit_get_r2t_from_list()
109 lockdep_assert_held(&cmd->r2t_lock); in iscsit_free_r2t()
111 list_del(&r2t->r2t_list); in iscsit_free_r2t()
119 spin_lock_bh(&cmd->r2t_lock); in iscsit_free_r2ts_from_list()
120 list_for_each_entry_safe(r2t, r2t_tmp, &cmd->cmd_r2t_list, r2t_list) in iscsit_free_r2ts_from_list()
122 spin_unlock_bh(&cmd->r2t_lock); in iscsit_free_r2ts_from_list()
127 int tag = -1; in iscsit_wait_for_tag()
135 sbq = &se_sess->sess_tag_pool; in iscsit_wait_for_tag()
136 ws = &sbq->ws[0]; in iscsit_wait_for_tag()
158 struct se_session *se_sess = conn->sess->se_sess; in iscsit_allocate_cmd()
161 tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu); in iscsit_allocate_cmd()
167 size = sizeof(struct iscsit_cmd) + conn->conn_transport->priv_size; in iscsit_allocate_cmd()
168 cmd = (struct iscsit_cmd *)(se_sess->sess_cmd_map + (tag * size)); in iscsit_allocate_cmd()
171 cmd->se_cmd.map_tag = tag; in iscsit_allocate_cmd()
172 cmd->se_cmd.map_cpu = cpu; in iscsit_allocate_cmd()
173 cmd->conn = conn; in iscsit_allocate_cmd()
174 cmd->data_direction = DMA_NONE; in iscsit_allocate_cmd()
175 INIT_LIST_HEAD(&cmd->i_conn_node); in iscsit_allocate_cmd()
176 INIT_LIST_HEAD(&cmd->datain_list); in iscsit_allocate_cmd()
177 INIT_LIST_HEAD(&cmd->cmd_r2t_list); in iscsit_allocate_cmd()
178 spin_lock_init(&cmd->datain_lock); in iscsit_allocate_cmd()
179 spin_lock_init(&cmd->dataout_timeout_lock); in iscsit_allocate_cmd()
180 spin_lock_init(&cmd->istate_lock); in iscsit_allocate_cmd()
181 spin_lock_init(&cmd->error_lock); in iscsit_allocate_cmd()
182 spin_lock_init(&cmd->r2t_lock); in iscsit_allocate_cmd()
183 timer_setup(&cmd->dataout_timer, iscsit_handle_dataout_timeout, 0); in iscsit_allocate_cmd()
195 for (i = 0; i < cmd->seq_count; i++) in iscsit_get_seq_holder_for_datain()
196 if (cmd->seq_list[i].seq_send_order == seq_send_order) in iscsit_get_seq_holder_for_datain()
197 return &cmd->seq_list[i]; in iscsit_get_seq_holder_for_datain()
206 if (!cmd->seq_list) { in iscsit_get_seq_holder_for_r2t()
207 pr_err("struct iscsit_cmd->seq_list is NULL!\n"); in iscsit_get_seq_holder_for_r2t()
211 for (i = 0; i < cmd->seq_count; i++) { in iscsit_get_seq_holder_for_r2t()
212 if (cmd->seq_list[i].type != SEQTYPE_NORMAL) in iscsit_get_seq_holder_for_r2t()
214 if (cmd->seq_list[i].seq_send_order == cmd->seq_send_order) { in iscsit_get_seq_holder_for_r2t()
215 cmd->seq_send_order++; in iscsit_get_seq_holder_for_r2t()
216 return &cmd->seq_list[i]; in iscsit_get_seq_holder_for_r2t()
229 spin_lock_bh(&cmd->r2t_lock); in iscsit_get_holder_for_r2tsn()
230 list_for_each_entry(r2t, &cmd->cmd_r2t_list, r2t_list) { in iscsit_get_holder_for_r2tsn()
231 if (r2t->r2t_sn == r2t_sn) { in iscsit_get_holder_for_r2tsn()
232 spin_unlock_bh(&cmd->r2t_lock); in iscsit_get_holder_for_r2tsn()
236 spin_unlock_bh(&cmd->r2t_lock); in iscsit_get_holder_for_r2tsn()
252 max_cmdsn = atomic_read(&sess->max_cmd_sn); in iscsit_check_received_cmdsn()
258 } else if (cmdsn == sess->exp_cmd_sn) { in iscsit_check_received_cmdsn()
259 sess->exp_cmd_sn++; in iscsit_check_received_cmdsn()
262 sess->exp_cmd_sn); in iscsit_check_received_cmdsn()
265 } else if (iscsi_sna_gt(cmdsn, sess->exp_cmd_sn)) { in iscsit_check_received_cmdsn()
268 cmdsn, sess->exp_cmd_sn); in iscsit_check_received_cmdsn()
274 sess->exp_cmd_sn); in iscsit_check_received_cmdsn()
282 * Commands may be received out of order if MC/S is in use.
292 mutex_lock(&conn->sess->cmdsn_mutex); in iscsit_sequence_cmd()
294 cmdsn_ret = iscsit_check_received_cmdsn(conn->sess, be32_to_cpu(cmdsn)); in iscsit_sequence_cmd()
298 if ((ret >= 0) && !list_empty(&conn->sess->sess_ooo_cmdsn_list)) in iscsit_sequence_cmd()
299 iscsit_execute_ooo_cmdsns(conn->sess); in iscsit_sequence_cmd()
306 ret = iscsit_handle_ooo_cmdsn(conn->sess, cmd, be32_to_cpu(cmdsn)); in iscsit_sequence_cmd()
317 cmd->i_state = ISTATE_REMOVE; in iscsit_sequence_cmd()
318 iscsit_add_cmd_to_immediate_queue(cmd, conn, cmd->i_state); in iscsit_sequence_cmd()
327 mutex_unlock(&conn->sess->cmdsn_mutex); in iscsit_sequence_cmd()
338 struct iscsit_conn *conn = cmd->conn; in iscsit_check_unsolicited_dataout()
339 struct se_cmd *se_cmd = &cmd->se_cmd; in iscsit_check_unsolicited_dataout()
341 u32 payload_length = ntoh24(hdr->dlength); in iscsit_check_unsolicited_dataout()
343 if (conn->sess->sess_ops->InitialR2T) { in iscsit_check_unsolicited_dataout()
348 return -1; in iscsit_check_unsolicited_dataout()
351 if ((cmd->first_burst_len + payload_length) > in iscsit_check_unsolicited_dataout()
352 conn->sess->sess_ops->FirstBurstLength) { in iscsit_check_unsolicited_dataout()
355 (cmd->first_burst_len + payload_length), in iscsit_check_unsolicited_dataout()
356 conn->sess->sess_ops->FirstBurstLength); in iscsit_check_unsolicited_dataout()
359 return -1; in iscsit_check_unsolicited_dataout()
362 if (!(hdr->flags & ISCSI_FLAG_CMD_FINAL)) in iscsit_check_unsolicited_dataout()
365 if (((cmd->first_burst_len + payload_length) != cmd->se_cmd.data_length) && in iscsit_check_unsolicited_dataout()
366 ((cmd->first_burst_len + payload_length) != in iscsit_check_unsolicited_dataout()
367 conn->sess->sess_ops->FirstBurstLength)) { in iscsit_check_unsolicited_dataout()
368 pr_err("Unsolicited non-immediate data received %u" in iscsit_check_unsolicited_dataout()
371 (cmd->first_burst_len + payload_length), in iscsit_check_unsolicited_dataout()
372 conn->sess->sess_ops->FirstBurstLength, cmd->se_cmd.data_length); in iscsit_check_unsolicited_dataout()
375 return -1; in iscsit_check_unsolicited_dataout()
386 spin_lock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_itt()
387 list_for_each_entry(cmd, &conn->conn_cmd_list, i_conn_node) { in iscsit_find_cmd_from_itt()
388 if (cmd->init_task_tag == init_task_tag) { in iscsit_find_cmd_from_itt()
389 spin_unlock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_itt()
393 spin_unlock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_itt()
396 init_task_tag, conn->cid); in iscsit_find_cmd_from_itt()
408 spin_lock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_itt_or_dump()
409 list_for_each_entry(cmd, &conn->conn_cmd_list, i_conn_node) { in iscsit_find_cmd_from_itt_or_dump()
410 if (cmd->cmd_flags & ICF_GOT_LAST_DATAOUT) in iscsit_find_cmd_from_itt_or_dump()
412 if (cmd->init_task_tag == init_task_tag) { in iscsit_find_cmd_from_itt_or_dump()
413 spin_unlock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_itt_or_dump()
417 spin_unlock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_itt_or_dump()
420 " dumping payload\n", init_task_tag, conn->cid); in iscsit_find_cmd_from_itt_or_dump()
434 spin_lock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_ttt()
435 list_for_each_entry(cmd, &conn->conn_cmd_list, i_conn_node) { in iscsit_find_cmd_from_ttt()
436 if (cmd->targ_xfer_tag == targ_xfer_tag) { in iscsit_find_cmd_from_ttt()
437 spin_unlock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_ttt()
441 spin_unlock_bh(&conn->cmd_lock); in iscsit_find_cmd_from_ttt()
444 targ_xfer_tag, conn->cid); in iscsit_find_cmd_from_ttt()
460 spin_lock(&sess->cr_i_lock); in iscsit_find_cmd_for_recovery()
461 list_for_each_entry(cr, &sess->cr_inactive_list, cr_list) { in iscsit_find_cmd_for_recovery()
462 spin_lock(&cr->conn_recovery_cmd_lock); in iscsit_find_cmd_for_recovery()
463 list_for_each_entry(cmd, &cr->conn_recovery_cmd_list, i_conn_node) { in iscsit_find_cmd_for_recovery()
464 if (cmd->init_task_tag == init_task_tag) { in iscsit_find_cmd_for_recovery()
465 spin_unlock(&cr->conn_recovery_cmd_lock); in iscsit_find_cmd_for_recovery()
466 spin_unlock(&sess->cr_i_lock); in iscsit_find_cmd_for_recovery()
470 return -2; in iscsit_find_cmd_for_recovery()
473 spin_unlock(&cr->conn_recovery_cmd_lock); in iscsit_find_cmd_for_recovery()
475 spin_unlock(&sess->cr_i_lock); in iscsit_find_cmd_for_recovery()
480 spin_lock(&sess->cr_a_lock); in iscsit_find_cmd_for_recovery()
481 list_for_each_entry(cr, &sess->cr_active_list, cr_list) { in iscsit_find_cmd_for_recovery()
482 spin_lock(&cr->conn_recovery_cmd_lock); in iscsit_find_cmd_for_recovery()
483 list_for_each_entry(cmd, &cr->conn_recovery_cmd_list, i_conn_node) { in iscsit_find_cmd_for_recovery()
484 if (cmd->init_task_tag == init_task_tag) { in iscsit_find_cmd_for_recovery()
485 spin_unlock(&cr->conn_recovery_cmd_lock); in iscsit_find_cmd_for_recovery()
486 spin_unlock(&sess->cr_a_lock); in iscsit_find_cmd_for_recovery()
493 spin_unlock(&cr->conn_recovery_cmd_lock); in iscsit_find_cmd_for_recovery()
495 spin_unlock(&sess->cr_a_lock); in iscsit_find_cmd_for_recovery()
497 return -1; in iscsit_find_cmd_for_recovery()
513 INIT_LIST_HEAD(&qr->qr_list); in iscsit_add_cmd_to_immediate_queue()
514 qr->cmd = cmd; in iscsit_add_cmd_to_immediate_queue()
515 qr->state = state; in iscsit_add_cmd_to_immediate_queue()
517 spin_lock_bh(&conn->immed_queue_lock); in iscsit_add_cmd_to_immediate_queue()
518 list_add_tail(&qr->qr_list, &conn->immed_queue_list); in iscsit_add_cmd_to_immediate_queue()
519 atomic_inc(&cmd->immed_queue_count); in iscsit_add_cmd_to_immediate_queue()
520 atomic_set(&conn->check_immediate_queue, 1); in iscsit_add_cmd_to_immediate_queue()
521 spin_unlock_bh(&conn->immed_queue_lock); in iscsit_add_cmd_to_immediate_queue()
523 wake_up(&conn->queues_wq); in iscsit_add_cmd_to_immediate_queue()
531 spin_lock_bh(&conn->immed_queue_lock); in iscsit_get_cmd_from_immediate_queue()
532 if (list_empty(&conn->immed_queue_list)) { in iscsit_get_cmd_from_immediate_queue()
533 spin_unlock_bh(&conn->immed_queue_lock); in iscsit_get_cmd_from_immediate_queue()
536 qr = list_first_entry(&conn->immed_queue_list, in iscsit_get_cmd_from_immediate_queue()
539 list_del(&qr->qr_list); in iscsit_get_cmd_from_immediate_queue()
540 if (qr->cmd) in iscsit_get_cmd_from_immediate_queue()
541 atomic_dec(&qr->cmd->immed_queue_count); in iscsit_get_cmd_from_immediate_queue()
542 spin_unlock_bh(&conn->immed_queue_lock); in iscsit_get_cmd_from_immediate_queue()
553 spin_lock_bh(&conn->immed_queue_lock); in iscsit_remove_cmd_from_immediate_queue()
554 if (!atomic_read(&cmd->immed_queue_count)) { in iscsit_remove_cmd_from_immediate_queue()
555 spin_unlock_bh(&conn->immed_queue_lock); in iscsit_remove_cmd_from_immediate_queue()
559 list_for_each_entry_safe(qr, qr_tmp, &conn->immed_queue_list, qr_list) { in iscsit_remove_cmd_from_immediate_queue()
560 if (qr->cmd != cmd) in iscsit_remove_cmd_from_immediate_queue()
563 atomic_dec(&qr->cmd->immed_queue_count); in iscsit_remove_cmd_from_immediate_queue()
564 list_del(&qr->qr_list); in iscsit_remove_cmd_from_immediate_queue()
567 spin_unlock_bh(&conn->immed_queue_lock); in iscsit_remove_cmd_from_immediate_queue()
569 if (atomic_read(&cmd->immed_queue_count)) { in iscsit_remove_cmd_from_immediate_queue()
571 cmd->init_task_tag, in iscsit_remove_cmd_from_immediate_queue()
572 atomic_read(&cmd->immed_queue_count)); in iscsit_remove_cmd_from_immediate_queue()
587 return -ENOMEM; in iscsit_add_cmd_to_response_queue()
589 INIT_LIST_HEAD(&qr->qr_list); in iscsit_add_cmd_to_response_queue()
590 qr->cmd = cmd; in iscsit_add_cmd_to_response_queue()
591 qr->state = state; in iscsit_add_cmd_to_response_queue()
593 spin_lock_bh(&conn->response_queue_lock); in iscsit_add_cmd_to_response_queue()
594 list_add_tail(&qr->qr_list, &conn->response_queue_list); in iscsit_add_cmd_to_response_queue()
595 atomic_inc(&cmd->response_queue_count); in iscsit_add_cmd_to_response_queue()
596 spin_unlock_bh(&conn->response_queue_lock); in iscsit_add_cmd_to_response_queue()
598 wake_up(&conn->queues_wq); in iscsit_add_cmd_to_response_queue()
606 spin_lock_bh(&conn->response_queue_lock); in iscsit_get_cmd_from_response_queue()
607 if (list_empty(&conn->response_queue_list)) { in iscsit_get_cmd_from_response_queue()
608 spin_unlock_bh(&conn->response_queue_lock); in iscsit_get_cmd_from_response_queue()
612 qr = list_first_entry(&conn->response_queue_list, in iscsit_get_cmd_from_response_queue()
615 list_del(&qr->qr_list); in iscsit_get_cmd_from_response_queue()
616 if (qr->cmd) in iscsit_get_cmd_from_response_queue()
617 atomic_dec(&qr->cmd->response_queue_count); in iscsit_get_cmd_from_response_queue()
618 spin_unlock_bh(&conn->response_queue_lock); in iscsit_get_cmd_from_response_queue()
629 spin_lock_bh(&conn->response_queue_lock); in iscsit_remove_cmd_from_response_queue()
630 if (!atomic_read(&cmd->response_queue_count)) { in iscsit_remove_cmd_from_response_queue()
631 spin_unlock_bh(&conn->response_queue_lock); in iscsit_remove_cmd_from_response_queue()
635 list_for_each_entry_safe(qr, qr_tmp, &conn->response_queue_list, in iscsit_remove_cmd_from_response_queue()
637 if (qr->cmd != cmd) in iscsit_remove_cmd_from_response_queue()
640 atomic_dec(&qr->cmd->response_queue_count); in iscsit_remove_cmd_from_response_queue()
641 list_del(&qr->qr_list); in iscsit_remove_cmd_from_response_queue()
644 spin_unlock_bh(&conn->response_queue_lock); in iscsit_remove_cmd_from_response_queue()
646 if (atomic_read(&cmd->response_queue_count)) { in iscsit_remove_cmd_from_response_queue()
648 cmd->init_task_tag, in iscsit_remove_cmd_from_response_queue()
649 atomic_read(&cmd->response_queue_count)); in iscsit_remove_cmd_from_response_queue()
657 spin_lock_bh(&conn->immed_queue_lock); in iscsit_conn_all_queues_empty()
658 empty = list_empty(&conn->immed_queue_list); in iscsit_conn_all_queues_empty()
659 spin_unlock_bh(&conn->immed_queue_lock); in iscsit_conn_all_queues_empty()
664 spin_lock_bh(&conn->response_queue_lock); in iscsit_conn_all_queues_empty()
665 empty = list_empty(&conn->response_queue_list); in iscsit_conn_all_queues_empty()
666 spin_unlock_bh(&conn->response_queue_lock); in iscsit_conn_all_queues_empty()
675 spin_lock_bh(&conn->immed_queue_lock); in iscsit_free_queue_reqs_for_conn()
676 list_for_each_entry_safe(qr, qr_tmp, &conn->immed_queue_list, qr_list) { in iscsit_free_queue_reqs_for_conn()
677 list_del(&qr->qr_list); in iscsit_free_queue_reqs_for_conn()
678 if (qr->cmd) in iscsit_free_queue_reqs_for_conn()
679 atomic_dec(&qr->cmd->immed_queue_count); in iscsit_free_queue_reqs_for_conn()
683 spin_unlock_bh(&conn->immed_queue_lock); in iscsit_free_queue_reqs_for_conn()
685 spin_lock_bh(&conn->response_queue_lock); in iscsit_free_queue_reqs_for_conn()
686 list_for_each_entry_safe(qr, qr_tmp, &conn->response_queue_list, in iscsit_free_queue_reqs_for_conn()
688 list_del(&qr->qr_list); in iscsit_free_queue_reqs_for_conn()
689 if (qr->cmd) in iscsit_free_queue_reqs_for_conn()
690 atomic_dec(&qr->cmd->response_queue_count); in iscsit_free_queue_reqs_for_conn()
694 spin_unlock_bh(&conn->response_queue_lock); in iscsit_free_queue_reqs_for_conn()
700 struct se_cmd *se_cmd = &cmd->se_cmd; in iscsit_release_cmd()
702 WARN_ON(!list_empty(&cmd->i_conn_node)); in iscsit_release_cmd()
704 if (cmd->conn) in iscsit_release_cmd()
705 sess = cmd->conn->sess; in iscsit_release_cmd()
707 sess = cmd->sess; in iscsit_release_cmd()
709 BUG_ON(!sess || !sess->se_sess); in iscsit_release_cmd()
711 kfree(cmd->buf_ptr); in iscsit_release_cmd()
712 kfree(cmd->pdu_list); in iscsit_release_cmd()
713 kfree(cmd->seq_list); in iscsit_release_cmd()
714 kfree(cmd->tmr_req); in iscsit_release_cmd()
715 kfree(cmd->overflow_buf); in iscsit_release_cmd()
716 kfree(cmd->iov_data); in iscsit_release_cmd()
717 kfree(cmd->text_in_ptr); in iscsit_release_cmd()
719 target_free_tag(sess->se_sess, se_cmd); in iscsit_release_cmd()
725 struct iscsit_conn *conn = cmd->conn; in __iscsit_free_cmd()
727 WARN_ON(!list_empty(&cmd->i_conn_node)); in __iscsit_free_cmd()
729 if (cmd->data_direction == DMA_TO_DEVICE) { in __iscsit_free_cmd()
733 if (cmd->data_direction == DMA_FROM_DEVICE) in __iscsit_free_cmd()
741 if (conn && conn->conn_transport->iscsit_unmap_cmd) in __iscsit_free_cmd()
742 conn->conn_transport->iscsit_unmap_cmd(conn, cmd); in __iscsit_free_cmd()
747 struct se_cmd *se_cmd = cmd->se_cmd.se_tfo ? &cmd->se_cmd : NULL; in iscsit_free_cmd()
750 WARN_ON(!list_empty(&cmd->i_conn_node)); in iscsit_free_cmd()
755 if (!rc && shutdown && se_cmd->se_sess) { in iscsit_free_cmd()
768 spin_lock_bh(&sess->session_usage_lock); in iscsit_check_session_usage_count()
769 if (sess->session_usage_count != 0) { in iscsit_check_session_usage_count()
770 sess->session_waiting_on_uc = 1; in iscsit_check_session_usage_count()
771 spin_unlock_bh(&sess->session_usage_lock); in iscsit_check_session_usage_count()
775 wait_for_completion(&sess->session_waiting_on_uc_comp); in iscsit_check_session_usage_count()
778 spin_unlock_bh(&sess->session_usage_lock); in iscsit_check_session_usage_count()
785 spin_lock_bh(&sess->session_usage_lock); in iscsit_dec_session_usage_count()
786 sess->session_usage_count--; in iscsit_dec_session_usage_count()
788 if (!sess->session_usage_count && sess->session_waiting_on_uc) in iscsit_dec_session_usage_count()
789 complete(&sess->session_waiting_on_uc_comp); in iscsit_dec_session_usage_count()
791 spin_unlock_bh(&sess->session_usage_lock); in iscsit_dec_session_usage_count()
796 spin_lock_bh(&sess->session_usage_lock); in iscsit_inc_session_usage_count()
797 sess->session_usage_count++; in iscsit_inc_session_usage_count()
798 spin_unlock_bh(&sess->session_usage_lock); in iscsit_inc_session_usage_count()
805 spin_lock_bh(&sess->conn_lock); in iscsit_get_conn_from_cid()
806 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { in iscsit_get_conn_from_cid()
807 if ((conn->cid == cid) && in iscsit_get_conn_from_cid()
808 (conn->conn_state == TARG_CONN_STATE_LOGGED_IN)) { in iscsit_get_conn_from_cid()
810 spin_unlock_bh(&sess->conn_lock); in iscsit_get_conn_from_cid()
814 spin_unlock_bh(&sess->conn_lock); in iscsit_get_conn_from_cid()
823 spin_lock_bh(&sess->conn_lock); in iscsit_get_conn_from_cid_rcfr()
824 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { in iscsit_get_conn_from_cid_rcfr()
825 if (conn->cid == cid) { in iscsit_get_conn_from_cid_rcfr()
827 spin_lock(&conn->state_lock); in iscsit_get_conn_from_cid_rcfr()
828 atomic_set(&conn->connection_wait_rcfr, 1); in iscsit_get_conn_from_cid_rcfr()
829 spin_unlock(&conn->state_lock); in iscsit_get_conn_from_cid_rcfr()
830 spin_unlock_bh(&sess->conn_lock); in iscsit_get_conn_from_cid_rcfr()
834 spin_unlock_bh(&sess->conn_lock); in iscsit_get_conn_from_cid_rcfr()
841 spin_lock_bh(&conn->conn_usage_lock); in iscsit_check_conn_usage_count()
842 if (conn->conn_usage_count != 0) { in iscsit_check_conn_usage_count()
843 conn->conn_waiting_on_uc = 1; in iscsit_check_conn_usage_count()
844 spin_unlock_bh(&conn->conn_usage_lock); in iscsit_check_conn_usage_count()
846 wait_for_completion(&conn->conn_waiting_on_uc_comp); in iscsit_check_conn_usage_count()
849 spin_unlock_bh(&conn->conn_usage_lock); in iscsit_check_conn_usage_count()
854 spin_lock_bh(&conn->conn_usage_lock); in iscsit_dec_conn_usage_count()
855 conn->conn_usage_count--; in iscsit_dec_conn_usage_count()
857 if (!conn->conn_usage_count && conn->conn_waiting_on_uc) in iscsit_dec_conn_usage_count()
858 complete(&conn->conn_waiting_on_uc_comp); in iscsit_dec_conn_usage_count()
860 spin_unlock_bh(&conn->conn_usage_lock); in iscsit_dec_conn_usage_count()
865 spin_lock_bh(&conn->conn_usage_lock); in iscsit_inc_conn_usage_count()
866 conn->conn_usage_count++; in iscsit_inc_conn_usage_count()
867 spin_unlock_bh(&conn->conn_usage_lock); in iscsit_inc_conn_usage_count()
877 return -1; in iscsit_add_nopin()
879 cmd->iscsi_opcode = ISCSI_OP_NOOP_IN; in iscsit_add_nopin()
882 cmd->init_task_tag = RESERVED_ITT; in iscsit_add_nopin()
883 cmd->targ_xfer_tag = (want_response) ? in iscsit_add_nopin()
884 session_get_next_ttt(conn->sess) : 0xFFFFFFFF; in iscsit_add_nopin()
885 spin_lock_bh(&conn->cmd_lock); in iscsit_add_nopin()
886 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); in iscsit_add_nopin()
887 spin_unlock_bh(&conn->cmd_lock); in iscsit_add_nopin()
899 struct iscsit_session *sess = conn->sess; in iscsit_handle_nopin_response_timeout()
903 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_handle_nopin_response_timeout()
904 if (conn->nopin_response_timer_flags & ISCSI_TF_STOP) { in iscsit_handle_nopin_response_timeout()
905 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_handle_nopin_response_timeout()
912 conn->cid, sess->sess_ops->InitiatorName, sess->isid, in iscsit_handle_nopin_response_timeout()
913 sess->tpg->tpg_tiqn->tiqn, (u32)sess->tpg->tpgt); in iscsit_handle_nopin_response_timeout()
914 conn->nopin_response_timer_flags &= ~ISCSI_TF_RUNNING; in iscsit_handle_nopin_response_timeout()
915 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_handle_nopin_response_timeout()
924 struct iscsit_session *sess = conn->sess; in iscsit_mod_nopin_response_timer()
927 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_mod_nopin_response_timer()
928 if (!(conn->nopin_response_timer_flags & ISCSI_TF_RUNNING)) { in iscsit_mod_nopin_response_timer()
929 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_mod_nopin_response_timer()
933 mod_timer(&conn->nopin_response_timer, in iscsit_mod_nopin_response_timer()
934 (get_jiffies_64() + na->nopin_response_timeout * HZ)); in iscsit_mod_nopin_response_timer()
935 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_mod_nopin_response_timer()
940 struct iscsit_session *sess = conn->sess; in iscsit_start_nopin_response_timer()
943 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_start_nopin_response_timer()
944 if (conn->nopin_response_timer_flags & ISCSI_TF_RUNNING) { in iscsit_start_nopin_response_timer()
945 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_start_nopin_response_timer()
949 conn->nopin_response_timer_flags &= ~ISCSI_TF_STOP; in iscsit_start_nopin_response_timer()
950 conn->nopin_response_timer_flags |= ISCSI_TF_RUNNING; in iscsit_start_nopin_response_timer()
951 mod_timer(&conn->nopin_response_timer, in iscsit_start_nopin_response_timer()
952 jiffies + na->nopin_response_timeout * HZ); in iscsit_start_nopin_response_timer()
955 " seconds\n", conn->cid, na->nopin_response_timeout); in iscsit_start_nopin_response_timer()
956 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_start_nopin_response_timer()
961 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_response_timer()
962 if (!(conn->nopin_response_timer_flags & ISCSI_TF_RUNNING)) { in iscsit_stop_nopin_response_timer()
963 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_response_timer()
966 conn->nopin_response_timer_flags |= ISCSI_TF_STOP; in iscsit_stop_nopin_response_timer()
967 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_response_timer()
969 del_timer_sync(&conn->nopin_response_timer); in iscsit_stop_nopin_response_timer()
971 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_response_timer()
972 conn->nopin_response_timer_flags &= ~ISCSI_TF_RUNNING; in iscsit_stop_nopin_response_timer()
973 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_response_timer()
982 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_handle_nopin_timeout()
983 if (conn->nopin_timer_flags & ISCSI_TF_STOP) { in iscsit_handle_nopin_timeout()
984 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_handle_nopin_timeout()
988 conn->nopin_timer_flags &= ~ISCSI_TF_RUNNING; in iscsit_handle_nopin_timeout()
989 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_handle_nopin_timeout()
997 struct iscsit_session *sess = conn->sess; in __iscsit_start_nopin_timer()
1000 lockdep_assert_held(&conn->nopin_timer_lock); in __iscsit_start_nopin_timer()
1005 if (!na->nopin_timeout) in __iscsit_start_nopin_timer()
1008 if (conn->nopin_timer_flags & ISCSI_TF_RUNNING) in __iscsit_start_nopin_timer()
1011 conn->nopin_timer_flags &= ~ISCSI_TF_STOP; in __iscsit_start_nopin_timer()
1012 conn->nopin_timer_flags |= ISCSI_TF_RUNNING; in __iscsit_start_nopin_timer()
1013 mod_timer(&conn->nopin_timer, jiffies + na->nopin_timeout * HZ); in __iscsit_start_nopin_timer()
1016 " interval\n", conn->cid, na->nopin_timeout); in __iscsit_start_nopin_timer()
1021 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_start_nopin_timer()
1023 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_start_nopin_timer()
1028 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_timer()
1029 if (!(conn->nopin_timer_flags & ISCSI_TF_RUNNING)) { in iscsit_stop_nopin_timer()
1030 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_timer()
1033 conn->nopin_timer_flags |= ISCSI_TF_STOP; in iscsit_stop_nopin_timer()
1034 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_timer()
1036 del_timer_sync(&conn->nopin_timer); in iscsit_stop_nopin_timer()
1038 spin_lock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_timer()
1039 conn->nopin_timer_flags &= ~ISCSI_TF_RUNNING; in iscsit_stop_nopin_timer()
1040 spin_unlock_bh(&conn->nopin_timer_lock); in iscsit_stop_nopin_timer()
1046 struct iscsi_login *login = conn->login; in iscsit_login_timeout()
1050 spin_lock_bh(&conn->login_timer_lock); in iscsit_login_timeout()
1051 login->login_failed = 1; in iscsit_login_timeout()
1053 if (conn->login_kworker) { in iscsit_login_timeout()
1054 pr_debug("Sending SIGINT to conn->login_kworker %s/%d\n", in iscsit_login_timeout()
1055 conn->login_kworker->comm, conn->login_kworker->pid); in iscsit_login_timeout()
1056 send_sig(SIGINT, conn->login_kworker, 1); in iscsit_login_timeout()
1058 schedule_delayed_work(&conn->login_work, 0); in iscsit_login_timeout()
1060 spin_unlock_bh(&conn->login_timer_lock); in iscsit_login_timeout()
1067 conn->login_kworker = kthr; in iscsit_start_login_timer()
1068 mod_timer(&conn->login_timer, jiffies + TA_LOGIN_TIMEOUT * HZ); in iscsit_start_login_timer()
1073 struct iscsi_login *login = conn->login; in iscsit_set_login_timer_kworker()
1076 spin_lock_bh(&conn->login_timer_lock); in iscsit_set_login_timer_kworker()
1077 if (login->login_failed) { in iscsit_set_login_timer_kworker()
1079 ret = -1; in iscsit_set_login_timer_kworker()
1081 conn->login_kworker = kthr; in iscsit_set_login_timer_kworker()
1083 spin_unlock_bh(&conn->login_timer_lock); in iscsit_set_login_timer_kworker()
1091 timer_delete_sync(&conn->login_timer); in iscsit_stop_login_timer()
1104 tx_size = cmd->tx_size; in iscsit_send_tx_data()
1107 iov = &cmd->iov_data[0]; in iscsit_send_tx_data()
1108 iov_count = cmd->iov_data_count; in iscsit_send_tx_data()
1110 iov = &cmd->iov_misc[0]; in iscsit_send_tx_data()
1111 iov_count = cmd->iov_misc_count; in iscsit_send_tx_data()
1116 if (tx_sent == -EAGAIN) { in iscsit_send_tx_data()
1117 pr_err("tx_data() returned -EAGAIN\n"); in iscsit_send_tx_data()
1120 return -1; in iscsit_send_tx_data()
1122 cmd->tx_size = 0; in iscsit_send_tx_data()
1131 struct scatterlist *sg = cmd->first_data_sg; in iscsit_fe_sendpage_sg()
1136 u32 offset = cmd->first_data_sg_off; in iscsit_fe_sendpage_sg()
1141 if (conn->conn_ops->HeaderDigest) in iscsit_fe_sendpage_sg()
1144 iov.iov_base = cmd->pdu; in iscsit_fe_sendpage_sg()
1149 if (tx_sent == -EAGAIN) { in iscsit_fe_sendpage_sg()
1150 pr_err("tx_data() returned -EAGAIN\n"); in iscsit_fe_sendpage_sg()
1153 return -1; in iscsit_fe_sendpage_sg()
1156 data_len = cmd->tx_size - tx_hdr_size - cmd->padding; in iscsit_fe_sendpage_sg()
1159 * in order to determine proper offset into cmd->iov_data[] in iscsit_fe_sendpage_sg()
1161 if (conn->conn_ops->DataDigest) { in iscsit_fe_sendpage_sg()
1162 data_len -= ISCSI_CRC_LEN; in iscsit_fe_sendpage_sg()
1163 if (cmd->padding) in iscsit_fe_sendpage_sg()
1164 iov_off = (cmd->iov_data_count - 2); in iscsit_fe_sendpage_sg()
1166 iov_off = (cmd->iov_data_count - 1); in iscsit_fe_sendpage_sg()
1168 iov_off = (cmd->iov_data_count - 1); in iscsit_fe_sendpage_sg()
1174 u32 space = (sg->length - offset); in iscsit_fe_sendpage_sg()
1177 bvec_set_page(&bvec, sg_page(sg), sub_len, sg->offset + offset); in iscsit_fe_sendpage_sg()
1180 tx_sent = conn->sock->ops->sendmsg(conn->sock, &msghdr, in iscsit_fe_sendpage_sg()
1183 if (tx_sent == -EAGAIN) { in iscsit_fe_sendpage_sg()
1184 pr_err("sendmsg/splice returned -EAGAIN\n"); in iscsit_fe_sendpage_sg()
1189 return -1; in iscsit_fe_sendpage_sg()
1192 data_len -= sub_len; in iscsit_fe_sendpage_sg()
1198 if (cmd->padding) { in iscsit_fe_sendpage_sg()
1199 struct kvec *iov_p = &cmd->iov_data[iov_off++]; in iscsit_fe_sendpage_sg()
1201 tx_sent = tx_data(conn, iov_p, 1, cmd->padding); in iscsit_fe_sendpage_sg()
1202 if (cmd->padding != tx_sent) { in iscsit_fe_sendpage_sg()
1203 if (tx_sent == -EAGAIN) { in iscsit_fe_sendpage_sg()
1204 pr_err("tx_data() returned -EAGAIN\n"); in iscsit_fe_sendpage_sg()
1207 return -1; in iscsit_fe_sendpage_sg()
1212 if (conn->conn_ops->DataDigest) { in iscsit_fe_sendpage_sg()
1213 struct kvec *iov_d = &cmd->iov_data[iov_off]; in iscsit_fe_sendpage_sg()
1217 if (tx_sent == -EAGAIN) { in iscsit_fe_sendpage_sg()
1218 pr_err("tx_data() returned -EAGAIN\n"); in iscsit_fe_sendpage_sg()
1221 return -1; in iscsit_fe_sendpage_sg()
1234 * Returns: 0 on success, -1 on error.
1239 struct iscsi_login *login = conn->conn_login; in iscsit_tx_login_rsp()
1241 login->login_failed = 1; in iscsit_tx_login_rsp()
1244 memset(&login->rsp[0], 0, ISCSI_HDR_LEN); in iscsit_tx_login_rsp()
1246 hdr = (struct iscsi_login_rsp *)&login->rsp[0]; in iscsit_tx_login_rsp()
1247 hdr->opcode = ISCSI_OP_LOGIN_RSP; in iscsit_tx_login_rsp()
1248 hdr->status_class = status_class; in iscsit_tx_login_rsp()
1249 hdr->status_detail = status_detail; in iscsit_tx_login_rsp()
1250 hdr->itt = conn->login_itt; in iscsit_tx_login_rsp()
1252 return conn->conn_transport->iscsit_put_login_tx(conn, login, 0); in iscsit_tx_login_rsp()
1259 pr_debug("-----------------------------[Session Params for" in iscsit_print_session_params()
1260 " SID: %u]-----------------------------\n", sess->sid); in iscsit_print_session_params()
1261 spin_lock_bh(&sess->conn_lock); in iscsit_print_session_params()
1262 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) in iscsit_print_session_params()
1263 iscsi_dump_conn_ops(conn->conn_ops); in iscsit_print_session_params()
1264 spin_unlock_bh(&sess->conn_lock); in iscsit_print_session_params()
1266 iscsi_dump_sess_ops(sess->sess_ops); in iscsit_print_session_params()
1278 if (!conn || !conn->sock || !conn->conn_ops) in rx_data()
1279 return -1; in rx_data()
1285 rx_loop = sock_recvmsg(conn->sock, &msg, MSG_WAITALL); in rx_data()
1308 if (!conn || !conn->sock || !conn->conn_ops) in tx_data()
1309 return -1; in tx_data()
1313 return -1; in tx_data()
1321 int tx_loop = sock_sendmsg(conn->sock, &msg); in tx_data()
1348 ls = &tiqn->login_stats; in iscsit_collect_login_stats()
1350 spin_lock(&ls->lock); in iscsit_collect_login_stats()
1352 ls->accepts++; in iscsit_collect_login_stats()
1354 ls->redirects++; in iscsit_collect_login_stats()
1355 ls->last_fail_type = ISCSI_LOGIN_FAIL_REDIRECT; in iscsit_collect_login_stats()
1358 ls->authenticate_fails++; in iscsit_collect_login_stats()
1359 ls->last_fail_type = ISCSI_LOGIN_FAIL_AUTHENTICATE; in iscsit_collect_login_stats()
1362 ls->authorize_fails++; in iscsit_collect_login_stats()
1363 ls->last_fail_type = ISCSI_LOGIN_FAIL_AUTHORIZE; in iscsit_collect_login_stats()
1366 ls->negotiate_fails++; in iscsit_collect_login_stats()
1367 ls->last_fail_type = ISCSI_LOGIN_FAIL_NEGOTIATE; in iscsit_collect_login_stats()
1369 ls->other_fails++; in iscsit_collect_login_stats()
1370 ls->last_fail_type = ISCSI_LOGIN_FAIL_OTHER; in iscsit_collect_login_stats()
1375 if (conn->param_list) in iscsit_collect_login_stats()
1377 conn->param_list); in iscsit_collect_login_stats()
1378 strscpy(ls->last_intr_fail_name, in iscsit_collect_login_stats()
1379 (intrname ? intrname->value : "Unknown"), in iscsit_collect_login_stats()
1380 sizeof(ls->last_intr_fail_name)); in iscsit_collect_login_stats()
1382 ls->last_intr_fail_ip_family = conn->login_family; in iscsit_collect_login_stats()
1384 ls->last_intr_fail_sockaddr = conn->login_sockaddr; in iscsit_collect_login_stats()
1385 ls->last_fail_time = get_jiffies_64(); in iscsit_collect_login_stats()
1388 spin_unlock(&ls->lock); in iscsit_collect_login_stats()
1398 tpg = conn->tpg; in iscsit_snmp_get_tiqn()
1402 if (!tpg->tpg_tiqn) in iscsit_snmp_get_tiqn()
1405 return tpg->tpg_tiqn; in iscsit_snmp_get_tiqn()
1410 struct iscsi_portal_group *tpg = sess->tpg; in iscsit_fill_cxn_timeout_err_stats()
1411 struct iscsi_tiqn *tiqn = tpg->tpg_tiqn; in iscsit_fill_cxn_timeout_err_stats()
1416 spin_lock_bh(&tiqn->sess_err_stats.lock); in iscsit_fill_cxn_timeout_err_stats()
1417 strscpy(tiqn->sess_err_stats.last_sess_fail_rem_name, in iscsit_fill_cxn_timeout_err_stats()
1418 sess->sess_ops->InitiatorName, in iscsit_fill_cxn_timeout_err_stats()
1419 sizeof(tiqn->sess_err_stats.last_sess_fail_rem_name)); in iscsit_fill_cxn_timeout_err_stats()
1420 tiqn->sess_err_stats.last_sess_failure_type = in iscsit_fill_cxn_timeout_err_stats()
1422 tiqn->sess_err_stats.cxn_timeout_errors++; in iscsit_fill_cxn_timeout_err_stats()
1423 atomic_long_inc(&sess->conn_timeout_errors); in iscsit_fill_cxn_timeout_err_stats()
1424 spin_unlock_bh(&tiqn->sess_err_stats.lock); in iscsit_fill_cxn_timeout_err_stats()