iPXE
fc.h File Reference

Fibre Channel. More...

#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/list.h>
#include <ipxe/tables.h>
#include <ipxe/interface.h>
#include <ipxe/retry.h>
#include <ipxe/socket.h>

Go to the source code of this file.

Data Structures

struct  fc_name
 A Fibre Channel name. More...
struct  fc_port_id
 A Fibre Channel port identifier. More...
struct  sockaddr_fc
 Fibre Channel socket address. More...
 A Fibre Channel link state nonitor. More...
struct  fc_frame_header
 A Fibre Channel Frame Header. More...
struct  fc_responder
 A Fibre Channel responder. More...
struct  fc_port
 A Fibre Channel port. More...
struct  fc_peer
 A Fibre Channel peer. More...
struct  fc_ulp
 A Fibre Channel upper-layer protocol. More...
struct  fc_ulp_user
 A Fibre Channel upper-layer protocol user. More...

Macros

#define FC_NAME_STRLEN   23 /* "xx:xx:xx:xx:xx:xx:xx:xx" */
 Length of Fibre Channel name text.
#define FC_PORT_ID_STRLEN   9 /* "xx.xx.xx" */
 Length of Fibre Channel port identifier next.
#define FC_LINK_RETRY_DELAY   ( 2 * TICKS_PER_SEC )
 Delay between failed link-up attempts.
#define FC_R_CTL_ROUTING_MASK   0xf0
 Fibre Channel Routing Control Routing mask.
#define FC_R_CTL_INFO_MASK   0x07
 Fibre Channel Routing Control Information mask.
#define FC_RX_ID_UNKNOWN   0xffff
 Responder exchange identifier used before first response.
#define FC_RESPONDERS   __table ( struct fc_responder, "fc_responders" )
 Fibre Channel responder table.
#define __fc_responder   __table_entry ( FC_RESPONDERS, 01 )
 Declare a Fibre Channel responder.

Enumerations

enum  fc_r_ctl_routing {
  FC_R_CTL_DATA = 0x00 , FC_R_CTL_ELS = 0x20 , FC_R_CTL_FC4_LINK = 0x30 , FC_R_CTL_VIDEO = 0x40 ,
  FC_R_CTL_EH = 0x50 , FC_R_CTL_BLS = 0x80 , FC_R_CTL_LINK_CTRL = 0xc0 , FC_R_CTL_EXT_ROUTE = 0xf0
}
 Fibre Channel Routing Control Routing. More...
enum  fc_r_ctl_info {
  FC_R_CTL_UNCAT = 0x00 , FC_R_CTL_SOL_DATA = 0x01 , FC_R_CTL_UNSOL_CTRL = 0x02 , FC_R_CTL_SOL_CTRL = 0x03 ,
  FC_R_CTL_UNSOL_DATA = 0x04 , FC_R_CTL_DATA_DESC = 0x05 , FC_R_CTL_UNSOL_CMD = 0x06 , FC_R_CTL_CMD_STAT = 0x07
}
 Fibre Channel Routing Control Information. More...
enum  fc_type { FC_TYPE_BLS = 0x00 , FC_TYPE_ELS = 0x01 , FC_TYPE_FCP = 0x08 , FC_TYPE_CT = 0x20 }
 Fibre Channel Data Structure Type. More...
enum  fc_f_ctl_es {
  FC_F_CTL_ES_RESPONDER = 0x80 , FC_F_CTL_ES_RECIPIENT = 0x40 , FC_F_CTL_ES_FIRST = 0x20 , FC_F_CTL_ES_LAST = 0x10 ,
  FC_F_CTL_ES_END = 0x08 , FC_F_CTL_ES_TRANSFER = 0x01
}
 Fibre Channel Frame Control - Exchange and Sequence. More...
enum  fc_f_ctl_misc { FC_F_CTL_MISC_REL_OFF = 0x08 }
 Fibre Channel Frame Control - Miscellaneous. More...
enum  fc_port_flags { FC_PORT_HAS_FABRIC = 0x0001 , FC_PORT_HAS_NS = 0x0002 }
 Fibre Channel port flags. More...
enum  fc_ulp_flags { FC_ULP_ORIGINATED_LOGIN_OK = 0x0001 }
 Fibre Channel upper-layer protocol flags. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
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 int fc_link_ok (struct fc_link_state *link)
 Check Fibre Channel link state.
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_portfc_port_get (struct fc_port *port)
 Get reference to Fibre Channel port.
static void fc_port_put (struct fc_port *port)
 Drop reference to 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.
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 struct fc_peerfc_peer_get (struct fc_peer *peer)
 Get reference to Fibre Channel peer.
static void fc_peer_put (struct fc_peer *peer)
 Drop reference to 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.
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 struct fc_ulpfc_ulp_get (struct fc_ulp *ulp)
 Get reference to Fibre Channel upper-layer protocol.
static void fc_ulp_put (struct fc_ulp *ulp)
 Drop reference to Fibre Channel upper-layer protocol.
static struct fc_ulp_userfc_ulp_user_get (struct fc_ulp_user *user)
 Get reference to Fibre Channel upper-layer protocol user.
static void fc_ulp_user_put (struct fc_ulp_user *user)
 Drop reference to Fibre Channel upper-layer protocol user.
static void fc_ulp_user_init (struct fc_ulp_user *user, void(*examine)(struct fc_ulp_user *user), struct refcnt *refcnt)
 Initialise Fibre Channel upper-layer protocol user.
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.
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.

Variables

struct fc_port_id fc_empty_port_id
 Unassigned port ID.
struct fc_port_id fc_f_port_id
 F_Port contoller port ID.
struct fc_port_id fc_gs_port_id
 Generic services port ID.
struct fc_port_id fc_ptp_low_port_id
 Point-to-point low port ID.
struct fc_port_id fc_ptp_high_port_id
 Point-to-point high port ID.
struct list_head fc_ports
struct list_head fc_peers

Detailed Description

Fibre Channel.

Definition in file fc.h.

Macro Definition Documentation

◆ FC_NAME_STRLEN

#define FC_NAME_STRLEN   23 /* "xx:xx:xx:xx:xx:xx:xx:xx" */

Length of Fibre Channel name text.

Definition at line 35 of file fc.h.

Referenced by fc_ntoa(), and fcp_parse_uri().

◆ FC_PORT_ID_STRLEN

#define FC_PORT_ID_STRLEN   9 /* "xx.xx.xx" */

Length of Fibre Channel port identifier next.

Definition at line 43 of file fc.h.

Referenced by fc_id_ntoa().

◆ FC_LINK_RETRY_DELAY

#define FC_LINK_RETRY_DELAY   ( 2 * TICKS_PER_SEC )

Delay between failed link-up attempts.

Definition at line 87 of file fc.h.

Referenced by fc_link_err(), and fc_link_expired().

◆ FC_R_CTL_ROUTING_MASK

#define FC_R_CTL_ROUTING_MASK   0xf0

Fibre Channel Routing Control Routing mask.

Definition at line 173 of file fc.h.

◆ FC_R_CTL_INFO_MASK

#define FC_R_CTL_INFO_MASK   0x07

Fibre Channel Routing Control Information mask.

Definition at line 188 of file fc.h.

Referenced by fc_xchg_rx().

◆ FC_RX_ID_UNKNOWN

#define FC_RX_ID_UNKNOWN   0xffff

