Lines Matching +full:max +full:- +full:reason

1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * Copyright (C) 2004 - 2006 Mike Christie
7 * Copyright (C) 2004 - 2005 Dmitry Yusupov
8 * Copyright (C) 2004 - 2005 Alex Aizman
9 * maintained by open-iscsi@googlegroups.com
60 &(_conn)->cls_conn->dev, \
71 &(_session)->cls_session->dev, \
82 &(_session)->cls_session->dev, \
90 struct Scsi_Host *shost = conn->session->host; in iscsi_conn_queue_xmit()
93 if (ihost->workq) in iscsi_conn_queue_xmit()
94 queue_work(ihost->workq, &conn->xmitwork); in iscsi_conn_queue_xmit()
100 struct Scsi_Host *shost = conn->session->host; in iscsi_conn_queue_recv()
103 if (ihost->workq && !test_bit(ISCSI_CONN_FLAG_SUSPEND_RX, &conn->flags)) in iscsi_conn_queue_recv()
104 queue_work(ihost->workq, &conn->recvwork); in iscsi_conn_queue_recv()
113 * max sequence numbers in __iscsi_update_cmdsn()
115 if (iscsi_sna_lt(max_cmdsn, exp_cmdsn - 1)) in __iscsi_update_cmdsn()
118 if (exp_cmdsn != session->exp_cmdsn && in __iscsi_update_cmdsn()
119 !iscsi_sna_lt(exp_cmdsn, session->exp_cmdsn)) in __iscsi_update_cmdsn()
120 session->exp_cmdsn = exp_cmdsn; in __iscsi_update_cmdsn()
122 if (max_cmdsn != session->max_cmdsn && in __iscsi_update_cmdsn()
123 !iscsi_sna_lt(max_cmdsn, session->max_cmdsn)) in __iscsi_update_cmdsn()
124 session->max_cmdsn = max_cmdsn; in __iscsi_update_cmdsn()
129 __iscsi_update_cmdsn(session, be32_to_cpu(hdr->exp_cmdsn), in iscsi_update_cmdsn()
130 be32_to_cpu(hdr->max_cmdsn)); in iscsi_update_cmdsn()
135 * iscsi_prep_data_out_pdu - initialize Data-Out
141 * Initialize Data-Out within this R2T sequence and finds
149 struct iscsi_conn *conn = task->conn; in iscsi_prep_data_out_pdu()
150 unsigned int left = r2t->data_length - r2t->sent; in iscsi_prep_data_out_pdu()
152 task->hdr_len = sizeof(struct iscsi_data); in iscsi_prep_data_out_pdu()
155 hdr->ttt = r2t->ttt; in iscsi_prep_data_out_pdu()
156 hdr->datasn = cpu_to_be32(r2t->datasn); in iscsi_prep_data_out_pdu()
157 r2t->datasn++; in iscsi_prep_data_out_pdu()
158 hdr->opcode = ISCSI_OP_SCSI_DATA_OUT; in iscsi_prep_data_out_pdu()
159 hdr->lun = task->lun; in iscsi_prep_data_out_pdu()
160 hdr->itt = task->hdr_itt; in iscsi_prep_data_out_pdu()
161 hdr->exp_statsn = r2t->exp_statsn; in iscsi_prep_data_out_pdu()
162 hdr->offset = cpu_to_be32(r2t->data_offset + r2t->sent); in iscsi_prep_data_out_pdu()
163 if (left > conn->max_xmit_dlength) { in iscsi_prep_data_out_pdu()
164 hton24(hdr->dlength, conn->max_xmit_dlength); in iscsi_prep_data_out_pdu()
165 r2t->data_count = conn->max_xmit_dlength; in iscsi_prep_data_out_pdu()
166 hdr->flags = 0; in iscsi_prep_data_out_pdu()
168 hton24(hdr->dlength, left); in iscsi_prep_data_out_pdu()
169 r2t->data_count = left; in iscsi_prep_data_out_pdu()
170 hdr->flags = ISCSI_FLAG_CMD_FINAL; in iscsi_prep_data_out_pdu()
172 conn->dataout_pdus_cnt++; in iscsi_prep_data_out_pdu()
178 unsigned exp_len = task->hdr_len + len; in iscsi_add_hdr()
180 if (exp_len > task->hdr_max) { in iscsi_add_hdr()
182 return -EINVAL; in iscsi_add_hdr()
185 WARN_ON(len & (ISCSI_PAD_LEN - 1)); /* caller must pad the AHS */ in iscsi_add_hdr()
186 task->hdr_len = exp_len; in iscsi_add_hdr()
195 struct scsi_cmnd *cmd = task->sc; in iscsi_prep_ecdb_ahs()
202 rlen = cmd->cmd_len - ISCSI_CDB_SIZE; in iscsi_prep_ecdb_ahs()
204 BUG_ON(rlen > sizeof(ecdb_ahdr->ecdb)); in iscsi_prep_ecdb_ahs()
205 ahslength = rlen + sizeof(ecdb_ahdr->reserved); in iscsi_prep_ecdb_ahs()
209 rc = iscsi_add_hdr(task, sizeof(ecdb_ahdr->ahslength) + in iscsi_prep_ecdb_ahs()
210 sizeof(ecdb_ahdr->ahstype) + ahslength + pad_len); in iscsi_prep_ecdb_ahs()
215 memset(&ecdb_ahdr->ecdb[rlen], 0, pad_len); in iscsi_prep_ecdb_ahs()
217 ecdb_ahdr->ahslength = cpu_to_be16(ahslength); in iscsi_prep_ecdb_ahs()
218 ecdb_ahdr->ahstype = ISCSI_AHSTYPE_CDB; in iscsi_prep_ecdb_ahs()
219 ecdb_ahdr->reserved = 0; in iscsi_prep_ecdb_ahs()
220 memcpy(ecdb_ahdr->ecdb, cmd->cmnd + ISCSI_CDB_SIZE, rlen); in iscsi_prep_ecdb_ahs()
222 ISCSI_DBG_SESSION(task->conn->session, in iscsi_prep_ecdb_ahs()
225 "%u\n", cmd->cmd_len, rlen, pad_len, ahslength, in iscsi_prep_ecdb_ahs()
226 task->hdr_len); in iscsi_prep_ecdb_ahs()
231 * iscsi_check_tmf_restrictions - check if a task is affected by TMF
241 * so we have to send all outstanding Data-Out PDUs to the target.
245 struct iscsi_session *session = task->conn->session; in iscsi_check_tmf_restrictions()
246 struct iscsi_tm *tmf = &session->tmhdr; in iscsi_check_tmf_restrictions()
249 if (session->tmf_state == TMF_INITIAL) in iscsi_check_tmf_restrictions()
252 if ((tmf->opcode & ISCSI_OPCODE_MASK) != ISCSI_OP_SCSI_TMFUNC) in iscsi_check_tmf_restrictions()
260 hdr_lun = scsilun_to_int(&tmf->lun); in iscsi_check_tmf_restrictions()
261 if (hdr_lun != task->sc->device->lun) in iscsi_check_tmf_restrictions()
271 opcode, task->itt, task->hdr_itt); in iscsi_check_tmf_restrictions()
272 return -EACCES; in iscsi_check_tmf_restrictions()
275 * And also all data-out PDUs in response to R2T in iscsi_check_tmf_restrictions()
278 if (session->fast_abort) { in iscsi_check_tmf_restrictions()
281 opcode, task->itt, task->hdr_itt); in iscsi_check_tmf_restrictions()
282 return -EACCES; in iscsi_check_tmf_restrictions()
290 * we will only hit this for data-outs in iscsi_check_tmf_restrictions()
293 task->hdr_itt == tmf->rtt) { in iscsi_check_tmf_restrictions()
296 "data-out due to abort task in " in iscsi_check_tmf_restrictions()
297 "progress\n", task->itt, in iscsi_check_tmf_restrictions()
298 task->hdr_itt); in iscsi_check_tmf_restrictions()
299 return -EACCES; in iscsi_check_tmf_restrictions()
308 * iscsi_prep_scsi_cmd_pdu - prep iscsi scsi cmd pdu
316 struct iscsi_conn *conn = task->conn; in iscsi_prep_scsi_cmd_pdu()
317 struct iscsi_session *session = conn->session; in iscsi_prep_scsi_cmd_pdu()
318 struct scsi_cmnd *sc = task->sc; in iscsi_prep_scsi_cmd_pdu()
328 if (conn->session->tt->alloc_pdu) { in iscsi_prep_scsi_cmd_pdu()
329 rc = conn->session->tt->alloc_pdu(task, ISCSI_OP_SCSI_CMD); in iscsi_prep_scsi_cmd_pdu()
333 hdr = (struct iscsi_scsi_req *)task->hdr; in iscsi_prep_scsi_cmd_pdu()
334 itt = hdr->itt; in iscsi_prep_scsi_cmd_pdu()
337 if (session->tt->parse_pdu_itt) in iscsi_prep_scsi_cmd_pdu()
338 hdr->itt = task->hdr_itt = itt; in iscsi_prep_scsi_cmd_pdu()
340 hdr->itt = task->hdr_itt = build_itt(task->itt, in iscsi_prep_scsi_cmd_pdu()
341 task->conn->session->age); in iscsi_prep_scsi_cmd_pdu()
342 task->hdr_len = 0; in iscsi_prep_scsi_cmd_pdu()
346 hdr->opcode = ISCSI_OP_SCSI_CMD; in iscsi_prep_scsi_cmd_pdu()
347 hdr->flags = ISCSI_ATTR_SIMPLE; in iscsi_prep_scsi_cmd_pdu()
348 int_to_scsilun(sc->device->lun, &hdr->lun); in iscsi_prep_scsi_cmd_pdu()
349 task->lun = hdr->lun; in iscsi_prep_scsi_cmd_pdu()
350 hdr->exp_statsn = cpu_to_be32(conn->exp_statsn); in iscsi_prep_scsi_cmd_pdu()
351 cmd_len = sc->cmd_len; in iscsi_prep_scsi_cmd_pdu()
353 memset(&hdr->cdb[cmd_len], 0, ISCSI_CDB_SIZE - cmd_len); in iscsi_prep_scsi_cmd_pdu()
360 memcpy(hdr->cdb, sc->cmnd, cmd_len); in iscsi_prep_scsi_cmd_pdu()
362 task->imm_count = 0; in iscsi_prep_scsi_cmd_pdu()
364 task->protected = true; in iscsi_prep_scsi_cmd_pdu()
367 hdr->data_length = cpu_to_be32(transfer_length); in iscsi_prep_scsi_cmd_pdu()
368 if (sc->sc_data_direction == DMA_TO_DEVICE) { in iscsi_prep_scsi_cmd_pdu()
369 struct iscsi_r2t_info *r2t = &task->unsol_r2t; in iscsi_prep_scsi_cmd_pdu()
371 hdr->flags |= ISCSI_FLAG_CMD_WRITE; in iscsi_prep_scsi_cmd_pdu()
378 * unsol_count bytes(as Data-Out) to be sent in iscsi_prep_scsi_cmd_pdu()
384 * pad_count bytes to be sent as zero-padding in iscsi_prep_scsi_cmd_pdu()
388 if (session->imm_data_en) { in iscsi_prep_scsi_cmd_pdu()
389 if (transfer_length >= session->first_burst) in iscsi_prep_scsi_cmd_pdu()
390 task->imm_count = min(session->first_burst, in iscsi_prep_scsi_cmd_pdu()
391 conn->max_xmit_dlength); in iscsi_prep_scsi_cmd_pdu()
393 task->imm_count = min(transfer_length, in iscsi_prep_scsi_cmd_pdu()
394 conn->max_xmit_dlength); in iscsi_prep_scsi_cmd_pdu()
395 hton24(hdr->dlength, task->imm_count); in iscsi_prep_scsi_cmd_pdu()
397 zero_data(hdr->dlength); in iscsi_prep_scsi_cmd_pdu()
399 if (!session->initial_r2t_en) { in iscsi_prep_scsi_cmd_pdu()
400 r2t->data_length = min(session->first_burst, in iscsi_prep_scsi_cmd_pdu()
401 transfer_length) - in iscsi_prep_scsi_cmd_pdu()
402 task->imm_count; in iscsi_prep_scsi_cmd_pdu()
403 r2t->data_offset = task->imm_count; in iscsi_prep_scsi_cmd_pdu()
404 r2t->ttt = cpu_to_be32(ISCSI_RESERVED_TAG); in iscsi_prep_scsi_cmd_pdu()
405 r2t->exp_statsn = cpu_to_be32(conn->exp_statsn); in iscsi_prep_scsi_cmd_pdu()
408 if (!task->unsol_r2t.data_length) in iscsi_prep_scsi_cmd_pdu()
409 /* No unsolicit Data-Out's */ in iscsi_prep_scsi_cmd_pdu()
410 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsi_prep_scsi_cmd_pdu()
412 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsi_prep_scsi_cmd_pdu()
413 zero_data(hdr->dlength); in iscsi_prep_scsi_cmd_pdu()
415 if (sc->sc_data_direction == DMA_FROM_DEVICE) in iscsi_prep_scsi_cmd_pdu()
416 hdr->flags |= ISCSI_FLAG_CMD_READ; in iscsi_prep_scsi_cmd_pdu()
420 hdrlength = task->hdr_len - sizeof(*hdr); in iscsi_prep_scsi_cmd_pdu()
422 WARN_ON(hdrlength & (ISCSI_PAD_LEN-1)); in iscsi_prep_scsi_cmd_pdu()
426 hdr->hlength = hdrlength & 0xFF; in iscsi_prep_scsi_cmd_pdu()
427 hdr->cmdsn = task->cmdsn = cpu_to_be32(session->cmdsn); in iscsi_prep_scsi_cmd_pdu()
429 if (session->tt->init_task && session->tt->init_task(task)) in iscsi_prep_scsi_cmd_pdu()
430 return -EIO; in iscsi_prep_scsi_cmd_pdu()
432 task->state = ISCSI_TASK_RUNNING; in iscsi_prep_scsi_cmd_pdu()
433 session->cmdsn++; in iscsi_prep_scsi_cmd_pdu()
435 conn->scsicmd_pdus_cnt++; in iscsi_prep_scsi_cmd_pdu()
438 sc->sc_data_direction == DMA_TO_DEVICE ? in iscsi_prep_scsi_cmd_pdu()
439 "write" : "read", conn->id, sc, sc->cmnd[0], in iscsi_prep_scsi_cmd_pdu()
440 task->itt, transfer_length, in iscsi_prep_scsi_cmd_pdu()
441 session->cmdsn, in iscsi_prep_scsi_cmd_pdu()
442 session->max_cmdsn - session->exp_cmdsn + 1); in iscsi_prep_scsi_cmd_pdu()
447 * iscsi_free_task - free a task
451 * This function returns the scsi command to scsi-ml or cleans
456 struct iscsi_conn *conn = task->conn; in iscsi_free_task()
457 struct iscsi_session *session = conn->session; in iscsi_free_task()
458 struct scsi_cmnd *sc = task->sc; in iscsi_free_task()
459 int oldstate = task->state; in iscsi_free_task()
462 task->itt, task->state, task->sc); in iscsi_free_task()
464 session->tt->cleanup_task(task); in iscsi_free_task()
465 task->state = ISCSI_TASK_FREE; in iscsi_free_task()
466 task->sc = NULL; in iscsi_free_task()
470 if (conn->login_task == task) in iscsi_free_task()
473 kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*)); in iscsi_free_task()
477 iscsi_cmd(sc)->task = NULL; in iscsi_free_task()
480 * it will decide how to return sc to scsi-ml. in iscsi_free_task()
489 return refcount_inc_not_zero(&task->refcount); in iscsi_get_task()
494 * __iscsi_put_task - drop the refcount on a task
501 if (refcount_dec_and_test(&task->refcount)) in __iscsi_put_task()
508 struct iscsi_session *session = task->conn->session; in iscsi_put_task()
510 if (refcount_dec_and_test(&task->refcount)) { in iscsi_put_task()
511 spin_lock_bh(&session->back_lock); in iscsi_put_task()
513 spin_unlock_bh(&session->back_lock); in iscsi_put_task()
519 * iscsi_complete_task - finish a task
527 struct iscsi_conn *conn = task->conn; in iscsi_complete_task()
529 ISCSI_DBG_SESSION(conn->session, in iscsi_complete_task()
531 task->itt, task->state, task->sc); in iscsi_complete_task()
532 if (task->state == ISCSI_TASK_COMPLETED || in iscsi_complete_task()
533 task->state == ISCSI_TASK_ABRT_TMF || in iscsi_complete_task()
534 task->state == ISCSI_TASK_ABRT_SESS_RECOV || in iscsi_complete_task()
535 task->state == ISCSI_TASK_REQUEUE_SCSIQ) in iscsi_complete_task()
537 WARN_ON_ONCE(task->state == ISCSI_TASK_FREE); in iscsi_complete_task()
538 task->state = state; in iscsi_complete_task()
540 if (READ_ONCE(conn->ping_task) == task) in iscsi_complete_task()
541 WRITE_ONCE(conn->ping_task, NULL); in iscsi_complete_task()
548 * iscsi_complete_scsi_task - finish scsi task normally
551 * @max_cmdsn: max cmd sn in cpu format
561 struct iscsi_conn *conn = task->conn; in iscsi_complete_scsi_task()
563 ISCSI_DBG_SESSION(conn->session, "[itt 0x%x]\n", task->itt); in iscsi_complete_scsi_task()
565 conn->last_recv = jiffies; in iscsi_complete_scsi_task()
566 __iscsi_update_cmdsn(conn->session, exp_cmdsn, max_cmdsn); in iscsi_complete_scsi_task()
576 struct iscsi_conn *conn = task->conn; in cleanup_queued_task()
584 if (task->state == ISCSI_TASK_COMPLETED) in cleanup_queued_task()
587 if (!list_empty(&task->running)) { in cleanup_queued_task()
588 list_del_init(&task->running); in cleanup_queued_task()
593 if (task->state == ISCSI_TASK_RUNNING || in cleanup_queued_task()
594 task->state == ISCSI_TASK_COMPLETED) in cleanup_queued_task()
598 if (conn->session->running_aborted_task == task) { in cleanup_queued_task()
599 conn->session->running_aborted_task = NULL; in cleanup_queued_task()
603 if (conn->task == task) { in cleanup_queued_task()
604 conn->task = NULL; in cleanup_queued_task()
617 struct iscsi_conn *conn = task->conn; in __fail_scsi_task()
624 if (task->state == ISCSI_TASK_PENDING) { in __fail_scsi_task()
629 conn->session->queued_cmdsn--; in __fail_scsi_task()
637 sc = task->sc; in __fail_scsi_task()
638 sc->result = err << 16; in __fail_scsi_task()
645 struct iscsi_session *session = task->conn->session; in fail_scsi_task()
647 spin_lock_bh(&session->back_lock); in fail_scsi_task()
649 spin_unlock_bh(&session->back_lock); in fail_scsi_task()
655 struct iscsi_session *session = conn->session; in iscsi_prep_mgmt_task()
656 struct iscsi_hdr *hdr = task->hdr; in iscsi_prep_mgmt_task()
658 uint8_t opcode = hdr->opcode & ISCSI_OPCODE_MASK; in iscsi_prep_mgmt_task()
660 if (conn->session->state == ISCSI_STATE_LOGGING_OUT) in iscsi_prep_mgmt_task()
661 return -ENOTCONN; in iscsi_prep_mgmt_task()
664 nop->exp_statsn = cpu_to_be32(conn->exp_statsn); in iscsi_prep_mgmt_task()
666 * pre-format CmdSN for outgoing PDU. in iscsi_prep_mgmt_task()
668 nop->cmdsn = cpu_to_be32(session->cmdsn); in iscsi_prep_mgmt_task()
669 if (hdr->itt != RESERVED_ITT) { in iscsi_prep_mgmt_task()
672 * If we start to send tmfs or nops as non-immediate then in iscsi_prep_mgmt_task()
678 if (conn->c_stage == ISCSI_CONN_STARTED && in iscsi_prep_mgmt_task()
679 !(hdr->opcode & ISCSI_OP_IMMEDIATE)) { in iscsi_prep_mgmt_task()
680 session->queued_cmdsn++; in iscsi_prep_mgmt_task()
681 session->cmdsn++; in iscsi_prep_mgmt_task()
685 if (session->tt->init_task && session->tt->init_task(task)) in iscsi_prep_mgmt_task()
686 return -EIO; in iscsi_prep_mgmt_task()
688 if ((hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) in iscsi_prep_mgmt_task()
689 session->state = ISCSI_STATE_LOGGING_OUT; in iscsi_prep_mgmt_task()
691 task->state = ISCSI_TASK_RUNNING; in iscsi_prep_mgmt_task()
692 ISCSI_DBG_SESSION(session, "mgmtpdu [op 0x%x hdr->itt 0x%x " in iscsi_prep_mgmt_task()
693 "datalen %d]\n", hdr->opcode & ISCSI_OPCODE_MASK, in iscsi_prep_mgmt_task()
694 hdr->itt, task->data_count); in iscsi_prep_mgmt_task()
699 * iscsi_alloc_mgmt_task - allocate and setup a mgmt task.
709 struct iscsi_session *session = conn->session; in iscsi_alloc_mgmt_task()
710 uint8_t opcode = hdr->opcode & ISCSI_OPCODE_MASK; in iscsi_alloc_mgmt_task()
714 if (session->state == ISCSI_STATE_TERMINATE || in iscsi_alloc_mgmt_task()
715 !test_bit(ISCSI_CONN_FLAG_BOUND, &conn->flags)) in iscsi_alloc_mgmt_task()
721 * request-followed-by-response sequence. in iscsi_alloc_mgmt_task()
725 if (conn->login_task->state != ISCSI_TASK_FREE) { in iscsi_alloc_mgmt_task()
732 …iscsi_conn_printk(KERN_ERR, conn, "Invalid buffer len of %u for login task. Max len is %u\n", data… in iscsi_alloc_mgmt_task()
736 task = conn->login_task; in iscsi_alloc_mgmt_task()
738 if (session->state != ISCSI_STATE_LOGGED_IN) in iscsi_alloc_mgmt_task()
746 BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE); in iscsi_alloc_mgmt_task()
747 BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED); in iscsi_alloc_mgmt_task()
749 if (!kfifo_out(&session->cmdpool.queue, in iscsi_alloc_mgmt_task()
758 refcount_set(&task->refcount, 1); in iscsi_alloc_mgmt_task()
759 task->conn = conn; in iscsi_alloc_mgmt_task()
760 task->sc = NULL; in iscsi_alloc_mgmt_task()
761 INIT_LIST_HEAD(&task->running); in iscsi_alloc_mgmt_task()
762 task->state = ISCSI_TASK_PENDING; in iscsi_alloc_mgmt_task()
765 memcpy(task->data, data, data_size); in iscsi_alloc_mgmt_task()
766 task->data_count = data_size; in iscsi_alloc_mgmt_task()
768 task->data_count = 0; in iscsi_alloc_mgmt_task()
770 if (conn->session->tt->alloc_pdu) { in iscsi_alloc_mgmt_task()
771 if (conn->session->tt->alloc_pdu(task, hdr->opcode)) { in iscsi_alloc_mgmt_task()
778 itt = task->hdr->itt; in iscsi_alloc_mgmt_task()
779 task->hdr_len = sizeof(struct iscsi_hdr); in iscsi_alloc_mgmt_task()
780 memcpy(task->hdr, hdr, sizeof(struct iscsi_hdr)); in iscsi_alloc_mgmt_task()
782 if (hdr->itt != RESERVED_ITT) { in iscsi_alloc_mgmt_task()
783 if (session->tt->parse_pdu_itt) in iscsi_alloc_mgmt_task()
784 task->hdr->itt = itt; in iscsi_alloc_mgmt_task()
786 task->hdr->itt = build_itt(task->itt, in iscsi_alloc_mgmt_task()
787 task->conn->session->age); in iscsi_alloc_mgmt_task()
798 * iscsi_send_mgmt_task - Send task created with iscsi_alloc_mgmt_task.
801 * On failure this returns a non-zero error code, and the driver must free
806 struct iscsi_conn *conn = task->conn; in iscsi_send_mgmt_task()
807 struct iscsi_session *session = conn->session; in iscsi_send_mgmt_task()
808 struct iscsi_host *ihost = shost_priv(conn->session->host); in iscsi_send_mgmt_task()
811 if (!ihost->workq) { in iscsi_send_mgmt_task()
816 rc = session->tt->xmit_task(task); in iscsi_send_mgmt_task()
820 list_add_tail(&task->running, &conn->mgmtqueue); in iscsi_send_mgmt_task()
835 return -ENOMEM; in __iscsi_conn_send_pdu()
846 struct iscsi_conn *conn = cls_conn->dd_data; in iscsi_conn_send_pdu()
847 struct iscsi_session *session = conn->session; in iscsi_conn_send_pdu()
850 spin_lock_bh(&session->frwd_lock); in iscsi_conn_send_pdu()
852 err = -EPERM; in iscsi_conn_send_pdu()
853 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_send_pdu()
859 * iscsi_scsi_cmd_rsp - SCSI Command Response processing
874 struct iscsi_session *session = conn->session; in iscsi_scsi_cmd_rsp()
875 struct scsi_cmnd *sc = task->sc; in iscsi_scsi_cmd_rsp()
878 conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1; in iscsi_scsi_cmd_rsp()
880 sc->result = (DID_OK << 16) | rhdr->cmd_status; in iscsi_scsi_cmd_rsp()
882 if (task->protected) { in iscsi_scsi_cmd_rsp()
888 * callback but still published T10-PI support to scsi-mid in iscsi_scsi_cmd_rsp()
891 BUG_ON(!session->tt->check_protection); in iscsi_scsi_cmd_rsp()
893 ascq = session->tt->check_protection(task, &sector); in iscsi_scsi_cmd_rsp()
896 scsi_set_sense_information(sc->sense_buffer, in iscsi_scsi_cmd_rsp()
903 if (rhdr->response != ISCSI_STATUS_CMD_COMPLETED) { in iscsi_scsi_cmd_rsp()
904 sc->result = DID_ERROR << 16; in iscsi_scsi_cmd_rsp()
908 if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) { in iscsi_scsi_cmd_rsp()
916 sc->result = DID_BAD_TARGET << 16; in iscsi_scsi_cmd_rsp()
924 memcpy(sc->sense_buffer, data + 2, in iscsi_scsi_cmd_rsp()
931 if (rhdr->flags & (ISCSI_FLAG_CMD_BIDI_UNDERFLOW | in iscsi_scsi_cmd_rsp()
933 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status; in iscsi_scsi_cmd_rsp()
936 if (rhdr->flags & (ISCSI_FLAG_CMD_UNDERFLOW | in iscsi_scsi_cmd_rsp()
938 int res_count = be32_to_cpu(rhdr->residual_count); in iscsi_scsi_cmd_rsp()
941 (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW || in iscsi_scsi_cmd_rsp()
943 /* write side for bidi or uni-io set_resid */ in iscsi_scsi_cmd_rsp()
946 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status; in iscsi_scsi_cmd_rsp()
950 sc, sc->result, task->itt); in iscsi_scsi_cmd_rsp()
951 conn->scsirsp_pdus_cnt++; in iscsi_scsi_cmd_rsp()
956 * iscsi_data_in_rsp - SCSI Data-In Response processing
969 struct scsi_cmnd *sc = task->sc; in iscsi_data_in_rsp()
971 if (!(rhdr->flags & ISCSI_FLAG_DATA_STATUS)) in iscsi_data_in_rsp()
974 iscsi_update_cmdsn(conn->session, (struct iscsi_nopin *)hdr); in iscsi_data_in_rsp()
975 sc->result = (DID_OK << 16) | rhdr->cmd_status; in iscsi_data_in_rsp()
976 conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1; in iscsi_data_in_rsp()
977 if (rhdr->flags & (ISCSI_FLAG_DATA_UNDERFLOW | in iscsi_data_in_rsp()
979 int res_count = be32_to_cpu(rhdr->residual_count); in iscsi_data_in_rsp()
982 (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW || in iscsi_data_in_rsp()
983 res_count <= sc->sdb.length)) in iscsi_data_in_rsp()
986 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status; in iscsi_data_in_rsp()
989 ISCSI_DBG_SESSION(conn->session, "data in with status done " in iscsi_data_in_rsp()
991 sc, sc->result, task->itt); in iscsi_data_in_rsp()
992 conn->scsirsp_pdus_cnt++; in iscsi_data_in_rsp()
999 struct iscsi_session *session = conn->session; in iscsi_tmf_rsp()
1001 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1; in iscsi_tmf_rsp()
1002 conn->tmfrsp_pdus_cnt++; in iscsi_tmf_rsp()
1004 if (session->tmf_state != TMF_QUEUED) in iscsi_tmf_rsp()
1007 if (tmf->response == ISCSI_TMF_RSP_COMPLETE) in iscsi_tmf_rsp()
1008 session->tmf_state = TMF_SUCCESS; in iscsi_tmf_rsp()
1009 else if (tmf->response == ISCSI_TMF_RSP_NO_TASK) in iscsi_tmf_rsp()
1010 session->tmf_state = TMF_NOT_FOUND; in iscsi_tmf_rsp()
1012 session->tmf_state = TMF_FAILED; in iscsi_tmf_rsp()
1013 wake_up(&session->ehwait); in iscsi_tmf_rsp()
1022 if (READ_ONCE(conn->ping_task)) in iscsi_send_nopout()
1023 return -EINVAL; in iscsi_send_nopout()
1031 hdr.lun = rhdr->lun; in iscsi_send_nopout()
1032 hdr.ttt = rhdr->ttt; in iscsi_send_nopout()
1039 return -ENOMEM; in iscsi_send_nopout()
1042 WRITE_ONCE(conn->ping_task, task); in iscsi_send_nopout()
1046 WRITE_ONCE(conn->ping_task, NULL); in iscsi_send_nopout()
1050 return -EIO; in iscsi_send_nopout()
1053 conn->last_ping = jiffies; in iscsi_send_nopout()
1060 * iscsi_nop_out_rsp - SCSI NOP Response processing
1072 struct iscsi_conn *conn = task->conn; in iscsi_nop_out_rsp()
1075 if (READ_ONCE(conn->ping_task) != task) { in iscsi_nop_out_rsp()
1080 if (iscsi_recv_pdu(conn->cls_conn, (struct iscsi_hdr *)nop, in iscsi_nop_out_rsp()
1084 mod_timer(&conn->transport_timer, jiffies + conn->recv_timeout); in iscsi_nop_out_rsp()
1096 conn->exp_statsn = be32_to_cpu(reject->statsn) + 1; in iscsi_handle_reject()
1098 if (ntoh24(reject->dlength) > datalen || in iscsi_handle_reject()
1099 ntoh24(reject->dlength) < sizeof(struct iscsi_hdr)) { in iscsi_handle_reject()
1102 "%u, datalen %d\n", ntoh24(reject->dlength), in iscsi_handle_reject()
1109 switch (reject->reason) { in iscsi_handle_reject()
1126 * For nops-outs, we could have sent more than one if in iscsi_handle_reject()
1127 * the target is sending us lots of nop-ins in iscsi_handle_reject()
1134 * nop-out in response to target's nop-out rejected. in iscsi_handle_reject()
1138 spin_unlock(&conn->session->back_lock); in iscsi_handle_reject()
1139 spin_lock(&conn->session->frwd_lock); in iscsi_handle_reject()
1142 spin_unlock(&conn->session->frwd_lock); in iscsi_handle_reject()
1143 spin_lock(&conn->session->back_lock); in iscsi_handle_reject()
1164 "pdu (op 0x%x itt 0x%x) rejected. Reason " in iscsi_handle_reject()
1166 rejected_pdu.itt, reject->reason); in iscsi_handle_reject()
1173 * iscsi_itt_to_task - look up task by itt
1184 struct iscsi_session *session = conn->session; in iscsi_itt_to_task()
1190 if (session->tt->parse_pdu_itt) in iscsi_itt_to_task()
1191 session->tt->parse_pdu_itt(conn, itt, &i, NULL); in iscsi_itt_to_task()
1194 if (i >= session->cmds_max) in iscsi_itt_to_task()
1197 return session->cmds[i]; in iscsi_itt_to_task()
1202 * __iscsi_complete_pdu - complete pdu
1215 struct iscsi_session *session = conn->session; in __iscsi_complete_pdu()
1216 int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0; in __iscsi_complete_pdu()
1220 conn->last_recv = jiffies; in __iscsi_complete_pdu()
1221 rc = iscsi_verify_itt(conn, hdr->itt); in __iscsi_complete_pdu()
1225 if (hdr->itt != RESERVED_ITT) in __iscsi_complete_pdu()
1226 itt = get_itt(hdr->itt); in __iscsi_complete_pdu()
1231 opcode, conn->id, itt, datalen); in __iscsi_complete_pdu()
1243 if (hdr->ttt == cpu_to_be32(ISCSI_RESERVED_TAG)) in __iscsi_complete_pdu()
1247 spin_unlock(&session->back_lock); in __iscsi_complete_pdu()
1248 spin_lock(&session->frwd_lock); in __iscsi_complete_pdu()
1250 spin_unlock(&session->frwd_lock); in __iscsi_complete_pdu()
1251 spin_lock(&session->back_lock); in __iscsi_complete_pdu()
1257 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1; in __iscsi_complete_pdu()
1258 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen)) in __iscsi_complete_pdu()
1271 task = iscsi_itt_to_ctask(conn, hdr->itt); in __iscsi_complete_pdu()
1274 task->last_xfer = jiffies; in __iscsi_complete_pdu()
1286 task = iscsi_itt_to_task(conn, hdr->itt); in __iscsi_complete_pdu()
1307 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1; in __iscsi_complete_pdu()
1329 if (hdr->ttt != cpu_to_be32(ISCSI_RESERVED_TAG) || datalen) { in __iscsi_complete_pdu()
1333 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1; in __iscsi_complete_pdu()
1346 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen)) in __iscsi_complete_pdu()
1358 spin_lock(&conn->session->back_lock); in iscsi_complete_pdu()
1360 spin_unlock(&conn->session->back_lock); in iscsi_complete_pdu()
1367 struct iscsi_session *session = conn->session; in iscsi_verify_itt()
1373 if (session->tt->parse_pdu_itt) in iscsi_verify_itt()
1374 session->tt->parse_pdu_itt(conn, itt, &i, &age); in iscsi_verify_itt()
1380 if (age != session->age) { in iscsi_verify_itt()
1383 (__force u32)itt, session->age); in iscsi_verify_itt()
1387 if (i >= session->cmds_max) { in iscsi_verify_itt()
1389 "received invalid itt index %u (max cmds " in iscsi_verify_itt()
1390 "%u.\n", i, session->cmds_max); in iscsi_verify_itt()
1398 * iscsi_itt_to_ctask - look up ctask by itt
1414 if (!task || !task->sc) in iscsi_itt_to_ctask()
1417 if (iscsi_cmd(task->sc)->age != conn->session->age) { in iscsi_itt_to_ctask()
1418 iscsi_session_printk(KERN_ERR, conn->session, in iscsi_itt_to_ctask()
1420 iscsi_cmd(task->sc)->age, conn->session->age); in iscsi_itt_to_ctask()
1433 spin_lock_bh(&session->frwd_lock); in iscsi_session_failure()
1434 conn = session->leadconn; in iscsi_session_failure()
1435 if (session->state == ISCSI_STATE_TERMINATE || !conn) { in iscsi_session_failure()
1436 spin_unlock_bh(&session->frwd_lock); in iscsi_session_failure()
1440 iscsi_get_conn(conn->cls_conn); in iscsi_session_failure()
1441 spin_unlock_bh(&session->frwd_lock); in iscsi_session_failure()
1448 iscsi_conn_error_event(conn->cls_conn, err); in iscsi_session_failure()
1451 iscsi_put_conn(conn->cls_conn); in iscsi_session_failure()
1457 struct iscsi_session *session = conn->session; in iscsi_set_conn_failed()
1459 if (session->state == ISCSI_STATE_FAILED) in iscsi_set_conn_failed()
1462 if (conn->stop_stage == 0) in iscsi_set_conn_failed()
1463 session->state = ISCSI_STATE_FAILED; in iscsi_set_conn_failed()
1465 set_bit(ISCSI_CONN_FLAG_SUSPEND_TX, &conn->flags); in iscsi_set_conn_failed()
1466 set_bit(ISCSI_CONN_FLAG_SUSPEND_RX, &conn->flags); in iscsi_set_conn_failed()
1472 struct iscsi_session *session = conn->session; in iscsi_conn_failure()
1475 spin_lock_bh(&session->frwd_lock); in iscsi_conn_failure()
1477 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_failure()
1480 iscsi_conn_error_event(conn->cls_conn, err); in iscsi_conn_failure()
1486 struct iscsi_session *session = conn->session; in iscsi_check_cmdsn_window_closed()
1489 * Check for iSCSI window and take care of CmdSN wrap-around in iscsi_check_cmdsn_window_closed()
1491 if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) { in iscsi_check_cmdsn_window_closed()
1494 session->exp_cmdsn, session->max_cmdsn, in iscsi_check_cmdsn_window_closed()
1495 session->cmdsn, session->queued_cmdsn); in iscsi_check_cmdsn_window_closed()
1496 return -ENOSPC; in iscsi_check_cmdsn_window_closed()
1506 if (!conn->task) { in iscsi_xmit_task()
1519 conn->task = NULL; in iscsi_xmit_task()
1533 if (test_bit(ISCSI_CONN_FLAG_SUSPEND_TX, &conn->flags)) { in iscsi_xmit_task()
1538 conn->task = task; in iscsi_xmit_task()
1539 return -ENODATA; in iscsi_xmit_task()
1542 spin_unlock_bh(&conn->session->frwd_lock); in iscsi_xmit_task()
1543 rc = conn->session->tt->xmit_task(task); in iscsi_xmit_task()
1544 spin_lock_bh(&conn->session->frwd_lock); in iscsi_xmit_task()
1547 task->last_xfer = jiffies; in iscsi_xmit_task()
1551 * as conn->task above. in iscsi_xmit_task()
1554 conn->task = task; in iscsi_xmit_task()
1562 * iscsi_requeue_task - requeue task to run from session workqueue
1569 struct iscsi_conn *conn = task->conn; in iscsi_requeue_task()
1575 spin_lock_bh(&conn->session->frwd_lock); in iscsi_requeue_task()
1576 if (list_empty(&task->running)) { in iscsi_requeue_task()
1577 list_add_tail(&task->running, &conn->requeue); in iscsi_requeue_task()
1586 spin_unlock_bh(&conn->session->frwd_lock); in iscsi_requeue_task()
1591 * iscsi_data_xmit - xmit any command into the scheduled connection
1595 * The function can return -EAGAIN in which case the caller must
1596 * re-schedule it again later or recover. '0' return code means
1604 spin_lock_bh(&conn->session->frwd_lock); in iscsi_data_xmit()
1605 if (test_bit(ISCSI_CONN_FLAG_SUSPEND_TX, &conn->flags)) { in iscsi_data_xmit()
1606 ISCSI_DBG_SESSION(conn->session, "Tx suspended!\n"); in iscsi_data_xmit()
1607 spin_unlock_bh(&conn->session->frwd_lock); in iscsi_data_xmit()
1608 return -ENODATA; in iscsi_data_xmit()
1611 if (conn->task) { in iscsi_data_xmit()
1612 rc = iscsi_xmit_task(conn, conn->task, false); in iscsi_data_xmit()
1619 * only have one nop-out as a ping from us and targets should not in iscsi_data_xmit()
1620 * overflow us with nop-ins in iscsi_data_xmit()
1623 while (!list_empty(&conn->mgmtqueue)) { in iscsi_data_xmit()
1624 task = list_entry(conn->mgmtqueue.next, struct iscsi_task, in iscsi_data_xmit()
1626 list_del_init(&task->running); in iscsi_data_xmit()
1629 spin_lock_bh(&conn->session->back_lock); in iscsi_data_xmit()
1631 spin_unlock_bh(&conn->session->back_lock); in iscsi_data_xmit()
1640 while (!list_empty(&conn->requeue)) { in iscsi_data_xmit()
1642 * we always do fastlogout - conn stop code will clean up. in iscsi_data_xmit()
1644 if (conn->session->state == ISCSI_STATE_LOGGING_OUT) in iscsi_data_xmit()
1647 task = list_entry(conn->requeue.next, struct iscsi_task, in iscsi_data_xmit()
1653 list_del_init(&task->running); in iscsi_data_xmit()
1657 if (!list_empty(&conn->mgmtqueue)) in iscsi_data_xmit()
1662 while (!list_empty(&conn->cmdqueue)) { in iscsi_data_xmit()
1663 task = list_entry(conn->cmdqueue.next, struct iscsi_task, in iscsi_data_xmit()
1665 list_del_init(&task->running); in iscsi_data_xmit()
1666 if (conn->session->state == ISCSI_STATE_LOGGING_OUT) { in iscsi_data_xmit()
1672 if (rc == -ENOMEM || rc == -EACCES) in iscsi_data_xmit()
1686 if (!list_empty(&conn->mgmtqueue)) in iscsi_data_xmit()
1688 if (!list_empty(&conn->requeue)) in iscsi_data_xmit()
1692 spin_unlock_bh(&conn->session->frwd_lock); in iscsi_data_xmit()
1693 return -ENODATA; in iscsi_data_xmit()
1696 spin_unlock_bh(&conn->session->frwd_lock); in iscsi_data_xmit()
1706 * serialize Xmit worker on a per-connection basis. in iscsi_xmitworker()
1710 } while (rc >= 0 || rc == -EAGAIN); in iscsi_xmitworker()
1718 if (!kfifo_out(&conn->session->cmdpool.queue, in iscsi_alloc_task()
1722 iscsi_cmd(sc)->age = conn->session->age; in iscsi_alloc_task()
1723 iscsi_cmd(sc)->task = task; in iscsi_alloc_task()
1725 refcount_set(&task->refcount, 1); in iscsi_alloc_task()
1726 task->state = ISCSI_TASK_PENDING; in iscsi_alloc_task()
1727 task->conn = conn; in iscsi_alloc_task()
1728 task->sc = sc; in iscsi_alloc_task()
1729 task->have_checked_conn = false; in iscsi_alloc_task()
1730 task->last_timeout = jiffies; in iscsi_alloc_task()
1731 task->last_xfer = jiffies; in iscsi_alloc_task()
1732 task->protected = false; in iscsi_alloc_task()
1733 INIT_LIST_HEAD(&task->running); in iscsi_alloc_task()
1754 int reason = 0; in iscsi_queuecommand() local
1759 sc->result = 0; in iscsi_queuecommand()
1760 iscsi_cmd(sc)->task = NULL; in iscsi_queuecommand()
1764 cls_session = starget_to_session(scsi_target(sc->device)); in iscsi_queuecommand()
1765 session = cls_session->dd_data; in iscsi_queuecommand()
1766 spin_lock_bh(&session->frwd_lock); in iscsi_queuecommand()
1768 reason = iscsi_session_chkready(cls_session); in iscsi_queuecommand()
1769 if (reason) { in iscsi_queuecommand()
1770 sc->result = reason; in iscsi_queuecommand()
1774 if (session->state != ISCSI_STATE_LOGGED_IN) { in iscsi_queuecommand()
1781 switch (session->state) { in iscsi_queuecommand()
1788 reason = FAILURE_SESSION_FAILED; in iscsi_queuecommand()
1789 sc->result = DID_NO_CONNECT << 16; in iscsi_queuecommand()
1794 reason = FAILURE_SESSION_IN_RECOVERY; in iscsi_queuecommand()
1795 sc->result = DID_IMM_RETRY << 16; in iscsi_queuecommand()
1798 reason = FAILURE_SESSION_LOGGING_OUT; in iscsi_queuecommand()
1799 sc->result = DID_IMM_RETRY << 16; in iscsi_queuecommand()
1802 reason = FAILURE_SESSION_RECOVERY_TIMEOUT; in iscsi_queuecommand()
1803 sc->result = DID_TRANSPORT_FAILFAST << 16; in iscsi_queuecommand()
1806 reason = FAILURE_SESSION_TERMINATE; in iscsi_queuecommand()
1807 sc->result = DID_NO_CONNECT << 16; in iscsi_queuecommand()
1810 reason = FAILURE_SESSION_FREED; in iscsi_queuecommand()
1811 sc->result = DID_NO_CONNECT << 16; in iscsi_queuecommand()
1816 conn = session->leadconn; in iscsi_queuecommand()
1818 reason = FAILURE_SESSION_FREED; in iscsi_queuecommand()
1819 sc->result = DID_NO_CONNECT << 16; in iscsi_queuecommand()
1823 if (test_bit(ISCSI_CONN_FLAG_SUSPEND_TX, &conn->flags)) { in iscsi_queuecommand()
1824 reason = FAILURE_SESSION_IN_RECOVERY; in iscsi_queuecommand()
1825 sc->result = DID_REQUEUE << 16; in iscsi_queuecommand()
1830 reason = FAILURE_WINDOW_CLOSED; in iscsi_queuecommand()
1836 reason = FAILURE_OOM; in iscsi_queuecommand()
1840 if (!ihost->workq) { in iscsi_queuecommand()
1841 reason = iscsi_prep_scsi_cmd_pdu(task); in iscsi_queuecommand()
1842 if (reason) { in iscsi_queuecommand()
1843 if (reason == -ENOMEM || reason == -EACCES) { in iscsi_queuecommand()
1844 reason = FAILURE_OOM; in iscsi_queuecommand()
1847 sc->result = DID_ABORT << 16; in iscsi_queuecommand()
1851 if (session->tt->xmit_task(task)) { in iscsi_queuecommand()
1852 session->cmdsn--; in iscsi_queuecommand()
1853 reason = FAILURE_SESSION_NOT_READY; in iscsi_queuecommand()
1857 list_add_tail(&task->running, &conn->cmdqueue); in iscsi_queuecommand()
1861 session->queued_cmdsn++; in iscsi_queuecommand()
1862 spin_unlock_bh(&session->frwd_lock); in iscsi_queuecommand()
1866 spin_lock_bh(&session->back_lock); in iscsi_queuecommand()
1868 spin_unlock_bh(&session->back_lock); in iscsi_queuecommand()
1870 spin_unlock_bh(&session->frwd_lock); in iscsi_queuecommand()
1872 sc->cmnd[0], reason); in iscsi_queuecommand()
1876 spin_lock_bh(&session->back_lock); in iscsi_queuecommand()
1878 spin_unlock_bh(&session->back_lock); in iscsi_queuecommand()
1880 spin_unlock_bh(&session->frwd_lock); in iscsi_queuecommand()
1882 sc->cmnd[0], reason); in iscsi_queuecommand()
1892 struct iscsi_session *session = cls_session->dd_data; in iscsi_target_alloc()
1894 starget->can_queue = session->scsi_cmds_max; in iscsi_target_alloc()
1903 spin_lock(&session->frwd_lock); in iscsi_tmf_timedout()
1904 if (session->tmf_state == TMF_QUEUED) { in iscsi_tmf_timedout()
1905 session->tmf_state = TMF_TIMEDOUT; in iscsi_tmf_timedout()
1908 wake_up(&session->ehwait); in iscsi_tmf_timedout()
1910 spin_unlock(&session->frwd_lock); in iscsi_tmf_timedout()
1916 __must_hold(&session->frwd_lock) in iscsi_exec_task_mgmt_fn()
1918 struct iscsi_session *session = conn->session; in iscsi_exec_task_mgmt_fn()
1921 spin_unlock_bh(&session->frwd_lock); in iscsi_exec_task_mgmt_fn()
1924 spin_lock_bh(&session->frwd_lock); in iscsi_exec_task_mgmt_fn()
1925 return -EPERM; in iscsi_exec_task_mgmt_fn()
1927 conn->tmfcmd_pdus_cnt++; in iscsi_exec_task_mgmt_fn()
1928 session->tmf_timer.expires = timeout * HZ + jiffies; in iscsi_exec_task_mgmt_fn()
1929 add_timer(&session->tmf_timer); in iscsi_exec_task_mgmt_fn()
1932 spin_unlock_bh(&session->frwd_lock); in iscsi_exec_task_mgmt_fn()
1933 mutex_unlock(&session->eh_mutex); in iscsi_exec_task_mgmt_fn()
1943 wait_event_interruptible(session->ehwait, age != session->age || in iscsi_exec_task_mgmt_fn()
1944 session->state != ISCSI_STATE_LOGGED_IN || in iscsi_exec_task_mgmt_fn()
1945 session->tmf_state != TMF_QUEUED); in iscsi_exec_task_mgmt_fn()
1948 del_timer_sync(&session->tmf_timer); in iscsi_exec_task_mgmt_fn()
1950 mutex_lock(&session->eh_mutex); in iscsi_exec_task_mgmt_fn()
1951 spin_lock_bh(&session->frwd_lock); in iscsi_exec_task_mgmt_fn()
1953 if (age != session->age || in iscsi_exec_task_mgmt_fn()
1954 session->state != ISCSI_STATE_LOGGED_IN) in iscsi_exec_task_mgmt_fn()
1955 return -ENOTCONN; in iscsi_exec_task_mgmt_fn()
1964 struct iscsi_session *session = conn->session; in fail_scsi_tasks()
1969 spin_lock_bh(&session->back_lock); in fail_scsi_tasks()
1970 for (i = 0; i < session->cmds_max; i++) { in fail_scsi_tasks()
1971 task = session->cmds[i]; in fail_scsi_tasks()
1972 if (!task->sc || task->state == ISCSI_TASK_FREE) in fail_scsi_tasks()
1975 if (lun != -1 && lun != task->sc->device->lun) in fail_scsi_tasks()
1979 * callout path then when we return scsi-ml owns the cmd. Wait in fail_scsi_tasks()
1983 spin_unlock_bh(&session->back_lock); in fail_scsi_tasks()
1984 spin_unlock_bh(&session->frwd_lock); in fail_scsi_tasks()
1986 spin_lock_bh(&session->frwd_lock); in fail_scsi_tasks()
1992 task->sc, task->itt, task->state); in fail_scsi_tasks()
1996 spin_unlock_bh(&session->back_lock); in fail_scsi_tasks()
2000 * iscsi_suspend_queue - suspend iscsi_queuecommand
2012 spin_lock_bh(&conn->session->frwd_lock); in iscsi_suspend_queue()
2013 set_bit(ISCSI_CONN_FLAG_SUSPEND_TX, &conn->flags); in iscsi_suspend_queue()
2014 spin_unlock_bh(&conn->session->frwd_lock); in iscsi_suspend_queue()
2019 * iscsi_suspend_tx - suspend iscsi_data_xmit
2028 struct Scsi_Host *shost = conn->session->host; in iscsi_suspend_tx()
2031 set_bit(ISCSI_CONN_FLAG_SUSPEND_TX, &conn->flags); in iscsi_suspend_tx()
2032 if (ihost->workq) in iscsi_suspend_tx()
2033 flush_work(&conn->xmitwork); in iscsi_suspend_tx()
2039 clear_bit(ISCSI_CONN_FLAG_SUSPEND_TX, &conn->flags); in iscsi_start_tx()
2044 * iscsi_suspend_rx - Prevent recvwork from running again.
2049 struct Scsi_Host *shost = conn->session->host; in iscsi_suspend_rx()
2052 set_bit(ISCSI_CONN_FLAG_SUSPEND_RX, &conn->flags); in iscsi_suspend_rx()
2053 if (ihost->workq) in iscsi_suspend_rx()
2054 flush_work(&conn->recvwork); in iscsi_suspend_rx()
2066 if (READ_ONCE(conn->ping_task) && in iscsi_has_ping_timed_out()
2067 time_before_eq(conn->last_recv + (conn->recv_timeout * HZ) + in iscsi_has_ping_timed_out()
2068 (conn->ping_timeout * HZ), jiffies)) in iscsi_has_ping_timed_out()
2083 cls_session = starget_to_session(scsi_target(sc->device)); in iscsi_eh_cmd_timed_out()
2084 session = cls_session->dd_data; in iscsi_eh_cmd_timed_out()
2088 spin_lock_bh(&session->frwd_lock); in iscsi_eh_cmd_timed_out()
2089 spin_lock(&session->back_lock); in iscsi_eh_cmd_timed_out()
2090 task = iscsi_cmd(sc)->task; in iscsi_eh_cmd_timed_out()
2097 spin_unlock(&session->back_lock); in iscsi_eh_cmd_timed_out()
2107 spin_unlock(&session->back_lock); in iscsi_eh_cmd_timed_out()
2110 spin_unlock(&session->back_lock); in iscsi_eh_cmd_timed_out()
2112 if (session->state != ISCSI_STATE_LOGGED_IN) { in iscsi_eh_cmd_timed_out()
2121 sc->result = DID_NO_CONNECT << 16; in iscsi_eh_cmd_timed_out()
2134 conn = session->leadconn; in iscsi_eh_cmd_timed_out()
2148 if (time_after(task->last_xfer, task->last_timeout)) { in iscsi_eh_cmd_timed_out()
2150 "scsi-ml for more time to complete. " in iscsi_eh_cmd_timed_out()
2152 "%lu\n.", task->last_xfer, task->last_timeout); in iscsi_eh_cmd_timed_out()
2153 task->have_checked_conn = false; in iscsi_eh_cmd_timed_out()
2158 if (!conn->recv_timeout && !conn->ping_timeout) in iscsi_eh_cmd_timed_out()
2169 spin_lock(&session->back_lock); in iscsi_eh_cmd_timed_out()
2170 for (i = 0; i < conn->session->cmds_max; i++) { in iscsi_eh_cmd_timed_out()
2171 running_task = conn->session->cmds[i]; in iscsi_eh_cmd_timed_out()
2172 if (!running_task->sc || running_task == task || in iscsi_eh_cmd_timed_out()
2173 running_task->state != ISCSI_TASK_RUNNING) in iscsi_eh_cmd_timed_out()
2180 if (time_after(running_task->sc->jiffies_at_alloc, in iscsi_eh_cmd_timed_out()
2181 task->sc->jiffies_at_alloc)) in iscsi_eh_cmd_timed_out()
2184 if (time_after(running_task->last_xfer, task->last_timeout)) { in iscsi_eh_cmd_timed_out()
2188 * we started/last-checked. We could be queueing in iscsi_eh_cmd_timed_out()
2197 "Asking scsi-ml for more time to " in iscsi_eh_cmd_timed_out()
2200 task->last_xfer, running_task->last_xfer, in iscsi_eh_cmd_timed_out()
2201 task->last_timeout); in iscsi_eh_cmd_timed_out()
2202 spin_unlock(&session->back_lock); in iscsi_eh_cmd_timed_out()
2207 spin_unlock(&session->back_lock); in iscsi_eh_cmd_timed_out()
2210 if (task->have_checked_conn) in iscsi_eh_cmd_timed_out()
2217 if (READ_ONCE(conn->ping_task)) { in iscsi_eh_cmd_timed_out()
2218 task->have_checked_conn = true; in iscsi_eh_cmd_timed_out()
2225 task->have_checked_conn = true; in iscsi_eh_cmd_timed_out()
2229 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_cmd_timed_out()
2232 task->last_timeout = jiffies; in iscsi_eh_cmd_timed_out()
2244 struct iscsi_session *session = conn->session; in iscsi_check_transport_timeouts()
2247 spin_lock(&session->frwd_lock); in iscsi_check_transport_timeouts()
2248 if (session->state != ISCSI_STATE_LOGGED_IN) in iscsi_check_transport_timeouts()
2251 recv_timeout = conn->recv_timeout; in iscsi_check_transport_timeouts()
2256 last_recv = conn->last_recv; in iscsi_check_transport_timeouts()
2262 conn->ping_timeout, conn->recv_timeout, in iscsi_check_transport_timeouts()
2263 last_recv, conn->last_ping, jiffies); in iscsi_check_transport_timeouts()
2264 spin_unlock(&session->frwd_lock); in iscsi_check_transport_timeouts()
2275 next_timeout = conn->last_ping + (conn->ping_timeout * HZ); in iscsi_check_transport_timeouts()
2280 mod_timer(&conn->transport_timer, next_timeout); in iscsi_check_transport_timeouts()
2282 spin_unlock(&session->frwd_lock); in iscsi_check_transport_timeouts()
2286 * iscsi_conn_unbind - prevent queueing to conn.
2302 conn = cls_conn->dd_data; in iscsi_conn_unbind()
2303 session = conn->session; in iscsi_conn_unbind()
2310 mutex_lock(&session->eh_mutex); in iscsi_conn_unbind()
2315 spin_lock_bh(&session->frwd_lock); in iscsi_conn_unbind()
2316 clear_bit(ISCSI_CONN_FLAG_BOUND, &conn->flags); in iscsi_conn_unbind()
2324 if (session->state == ISCSI_STATE_LOGGED_IN) in iscsi_conn_unbind()
2327 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_unbind()
2328 mutex_unlock(&session->eh_mutex); in iscsi_conn_unbind()
2336 hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE; in iscsi_prep_abort_task_pdu()
2337 hdr->flags = ISCSI_TM_FUNC_ABORT_TASK & ISCSI_FLAG_TM_FUNC_MASK; in iscsi_prep_abort_task_pdu()
2338 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsi_prep_abort_task_pdu()
2339 hdr->lun = task->lun; in iscsi_prep_abort_task_pdu()
2340 hdr->rtt = task->hdr_itt; in iscsi_prep_abort_task_pdu()
2341 hdr->refcmdsn = task->cmdsn; in iscsi_prep_abort_task_pdu()
2353 cls_session = starget_to_session(scsi_target(sc->device)); in iscsi_eh_abort()
2354 session = cls_session->dd_data; in iscsi_eh_abort()
2359 mutex_lock(&session->eh_mutex); in iscsi_eh_abort()
2360 spin_lock_bh(&session->frwd_lock); in iscsi_eh_abort()
2365 if (!iscsi_cmd(sc)->task) { in iscsi_eh_abort()
2368 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2369 mutex_unlock(&session->eh_mutex); in iscsi_eh_abort()
2377 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN || in iscsi_eh_abort()
2378 iscsi_cmd(sc)->age != session->age) { in iscsi_eh_abort()
2379 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2380 mutex_unlock(&session->eh_mutex); in iscsi_eh_abort()
2386 spin_lock(&session->back_lock); in iscsi_eh_abort()
2387 task = iscsi_cmd(sc)->task; in iscsi_eh_abort()
2388 if (!task || !task->sc) { in iscsi_eh_abort()
2392 spin_unlock(&session->back_lock); in iscsi_eh_abort()
2393 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2394 mutex_unlock(&session->eh_mutex); in iscsi_eh_abort()
2399 spin_unlock(&session->back_lock); in iscsi_eh_abort()
2400 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2401 mutex_unlock(&session->eh_mutex); in iscsi_eh_abort()
2407 ISCSI_DBG_EH(session, "aborting [sc %p itt 0x%x]\n", sc, task->itt); in iscsi_eh_abort()
2408 conn = session->leadconn; in iscsi_eh_abort()
2409 iscsi_get_conn(conn->cls_conn); in iscsi_eh_abort()
2410 conn->eh_abort_cnt++; in iscsi_eh_abort()
2411 age = session->age; in iscsi_eh_abort()
2412 spin_unlock(&session->back_lock); in iscsi_eh_abort()
2414 if (task->state == ISCSI_TASK_PENDING) { in iscsi_eh_abort()
2420 if (session->tmf_state != TMF_INITIAL) in iscsi_eh_abort()
2422 session->tmf_state = TMF_QUEUED; in iscsi_eh_abort()
2424 hdr = &session->tmhdr; in iscsi_eh_abort()
2427 if (iscsi_exec_task_mgmt_fn(conn, hdr, age, session->abort_timeout)) in iscsi_eh_abort()
2430 switch (session->tmf_state) { in iscsi_eh_abort()
2432 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2443 spin_lock_bh(&session->frwd_lock); in iscsi_eh_abort()
2445 session->tmf_state = TMF_INITIAL; in iscsi_eh_abort()
2447 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2451 session->running_aborted_task = task; in iscsi_eh_abort()
2452 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2457 session->tmf_state = TMF_INITIAL; in iscsi_eh_abort()
2466 session->tmf_state = TMF_INITIAL; in iscsi_eh_abort()
2471 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2474 sc, task->itt); in iscsi_eh_abort()
2476 iscsi_put_conn(conn->cls_conn); in iscsi_eh_abort()
2477 mutex_unlock(&session->eh_mutex); in iscsi_eh_abort()
2481 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_abort()
2484 task ? task->itt : 0); in iscsi_eh_abort()
2490 if (!session->running_aborted_task) in iscsi_eh_abort()
2493 iscsi_put_conn(conn->cls_conn); in iscsi_eh_abort()
2494 mutex_unlock(&session->eh_mutex); in iscsi_eh_abort()
2502 hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE; in iscsi_prep_lun_reset_pdu()
2503 hdr->flags = ISCSI_TM_FUNC_LOGICAL_UNIT_RESET & ISCSI_FLAG_TM_FUNC_MASK; in iscsi_prep_lun_reset_pdu()
2504 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsi_prep_lun_reset_pdu()
2505 int_to_scsilun(sc->device->lun, &hdr->lun); in iscsi_prep_lun_reset_pdu()
2506 hdr->rtt = RESERVED_ITT; in iscsi_prep_lun_reset_pdu()
2517 cls_session = starget_to_session(scsi_target(sc->device)); in iscsi_eh_device_reset()
2518 session = cls_session->dd_data; in iscsi_eh_device_reset()
2521 sc->device->lun); in iscsi_eh_device_reset()
2523 mutex_lock(&session->eh_mutex); in iscsi_eh_device_reset()
2524 spin_lock_bh(&session->frwd_lock); in iscsi_eh_device_reset()
2529 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) in iscsi_eh_device_reset()
2531 conn = session->leadconn; in iscsi_eh_device_reset()
2534 if (session->tmf_state != TMF_INITIAL) in iscsi_eh_device_reset()
2536 session->tmf_state = TMF_QUEUED; in iscsi_eh_device_reset()
2538 hdr = &session->tmhdr; in iscsi_eh_device_reset()
2541 if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age, in iscsi_eh_device_reset()
2542 session->lu_reset_timeout)) { in iscsi_eh_device_reset()
2547 switch (session->tmf_state) { in iscsi_eh_device_reset()
2551 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_device_reset()
2555 session->tmf_state = TMF_INITIAL; in iscsi_eh_device_reset()
2560 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_device_reset()
2564 spin_lock_bh(&session->frwd_lock); in iscsi_eh_device_reset()
2566 fail_scsi_tasks(conn, sc->device->lun, DID_ERROR); in iscsi_eh_device_reset()
2567 session->tmf_state = TMF_INITIAL; in iscsi_eh_device_reset()
2568 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_device_reset()
2574 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_device_reset()
2578 mutex_unlock(&session->eh_mutex); in iscsi_eh_device_reset()
2585 struct iscsi_session *session = cls_session->dd_data; in iscsi_session_recovery_timedout()
2587 spin_lock_bh(&session->frwd_lock); in iscsi_session_recovery_timedout()
2588 if (session->state != ISCSI_STATE_LOGGED_IN) { in iscsi_session_recovery_timedout()
2589 session->state = ISCSI_STATE_RECOVERY_FAILED; in iscsi_session_recovery_timedout()
2590 wake_up(&session->ehwait); in iscsi_session_recovery_timedout()
2592 spin_unlock_bh(&session->frwd_lock); in iscsi_session_recovery_timedout()
2597 * iscsi_eh_session_reset - drop session and attempt relogin
2609 cls_session = starget_to_session(scsi_target(sc->device)); in iscsi_eh_session_reset()
2610 session = cls_session->dd_data; in iscsi_eh_session_reset()
2612 mutex_lock(&session->eh_mutex); in iscsi_eh_session_reset()
2613 spin_lock_bh(&session->frwd_lock); in iscsi_eh_session_reset()
2614 if (session->state == ISCSI_STATE_TERMINATE) { in iscsi_eh_session_reset()
2618 "%s [age %d]\n", session->targetname, in iscsi_eh_session_reset()
2619 session->age); in iscsi_eh_session_reset()
2620 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_session_reset()
2621 mutex_unlock(&session->eh_mutex); in iscsi_eh_session_reset()
2625 conn = session->leadconn; in iscsi_eh_session_reset()
2626 iscsi_get_conn(conn->cls_conn); in iscsi_eh_session_reset()
2628 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_session_reset()
2629 mutex_unlock(&session->eh_mutex); in iscsi_eh_session_reset()
2632 iscsi_put_conn(conn->cls_conn); in iscsi_eh_session_reset()
2635 wait_event_interruptible(session->ehwait, in iscsi_eh_session_reset()
2636 session->state == ISCSI_STATE_TERMINATE || in iscsi_eh_session_reset()
2637 session->state == ISCSI_STATE_LOGGED_IN || in iscsi_eh_session_reset()
2638 session->state == ISCSI_STATE_RECOVERY_FAILED); in iscsi_eh_session_reset()
2642 mutex_lock(&session->eh_mutex); in iscsi_eh_session_reset()
2643 spin_lock_bh(&session->frwd_lock); in iscsi_eh_session_reset()
2644 if (session->state == ISCSI_STATE_LOGGED_IN) { in iscsi_eh_session_reset()
2647 session->targetname, conn->persistent_address); in iscsi_eh_session_reset()
2650 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_session_reset()
2651 mutex_unlock(&session->eh_mutex); in iscsi_eh_session_reset()
2659 hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE; in iscsi_prep_tgt_reset_pdu()
2660 hdr->flags = ISCSI_TM_FUNC_TARGET_WARM_RESET & ISCSI_FLAG_TM_FUNC_MASK; in iscsi_prep_tgt_reset_pdu()
2661 hdr->flags |= ISCSI_FLAG_CMD_FINAL; in iscsi_prep_tgt_reset_pdu()
2662 hdr->rtt = RESERVED_ITT; in iscsi_prep_tgt_reset_pdu()
2666 * iscsi_eh_target_reset - reset target
2679 cls_session = starget_to_session(scsi_target(sc->device)); in iscsi_eh_target_reset()
2680 session = cls_session->dd_data; in iscsi_eh_target_reset()
2683 session->targetname); in iscsi_eh_target_reset()
2685 mutex_lock(&session->eh_mutex); in iscsi_eh_target_reset()
2686 spin_lock_bh(&session->frwd_lock); in iscsi_eh_target_reset()
2691 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) in iscsi_eh_target_reset()
2693 conn = session->leadconn; in iscsi_eh_target_reset()
2696 if (session->tmf_state != TMF_INITIAL) in iscsi_eh_target_reset()
2698 session->tmf_state = TMF_QUEUED; in iscsi_eh_target_reset()
2700 hdr = &session->tmhdr; in iscsi_eh_target_reset()
2703 if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age, in iscsi_eh_target_reset()
2704 session->tgt_reset_timeout)) { in iscsi_eh_target_reset()
2709 switch (session->tmf_state) { in iscsi_eh_target_reset()
2713 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_target_reset()
2717 session->tmf_state = TMF_INITIAL; in iscsi_eh_target_reset()
2722 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_target_reset()
2726 spin_lock_bh(&session->frwd_lock); in iscsi_eh_target_reset()
2728 fail_scsi_tasks(conn, -1, DID_ERROR); in iscsi_eh_target_reset()
2729 session->tmf_state = TMF_INITIAL; in iscsi_eh_target_reset()
2730 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_target_reset()
2736 spin_unlock_bh(&session->frwd_lock); in iscsi_eh_target_reset()
2738 ISCSI_DBG_EH(session, "tgt %s reset result = %s\n", session->targetname, in iscsi_eh_target_reset()
2740 mutex_unlock(&session->eh_mutex); in iscsi_eh_target_reset()
2745 * iscsi_eh_recover_target - reset target and possibly the session
2763 * Pre-allocate a pool of @max items of @item_size. By default, the pool
2764 * should be accessed via kfifo_{get,put} on q->queue.
2766 * by passing in a non-NULL @items pointer
2769 iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size) in iscsi_pool_init() argument
2775 q->max = max; in iscsi_pool_init()
2781 q->pool = kvcalloc(num_arrays * max, sizeof(void *), GFP_KERNEL); in iscsi_pool_init()
2782 if (q->pool == NULL) in iscsi_pool_init()
2783 return -ENOMEM; in iscsi_pool_init()
2785 kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*)); in iscsi_pool_init()
2787 for (i = 0; i < max; i++) { in iscsi_pool_init()
2788 q->pool[i] = kzalloc(item_size, GFP_KERNEL); in iscsi_pool_init()
2789 if (q->pool[i] == NULL) { in iscsi_pool_init()
2790 q->max = i; in iscsi_pool_init()
2793 kfifo_in(&q->queue, (void*)&q->pool[i], sizeof(void*)); in iscsi_pool_init()
2797 *items = q->pool + max; in iscsi_pool_init()
2798 memcpy(*items, q->pool, max * sizeof(void *)); in iscsi_pool_init()
2805 return -ENOMEM; in iscsi_pool_init()
2813 for (i = 0; i < q->max; i++) in iscsi_pool_free()
2814 kfree(q->pool[i]); in iscsi_pool_free()
2815 kvfree(q->pool); in iscsi_pool_free()
2833 printk(KERN_ERR "iscsi: invalid max cmds of %d. Must be a power of two that is at least %d.\n", in iscsi_host_get_max_scsi_cmds()
2835 return -EINVAL; in iscsi_host_get_max_scsi_cmds()
2839 …printk(KERN_INFO "iscsi: invalid max cmds of %d. Must be a power of 2 less than or equal to %d. Us… in iscsi_host_get_max_scsi_cmds()
2848 …printk(KERN_ERR "iscsi: invalid max cmds of %d. Must be a power of 2 greater than %d.\n", requeste… in iscsi_host_get_max_scsi_cmds()
2849 return -EINVAL; in iscsi_host_get_max_scsi_cmds()
2852 …printk(KERN_INFO "iscsi: invalid max cmds %d. Must be a power of 2. Rounding max cmds down to %d.\… in iscsi_host_get_max_scsi_cmds()
2856 scsi_cmds = total_cmds - ISCSI_MGMT_CMDS_MAX; in iscsi_host_get_max_scsi_cmds()
2857 if (shost->can_queue && scsi_cmds > shost->can_queue) { in iscsi_host_get_max_scsi_cmds()
2858 total_cmds = shost->can_queue; in iscsi_host_get_max_scsi_cmds()
2860 …printk(KERN_INFO "iscsi: requested max cmds %u is higher than driver limit. Using driver limit %u\… in iscsi_host_get_max_scsi_cmds()
2861 requested_cmds_max, shost->can_queue); in iscsi_host_get_max_scsi_cmds()
2870 * iscsi_host_add - add host to system
2879 if (!shost->can_queue) in iscsi_host_add()
2880 shost->can_queue = ISCSI_DEF_XMIT_CMDS_MAX; in iscsi_host_add()
2882 if (!shost->cmd_per_lun) in iscsi_host_add()
2883 shost->cmd_per_lun = ISCSI_DEF_CMD_PER_LUN; in iscsi_host_add()
2890 * iscsi_host_alloc - allocate a host and driver data
2910 ihost->workq = alloc_workqueue("iscsi_q_%d", in iscsi_host_alloc()
2912 1, shost->host_no); in iscsi_host_alloc()
2913 if (!ihost->workq) in iscsi_host_alloc()
2917 spin_lock_init(&ihost->lock); in iscsi_host_alloc()
2918 ihost->state = ISCSI_HOST_SETUP; in iscsi_host_alloc()
2919 ihost->num_sessions = 0; in iscsi_host_alloc()
2920 init_waitqueue_head(&ihost->session_removal_wq); in iscsi_host_alloc()
2931 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_INVALID_HOST); in iscsi_notify_host_removed()
2935 * iscsi_host_remove - remove host and sessions
2947 spin_lock_irqsave(&ihost->lock, flags); in iscsi_host_remove()
2948 ihost->state = ISCSI_HOST_REMOVED; in iscsi_host_remove()
2949 spin_unlock_irqrestore(&ihost->lock, flags); in iscsi_host_remove()
2956 wait_event_interruptible(ihost->session_removal_wq, in iscsi_host_remove()
2957 ihost->num_sessions == 0); in iscsi_host_remove()
2969 if (ihost->workq) in iscsi_host_free()
2970 destroy_workqueue(ihost->workq); in iscsi_host_free()
2972 kfree(ihost->netdev); in iscsi_host_free()
2973 kfree(ihost->hwaddress); in iscsi_host_free()
2974 kfree(ihost->initiatorname); in iscsi_host_free()
2992 spin_lock_irqsave(&ihost->lock, flags); in iscsi_host_dec_session_cnt()
2993 ihost->num_sessions--; in iscsi_host_dec_session_cnt()
2994 if (ihost->num_sessions == 0) in iscsi_host_dec_session_cnt()
2995 wake_up(&ihost->session_removal_wq); in iscsi_host_dec_session_cnt()
2996 spin_unlock_irqrestore(&ihost->lock, flags); in iscsi_host_dec_session_cnt()
3001 * iscsi_session_setup - create iscsi cls session and host and session
3028 spin_lock_irqsave(&ihost->lock, flags); in iscsi_session_setup()
3029 if (ihost->state == ISCSI_HOST_REMOVED) { in iscsi_session_setup()
3030 spin_unlock_irqrestore(&ihost->lock, flags); in iscsi_session_setup()
3033 ihost->num_sessions++; in iscsi_session_setup()
3034 spin_unlock_irqrestore(&ihost->lock, flags); in iscsi_session_setup()
3045 session = cls_session->dd_data; in iscsi_session_setup()
3046 session->cls_session = cls_session; in iscsi_session_setup()
3047 session->host = shost; in iscsi_session_setup()
3048 session->state = ISCSI_STATE_FREE; in iscsi_session_setup()
3049 session->fast_abort = 1; in iscsi_session_setup()
3050 session->tgt_reset_timeout = 30; in iscsi_session_setup()
3051 session->lu_reset_timeout = 15; in iscsi_session_setup()
3052 session->abort_timeout = 10; in iscsi_session_setup()
3053 session->scsi_cmds_max = scsi_cmds; in iscsi_session_setup()
3054 session->cmds_max = scsi_cmds + ISCSI_MGMT_CMDS_MAX; in iscsi_session_setup()
3055 session->queued_cmdsn = session->cmdsn = initial_cmdsn; in iscsi_session_setup()
3056 session->exp_cmdsn = initial_cmdsn + 1; in iscsi_session_setup()
3057 session->max_cmdsn = initial_cmdsn + 1; in iscsi_session_setup()
3058 session->max_r2t = 1; in iscsi_session_setup()
3059 session->tt = iscsit; in iscsi_session_setup()
3060 session->dd_data = cls_session->dd_data + sizeof(*session); in iscsi_session_setup()
3062 session->tmf_state = TMF_INITIAL; in iscsi_session_setup()
3063 timer_setup(&session->tmf_timer, iscsi_tmf_timedout, 0); in iscsi_session_setup()
3064 mutex_init(&session->eh_mutex); in iscsi_session_setup()
3065 init_waitqueue_head(&session->ehwait); in iscsi_session_setup()
3067 spin_lock_init(&session->frwd_lock); in iscsi_session_setup()
3068 spin_lock_init(&session->back_lock); in iscsi_session_setup()
3071 if (iscsi_pool_init(&session->cmdpool, session->cmds_max, in iscsi_session_setup()
3072 (void***)&session->cmds, in iscsi_session_setup()
3076 /* pre-format cmds pool with ITT */ in iscsi_session_setup()
3077 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { in iscsi_session_setup()
3078 struct iscsi_task *task = session->cmds[cmd_i]; in iscsi_session_setup()
3081 task->dd_data = &task[1]; in iscsi_session_setup()
3082 task->itt = cmd_i; in iscsi_session_setup()
3083 task->state = ISCSI_TASK_FREE; in iscsi_session_setup()
3084 INIT_LIST_HEAD(&task->running); in iscsi_session_setup()
3087 if (!try_module_get(iscsit->owner)) in iscsi_session_setup()
3096 module_put(iscsit->owner); in iscsi_session_setup()
3098 iscsi_pool_free(&session->cmdpool); in iscsi_session_setup()
3108 * issi_session_remove - Remove session from iSCSI class.
3112 struct iscsi_session *session = cls_session->dd_data; in iscsi_session_remove()
3113 struct Scsi_Host *shost = session->host; in iscsi_session_remove()
3126 * iscsi_session_free - Free iscsi session and it's resources
3131 struct iscsi_session *session = cls_session->dd_data; in iscsi_session_free()
3132 struct module *owner = cls_session->transport->owner; in iscsi_session_free()
3134 iscsi_pool_free(&session->cmdpool); in iscsi_session_free()
3135 kfree(session->password); in iscsi_session_free()
3136 kfree(session->password_in); in iscsi_session_free()
3137 kfree(session->username); in iscsi_session_free()
3138 kfree(session->username_in); in iscsi_session_free()
3139 kfree(session->targetname); in iscsi_session_free()
3140 kfree(session->targetalias); in iscsi_session_free()
3141 kfree(session->initiatorname); in iscsi_session_free()
3142 kfree(session->boot_root); in iscsi_session_free()
3143 kfree(session->boot_nic); in iscsi_session_free()
3144 kfree(session->boot_target); in iscsi_session_free()
3145 kfree(session->ifacename); in iscsi_session_free()
3146 kfree(session->portal_type); in iscsi_session_free()
3147 kfree(session->discovery_parent_type); in iscsi_session_free()
3155 * iscsi_session_teardown - destroy session and cls_session
3166 * iscsi_conn_setup - create iscsi_cls_conn and iscsi_conn
3175 struct iscsi_session *session = cls_session->dd_data; in iscsi_conn_setup()
3185 conn = cls_conn->dd_data; in iscsi_conn_setup()
3187 conn->dd_data = cls_conn->dd_data + sizeof(*conn); in iscsi_conn_setup()
3188 conn->session = session; in iscsi_conn_setup()
3189 conn->cls_conn = cls_conn; in iscsi_conn_setup()
3190 conn->c_stage = ISCSI_CONN_INITIAL_STAGE; in iscsi_conn_setup()
3191 conn->id = conn_idx; in iscsi_conn_setup()
3192 conn->exp_statsn = 0; in iscsi_conn_setup()
3194 timer_setup(&conn->transport_timer, iscsi_check_transport_timeouts, 0); in iscsi_conn_setup()
3196 INIT_LIST_HEAD(&conn->mgmtqueue); in iscsi_conn_setup()
3197 INIT_LIST_HEAD(&conn->cmdqueue); in iscsi_conn_setup()
3198 INIT_LIST_HEAD(&conn->requeue); in iscsi_conn_setup()
3199 INIT_WORK(&conn->xmitwork, iscsi_xmitworker); in iscsi_conn_setup()
3202 spin_lock_bh(&session->frwd_lock); in iscsi_conn_setup()
3203 if (!kfifo_out(&session->cmdpool.queue, in iscsi_conn_setup()
3204 (void*)&conn->login_task, in iscsi_conn_setup()
3206 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_setup()
3209 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_setup()
3215 conn->login_task->data = conn->data = data; in iscsi_conn_setup()
3224 free_pages((unsigned long) conn->data, in iscsi_conn_setup()
3228 kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task, in iscsi_conn_setup()
3237 * iscsi_conn_teardown - teardown iscsi connection
3241 * like scsi-mls remove + put host
3245 struct iscsi_conn *conn = cls_conn->dd_data; in iscsi_conn_teardown()
3246 struct iscsi_session *session = conn->session; in iscsi_conn_teardown()
3250 del_timer_sync(&conn->transport_timer); in iscsi_conn_teardown()
3252 mutex_lock(&session->eh_mutex); in iscsi_conn_teardown()
3253 spin_lock_bh(&session->frwd_lock); in iscsi_conn_teardown()
3254 conn->c_stage = ISCSI_CONN_CLEANUP_WAIT; in iscsi_conn_teardown()
3255 if (session->leadconn == conn) { in iscsi_conn_teardown()
3259 session->state = ISCSI_STATE_TERMINATE; in iscsi_conn_teardown()
3260 wake_up(&session->ehwait); in iscsi_conn_teardown()
3262 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_teardown()
3267 spin_lock_bh(&session->frwd_lock); in iscsi_conn_teardown()
3268 free_pages((unsigned long) conn->data, in iscsi_conn_teardown()
3270 kfree(conn->persistent_address); in iscsi_conn_teardown()
3271 kfree(conn->local_ipaddr); in iscsi_conn_teardown()
3273 spin_lock_bh(&session->back_lock); in iscsi_conn_teardown()
3274 kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task, in iscsi_conn_teardown()
3276 spin_unlock_bh(&session->back_lock); in iscsi_conn_teardown()
3277 if (session->leadconn == conn) in iscsi_conn_teardown()
3278 session->leadconn = NULL; in iscsi_conn_teardown()
3279 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_teardown()
3280 mutex_unlock(&session->eh_mutex); in iscsi_conn_teardown()
3288 struct iscsi_conn *conn = cls_conn->dd_data; in iscsi_conn_start()
3289 struct iscsi_session *session = conn->session; in iscsi_conn_start()
3294 return -EPERM; in iscsi_conn_start()
3297 if ((session->imm_data_en || !session->initial_r2t_en) && in iscsi_conn_start()
3298 session->first_burst > session->max_burst) { in iscsi_conn_start()
3301 session->first_burst, session->max_burst); in iscsi_conn_start()
3302 return -EINVAL; in iscsi_conn_start()
3305 if (conn->ping_timeout && !conn->recv_timeout) { in iscsi_conn_start()
3308 conn->recv_timeout = 5; in iscsi_conn_start()
3311 if (conn->recv_timeout && !conn->ping_timeout) { in iscsi_conn_start()
3314 conn->ping_timeout = 5; in iscsi_conn_start()
3317 spin_lock_bh(&session->frwd_lock); in iscsi_conn_start()
3318 conn->c_stage = ISCSI_CONN_STARTED; in iscsi_conn_start()
3319 session->state = ISCSI_STATE_LOGGED_IN; in iscsi_conn_start()
3320 session->queued_cmdsn = session->cmdsn; in iscsi_conn_start()
3322 conn->last_recv = jiffies; in iscsi_conn_start()
3323 conn->last_ping = jiffies; in iscsi_conn_start()
3324 if (conn->recv_timeout && conn->ping_timeout) in iscsi_conn_start()
3325 mod_timer(&conn->transport_timer, in iscsi_conn_start()
3326 jiffies + (conn->recv_timeout * HZ)); in iscsi_conn_start()
3328 switch(conn->stop_stage) { in iscsi_conn_start()
3331 * unblock eh_abort() if it is blocked. re-try all in iscsi_conn_start()
3334 conn->stop_stage = 0; in iscsi_conn_start()
3335 session->tmf_state = TMF_INITIAL; in iscsi_conn_start()
3336 session->age++; in iscsi_conn_start()
3337 if (session->age == 16) in iscsi_conn_start()
3338 session->age = 0; in iscsi_conn_start()
3341 conn->stop_stage = 0; in iscsi_conn_start()
3346 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_start()
3348 iscsi_unblock_session(session->cls_session); in iscsi_conn_start()
3349 wake_up(&session->ehwait); in iscsi_conn_start()
3360 for (i = 0; i < conn->session->cmds_max; i++) { in fail_mgmt_tasks()
3361 task = conn->session->cmds[i]; in fail_mgmt_tasks()
3362 if (task->sc) in fail_mgmt_tasks()
3365 if (task->state == ISCSI_TASK_FREE) in fail_mgmt_tasks()
3368 ISCSI_DBG_SESSION(conn->session, in fail_mgmt_tasks()
3370 task->itt, task->state); in fail_mgmt_tasks()
3372 spin_lock_bh(&session->back_lock); in fail_mgmt_tasks()
3374 spin_unlock_bh(&session->back_lock); in fail_mgmt_tasks()
3379 if (task->state == ISCSI_TASK_PENDING) in fail_mgmt_tasks()
3382 spin_unlock_bh(&session->back_lock); in fail_mgmt_tasks()
3388 struct iscsi_conn *conn = cls_conn->dd_data; in iscsi_conn_stop()
3389 struct iscsi_session *session = conn->session; in iscsi_conn_stop()
3392 mutex_lock(&session->eh_mutex); in iscsi_conn_stop()
3393 spin_lock_bh(&session->frwd_lock); in iscsi_conn_stop()
3394 if (conn->stop_stage == STOP_CONN_TERM) { in iscsi_conn_stop()
3395 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_stop()
3396 mutex_unlock(&session->eh_mutex); in iscsi_conn_stop()
3406 session->state = ISCSI_STATE_TERMINATE; in iscsi_conn_stop()
3407 else if (conn->stop_stage != STOP_CONN_RECOVER) in iscsi_conn_stop()
3408 session->state = ISCSI_STATE_IN_RECOVERY; in iscsi_conn_stop()
3410 old_stop_stage = conn->stop_stage; in iscsi_conn_stop()
3411 conn->stop_stage = flag; in iscsi_conn_stop()
3412 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_stop()
3414 del_timer_sync(&conn->transport_timer); in iscsi_conn_stop()
3417 spin_lock_bh(&session->frwd_lock); in iscsi_conn_stop()
3418 conn->c_stage = ISCSI_CONN_STOPPED; in iscsi_conn_stop()
3419 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_stop()
3423 * header digest. conn->hdr_size used for optimization in iscsi_conn_stop()
3424 * in hdr_extract() and will be re-negotiated at in iscsi_conn_stop()
3428 conn->hdrdgst_en = 0; in iscsi_conn_stop()
3429 conn->datadgst_en = 0; in iscsi_conn_stop()
3430 if (session->state == ISCSI_STATE_IN_RECOVERY && in iscsi_conn_stop()
3433 iscsi_block_session(session->cls_session); in iscsi_conn_stop()
3440 spin_lock_bh(&session->frwd_lock); in iscsi_conn_stop()
3441 fail_scsi_tasks(conn, -1, DID_TRANSPORT_DISRUPTED); in iscsi_conn_stop()
3443 memset(&session->tmhdr, 0, sizeof(session->tmhdr)); in iscsi_conn_stop()
3444 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_stop()
3445 mutex_unlock(&session->eh_mutex); in iscsi_conn_stop()
3452 struct iscsi_session *session = cls_session->dd_data; in iscsi_conn_bind()
3453 struct iscsi_conn *conn = cls_conn->dd_data; in iscsi_conn_bind()
3455 spin_lock_bh(&session->frwd_lock); in iscsi_conn_bind()
3457 session->leadconn = conn; in iscsi_conn_bind()
3459 set_bit(ISCSI_CONN_FLAG_BOUND, &conn->flags); in iscsi_conn_bind()
3460 spin_unlock_bh(&session->frwd_lock); in iscsi_conn_bind()
3464 * we have to reset max/exp cmdsn so we can see the new values. in iscsi_conn_bind()
3466 spin_lock_bh(&session->back_lock); in iscsi_conn_bind()
3467 session->max_cmdsn = session->exp_cmdsn = session->cmdsn + 1; in iscsi_conn_bind()
3468 spin_unlock_bh(&session->back_lock); in iscsi_conn_bind()
3472 clear_bit(ISCSI_CONN_FLAG_SUSPEND_RX, &conn->flags); in iscsi_conn_bind()
3473 clear_bit(ISCSI_CONN_FLAG_SUSPEND_TX, &conn->flags); in iscsi_conn_bind()
3489 return -ENOMEM; in iscsi_switch_str_param()
3500 struct iscsi_conn *conn = cls_conn->dd_data; in iscsi_set_param()
3501 struct iscsi_session *session = conn->session; in iscsi_set_param()
3506 sscanf(buf, "%d", &session->fast_abort); in iscsi_set_param()
3509 sscanf(buf, "%d", &session->abort_timeout); in iscsi_set_param()
3512 sscanf(buf, "%d", &session->lu_reset_timeout); in iscsi_set_param()
3515 sscanf(buf, "%d", &session->tgt_reset_timeout); in iscsi_set_param()
3518 sscanf(buf, "%d", &conn->ping_timeout); in iscsi_set_param()
3521 sscanf(buf, "%d", &conn->recv_timeout); in iscsi_set_param()
3524 sscanf(buf, "%d", &conn->max_recv_dlength); in iscsi_set_param()
3527 sscanf(buf, "%d", &conn->max_xmit_dlength); in iscsi_set_param()
3530 sscanf(buf, "%d", &conn->hdrdgst_en); in iscsi_set_param()
3533 sscanf(buf, "%d", &conn->datadgst_en); in iscsi_set_param()
3536 sscanf(buf, "%d", &session->initial_r2t_en); in iscsi_set_param()
3539 sscanf(buf, "%hu", &session->max_r2t); in iscsi_set_param()
3542 sscanf(buf, "%d", &session->imm_data_en); in iscsi_set_param()
3545 sscanf(buf, "%d", &session->first_burst); in iscsi_set_param()
3548 sscanf(buf, "%d", &session->max_burst); in iscsi_set_param()
3551 sscanf(buf, "%d", &session->pdu_inorder_en); in iscsi_set_param()
3554 sscanf(buf, "%d", &session->dataseq_inorder_en); in iscsi_set_param()
3557 sscanf(buf, "%d", &session->erl); in iscsi_set_param()
3560 sscanf(buf, "%u", &conn->exp_statsn); in iscsi_set_param()
3563 return iscsi_switch_str_param(&session->username, buf); in iscsi_set_param()
3565 return iscsi_switch_str_param(&session->username_in, buf); in iscsi_set_param()
3567 return iscsi_switch_str_param(&session->password, buf); in iscsi_set_param()
3569 return iscsi_switch_str_param(&session->password_in, buf); in iscsi_set_param()
3571 return iscsi_switch_str_param(&session->targetname, buf); in iscsi_set_param()
3573 return iscsi_switch_str_param(&session->targetalias, buf); in iscsi_set_param()
3575 sscanf(buf, "%d", &session->tpgt); in iscsi_set_param()
3578 sscanf(buf, "%d", &conn->persistent_port); in iscsi_set_param()
3581 return iscsi_switch_str_param(&conn->persistent_address, buf); in iscsi_set_param()
3583 return iscsi_switch_str_param(&session->ifacename, buf); in iscsi_set_param()
3585 return iscsi_switch_str_param(&session->initiatorname, buf); in iscsi_set_param()
3587 return iscsi_switch_str_param(&session->boot_root, buf); in iscsi_set_param()
3589 return iscsi_switch_str_param(&session->boot_nic, buf); in iscsi_set_param()
3591 return iscsi_switch_str_param(&session->boot_target, buf); in iscsi_set_param()
3593 return iscsi_switch_str_param(&session->portal_type, buf); in iscsi_set_param()
3595 return iscsi_switch_str_param(&session->discovery_parent_type, in iscsi_set_param()
3599 session->discovery_sess = !!val; in iscsi_set_param()
3602 return iscsi_switch_str_param(&conn->local_ipaddr, buf); in iscsi_set_param()
3604 return -ENOSYS; in iscsi_set_param()
3614 struct iscsi_session *session = cls_session->dd_data; in iscsi_session_get_param()
3619 len = sysfs_emit(buf, "%d\n", session->fast_abort); in iscsi_session_get_param()
3622 len = sysfs_emit(buf, "%d\n", session->abort_timeout); in iscsi_session_get_param()
3625 len = sysfs_emit(buf, "%d\n", session->lu_reset_timeout); in iscsi_session_get_param()
3628 len = sysfs_emit(buf, "%d\n", session->tgt_reset_timeout); in iscsi_session_get_param()
3631 len = sysfs_emit(buf, "%d\n", session->initial_r2t_en); in iscsi_session_get_param()
3634 len = sysfs_emit(buf, "%hu\n", session->max_r2t); in iscsi_session_get_param()
3637 len = sysfs_emit(buf, "%d\n", session->imm_data_en); in iscsi_session_get_param()
3640 len = sysfs_emit(buf, "%u\n", session->first_burst); in iscsi_session_get_param()
3643 len = sysfs_emit(buf, "%u\n", session->max_burst); in iscsi_session_get_param()
3646 len = sysfs_emit(buf, "%d\n", session->pdu_inorder_en); in iscsi_session_get_param()
3649 len = sysfs_emit(buf, "%d\n", session->dataseq_inorder_en); in iscsi_session_get_param()
3652 len = sysfs_emit(buf, "%d\n", session->def_taskmgmt_tmo); in iscsi_session_get_param()
3655 len = sysfs_emit(buf, "%d\n", session->erl); in iscsi_session_get_param()
3658 len = sysfs_emit(buf, "%s\n", session->targetname); in iscsi_session_get_param()
3661 len = sysfs_emit(buf, "%s\n", session->targetalias); in iscsi_session_get_param()
3664 len = sysfs_emit(buf, "%d\n", session->tpgt); in iscsi_session_get_param()
3667 len = sysfs_emit(buf, "%s\n", session->username); in iscsi_session_get_param()
3670 len = sysfs_emit(buf, "%s\n", session->username_in); in iscsi_session_get_param()
3673 len = sysfs_emit(buf, "%s\n", session->password); in iscsi_session_get_param()
3676 len = sysfs_emit(buf, "%s\n", session->password_in); in iscsi_session_get_param()
3679 len = sysfs_emit(buf, "%s\n", session->ifacename); in iscsi_session_get_param()
3682 len = sysfs_emit(buf, "%s\n", session->initiatorname); in iscsi_session_get_param()
3685 len = sysfs_emit(buf, "%s\n", session->boot_root); in iscsi_session_get_param()
3688 len = sysfs_emit(buf, "%s\n", session->boot_nic); in iscsi_session_get_param()
3691 len = sysfs_emit(buf, "%s\n", session->boot_target); in iscsi_session_get_param()
3694 len = sysfs_emit(buf, "%u\n", session->auto_snd_tgt_disable); in iscsi_session_get_param()
3697 len = sysfs_emit(buf, "%u\n", session->discovery_sess); in iscsi_session_get_param()
3700 len = sysfs_emit(buf, "%s\n", session->portal_type); in iscsi_session_get_param()
3703 len = sysfs_emit(buf, "%u\n", session->chap_auth_en); in iscsi_session_get_param()
3706 len = sysfs_emit(buf, "%u\n", session->discovery_logout_en); in iscsi_session_get_param()
3709 len = sysfs_emit(buf, "%u\n", session->bidi_chap_en); in iscsi_session_get_param()
3712 len = sysfs_emit(buf, "%u\n", session->discovery_auth_optional); in iscsi_session_get_param()
3715 len = sysfs_emit(buf, "%d\n", session->time2wait); in iscsi_session_get_param()
3718 len = sysfs_emit(buf, "%d\n", session->time2retain); in iscsi_session_get_param()
3721 len = sysfs_emit(buf, "%u\n", session->tsid); in iscsi_session_get_param()
3725 session->isid[0], session->isid[1], in iscsi_session_get_param()
3726 session->isid[2], session->isid[3], in iscsi_session_get_param()
3727 session->isid[4], session->isid[5]); in iscsi_session_get_param()
3730 len = sysfs_emit(buf, "%u\n", session->discovery_parent_idx); in iscsi_session_get_param()
3733 if (session->discovery_parent_type) in iscsi_session_get_param()
3735 session->discovery_parent_type); in iscsi_session_get_param()
3740 return -ENOSYS; in iscsi_session_get_param()
3754 switch (addr->ss_family) { in iscsi_conn_get_addr_param()
3762 return -EINVAL; in iscsi_conn_get_addr_param()
3769 len = sysfs_emit(buf, "%pI4\n", &sin->sin_addr.s_addr); in iscsi_conn_get_addr_param()
3771 len = sysfs_emit(buf, "%pI6\n", &sin6->sin6_addr); in iscsi_conn_get_addr_param()
3776 len = sysfs_emit(buf, "%hu\n", be16_to_cpu(sin->sin_port)); in iscsi_conn_get_addr_param()
3779 be16_to_cpu(sin6->sin6_port)); in iscsi_conn_get_addr_param()
3782 return -EINVAL; in iscsi_conn_get_addr_param()
3792 struct iscsi_conn *conn = cls_conn->dd_data; in iscsi_conn_get_param()
3797 len = sysfs_emit(buf, "%u\n", conn->ping_timeout); in iscsi_conn_get_param()
3800 len = sysfs_emit(buf, "%u\n", conn->recv_timeout); in iscsi_conn_get_param()
3803 len = sysfs_emit(buf, "%u\n", conn->max_recv_dlength); in iscsi_conn_get_param()
3806 len = sysfs_emit(buf, "%u\n", conn->max_xmit_dlength); in iscsi_conn_get_param()
3809 len = sysfs_emit(buf, "%d\n", conn->hdrdgst_en); in iscsi_conn_get_param()
3812 len = sysfs_emit(buf, "%d\n", conn->datadgst_en); in iscsi_conn_get_param()
3815 len = sysfs_emit(buf, "%d\n", conn->ifmarker_en); in iscsi_conn_get_param()
3818 len = sysfs_emit(buf, "%d\n", conn->ofmarker_en); in iscsi_conn_get_param()
3821 len = sysfs_emit(buf, "%u\n", conn->exp_statsn); in iscsi_conn_get_param()
3824 len = sysfs_emit(buf, "%d\n", conn->persistent_port); in iscsi_conn_get_param()
3827 len = sysfs_emit(buf, "%s\n", conn->persistent_address); in iscsi_conn_get_param()
3830 len = sysfs_emit(buf, "%u\n", conn->statsn); in iscsi_conn_get_param()
3833 len = sysfs_emit(buf, "%u\n", conn->max_segment_size); in iscsi_conn_get_param()
3836 len = sysfs_emit(buf, "%u\n", conn->keepalive_tmo); in iscsi_conn_get_param()
3839 len = sysfs_emit(buf, "%u\n", conn->local_port); in iscsi_conn_get_param()
3842 len = sysfs_emit(buf, "%u\n", conn->tcp_timestamp_stat); in iscsi_conn_get_param()
3845 len = sysfs_emit(buf, "%u\n", conn->tcp_nagle_disable); in iscsi_conn_get_param()
3848 len = sysfs_emit(buf, "%u\n", conn->tcp_wsf_disable); in iscsi_conn_get_param()
3851 len = sysfs_emit(buf, "%u\n", conn->tcp_timer_scale); in iscsi_conn_get_param()
3854 len = sysfs_emit(buf, "%u\n", conn->tcp_timestamp_en); in iscsi_conn_get_param()
3857 len = sysfs_emit(buf, "%u\n", conn->fragment_disable); in iscsi_conn_get_param()
3860 len = sysfs_emit(buf, "%u\n", conn->ipv4_tos); in iscsi_conn_get_param()
3863 len = sysfs_emit(buf, "%u\n", conn->ipv6_traffic_class); in iscsi_conn_get_param()
3866 len = sysfs_emit(buf, "%u\n", conn->ipv6_flow_label); in iscsi_conn_get_param()
3869 len = sysfs_emit(buf, "%u\n", conn->is_fw_assigned_ipv6); in iscsi_conn_get_param()
3872 len = sysfs_emit(buf, "%u\n", conn->tcp_xmit_wsf); in iscsi_conn_get_param()
3875 len = sysfs_emit(buf, "%u\n", conn->tcp_recv_wsf); in iscsi_conn_get_param()
3878 len = sysfs_emit(buf, "%s\n", conn->local_ipaddr); in iscsi_conn_get_param()
3881 return -ENOSYS; in iscsi_conn_get_param()
3896 len = sysfs_emit(buf, "%s\n", ihost->netdev); in iscsi_host_get_param()
3899 len = sysfs_emit(buf, "%s\n", ihost->hwaddress); in iscsi_host_get_param()
3902 len = sysfs_emit(buf, "%s\n", ihost->initiatorname); in iscsi_host_get_param()
3905 return -ENOSYS; in iscsi_host_get_param()
3919 return iscsi_switch_str_param(&ihost->netdev, buf); in iscsi_host_set_param()
3921 return iscsi_switch_str_param(&ihost->hwaddress, buf); in iscsi_host_set_param()
3923 return iscsi_switch_str_param(&ihost->initiatorname, buf); in iscsi_host_set_param()
3925 return -ENOSYS; in iscsi_host_set_param()