iPXE
Data Structures | Defines | Enumerations | Functions | Variables
fcoe.c File Reference

FCoE protocol. More...

#include <stddef.h>
#include <stdlib.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/if_ether.h>
#include <ipxe/if_arp.h>
#include <ipxe/iobuf.h>
#include <ipxe/interface.h>
#include <ipxe/xfer.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/vlan.h>
#include <ipxe/features.h>
#include <ipxe/errortab.h>
#include <ipxe/device.h>
#include <ipxe/crc32.h>
#include <ipxe/retry.h>
#include <ipxe/timer.h>
#include <ipxe/fc.h>
#include <ipxe/fip.h>
#include <ipxe/fcoe.h>

Go to the source code of this file.

Data Structures

struct  fcoe_port
 An FCoE port. More...
struct  fip_handler
 A FIP handler. More...

Defines

#define EINVAL_UNDERLENGTH   __einfo_error ( EINFO_EINVAL_UNDERLENGTH )
#define EINFO_EINVAL_UNDERLENGTH   __einfo_uniqify ( EINFO_EINVAL, 0x01, "Underlength packet" )
#define EINVAL_SOF   __einfo_error ( EINFO_EINVAL_SOF )
#define EINFO_EINVAL_SOF   __einfo_uniqify ( EINFO_EINVAL, 0x02, "Invalid SoF delimiter" )
#define EINVAL_CRC   __einfo_error ( EINFO_EINVAL_CRC )
#define EINFO_EINVAL_CRC   __einfo_uniqify ( EINFO_EINVAL, 0x03, "Invalid CRC (not stripped?)" )
#define EINVAL_EOF   __einfo_error ( EINFO_EINVAL_EOF )
#define EINFO_EINVAL_EOF   __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid EoF delimiter" )
#define FCOE_MAX_VLAN_REQUESTS   2
 Maximum number of VLAN requests before giving up on VLAN discovery.
#define FCOE_VLAN_RETRY_DELAY   ( TICKS_PER_SEC )
 Delay between retrying VLAN requests.
#define FCOE_VLAN_POLL_DELAY   ( 30 * TICKS_PER_SEC )
 Delay between retrying polling VLAN requests.
#define FCOE_MAX_FIP_SOLICITATIONS   2
 Maximum number of FIP solicitations before giving up on FIP.
#define FCOE_FIP_RETRY_DELAY   ( TICKS_PER_SEC )
 Delay between retrying FIP solicitations.
#define FCOE_MAX_FIP_MISSING_KEEPALIVES   4
 Maximum number of missing discovery advertisements.

Enumerations

enum  fcoe_flags {
  FCOE_HAVE_NETWORK = 0x0001, FCOE_HAVE_FCF = 0x0002, FCOE_HAVE_FIP_FCF = 0x0004, FCOE_FCF_ALLOWS_SPMA = 0x0008,
  FCOE_VLAN_FOUND = 0x0010, FCOE_VLAN_TIMED_OUT = 0x0020
}
 FCoE flags. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FEATURE (FEATURE_PROTOCOL,"FCoE", DHCP_EB_FEATURE_FCOE, 1)
static LIST_HEAD (fcoe_ports)
 List of FCoE ports.
static struct fcoe_portfcoe_demux (struct net_device *netdev)
 Identify FCoE port by network device.
static void fcoe_reset (struct fcoe_port *fcoe)
 Reset FCoE port.
