aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libiscsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libiscsi.c')
-rw-r--r--drivers/scsi/libiscsi.c236
1 files changed, 148 insertions, 88 deletions
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 809d32d95c76..dfaa8adf099e 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -38,6 +38,28 @@
38#include <scsi/scsi_transport_iscsi.h> 38#include <scsi/scsi_transport_iscsi.h>
39#include <scsi/libiscsi.h> 39#include <scsi/libiscsi.h>
40 40
41static int iscsi_dbg_lib;
42module_param_named(debug_libiscsi, iscsi_dbg_lib, int, S_IRUGO | S_IWUSR);
43MODULE_PARM_DESC(debug_libiscsi, "Turn on debugging for libiscsi module. "
44 "Set to 1 to turn on, and zero to turn off. Default "
45 "is off.");
46
47#define ISCSI_DBG_CONN(_conn, dbg_fmt, arg...) \
48 do { \
49 if (iscsi_dbg_lib) \
50 iscsi_conn_printk(KERN_INFO, _conn, \
51 "%s " dbg_fmt, \
52 __func__, ##arg); \
53 } while (0);
54
55#define ISCSI_DBG_SESSION(_session, dbg_fmt, arg...) \
56 do { \
57 if (iscsi_dbg_lib) \
58 iscsi_session_printk(KERN_INFO, _session, \
59 "%s " dbg_fmt, \
60 __func__, ##arg); \
61 } while (0);
62
41/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */ 63/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
42#define SNA32_CHECK 2147483648UL 64#define SNA32_CHECK 2147483648UL
43 65
@@ -54,6 +76,15 @@ static int iscsi_sna_lte(u32 n1, u32 n2)
54 (n1 > n2 && (n2 - n1 < SNA32_CHECK))); 76 (n1 > n2 && (n2 - n1 < SNA32_CHECK)));
55} 77}
56 78
79inline void iscsi_conn_queue_work(struct iscsi_conn *conn)
80{
81 struct Scsi_Host *shost = conn->session->host;
82 struct iscsi_host *ihost = shost_priv(shost);
83
84 queue_work(ihost->workq, &conn->xmitwork);
85}
86EXPORT_SYMBOL_GPL(iscsi_conn_queue_work);
87
57void 88void
58iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr) 89iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr)
59{ 90{
@@ -81,8 +112,7 @@ iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr)
81 if (!list_empty(&session->leadconn->xmitqueue) || 112 if (!list_empty(&session->leadconn->xmitqueue) ||
82 !list_empty(&session->leadconn->mgmtqueue)) { 113 !list_empty(&session->leadconn->mgmtqueue)) {
83 if (!(session->tt->caps & CAP_DATA_PATH_OFFLOAD)) 114 if (!(session->tt->caps & CAP_DATA_PATH_OFFLOAD))
84 scsi_queue_work(session->host, 115 iscsi_conn_queue_work(session->leadconn);
85 &session->leadconn->xmitwork);
86 } 116 }
87 } 117 }
88} 118}
@@ -176,10 +206,11 @@ static int iscsi_prep_ecdb_ahs(struct iscsi_task *task)
176 ecdb_ahdr->reserved = 0; 206 ecdb_ahdr->reserved = 0;
177 memcpy(ecdb_ahdr->ecdb, cmd->cmnd + ISCSI_CDB_SIZE, rlen); 207 memcpy(ecdb_ahdr->ecdb, cmd->cmnd + ISCSI_CDB_SIZE, rlen);
178 208
179 debug_scsi("iscsi_prep_ecdb_ahs: varlen_cdb_len %d " 209 ISCSI_DBG_SESSION(task->conn->session,
180 "rlen %d pad_len %d ahs_length %d iscsi_headers_size %u\n", 210 "iscsi_prep_ecdb_ahs: varlen_cdb_len %d "
181 cmd->cmd_len, rlen, pad_len, ahslength, task->hdr_len); 211 "rlen %d pad_len %d ahs_length %d iscsi_headers_size "
182 212 "%u\n", cmd->cmd_len, rlen, pad_len, ahslength,
213 task->hdr_len);
183 return 0; 214 return 0;
184} 215}
185 216
@@ -201,10 +232,11 @@ static int iscsi_prep_bidi_ahs(struct iscsi_task *task)
201 rlen_ahdr->reserved = 0; 232 rlen_ahdr->reserved = 0;
202 rlen_ahdr->read_length = cpu_to_be32(scsi_in(sc)->length); 233 rlen_ahdr->read_length = cpu_to_be32(scsi_in(sc)->length);
203 234
204 debug_scsi("bidi-in rlen_ahdr->read_length(%d) " 235 ISCSI_DBG_SESSION(task->conn->session,
205 "rlen_ahdr->ahslength(%d)\n", 236 "bidi-in rlen_ahdr->read_length(%d) "
206 be32_to_cpu(rlen_ahdr->read_length), 237 "rlen_ahdr->ahslength(%d)\n",
207 be16_to_cpu(rlen_ahdr->ahslength)); 238 be32_to_cpu(rlen_ahdr->read_length),
239 be16_to_cpu(rlen_ahdr->ahslength));
208 return 0; 240 return 0;
209} 241}
210 242
@@ -335,13 +367,15 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
335 list_move_tail(&task->running, &conn->run_list); 367 list_move_tail(&task->running, &conn->run_list);
336 368
337 conn->scsicmd_pdus_cnt++; 369 conn->scsicmd_pdus_cnt++;
338 debug_scsi("iscsi prep [%s cid %d sc %p cdb 0x%x itt 0x%x len %d " 370 ISCSI_DBG_SESSION(session, "iscsi prep [%s cid %d sc %p cdb 0x%x "
339 "bidi_len %d cmdsn %d win %d]\n", scsi_bidi_cmnd(sc) ? 371 "itt 0x%x len %d bidi_len %d cmdsn %d win %d]\n",
340 "bidirectional" : sc->sc_data_direction == DMA_TO_DEVICE ? 372 scsi_bidi_cmnd(sc) ? "bidirectional" :
341 "write" : "read", conn->id, sc, sc->cmnd[0], task->itt, 373 sc->sc_data_direction == DMA_TO_DEVICE ?
342 scsi_bufflen(sc), 374 "write" : "read", conn->id, sc, sc->cmnd[0],
343 scsi_bidi_cmnd(sc) ? scsi_in(sc)->length : 0, 375 task->itt, scsi_bufflen(sc),
344 session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1); 376 scsi_bidi_cmnd(sc) ? scsi_in(sc)->length : 0,
377 session->cmdsn,
378 session->max_cmdsn - session->exp_cmdsn + 1);
345 return 0; 379 return 0;
346} 380}
347 381
@@ -483,9 +517,9 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn,
483 517
484 task->state = ISCSI_TASK_RUNNING; 518 task->state = ISCSI_TASK_RUNNING;
485 list_move_tail(&task->running, &conn->mgmt_run_list); 519 list_move_tail(&task->running, &conn->mgmt_run_list);
486 debug_scsi("mgmtpdu [op 0x%x hdr->itt 0x%x datalen %d]\n", 520 ISCSI_DBG_SESSION(session, "mgmtpdu [op 0x%x hdr->itt 0x%x "
487 hdr->opcode & ISCSI_OPCODE_MASK, hdr->itt, 521 "datalen %d]\n", hdr->opcode & ISCSI_OPCODE_MASK,
488 task->data_count); 522 hdr->itt, task->data_count);
489 return 0; 523 return 0;
490} 524}
491 525
@@ -560,7 +594,7 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
560 goto free_task; 594 goto free_task;
561 595
562 } else 596 } else
563 scsi_queue_work(conn->session->host, &conn->xmitwork); 597 iscsi_conn_queue_work(conn);
564 598
565 return task; 599 return task;
566 600
@@ -637,8 +671,9 @@ invalid_datalen:
637 671
638 memcpy(sc->sense_buffer, data + 2, 672 memcpy(sc->sense_buffer, data + 2,
639 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE)); 673 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
640 debug_scsi("copied %d bytes of sense\n", 674 ISCSI_DBG_SESSION(session, "copied %d bytes of sense\n",
641 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE)); 675 min_t(uint16_t, senselen,
676 SCSI_SENSE_BUFFERSIZE));
642 } 677 }
643 678
644 if (rhdr->flags & (ISCSI_FLAG_CMD_BIDI_UNDERFLOW | 679 if (rhdr->flags & (ISCSI_FLAG_CMD_BIDI_UNDERFLOW |
@@ -666,8 +701,8 @@ invalid_datalen:
666 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status; 701 sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
667 } 702 }
668out: 703out:
669 debug_scsi("done [sc %lx res %d itt 0x%x]\n", 704 ISCSI_DBG_SESSION(session, "done [sc %p res %d itt 0x%x]\n",
670 (long)sc, sc->result, task->itt); 705 sc, sc->result, task->itt);
671 conn->scsirsp_pdus_cnt++; 706 conn->scsirsp_pdus_cnt++;
672 707
673 __iscsi_put_task(task); 708 __iscsi_put_task(task);
@@ -835,8 +870,8 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
835 else 870 else
836 itt = ~0U; 871 itt = ~0U;
837 872
838 debug_scsi("[op 0x%x cid %d itt 0x%x len %d]\n", 873 ISCSI_DBG_SESSION(session, "[op 0x%x cid %d itt 0x%x len %d]\n",
839 opcode, conn->id, itt, datalen); 874 opcode, conn->id, itt, datalen);
840 875
841 if (itt == ~0U) { 876 if (itt == ~0U) {
842 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr); 877 iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
@@ -1034,10 +1069,9 @@ struct iscsi_task *iscsi_itt_to_ctask(struct iscsi_conn *conn, itt_t itt)
1034} 1069}
1035EXPORT_SYMBOL_GPL(iscsi_itt_to_ctask); 1070EXPORT_SYMBOL_GPL(iscsi_itt_to_ctask);
1036 1071
1037void iscsi_session_failure(struct iscsi_cls_session *cls_session, 1072void iscsi_session_failure(struct iscsi_session *session,
1038 enum iscsi_err err) 1073 enum iscsi_err err)
1039{ 1074{
1040 struct iscsi_session *session = cls_session->dd_data;
1041 struct iscsi_conn *conn; 1075 struct iscsi_conn *conn;
1042 struct device *dev; 1076 struct device *dev;
1043 unsigned long flags; 1077 unsigned long flags;
@@ -1095,10 +1129,10 @@ static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn)
1095 * Check for iSCSI window and take care of CmdSN wrap-around 1129 * Check for iSCSI window and take care of CmdSN wrap-around
1096 */ 1130 */
1097 if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) { 1131 if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) {
1098 debug_scsi("iSCSI CmdSN closed. ExpCmdSn %u MaxCmdSN %u " 1132 ISCSI_DBG_SESSION(session, "iSCSI CmdSN closed. ExpCmdSn "
1099 "CmdSN %u/%u\n", session->exp_cmdsn, 1133 "%u MaxCmdSN %u CmdSN %u/%u\n",
1100 session->max_cmdsn, session->cmdsn, 1134 session->exp_cmdsn, session->max_cmdsn,
1101 session->queued_cmdsn); 1135 session->cmdsn, session->queued_cmdsn);
1102 return -ENOSPC; 1136 return -ENOSPC;
1103 } 1137 }
1104 return 0; 1138 return 0;
@@ -1133,7 +1167,7 @@ void iscsi_requeue_task(struct iscsi_task *task)
1133 struct iscsi_conn *conn = task->conn; 1167 struct iscsi_conn *conn = task->conn;
1134 1168
1135 list_move_tail(&task->running, &conn->requeue); 1169 list_move_tail(&task->running, &conn->requeue);
1136 scsi_queue_work(conn->session->host, &conn->xmitwork); 1170 iscsi_conn_queue_work(conn);
1137} 1171}
1138EXPORT_SYMBOL_GPL(iscsi_requeue_task); 1172EXPORT_SYMBOL_GPL(iscsi_requeue_task);
1139 1173
@@ -1152,7 +1186,7 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)
1152 1186
1153 spin_lock_bh(&conn->session->lock); 1187 spin_lock_bh(&conn->session->lock);
1154 if (unlikely(conn->suspend_tx)) { 1188 if (unlikely(conn->suspend_tx)) {
1155 debug_scsi("conn %d Tx suspended!\n", conn->id); 1189 ISCSI_DBG_SESSION(conn->session, "Tx suspended!\n");
1156 spin_unlock_bh(&conn->session->lock); 1190 spin_unlock_bh(&conn->session->lock);
1157 return -ENODATA; 1191 return -ENODATA;
1158 } 1192 }
@@ -1386,7 +1420,7 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1386 goto prepd_reject; 1420 goto prepd_reject;
1387 } 1421 }
1388 } else 1422 } else
1389 scsi_queue_work(session->host, &conn->xmitwork); 1423 iscsi_conn_queue_work(conn);
1390 1424
1391 session->queued_cmdsn++; 1425 session->queued_cmdsn++;
1392 spin_unlock(&session->lock); 1426 spin_unlock(&session->lock);
@@ -1398,7 +1432,8 @@ prepd_reject:
1398 iscsi_complete_command(task); 1432 iscsi_complete_command(task);
1399reject: 1433reject:
1400 spin_unlock(&session->lock); 1434 spin_unlock(&session->lock);
1401 debug_scsi("cmd 0x%x rejected (%d)\n", sc->cmnd[0], reason); 1435 ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n",
1436 sc->cmnd[0], reason);
1402 spin_lock(host->host_lock); 1437 spin_lock(host->host_lock);
1403 return SCSI_MLQUEUE_TARGET_BUSY; 1438 return SCSI_MLQUEUE_TARGET_BUSY;
1404 1439
@@ -1407,7 +1442,8 @@ prepd_fault:
1407 iscsi_complete_command(task); 1442 iscsi_complete_command(task);
1408fault: 1443fault:
1409 spin_unlock(&session->lock); 1444 spin_unlock(&session->lock);
1410 debug_scsi("iscsi: cmd 0x%x is not queued (%d)\n", sc->cmnd[0], reason); 1445 ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n",
1446 sc->cmnd[0], reason);
1411 if (!scsi_bidi_cmnd(sc)) 1447 if (!scsi_bidi_cmnd(sc))
1412 scsi_set_resid(sc, scsi_bufflen(sc)); 1448 scsi_set_resid(sc, scsi_bufflen(sc));
1413 else { 1449 else {
@@ -1422,8 +1458,6 @@ EXPORT_SYMBOL_GPL(iscsi_queuecommand);
1422 1458
1423int iscsi_change_queue_depth(struct scsi_device *sdev, int depth) 1459int iscsi_change_queue_depth(struct scsi_device *sdev, int depth)
1424{ 1460{
1425 if (depth > ISCSI_MAX_CMD_PER_LUN)
1426 depth = ISCSI_MAX_CMD_PER_LUN;
1427 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth); 1461 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
1428 return sdev->queue_depth; 1462 return sdev->queue_depth;
1429} 1463}
@@ -1457,8 +1491,10 @@ int iscsi_eh_target_reset(struct scsi_cmnd *sc)
1457 spin_lock_bh(&session->lock); 1491 spin_lock_bh(&session->lock);
1458 if (session->state == ISCSI_STATE_TERMINATE) { 1492 if (session->state == ISCSI_STATE_TERMINATE) {
1459failed: 1493failed:
1460 debug_scsi("failing target reset: session terminated " 1494 iscsi_session_printk(KERN_INFO, session,
1461 "[CID %d age %d]\n", conn->id, session->age); 1495 "failing target reset: Could not log "
1496 "back into target [age %d]\n",
1497 session->age);
1462 spin_unlock_bh(&session->lock); 1498 spin_unlock_bh(&session->lock);
1463 mutex_unlock(&session->eh_mutex); 1499 mutex_unlock(&session->eh_mutex);
1464 return FAILED; 1500 return FAILED;
@@ -1472,7 +1508,7 @@ failed:
1472 */ 1508 */
1473 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 1509 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1474 1510
1475 debug_scsi("iscsi_eh_target_reset wait for relogin\n"); 1511 ISCSI_DBG_SESSION(session, "wait for relogin\n");
1476 wait_event_interruptible(conn->ehwait, 1512 wait_event_interruptible(conn->ehwait,
1477 session->state == ISCSI_STATE_TERMINATE || 1513 session->state == ISCSI_STATE_TERMINATE ||
1478 session->state == ISCSI_STATE_LOGGED_IN || 1514 session->state == ISCSI_STATE_LOGGED_IN ||
@@ -1501,7 +1537,7 @@ static void iscsi_tmf_timedout(unsigned long data)
1501 spin_lock(&session->lock); 1537 spin_lock(&session->lock);
1502 if (conn->tmf_state == TMF_QUEUED) { 1538 if (conn->tmf_state == TMF_QUEUED) {
1503 conn->tmf_state = TMF_TIMEDOUT; 1539 conn->tmf_state = TMF_TIMEDOUT;
1504 debug_scsi("tmf timedout\n"); 1540 ISCSI_DBG_SESSION(session, "tmf timedout\n");
1505 /* unblock eh_abort() */ 1541 /* unblock eh_abort() */
1506 wake_up(&conn->ehwait); 1542 wake_up(&conn->ehwait);
1507 } 1543 }
@@ -1521,7 +1557,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
1521 spin_unlock_bh(&session->lock); 1557 spin_unlock_bh(&session->lock);
1522 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 1558 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1523 spin_lock_bh(&session->lock); 1559 spin_lock_bh(&session->lock);
1524 debug_scsi("tmf exec failure\n"); 1560 ISCSI_DBG_SESSION(session, "tmf exec failure\n");
1525 return -EPERM; 1561 return -EPERM;
1526 } 1562 }
1527 conn->tmfcmd_pdus_cnt++; 1563 conn->tmfcmd_pdus_cnt++;
@@ -1529,7 +1565,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
1529 conn->tmf_timer.function = iscsi_tmf_timedout; 1565 conn->tmf_timer.function = iscsi_tmf_timedout;
1530 conn->tmf_timer.data = (unsigned long)conn; 1566 conn->tmf_timer.data = (unsigned long)conn;
1531 add_timer(&conn->tmf_timer); 1567 add_timer(&conn->tmf_timer);
1532 debug_scsi("tmf set timeout\n"); 1568 ISCSI_DBG_SESSION(session, "tmf set timeout\n");
1533 1569
1534 spin_unlock_bh(&session->lock); 1570 spin_unlock_bh(&session->lock);
1535 mutex_unlock(&session->eh_mutex); 1571 mutex_unlock(&session->eh_mutex);
@@ -1567,22 +1603,27 @@ static void fail_all_commands(struct iscsi_conn *conn, unsigned lun,
1567{ 1603{
1568 struct iscsi_task *task, *tmp; 1604 struct iscsi_task *task, *tmp;
1569 1605
1570 if (conn->task && (conn->task->sc->device->lun == lun || lun == -1)) 1606 if (conn->task) {
1571 conn->task = NULL; 1607 if (lun == -1 ||
1608 (conn->task->sc && conn->task->sc->device->lun == lun))
1609 conn->task = NULL;
1610 }
1572 1611
1573 /* flush pending */ 1612 /* flush pending */
1574 list_for_each_entry_safe(task, tmp, &conn->xmitqueue, running) { 1613 list_for_each_entry_safe(task, tmp, &conn->xmitqueue, running) {
1575 if (lun == task->sc->device->lun || lun == -1) { 1614 if (lun == task->sc->device->lun || lun == -1) {
1576 debug_scsi("failing pending sc %p itt 0x%x\n", 1615 ISCSI_DBG_SESSION(conn->session,
1577 task->sc, task->itt); 1616 "failing pending sc %p itt 0x%x\n",
1617 task->sc, task->itt);
1578 fail_command(conn, task, error << 16); 1618 fail_command(conn, task, error << 16);
1579 } 1619 }
1580 } 1620 }
1581 1621
1582 list_for_each_entry_safe(task, tmp, &conn->requeue, running) { 1622 list_for_each_entry_safe(task, tmp, &conn->requeue, running) {
1583 if (lun == task->sc->device->lun || lun == -1) { 1623 if (lun == task->sc->device->lun || lun == -1) {
1584 debug_scsi("failing requeued sc %p itt 0x%x\n", 1624 ISCSI_DBG_SESSION(conn->session,
1585 task->sc, task->itt); 1625 "failing requeued sc %p itt 0x%x\n",
1626 task->sc, task->itt);
1586 fail_command(conn, task, error << 16); 1627 fail_command(conn, task, error << 16);
1587 } 1628 }
1588 } 1629 }
@@ -1590,8 +1631,9 @@ static void fail_all_commands(struct iscsi_conn *conn, unsigned lun,
1590 /* fail all other running */ 1631 /* fail all other running */
1591 list_for_each_entry_safe(task, tmp, &conn->run_list, running) { 1632 list_for_each_entry_safe(task, tmp, &conn->run_list, running) {
1592 if (lun == task->sc->device->lun || lun == -1) { 1633 if (lun == task->sc->device->lun || lun == -1) {
1593 debug_scsi("failing in progress sc %p itt 0x%x\n", 1634 ISCSI_DBG_SESSION(conn->session,
1594 task->sc, task->itt); 1635 "failing in progress sc %p itt 0x%x\n",
1636 task->sc, task->itt);
1595 fail_command(conn, task, error << 16); 1637 fail_command(conn, task, error << 16);
1596 } 1638 }
1597 } 1639 }
@@ -1599,9 +1641,12 @@ static void fail_all_commands(struct iscsi_conn *conn, unsigned lun,
1599 1641
1600void iscsi_suspend_tx(struct iscsi_conn *conn) 1642void iscsi_suspend_tx(struct iscsi_conn *conn)
1601{ 1643{
1644 struct Scsi_Host *shost = conn->session->host;
1645 struct iscsi_host *ihost = shost_priv(shost);
1646
1602 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx); 1647 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1603 if (!(conn->session->tt->caps & CAP_DATA_PATH_OFFLOAD)) 1648 if (!(conn->session->tt->caps & CAP_DATA_PATH_OFFLOAD))
1604 scsi_flush_work(conn->session->host); 1649 flush_workqueue(ihost->workq);
1605} 1650}
1606EXPORT_SYMBOL_GPL(iscsi_suspend_tx); 1651EXPORT_SYMBOL_GPL(iscsi_suspend_tx);
1607 1652
@@ -1609,7 +1654,7 @@ static void iscsi_start_tx(struct iscsi_conn *conn)
1609{ 1654{
1610 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx); 1655 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1611 if (!(conn->session->tt->caps & CAP_DATA_PATH_OFFLOAD)) 1656 if (!(conn->session->tt->caps & CAP_DATA_PATH_OFFLOAD))
1612 scsi_queue_work(conn->session->host, &conn->xmitwork); 1657 iscsi_conn_queue_work(conn);
1613} 1658}
1614 1659
1615static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd) 1660static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
@@ -1622,7 +1667,7 @@ static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
1622 cls_session = starget_to_session(scsi_target(scmd->device)); 1667 cls_session = starget_to_session(scsi_target(scmd->device));
1623 session = cls_session->dd_data; 1668 session = cls_session->dd_data;
1624 1669
1625 debug_scsi("scsi cmd %p timedout\n", scmd); 1670 ISCSI_DBG_SESSION(session, "scsi cmd %p timedout\n", scmd);
1626 1671
1627 spin_lock(&session->lock); 1672 spin_lock(&session->lock);
1628 if (session->state != ISCSI_STATE_LOGGED_IN) { 1673 if (session->state != ISCSI_STATE_LOGGED_IN) {
@@ -1662,8 +1707,8 @@ static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
1662 rc = BLK_EH_RESET_TIMER; 1707 rc = BLK_EH_RESET_TIMER;
1663done: 1708done:
1664 spin_unlock(&session->lock); 1709 spin_unlock(&session->lock);
1665 debug_scsi("return %s\n", rc == BLK_EH_RESET_TIMER ? 1710 ISCSI_DBG_SESSION(session, "return %s\n", rc == BLK_EH_RESET_TIMER ?
1666 "timer reset" : "nh"); 1711 "timer reset" : "nh");
1667 return rc; 1712 return rc;
1668} 1713}
1669 1714
@@ -1697,13 +1742,13 @@ static void iscsi_check_transport_timeouts(unsigned long data)
1697 1742
1698 if (time_before_eq(last_recv + recv_timeout, jiffies)) { 1743 if (time_before_eq(last_recv + recv_timeout, jiffies)) {
1699 /* send a ping to try to provoke some traffic */ 1744 /* send a ping to try to provoke some traffic */
1700 debug_scsi("Sending nopout as ping on conn %p\n", conn); 1745 ISCSI_DBG_CONN(conn, "Sending nopout as ping\n");
1701 iscsi_send_nopout(conn, NULL); 1746 iscsi_send_nopout(conn, NULL);
1702 next_timeout = conn->last_ping + (conn->ping_timeout * HZ); 1747 next_timeout = conn->last_ping + (conn->ping_timeout * HZ);
1703 } else 1748 } else
1704 next_timeout = last_recv + recv_timeout; 1749 next_timeout = last_recv + recv_timeout;
1705 1750
1706 debug_scsi("Setting next tmo %lu\n", next_timeout); 1751 ISCSI_DBG_CONN(conn, "Setting next tmo %lu\n", next_timeout);
1707 mod_timer(&conn->transport_timer, next_timeout); 1752 mod_timer(&conn->transport_timer, next_timeout);
1708done: 1753done:
1709 spin_unlock(&session->lock); 1754 spin_unlock(&session->lock);
@@ -1740,7 +1785,8 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1740 * got the command. 1785 * got the command.
1741 */ 1786 */
1742 if (!sc->SCp.ptr) { 1787 if (!sc->SCp.ptr) {
1743 debug_scsi("sc never reached iscsi layer or it completed.\n"); 1788 ISCSI_DBG_SESSION(session, "sc never reached iscsi layer or "
1789 "it completed.\n");
1744 spin_unlock_bh(&session->lock); 1790 spin_unlock_bh(&session->lock);
1745 mutex_unlock(&session->eh_mutex); 1791 mutex_unlock(&session->eh_mutex);
1746 return SUCCESS; 1792 return SUCCESS;
@@ -1762,11 +1808,13 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1762 age = session->age; 1808 age = session->age;
1763 1809
1764 task = (struct iscsi_task *)sc->SCp.ptr; 1810 task = (struct iscsi_task *)sc->SCp.ptr;
1765 debug_scsi("aborting [sc %p itt 0x%x]\n", sc, task->itt); 1811 ISCSI_DBG_SESSION(session, "aborting [sc %p itt 0x%x]\n",
1812 sc, task->itt);
1766 1813
1767 /* task completed before time out */ 1814 /* task completed before time out */
1768 if (!task->sc) { 1815 if (!task->sc) {
1769 debug_scsi("sc completed while abort in progress\n"); 1816 ISCSI_DBG_SESSION(session, "sc completed while abort in "
1817 "progress\n");
1770 goto success; 1818 goto success;
1771 } 1819 }
1772 1820
@@ -1815,7 +1863,8 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1815 if (!sc->SCp.ptr) { 1863 if (!sc->SCp.ptr) {
1816 conn->tmf_state = TMF_INITIAL; 1864 conn->tmf_state = TMF_INITIAL;
1817 /* task completed before tmf abort response */ 1865 /* task completed before tmf abort response */
1818 debug_scsi("sc completed while abort in progress\n"); 1866 ISCSI_DBG_SESSION(session, "sc completed while abort "
1867 "in progress\n");
1819 goto success; 1868 goto success;
1820 } 1869 }
1821 /* fall through */ 1870 /* fall through */
@@ -1827,15 +1876,16 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1827success: 1876success:
1828 spin_unlock_bh(&session->lock); 1877 spin_unlock_bh(&session->lock);
1829success_unlocked: 1878success_unlocked:
1830 debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, task->itt); 1879 ISCSI_DBG_SESSION(session, "abort success [sc %p itt 0x%x]\n",
1880 sc, task->itt);
1831 mutex_unlock(&session->eh_mutex); 1881 mutex_unlock(&session->eh_mutex);
1832 return SUCCESS; 1882 return SUCCESS;
1833 1883
1834failed: 1884failed:
1835 spin_unlock_bh(&session->lock); 1885 spin_unlock_bh(&session->lock);
1836failed_unlocked: 1886failed_unlocked:
1837 debug_scsi("abort failed [sc %p itt 0x%x]\n", sc, 1887 ISCSI_DBG_SESSION(session, "abort failed [sc %p itt 0x%x]\n", sc,
1838 task ? task->itt : 0); 1888 task ? task->itt : 0);
1839 mutex_unlock(&session->eh_mutex); 1889 mutex_unlock(&session->eh_mutex);
1840 return FAILED; 1890 return FAILED;
1841} 1891}
@@ -1862,7 +1912,8 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
1862 cls_session = starget_to_session(scsi_target(sc->device)); 1912 cls_session = starget_to_session(scsi_target(sc->device));
1863 session = cls_session->dd_data; 1913 session = cls_session->dd_data;
1864 1914
1865 debug_scsi("LU Reset [sc %p lun %u]\n", sc, sc->device->lun); 1915 ISCSI_DBG_SESSION(session, "LU Reset [sc %p lun %u]\n",
1916 sc, sc->device->lun);
1866 1917
1867 mutex_lock(&session->eh_mutex); 1918 mutex_lock(&session->eh_mutex);
1868 spin_lock_bh(&session->lock); 1919 spin_lock_bh(&session->lock);
@@ -1916,8 +1967,8 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
1916unlock: 1967unlock:
1917 spin_unlock_bh(&session->lock); 1968 spin_unlock_bh(&session->lock);
1918done: 1969done:
1919 debug_scsi("iscsi_eh_device_reset %s\n", 1970 ISCSI_DBG_SESSION(session, "dev reset result = %s\n",
1920 rc == SUCCESS ? "SUCCESS" : "FAILED"); 1971 rc == SUCCESS ? "SUCCESS" : "FAILED");
1921 mutex_unlock(&session->eh_mutex); 1972 mutex_unlock(&session->eh_mutex);
1922 return rc; 1973 return rc;
1923} 1974}
@@ -1944,7 +1995,7 @@ iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size)
1944 num_arrays++; 1995 num_arrays++;
1945 q->pool = kzalloc(num_arrays * max * sizeof(void*), GFP_KERNEL); 1996 q->pool = kzalloc(num_arrays * max * sizeof(void*), GFP_KERNEL);
1946 if (q->pool == NULL) 1997 if (q->pool == NULL)
1947 goto enomem; 1998 return -ENOMEM;
1948 1999
1949 q->queue = kfifo_init((void*)q->pool, max * sizeof(void*), 2000 q->queue = kfifo_init((void*)q->pool, max * sizeof(void*),
1950 GFP_KERNEL, NULL); 2001 GFP_KERNEL, NULL);
@@ -1979,8 +2030,7 @@ void iscsi_pool_free(struct iscsi_pool *q)
1979 2030
1980 for (i = 0; i < q->max; i++) 2031 for (i = 0; i < q->max; i++)
1981 kfree(q->pool[i]); 2032 kfree(q->pool[i]);
1982 if (q->pool) 2033 kfree(q->pool);
1983 kfree(q->pool);
1984 kfree(q->queue); 2034 kfree(q->queue);
1985} 2035}
1986EXPORT_SYMBOL_GPL(iscsi_pool_free); 2036EXPORT_SYMBOL_GPL(iscsi_pool_free);
@@ -1998,6 +2048,9 @@ int iscsi_host_add(struct Scsi_Host *shost, struct device *pdev)
1998 if (!shost->can_queue) 2048 if (!shost->can_queue)
1999 shost->can_queue = ISCSI_DEF_XMIT_CMDS_MAX; 2049 shost->can_queue = ISCSI_DEF_XMIT_CMDS_MAX;
2000 2050
2051 if (!shost->cmd_per_lun)
2052 shost->cmd_per_lun = ISCSI_DEF_CMD_PER_LUN;
2053
2001 if (!shost->transportt->eh_timed_out) 2054 if (!shost->transportt->eh_timed_out)
2002 shost->transportt->eh_timed_out = iscsi_eh_cmd_timed_out; 2055 shost->transportt->eh_timed_out = iscsi_eh_cmd_timed_out;
2003 return scsi_add_host(shost, pdev); 2056 return scsi_add_host(shost, pdev);
@@ -2008,13 +2061,13 @@ EXPORT_SYMBOL_GPL(iscsi_host_add);
2008 * iscsi_host_alloc - allocate a host and driver data 2061 * iscsi_host_alloc - allocate a host and driver data
2009 * @sht: scsi host template 2062 * @sht: scsi host template
2010 * @dd_data_size: driver host data size 2063 * @dd_data_size: driver host data size
2011 * @qdepth: default device queue depth 2064 * @xmit_can_sleep: bool indicating if LLD will queue IO from a work queue
2012 * 2065 *
2013 * This should be called by partial offload and software iscsi drivers. 2066 * This should be called by partial offload and software iscsi drivers.
2014 * To access the driver specific memory use the iscsi_host_priv() macro. 2067 * To access the driver specific memory use the iscsi_host_priv() macro.
2015 */ 2068 */
2016struct Scsi_Host *iscsi_host_alloc(struct scsi_host_template *sht, 2069struct Scsi_Host *iscsi_host_alloc(struct scsi_host_template *sht,
2017 int dd_data_size, uint16_t qdepth) 2070 int dd_data_size, bool xmit_can_sleep)
2018{ 2071{
2019 struct Scsi_Host *shost; 2072 struct Scsi_Host *shost;
2020 struct iscsi_host *ihost; 2073 struct iscsi_host *ihost;
@@ -2022,28 +2075,31 @@ struct Scsi_Host *iscsi_host_alloc(struct scsi_host_template *sht,
2022 shost = scsi_host_alloc(sht, sizeof(struct iscsi_host) + dd_data_size); 2075 shost = scsi_host_alloc(sht, sizeof(struct iscsi_host) + dd_data_size);
2023 if (!shost) 2076 if (!shost)
2024 return NULL; 2077 return NULL;
2078 ihost = shost_priv(shost);
2025 2079
2026 if (qdepth > ISCSI_MAX_CMD_PER_LUN || qdepth < 1) { 2080 if (xmit_can_sleep) {
2027 if (qdepth != 0) 2081 snprintf(ihost->workq_name, sizeof(ihost->workq_name),
2028 printk(KERN_ERR "iscsi: invalid queue depth of %d. " 2082 "iscsi_q_%d", shost->host_no);
2029 "Queue depth must be between 1 and %d.\n", 2083 ihost->workq = create_singlethread_workqueue(ihost->workq_name);
2030 qdepth, ISCSI_MAX_CMD_PER_LUN); 2084 if (!ihost->workq)
2031 qdepth = ISCSI_DEF_CMD_PER_LUN; 2085 goto free_host;
2032 } 2086 }
2033 shost->cmd_per_lun = qdepth;
2034 2087
2035 ihost = shost_priv(shost);
2036 spin_lock_init(&ihost->lock); 2088 spin_lock_init(&ihost->lock);
2037 ihost->state = ISCSI_HOST_SETUP; 2089 ihost->state = ISCSI_HOST_SETUP;
2038 ihost->num_sessions = 0; 2090 ihost->num_sessions = 0;
2039 init_waitqueue_head(&ihost->session_removal_wq); 2091 init_waitqueue_head(&ihost->session_removal_wq);
2040 return shost; 2092 return shost;
2093
2094free_host:
2095 scsi_host_put(shost);
2096 return NULL;
2041} 2097}
2042EXPORT_SYMBOL_GPL(iscsi_host_alloc); 2098EXPORT_SYMBOL_GPL(iscsi_host_alloc);
2043 2099
2044static void iscsi_notify_host_removed(struct iscsi_cls_session *cls_session) 2100static void iscsi_notify_host_removed(struct iscsi_cls_session *cls_session)
2045{ 2101{
2046 iscsi_session_failure(cls_session, ISCSI_ERR_INVALID_HOST); 2102 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_INVALID_HOST);
2047} 2103}
2048 2104
2049/** 2105/**
@@ -2069,6 +2125,8 @@ void iscsi_host_remove(struct Scsi_Host *shost)
2069 flush_signals(current); 2125 flush_signals(current);
2070 2126
2071 scsi_remove_host(shost); 2127 scsi_remove_host(shost);
2128 if (ihost->workq)
2129 destroy_workqueue(ihost->workq);
2072} 2130}
2073EXPORT_SYMBOL_GPL(iscsi_host_remove); 2131EXPORT_SYMBOL_GPL(iscsi_host_remove);
2074 2132
@@ -2467,14 +2525,16 @@ flush_control_queues(struct iscsi_session *session, struct iscsi_conn *conn)
2467 2525
2468 /* handle pending */ 2526 /* handle pending */
2469 list_for_each_entry_safe(task, tmp, &conn->mgmtqueue, running) { 2527 list_for_each_entry_safe(task, tmp, &conn->mgmtqueue, running) {
2470 debug_scsi("flushing pending mgmt task itt 0x%x\n", task->itt); 2528 ISCSI_DBG_SESSION(session, "flushing pending mgmt task "
2529 "itt 0x%x\n", task->itt);
2471 /* release ref from prep task */ 2530 /* release ref from prep task */
2472 __iscsi_put_task(task); 2531 __iscsi_put_task(task);
2473 } 2532 }
2474 2533
2475 /* handle running */ 2534 /* handle running */
2476 list_for_each_entry_safe(task, tmp, &conn->mgmt_run_list, running) { 2535 list_for_each_entry_safe(task, tmp, &conn->mgmt_run_list, running) {
2477 debug_scsi("flushing running mgmt task itt 0x%x\n", task->itt); 2536 ISCSI_DBG_SESSION(session, "flushing running mgmt task "
2537 "itt 0x%x\n", task->itt);
2478 /* release ref from prep task */ 2538 /* release ref from prep task */
2479 __iscsi_put_task(task); 2539 __iscsi_put_task(task);
2480 } 2540 }
@@ -2524,7 +2584,7 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
2524 conn->datadgst_en = 0; 2584 conn->datadgst_en = 0;
2525 if (session->state == ISCSI_STATE_IN_RECOVERY && 2585 if (session->state == ISCSI_STATE_IN_RECOVERY &&
2526 old_stop_stage != STOP_CONN_RECOVER) { 2586 old_stop_stage != STOP_CONN_RECOVER) {
2527 debug_scsi("blocking session\n"); 2587 ISCSI_DBG_SESSION(session, "blocking session\n");
2528 iscsi_block_session(session->cls_session); 2588 iscsi_block_session(session->cls_session);
2529 } 2589 }
2530 } 2590 }