]>
Commit | Line | Data |
---|---|---|
bcecde14 | 1 | /** @file\r |
2 | \r | |
9f6c5db2 | 3 | Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>\r |
bcecde14 | 4 | \r |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions\r | |
7 | of the BSD License which accompanies this distribution. The\r | |
8 | full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "BiosSnp16.h"\r | |
17 | \r | |
18 | \r | |
19 | ///\r | |
20 | /// EFI Driver Binding Protocol Instance\r | |
21 | ///\r | |
22 | EFI_DRIVER_BINDING_PROTOCOL gBiosSnp16DriverBinding = {\r | |
23 | BiosSnp16DriverBindingSupported,\r | |
24 | BiosSnp16DriverBindingStart,\r | |
25 | BiosSnp16DriverBindingStop,\r | |
26 | 0x3,\r | |
27 | NULL,\r | |
28 | NULL\r | |
29 | };\r | |
30 | \r | |
31 | ///\r | |
32 | /// This boolean is used to determine if we should release the cached vector during an error condition.\r | |
33 | ///\r | |
34 | BOOLEAN mCachedInt1A = FALSE;\r | |
35 | \r | |
36 | //\r | |
37 | // Private worker functions;\r | |
38 | //\r | |
39 | \r | |
40 | /**\r | |
41 | Start the UNDI interface.\r | |
42 | \r | |
43 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
44 | @param Ax PCI address of Undi device.\r | |
45 | \r | |
46 | @retval EFI_DEVICE_ERROR Fail to start 16 bit UNDI ROM. \r | |
47 | @retval Others Status of start 16 bit UNDI ROM. \r | |
48 | **/\r | |
49 | EFI_STATUS\r | |
50 | Undi16SimpleNetworkStartUndi (\r | |
51 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice,\r | |
52 | UINT16 Ax\r | |
53 | );\r | |
54 | \r | |
55 | /**\r | |
56 | Start the UNDI interface\r | |
57 | \r | |
58 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
59 | \r | |
60 | @retval EFI_DEVICE_ERROR Fail to start 16 bit UNDI ROM. \r | |
61 | @retval Others Status of start 16 bit UNDI ROM. \r | |
62 | **/\r | |
63 | EFI_STATUS\r | |
64 | Undi16SimpleNetworkStopUndi (\r | |
65 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice\r | |
66 | );\r | |
67 | \r | |
68 | /**\r | |
69 | Stop the UNDI interface\r | |
70 | \r | |
71 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
72 | \r | |
73 | @retval EFI_DEVICE_ERROR Fail to stop 16 bit UNDI ROM. \r | |
74 | @retval Others Status of stop 16 bit UNDI ROM. \r | |
75 | **/\r | |
76 | EFI_STATUS\r | |
77 | Undi16SimpleNetworkCleanupUndi (\r | |
78 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice\r | |
79 | );\r | |
80 | \r | |
81 | /**\r | |
82 | Get runtime information for Undi network interface\r | |
83 | \r | |
84 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
85 | \r | |
86 | @retval EFI_SUCCESS Sucess operation. \r | |
87 | @retval Others Fail to get runtime information for Undi network interface. \r | |
88 | **/\r | |
89 | EFI_STATUS\r | |
90 | Undi16SimpleNetworkGetInformation (\r | |
91 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
92 | );\r | |
93 | \r | |
94 | /**\r | |
95 | Get NIC type\r | |
96 | \r | |
97 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
98 | \r | |
99 | @retval EFI_SUCCESS Sucess operation. \r | |
100 | @retval Others Fail to get NIC type.\r | |
101 | **/\r | |
102 | EFI_STATUS\r | |
103 | Undi16SimpleNetworkGetNicType (\r | |
104 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
105 | );\r | |
106 | \r | |
107 | /**\r | |
108 | Get NDIS information\r | |
109 | \r | |
110 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
111 | \r | |
112 | @retval EFI_SUCCESS Sucess operation. \r | |
113 | @retval Others Fail to get NDIS information.\r | |
114 | **/\r | |
115 | EFI_STATUS\r | |
116 | Undi16SimpleNetworkGetNdisInfo (\r | |
117 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
118 | );\r | |
119 | \r | |
120 | /**\r | |
121 | Signal handlers for ExitBootServices event.\r | |
122 | \r | |
123 | Clean up any Real-mode UNDI residue from the system \r | |
124 | \r | |
125 | @param Event ExitBootServices event\r | |
126 | @param Context \r | |
127 | **/\r | |
128 | VOID\r | |
129 | EFIAPI\r | |
130 | Undi16SimpleNetworkEvent (\r | |
131 | IN EFI_EVENT Event,\r | |
132 | IN VOID *Context\r | |
133 | );\r | |
134 | \r | |
135 | /**\r | |
136 | Loads the undi driver.\r | |
137 | \r | |
138 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
139 | \r | |
140 | @retval EFI_SUCCESS - Successfully loads undi driver.\r | |
141 | @retval EFI_NOT_FOUND - Doesn't find undi driver or undi driver load failure.\r | |
142 | **/\r | |
143 | EFI_STATUS\r | |
144 | Undi16SimpleNetworkLoadUndi (\r | |
145 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice\r | |
146 | );\r | |
147 | \r | |
148 | /**\r | |
149 | Unload 16 bit UNDI Option ROM from memory\r | |
150 | \r | |
151 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
152 | \r | |
153 | @return EFI_STATUS \r | |
154 | **/\r | |
155 | EFI_STATUS\r | |
156 | Undi16SimpleNetworkUnloadUndi (\r | |
157 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice\r | |
158 | );\r | |
159 | \r | |
160 | /**\r | |
161 | Entry point for EFI drivers.\r | |
162 | \r | |
163 | @param ImageHandle Handle that identifies the loaded image.\r | |
164 | @param SystemTable System Table for this image.\r | |
165 | \r | |
166 | @return EFI_STATUS Return status from EfiLibInstallAllDriverProtocols. \r | |
167 | **/\r | |
168 | EFI_STATUS\r | |
169 | EFIAPI\r | |
170 | BiosSnp16DriverEntryPoint (\r | |
171 | IN EFI_HANDLE ImageHandle,\r | |
172 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
173 | )\r | |
174 | {\r | |
175 | return EfiLibInstallDriverBindingComponentName2 (\r | |
176 | ImageHandle,\r | |
177 | SystemTable,\r | |
178 | &gBiosSnp16DriverBinding,\r | |
179 | ImageHandle,\r | |
180 | &gBiosSnp16ComponentName,\r | |
181 | &gBiosSnp16ComponentName2\r | |
182 | );\r | |
183 | }\r | |
184 | \r | |
185 | //\r | |
186 | // EFI Driver Binding Protocol Functions\r | |
187 | //\r | |
188 | /**\r | |
189 | Tests to see if this driver supports a given controller.\r | |
190 | \r | |
191 | @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
192 | @param Controller The handle of the controller to test.\r | |
193 | @param RemainingDevicePath A pointer to the remaining portion of a device path.\r | |
194 | \r | |
195 | @retval EFI_SUCCESS The driver supports given controller.\r | |
196 | @retval EFI_UNSUPPORT The driver doesn't support given controller.\r | |
197 | @retval Other Other errors prevent driver finishing to test\r | |
198 | if the driver supports given controller.\r | |
199 | **/\r | |
200 | EFI_STATUS\r | |
201 | EFIAPI\r | |
202 | BiosSnp16DriverBindingSupported (\r | |
203 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
204 | IN EFI_HANDLE Controller,\r | |
205 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
206 | )\r | |
207 | {\r | |
208 | EFI_STATUS Status;\r | |
209 | EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r | |
210 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
211 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
212 | PCI_TYPE00 Pci;\r | |
213 | \r | |
214 | //\r | |
215 | // See if the Legacy BIOS Protocol is available\r | |
216 | //\r | |
217 | Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r | |
218 | if (EFI_ERROR (Status)) {\r | |
219 | return Status;\r | |
220 | }\r | |
221 | //\r | |
222 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
223 | //\r | |
224 | Status = gBS->OpenProtocol (\r | |
225 | Controller,\r | |
226 | &gEfiDevicePathProtocolGuid,\r | |
227 | (VOID **) &DevicePath,\r | |
228 | This->DriverBindingHandle,\r | |
229 | Controller,\r | |
230 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
231 | );\r | |
232 | if (EFI_ERROR (Status)) {\r | |
233 | return Status;\r | |
234 | }\r | |
235 | \r | |
236 | gBS->CloseProtocol (\r | |
237 | Controller,\r | |
238 | &gEfiDevicePathProtocolGuid,\r | |
239 | This->DriverBindingHandle,\r | |
240 | Controller\r | |
241 | );\r | |
242 | \r | |
243 | //\r | |
244 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
245 | //\r | |
246 | Status = gBS->OpenProtocol (\r | |
247 | Controller,\r | |
248 | &gEfiPciIoProtocolGuid,\r | |
249 | (VOID **) &PciIo,\r | |
250 | This->DriverBindingHandle,\r | |
251 | Controller,\r | |
252 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
253 | );\r | |
254 | if (EFI_ERROR (Status)) {\r | |
255 | return Status;\r | |
256 | }\r | |
257 | //\r | |
258 | // See if this is a PCI Network Controller by looking at the Command register and\r | |
259 | // Class Code Register\r | |
260 | //\r | |
261 | Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, sizeof (Pci) / sizeof (UINT32), &Pci);\r | |
262 | if (EFI_ERROR (Status)) {\r | |
263 | Status = EFI_UNSUPPORTED;\r | |
264 | goto Done;\r | |
265 | }\r | |
266 | \r | |
267 | Status = EFI_UNSUPPORTED;\r | |
268 | if (Pci.Hdr.ClassCode[2] == PCI_CLASS_NETWORK) {\r | |
269 | Status = EFI_SUCCESS;\r | |
270 | }\r | |
271 | \r | |
272 | Done:\r | |
273 | gBS->CloseProtocol (\r | |
274 | Controller,\r | |
275 | &gEfiPciIoProtocolGuid,\r | |
276 | This->DriverBindingHandle,\r | |
277 | Controller\r | |
278 | );\r | |
279 | \r | |
280 | return Status;\r | |
281 | }\r | |
282 | \r | |
283 | /**\r | |
284 | Starts the Snp device controller\r | |
285 | \r | |
286 | @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
287 | @param Controller The handle of the controller to test.\r | |
288 | @param RemainingDevicePath A pointer to the remaining portion of a device path.\r | |
289 | \r | |
290 | @retval EFI_SUCCESS - The device was started. \r | |
291 | @retval EFI_DEVICE_ERROR - The device could not be started due to a device error.\r | |
292 | @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r | |
293 | **/\r | |
294 | EFI_STATUS\r | |
295 | EFIAPI\r | |
296 | BiosSnp16DriverBindingStart (\r | |
297 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
298 | IN EFI_HANDLE Controller,\r | |
299 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
300 | )\r | |
301 | {\r | |
302 | EFI_STATUS Status;\r | |
303 | EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r | |
304 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
305 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
306 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
307 | EFI_DEV_PATH Node;\r | |
308 | UINTN Index;\r | |
309 | UINTN Index2;\r | |
310 | UINTN Segment;\r | |
311 | UINTN Bus;\r | |
312 | UINTN Device;\r | |
313 | UINTN Function;\r | |
314 | UINTN Flags;\r | |
315 | UINT64 Supports;\r | |
316 | \r | |
317 | SimpleNetworkDevice = NULL;\r | |
318 | PciIo = NULL;\r | |
319 | \r | |
320 | //\r | |
321 | // See if the Legacy BIOS Protocol is available\r | |
322 | //\r | |
323 | Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r | |
324 | if (EFI_ERROR (Status)) {\r | |
325 | return Status;\r | |
326 | }\r | |
327 | //\r | |
328 | // Open the IO Abstraction(s) needed\r | |
329 | //\r | |
330 | Status = gBS->OpenProtocol (\r | |
331 | Controller,\r | |
332 | &gEfiDevicePathProtocolGuid,\r | |
333 | (VOID **) &DevicePath,\r | |
334 | This->DriverBindingHandle,\r | |
335 | Controller,\r | |
336 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
337 | );\r | |
338 | if (EFI_ERROR (Status)) {\r | |
339 | goto Done;\r | |
340 | }\r | |
341 | \r | |
342 | Status = gBS->OpenProtocol (\r | |
343 | Controller,\r | |
344 | &gEfiPciIoProtocolGuid,\r | |
345 | (VOID **) &PciIo,\r | |
346 | This->DriverBindingHandle,\r | |
347 | Controller,\r | |
348 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
349 | );\r | |
350 | if (EFI_ERROR (Status)) {\r | |
351 | goto Done;\r | |
352 | }\r | |
353 | \r | |
354 | Status = PciIo->Attributes (\r | |
355 | PciIo,\r | |
356 | EfiPciIoAttributeOperationSupported,\r | |
357 | 0,\r | |
358 | &Supports\r | |
359 | );\r | |
360 | if (!EFI_ERROR (Status)) {\r | |
361 | Supports &= EFI_PCI_DEVICE_ENABLE;\r | |
362 | Status = PciIo->Attributes (\r | |
363 | PciIo,\r | |
364 | EfiPciIoAttributeOperationEnable,\r | |
365 | Supports,\r | |
366 | NULL\r | |
367 | );\r | |
368 | }\r | |
369 | \r | |
370 | if (EFI_ERROR (Status)) {\r | |
371 | goto Done;\r | |
372 | }\r | |
373 | //\r | |
374 | // Check to see if there is a legacy option ROM image associated with this PCI device\r | |
375 | //\r | |
376 | Status = LegacyBios->CheckPciRom (\r | |
377 | LegacyBios,\r | |
378 | Controller,\r | |
379 | NULL,\r | |
380 | NULL,\r | |
381 | &Flags\r | |
382 | );\r | |
383 | if (EFI_ERROR (Status)) {\r | |
384 | goto Done;\r | |
385 | }\r | |
386 | //\r | |
387 | // Post the legacy option ROM if it is available.\r | |
388 | //\r | |
389 | Status = LegacyBios->InstallPciRom (\r | |
390 | LegacyBios,\r | |
391 | Controller,\r | |
392 | NULL,\r | |
393 | &Flags,\r | |
394 | NULL,\r | |
395 | NULL,\r | |
396 | NULL,\r | |
397 | NULL\r | |
398 | );\r | |
399 | if (EFI_ERROR (Status)) {\r | |
400 | goto Done;\r | |
401 | }\r | |
402 | //\r | |
403 | // Allocate memory for this SimpleNetwork device instance\r | |
404 | //\r | |
405 | Status = gBS->AllocatePool (\r | |
406 | EfiBootServicesData,\r | |
407 | sizeof (EFI_SIMPLE_NETWORK_DEV),\r | |
408 | (VOID **) &SimpleNetworkDevice\r | |
409 | );\r | |
410 | if (EFI_ERROR (Status)) {\r | |
411 | Status = EFI_OUT_OF_RESOURCES;\r | |
412 | goto Done;\r | |
413 | }\r | |
414 | \r | |
415 | ZeroMem (SimpleNetworkDevice, sizeof (EFI_SIMPLE_NETWORK_DEV));\r | |
416 | \r | |
417 | //\r | |
418 | // Initialize the SimpleNetwork device instance\r | |
419 | //\r | |
420 | SimpleNetworkDevice->Signature = EFI_SIMPLE_NETWORK_DEV_SIGNATURE;\r | |
421 | SimpleNetworkDevice->LegacyBios = LegacyBios;\r | |
422 | SimpleNetworkDevice->BaseDevicePath = DevicePath;\r | |
423 | SimpleNetworkDevice->PciIo = PciIo;\r | |
424 | \r | |
425 | //\r | |
426 | // Initialize the Nii Protocol\r | |
427 | //\r | |
428 | SimpleNetworkDevice->Nii.Revision = EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION;\r | |
429 | SimpleNetworkDevice->Nii.Type = EfiNetworkInterfaceUndi;\r | |
430 | \r | |
431 | CopyMem (&SimpleNetworkDevice->Nii.StringId, "UNDI", 4);\r | |
432 | \r | |
433 | //\r | |
434 | // Load 16 bit UNDI Option ROM into Memory\r | |
435 | //\r | |
436 | Status = Undi16SimpleNetworkLoadUndi (SimpleNetworkDevice);\r | |
437 | if (EFI_ERROR (Status)) {\r | |
438 | DEBUG ((DEBUG_NET, "ERROR : Could not load UNDI. Status = %r\n", Status));\r | |
439 | goto Done;\r | |
440 | }\r | |
441 | \r | |
442 | SimpleNetworkDevice->UndiLoaded = TRUE;\r | |
443 | \r | |
444 | //\r | |
445 | // Call PXENV_START_UNDI - Initilizes the UNID interface for use.\r | |
446 | //\r | |
447 | PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function);\r | |
448 | Status = Undi16SimpleNetworkStartUndi (\r | |
449 | SimpleNetworkDevice,\r | |
450 | (UINT16) ((Bus << 0x8) | (Device << 0x3) | (Function))\r | |
451 | );\r | |
452 | if (EFI_ERROR (Status)) {\r | |
453 | DEBUG ((DEBUG_NET, "ERROR : Could not StartUndi. Status = %r\n", Status));\r | |
454 | goto Done;\r | |
455 | }\r | |
456 | //\r | |
457 | // Initialize the Simple Network Protocol\r | |
458 | //\r | |
459 | DEBUG ((DEBUG_NET, "Initialize SimpleNetworkDevice instance\n"));\r | |
460 | \r | |
461 | SimpleNetworkDevice->SimpleNetwork.Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;\r | |
462 | SimpleNetworkDevice->SimpleNetwork.Start = Undi16SimpleNetworkStart;\r | |
463 | SimpleNetworkDevice->SimpleNetwork.Stop = Undi16SimpleNetworkStop;\r | |
464 | SimpleNetworkDevice->SimpleNetwork.Initialize = Undi16SimpleNetworkInitialize;\r | |
465 | SimpleNetworkDevice->SimpleNetwork.Reset = Undi16SimpleNetworkReset;\r | |
466 | SimpleNetworkDevice->SimpleNetwork.Shutdown = Undi16SimpleNetworkShutdown;\r | |
467 | SimpleNetworkDevice->SimpleNetwork.ReceiveFilters = Undi16SimpleNetworkReceiveFilters;\r | |
468 | SimpleNetworkDevice->SimpleNetwork.StationAddress = Undi16SimpleNetworkStationAddress;\r | |
469 | SimpleNetworkDevice->SimpleNetwork.Statistics = Undi16SimpleNetworkStatistics;\r | |
470 | SimpleNetworkDevice->SimpleNetwork.MCastIpToMac = Undi16SimpleNetworkMCastIpToMac;\r | |
471 | SimpleNetworkDevice->SimpleNetwork.NvData = Undi16SimpleNetworkNvData;\r | |
472 | SimpleNetworkDevice->SimpleNetwork.GetStatus = Undi16SimpleNetworkGetStatus;\r | |
473 | SimpleNetworkDevice->SimpleNetwork.Transmit = Undi16SimpleNetworkTransmit;\r | |
474 | SimpleNetworkDevice->SimpleNetwork.Receive = Undi16SimpleNetworkReceive;\r | |
475 | SimpleNetworkDevice->SimpleNetwork.Mode = &(SimpleNetworkDevice->SimpleNetworkMode);\r | |
476 | \r | |
477 | Status = gBS->CreateEvent (\r | |
478 | EVT_NOTIFY_WAIT,\r | |
479 | TPL_NOTIFY,\r | |
480 | Undi16SimpleNetworkWaitForPacket,\r | |
481 | &SimpleNetworkDevice->SimpleNetwork,\r | |
482 | &SimpleNetworkDevice->SimpleNetwork.WaitForPacket\r | |
483 | );\r | |
484 | if (EFI_ERROR (Status)) {\r | |
485 | DEBUG ((DEBUG_ERROR, "ERROR : Could not create event. Status = %r\n", Status));\r | |
486 | goto Done;\r | |
487 | }\r | |
488 | //\r | |
489 | // Create an event to be signalled when ExitBootServices occurs in order\r | |
490 | // to clean up nicely\r | |
491 | //\r | |
492 | Status = gBS->CreateEventEx (\r | |
493 | EVT_NOTIFY_SIGNAL,\r | |
494 | TPL_NOTIFY,\r | |
495 | Undi16SimpleNetworkEvent,\r | |
496 | NULL,\r | |
497 | &gEfiEventExitBootServicesGuid,\r | |
498 | &SimpleNetworkDevice->EfiBootEvent\r | |
499 | );\r | |
500 | if (EFI_ERROR (Status)) {\r | |
501 | DEBUG ((DEBUG_ERROR, "ERROR : Could not create event. Status = %r\n", Status));\r | |
502 | goto Done;\r | |
503 | }\r | |
504 | \r | |
505 | //\r | |
506 | // Create an event to be signalled when Legacy Boot occurs to clean up the IVT\r | |
507 | //\r | |
508 | Status = EfiCreateEventLegacyBootEx(\r | |
509 | TPL_NOTIFY, \r | |
510 | Undi16SimpleNetworkEvent, \r | |
511 | NULL, \r | |
512 | &SimpleNetworkDevice->LegacyBootEvent\r | |
513 | );\r | |
514 | \r | |
515 | if (EFI_ERROR(Status)) {\r | |
516 | DEBUG ((DEBUG_ERROR,"ERROR : Could not create event. Status = %r\n",Status));\r | |
517 | goto Done;\r | |
518 | }\r | |
519 | \r | |
520 | //\r | |
521 | // Initialize the SimpleNetwork Mode Information\r | |
522 | //\r | |
523 | DEBUG ((DEBUG_NET, "Initialize Mode Information\n"));\r | |
524 | \r | |
525 | SimpleNetworkDevice->SimpleNetworkMode.State = EfiSimpleNetworkStopped;\r | |
526 | SimpleNetworkDevice->SimpleNetworkMode.MediaHeaderSize = 14;\r | |
527 | SimpleNetworkDevice->SimpleNetworkMode.MacAddressChangeable = TRUE;\r | |
528 | SimpleNetworkDevice->SimpleNetworkMode.MultipleTxSupported = TRUE;\r | |
529 | SimpleNetworkDevice->SimpleNetworkMode.ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST |\r | |
530 | EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST |\r | |
531 | EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST |\r | |
532 | EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS |\r | |
533 | EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;\r | |
534 | SimpleNetworkDevice->SimpleNetworkMode.MaxMCastFilterCount = MAXNUM_MCADDR;\r | |
535 | \r | |
536 | //\r | |
537 | // Initialize the SimpleNetwork Private Information\r | |
538 | //\r | |
539 | DEBUG ((DEBUG_NET, "Initialize Private Information\n"));\r | |
540 | \r | |
541 | Status = BiosSnp16AllocatePagesBelowOneMb (\r | |
542 | sizeof (PXENV_UNDI_TBD_T) / EFI_PAGE_SIZE + 1,\r | |
543 | (VOID **) &SimpleNetworkDevice->Xmit\r | |
544 | );\r | |
545 | if (EFI_ERROR (Status)) {\r | |
546 | goto Done;\r | |
547 | }\r | |
548 | \r | |
549 | Status = BiosSnp16AllocatePagesBelowOneMb (\r | |
550 | 1,\r | |
551 | &SimpleNetworkDevice->TxRealModeMediaHeader\r | |
552 | );\r | |
553 | if (EFI_ERROR (Status)) {\r | |
554 | goto Done;\r | |
555 | }\r | |
556 | \r | |
557 | Status = BiosSnp16AllocatePagesBelowOneMb (\r | |
558 | 1,\r | |
559 | &SimpleNetworkDevice->TxRealModeDataBuffer\r | |
560 | );\r | |
561 | if (EFI_ERROR (Status)) {\r | |
562 | goto Done;\r | |
563 | }\r | |
564 | \r | |
565 | Status = BiosSnp16AllocatePagesBelowOneMb (\r | |
566 | 1,\r | |
567 | &SimpleNetworkDevice->TxDestAddr\r | |
568 | );\r | |
569 | if (EFI_ERROR (Status)) {\r | |
570 | goto Done;\r | |
571 | }\r | |
572 | \r | |
573 | SimpleNetworkDevice->Xmit->XmitOffset = (UINT16) (((UINT32)(UINTN) SimpleNetworkDevice->TxRealModeMediaHeader) & 0x000f);\r | |
574 | \r | |
575 | SimpleNetworkDevice->Xmit->XmitSegment = (UINT16) (((UINT32)(UINTN) SimpleNetworkDevice->TxRealModeMediaHeader) >> 4);\r | |
576 | \r | |
577 | SimpleNetworkDevice->Xmit->DataBlkCount = 1;\r | |
578 | \r | |
579 | SimpleNetworkDevice->Xmit->DataBlock[0].TDPtrType = 1;\r | |
580 | SimpleNetworkDevice->Xmit->DataBlock[0].TDRsvdByte = 0;\r | |
581 | \r | |
582 | SimpleNetworkDevice->Xmit->DataBlock[0].TDDataPtrOffset = (UINT16) (((UINT32)(UINTN) SimpleNetworkDevice->TxRealModeDataBuffer) & 0x000f);\r | |
583 | \r | |
584 | SimpleNetworkDevice->Xmit->DataBlock[0].TDDataPtrSegment = (UINT16) (((UINT32)(UINTN) SimpleNetworkDevice->TxRealModeDataBuffer) >> 4);\r | |
585 | \r | |
586 | SimpleNetworkDevice->TxBufferFifo.First = 0;\r | |
587 | SimpleNetworkDevice->TxBufferFifo.Last = 0;\r | |
588 | \r | |
589 | //\r | |
590 | // Start() the SimpleNetwork device\r | |
591 | //\r | |
592 | DEBUG ((DEBUG_NET, "Start()\n"));\r | |
593 | \r | |
594 | Status = Undi16SimpleNetworkStart (&SimpleNetworkDevice->SimpleNetwork);\r | |
595 | if (EFI_ERROR (Status)) {\r | |
596 | goto Done;\r | |
597 | }\r | |
598 | //\r | |
599 | // GetInformation() the SimpleNetwork device\r | |
600 | //\r | |
601 | DEBUG ((DEBUG_NET, "GetInformation()\n"));\r | |
602 | \r | |
603 | Status = Undi16SimpleNetworkGetInformation (&SimpleNetworkDevice->SimpleNetwork);\r | |
604 | if (EFI_ERROR (Status)) {\r | |
605 | goto Done;\r | |
606 | }\r | |
607 | //\r | |
608 | // Build the device path for the child device\r | |
609 | //\r | |
610 | ZeroMem (&Node, sizeof (Node));\r | |
611 | Node.DevPath.Type = MESSAGING_DEVICE_PATH;\r | |
612 | Node.DevPath.SubType = MSG_MAC_ADDR_DP;\r | |
613 | SetDevicePathNodeLength (&Node.DevPath, sizeof (MAC_ADDR_DEVICE_PATH));\r | |
614 | CopyMem (\r | |
615 | &Node.MacAddr.MacAddress,\r | |
616 | &SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress,\r | |
617 | sizeof (EFI_MAC_ADDRESS)\r | |
618 | );\r | |
619 | SimpleNetworkDevice->DevicePath = AppendDevicePathNode (\r | |
620 | SimpleNetworkDevice->BaseDevicePath,\r | |
621 | &Node.DevPath\r | |
622 | );\r | |
623 | \r | |
624 | //\r | |
625 | // GetNicType() the SimpleNetwork device\r | |
626 | //\r | |
627 | DEBUG ((DEBUG_NET, "GetNicType()\n"));\r | |
628 | \r | |
629 | Status = Undi16SimpleNetworkGetNicType (&SimpleNetworkDevice->SimpleNetwork);\r | |
630 | if (EFI_ERROR (Status)) {\r | |
631 | goto Done;\r | |
632 | }\r | |
633 | //\r | |
634 | // GetNdisInfo() the SimpleNetwork device\r | |
635 | //\r | |
636 | DEBUG ((DEBUG_NET, "GetNdisInfo()\n"));\r | |
637 | \r | |
638 | Status = Undi16SimpleNetworkGetNdisInfo (&SimpleNetworkDevice->SimpleNetwork);\r | |
639 | if (EFI_ERROR (Status)) {\r | |
640 | goto Done;\r | |
641 | }\r | |
642 | //\r | |
643 | // Stop() the SimpleNetwork device\r | |
644 | //\r | |
645 | DEBUG ((DEBUG_NET, "Stop()\n"));\r | |
646 | \r | |
647 | Status = SimpleNetworkDevice->SimpleNetwork.Stop (&SimpleNetworkDevice->SimpleNetwork);\r | |
648 | if (EFI_ERROR (Status)) {\r | |
649 | goto Done;\r | |
650 | }\r | |
651 | //\r | |
652 | // Print Mode information\r | |
653 | //\r | |
654 | DEBUG ((DEBUG_NET, "Mode->State = %d\n", SimpleNetworkDevice->SimpleNetworkMode.State));\r | |
655 | DEBUG ((DEBUG_NET, "Mode->HwAddressSize = %d\n", SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize));\r | |
656 | DEBUG ((DEBUG_NET, "Mode->MacAddressChangeable = %d\n", SimpleNetworkDevice->SimpleNetworkMode.MacAddressChangeable));\r | |
657 | DEBUG ((DEBUG_NET, "Mode->MultiplTxSupported = %d\n", SimpleNetworkDevice->SimpleNetworkMode.MultipleTxSupported));\r | |
658 | DEBUG ((DEBUG_NET, "Mode->NvRamSize = %d\n", SimpleNetworkDevice->SimpleNetworkMode.NvRamSize));\r | |
659 | DEBUG ((DEBUG_NET, "Mode->NvRamAccessSize = %d\n", SimpleNetworkDevice->SimpleNetworkMode.NvRamAccessSize));\r | |
660 | DEBUG ((DEBUG_NET, "Mode->ReceiveFilterSetting = %d\n", SimpleNetworkDevice->SimpleNetworkMode.ReceiveFilterSetting));\r | |
661 | DEBUG ((DEBUG_NET, "Mode->IfType = %d\n", SimpleNetworkDevice->SimpleNetworkMode.IfType));\r | |
662 | DEBUG ((DEBUG_NET, "Mode->MCastFilterCount = %d\n", SimpleNetworkDevice->SimpleNetworkMode.MCastFilterCount));\r | |
663 | for (Index = 0; Index < SimpleNetworkDevice->SimpleNetworkMode.MCastFilterCount; Index++) {\r | |
664 | DEBUG ((DEBUG_NET, " Filter[%02d] = ", Index));\r | |
665 | for (Index2 = 0; Index2 < 16; Index2++) {\r | |
666 | DEBUG ((DEBUG_NET, "%02x ", SimpleNetworkDevice->SimpleNetworkMode.MCastFilter[Index].Addr[Index2]));\r | |
667 | }\r | |
668 | \r | |
669 | DEBUG ((DEBUG_NET, "\n"));\r | |
670 | }\r | |
671 | \r | |
672 | DEBUG ((DEBUG_NET, "CurrentAddress = "));\r | |
673 | for (Index2 = 0; Index2 < 16; Index2++) {\r | |
674 | DEBUG ((DEBUG_NET, "%02x ", SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress.Addr[Index2]));\r | |
675 | }\r | |
676 | \r | |
677 | DEBUG ((DEBUG_NET, "\n"));\r | |
678 | \r | |
679 | DEBUG ((DEBUG_NET, "BroadcastAddress = "));\r | |
680 | for (Index2 = 0; Index2 < 16; Index2++) {\r | |
681 | DEBUG ((DEBUG_NET, "%02x ", SimpleNetworkDevice->SimpleNetworkMode.BroadcastAddress.Addr[Index2]));\r | |
682 | }\r | |
683 | \r | |
684 | DEBUG ((DEBUG_NET, "\n"));\r | |
685 | \r | |
686 | DEBUG ((DEBUG_NET, "PermanentAddress = "));\r | |
687 | for (Index2 = 0; Index2 < 16; Index2++) {\r | |
688 | DEBUG ((DEBUG_NET, "%02x ", SimpleNetworkDevice->SimpleNetworkMode.PermanentAddress.Addr[Index2]));\r | |
689 | }\r | |
690 | \r | |
691 | DEBUG ((DEBUG_NET, "\n"));\r | |
692 | \r | |
693 | //\r | |
694 | // The network device was started, information collected, and stopped.\r | |
695 | // Install protocol interfaces for the SimpleNetwork device.\r | |
696 | //\r | |
697 | DEBUG ((DEBUG_NET, "Install Protocol Interfaces on network interface\n"));\r | |
698 | \r | |
699 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
700 | &SimpleNetworkDevice->Handle,\r | |
701 | &gEfiSimpleNetworkProtocolGuid,\r | |
702 | &SimpleNetworkDevice->SimpleNetwork,\r | |
703 | &gEfiNetworkInterfaceIdentifierProtocolGuid,\r | |
704 | &SimpleNetworkDevice->Nii,\r | |
705 | &gEfiDevicePathProtocolGuid,\r | |
706 | SimpleNetworkDevice->DevicePath,\r | |
707 | NULL\r | |
708 | );\r | |
709 | if (EFI_ERROR (Status)) {\r | |
710 | goto Done;\r | |
711 | }\r | |
712 | //\r | |
713 | // Open PCI I/O from the newly created child handle\r | |
714 | //\r | |
715 | Status = gBS->OpenProtocol (\r | |
716 | Controller,\r | |
717 | &gEfiPciIoProtocolGuid,\r | |
718 | (VOID **) &PciIo,\r | |
719 | This->DriverBindingHandle,\r | |
720 | SimpleNetworkDevice->Handle,\r | |
721 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
722 | );\r | |
723 | \r | |
724 | DEBUG ((DEBUG_INIT, "UNDI16 Driver : EFI_SUCCESS\n"));\r | |
725 | \r | |
726 | Done:\r | |
727 | if (EFI_ERROR (Status)) {\r | |
728 | if (SimpleNetworkDevice != NULL) {\r | |
729 | \r | |
730 | Undi16SimpleNetworkShutdown (&SimpleNetworkDevice->SimpleNetwork);\r | |
731 | //\r | |
732 | // CLOSE + SHUTDOWN\r | |
733 | //\r | |
734 | Undi16SimpleNetworkCleanupUndi (SimpleNetworkDevice);\r | |
735 | //\r | |
736 | // CLEANUP\r | |
737 | //\r | |
738 | Undi16SimpleNetworkStopUndi (SimpleNetworkDevice);\r | |
739 | //\r | |
740 | // STOP\r | |
741 | //\r | |
742 | if (SimpleNetworkDevice->UndiLoaded) {\r | |
743 | Undi16SimpleNetworkUnloadUndi (SimpleNetworkDevice);\r | |
744 | }\r | |
745 | \r | |
746 | if (SimpleNetworkDevice->SimpleNetwork.WaitForPacket != NULL) {\r | |
747 | gBS->CloseEvent (SimpleNetworkDevice->SimpleNetwork.WaitForPacket);\r | |
748 | }\r | |
749 | \r | |
750 | if (SimpleNetworkDevice->LegacyBootEvent != NULL) {\r | |
751 | gBS->CloseEvent (SimpleNetworkDevice->LegacyBootEvent);\r | |
752 | }\r | |
753 | \r | |
754 | if (SimpleNetworkDevice->EfiBootEvent != NULL) {\r | |
755 | gBS->CloseEvent (SimpleNetworkDevice->EfiBootEvent);\r | |
756 | }\r | |
757 | \r | |
758 | if (SimpleNetworkDevice->Xmit != NULL) {\r | |
759 | gBS->FreePages (\r | |
760 | (EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->Xmit,\r | |
761 | sizeof (PXENV_UNDI_TBD_T) / EFI_PAGE_SIZE + 1\r | |
762 | );\r | |
763 | }\r | |
764 | \r | |
765 | if (SimpleNetworkDevice->TxRealModeMediaHeader != NULL) {\r | |
766 | gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->TxRealModeMediaHeader, 1);\r | |
767 | }\r | |
768 | \r | |
769 | if (SimpleNetworkDevice->TxRealModeDataBuffer != NULL) {\r | |
770 | gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->TxRealModeDataBuffer, 1);\r | |
771 | }\r | |
772 | \r | |
773 | if (SimpleNetworkDevice->TxDestAddr != NULL) {\r | |
774 | gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->TxDestAddr, 1);\r | |
775 | }\r | |
776 | \r | |
777 | gBS->FreePool (SimpleNetworkDevice);\r | |
778 | \r | |
779 | //\r | |
780 | // Only restore the vector if it was cached.\r | |
781 | //\r | |
782 | if (mCachedInt1A) {\r | |
783 | RestoreCachedVectorAddress (0x1A);\r | |
784 | mCachedInt1A = FALSE;\r | |
785 | }\r | |
786 | }\r | |
787 | \r | |
788 | if (PciIo != NULL) {\r | |
789 | Status = PciIo->Attributes (\r | |
790 | PciIo,\r | |
791 | EfiPciIoAttributeOperationSupported,\r | |
792 | 0,\r | |
793 | &Supports\r | |
794 | );\r | |
795 | if (!EFI_ERROR (Status)) {\r | |
796 | Supports &= EFI_PCI_DEVICE_ENABLE;\r | |
797 | Status = PciIo->Attributes (\r | |
798 | PciIo,\r | |
799 | EfiPciIoAttributeOperationDisable,\r | |
800 | Supports,\r | |
801 | NULL\r | |
802 | );\r | |
803 | }\r | |
804 | }\r | |
805 | \r | |
806 | gBS->CloseProtocol (\r | |
807 | Controller,\r | |
808 | &gEfiPciIoProtocolGuid,\r | |
809 | This->DriverBindingHandle,\r | |
810 | Controller\r | |
811 | );\r | |
812 | \r | |
813 | gBS->CloseProtocol (\r | |
814 | Controller,\r | |
815 | &gEfiDevicePathProtocolGuid,\r | |
816 | This->DriverBindingHandle,\r | |
817 | Controller\r | |
818 | );\r | |
819 | if (Status != EFI_OUT_OF_RESOURCES) {\r | |
820 | Status = EFI_DEVICE_ERROR;\r | |
821 | }\r | |
822 | } \r | |
823 | return Status;\r | |
824 | }\r | |
825 | \r | |
826 | /**\r | |
827 | Stops the device by given device controller.\r | |
828 | \r | |
829 | @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
830 | @param Controller The handle of the controller to test.\r | |
831 | @param NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
832 | @param ChildHandleBuffer An array of child handles to be freed. May be NULL if\r | |
833 | NumberOfChildren is 0.\r | |
834 | \r | |
835 | @retval EFI_SUCCESS - The device was stopped.\r | |
836 | @retval EFI_DEVICE_ERROR - The device could not be stopped due to a device error.\r | |
837 | **/\r | |
838 | EFI_STATUS\r | |
839 | EFIAPI\r | |
840 | BiosSnp16DriverBindingStop (\r | |
841 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
842 | IN EFI_HANDLE Controller,\r | |
843 | IN UINTN NumberOfChildren,\r | |
844 | IN EFI_HANDLE *ChildHandleBuffer\r | |
845 | )\r | |
846 | {\r | |
847 | EFI_STATUS Status;\r | |
848 | UINTN Index;\r | |
849 | BOOLEAN AllChildrenStopped;\r | |
850 | EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNetwork;\r | |
851 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
852 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
853 | UINT64 Supports;\r | |
854 | \r | |
855 | //\r | |
856 | // Complete all outstanding transactions to Controller.\r | |
857 | // Don't allow any new transaction to Controller to be started.\r | |
858 | //\r | |
859 | if (NumberOfChildren == 0) {\r | |
860 | //\r | |
861 | // Close the bus driver\r | |
862 | //\r | |
863 | Status = gBS->OpenProtocol (\r | |
864 | Controller,\r | |
865 | &gEfiPciIoProtocolGuid,\r | |
866 | (VOID **) &PciIo,\r | |
867 | This->DriverBindingHandle,\r | |
868 | Controller,\r | |
869 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
870 | );\r | |
871 | if (!EFI_ERROR (Status)) {\r | |
872 | Status = PciIo->Attributes (\r | |
873 | PciIo,\r | |
874 | EfiPciIoAttributeOperationSupported,\r | |
875 | 0,\r | |
876 | &Supports\r | |
877 | );\r | |
878 | if (!EFI_ERROR (Status)) {\r | |
879 | Supports &= EFI_PCI_DEVICE_ENABLE;\r | |
880 | Status = PciIo->Attributes (\r | |
881 | PciIo,\r | |
882 | EfiPciIoAttributeOperationDisable,\r | |
883 | Supports,\r | |
884 | NULL\r | |
885 | );\r | |
886 | }\r | |
887 | }\r | |
888 | \r | |
889 | Status = gBS->CloseProtocol (\r | |
890 | Controller,\r | |
891 | &gEfiPciIoProtocolGuid,\r | |
892 | This->DriverBindingHandle,\r | |
893 | Controller\r | |
894 | );\r | |
895 | \r | |
896 | Status = gBS->CloseProtocol (\r | |
897 | Controller,\r | |
898 | &gEfiDevicePathProtocolGuid,\r | |
899 | This->DriverBindingHandle,\r | |
900 | Controller\r | |
901 | );\r | |
902 | \r | |
903 | if (EFI_ERROR (Status)) {\r | |
904 | Status = EFI_DEVICE_ERROR;\r | |
905 | }\r | |
906 | return Status;\r | |
907 | }\r | |
908 | \r | |
909 | AllChildrenStopped = TRUE;\r | |
910 | \r | |
911 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
912 | \r | |
913 | Status = gBS->OpenProtocol (\r | |
914 | ChildHandleBuffer[Index],\r | |
915 | &gEfiSimpleNetworkProtocolGuid,\r | |
916 | (VOID **) &SimpleNetwork,\r | |
917 | This->DriverBindingHandle,\r | |
918 | Controller,\r | |
919 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
920 | );\r | |
921 | if (!EFI_ERROR (Status)) {\r | |
922 | \r | |
923 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (SimpleNetwork);\r | |
924 | \r | |
925 | Status = gBS->CloseProtocol (\r | |
926 | Controller,\r | |
927 | &gEfiPciIoProtocolGuid,\r | |
928 | This->DriverBindingHandle,\r | |
929 | ChildHandleBuffer[Index]\r | |
930 | );\r | |
931 | \r | |
932 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
933 | SimpleNetworkDevice->Handle,\r | |
934 | &gEfiSimpleNetworkProtocolGuid,\r | |
935 | &SimpleNetworkDevice->SimpleNetwork,\r | |
936 | &gEfiNetworkInterfaceIdentifierProtocolGuid,\r | |
937 | &SimpleNetworkDevice->Nii,\r | |
938 | &gEfiDevicePathProtocolGuid,\r | |
939 | SimpleNetworkDevice->DevicePath,\r | |
940 | NULL\r | |
941 | );\r | |
942 | if (EFI_ERROR (Status)) {\r | |
943 | gBS->OpenProtocol (\r | |
944 | Controller,\r | |
945 | &gEfiPciIoProtocolGuid,\r | |
946 | (VOID **) &PciIo,\r | |
947 | This->DriverBindingHandle,\r | |
948 | ChildHandleBuffer[Index],\r | |
949 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
950 | );\r | |
951 | } else {\r | |
952 | \r | |
953 | Undi16SimpleNetworkShutdown (&SimpleNetworkDevice->SimpleNetwork);\r | |
954 | //\r | |
955 | // CLOSE + SHUTDOWN\r | |
956 | //\r | |
957 | Undi16SimpleNetworkCleanupUndi (SimpleNetworkDevice);\r | |
958 | //\r | |
959 | // CLEANUP\r | |
960 | //\r | |
961 | Undi16SimpleNetworkStopUndi (SimpleNetworkDevice);\r | |
962 | //\r | |
963 | // STOP\r | |
964 | //\r | |
965 | if (SimpleNetworkDevice->UndiLoaded) {\r | |
966 | Undi16SimpleNetworkUnloadUndi (SimpleNetworkDevice);\r | |
967 | }\r | |
968 | \r | |
969 | if (SimpleNetworkDevice->SimpleNetwork.WaitForPacket != NULL) {\r | |
970 | gBS->CloseEvent (SimpleNetworkDevice->SimpleNetwork.WaitForPacket);\r | |
971 | }\r | |
972 | \r | |
973 | if (SimpleNetworkDevice->LegacyBootEvent != NULL) {\r | |
974 | gBS->CloseEvent (SimpleNetworkDevice->LegacyBootEvent);\r | |
975 | }\r | |
976 | \r | |
977 | if (SimpleNetworkDevice->EfiBootEvent != NULL) {\r | |
978 | gBS->CloseEvent (SimpleNetworkDevice->EfiBootEvent);\r | |
979 | }\r | |
980 | \r | |
981 | if (SimpleNetworkDevice->Xmit != NULL) {\r | |
982 | gBS->FreePages (\r | |
983 | (EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->Xmit,\r | |
984 | sizeof (PXENV_UNDI_TBD_T) / EFI_PAGE_SIZE + 1\r | |
985 | );\r | |
986 | }\r | |
987 | \r | |
988 | if (SimpleNetworkDevice->TxRealModeMediaHeader != NULL) {\r | |
989 | gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->TxRealModeMediaHeader, 1);\r | |
990 | }\r | |
991 | \r | |
992 | if (SimpleNetworkDevice->TxRealModeDataBuffer != NULL) {\r | |
993 | gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->TxRealModeDataBuffer, 1);\r | |
994 | }\r | |
995 | \r | |
996 | if (SimpleNetworkDevice->TxDestAddr != NULL) {\r | |
997 | gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->TxDestAddr, 1);\r | |
998 | }\r | |
999 | \r | |
1000 | gBS->FreePool (SimpleNetworkDevice);\r | |
1001 | }\r | |
1002 | \r | |
1003 | }\r | |
1004 | \r | |
1005 | if (EFI_ERROR (Status)) {\r | |
1006 | AllChildrenStopped = FALSE;\r | |
1007 | }\r | |
1008 | }\r | |
1009 | \r | |
1010 | if (!AllChildrenStopped) {\r | |
1011 | return EFI_DEVICE_ERROR;\r | |
1012 | }\r | |
1013 | \r | |
1014 | return EFI_SUCCESS;\r | |
1015 | }\r | |
1016 | \r | |
1017 | //\r | |
1018 | // FIFO Support Functions\r | |
1019 | //\r | |
1020 | /**\r | |
1021 | Judge whether transmit FIFO is full.\r | |
1022 | \r | |
1023 | @param Fifo Point to trasmit FIFO structure.\r | |
1024 | \r | |
1025 | @return BOOLEAN whether transmit FIFO is full.\r | |
1026 | **/\r | |
1027 | BOOLEAN\r | |
1028 | SimpleNetworkTransmitFifoFull (\r | |
1029 | EFI_SIMPLE_NETWORK_DEV_FIFO *Fifo\r | |
1030 | )\r | |
1031 | {\r | |
1032 | if (((Fifo->Last + 1) % EFI_SIMPLE_NETWORK_MAX_TX_FIFO_SIZE) == Fifo->First) {\r | |
1033 | return TRUE;\r | |
1034 | }\r | |
1035 | \r | |
1036 | return FALSE;\r | |
1037 | }\r | |
1038 | \r | |
1039 | /**\r | |
1040 | Judge whether transmit FIFO is empty.\r | |
1041 | \r | |
1042 | @param Fifo Point to trasmit FIFO structure.\r | |
1043 | \r | |
1044 | @return BOOLEAN whether transmit FIFO is empty.\r | |
1045 | **/\r | |
1046 | BOOLEAN\r | |
1047 | SimpleNetworkTransmitFifoEmpty (\r | |
1048 | EFI_SIMPLE_NETWORK_DEV_FIFO *Fifo\r | |
1049 | )\r | |
1050 | {\r | |
1051 | if (Fifo->Last == Fifo->First) {\r | |
1052 | return TRUE;\r | |
1053 | }\r | |
1054 | \r | |
1055 | return FALSE;\r | |
1056 | }\r | |
1057 | \r | |
1058 | \r | |
1059 | /**\r | |
1060 | Add data into transmit buffer.\r | |
1061 | \r | |
1062 | @param Fifo Point to trasmit FIFO structure.\r | |
1063 | @param Data The data point want to be added.\r | |
1064 | \r | |
1065 | @retval EFI_OUT_OF_RESOURCES FIFO is full \r | |
1066 | @retval EFI_SUCCESS Success operation. \r | |
1067 | **/\r | |
1068 | EFI_STATUS\r | |
1069 | SimpleNetworkTransmitFifoAdd (\r | |
1070 | EFI_SIMPLE_NETWORK_DEV_FIFO *Fifo,\r | |
1071 | VOID *Data\r | |
1072 | )\r | |
1073 | {\r | |
1074 | if (SimpleNetworkTransmitFifoFull (Fifo)) {\r | |
1075 | return EFI_OUT_OF_RESOURCES;\r | |
1076 | }\r | |
1077 | \r | |
1078 | Fifo->Data[Fifo->Last] = Data;\r | |
1079 | Fifo->Last = (Fifo->Last + 1) % EFI_SIMPLE_NETWORK_MAX_TX_FIFO_SIZE;\r | |
1080 | return EFI_SUCCESS;\r | |
1081 | }\r | |
1082 | \r | |
1083 | /**\r | |
1084 | Get a data and remove it from network transmit FIFO.\r | |
1085 | \r | |
1086 | @param Fifo Point to trasmit FIFO structure.\r | |
1087 | @param Data On return, point to the data point want to be got and removed.\r | |
1088 | \r | |
1089 | @retval EFI_OUT_OF_RESOURCES network transmit buffer is empty. \r | |
1090 | @retval EFI_SUCCESS Success operation. \r | |
1091 | **/\r | |
1092 | EFI_STATUS\r | |
1093 | SimpleNetworkTransmitFifoRemove (\r | |
1094 | EFI_SIMPLE_NETWORK_DEV_FIFO *Fifo,\r | |
1095 | VOID **Data\r | |
1096 | )\r | |
1097 | {\r | |
1098 | if (SimpleNetworkTransmitFifoEmpty (Fifo)) {\r | |
1099 | return EFI_OUT_OF_RESOURCES;\r | |
1100 | }\r | |
1101 | \r | |
1102 | *Data = Fifo->Data[Fifo->First];\r | |
1103 | Fifo->First = (Fifo->First + 1) % EFI_SIMPLE_NETWORK_MAX_TX_FIFO_SIZE;\r | |
1104 | return EFI_SUCCESS;\r | |
1105 | }\r | |
1106 | \r | |
1107 | /**\r | |
1108 | Get recive filter setting according to EFI mask value.\r | |
1109 | \r | |
1110 | @param ReceiveFilterSetting filter setting EFI mask value.\r | |
1111 | \r | |
1112 | @return UINT16 Undi filter setting value.\r | |
1113 | **/\r | |
1114 | UINT16\r | |
1115 | Undi16GetPacketFilterSetting (\r | |
1116 | UINTN ReceiveFilterSetting\r | |
1117 | )\r | |
1118 | {\r | |
1119 | UINT16 PktFilter;\r | |
1120 | \r | |
1121 | PktFilter = 0;\r | |
1122 | if ((ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_UNICAST) != 0) {\r | |
1123 | PktFilter |= FLTR_DIRECTED;\r | |
1124 | }\r | |
1125 | \r | |
1126 | if ((ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0) {\r | |
1127 | PktFilter |= FLTR_DIRECTED;\r | |
1128 | }\r | |
1129 | \r | |
1130 | if ((ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) != 0) {\r | |
1131 | PktFilter |= FLTR_BRDCST;\r | |
1132 | }\r | |
1133 | \r | |
1134 | if ((ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) != 0) {\r | |
1135 | PktFilter |= FLTR_PRMSCS;\r | |
1136 | }\r | |
1137 | \r | |
1138 | if ((ReceiveFilterSetting & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) != 0) {\r | |
1139 | PktFilter |= FLTR_PRMSCS;\r | |
1140 | //\r | |
1141 | // @bug : Do not know if this is right????\r | |
1142 | //\r | |
1143 | }\r | |
1144 | //\r | |
1145 | // @bug : What is FLTR_SRC_RTG?\r | |
1146 | //\r | |
1147 | return PktFilter;\r | |
1148 | }\r | |
1149 | \r | |
1150 | /**\r | |
1151 | Get filter setting from multi cast buffer .\r | |
1152 | \r | |
1153 | @param Mode Point to mode structure.\r | |
1154 | @param McastBuffer The multi cast buffer \r | |
1155 | @param HwAddressSize Size of filter value.\r | |
1156 | \r | |
1157 | **/\r | |
1158 | VOID\r | |
1159 | Undi16GetMCastFilters (\r | |
1160 | IN EFI_SIMPLE_NETWORK_MODE *Mode,\r | |
1161 | IN OUT PXENV_UNDI_MCAST_ADDR_T *McastBuffer,\r | |
1162 | IN UINTN HwAddressSize\r | |
1163 | )\r | |
1164 | {\r | |
1165 | UINTN Index;\r | |
1166 | \r | |
1167 | //\r | |
1168 | // @bug : What if Mode->MCastFilterCount > MAXNUM_MCADDR?\r | |
1169 | //\r | |
1170 | McastBuffer->MCastAddrCount = (UINT16) Mode->MCastFilterCount;\r | |
1171 | for (Index = 0; Index < MAXNUM_MCADDR; Index++) {\r | |
1172 | if (Index < McastBuffer->MCastAddrCount) {\r | |
1173 | CopyMem (&McastBuffer->MCastAddr[Index], &Mode->MCastFilter[Index], HwAddressSize);\r | |
1174 | } else {\r | |
1175 | ZeroMem (&McastBuffer->MCastAddr[Index], HwAddressSize);\r | |
1176 | }\r | |
1177 | }\r | |
1178 | }\r | |
1179 | //\r | |
1180 | // Load 16 bit UNDI Option ROM into memory\r | |
1181 | //\r | |
1182 | /**\r | |
1183 | Loads the undi driver.\r | |
1184 | \r | |
1185 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
1186 | \r | |
1187 | @retval EFI_SUCCESS - Successfully loads undi driver.\r | |
1188 | @retval EFI_NOT_FOUND - Doesn't find undi driver or undi driver load failure.\r | |
1189 | **/\r | |
1190 | EFI_STATUS\r | |
1191 | Undi16SimpleNetworkLoadUndi (\r | |
1192 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice\r | |
1193 | )\r | |
1194 | {\r | |
1195 | EFI_STATUS Status;\r | |
1196 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
1197 | UINTN RomAddress;\r | |
1198 | PCI_EXPANSION_ROM_HEADER *PciExpansionRomHeader;\r | |
1199 | PCI_DATA_STRUCTURE *PciDataStructure;\r | |
1200 | PCI_TYPE00 Pci;\r | |
1201 | \r | |
1202 | if (!mCachedInt1A) {\r | |
1203 | Status = CacheVectorAddress (0x1A);\r | |
1204 | if (!EFI_ERROR (Status)) {\r | |
1205 | mCachedInt1A = TRUE; \r | |
1206 | }\r | |
1207 | }\r | |
1208 | \r | |
1209 | PciIo = SimpleNetworkDevice->PciIo;\r | |
1210 | \r | |
1211 | PciIo->Pci.Read (\r | |
1212 | PciIo,\r | |
1213 | EfiPciIoWidthUint32,\r | |
1214 | 0,\r | |
1215 | sizeof (Pci) / sizeof (UINT32),\r | |
1216 | &Pci\r | |
1217 | );\r | |
1218 | \r | |
1219 | for (RomAddress = 0xc0000; RomAddress < 0xfffff; RomAddress += 0x800) {\r | |
1220 | \r | |
1221 | PciExpansionRomHeader = (PCI_EXPANSION_ROM_HEADER *) RomAddress;\r | |
1222 | \r | |
1223 | if (PciExpansionRomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {\r | |
1224 | continue;\r | |
1225 | }\r | |
1226 | \r | |
1227 | DEBUG ((DEBUG_INIT, "Option ROM found at %X\n", RomAddress));\r | |
1228 | \r | |
94020bb4 | 1229 | //\r |
1230 | // If the pointer to the PCI Data Structure is invalid, no further images can be located. \r | |
1231 | // The PCI Data Structure must be DWORD aligned. \r | |
1232 | //\r | |
1233 | if (PciExpansionRomHeader->PcirOffset == 0 ||\r | |
1234 | (PciExpansionRomHeader->PcirOffset & 3) != 0 ||\r | |
1235 | RomAddress + PciExpansionRomHeader->PcirOffset + sizeof (PCI_DATA_STRUCTURE) > 0x100000) {\r | |
1236 | break;\r | |
1237 | }\r | |
1238 | \r | |
bcecde14 | 1239 | PciDataStructure = (PCI_DATA_STRUCTURE *) (RomAddress + PciExpansionRomHeader->PcirOffset);\r |
1240 | \r | |
1241 | if (PciDataStructure->Signature != PCI_DATA_STRUCTURE_SIGNATURE) {\r | |
1242 | continue;\r | |
1243 | }\r | |
1244 | \r | |
1245 | DEBUG ((DEBUG_INIT, "PCI Data Structure found at %X\n", PciDataStructure));\r | |
1246 | \r | |
1247 | if (PciDataStructure->VendorId != Pci.Hdr.VendorId || PciDataStructure->DeviceId != Pci.Hdr.DeviceId) {\r | |
1248 | continue;\r | |
1249 | }\r | |
1250 | \r | |
1251 | DEBUG (\r | |
1252 | (DEBUG_INIT, \r | |
1253 | "PCI device with matchinng VendorId and DeviceId (%d,%d)\n",\r | |
1254 | (UINTN) PciDataStructure->VendorId,\r | |
1255 | (UINTN) PciDataStructure->DeviceId)\r | |
1256 | );\r | |
1257 | \r | |
1258 | Status = LaunchBaseCode (SimpleNetworkDevice, RomAddress);\r | |
1259 | \r | |
1260 | if (!EFI_ERROR (Status)) {\r | |
1261 | return EFI_SUCCESS;\r | |
1262 | }\r | |
9f6c5db2 EL |
1263 | \r |
1264 | //\r | |
1265 | // Free resources allocated in LaunchBaseCode\r | |
1266 | //\r | |
1267 | Undi16SimpleNetworkUnloadUndi (SimpleNetworkDevice);\r | |
bcecde14 | 1268 | }\r |
1269 | \r | |
1270 | return EFI_NOT_FOUND;\r | |
1271 | }\r | |
1272 | \r | |
1273 | /**\r | |
1274 | Unload 16 bit UNDI Option ROM from memory\r | |
1275 | \r | |
1276 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
1277 | \r | |
1278 | @return EFI_STATUS \r | |
1279 | **/\r | |
1280 | EFI_STATUS\r | |
1281 | Undi16SimpleNetworkUnloadUndi (\r | |
1282 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice\r | |
1283 | )\r | |
1284 | {\r | |
1285 | if (SimpleNetworkDevice->UndiLoaderTable != NULL) {\r | |
1286 | ZeroMem (SimpleNetworkDevice->UndiLoaderTable, SimpleNetworkDevice->UndiLoaderTablePages << EFI_PAGE_SHIFT);\r | |
1287 | gBS->FreePages (\r | |
1288 | (EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->UndiLoaderTable,\r | |
1289 | SimpleNetworkDevice->UndiLoaderTablePages\r | |
1290 | );\r | |
1291 | }\r | |
1292 | \r | |
1293 | if (SimpleNetworkDevice->DestinationDataSegment != NULL) {\r | |
1294 | ZeroMem (\r | |
1295 | SimpleNetworkDevice->DestinationDataSegment,\r | |
1296 | SimpleNetworkDevice->DestinationDataSegmentPages << EFI_PAGE_SHIFT\r | |
1297 | );\r | |
1298 | gBS->FreePages (\r | |
1299 | (EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->DestinationDataSegment,\r | |
1300 | SimpleNetworkDevice->DestinationDataSegmentPages\r | |
1301 | );\r | |
1302 | }\r | |
1303 | \r | |
1304 | if (SimpleNetworkDevice->DestinationStackSegment != NULL) {\r | |
1305 | ZeroMem (\r | |
1306 | SimpleNetworkDevice->DestinationStackSegment,\r | |
1307 | SimpleNetworkDevice->DestinationStackSegmentPages << EFI_PAGE_SHIFT\r | |
1308 | );\r | |
1309 | gBS->FreePages (\r | |
1310 | (EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->DestinationStackSegment,\r | |
1311 | SimpleNetworkDevice->DestinationStackSegmentPages\r | |
1312 | );\r | |
1313 | }\r | |
1314 | \r | |
1315 | if (SimpleNetworkDevice->DestinationCodeSegment != NULL) {\r | |
1316 | ZeroMem (\r | |
1317 | SimpleNetworkDevice->DestinationCodeSegment,\r | |
1318 | SimpleNetworkDevice->DestinationCodeSegmentPages << EFI_PAGE_SHIFT\r | |
1319 | );\r | |
1320 | gBS->FreePages (\r | |
1321 | (EFI_PHYSICAL_ADDRESS) (UINTN) SimpleNetworkDevice->DestinationCodeSegment,\r | |
1322 | SimpleNetworkDevice->DestinationCodeSegmentPages\r | |
1323 | );\r | |
1324 | }\r | |
1325 | \r | |
1326 | return EFI_SUCCESS;\r | |
1327 | }\r | |
1328 | \r | |
1329 | /**\r | |
1330 | Start the UNDI interface.\r | |
1331 | \r | |
1332 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
1333 | @param Ax PCI address of Undi device.\r | |
1334 | \r | |
1335 | @retval EFI_DEVICE_ERROR Fail to start 16 bit UNDI ROM. \r | |
1336 | @retval Others Status of start 16 bit UNDI ROM. \r | |
1337 | **/\r | |
1338 | EFI_STATUS\r | |
1339 | Undi16SimpleNetworkStartUndi (\r | |
1340 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice,\r | |
1341 | UINT16 Ax\r | |
1342 | )\r | |
1343 | {\r | |
1344 | EFI_STATUS Status;\r | |
1345 | PXENV_START_UNDI_T Start;\r | |
1346 | \r | |
1347 | //\r | |
1348 | // Call 16 bit UNDI ROM to start the network interface\r | |
1349 | //\r | |
1350 | //\r | |
1351 | // @bug : What is this state supposed to be???\r | |
1352 | //\r | |
1353 | Start.Status = INIT_PXE_STATUS;\r | |
1354 | Start.Ax = Ax;\r | |
1355 | Start.Bx = 0x0000;\r | |
1356 | Start.Dx = 0x0000;\r | |
1357 | Start.Di = 0x0000;\r | |
1358 | Start.Es = 0x0000;\r | |
1359 | \r | |
1360 | Status = PxeStartUndi (SimpleNetworkDevice, &Start);\r | |
1361 | if (EFI_ERROR (Status)) {\r | |
1362 | return Status;\r | |
1363 | }\r | |
1364 | //\r | |
1365 | // Check the status code from the 16 bit UNDI ROM\r | |
1366 | //\r | |
1367 | if (Start.Status != PXENV_STATUS_SUCCESS) {\r | |
1368 | return EFI_DEVICE_ERROR;\r | |
1369 | }\r | |
1370 | \r | |
1371 | return Status;\r | |
1372 | }\r | |
1373 | \r | |
1374 | \r | |
1375 | /**\r | |
1376 | Stop the UNDI interface\r | |
1377 | \r | |
1378 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
1379 | \r | |
1380 | @retval EFI_DEVICE_ERROR Fail to stop 16 bit UNDI ROM. \r | |
1381 | @retval Others Status of stop 16 bit UNDI ROM. \r | |
1382 | **/\r | |
1383 | EFI_STATUS\r | |
1384 | Undi16SimpleNetworkStopUndi (\r | |
1385 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice\r | |
1386 | )\r | |
1387 | {\r | |
1388 | EFI_STATUS Status;\r | |
1389 | PXENV_STOP_UNDI_T Stop;\r | |
1390 | \r | |
1391 | //\r | |
1392 | // Call 16 bit UNDI ROM to start the network interface\r | |
1393 | //\r | |
1394 | Stop.Status = INIT_PXE_STATUS;\r | |
1395 | \r | |
1396 | Status = PxeUndiStop (SimpleNetworkDevice, &Stop);\r | |
1397 | if (EFI_ERROR (Status)) {\r | |
1398 | return Status;\r | |
1399 | }\r | |
1400 | //\r | |
1401 | // Check the status code from the 16 bit UNDI ROM\r | |
1402 | //\r | |
1403 | if (Stop.Status != PXENV_STATUS_SUCCESS) {\r | |
1404 | return EFI_DEVICE_ERROR;\r | |
1405 | }\r | |
1406 | \r | |
1407 | return Status;\r | |
1408 | }\r | |
1409 | \r | |
1410 | /**\r | |
1411 | Cleanup Unid network interface\r | |
1412 | \r | |
1413 | @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.\r | |
1414 | \r | |
1415 | @retval EFI_DEVICE_ERROR Fail to cleanup 16 bit UNDI ROM. \r | |
1416 | @retval Others Status of cleanup 16 bit UNDI ROM. \r | |
1417 | **/\r | |
1418 | EFI_STATUS\r | |
1419 | Undi16SimpleNetworkCleanupUndi (\r | |
1420 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice\r | |
1421 | )\r | |
1422 | {\r | |
1423 | EFI_STATUS Status;\r | |
1424 | PXENV_UNDI_CLEANUP_T Cleanup;\r | |
1425 | \r | |
1426 | //\r | |
1427 | // Call 16 bit UNDI ROM to cleanup the network interface\r | |
1428 | //\r | |
1429 | Cleanup.Status = INIT_PXE_STATUS;\r | |
1430 | \r | |
1431 | Status = PxeUndiCleanup (SimpleNetworkDevice, &Cleanup);\r | |
1432 | if (EFI_ERROR (Status)) {\r | |
1433 | return Status;\r | |
1434 | }\r | |
1435 | //\r | |
1436 | // Check the status code from the 16 bit UNDI ROM\r | |
1437 | //\r | |
1438 | if (Cleanup.Status != PXENV_STATUS_SUCCESS) {\r | |
1439 | return EFI_DEVICE_ERROR;\r | |
1440 | }\r | |
1441 | \r | |
1442 | return Status;\r | |
1443 | }\r | |
1444 | \r | |
1445 | /**\r | |
1446 | Get runtime information for Undi network interface\r | |
1447 | \r | |
1448 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
1449 | \r | |
1450 | @retval EFI_SUCCESS Sucess operation. \r | |
1451 | @retval Others Fail to get runtime information for Undi network interface. \r | |
1452 | **/\r | |
1453 | EFI_STATUS\r | |
1454 | Undi16SimpleNetworkGetInformation (\r | |
1455 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
1456 | )\r | |
1457 | {\r | |
1458 | EFI_STATUS Status;\r | |
1459 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
1460 | UINTN Index;\r | |
1461 | \r | |
1462 | if (This == NULL) {\r | |
1463 | return EFI_INVALID_PARAMETER;\r | |
1464 | }\r | |
1465 | \r | |
1466 | Status = EFI_SUCCESS;\r | |
1467 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
1468 | \r | |
1469 | if (SimpleNetworkDevice == NULL) {\r | |
1470 | return EFI_DEVICE_ERROR;\r | |
1471 | }\r | |
1472 | //\r | |
1473 | // Verify that the current state of the adapter is valid for this call.\r | |
1474 | //\r | |
1475 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
1476 | case EfiSimpleNetworkStarted:\r | |
1477 | case EfiSimpleNetworkInitialized:\r | |
1478 | break;\r | |
1479 | \r | |
1480 | case EfiSimpleNetworkStopped:\r | |
1481 | return EFI_NOT_STARTED;\r | |
1482 | \r | |
1483 | default:\r | |
1484 | return EFI_DEVICE_ERROR;\r | |
1485 | }\r | |
1486 | //\r | |
1487 | // Call 16 bit UNDI ROM to start the network interface\r | |
1488 | //\r | |
1489 | ZeroMem (&SimpleNetworkDevice->GetInformation, sizeof (PXENV_UNDI_GET_INFORMATION_T));\r | |
1490 | \r | |
1491 | SimpleNetworkDevice->GetInformation.Status = INIT_PXE_STATUS;\r | |
1492 | \r | |
1493 | Status = PxeUndiGetInformation (SimpleNetworkDevice, &SimpleNetworkDevice->GetInformation);\r | |
1494 | if (EFI_ERROR (Status)) {\r | |
1495 | return Status;\r | |
1496 | }\r | |
1497 | \r | |
1498 | DEBUG ((DEBUG_NET, " GetInformation.Status = %d\n", SimpleNetworkDevice->GetInformation.Status));\r | |
1499 | DEBUG ((DEBUG_NET, " GetInformation.BaseIo = %d\n", SimpleNetworkDevice->GetInformation.BaseIo));\r | |
1500 | DEBUG ((DEBUG_NET, " GetInformation.IntNumber = %d\n", SimpleNetworkDevice->GetInformation.IntNumber));\r | |
1501 | DEBUG ((DEBUG_NET, " GetInformation.MaxTranUnit = %d\n", SimpleNetworkDevice->GetInformation.MaxTranUnit));\r | |
1502 | DEBUG ((DEBUG_NET, " GetInformation.HwType = %d\n", SimpleNetworkDevice->GetInformation.HwType));\r | |
1503 | DEBUG ((DEBUG_NET, " GetInformation.HwAddrLen = %d\n", SimpleNetworkDevice->GetInformation.HwAddrLen));\r | |
1504 | DEBUG ((DEBUG_NET, " GetInformation.ROMAddress = %d\n", SimpleNetworkDevice->GetInformation.ROMAddress));\r | |
1505 | DEBUG ((DEBUG_NET, " GetInformation.RxBufCt = %d\n", SimpleNetworkDevice->GetInformation.RxBufCt));\r | |
1506 | DEBUG ((DEBUG_NET, " GetInformation.TxBufCt = %d\n", SimpleNetworkDevice->GetInformation.TxBufCt));\r | |
1507 | \r | |
1508 | DEBUG ((DEBUG_NET, " GetInformation.CurNodeAddr ="));\r | |
1509 | for (Index = 0; Index < 16; Index++) {\r | |
1510 | DEBUG ((DEBUG_NET, "%02x ", SimpleNetworkDevice->GetInformation.CurrentNodeAddress[Index]));\r | |
1511 | }\r | |
1512 | \r | |
1513 | DEBUG ((DEBUG_NET, "\n"));\r | |
1514 | \r | |
1515 | DEBUG ((DEBUG_NET, " GetInformation.PermNodeAddr ="));\r | |
1516 | for (Index = 0; Index < 16; Index++) {\r | |
1517 | DEBUG ((DEBUG_NET, "%02x ", SimpleNetworkDevice->GetInformation.PermNodeAddress[Index]));\r | |
1518 | }\r | |
1519 | \r | |
1520 | DEBUG ((DEBUG_NET, "\n"));\r | |
1521 | \r | |
1522 | //\r | |
1523 | // Check the status code from the 16 bit UNDI ROM\r | |
1524 | //\r | |
1525 | if (SimpleNetworkDevice->GetInformation.Status != PXENV_STATUS_SUCCESS) {\r | |
1526 | return EFI_DEVICE_ERROR;\r | |
1527 | }\r | |
1528 | //\r | |
1529 | // The information has been retrieved. Fill in Mode data.\r | |
1530 | //\r | |
1531 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize = SimpleNetworkDevice->GetInformation.HwAddrLen;\r | |
1532 | \r | |
1533 | SimpleNetworkDevice->SimpleNetworkMode.MaxPacketSize = SimpleNetworkDevice->GetInformation.MaxTranUnit;\r | |
1534 | \r | |
1535 | SimpleNetworkDevice->SimpleNetworkMode.IfType = (UINT8) SimpleNetworkDevice->GetInformation.HwType;\r | |
1536 | \r | |
1537 | ZeroMem (\r | |
1538 | &SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress,\r | |
1539 | sizeof SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress\r | |
1540 | );\r | |
1541 | \r | |
1542 | CopyMem (\r | |
1543 | &SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress,\r | |
1544 | &SimpleNetworkDevice->GetInformation.CurrentNodeAddress,\r | |
1545 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
1546 | );\r | |
1547 | \r | |
1548 | ZeroMem (\r | |
1549 | &SimpleNetworkDevice->SimpleNetworkMode.PermanentAddress,\r | |
1550 | sizeof SimpleNetworkDevice->SimpleNetworkMode.PermanentAddress\r | |
1551 | );\r | |
1552 | \r | |
1553 | CopyMem (\r | |
1554 | &SimpleNetworkDevice->SimpleNetworkMode.PermanentAddress,\r | |
1555 | &SimpleNetworkDevice->GetInformation.PermNodeAddress,\r | |
1556 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
1557 | );\r | |
1558 | \r | |
1559 | //\r | |
1560 | // hard code broadcast address - not avail in PXE2.1\r | |
1561 | //\r | |
1562 | ZeroMem (\r | |
1563 | &SimpleNetworkDevice->SimpleNetworkMode.BroadcastAddress,\r | |
1564 | sizeof SimpleNetworkDevice->SimpleNetworkMode.BroadcastAddress\r | |
1565 | );\r | |
1566 | \r | |
1567 | SetMem (\r | |
1568 | &SimpleNetworkDevice->SimpleNetworkMode.BroadcastAddress,\r | |
1569 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize,\r | |
1570 | 0xff\r | |
1571 | );\r | |
1572 | \r | |
1573 | return Status;\r | |
1574 | }\r | |
1575 | \r | |
1576 | /**\r | |
1577 | Get NIC type\r | |
1578 | \r | |
1579 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
1580 | \r | |
1581 | @retval EFI_SUCCESS Sucess operation. \r | |
1582 | @retval Others Fail to get NIC type.\r | |
1583 | **/\r | |
1584 | EFI_STATUS\r | |
1585 | Undi16SimpleNetworkGetNicType (\r | |
1586 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
1587 | )\r | |
1588 | {\r | |
1589 | EFI_STATUS Status;\r | |
1590 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
1591 | \r | |
1592 | if (This == NULL) {\r | |
1593 | return EFI_INVALID_PARAMETER;\r | |
1594 | }\r | |
1595 | \r | |
1596 | Status = EFI_SUCCESS;\r | |
1597 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
1598 | \r | |
1599 | if (SimpleNetworkDevice == NULL) {\r | |
1600 | return EFI_DEVICE_ERROR;\r | |
1601 | }\r | |
1602 | \r | |
1603 | ZeroMem (&SimpleNetworkDevice->GetNicType, sizeof (PXENV_UNDI_GET_NIC_TYPE_T));\r | |
1604 | \r | |
1605 | SimpleNetworkDevice->GetNicType.Status = INIT_PXE_STATUS;\r | |
1606 | \r | |
1607 | Status = PxeUndiGetNicType (SimpleNetworkDevice, &SimpleNetworkDevice->GetNicType);\r | |
1608 | \r | |
1609 | if (EFI_ERROR (Status)) {\r | |
1610 | return Status;\r | |
1611 | }\r | |
1612 | \r | |
1613 | DEBUG ((DEBUG_NET, " GetNicType.Status = %d\n", SimpleNetworkDevice->GetNicType.Status));\r | |
1614 | DEBUG ((DEBUG_NET, " GetNicType.NicType = %d\n", SimpleNetworkDevice->GetNicType.NicType));\r | |
1615 | //\r | |
1616 | // Check the status code from the 16 bit UNDI ROM\r | |
1617 | //\r | |
1618 | if (SimpleNetworkDevice->GetNicType.Status != PXENV_STATUS_SUCCESS) {\r | |
1619 | return EFI_DEVICE_ERROR;\r | |
1620 | }\r | |
1621 | //\r | |
1622 | // The information has been retrieved. Fill in Mode data.\r | |
1623 | //\r | |
1624 | return Status;\r | |
1625 | }\r | |
1626 | \r | |
1627 | /**\r | |
1628 | Get NDIS information\r | |
1629 | \r | |
1630 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
1631 | \r | |
1632 | @retval EFI_SUCCESS Sucess operation. \r | |
1633 | @retval Others Fail to get NDIS information.\r | |
1634 | **/\r | |
1635 | EFI_STATUS\r | |
1636 | Undi16SimpleNetworkGetNdisInfo (\r | |
1637 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
1638 | )\r | |
1639 | {\r | |
1640 | EFI_STATUS Status;\r | |
1641 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
1642 | \r | |
1643 | if (This == NULL) {\r | |
1644 | return EFI_INVALID_PARAMETER;\r | |
1645 | }\r | |
1646 | \r | |
1647 | Status = EFI_SUCCESS;\r | |
1648 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
1649 | \r | |
1650 | if (SimpleNetworkDevice == NULL) {\r | |
1651 | return EFI_DEVICE_ERROR;\r | |
1652 | }\r | |
1653 | \r | |
1654 | ZeroMem (&SimpleNetworkDevice->GetNdisInfo, sizeof (PXENV_UNDI_GET_NDIS_INFO_T));\r | |
1655 | \r | |
1656 | SimpleNetworkDevice->GetNdisInfo.Status = INIT_PXE_STATUS;\r | |
1657 | \r | |
1658 | Status = PxeUndiGetNdisInfo (SimpleNetworkDevice, &SimpleNetworkDevice->GetNdisInfo);\r | |
1659 | \r | |
1660 | if (EFI_ERROR (Status)) {\r | |
1661 | return Status;\r | |
1662 | }\r | |
1663 | \r | |
1664 | DEBUG ((DEBUG_NET, " GetNdisInfo.Status = %d\n", SimpleNetworkDevice->GetNdisInfo.Status));\r | |
1665 | DEBUG ((DEBUG_NET, " GetNdisInfo.IfaceType = %a\n", SimpleNetworkDevice->GetNdisInfo.IfaceType));\r | |
1666 | DEBUG ((DEBUG_NET, " GetNdisInfo.LinkSpeed = %d\n", SimpleNetworkDevice->GetNdisInfo.LinkSpeed));\r | |
1667 | DEBUG ((DEBUG_NET, " GetNdisInfo.ServiceFlags = %08x\n", SimpleNetworkDevice->GetNdisInfo.ServiceFlags));\r | |
1668 | \r | |
1669 | //\r | |
1670 | // Check the status code from the 16 bit UNDI ROM\r | |
1671 | //\r | |
1672 | if (SimpleNetworkDevice->GetNdisInfo.Status != PXENV_STATUS_SUCCESS) {\r | |
1673 | return EFI_DEVICE_ERROR;\r | |
1674 | }\r | |
1675 | //\r | |
1676 | // The information has been retrieved. Fill in Mode data.\r | |
1677 | //\r | |
1678 | return Status;\r | |
1679 | }\r | |
1680 | \r | |
1681 | /**\r | |
1682 | Call Undi ROM 16bit ISR() to check interrupt cause.\r | |
1683 | \r | |
1684 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
1685 | @param FrameLength The length of frame buffer.\r | |
1686 | @param FrameHeaderLength The length of frame buffer's header if has.\r | |
1687 | @param Frame The frame buffer to process network interrupt.\r | |
1688 | @param ProtType The type network transmit protocol\r | |
1689 | @param PktType The type of package.\r | |
1690 | \r | |
1691 | @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM's ISR, or status is invalid. \r | |
1692 | @retval EFI_SUCCESS Success operation. \r | |
1693 | **/\r | |
1694 | EFI_STATUS\r | |
1695 | Undi16SimpleNetworkIsr (\r | |
1696 | IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r | |
1697 | IN UINTN *FrameLength,\r | |
1698 | IN UINTN *FrameHeaderLength, OPTIONAL\r | |
1699 | IN UINT8 *Frame, OPTIONAL\r | |
1700 | IN UINT8 *ProtType, OPTIONAL\r | |
1701 | IN UINT8 *PktType OPTIONAL\r | |
1702 | )\r | |
1703 | {\r | |
1704 | EFI_STATUS Status;\r | |
1705 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
1706 | BOOLEAN FrameReceived;\r | |
1707 | \r | |
1708 | if (This == NULL) {\r | |
1709 | return EFI_INVALID_PARAMETER;\r | |
1710 | }\r | |
1711 | \r | |
1712 | Status = EFI_SUCCESS;\r | |
1713 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
1714 | \r | |
1715 | if (SimpleNetworkDevice == NULL) {\r | |
1716 | return EFI_DEVICE_ERROR;\r | |
1717 | }\r | |
1718 | \r | |
1719 | FrameReceived = FALSE;\r | |
1720 | \r | |
1721 | //\r | |
1722 | // Verify that the current state of the adapter is valid for this call.\r | |
1723 | //\r | |
1724 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
1725 | case EfiSimpleNetworkInitialized:\r | |
1726 | break;\r | |
1727 | \r | |
1728 | case EfiSimpleNetworkStopped:\r | |
1729 | return EFI_NOT_STARTED;\r | |
1730 | \r | |
1731 | case EfiSimpleNetworkStarted:\r | |
1732 | default:\r | |
1733 | return EFI_DEVICE_ERROR;\r | |
1734 | }\r | |
1735 | \r | |
1736 | DEBUG ((DEBUG_NET, "Isr() IsrValid = %d\n", SimpleNetworkDevice->IsrValid));\r | |
1737 | \r | |
1738 | if (!SimpleNetworkDevice->IsrValid) {\r | |
1739 | //\r | |
1740 | // Call 16 bit UNDI ROM to open the network interface\r | |
1741 | //\r | |
1742 | ZeroMem (&SimpleNetworkDevice->Isr, sizeof (PXENV_UNDI_ISR_T));\r | |
1743 | SimpleNetworkDevice->Isr.Status = INIT_PXE_STATUS;\r | |
1744 | SimpleNetworkDevice->Isr.FuncFlag = PXENV_UNDI_ISR_IN_START;\r | |
1745 | \r | |
1746 | DEBUG ((DEBUG_NET, "Isr() START\n"));\r | |
1747 | \r | |
1748 | Status = PxeUndiIsr (SimpleNetworkDevice, &SimpleNetworkDevice->Isr);\r | |
1749 | if (EFI_ERROR (Status)) {\r | |
1750 | return Status;\r | |
1751 | }\r | |
1752 | //\r | |
1753 | // Check the status code from the 16 bit UNDI ROM\r | |
1754 | //\r | |
1755 | if (SimpleNetworkDevice->Isr.Status != PXENV_STATUS_SUCCESS) {\r | |
1756 | return EFI_DEVICE_ERROR;\r | |
1757 | }\r | |
1758 | //\r | |
1759 | // There have been no events on this UNDI interface, so return EFI_NOT_READY\r | |
1760 | //\r | |
1761 | if (SimpleNetworkDevice->Isr.FuncFlag == PXENV_UNDI_ISR_OUT_NOT_OURS) {\r | |
1762 | return EFI_SUCCESS;\r | |
1763 | }\r | |
1764 | //\r | |
1765 | // There is data to process, so call until all events processed.\r | |
1766 | //\r | |
1767 | ZeroMem (&SimpleNetworkDevice->Isr, sizeof (PXENV_UNDI_ISR_T));\r | |
1768 | SimpleNetworkDevice->Isr.Status = INIT_PXE_STATUS;\r | |
1769 | SimpleNetworkDevice->Isr.FuncFlag = PXENV_UNDI_ISR_IN_PROCESS;\r | |
1770 | \r | |
1771 | DEBUG ((DEBUG_NET, "Isr() PROCESS\n"));\r | |
1772 | \r | |
1773 | Status = PxeUndiIsr (SimpleNetworkDevice, &SimpleNetworkDevice->Isr);\r | |
1774 | if (EFI_ERROR (Status)) {\r | |
1775 | return Status;\r | |
1776 | }\r | |
1777 | \r | |
1778 | SimpleNetworkDevice->IsrValid = TRUE;\r | |
1779 | }\r | |
1780 | //\r | |
1781 | // Call UNDI GET_NEXT until DONE\r | |
1782 | //\r | |
1783 | while (SimpleNetworkDevice->Isr.FuncFlag != PXENV_UNDI_ISR_OUT_DONE) {\r | |
1784 | //\r | |
1785 | // Check the status code from the 16 bit UNDI ROM\r | |
1786 | //\r | |
1787 | if (SimpleNetworkDevice->Isr.Status != PXENV_STATUS_SUCCESS) {\r | |
1788 | return EFI_DEVICE_ERROR;\r | |
1789 | }\r | |
1790 | //\r | |
1791 | // UNDI is busy. Caller will have to call again.\r | |
1792 | // This should never happen with a polled mode driver.\r | |
1793 | //\r | |
1794 | if (SimpleNetworkDevice->Isr.FuncFlag == PXENV_UNDI_ISR_OUT_BUSY) {\r | |
1795 | DEBUG ((DEBUG_NET, " BUSY\n"));\r | |
1796 | return EFI_SUCCESS;\r | |
1797 | }\r | |
1798 | //\r | |
1799 | // Check for invalud UNDI FuncFlag\r | |
1800 | //\r | |
1801 | if (SimpleNetworkDevice->Isr.FuncFlag != PXENV_UNDI_ISR_OUT_RECEIVE &&\r | |
1802 | SimpleNetworkDevice->Isr.FuncFlag != PXENV_UNDI_ISR_OUT_TRANSMIT\r | |
1803 | ) {\r | |
1804 | DEBUG ((DEBUG_NET, " Invalid SimpleNetworkDevice->Isr.FuncFlag value %d\n", SimpleNetworkDevice->Isr.FuncFlag));\r | |
1805 | return EFI_DEVICE_ERROR;\r | |
1806 | }\r | |
1807 | //\r | |
1808 | // Check for Transmit Event\r | |
1809 | //\r | |
1810 | if (SimpleNetworkDevice->Isr.FuncFlag == PXENV_UNDI_ISR_OUT_TRANSMIT) {\r | |
1811 | DEBUG ((DEBUG_NET, " TRANSMIT\n"));\r | |
1812 | SimpleNetworkDevice->InterruptStatus |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r | |
1813 | }\r | |
1814 | //\r | |
1815 | // Check for Receive Event\r | |
1816 | //\r | |
1817 | else if (SimpleNetworkDevice->Isr.FuncFlag == PXENV_UNDI_ISR_OUT_RECEIVE) {\r | |
1818 | //\r | |
1819 | // note - this code will hang on a receive interrupt in a GetStatus loop\r | |
1820 | //\r | |
1821 | DEBUG ((DEBUG_NET, " RECEIVE\n"));\r | |
1822 | SimpleNetworkDevice->InterruptStatus |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;\r | |
1823 | \r | |
1824 | DEBUG ((DEBUG_NET, "SimpleNetworkDevice->Isr.BufferLength = %d\n", SimpleNetworkDevice->Isr.BufferLength));\r | |
1825 | DEBUG ((DEBUG_NET, "SimpleNetworkDevice->Isr.FrameLength = %d\n", SimpleNetworkDevice->Isr.FrameLength));\r | |
1826 | DEBUG ((DEBUG_NET, "SimpleNetworkDevice->Isr.FrameHeaderLength = %d\n", SimpleNetworkDevice->Isr.FrameHeaderLength));\r | |
1827 | DEBUG (\r | |
1828 | (\r | |
1829 | DEBUG_NET, "SimpleNetworkDevice->Isr.Frame = %04x:%04x\n", SimpleNetworkDevice->Isr.FrameSegSel,\r | |
1830 | SimpleNetworkDevice->Isr.FrameOffset\r | |
1831 | )\r | |
1832 | );\r | |
1833 | DEBUG ((DEBUG_NET, "SimpleNetworkDevice->Isr.ProtType = 0x%02x\n", SimpleNetworkDevice->Isr.BufferLength));\r | |
1834 | DEBUG ((DEBUG_NET, "SimpleNetworkDevice->Isr.PktType = 0x%02x\n", SimpleNetworkDevice->Isr.BufferLength));\r | |
1835 | \r | |
1836 | if (FrameReceived) {\r | |
1837 | return EFI_SUCCESS;\r | |
1838 | }\r | |
1839 | \r | |
1840 | if ((Frame == NULL) || (SimpleNetworkDevice->Isr.FrameLength > *FrameLength)) {\r | |
1841 | DEBUG ((DEBUG_NET, "return EFI_BUFFER_TOO_SMALL *FrameLength = %08x\n", *FrameLength));\r | |
1842 | *FrameLength = SimpleNetworkDevice->Isr.FrameLength;\r | |
1843 | return EFI_BUFFER_TOO_SMALL;\r | |
1844 | }\r | |
1845 | \r | |
1846 | *FrameLength = SimpleNetworkDevice->Isr.FrameLength;\r | |
1847 | if (FrameHeaderLength != NULL) {\r | |
1848 | *FrameHeaderLength = SimpleNetworkDevice->Isr.FrameHeaderLength;\r | |
1849 | }\r | |
1850 | \r | |
1851 | if (ProtType != NULL) {\r | |
1852 | *ProtType = SimpleNetworkDevice->Isr.ProtType;\r | |
1853 | }\r | |
1854 | \r | |
1855 | if (PktType != NULL) {\r | |
1856 | *PktType = SimpleNetworkDevice->Isr.PktType;\r | |
1857 | }\r | |
1858 | \r | |
1859 | CopyMem (\r | |
1860 | Frame,\r | |
1861 | (VOID *)(UINTN) ((SimpleNetworkDevice->Isr.FrameSegSel << 4) + SimpleNetworkDevice->Isr.FrameOffset),\r | |
1862 | SimpleNetworkDevice->Isr.BufferLength\r | |
1863 | );\r | |
1864 | Frame = Frame + SimpleNetworkDevice->Isr.BufferLength;\r | |
1865 | if (SimpleNetworkDevice->Isr.BufferLength == SimpleNetworkDevice->Isr.FrameLength) {\r | |
1866 | FrameReceived = TRUE;\r | |
1867 | }\r | |
1868 | }\r | |
1869 | //\r | |
1870 | // There is data to process, so call until all events processed.\r | |
1871 | //\r | |
1872 | ZeroMem (&SimpleNetworkDevice->Isr, sizeof (PXENV_UNDI_ISR_T));\r | |
1873 | SimpleNetworkDevice->Isr.Status = INIT_PXE_STATUS;\r | |
1874 | SimpleNetworkDevice->Isr.FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT;\r | |
1875 | \r | |
1876 | DEBUG ((DEBUG_NET, "Isr() GET NEXT\n"));\r | |
1877 | \r | |
1878 | Status = PxeUndiIsr (SimpleNetworkDevice, &SimpleNetworkDevice->Isr);\r | |
1879 | if (EFI_ERROR (Status)) {\r | |
1880 | return Status;\r | |
1881 | }\r | |
1882 | //\r | |
1883 | // Check the status code from the 16 bit UNDI ROM\r | |
1884 | //\r | |
1885 | // if (SimpleNetworkDevice->Isr.Status != PXENV_STATUS_SUCCESS) {\r | |
1886 | // return EFI_DEVICE_ERROR;\r | |
1887 | // }\r | |
1888 | //\r | |
1889 | }\r | |
1890 | \r | |
1891 | SimpleNetworkDevice->IsrValid = FALSE;\r | |
1892 | return EFI_SUCCESS;\r | |
1893 | }\r | |
1894 | //\r | |
1895 | // ///////////////////////////////////////////////////////////////////////////////////////\r | |
1896 | // Simple Network Protocol Interface Functions using 16 bit UNDI Option ROMs\r | |
1897 | /////////////////////////////////////////////////////////////////////////////////////////\r | |
1898 | //\r | |
1899 | // Start()\r | |
1900 | //\r | |
1901 | /**\r | |
1902 | Call 16 bit UNDI ROM to start the network interface\r | |
1903 | \r | |
1904 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
1905 | \r | |
1906 | @retval EFI_DEVICE_ERROR Network interface has not be initialized.\r | |
1907 | @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM call.\r | |
1908 | @retval EFI_SUCESS Success operation.\r | |
1909 | **/\r | |
1910 | EFI_STATUS\r | |
1911 | EFIAPI\r | |
1912 | Undi16SimpleNetworkStart (\r | |
1913 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
1914 | )\r | |
1915 | {\r | |
1916 | EFI_STATUS Status;\r | |
1917 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
1918 | PXENV_UNDI_STARTUP_T Startup;\r | |
1919 | \r | |
1920 | if (This == NULL) {\r | |
1921 | return EFI_INVALID_PARAMETER;\r | |
1922 | }\r | |
1923 | \r | |
1924 | Status = EFI_SUCCESS;\r | |
1925 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
1926 | \r | |
1927 | if (SimpleNetworkDevice == NULL) {\r | |
1928 | return EFI_DEVICE_ERROR;\r | |
1929 | }\r | |
1930 | //\r | |
1931 | // Verify that the current state of the adapter is valid for this call.\r | |
1932 | //\r | |
1933 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
1934 | case EfiSimpleNetworkStopped:\r | |
1935 | break;\r | |
1936 | \r | |
1937 | case EfiSimpleNetworkStarted:\r | |
1938 | case EfiSimpleNetworkInitialized:\r | |
1939 | return EFI_ALREADY_STARTED;\r | |
1940 | \r | |
1941 | default:\r | |
1942 | return EFI_DEVICE_ERROR;\r | |
1943 | }\r | |
1944 | //\r | |
1945 | // Call 16 bit UNDI ROM to start the network interface\r | |
1946 | //\r | |
1947 | Startup.Status = INIT_PXE_STATUS;\r | |
1948 | \r | |
1949 | Status = PxeUndiStartup (SimpleNetworkDevice, &Startup);\r | |
1950 | if (EFI_ERROR (Status)) {\r | |
1951 | return Status;\r | |
1952 | }\r | |
1953 | //\r | |
1954 | // Check the status code from the 16 bit UNDI ROM\r | |
1955 | //\r | |
1956 | if (Startup.Status != PXENV_STATUS_SUCCESS) {\r | |
1957 | return EFI_DEVICE_ERROR;\r | |
1958 | }\r | |
1959 | //\r | |
1960 | // The UNDI interface has been started, so update the State.\r | |
1961 | //\r | |
1962 | SimpleNetworkDevice->SimpleNetworkMode.State = EfiSimpleNetworkStarted;\r | |
1963 | \r | |
1964 | //\r | |
1965 | //\r | |
1966 | //\r | |
1967 | SimpleNetworkDevice->SimpleNetworkMode.ReceiveFilterSetting = 0;\r | |
1968 | SimpleNetworkDevice->SimpleNetworkMode.MCastFilterCount = 0;\r | |
1969 | \r | |
1970 | return Status;\r | |
1971 | }\r | |
1972 | //\r | |
1973 | // Stop()\r | |
1974 | //\r | |
1975 | /**\r | |
1976 | Call 16 bit UNDI ROM to stop the network interface\r | |
1977 | \r | |
1978 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
1979 | \r | |
1980 | @retval EFI_DEVICE_ERROR Network interface has not be initialized.\r | |
1981 | @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM call.\r | |
1982 | @retval EFI_SUCESS Success operation.\r | |
1983 | **/\r | |
1984 | EFI_STATUS\r | |
1985 | EFIAPI\r | |
1986 | Undi16SimpleNetworkStop (\r | |
1987 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
1988 | )\r | |
1989 | {\r | |
1990 | EFI_STATUS Status;\r | |
1991 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
1992 | \r | |
1993 | if (This == NULL) {\r | |
1994 | return EFI_INVALID_PARAMETER;\r | |
1995 | }\r | |
1996 | \r | |
1997 | Status = EFI_SUCCESS;\r | |
1998 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
1999 | \r | |
2000 | if (SimpleNetworkDevice == NULL) {\r | |
2001 | return EFI_DEVICE_ERROR;\r | |
2002 | }\r | |
2003 | //\r | |
2004 | // Verify that the current state of the adapter is valid for this call.\r | |
2005 | //\r | |
2006 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
2007 | case EfiSimpleNetworkStarted:\r | |
2008 | break;\r | |
2009 | \r | |
2010 | case EfiSimpleNetworkStopped:\r | |
2011 | return EFI_NOT_STARTED;\r | |
2012 | \r | |
2013 | case EfiSimpleNetworkInitialized:\r | |
2014 | default:\r | |
2015 | return EFI_DEVICE_ERROR;\r | |
2016 | }\r | |
2017 | \r | |
2018 | SimpleNetworkDevice->SimpleNetworkMode.State = EfiSimpleNetworkStopped;\r | |
2019 | \r | |
2020 | return Status;\r | |
2021 | }\r | |
2022 | \r | |
2023 | //\r | |
2024 | // Initialize()\r | |
2025 | //\r | |
2026 | /**\r | |
2027 | Initialize network interface \r | |
2028 | \r | |
2029 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
2030 | @param ExtraRxBufferSize The size of extra request receive buffer.\r | |
2031 | @param ExtraTxBufferSize The size of extra request transmit buffer.\r | |
2032 | \r | |
2033 | @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM call.\r | |
2034 | @retval EFI_SUCESS Success operation.\r | |
2035 | **/\r | |
2036 | EFI_STATUS\r | |
2037 | EFIAPI\r | |
2038 | Undi16SimpleNetworkInitialize (\r | |
2039 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
2040 | IN UINTN ExtraRxBufferSize OPTIONAL,\r | |
2041 | IN UINTN ExtraTxBufferSize OPTIONAL\r | |
2042 | )\r | |
2043 | {\r | |
2044 | EFI_STATUS Status;\r | |
2045 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
2046 | PXENV_UNDI_INITIALIZE_T Initialize;\r | |
2047 | PXENV_UNDI_OPEN_T Open;\r | |
2048 | \r | |
2049 | if (This == NULL) {\r | |
2050 | return EFI_INVALID_PARAMETER;\r | |
2051 | }\r | |
2052 | \r | |
2053 | Status = EFI_SUCCESS;\r | |
2054 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
2055 | \r | |
2056 | if (SimpleNetworkDevice == NULL) {\r | |
2057 | return EFI_DEVICE_ERROR;\r | |
2058 | }\r | |
2059 | //\r | |
2060 | // Verify that the current state of the adapter is valid for this call.\r | |
2061 | //\r | |
2062 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
2063 | case EfiSimpleNetworkStopped:\r | |
2064 | return EFI_NOT_STARTED;\r | |
2065 | \r | |
2066 | case EfiSimpleNetworkStarted:\r | |
2067 | break;\r | |
2068 | \r | |
2069 | case EfiSimpleNetworkInitialized:\r | |
2070 | default:\r | |
2071 | return EFI_DEVICE_ERROR;\r | |
2072 | }\r | |
2073 | //\r | |
2074 | // Call 16 bit UNDI ROM to start the network interface\r | |
2075 | //\r | |
2076 | Initialize.Status = INIT_PXE_STATUS;\r | |
2077 | Initialize.ProtocolIni = 0;\r | |
2078 | \r | |
2079 | Status = PxeUndiInitialize (SimpleNetworkDevice, &Initialize);\r | |
2080 | \r | |
2081 | if (EFI_ERROR (Status)) {\r | |
2082 | DEBUG ((DEBUG_ERROR, "ERROR : PxeUndiInitialize() - Status = %r\n", Status));\r | |
2083 | DEBUG ((DEBUG_ERROR, "Initialize.Status == %xh\n", Initialize.Status));\r | |
2084 | \r | |
2085 | if (Initialize.Status == PXENV_STATUS_UNDI_MEDIATEST_FAILED) {\r | |
2086 | Status = EFI_NO_MEDIA;\r | |
2087 | }\r | |
2088 | \r | |
2089 | return Status;\r | |
2090 | }\r | |
2091 | //\r | |
2092 | // Check the status code from the 16 bit UNDI ROM\r | |
2093 | //\r | |
2094 | if (Initialize.Status != PXENV_STATUS_SUCCESS) {\r | |
2095 | DEBUG ((DEBUG_ERROR, "ERROR : PxeUndiInitialize() - Initialize.Status = %04x\n", Initialize.Status));\r | |
2096 | return EFI_DEVICE_ERROR;\r | |
2097 | }\r | |
2098 | //\r | |
2099 | // Call 16 bit UNDI ROM to open the network interface\r | |
2100 | //\r | |
2101 | Open.Status = INIT_PXE_STATUS;\r | |
2102 | Open.OpenFlag = 0;\r | |
2103 | Open.PktFilter = Undi16GetPacketFilterSetting (SimpleNetworkDevice->SimpleNetworkMode.ReceiveFilterSetting);\r | |
2104 | Undi16GetMCastFilters (\r | |
2105 | &SimpleNetworkDevice->SimpleNetworkMode,\r | |
2106 | &Open.McastBuffer,\r | |
2107 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2108 | );\r | |
2109 | \r | |
2110 | Status = PxeUndiOpen (SimpleNetworkDevice, &Open);\r | |
2111 | \r | |
2112 | if (EFI_ERROR (Status)) {\r | |
2113 | DEBUG ((DEBUG_ERROR, "ERROR : PxeUndiOpen() - Status = %r\n", Status));\r | |
2114 | return Status;\r | |
2115 | }\r | |
2116 | //\r | |
2117 | // Check the status code from the 16 bit UNDI ROM\r | |
2118 | //\r | |
2119 | if (Open.Status != PXENV_STATUS_SUCCESS) {\r | |
2120 | DEBUG ((DEBUG_ERROR, "ERROR : PxeUndiOpen() - Open.Status = %04x\n", Open.Status));\r | |
2121 | return EFI_DEVICE_ERROR;\r | |
2122 | }\r | |
2123 | //\r | |
2124 | // The UNDI interface has been initialized, so update the State.\r | |
2125 | //\r | |
2126 | SimpleNetworkDevice->SimpleNetworkMode.State = EfiSimpleNetworkInitialized;\r | |
2127 | \r | |
2128 | //\r | |
2129 | // If initialize succeeds, then assume that media is present.\r | |
2130 | //\r | |
2131 | SimpleNetworkDevice->SimpleNetworkMode.MediaPresent = TRUE;\r | |
2132 | \r | |
2133 | //\r | |
2134 | // Reset the recycled transmit buffer FIFO\r | |
2135 | //\r | |
2136 | SimpleNetworkDevice->TxBufferFifo.First = 0;\r | |
2137 | SimpleNetworkDevice->TxBufferFifo.Last = 0;\r | |
2138 | SimpleNetworkDevice->IsrValid = FALSE;\r | |
2139 | \r | |
2140 | return Status;\r | |
2141 | }\r | |
2142 | //\r | |
2143 | // Reset()\r | |
2144 | //\r | |
2145 | /**\r | |
2146 | Reset network interface.\r | |
2147 | \r | |
2148 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
2149 | @param ExtendedVerification Need extended verfication.\r | |
2150 | \r | |
2151 | @retval EFI_INVALID_PARAMETER Invalid This paramter.\r | |
2152 | @retval EFI_DEVICE_ERROR Network device has not been initialized.\r | |
2153 | @retval EFI_NOT_STARTED Network device has been stopped.\r | |
2154 | @retval EFI_DEVICE_ERROR Invalid status for network device\r | |
2155 | @retval EFI_SUCCESS Success operation.\r | |
2156 | **/\r | |
2157 | EFI_STATUS\r | |
2158 | EFIAPI\r | |
2159 | Undi16SimpleNetworkReset (\r | |
2160 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
2161 | IN BOOLEAN ExtendedVerification\r | |
2162 | )\r | |
2163 | {\r | |
2164 | EFI_STATUS Status;\r | |
2165 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
2166 | PXENV_UNDI_RESET_T Reset;\r | |
2167 | UINT16 Rx_filter;\r | |
2168 | \r | |
2169 | if (This == NULL) {\r | |
2170 | return EFI_INVALID_PARAMETER;\r | |
2171 | }\r | |
2172 | \r | |
2173 | Status = EFI_SUCCESS;\r | |
2174 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
2175 | \r | |
2176 | if (SimpleNetworkDevice == NULL) {\r | |
2177 | return EFI_DEVICE_ERROR;\r | |
2178 | }\r | |
2179 | //\r | |
2180 | // Verify that the current state of the adapter is valid for this call.\r | |
2181 | //\r | |
2182 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
2183 | case EfiSimpleNetworkStopped:\r | |
2184 | return EFI_NOT_STARTED;\r | |
2185 | \r | |
2186 | case EfiSimpleNetworkInitialized:\r | |
2187 | break;\r | |
2188 | \r | |
2189 | case EfiSimpleNetworkStarted:\r | |
2190 | default:\r | |
2191 | return EFI_DEVICE_ERROR;\r | |
2192 | }\r | |
2193 | \r | |
2194 | Reset.Status = INIT_PXE_STATUS;\r | |
2195 | \r | |
2196 | Rx_filter = Undi16GetPacketFilterSetting (SimpleNetworkDevice->SimpleNetworkMode.ReceiveFilterSetting);\r | |
2197 | \r | |
2198 | Undi16GetMCastFilters (\r | |
2199 | &SimpleNetworkDevice->SimpleNetworkMode,\r | |
2200 | &Reset.R_Mcast_Buf,\r | |
2201 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2202 | );\r | |
2203 | \r | |
2204 | Status = PxeUndiResetNic (SimpleNetworkDevice, &Reset, Rx_filter);\r | |
2205 | \r | |
2206 | if (EFI_ERROR (Status)) {\r | |
2207 | return Status;\r | |
2208 | }\r | |
2209 | //\r | |
2210 | // Check the status code from the 16 bit UNDI ROM\r | |
2211 | //\r | |
2212 | if (Reset.Status != PXENV_STATUS_SUCCESS) {\r | |
2213 | return EFI_DEVICE_ERROR;\r | |
2214 | }\r | |
2215 | //\r | |
2216 | // Reset the recycled transmit buffer FIFO\r | |
2217 | //\r | |
2218 | SimpleNetworkDevice->TxBufferFifo.First = 0;\r | |
2219 | SimpleNetworkDevice->TxBufferFifo.Last = 0;\r | |
2220 | SimpleNetworkDevice->IsrValid = FALSE;\r | |
2221 | \r | |
2222 | return Status;\r | |
2223 | }\r | |
2224 | //\r | |
2225 | // Shutdown()\r | |
2226 | //\r | |
2227 | /**\r | |
2228 | Shutdown network interface.\r | |
2229 | \r | |
2230 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
2231 | \r | |
2232 | @retval EFI_INVALID_PARAMETER Invalid This paramter.\r | |
2233 | @retval EFI_DEVICE_ERROR Network device has not been initialized.\r | |
2234 | @retval EFI_NOT_STARTED Network device has been stopped.\r | |
2235 | @retval EFI_DEVICE_ERROR Invalid status for network device\r | |
2236 | @retval EFI_SUCCESS Success operation.\r | |
2237 | **/\r | |
2238 | EFI_STATUS\r | |
2239 | EFIAPI\r | |
2240 | Undi16SimpleNetworkShutdown (\r | |
2241 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
2242 | )\r | |
2243 | {\r | |
2244 | EFI_STATUS Status;\r | |
2245 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
2246 | PXENV_UNDI_CLOSE_T Close;\r | |
2247 | PXENV_UNDI_SHUTDOWN_T Shutdown;\r | |
2248 | \r | |
2249 | if (This == NULL) {\r | |
2250 | return EFI_INVALID_PARAMETER;\r | |
2251 | }\r | |
2252 | \r | |
2253 | Status = EFI_SUCCESS;\r | |
2254 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
2255 | \r | |
2256 | if (SimpleNetworkDevice == NULL) {\r | |
2257 | return EFI_DEVICE_ERROR;\r | |
2258 | }\r | |
2259 | //\r | |
2260 | // Verify that the current state of the adapter is valid for this call.\r | |
2261 | //\r | |
2262 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
2263 | case EfiSimpleNetworkStopped:\r | |
2264 | return EFI_NOT_STARTED;\r | |
2265 | \r | |
2266 | case EfiSimpleNetworkInitialized:\r | |
2267 | break;\r | |
2268 | \r | |
2269 | case EfiSimpleNetworkStarted:\r | |
2270 | default:\r | |
2271 | return EFI_DEVICE_ERROR;\r | |
2272 | }\r | |
2273 | \r | |
2274 | SimpleNetworkDevice->IsrValid = FALSE;\r | |
2275 | \r | |
2276 | //\r | |
2277 | // Call 16 bit UNDI ROM to start the network interface\r | |
2278 | //\r | |
2279 | Close.Status = INIT_PXE_STATUS;\r | |
2280 | \r | |
2281 | Status = PxeUndiClose (SimpleNetworkDevice, &Close);\r | |
2282 | \r | |
2283 | if (EFI_ERROR (Status)) {\r | |
2284 | return Status;\r | |
2285 | }\r | |
2286 | //\r | |
2287 | // Check the status code from the 16 bit UNDI ROM\r | |
2288 | //\r | |
2289 | if (Close.Status != PXENV_STATUS_SUCCESS) {\r | |
2290 | return EFI_DEVICE_ERROR;\r | |
2291 | }\r | |
2292 | //\r | |
2293 | // Call 16 bit UNDI ROM to open the network interface\r | |
2294 | //\r | |
2295 | Shutdown.Status = INIT_PXE_STATUS;\r | |
2296 | \r | |
2297 | Status = PxeUndiShutdown (SimpleNetworkDevice, &Shutdown);\r | |
2298 | \r | |
2299 | if (EFI_ERROR (Status)) {\r | |
2300 | return Status;\r | |
2301 | }\r | |
2302 | //\r | |
2303 | // Check the status code from the 16 bit UNDI ROM\r | |
2304 | //\r | |
2305 | if (Shutdown.Status != PXENV_STATUS_SUCCESS) {\r | |
2306 | return EFI_DEVICE_ERROR;\r | |
2307 | }\r | |
2308 | //\r | |
2309 | // The UNDI interface has been initialized, so update the State.\r | |
2310 | //\r | |
2311 | SimpleNetworkDevice->SimpleNetworkMode.State = EfiSimpleNetworkStarted;\r | |
2312 | \r | |
2313 | //\r | |
2314 | // If shutdown succeeds, then assume that media is not present.\r | |
2315 | //\r | |
2316 | SimpleNetworkDevice->SimpleNetworkMode.MediaPresent = FALSE;\r | |
2317 | \r | |
2318 | //\r | |
2319 | // Reset the recycled transmit buffer FIFO\r | |
2320 | //\r | |
2321 | SimpleNetworkDevice->TxBufferFifo.First = 0;\r | |
2322 | SimpleNetworkDevice->TxBufferFifo.Last = 0;\r | |
2323 | \r | |
2324 | //\r | |
2325 | // A short delay. Without this an initialize immediately following\r | |
2326 | // a shutdown will cause some versions of UNDI-16 to stop operating.\r | |
2327 | //\r | |
2328 | gBS->Stall (250000);\r | |
2329 | \r | |
2330 | return Status;\r | |
2331 | }\r | |
2332 | //\r | |
2333 | // ReceiveFilters()\r | |
2334 | //\r | |
2335 | /**\r | |
2336 | Reset network interface.\r | |
2337 | \r | |
2338 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
2339 | @param Enable Enable mask value\r | |
2340 | @param Disable Disable mask value\r | |
2341 | @param ResetMCastFilter Whether reset multi cast filter or not\r | |
2342 | @param MCastFilterCnt Count of mutli cast filter for different MAC address\r | |
2343 | @param MCastFilter Buffer for mustli cast filter for different MAC address.\r | |
2344 | \r | |
2345 | @retval EFI_INVALID_PARAMETER Invalid This paramter.\r | |
2346 | @retval EFI_DEVICE_ERROR Network device has not been initialized.\r | |
2347 | @retval EFI_NOT_STARTED Network device has been stopped.\r | |
2348 | @retval EFI_DEVICE_ERROR Invalid status for network device\r | |
2349 | @retval EFI_SUCCESS Success operation.\r | |
2350 | **/\r | |
2351 | EFI_STATUS\r | |
2352 | EFIAPI\r | |
2353 | Undi16SimpleNetworkReceiveFilters (\r | |
2354 | IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r | |
2355 | IN UINT32 Enable,\r | |
2356 | IN UINT32 Disable,\r | |
2357 | IN BOOLEAN ResetMCastFilter,\r | |
2358 | IN UINTN MCastFilterCnt OPTIONAL,\r | |
2359 | IN EFI_MAC_ADDRESS * MCastFilter OPTIONAL\r | |
2360 | )\r | |
2361 | {\r | |
2362 | EFI_STATUS Status;\r | |
2363 | UINTN Index;\r | |
2364 | UINT32 NewFilter;\r | |
2365 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
2366 | PXENV_UNDI_CLOSE_T Close;\r | |
2367 | PXENV_UNDI_OPEN_T Open;\r | |
2368 | \r | |
2369 | if (This == NULL) {\r | |
2370 | return EFI_INVALID_PARAMETER;\r | |
2371 | }\r | |
2372 | \r | |
2373 | Status = EFI_SUCCESS;\r | |
2374 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
2375 | \r | |
2376 | if (SimpleNetworkDevice == NULL) {\r | |
2377 | return EFI_DEVICE_ERROR;\r | |
2378 | }\r | |
2379 | //\r | |
2380 | // Verify that the current state of the adapter is valid for this call.\r | |
2381 | //\r | |
2382 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
2383 | case EfiSimpleNetworkStopped:\r | |
2384 | return EFI_NOT_STARTED;\r | |
2385 | \r | |
2386 | case EfiSimpleNetworkInitialized:\r | |
2387 | break;\r | |
2388 | \r | |
2389 | case EfiSimpleNetworkStarted:\r | |
2390 | default:\r | |
2391 | return EFI_DEVICE_ERROR;\r | |
2392 | }\r | |
2393 | //\r | |
2394 | // First deal with possible filter setting changes\r | |
2395 | //\r | |
2396 | if ((Enable == 0) && (Disable == 0) && !ResetMCastFilter) {\r | |
2397 | return EFI_SUCCESS;\r | |
2398 | }\r | |
2399 | \r | |
2400 | NewFilter = (SimpleNetworkDevice->SimpleNetworkMode.ReceiveFilterSetting | Enable) &~Disable;\r | |
2401 | \r | |
2402 | if ((NewFilter & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0) {\r | |
2403 | if ((MCastFilterCnt == 0) || (MCastFilter == 0) || MCastFilterCnt > SimpleNetworkDevice->SimpleNetworkMode.MaxMCastFilterCount) {\r | |
2404 | return EFI_INVALID_PARAMETER;\r | |
2405 | }\r | |
2406 | }\r | |
2407 | //\r | |
2408 | // Call 16 bit UNDI ROM to close the network interface\r | |
2409 | //\r | |
2410 | Close.Status = INIT_PXE_STATUS;\r | |
2411 | \r | |
2412 | Status = PxeUndiClose (SimpleNetworkDevice, &Close);\r | |
2413 | \r | |
2414 | if (EFI_ERROR (Status)) {\r | |
2415 | return Status;\r | |
2416 | }\r | |
2417 | //\r | |
2418 | // Check the status code from the 16 bit UNDI ROM\r | |
2419 | //\r | |
2420 | if (Close.Status != PXENV_STATUS_SUCCESS) {\r | |
2421 | return EFI_DEVICE_ERROR;\r | |
2422 | }\r | |
2423 | //\r | |
2424 | // Call 16 bit UNDI ROM to open the network interface\r | |
2425 | //\r | |
2426 | //\r | |
2427 | // Reset the recycled transmit buffer FIFO\r | |
2428 | //\r | |
2429 | SimpleNetworkDevice->TxBufferFifo.First = 0;\r | |
2430 | SimpleNetworkDevice->TxBufferFifo.Last = 0;\r | |
2431 | \r | |
2432 | //\r | |
2433 | // Call 16 bit UNDI ROM to open the network interface\r | |
2434 | //\r | |
2435 | ZeroMem (&Open, sizeof Open);\r | |
2436 | \r | |
2437 | Open.Status = INIT_PXE_STATUS;\r | |
2438 | Open.PktFilter = Undi16GetPacketFilterSetting (NewFilter);\r | |
2439 | \r | |
2440 | if ((NewFilter & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0) {\r | |
2441 | //\r | |
2442 | // Copy the MAC addresses into the UNDI open parameter structure\r | |
2443 | //\r | |
2444 | Open.McastBuffer.MCastAddrCount = (UINT16) MCastFilterCnt;\r | |
2445 | for (Index = 0; Index < MCastFilterCnt; ++Index) {\r | |
2446 | CopyMem (\r | |
2447 | Open.McastBuffer.MCastAddr[Index],\r | |
2448 | &MCastFilter[Index],\r | |
2449 | sizeof Open.McastBuffer.MCastAddr[Index]\r | |
2450 | );\r | |
2451 | }\r | |
2452 | } else if (!ResetMCastFilter) {\r | |
2453 | for (Index = 0; Index < SimpleNetworkDevice->SimpleNetworkMode.MCastFilterCount; ++Index) {\r | |
2454 | CopyMem (\r | |
2455 | Open.McastBuffer.MCastAddr[Index],\r | |
2456 | &SimpleNetworkDevice->SimpleNetworkMode.MCastFilter[Index],\r | |
2457 | sizeof Open.McastBuffer.MCastAddr[Index]\r | |
2458 | );\r | |
2459 | }\r | |
2460 | }\r | |
2461 | \r | |
2462 | Status = PxeUndiOpen (SimpleNetworkDevice, &Open);\r | |
2463 | \r | |
2464 | if (EFI_ERROR (Status)) {\r | |
2465 | return Status;\r | |
2466 | }\r | |
2467 | //\r | |
2468 | // Check the status code from the 16 bit UNDI ROM\r | |
2469 | //\r | |
2470 | if (Open.Status != PXENV_STATUS_SUCCESS) {\r | |
2471 | return EFI_DEVICE_ERROR;\r | |
2472 | }\r | |
2473 | \r | |
2474 | SimpleNetworkDevice->IsrValid = FALSE;\r | |
2475 | SimpleNetworkDevice->SimpleNetworkMode.ReceiveFilterSetting = NewFilter;\r | |
2476 | \r | |
2477 | if ((NewFilter & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0) {\r | |
2478 | SimpleNetworkDevice->SimpleNetworkMode.MCastFilterCount = (UINT32) MCastFilterCnt;\r | |
2479 | for (Index = 0; Index < MCastFilterCnt; ++Index) {\r | |
2480 | CopyMem (\r | |
2481 | &SimpleNetworkDevice->SimpleNetworkMode.MCastFilter[Index],\r | |
2482 | &MCastFilter[Index],\r | |
2483 | sizeof (EFI_MAC_ADDRESS)\r | |
2484 | ); \r | |
2485 | }\r | |
2486 | }\r | |
2487 | //\r | |
2488 | // Read back multicast addresses.\r | |
2489 | //\r | |
2490 | return EFI_SUCCESS;\r | |
2491 | }\r | |
2492 | //\r | |
2493 | // StationAddress()\r | |
2494 | //\r | |
2495 | /**\r | |
2496 | Set new MAC address.\r | |
2497 | \r | |
2498 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
2499 | @param Reset Whether reset station MAC address to permenent address\r | |
2500 | @param New A pointer to New address\r | |
2501 | \r | |
2502 | @retval EFI_INVALID_PARAMETER Invalid This paramter.\r | |
2503 | @retval EFI_DEVICE_ERROR Network device has not been initialized.\r | |
2504 | @retval EFI_NOT_STARTED Network device has been stopped.\r | |
2505 | @retval EFI_DEVICE_ERROR Invalid status for network device\r | |
2506 | @retval EFI_SUCCESS Success operation.\r | |
2507 | **/\r | |
2508 | EFI_STATUS\r | |
2509 | EFIAPI\r | |
2510 | Undi16SimpleNetworkStationAddress (\r | |
2511 | IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r | |
2512 | IN BOOLEAN Reset,\r | |
2513 | IN EFI_MAC_ADDRESS * New OPTIONAL\r | |
2514 | )\r | |
2515 | {\r | |
2516 | EFI_STATUS Status;\r | |
2517 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
2518 | PXENV_UNDI_SET_STATION_ADDR_T SetStationAddr;\r | |
2519 | //\r | |
2520 | // EFI_DEVICE_PATH_PROTOCOL *OldDevicePath;\r | |
2521 | //\r | |
2522 | PXENV_UNDI_CLOSE_T Close;\r | |
2523 | PXENV_UNDI_OPEN_T Open;\r | |
2524 | \r | |
2525 | if (This == NULL) {\r | |
2526 | return EFI_INVALID_PARAMETER;\r | |
2527 | }\r | |
2528 | \r | |
2529 | Status = EFI_SUCCESS;\r | |
2530 | \r | |
2531 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
2532 | \r | |
2533 | if (SimpleNetworkDevice == NULL) {\r | |
2534 | return EFI_DEVICE_ERROR;\r | |
2535 | }\r | |
2536 | //\r | |
2537 | // Verify that the current state of the adapter is valid for this call.\r | |
2538 | //\r | |
2539 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
2540 | case EfiSimpleNetworkInitialized:\r | |
2541 | break;\r | |
2542 | \r | |
2543 | case EfiSimpleNetworkStopped:\r | |
2544 | return EFI_NOT_STARTED;\r | |
2545 | \r | |
2546 | case EfiSimpleNetworkStarted:\r | |
2547 | default:\r | |
2548 | return EFI_DEVICE_ERROR;\r | |
2549 | }\r | |
2550 | //\r | |
2551 | // Call 16 bit UNDI ROM to open the network interface\r | |
2552 | //\r | |
2553 | SetStationAddr.Status = INIT_PXE_STATUS;\r | |
2554 | \r | |
2555 | if (Reset) {\r | |
2556 | //\r | |
2557 | // If we are reseting the Station Address to the permanent address, and the\r | |
2558 | // Station Address is not programmable, then just return EFI_SUCCESS.\r | |
2559 | //\r | |
2560 | if (!SimpleNetworkDevice->SimpleNetworkMode.MacAddressChangeable) {\r | |
2561 | return EFI_SUCCESS;\r | |
2562 | }\r | |
2563 | //\r | |
2564 | // If the address is already the permanent address, then just return success.\r | |
2565 | //\r | |
2566 | if (CompareMem (\r | |
2567 | &SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress,\r | |
2568 | &SimpleNetworkDevice->SimpleNetworkMode.PermanentAddress,\r | |
2569 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2570 | ) == 0) {\r | |
2571 | return EFI_SUCCESS;\r | |
2572 | }\r | |
2573 | //\r | |
2574 | // Copy the adapters permanent address to the new station address\r | |
2575 | //\r | |
2576 | CopyMem (\r | |
2577 | &SetStationAddr.StationAddress,\r | |
2578 | &SimpleNetworkDevice->SimpleNetworkMode.PermanentAddress,\r | |
2579 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2580 | );\r | |
2581 | } else {\r | |
2582 | //\r | |
2583 | // If we are setting the Station Address, and the\r | |
2584 | // Station Address is not programmable, return invalid parameter.\r | |
2585 | //\r | |
2586 | if (!SimpleNetworkDevice->SimpleNetworkMode.MacAddressChangeable) {\r | |
2587 | return EFI_INVALID_PARAMETER;\r | |
2588 | }\r | |
2589 | //\r | |
2590 | // If the address is already the new address, then just return success.\r | |
2591 | //\r | |
2592 | if (CompareMem (\r | |
2593 | &SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress,\r | |
2594 | New,\r | |
2595 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2596 | ) == 0) {\r | |
2597 | return EFI_SUCCESS;\r | |
2598 | }\r | |
2599 | //\r | |
2600 | // Copy New to the new station address\r | |
2601 | //\r | |
2602 | CopyMem (\r | |
2603 | &SetStationAddr.StationAddress,\r | |
2604 | New,\r | |
2605 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2606 | );\r | |
2607 | \r | |
2608 | }\r | |
2609 | //\r | |
2610 | // Call 16 bit UNDI ROM to stop the network interface\r | |
2611 | //\r | |
2612 | Close.Status = INIT_PXE_STATUS;\r | |
2613 | \r | |
2614 | PxeUndiClose (SimpleNetworkDevice, &Close);\r | |
2615 | \r | |
2616 | //\r | |
2617 | // Call 16-bit UNDI ROM to set the station address\r | |
2618 | //\r | |
2619 | SetStationAddr.Status = PXENV_STATUS_SUCCESS;\r | |
2620 | \r | |
2621 | Status = PxeUndiSetStationAddr (SimpleNetworkDevice, &SetStationAddr);\r | |
2622 | \r | |
2623 | //\r | |
2624 | // Call 16-bit UNDI ROM to start the network interface\r | |
2625 | //\r | |
2626 | Open.Status = PXENV_STATUS_SUCCESS;\r | |
2627 | Open.OpenFlag = 0;\r | |
2628 | Open.PktFilter = Undi16GetPacketFilterSetting (SimpleNetworkDevice->SimpleNetworkMode.ReceiveFilterSetting);\r | |
2629 | Undi16GetMCastFilters (\r | |
2630 | &SimpleNetworkDevice->SimpleNetworkMode,\r | |
2631 | &Open.McastBuffer,\r | |
2632 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2633 | );\r | |
2634 | \r | |
2635 | PxeUndiOpen (SimpleNetworkDevice, &Open);\r | |
2636 | \r | |
2637 | //\r | |
2638 | // Check status from station address change\r | |
2639 | //\r | |
2640 | if (EFI_ERROR (Status)) {\r | |
2641 | return Status;\r | |
2642 | }\r | |
2643 | //\r | |
2644 | // Check the status code from the 16 bit UNDI ROM\r | |
2645 | //\r | |
2646 | if (SetStationAddr.Status != PXENV_STATUS_SUCCESS) {\r | |
2647 | return EFI_DEVICE_ERROR;\r | |
2648 | }\r | |
2649 | \r | |
2650 | CopyMem (\r | |
2651 | &SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress,\r | |
2652 | &SetStationAddr.StationAddress,\r | |
2653 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2654 | );\r | |
2655 | \r | |
2656 | #if 0 /* The device path is based on the permanent address not the current address. */\r | |
2657 | //\r | |
2658 | // The station address was changed, so update the device path with the new MAC address.\r | |
2659 | //\r | |
2660 | OldDevicePath = SimpleNetworkDevice->DevicePath;\r | |
2661 | SimpleNetworkDevice->DevicePath = DuplicateDevicePath (SimpleNetworkDevice->BaseDevicePath);\r | |
2662 | SimpleNetworkAppendMacAddressDevicePath (\r | |
2663 | &SimpleNetworkDevice->DevicePath,\r | |
2664 | &SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress\r | |
2665 | );\r | |
2666 | \r | |
2667 | Status = LibReinstallProtocolInterfaces (\r | |
2668 | SimpleNetworkDevice->Handle,\r | |
2669 | &DevicePathProtocol,\r | |
2670 | OldDevicePath,\r | |
2671 | SimpleNetworkDevice->DevicePath,\r | |
2672 | NULL\r | |
2673 | );\r | |
2674 | \r | |
2675 | if (EFI_ERROR (Status)) {\r | |
2676 | DEBUG ((DEBUG_ERROR, "Failed to reinstall the DevicePath protocol for the Simple Network Device\n"));\r | |
2677 | DEBUG ((DEBUG_ERROR, " Status = %r\n", Status));\r | |
2678 | }\r | |
2679 | \r | |
2680 | FreePool (OldDevicePath);\r | |
2681 | #endif /* 0 */\r | |
2682 | \r | |
2683 | return Status;\r | |
2684 | }\r | |
2685 | //\r | |
2686 | // Statistics()\r | |
2687 | //\r | |
2688 | /**\r | |
2689 | Resets or collects the statistics on a network interface.\r | |
2690 | \r | |
2691 | @param This Protocol instance pointer.\r | |
2692 | @param Reset Set to TRUE to reset the statistics for the network interface.\r | |
2693 | @param StatisticsSize On input the size, in bytes, of StatisticsTable. On\r | |
2694 | output the size, in bytes, of the resulting table of\r | |
2695 | statistics.\r | |
2696 | @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r | |
2697 | contains the statistics.\r | |
2698 | \r | |
2699 | @retval EFI_SUCCESS The statistics were collected from the network interface.\r | |
2700 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
2701 | @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r | |
2702 | size needed to hold the statistics is returned in\r | |
2703 | StatisticsSize.\r | |
2704 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r | |
2705 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
2706 | @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r | |
2707 | \r | |
2708 | **/\r | |
2709 | EFI_STATUS\r | |
2710 | EFIAPI\r | |
2711 | Undi16SimpleNetworkStatistics (\r | |
2712 | IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r | |
2713 | IN BOOLEAN Reset,\r | |
2714 | IN OUT UINTN *StatisticsSize OPTIONAL,\r | |
2715 | OUT EFI_NETWORK_STATISTICS * StatisticsTable OPTIONAL\r | |
2716 | )\r | |
2717 | {\r | |
2718 | EFI_STATUS Status;\r | |
2719 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
2720 | PXENV_UNDI_CLEAR_STATISTICS_T ClearStatistics;\r | |
2721 | PXENV_UNDI_GET_STATISTICS_T GetStatistics;\r | |
2722 | \r | |
2723 | if (This == NULL) {\r | |
2724 | return EFI_INVALID_PARAMETER;\r | |
2725 | }\r | |
2726 | \r | |
2727 | Status = EFI_SUCCESS;\r | |
2728 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
2729 | \r | |
2730 | if (SimpleNetworkDevice == NULL) {\r | |
2731 | return EFI_DEVICE_ERROR;\r | |
2732 | }\r | |
2733 | //\r | |
2734 | // Verify that the current state of the adapter is valid for this call.\r | |
2735 | //\r | |
2736 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
2737 | case EfiSimpleNetworkInitialized:\r | |
2738 | break;\r | |
2739 | \r | |
2740 | case EfiSimpleNetworkStopped:\r | |
2741 | return EFI_NOT_STARTED;\r | |
2742 | \r | |
2743 | case EfiSimpleNetworkStarted:\r | |
2744 | default:\r | |
2745 | return EFI_DEVICE_ERROR;\r | |
2746 | }\r | |
2747 | \r | |
2748 | if ((StatisticsSize != NULL) && (*StatisticsSize != 0) && (StatisticsTable == NULL)) {\r | |
2749 | return EFI_INVALID_PARAMETER;\r | |
2750 | }\r | |
2751 | \r | |
2752 | //\r | |
2753 | // If Reset is TRUE, then clear all the statistics.\r | |
2754 | //\r | |
2755 | if (Reset) {\r | |
2756 | \r | |
2757 | DEBUG ((DEBUG_NET, " RESET Statistics\n"));\r | |
2758 | \r | |
2759 | //\r | |
2760 | // Call 16 bit UNDI ROM to open the network interface\r | |
2761 | //\r | |
2762 | ClearStatistics.Status = INIT_PXE_STATUS;\r | |
2763 | \r | |
2764 | Status = PxeUndiClearStatistics (SimpleNetworkDevice, &ClearStatistics);\r | |
2765 | \r | |
2766 | if (EFI_ERROR (Status)) {\r | |
2767 | return Status;\r | |
2768 | }\r | |
2769 | //\r | |
2770 | // Check the status code from the 16 bit UNDI ROM\r | |
2771 | //\r | |
2772 | if (ClearStatistics.Status != PXENV_STATUS_SUCCESS) {\r | |
2773 | return EFI_DEVICE_ERROR;\r | |
2774 | }\r | |
2775 | \r | |
2776 | DEBUG ((DEBUG_NET, " RESET Statistics Complete"));\r | |
2777 | }\r | |
2778 | \r | |
2779 | if (StatisticsSize != NULL) {\r | |
2780 | EFI_NETWORK_STATISTICS LocalStatisticsTable;\r | |
2781 | \r | |
2782 | DEBUG ((DEBUG_NET, " GET Statistics\n"));\r | |
2783 | \r | |
2784 | //\r | |
2785 | // If the size if valid, then see if the table is valid\r | |
2786 | //\r | |
2787 | if (StatisticsTable == NULL) {\r | |
2788 | DEBUG ((DEBUG_NET, " StatisticsTable is NULL\n"));\r | |
2789 | return EFI_INVALID_PARAMETER;\r | |
2790 | }\r | |
2791 | //\r | |
2792 | // Call 16 bit UNDI ROM to open the network interface\r | |
2793 | //\r | |
2794 | GetStatistics.Status = INIT_PXE_STATUS;\r | |
2795 | GetStatistics.XmtGoodFrames = 0;\r | |
2796 | GetStatistics.RcvGoodFrames = 0;\r | |
2797 | GetStatistics.RcvCRCErrors = 0;\r | |
2798 | GetStatistics.RcvResourceErrors = 0;\r | |
2799 | \r | |
2800 | Status = PxeUndiGetStatistics (SimpleNetworkDevice, &GetStatistics);\r | |
2801 | \r | |
2802 | if (EFI_ERROR (Status)) {\r | |
2803 | return Status;\r | |
2804 | }\r | |
2805 | //\r | |
2806 | // Check the status code from the 16 bit UNDI ROM\r | |
2807 | //\r | |
2808 | if (GetStatistics.Status != PXENV_STATUS_SUCCESS) {\r | |
2809 | return EFI_DEVICE_ERROR;\r | |
2810 | }\r | |
2811 | //\r | |
2812 | // Fill in the Statistics Table with the collected values.\r | |
2813 | //\r | |
2814 | SetMem (&LocalStatisticsTable, sizeof LocalStatisticsTable, 0xff);\r | |
2815 | \r | |
2816 | LocalStatisticsTable.TxGoodFrames = GetStatistics.XmtGoodFrames;\r | |
2817 | LocalStatisticsTable.RxGoodFrames = GetStatistics.RcvGoodFrames;\r | |
2818 | LocalStatisticsTable.RxCrcErrorFrames = GetStatistics.RcvCRCErrors;\r | |
2819 | LocalStatisticsTable.RxDroppedFrames = GetStatistics.RcvResourceErrors;\r | |
2820 | \r | |
2821 | CopyMem (StatisticsTable, &LocalStatisticsTable, *StatisticsSize);\r | |
2822 | \r | |
2823 | DEBUG (\r | |
2824 | (DEBUG_NET,\r | |
2825 | " Statistics Collected : Size=%d Buf=%08x\n",\r | |
2826 | *StatisticsSize,\r | |
2827 | StatisticsTable)\r | |
2828 | );\r | |
2829 | \r | |
2830 | DEBUG ((DEBUG_NET, " GET Statistics Complete"));\r | |
2831 | \r | |
2832 | if (*StatisticsSize < sizeof LocalStatisticsTable) {\r | |
2833 | DEBUG ((DEBUG_NET, " BUFFER TOO SMALL\n"));\r | |
2834 | Status = EFI_BUFFER_TOO_SMALL;\r | |
2835 | }\r | |
2836 | \r | |
2837 | *StatisticsSize = sizeof LocalStatisticsTable;\r | |
2838 | \r | |
2839 | return Status;\r | |
2840 | \r | |
2841 | }\r | |
2842 | \r | |
2843 | return EFI_SUCCESS;\r | |
2844 | }\r | |
2845 | //\r | |
2846 | // MCastIpToMac()\r | |
2847 | //\r | |
2848 | /**\r | |
2849 | Translate IP address to MAC address.\r | |
2850 | \r | |
2851 | @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.\r | |
2852 | @param IPv6 IPv6 or IPv4\r | |
2853 | @param IP A pointer to given Ip address.\r | |
2854 | @param MAC On return, translated MAC address.\r | |
2855 | \r | |
2856 | @retval EFI_INVALID_PARAMETER Invalid This paramter.\r | |
2857 | @retval EFI_INVALID_PARAMETER Invalid IP address.\r | |
2858 | @retval EFI_INVALID_PARAMETER Invalid return buffer for holding MAC address.\r | |
2859 | @retval EFI_UNSUPPORTED Do not support IPv6 \r | |
2860 | @retval EFI_DEVICE_ERROR Network device has not been initialized.\r | |
2861 | @retval EFI_NOT_STARTED Network device has been stopped.\r | |
2862 | @retval EFI_DEVICE_ERROR Invalid status for network device\r | |
2863 | @retval EFI_SUCCESS Success operation.\r | |
2864 | **/\r | |
2865 | EFI_STATUS\r | |
2866 | EFIAPI\r | |
2867 | Undi16SimpleNetworkMCastIpToMac (\r | |
2868 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
2869 | IN BOOLEAN IPv6,\r | |
2870 | IN EFI_IP_ADDRESS *IP,\r | |
2871 | OUT EFI_MAC_ADDRESS *MAC\r | |
2872 | )\r | |
2873 | {\r | |
2874 | EFI_STATUS Status;\r | |
2875 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
2876 | PXENV_UNDI_GET_MCAST_ADDR_T GetMcastAddr;\r | |
2877 | \r | |
2878 | if (This == NULL || IP == NULL || MAC == NULL) {\r | |
2879 | return EFI_INVALID_PARAMETER;\r | |
2880 | }\r | |
2881 | \r | |
2882 | Status = EFI_SUCCESS;\r | |
2883 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
2884 | \r | |
2885 | if (SimpleNetworkDevice == NULL) {\r | |
2886 | return EFI_DEVICE_ERROR;\r | |
2887 | }\r | |
2888 | //\r | |
2889 | // Verify that the current state of the adapter is valid for this call.\r | |
2890 | //\r | |
2891 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
2892 | case EfiSimpleNetworkStopped:\r | |
2893 | return EFI_NOT_STARTED;\r | |
2894 | \r | |
2895 | case EfiSimpleNetworkInitialized:\r | |
2896 | break;\r | |
2897 | \r | |
2898 | case EfiSimpleNetworkStarted:\r | |
2899 | default:\r | |
2900 | return EFI_DEVICE_ERROR;\r | |
2901 | }\r | |
2902 | //\r | |
2903 | // 16 bit UNDI Option ROMS do not support IPv6. Check for IPv6 usage.\r | |
2904 | //\r | |
2905 | if (IPv6) {\r | |
2906 | return EFI_UNSUPPORTED;\r | |
2907 | }\r | |
2908 | //\r | |
2909 | // Call 16 bit UNDI ROM to open the network interface\r | |
2910 | //\r | |
2911 | GetMcastAddr.Status = INIT_PXE_STATUS;\r | |
2912 | CopyMem (&GetMcastAddr.InetAddr, IP, 4);\r | |
2913 | \r | |
2914 | Status = PxeUndiGetMcastAddr (SimpleNetworkDevice, &GetMcastAddr);\r | |
2915 | \r | |
2916 | if (EFI_ERROR (Status)) {\r | |
2917 | return Status;\r | |
2918 | }\r | |
2919 | //\r | |
2920 | // Check the status code from the 16 bit UNDI ROM\r | |
2921 | //\r | |
2922 | if (GetMcastAddr.Status != PXENV_STATUS_SUCCESS) {\r | |
2923 | return EFI_DEVICE_ERROR;\r | |
2924 | }\r | |
2925 | //\r | |
2926 | // Copy the MAC address from the returned data structure.\r | |
2927 | //\r | |
2928 | CopyMem (\r | |
2929 | MAC,\r | |
2930 | &GetMcastAddr.MediaAddr,\r | |
2931 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
2932 | );\r | |
2933 | \r | |
2934 | return Status;\r | |
2935 | }\r | |
2936 | //\r | |
2937 | // NvData()\r | |
2938 | //\r | |
2939 | /**\r | |
2940 | Performs read and write operations on the NVRAM device attached to a \r | |
2941 | network interface.\r | |
2942 | \r | |
2943 | @param This The protocol instance pointer.\r | |
2944 | @param ReadWrite TRUE for read operations, FALSE for write operations.\r | |
2945 | @param Offset Byte offset in the NVRAM device at which to start the read or\r | |
2946 | write operation. This must be a multiple of NvRamAccessSize and\r | |
2947 | less than NvRamSize.\r | |
2948 | @param BufferSize The number of bytes to read or write from the NVRAM device.\r | |
2949 | This must also be a multiple of NvramAccessSize.\r | |
2950 | @param Buffer A pointer to the data buffer.\r | |
2951 | \r | |
2952 | @retval EFI_SUCCESS The NVRAM access was performed.\r | |
2953 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
2954 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r | |
2955 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
2956 | @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r | |
2957 | \r | |
2958 | **/\r | |
2959 | EFI_STATUS\r | |
2960 | EFIAPI\r | |
2961 | Undi16SimpleNetworkNvData (\r | |
2962 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
2963 | IN BOOLEAN ReadWrite,\r | |
2964 | IN UINTN Offset,\r | |
2965 | IN UINTN BufferSize,\r | |
2966 | IN OUT VOID *Buffer\r | |
2967 | )\r | |
2968 | {\r | |
2969 | return EFI_UNSUPPORTED;\r | |
2970 | }\r | |
2971 | //\r | |
2972 | // GetStatus()\r | |
2973 | //\r | |
2974 | /**\r | |
2975 | Reads the current interrupt status and recycled transmit buffer status from \r | |
2976 | a network interface.\r | |
2977 | \r | |
2978 | @param This The protocol instance pointer.\r | |
2979 | @param InterruptStatus A pointer to the bit mask of the currently active interrupts\r | |
2980 | If this is NULL, the interrupt status will not be read from\r | |
2981 | the device. If this is not NULL, the interrupt status will\r | |
2982 | be read from the device. When the interrupt status is read,\r | |
2983 | it will also be cleared. Clearing the transmit interrupt\r | |
2984 | does not empty the recycled transmit buffer array.\r | |
2985 | @param TxBuf Recycled transmit buffer address. The network interface will\r | |
2986 | not transmit if its internal recycled transmit buffer array\r | |
2987 | is full. Reading the transmit buffer does not clear the\r | |
2988 | transmit interrupt. If this is NULL, then the transmit buffer\r | |
2989 | status will not be read. If there are no transmit buffers to\r | |
2990 | recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r | |
2991 | \r | |
2992 | @retval EFI_SUCCESS The status of the network interface was retrieved.\r | |
2993 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
2994 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r | |
2995 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
2996 | @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r | |
2997 | \r | |
2998 | **/\r | |
2999 | EFI_STATUS\r | |
3000 | EFIAPI\r | |
3001 | Undi16SimpleNetworkGetStatus (\r | |
3002 | IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r | |
3003 | OUT UINT32 *InterruptStatus OPTIONAL,\r | |
3004 | OUT VOID **TxBuf OPTIONAL\r | |
3005 | )\r | |
3006 | {\r | |
3007 | EFI_STATUS Status;\r | |
3008 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
3009 | UINTN FrameLength;\r | |
3010 | \r | |
3011 | if (This == NULL) {\r | |
3012 | return EFI_INVALID_PARAMETER;\r | |
3013 | }\r | |
3014 | \r | |
3015 | Status = EFI_SUCCESS;\r | |
3016 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
3017 | \r | |
3018 | if (SimpleNetworkDevice == NULL) {\r | |
3019 | return EFI_DEVICE_ERROR;\r | |
3020 | }\r | |
3021 | //\r | |
3022 | // Verify that the current state of the adapter is valid for this call.\r | |
3023 | //\r | |
3024 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
3025 | case EfiSimpleNetworkInitialized:\r | |
3026 | break;\r | |
3027 | \r | |
3028 | case EfiSimpleNetworkStopped:\r | |
3029 | return EFI_NOT_STARTED;\r | |
3030 | \r | |
3031 | case EfiSimpleNetworkStarted:\r | |
3032 | default:\r | |
3033 | return EFI_DEVICE_ERROR;\r | |
3034 | }\r | |
3035 | \r | |
3036 | if (InterruptStatus == NULL && TxBuf == NULL) {\r | |
3037 | return EFI_INVALID_PARAMETER;\r | |
3038 | }\r | |
3039 | \r | |
3040 | FrameLength = 0;\r | |
3041 | Status = Undi16SimpleNetworkIsr (This, &FrameLength, NULL, NULL, NULL, NULL);\r | |
3042 | \r | |
3043 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
3044 | if (EFI_ERROR (Status)) {\r | |
3045 | return Status;\r | |
3046 | }\r | |
3047 | }\r | |
3048 | //\r | |
3049 | // See if the caller wants interrupt info.\r | |
3050 | //\r | |
3051 | if (InterruptStatus != NULL) {\r | |
3052 | *InterruptStatus = SimpleNetworkDevice->InterruptStatus;\r | |
3053 | SimpleNetworkDevice->InterruptStatus = 0;\r | |
3054 | }\r | |
3055 | //\r | |
3056 | // See if the caller wants transmit buffer status info.\r | |
3057 | //\r | |
3058 | if (TxBuf != NULL) {\r | |
3059 | *TxBuf = 0;\r | |
3060 | SimpleNetworkTransmitFifoRemove (&(SimpleNetworkDevice->TxBufferFifo), TxBuf);\r | |
3061 | }\r | |
3062 | \r | |
3063 | return EFI_SUCCESS;\r | |
3064 | }\r | |
3065 | \r | |
3066 | /**\r | |
3067 | Places a packet in the transmit queue of a network interface.\r | |
3068 | \r | |
3069 | @param This The protocol instance pointer.\r | |
3070 | @param HeaderSize The size, in bytes, of the media header to be filled in by\r | |
3071 | the Transmit() function. If HeaderSize is non-zero, then it\r | |
3072 | must be equal to This->Mode->MediaHeaderSize and the DestAddr\r | |
3073 | and Protocol parameters must not be NULL.\r | |
3074 | @param BufferSize The size, in bytes, of the entire packet (media header and\r | |
3075 | data) to be transmitted through the network interface.\r | |
3076 | @param Buffer A pointer to the packet (media header followed by data) to be\r | |
3077 | transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r | |
3078 | then the media header in Buffer must already be filled in by the\r | |
3079 | caller. If HeaderSize is non-zero, then the media header will be\r | |
3080 | filled in by the Transmit() function.\r | |
3081 | @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter\r | |
3082 | is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r | |
3083 | This->Mode->CurrentAddress is used for the source HW MAC address.\r | |
3084 | @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this\r | |
3085 | parameter is ignored.\r | |
3086 | @param Protocol The type of header to build. If HeaderSize is zero, then this\r | |
3087 | parameter is ignored. See RFC 1700, section "Ether Types", for\r | |
3088 | examples.\r | |
3089 | \r | |
3090 | @retval EFI_SUCCESS The packet was placed on the transmit queue.\r | |
3091 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
3092 | @retval EFI_NOT_READY The network interface is too busy to accept this transmit request. \r | |
3093 | @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r | |
3094 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r | |
3095 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
3096 | @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r | |
3097 | \r | |
3098 | **/\r | |
3099 | EFI_STATUS\r | |
3100 | EFIAPI\r | |
3101 | Undi16SimpleNetworkTransmit (\r | |
3102 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
3103 | IN UINTN HeaderSize,\r | |
3104 | IN UINTN BufferSize,\r | |
3105 | IN VOID *Buffer,\r | |
3106 | IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,\r | |
3107 | IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,\r | |
3108 | IN UINT16 *Protocol OPTIONAL\r | |
3109 | )\r | |
3110 | {\r | |
3111 | EFI_STATUS Status;\r | |
3112 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
3113 | PXENV_UNDI_TRANSMIT_T XmitInfo;\r | |
3114 | \r | |
3115 | if (This == NULL) {\r | |
3116 | return EFI_INVALID_PARAMETER;\r | |
3117 | }\r | |
3118 | \r | |
3119 | Status = EFI_SUCCESS;\r | |
3120 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
3121 | \r | |
3122 | if (SimpleNetworkDevice == NULL) {\r | |
3123 | return EFI_DEVICE_ERROR;\r | |
3124 | }\r | |
3125 | //\r | |
3126 | // Verify that the current state of the adapter is valid for this call.\r | |
3127 | //\r | |
3128 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
3129 | case EfiSimpleNetworkInitialized:\r | |
3130 | break;\r | |
3131 | \r | |
3132 | case EfiSimpleNetworkStopped:\r | |
3133 | return EFI_NOT_STARTED;\r | |
3134 | \r | |
3135 | case EfiSimpleNetworkStarted:\r | |
3136 | default:\r | |
3137 | return EFI_DEVICE_ERROR;\r | |
3138 | }\r | |
3139 | \r | |
3140 | if (Buffer == NULL) {\r | |
3141 | return EFI_INVALID_PARAMETER;\r | |
3142 | }\r | |
3143 | \r | |
3144 | if (BufferSize < SimpleNetworkDevice->SimpleNetworkMode.MediaHeaderSize) {\r | |
3145 | return EFI_BUFFER_TOO_SMALL;\r | |
3146 | }\r | |
3147 | \r | |
3148 | if (HeaderSize != 0) {\r | |
3149 | if (HeaderSize != SimpleNetworkDevice->SimpleNetworkMode.MediaHeaderSize) {\r | |
3150 | return EFI_INVALID_PARAMETER;\r | |
3151 | }\r | |
3152 | \r | |
3153 | if (DestAddr == NULL || Protocol == NULL) {\r | |
3154 | return EFI_INVALID_PARAMETER;\r | |
3155 | }\r | |
3156 | \r | |
3157 | if (DestAddr != NULL) {\r | |
3158 | CopyMem (\r | |
3159 | Buffer,\r | |
3160 | DestAddr,\r | |
3161 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
3162 | );\r | |
3163 | }\r | |
3164 | \r | |
3165 | if (SrcAddr == NULL) {\r | |
3166 | SrcAddr = &SimpleNetworkDevice->SimpleNetworkMode.CurrentAddress;\r | |
3167 | }\r | |
3168 | \r | |
3169 | CopyMem (\r | |
3170 | (UINT8 *) Buffer + SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize,\r | |
3171 | SrcAddr,\r | |
3172 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
3173 | );\r | |
3174 | \r | |
3175 | if (Protocol != NULL) {\r | |
3176 | *(UINT16 *) ((UINT8 *) Buffer + 2 * SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize) = (UINT16) (((*Protocol & 0xFF) << 8) | ((*Protocol >> 8) & 0xFF));\r | |
3177 | }\r | |
3178 | }\r | |
3179 | //\r | |
3180 | // See if the recycled transmit buffer FIFO is full.\r | |
3181 | // If it is full, then we can not transmit until the caller calls GetStatus() to pull\r | |
3182 | // off recycled transmit buffers.\r | |
3183 | //\r | |
3184 | if (SimpleNetworkTransmitFifoFull (&(SimpleNetworkDevice->TxBufferFifo))) {\r | |
3185 | return EFI_NOT_READY;\r | |
3186 | }\r | |
3187 | //\r | |
3188 | // Output debug trace message.\r | |
3189 | //\r | |
3190 | DEBUG ((DEBUG_NET, "Undi16SimpleNetworkTransmit\n\r "));\r | |
3191 | \r | |
3192 | //\r | |
3193 | // Initialize UNDI WRITE parameter structure.\r | |
3194 | //\r | |
3195 | XmitInfo.Status = INIT_PXE_STATUS;\r | |
3196 | XmitInfo.Protocol = P_UNKNOWN;\r | |
3197 | XmitInfo.XmitFlag = XMT_DESTADDR;\r | |
3198 | XmitInfo.DestAddrOffset = (UINT16) ((UINT32)(UINTN) SimpleNetworkDevice->TxDestAddr & 0x000f);\r | |
3199 | XmitInfo.DestAddrSegment = (UINT16) ((UINT32)(UINTN) SimpleNetworkDevice->TxDestAddr >> 4);\r | |
3200 | XmitInfo.TBDOffset = (UINT16) ((UINT32)(UINTN) SimpleNetworkDevice->Xmit & 0x000f);\r | |
3201 | XmitInfo.TBDSegment = (UINT16) ((UINT32)(UINTN) SimpleNetworkDevice->Xmit >> 4);\r | |
3202 | XmitInfo.Reserved[0] = 0;\r | |
3203 | XmitInfo.Reserved[1] = 0;\r | |
3204 | \r | |
3205 | CopyMem (\r | |
3206 | SimpleNetworkDevice->TxDestAddr,\r | |
3207 | Buffer,\r | |
3208 | SimpleNetworkDevice->SimpleNetworkMode.HwAddressSize\r | |
3209 | );\r | |
3210 | \r | |
3211 | CopyMem (\r | |
3212 | SimpleNetworkDevice->TxRealModeMediaHeader,\r | |
3213 | Buffer,\r | |
3214 | SimpleNetworkDevice->SimpleNetworkMode.MediaHeaderSize\r | |
3215 | );\r | |
3216 | \r | |
3217 | SimpleNetworkDevice->Xmit->ImmedLength = (UINT16) SimpleNetworkDevice->SimpleNetworkMode.MediaHeaderSize;\r | |
3218 | \r | |
3219 | SimpleNetworkDevice->Xmit->DataBlock[0].TDDataLen = (UINT16) (BufferSize - SimpleNetworkDevice->Xmit->ImmedLength);\r | |
3220 | \r | |
3221 | CopyMem (\r | |
3222 | SimpleNetworkDevice->TxRealModeDataBuffer,\r | |
3223 | (UINT8 *) Buffer + SimpleNetworkDevice->SimpleNetworkMode.MediaHeaderSize,\r | |
3224 | SimpleNetworkDevice->Xmit->DataBlock[0].TDDataLen\r | |
3225 | );\r | |
3226 | \r | |
3227 | //\r | |
3228 | // Make API call to UNDI TRANSMIT\r | |
3229 | //\r | |
3230 | XmitInfo.Status = 0;\r | |
3231 | \r | |
3232 | Status = PxeUndiTransmit (SimpleNetworkDevice, &XmitInfo);\r | |
3233 | \r | |
3234 | if (EFI_ERROR (Status)) {\r | |
3235 | return Status;\r | |
3236 | }\r | |
3237 | //\r | |
3238 | // Check the status code from the 16 bit UNDI ROM\r | |
3239 | //\r | |
3240 | switch (XmitInfo.Status) {\r | |
3241 | case PXENV_STATUS_OUT_OF_RESOURCES:\r | |
3242 | return EFI_NOT_READY;\r | |
3243 | \r | |
3244 | case PXENV_STATUS_SUCCESS:\r | |
3245 | break;\r | |
3246 | \r | |
3247 | default:\r | |
3248 | return EFI_DEVICE_ERROR;\r | |
3249 | }\r | |
3250 | //\r | |
3251 | // Add address of Buffer to the recycled transmit buffer FIFO\r | |
3252 | //\r | |
3253 | SimpleNetworkTransmitFifoAdd (&(SimpleNetworkDevice->TxBufferFifo), Buffer);\r | |
3254 | \r | |
3255 | return EFI_SUCCESS;\r | |
3256 | }\r | |
3257 | \r | |
3258 | /**\r | |
3259 | Receives a packet from a network interface.\r | |
3260 | \r | |
3261 | @param This The protocol instance pointer.\r | |
3262 | @param HeaderSize The size, in bytes, of the media header received on the network\r | |
3263 | interface. If this parameter is NULL, then the media header size\r | |
3264 | will not be returned.\r | |
3265 | @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r | |
3266 | bytes, of the packet that was received on the network interface.\r | |
3267 | @param Buffer A pointer to the data buffer to receive both the media header and\r | |
3268 | the data.\r | |
3269 | @param SrcAddr The source HW MAC address. If this parameter is NULL, the\r | |
3270 | HW MAC source address will not be extracted from the media\r | |
3271 | header.\r | |
3272 | @param DestAddr The destination HW MAC address. If this parameter is NULL,\r | |
3273 | the HW MAC destination address will not be extracted from the\r | |
3274 | media header.\r | |
3275 | @param Protocol The media header type. If this parameter is NULL, then the\r | |
3276 | protocol will not be extracted from the media header. See\r | |
3277 | RFC 1700 section "Ether Types" for examples.\r | |
3278 | \r | |
3279 | @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has\r | |
3280 | been updated to the number of bytes received.\r | |
3281 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
3282 | @retval EFI_NOT_READY The network interface is too busy to accept this transmit\r | |
3283 | request.\r | |
3284 | @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r | |
3285 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r | |
3286 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
3287 | @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r | |
3288 | \r | |
3289 | **/\r | |
3290 | EFI_STATUS\r | |
3291 | EFIAPI\r | |
3292 | Undi16SimpleNetworkReceive (\r | |
3293 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
3294 | OUT UINTN *HeaderSize OPTIONAL,\r | |
3295 | IN OUT UINTN *BufferSize,\r | |
3296 | OUT VOID *Buffer,\r | |
3297 | OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,\r | |
3298 | OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,\r | |
3299 | OUT UINT16 *Protocol OPTIONAL\r | |
3300 | )\r | |
3301 | {\r | |
3302 | EFI_STATUS Status;\r | |
3303 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
3304 | UINTN MediaAddrSize;\r | |
3305 | UINT8 ProtType;\r | |
3306 | \r | |
3307 | if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r | |
3308 | return EFI_INVALID_PARAMETER;\r | |
3309 | }\r | |
3310 | \r | |
3311 | Status = EFI_SUCCESS;\r | |
3312 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
3313 | \r | |
3314 | if (SimpleNetworkDevice == NULL) {\r | |
3315 | return EFI_DEVICE_ERROR;\r | |
3316 | }\r | |
3317 | //\r | |
3318 | // Verify that the current state of the adapter is valid for this call.\r | |
3319 | //\r | |
3320 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
3321 | case EfiSimpleNetworkInitialized:\r | |
3322 | break;\r | |
3323 | \r | |
3324 | case EfiSimpleNetworkStopped:\r | |
3325 | return EFI_NOT_STARTED;\r | |
3326 | \r | |
3327 | case EfiSimpleNetworkStarted:\r | |
3328 | default:\r | |
3329 | return EFI_DEVICE_ERROR;\r | |
3330 | }\r | |
3331 | \r | |
3332 | Status = Undi16SimpleNetworkIsr (\r | |
3333 | This,\r | |
3334 | BufferSize,\r | |
3335 | HeaderSize,\r | |
3336 | Buffer,\r | |
3337 | &ProtType,\r | |
3338 | NULL\r | |
3339 | );\r | |
3340 | \r | |
3341 | if (EFI_ERROR (Status)) {\r | |
3342 | return Status;\r | |
3343 | }\r | |
3344 | \r | |
3345 | if ((SimpleNetworkDevice->InterruptStatus & EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT) == 0) {\r | |
3346 | return EFI_NOT_READY;\r | |
3347 | \r | |
3348 | }\r | |
3349 | \r | |
3350 | SimpleNetworkDevice->InterruptStatus &= ~EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;\r | |
3351 | \r | |
3352 | MediaAddrSize = This->Mode->HwAddressSize;\r | |
3353 | \r | |
3354 | if (SrcAddr != NULL) {\r | |
3355 | CopyMem (SrcAddr, (UINT8 *) Buffer + MediaAddrSize, MediaAddrSize);\r | |
3356 | }\r | |
3357 | \r | |
3358 | if (DestAddr != NULL) {\r | |
3359 | CopyMem (DestAddr, Buffer, MediaAddrSize);\r | |
3360 | }\r | |
3361 | \r | |
3362 | if (Protocol != NULL) {\r | |
3363 | *((UINT8 *) Protocol) = *((UINT8 *) Buffer + (2 * MediaAddrSize) + 1);\r | |
3364 | *((UINT8 *) Protocol + 1) = *((UINT8 *) Buffer + (2 * MediaAddrSize));\r | |
3365 | }\r | |
3366 | \r | |
3367 | DEBUG ((DEBUG_NET, "Packet Received: BufferSize=%d HeaderSize = %d\n", *BufferSize, *HeaderSize));\r | |
3368 | \r | |
3369 | return Status;\r | |
3370 | \r | |
3371 | }\r | |
3372 | //\r | |
3373 | // WaitForPacket()\r | |
3374 | //\r | |
3375 | /**\r | |
3376 | wait for a packet to be received.\r | |
3377 | \r | |
3378 | @param Event Event used with WaitForEvent() to wait for a packet to be received.\r | |
3379 | @param Context Event Context\r | |
3380 | \r | |
3381 | **/\r | |
3382 | VOID\r | |
3383 | EFIAPI\r | |
3384 | Undi16SimpleNetworkWaitForPacket (\r | |
3385 | IN EFI_EVENT Event,\r | |
3386 | IN VOID *Context\r | |
3387 | )\r | |
3388 | {\r | |
3389 | //\r | |
3390 | // Someone is waiting on the receive packet event, if there's\r | |
3391 | // a packet pending, signal the event\r | |
3392 | //\r | |
3393 | if (!EFI_ERROR (Undi16SimpleNetworkCheckForPacket (Context))) {\r | |
3394 | gBS->SignalEvent (Event);\r | |
3395 | }\r | |
3396 | }\r | |
3397 | //\r | |
3398 | // CheckForPacket()\r | |
3399 | //\r | |
3400 | /**\r | |
3401 | Check whether packet is ready for receive.\r | |
3402 | \r | |
3403 | @param This The protocol instance pointer.\r | |
3404 | \r | |
3405 | @retval EFI_SUCCESS Receive data is ready.\r | |
3406 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
3407 | @retval EFI_NOT_READY The network interface is too busy to accept this transmit\r | |
3408 | request.\r | |
3409 | @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r | |
3410 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r | |
3411 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
3412 | @retval EFI_UNSUPPORTED This function is not supported by the network interface.\r | |
3413 | **/\r | |
3414 | EFI_STATUS\r | |
3415 | Undi16SimpleNetworkCheckForPacket (\r | |
3416 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
3417 | )\r | |
3418 | {\r | |
3419 | EFI_STATUS Status;\r | |
3420 | EFI_SIMPLE_NETWORK_DEV *SimpleNetworkDevice;\r | |
3421 | UINTN FrameLength;\r | |
3422 | \r | |
3423 | if (This == NULL) {\r | |
3424 | return EFI_INVALID_PARAMETER;\r | |
3425 | }\r | |
3426 | \r | |
3427 | Status = EFI_SUCCESS;\r | |
3428 | SimpleNetworkDevice = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r | |
3429 | \r | |
3430 | if (SimpleNetworkDevice == NULL) {\r | |
3431 | return EFI_DEVICE_ERROR;\r | |
3432 | }\r | |
3433 | //\r | |
3434 | // Verify that the current state of the adapter is valid for this call.\r | |
3435 | //\r | |
3436 | switch (SimpleNetworkDevice->SimpleNetworkMode.State) {\r | |
3437 | case EfiSimpleNetworkInitialized:\r | |
3438 | break;\r | |
3439 | \r | |
3440 | case EfiSimpleNetworkStopped:\r | |
3441 | return EFI_NOT_STARTED;\r | |
3442 | \r | |
3443 | case EfiSimpleNetworkStarted:\r | |
3444 | default:\r | |
3445 | return EFI_DEVICE_ERROR;\r | |
3446 | }\r | |
3447 | \r | |
3448 | FrameLength = 0;\r | |
3449 | Status = Undi16SimpleNetworkIsr (\r | |
3450 | This,\r | |
3451 | &FrameLength,\r | |
3452 | NULL,\r | |
3453 | NULL,\r | |
3454 | NULL,\r | |
3455 | NULL\r | |
3456 | );\r | |
3457 | \r | |
3458 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
3459 | if (EFI_ERROR (Status)) {\r | |
3460 | return Status;\r | |
3461 | }\r | |
3462 | }\r | |
3463 | \r | |
3464 | return ((SimpleNetworkDevice->InterruptStatus & EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT) != 0) ? EFI_SUCCESS : EFI_NOT_READY;\r | |
3465 | }\r | |
3466 | \r | |
3467 | /**\r | |
3468 | Signal handlers for ExitBootServices event.\r | |
3469 | \r | |
3470 | Clean up any Real-mode UNDI residue from the system \r | |
3471 | \r | |
3472 | @param Event ExitBootServices event\r | |
3473 | @param Context \r | |
3474 | **/\r | |
3475 | VOID\r | |
3476 | EFIAPI\r | |
3477 | Undi16SimpleNetworkEvent (\r | |
3478 | IN EFI_EVENT Event,\r | |
3479 | IN VOID *Context\r | |
3480 | )\r | |
3481 | {\r | |
3482 | //\r | |
3483 | // NOTE: This is not the only way to effect this cleanup. The prescribed mechanism\r | |
3484 | // would be to perform an UNDI STOP command. This strategam has been attempted\r | |
3485 | // but results in problems making some of the EFI core services from TPL_CALLBACK.\r | |
3486 | // This issue needs to be resolved, but the other alternative has been to perform\r | |
3487 | // the unchain logic explicitly, as done below.\r | |
3488 | //\r | |
3489 | RestoreCachedVectorAddress (0x1A);\r | |
3490 | }\r | |
3491 | \r | |
3492 | /**\r | |
3493 | Allocate buffer below 1M for real mode.\r | |
3494 | \r | |
3495 | @param NumPages The number pages want to be allocated.\r | |
3496 | @param Buffer On return, allocated buffer.\r | |
3497 | \r | |
3498 | @return Status of allocating pages.\r | |
3499 | **/\r | |
3500 | EFI_STATUS\r | |
3501 | BiosSnp16AllocatePagesBelowOneMb (\r | |
3502 | UINTN NumPages,\r | |
3503 | VOID **Buffer\r | |
3504 | )\r | |
3505 | {\r | |
3506 | EFI_STATUS Status;\r | |
3507 | EFI_PHYSICAL_ADDRESS PhysicalAddress;\r | |
3508 | \r | |
3509 | PhysicalAddress = 0x000fffff;\r | |
3510 | Status = gBS->AllocatePages (\r | |
3511 | AllocateMaxAddress,\r | |
3512 | EfiRuntimeServicesData,\r | |
3513 | NumPages,\r | |
3514 | &PhysicalAddress\r | |
3515 | );\r | |
3516 | if (EFI_ERROR (Status)) {\r | |
3517 | return Status;\r | |
3518 | }\r | |
3519 | \r | |
3520 | *Buffer = (VOID *) (UINTN) PhysicalAddress;\r | |
3521 | return EFI_SUCCESS;\r | |
3522 | }\r |