static int fcoe_deliver (struct fcoe_port *fcoe, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Transmit FCoE packet.
static struct io_bufferfcoe_alloc_iob (struct fcoe_port *fcoe __unused, size_t len)
 Allocate FCoE I/O buffer.
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.
static size_t fcoe_window (struct fcoe_port *fcoe)
 Check FCoE flow control window.
static void fcoe_close (struct fcoe_port *fcoe, int rc)
 Close FCoE port.
static struct devicefcoe_identify_device (struct fcoe_port *fcoe)
 Identify device underlying FCoE port.
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.
static int fcoe_fip_tx_vlan (struct fcoe_port *fcoe)
 Send FIP VLAN request.
static int fcoe_fip_rx_vlan (struct fcoe_port *fcoe, struct fip_descriptors *descs, unsigned int flags __unused)
 Handle received FIP VLAN notification.
static int fcoe_fip_tx_solicitation (struct fcoe_port *fcoe)
 Send FIP discovery solicitation.
static int fcoe_fip_rx_advertisement (struct fcoe_port *fcoe, struct fip_descriptors *descs, unsigned int flags)
 Handle received FIP discovery advertisement.
static int fcoe_fip_rx_els_response (struct fcoe_port *fcoe, struct fip_descriptors *descs, unsigned int flags __unused)
 Handle received FIP ELS response.
static int fcoe_fip_tx_keepalive (struct fcoe_port *fcoe)
 Send FIP keepalive.
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.
static void fcoe_expired (struct retry_timer *timer, int over __unused)
 Handle FCoE timer expiry.
static int fcoe_probe (struct net_device *netdev)
 Create FCoE port.
static void fcoe_notify (struct net_device *netdev)
 Handle FCoE port device or link state change.
static void fcoe_remove (struct net_device *netdev)
 Destroy FCoE port.

Variables

struct net_protocol fcoe_protocol __net_protocol
 FCoE protocol.
static uint8_t all_fcoe_macs [ETH_ALEN]
 FCoE All-FCoE-MACs address.
static uint8_t all_enode_macs [ETH_ALEN]
 FCoE All-ENode-MACs address.
static uint8_t all_fcf_macs [ETH_ALEN]
 FCoE All-FCF-MACs address.
static uint8_t default_fcf_mac [ETH_ALEN]
 Default FCoE forwarded MAC address.
static struct interface_operation fcoe_transport_op []
 FCoE transport interface operations.
static struct interface_descriptor fcoe_transport_desc
 FCoE transport interface descriptor.
static struct fip_handler fip_handlers []
 FIP handlers.
struct net_driver fcoe_driver __net_driver
 FCoE driver.
struct errortab fcoe_errors[] __errortab
 Human-readable message for CRC errors.

Detailed Description

FCoE protocol.

Definition in file fcoe.c.


Define Documentation

Definition at line 57 of file fcoe.c.

Referenced by fcoe_rx().

#define EINFO_EINVAL_UNDERLENGTH   __einfo_uniqify ( EINFO_EINVAL, 0x01, "Underlength packet" )

Definition at line 58 of file fcoe.c.

Definition at line 60 of file fcoe.c.

Referenced by fcoe_rx().

#define EINFO_EINVAL_SOF   __einfo_uniqify ( EINFO_EINVAL, 0x02, "Invalid SoF delimiter" )

Definition at line 61 of file fcoe.c.

Definition at line 63 of file fcoe.c.

Referenced by fcoe_rx().

#define EINFO_EINVAL_CRC   __einfo_uniqify ( EINFO_EINVAL, 0x03, "Invalid CRC (not stripped?)" )

Definition at line 64 of file fcoe.c.

Definition at line 66 of file fcoe.c.

Referenced by fcoe_rx().

#define EINFO_EINVAL_EOF   __einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid EoF delimiter" )

Definition at line 67 of file fcoe.c.

#define FCOE_MAX_VLAN_REQUESTS   2

Maximum number of VLAN requests before giving up on VLAN discovery.

Definition at line 138 of file fcoe.c.

Referenced by fcoe_expired().

Delay between retrying VLAN requests.

Definition at line 141 of file fcoe.c.

Referenced by fcoe_expired().

#define FCOE_VLAN_POLL_DELAY   ( 30 * TICKS_PER_SEC )

Delay between retrying polling VLAN requests.

Definition at line 144 of file fcoe.c.

Referenced by fcoe_expired().

Maximum number of FIP solicitations before giving up on FIP.

Definition at line 147 of file fcoe.c.

Referenced by fcoe_expired().

Delay between retrying FIP solicitations.

Definition at line 150 of file fcoe.c.

Referenced by fcoe_expired().

Maximum number of missing discovery advertisements.

Definition at line 153 of file fcoe.c.

Referenced by fcoe_expired().


Enumeration Type Documentation

enum fcoe_flags

FCoE flags.

Enumerator:
FCOE_HAVE_NETWORK 

Underlying network device is available.

FCOE_HAVE_FCF 

We have selected an FCoE forwarder to use.

FCOE_HAVE_FIP_FCF 

We have a FIP-capable FCoE forwarder available to be used.

FCOE_FCF_ALLOWS_SPMA 

FCoE forwarder supports server-provided MAC addresses.

FCOE_VLAN_FOUND 

An alternative VLAN has been found.

FCOE_VLAN_TIMED_OUT 

VLAN discovery has timed out.

Definition at line 103 of file fcoe.c.

                {
        /** Underlying network device is available */
        FCOE_HAVE_NETWORK = 0x0001,
        /** We have selected an FCoE forwarder to use */
        FCOE_HAVE_FCF = 0x0002,
        /** We have a FIP-capable FCoE forwarder available to be used */
        FCOE_HAVE_FIP_FCF = 0x0004,
        /** FCoE forwarder supports server-provided MAC addresses */
        FCOE_FCF_ALLOWS_SPMA = 0x0008,
        /** An alternative VLAN has been found */
        FCOE_VLAN_FOUND = 0x0010,
        /** VLAN discovery has timed out */
        FCOE_VLAN_TIMED_OUT = 0x0020,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
FEATURE ( FEATURE_PROTOCOL  ,
"FCoE"  ,
DHCP_EB_FEATURE_FCOE  ,
 
)
static LIST_HEAD ( fcoe_ports  ) [static]

List of FCoE ports.

static struct fcoe_port* fcoe_demux ( struct net_device netdev) [static, read]

Identify FCoE port by network device.

Parameters:
netdevNetwork device
Return values:
fcoeFCoE port, or NULL

Definition at line 171 of file fcoe.c.

References fcoe_port::list, list_for_each_entry, fcoe_port::netdev, and NULL.

Referenced by fcoe_fip_rx(), fcoe_notify(), fcoe_remove(), and fcoe_rx().

                                                                   {
        struct fcoe_port *fcoe;

        list_for_each_entry ( fcoe, &fcoe_ports, list ) {
                if ( fcoe->netdev == netdev )
                        return fcoe;
        }
        return NULL;
}
static void fcoe_reset ( struct fcoe_port fcoe) [static]

Reset FCoE port.

Parameters:
fcoeFCoE port

Definition at line 186 of file fcoe.c.

References DBGC, default_fcf_mac, ECANCELED, fcoe_port::fcf_mac, FCOE_HAVE_NETWORK, FIP_LOWEST_PRIORITY, fcoe_port::flags, intf_restart(), fcoe_port::keepalive, net_device::ll_addr, fcoe_port::local_mac, memcpy(), net_device::name, fcoe_port::netdev, netdev_is_open(), netdev_link_ok(), fcoe_port::priority, start_timer_nodelay(), stop_timer(), fcoe_port::timeouts, fcoe_port::timer, fcoe_port::transport, vlan_can_be_trunk(), and xfer_window_changed().

Referenced by fcoe_expired(), fcoe_fip_rx_advertisement(), and fcoe_notify().

                                                  {

        /* Detach FC port, if any */
        intf_restart ( &fcoe->transport, -ECANCELED );

        /* Reset any FIP state */
        stop_timer ( &fcoe->timer );
        fcoe->timeouts = 0;
        fcoe->flags = 0;
        fcoe->priority = ( FIP_LOWEST_PRIORITY + 1 );
        fcoe->keepalive = 0;
        memcpy ( fcoe->fcf_mac, default_fcf_mac,
                 sizeof ( fcoe->fcf_mac ) );
        memcpy ( fcoe->local_mac, fcoe->netdev->ll_addr,
                 sizeof ( fcoe->local_mac ) );

        /* Start FIP solicitation if network is available */
        if ( netdev_is_open ( fcoe->netdev ) &&
             netdev_link_ok ( fcoe->netdev ) ) {
                fcoe->flags |= FCOE_HAVE_NETWORK;
                start_timer_nodelay ( &fcoe->timer );
                DBGC ( fcoe, "FCoE %s starting %s\n", fcoe->netdev->name,
                       ( vlan_can_be_trunk ( fcoe->netdev ) ?
                         "VLAN discovery" : "FIP solicitation" ) );
        }

        /* Send notification of window change */
        xfer_window_changed ( &fcoe->transport );
}
static int fcoe_deliver ( struct fcoe_port fcoe,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
) [static]

Transmit FCoE packet.

Parameters:
fcoeFCoE port
iobufI/O buffer
metaData transfer metadata
Return values:
rcReturn status code

Definition at line 224 of file fcoe.c.

References fip_header::code, fc_els_frame_common::command, cpu_to_le32, fcoe_footer::crc, crc32_le(), io_buffer::data, DBGC, done, fcoe_footer::eof, fc_frame_header::f_ctl_es, fc, FC_ELS_FLOGI, FC_F_CTL_ES_END, FC_R_CTL_ELS, FC_R_CTL_UNSOL_CTRL, fcoe_port::fcf_mac, FCOE_EOF_N, FCOE_EOF_T, FCOE_FCF_ALLOWS_SPMA, FCOE_HAVE_FIP_FCF, FCOE_SOF_I3, FCOE_SOF_N3, FIP_CODE_ELS, FIP_ELS_REQUEST, FIP_FLOGI, FIP_FP, FIP_MAC_ADDRESS, FIP_SP, FIP_VERSION, fip_header::flags, fcoe_port::flags, free_iob(), htons, iob_disown, iob_len(), iob_push, iob_put, fip_header::len, fip_mac_address::len, fip_login::len, net_device::ll_addr, fcoe_port::local_mac, fip_mac_address::mac, memcpy(), memset(), net_device::name, net_tx(), fcoe_port::netdev, ntohs, offsetof, fc_frame_header::r_ctl, rc, fc_frame_header::seq_cnt, fcoe_header::sof, strerror(), fip_header::subcode, fip_mac_address::type, fip_login::type, and fip_header::version.

                                                                {
        struct fc_frame_header *fchdr = iobuf->data;
        struct fc_els_frame_common *els = ( iobuf->data + sizeof ( *fchdr ) );
        struct fcoe_header *fcoehdr;
        struct fcoe_footer *fcoeftr;
        struct fip_header *fiphdr;
        struct fip_login *fipflogi;
        struct fip_mac_address *fipmac;
        uint32_t crc;
        struct net_protocol *net_protocol;
        void *ll_source;
        int rc;

        /* Send as FIP or FCoE as appropriate */
        if ( ( fchdr->r_ctl == ( FC_R_CTL_ELS | FC_R_CTL_UNSOL_CTRL ) ) &&
             ( els->command == FC_ELS_FLOGI ) &&
             ( fcoe->flags & FCOE_HAVE_FIP_FCF ) ) {

                /* Create FIP FLOGI descriptor */
                fipflogi = iob_push ( iobuf,
                                      offsetof ( typeof ( *fipflogi ), fc ) );
                memset ( fipflogi, 0, offsetof ( typeof ( *fipflogi ), fc ) );
                fipflogi->type = FIP_FLOGI;
                fipflogi->len = ( iob_len ( iobuf ) / 4 );

                /* Create FIP MAC address descriptor */
                fipmac = iob_put ( iobuf, sizeof ( *fipmac ) );
                memset ( fipmac, 0, sizeof ( *fipmac ) );
                fipmac->type = FIP_MAC_ADDRESS;
                fipmac->len = ( sizeof ( *fipmac ) / 4 );
                if ( fcoe->flags & FCOE_FCF_ALLOWS_SPMA ) {
                        memcpy ( fipmac->mac, fcoe->netdev->ll_addr,
                                 sizeof ( fipmac->mac ) );
                }

                /* Create FIP header */
                fiphdr = iob_push ( iobuf, sizeof ( *fiphdr ) );
                memset ( fiphdr, 0, sizeof ( *fiphdr ) );
                fiphdr->version = FIP_VERSION;
                fiphdr->code = htons ( FIP_CODE_ELS );
                fiphdr->subcode = FIP_ELS_REQUEST;
                fiphdr->len =
                        htons ( ( iob_len ( iobuf ) - sizeof ( *fiphdr ) ) / 4);
                fiphdr->flags = ( ( fcoe->flags & FCOE_FCF_ALLOWS_SPMA ) ?
                                  htons ( FIP_SP ) : htons ( FIP_FP ) );

                /* Send as FIP packet from netdev's own MAC address */
                net_protocol = &fip_protocol;
                ll_source = fcoe->netdev->ll_addr;

        } else {

                /* Calculate CRC */
                crc = crc32_le ( ~((uint32_t)0), iobuf->data,
                                 iob_len ( iobuf ) );

                /* Create FCoE header */
                fcoehdr = iob_push ( iobuf, sizeof ( *fcoehdr ) );
                memset ( fcoehdr, 0, sizeof ( *fcoehdr ) );
                fcoehdr->sof = ( ( fchdr->seq_cnt == ntohs ( 0 ) ) ?
                                 FCOE_SOF_I3 : FCOE_SOF_N3 );

                /* Create FCoE footer */
                fcoeftr = iob_put ( iobuf, sizeof ( *fcoeftr ) );
                memset ( fcoeftr, 0, sizeof ( *fcoeftr ) );
                fcoeftr->crc = cpu_to_le32 ( crc ^ ~((uint32_t)0) );
                fcoeftr->eof = ( ( fchdr->f_ctl_es & FC_F_CTL_ES_END ) ?
                                 FCOE_EOF_T : FCOE_EOF_N );

                /* Send as FCoE packet from FCoE MAC address */
                net_protocol = &fcoe_protocol;
                ll_source = fcoe->local_mac;
        }

        /* Transmit packet */
        if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev, net_protocol,
                             fcoe->fcf_mac, ll_source ) ) != 0 ) {
                DBGC ( fcoe, "FCoE %s could not transmit: %s\n",
                       fcoe->netdev->name, strerror ( rc ) );
                goto done;
        }

 done:
        free_iob ( iobuf );
        return rc;
}
static struct io_buffer* fcoe_alloc_iob ( struct fcoe_port *fcoe  __unused,
size_t  len 
) [static, read]

