scsi_transport_iscsi.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * iSCSI transport class definitions
  3. *
  4. * Copyright (C) IBM Corporation, 2004
  5. * Copyright (C) Mike Christie, 2004 - 2005
  6. * Copyright (C) Dmitry Yusupov, 2004 - 2005
  7. * Copyright (C) Alex Aizman, 2004 - 2005
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef SCSI_TRANSPORT_ISCSI_H
  24. #define SCSI_TRANSPORT_ISCSI_H
  25. #include <linux/device.h>
  26. #include <scsi/iscsi_if.h>
  27. struct scsi_transport_template;
  28. struct Scsi_Host;
  29. struct mempool_zone;
  30. struct iscsi_cls_conn;
  31. /**
  32. * struct iscsi_transport - iSCSI Transport template
  33. *
  34. * @name: transport name
  35. * @caps: iSCSI Data-Path capabilities
  36. * @create_session: create new iSCSI session object
  37. * @destroy_session: destroy existing iSCSI session object
  38. * @create_conn: create new iSCSI connection
  39. * @bind_conn: associate this connection with existing iSCSI session
  40. * and specified transport descriptor
  41. * @destroy_conn: destroy inactive iSCSI connection
  42. * @set_param: set iSCSI Data-Path operational parameter
  43. * @start_conn: set connection to be operational
  44. * @stop_conn: suspend/recover/terminate connection
  45. * @send_pdu: send iSCSI PDU, Login, Logout, NOP-Out, Reject, Text.
  46. *
  47. * Template API provided by iSCSI Transport
  48. */
  49. struct iscsi_transport {
  50. struct module *owner;
  51. char *name;
  52. unsigned int caps;
  53. /* LLD sets this to indicate what values it can export to sysfs */
  54. unsigned int param_mask;
  55. struct scsi_host_template *host_template;
  56. /* LLD session/scsi_host data size */
  57. int hostdata_size;
  58. /* LLD connection data size */
  59. int conndata_size;
  60. /* LLD session data size */
  61. int sessiondata_size;
  62. int max_lun;
  63. unsigned int max_conn;
  64. unsigned int max_cmd_len;
  65. struct iscsi_cls_session *(*create_session)
  66. (struct scsi_transport_template *t, uint32_t sn, uint32_t *hn);
  67. void (*destroy_session) (struct iscsi_cls_session *session);
  68. struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,
  69. uint32_t cid);
  70. int (*bind_conn) (struct iscsi_cls_session *session,
  71. struct iscsi_cls_conn *cls_conn,
  72. uint32_t transport_fd, int is_leading);
  73. int (*start_conn) (struct iscsi_cls_conn *conn);
  74. void (*stop_conn) (struct iscsi_cls_conn *conn, int flag);
  75. void (*destroy_conn) (struct iscsi_cls_conn *conn);
  76. int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param,
  77. uint32_t value);
  78. int (*get_conn_param) (struct iscsi_cls_conn *conn,
  79. enum iscsi_param param, uint32_t *value);
  80. int (*get_session_param) (struct iscsi_cls_session *session,
  81. enum iscsi_param param, uint32_t *value);
  82. int (*get_conn_str_param) (struct iscsi_cls_conn *conn,
  83. enum iscsi_param param, char *buf);
  84. int (*get_session_str_param) (struct iscsi_cls_session *session,
  85. enum iscsi_param param, char *buf);
  86. int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
  87. char *data, uint32_t data_size);
  88. void (*get_stats) (struct iscsi_cls_conn *conn,
  89. struct iscsi_stats *stats);
  90. };
  91. /*
  92. * transport registration upcalls
  93. */
  94. extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt);
  95. extern int iscsi_unregister_transport(struct iscsi_transport *tt);
  96. /*
  97. * control plane upcalls
  98. */
  99. extern void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error);
  100. extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
  101. char *data, uint32_t data_size);
  102. struct iscsi_cls_conn {
  103. struct list_head conn_list; /* item in connlist */
  104. void *dd_data; /* LLD private data */
  105. struct iscsi_transport *transport;
  106. uint32_t cid; /* connection id */
  107. /* portal/group values we got during discovery */
  108. char *persistent_address;
  109. int persistent_port;
  110. /* portal/group values we are currently using */
  111. char *address;
  112. int port;
  113. int active; /* must be accessed with the connlock */
  114. struct device dev; /* sysfs transport/container device */
  115. struct mempool_zone *z_error;
  116. struct mempool_zone *z_pdu;
  117. struct list_head freequeue;
  118. };
  119. #define iscsi_dev_to_conn(_dev) \
  120. container_of(_dev, struct iscsi_cls_conn, dev)
  121. struct iscsi_cls_session {
  122. struct list_head sess_list; /* item in session_list */
  123. struct iscsi_transport *transport;
  124. /* iSCSI values used as unique id by userspace. */
  125. char *targetname;
  126. int tpgt;
  127. int sid; /* session id */
  128. void *dd_data; /* LLD private data */
  129. struct device dev; /* sysfs transport/container device */
  130. };
  131. #define iscsi_dev_to_session(_dev) \
  132. container_of(_dev, struct iscsi_cls_session, dev)
  133. #define iscsi_session_to_shost(_session) \
  134. dev_to_shost(_session->dev.parent)
  135. /*
  136. * session and connection functions that can be used by HW iSCSI LLDs
  137. */
  138. extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost,
  139. struct iscsi_transport *t);
  140. extern int iscsi_destroy_session(struct iscsi_cls_session *session);
  141. extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess,
  142. uint32_t cid);
  143. extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn);
  144. /*
  145. * session functions used by software iscsi
  146. */
  147. extern struct Scsi_Host *
  148. iscsi_transport_create_session(struct scsi_transport_template *scsit,
  149. struct iscsi_transport *transport);
  150. extern int iscsi_transport_destroy_session(struct Scsi_Host *shost);
  151. #endif