iscsi_if.h 11 KB

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