Allocate FCoE I/O buffer.

Parameters:
lenPayload length
Return values:
iobufI/O buffer, or NULL

Definition at line 319 of file fcoe.c.

References alloc_iob(), iob_reserve, and MAX_LL_HEADER_LEN.

                                                        {
        struct io_buffer *iobuf;

        iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( struct fcoe_header ) +
                            len + sizeof ( struct fcoe_footer ) );
        if ( iobuf ) {
                iob_reserve ( iobuf, ( MAX_LL_HEADER_LEN +
                                       sizeof ( struct fcoe_header ) ) );
        }
        return iobuf;
}
static int fcoe_rx ( struct io_buffer iobuf,
struct net_device netdev,
const void *  ll_dest,
const void *  ll_source,
unsigned int flags  __unused 
) [static]

Process incoming FCoE packets.

Parameters:
iobufI/O buffer
netdevNetwork device
ll_destLink-layer destination address
ll_sourceLink-layer source address
flagsPacket flags
Return values:
rcReturn status code

Definition at line 342 of file fcoe.c.

References fcoe_footer::crc, crc32_le(), io_buffer::data, DBG, DBGC, DBGC2, default_fcf_mac, done, EINVAL_CRC, EINVAL_EOF, EINVAL_SOF, EINVAL_UNDERLENGTH, ENOTCONN, fcoe_footer::eof, EPROTONOSUPPORT, eth_ntoa(), fcoe_port::fcf_mac, fcoe_demux(), FCOE_EOF_N, FCOE_EOF_T, FCOE_FRAME_VER, FCOE_HAVE_FCF, FCOE_HAVE_FIP_FCF, FCOE_SOF_I3, FCOE_SOF_N3, fcoe_port::flags, free_iob(), iob_disown, iob_len(), iob_pull, iob_unput, le32_to_cpu, fcoe_port::local_mac, memcmp(), memcpy(), net_device::name, fcoe_port::netdev, NULL, rc, fcoe_header::sof, strerror(), fcoe_port::transport, fcoe_header::version, and xfer_deliver_iob().

                                                   {
        struct fcoe_header *fcoehdr;
        struct fcoe_footer *fcoeftr;
        struct fcoe_port *fcoe;
        int rc;

        /* Identify FCoE port */
        if ( ( fcoe = fcoe_demux ( netdev ) ) == NULL ) {
                DBG ( "FCoE received frame for net device %s missing FCoE "
                      "port\n", netdev->name );
                rc = -ENOTCONN;
                goto done;
        }

        /* Discard packets not destined for us */
        if ( ( memcmp ( fcoe->local_mac, ll_dest,
                        sizeof ( fcoe->local_mac ) ) != 0 ) &&
             ( memcmp ( default_fcf_mac, ll_dest,
                        sizeof ( default_fcf_mac ) ) != 0 ) ) {
                DBGC2 ( fcoe, "FCoE %s ignoring packet for %s\n",
                        fcoe->netdev->name, eth_ntoa ( ll_dest ) );
                rc = -ENOTCONN;
                goto done;
        }

        /* Sanity check */
        if ( iob_len ( iobuf ) < ( sizeof ( *fcoehdr ) + sizeof ( *fcoeftr ) )){
                DBGC ( fcoe, "FCoE %s received under-length frame (%zd "
                       "bytes)\n", fcoe->netdev->name, iob_len ( iobuf ) );
                rc = -EINVAL_UNDERLENGTH;
                goto done;
        }

        /* Strip header and footer */
        fcoehdr = iobuf->data;
        iob_pull ( iobuf, sizeof ( *fcoehdr ) );
        fcoeftr = ( iobuf->data + iob_len ( iobuf ) - sizeof ( *fcoeftr ) );
        iob_unput ( iobuf, sizeof ( *fcoeftr ) );

        /* Validity checks */
        if ( fcoehdr->version != FCOE_FRAME_VER ) {
                DBGC ( fcoe, "FCoE %s received unsupported frame version "
                       "%02x\n", fcoe->netdev->name, fcoehdr->version );
                rc = -EPROTONOSUPPORT;
                goto done;
        }
        if ( ! ( ( fcoehdr->sof == FCOE_SOF_I3 ) ||
                 ( fcoehdr->sof == FCOE_SOF_N3 ) ) ) {
                DBGC ( fcoe, "FCoE %s received unsupported start-of-frame "
                       "delimiter %02x\n", fcoe->netdev->name, fcoehdr->sof );
                rc = -EINVAL_SOF;
                goto done;
        }
        if ( ( le32_to_cpu ( fcoeftr->crc ) ^ ~((uint32_t)0) ) !=
             crc32_le ( ~((uint32_t)0), iobuf->data, iob_len ( iobuf ) ) ) {
                DBGC ( fcoe, "FCoE %s received invalid CRC\n",
                       fcoe->netdev->name );
                rc = -EINVAL_CRC;
                goto done;
        }
        if ( ! ( ( fcoeftr->eof == FCOE_EOF_N ) ||
                 ( fcoeftr->eof == FCOE_EOF_T ) ) ) {
                DBGC ( fcoe, "FCoE %s received unsupported end-of-frame "
                       "delimiter %02x\n", fcoe->netdev->name, fcoeftr->eof );
                rc = -EINVAL_EOF;
                goto done;
        }

        /* Record FCF address if applicable */
        if ( ( fcoe->flags & FCOE_HAVE_FCF ) &&
             ( ! ( fcoe->flags & FCOE_HAVE_FIP_FCF ) ) ) {
                memcpy ( &fcoe->fcf_mac, ll_source, sizeof ( fcoe->fcf_mac ) );
        }

        /* Hand off via transport interface */
        if ( ( rc = xfer_deliver_iob ( &fcoe->transport,
                                       iob_disown ( iobuf ) ) ) != 0 ) {
                DBGC ( fcoe, "FCoE %s could not deliver frame: %s\n",
                       fcoe->netdev->name, strerror ( rc ) );
                goto done;
        }

 done:
        free_iob ( iobuf );
        return rc;
}
static size_t fcoe_window ( struct fcoe_port fcoe) [static]

