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

Fibre Channel. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/refcnt.h>
#include <ipxe/list.h>
#include <ipxe/tables.h>
#include <ipxe/timer.h>
#include <ipxe/retry.h>
#include <ipxe/interface.h>
#include <ipxe/xfer.h>
#include <ipxe/iobuf.h>
#include <ipxe/fc.h>
#include <ipxe/fcels.h>
#include <ipxe/fcns.h>

Go to the source code of this file.

Data Structures

struct  fc_exchange
 A Fibre Channel exchange. More...

Defines

#define EUNKNOWN_LINK_STATUS   __einfo_error ( EINFO_EUNKNOWN_LINK_STATUS )
 Default link status code.
#define EINFO_EUNKNOWN_LINK_STATUS   __einfo_uniqify ( EINFO_EINPROGRESS, 0x01, "Unknown" )
#define FC_TIMEOUT   ( 1 * TICKS_PER_SEC )
 Fibre Channel timeout.

Enumerations

enum  fc_exchange_flags { FC_XCHG_ORIGINATOR = 0x0001, FC_XCHG_SEQ_INITIATIVE = 0x0002, FC_XCHG_SEQ_FIRST = 0x0004 }
 Fibre Channel exchange flags. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 LIST_HEAD (fc_ports)
 List of Fibre Channel ports.
 LIST_HEAD (fc_peers)
 List of Fibre Channel peers.
const char * fc_id_ntoa (const struct fc_port_id *id)
 Format Fibre Channel port ID.
int fc_id_aton (const char *id_text, struct fc_port_id *id)
 Parse Fibre Channel port ID.
const char * fc_ntoa (const struct fc_name *wwn)
 Format Fibre Channel WWN.
int fc_aton (const char *wwn_text, struct fc_name *wwn)
 Parse Fibre Channel WWN.
struct sockaddrfc_fill_sockaddr (struct sockaddr_fc *sa_fc, struct fc_port_id *id)
 Fill Fibre Channel socket address.
static void fc_link_up (struct fc_link_state *link)
 Mark Fibre Channel link as up.
static void fc_link_err (struct fc_link_state *link, int rc)
 Mark Fibre Channel link as down.
static void fc_link_examine (struct fc_link_state *link)
 Examine Fibre Channel link state.
static void fc_link_expired (struct retry_timer *timer, int over __unused)
 Handle Fibre Channel link retry timer expiry.
static void fc_link_init (struct fc_link_state *link, void(*examine)(struct fc_link_state *link), struct refcnt *refcnt)
 Initialise Fibre Channel link state monitor.
static void fc_link_start (struct fc_link_state *link)
 Start monitoring Fibre Channel link state.
static void fc_link_stop (struct fc_link_state *link)
 Stop monitoring Fibre Channel link state.
static unsigned int fc_new_xchg_id (void)
 Create local Fibre Channel exchange identifier.
static unsigned int fc_new_seq_id (void)
 Create local Fibre Channel sequence identifier.
static void fc_xchg_free (struct refcnt *refcnt)
 Free Fibre Channel exchange.
static void fc_xchg_close (struct fc_exchange *xchg, int rc)
 Close Fibre Channel exchange.
static void fc_xchg_expired (struct retry_timer *timer, int over __unused)
 Handle exchange timeout.
static size_t fc_xchg_window (struct fc_exchange *xchg __unused)
 Check Fibre Channel exchange window.
static struct io_bufferfc_xchg_alloc_iob (struct fc_exchange *xchg, size_t len)
 Allocate Fibre Channel I/O buffer.
