Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / ibft.h
1 #ifndef _IPXE_IBFT_H
2 #define _IPXE_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 <ipxe/acpi.h>
46 #include <ipxe/scsi.h>
47 #include <ipxe/in.h>
48
49 /** iSCSI Boot Firmware Table signature */
50 #define IBFT_SIG ACPI_SIGNATURE ( 'i', 'B', 'F', 'T' )
51
52 /** An offset from the start of the iBFT */
53 typedef uint16_t ibft_off_t;
54
55 /** Length of a string within the iBFT (excluding terminating NUL) */
56 typedef uint16_t ibft_size_t;
57
58 /** A string within the iBFT */
59 struct ibft_string {
60         /** Length of string */
61         ibft_size_t len;
62         /** Offset to string */
63         ibft_off_t offset;
64 } __attribute__ (( packed ));
65
66 /** An IP address within the iBFT */
67 struct ibft_ipaddr {
68         /** Reserved; must be zero */
69         uint16_t zeroes[5];
70         /** Must be 0xffff if IPv4 address is present, otherwise zero */
71         uint16_t ones;
72         /** The IPv4 address, or zero if not present */
73         struct in_addr in;
74 } __attribute__ (( packed ));
75
76 /**
77  * iBFT structure header
78  *
79  * This structure is common to several sections within the iBFT.
80  */
81 struct ibft_header {
82         /** Structure ID
83          *
84          * This is an IBFT_STRUCTURE_ID_XXX constant
85          */
86         uint8_t structure_id;
87         /** Version (always 1) */
88         uint8_t version;
89         /** Length, including this header */
90         uint16_t length;
91         /** Index 
92          *
93          * This is the number of the NIC or Target, when applicable.
94          */
95         uint8_t index;
96         /** Flags */
97         uint8_t flags;
98 } __attribute__ (( packed ));
99
100 /**
101  * iBFT Control structure
102  *
103  */
104 struct ibft_control {
105         /** Common header */
106         struct ibft_header header;
107         /** Extensions */
108         uint16_t extensions;
109         /** Offset to Initiator structure */
110         ibft_off_t initiator;
111         /** Offset to NIC structure for NIC 0 */
112         ibft_off_t nic_0;
113         /** Offset to Target structure for target 0 */
114         ibft_off_t target_0;
115         /** Offset to NIC structure for NIC 1 */
116         ibft_off_t nic_1;
117         /** Offset to Target structure for target 1 */
118         ibft_off_t target_1;
119 } __attribute__ (( packed ));
120
121 /** Structure ID for Control section */
122 #define IBFT_STRUCTURE_ID_CONTROL 0x01
123
124 /** Attempt login only to specified target
125  *
126  * If this flag is not set, all targets will be logged in to.
127  */
128 #define IBFT_FL_CONTROL_SINGLE_LOGIN_ONLY 0x01
129
130 /**
131  * iBFT Initiator structure
132  *
133  */
134 struct ibft_initiator {
135         /** Common header */
136         struct ibft_header header;
137         /** iSNS server */
138         struct ibft_ipaddr isns_server;
139         /** SLP server */
140         struct ibft_ipaddr slp_server;
141         /** Primary and secondary Radius servers */
142         struct ibft_ipaddr radius[2];
143         /** Initiator name */
144         struct ibft_string initiator_name;
145 } __attribute__ (( packed ));
146
147 /** Structure ID for Initiator section */
148 #define IBFT_STRUCTURE_ID_INITIATOR 0x02
149
150 /** Initiator block valid */
151 #define IBFT_FL_INITIATOR_BLOCK_VALID 0x01
152
153 /** Initiator firmware boot selected */
154 #define IBFT_FL_INITIATOR_FIRMWARE_BOOT_SELECTED 0x02
155
156 /**
157  * iBFT NIC structure
158  *
159  */
160 struct ibft_nic {
161         /** Common header */
162         struct ibft_header header;
163         /** IP address */
164         struct ibft_ipaddr ip_address;
165         /** Subnet mask
166          *
167          * This is the length of the subnet mask in bits (e.g. /24).
168          */
169         uint8_t subnet_mask_prefix;
170         /** Origin */
171         uint8_t origin;
172         /** Default gateway */
173         struct ibft_ipaddr gateway;
174         /** Primary and secondary DNS servers */
175         struct ibft_ipaddr dns[2];
176         /** DHCP server */
177         struct ibft_ipaddr dhcp;
178         /** VLAN tag */
179         uint16_t vlan;
180         /** MAC address */
181         uint8_t mac_address[6];
182         /** PCI bus:dev:fn */
183         uint16_t pci_bus_dev_func;
184         /** Hostname */
185         struct ibft_string hostname;
186 } __attribute__ (( packed ));
187
188 /** Structure ID for NIC section */
189 #define IBFT_STRUCTURE_ID_NIC 0x03
190
191 /** NIC block valid */
192 #define IBFT_FL_NIC_BLOCK_VALID 0x01
193
194 /** NIC firmware boot selected */
195 #define IBFT_FL_NIC_FIRMWARE_BOOT_SELECTED 0x02
196
197 /** NIC global / link local */
198 #define IBFT_FL_NIC_GLOBAL 0x04
199
200 /** NIC IP address origin */
201 #define IBFT_NIC_ORIGIN_OTHER 0x00
202 #define IBFT_NIC_ORIGIN_MANUAL 0x01
203 #define IBFT_NIC_ORIGIN_WELLKNOWN 0x02
204 #define IBFT_NIC_ORIGIN_DHCP 0x03
205 #define IBFT_NIC_ORIGIN_RA 0x04
206 #define IBFT_NIC_ORIGIN_UNCHANGED 0x0f
207
208 /**
209  * iBFT Target structure
210  *
211  */
212 struct ibft_target {
213         /** Common header */
214         struct ibft_header header;
215         /** IP address */
216         struct ibft_ipaddr ip_address;
217         /** TCP port */
218         uint16_t socket;
219         /** Boot LUN */
220         struct scsi_lun boot_lun;
221         /** CHAP type
222          *
223          * This is an IBFT_CHAP_XXX constant.
224          */
225         uint8_t chap_type;
226         /** NIC association */
227         uint8_t nic_association;
228         /** Target name */
229         struct ibft_string target_name;
230         /** CHAP name */
231         struct ibft_string chap_name;
232         /** CHAP secret */
233         struct ibft_string chap_secret;
234         /** Reverse CHAP name */
235         struct ibft_string reverse_chap_name;
236         /** Reverse CHAP secret */
237         struct ibft_string reverse_chap_secret;
238 } __attribute__ (( packed ));
239
240 /** Structure ID for Target section */
241 #define IBFT_STRUCTURE_ID_TARGET 0x04
242
243 /** Target block valid */
244 #define IBFT_FL_TARGET_BLOCK_VALID 0x01
245
246 /** Target firmware boot selected */
247 #define IBFT_FL_TARGET_FIRMWARE_BOOT_SELECTED 0x02
248
249 /** Target use Radius CHAP */
250 #define IBFT_FL_TARGET_USE_CHAP 0x04
251
252 /** Target use Radius rCHAP */
253 #define IBFT_FL_TARGET_USE_RCHAP 0x08
254
255 /* Values for chap_type */
256 #define IBFT_CHAP_NONE          0       /**< No CHAP authentication */
257 #define IBFT_CHAP_ONE_WAY       1       /**< One-way CHAP */
258 #define IBFT_CHAP_MUTUAL        2       /**< Mutual CHAP */
259
260 /**
261  * iSCSI Boot Firmware Table (iBFT)
262  */
263 struct ibft_table {
264         /** ACPI header */
265         struct acpi_description_header acpi;
266         /** Reserved */
267         uint8_t reserved[12];
268         /** Control structure */
269         struct ibft_control control;
270 } __attribute__ (( packed ));
271
272 struct iscsi_session;
273 struct net_device;
274
275 extern int ibft_describe ( struct iscsi_session *iscsi,
276                            struct acpi_description_header *acpi,
277                            size_t len );
278
279 #endif /* _IPXE_IBFT_H */