Check FCoE flow control window.

Parameters:
fcoeFCoE port
Return values:
lenLength of window

Definition at line 437 of file fcoe.c.

References FCOE_HAVE_FCF, and fcoe_port::flags.

                                                     {
        return ( ( fcoe->flags & FCOE_HAVE_FCF ) ? ~( ( size_t ) 0 ) : 0 );
}
static void fcoe_close ( struct fcoe_port fcoe,
int  rc 
) [static]

Close FCoE port.

Parameters:
fcoeFCoE port
rcReason for close

Definition at line 447 of file fcoe.c.

References intf_shutdown(), fcoe_port::list, list_del, fcoe_port::netdev, netdev_put(), ref_put, fcoe_port::refcnt, stop_timer(), fcoe_port::timer, and fcoe_port::transport.

Referenced by fcoe_remove().

                                                          {

        stop_timer ( &fcoe->timer );
        intf_shutdown ( &fcoe->transport, rc );
        netdev_put ( fcoe->netdev );
        list_del ( &fcoe->list );
        ref_put ( &fcoe->refcnt );
}
static struct device* fcoe_identify_device ( struct fcoe_port fcoe) [static, read]

Identify device underlying FCoE port.

Parameters:
fcoeFCoE port
Return values:
deviceUnderlying device

Definition at line 462 of file fcoe.c.

References net_device::dev, and fcoe_port::netdev.

                                                                       {
        return fcoe->netdev->dev;
}
static int fcoe_fip_parse ( struct fcoe_port fcoe,
struct fip_header fiphdr,
size_t  len,
struct fip_descriptors descs 
) [static]

Parse FIP packet into descriptor set.

Parameters:
fcoeFCoE port
fiphdrFIP header
lenLength of FIP packet
descsDescriptor set to fill in
Return values:
rcReturn status code

Definition at line 496 of file fcoe.c.

References fip_descriptor::common, DBGC, fip_descriptors::desc, EINVAL, ENOTSUP, FIP_IS_CRITICAL, FIP_NUM_DESCRIPTOR_TYPES, FIP_RESERVED, FIP_VERSION, fip_header::len, fip_common::len, len, memset(), net_device::name, fcoe_port::netdev, ntohs, NULL, fip_common::type, and fip_header::version.

Referenced by fcoe_fip_rx().

                                                                        {
        union fip_descriptor *desc;
        size_t descs_len;
        size_t desc_len;
        size_t desc_offset;
        unsigned int desc_type;

        /* Check FIP version */
        if ( fiphdr->version != FIP_VERSION ) {
                DBGC ( fcoe, "FCoE %s received unsupported FIP version %02x\n",
                       fcoe->netdev->name, fiphdr->version );
                return -EINVAL;
        }

        /* Check length */
        descs_len = ( ntohs ( fiphdr->len ) * 4 );
        if ( ( sizeof ( *fiphdr ) + descs_len ) > len ) {
                DBGC ( fcoe, "FCoE %s received bad descriptor list length\n",
                       fcoe->netdev->name );
                return -EINVAL;
        }

        /* Parse descriptor list */
        memset ( descs, 0, sizeof ( *descs ) );
        for ( desc_offset = 0 ;
              desc_offset <= ( descs_len - sizeof ( desc->common ) ) ;
              desc_offset += desc_len ) {

                /* Find descriptor and validate length */
                desc = ( ( ( void * ) ( fiphdr + 1 ) ) + desc_offset );
                desc_type = desc->common.type;
                desc_len = ( desc->common.len * 4 );
                if ( desc_len == 0 ) {
                        DBGC ( fcoe, "FCoE %s received zero-length "
                               "descriptor\n", fcoe->netdev->name );
                        return -EINVAL;
                }
                if ( ( desc_offset + desc_len ) > descs_len ) {
                        DBGC ( fcoe, "FCoE %s descriptor overrun\n",
                               fcoe->netdev->name );
                        return -EINVAL;
                }

                /* Handle descriptors that we understand */
                if ( ( desc_type > FIP_RESERVED ) &&
                     ( desc_type < FIP_NUM_DESCRIPTOR_TYPES ) ) {
                        /* Use only the first instance of a descriptor */
                        if ( descs->desc[desc_type] == NULL )
                                descs->desc[desc_type] = desc;
                        continue;
                }

                /* Abort if we cannot understand a critical descriptor */
                if ( FIP_IS_CRITICAL ( desc_type ) ) {
                        DBGC ( fcoe, "FCoE %s cannot understand critical "
                               "descriptor type %02x\n",
                               fcoe->netdev->name, desc_type );
                        return -ENOTSUP;
                }

                /* Ignore non-critical descriptors that we cannot understand */
        }

        return 0;
}
static int fcoe_fip_tx_vlan ( struct fcoe_port fcoe) [static]

Send FIP VLAN request.

Parameters:
fcoeFCoE port
Return values:
rcReturn status code

Definition at line 569 of file fcoe.c.

References __attribute__, all_fcf_macs, alloc_iob(), DBGC, ENOMEM, FIP_CODE_VLAN, FIP_MAC_ADDRESS, FIP_VERSION, FIP_VLAN_REQUEST, htons, iob_disown, iob_put, iob_reserve, net_device::ll_addr, MAX_LL_HEADER_LEN, memcpy(), memset(), net_device::name, net_tx(), fcoe_port::netdev, rc, request, and strerror().

