iscsi_if.h 13 KB

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