Home | History | Annotate | Download | only in gpxe
      1 #ifndef _GPXE_IBFT_H
      2 #define _GPXE_IBFT_H
      3 
      4 /*
      5  * Copyright Fen Systems Ltd. 2007.  Portions of this code are derived
      6  * from IBM Corporation Sample Programs.  Copyright IBM Corporation
      7  * 2004, 2007.  All rights reserved.
      8  *
      9  * Permission is hereby granted, free of charge, to any person
     10  * obtaining a copy of this software and associated documentation
     11  * files (the "Software"), to deal in the Software without
     12  * restriction, including without limitation the rights to use, copy,
     13  * modify, merge, publish, distribute, sublicense, and/or sell copies
     14  * of the Software, and to permit persons to whom the Software is
     15  * furnished to do so, subject to the following conditions:
     16  *
     17  * The above copyright notice and this permission notice shall be
     18  * included in all copies or substantial portions of the Software.
     19  *
     20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
     24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
     25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     27  * SOFTWARE.
     28  *
     29  */
     30 
     31 FILE_LICENCE ( BSD2 );
     32 
     33 /** @file
     34  *
     35  * iSCSI boot firmware table
     36  *
     37  * The information in this file is derived from the document "iSCSI
     38  * Boot Firmware Table (iBFT)" as published by IBM at
     39  *
     40  * ftp://ftp.software.ibm.com/systems/support/system_x_pdf/ibm_iscsi_boot_firmware_table_v1.02.pdf
     41  *
     42  */
     43 
     44 #include <stdint.h>
     45 #include <gpxe/acpi.h>
     46 #include <gpxe/in.h>
     47 
     48 /** iSCSI Boot Firmware Table signature */
     49 #define IBFT_SIG "iBFT"
     50 
     51 /** An offset from the start of the iBFT */
     52 typedef uint16_t ibft_off_t;
     53 
     54 /** Length of a string within the iBFT (excluding terminating NUL) */
     55 typedef uint16_t ibft_size_t;
     56 
     57 /** A string within the iBFT */
     58 struct ibft_string {
     59 	/** Length of string */
     60 	ibft_size_t length;
     61 	/** Offset to string */
     62 	ibft_off_t offset;
     63 } __attribute__ (( packed ));
     64 
     65 /** An IP address within the iBFT */
     66 struct ibft_ipaddr {
     67 	/** Reserved; must be zero */
     68 	uint16_t zeroes[5];
     69 	/** Must be 0xffff if IPv4 address is present, otherwise zero */
     70 	uint16_t ones;
     71 	/** The IPv4 address, or zero if not present */
     72 	struct in_addr in;
     73 } __attribute__ (( packed ));
     74 
     75 /**
     76  * iBFT structure header
     77  *
     78  * This structure is common to several sections within the iBFT.
     79  */
     80 struct ibft_header {
     81 	/** Structure ID
     82 	 *
     83 	 * This is an IBFT_STRUCTURE_ID_XXX constant
     84 	 */
     85 	uint8_t structure_id;
     86 	/** Version (always 1) */
     87 	uint8_t version;
     88 	/** Length, including this header */
     89 	uint16_t length;
     90 	/** Index
     91 	 *
     92 	 * This is the number of the NIC or Target, when applicable.
     93 	 */
     94 	uint8_t index;
     95 	/** Flags */
     96 	uint8_t flags;
     97 } __attribute__ (( packed ));
     98 
     99 /**
    100  * iBFT Control structure
    101  *
    102  */
    103 struct ibft_control {
    104 	/** Common header */
    105 	struct ibft_header header;
    106 	/** Extensions */
    107 	uint16_t extensions;
    108 	/** Offset to Initiator structure */
    109 	ibft_off_t initiator;
    110 	/** Offset to NIC structure for NIC 0 */
    111 	ibft_off_t nic_0;
    112 	/** Offset to Target structure for target 0 */
    113 	ibft_off_t target_0;
    114 	/** Offset to NIC structure for NIC 1 */
    115 	ibft_off_t nic_1;
    116 	/** Offset to Target structure for target 1 */
    117 	ibft_off_t target_1;
    118 } __attribute__ (( packed ));
    119 
    120 /** Structure ID for Control section */
    121 #define IBFT_STRUCTURE_ID_CONTROL 0x01
    122 
    123 /** Attempt login only to specified target
    124  *
    125  * If this flag is not set, all targets will be logged in to.
    126  */
    127 #define IBFT_FL_CONTROL_SINGLE_LOGIN_ONLY 0x01
    128 
    129 /**
    130  * iBFT Initiator structure
    131  *
    132  */
    133 struct ibft_initiator {
    134 	/** Common header */
    135 	struct ibft_header header;
    136 	/** iSNS server */
    137 	struct ibft_ipaddr isns_server;
    138 	/** SLP server */
    139 	struct ibft_ipaddr slp_server;
    140 	/** Primary and secondary Radius servers */
    141 	struct ibft_ipaddr radius[2];
    142 	/** Initiator name */
    143 	struct ibft_string initiator_name;
    144 } __attribute__ (( packed ));
    145 
    146 /** Structure ID for Initiator section */
    147 #define IBFT_STRUCTURE_ID_INITIATOR 0x02
    148 
    149 /** Initiator block valid */
    150 #define IBFT_FL_INITIATOR_BLOCK_VALID 0x01
    151 
    152 /** Initiator firmware boot selected */
    153 #define IBFT_FL_INITIATOR_FIRMWARE_BOOT_SELECTED 0x02
    154 
    155 /**
    156  * iBFT NIC structure
    157  *
    158  */
    159 struct ibft_nic {
    160 	/** Common header */
    161 	struct ibft_header header;
    162 	/** IP address */
    163 	struct ibft_ipaddr ip_address;
    164 	/** Subnet mask
    165 	 *
    166 	 * This is the length of the subnet mask in bits (e.g. /24).
    167 	 */
    168 	uint8_t subnet_mask_prefix;
    169 	/** Origin */
    170 	uint8_t origin;
    171 	/** Default gateway */
    172 	struct ibft_ipaddr gateway;
    173 	/** Primary and secondary DNS servers */
    174 	struct ibft_ipaddr dns[2];
    175 	/** DHCP server */
    176 	struct ibft_ipaddr dhcp;
    177 	/** VLAN tag */
    178 	uint16_t vlan;
    179 	/** MAC address */
    180 	uint8_t mac_address[6];
    181 	/** PCI bus:dev:fn */
    182 	uint16_t pci_bus_dev_func;
    183 	/** Hostname */
    184 	struct ibft_string hostname;
    185 } __attribute__ (( packed ));
    186 
    187 /** Structure ID for NIC section */
    188 #define IBFT_STRUCTURE_ID_NIC 0x03
    189 
    190 /** NIC block valid */
    191 #define IBFT_FL_NIC_BLOCK_VALID 0x01
    192 
    193 /** NIC firmware boot selected */
    194 #define IBFT_FL_NIC_FIRMWARE_BOOT_SELECTED 0x02
    195 
    196 /** NIC global / link local */
    197 #define IBFT_FL_NIC_GLOBAL 0x04
    198 
    199 /**
    200  * iBFT Target structure
    201  *
    202  */
    203 struct ibft_target {
    204 	/** Common header */
    205 	struct ibft_header header;
    206 	/** IP address */
    207 	struct ibft_ipaddr ip_address;
    208 	/** TCP port */
    209 	uint16_t socket;
    210 	/** Boot LUN */
    211 	uint64_t boot_lun;
    212 	/** CHAP type
    213 	 *
    214 	 * This is an IBFT_CHAP_XXX constant.
    215 	 */
    216 	uint8_t chap_type;
    217 	/** NIC association */
    218 	uint8_t nic_association;
    219 	/** Target name */
    220 	struct ibft_string target_name;
    221 	/** CHAP name */
    222 	struct ibft_string chap_name;
    223 	/** CHAP secret */
    224 	struct ibft_string chap_secret;
    225 	/** Reverse CHAP name */
    226 	struct ibft_string reverse_chap_name;
    227 	/** Reverse CHAP secret */
    228 	struct ibft_string reverse_chap_secret;
    229 } __attribute__ (( packed ));
    230 
    231 /** Structure ID for Target section */
    232 #define IBFT_STRUCTURE_ID_TARGET 0x04
    233 
    234 /** Target block valid */
    235 #define IBFT_FL_TARGET_BLOCK_VALID 0x01
    236 
    237 /** Target firmware boot selected */
    238 #define IBFT_FL_TARGET_FIRMWARE_BOOT_SELECTED 0x02
    239 
    240 /** Target use Radius CHAP */
    241 #define IBFT_FL_TARGET_USE_CHAP 0x04
    242 
    243 /** Target use Radius rCHAP */
    244 #define IBFT_FL_TARGET_USE_RCHAP 0x08
    245 
    246 /* Values for chap_type */
    247 #define IBFT_CHAP_NONE		0	/**< No CHAP authentication */
    248 #define IBFT_CHAP_ONE_WAY	1	/**< One-way CHAP */
    249 #define IBFT_CHAP_MUTUAL	2	/**< Mutual CHAP */
    250 
    251 /**
    252  * iSCSI Boot Firmware Table (iBFT)
    253  */
    254 struct ibft_table {
    255 	/** ACPI header */
    256 	struct acpi_description_header acpi;
    257 	/** Reserved */
    258 	uint8_t reserved[12];
    259 	/** Control structure */
    260 	struct ibft_control control;
    261 } __attribute__ (( packed ));
    262 
    263 /**
    264  * iSCSI string block descriptor
    265  *
    266  * This is an internal structure that we use to keep track of the
    267  * allocation of string data.
    268  */
    269 struct ibft_string_block {
    270 	/** The iBFT containing these strings */
    271 	struct ibft_table *table;
    272 	/** Offset of first free byte within iBFT */
    273 	unsigned int offset;
    274 };
    275 
    276 /** Amount of space reserved for strings in a gPXE iBFT */
    277 #define IBFT_STRINGS_SIZE 384
    278 
    279 /**
    280  * An iBFT created by gPXE
    281  *
    282  */
    283 struct gpxe_ibft {
    284 	/** The fixed section */
    285 	struct ibft_table table;
    286 	/** The Initiator section */
    287 	struct ibft_initiator initiator __attribute__ (( aligned ( 16 ) ));
    288 	/** The NIC section */
    289 	struct ibft_nic nic __attribute__ (( aligned ( 16 ) ));
    290 	/** The Target section */
    291 	struct ibft_target target __attribute__ (( aligned ( 16 ) ));
    292 	/** Strings block */
    293 	char strings[IBFT_STRINGS_SIZE];
    294 } __attribute__ (( packed, aligned ( 16 ) ));
    295 
    296 struct net_device;
    297 struct iscsi_session;
    298 
    299 extern int ibft_fill_data ( struct net_device *netdev,
    300 			    struct iscsi_session *iscsi );
    301 
    302 #endif /* _GPXE_IBFT_H */
    303