7 * Fibre Channel Extended Link Services
11 FILE_LICENCE ( GPL2_OR_LATER );
15 #include <ipxe/tables.h>
16 #include <ipxe/refcnt.h>
17 #include <ipxe/list.h>
18 #include <ipxe/process.h>
19 #include <ipxe/interface.h>
21 /** Fibre Channel ELS frame common parameters */
22 struct fc_els_frame_common {
23 /** ELS command code */
27 } __attribute__ (( packed ));
29 /** Fibre Channel ELS command codes */
30 enum fc_els_command_code {
31 FC_ELS_LS_RJT = 0x01, /**< Link Service Reject */
32 FC_ELS_LS_ACC = 0x02, /**< Link Service Accept */
33 FC_ELS_PLOGI = 0x03, /**< Port Login */
34 FC_ELS_FLOGI = 0x04, /**< Fabric Login */
35 FC_ELS_LOGO = 0x05, /**< Logout */
36 FC_ELS_RTV = 0x0e, /**< Read Timeout Value */
37 FC_ELS_ECHO = 0x10, /**< Echo */
38 FC_ELS_PRLI = 0x20, /**< Process Login */
39 FC_ELS_PRLO = 0x21, /**< Process Logout */
42 /** A Fibre Channel LS_RJT frame */
43 struct fc_ls_rjt_frame {
44 /** ELS command code */
50 /** Reason code explanation */
54 } __attribute__ (( packed ));
56 /** Fibre Channel ELS rejection reason codes */
57 enum fc_els_reject_reason {
58 /** Invalid ELS command code */
59 FC_ELS_RJT_INVALID_COMMAND = 0x01,
61 FC_ELS_RJT_ILLOGICAL = 0x03,
63 FC_ELS_RJT_BUSY = 0x05,
65 FC_ELS_RJT_PROTOCOL = 0x07,
66 /** Unable to perform command request */
67 FC_ELS_RJT_UNABLE = 0x09,
68 /** Command not supported */
69 FC_ELS_RJT_UNSUPPORTED = 0x0b,
70 /** Command already in progress */
71 FC_ELS_RJT_IN_PROGRESS = 0x0e,
74 /** Fibre Channel "common" service parameters */
75 struct fc_login_common {
78 /** Buffer-to-buffer credit */
87 /** Maximum number of concurrent sequences */
89 /** Relative offset by info category */
93 /** Resource allocation timeout value */
97 /** Error detection timeout value */
99 } __attribute__ (( packed ));
101 /** Fibre Channel default login version */
102 #define FC_LOGIN_VERSION 0x2020
104 /** Fibre Channel default buffer-to-buffer credit */
105 #define FC_LOGIN_DEFAULT_B2B 10
107 /** Continuously increasing relative offset */
108 #define FC_LOGIN_CONTINUOUS_OFFSET 0x8000
111 #define FC_LOGIN_CLEAN 0x8000
113 /** Multiple N_Port_ID support */
114 #define FC_LOGIN_MULTI_N 0x8000
116 /** Random relative offset */
117 #define FC_LOGIN_RANDOM_OFFSET 0x4000
119 /** Virtual fabrics */
120 #define FC_LOGIN_VIRTUAL 0x4000
122 /** Vendor version level */
123 #define FC_LOGIN_VENDOR 0x2000
125 /** Multiple N_Port_ID support */
126 #define FC_LOGIN_MULTI_F 0x2000
128 /** Forwarder port */
129 #define FC_LOGIN_F_PORT 0x1000
131 /** Alternative credit management */
132 #define FC_LOGIN_ALT_CREDIT 0x0800
134 /** Name server session started */
135 #define FC_LOGIN_NSS_STARTED 0x0800
137 /** Begin name server session */
138 #define FC_LOGIN_NSS_BEGIN 0x0400
140 /** 1ns error detection timer resolution */
141 #define FC_LOGIN_HIRES_E_D_TOV 0x0400
143 /** Broadcast supported */
144 #define FC_LOGIN_BROADCAST 0x0100
146 /** Query buffer conditions */
147 #define FC_LOGIN_QUERY_BUF 0x0040
150 #define FC_LOGIN_SECURITY 0x0020
152 /** Clock sync primitive capable */
153 #define FC_LOGIN_CLOCK_SYNC 0x0010
155 /** Short R_T timeout */
156 #define FC_LOGIN_SHORT_R_T_TOV 0x0008
158 /** Dynamic half duplex */
159 #define FC_LOGIN_DHD 0x0004
161 /** Continuously increasing sequence count */
162 #define FC_LOGIN_CONTINUOUS_SEQ 0x0002
165 #define FC_LOGIN_PAYLOAD 0x0001
167 /** Fibre Channel default MTU */
168 #define FC_LOGIN_DEFAULT_MTU 1452
170 /** Default maximum number of concurrent sequences */
171 #define FC_LOGIN_DEFAULT_MAX_SEQ 255
173 /** Default relative offset by info category */
174 #define FC_LOGIN_DEFAULT_REL_OFFS 0x1f
176 /** Default E_D timeout value */
177 #define FC_LOGIN_DEFAULT_E_D_TOV 2000
179 /** Fibre Channel class-specific login parameters */
180 struct fc_login_class {
183 /** Initiator flags */
185 /** Recipient flags */
186 uint16_t recip_flags;
187 /** Receive data field size */
189 /** Maximum number of concurrent sequences */
191 /** End-to-end credit */
195 /** Maximum number of open sequences per exchange */
196 uint8_t max_seq_per_xchg;
198 uint8_t reserved1[2];
199 } __attribute__ (( packed ));
202 #define FC_LOGIN_CLASS_VALID 0x8000
204 /** Sequential delivery requested */
205 #define FC_LOGIN_CLASS_SEQUENTIAL 0x0800
207 /** A Fibre Channel FLOGI/PLOGI frame */
208 struct fc_login_frame {
209 /** ELS command code */
213 /** Common service parameters */
214 struct fc_login_common common;
216 struct fc_name port_wwn;
218 struct fc_name node_wwn;
219 /** Class 1 service parameters */
220 struct fc_login_class class1;
221 /** Class 2 service parameters */
222 struct fc_login_class class2;
223 /** Class 3 service parameters */
224 struct fc_login_class class3;
225 /** Class 4 service parameters */
226 struct fc_login_class class4;
227 /** Vendor version level */
228 uint8_t vendor_version[16];
229 } __attribute__ (( packed ));
231 /** A Fibre Channel LOGO request frame */
232 struct fc_logout_request_frame {
233 /** ELS command code */
238 struct fc_port_id port_id;
240 struct fc_name port_wwn;
241 } __attribute__ (( packed ));
243 /** A Fibre Channel LOGO response frame */
244 struct fc_logout_response_frame {
245 /** ELS command code */
249 } __attribute__ (( packed ));
251 /** A Fibre Channel PRLI service parameter page */
252 struct fc_prli_page {
255 /** Type code extension */
257 /** Flags and response code */
260 uint32_t reserved[2];
261 } __attribute__ (( packed ));
263 /** Establish image pair */
264 #define FC_PRLI_ESTABLISH 0x2000
266 /** Response code mask */
267 #define FC_PRLI_RESPONSE_MASK 0x0f00
269 /** Request was executed successfully */
270 #define FC_PRLI_RESPONSE_SUCCESS 0x0100
272 /** A Fibre Channel PRLI frame */
273 struct fc_prli_frame {
274 /** ELS command code */
278 /** Payload length */
280 /** Service parameter page */
281 struct fc_prli_page page;
282 } __attribute__ (( packed ));
284 /** A Fibre Channel RTV request frame */
285 struct fc_rtv_request_frame {
286 /** ELS command code */
290 } __attribute__ (( packed ));
292 /** A Fibre Channel RTV response frame */
293 struct fc_rtv_response_frame {
294 /** ELS command code */
297 uint8_t reserved0[3];
298 /** Resource allocation timeout value */
300 /** Error detection timeout value */
302 /** Timeout qualifier */
306 } __attribute__ (( packed ));
308 /** 1ns error detection timer resolution */
309 #define FC_RTV_HIRES_E_D_TOV 0x0400
311 /** Short R_T timeout */
312 #define FC_RTV_SHORT_R_T_TOV 0x0008
314 /** A Fibre Channel ECHO frame */
315 struct fc_echo_frame_header {
316 /** ELS command code */
320 } __attribute__ (( packed ));
322 /** A Fibre Channel extended link services transaction */
324 /** Reference count */
325 struct refcnt refcnt;
326 /** Job control interface */
327 struct interface job;
328 /** Fibre Channel exchange */
329 struct interface xchg;
330 /** Request sending process */
331 struct process process;
333 /** Fibre Channel port */
334 struct fc_port *port;
336 struct fc_port_id port_id;
338 struct fc_port_id peer_port_id;
339 /** ELS handler, if known */
340 struct fc_els_handler *handler;
345 /** Fibre Channel extended link services transaction flags */
347 /** ELS transaction is a request */
348 FC_ELS_REQUEST = 0x0001,
351 /** A Fibre Channel extended link services handler */
352 struct fc_els_handler {
355 /** Transmit ELS frame
357 * @v els Fibre Channel ELS transaction
358 * @ret rc Return status code
360 int ( * tx ) ( struct fc_els *els );
361 /** Receive ELS frame
363 * @v els Fibre Channel ELS transaction
365 * @v len Length of ELS frame
366 * @ret rc Return status code
368 int ( * rx ) ( struct fc_els *els, void *data, size_t len );
371 * @v els Fibre Channel ELS transaction
373 * @v len Length of ELS frame
374 * @ret rc Return status code
376 int ( * detect ) ( struct fc_els *els, const void *data, size_t len );
379 /** Fibre Channel ELS handler table */
380 #define FC_ELS_HANDLERS __table ( struct fc_els_handler, "fc_els_handlers" )
382 /** Declare a Fibre Channel ELS handler */
383 #define __fc_els_handler __table_entry ( FC_ELS_HANDLERS, 01 )
385 /** A Fibre Channel ELS PRLI descriptor */
386 struct fc_els_prli_descriptor {
387 /** Upper-layer protocol type */
389 /** Service parameter length */
391 /** Fibre Channel ELS handler */
392 struct fc_els_handler *handler;
395 /** Fibre Channel ELS PRLI descriptor table */
396 #define FC_ELS_PRLI_DESCRIPTORS \
397 __table ( struct fc_els_prli_descriptor, "fc_els_prli_descriptors" )
399 /** Declare a Fibre Channel ELS PRLI descriptor */
400 #define __fc_els_prli_descriptor __table_entry ( FC_ELS_PRLI_DESCRIPTORS, 01 )
403 * Check if Fibre Channel ELS transaction is a request
405 * @v els Fibre Channel ELS transaction
406 * @ret is_request ELS transaction is a request
408 static inline int fc_els_is_request ( struct fc_els *els ) {
409 return ( els->flags & FC_ELS_REQUEST );
413 * Calculate ELS command to transmit
415 * @v els Fibre Channel ELS transaction
416 * @v request_command Command for requests
417 * @v command Command to transmit
419 static inline unsigned int fc_els_tx_command ( struct fc_els *els,
420 unsigned int request_command ) {
421 return ( fc_els_is_request ( els ) ? request_command : FC_ELS_LS_ACC );
424 extern int fc_els_tx ( struct fc_els *els, const void *data, size_t len );
425 extern int fc_els_request ( struct interface *job, struct fc_port *port,
426 struct fc_port_id *peer_port_id,
427 struct fc_els_handler *handler );
428 extern int fc_els_flogi ( struct interface *parent, struct fc_port *port );
429 extern int fc_els_plogi ( struct interface *parent, struct fc_port *port,
430 struct fc_port_id *peer_port_id );
431 extern int fc_els_logo ( struct interface *parent, struct fc_port *port,
432 struct fc_port_id *peer_port_id );
433 extern int fc_els_prli ( struct interface *parent, struct fc_port *port,
434 struct fc_port_id *peer_port_id, unsigned int type );
435 extern int fc_els_prli_tx ( struct fc_els *els,
436 struct fc_els_prli_descriptor *descriptor,
438 extern int fc_els_prli_rx ( struct fc_els *els,
439 struct fc_els_prli_descriptor *descriptor,
440 void *data, size_t len );
441 extern int fc_els_prli_detect ( struct fc_els *els __unused,
442 struct fc_els_prli_descriptor *descriptor,
443 const void *data, size_t len );
445 #endif /* _IPXE_FCELS_H */