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:429
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition string.c:485

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:522
#define ENOMEM
Not enough space.
Definition errno.h:535
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 941 of file fc.c.

943 {
944 struct fc_peer *peer;
945 struct fc_peer *tmp;
946 int rc;
947
948 /* Perform implicit logout if logged in and details differ */
949 if ( fc_link_ok ( &port->link ) &&
950 ( ( ( !! ( port->flags & FC_PORT_HAS_FABRIC ) ) !=
951 ( !! has_fabric ) ) ||
952 ( memcmp ( &port->link_node_wwn, link_node_wwn,
953 sizeof ( port->link_node_wwn ) ) != 0 ) ||
954 ( memcmp ( &port->link_port_wwn, link_port_wwn,
955 sizeof ( port->link_port_wwn ) ) != 0 ) ||
956 ( has_fabric &&
957 ( memcmp ( &port->port_id, port_id,
958 sizeof ( port->port_id ) ) != 0 ) ) ) ) {
959 fc_port_logout ( port, 0 );
960 }
961
962 /* Log in, if applicable */
963 if ( ! fc_link_ok ( &port->link ) ) {
964
965 /* Record link port name */
966 memcpy ( &port->link_node_wwn, link_node_wwn,
967 sizeof ( port->link_node_wwn ) );
968 memcpy ( &port->link_port_wwn, link_port_wwn,
969 sizeof ( port->link_port_wwn ) );
970 DBGC ( port, "FCPORT %s logged in to %s",
971 port->name, fc_ntoa ( &port->link_node_wwn ) );
972 DBGC ( port, " port %s\n", fc_ntoa ( &port->link_port_wwn ) );
973
974 /* Calculate local (and possibly remote) port IDs */
975 if ( has_fabric ) {
976 port->flags |= FC_PORT_HAS_FABRIC;
977 memcpy ( &port->port_id, port_id,
978 sizeof ( port->port_id ) );
979 } else {
980 port->flags &= ~FC_PORT_HAS_FABRIC;
981 if ( memcmp ( &port->port_wwn, link_port_wwn,
982 sizeof ( port->port_wwn ) ) > 0 ) {
983 memcpy ( &port->port_id, &fc_ptp_high_port_id,
984 sizeof ( port->port_id ) );
985 memcpy ( &port->ptp_link_port_id,
987 sizeof ( port->ptp_link_port_id ) );
988 } else {
989 memcpy ( &port->port_id, &fc_ptp_low_port_id,
990 sizeof ( port->port_id ) );
991 memcpy ( &port->ptp_link_port_id,
993 sizeof ( port->ptp_link_port_id ) );
994 }
995 }
996 DBGC ( port, "FCPORT %s logged in via a %s, with local ID "
997 "%s\n", port->name,
998 ( ( port->flags & FC_PORT_HAS_FABRIC ) ?
999 "fabric" : "point-to-point link" ),
1000 fc_id_ntoa ( &port->port_id ) );
1001 }
1002
1003 /* Log in to name server, if attached to a fabric */
1004 if ( has_fabric && ! ( port->flags & FC_PORT_HAS_NS ) ) {
1005
1006 DBGC ( port, "FCPORT %s attempting login to name server\n",
1007 port->name );
1008
1009 intf_restart ( &port->ns_plogi, -ECANCELED );
1010 if ( ( rc = fc_els_plogi ( &port->ns_plogi, port,
1011 &fc_gs_port_id ) ) != 0 ) {
1012 DBGC ( port, "FCPORT %s could not initiate name "
1013 "server PLOGI: %s\n",
1014 port->name, strerror ( rc ) );
1015 fc_port_logout ( port, rc );
1016 return rc;
1017 }
1018 }
1019
1020 /* Record login */
1021 fc_link_up ( &port->link );
1022
1023 /* Notify peers of link state change */
1025 fc_peer_get ( peer );
1026 fc_link_examine ( &peer->link );
1027 fc_peer_put ( peer );
1028 }
1029
1030 return 0;
1031}
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:1039
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:733
#define DBGC(...)
Definition compiler.h:505
#define ECANCELED
Operation canceled.
Definition errno.h:344
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 1039 of file fc.c.

1039 {
1040 struct fc_peer *peer;
1041 struct fc_peer *tmp;
1042
1043 DBGC ( port, "FCPORT %s logged out: %s\n",
1044 port->name, strerror ( rc ) );
1045
1046 /* Erase port details */
1047 memset ( &port->port_id, 0, sizeof ( port->port_id ) );
1048 port->flags = 0;
1049
1050 /* Record logout */
1051 fc_link_err ( &port->link, rc );
1052
1053 /* Notify peers of link state change */
1055 fc_peer_get ( peer );
1056 fc_link_examine ( &peer->link );
1057 fc_peer_put ( peer );
1058 }
1059}
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 1189 of file fc.c.