Responder exchange identifier used before first response.

Definition at line 214 of file fc.h.

Referenced by fc_xchg_create().

◆ FC_RESPONDERS

#define FC_RESPONDERS   __table ( struct fc_responder, "fc_responders" )

Fibre Channel responder table.

Definition at line 240 of file fc.h.

Referenced by fc_xchg_respond().

◆ __fc_responder

#define __fc_responder   __table_entry ( FC_RESPONDERS, 01 )

Declare a Fibre Channel responder.

Definition at line 243 of file fc.h.

Enumeration Type Documentation

◆ fc_r_ctl_routing

Fibre Channel Routing Control Routing.

Enumerator
FC_R_CTL_DATA 

Device Data.

FC_R_CTL_ELS 

Extended Link Services.

FC_R_CTL_FC4_LINK 

FC-4 Link Data.

FC_R_CTL_VIDEO 

Video Data.

FC_R_CTL_EH 

Extended Headers.

FC_R_CTL_BLS 

Basic Link Services.

FC_R_CTL_LINK_CTRL 

Link Control.

FC_R_CTL_EXT_ROUTE 

Extended Routing.

Definition at line 161 of file fc.h.

161 {
162 FC_R_CTL_DATA = 0x00, /**< Device Data */
163 FC_R_CTL_ELS = 0x20, /**< Extended Link Services */
164 FC_R_CTL_FC4_LINK = 0x30, /**< FC-4 Link Data */
165 FC_R_CTL_VIDEO = 0x40, /**< Video Data */
166 FC_R_CTL_EH = 0x50, /**< Extended Headers */
167 FC_R_CTL_BLS = 0x80, /**< Basic Link Services */
168 FC_R_CTL_LINK_CTRL = 0xc0, /**< Link Control */
169 FC_R_CTL_EXT_ROUTE = 0xf0, /**< Extended Routing */
170};
@ FC_R_CTL_BLS
Basic Link Services.
Definition fc.h:167
@ FC_R_CTL_DATA
Device Data.
Definition fc.h:162
@ FC_R_CTL_ELS
Extended Link Services.
Definition fc.h:163
@ FC_R_CTL_EH
Extended Headers.
Definition fc.h:166
@ FC_R_CTL_FC4_LINK
FC-4 Link Data.
Definition fc.h:164
@ FC_R_CTL_VIDEO
Video Data.
Definition fc.h:165
@ FC_R_CTL_LINK_CTRL
Link Control.
Definition fc.h:168
@ FC_R_CTL_EXT_ROUTE
Extended Routing.
Definition fc.h:169

◆ fc_r_ctl_info

Fibre Channel Routing Control Information.

Enumerator
FC_R_CTL_UNCAT 

Uncategorized.

FC_R_CTL_SOL_DATA 

Solicited Data.

FC_R_CTL_UNSOL_CTRL 

Unsolicited Control.

FC_R_CTL_SOL_CTRL 

Solicited Control.

FC_R_CTL_UNSOL_DATA 

Unsolicited Data.

FC_R_CTL_DATA_DESC 

Data Descriptor.

FC_R_CTL_UNSOL_CMD 

Unsolicited Command.

FC_R_CTL_CMD_STAT 

Command Status.

Definition at line 176 of file fc.h.

176 {
177 FC_R_CTL_UNCAT = 0x00, /**< Uncategorized */
178 FC_R_CTL_SOL_DATA = 0x01, /**< Solicited Data */
179 FC_R_CTL_UNSOL_CTRL = 0x02, /**< Unsolicited Control */
180 FC_R_CTL_SOL_CTRL = 0x03, /**< Solicited Control */
181 FC_R_CTL_UNSOL_DATA = 0x04, /**< Unsolicited Data */
182 FC_R_CTL_DATA_DESC = 0x05, /**< Data Descriptor */
183 FC_R_CTL_UNSOL_CMD = 0x06, /**< Unsolicited Command */
184 FC_R_CTL_CMD_STAT = 0x07, /**< Command Status */
185};
@ FC_R_CTL_UNCAT
Uncategorized.
Definition fc.h:177
@ FC_R_CTL_UNSOL_DATA
Unsolicited Data.
Definition fc.h:181
@ FC_R_CTL_UNSOL_CTRL
Unsolicited Control.
Definition fc.h:179
@ FC_R_CTL_DATA_DESC
Data Descriptor.
Definition fc.h:182
@ FC_R_CTL_UNSOL_CMD
Unsolicited Command.
Definition fc.h:183
@ FC_R_CTL_SOL_DATA
Solicited Data.
Definition fc.h:178
@ FC_R_CTL_CMD_STAT
Command Status.
Definition fc.h:184
@ FC_R_CTL_SOL_CTRL
Solicited Control.
Definition fc.h:180

◆ fc_type

enum fc_type

Fibre Channel Data Structure Type.

Enumerator
FC_TYPE_BLS 

Basic Link Service.

FC_TYPE_ELS 

Extended Link Service.

FC_TYPE_FCP 

Fibre Channel Protocol.

FC_TYPE_CT 

Common Transport.

Definition at line 191 of file fc.h.

191 {
192 FC_TYPE_BLS = 0x00, /**< Basic Link Service */
193 FC_TYPE_ELS = 0x01, /**< Extended Link Service */
194 FC_TYPE_FCP = 0x08, /**< Fibre Channel Protocol */
195 FC_TYPE_CT = 0x20, /**< Common Transport */
196};
@ FC_TYPE_BLS
Basic Link Service.
Definition fc.h:192
@ FC_TYPE_FCP
Fibre Channel Protocol.
Definition fc.h:194
@ FC_TYPE_CT
Common Transport.
Definition fc.h:195
@ FC_TYPE_ELS
Extended Link Service.
Definition fc.h:193

◆ fc_f_ctl_es

Fibre Channel Frame Control - Exchange and Sequence.

Enumerator
FC_F_CTL_ES_RESPONDER 

Responder of Exchange.

FC_F_CTL_ES_RECIPIENT 

Sequence Recipient.

FC_F_CTL_ES_FIRST 

First Sequence of Exchange.

FC_F_CTL_ES_LAST 

Last Sequence of Exchange.

FC_F_CTL_ES_END 

Last Data Frame of Sequence.

FC_F_CTL_ES_TRANSFER 

Transfer Sequence Initiative.

Definition at line 199 of file fc.h.

199 {
200 FC_F_CTL_ES_RESPONDER = 0x80, /**< Responder of Exchange */
201 FC_F_CTL_ES_RECIPIENT = 0x40, /**< Sequence Recipient */
202 FC_F_CTL_ES_FIRST = 0x20, /**< First Sequence of Exchange */
203 FC_F_CTL_ES_LAST = 0x10, /**< Last Sequence of Exchange */
204 FC_F_CTL_ES_END = 0x08, /**< Last Data Frame of Sequence */
205 FC_F_CTL_ES_TRANSFER = 0x01, /**< Transfer Sequence Initiative */
206};
@ FC_F_CTL_ES_FIRST
First Sequence of Exchange.
Definition fc.h:202
@ FC_F_CTL_ES_END
Last Data Frame of Sequence.
Definition fc.h:204
@ FC_F_CTL_ES_RECIPIENT
Sequence Recipient.
Definition fc.h:201
@ FC_F_CTL_ES_TRANSFER
Transfer Sequence Initiative.
Definition fc.h:205
@ FC_F_CTL_ES_LAST
Last Sequence of Exchange.
Definition fc.h:203
@ FC_F_CTL_ES_RESPONDER
Responder of Exchange.
Definition fc.h:200

