[infiniband] Do not use GRH for local paths
[ipxe.git] / src / interface / efi / efi_bofm.c
1 /*
2 * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 #include <errno.h>
27 #include <ipxe/bofm.h>
28 #include <ipxe/efi/efi.h>
29 #include <ipxe/efi/efi_pci.h>
30 #include <ipxe/efi/efi_driver.h>
31
32 /** @file
33 *
34 * IBM BladeCenter Open Fabric Manager (BOFM) EFI interface
35 *
36 */
37
38 /***************************************************************************
39 *
40 * EFI BOFM definitions
41 *
42 ***************************************************************************
43 *
44 * Taken from the BOFM UEFI Vendor Specification document
45 *
46 */
47
48 #define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID \
49 { 0x03207ce2, 0xd9c7, 0x11dc, \
50 { 0xa9, 0x4d, 0x00, 0x19, 0x7d, 0x89, 0x02, 0x38 } }
51
52 #define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID \
53 { 0xe82a9763, 0x0584, 0x4e41, \
54 { 0xbb, 0x39, 0xe0, 0xcd, 0xb8, 0xc1, 0xf0, 0xfc } }
55
56 typedef struct {
57 UINT8 Id;
58 UINT8 ResultByte;
59 } __attribute__ (( packed )) BOFM_EPID_Results_t;
60
61 typedef struct {
62 UINT8 Version;
63 UINT8 Level;
64 UINT16 Length;
65 UINT8 Checksum;
66 UINT8 Profile[32];
67 UINT8 GlobalOption0;
68 UINT8 GlobalOption1;
69 UINT8 GlobalOption2;
70 UINT8 GlobalOption3;
71 UINT32 SequenceStamp;
72 UINT8 Regions[911]; // For use by BOFM Driver
73 UINT32 Reserved1;
74 } __attribute__ (( packed )) BOFM_Parameters_t;
75
76 typedef struct {
77 UINT32 Reserved1;
78 UINT8 Version;
79 UINT8 Level;
80 UINT8 Checksum;
81 UINT32 SequenceStamp;
82 UINT8 SUIDResults;
83 UINT8 EntryResults[32];
84 UINT8 Reserved2;
85 UINT8 Reserved3;
86 UINT8 FCTgtResults[2];
87 UINT8 SASTgtResults[2];
88 BOFM_EPID_Results_t EPIDResults[2];
89 UINT8 Results4[10];
90 } __attribute__ (( packed )) BOFM_Results_t;
91
92 typedef struct {
93 UINT32 Signature;
94 UINT32 SubSignature;
95 BOFM_Parameters_t Parameters;
96 BOFM_Results_t Results;
97 } __attribute__ (( packed )) BOFM_DataStructure_t;
98
99 #define IBM_BOFM_TABLE BOFM_DataStructure_t
100
101 typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL
102 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL;
103
104 typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2
105 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2;
106
107 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT ) (
108 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
109 EFI_HANDLE ControllerHandle,
110 UINT8 SupporttedOptions,
111 UINT8 iSCSI_Parameter_Version,
112 UINT8 BOFM_Parameter_Version
113 );
114
115 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS ) (
116 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
117 EFI_HANDLE ControllerHandle,
118 BOOLEAN ResetRequired,
119 UINT8 BOFMReturnCode
120 );
121
122 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 ) (
123 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *This,
124 EFI_HANDLE ControllerHandle,
125 BOOLEAN ResetRequired,
126 UINT8 BOFMReturnCode
127 );
128
129 struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL {
130 IBM_BOFM_TABLE BofmTable;
131 IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus;
132 IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
133 };
134
135 struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 {
136 UINT32 Signature;
137 UINT32 Reserved1;
138 UINT64 Reserved2;
139 IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus;
140 IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
141 IBM_BOFM_TABLE BofmTable;
142 };
143
144 /***************************************************************************
145 *
146 * EFI BOFM interface
147 *
148 ***************************************************************************
149 */
150
151 /** BOFM1 protocol GUID */
152 static EFI_GUID bofm1_protocol_guid =
153 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID;
154
155 /** BOFM2 protocol GUID */
156 static EFI_GUID bofm2_protocol_guid =
157 IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID;
158
159 /**
160 * Check if device is supported
161 *
162 * @v device EFI device handle
163 * @ret rc Return status code
164 */
165 static int efi_bofm_supported ( EFI_HANDLE device ) {
166 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
167 struct pci_device pci;
168 union {
169 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
170 void *interface;
171 } bofm1;
172 EFI_STATUS efirc;
173 int rc;
174
175 /* Get PCI device information */
176 if ( ( rc = efipci_info ( device, &pci ) ) != 0 )
177 return rc;
178
179 /* Look for a BOFM driver */
180 if ( ( rc = bofm_find_driver ( &pci ) ) != 0 ) {
181 DBGCP ( device, "EFIBOFM %s has no driver\n",
182 efi_handle_name ( device ) );
183 return rc;
184 }
185
186 /* Locate BOFM protocol */
187 if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
188 &bofm1.interface ) ) != 0 ) {
189 rc = -EEFI ( efirc );
190 DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n",
191 efi_handle_name ( device ) );
192 return rc;
193 }
194
195 /* Register support for this device */
196 if ( ( efirc = bofm1.bofm1->RegisterSupport ( bofm1.bofm1, device,
197 0x04 /* Can change MAC */,
198 0x00 /* No iSCSI */,
199 0x02 /* Version */ ))!=0){
200 rc = -EEFI ( efirc );
201 DBGC ( device, "EFIBOFM %s could not register support: %s\n",
202 efi_handle_name ( device ), strerror ( rc ) );
203 return rc;
204 }
205
206 DBGC ( device, "EFIBOFM %s has driver \"%s\"\n",
207 efi_handle_name ( device ), pci.id->name );
208 return 0;
209 }
210
211 /**
212 * Attach driver to device
213 *
214 * @v efidev EFI device
215 * @ret rc Return status code
216 */
217 static int efi_bofm_start ( struct efi_device *efidev ) {
218 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
219 EFI_HANDLE device = efidev->device;
220 union {
221 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
222 void *interface;
223 } bofm1;
224 union {
225 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *bofm2;
226 void *interface;
227 } bofm2;
228 struct pci_device pci;
229 IBM_BOFM_TABLE *bofmtab;
230 IBM_BOFM_TABLE *bofmtab2;
231 int bofmrc;
232 EFI_STATUS efirc;
233 int rc;
234
235 /* Open PCI device, if possible */
236 if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
237 &pci ) ) != 0 )
238 goto err_open;
239
240 /* Locate BOFM protocol */
241 if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
242 &bofm1.interface ) ) != 0 ) {
243 rc = -EEFI ( efirc );
244 DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n",
245 efi_handle_name ( device ) );
246 goto err_locate_bofm;
247 }
248 bofmtab = &bofm1.bofm1->BofmTable;
249 DBGC ( device, "EFIBOFM %s found version 1 BOFM table at %p+%04x\n",
250 efi_handle_name ( device ), bofmtab, bofmtab->Parameters.Length);
251
252 /* Locate BOFM2 protocol, if available */
253 if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL,
254 &bofm2.interface ) ) == 0 ) {
255 bofmtab2 = &bofm2.bofm2->BofmTable;
256 DBGC ( device, "EFIBOFM %s found version 2 BOFM table at "
257 "%p+%04x\n", efi_handle_name ( device ), bofmtab2,
258 bofmtab2->Parameters.Length );
259 assert ( bofm2.bofm2->RegisterSupport ==
260 bofm1.bofm1->RegisterSupport );
261 } else {
262 DBGC ( device, "EFIBOFM %s cannot find BOFM2 protocol\n",
263 efi_handle_name ( device ) );
264 /* Not a fatal error; may be a BOFM1-only system */
265 bofmtab2 = NULL;
266 }
267
268 /* Process BOFM table */
269 DBGC2 ( device, "EFIBOFM %s version 1 before processing:\n",
270 efi_handle_name ( device ) );
271 DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
272 if ( bofmtab2 ) {
273 DBGC2 ( device, "EFIBOFM %s version 2 before processing:\n",
274 efi_handle_name ( device ) );
275 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
276 }
277 bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), &pci );
278 DBGC ( device, "EFIBOFM %s status %08x\n",
279 efi_handle_name ( device ), bofmrc );
280 DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n",
281 efi_handle_name ( device ) );
282 DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
283 if ( bofmtab2 ) {
284 DBGC2 ( device, "EFIBOFM %s version 2 after processing:\n",
285 efi_handle_name ( device ) );
286 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
287 }
288
289 /* Return BOFM status */
290 if ( bofmtab2 ) {
291 if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
292 FALSE, bofmrc ) ) != 0){
293 rc = -EEFI ( efirc );
294 DBGC ( device, "EFIBOFM %s could not set BOFM2 "
295 "status: %s\n", efi_handle_name ( device ),
296 strerror ( rc ) );
297 goto err_set_status;
298 }
299 } else {
300 if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
301 FALSE, bofmrc ) ) != 0){
302 rc = -EEFI ( efirc );
303 DBGC ( device, "EFIBOFM %s could not set BOFM "
304 "status: %s\n", efi_handle_name ( device ),
305 strerror ( rc ) );
306 goto err_set_status;
307 }
308 }
309
310 /* BOFM (ab)uses the "start" method to mean "process and exit" */
311 rc = -EAGAIN;
312
313 err_set_status:
314 err_locate_bofm:
315 efipci_close ( device );
316 err_open:
317 return rc;
318 }
319
320 /**
321 * Detach driver from device
322 *
323 * @v device EFI device
324 */
325 static void efi_bofm_stop ( struct efi_device *efidev __unused ) {
326
327 /* Should never happen */
328 assert ( 0 );
329 }
330
331 /** EFI BOFM driver */
332 struct efi_driver efi_bofm_driver __efi_driver ( EFI_DRIVER_EARLY ) = {
333 .name = "BOFM",
334 .supported = efi_bofm_supported,
335 .start = efi_bofm_start,
336 .stop = efi_bofm_stop,
337 };