10 FILE_LICENCE ( BSD2
);
14 #include <gpxe/iobuf.h>
15 #include <gpxe/xfer.h>
16 #include <gpxe/scsi.h>
18 /*****************************************************************************
22 *****************************************************************************
25 /** An SRP information unit tag */
28 } __attribute__ (( packed
));
33 } __attribute__ (( packed
));
35 /** An SRP port ID pair */
37 /** Initiator port ID */
38 struct srp_port_id initiator
;
40 struct srp_port_id target
;
41 } __attribute__ (( packed
));
43 /** SRP information unit common fields */
45 /** Information unit type */
51 } __attribute__ (( packed
));
53 /*****************************************************************************
57 *****************************************************************************
60 /** An SRP login request information unit */
61 struct srp_login_req
{
62 /** Information unit type
64 * This must be @c SRP_LOGIN_REQ
71 /** Requested maximum initiator to target IU length */
72 uint32_t max_i_t_iu_len
;
75 /** Required buffer formats
77 * This is the bitwise OR of one or more @c
78 * SRP_LOGIN_REQ_FMT_XXX constants.
80 uint16_t required_buffer_formats
;
83 * This is the bitwise OR of zero or more @c
84 * SRP_LOGIN_REQ_FLAG_XXX and @c SRP_LOGIN_REQ_MCA_XXX
90 /** Initiator and target port identifiers */
91 struct srp_port_ids port_ids
;
92 } __attribute__ (( packed
));
94 /** Type of an SRP login request */
95 #define SRP_LOGIN_REQ 0x00
97 /** Require indirect data buffer descriptor format */
98 #define SRP_LOGIN_REQ_FMT_IDBD 0x04
100 /** Require direct data buffer descriptor format */
101 #define SRP_LOGIN_REQ_FMT_DDBD 0x02
103 /** Use solicited notification for asynchronous events */
104 #define SRP_LOGIN_REQ_FLAG_AESOLNT 0x40
106 /** Use solicited notification for credit request */
107 #define SRP_LOGIN_REQ_FLAG_CRSOLNT 0x20
109 /** Use solicited notification for logouts */
110 #define SRP_LOGIN_REQ_FLAG_LOSOLNT 0x10
112 /** Multi-channel action mask */
113 #define SRP_LOGIN_REQ_MCA_MASK 0x03
115 /** Single RDMA channel operation */
116 #define SRP_LOGIN_REQ_MCA_SINGLE_CHANNEL 0x00
118 /** Multiple independent RDMA channel operation */
119 #define SRP_LOGIN_REQ_MCA_MULTIPLE_CHANNELS 0x01
121 /*****************************************************************************
125 *****************************************************************************
128 /** An SRP login response */
129 struct srp_login_rsp
{
130 /** Information unit type
132 * This must be @c SRP_LOGIN_RSP
136 uint8_t reserved0
[3];
137 /** Request limit delta */
138 uint32_t request_limit_delta
;
141 /** Maximum initiator to target IU length */
142 uint32_t max_i_t_iu_len
;
143 /** Maximum target to initiator IU length */
144 uint32_t max_t_i_iu_len
;
145 /** Supported buffer formats
147 * This is the bitwise OR of one or more @c
148 * SRP_LOGIN_RSP_FMT_XXX constants.
150 uint16_t supported_buffer_formats
;
153 * This is the bitwise OR of zero or more @c
154 * SRP_LOGIN_RSP_FLAG_XXX and @c SRP_LOGIN_RSP_MCR_XXX
159 uint8_t reserved1
[25];
160 } __attribute__ (( packed
));
162 /** Type of an SRP login response */
163 #define SRP_LOGIN_RSP 0xc0
165 /** Indirect data buffer descriptor format supported */
166 #define SRP_LOGIN_RSP_FMT_IDBD 0x04
168 /** Direct data buffer descriptor format supported */
169 #define SRP_LOGIN_RSP_FMT_DDBD 0x02
171 /** Solicited notification is supported */
172 #define SRP_LOGIN_RSP_FLAG_SOLNTSUP 0x10
174 /** Multi-channel result mask */
175 #define SRP_LOGIN_RSP_MCR_MASK 0x03
177 /** No existing RDMA channels were associated with the same I_T nexus */
178 #define SRP_LOGIN_RSP_MCR_NO_EXISTING_CHANNELS 0x00
180 /** One or more existing RDMA channels were terminated */
181 #define SRP_LOGIN_RSP_MCR_EXISTING_CHANNELS_TERMINATED 0x01
183 /** One or more existing RDMA channels continue to operate independently */
184 #define SRP_LOGIN_RSP_MCR_EXISTING_CHANNELS_CONTINUE 0x02
186 /*****************************************************************************
190 *****************************************************************************
193 /** An SRP login rejection */
194 struct srp_login_rej
{
195 /** Information unit type
197 * This must be @c SRP_LOGIN_REJ
201 uint8_t reserved0
[3];
204 * This is a @c SRP_LOGIN_REJ_REASON_XXX constant.
210 uint8_t reserved1
[8];
211 /** Supported buffer formats
213 * This is the bitwise OR of one or more @c
214 * SRP_LOGIN_REJ_FMT_XXX constants.
216 uint16_t supported_buffer_formats
;
218 uint8_t reserved2
[6];
219 } __attribute__ (( packed
));
221 /** Type of an SRP login rejection */
222 #define SRP_LOGIN_REJ 0xc2
224 /** Unable to establish RDMA channel, no reason specified */
225 #define SRP_LOGIN_REJ_REASON_UNKNOWN 0x00010000UL
227 /** Insufficient RDMA channel resources */
228 #define SRP_LOGIN_REJ_REASON_INSUFFICIENT_RESOURCES 0x00010001UL
230 /** Requested maximum initiator to target IU length value too large */
231 #define SRP_LOGIN_REJ_REASON_BAD_MAX_I_T_IU_LEN 0x00010002UL
233 /** Unable to associate RDMA channel with specified I_T nexus */
234 #define SRP_LOGIN_REJ_REASON_CANNOT_ASSOCIATE 0x00010003UL
236 /** One or more requested data buffer descriptor formats are not supported */
237 #define SRP_LOGIN_REJ_REASON_UNSUPPORTED_BUFFER_FORMAT 0x00010004UL
239 /** SRP target port does not support multiple RDMA channels per I_T nexus */
240 #define SRP_LOGIN_REJ_REASON_NO_MULTIPLE_CHANNELS 0x00010005UL
242 /** RDMA channel limit reached for this initiator */
243 #define SRP_LOGIN_REJ_REASON_NO_MORE_CHANNELS 0x00010006UL
245 /** Indirect data buffer descriptor format supported */
246 #define SRP_LOGIN_REJ_FMT_IDBD 0x04
248 /** Direct data buffer descriptor format supported */
249 #define SRP_LOGIN_REJ_FMT_DDBD 0x02
251 /*****************************************************************************
255 *****************************************************************************
258 /** An SRP initiator logout request */
259 struct srp_i_logout
{
260 /** Information unit type
262 * This must be @c SRP_I_LOGOUT
266 uint8_t reserved0
[7];
269 } __attribute__ (( packed
));
271 /** Type of an SRP initiator logout request */
272 #define SRP_I_LOGOUT 0x03
274 /*****************************************************************************
278 *****************************************************************************
281 /** An SRP target logout request */
282 struct srp_t_logout
{
283 /** Information unit type
285 * This must be @c SRP_T_LOGOUT
290 * This is the bitwise OR of zero or more @c
291 * SRP_T_LOGOUT_FLAG_XXX constants.
295 uint8_t reserved0
[2];
298 * This is a @c SRP_T_LOGOUT_REASON_XXX constant.
303 } __attribute__ (( packed
));
305 /** Type of an SRP target logout request */
306 #define SRP_T_LOGOUT 0x80
308 /** The initiator specified solicited notification of logouts */
309 #define SRP_T_LOGOUT_FLAG_SOLNT 0x01
311 /** No reason specified */
312 #define SRP_T_LOGOUT_REASON_UNKNOWN 0x00000000UL
314 /** Inactive RDMA channel (reclaiming resources) */
315 #define SRP_T_LOGOUT_REASON_INACTIVE 0x00000001UL
317 /** Invalid information unit type code received by SRP target port */
318 #define SRP_T_LOGOUT_REASON_INVALID_TYPE 0x00000002UL
320 /** SRP initiator port sent response with no corresponding request */
321 #define SRP_T_LOGOUT_REASON_SPURIOUS_RESPONSE 0x00000003UL
323 /** RDMA channel disconnected due to multi-channel action code in new login */
324 #define SRP_T_LOGOUT_REASON_MCA 0x00000004UL
326 /** Unsuppported format code value specified in data-out buffer descriptor */
327 #define SRP_T_LOGOUT_UNSUPPORTED_DATA_OUT_FORMAT 0x00000005UL
329 /** Unsuppported format code value specified in data-in buffer descriptor */
330 #define SRP_T_LOGOUT_UNSUPPORTED_DATA_IN_FORMAT 0x00000006UL
332 /** Invalid length for IU type */
333 #define SRP_T_LOGOUT_INVALID_IU_LEN 0x00000008UL
335 /*****************************************************************************
339 *****************************************************************************
342 /** An SRP task management request */
343 struct srp_tsk_mgmt
{
344 /** Information unit type
346 * This must be @c SRP_TSK_MGMT
351 * This is the bitwise OR of zero or more
352 * @c SRP_TSK_MGMT_FLAG_XXX constants.
356 uint8_t reserved0
[6];
360 uint8_t reserved1
[4];
361 /** Logical unit number */
364 uint8_t reserved2
[2];
365 /** Task management function
367 * This is a @c SRP_TASK_MGMT_FUNC_XXX constant
371 uint8_t reserved3
[1];
372 /** Tag of task to be managed */
373 struct srp_tag managed_tag
;
375 uint8_t reserved4
[8];
376 } __attribute__ (( packed
));
378 /** Type of an SRP task management request */
379 #define SRP_TSK_MGMT 0x01
381 /** Use solicited notification for unsuccessful completions */
382 #define SRP_TSK_MGMT_FLAG_UCSOLNT 0x04
384 /** Use solicited notification for successful completions */
385 #define SRP_TSK_MGMT_FLAG_SCSOLNT 0x02
387 /** The task manager shall perform an ABORT TASK function */
388 #define SRP_TSK_MGMT_FUNC_ABORT_TASK 0x01
390 /** The task manager shall perform an ABORT TASK SET function */
391 #define SRP_TSK_MGMT_FUNC_ABORT_TASK_SET 0x02
393 /** The task manager shall perform a CLEAR TASK SET function */
394 #define SRP_TSK_MGMT_FUNC_CLEAR_TASK_SET 0x04
396 /** The task manager shall perform a LOGICAL UNIT RESET function */
397 #define SRP_TSK_MGMT_FUNC_LOGICAL_UNIT_RESET 0x08
399 /** The task manager shall perform a CLEAR ACA function */
400 #define SRP_TSK_MGMT_FUNC_CLEAR_ACA 0x40
402 /*****************************************************************************
406 *****************************************************************************
409 /** An SRP SCSI command */
411 /** Information unit type
413 * This must be @c SRP_CMD
418 * This is the bitwise OR of zero or more @c SRP_CMD_FLAG_XXX
423 uint8_t reserved0
[3];
424 /** Data buffer descriptor formats
426 * This is the bitwise OR of one @c SRP_CMD_DO_FMT_XXX and one @c
427 * SRP_CMD_DI_FMT_XXX constant.
429 uint8_t data_buffer_formats
;
430 /** Data-out buffer descriptor count */
431 uint8_t data_out_buffer_count
;
432 /** Data-in buffer descriptor count */
433 uint8_t data_in_buffer_count
;
437 uint8_t reserved1
[4];
438 /** Logical unit number */
441 uint8_t reserved2
[1];
444 * This is a @c SRP_CMD_TASK_ATTR_XXX constant.
448 uint8_t reserved3
[1];
449 /** Additional CDB length */
450 uint8_t additional_cdb_len
;
451 /** Command data block */
453 } __attribute__ (( packed
));
455 /** Type of an SRP SCSI command */
458 /** Use solicited notification for unsuccessful completions */
459 #define SRP_CMD_FLAG_UCSOLNT 0x04
461 /** Use solicited notification for successful completions */
462 #define SRP_CMD_FLAG_SCSOLNT 0x02
464 /** Data-out buffer format mask */
465 #define SRP_CMD_DO_FMT_MASK 0xf0
467 /** Direct data-out buffer format */
468 #define SRP_CMD_DO_FMT_DIRECT 0x10
470 /** Indirect data-out buffer format */
471 #define SRP_CMD_DO_FMT_INDIRECT 0x20
473 /** Data-in buffer format mask */
474 #define SRP_CMD_DI_FMT_MASK 0x0f
476 /** Direct data-in buffer format */
477 #define SRP_CMD_DI_FMT_DIRECT 0x01
479 /** Indirect data-in buffer format */
480 #define SRP_CMD_DI_FMT_INDIRECT 0x02
482 /** Use the rules for a simple task attribute */
483 #define SRP_CMD_TASK_ATTR_SIMPLE 0x00
485 /** Use the rules for a head of queue task attribute */
486 #define SRP_CMD_TASK_ATTR_QUEUE_HEAD 0x01
488 /** Use the rules for an ordered task attribute */
489 #define SRP_CMD_TASK_ATTR_ORDERED 0x02
491 /** Use the rules for an automatic contingent allegiance task attribute */
492 #define SRP_CMD_TASK_ATTR_AUTOMATIC_CONTINGENT_ALLEGIANCE 0x08
494 /** An SRP memory descriptor */
495 struct srp_memory_descriptor
{
496 /** Virtual address */
502 } __attribute__ (( packed
));
504 /*****************************************************************************
508 *****************************************************************************
511 /** An SRP SCSI response */
513 /** Information unit type
515 * This must be @c SRP_RSP
520 * This is the bitwise OR of zero or more @c SRP_RSP_FLAG_XXX
525 uint8_t reserved0
[2];
526 /** Request limit delta */
527 uint32_t request_limit_delta
;
531 uint8_t reserved1
[2];
534 * This is the bitwise OR of zero or more @c SRP_RSP_VALID_XXX
540 * This is the SCSI status code.
543 /** Data-out residual count */
544 uint32_t data_out_residual_count
;
545 /** Data-in residual count */
546 uint32_t data_in_residual_count
;
547 /** Sense data list length */
548 uint32_t sense_data_len
;
549 /** Response data list length */
550 uint32_t response_data_len
;
551 } __attribute__ (( packed
));
553 /** Type of an SRP SCSI response */
556 /** The initiator specified solicited notification of this response */
557 #define SRP_RSP_FLAG_SOLNT 0x01
559 /** Data-in residual count field is valid and represents an underflow */
560 #define SRP_RSP_VALID_DIUNDER 0x20
562 /** Data-in residual count field is valid and represents an overflow */
563 #define SRP_RSP_VALID_DIOVER 0x10
565 /** Data-out residual count field is valid and represents an underflow */
566 #define SRP_RSP_VALID_DOUNDER 0x08
568 /** Data-out residual count field is valid and represents an overflow */
569 #define SRP_RSP_VALID_DOOVER 0x04
571 /** Sense data list length field is valid */
572 #define SRP_RSP_VALID_SNSVALID 0x02
574 /** Response data list length field is valid */
575 #define SRP_RSP_VALID_RSPVALID 0x01
578 * Get response data portion of SCSI response
580 * @v rsp SCSI response
581 * @ret response_data Response data, or NULL if not present
583 static inline void * srp_rsp_response_data ( struct srp_rsp
*rsp
) {
584 return ( ( rsp
->valid
& SRP_RSP_VALID_RSPVALID
) ?
585 ( ( ( void * ) rsp
) + sizeof ( *rsp
) ) : NULL
);
589 * Get length of response data portion of SCSI response
591 * @v rsp SCSI response
592 * @ret response_data_len Response data length
594 static inline size_t srp_rsp_response_data_len ( struct srp_rsp
*rsp
) {
595 return ( ( rsp
->valid
& SRP_RSP_VALID_RSPVALID
) ?
596 ntohl ( rsp
->response_data_len
) : 0 );
600 * Get sense data portion of SCSI response
602 * @v rsp SCSI response
603 * @ret sense_data Sense data, or NULL if not present
605 static inline void * srp_rsp_sense_data ( struct srp_rsp
*rsp
) {
606 return ( ( rsp
->valid
& SRP_RSP_VALID_SNSVALID
) ?
607 ( ( ( void * ) rsp
) + sizeof ( *rsp
) +
608 srp_rsp_response_data_len ( rsp
) ) : NULL
);
612 * Get length of sense data portion of SCSI response
614 * @v rsp SCSI response
615 * @ret sense_data_len Sense data length
617 static inline size_t srp_rsp_sense_data_len ( struct srp_rsp
*rsp
) {
618 return ( ( rsp
->valid
& SRP_RSP_VALID_SNSVALID
) ?
619 ntohl ( rsp
->sense_data_len
) : 0 );
622 /*****************************************************************************
626 *****************************************************************************
629 /** An SRP credit request */
630 struct srp_cred_req
{
631 /** Information unit type
633 * This must be @c SRP_CRED_REQ
638 * This is the bitwise OR of zero or more
639 * @c SRP_CRED_REQ_FLAG_XXX constants.
643 uint8_t reserved0
[2];
644 /** Request limit delta */
645 uint32_t request_limit_delta
;
648 } __attribute__ (( packed
));
650 /** Type of an SRP credit request */
651 #define SRP_CRED_REQ 0x81
653 /** The initiator specified solicited notification of credit requests */
654 #define SRP_CRED_REQ_FLAG_SOLNT 0x01
656 /*****************************************************************************
660 *****************************************************************************
663 /** An SRP credit response */
664 struct srp_cred_rsp
{
665 /** Information unit type
667 * This must be @c SRP_CRED_RSP
671 uint8_t reserved0
[7];
674 } __attribute__ (( packed
));
676 /** Type of an SRP credit response */
677 #define SRP_CRED_RSP 0x41
679 /*****************************************************************************
681 * Asynchronous event request
683 *****************************************************************************
686 /** An SRP asynchronous event request */
688 /** Information unit type
690 * This must be @c SRP_AER_REQ
695 * This is the bitwise OR of zero or more @c
696 * SRP_AER_REQ_FLAG_XXX constants.
700 uint8_t reserved0
[2];
701 /** Request limit delta */
702 uint32_t request_limit_delta
;
706 uint8_t reserved1
[4];
707 /** Logical unit number */
709 /** Sense data list length */
710 uint32_t sense_data_len
;
712 uint8_t reserved2
[4];
713 } __attribute__ (( packed
));
715 /** Type of an SRP asynchronous event request */
716 #define SRP_AER_REQ 0x82
718 /** The initiator specified solicited notification of asynchronous events */
719 #define SRP_AER_REQ_FLAG_SOLNT 0x01
722 * Get sense data portion of asynchronous event request
724 * @v aer_req SRP asynchronous event request
725 * @ret sense_data Sense data
727 static inline __always_inline
void *
728 srp_aer_req_sense_data ( struct srp_aer_req
*aer_req
) {
729 return ( ( ( void * ) aer_req
) + sizeof ( *aer_req
) );
733 * Get length of sense data portion of asynchronous event request
735 * @v aer_req SRP asynchronous event request
736 * @ret sense_data_len Sense data length
738 static inline __always_inline
size_t
739 srp_aer_req_sense_data_len ( struct srp_aer_req
*aer_req
) {
740 return ( ntohl ( aer_req
->sense_data_len
) );
743 /*****************************************************************************
745 * Asynchronous event response
747 *****************************************************************************
750 /** An SRP asynchronous event response */
752 /** Information unit type
754 * This must be @c SRP_AER_RSP
758 uint8_t reserved0
[7];
761 } __attribute__ (( packed
));
763 /** Type of an SRP asynchronous event response */
764 #define SRP_AER_RSP 0x42
766 /*****************************************************************************
770 *****************************************************************************
773 /** Maximum length of any initiator-to-target IU that we will send
775 * The longest IU is a SRP_CMD with no additional CDB and two direct
776 * data buffer descriptors, which comes to 80 bytes.
778 #define SRP_MAX_I_T_IU_LEN 80
780 /*****************************************************************************
784 *****************************************************************************
789 /** An SRP transport type */
790 struct srp_transport_type
{
791 /** Length of transport private data */
796 * @v root_path Root path
797 * @ret Return status code
799 int ( * parse_root_path
) ( struct srp_device
*srp
,
800 const char *root_path
);
801 /** Connect SRP session
804 * @ret rc Return status code
806 * This method should open the underlying socket.
808 int ( * connect
) ( struct srp_device
*srp
);
813 /** Reference count */
814 struct refcnt refcnt
;
816 /** Initiator and target port IDs */
817 struct srp_port_ids port_ids
;
818 /** Logical unit number */
821 uint32_t memory_handle
;
825 * This is the bitwise-OR of zero or more @c SRP_STATE_XXX
830 unsigned int retry_count
;
831 /** Current SCSI command */
832 struct scsi_command
*command
;
834 /** Underlying data transfer interface */
835 struct xfer_interface socket
;
837 /** Transport type */
838 struct srp_transport_type
*transport
;
839 /** Transport private data */
840 char transport_priv
[0];
844 * Get SRP transport private data
847 * @ret priv SRP transport private data
849 static inline __always_inline
void *
850 srp_transport_priv ( struct srp_device
*srp
) {
851 return ( ( void * ) srp
->transport_priv
);
854 /** SRP state flags */
856 /** Underlying socket is open */
857 SRP_STATE_SOCKET_OPEN
= 0x0001,
858 /** Session is logged in */
859 SRP_STATE_LOGGED_IN
= 0x0002,
862 /** Maximum number of SRP retry attempts */
863 #define SRP_MAX_RETRIES 3
865 extern int srp_attach ( struct scsi_device
*scsi
, const char *root_path
);
866 extern void srp_detach ( struct scsi_device
*scsi
);
868 #endif /* _GPXE_SRP_H */