◆ fc_f_ctl_misc

Fibre Channel Frame Control - Miscellaneous.

Enumerator
FC_F_CTL_MISC_REL_OFF 

Relative Offset Present.

Definition at line 209 of file fc.h.

209 {
210 FC_F_CTL_MISC_REL_OFF = 0x08, /**< Relative Offset Present */
211};
@ FC_F_CTL_MISC_REL_OFF
Relative Offset Present.
Definition fc.h:210

◆ fc_port_flags

Fibre Channel port flags.

Enumerator
FC_PORT_HAS_FABRIC 

Port is attached to a fabric.

FC_PORT_HAS_NS 

Port is logged in to a name server.

Definition at line 291 of file fc.h.

291 {
292 /** Port is attached to a fabric */
293 FC_PORT_HAS_FABRIC = 0x0001,
294 /** Port is logged in to a name server */
295 FC_PORT_HAS_NS = 0x0002,
296};
@ FC_PORT_HAS_FABRIC
Port is attached to a fabric.
Definition fc.h:293
@ FC_PORT_HAS_NS
Port is logged in to a name server.
Definition fc.h:295

◆ fc_ulp_flags

Fibre Channel upper-layer protocol flags.

Enumerator
FC_ULP_ORIGINATED_LOGIN_OK 

A login originated by us has succeeded.

Definition at line 448 of file fc.h.

448 {
449 /** A login originated by us has succeeded */
451};
@ FC_ULP_ORIGINATED_LOGIN_OK
A login originated by us has succeeded.
Definition fc.h:450

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ fc_id_ntoa()

const char * fc_id_ntoa ( const struct fc_port_id * id)
extern

Format Fibre Channel port ID.

Parameters
idFibre Channel port ID
Return values
id_textPort ID text

Definition at line 92 of file fc.c.

92 {
93 static char id_text[ FC_PORT_ID_STRLEN + 1 /* NUL */ ];
94
95 snprintf ( id_text, sizeof ( id_text ), "%02x.%02x.%02x",
96 id->bytes[0], id->bytes[1], id->bytes[2] );
97 return id_text;
98}
uint8_t id
Request identifier.
Definition ena.h:1
#define FC_PORT_ID_STRLEN
Length of Fibre Channel port identifier next.
Definition fc.h:43
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References FC_PORT_ID_STRLEN, id, 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().

◆ fc_id_aton()

int fc_id_aton ( const char * id_text,
struct fc_port_id * id )
extern

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.

107 {
108 char *ptr = ( ( char * ) id_text );
109 unsigned int i = 0;
110
111 while ( 1 ) {
112 id->bytes[i++] = strtoul ( ptr, &ptr, 16 );
113 if ( i == sizeof ( id->bytes ) )
114 return ( ( *ptr == '\0' ) ? 0 : -EINVAL );
115 if ( *ptr != '.' )
116 return -EINVAL;
117 ptr++;
118 }
119}
#define EINVAL
Invalid argument.
Definition errno.h:472
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition string.c:516

References EINVAL, id, and strtoul().

Referenced by parse_fc_port_id().

◆ fc_ntoa()

const char * fc_ntoa ( const struct fc_name * wwn)
extern

Format Fibre Channel WWN.

Parameters
wwnFibre Channel WWN
Return values
wwn_textWWN text

Definition at line 127 of file fc.c.

127 {
128 static char wwn_text[ FC_NAME_STRLEN + 1 /* NUL */ ];
129
130 snprintf ( wwn_text, sizeof ( wwn_text ),
131 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
132 wwn->bytes[0], wwn->bytes[1], wwn->bytes[2], wwn->bytes[3],
133 wwn->bytes[4], wwn->bytes[5], wwn->bytes[6], wwn->bytes[7] );
134 return wwn_text;
135}
uint64_t wwn
WWN.
Definition edd.h:1
#define FC_NAME_STRLEN
Length of Fibre Channel name text.
Definition fc.h:35

References FC_NAME_STRLEN, snprintf(), and wwn.

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().

◆ fc_aton()

int fc_aton ( const char * wwn_text,
struct fc_name * wwn )
extern

Parse Fibre Channel WWN.

Parameters
wwn_textWWN text
Return values
wwnFibre Channel WWN
rcReturn status code

Definition at line 144 of file fc.c.

144 {
145 char *ptr = ( ( char * ) wwn_text );
146 unsigned int i = 0;
147
148 while ( 1 ) {
149 wwn->bytes[i++] = strtoul ( ptr, &ptr, 16 );
150 if ( i == sizeof ( wwn->bytes ) )
151 return ( ( *ptr == '\0' ) ? 0 : -EINVAL );
152 if ( *ptr != ':' )
153 return -EINVAL;
154 ptr++;
155 }
156}

References EINVAL, strtoul(), and wwn.

Referenced by fcp_parse_uri().

◆ fc_fill_sockaddr()

struct sockaddr * fc_fill_sockaddr ( struct sockaddr_fc * sa_fc,
struct fc_port_id * id )
extern

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.

166 {
167 union {
168 struct sockaddr sa;
169 struct sockaddr_fc fc;
170 } *u = container_of ( sa_fc, typeof ( *u ), fc );
171
172 memset ( sa_fc, 0, sizeof ( *sa_fc ) );
173 sa_fc->sfc_family = AF_FC;
174 memcpy ( &sa_fc->sfc_port_id, id, sizeof ( sa_fc->sfc_port_id ) );
175 return &u->sa;
176}
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
union @104331263140136355135267063077374276003064103115 u
#define AF_FC
Fibre Channel addresses.
Definition socket.h:66
u16 fc
802.11 Frame Control field
Definition ieee80211.h:0
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
Fibre Channel socket address.
Definition fc.h:48
sa_family_t sfc_family
Socket address family (part of struct sockaddr).
Definition fc.h:53
struct fc_port_id sfc_port_id
Port ID.
Definition fc.h:55
Generalized socket address structure.
Definition socket.h:97
struct sockaddr sa
Definition syslog.c:57

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

Referenced by fc_els_tx(), and fc_xchg_rx().

◆ fc_link_ok()

int fc_link_ok ( struct fc_link_state * link)
inlinestatic

Check Fibre Channel link state.

Parameters
linkFibre Channel link state monitor
Return values
link_upLink is up

Definition at line 109 of file fc.h.

109 {
110 return ( link->rc == 0 );
111}
u32 link
Link to next descriptor.
Definition ar9003_mac.h:1

References link.

Referenced by fc_els_plogi_rx(), fc_els_prli_rx(), fc_els_prli_tx(), fc_peer_examine(), fc_peer_login(), fc_peer_logout(), fc_port_close(), fc_port_examine(), fc_port_login(), fc_port_window_changed(), fc_ulp_examine(), fc_ulp_login(), fc_ulp_logout(), fcels_exec(), fcpdev_examine(), fcpdev_identify_device(), fcpdev_window(), fcpeerstat(), and fcportstat().

◆ fc_xchg_originate()

int fc_xchg_originate ( struct interface * parent,
struct fc_port * port,
struct fc_port_id * peer_port_id,
unsigned int type )
extern

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.

