scsi_transport_iscsi.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * iSCSI transport class definitions
  3. *
  4. * Copyright (C) IBM Corporation, 2004
  5. * Copyright (C) Mike Christie, 2004 - 2006
  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 iscsi_transport;
  29. struct Scsi_Host;
  30. struct mempool_zone;
  31. struct iscsi_cls_conn;
  32. struct iscsi_conn;
  33. struct iscsi_cmd_task;
  34. struct iscsi_mgmt_task;
  35. /**
  36. * struct iscsi_transport - iSCSI Transport template
  37. *
  38. * @name: transport name
  39. * @caps: iSCSI Data-Path capabilities
  40. * @create_session: create new iSCSI session object
  41. * @destroy_session: destroy existing iSCSI session object
  42. * @create_conn: create new iSCSI connection
  43. * @bind_conn: associate this connection with existing iSCSI session
  44. * and specified transport descriptor
  45. * @destroy_conn: destroy inactive iSCSI connection
  46. * @set_param: set iSCSI Data-Path operational parameter
  47. * @start_conn: set connection to be operational
  48. * @stop_conn: suspend/recover/terminate connection
  49. * @send_pdu: send iSCSI PDU, Login, Logout, NOP-Out, Reject, Text.
  50. * @session_recovery_timedout: notify LLD a block during recovery timed out
  51. * @suspend_conn_recv: susepend the recv side of the connection
  52. * @termincate_conn: destroy socket connection. Called with mutex lock.
  53. * @init_cmd_task: Initialize a iscsi_cmd_task and any internal structs.
  54. * Called from queuecommand with session lock held.
  55. * @init_mgmt_task: Initialize a iscsi_mgmt_task and any internal structs.
  56. * Called from iscsi_conn_send_generic with xmitmutex.
  57. * @xmit_cmd_task: requests LLD to transfer cmd task
  58. * @xmit_mgmt_task: requests LLD to transfer mgmt task
  59. * @cleanup_cmd_task: requests LLD to fail cmd task. Called with xmitmutex
  60. * and session->lock after the connection has been
  61. * suspended and terminated during recovery. If called
  62. * from abort task then connection is not suspended
  63. * or terminated but sk_callback_lock is held
  64. *
  65. * Template API provided by iSCSI Transport
  66. */
  67. struct iscsi_transport {
  68. struct module *owner;
  69. char *name;
  70. unsigned int caps;
  71. /* LLD sets this to indicate what values it can export to sysfs */
  72. unsigned int param_mask;
  73. struct scsi_host_template *host_template;
  74. /* LLD connection data size */
  75. int conndata_size;
  76. /* LLD session data size */
  77. int sessiondata_size;
  78. int max_lun;
  79. unsigned int max_conn;
  80. unsigned int max_cmd_len;
  81. struct iscsi_cls_session *(*create_session) (struct iscsi_transport *it,
  82. struct scsi_transport_template *t, uint32_t sn, uint32_t *hn);
  83. void (*destroy_session) (struct iscsi_cls_session *session);
  84. struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,
  85. uint32_t cid);
  86. int (*bind_conn) (struct iscsi_cls_session *session,
  87. struct iscsi_cls_conn *cls_conn,
  88. uint32_t transport_fd, int is_leading);
  89. int (*start_conn) (struct iscsi_cls_conn *conn);
  90. void (*stop_conn) (struct iscsi_cls_conn *conn, int flag);
  91. void (*destroy_conn) (struct iscsi_cls_conn *conn);
  92. int (*set_param) (struct iscsi_cls_conn *conn, enum iscsi_param param,
  93. uint32_t value);
  94. int (*get_conn_param) (struct iscsi_cls_conn *conn,
  95. enum iscsi_param param, uint32_t *value);
  96. int (*get_session_param) (struct iscsi_cls_session *session,
  97. enum iscsi_param param, uint32_t *value);
  98. int (*get_conn_str_param) (struct iscsi_cls_conn *conn,
  99. enum iscsi_param param, char *buf);
  100. int (*get_session_str_param) (struct iscsi_cls_session *session,
  101. enum iscsi_param param, char *buf);
  102. int (*send_pdu) (struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
  103. char *data, uint32_t data_size);
  104. void (*get_stats) (struct iscsi_cls_conn *conn,
  105. struct iscsi_stats *stats);
  106. void (*suspend_conn_recv) (struct iscsi_conn *conn);
  107. void (*terminate_conn) (struct iscsi_conn *conn);
  108. void (*init_cmd_task) (struct iscsi_cmd_task *ctask);
  109. void (*init_mgmt_task) (struct iscsi_conn *conn,
  110. struct iscsi_mgmt_task *mtask,
  111. char *data, uint32_t data_size);
  112. int (*xmit_cmd_task) (struct iscsi_conn *conn,
  113. struct iscsi_cmd_task *ctask);
  114. void (*cleanup_cmd_task) (struct iscsi_conn *conn,
  115. struct iscsi_cmd_task *ctask);
  116. int (*xmit_mgmt_task) (struct iscsi_conn *conn,
  117. struct iscsi_mgmt_task *mtask);
  118. void (*session_recovery_timedout) (struct iscsi_cls_session *session);
  119. };
  120. /*
  121. * transport registration upcalls
  122. */
  123. extern struct scsi_transport_template *iscsi_register_transport(struct iscsi_transport *tt);
  124. extern int iscsi_unregister_transport(struct iscsi_transport *tt);
  125. /*
  126. * control plane upcalls
  127. */
  128. extern void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error);
  129. extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
  130. char *data, uint32_t data_size);
  131. /* Connection's states */
  132. #define ISCSI_CONN_INITIAL_STAGE 0
  133. #define ISCSI_CONN_STARTED 1
  134. #define ISCSI_CONN_STOPPED 2
  135. #define ISCSI_CONN_CLEANUP_WAIT 3
  136. struct iscsi_cls_conn {
  137. struct list_head conn_list; /* item in connlist */
  138. void *dd_data; /* LLD private data */
  139. struct iscsi_transport *transport;
  140. uint32_t cid; /* connection id */
  141. /* portal/group values we got during discovery */
  142. char *persistent_address;
  143. int persistent_port;
  144. /* portal/group values we are currently using */
  145. char *address;
  146. int port;
  147. int active; /* must be accessed with the connlock */
  148. struct device dev; /* sysfs transport/container device */
  149. struct mempool_zone *z_error;
  150. struct mempool_zone *z_pdu;
  151. struct list_head freequeue;
  152. };
  153. #define iscsi_dev_to_conn(_dev) \
  154. container_of(_dev, struct iscsi_cls_conn, dev)
  155. /* Session's states */
  156. #define ISCSI_STATE_FREE 1
  157. #define ISCSI_STATE_LOGGED_IN 2
  158. #define ISCSI_STATE_FAILED 3
  159. #define ISCSI_STATE_TERMINATE 4
  160. struct iscsi_cls_session {
  161. struct list_head sess_list; /* item in session_list */
  162. struct list_head host_list;
  163. struct iscsi_transport *transport;
  164. /* iSCSI values used as unique id by userspace. */
  165. char *targetname;
  166. int tpgt;
  167. /* recovery fields */
  168. int recovery_tmo;
  169. struct work_struct recovery_work;
  170. int target_id;
  171. int channel;
  172. int sid; /* session id */
  173. void *dd_data; /* LLD private data */
  174. struct device dev; /* sysfs transport/container device */
  175. };
  176. #define iscsi_dev_to_session(_dev) \
  177. container_of(_dev, struct iscsi_cls_session, dev)
  178. #define iscsi_session_to_shost(_session) \
  179. dev_to_shost(_session->dev.parent)
  180. struct iscsi_host {
  181. int next_target_id;
  182. struct list_head sessions;
  183. struct mutex mutex;
  184. };
  185. /*
  186. * session and connection functions that can be used by HW iSCSI LLDs
  187. */
  188. extern struct iscsi_cls_session *iscsi_create_session(struct Scsi_Host *shost,
  189. struct iscsi_transport *t, int channel);
  190. extern int iscsi_destroy_session(struct iscsi_cls_session *session);
  191. extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess,
  192. uint32_t cid);
  193. extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn);
  194. extern void iscsi_unblock_session(struct iscsi_cls_session *session);
  195. extern void iscsi_block_session(struct iscsi_cls_session *session);
  196. #endif