iPXE
fip.h
Go to the documentation of this file.
00001 #ifndef _IPXE_FIP_H
00002 #define _IPXE_FIP_H
00003 
00004 /*
00005  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020  * 02110-1301, USA.
00021  */
00022 
00023 #include <stdint.h>
00024 #include <ipxe/fc.h>
00025 #include <ipxe/fcels.h>
00026 #include <ipxe/fcoe.h>
00027 
00028 /** A FIP frame header */
00029 struct fip_header {
00030         /** Frame version */
00031         uint8_t version;
00032         /** Reserved */
00033         uint8_t reserved_a;
00034         /** Protocol code */
00035         uint16_t code;
00036         /** Reserved */
00037         uint8_t reserved_b;
00038         /** Subcode */
00039         uint8_t subcode;
00040         /** Descriptor list length in 32-bit words */
00041         uint16_t len;
00042         /** Flags */
00043         uint16_t flags;
00044 } __attribute__ (( packed ));
00045 
00046 /** FIP frame version */
00047 #define FIP_VERSION 0x10
00048 
00049 /** FIP protocol code */
00050 enum fip_code {
00051         FIP_CODE_DISCOVERY = 0x0001,    /**< Discovery */
00052         FIP_CODE_ELS = 0x0002,          /**< Extended link services */
00053         FIP_CODE_MAINTAIN = 0x0003,     /**< Maintain virtual links */
00054         FIP_CODE_VLAN = 0x0004,         /**< VLAN */
00055 };
00056 
00057 /** FIP protocol subcode for discovery */
00058 enum fip_discovery_subcode {
00059         FIP_DISCOVERY_SOLICIT = 0x01,   /**< Discovery solicitation */
00060         FIP_DISCOVERY_ADVERTISE = 0x02, /**< Discovery advertisement */
00061 };
00062 
00063 /** FIP protocol subcode for extended link services */
00064 enum fip_els_subcode {
00065         FIP_ELS_REQUEST = 0x01,         /**< ELS request */
00066         FIP_ELS_RESPONSE = 0x02,        /**< ELS response */
00067 };
00068 
00069 /** FIP protocol subcode for keep alive / clear links */
00070 enum fip_vitality_subcode {
00071         FIP_MAINTAIN_KEEP_ALIVE = 0x01, /**< Keep alive */
00072         FIP_MAINTAIN_CLEAR_LINKS = 0x02,/**< Clear virtual links */
00073 };
00074 
00075 /** FIP protocol subcode for VLAN */
00076 enum fip_vlan_subcode {
00077         FIP_VLAN_REQUEST = 0x01,        /**< VLAN request */
00078         FIP_VLAN_NOTIFY = 0x02,         /**< VLAN notification */
00079 };
00080 
00081 /** FIP flags */
00082 enum fip_flags {
00083         FIP_FP  = 0x8000,               /**< Fabric-provided MAC address */
00084         FIP_SP  = 0x4000,               /**< Server-provided MAC address */
00085         FIP_A   = 0x0004,               /**< Available for login */
00086         FIP_S   = 0x0002,               /**< Solicited */
00087         FIP_F   = 0x0001,               /**< Forwarder */
00088 };
00089 
00090 /** FIP descriptor common fields */
00091 struct fip_common {
00092         /** Type */
00093         uint8_t type;
00094         /** Length in 32-bit words */
00095         uint8_t len;
00096         /** Reserved */
00097         uint8_t reserved[2];
00098 } __attribute__ (( packed ));
00099 
00100 /** FIP descriptor types */
00101 enum fip_type {
00102         FIP_RESERVED = 0x00,            /**< Reserved */
00103         FIP_PRIORITY = 0x01,            /**< Priority */
00104         FIP_MAC_ADDRESS = 0x02,         /**< MAC address */
00105         FIP_FC_MAP = 0x03,              /**< FC-MAP */
00106         FIP_NAME_ID = 0x04,             /**< Name identifier */
00107         FIP_FABRIC = 0x05,              /**< Fabric */
00108         FIP_MAX_FCOE_SIZE = 0x06,       /**< Max FCoE size */
00109         FIP_FLOGI = 0x07,               /**< FLOGI */
00110         FIP_NPIV_FDISC = 0x08,          /**< NPIV FDISC */
00111         FIP_LOGO = 0x09,                /**< LOGO */
00112         FIP_ELP = 0x0a,                 /**< ELP */
00113         FIP_VX_PORT_ID = 0x0b,          /**< Vx port identification */
00114         FIP_FKA_ADV_P = 0x0c,           /**< FKA ADV period */
00115         FIP_VENDOR_ID = 0x0d,           /**< Vendor ID */
00116         FIP_VLAN = 0x0e,                /**< VLAN */
00117         FIP_NUM_DESCRIPTOR_TYPES
00118 };
00119 
00120 /** FIP descriptor type is critical */
00121 #define FIP_IS_CRITICAL( type ) ( (type) <= 0x7f )
00122 
00123 /** A FIP priority descriptor */
00124 struct fip_priority {
00125         /** Type */
00126         uint8_t type;
00127         /** Length in 32-bit words */
00128         uint8_t len;
00129         /** Reserved */
00130         uint8_t reserved;
00131         /** Priority
00132          *
00133          * A higher value indicates a lower priority.
00134          */
00135         uint8_t priority;
00136 } __attribute__ (( packed ));
00137 
00138 /** Default FIP priority */
00139 #define FIP_DEFAULT_PRIORITY 128
00140 
00141 /** Lowest FIP priority */
00142 #define FIP_LOWEST_PRIORITY 255
00143 
00144 /** A FIP MAC address descriptor */
00145 struct fip_mac_address {
00146         /** Type */
00147         uint8_t type;
00148         /** Length in 32-bit words */
00149         uint8_t len;
00150         /** MAC address */
00151         uint8_t mac[ETH_ALEN];
00152 } __attribute__ (( packed ));
00153 
00154 /** A FIP FC-MAP descriptor */
00155 struct fip_fc_map {
00156         /** Type */
00157         uint8_t type;
00158         /** Length in 32-bit words */
00159         uint8_t len;
00160         /** Reserved */
00161         uint8_t reserved[3];
00162         /** FC-MAP */
00163         struct fcoe_map map;
00164 } __attribute__ (( packed ));
00165 
00166 /** A FIP name identifier descriptor */
00167 struct fip_name_id {
00168         /** Type */
00169         uint8_t type;
00170         /** Length in 32-bit words */
00171         uint8_t len;
00172         /** Reserved */
00173         uint8_t reserved[2];
00174         /** Name identifier */
00175         struct fc_name name;
00176 } __attribute__ (( packed ));
00177 
00178 /** A FIP fabric descriptor */
00179 struct fip_fabric {
00180         /** Type */
00181         uint8_t type;
00182         /** Length in 32-bit words */
00183         uint8_t len;
00184         /** Virtual Fabric ID, if any */
00185         uint16_t vf_id;
00186         /** Reserved */
00187         uint8_t reserved;
00188         /** FC-MAP */
00189         struct fcoe_map map;
00190         /** Fabric name */
00191         struct fc_name name;
00192 } __attribute__ (( packed ));
00193 
00194 /** A FIP max FCoE size descriptor */
00195 struct fip_max_fcoe_size {
00196         /** Type */
00197         uint8_t type;
00198         /** Length in 32-bit words */
00199         uint8_t len;
00200         /** Maximum FCoE size */
00201         uint16_t mtu;
00202 } __attribute__ (( packed ));
00203 
00204 /** A FIP descriptor containing an encapsulated ELS frame */
00205 struct fip_els {
00206         /** Type */
00207         uint8_t type;
00208         /** Length in 32-bit words */
00209         uint8_t len;
00210         /** Reserved */
00211         uint8_t reserved[2];
00212         /** Fibre Channel frame header */
00213         struct fc_frame_header fc;
00214         /** ELS frame */
00215         struct fc_els_frame_common els;
00216 } __attribute__ (( packed ));
00217 
00218 /** A FIP descriptor containing an encapsulated login frame */
00219 struct fip_login {
00220         /** Type */
00221         uint8_t type;
00222         /** Length in 32-bit words */
00223         uint8_t len;
00224         /** Reserved */
00225         uint8_t reserved[2];
00226         /** Fibre Channel frame header */
00227         struct fc_frame_header fc;
00228         /** ELS frame */
00229         struct fc_login_frame els;
00230 } __attribute__ (( packed ));
00231 
00232 /** A FIP descriptor containing an encapsulated LOGO request frame */
00233 struct fip_logo_request {
00234         /** Type */
00235         uint8_t type;
00236         /** Length in 32-bit words */
00237         uint8_t len;
00238         /** Reserved */
00239         uint8_t reserved[2];
00240         /** Fibre Channel frame header */
00241         struct fc_frame_header fc;
00242         /** ELS frame */
00243         struct fc_logout_request_frame els;
00244 } __attribute__ (( packed ));
00245 
00246 /** A FIP descriptor containing an encapsulated LOGO response frame */
00247 struct fip_logo_response {
00248         /** Type */
00249         uint8_t type;
00250         /** Length in 32-bit words */
00251         uint8_t len;
00252         /** Reserved */
00253         uint8_t reserved[2];
00254         /** Fibre Channel frame header */
00255         struct fc_frame_header fc;
00256         /** ELS frame */
00257         struct fc_logout_response_frame els;
00258 } __attribute__ (( packed ));
00259 
00260 /** A FIP descriptor containing an encapsulated ELP frame */
00261 struct fip_elp {
00262         /** Type */
00263         uint8_t type;
00264         /** Length in 32-bit words */
00265         uint8_t len;
00266         /** Reserved */
00267         uint8_t reserved[2];
00268         /** Fibre Channel frame header */
00269         struct fc_frame_header fc;
00270         /** ELS frame */
00271         struct fc_els_frame_common els;
00272         /** Uninteresting content */
00273         uint32_t dull[25];
00274 } __attribute__ (( packed ));
00275 
00276 /** A FIP descriptor containing an encapsulated LS_RJT frame */
00277 struct fip_ls_rjt {
00278         /** Type */
00279         uint8_t type;
00280         /** Length in 32-bit words */
00281         uint8_t len;
00282         /** Reserved */
00283         uint8_t reserved[2];
00284         /** Fibre Channel frame header */
00285         struct fc_frame_header fc;
00286         /** ELS frame */
00287         struct fc_ls_rjt_frame els;
00288 } __attribute__ (( packed ));
00289 
00290 /** A FIP Vx port identification descriptor */
00291 struct fip_vx_port_id {
00292         /** Type */
00293         uint8_t type;
00294         /** Length in 32-bit words */
00295         uint8_t len;
00296         /** MAC address */
00297         uint8_t mac[ETH_ALEN];
00298         /** Reserved */
00299         uint8_t reserved;
00300         /** Address identifier */
00301         struct fc_port_id id;
00302         /** Port name */
00303         struct fc_name name;
00304 } __attribute__ (( packed ));
00305 
00306 /** A FIP FKA ADV period descriptor */
00307 struct fip_fka_adv_p {
00308         /** Type */
00309         uint8_t type;
00310         /** Length in 32-bit words */
00311         uint8_t len;
00312         /** Reserved */
00313         uint8_t reserved;
00314         /** Flags */
00315         uint8_t flags;
00316         /** Keep alive advertisement period in milliseconds */
00317         uint32_t period;
00318 } __attribute__ (( packed ));
00319 
00320 /** FIP FKA ADV period flags */
00321 enum fip_fka_adv_p_flags {
00322         FIP_NO_KEEPALIVE = 0x01,        /**< Do not send keepalives */
00323 };
00324 
00325 /** A FIP vendor ID descriptor */
00326 struct fip_vendor_id {
00327         /** Type */
00328         uint8_t type;
00329         /** Length in 32-bit words */
00330         uint8_t len;
00331         /** Reserved */
00332         uint8_t reserved[2];
00333         /** Vendor ID */
00334         uint8_t vendor[8];
00335 } __attribute__ (( packed ));
00336 
00337 /** A FIP VLAN descriptor */
00338 struct fip_vlan {
00339         /** Type */
00340         uint8_t type;
00341         /** Length in 32-bit words */
00342         uint8_t len;
00343         /** VLAN ID */
00344         uint16_t vlan;
00345 } __attribute__ (( packed ));
00346 
00347 /** A FIP descriptor */
00348 union fip_descriptor {
00349         /** Common fields */
00350         struct fip_common common;
00351         /** Priority descriptor */
00352         struct fip_priority priority;
00353         /** MAC address descriptor */
00354         struct fip_mac_address mac_address;
00355         /** FC-MAP descriptor */
00356         struct fip_fc_map fc_map;
00357         /** Name identifier descriptor */
00358         struct fip_name_id name_id;
00359         /** Fabric descriptor */
00360         struct fip_fabric fabric;
00361         /** Max FCoE size descriptor */
00362         struct fip_max_fcoe_size max_fcoe_size;
00363         /** FLOGI descriptor */
00364         struct fip_els flogi;
00365         /** FLOGI request descriptor */
00366         struct fip_login flogi_request;
00367         /** FLOGI LS_ACC descriptor */
00368         struct fip_login flogi_ls_acc;
00369         /** FLOGI LS_RJT descriptor */
00370         struct fip_ls_rjt flogi_ls_rjt;
00371         /** NPIV FDISC descriptor */
00372         struct fip_els npiv_fdisc;
00373         /** NPIV FDISC request descriptor */
00374         struct fip_login npiv_fdisc_request;
00375         /** NPIV FDISC LS_ACC descriptor */
00376         struct fip_login npiv_fdisc_ls_acc;
00377         /** NPIV FDISC LS_RJT descriptor */
00378         struct fip_ls_rjt npiv_fdisc_ls_rjt;
00379         /** LOGO descriptor */
00380         struct fip_els logo;
00381         /** LOGO request descriptor */
00382         struct fip_logo_request logo_request;
00383         /** LOGO LS_ACC descriptor */
00384         struct fip_logo_response logo_ls_acc;
00385         /** LOGO LS_RJT descriptor */
00386         struct fip_ls_rjt logo_ls_rjt;
00387         /** ELS descriptor */
00388         struct fip_els elp;
00389         /** ELP request descriptor */
00390         struct fip_elp elp_request;
00391         /** ELP LS_ACC descriptor */
00392         struct fip_elp elp_ls_acc;
00393         /** ELP LS_RJT descriptor */
00394         struct fip_ls_rjt elp_ls_rjt;
00395         /** Vx port identification descriptor */
00396         struct fip_vx_port_id vx_port_id;
00397         /** FKA ADV period descriptor */
00398         struct fip_fka_adv_p fka_adv_p;
00399         /** Vendor ID descriptor */
00400         struct fip_vendor_id vendor_id;
00401         /** VLAN descriptor */
00402         struct fip_vlan vlan;
00403 } __attribute__ (( packed ));
00404 
00405 /** A FIP descriptor set */
00406 struct fip_descriptors {
00407         /** Descriptors, indexed by type */
00408         union fip_descriptor *desc[FIP_NUM_DESCRIPTOR_TYPES];
00409 };
00410 
00411 /**
00412  * Define a function to extract a specific FIP descriptor type from a list
00413  *
00414  * @v type              Descriptor type
00415  * @v name              Descriptor name
00416  * @v finder            Descriptor finder
00417  */
00418 #define FIP_DESCRIPTOR( type, name )                                    \
00419         static inline __attribute__ (( always_inline ))                 \
00420         typeof ( ( ( union fip_descriptor * ) NULL )->name ) *          \
00421         fip_ ## name ( struct fip_descriptors *descs ) {                \
00422                 return &(descs->desc[type]->name);                      \
00423         }
00424 FIP_DESCRIPTOR ( FIP_PRIORITY, priority );
00425 FIP_DESCRIPTOR ( FIP_MAC_ADDRESS, mac_address );
00426 FIP_DESCRIPTOR ( FIP_FC_MAP, fc_map );
00427 FIP_DESCRIPTOR ( FIP_NAME_ID, name_id );
00428 FIP_DESCRIPTOR ( FIP_FABRIC, fabric );
00429 FIP_DESCRIPTOR ( FIP_MAX_FCOE_SIZE, max_fcoe_size );
00430 FIP_DESCRIPTOR ( FIP_FLOGI, flogi );
00431 FIP_DESCRIPTOR ( FIP_FLOGI, flogi_request );
00432 FIP_DESCRIPTOR ( FIP_FLOGI, flogi_ls_acc );
00433 FIP_DESCRIPTOR ( FIP_FLOGI, flogi_ls_rjt );
00434 FIP_DESCRIPTOR ( FIP_NPIV_FDISC, npiv_fdisc );
00435 FIP_DESCRIPTOR ( FIP_NPIV_FDISC, npiv_fdisc_request );
00436 FIP_DESCRIPTOR ( FIP_NPIV_FDISC, npiv_fdisc_ls_acc );
00437 FIP_DESCRIPTOR ( FIP_NPIV_FDISC, npiv_fdisc_ls_rjt );
00438 FIP_DESCRIPTOR ( FIP_LOGO, logo );
00439 FIP_DESCRIPTOR ( FIP_LOGO, logo_request );
00440 FIP_DESCRIPTOR ( FIP_LOGO, logo_ls_acc );
00441 FIP_DESCRIPTOR ( FIP_LOGO, logo_ls_rjt );
00442 FIP_DESCRIPTOR ( FIP_ELP, elp );
00443 FIP_DESCRIPTOR ( FIP_ELP, elp_request );
00444 FIP_DESCRIPTOR ( FIP_ELP, elp_ls_acc );
00445 FIP_DESCRIPTOR ( FIP_ELP, elp_ls_rjt );
00446 FIP_DESCRIPTOR ( FIP_VX_PORT_ID, vx_port_id );
00447 FIP_DESCRIPTOR ( FIP_FKA_ADV_P, fka_adv_p );
00448 FIP_DESCRIPTOR ( FIP_VENDOR_ID, vendor_id );
00449 FIP_DESCRIPTOR ( FIP_VLAN, vlan );
00450 
00451 #endif /* _IPXE_FIP_H */