729 {
730 struct fc_exchange *xchg;
731
732 /* Allocate and initialise structure */
734 if ( ! xchg )
735 return -ENOMEM;
738
739 DBGC2 ( port, "FCXCHG %s/%04x originating to %s (type %02x)\n",
740 port->name, xchg->xchg_id, fc_id_ntoa ( &xchg->peer_port_id ),
741 xchg->type );
742
743 /* Attach to parent interface and return */
744 intf_plug_plug ( &xchg->ulp, parent );
745 return xchg->xchg_id;
746}
u8 port
Port number.
Definition CIB_PRM.h:3
uint32_t type
Operating system type.
Definition ena.h:1
static struct fc_exchange * fc_xchg_create(struct fc_port *port, struct fc_port_id *peer_port_id, unsigned int type)
Create new Fibre Channel exchange.
Definition fc.c:695
const char * fc_id_ntoa(const struct fc_port_id *id)
Format Fibre Channel port ID.
Definition fc.c:92
@ FC_XCHG_ORIGINATOR
We are the exchange originator.
Definition fc.c:320
@ FC_XCHG_SEQ_FIRST
This is the first sequence of the exchange.
Definition fc.c:324
@ FC_XCHG_SEQ_INITIATIVE
We have the sequence initiative.
Definition fc.c:322
#define DBGC2(...)
Definition compiler.h:547
#define ENOMEM
Not enough space.
Definition errno.h:578
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
A Fibre Channel exchange.
Definition fc.c:287
unsigned int type
Data structure type.
Definition fc.c:298
struct fc_port_id peer_port_id
Peer port ID.
Definition fc.c:296
struct interface ulp
Upper-layer protocol interface.
Definition fc.c:314
unsigned int flags
Flags.
Definition fc.c:300
uint16_t xchg_id
Local exchange ID.
Definition fc.c:302

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_exchange::peer_port_id, port, fc_exchange::type, type, fc_exchange::ulp, and fc_exchange::xchg_id.

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

◆ fc_port_get()

struct fc_port * fc_port_get ( struct fc_port * port)
inlinestatic

Get reference to Fibre Channel port.

Parameters
portFibre Channel port
Return values
portFibre Channel port

Definition at line 305 of file fc.h.

305 {
306 ref_get ( &port->refcnt );
307 return port;
308}
#define ref_get(refcnt)
Get additional reference to object.
Definition refcnt.h:93

References port, and ref_get.

Referenced by fc_els_create(), fc_ns_query(), fc_peer_login(), and fc_xchg_create().

◆ fc_port_put()

void fc_port_put ( struct fc_port * port)
inlinestatic

Drop reference to Fibre Channel port.

Parameters
portFibre Channel port

Definition at line 316 of file fc.h.

316 {
317 ref_put ( &port->refcnt );
318}
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107

References port, and ref_put.

Referenced by fc_els_free(), fc_ns_query_free(), fc_peer_logout(), and fc_xchg_free().

◆ fc_port_login()

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 )
extern

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 942 of file fc.c.

944 {
945 struct fc_peer *peer;
946 struct fc_peer *tmp;
947 int rc;
948
949 /* Perform implicit logout if logged in and details differ */
950 if ( fc_link_ok ( &port->link ) &&
951 ( ( ( !! ( port->flags & FC_PORT_HAS_FABRIC ) ) !=
952 ( !! has_fabric ) ) ||
953 ( memcmp ( &port->link_node_wwn, link_node_wwn,
954 sizeof ( port->link_node_wwn ) ) != 0 ) ||
955 ( memcmp ( &port->link_port_wwn, link_port_wwn,
956 sizeof ( port->link_port_wwn ) ) != 0 ) ||
957 ( has_fabric &&
958 ( memcmp ( &port->port_id, port_id,
959 sizeof ( port->port_id ) ) != 0 ) ) ) ) {
960 fc_port_logout ( port, 0 );
961 }
962
963 /* Log in, if applicable */
964 if ( ! fc_link_ok ( &port->link ) ) {
965
966 /* Record link port name */
967 memcpy ( &port->link_node_wwn, link_node_wwn,
968 sizeof ( port->link_node_wwn ) );
969 memcpy ( &port->link_port_wwn, link_port_wwn,
970 sizeof ( port->link_port_wwn ) );
971 DBGC ( port, "FCPORT %s logged in to %s",
972 port->name, fc_ntoa ( &port->link_node_wwn ) );
973 DBGC ( port, " port %s\n", fc_ntoa ( &port->link_port_wwn ) );
974
975 /* Calculate local (and possibly remote) port IDs */
976 if ( has_fabric ) {
977 port->flags |= FC_PORT_HAS_FABRIC;
978 memcpy ( &port->port_id, port_id,
979 sizeof ( port->port_id ) );
980 } else {
981 port->flags &= ~FC_PORT_HAS_FABRIC;
982 if ( memcmp ( &port->port_wwn, link_port_wwn,
983 sizeof ( port->port_wwn ) ) > 0 ) {
984 memcpy ( &port->port_id, &fc_ptp_high_port_id,
985 sizeof ( port->port_id ) );
986 memcpy ( &port->ptp_link_port_id,
988 sizeof ( port->ptp_link_port_id ) );
989 } else {
990 memcpy ( &port->port_id, &fc_ptp_low_port_id,
991 sizeof ( port->port_id ) );
992 memcpy ( &port->ptp_link_port_id,
994 sizeof ( port->ptp_link_port_id ) );
995 }
996 }
997 DBGC ( port, "FCPORT %s logged in via a %s, with local ID "
998 "%s\n", port->name,
999 ( ( port->flags & FC_PORT_HAS_FABRIC ) ?
1000 "fabric" : "point-to-point link" ),
1001 fc_id_ntoa ( &port->port_id ) );
1002 }
1003
1004 /* Log in to name server, if attached to a fabric */
1005 if ( has_fabric && ! ( port->flags & FC_PORT_HAS_NS ) ) {
1006
1007 DBGC ( port, "FCPORT %s attempting login to name server\n",
1008 port->name );
1009
1010 intf_restart ( &port->ns_plogi, -ECANCELED );
1011 if ( ( rc = fc_els_plogi ( &port->ns_plogi, port,
1012 &fc_gs_port_id ) ) != 0 ) {
1013 DBGC ( port, "FCPORT %s could not initiate name "
1014 "server PLOGI: %s\n",
1015 port->name, strerror ( rc ) );
1016 fc_port_logout ( port, rc );
1017 return rc;
1018 }
1019 }
1020
1021 /* Record login */
1022 fc_link_up ( &port->link );
1023
1024 /* Notify peers of link state change */
1026 fc_peer_get ( peer );
1027 fc_link_examine ( &peer->link );
1028 fc_peer_put ( peer );
1029 }
1030
1031 return 0;
1032}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
struct fc_port_id fc_ptp_high_port_id
Point-to-point high port ID.
Definition fc.c:77
static void fc_link_up(struct fc_link_state *link)
Mark Fibre Channel link as up.
Definition fc.c:195
struct fc_port_id fc_ptp_low_port_id
Point-to-point low port ID.
Definition fc.c:74
const char * fc_ntoa(const struct fc_name *wwn)
Format Fibre Channel WWN.
Definition fc.c:127
struct fc_port_id fc_gs_port_id
Generic services port ID.
Definition fc.c:71
static void fc_link_examine(struct fc_link_state *link)
Examine Fibre Channel link state.
Definition fc.c:226
void fc_port_logout(struct fc_port *port, int rc)
Log out Fibre Channel port.
Definition fc.c:1040
static void fc_peer_put(struct fc_peer *peer)
Drop reference to Fibre Channel peer.
Definition fc.h:391
static struct fc_peer * fc_peer_get(struct fc_peer *peer)
Get reference to Fibre Channel peer.
Definition fc.h:380
struct list_head fc_peers
static int fc_link_ok(struct fc_link_state *link)
Check Fibre Channel link state.
Definition fc.h:109
int fc_els_plogi(struct interface *parent, struct fc_port *port, struct fc_port_id *peer_port_id)
Create PLOGI request.
Definition fcels.c:736
#define DBGC(...)
Definition compiler.h:530
#define ECANCELED
Operation canceled.
Definition errno.h:387
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition interface.c:344
unsigned long tmp
Definition linux_pci.h:65
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition list.h:459
struct mschapv2_challenge peer
Peer challenge.
Definition mschapv2.h:1
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
A Fibre Channel peer.
Definition fc.h:341
struct list_head list
List of all peers.
Definition fc.h:345
struct fc_port_id port_id
Peer port ID, if known.
Definition fc.h:357

