iscsi_if.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. ISCSI_UEVENT_TRANSPORT_EP_CONNECT = UEVENT_BASE + 12,
  41. ISCSI_UEVENT_TRANSPORT_EP_POLL = UEVENT_BASE + 13,
  42. ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT = UEVENT_BASE + 14,
  43. /* up events */
  44. ISCSI_KEVENT_RECV_PDU = KEVENT_BASE + 1,
  45. ISCSI_KEVENT_CONN_ERROR = KEVENT_BASE + 2,
  46. ISCSI_KEVENT_IF_ERROR = KEVENT_BASE + 3,
  47. };
  48. struct iscsi_uevent {
  49. uint32_t type; /* k/u events type */
  50. uint32_t iferror; /* carries interface or resource errors */
  51. uint64_t transport_handle;
  52. union {
  53. /* messages u -> k */
  54. struct msg_create_session {
  55. uint32_t initial_cmdsn;
  56. } c_session;
  57. struct msg_destroy_session {
  58. uint32_t sid;
  59. } d_session;
  60. struct msg_create_conn {
  61. uint32_t sid;
  62. uint32_t cid;
  63. } c_conn;
  64. struct msg_bind_conn {
  65. uint32_t sid;
  66. uint32_t cid;
  67. uint64_t transport_eph;
  68. uint32_t is_leading;
  69. } b_conn;
  70. struct msg_destroy_conn {
  71. uint32_t sid;
  72. uint32_t cid;
  73. } d_conn;
  74. struct msg_send_pdu {
  75. uint32_t sid;
  76. uint32_t cid;
  77. uint32_t hdr_size;
  78. uint32_t data_size;
  79. } send_pdu;
  80. struct msg_set_param {
  81. uint32_t sid;
  82. uint32_t cid;
  83. uint32_t param; /* enum iscsi_param */
  84. uint32_t len;
  85. } set_param;
  86. struct msg_start_conn {
  87. uint32_t sid;
  88. uint32_t cid;
  89. } start_conn;
  90. struct msg_stop_conn {
  91. uint32_t sid;
  92. uint32_t cid;
  93. uint64_t conn_handle;
  94. uint32_t flag;
  95. } stop_conn;
  96. struct msg_get_stats {
  97. uint32_t sid;
  98. uint32_t cid;
  99. } get_stats;
  100. struct msg_transport_connect {
  101. uint32_t non_blocking;
  102. } ep_connect;
  103. struct msg_transport_poll {
  104. uint64_t ep_handle;
  105. uint32_t timeout_ms;
  106. } ep_poll;
  107. struct msg_transport_disconnect {
  108. uint64_t ep_handle;
  109. } ep_disconnect;
  110. } u;
  111. union {
  112. /* messages k -> u */
  113. int retcode;
  114. struct msg_create_session_ret {
  115. uint32_t sid;
  116. uint32_t host_no;
  117. } c_session_ret;
  118. struct msg_create_conn_ret {
  119. uint32_t sid;
  120. uint32_t cid;
  121. } c_conn_ret;
  122. struct msg_recv_req {
  123. uint32_t sid;
  124. uint32_t cid;
  125. uint64_t recv_handle;
  126. } recv_req;
  127. struct msg_conn_error {
  128. uint32_t sid;
  129. uint32_t cid;
  130. uint32_t error; /* enum iscsi_err */
  131. } connerror;
  132. struct msg_transport_connect_ret {
  133. uint64_t handle;
  134. } ep_connect_ret;
  135. } r;
  136. } __attribute__ ((aligned (sizeof(uint64_t))));
  137. /*
  138. * Common error codes
  139. */
  140. enum iscsi_err {
  141. ISCSI_OK = 0,
  142. ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1,
  143. ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2,
  144. ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3,
  145. ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4,
  146. ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5,
  147. ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6,
  148. ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7,
  149. ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8,
  150. ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9,
  151. ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10,
  152. ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11,
  153. ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12,
  154. ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13,
  155. ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14,
  156. ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15,
  157. ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16,
  158. ISCSI_ERR_NO_SCSI_CMD = ISCSI_ERR_BASE + 17,
  159. };
  160. /*
  161. * iSCSI Parameters (RFC3720)
  162. */
  163. enum iscsi_param {
  164. /* passed in using netlink set param */
  165. ISCSI_PARAM_MAX_RECV_DLENGTH,
  166. ISCSI_PARAM_MAX_XMIT_DLENGTH,
  167. ISCSI_PARAM_HDRDGST_EN,
  168. ISCSI_PARAM_DATADGST_EN,
  169. ISCSI_PARAM_INITIAL_R2T_EN,
  170. ISCSI_PARAM_MAX_R2T,
  171. ISCSI_PARAM_IMM_DATA_EN,
  172. ISCSI_PARAM_FIRST_BURST,
  173. ISCSI_PARAM_MAX_BURST,
  174. ISCSI_PARAM_PDU_INORDER_EN,
  175. ISCSI_PARAM_DATASEQ_INORDER_EN,
  176. ISCSI_PARAM_ERL,
  177. ISCSI_PARAM_IFMARKER_EN,
  178. ISCSI_PARAM_OFMARKER_EN,
  179. ISCSI_PARAM_EXP_STATSN,
  180. ISCSI_PARAM_TARGET_NAME,
  181. ISCSI_PARAM_TPGT,
  182. ISCSI_PARAM_PERSISTENT_ADDRESS,
  183. ISCSI_PARAM_PERSISTENT_PORT,
  184. ISCSI_PARAM_SESS_RECOVERY_TMO,
  185. /* pased in through bind conn using transport_fd */
  186. ISCSI_PARAM_CONN_PORT,
  187. ISCSI_PARAM_CONN_ADDRESS,
  188. /* must always be last */
  189. ISCSI_PARAM_MAX,
  190. };
  191. #define ISCSI_MAX_RECV_DLENGTH (1 << ISCSI_PARAM_MAX_RECV_DLENGTH)
  192. #define ISCSI_MAX_XMIT_DLENGTH (1 << ISCSI_PARAM_MAX_XMIT_DLENGTH)
  193. #define ISCSI_HDRDGST_EN (1 << ISCSI_PARAM_HDRDGST_EN)
  194. #define ISCSI_DATADGST_EN (1 << ISCSI_PARAM_DATADGST_EN)
  195. #define ISCSI_INITIAL_R2T_EN (1 << ISCSI_PARAM_INITIAL_R2T_EN)
  196. #define ISCSI_MAX_R2T (1 << ISCSI_PARAM_MAX_R2T)
  197. #define ISCSI_IMM_DATA_EN (1 << ISCSI_PARAM_IMM_DATA_EN)
  198. #define ISCSI_FIRST_BURST (1 << ISCSI_PARAM_FIRST_BURST)
  199. #define ISCSI_MAX_BURST (1 << ISCSI_PARAM_MAX_BURST)
  200. #define ISCSI_PDU_INORDER_EN (1 << ISCSI_PARAM_PDU_INORDER_EN)
  201. #define ISCSI_DATASEQ_INORDER_EN (1 << ISCSI_PARAM_DATASEQ_INORDER_EN)
  202. #define ISCSI_ERL (1 << ISCSI_PARAM_ERL)
  203. #define ISCSI_IFMARKER_EN (1 << ISCSI_PARAM_IFMARKER_EN)
  204. #define ISCSI_OFMARKER_EN (1 << ISCSI_PARAM_OFMARKER_EN)
  205. #define ISCSI_EXP_STATSN (1 << ISCSI_PARAM_EXP_STATSN)
  206. #define ISCSI_TARGET_NAME (1 << ISCSI_PARAM_TARGET_NAME)
  207. #define ISCSI_TPGT (1 << ISCSI_PARAM_TPGT)
  208. #define ISCSI_PERSISTENT_ADDRESS (1 << ISCSI_PARAM_PERSISTENT_ADDRESS)
  209. #define ISCSI_PERSISTENT_PORT (1 << ISCSI_PARAM_PERSISTENT_PORT)
  210. #define ISCSI_SESS_RECOVERY_TMO (1 << ISCSI_PARAM_SESS_RECOVERY_TMO)
  211. #define ISCSI_CONN_PORT (1 << ISCSI_PARAM_CONN_PORT)
  212. #define ISCSI_CONN_ADDRESS (1 << ISCSI_PARAM_CONN_ADDRESS)
  213. #define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
  214. #define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
  215. #define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata))
  216. /**
  217. * iscsi_hostdata - get LLD hostdata from scsi_host
  218. * @_hostdata: pointer to scsi host's hostdata
  219. **/
  220. #define iscsi_hostdata(_hostdata) ((void*)_hostdata + sizeof(unsigned long))
  221. /*
  222. * These flags presents iSCSI Data-Path capabilities.
  223. */
  224. #define CAP_RECOVERY_L0 0x1
  225. #define CAP_RECOVERY_L1 0x2
  226. #define CAP_RECOVERY_L2 0x4
  227. #define CAP_MULTI_R2T 0x8
  228. #define CAP_HDRDGST 0x10
  229. #define CAP_DATADGST 0x20
  230. #define CAP_MULTI_CONN 0x40
  231. #define CAP_TEXT_NEGO 0x80
  232. #define CAP_MARKERS 0x100
  233. /*
  234. * These flags describes reason of stop_conn() call
  235. */
  236. #define STOP_CONN_TERM 0x1
  237. #define STOP_CONN_SUSPEND 0x2
  238. #define STOP_CONN_RECOVER 0x3
  239. #define ISCSI_STATS_CUSTOM_MAX 32
  240. #define ISCSI_STATS_CUSTOM_DESC_MAX 64
  241. struct iscsi_stats_custom {
  242. char desc[ISCSI_STATS_CUSTOM_DESC_MAX];
  243. uint64_t value;
  244. };
  245. /*
  246. * struct iscsi_stats - iSCSI Statistics (iSCSI MIB)
  247. *
  248. * Note: this structure contains counters collected on per-connection basis.
  249. */
  250. struct iscsi_stats {
  251. /* octets */
  252. uint64_t txdata_octets;
  253. uint64_t rxdata_octets;
  254. /* xmit pdus */
  255. uint32_t noptx_pdus;
  256. uint32_t scsicmd_pdus;
  257. uint32_t tmfcmd_pdus;
  258. uint32_t login_pdus;
  259. uint32_t text_pdus;
  260. uint32_t dataout_pdus;
  261. uint32_t logout_pdus;
  262. uint32_t snack_pdus;
  263. /* recv pdus */
  264. uint32_t noprx_pdus;
  265. uint32_t scsirsp_pdus;
  266. uint32_t tmfrsp_pdus;
  267. uint32_t textrsp_pdus;
  268. uint32_t datain_pdus;
  269. uint32_t logoutrsp_pdus;
  270. uint32_t r2t_pdus;
  271. uint32_t async_pdus;
  272. uint32_t rjt_pdus;
  273. /* errors */
  274. uint32_t digest_err;
  275. uint32_t timeout_err;
  276. /*
  277. * iSCSI Custom Statistics support, i.e. Transport could
  278. * extend existing MIB statistics with its own specific statistics
  279. * up to ISCSI_STATS_CUSTOM_MAX
  280. */
  281. uint32_t custom_length;
  282. struct iscsi_stats_custom custom[0]
  283. __attribute__ ((aligned (sizeof(uint64_t))));
  284. };
  285. #endif