iscsi_if.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. ISCSI_UEVENT_SET_IFACE_PARAMS = UEVENT_BASE + 21,
  54. /* up events */
  55. ISCSI_KEVENT_RECV_PDU = KEVENT_BASE + 1,
  56. ISCSI_KEVENT_CONN_ERROR = KEVENT_BASE + 2,
  57. ISCSI_KEVENT_IF_ERROR = KEVENT_BASE + 3,
  58. ISCSI_KEVENT_DESTROY_SESSION = KEVENT_BASE + 4,
  59. ISCSI_KEVENT_UNBIND_SESSION = KEVENT_BASE + 5,
  60. ISCSI_KEVENT_CREATE_SESSION = KEVENT_BASE + 6,
  61. ISCSI_KEVENT_PATH_REQ = KEVENT_BASE + 7,
  62. ISCSI_KEVENT_IF_DOWN = KEVENT_BASE + 8,
  63. ISCSI_KEVENT_CONN_LOGIN_STATE = KEVENT_BASE + 9,
  64. };
  65. enum iscsi_tgt_dscvr {
  66. ISCSI_TGT_DSCVR_SEND_TARGETS = 1,
  67. ISCSI_TGT_DSCVR_ISNS = 2,
  68. ISCSI_TGT_DSCVR_SLP = 3,
  69. };
  70. struct iscsi_uevent {
  71. uint32_t type; /* k/u events type */
  72. uint32_t iferror; /* carries interface or resource errors */
  73. uint64_t transport_handle;
  74. union {
  75. /* messages u -> k */
  76. struct msg_create_session {
  77. uint32_t initial_cmdsn;
  78. uint16_t cmds_max;
  79. uint16_t queue_depth;
  80. } c_session;
  81. struct msg_create_bound_session {
  82. uint64_t ep_handle;
  83. uint32_t initial_cmdsn;
  84. uint16_t cmds_max;
  85. uint16_t queue_depth;
  86. } c_bound_session;
  87. struct msg_destroy_session {
  88. uint32_t sid;
  89. } d_session;
  90. struct msg_create_conn {
  91. uint32_t sid;
  92. uint32_t cid;
  93. } c_conn;
  94. struct msg_bind_conn {
  95. uint32_t sid;
  96. uint32_t cid;
  97. uint64_t transport_eph;
  98. uint32_t is_leading;
  99. } b_conn;
  100. struct msg_destroy_conn {
  101. uint32_t sid;
  102. uint32_t cid;
  103. } d_conn;
  104. struct msg_send_pdu {
  105. uint32_t sid;
  106. uint32_t cid;
  107. uint32_t hdr_size;
  108. uint32_t data_size;
  109. } send_pdu;
  110. struct msg_set_param {
  111. uint32_t sid;
  112. uint32_t cid;
  113. uint32_t param; /* enum iscsi_param */
  114. uint32_t len;
  115. } set_param;
  116. struct msg_start_conn {
  117. uint32_t sid;
  118. uint32_t cid;
  119. } start_conn;
  120. struct msg_stop_conn {
  121. uint32_t sid;
  122. uint32_t cid;
  123. uint64_t conn_handle;
  124. uint32_t flag;
  125. } stop_conn;
  126. struct msg_get_stats {
  127. uint32_t sid;
  128. uint32_t cid;
  129. } get_stats;
  130. struct msg_transport_connect {
  131. uint32_t non_blocking;
  132. } ep_connect;
  133. struct msg_transport_connect_through_host {
  134. uint32_t host_no;
  135. uint32_t non_blocking;
  136. } ep_connect_through_host;
  137. struct msg_transport_poll {
  138. uint64_t ep_handle;
  139. uint32_t timeout_ms;
  140. } ep_poll;
  141. struct msg_transport_disconnect {
  142. uint64_t ep_handle;
  143. } ep_disconnect;
  144. struct msg_tgt_dscvr {
  145. enum iscsi_tgt_dscvr type;
  146. uint32_t host_no;
  147. /*
  148. * enable = 1 to establish a new connection
  149. * with the server. enable = 0 to disconnect
  150. * from the server. Used primarily to switch
  151. * from one iSNS server to another.
  152. */
  153. uint32_t enable;
  154. } tgt_dscvr;
  155. struct msg_set_host_param {
  156. uint32_t host_no;
  157. uint32_t param; /* enum iscsi_host_param */
  158. uint32_t len;
  159. } set_host_param;
  160. struct msg_set_path {
  161. uint32_t host_no;
  162. } set_path;
  163. struct msg_set_iface_params {
  164. uint32_t host_no;
  165. uint32_t count;
  166. } set_iface_params;
  167. } u;
  168. union {
  169. /* messages k -> u */
  170. int retcode;
  171. struct msg_create_session_ret {
  172. uint32_t sid;
  173. uint32_t host_no;
  174. } c_session_ret;
  175. struct msg_create_conn_ret {
  176. uint32_t sid;
  177. uint32_t cid;
  178. } c_conn_ret;
  179. struct msg_unbind_session {
  180. uint32_t sid;
  181. uint32_t host_no;
  182. } unbind_session;
  183. struct msg_recv_req {
  184. uint32_t sid;
  185. uint32_t cid;
  186. uint64_t recv_handle;
  187. } recv_req;
  188. struct msg_conn_login {
  189. uint32_t sid;
  190. uint32_t cid;
  191. uint32_t state; /* enum iscsi_conn_state */
  192. } conn_login;
  193. struct msg_conn_error {
  194. uint32_t sid;
  195. uint32_t cid;
  196. uint32_t error; /* enum iscsi_err */
  197. } connerror;
  198. struct msg_session_destroyed {
  199. uint32_t host_no;
  200. uint32_t sid;
  201. } d_session;
  202. struct msg_transport_connect_ret {
  203. uint64_t handle;
  204. } ep_connect_ret;
  205. struct msg_req_path {
  206. uint32_t host_no;
  207. } req_path;
  208. struct msg_notify_if_down {
  209. uint32_t host_no;
  210. } notify_if_down;
  211. } r;
  212. } __attribute__ ((aligned (sizeof(uint64_t))));
  213. enum iscsi_param_type {
  214. ISCSI_PARAM, /* iscsi_param (session, conn, target, LU) */
  215. ISCSI_HOST_PARAM, /* iscsi_host_param */
  216. ISCSI_NET_PARAM, /* iscsi_net_param */
  217. };
  218. struct iscsi_iface_param_info {
  219. uint32_t iface_num; /* iface number, 0 - n */
  220. uint32_t len; /* Actual length of the param */
  221. uint16_t param; /* iscsi param value */
  222. uint8_t iface_type; /* IPv4 or IPv6 */
  223. uint8_t param_type; /* iscsi_param_type */
  224. uint8_t value[0]; /* length sized value follows */
  225. } __packed;
  226. /*
  227. * To keep the struct iscsi_uevent size the same for userspace code
  228. * compatibility, the main structure for ISCSI_UEVENT_PATH_UPDATE and
  229. * ISCSI_KEVENT_PATH_REQ is defined separately and comes after the
  230. * struct iscsi_uevent in the NETLINK_ISCSI message.
  231. */
  232. struct iscsi_path {
  233. uint64_t handle;
  234. uint8_t mac_addr[6];
  235. uint8_t mac_addr_old[6];
  236. uint32_t ip_addr_len; /* 4 or 16 */
  237. union {
  238. struct in_addr v4_addr;
  239. struct in6_addr v6_addr;
  240. } src;
  241. union {
  242. struct in_addr v4_addr;
  243. struct in6_addr v6_addr;
  244. } dst;
  245. uint16_t vlan_id;
  246. uint16_t pmtu;
  247. } __attribute__ ((aligned (sizeof(uint64_t))));
  248. /* iscsi iface enabled/disabled setting */
  249. #define ISCSI_IFACE_DISABLE 0x01
  250. #define ISCSI_IFACE_ENABLE 0x02
  251. /* ipv4 bootproto */
  252. #define ISCSI_BOOTPROTO_STATIC 0x01
  253. #define ISCSI_BOOTPROTO_DHCP 0x02
  254. /* ipv6 addr autoconfig type */
  255. #define ISCSI_IPV6_AUTOCFG_DISABLE 0x01
  256. #define ISCSI_IPV6_AUTOCFG_ND_ENABLE 0x02
  257. #define ISCSI_IPV6_AUTOCFG_DHCPV6_ENABLE 0x03
  258. /* ipv6 link local addr type */
  259. #define ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE 0x01
  260. #define ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE 0x02
  261. /* ipv6 router addr type */
  262. #define ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE 0x01
  263. #define ISCSI_IPV6_ROUTER_AUTOCFG_DISABLE 0x02
  264. #define ISCSI_IFACE_TYPE_IPV4 0x01
  265. #define ISCSI_IFACE_TYPE_IPV6 0x02
  266. #define ISCSI_MAX_VLAN_ID 4095
  267. #define ISCSI_MAX_VLAN_PRIORITY 7
  268. /* iscsi vlan enable/disabled setting */
  269. #define ISCSI_VLAN_DISABLE 0x01
  270. #define ISCSI_VLAN_ENABLE 0x02
  271. /* iSCSI network params */
  272. enum iscsi_net_param {
  273. ISCSI_NET_PARAM_IPV4_ADDR = 1,
  274. ISCSI_NET_PARAM_IPV4_SUBNET = 2,
  275. ISCSI_NET_PARAM_IPV4_GW = 3,
  276. ISCSI_NET_PARAM_IPV4_BOOTPROTO = 4,
  277. ISCSI_NET_PARAM_MAC = 5,
  278. ISCSI_NET_PARAM_IPV6_LINKLOCAL = 6,
  279. ISCSI_NET_PARAM_IPV6_ADDR = 7,
  280. ISCSI_NET_PARAM_IPV6_ROUTER = 8,
  281. ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG = 9,
  282. ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG = 10,
  283. ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG = 11,
  284. ISCSI_NET_PARAM_IFACE_ENABLE = 12,
  285. ISCSI_NET_PARAM_VLAN_ID = 13,
  286. ISCSI_NET_PARAM_VLAN_PRIORITY = 14,
  287. ISCSI_NET_PARAM_VLAN_ENABLED = 15,
  288. ISCSI_NET_PARAM_VLAN_TAG = 16,
  289. ISCSI_NET_PARAM_IFACE_TYPE = 17,
  290. ISCSI_NET_PARAM_IFACE_NAME = 18,
  291. ISCSI_NET_PARAM_MTU = 19,
  292. ISCSI_NET_PARAM_PORT = 20,
  293. };
  294. enum iscsi_conn_state {
  295. ISCSI_CONN_STATE_FREE,
  296. ISCSI_CONN_STATE_XPT_WAIT,
  297. ISCSI_CONN_STATE_IN_LOGIN,
  298. ISCSI_CONN_STATE_LOGGED_IN,
  299. ISCSI_CONN_STATE_IN_LOGOUT,
  300. ISCSI_CONN_STATE_LOGOUT_REQUESTED,
  301. ISCSI_CONN_STATE_CLEANUP_WAIT,
  302. };
  303. /*
  304. * Common error codes
  305. */
  306. enum iscsi_err {
  307. ISCSI_OK = 0,
  308. ISCSI_ERR_DATASN = ISCSI_ERR_BASE + 1,
  309. ISCSI_ERR_DATA_OFFSET = ISCSI_ERR_BASE + 2,
  310. ISCSI_ERR_MAX_CMDSN = ISCSI_ERR_BASE + 3,
  311. ISCSI_ERR_EXP_CMDSN = ISCSI_ERR_BASE + 4,
  312. ISCSI_ERR_BAD_OPCODE = ISCSI_ERR_BASE + 5,
  313. ISCSI_ERR_DATALEN = ISCSI_ERR_BASE + 6,
  314. ISCSI_ERR_AHSLEN = ISCSI_ERR_BASE + 7,
  315. ISCSI_ERR_PROTO = ISCSI_ERR_BASE + 8,
  316. ISCSI_ERR_LUN = ISCSI_ERR_BASE + 9,
  317. ISCSI_ERR_BAD_ITT = ISCSI_ERR_BASE + 10,
  318. ISCSI_ERR_CONN_FAILED = ISCSI_ERR_BASE + 11,
  319. ISCSI_ERR_R2TSN = ISCSI_ERR_BASE + 12,
  320. ISCSI_ERR_SESSION_FAILED = ISCSI_ERR_BASE + 13,
  321. ISCSI_ERR_HDR_DGST = ISCSI_ERR_BASE + 14,
  322. ISCSI_ERR_DATA_DGST = ISCSI_ERR_BASE + 15,
  323. ISCSI_ERR_PARAM_NOT_FOUND = ISCSI_ERR_BASE + 16,
  324. ISCSI_ERR_NO_SCSI_CMD = ISCSI_ERR_BASE + 17,
  325. ISCSI_ERR_INVALID_HOST = ISCSI_ERR_BASE + 18,
  326. ISCSI_ERR_XMIT_FAILED = ISCSI_ERR_BASE + 19,
  327. ISCSI_ERR_TCP_CONN_CLOSE = ISCSI_ERR_BASE + 20,
  328. ISCSI_ERR_SCSI_EH_SESSION_RST = ISCSI_ERR_BASE + 21,
  329. };
  330. /*
  331. * iSCSI Parameters (RFC3720)
  332. */
  333. enum iscsi_param {
  334. /* passed in using netlink set param */
  335. ISCSI_PARAM_MAX_RECV_DLENGTH,
  336. ISCSI_PARAM_MAX_XMIT_DLENGTH,
  337. ISCSI_PARAM_HDRDGST_EN,
  338. ISCSI_PARAM_DATADGST_EN,
  339. ISCSI_PARAM_INITIAL_R2T_EN,
  340. ISCSI_PARAM_MAX_R2T,
  341. ISCSI_PARAM_IMM_DATA_EN,
  342. ISCSI_PARAM_FIRST_BURST,
  343. ISCSI_PARAM_MAX_BURST,
  344. ISCSI_PARAM_PDU_INORDER_EN,
  345. ISCSI_PARAM_DATASEQ_INORDER_EN,
  346. ISCSI_PARAM_ERL,
  347. ISCSI_PARAM_IFMARKER_EN,
  348. ISCSI_PARAM_OFMARKER_EN,
  349. ISCSI_PARAM_EXP_STATSN,
  350. ISCSI_PARAM_TARGET_NAME,
  351. ISCSI_PARAM_TPGT,
  352. ISCSI_PARAM_PERSISTENT_ADDRESS,
  353. ISCSI_PARAM_PERSISTENT_PORT,
  354. ISCSI_PARAM_SESS_RECOVERY_TMO,
  355. /* passed in through bind conn using transport_fd */
  356. ISCSI_PARAM_CONN_PORT,
  357. ISCSI_PARAM_CONN_ADDRESS,
  358. ISCSI_PARAM_USERNAME,
  359. ISCSI_PARAM_USERNAME_IN,
  360. ISCSI_PARAM_PASSWORD,
  361. ISCSI_PARAM_PASSWORD_IN,
  362. ISCSI_PARAM_FAST_ABORT,
  363. ISCSI_PARAM_ABORT_TMO,
  364. ISCSI_PARAM_LU_RESET_TMO,
  365. ISCSI_PARAM_HOST_RESET_TMO,
  366. ISCSI_PARAM_PING_TMO,
  367. ISCSI_PARAM_RECV_TMO,
  368. ISCSI_PARAM_IFACE_NAME,
  369. ISCSI_PARAM_ISID,
  370. ISCSI_PARAM_INITIATOR_NAME,
  371. ISCSI_PARAM_TGT_RESET_TMO,
  372. ISCSI_PARAM_TARGET_ALIAS,
  373. /* must always be last */
  374. ISCSI_PARAM_MAX,
  375. };
  376. /* iSCSI HBA params */
  377. enum iscsi_host_param {
  378. ISCSI_HOST_PARAM_HWADDRESS,
  379. ISCSI_HOST_PARAM_INITIATOR_NAME,
  380. ISCSI_HOST_PARAM_NETDEV_NAME,
  381. ISCSI_HOST_PARAM_IPADDRESS,
  382. ISCSI_HOST_PARAM_MAX,
  383. };
  384. #define iscsi_ptr(_handle) ((void*)(unsigned long)_handle)
  385. #define iscsi_handle(_ptr) ((uint64_t)(unsigned long)_ptr)
  386. /*
  387. * These flags presents iSCSI Data-Path capabilities.
  388. */
  389. #define CAP_RECOVERY_L0 0x1
  390. #define CAP_RECOVERY_L1 0x2
  391. #define CAP_RECOVERY_L2 0x4
  392. #define CAP_MULTI_R2T 0x8
  393. #define CAP_HDRDGST 0x10
  394. #define CAP_DATADGST 0x20
  395. #define CAP_MULTI_CONN 0x40
  396. #define CAP_TEXT_NEGO 0x80
  397. #define CAP_MARKERS 0x100
  398. #define CAP_FW_DB 0x200
  399. #define CAP_SENDTARGETS_OFFLOAD 0x400 /* offload discovery process */
  400. #define CAP_DATA_PATH_OFFLOAD 0x800 /* offload entire IO path */
  401. #define CAP_DIGEST_OFFLOAD 0x1000 /* offload hdr and data digests */
  402. #define CAP_PADDING_OFFLOAD 0x2000 /* offload padding insertion, removal,
  403. and verification */
  404. #define CAP_LOGIN_OFFLOAD 0x4000 /* offload session login */
  405. /*
  406. * These flags describes reason of stop_conn() call
  407. */
  408. #define STOP_CONN_TERM 0x1
  409. #define STOP_CONN_SUSPEND 0x2
  410. #define STOP_CONN_RECOVER 0x3
  411. #define ISCSI_STATS_CUSTOM_MAX 32
  412. #define ISCSI_STATS_CUSTOM_DESC_MAX 64
  413. struct iscsi_stats_custom {
  414. char desc[ISCSI_STATS_CUSTOM_DESC_MAX];
  415. uint64_t value;
  416. };
  417. /*
  418. * struct iscsi_stats - iSCSI Statistics (iSCSI MIB)
  419. *
  420. * Note: this structure contains counters collected on per-connection basis.
  421. */
  422. struct iscsi_stats {
  423. /* octets */
  424. uint64_t txdata_octets;
  425. uint64_t rxdata_octets;
  426. /* xmit pdus */
  427. uint32_t noptx_pdus;
  428. uint32_t scsicmd_pdus;
  429. uint32_t tmfcmd_pdus;
  430. uint32_t login_pdus;
  431. uint32_t text_pdus;
  432. uint32_t dataout_pdus;
  433. uint32_t logout_pdus;
  434. uint32_t snack_pdus;
  435. /* recv pdus */
  436. uint32_t noprx_pdus;
  437. uint32_t scsirsp_pdus;
  438. uint32_t tmfrsp_pdus;
  439. uint32_t textrsp_pdus;
  440. uint32_t datain_pdus;
  441. uint32_t logoutrsp_pdus;
  442. uint32_t r2t_pdus;
  443. uint32_t async_pdus;
  444. uint32_t rjt_pdus;
  445. /* errors */
  446. uint32_t digest_err;
  447. uint32_t timeout_err;
  448. /*
  449. * iSCSI Custom Statistics support, i.e. Transport could
  450. * extend existing MIB statistics with its own specific statistics
  451. * up to ISCSI_STATS_CUSTOM_MAX
  452. */
  453. uint32_t custom_length;
  454. struct iscsi_stats_custom custom[0]
  455. __attribute__ ((aligned (sizeof(uint64_t))));
  456. };
  457. #endif