3 Copyright (c) 1999 - 2010, 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
));
1229 PciDataStructure
= (PCI_DATA_STRUCTURE
*) (RomAddress
+ PciExpansionRomHeader
->PcirOffset
);
1231 if (PciDataStructure
->Signature
!= PCI_DATA_STRUCTURE_SIGNATURE
) {
1235 DEBUG ((DEBUG_INIT
, "PCI Data Structure found at %X\n", PciDataStructure
));
1237 if (PciDataStructure
->VendorId
!= Pci
.Hdr
.VendorId
|| PciDataStructure
->DeviceId
!= Pci
.Hdr
.DeviceId
) {
1243 "PCI device with matchinng VendorId and DeviceId (%d,%d)\n",
1244 (UINTN
) PciDataStructure
->VendorId
,
1245 (UINTN
) PciDataStructure
->DeviceId
)
1248 Status
= LaunchBaseCode (SimpleNetworkDevice
, RomAddress
);
1250 if (!EFI_ERROR (Status
)) {
1255 return EFI_NOT_FOUND
;
1259 Unload 16 bit UNDI Option ROM from memory
1261 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1266 Undi16SimpleNetworkUnloadUndi (
1267 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
1270 if (SimpleNetworkDevice
->UndiLoaderTable
!= NULL
) {
1271 ZeroMem (SimpleNetworkDevice
->UndiLoaderTable
, SimpleNetworkDevice
->UndiLoaderTablePages
<< EFI_PAGE_SHIFT
);
1273 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->UndiLoaderTable
,
1274 SimpleNetworkDevice
->UndiLoaderTablePages
1278 if (SimpleNetworkDevice
->DestinationDataSegment
!= NULL
) {
1280 SimpleNetworkDevice
->DestinationDataSegment
,
1281 SimpleNetworkDevice
->DestinationDataSegmentPages
<< EFI_PAGE_SHIFT
1284 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->DestinationDataSegment
,
1285 SimpleNetworkDevice
->DestinationDataSegmentPages
1289 if (SimpleNetworkDevice
->DestinationStackSegment
!= NULL
) {
1291 SimpleNetworkDevice
->DestinationStackSegment
,
1292 SimpleNetworkDevice
->DestinationStackSegmentPages
<< EFI_PAGE_SHIFT
1295 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->DestinationStackSegment
,
1296 SimpleNetworkDevice
->DestinationStackSegmentPages
1300 if (SimpleNetworkDevice
->DestinationCodeSegment
!= NULL
) {
1302 SimpleNetworkDevice
->DestinationCodeSegment
,
1303 SimpleNetworkDevice
->DestinationCodeSegmentPages
<< EFI_PAGE_SHIFT
1306 (EFI_PHYSICAL_ADDRESS
) (UINTN
) SimpleNetworkDevice
->DestinationCodeSegment
,
1307 SimpleNetworkDevice
->DestinationCodeSegmentPages
1315 Start the UNDI interface.
1317 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1318 @param Ax PCI address of Undi device.
1320 @retval EFI_DEVICE_ERROR Fail to start 16 bit UNDI ROM.
1321 @retval Others Status of start 16 bit UNDI ROM.
1324 Undi16SimpleNetworkStartUndi (
1325 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
,
1330 PXENV_START_UNDI_T Start
;
1333 // Call 16 bit UNDI ROM to start the network interface
1336 // @bug : What is this state supposed to be???
1338 Start
.Status
= INIT_PXE_STATUS
;
1345 Status
= PxeStartUndi (SimpleNetworkDevice
, &Start
);
1346 if (EFI_ERROR (Status
)) {
1350 // Check the status code from the 16 bit UNDI ROM
1352 if (Start
.Status
!= PXENV_STATUS_SUCCESS
) {
1353 return EFI_DEVICE_ERROR
;
1361 Stop the UNDI interface
1363 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1365 @retval EFI_DEVICE_ERROR Fail to stop 16 bit UNDI ROM.
1366 @retval Others Status of stop 16 bit UNDI ROM.
1369 Undi16SimpleNetworkStopUndi (
1370 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
1374 PXENV_STOP_UNDI_T Stop
;
1377 // Call 16 bit UNDI ROM to start the network interface
1379 Stop
.Status
= INIT_PXE_STATUS
;
1381 Status
= PxeUndiStop (SimpleNetworkDevice
, &Stop
);
1382 if (EFI_ERROR (Status
)) {
1386 // Check the status code from the 16 bit UNDI ROM
1388 if (Stop
.Status
!= PXENV_STATUS_SUCCESS
) {
1389 return EFI_DEVICE_ERROR
;
1396 Cleanup Unid network interface
1398 @param SimpleNetworkDevice A pointer to EFI_SIMPLE_NETWORK_DEV data structure.
1400 @retval EFI_DEVICE_ERROR Fail to cleanup 16 bit UNDI ROM.
1401 @retval Others Status of cleanup 16 bit UNDI ROM.
1404 Undi16SimpleNetworkCleanupUndi (
1405 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
1409 PXENV_UNDI_CLEANUP_T Cleanup
;
1412 // Call 16 bit UNDI ROM to cleanup the network interface
1414 Cleanup
.Status
= INIT_PXE_STATUS
;
1416 Status
= PxeUndiCleanup (SimpleNetworkDevice
, &Cleanup
);
1417 if (EFI_ERROR (Status
)) {
1421 // Check the status code from the 16 bit UNDI ROM
1423 if (Cleanup
.Status
!= PXENV_STATUS_SUCCESS
) {
1424 return EFI_DEVICE_ERROR
;
1431 Get runtime information for Undi network interface
1433 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1435 @retval EFI_SUCCESS Sucess operation.
1436 @retval Others Fail to get runtime information for Undi network interface.
1439 Undi16SimpleNetworkGetInformation (
1440 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1444 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1448 return EFI_INVALID_PARAMETER
;
1451 Status
= EFI_SUCCESS
;
1452 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1454 if (SimpleNetworkDevice
== NULL
) {
1455 return EFI_DEVICE_ERROR
;
1458 // Verify that the current state of the adapter is valid for this call.
1460 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
1461 case EfiSimpleNetworkStarted
:
1462 case EfiSimpleNetworkInitialized
:
1465 case EfiSimpleNetworkStopped
:
1466 return EFI_NOT_STARTED
;
1469 return EFI_DEVICE_ERROR
;
1472 // Call 16 bit UNDI ROM to start the network interface
1474 ZeroMem (&SimpleNetworkDevice
->GetInformation
, sizeof (PXENV_UNDI_GET_INFORMATION_T
));
1476 SimpleNetworkDevice
->GetInformation
.Status
= INIT_PXE_STATUS
;
1478 Status
= PxeUndiGetInformation (SimpleNetworkDevice
, &SimpleNetworkDevice
->GetInformation
);
1479 if (EFI_ERROR (Status
)) {
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
));
1493 DEBUG ((DEBUG_NET
, " GetInformation.CurNodeAddr ="));
1494 for (Index
= 0; Index
< 16; Index
++) {
1495 DEBUG ((DEBUG_NET
, "%02x ", SimpleNetworkDevice
->GetInformation
.CurrentNodeAddress
[Index
]));
1498 DEBUG ((DEBUG_NET
, "\n"));
1500 DEBUG ((DEBUG_NET
, " GetInformation.PermNodeAddr ="));
1501 for (Index
= 0; Index
< 16; Index
++) {
1502 DEBUG ((DEBUG_NET
, "%02x ", SimpleNetworkDevice
->GetInformation
.PermNodeAddress
[Index
]));
1505 DEBUG ((DEBUG_NET
, "\n"));
1508 // Check the status code from the 16 bit UNDI ROM
1510 if (SimpleNetworkDevice
->GetInformation
.Status
!= PXENV_STATUS_SUCCESS
) {
1511 return EFI_DEVICE_ERROR
;
1514 // The information has been retrieved. Fill in Mode data.
1516 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
= SimpleNetworkDevice
->GetInformation
.HwAddrLen
;
1518 SimpleNetworkDevice
->SimpleNetworkMode
.MaxPacketSize
= SimpleNetworkDevice
->GetInformation
.MaxTranUnit
;
1520 SimpleNetworkDevice
->SimpleNetworkMode
.IfType
= (UINT8
) SimpleNetworkDevice
->GetInformation
.HwType
;
1523 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
1524 sizeof SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
1528 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
1529 &SimpleNetworkDevice
->GetInformation
.CurrentNodeAddress
,
1530 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
1534 &SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
,
1535 sizeof SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
1539 &SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
,
1540 &SimpleNetworkDevice
->GetInformation
.PermNodeAddress
,
1541 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
1545 // hard code broadcast address - not avail in PXE2.1
1548 &SimpleNetworkDevice
->SimpleNetworkMode
.BroadcastAddress
,
1549 sizeof SimpleNetworkDevice
->SimpleNetworkMode
.BroadcastAddress
1553 &SimpleNetworkDevice
->SimpleNetworkMode
.BroadcastAddress
,
1554 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
,
1564 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1566 @retval EFI_SUCCESS Sucess operation.
1567 @retval Others Fail to get NIC type.
1570 Undi16SimpleNetworkGetNicType (
1571 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1575 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1578 return EFI_INVALID_PARAMETER
;
1581 Status
= EFI_SUCCESS
;
1582 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1584 if (SimpleNetworkDevice
== NULL
) {
1585 return EFI_DEVICE_ERROR
;
1588 ZeroMem (&SimpleNetworkDevice
->GetNicType
, sizeof (PXENV_UNDI_GET_NIC_TYPE_T
));
1590 SimpleNetworkDevice
->GetNicType
.Status
= INIT_PXE_STATUS
;
1592 Status
= PxeUndiGetNicType (SimpleNetworkDevice
, &SimpleNetworkDevice
->GetNicType
);
1594 if (EFI_ERROR (Status
)) {
1598 DEBUG ((DEBUG_NET
, " GetNicType.Status = %d\n", SimpleNetworkDevice
->GetNicType
.Status
));
1599 DEBUG ((DEBUG_NET
, " GetNicType.NicType = %d\n", SimpleNetworkDevice
->GetNicType
.NicType
));
1601 // Check the status code from the 16 bit UNDI ROM
1603 if (SimpleNetworkDevice
->GetNicType
.Status
!= PXENV_STATUS_SUCCESS
) {
1604 return EFI_DEVICE_ERROR
;
1607 // The information has been retrieved. Fill in Mode data.
1613 Get NDIS information
1615 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
1617 @retval EFI_SUCCESS Sucess operation.
1618 @retval Others Fail to get NDIS information.
1621 Undi16SimpleNetworkGetNdisInfo (
1622 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1626 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1629 return EFI_INVALID_PARAMETER
;
1632 Status
= EFI_SUCCESS
;
1633 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1635 if (SimpleNetworkDevice
== NULL
) {
1636 return EFI_DEVICE_ERROR
;
1639 ZeroMem (&SimpleNetworkDevice
->GetNdisInfo
, sizeof (PXENV_UNDI_GET_NDIS_INFO_T
));
1641 SimpleNetworkDevice
->GetNdisInfo
.Status
= INIT_PXE_STATUS
;
1643 Status
= PxeUndiGetNdisInfo (SimpleNetworkDevice
, &SimpleNetworkDevice
->GetNdisInfo
);
1645 if (EFI_ERROR (Status
)) {
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
));
1655 // Check the status code from the 16 bit UNDI ROM
1657 if (SimpleNetworkDevice
->GetNdisInfo
.Status
!= PXENV_STATUS_SUCCESS
) {
1658 return EFI_DEVICE_ERROR
;
1661 // The information has been retrieved. Fill in Mode data.
1667 Call Undi ROM 16bit ISR() to check interrupt cause.
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.
1676 @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM's ISR, or status is invalid.
1677 @retval EFI_SUCCESS Success operation.
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
1690 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1691 BOOLEAN FrameReceived
;
1694 return EFI_INVALID_PARAMETER
;
1697 Status
= EFI_SUCCESS
;
1698 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1700 if (SimpleNetworkDevice
== NULL
) {
1701 return EFI_DEVICE_ERROR
;
1704 FrameReceived
= FALSE
;
1707 // Verify that the current state of the adapter is valid for this call.
1709 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
1710 case EfiSimpleNetworkInitialized
:
1713 case EfiSimpleNetworkStopped
:
1714 return EFI_NOT_STARTED
;
1716 case EfiSimpleNetworkStarted
:
1718 return EFI_DEVICE_ERROR
;
1721 DEBUG ((DEBUG_NET
, "Isr() IsrValid = %d\n", SimpleNetworkDevice
->IsrValid
));
1723 if (!SimpleNetworkDevice
->IsrValid
) {
1725 // Call 16 bit UNDI ROM to open the network interface
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
;
1731 DEBUG ((DEBUG_NET
, "Isr() START\n"));
1733 Status
= PxeUndiIsr (SimpleNetworkDevice
, &SimpleNetworkDevice
->Isr
);
1734 if (EFI_ERROR (Status
)) {
1738 // Check the status code from the 16 bit UNDI ROM
1740 if (SimpleNetworkDevice
->Isr
.Status
!= PXENV_STATUS_SUCCESS
) {
1741 return EFI_DEVICE_ERROR
;
1744 // There have been no events on this UNDI interface, so return EFI_NOT_READY
1746 if (SimpleNetworkDevice
->Isr
.FuncFlag
== PXENV_UNDI_ISR_OUT_NOT_OURS
) {
1750 // There is data to process, so call until all events processed.
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
;
1756 DEBUG ((DEBUG_NET
, "Isr() PROCESS\n"));
1758 Status
= PxeUndiIsr (SimpleNetworkDevice
, &SimpleNetworkDevice
->Isr
);
1759 if (EFI_ERROR (Status
)) {
1763 SimpleNetworkDevice
->IsrValid
= TRUE
;
1766 // Call UNDI GET_NEXT until DONE
1768 while (SimpleNetworkDevice
->Isr
.FuncFlag
!= PXENV_UNDI_ISR_OUT_DONE
) {
1770 // Check the status code from the 16 bit UNDI ROM
1772 if (SimpleNetworkDevice
->Isr
.Status
!= PXENV_STATUS_SUCCESS
) {
1773 return EFI_DEVICE_ERROR
;
1776 // UNDI is busy. Caller will have to call again.
1777 // This should never happen with a polled mode driver.
1779 if (SimpleNetworkDevice
->Isr
.FuncFlag
== PXENV_UNDI_ISR_OUT_BUSY
) {
1780 DEBUG ((DEBUG_NET
, " BUSY\n"));
1784 // Check for invalud UNDI FuncFlag
1786 if (SimpleNetworkDevice
->Isr
.FuncFlag
!= PXENV_UNDI_ISR_OUT_RECEIVE
&&
1787 SimpleNetworkDevice
->Isr
.FuncFlag
!= PXENV_UNDI_ISR_OUT_TRANSMIT
1789 DEBUG ((DEBUG_NET
, " Invalid SimpleNetworkDevice->Isr.FuncFlag value %d\n", SimpleNetworkDevice
->Isr
.FuncFlag
));
1790 return EFI_DEVICE_ERROR
;
1793 // Check for Transmit Event
1795 if (SimpleNetworkDevice
->Isr
.FuncFlag
== PXENV_UNDI_ISR_OUT_TRANSMIT
) {
1796 DEBUG ((DEBUG_NET
, " TRANSMIT\n"));
1797 SimpleNetworkDevice
->InterruptStatus
|= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
;
1800 // Check for Receive Event
1802 else if (SimpleNetworkDevice
->Isr
.FuncFlag
== PXENV_UNDI_ISR_OUT_RECEIVE
) {
1804 // note - this code will hang on a receive interrupt in a GetStatus loop
1806 DEBUG ((DEBUG_NET
, " RECEIVE\n"));
1807 SimpleNetworkDevice
->InterruptStatus
|= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
;
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
));
1814 DEBUG_NET
, "SimpleNetworkDevice->Isr.Frame = %04x:%04x\n", SimpleNetworkDevice
->Isr
.FrameSegSel
,
1815 SimpleNetworkDevice
->Isr
.FrameOffset
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
));
1821 if (FrameReceived
) {
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
;
1831 *FrameLength
= SimpleNetworkDevice
->Isr
.FrameLength
;
1832 if (FrameHeaderLength
!= NULL
) {
1833 *FrameHeaderLength
= SimpleNetworkDevice
->Isr
.FrameHeaderLength
;
1836 if (ProtType
!= NULL
) {
1837 *ProtType
= SimpleNetworkDevice
->Isr
.ProtType
;
1840 if (PktType
!= NULL
) {
1841 *PktType
= SimpleNetworkDevice
->Isr
.PktType
;
1846 (VOID
*)(UINTN
) ((SimpleNetworkDevice
->Isr
.FrameSegSel
<< 4) + SimpleNetworkDevice
->Isr
.FrameOffset
),
1847 SimpleNetworkDevice
->Isr
.BufferLength
1849 Frame
= Frame
+ SimpleNetworkDevice
->Isr
.BufferLength
;
1850 if (SimpleNetworkDevice
->Isr
.BufferLength
== SimpleNetworkDevice
->Isr
.FrameLength
) {
1851 FrameReceived
= TRUE
;
1855 // There is data to process, so call until all events processed.
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
;
1861 DEBUG ((DEBUG_NET
, "Isr() GET NEXT\n"));
1863 Status
= PxeUndiIsr (SimpleNetworkDevice
, &SimpleNetworkDevice
->Isr
);
1864 if (EFI_ERROR (Status
)) {
1868 // Check the status code from the 16 bit UNDI ROM
1870 // if (SimpleNetworkDevice->Isr.Status != PXENV_STATUS_SUCCESS) {
1871 // return EFI_DEVICE_ERROR;
1876 SimpleNetworkDevice
->IsrValid
= FALSE
;
1880 // ///////////////////////////////////////////////////////////////////////////////////////
1881 // Simple Network Protocol Interface Functions using 16 bit UNDI Option ROMs
1882 /////////////////////////////////////////////////////////////////////////////////////////
1887 Call 16 bit UNDI ROM to start the network interface
1889 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
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.
1897 Undi16SimpleNetworkStart (
1898 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1902 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1903 PXENV_UNDI_STARTUP_T Startup
;
1906 return EFI_INVALID_PARAMETER
;
1909 Status
= EFI_SUCCESS
;
1910 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1912 if (SimpleNetworkDevice
== NULL
) {
1913 return EFI_DEVICE_ERROR
;
1916 // Verify that the current state of the adapter is valid for this call.
1918 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
1919 case EfiSimpleNetworkStopped
:
1922 case EfiSimpleNetworkStarted
:
1923 case EfiSimpleNetworkInitialized
:
1924 return EFI_ALREADY_STARTED
;
1927 return EFI_DEVICE_ERROR
;
1930 // Call 16 bit UNDI ROM to start the network interface
1932 Startup
.Status
= INIT_PXE_STATUS
;
1934 Status
= PxeUndiStartup (SimpleNetworkDevice
, &Startup
);
1935 if (EFI_ERROR (Status
)) {
1939 // Check the status code from the 16 bit UNDI ROM
1941 if (Startup
.Status
!= PXENV_STATUS_SUCCESS
) {
1942 return EFI_DEVICE_ERROR
;
1945 // The UNDI interface has been started, so update the State.
1947 SimpleNetworkDevice
->SimpleNetworkMode
.State
= EfiSimpleNetworkStarted
;
1952 SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
= 0;
1953 SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilterCount
= 0;
1961 Call 16 bit UNDI ROM to stop the network interface
1963 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
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.
1971 Undi16SimpleNetworkStop (
1972 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
1976 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
1979 return EFI_INVALID_PARAMETER
;
1982 Status
= EFI_SUCCESS
;
1983 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
1985 if (SimpleNetworkDevice
== NULL
) {
1986 return EFI_DEVICE_ERROR
;
1989 // Verify that the current state of the adapter is valid for this call.
1991 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
1992 case EfiSimpleNetworkStarted
:
1995 case EfiSimpleNetworkStopped
:
1996 return EFI_NOT_STARTED
;
1998 case EfiSimpleNetworkInitialized
:
2000 return EFI_DEVICE_ERROR
;
2003 SimpleNetworkDevice
->SimpleNetworkMode
.State
= EfiSimpleNetworkStopped
;
2012 Initialize network interface
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.
2018 @retval EFI_DEVICE_ERROR Fail to execute 16 bit ROM call.
2019 @retval EFI_SUCESS Success operation.
2023 Undi16SimpleNetworkInitialize (
2024 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
2025 IN UINTN ExtraRxBufferSize OPTIONAL
,
2026 IN UINTN ExtraTxBufferSize OPTIONAL
2030 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2031 PXENV_UNDI_INITIALIZE_T Initialize
;
2032 PXENV_UNDI_OPEN_T Open
;
2035 return EFI_INVALID_PARAMETER
;
2038 Status
= EFI_SUCCESS
;
2039 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2041 if (SimpleNetworkDevice
== NULL
) {
2042 return EFI_DEVICE_ERROR
;
2045 // Verify that the current state of the adapter is valid for this call.
2047 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2048 case EfiSimpleNetworkStopped
:
2049 return EFI_NOT_STARTED
;
2051 case EfiSimpleNetworkStarted
:
2054 case EfiSimpleNetworkInitialized
:
2056 return EFI_DEVICE_ERROR
;
2059 // Call 16 bit UNDI ROM to start the network interface
2061 Initialize
.Status
= INIT_PXE_STATUS
;
2062 Initialize
.ProtocolIni
= 0;
2064 Status
= PxeUndiInitialize (SimpleNetworkDevice
, &Initialize
);
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
));
2070 if (Initialize
.Status
== PXENV_STATUS_UNDI_MEDIATEST_FAILED
) {
2071 Status
= EFI_NO_MEDIA
;
2077 // Check the status code from the 16 bit UNDI ROM
2079 if (Initialize
.Status
!= PXENV_STATUS_SUCCESS
) {
2080 DEBUG ((DEBUG_ERROR
, "ERROR : PxeUndiInitialize() - Initialize.Status = %04x\n", Initialize
.Status
));
2081 return EFI_DEVICE_ERROR
;
2084 // Call 16 bit UNDI ROM to open the network interface
2086 Open
.Status
= INIT_PXE_STATUS
;
2088 Open
.PktFilter
= Undi16GetPacketFilterSetting (SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
);
2089 Undi16GetMCastFilters (
2090 &SimpleNetworkDevice
->SimpleNetworkMode
,
2092 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2095 Status
= PxeUndiOpen (SimpleNetworkDevice
, &Open
);
2097 if (EFI_ERROR (Status
)) {
2098 DEBUG ((DEBUG_ERROR
, "ERROR : PxeUndiOpen() - Status = %r\n", Status
));
2102 // Check the status code from the 16 bit UNDI ROM
2104 if (Open
.Status
!= PXENV_STATUS_SUCCESS
) {
2105 DEBUG ((DEBUG_ERROR
, "ERROR : PxeUndiOpen() - Open.Status = %04x\n", Open
.Status
));
2106 return EFI_DEVICE_ERROR
;
2109 // The UNDI interface has been initialized, so update the State.
2111 SimpleNetworkDevice
->SimpleNetworkMode
.State
= EfiSimpleNetworkInitialized
;
2114 // If initialize succeeds, then assume that media is present.
2116 SimpleNetworkDevice
->SimpleNetworkMode
.MediaPresent
= TRUE
;
2119 // Reset the recycled transmit buffer FIFO
2121 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
2122 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
2123 SimpleNetworkDevice
->IsrValid
= FALSE
;
2131 Reset network interface.
2133 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
2134 @param ExtendedVerification Need extended verfication.
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.
2144 Undi16SimpleNetworkReset (
2145 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
2146 IN BOOLEAN ExtendedVerification
2150 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2151 PXENV_UNDI_RESET_T Reset
;
2155 return EFI_INVALID_PARAMETER
;
2158 Status
= EFI_SUCCESS
;
2159 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2161 if (SimpleNetworkDevice
== NULL
) {
2162 return EFI_DEVICE_ERROR
;
2165 // Verify that the current state of the adapter is valid for this call.
2167 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2168 case EfiSimpleNetworkStopped
:
2169 return EFI_NOT_STARTED
;
2171 case EfiSimpleNetworkInitialized
:
2174 case EfiSimpleNetworkStarted
:
2176 return EFI_DEVICE_ERROR
;
2179 Reset
.Status
= INIT_PXE_STATUS
;
2181 Rx_filter
= Undi16GetPacketFilterSetting (SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
);
2183 Undi16GetMCastFilters (
2184 &SimpleNetworkDevice
->SimpleNetworkMode
,
2186 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2189 Status
= PxeUndiResetNic (SimpleNetworkDevice
, &Reset
, Rx_filter
);
2191 if (EFI_ERROR (Status
)) {
2195 // Check the status code from the 16 bit UNDI ROM
2197 if (Reset
.Status
!= PXENV_STATUS_SUCCESS
) {
2198 return EFI_DEVICE_ERROR
;
2201 // Reset the recycled transmit buffer FIFO
2203 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
2204 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
2205 SimpleNetworkDevice
->IsrValid
= FALSE
;
2213 Shutdown network interface.
2215 @param This A pointer to EFI_SIMPLE_NETWORK_PROTOCOL structure.
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.
2225 Undi16SimpleNetworkShutdown (
2226 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
2230 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2231 PXENV_UNDI_CLOSE_T Close
;
2232 PXENV_UNDI_SHUTDOWN_T Shutdown
;
2235 return EFI_INVALID_PARAMETER
;
2238 Status
= EFI_SUCCESS
;
2239 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2241 if (SimpleNetworkDevice
== NULL
) {
2242 return EFI_DEVICE_ERROR
;
2245 // Verify that the current state of the adapter is valid for this call.
2247 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2248 case EfiSimpleNetworkStopped
:
2249 return EFI_NOT_STARTED
;
2251 case EfiSimpleNetworkInitialized
:
2254 case EfiSimpleNetworkStarted
:
2256 return EFI_DEVICE_ERROR
;
2259 SimpleNetworkDevice
->IsrValid
= FALSE
;
2262 // Call 16 bit UNDI ROM to start the network interface
2264 Close
.Status
= INIT_PXE_STATUS
;
2266 Status
= PxeUndiClose (SimpleNetworkDevice
, &Close
);
2268 if (EFI_ERROR (Status
)) {
2272 // Check the status code from the 16 bit UNDI ROM
2274 if (Close
.Status
!= PXENV_STATUS_SUCCESS
) {
2275 return EFI_DEVICE_ERROR
;
2278 // Call 16 bit UNDI ROM to open the network interface
2280 Shutdown
.Status
= INIT_PXE_STATUS
;
2282 Status
= PxeUndiShutdown (SimpleNetworkDevice
, &Shutdown
);
2284 if (EFI_ERROR (Status
)) {
2288 // Check the status code from the 16 bit UNDI ROM
2290 if (Shutdown
.Status
!= PXENV_STATUS_SUCCESS
) {
2291 return EFI_DEVICE_ERROR
;
2294 // The UNDI interface has been initialized, so update the State.
2296 SimpleNetworkDevice
->SimpleNetworkMode
.State
= EfiSimpleNetworkStarted
;
2299 // If shutdown succeeds, then assume that media is not present.
2301 SimpleNetworkDevice
->SimpleNetworkMode
.MediaPresent
= FALSE
;
2304 // Reset the recycled transmit buffer FIFO
2306 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
2307 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
2310 // A short delay. Without this an initialize immediately following
2311 // a shutdown will cause some versions of UNDI-16 to stop operating.
2313 gBS
->Stall (250000);
2321 Reset network interface.
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.
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.
2338 Undi16SimpleNetworkReceiveFilters (
2339 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
2342 IN BOOLEAN ResetMCastFilter
,
2343 IN UINTN MCastFilterCnt OPTIONAL
,
2344 IN EFI_MAC_ADDRESS
* MCastFilter OPTIONAL
2350 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2351 PXENV_UNDI_CLOSE_T Close
;
2352 PXENV_UNDI_OPEN_T Open
;
2355 return EFI_INVALID_PARAMETER
;
2358 Status
= EFI_SUCCESS
;
2359 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2361 if (SimpleNetworkDevice
== NULL
) {
2362 return EFI_DEVICE_ERROR
;
2365 // Verify that the current state of the adapter is valid for this call.
2367 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2368 case EfiSimpleNetworkStopped
:
2369 return EFI_NOT_STARTED
;
2371 case EfiSimpleNetworkInitialized
:
2374 case EfiSimpleNetworkStarted
:
2376 return EFI_DEVICE_ERROR
;
2379 // First deal with possible filter setting changes
2381 if ((Enable
== 0) && (Disable
== 0) && !ResetMCastFilter
) {
2385 NewFilter
= (SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
| Enable
) &~Disable
;
2387 if ((NewFilter
& EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
) != 0) {
2388 if ((MCastFilterCnt
== 0) || (MCastFilter
== 0) || MCastFilterCnt
> SimpleNetworkDevice
->SimpleNetworkMode
.MaxMCastFilterCount
) {
2389 return EFI_INVALID_PARAMETER
;
2393 // Call 16 bit UNDI ROM to close the network interface
2395 Close
.Status
= INIT_PXE_STATUS
;
2397 Status
= PxeUndiClose (SimpleNetworkDevice
, &Close
);
2399 if (EFI_ERROR (Status
)) {
2403 // Check the status code from the 16 bit UNDI ROM
2405 if (Close
.Status
!= PXENV_STATUS_SUCCESS
) {
2406 return EFI_DEVICE_ERROR
;
2409 // Call 16 bit UNDI ROM to open the network interface
2412 // Reset the recycled transmit buffer FIFO
2414 SimpleNetworkDevice
->TxBufferFifo
.First
= 0;
2415 SimpleNetworkDevice
->TxBufferFifo
.Last
= 0;
2418 // Call 16 bit UNDI ROM to open the network interface
2420 ZeroMem (&Open
, sizeof Open
);
2422 Open
.Status
= INIT_PXE_STATUS
;
2423 Open
.PktFilter
= Undi16GetPacketFilterSetting (NewFilter
);
2425 if ((NewFilter
& EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
) != 0) {
2427 // Copy the MAC addresses into the UNDI open parameter structure
2429 Open
.McastBuffer
.MCastAddrCount
= (UINT16
) MCastFilterCnt
;
2430 for (Index
= 0; Index
< MCastFilterCnt
; ++Index
) {
2432 Open
.McastBuffer
.MCastAddr
[Index
],
2433 &MCastFilter
[Index
],
2434 sizeof Open
.McastBuffer
.MCastAddr
[Index
]
2437 } else if (!ResetMCastFilter
) {
2438 for (Index
= 0; Index
< SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilterCount
; ++Index
) {
2440 Open
.McastBuffer
.MCastAddr
[Index
],
2441 &SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilter
[Index
],
2442 sizeof Open
.McastBuffer
.MCastAddr
[Index
]
2447 Status
= PxeUndiOpen (SimpleNetworkDevice
, &Open
);
2449 if (EFI_ERROR (Status
)) {
2453 // Check the status code from the 16 bit UNDI ROM
2455 if (Open
.Status
!= PXENV_STATUS_SUCCESS
) {
2456 return EFI_DEVICE_ERROR
;
2459 SimpleNetworkDevice
->IsrValid
= FALSE
;
2460 SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
= NewFilter
;
2462 if ((NewFilter
& EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
) != 0) {
2463 SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilterCount
= (UINT32
) MCastFilterCnt
;
2464 for (Index
= 0; Index
< MCastFilterCnt
; ++Index
) {
2466 &SimpleNetworkDevice
->SimpleNetworkMode
.MCastFilter
[Index
],
2467 &MCastFilter
[Index
],
2468 sizeof (EFI_MAC_ADDRESS
)
2473 // Read back multicast addresses.
2481 Set new MAC address.
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
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.
2495 Undi16SimpleNetworkStationAddress (
2496 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
2498 IN EFI_MAC_ADDRESS
* New OPTIONAL
2502 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2503 PXENV_UNDI_SET_STATION_ADDR_T SetStationAddr
;
2505 // EFI_DEVICE_PATH_PROTOCOL *OldDevicePath;
2507 PXENV_UNDI_CLOSE_T Close
;
2508 PXENV_UNDI_OPEN_T Open
;
2511 return EFI_INVALID_PARAMETER
;
2514 Status
= EFI_SUCCESS
;
2516 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2518 if (SimpleNetworkDevice
== NULL
) {
2519 return EFI_DEVICE_ERROR
;
2522 // Verify that the current state of the adapter is valid for this call.
2524 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2525 case EfiSimpleNetworkInitialized
:
2528 case EfiSimpleNetworkStopped
:
2529 return EFI_NOT_STARTED
;
2531 case EfiSimpleNetworkStarted
:
2533 return EFI_DEVICE_ERROR
;
2536 // Call 16 bit UNDI ROM to open the network interface
2538 SetStationAddr
.Status
= INIT_PXE_STATUS
;
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.
2545 if (!SimpleNetworkDevice
->SimpleNetworkMode
.MacAddressChangeable
) {
2549 // If the address is already the permanent address, then just return success.
2552 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
2553 &SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
,
2554 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2559 // Copy the adapters permanent address to the new station address
2562 &SetStationAddr
.StationAddress
,
2563 &SimpleNetworkDevice
->SimpleNetworkMode
.PermanentAddress
,
2564 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2568 // If we are setting the Station Address, and the
2569 // Station Address is not programmable, return invalid parameter.
2571 if (!SimpleNetworkDevice
->SimpleNetworkMode
.MacAddressChangeable
) {
2572 return EFI_INVALID_PARAMETER
;
2575 // If the address is already the new address, then just return success.
2578 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
2580 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2585 // Copy New to the new station address
2588 &SetStationAddr
.StationAddress
,
2590 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2595 // Call 16 bit UNDI ROM to stop the network interface
2597 Close
.Status
= INIT_PXE_STATUS
;
2599 PxeUndiClose (SimpleNetworkDevice
, &Close
);
2602 // Call 16-bit UNDI ROM to set the station address
2604 SetStationAddr
.Status
= PXENV_STATUS_SUCCESS
;
2606 Status
= PxeUndiSetStationAddr (SimpleNetworkDevice
, &SetStationAddr
);
2609 // Call 16-bit UNDI ROM to start the network interface
2611 Open
.Status
= PXENV_STATUS_SUCCESS
;
2613 Open
.PktFilter
= Undi16GetPacketFilterSetting (SimpleNetworkDevice
->SimpleNetworkMode
.ReceiveFilterSetting
);
2614 Undi16GetMCastFilters (
2615 &SimpleNetworkDevice
->SimpleNetworkMode
,
2617 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2620 PxeUndiOpen (SimpleNetworkDevice
, &Open
);
2623 // Check status from station address change
2625 if (EFI_ERROR (Status
)) {
2629 // Check the status code from the 16 bit UNDI ROM
2631 if (SetStationAddr
.Status
!= PXENV_STATUS_SUCCESS
) {
2632 return EFI_DEVICE_ERROR
;
2636 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
,
2637 &SetStationAddr
.StationAddress
,
2638 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2641 #if 0 /* The device path is based on the permanent address not the current address. */
2643 // The station address was changed, so update the device path with the new MAC address.
2645 OldDevicePath
= SimpleNetworkDevice
->DevicePath
;
2646 SimpleNetworkDevice
->DevicePath
= DuplicateDevicePath (SimpleNetworkDevice
->BaseDevicePath
);
2647 SimpleNetworkAppendMacAddressDevicePath (
2648 &SimpleNetworkDevice
->DevicePath
,
2649 &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
2652 Status
= LibReinstallProtocolInterfaces (
2653 SimpleNetworkDevice
->Handle
,
2654 &DevicePathProtocol
,
2656 SimpleNetworkDevice
->DevicePath
,
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
));
2665 FreePool (OldDevicePath
);
2674 Resets or collects the statistics on a network interface.
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
2681 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
2682 contains the statistics.
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
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.
2696 Undi16SimpleNetworkStatistics (
2697 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
2699 IN OUT UINTN
*StatisticsSize OPTIONAL
,
2700 OUT EFI_NETWORK_STATISTICS
* StatisticsTable OPTIONAL
2704 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2705 PXENV_UNDI_CLEAR_STATISTICS_T ClearStatistics
;
2706 PXENV_UNDI_GET_STATISTICS_T GetStatistics
;
2709 return EFI_INVALID_PARAMETER
;
2712 Status
= EFI_SUCCESS
;
2713 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2715 if (SimpleNetworkDevice
== NULL
) {
2716 return EFI_DEVICE_ERROR
;
2719 // Verify that the current state of the adapter is valid for this call.
2721 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2722 case EfiSimpleNetworkInitialized
:
2725 case EfiSimpleNetworkStopped
:
2726 return EFI_NOT_STARTED
;
2728 case EfiSimpleNetworkStarted
:
2730 return EFI_DEVICE_ERROR
;
2733 if ((StatisticsSize
!= NULL
) && (*StatisticsSize
!= 0) && (StatisticsTable
== NULL
)) {
2734 return EFI_INVALID_PARAMETER
;
2738 // If Reset is TRUE, then clear all the statistics.
2742 DEBUG ((DEBUG_NET
, " RESET Statistics\n"));
2745 // Call 16 bit UNDI ROM to open the network interface
2747 ClearStatistics
.Status
= INIT_PXE_STATUS
;
2749 Status
= PxeUndiClearStatistics (SimpleNetworkDevice
, &ClearStatistics
);
2751 if (EFI_ERROR (Status
)) {
2755 // Check the status code from the 16 bit UNDI ROM
2757 if (ClearStatistics
.Status
!= PXENV_STATUS_SUCCESS
) {
2758 return EFI_DEVICE_ERROR
;
2761 DEBUG ((DEBUG_NET
, " RESET Statistics Complete"));
2764 if (StatisticsSize
!= NULL
) {
2765 EFI_NETWORK_STATISTICS LocalStatisticsTable
;
2767 DEBUG ((DEBUG_NET
, " GET Statistics\n"));
2770 // If the size if valid, then see if the table is valid
2772 if (StatisticsTable
== NULL
) {
2773 DEBUG ((DEBUG_NET
, " StatisticsTable is NULL\n"));
2774 return EFI_INVALID_PARAMETER
;
2777 // Call 16 bit UNDI ROM to open the network interface
2779 GetStatistics
.Status
= INIT_PXE_STATUS
;
2780 GetStatistics
.XmtGoodFrames
= 0;
2781 GetStatistics
.RcvGoodFrames
= 0;
2782 GetStatistics
.RcvCRCErrors
= 0;
2783 GetStatistics
.RcvResourceErrors
= 0;
2785 Status
= PxeUndiGetStatistics (SimpleNetworkDevice
, &GetStatistics
);
2787 if (EFI_ERROR (Status
)) {
2791 // Check the status code from the 16 bit UNDI ROM
2793 if (GetStatistics
.Status
!= PXENV_STATUS_SUCCESS
) {
2794 return EFI_DEVICE_ERROR
;
2797 // Fill in the Statistics Table with the collected values.
2799 SetMem (&LocalStatisticsTable
, sizeof LocalStatisticsTable
, 0xff);
2801 LocalStatisticsTable
.TxGoodFrames
= GetStatistics
.XmtGoodFrames
;
2802 LocalStatisticsTable
.RxGoodFrames
= GetStatistics
.RcvGoodFrames
;
2803 LocalStatisticsTable
.RxCrcErrorFrames
= GetStatistics
.RcvCRCErrors
;
2804 LocalStatisticsTable
.RxDroppedFrames
= GetStatistics
.RcvResourceErrors
;
2806 CopyMem (StatisticsTable
, &LocalStatisticsTable
, *StatisticsSize
);
2810 " Statistics Collected : Size=%d Buf=%08x\n",
2815 DEBUG ((DEBUG_NET
, " GET Statistics Complete"));
2817 if (*StatisticsSize
< sizeof LocalStatisticsTable
) {
2818 DEBUG ((DEBUG_NET
, " BUFFER TOO SMALL\n"));
2819 Status
= EFI_BUFFER_TOO_SMALL
;
2822 *StatisticsSize
= sizeof LocalStatisticsTable
;
2834 Translate IP address to MAC address.
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.
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.
2852 Undi16SimpleNetworkMCastIpToMac (
2853 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
2855 IN EFI_IP_ADDRESS
*IP
,
2856 OUT EFI_MAC_ADDRESS
*MAC
2860 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2861 PXENV_UNDI_GET_MCAST_ADDR_T GetMcastAddr
;
2863 if (This
== NULL
|| IP
== NULL
|| MAC
== NULL
) {
2864 return EFI_INVALID_PARAMETER
;
2867 Status
= EFI_SUCCESS
;
2868 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
2870 if (SimpleNetworkDevice
== NULL
) {
2871 return EFI_DEVICE_ERROR
;
2874 // Verify that the current state of the adapter is valid for this call.
2876 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
2877 case EfiSimpleNetworkStopped
:
2878 return EFI_NOT_STARTED
;
2880 case EfiSimpleNetworkInitialized
:
2883 case EfiSimpleNetworkStarted
:
2885 return EFI_DEVICE_ERROR
;
2888 // 16 bit UNDI Option ROMS do not support IPv6. Check for IPv6 usage.
2891 return EFI_UNSUPPORTED
;
2894 // Call 16 bit UNDI ROM to open the network interface
2896 GetMcastAddr
.Status
= INIT_PXE_STATUS
;
2897 CopyMem (&GetMcastAddr
.InetAddr
, IP
, 4);
2899 Status
= PxeUndiGetMcastAddr (SimpleNetworkDevice
, &GetMcastAddr
);
2901 if (EFI_ERROR (Status
)) {
2905 // Check the status code from the 16 bit UNDI ROM
2907 if (GetMcastAddr
.Status
!= PXENV_STATUS_SUCCESS
) {
2908 return EFI_DEVICE_ERROR
;
2911 // Copy the MAC address from the returned data structure.
2915 &GetMcastAddr
.MediaAddr
,
2916 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
2925 Performs read and write operations on the NVRAM device attached to a
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.
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.
2946 Undi16SimpleNetworkNvData (
2947 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
2948 IN BOOLEAN ReadWrite
,
2950 IN UINTN BufferSize
,
2954 return EFI_UNSUPPORTED
;
2960 Reads the current interrupt status and recycled transmit buffer status from
2961 a network interface.
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.
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.
2986 Undi16SimpleNetworkGetStatus (
2987 IN EFI_SIMPLE_NETWORK_PROTOCOL
* This
,
2988 OUT UINT32
*InterruptStatus OPTIONAL
,
2989 OUT VOID
**TxBuf OPTIONAL
2993 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
2997 return EFI_INVALID_PARAMETER
;
3000 Status
= EFI_SUCCESS
;
3001 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
3003 if (SimpleNetworkDevice
== NULL
) {
3004 return EFI_DEVICE_ERROR
;
3007 // Verify that the current state of the adapter is valid for this call.
3009 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
3010 case EfiSimpleNetworkInitialized
:
3013 case EfiSimpleNetworkStopped
:
3014 return EFI_NOT_STARTED
;
3016 case EfiSimpleNetworkStarted
:
3018 return EFI_DEVICE_ERROR
;
3021 if (InterruptStatus
== NULL
&& TxBuf
== NULL
) {
3022 return EFI_INVALID_PARAMETER
;
3026 Status
= Undi16SimpleNetworkIsr (This
, &FrameLength
, NULL
, NULL
, NULL
, NULL
);
3028 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3029 if (EFI_ERROR (Status
)) {
3034 // See if the caller wants interrupt info.
3036 if (InterruptStatus
!= NULL
) {
3037 *InterruptStatus
= SimpleNetworkDevice
->InterruptStatus
;
3038 SimpleNetworkDevice
->InterruptStatus
= 0;
3041 // See if the caller wants transmit buffer status info.
3043 if (TxBuf
!= NULL
) {
3045 SimpleNetworkTransmitFifoRemove (&(SimpleNetworkDevice
->TxBufferFifo
), TxBuf
);
3052 Places a packet in the transmit queue of a network interface.
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
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.
3086 Undi16SimpleNetworkTransmit (
3087 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
3088 IN UINTN HeaderSize
,
3089 IN UINTN BufferSize
,
3091 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
3092 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
3093 IN UINT16
*Protocol OPTIONAL
3097 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
3098 PXENV_UNDI_TRANSMIT_T XmitInfo
;
3101 return EFI_INVALID_PARAMETER
;
3104 Status
= EFI_SUCCESS
;
3105 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
3107 if (SimpleNetworkDevice
== NULL
) {
3108 return EFI_DEVICE_ERROR
;
3111 // Verify that the current state of the adapter is valid for this call.
3113 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
3114 case EfiSimpleNetworkInitialized
:
3117 case EfiSimpleNetworkStopped
:
3118 return EFI_NOT_STARTED
;
3120 case EfiSimpleNetworkStarted
:
3122 return EFI_DEVICE_ERROR
;
3125 if (Buffer
== NULL
) {
3126 return EFI_INVALID_PARAMETER
;
3129 if (BufferSize
< SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
) {
3130 return EFI_BUFFER_TOO_SMALL
;
3133 if (HeaderSize
!= 0) {
3134 if (HeaderSize
!= SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
) {
3135 return EFI_INVALID_PARAMETER
;
3138 if (DestAddr
== NULL
|| Protocol
== NULL
) {
3139 return EFI_INVALID_PARAMETER
;
3142 if (DestAddr
!= NULL
) {
3146 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
3150 if (SrcAddr
== NULL
) {
3151 SrcAddr
= &SimpleNetworkDevice
->SimpleNetworkMode
.CurrentAddress
;
3155 (UINT8
*) Buffer
+ SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
,
3157 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
3160 if (Protocol
!= NULL
) {
3161 *(UINT16
*) ((UINT8
*) Buffer
+ 2 * SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
) = (UINT16
) (((*Protocol
& 0xFF) << 8) | ((*Protocol
>> 8) & 0xFF));
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.
3169 if (SimpleNetworkTransmitFifoFull (&(SimpleNetworkDevice
->TxBufferFifo
))) {
3170 return EFI_NOT_READY
;
3173 // Output debug trace message.
3175 DEBUG ((DEBUG_NET
, "Undi16SimpleNetworkTransmit\n\r "));
3178 // Initialize UNDI WRITE parameter structure.
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;
3191 SimpleNetworkDevice
->TxDestAddr
,
3193 SimpleNetworkDevice
->SimpleNetworkMode
.HwAddressSize
3197 SimpleNetworkDevice
->TxRealModeMediaHeader
,
3199 SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
3202 SimpleNetworkDevice
->Xmit
->ImmedLength
= (UINT16
) SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
;
3204 SimpleNetworkDevice
->Xmit
->DataBlock
[0].TDDataLen
= (UINT16
) (BufferSize
- SimpleNetworkDevice
->Xmit
->ImmedLength
);
3207 SimpleNetworkDevice
->TxRealModeDataBuffer
,
3208 (UINT8
*) Buffer
+ SimpleNetworkDevice
->SimpleNetworkMode
.MediaHeaderSize
,
3209 SimpleNetworkDevice
->Xmit
->DataBlock
[0].TDDataLen
3213 // Make API call to UNDI TRANSMIT
3215 XmitInfo
.Status
= 0;
3217 Status
= PxeUndiTransmit (SimpleNetworkDevice
, &XmitInfo
);
3219 if (EFI_ERROR (Status
)) {
3223 // Check the status code from the 16 bit UNDI ROM
3225 switch (XmitInfo
.Status
) {
3226 case PXENV_STATUS_OUT_OF_RESOURCES
:
3227 return EFI_NOT_READY
;
3229 case PXENV_STATUS_SUCCESS
:
3233 return EFI_DEVICE_ERROR
;
3236 // Add address of Buffer to the recycled transmit buffer FIFO
3238 SimpleNetworkTransmitFifoAdd (&(SimpleNetworkDevice
->TxBufferFifo
), Buffer
);
3244 Receives a packet from a network interface.
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
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
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
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.
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
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.
3277 Undi16SimpleNetworkReceive (
3278 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
3279 OUT UINTN
*HeaderSize OPTIONAL
,
3280 IN OUT UINTN
*BufferSize
,
3282 OUT EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
3283 OUT EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
3284 OUT UINT16
*Protocol OPTIONAL
3288 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
3289 UINTN MediaAddrSize
;
3292 if (This
== NULL
|| BufferSize
== NULL
|| Buffer
== NULL
) {
3293 return EFI_INVALID_PARAMETER
;
3296 Status
= EFI_SUCCESS
;
3297 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
3299 if (SimpleNetworkDevice
== NULL
) {
3300 return EFI_DEVICE_ERROR
;
3303 // Verify that the current state of the adapter is valid for this call.
3305 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
3306 case EfiSimpleNetworkInitialized
:
3309 case EfiSimpleNetworkStopped
:
3310 return EFI_NOT_STARTED
;
3312 case EfiSimpleNetworkStarted
:
3314 return EFI_DEVICE_ERROR
;
3317 Status
= Undi16SimpleNetworkIsr (
3326 if (EFI_ERROR (Status
)) {
3330 if ((SimpleNetworkDevice
->InterruptStatus
& EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
) == 0) {
3331 return EFI_NOT_READY
;
3335 SimpleNetworkDevice
->InterruptStatus
&= ~EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
;
3337 MediaAddrSize
= This
->Mode
->HwAddressSize
;
3339 if (SrcAddr
!= NULL
) {
3340 CopyMem (SrcAddr
, (UINT8
*) Buffer
+ MediaAddrSize
, MediaAddrSize
);
3343 if (DestAddr
!= NULL
) {
3344 CopyMem (DestAddr
, Buffer
, MediaAddrSize
);
3347 if (Protocol
!= NULL
) {
3348 *((UINT8
*) Protocol
) = *((UINT8
*) Buffer
+ (2 * MediaAddrSize
) + 1);
3349 *((UINT8
*) Protocol
+ 1) = *((UINT8
*) Buffer
+ (2 * MediaAddrSize
));
3352 DEBUG ((DEBUG_NET
, "Packet Received: BufferSize=%d HeaderSize = %d\n", *BufferSize
, *HeaderSize
));
3361 wait for a packet to be received.
3363 @param Event Event used with WaitForEvent() to wait for a packet to be received.
3364 @param Context Event Context
3369 Undi16SimpleNetworkWaitForPacket (
3375 // Someone is waiting on the receive packet event, if there's
3376 // a packet pending, signal the event
3378 if (!EFI_ERROR (Undi16SimpleNetworkCheckForPacket (Context
))) {
3379 gBS
->SignalEvent (Event
);
3386 Check whether packet is ready for receive.
3388 @param This The protocol instance pointer.
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
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.
3400 Undi16SimpleNetworkCheckForPacket (
3401 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
3405 EFI_SIMPLE_NETWORK_DEV
*SimpleNetworkDevice
;
3409 return EFI_INVALID_PARAMETER
;
3412 Status
= EFI_SUCCESS
;
3413 SimpleNetworkDevice
= EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This
);
3415 if (SimpleNetworkDevice
== NULL
) {
3416 return EFI_DEVICE_ERROR
;
3419 // Verify that the current state of the adapter is valid for this call.
3421 switch (SimpleNetworkDevice
->SimpleNetworkMode
.State
) {
3422 case EfiSimpleNetworkInitialized
:
3425 case EfiSimpleNetworkStopped
:
3426 return EFI_NOT_STARTED
;
3428 case EfiSimpleNetworkStarted
:
3430 return EFI_DEVICE_ERROR
;
3434 Status
= Undi16SimpleNetworkIsr (
3443 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
3444 if (EFI_ERROR (Status
)) {
3449 return ((SimpleNetworkDevice
->InterruptStatus
& EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT
) != 0) ? EFI_SUCCESS
: EFI_NOT_READY
;
3453 Signal handlers for ExitBootServices event.
3455 Clean up any Real-mode UNDI residue from the system
3457 @param Event ExitBootServices event
3462 Undi16SimpleNetworkEvent (
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.
3474 RestoreCachedVectorAddress (0x1A);
3478 Allocate buffer below 1M for real mode.
3480 @param NumPages The number pages want to be allocated.
3481 @param Buffer On return, allocated buffer.
3483 @return Status of allocating pages.
3486 BiosSnp16AllocatePagesBelowOneMb (
3492 EFI_PHYSICAL_ADDRESS PhysicalAddress
;
3494 PhysicalAddress
= 0x000fffff;
3495 Status
= gBS
->AllocatePages (
3497 EfiRuntimeServicesData
,
3501 if (EFI_ERROR (Status
)) {
3505 *Buffer
= (VOID
*) (UINTN
) PhysicalAddress
;