1190 {
1191 struct fc_port *port;
1192
1193 /* Allocate and initialise structure */
1194 port = zalloc ( sizeof ( *port ) );
1195 if ( ! port )
1196 return -ENOMEM;
1197 ref_init ( &port->refcnt, NULL );
1198 intf_init ( &port->transport, &fc_port_transport_desc, &port->refcnt );
1199 fc_link_init ( &port->link, fc_port_examine, &port->refcnt );
1200 intf_init ( &port->flogi, &fc_port_flogi_desc, &port->refcnt );
1201 intf_init ( &port->ns_plogi, &fc_port_ns_plogi_desc, &port->refcnt );
1202 list_add_tail ( &port->list, &fc_ports );
1203 INIT_LIST_HEAD ( &port->xchgs );
1204 memcpy ( &port->node_wwn, node_wwn, sizeof ( port->node_wwn ) );
1205 memcpy ( &port->port_wwn, port_wwn, sizeof ( port->port_wwn ) );
1206 snprintf ( port->name, sizeof ( port->name ), "%s", name );
1207
1208 DBGC ( port, "FCPORT %s opened as %s",
1209 port->name, fc_ntoa ( &port->node_wwn ) );
1210 DBGC ( port, " port %s\n", fc_ntoa ( &port->port_wwn ) );
1211
1212 /* Attach to transport layer, mortalise self, and return */
1213 intf_plug_plug ( &port->transport, transport );
1214 ref_put ( &port->refcnt );
1215 return 0;
1216}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
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:1101
static struct interface_descriptor fc_port_flogi_desc
Fibre Channel port FLOGI interface descriptor.
Definition fc.c:1168
static struct interface_descriptor fc_port_transport_desc
Fibre Channel port transport interface descriptor.
Definition fc.c:1159
static struct interface_descriptor fc_port_ns_plogi_desc
Fibre Channel port name server PLOGI interface descriptor.
Definition fc.c:1177
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:662
#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 1224 of file fc.c.

1224 {
1225 struct fc_port *port;
1226
1228 if ( strcmp ( name, port->name ) == 0 )
1229 return port;
1230 }
1231 return NULL;
1232}
#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 1516 of file fc.c.

1516 {
1517 struct fc_peer *peer;
1518
1519 /* Look for an existing peer */
1521 if ( memcmp ( &peer->port_wwn, port_wwn,
1522 sizeof ( peer->port_wwn ) ) == 0 )
1523 return fc_peer_get ( peer );
1524 }
1525
1526 /* Create a new peer */
1528 if ( ! peer )
1529 return NULL;
1530
1531 return peer;
1532}
static struct fc_peer * fc_peer_create(const struct fc_name *port_wwn)
Create Fibre Channel peer.
Definition fc.c:1489
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 1541 of file fc.c.

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

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

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

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

1881 {
1882 struct fc_ulp *ulp;
1883 struct fc_peer *peer;
1884
1885 /* Get peer */
1887 if ( ! peer )
1888 goto err_peer_get_wwn;
1889
1890 /* Get ULP */
1891 ulp = fc_ulp_get_type ( peer, type );
1892 if ( ! ulp )
1893 goto err_ulp_get_type;
1894
1895 /* Drop temporary reference to peer */
1896 fc_peer_put ( peer );
1897
1898 return ulp;
1899
1900 fc_ulp_put ( ulp );
1901 err_ulp_get_type:
1902 fc_peer_put ( peer );
1903 err_peer_get_wwn:
1904 return NULL;
1905}
struct fc_peer * fc_peer_get_wwn(const struct fc_name *port_wwn)
Get Fibre Channel peer by node name.
Definition fc.c:1516
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:1855

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

1917 {
1918 struct fc_ulp *ulp;
1919 struct fc_peer *peer;
1920
1921 /* Get peer */
1922 peer = fc_peer_get_port_id ( port, peer_port_id );
1923 if ( ! peer )
1924 goto err_peer_get_wwn;
1925
1926 /* Get ULP */
1927 ulp = fc_ulp_get_type ( peer, type );
1928 if ( ! ulp )
1929 goto err_ulp_get_type;
1930
1931 /* Drop temporary reference to peer */
1932 fc_peer_put ( peer );
1933
1934 return ulp;
1935
1936 fc_ulp_put ( ulp );
1937 err_ulp_get_type:
1938 fc_peer_put ( peer );
1939 err_peer_get_wwn:
1940 return NULL;
1941}
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:1541

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

1607 {
1608
1609 /* Sanity check */
1610 assert ( user->ulp == NULL );
1611
1612 /* Increment peer's usage count */
1613 fc_peer_increment ( ulp->peer );
1614
1615 /* Attach user */
1616 user->ulp = fc_ulp_get ( ulp );
1617 list_add ( &user->list, &ulp->users );
1618}
static void fc_peer_increment(struct fc_peer *peer)
Increment Fibre Channel peer active usage count.
Definition fc.c:1271
#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 1625 of file fc.c.

1625 {
1626 struct fc_ulp *ulp = user->ulp;
1627
1628 /* Do nothing if not attached */
1629 if ( ! ulp )
1630 return;
1631
1632 /* Sanity checks */
1633 list_check_contains_entry ( user, &ulp->users, list );
1634
1635 /* Detach user and log out if no users remain */
1636 list_del ( &user->list );
1637 if ( list_empty ( &ulp->users ) )
1638 fc_ulp_logout ( ulp, 0 );
1639
1640 /* Decrement our peer's usage count */
1641 fc_peer_decrement ( ulp->peer );
1642
1643 /* Drop reference */
1644 user->ulp = NULL;
1645 fc_ulp_put ( ulp );
1646}
static void fc_peer_decrement(struct fc_peer *peer)
Decrement Fibre Channel peer active usage count.
Definition fc.c:1282
void fc_ulp_logout(struct fc_ulp *ulp, int rc)
Log out Fibre Channel upper-layer protocol.
Definition fc.c:1727
#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 1657 of file fc.c.

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

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