aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.c74
-rw-r--r--drivers/scsi/iscsi_tcp.c102
-rw-r--r--drivers/scsi/libiscsi.c213
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c1
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c5
-rw-r--r--include/scsi/iscsi_if.h7
-rw-r--r--include/scsi/libiscsi.h31
-rw-r--r--include/scsi/scsi_transport_iscsi.h8
8 files changed, 225 insertions, 216 deletions
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index 32f5d5e79abf..5a750042e2b2 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -74,6 +74,10 @@
74 74
75#include "iscsi_iser.h" 75#include "iscsi_iser.h"
76 76
77static struct scsi_host_template iscsi_iser_sht;
78static struct iscsi_transport iscsi_iser_transport;
79static struct scsi_transport_template *iscsi_iser_scsi_transport;
80
77static unsigned int iscsi_max_lun = 512; 81static unsigned int iscsi_max_lun = 512;
78module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); 82module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
79 83
@@ -363,40 +367,64 @@ iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
363 return iscsi_conn_start(cls_conn); 367 return iscsi_conn_start(cls_conn);
364} 368}
365 369
366static struct iscsi_transport iscsi_iser_transport; 370static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session)
371{
372 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
373
374 iscsi_session_teardown(cls_session);
375 scsi_remove_host(shost);
376 iscsi_host_teardown(shost);
377 scsi_host_put(shost);
378}
367 379
368static struct iscsi_cls_session * 380static struct iscsi_cls_session *
369iscsi_iser_session_create(struct iscsi_transport *iscsit, 381iscsi_iser_session_create(struct Scsi_Host *shost,
370 struct scsi_transport_template *scsit, 382 uint16_t cmds_max, uint16_t qdepth,
371 struct Scsi_Host *shost, 383 uint32_t initial_cmdsn, uint32_t *hostno)
372 uint16_t cmds_max, uint16_t qdepth,
373 uint32_t initial_cmdsn, uint32_t *hostno)
374{ 384{
375 struct iscsi_cls_session *cls_session; 385 struct iscsi_cls_session *cls_session;
376 struct iscsi_session *session; 386 struct iscsi_session *session;
377 int i; 387 int i;
378 uint32_t hn;
379 struct iscsi_cmd_task *ctask; 388 struct iscsi_cmd_task *ctask;
380 struct iscsi_mgmt_task *mtask; 389 struct iscsi_mgmt_task *mtask;
381 struct iscsi_iser_cmd_task *iser_ctask; 390 struct iscsi_iser_cmd_task *iser_ctask;
382 struct iser_desc *desc; 391 struct iser_desc *desc;
383 392
393 if (shost) {
394 printk(KERN_ERR "iscsi_tcp: invalid shost %d.\n",
395 shost->host_no);
396 return NULL;
397 }
398
399 shost = scsi_host_alloc(&iscsi_iser_sht, 0);
400 if (!shost)
401 return NULL;
402 shost->transportt = iscsi_iser_scsi_transport;
403 shost->max_lun = iscsi_max_lun;
404 shost->max_id = 0;
405 shost->max_channel = 0;
406 shost->max_cmd_len = 16;
407
408 iscsi_host_setup(shost, qdepth);
409
410 if (scsi_add_host(shost, NULL))
411 goto free_host;
412 *hostno = shost->host_no;
413
384 /* 414 /*
385 * we do not support setting can_queue cmd_per_lun from userspace yet 415 * we do not support setting can_queue cmd_per_lun from userspace yet
386 * because we preallocate so many resources 416 * because we preallocate so many resources
387 */ 417 */
388 cls_session = iscsi_session_setup(iscsit, scsit, 418 cls_session = iscsi_session_setup(&iscsi_iser_transport, shost,
389 ISCSI_DEF_XMIT_CMDS_MAX, 419 ISCSI_DEF_XMIT_CMDS_MAX,
390 ISCSI_MAX_CMD_PER_LUN,
391 sizeof(struct iscsi_iser_cmd_task), 420 sizeof(struct iscsi_iser_cmd_task),
392 sizeof(struct iser_desc), 421 sizeof(struct iser_desc),
393 initial_cmdsn, &hn); 422 initial_cmdsn);
394 if (!cls_session) 423 if (!cls_session)
395 return NULL; 424 goto remove_host;
396 425 session = cls_session->dd_data;
397 *hostno = hn;
398 session = class_to_transport_session(cls_session);
399 426
427 shost->can_queue = session->cmds_max;
400 /* libiscsi setup itts, data and pool so just set desc fields */ 428 /* libiscsi setup itts, data and pool so just set desc fields */
401 for (i = 0; i < session->cmds_max; i++) { 429 for (i = 0; i < session->cmds_max; i++) {
402 ctask = session->cmds[i]; 430 ctask = session->cmds[i];
@@ -413,6 +441,13 @@ iscsi_iser_session_create(struct iscsi_transport *iscsit,
413 } 441 }
414 442
415 return cls_session; 443 return cls_session;
444
445remove_host:
446 scsi_remove_host(shost);
447free_host:
448 iscsi_host_teardown(shost);
449 scsi_host_put(shost);
450 return NULL;
416} 451}
417 452
418static int 453static int
@@ -589,12 +624,11 @@ static struct iscsi_transport iscsi_iser_transport = {
589 .host_param_mask = ISCSI_HOST_HWADDRESS | 624 .host_param_mask = ISCSI_HOST_HWADDRESS |
590 ISCSI_HOST_NETDEV_NAME | 625 ISCSI_HOST_NETDEV_NAME |
591 ISCSI_HOST_INITIATOR_NAME, 626 ISCSI_HOST_INITIATOR_NAME,
592 .host_template = &iscsi_iser_sht,
593 .conndata_size = sizeof(struct iscsi_conn), 627 .conndata_size = sizeof(struct iscsi_conn),
594 .max_lun = ISCSI_ISER_MAX_LUN, 628 .sessiondata_size = sizeof(struct iscsi_session),
595 /* session management */ 629 /* session management */
596 .create_session = iscsi_iser_session_create, 630 .create_session = iscsi_iser_session_create,
597 .destroy_session = iscsi_session_teardown, 631 .destroy_session = iscsi_iser_session_destroy,
598 /* connection management */ 632 /* connection management */
599 .create_conn = iscsi_iser_conn_create, 633 .create_conn = iscsi_iser_conn_create,
600 .bind_conn = iscsi_iser_conn_bind, 634 .bind_conn = iscsi_iser_conn_bind,
@@ -633,8 +667,6 @@ static int __init iser_init(void)
633 return -EINVAL; 667 return -EINVAL;
634 } 668 }
635 669
636 iscsi_iser_transport.max_lun = iscsi_max_lun;
637
638 memset(&ig, 0, sizeof(struct iser_global)); 670 memset(&ig, 0, sizeof(struct iser_global));
639 671
640 ig.desc_cache = kmem_cache_create("iser_descriptors", 672 ig.desc_cache = kmem_cache_create("iser_descriptors",
@@ -650,7 +682,9 @@ static int __init iser_init(void)
650 mutex_init(&ig.connlist_mutex); 682 mutex_init(&ig.connlist_mutex);
651 INIT_LIST_HEAD(&ig.connlist); 683 INIT_LIST_HEAD(&ig.connlist);
652 684
653 if (!iscsi_register_transport(&iscsi_iser_transport)) { 685 iscsi_iser_scsi_transport = iscsi_register_transport(
686 &iscsi_iser_transport);
687 if (!iscsi_iser_scsi_transport) {
654 iser_err("iscsi_register_transport failed\n"); 688 iser_err("iscsi_register_transport failed\n");
655 err = -EINVAL; 689 err = -EINVAL;
656 goto register_transport_failure; 690 goto register_transport_failure;
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index aecadbdce9df..8cdcaf33fb4e 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -64,6 +64,10 @@ MODULE_LICENSE("GPL");
64#define BUG_ON(expr) 64#define BUG_ON(expr)
65#endif 65#endif
66 66
67static struct scsi_transport_template *iscsi_tcp_scsi_transport;
68static struct scsi_host_template iscsi_sht;
69static struct iscsi_transport iscsi_tcp_transport;
70
67static unsigned int iscsi_max_lun = 512; 71static unsigned int iscsi_max_lun = 512;
68module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); 72module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
69 73
@@ -1623,6 +1627,8 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
1623 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, 1627 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
1624 int is_leading) 1628 int is_leading)
1625{ 1629{
1630 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1631 struct iscsi_host *ihost = shost_priv(shost);
1626 struct iscsi_conn *conn = cls_conn->dd_data; 1632 struct iscsi_conn *conn = cls_conn->dd_data;
1627 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 1633 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1628 struct sock *sk; 1634 struct sock *sk;
@@ -1646,8 +1652,8 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
1646 if (err) 1652 if (err)
1647 goto free_socket; 1653 goto free_socket;
1648 1654
1649 err = iscsi_tcp_get_addr(conn, sock, conn->local_address, 1655 err = iscsi_tcp_get_addr(conn, sock, ihost->local_address,
1650 &conn->local_port, kernel_getsockname); 1656 &ihost->local_port, kernel_getsockname);
1651 if (err) 1657 if (err)
1652 goto free_socket; 1658 goto free_socket;
1653 1659
@@ -1821,29 +1827,6 @@ iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
1821 return len; 1827 return len;
1822} 1828}
1823 1829
1824static int
1825iscsi_tcp_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
1826 char *buf)
1827{
1828 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1829 int len;
1830
1831 switch (param) {
1832 case ISCSI_HOST_PARAM_IPADDRESS:
1833 spin_lock_bh(&session->lock);
1834 if (!session->leadconn)
1835 len = -ENODEV;
1836 else
1837 len = sprintf(buf, "%s\n",
1838 session->leadconn->local_address);
1839 spin_unlock_bh(&session->lock);
1840 break;
1841 default:
1842 return iscsi_host_get_param(shost, param, buf);
1843 }
1844 return len;
1845}
1846
1847static void 1830static void
1848iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) 1831iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
1849{ 1832{
@@ -1869,26 +1852,44 @@ iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
1869} 1852}
1870 1853
1871static struct iscsi_cls_session * 1854static struct iscsi_cls_session *
1872iscsi_tcp_session_create(struct iscsi_transport *iscsit, 1855iscsi_tcp_session_create(struct Scsi_Host *shost, uint16_t cmds_max,
1873 struct scsi_transport_template *scsit,
1874 struct Scsi_Host *shost, uint16_t cmds_max,
1875 uint16_t qdepth, uint32_t initial_cmdsn, 1856 uint16_t qdepth, uint32_t initial_cmdsn,
1876 uint32_t *hostno) 1857 uint32_t *hostno)
1877{ 1858{
1878 struct iscsi_cls_session *cls_session; 1859 struct iscsi_cls_session *cls_session;
1879 struct iscsi_session *session; 1860 struct iscsi_session *session;
1880 uint32_t hn;
1881 int cmd_i; 1861 int cmd_i;
1882 1862
1883 cls_session = iscsi_session_setup(iscsit, scsit, cmds_max, qdepth, 1863 if (shost) {
1884 sizeof(struct iscsi_tcp_cmd_task), 1864 printk(KERN_ERR "iscsi_tcp: invalid shost %d.\n",
1885 sizeof(struct iscsi_tcp_mgmt_task), 1865 shost->host_no);
1886 initial_cmdsn, &hn); 1866 return NULL;
1887 if (!cls_session) 1867 }
1868
1869 shost = scsi_host_alloc(&iscsi_sht, sizeof(struct iscsi_host));
1870 if (!shost)
1888 return NULL; 1871 return NULL;
1889 *hostno = hn; 1872 shost->transportt = iscsi_tcp_scsi_transport;
1873 shost->max_lun = iscsi_max_lun;
1874 shost->max_id = 0;
1875 shost->max_channel = 0;
1876 shost->max_cmd_len = 16;
1877
1878 iscsi_host_setup(shost, qdepth);
1879
1880 if (scsi_add_host(shost, NULL))
1881 goto free_host;
1882 *hostno = shost->host_no;
1883
1884 cls_session = iscsi_session_setup(&iscsi_tcp_transport, shost, cmds_max,
1885 sizeof(struct iscsi_tcp_cmd_task),
1886 sizeof(struct iscsi_tcp_mgmt_task),
1887 initial_cmdsn);
1888 if (!cls_session)
1889 goto remove_host;
1890 session = cls_session->dd_data;
1890 1891
1891 session = class_to_transport_session(cls_session); 1892 shost->can_queue = session->cmds_max;
1892 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { 1893 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
1893 struct iscsi_cmd_task *ctask = session->cmds[cmd_i]; 1894 struct iscsi_cmd_task *ctask = session->cmds[cmd_i];
1894 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; 1895 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
@@ -1904,20 +1905,30 @@ iscsi_tcp_session_create(struct iscsi_transport *iscsit,
1904 mtask->hdr = (struct iscsi_hdr *) &tcp_mtask->hdr; 1905 mtask->hdr = (struct iscsi_hdr *) &tcp_mtask->hdr;
1905 } 1906 }
1906 1907
1907 if (iscsi_r2tpool_alloc(class_to_transport_session(cls_session))) 1908 if (iscsi_r2tpool_alloc(session))
1908 goto r2tpool_alloc_fail; 1909 goto remove_session;
1909
1910 return cls_session; 1910 return cls_session;
1911 1911
1912r2tpool_alloc_fail: 1912remove_session:
1913 iscsi_session_teardown(cls_session); 1913 iscsi_session_teardown(cls_session);
1914remove_host:
1915 scsi_remove_host(shost);
1916free_host:
1917 iscsi_host_teardown(shost);
1918 scsi_host_put(shost);
1914 return NULL; 1919 return NULL;
1915} 1920}
1916 1921
1917static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session) 1922static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session)
1918{ 1923{
1919 iscsi_r2tpool_free(class_to_transport_session(cls_session)); 1924 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1925
1926 iscsi_r2tpool_free(cls_session->dd_data);
1920 iscsi_session_teardown(cls_session); 1927 iscsi_session_teardown(cls_session);
1928
1929 scsi_remove_host(shost);
1930 iscsi_host_teardown(shost);
1931 scsi_host_put(shost);
1921} 1932}
1922 1933
1923static int iscsi_tcp_slave_configure(struct scsi_device *sdev) 1934static int iscsi_tcp_slave_configure(struct scsi_device *sdev)
@@ -1976,8 +1987,8 @@ static struct iscsi_transport iscsi_tcp_transport = {
1976 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS | 1987 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
1977 ISCSI_HOST_INITIATOR_NAME | 1988 ISCSI_HOST_INITIATOR_NAME |
1978 ISCSI_HOST_NETDEV_NAME, 1989 ISCSI_HOST_NETDEV_NAME,
1979 .host_template = &iscsi_sht,
1980 .conndata_size = sizeof(struct iscsi_conn), 1990 .conndata_size = sizeof(struct iscsi_conn),
1991 .sessiondata_size = sizeof(struct iscsi_session),
1981 /* session management */ 1992 /* session management */
1982 .create_session = iscsi_tcp_session_create, 1993 .create_session = iscsi_tcp_session_create,
1983 .destroy_session = iscsi_tcp_session_destroy, 1994 .destroy_session = iscsi_tcp_session_destroy,
@@ -1991,7 +2002,7 @@ static struct iscsi_transport iscsi_tcp_transport = {
1991 .start_conn = iscsi_conn_start, 2002 .start_conn = iscsi_conn_start,
1992 .stop_conn = iscsi_tcp_conn_stop, 2003 .stop_conn = iscsi_tcp_conn_stop,
1993 /* iscsi host params */ 2004 /* iscsi host params */
1994 .get_host_param = iscsi_tcp_host_get_param, 2005 .get_host_param = iscsi_host_get_param,
1995 .set_host_param = iscsi_host_set_param, 2006 .set_host_param = iscsi_host_set_param,
1996 /* IO */ 2007 /* IO */
1997 .send_pdu = iscsi_conn_send_pdu, 2008 .send_pdu = iscsi_conn_send_pdu,
@@ -2013,9 +2024,10 @@ iscsi_tcp_init(void)
2013 iscsi_max_lun); 2024 iscsi_max_lun);
2014 return -EINVAL; 2025 return -EINVAL;
2015 } 2026 }
2016 iscsi_tcp_transport.max_lun = iscsi_max_lun;
2017 2027
2018 if (!iscsi_register_transport(&iscsi_tcp_transport)) 2028 iscsi_tcp_scsi_transport = iscsi_register_transport(
2029 &iscsi_tcp_transport);
2030 if (!iscsi_tcp_scsi_transport)
2019 return -ENODEV; 2031 return -ENODEV;
2020 2032
2021 return 0; 2033 return 0;
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 01a1a4d36f21..64b1dd827366 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -38,14 +38,6 @@
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
41struct iscsi_session *
42class_to_transport_session(struct iscsi_cls_session *cls_session)
43{
44 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
45 return iscsi_hostdata(shost->hostdata);
46}
47EXPORT_SYMBOL_GPL(class_to_transport_session);
48
49/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */ 41/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
50#define SNA32_CHECK 2147483648UL 42#define SNA32_CHECK 2147483648UL
51 43
@@ -1096,6 +1088,7 @@ enum {
1096 1088
1097int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) 1089int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1098{ 1090{
1091 struct iscsi_cls_session *cls_session;
1099 struct Scsi_Host *host; 1092 struct Scsi_Host *host;
1100 int reason = 0; 1093 int reason = 0;
1101 struct iscsi_session *session; 1094 struct iscsi_session *session;
@@ -1109,10 +1102,11 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1109 host = sc->device->host; 1102 host = sc->device->host;
1110 spin_unlock(host->host_lock); 1103 spin_unlock(host->host_lock);
1111 1104
1112 session = iscsi_hostdata(host->hostdata); 1105 cls_session = starget_to_session(scsi_target(sc->device));
1106 session = cls_session->dd_data;
1113 spin_lock(&session->lock); 1107 spin_lock(&session->lock);
1114 1108
1115 reason = iscsi_session_chkready(session_to_cls(session)); 1109 reason = iscsi_session_chkready(cls_session);
1116 if (reason) { 1110 if (reason) {
1117 sc->result = reason; 1111 sc->result = reason;
1118 goto fault; 1112 goto fault;
@@ -1222,7 +1216,7 @@ EXPORT_SYMBOL_GPL(iscsi_change_queue_depth);
1222 1216
1223void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session) 1217void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session)
1224{ 1218{
1225 struct iscsi_session *session = class_to_transport_session(cls_session); 1219 struct iscsi_session *session = cls_session->dd_data;
1226 1220
1227 spin_lock_bh(&session->lock); 1221 spin_lock_bh(&session->lock);
1228 if (session->state != ISCSI_STATE_LOGGED_IN) { 1222 if (session->state != ISCSI_STATE_LOGGED_IN) {
@@ -1236,9 +1230,13 @@ EXPORT_SYMBOL_GPL(iscsi_session_recovery_timedout);
1236 1230
1237int iscsi_eh_host_reset(struct scsi_cmnd *sc) 1231int iscsi_eh_host_reset(struct scsi_cmnd *sc)
1238{ 1232{
1239 struct Scsi_Host *host = sc->device->host; 1233 struct iscsi_cls_session *cls_session;
1240 struct iscsi_session *session = iscsi_hostdata(host->hostdata); 1234 struct iscsi_session *session;
1241 struct iscsi_conn *conn = session->leadconn; 1235 struct iscsi_conn *conn;
1236
1237 cls_session = starget_to_session(scsi_target(sc->device));
1238 session = cls_session->dd_data;
1239 conn = session->leadconn;
1242 1240
1243 mutex_lock(&session->eh_mutex); 1241 mutex_lock(&session->eh_mutex);
1244 spin_lock_bh(&session->lock); 1242 spin_lock_bh(&session->lock);
@@ -1405,7 +1403,7 @@ static enum scsi_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
1405 enum scsi_eh_timer_return rc = EH_NOT_HANDLED; 1403 enum scsi_eh_timer_return rc = EH_NOT_HANDLED;
1406 1404
1407 cls_session = starget_to_session(scsi_target(scmd->device)); 1405 cls_session = starget_to_session(scsi_target(scmd->device));
1408 session = class_to_transport_session(cls_session); 1406 session = cls_session->dd_data;
1409 1407
1410 debug_scsi("scsi cmd %p timedout\n", scmd); 1408 debug_scsi("scsi cmd %p timedout\n", scmd);
1411 1409
@@ -1507,13 +1505,16 @@ static void iscsi_prep_abort_task_pdu(struct iscsi_cmd_task *ctask,
1507 1505
1508int iscsi_eh_abort(struct scsi_cmnd *sc) 1506int iscsi_eh_abort(struct scsi_cmnd *sc)
1509{ 1507{
1510 struct Scsi_Host *host = sc->device->host; 1508 struct iscsi_cls_session *cls_session;
1511 struct iscsi_session *session = iscsi_hostdata(host->hostdata); 1509 struct iscsi_session *session;
1512 struct iscsi_conn *conn; 1510 struct iscsi_conn *conn;
1513 struct iscsi_cmd_task *ctask; 1511 struct iscsi_cmd_task *ctask;
1514 struct iscsi_tm *hdr; 1512 struct iscsi_tm *hdr;
1515 int rc, age; 1513 int rc, age;
1516 1514
1515 cls_session = starget_to_session(scsi_target(sc->device));
1516 session = cls_session->dd_data;
1517
1517 mutex_lock(&session->eh_mutex); 1518 mutex_lock(&session->eh_mutex);
1518 spin_lock_bh(&session->lock); 1519 spin_lock_bh(&session->lock);
1519 /* 1520 /*
@@ -1630,12 +1631,15 @@ static void iscsi_prep_lun_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr)
1630 1631
1631int iscsi_eh_device_reset(struct scsi_cmnd *sc) 1632int iscsi_eh_device_reset(struct scsi_cmnd *sc)
1632{ 1633{
1633 struct Scsi_Host *host = sc->device->host; 1634 struct iscsi_cls_session *cls_session;
1634 struct iscsi_session *session = iscsi_hostdata(host->hostdata); 1635 struct iscsi_session *session;
1635 struct iscsi_conn *conn; 1636 struct iscsi_conn *conn;
1636 struct iscsi_tm *hdr; 1637 struct iscsi_tm *hdr;
1637 int rc = FAILED; 1638 int rc = FAILED;
1638 1639
1640 cls_session = starget_to_session(scsi_target(sc->device));
1641 session = cls_session->dd_data;
1642
1639 debug_scsi("LU Reset [sc %p lun %u]\n", sc, sc->device->lun); 1643 debug_scsi("LU Reset [sc %p lun %u]\n", sc, sc->device->lun);
1640 1644
1641 mutex_lock(&session->eh_mutex); 1645 mutex_lock(&session->eh_mutex);
@@ -1760,55 +1764,53 @@ void iscsi_pool_free(struct iscsi_pool *q)
1760} 1764}
1761EXPORT_SYMBOL_GPL(iscsi_pool_free); 1765EXPORT_SYMBOL_GPL(iscsi_pool_free);
1762 1766
1763/* 1767void iscsi_host_setup(struct Scsi_Host *shost, uint16_t qdepth)
1764 * iSCSI Session's hostdata organization: 1768{
1765 * 1769 if (qdepth > ISCSI_MAX_CMD_PER_LUN || qdepth < 1) {
1766 * *------------------* <== hostdata_session(host->hostdata) 1770 if (qdepth != 0)
1767 * | ptr to class sess| 1771 printk(KERN_ERR "iscsi: invalid queue depth of %d. "
1768 * |------------------| <== iscsi_hostdata(host->hostdata) 1772 "Queue depth must be between 1 and %d.\n",
1769 * | iscsi_session | 1773 qdepth, ISCSI_MAX_CMD_PER_LUN);
1770 * *------------------* 1774 qdepth = ISCSI_DEF_CMD_PER_LUN;
1771 */ 1775 }
1776
1777 shost->transportt->create_work_queue = 1;
1778 shost->transportt->eh_timed_out = iscsi_eh_cmd_timed_out;
1779 shost->cmd_per_lun = qdepth;
1780}
1781EXPORT_SYMBOL_GPL(iscsi_host_setup);
1772 1782
1773#define hostdata_privsize(_sz) (sizeof(unsigned long) + _sz + \ 1783void iscsi_host_teardown(struct Scsi_Host *shost)
1774 _sz % sizeof(unsigned long)) 1784{
1785 struct iscsi_host *ihost = shost_priv(shost);
1775 1786
1776#define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata)) 1787 kfree(ihost->netdev);
1788 kfree(ihost->hwaddress);
1789 kfree(ihost->initiatorname);
1790}
1791EXPORT_SYMBOL_GPL(iscsi_host_teardown);
1777 1792
1778/** 1793/**
1779 * iscsi_session_setup - create iscsi cls session and host and session 1794 * iscsi_session_setup - create iscsi cls session and host and session
1780 * @scsit: scsi transport template
1781 * @iscsit: iscsi transport template 1795 * @iscsit: iscsi transport template
1782 * @cmds_max: scsi host can queue 1796 * @shost: scsi host
1783 * @qdepth: scsi host cmds per lun 1797 * @cmds_max: session can queue
1784 * @cmd_task_size: LLD ctask private data size 1798 * @cmd_task_size: LLD ctask private data size
1785 * @mgmt_task_size: LLD mtask private data size 1799 * @mgmt_task_size: LLD mtask private data size
1786 * @initial_cmdsn: initial CmdSN 1800 * @initial_cmdsn: initial CmdSN
1787 * @hostno: host no allocated
1788 * 1801 *
1789 * This can be used by software iscsi_transports that allocate 1802 * This can be used by software iscsi_transports that allocate
1790 * a session per scsi host. 1803 * a session per scsi host.
1791 **/ 1804 */
1792struct iscsi_cls_session * 1805struct iscsi_cls_session *
1793iscsi_session_setup(struct iscsi_transport *iscsit, 1806iscsi_session_setup(struct iscsi_transport *iscsit, struct Scsi_Host *shost,
1794 struct scsi_transport_template *scsit, 1807 uint16_t cmds_max, int cmd_task_size, int mgmt_task_size,
1795 uint16_t cmds_max, uint16_t qdepth, 1808 uint32_t initial_cmdsn)
1796 int cmd_task_size, int mgmt_task_size,
1797 uint32_t initial_cmdsn, uint32_t *hostno)
1798{ 1809{
1799 struct Scsi_Host *shost;
1800 struct iscsi_session *session; 1810 struct iscsi_session *session;
1801 struct iscsi_cls_session *cls_session; 1811 struct iscsi_cls_session *cls_session;
1802 int cmd_i; 1812 int cmd_i;
1803 1813
1804 if (qdepth > ISCSI_MAX_CMD_PER_LUN || qdepth < 1) {
1805 if (qdepth != 0)
1806 printk(KERN_ERR "iscsi: invalid queue depth of %d. "
1807 "Queue depth must be between 1 and %d.\n",
1808 qdepth, ISCSI_MAX_CMD_PER_LUN);
1809 qdepth = ISCSI_DEF_CMD_PER_LUN;
1810 }
1811
1812 if (!is_power_of_2(cmds_max) || cmds_max >= ISCSI_MGMT_ITT_OFFSET || 1814 if (!is_power_of_2(cmds_max) || cmds_max >= ISCSI_MGMT_ITT_OFFSET ||
1813 cmds_max < 2) { 1815 cmds_max < 2) {
1814 if (cmds_max != 0) 1816 if (cmds_max != 0)
@@ -1819,25 +1821,11 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1819 cmds_max = ISCSI_DEF_XMIT_CMDS_MAX; 1821 cmds_max = ISCSI_DEF_XMIT_CMDS_MAX;
1820 } 1822 }
1821 1823
1822 shost = scsi_host_alloc(iscsit->host_template, 1824 cls_session = iscsi_alloc_session(shost, iscsit);
1823 hostdata_privsize(sizeof(*session))); 1825 if (!cls_session)
1824 if (!shost)
1825 return NULL; 1826 return NULL;
1826 1827 session = cls_session->dd_data;
1827 /* the iscsi layer takes one task for reserve */ 1828 session->cls_session = cls_session;
1828 shost->can_queue = cmds_max - 1;
1829 shost->cmd_per_lun = qdepth;
1830 shost->max_id = 1;
1831 shost->max_channel = 0;
1832 shost->max_lun = iscsit->max_lun;
1833 shost->max_cmd_len = 16;
1834 shost->transportt = scsit;
1835 shost->transportt->create_work_queue = 1;
1836 shost->transportt->eh_timed_out = iscsi_eh_cmd_timed_out;
1837 *hostno = shost->host_no;
1838
1839 session = iscsi_hostdata(shost->hostdata);
1840 memset(session, 0, sizeof(struct iscsi_session));
1841 session->host = shost; 1829 session->host = shost;
1842 session->state = ISCSI_STATE_FREE; 1830 session->state = ISCSI_STATE_FREE;
1843 session->fast_abort = 1; 1831 session->fast_abort = 1;
@@ -1851,6 +1839,7 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1851 session->max_r2t = 1; 1839 session->max_r2t = 1;
1852 session->tt = iscsit; 1840 session->tt = iscsit;
1853 mutex_init(&session->eh_mutex); 1841 mutex_init(&session->eh_mutex);
1842 spin_lock_init(&session->lock);
1854 1843
1855 /* initialize SCSI PDU commands pool */ 1844 /* initialize SCSI PDU commands pool */
1856 if (iscsi_pool_init(&session->cmdpool, session->cmds_max, 1845 if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
@@ -1868,8 +1857,6 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1868 INIT_LIST_HEAD(&ctask->running); 1857 INIT_LIST_HEAD(&ctask->running);
1869 } 1858 }
1870 1859
1871 spin_lock_init(&session->lock);
1872
1873 /* initialize immediate command pool */ 1860 /* initialize immediate command pool */
1874 if (iscsi_pool_init(&session->mgmtpool, session->mgmtpool_max, 1861 if (iscsi_pool_init(&session->mgmtpool, session->mgmtpool_max,
1875 (void***)&session->mgmt_cmds, 1862 (void***)&session->mgmt_cmds,
@@ -1887,49 +1874,37 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1887 INIT_LIST_HEAD(&mtask->running); 1874 INIT_LIST_HEAD(&mtask->running);
1888 } 1875 }
1889 1876
1890 if (scsi_add_host(shost, NULL))
1891 goto add_host_fail;
1892
1893 if (!try_module_get(iscsit->owner)) 1877 if (!try_module_get(iscsit->owner))
1894 goto cls_session_fail; 1878 goto module_get_fail;
1895
1896 cls_session = iscsi_create_session(shost, iscsit, 0);
1897 if (!cls_session)
1898 goto module_put;
1899 *(unsigned long*)shost->hostdata = (unsigned long)cls_session;
1900 1879
1880 if (iscsi_add_session(cls_session, 0))
1881 goto cls_session_fail;
1901 return cls_session; 1882 return cls_session;
1902 1883
1903module_put:
1904 module_put(iscsit->owner);
1905cls_session_fail: 1884cls_session_fail:
1906 scsi_remove_host(shost); 1885 module_put(iscsit->owner);
1907add_host_fail: 1886module_get_fail:
1908 iscsi_pool_free(&session->mgmtpool); 1887 iscsi_pool_free(&session->mgmtpool);
1909mgmtpool_alloc_fail: 1888mgmtpool_alloc_fail:
1910 iscsi_pool_free(&session->cmdpool); 1889 iscsi_pool_free(&session->cmdpool);
1911cmdpool_alloc_fail: 1890cmdpool_alloc_fail:
1912 scsi_host_put(shost); 1891 iscsi_free_session(cls_session);
1913 return NULL; 1892 return NULL;
1914} 1893}
1915EXPORT_SYMBOL_GPL(iscsi_session_setup); 1894EXPORT_SYMBOL_GPL(iscsi_session_setup);
1916 1895
1917/** 1896/**
1918 * iscsi_session_teardown - destroy session, host, and cls_session 1897 * iscsi_session_teardown - destroy session, host, and cls_session
1919 * shost: scsi host 1898 * @cls_session: iscsi session
1920 * 1899 *
1921 * This can be used by software iscsi_transports that allocate 1900 * The driver must have called iscsi_remove_session before
1922 * a session per scsi host. 1901 * calling this.
1923 **/ 1902 */
1924void iscsi_session_teardown(struct iscsi_cls_session *cls_session) 1903void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
1925{ 1904{
1926 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); 1905 struct iscsi_session *session = cls_session->dd_data;
1927 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1928 struct module *owner = cls_session->transport->owner; 1906 struct module *owner = cls_session->transport->owner;
1929 1907
1930 iscsi_remove_session(cls_session);
1931 scsi_remove_host(shost);
1932
1933 iscsi_pool_free(&session->mgmtpool); 1908 iscsi_pool_free(&session->mgmtpool);
1934 iscsi_pool_free(&session->cmdpool); 1909 iscsi_pool_free(&session->cmdpool);
1935 1910
@@ -1938,12 +1913,8 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
1938 kfree(session->username); 1913 kfree(session->username);
1939 kfree(session->username_in); 1914 kfree(session->username_in);
1940 kfree(session->targetname); 1915 kfree(session->targetname);
1941 kfree(session->netdev);
1942 kfree(session->hwaddress);
1943 kfree(session->initiatorname);
1944 1916
1945 iscsi_free_session(cls_session); 1917 iscsi_destroy_session(cls_session);
1946 scsi_host_put(shost);
1947 module_put(owner); 1918 module_put(owner);
1948} 1919}
1949EXPORT_SYMBOL_GPL(iscsi_session_teardown); 1920EXPORT_SYMBOL_GPL(iscsi_session_teardown);
@@ -1956,7 +1927,7 @@ EXPORT_SYMBOL_GPL(iscsi_session_teardown);
1956struct iscsi_cls_conn * 1927struct iscsi_cls_conn *
1957iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx) 1928iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1958{ 1929{
1959 struct iscsi_session *session = class_to_transport_session(cls_session); 1930 struct iscsi_session *session = cls_session->dd_data;
1960 struct iscsi_conn *conn; 1931 struct iscsi_conn *conn;
1961 struct iscsi_cls_conn *cls_conn; 1932 struct iscsi_cls_conn *cls_conn;
1962 char *data; 1933 char *data;
@@ -2140,7 +2111,7 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
2140 } 2111 }
2141 spin_unlock_bh(&session->lock); 2112 spin_unlock_bh(&session->lock);
2142 2113
2143 iscsi_unblock_session(session_to_cls(session)); 2114 iscsi_unblock_session(session->cls_session);
2144 wake_up(&conn->ehwait); 2115 wake_up(&conn->ehwait);
2145 return 0; 2116 return 0;
2146} 2117}
@@ -2225,7 +2196,7 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
2225 if (session->state == ISCSI_STATE_IN_RECOVERY && 2196 if (session->state == ISCSI_STATE_IN_RECOVERY &&
2226 old_stop_stage != STOP_CONN_RECOVER) { 2197 old_stop_stage != STOP_CONN_RECOVER) {
2227 debug_scsi("blocking session\n"); 2198 debug_scsi("blocking session\n");
2228 iscsi_block_session(session_to_cls(session)); 2199 iscsi_block_session(session->cls_session);
2229 } 2200 }
2230 } 2201 }
2231 2202
@@ -2260,7 +2231,7 @@ EXPORT_SYMBOL_GPL(iscsi_conn_stop);
2260int iscsi_conn_bind(struct iscsi_cls_session *cls_session, 2231int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
2261 struct iscsi_cls_conn *cls_conn, int is_leading) 2232 struct iscsi_cls_conn *cls_conn, int is_leading)
2262{ 2233{
2263 struct iscsi_session *session = class_to_transport_session(cls_session); 2234 struct iscsi_session *session = cls_session->dd_data;
2264 struct iscsi_conn *conn = cls_conn->dd_data; 2235 struct iscsi_conn *conn = cls_conn->dd_data;
2265 2236
2266 spin_lock_bh(&session->lock); 2237 spin_lock_bh(&session->lock);
@@ -2410,8 +2381,7 @@ EXPORT_SYMBOL_GPL(iscsi_set_param);
2410int iscsi_session_get_param(struct iscsi_cls_session *cls_session, 2381int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
2411 enum iscsi_param param, char *buf) 2382 enum iscsi_param param, char *buf)
2412{ 2383{
2413 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); 2384 struct iscsi_session *session = cls_session->dd_data;
2414 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
2415 int len; 2385 int len;
2416 2386
2417 switch(param) { 2387 switch(param) {
@@ -2525,29 +2495,34 @@ EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
2525int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param, 2495int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
2526 char *buf) 2496 char *buf)
2527{ 2497{
2528 struct iscsi_session *session = iscsi_hostdata(shost->hostdata); 2498 struct iscsi_host *ihost = shost_priv(shost);
2529 int len; 2499 int len;
2530 2500
2531 switch (param) { 2501 switch (param) {
2532 case ISCSI_HOST_PARAM_NETDEV_NAME: 2502 case ISCSI_HOST_PARAM_NETDEV_NAME:
2533 if (!session->netdev) 2503 if (!ihost->netdev)
2534 len = sprintf(buf, "%s\n", "default"); 2504 len = sprintf(buf, "%s\n", "default");
2535 else 2505 else
2536 len = sprintf(buf, "%s\n", session->netdev); 2506 len = sprintf(buf, "%s\n", ihost->netdev);
2537 break; 2507 break;
2538 case ISCSI_HOST_PARAM_HWADDRESS: 2508 case ISCSI_HOST_PARAM_HWADDRESS:
2539 if (!session->hwaddress) 2509 if (!ihost->hwaddress)
2540 len = sprintf(buf, "%s\n", "default"); 2510 len = sprintf(buf, "%s\n", "default");
2541 else 2511 else
2542 len = sprintf(buf, "%s\n", session->hwaddress); 2512 len = sprintf(buf, "%s\n", ihost->hwaddress);
2543 break; 2513 break;
2544 case ISCSI_HOST_PARAM_INITIATOR_NAME: 2514 case ISCSI_HOST_PARAM_INITIATOR_NAME:
2545 if (!session->initiatorname) 2515 if (!ihost->initiatorname)
2546 len = sprintf(buf, "%s\n", "unknown"); 2516 len = sprintf(buf, "%s\n", "unknown");
2547 else 2517 else
2548 len = sprintf(buf, "%s\n", session->initiatorname); 2518 len = sprintf(buf, "%s\n", ihost->initiatorname);
2549 break; 2519 break;
2550 2520 case ISCSI_HOST_PARAM_IPADDRESS:
2521 if (!strlen(ihost->local_address))
2522 len = sprintf(buf, "%s\n", "unknown");
2523 else
2524 len = sprintf(buf, "%s\n",
2525 ihost->local_address);
2551 default: 2526 default:
2552 return -ENOSYS; 2527 return -ENOSYS;
2553 } 2528 }
@@ -2559,20 +2534,20 @@ EXPORT_SYMBOL_GPL(iscsi_host_get_param);
2559int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param, 2534int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param,
2560 char *buf, int buflen) 2535 char *buf, int buflen)
2561{ 2536{
2562 struct iscsi_session *session = iscsi_hostdata(shost->hostdata); 2537 struct iscsi_host *ihost = shost_priv(shost);
2563 2538
2564 switch (param) { 2539 switch (param) {
2565 case ISCSI_HOST_PARAM_NETDEV_NAME: 2540 case ISCSI_HOST_PARAM_NETDEV_NAME:
2566 if (!session->netdev) 2541 if (!ihost->netdev)
2567 session->netdev = kstrdup(buf, GFP_KERNEL); 2542 ihost->netdev = kstrdup(buf, GFP_KERNEL);
2568 break; 2543 break;
2569 case ISCSI_HOST_PARAM_HWADDRESS: 2544 case ISCSI_HOST_PARAM_HWADDRESS:
2570 if (!session->hwaddress) 2545 if (!ihost->hwaddress)
2571 session->hwaddress = kstrdup(buf, GFP_KERNEL); 2546 ihost->hwaddress = kstrdup(buf, GFP_KERNEL);
2572 break; 2547 break;
2573 case ISCSI_HOST_PARAM_INITIATOR_NAME: 2548 case ISCSI_HOST_PARAM_INITIATOR_NAME:
2574 if (!session->initiatorname) 2549 if (!ihost->initiatorname)
2575 session->initiatorname = kstrdup(buf, GFP_KERNEL); 2550 ihost->initiatorname = kstrdup(buf, GFP_KERNEL);
2576 break; 2551 break;
2577 default: 2552 default:
2578 return -ENOSYS; 2553 return -ENOSYS;
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 0c786944d2c2..6c6ee0f34995 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -114,7 +114,6 @@ static struct iscsi_transport qla4xxx_iscsi_transport = {
114 ISCSI_HOST_IPADDRESS | 114 ISCSI_HOST_IPADDRESS |
115 ISCSI_HOST_INITIATOR_NAME, 115 ISCSI_HOST_INITIATOR_NAME,
116 .sessiondata_size = sizeof(struct ddb_entry), 116 .sessiondata_size = sizeof(struct ddb_entry),
117 .host_template = &qla4xxx_driver_template,
118 117
119 .tgt_dscvr = qla4xxx_tgt_dscvr, 118 .tgt_dscvr = qla4xxx_tgt_dscvr,
120 .get_conn_param = qla4xxx_conn_get_param, 119 .get_conn_param = qla4xxx_conn_get_param,
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 5577a60bec4e..9c00a157b485 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -101,12 +101,10 @@ show_transport_##name(struct device *dev, \
101static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL); 101static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
102 102
103show_transport_attr(caps, "0x%x"); 103show_transport_attr(caps, "0x%x");
104show_transport_attr(max_lun, "%d");
105 104
106static struct attribute *iscsi_transport_attrs[] = { 105static struct attribute *iscsi_transport_attrs[] = {
107 &dev_attr_handle.attr, 106 &dev_attr_handle.attr,
108 &dev_attr_caps.attr, 107 &dev_attr_caps.attr,
109 &dev_attr_max_lun.attr,
110 NULL, 108 NULL,
111}; 109};
112 110
@@ -1034,8 +1032,7 @@ iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_uevent *ev,
1034 } 1032 }
1035 } 1033 }
1036 1034
1037 session = transport->create_session(transport, &priv->t, shost, 1035 session = transport->create_session(shost, cmds_max, queue_depth,
1038 cmds_max, queue_depth,
1039 initial_cmdsn, &host_no); 1036 initial_cmdsn, &host_no);
1040 if (shost) 1037 if (shost)
1041 scsi_host_put(shost); 1038 scsi_host_put(shost);
diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h
index 1883c85cd3ee..801a677777cc 100644
--- a/include/scsi/iscsi_if.h
+++ b/include/scsi/iscsi_if.h
@@ -310,13 +310,6 @@ enum iscsi_host_param {
310 310
311#define iscsi_ptr(_handle) ((void*)(unsigned long)_handle) 311#define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
312#define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr) 312#define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
313#define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
314
315/**
316 * iscsi_hostdata - get LLD hostdata from scsi_host
317 * @_hostdata: pointer to scsi host's hostdata
318 **/
319#define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long))
320 313
321/* 314/*
322 * These flags presents iSCSI Data-Path capabilities. 315 * These flags presents iSCSI Data-Path capabilities.
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index f24cf0246739..8a6271c20935 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -209,9 +209,6 @@ struct iscsi_conn {
209 /* remote portal currently connected to */ 209 /* remote portal currently connected to */
210 int portal_port; 210 int portal_port;
211 char portal_address[ISCSI_ADDRESS_BUF_LEN]; 211 char portal_address[ISCSI_ADDRESS_BUF_LEN];
212 /* local address */
213 int local_port;
214 char local_address[ISCSI_ADDRESS_BUF_LEN];
215 212
216 /* MIB-statistics */ 213 /* MIB-statistics */
217 uint64_t txdata_octets; 214 uint64_t txdata_octets;
@@ -247,6 +244,7 @@ enum {
247}; 244};
248 245
249struct iscsi_session { 246struct iscsi_session {
247 struct iscsi_cls_session *cls_session;
250 /* 248 /*
251 * Syncs up the scsi eh thread with the iscsi eh thread when sending 249 * Syncs up the scsi eh thread with the iscsi eh thread when sending
252 * task management functions. This must be taken before the session 250 * task management functions. This must be taken before the session
@@ -282,10 +280,6 @@ struct iscsi_session {
282 char *password; 280 char *password;
283 char *password_in; 281 char *password_in;
284 char *targetname; 282 char *targetname;
285 char *initiatorname;
286 /* hw address or netdev iscsi connection is bound to */
287 char *hwaddress;
288 char *netdev;
289 /* control data */ 283 /* control data */
290 struct iscsi_transport *tt; 284 struct iscsi_transport *tt;
291 struct Scsi_Host *host; 285 struct Scsi_Host *host;
@@ -307,6 +301,16 @@ struct iscsi_session {
307 struct iscsi_pool mgmtpool; /* Mgmt PDU's pool */ 301 struct iscsi_pool mgmtpool; /* Mgmt PDU's pool */
308}; 302};
309 303
304struct iscsi_host {
305 char *initiatorname;
306 /* hw address or netdev iscsi connection is bound to */
307 char *hwaddress;
308 char *netdev;
309 /* local address */
310 int local_port;
311 char local_address[ISCSI_ADDRESS_BUF_LEN];
312};
313
310/* 314/*
311 * scsi host template 315 * scsi host template
312 */ 316 */
@@ -326,27 +330,24 @@ extern int iscsi_host_set_param(struct Scsi_Host *shost,
326 int buflen); 330 int buflen);
327extern int iscsi_host_get_param(struct Scsi_Host *shost, 331extern int iscsi_host_get_param(struct Scsi_Host *shost,
328 enum iscsi_host_param param, char *buf); 332 enum iscsi_host_param param, char *buf);
333extern void iscsi_host_setup(struct Scsi_Host *shost, uint16_t qdepth);
334extern void iscsi_host_teardown(struct Scsi_Host *shost);
329 335
330/* 336/*
331 * session management 337 * session management
332 */ 338 */
333extern struct iscsi_cls_session * 339extern struct iscsi_cls_session *
334iscsi_session_setup(struct iscsi_transport *, struct scsi_transport_template *, 340iscsi_session_setup(struct iscsi_transport *, struct Scsi_Host *shost,
335 uint16_t, uint16_t, int, int, uint32_t, uint32_t *); 341 uint16_t, int, int, uint32_t);
336extern void iscsi_session_teardown(struct iscsi_cls_session *); 342extern void iscsi_session_teardown(struct iscsi_cls_session *);
337extern struct iscsi_session *class_to_transport_session(struct iscsi_cls_session *);
338extern void iscsi_session_recovery_timedout(struct iscsi_cls_session *); 343extern void iscsi_session_recovery_timedout(struct iscsi_cls_session *);
339extern int iscsi_set_param(struct iscsi_cls_conn *cls_conn, 344extern int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
340 enum iscsi_param param, char *buf, int buflen); 345 enum iscsi_param param, char *buf, int buflen);
341extern int iscsi_session_get_param(struct iscsi_cls_session *cls_session, 346extern int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
342 enum iscsi_param param, char *buf); 347 enum iscsi_param param, char *buf);
343 348
344#define session_to_cls(_sess) \
345 hostdata_session(_sess->host->hostdata)
346
347#define iscsi_session_printk(prefix, _sess, fmt, a...) \ 349#define iscsi_session_printk(prefix, _sess, fmt, a...) \
348 iscsi_cls_session_printk(prefix, \ 350 iscsi_cls_session_printk(prefix, _sess->cls_session, fmt, ##a)
349 (struct iscsi_cls_session *)session_to_cls(_sess), fmt, ##a)
350 351
351/* 352/*
352 * connection management 353 * connection management
diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h
index 728702292a80..702eda2904d7 100644
--- a/include/scsi/scsi_transport_iscsi.h
+++ b/include/scsi/scsi_transport_iscsi.h
@@ -83,15 +83,13 @@ struct iscsi_transport {
83 /* LLD sets this to indicate what values it can export to sysfs */ 83 /* LLD sets this to indicate what values it can export to sysfs */
84 uint64_t param_mask; 84 uint64_t param_mask;
85 uint64_t host_param_mask; 85 uint64_t host_param_mask;
86 struct scsi_host_template *host_template;
87 /* LLD connection data size */ 86 /* LLD connection data size */
88 int conndata_size; 87 int conndata_size;
89 /* LLD session data size */ 88 /* LLD session data size */
90 int sessiondata_size; 89 int sessiondata_size;
91 int max_lun; 90 struct iscsi_cls_session *(*create_session) (struct Scsi_Host *shost,
92 struct iscsi_cls_session *(*create_session) (struct iscsi_transport *it, 91 uint16_t cmds_max, uint16_t qdepth,
93 struct scsi_transport_template *t, struct Scsi_Host *shost, 92 uint32_t sn, uint32_t *hn);
94 uint16_t cmds_max, uint16_t qdepth, uint32_t sn, uint32_t *hn);
95 void (*destroy_session) (struct iscsi_cls_session *session); 93 void (*destroy_session) (struct iscsi_cls_session *session);
96 struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess, 94 struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,
97 uint32_t cid); 95 uint32_t cid);