Referenced by fcoe_expired().

                                                       {
        struct io_buffer *iobuf;
        struct {
                struct fip_header hdr;
                struct fip_mac_address mac_address;
        } __attribute__ (( packed )) *request;
        int rc;

        /* Allocate I/O buffer */
        iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( *request ) );
        if ( ! iobuf )
                return -ENOMEM;
        iob_reserve ( iobuf, MAX_LL_HEADER_LEN );

        /* Construct VLAN request */
        request = iob_put ( iobuf, sizeof ( *request ) );
        memset ( request, 0, sizeof ( *request ) );
        request->hdr.version = FIP_VERSION;
        request->hdr.code = htons ( FIP_CODE_VLAN );
        request->hdr.subcode = FIP_VLAN_REQUEST;
        request->hdr.len = htons ( ( sizeof ( *request ) -
                                     sizeof ( request->hdr ) ) / 4 );
        request->mac_address.type = FIP_MAC_ADDRESS;
        request->mac_address.len =
                ( sizeof ( request->mac_address ) / 4 );
        memcpy ( request->mac_address.mac, fcoe->netdev->ll_addr,
                 sizeof ( request->mac_address.mac ) );

        /* Send VLAN request */
        if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev,
                             &fip_protocol, all_fcf_macs,
                             fcoe->netdev->ll_addr ) ) != 0 ) {
                DBGC ( fcoe, "FCoE %s could not send VLAN request: "
                       "%s\n", fcoe->netdev->name, strerror ( rc ) );
                return rc;
        }

        return 0;
}
static int fcoe_fip_rx_vlan ( struct fcoe_port fcoe,
struct fip_descriptors descs,
unsigned int flags  __unused 
) [static]

Handle received FIP VLAN notification.

Parameters:
fcoeFCoE port
descsDescriptor list
flagsFlags
Return values:
rcReturn status code

Definition at line 617 of file fcoe.c.

References DBGC, EINVAL, eth_ntoa(), FCOE_VLAN_FOUND, FCOE_VLAN_PRIORITY, fcoe_port::flags, fip_mac_address::mac, net_device::name, fcoe_port::netdev, ntohs, rc, strerror(), tag, fip_vlan::vlan, and vlan_create().

                                                            {
        struct fip_mac_address *mac_address = fip_mac_address ( descs );
        struct fip_vlan *vlan = fip_vlan ( descs );
        unsigned int tag;
        int rc;

        /* Sanity checks */
        if ( ! mac_address ) {
                DBGC ( fcoe, "FCoE %s received VLAN notification missing MAC "
                       "address\n", fcoe->netdev->name );
                return -EINVAL;
        }
        if ( ! vlan ) {
                DBGC ( fcoe, "FCoE %s received VLAN notification missing VLAN "
                       "tag\n", fcoe->netdev->name );
                return -EINVAL;
        }

        /* Create VLAN */
        tag = ntohs ( vlan->vlan );
        DBGC ( fcoe, "FCoE %s creating VLAN %d for FCF %s\n",
               fcoe->netdev->name, tag, eth_ntoa ( mac_address->mac ) );
        if ( ( rc = vlan_create ( fcoe->netdev, tag,
                                  FCOE_VLAN_PRIORITY ) ) != 0 ) {
                DBGC ( fcoe, "FCoE %s could not create VLAN %d: %s\n",
                       fcoe->netdev->name, tag, strerror ( rc ) );
                return rc;
        }

        /* Record that a VLAN was found.  This FCoE port will play no
         * further active role; the real FCoE traffic will use the
         * port automatically created for the new VLAN device.
         */
        fcoe->flags |= FCOE_VLAN_FOUND;

        return 0;
}
static int fcoe_fip_tx_solicitation ( struct fcoe_port fcoe) [static]

Send FIP discovery solicitation.

Parameters:
fcoeFCoE port
Return values:
rcReturn status code

Definition at line 663 of file fcoe.c.

References __attribute__, all_fcf_macs, alloc_iob(), DBGC, ENOMEM, fcoe_name::fc, FIP_CODE_DISCOVERY, FIP_DISCOVERY_SOLICIT, FIP_FP, FIP_MAC_ADDRESS, FIP_MAX_FCOE_SIZE, FIP_NAME_ID, FIP_SP, FIP_VERSION, htons, iob_disown, iob_put, iob_reserve, net_device::ll_addr, MAX_LL_HEADER_LEN, memcpy(), memset(), net_device::name, net_tx(), fcoe_port::netdev, fcoe_port::node_wwn, rc, and strerror().

Referenced by fcoe_expired().

                                                               {
        struct io_buffer *iobuf;
        struct {
                struct fip_header hdr;
                struct fip_mac_address mac_address;
                struct fip_name_id name_id;
                struct fip_max_fcoe_size max_fcoe_size;
        } __attribute__ (( packed )) *solicitation;
        int rc;

        /* Allocate I/O buffer */
        iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( *solicitation ) );
        if ( ! iobuf )
                return -ENOMEM;
        iob_reserve ( iobuf, MAX_LL_HEADER_LEN );

        /* Construct discovery solicitation */
        solicitation = iob_put ( iobuf, sizeof ( *solicitation ) );
        memset ( solicitation, 0, sizeof ( *solicitation ) );
        solicitation->hdr.version = FIP_VERSION;
        solicitation->hdr.code = htons ( FIP_CODE_DISCOVERY );
        solicitation->hdr.subcode = FIP_DISCOVERY_SOLICIT;
        solicitation->hdr.len = htons ( ( sizeof ( *solicitation ) -
                                          sizeof ( solicitation->hdr ) ) / 4 );
        solicitation->hdr.flags = htons ( FIP_FP | FIP_SP );
        solicitation->mac_address.type = FIP_MAC_ADDRESS;
        solicitation->mac_address.len =
                ( sizeof ( solicitation->mac_address ) / 4 );
        memcpy ( solicitation->mac_address.mac, fcoe->netdev->ll_addr,
                 sizeof ( solicitation->mac_address.mac ) );
        solicitation->name_id.type = FIP_NAME_ID;
        solicitation->name_id.len = ( sizeof ( solicitation->name_id ) / 4 );
        memcpy ( &solicitation->name_id.name, &fcoe->node_wwn.fc,
                 sizeof ( solicitation->name_id.name ) );
        solicitation->max_fcoe_size.type = FIP_MAX_FCOE_SIZE;
        solicitation->max_fcoe_size.len =
                ( sizeof ( solicitation->max_fcoe_size ) / 4 );
        solicitation->max_fcoe_size.mtu =
                htons ( ETH_MAX_MTU - sizeof ( struct fcoe_header ) -
                        sizeof ( struct fcoe_footer ) );

        /* Send discovery solicitation */
        if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev,
                             &fip_protocol, all_fcf_macs,
                             fcoe->netdev->ll_addr ) ) != 0 ) {
                DBGC ( fcoe, "FCoE %s could not send discovery solicitation: "
                       "%s\n", fcoe->netdev->name, strerror ( rc ) );
                return rc;
        }

        return 0;
}
static int fcoe_fip_rx_advertisement ( struct fcoe_port fcoe,
struct fip_descriptors descs,
unsigned int  flags 
) [static]

Handle received FIP discovery advertisement.

Parameters:
fcoeFCoE port
descsDescriptor list
flagsFlags
Return values:
rcReturn status code

Definition at line 724 of file fcoe.c.

