iPXE
fcels.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26#include <stdint.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
30#include <assert.h>
31#include <byteswap.h>
32#include <ipxe/interface.h>
33#include <ipxe/xfer.h>
34#include <ipxe/iobuf.h>
35#include <ipxe/process.h>
36#include <ipxe/fc.h>
37#include <ipxe/fcels.h>
38
39/** @file
40 *
41 * Fibre Channel Extended Link Services
42 *
43 */
44
45/** Fibre Channel ELS transaction debug message format */
46#define FCELS_FMT "FCELS %s %s %s %s"
47
48/** Fibre Channel ELS transaction debug message arguments */
49#define FCELS_ARGS( els ) \
50 (els)->port->name, \
51 ( (els)->handler ? (els)->handler->name : "unknown ELS" ), \
52 ( fc_els_is_request ( els ) ? "to" : "from" ), \
53 fc_id_ntoa ( &(els)->peer_port_id )
54
55struct fc_els_handler fc_els_unknown_handler __fc_els_handler;
56
57/**
58 * Free Fibre Channel ELS transaction
59 *
60 * @v refcnt Reference count
61 */
62static void fc_els_free ( struct refcnt *refcnt ) {
63 struct fc_els *els = container_of ( refcnt, struct fc_els, refcnt );
64
65 assert ( ! process_running ( &els->process ) );
66 fc_port_put ( els->port );
67 free ( els );
68}
69
70/**
71 * Close Fibre Channel ELS transaction
72 *
73 * @v els Fibre Channel ELS transaction
74 * @v rc Reason for close
75 */
76static void fc_els_close ( struct fc_els *els, int rc ) {
77
78 if ( rc != 0 ) {
79 DBGC ( els, FCELS_FMT " complete (%s)\n",
80 FCELS_ARGS ( els ), strerror ( rc ) );
81 }
82
83 /* Stop process */
84 process_del ( &els->process );
85
86 /* Shut down interfaces */
87 intf_shutdown ( &els->xchg, rc );
88 intf_shutdown ( &els->job, rc );
89}
90
91/**
92 * Detect Fibre Channel ELS frame handler
93 *
94 * @v els Fibre Channel ELS transaction
95 * @v command ELS command code
96 * @ret handler ELS handler, or NULL
97 */
98static struct fc_els_handler * fc_els_detect ( struct fc_els *els,
99 const void *data,
100 size_t len ) {
101 const struct fc_els_frame_common *frame = data;
102 struct fc_els_handler *handler;
103 int rc;
104
105 /* Sanity check */
106 if ( len < sizeof ( *frame ) )
107 return NULL;
108
109 /* Try each handler in turn */
111 if ( ( rc = handler->detect ( els, data, len ) ) == 0 )
112 return handler;
113 }
114
115 return NULL;
116}
117
118/**
119 * Transmit Fibre Channel ELS frame
120 *
121 * @v els Fibre Channel ELS transaction
122 * @v data Data to transmit
123 * @v len Length of data
124 * @ret rc Return status code
125 */
126int fc_els_tx ( struct fc_els *els, const void *data, size_t len ) {
127 struct xfer_metadata meta;
128 struct sockaddr_fc dest;
129 int rc;
130
131 DBGC2 ( els, FCELS_FMT " transmitting:\n", FCELS_ARGS ( els ) );
132 DBGC2_HDA ( els, 0, data, len );
133
134 /* Construct metadata */
135 memset ( &meta, 0, sizeof ( meta ) );
136 meta.flags = ( fc_els_is_request ( els ) ?
138 meta.dest = fc_fill_sockaddr ( &dest, &els->peer_port_id );
139
140 /* Transmit frame */
141 if ( ( rc = xfer_deliver_raw_meta ( &els->xchg, data, len,
142 &meta ) ) != 0 ) {
143 DBGC ( els, FCELS_FMT " could not deliver frame: %s\n",
144 FCELS_ARGS ( els ), strerror ( rc ) );
145 return rc;
146 }
147
148 return 0;
149}
150
151/**
152 * Receive Fibre Channel ELS frame
153 *
154 * @v els Fibre Channel ELS transaction
155 * @v iobuf I/O buffer
156 * @v meta Data transfer metadata
157 * @ret rc Return status code
158 */
159static int fc_els_rx ( struct fc_els *els,
160 struct io_buffer *iobuf,
161 struct xfer_metadata *meta ) {
162 struct sockaddr_fc *src = ( ( struct sockaddr_fc * ) meta->src );
163 struct sockaddr_fc *dest = ( ( struct sockaddr_fc * ) meta->dest );
165 size_t len = iob_len ( iobuf );
166 int rc;
167
168 /* Sanity check */
169 if ( len < sizeof ( *frame ) ) {
170 DBGC ( els, FCELS_FMT " received underlength frame:\n",
171 FCELS_ARGS ( els ) );
172 DBGC_HDA ( els, 0, iobuf->data, len );
173 rc = -EINVAL;
174 goto done;
175 }
176 frame = iobuf->data;
177 if ( ! src ) {
178 DBGC ( els, FCELS_FMT " received frame missing source "
179 "address:\n", FCELS_ARGS ( els ) );
180 rc = -EINVAL;
181 goto done;
182 }
183 if ( ! dest ) {
184 DBGC ( els, FCELS_FMT " received frame missing destination "
185 "address:\n", FCELS_ARGS ( els ) );
186 rc = -EINVAL;
187 goto done;
188 }
189
190 /* Check for rejection responses */
191 if ( fc_els_is_request ( els ) &&
192 ( frame->command != FC_ELS_LS_ACC ) ) {
193 DBGC ( els, FCELS_FMT " rejected:\n", FCELS_ARGS ( els ) );
194 DBGC_HDA ( els, 0, frame, len );
195 rc = -EACCES;
196 goto done;
197 }
198
199 /* Update port IDs */
200 memcpy ( &els->port_id, &dest->sfc_port_id, sizeof ( els->port_id ) );
201 memcpy ( &els->peer_port_id, &src->sfc_port_id,
202 sizeof ( els->peer_port_id ) );
203
204 /* Determine handler, if necessary */
205 if ( ! els->handler )
206 els->handler = fc_els_detect ( els, frame, len );
207 if ( ! els->handler )
208 els->handler = &fc_els_unknown_handler;
209
210 DBGC2 ( els, FCELS_FMT " received:\n", FCELS_ARGS ( els ) );
211 DBGC2_HDA ( els, 0, frame, len );
212
213 /* Handle received frame */
214 if ( ( rc = els->handler->rx ( els, frame, len ) ) != 0 ) {
215 DBGC ( els, FCELS_FMT " could not handle received frame: "
216 "%s\n", FCELS_ARGS ( els ), strerror ( rc ) );
217 DBGC_HDA ( els, 0, frame, len );
218 goto done;
219 }
220
221 done:
222 /* Free I/O buffer */
223 free_iob ( iobuf );
224
225 /* Close transaction */
226 fc_els_close ( els, rc );
227
228 return rc;
229}
230
231/** Fibre Channel ELS exchange interface operations */
233 INTF_OP ( xfer_deliver, struct fc_els *, fc_els_rx ),
234 INTF_OP ( intf_close, struct fc_els *, fc_els_close ),
235};
236
237/** Fibre Channel ELS exchange interface descriptor */
239 INTF_DESC ( struct fc_els, xchg, fc_els_xchg_op );
240
241/** Fibre Channel ELS job control interface operations */
243 INTF_OP ( intf_close, struct fc_els *, fc_els_close ),
244};
245
246/** Fibre Channel ELS job control interface descriptor */
248 INTF_DESC ( struct fc_els, job, fc_els_job_op );
249
250/**
251 * Fibre Channel ELS process
252 *
253 * @v els Fibre Channel ELS transaction
254 */
255static void fc_els_step ( struct fc_els *els ) {
256 int xchg_id;
257 int rc;
258
259 /* Sanity check */
260 assert ( fc_els_is_request ( els ) );
261
262 /* Create exchange */
263 if ( ( xchg_id = fc_xchg_originate ( &els->xchg, els->port,
264 &els->peer_port_id,
265 FC_TYPE_ELS ) ) < 0 ) {
266 rc = xchg_id;
267 DBGC ( els, FCELS_FMT " could not create exchange: %s\n",
268 FCELS_ARGS ( els ), strerror ( rc ) );
269 fc_els_close ( els, rc );
270 return;
271 }
272
273 /* Transmit request */
274 if ( ( rc = els->handler->tx ( els ) ) != 0 ) {
275 DBGC ( els, FCELS_FMT " could not transmit request: %s\n",
276 FCELS_ARGS ( els ), strerror ( rc ) );
277 fc_els_close ( els, rc );
278 return;
279 }
280}
281
282/** Fibre Channel ELS process descriptor */
285
286/**
287 * Create ELS transaction
288 *
289 * @v port Fibre Channel port
290 * @v port_id Local port ID
291 * @v peer_port_id Peer port ID
292 * @ret els Fibre Channel ELS transaction, or NULL
293 */
294static struct fc_els * fc_els_create ( struct fc_port *port,
295 struct fc_port_id *port_id,
296 struct fc_port_id *peer_port_id ) {
297 struct fc_els *els;
298
299 /* Allocate and initialise structure */
300 els = zalloc ( sizeof ( *els ) );
301 if ( ! els )
302 return NULL;
303 ref_init ( &els->refcnt, fc_els_free );
304 intf_init ( &els->job, &fc_els_job_desc, &els->refcnt );
305 intf_init ( &els->xchg, &fc_els_xchg_desc, &els->refcnt );
307 &els->refcnt );
308 els->port = fc_port_get ( port );
309 memcpy ( &els->port_id, port_id, sizeof ( els->port_id ) );
311 sizeof ( els->peer_port_id ) );
312 return els;
313}
314
315/**
316 * Create ELS request
317 *
318 * @v job Parent job-control interface
319 * @v port Fibre Channel port
320 * @v peer_port_id Peer port ID
321 * @v handler ELS handler
322 * @ret rc Return status code
323 */
324int fc_els_request ( struct interface *job, struct fc_port *port,
325 struct fc_port_id *peer_port_id,
326 struct fc_els_handler *handler ) {
327 struct fc_els *els;
328
329 /* Allocate and initialise structure */
330 els = fc_els_create ( port, &port->port_id, peer_port_id );
331 if ( ! els )
332 return -ENOMEM;
333 els->handler = handler;
334 els->flags = FC_ELS_REQUEST;
335 process_add ( &els->process );
336
337 /* Attach to parent job interface, mortalise self, and return */
338 intf_plug_plug ( &els->job, job );
339 ref_put ( &els->refcnt );
340 return 0;
341}
342
343/**
344 * Create ELS response
345 *
346 * @v xchg Exchange interface
347 * @v port Fibre Channel port
348 * @v port_id Local port ID
349 * @v peer_port_id Peer port ID
350 * @ret rc Return status code
351 */
352static int fc_els_respond ( struct interface *xchg, struct fc_port *port,
353 struct fc_port_id *port_id,
354 struct fc_port_id *peer_port_id ) {
355 struct fc_els *els;
356
357 /* Allocate and initialise structure */
359 if ( ! els )
360 return -ENOMEM;
361
362 /* Attach to exchange interface, mortalise self, and return */
363 intf_plug_plug ( &els->xchg, xchg );
364 ref_put ( &els->refcnt );
365 return 0;
366}
367
368/** Fibre Channel ELS responder */
369struct fc_responder fc_els_responder __fc_responder = {
370 .type = FC_TYPE_ELS,
371 .respond = fc_els_respond,
372};
373
374/******************************************************************************
375 *
376 * Unknown ELS handler
377 *
378 ******************************************************************************
379 */
380
381/**
382 * Transmit unknown ELS request
383 *
384 * @v els Fibre Channel ELS transaction
385 * @ret rc Return status code
386 */
387static int fc_els_unknown_tx ( struct fc_els *els __unused ) {
388 return -ENOTSUP;
389}
390
391/**
392 * Transmit unknown ELS response
393 *
394 * @v els Fibre Channel ELS transaction
395 * @ret rc Return status code
396 */
397static int fc_els_unknown_tx_response ( struct fc_els *els ) {
398 struct fc_ls_rjt_frame ls_rjt;
399
400 /* Construct LS_RJT */
401 memset ( &ls_rjt, 0, sizeof ( ls_rjt ) );
402 ls_rjt.command = FC_ELS_LS_RJT;
404
405 /* Transmit LS_RJT */
406 return fc_els_tx ( els, &ls_rjt, sizeof ( ls_rjt ) );
407}
408
409/**
410 * Receive unknown ELS
411 *
412 * @v els Fibre Channel ELS transaction
413 * @v data ELS frame
414 * @v len Length of ELS frame
415 * @ret rc Return status code
416 */
417static int fc_els_unknown_rx ( struct fc_els *els, void *data, size_t len ) {
418 int rc;
419
420 DBGC ( els, FCELS_FMT ":\n", FCELS_ARGS ( els ) );
421 DBGC_HDA ( els, 0, data, len );
422
423 /* Transmit response, if applicable */
424 if ( ! fc_els_is_request ( els ) ) {
425 if ( ( rc = fc_els_unknown_tx_response ( els ) ) != 0 )
426 return rc;
427 }
428
429 return 0;
430}
431
432/**
433 * Detect unknown ELS
434 *
435 * @v els Fibre Channel ELS transaction
436 * @v data ELS frame
437 * @v len Length of ELS frame
438 * @ret rc Return status code
439 */
440static int fc_els_unknown_detect ( struct fc_els *els __unused,
441 const void *data __unused,
442 size_t len __unused ) {
443 return -ENOTSUP;
444}
445
446/** Unknown ELS handler */
447struct fc_els_handler fc_els_unknown_handler __fc_els_handler = {
448 .name = "UNKNOWN",
449 .tx = fc_els_unknown_tx,
450 .rx = fc_els_unknown_rx,
451 .detect = fc_els_unknown_detect,
452};
453
454/******************************************************************************
455 *
456 * FLOGI
457 *
458 ******************************************************************************
459 */
460
461/**
462 * Transmit FLOGI
463 *
464 * @v els Fibre Channel ELS transaction
465 * @ret rc Return status code
466 */
467static int fc_els_flogi_tx ( struct fc_els *els ) {
468 struct fc_login_frame flogi;
469
470 /* Construct FLOGI */
471 memset ( &flogi, 0, sizeof ( flogi ) );
472 flogi.command = fc_els_tx_command ( els, FC_ELS_FLOGI );
477 memcpy ( &flogi.port_wwn, &els->port->port_wwn,
478 sizeof ( flogi.port_wwn ) );
479 memcpy ( &flogi.node_wwn, &els->port->node_wwn,
480 sizeof ( flogi.node_wwn ) );
483
484 /* Transmit FLOGI */
485 return fc_els_tx ( els, &flogi, sizeof ( flogi ) );
486}
487
488/**
489 * Receive FLOGI
490 *
491 * @v els Fibre Channel ELS transaction
492 * @v data ELS frame
493 * @v len Length of ELS frame
494 * @ret rc Return status code
495 */
496static int fc_els_flogi_rx ( struct fc_els *els, void *data, size_t len ) {
497 struct fc_login_frame *flogi;
498 int has_fabric;
499 int rc;
500
501 /* Sanity check */
502 if ( len < sizeof ( *flogi ) ) {
503 DBGC ( els, FCELS_FMT " received underlength frame:\n",
504 FCELS_ARGS ( els ) );
505 DBGC_HDA ( els, 0, data, len );
506 return -EINVAL;
507 }
508 flogi = data;
509
510 /* Extract parameters */
511 has_fabric = ( flogi->common.flags & htons ( FC_LOGIN_F_PORT ) );
512 DBGC ( els, FCELS_FMT " has node %s\n", FCELS_ARGS ( els ),
513 fc_ntoa ( &flogi->node_wwn ) );
514 DBGC ( els, FCELS_FMT " has port %s\n", FCELS_ARGS ( els ),
515 fc_ntoa ( &flogi->port_wwn ) );
516 if ( has_fabric ) {
517 DBGC ( els, FCELS_FMT " has fabric with", FCELS_ARGS ( els ) );
518 DBGC ( els, " local ID %s\n", fc_id_ntoa ( &els->port_id ) );
519 } else {
520 DBGC ( els, FCELS_FMT " has point-to-point link\n",
521 FCELS_ARGS ( els ) );
522 }
523
524 /* Log in port */
525 if ( ( rc = fc_port_login ( els->port, &els->port_id, &flogi->node_wwn,
526 &flogi->port_wwn, has_fabric ) ) != 0 ) {
527 DBGC ( els, FCELS_FMT " could not log in port: %s\n",
528 FCELS_ARGS ( els ), strerror ( rc ) );
529 return rc;
530 }
531
532 /* Send any responses to the newly-assigned peer port ID, if
533 * applicable.
534 */
535 if ( ! has_fabric ) {
537 sizeof ( els->peer_port_id ) );
538 }
539
540 /* Transmit response, if applicable */
541 if ( ! fc_els_is_request ( els ) ) {
542 if ( ( rc = fc_els_flogi_tx ( els ) ) != 0 )
543 return rc;
544 }
545
546 return 0;
547}
548
549/**
550 * Detect FLOGI
551 *
552 * @v els Fibre Channel ELS transaction
553 * @v data ELS frame
554 * @v len Length of ELS frame
555 * @ret rc Return status code
556 */
557static int fc_els_flogi_detect ( struct fc_els *els __unused, const void *data,
558 size_t len __unused ) {
559 const struct fc_login_frame *flogi = data;
560
561 /* Check for FLOGI */
562 if ( flogi->command != FC_ELS_FLOGI )
563 return -EINVAL;
564
565 return 0;
566}
567
568/** FLOGI ELS handler */
569struct fc_els_handler fc_els_flogi_handler __fc_els_handler = {
570 .name = "FLOGI",
571 .tx = fc_els_flogi_tx,
572 .rx = fc_els_flogi_rx,
573 .detect = fc_els_flogi_detect,
574};
575
576/**
577 * Create FLOGI request
578 *
579 * @v parent Parent interface
580 * @v port Fibre Channel port
581 * @ret rc Return status code
582 */
583int fc_els_flogi ( struct interface *parent, struct fc_port *port ) {
584
585 return fc_els_request ( parent, port, &fc_f_port_id,
586 &fc_els_flogi_handler );
587}
588
589/******************************************************************************
590 *
591 * PLOGI
592 *
593 ******************************************************************************
594 */
595
596/**
597 * Transmit PLOGI
598 *
599 * @v els Fibre Channel ELS transaction
600 * @ret rc Return status code
601 */
602static int fc_els_plogi_tx ( struct fc_els *els ) {
603 struct fc_login_frame plogi;
604
605 /* Construct PLOGI */
606 memset ( &plogi, 0, sizeof ( plogi ) );
607 plogi.command = fc_els_tx_command ( els, FC_ELS_PLOGI );
615 memcpy ( &plogi.port_wwn, &els->port->port_wwn,
616 sizeof ( plogi.port_wwn ) );
617 memcpy ( &plogi.node_wwn, &els->port->node_wwn,
618 sizeof ( plogi.node_wwn ) );
623 plogi.class3.max_seq_per_xchg = 1;
624
625 /* Transmit PLOGI */
626 return fc_els_tx ( els, &plogi, sizeof ( plogi ) );
627}
628
629/**
630 * Receive PLOGI
631 *
632 * @v els Fibre Channel ELS transaction
633 * @v data ELS frame
634 * @v len Length of ELS frame
635 * @ret rc Return status code
636 */
637static int fc_els_plogi_rx ( struct fc_els *els, void *data, size_t len ) {
638 struct fc_login_frame *plogi;
639 struct fc_peer *peer;
640 int rc;
641
642 /* Sanity checks */
643 if ( len < sizeof ( *plogi ) ) {
644 DBGC ( els, FCELS_FMT " received underlength frame:\n",
645 FCELS_ARGS ( els ) );
646 DBGC_HDA ( els, 0, data, len );
647 rc = -EINVAL;
648 goto err_sanity;
649 }
650 plogi = data;
651 if ( ! fc_link_ok ( &els->port->link ) ) {
652 DBGC ( els, FCELS_FMT " received while port link is down\n",
653 FCELS_ARGS ( els ) );
654 rc = -EINVAL;
655 goto err_sanity;
656 }
657
658 /* Extract parameters */
659 DBGC ( els, FCELS_FMT " has node %s\n", FCELS_ARGS ( els ),
660 fc_ntoa ( &plogi->node_wwn ) );
661 DBGC ( els, FCELS_FMT " has port %s as %s\n",
662 FCELS_ARGS ( els ), fc_ntoa ( &plogi->port_wwn ),
663 fc_id_ntoa ( &els->peer_port_id ) );
664
665 /* Get peer */
666 peer = fc_peer_get_wwn ( &plogi->port_wwn );
667 if ( ! peer ) {
668 DBGC ( els, FCELS_FMT " could not create peer\n",
669 FCELS_ARGS ( els ) );
670 rc = -ENOMEM;
671 goto err_peer_get_wwn;
672 }
673
674 /* Record login */
675 if ( ( rc = fc_peer_login ( peer, els->port,
676 &els->peer_port_id ) ) != 0 ) {
677 DBGC ( els, FCELS_FMT " could not log in peer: %s\n",
678 FCELS_ARGS ( els ), strerror ( rc ) );
679 goto err_login;
680 }
681
682 /* Transmit response, if applicable */
683 if ( ! fc_els_is_request ( els ) ) {
684 if ( ( rc = fc_els_plogi_tx ( els ) ) != 0 )
685 goto err_plogi_tx;
686 }
687
688 /* Drop temporary reference to peer */
689 fc_peer_put ( peer );
690
691 return 0;
692
693 err_plogi_tx:
694 err_login:
695 fc_peer_put ( peer );
696 err_peer_get_wwn:
697 err_sanity:
698 return rc;
699}
700
701/**
702 * Detect PLOGI
703 *
704 * @v els Fibre Channel ELS transaction
705 * @v data ELS frame
706 * @v len Length of ELS frame
707 * @ret rc Return status code
708 */
709static int fc_els_plogi_detect ( struct fc_els *els __unused, const void *data,
710 size_t len __unused ) {
711 const struct fc_login_frame *plogi = data;
712
713 /* Check for PLOGI */
714 if ( plogi->command != FC_ELS_PLOGI )
715 return -EINVAL;
716
717 return 0;
718}
719
720/** PLOGI ELS handler */
721struct fc_els_handler fc_els_plogi_handler __fc_els_handler = {
722 .name = "PLOGI",
723 .tx = fc_els_plogi_tx,
724 .rx = fc_els_plogi_rx,
725 .detect = fc_els_plogi_detect,
726};
727
728/**
729 * Create PLOGI request
730 *
731 * @v parent Parent interface
732 * @v port Fibre Channel port
733 * @v peer_port_id Peer port ID
734 * @ret rc Return status code
735 */
736int fc_els_plogi ( struct interface *parent, struct fc_port *port,
737 struct fc_port_id *peer_port_id ) {
738
739 return fc_els_request ( parent, port, peer_port_id,
740 &fc_els_plogi_handler );
741}
742
743/******************************************************************************
744 *
745 * LOGO
746 *
747 ******************************************************************************
748 */
749
750/**
751 * Transmit LOGO request
752 *
753 * @v els Fibre Channel ELS transaction
754 * @ret rc Return status code
755 */
756static int fc_els_logo_tx ( struct fc_els *els ) {
757 struct fc_logout_request_frame logo;
758
759 /* Construct LOGO */
760 memset ( &logo, 0, sizeof ( logo ) );
761 logo.command = FC_ELS_LOGO;
762 memcpy ( &logo.port_id, &els->port->port_id, sizeof ( logo.port_id ) );
763 memcpy ( &logo.port_wwn, &els->port->port_wwn,
764 sizeof ( logo.port_wwn ) );
765
766 /* Transmit LOGO */
767 return fc_els_tx ( els, &logo, sizeof ( logo ) );
768}
769
770/**
771 * Transmit LOGO response
772 *
773 * @v els Fibre Channel ELS transaction
774 * @ret rc Return status code
775 */
776static int fc_els_logo_tx_response ( struct fc_els *els ) {
777 struct fc_logout_response_frame logo;
778
779 /* Construct LOGO */
780 memset ( &logo, 0, sizeof ( logo ) );
781 logo.command = FC_ELS_LS_ACC;
782
783 /* Transmit LOGO */
784 return fc_els_tx ( els, &logo, sizeof ( logo ) );
785}
786
787/**
788 * Log out individual peer or whole port as applicable
789 *
790 * @v els Fibre Channel ELS transaction
791 * @v port_id Peer port ID
792 */
793static void fc_els_logo_logout ( struct fc_els *els,
794 struct fc_port_id *peer_port_id ) {
795 struct fc_peer *peer;
796
797 if ( ( memcmp ( peer_port_id, &fc_f_port_id,
798 sizeof ( *peer_port_id ) ) == 0 ) ||
799 ( memcmp ( peer_port_id, &els->port->port_id,
800 sizeof ( *peer_port_id ) ) == 0 ) ) {
801 fc_port_logout ( els->port, 0 );
802 } else {
803 peer = fc_peer_get_port_id ( els->port, peer_port_id );
804 if ( peer ) {
805 fc_peer_logout ( peer, 0 );
806 fc_peer_put ( peer );
807 }
808 }
809}
810
811/**
812 * Receive LOGO request
813 *
814 * @v els Fibre Channel ELS transaction
815 * @v data ELS frame
816 * @v len Length of ELS frame
817 * @ret rc Return status code
818 */
819static int fc_els_logo_rx_request ( struct fc_els *els, void *data,
820 size_t len ) {
821 struct fc_logout_request_frame *logo;
822 int rc;
823
824 /* Sanity check */
825 if ( len < sizeof ( *logo ) ) {
826 DBGC ( els, FCELS_FMT " received underlength frame:\n",
827 FCELS_ARGS ( els ) );
828 DBGC_HDA ( els, 0, data, len );
829 return -EINVAL;
830 }
831 logo = data;
832
833 DBGC ( els, FCELS_FMT " has port %s as %s\n", FCELS_ARGS ( els ),
834 fc_ntoa ( &logo->port_wwn ), fc_id_ntoa ( &logo->port_id ) );
835
836 /* Log out individual peer or whole port as applicable */
837 fc_els_logo_logout ( els, &logo->port_id );
838
839 /* Transmit repsonse */
840 if ( ( rc = fc_els_logo_tx_response ( els ) ) != 0 )
841 return rc;
842
843 return 0;
844}
845
846/**
847 * Receive LOGO response
848 *
849 * @v els Fibre Channel ELS transaction
850 * @v data ELS frame
851 * @v len Length of ELS frame
852 * @ret rc Return status code
853 */
854static int fc_els_logo_rx_response ( struct fc_els *els, void *data __unused,
855 size_t len __unused ) {
856
857 /* Log out individual peer or whole port as applicable */
858 fc_els_logo_logout ( els, &els->peer_port_id );
859
860 return 0;
861}
862
863/**
864 * Receive LOGO
865 *
866 * @v els Fibre Channel ELS transaction
867 * @v data ELS frame
868 * @v len Length of ELS frame
869 * @ret rc Return status code
870 */
871static int fc_els_logo_rx ( struct fc_els *els, void *data, size_t len ) {
872
873 if ( fc_els_is_request ( els ) ) {
874 return fc_els_logo_rx_response ( els, data, len );
875 } else {
876 return fc_els_logo_rx_request ( els, data, len );
877 }
878}
879
880/**
881 * Detect LOGO
882 *
883 * @v els Fibre Channel ELS transaction
884 * @v data ELS frame
885 * @v len Length of ELS frame
886 * @ret rc Return status code
887 */
888static int fc_els_logo_detect ( struct fc_els *els __unused, const void *data,
889 size_t len __unused ) {
890 const struct fc_logout_request_frame *logo = data;
891
892 /* Check for LOGO */
893 if ( logo->command != FC_ELS_LOGO )
894 return -EINVAL;
895
896 return 0;
897}
898
899/** LOGO ELS handler */
900struct fc_els_handler fc_els_logo_handler __fc_els_handler = {
901 .name = "LOGO",
902 .tx = fc_els_logo_tx,
903 .rx = fc_els_logo_rx,
904 .detect = fc_els_logo_detect,
905};
906
907/**
908 * Create LOGO request
909 *
910 * @v parent Parent interface
911 * @v port Fibre Channel port
912 * @v peer_port_id Peer port ID
913 * @ret rc Return status code
914 */
915int fc_els_logo ( struct interface *parent, struct fc_port *port,
916 struct fc_port_id *peer_port_id ) {
917
918 return fc_els_request ( parent, port, peer_port_id,
919 &fc_els_logo_handler );
920}
921
922/******************************************************************************
923 *
924 * PRLI
925 *
926 ******************************************************************************
927 */
928
929/**
930 * Find PRLI descriptor
931 *
932 * @v type Upper-layer protocol type
933 * @ret descriptor PRLI descriptor, or NULL
934 */
935static struct fc_els_prli_descriptor *
936fc_els_prli_descriptor ( unsigned int type ) {
937 struct fc_els_prli_descriptor *descriptor;
938
940 if ( descriptor->type == type )
941 return descriptor;
942 }
943 return NULL;
944}
945
946/**
947 * Transmit PRLI
948 *
949 * @v els Fibre Channel ELS transaction
950 * @v descriptor ELS PRLI descriptor
951 * @v param Service parameters
952 * @ret rc Return status code
953 */
954int fc_els_prli_tx ( struct fc_els *els,
955 struct fc_els_prli_descriptor *descriptor, void *param ) {
956 struct {
957 struct fc_prli_frame frame;
958 uint8_t param[descriptor->param_len];
959 } __attribute__ (( packed )) prli;
960 struct fc_ulp *ulp;
961 int rc;
962
963 /* Get ULP */
964 ulp = fc_ulp_get_port_id_type ( els->port, &els->peer_port_id,
965 descriptor->type );
966 if ( ! ulp ) {
967 rc = -ENOMEM;
968 goto err_get_port_id_type;
969 }
970
971 /* Build frame for transmission */
972 memset ( &prli, 0, sizeof ( prli ) );
973 prli.frame.command = fc_els_tx_command ( els, FC_ELS_PRLI );
974 prli.frame.page_len =
975 ( sizeof ( prli.frame.page ) + sizeof ( prli.param ) );
976 prli.frame.len = htons ( sizeof ( prli ) );
977 prli.frame.page.type = descriptor->type;
978 if ( fc_els_is_request ( els ) ) {
979 prli.frame.page.flags |= htons ( FC_PRLI_ESTABLISH );
980 } else if ( fc_link_ok ( &ulp->link ) ) {
981 prli.frame.page.flags |= htons ( FC_PRLI_ESTABLISH |
983 }
984 memcpy ( &prli.param, param, sizeof ( prli.param ) );
985
986 /* Transmit frame */
987 if ( ( rc = fc_els_tx ( els, &prli, sizeof ( prli ) ) ) != 0 )
988 goto err_tx;
989
990 /* Drop temporary reference to ULP */
991 fc_ulp_put ( ulp );
992
993 return 0;
994
995 err_tx:
996 fc_ulp_put ( ulp );
997 err_get_port_id_type:
998 return rc;
999}
1000
1001/**
1002 * Receive PRLI
1003 *
1004 * @v els Fibre Channel ELS transaction
1005 * @v descriptor ELS PRLI descriptor
1006 * @v frame ELS frame
1007 * @v len Length of ELS frame
1008 * @ret rc Return status code
1009 */
1010int fc_els_prli_rx ( struct fc_els *els,
1011 struct fc_els_prli_descriptor *descriptor,
1012 void *data, size_t len ) {
1013 struct {
1014 struct fc_prli_frame frame;
1015 uint8_t param[descriptor->param_len];
1016 } __attribute__ (( packed )) *prli;
1017 struct fc_ulp *ulp;
1018 int rc;
1019
1020 /* Sanity check */
1021 if ( len < sizeof ( *prli ) ) {
1022 DBGC ( els, FCELS_FMT " received underlength frame:\n",
1023 FCELS_ARGS ( els ) );
1024 DBGC_HDA ( els, 0, data, len );
1025 rc = -EINVAL;
1026 goto err_sanity;
1027 }
1028 prli = data;
1029
1030 DBGC ( els, FCELS_FMT " has parameters:\n", FCELS_ARGS ( els ) );
1031 DBGC_HDA ( els, 0, prli->param, sizeof ( prli->param ) );
1032
1033 /* Get ULP */
1034 ulp = fc_ulp_get_port_id_type ( els->port, &els->peer_port_id,
1035 descriptor->type );
1036 if ( ! ulp ) {
1037 rc = -ENOMEM;
1038 goto err_get_port_id_type;
1039 }
1040
1041 /* Sanity check */
1042 if ( ! fc_link_ok ( &ulp->peer->link ) ) {
1043 DBGC ( els, FCELS_FMT " received while peer link is down\n",
1044 FCELS_ARGS ( els ) );
1045 rc = -EINVAL;
1046 goto err_link;
1047 }
1048
1049 /* Log in ULP, if applicable */
1050 if ( prli->frame.page.flags & htons ( FC_PRLI_ESTABLISH ) ) {
1051 if ( ( rc = fc_ulp_login ( ulp, prli->param,
1052 sizeof ( prli->param ),
1053 fc_els_is_request ( els ) ) ) != 0 ){
1054 DBGC ( els, FCELS_FMT " could not log in ULP: %s\n",
1055 FCELS_ARGS ( els ), strerror ( rc ) );
1056 goto err_login;
1057 }
1058 } else {
1059 if ( fc_els_is_request ( els ) ) {
1060 fc_ulp_logout ( ulp, -EACCES );
1061 } else {
1062 /* This is just an information-gathering PRLI; do not
1063 * log in or out
1064 */
1065 }
1066 }
1067
1068 /* Transmit response, if applicable */
1069 if ( ! fc_els_is_request ( els ) ) {
1070 if ( ( rc = els->handler->tx ( els ) ) != 0 )
1071 goto err_tx;
1072 }
1073
1074 /* Drop temporary reference to ULP */
1075 fc_ulp_put ( ulp );
1076
1077 return 0;
1078
1079 err_tx:
1080 err_login:
1081 err_link:
1082 fc_ulp_put ( ulp );
1083 err_get_port_id_type:
1084 err_sanity:
1085 return rc;
1086}
1087
1088/**
1089 * Detect PRLI
1090 *
1091 * @v els Fibre Channel ELS transaction
1092 * @v descriptor ELS PRLI descriptor
1093 * @v data ELS frame
1094 * @v len Length of ELS frame
1095 * @ret rc Return status code
1096 */
1098 struct fc_els_prli_descriptor *descriptor,
1099 const void *data, size_t len ) {
1100 const struct {
1101 struct fc_prli_frame frame;
1102 uint8_t param[descriptor->param_len];
1103 } __attribute__ (( packed )) *prli;
1104
1105 /* Check for sufficient length to contain service parameter page */
1106 if ( len < sizeof ( *prli ) )
1107 return -EINVAL;
1108 prli = data;
1109
1110 /* Check for PRLI */
1111 if ( prli->frame.command != FC_ELS_PRLI )
1112 return -EINVAL;
1113
1114 /* Check for upper-layer protocol type */
1115 if ( prli->frame.page.type != descriptor->type )
1116 return -EINVAL;
1117
1118 return 0;
1119}
1120
1121/**
1122 * Create PRLI request
1123 *
1124 * @v parent Parent interface
1125 * @v port Fibre Channel port
1126 * @v peer_port_id Peer port ID
1127 * @v type Upper-layer protocol type
1128 * @ret rc Return status code
1129 */
1130int fc_els_prli ( struct interface *parent, struct fc_port *port,
1131 struct fc_port_id *peer_port_id, unsigned int type ) {
1132 struct fc_els_prli_descriptor *descriptor;
1133
1134 /* Find a PRLI descriptor */
1135 descriptor = fc_els_prli_descriptor ( type );
1136 if ( ! descriptor )
1137 return -ENOTSUP;
1138
1139 return fc_els_request ( parent, port, peer_port_id,
1140 descriptor->handler );
1141}
1142
1143/******************************************************************************
1144 *
1145 * RTV
1146 *
1147 ******************************************************************************
1148 */
1149
1150/**
1151 * Transmit RTV response
1152 *
1153 * @v els Fibre Channel ELS transaction
1154 * @ret rc Return status code
1155 */
1156static int fc_els_rtv_tx_response ( struct fc_els *els ) {
1157 struct fc_rtv_response_frame rtv;
1158
1159 /* Construct RTV */
1160 memset ( &rtv, 0, sizeof ( rtv ) );
1161 rtv.command = FC_ELS_LS_ACC;
1163
1164 /* Transmit RTV */
1165 return fc_els_tx ( els, &rtv, sizeof ( rtv ) );
1166}
1167
1168/**
1169 * Receive RTV
1170 *
1171 * @v els Fibre Channel ELS transaction
1172 * @v data ELS frame
1173 * @v len Length of ELS frame
1174 * @ret rc Return status code
1175 */
1176static int fc_els_rtv_rx ( struct fc_els *els, void *data __unused,
1177 size_t len __unused ) {
1178 int rc;
1179
1180 DBGC ( els, FCELS_FMT "\n", FCELS_ARGS ( els ) );
1181
1182 /* Transmit response */
1183 if ( ! fc_els_is_request ( els ) ) {
1184 if ( ( rc = fc_els_rtv_tx_response ( els ) ) != 0 )
1185 return rc;
1186 }
1187
1188 return 0;
1189}
1190
1191/**
1192 * Detect RTV
1193 *
1194 * @v els Fibre Channel ELS transaction
1195 * @v data ELS frame
1196 * @v len Length of ELS frame
1197 * @ret rc Return status code
1198 */
1199static int fc_els_rtv_detect ( struct fc_els *els __unused, const void *data,
1200 size_t len __unused ) {
1201 const struct fc_rtv_request_frame *rtv = data;
1202
1203 /* Check for RTV */
1204 if ( rtv->command != FC_ELS_RTV )
1205 return -EINVAL;
1206
1207 return 0;
1208}
1209
1210/** RTV ELS handler */
1211struct fc_els_handler fc_els_rtv_handler __fc_els_handler = {
1212 .name = "RTV",
1213 .tx = fc_els_unknown_tx,
1214 .rx = fc_els_rtv_rx,
1215 .detect = fc_els_rtv_detect,
1216};
1217
1218/******************************************************************************
1219 *
1220 * ECHO
1221 *
1222 ******************************************************************************
1223 */
1224
1225/** ECHO request data */
1227 /** ECHO frame header */
1229 /** Magic marker */
1231} __attribute__ (( packed ));
1232
1233/** ECHO magic marker */
1234#define FC_ECHO_MAGIC 0x69505845
1235
1236/**
1237 * Transmit ECHO
1238 *
1239 * @v els Fibre Channel ELS transaction
1240 * @ret rc Return status code
1241 */
1242static int fc_els_echo_tx ( struct fc_els *els ) {
1244
1245 /* Construct ECHO */
1246 memset ( &echo, 0, sizeof ( echo ) );
1247 echo.echo.command = FC_ELS_ECHO;
1248 echo.magic = htonl ( FC_ECHO_MAGIC );
1249
1250 /* Transmit ECHO */
1251 return fc_els_tx ( els, &echo, sizeof ( echo ) );
1252}
1253
1254/**
1255 * Receive ECHO request
1256 *
1257 * @v els Fibre Channel ELS transaction
1258 * @v data ELS frame
1259 * @v len Length of ELS frame
1260 * @ret rc Return status code
1261 */
1262static int fc_els_echo_rx_request ( struct fc_els *els, void *data,
1263 size_t len ) {
1264 struct {
1266 char payload[ len - sizeof ( struct fc_echo_frame_header ) ];
1267 } *echo = data;
1268 int rc;
1269
1270 DBGC ( els, FCELS_FMT "\n", FCELS_ARGS ( els ) );
1271
1272 /* Transmit response */
1273 echo->echo.command = FC_ELS_LS_ACC;
1274 if ( ( rc = fc_els_tx ( els, echo, sizeof ( *echo ) ) ) != 0 )
1275 return rc;
1276
1277 /* Nothing to do */
1278 return 0;
1279}
1280
1281/**
1282 * Receive ECHO response
1283 *
1284 * @v els Fibre Channel ELS transaction
1285 * @v data ELS frame
1286 * @v len Length of ELS frame
1287 * @ret rc Return status code
1288 */
1289static int fc_els_echo_rx_response ( struct fc_els *els, void *data,
1290 size_t len ) {
1292
1293 DBGC ( els, FCELS_FMT "\n", FCELS_ARGS ( els ) );
1294
1295 /* Sanity check */
1296 if ( len != sizeof ( *echo ) ) {
1297 DBGC ( els, FCELS_FMT " received underlength echo response\n",
1298 FCELS_ARGS ( els ) );
1299 DBGC_HDA ( els, 0, data, len );
1300 return -EIO;
1301 }
1302 echo = data;
1303
1304 /* Check response is correct */
1305 if ( echo->magic != htonl ( FC_ECHO_MAGIC ) ) {
1306 DBGC ( els, FCELS_FMT " received bad echo response\n",
1307 FCELS_ARGS ( els ) );
1308 DBGC_HDA ( els, 0, data, len );
1309 return -EIO;
1310 }
1311
1312 return 0;
1313}
1314
1315/**
1316 * Receive ECHO
1317 *
1318 * @v els Fibre Channel ELS transaction
1319 * @v data ELS frame
1320 * @v len Length of ELS frame
1321 * @ret rc Return status code
1322 */
1323static int fc_els_echo_rx ( struct fc_els *els, void *data, size_t len ) {
1324
1325 if ( fc_els_is_request ( els ) ) {
1326 return fc_els_echo_rx_response ( els, data, len );
1327 } else {
1328 return fc_els_echo_rx_request ( els, data, len );
1329 }
1330}
1331
1332/**
1333 * Detect ECHO
1334 *
1335 * @v els Fibre Channel ELS transaction
1336 * @v data ELS frame
1337 * @v len Length of ELS frame
1338 * @ret rc Return status code
1339 */
1340static int fc_els_echo_detect ( struct fc_els *els __unused, const void *data,
1341 size_t len __unused ) {
1342 const struct fc_echo_frame_header *echo = data;
1343
1344 /* Check for ECHO */
1345 if ( echo->command != FC_ELS_ECHO )
1346 return -EINVAL;
1347
1348 return 0;
1349}
1350
1351/** ECHO ELS handler */
1352struct fc_els_handler fc_els_echo_handler __fc_els_handler = {
1353 .name = "ECHO",
1354 .tx = fc_els_echo_tx,
1355 .rx = fc_els_echo_rx,
1356 .detect = fc_els_echo_detect,
1357};
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
u8 port
Port number.
Definition CIB_PRM.h:3
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
static const void * src
Definition string.h:48
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:61
struct bofm_section_header done
Definition bofm_test.c:46
ring len
Length.
Definition dwmac.h:226
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t meta
Metadata flags.
Definition ena.h:3
Error codes.
struct sockaddr * fc_fill_sockaddr(struct sockaddr_fc *sa_fc, struct fc_port_id *id)
Fill Fibre Channel socket address.
Definition fc.c:165
struct fc_peer * fc_peer_get_wwn(const struct fc_name *port_wwn)
Get Fibre Channel peer by node name.
Definition fc.c:1517
struct fc_peer * fc_peer_get_port_id(struct fc_port *port, const struct fc_port_id *peer_port_id)
Get Fibre Channel peer by port ID.
Definition fc.c:1542
struct fc_port_id fc_f_port_id
F_Port contoller port ID.
Definition fc.c:68
const char * fc_ntoa(const struct fc_name *wwn)
Format Fibre Channel WWN.
Definition fc.c:127
void fc_peer_logout(struct fc_peer *peer, int rc)
Log out Fibre Channel peer.
Definition fc.c:1348
int fc_port_login(struct fc_port *port, struct fc_port_id *port_id, const struct fc_name *link_node_wwn, const struct fc_name *link_port_wwn, int has_fabric)
Log in Fibre Channel port.
Definition fc.c:942
int fc_xchg_originate(struct interface *parent, struct fc_port *port, struct fc_port_id *peer_port_id, unsigned int type)
Originate a new Fibre Channel exchange.
Definition fc.c:728
const char * fc_id_ntoa(const struct fc_port_id *id)
Format Fibre Channel port ID.
Definition fc.c:92
void fc_ulp_logout(struct fc_ulp *ulp, int rc)
Log out Fibre Channel upper-layer protocol.
Definition fc.c:1728
int fc_peer_login(struct fc_peer *peer, struct fc_port *port, struct fc_port_id *port_id)
Log in Fibre Channel peer.
Definition fc.c:1301
struct fc_ulp * fc_ulp_get_port_id_type(struct fc_port *port, const struct fc_port_id *peer_port_id, unsigned int type)
Get Fibre Channel upper-layer protocol by port ID and type.
Definition fc.c:1916
void fc_port_logout(struct fc_port *port, int rc)
Log out Fibre Channel port.
Definition fc.c:1040
int fc_ulp_login(struct fc_ulp *ulp, const void *param, size_t param_len, int originated)
Log in Fibre Channel upper-layer protocol.
Definition fc.c:1658
Fibre Channel.
static void fc_peer_put(struct fc_peer *peer)
Drop reference to Fibre Channel peer.
Definition fc.h:391
@ FC_TYPE_ELS
Extended Link Service.
Definition fc.h:193
static void fc_ulp_put(struct fc_ulp *ulp)
Drop reference to Fibre Channel upper-layer protocol.
Definition fc.h:486
static void fc_port_put(struct fc_port *port)
Drop reference to Fibre Channel port.
Definition fc.h:316
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition fc.h:109
static struct fc_port * fc_port_get(struct fc_port *port)
Get reference to Fibre Channel port.
Definition fc.h:305
#define __fc_responder
Declare a Fibre Channel responder.
Definition fc.h:243
static void fc_els_step(struct fc_els *els)
Fibre Channel ELS process.
Definition fcels.c:255
#define FC_ECHO_MAGIC
ECHO magic marker.
Definition fcels.c:1234
static void fc_els_free(struct refcnt *refcnt)
Free Fibre Channel ELS transaction.
Definition fcels.c:62
static struct fc_els_prli_descriptor * fc_els_prli_descriptor(unsigned int type)
Find PRLI descriptor.
Definition fcels.c:936
static struct interface_operation fc_els_xchg_op[]
Fibre Channel ELS exchange interface operations.
Definition fcels.c:232
static int fc_els_echo_rx_response(struct fc_els *els, void *data, size_t len)
Receive ECHO response.
Definition fcels.c:1289
static int fc_els_respond(struct interface *xchg, struct fc_port *port, struct fc_port_id *port_id, struct fc_port_id *peer_port_id)
Create ELS response.
Definition fcels.c:352
static int fc_els_logo_tx(struct fc_els *els)
Transmit LOGO request.
Definition fcels.c:756
int fc_els_tx(struct fc_els *els, const void *data, size_t len)
Transmit Fibre Channel ELS frame.
Definition fcels.c:126
int fc_els_request(struct interface *job, struct fc_port *port, struct fc_port_id *peer_port_id, struct fc_els_handler *handler)
Create ELS request.
Definition fcels.c:324
static int fc_els_unknown_rx(struct fc_els *els, void *data, size_t len)
Receive unknown ELS.
Definition fcels.c:417
static int fc_els_logo_detect(struct fc_els *els __unused, const void *data, size_t len __unused)
Detect LOGO.
Definition fcels.c:888
static int fc_els_flogi_rx(struct fc_els *els, void *data, size_t len)
Receive FLOGI.
Definition fcels.c:496
static struct fc_els_handler * fc_els_detect(struct fc_els *els, const void *data, size_t len)
Detect Fibre Channel ELS frame handler.
Definition fcels.c:98
static int fc_els_logo_tx_response(struct fc_els *els)
Transmit LOGO response.
Definition fcels.c:776
static int fc_els_echo_detect(struct fc_els *els __unused, const void *data, size_t len __unused)
Detect ECHO.
Definition fcels.c:1340
#define FCELS_FMT
Fibre Channel ELS transaction debug message format.
Definition fcels.c:46
static int fc_els_plogi_detect(struct fc_els *els __unused, const void *data, size_t len __unused)
Detect PLOGI.
Definition fcels.c:709
static struct interface_descriptor fc_els_xchg_desc
Fibre Channel ELS exchange interface descriptor.
Definition fcels.c:238
static int fc_els_plogi_tx(struct fc_els *els)
Transmit PLOGI.
Definition fcels.c:602
static int fc_els_flogi_tx(struct fc_els *els)
Transmit FLOGI.
Definition fcels.c:467
static int fc_els_echo_rx_request(struct fc_els *els, void *data, size_t len)
Receive ECHO request.
Definition fcels.c:1262
static struct interface_operation fc_els_job_op[]
Fibre Channel ELS job control interface operations.
Definition fcels.c:242
static int fc_els_rx(struct fc_els *els, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive Fibre Channel ELS frame.
Definition fcels.c:159
static int fc_els_rtv_tx_response(struct fc_els *els)
Transmit RTV response.
Definition fcels.c:1156
static int fc_els_unknown_tx(struct fc_els *els __unused)
Transmit unknown ELS request.
Definition fcels.c:387
static int fc_els_logo_rx_request(struct fc_els *els, void *data, size_t len)
Receive LOGO request.
Definition fcels.c:819
#define FCELS_ARGS(els)
Fibre Channel ELS transaction debug message arguments.
Definition fcels.c:49
static int fc_els_rtv_rx(struct fc_els *els, void *data __unused, size_t len __unused)
Receive RTV.
Definition fcels.c:1176
static int fc_els_rtv_detect(struct fc_els *els __unused, const void *data, size_t len __unused)
Detect RTV.
Definition fcels.c:1199
int fc_els_prli(struct interface *parent, struct fc_port *port, struct fc_port_id *peer_port_id, unsigned int type)
Create PRLI request.
Definition fcels.c:1130
static struct process_descriptor fc_els_process_desc
Fibre Channel ELS process descriptor.
Definition fcels.c:283
int fc_els_flogi(struct interface *parent, struct fc_port *port)
Create FLOGI request.
Definition fcels.c:583
static void fc_els_logo_logout(struct fc_els *els, struct fc_port_id *peer_port_id)
Log out individual peer or whole port as applicable.
Definition fcels.c:793
static int fc_els_plogi_rx(struct fc_els *els, void *data, size_t len)
Receive PLOGI.
Definition fcels.c:637
int fc_els_plogi(struct interface *parent, struct fc_port *port, struct fc_port_id *peer_port_id)
Create PLOGI request.
Definition fcels.c:736
int fc_els_prli_tx(struct fc_els *els, struct fc_els_prli_descriptor *descriptor, void *param)
Transmit PRLI.
Definition fcels.c:954
static int fc_els_logo_rx(struct fc_els *els, void *data, size_t len)
Receive LOGO.
Definition fcels.c:871
static struct interface_descriptor fc_els_job_desc
Fibre Channel ELS job control interface descriptor.
Definition fcels.c:247
static int fc_els_unknown_tx_response(struct fc_els *els)
Transmit unknown ELS response.
Definition fcels.c:397
static struct fc_els * fc_els_create(struct fc_port *port, struct fc_port_id *port_id, struct fc_port_id *peer_port_id)
Create ELS transaction.
Definition fcels.c:294
static int fc_els_unknown_detect(struct fc_els *els __unused, const void *data __unused, size_t len __unused)
Detect unknown ELS.
Definition fcels.c:440
int fc_els_logo(struct interface *parent, struct fc_port *port, struct fc_port_id *peer_port_id)
Create LOGO request.
Definition fcels.c:915
static int fc_els_echo_rx(struct fc_els *els, void *data, size_t len)
Receive ECHO.
Definition fcels.c:1323
static int fc_els_logo_rx_response(struct fc_els *els, void *data __unused, size_t len __unused)
Receive LOGO response.
Definition fcels.c:854
static int fc_els_echo_tx(struct fc_els *els)
Transmit ECHO.
Definition fcels.c:1242
static int fc_els_flogi_detect(struct fc_els *els __unused, const void *data, size_t len __unused)
Detect FLOGI.
Definition fcels.c:557
static void fc_els_close(struct fc_els *els, int rc)
Close Fibre Channel ELS transaction.
Definition fcels.c:76
int fc_els_prli_detect(struct fc_els *els __unused, struct fc_els_prli_descriptor *descriptor, const void *data, size_t len)
Detect PRLI.
Definition fcels.c:1097
int fc_els_prli_rx(struct fc_els *els, struct fc_els_prli_descriptor *descriptor, void *data, size_t len)
Receive PRLI.
Definition fcels.c:1010
Fibre Channel Extended Link Services.
@ FC_ELS_FLOGI
Fabric Login.
Definition fcels.h:35
@ FC_ELS_RTV
Read Timeout Value.
Definition fcels.h:37
@ FC_ELS_LS_ACC
Link Service Accept.
Definition fcels.h:33
@ FC_ELS_PLOGI
Port Login.
Definition fcels.h:34
@ FC_ELS_PRLI
Process Login.
Definition fcels.h:39
@ FC_ELS_LOGO
Logout.
Definition fcels.h:36
@ FC_ELS_LS_RJT
Link Service Reject.
Definition fcels.h:32
@ FC_ELS_ECHO
Echo.
Definition fcels.h:38
#define FC_LOGIN_CONTINUOUS_OFFSET
Continuously increasing relative offset.
Definition fcels.h:109
#define FC_LOGIN_CLASS_SEQUENTIAL
Sequential delivery requested.
Definition fcels.h:206
#define FC_LOGIN_DEFAULT_REL_OFFS
Default relative offset by info category.
Definition fcels.h:175
#define FC_LOGIN_DEFAULT_E_D_TOV
Default E_D timeout value.
Definition fcels.h:178
#define FC_LOGIN_VERSION
Fibre Channel default login version.
Definition fcels.h:103
#define FC_LOGIN_DEFAULT_MAX_SEQ
Default maximum number of concurrent sequences.
Definition fcels.h:172
#define FC_LOGIN_DEFAULT_MTU
Fibre Channel default MTU.
Definition fcels.h:169
#define __fc_els_handler
Declare a Fibre Channel ELS handler.
Definition fcels.h:384
#define FC_PRLI_RESPONSE_SUCCESS
Request was executed successfully.
Definition fcels.h:271
#define FC_ELS_HANDLERS
Fibre Channel ELS handler table.
Definition fcels.h:381
#define FC_LOGIN_CLASS_VALID
Class valid.
Definition fcels.h:203
#define FC_ELS_PRLI_DESCRIPTORS
Fibre Channel ELS PRLI descriptor table.
Definition fcels.h:397
static unsigned int fc_els_tx_command(struct fc_els *els, unsigned int request_command)
Calculate ELS command to transmit.
Definition fcels.h:420
static int fc_els_is_request(struct fc_els *els)
Check if Fibre Channel ELS transaction is a request.
Definition fcels.h:409
#define FC_PRLI_ESTABLISH
Establish image pair.
Definition fcels.h:265
#define FC_LOGIN_DEFAULT_B2B
Fibre Channel default buffer-to-buffer credit.
Definition fcels.h:106
@ FC_ELS_REQUEST
ELS transaction is a request.
Definition fcels.h:349
@ FC_ELS_RJT_UNSUPPORTED
Command not supported.
Definition fcels.h:70
#define FC_LOGIN_F_PORT
Forwarder port.
Definition fcels.h:130
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:598
#define DBGC2(...)
Definition compiler.h:547
#define DBGC2_HDA(...)
Definition compiler.h:548
#define DBGC(...)
Definition compiler.h:530
#define DBGC_HDA(...)
Definition compiler.h:531
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define EINVAL
Invalid argument.
Definition errno.h:472
#define ENOMEM
Not enough space.
Definition errno.h:578
#define EIO
Input/output error.
Definition errno.h:477
#define ENOTSUP
Operation not supported.
Definition errno.h:633
#define EACCES
Permission denied.
Definition errno.h:342
#define htonl(value)
Definition byteswap.h:134
#define htons(value)
Definition byteswap.h:136
#define __attribute__(x)
Definition compiler.h:10
struct hv_monitor_parameter param[4][32]
Parameters.
Definition hyperv.h:13
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition interface.c:279
Object interfaces.
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition interface.h:81
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition interface.h:33
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
I/O buffers.
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:220
int echo(void)
Definition kb.c:133
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:718
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:1
void process_del(struct process *process)
Remove process from process list.
Definition process.c:80
void process_add(struct process *process)
Add process to process list.
Definition process.c:60
Processes.
#define PROC_DESC_ONCE(object_type, process, _step)
Define a process descriptor for a process that runs only once.
Definition process.h:98
static int process_running(struct process *process)
Check if process is running.
Definition process.h:176
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition process.h:146
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
A Fibre Channel ECHO frame.
Definition fcels.h:316
ECHO request data.
Definition fcels.c:1226
uint32_t magic
Magic marker.
Definition fcels.c:1230
struct fc_echo_frame_header echo
ECHO frame header.
Definition fcels.c:1228
Fibre Channel ELS frame common parameters.
Definition fcels.h:23
A Fibre Channel extended link services handler.
Definition fcels.h:353
int(* rx)(struct fc_els *els, void *data, size_t len)
Receive ELS frame.
Definition fcels.h:369
int(* tx)(struct fc_els *els)
Transmit ELS frame.
Definition fcels.h:361
int(* detect)(struct fc_els *els, const void *data, size_t len)
Detect ELS frame.
Definition fcels.h:377
A Fibre Channel ELS PRLI descriptor.
Definition fcels.h:387
struct fc_els_handler * handler
Fibre Channel ELS handler.
Definition fcels.h:393
size_t param_len
Service parameter length.
Definition fcels.h:391
unsigned int type
Upper-layer protocol type.
Definition fcels.h:389
A Fibre Channel extended link services transaction.
Definition fcels.h:324
struct fc_port * port
Fibre Channel port.
Definition fcels.h:335
struct fc_port_id port_id
Local port ID.
Definition fcels.h:337
struct fc_els_handler * handler
ELS handler, if known.
Definition fcels.h:341
struct interface xchg
Fibre Channel exchange.
Definition fcels.h:330
struct interface job
Job control interface.
Definition fcels.h:328
struct refcnt refcnt
Reference count.
Definition fcels.h:326
struct fc_port_id peer_port_id
Peer port ID.
Definition fcels.h:339
unsigned int flags
Flags.
Definition fcels.h:343
struct process process
Request sending process.
Definition fcels.h:332
uint16_t mtu
Receive data field size.
Definition fcels.h:189
uint16_t max_seq
Maximum number of concurrent sequences.
Definition fcels.h:191
uint16_t flags
Flags.
Definition fcels.h:183
uint8_t max_seq_per_xchg
Maximum number of open sequences per exchange.
Definition fcels.h:197
uint16_t credit
Buffer-to-buffer credit.
Definition fcels.h:80
uint16_t rel_offs
Relative offset by info category.
Definition fcels.h:91
uint16_t mtu
Receive size.
Definition fcels.h:84
uint16_t flags
Flags.
Definition fcels.h:82
uint32_t e_d_tov
Error detection timeout value.
Definition fcels.h:99
uint16_t version
Login version.
Definition fcels.h:78
struct fc_login_common::@057055275144204264201027124204260000332106235341::@014376230376306047030265062056353210336054307263 plogi
union fc_login_common::@057055275144204264201027124204260000332106235341 u
"Common"?
uint16_t max_seq
Maximum number of concurrent sequences.
Definition fcels.h:89
A Fibre Channel FLOGI/PLOGI frame.
Definition fcels.h:209
struct fc_login_common common
Common service parameters.
Definition fcels.h:215
struct fc_login_class class3
Class 3 service parameters.
Definition fcels.h:225
uint8_t command
ELS command code.
Definition fcels.h:211
struct fc_name port_wwn
Port name.
Definition fcels.h:217
struct fc_name node_wwn
Node name.
Definition fcels.h:219
A Fibre Channel LOGO request frame.
Definition fcels.h:233
uint8_t command
ELS command code.
Definition fcels.h:235
struct fc_name port_wwn
Port name.
Definition fcels.h:241
struct fc_port_id port_id
Port ID.
Definition fcels.h:239
A Fibre Channel LOGO response frame.
Definition fcels.h:245
uint8_t command
ELS command code.
Definition fcels.h:247
A Fibre Channel LS_RJT frame.
Definition fcels.h:44
uint8_t command
ELS command code.
Definition fcels.h:46
uint8_t reason
Reason code.
Definition fcels.h:50
A Fibre Channel peer.
Definition fc.h:341
struct fc_link_state link
Link state monitor.
Definition fc.h:351
struct interface plogi
PLOGI interface.
Definition fc.h:353
A Fibre Channel port identifier.
Definition fc.h:38
A Fibre Channel port.
Definition fc.h:253
struct fc_name node_wwn
Node name.
Definition fc.h:264
struct fc_name port_wwn
Port name.
Definition fc.h:266
struct fc_link_state link
Link state monitor.
Definition fc.h:273
struct fc_port_id port_id
Local port ID.
Definition fc.h:268
struct fc_port_id ptp_link_port_id
Link port ID (for point-to-point links only).
Definition fc.h:281
A Fibre Channel PRLI frame.
Definition fcels.h:274
A Fibre Channel responder.
Definition fc.h:223
A Fibre Channel RTV request frame.
Definition fcels.h:286
uint8_t command
ELS command code.
Definition fcels.h:288
A Fibre Channel RTV response frame.
Definition fcels.h:294
uint8_t command
ELS command code.
Definition fcels.h:296
uint32_t e_d_tov
Error detection timeout value.
Definition fcels.h:302
A Fibre Channel upper-layer protocol.
Definition fc.h:414
struct fc_peer * peer
Fibre Channel peer.
Definition fc.h:418
struct interface prli
PRLI interface.
Definition fc.h:430
struct fc_link_state link
Link state monitor.
Definition fc.h:428
An object interface descriptor.
Definition interface.h:56
An object interface operation.
Definition interface.h:18
An object interface.
Definition interface.h:125
A persistent I/O buffer.
Definition iobuf.h:98
void * data
Start of data.
Definition iobuf.h:113
A process descriptor.
Definition process.h:32
A process.
Definition process.h:18
A reference counter.
Definition refcnt.h:27
Fibre Channel socket address.
Definition fc.h:48
Data transfer metadata.
Definition xfer.h:23
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386
unsigned long frame
Definition xengrant.h:180
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition xfer.c:195
int xfer_deliver_raw_meta(struct interface *intf, const void *data, size_t len, struct xfer_metadata *meta)
Deliver datagram as raw data.
Definition xfer.c:269
Data transfer interfaces.
#define XFER_FL_OVER
Sender is relinquishing use of half-duplex channel.
Definition xfer.h:51
#define XFER_FL_RESPONSE
Data content is a response.
Definition xfer.h:64
#define XFER_FL_OUT
This is the final data transfer.
Definition xfer.h:54