References DBGC, ECANCELED, fc_els_plogi(), fc_gs_port_id, 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_ptp_high_port_id, fc_ptp_low_port_id, intf_restart(), fc_peer::list, list_for_each_entry_safe, memcmp(), memcpy(), peer, port, fc_peer::port_id, rc, strerror(), and tmp.

Referenced by fc_els_flogi_rx().

◆ fc_port_logout()

void fc_port_logout ( struct fc_port * port,
int rc )
extern

Log out Fibre Channel port.

Parameters
portFibre Channel port
rcReason for logout

Definition at line 1040 of file fc.c.

1040 {
1041 struct fc_peer *peer;
1042 struct fc_peer *tmp;
1043
1044 DBGC ( port, "FCPORT %s logged out: %s\n",
1045 port->name, strerror ( rc ) );
1046
1047 /* Erase port details */
1048 memset ( &port->port_id, 0, sizeof ( port->port_id ) );
1049 port->flags = 0;
1050
1051 /* Record logout */
1052 fc_link_err ( &port->link, rc );
1053
1054 /* Notify peers of link state change */
1056 fc_peer_get ( peer );
1057 fc_link_examine ( &peer->link );
1058 fc_peer_put ( peer );
1059 }
1060}
static void fc_link_err(struct fc_link_state *link, int rc)
Mark Fibre Channel link as down.
Definition fc.c:210

References DBGC, fc_link_err(), fc_link_examine(), fc_peer_get(), fc_peer_put(), fc_peers, fc_peer::list, list_for_each_entry_safe, memset(), peer, port, rc, strerror(), and tmp.

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

◆ fc_port_open()

int fc_port_open ( struct interface * transport,
const struct fc_name * node_wwn,
const struct fc_name * port_wwn,
const char * name )
extern

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 1190 of file fc.c.

1191 {
1192 struct fc_port *port;
1193
1194 /* Allocate and initialise structure */
1195 port = zalloc ( sizeof ( *port ) );
1196 if ( ! port )
1197 return -ENOMEM;
1198 ref_init ( &port->refcnt, NULL );
1199 intf_init ( &port->transport, &fc_port_transport_desc, &port->refcnt );
1200 fc_link_init ( &port->link, fc_port_examine, &port->refcnt );
1201 intf_init ( &port->flogi, &fc_port_flogi_desc, &port->refcnt );
1202 intf_init ( &port->ns_plogi, &fc_port_ns_plogi_desc, &port->refcnt );
1203 list_add_tail ( &port->list, &fc_ports );
1204 INIT_LIST_HEAD ( &port->xchgs );
1205 memcpy ( &port->node_wwn, node_wwn, sizeof ( port->node_wwn ) );
1206 memcpy ( &port->port_wwn, port_wwn, sizeof ( port->port_wwn ) );
1207 snprintf ( port->name, sizeof ( port->name ), "%s", name );
1208
1209 DBGC ( port, "FCPORT %s opened as %s",
1210 port->name, fc_ntoa ( &port->node_wwn ) );
1211 DBGC ( port, " port %s\n", fc_ntoa ( &port->port_wwn ) );
1212
1213 /* Attach to transport layer, mortalise self, and return */
1214 intf_plug_plug ( &port->transport, transport );
1215 ref_put ( &port->refcnt );
1216 return 0;
1217}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
const char * name
Definition ath9k_hw.c:1986
static void fc_port_examine(struct fc_link_state *link)
Examine Fibre Channel port link state.
Definition fc.c:1102
static struct interface_descriptor fc_port_flogi_desc
Fibre Channel port FLOGI interface descriptor.
Definition fc.c:1169
static struct interface_descriptor fc_port_transport_desc
Fibre Channel port transport interface descriptor.
Definition fc.c:1160
static struct interface_descriptor fc_port_ns_plogi_desc
Fibre Channel port name server PLOGI interface descriptor.
Definition fc.c:1178
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.
Definition fc.c:252
struct list_head fc_ports
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:718
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
A Fibre Channel port.
Definition fc.h:253
struct fc_name node_wwn
Node name.
Definition fc.h:264
struct fc_name port_wwn
Port name.
Definition fc.h:266
struct interface transport
Transport interface.
Definition fc.h:262

References DBGC, ENOMEM, fc_link_init(), fc_ntoa(), fc_port_examine(), fc_port_flogi_desc, fc_port_ns_plogi_desc, fc_port_transport_desc, fc_ports, INIT_LIST_HEAD, intf_init(), intf_plug_plug(), list_add_tail, memcpy(), name, fc_port::node_wwn, NULL, port, fc_port::port_wwn, ref_init, ref_put, snprintf(), fc_port::transport, and zalloc().

Referenced by fcoe_expired().

◆ fc_port_find()

struct fc_port * fc_port_find ( const char * name)
extern

Find Fibre Channel port by name.

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

Definition at line 1225 of file fc.c.

1225 {
1226 struct fc_port *port;
1227
1229 if ( strcmp ( name, port->name ) == 0 )
1230 return port;
1231 }
1232 return NULL;
1233}
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
int strcmp(const char *first, const char *second)
Compare strings.
Definition string.c:174
struct list_head list
List of all ports.
Definition fc.h:257

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

Referenced by parse_fc_port().

◆ fc_peer_get()

struct fc_peer * fc_peer_get ( struct fc_peer * peer)
inlinestatic

Get reference to Fibre Channel peer.

Parameters
peerFibre Channel peer
Return values
peerFibre Channel peer

Definition at line 380 of file fc.h.

380 {
381 ref_get ( &peer->refcnt );
382 return peer;
383}

References peer, and ref_get.

Referenced by fc_ns_query(), fc_peer_get_port_id(), fc_peer_get_wwn(), fc_peer_login(), fc_port_login(), fc_port_logout(), and fc_ulp_create().

◆ fc_peer_put()

void fc_peer_put ( struct fc_peer * peer)
inlinestatic

Drop reference to Fibre Channel peer.

Parameters
peerFibre Channel peer

Definition at line 391 of file fc.h.

391 {
392 ref_put ( &peer->refcnt );
393}

References peer, and ref_put.