References DBGC, EINVAL, eth_ntoa(), fcoe_port::fcf_mac, FCOE_FCF_ALLOWS_SPMA, FCOE_HAVE_FCF, FCOE_HAVE_FIP_FCF, fcoe_reset(), FIP_A, FIP_F, FIP_NO_KEEPALIVE, FIP_S, FIP_SP, fcoe_port::flags, fip_fka_adv_p::flags, fcoe_port::keepalive, fip_mac_address::mac, memcmp(), memcpy(), net_device::name, fcoe_port::netdev, ntohl, fip_fka_adv_p::period, priority, fcoe_port::priority, fip_priority::priority, and fcoe_port::timeouts.

                                                            {
        struct fip_priority *priority = fip_priority ( descs );
        struct fip_mac_address *mac_address = fip_mac_address ( descs );
        struct fip_fka_adv_p *fka_adv_p = fip_fka_adv_p ( descs );

        /* Sanity checks */
        if ( ! priority ) {
                DBGC ( fcoe, "FCoE %s received advertisement missing "
                       "priority\n", fcoe->netdev->name );
                return -EINVAL;
        }
        if ( ! mac_address ) {
                DBGC ( fcoe, "FCoE %s received advertisement missing MAC "
                       "address\n", fcoe->netdev->name );
                return -EINVAL;
        }
        if ( ! fka_adv_p ) {
                DBGC ( fcoe, "FCoE %s received advertisement missing FKA ADV "
                       "period\n", fcoe->netdev->name );
                return -EINVAL;
        }

        if ( ! ( fcoe->flags & FCOE_HAVE_FCF ) ) {

                /* We are soliciting for an FCF.  Store the highest
                 * (i.e. lowest-valued) priority solicited
                 * advertisement that we receive.
                 */
                if ( ( ( flags & ( FIP_A | FIP_S | FIP_F ) ) ==
                       ( FIP_A | FIP_S | FIP_F ) ) &&
                     ( priority->priority < fcoe->priority ) ) {

                        fcoe->flags |= FCOE_HAVE_FIP_FCF;
                        fcoe->priority = priority->priority;
                        if ( fka_adv_p->flags & FIP_NO_KEEPALIVE ) {
                                fcoe->keepalive = 0;
                        } else {
                                fcoe->keepalive = ntohl ( fka_adv_p->period );
                        }
                        fcoe->flags &= ~FCOE_FCF_ALLOWS_SPMA;
                        if ( flags & FIP_SP )
                                fcoe->flags |= FCOE_FCF_ALLOWS_SPMA;
                        memcpy ( fcoe->fcf_mac, mac_address->mac,
                                 sizeof ( fcoe->fcf_mac ) );
                        DBGC ( fcoe, "FCoE %s selected FCF %s (pri %d",
                               fcoe->netdev->name, eth_ntoa ( fcoe->fcf_mac ),
                               fcoe->priority );
                        if ( fcoe->keepalive ) {
                                DBGC ( fcoe, ", FKA ADV %dms",
                                       fcoe->keepalive );
                        }
                        DBGC ( fcoe, ", %cPMA)\n",
                               ( ( fcoe->flags & FCOE_FCF_ALLOWS_SPMA ) ?
                                 'S' : 'F' ) );
                }

        } else if ( fcoe->flags & FCOE_HAVE_FIP_FCF ) {

                /* We are checking that the FCF remains alive.  Reset
                 * the timeout counter if this is an advertisement
                 * from our forwarder.
                 */
                if ( memcmp ( fcoe->fcf_mac, mac_address->mac,
                              sizeof ( fcoe->fcf_mac ) ) == 0 ) {
                        fcoe->timeouts = 0;
                }

        } else {

                /* We are operating in non-FIP mode and have received
                 * a FIP advertisement.  Reset the link in order to
                 * attempt FIP.
                 */
                fcoe_reset ( fcoe );

        }

        return 0;
}
static int fcoe_fip_rx_els_response ( struct fcoe_port fcoe,
struct fip_descriptors descs,
unsigned int flags  __unused 
) [static]

Handle received FIP ELS response.

Parameters:
fcoeFCoE port
descsDescriptor list
flagsFlags
Return values:
rcReturn status code

Definition at line 814 of file fcoe.c.

References DBGC, EINVAL, eth_ntoa(), fip_els::fc, fc, fip_els::len, fcoe_port::local_mac, fip_mac_address::mac, memcpy(), net_device::name, fcoe_port::netdev, offsetof, rc, strerror(), fcoe_port::transport, and xfer_deliver_raw().

                                                                    {
        struct fip_els *flogi = fip_flogi ( descs );
        struct fip_mac_address *mac_address = fip_mac_address ( descs );
        void *frame;
        size_t frame_len;
        int rc;

        /* Sanity checks */
        if ( ! flogi ) {
                DBGC ( fcoe, "FCoE %s received ELS response missing FLOGI\n",
                       fcoe->netdev->name );
                return -EINVAL;
        }
        if ( ! mac_address ) {
                DBGC ( fcoe, "FCoE %s received ELS response missing MAC "
                       "address\n", fcoe->netdev->name );
                return -EINVAL;
        }

        /* Record local MAC address */
        memcpy ( fcoe->local_mac, mac_address->mac, sizeof ( fcoe->local_mac ));
        DBGC ( fcoe, "FCoE %s using local MAC %s\n",
               fcoe->netdev->name, eth_ntoa ( fcoe->local_mac ) );

        /* Hand off via transport interface */
        frame = &flogi->fc;
        frame_len = ( ( flogi->len * 4 ) - offsetof ( typeof ( *flogi ), fc ) );
        if ( ( rc = xfer_deliver_raw ( &fcoe->transport, frame,
                                       frame_len ) ) != 0 ) {
                DBGC ( fcoe, "FCoE %s could not deliver FIP FLOGI frame: %s\n",
                       fcoe->netdev->name, strerror ( rc ) );
                return rc;
        }

        return 0;
}
static int fcoe_fip_tx_keepalive ( struct fcoe_port fcoe) [static]

Send FIP keepalive.

Parameters:
fcoeFCoE port
Return values:
rcReturn status code

Definition at line 859 of file fcoe.c.

References __attribute__, alloc_iob(), DBGC, ENOMEM, fcoe_port::fcf_mac, FIP_CODE_MAINTAIN, FIP_MAC_ADDRESS, FIP_MAINTAIN_KEEP_ALIVE, FIP_VERSION, htons, iob_disown, iob_put, iob_reserve, net_device::ll_addr, MAX_LL_HEADER_LEN, memcpy(), memset(), net_device::name, net_tx(), fcoe_port::netdev, rc, and strerror().

Referenced by fcoe_expired().

                                                            {
        struct io_buffer *iobuf;
        struct {
                struct fip_header hdr;
                struct fip_mac_address mac_address;
        } __attribute__ (( packed )) *keepalive;
        int rc;

        /* Allocate I/O buffer */
        iobuf = alloc_iob ( MAX_LL_HEADER_LEN + sizeof ( *keepalive ) );
        if ( ! iobuf )
                return -ENOMEM;
        iob_reserve ( iobuf, MAX_LL_HEADER_LEN );

        /* Construct keepalive */
        keepalive = iob_put ( iobuf, sizeof ( *keepalive ) );
        memset ( keepalive, 0, sizeof ( *keepalive ) );
        keepalive->hdr.version = FIP_VERSION;
        keepalive->hdr.code = htons ( FIP_CODE_MAINTAIN );
        keepalive->hdr.subcode = FIP_MAINTAIN_KEEP_ALIVE;
        keepalive->hdr.len =    htons ( ( sizeof ( *keepalive ) -
                                          sizeof ( keepalive->hdr ) ) / 4 );
        keepalive->mac_address.type = FIP_MAC_ADDRESS;
        keepalive->mac_address.len =
                ( sizeof ( keepalive->mac_address ) / 4 );
        memcpy ( keepalive->mac_address.mac, fcoe->netdev->ll_addr,
                 sizeof ( keepalive->mac_address.mac ) );

        /* Send keepalive */
        if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev,
                             &fip_protocol, fcoe->fcf_mac,
                             fcoe->netdev->ll_addr ) ) != 0 ) {
                DBGC ( fcoe, "FCoE %s could not send keepalive: %s\n",
                       fcoe->netdev->name, strerror ( rc ) );
                return rc;
        }

        return 0;
}
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 
) [static]

Process incoming FIP packets.

Parameters:
iobufI/O buffer
netdevNetwork device
ll_destLink-layer destination address
ll_sourceLink-layer source address
flagsPacket flags
Return values:
rcReturn status code

