iscsi_proto.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * RFC 3720 (iSCSI) protocol data types
  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_PROTO_H
  21. #define ISCSI_PROTO_H
  22. #include <linux/types.h>
  23. #include <scsi/scsi.h>
  24. #define ISCSI_DRAFT20_VERSION 0x00
  25. /* default iSCSI listen port for incoming connections */
  26. #define ISCSI_LISTEN_PORT 3260
  27. /* iSCSI header length */
  28. #define ISCSI_HDR_LEN 48
  29. /* iSCSI CRC32C length */
  30. #define ISCSI_CRC_LEN 4
  31. /* Padding word length */
  32. #define ISCSI_PAD_LEN 4
  33. /*
  34. * Serial Number Arithmetic, 32 bits, RFC1982
  35. */
  36. static inline int iscsi_sna_lt(u32 n1, u32 n2)
  37. {
  38. return (s32)(n1 - n2) < 0;
  39. }
  40. static inline int iscsi_sna_lte(u32 n1, u32 n2)
  41. {
  42. return (s32)(n1 - n2) <= 0;
  43. }
  44. static inline int iscsi_sna_gt(u32 n1, u32 n2)
  45. {
  46. return (s32)(n1 - n2) > 0;
  47. }
  48. static inline int iscsi_sna_gte(u32 n1, u32 n2)
  49. {
  50. return (s32)(n1 - n2) >= 0;
  51. }
  52. /*
  53. * useful common(control and data pathes) macro
  54. */
  55. #define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
  56. #define hton24(p, v) { \
  57. p[0] = (((v) >> 16) & 0xFF); \
  58. p[1] = (((v) >> 8) & 0xFF); \
  59. p[2] = ((v) & 0xFF); \
  60. }
  61. #define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
  62. /* initiator tags; opaque for target */
  63. typedef uint32_t __bitwise__ itt_t;
  64. /* below makes sense only for initiator that created this tag */
  65. #define build_itt(itt, age) ((__force itt_t)\
  66. ((itt) | ((age) << ISCSI_AGE_SHIFT)))
  67. #define get_itt(itt) ((__force uint32_t)(itt_t)(itt) & ISCSI_ITT_MASK)
  68. #define RESERVED_ITT ((__force itt_t)0xffffffff)
  69. /*
  70. * iSCSI Template Message Header
  71. */
  72. struct iscsi_hdr {
  73. uint8_t opcode;
  74. uint8_t flags; /* Final bit */
  75. uint8_t rsvd2[2];
  76. uint8_t hlength; /* AHSs total length */
  77. uint8_t dlength[3]; /* Data length */
  78. struct scsi_lun lun;
  79. itt_t itt; /* Initiator Task Tag, opaque for target */
  80. __be32 ttt; /* Target Task Tag */
  81. __be32 statsn;
  82. __be32 exp_statsn;
  83. __be32 max_statsn;
  84. uint8_t other[12];
  85. };
  86. /************************* RFC 3720 Begin *****************************/
  87. #define ISCSI_RESERVED_TAG 0xffffffff
  88. /* Opcode encoding bits */
  89. #define ISCSI_OP_RETRY 0x80
  90. #define ISCSI_OP_IMMEDIATE 0x40
  91. #define ISCSI_OPCODE_MASK 0x3F
  92. /* Initiator Opcode values */
  93. #define ISCSI_OP_NOOP_OUT 0x00
  94. #define ISCSI_OP_SCSI_CMD 0x01
  95. #define ISCSI_OP_SCSI_TMFUNC 0x02
  96. #define ISCSI_OP_LOGIN 0x03
  97. #define ISCSI_OP_TEXT 0x04
  98. #define ISCSI_OP_SCSI_DATA_OUT 0x05
  99. #define ISCSI_OP_LOGOUT 0x06
  100. #define ISCSI_OP_SNACK 0x10
  101. #define ISCSI_OP_VENDOR1_CMD 0x1c
  102. #define ISCSI_OP_VENDOR2_CMD 0x1d
  103. #define ISCSI_OP_VENDOR3_CMD 0x1e
  104. #define ISCSI_OP_VENDOR4_CMD 0x1f
  105. /* Target Opcode values */
  106. #define ISCSI_OP_NOOP_IN 0x20
  107. #define ISCSI_OP_SCSI_CMD_RSP 0x21
  108. #define ISCSI_OP_SCSI_TMFUNC_RSP 0x22
  109. #define ISCSI_OP_LOGIN_RSP 0x23
  110. #define ISCSI_OP_TEXT_RSP 0x24
  111. #define ISCSI_OP_SCSI_DATA_IN 0x25
  112. #define ISCSI_OP_LOGOUT_RSP 0x26
  113. #define ISCSI_OP_R2T 0x31
  114. #define ISCSI_OP_ASYNC_EVENT 0x32
  115. #define ISCSI_OP_REJECT 0x3f
  116. struct iscsi_ahs_hdr {
  117. __be16 ahslength;
  118. uint8_t ahstype;
  119. uint8_t ahspec[5];
  120. };
  121. #define ISCSI_AHSTYPE_CDB 1
  122. #define ISCSI_AHSTYPE_RLENGTH 2
  123. #define ISCSI_CDB_SIZE 16
  124. /* iSCSI PDU Header */
  125. struct iscsi_scsi_req {
  126. uint8_t opcode;
  127. uint8_t flags;
  128. __be16 rsvd2;
  129. uint8_t hlength;
  130. uint8_t dlength[3];
  131. struct scsi_lun lun;
  132. itt_t itt; /* Initiator Task Tag */
  133. __be32 data_length;
  134. __be32 cmdsn;
  135. __be32 exp_statsn;
  136. uint8_t cdb[ISCSI_CDB_SIZE]; /* SCSI Command Block */
  137. /* Additional Data (Command Dependent) */
  138. };
  139. /* Command PDU flags */
  140. #define ISCSI_FLAG_CMD_FINAL 0x80
  141. #define ISCSI_FLAG_CMD_READ 0x40
  142. #define ISCSI_FLAG_CMD_WRITE 0x20
  143. #define ISCSI_FLAG_CMD_ATTR_MASK 0x07 /* 3 bits */
  144. /* SCSI Command Attribute values */
  145. #define ISCSI_ATTR_UNTAGGED 0
  146. #define ISCSI_ATTR_SIMPLE 1
  147. #define ISCSI_ATTR_ORDERED 2
  148. #define ISCSI_ATTR_HEAD_OF_QUEUE 3
  149. #define ISCSI_ATTR_ACA 4
  150. struct iscsi_rlength_ahdr {
  151. __be16 ahslength;
  152. uint8_t ahstype;
  153. uint8_t reserved;
  154. __be32 read_length;
  155. };
  156. /* Extended CDB AHS */
  157. struct iscsi_ecdb_ahdr {
  158. __be16 ahslength; /* CDB length - 15, including reserved byte */
  159. uint8_t ahstype;
  160. uint8_t reserved;
  161. /* 4-byte aligned extended CDB spillover */
  162. uint8_t ecdb[SCSI_MAX_VARLEN_CDB_SIZE - ISCSI_CDB_SIZE];
  163. };
  164. /* SCSI Response Header */
  165. struct iscsi_scsi_rsp {
  166. uint8_t opcode;
  167. uint8_t flags;
  168. uint8_t response;
  169. uint8_t cmd_status;
  170. uint8_t hlength;
  171. uint8_t dlength[3];
  172. uint8_t rsvd[8];
  173. itt_t itt; /* Initiator Task Tag */
  174. __be32 rsvd1;
  175. __be32 statsn;
  176. __be32 exp_cmdsn;
  177. __be32 max_cmdsn;
  178. __be32 exp_datasn;
  179. __be32 bi_residual_count;
  180. __be32 residual_count;
  181. /* Response or Sense Data (optional) */
  182. };
  183. /* Command Response PDU flags */
  184. #define ISCSI_FLAG_CMD_BIDI_OVERFLOW 0x10
  185. #define ISCSI_FLAG_CMD_BIDI_UNDERFLOW 0x08
  186. #define ISCSI_FLAG_CMD_OVERFLOW 0x04
  187. #define ISCSI_FLAG_CMD_UNDERFLOW 0x02
  188. /* iSCSI Status values. Valid if Rsp Selector bit is not set */
  189. #define ISCSI_STATUS_CMD_COMPLETED 0
  190. #define ISCSI_STATUS_TARGET_FAILURE 1
  191. #define ISCSI_STATUS_SUBSYS_FAILURE 2
  192. /* Asynchronous Event Header */
  193. struct iscsi_async {
  194. uint8_t opcode;
  195. uint8_t flags;
  196. uint8_t rsvd2[2];
  197. uint8_t rsvd3;
  198. uint8_t dlength[3];
  199. struct scsi_lun lun;
  200. uint8_t rsvd4[8];
  201. __be32 statsn;
  202. __be32 exp_cmdsn;
  203. __be32 max_cmdsn;
  204. uint8_t async_event;
  205. uint8_t async_vcode;
  206. __be16 param1;
  207. __be16 param2;
  208. __be16 param3;
  209. uint8_t rsvd5[4];
  210. };
  211. /* iSCSI Event Codes */
  212. #define ISCSI_ASYNC_MSG_SCSI_EVENT 0
  213. #define ISCSI_ASYNC_MSG_REQUEST_LOGOUT 1
  214. #define ISCSI_ASYNC_MSG_DROPPING_CONNECTION 2
  215. #define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS 3
  216. #define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION 4
  217. #define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC 255
  218. /* NOP-Out Message */
  219. struct iscsi_nopout {
  220. uint8_t opcode;
  221. uint8_t flags;
  222. __be16 rsvd2;
  223. uint8_t rsvd3;
  224. uint8_t dlength[3];
  225. struct scsi_lun lun;
  226. itt_t itt; /* Initiator Task Tag */
  227. __be32 ttt; /* Target Transfer Tag */
  228. __be32 cmdsn;
  229. __be32 exp_statsn;
  230. uint8_t rsvd4[16];
  231. };
  232. /* NOP-In Message */
  233. struct iscsi_nopin {
  234. uint8_t opcode;
  235. uint8_t flags;
  236. __be16 rsvd2;
  237. uint8_t rsvd3;
  238. uint8_t dlength[3];
  239. struct scsi_lun lun;
  240. itt_t itt; /* Initiator Task Tag */
  241. __be32 ttt; /* Target Transfer Tag */
  242. __be32 statsn;
  243. __be32 exp_cmdsn;
  244. __be32 max_cmdsn;
  245. uint8_t rsvd4[12];
  246. };
  247. /* SCSI Task Management Message Header */
  248. struct iscsi_tm {
  249. uint8_t opcode;
  250. uint8_t flags;
  251. uint8_t rsvd1[2];
  252. uint8_t hlength;
  253. uint8_t dlength[3];
  254. struct scsi_lun lun;
  255. itt_t itt; /* Initiator Task Tag */
  256. itt_t rtt; /* Reference Task Tag */
  257. __be32 cmdsn;
  258. __be32 exp_statsn;
  259. __be32 refcmdsn;
  260. __be32 exp_datasn;
  261. uint8_t rsvd2[8];
  262. };
  263. #define ISCSI_FLAG_TM_FUNC_MASK 0x7F
  264. /* Function values */
  265. #define ISCSI_TM_FUNC_ABORT_TASK 1
  266. #define ISCSI_TM_FUNC_ABORT_TASK_SET 2
  267. #define ISCSI_TM_FUNC_CLEAR_ACA 3
  268. #define ISCSI_TM_FUNC_CLEAR_TASK_SET 4
  269. #define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET 5
  270. #define ISCSI_TM_FUNC_TARGET_WARM_RESET 6
  271. #define ISCSI_TM_FUNC_TARGET_COLD_RESET 7
  272. #define ISCSI_TM_FUNC_TASK_REASSIGN 8
  273. #define ISCSI_TM_FUNC_VALUE(hdr) ((hdr)->flags & ISCSI_FLAG_TM_FUNC_MASK)
  274. /* SCSI Task Management Response Header */
  275. struct iscsi_tm_rsp {
  276. uint8_t opcode;
  277. uint8_t flags;
  278. uint8_t response; /* see Response values below */
  279. uint8_t qualifier;
  280. uint8_t hlength;
  281. uint8_t dlength[3];
  282. uint8_t rsvd2[8];
  283. itt_t itt; /* Initiator Task Tag */
  284. itt_t rtt; /* Reference Task Tag */
  285. __be32 statsn;
  286. __be32 exp_cmdsn;
  287. __be32 max_cmdsn;
  288. uint8_t rsvd3[12];
  289. };
  290. /* Response values */
  291. #define ISCSI_TMF_RSP_COMPLETE 0x00
  292. #define ISCSI_TMF_RSP_NO_TASK 0x01
  293. #define ISCSI_TMF_RSP_NO_LUN 0x02
  294. #define ISCSI_TMF_RSP_TASK_ALLEGIANT 0x03
  295. #define ISCSI_TMF_RSP_NO_FAILOVER 0x04
  296. #define ISCSI_TMF_RSP_NOT_SUPPORTED 0x05
  297. #define ISCSI_TMF_RSP_AUTH_FAILED 0x06
  298. #define ISCSI_TMF_RSP_REJECTED 0xff
  299. /* Ready To Transfer Header */
  300. struct iscsi_r2t_rsp {
  301. uint8_t opcode;
  302. uint8_t flags;
  303. uint8_t rsvd2[2];
  304. uint8_t hlength;
  305. uint8_t dlength[3];
  306. struct scsi_lun lun;
  307. itt_t itt; /* Initiator Task Tag */
  308. __be32 ttt; /* Target Transfer Tag */
  309. __be32 statsn;
  310. __be32 exp_cmdsn;
  311. __be32 max_cmdsn;
  312. __be32 r2tsn;
  313. __be32 data_offset;
  314. __be32 data_length;
  315. };
  316. /* SCSI Data Hdr */
  317. struct iscsi_data {
  318. uint8_t opcode;
  319. uint8_t flags;
  320. uint8_t rsvd2[2];
  321. uint8_t rsvd3;
  322. uint8_t dlength[3];
  323. struct scsi_lun lun;
  324. itt_t itt;
  325. __be32 ttt;
  326. __be32 rsvd4;
  327. __be32 exp_statsn;
  328. __be32 rsvd5;
  329. __be32 datasn;
  330. __be32 offset;
  331. __be32 rsvd6;
  332. /* Payload */
  333. };
  334. /* SCSI Data Response Hdr */
  335. struct iscsi_data_rsp {
  336. uint8_t opcode;
  337. uint8_t flags;
  338. uint8_t rsvd2;
  339. uint8_t cmd_status;
  340. uint8_t hlength;
  341. uint8_t dlength[3];
  342. struct scsi_lun lun;
  343. itt_t itt;
  344. __be32 ttt;
  345. __be32 statsn;
  346. __be32 exp_cmdsn;
  347. __be32 max_cmdsn;
  348. __be32 datasn;
  349. __be32 offset;
  350. __be32 residual_count;
  351. };
  352. /* Data Response PDU flags */
  353. #define ISCSI_FLAG_DATA_ACK 0x40
  354. #define ISCSI_FLAG_DATA_OVERFLOW 0x04
  355. #define ISCSI_FLAG_DATA_UNDERFLOW 0x02
  356. #define ISCSI_FLAG_DATA_STATUS 0x01
  357. /* Text Header */
  358. struct iscsi_text {
  359. uint8_t opcode;
  360. uint8_t flags;
  361. uint8_t rsvd2[2];
  362. uint8_t hlength;
  363. uint8_t dlength[3];
  364. uint8_t rsvd4[8];
  365. itt_t itt;
  366. __be32 ttt;
  367. __be32 cmdsn;
  368. __be32 exp_statsn;
  369. uint8_t rsvd5[16];
  370. /* Text - key=value pairs */
  371. };
  372. #define ISCSI_FLAG_TEXT_CONTINUE 0x40
  373. /* Text Response Header */
  374. struct iscsi_text_rsp {
  375. uint8_t opcode;
  376. uint8_t flags;
  377. uint8_t rsvd2[2];
  378. uint8_t hlength;
  379. uint8_t dlength[3];
  380. uint8_t rsvd4[8];
  381. itt_t itt;
  382. __be32 ttt;
  383. __be32 statsn;
  384. __be32 exp_cmdsn;
  385. __be32 max_cmdsn;
  386. uint8_t rsvd5[12];
  387. /* Text Response - key:value pairs */
  388. };
  389. /* Login Header */
  390. struct iscsi_login_req {
  391. uint8_t opcode;
  392. uint8_t flags;
  393. uint8_t max_version; /* Max. version supported */
  394. uint8_t min_version; /* Min. version supported */
  395. uint8_t hlength;
  396. uint8_t dlength[3];
  397. uint8_t isid[6]; /* Initiator Session ID */
  398. __be16 tsih; /* Target Session Handle */
  399. itt_t itt; /* Initiator Task Tag */
  400. __be16 cid;
  401. __be16 rsvd3;
  402. __be32 cmdsn;
  403. __be32 exp_statsn;
  404. uint8_t rsvd5[16];
  405. };
  406. /* Login PDU flags */
  407. #define ISCSI_FLAG_LOGIN_TRANSIT 0x80
  408. #define ISCSI_FLAG_LOGIN_CONTINUE 0x40
  409. #define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C /* 2 bits */
  410. #define ISCSI_FLAG_LOGIN_CURRENT_STAGE1 0x04
  411. #define ISCSI_FLAG_LOGIN_CURRENT_STAGE2 0x08
  412. #define ISCSI_FLAG_LOGIN_CURRENT_STAGE3 0x0C
  413. #define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03 /* 2 bits */
  414. #define ISCSI_FLAG_LOGIN_NEXT_STAGE1 0x01
  415. #define ISCSI_FLAG_LOGIN_NEXT_STAGE2 0x02
  416. #define ISCSI_FLAG_LOGIN_NEXT_STAGE3 0x03
  417. #define ISCSI_LOGIN_CURRENT_STAGE(flags) \
  418. ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
  419. #define ISCSI_LOGIN_NEXT_STAGE(flags) \
  420. (flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
  421. /* Login Response Header */
  422. struct iscsi_login_rsp {
  423. uint8_t opcode;
  424. uint8_t flags;
  425. uint8_t max_version; /* Max. version supported */
  426. uint8_t active_version; /* Active version */
  427. uint8_t hlength;
  428. uint8_t dlength[3];
  429. uint8_t isid[6]; /* Initiator Session ID */
  430. __be16 tsih; /* Target Session Handle */
  431. itt_t itt; /* Initiator Task Tag */
  432. __be32 rsvd3;
  433. __be32 statsn;
  434. __be32 exp_cmdsn;
  435. __be32 max_cmdsn;
  436. uint8_t status_class; /* see Login RSP ststus classes below */
  437. uint8_t status_detail; /* see Login RSP Status details below */
  438. uint8_t rsvd4[10];
  439. };
  440. /* Login stage (phase) codes for CSG, NSG */
  441. #define ISCSI_INITIAL_LOGIN_STAGE -1
  442. #define ISCSI_SECURITY_NEGOTIATION_STAGE 0
  443. #define ISCSI_OP_PARMS_NEGOTIATION_STAGE 1
  444. #define ISCSI_FULL_FEATURE_PHASE 3
  445. /* Login Status response classes */
  446. #define ISCSI_STATUS_CLS_SUCCESS 0x00
  447. #define ISCSI_STATUS_CLS_REDIRECT 0x01
  448. #define ISCSI_STATUS_CLS_INITIATOR_ERR 0x02
  449. #define ISCSI_STATUS_CLS_TARGET_ERR 0x03
  450. /* Login Status response detail codes */
  451. /* Class-0 (Success) */
  452. #define ISCSI_LOGIN_STATUS_ACCEPT 0x00
  453. /* Class-1 (Redirection) */
  454. #define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP 0x01
  455. #define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM 0x02
  456. /* Class-2 (Initiator Error) */
  457. #define ISCSI_LOGIN_STATUS_INIT_ERR 0x00
  458. #define ISCSI_LOGIN_STATUS_AUTH_FAILED 0x01
  459. #define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN 0x02
  460. #define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND 0x03
  461. #define ISCSI_LOGIN_STATUS_TGT_REMOVED 0x04
  462. #define ISCSI_LOGIN_STATUS_NO_VERSION 0x05
  463. #define ISCSI_LOGIN_STATUS_ISID_ERROR 0x06
  464. #define ISCSI_LOGIN_STATUS_MISSING_FIELDS 0x07
  465. #define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED 0x08
  466. #define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE 0x09
  467. #define ISCSI_LOGIN_STATUS_NO_SESSION 0x0a
  468. #define ISCSI_LOGIN_STATUS_INVALID_REQUEST 0x0b
  469. /* Class-3 (Target Error) */
  470. #define ISCSI_LOGIN_STATUS_TARGET_ERROR 0x00
  471. #define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE 0x01
  472. #define ISCSI_LOGIN_STATUS_NO_RESOURCES 0x02
  473. /* Logout Header */
  474. struct iscsi_logout {
  475. uint8_t opcode;
  476. uint8_t flags;
  477. uint8_t rsvd1[2];
  478. uint8_t hlength;
  479. uint8_t dlength[3];
  480. uint8_t rsvd2[8];
  481. itt_t itt; /* Initiator Task Tag */
  482. __be16 cid;
  483. uint8_t rsvd3[2];
  484. __be32 cmdsn;
  485. __be32 exp_statsn;
  486. uint8_t rsvd4[16];
  487. };
  488. /* Logout PDU flags */
  489. #define ISCSI_FLAG_LOGOUT_REASON_MASK 0x7F
  490. /* logout reason_code values */
  491. #define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
  492. #define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
  493. #define ISCSI_LOGOUT_REASON_RECOVERY 2
  494. #define ISCSI_LOGOUT_REASON_AEN_REQUEST 3
  495. /* Logout Response Header */
  496. struct iscsi_logout_rsp {
  497. uint8_t opcode;
  498. uint8_t flags;
  499. uint8_t response; /* see Logout response values below */
  500. uint8_t rsvd2;
  501. uint8_t hlength;
  502. uint8_t dlength[3];
  503. uint8_t rsvd3[8];
  504. itt_t itt; /* Initiator Task Tag */
  505. __be32 rsvd4;
  506. __be32 statsn;
  507. __be32 exp_cmdsn;
  508. __be32 max_cmdsn;
  509. __be32 rsvd5;
  510. __be16 t2wait;
  511. __be16 t2retain;
  512. __be32 rsvd6;
  513. };
  514. /* logout response status values */
  515. #define ISCSI_LOGOUT_SUCCESS 0
  516. #define ISCSI_LOGOUT_CID_NOT_FOUND 1
  517. #define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED 2
  518. #define ISCSI_LOGOUT_CLEANUP_FAILED 3
  519. /* SNACK Header */
  520. struct iscsi_snack {
  521. uint8_t opcode;
  522. uint8_t flags;
  523. uint8_t rsvd2[2];
  524. uint8_t hlength;
  525. uint8_t dlength[3];
  526. uint8_t lun[8];
  527. itt_t itt;
  528. __be32 ttt;
  529. uint8_t rsvd3[4];
  530. __be32 exp_statsn;
  531. uint8_t rsvd4[8];
  532. __be32 begrun;
  533. __be32 runlength;
  534. };
  535. /* SNACK PDU flags */
  536. #define ISCSI_FLAG_SNACK_TYPE_DATA 0
  537. #define ISCSI_FLAG_SNACK_TYPE_R2T 0
  538. #define ISCSI_FLAG_SNACK_TYPE_STATUS 1
  539. #define ISCSI_FLAG_SNACK_TYPE_DATA_ACK 2
  540. #define ISCSI_FLAG_SNACK_TYPE_RDATA 3
  541. #define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F /* 4 bits */
  542. /* Reject Message Header */
  543. struct iscsi_reject {
  544. uint8_t opcode;
  545. uint8_t flags;
  546. uint8_t reason;
  547. uint8_t rsvd2;
  548. uint8_t hlength;
  549. uint8_t dlength[3];
  550. uint8_t rsvd3[8];
  551. __be32 ffffffff;
  552. uint8_t rsvd4[4];
  553. __be32 statsn;
  554. __be32 exp_cmdsn;
  555. __be32 max_cmdsn;
  556. __be32 datasn;
  557. uint8_t rsvd5[8];
  558. /* Text - Rejected hdr */
  559. };
  560. /* Reason for Reject */
  561. #define ISCSI_REASON_CMD_BEFORE_LOGIN 1
  562. #define ISCSI_REASON_DATA_DIGEST_ERROR 2
  563. #define ISCSI_REASON_DATA_SNACK_REJECT 3
  564. #define ISCSI_REASON_PROTOCOL_ERROR 4
  565. #define ISCSI_REASON_CMD_NOT_SUPPORTED 5
  566. #define ISCSI_REASON_IMM_CMD_REJECT 6
  567. #define ISCSI_REASON_TASK_IN_PROGRESS 7
  568. #define ISCSI_REASON_INVALID_SNACK 8
  569. #define ISCSI_REASON_BOOKMARK_INVALID 9
  570. #define ISCSI_REASON_BOOKMARK_NO_RESOURCES 10
  571. #define ISCSI_REASON_NEGOTIATION_RESET 11
  572. /* Max. number of Key=Value pairs in a text message */
  573. #define MAX_KEY_VALUE_PAIRS 8192
  574. /* maximum length for text keys/values */
  575. #define KEY_MAXLEN 64
  576. #define VALUE_MAXLEN 255
  577. #define TARGET_NAME_MAXLEN VALUE_MAXLEN
  578. #define ISCSI_DEF_MAX_RECV_SEG_LEN 8192
  579. #define ISCSI_MIN_MAX_RECV_SEG_LEN 512
  580. #define ISCSI_MAX_MAX_RECV_SEG_LEN 16777215
  581. #define ISCSI_DEF_FIRST_BURST_LEN 65536
  582. #define ISCSI_MIN_FIRST_BURST_LEN 512
  583. #define ISCSI_MAX_FIRST_BURST_LEN 16777215
  584. #define ISCSI_DEF_MAX_BURST_LEN 262144
  585. #define ISCSI_MIN_MAX_BURST_LEN 512
  586. #define ISCSI_MAX_MAX_BURST_LEN 16777215
  587. #define ISCSI_DEF_TIME2WAIT 2
  588. #define ISCSI_NAME_LEN 224
  589. /************************* RFC 3720 End *****************************/
  590. #endif /* ISCSI_PROTO_H */