3 Copyright (c) 1999 - 2012, Intel Corporation. All rights reserved.<BR>
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
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.
16 #include "BiosSnp16.h"
20 /// EFI Driver Binding Protocol Instance
22 EFI_DRIVER_BINDING_PROTOCOL gBiosSnp16DriverBinding
= {
23 BiosSnp16DriverBindingSupported
,
24 BiosSnp16DriverBindingStart
,
25 BiosSnp16DriverBindingStop
,
32 /// This boolean is used to determine if we should release the cached vector during an error condition.
34 BOOLEAN mCachedInt1A
= FALSE
;
37 // Private worker functions;
41 Start the UNDI interface.
43 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
44 @param Ax PCI address of Undi device.
46 @retval EFI_DEVICE_ERROR Fail to start 16 bit UNDI ROM.
47 @retval Others Status of start 16 bit UNDI ROM.
50 Undi16SimpleNetworkStartUndi (
51 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
,
56 Start the UNDI interface
58 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
60 @retval EFI_DEVICE_ERROR Fail to start 16 bit UNDI ROM.
61 @retval Others Status of start 16 bit UNDI ROM.
64 Undi16SimpleNetworkStopUndi (
65 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
69 Stop the UNDI interface
71 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
73 @retval EFI_DEVICE_ERROR Fail to stop 16 bit UNDI ROM.
74 @retval Others Status of stop 16 bit UNDI ROM.
77 Undi16SimpleNetworkCleanupUndi (
78 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
82 Get runtime information for Undi network interface
84 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
86 @retval EFI_SUCCESS Sucess operation.
87 @retval Others Fail to get runtime information for Undi network interface.
90 Undi16SimpleNetworkGetInformation (
91 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
97 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
99 @retval EFI_SUCCESS Sucess operation.
100 @retval Others Fail to get NIC type.
103 Undi16SimpleNetworkGetNicType (
104 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
110 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
112 @retval EFI_SUCCESS Sucess operation.
113 @retval Others Fail to get NDIS information.
116 Undi16SimpleNetworkGetNdisInfo (
117 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
121 Signal handlers for ExitBootServices event.
123 Clean up any Real-mode UNDI residue from the system
125 @param Event ExitBootServices event
130 Undi16SimpleNetworkEvent (
136 Loads the undi driver.
138 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
140 @retval EFI_SUCCESS - Successfully loads undi driver.
141 @retval EFI_NOT_FOUND - Doesn't find undi driver or undi driver load failure.
144 Undi16SimpleNetworkLoadUndi (
145 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
149 Unload 16 bit UNDI Option ROM from memory
151 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
156 Undi16SimpleNetworkUnloadUndi (
157 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
161 Entry point for EFI drivers.
163 @param ImageHandle Handle that identifies the loaded image.
164 @param SystemTable System Table for this image.
166 @return EFI_STATUS Return status from EfiLibInstallAllDriverProtocols.
170 BiosSnp16DriverEntryPoint (
171 IN EFI_HANDLE ImageHandle
,
172 IN EFI_SYSTEM_TABLE
*SystemTable
175 return EfiLibInstallDriverBindingComponentName2 (
178 &gBiosSnp16DriverBinding
,
180 &gBiosSnp16ComponentName
,
181 &gBiosSnp16ComponentName2
186 // EFI Driver Binding Protocol Functions
189 Tests to see if this driver supports a given controller.
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.
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.
202 BiosSnp16DriverBindingSupported (
203 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
204 IN EFI_HANDLE Controller
,
205 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
209 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
210 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
211 EFI_PCI_IO_PROTOCOL
*PciIo
;
215 // See if the Legacy BIOS Protocol is available
217 Status
= gBS
->LocateProtocol (&gEfiLegacyBiosProtocolGuid
, NULL
, (VOID
**) &LegacyBios
);
218 if (EFI_ERROR (Status
)) {
222 // Open the IO Abstraction(s) needed to perform the supported test
224 Status
= gBS
->OpenProtocol (
226 &gEfiDevicePathProtocolGuid
,
227 (VOID
**) &DevicePath
,
228 This
->DriverBindingHandle
,
230 EFI_OPEN_PROTOCOL_BY_DRIVER
232 if (EFI_ERROR (Status
)) {
238 &gEfiDevicePathProtocolGuid
,
239 This
->DriverBindingHandle
,
244 // Open the IO Abstraction(s) needed to perform the supported test
246 Status
= gBS
->OpenProtocol (
248 &gEfiPciIoProtocolGuid
,
250 This
->DriverBindingHandle
,
252 EFI_OPEN_PROTOCOL_BY_DRIVER
254 if (EFI_ERROR (Status
)) {
258 // See if this is a PCI Network Controller by looking at the Command register and
259 // Class Code Register
261 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0, sizeof (Pci
) / sizeof (UINT32
), &Pci
);
262 if (EFI_ERROR (Status
)) {
263 Status
= EFI_UNSUPPORTED
;
267 Status
= EFI_UNSUPPORTED
;
268 if (Pci
.Hdr
.ClassCode
[2] == PCI_CLASS_NETWORK
) {
269 Status
= EFI_SUCCESS
;
275 &gEfiPciIoProtocolGuid
,
276 This
->DriverBindingHandle
,
284 Starts the Snp device controller
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.
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.
296 BiosSnp16DriverBindingStart (
297 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
298 IN EFI_HANDLE Controller
,
299 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
303 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
304 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
305 EFI_PCI_IO_PROTOCOL
*PciIo
;
306 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
317 SimpleNetworkDevice
= NULL
;
321 // See if the Legacy BIOS Protocol is available
323 Status
= gBS
->LocateProtocol (&gEfiLegacyBiosProtocolGuid
, NULL
, (VOID
**) &LegacyBios
);
324 if (EFI_ERROR (Status
)) {
328 // Open the IO Abstraction(s) needed
330 Status
= gBS
->OpenProtocol (
332 &gEfiDevicePathProtocolGuid
,
333 (VOID
**) &DevicePath
,
334 This
->DriverBindingHandle
,
336 EFI_OPEN_PROTOCOL_BY_DRIVER
338 if (EFI_ERROR (Status
)) {
342 Status
= gBS
->OpenProtocol (
344 &gEfiPciIoProtocolGuid
,
346 This
->DriverBindingHandle
,
348 EFI_OPEN_PROTOCOL_BY_DRIVER
350 if (EFI_ERROR (Status
)) {
354 Status
= PciIo
->Attributes (
356 EfiPciIoAttributeOperationSupported
,
360 if (!EFI_ERROR (Status
)) {
361 Supports
&= EFI_PCI_DEVICE_ENABLE
;
362 Status
= PciIo
->Attributes (
364 EfiPciIoAttributeOperationEnable
,
370 if (EFI_ERROR (Status
)) {
374 // Check to see if there is a legacy option ROM image associated with this PCI device
376 Status
= LegacyBios
->CheckPciRom (
383 if (EFI_ERROR (Status
)) {
387 // Post the legacy option ROM if it is available.
389 Status
= LegacyBios
->InstallPciRom (
399 if (EFI_ERROR (Status
)) {
403 // Allocate memory for this SimpleNetwork device instance
405 Status
= gBS
->AllocatePool (
407 sizeof (EFI_SIMPLE_NETWORK_DEV
),
408 (VOID
**) &SimpleNetworkDevice
410 if (EFI_ERROR (Status
)) {
411 Status
= EFI_OUT_OF_RESOURCES
;
415 ZeroMem (SimpleNetworkDevice
, sizeof (EFI_SIMPLE_NETWORK_DEV
));
418 // Initialize the SimpleNetwork device instance
420 SimpleNetworkDevice
->Signature
= EFI_SIMPLE_NETWORK_DEV_SIGNATURE
;
421 SimpleNetworkDevice
->LegacyBios
= LegacyBios
;
422 SimpleNetworkDevice
->BaseDevicePath
= DevicePath
;
423 SimpleNetworkDevice
->PciIo
= PciIo
;
426 // Initialize the Nii Protocol
428 SimpleNetworkDevice
->Nii
.Revision
= EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL_REVISION
;
429 SimpleNetworkDevice
->Nii
.Type
= EfiNetworkInterfaceUndi
;
431 CopyMem (&SimpleNetworkDevice
->Nii
.StringId
, "UNDI", 4);
434 // Load 16 bit UNDI Option ROM into Memory
436 Status
= Undi16SimpleNetworkLoadUndi (SimpleNetworkDevice
);
437 if (EFI_ERROR (Status
)) {
438 DEBUG ((DEBUG_NET
, "ERROR : Could not load UNDI. Status = %r\n", Status
));
442 SimpleNetworkDevice
->UndiLoaded
= TRUE
;
445 // Call PXENV_START_UNDI - Initilizes the UNID interface for use.
447 PciIo
->GetLocation (PciIo
, &Segment
, &Bus
, &Device
, &Function
);
448 Status
= Undi16SimpleNetworkStartUndi (
450 (UINT16
) ((Bus
<< 0x8) | (Device
<< 0x3) | (Function
))
452 if (EFI_ERROR (Status
)) {
453 DEBUG ((DEBUG_NET
, "ERROR : Could not StartUndi. Status = %r\n", Status
));
457 // Initialize the Simple Network Protocol
459 DEBUG ((DEBUG_NET
, "Initialize SimpleNetworkDevice instance\n"));
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
);
477 Status
= gBS
->CreateEvent (
480 Undi16SimpleNetworkWaitForPacket
,
481 &SimpleNetworkDevice
->SimpleNetwork
,
482 &SimpleNetworkDevice
->SimpleNetwork
.WaitForPacket
484 if (EFI_ERROR (Status
)) {
485 DEBUG ((DEBUG_ERROR
, "ERROR : Could not create event. Status = %r\n", Status
));
489 // Create an event to be signalled when ExitBootServices occurs in order
490 // to clean up nicely
492 Status
= gBS
->CreateEventEx (
495 Undi16SimpleNetworkEvent
,
497 &gEfiEventExitBootServicesGuid
,
498 &SimpleNetworkDevice
->EfiBootEvent
500 if (EFI_ERROR (Status
)) {
501 DEBUG ((DEBUG_ERROR
, "ERROR : Could not create event. Status = %r\n", Status
));
506 // Create an event to be signalled when Legacy Boot occurs to clean up the IVT
508 Status
= EfiCreateEventLegacyBootEx(
510 Undi16SimpleNetworkEvent
,
512 &SimpleNetworkDevice
->LegacyBootEvent
515 if (EFI_ERROR(Status
)) {
516 DEBUG ((DEBUG_ERROR
,"ERROR : Could not create event. Status = %r\n",Status
));
521 // Initialize the SimpleNetwork Mode Information
523 DEBUG ((DEBUG_NET
, "Initialize Mode Information\n"));
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
;
537 // Initialize the SimpleNetwork Private Information
539 DEBUG ((DEBUG_NET
, "Initialize Private Information\n"));
541 Status
= BiosSnp16AllocatePagesBelowOneMb (
542 sizeof (PXENV_UNDI_TBD_T
) / EFI_PAGE_SIZE
+ 1,
543 (VOID
**) &SimpleNetworkDevice
->Xmit
545 if (EFI_ERROR (Status
)) {
549 Status
= BiosSnp16AllocatePagesBelowOneMb (
551 &SimpleNetworkDevice
->TxRealModeMediaHeader
553 if (EFI_ERROR (Status
)) {
557 Status
= BiosSnp16AllocatePagesBelowOneMb (
559 &SimpleNetworkDevice
->TxRealModeDataBuffer
561 if (EFI_ERROR (Status
)) {
565 Status
= BiosSnp16AllocatePagesBelowOneMb (
567 &SimpleNetworkDevice
->TxDestAddr
569 if (EFI_ERROR (Status
)) {
573 SimpleNetworkDevice
->Xmit
->XmitOffset
= (UINT16
) (((UINT32
)(UINTN
) SimpleNetworkDevice
->TxRealModeMediaHeader
) & 0x000f);
575 SimpleNetworkDevice
->Xmit
->XmitSegment
= (UINT16
) (((UINT32
)(UINTN
) SimpleNetworkDevice
->TxRealModeMediaHeader
) >> 4);
577 SimpleNetworkDevice
->Xmit
->DataBlkCount
= 1;
579 SimpleNetworkDevice
->Xmit
->DataBlock
[0].TDPtrType
= 1;
580 SimpleNetworkDevice
->Xmit
->DataBlock
[0].TDRsvdByte
= 0;
582 SimpleNetworkDevice
->Xmit
->DataBlock
[0].TDDataPtrOffset
= (UINT16
) (((UINT32
)(UINTN
) SimpleNetworkDevice
->TxRealModeDataBuffer
) & 0x000f);
584 SimpleNetworkDevice
->Xmit
->DataBlock
[0].TDDataPtrSegment
= (UINT16
) (((UINT32
)(UINTN
) SimpleNetworkDevice
->TxRealModeDataBuffer
) >> 4);
586 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
587 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
590 // Start() the SimpleNetwork device
592 DEBUG ((DEBUG_NET
, "Start()\n"));
594 Status
= Undi16SimpleNetworkStart (&SimpleNetworkDevice
->SimpleNetwork
);
595 if (EFI_ERROR (Status
)) {
599 // GetInformation() the SimpleNetwork device
601 DEBUG ((DEBUG_NET
, "GetInformation()\n"));
603 Status
= Undi16SimpleNetworkGetInformation (&SimpleNetworkDevice
->SimpleNetwork
);
604 if (EFI_ERROR (Status
)) {
608 // Build the device path for the child device
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
));
615 &Node
.MacAddr
.MacAddress
,
616 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
617 sizeof (EFI_MAC_ADDRESS
)
619 SimpleNetworkDevice
->DevicePath
= AppendDevicePathNode (
620 SimpleNetworkDevice
->BaseDevicePath
,
625 // GetNicType() the SimpleNetwork device
627 DEBUG ((DEBUG_NET
, "GetNicType()\n"));
629 Status
= Undi16SimpleNetworkGetNicType (&SimpleNetworkDevice
->SimpleNetwork
);
630 if (EFI_ERROR (Status
)) {
634 // GetNdisInfo() the SimpleNetwork device
636 DEBUG ((DEBUG_NET
, "GetNdisInfo()\n"));
638 Status
= Undi16SimpleNetworkGetNdisInfo (&SimpleNetworkDevice
->SimpleNetwork
);
639 if (EFI_ERROR (Status
)) {
643 // Stop() the SimpleNetwork device
645 DEBUG ((DEBUG_NET
, "Stop()\n"));
647 Status
= SimpleNetworkDevice
->SimpleNetwork
.Stop (&SimpleNetworkDevice
->SimpleNetwork
);
648 if (EFI_ERROR (Status
)) {
652 // Print Mode information
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
]));
669 DEBUG ((DEBUG_NET
, "\n"));
672 DEBUG ((DEBUG_NET
, "CurrentAddress = "));
673 for (Index2
= 0; Index2
< 16; Index2
++) {
674 DEBUG ((DEBUG_NET
, "%02x ", SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
.Addr
[Index2
]));
677 DEBUG ((DEBUG_NET
, "\n"));
679 DEBUG ((DEBUG_NET
, "BroadcastAddress = "));
680 for (Index2
= 0; Index2
< 16; Index2
++) {
681 DEBUG ((DEBUG_NET
, "%02x ", SimpleNetworkDevice
->SimpleNetworkMode
.BroadcastAddress
.Addr
[Index2
]));
684 DEBUG ((DEBUG_NET
, "\n"));
686 DEBUG ((DEBUG_NET
, "PermanentAddress = "));
687 for (Index2
= 0; Index2
< 16; Index2
++) {
688 DEBUG ((DEBUG_NET
, "%02x ", SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
.Addr
[Index2
]));
691 DEBUG ((DEBUG_NET
, "\n"));
694 // The network device was started, information collected, and stopped.
695 // Install protocol interfaces for the SimpleNetwork device.
697 DEBUG ((DEBUG_NET
, "Install Protocol Interfaces on network interface\n"));
699 Status
= gBS
->InstallMultipleProtocolInterfaces (
700 &SimpleNetworkDevice
->Handle
,
701 &gEfiSimpleNetworkProtocolGuid
,
702 &SimpleNetworkDevice
->SimpleNetwork
,
703 &gEfiNetworkInterfaceIdentifierProtocolGuid
,
704 &SimpleNetworkDevice
->Nii
,
705 &gEfiDevicePathProtocolGuid
,
706 SimpleNetworkDevice
->DevicePath
,
709 if (EFI_ERROR (Status
)) {
713 // Open PCI I/O from the newly created child handle
715 Status
= gBS
->OpenProtocol (
717 &gEfiPciIoProtocolGuid
,
719 This
->DriverBindingHandle
,
720 SimpleNetworkDevice
->Handle
,
721 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
724 DEBUG ((DEBUG_INIT
, "UNDI16 Driver : EFI_SUCCESS\n"));
727 if (EFI_ERROR (Status
)) {
728 if (SimpleNetworkDevice
!= NULL
) {
730 Undi16SimpleNetworkShutdown (&SimpleNetworkDevice
->SimpleNetwork
);
734 Undi16SimpleNetworkCleanupUndi (SimpleNetworkDevice
);
738 Undi16SimpleNetworkStopUndi (SimpleNetworkDevice
);
742 if (SimpleNetworkDevice
->UndiLoaded
) {
743 Undi16SimpleNetworkUnloadUndi (SimpleNetworkDevice
);
746 if (SimpleNetworkDevice
->SimpleNetwork
.WaitForPacket
!= NULL
) {
747 gBS
->CloseEvent (SimpleNetworkDevice
->SimpleNetwork
.WaitForPacket
);
750 if (SimpleNetworkDevice
->LegacyBootEvent
!= NULL
) {
751 gBS
->CloseEvent (SimpleNetworkDevice
->LegacyBootEvent
);
754 if (SimpleNetworkDevice
->EfiBootEvent
!= NULL
) {
755 gBS
->CloseEvent (SimpleNetworkDevice
->EfiBootEvent
);
758 if (SimpleNetworkDevice
->Xmit
!= NULL
) {
760 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->Xmit
,
761 sizeof (PXENV_UNDI_TBD_T
) / EFI_PAGE_SIZE
+ 1
765 if (SimpleNetworkDevice
->TxRealModeMediaHeader
!= NULL
) {
766 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->TxRealModeMediaHeader
, 1);
769 if (SimpleNetworkDevice
->TxRealModeDataBuffer
!= NULL
) {
770 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->TxRealModeDataBuffer
, 1);
773 if (SimpleNetworkDevice
->TxDestAddr
!= NULL
) {
774 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->TxDestAddr
, 1);
777 gBS
->FreePool (SimpleNetworkDevice
);
780 // Only restore the vector if it was cached.
783 RestoreCachedVectorAddress (0x1A);
784 mCachedInt1A
= FALSE
;
789 Status
= PciIo
->Attributes (
791 EfiPciIoAttributeOperationSupported
,
795 if (!EFI_ERROR (Status
)) {
796 Supports
&= EFI_PCI_DEVICE_ENABLE
;
797 Status
= PciIo
->Attributes (
799 EfiPciIoAttributeOperationDisable
,
808 &gEfiPciIoProtocolGuid
,
809 This
->DriverBindingHandle
,
815 &gEfiDevicePathProtocolGuid
,
816 This
->DriverBindingHandle
,
819 if (Status
!= EFI_OUT_OF_RESOURCES
) {
820 Status
= EFI_DEVICE_ERROR
;
827 Stops the device by given device controller.
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.
835 @retval EFI_SUCCESS - The device was stopped.
836 @retval EFI_DEVICE_ERROR - The device could not be stopped due to a device error.
840 BiosSnp16DriverBindingStop (
841 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
842 IN EFI_HANDLE Controller
,
843 IN UINTN NumberOfChildren
,
844 IN EFI_HANDLE
*ChildHandleBuffer
849 BOOLEAN AllChildrenStopped
;
850 EFI_SIMPLE_NETWORK_PROTOCOL
*SimpleNetwork
;
851 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
852 EFI_PCI_IO_PROTOCOL
*PciIo
;
856 // Complete all outstanding transactions to Controller.
857 // Don't allow any new transaction to Controller to be started.
859 if (NumberOfChildren
== 0) {
861 // Close the bus driver
863 Status
= gBS
->OpenProtocol (
865 &gEfiPciIoProtocolGuid
,
867 This
->DriverBindingHandle
,
869 EFI_OPEN_PROTOCOL_GET_PROTOCOL
871 if (!EFI_ERROR (Status
)) {
872 Status
= PciIo
->Attributes (
874 EfiPciIoAttributeOperationSupported
,
878 if (!EFI_ERROR (Status
)) {
879 Supports
&= EFI_PCI_DEVICE_ENABLE
;
880 Status
= PciIo
->Attributes (
882 EfiPciIoAttributeOperationDisable
,
889 Status
= gBS
->CloseProtocol (
891 &gEfiPciIoProtocolGuid
,
892 This
->DriverBindingHandle
,
896 Status
= gBS
->CloseProtocol (
898 &gEfiDevicePathProtocolGuid
,
899 This
->DriverBindingHandle
,
903 if (EFI_ERROR (Status
)) {
904 Status
= EFI_DEVICE_ERROR
;
909 AllChildrenStopped
= TRUE
;
911 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
913 Status
= gBS
->OpenProtocol (
914 ChildHandleBuffer
[Index
],
915 &gEfiSimpleNetworkProtocolGuid
,
916 (VOID
**) &SimpleNetwork
,
917 This
->DriverBindingHandle
,
919 EFI_OPEN_PROTOCOL_GET_PROTOCOL
921 if (!EFI_ERROR (Status
)) {
923 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (SimpleNetwork
);
925 Status
= gBS
->CloseProtocol (
927 &gEfiPciIoProtocolGuid
,
928 This
->DriverBindingHandle
,
929 ChildHandleBuffer
[Index
]
932 Status
= gBS
->UninstallMultipleProtocolInterfaces (
933 SimpleNetworkDevice
->Handle
,
934 &gEfiSimpleNetworkProtocolGuid
,
935 &SimpleNetworkDevice
->SimpleNetwork
,
936 &gEfiNetworkInterfaceIdentifierProtocolGuid
,
937 &SimpleNetworkDevice
->Nii
,
938 &gEfiDevicePathProtocolGuid
,
939 SimpleNetworkDevice
->DevicePath
,
942 if (EFI_ERROR (Status
)) {
945 &gEfiPciIoProtocolGuid
,
947 This
->DriverBindingHandle
,
948 ChildHandleBuffer
[Index
],
949 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
953 Undi16SimpleNetworkShutdown (&SimpleNetworkDevice
->SimpleNetwork
);
957 Undi16SimpleNetworkCleanupUndi (SimpleNetworkDevice
);
961 Undi16SimpleNetworkStopUndi (SimpleNetworkDevice
);
965 if (SimpleNetworkDevice
->UndiLoaded
) {
966 Undi16SimpleNetworkUnloadUndi (SimpleNetworkDevice
);
969 if (SimpleNetworkDevice
->SimpleNetwork
.WaitForPacket
!= NULL
) {
970 gBS
->CloseEvent (SimpleNetworkDevice
->SimpleNetwork
.WaitForPacket
);
973 if (SimpleNetworkDevice
->LegacyBootEvent
!= NULL
) {
974 gBS
->CloseEvent (SimpleNetworkDevice
->LegacyBootEvent
);
977 if (SimpleNetworkDevice
->EfiBootEvent
!= NULL
) {
978 gBS
->CloseEvent (SimpleNetworkDevice
->EfiBootEvent
);
981 if (SimpleNetworkDevice
->Xmit
!= NULL
) {
983 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->Xmit
,
984 sizeof (PXENV_UNDI_TBD_T
) / EFI_PAGE_SIZE
+ 1
988 if (SimpleNetworkDevice
->TxRealModeMediaHeader
!= NULL
) {
989 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->TxRealModeMediaHeader
, 1);
992 if (SimpleNetworkDevice
->TxRealModeDataBuffer
!= NULL
) {
993 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->TxRealModeDataBuffer
, 1);
996 if (SimpleNetworkDevice
->TxDestAddr
!= NULL
) {
997 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->TxDestAddr
, 1);
1000 gBS
->FreePool (SimpleNetworkDevice
);
1005 if (EFI_ERROR (Status
)) {
1006 AllChildrenStopped
= FALSE
;
1010 if (!AllChildrenStopped
) {
1011 return EFI_DEVICE_ERROR
;
1018 // FIFO Support Functions
1021 Judge whether transmit FIFO is full.
1023 @param Fifo Point to trasmit FIFO structure.
1025 @return BOOLEAN whether transmit FIFO is full.
1028 SimpleNetworkTransmitFifoFull (
1029 EFI_SIMPLE_NETWORK_DEV_FIFO
*Fifo
1032 if (((Fifo
->Last
+ 1) % EFI_SIMPLE_NETWORK_MAX_TX_FIFO_SIZE
) == Fifo
->First
) {
1040 Judge whether transmit FIFO is empty.
1042 @param Fifo Point to trasmit FIFO structure.
1044 @return BOOLEAN whether transmit FIFO is empty.
1047 SimpleNetworkTransmitFifoEmpty (
1048 EFI_SIMPLE_NETWORK_DEV_FIFO
*Fifo
1051 if (Fifo
->Last
== Fifo
->First
) {
1060 Add data into transmit buffer.
1062 @param Fifo Point to trasmit FIFO structure.
1063 @param Data The data point want to be added.
1065 @retval EFI_OUT_OF_RESOURCES FIFO is full
1066 @retval EFI_SUCCESS Success operation.
1069 SimpleNetworkTransmitFifoAdd (
1070 EFI_SIMPLE_NETWORK_DEV_FIFO
*Fifo
,
1074 if (SimpleNetworkTransmitFifoFull (Fifo
)) {
1075 return EFI_OUT_OF_RESOURCES
;
1078 Fifo
->Data
[Fifo
->Last
] = Data
;
1079 Fifo
->Last
= (Fifo
->Last
+ 1) % EFI_SIMPLE_NETWORK_MAX_TX_FIFO_SIZE
;
1084 Get a data and remove it from network transmit FIFO.
1086 @param Fifo Point to trasmit FIFO structure.
1087 @param Data On return, point to the data point want to be got and removed.
1089 @retval EFI_OUT_OF_RESOURCES network transmit buffer is empty.
1090 @retval EFI_SUCCESS Success operation.
1093 SimpleNetworkTransmitFifoRemove (
1094 EFI_SIMPLE_NETWORK_DEV_FIFO
*Fifo
,
1098 if (SimpleNetworkTransmitFifoEmpty (Fifo
)) {
1099 return EFI_OUT_OF_RESOURCES
;
1102 *Data
= Fifo
->Data
[Fifo
->First
];
1103 Fifo
->First
= (Fifo
->First
+ 1) % EFI_SIMPLE_NETWORK_MAX_TX_FIFO_SIZE
;
1108 Get recive filter setting according to EFI mask value.
1110 @param ReceiveFilterSetting filter setting EFI mask value.
1112 @return UINT16 Undi filter setting value.
1115 Undi16GetPacketFilterSetting (
1116 UINTN ReceiveFilterSetting
1122 if ((ReceiveFilterSetting
& EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
) != 0) {
1123 PktFilter
|= FLTR_DIRECTED
;
1126 if ((ReceiveFilterSetting
& EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
) != 0) {
1127 PktFilter
|= FLTR_DIRECTED
;
1130 if ((ReceiveFilterSetting
& EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
) != 0) {
1131 PktFilter
|= FLTR_BRDCST
;
1134 if ((ReceiveFilterSetting
& EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS
) != 0) {
1135 PktFilter
|= FLTR_PRMSCS
;
1138 if ((ReceiveFilterSetting
& EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
) != 0) {
1139 PktFilter
|= FLTR_PRMSCS
;
1141 // @bug : Do not know if this is right????
1145 // @bug : What is FLTR_SRC_RTG?
1151 Get filter setting from multi cast buffer .
1153 @param Mode Point to mode structure.
1154 @param McastBuffer The multi cast buffer
1155 @param HwAddressSize Size of filter value.
1159 Undi16GetMCastFilters (
1160 IN EFI_SIMPLE_NETWORK_MODE
*Mode
,
1161 IN OUT PXENV_UNDI_MCAST_ADDR_T
*McastBuffer
,
1162 IN UINTN HwAddressSize
1168 // @bug : What if Mode->MCastFilterCount > MAXNUM_MCADDR?
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
);
1175 ZeroMem (&McastBuffer
->MCastAddr
[Index
], HwAddressSize
);
1180 // Load 16 bit UNDI Option ROM into memory
1183 Loads the undi driver.
1185 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1187 @retval EFI_SUCCESS - Successfully loads undi driver.
1188 @retval EFI_NOT_FOUND - Doesn't find undi driver or undi driver load failure.
1191 Undi16SimpleNetworkLoadUndi (
1192 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
1196 EFI_PCI_IO_PROTOCOL
*PciIo
;
1198 PCI_EXPANSION_ROM_HEADER
*PciExpansionRomHeader
;
1199 PCI_DATA_STRUCTURE
*PciDataStructure
;
1202 if (!mCachedInt1A
) {
1203 Status
= CacheVectorAddress (0x1A);
1204 if (!EFI_ERROR (Status
)) {
1205 mCachedInt1A
= TRUE
;
1209 PciIo
= SimpleNetworkDevice
->PciIo
;
1213 EfiPciIoWidthUint32
,
1215 sizeof (Pci
) / sizeof (UINT32
),
1219 for (RomAddress
= 0xc0000; RomAddress
< 0xfffff; RomAddress
+= 0x800) {
1221 PciExpansionRomHeader
= (PCI_EXPANSION_ROM_HEADER
*) RomAddress
;
1223 if (PciExpansionRomHeader
->Signature
!= PCI_EXPANSION_ROM_HEADER_SIGNATURE
) {
1227 DEBUG ((DEBUG_INIT
, "Option ROM found at %X\n", RomAddress
));
1230 // If the pointer to the PCI Data Structure is invalid, no further images can be located.
1231 // The PCI Data Structure must be DWORD aligned.
1233 if (PciExpansionRomHeader
->PcirOffset
== 0 ||
1234 (PciExpansionRomHeader
->PcirOffset
& 3) != 0 ||
1235 RomAddress
+ PciExpansionRomHeader
->PcirOffset
+ sizeof (PCI_DATA_STRUCTURE
) > 0x100000) {
1239 PciDataStructure
= (PCI_DATA_STRUCTURE
*) (RomAddress
+ PciExpansionRomHeader
->PcirOffset
);
1241 if (PciDataStructure
->Signature
!= PCI_DATA_STRUCTURE_SIGNATURE
) {
1245 DEBUG ((DEBUG_INIT
, "PCI Data Structure found at %X\n", PciDataStructure
));
1247 if (PciDataStructure
->VendorId
!= Pci
.Hdr
.VendorId
|| PciDataStructure
->DeviceId
!= Pci
.Hdr
.DeviceId
) {
1253 "PCI device with matchinng VendorId and DeviceId (%d,%d)\n",
1254 (UINTN
) PciDataStructure
->VendorId
,
1255 (UINTN
) PciDataStructure
->DeviceId
)
1258 Status
= LaunchBaseCode (SimpleNetworkDevice
, RomAddress
);
1260 if (!EFI_ERROR (Status
)) {
1265 return EFI_NOT_FOUND
;
1269 Unload 16 bit UNDI Option ROM from memory
1271 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1276 Undi16SimpleNetworkUnloadUndi (
1277 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
1280 if (SimpleNetworkDevice
->UndiLoaderTable
!= NULL
) {
1281 ZeroMem (SimpleNetworkDevice
->UndiLoaderTable
, SimpleNetworkDevice
->UndiLoaderTablePages
<< EFI_PAGE_SHIFT
);
1283 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->UndiLoaderTable
,
1284 SimpleNetworkDevice
->UndiLoaderTablePages
1288 if (SimpleNetworkDevice
->DestinationDataSegment
!= NULL
) {
1290 SimpleNetworkDevice
->DestinationDataSegment
,
1291 SimpleNetworkDevice
->DestinationDataSegmentPages
<< EFI_PAGE_SHIFT
1294 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->DestinationDataSegment
,
1295 SimpleNetworkDevice
->DestinationDataSegmentPages
1299 if (SimpleNetworkDevice
->DestinationStackSegment
!= NULL
) {
1301 SimpleNetworkDevice
->DestinationStackSegment
,
1302 SimpleNetworkDevice
->DestinationStackSegmentPages
<< EFI_PAGE_SHIFT
1305 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->DestinationStackSegment
,
1306 SimpleNetworkDevice
->DestinationStackSegmentPages
1310 if (SimpleNetworkDevice
->DestinationCodeSegment
!= NULL
) {
1312 SimpleNetworkDevice
->DestinationCodeSegment
,
1313 SimpleNetworkDevice
->DestinationCodeSegmentPages
<< EFI_PAGE_SHIFT
1316 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->DestinationCodeSegment
,
1317 SimpleNetworkDevice
->DestinationCodeSegmentPages
1325 Start the UNDI interface.
1327 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1328 @param Ax PCI address of Undi device.
1330 @retval EFI_DEVICE_ERROR Fail to start 16 bit UNDI ROM.
1331 @retval Others Status of start 16 bit UNDI ROM.
1334 Undi16SimpleNetworkStartUndi (
1335 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
,
1340 PXENV_START_UNDI_T Start
;
1343 // Call 16 bit UNDI ROM to start the network interface
1346 // @bug : What is this state supposed to be???
1348 Start
.Status
= INIT_PXE_STATUS
;
1355 Status
= PxeStartUndi (SimpleNetworkDevice
, &Start
);
1356 if (EFI_ERROR (Status
)) {
1360 // Check the status code from the 16 bit UNDI ROM
1362 if (Start
.Status
!= PXENV_STATUS_SUCCESS
) {
1363 return EFI_DEVICE_ERROR
;
1371 Stop the UNDI interface
1373 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1375 @retval EFI_DEVICE_ERROR Fail to stop 16 bit UNDI ROM.
1376 @retval Others Status of stop 16 bit UNDI ROM.
1379 Undi16SimpleNetworkStopUndi (
1380 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
1384 PXENV_STOP_UNDI_T Stop
;
1387 // Call 16 bit UNDI ROM to start the network interface
1389 Stop
.Status
= INIT_PXE_STATUS
;
1391 Status
= PxeUndiStop (SimpleNetworkDevice
, &Stop
);
1392 if (EFI_ERROR (Status
)) {
1396 // Check the status code from the 16 bit UNDI ROM
1398 if (Stop
.Status
!= PXENV_STATUS_SUCCESS
) {
1399 return EFI_DEVICE_ERROR
;
1406 Cleanup Unid network interface
1408 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1410 @retval EFI_DEVICE_ERROR Fail to cleanup 16 bit UNDI ROM.
1411 @retval Others Status of cleanup 16 bit UNDI ROM.
1414 Undi16SimpleNetworkCleanupUndi (
1415 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
1419 PXENV_UNDI_CLEANUP_T Cleanup
;
1422 // Call 16 bit UNDI ROM to cleanup the network interface
1424 Cleanup
.Status
= INIT_PXE_STATUS
;
1426 Status
= PxeUndiCleanup (SimpleNetworkDevice
, &Cleanup
);
1427 if (EFI_ERROR (Status
)) {
1431 // Check the status code from the 16 bit UNDI ROM
1433 if (Cleanup
.Status
!= PXENV_STATUS_SUCCESS
) {
1434 return EFI_DEVICE_ERROR
;
1441 Get runtime information for Undi network interface
1443 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1445 @retval EFI_SUCCESS Sucess operation.
1446 @retval Others Fail to get runtime information for Undi network interface.
1449 Undi16SimpleNetworkGetInformation (
1450 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1454 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1458 return EFI_INVALID_PARAMETER
;
1461 Status
= EFI_SUCCESS
;
1462 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1464 if (SimpleNetworkDevice
== NULL
) {
1465 return EFI_DEVICE_ERROR
;
1468 // Verify that the current state of the adapter is valid for this call.
1470 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
1471 case EfiSimpleNetworkStarted
:
1472 case EfiSimpleNetworkInitialized
:
1475 case EfiSimpleNetworkStopped
:
1476 return EFI_NOT_STARTED
;
1479 return EFI_DEVICE_ERROR
;
1482 // Call 16 bit UNDI ROM to start the network interface
1484 ZeroMem (&SimpleNetworkDevice
->GetInformation
, sizeof (PXENV_UNDI_GET_INFORMATION_T
));
1486 SimpleNetworkDevice
->GetInformation
.Status
= INIT_PXE_STATUS
;
1488 Status
= PxeUndiGetInformation (SimpleNetworkDevice
, &SimpleNetworkDevice
->GetInformation
);
1489 if (EFI_ERROR (Status
)) {
1493 DEBUG ((DEBUG_NET
, " GetInformation.Status = %d\n", SimpleNetworkDevice
->GetInformation
.Status
));
1494 DEBUG ((DEBUG_NET
, " GetInformation.BaseIo = %d\n", SimpleNetworkDevice
->GetInformation
.BaseIo
));
1495 DEBUG ((DEBUG_NET
, " GetInformation.IntNumber = %d\n", SimpleNetworkDevice
->GetInformation
.IntNumber
));
1496 DEBUG ((DEBUG_NET
, " GetInformation.MaxTranUnit = %d\n", SimpleNetworkDevice
->GetInformation
.MaxTranUnit
));
1497 DEBUG ((DEBUG_NET
, " GetInformation.HwType = %d\n", SimpleNetworkDevice
->GetInformation
.HwType
));
1498 DEBUG ((DEBUG_NET
, " GetInformation.HwAddrLen = %d\n", SimpleNetworkDevice
->GetInformation
.HwAddrLen
));
1499 DEBUG ((DEBUG_NET
, " GetInformation.ROMAddress = %d\n", SimpleNetworkDevice
->GetInformation
.ROMAddress
));
1500 DEBUG ((DEBUG_NET
, " GetInformation.RxBufCt = %d\n", SimpleNetworkDevice
->GetInformation
.RxBufCt
));
1501 DEBUG ((DEBUG_NET
, " GetInformation.TxBufCt = %d\n", SimpleNetworkDevice
->GetInformation
.TxBufCt
));
1503 DEBUG ((DEBUG_NET
, " GetInformation.CurNodeAddr ="));
1504 for (Index
= 0; Index
< 16; Index
++) {
1505 DEBUG ((DEBUG_NET
, "%02x ", SimpleNetworkDevice
->GetInformation
.CurrentNodeAddress
[Index
]));
1508 DEBUG ((DEBUG_NET
, "\n"));
1510 DEBUG ((DEBUG_NET
, " GetInformation.PermNodeAddr ="));
1511 for (Index
= 0; Index
< 16; Index
++) {
1512 DEBUG ((DEBUG_NET
, "%02x ", SimpleNetworkDevice
->GetInformation
.PermNodeAddress
[Index
]));
1515 DEBUG ((DEBUG_NET
, "\n"));
1518 // Check the status code from the 16 bit UNDI ROM
1520 if (SimpleNetworkDevice
->GetInformation
.Status
!= PXENV_STATUS_SUCCESS
) {
1521 return EFI_DEVICE_ERROR
;
1524 // The information has been retrieved. Fill in Mode data.
1526 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
= SimpleNetworkDevice
->GetInformation
.HwAddrLen
;
1528 SimpleNetworkDevice
->SimpleNetworkMode
.MaxPacketSize
= SimpleNetworkDevice
->GetInformation
.MaxTranUnit
;
1530 SimpleNetworkDevice
->SimpleNetworkMode
.IfType
= (UINT8
) SimpleNetworkDevice
->GetInformation
.HwType
;
1533 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
1534 sizeof SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
1538 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
1539 &SimpleNetworkDevice
->GetInformation
.CurrentNodeAddress
,
1540 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
1544 &SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
,
1545 sizeof SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
1549 &SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
,
1550 &SimpleNetworkDevice
->GetInformation
.PermNodeAddress
,
1551 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
1555 // hard code broadcast address - not avail in PXE2.1
1558 &SimpleNetworkDevice
->SimpleNetworkMode
.BroadcastAddress
,
1559 sizeof SimpleNetworkDevice
->SimpleNetworkMode
.BroadcastAddress
1563 &SimpleNetworkDevice
->SimpleNetworkMode
.BroadcastAddress
,
1564 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
,
1574 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1576 @retval EFI_SUCCESS Sucess operation.
1577 @retval Others Fail to get NIC type.
1580 Undi16SimpleNetworkGetNicType (
1581 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1585 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1588 return EFI_INVALID_PARAMETER
;
1591 Status
= EFI_SUCCESS
;
1592 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1594 if (SimpleNetworkDevice
== NULL
) {
1595 return EFI_DEVICE_ERROR
;
1598 ZeroMem (&SimpleNetworkDevice
->GetNicType
, sizeof (PXENV_UNDI_GET_NIC_TYPE_T
));
1600 SimpleNetworkDevice
->GetNicType
.Status
= INIT_PXE_STATUS
;
1602 Status
= PxeUndiGetNicType (SimpleNetworkDevice
, &SimpleNetworkDevice
->GetNicType
);
1604 if (EFI_ERROR (Status
)) {
1608 DEBUG ((DEBUG_NET
, " GetNicType.Status = %d\n", SimpleNetworkDevice
->GetNicType
.Status
));
1609 DEBUG ((DEBUG_NET
, " GetNicType.NicType = %d\n", SimpleNetworkDevice
->GetNicType
.NicType
));
1611 // Check the status code from the 16 bit UNDI ROM
1613 if (SimpleNetworkDevice
->GetNicType
.Status
!= PXENV_STATUS_SUCCESS
) {
1614 return EFI_DEVICE_ERROR
;
1617 // The information has been retrieved. Fill in Mode data.
1623 Get NDIS information
1625 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1627 @retval EFI_SUCCESS Sucess operation.
1628 @retval Others Fail to get NDIS information.
1631 Undi16SimpleNetworkGetNdisInfo (
1632 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1636 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1639 return EFI_INVALID_PARAMETER
;
1642 Status
= EFI_SUCCESS
;
1643 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1645 if (SimpleNetworkDevice
== NULL
) {
1646 return EFI_DEVICE_ERROR
;
1649 ZeroMem (&SimpleNetworkDevice
->GetNdisInfo
, sizeof (PXENV_UNDI_GET_NDIS_INFO_T
));
1651 SimpleNetworkDevice
->GetNdisInfo
.Status
= INIT_PXE_STATUS
;
1653 Status
= PxeUndiGetNdisInfo (SimpleNetworkDevice
, &SimpleNetworkDevice
->GetNdisInfo
);
1655 if (EFI_ERROR (Status
)) {
1659 DEBUG ((DEBUG_NET
, " GetNdisInfo.Status = %d\n", SimpleNetworkDevice
->GetNdisInfo
.Status
));
1660 DEBUG ((DEBUG_NET
, " GetNdisInfo.IfaceType = %a\n", SimpleNetworkDevice
->GetNdisInfo
.IfaceType
));
1661 DEBUG ((DEBUG_NET
, " GetNdisInfo.LinkSpeed = %d\n", SimpleNetworkDevice
->GetNdisInfo
.LinkSpeed
));
1662 DEBUG ((DEBUG_NET
, " GetNdisInfo.ServiceFlags = %08x\n", SimpleNetworkDevice
->GetNdisInfo
.ServiceFlags
));
1665 // Check the status code from the 16 bit UNDI ROM
1667 if (SimpleNetworkDevice
->GetNdisInfo
.Status
!= PXENV_STATUS_SUCCESS
) {
1668 return EFI_DEVICE_ERROR
;
1671 // The information has been retrieved. Fill in Mode data.
1677 Call Undi ROM 16bit ISR() to check interrupt cause.
1679 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1680 @param FrameLength The length of frame buffer.
1681 @param FrameHeaderLength The length of frame buffer's header if has.
1682 @param Frame The frame buffer to process network interrupt.
1683 @param ProtType The type network transmit protocol
1684 @param PktType The type of package.
1686 @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM's ISR, or status is invalid.
1687 @retval EFI_SUCCESS Success operation.
1690 Undi16SimpleNetworkIsr (
1691 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
1692 IN UINTN
*FrameLength
,
1693 IN UINTN
*FrameHeaderLength
, OPTIONAL
1694 IN UINT8
*Frame
, OPTIONAL
1695 IN UINT8
*ProtType
, OPTIONAL
1696 IN UINT8
*PktType OPTIONAL
1700 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1701 BOOLEAN FrameReceived
;
1704 return EFI_INVALID_PARAMETER
;
1707 Status
= EFI_SUCCESS
;
1708 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1710 if (SimpleNetworkDevice
== NULL
) {
1711 return EFI_DEVICE_ERROR
;
1714 FrameReceived
= FALSE
;
1717 // Verify that the current state of the adapter is valid for this call.
1719 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
1720 case EfiSimpleNetworkInitialized
:
1723 case EfiSimpleNetworkStopped
:
1724 return EFI_NOT_STARTED
;
1726 case EfiSimpleNetworkStarted
:
1728 return EFI_DEVICE_ERROR
;
1731 DEBUG ((DEBUG_NET
, "Isr() IsrValid = %d\n", SimpleNetworkDevice
->IsrValid
));
1733 if (!SimpleNetworkDevice
->IsrValid
) {
1735 // Call 16 bit UNDI ROM to open the network interface
1737 ZeroMem (&SimpleNetworkDevice
->Isr
, sizeof (PXENV_UNDI_ISR_T
));
1738 SimpleNetworkDevice
->Isr
.Status
= INIT_PXE_STATUS
;
1739 SimpleNetworkDevice
->Isr
.FuncFlag
= PXENV_UNDI_ISR_IN_START
;
1741 DEBUG ((DEBUG_NET
, "Isr() START\n"));
1743 Status
= PxeUndiIsr (SimpleNetworkDevice
, &SimpleNetworkDevice
->Isr
);
1744 if (EFI_ERROR (Status
)) {
1748 // Check the status code from the 16 bit UNDI ROM
1750 if (SimpleNetworkDevice
->Isr
.Status
!= PXENV_STATUS_SUCCESS
) {
1751 return EFI_DEVICE_ERROR
;
1754 // There have been no events on this UNDI interface, so return EFI_NOT_READY
1756 if (SimpleNetworkDevice
->Isr
.FuncFlag
== PXENV_UNDI_ISR_OUT_NOT_OURS
) {
1760 // There is data to process, so call until all events processed.
1762 ZeroMem (&SimpleNetworkDevice
->Isr
, sizeof (PXENV_UNDI_ISR_T
));
1763 SimpleNetworkDevice
->Isr
.Status
= INIT_PXE_STATUS
;
1764 SimpleNetworkDevice
->Isr
.FuncFlag
= PXENV_UNDI_ISR_IN_PROCESS
;
1766 DEBUG ((DEBUG_NET
, "Isr() PROCESS\n"));
1768 Status
= PxeUndiIsr (SimpleNetworkDevice
, &SimpleNetworkDevice
->Isr
);
1769 if (EFI_ERROR (Status
)) {
1773 SimpleNetworkDevice
->IsrValid
= TRUE
;
1776 // Call UNDI GET_NEXT until DONE
1778 while (SimpleNetworkDevice
->Isr
.FuncFlag
!= PXENV_UNDI_ISR_OUT_DONE
) {
1780 // Check the status code from the 16 bit UNDI ROM
1782 if (SimpleNetworkDevice
->Isr
.Status
!= PXENV_STATUS_SUCCESS
) {
1783 return EFI_DEVICE_ERROR
;
1786 // UNDI is busy. Caller will have to call again.
1787 // This should never happen with a polled mode driver.
1789 if (SimpleNetworkDevice
->Isr
.FuncFlag
== PXENV_UNDI_ISR_OUT_BUSY
) {
1790 DEBUG ((DEBUG_NET
, " BUSY\n"));
1794 // Check for invalud UNDI FuncFlag
1796 if (SimpleNetworkDevice
->Isr
.FuncFlag
!= PXENV_UNDI_ISR_OUT_RECEIVE
&&
1797 SimpleNetworkDevice
->Isr
.FuncFlag
!= PXENV_UNDI_ISR_OUT_TRANSMIT
1799 DEBUG ((DEBUG_NET
, " Invalid SimpleNetworkDevice->Isr.FuncFlag value %d\n", SimpleNetworkDevice
->Isr
.FuncFlag
));
1800 return EFI_DEVICE_ERROR
;
1803 // Check for Transmit Event
1805 if (SimpleNetworkDevice
->Isr
.FuncFlag
== PXENV_UNDI_ISR_OUT_TRANSMIT
) {
1806 DEBUG ((DEBUG_NET
, " TRANSMIT\n"));
1807 SimpleNetworkDevice
->InterruptStatus
|= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
1810 // Check for Receive Event
1812 else if (SimpleNetworkDevice
->Isr
.FuncFlag
== PXENV_UNDI_ISR_OUT_RECEIVE
) {
1814 // note - this code will hang on a receive interrupt in a GetStatus loop
1816 DEBUG ((DEBUG_NET
, " RECEIVE\n"));
1817 SimpleNetworkDevice
->InterruptStatus
|= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
;
1819 DEBUG ((DEBUG_NET
, "SimpleNetworkDevice->Isr.BufferLength = %d\n", SimpleNetworkDevice
->Isr
.BufferLength
));
1820 DEBUG ((DEBUG_NET
, "SimpleNetworkDevice->Isr.FrameLength = %d\n", SimpleNetworkDevice
->Isr
.FrameLength
));
1821 DEBUG ((DEBUG_NET
, "SimpleNetworkDevice->Isr.FrameHeaderLength = %d\n", SimpleNetworkDevice
->Isr
.FrameHeaderLength
));
1824 DEBUG_NET
, "SimpleNetworkDevice->Isr.Frame = %04x:%04x\n", SimpleNetworkDevice
->Isr
.FrameSegSel
,
1825 SimpleNetworkDevice
->Isr
.FrameOffset
1828 DEBUG ((DEBUG_NET
, "SimpleNetworkDevice->Isr.ProtType = 0x%02x\n", SimpleNetworkDevice
->Isr
.BufferLength
));
1829 DEBUG ((DEBUG_NET
, "SimpleNetworkDevice->Isr.PktType = 0x%02x\n", SimpleNetworkDevice
->Isr
.BufferLength
));
1831 if (FrameReceived
) {
1835 if ((Frame
== NULL
) || (SimpleNetworkDevice
->Isr
.FrameLength
> *FrameLength
)) {
1836 DEBUG ((DEBUG_NET
, "return EFI_BUFFER_TOO_SMALL *FrameLength = %08x\n", *FrameLength
));
1837 *FrameLength
= SimpleNetworkDevice
->Isr
.FrameLength
;
1838 return EFI_BUFFER_TOO_SMALL
;
1841 *FrameLength
= SimpleNetworkDevice
->Isr
.FrameLength
;
1842 if (FrameHeaderLength
!= NULL
) {
1843 *FrameHeaderLength
= SimpleNetworkDevice
->Isr
.FrameHeaderLength
;
1846 if (ProtType
!= NULL
) {
1847 *ProtType
= SimpleNetworkDevice
->Isr
.ProtType
;
1850 if (PktType
!= NULL
) {
1851 *PktType
= SimpleNetworkDevice
->Isr
.PktType
;
1856 (VOID
*)(UINTN
) ((SimpleNetworkDevice
->Isr
.FrameSegSel
<< 4) + SimpleNetworkDevice
->Isr
.FrameOffset
),
1857 SimpleNetworkDevice
->Isr
.BufferLength
1859 Frame
= Frame
+ SimpleNetworkDevice
->Isr
.BufferLength
;
1860 if (SimpleNetworkDevice
->Isr
.BufferLength
== SimpleNetworkDevice
->Isr
.FrameLength
) {
1861 FrameReceived
= TRUE
;
1865 // There is data to process, so call until all events processed.
1867 ZeroMem (&SimpleNetworkDevice
->Isr
, sizeof (PXENV_UNDI_ISR_T
));
1868 SimpleNetworkDevice
->Isr
.Status
= INIT_PXE_STATUS
;
1869 SimpleNetworkDevice
->Isr
.FuncFlag
= PXENV_UNDI_ISR_IN_GET_NEXT
;
1871 DEBUG ((DEBUG_NET
, "Isr() GET NEXT\n"));
1873 Status
= PxeUndiIsr (SimpleNetworkDevice
, &SimpleNetworkDevice
->Isr
);
1874 if (EFI_ERROR (Status
)) {
1878 // Check the status code from the 16 bit UNDI ROM
1880 // if (SimpleNetworkDevice->Isr.Status != PXENV_STATUS_SUCCESS) {
1881 // return EFI_DEVICE_ERROR;
1886 SimpleNetworkDevice
->IsrValid
= FALSE
;
1890 // ///////////////////////////////////////////////////////////////////////////////////////
1891 // Simple Network Protocol Interface Functions using 16 bit UNDI Option ROMs
1892 /////////////////////////////////////////////////////////////////////////////////////////
1897 Call 16 bit UNDI ROM to start the network interface
1899 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1901 @retval EFI_DEVICE_ERROR Network interface has not be initialized.
1902 @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM call.
1903 @retval EFI_SUCESS Success operation.
1907 Undi16SimpleNetworkStart (
1908 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1912 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1913 PXENV_UNDI_STARTUP_T Startup
;
1916 return EFI_INVALID_PARAMETER
;
1919 Status
= EFI_SUCCESS
;
1920 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1922 if (SimpleNetworkDevice
== NULL
) {
1923 return EFI_DEVICE_ERROR
;
1926 // Verify that the current state of the adapter is valid for this call.
1928 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
1929 case EfiSimpleNetworkStopped
:
1932 case EfiSimpleNetworkStarted
:
1933 case EfiSimpleNetworkInitialized
:
1934 return EFI_ALREADY_STARTED
;
1937 return EFI_DEVICE_ERROR
;
1940 // Call 16 bit UNDI ROM to start the network interface
1942 Startup
.Status
= INIT_PXE_STATUS
;
1944 Status
= PxeUndiStartup (SimpleNetworkDevice
, &Startup
);
1945 if (EFI_ERROR (Status
)) {
1949 // Check the status code from the 16 bit UNDI ROM
1951 if (Startup
.Status
!= PXENV_STATUS_SUCCESS
) {
1952 return EFI_DEVICE_ERROR
;
1955 // The UNDI interface has been started, so update the State.
1957 SimpleNetworkDevice
->SimpleNetworkMode
.State
= EfiSimpleNetworkStarted
;
1962 SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
= 0;
1963 SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilterCount
= 0;
1971 Call 16 bit UNDI ROM to stop the network interface
1973 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1975 @retval EFI_DEVICE_ERROR Network interface has not be initialized.
1976 @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM call.
1977 @retval EFI_SUCESS Success operation.
1981 Undi16SimpleNetworkStop (
1982 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1986 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1989 return EFI_INVALID_PARAMETER
;
1992 Status
= EFI_SUCCESS
;
1993 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1995 if (SimpleNetworkDevice
== NULL
) {
1996 return EFI_DEVICE_ERROR
;
1999 // Verify that the current state of the adapter is valid for this call.
2001 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2002 case EfiSimpleNetworkStarted
:
2005 case EfiSimpleNetworkStopped
:
2006 return EFI_NOT_STARTED
;
2008 case EfiSimpleNetworkInitialized
:
2010 return EFI_DEVICE_ERROR
;
2013 SimpleNetworkDevice
->SimpleNetworkMode
.State
= EfiSimpleNetworkStopped
;
2022 Initialize network interface
2024 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
2025 @param ExtraRxBufferSize The size of extra request receive buffer.
2026 @param ExtraTxBufferSize The size of extra request transmit buffer.
2028 @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM call.
2029 @retval EFI_SUCESS Success operation.
2033 Undi16SimpleNetworkInitialize (
2034 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
2035 IN UINTN ExtraRxBufferSize OPTIONAL
,
2036 IN UINTN ExtraTxBufferSize OPTIONAL
2040 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2041 PXENV_UNDI_INITIALIZE_T Initialize
;
2042 PXENV_UNDI_OPEN_T Open
;
2045 return EFI_INVALID_PARAMETER
;
2048 Status
= EFI_SUCCESS
;
2049 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2051 if (SimpleNetworkDevice
== NULL
) {
2052 return EFI_DEVICE_ERROR
;
2055 // Verify that the current state of the adapter is valid for this call.
2057 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2058 case EfiSimpleNetworkStopped
:
2059 return EFI_NOT_STARTED
;
2061 case EfiSimpleNetworkStarted
:
2064 case EfiSimpleNetworkInitialized
:
2066 return EFI_DEVICE_ERROR
;
2069 // Call 16 bit UNDI ROM to start the network interface
2071 Initialize
.Status
= INIT_PXE_STATUS
;
2072 Initialize
.ProtocolIni
= 0;
2074 Status
= PxeUndiInitialize (SimpleNetworkDevice
, &Initialize
);
2076 if (EFI_ERROR (Status
)) {
2077 DEBUG ((DEBUG_ERROR
, "ERROR : PxeUndiInitialize() - Status = %r\n", Status
));
2078 DEBUG ((DEBUG_ERROR
, "Initialize.Status == %xh\n", Initialize
.Status
));
2080 if (Initialize
.Status
== PXENV_STATUS_UNDI_MEDIATEST_FAILED
) {
2081 Status
= EFI_NO_MEDIA
;
2087 // Check the status code from the 16 bit UNDI ROM
2089 if (Initialize
.Status
!= PXENV_STATUS_SUCCESS
) {
2090 DEBUG ((DEBUG_ERROR
, "ERROR : PxeUndiInitialize() - Initialize.Status = %04x\n", Initialize
.Status
));
2091 return EFI_DEVICE_ERROR
;
2094 // Call 16 bit UNDI ROM to open the network interface
2096 Open
.Status
= INIT_PXE_STATUS
;
2098 Open
.PktFilter
= Undi16GetPacketFilterSetting (SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
);
2099 Undi16GetMCastFilters (
2100 &SimpleNetworkDevice
->SimpleNetworkMode
,
2102 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2105 Status
= PxeUndiOpen (SimpleNetworkDevice
, &Open
);
2107 if (EFI_ERROR (Status
)) {
2108 DEBUG ((DEBUG_ERROR
, "ERROR : PxeUndiOpen() - Status = %r\n", Status
));
2112 // Check the status code from the 16 bit UNDI ROM
2114 if (Open
.Status
!= PXENV_STATUS_SUCCESS
) {
2115 DEBUG ((DEBUG_ERROR
, "ERROR : PxeUndiOpen() - Open.Status = %04x\n", Open
.Status
));
2116 return EFI_DEVICE_ERROR
;
2119 // The UNDI interface has been initialized, so update the State.
2121 SimpleNetworkDevice
->SimpleNetworkMode
.State
= EfiSimpleNetworkInitialized
;
2124 // If initialize succeeds, then assume that media is present.
2126 SimpleNetworkDevice
->SimpleNetworkMode
.MediaPresent
= TRUE
;
2129 // Reset the recycled transmit buffer FIFO
2131 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
2132 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
2133 SimpleNetworkDevice
->IsrValid
= FALSE
;
2141 Reset network interface.
2143 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
2144 @param ExtendedVerification Need extended verfication.
2146 @retval EFI_INVALID_PARAMETER Invalid This paramter.
2147 @retval EFI_DEVICE_ERROR Network device has not been initialized.
2148 @retval EFI_NOT_STARTED Network device has been stopped.
2149 @retval EFI_DEVICE_ERROR Invalid status for network device
2150 @retval EFI_SUCCESS Success operation.
2154 Undi16SimpleNetworkReset (
2155 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
2156 IN BOOLEAN ExtendedVerification
2160 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2161 PXENV_UNDI_RESET_T Reset
;
2165 return EFI_INVALID_PARAMETER
;
2168 Status
= EFI_SUCCESS
;
2169 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2171 if (SimpleNetworkDevice
== NULL
) {
2172 return EFI_DEVICE_ERROR
;
2175 // Verify that the current state of the adapter is valid for this call.
2177 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2178 case EfiSimpleNetworkStopped
:
2179 return EFI_NOT_STARTED
;
2181 case EfiSimpleNetworkInitialized
:
2184 case EfiSimpleNetworkStarted
:
2186 return EFI_DEVICE_ERROR
;
2189 Reset
.Status
= INIT_PXE_STATUS
;
2191 Rx_filter
= Undi16GetPacketFilterSetting (SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
);
2193 Undi16GetMCastFilters (
2194 &SimpleNetworkDevice
->SimpleNetworkMode
,
2196 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2199 Status
= PxeUndiResetNic (SimpleNetworkDevice
, &Reset
, Rx_filter
);
2201 if (EFI_ERROR (Status
)) {
2205 // Check the status code from the 16 bit UNDI ROM
2207 if (Reset
.Status
!= PXENV_STATUS_SUCCESS
) {
2208 return EFI_DEVICE_ERROR
;
2211 // Reset the recycled transmit buffer FIFO
2213 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
2214 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
2215 SimpleNetworkDevice
->IsrValid
= FALSE
;
2223 Shutdown network interface.
2225 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
2227 @retval EFI_INVALID_PARAMETER Invalid This paramter.
2228 @retval EFI_DEVICE_ERROR Network device has not been initialized.
2229 @retval EFI_NOT_STARTED Network device has been stopped.
2230 @retval EFI_DEVICE_ERROR Invalid status for network device
2231 @retval EFI_SUCCESS Success operation.
2235 Undi16SimpleNetworkShutdown (
2236 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
2240 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2241 PXENV_UNDI_CLOSE_T Close
;
2242 PXENV_UNDI_SHUTDOWN_T Shutdown
;
2245 return EFI_INVALID_PARAMETER
;
2248 Status
= EFI_SUCCESS
;
2249 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2251 if (SimpleNetworkDevice
== NULL
) {
2252 return EFI_DEVICE_ERROR
;
2255 // Verify that the current state of the adapter is valid for this call.
2257 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2258 case EfiSimpleNetworkStopped
:
2259 return EFI_NOT_STARTED
;
2261 case EfiSimpleNetworkInitialized
:
2264 case EfiSimpleNetworkStarted
:
2266 return EFI_DEVICE_ERROR
;
2269 SimpleNetworkDevice
->IsrValid
= FALSE
;
2272 // Call 16 bit UNDI ROM to start the network interface
2274 Close
.Status
= INIT_PXE_STATUS
;
2276 Status
= PxeUndiClose (SimpleNetworkDevice
, &Close
);
2278 if (EFI_ERROR (Status
)) {
2282 // Check the status code from the 16 bit UNDI ROM
2284 if (Close
.Status
!= PXENV_STATUS_SUCCESS
) {
2285 return EFI_DEVICE_ERROR
;
2288 // Call 16 bit UNDI ROM to open the network interface
2290 Shutdown
.Status
= INIT_PXE_STATUS
;
2292 Status
= PxeUndiShutdown (SimpleNetworkDevice
, &Shutdown
);
2294 if (EFI_ERROR (Status
)) {
2298 // Check the status code from the 16 bit UNDI ROM
2300 if (Shutdown
.Status
!= PXENV_STATUS_SUCCESS
) {
2301 return EFI_DEVICE_ERROR
;
2304 // The UNDI interface has been initialized, so update the State.
2306 SimpleNetworkDevice
->SimpleNetworkMode
.State
= EfiSimpleNetworkStarted
;
2309 // If shutdown succeeds, then assume that media is not present.
2311 SimpleNetworkDevice
->SimpleNetworkMode
.MediaPresent
= FALSE
;
2314 // Reset the recycled transmit buffer FIFO
2316 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
2317 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
2320 // A short delay. Without this an initialize immediately following
2321 // a shutdown will cause some versions of UNDI-16 to stop operating.
2323 gBS
->Stall (250000);
2331 Reset network interface.
2333 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
2334 @param Enable Enable mask value
2335 @param Disable Disable mask value
2336 @param ResetMCastFilter Whether reset multi cast filter or not
2337 @param MCastFilterCnt Count of mutli cast filter for different MAC address
2338 @param MCastFilter Buffer for mustli cast filter for different MAC address.
2340 @retval EFI_INVALID_PARAMETER Invalid This paramter.
2341 @retval EFI_DEVICE_ERROR Network device has not been initialized.
2342 @retval EFI_NOT_STARTED Network device has been stopped.
2343 @retval EFI_DEVICE_ERROR Invalid status for network device
2344 @retval EFI_SUCCESS Success operation.
2348 Undi16SimpleNetworkReceiveFilters (
2349 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
2352 IN BOOLEAN ResetMCastFilter
,
2353 IN UINTN MCastFilterCnt OPTIONAL
,
2354 IN EFI_MAC_ADDRESS
* MCastFilter OPTIONAL
2360 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2361 PXENV_UNDI_CLOSE_T Close
;
2362 PXENV_UNDI_OPEN_T Open
;
2365 return EFI_INVALID_PARAMETER
;
2368 Status
= EFI_SUCCESS
;
2369 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2371 if (SimpleNetworkDevice
== NULL
) {
2372 return EFI_DEVICE_ERROR
;
2375 // Verify that the current state of the adapter is valid for this call.
2377 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2378 case EfiSimpleNetworkStopped
:
2379 return EFI_NOT_STARTED
;
2381 case EfiSimpleNetworkInitialized
:
2384 case EfiSimpleNetworkStarted
:
2386 return EFI_DEVICE_ERROR
;
2389 // First deal with possible filter setting changes
2391 if ((Enable
== 0) && (Disable
== 0) && !ResetMCastFilter
) {
2395 NewFilter
= (SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
| Enable
) &~Disable
;
2397 if ((NewFilter
& EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
) != 0) {
2398 if ((MCastFilterCnt
== 0) || (MCastFilter
== 0) || MCastFilterCnt
> SimpleNetworkDevice
->SimpleNetworkMode
.MaxMCastFilterCount
) {
2399 return EFI_INVALID_PARAMETER
;
2403 // Call 16 bit UNDI ROM to close the network interface
2405 Close
.Status
= INIT_PXE_STATUS
;
2407 Status
= PxeUndiClose (SimpleNetworkDevice
, &Close
);
2409 if (EFI_ERROR (Status
)) {
2413 // Check the status code from the 16 bit UNDI ROM
2415 if (Close
.Status
!= PXENV_STATUS_SUCCESS
) {
2416 return EFI_DEVICE_ERROR
;
2419 // Call 16 bit UNDI ROM to open the network interface
2422 // Reset the recycled transmit buffer FIFO
2424 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
2425 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
2428 // Call 16 bit UNDI ROM to open the network interface
2430 ZeroMem (&Open
, sizeof Open
);
2432 Open
.Status
= INIT_PXE_STATUS
;
2433 Open
.PktFilter
= Undi16GetPacketFilterSetting (NewFilter
);
2435 if ((NewFilter
& EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
) != 0) {
2437 // Copy the MAC addresses into the UNDI open parameter structure
2439 Open
.McastBuffer
.MCastAddrCount
= (UINT16
) MCastFilterCnt
;
2440 for (Index
= 0; Index
< MCastFilterCnt
; ++Index
) {
2442 Open
.McastBuffer
.MCastAddr
[Index
],
2443 &MCastFilter
[Index
],
2444 sizeof Open
.McastBuffer
.MCastAddr
[Index
]
2447 } else if (!ResetMCastFilter
) {
2448 for (Index
= 0; Index
< SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilterCount
; ++Index
) {
2450 Open
.McastBuffer
.MCastAddr
[Index
],
2451 &SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilter
[Index
],
2452 sizeof Open
.McastBuffer
.MCastAddr
[Index
]
2457 Status
= PxeUndiOpen (SimpleNetworkDevice
, &Open
);
2459 if (EFI_ERROR (Status
)) {
2463 // Check the status code from the 16 bit UNDI ROM
2465 if (Open
.Status
!= PXENV_STATUS_SUCCESS
) {
2466 return EFI_DEVICE_ERROR
;
2469 SimpleNetworkDevice
->IsrValid
= FALSE
;
2470 SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
= NewFilter
;
2472 if ((NewFilter
& EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
) != 0) {
2473 SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilterCount
= (UINT32
) MCastFilterCnt
;
2474 for (Index
= 0; Index
< MCastFilterCnt
; ++Index
) {
2476 &SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilter
[Index
],
2477 &MCastFilter
[Index
],
2478 sizeof (EFI_MAC_ADDRESS
)
2483 // Read back multicast addresses.
2491 Set new MAC address.
2493 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
2494 @param Reset Whether reset station MAC address to permenent address
2495 @param New A pointer to New address
2497 @retval EFI_INVALID_PARAMETER Invalid This paramter.
2498 @retval EFI_DEVICE_ERROR Network device has not been initialized.
2499 @retval EFI_NOT_STARTED Network device has been stopped.
2500 @retval EFI_DEVICE_ERROR Invalid status for network device
2501 @retval EFI_SUCCESS Success operation.
2505 Undi16SimpleNetworkStationAddress (
2506 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
2508 IN EFI_MAC_ADDRESS
* New OPTIONAL
2512 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2513 PXENV_UNDI_SET_STATION_ADDR_T SetStationAddr
;
2515 // EFI_DEVICE_PATH_PROTOCOL *OldDevicePath;
2517 PXENV_UNDI_CLOSE_T Close
;
2518 PXENV_UNDI_OPEN_T Open
;
2521 return EFI_INVALID_PARAMETER
;
2524 Status
= EFI_SUCCESS
;
2526 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2528 if (SimpleNetworkDevice
== NULL
) {
2529 return EFI_DEVICE_ERROR
;
2532 // Verify that the current state of the adapter is valid for this call.
2534 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2535 case EfiSimpleNetworkInitialized
:
2538 case EfiSimpleNetworkStopped
:
2539 return EFI_NOT_STARTED
;
2541 case EfiSimpleNetworkStarted
:
2543 return EFI_DEVICE_ERROR
;
2546 // Call 16 bit UNDI ROM to open the network interface
2548 SetStationAddr
.Status
= INIT_PXE_STATUS
;
2552 // If we are reseting the Station Address to the permanent address, and the
2553 // Station Address is not programmable, then just return EFI_SUCCESS.
2555 if (!SimpleNetworkDevice
->SimpleNetworkMode
.MacAddressChangeable
) {
2559 // If the address is already the permanent address, then just return success.
2562 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
2563 &SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
,
2564 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2569 // Copy the adapters permanent address to the new station address
2572 &SetStationAddr
.StationAddress
,
2573 &SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
,
2574 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2578 // If we are setting the Station Address, and the
2579 // Station Address is not programmable, return invalid parameter.
2581 if (!SimpleNetworkDevice
->SimpleNetworkMode
.MacAddressChangeable
) {
2582 return EFI_INVALID_PARAMETER
;
2585 // If the address is already the new address, then just return success.
2588 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
2590 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2595 // Copy New to the new station address
2598 &SetStationAddr
.StationAddress
,
2600 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2605 // Call 16 bit UNDI ROM to stop the network interface
2607 Close
.Status
= INIT_PXE_STATUS
;
2609 PxeUndiClose (SimpleNetworkDevice
, &Close
);
2612 // Call 16-bit UNDI ROM to set the station address
2614 SetStationAddr
.Status
= PXENV_STATUS_SUCCESS
;
2616 Status
= PxeUndiSetStationAddr (SimpleNetworkDevice
, &SetStationAddr
);
2619 // Call 16-bit UNDI ROM to start the network interface
2621 Open
.Status
= PXENV_STATUS_SUCCESS
;
2623 Open
.PktFilter
= Undi16GetPacketFilterSetting (SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
);
2624 Undi16GetMCastFilters (
2625 &SimpleNetworkDevice
->SimpleNetworkMode
,
2627 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2630 PxeUndiOpen (SimpleNetworkDevice
, &Open
);
2633 // Check status from station address change
2635 if (EFI_ERROR (Status
)) {
2639 // Check the status code from the 16 bit UNDI ROM
2641 if (SetStationAddr
.Status
!= PXENV_STATUS_SUCCESS
) {
2642 return EFI_DEVICE_ERROR
;
2646 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
2647 &SetStationAddr
.StationAddress
,
2648 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2651 #if 0 /* The device path is based on the permanent address not the current address. */
2653 // The station address was changed, so update the device path with the new MAC address.
2655 OldDevicePath
= SimpleNetworkDevice
->DevicePath
;
2656 SimpleNetworkDevice
->DevicePath
= DuplicateDevicePath (SimpleNetworkDevice
->BaseDevicePath
);
2657 SimpleNetworkAppendMacAddressDevicePath (
2658 &SimpleNetworkDevice
->DevicePath
,
2659 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
2662 Status
= LibReinstallProtocolInterfaces (
2663 SimpleNetworkDevice
->Handle
,
2664 &DevicePathProtocol
,
2666 SimpleNetworkDevice
->DevicePath
,
2670 if (EFI_ERROR (Status
)) {
2671 DEBUG ((DEBUG_ERROR
, "Failed to reinstall the DevicePath protocol for the Simple Network Device\n"));
2672 DEBUG ((DEBUG_ERROR
, " Status = %r\n", Status
));
2675 FreePool (OldDevicePath
);
2684 Resets or collects the statistics on a network interface.
2686 @param This Protocol instance pointer.
2687 @param Reset Set to TRUE to reset the statistics for the network interface.
2688 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On
2689 output the size, in bytes, of the resulting table of
2691 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
2692 contains the statistics.
2694 @retval EFI_SUCCESS The statistics were collected from the network interface.
2695 @retval EFI_NOT_STARTED The network interface has not been started.
2696 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer
2697 size needed to hold the statistics is returned in
2699 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
2700 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
2701 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
2706 Undi16SimpleNetworkStatistics (
2707 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
2709 IN OUT UINTN
*StatisticsSize OPTIONAL
,
2710 OUT EFI_NETWORK_STATISTICS
* StatisticsTable OPTIONAL
2714 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2715 PXENV_UNDI_CLEAR_STATISTICS_T ClearStatistics
;
2716 PXENV_UNDI_GET_STATISTICS_T GetStatistics
;
2719 return EFI_INVALID_PARAMETER
;
2722 Status
= EFI_SUCCESS
;
2723 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2725 if (SimpleNetworkDevice
== NULL
) {
2726 return EFI_DEVICE_ERROR
;
2729 // Verify that the current state of the adapter is valid for this call.
2731 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2732 case EfiSimpleNetworkInitialized
:
2735 case EfiSimpleNetworkStopped
:
2736 return EFI_NOT_STARTED
;
2738 case EfiSimpleNetworkStarted
:
2740 return EFI_DEVICE_ERROR
;
2743 if ((StatisticsSize
!= NULL
) && (*StatisticsSize
!= 0) && (StatisticsTable
== NULL
)) {
2744 return EFI_INVALID_PARAMETER
;
2748 // If Reset is TRUE, then clear all the statistics.
2752 DEBUG ((DEBUG_NET
, " RESET Statistics\n"));
2755 // Call 16 bit UNDI ROM to open the network interface
2757 ClearStatistics
.Status
= INIT_PXE_STATUS
;
2759 Status
= PxeUndiClearStatistics (SimpleNetworkDevice
, &ClearStatistics
);
2761 if (EFI_ERROR (Status
)) {
2765 // Check the status code from the 16 bit UNDI ROM
2767 if (ClearStatistics
.Status
!= PXENV_STATUS_SUCCESS
) {
2768 return EFI_DEVICE_ERROR
;
2771 DEBUG ((DEBUG_NET
, " RESET Statistics Complete"));
2774 if (StatisticsSize
!= NULL
) {
2775 EFI_NETWORK_STATISTICS LocalStatisticsTable
;
2777 DEBUG ((DEBUG_NET
, " GET Statistics\n"));
2780 // If the size if valid, then see if the table is valid
2782 if (StatisticsTable
== NULL
) {
2783 DEBUG ((DEBUG_NET
, " StatisticsTable is NULL\n"));
2784 return EFI_INVALID_PARAMETER
;
2787 // Call 16 bit UNDI ROM to open the network interface
2789 GetStatistics
.Status
= INIT_PXE_STATUS
;
2790 GetStatistics
.XmtGoodFrames
= 0;
2791 GetStatistics
.RcvGoodFrames
= 0;
2792 GetStatistics
.RcvCRCErrors
= 0;
2793 GetStatistics
.RcvResourceErrors
= 0;
2795 Status
= PxeUndiGetStatistics (SimpleNetworkDevice
, &GetStatistics
);
2797 if (EFI_ERROR (Status
)) {
2801 // Check the status code from the 16 bit UNDI ROM
2803 if (GetStatistics
.Status
!= PXENV_STATUS_SUCCESS
) {
2804 return EFI_DEVICE_ERROR
;
2807 // Fill in the Statistics Table with the collected values.
2809 SetMem (&LocalStatisticsTable
, sizeof LocalStatisticsTable
, 0xff);
2811 LocalStatisticsTable
.TxGoodFrames
= GetStatistics
.XmtGoodFrames
;
2812 LocalStatisticsTable
.RxGoodFrames
= GetStatistics
.RcvGoodFrames
;
2813 LocalStatisticsTable
.RxCrcErrorFrames
= GetStatistics
.RcvCRCErrors
;
2814 LocalStatisticsTable
.RxDroppedFrames
= GetStatistics
.RcvResourceErrors
;
2816 CopyMem (StatisticsTable
, &LocalStatisticsTable
, *StatisticsSize
);
2820 " Statistics Collected : Size=%d Buf=%08x\n",
2825 DEBUG ((DEBUG_NET
, " GET Statistics Complete"));
2827 if (*StatisticsSize
< sizeof LocalStatisticsTable
) {
2828 DEBUG ((DEBUG_NET
, " BUFFER TOO SMALL\n"));
2829 Status
= EFI_BUFFER_TOO_SMALL
;
2832 *StatisticsSize
= sizeof LocalStatisticsTable
;
2844 Translate IP address to MAC address.
2846 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
2847 @param IPv6 IPv6 or IPv4
2848 @param IP A pointer to given Ip address.
2849 @param MAC On return, translated MAC address.
2851 @retval EFI_INVALID_PARAMETER Invalid This paramter.
2852 @retval EFI_INVALID_PARAMETER Invalid IP address.
2853 @retval EFI_INVALID_PARAMETER Invalid return buffer for holding MAC address.
2854 @retval EFI_UNSUPPORTED Do not support IPv6
2855 @retval EFI_DEVICE_ERROR Network device has not been initialized.
2856 @retval EFI_NOT_STARTED Network device has been stopped.
2857 @retval EFI_DEVICE_ERROR Invalid status for network device
2858 @retval EFI_SUCCESS Success operation.
2862 Undi16SimpleNetworkMCastIpToMac (
2863 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
2865 IN EFI_IP_ADDRESS
*IP
,
2866 OUT EFI_MAC_ADDRESS
*MAC
2870 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2871 PXENV_UNDI_GET_MCAST_ADDR_T GetMcastAddr
;
2873 if (This
== NULL
|| IP
== NULL
|| MAC
== NULL
) {
2874 return EFI_INVALID_PARAMETER
;
2877 Status
= EFI_SUCCESS
;
2878 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2880 if (SimpleNetworkDevice
== NULL
) {
2881 return EFI_DEVICE_ERROR
;
2884 // Verify that the current state of the adapter is valid for this call.
2886 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2887 case EfiSimpleNetworkStopped
:
2888 return EFI_NOT_STARTED
;
2890 case EfiSimpleNetworkInitialized
:
2893 case EfiSimpleNetworkStarted
:
2895 return EFI_DEVICE_ERROR
;
2898 // 16 bit UNDI Option ROMS do not support IPv6. Check for IPv6 usage.
2901 return EFI_UNSUPPORTED
;
2904 // Call 16 bit UNDI ROM to open the network interface
2906 GetMcastAddr
.Status
= INIT_PXE_STATUS
;
2907 CopyMem (&GetMcastAddr
.InetAddr
, IP
, 4);
2909 Status
= PxeUndiGetMcastAddr (SimpleNetworkDevice
, &GetMcastAddr
);
2911 if (EFI_ERROR (Status
)) {
2915 // Check the status code from the 16 bit UNDI ROM
2917 if (GetMcastAddr
.Status
!= PXENV_STATUS_SUCCESS
) {
2918 return EFI_DEVICE_ERROR
;
2921 // Copy the MAC address from the returned data structure.
2925 &GetMcastAddr
.MediaAddr
,
2926 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2935 Performs read and write operations on the NVRAM device attached to a
2938 @param This The protocol instance pointer.
2939 @param ReadWrite TRUE for read operations, FALSE for write operations.
2940 @param Offset Byte offset in the NVRAM device at which to start the read or
2941 write operation. This must be a multiple of NvRamAccessSize and
2942 less than NvRamSize.
2943 @param BufferSize The number of bytes to read or write from the NVRAM device.
2944 This must also be a multiple of NvramAccessSize.
2945 @param Buffer A pointer to the data buffer.
2947 @retval EFI_SUCCESS The NVRAM access was performed.
2948 @retval EFI_NOT_STARTED The network interface has not been started.
2949 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
2950 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
2951 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
2956 Undi16SimpleNetworkNvData (
2957 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
2958 IN BOOLEAN ReadWrite
,
2960 IN UINTN BufferSize
,
2964 return EFI_UNSUPPORTED
;
2970 Reads the current interrupt status and recycled transmit buffer status from
2971 a network interface.
2973 @param This The protocol instance pointer.
2974 @param InterruptStatus A pointer to the bit mask of the currently active interrupts
2975 If this is NULL, the interrupt status will not be read from
2976 the device. If this is not NULL, the interrupt status will
2977 be read from the device. When the interrupt status is read,
2978 it will also be cleared. Clearing the transmit interrupt
2979 does not empty the recycled transmit buffer array.
2980 @param TxBuf Recycled transmit buffer address. The network interface will
2981 not transmit if its internal recycled transmit buffer array
2982 is full. Reading the transmit buffer does not clear the
2983 transmit interrupt. If this is NULL, then the transmit buffer
2984 status will not be read. If there are no transmit buffers to
2985 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
2987 @retval EFI_SUCCESS The status of the network interface was retrieved.
2988 @retval EFI_NOT_STARTED The network interface has not been started.
2989 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
2990 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
2991 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
2996 Undi16SimpleNetworkGetStatus (
2997 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
2998 OUT UINT32
*InterruptStatus OPTIONAL
,
2999 OUT VOID
**TxBuf OPTIONAL
3003 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
3007 return EFI_INVALID_PARAMETER
;
3010 Status
= EFI_SUCCESS
;
3011 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
3013 if (SimpleNetworkDevice
== NULL
) {
3014 return EFI_DEVICE_ERROR
;
3017 // Verify that the current state of the adapter is valid for this call.
3019 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
3020 case EfiSimpleNetworkInitialized
:
3023 case EfiSimpleNetworkStopped
:
3024 return EFI_NOT_STARTED
;
3026 case EfiSimpleNetworkStarted
:
3028 return EFI_DEVICE_ERROR
;
3031 if (InterruptStatus
== NULL
&& TxBuf
== NULL
) {
3032 return EFI_INVALID_PARAMETER
;
3036 Status
= Undi16SimpleNetworkIsr (This
, &FrameLength
, NULL
, NULL
, NULL
, NULL
);
3038 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3039 if (EFI_ERROR (Status
)) {
3044 // See if the caller wants interrupt info.
3046 if (InterruptStatus
!= NULL
) {
3047 *InterruptStatus
= SimpleNetworkDevice
->InterruptStatus
;
3048 SimpleNetworkDevice
->InterruptStatus
= 0;
3051 // See if the caller wants transmit buffer status info.
3053 if (TxBuf
!= NULL
) {
3055 SimpleNetworkTransmitFifoRemove (&(SimpleNetworkDevice
->TxBufferFifo
), TxBuf
);
3062 Places a packet in the transmit queue of a network interface.
3064 @param This The protocol instance pointer.
3065 @param HeaderSize The size, in bytes, of the media header to be filled in by
3066 the Transmit() function. If HeaderSize is non-zero, then it
3067 must be equal to This->Mode->MediaHeaderSize and the DestAddr
3068 and Protocol parameters must not be NULL.
3069 @param BufferSize The size, in bytes, of the entire packet (media header and
3070 data) to be transmitted through the network interface.
3071 @param Buffer A pointer to the packet (media header followed by data) to be
3072 transmitted. This parameter cannot be NULL. If HeaderSize is zero,
3073 then the media header in Buffer must already be filled in by the
3074 caller. If HeaderSize is non-zero, then the media header will be
3075 filled in by the Transmit() function.
3076 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter
3077 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
3078 This->Mode->CurrentAddress is used for the source HW MAC address.
3079 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this
3080 parameter is ignored.
3081 @param Protocol The type of header to build. If HeaderSize is zero, then this
3082 parameter is ignored. See RFC 1700, section "Ether Types", for
3085 @retval EFI_SUCCESS The packet was placed on the transmit queue.
3086 @retval EFI_NOT_STARTED The network interface has not been started.
3087 @retval EFI_NOT_READY The network interface is too busy to accept this transmit request.
3088 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
3089 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
3090 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
3091 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
3096 Undi16SimpleNetworkTransmit (
3097 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
3098 IN UINTN HeaderSize
,
3099 IN UINTN BufferSize
,
3101 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
3102 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
3103 IN UINT16
*Protocol OPTIONAL
3107 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
3108 PXENV_UNDI_TRANSMIT_T XmitInfo
;
3111 return EFI_INVALID_PARAMETER
;
3114 Status
= EFI_SUCCESS
;
3115 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
3117 if (SimpleNetworkDevice
== NULL
) {
3118 return EFI_DEVICE_ERROR
;
3121 // Verify that the current state of the adapter is valid for this call.
3123 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
3124 case EfiSimpleNetworkInitialized
:
3127 case EfiSimpleNetworkStopped
:
3128 return EFI_NOT_STARTED
;
3130 case EfiSimpleNetworkStarted
:
3132 return EFI_DEVICE_ERROR
;
3135 if (Buffer
== NULL
) {
3136 return EFI_INVALID_PARAMETER
;
3139 if (BufferSize
< SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
) {
3140 return EFI_BUFFER_TOO_SMALL
;
3143 if (HeaderSize
!= 0) {
3144 if (HeaderSize
!= SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
) {
3145 return EFI_INVALID_PARAMETER
;
3148 if (DestAddr
== NULL
|| Protocol
== NULL
) {
3149 return EFI_INVALID_PARAMETER
;
3152 if (DestAddr
!= NULL
) {
3156 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
3160 if (SrcAddr
== NULL
) {
3161 SrcAddr
= &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
;
3165 (UINT8
*) Buffer
+ SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
,
3167 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
3170 if (Protocol
!= NULL
) {
3171 *(UINT16
*) ((UINT8
*) Buffer
+ 2 * SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
) = (UINT16
) (((*Protocol
& 0xFF) << 8) | ((*Protocol
>> 8) & 0xFF));
3175 // See if the recycled transmit buffer FIFO is full.
3176 // If it is full, then we can not transmit until the caller calls GetStatus() to pull
3177 // off recycled transmit buffers.
3179 if (SimpleNetworkTransmitFifoFull (&(SimpleNetworkDevice
->TxBufferFifo
))) {
3180 return EFI_NOT_READY
;
3183 // Output debug trace message.
3185 DEBUG ((DEBUG_NET
, "Undi16SimpleNetworkTransmit\n\r "));
3188 // Initialize UNDI WRITE parameter structure.
3190 XmitInfo
.Status
= INIT_PXE_STATUS
;
3191 XmitInfo
.Protocol
= P_UNKNOWN
;
3192 XmitInfo
.XmitFlag
= XMT_DESTADDR
;
3193 XmitInfo
.DestAddrOffset
= (UINT16
) ((UINT32
)(UINTN
) SimpleNetworkDevice
->TxDestAddr
& 0x000f);
3194 XmitInfo
.DestAddrSegment
= (UINT16
) ((UINT32
)(UINTN
) SimpleNetworkDevice
->TxDestAddr
>> 4);
3195 XmitInfo
.TBDOffset
= (UINT16
) ((UINT32
)(UINTN
) SimpleNetworkDevice
->Xmit
& 0x000f);
3196 XmitInfo
.TBDSegment
= (UINT16
) ((UINT32
)(UINTN
) SimpleNetworkDevice
->Xmit
>> 4);
3197 XmitInfo
.Reserved
[0] = 0;
3198 XmitInfo
.Reserved
[1] = 0;
3201 SimpleNetworkDevice
->TxDestAddr
,
3203 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
3207 SimpleNetworkDevice
->TxRealModeMediaHeader
,
3209 SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
3212 SimpleNetworkDevice
->Xmit
->ImmedLength
= (UINT16
) SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
;
3214 SimpleNetworkDevice
->Xmit
->DataBlock
[0].TDDataLen
= (UINT16
) (BufferSize
- SimpleNetworkDevice
->Xmit
->ImmedLength
);
3217 SimpleNetworkDevice
->TxRealModeDataBuffer
,
3218 (UINT8
*) Buffer
+ SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
,
3219 SimpleNetworkDevice
->Xmit
->DataBlock
[0].TDDataLen
3223 // Make API call to UNDI TRANSMIT
3225 XmitInfo
.Status
= 0;
3227 Status
= PxeUndiTransmit (SimpleNetworkDevice
, &XmitInfo
);
3229 if (EFI_ERROR (Status
)) {
3233 // Check the status code from the 16 bit UNDI ROM
3235 switch (XmitInfo
.Status
) {
3236 case PXENV_STATUS_OUT_OF_RESOURCES
:
3237 return EFI_NOT_READY
;
3239 case PXENV_STATUS_SUCCESS
:
3243 return EFI_DEVICE_ERROR
;
3246 // Add address of Buffer to the recycled transmit buffer FIFO
3248 SimpleNetworkTransmitFifoAdd (&(SimpleNetworkDevice
->TxBufferFifo
), Buffer
);
3254 Receives a packet from a network interface.
3256 @param This The protocol instance pointer.
3257 @param HeaderSize The size, in bytes, of the media header received on the network
3258 interface. If this parameter is NULL, then the media header size
3259 will not be returned.
3260 @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in
3261 bytes, of the packet that was received on the network interface.
3262 @param Buffer A pointer to the data buffer to receive both the media header and
3264 @param SrcAddr The source HW MAC address. If this parameter is NULL, the
3265 HW MAC source address will not be extracted from the media
3267 @param DestAddr The destination HW MAC address. If this parameter is NULL,
3268 the HW MAC destination address will not be extracted from the
3270 @param Protocol The media header type. If this parameter is NULL, then the
3271 protocol will not be extracted from the media header. See
3272 RFC 1700 section "Ether Types" for examples.
3274 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has
3275 been updated to the number of bytes received.
3276 @retval EFI_NOT_STARTED The network interface has not been started.
3277 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
3279 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
3280 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
3281 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
3282 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
3287 Undi16SimpleNetworkReceive (
3288 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
3289 OUT UINTN
*HeaderSize OPTIONAL
,
3290 IN OUT UINTN
*BufferSize
,
3292 OUT EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
3293 OUT EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
3294 OUT UINT16
*Protocol OPTIONAL
3298 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
3299 UINTN MediaAddrSize
;
3302 if (This
== NULL
|| BufferSize
== NULL
|| Buffer
== NULL
) {
3303 return EFI_INVALID_PARAMETER
;
3306 Status
= EFI_SUCCESS
;
3307 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
3309 if (SimpleNetworkDevice
== NULL
) {
3310 return EFI_DEVICE_ERROR
;
3313 // Verify that the current state of the adapter is valid for this call.
3315 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
3316 case EfiSimpleNetworkInitialized
:
3319 case EfiSimpleNetworkStopped
:
3320 return EFI_NOT_STARTED
;
3322 case EfiSimpleNetworkStarted
:
3324 return EFI_DEVICE_ERROR
;
3327 Status
= Undi16SimpleNetworkIsr (
3336 if (EFI_ERROR (Status
)) {
3340 if ((SimpleNetworkDevice
->InterruptStatus
& EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
) == 0) {
3341 return EFI_NOT_READY
;
3345 SimpleNetworkDevice
->InterruptStatus
&= ~EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
;
3347 MediaAddrSize
= This
->Mode
->HwAddressSize
;
3349 if (SrcAddr
!= NULL
) {
3350 CopyMem (SrcAddr
, (UINT8
*) Buffer
+ MediaAddrSize
, MediaAddrSize
);
3353 if (DestAddr
!= NULL
) {
3354 CopyMem (DestAddr
, Buffer
, MediaAddrSize
);
3357 if (Protocol
!= NULL
) {
3358 *((UINT8
*) Protocol
) = *((UINT8
*) Buffer
+ (2 * MediaAddrSize
) + 1);
3359 *((UINT8
*) Protocol
+ 1) = *((UINT8
*) Buffer
+ (2 * MediaAddrSize
));
3362 DEBUG ((DEBUG_NET
, "Packet Received: BufferSize=%d HeaderSize = %d\n", *BufferSize
, *HeaderSize
));
3371 wait for a packet to be received.
3373 @param Event Event used with WaitForEvent() to wait for a packet to be received.
3374 @param Context Event Context
3379 Undi16SimpleNetworkWaitForPacket (
3385 // Someone is waiting on the receive packet event, if there's
3386 // a packet pending, signal the event
3388 if (!EFI_ERROR (Undi16SimpleNetworkCheckForPacket (Context
))) {
3389 gBS
->SignalEvent (Event
);
3396 Check whether packet is ready for receive.
3398 @param This The protocol instance pointer.
3400 @retval EFI_SUCCESS Receive data is ready.
3401 @retval EFI_NOT_STARTED The network interface has not been started.
3402 @retval EFI_NOT_READY The network interface is too busy to accept this transmit
3404 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
3405 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
3406 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
3407 @retval EFI_UNSUPPORTED This function is not supported by the network interface.
3410 Undi16SimpleNetworkCheckForPacket (
3411 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
3415 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
3419 return EFI_INVALID_PARAMETER
;
3422 Status
= EFI_SUCCESS
;
3423 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
3425 if (SimpleNetworkDevice
== NULL
) {
3426 return EFI_DEVICE_ERROR
;
3429 // Verify that the current state of the adapter is valid for this call.
3431 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
3432 case EfiSimpleNetworkInitialized
:
3435 case EfiSimpleNetworkStopped
:
3436 return EFI_NOT_STARTED
;
3438 case EfiSimpleNetworkStarted
:
3440 return EFI_DEVICE_ERROR
;
3444 Status
= Undi16SimpleNetworkIsr (
3453 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3454 if (EFI_ERROR (Status
)) {
3459 return ((SimpleNetworkDevice
->InterruptStatus
& EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
) != 0) ? EFI_SUCCESS
: EFI_NOT_READY
;
3463 Signal handlers for ExitBootServices event.
3465 Clean up any Real-mode UNDI residue from the system
3467 @param Event ExitBootServices event
3472 Undi16SimpleNetworkEvent (
3478 // NOTE: This is not the only way to effect this cleanup. The prescribed mechanism
3479 // would be to perform an UNDI STOP command. This strategam has been attempted
3480 // but results in problems making some of the EFI core services from TPL_CALLBACK.
3481 // This issue needs to be resolved, but the other alternative has been to perform
3482 // the unchain logic explicitly, as done below.
3484 RestoreCachedVectorAddress (0x1A);
3488 Allocate buffer below 1M for real mode.
3490 @param NumPages The number pages want to be allocated.
3491 @param Buffer On return, allocated buffer.
3493 @return Status of allocating pages.
3496 BiosSnp16AllocatePagesBelowOneMb (
3502 EFI_PHYSICAL_ADDRESS PhysicalAddress
;
3504 PhysicalAddress
= 0x000fffff;
3505 Status
= gBS
->AllocatePages (
3507 EfiRuntimeServicesData
,
3511 if (EFI_ERROR (Status
)) {
3515 *Buffer
= (VOID
*) (UINTN
) PhysicalAddress
;