1 #ifndef _IPXE_FCELS_H
2 #define _IPXE_FCELS_H
3 
4 /**
5  * @file
6  *
7  * Fibre Channel Extended Link Services
8  *
9  */
10 
11 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 
13 #include <stdint.h>
14 #include <ipxe/fc.h>
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>
20 
21 /** Fibre Channel ELS frame common parameters */
22 struct fc_els_frame_common {
23 	/** ELS command code */
24 	uint8_t command;
25 	/** Reserved */
26 	uint8_t reserved[3];
27 } __attribute__ (( packed ));
28 
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 */
40 };
41 
42 /** A Fibre Channel LS_RJT frame */
43 struct fc_ls_rjt_frame {
44 	/** ELS command code */
45 	uint8_t command;
46 	/** Reserved */
47 	uint8_t reserved[4];
48 	/** Reason code */
49 	uint8_t reason;
50 	/** Reason code explanation */
51 	uint8_t explanation;
52 	/** Vendor unique */
53 	uint8_t vendor;
54 } __attribute__ (( packed ));
55 
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,
60 	/** Logical error */
61 	FC_ELS_RJT_ILLOGICAL = 0x03,
62 	/** Logical busy */
63 	FC_ELS_RJT_BUSY = 0x05,
64 	/** Protocol error */
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,
72 };
73 
74 /** Fibre Channel "common" service parameters */
75 struct fc_login_common {
76 	/** Login version */
77 	uint16_t version;
78 	/** Buffer-to-buffer credit */
79 	uint16_t credit;
80 	/** Flags */
81 	uint16_t flags;
82 	/** Receive size */
83 	uint16_t mtu;
84 	/** "Common"?! */
85 	union {
86 		struct {
87 			/** Maximum number of concurrent sequences */
88 			uint16_t max_seq;
89 			/** Relative offset by info category */
90 			uint16_t rel_offs;
91 		} plogi;
92 		struct {
93 			/** Resource allocation timeout value */
94 			uint32_t r_a_tov;
95 		} flogi;
96 	} u;
97 	/** Error detection timeout value */
98 	uint32_t e_d_tov;
99 } __attribute__ (( packed ));
100 
101 /** Fibre Channel default login version */
102 #define FC_LOGIN_VERSION 0x2020
103 
104 /** Fibre Channel default buffer-to-buffer credit */
105 #define FC_LOGIN_DEFAULT_B2B 10
106 
107 /** Continuously increasing relative offset */
108 #define FC_LOGIN_CONTINUOUS_OFFSET 0x8000
109 
110 /** Clean address */
111 #define FC_LOGIN_CLEAN 0x8000
112 
113 /** Multiple N_Port_ID support */
114 #define FC_LOGIN_MULTI_N 0x8000
115 
116 /** Random relative offset */
117 #define FC_LOGIN_RANDOM_OFFSET 0x4000
118 
119 /** Virtual fabrics */
120 #define FC_LOGIN_VIRTUAL 0x4000
121 
122 /** Vendor version level */
123 #define FC_LOGIN_VENDOR 0x2000
124 
125 /** Multiple N_Port_ID support */
126 #define FC_LOGIN_MULTI_F 0x2000
127 
128 /** Forwarder port */
129 #define FC_LOGIN_F_PORT 0x1000
130 
131 /** Alternative credit management */
132 #define FC_LOGIN_ALT_CREDIT 0x0800
133 
134 /** Name server session started */
135 #define FC_LOGIN_NSS_STARTED 0x0800
136 
137 /** Begin name server session */
138 #define FC_LOGIN_NSS_BEGIN 0x0400
139 
140 /** 1ns error detection timer resolution */
141 #define FC_LOGIN_HIRES_E_D_TOV 0x0400
142 
143 /** Broadcast supported */
144 #define FC_LOGIN_BROADCAST 0x0100
145 
146 /** Query buffer conditions */
147 #define FC_LOGIN_QUERY_BUF 0x0040
148 
149 /** Security */
150 #define FC_LOGIN_SECURITY 0x0020
151 
152 /** Clock sync primitive capable */
153 #define FC_LOGIN_CLOCK_SYNC 0x0010
154 
155 /** Short R_T timeout */
156 #define FC_LOGIN_SHORT_R_T_TOV 0x0008
157 
158 /** Dynamic half duplex */
159 #define FC_LOGIN_DHD 0x0004
160 
161 /** Continuously increasing sequence count */
162 #define FC_LOGIN_CONTINUOUS_SEQ 0x0002
163 
164 /** Payload */
165 #define FC_LOGIN_PAYLOAD 0x0001
166 
167 /** Fibre Channel default MTU */
168 #define FC_LOGIN_DEFAULT_MTU 1452
169 
170 /** Default maximum number of concurrent sequences */
171 #define FC_LOGIN_DEFAULT_MAX_SEQ 255
172 
173 /** Default relative offset by info category */
174 #define FC_LOGIN_DEFAULT_REL_OFFS 0x1f
175 
176 /** Default E_D timeout value */
177 #define FC_LOGIN_DEFAULT_E_D_TOV 2000
178 
179 /** Fibre Channel class-specific login parameters */
180 struct fc_login_class {
181 	/** Flags */
182 	uint16_t flags;
183 	/** Initiator flags */
184 	uint16_t init_flags;
185 	/** Recipient flags */
186 	uint16_t recip_flags;
187 	/** Receive data field size */
188 	uint16_t mtu;
189 	/** Maximum number of concurrent sequences */
190 	uint16_t max_seq;
191 	/** End-to-end credit */
192 	uint16_t credit;
193 	/** Reserved */
194 	uint8_t reserved0;
195 	/** Maximum number of open sequences per exchange */
196 	uint8_t max_seq_per_xchg;
197 	/** Reserved */
198 	uint8_t reserved1[2];
199 } __attribute__ (( packed ));
200 
201 /** Class valid */
202 #define FC_LOGIN_CLASS_VALID 0x8000
203 
204 /** Sequential delivery requested */
205 #define FC_LOGIN_CLASS_SEQUENTIAL 0x0800
206 
207 /** A Fibre Channel FLOGI/PLOGI frame */
208 struct fc_login_frame {
209 	/** ELS command code */
210 	uint8_t command;
211 	/** Reserved */
212 	uint8_t reserved[3];
213 	/** Common service parameters */
214 	struct fc_login_common common;
215 	/** Port name */
216 	struct fc_name port_wwn;
217 	/** Node name */
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 ));
230 
231 /** A Fibre Channel LOGO request frame */
232 struct fc_logout_request_frame {
233 	/** ELS command code */
234 	uint8_t command;
235 	/** Reserved */
236 	uint8_t reserved[4];
237 	/** Port ID */
238 	struct fc_port_id port_id;
239 	/** Port name */
240 	struct fc_name port_wwn;
241 } __attribute__ (( packed ));
242 
243 /** A Fibre Channel LOGO response frame */
244 struct fc_logout_response_frame {
245 	/** ELS command code */
246 	uint8_t command;
247 	/** Reserved */
248 	uint8_t reserved[3];
249 } __attribute__ (( packed ));
250 
251 /** A Fibre Channel PRLI service parameter page */
252 struct fc_prli_page {
253 	/** Type code */
254 	uint8_t type;
255 	/** Type code extension */
256 	uint8_t type_ext;
257 	/** Flags and response code */
258 	uint16_t flags;
259 	/** Reserved */
260 	uint32_t reserved[2];
261 } __attribute__ (( packed ));
262 
263 /** Establish image pair */
264 #define FC_PRLI_ESTABLISH 0x2000
265 
266 /** Response code mask */
267 #define FC_PRLI_RESPONSE_MASK 0x0f00
268 
269 /** Request was executed successfully */
270 #define FC_PRLI_RESPONSE_SUCCESS 0x0100
271 
272 /** A Fibre Channel PRLI frame */
273 struct fc_prli_frame {
274 	/** ELS command code */
275 	uint8_t command;
276 	/** Page length */
277 	uint8_t page_len;
278 	/** Payload length */
279 	uint16_t len;
280 	/** Service parameter page */
281 	struct fc_prli_page page;
282 } __attribute__ (( packed ));
283 
284 /** A Fibre Channel RTV request frame */
285 struct fc_rtv_request_frame {
286 	/** ELS command code */
287 	uint8_t command;
288 	/** Reserved */
289 	uint8_t reserved[3];
290 } __attribute__ (( packed ));
291 
292 /** A Fibre Channel RTV response frame */
293 struct fc_rtv_response_frame {
294 	/** ELS command code */
295 	uint8_t command;
296 	/** Reserved */
297 	uint8_t reserved0[3];
298 	/** Resource allocation timeout value */
299 	uint32_t r_a_tov;
300 	/** Error detection timeout value */
301 	uint32_t e_d_tov;
302 	/** Timeout qualifier */
303 	uint16_t flags;
304 	/** Reserved */
305 	uint16_t reserved1;
306 } __attribute__ (( packed ));
307 
308 /** 1ns error detection timer resolution */
309 #define FC_RTV_HIRES_E_D_TOV 0x0400
310 
311 /** Short R_T timeout */
312 #define FC_RTV_SHORT_R_T_TOV 0x0008
313 
314 /** A Fibre Channel ECHO frame */
315 struct fc_echo_frame_header {
316 	/** ELS command code */
317 	uint8_t command;
318 	/** Reserved */
319 	uint8_t reserved[3];
320 } __attribute__ (( packed ));
321 
322 /** A Fibre Channel extended link services transaction */
323 struct fc_els {
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;
332 
333 	/** Fibre Channel port */
334 	struct fc_port *port;
335 	/** Local port ID */
336 	struct fc_port_id port_id;
337 	/** Peer port ID */
338 	struct fc_port_id peer_port_id;
339 	/** ELS handler, if known */
340 	struct fc_els_handler *handler;
341 	/** Flags */
342 	unsigned int flags;
343 };
344 
345 /** Fibre Channel extended link services transaction flags */
346 enum fc_els_flags {
347 	/** ELS transaction is a request */
348 	FC_ELS_REQUEST = 0x0001,
349 };
350 
351 /** A Fibre Channel extended link services handler */
352 struct fc_els_handler {
353 	/** Name */
354 	const char *name;
355 	/** Transmit ELS frame
356 	 *
357 	 * @v els		Fibre Channel ELS transaction
358 	 * @ret rc		Return status code
359 	 */
360 	int ( * tx ) ( struct fc_els *els );
361 	/** Receive ELS frame
362 	 *
363 	 * @v els		Fibre Channel ELS transaction
364 	 * @v data		ELS frame
365 	 * @v len		Length of ELS frame
366 	 * @ret rc		Return status code
367 	 */
368 	int ( * rx ) ( struct fc_els *els, void *data, size_t len );
369 	/** Detect ELS frame
370 	 *
371 	 * @v els		Fibre Channel ELS transaction
372 	 * @v data		ELS frame
373 	 * @v len		Length of ELS frame
374 	 * @ret rc		Return status code
375 	 */
376 	int ( * detect ) ( struct fc_els *els, const void *data, size_t len );
377 };
378 
379 /** Fibre Channel ELS handler table */
380 #define FC_ELS_HANDLERS __table ( struct fc_els_handler, "fc_els_handlers" )
381 
382 /** Declare a Fibre Channel ELS handler */
383 #define __fc_els_handler __table_entry ( FC_ELS_HANDLERS, 01 )
384 
385 /** A Fibre Channel ELS PRLI descriptor */
386 struct fc_els_prli_descriptor {
387 	/** Upper-layer protocol type */
388 	unsigned int type;
389 	/** Service parameter length */
390 	size_t param_len;
391 	/** Fibre Channel ELS handler */
392 	struct fc_els_handler *handler;
393 };
394 
395 /** Fibre Channel ELS PRLI descriptor table */
396 #define FC_ELS_PRLI_DESCRIPTORS \
397 	__table ( struct fc_els_prli_descriptor, "fc_els_prli_descriptors" )
398 
399 /** Declare a Fibre Channel ELS PRLI descriptor */
400 #define __fc_els_prli_descriptor __table_entry ( FC_ELS_PRLI_DESCRIPTORS, 01 )
401 
402 /**
403  * Check if Fibre Channel ELS transaction is a request
404  *
405  * @v els		Fibre Channel ELS transaction
406  * @ret is_request	ELS transaction is a request
407  */
fc_els_is_request(struct fc_els * els)408 static inline int fc_els_is_request ( struct fc_els *els ) {
409 	return ( els->flags & FC_ELS_REQUEST );
410 }
411 
412 /**
413  * Calculate ELS command to transmit
414  *
415  * @v els		Fibre Channel ELS transaction
416  * @v request_command	Command for requests
417  * @v command		Command to transmit
418  */
fc_els_tx_command(struct fc_els * els,unsigned int request_command)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 );
422 }
423 
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,
437 			    void *param );
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 );
444 
445 #endif /* _IPXE_FCELS_H */
446