iscsi_if.h 7.9 KB

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