Referenced by fc_els_logo_logout(), fc_els_plogi_rx(), fc_ns_query_free(), fc_peer_logout(), fc_port_login(), fc_port_logout(), fc_ulp_free(), fc_ulp_get_port_id_type(), and fc_ulp_get_wwn_type().

◆ fc_peer_get_wwn()

struct fc_peer * fc_peer_get_wwn ( const struct fc_name * port_wwn)
extern

Get Fibre Channel peer by node name.

Parameters
port_wwnNode name
Return values
peerFibre Channel peer, or NULL

Definition at line 1517 of file fc.c.

1517 {
1518 struct fc_peer *peer;
1519
1520 /* Look for an existing peer */
1522 if ( memcmp ( &peer->port_wwn, port_wwn,
1523 sizeof ( peer->port_wwn ) ) == 0 )
1524 return fc_peer_get ( peer );
1525 }
1526
1527 /* Create a new peer */
1529 if ( ! peer )
1530 return NULL;
1531
1532 return peer;
1533}
static struct fc_peer * fc_peer_create(const struct fc_name *port_wwn)
Create Fibre Channel peer.
Definition fc.c:1490
struct fc_name port_wwn
Port name.
Definition fc.h:348

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

Referenced by fc_els_plogi_rx(), and fc_ulp_get_wwn_type().

◆ fc_peer_get_port_id()

struct fc_peer * fc_peer_get_port_id ( struct fc_port * port,
const struct fc_port_id * peer_port_id )
extern

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 1542 of file fc.c.

1543 {
1544 struct fc_peer *peer;
1545
1546 /* Look for an existing peer */
1548 if ( ( peer->port == port ) &&
1549 ( memcmp ( &peer->port_id, peer_port_id,
1550 sizeof ( peer->port_id ) ) == 0 ) )
1551 return fc_peer_get ( peer );
1552 }
1553
1554 /* Cannot create a new peer, since we have no port name to use */
1555 return NULL;
1556}

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

Referenced by fc_els_logo_logout(), and fc_ulp_get_port_id_type().

◆ fc_peer_login()

int fc_peer_login ( struct fc_peer * peer,
struct fc_port * port,
struct fc_port_id * port_id )
extern

Log in Fibre Channel peer.

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

Definition at line 1301 of file fc.c.

1302 {
1303 struct fc_ulp *ulp;
1304 struct fc_ulp *tmp;
1305
1306 /* Perform implicit logout if logged in and details differ */
1307 if ( fc_link_ok ( &peer->link ) &&
1308 ( ( peer->port != port ) ||
1309 ( memcmp ( &peer->port_id, port_id,
1310 sizeof ( peer->port_id ) ) !=0 ) ) ) {
1311 fc_peer_logout ( peer, 0 );
1312 }
1313
1314 /* Log in, if applicable */
1315 if ( ! fc_link_ok ( &peer->link ) ) {
1316
1317 /* Record peer details */
1318 assert ( peer->port == NULL );
1319 peer->port = fc_port_get ( port );
1320 memcpy ( &peer->port_id, port_id, sizeof ( peer->port_id ) );
1321 DBGC ( peer, "FCPEER %s logged in via %s as %s\n",
1322 fc_ntoa ( &peer->port_wwn ), peer->port->name,
1323 fc_id_ntoa ( &peer->port_id ) );
1324
1325 /* Add login reference */
1326 fc_peer_get ( peer );
1327 }
1328
1329 /* Record login */
1330 fc_link_up ( &peer->link );
1331
1332 /* Notify ULPs of link state change */
1333 list_for_each_entry_safe ( ulp, tmp, &peer->ulps, list ) {
1334 fc_ulp_get ( ulp );
1335 fc_link_examine ( &ulp->link );
1336 fc_ulp_put ( ulp );
1337 }
1338
1339 return 0;
1340}
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:61
void fc_peer_logout(struct fc_peer *peer, int rc)
Log out Fibre Channel peer.
Definition fc.c:1348
static struct fc_ulp * fc_ulp_get(struct fc_ulp *ulp)
Get reference to Fibre Channel upper-layer protocol.
Definition fc.h:475
static void fc_ulp_put(struct fc_ulp *ulp)
Drop reference to Fibre Channel upper-layer protocol.
Definition fc.h:486
static struct fc_port * fc_port_get(struct fc_port *port)
Get reference to Fibre Channel port.
Definition fc.h:305
A Fibre Channel upper-layer protocol.
Definition fc.h:414
struct fc_link_state link
Link state monitor.
Definition fc.h:428
struct list_head list
List of upper-layer protocols.
Definition fc.h:420

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_ulp::link, fc_ulp::list, list_for_each_entry_safe, memcmp(), memcpy(), NULL, peer, port, and tmp.

Referenced by fc_els_plogi_rx().

◆ fc_peer_logout()

void fc_peer_logout ( struct fc_peer * peer,
int rc )
extern

Log out Fibre Channel peer.

Parameters
peerFibre Channel peer
rcReason for logout

Definition at line 1348 of file fc.c.

1348 {
1349 struct fc_ulp *ulp;
1350 struct fc_ulp *tmp;
1351
1352 DBGC ( peer, "FCPEER %s logged out: %s\n",
1353 fc_ntoa ( &peer->port_wwn ), strerror ( rc ) );
1354
1355 /* Drop login reference, if applicable */
1356 if ( fc_link_ok ( &peer->link ) )
1357 fc_peer_put ( peer );
1358
1359 /* Erase peer details */
1360 fc_port_put ( peer->port );
1361 peer->port = NULL;
1362
1363 /* Record logout */
1364 fc_link_err ( &peer->link, rc );
1365
1366 /* Notify ULPs of link state change */
1367 list_for_each_entry_safe ( ulp, tmp, &peer->ulps, list ) {
1368 fc_ulp_get ( ulp );
1369 fc_link_examine ( &ulp->link );
1370 fc_ulp_put ( ulp );
1371 }
1372
1373 /* Close peer if there are no active users */
1374 if ( peer->usage == 0 )
1375 fc_peer_close ( peer, rc );
1376}
static void fc_peer_close(struct fc_peer *peer, int rc)
Close Fibre Channel peer.
Definition fc.c:1248
static void fc_port_put(struct fc_port *port)
Drop reference to Fibre Channel port.
Definition fc.h:316

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_ulp::link, fc_ulp::list, list_for_each_entry_safe, NULL, peer, rc, strerror(), and tmp.

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

◆ fc_ulp_get()

struct fc_ulp * fc_ulp_get ( struct fc_ulp * ulp)
inlinestatic

Get reference to Fibre Channel upper-layer protocol.

Parameters
ulpFibre Channel upper-layer protocol
Return values
ulpFibre Channel upper-layer protocol

Definition at line 475 of file fc.h.

475 {
476 ref_get ( &ulp->refcnt );
477 return ulp;
478}
struct refcnt refcnt
Reference count.
Definition fc.h:416

References ref_get, and fc_ulp::refcnt.

Referenced by fc_peer_login(), fc_peer_logout(), fc_ulp_attach(), fc_ulp_get_type(), and fc_ulp_login().

◆ fc_ulp_put()

void fc_ulp_put ( struct fc_ulp * ulp)
inlinestatic

Drop reference to Fibre Channel upper-layer protocol.

Parameters
ulpFibre Channel upper-layer protocol