Definition at line 937 of file fcoe.c.

References all_enode_macs, all_fcoe_macs, fip_header::code, fip_handler::code, io_buffer::data, DBG, DBGC, DBGC2, done, ENOTCONN, ENOTSUP, ETH_ALEN, eth_ntoa(), fcoe_demux(), fcoe_fip_parse(), fip_handlers, fip_header::flags, free_iob(), iob_len(), net_device::ll_addr, memcmp(), net_device::name, fcoe_port::netdev, ntohs, NULL, rc, fip_handler::rx, fip_header::subcode, and fip_handler::subcode.

                                                       {
        struct fip_header *fiphdr = iobuf->data;
        struct fip_descriptors descs;
        struct fip_handler *handler;
        struct fcoe_port *fcoe;
        unsigned int i;
        int rc;

        /* Identify FCoE port */
        if ( ( fcoe = fcoe_demux ( netdev ) ) == NULL ) {
                DBG ( "FCoE received FIP frame for net device %s missing FCoE "
                      "port\n", netdev->name );
                rc = -ENOTCONN;
                goto done;
        }

        /* Discard packets not destined for us */
        if ( ( memcmp ( fcoe->netdev->ll_addr, ll_dest, ETH_ALEN ) != 0 ) &&
             ( memcmp ( all_fcoe_macs, ll_dest,
                        sizeof ( all_fcoe_macs ) ) != 0 ) &&
             ( memcmp ( all_enode_macs, ll_dest,
                        sizeof ( all_enode_macs ) ) != 0 ) ) {
                DBGC2 ( fcoe, "FCoE %s ignoring FIP packet for %s\n",
                        fcoe->netdev->name, eth_ntoa ( ll_dest ) );
                rc = -ENOTCONN;
                goto done;
        }

        /* Parse FIP packet */
        if ( ( rc = fcoe_fip_parse ( fcoe, fiphdr, iob_len ( iobuf ),
                                     &descs ) ) != 0 )
                goto done;

        /* Find a suitable handler */
        for ( i = 0 ; i < ( sizeof ( fip_handlers ) /
                            sizeof ( fip_handlers[0] ) ) ; i++ ) {
                handler = &fip_handlers[i];
                if ( ( handler->code == ntohs ( fiphdr->code ) ) &&
                     ( handler->subcode == fiphdr->subcode ) ) {
                        rc = handler->rx ( fcoe, &descs,
                                           ntohs ( fiphdr->flags ) );
                        goto done;
                }
        }
        DBGC ( fcoe, "FCoE %s received unsupported FIP code %04x.%02x\n",
               fcoe->netdev->name, ntohs ( fiphdr->code ), fiphdr->subcode );
        rc = -ENOTSUP;

 done:
        free_iob ( iobuf );
        return rc;
}
static void fcoe_expired ( struct retry_timer timer,
int over  __unused 
) [static]

Handle FCoE timer expiry.

Parameters:
timerFIP timer
overTimer expired

Definition at line 1007 of file fcoe.c.

References assert, container_of, DBGC, eth_ntoa(), fcoe_name::fc, fc_port_open(), fcoe_port::fcf_mac, FCOE_FIP_RETRY_DELAY, fcoe_fip_tx_keepalive(), fcoe_fip_tx_solicitation(), fcoe_fip_tx_vlan(), FCOE_HAVE_FCF, FCOE_HAVE_FIP_FCF, FCOE_HAVE_NETWORK, FCOE_MAX_FIP_MISSING_KEEPALIVES, FCOE_MAX_FIP_SOLICITATIONS, FCOE_MAX_VLAN_REQUESTS, fcoe_reset(), FCOE_VLAN_FOUND, FCOE_VLAN_POLL_DELAY, FCOE_VLAN_RETRY_DELAY, FCOE_VLAN_TIMED_OUT, fcoe_port::flags, fcoe_port::keepalive, net_device::name, fcoe_port::netdev, fcoe_port::node_wwn, fcoe_port::port_wwn, rc, start_timer_fixed(), start_timer_nodelay(), stop_timer(), strerror(), TICKS_PER_MS, fcoe_port::timeouts, fcoe_port::timer, fcoe_port::transport, vlan_can_be_trunk(), and xfer_window_changed().

Referenced by fcoe_probe().

                                                                          {
        struct fcoe_port *fcoe =
                container_of ( timer, struct fcoe_port, timer );
        int rc;

        /* Sanity check */
        assert ( fcoe->flags & FCOE_HAVE_NETWORK );

        /* Increment the timeout counter */
        fcoe->timeouts++;

        if ( vlan_can_be_trunk ( fcoe->netdev ) &&
             ! ( fcoe->flags & FCOE_VLAN_TIMED_OUT ) ) {

                /* If we have already found a VLAN, send infrequent
                 * VLAN requests, in case VLAN information changes.
                 */
                if ( fcoe->flags & FCOE_VLAN_FOUND ) {
                        fcoe->flags &= ~FCOE_VLAN_FOUND;
                        fcoe->timeouts = 0;
                        start_timer_fixed ( &fcoe->timer,
                                            FCOE_VLAN_POLL_DELAY );
                        fcoe_fip_tx_vlan ( fcoe );
                        return;
                }

                /* If we have not yet found a VLAN, and we have not
                 * yet timed out and given up on finding one, then
                 * send a VLAN request and wait.
                 */
                if ( fcoe->timeouts <= FCOE_MAX_VLAN_REQUESTS ) {
                        start_timer_fixed ( &fcoe->timer,
                                            FCOE_VLAN_RETRY_DELAY );
                        fcoe_fip_tx_vlan ( fcoe );
                        return;
                }

                /* We have timed out waiting for a VLAN; proceed to
                 * FIP discovery.
                 */
                fcoe->flags |= FCOE_VLAN_TIMED_OUT;
                fcoe->timeouts = 0;
                DBGC ( fcoe, "FCoE %s giving up on VLAN discovery\n",
                       fcoe->netdev->name );
                start_timer_nodelay ( &fcoe->timer );

        } else if ( ! ( fcoe->flags & FCOE_HAVE_FCF ) ) {

                /* If we have not yet found a FIP-capable forwarder,
                 * and we have not yet timed out and given up on
                 * finding one, then send a FIP solicitation and wait.
                 */
                start_timer_fixed ( &fcoe->timer, FCOE_FIP_RETRY_DELAY );
                if ( ( ! ( fcoe->flags & FCOE_HAVE_FIP_FCF ) ) &&
                     ( fcoe->timeouts <= FCOE_MAX_FIP_SOLICITATIONS ) ) {
                        fcoe_fip_tx_solicitation ( fcoe );
                        return;
                }

                /* Attach Fibre Channel port */
                if ( ( rc = fc_port_open ( &fcoe->transport, &fcoe->node_wwn.fc,
                                           &fcoe->port_wwn.fc,
                                           fcoe->netdev->name ) ) != 0 ) {
                        DBGC ( fcoe, "FCoE %s could not create FC port: %s\n",
                               fcoe->netdev->name, strerror ( rc ) );
                        /* We will try again on the next timer expiry */
                        return;
                }
                stop_timer ( &fcoe->timer );

                /* Either we have found a FIP-capable forwarder, or we
                 * have timed out and will fall back to pre-FIP mode.
                 */
                fcoe->flags |= FCOE_HAVE_FCF;
                fcoe->timeouts = 0;
                DBGC ( fcoe, "FCoE %s using %sFIP FCF %s\n", fcoe->netdev->name,
                       ( ( fcoe->flags & FCOE_HAVE_FIP_FCF ) ? "" : "non-" ),
                       eth_ntoa ( fcoe->fcf_mac ) );

                /* Start sending keepalives if applicable */
                if ( fcoe->keepalive )
                        start_timer_nodelay ( &fcoe->timer );

                /* Send notification of window change */
                xfer_window_changed ( &fcoe->transport );

        } else {

                /* Send keepalive */
                start_timer_fixed ( &fcoe->timer,
                                    ( fcoe->keepalive * TICKS_PER_MS ) );
                fcoe_fip_tx_keepalive ( fcoe );

                /* Abandon FCF if we have not seen its advertisements */
                if ( fcoe->timeouts > FCOE_MAX_FIP_MISSING_KEEPALIVES ) {
                        DBGC ( fcoe, "FCoE %s abandoning FCF %s\n",
                               fcoe->netdev->name, eth_ntoa ( fcoe->fcf_mac ));
                        fcoe_reset ( fcoe );
                }
        }
}
static int fcoe_probe ( struct net_device netdev) [static]

