2008-02-20 03:38:48 +01:00
|
|
|
/** @file
|
2009-06-29 11:19:25 +02:00
|
|
|
Implementation of driver entry point and driver binding protocol.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2011-07-04 09:33:34 +02:00
|
|
|
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:33:45 +02:00
|
|
|
This program and the accompanying materials are licensed
|
2010-01-08 03:35:56 +01:00
|
|
|
and made available under the terms and conditions of the BSD License which
|
|
|
|
accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "Snp.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// Module global variables needed to support undi 3.0 interface
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
EFI_PCI_IO_PROTOCOL *mPciIo;
|
|
|
|
V2P *mV2p = NULL; // undi3.0 map_list head
|
2008-02-20 03:38:48 +01:00
|
|
|
// End Global variables
|
|
|
|
//
|
|
|
|
|
2009-04-10 10:31:45 +02:00
|
|
|
/**
|
|
|
|
One notified function to stop UNDI device when gBS->ExitBootServices() called.
|
|
|
|
|
|
|
|
@param Event Pointer to this event
|
|
|
|
@param Context Event hanlder private data
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
SnpNotifyExitBootServices (
|
|
|
|
EFI_EVENT Event,
|
|
|
|
VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SNP_DRIVER *Snp;
|
|
|
|
|
|
|
|
Snp = (SNP_DRIVER *)Context;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Shutdown and stop UNDI driver
|
|
|
|
//
|
|
|
|
PxeShutdown (Snp);
|
|
|
|
PxeStop (Snp);
|
|
|
|
}
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Send command to UNDI. It does nothing currently.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@param Cdb command to be sent to UNDI.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
|
|
|
@retval EFI_INVALID_PARAMETER The command is 0.
|
|
|
|
@retval EFI_UNSUPPORTED Default return status because it's not
|
2008-12-29 02:16:13 +01:00
|
|
|
supported currently.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-02-20 03:38:48 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-11-13 04:42:21 +01:00
|
|
|
IssueHwUndiCommand (
|
|
|
|
UINT64 Cdb
|
2008-02-20 03:38:48 +01:00
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "\nIssueHwUndiCommand() - This should not be called!"));
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Cdb == 0) {
|
2008-02-20 03:38:48 +01:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// %%TBD - For now, nothing is done.
|
|
|
|
//
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Compute 8-bit checksum of a buffer.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@param Buffer Pointer to buffer.
|
|
|
|
@param Length Length of buffer in bytes.
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2010-01-08 03:35:56 +01:00
|
|
|
@return 8-bit checksum of all bytes in buffer, or zero if ptr is NULL or len
|
2008-12-29 02:16:13 +01:00
|
|
|
is zero.
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
UINT8
|
2008-11-13 04:42:21 +01:00
|
|
|
Calc8BitCksum (
|
|
|
|
VOID *Buffer,
|
|
|
|
UINTN Length
|
2008-02-20 03:38:48 +01:00
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
UINT8 *Ptr;
|
|
|
|
UINT8 Cksum;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Ptr = Buffer;
|
|
|
|
Cksum = 0;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Ptr == NULL || Length == 0) {
|
2008-02-20 03:38:48 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
while (Length-- != 0) {
|
|
|
|
Cksum = (UINT8) (Cksum + *Ptr++);
|
2008-02-20 03:38:48 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
return Cksum;
|
2008-02-20 03:38:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-11-13 04:42:21 +01:00
|
|
|
Test to see if this driver supports ControllerHandle. This service
|
|
|
|
is called by the EFI boot service ConnectController(). In
|
|
|
|
order to make drivers as small as possible, there are a few calling
|
|
|
|
restrictions for this service. ConnectController() must
|
|
|
|
follow these calling restrictions. If any other agent wishes to call
|
|
|
|
Supported() it must also follow these calling restrictions.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
2008-12-29 02:16:13 +01:00
|
|
|
@param ControllerHandle Handle of device to test.
|
2008-11-13 04:42:21 +01:00
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@retval EFI_SUCCESS This driver supports this device.
|
|
|
|
@retval EFI_ALREADY_STARTED This driver is already running on this device.
|
|
|
|
@retval other This driver does not support this device.
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SimpleNetworkDriverSupported (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *NiiProtocol;
|
2008-11-13 04:42:21 +01:00
|
|
|
PXE_UNDI *Pxe;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiNetworkInterfaceIdentifierProtocolGuid_31,
|
|
|
|
(VOID **) &NiiProtocol,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
if (Status == EFI_ALREADY_STARTED) {
|
2008-10-27 11:13:00 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "Support(): Already Started. on handle %p\n", Controller));
|
2008-02-20 03:38:48 +01:00
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-10-27 11:13:00 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "Support(): UNDI3.1 found on handle %p\n", Controller));
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// check the version, we don't want to connect to the undi16
|
|
|
|
//
|
|
|
|
if (NiiProtocol->Type != EfiNetworkInterfaceUndi) {
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Check to see if !PXE structure is valid. Paragraph alignment of !PXE structure is required.
|
|
|
|
//
|
2010-01-08 03:35:56 +01:00
|
|
|
if ((NiiProtocol->Id & 0x0F) != 0) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\n!PXE structure is not paragraph aligned.\n"));
|
2008-02-20 03:38:48 +01:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2009-04-20 07:47:57 +02:00
|
|
|
Pxe = (PXE_UNDI *) (UINTN) (NiiProtocol->Id);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Verify !PXE revisions.
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Pxe->hw.Signature != PXE_ROMID_SIGNATURE) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\n!PXE signature is not valid.\n"));
|
2008-02-20 03:38:48 +01:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Pxe->hw.Rev < PXE_ROMID_REV) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\n!PXE.Rev is not supported.\n"));
|
2008-02-20 03:38:48 +01:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Pxe->hw.MajorVer < PXE_ROMID_MAJORVER) {
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\n!PXE.MajorVer is not supported.\n"));
|
2008-02-20 03:38:48 +01:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
} else if (Pxe->hw.MajorVer == PXE_ROMID_MAJORVER && Pxe->hw.MinorVer < PXE_ROMID_MINORVER) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\n!PXE.MinorVer is not supported."));
|
2008-02-20 03:38:48 +01:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Do S/W UNDI specific checks.
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) == 0) {
|
|
|
|
if (Pxe->sw.EntryPoint < Pxe->sw.Len) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\n!PXE S/W entry point is not valid."));
|
2008-02-20 03:38:48 +01:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Pxe->sw.BusCnt == 0) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\n!PXE.BusCnt is zero."));
|
2008-02-20 03:38:48 +01:00
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
2008-10-27 11:13:00 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "Support(): supported on %p\n", Controller));
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
Done:
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiNetworkInterfaceIdentifierProtocolGuid_31,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-11-13 04:42:21 +01:00
|
|
|
Start this driver on ControllerHandle. This service is called by the
|
|
|
|
EFI boot service ConnectController(). In order to make
|
|
|
|
drivers as small as possible, there are a few calling restrictions for
|
|
|
|
this service. ConnectController() must follow these
|
|
|
|
calling restrictions. If any other agent wishes to call Start() it
|
|
|
|
must also follow these calling restrictions.
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
2008-11-13 04:42:21 +01:00
|
|
|
@param ControllerHandle Handle of device to bind driver to.
|
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@retval EFI_SUCCESS This driver is added to ControllerHandle
|
|
|
|
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
|
|
|
|
@retval other This driver does not support this device
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SimpleNetworkDriverStart (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *NiiDevicePath;
|
|
|
|
EFI_STATUS Status;
|
2008-11-13 04:42:21 +01:00
|
|
|
PXE_UNDI *Pxe;
|
|
|
|
SNP_DRIVER *Snp;
|
|
|
|
VOID *Address;
|
2008-02-20 03:38:48 +01:00
|
|
|
EFI_HANDLE Handle;
|
|
|
|
PXE_PCI_CONFIG_INFO ConfigInfo;
|
|
|
|
PCI_TYPE00 *ConfigHeader;
|
|
|
|
UINT32 *TempBar;
|
|
|
|
UINT8 BarIndex;
|
|
|
|
PXE_STATFLAGS InitStatFlags;
|
|
|
|
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nSnpNotifyNetworkInterfaceIdentifier() "));
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
(VOID **) &NiiDevicePath,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->LocateDevicePath (
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
&NiiDevicePath,
|
|
|
|
&Handle
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Handle,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
2008-11-13 04:42:21 +01:00
|
|
|
(VOID **) &mPciIo,
|
2008-02-20 03:38:48 +01:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Get the NII interface.
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiNetworkInterfaceIdentifierProtocolGuid_31,
|
|
|
|
(VOID **) &Nii,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG ((EFI_D_INFO, "Start(): UNDI3.1 found\n"));
|
|
|
|
|
2009-04-20 07:47:57 +02:00
|
|
|
Pxe = (PXE_UNDI *) (UINTN) (Nii->Id);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Calc8BitCksum (Pxe, Pxe->hw.Len) != 0) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\n!PXE checksum is not correct.\n"));
|
2008-02-20 03:38:48 +01:00
|
|
|
goto NiiError;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) {
|
2008-02-20 03:38:48 +01:00
|
|
|
//
|
|
|
|
// We can get any packets.
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
} else if ((Pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) {
|
2008-02-20 03:38:48 +01:00
|
|
|
//
|
|
|
|
// We need to be able to get broadcast packets for DHCP.
|
|
|
|
// If we do not have promiscuous support, we must at least have
|
|
|
|
// broadcast support or we cannot do DHCP!
|
|
|
|
//
|
|
|
|
} else {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nUNDI does not have promiscuous or broadcast support."));
|
2008-02-20 03:38:48 +01:00
|
|
|
goto NiiError;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// OK, we like this UNDI, and we know snp is not already there on this handle
|
|
|
|
// Allocate and initialize a new simple network protocol structure.
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = mPciIo->AllocateBuffer (
|
|
|
|
mPciIo,
|
2008-02-20 03:38:48 +01:00
|
|
|
AllocateAnyPages,
|
|
|
|
EfiBootServicesData,
|
|
|
|
SNP_MEM_PAGES (sizeof (SNP_DRIVER)),
|
2008-11-13 04:42:21 +01:00
|
|
|
&Address,
|
2008-02-20 03:38:48 +01:00
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
if (Status != EFI_SUCCESS) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nCould not allocate SNP_DRIVER structure.\n"));
|
2008-02-20 03:38:48 +01:00
|
|
|
goto NiiError;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp = (SNP_DRIVER *) (UINTN) Address;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
ZeroMem (Snp, sizeof (SNP_DRIVER));
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->PciIo = mPciIo;
|
|
|
|
Snp->Signature = SNP_DRIVER_SIGNATURE;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
EfiInitializeLock (&Snp->Lock, TPL_NOTIFY);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Snp.Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION;
|
|
|
|
Snp->Snp.Start = SnpUndi32Start;
|
|
|
|
Snp->Snp.Stop = SnpUndi32Stop;
|
|
|
|
Snp->Snp.Initialize = SnpUndi32Initialize;
|
|
|
|
Snp->Snp.Reset = SnpUndi32Reset;
|
|
|
|
Snp->Snp.Shutdown = SnpUndi32Shutdown;
|
|
|
|
Snp->Snp.ReceiveFilters = SnpUndi32ReceiveFilters;
|
|
|
|
Snp->Snp.StationAddress = SnpUndi32StationAddress;
|
|
|
|
Snp->Snp.Statistics = SnpUndi32Statistics;
|
|
|
|
Snp->Snp.MCastIpToMac = SnpUndi32McastIpToMac;
|
|
|
|
Snp->Snp.NvData = SnpUndi32NvData;
|
|
|
|
Snp->Snp.GetStatus = SnpUndi32GetStatus;
|
|
|
|
Snp->Snp.Transmit = SnpUndi32Transmit;
|
|
|
|
Snp->Snp.Receive = SnpUndi32Receive;
|
|
|
|
Snp->Snp.WaitForPacket = NULL;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Snp.Mode = &Snp->Mode;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->TxRxBufferSize = 0;
|
|
|
|
Snp->TxRxBuffer = NULL;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->IfNum = Nii->IfNum;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) != 0) {
|
|
|
|
Snp->IsSwUndi = FALSE;
|
|
|
|
Snp->IssueUndi32Command = &IssueHwUndiCommand;
|
2008-02-20 03:38:48 +01:00
|
|
|
} else {
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->IsSwUndi = TRUE;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->sw.Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR) != 0) {
|
|
|
|
Snp->IssueUndi32Command = (ISSUE_UNDI32_COMMAND) (UINTN) Pxe->sw.EntryPoint;
|
2008-02-20 03:38:48 +01:00
|
|
|
} else {
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->IssueUndi32Command = (ISSUE_UNDI32_COMMAND) (UINTN) ((UINT8) (UINTN) Pxe + Pxe->sw.EntryPoint);
|
2008-02-20 03:38:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Allocate a global CPB and DB buffer for this UNDI interface.
|
|
|
|
// we do this because:
|
|
|
|
//
|
|
|
|
// -UNDI 3.0 wants all the addresses passed to it (even the cpb and db) to be
|
|
|
|
// within 2GB limit, create them here and map them so that when undi calls
|
|
|
|
// v2p callback to check if the physical address is < 2gb, we will pass.
|
|
|
|
//
|
|
|
|
// -This is not a requirement for 3.1 or later UNDIs but the code looks
|
|
|
|
// simpler if we use the same cpb, db variables for both old and new undi
|
|
|
|
// interfaces from all the SNP interface calls (we don't map the buffers
|
|
|
|
// for the newer undi interfaces though)
|
|
|
|
// .
|
|
|
|
// -it is OK to allocate one global set of CPB, DB pair for each UNDI
|
|
|
|
// interface as EFI does not multi-task and so SNP will not be re-entered!
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = mPciIo->AllocateBuffer (
|
|
|
|
mPciIo,
|
2008-02-20 03:38:48 +01:00
|
|
|
AllocateAnyPages,
|
|
|
|
EfiBootServicesData,
|
|
|
|
SNP_MEM_PAGES (4096),
|
2008-11-13 04:42:21 +01:00
|
|
|
&Address,
|
2008-02-20 03:38:48 +01:00
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
if (Status != EFI_SUCCESS) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nCould not allocate CPB and DB structures.\n"));
|
2008-02-20 03:38:48 +01:00
|
|
|
goto Error_DeleteSNP;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cpb = (VOID *) (UINTN) Address;
|
|
|
|
Snp->Db = (VOID *) ((UINTN) Address + 2048);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
// PxeStart call is going to give the callback functions to UNDI, these callback
|
2008-02-20 03:38:48 +01:00
|
|
|
// functions use the BarIndex values from the snp structure, so these must be initialized
|
2008-11-13 04:42:21 +01:00
|
|
|
// with default values before doing a PxeStart. The correct values can be obtained after
|
2008-02-20 03:38:48 +01:00
|
|
|
// getting the config information from UNDI
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->MemoryBarIndex = 0;
|
|
|
|
Snp->IoBarIndex = 1;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// we need the undi init information many times in this snp code, just get it
|
|
|
|
// once here and store it in the snp driver structure. to get Init Info
|
|
|
|
// from UNDI we have to start undi first.
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = PxeStart (Snp);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
if (Status != EFI_SUCCESS) {
|
|
|
|
goto Error_DeleteSNP;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.OpCode = PXE_OPCODE_GET_INIT_INFO;
|
|
|
|
Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
|
|
|
|
Snp->Cdb.CPBaddr = PXE_DBADDR_NOT_USED;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2010-09-15 09:48:11 +02:00
|
|
|
Snp->Cdb.DBsize = (UINT16) sizeof (Snp->InitInfo);
|
|
|
|
Snp->Cdb.DBaddr = (UINT64)(UINTN) (&Snp->InitInfo);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
|
|
|
|
Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.IFnum = Snp->IfNum;
|
|
|
|
Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->undi.get_init_info() "));
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
(*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Save the INIT Stat Code...
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
InitStatFlags = Snp->Cdb.StatFlags;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->undi.init_info() %xh:%xh\n", Snp->Cdb.StatFlags, Snp->Cdb.StatCode));
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeStop (Snp);
|
2008-02-20 03:38:48 +01:00
|
|
|
goto Error_DeleteSNP;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.OpCode = PXE_OPCODE_GET_CONFIG_INFO;
|
|
|
|
Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;
|
|
|
|
Snp->Cdb.CPBaddr = PXE_DBADDR_NOT_USED;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2010-09-15 09:48:11 +02:00
|
|
|
Snp->Cdb.DBsize = (UINT16) sizeof (ConfigInfo);
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.DBaddr = (UINT64)(UINTN) &ConfigInfo;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
|
|
|
|
Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.IFnum = Snp->IfNum;
|
|
|
|
Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->undi.get_config_info() "));
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
(*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->undi.config_info() %xh:%xh\n", Snp->Cdb.StatFlags, Snp->Cdb.StatCode));
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeStop (Snp);
|
2008-02-20 03:38:48 +01:00
|
|
|
goto Error_DeleteSNP;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Find the correct BAR to do IO.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Enumerate through the PCI BARs for the device to determine which one is
|
|
|
|
// the IO BAR. Save the index of the BAR into the adapter info structure.
|
|
|
|
// for regular 32bit BARs, 0 is memory mapped, 1 is io mapped
|
|
|
|
//
|
|
|
|
ConfigHeader = (PCI_TYPE00 *) &ConfigInfo.Config.Byte[0];
|
|
|
|
TempBar = (UINT32 *) &ConfigHeader->Device.Bar[0];
|
|
|
|
for (BarIndex = 0; BarIndex <= 5; BarIndex++) {
|
|
|
|
if ((*TempBar & PCI_BAR_MEM_MASK) == PCI_BAR_MEM_64BIT) {
|
|
|
|
//
|
|
|
|
// This is a 64-bit memory bar, skip this and the
|
|
|
|
// next bar as well.
|
|
|
|
//
|
|
|
|
TempBar++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*TempBar & PCI_BAR_IO_MASK) == PCI_BAR_IO_MODE) {
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->IoBarIndex = BarIndex;
|
2008-02-20 03:38:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TempBar++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize simple network protocol mode structure
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.State = EfiSimpleNetworkStopped;
|
|
|
|
Snp->Mode.HwAddressSize = Snp->InitInfo.HWaddrLen;
|
|
|
|
Snp->Mode.MediaHeaderSize = Snp->InitInfo.MediaHeaderLen;
|
|
|
|
Snp->Mode.MaxPacketSize = Snp->InitInfo.FrameDataLen;
|
|
|
|
Snp->Mode.NvRamAccessSize = Snp->InitInfo.NvWidth;
|
|
|
|
Snp->Mode.NvRamSize = Snp->InitInfo.NvCount * Snp->Mode.NvRamAccessSize;
|
|
|
|
Snp->Mode.IfType = Snp->InitInfo.IFtype;
|
|
|
|
Snp->Mode.MaxMCastFilterCount = Snp->InitInfo.MCastFilterCnt;
|
|
|
|
Snp->Mode.MCastFilterCount = 0;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
switch (InitStatFlags & PXE_STATFLAGS_CABLE_DETECT_MASK) {
|
|
|
|
case PXE_STATFLAGS_CABLE_DETECT_SUPPORTED:
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.MediaPresentSupported = TRUE;
|
2008-02-20 03:38:48 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_STATFLAGS_CABLE_DETECT_NOT_SUPPORTED:
|
|
|
|
default:
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.MediaPresentSupported = FALSE;
|
2008-02-20 03:38:48 +01:00
|
|
|
}
|
|
|
|
|
2010-02-12 09:45:15 +01:00
|
|
|
switch (InitStatFlags & PXE_STATFLAGS_GET_STATUS_NO_MEDIA_MASK) {
|
|
|
|
case PXE_STATFLAGS_GET_STATUS_NO_MEDIA_SUPPORTED:
|
|
|
|
Snp->MediaStatusSupported = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_STATFLAGS_GET_STATUS_NO_MEDIA_NOT_SUPPORTED:
|
|
|
|
default:
|
|
|
|
Snp->MediaStatusSupported = FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_STATION_ADDR_SETTABLE) != 0) {
|
|
|
|
Snp->Mode.MacAddressChangeable = TRUE;
|
2008-02-20 03:38:48 +01:00
|
|
|
} else {
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.MacAddressChangeable = FALSE;
|
2008-02-20 03:38:48 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_MULTI_FRAME_SUPPORTED) != 0) {
|
|
|
|
Snp->Mode.MultipleTxSupported = TRUE;
|
2008-02-20 03:38:48 +01:00
|
|
|
} else {
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.MultipleTxSupported = FALSE;
|
2008-02-20 03:38:48 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) != 0) {
|
|
|
|
Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) {
|
|
|
|
Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) {
|
|
|
|
Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED) != 0) {
|
|
|
|
Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-01-08 03:35:56 +01:00
|
|
|
if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) != 0) {
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.ReceiveFilterSetting = 0;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// need to get the station address to save in the mode structure. we need to
|
|
|
|
// initialize the UNDI first for this.
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->TxRxBufferSize = Snp->InitInfo.MemoryRequired;
|
|
|
|
Status = PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
PxeStop (Snp);
|
2008-02-20 03:38:48 +01:00
|
|
|
goto Error_DeleteSNP;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = PxeGetStnAddr (Snp);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
if (Status != EFI_SUCCESS) {
|
2008-12-29 02:16:13 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "\nSnp->undi.get_station_addr() failed.\n"));
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeShutdown (Snp);
|
|
|
|
PxeStop (Snp);
|
2008-02-20 03:38:48 +01:00
|
|
|
goto Error_DeleteSNP;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.MediaPresent = FALSE;
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// We should not leave UNDI started and initialized here. this DriverStart()
|
|
|
|
// routine must only find and attach the SNP interface to UNDI layer that it
|
|
|
|
// finds on the given handle!
|
2008-11-13 04:42:21 +01:00
|
|
|
// The UNDI layer will be started when upper layers call Snp->start.
|
2008-02-20 03:38:48 +01:00
|
|
|
// How ever, this DriverStart() must fill up the snp mode structure which
|
|
|
|
// contains the MAC address of the NIC. For this reason we started and
|
|
|
|
// initialized UNDI here, now we are done, do a shutdown and stop of the
|
|
|
|
// UNDI interface!
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeShutdown (Snp);
|
|
|
|
PxeStop (Snp);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2009-04-10 10:31:45 +02:00
|
|
|
//
|
|
|
|
// Create EXIT_BOOT_SERIVES Event
|
|
|
|
//
|
|
|
|
Status = gBS->CreateEventEx (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
SnpNotifyExitBootServices,
|
|
|
|
Snp,
|
|
|
|
&gEfiEventExitBootServicesGuid,
|
|
|
|
&Snp->ExitBootServicesEvent
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Error_DeleteSNP;
|
|
|
|
}
|
|
|
|
|
2008-02-20 03:38:48 +01:00
|
|
|
//
|
|
|
|
// add SNP to the undi handle
|
|
|
|
//
|
|
|
|
Status = gBS->InstallProtocolInterface (
|
|
|
|
&Controller,
|
|
|
|
&gEfiSimpleNetworkProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
2008-11-13 04:42:21 +01:00
|
|
|
&(Snp->Snp)
|
2008-02-20 03:38:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = mPciIo->FreeBuffer (
|
|
|
|
mPciIo,
|
2008-02-20 03:38:48 +01:00
|
|
|
SNP_MEM_PAGES (4096),
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cpb
|
2008-02-20 03:38:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
Error_DeleteSNP:
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
mPciIo->FreeBuffer (
|
|
|
|
mPciIo,
|
2008-02-20 03:38:48 +01:00
|
|
|
SNP_MEM_PAGES (sizeof (SNP_DRIVER)),
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp
|
2008-02-20 03:38:48 +01:00
|
|
|
);
|
|
|
|
NiiError:
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiNetworkInterfaceIdentifierProtocolGuid_31,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-11-13 04:42:21 +01:00
|
|
|
Stop this driver on ControllerHandle. This service is called by the
|
|
|
|
EFI boot service DisconnectController(). In order to
|
|
|
|
make drivers as small as possible, there are a few calling
|
|
|
|
restrictions for this service. DisconnectController()
|
|
|
|
must follow these calling restrictions. If any other agent wishes
|
|
|
|
to call Stop() it must also follow these calling restrictions.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to stop driver on
|
|
|
|
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
|
|
|
|
children is zero stop the entire bus driver.
|
|
|
|
@param ChildHandleBuffer List of Child Handles to Stop.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver is removed ControllerHandle
|
|
|
|
@retval other This driver was not removed from this device
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
SimpleNetworkDriverStop (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN UINTN NumberOfChildren,
|
|
|
|
IN EFI_HANDLE *ChildHandleBuffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_SIMPLE_NETWORK_PROTOCOL *SnpProtocol;
|
|
|
|
SNP_DRIVER *Snp;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get our context back.
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiSimpleNetworkProtocolGuid,
|
|
|
|
(VOID **) &SnpProtocol,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (SnpProtocol);
|
|
|
|
|
|
|
|
Status = gBS->UninstallProtocolInterface (
|
|
|
|
Controller,
|
|
|
|
&gEfiSimpleNetworkProtocolGuid,
|
2008-11-13 04:42:21 +01:00
|
|
|
&Snp->Snp
|
2008-02-20 03:38:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2009-04-10 10:31:45 +02:00
|
|
|
//
|
|
|
|
// Close EXIT_BOOT_SERIVES Event
|
|
|
|
//
|
|
|
|
gBS->CloseEvent (Snp->ExitBootServicesEvent);
|
|
|
|
|
2008-02-20 03:38:48 +01:00
|
|
|
Status = gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiNetworkInterfaceIdentifierProtocolGuid_31,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
Status = gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeShutdown (Snp);
|
|
|
|
PxeStop (Snp);
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
mPciIo->FreeBuffer (
|
|
|
|
mPciIo,
|
2008-02-20 03:38:48 +01:00
|
|
|
SNP_MEM_PAGES (4096),
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cpb
|
2008-02-20 03:38:48 +01:00
|
|
|
);
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
mPciIo->FreeBuffer (
|
|
|
|
mPciIo,
|
2008-02-20 03:38:48 +01:00
|
|
|
SNP_MEM_PAGES (sizeof (SNP_DRIVER)),
|
|
|
|
Snp
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
//
|
|
|
|
// Simple Network Protocol Driver Global Variables
|
|
|
|
//
|
|
|
|
EFI_DRIVER_BINDING_PROTOCOL mSimpleNetworkDriverBinding = {
|
|
|
|
SimpleNetworkDriverSupported,
|
|
|
|
SimpleNetworkDriverStart,
|
|
|
|
SimpleNetworkDriverStop,
|
|
|
|
0xa,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This routine maps the given CPU address to a Device address. It creates a
|
|
|
|
an entry in the map list with the virtual and physical addresses and the
|
|
|
|
un map cookie.
|
|
|
|
|
|
|
|
@param V2p pointer to return a map list node pointer.
|
|
|
|
@param Type the direction in which the data flows from the given
|
|
|
|
virtual address device->cpu or cpu->device or both
|
|
|
|
ways.
|
|
|
|
@param VirtualAddress virtual address (or CPU address) to be mapped.
|
|
|
|
@param BufferSize size of the buffer to be mapped.
|
|
|
|
|
|
|
|
@retval EFI_SUCEESS routine has completed the mapping.
|
|
|
|
@retval EFI_INVALID_PARAMETER invalid parameter.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES out of resource.
|
|
|
|
@retval other error as indicated.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
AddV2P (
|
|
|
|
IN OUT V2P **V2p,
|
|
|
|
EFI_PCI_IO_PROTOCOL_OPERATION Type,
|
|
|
|
VOID *VirtualAddress,
|
|
|
|
UINTN BufferSize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
if ((V2p == NULL) || (VirtualAddress == NULL) || (BufferSize == 0)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
*V2p = AllocatePool (sizeof (V2P));
|
2009-06-29 11:19:25 +02:00
|
|
|
if (*V2p == NULL) {
|
2008-11-13 04:42:21 +01:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = mPciIo->Map (
|
2008-12-29 02:16:13 +01:00
|
|
|
mPciIo,
|
|
|
|
Type,
|
|
|
|
VirtualAddress,
|
|
|
|
&BufferSize,
|
|
|
|
&(*V2p)->PhysicalAddress,
|
|
|
|
&(*V2p)->Unmap
|
|
|
|
);
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Status != EFI_SUCCESS) {
|
|
|
|
FreePool (*V2p);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
(*V2p)->VirtualAddress = VirtualAddress;
|
2008-12-29 02:16:13 +01:00
|
|
|
(*V2p)->BufferSize = BufferSize;
|
|
|
|
(*V2p)->Next = mV2p;
|
|
|
|
mV2p = *V2p;
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This routine searches the linked list of mapped address nodes (for undi3.0
|
|
|
|
interface) to find the node that corresponds to the given virtual address and
|
|
|
|
returns a pointer to that node.
|
|
|
|
|
|
|
|
@param V2p pointer to return a map list node pointer.
|
|
|
|
@param VirtualAddr virtual address (or CPU address) to be searched in
|
|
|
|
the map list
|
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@retval EFI_SUCEESS A match was found.
|
|
|
|
@retval Other A match cannot be found.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
FindV2p (
|
|
|
|
V2P **V2p,
|
|
|
|
VOID *VirtualAddr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
V2P *Ptr;
|
|
|
|
|
|
|
|
if (V2p == NULL || VirtualAddr == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Ptr = mV2p; Ptr != NULL; Ptr = Ptr->Next) {
|
|
|
|
if (Ptr->VirtualAddress == VirtualAddr) {
|
|
|
|
*V2p = Ptr;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Unmap the given virtual address and free the memory allocated for the map list
|
|
|
|
node corresponding to that address.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@param VirtualAddress virtual address (or CPU address) to be unmapped.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@retval EFI_SUCEESS Successfully unmapped.
|
|
|
|
@retval Other Other errors as indicated.
|
2008-11-13 04:42:21 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
DelV2p (
|
|
|
|
VOID *VirtualAddress
|
|
|
|
)
|
|
|
|
{
|
|
|
|
V2P *Current;
|
|
|
|
V2P *Next;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
if (VirtualAddress == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mV2p == NULL) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Is our node at the head of the list??
|
|
|
|
//
|
|
|
|
if ((Current = mV2p)->VirtualAddress == VirtualAddress) {
|
|
|
|
mV2p = mV2p->Next;
|
|
|
|
|
|
|
|
Status = mPciIo->Unmap (mPciIo, Current->Unmap);
|
|
|
|
|
|
|
|
FreePool (Current);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "Unmap failed with status = %r\n", Status));
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; Current->Next != NULL; Current = Next) {
|
|
|
|
if ((Next = Current->Next)->VirtualAddress == VirtualAddress) {
|
|
|
|
Current->Next = Next->Next;
|
|
|
|
Status = mPciIo->Unmap (mPciIo, Next->Unmap);
|
|
|
|
FreePool (Next);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "Unmap failed with status = %r\n", Status));
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
/**
|
2008-11-13 04:42:21 +01:00
|
|
|
The SNP driver entry point.
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@param ImageHandle The driver image handle.
|
|
|
|
@param SystemTable The system table.
|
2008-02-20 03:38:48 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@retval EFI_SUCEESS Initialization routine has found UNDI hardware,
|
|
|
|
loaded it's ROM, and installed a notify event for
|
|
|
|
the Network Indentifier Interface Protocol
|
|
|
|
successfully.
|
|
|
|
@retval Other Return value from HandleProtocol for
|
|
|
|
DeviceIoProtocol or LoadedImageProtocol
|
2008-02-20 03:38:48 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
InitializeSnpNiiDriver (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return EfiLibInstallDriverBindingComponentName2 (
|
|
|
|
ImageHandle,
|
|
|
|
SystemTable,
|
|
|
|
&mSimpleNetworkDriverBinding,
|
2011-07-04 09:33:34 +02:00
|
|
|
ImageHandle,
|
2008-02-20 03:38:48 +01:00
|
|
|
&gSimpleNetworkComponentName,
|
|
|
|
&gSimpleNetworkComponentName2
|
|
|
|
);
|
|
|
|
}
|