Definition at line 486 of file fc.h.

486 {
487 ref_put ( &ulp->refcnt );
488}

References ref_put, and fc_ulp::refcnt.

Referenced by fc_els_prli_rx(), fc_els_prli_tx(), fc_peer_login(), fc_peer_logout(), fc_ulp_detach(), fc_ulp_get_port_id_type(), fc_ulp_get_wwn_type(), fc_ulp_logout(), and fcpdev_open().

◆ fc_ulp_user_get()

struct fc_ulp_user * fc_ulp_user_get ( struct fc_ulp_user * user)
inlinestatic

Get reference to Fibre Channel upper-layer protocol user.

Parameters
userFibre Channel upper-layer protocol user
Return values
userFibre Channel upper-layer protocol user

Definition at line 497 of file fc.h.

497 {
498 ref_get ( user->refcnt );
499 return user;
500}
struct refcnt * refcnt
Containing object reference count, or NULL.
Definition fc.h:460

References ref_get, and fc_ulp_user::refcnt.

Referenced by fc_ulp_login(), and fc_ulp_logout().

◆ fc_ulp_user_put()

void fc_ulp_user_put ( struct fc_ulp_user * user)
inlinestatic

Drop reference to Fibre Channel upper-layer protocol user.

Parameters
userFibre Channel upper-layer protocol user

Definition at line 508 of file fc.h.

508 {
509 ref_put ( user->refcnt );
510}

References ref_put, and fc_ulp_user::refcnt.

Referenced by fc_ulp_login(), and fc_ulp_logout().

◆ fc_ulp_user_init()

void fc_ulp_user_init ( struct fc_ulp_user * user,
void(* examine )(struct fc_ulp_user *user),
struct refcnt * refcnt )
inlinestatic

Initialise Fibre Channel upper-layer protocol user.

Parameters
userFibre Channel upper-layer protocol user
examineExamine link state method
refcntContaining object reference count, or NULL

Definition at line 520 of file fc.h.

522 {
523 user->examine = examine;
524 user->refcnt = refcnt;
525}
void(* examine)(struct fc_ulp_user *user)
Examine link state.
Definition fc.h:465
A reference counter.
Definition refcnt.h:27

References fc_ulp_user::examine, and fc_ulp_user::refcnt.

Referenced by fcpdev_open().

◆ fc_ulp_get_wwn_type()

struct fc_ulp * fc_ulp_get_wwn_type ( const struct fc_name * port_wwn,
unsigned int type )
extern

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 1881 of file fc.c.

1882 {
1883 struct fc_ulp *ulp;
1884 struct fc_peer *peer;
1885
1886 /* Get peer */
1888 if ( ! peer )
1889 goto err_peer_get_wwn;
1890
1891 /* Get ULP */
1892 ulp = fc_ulp_get_type ( peer, type );
1893 if ( ! ulp )
1894 goto err_ulp_get_type;
1895
1896 /* Drop temporary reference to peer */
1897 fc_peer_put ( peer );
1898
1899 return ulp;
1900
1901 fc_ulp_put ( ulp );
1902 err_ulp_get_type:
1903 fc_peer_put ( peer );
1904 err_peer_get_wwn:
1905 return NULL;
1906}
struct fc_peer * fc_peer_get_wwn(const struct fc_name *port_wwn)
Get Fibre Channel peer by node name.
Definition fc.c:1517
static struct fc_ulp * fc_ulp_get_type(struct fc_peer *peer, unsigned int type)
Get Fibre Channel upper-layer protocol by peer and type.
Definition fc.c:1856

References fc_peer_get_wwn(), fc_peer_put(), fc_ulp_get_type(), fc_ulp_put(), NULL, peer, fc_peer::port_wwn, and type.

Referenced by fcpdev_open().

◆ fc_ulp_get_port_id_type()

struct fc_ulp * fc_ulp_get_port_id_type ( struct fc_port * port,
const struct fc_port_id * peer_port_id,
unsigned int type )
extern

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 1916 of file fc.c.

1918 {
1919 struct fc_ulp *ulp;
1920 struct fc_peer *peer;
1921
1922 /* Get peer */
1923 peer = fc_peer_get_port_id ( port, peer_port_id );
1924 if ( ! peer )
1925 goto err_peer_get_wwn;
1926
1927 /* Get ULP */
1928 ulp = fc_ulp_get_type ( peer, type );
1929 if ( ! ulp )
1930 goto err_ulp_get_type;
1931
1932 /* Drop temporary reference to peer */
1933 fc_peer_put ( peer );
1934
1935 return ulp;
1936
1937 fc_ulp_put ( ulp );
1938 err_ulp_get_type:
1939 fc_peer_put ( peer );
1940 err_peer_get_wwn:
1941 return NULL;
1942}
struct fc_peer * fc_peer_get_port_id(struct fc_port *port, const struct fc_port_id *peer_port_id)
Get Fibre Channel peer by port ID.
Definition fc.c:1542

References fc_peer_get_port_id(), fc_peer_put(), fc_ulp_get_type(), fc_ulp_put(), NULL, peer, port, and type.

Referenced by fc_els_prli_rx(), and fc_els_prli_tx().

◆ fc_ulp_attach()

void fc_ulp_attach ( struct fc_ulp * ulp,
struct fc_ulp_user * user )
extern

Attach Fibre Channel upper-layer protocol user.

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

Definition at line 1608 of file fc.c.

1608 {
1609
1610 /* Sanity check */
1611 assert ( user->ulp == NULL );
1612
1613 /* Increment peer's usage count */
1614 fc_peer_increment ( ulp->peer );
1615
1616 /* Attach user */
1617 user->ulp = fc_ulp_get ( ulp );
1618 list_add ( &user->list, &ulp->users );
1619}
static void fc_peer_increment(struct fc_peer *peer)
Increment Fibre Channel peer active usage count.
Definition fc.c:1272
#define list_add(new, head)
Add a new entry to the head of a list.
Definition list.h:70
struct list_head list
List of users.
Definition fc.h:458
struct fc_ulp * ulp
Fibre Channel upper layer protocol.
Definition fc.h:456
struct fc_peer * peer
Fibre Channel peer.
Definition fc.h:418
struct list_head users
Active users of this upper-layer protocol.
Definition fc.h:444

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().

◆ fc_ulp_detach()

void fc_ulp_detach ( struct fc_ulp_user * user)
extern

Detach Fibre Channel upper-layer protocol user.

Parameters
userFibre Channel upper-layer protocol user

Definition at line 1626 of file fc.c.

1626 {
1627 struct fc_ulp *ulp = user->ulp;
1628
1629 /* Do nothing if not attached */
1630 if ( ! ulp )
1631 return;
1632
1633 /* Sanity checks */
1634 list_check_contains_entry ( user, &ulp->users, list );
1635
1636 /* Detach user and log out if no users remain */
1637 list_del ( &user->list );
1638 if ( list_empty ( &ulp->users ) )
1639 fc_ulp_logout ( ulp, 0 );
1640
1641 /* Decrement our peer's usage count */
1642 fc_peer_decrement ( ulp->peer );
1643
1644 /* Drop reference */
1645 user->ulp = NULL;
1646 fc_ulp_put ( ulp );
1647}
static void fc_peer_decrement(struct fc_peer *peer)
Decrement Fibre Channel peer active usage count.
Definition fc.c:1283
void fc_ulp_logout(struct fc_ulp *ulp, int rc)
Log out Fibre Channel upper-layer protocol.
Definition fc.c:1728
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define list_empty(list)
Test whether a list is empty.
Definition list.h:137
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition list.h:550

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().

