iPXE
fcoe.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 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stddef.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #include <byteswap.h>
30 #include <ipxe/if_ether.h>
31 #include <ipxe/if_arp.h>
32 #include <ipxe/iobuf.h>
33 #include <ipxe/interface.h>
34 #include <ipxe/xfer.h>
35 #include <ipxe/netdevice.h>
36 #include <ipxe/ethernet.h>
37 #include <ipxe/vlan.h>
38 #include <ipxe/features.h>
39 #include <ipxe/errortab.h>
40 #include <ipxe/device.h>
41 #include <ipxe/crc32.h>
42 #include <ipxe/retry.h>
43 #include <ipxe/timer.h>
44 #include <ipxe/fc.h>
45 #include <ipxe/fip.h>
46 #include <ipxe/fcoe.h>
47 
48 /** @file
49  *
50  * FCoE protocol
51  *
52  */
53 
55 
56 /* Disambiguate the various error causes */
57 #define EINVAL_UNDERLENGTH __einfo_error ( EINFO_EINVAL_UNDERLENGTH )
58 #define EINFO_EINVAL_UNDERLENGTH \
59  __einfo_uniqify ( EINFO_EINVAL, 0x01, "Underlength packet" )
60 #define EINVAL_SOF __einfo_error ( EINFO_EINVAL_SOF )
61 #define EINFO_EINVAL_SOF \
62  __einfo_uniqify ( EINFO_EINVAL, 0x02, "Invalid SoF delimiter" )
63 #define EINVAL_CRC __einfo_error ( EINFO_EINVAL_CRC )
64 #define EINFO_EINVAL_CRC \
65  __einfo_uniqify ( EINFO_EINVAL, 0x03, "Invalid CRC (not stripped?)" )
66 #define EINVAL_EOF __einfo_error ( EINFO_EINVAL_EOF )
67 #define EINFO_EINVAL_EOF \
68  __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid EoF delimiter" )
69 
70 /** An FCoE port */
71 struct fcoe_port {
72  /** Transport interface */
74  /** Network device */
75  struct net_device *netdev;
76 
77  /** Node WWN */
79  /** Port WWN */
81 
82  /** FIP retransmission timer */
84  /** FIP timeout counter */
85  unsigned int timeouts;
86  /** Flags */
87  unsigned int flags;
88  /** FCoE forwarder priority */
89  unsigned int priority;
90  /** Keepalive delay (in ms) */
91  unsigned int keepalive;
92  /** FCoE forwarder MAC address */
94  /** Local MAC address */
96 };
97 
98 /** FCoE flags */
99 enum fcoe_flags {
100  /** Underlying network device is available */
102  /** We have selected an FCoE forwarder to use */
103  FCOE_HAVE_FCF = 0x0002,
104  /** We have a FIP-capable FCoE forwarder available to be used */
106  /** FCoE forwarder supports server-provided MAC addresses */
108  /** An alternative VLAN has been found */
109  FCOE_VLAN_FOUND = 0x0010,
110  /** VLAN discovery has timed out */
112 };
113 
114 struct net_driver fcoe_driver __net_driver;
115 struct net_protocol fcoe_protocol __net_protocol;
116 struct net_protocol fip_protocol __net_protocol;
117 
118 /** FCoE All-FCoE-MACs address */
120  { 0x01, 0x10, 0x18, 0x01, 0x00, 0x00 };
121 
122 /** FCoE All-ENode-MACs address */
124  { 0x01, 0x10, 0x18, 0x01, 0x00, 0x01 };
125 
126 /** FCoE All-FCF-MACs address */
128  { 0x01, 0x10, 0x18, 0x01, 0x00, 0x02 };
129 
130 /** Default FCoE forwarded MAC address */
132  { 0x0e, 0xfc, 0x00, 0xff, 0xff, 0xfe };
133 
134 /** Maximum number of VLAN requests before giving up on VLAN discovery */
135 #define FCOE_MAX_VLAN_REQUESTS 2
136 
137 /** Delay between retrying VLAN requests */
138 #define FCOE_VLAN_RETRY_DELAY ( TICKS_PER_SEC )
139 
140 /** Delay between retrying polling VLAN requests */
141 #define FCOE_VLAN_POLL_DELAY ( 30 * TICKS_PER_SEC )
142 
143 /** Maximum number of FIP solicitations before giving up on FIP */
144 #define FCOE_MAX_FIP_SOLICITATIONS 2
145 
146 /** Delay between retrying FIP solicitations */
147 #define FCOE_FIP_RETRY_DELAY ( TICKS_PER_SEC )
148 
149 /** Maximum number of missing discovery advertisements */
150 #define FCOE_MAX_FIP_MISSING_KEEPALIVES 4
151 
152 /******************************************************************************
153  *
154  * FCoE protocol
155  *
156  ******************************************************************************
157  */
158 
159 /**
160  * Reset FCoE port
161  *
162  * @v fcoe FCoE port
163  */
164 static void fcoe_reset ( struct fcoe_port *fcoe ) {
165 
166  /* Detach FC port, if any */
167  intf_restart ( &fcoe->transport, -ECANCELED );
168 
169  /* Reset any FIP state */
170  stop_timer ( &fcoe->timer );
171  fcoe->timeouts = 0;
172  fcoe->flags = 0;
173  fcoe->priority = ( FIP_LOWEST_PRIORITY + 1 );
174  fcoe->keepalive = 0;
175  memcpy ( fcoe->fcf_mac, default_fcf_mac,
176  sizeof ( fcoe->fcf_mac ) );
177  memcpy ( fcoe->local_mac, fcoe->netdev->ll_addr,
178  sizeof ( fcoe->local_mac ) );
179 
180  /* Start FIP solicitation if network is available */
181  if ( netdev_is_open ( fcoe->netdev ) &&
182  netdev_link_ok ( fcoe->netdev ) ) {
183  fcoe->flags |= FCOE_HAVE_NETWORK;
184  start_timer_nodelay ( &fcoe->timer );
185  DBGC ( fcoe, "FCoE %s starting %s\n", fcoe->netdev->name,
186  ( vlan_can_be_trunk ( fcoe->netdev ) ?
187  "VLAN discovery" : "FIP solicitation" ) );
188  }
189 
190  /* Send notification of window change */
191  xfer_window_changed ( &fcoe->transport );
192 }
193 
194 /**
195  * Transmit FCoE packet
196  *
197  * @v fcoe FCoE port
198  * @v iobuf I/O buffer
199  * @v meta Data transfer metadata
200  * @ret rc Return status code
201  */
202 static int fcoe_deliver ( struct fcoe_port *fcoe,
203  struct io_buffer *iobuf,
204  struct xfer_metadata *meta __unused ) {
205  struct fc_frame_header *fchdr = iobuf->data;
206  struct fc_els_frame_common *els = ( iobuf->data + sizeof ( *fchdr ) );
207  struct fcoe_header *fcoehdr;
208  struct fcoe_footer *fcoeftr;
209  struct fip_header *fiphdr;
210  struct fip_login *fipflogi;
211  struct fip_mac_address *fipmac;
212  uint32_t crc;
213  struct net_protocol *net_protocol;
214  void *ll_source;
215  int rc;
216 
217  /* Send as FIP or FCoE as appropriate */
218  if ( ( fchdr->r_ctl == ( FC_R_CTL_ELS | FC_R_CTL_UNSOL_CTRL ) ) &&
219  ( els->command == FC_ELS_FLOGI ) &&
220  ( fcoe->flags & FCOE_HAVE_FIP_FCF ) ) {
221 
222  /* Create FIP FLOGI descriptor */
223  fipflogi = iob_push ( iobuf,
224  offsetof ( typeof ( *fipflogi ), fc ) );
225  memset ( fipflogi, 0, offsetof ( typeof ( *fipflogi ), fc ) );
226  fipflogi->type = FIP_FLOGI;
227  fipflogi->len = ( iob_len ( iobuf ) / 4 );
228 
229  /* Create FIP MAC address descriptor */
230  fipmac = iob_put ( iobuf, sizeof ( *fipmac ) );
231  memset ( fipmac, 0, sizeof ( *fipmac ) );
232  fipmac->type = FIP_MAC_ADDRESS;
233  fipmac->len = ( sizeof ( *fipmac ) / 4 );
234  if ( fcoe->flags & FCOE_FCF_ALLOWS_SPMA ) {
235  memcpy ( fipmac->mac, fcoe->netdev->ll_addr,
236  sizeof ( fipmac->mac ) );
237  }
238 
239  /* Create FIP header */
240  fiphdr = iob_push ( iobuf, sizeof ( *fiphdr ) );
241  memset ( fiphdr, 0, sizeof ( *fiphdr ) );
242  fiphdr->version = FIP_VERSION;
243  fiphdr->code = htons ( FIP_CODE_ELS );
244  fiphdr->subcode = FIP_ELS_REQUEST;
245  fiphdr->len =
246  htons ( ( iob_len ( iobuf ) - sizeof ( *fiphdr ) ) / 4);
247  fiphdr->flags = ( ( fcoe->flags & FCOE_FCF_ALLOWS_SPMA ) ?
248  htons ( FIP_SP ) : htons ( FIP_FP ) );
249 
250  /* Send as FIP packet from netdev's own MAC address */
251  net_protocol = &fip_protocol;
252  ll_source = fcoe->netdev->ll_addr;
253 
254  } else {
255 
256  /* Calculate CRC */
257  crc = crc32_le ( ~((uint32_t)0), iobuf->data,
258  iob_len ( iobuf ) );
259 
260  /* Create FCoE header */
261  fcoehdr = iob_push ( iobuf, sizeof ( *fcoehdr ) );
262  memset ( fcoehdr, 0, sizeof ( *fcoehdr ) );
263  fcoehdr->sof = ( ( fchdr->seq_cnt == ntohs ( 0 ) ) ?
265 
266  /* Create FCoE footer */
267  fcoeftr = iob_put ( iobuf, sizeof ( *fcoeftr ) );
268  memset ( fcoeftr, 0, sizeof ( *fcoeftr ) );
269  fcoeftr->crc = cpu_to_le32 ( crc ^ ~((uint32_t)0) );
270  fcoeftr->eof = ( ( fchdr->f_ctl_es & FC_F_CTL_ES_END ) ?
272 
273  /* Send as FCoE packet from FCoE MAC address */
274  net_protocol = &fcoe_protocol;
275  ll_source = fcoe->local_mac;
276  }
277 
278  /* Transmit packet */
279  if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev, net_protocol,
280  fcoe->fcf_mac, ll_source ) ) != 0 ) {
281  DBGC ( fcoe, "FCoE %s could not transmit: %s\n",
282  fcoe->netdev->name, strerror ( rc ) );
283  goto done;
284  }
285 
286  done:
287  free_iob ( iobuf );
288  return rc;
289 }
290 
291 /**
292  * Allocate FCoE I/O buffer
293  *
294  * @v len Payload length
295  * @ret iobuf I/O buffer, or NULL
296  */
297 static struct io_buffer * fcoe_alloc_iob ( struct fcoe_port *fcoe __unused,
298  size_t len ) {
299  struct io_buffer *iobuf;
300 
301  iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( struct fcoe_header ) +
302  len + sizeof ( struct fcoe_footer ) );
303  if ( iobuf ) {
304  iob_reserve ( iobuf, ( MAX_LL_HEADER_LEN +
305  sizeof ( struct fcoe_header ) ) );
306  }
307  return iobuf;
308 }
309 
310 /**
311  * Process incoming FCoE packets
312  *
313  * @v iobuf I/O buffer
314  * @v netdev Network device
315  * @v ll_dest Link-layer destination address
316  * @v ll_source Link-layer source address
317  * @v flags Packet flags
318  * @ret rc Return status code
319  */
320 static int fcoe_rx ( struct io_buffer *iobuf, struct net_device *netdev,
321  const void *ll_dest, const void *ll_source,
322  unsigned int flags __unused ) {
323  struct fcoe_header *fcoehdr;
324  struct fcoe_footer *fcoeftr;
325  struct fcoe_port *fcoe;
326  int rc;
327 
328  /* Identify FCoE port */
329  fcoe = netdev_priv ( netdev, &fcoe_driver );
330  if ( ! fcoe->netdev ) {
331  DBG ( "FCoE received frame for net device %s missing FCoE "
332  "port\n", netdev->name );
333  rc = -ENOTCONN;
334  goto done;
335  }
336 
337  /* Discard packets not destined for us */
338  if ( ( memcmp ( fcoe->local_mac, ll_dest,
339  sizeof ( fcoe->local_mac ) ) != 0 ) &&
340  ( memcmp ( default_fcf_mac, ll_dest,
341  sizeof ( default_fcf_mac ) ) != 0 ) ) {
342  DBGC2 ( fcoe, "FCoE %s ignoring packet for %s\n",
343  fcoe->netdev->name, eth_ntoa ( ll_dest ) );
344  rc = -ENOTCONN;
345  goto done;
346  }
347 
348  /* Sanity check */
349  if ( iob_len ( iobuf ) < ( sizeof ( *fcoehdr ) + sizeof ( *fcoeftr ) )){
350  DBGC ( fcoe, "FCoE %s received under-length frame (%zd "
351  "bytes)\n", fcoe->netdev->name, iob_len ( iobuf ) );
353  goto done;
354  }
355 
356  /* Strip header and footer */
357  fcoehdr = iobuf->data;
358  iob_pull ( iobuf, sizeof ( *fcoehdr ) );
359  fcoeftr = ( iobuf->data + iob_len ( iobuf ) - sizeof ( *fcoeftr ) );
360  iob_unput ( iobuf, sizeof ( *fcoeftr ) );
361 
362  /* Validity checks */
363  if ( fcoehdr->version != FCOE_FRAME_VER ) {
364  DBGC ( fcoe, "FCoE %s received unsupported frame version "
365  "%02x\n", fcoe->netdev->name, fcoehdr->version );
366  rc = -EPROTONOSUPPORT;
367  goto done;
368  }
369  if ( ! ( ( fcoehdr->sof == FCOE_SOF_I3 ) ||
370  ( fcoehdr->sof == FCOE_SOF_N3 ) ) ) {
371  DBGC ( fcoe, "FCoE %s received unsupported start-of-frame "
372  "delimiter %02x\n", fcoe->netdev->name, fcoehdr->sof );
373  rc = -EINVAL_SOF;
374  goto done;
375  }
376  if ( ( le32_to_cpu ( fcoeftr->crc ) ^ ~((uint32_t)0) ) !=
377  crc32_le ( ~((uint32_t)0), iobuf->data, iob_len ( iobuf ) ) ) {
378  DBGC ( fcoe, "FCoE %s received invalid CRC\n",
379  fcoe->netdev->name );
380  rc = -EINVAL_CRC;
381  goto done;
382  }
383  if ( ! ( ( fcoeftr->eof == FCOE_EOF_N ) ||
384  ( fcoeftr->eof == FCOE_EOF_T ) ) ) {
385  DBGC ( fcoe, "FCoE %s received unsupported end-of-frame "
386  "delimiter %02x\n", fcoe->netdev->name, fcoeftr->eof );
387  rc = -EINVAL_EOF;
388  goto done;
389  }
390 
391  /* Record FCF address if applicable */
392  if ( ( fcoe->flags & FCOE_HAVE_FCF ) &&
393  ( ! ( fcoe->flags & FCOE_HAVE_FIP_FCF ) ) ) {
394  memcpy ( &fcoe->fcf_mac, ll_source, sizeof ( fcoe->fcf_mac ) );
395  }
396 
397  /* Hand off via transport interface */
398  if ( ( rc = xfer_deliver_iob ( &fcoe->transport,
399  iob_disown ( iobuf ) ) ) != 0 ) {
400  DBGC ( fcoe, "FCoE %s could not deliver frame: %s\n",
401  fcoe->netdev->name, strerror ( rc ) );
402  goto done;
403  }
404 
405  done:
406  free_iob ( iobuf );
407  return rc;
408 }
409 
410 /**
411  * Check FCoE flow control window
412  *
413  * @v fcoe FCoE port
414  * @ret len Length of window
415  */
416 static size_t fcoe_window ( struct fcoe_port *fcoe ) {
417  return ( ( fcoe->flags & FCOE_HAVE_FCF ) ? ~( ( size_t ) 0 ) : 0 );
418 }
419 
420 /**
421  * Close FCoE port
422  *
423  * @v fcoe FCoE port
424  * @v rc Reason for close
425  */
426 static void fcoe_close ( struct fcoe_port *fcoe, int rc ) {
427 
428  stop_timer ( &fcoe->timer );
429  intf_shutdown ( &fcoe->transport, rc );
430 }
431 
432 /**
433  * Identify device underlying FCoE port
434  *
435  * @v fcoe FCoE port
436  * @ret device Underlying device
437  */
438 static struct device * fcoe_identify_device ( struct fcoe_port *fcoe ) {
439  return fcoe->netdev->dev;
440 }
441 
442 /** FCoE transport interface operations */
446  INTF_OP ( xfer_window, struct fcoe_port *, fcoe_window ),
447  INTF_OP ( intf_close, struct fcoe_port *, fcoe_close ),
448  INTF_OP ( identify_device, struct fcoe_port *,
450 };
451 
452 /** FCoE transport interface descriptor */
454  INTF_DESC ( struct fcoe_port, transport, fcoe_transport_op );
455 
456 /******************************************************************************
457  *
458  * FIP protocol
459  *
460  ******************************************************************************
461  */
462 
463 /**
464  * Parse FIP packet into descriptor set
465  *
466  * @v fcoe FCoE port
467  * @v fiphdr FIP header
468  * @v len Length of FIP packet
469  * @v descs Descriptor set to fill in
470  * @ret rc Return status code
471  */
472 static int fcoe_fip_parse ( struct fcoe_port *fcoe, struct fip_header *fiphdr,
473  size_t len, struct fip_descriptors *descs ) {
474  union fip_descriptor *desc;
475  size_t descs_len;
476  size_t desc_len;
477  size_t desc_offset;
478  unsigned int desc_type;
479 
480  /* Check FIP version */
481  if ( fiphdr->version != FIP_VERSION ) {
482  DBGC ( fcoe, "FCoE %s received unsupported FIP version %02x\n",
483  fcoe->netdev->name, fiphdr->version );
484  return -EINVAL;
485  }
486 
487  /* Check length */
488  descs_len = ( ntohs ( fiphdr->len ) * 4 );
489  if ( ( sizeof ( *fiphdr ) + descs_len ) > len ) {
490  DBGC ( fcoe, "FCoE %s received bad descriptor list length\n",
491  fcoe->netdev->name );
492  return -EINVAL;
493  }
494 
495  /* Parse descriptor list */
496  memset ( descs, 0, sizeof ( *descs ) );
497  for ( desc_offset = 0 ;
498  desc_offset <= ( descs_len - sizeof ( desc->common ) ) ;
499  desc_offset += desc_len ) {
500 
501  /* Find descriptor and validate length */
502  desc = ( ( ( void * ) ( fiphdr + 1 ) ) + desc_offset );
503  desc_type = desc->common.type;
504  desc_len = ( desc->common.len * 4 );
505  if ( desc_len == 0 ) {
506  DBGC ( fcoe, "FCoE %s received zero-length "
507  "descriptor\n", fcoe->netdev->name );
508  return -EINVAL;
509  }
510  if ( ( desc_offset + desc_len ) > descs_len ) {
511  DBGC ( fcoe, "FCoE %s descriptor overrun\n",
512  fcoe->netdev->name );
513  return -EINVAL;
514  }
515 
516  /* Handle descriptors that we understand */
517  if ( ( desc_type > FIP_RESERVED ) &&
518  ( desc_type < FIP_NUM_DESCRIPTOR_TYPES ) ) {
519  /* Use only the first instance of a descriptor */
520  if ( descs->desc[desc_type] == NULL )
521  descs->desc[desc_type] = desc;
522  continue;
523  }
524 
525  /* Abort if we cannot understand a critical descriptor */
526  if ( FIP_IS_CRITICAL ( desc_type ) ) {
527  DBGC ( fcoe, "FCoE %s cannot understand critical "
528  "descriptor type %02x\n",
529  fcoe->netdev->name, desc_type );
530  return -ENOTSUP;
531  }
532 
533  /* Ignore non-critical descriptors that we cannot understand */
534  }
535 
536  return 0;
537 }
538 
539 /**
540  * Send FIP VLAN request
541  *
542  * @v fcoe FCoE port
543  * @ret rc Return status code
544  */
545 static int fcoe_fip_tx_vlan ( struct fcoe_port *fcoe ) {
546  struct io_buffer *iobuf;
547  struct {
548  struct fip_header hdr;
549  struct fip_mac_address mac_address;
550  } __attribute__ (( packed )) *request;
551  int rc;
552 
553  /* Allocate I/O buffer */
554  iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( *request ) );
555  if ( ! iobuf )
556  return -ENOMEM;
557  iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
558 
559  /* Construct VLAN request */
560  request = iob_put ( iobuf, sizeof ( *request ) );
561  memset ( request, 0, sizeof ( *request ) );
562  request->hdr.version = FIP_VERSION;
563  request->hdr.code = htons ( FIP_CODE_VLAN );
564  request->hdr.subcode = FIP_VLAN_REQUEST;
565  request->hdr.len = htons ( ( sizeof ( *request ) -
566  sizeof ( request->hdr ) ) / 4 );
567  request->mac_address.type = FIP_MAC_ADDRESS;
568  request->mac_address.len =
569  ( sizeof ( request->mac_address ) / 4 );
570  memcpy ( request->mac_address.mac, fcoe->netdev->ll_addr,
571  sizeof ( request->mac_address.mac ) );
572 
573  /* Send VLAN request */
574  if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev,
575  &fip_protocol, all_fcf_macs,
576  fcoe->netdev->ll_addr ) ) != 0 ) {
577  DBGC ( fcoe, "FCoE %s could not send VLAN request: "
578  "%s\n", fcoe->netdev->name, strerror ( rc ) );
579  return rc;
580  }
581 
582  return 0;
583 }
584 
585 /**
586  * Handle received FIP VLAN notification
587  *
588  * @v fcoe FCoE port
589  * @v descs Descriptor list
590  * @v flags Flags
591  * @ret rc Return status code
592  */
593 static int fcoe_fip_rx_vlan ( struct fcoe_port *fcoe,
594  struct fip_descriptors *descs,
595  unsigned int flags __unused ) {
596  struct fip_mac_address *mac_address = fip_mac_address ( descs );
597  struct fip_vlan *vlan = fip_vlan ( descs );
598  unsigned int tag;
599  int rc;
600 
601  /* Sanity checks */
602  if ( ! mac_address ) {
603  DBGC ( fcoe, "FCoE %s received VLAN notification missing MAC "
604  "address\n", fcoe->netdev->name );
605  return -EINVAL;
606  }
607  if ( ! vlan ) {
608  DBGC ( fcoe, "FCoE %s received VLAN notification missing VLAN "
609  "tag\n", fcoe->netdev->name );
610  return -EINVAL;
611  }
612 
613  /* Create VLAN */
614  tag = ntohs ( vlan->vlan );
615  DBGC ( fcoe, "FCoE %s creating VLAN %d for FCF %s\n",
616  fcoe->netdev->name, tag, eth_ntoa ( mac_address->mac ) );
617  if ( ( rc = vlan_create ( fcoe->netdev, tag,
618  FCOE_VLAN_PRIORITY ) ) != 0 ) {
619  DBGC ( fcoe, "FCoE %s could not create VLAN %d: %s\n",
620  fcoe->netdev->name, tag, strerror ( rc ) );
621  return rc;
622  }
623 
624  /* Record that a VLAN was found. This FCoE port will play no
625  * further active role; the real FCoE traffic will use the
626  * port automatically created for the new VLAN device.
627  */
628  fcoe->flags |= FCOE_VLAN_FOUND;
629 
630  return 0;
631 }
632 
633 /**
634  * Send FIP discovery solicitation
635  *
636  * @v fcoe FCoE port
637  * @ret rc Return status code
638  */
639 static int fcoe_fip_tx_solicitation ( struct fcoe_port *fcoe ) {
640  struct io_buffer *iobuf;
641  struct {
642  struct fip_header hdr;
643  struct fip_mac_address mac_address;
644  struct fip_name_id name_id;
645  struct fip_max_fcoe_size max_fcoe_size;
646  } __attribute__ (( packed )) *solicitation;
647  int rc;
648 
649  /* Allocate I/O buffer */
650  iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( *solicitation ) );
651  if ( ! iobuf )
652  return -ENOMEM;
653  iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
654 
655  /* Construct discovery solicitation */
656  solicitation = iob_put ( iobuf, sizeof ( *solicitation ) );
657  memset ( solicitation, 0, sizeof ( *solicitation ) );
658  solicitation->hdr.version = FIP_VERSION;
659  solicitation->hdr.code = htons ( FIP_CODE_DISCOVERY );
660  solicitation->hdr.subcode = FIP_DISCOVERY_SOLICIT;
661  solicitation->hdr.len = htons ( ( sizeof ( *solicitation ) -
662  sizeof ( solicitation->hdr ) ) / 4 );
663  solicitation->hdr.flags = htons ( FIP_FP | FIP_SP );
664  solicitation->mac_address.type = FIP_MAC_ADDRESS;
665  solicitation->mac_address.len =
666  ( sizeof ( solicitation->mac_address ) / 4 );
667  memcpy ( solicitation->mac_address.mac, fcoe->netdev->ll_addr,
668  sizeof ( solicitation->mac_address.mac ) );
669  solicitation->name_id.type = FIP_NAME_ID;
670  solicitation->name_id.len = ( sizeof ( solicitation->name_id ) / 4 );
671  memcpy ( &solicitation->name_id.name, &fcoe->node_wwn.fc,
672  sizeof ( solicitation->name_id.name ) );
673  solicitation->max_fcoe_size.type = FIP_MAX_FCOE_SIZE;
674  solicitation->max_fcoe_size.len =
675  ( sizeof ( solicitation->max_fcoe_size ) / 4 );
676  solicitation->max_fcoe_size.mtu =
677  htons ( ETH_MAX_MTU - sizeof ( struct fcoe_header ) -
678  sizeof ( struct fcoe_footer ) );
679 
680  /* Send discovery solicitation */
681  if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev,
682  &fip_protocol, all_fcf_macs,
683  fcoe->netdev->ll_addr ) ) != 0 ) {
684  DBGC ( fcoe, "FCoE %s could not send discovery solicitation: "
685  "%s\n", fcoe->netdev->name, strerror ( rc ) );
686  return rc;
687  }
688 
689  return 0;
690 }
691 
692 /**
693  * Handle received FIP discovery advertisement
694  *
695  * @v fcoe FCoE port
696  * @v descs Descriptor list
697  * @v flags Flags
698  * @ret rc Return status code
699  */
700 static int fcoe_fip_rx_advertisement ( struct fcoe_port *fcoe,
701  struct fip_descriptors *descs,
702  unsigned int flags ) {
703  struct fip_priority *priority = fip_priority ( descs );
704  struct fip_mac_address *mac_address = fip_mac_address ( descs );
705  struct fip_fka_adv_p *fka_adv_p = fip_fka_adv_p ( descs );
706 
707  /* Sanity checks */
708  if ( ! priority ) {
709  DBGC ( fcoe, "FCoE %s received advertisement missing "
710  "priority\n", fcoe->netdev->name );
711  return -EINVAL;
712  }
713  if ( ! mac_address ) {
714  DBGC ( fcoe, "FCoE %s received advertisement missing MAC "
715  "address\n", fcoe->netdev->name );
716  return -EINVAL;
717  }
718  if ( ! fka_adv_p ) {
719  DBGC ( fcoe, "FCoE %s received advertisement missing FKA ADV "
720  "period\n", fcoe->netdev->name );
721  return -EINVAL;
722  }
723 
724  if ( ! ( fcoe->flags & FCOE_HAVE_FCF ) ) {
725 
726  /* We are soliciting for an FCF. Store the highest
727  * (i.e. lowest-valued) priority solicited
728  * advertisement that we receive.
729  */
730  if ( ( ( flags & ( FIP_A | FIP_S | FIP_F ) ) ==
731  ( FIP_A | FIP_S | FIP_F ) ) &&
732  ( priority->priority < fcoe->priority ) ) {
733 
734  fcoe->flags |= FCOE_HAVE_FIP_FCF;
735  fcoe->priority = priority->priority;
736  if ( fka_adv_p->flags & FIP_NO_KEEPALIVE ) {
737  fcoe->keepalive = 0;
738  } else {
739  fcoe->keepalive = ntohl ( fka_adv_p->period );
740  }
741  fcoe->flags &= ~FCOE_FCF_ALLOWS_SPMA;
742  if ( flags & FIP_SP )
743  fcoe->flags |= FCOE_FCF_ALLOWS_SPMA;
744  memcpy ( fcoe->fcf_mac, mac_address->mac,
745  sizeof ( fcoe->fcf_mac ) );
746  DBGC ( fcoe, "FCoE %s selected FCF %s (pri %d",
747  fcoe->netdev->name, eth_ntoa ( fcoe->fcf_mac ),
748  fcoe->priority );
749  if ( fcoe->keepalive ) {
750  DBGC ( fcoe, ", FKA ADV %dms",
751  fcoe->keepalive );
752  }
753  DBGC ( fcoe, ", %cPMA)\n",
754  ( ( fcoe->flags & FCOE_FCF_ALLOWS_SPMA ) ?
755  'S' : 'F' ) );
756  }
757 
758  } else if ( fcoe->flags & FCOE_HAVE_FIP_FCF ) {
759 
760  /* We are checking that the FCF remains alive. Reset
761  * the timeout counter if this is an advertisement
762  * from our forwarder.
763  */
764  if ( memcmp ( fcoe->fcf_mac, mac_address->mac,
765  sizeof ( fcoe->fcf_mac ) ) == 0 ) {
766  fcoe->timeouts = 0;
767  }
768 
769  } else {
770 
771  /* We are operating in non-FIP mode and have received
772  * a FIP advertisement. Reset the link in order to
773  * attempt FIP.
774  */
775  fcoe_reset ( fcoe );
776 
777  }
778 
779  return 0;
780 }
781 
782 /**
783  * Handle received FIP ELS response
784  *
785  * @v fcoe FCoE port
786  * @v descs Descriptor list
787  * @v flags Flags
788  * @ret rc Return status code
789  */
790 static int fcoe_fip_rx_els_response ( struct fcoe_port *fcoe,
791  struct fip_descriptors *descs,
792  unsigned int flags __unused ) {
793  struct fip_els *flogi = fip_flogi ( descs );
794  struct fip_mac_address *mac_address = fip_mac_address ( descs );
795  void *frame;
796  size_t frame_len;
797  int rc;
798 
799  /* Sanity checks */
800  if ( ! flogi ) {
801  DBGC ( fcoe, "FCoE %s received ELS response missing FLOGI\n",
802  fcoe->netdev->name );
803  return -EINVAL;
804  }
805  if ( ! mac_address ) {
806  DBGC ( fcoe, "FCoE %s received ELS response missing MAC "
807  "address\n", fcoe->netdev->name );
808  return -EINVAL;
809  }
810 
811  /* Record local MAC address */
812  memcpy ( fcoe->local_mac, mac_address->mac, sizeof ( fcoe->local_mac ));
813  DBGC ( fcoe, "FCoE %s using local MAC %s\n",
814  fcoe->netdev->name, eth_ntoa ( fcoe->local_mac ) );
815 
816  /* Hand off via transport interface */
817  frame = &flogi->fc;
818  frame_len = ( ( flogi->len * 4 ) - offsetof ( typeof ( *flogi ), fc ) );
819  if ( ( rc = xfer_deliver_raw ( &fcoe->transport, frame,
820  frame_len ) ) != 0 ) {
821  DBGC ( fcoe, "FCoE %s could not deliver FIP FLOGI frame: %s\n",
822  fcoe->netdev->name, strerror ( rc ) );
823  return rc;
824  }
825 
826  return 0;
827 }
828 
829 /**
830  * Send FIP keepalive
831  *
832  * @v fcoe FCoE port
833  * @ret rc Return status code
834  */
835 static int fcoe_fip_tx_keepalive ( struct fcoe_port *fcoe ) {
836  struct io_buffer *iobuf;
837  struct {
838  struct fip_header hdr;
839  struct fip_mac_address mac_address;
840  } __attribute__ (( packed )) *keepalive;
841  int rc;
842 
843  /* Allocate I/O buffer */
844  iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( *keepalive ) );
845  if ( ! iobuf )
846  return -ENOMEM;
847  iob_reserve ( iobuf, MAX_LL_HEADER_LEN );
848 
849  /* Construct keepalive */
850  keepalive = iob_put ( iobuf, sizeof ( *keepalive ) );
851  memset ( keepalive, 0, sizeof ( *keepalive ) );
852  keepalive->hdr.version = FIP_VERSION;
853  keepalive->hdr.code = htons ( FIP_CODE_MAINTAIN );
854  keepalive->hdr.subcode = FIP_MAINTAIN_KEEP_ALIVE;
855  keepalive->hdr.len = htons ( ( sizeof ( *keepalive ) -
856  sizeof ( keepalive->hdr ) ) / 4 );
857  keepalive->mac_address.type = FIP_MAC_ADDRESS;
858  keepalive->mac_address.len =
859  ( sizeof ( keepalive->mac_address ) / 4 );
860  memcpy ( keepalive->mac_address.mac, fcoe->netdev->ll_addr,
861  sizeof ( keepalive->mac_address.mac ) );
862 
863  /* Send keepalive */
864  if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev,
865  &fip_protocol, fcoe->fcf_mac,
866  fcoe->netdev->ll_addr ) ) != 0 ) {
867  DBGC ( fcoe, "FCoE %s could not send keepalive: %s\n",
868  fcoe->netdev->name, strerror ( rc ) );
869  return rc;
870  }
871 
872  return 0;
873 }
874 
875 /** A FIP handler */
876 struct fip_handler {
877  /** Protocol code */
879  /** Protocol subcode */
881  /**
882  * Receive FIP packet
883  *
884  * @v fcoe FCoE port
885  * @v descs Descriptor list
886  * @v flags Flags
887  * @ret rc Return status code
888  */
889  int ( * rx ) ( struct fcoe_port *fcoe, struct fip_descriptors *descs,
890  unsigned int flags );
891 };
892 
893 /** FIP handlers */
894 static struct fip_handler fip_handlers[] = {
901 };
902 
903 /**
904  * Process incoming FIP packets
905  *
906  * @v iobuf I/O buffer
907  * @v netdev Network device
908  * @v ll_dest Link-layer destination address
909  * @v ll_source Link-layer source address
910  * @v flags Packet flags
911  * @ret rc Return status code
912  */
913 static int fcoe_fip_rx ( struct io_buffer *iobuf,
914  struct net_device *netdev,
915  const void *ll_dest,
916  const void *ll_source __unused,
917  unsigned int flags __unused ) {
918  struct fip_header *fiphdr = iobuf->data;
919  struct fip_descriptors descs;
920  struct fip_handler *handler;
921  struct fcoe_port *fcoe;
922  unsigned int i;
923  int rc;
924 
925  /* Identify FCoE port */
926  fcoe = netdev_priv ( netdev, &fcoe_driver );
927  if ( ! fcoe->netdev ) {
928  DBG ( "FCoE received FIP frame for net device %s missing FCoE "
929  "port\n", netdev->name );
930  rc = -ENOTCONN;
931  goto done;
932  }
933 
934  /* Discard packets not destined for us */
935  if ( ( memcmp ( fcoe->netdev->ll_addr, ll_dest, ETH_ALEN ) != 0 ) &&
936  ( memcmp ( all_fcoe_macs, ll_dest,
937  sizeof ( all_fcoe_macs ) ) != 0 ) &&
938  ( memcmp ( all_enode_macs, ll_dest,
939  sizeof ( all_enode_macs ) ) != 0 ) ) {
940  DBGC2 ( fcoe, "FCoE %s ignoring FIP packet for %s\n",
941  fcoe->netdev->name, eth_ntoa ( ll_dest ) );
942  rc = -ENOTCONN;
943  goto done;
944  }
945 
946  /* Parse FIP packet */
947  if ( ( rc = fcoe_fip_parse ( fcoe, fiphdr, iob_len ( iobuf ),
948  &descs ) ) != 0 )
949  goto done;
950 
951  /* Find a suitable handler */
952  for ( i = 0 ; i < ( sizeof ( fip_handlers ) /
953  sizeof ( fip_handlers[0] ) ) ; i++ ) {
954  handler = &fip_handlers[i];
955  if ( ( handler->code == ntohs ( fiphdr->code ) ) &&
956  ( handler->subcode == fiphdr->subcode ) ) {
957  rc = handler->rx ( fcoe, &descs,
958  ntohs ( fiphdr->flags ) );
959  goto done;
960  }
961  }
962  DBGC ( fcoe, "FCoE %s received unsupported FIP code %04x.%02x\n",
963  fcoe->netdev->name, ntohs ( fiphdr->code ), fiphdr->subcode );
964  rc = -ENOTSUP;
965 
966  done:
967  free_iob ( iobuf );
968  return rc;
969 }
970 
971 /******************************************************************************
972  *
973  * FCoE ports
974  *
975  ******************************************************************************
976  */
977 
978 /**
979  * Handle FCoE timer expiry
980  *
981  * @v timer FIP timer
982  * @v over Timer expired
983  */
984 static void fcoe_expired ( struct retry_timer *timer, int over __unused ) {
985  struct fcoe_port *fcoe =
986  container_of ( timer, struct fcoe_port, timer );
987  int rc;
988 
989  /* Sanity check */
990  assert ( fcoe->flags & FCOE_HAVE_NETWORK );
991 
992  /* Increment the timeout counter */
993  fcoe->timeouts++;
994 
995  if ( vlan_can_be_trunk ( fcoe->netdev ) &&
996  ! ( fcoe->flags & FCOE_VLAN_TIMED_OUT ) ) {
997 
998  /* If we have already found a VLAN, send infrequent
999  * VLAN requests, in case VLAN information changes.
1000  */
1001  if ( fcoe->flags & FCOE_VLAN_FOUND ) {
1002  fcoe->flags &= ~FCOE_VLAN_FOUND;
1003  fcoe->timeouts = 0;
1004  start_timer_fixed ( &fcoe->timer,
1006  fcoe_fip_tx_vlan ( fcoe );
1007  return;
1008  }
1009 
1010  /* If we have not yet found a VLAN, and we have not
1011  * yet timed out and given up on finding one, then
1012  * send a VLAN request and wait.
1013  */
1014  if ( fcoe->timeouts <= FCOE_MAX_VLAN_REQUESTS ) {
1015  start_timer_fixed ( &fcoe->timer,
1017  fcoe_fip_tx_vlan ( fcoe );
1018  return;
1019  }
1020 
1021  /* We have timed out waiting for a VLAN; proceed to
1022  * FIP discovery.
1023  */
1024  fcoe->flags |= FCOE_VLAN_TIMED_OUT;
1025  fcoe->timeouts = 0;
1026  DBGC ( fcoe, "FCoE %s giving up on VLAN discovery\n",
1027  fcoe->netdev->name );
1028  start_timer_nodelay ( &fcoe->timer );
1029 
1030  } else if ( ! ( fcoe->flags & FCOE_HAVE_FCF ) ) {
1031 
1032  /* If we have not yet found a FIP-capable forwarder,
1033  * and we have not yet timed out and given up on
1034  * finding one, then send a FIP solicitation and wait.
1035  */
1037  if ( ( ! ( fcoe->flags & FCOE_HAVE_FIP_FCF ) ) &&
1038  ( fcoe->timeouts <= FCOE_MAX_FIP_SOLICITATIONS ) ) {
1039  fcoe_fip_tx_solicitation ( fcoe );
1040  return;
1041  }
1042 
1043  /* Attach Fibre Channel port */
1044  if ( ( rc = fc_port_open ( &fcoe->transport, &fcoe->node_wwn.fc,
1045  &fcoe->port_wwn.fc,
1046  fcoe->netdev->name ) ) != 0 ) {
1047  DBGC ( fcoe, "FCoE %s could not create FC port: %s\n",
1048  fcoe->netdev->name, strerror ( rc ) );
1049  /* We will try again on the next timer expiry */
1050  return;
1051  }
1052  stop_timer ( &fcoe->timer );
1053 
1054  /* Either we have found a FIP-capable forwarder, or we
1055  * have timed out and will fall back to pre-FIP mode.
1056  */
1057  fcoe->flags |= FCOE_HAVE_FCF;
1058  fcoe->timeouts = 0;
1059  DBGC ( fcoe, "FCoE %s using %sFIP FCF %s\n", fcoe->netdev->name,
1060  ( ( fcoe->flags & FCOE_HAVE_FIP_FCF ) ? "" : "non-" ),
1061  eth_ntoa ( fcoe->fcf_mac ) );
1062 
1063  /* Start sending keepalives if applicable */
1064  if ( fcoe->keepalive )
1065  start_timer_nodelay ( &fcoe->timer );
1066 
1067  /* Send notification of window change */
1068  xfer_window_changed ( &fcoe->transport );
1069 
1070  } else {
1071 
1072  /* Send keepalive */
1073  start_timer_fixed ( &fcoe->timer,
1074  ( fcoe->keepalive * TICKS_PER_MS ) );
1075  fcoe_fip_tx_keepalive ( fcoe );
1076 
1077  /* Abandon FCF if we have not seen its advertisements */
1078  if ( fcoe->timeouts > FCOE_MAX_FIP_MISSING_KEEPALIVES ) {
1079  DBGC ( fcoe, "FCoE %s abandoning FCF %s\n",
1080  fcoe->netdev->name, eth_ntoa ( fcoe->fcf_mac ));
1081  fcoe_reset ( fcoe );
1082  }
1083  }
1084 }
1085 
1086 /**
1087  * Create FCoE port
1088  *
1089  * @v netdev Network device
1090  * @v priv Private data
1091  * @ret rc Return status code
1092  */
1093 static int fcoe_probe ( struct net_device *netdev, void *priv ) {
1095  struct fcoe_port *fcoe = priv;
1096 
1097  /* Sanity check */
1098  if ( ll_protocol->ll_proto != htons ( ARPHRD_ETHER ) ) {
1099  /* Not an error; simply skip this net device */
1100  DBG ( "FCoE skipping non-Ethernet device %s\n", netdev->name );
1101  return 0;
1102  }
1103 
1104  /* Initialise structure */
1106  timer_init ( &fcoe->timer, fcoe_expired, &netdev->refcnt );
1107  fcoe->netdev = netdev;
1108 
1109  /* Construct node and port names */
1111  memcpy ( &fcoe->node_wwn.fcoe.mac, netdev->ll_addr,
1112  sizeof ( fcoe->node_wwn.fcoe.mac ) );
1114  memcpy ( &fcoe->port_wwn.fcoe.mac, netdev->ll_addr,
1115  sizeof ( fcoe->port_wwn.fcoe.mac ) );
1116 
1117  DBGC ( fcoe, "FCoE %s is %s", fcoe->netdev->name,
1118  fc_ntoa ( &fcoe->node_wwn.fc ) );
1119  DBGC ( fcoe, " port %s\n", fc_ntoa ( &fcoe->port_wwn.fc ) );
1120 
1121  return 0;
1122 }
1123 
1124 /**
1125  * Handle FCoE port device or link state change
1126  *
1127  * @v netdev Network device
1128  * @v priv Private data
1129  */
1130 static void fcoe_notify ( struct net_device *netdev, void *priv ) {
1131  struct fcoe_port *fcoe = priv;
1132 
1133  /* Skip non-FCoE net devices */
1134  if ( ! fcoe->netdev )
1135  return;
1136 
1137  /* Reset the FCoE link if necessary */
1138  if ( ! ( netdev_is_open ( netdev ) &&
1139  netdev_link_ok ( netdev ) &&
1140  ( fcoe->flags & FCOE_HAVE_NETWORK ) ) ) {
1141  fcoe_reset ( fcoe );
1142  }
1143 }
1144 
1145 /**
1146  * Destroy FCoE port
1147  *
1148  * @v netdev Network device
1149  * @v priv Private data
1150  */
1151 static void fcoe_remove ( struct net_device *netdev __unused, void *priv ) {
1152  struct fcoe_port *fcoe = priv;
1153 
1154  /* Skip non-FCoE net devices */
1155  if ( ! fcoe->netdev )
1156  return;
1157 
1158  /* Close FCoE device */
1159  fcoe_close ( fcoe, 0 );
1160 }
1161 
1162 /** FCoE driver */
1163 struct net_driver fcoe_driver __net_driver = {
1164  .name = "FCoE",
1165  .priv_len = sizeof ( struct fcoe_port ),
1166  .probe = fcoe_probe,
1167  .notify = fcoe_notify,
1168  .remove = fcoe_remove,
1169 };
1170 
1171 /** FCoE protocol */
1172 struct net_protocol fcoe_protocol __net_protocol = {
1173  .name = "FCoE",
1174  .net_proto = htons ( ETH_P_FCOE ),
1175  .rx = fcoe_rx,
1176 };
1177 
1178 /** FIP protocol */
1179 struct net_protocol fip_protocol __net_protocol = {
1180  .name = "FIP",
1181  .net_proto = htons ( ETH_P_FIP ),
1182  .rx = fcoe_fip_rx,
1183 };
1184 
1185 /** Human-readable message for CRC errors
1186  *
1187  * It seems as though several drivers neglect to strip the Ethernet
1188  * CRC, which will cause the FCoE footer to be misplaced and result
1189  * (coincidentally) in an "invalid CRC" error from FCoE.
1190  */
1191 struct errortab fcoe_errors[] __errortab = {
1193 };
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
#define __attribute__(x)
Definition: compiler.h:10
#define EINVAL
Invalid argument.
Definition: errno.h:428
An object interface operation.
Definition: interface.h:17
A FIP descriptor containing an encapsulated login frame.
Definition: fip.h:219
Fibre Channel ELS frame common parameters.
Definition: fcels.h:22
#define FCOE_AUTHORITY_IEEE
IEEE 48-bit address.
Definition: fcoe.h:31
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
unsigned short uint16_t
Definition: stdint.h:11
#define FCOE_VLAN_POLL_DELAY
Delay between retrying polling VLAN requests.
Definition: fcoe.c:141
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
const char * name
Protocol name.
Definition: netdevice.h:66
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:343
fcoe_flags
FCoE flags.
Definition: fcoe.c:99
#define iob_put(iobuf, len)
Definition: iobuf.h:120
Error message tables.
Data transfer metadata.
Definition: xfer.h:22
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:278
An alternative VLAN has been found.
Definition: fcoe.c:109
#define EINVAL_UNDERLENGTH
Definition: fcoe.c:57
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition: xfer.c:255
Reserved.
Definition: fip.h:102
unsigned int priority
FCoE forwarder priority.
Definition: fcoe.c:89
#define FIP_LOWEST_PRIORITY
Lowest FIP priority.
Definition: fip.h:142
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition: retry.h:99
Discovery advertisement.
Definition: fip.h:60
uint8_t type
Type.
Definition: fip.h:93
static int fcoe_fip_tx_keepalive(struct fcoe_port *fcoe)
Send FIP keepalive.
Definition: fcoe.c:835
unsigned int flags
Flags.
Definition: fcoe.c:87
#define FEATURE_PROTOCOL
Network protocols.
Definition: features.h:21
#define le32_to_cpu(value)
Definition: byteswap.h:113
Fabric Login.
Definition: fcels.h:34
A FIP priority descriptor.
Definition: fip.h:124
struct net_device * netdev
Network device.
Definition: fcoe.c:75
uint16_t seq_cnt
Sequence count.
Definition: fc.h:146
Error codes.
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
uint8_t len
Length in 32-bit words.
Definition: fip.h:95
#define FCOE_VLAN_RETRY_DELAY
Delay between retrying VLAN requests.
Definition: fcoe.c:138
#define iob_push(iobuf, len)
Definition: iobuf.h:84
u16 fc
802.11 Frame Control field
Definition: ieee80211.h:14
uint8_t mac[ETH_ALEN]
MAC address.
Definition: fcoe.h:26
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
uint8_t flags
Flags.
Definition: fip.h:315
static struct interface_operation fcoe_transport_op[]
FCoE transport interface operations.
Definition: fcoe.c:443
#define FIP_VERSION
FIP frame version.
Definition: fip.h:47
uint8_t command
ELS command code.
Definition: fcels.h:24
static int fcoe_probe(struct net_device *netdev, void *priv)
Create FCoE port.
Definition: fcoe.c:1093
static struct fip_handler fip_handlers[]
FIP handlers.
Definition: fcoe.c:894
#define __einfo_errortab(einfo)
Definition: errortab.h:23
Retry timers.
static struct interface_descriptor fcoe_transport_desc
FCoE transport interface descriptor.
Definition: fcoe.c:453
unsigned int timeouts
FIP timeout counter.
Definition: fcoe.c:85
A FIP handler.
Definition: fcoe.c:876
#define FCOE_VLAN_PRIORITY
FCoE VLAN priority.
Definition: fcoe.h:90
#define DBGC(...)
Definition: compiler.h:505
MAC address.
Definition: fip.h:104
FLOGI.
Definition: fip.h:109
A retry timer.
Definition: retry.h:21
uint8_t version
FCoE frame version.
Definition: fcoe.h:52
Underlying network device is available.
Definition: fcoe.c:101
#define FCOE_FIP_RETRY_DELAY
Delay between retrying FIP solicitations.
Definition: fcoe.c:147
#define ntohl(value)
Definition: byteswap.h:134
Max FCoE size.
Definition: fip.h:108
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:158
Extended Link Services.
Definition: fc.h:162
#define ETH_MAX_MTU
Definition: if_ether.h:14
static void fcoe_notify(struct net_device *netdev, void *priv)
Handle FCoE port device or link state change.
Definition: fcoe.c:1130
Forwarder.
Definition: fip.h:87
static void fcoe_close(struct fcoe_port *fcoe, int rc)
Close FCoE port.
Definition: fcoe.c:426
iPXE timers
Available for login.
Definition: fip.h:85
#define ntohs(value)
Definition: byteswap.h:136
const char * fc_ntoa(const struct fc_name *wwn)
Format Fibre Channel WWN.
Definition: fc.c:127
struct fip_common common
Common fields.
Definition: fip.h:350
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
static int fcoe_fip_tx_vlan(struct fcoe_port *fcoe)
Send FIP VLAN request.
Definition: fcoe.c:545
uint8_t local_mac[ETH_ALEN]
Local MAC address.
Definition: fcoe.c:95
An FCoE header.
Definition: fcoe.h:50
struct net_protocol fcoe_protocol __net_protocol
FCoE protocol.
Definition: fcoe.c:115
Last Data Frame of Sequence.
Definition: fc.h:203
uint8_t type
Type.
Definition: fip.h:147
Unsolicited Control.
Definition: fc.h:178
uint8_t len
Length in 32-bit words.
Definition: fip.h:223
#define FCOE_MAX_VLAN_REQUESTS
Maximum number of VLAN requests before giving up on VLAN discovery.
Definition: fcoe.c:135
static int fcoe_rx(struct io_buffer *iobuf, struct net_device *netdev, const void *ll_dest, const void *ll_source, unsigned int flags __unused)
Process incoming FCoE packets.
Definition: fcoe.c:320
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
A network upper-layer driver.
Definition: netdevice.h:473
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
A link-layer protocol.
Definition: netdevice.h:114
Address Resolution Protocol constants and types.
int vlan_create(struct net_device *trunk, unsigned int tag, unsigned int priority)
Create VLAN device.
Definition: vlan.c:343
End of Frame Terminate.
Definition: fcoe.h:84
#define ECANCELED
Operation canceled.
Definition: errno.h:343
int xfer_deliver_raw(struct interface *intf, const void *data, size_t len)
Deliver datagram as raw data without metadata.
Definition: xfer.c:288
static int fcoe_fip_parse(struct fcoe_port *fcoe, struct fip_header *fiphdr, size_t len, struct fip_descriptors *descs)
Parse FIP packet into descriptor set.
Definition: fcoe.c:472
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
A FIP VLAN descriptor.
Definition: fip.h:338
Data transfer interfaces.
static uint8_t all_enode_macs[ETH_ALEN]
FCoE All-ENode-MACs address.
Definition: fcoe.c:123
A timer.
Definition: timer.h:28
u32 crc32_le(u32 seed, const void *data, size_t len)
Calculate 32-bit little-endian CRC checksum.
Definition: crc32.c:39
Keep alive.
Definition: fip.h:71
uint16_t code
Protocol code.
Definition: fip.h:35
Fibre Channel over Ethernet.
A FIP frame header.
Definition: fip.h:29
unsigned long frame
Definition: xengrant.h:179
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define ENOMEM
Not enough space.
Definition: errno.h:534
static int fcoe_deliver(struct fcoe_port *fcoe, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
Transmit FCoE packet.
Definition: fcoe.c:202
A hardware device.
Definition: device.h:73
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct io_buffer * fcoe_alloc_iob(struct fcoe_port *fcoe __unused, size_t len)
Allocate FCoE I/O buffer.
Definition: fcoe.c:297
const char * name
Name.
Definition: netdevice.h:475
Discovery solicitation.
Definition: fip.h:59
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:658
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
Ethernet protocol.
An object interface.
Definition: interface.h:124
static uint8_t all_fcf_macs[ETH_ALEN]
FCoE All-FCF-MACs address.
Definition: fcoe.c:127
void * netdev_priv(struct net_device *netdev, struct net_driver *driver)
Get network device driver private data.
Definition: netdevice.c:152
Object interfaces.
#define ETH_P_FIP
Definition: if_ether.h:28
static int fcoe_fip_rx_advertisement(struct fcoe_port *fcoe, struct fip_descriptors *descs, unsigned int flags)
Handle received FIP discovery advertisement.
Definition: fcoe.c:700
struct errortab fcoe_errors [] __errortab
Human-readable message for CRC errors.
Definition: fcoe.c:1191
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:636
static struct net_device * netdev
Definition: gdbudp.c:52
#define MAX_LL_HEADER_LEN
Maximum length of a link-layer header.
Definition: netdevice.h:45
uint16_t flags
Flags.
Definition: fip.h:43
Feature list.
union fcoe_name node_wwn
Node WWN.
Definition: fcoe.c:78
We have a FIP-capable FCoE forwarder available to be used.
Definition: fcoe.c:105
#define EINFO_EINVAL_CRC
Definition: fcoe.c:64
#define FCOE_MAX_FIP_MISSING_KEEPALIVES
Maximum number of missing discovery advertisements.
Definition: fcoe.c:150
static void fcoe_reset(struct fcoe_port *fcoe)
Reset FCoE port.
Definition: fcoe.c:164
uint8_t version
Frame version.
Definition: fip.h:31
uint16_t vlan
VLAN ID.
Definition: fip.h:344
uint16_t authority
Naming authority.
Definition: fcoe.h:24
Maintain virtual links.
Definition: fip.h:53
#define cpu_to_le32(value)
Definition: byteswap.h:107
int meta(WINDOW *, bool)
FCoE forwarder supports server-provided MAC addresses.
Definition: fcoe.c:107
#define ENOTCONN
The socket is not connected.
Definition: errno.h:569
An object interface descriptor.
Definition: interface.h:55
#define iob_unput(iobuf, len)
Definition: iobuf.h:135
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct refcnt refcnt
Reference counter.
Definition: netdevice.h:354
uint8_t len
Length in 32-bit words.
Definition: fip.h:149
static int fcoe_fip_tx_solicitation(struct fcoe_port *fcoe)
Send FIP discovery solicitation.
Definition: fcoe.c:639
uint8_t r_ctl
Routing control.
Definition: fc.h:126
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:175
A FIP descriptor set.
Definition: fip.h:406
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
VLAN.
Definition: fip.h:54
uint16_t len
Descriptor list length in 32-bit words.
Definition: fip.h:41
ELS response.
Definition: fip.h:66
A network device.
Definition: netdevice.h:352
int fc_port_open(struct interface *transport, const struct fc_name *node_wwn, const struct fc_name *port_wwn, const char *name)
Create Fibre Channel port.
Definition: fc.c:1189
Name identifier.
Definition: fip.h:106
#define FCOE_MAX_FIP_SOLICITATIONS
Maximum number of FIP solicitations before giving up on FIP.
Definition: fcoe.c:144
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
A FIP MAC address descriptor.
Definition: fip.h:145
An FCoE port.
Definition: fcoe.c:71
unsigned char uint8_t
Definition: stdint.h:10
A FIP max FCoE size descriptor.
Definition: fip.h:195
static void fcoe_remove(struct net_device *netdev __unused, void *priv)
Destroy FCoE port.
Definition: fcoe.c:1151
static struct device * fcoe_identify_device(struct fcoe_port *fcoe)
Identify device underlying FCoE port.
Definition: fcoe.c:438
#define ETH_ALEN
Definition: if_ether.h:8
Fibre Channel.
uint16_t ll_proto
Link-layer protocol.
Definition: netdevice.h:194
A FIP FKA ADV period descriptor.
Definition: fip.h:307
unsigned int uint32_t
Definition: stdint.h:12
union fip_descriptor * desc[FIP_NUM_DESCRIPTOR_TYPES]
Descriptors, indexed by type.
Definition: fip.h:408
#define EINVAL_CRC
Definition: fcoe.c:63
struct retry_timer timer
FIP retransmission timer.
Definition: fcoe.c:83
A FIP descriptor containing an encapsulated ELS frame.
Definition: fip.h:205
#define EINVAL_EOF
Definition: fcoe.c:66
static size_t fcoe_window(struct fcoe_port *fcoe)
Check FCoE flow control window.
Definition: fcoe.c:416
static int fcoe_fip_rx(struct io_buffer *iobuf, struct net_device *netdev, const void *ll_dest, const void *ll_source __unused, unsigned int flags __unused)
Process incoming FIP packets.
Definition: fcoe.c:913
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
struct fc_name fc
Fibre Channel name.
Definition: fcoe.h:20
A network-layer protocol.
Definition: netdevice.h:64
static void fcoe_expired(struct retry_timer *timer, int over __unused)
Handle FCoE timer expiry.
Definition: fcoe.c:984
Solicited.
Definition: fip.h:86
Network device management.
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
uint8_t f_ctl_es
Frame control - exchange and sequence.
Definition: fc.h:136
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
VLAN discovery has timed out.
Definition: fcoe.c:111
static int fcoe_fip_rx_vlan(struct fcoe_port *fcoe, struct fip_descriptors *descs, unsigned int flags __unused)
Handle received FIP VLAN notification.
Definition: fcoe.c:593
Start of Frame Initiate Class 3.
Definition: fcoe.h:67
#define iob_reserve(iobuf, len)
Definition: iobuf.h:67
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
VLAN request.
Definition: fip.h:77
int vlan_can_be_trunk(struct net_device *trunk)
Check if network device can be used as a VLAN trunk device.
Definition: vlan.c:329
Extended link services.
Definition: fip.h:52
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
int net_tx(struct io_buffer *iobuf, struct net_device *netdev, struct net_protocol *net_protocol, const void *ll_dest, const void *ll_source)
Transmit network-layer packet.
Definition: netdevice.c:1073
uint32_t len
Length.
Definition: ena.h:14
unsigned int keepalive
Keepalive delay (in ms)
Definition: fcoe.c:91
#define DBGC2(...)
Definition: compiler.h:522
VLAN notification.
Definition: fip.h:78
static struct tlan_private * priv
Definition: tlan.c:224
#define EPROTONOSUPPORT
Protocol not supported.
Definition: errno.h:629
static int fcoe_fip_rx_els_response(struct fcoe_port *fcoe, struct fip_descriptors *descs, unsigned int flags __unused)
Handle received FIP ELS response.
Definition: fcoe.c:790
struct net_driver fcoe_driver __net_driver
FCoE driver.
Definition: fcoe.c:114
uint16_t priority
Priotity.
Definition: stp.h:12
uint8_t subcode
Protocol subcode.
Definition: fcoe.c:880
uint16_t code
Protocol code.
Definition: fcoe.c:878
#define EINVAL_SOF
Definition: fcoe.c:60
void * data
Start of data.
Definition: iobuf.h:48
int(* rx)(struct fcoe_port *fcoe, struct fip_descriptors *descs, unsigned int flags)
Receive FIP packet.
Definition: fcoe.c:889
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
Virtual LANs.
We have selected an FCoE forwarder to use.
Definition: fcoe.c:103
uint8_t mac[ETH_ALEN]
MAC address.
Definition: fip.h:151
Device model.
struct device * identify_device(struct interface *intf)
Identify a device behind an interface.
Definition: device.c:125
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition: acpi.c:45
uint8_t sof
Start of Frame marker.
Definition: fcoe.h:56
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
#define DHCP_EB_FEATURE_FCOE
FCoE protocol.
Definition: features.h:53
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
Fabric-provided MAC address.
Definition: fip.h:83
uint8_t subcode
Subcode.
Definition: fip.h:39
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define FCOE_FRAME_VER
FCoE frame version.
Definition: fcoe.h:60
#define ARPHRD_ETHER
Ethernet 10Mbps.
Definition: if_arp.h:16
ELS request.
Definition: fip.h:65
struct fc_frame_header fc
Fibre Channel frame header.
Definition: fip.h:213
A FIP descriptor.
Definition: fip.h:348
#define FCOE_AUTHORITY_IEEE_EXTENDED
IEEE extended.
Definition: fcoe.h:34
uint8_t type
Type.
Definition: fip.h:221
uint64_t tag
Identity tag.
Definition: edd.h:30
union fcoe_name port_wwn
Port WWN.
Definition: fcoe.c:80
static uint8_t all_fcoe_macs[ETH_ALEN]
FCoE All-FCoE-MACs address.
Definition: fcoe.c:119
A FIP name identifier descriptor.
Definition: fip.h:167
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
#define FIP_IS_CRITICAL(type)
FIP descriptor type is critical.
Definition: fip.h:121
static uint8_t default_fcf_mac[ETH_ALEN]
Default FCoE forwarded MAC address.
Definition: fcoe.c:131
Discovery.
Definition: fip.h:51
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Do not send keepalives.
Definition: fip.h:322
Start of Frame Normal Class 3.
Definition: fcoe.h:68
#define htons(value)
Definition: byteswap.h:135
struct bofm_section_header done
Definition: bofm_test.c:46
uint8_t fcf_mac[ETH_ALEN]
FCoE forwarder MAC address.
Definition: fcoe.c:93
#define TICKS_PER_MS
Number of ticks per millisecond.
Definition: timer.h:25
uint8_t len
Length in 32-bit words.
Definition: fip.h:209
uint32_t period
Keep alive advertisement period in milliseconds.
Definition: fip.h:317
struct fcoe_name::@551 fcoe
FCoE name.
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
struct interface transport
Transport interface.
Definition: fcoe.c:73
Server-provided MAC address.
Definition: fip.h:84
End of Frame Normal.
Definition: fcoe.h:83
An FCoE name.
Definition: fcoe.h:18
A Fibre Channel Frame Header.
Definition: fc.h:120
#define ETH_P_FCOE
Definition: if_ether.h:27
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33
uint8_t flags
Flags.
Definition: ena.h:18
FEATURE(FEATURE_PROTOCOL, "FCoE", DHCP_EB_FEATURE_FCOE, 1)