iscsi_if.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * iSCSI User/Kernel Shares (Defines, Constants, Protocol definitions, etc)
  3. *
  4. * Copyright (C) 2005 Dmitry Yusupov
  5. * Copyright (C) 2005 Alex Aizman
  6. * maintained by open-iscsi@googlegroups.com
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published
  10. * by the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * See the file COPYING included with this distribution for more details.
  19. */
  20. #ifndef ISCSI_IF_H
  21. #define ISCSI_IF_H
  22. #include <scsi/iscsi_proto.h>
  23. #define UEVENT_BASE 10
  24. #define KEVENT_BASE 100
  25. #define ISCSI_ERR_BASE 1000
  26. enum iscsi_uevent_e {
  27. ISCSI_UEVENT_UNKNOWN = 0,
  28. /* down events */
  29. ISCSI_UEVENT_CREATE_SESSION = UEVENT_BASE + 1,
  30. ISCSI_UEVENT_DESTROY_SESSION = UEVENT_BASE + 2,
  31. ISCSI_UEVENT_CREATE_CONN = UEVENT_BASE + 3,
  32. ISCSI_UEVENT_DESTROY_CONN = UEVENT_BASE + 4,
  33. ISCSI_UEVENT_BIND_CONN = UEVENT_BASE + 5,
  34. ISCSI_UEVENT_SET_PARAM = UEVENT_BASE + 6,
  35. ISCSI_UEVENT_START_CONN = UEVENT_BASE + 7,
  36. ISCSI_UEVENT_STOP_CONN = UEVENT_BASE + 8,
  37. ISCSI_UEVENT_SEND_PDU = UEVENT_BASE + 9,
  38. ISCSI_UEVENT_GET_STATS = UEVENT_BASE + 10,
  39. ISCSI_UEVENT_GET_PARAM = UEVENT_BASE + 11,
  40. /* up events */
  41. ISCSI_KEVENT_RECV_PDU = KEVENT_BASE + 1,
  42. ISCSI_KEVENT_CONN_ERROR = KEVENT_BASE + 2,
  43. ISCSI_KEVENT_IF_ERROR = KEVENT_BASE + 3,
  44. };
  45. struct iscsi_uevent {
  46. uint32_t type; /* k/u events type */
  47. uint32_t iferror; /* carries interface or resource errors */
  48. uint64_t transport_handle;
  49. union {
  50. /* messages u -> k */
  51. struct msg_create_session {
  52. uint32_t initial_cmdsn;
  53. } c_session;
  54. struct msg_destroy_session {
  55. uint64_t session_handle;
  56. uint32_t sid;
  57. } d_session;
  58. struct msg_create_conn {
  59. uint64_t session_handle;
  60. uint32_t cid;
  61. uint32_t sid;
  62. } c_conn;
  63. struct msg_bind_conn {
  64. uint64_t session_handle;
  65. uint64_t conn_handle;
  66. uint32_t transport_fd;
  67. uint32_t is_leading;
  68. } b_conn;
  69. struct msg_destroy_conn {
  70. uint64_t conn_handle;
  71. uint32_t cid;
  72. } d_conn;
  73. struct msg_send_pdu {
  74. uint32_t hdr_size;
  75. uint32_t data_size;
  76. uint64_t conn_handle;
  77. } send_pdu;
  78. struct msg_set_param {
  79. uint64_t conn_handle;
  80. uint32_t param; /* enum iscsi_param */
  81. uint32_t value;
  82. } set_param;
  83. struct msg_start_conn {
  84. uint64_t conn_handle;
  85. } start_conn;
  86. struct msg_stop_conn {
  87. uint64_t conn_handle;
  88. uint32_t flag;
  89. } stop_conn;
  90. struct msg_get_stats {
  91. uint64_t conn_handle;
  92. } get_stats;
  93. } u;
  94. union {
  95. /* messages k -> u */
  96. uint64_t handle;
  97. int retcode;
  98. struct msg_create_session_ret {
  99. uint64_t session_handle;
  100. uint32_t sid;
  101. } c_session_ret;
  102. struct msg_recv_req {
  103. uint64_t recv_handle;
  104. uint64_t conn_handle;
  105. } recv_req;
  106. struct msg_conn_error {
  107. uint64_t conn_handle;
  108. uint32_t error; /* enum iscsi_err */
  109. } connerror;
  110. } r;
  111. } __attribute__ ((aligned (sizeof(uint64_t))));
  112. /*
  113. * Common error codes
  114. */
  115. enum iscsi_err {
  116. ISCSI_OK = 0,
  117. ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1,
  118. ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2,
  119. ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3,
  120. ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4,
  121. ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5,
  122. ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6,
  123. ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7,
  124. ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8,
  125. ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9,
  126. ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10,
  127. ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11,
  128. ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12,
  129. ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13,
  130. ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14,
  131. ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15,
  132. ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16
  133. };
  134. /*
  135. * iSCSI Parameters (RFC3720)
  136. */
  137. enum iscsi_param {
  138. ISCSI_PARAM_MAX_RECV_DLENGTH = 0,
  139. ISCSI_PARAM_MAX_XMIT_DLENGTH = 1,
  140. ISCSI_PARAM_HDRDGST_EN = 2,
  141. ISCSI_PARAM_DATADGST_EN = 3,
  142. ISCSI_PARAM_INITIAL_R2T_EN = 4,
  143. ISCSI_PARAM_MAX_R2T = 5,
  144. ISCSI_PARAM_IMM_DATA_EN = 6,
  145. ISCSI_PARAM_FIRST_BURST = 7,
  146. ISCSI_PARAM_MAX_BURST = 8,
  147. ISCSI_PARAM_PDU_INORDER_EN = 9,
  148. ISCSI_PARAM_DATASEQ_INORDER_EN = 10,
  149. ISCSI_PARAM_ERL = 11,
  150. ISCSI_PARAM_IFMARKER_EN = 12,
  151. ISCSI_PARAM_OFMARKER_EN = 13,
  152. };
  153. #define ISCSI_PARAM_MAX 14
  154. typedef uint64_t iscsi_sessionh_t; /* iSCSI Data-Path session handle */
  155. typedef uint64_t iscsi_connh_t; /* iSCSI Data-Path connection handle */
  156. #define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
  157. #define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
  158. #define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
  159. /**
  160. * iscsi_hostdata - get LLD hostdata from scsi_host
  161. * @_hostdata: pointer to scsi host's hostdata
  162. **/
  163. #define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long))
  164. /*
  165. * These flags presents iSCSI Data-Path capabilities.
  166. */
  167. #define CAP_RECOVERY_L0 0x1
  168. #define CAP_RECOVERY_L1 0x2
  169. #define CAP_RECOVERY_L2 0x4
  170. #define CAP_MULTI_R2T 0x8
  171. #define CAP_HDRDGST 0x10
  172. #define CAP_DATADGST 0x20
  173. #define CAP_MULTI_CONN 0x40
  174. #define CAP_TEXT_NEGO 0x80
  175. #define CAP_MARKERS 0x100
  176. /*
  177. * These flags describes reason of stop_conn() call
  178. */
  179. #define STOP_CONN_TERM 0x1
  180. #define STOP_CONN_SUSPEND 0x2
  181. #define STOP_CONN_RECOVER 0x3
  182. #define ISCSI_STATS_CUSTOM_MAX 32
  183. #define ISCSI_STATS_CUSTOM_DESC_MAX 64
  184. struct iscsi_stats_custom {
  185. char desc[ISCSI_STATS_CUSTOM_DESC_MAX];
  186. uint64_t value;
  187. };
  188. /*
  189. * struct iscsi_stats - iSCSI Statistics (iSCSI MIB)
  190. *
  191. * Note: this structure contains counters collected on per-connection basis.
  192. */
  193. struct iscsi_stats {
  194. /* octets */
  195. uint64_t txdata_octets;
  196. uint64_t rxdata_octets;
  197. /* xmit pdus */
  198. uint32_t noptx_pdus;
  199. uint32_t scsicmd_pdus;
  200. uint32_t tmfcmd_pdus;
  201. uint32_t login_pdus;
  202. uint32_t text_pdus;
  203. uint32_t dataout_pdus;
  204. uint32_t logout_pdus;
  205. uint32_t snack_pdus;
  206. /* recv pdus */
  207. uint32_t noprx_pdus;
  208. uint32_t scsirsp_pdus;
  209. uint32_t tmfrsp_pdus;
  210. uint32_t textrsp_pdus;
  211. uint32_t datain_pdus;
  212. uint32_t logoutrsp_pdus;
  213. uint32_t r2t_pdus;
  214. uint32_t async_pdus;
  215. uint32_t rjt_pdus;
  216. /* errors */
  217. uint32_t digest_err;
  218. uint32_t timeout_err;
  219. /*
  220. * iSCSI Custom Statistics support, i.e. Transport could
  221. * extend existing MIB statistics with its own specific statistics
  222. * up to ISCSI_STATS_CUSTOM_MAX
  223. */
  224. uint32_t custom_length;
  225. struct iscsi_stats_custom custom[0]
  226. __attribute__ ((aligned (sizeof(uint64_t))));
  227. };
  228. #endif