iscsi_if.h 9.5 KB

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