You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

srp.h 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. #ifndef _GPXE_SRP_H
  2. #define _GPXE_SRP_H
  3. /** @file
  4. *
  5. * SCSI RDMA Protocol
  6. *
  7. */
  8. FILE_LICENCE ( BSD2 );
  9. #include <stdint.h>
  10. #include <byteswap.h>
  11. #include <gpxe/iobuf.h>
  12. #include <gpxe/xfer.h>
  13. #include <gpxe/scsi.h>
  14. /*****************************************************************************
  15. *
  16. * Common fields
  17. *
  18. *****************************************************************************
  19. */
  20. /** An SRP information unit tag */
  21. struct srp_tag {
  22. uint32_t dwords[2];
  23. } __attribute__ (( packed ));
  24. /** An SRP port ID */
  25. struct srp_port_id {
  26. uint8_t bytes[16];
  27. } __attribute__ (( packed ));
  28. /** An SRP port ID pair */
  29. struct srp_port_ids {
  30. /** Initiator port ID */
  31. struct srp_port_id initiator;
  32. /** Target port ID */
  33. struct srp_port_id target;
  34. } __attribute__ (( packed ));
  35. /** SRP information unit common fields */
  36. struct srp_common {
  37. /** Information unit type */
  38. uint8_t type;
  39. /** Reserved */
  40. uint8_t reserved0[7];
  41. /** Tag */
  42. struct srp_tag tag;
  43. } __attribute__ (( packed ));
  44. /*****************************************************************************
  45. *
  46. * Login request
  47. *
  48. *****************************************************************************
  49. */
  50. /** An SRP login request information unit */
  51. struct srp_login_req {
  52. /** Information unit type
  53. *
  54. * This must be @c SRP_LOGIN_REQ
  55. */
  56. uint8_t type;
  57. /** Reserved */
  58. uint8_t reserved0[7];
  59. /** Tag */
  60. struct srp_tag tag;
  61. /** Requested maximum initiator to target IU length */
  62. uint32_t max_i_t_iu_len;
  63. /** Reserved */
  64. uint8_t reserved1[4];
  65. /** Required buffer formats
  66. *
  67. * This is the bitwise OR of one or more @c
  68. * SRP_LOGIN_REQ_FMT_XXX constants.
  69. */
  70. uint16_t required_buffer_formats;
  71. /** Flags
  72. *
  73. * This is the bitwise OR of zero or more @c
  74. * SRP_LOGIN_REQ_FLAG_XXX and @c SRP_LOGIN_REQ_MCA_XXX
  75. * constants.
  76. */
  77. uint8_t flags;
  78. /** Reserved */
  79. uint8_t reserved2[5];
  80. /** Initiator and target port identifiers */
  81. struct srp_port_ids port_ids;
  82. } __attribute__ (( packed ));
  83. /** Type of an SRP login request */
  84. #define SRP_LOGIN_REQ 0x00
  85. /** Require indirect data buffer descriptor format */
  86. #define SRP_LOGIN_REQ_FMT_IDBD 0x04
  87. /** Require direct data buffer descriptor format */
  88. #define SRP_LOGIN_REQ_FMT_DDBD 0x02
  89. /** Use solicited notification for asynchronous events */
  90. #define SRP_LOGIN_REQ_FLAG_AESOLNT 0x40
  91. /** Use solicited notification for credit request */
  92. #define SRP_LOGIN_REQ_FLAG_CRSOLNT 0x20
  93. /** Use solicited notification for logouts */
  94. #define SRP_LOGIN_REQ_FLAG_LOSOLNT 0x10
  95. /** Multi-channel action mask */
  96. #define SRP_LOGIN_REQ_MCA_MASK 0x03
  97. /** Single RDMA channel operation */
  98. #define SRP_LOGIN_REQ_MCA_SINGLE_CHANNEL 0x00
  99. /** Multiple independent RDMA channel operation */
  100. #define SRP_LOGIN_REQ_MCA_MULTIPLE_CHANNELS 0x01
  101. /*****************************************************************************
  102. *
  103. * Login response
  104. *
  105. *****************************************************************************
  106. */
  107. /** An SRP login response */
  108. struct srp_login_rsp {
  109. /** Information unit type
  110. *
  111. * This must be @c SRP_LOGIN_RSP
  112. */
  113. uint8_t type;
  114. /** Reserved */
  115. uint8_t reserved0[3];
  116. /** Request limit delta */
  117. uint32_t request_limit_delta;
  118. /** Tag */
  119. struct srp_tag tag;
  120. /** Maximum initiator to target IU length */
  121. uint32_t max_i_t_iu_len;
  122. /** Maximum target to initiator IU length */
  123. uint32_t max_t_i_iu_len;
  124. /** Supported buffer formats
  125. *
  126. * This is the bitwise OR of one or more @c
  127. * SRP_LOGIN_RSP_FMT_XXX constants.
  128. */
  129. uint16_t supported_buffer_formats;
  130. /** Flags
  131. *
  132. * This is the bitwise OR of zero or more @c
  133. * SRP_LOGIN_RSP_FLAG_XXX and @c SRP_LOGIN_RSP_MCR_XXX
  134. * constants.
  135. */
  136. uint8_t flags;
  137. /** Reserved */
  138. uint8_t reserved1[25];
  139. } __attribute__ (( packed ));
  140. /** Type of an SRP login response */
  141. #define SRP_LOGIN_RSP 0xc0
  142. /** Indirect data buffer descriptor format supported */
  143. #define SRP_LOGIN_RSP_FMT_IDBD 0x04
  144. /** Direct data buffer descriptor format supported */
  145. #define SRP_LOGIN_RSP_FMT_DDBD 0x02
  146. /** Solicited notification is supported */
  147. #define SRP_LOGIN_RSP_FLAG_SOLNTSUP 0x10
  148. /** Multi-channel result mask */
  149. #define SRP_LOGIN_RSP_MCR_MASK 0x03
  150. /** No existing RDMA channels were associated with the same I_T nexus */
  151. #define SRP_LOGIN_RSP_MCR_NO_EXISTING_CHANNELS 0x00
  152. /** One or more existing RDMA channels were terminated */
  153. #define SRP_LOGIN_RSP_MCR_EXISTING_CHANNELS_TERMINATED 0x01
  154. /** One or more existing RDMA channels continue to operate independently */
  155. #define SRP_LOGIN_RSP_MCR_EXISTING_CHANNELS_CONTINUE 0x02
  156. /*****************************************************************************
  157. *
  158. * Login rejection
  159. *
  160. *****************************************************************************
  161. */
  162. /** An SRP login rejection */
  163. struct srp_login_rej {
  164. /** Information unit type
  165. *
  166. * This must be @c SRP_LOGIN_REJ
  167. */
  168. uint8_t type;
  169. /** Reserved */
  170. uint8_t reserved0[3];
  171. /** Reason
  172. *
  173. * This is a @c SRP_LOGIN_REJ_REASON_XXX constant.
  174. */
  175. uint32_t reason;
  176. /** Tag */
  177. struct srp_tag tag;
  178. /** Reserved */
  179. uint8_t reserved1[8];
  180. /** Supported buffer formats
  181. *
  182. * This is the bitwise OR of one or more @c
  183. * SRP_LOGIN_REJ_FMT_XXX constants.
  184. */
  185. uint16_t supported_buffer_formats;
  186. /** Reserved */
  187. uint8_t reserved2[6];
  188. } __attribute__ (( packed ));
  189. /** Type of an SRP login rejection */
  190. #define SRP_LOGIN_REJ 0xc2
  191. /** Unable to establish RDMA channel, no reason specified */
  192. #define SRP_LOGIN_REJ_REASON_UNKNOWN 0x00010000UL
  193. /** Insufficient RDMA channel resources */
  194. #define SRP_LOGIN_REJ_REASON_INSUFFICIENT_RESOURCES 0x00010001UL
  195. /** Requested maximum initiator to target IU length value too large */
  196. #define SRP_LOGIN_REJ_REASON_BAD_MAX_I_T_IU_LEN 0x00010002UL
  197. /** Unable to associate RDMA channel with specified I_T nexus */
  198. #define SRP_LOGIN_REJ_REASON_CANNOT_ASSOCIATE 0x00010003UL
  199. /** One or more requested data buffer descriptor formats are not supported */
  200. #define SRP_LOGIN_REJ_REASON_UNSUPPORTED_BUFFER_FORMAT 0x00010004UL
  201. /** SRP target port does not support multiple RDMA channels per I_T nexus */
  202. #define SRP_LOGIN_REJ_REASON_NO_MULTIPLE_CHANNELS 0x00010005UL
  203. /** RDMA channel limit reached for this initiator */
  204. #define SRP_LOGIN_REJ_REASON_NO_MORE_CHANNELS 0x00010006UL
  205. /** Indirect data buffer descriptor format supported */
  206. #define SRP_LOGIN_REJ_FMT_IDBD 0x04
  207. /** Direct data buffer descriptor format supported */
  208. #define SRP_LOGIN_REJ_FMT_DDBD 0x02
  209. /*****************************************************************************
  210. *
  211. * Initiator logout
  212. *
  213. *****************************************************************************
  214. */
  215. /** An SRP initiator logout request */
  216. struct srp_i_logout {
  217. /** Information unit type
  218. *
  219. * This must be @c SRP_I_LOGOUT
  220. */
  221. uint8_t type;
  222. /** Reserved */
  223. uint8_t reserved0[7];
  224. /** Tag */
  225. struct srp_tag tag;
  226. } __attribute__ (( packed ));
  227. /** Type of an SRP initiator logout request */
  228. #define SRP_I_LOGOUT 0x03
  229. /*****************************************************************************
  230. *
  231. * Target logout
  232. *
  233. *****************************************************************************
  234. */
  235. /** An SRP target logout request */
  236. struct srp_t_logout {
  237. /** Information unit type
  238. *
  239. * This must be @c SRP_T_LOGOUT
  240. */
  241. uint8_t type;
  242. /** Flags
  243. *
  244. * This is the bitwise OR of zero or more @c
  245. * SRP_T_LOGOUT_FLAG_XXX constants.
  246. */
  247. uint8_t flags;
  248. /** Reserved */
  249. uint8_t reserved0[2];
  250. /** Reason
  251. *
  252. * This is a @c SRP_T_LOGOUT_REASON_XXX constant.
  253. */
  254. uint32_t reason;
  255. /** Tag */
  256. struct srp_tag tag;
  257. } __attribute__ (( packed ));
  258. /** Type of an SRP target logout request */
  259. #define SRP_T_LOGOUT 0x80
  260. /** The initiator specified solicited notification of logouts */
  261. #define SRP_T_LOGOUT_FLAG_SOLNT 0x01
  262. /** No reason specified */
  263. #define SRP_T_LOGOUT_REASON_UNKNOWN 0x00000000UL
  264. /** Inactive RDMA channel (reclaiming resources) */
  265. #define SRP_T_LOGOUT_REASON_INACTIVE 0x00000001UL
  266. /** Invalid information unit type code received by SRP target port */
  267. #define SRP_T_LOGOUT_REASON_INVALID_TYPE 0x00000002UL
  268. /** SRP initiator port sent response with no corresponding request */
  269. #define SRP_T_LOGOUT_REASON_SPURIOUS_RESPONSE 0x00000003UL
  270. /** RDMA channel disconnected due to multi-channel action code in new login */
  271. #define SRP_T_LOGOUT_REASON_MCA 0x00000004UL
  272. /** Unsuppported format code value specified in data-out buffer descriptor */
  273. #define SRP_T_LOGOUT_UNSUPPORTED_DATA_OUT_FORMAT 0x00000005UL
  274. /** Unsuppported format code value specified in data-in buffer descriptor */
  275. #define SRP_T_LOGOUT_UNSUPPORTED_DATA_IN_FORMAT 0x00000006UL
  276. /** Invalid length for IU type */
  277. #define SRP_T_LOGOUT_INVALID_IU_LEN 0x00000008UL
  278. /*****************************************************************************
  279. *
  280. * Task management
  281. *
  282. *****************************************************************************
  283. */
  284. /** An SRP task management request */
  285. struct srp_tsk_mgmt {
  286. /** Information unit type
  287. *
  288. * This must be @c SRP_TSK_MGMT
  289. */
  290. uint8_t type;
  291. /** Flags
  292. *
  293. * This is the bitwise OR of zero or more
  294. * @c SRP_TSK_MGMT_FLAG_XXX constants.
  295. */
  296. uint8_t flags;
  297. /** Reserved */
  298. uint8_t reserved0[6];
  299. /** Tag */
  300. struct srp_tag tag;
  301. /** Reserved */
  302. uint8_t reserved1[4];
  303. /** Logical unit number */
  304. struct scsi_lun lun;
  305. /** Reserved */
  306. uint8_t reserved2[2];
  307. /** Task management function
  308. *
  309. * This is a @c SRP_TASK_MGMT_FUNC_XXX constant
  310. */
  311. uint8_t function;
  312. /** Reserved */
  313. uint8_t reserved3[1];
  314. /** Tag of task to be managed */
  315. struct srp_tag managed_tag;
  316. /** Reserved */
  317. uint8_t reserved4[8];
  318. } __attribute__ (( packed ));
  319. /** Type of an SRP task management request */
  320. #define SRP_TSK_MGMT 0x01
  321. /** Use solicited notification for unsuccessful completions */
  322. #define SRP_TSK_MGMT_FLAG_UCSOLNT 0x04
  323. /** Use solicited notification for successful completions */
  324. #define SRP_TSK_MGMT_FLAG_SCSOLNT 0x02
  325. /** The task manager shall perform an ABORT TASK function */
  326. #define SRP_TSK_MGMT_FUNC_ABORT_TASK 0x01
  327. /** The task manager shall perform an ABORT TASK SET function */
  328. #define SRP_TSK_MGMT_FUNC_ABORT_TASK_SET 0x02
  329. /** The task manager shall perform a CLEAR TASK SET function */
  330. #define SRP_TSK_MGMT_FUNC_CLEAR_TASK_SET 0x04
  331. /** The task manager shall perform a LOGICAL UNIT RESET function */
  332. #define SRP_TSK_MGMT_FUNC_LOGICAL_UNIT_RESET 0x08
  333. /** The task manager shall perform a CLEAR ACA function */
  334. #define SRP_TSK_MGMT_FUNC_CLEAR_ACA 0x40
  335. /*****************************************************************************
  336. *
  337. * SCSI command
  338. *
  339. *****************************************************************************
  340. */
  341. /** An SRP SCSI command */
  342. struct srp_cmd {
  343. /** Information unit type
  344. *
  345. * This must be @c SRP_CMD
  346. */
  347. uint8_t type;
  348. /** Flags
  349. *
  350. * This is the bitwise OR of zero or more @c SRP_CMD_FLAG_XXX
  351. * constants.
  352. */
  353. uint8_t flags;
  354. /** Reserved */
  355. uint8_t reserved0[3];
  356. /** Data buffer descriptor formats
  357. *
  358. * This is the bitwise OR of one @c SRP_CMD_DO_FMT_XXX and one @c
  359. * SRP_CMD_DI_FMT_XXX constant.
  360. */
  361. uint8_t data_buffer_formats;
  362. /** Data-out buffer descriptor count */
  363. uint8_t data_out_buffer_count;
  364. /** Data-in buffer descriptor count */
  365. uint8_t data_in_buffer_count;
  366. /** Tag */
  367. struct srp_tag tag;
  368. /** Reserved */
  369. uint8_t reserved1[4];
  370. /** Logical unit number */
  371. struct scsi_lun lun;
  372. /** Reserved */
  373. uint8_t reserved2[1];
  374. /** Task attribute
  375. *
  376. * This is a @c SRP_CMD_TASK_ATTR_XXX constant.
  377. */
  378. uint8_t task_attr;
  379. /** Reserved */
  380. uint8_t reserved3[1];
  381. /** Additional CDB length */
  382. uint8_t additional_cdb_len;
  383. /** Command data block */
  384. union scsi_cdb cdb;
  385. } __attribute__ (( packed ));
  386. /** Type of an SRP SCSI command */
  387. #define SRP_CMD 0x02
  388. /** Use solicited notification for unsuccessful completions */
  389. #define SRP_CMD_FLAG_UCSOLNT 0x04
  390. /** Use solicited notification for successful completions */
  391. #define SRP_CMD_FLAG_SCSOLNT 0x02
  392. /** Data-out buffer format mask */
  393. #define SRP_CMD_DO_FMT_MASK 0xf0
  394. /** Direct data-out buffer format */
  395. #define SRP_CMD_DO_FMT_DIRECT 0x10
  396. /** Indirect data-out buffer format */
  397. #define SRP_CMD_DO_FMT_INDIRECT 0x20
  398. /** Data-in buffer format mask */
  399. #define SRP_CMD_DI_FMT_MASK 0x0f
  400. /** Direct data-in buffer format */
  401. #define SRP_CMD_DI_FMT_DIRECT 0x01
  402. /** Indirect data-in buffer format */
  403. #define SRP_CMD_DI_FMT_INDIRECT 0x02
  404. /** Use the rules for a simple task attribute */
  405. #define SRP_CMD_TASK_ATTR_SIMPLE 0x00
  406. /** Use the rules for a head of queue task attribute */
  407. #define SRP_CMD_TASK_ATTR_QUEUE_HEAD 0x01
  408. /** Use the rules for an ordered task attribute */
  409. #define SRP_CMD_TASK_ATTR_ORDERED 0x02
  410. /** Use the rules for an automatic contingent allegiance task attribute */
  411. #define SRP_CMD_TASK_ATTR_AUTOMATIC_CONTINGENT_ALLEGIANCE 0x08
  412. /** An SRP memory descriptor */
  413. struct srp_memory_descriptor {
  414. /** Virtual address */
  415. uint64_t address;
  416. /** Memory handle */
  417. uint32_t handle;
  418. /** Data length */
  419. uint32_t len;
  420. } __attribute__ (( packed ));
  421. /*****************************************************************************
  422. *
  423. * SCSI response
  424. *
  425. *****************************************************************************
  426. */
  427. /** An SRP SCSI response */
  428. struct srp_rsp {
  429. /** Information unit type
  430. *
  431. * This must be @c SRP_RSP
  432. */
  433. uint8_t type;
  434. /** Flags
  435. *
  436. * This is the bitwise OR of zero or more @c SRP_RSP_FLAG_XXX
  437. * constants.
  438. */
  439. uint8_t flags;
  440. /** Reserved */
  441. uint8_t reserved0[2];
  442. /** Request limit delta */
  443. uint32_t request_limit_delta;
  444. /** Tag */
  445. struct srp_tag tag;
  446. /** Reserved */
  447. uint8_t reserved1[2];
  448. /** Valid fields
  449. *
  450. * This is the bitwise OR of zero or more @c SRP_RSP_VALID_XXX
  451. * constants.
  452. */
  453. uint8_t valid;
  454. /** Status
  455. *
  456. * This is the SCSI status code.
  457. */
  458. uint8_t status;
  459. /** Data-out residual count */
  460. uint32_t data_out_residual_count;
  461. /** Data-in residual count */
  462. uint32_t data_in_residual_count;
  463. /** Sense data list length */
  464. uint32_t sense_data_len;
  465. /** Response data list length */
  466. uint32_t response_data_len;
  467. } __attribute__ (( packed ));
  468. /** Type of an SRP SCSI response */
  469. #define SRP_RSP 0xc1
  470. /** The initiator specified solicited notification of this response */
  471. #define SRP_RSP_FLAG_SOLNT 0x01
  472. /** Data-in residual count field is valid and represents an underflow */
  473. #define SRP_RSP_VALID_DIUNDER 0x20
  474. /** Data-in residual count field is valid and represents an overflow */
  475. #define SRP_RSP_VALID_DIOVER 0x10
  476. /** Data-out residual count field is valid and represents an underflow */
  477. #define SRP_RSP_VALID_DOUNDER 0x08
  478. /** Data-out residual count field is valid and represents an overflow */
  479. #define SRP_RSP_VALID_DOOVER 0x04
  480. /** Sense data list length field is valid */
  481. #define SRP_RSP_VALID_SNSVALID 0x02
  482. /** Response data list length field is valid */
  483. #define SRP_RSP_VALID_RSPVALID 0x01
  484. /**
  485. * Get response data portion of SCSI response
  486. *
  487. * @v rsp SCSI response
  488. * @ret response_data Response data, or NULL if not present
  489. */
  490. static inline void * srp_rsp_response_data ( struct srp_rsp *rsp ) {
  491. return ( ( rsp->valid & SRP_RSP_VALID_RSPVALID ) ?
  492. ( ( ( void * ) rsp ) + sizeof ( *rsp ) ) : NULL );
  493. }
  494. /**
  495. * Get length of response data portion of SCSI response
  496. *
  497. * @v rsp SCSI response
  498. * @ret response_data_len Response data length
  499. */
  500. static inline size_t srp_rsp_response_data_len ( struct srp_rsp *rsp ) {
  501. return ( ( rsp->valid & SRP_RSP_VALID_RSPVALID ) ?
  502. ntohl ( rsp->response_data_len ) : 0 );
  503. }
  504. /**
  505. * Get sense data portion of SCSI response
  506. *
  507. * @v rsp SCSI response
  508. * @ret sense_data Sense data, or NULL if not present
  509. */
  510. static inline void * srp_rsp_sense_data ( struct srp_rsp *rsp ) {
  511. return ( ( rsp->valid & SRP_RSP_VALID_SNSVALID ) ?
  512. ( ( ( void * ) rsp ) + sizeof ( *rsp ) +
  513. srp_rsp_response_data_len ( rsp ) ) : NULL );
  514. }
  515. /**
  516. * Get length of sense data portion of SCSI response
  517. *
  518. * @v rsp SCSI response
  519. * @ret sense_data_len Sense data length
  520. */
  521. static inline size_t srp_rsp_sense_data_len ( struct srp_rsp *rsp ) {
  522. return ( ( rsp->valid & SRP_RSP_VALID_SNSVALID ) ?
  523. ntohl ( rsp->sense_data_len ) : 0 );
  524. }
  525. /*****************************************************************************
  526. *
  527. * Credit request
  528. *
  529. *****************************************************************************
  530. */
  531. /** An SRP credit request */
  532. struct srp_cred_req {
  533. /** Information unit type
  534. *
  535. * This must be @c SRP_CRED_REQ
  536. */
  537. uint8_t type;
  538. /** Flags
  539. *
  540. * This is the bitwise OR of zero or more
  541. * @c SRP_CRED_REQ_FLAG_XXX constants.
  542. */
  543. uint8_t flags;
  544. /** Reserved */
  545. uint8_t reserved0[2];
  546. /** Request limit delta */
  547. uint32_t request_limit_delta;
  548. /** Tag */
  549. struct srp_tag tag;
  550. } __attribute__ (( packed ));
  551. /** Type of an SRP credit request */
  552. #define SRP_CRED_REQ 0x81
  553. /** The initiator specified solicited notification of credit requests */
  554. #define SRP_CRED_REQ_FLAG_SOLNT 0x01
  555. /*****************************************************************************
  556. *
  557. * Credit response
  558. *
  559. *****************************************************************************
  560. */
  561. /** An SRP credit response */
  562. struct srp_cred_rsp {
  563. /** Information unit type
  564. *
  565. * This must be @c SRP_CRED_RSP
  566. */
  567. uint8_t type;
  568. /** Reserved */
  569. uint8_t reserved0[7];
  570. /** Tag */
  571. struct srp_tag tag;
  572. } __attribute__ (( packed ));
  573. /** Type of an SRP credit response */
  574. #define SRP_CRED_RSP 0x41
  575. /*****************************************************************************
  576. *
  577. * Asynchronous event request
  578. *
  579. *****************************************************************************
  580. */
  581. /** An SRP asynchronous event request */
  582. struct srp_aer_req {
  583. /** Information unit type
  584. *
  585. * This must be @c SRP_AER_REQ
  586. */
  587. uint8_t type;
  588. /** Flags
  589. *
  590. * This is the bitwise OR of zero or more @c
  591. * SRP_AER_REQ_FLAG_XXX constants.
  592. */
  593. uint8_t flags;
  594. /** Reserved */
  595. uint8_t reserved0[2];
  596. /** Request limit delta */
  597. uint32_t request_limit_delta;
  598. /** Tag */
  599. struct srp_tag tag;
  600. /** Reserved */
  601. uint8_t reserved1[4];
  602. /** Logical unit number */
  603. struct scsi_lun lun;
  604. /** Sense data list length */
  605. uint32_t sense_data_len;
  606. /** Reserved */
  607. uint8_t reserved2[4];
  608. } __attribute__ (( packed ));
  609. /** Type of an SRP asynchronous event request */
  610. #define SRP_AER_REQ 0x82
  611. /** The initiator specified solicited notification of asynchronous events */
  612. #define SRP_AER_REQ_FLAG_SOLNT 0x01
  613. /**
  614. * Get sense data portion of asynchronous event request
  615. *
  616. * @v aer_req SRP asynchronous event request
  617. * @ret sense_data Sense data
  618. */
  619. static inline __always_inline void *
  620. srp_aer_req_sense_data ( struct srp_aer_req *aer_req ) {
  621. return ( ( ( void * ) aer_req ) + sizeof ( *aer_req ) );
  622. }
  623. /**
  624. * Get length of sense data portion of asynchronous event request
  625. *
  626. * @v aer_req SRP asynchronous event request
  627. * @ret sense_data_len Sense data length
  628. */
  629. static inline __always_inline size_t
  630. srp_aer_req_sense_data_len ( struct srp_aer_req *aer_req ) {
  631. return ( ntohl ( aer_req->sense_data_len ) );
  632. }
  633. /*****************************************************************************
  634. *
  635. * Asynchronous event response
  636. *
  637. *****************************************************************************
  638. */
  639. /** An SRP asynchronous event response */
  640. struct srp_aer_rsp {
  641. /** Information unit type
  642. *
  643. * This must be @c SRP_AER_RSP
  644. */
  645. uint8_t type;
  646. /** Reserved */
  647. uint8_t reserved0[7];
  648. /** Tag */
  649. struct srp_tag tag;
  650. } __attribute__ (( packed ));
  651. /** Type of an SRP asynchronous event response */
  652. #define SRP_AER_RSP 0x42
  653. /*****************************************************************************
  654. *
  655. * Information units
  656. *
  657. *****************************************************************************
  658. */
  659. /** Maximum length of any initiator-to-target IU that we will send
  660. *
  661. * The longest IU is a SRP_CMD with no additional CDB and two direct
  662. * data buffer descriptors, which comes to 80 bytes.
  663. */
  664. #define SRP_MAX_I_T_IU_LEN 80
  665. /*****************************************************************************
  666. *
  667. * SRP device
  668. *
  669. *****************************************************************************
  670. */
  671. struct srp_device;
  672. /** An SRP transport type */
  673. struct srp_transport_type {
  674. /** Length of transport private data */
  675. size_t priv_len;
  676. /** Parse root path
  677. *
  678. * @v srp SRP device
  679. * @v root_path Root path
  680. * @ret Return status code
  681. */
  682. int ( * parse_root_path ) ( struct srp_device *srp,
  683. const char *root_path );
  684. /** Connect SRP session
  685. *
  686. * @v srp SRP device
  687. * @ret rc Return status code
  688. *
  689. * This method should open the underlying socket.
  690. */
  691. int ( * connect ) ( struct srp_device *srp );
  692. };
  693. /** An SRP device */
  694. struct srp_device {
  695. /** Reference count */
  696. struct refcnt refcnt;
  697. /** Initiator and target port IDs */
  698. struct srp_port_ids port_ids;
  699. /** Logical unit number */
  700. struct scsi_lun lun;
  701. /** Memory handle */
  702. uint32_t memory_handle;
  703. /** Current state
  704. *
  705. * This is the bitwise-OR of zero or more @c SRP_STATE_XXX
  706. * flags.
  707. */
  708. unsigned int state;
  709. /** Retry counter */
  710. unsigned int retry_count;
  711. /** Instant return status code
  712. *
  713. * Used to avoid retrying the connection on every new SCSI
  714. * command after the retry count has been exceeded.
  715. */
  716. int instant_rc;
  717. /** Current SCSI command */
  718. struct scsi_command *command;
  719. /** Underlying data transfer interface */
  720. struct xfer_interface socket;
  721. /** Transport type */
  722. struct srp_transport_type *transport;
  723. /** Transport private data */
  724. char transport_priv[0];
  725. };
  726. /**
  727. * Get SRP transport private data
  728. *
  729. * @v srp SRP device
  730. * @ret priv SRP transport private data
  731. */
  732. static inline __always_inline void *
  733. srp_transport_priv ( struct srp_device *srp ) {
  734. return ( ( void * ) srp->transport_priv );
  735. }
  736. /** SRP state flags */
  737. enum srp_state {
  738. /** Underlying socket is open */
  739. SRP_STATE_SOCKET_OPEN = 0x0001,
  740. /** Session is logged in */
  741. SRP_STATE_LOGGED_IN = 0x0002,
  742. };
  743. /** Maximum number of SRP retry attempts */
  744. #define SRP_MAX_RETRIES 3
  745. extern int srp_attach ( struct scsi_device *scsi, const char *root_path );
  746. extern void srp_detach ( struct scsi_device *scsi );
  747. #endif /* _GPXE_SRP_H */