4 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
5 * Copyright (C) 2004 - 2006 Mike Christie
6 * Copyright (C) 2004 - 2005 Dmitry Yusupov
7 * Copyright (C) 2004 - 2005 Alex Aizman
8 * maintained by open-iscsi@googlegroups.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <linux/types.h>
25 #include <linux/kfifo.h>
26 #include <linux/delay.h>
27 #include <asm/unaligned.h>
29 #include <scsi/scsi_cmnd.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_eh.h>
32 #include <scsi/scsi_tcq.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi.h>
35 #include <scsi/iscsi_proto.h>
36 #include <scsi/scsi_transport.h>
37 #include <scsi/scsi_transport_iscsi.h>
38 #include <scsi/libiscsi.h>
40 struct iscsi_session *
41 class_to_transport_session(struct iscsi_cls_session *cls_session)
43 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
44 return iscsi_hostdata(shost->hostdata);
46 EXPORT_SYMBOL_GPL(class_to_transport_session);
48 /* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
49 #define SNA32_CHECK 2147483648UL
51 static int iscsi_sna_lt(u32 n1, u32 n2)
53 return n1 != n2 && ((n1 < n2 && (n2 - n1 < SNA32_CHECK)) ||
54 (n1 > n2 && (n2 - n1 < SNA32_CHECK)));
57 /* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
58 static int iscsi_sna_lte(u32 n1, u32 n2)
60 return n1 == n2 || ((n1 < n2 && (n2 - n1 < SNA32_CHECK)) ||
61 (n1 > n2 && (n2 - n1 < SNA32_CHECK)));
65 iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr)
67 uint32_t max_cmdsn = be32_to_cpu(hdr->max_cmdsn);
68 uint32_t exp_cmdsn = be32_to_cpu(hdr->exp_cmdsn);
71 * standard specifies this check for when to update expected and
72 * max sequence numbers
74 if (iscsi_sna_lt(max_cmdsn, exp_cmdsn - 1))
77 if (exp_cmdsn != session->exp_cmdsn &&
78 !iscsi_sna_lt(exp_cmdsn, session->exp_cmdsn))
79 session->exp_cmdsn = exp_cmdsn;
81 if (max_cmdsn != session->max_cmdsn &&
82 !iscsi_sna_lt(max_cmdsn, session->max_cmdsn)) {
83 session->max_cmdsn = max_cmdsn;
85 * if the window closed with IO queued, then kick the
88 if (!list_empty(&session->leadconn->xmitqueue) ||
89 !list_empty(&session->leadconn->mgmtqueue))
90 scsi_queue_work(session->host,
91 &session->leadconn->xmitwork);
94 EXPORT_SYMBOL_GPL(iscsi_update_cmdsn);
96 void iscsi_prep_unsolicit_data_pdu(struct iscsi_cmd_task *ctask,
97 struct iscsi_data *hdr)
99 struct iscsi_conn *conn = ctask->conn;
101 memset(hdr, 0, sizeof(struct iscsi_data));
102 hdr->ttt = cpu_to_be32(ISCSI_RESERVED_TAG);
103 hdr->datasn = cpu_to_be32(ctask->unsol_datasn);
104 ctask->unsol_datasn++;
105 hdr->opcode = ISCSI_OP_SCSI_DATA_OUT;
106 memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun));
108 hdr->itt = ctask->hdr->itt;
109 hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
110 hdr->offset = cpu_to_be32(ctask->unsol_offset);
112 if (ctask->unsol_count > conn->max_xmit_dlength) {
113 hton24(hdr->dlength, conn->max_xmit_dlength);
114 ctask->data_count = conn->max_xmit_dlength;
115 ctask->unsol_offset += ctask->data_count;
118 hton24(hdr->dlength, ctask->unsol_count);
119 ctask->data_count = ctask->unsol_count;
120 hdr->flags = ISCSI_FLAG_CMD_FINAL;
123 EXPORT_SYMBOL_GPL(iscsi_prep_unsolicit_data_pdu);
126 * iscsi_prep_scsi_cmd_pdu - prep iscsi scsi cmd pdu
127 * @ctask: iscsi cmd task
129 * Prep basic iSCSI PDU fields for a scsi cmd pdu. The LLD should set
130 * fields like dlength or final based on how much data it sends
132 static void iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
134 struct iscsi_conn *conn = ctask->conn;
135 struct iscsi_session *session = conn->session;
136 struct iscsi_cmd *hdr = ctask->hdr;
137 struct scsi_cmnd *sc = ctask->sc;
139 hdr->opcode = ISCSI_OP_SCSI_CMD;
140 hdr->flags = ISCSI_ATTR_SIMPLE;
141 int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
142 hdr->itt = build_itt(ctask->itt, conn->id, session->age);
143 hdr->data_length = cpu_to_be32(scsi_bufflen(sc));
144 hdr->cmdsn = cpu_to_be32(session->cmdsn);
146 hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
147 memcpy(hdr->cdb, sc->cmnd, sc->cmd_len);
148 if (sc->cmd_len < MAX_COMMAND_SIZE)
149 memset(&hdr->cdb[sc->cmd_len], 0,
150 MAX_COMMAND_SIZE - sc->cmd_len);
152 ctask->data_count = 0;
153 ctask->imm_count = 0;
154 if (sc->sc_data_direction == DMA_TO_DEVICE) {
155 hdr->flags |= ISCSI_FLAG_CMD_WRITE;
159 * imm_count bytes to be sent right after
162 * unsol_count bytes(as Data-Out) to be sent
163 * without R2T ack right after
166 * r2t_data_count bytes to be sent via R2T ack's
168 * pad_count bytes to be sent as zero-padding
170 ctask->unsol_count = 0;
171 ctask->unsol_offset = 0;
172 ctask->unsol_datasn = 0;
174 if (session->imm_data_en) {
175 if (scsi_bufflen(sc) >= session->first_burst)
176 ctask->imm_count = min(session->first_burst,
177 conn->max_xmit_dlength);
179 ctask->imm_count = min(scsi_bufflen(sc),
180 conn->max_xmit_dlength);
181 hton24(ctask->hdr->dlength, ctask->imm_count);
183 zero_data(ctask->hdr->dlength);
185 if (!session->initial_r2t_en) {
186 ctask->unsol_count = min((session->first_burst),
187 (scsi_bufflen(sc))) - ctask->imm_count;
188 ctask->unsol_offset = ctask->imm_count;
191 if (!ctask->unsol_count)
192 /* No unsolicit Data-Out's */
193 ctask->hdr->flags |= ISCSI_FLAG_CMD_FINAL;
195 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
196 zero_data(hdr->dlength);
198 if (sc->sc_data_direction == DMA_FROM_DEVICE)
199 hdr->flags |= ISCSI_FLAG_CMD_READ;
202 conn->scsicmd_pdus_cnt++;
204 debug_scsi("iscsi prep [%s cid %d sc %p cdb 0x%x itt 0x%x len %d "
205 "cmdsn %d win %d]\n",
206 sc->sc_data_direction == DMA_TO_DEVICE ? "write" : "read",
207 conn->id, sc, sc->cmnd[0], ctask->itt, scsi_bufflen(sc),
208 session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1);
212 * iscsi_complete_command - return command back to scsi-ml
213 * @ctask: iscsi cmd task
215 * Must be called with session lock.
216 * This function returns the scsi command to scsi-ml and returns
217 * the cmd task to the pool of available cmd tasks.
219 static void iscsi_complete_command(struct iscsi_cmd_task *ctask)
221 struct iscsi_session *session = ctask->conn->session;
222 struct scsi_cmnd *sc = ctask->sc;
224 ctask->state = ISCSI_TASK_COMPLETED;
226 /* SCSI eh reuses commands to verify us */
228 list_del_init(&ctask->running);
229 __kfifo_put(session->cmdpool.queue, (void*)&ctask, sizeof(void*));
233 static void __iscsi_get_ctask(struct iscsi_cmd_task *ctask)
235 atomic_inc(&ctask->refcount);
238 static void __iscsi_put_ctask(struct iscsi_cmd_task *ctask)
240 if (atomic_dec_and_test(&ctask->refcount))
241 iscsi_complete_command(ctask);
245 * iscsi_cmd_rsp - SCSI Command Response processing
246 * @conn: iscsi connection
248 * @ctask: scsi command task
249 * @data: cmd data buffer
250 * @datalen: len of buffer
252 * iscsi_cmd_rsp sets up the scsi_cmnd fields based on the PDU and
253 * then completes the command and task.
255 static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
256 struct iscsi_cmd_task *ctask, char *data,
259 struct iscsi_cmd_rsp *rhdr = (struct iscsi_cmd_rsp *)hdr;
260 struct iscsi_session *session = conn->session;
261 struct scsi_cmnd *sc = ctask->sc;
263 iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr);
264 conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
266 sc->result = (DID_OK << 16) | rhdr->cmd_status;
268 if (rhdr->response != ISCSI_STATUS_CMD_COMPLETED) {
269 sc->result = DID_ERROR << 16;
273 if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) {
278 printk(KERN_ERR "iscsi: Got CHECK_CONDITION but "
279 "invalid data buffer size of %d\n", datalen);
280 sc->result = DID_BAD_TARGET << 16;
284 senselen = be16_to_cpu(get_unaligned((__be16 *) data));
285 if (datalen < senselen)
286 goto invalid_datalen;
288 memcpy(sc->sense_buffer, data + 2,
289 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
290 debug_scsi("copied %d bytes of sense\n",
291 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
294 if (rhdr->flags & (ISCSI_FLAG_CMD_UNDERFLOW |
295 ISCSI_FLAG_CMD_OVERFLOW)) {
296 int res_count = be32_to_cpu(rhdr->residual_count);
299 (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW ||
300 res_count <= scsi_bufflen(sc)))
301 scsi_set_resid(sc, res_count);
303 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
304 } else if (rhdr->flags & (ISCSI_FLAG_CMD_BIDI_UNDERFLOW |
305 ISCSI_FLAG_CMD_BIDI_OVERFLOW))
306 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
309 debug_scsi("done [sc %lx res %d itt 0x%x]\n",
310 (long)sc, sc->result, ctask->itt);
311 conn->scsirsp_pdus_cnt++;
313 __iscsi_put_ctask(ctask);
316 static void iscsi_tmf_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
318 struct iscsi_tm_rsp *tmf = (struct iscsi_tm_rsp *)hdr;
320 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
321 conn->tmfrsp_pdus_cnt++;
323 if (conn->tmf_state != TMF_QUEUED)
326 if (tmf->response == ISCSI_TMF_RSP_COMPLETE)
327 conn->tmf_state = TMF_SUCCESS;
328 else if (tmf->response == ISCSI_TMF_RSP_NO_TASK)
329 conn->tmf_state = TMF_NOT_FOUND;
331 conn->tmf_state = TMF_FAILED;
332 wake_up(&conn->ehwait);
335 static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
336 char *data, int datalen)
338 struct iscsi_reject *reject = (struct iscsi_reject *)hdr;
339 struct iscsi_hdr rejected_pdu;
342 conn->exp_statsn = be32_to_cpu(reject->statsn) + 1;
344 if (reject->reason == ISCSI_REASON_DATA_DIGEST_ERROR) {
345 if (ntoh24(reject->dlength) > datalen)
346 return ISCSI_ERR_PROTO;
348 if (ntoh24(reject->dlength) >= sizeof(struct iscsi_hdr)) {
349 memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr));
350 itt = get_itt(rejected_pdu.itt);
351 printk(KERN_ERR "itt 0x%x had pdu (op 0x%x) rejected "
352 "due to DataDigest error.\n", itt,
353 rejected_pdu.opcode);
360 * __iscsi_complete_pdu - complete pdu
364 * @datalen: len of data buffer
366 * Completes pdu processing by freeing any resources allocated at
367 * queuecommand or send generic. session lock must be held and verify
368 * itt must have been called.
370 int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
371 char *data, int datalen)
373 struct iscsi_session *session = conn->session;
374 int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0;
375 struct iscsi_cmd_task *ctask;
376 struct iscsi_mgmt_task *mtask;
379 if (hdr->itt != RESERVED_ITT)
380 itt = get_itt(hdr->itt);
384 if (itt < session->cmds_max) {
385 ctask = session->cmds[itt];
387 debug_scsi("cmdrsp [op 0x%x cid %d itt 0x%x len %d]\n",
388 opcode, conn->id, ctask->itt, datalen);
391 case ISCSI_OP_SCSI_CMD_RSP:
392 BUG_ON((void*)ctask != ctask->sc->SCp.ptr);
393 iscsi_scsi_cmd_rsp(conn, hdr, ctask, data,
396 case ISCSI_OP_SCSI_DATA_IN:
397 BUG_ON((void*)ctask != ctask->sc->SCp.ptr);
398 if (hdr->flags & ISCSI_FLAG_DATA_STATUS) {
399 conn->scsirsp_pdus_cnt++;
400 __iscsi_put_ctask(ctask);
404 /* LLD handles this for now */
407 rc = ISCSI_ERR_BAD_OPCODE;
410 } else if (itt >= ISCSI_MGMT_ITT_OFFSET &&
411 itt < ISCSI_MGMT_ITT_OFFSET + session->mgmtpool_max) {
412 mtask = session->mgmt_cmds[itt - ISCSI_MGMT_ITT_OFFSET];
414 debug_scsi("immrsp [op 0x%x cid %d itt 0x%x len %d]\n",
415 opcode, conn->id, mtask->itt, datalen);
417 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
419 case ISCSI_OP_LOGOUT_RSP:
421 rc = ISCSI_ERR_PROTO;
424 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
426 case ISCSI_OP_LOGIN_RSP:
427 case ISCSI_OP_TEXT_RSP:
429 * login related PDU's exp_statsn is handled in
432 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
433 rc = ISCSI_ERR_CONN_FAILED;
434 list_del_init(&mtask->running);
435 if (conn->login_mtask != mtask)
436 __kfifo_put(session->mgmtpool.queue,
437 (void*)&mtask, sizeof(void*));
439 case ISCSI_OP_SCSI_TMFUNC_RSP:
441 rc = ISCSI_ERR_PROTO;
445 iscsi_tmf_rsp(conn, hdr);
447 case ISCSI_OP_NOOP_IN:
448 if (hdr->ttt != cpu_to_be32(ISCSI_RESERVED_TAG) || datalen) {
449 rc = ISCSI_ERR_PROTO;
452 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
454 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
455 rc = ISCSI_ERR_CONN_FAILED;
456 list_del_init(&mtask->running);
457 __kfifo_put(session->mgmtpool.queue,
458 (void*)&mtask, sizeof(void*));
461 rc = ISCSI_ERR_BAD_OPCODE;
464 } else if (itt == ~0U) {
465 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
468 case ISCSI_OP_NOOP_IN:
470 rc = ISCSI_ERR_PROTO;
474 if (hdr->ttt == cpu_to_be32(ISCSI_RESERVED_TAG))
477 if (iscsi_recv_pdu(conn->cls_conn, hdr, NULL, 0))
478 rc = ISCSI_ERR_CONN_FAILED;
480 case ISCSI_OP_REJECT:
481 rc = iscsi_handle_reject(conn, hdr, data, datalen);
483 case ISCSI_OP_ASYNC_EVENT:
484 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
485 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
486 rc = ISCSI_ERR_CONN_FAILED;
489 rc = ISCSI_ERR_BAD_OPCODE;
493 rc = ISCSI_ERR_BAD_ITT;
497 EXPORT_SYMBOL_GPL(__iscsi_complete_pdu);
499 int iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
500 char *data, int datalen)
504 spin_lock(&conn->session->lock);
505 rc = __iscsi_complete_pdu(conn, hdr, data, datalen);
506 spin_unlock(&conn->session->lock);
509 EXPORT_SYMBOL_GPL(iscsi_complete_pdu);
511 /* verify itt (itt encoding: age+cid+itt) */
512 int iscsi_verify_itt(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
515 struct iscsi_session *session = conn->session;
516 struct iscsi_cmd_task *ctask;
519 if (hdr->itt != RESERVED_ITT) {
520 if (((__force u32)hdr->itt & ISCSI_AGE_MASK) !=
521 (session->age << ISCSI_AGE_SHIFT)) {
522 printk(KERN_ERR "iscsi: received itt %x expected "
523 "session age (%x)\n", (__force u32)hdr->itt,
524 session->age & ISCSI_AGE_MASK);
525 return ISCSI_ERR_BAD_ITT;
528 if (((__force u32)hdr->itt & ISCSI_CID_MASK) !=
529 (conn->id << ISCSI_CID_SHIFT)) {
530 printk(KERN_ERR "iscsi: received itt %x, expected "
531 "CID (%x)\n", (__force u32)hdr->itt, conn->id);
532 return ISCSI_ERR_BAD_ITT;
534 itt = get_itt(hdr->itt);
538 if (itt < session->cmds_max) {
539 ctask = session->cmds[itt];
542 printk(KERN_INFO "iscsi: dropping ctask with "
543 "itt 0x%x\n", ctask->itt);
545 return ISCSI_ERR_NO_SCSI_CMD;
548 if (ctask->sc->SCp.phase != session->age) {
549 printk(KERN_ERR "iscsi: ctask's session age %d, "
550 "expected %d\n", ctask->sc->SCp.phase,
552 return ISCSI_ERR_SESSION_FAILED;
559 EXPORT_SYMBOL_GPL(iscsi_verify_itt);
561 void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err)
563 struct iscsi_session *session = conn->session;
566 spin_lock_irqsave(&session->lock, flags);
567 if (session->state == ISCSI_STATE_FAILED) {
568 spin_unlock_irqrestore(&session->lock, flags);
572 if (conn->stop_stage == 0)
573 session->state = ISCSI_STATE_FAILED;
574 spin_unlock_irqrestore(&session->lock, flags);
575 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
576 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
577 iscsi_conn_error(conn->cls_conn, err);
579 EXPORT_SYMBOL_GPL(iscsi_conn_failure);
581 static void iscsi_prep_mtask(struct iscsi_conn *conn,
582 struct iscsi_mgmt_task *mtask)
584 struct iscsi_session *session = conn->session;
585 struct iscsi_hdr *hdr = mtask->hdr;
586 struct iscsi_nopout *nop = (struct iscsi_nopout *)hdr;
588 if (hdr->opcode != (ISCSI_OP_LOGIN | ISCSI_OP_IMMEDIATE) &&
589 hdr->opcode != (ISCSI_OP_TEXT | ISCSI_OP_IMMEDIATE))
590 nop->exp_statsn = cpu_to_be32(conn->exp_statsn);
592 * pre-format CmdSN for outgoing PDU.
594 nop->cmdsn = cpu_to_be32(session->cmdsn);
595 if (hdr->itt != RESERVED_ITT) {
596 hdr->itt = build_itt(mtask->itt, conn->id, session->age);
598 * TODO: We always use immediate, so we never hit this.
599 * If we start to send tmfs or nops as non-immediate then
600 * we should start checking the cmdsn numbers for mgmt tasks.
602 if (conn->c_stage == ISCSI_CONN_STARTED &&
603 !(hdr->opcode & ISCSI_OP_IMMEDIATE)) {
604 session->queued_cmdsn++;
609 if (session->tt->init_mgmt_task)
610 session->tt->init_mgmt_task(conn, mtask);
612 debug_scsi("mgmtpdu [op 0x%x hdr->itt 0x%x datalen %d]\n",
613 hdr->opcode & ISCSI_OPCODE_MASK, hdr->itt,
617 static int iscsi_xmit_mtask(struct iscsi_conn *conn)
619 struct iscsi_hdr *hdr = conn->mtask->hdr;
620 int rc, was_logout = 0;
622 spin_unlock_bh(&conn->session->lock);
623 if ((hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) {
624 conn->session->state = ISCSI_STATE_IN_RECOVERY;
625 iscsi_block_session(session_to_cls(conn->session));
628 rc = conn->session->tt->xmit_mgmt_task(conn, conn->mtask);
629 spin_lock_bh(&conn->session->lock);
633 /* done with this in-progress mtask */
637 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
643 static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn)
645 struct iscsi_session *session = conn->session;
648 * Check for iSCSI window and take care of CmdSN wrap-around
650 if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) {
651 debug_scsi("iSCSI CmdSN closed. ExpCmdSn %u MaxCmdSN %u "
652 "CmdSN %u/%u\n", session->exp_cmdsn,
653 session->max_cmdsn, session->cmdsn,
654 session->queued_cmdsn);
660 static int iscsi_xmit_ctask(struct iscsi_conn *conn)
662 struct iscsi_cmd_task *ctask = conn->ctask;
665 __iscsi_get_ctask(ctask);
666 spin_unlock_bh(&conn->session->lock);
667 rc = conn->session->tt->xmit_cmd_task(conn, ctask);
668 spin_lock_bh(&conn->session->lock);
669 __iscsi_put_ctask(ctask);
671 /* done with this ctask */
677 * iscsi_requeue_ctask - requeue ctask to run from session workqueue
678 * @ctask: ctask to requeue
680 * LLDs that need to run a ctask from the session workqueue should call
681 * this. The session lock must be held.
683 void iscsi_requeue_ctask(struct iscsi_cmd_task *ctask)
685 struct iscsi_conn *conn = ctask->conn;
687 list_move_tail(&ctask->running, &conn->requeue);
688 scsi_queue_work(conn->session->host, &conn->xmitwork);
690 EXPORT_SYMBOL_GPL(iscsi_requeue_ctask);
693 * iscsi_data_xmit - xmit any command into the scheduled connection
694 * @conn: iscsi connection
697 * The function can return -EAGAIN in which case the caller must
698 * re-schedule it again later or recover. '0' return code means
701 static int iscsi_data_xmit(struct iscsi_conn *conn)
705 spin_lock_bh(&conn->session->lock);
706 if (unlikely(conn->suspend_tx)) {
707 debug_scsi("conn %d Tx suspended!\n", conn->id);
708 spin_unlock_bh(&conn->session->lock);
713 rc = iscsi_xmit_ctask(conn);
719 rc = iscsi_xmit_mtask(conn);
725 * process mgmt pdus like nops before commands since we should
726 * only have one nop-out as a ping from us and targets should not
727 * overflow us with nop-ins
730 while (!list_empty(&conn->mgmtqueue)) {
731 conn->mtask = list_entry(conn->mgmtqueue.next,
732 struct iscsi_mgmt_task, running);
733 iscsi_prep_mtask(conn, conn->mtask);
734 list_move_tail(conn->mgmtqueue.next, &conn->mgmt_run_list);
735 rc = iscsi_xmit_mtask(conn);
740 /* process pending command queue */
741 while (!list_empty(&conn->xmitqueue)) {
742 if (conn->tmf_state == TMF_QUEUED)
745 conn->ctask = list_entry(conn->xmitqueue.next,
746 struct iscsi_cmd_task, running);
747 iscsi_prep_scsi_cmd_pdu(conn->ctask);
748 conn->session->tt->init_cmd_task(conn->ctask);
749 conn->ctask->state = ISCSI_TASK_RUNNING;
750 list_move_tail(conn->xmitqueue.next, &conn->run_list);
751 rc = iscsi_xmit_ctask(conn);
755 * we could continuously get new ctask requests so
756 * we need to check the mgmt queue for nops that need to
757 * be sent to aviod starvation
759 if (!list_empty(&conn->mgmtqueue))
763 while (!list_empty(&conn->requeue)) {
764 if (conn->session->fast_abort && conn->tmf_state != TMF_INITIAL)
767 conn->ctask = list_entry(conn->requeue.next,
768 struct iscsi_cmd_task, running);
769 conn->ctask->state = ISCSI_TASK_RUNNING;
770 list_move_tail(conn->requeue.next, &conn->run_list);
771 rc = iscsi_xmit_ctask(conn);
774 if (!list_empty(&conn->mgmtqueue))
777 spin_unlock_bh(&conn->session->lock);
781 if (unlikely(conn->suspend_tx))
783 spin_unlock_bh(&conn->session->lock);
787 static void iscsi_xmitworker(struct work_struct *work)
789 struct iscsi_conn *conn =
790 container_of(work, struct iscsi_conn, xmitwork);
793 * serialize Xmit worker on a per-connection basis.
796 rc = iscsi_data_xmit(conn);
797 } while (rc >= 0 || rc == -EAGAIN);
801 FAILURE_BAD_HOST = 1,
802 FAILURE_SESSION_FAILED,
803 FAILURE_SESSION_FREED,
804 FAILURE_WINDOW_CLOSED,
806 FAILURE_SESSION_TERMINATE,
807 FAILURE_SESSION_IN_RECOVERY,
808 FAILURE_SESSION_RECOVERY_TIMEOUT,
811 int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
813 struct Scsi_Host *host;
815 struct iscsi_session *session;
816 struct iscsi_conn *conn;
817 struct iscsi_cmd_task *ctask = NULL;
819 sc->scsi_done = done;
823 host = sc->device->host;
824 session = iscsi_hostdata(host->hostdata);
826 spin_lock(&session->lock);
829 * ISCSI_STATE_FAILED is a temp. state. The recovery
830 * code will decide what is best to do with command queued
833 if (session->state != ISCSI_STATE_LOGGED_IN &&
834 session->state != ISCSI_STATE_FAILED) {
836 * to handle the race between when we set the recovery state
837 * and block the session we requeue here (commands could
838 * be entering our queuecommand while a block is starting
839 * up because the block code is not locked)
841 if (session->state == ISCSI_STATE_IN_RECOVERY) {
842 reason = FAILURE_SESSION_IN_RECOVERY;
846 if (session->state == ISCSI_STATE_RECOVERY_FAILED)
847 reason = FAILURE_SESSION_RECOVERY_TIMEOUT;
848 else if (session->state == ISCSI_STATE_TERMINATE)
849 reason = FAILURE_SESSION_TERMINATE;
851 reason = FAILURE_SESSION_FREED;
855 conn = session->leadconn;
857 reason = FAILURE_SESSION_FREED;
861 if (iscsi_check_cmdsn_window_closed(conn)) {
862 reason = FAILURE_WINDOW_CLOSED;
866 if (!__kfifo_get(session->cmdpool.queue, (void*)&ctask,
868 reason = FAILURE_OOM;
871 session->queued_cmdsn++;
873 sc->SCp.phase = session->age;
874 sc->SCp.ptr = (char *)ctask;
876 atomic_set(&ctask->refcount, 1);
877 ctask->state = ISCSI_TASK_PENDING;
880 INIT_LIST_HEAD(&ctask->running);
882 list_add_tail(&ctask->running, &conn->xmitqueue);
883 spin_unlock(&session->lock);
885 scsi_queue_work(host, &conn->xmitwork);
889 spin_unlock(&session->lock);
890 debug_scsi("cmd 0x%x rejected (%d)\n", sc->cmnd[0], reason);
891 return SCSI_MLQUEUE_HOST_BUSY;
894 spin_unlock(&session->lock);
895 printk(KERN_ERR "iscsi: cmd 0x%x is not queued (%d)\n",
896 sc->cmnd[0], reason);
897 sc->result = (DID_NO_CONNECT << 16);
898 scsi_set_resid(sc, scsi_bufflen(sc));
902 EXPORT_SYMBOL_GPL(iscsi_queuecommand);
904 int iscsi_change_queue_depth(struct scsi_device *sdev, int depth)
906 if (depth > ISCSI_MAX_CMD_PER_LUN)
907 depth = ISCSI_MAX_CMD_PER_LUN;
908 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
909 return sdev->queue_depth;
911 EXPORT_SYMBOL_GPL(iscsi_change_queue_depth);
913 static struct iscsi_mgmt_task *
914 __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
915 char *data, uint32_t data_size)
917 struct iscsi_session *session = conn->session;
918 struct iscsi_mgmt_task *mtask;
920 if (session->state == ISCSI_STATE_TERMINATE)
923 if (hdr->opcode == (ISCSI_OP_LOGIN | ISCSI_OP_IMMEDIATE) ||
924 hdr->opcode == (ISCSI_OP_TEXT | ISCSI_OP_IMMEDIATE))
926 * Login and Text are sent serially, in
927 * request-followed-by-response sequence.
928 * Same mtask can be used. Same ITT must be used.
929 * Note that login_mtask is preallocated at conn_create().
931 mtask = conn->login_mtask;
933 BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
934 BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
936 if (!__kfifo_get(session->mgmtpool.queue,
937 (void*)&mtask, sizeof(void*)))
942 memcpy(mtask->data, data, data_size);
943 mtask->data_count = data_size;
945 mtask->data_count = 0;
947 memcpy(mtask->hdr, hdr, sizeof(struct iscsi_hdr));
948 INIT_LIST_HEAD(&mtask->running);
949 list_add_tail(&mtask->running, &conn->mgmtqueue);
953 int iscsi_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr,
954 char *data, uint32_t data_size)
956 struct iscsi_conn *conn = cls_conn->dd_data;
957 struct iscsi_session *session = conn->session;
960 spin_lock_bh(&session->lock);
961 if (!__iscsi_conn_send_pdu(conn, hdr, data, data_size))
963 spin_unlock_bh(&session->lock);
964 scsi_queue_work(session->host, &conn->xmitwork);
967 EXPORT_SYMBOL_GPL(iscsi_conn_send_pdu);
969 void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session)
971 struct iscsi_session *session = class_to_transport_session(cls_session);
973 spin_lock_bh(&session->lock);
974 if (session->state != ISCSI_STATE_LOGGED_IN) {
975 session->state = ISCSI_STATE_RECOVERY_FAILED;
976 if (session->leadconn)
977 wake_up(&session->leadconn->ehwait);
979 spin_unlock_bh(&session->lock);
981 EXPORT_SYMBOL_GPL(iscsi_session_recovery_timedout);
983 int iscsi_eh_host_reset(struct scsi_cmnd *sc)
985 struct Scsi_Host *host = sc->device->host;
986 struct iscsi_session *session = iscsi_hostdata(host->hostdata);
987 struct iscsi_conn *conn = session->leadconn;
989 spin_lock_bh(&session->lock);
990 if (session->state == ISCSI_STATE_TERMINATE) {
992 debug_scsi("failing host reset: session terminated "
993 "[CID %d age %d]\n", conn->id, session->age);
994 spin_unlock_bh(&session->lock);
998 spin_unlock_bh(&session->lock);
1001 * we drop the lock here but the leadconn cannot be destoyed while
1002 * we are in the scsi eh
1004 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1006 debug_scsi("iscsi_eh_host_reset wait for relogin\n");
1007 wait_event_interruptible(conn->ehwait,
1008 session->state == ISCSI_STATE_TERMINATE ||
1009 session->state == ISCSI_STATE_LOGGED_IN ||
1010 session->state == ISCSI_STATE_RECOVERY_FAILED);
1011 if (signal_pending(current))
1012 flush_signals(current);
1014 spin_lock_bh(&session->lock);
1015 if (session->state == ISCSI_STATE_LOGGED_IN)
1016 printk(KERN_INFO "iscsi: host reset succeeded\n");
1019 spin_unlock_bh(&session->lock);
1023 EXPORT_SYMBOL_GPL(iscsi_eh_host_reset);
1025 static void iscsi_tmf_timedout(unsigned long data)
1027 struct iscsi_conn *conn = (struct iscsi_conn *)data;
1028 struct iscsi_session *session = conn->session;
1030 spin_lock(&session->lock);
1031 if (conn->tmf_state == TMF_QUEUED) {
1032 conn->tmf_state = TMF_TIMEDOUT;
1033 debug_scsi("tmf timedout\n");
1034 /* unblock eh_abort() */
1035 wake_up(&conn->ehwait);
1037 spin_unlock(&session->lock);
1040 static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
1041 struct iscsi_tm *hdr, int age)
1043 struct iscsi_session *session = conn->session;
1044 struct iscsi_mgmt_task *mtask;
1046 mtask = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)hdr,
1049 spin_unlock_bh(&session->lock);
1050 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1051 spin_lock_bh(&session->lock);
1052 debug_scsi("tmf exec failure\n");
1055 conn->tmfcmd_pdus_cnt++;
1056 conn->tmf_timer.expires = 30 * HZ + jiffies;
1057 conn->tmf_timer.function = iscsi_tmf_timedout;
1058 conn->tmf_timer.data = (unsigned long)conn;
1059 add_timer(&conn->tmf_timer);
1060 debug_scsi("tmf set timeout\n");
1062 spin_unlock_bh(&session->lock);
1063 mutex_unlock(&session->eh_mutex);
1064 scsi_queue_work(session->host, &conn->xmitwork);
1067 * block eh thread until:
1071 * 3) session is terminated or restarted or userspace has
1072 * given up on recovery
1074 wait_event_interruptible(conn->ehwait, age != session->age ||
1075 session->state != ISCSI_STATE_LOGGED_IN ||
1076 conn->tmf_state != TMF_QUEUED);
1077 if (signal_pending(current))
1078 flush_signals(current);
1079 del_timer_sync(&conn->tmf_timer);
1081 mutex_lock(&session->eh_mutex);
1082 spin_lock_bh(&session->lock);
1083 /* if the session drops it will clean up the mtask */
1084 if (age != session->age ||
1085 session->state != ISCSI_STATE_LOGGED_IN)
1088 if (!list_empty(&mtask->running)) {
1089 list_del_init(&mtask->running);
1090 __kfifo_put(session->mgmtpool.queue, (void*)&mtask,
1097 * session lock must be held
1099 static void fail_command(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1102 struct scsi_cmnd *sc;
1108 if (ctask->state == ISCSI_TASK_PENDING)
1110 * cmd never made it to the xmit thread, so we should not count
1111 * the cmd in the sequencing
1113 conn->session->queued_cmdsn--;
1115 conn->session->tt->cleanup_cmd_task(conn, ctask);
1118 scsi_set_resid(sc, scsi_bufflen(sc));
1119 if (conn->ctask == ctask)
1121 /* release ref from queuecommand */
1122 __iscsi_put_ctask(ctask);
1126 * Fail commands. session lock held and recv side suspended and xmit
1129 static void fail_all_commands(struct iscsi_conn *conn, unsigned lun)
1131 struct iscsi_cmd_task *ctask, *tmp;
1133 if (conn->ctask && (conn->ctask->sc->device->lun == lun || lun == -1))
1137 list_for_each_entry_safe(ctask, tmp, &conn->xmitqueue, running) {
1138 if (lun == ctask->sc->device->lun || lun == -1) {
1139 debug_scsi("failing pending sc %p itt 0x%x\n",
1140 ctask->sc, ctask->itt);
1141 fail_command(conn, ctask, DID_BUS_BUSY << 16);
1145 list_for_each_entry_safe(ctask, tmp, &conn->requeue, running) {
1146 if (lun == ctask->sc->device->lun || lun == -1) {
1147 debug_scsi("failing requeued sc %p itt 0x%x\n",
1148 ctask->sc, ctask->itt);
1149 fail_command(conn, ctask, DID_BUS_BUSY << 16);
1153 /* fail all other running */
1154 list_for_each_entry_safe(ctask, tmp, &conn->run_list, running) {
1155 if (lun == ctask->sc->device->lun || lun == -1) {
1156 debug_scsi("failing in progress sc %p itt 0x%x\n",
1157 ctask->sc, ctask->itt);
1158 fail_command(conn, ctask, DID_BUS_BUSY << 16);
1163 static void iscsi_suspend_tx(struct iscsi_conn *conn)
1165 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1166 scsi_flush_work(conn->session->host);
1169 static void iscsi_start_tx(struct iscsi_conn *conn)
1171 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1172 scsi_queue_work(conn->session->host, &conn->xmitwork);
1175 static void iscsi_prep_abort_task_pdu(struct iscsi_cmd_task *ctask,
1176 struct iscsi_tm *hdr)
1178 memset(hdr, 0, sizeof(*hdr));
1179 hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
1180 hdr->flags = ISCSI_TM_FUNC_ABORT_TASK & ISCSI_FLAG_TM_FUNC_MASK;
1181 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
1182 memcpy(hdr->lun, ctask->hdr->lun, sizeof(hdr->lun));
1183 hdr->rtt = ctask->hdr->itt;
1184 hdr->refcmdsn = ctask->hdr->cmdsn;
1187 int iscsi_eh_abort(struct scsi_cmnd *sc)
1189 struct Scsi_Host *host = sc->device->host;
1190 struct iscsi_session *session = iscsi_hostdata(host->hostdata);
1191 struct iscsi_conn *conn;
1192 struct iscsi_cmd_task *ctask;
1193 struct iscsi_tm *hdr;
1196 mutex_lock(&session->eh_mutex);
1197 spin_lock_bh(&session->lock);
1199 * if session was ISCSI_STATE_IN_RECOVERY then we may not have
1203 debug_scsi("sc never reached iscsi layer or it completed.\n");
1204 spin_unlock_bh(&session->lock);
1205 mutex_unlock(&session->eh_mutex);
1210 * If we are not logged in or we have started a new session
1211 * then let the host reset code handle this
1213 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN ||
1214 sc->SCp.phase != session->age) {
1215 spin_unlock_bh(&session->lock);
1216 mutex_unlock(&session->eh_mutex);
1220 conn = session->leadconn;
1221 conn->eh_abort_cnt++;
1224 ctask = (struct iscsi_cmd_task *)sc->SCp.ptr;
1225 debug_scsi("aborting [sc %p itt 0x%x]\n", sc, ctask->itt);
1227 /* ctask completed before time out */
1229 debug_scsi("sc completed while abort in progress\n");
1233 if (ctask->state == ISCSI_TASK_PENDING) {
1234 fail_command(conn, ctask, DID_ABORT << 16);
1238 /* only have one tmf outstanding at a time */
1239 if (conn->tmf_state != TMF_INITIAL)
1241 conn->tmf_state = TMF_QUEUED;
1244 iscsi_prep_abort_task_pdu(ctask, hdr);
1246 if (iscsi_exec_task_mgmt_fn(conn, hdr, age)) {
1251 switch (conn->tmf_state) {
1253 spin_unlock_bh(&session->lock);
1254 iscsi_suspend_tx(conn);
1256 * clean up task if aborted. grab the recv lock as a writer
1258 write_lock_bh(conn->recv_lock);
1259 spin_lock(&session->lock);
1260 fail_command(conn, ctask, DID_ABORT << 16);
1261 conn->tmf_state = TMF_INITIAL;
1262 spin_unlock(&session->lock);
1263 write_unlock_bh(conn->recv_lock);
1264 iscsi_start_tx(conn);
1265 goto success_unlocked;
1267 spin_unlock_bh(&session->lock);
1268 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1269 goto failed_unlocked;
1272 conn->tmf_state = TMF_INITIAL;
1273 /* ctask completed before tmf abort response */
1274 debug_scsi("sc completed while abort in progress\n");
1279 conn->tmf_state = TMF_INITIAL;
1284 spin_unlock_bh(&session->lock);
1286 debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, ctask->itt);
1287 mutex_unlock(&session->eh_mutex);
1291 spin_unlock_bh(&session->lock);
1293 debug_scsi("abort failed [sc %p itt 0x%x]\n", sc,
1294 ctask ? ctask->itt : 0);
1295 mutex_unlock(&session->eh_mutex);
1298 EXPORT_SYMBOL_GPL(iscsi_eh_abort);
1300 static void iscsi_prep_lun_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr)
1302 memset(hdr, 0, sizeof(*hdr));
1303 hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
1304 hdr->flags = ISCSI_TM_FUNC_LOGICAL_UNIT_RESET & ISCSI_FLAG_TM_FUNC_MASK;
1305 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
1306 int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
1307 hdr->rtt = ISCSI_RESERVED_TAG;
1310 int iscsi_eh_device_reset(struct scsi_cmnd *sc)
1312 struct Scsi_Host *host = sc->device->host;
1313 struct iscsi_session *session = iscsi_hostdata(host->hostdata);
1314 struct iscsi_conn *conn;
1315 struct iscsi_tm *hdr;
1318 debug_scsi("LU Reset [sc %p lun %u]\n", sc, sc->device->lun);
1320 mutex_lock(&session->eh_mutex);
1321 spin_lock_bh(&session->lock);
1323 * Just check if we are not logged in. We cannot check for
1324 * the phase because the reset could come from a ioctl.
1326 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
1328 conn = session->leadconn;
1330 /* only have one tmf outstanding at a time */
1331 if (conn->tmf_state != TMF_INITIAL)
1333 conn->tmf_state = TMF_QUEUED;
1336 iscsi_prep_lun_reset_pdu(sc, hdr);
1338 if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age)) {
1343 switch (conn->tmf_state) {
1347 spin_unlock_bh(&session->lock);
1348 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1351 conn->tmf_state = TMF_INITIAL;
1356 spin_unlock_bh(&session->lock);
1358 iscsi_suspend_tx(conn);
1359 /* need to grab the recv lock then session lock */
1360 write_lock_bh(conn->recv_lock);
1361 spin_lock(&session->lock);
1362 fail_all_commands(conn, sc->device->lun);
1363 conn->tmf_state = TMF_INITIAL;
1364 spin_unlock(&session->lock);
1365 write_unlock_bh(conn->recv_lock);
1367 iscsi_start_tx(conn);
1371 spin_unlock_bh(&session->lock);
1373 debug_scsi("iscsi_eh_device_reset %s\n",
1374 rc == SUCCESS ? "SUCCESS" : "FAILED");
1375 mutex_unlock(&session->eh_mutex);
1378 EXPORT_SYMBOL_GPL(iscsi_eh_device_reset);
1381 iscsi_pool_init(struct iscsi_queue *q, int max, void ***items, int item_size)
1385 *items = kmalloc(max * sizeof(void*), GFP_KERNEL);
1390 q->pool = kmalloc(max * sizeof(void*), GFP_KERNEL);
1391 if (q->pool == NULL) {
1396 q->queue = kfifo_init((void*)q->pool, max * sizeof(void*),
1398 if (q->queue == ERR_PTR(-ENOMEM)) {
1404 for (i = 0; i < max; i++) {
1405 q->pool[i] = kmalloc(item_size, GFP_KERNEL);
1406 if (q->pool[i] == NULL) {
1409 for (j = 0; j < i; j++)
1412 kfifo_free(q->queue);
1417 memset(q->pool[i], 0, item_size);
1418 (*items)[i] = q->pool[i];
1419 __kfifo_put(q->queue, (void*)&q->pool[i], sizeof(void*));
1423 EXPORT_SYMBOL_GPL(iscsi_pool_init);
1425 void iscsi_pool_free(struct iscsi_queue *q, void **items)
1429 for (i = 0; i < q->max; i++)
1434 EXPORT_SYMBOL_GPL(iscsi_pool_free);
1437 * iSCSI Session's hostdata organization:
1439 * *------------------* <== hostdata_session(host->hostdata)
1440 * | ptr to class sess|
1441 * |------------------| <== iscsi_hostdata(host->hostdata)
1443 * *------------------*
1446 #define hostdata_privsize(_sz) (sizeof(unsigned long) + _sz + \
1447 _sz % sizeof(unsigned long))
1449 #define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
1452 * iscsi_session_setup - create iscsi cls session and host and session
1453 * @scsit: scsi transport template
1454 * @iscsit: iscsi transport template
1455 * @cmds_max: scsi host can queue
1456 * @qdepth: scsi host cmds per lun
1457 * @cmd_task_size: LLD ctask private data size
1458 * @mgmt_task_size: LLD mtask private data size
1459 * @initial_cmdsn: initial CmdSN
1460 * @hostno: host no allocated
1462 * This can be used by software iscsi_transports that allocate
1463 * a session per scsi host.
1465 struct iscsi_cls_session *
1466 iscsi_session_setup(struct iscsi_transport *iscsit,
1467 struct scsi_transport_template *scsit,
1468 uint16_t cmds_max, uint16_t qdepth,
1469 int cmd_task_size, int mgmt_task_size,
1470 uint32_t initial_cmdsn, uint32_t *hostno)
1472 struct Scsi_Host *shost;
1473 struct iscsi_session *session;
1474 struct iscsi_cls_session *cls_session;
1477 if (qdepth > ISCSI_MAX_CMD_PER_LUN || qdepth < 1) {
1479 printk(KERN_ERR "iscsi: invalid queue depth of %d. "
1480 "Queue depth must be between 1 and %d.\n",
1481 qdepth, ISCSI_MAX_CMD_PER_LUN);
1482 qdepth = ISCSI_DEF_CMD_PER_LUN;
1485 if (cmds_max < 2 || (cmds_max & (cmds_max - 1)) ||
1486 cmds_max >= ISCSI_MGMT_ITT_OFFSET) {
1488 printk(KERN_ERR "iscsi: invalid can_queue of %d. "
1489 "can_queue must be a power of 2 and between "
1490 "2 and %d - setting to %d.\n", cmds_max,
1491 ISCSI_MGMT_ITT_OFFSET, ISCSI_DEF_XMIT_CMDS_MAX);
1492 cmds_max = ISCSI_DEF_XMIT_CMDS_MAX;
1495 shost = scsi_host_alloc(iscsit->host_template,
1496 hostdata_privsize(sizeof(*session)));
1500 /* the iscsi layer takes one task for reserve */
1501 shost->can_queue = cmds_max - 1;
1502 shost->cmd_per_lun = qdepth;
1504 shost->max_channel = 0;
1505 shost->max_lun = iscsit->max_lun;
1506 shost->max_cmd_len = iscsit->max_cmd_len;
1507 shost->transportt = scsit;
1508 shost->transportt->create_work_queue = 1;
1509 *hostno = shost->host_no;
1511 session = iscsi_hostdata(shost->hostdata);
1512 memset(session, 0, sizeof(struct iscsi_session));
1513 session->host = shost;
1514 session->state = ISCSI_STATE_FREE;
1515 session->mgmtpool_max = ISCSI_MGMT_CMDS_MAX;
1516 session->cmds_max = cmds_max;
1517 session->queued_cmdsn = session->cmdsn = initial_cmdsn;
1518 session->exp_cmdsn = initial_cmdsn + 1;
1519 session->max_cmdsn = initial_cmdsn + 1;
1520 session->max_r2t = 1;
1521 session->tt = iscsit;
1522 mutex_init(&session->eh_mutex);
1524 /* initialize SCSI PDU commands pool */
1525 if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
1526 (void***)&session->cmds,
1527 cmd_task_size + sizeof(struct iscsi_cmd_task)))
1528 goto cmdpool_alloc_fail;
1530 /* pre-format cmds pool with ITT */
1531 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
1532 struct iscsi_cmd_task *ctask = session->cmds[cmd_i];
1535 ctask->dd_data = &ctask[1];
1537 INIT_LIST_HEAD(&ctask->running);
1540 spin_lock_init(&session->lock);
1542 /* initialize immediate command pool */
1543 if (iscsi_pool_init(&session->mgmtpool, session->mgmtpool_max,
1544 (void***)&session->mgmt_cmds,
1545 mgmt_task_size + sizeof(struct iscsi_mgmt_task)))
1546 goto mgmtpool_alloc_fail;
1549 /* pre-format immediate cmds pool with ITT */
1550 for (cmd_i = 0; cmd_i < session->mgmtpool_max; cmd_i++) {
1551 struct iscsi_mgmt_task *mtask = session->mgmt_cmds[cmd_i];
1554 mtask->dd_data = &mtask[1];
1555 mtask->itt = ISCSI_MGMT_ITT_OFFSET + cmd_i;
1556 INIT_LIST_HEAD(&mtask->running);
1559 if (scsi_add_host(shost, NULL))
1562 if (!try_module_get(iscsit->owner))
1563 goto cls_session_fail;
1565 cls_session = iscsi_create_session(shost, iscsit, 0);
1568 *(unsigned long*)shost->hostdata = (unsigned long)cls_session;
1573 module_put(iscsit->owner);
1575 scsi_remove_host(shost);
1577 iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
1578 mgmtpool_alloc_fail:
1579 iscsi_pool_free(&session->cmdpool, (void**)session->cmds);
1581 scsi_host_put(shost);
1584 EXPORT_SYMBOL_GPL(iscsi_session_setup);
1587 * iscsi_session_teardown - destroy session, host, and cls_session
1590 * This can be used by software iscsi_transports that allocate
1591 * a session per scsi host.
1593 void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
1595 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1596 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1597 struct module *owner = cls_session->transport->owner;
1599 iscsi_unblock_session(cls_session);
1600 scsi_remove_host(shost);
1602 iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
1603 iscsi_pool_free(&session->cmdpool, (void**)session->cmds);
1605 kfree(session->password);
1606 kfree(session->password_in);
1607 kfree(session->username);
1608 kfree(session->username_in);
1609 kfree(session->targetname);
1610 kfree(session->netdev);
1611 kfree(session->hwaddress);
1612 kfree(session->initiatorname);
1614 iscsi_destroy_session(cls_session);
1615 scsi_host_put(shost);
1618 EXPORT_SYMBOL_GPL(iscsi_session_teardown);
1621 * iscsi_conn_setup - create iscsi_cls_conn and iscsi_conn
1622 * @cls_session: iscsi_cls_session
1625 struct iscsi_cls_conn *
1626 iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1628 struct iscsi_session *session = class_to_transport_session(cls_session);
1629 struct iscsi_conn *conn;
1630 struct iscsi_cls_conn *cls_conn;
1633 cls_conn = iscsi_create_conn(cls_session, conn_idx);
1636 conn = cls_conn->dd_data;
1637 memset(conn, 0, sizeof(*conn));
1639 conn->session = session;
1640 conn->cls_conn = cls_conn;
1641 conn->c_stage = ISCSI_CONN_INITIAL_STAGE;
1642 conn->id = conn_idx;
1643 conn->exp_statsn = 0;
1644 conn->tmf_state = TMF_INITIAL;
1645 INIT_LIST_HEAD(&conn->run_list);
1646 INIT_LIST_HEAD(&conn->mgmt_run_list);
1647 INIT_LIST_HEAD(&conn->mgmtqueue);
1648 INIT_LIST_HEAD(&conn->xmitqueue);
1649 INIT_LIST_HEAD(&conn->requeue);
1650 INIT_WORK(&conn->xmitwork, iscsi_xmitworker);
1652 /* allocate login_mtask used for the login/text sequences */
1653 spin_lock_bh(&session->lock);
1654 if (!__kfifo_get(session->mgmtpool.queue,
1655 (void*)&conn->login_mtask,
1657 spin_unlock_bh(&session->lock);
1658 goto login_mtask_alloc_fail;
1660 spin_unlock_bh(&session->lock);
1662 data = kmalloc(ISCSI_DEF_MAX_RECV_SEG_LEN, GFP_KERNEL);
1664 goto login_mtask_data_alloc_fail;
1665 conn->login_mtask->data = conn->data = data;
1667 init_timer(&conn->tmf_timer);
1668 init_waitqueue_head(&conn->ehwait);
1672 login_mtask_data_alloc_fail:
1673 __kfifo_put(session->mgmtpool.queue, (void*)&conn->login_mtask,
1675 login_mtask_alloc_fail:
1676 iscsi_destroy_conn(cls_conn);
1679 EXPORT_SYMBOL_GPL(iscsi_conn_setup);
1682 * iscsi_conn_teardown - teardown iscsi connection
1683 * cls_conn: iscsi class connection
1685 * TODO: we may need to make this into a two step process
1686 * like scsi-mls remove + put host
1688 void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
1690 struct iscsi_conn *conn = cls_conn->dd_data;
1691 struct iscsi_session *session = conn->session;
1692 unsigned long flags;
1694 spin_lock_bh(&session->lock);
1695 conn->c_stage = ISCSI_CONN_CLEANUP_WAIT;
1696 if (session->leadconn == conn) {
1698 * leading connection? then give up on recovery.
1700 session->state = ISCSI_STATE_TERMINATE;
1701 wake_up(&conn->ehwait);
1703 spin_unlock_bh(&session->lock);
1706 * Block until all in-progress commands for this connection
1710 spin_lock_irqsave(session->host->host_lock, flags);
1711 if (!session->host->host_busy) { /* OK for ERL == 0 */
1712 spin_unlock_irqrestore(session->host->host_lock, flags);
1715 spin_unlock_irqrestore(session->host->host_lock, flags);
1716 msleep_interruptible(500);
1717 printk(KERN_INFO "iscsi: scsi conn_destroy(): host_busy %d "
1718 "host_failed %d\n", session->host->host_busy,
1719 session->host->host_failed);
1721 * force eh_abort() to unblock
1723 wake_up(&conn->ehwait);
1726 /* flush queued up work because we free the connection below */
1727 iscsi_suspend_tx(conn);
1729 spin_lock_bh(&session->lock);
1731 kfree(conn->persistent_address);
1732 __kfifo_put(session->mgmtpool.queue, (void*)&conn->login_mtask,
1734 if (session->leadconn == conn)
1735 session->leadconn = NULL;
1736 spin_unlock_bh(&session->lock);
1738 iscsi_destroy_conn(cls_conn);
1740 EXPORT_SYMBOL_GPL(iscsi_conn_teardown);
1742 int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
1744 struct iscsi_conn *conn = cls_conn->dd_data;
1745 struct iscsi_session *session = conn->session;
1748 printk(KERN_ERR "iscsi: can't start unbound connection\n");
1752 if ((session->imm_data_en || !session->initial_r2t_en) &&
1753 session->first_burst > session->max_burst) {
1754 printk("iscsi: invalid burst lengths: "
1755 "first_burst %d max_burst %d\n",
1756 session->first_burst, session->max_burst);
1760 spin_lock_bh(&session->lock);
1761 conn->c_stage = ISCSI_CONN_STARTED;
1762 session->state = ISCSI_STATE_LOGGED_IN;
1763 session->queued_cmdsn = session->cmdsn;
1765 switch(conn->stop_stage) {
1766 case STOP_CONN_RECOVER:
1768 * unblock eh_abort() if it is blocked. re-try all
1769 * commands after successful recovery
1771 conn->stop_stage = 0;
1772 conn->tmf_state = TMF_INITIAL;
1774 spin_unlock_bh(&session->lock);
1776 iscsi_unblock_session(session_to_cls(session));
1777 wake_up(&conn->ehwait);
1779 case STOP_CONN_TERM:
1780 conn->stop_stage = 0;
1785 spin_unlock_bh(&session->lock);
1789 EXPORT_SYMBOL_GPL(iscsi_conn_start);
1792 flush_control_queues(struct iscsi_session *session, struct iscsi_conn *conn)
1794 struct iscsi_mgmt_task *mtask, *tmp;
1796 /* handle pending */
1797 list_for_each_entry_safe(mtask, tmp, &conn->mgmtqueue, running) {
1798 debug_scsi("flushing pending mgmt task itt 0x%x\n", mtask->itt);
1799 list_del_init(&mtask->running);
1800 if (mtask == conn->login_mtask)
1802 __kfifo_put(session->mgmtpool.queue, (void*)&mtask,
1806 /* handle running */
1807 list_for_each_entry_safe(mtask, tmp, &conn->mgmt_run_list, running) {
1808 debug_scsi("flushing running mgmt task itt 0x%x\n", mtask->itt);
1809 list_del_init(&mtask->running);
1811 if (mtask == conn->login_mtask)
1813 __kfifo_put(session->mgmtpool.queue, (void*)&mtask,
1820 static void iscsi_start_session_recovery(struct iscsi_session *session,
1821 struct iscsi_conn *conn, int flag)
1825 mutex_lock(&session->eh_mutex);
1826 spin_lock_bh(&session->lock);
1827 if (conn->stop_stage == STOP_CONN_TERM) {
1828 spin_unlock_bh(&session->lock);
1829 mutex_unlock(&session->eh_mutex);
1834 * The LLD either freed/unset the lock on us, or userspace called
1835 * stop but did not create a proper connection (connection was never
1836 * bound or it was unbound then stop was called).
1838 if (!conn->recv_lock) {
1839 spin_unlock_bh(&session->lock);
1840 mutex_unlock(&session->eh_mutex);
1845 * When this is called for the in_login state, we only want to clean
1846 * up the login task and connection. We do not need to block and set
1847 * the recovery state again
1849 if (flag == STOP_CONN_TERM)
1850 session->state = ISCSI_STATE_TERMINATE;
1851 else if (conn->stop_stage != STOP_CONN_RECOVER)
1852 session->state = ISCSI_STATE_IN_RECOVERY;
1854 old_stop_stage = conn->stop_stage;
1855 conn->stop_stage = flag;
1856 conn->c_stage = ISCSI_CONN_STOPPED;
1857 spin_unlock_bh(&session->lock);
1859 iscsi_suspend_tx(conn);
1861 write_lock_bh(conn->recv_lock);
1862 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
1863 write_unlock_bh(conn->recv_lock);
1866 * for connection level recovery we should not calculate
1867 * header digest. conn->hdr_size used for optimization
1868 * in hdr_extract() and will be re-negotiated at
1871 if (flag == STOP_CONN_RECOVER) {
1872 conn->hdrdgst_en = 0;
1873 conn->datadgst_en = 0;
1874 if (session->state == ISCSI_STATE_IN_RECOVERY &&
1875 old_stop_stage != STOP_CONN_RECOVER) {
1876 debug_scsi("blocking session\n");
1877 iscsi_block_session(session_to_cls(session));
1884 spin_lock_bh(&session->lock);
1885 fail_all_commands(conn, -1);
1886 flush_control_queues(session, conn);
1887 spin_unlock_bh(&session->lock);
1888 mutex_unlock(&session->eh_mutex);
1891 void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
1893 struct iscsi_conn *conn = cls_conn->dd_data;
1894 struct iscsi_session *session = conn->session;
1897 case STOP_CONN_RECOVER:
1898 case STOP_CONN_TERM:
1899 iscsi_start_session_recovery(session, conn, flag);
1902 printk(KERN_ERR "iscsi: invalid stop flag %d\n", flag);
1905 EXPORT_SYMBOL_GPL(iscsi_conn_stop);
1907 int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
1908 struct iscsi_cls_conn *cls_conn, int is_leading)
1910 struct iscsi_session *session = class_to_transport_session(cls_session);
1911 struct iscsi_conn *conn = cls_conn->dd_data;
1913 spin_lock_bh(&session->lock);
1915 session->leadconn = conn;
1916 spin_unlock_bh(&session->lock);
1919 * Unblock xmitworker(), Login Phase will pass through.
1921 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
1922 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1925 EXPORT_SYMBOL_GPL(iscsi_conn_bind);
1928 int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
1929 enum iscsi_param param, char *buf, int buflen)
1931 struct iscsi_conn *conn = cls_conn->dd_data;
1932 struct iscsi_session *session = conn->session;
1936 case ISCSI_PARAM_FAST_ABORT:
1937 sscanf(buf, "%d", &session->fast_abort);
1939 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1940 sscanf(buf, "%d", &conn->max_recv_dlength);
1942 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1943 sscanf(buf, "%d", &conn->max_xmit_dlength);
1945 case ISCSI_PARAM_HDRDGST_EN:
1946 sscanf(buf, "%d", &conn->hdrdgst_en);
1948 case ISCSI_PARAM_DATADGST_EN:
1949 sscanf(buf, "%d", &conn->datadgst_en);
1951 case ISCSI_PARAM_INITIAL_R2T_EN:
1952 sscanf(buf, "%d", &session->initial_r2t_en);
1954 case ISCSI_PARAM_MAX_R2T:
1955 sscanf(buf, "%d", &session->max_r2t);
1957 case ISCSI_PARAM_IMM_DATA_EN:
1958 sscanf(buf, "%d", &session->imm_data_en);
1960 case ISCSI_PARAM_FIRST_BURST:
1961 sscanf(buf, "%d", &session->first_burst);
1963 case ISCSI_PARAM_MAX_BURST:
1964 sscanf(buf, "%d", &session->max_burst);
1966 case ISCSI_PARAM_PDU_INORDER_EN:
1967 sscanf(buf, "%d", &session->pdu_inorder_en);
1969 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1970 sscanf(buf, "%d", &session->dataseq_inorder_en);
1972 case ISCSI_PARAM_ERL:
1973 sscanf(buf, "%d", &session->erl);
1975 case ISCSI_PARAM_IFMARKER_EN:
1976 sscanf(buf, "%d", &value);
1979 case ISCSI_PARAM_OFMARKER_EN:
1980 sscanf(buf, "%d", &value);
1983 case ISCSI_PARAM_EXP_STATSN:
1984 sscanf(buf, "%u", &conn->exp_statsn);
1986 case ISCSI_PARAM_USERNAME:
1987 kfree(session->username);
1988 session->username = kstrdup(buf, GFP_KERNEL);
1989 if (!session->username)
1992 case ISCSI_PARAM_USERNAME_IN:
1993 kfree(session->username_in);
1994 session->username_in = kstrdup(buf, GFP_KERNEL);
1995 if (!session->username_in)
1998 case ISCSI_PARAM_PASSWORD:
1999 kfree(session->password);
2000 session->password = kstrdup(buf, GFP_KERNEL);
2001 if (!session->password)
2004 case ISCSI_PARAM_PASSWORD_IN:
2005 kfree(session->password_in);
2006 session->password_in = kstrdup(buf, GFP_KERNEL);
2007 if (!session->password_in)
2010 case ISCSI_PARAM_TARGET_NAME:
2011 /* this should not change between logins */
2012 if (session->targetname)
2015 session->targetname = kstrdup(buf, GFP_KERNEL);
2016 if (!session->targetname)
2019 case ISCSI_PARAM_TPGT:
2020 sscanf(buf, "%d", &session->tpgt);
2022 case ISCSI_PARAM_PERSISTENT_PORT:
2023 sscanf(buf, "%d", &conn->persistent_port);
2025 case ISCSI_PARAM_PERSISTENT_ADDRESS:
2027 * this is the address returned in discovery so it should
2028 * not change between logins.
2030 if (conn->persistent_address)
2033 conn->persistent_address = kstrdup(buf, GFP_KERNEL);
2034 if (!conn->persistent_address)
2043 EXPORT_SYMBOL_GPL(iscsi_set_param);
2045 int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
2046 enum iscsi_param param, char *buf)
2048 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
2049 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
2053 case ISCSI_PARAM_FAST_ABORT:
2054 len = sprintf(buf, "%d\n", session->fast_abort);
2056 case ISCSI_PARAM_INITIAL_R2T_EN:
2057 len = sprintf(buf, "%d\n", session->initial_r2t_en);
2059 case ISCSI_PARAM_MAX_R2T:
2060 len = sprintf(buf, "%hu\n", session->max_r2t);
2062 case ISCSI_PARAM_IMM_DATA_EN:
2063 len = sprintf(buf, "%d\n", session->imm_data_en);
2065 case ISCSI_PARAM_FIRST_BURST:
2066 len = sprintf(buf, "%u\n", session->first_burst);
2068 case ISCSI_PARAM_MAX_BURST:
2069 len = sprintf(buf, "%u\n", session->max_burst);
2071 case ISCSI_PARAM_PDU_INORDER_EN:
2072 len = sprintf(buf, "%d\n", session->pdu_inorder_en);
2074 case ISCSI_PARAM_DATASEQ_INORDER_EN:
2075 len = sprintf(buf, "%d\n", session->dataseq_inorder_en);
2077 case ISCSI_PARAM_ERL:
2078 len = sprintf(buf, "%d\n", session->erl);
2080 case ISCSI_PARAM_TARGET_NAME:
2081 len = sprintf(buf, "%s\n", session->targetname);
2083 case ISCSI_PARAM_TPGT:
2084 len = sprintf(buf, "%d\n", session->tpgt);
2086 case ISCSI_PARAM_USERNAME:
2087 len = sprintf(buf, "%s\n", session->username);
2089 case ISCSI_PARAM_USERNAME_IN:
2090 len = sprintf(buf, "%s\n", session->username_in);
2092 case ISCSI_PARAM_PASSWORD:
2093 len = sprintf(buf, "%s\n", session->password);
2095 case ISCSI_PARAM_PASSWORD_IN:
2096 len = sprintf(buf, "%s\n", session->password_in);
2104 EXPORT_SYMBOL_GPL(iscsi_session_get_param);
2106 int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
2107 enum iscsi_param param, char *buf)
2109 struct iscsi_conn *conn = cls_conn->dd_data;
2113 case ISCSI_PARAM_MAX_RECV_DLENGTH:
2114 len = sprintf(buf, "%u\n", conn->max_recv_dlength);
2116 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
2117 len = sprintf(buf, "%u\n", conn->max_xmit_dlength);
2119 case ISCSI_PARAM_HDRDGST_EN:
2120 len = sprintf(buf, "%d\n", conn->hdrdgst_en);
2122 case ISCSI_PARAM_DATADGST_EN:
2123 len = sprintf(buf, "%d\n", conn->datadgst_en);
2125 case ISCSI_PARAM_IFMARKER_EN:
2126 len = sprintf(buf, "%d\n", conn->ifmarker_en);
2128 case ISCSI_PARAM_OFMARKER_EN:
2129 len = sprintf(buf, "%d\n", conn->ofmarker_en);
2131 case ISCSI_PARAM_EXP_STATSN:
2132 len = sprintf(buf, "%u\n", conn->exp_statsn);
2134 case ISCSI_PARAM_PERSISTENT_PORT:
2135 len = sprintf(buf, "%d\n", conn->persistent_port);
2137 case ISCSI_PARAM_PERSISTENT_ADDRESS:
2138 len = sprintf(buf, "%s\n", conn->persistent_address);
2146 EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
2148 int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
2151 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
2155 case ISCSI_HOST_PARAM_NETDEV_NAME:
2156 if (!session->netdev)
2157 len = sprintf(buf, "%s\n", "default");
2159 len = sprintf(buf, "%s\n", session->netdev);
2161 case ISCSI_HOST_PARAM_HWADDRESS:
2162 if (!session->hwaddress)
2163 len = sprintf(buf, "%s\n", "default");
2165 len = sprintf(buf, "%s\n", session->hwaddress);
2167 case ISCSI_HOST_PARAM_INITIATOR_NAME:
2168 if (!session->initiatorname)
2169 len = sprintf(buf, "%s\n", "unknown");
2171 len = sprintf(buf, "%s\n", session->initiatorname);
2180 EXPORT_SYMBOL_GPL(iscsi_host_get_param);
2182 int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param,
2183 char *buf, int buflen)
2185 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
2188 case ISCSI_HOST_PARAM_NETDEV_NAME:
2189 if (!session->netdev)
2190 session->netdev = kstrdup(buf, GFP_KERNEL);
2192 case ISCSI_HOST_PARAM_HWADDRESS:
2193 if (!session->hwaddress)
2194 session->hwaddress = kstrdup(buf, GFP_KERNEL);
2196 case ISCSI_HOST_PARAM_INITIATOR_NAME:
2197 if (!session->initiatorname)
2198 session->initiatorname = kstrdup(buf, GFP_KERNEL);
2206 EXPORT_SYMBOL_GPL(iscsi_host_set_param);
2208 MODULE_AUTHOR("Mike Christie");
2209 MODULE_DESCRIPTION("iSCSI library functions");
2210 MODULE_LICENSE("GPL");