static int fc_xchg_tx (struct fc_exchange *xchg, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Transmit data as part of a Fibre Channel exchange.
static int fc_xchg_rx (struct fc_exchange *xchg, struct io_buffer *iobuf, struct xfer_metadata *meta __unused)
 Receive data as part of a Fibre Channel exchange.
static struct fc_exchangefc_xchg_create (struct fc_port *port, struct fc_port_id *peer_port_id, unsigned int type)
 Create new Fibre Channel exchange.
int fc_xchg_originate (struct interface *parent, struct fc_port *port, struct fc_port_id *peer_port_id, unsigned int type)
 Originate a new Fibre Channel exchange.
static struct fc_exchangefc_xchg_respond (struct fc_port *port, struct fc_frame_header *fchdr)
 Open a new responder Fibre Channel exchange.
static void fc_port_close (struct fc_port *port, int rc)
 Close Fibre Channel port.
static struct fc_exchangefc_port_demux (struct fc_port *port, unsigned int xchg_id)
 Identify Fibre Channel exchange by local exchange ID.
static int fc_port_deliver (struct fc_port *port, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Handle received frame from Fibre Channel port.
int fc_port_login (struct fc_port *port, struct fc_port_id *port_id, const struct fc_name *link_node_wwn, const struct fc_name *link_port_wwn, int has_fabric)
 Log in Fibre Channel port.
void fc_port_logout (struct fc_port *port, int rc)
 Log out Fibre Channel port.
static void fc_port_flogi_done (struct fc_port *port, int rc)
 Handle FLOGI completion.
static void fc_port_ns_plogi_done (struct fc_port *port, int rc)
 Handle name server PLOGI completion.
static void fc_port_examine (struct fc_link_state *link)
 Examine Fibre Channel port link state.
static void fc_port_window_changed (struct fc_port *port)
 Handle change of flow control window.
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.
struct fc_portfc_port_find (const char *name)
 Find Fibre Channel port by name.
static void fc_peer_close (struct fc_peer *peer, int rc)
 Close Fibre Channel peer.
static void fc_peer_increment (struct fc_peer *peer)
 Increment Fibre Channel peer active usage count.
static void fc_peer_decrement (struct fc_peer *peer)
 Decrement Fibre Channel peer active usage count.
int fc_peer_login (struct fc_peer *peer, struct fc_port *port, struct fc_port_id *port_id)
 Log in Fibre Channel peer.
void fc_peer_logout (struct fc_peer *peer, int rc)
 Log out Fibre Channel peer.
static void fc_peer_plogi_done (struct fc_peer *peer, int rc)
 Handle PLOGI completion.
static int fc_peer_plogi (struct fc_peer *peer, struct fc_port *port, struct fc_port_id *peer_port_id)
 Initiate PLOGI.
static void fc_peer_examine (struct fc_link_state *link)
 Examine Fibre Channel peer link state.
static struct fc_peerfc_peer_create (const struct fc_name *port_wwn)
 Create Fibre Channel peer.
struct fc_peerfc_peer_get_wwn (const struct fc_name *port_wwn)
 Get Fibre Channel peer by node name.
struct fc_peerfc_peer_get_port_id (struct fc_port *port, const struct fc_port_id *peer_port_id)
 Get Fibre Channel peer by port ID.
static void fc_ulp_free (struct refcnt *refcnt)
 Free Fibre Channel upper-layer protocol.
static void fc_ulp_close (struct fc_ulp *ulp, int rc)
 Close Fibre Channel upper-layer protocol.
void fc_ulp_attach (struct fc_ulp *ulp, struct fc_ulp_user *user)
 Attach Fibre Channel upper-layer protocol user.
void fc_ulp_detach (struct fc_ulp_user *user)
 Detach Fibre Channel upper-layer protocol user.
int fc_ulp_login (struct fc_ulp *ulp, const void *param, size_t param_len, int originated)
 Log in Fibre Channel upper-layer protocol.
void fc_ulp_logout (struct fc_ulp *ulp, int rc)
 Log out Fibre Channel upper-layer protocol.
static void fc_ulp_prli_done (struct fc_ulp *ulp, int rc)
 Handle PRLI completion.
static void fc_ulp_examine (struct fc_link_state *link)
 Examine Fibre Channel upper-layer protocol link state.
static struct fc_ulpfc_ulp_create (struct fc_peer *peer, unsigned int type)
 Create Fibre Channel upper-layer protocl.
static struct fc_ulpfc_ulp_get_type (struct fc_peer *peer, unsigned int type)
 Get Fibre Channel upper-layer protocol by peer and type.
struct fc_ulpfc_ulp_get_wwn_type (const struct fc_name *port_wwn, unsigned int type)
 Get Fibre Channel upper-layer protocol by port name and type.
struct fc_ulpfc_ulp_get_port_id_type (struct fc_port *port, const struct fc_port_id *peer_port_id, unsigned int type)
 Get Fibre Channel upper-layer protocol by port ID and type.
 REQUIRING_SYMBOL (fc_ports)
 REQUIRE_OBJECT (config_fc)

Variables

struct fc_port_id fc_empty_port_id = { .bytes = { 0x00, 0x00, 0x00 } }
 Unassigned port ID.
struct fc_port_id fc_f_port_id = { .bytes = { 0xff, 0xff, 0xfe } }
 F_Port contoller port ID.
struct fc_port_id fc_gs_port_id = { .bytes = { 0xff, 0xff, 0xfc } }
 Generic services port ID.
struct fc_port_id fc_ptp_low_port_id = { .bytes = { 0x01, 0x01, 0x01 } }
 Point-to-point low port ID.
struct fc_port_id fc_ptp_high_port_id = { .bytes = { 0x01, 0x01, 0x02 } }
 Point-to-point high port ID.
static const uint8_t fc_r_ctl_info_meta_flags [FC_R_CTL_INFO_MASK+1]
 Mapping from Fibre Channel routing control information to xfer metadata.
static struct interface_operation fc_xchg_ulp_op []
 Fibre Channel exchange ULP interface operations.
static struct interface_descriptor fc_xchg_ulp_desc
 Fibre Channel exchange ULP interface descriptor.
static struct interface_operation fc_port_transport_op []
 Fibre Channel port transport interface operations.
static struct interface_descriptor fc_port_transport_desc
 Fibre Channel port transport interface descriptor.
static struct interface_operation fc_port_flogi_op []
 Fibre Channel port FLOGI interface operations.
static struct interface_descriptor fc_port_flogi_desc
 Fibre Channel port FLOGI interface descriptor.
static struct interface_operation fc_port_ns_plogi_op []
 Fibre Channel port name server PLOGI interface operations.
static struct interface_descriptor fc_port_ns_plogi_desc
 Fibre Channel port name server PLOGI interface descriptor.
static struct interface_operation fc_peer_plogi_op []
 Fibre Channel peer PLOGI interface operations.
static struct interface_descriptor fc_peer_plogi_desc
 Fibre Channel peer PLOGI interface descriptor.
static struct interface_operation fc_ulp_prli_op []
 Fibre Channel upper-layer protocol PRLI interface operations.
static struct interface_descriptor fc_ulp_prli_desc
 Fibre Channel upper-layer protocol PRLI interface descriptor.

Detailed Description

Fibre Channel.

Definition in file fc.c.


Define Documentation

Default link status code.

Definition at line 186 of file fc.c.

Referenced by fc_link_err(), and fc_link_init().

Definition at line 187 of file fc.c.

#define FC_TIMEOUT   ( 1 * TICKS_PER_SEC )

Fibre Channel timeout.

Definition at line 328 of file fc.c.

Referenced by fc_xchg_rx(), and fc_xchg_tx().


Enumeration Type Documentation

Fibre Channel exchange flags.

Enumerator:
FC_XCHG_ORIGINATOR 

We are the exchange originator.

FC_XCHG_SEQ_INITIATIVE 

We have the sequence initiative.

FC_XCHG_SEQ_FIRST 

This is the first sequence of the exchange.

Definition at line 318 of file fc.c.

                       {
        /** We are the exchange originator */
        FC_XCHG_ORIGINATOR = 0x0001,
        /** We have the sequence initiative */
        FC_XCHG_SEQ_INITIATIVE = 0x0002,
        /** This is the first sequence of the exchange */
        FC_XCHG_SEQ_FIRST = 0x0004,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

List of Fibre Channel ports.

List of Fibre Channel peers.

const char* fc_id_ntoa ( const struct fc_port_id id)

Format Fibre Channel port ID.

Parameters:
idFibre Channel port ID
Return values:
id_textPort ID text

Definition at line 92 of file fc.c.

References fc_port_id::bytes, FC_PORT_ID_STRLEN, and snprintf().

Referenced by fc_els_flogi_rx(), fc_els_logo_rx_request(), fc_els_plogi_rx(), fc_ns_query_deliver(), fc_peer_login(), fc_port_deliver(), fc_port_login(), fc_xchg_originate(), fc_xchg_respond(), fcels(), fcpeerstat(), and fcportstat().

                                                        {
        static char id_text[ FC_PORT_ID_STRLEN + 1 /* NUL */ ];

        snprintf ( id_text, sizeof ( id_text ), "%02x.%02x.%02x",
                   id->bytes[0], id->bytes[1], id->bytes[2] );
        return id_text;
}
int fc_id_aton ( const char *  id_text,
struct fc_port_id id 
)

Parse Fibre Channel port ID.

Parameters:
id_textPort ID text
Return values:
idFibre Channel port ID
rcReturn status code

Definition at line 107 of file fc.c.

References fc_port_id::bytes, EINVAL, and strtoul().

Referenced by parse_fc_port_id().

                                                              {
        char *ptr = ( ( char * ) id_text );
        unsigned int i = 0;

        while ( 1 ) {
                id->bytes[i++] = strtoul ( ptr, &ptr, 16 );
                if ( i == sizeof ( id->bytes ) )
                        return ( ( *ptr == '\0' ) ? 0 : -EINVAL );
                if ( *ptr != '.' )
                        return -EINVAL;
                ptr++;
        }
}
const char* fc_ntoa ( const struct fc_name wwn)

Format Fibre Channel WWN.

Parameters:
wwnFibre Channel WWN
Return values:
wwn_textWWN text

Definition at line 127 of file fc.c.

References fc_name::bytes, FC_NAME_STRLEN, and snprintf().

Referenced by fc_els_flogi_rx(), fc_els_logo_rx_request(), fc_els_plogi_rx(), fc_ns_query(), fc_ns_query_deliver(), fc_peer_close(), fc_peer_create(), fc_peer_examine(), fc_peer_login(), fc_peer_logout(), fc_peer_plogi(), fc_port_login(), fc_port_open(), fc_ulp_close(), fc_ulp_create(), fc_ulp_examine(), fc_ulp_login(), fc_ulp_logout(), fcoe_probe(), fcpdev_open(), fcpeerstat(), and fcportstat().

                                                   {
        static char wwn_text[ FC_NAME_STRLEN + 1 /* NUL */ ];

        snprintf ( wwn_text, sizeof ( wwn_text ),
                   "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
                   wwn->bytes[0], wwn->bytes[1], wwn->bytes[2], wwn->bytes[3],
                   wwn->bytes[4], wwn->bytes[5], wwn->bytes[6], wwn->bytes[7] );
        return wwn_text;
}
int fc_aton ( const char *  wwn_text,
struct fc_name wwn 
)

Parse Fibre Channel WWN.

Parameters:
wwn_textWWN text
Return values:
wwnFibre Channel WWN
rcReturn status code

Definition at line 144 of file fc.c.

References fc_name::bytes, EINVAL, and strtoul().

Referenced by fcp_parse_uri().

                                                          {
        char *ptr = ( ( char * ) wwn_text );
        unsigned int i = 0;

        while ( 1 ) {
                wwn->bytes[i++] = strtoul ( ptr, &ptr, 16 );
                if ( i == sizeof ( wwn->bytes ) )
                        return ( ( *ptr == '\0' ) ? 0 : -EINVAL );
                if ( *ptr != ':' )
                        return -EINVAL;
                ptr++;
        }
}
struct sockaddr* fc_fill_sockaddr ( struct sockaddr_fc sa_fc,
struct fc_port_id id 
) [read]

Fill Fibre Channel socket address.

Parameters:
sa_fcFibre Channel socket address to fill in
idFibre Channel port ID
Return values:
saSocket address

Definition at line 165 of file fc.c.

References AF_FC, container_of, fc, memcpy(), memset(), sockaddr_fc::sfc_family, sockaddr_fc::sfc_port_id, and u.

Referenced by fc_els_tx(), and fc_xchg_rx().

                                                             {
        union {
                struct sockaddr sa;
                struct sockaddr_fc fc;
        } *u = container_of ( sa_fc, typeof ( *u ), fc );

        memset ( sa_fc, 0, sizeof ( *sa_fc ) );
        sa_fc->sfc_family = AF_FC;
        memcpy ( &sa_fc->sfc_port_id, id, sizeof ( sa_fc->sfc_port_id ) );
        return &u->sa;
}
static void fc_link_up ( struct fc_link_state link) [static]

Mark Fibre Channel link as up.

Parameters:
linkFibre Channel link state monitor

Definition at line 195 of file fc.c.

References fc_link_state::rc, stop_timer(), and fc_link_state::timer.

Referenced by fc_peer_login(), fc_port_login(), and fc_ulp_login().

                                                      {

        /* Stop retry timer */
        stop_timer ( &link->timer );

        /* Record link state */
        link->rc = 0;
}
static void fc_link_err ( struct fc_link_state link,
int  rc 
) [static]

Mark Fibre Channel link as down.

Parameters:
linkFibre Channel link state monitor
rcLink state

Definition at line 210 of file fc.c.

References EUNKNOWN_LINK_STATUS, FC_LINK_RETRY_DELAY, fc_link_state::rc, rc, start_timer_fixed(), and fc_link_state::timer.

Referenced by fc_peer_logout(), fc_port_logout(), and fc_ulp_logout().

                                                               {

        /* Record link state */
        if ( rc == 0 )
                rc = -EUNKNOWN_LINK_STATUS;
        link->rc = rc;

        /* Schedule another link examination */
        start_timer_fixed ( &link->timer, FC_LINK_RETRY_DELAY );
}
static void fc_link_examine ( struct fc_link_state link) [static]

Examine Fibre Channel link state.

Parameters:
linkFibre Channel link state monitor

Definition at line 226 of file fc.c.

References fc_link_state::examine.

Referenced by fc_link_expired(), fc_peer_login(), fc_peer_logout(), fc_port_login(), and fc_port_logout().

                                                           {

        link->examine ( link );
}
static void fc_link_expired ( struct retry_timer timer,
int over  __unused 
) [static]

Handle Fibre Channel link retry timer expiry.

Definition at line 234 of file fc.c.

References container_of, fc_link_examine(), FC_LINK_RETRY_DELAY, link, start_timer_fixed(), and fc_link_state::timer.

Referenced by fc_link_init().

                                                                             {
        struct fc_link_state *link =
                container_of ( timer, struct fc_link_state, timer );

        /* Schedule another link examination */
        start_timer_fixed ( &link->timer, FC_LINK_RETRY_DELAY );

        /* Examine link */
        fc_link_examine ( link );
}
static void fc_link_init ( struct fc_link_state link,
void(*)(struct fc_link_state *link examine,
struct refcnt refcnt 
) [static]

Initialise Fibre Channel link state monitor.

Parameters:
linkFibre Channel link state monitor
examineExamine link state method
refcntReference counter

Definition at line 252 of file fc.c.

References EUNKNOWN_LINK_STATUS, fc_link_state::examine, fc_link_expired(), fc_link_state::rc, and fc_link_state::timer.

Referenced by fc_peer_create(), fc_port_open(), and fc_ulp_create().

                                                   {

        link->rc = -EUNKNOWN_LINK_STATUS;
        timer_init ( &link->timer, fc_link_expired, refcnt );
        link->examine = examine;
}
static void fc_link_start ( struct fc_link_state link) [static]

Start monitoring Fibre Channel link state.

Parameters:
linkFibre Channel link state monitor

Definition at line 266 of file fc.c.

References start_timer_nodelay(), and fc_link_state::timer.

Referenced by fc_peer_create(), fc_port_window_changed(), fc_ulp_create(), and fc_ulp_login().

                                                         {
        start_timer_nodelay ( &link->timer );
}
static void fc_link_stop ( struct fc_link_state link) [static]

Stop monitoring Fibre Channel link state.

Parameters:
linkFibre Channel link state monitor

Definition at line 275 of file fc.c.

References stop_timer(), and fc_link_state::timer.

Referenced by fc_peer_close(), fc_port_close(), fc_port_window_changed(), fc_ulp_close(), and fc_ulp_login().

                                                        {
        stop_timer ( &link->timer );
}
static unsigned int fc_new_xchg_id ( void  ) [static]

Create local Fibre Channel exchange identifier.

Return values:
xchg_idLocal exchange ID

Definition at line 335 of file fc.c.

Referenced by fc_xchg_create().

                                            {
        static uint16_t next_id = 0x0000;

        /* We must avoid using FC_RX_ID_UNKNOWN (0xffff) */
        next_id += 2;
        return next_id;
}
static unsigned int fc_new_seq_id ( void  ) [static]

Create local Fibre Channel sequence identifier.

Return values:
seq_idLocal sequence identifier

Definition at line 348 of file fc.c.

Referenced by fc_xchg_create(), and fc_xchg_rx().

                                           {
        static uint8_t seq_id = 0x00;

        return (++seq_id);
}
static void fc_xchg_free ( struct refcnt refcnt) [static]

Free Fibre Channel exchange.

Parameters:
refcntReference count

Definition at line 359 of file fc.c.

References assert, container_of, fc_port_put(), free, fc_exchange::list, list_empty, fc_exchange::port, and fc_exchange::timer.

Referenced by fc_xchg_create().

                                                   {
        struct fc_exchange *xchg =
                container_of ( refcnt, struct fc_exchange, refcnt );

        assert ( ! timer_running ( &xchg->timer ) );
        assert ( list_empty ( &xchg->list ) );

        fc_port_put ( xchg->port );
        free ( xchg );
}
static void fc_xchg_close ( struct fc_exchange xchg,
int  rc 
) [static]

Close Fibre Channel exchange.

Parameters:
xchgFibre Channel exchange
rcReason for close

Definition at line 376 of file fc.c.

References DBGC2, INIT_LIST_HEAD, intf_shutdown(), fc_exchange::list, list_del, list_empty, fc_port::name, fc_exchange::port, port, ref_put, fc_exchange::refcnt, stop_timer(), strerror(), fc_exchange::timer, fc_exchange::ulp, and fc_exchange::xchg_id.

Referenced by fc_port_close(), fc_xchg_expired(), and fc_xchg_rx().

                                                               {
        struct fc_port *port = xchg->port;

        if ( rc != 0 ) {
                DBGC2 ( port, "FCXCHG %s/%04x closed: %s\n",
                        port->name, xchg->xchg_id, strerror ( rc ) );
        }

        /* Stop timer */
        stop_timer ( &xchg->timer );

        /* If list still holds a reference, remove from list of open
         * exchanges and drop list's reference.
         */
        if ( ! list_empty ( &xchg->list ) ) {
                list_del ( &xchg->list );
                INIT_LIST_HEAD ( &xchg->list );
                ref_put ( &xchg->refcnt );
        }

        /* Shutdown interfaces */
        intf_shutdown ( &xchg->ulp, rc );
}
static void fc_xchg_expired ( struct retry_timer timer,
int over  __unused 
) [static]

Handle exchange timeout.

Parameters:
timerTimeout timer
overFailure indicator

Definition at line 406 of file fc.c.

References container_of, DBGC, ETIMEDOUT, fc_xchg_close(), fc_port::name, fc_exchange::port, port, and fc_exchange::xchg_id.

Referenced by fc_xchg_create().

                                                                             {
        struct fc_exchange *xchg =
                container_of ( timer, struct fc_exchange, timer );
        struct fc_port *port = xchg->port;

        DBGC ( port, "FCXCHG %s/%04x timed out\n", port->name, xchg->xchg_id );

        /* Terminate the exchange */
        fc_xchg_close ( xchg, -ETIMEDOUT );
}
static size_t fc_xchg_window ( struct fc_exchange *xchg  __unused) [static]

Check Fibre Channel exchange window.

Parameters:
xchgFibre Channel exchange
Return values:
lenLength opf window

Definition at line 423 of file fc.c.

References FC_LOGIN_DEFAULT_MTU.

                                                                   {

        /* We don't currently store the path MTU */
        return FC_LOGIN_DEFAULT_MTU;
}
static struct io_buffer* fc_xchg_alloc_iob ( struct fc_exchange xchg,
size_t  len 
) [static, read]

Allocate Fibre Channel I/O buffer.

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

Definition at line 436 of file fc.c.

References iob_reserve, fc_exchange::port, port, fc_port::transport, and xfer_alloc_iob().

                                                           {
        struct fc_port *port = xchg->port;
        struct io_buffer *iobuf;

        iobuf = xfer_alloc_iob ( &port->transport,
                                 ( sizeof ( struct fc_frame_header ) + len ) );
        if ( iobuf ) {
                iob_reserve ( iobuf, sizeof ( struct fc_frame_header ) );
        }
        return iobuf;
}
static int fc_xchg_tx ( struct fc_exchange xchg,
struct io_buffer iobuf,
struct xfer_metadata meta 
) [static]

Transmit data as part of a Fibre Channel exchange.

Parameters:
xchgFibre Channel exchange
iobufI/O buffer
metaData transfer metadata
Return values:
rcReturn status code

Definition at line 457 of file fc.c.

References fc_frame_header::d_id, DBGC, xfer_metadata::dest, dest, done, EBUSY, fc_frame_header::f_ctl_es, fc_frame_header::f_ctl_misc, FC_F_CTL_ES_END, FC_F_CTL_ES_FIRST, FC_F_CTL_ES_LAST, FC_F_CTL_ES_RESPONDER, FC_F_CTL_ES_TRANSFER, FC_F_CTL_MISC_REL_OFF, FC_R_CTL_CMD_STAT, FC_R_CTL_DATA, FC_R_CTL_ELS, FC_R_CTL_SOL_CTRL, FC_R_CTL_SOL_DATA, FC_R_CTL_UNSOL_CMD, FC_R_CTL_UNSOL_CTRL, FC_R_CTL_UNSOL_DATA, FC_TIMEOUT, FC_TYPE_CT, FC_TYPE_ELS, FC_XCHG_ORIGINATOR, FC_XCHG_SEQ_FIRST, FC_XCHG_SEQ_INITIATIVE, xfer_metadata::flags, fc_exchange::flags, free_iob(), htonl, htons, iob_disown, iob_push, memcpy(), memset(), fc_port::name, xfer_metadata::offset, fc_frame_header::ox_id, fc_frame_header::parameter, fc_exchange::peer_port_id, fc_exchange::peer_xchg_id, fc_exchange::port, port, fc_port::port_id, fc_frame_header::r_ctl, rc, fc_frame_header::rx_id, fc_frame_header::s_id, fc_frame_header::seq_cnt, fc_exchange::seq_cnt, fc_frame_header::seq_id, fc_exchange::seq_id, sockaddr_fc::sfc_port_id, start_timer_fixed(), strerror(), fc_exchange::timer, fc_port::transport, fc_frame_header::type, fc_exchange::type, fc_exchange::xchg_id, xfer_deliver_iob(), XFER_FL_ABS_OFFSET, XFER_FL_CMD_STAT, XFER_FL_OUT, XFER_FL_OVER, and XFER_FL_RESPONSE.

                                                     {
        struct fc_port *port = xchg->port;
        struct sockaddr_fc *dest = ( ( struct sockaddr_fc * ) meta->dest );
        struct fc_frame_header *fchdr;
        unsigned int r_ctl;
        unsigned int f_ctl_es;
        int rc;

        /* Sanity checks */
        if ( ! ( xchg->flags & FC_XCHG_SEQ_INITIATIVE ) ) {
                DBGC ( port, "FCXCHG %s/%04x cannot transmit while not "
                       "holding sequence initiative\n",
                       port->name, xchg->xchg_id );
                rc = -EBUSY;
                goto done;
        }

        /* Calculate routing control */
        switch ( xchg->type ) {
        case FC_TYPE_ELS:
                r_ctl = FC_R_CTL_ELS;
                if ( meta->flags & XFER_FL_RESPONSE ) {
                        r_ctl |= FC_R_CTL_SOL_CTRL;
                } else {
                        r_ctl |= FC_R_CTL_UNSOL_CTRL;
                }
                break;
        case FC_TYPE_CT:
                r_ctl = FC_R_CTL_DATA;
                if ( meta->flags & XFER_FL_RESPONSE ) {
                        r_ctl |= FC_R_CTL_SOL_CTRL;
                } else {
                        r_ctl |= FC_R_CTL_UNSOL_CTRL;
                }
                break;
        default:
                r_ctl = FC_R_CTL_DATA;
                switch ( meta->flags &
                         ( XFER_FL_CMD_STAT | XFER_FL_RESPONSE ) ) {
                case ( XFER_FL_CMD_STAT | XFER_FL_RESPONSE ):
                        r_ctl |= FC_R_CTL_CMD_STAT;
                        break;
                case ( XFER_FL_CMD_STAT ):
                        r_ctl |= FC_R_CTL_UNSOL_CMD;
                        break;
                case ( XFER_FL_RESPONSE ):
                        r_ctl |= FC_R_CTL_SOL_DATA;
                        break;
                default:
                        r_ctl |= FC_R_CTL_UNSOL_DATA;
                        break;
                }
                break;
        }

        /* Calculate exchange and sequence control */
        f_ctl_es = 0;
        if ( ! ( xchg->flags & FC_XCHG_ORIGINATOR ) )
                f_ctl_es |= FC_F_CTL_ES_RESPONDER;
        if ( xchg->flags & FC_XCHG_SEQ_FIRST )
                f_ctl_es |= FC_F_CTL_ES_FIRST;
        if ( meta->flags & XFER_FL_OUT )
                f_ctl_es |= ( FC_F_CTL_ES_END | FC_F_CTL_ES_LAST );
        if ( meta->flags & XFER_FL_OVER )
                f_ctl_es |= ( FC_F_CTL_ES_END | FC_F_CTL_ES_TRANSFER );

        /* Create frame header */
        fchdr = iob_push ( iobuf, sizeof ( *fchdr ) );
        memset ( fchdr, 0, sizeof ( *fchdr ) );
        fchdr->r_ctl = r_ctl;
        memcpy ( &fchdr->d_id,
                 ( dest ? &dest->sfc_port_id : &xchg->peer_port_id ),
                 sizeof ( fchdr->d_id ) );
        memcpy ( &fchdr->s_id, &port->port_id, sizeof ( fchdr->s_id ) );
        fchdr->type = xchg->type;
        fchdr->f_ctl_es = f_ctl_es;
        fchdr->seq_id = xchg->seq_id;
        fchdr->seq_cnt = htons ( xchg->seq_cnt++ );
        fchdr->ox_id = htons ( ( xchg->flags & FC_XCHG_ORIGINATOR ) ?
                               xchg->xchg_id : xchg->peer_xchg_id );
        fchdr->rx_id = htons ( ( xchg->flags & FC_XCHG_ORIGINATOR ) ?
                               xchg->peer_xchg_id : xchg->xchg_id );
        if ( meta->flags & XFER_FL_ABS_OFFSET ) {
                fchdr->f_ctl_misc |= FC_F_CTL_MISC_REL_OFF;
                fchdr->parameter = htonl ( meta->offset );
        }

        /* Relinquish sequence initiative if applicable */
        if ( meta->flags & XFER_FL_OVER ) {
                xchg->flags &= ~( FC_XCHG_SEQ_INITIATIVE | FC_XCHG_SEQ_FIRST );
                xchg->seq_cnt = 0;
        }

        /* Reset timeout */
        start_timer_fixed ( &xchg->timer, FC_TIMEOUT );

        /* Deliver frame */
        if ( ( rc = xfer_deliver_iob ( &port->transport,
                                       iob_disown ( iobuf ) ) ) != 0 ) {
                DBGC ( port, "FCXCHG %s/%04x cannot transmit: %s\n",
                       port->name, xchg->xchg_id, strerror ( rc ) );
                goto done;
        }

 done:
        free_iob ( iobuf );
        return rc;
}
static int fc_xchg_rx ( struct fc_exchange xchg,
struct io_buffer iobuf,
struct xfer_metadata *meta  __unused 
) [static]

Receive data as part of a Fibre Channel exchange.

Parameters:
xchgFibre Channel exchange
iobufI/O buffer
metaData transfer metadata
Return values:
rcReturn status code

Definition at line 587 of file fc.c.

References fc_frame_header::d_id, io_buffer::data, DBGC, xfer_metadata::dest, done, EBUSY, EPIPE, fc_frame_header::f_ctl_es, fc_frame_header::f_ctl_misc, FC_F_CTL_ES_END, FC_F_CTL_ES_LAST, FC_F_CTL_ES_RESPONDER, FC_F_CTL_ES_TRANSFER, FC_F_CTL_MISC_REL_OFF, fc_fill_sockaddr(), fc_new_seq_id(), FC_R_CTL_INFO_MASK, FC_TIMEOUT, fc_xchg_close(), FC_XCHG_SEQ_INITIATIVE, xfer_metadata::flags, fc_exchange::flags, free_iob(), iob_disown, iob_pull, memset(), fc_port::name, ntohl, ntohs, xfer_metadata::offset, fc_frame_header::ox_id, fc_frame_header::parameter, fc_exchange::peer_xchg_id, fc_exchange::port, port, fc_frame_header::r_ctl, rc, fc_frame_header::rx_id, fc_frame_header::s_id, fc_frame_header::seq_cnt, fc_exchange::seq_cnt, fc_frame_header::seq_id, fc_exchange::seq_id, xfer_metadata::src, start_timer_fixed(), strerror(), fc_exchange::timer, fc_exchange::ulp, fc_exchange::xchg_id, xfer_deliver(), XFER_FL_ABS_OFFSET, XFER_FL_OUT, and XFER_FL_OVER.

Referenced by fc_port_deliver().

                                                              {
        struct fc_port *port = xchg->port;
        struct fc_frame_header *fchdr = iobuf->data;
        struct xfer_metadata fc_meta;
        struct sockaddr_fc src;
        struct sockaddr_fc dest;
        int rc;

        /* Record peer exchange ID */
        xchg->peer_xchg_id =
                ntohs ( ( fchdr->f_ctl_es & FC_F_CTL_ES_RESPONDER ) ?
                        fchdr->rx_id : fchdr->ox_id );

        /* Sequence checks */
        if ( xchg->flags & FC_XCHG_SEQ_INITIATIVE ) {
                DBGC ( port, "FCXCHG %s/%04x received frame while holding "
                       "sequence initiative\n", port->name, xchg->xchg_id );
                rc = -EBUSY;
                goto done;
        }
        if ( ntohs ( fchdr->seq_cnt ) != xchg->seq_cnt ) {
                DBGC ( port, "FCXCHG %s/%04x received out-of-order frame %d "
                       "(expected %d)\n", port->name, xchg->xchg_id,
                       ntohs ( fchdr->seq_cnt ), xchg->seq_cnt );
                rc = -EPIPE;
                goto done;
        }
        if ( xchg->seq_cnt == 0 )
                xchg->seq_id = fchdr->seq_id;
        xchg->seq_cnt++;
        if ( fchdr->seq_id != xchg->seq_id ) {
                DBGC ( port, "FCXCHG %s/%04x received frame for incorrect "
                       "sequence %02x (expected %02x)\n", port->name,
                       xchg->xchg_id, fchdr->seq_id, xchg->seq_id );
                rc = -EPIPE;
                goto done;
        }

        /* Check for end of sequence and transfer of sequence initiative */
        if ( fchdr->f_ctl_es & FC_F_CTL_ES_END ) {
                xchg->seq_cnt = 0;
                if ( fchdr->f_ctl_es & FC_F_CTL_ES_TRANSFER ) {
                        xchg->flags |= FC_XCHG_SEQ_INITIATIVE;
                        xchg->seq_id = fc_new_seq_id();
                }
        }

        /* Construct metadata */
        memset ( &fc_meta, 0, sizeof ( fc_meta ) );
        fc_meta.flags =
                fc_r_ctl_info_meta_flags[ fchdr->r_ctl & FC_R_CTL_INFO_MASK ];
        if ( fchdr->f_ctl_es & FC_F_CTL_ES_TRANSFER ) {
                fc_meta.flags |= XFER_FL_OVER;
        }
        if ( ( fchdr->f_ctl_es & FC_F_CTL_ES_LAST ) &&
             ( fchdr->f_ctl_es & FC_F_CTL_ES_END ) ) {
                fc_meta.flags |= XFER_FL_OUT;
        }
        if ( fchdr->f_ctl_misc & FC_F_CTL_MISC_REL_OFF ) {
                fc_meta.flags |= XFER_FL_ABS_OFFSET;
                fc_meta.offset = ntohl ( fchdr->parameter );
        }
        fc_meta.src = fc_fill_sockaddr ( &src, &fchdr->s_id );
        fc_meta.dest = fc_fill_sockaddr ( &dest, &fchdr->d_id );

        /* Reset timeout */
        start_timer_fixed ( &xchg->timer, FC_TIMEOUT );

        /* Deliver via exchange's ULP interface */
        iob_pull ( iobuf, sizeof ( *fchdr ) );
        if ( ( rc = xfer_deliver ( &xchg->ulp, iob_disown ( iobuf ),
                                   &fc_meta ) ) != 0 ) {
                DBGC ( port, "FCXCHG %s/%04x cannot deliver frame: %s\n",
                       port->name, xchg->xchg_id, strerror ( rc ) );
                goto done;
        }

        /* Close exchange if applicable */
        if ( ( fchdr->f_ctl_es & FC_F_CTL_ES_LAST ) &&
             ( fchdr->f_ctl_es & FC_F_CTL_ES_END ) ) {
                fc_xchg_close ( xchg, 0 );
        }

 done:
        free_iob ( iobuf );
        return rc;
}
static struct fc_exchange* fc_xchg_create ( struct fc_port port,
struct fc_port_id peer_port_id,
unsigned int  type 
) [static, read]

Create new Fibre Channel exchange.

Parameters:
portFibre Channel port
peer_port_idPeer port ID
Return values:
xchgExchange, or NULL

Definition at line 695 of file fc.c.

References fc_new_seq_id(), fc_new_xchg_id(), fc_port_get(), FC_RX_ID_UNKNOWN, fc_xchg_expired(), fc_xchg_free(), intf_init(), fc_exchange::list, list_add, memcpy(), NULL, fc_exchange::peer_port_id, fc_exchange::peer_xchg_id, fc_exchange::port, ref_init, fc_exchange::refcnt, fc_exchange::seq_id, fc_exchange::timer, fc_exchange::type, type, fc_exchange::ulp, fc_exchange::xchg_id, fc_port::xchgs, and zalloc().

Referenced by fc_xchg_originate(), and fc_xchg_respond().

                                                                 {
        struct fc_exchange *xchg;

        /* Allocate and initialise structure */
        xchg = zalloc ( sizeof ( *xchg ) );
        if ( ! xchg )
                return NULL;
        ref_init ( &xchg->refcnt, fc_xchg_free );
        intf_init ( &xchg->ulp, &fc_xchg_ulp_desc, &xchg->refcnt );
        timer_init ( &xchg->timer, fc_xchg_expired, &xchg->refcnt );
        xchg->port = fc_port_get ( port );
        memcpy ( &xchg->peer_port_id, peer_port_id,
                 sizeof ( xchg->peer_port_id ) );
        xchg->type = type;
        xchg->xchg_id = fc_new_xchg_id();
        xchg->peer_xchg_id = FC_RX_ID_UNKNOWN;
        xchg->seq_id = fc_new_seq_id();

        /* Transfer reference to list of exchanges and return */
        list_add ( &xchg->list, &port->xchgs );
        return xchg;
}
int fc_xchg_originate ( struct interface parent,
struct fc_port port,
struct fc_port_id peer_port_id,
unsigned int  type 
)

Originate a new Fibre Channel exchange.

Parameters:
parentInterface to which to attach
portFibre Channel port
peer_port_idPeer port ID
Return values:
xchg_idExchange ID, or negative error

Definition at line 728 of file fc.c.

References DBGC2, ENOMEM, fc_id_ntoa(), fc_xchg_create(), FC_XCHG_ORIGINATOR, FC_XCHG_SEQ_FIRST, FC_XCHG_SEQ_INITIATIVE, fc_exchange::flags, intf_plug_plug(), fc_port::name, fc_exchange::peer_port_id, fc_exchange::type, fc_exchange::ulp, and fc_exchange::xchg_id.

Referenced by fc_els_step(), fc_ns_query_step(), and fcpdev_scsi_command().

                                                                             {
        struct fc_exchange *xchg;

        /* Allocate and initialise structure */
        xchg = fc_xchg_create ( port, peer_port_id, type );
        if ( ! xchg )
                return -ENOMEM;
        xchg->flags = ( FC_XCHG_ORIGINATOR | FC_XCHG_SEQ_INITIATIVE |
                        FC_XCHG_SEQ_FIRST );

        DBGC2 ( port, "FCXCHG %s/%04x originating to %s (type %02x)\n",
                port->name, xchg->xchg_id, fc_id_ntoa ( &xchg->peer_port_id ),
                xchg->type );

        /* Attach to parent interface and return */
        intf_plug_plug ( &xchg->ulp, parent );
        return xchg->xchg_id;
}
static struct fc_exchange* fc_xchg_respond ( struct fc_port port,
struct fc_frame_header fchdr 
) [static, read]

Open a new responder Fibre Channel exchange.

Parameters:
portFibre Channel port
fchdrFibre Channel frame header
Return values:
xchgFibre Channel exchange, or NULL

Definition at line 755 of file fc.c.

References fc_frame_header::d_id, DBGC, DBGC2, fc_id_ntoa(), FC_RESPONDERS, fc_xchg_create(), for_each_table_entry, fc_port::name, ntohs, NULL, fc_frame_header::ox_id, fc_exchange::peer_port_id, rc, fc_responder::respond, fc_frame_header::s_id, fc_frame_header::seq_id, fc_exchange::seq_id, strerror(), fc_frame_header::type, fc_responder::type, fc_exchange::type, type, fc_exchange::ulp, and fc_exchange::xchg_id.

Referenced by fc_port_deliver().

                                                                              {
        struct fc_exchange *xchg;
        struct fc_responder *responder;
        unsigned int type = fchdr->type;
        int rc;

        /* Allocate and initialise structure */
        xchg = fc_xchg_create ( port, &fchdr->s_id, type );
        if ( ! xchg )
                return NULL;
        xchg->seq_id = fchdr->seq_id;

        DBGC2 ( port, "FCXCHG %s/%04x responding to %s xchg %04x (type "
                "%02x)\n", port->name, xchg->xchg_id,
                fc_id_ntoa ( &xchg->peer_port_id ),
                ntohs ( fchdr->ox_id ), xchg->type );

        /* Find a responder, if any */
        for_each_table_entry ( responder, FC_RESPONDERS ) {
                if ( responder->type == type ) {
                        if ( ( rc = responder->respond ( &xchg->ulp, port,
                                                         &fchdr->d_id,
                                                         &fchdr->s_id ) ) !=0 ){
                                DBGC ( port, "FCXCHG %s/%04x could not "
                                       "respond: %s\n", port->name,
                                       xchg->xchg_id, strerror ( rc ) );
                        }
                }
                break;
        }

        /* We may or may not have a ULP attached at this point, but
         * the exchange does exist.
         */
        return xchg;
}
static void fc_port_close ( struct fc_port port,
int  rc 
) [static]

Close Fibre Channel port.

Parameters:
portFibre Channel port
rcReason for close

Definition at line 806 of file fc.c.

References DBGC, fc_link_ok(), fc_link_stop(), fc_port_logout(), fc_xchg_close(), fc_port::flogi, INIT_LIST_HEAD, intf_shutdown(), fc_port::link, fc_port::list, fc_exchange::list, list_del, list_for_each_entry_safe, fc_port::name, fc_port::ns_plogi, fc_port::transport, and fc_port::xchgs.

                                                           {
        struct fc_exchange *xchg;
        struct fc_exchange *tmp;

        DBGC ( port, "FCPORT %s closed\n", port->name );

        /* Log out port, if necessary */
        if ( fc_link_ok ( &port->link ) )
                fc_port_logout ( port, rc );

        /* Stop link monitor */
        fc_link_stop ( &port->link );

        /* Shut down interfaces */
        intf_shutdown ( &port->transport, rc );
        intf_shutdown ( &port->flogi, rc );
        intf_shutdown ( &port->ns_plogi, rc );

        /* Shut down any remaining exchanges */
        list_for_each_entry_safe ( xchg, tmp, &port->xchgs, list )
                fc_xchg_close ( xchg, rc );

        /* Remove from list of ports */
        list_del ( &port->list );
        INIT_LIST_HEAD ( &port->list );
}
static struct fc_exchange* fc_port_demux ( struct fc_port port,
unsigned int  xchg_id 
) [static, read]

Identify Fibre Channel exchange by local exchange ID.

Parameters:
portFibre Channel port
xchg_idLocal exchange ID
Return values:
xchgFibre Channel exchange, or NULL

Definition at line 840 of file fc.c.

References fc_exchange::list, list_for_each_entry, NULL, fc_exchange::xchg_id, and fc_port::xchgs.

Referenced by fc_port_deliver().

                                                                   {
        struct fc_exchange *xchg;

        list_for_each_entry ( xchg, &port->xchgs, list ) {
                if ( xchg->xchg_id == xchg_id )
                        return xchg;
        }
        return NULL;
}
static int fc_port_deliver ( struct fc_port port,
struct io_buffer iobuf,
struct xfer_metadata meta 
) [static]

Handle received frame from Fibre Channel port.

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

Definition at line 859 of file fc.c.

References fc_frame_header::d_id, io_buffer::data, DBGC, EINVAL, ENOMEM, ENOTCONN, fc_frame_header::f_ctl_es, FC_F_CTL_ES_FIRST, FC_F_CTL_ES_RESPONDER, fc_id_ntoa(), fc_port_demux(), fc_xchg_respond(), fc_xchg_rx(), free_iob(), iob_disown, iob_len(), memcmp(), fc_port::name, ntohs, fc_frame_header::ox_id, fc_port::port_id, rc, ref_get, ref_put, fc_exchange::refcnt, fc_frame_header::rx_id, and fc_frame_header::seq_cnt.

                                                          {
        struct fc_frame_header *fchdr = iobuf->data;
        unsigned int xchg_id;
        struct fc_exchange *xchg;
        int rc;

        /* Sanity check */
        if ( iob_len ( iobuf ) < sizeof ( *fchdr ) ) {
                DBGC ( port, "FCPORT %s received underlength frame (%zd "
                       "bytes)\n", port->name, iob_len ( iobuf ) );
                rc = -EINVAL;
                goto err_sanity;
        }

        /* Verify local port ID */
        if ( ( memcmp ( &fchdr->d_id, &port->port_id,
                        sizeof ( fchdr->d_id ) ) != 0 ) &&
             ( memcmp ( &fchdr->d_id, &fc_f_port_id,
                        sizeof ( fchdr->d_id ) ) != 0 ) &&
             ( memcmp ( &port->port_id, &fc_empty_port_id,
                        sizeof ( port->port_id ) ) != 0 ) ) {
                DBGC ( port, "FCPORT %s received frame for incorrect port ID "
                       "%s\n", port->name, fc_id_ntoa ( &fchdr->d_id ) );
                rc = -ENOTCONN;
                goto err_port_id;
        }

        /* Demultiplex amongst active exchanges */
        xchg_id = ntohs ( ( fchdr->f_ctl_es & FC_F_CTL_ES_RESPONDER ) ?
                          fchdr->ox_id : fchdr->rx_id );
        xchg = fc_port_demux ( port, xchg_id );

        /* If we have no active exchange and this frame starts a new
         * exchange, try to create a new responder exchange
         */
        if ( ( fchdr->f_ctl_es & FC_F_CTL_ES_FIRST ) &&
             ( fchdr->seq_cnt == 0 ) ) {

                /* Create new exchange */
                xchg = fc_xchg_respond ( port, fchdr );
                if ( ! xchg ) {
                        DBGC ( port, "FCPORT %s cannot create new exchange\n",
                               port->name );
                        rc = -ENOMEM;
                        goto err_respond;
                }
        }

        /* Fail if no exchange exists */
        if ( ! xchg ) {
                DBGC ( port, "FCPORT %s xchg %04x unknown\n",
                       port->name, xchg_id );
                rc = -ENOTCONN;
                goto err_no_xchg;
        }

        /* Pass received frame to exchange */
        ref_get ( &xchg->refcnt );
        if ( ( rc = fc_xchg_rx ( xchg, iob_disown ( iobuf ), meta ) ) != 0 )
                goto err_xchg_rx;

 err_xchg_rx:
        ref_put ( &xchg->refcnt );
 err_no_xchg:
 err_respond:
 err_port_id:
 err_sanity:
        free_iob ( iobuf );
        return rc;
}
int fc_port_login ( struct fc_port port,
struct fc_port_id port_id,
const struct fc_name link_node_wwn,
const struct fc_name link_port_wwn,
int  has_fabric 
)

Log in Fibre Channel port.

Parameters:
portFibre Channel port
port_idLocal port ID
link_node_wwnLink node name
link_port_wwnLink port name
has_fabricLink is to a fabric
Return values:
rcReturn status code

Definition at line 941 of file fc.c.

References DBGC, ECANCELED, fc_els_plogi(), fc_id_ntoa(), fc_link_examine(), fc_link_ok(), fc_link_up(), fc_ntoa(), fc_peer_get(), fc_peer_put(), fc_peers, FC_PORT_HAS_FABRIC, FC_PORT_HAS_NS, fc_port_logout(), fc_port::flags, intf_restart(), fc_port::link, fc_peer::link, fc_port::link_node_wwn, fc_port::link_port_wwn, fc_peer::list, list_for_each_entry_safe, memcmp(), memcpy(), fc_port::name, fc_port::ns_plogi, fc_port::port_id, fc_port::port_wwn, fc_port::ptp_link_port_id, rc, and strerror().

Referenced by fc_els_flogi_rx().

                                                                          {
        struct fc_peer *peer;
        struct fc_peer *tmp;
        int rc;

        /* Perform implicit logout if logged in and details differ */
        if ( fc_link_ok ( &port->link ) &&
             ( ( ( !! ( port->flags & FC_PORT_HAS_FABRIC ) ) !=
                 ( !! has_fabric ) ) ||
               ( memcmp ( &port->link_node_wwn, link_node_wwn,
                          sizeof ( port->link_node_wwn ) ) != 0 ) ||
               ( memcmp ( &port->link_port_wwn, link_port_wwn,
                          sizeof ( port->link_port_wwn ) ) != 0 ) ||
               ( has_fabric &&
                 ( memcmp ( &port->port_id, port_id,
                            sizeof ( port->port_id ) ) != 0 ) ) ) ) {
                fc_port_logout ( port, 0 );
        }

        /* Log in, if applicable */
        if ( ! fc_link_ok ( &port->link ) ) {

                /* Record link port name */
                memcpy ( &port->link_node_wwn, link_node_wwn,
                         sizeof ( port->link_node_wwn ) );
                memcpy ( &port->link_port_wwn, link_port_wwn,
                         sizeof ( port->link_port_wwn ) );
                DBGC ( port, "FCPORT %s logged in to %s",
                       port->name, fc_ntoa ( &port->link_node_wwn ) );
                DBGC ( port, " port %s\n", fc_ntoa ( &port->link_port_wwn ) );

                /* Calculate local (and possibly remote) port IDs */
                if ( has_fabric ) {
                        port->flags |= FC_PORT_HAS_FABRIC;
                        memcpy ( &port->port_id, port_id,
                                 sizeof ( port->port_id ) );
                } else {
                        port->flags &= ~FC_PORT_HAS_FABRIC;
                        if ( memcmp ( &port->port_wwn, link_port_wwn,
                                      sizeof ( port->port_wwn ) ) > 0 ) {
                                memcpy ( &port->port_id, &fc_ptp_high_port_id,
                                         sizeof ( port->port_id ) );
                                memcpy ( &port->ptp_link_port_id,
                                         &fc_ptp_low_port_id,
                                         sizeof ( port->ptp_link_port_id ) );
                        } else {
                                memcpy ( &port->port_id, &fc_ptp_low_port_id,
                                         sizeof ( port->port_id ) );
                                memcpy ( &port->ptp_link_port_id,
                                         &fc_ptp_high_port_id,
                                         sizeof ( port->ptp_link_port_id ) );
                        }
                }
                DBGC ( port, "FCPORT %s logged in via a %s, with local ID "
                       "%s\n", port->name,
                       ( ( port->flags & FC_PORT_HAS_FABRIC ) ?
                         "fabric" : "point-to-point link" ),
                       fc_id_ntoa ( &port->port_id ) );
        }

        /* Log in to name server, if attached to a fabric */
        if ( has_fabric && ! ( port->flags & FC_PORT_HAS_NS ) ) {

                DBGC ( port, "FCPORT %s attempting login to name server\n",
                       port->name );

                intf_restart ( &port->ns_plogi, -ECANCELED );
                if ( ( rc = fc_els_plogi ( &port->ns_plogi, port,
                                           &fc_gs_port_id ) ) != 0 ) {
                        DBGC ( port, "FCPORT %s could not initiate name "
                               "server PLOGI: %s\n",
                               port->name, strerror ( rc ) );
                        fc_port_logout ( port, rc );
                        return rc;
                }
        }

        /* Record login */
        fc_link_up ( &port->link );

        /* Notify peers of link state change */
        list_for_each_entry_safe ( peer, tmp, &fc_peers, list ) {
                fc_peer_get ( peer );
                fc_link_examine ( &peer->link );
                fc_peer_put ( peer );
        }

        return 0;
}
void fc_port_logout ( struct fc_port port,
int  rc 
)

Log out Fibre Channel port.

Parameters:
portFibre Channel port
rcReason for logout

Definition at line 1039 of file fc.c.

References DBGC, fc_link_err(), fc_link_examine(), fc_peer_get(), fc_peer_put(), fc_peers, fc_port::flags, fc_port::link, fc_peer::link, fc_peer::list, list_for_each_entry_safe, memset(), fc_port::name, fc_port::port_id, and strerror().

Referenced by fc_els_logo_logout(), fc_port_close(), fc_port_examine(), fc_port_flogi_done(), fc_port_login(), and fc_port_window_changed().

                                                     {
        struct fc_peer *peer;
        struct fc_peer *tmp;

        DBGC ( port, "FCPORT %s logged out: %s\n",
               port->name, strerror ( rc ) );

        /* Erase port details */
        memset ( &port->port_id, 0, sizeof ( port->port_id ) );
        port->flags = 0;

        /* Record logout */
        fc_link_err ( &port->link, rc );

        /* Notify peers of link state change */
        list_for_each_entry_safe ( peer, tmp, &fc_peers, list ) {
                fc_peer_get ( peer );
                fc_link_examine ( &peer->link );
                fc_peer_put ( peer );
        }
}
static void fc_port_flogi_done ( struct fc_port port,
int  rc 
) [static]

Handle FLOGI completion.

Parameters:
portFibre Channel port
rcReason for completion

Definition at line 1067 of file fc.c.

References fc_port_logout(), fc_port::flogi, and intf_restart().

                                                                {

        intf_restart ( &port->flogi, rc );

        if ( rc != 0 )
                fc_port_logout ( port, rc );
}
static void fc_port_ns_plogi_done ( struct fc_port port,
int  rc 
) [static]

Handle name server PLOGI completion.

Parameters:
portFibre Channel port
rcReason for completion

Definition at line 1081 of file fc.c.

References DBGC, FC_PORT_HAS_NS, fc_port::flags, intf_restart(), fc_port::name, fc_port::ns_plogi, and strerror().

                                                                   {

        intf_restart ( &port->ns_plogi, rc );

        if ( rc == 0 ) {
                port->flags |= FC_PORT_HAS_NS;
                DBGC ( port, "FCPORT %s logged in to name server\n",
                       port->name );
        } else {
                DBGC ( port, "FCPORT %s could not log in to name server: %s\n",
                       port->name, strerror ( rc ) );
                /* Absence of a name server is not a fatal error */
        }
}
static void fc_port_examine ( struct fc_link_state link) [static]

Examine Fibre Channel port link state.

@ link Fibre Channel link state monitor

Definition at line 1101 of file fc.c.

References container_of, DBGC, ECANCELED, fc_els_flogi(), fc_link_ok(), fc_port_logout(), fc_port::flogi, intf_restart(), fc_port::link, fc_port::name, port, rc, and strerror().

Referenced by fc_port_open().

                                                           {
        struct fc_port *port = container_of ( link, struct fc_port, link );
        int rc;

        /* Do nothing if already logged in */
        if ( fc_link_ok ( &port->link ) )
                return;

        DBGC ( port, "FCPORT %s attempting login\n", port->name );

        /* Try to create FLOGI ELS */
        intf_restart ( &port->flogi, -ECANCELED );
        if ( ( rc = fc_els_flogi ( &port->flogi, port ) ) != 0 ) {
                DBGC ( port, "FCPORT %s could not initiate FLOGI: %s\n",
                       port->name, strerror ( rc ) );
                fc_port_logout ( port, rc );
                return;
        }
}
static void fc_port_window_changed ( struct fc_port port) [static]

Handle change of flow control window.

Parameters:
portFibre Channel port

Definition at line 1126 of file fc.c.

References ENOTCONN, fc_link_ok(), fc_link_start(), fc_link_stop(), fc_port_logout(), fc_port::link, fc_port::transport, and xfer_window().

                                                            {
        size_t window;

        /* Check if transport layer is ready */
        window = xfer_window ( &port->transport );
        if ( window > 0 ) {

                /* Transport layer is ready.  Start login if the link
                 * is not already up.
                 */
                if ( ! fc_link_ok ( &port->link ) )
                        fc_link_start ( &port->link );

        } else {

                /* Transport layer is not ready.  Log out port and
                 * wait for transport layer before attempting log in
                 * again.
                 */
                fc_port_logout ( port, -ENOTCONN );
                fc_link_stop ( &port->link );
        }
}
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.

Parameters:
transportTransport interface
nodeFibre Channel node name
portFibre Channel port name
nameSymbolic port name
Return values:
rcReturn status code

Definition at line 1189 of file fc.c.

References DBGC, ENOMEM, fc_link_init(), fc_ntoa(), fc_port_examine(), fc_ports, fc_port::flogi, INIT_LIST_HEAD, intf_init(), intf_plug_plug(), fc_port::link, fc_port::list, list_add_tail, memcpy(), fc_port::name, fc_port::node_wwn, fc_port::ns_plogi, NULL, port, fc_port::port_wwn, ref_init, ref_put, fc_port::refcnt, snprintf(), fc_port::transport, fc_port::xchgs, and zalloc().

Referenced by fcoe_expired().

                                                                      {
        struct fc_port *port;

        /* Allocate and initialise structure */
        port = zalloc ( sizeof ( *port ) );
        if ( ! port )
                return -ENOMEM;
        ref_init ( &port->refcnt, NULL );
        intf_init ( &port->transport, &fc_port_transport_desc, &port->refcnt );
        fc_link_init ( &port->link, fc_port_examine, &port->refcnt );
        intf_init ( &port->flogi, &fc_port_flogi_desc, &port->refcnt );
        intf_init ( &port->ns_plogi, &fc_port_ns_plogi_desc, &port->refcnt );
        list_add_tail ( &port->list, &fc_ports );
        INIT_LIST_HEAD ( &port->xchgs );
        memcpy ( &port->node_wwn, node_wwn, sizeof ( port->node_wwn ) );
        memcpy ( &port->port_wwn, port_wwn, sizeof ( port->port_wwn ) );
        snprintf ( port->name, sizeof ( port->name ), "%s", name );

        DBGC ( port, "FCPORT %s opened as %s",
               port->name, fc_ntoa ( &port->node_wwn ) );
        DBGC ( port, " port %s\n", fc_ntoa ( &port->port_wwn ) );

        /* Attach to transport layer, mortalise self, and return */
        intf_plug_plug ( &port->transport, transport );
        ref_put ( &port->refcnt );
        return 0;
}
struct fc_port* fc_port_find ( const char *  name) [read]

Find Fibre Channel port by name.

Parameters:
nameFibre Channel port name
Return values:
portFibre Channel port, or NULL

Definition at line 1224 of file fc.c.

References fc_ports, fc_port::list, list_for_each_entry, fc_port::name, NULL, port, and strcmp().

Referenced by parse_fc_port().

                                                   {
        struct fc_port *port;

        list_for_each_entry ( port, &fc_ports, list ) {
                if ( strcmp ( name, port->name ) == 0 )
                        return port;
        }
        return NULL;
}
static void fc_peer_close ( struct fc_peer peer,
int  rc 
) [static]

Close Fibre Channel peer.

Parameters:
peerFibre Channel peer
rcReason for close

Definition at line 1247 of file fc.c.

References assert, DBGC, fc_link_stop(), fc_ntoa(), INIT_LIST_HEAD, intf_shutdown(), fc_peer::link, fc_peer::list, list_del, list_empty, fc_peer::plogi, fc_peer::port_wwn, strerror(), and fc_peer::ulps.

Referenced by fc_peer_logout().

                                                           {

        DBGC ( peer, "FCPEER %s closed: %s\n",
               fc_ntoa ( &peer->port_wwn ) , strerror ( rc ) );

        /* Sanity check */
        assert ( list_empty ( &peer->ulps ) );

        /* Stop link timer */
        fc_link_stop ( &peer->link );

        /* Shut down interfaces */
        intf_shutdown ( &peer->plogi, rc );

        /* Remove from list of peers */
        list_del ( &peer->list );
        INIT_LIST_HEAD ( &peer->list );
}
static void fc_peer_increment ( struct fc_peer peer) [static]

Increment Fibre Channel peer active usage count.

Parameters:
peerFibre Channel peer

Definition at line 1271 of file fc.c.

References fc_peer::usage.

Referenced by fc_ulp_attach().

                                                       {

        /* Increment our usage count */
        peer->usage++;
}
static void fc_peer_decrement ( struct fc_peer peer) [static]

Decrement Fibre Channel peer active usage count.

Parameters:
peerFibre Channel peer

Definition at line 1282 of file fc.c.

References assert, fc_peer_logout(), and fc_peer::usage.

Referenced by fc_ulp_detach().

                                                       {

        /* Sanity check */
        assert ( peer->usage > 0 );

        /* Decrement our usage count and log out if we reach zero */
        if ( --(peer->usage) == 0 )
                fc_peer_logout ( peer, 0 );
}
int fc_peer_login ( struct fc_peer peer,
struct fc_port port,
struct fc_port_id port_id 
)

Log in Fibre Channel peer.

Parameters:
peerFibre Channel peer
portFibre Channel port
port_idPort ID
Return values:
rcReturn status code

Definition at line 1300 of file fc.c.

References assert, DBGC, fc_id_ntoa(), fc_link_examine(), fc_link_ok(), fc_link_up(), fc_ntoa(), fc_peer_get(), fc_peer_logout(), fc_port_get(), fc_ulp_get(), fc_ulp_put(), fc_peer::link, fc_ulp::link, fc_ulp::list, list_for_each_entry_safe, memcmp(), memcpy(), fc_port::name, NULL, fc_peer::port, fc_peer::port_id, fc_peer::port_wwn, and fc_peer::ulps.

Referenced by fc_els_plogi_rx().

                                                 {
        struct fc_ulp *ulp;
        struct fc_ulp *tmp;

        /* Perform implicit logout if logged in and details differ */
        if ( fc_link_ok ( &peer->link ) &&
             ( ( peer->port != port ) ||
               ( memcmp ( &peer->port_id, port_id,
                          sizeof ( peer->port_id ) ) !=0 ) ) ) {
                fc_peer_logout ( peer, 0 );
        }

        /* Log in, if applicable */
        if ( ! fc_link_ok ( &peer->link ) ) {

                /* Record peer details */
                assert ( peer->port == NULL );
                peer->port = fc_port_get ( port );
                memcpy ( &peer->port_id, port_id, sizeof ( peer->port_id ) );
                DBGC ( peer, "FCPEER %s logged in via %s as %s\n",
                       fc_ntoa ( &peer->port_wwn ), peer->port->name,
                       fc_id_ntoa ( &peer->port_id ) );

                /* Add login reference */
                fc_peer_get ( peer );
        }

        /* Record login */
        fc_link_up ( &peer->link );

        /* Notify ULPs of link state change */
        list_for_each_entry_safe ( ulp, tmp, &peer->ulps, list ) {
                fc_ulp_get ( ulp );
                fc_link_examine ( &ulp->link );
                fc_ulp_put ( ulp );
        }

        return 0;
}
void fc_peer_logout ( struct fc_peer peer,
int  rc 
)

Log out Fibre Channel peer.

Parameters:
peerFibre Channel peer
rcReason for logout

Definition at line 1347 of file fc.c.

References DBGC, fc_link_err(), fc_link_examine(), fc_link_ok(), fc_ntoa(), fc_peer_close(), fc_peer_put(), fc_port_put(), fc_ulp_get(), fc_ulp_put(), fc_peer::link, fc_ulp::link, fc_ulp::list, list_for_each_entry_safe, NULL, fc_peer::port, fc_peer::port_wwn, strerror(), fc_peer::ulps, and fc_peer::usage.

Referenced by fc_els_logo_logout(), fc_peer_decrement(), fc_peer_examine(), fc_peer_login(), fc_peer_plogi(), and fc_peer_plogi_done().

                                                     {
        struct fc_ulp *ulp;
        struct fc_ulp *tmp;

        DBGC ( peer, "FCPEER %s logged out: %s\n",
               fc_ntoa ( &peer->port_wwn ), strerror ( rc ) );

        /* Drop login reference, if applicable */
        if ( fc_link_ok ( &peer->link ) )
                fc_peer_put ( peer );

        /* Erase peer details */
        fc_port_put ( peer->port );
        peer->port = NULL;

        /* Record logout */
        fc_link_err ( &peer->link, rc );

        /* Notify ULPs of link state change */
        list_for_each_entry_safe ( ulp, tmp, &peer->ulps, list ) {
                fc_ulp_get ( ulp );
                fc_link_examine ( &ulp->link );
                fc_ulp_put ( ulp );
        }

        /* Close peer if there are no active users */
        if ( peer->usage == 0 )
                fc_peer_close ( peer, rc );
}
static void fc_peer_plogi_done ( struct fc_peer peer,
int  rc 
) [static]

Handle PLOGI completion.

Parameters:
peerFibre Channel peer
rcReason for completion

Definition at line 1383 of file fc.c.

References fc_peer_logout(), intf_restart(), and fc_peer::plogi.

                                                                {

        intf_restart ( &peer->plogi, rc );

        if ( rc != 0 )
                fc_peer_logout ( peer, rc );
}
static int fc_peer_plogi ( struct fc_peer peer,
struct fc_port port,
struct fc_port_id peer_port_id 
) [static]

Initiate PLOGI.

Parameters:
peerFibre Channel peer
portFibre Channel port
peer_port_idPeer port ID
Return values:
rcReturn status code

Definition at line 1399 of file fc.c.

References DBGC, ECANCELED, fc_els_plogi(), fc_ntoa(), fc_peer_logout(), intf_restart(), fc_peer::plogi, fc_peer::port_wwn, rc, and strerror().

Referenced by fc_peer_examine().

                                                             {
        int rc;

        /* Try to create PLOGI ELS */
        intf_restart ( &peer->plogi, -ECANCELED );
        if ( ( rc = fc_els_plogi ( &peer->plogi, port, peer_port_id ) ) != 0 ) {
                DBGC ( peer, "FCPEER %s could not initiate PLOGI: %s\n",
                       fc_ntoa ( &peer->port_wwn ), strerror ( rc ) );
                fc_peer_logout ( peer, rc );
                return rc;
        }

        return 0;
}
static void fc_peer_examine ( struct fc_link_state link) [static]

Examine Fibre Channel peer link state.

@ link Fibre Channel link state monitor

Definition at line 1420 of file fc.c.

References assert, container_of, DBGC, ENOTCONN, fc_link_ok(), fc_ntoa(), fc_peer_logout(), fc_peer_plogi(), FC_PORT_HAS_FABRIC, FC_PORT_HAS_NS, fc_ports, fc_port::flags, fc_port::link, fc_peer::link, fc_port::link_port_wwn, fc_port::list, list_for_each_entry, memcmp(), fc_port::name, NULL, fc_peer::port, port, fc_peer::port_wwn, fc_port::ptp_link_port_id, rc, and strerror().

Referenced by fc_peer_create().

                                                           {
        struct fc_peer *peer = container_of ( link, struct fc_peer, link );
        struct fc_port *port;
        int rc;

        /* Check to see if underlying port link has gone down */
        if ( peer->port && ( ! fc_link_ok ( &peer->port->link ) ) ) {
                fc_peer_logout ( peer, -ENOTCONN );
                return;
        }

        /* Do nothing if already logged in */
        if ( fc_link_ok ( &peer->link ) )
                return;

        DBGC ( peer, "FCPEER %s attempting login\n",
               fc_ntoa ( &peer->port_wwn ) );

        /* Sanity check */
        assert ( peer->port == NULL );

        /* First, look for a port with the peer attached via a
         * point-to-point link.
         */
        list_for_each_entry ( port, &fc_ports, list ) {
                if ( fc_link_ok ( &port->link ) &&
                     ( ! ( port->flags & FC_PORT_HAS_FABRIC ) ) &&
                     ( memcmp ( &peer->port_wwn, &port->link_port_wwn,
                                sizeof ( peer->port_wwn ) ) == 0 ) ) {
                        /* Use this peer port ID, and stop looking */
                        fc_peer_plogi ( peer, port, &port->ptp_link_port_id );
                        return;
                }
        }

        /* If the peer is not directly attached, try initiating a name
         * server lookup on any suitable ports.
         */
        list_for_each_entry ( port, &fc_ports, list ) {
                if ( fc_link_ok ( &port->link ) &&
                     ( port->flags & FC_PORT_HAS_FABRIC ) &&
                     ( port->flags & FC_PORT_HAS_NS ) ) {
                        if ( ( rc = fc_ns_query ( peer, port,
                                                  fc_peer_plogi ) ) != 0 ) {
                                DBGC ( peer, "FCPEER %s could not attempt "
                                       "name server lookup on %s: %s\n",
                                       fc_ntoa ( &peer->port_wwn ), port->name,
                                       strerror ( rc ) );
                                /* Non-fatal */
                        }
                }
        }
}
static struct fc_peer* fc_peer_create ( const struct fc_name port_wwn) [static, read]

Create Fibre Channel peer.

Parameters:
port_wwnNode name
Return values:
peerFibre Channel peer, or NULL

Definition at line 1489 of file fc.c.

References DBGC, fc_link_init(), fc_link_start(), fc_ntoa(), fc_peer_examine(), fc_peers, INIT_LIST_HEAD, intf_init(), fc_peer::link, fc_peer::list, list_add_tail, memcpy(), NULL, fc_peer::plogi, fc_peer::port_wwn, ref_init, fc_peer::refcnt, fc_peer::ulps, and zalloc().

Referenced by fc_peer_get_wwn().

                                                                          {
        struct fc_peer *peer;

        /* Allocate and initialise structure */
        peer = zalloc ( sizeof ( *peer ) );
        if ( ! peer )
                return NULL;
        ref_init ( &peer->refcnt, NULL );
        fc_link_init ( &peer->link, fc_peer_examine, &peer->refcnt );
        intf_init ( &peer->plogi, &fc_peer_plogi_desc, &peer->refcnt );
        list_add_tail ( &peer->list, &fc_peers );
        memcpy ( &peer->port_wwn, port_wwn, sizeof ( peer->port_wwn ) );
        INIT_LIST_HEAD ( &peer->ulps );

        /* Start link monitor */
        fc_link_start ( &peer->link );

        DBGC ( peer, "FCPEER %s created\n", fc_ntoa ( &peer->port_wwn ) );
        return peer;
}
struct fc_peer* fc_peer_get_wwn ( const struct fc_name port_wwn) [read]

Get Fibre Channel peer by node name.

Parameters:
port_wwnNode name
Return values:
peerFibre Channel peer, or NULL

Definition at line 1516 of file fc.c.

References fc_peer_create(), fc_peer_get(), fc_peers, fc_peer::list, list_for_each_entry, memcmp(), NULL, and fc_peer::port_wwn.

Referenced by fc_els_plogi_rx(), and fc_ulp_get_wwn_type().

                                                                    {
        struct fc_peer *peer;

        /* Look for an existing peer */
        list_for_each_entry ( peer, &fc_peers, list ) {
                if ( memcmp ( &peer->port_wwn, port_wwn,
                              sizeof ( peer->port_wwn ) ) == 0 )
                        return fc_peer_get ( peer );
        }

        /* Create a new peer */
        peer = fc_peer_create ( port_wwn );
        if ( ! peer )
                return NULL;

        return peer;
}
struct fc_peer* fc_peer_get_port_id ( struct fc_port port,
const struct fc_port_id peer_port_id 
) [read]

Get Fibre Channel peer by port ID.

Parameters:
portFibre Channel port
peer_port_idPeer port ID
Return values:
peerFibre Channel peer, or NULL

Definition at line 1541 of file fc.c.

References fc_peer_get(), fc_peers, fc_peer::list, list_for_each_entry, memcmp(), NULL, fc_peer::port, and fc_peer::port_id.

Referenced by fc_els_logo_logout(), and fc_ulp_get_port_id_type().

                                                                              {
        struct fc_peer *peer;

        /* Look for an existing peer */
        list_for_each_entry ( peer, &fc_peers, list ) {
                if ( ( peer->port == port ) &&
                     ( memcmp ( &peer->port_id, peer_port_id,
                                sizeof ( peer->port_id ) ) == 0 ) )
                        return fc_peer_get ( peer );
        }

        /* Cannot create a new peer, since we have no port name to use */
        return NULL;
}
static void fc_ulp_free ( struct refcnt refcnt) [static]

Free Fibre Channel upper-layer protocol.

Parameters:
refcntReference count

Definition at line 1569 of file fc.c.

References container_of, fc_peer_put(), free, and fc_ulp::peer.

Referenced by fc_ulp_create().

                                                  {
        struct fc_ulp *ulp = container_of ( refcnt, struct fc_ulp, refcnt );

        fc_peer_put ( ulp->peer );
        free ( ulp );
}
static void fc_ulp_close ( struct fc_ulp ulp,
int  rc 
) [static]

Close Fibre Channel upper-layer protocol.

Parameters:
ulpFibre Channel upper-layer protocol
rcReason for close

Definition at line 1582 of file fc.c.

References assert, DBGC, fc_link_stop(), fc_ntoa(), INIT_LIST_HEAD, intf_shutdown(), fc_ulp::link, fc_ulp::list, list_del, list_empty, fc_ulp::peer, fc_peer::port_wwn, fc_ulp::prli, strerror(), fc_ulp::type, and fc_ulp::users.

Referenced by fc_ulp_logout().

                                                        {

        DBGC ( ulp, "FCULP %s/%02x closed: %s\n",
               fc_ntoa ( &ulp->peer->port_wwn ), ulp->type, strerror ( rc ) );

        /* Sanity check */
        assert ( list_empty ( &ulp->users ) );

        /* Stop link monitor */
        fc_link_stop ( &ulp->link );

        /* Shut down interfaces */
        intf_shutdown ( &ulp->prli, rc );

        /* Remove from list of ULPs */
        list_del ( &ulp->list );
        INIT_LIST_HEAD ( &ulp->list );
}
void fc_ulp_attach ( struct fc_ulp ulp,
struct fc_ulp_user user 
)

Attach Fibre Channel upper-layer protocol user.

Parameters:
ulpFibre Channel upper-layer protocol
userFibre Channel upper-layer protocol user

Definition at line 1607 of file fc.c.

References assert, fc_peer_increment(), fc_ulp_get(), fc_ulp_user::list, list_add, NULL, fc_ulp::peer, fc_ulp_user::ulp, and fc_ulp::users.

Referenced by fcpdev_open().

                                                                    {

        /* Sanity check */
        assert ( user->ulp == NULL );

        /* Increment peer's usage count */
        fc_peer_increment ( ulp->peer );

        /* Attach user */
        user->ulp = fc_ulp_get ( ulp );
        list_add ( &user->list, &ulp->users );
}
void fc_ulp_detach ( struct fc_ulp_user user)

Detach Fibre Channel upper-layer protocol user.

Parameters:
userFibre Channel upper-layer protocol user

Definition at line 1625 of file fc.c.

References fc_peer_decrement(), fc_ulp_logout(), fc_ulp_put(), fc_ulp::list, fc_ulp_user::list, list_check_contains_entry, list_del, list_empty, NULL, fc_ulp::peer, fc_ulp_user::ulp, and fc_ulp::users.

Referenced by fcpdev_close().

                                                {
        struct fc_ulp *ulp = user->ulp;

        /* Do nothing if not attached */
        if ( ! ulp )
                return;

        /* Sanity checks */
        list_check_contains_entry ( user, &ulp->users, list );

        /* Detach user and log out if no users remain */
        list_del ( &user->list );
        if ( list_empty ( &ulp->users ) )
                fc_ulp_logout ( ulp, 0 );

        /* Decrement our peer's usage count */
        fc_peer_decrement ( ulp->peer );

        /* Drop reference */
        user->ulp = NULL;
        fc_ulp_put ( ulp );
}
int fc_ulp_login ( struct fc_ulp ulp,
const void *  param,
size_t  param_len,
int  originated 
)

Log in Fibre Channel upper-layer protocol.

Parameters:
ulpFibre Channel upper-layer protocol
paramService parameters
param_lenLength of service parameters
originatedLogin was originated by us
Return values:
rcReturn status code

Definition at line 1657 of file fc.c.

References assert, DBGC, DBGC_HDA, ENOMEM, fc_ulp_user::examine, fc_link_ok(), fc_link_start(), fc_link_stop(), fc_link_up(), fc_ntoa(), fc_ulp_get(), fc_ulp_logout(), FC_ULP_ORIGINATED_LOGIN_OK, fc_ulp_user_get(), fc_ulp_user_put(), fc_ulp::flags, fc_ulp::link, fc_ulp_user::list, list_for_each_entry_safe, malloc(), memcmp(), memcpy(), NULL, fc_ulp::param, fc_ulp::param_len, fc_ulp::peer, fc_peer::port_wwn, fc_ulp::type, user, and fc_ulp::users.

Referenced by fc_els_prli_rx().

                                    {
        struct fc_ulp_user *user;
        struct fc_ulp_user *tmp;

        /* Perform implicit logout if logged in and service parameters differ */
        if ( fc_link_ok ( &ulp->link ) &&
             ( ( ulp->param_len != param_len ) ||
               ( memcmp ( ulp->param, param, ulp->param_len ) != 0 ) ) ) {
                fc_ulp_logout ( ulp, 0 );
        }

        /* Work around a bug in some versions of the Linux Fibre
         * Channel stack, which fail to fully initialise image pairs
         * established via a PRLI originated by the Linux stack
         * itself.
         */
        if ( originated )
                ulp->flags |= FC_ULP_ORIGINATED_LOGIN_OK;
        if ( ! ( ulp->flags & FC_ULP_ORIGINATED_LOGIN_OK ) ) {
                DBGC ( ulp, "FCULP %s/%02x sending extra PRLI to work around "
                       "Linux bug\n",
                       fc_ntoa ( &ulp->peer->port_wwn ), ulp->type );
                fc_link_stop ( &ulp->link );
                fc_link_start ( &ulp->link );
                return 0;
        }

        /* Log in, if applicable */
        if ( ! fc_link_ok ( &ulp->link ) ) {

                /* Record service parameters */
                assert ( ulp->param == NULL );
                assert ( ulp->param_len == 0 );
                ulp->param = malloc ( param_len );
                if ( ! ulp->param ) {
                        DBGC ( ulp, "FCULP %s/%02x could not record "
                               "parameters\n",
                               fc_ntoa ( &ulp->peer->port_wwn ), ulp->type );
                        return -ENOMEM;
                }
                memcpy ( ulp->param, param, param_len );
                ulp->param_len = param_len;
                DBGC ( ulp, "FCULP %s/%02x logged in with parameters:\n",
                       fc_ntoa ( &ulp->peer->port_wwn ), ulp->type );
                DBGC_HDA ( ulp, 0, ulp->param, ulp->param_len );

                /* Add login reference */
                fc_ulp_get ( ulp );
        }

        /* Record login */
        fc_link_up ( &ulp->link );

        /* Notify users of link state change */
        list_for_each_entry_safe ( user, tmp, &ulp->users, list ) {
                fc_ulp_user_get ( user );
                user->examine ( user );
                fc_ulp_user_put ( user );
        }

        return 0;
}
void fc_ulp_logout ( struct fc_ulp ulp,
int  rc 
)

Log out Fibre Channel upper-layer protocol.

Parameters:
ulpFibre Channel upper-layer protocol
rcReason for logout

Definition at line 1727 of file fc.c.

References DBGC, fc_ulp_user::examine, fc_link_err(), fc_link_ok(), fc_ntoa(), fc_ulp_close(), fc_ulp_put(), fc_ulp_user_get(), fc_ulp_user_put(), fc_ulp::flags, free, fc_ulp::link, fc_ulp_user::list, list_empty, list_for_each_entry_safe, NULL, fc_ulp::param, fc_ulp::param_len, fc_ulp::peer, fc_peer::port_wwn, strerror(), fc_ulp::type, user, and fc_ulp::users.

Referenced by fc_els_prli_rx(), fc_ulp_detach(), fc_ulp_examine(), fc_ulp_login(), and fc_ulp_prli_done().

                                                  {
        struct fc_ulp_user *user;
        struct fc_ulp_user *tmp;

        DBGC ( ulp, "FCULP %s/%02x logged out: %s\n",
               fc_ntoa ( &ulp->peer->port_wwn ), ulp->type, strerror ( rc ) );

        /* Drop login reference, if applicable */
        if ( fc_link_ok ( &ulp->link ) )
                fc_ulp_put ( ulp );

        /* Discard service parameters */
        free ( ulp->param );
        ulp->param = NULL;
        ulp->param_len = 0;
        ulp->flags = 0;

        /* Record logout */
        fc_link_err ( &ulp->link, rc );

        /* Notify users of link state change */
        list_for_each_entry_safe ( user, tmp, &ulp->users, list ) {
                fc_ulp_user_get ( user );
                user->examine ( user );
                fc_ulp_user_put ( user );
        }

        /* Close ULP if there are no clients attached */
        if ( list_empty ( &ulp->users ) )
                fc_ulp_close ( ulp, rc );
}
static void fc_ulp_prli_done ( struct fc_ulp ulp,
int  rc 
) [static]

Handle PRLI completion.

Parameters:
ulpFibre Channel upper-layer protocol
rcReason for completion

Definition at line 1765 of file fc.c.

References fc_ulp_logout(), intf_restart(), and fc_ulp::prli.

                                                            {

        intf_restart ( &ulp->prli, rc );

        if ( rc != 0 )
                fc_ulp_logout ( ulp, rc );
}
static void fc_ulp_examine ( struct fc_link_state link) [static]

Examine Fibre Channel upper-layer protocol link state.

@ link Fibre Channel link state monitor

Definition at line 1778 of file fc.c.

References container_of, DBGC, ECANCELED, ENOTCONN, fc_els_prli(), fc_link_ok(), fc_ntoa(), fc_ulp_logout(), FC_ULP_ORIGINATED_LOGIN_OK, fc_ulp::flags, intf_restart(), fc_peer::link, fc_ulp::link, fc_ulp::peer, fc_peer::port, fc_peer::port_id, fc_peer::port_wwn, fc_ulp::prli, rc, strerror(), and fc_ulp::type.

Referenced by fc_ulp_create().

                                                          {
        struct fc_ulp *ulp = container_of ( link, struct fc_ulp, link );
        int rc;

        /* Check to see if underlying peer link has gone down */
        if ( ! fc_link_ok ( &ulp->peer->link ) ) {
                fc_ulp_logout ( ulp, -ENOTCONN );
                return;
        }

        /* Do nothing if already logged in */
        if ( fc_link_ok ( &ulp->link ) &&
             ( ulp->flags & FC_ULP_ORIGINATED_LOGIN_OK ) )
                return;

        DBGC ( ulp, "FCULP %s/%02x attempting login\n",
               fc_ntoa ( &ulp->peer->port_wwn ), ulp->type );

        /* Try to create PRLI ELS */
        intf_restart ( &ulp->prli, -ECANCELED );
        if ( ( rc = fc_els_prli ( &ulp->prli, ulp->peer->port,
                                  &ulp->peer->port_id, ulp->type ) ) != 0 ) {
                DBGC ( ulp, "FCULP %s/%02x could not initiate PRLI: %s\n",
                       fc_ntoa ( &ulp->peer->port_wwn ), ulp->type,
                       strerror ( rc ) );
                fc_ulp_logout ( ulp, rc );
                return;
        }
}
static struct fc_ulp* fc_ulp_create ( struct fc_peer peer,
unsigned int  type 
) [static, read]

Create Fibre Channel upper-layer protocl.

Parameters:
peerFibre Channel peer
typeType
Return values:
ulpFibre Channel upper-layer protocol, or NULL

Definition at line 1824 of file fc.c.

References DBGC, fc_link_init(), fc_link_start(), fc_ntoa(), fc_peer_get(), fc_ulp_examine(), fc_ulp_free(), INIT_LIST_HEAD, intf_init(), fc_ulp::link, fc_ulp::list, list_add_tail, NULL, fc_ulp::peer, fc_peer::port_wwn, fc_ulp::prli, ref_init, fc_ulp::refcnt, type, fc_ulp::type, fc_peer::ulps, fc_ulp::users, and zalloc().

Referenced by fc_ulp_get_type().

                                                           {
        struct fc_ulp *ulp;

        /* Allocate and initialise structure */
        ulp = zalloc ( sizeof ( *ulp ) );
        if ( ! ulp )
                return NULL;
        ref_init ( &ulp->refcnt, fc_ulp_free );
        fc_link_init ( &ulp->link, fc_ulp_examine, &ulp->refcnt );
        intf_init ( &ulp->prli, &fc_ulp_prli_desc, &ulp->refcnt );
        ulp->peer = fc_peer_get ( peer );
        list_add_tail ( &ulp->list, &peer->ulps );
        ulp->type = type;
        INIT_LIST_HEAD ( &ulp->users );

        /* Start link state monitor */
        fc_link_start ( &ulp->link );

        DBGC ( ulp, "FCULP %s/%02x created\n",
               fc_ntoa ( &ulp->peer->port_wwn ), ulp->type );
        return ulp;
}
static struct fc_ulp* fc_ulp_get_type ( struct fc_peer peer,
unsigned int  type 
) [static, read]

Get Fibre Channel upper-layer protocol by peer and type.

Parameters:
peerFibre Channel peer
typeType
Return values:
ulpFibre Channel upper-layer protocol, or NULL

Definition at line 1855 of file fc.c.

References fc_ulp_create(), fc_ulp_get(), fc_ulp::list, list_for_each_entry, NULL, fc_ulp::type, and fc_peer::ulps.

Referenced by fc_ulp_get_port_id_type(), and fc_ulp_get_wwn_type().

                                                             {
        struct fc_ulp *ulp;

        /* Look for an existing ULP */
        list_for_each_entry ( ulp, &peer->ulps, list ) {
                if ( ulp->type == type )
                        return fc_ulp_get ( ulp );
        }

        /* Create a new ULP */
        ulp = fc_ulp_create ( peer, type );
        if ( ! ulp )
                return NULL;

        return ulp;
}
struct fc_ulp* fc_ulp_get_wwn_type ( const struct fc_name port_wwn,
unsigned int  type 
) [read]

Get Fibre Channel upper-layer protocol by port name and type.

Parameters:
port_wwnPort name
typeType
Return values:
ulpFibre Channel upper-layer protocol, or NULL

Definition at line 1880 of file fc.c.

References fc_peer_get_wwn(), fc_peer_put(), fc_ulp_get_type(), fc_ulp_put(), and NULL.

Referenced by fcpdev_open().

                                                          {
        struct fc_ulp *ulp;
        struct fc_peer *peer;

        /* Get peer */
        peer = fc_peer_get_wwn ( port_wwn );
        if ( ! peer )
                goto err_peer_get_wwn;

        /* Get ULP */
        ulp = fc_ulp_get_type ( peer, type );
        if ( ! ulp )
                goto err_ulp_get_type;

        /* Drop temporary reference to peer */
        fc_peer_put ( peer );

        return ulp;

        fc_ulp_put ( ulp );
 err_ulp_get_type:
        fc_peer_put ( peer );
 err_peer_get_wwn:
        return NULL;
}
struct fc_ulp* fc_ulp_get_port_id_type ( struct fc_port port,
const struct fc_port_id peer_port_id,
unsigned int  type 
) [read]

Get Fibre Channel upper-layer protocol by port ID and type.

Parameters:
portFibre Channel port
peer_port_idPeer port ID
typeType
Return values:
ulpFibre Channel upper-layer protocol, or NULL

Definition at line 1915 of file fc.c.

References fc_peer_get_port_id(), fc_peer_put(), fc_ulp_get_type(), fc_ulp_put(), and NULL.

Referenced by fc_els_prli_rx(), and fc_els_prli_tx().

                                                              {
        struct fc_ulp *ulp;
        struct fc_peer *peer;

        /* Get peer */
        peer = fc_peer_get_port_id ( port, peer_port_id );
        if ( ! peer )
                goto err_peer_get_wwn;

        /* Get ULP */
        ulp = fc_ulp_get_type ( peer, type );
        if ( ! ulp )
                goto err_ulp_get_type;

        /* Drop temporary reference to peer */
        fc_peer_put ( peer );

        return ulp;

        fc_ulp_put ( ulp );
 err_ulp_get_type:
        fc_peer_put ( peer );
 err_peer_get_wwn:
        return NULL;
}
REQUIRE_OBJECT ( config_fc  )

Variable Documentation

struct fc_port_id fc_empty_port_id = { .bytes = { 0x00, 0x00, 0x00 } }

Unassigned port ID.

Definition at line 65 of file fc.c.

Referenced by fcels_exec().

struct fc_port_id fc_f_port_id = { .bytes = { 0xff, 0xff, 0xfe } }

F_Port contoller port ID.

Definition at line 68 of file fc.c.

Referenced by fc_els_flogi(), fc_els_logo_logout(), and fcels_exec().

struct fc_port_id fc_gs_port_id = { .bytes = { 0xff, 0xff, 0xfc } }

Generic services port ID.

Definition at line 71 of file fc.c.

Referenced by fc_ns_query_step().

struct fc_port_id fc_ptp_low_port_id = { .bytes = { 0x01, 0x01, 0x01 } }

Point-to-point low port ID.

Definition at line 74 of file fc.c.

struct fc_port_id fc_ptp_high_port_id = { .bytes = { 0x01, 0x01, 0x02 } }

Point-to-point high port ID.

Definition at line 77 of file fc.c.

Initial value:

Mapping from Fibre Channel routing control information to xfer metadata.

Definition at line 568 of file fc.c.

Initial value:

Fibre Channel exchange ULP interface operations.

Definition at line 677 of file fc.c.

Initial value:

Fibre Channel exchange ULP interface descriptor.

Definition at line 685 of file fc.c.

Initial value:

Fibre Channel port transport interface operations.

Definition at line 1151 of file fc.c.

Initial value:
        INTF_DESC ( struct fc_port, transport, fc_port_transport_op )

Fibre Channel port transport interface descriptor.

Definition at line 1159 of file fc.c.

Initial value:

Fibre Channel port FLOGI interface operations.

Definition at line 1163 of file fc.c.

Initial value:
        INTF_DESC ( struct fc_port, flogi, fc_port_flogi_op )

Fibre Channel port FLOGI interface descriptor.

Definition at line 1168 of file fc.c.

Initial value:

Fibre Channel port name server PLOGI interface operations.

Definition at line 1172 of file fc.c.

Initial value:
        INTF_DESC ( struct fc_port, ns_plogi, fc_port_ns_plogi_op )

Fibre Channel port name server PLOGI interface descriptor.

Definition at line 1177 of file fc.c.

Initial value:

Fibre Channel peer PLOGI interface operations.

Definition at line 1475 of file fc.c.

Initial value:

Fibre Channel peer PLOGI interface descriptor.

Definition at line 1480 of file fc.c.

Initial value:

Fibre Channel upper-layer protocol PRLI interface operations.

Definition at line 1809 of file fc.c.

Initial value:
        INTF_DESC ( struct fc_ulp, prli, fc_ulp_prli_op )

Fibre Channel upper-layer protocol PRLI interface descriptor.

Definition at line 1814 of file fc.c.