Create FCoE port.

Parameters:
netdevNetwork device
Return values:
rcReturn status code

Definition at line 1115 of file fcoe.c.

References ARPHRD_ETHER, fcoe_name::authority, DBG, DBGC, ENOMEM, fcoe_name::fc, fc_ntoa(), fcoe_name::fcoe, FCOE_AUTHORITY_IEEE, FCOE_AUTHORITY_IEEE_EXTENDED, fcoe_expired(), htons, intf_init(), fcoe_port::list, list_add, net_device::ll_addr, ll_protocol::ll_proto, net_device::ll_protocol, fcoe_name::mac, memcpy(), net_device::name, fcoe_port::netdev, netdev_get(), netdev_put(), fcoe_port::node_wwn, NULL, fcoe_port::port_wwn, rc, ref_init, fcoe_port::refcnt, fcoe_port::timer, fcoe_port::transport, and zalloc().

                                                    {
        struct ll_protocol *ll_protocol = netdev->ll_protocol;
        struct fcoe_port *fcoe;
        int rc;

        /* Sanity check */
        if ( ll_protocol->ll_proto != htons ( ARPHRD_ETHER ) ) {
                /* Not an error; simply skip this net device */
                DBG ( "FCoE skipping non-Ethernet device %s\n", netdev->name );
                rc = 0;
                goto err_non_ethernet;
        }

        /* Allocate and initialise structure */
        fcoe = zalloc ( sizeof ( *fcoe ) );
        if ( ! fcoe ) {
                rc = -ENOMEM;
                goto err_zalloc;
        }
        ref_init ( &fcoe->refcnt, NULL );
        intf_init ( &fcoe->transport, &fcoe_transport_desc, &fcoe->refcnt );
        timer_init ( &fcoe->timer, fcoe_expired, &fcoe->refcnt );
        fcoe->netdev = netdev_get ( netdev );

        /* Construct node and port names */
        fcoe->node_wwn.fcoe.authority = htons ( FCOE_AUTHORITY_IEEE );
        memcpy ( &fcoe->node_wwn.fcoe.mac, netdev->ll_addr,
                 sizeof ( fcoe->node_wwn.fcoe.mac ) );
        fcoe->port_wwn.fcoe.authority = htons ( FCOE_AUTHORITY_IEEE_EXTENDED );
        memcpy ( &fcoe->port_wwn.fcoe.mac, netdev->ll_addr,
                 sizeof ( fcoe->port_wwn.fcoe.mac ) );

        DBGC ( fcoe, "FCoE %s is %s", fcoe->netdev->name,
               fc_ntoa ( &fcoe->node_wwn.fc ) );
        DBGC ( fcoe, " port %s\n", fc_ntoa ( &fcoe->port_wwn.fc ) );

        /* Transfer reference to port list */
        list_add ( &fcoe->list, &fcoe_ports );
        return 0;

        netdev_put ( fcoe->netdev );
 err_zalloc:
 err_non_ethernet:
        return rc;
}
static void fcoe_notify ( struct net_device netdev) [static]

Handle FCoE port device or link state change.

Parameters:
netdevNetwork device

Definition at line 1166 of file fcoe.c.

References DBG, fcoe_demux(), FCOE_HAVE_NETWORK, fcoe_reset(), fcoe_port::flags, net_device::name, netdev_is_open(), netdev_link_ok(), and NULL.

                                                      {
        struct fcoe_port *fcoe;

        /* Sanity check */
        if ( ( fcoe = fcoe_demux ( netdev ) ) == NULL ) {
                DBG ( "FCoE notification for net device %s missing FCoE "
                      "port\n", netdev->name );
                return;
        }

        /* Reset the FCoE link if necessary */
        if ( ! ( netdev_is_open ( netdev ) &&
                 netdev_link_ok ( netdev ) &&
                 ( fcoe->flags & FCOE_HAVE_NETWORK ) ) ) {
                fcoe_reset ( fcoe );
        }
}
static void fcoe_remove ( struct net_device netdev) [static]

Destroy FCoE port.

Parameters:
netdevNetwork device

Definition at line 1189 of file fcoe.c.

References DBG, fcoe_close(), fcoe_demux(), net_device::name, and NULL.

                                                      {
        struct fcoe_port *fcoe;

        /* Sanity check */
        if ( ( fcoe = fcoe_demux ( netdev ) ) == NULL ) {
                DBG ( "FCoE removal of net device %s missing FCoE port\n",
                      netdev->name );
                return;
        }

        /* Close FCoE device */
        fcoe_close ( fcoe, 0 );
}

Variable Documentation

struct net_protocol fip_protocol __net_protocol
Initial value:
 {
        .name = "FCoE",
        .net_proto = htons ( ETH_P_FCOE ),
        .rx = fcoe_rx,
}

FCoE protocol.

AoE protocol.

FIP protocol.

Definition at line 118 of file fcoe.c.

Initial value:
        { 0x01, 0x10, 0x18, 0x01, 0x00, 0x00 }

FCoE All-FCoE-MACs address.

Definition at line 122 of file fcoe.c.

Referenced by fcoe_fip_rx().

Initial value:
        { 0x01, 0x10, 0x18, 0x01, 0x00, 0x01 }

FCoE All-ENode-MACs address.

Definition at line 126 of file fcoe.c.

Referenced by fcoe_fip_rx().

Initial value:
        { 0x01, 0x10, 0x18, 0x01, 0x00, 0x02 }

FCoE All-FCF-MACs address.

Definition at line 130 of file fcoe.c.

Referenced by fcoe_fip_tx_solicitation(), and fcoe_fip_tx_vlan().

Initial value:
        { 0x0e, 0xfc, 0x00, 0xff, 0xff, 0xfe }

Default FCoE forwarded MAC address.

Definition at line 134 of file fcoe.c.

Referenced by fcoe_reset(), and fcoe_rx().

Initial value:

FCoE transport interface operations.

Definition at line 467 of file fcoe.c.

Initial value:

FCoE transport interface descriptor.

Definition at line 477 of file fcoe.c.

struct fip_handler fip_handlers[] [static]
struct net_driver fcoe_driver __net_driver
Initial value:
 {
        .name = "FCoE",
        .probe = fcoe_probe,
        .notify = fcoe_notify,
        .remove = fcoe_remove,
}

FCoE driver.

Definition at line 1204 of file fcoe.c.

struct errortab fcoe_errors [] __errortab
Initial value:

Human-readable message for CRC errors.

It seems as though several drivers neglect to strip the Ethernet CRC, which will cause the FCoE footer to be misplaced and result (coincidentally) in an "invalid CRC" error from FCoE.

Definition at line 1231 of file fcoe.c.