Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / bofm.h
1 #ifndef _IPXE_BOFM_H
2 #define _IPXE_BOFM_H
3
4 /**
5  * @file
6  *
7  * IBM BladeCenter Open Fabric Manager (BOFM)
8  *
9  */
10
11 FILE_LICENCE ( GPL2_OR_LATER );
12
13 #include <stdint.h>
14 #include <ipxe/list.h>
15 #include <ipxe/pci.h>
16 #include <config/sideband.h>
17
18 /** 'IBM ' signature
19  *
20  * Present in %edi when the BIOS initialisation entry point is called,
21  * with the BOFM table pointer in %esi.
22  *
23  * Defined in section 4.1.2 of the POST/BIOS BOFM I/O Address
24  * Re-Assignment Architecture document.
25  */
26 #define IBMs_SIGNATURE ( ( 'I' << 24 ) + ( 'B' << 16 ) + ( 'M' << 8 ) + ' ' )
27
28 /** ' IBM' signature
29  *
30  * Returned in %edi from the BIOS initialisation entry point, with the
31  * return code in %dl.
32  *
33  * Defined in section 4.1.2 of the POST/BIOS BOFM I/O Address
34  * Re-Assignment Architecture document.
35  */
36 #define sIBM_SIGNATURE ( ( ' ' << 24 ) + ( 'I' << 16 ) + ( 'B' << 8 ) + 'M' )
37
38 /** @defgroup bofmrc BOFM return codes
39  *
40  * Defined in section 4.1.3 of the POST/BIOS BOFM I/O Address
41  * Re-Assignment Architecture document.
42  *
43  * @{
44  */
45
46 /** Successful */
47 #define BOFM_SUCCESS 0x00
48
49 /** Invalid action string */
50 #define BOFM_ERR_INVALID_ACTION 0x01
51
52 /** Unsupported parameter structure version */
53 #define BOFM_ERR_UNSUPPORTED 0x02
54
55 /** Device error prohibited MAC/WWN update */
56 #define BOFM_ERR_DEVICE_ERROR 0x03
57
58 /** PCI reset required (may be combined with another return code) */
59 #define BOFM_PCI_RESET 0x80
60
61 /** @} */
62
63 /** Skip option ROM initialisation
64  *
65  * A BOFM BIOS may call the initialisation entry point multiple times;
66  * only the last call should result in actual initialisation.
67  *
68  * This flag is internal to iPXE.
69  */
70 #define BOFM_SKIP_INIT 0x80000000UL
71
72 /** BOFM table header
73  *
74  * Defined in section 4.1 of the Open Fabric Manager Parameter
75  * Specification document.
76  */
77 struct bofm_global_header {
78         /** Signature */
79         uint32_t magic;
80         /** Subsignature (action string) */
81         uint32_t action;
82         /** Data structure version */
83         uint8_t version;
84         /** Data structure level */
85         uint8_t level;
86         /** Data structure length */
87         uint16_t length;
88         /** Data structure checksum */
89         uint8_t checksum;
90         /** Data structure profile */
91         char profile[32];
92         /** Data structure global options */
93         uint32_t options;
94         /** Data structure sequence stamp */
95         uint32_t sequence;
96 } __attribute__ (( packed ));
97
98 /** BOFM table header signature
99  *
100  * Defined in section 4.1.2 of the POST/BIOS BOFM I/O Address
101  * Re-Assignment Architecture document.
102  */
103 #define BOFM_IOAA_MAGIC  ( 'I' + ( 'O' << 8 ) + ( 'A' << 16 ) + ( 'A' << 24 ) )
104
105 /** @defgroup bofmaction BOFM header subsignatures (action strings)
106  *
107  * Defined in section 4.1.2 of the POST/BIOS BOFM I/O Address
108  * Re-Assignment Architecture document.
109  *
110  * @{
111  */
112
113 /** Update MAC/WWN */
114 #define BOFM_ACTION_UPDT ( 'U' + ( 'P' << 8 ) + ( 'D' << 16 ) + ( 'T' << 24 ) )
115
116 /** Restore MAC/WWN to factory default */
117 #define BOFM_ACTION_DFLT ( 'D' + ( 'F' << 8 ) + ( 'L' << 16 ) + ( 'T' << 24 ) )
118
119 /** Harvest MAC/WWN */
120 #define BOFM_ACTION_HVST ( 'H' + ( 'V' << 8 ) + ( 'S' << 16 ) + ( 'T' << 24 ) )
121
122 /** Update MAC/WWN and initialise device */
123 #define BOFM_ACTION_PARM ( 'P' + ( 'A' << 8 ) + ( 'R' << 16 ) + ( 'M' << 24 ) )
124
125 /** Just initialise the device */
126 #define BOFM_ACTION_NONE ( 'N' + ( 'O' << 8 ) + ( 'N' << 16 ) + ( 'E' << 24 ) )
127
128 /** @} */
129
130 /** BOFM section header
131  *
132  * Defined in section 4.2 of the Open Fabric Manager Parameter
133  * Specification document.
134  */
135 struct bofm_section_header {
136         /** Signature */
137         uint32_t magic;
138         /** Length */
139         uint16_t length;
140 } __attribute__ (( packed ));
141
142 /** @defgroup bofmsections BOFM section header signatures
143  *
144  * Defined in section 4.2 of the Open Fabric Manager Parameter
145  * Specification document.
146  *
147  * @{
148  */
149
150 /** EN start marker */
151 #define BOFM_EN_MAGIC    ( ' ' + ( ' ' << 8 ) + ( 'E' << 16 ) + ( 'N' << 24 ) )
152
153 /** End marker */
154 #define BOFM_DONE_MAGIC  ( 'D' + ( 'O' << 8 ) + ( 'N' << 16 ) + ( 'E' << 24 ) )
155
156 /** @} */
157
158 /** BOFM Ethernet parameter entry
159  *
160  * Defined in section 5.1 of the Open Fabric Manager Parameter
161  * Specification document.
162  */
163 struct bofm_en {
164         /** Options */
165         uint16_t options;
166         /** PCI bus:dev.fn
167          *
168          * Valid only if @c options indicates @c BOFM_EN_MAP_PFA
169          */
170         uint16_t busdevfn;
171         /** Slot or mezzanine number
172          *
173          * Valid only if @c options indicates @c BOFM_EN_MAP_SLOT_PORT
174          */
175         uint8_t slot;
176         /** Port number
177          *
178          * Valid only if @c options indicates @c BOFM_EN_MAP_SLOT_PORT
179          */
180         uint8_t port;
181         /** Multi-port index */
182         uint8_t mport;
183         /** VLAN tag for MAC address A */
184         uint16_t vlan_a;
185         /** MAC address A
186          *
187          * MAC address A is the sole MAC address, or the lower
188          * (inclusive) bound of a range of MAC addresses.
189          */
190         uint8_t mac_a[6];
191         /** VLAN tag for MAC address B */
192         uint16_t vlan_b;
193         /** MAC address B
194          *
195          * MAC address B is unset, or the upper (inclusive) bound of a
196          * range of MAC addresses
197          */
198         uint8_t mac_b[6];
199 } __attribute__ (( packed ));
200
201 /** @defgroup bofmenopts BOFM Ethernet parameter entry options
202  *
203  * Defined in section 5.1 of the Open Fabric Manager Parameter
204  * Specification document.
205  *
206  * @{
207  */
208
209 /** Port mapping mask */
210 #define BOFM_EN_MAP_MASK        0x0001
211
212 /** Port mapping is by PCI bus:dev.fn */
213 #define BOFM_EN_MAP_PFA                 0x0000
214
215 /** Port mapping is by slot/port */
216 #define BOFM_EN_MAP_SLOT_PORT           0x0001
217
218 /** MAC address B is present */
219 #define BOFM_EN_EN_B            0x0002
220
221 /** VLAN tag for MAC address B is present */
222 #define BOFM_EN_VLAN_B          0x0004
223
224 /** MAC address A is present */
225 #define BOFM_EN_EN_A            0x0008
226
227 /** VLAN tag for MAC address A is present */
228 #define BOFM_EN_VLAN_A          0x0010
229
230 /** Entry consumption indicator mask */
231 #define BOFM_EN_CSM_MASK        0x00c0
232
233 /** Entry has not been used */
234 #define BOFM_EN_CSM_UNUSED              0x0000
235
236 /** Entry has been used successfully */
237 #define BOFM_EN_CSM_SUCCESS             0x0040
238
239 /** Entry has been used but failed */
240 #define BOFM_EN_CSM_FAILED              0x0080
241
242 /** Consumed entry change mask */
243 #define BOFM_EN_CHG_MASK        0x0100
244
245 /** Consumed entry is same as previous active entry */
246 #define BOFM_EN_CHG_UNCHANGED           0x0000
247
248 /** Consumed entry is different than previous active entry */
249 #define BOFM_EN_CHG_CHANGED             0x0100
250
251 /** Ignore values - it's harvest time */
252 #define BOFM_EN_USAGE_HARVEST   0x1000
253
254 /** Use entry values for assignment */
255 #define BOFM_EN_USAGE_ENTRY     0x0800
256
257 /** Use factory default values */
258 #define BOFM_EN_USAGE_DEFAULT   0x0400
259
260 /** Harvest complete */
261 #define BOFM_EN_HVST            0x2000
262
263 /** Harvest request mask */
264 #define BOFM_EN_RQ_HVST_MASK    0xc000
265
266 /** Do not harvest */
267 #define BOFM_EN_RQ_HVST_NONE            0x0000
268
269 /** Harvest factory default values */
270 #define BOFM_EN_RQ_HVST_DEFAULT         0x4000
271
272 /** Harvest active values */
273 #define BOFM_EN_RQ_HVST_ACTIVE          0xc000
274
275 /** @} */
276
277 /** BOFM magic value debug message format */
278 #define BOFM_MAGIC_FMT "'%c%c%c%c'"
279
280 /** BOFM magic value debug message arguments */
281 #define BOFM_MAGIC_ARGS( magic )                                        \
282         ( ( (magic) >> 0 ) & 0xff ), ( ( (magic) >> 8 ) & 0xff ),       \
283         ( ( (magic) >> 16 ) & 0xff ), ( ( (magic) >> 24 ) & 0xff )
284
285 /** A BOFM device */
286 struct bofm_device {
287         /** Underlying PCI device */
288         struct pci_device *pci;
289         /** BOFM device operations */
290         struct bofm_operations *op;
291         /** List of BOFM devices */
292         struct list_head list;
293 };
294
295 /** BOFM device operations */
296 struct bofm_operations {
297         /** Harvest Ethernet MAC
298          *
299          * @v bofm              BOFM device
300          * @v mport             Multi-port index
301          * @v mac               MAC to fill in
302          * @ret rc              Return status code
303          */
304         int ( * harvest ) ( struct bofm_device *bofm, unsigned int mport,
305                             uint8_t *mac );
306         /** Update Ethernet MAC
307          *
308          * @v bofm              BOFM device
309          * @v mport             Multi-port index
310          * @v mac               New MAC
311          * @ret rc              Return status code
312          */
313         int ( * update ) ( struct bofm_device *bofm, unsigned int mport,
314                            const uint8_t *mac );
315 };
316
317 /** BOFM driver table */
318 #define BOFM_DRIVERS __table ( struct pci_driver, "bofm_drivers" )
319
320 /** Declare a BOFM driver
321  *
322  * In the common case of non-BOFM-enabled builds, allow any BOFM code
323  * to be garbage-collected at link time to save space.
324  */
325 #ifdef CONFIG_BOFM
326 #define __bofm_driver __table_entry ( BOFM_DRIVERS, 01 )
327 #else
328 #define __bofm_driver
329 #endif
330
331 /**
332  * Initialise BOFM device
333  *
334  * @v bofm              BOFM device
335  * @v pci               PCI device
336  * @v op                BOFM device operations
337  */
338 static inline __attribute__ (( always_inline )) void
339 bofm_init ( struct bofm_device *bofm, struct pci_device *pci,
340             struct bofm_operations *op ) {
341         bofm->pci = pci;
342         bofm->op = op;
343 }
344
345 extern int bofm_register ( struct bofm_device *bofm );
346 extern void bofm_unregister ( struct bofm_device *bofm );
347 extern int bofm_find_driver ( struct pci_device *pci );
348 extern int bofm ( userptr_t bofmtab, struct pci_device *pci );
349 extern void bofm_test ( struct pci_device *pci );
350
351 #endif /* _IPXE_BOFM_H */