]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/scsi/libiscsi.c
UBUNTU: Ubuntu-5.11.0-22.23
[mirror_ubuntu-hirsute-kernel.git] / drivers / scsi / libiscsi.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * iSCSI lib functions
4 *
5 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
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
10 */
11 #include <linux/types.h>
12 #include <linux/kfifo.h>
13 #include <linux/delay.h>
14 #include <linux/log2.h>
15 #include <linux/slab.h>
16 #include <linux/sched/signal.h>
17 #include <linux/module.h>
18 #include <asm/unaligned.h>
19 #include <net/tcp.h>
20 #include <scsi/scsi_cmnd.h>
21 #include <scsi/scsi_device.h>
22 #include <scsi/scsi_eh.h>
23 #include <scsi/scsi_tcq.h>
24 #include <scsi/scsi_host.h>
25 #include <scsi/scsi.h>
26 #include <scsi/iscsi_proto.h>
27 #include <scsi/scsi_transport.h>
28 #include <scsi/scsi_transport_iscsi.h>
29 #include <scsi/libiscsi.h>
30 #include <trace/events/iscsi.h>
31
32 static int iscsi_dbg_lib_conn;
33 module_param_named(debug_libiscsi_conn, iscsi_dbg_lib_conn, int,
34 S_IRUGO | S_IWUSR);
35 MODULE_PARM_DESC(debug_libiscsi_conn,
36 "Turn on debugging for connections in libiscsi module. "
37 "Set to 1 to turn on, and zero to turn off. Default is off.");
38
39 static int iscsi_dbg_lib_session;
40 module_param_named(debug_libiscsi_session, iscsi_dbg_lib_session, int,
41 S_IRUGO | S_IWUSR);
42 MODULE_PARM_DESC(debug_libiscsi_session,
43 "Turn on debugging for sessions in libiscsi module. "
44 "Set to 1 to turn on, and zero to turn off. Default is off.");
45
46 static int iscsi_dbg_lib_eh;
47 module_param_named(debug_libiscsi_eh, iscsi_dbg_lib_eh, int,
48 S_IRUGO | S_IWUSR);
49 MODULE_PARM_DESC(debug_libiscsi_eh,
50 "Turn on debugging for error handling in libiscsi module. "
51 "Set to 1 to turn on, and zero to turn off. Default is off.");
52
53 #define ISCSI_DBG_CONN(_conn, dbg_fmt, arg...) \
54 do { \
55 if (iscsi_dbg_lib_conn) \
56 iscsi_conn_printk(KERN_INFO, _conn, \
57 "%s " dbg_fmt, \
58 __func__, ##arg); \
59 iscsi_dbg_trace(trace_iscsi_dbg_conn, \
60 &(_conn)->cls_conn->dev, \
61 "%s " dbg_fmt, __func__, ##arg);\
62 } while (0);
63
64 #define ISCSI_DBG_SESSION(_session, dbg_fmt, arg...) \
65 do { \
66 if (iscsi_dbg_lib_session) \
67 iscsi_session_printk(KERN_INFO, _session, \
68 "%s " dbg_fmt, \
69 __func__, ##arg); \
70 iscsi_dbg_trace(trace_iscsi_dbg_session, \
71 &(_session)->cls_session->dev, \
72 "%s " dbg_fmt, __func__, ##arg); \
73 } while (0);
74
75 #define ISCSI_DBG_EH(_session, dbg_fmt, arg...) \
76 do { \
77 if (iscsi_dbg_lib_eh) \
78 iscsi_session_printk(KERN_INFO, _session, \
79 "%s " dbg_fmt, \
80 __func__, ##arg); \
81 iscsi_dbg_trace(trace_iscsi_dbg_eh, \
82 &(_session)->cls_session->dev, \
83 "%s " dbg_fmt, __func__, ##arg); \
84 } while (0);
85
86 inline void iscsi_conn_queue_work(struct iscsi_conn *conn)
87 {
88 struct Scsi_Host *shost = conn->session->host;
89 struct iscsi_host *ihost = shost_priv(shost);
90
91 if (ihost->workq)
92 queue_work(ihost->workq, &conn->xmitwork);
93 }
94 EXPORT_SYMBOL_GPL(iscsi_conn_queue_work);
95
96 static void __iscsi_update_cmdsn(struct iscsi_session *session,
97 uint32_t exp_cmdsn, uint32_t max_cmdsn)
98 {
99 /*
100 * standard specifies this check for when to update expected and
101 * max sequence numbers
102 */
103 if (iscsi_sna_lt(max_cmdsn, exp_cmdsn - 1))
104 return;
105
106 if (exp_cmdsn != session->exp_cmdsn &&
107 !iscsi_sna_lt(exp_cmdsn, session->exp_cmdsn))
108 session->exp_cmdsn = exp_cmdsn;
109
110 if (max_cmdsn != session->max_cmdsn &&
111 !iscsi_sna_lt(max_cmdsn, session->max_cmdsn))
112 session->max_cmdsn = max_cmdsn;
113 }
114
115 void iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr)
116 {
117 __iscsi_update_cmdsn(session, be32_to_cpu(hdr->exp_cmdsn),
118 be32_to_cpu(hdr->max_cmdsn));
119 }
120 EXPORT_SYMBOL_GPL(iscsi_update_cmdsn);
121
122 /**
123 * iscsi_prep_data_out_pdu - initialize Data-Out
124 * @task: scsi command task
125 * @r2t: R2T info
126 * @hdr: iscsi data in pdu
127 *
128 * Notes:
129 * Initialize Data-Out within this R2T sequence and finds
130 * proper data_offset within this SCSI command.
131 *
132 * This function is called with connection lock taken.
133 **/
134 void iscsi_prep_data_out_pdu(struct iscsi_task *task, struct iscsi_r2t_info *r2t,
135 struct iscsi_data *hdr)
136 {
137 struct iscsi_conn *conn = task->conn;
138 unsigned int left = r2t->data_length - r2t->sent;
139
140 task->hdr_len = sizeof(struct iscsi_data);
141
142 memset(hdr, 0, sizeof(struct iscsi_data));
143 hdr->ttt = r2t->ttt;
144 hdr->datasn = cpu_to_be32(r2t->datasn);
145 r2t->datasn++;
146 hdr->opcode = ISCSI_OP_SCSI_DATA_OUT;
147 hdr->lun = task->lun;
148 hdr->itt = task->hdr_itt;
149 hdr->exp_statsn = r2t->exp_statsn;
150 hdr->offset = cpu_to_be32(r2t->data_offset + r2t->sent);
151 if (left > conn->max_xmit_dlength) {
152 hton24(hdr->dlength, conn->max_xmit_dlength);
153 r2t->data_count = conn->max_xmit_dlength;
154 hdr->flags = 0;
155 } else {
156 hton24(hdr->dlength, left);
157 r2t->data_count = left;
158 hdr->flags = ISCSI_FLAG_CMD_FINAL;
159 }
160 conn->dataout_pdus_cnt++;
161 }
162 EXPORT_SYMBOL_GPL(iscsi_prep_data_out_pdu);
163
164 static int iscsi_add_hdr(struct iscsi_task *task, unsigned len)
165 {
166 unsigned exp_len = task->hdr_len + len;
167
168 if (exp_len > task->hdr_max) {
169 WARN_ON(1);
170 return -EINVAL;
171 }
172
173 WARN_ON(len & (ISCSI_PAD_LEN - 1)); /* caller must pad the AHS */
174 task->hdr_len = exp_len;
175 return 0;
176 }
177
178 /*
179 * make an extended cdb AHS
180 */
181 static int iscsi_prep_ecdb_ahs(struct iscsi_task *task)
182 {
183 struct scsi_cmnd *cmd = task->sc;
184 unsigned rlen, pad_len;
185 unsigned short ahslength;
186 struct iscsi_ecdb_ahdr *ecdb_ahdr;
187 int rc;
188
189 ecdb_ahdr = iscsi_next_hdr(task);
190 rlen = cmd->cmd_len - ISCSI_CDB_SIZE;
191
192 BUG_ON(rlen > sizeof(ecdb_ahdr->ecdb));
193 ahslength = rlen + sizeof(ecdb_ahdr->reserved);
194
195 pad_len = iscsi_padding(rlen);
196
197 rc = iscsi_add_hdr(task, sizeof(ecdb_ahdr->ahslength) +
198 sizeof(ecdb_ahdr->ahstype) + ahslength + pad_len);
199 if (rc)
200 return rc;
201
202 if (pad_len)
203 memset(&ecdb_ahdr->ecdb[rlen], 0, pad_len);
204
205 ecdb_ahdr->ahslength = cpu_to_be16(ahslength);
206 ecdb_ahdr->ahstype = ISCSI_AHSTYPE_CDB;
207 ecdb_ahdr->reserved = 0;
208 memcpy(ecdb_ahdr->ecdb, cmd->cmnd + ISCSI_CDB_SIZE, rlen);
209
210 ISCSI_DBG_SESSION(task->conn->session,
211 "iscsi_prep_ecdb_ahs: varlen_cdb_len %d "
212 "rlen %d pad_len %d ahs_length %d iscsi_headers_size "
213 "%u\n", cmd->cmd_len, rlen, pad_len, ahslength,
214 task->hdr_len);
215 return 0;
216 }
217
218 /**
219 * iscsi_check_tmf_restrictions - check if a task is affected by TMF
220 * @task: iscsi task
221 * @opcode: opcode to check for
222 *
223 * During TMF a task has to be checked if it's affected.
224 * All unrelated I/O can be passed through, but I/O to the
225 * affected LUN should be restricted.
226 * If 'fast_abort' is set we won't be sending any I/O to the
227 * affected LUN.
228 * Otherwise the target is waiting for all TTTs to be completed,
229 * so we have to send all outstanding Data-Out PDUs to the target.
230 */
231 static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode)
232 {
233 struct iscsi_conn *conn = task->conn;
234 struct iscsi_tm *tmf = &conn->tmhdr;
235 u64 hdr_lun;
236
237 if (conn->tmf_state == TMF_INITIAL)
238 return 0;
239
240 if ((tmf->opcode & ISCSI_OPCODE_MASK) != ISCSI_OP_SCSI_TMFUNC)
241 return 0;
242
243 switch (ISCSI_TM_FUNC_VALUE(tmf)) {
244 case ISCSI_TM_FUNC_LOGICAL_UNIT_RESET:
245 /*
246 * Allow PDUs for unrelated LUNs
247 */
248 hdr_lun = scsilun_to_int(&tmf->lun);
249 if (hdr_lun != task->sc->device->lun)
250 return 0;
251 fallthrough;
252 case ISCSI_TM_FUNC_TARGET_WARM_RESET:
253 /*
254 * Fail all SCSI cmd PDUs
255 */
256 if (opcode != ISCSI_OP_SCSI_DATA_OUT) {
257 iscsi_conn_printk(KERN_INFO, conn,
258 "task [op %x itt "
259 "0x%x/0x%x] "
260 "rejected.\n",
261 opcode, task->itt,
262 task->hdr_itt);
263 return -EACCES;
264 }
265 /*
266 * And also all data-out PDUs in response to R2T
267 * if fast_abort is set.
268 */
269 if (conn->session->fast_abort) {
270 iscsi_conn_printk(KERN_INFO, conn,
271 "task [op %x itt "
272 "0x%x/0x%x] fast abort.\n",
273 opcode, task->itt,
274 task->hdr_itt);
275 return -EACCES;
276 }
277 break;
278 case ISCSI_TM_FUNC_ABORT_TASK:
279 /*
280 * the caller has already checked if the task
281 * they want to abort was in the pending queue so if
282 * we are here the cmd pdu has gone out already, and
283 * we will only hit this for data-outs
284 */
285 if (opcode == ISCSI_OP_SCSI_DATA_OUT &&
286 task->hdr_itt == tmf->rtt) {
287 ISCSI_DBG_SESSION(conn->session,
288 "Preventing task %x/%x from sending "
289 "data-out due to abort task in "
290 "progress\n", task->itt,
291 task->hdr_itt);
292 return -EACCES;
293 }
294 break;
295 }
296
297 return 0;
298 }
299
300 /**
301 * iscsi_prep_scsi_cmd_pdu - prep iscsi scsi cmd pdu
302 * @task: iscsi task
303 *
304 * Prep basic iSCSI PDU fields for a scsi cmd pdu. The LLD should set
305 * fields like dlength or final based on how much data it sends
306 */
307 static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
308 {
309 struct iscsi_conn *conn = task->conn;
310 struct iscsi_session *session = conn->session;
311 struct scsi_cmnd *sc = task->sc;
312 struct iscsi_scsi_req *hdr;
313 unsigned hdrlength, cmd_len, transfer_length;
314 itt_t itt;
315 int rc;
316
317 rc = iscsi_check_tmf_restrictions(task, ISCSI_OP_SCSI_CMD);
318 if (rc)
319 return rc;
320
321 if (conn->session->tt->alloc_pdu) {
322 rc = conn->session->tt->alloc_pdu(task, ISCSI_OP_SCSI_CMD);
323 if (rc)
324 return rc;
325 }
326 hdr = (struct iscsi_scsi_req *)task->hdr;
327 itt = hdr->itt;
328 memset(hdr, 0, sizeof(*hdr));
329
330 if (session->tt->parse_pdu_itt)
331 hdr->itt = task->hdr_itt = itt;
332 else
333 hdr->itt = task->hdr_itt = build_itt(task->itt,
334 task->conn->session->age);
335 task->hdr_len = 0;
336 rc = iscsi_add_hdr(task, sizeof(*hdr));
337 if (rc)
338 return rc;
339 hdr->opcode = ISCSI_OP_SCSI_CMD;
340 hdr->flags = ISCSI_ATTR_SIMPLE;
341 int_to_scsilun(sc->device->lun, &hdr->lun);
342 task->lun = hdr->lun;
343 hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
344 cmd_len = sc->cmd_len;
345 if (cmd_len < ISCSI_CDB_SIZE)
346 memset(&hdr->cdb[cmd_len], 0, ISCSI_CDB_SIZE - cmd_len);
347 else if (cmd_len > ISCSI_CDB_SIZE) {
348 rc = iscsi_prep_ecdb_ahs(task);
349 if (rc)
350 return rc;
351 cmd_len = ISCSI_CDB_SIZE;
352 }
353 memcpy(hdr->cdb, sc->cmnd, cmd_len);
354
355 task->imm_count = 0;
356 if (scsi_get_prot_op(sc) != SCSI_PROT_NORMAL)
357 task->protected = true;
358
359 transfer_length = scsi_transfer_length(sc);
360 hdr->data_length = cpu_to_be32(transfer_length);
361 if (sc->sc_data_direction == DMA_TO_DEVICE) {
362 struct iscsi_r2t_info *r2t = &task->unsol_r2t;
363
364 hdr->flags |= ISCSI_FLAG_CMD_WRITE;
365 /*
366 * Write counters:
367 *
368 * imm_count bytes to be sent right after
369 * SCSI PDU Header
370 *
371 * unsol_count bytes(as Data-Out) to be sent
372 * without R2T ack right after
373 * immediate data
374 *
375 * r2t data_length bytes to be sent via R2T ack's
376 *
377 * pad_count bytes to be sent as zero-padding
378 */
379 memset(r2t, 0, sizeof(*r2t));
380
381 if (session->imm_data_en) {
382 if (transfer_length >= session->first_burst)
383 task->imm_count = min(session->first_burst,
384 conn->max_xmit_dlength);
385 else
386 task->imm_count = min(transfer_length,
387 conn->max_xmit_dlength);
388 hton24(hdr->dlength, task->imm_count);
389 } else
390 zero_data(hdr->dlength);
391
392 if (!session->initial_r2t_en) {
393 r2t->data_length = min(session->first_burst,
394 transfer_length) -
395 task->imm_count;
396 r2t->data_offset = task->imm_count;
397 r2t->ttt = cpu_to_be32(ISCSI_RESERVED_TAG);
398 r2t->exp_statsn = cpu_to_be32(conn->exp_statsn);
399 }
400
401 if (!task->unsol_r2t.data_length)
402 /* No unsolicit Data-Out's */
403 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
404 } else {
405 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
406 zero_data(hdr->dlength);
407
408 if (sc->sc_data_direction == DMA_FROM_DEVICE)
409 hdr->flags |= ISCSI_FLAG_CMD_READ;
410 }
411
412 /* calculate size of additional header segments (AHSs) */
413 hdrlength = task->hdr_len - sizeof(*hdr);
414
415 WARN_ON(hdrlength & (ISCSI_PAD_LEN-1));
416 hdrlength /= ISCSI_PAD_LEN;
417
418 WARN_ON(hdrlength >= 256);
419 hdr->hlength = hdrlength & 0xFF;
420 hdr->cmdsn = task->cmdsn = cpu_to_be32(session->cmdsn);
421
422 if (session->tt->init_task && session->tt->init_task(task))
423 return -EIO;
424
425 task->state = ISCSI_TASK_RUNNING;
426 session->cmdsn++;
427
428 conn->scsicmd_pdus_cnt++;
429 ISCSI_DBG_SESSION(session, "iscsi prep [%s cid %d sc %p cdb 0x%x "
430 "itt 0x%x len %d cmdsn %d win %d]\n",
431 sc->sc_data_direction == DMA_TO_DEVICE ?
432 "write" : "read", conn->id, sc, sc->cmnd[0],
433 task->itt, transfer_length,
434 session->cmdsn,
435 session->max_cmdsn - session->exp_cmdsn + 1);
436 return 0;
437 }
438
439 /**
440 * iscsi_free_task - free a task
441 * @task: iscsi cmd task
442 *
443 * Must be called with session back_lock.
444 * This function returns the scsi command to scsi-ml or cleans
445 * up mgmt tasks then returns the task to the pool.
446 */
447 static void iscsi_free_task(struct iscsi_task *task)
448 {
449 struct iscsi_conn *conn = task->conn;
450 struct iscsi_session *session = conn->session;
451 struct scsi_cmnd *sc = task->sc;
452 int oldstate = task->state;
453
454 ISCSI_DBG_SESSION(session, "freeing task itt 0x%x state %d sc %p\n",
455 task->itt, task->state, task->sc);
456
457 session->tt->cleanup_task(task);
458 task->state = ISCSI_TASK_FREE;
459 task->sc = NULL;
460 /*
461 * login task is preallocated so do not free
462 */
463 if (conn->login_task == task)
464 return;
465
466 kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*));
467
468 if (sc) {
469 /* SCSI eh reuses commands to verify us */
470 sc->SCp.ptr = NULL;
471 /*
472 * queue command may call this to free the task, so
473 * it will decide how to return sc to scsi-ml.
474 */
475 if (oldstate != ISCSI_TASK_REQUEUE_SCSIQ)
476 sc->scsi_done(sc);
477 }
478 }
479
480 void __iscsi_get_task(struct iscsi_task *task)
481 {
482 refcount_inc(&task->refcount);
483 }
484 EXPORT_SYMBOL_GPL(__iscsi_get_task);
485
486 void __iscsi_put_task(struct iscsi_task *task)
487 {
488 if (refcount_dec_and_test(&task->refcount))
489 iscsi_free_task(task);
490 }
491 EXPORT_SYMBOL_GPL(__iscsi_put_task);
492
493 void iscsi_put_task(struct iscsi_task *task)
494 {
495 struct iscsi_session *session = task->conn->session;
496
497 /* regular RX path uses back_lock */
498 spin_lock_bh(&session->back_lock);
499 __iscsi_put_task(task);
500 spin_unlock_bh(&session->back_lock);
501 }
502 EXPORT_SYMBOL_GPL(iscsi_put_task);
503
504 /**
505 * iscsi_complete_task - finish a task
506 * @task: iscsi cmd task
507 * @state: state to complete task with
508 *
509 * Must be called with session back_lock.
510 */
511 static void iscsi_complete_task(struct iscsi_task *task, int state)
512 {
513 struct iscsi_conn *conn = task->conn;
514
515 ISCSI_DBG_SESSION(conn->session,
516 "complete task itt 0x%x state %d sc %p\n",
517 task->itt, task->state, task->sc);
518 if (task->state == ISCSI_TASK_COMPLETED ||
519 task->state == ISCSI_TASK_ABRT_TMF ||
520 task->state == ISCSI_TASK_ABRT_SESS_RECOV ||
521 task->state == ISCSI_TASK_REQUEUE_SCSIQ)
522 return;
523 WARN_ON_ONCE(task->state == ISCSI_TASK_FREE);
524 task->state = state;
525
526 spin_lock_bh(&conn->taskqueuelock);
527 if (!list_empty(&task->running)) {
528 pr_debug_once("%s while task on list", __func__);
529 list_del_init(&task->running);
530 }
531 spin_unlock_bh(&conn->taskqueuelock);
532
533 if (conn->task == task)
534 conn->task = NULL;
535
536 if (READ_ONCE(conn->ping_task) == task)
537 WRITE_ONCE(conn->ping_task, NULL);
538
539 /* release get from queueing */
540 __iscsi_put_task(task);
541 }
542
543 /**
544 * iscsi_complete_scsi_task - finish scsi task normally
545 * @task: iscsi task for scsi cmd
546 * @exp_cmdsn: expected cmd sn in cpu format
547 * @max_cmdsn: max cmd sn in cpu format
548 *
549 * This is used when drivers do not need or cannot perform
550 * lower level pdu processing.
551 *
552 * Called with session back_lock
553 */
554 void iscsi_complete_scsi_task(struct iscsi_task *task,
555 uint32_t exp_cmdsn, uint32_t max_cmdsn)
556 {
557 struct iscsi_conn *conn = task->conn;
558
559 ISCSI_DBG_SESSION(conn->session, "[itt 0x%x]\n", task->itt);
560
561 conn->last_recv = jiffies;
562 __iscsi_update_cmdsn(conn->session, exp_cmdsn, max_cmdsn);
563 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
564 }
565 EXPORT_SYMBOL_GPL(iscsi_complete_scsi_task);
566
567
568 /*
569 * session back_lock must be held and if not called for a task that is
570 * still pending or from the xmit thread, then xmit thread must
571 * be suspended.
572 */
573 static void fail_scsi_task(struct iscsi_task *task, int err)
574 {
575 struct iscsi_conn *conn = task->conn;
576 struct scsi_cmnd *sc;
577 int state;
578
579 /*
580 * if a command completes and we get a successful tmf response
581 * we will hit this because the scsi eh abort code does not take
582 * a ref to the task.
583 */
584 sc = task->sc;
585 if (!sc)
586 return;
587
588 if (task->state == ISCSI_TASK_PENDING) {
589 /*
590 * cmd never made it to the xmit thread, so we should not count
591 * the cmd in the sequencing
592 */
593 conn->session->queued_cmdsn--;
594 /* it was never sent so just complete like normal */
595 state = ISCSI_TASK_COMPLETED;
596 } else if (err == DID_TRANSPORT_DISRUPTED)
597 state = ISCSI_TASK_ABRT_SESS_RECOV;
598 else
599 state = ISCSI_TASK_ABRT_TMF;
600
601 sc->result = err << 16;
602 scsi_set_resid(sc, scsi_bufflen(sc));
603
604 /* regular RX path uses back_lock */
605 spin_lock_bh(&conn->session->back_lock);
606 iscsi_complete_task(task, state);
607 spin_unlock_bh(&conn->session->back_lock);
608 }
609
610 static int iscsi_prep_mgmt_task(struct iscsi_conn *conn,
611 struct iscsi_task *task)
612 {
613 struct iscsi_session *session = conn->session;
614 struct iscsi_hdr *hdr = task->hdr;
615 struct iscsi_nopout *nop = (struct iscsi_nopout *)hdr;
616 uint8_t opcode = hdr->opcode & ISCSI_OPCODE_MASK;
617
618 if (conn->session->state == ISCSI_STATE_LOGGING_OUT)
619 return -ENOTCONN;
620
621 if (opcode != ISCSI_OP_LOGIN && opcode != ISCSI_OP_TEXT)
622 nop->exp_statsn = cpu_to_be32(conn->exp_statsn);
623 /*
624 * pre-format CmdSN for outgoing PDU.
625 */
626 nop->cmdsn = cpu_to_be32(session->cmdsn);
627 if (hdr->itt != RESERVED_ITT) {
628 /*
629 * TODO: We always use immediate for normal session pdus.
630 * If we start to send tmfs or nops as non-immediate then
631 * we should start checking the cmdsn numbers for mgmt tasks.
632 *
633 * During discovery sessions iscsid sends TEXT as non immediate,
634 * but we always only send one PDU at a time.
635 */
636 if (conn->c_stage == ISCSI_CONN_STARTED &&
637 !(hdr->opcode & ISCSI_OP_IMMEDIATE)) {
638 session->queued_cmdsn++;
639 session->cmdsn++;
640 }
641 }
642
643 if (session->tt->init_task && session->tt->init_task(task))
644 return -EIO;
645
646 if ((hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
647 session->state = ISCSI_STATE_LOGGING_OUT;
648
649 task->state = ISCSI_TASK_RUNNING;
650 ISCSI_DBG_SESSION(session, "mgmtpdu [op 0x%x hdr->itt 0x%x "
651 "datalen %d]\n", hdr->opcode & ISCSI_OPCODE_MASK,
652 hdr->itt, task->data_count);
653 return 0;
654 }
655
656 static struct iscsi_task *
657 __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
658 char *data, uint32_t data_size)
659 {
660 struct iscsi_session *session = conn->session;
661 struct iscsi_host *ihost = shost_priv(session->host);
662 uint8_t opcode = hdr->opcode & ISCSI_OPCODE_MASK;
663 struct iscsi_task *task;
664 itt_t itt;
665
666 if (session->state == ISCSI_STATE_TERMINATE)
667 return NULL;
668
669 if (opcode == ISCSI_OP_LOGIN || opcode == ISCSI_OP_TEXT) {
670 /*
671 * Login and Text are sent serially, in
672 * request-followed-by-response sequence.
673 * Same task can be used. Same ITT must be used.
674 * Note that login_task is preallocated at conn_create().
675 */
676 if (conn->login_task->state != ISCSI_TASK_FREE) {
677 iscsi_conn_printk(KERN_ERR, conn, "Login/Text in "
678 "progress. Cannot start new task.\n");
679 return NULL;
680 }
681
682 if (data_size > ISCSI_DEF_MAX_RECV_SEG_LEN) {
683 iscsi_conn_printk(KERN_ERR, conn, "Invalid buffer len of %u for login task. Max len is %u\n", data_size, ISCSI_DEF_MAX_RECV_SEG_LEN);
684 return NULL;
685 }
686
687 task = conn->login_task;
688 } else {
689 if (session->state != ISCSI_STATE_LOGGED_IN)
690 return NULL;
691
692 if (data_size != 0) {
693 iscsi_conn_printk(KERN_ERR, conn, "Can not send data buffer of len %u for op 0x%x\n", data_size, opcode);
694 return NULL;
695 }
696
697 BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
698 BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
699
700 if (!kfifo_out(&session->cmdpool.queue,
701 (void*)&task, sizeof(void*)))
702 return NULL;
703 }
704 /*
705 * released in complete pdu for task we expect a response for, and
706 * released by the lld when it has transmitted the task for
707 * pdus we do not expect a response for.
708 */
709 refcount_set(&task->refcount, 1);
710 task->conn = conn;
711 task->sc = NULL;
712 INIT_LIST_HEAD(&task->running);
713 task->state = ISCSI_TASK_PENDING;
714
715 if (data_size) {
716 memcpy(task->data, data, data_size);
717 task->data_count = data_size;
718 } else
719 task->data_count = 0;
720
721 if (conn->session->tt->alloc_pdu) {
722 if (conn->session->tt->alloc_pdu(task, hdr->opcode)) {
723 iscsi_conn_printk(KERN_ERR, conn, "Could not allocate "
724 "pdu for mgmt task.\n");
725 goto free_task;
726 }
727 }
728
729 itt = task->hdr->itt;
730 task->hdr_len = sizeof(struct iscsi_hdr);
731 memcpy(task->hdr, hdr, sizeof(struct iscsi_hdr));
732
733 if (hdr->itt != RESERVED_ITT) {
734 if (session->tt->parse_pdu_itt)
735 task->hdr->itt = itt;
736 else
737 task->hdr->itt = build_itt(task->itt,
738 task->conn->session->age);
739 }
740
741 if (unlikely(READ_ONCE(conn->ping_task) == INVALID_SCSI_TASK))
742 WRITE_ONCE(conn->ping_task, task);
743
744 if (!ihost->workq) {
745 if (iscsi_prep_mgmt_task(conn, task))
746 goto free_task;
747
748 if (session->tt->xmit_task(task))
749 goto free_task;
750 } else {
751 spin_lock_bh(&conn->taskqueuelock);
752 list_add_tail(&task->running, &conn->mgmtqueue);
753 spin_unlock_bh(&conn->taskqueuelock);
754 iscsi_conn_queue_work(conn);
755 }
756
757 return task;
758
759 free_task:
760 /* regular RX path uses back_lock */
761 spin_lock(&session->back_lock);
762 __iscsi_put_task(task);
763 spin_unlock(&session->back_lock);
764 return NULL;
765 }
766
767 int iscsi_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr,
768 char *data, uint32_t data_size)
769 {
770 struct iscsi_conn *conn = cls_conn->dd_data;
771 struct iscsi_session *session = conn->session;
772 int err = 0;
773
774 spin_lock_bh(&session->frwd_lock);
775 if (!__iscsi_conn_send_pdu(conn, hdr, data, data_size))
776 err = -EPERM;
777 spin_unlock_bh(&session->frwd_lock);
778 return err;
779 }
780 EXPORT_SYMBOL_GPL(iscsi_conn_send_pdu);
781
782 /**
783 * iscsi_scsi_cmd_rsp - SCSI Command Response processing
784 * @conn: iscsi connection
785 * @hdr: iscsi header
786 * @task: scsi command task
787 * @data: cmd data buffer
788 * @datalen: len of buffer
789 *
790 * iscsi_cmd_rsp sets up the scsi_cmnd fields based on the PDU and
791 * then completes the command and task. called under back_lock
792 **/
793 static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
794 struct iscsi_task *task, char *data,
795 int datalen)
796 {
797 struct iscsi_scsi_rsp *rhdr = (struct iscsi_scsi_rsp *)hdr;
798 struct iscsi_session *session = conn->session;
799 struct scsi_cmnd *sc = task->sc;
800
801 iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr);
802 conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
803
804 sc->result = (DID_OK << 16) | rhdr->cmd_status;
805
806 if (task->protected) {
807 sector_t sector;
808 u8 ascq;
809
810 /**
811 * Transports that didn't implement check_protection
812 * callback but still published T10-PI support to scsi-mid
813 * deserve this BUG_ON.
814 **/
815 BUG_ON(!session->tt->check_protection);
816
817 ascq = session->tt->check_protection(task, &sector);
818 if (ascq) {
819 sc->result = DRIVER_SENSE << 24 |
820 SAM_STAT_CHECK_CONDITION;
821 scsi_build_sense_buffer(1, sc->sense_buffer,
822 ILLEGAL_REQUEST, 0x10, ascq);
823 scsi_set_sense_information(sc->sense_buffer,
824 SCSI_SENSE_BUFFERSIZE,
825 sector);
826 goto out;
827 }
828 }
829
830 if (rhdr->response != ISCSI_STATUS_CMD_COMPLETED) {
831 sc->result = DID_ERROR << 16;
832 goto out;
833 }
834
835 if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) {
836 uint16_t senselen;
837
838 if (datalen < 2) {
839 invalid_datalen:
840 iscsi_conn_printk(KERN_ERR, conn,
841 "Got CHECK_CONDITION but invalid data "
842 "buffer size of %d\n", datalen);
843 sc->result = DID_BAD_TARGET << 16;
844 goto out;
845 }
846
847 senselen = get_unaligned_be16(data);
848 if (datalen < senselen)
849 goto invalid_datalen;
850
851 memcpy(sc->sense_buffer, data + 2,
852 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
853 ISCSI_DBG_SESSION(session, "copied %d bytes of sense\n",
854 min_t(uint16_t, senselen,
855 SCSI_SENSE_BUFFERSIZE));
856 }
857
858 if (rhdr->flags & (ISCSI_FLAG_CMD_BIDI_UNDERFLOW |
859 ISCSI_FLAG_CMD_BIDI_OVERFLOW)) {
860 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
861 }
862
863 if (rhdr->flags & (ISCSI_FLAG_CMD_UNDERFLOW |
864 ISCSI_FLAG_CMD_OVERFLOW)) {
865 int res_count = be32_to_cpu(rhdr->residual_count);
866
867 if (res_count > 0 &&
868 (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW ||
869 res_count <= scsi_bufflen(sc)))
870 /* write side for bidi or uni-io set_resid */
871 scsi_set_resid(sc, res_count);
872 else
873 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
874 }
875 out:
876 ISCSI_DBG_SESSION(session, "cmd rsp done [sc %p res %d itt 0x%x]\n",
877 sc, sc->result, task->itt);
878 conn->scsirsp_pdus_cnt++;
879 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
880 }
881
882 /**
883 * iscsi_data_in_rsp - SCSI Data-In Response processing
884 * @conn: iscsi connection
885 * @hdr: iscsi pdu
886 * @task: scsi command task
887 *
888 * iscsi_data_in_rsp sets up the scsi_cmnd fields based on the data received
889 * then completes the command and task. called under back_lock
890 **/
891 static void
892 iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
893 struct iscsi_task *task)
894 {
895 struct iscsi_data_rsp *rhdr = (struct iscsi_data_rsp *)hdr;
896 struct scsi_cmnd *sc = task->sc;
897
898 if (!(rhdr->flags & ISCSI_FLAG_DATA_STATUS))
899 return;
900
901 iscsi_update_cmdsn(conn->session, (struct iscsi_nopin *)hdr);
902 sc->result = (DID_OK << 16) | rhdr->cmd_status;
903 conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
904 if (rhdr->flags & (ISCSI_FLAG_DATA_UNDERFLOW |
905 ISCSI_FLAG_DATA_OVERFLOW)) {
906 int res_count = be32_to_cpu(rhdr->residual_count);
907
908 if (res_count > 0 &&
909 (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW ||
910 res_count <= sc->sdb.length))
911 scsi_set_resid(sc, res_count);
912 else
913 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
914 }
915
916 ISCSI_DBG_SESSION(conn->session, "data in with status done "
917 "[sc %p res %d itt 0x%x]\n",
918 sc, sc->result, task->itt);
919 conn->scsirsp_pdus_cnt++;
920 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
921 }
922
923 static void iscsi_tmf_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
924 {
925 struct iscsi_tm_rsp *tmf = (struct iscsi_tm_rsp *)hdr;
926
927 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
928 conn->tmfrsp_pdus_cnt++;
929
930 if (conn->tmf_state != TMF_QUEUED)
931 return;
932
933 if (tmf->response == ISCSI_TMF_RSP_COMPLETE)
934 conn->tmf_state = TMF_SUCCESS;
935 else if (tmf->response == ISCSI_TMF_RSP_NO_TASK)
936 conn->tmf_state = TMF_NOT_FOUND;
937 else
938 conn->tmf_state = TMF_FAILED;
939 wake_up(&conn->ehwait);
940 }
941
942 static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
943 {
944 struct iscsi_nopout hdr;
945 struct iscsi_task *task;
946
947 if (!rhdr) {
948 if (READ_ONCE(conn->ping_task))
949 return -EINVAL;
950 WRITE_ONCE(conn->ping_task, INVALID_SCSI_TASK);
951 }
952
953 memset(&hdr, 0, sizeof(struct iscsi_nopout));
954 hdr.opcode = ISCSI_OP_NOOP_OUT | ISCSI_OP_IMMEDIATE;
955 hdr.flags = ISCSI_FLAG_CMD_FINAL;
956
957 if (rhdr) {
958 hdr.lun = rhdr->lun;
959 hdr.ttt = rhdr->ttt;
960 hdr.itt = RESERVED_ITT;
961 } else
962 hdr.ttt = RESERVED_ITT;
963
964 task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0);
965 if (!task) {
966 if (!rhdr)
967 WRITE_ONCE(conn->ping_task, NULL);
968 iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n");
969 return -EIO;
970 } else if (!rhdr) {
971 /* only track our nops */
972 conn->last_ping = jiffies;
973 }
974
975 return 0;
976 }
977
978 /**
979 * iscsi_nop_out_rsp - SCSI NOP Response processing
980 * @task: scsi command task
981 * @nop: the nop structure
982 * @data: where to put the data
983 * @datalen: length of data
984 *
985 * iscsi_nop_out_rsp handles nop response from use or
986 * from user space. called under back_lock
987 **/
988 static int iscsi_nop_out_rsp(struct iscsi_task *task,
989 struct iscsi_nopin *nop, char *data, int datalen)
990 {
991 struct iscsi_conn *conn = task->conn;
992 int rc = 0;
993
994 if (READ_ONCE(conn->ping_task) != task) {
995 /*
996 * If this is not in response to one of our
997 * nops then it must be from userspace.
998 */
999 if (iscsi_recv_pdu(conn->cls_conn, (struct iscsi_hdr *)nop,
1000 data, datalen))
1001 rc = ISCSI_ERR_CONN_FAILED;
1002 } else
1003 mod_timer(&conn->transport_timer, jiffies + conn->recv_timeout);
1004 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
1005 return rc;
1006 }
1007
1008 static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
1009 char *data, int datalen)
1010 {
1011 struct iscsi_reject *reject = (struct iscsi_reject *)hdr;
1012 struct iscsi_hdr rejected_pdu;
1013 int opcode, rc = 0;
1014
1015 conn->exp_statsn = be32_to_cpu(reject->statsn) + 1;
1016
1017 if (ntoh24(reject->dlength) > datalen ||
1018 ntoh24(reject->dlength) < sizeof(struct iscsi_hdr)) {
1019 iscsi_conn_printk(KERN_ERR, conn, "Cannot handle rejected "
1020 "pdu. Invalid data length (pdu dlength "
1021 "%u, datalen %d\n", ntoh24(reject->dlength),
1022 datalen);
1023 return ISCSI_ERR_PROTO;
1024 }
1025 memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr));
1026 opcode = rejected_pdu.opcode & ISCSI_OPCODE_MASK;
1027
1028 switch (reject->reason) {
1029 case ISCSI_REASON_DATA_DIGEST_ERROR:
1030 iscsi_conn_printk(KERN_ERR, conn,
1031 "pdu (op 0x%x itt 0x%x) rejected "
1032 "due to DataDigest error.\n",
1033 opcode, rejected_pdu.itt);
1034 break;
1035 case ISCSI_REASON_IMM_CMD_REJECT:
1036 iscsi_conn_printk(KERN_ERR, conn,
1037 "pdu (op 0x%x itt 0x%x) rejected. Too many "
1038 "immediate commands.\n",
1039 opcode, rejected_pdu.itt);
1040 /*
1041 * We only send one TMF at a time so if the target could not
1042 * handle it, then it should get fixed (RFC mandates that
1043 * a target can handle one immediate TMF per conn).
1044 *
1045 * For nops-outs, we could have sent more than one if
1046 * the target is sending us lots of nop-ins
1047 */
1048 if (opcode != ISCSI_OP_NOOP_OUT)
1049 return 0;
1050
1051 if (rejected_pdu.itt == cpu_to_be32(ISCSI_RESERVED_TAG)) {
1052 /*
1053 * nop-out in response to target's nop-out rejected.
1054 * Just resend.
1055 */
1056 /* In RX path we are under back lock */
1057 spin_unlock(&conn->session->back_lock);
1058 spin_lock(&conn->session->frwd_lock);
1059 iscsi_send_nopout(conn,
1060 (struct iscsi_nopin*)&rejected_pdu);
1061 spin_unlock(&conn->session->frwd_lock);
1062 spin_lock(&conn->session->back_lock);
1063 } else {
1064 struct iscsi_task *task;
1065 /*
1066 * Our nop as ping got dropped. We know the target
1067 * and transport are ok so just clean up
1068 */
1069 task = iscsi_itt_to_task(conn, rejected_pdu.itt);
1070 if (!task) {
1071 iscsi_conn_printk(KERN_ERR, conn,
1072 "Invalid pdu reject. Could "
1073 "not lookup rejected task.\n");
1074 rc = ISCSI_ERR_BAD_ITT;
1075 } else
1076 rc = iscsi_nop_out_rsp(task,
1077 (struct iscsi_nopin*)&rejected_pdu,
1078 NULL, 0);
1079 }
1080 break;
1081 default:
1082 iscsi_conn_printk(KERN_ERR, conn,
1083 "pdu (op 0x%x itt 0x%x) rejected. Reason "
1084 "code 0x%x\n", rejected_pdu.opcode,
1085 rejected_pdu.itt, reject->reason);
1086 break;
1087 }
1088 return rc;
1089 }
1090
1091 /**
1092 * iscsi_itt_to_task - look up task by itt
1093 * @conn: iscsi connection
1094 * @itt: itt
1095 *
1096 * This should be used for mgmt tasks like login and nops, or if
1097 * the LDD's itt space does not include the session age.
1098 *
1099 * The session back_lock must be held.
1100 */
1101 struct iscsi_task *iscsi_itt_to_task(struct iscsi_conn *conn, itt_t itt)
1102 {
1103 struct iscsi_session *session = conn->session;
1104 int i;
1105
1106 if (itt == RESERVED_ITT)
1107 return NULL;
1108
1109 if (session->tt->parse_pdu_itt)
1110 session->tt->parse_pdu_itt(conn, itt, &i, NULL);
1111 else
1112 i = get_itt(itt);
1113 if (i >= session->cmds_max)
1114 return NULL;
1115
1116 return session->cmds[i];
1117 }
1118 EXPORT_SYMBOL_GPL(iscsi_itt_to_task);
1119
1120 /**
1121 * __iscsi_complete_pdu - complete pdu
1122 * @conn: iscsi conn
1123 * @hdr: iscsi header
1124 * @data: data buffer
1125 * @datalen: len of data buffer
1126 *
1127 * Completes pdu processing by freeing any resources allocated at
1128 * queuecommand or send generic. session back_lock must be held and verify
1129 * itt must have been called.
1130 */
1131 int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
1132 char *data, int datalen)
1133 {
1134 struct iscsi_session *session = conn->session;
1135 int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0;
1136 struct iscsi_task *task;
1137 uint32_t itt;
1138
1139 conn->last_recv = jiffies;
1140 rc = iscsi_verify_itt(conn, hdr->itt);
1141 if (rc)
1142 return rc;
1143
1144 if (hdr->itt != RESERVED_ITT)
1145 itt = get_itt(hdr->itt);
1146 else
1147 itt = ~0U;
1148
1149 ISCSI_DBG_SESSION(session, "[op 0x%x cid %d itt 0x%x len %d]\n",
1150 opcode, conn->id, itt, datalen);
1151
1152 if (itt == ~0U) {
1153 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
1154
1155 switch(opcode) {
1156 case ISCSI_OP_NOOP_IN:
1157 if (datalen) {
1158 rc = ISCSI_ERR_PROTO;
1159 break;
1160 }
1161
1162 if (hdr->ttt == cpu_to_be32(ISCSI_RESERVED_TAG))
1163 break;
1164
1165 /* In RX path we are under back lock */
1166 spin_unlock(&session->back_lock);
1167 spin_lock(&session->frwd_lock);
1168 iscsi_send_nopout(conn, (struct iscsi_nopin*)hdr);
1169 spin_unlock(&session->frwd_lock);
1170 spin_lock(&session->back_lock);
1171 break;
1172 case ISCSI_OP_REJECT:
1173 rc = iscsi_handle_reject(conn, hdr, data, datalen);
1174 break;
1175 case ISCSI_OP_ASYNC_EVENT:
1176 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
1177 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
1178 rc = ISCSI_ERR_CONN_FAILED;
1179 break;
1180 default:
1181 rc = ISCSI_ERR_BAD_OPCODE;
1182 break;
1183 }
1184 goto out;
1185 }
1186
1187 switch(opcode) {
1188 case ISCSI_OP_SCSI_CMD_RSP:
1189 case ISCSI_OP_SCSI_DATA_IN:
1190 task = iscsi_itt_to_ctask(conn, hdr->itt);
1191 if (!task)
1192 return ISCSI_ERR_BAD_ITT;
1193 task->last_xfer = jiffies;
1194 break;
1195 case ISCSI_OP_R2T:
1196 /*
1197 * LLD handles R2Ts if they need to.
1198 */
1199 return 0;
1200 case ISCSI_OP_LOGOUT_RSP:
1201 case ISCSI_OP_LOGIN_RSP:
1202 case ISCSI_OP_TEXT_RSP:
1203 case ISCSI_OP_SCSI_TMFUNC_RSP:
1204 case ISCSI_OP_NOOP_IN:
1205 task = iscsi_itt_to_task(conn, hdr->itt);
1206 if (!task)
1207 return ISCSI_ERR_BAD_ITT;
1208 break;
1209 default:
1210 return ISCSI_ERR_BAD_OPCODE;
1211 }
1212
1213 switch(opcode) {
1214 case ISCSI_OP_SCSI_CMD_RSP:
1215 iscsi_scsi_cmd_rsp(conn, hdr, task, data, datalen);
1216 break;
1217 case ISCSI_OP_SCSI_DATA_IN:
1218 iscsi_data_in_rsp(conn, hdr, task);
1219 break;
1220 case ISCSI_OP_LOGOUT_RSP:
1221 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
1222 if (datalen) {
1223 rc = ISCSI_ERR_PROTO;
1224 break;
1225 }
1226 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
1227 goto recv_pdu;
1228 case ISCSI_OP_LOGIN_RSP:
1229 case ISCSI_OP_TEXT_RSP:
1230 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
1231 /*
1232 * login related PDU's exp_statsn is handled in
1233 * userspace
1234 */
1235 goto recv_pdu;
1236 case ISCSI_OP_SCSI_TMFUNC_RSP:
1237 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
1238 if (datalen) {
1239 rc = ISCSI_ERR_PROTO;
1240 break;
1241 }
1242
1243 iscsi_tmf_rsp(conn, hdr);
1244 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
1245 break;
1246 case ISCSI_OP_NOOP_IN:
1247 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
1248 if (hdr->ttt != cpu_to_be32(ISCSI_RESERVED_TAG) || datalen) {
1249 rc = ISCSI_ERR_PROTO;
1250 break;
1251 }
1252 conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
1253
1254 rc = iscsi_nop_out_rsp(task, (struct iscsi_nopin*)hdr,
1255 data, datalen);
1256 break;
1257 default:
1258 rc = ISCSI_ERR_BAD_OPCODE;
1259 break;
1260 }
1261
1262 out:
1263 return rc;
1264 recv_pdu:
1265 if (iscsi_recv_pdu(conn->cls_conn, hdr, data, datalen))
1266 rc = ISCSI_ERR_CONN_FAILED;
1267 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
1268 return rc;
1269 }
1270 EXPORT_SYMBOL_GPL(__iscsi_complete_pdu);
1271
1272 int iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
1273 char *data, int datalen)
1274 {
1275 int rc;
1276
1277 spin_lock(&conn->session->back_lock);
1278 rc = __iscsi_complete_pdu(conn, hdr, data, datalen);
1279 spin_unlock(&conn->session->back_lock);
1280 return rc;
1281 }
1282 EXPORT_SYMBOL_GPL(iscsi_complete_pdu);
1283
1284 int iscsi_verify_itt(struct iscsi_conn *conn, itt_t itt)
1285 {
1286 struct iscsi_session *session = conn->session;
1287 int age = 0, i = 0;
1288
1289 if (itt == RESERVED_ITT)
1290 return 0;
1291
1292 if (session->tt->parse_pdu_itt)
1293 session->tt->parse_pdu_itt(conn, itt, &i, &age);
1294 else {
1295 i = get_itt(itt);
1296 age = ((__force u32)itt >> ISCSI_AGE_SHIFT) & ISCSI_AGE_MASK;
1297 }
1298
1299 if (age != session->age) {
1300 iscsi_conn_printk(KERN_ERR, conn,
1301 "received itt %x expected session age (%x)\n",
1302 (__force u32)itt, session->age);
1303 return ISCSI_ERR_BAD_ITT;
1304 }
1305
1306 if (i >= session->cmds_max) {
1307 iscsi_conn_printk(KERN_ERR, conn,
1308 "received invalid itt index %u (max cmds "
1309 "%u.\n", i, session->cmds_max);
1310 return ISCSI_ERR_BAD_ITT;
1311 }
1312 return 0;
1313 }
1314 EXPORT_SYMBOL_GPL(iscsi_verify_itt);
1315
1316 /**
1317 * iscsi_itt_to_ctask - look up ctask by itt
1318 * @conn: iscsi connection
1319 * @itt: itt
1320 *
1321 * This should be used for cmd tasks.
1322 *
1323 * The session back_lock must be held.
1324 */
1325 struct iscsi_task *iscsi_itt_to_ctask(struct iscsi_conn *conn, itt_t itt)
1326 {
1327 struct iscsi_task *task;
1328
1329 if (iscsi_verify_itt(conn, itt))
1330 return NULL;
1331
1332 task = iscsi_itt_to_task(conn, itt);
1333 if (!task || !task->sc)
1334 return NULL;
1335
1336 if (task->sc->SCp.phase != conn->session->age) {
1337 iscsi_session_printk(KERN_ERR, conn->session,
1338 "task's session age %d, expected %d\n",
1339 task->sc->SCp.phase, conn->session->age);
1340 return NULL;
1341 }
1342
1343 return task;
1344 }
1345 EXPORT_SYMBOL_GPL(iscsi_itt_to_ctask);
1346
1347 void iscsi_session_failure(struct iscsi_session *session,
1348 enum iscsi_err err)
1349 {
1350 struct iscsi_conn *conn;
1351 struct device *dev;
1352
1353 spin_lock_bh(&session->frwd_lock);
1354 conn = session->leadconn;
1355 if (session->state == ISCSI_STATE_TERMINATE || !conn) {
1356 spin_unlock_bh(&session->frwd_lock);
1357 return;
1358 }
1359
1360 dev = get_device(&conn->cls_conn->dev);
1361 spin_unlock_bh(&session->frwd_lock);
1362 if (!dev)
1363 return;
1364 /*
1365 * if the host is being removed bypass the connection
1366 * recovery initialization because we are going to kill
1367 * the session.
1368 */
1369 if (err == ISCSI_ERR_INVALID_HOST)
1370 iscsi_conn_error_event(conn->cls_conn, err);
1371 else
1372 iscsi_conn_failure(conn, err);
1373 put_device(dev);
1374 }
1375 EXPORT_SYMBOL_GPL(iscsi_session_failure);
1376
1377 void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err)
1378 {
1379 struct iscsi_session *session = conn->session;
1380
1381 spin_lock_bh(&session->frwd_lock);
1382 if (session->state == ISCSI_STATE_FAILED) {
1383 spin_unlock_bh(&session->frwd_lock);
1384 return;
1385 }
1386
1387 if (conn->stop_stage == 0)
1388 session->state = ISCSI_STATE_FAILED;
1389 spin_unlock_bh(&session->frwd_lock);
1390
1391 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1392 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
1393 iscsi_conn_error_event(conn->cls_conn, err);
1394 }
1395 EXPORT_SYMBOL_GPL(iscsi_conn_failure);
1396
1397 static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn)
1398 {
1399 struct iscsi_session *session = conn->session;
1400
1401 /*
1402 * Check for iSCSI window and take care of CmdSN wrap-around
1403 */
1404 if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) {
1405 ISCSI_DBG_SESSION(session, "iSCSI CmdSN closed. ExpCmdSn "
1406 "%u MaxCmdSN %u CmdSN %u/%u\n",
1407 session->exp_cmdsn, session->max_cmdsn,
1408 session->cmdsn, session->queued_cmdsn);
1409 return -ENOSPC;
1410 }
1411 return 0;
1412 }
1413
1414 static int iscsi_xmit_task(struct iscsi_conn *conn)
1415 {
1416 struct iscsi_task *task = conn->task;
1417 int rc;
1418
1419 if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx))
1420 return -ENODATA;
1421
1422 spin_lock_bh(&conn->session->back_lock);
1423 if (conn->task == NULL) {
1424 spin_unlock_bh(&conn->session->back_lock);
1425 return -ENODATA;
1426 }
1427 __iscsi_get_task(task);
1428 spin_unlock_bh(&conn->session->back_lock);
1429 spin_unlock_bh(&conn->session->frwd_lock);
1430 rc = conn->session->tt->xmit_task(task);
1431 spin_lock_bh(&conn->session->frwd_lock);
1432 if (!rc) {
1433 /* done with this task */
1434 task->last_xfer = jiffies;
1435 conn->task = NULL;
1436 }
1437 /* regular RX path uses back_lock */
1438 spin_lock(&conn->session->back_lock);
1439 __iscsi_put_task(task);
1440 spin_unlock(&conn->session->back_lock);
1441 return rc;
1442 }
1443
1444 /**
1445 * iscsi_requeue_task - requeue task to run from session workqueue
1446 * @task: task to requeue
1447 *
1448 * LLDs that need to run a task from the session workqueue should call
1449 * this. The session frwd_lock must be held. This should only be called
1450 * by software drivers.
1451 */
1452 void iscsi_requeue_task(struct iscsi_task *task)
1453 {
1454 struct iscsi_conn *conn = task->conn;
1455
1456 /*
1457 * this may be on the requeue list already if the xmit_task callout
1458 * is handling the r2ts while we are adding new ones
1459 */
1460 spin_lock_bh(&conn->taskqueuelock);
1461 if (list_empty(&task->running))
1462 list_add_tail(&task->running, &conn->requeue);
1463 spin_unlock_bh(&conn->taskqueuelock);
1464 iscsi_conn_queue_work(conn);
1465 }
1466 EXPORT_SYMBOL_GPL(iscsi_requeue_task);
1467
1468 /**
1469 * iscsi_data_xmit - xmit any command into the scheduled connection
1470 * @conn: iscsi connection
1471 *
1472 * Notes:
1473 * The function can return -EAGAIN in which case the caller must
1474 * re-schedule it again later or recover. '0' return code means
1475 * successful xmit.
1476 **/
1477 static int iscsi_data_xmit(struct iscsi_conn *conn)
1478 {
1479 struct iscsi_task *task;
1480 int rc = 0;
1481
1482 spin_lock_bh(&conn->session->frwd_lock);
1483 if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) {
1484 ISCSI_DBG_SESSION(conn->session, "Tx suspended!\n");
1485 spin_unlock_bh(&conn->session->frwd_lock);
1486 return -ENODATA;
1487 }
1488
1489 if (conn->task) {
1490 rc = iscsi_xmit_task(conn);
1491 if (rc)
1492 goto done;
1493 }
1494
1495 /*
1496 * process mgmt pdus like nops before commands since we should
1497 * only have one nop-out as a ping from us and targets should not
1498 * overflow us with nop-ins
1499 */
1500 spin_lock_bh(&conn->taskqueuelock);
1501 check_mgmt:
1502 while (!list_empty(&conn->mgmtqueue)) {
1503 conn->task = list_entry(conn->mgmtqueue.next,
1504 struct iscsi_task, running);
1505 list_del_init(&conn->task->running);
1506 spin_unlock_bh(&conn->taskqueuelock);
1507 if (iscsi_prep_mgmt_task(conn, conn->task)) {
1508 /* regular RX path uses back_lock */
1509 spin_lock_bh(&conn->session->back_lock);
1510 __iscsi_put_task(conn->task);
1511 spin_unlock_bh(&conn->session->back_lock);
1512 conn->task = NULL;
1513 spin_lock_bh(&conn->taskqueuelock);
1514 continue;
1515 }
1516 rc = iscsi_xmit_task(conn);
1517 if (rc)
1518 goto done;
1519 spin_lock_bh(&conn->taskqueuelock);
1520 }
1521
1522 /* process pending command queue */
1523 while (!list_empty(&conn->cmdqueue)) {
1524 conn->task = list_entry(conn->cmdqueue.next, struct iscsi_task,
1525 running);
1526 list_del_init(&conn->task->running);
1527 spin_unlock_bh(&conn->taskqueuelock);
1528 if (conn->session->state == ISCSI_STATE_LOGGING_OUT) {
1529 fail_scsi_task(conn->task, DID_IMM_RETRY);
1530 spin_lock_bh(&conn->taskqueuelock);
1531 continue;
1532 }
1533 rc = iscsi_prep_scsi_cmd_pdu(conn->task);
1534 if (rc) {
1535 if (rc == -ENOMEM || rc == -EACCES)
1536 fail_scsi_task(conn->task, DID_IMM_RETRY);
1537 else
1538 fail_scsi_task(conn->task, DID_ABORT);
1539 spin_lock_bh(&conn->taskqueuelock);
1540 continue;
1541 }
1542 rc = iscsi_xmit_task(conn);
1543 if (rc)
1544 goto done;
1545 /*
1546 * we could continuously get new task requests so
1547 * we need to check the mgmt queue for nops that need to
1548 * be sent to aviod starvation
1549 */
1550 spin_lock_bh(&conn->taskqueuelock);
1551 if (!list_empty(&conn->mgmtqueue))
1552 goto check_mgmt;
1553 }
1554
1555 while (!list_empty(&conn->requeue)) {
1556 /*
1557 * we always do fastlogout - conn stop code will clean up.
1558 */
1559 if (conn->session->state == ISCSI_STATE_LOGGING_OUT)
1560 break;
1561
1562 task = list_entry(conn->requeue.next, struct iscsi_task,
1563 running);
1564 if (iscsi_check_tmf_restrictions(task, ISCSI_OP_SCSI_DATA_OUT))
1565 break;
1566
1567 conn->task = task;
1568 list_del_init(&conn->task->running);
1569 conn->task->state = ISCSI_TASK_RUNNING;
1570 spin_unlock_bh(&conn->taskqueuelock);
1571 rc = iscsi_xmit_task(conn);
1572 if (rc)
1573 goto done;
1574 spin_lock_bh(&conn->taskqueuelock);
1575 if (!list_empty(&conn->mgmtqueue))
1576 goto check_mgmt;
1577 }
1578 spin_unlock_bh(&conn->taskqueuelock);
1579 spin_unlock_bh(&conn->session->frwd_lock);
1580 return -ENODATA;
1581
1582 done:
1583 spin_unlock_bh(&conn->session->frwd_lock);
1584 return rc;
1585 }
1586
1587 static void iscsi_xmitworker(struct work_struct *work)
1588 {
1589 struct iscsi_conn *conn =
1590 container_of(work, struct iscsi_conn, xmitwork);
1591 int rc;
1592 /*
1593 * serialize Xmit worker on a per-connection basis.
1594 */
1595 do {
1596 rc = iscsi_data_xmit(conn);
1597 } while (rc >= 0 || rc == -EAGAIN);
1598 }
1599
1600 static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn,
1601 struct scsi_cmnd *sc)
1602 {
1603 struct iscsi_task *task;
1604
1605 if (!kfifo_out(&conn->session->cmdpool.queue,
1606 (void *) &task, sizeof(void *)))
1607 return NULL;
1608
1609 sc->SCp.phase = conn->session->age;
1610 sc->SCp.ptr = (char *) task;
1611
1612 refcount_set(&task->refcount, 1);
1613 task->state = ISCSI_TASK_PENDING;
1614 task->conn = conn;
1615 task->sc = sc;
1616 task->have_checked_conn = false;
1617 task->last_timeout = jiffies;
1618 task->last_xfer = jiffies;
1619 task->protected = false;
1620 INIT_LIST_HEAD(&task->running);
1621 return task;
1622 }
1623
1624 enum {
1625 FAILURE_BAD_HOST = 1,
1626 FAILURE_SESSION_FAILED,
1627 FAILURE_SESSION_FREED,
1628 FAILURE_WINDOW_CLOSED,
1629 FAILURE_OOM,
1630 FAILURE_SESSION_TERMINATE,
1631 FAILURE_SESSION_IN_RECOVERY,
1632 FAILURE_SESSION_RECOVERY_TIMEOUT,
1633 FAILURE_SESSION_LOGGING_OUT,
1634 FAILURE_SESSION_NOT_READY,
1635 };
1636
1637 int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)
1638 {
1639 struct iscsi_cls_session *cls_session;
1640 struct iscsi_host *ihost;
1641 int reason = 0;
1642 struct iscsi_session *session;
1643 struct iscsi_conn *conn;
1644 struct iscsi_task *task = NULL;
1645
1646 sc->result = 0;
1647 sc->SCp.ptr = NULL;
1648
1649 ihost = shost_priv(host);
1650
1651 cls_session = starget_to_session(scsi_target(sc->device));
1652 session = cls_session->dd_data;
1653 spin_lock_bh(&session->frwd_lock);
1654
1655 reason = iscsi_session_chkready(cls_session);
1656 if (reason) {
1657 sc->result = reason;
1658 goto fault;
1659 }
1660
1661 if (session->state != ISCSI_STATE_LOGGED_IN) {
1662 /*
1663 * to handle the race between when we set the recovery state
1664 * and block the session we requeue here (commands could
1665 * be entering our queuecommand while a block is starting
1666 * up because the block code is not locked)
1667 */
1668 switch (session->state) {
1669 case ISCSI_STATE_FAILED:
1670 /*
1671 * cmds should fail during shutdown, if the session
1672 * state is bad, allowing completion to happen
1673 */
1674 if (unlikely(system_state != SYSTEM_RUNNING)) {
1675 reason = FAILURE_SESSION_FAILED;
1676 sc->result = DID_NO_CONNECT << 16;
1677 break;
1678 }
1679 fallthrough;
1680 case ISCSI_STATE_IN_RECOVERY:
1681 reason = FAILURE_SESSION_IN_RECOVERY;
1682 sc->result = DID_IMM_RETRY << 16;
1683 break;
1684 case ISCSI_STATE_LOGGING_OUT:
1685 reason = FAILURE_SESSION_LOGGING_OUT;
1686 sc->result = DID_IMM_RETRY << 16;
1687 break;
1688 case ISCSI_STATE_RECOVERY_FAILED:
1689 reason = FAILURE_SESSION_RECOVERY_TIMEOUT;
1690 sc->result = DID_TRANSPORT_FAILFAST << 16;
1691 break;
1692 case ISCSI_STATE_TERMINATE:
1693 reason = FAILURE_SESSION_TERMINATE;
1694 sc->result = DID_NO_CONNECT << 16;
1695 break;
1696 default:
1697 reason = FAILURE_SESSION_FREED;
1698 sc->result = DID_NO_CONNECT << 16;
1699 }
1700 goto fault;
1701 }
1702
1703 conn = session->leadconn;
1704 if (!conn) {
1705 reason = FAILURE_SESSION_FREED;
1706 sc->result = DID_NO_CONNECT << 16;
1707 goto fault;
1708 }
1709
1710 if (test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx)) {
1711 reason = FAILURE_SESSION_IN_RECOVERY;
1712 sc->result = DID_REQUEUE << 16;
1713 goto fault;
1714 }
1715
1716 if (iscsi_check_cmdsn_window_closed(conn)) {
1717 reason = FAILURE_WINDOW_CLOSED;
1718 goto reject;
1719 }
1720
1721 task = iscsi_alloc_task(conn, sc);
1722 if (!task) {
1723 reason = FAILURE_OOM;
1724 goto reject;
1725 }
1726
1727 if (!ihost->workq) {
1728 reason = iscsi_prep_scsi_cmd_pdu(task);
1729 if (reason) {
1730 if (reason == -ENOMEM || reason == -EACCES) {
1731 reason = FAILURE_OOM;
1732 goto prepd_reject;
1733 } else {
1734 sc->result = DID_ABORT << 16;
1735 goto prepd_fault;
1736 }
1737 }
1738 if (session->tt->xmit_task(task)) {
1739 session->cmdsn--;
1740 reason = FAILURE_SESSION_NOT_READY;
1741 goto prepd_reject;
1742 }
1743 } else {
1744 spin_lock_bh(&conn->taskqueuelock);
1745 list_add_tail(&task->running, &conn->cmdqueue);
1746 spin_unlock_bh(&conn->taskqueuelock);
1747 iscsi_conn_queue_work(conn);
1748 }
1749
1750 session->queued_cmdsn++;
1751 spin_unlock_bh(&session->frwd_lock);
1752 return 0;
1753
1754 prepd_reject:
1755 spin_lock_bh(&session->back_lock);
1756 iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ);
1757 spin_unlock_bh(&session->back_lock);
1758 reject:
1759 spin_unlock_bh(&session->frwd_lock);
1760 ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n",
1761 sc->cmnd[0], reason);
1762 return SCSI_MLQUEUE_TARGET_BUSY;
1763
1764 prepd_fault:
1765 spin_lock_bh(&session->back_lock);
1766 iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ);
1767 spin_unlock_bh(&session->back_lock);
1768 fault:
1769 spin_unlock_bh(&session->frwd_lock);
1770 ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n",
1771 sc->cmnd[0], reason);
1772 scsi_set_resid(sc, scsi_bufflen(sc));
1773 sc->scsi_done(sc);
1774 return 0;
1775 }
1776 EXPORT_SYMBOL_GPL(iscsi_queuecommand);
1777
1778 int iscsi_target_alloc(struct scsi_target *starget)
1779 {
1780 struct iscsi_cls_session *cls_session = starget_to_session(starget);
1781 struct iscsi_session *session = cls_session->dd_data;
1782
1783 starget->can_queue = session->scsi_cmds_max;
1784 return 0;
1785 }
1786 EXPORT_SYMBOL_GPL(iscsi_target_alloc);
1787
1788 static void iscsi_tmf_timedout(struct timer_list *t)
1789 {
1790 struct iscsi_conn *conn = from_timer(conn, t, tmf_timer);
1791 struct iscsi_session *session = conn->session;
1792
1793 spin_lock(&session->frwd_lock);
1794 if (conn->tmf_state == TMF_QUEUED) {
1795 conn->tmf_state = TMF_TIMEDOUT;
1796 ISCSI_DBG_EH(session, "tmf timedout\n");
1797 /* unblock eh_abort() */
1798 wake_up(&conn->ehwait);
1799 }
1800 spin_unlock(&session->frwd_lock);
1801 }
1802
1803 static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
1804 struct iscsi_tm *hdr, int age,
1805 int timeout)
1806 __must_hold(&session->frwd_lock)
1807 {
1808 struct iscsi_session *session = conn->session;
1809 struct iscsi_task *task;
1810
1811 task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)hdr,
1812 NULL, 0);
1813 if (!task) {
1814 spin_unlock_bh(&session->frwd_lock);
1815 iscsi_conn_printk(KERN_ERR, conn, "Could not send TMF.\n");
1816 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1817 spin_lock_bh(&session->frwd_lock);
1818 return -EPERM;
1819 }
1820 conn->tmfcmd_pdus_cnt++;
1821 conn->tmf_timer.expires = timeout * HZ + jiffies;
1822 add_timer(&conn->tmf_timer);
1823 ISCSI_DBG_EH(session, "tmf set timeout\n");
1824
1825 spin_unlock_bh(&session->frwd_lock);
1826 mutex_unlock(&session->eh_mutex);
1827
1828 /*
1829 * block eh thread until:
1830 *
1831 * 1) tmf response
1832 * 2) tmf timeout
1833 * 3) session is terminated or restarted or userspace has
1834 * given up on recovery
1835 */
1836 wait_event_interruptible(conn->ehwait, age != session->age ||
1837 session->state != ISCSI_STATE_LOGGED_IN ||
1838 conn->tmf_state != TMF_QUEUED);
1839 if (signal_pending(current))
1840 flush_signals(current);
1841 del_timer_sync(&conn->tmf_timer);
1842
1843 mutex_lock(&session->eh_mutex);
1844 spin_lock_bh(&session->frwd_lock);
1845 /* if the session drops it will clean up the task */
1846 if (age != session->age ||
1847 session->state != ISCSI_STATE_LOGGED_IN)
1848 return -ENOTCONN;
1849 return 0;
1850 }
1851
1852 /*
1853 * Fail commands. session lock held and recv side suspended and xmit
1854 * thread flushed
1855 */
1856 static void fail_scsi_tasks(struct iscsi_conn *conn, u64 lun, int error)
1857 {
1858 struct iscsi_task *task;
1859 int i;
1860
1861 for (i = 0; i < conn->session->cmds_max; i++) {
1862 task = conn->session->cmds[i];
1863 if (!task->sc || task->state == ISCSI_TASK_FREE)
1864 continue;
1865
1866 if (lun != -1 && lun != task->sc->device->lun)
1867 continue;
1868
1869 ISCSI_DBG_SESSION(conn->session,
1870 "failing sc %p itt 0x%x state %d\n",
1871 task->sc, task->itt, task->state);
1872 fail_scsi_task(task, error);
1873 }
1874 }
1875
1876 /**
1877 * iscsi_suspend_queue - suspend iscsi_queuecommand
1878 * @conn: iscsi conn to stop queueing IO on
1879 *
1880 * This grabs the session frwd_lock to make sure no one is in
1881 * xmit_task/queuecommand, and then sets suspend to prevent
1882 * new commands from being queued. This only needs to be called
1883 * by offload drivers that need to sync a path like ep disconnect
1884 * with the iscsi_queuecommand/xmit_task. To start IO again libiscsi
1885 * will call iscsi_start_tx and iscsi_unblock_session when in FFP.
1886 */
1887 void iscsi_suspend_queue(struct iscsi_conn *conn)
1888 {
1889 spin_lock_bh(&conn->session->frwd_lock);
1890 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1891 spin_unlock_bh(&conn->session->frwd_lock);
1892 }
1893 EXPORT_SYMBOL_GPL(iscsi_suspend_queue);
1894
1895 /**
1896 * iscsi_suspend_tx - suspend iscsi_data_xmit
1897 * @conn: iscsi conn tp stop processing IO on.
1898 *
1899 * This function sets the suspend bit to prevent iscsi_data_xmit
1900 * from sending new IO, and if work is queued on the xmit thread
1901 * it will wait for it to be completed.
1902 */
1903 void iscsi_suspend_tx(struct iscsi_conn *conn)
1904 {
1905 struct Scsi_Host *shost = conn->session->host;
1906 struct iscsi_host *ihost = shost_priv(shost);
1907
1908 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1909 if (ihost->workq)
1910 flush_workqueue(ihost->workq);
1911 }
1912 EXPORT_SYMBOL_GPL(iscsi_suspend_tx);
1913
1914 static void iscsi_start_tx(struct iscsi_conn *conn)
1915 {
1916 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1917 iscsi_conn_queue_work(conn);
1918 }
1919
1920 /*
1921 * We want to make sure a ping is in flight. It has timed out.
1922 * And we are not busy processing a pdu that is making
1923 * progress but got started before the ping and is taking a while
1924 * to complete so the ping is just stuck behind it in a queue.
1925 */
1926 static int iscsi_has_ping_timed_out(struct iscsi_conn *conn)
1927 {
1928 if (READ_ONCE(conn->ping_task) &&
1929 time_before_eq(conn->last_recv + (conn->recv_timeout * HZ) +
1930 (conn->ping_timeout * HZ), jiffies))
1931 return 1;
1932 else
1933 return 0;
1934 }
1935
1936 enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
1937 {
1938 enum blk_eh_timer_return rc = BLK_EH_DONE;
1939 struct iscsi_task *task = NULL, *running_task;
1940 struct iscsi_cls_session *cls_session;
1941 struct iscsi_session *session;
1942 struct iscsi_conn *conn;
1943 int i;
1944
1945 cls_session = starget_to_session(scsi_target(sc->device));
1946 session = cls_session->dd_data;
1947
1948 ISCSI_DBG_EH(session, "scsi cmd %p timedout\n", sc);
1949
1950 spin_lock_bh(&session->frwd_lock);
1951 task = (struct iscsi_task *)sc->SCp.ptr;
1952 if (!task) {
1953 /*
1954 * Raced with completion. Blk layer has taken ownership
1955 * so let timeout code complete it now.
1956 */
1957 rc = BLK_EH_DONE;
1958 goto done;
1959 }
1960
1961 if (session->state != ISCSI_STATE_LOGGED_IN) {
1962 /*
1963 * During shutdown, if session is prematurely disconnected,
1964 * recovery won't happen and there will be hung cmds. Not
1965 * handling cmds would trigger EH, also bad in this case.
1966 * Instead, handle cmd, allow completion to happen and let
1967 * upper layer to deal with the result.
1968 */
1969 if (unlikely(system_state != SYSTEM_RUNNING)) {
1970 sc->result = DID_NO_CONNECT << 16;
1971 ISCSI_DBG_EH(session, "sc on shutdown, handled\n");
1972 rc = BLK_EH_DONE;
1973 goto done;
1974 }
1975 /*
1976 * We are probably in the middle of iscsi recovery so let
1977 * that complete and handle the error.
1978 */
1979 rc = BLK_EH_RESET_TIMER;
1980 goto done;
1981 }
1982
1983 conn = session->leadconn;
1984 if (!conn) {
1985 /* In the middle of shuting down */
1986 rc = BLK_EH_RESET_TIMER;
1987 goto done;
1988 }
1989
1990 /*
1991 * If we have sent (at least queued to the network layer) a pdu or
1992 * recvd one for the task since the last timeout ask for
1993 * more time. If on the next timeout we have not made progress
1994 * we can check if it is the task or connection when we send the
1995 * nop as a ping.
1996 */
1997 if (time_after(task->last_xfer, task->last_timeout)) {
1998 ISCSI_DBG_EH(session, "Command making progress. Asking "
1999 "scsi-ml for more time to complete. "
2000 "Last data xfer at %lu. Last timeout was at "
2001 "%lu\n.", task->last_xfer, task->last_timeout);
2002 task->have_checked_conn = false;
2003 rc = BLK_EH_RESET_TIMER;
2004 goto done;
2005 }
2006
2007 if (!conn->recv_timeout && !conn->ping_timeout)
2008 goto done;
2009 /*
2010 * if the ping timedout then we are in the middle of cleaning up
2011 * and can let the iscsi eh handle it
2012 */
2013 if (iscsi_has_ping_timed_out(conn)) {
2014 rc = BLK_EH_RESET_TIMER;
2015 goto done;
2016 }
2017
2018 for (i = 0; i < conn->session->cmds_max; i++) {
2019 running_task = conn->session->cmds[i];
2020 if (!running_task->sc || running_task == task ||
2021 running_task->state != ISCSI_TASK_RUNNING)
2022 continue;
2023
2024 /*
2025 * Only check if cmds started before this one have made
2026 * progress, or this could never fail
2027 */
2028 if (time_after(running_task->sc->jiffies_at_alloc,
2029 task->sc->jiffies_at_alloc))
2030 continue;
2031
2032 if (time_after(running_task->last_xfer, task->last_timeout)) {
2033 /*
2034 * This task has not made progress, but a task
2035 * started before us has transferred data since
2036 * we started/last-checked. We could be queueing
2037 * too many tasks or the LU is bad.
2038 *
2039 * If the device is bad the cmds ahead of us on
2040 * other devs will complete, and this loop will
2041 * eventually fail starting the scsi eh.
2042 */
2043 ISCSI_DBG_EH(session, "Command has not made progress "
2044 "but commands ahead of it have. "
2045 "Asking scsi-ml for more time to "
2046 "complete. Our last xfer vs running task "
2047 "last xfer %lu/%lu. Last check %lu.\n",
2048 task->last_xfer, running_task->last_xfer,
2049 task->last_timeout);
2050 rc = BLK_EH_RESET_TIMER;
2051 goto done;
2052 }
2053 }
2054
2055 /* Assumes nop timeout is shorter than scsi cmd timeout */
2056 if (task->have_checked_conn)
2057 goto done;
2058
2059 /*
2060 * Checking the transport already or nop from a cmd timeout still
2061 * running
2062 */
2063 if (READ_ONCE(conn->ping_task)) {
2064 task->have_checked_conn = true;
2065 rc = BLK_EH_RESET_TIMER;
2066 goto done;
2067 }
2068
2069 /* Make sure there is a transport check done */
2070 iscsi_send_nopout(conn, NULL);
2071 task->have_checked_conn = true;
2072 rc = BLK_EH_RESET_TIMER;
2073
2074 done:
2075 if (task)
2076 task->last_timeout = jiffies;
2077 spin_unlock_bh(&session->frwd_lock);
2078 ISCSI_DBG_EH(session, "return %s\n", rc == BLK_EH_RESET_TIMER ?
2079 "timer reset" : "shutdown or nh");
2080 return rc;
2081 }
2082 EXPORT_SYMBOL_GPL(iscsi_eh_cmd_timed_out);
2083
2084 static void iscsi_check_transport_timeouts(struct timer_list *t)
2085 {
2086 struct iscsi_conn *conn = from_timer(conn, t, transport_timer);
2087 struct iscsi_session *session = conn->session;
2088 unsigned long recv_timeout, next_timeout = 0, last_recv;
2089
2090 spin_lock(&session->frwd_lock);
2091 if (session->state != ISCSI_STATE_LOGGED_IN)
2092 goto done;
2093
2094 recv_timeout = conn->recv_timeout;
2095 if (!recv_timeout)
2096 goto done;
2097
2098 recv_timeout *= HZ;
2099 last_recv = conn->last_recv;
2100
2101 if (iscsi_has_ping_timed_out(conn)) {
2102 iscsi_conn_printk(KERN_ERR, conn, "ping timeout of %d secs "
2103 "expired, recv timeout %d, last rx %lu, "
2104 "last ping %lu, now %lu\n",
2105 conn->ping_timeout, conn->recv_timeout,
2106 last_recv, conn->last_ping, jiffies);
2107 spin_unlock(&session->frwd_lock);
2108 iscsi_conn_failure(conn, ISCSI_ERR_NOP_TIMEDOUT);
2109 return;
2110 }
2111
2112 if (time_before_eq(last_recv + recv_timeout, jiffies)) {
2113 /* send a ping to try to provoke some traffic */
2114 ISCSI_DBG_CONN(conn, "Sending nopout as ping\n");
2115 if (iscsi_send_nopout(conn, NULL))
2116 next_timeout = jiffies + (1 * HZ);
2117 else
2118 next_timeout = conn->last_ping + (conn->ping_timeout * HZ);
2119 } else
2120 next_timeout = last_recv + recv_timeout;
2121
2122 ISCSI_DBG_CONN(conn, "Setting next tmo %lu\n", next_timeout);
2123 mod_timer(&conn->transport_timer, next_timeout);
2124 done:
2125 spin_unlock(&session->frwd_lock);
2126 }
2127
2128 static void iscsi_prep_abort_task_pdu(struct iscsi_task *task,
2129 struct iscsi_tm *hdr)
2130 {
2131 memset(hdr, 0, sizeof(*hdr));
2132 hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
2133 hdr->flags = ISCSI_TM_FUNC_ABORT_TASK & ISCSI_FLAG_TM_FUNC_MASK;
2134 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
2135 hdr->lun = task->lun;
2136 hdr->rtt = task->hdr_itt;
2137 hdr->refcmdsn = task->cmdsn;
2138 }
2139
2140 int iscsi_eh_abort(struct scsi_cmnd *sc)
2141 {
2142 struct iscsi_cls_session *cls_session;
2143 struct iscsi_session *session;
2144 struct iscsi_conn *conn;
2145 struct iscsi_task *task;
2146 struct iscsi_tm *hdr;
2147 int age;
2148
2149 cls_session = starget_to_session(scsi_target(sc->device));
2150 session = cls_session->dd_data;
2151
2152 ISCSI_DBG_EH(session, "aborting sc %p\n", sc);
2153
2154 mutex_lock(&session->eh_mutex);
2155 spin_lock_bh(&session->frwd_lock);
2156 /*
2157 * if session was ISCSI_STATE_IN_RECOVERY then we may not have
2158 * got the command.
2159 */
2160 if (!sc->SCp.ptr) {
2161 ISCSI_DBG_EH(session, "sc never reached iscsi layer or "
2162 "it completed.\n");
2163 spin_unlock_bh(&session->frwd_lock);
2164 mutex_unlock(&session->eh_mutex);
2165 return SUCCESS;
2166 }
2167
2168 /*
2169 * If we are not logged in or we have started a new session
2170 * then let the host reset code handle this
2171 */
2172 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN ||
2173 sc->SCp.phase != session->age) {
2174 spin_unlock_bh(&session->frwd_lock);
2175 mutex_unlock(&session->eh_mutex);
2176 ISCSI_DBG_EH(session, "failing abort due to dropped "
2177 "session.\n");
2178 return FAILED;
2179 }
2180
2181 conn = session->leadconn;
2182 conn->eh_abort_cnt++;
2183 age = session->age;
2184
2185 task = (struct iscsi_task *)sc->SCp.ptr;
2186 ISCSI_DBG_EH(session, "aborting [sc %p itt 0x%x]\n",
2187 sc, task->itt);
2188
2189 /* task completed before time out */
2190 if (!task->sc) {
2191 ISCSI_DBG_EH(session, "sc completed while abort in progress\n");
2192 goto success;
2193 }
2194
2195 if (task->state == ISCSI_TASK_PENDING) {
2196 fail_scsi_task(task, DID_ABORT);
2197 goto success;
2198 }
2199
2200 /* only have one tmf outstanding at a time */
2201 if (conn->tmf_state != TMF_INITIAL)
2202 goto failed;
2203 conn->tmf_state = TMF_QUEUED;
2204
2205 hdr = &conn->tmhdr;
2206 iscsi_prep_abort_task_pdu(task, hdr);
2207
2208 if (iscsi_exec_task_mgmt_fn(conn, hdr, age, session->abort_timeout))
2209 goto failed;
2210
2211 switch (conn->tmf_state) {
2212 case TMF_SUCCESS:
2213 spin_unlock_bh(&session->frwd_lock);
2214 /*
2215 * stop tx side incase the target had sent a abort rsp but
2216 * the initiator was still writing out data.
2217 */
2218 iscsi_suspend_tx(conn);
2219 /*
2220 * we do not stop the recv side because targets have been
2221 * good and have never sent us a successful tmf response
2222 * then sent more data for the cmd.
2223 */
2224 spin_lock_bh(&session->frwd_lock);
2225 fail_scsi_task(task, DID_ABORT);
2226 conn->tmf_state = TMF_INITIAL;
2227 memset(hdr, 0, sizeof(*hdr));
2228 spin_unlock_bh(&session->frwd_lock);
2229 iscsi_start_tx(conn);
2230 goto success_unlocked;
2231 case TMF_TIMEDOUT:
2232 spin_unlock_bh(&session->frwd_lock);
2233 iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST);
2234 goto failed_unlocked;
2235 case TMF_NOT_FOUND:
2236 if (!sc->SCp.ptr) {
2237 conn->tmf_state = TMF_INITIAL;
2238 memset(hdr, 0, sizeof(*hdr));
2239 /* task completed before tmf abort response */
2240 ISCSI_DBG_EH(session, "sc completed while abort in "
2241 "progress\n");
2242 goto success;
2243 }
2244 fallthrough;
2245 default:
2246 conn->tmf_state = TMF_INITIAL;
2247 goto failed;
2248 }
2249
2250 success:
2251 spin_unlock_bh(&session->frwd_lock);
2252 success_unlocked:
2253 ISCSI_DBG_EH(session, "abort success [sc %p itt 0x%x]\n",
2254 sc, task->itt);
2255 mutex_unlock(&session->eh_mutex);
2256 return SUCCESS;
2257
2258 failed:
2259 spin_unlock_bh(&session->frwd_lock);
2260 failed_unlocked:
2261 ISCSI_DBG_EH(session, "abort failed [sc %p itt 0x%x]\n", sc,
2262 task ? task->itt : 0);
2263 mutex_unlock(&session->eh_mutex);
2264 return FAILED;
2265 }
2266 EXPORT_SYMBOL_GPL(iscsi_eh_abort);
2267
2268 static void iscsi_prep_lun_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr)
2269 {
2270 memset(hdr, 0, sizeof(*hdr));
2271 hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
2272 hdr->flags = ISCSI_TM_FUNC_LOGICAL_UNIT_RESET & ISCSI_FLAG_TM_FUNC_MASK;
2273 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
2274 int_to_scsilun(sc->device->lun, &hdr->lun);
2275 hdr->rtt = RESERVED_ITT;
2276 }
2277
2278 int iscsi_eh_device_reset(struct scsi_cmnd *sc)
2279 {
2280 struct iscsi_cls_session *cls_session;
2281 struct iscsi_session *session;
2282 struct iscsi_conn *conn;
2283 struct iscsi_tm *hdr;
2284 int rc = FAILED;
2285
2286 cls_session = starget_to_session(scsi_target(sc->device));
2287 session = cls_session->dd_data;
2288
2289 ISCSI_DBG_EH(session, "LU Reset [sc %p lun %llu]\n", sc,
2290 sc->device->lun);
2291
2292 mutex_lock(&session->eh_mutex);
2293 spin_lock_bh(&session->frwd_lock);
2294 /*
2295 * Just check if we are not logged in. We cannot check for
2296 * the phase because the reset could come from a ioctl.
2297 */
2298 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
2299 goto unlock;
2300 conn = session->leadconn;
2301
2302 /* only have one tmf outstanding at a time */
2303 if (conn->tmf_state != TMF_INITIAL)
2304 goto unlock;
2305 conn->tmf_state = TMF_QUEUED;
2306
2307 hdr = &conn->tmhdr;
2308 iscsi_prep_lun_reset_pdu(sc, hdr);
2309
2310 if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age,
2311 session->lu_reset_timeout)) {
2312 rc = FAILED;
2313 goto unlock;
2314 }
2315
2316 switch (conn->tmf_state) {
2317 case TMF_SUCCESS:
2318 break;
2319 case TMF_TIMEDOUT:
2320 spin_unlock_bh(&session->frwd_lock);
2321 iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST);
2322 goto done;
2323 default:
2324 conn->tmf_state = TMF_INITIAL;
2325 goto unlock;
2326 }
2327
2328 rc = SUCCESS;
2329 spin_unlock_bh(&session->frwd_lock);
2330
2331 iscsi_suspend_tx(conn);
2332
2333 spin_lock_bh(&session->frwd_lock);
2334 memset(hdr, 0, sizeof(*hdr));
2335 fail_scsi_tasks(conn, sc->device->lun, DID_ERROR);
2336 conn->tmf_state = TMF_INITIAL;
2337 spin_unlock_bh(&session->frwd_lock);
2338
2339 iscsi_start_tx(conn);
2340 goto done;
2341
2342 unlock:
2343 spin_unlock_bh(&session->frwd_lock);
2344 done:
2345 ISCSI_DBG_EH(session, "dev reset result = %s\n",
2346 rc == SUCCESS ? "SUCCESS" : "FAILED");
2347 mutex_unlock(&session->eh_mutex);
2348 return rc;
2349 }
2350 EXPORT_SYMBOL_GPL(iscsi_eh_device_reset);
2351
2352 void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session)
2353 {
2354 struct iscsi_session *session = cls_session->dd_data;
2355
2356 spin_lock_bh(&session->frwd_lock);
2357 if (session->state != ISCSI_STATE_LOGGED_IN) {
2358 session->state = ISCSI_STATE_RECOVERY_FAILED;
2359 if (session->leadconn)
2360 wake_up(&session->leadconn->ehwait);
2361 }
2362 spin_unlock_bh(&session->frwd_lock);
2363 }
2364 EXPORT_SYMBOL_GPL(iscsi_session_recovery_timedout);
2365
2366 /**
2367 * iscsi_eh_session_reset - drop session and attempt relogin
2368 * @sc: scsi command
2369 *
2370 * This function will wait for a relogin, session termination from
2371 * userspace, or a recovery/replacement timeout.
2372 */
2373 int iscsi_eh_session_reset(struct scsi_cmnd *sc)
2374 {
2375 struct iscsi_cls_session *cls_session;
2376 struct iscsi_session *session;
2377 struct iscsi_conn *conn;
2378
2379 cls_session = starget_to_session(scsi_target(sc->device));
2380 session = cls_session->dd_data;
2381 conn = session->leadconn;
2382
2383 mutex_lock(&session->eh_mutex);
2384 spin_lock_bh(&session->frwd_lock);
2385 if (session->state == ISCSI_STATE_TERMINATE) {
2386 failed:
2387 ISCSI_DBG_EH(session,
2388 "failing session reset: Could not log back into "
2389 "%s [age %d]\n", session->targetname,
2390 session->age);
2391 spin_unlock_bh(&session->frwd_lock);
2392 mutex_unlock(&session->eh_mutex);
2393 return FAILED;
2394 }
2395
2396 spin_unlock_bh(&session->frwd_lock);
2397 mutex_unlock(&session->eh_mutex);
2398 /*
2399 * we drop the lock here but the leadconn cannot be destoyed while
2400 * we are in the scsi eh
2401 */
2402 iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST);
2403
2404 ISCSI_DBG_EH(session, "wait for relogin\n");
2405 wait_event_interruptible(conn->ehwait,
2406 session->state == ISCSI_STATE_TERMINATE ||
2407 session->state == ISCSI_STATE_LOGGED_IN ||
2408 session->state == ISCSI_STATE_RECOVERY_FAILED);
2409 if (signal_pending(current))
2410 flush_signals(current);
2411
2412 mutex_lock(&session->eh_mutex);
2413 spin_lock_bh(&session->frwd_lock);
2414 if (session->state == ISCSI_STATE_LOGGED_IN) {
2415 ISCSI_DBG_EH(session,
2416 "session reset succeeded for %s,%s\n",
2417 session->targetname, conn->persistent_address);
2418 } else
2419 goto failed;
2420 spin_unlock_bh(&session->frwd_lock);
2421 mutex_unlock(&session->eh_mutex);
2422 return SUCCESS;
2423 }
2424 EXPORT_SYMBOL_GPL(iscsi_eh_session_reset);
2425
2426 static void iscsi_prep_tgt_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr)
2427 {
2428 memset(hdr, 0, sizeof(*hdr));
2429 hdr->opcode = ISCSI_OP_SCSI_TMFUNC | ISCSI_OP_IMMEDIATE;
2430 hdr->flags = ISCSI_TM_FUNC_TARGET_WARM_RESET & ISCSI_FLAG_TM_FUNC_MASK;
2431 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
2432 hdr->rtt = RESERVED_ITT;
2433 }
2434
2435 /**
2436 * iscsi_eh_target_reset - reset target
2437 * @sc: scsi command
2438 *
2439 * This will attempt to send a warm target reset.
2440 */
2441 static int iscsi_eh_target_reset(struct scsi_cmnd *sc)
2442 {
2443 struct iscsi_cls_session *cls_session;
2444 struct iscsi_session *session;
2445 struct iscsi_conn *conn;
2446 struct iscsi_tm *hdr;
2447 int rc = FAILED;
2448
2449 cls_session = starget_to_session(scsi_target(sc->device));
2450 session = cls_session->dd_data;
2451
2452 ISCSI_DBG_EH(session, "tgt Reset [sc %p tgt %s]\n", sc,
2453 session->targetname);
2454
2455 mutex_lock(&session->eh_mutex);
2456 spin_lock_bh(&session->frwd_lock);
2457 /*
2458 * Just check if we are not logged in. We cannot check for
2459 * the phase because the reset could come from a ioctl.
2460 */
2461 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN)
2462 goto unlock;
2463 conn = session->leadconn;
2464
2465 /* only have one tmf outstanding at a time */
2466 if (conn->tmf_state != TMF_INITIAL)
2467 goto unlock;
2468 conn->tmf_state = TMF_QUEUED;
2469
2470 hdr = &conn->tmhdr;
2471 iscsi_prep_tgt_reset_pdu(sc, hdr);
2472
2473 if (iscsi_exec_task_mgmt_fn(conn, hdr, session->age,
2474 session->tgt_reset_timeout)) {
2475 rc = FAILED;
2476 goto unlock;
2477 }
2478
2479 switch (conn->tmf_state) {
2480 case TMF_SUCCESS:
2481 break;
2482 case TMF_TIMEDOUT:
2483 spin_unlock_bh(&session->frwd_lock);
2484 iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST);
2485 goto done;
2486 default:
2487 conn->tmf_state = TMF_INITIAL;
2488 goto unlock;
2489 }
2490
2491 rc = SUCCESS;
2492 spin_unlock_bh(&session->frwd_lock);
2493
2494 iscsi_suspend_tx(conn);
2495
2496 spin_lock_bh(&session->frwd_lock);
2497 memset(hdr, 0, sizeof(*hdr));
2498 fail_scsi_tasks(conn, -1, DID_ERROR);
2499 conn->tmf_state = TMF_INITIAL;
2500 spin_unlock_bh(&session->frwd_lock);
2501
2502 iscsi_start_tx(conn);
2503 goto done;
2504
2505 unlock:
2506 spin_unlock_bh(&session->frwd_lock);
2507 done:
2508 ISCSI_DBG_EH(session, "tgt %s reset result = %s\n", session->targetname,
2509 rc == SUCCESS ? "SUCCESS" : "FAILED");
2510 mutex_unlock(&session->eh_mutex);
2511 return rc;
2512 }
2513
2514 /**
2515 * iscsi_eh_recover_target - reset target and possibly the session
2516 * @sc: scsi command
2517 *
2518 * This will attempt to send a warm target reset. If that fails,
2519 * we will escalate to ERL0 session recovery.
2520 */
2521 int iscsi_eh_recover_target(struct scsi_cmnd *sc)
2522 {
2523 int rc;
2524
2525 rc = iscsi_eh_target_reset(sc);
2526 if (rc == FAILED)
2527 rc = iscsi_eh_session_reset(sc);
2528 return rc;
2529 }
2530 EXPORT_SYMBOL_GPL(iscsi_eh_recover_target);
2531
2532 /*
2533 * Pre-allocate a pool of @max items of @item_size. By default, the pool
2534 * should be accessed via kfifo_{get,put} on q->queue.
2535 * Optionally, the caller can obtain the array of object pointers
2536 * by passing in a non-NULL @items pointer
2537 */
2538 int
2539 iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size)
2540 {
2541 int i, num_arrays = 1;
2542
2543 memset(q, 0, sizeof(*q));
2544
2545 q->max = max;
2546
2547 /* If the user passed an items pointer, he wants a copy of
2548 * the array. */
2549 if (items)
2550 num_arrays++;
2551 q->pool = kvcalloc(num_arrays * max, sizeof(void *), GFP_KERNEL);
2552 if (q->pool == NULL)
2553 return -ENOMEM;
2554
2555 kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*));
2556
2557 for (i = 0; i < max; i++) {
2558 q->pool[i] = kzalloc(item_size, GFP_KERNEL);
2559 if (q->pool[i] == NULL) {
2560 q->max = i;
2561 goto enomem;
2562 }
2563 kfifo_in(&q->queue, (void*)&q->pool[i], sizeof(void*));
2564 }
2565
2566 if (items) {
2567 *items = q->pool + max;
2568 memcpy(*items, q->pool, max * sizeof(void *));
2569 }
2570
2571 return 0;
2572
2573 enomem:
2574 iscsi_pool_free(q);
2575 return -ENOMEM;
2576 }
2577 EXPORT_SYMBOL_GPL(iscsi_pool_init);
2578
2579 void iscsi_pool_free(struct iscsi_pool *q)
2580 {
2581 int i;
2582
2583 for (i = 0; i < q->max; i++)
2584 kfree(q->pool[i]);
2585 kvfree(q->pool);
2586 }
2587 EXPORT_SYMBOL_GPL(iscsi_pool_free);
2588
2589 /**
2590 * iscsi_host_add - add host to system
2591 * @shost: scsi host
2592 * @pdev: parent device
2593 *
2594 * This should be called by partial offload and software iscsi drivers
2595 * to add a host to the system.
2596 */
2597 int iscsi_host_add(struct Scsi_Host *shost, struct device *pdev)
2598 {
2599 if (!shost->can_queue)
2600 shost->can_queue = ISCSI_DEF_XMIT_CMDS_MAX;
2601
2602 if (!shost->cmd_per_lun)
2603 shost->cmd_per_lun = ISCSI_DEF_CMD_PER_LUN;
2604
2605 return scsi_add_host(shost, pdev);
2606 }
2607 EXPORT_SYMBOL_GPL(iscsi_host_add);
2608
2609 /**
2610 * iscsi_host_alloc - allocate a host and driver data
2611 * @sht: scsi host template
2612 * @dd_data_size: driver host data size
2613 * @xmit_can_sleep: bool indicating if LLD will queue IO from a work queue
2614 *
2615 * This should be called by partial offload and software iscsi drivers.
2616 * To access the driver specific memory use the iscsi_host_priv() macro.
2617 */
2618 struct Scsi_Host *iscsi_host_alloc(struct scsi_host_template *sht,
2619 int dd_data_size, bool xmit_can_sleep)
2620 {
2621 struct Scsi_Host *shost;
2622 struct iscsi_host *ihost;
2623
2624 shost = scsi_host_alloc(sht, sizeof(struct iscsi_host) + dd_data_size);
2625 if (!shost)
2626 return NULL;
2627 ihost = shost_priv(shost);
2628
2629 if (xmit_can_sleep) {
2630 snprintf(ihost->workq_name, sizeof(ihost->workq_name),
2631 "iscsi_q_%d", shost->host_no);
2632 ihost->workq = alloc_workqueue("%s",
2633 WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND,
2634 1, ihost->workq_name);
2635 if (!ihost->workq)
2636 goto free_host;
2637 }
2638
2639 spin_lock_init(&ihost->lock);
2640 ihost->state = ISCSI_HOST_SETUP;
2641 ihost->num_sessions = 0;
2642 init_waitqueue_head(&ihost->session_removal_wq);
2643 return shost;
2644
2645 free_host:
2646 scsi_host_put(shost);
2647 return NULL;
2648 }
2649 EXPORT_SYMBOL_GPL(iscsi_host_alloc);
2650
2651 static void iscsi_notify_host_removed(struct iscsi_cls_session *cls_session)
2652 {
2653 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_INVALID_HOST);
2654 }
2655
2656 /**
2657 * iscsi_host_remove - remove host and sessions
2658 * @shost: scsi host
2659 *
2660 * If there are any sessions left, this will initiate the removal and wait
2661 * for the completion.
2662 */
2663 void iscsi_host_remove(struct Scsi_Host *shost)
2664 {
2665 struct iscsi_host *ihost = shost_priv(shost);
2666 unsigned long flags;
2667
2668 spin_lock_irqsave(&ihost->lock, flags);
2669 ihost->state = ISCSI_HOST_REMOVED;
2670 spin_unlock_irqrestore(&ihost->lock, flags);
2671
2672 iscsi_host_for_each_session(shost, iscsi_notify_host_removed);
2673 wait_event_interruptible(ihost->session_removal_wq,
2674 ihost->num_sessions == 0);
2675 if (signal_pending(current))
2676 flush_signals(current);
2677
2678 scsi_remove_host(shost);
2679 if (ihost->workq)
2680 destroy_workqueue(ihost->workq);
2681 }
2682 EXPORT_SYMBOL_GPL(iscsi_host_remove);
2683
2684 void iscsi_host_free(struct Scsi_Host *shost)
2685 {
2686 struct iscsi_host *ihost = shost_priv(shost);
2687
2688 kfree(ihost->netdev);
2689 kfree(ihost->hwaddress);
2690 kfree(ihost->initiatorname);
2691 scsi_host_put(shost);
2692 }
2693 EXPORT_SYMBOL_GPL(iscsi_host_free);
2694
2695 static void iscsi_host_dec_session_cnt(struct Scsi_Host *shost)
2696 {
2697 struct iscsi_host *ihost = shost_priv(shost);
2698 unsigned long flags;
2699
2700 shost = scsi_host_get(shost);
2701 if (!shost) {
2702 printk(KERN_ERR "Invalid state. Cannot notify host removal "
2703 "of session teardown event because host already "
2704 "removed.\n");
2705 return;
2706 }
2707
2708 spin_lock_irqsave(&ihost->lock, flags);
2709 ihost->num_sessions--;
2710 if (ihost->num_sessions == 0)
2711 wake_up(&ihost->session_removal_wq);
2712 spin_unlock_irqrestore(&ihost->lock, flags);
2713 scsi_host_put(shost);
2714 }
2715
2716 /**
2717 * iscsi_session_setup - create iscsi cls session and host and session
2718 * @iscsit: iscsi transport template
2719 * @shost: scsi host
2720 * @cmds_max: session can queue
2721 * @dd_size: private driver data size, added to session allocation size
2722 * @cmd_task_size: LLD task private data size
2723 * @initial_cmdsn: initial CmdSN
2724 * @id: target ID to add to this session
2725 *
2726 * This can be used by software iscsi_transports that allocate
2727 * a session per scsi host.
2728 *
2729 * Callers should set cmds_max to the largest total numer (mgmt + scsi) of
2730 * tasks they support. The iscsi layer reserves ISCSI_MGMT_CMDS_MAX tasks
2731 * for nop handling and login/logout requests.
2732 */
2733 struct iscsi_cls_session *
2734 iscsi_session_setup(struct iscsi_transport *iscsit, struct Scsi_Host *shost,
2735 uint16_t cmds_max, int dd_size, int cmd_task_size,
2736 uint32_t initial_cmdsn, unsigned int id)
2737 {
2738 struct iscsi_host *ihost = shost_priv(shost);
2739 struct iscsi_session *session;
2740 struct iscsi_cls_session *cls_session;
2741 int cmd_i, scsi_cmds, total_cmds = cmds_max;
2742 unsigned long flags;
2743
2744 spin_lock_irqsave(&ihost->lock, flags);
2745 if (ihost->state == ISCSI_HOST_REMOVED) {
2746 spin_unlock_irqrestore(&ihost->lock, flags);
2747 return NULL;
2748 }
2749 ihost->num_sessions++;
2750 spin_unlock_irqrestore(&ihost->lock, flags);
2751
2752 if (!total_cmds)
2753 total_cmds = ISCSI_DEF_XMIT_CMDS_MAX;
2754 /*
2755 * The iscsi layer needs some tasks for nop handling and tmfs,
2756 * so the cmds_max must at least be greater than ISCSI_MGMT_CMDS_MAX
2757 * + 1 command for scsi IO.
2758 */
2759 if (total_cmds < ISCSI_TOTAL_CMDS_MIN) {
2760 printk(KERN_ERR "iscsi: invalid can_queue of %d. can_queue "
2761 "must be a power of two that is at least %d.\n",
2762 total_cmds, ISCSI_TOTAL_CMDS_MIN);
2763 goto dec_session_count;
2764 }
2765
2766 if (total_cmds > ISCSI_TOTAL_CMDS_MAX) {
2767 printk(KERN_ERR "iscsi: invalid can_queue of %d. can_queue "
2768 "must be a power of 2 less than or equal to %d.\n",
2769 cmds_max, ISCSI_TOTAL_CMDS_MAX);
2770 total_cmds = ISCSI_TOTAL_CMDS_MAX;
2771 }
2772
2773 if (!is_power_of_2(total_cmds)) {
2774 printk(KERN_ERR "iscsi: invalid can_queue of %d. can_queue "
2775 "must be a power of 2.\n", total_cmds);
2776 total_cmds = rounddown_pow_of_two(total_cmds);
2777 if (total_cmds < ISCSI_TOTAL_CMDS_MIN)
2778 goto dec_session_count;
2779 printk(KERN_INFO "iscsi: Rounding can_queue to %d.\n",
2780 total_cmds);
2781 }
2782 scsi_cmds = total_cmds - ISCSI_MGMT_CMDS_MAX;
2783
2784 cls_session = iscsi_alloc_session(shost, iscsit,
2785 sizeof(struct iscsi_session) +
2786 dd_size);
2787 if (!cls_session)
2788 goto dec_session_count;
2789 session = cls_session->dd_data;
2790 session->cls_session = cls_session;
2791 session->host = shost;
2792 session->state = ISCSI_STATE_FREE;
2793 session->fast_abort = 1;
2794 session->tgt_reset_timeout = 30;
2795 session->lu_reset_timeout = 15;
2796 session->abort_timeout = 10;
2797 session->scsi_cmds_max = scsi_cmds;
2798 session->cmds_max = total_cmds;
2799 session->queued_cmdsn = session->cmdsn = initial_cmdsn;
2800 session->exp_cmdsn = initial_cmdsn + 1;
2801 session->max_cmdsn = initial_cmdsn + 1;
2802 session->max_r2t = 1;
2803 session->tt = iscsit;
2804 session->dd_data = cls_session->dd_data + sizeof(*session);
2805
2806 mutex_init(&session->eh_mutex);
2807 spin_lock_init(&session->frwd_lock);
2808 spin_lock_init(&session->back_lock);
2809
2810 /* initialize SCSI PDU commands pool */
2811 if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
2812 (void***)&session->cmds,
2813 cmd_task_size + sizeof(struct iscsi_task)))
2814 goto cmdpool_alloc_fail;
2815
2816 /* pre-format cmds pool with ITT */
2817 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
2818 struct iscsi_task *task = session->cmds[cmd_i];
2819
2820 if (cmd_task_size)
2821 task->dd_data = &task[1];
2822 task->itt = cmd_i;
2823 task->state = ISCSI_TASK_FREE;
2824 INIT_LIST_HEAD(&task->running);
2825 }
2826
2827 if (!try_module_get(iscsit->owner))
2828 goto module_get_fail;
2829
2830 if (iscsi_add_session(cls_session, id))
2831 goto cls_session_fail;
2832
2833 return cls_session;
2834
2835 cls_session_fail:
2836 module_put(iscsit->owner);
2837 module_get_fail:
2838 iscsi_pool_free(&session->cmdpool);
2839 cmdpool_alloc_fail:
2840 iscsi_free_session(cls_session);
2841 dec_session_count:
2842 iscsi_host_dec_session_cnt(shost);
2843 return NULL;
2844 }
2845 EXPORT_SYMBOL_GPL(iscsi_session_setup);
2846
2847 /**
2848 * iscsi_session_teardown - destroy session, host, and cls_session
2849 * @cls_session: iscsi session
2850 */
2851 void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
2852 {
2853 struct iscsi_session *session = cls_session->dd_data;
2854 struct module *owner = cls_session->transport->owner;
2855 struct Scsi_Host *shost = session->host;
2856
2857 iscsi_pool_free(&session->cmdpool);
2858
2859 iscsi_remove_session(cls_session);
2860
2861 kfree(session->password);
2862 kfree(session->password_in);
2863 kfree(session->username);
2864 kfree(session->username_in);
2865 kfree(session->targetname);
2866 kfree(session->targetalias);
2867 kfree(session->initiatorname);
2868 kfree(session->boot_root);
2869 kfree(session->boot_nic);
2870 kfree(session->boot_target);
2871 kfree(session->ifacename);
2872 kfree(session->portal_type);
2873 kfree(session->discovery_parent_type);
2874
2875 iscsi_free_session(cls_session);
2876
2877 iscsi_host_dec_session_cnt(shost);
2878 module_put(owner);
2879 }
2880 EXPORT_SYMBOL_GPL(iscsi_session_teardown);
2881
2882 /**
2883 * iscsi_conn_setup - create iscsi_cls_conn and iscsi_conn
2884 * @cls_session: iscsi_cls_session
2885 * @dd_size: private driver data size
2886 * @conn_idx: cid
2887 */
2888 struct iscsi_cls_conn *
2889 iscsi_conn_setup(struct iscsi_cls_session *cls_session, int dd_size,
2890 uint32_t conn_idx)
2891 {
2892 struct iscsi_session *session = cls_session->dd_data;
2893 struct iscsi_conn *conn;
2894 struct iscsi_cls_conn *cls_conn;
2895 char *data;
2896
2897 cls_conn = iscsi_create_conn(cls_session, sizeof(*conn) + dd_size,
2898 conn_idx);
2899 if (!cls_conn)
2900 return NULL;
2901 conn = cls_conn->dd_data;
2902 memset(conn, 0, sizeof(*conn) + dd_size);
2903
2904 conn->dd_data = cls_conn->dd_data + sizeof(*conn);
2905 conn->session = session;
2906 conn->cls_conn = cls_conn;
2907 conn->c_stage = ISCSI_CONN_INITIAL_STAGE;
2908 conn->id = conn_idx;
2909 conn->exp_statsn = 0;
2910 conn->tmf_state = TMF_INITIAL;
2911
2912 timer_setup(&conn->transport_timer, iscsi_check_transport_timeouts, 0);
2913
2914 INIT_LIST_HEAD(&conn->mgmtqueue);
2915 INIT_LIST_HEAD(&conn->cmdqueue);
2916 INIT_LIST_HEAD(&conn->requeue);
2917 spin_lock_init(&conn->taskqueuelock);
2918 INIT_WORK(&conn->xmitwork, iscsi_xmitworker);
2919
2920 /* allocate login_task used for the login/text sequences */
2921 spin_lock_bh(&session->frwd_lock);
2922 if (!kfifo_out(&session->cmdpool.queue,
2923 (void*)&conn->login_task,
2924 sizeof(void*))) {
2925 spin_unlock_bh(&session->frwd_lock);
2926 goto login_task_alloc_fail;
2927 }
2928 spin_unlock_bh(&session->frwd_lock);
2929
2930 data = (char *) __get_free_pages(GFP_KERNEL,
2931 get_order(ISCSI_DEF_MAX_RECV_SEG_LEN));
2932 if (!data)
2933 goto login_task_data_alloc_fail;
2934 conn->login_task->data = conn->data = data;
2935
2936 timer_setup(&conn->tmf_timer, iscsi_tmf_timedout, 0);
2937 init_waitqueue_head(&conn->ehwait);
2938
2939 return cls_conn;
2940
2941 login_task_data_alloc_fail:
2942 kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task,
2943 sizeof(void*));
2944 login_task_alloc_fail:
2945 iscsi_destroy_conn(cls_conn);
2946 return NULL;
2947 }
2948 EXPORT_SYMBOL_GPL(iscsi_conn_setup);
2949
2950 /**
2951 * iscsi_conn_teardown - teardown iscsi connection
2952 * @cls_conn: iscsi class connection
2953 *
2954 * TODO: we may need to make this into a two step process
2955 * like scsi-mls remove + put host
2956 */
2957 void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
2958 {
2959 struct iscsi_conn *conn = cls_conn->dd_data;
2960 struct iscsi_session *session = conn->session;
2961
2962 del_timer_sync(&conn->transport_timer);
2963
2964 mutex_lock(&session->eh_mutex);
2965 spin_lock_bh(&session->frwd_lock);
2966 conn->c_stage = ISCSI_CONN_CLEANUP_WAIT;
2967 if (session->leadconn == conn) {
2968 /*
2969 * leading connection? then give up on recovery.
2970 */
2971 session->state = ISCSI_STATE_TERMINATE;
2972 wake_up(&conn->ehwait);
2973 }
2974 spin_unlock_bh(&session->frwd_lock);
2975
2976 /* flush queued up work because we free the connection below */
2977 iscsi_suspend_tx(conn);
2978
2979 spin_lock_bh(&session->frwd_lock);
2980 free_pages((unsigned long) conn->data,
2981 get_order(ISCSI_DEF_MAX_RECV_SEG_LEN));
2982 kfree(conn->persistent_address);
2983 kfree(conn->local_ipaddr);
2984 /* regular RX path uses back_lock */
2985 spin_lock_bh(&session->back_lock);
2986 kfifo_in(&session->cmdpool.queue, (void*)&conn->login_task,
2987 sizeof(void*));
2988 spin_unlock_bh(&session->back_lock);
2989 if (session->leadconn == conn)
2990 session->leadconn = NULL;
2991 spin_unlock_bh(&session->frwd_lock);
2992 mutex_unlock(&session->eh_mutex);
2993
2994 iscsi_destroy_conn(cls_conn);
2995 }
2996 EXPORT_SYMBOL_GPL(iscsi_conn_teardown);
2997
2998 int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
2999 {
3000 struct iscsi_conn *conn = cls_conn->dd_data;
3001 struct iscsi_session *session = conn->session;
3002
3003 if (!session) {
3004 iscsi_conn_printk(KERN_ERR, conn,
3005 "can't start unbound connection\n");
3006 return -EPERM;
3007 }
3008
3009 if ((session->imm_data_en || !session->initial_r2t_en) &&
3010 session->first_burst > session->max_burst) {
3011 iscsi_conn_printk(KERN_INFO, conn, "invalid burst lengths: "
3012 "first_burst %d max_burst %d\n",
3013 session->first_burst, session->max_burst);
3014 return -EINVAL;
3015 }
3016
3017 if (conn->ping_timeout && !conn->recv_timeout) {
3018 iscsi_conn_printk(KERN_ERR, conn, "invalid recv timeout of "
3019 "zero. Using 5 seconds\n.");
3020 conn->recv_timeout = 5;
3021 }
3022
3023 if (conn->recv_timeout && !conn->ping_timeout) {
3024 iscsi_conn_printk(KERN_ERR, conn, "invalid ping timeout of "
3025 "zero. Using 5 seconds.\n");
3026 conn->ping_timeout = 5;
3027 }
3028
3029 spin_lock_bh(&session->frwd_lock);
3030 conn->c_stage = ISCSI_CONN_STARTED;
3031 session->state = ISCSI_STATE_LOGGED_IN;
3032 session->queued_cmdsn = session->cmdsn;
3033
3034 conn->last_recv = jiffies;
3035 conn->last_ping = jiffies;
3036 if (conn->recv_timeout && conn->ping_timeout)
3037 mod_timer(&conn->transport_timer,
3038 jiffies + (conn->recv_timeout * HZ));
3039
3040 switch(conn->stop_stage) {
3041 case STOP_CONN_RECOVER:
3042 /*
3043 * unblock eh_abort() if it is blocked. re-try all
3044 * commands after successful recovery
3045 */
3046 conn->stop_stage = 0;
3047 conn->tmf_state = TMF_INITIAL;
3048 session->age++;
3049 if (session->age == 16)
3050 session->age = 0;
3051 break;
3052 case STOP_CONN_TERM:
3053 conn->stop_stage = 0;
3054 break;
3055 default:
3056 break;
3057 }
3058 spin_unlock_bh(&session->frwd_lock);
3059
3060 iscsi_unblock_session(session->cls_session);
3061 wake_up(&conn->ehwait);
3062 return 0;
3063 }
3064 EXPORT_SYMBOL_GPL(iscsi_conn_start);
3065
3066 static void
3067 fail_mgmt_tasks(struct iscsi_session *session, struct iscsi_conn *conn)
3068 {
3069 struct iscsi_task *task;
3070 int i, state;
3071
3072 for (i = 0; i < conn->session->cmds_max; i++) {
3073 task = conn->session->cmds[i];
3074 if (task->sc)
3075 continue;
3076
3077 if (task->state == ISCSI_TASK_FREE)
3078 continue;
3079
3080 ISCSI_DBG_SESSION(conn->session,
3081 "failing mgmt itt 0x%x state %d\n",
3082 task->itt, task->state);
3083 state = ISCSI_TASK_ABRT_SESS_RECOV;
3084 if (task->state == ISCSI_TASK_PENDING)
3085 state = ISCSI_TASK_COMPLETED;
3086 spin_lock_bh(&session->back_lock);
3087 iscsi_complete_task(task, state);
3088 spin_unlock_bh(&session->back_lock);
3089 }
3090 }
3091
3092 static void iscsi_start_session_recovery(struct iscsi_session *session,
3093 struct iscsi_conn *conn, int flag)
3094 {
3095 int old_stop_stage;
3096
3097 mutex_lock(&session->eh_mutex);
3098 spin_lock_bh(&session->frwd_lock);
3099 if (conn->stop_stage == STOP_CONN_TERM) {
3100 spin_unlock_bh(&session->frwd_lock);
3101 mutex_unlock(&session->eh_mutex);
3102 return;
3103 }
3104
3105 /*
3106 * When this is called for the in_login state, we only want to clean
3107 * up the login task and connection. We do not need to block and set
3108 * the recovery state again
3109 */
3110 if (flag == STOP_CONN_TERM)
3111 session->state = ISCSI_STATE_TERMINATE;
3112 else if (conn->stop_stage != STOP_CONN_RECOVER)
3113 session->state = ISCSI_STATE_IN_RECOVERY;
3114
3115 old_stop_stage = conn->stop_stage;
3116 conn->stop_stage = flag;
3117 spin_unlock_bh(&session->frwd_lock);
3118
3119 del_timer_sync(&conn->transport_timer);
3120 iscsi_suspend_tx(conn);
3121
3122 spin_lock_bh(&session->frwd_lock);
3123 conn->c_stage = ISCSI_CONN_STOPPED;
3124 spin_unlock_bh(&session->frwd_lock);
3125
3126 /*
3127 * for connection level recovery we should not calculate
3128 * header digest. conn->hdr_size used for optimization
3129 * in hdr_extract() and will be re-negotiated at
3130 * set_param() time.
3131 */
3132 if (flag == STOP_CONN_RECOVER) {
3133 conn->hdrdgst_en = 0;
3134 conn->datadgst_en = 0;
3135 if (session->state == ISCSI_STATE_IN_RECOVERY &&
3136 old_stop_stage != STOP_CONN_RECOVER) {
3137 ISCSI_DBG_SESSION(session, "blocking session\n");
3138 iscsi_block_session(session->cls_session);
3139 }
3140 }
3141
3142 /*
3143 * flush queues.
3144 */
3145 spin_lock_bh(&session->frwd_lock);
3146 fail_scsi_tasks(conn, -1, DID_TRANSPORT_DISRUPTED);
3147 fail_mgmt_tasks(session, conn);
3148 memset(&conn->tmhdr, 0, sizeof(conn->tmhdr));
3149 spin_unlock_bh(&session->frwd_lock);
3150 mutex_unlock(&session->eh_mutex);
3151 }
3152
3153 void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
3154 {
3155 struct iscsi_conn *conn = cls_conn->dd_data;
3156 struct iscsi_session *session = conn->session;
3157
3158 switch (flag) {
3159 case STOP_CONN_RECOVER:
3160 cls_conn->state = ISCSI_CONN_FAILED;
3161 break;
3162 case STOP_CONN_TERM:
3163 cls_conn->state = ISCSI_CONN_DOWN;
3164 break;
3165 default:
3166 iscsi_conn_printk(KERN_ERR, conn,
3167 "invalid stop flag %d\n", flag);
3168 return;
3169 }
3170
3171 iscsi_start_session_recovery(session, conn, flag);
3172 }
3173 EXPORT_SYMBOL_GPL(iscsi_conn_stop);
3174
3175 int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
3176 struct iscsi_cls_conn *cls_conn, int is_leading)
3177 {
3178 struct iscsi_session *session = cls_session->dd_data;
3179 struct iscsi_conn *conn = cls_conn->dd_data;
3180
3181 spin_lock_bh(&session->frwd_lock);
3182 if (is_leading)
3183 session->leadconn = conn;
3184 spin_unlock_bh(&session->frwd_lock);
3185
3186 /*
3187 * Unblock xmitworker(), Login Phase will pass through.
3188 */
3189 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
3190 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
3191 return 0;
3192 }
3193 EXPORT_SYMBOL_GPL(iscsi_conn_bind);
3194
3195 int iscsi_switch_str_param(char **param, char *new_val_buf)
3196 {
3197 char *new_val;
3198
3199 if (*param) {
3200 if (!strcmp(*param, new_val_buf))
3201 return 0;
3202 }
3203
3204 new_val = kstrdup(new_val_buf, GFP_NOIO);
3205 if (!new_val)
3206 return -ENOMEM;
3207
3208 kfree(*param);
3209 *param = new_val;
3210 return 0;
3211 }
3212 EXPORT_SYMBOL_GPL(iscsi_switch_str_param);
3213
3214 int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
3215 enum iscsi_param param, char *buf, int buflen)
3216 {
3217 struct iscsi_conn *conn = cls_conn->dd_data;
3218 struct iscsi_session *session = conn->session;
3219 int val;
3220
3221 switch(param) {
3222 case ISCSI_PARAM_FAST_ABORT:
3223 sscanf(buf, "%d", &session->fast_abort);
3224 break;
3225 case ISCSI_PARAM_ABORT_TMO:
3226 sscanf(buf, "%d", &session->abort_timeout);
3227 break;
3228 case ISCSI_PARAM_LU_RESET_TMO:
3229 sscanf(buf, "%d", &session->lu_reset_timeout);
3230 break;
3231 case ISCSI_PARAM_TGT_RESET_TMO:
3232 sscanf(buf, "%d", &session->tgt_reset_timeout);
3233 break;
3234 case ISCSI_PARAM_PING_TMO:
3235 sscanf(buf, "%d", &conn->ping_timeout);
3236 break;
3237 case ISCSI_PARAM_RECV_TMO:
3238 sscanf(buf, "%d", &conn->recv_timeout);
3239 break;
3240 case ISCSI_PARAM_MAX_RECV_DLENGTH:
3241 sscanf(buf, "%d", &conn->max_recv_dlength);
3242 break;
3243 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
3244 sscanf(buf, "%d", &conn->max_xmit_dlength);
3245 break;
3246 case ISCSI_PARAM_HDRDGST_EN:
3247 sscanf(buf, "%d", &conn->hdrdgst_en);
3248 break;
3249 case ISCSI_PARAM_DATADGST_EN:
3250 sscanf(buf, "%d", &conn->datadgst_en);
3251 break;
3252 case ISCSI_PARAM_INITIAL_R2T_EN:
3253 sscanf(buf, "%d", &session->initial_r2t_en);
3254 break;
3255 case ISCSI_PARAM_MAX_R2T:
3256 sscanf(buf, "%hu", &session->max_r2t);
3257 break;
3258 case ISCSI_PARAM_IMM_DATA_EN:
3259 sscanf(buf, "%d", &session->imm_data_en);
3260 break;
3261 case ISCSI_PARAM_FIRST_BURST:
3262 sscanf(buf, "%d", &session->first_burst);
3263 break;
3264 case ISCSI_PARAM_MAX_BURST:
3265 sscanf(buf, "%d", &session->max_burst);
3266 break;
3267 case ISCSI_PARAM_PDU_INORDER_EN:
3268 sscanf(buf, "%d", &session->pdu_inorder_en);
3269 break;
3270 case ISCSI_PARAM_DATASEQ_INORDER_EN:
3271 sscanf(buf, "%d", &session->dataseq_inorder_en);
3272 break;
3273 case ISCSI_PARAM_ERL:
3274 sscanf(buf, "%d", &session->erl);
3275 break;
3276 case ISCSI_PARAM_EXP_STATSN:
3277 sscanf(buf, "%u", &conn->exp_statsn);
3278 break;
3279 case ISCSI_PARAM_USERNAME:
3280 return iscsi_switch_str_param(&session->username, buf);
3281 case ISCSI_PARAM_USERNAME_IN:
3282 return iscsi_switch_str_param(&session->username_in, buf);
3283 case ISCSI_PARAM_PASSWORD:
3284 return iscsi_switch_str_param(&session->password, buf);
3285 case ISCSI_PARAM_PASSWORD_IN:
3286 return iscsi_switch_str_param(&session->password_in, buf);
3287 case ISCSI_PARAM_TARGET_NAME:
3288 return iscsi_switch_str_param(&session->targetname, buf);
3289 case ISCSI_PARAM_TARGET_ALIAS:
3290 return iscsi_switch_str_param(&session->targetalias, buf);
3291 case ISCSI_PARAM_TPGT:
3292 sscanf(buf, "%d", &session->tpgt);
3293 break;
3294 case ISCSI_PARAM_PERSISTENT_PORT:
3295 sscanf(buf, "%d", &conn->persistent_port);
3296 break;
3297 case ISCSI_PARAM_PERSISTENT_ADDRESS:
3298 return iscsi_switch_str_param(&conn->persistent_address, buf);
3299 case ISCSI_PARAM_IFACE_NAME:
3300 return iscsi_switch_str_param(&session->ifacename, buf);
3301 case ISCSI_PARAM_INITIATOR_NAME:
3302 return iscsi_switch_str_param(&session->initiatorname, buf);
3303 case ISCSI_PARAM_BOOT_ROOT:
3304 return iscsi_switch_str_param(&session->boot_root, buf);
3305 case ISCSI_PARAM_BOOT_NIC:
3306 return iscsi_switch_str_param(&session->boot_nic, buf);
3307 case ISCSI_PARAM_BOOT_TARGET:
3308 return iscsi_switch_str_param(&session->boot_target, buf);
3309 case ISCSI_PARAM_PORTAL_TYPE:
3310 return iscsi_switch_str_param(&session->portal_type, buf);
3311 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
3312 return iscsi_switch_str_param(&session->discovery_parent_type,
3313 buf);
3314 case ISCSI_PARAM_DISCOVERY_SESS:
3315 sscanf(buf, "%d", &val);
3316 session->discovery_sess = !!val;
3317 break;
3318 case ISCSI_PARAM_LOCAL_IPADDR:
3319 return iscsi_switch_str_param(&conn->local_ipaddr, buf);
3320 default:
3321 return -ENOSYS;
3322 }
3323
3324 return 0;
3325 }
3326 EXPORT_SYMBOL_GPL(iscsi_set_param);
3327
3328 int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
3329 enum iscsi_param param, char *buf)
3330 {
3331 struct iscsi_session *session = cls_session->dd_data;
3332 int len;
3333
3334 switch(param) {
3335 case ISCSI_PARAM_FAST_ABORT:
3336 len = sysfs_emit(buf, "%d\n", session->fast_abort);
3337 break;
3338 case ISCSI_PARAM_ABORT_TMO:
3339 len = sysfs_emit(buf, "%d\n", session->abort_timeout);
3340 break;
3341 case ISCSI_PARAM_LU_RESET_TMO:
3342 len = sysfs_emit(buf, "%d\n", session->lu_reset_timeout);
3343 break;
3344 case ISCSI_PARAM_TGT_RESET_TMO:
3345 len = sysfs_emit(buf, "%d\n", session->tgt_reset_timeout);
3346 break;
3347 case ISCSI_PARAM_INITIAL_R2T_EN:
3348 len = sysfs_emit(buf, "%d\n", session->initial_r2t_en);
3349 break;
3350 case ISCSI_PARAM_MAX_R2T:
3351 len = sysfs_emit(buf, "%hu\n", session->max_r2t);
3352 break;
3353 case ISCSI_PARAM_IMM_DATA_EN:
3354 len = sysfs_emit(buf, "%d\n", session->imm_data_en);
3355 break;
3356 case ISCSI_PARAM_FIRST_BURST:
3357 len = sysfs_emit(buf, "%u\n", session->first_burst);
3358 break;
3359 case ISCSI_PARAM_MAX_BURST:
3360 len = sysfs_emit(buf, "%u\n", session->max_burst);
3361 break;
3362 case ISCSI_PARAM_PDU_INORDER_EN:
3363 len = sysfs_emit(buf, "%d\n", session->pdu_inorder_en);
3364 break;
3365 case ISCSI_PARAM_DATASEQ_INORDER_EN:
3366 len = sysfs_emit(buf, "%d\n", session->dataseq_inorder_en);
3367 break;
3368 case ISCSI_PARAM_DEF_TASKMGMT_TMO:
3369 len = sysfs_emit(buf, "%d\n", session->def_taskmgmt_tmo);
3370 break;
3371 case ISCSI_PARAM_ERL:
3372 len = sysfs_emit(buf, "%d\n", session->erl);
3373 break;
3374 case ISCSI_PARAM_TARGET_NAME:
3375 len = sysfs_emit(buf, "%s\n", session->targetname);
3376 break;
3377 case ISCSI_PARAM_TARGET_ALIAS:
3378 len = sysfs_emit(buf, "%s\n", session->targetalias);
3379 break;
3380 case ISCSI_PARAM_TPGT:
3381 len = sysfs_emit(buf, "%d\n", session->tpgt);
3382 break;
3383 case ISCSI_PARAM_USERNAME:
3384 len = sysfs_emit(buf, "%s\n", session->username);
3385 break;
3386 case ISCSI_PARAM_USERNAME_IN:
3387 len = sysfs_emit(buf, "%s\n", session->username_in);
3388 break;
3389 case ISCSI_PARAM_PASSWORD:
3390 len = sysfs_emit(buf, "%s\n", session->password);
3391 break;
3392 case ISCSI_PARAM_PASSWORD_IN:
3393 len = sysfs_emit(buf, "%s\n", session->password_in);
3394 break;
3395 case ISCSI_PARAM_IFACE_NAME:
3396 len = sysfs_emit(buf, "%s\n", session->ifacename);
3397 break;
3398 case ISCSI_PARAM_INITIATOR_NAME:
3399 len = sysfs_emit(buf, "%s\n", session->initiatorname);
3400 break;
3401 case ISCSI_PARAM_BOOT_ROOT:
3402 len = sysfs_emit(buf, "%s\n", session->boot_root);
3403 break;
3404 case ISCSI_PARAM_BOOT_NIC:
3405 len = sysfs_emit(buf, "%s\n", session->boot_nic);
3406 break;
3407 case ISCSI_PARAM_BOOT_TARGET:
3408 len = sysfs_emit(buf, "%s\n", session->boot_target);
3409 break;
3410 case ISCSI_PARAM_AUTO_SND_TGT_DISABLE:
3411 len = sysfs_emit(buf, "%u\n", session->auto_snd_tgt_disable);
3412 break;
3413 case ISCSI_PARAM_DISCOVERY_SESS:
3414 len = sysfs_emit(buf, "%u\n", session->discovery_sess);
3415 break;
3416 case ISCSI_PARAM_PORTAL_TYPE:
3417 len = sysfs_emit(buf, "%s\n", session->portal_type);
3418 break;
3419 case ISCSI_PARAM_CHAP_AUTH_EN:
3420 len = sysfs_emit(buf, "%u\n", session->chap_auth_en);
3421 break;
3422 case ISCSI_PARAM_DISCOVERY_LOGOUT_EN:
3423 len = sysfs_emit(buf, "%u\n", session->discovery_logout_en);
3424 break;
3425 case ISCSI_PARAM_BIDI_CHAP_EN:
3426 len = sysfs_emit(buf, "%u\n", session->bidi_chap_en);
3427 break;
3428 case ISCSI_PARAM_DISCOVERY_AUTH_OPTIONAL:
3429 len = sysfs_emit(buf, "%u\n", session->discovery_auth_optional);
3430 break;
3431 case ISCSI_PARAM_DEF_TIME2WAIT:
3432 len = sysfs_emit(buf, "%d\n", session->time2wait);
3433 break;
3434 case ISCSI_PARAM_DEF_TIME2RETAIN:
3435 len = sysfs_emit(buf, "%d\n", session->time2retain);
3436 break;
3437 case ISCSI_PARAM_TSID:
3438 len = sysfs_emit(buf, "%u\n", session->tsid);
3439 break;
3440 case ISCSI_PARAM_ISID:
3441 len = sysfs_emit(buf, "%02x%02x%02x%02x%02x%02x\n",
3442 session->isid[0], session->isid[1],
3443 session->isid[2], session->isid[3],
3444 session->isid[4], session->isid[5]);
3445 break;
3446 case ISCSI_PARAM_DISCOVERY_PARENT_IDX:
3447 len = sysfs_emit(buf, "%u\n", session->discovery_parent_idx);
3448 break;
3449 case ISCSI_PARAM_DISCOVERY_PARENT_TYPE:
3450 if (session->discovery_parent_type)
3451 len = sysfs_emit(buf, "%s\n",
3452 session->discovery_parent_type);
3453 else
3454 len = sysfs_emit(buf, "\n");
3455 break;
3456 default:
3457 return -ENOSYS;
3458 }
3459
3460 return len;
3461 }
3462 EXPORT_SYMBOL_GPL(iscsi_session_get_param);
3463
3464 int iscsi_conn_get_addr_param(struct sockaddr_storage *addr,
3465 enum iscsi_param param, char *buf)
3466 {
3467 struct sockaddr_in6 *sin6 = NULL;
3468 struct sockaddr_in *sin = NULL;
3469 int len;
3470
3471 switch (addr->ss_family) {
3472 case AF_INET:
3473 sin = (struct sockaddr_in *)addr;
3474 break;
3475 case AF_INET6:
3476 sin6 = (struct sockaddr_in6 *)addr;
3477 break;
3478 default:
3479 return -EINVAL;
3480 }
3481
3482 switch (param) {
3483 case ISCSI_PARAM_CONN_ADDRESS:
3484 case ISCSI_HOST_PARAM_IPADDRESS:
3485 if (sin)
3486 len = sysfs_emit(buf, "%pI4\n", &sin->sin_addr.s_addr);
3487 else
3488 len = sysfs_emit(buf, "%pI6\n", &sin6->sin6_addr);
3489 break;
3490 case ISCSI_PARAM_CONN_PORT:
3491 case ISCSI_PARAM_LOCAL_PORT:
3492 if (sin)
3493 len = sysfs_emit(buf, "%hu\n", be16_to_cpu(sin->sin_port));
3494 else
3495 len = sysfs_emit(buf, "%hu\n",
3496 be16_to_cpu(sin6->sin6_port));
3497 break;
3498 default:
3499 return -EINVAL;
3500 }
3501
3502 return len;
3503 }
3504 EXPORT_SYMBOL_GPL(iscsi_conn_get_addr_param);
3505
3506 int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
3507 enum iscsi_param param, char *buf)
3508 {
3509 struct iscsi_conn *conn = cls_conn->dd_data;
3510 int len;
3511
3512 switch(param) {
3513 case ISCSI_PARAM_PING_TMO:
3514 len = sysfs_emit(buf, "%u\n", conn->ping_timeout);
3515 break;
3516 case ISCSI_PARAM_RECV_TMO:
3517 len = sysfs_emit(buf, "%u\n", conn->recv_timeout);
3518 break;
3519 case ISCSI_PARAM_MAX_RECV_DLENGTH:
3520 len = sysfs_emit(buf, "%u\n", conn->max_recv_dlength);
3521 break;
3522 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
3523 len = sysfs_emit(buf, "%u\n", conn->max_xmit_dlength);
3524 break;
3525 case ISCSI_PARAM_HDRDGST_EN:
3526 len = sysfs_emit(buf, "%d\n", conn->hdrdgst_en);
3527 break;
3528 case ISCSI_PARAM_DATADGST_EN:
3529 len = sysfs_emit(buf, "%d\n", conn->datadgst_en);
3530 break;
3531 case ISCSI_PARAM_IFMARKER_EN:
3532 len = sysfs_emit(buf, "%d\n", conn->ifmarker_en);
3533 break;
3534 case ISCSI_PARAM_OFMARKER_EN:
3535 len = sysfs_emit(buf, "%d\n", conn->ofmarker_en);
3536 break;
3537 case ISCSI_PARAM_EXP_STATSN:
3538 len = sysfs_emit(buf, "%u\n", conn->exp_statsn);
3539 break;
3540 case ISCSI_PARAM_PERSISTENT_PORT:
3541 len = sysfs_emit(buf, "%d\n", conn->persistent_port);
3542 break;
3543 case ISCSI_PARAM_PERSISTENT_ADDRESS:
3544 len = sysfs_emit(buf, "%s\n", conn->persistent_address);
3545 break;
3546 case ISCSI_PARAM_STATSN:
3547 len = sysfs_emit(buf, "%u\n", conn->statsn);
3548 break;
3549 case ISCSI_PARAM_MAX_SEGMENT_SIZE:
3550 len = sysfs_emit(buf, "%u\n", conn->max_segment_size);
3551 break;
3552 case ISCSI_PARAM_KEEPALIVE_TMO:
3553 len = sysfs_emit(buf, "%u\n", conn->keepalive_tmo);
3554 break;
3555 case ISCSI_PARAM_LOCAL_PORT:
3556 len = sysfs_emit(buf, "%u\n", conn->local_port);
3557 break;
3558 case ISCSI_PARAM_TCP_TIMESTAMP_STAT:
3559 len = sysfs_emit(buf, "%u\n", conn->tcp_timestamp_stat);
3560 break;
3561 case ISCSI_PARAM_TCP_NAGLE_DISABLE:
3562 len = sysfs_emit(buf, "%u\n", conn->tcp_nagle_disable);
3563 break;
3564 case ISCSI_PARAM_TCP_WSF_DISABLE:
3565 len = sysfs_emit(buf, "%u\n", conn->tcp_wsf_disable);
3566 break;
3567 case ISCSI_PARAM_TCP_TIMER_SCALE:
3568 len = sysfs_emit(buf, "%u\n", conn->tcp_timer_scale);
3569 break;
3570 case ISCSI_PARAM_TCP_TIMESTAMP_EN:
3571 len = sysfs_emit(buf, "%u\n", conn->tcp_timestamp_en);
3572 break;
3573 case ISCSI_PARAM_IP_FRAGMENT_DISABLE:
3574 len = sysfs_emit(buf, "%u\n", conn->fragment_disable);
3575 break;
3576 case ISCSI_PARAM_IPV4_TOS:
3577 len = sysfs_emit(buf, "%u\n", conn->ipv4_tos);
3578 break;
3579 case ISCSI_PARAM_IPV6_TC:
3580 len = sysfs_emit(buf, "%u\n", conn->ipv6_traffic_class);
3581 break;
3582 case ISCSI_PARAM_IPV6_FLOW_LABEL:
3583 len = sysfs_emit(buf, "%u\n", conn->ipv6_flow_label);
3584 break;
3585 case ISCSI_PARAM_IS_FW_ASSIGNED_IPV6:
3586 len = sysfs_emit(buf, "%u\n", conn->is_fw_assigned_ipv6);
3587 break;
3588 case ISCSI_PARAM_TCP_XMIT_WSF:
3589 len = sysfs_emit(buf, "%u\n", conn->tcp_xmit_wsf);
3590 break;
3591 case ISCSI_PARAM_TCP_RECV_WSF:
3592 len = sysfs_emit(buf, "%u\n", conn->tcp_recv_wsf);
3593 break;
3594 case ISCSI_PARAM_LOCAL_IPADDR:
3595 len = sysfs_emit(buf, "%s\n", conn->local_ipaddr);
3596 break;
3597 default:
3598 return -ENOSYS;
3599 }
3600
3601 return len;
3602 }
3603 EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
3604
3605 int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
3606 char *buf)
3607 {
3608 struct iscsi_host *ihost = shost_priv(shost);
3609 int len;
3610
3611 switch (param) {
3612 case ISCSI_HOST_PARAM_NETDEV_NAME:
3613 len = sysfs_emit(buf, "%s\n", ihost->netdev);
3614 break;
3615 case ISCSI_HOST_PARAM_HWADDRESS:
3616 len = sysfs_emit(buf, "%s\n", ihost->hwaddress);
3617 break;
3618 case ISCSI_HOST_PARAM_INITIATOR_NAME:
3619 len = sysfs_emit(buf, "%s\n", ihost->initiatorname);
3620 break;
3621 default:
3622 return -ENOSYS;
3623 }
3624
3625 return len;
3626 }
3627 EXPORT_SYMBOL_GPL(iscsi_host_get_param);
3628
3629 int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param,
3630 char *buf, int buflen)
3631 {
3632 struct iscsi_host *ihost = shost_priv(shost);
3633
3634 switch (param) {
3635 case ISCSI_HOST_PARAM_NETDEV_NAME:
3636 return iscsi_switch_str_param(&ihost->netdev, buf);
3637 case ISCSI_HOST_PARAM_HWADDRESS:
3638 return iscsi_switch_str_param(&ihost->hwaddress, buf);
3639 case ISCSI_HOST_PARAM_INITIATOR_NAME:
3640 return iscsi_switch_str_param(&ihost->initiatorname, buf);
3641 default:
3642 return -ENOSYS;
3643 }
3644
3645 return 0;
3646 }
3647 EXPORT_SYMBOL_GPL(iscsi_host_set_param);
3648
3649 MODULE_AUTHOR("Mike Christie");
3650 MODULE_DESCRIPTION("iSCSI library functions");
3651 MODULE_LICENSE("GPL");