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