◆ fc_ulp_login()

int fc_ulp_login ( struct fc_ulp * ulp,
const void * param,
size_t param_len,
int originated )
extern

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 1658 of file fc.c.

1659 {
1660 struct fc_ulp_user *user;
1661 struct fc_ulp_user *tmp;
1662
1663 /* Perform implicit logout if logged in and service parameters differ */
1664 if ( fc_link_ok ( &ulp->link ) &&
1665 ( ( ulp->param_len != param_len ) ||
1666 ( memcmp ( ulp->param, param, ulp->param_len ) != 0 ) ) ) {
1667 fc_ulp_logout ( ulp, 0 );
1668 }
1669
1670 /* Work around a bug in some versions of the Linux Fibre
1671 * Channel stack, which fail to fully initialise image pairs
1672 * established via a PRLI originated by the Linux stack
1673 * itself.
1674 */
1675 if ( originated )
1677 if ( ! ( ulp->flags & FC_ULP_ORIGINATED_LOGIN_OK ) ) {
1678 DBGC ( ulp, "FCULP %s/%02x sending extra PRLI to work around "
1679 "Linux bug\n",
1680 fc_ntoa ( &ulp->peer->port_wwn ), ulp->type );
1681 fc_link_stop ( &ulp->link );
1682 fc_link_start ( &ulp->link );
1683 return 0;
1684 }
1685
1686 /* Log in, if applicable */
1687 if ( ! fc_link_ok ( &ulp->link ) ) {
1688
1689 /* Record service parameters */
1690 assert ( ulp->param == NULL );
1691 assert ( ulp->param_len == 0 );
1692 ulp->param = malloc ( param_len );
1693 if ( ! ulp->param ) {
1694 DBGC ( ulp, "FCULP %s/%02x could not record "
1695 "parameters\n",
1696 fc_ntoa ( &ulp->peer->port_wwn ), ulp->type );
1697 return -ENOMEM;
1698 }
1699 memcpy ( ulp->param, param, param_len );
1700 ulp->param_len = param_len;
1701 DBGC ( ulp, "FCULP %s/%02x logged in with parameters:\n",
1702 fc_ntoa ( &ulp->peer->port_wwn ), ulp->type );
1703 DBGC_HDA ( ulp, 0, ulp->param, ulp->param_len );
1704
1705 /* Add login reference */
1706 fc_ulp_get ( ulp );
1707 }
1708
1709 /* Record login */
1710 fc_link_up ( &ulp->link );
1711
1712 /* Notify users of link state change */
1713 list_for_each_entry_safe ( user, tmp, &ulp->users, list ) {
1714 fc_ulp_user_get ( user );
1715 user->examine ( user );
1716 fc_ulp_user_put ( user );
1717 }
1718
1719 return 0;
1720}
static void fc_link_start(struct fc_link_state *link)
Start monitoring Fibre Channel link state.
Definition fc.c:266
static void fc_link_stop(struct fc_link_state *link)
Stop monitoring Fibre Channel link state.
Definition fc.c:275
static void fc_ulp_user_put(struct fc_ulp_user *user)
Drop reference to Fibre Channel upper-layer protocol user.
Definition fc.h:508
static struct fc_ulp_user * fc_ulp_user_get(struct fc_ulp_user *user)
Get reference to Fibre Channel upper-layer protocol user.
Definition fc.h:497
#define DBGC_HDA(...)
Definition compiler.h:531
struct hv_monitor_parameter param[4][32]
Parameters.
Definition hyperv.h:13
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:677
A Fibre Channel upper-layer protocol user.
Definition fc.h:454
unsigned int type
Type.
Definition fc.h:423
unsigned int flags
Flags.
Definition fc.h:425
size_t param_len
Service parameter length.
Definition fc.h:434
void * param
Service parameters, if any.
Definition fc.h:432

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, param, fc_ulp::param_len, fc_ulp::peer, fc_peer::port_wwn, tmp, fc_ulp::type, fc_ulp_user::ulp, and fc_ulp::users.

Referenced by fc_els_prli_rx().

◆ fc_ulp_logout()

void fc_ulp_logout ( struct fc_ulp * ulp,
int rc )
extern

Log out Fibre Channel upper-layer protocol.

Parameters
ulpFibre Channel upper-layer protocol
rcReason for logout

Definition at line 1728 of file fc.c.

1728 {
1729 struct fc_ulp_user *user;
1730 struct fc_ulp_user *tmp;
1731
1732 DBGC ( ulp, "FCULP %s/%02x logged out: %s\n",
1733 fc_ntoa ( &ulp->peer->port_wwn ), ulp->type, strerror ( rc ) );
1734
1735 /* Drop login reference, if applicable */
1736 if ( fc_link_ok ( &ulp->link ) )
1737 fc_ulp_put ( ulp );
1738
1739 /* Discard service parameters */
1740 free ( ulp->param );
1741 ulp->param = NULL;
1742 ulp->param_len = 0;
1743 ulp->flags = 0;
1744
1745 /* Record logout */
1746 fc_link_err ( &ulp->link, rc );
1747
1748 /* Notify users of link state change */
1749 list_for_each_entry_safe ( user, tmp, &ulp->users, list ) {
1750 fc_ulp_user_get ( user );
1751 user->examine ( user );
1752 fc_ulp_user_put ( user );
1753 }
1754
1755 /* Close ULP if there are no clients attached */
1756 if ( list_empty ( &ulp->users ) )
1757 fc_ulp_close ( ulp, rc );
1758}
static void fc_ulp_close(struct fc_ulp *ulp, int rc)
Close Fibre Channel upper-layer protocol.
Definition fc.c:1583
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55

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, rc, strerror(), tmp, fc_ulp::type, fc_ulp_user::ulp, and fc_ulp::users.

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

Variable Documentation

◆ fc_empty_port_id

struct fc_port_id fc_empty_port_id
extern

Unassigned port ID.

Definition at line 65 of file fc.c.

65{ .bytes = { 0x00, 0x00, 0x00 } };

Referenced by fc_port_deliver(), and fcels_exec().

◆ fc_f_port_id

struct fc_port_id fc_f_port_id
extern

F_Port contoller port ID.

Definition at line 68 of file fc.c.

68{ .bytes = { 0xff, 0xff, 0xfe } };

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

◆ fc_gs_port_id

struct fc_port_id fc_gs_port_id
extern

Generic services port ID.

Definition at line 71 of file fc.c.

71{ .bytes = { 0xff, 0xff, 0xfc } };

Referenced by fc_ns_query_step(), and fc_port_login().

◆ fc_ptp_low_port_id

struct fc_port_id fc_ptp_low_port_id
extern

Point-to-point low port ID.

Definition at line 74 of file fc.c.

74{ .bytes = { 0x01, 0x01, 0x01 } };

Referenced by fc_port_login().

◆ fc_ptp_high_port_id

struct fc_port_id fc_ptp_high_port_id
extern

Point-to-point high port ID.

Definition at line 77 of file fc.c.

77{ .bytes = { 0x01, 0x01, 0x02 } };

Referenced by fc_port_login().

◆ fc_ports

◆ fc_peers