2008-02-20 03:35:04 +01:00
|
|
|
/** @file
|
2008-11-13 04:42:21 +01:00
|
|
|
Implementation of initializing a network adapter.
|
|
|
|
|
|
|
|
Copyright (c) 2004 - 2008, Intel Corporation. <BR>
|
|
|
|
All rights reserved. This program and the accompanying materials are licensed
|
|
|
|
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:35:04 +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"
|
|
|
|
|
|
|
|
/**
|
|
|
|
this routine calls undi to initialize the interface.
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@param Snp pointer to snp driver structure
|
|
|
|
@param CableDetectFlag Do/don't detect the cable (depending on what undi supports)
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS UNDI is initialized successfully
|
|
|
|
@retval EFI_DEVICE_ERROR UNDI could not be initialized
|
|
|
|
@retval Other other errors
|
2008-02-20 03:35:04 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeInit (
|
|
|
|
SNP_DRIVER *Snp,
|
2008-02-20 03:35:04 +01:00
|
|
|
UINT16 CableDetectFlag
|
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
PXE_CPB_INITIALIZE *Cpb;
|
|
|
|
VOID *Addr;
|
2008-02-20 03:35:04 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb = Snp->Cpb;
|
|
|
|
if (Snp->TxRxBufferSize != 0) {
|
|
|
|
Status = Snp->PciIo->AllocateBuffer (
|
|
|
|
Snp->PciIo,
|
|
|
|
AllocateAnyPages,
|
|
|
|
EfiBootServicesData,
|
|
|
|
SNP_MEM_PAGES (Snp->TxRxBufferSize),
|
|
|
|
&Addr,
|
|
|
|
0
|
|
|
|
);
|
2008-02-20 03:35:04 +01:00
|
|
|
|
|
|
|
if (Status != EFI_SUCCESS) {
|
|
|
|
DEBUG (
|
|
|
|
(EFI_D_ERROR,
|
2008-11-13 04:42:21 +01:00
|
|
|
"\nSnp->PxeInit() AllocateBuffer %xh (%r)\n",
|
2008-02-20 03:35:04 +01:00
|
|
|
Status,
|
|
|
|
Status)
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
ASSERT (Addr);
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->TxRxBuffer = Addr;
|
2008-02-20 03:35:04 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->MemoryAddr = (UINT64)(UINTN) Snp->TxRxBuffer;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->MemoryLength = Snp->TxRxBufferSize;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// let UNDI decide/detect these values
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->LinkSpeed = 0;
|
|
|
|
Cpb->TxBufCnt = 0;
|
|
|
|
Cpb->TxBufSize = 0;
|
|
|
|
Cpb->RxBufCnt = 0;
|
|
|
|
Cpb->RxBufSize = 0;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->DuplexMode = PXE_DUPLEX_DEFAULT;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->LoopBackMode = LOOPBACK_NORMAL;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.OpCode = PXE_OPCODE_INITIALIZE;
|
|
|
|
Snp->Cdb.OpFlags = CableDetectFlag;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.CPBsize = sizeof (PXE_CPB_INITIALIZE);
|
|
|
|
Snp->Cdb.DBsize = sizeof (PXE_DB_INITIALIZE);
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.CPBaddr = (UINT64)(UINTN) Snp->Cpb;
|
|
|
|
Snp->Cdb.DBaddr = (UINT64)(UINTN) Snp->Db;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
|
|
|
|
Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
|
|
|
|
Snp->Cdb.IFnum = Snp->IfNum;
|
|
|
|
Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->undi.initialize() "));
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
(*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp->Cdb.StatCode == PXE_STATCODE_SUCCESS) {
|
|
|
|
Snp->Mode.State = EfiSimpleNetworkInitialized;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
DEBUG (
|
|
|
|
(EFI_D_WARN,
|
2008-11-13 04:42:21 +01:00
|
|
|
"\nSnp->undi.initialize() %xh:%xh\n",
|
|
|
|
Snp->Cdb.StatFlags,
|
|
|
|
Snp->Cdb.StatCode)
|
2008-02-20 03:35:04 +01:00
|
|
|
);
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp->TxRxBuffer != NULL) {
|
|
|
|
Snp->PciIo->FreeBuffer (
|
|
|
|
Snp->PciIo,
|
|
|
|
SNP_MEM_PAGES (Snp->TxRxBufferSize),
|
|
|
|
(VOID *) Snp->TxRxBuffer
|
2008-02-20 03:35:04 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->TxRxBuffer = NULL;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = EFI_DEVICE_ERROR;
|
2008-02-20 03:35:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-11-13 04:42:21 +01:00
|
|
|
Resets a network adapter and allocates the transmit and receive buffers
|
|
|
|
required by the network interface; optionally, also requests allocation of
|
|
|
|
additional transmit and receive buffers.
|
|
|
|
|
|
|
|
This function allocates the transmit and receive buffers required by the network
|
|
|
|
interface. If this allocation fails, then EFI_OUT_OF_RESOURCES is returned.
|
|
|
|
If the allocation succeeds and the network interface is successfully initialized,
|
|
|
|
then EFI_SUCCESS will be returned.
|
|
|
|
|
|
|
|
@param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
|
|
|
|
|
|
|
|
@param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
|
|
|
|
that the driver should allocate for the network interface.
|
|
|
|
Some network interfaces will not be able to use the
|
|
|
|
extra buffer, and the caller will not know if it is
|
|
|
|
actually being used.
|
|
|
|
@param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
|
|
|
|
that the driver should allocate for the network interface.
|
|
|
|
Some network interfaces will not be able to use the
|
|
|
|
extra buffer, and the caller will not know if it is
|
|
|
|
actually being used.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The network interface was initialized.
|
|
|
|
@retval EFI_NOT_STARTED The network interface has not been started.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES There was not enough memory for the transmit and
|
|
|
|
receive buffers.
|
|
|
|
@retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid
|
|
|
|
EFI_SIMPLE_NETWORK_PROTOCOL structure.
|
|
|
|
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
|
|
|
@retval EFI_UNSUPPORTED The increased buffer size feature is not supported.
|
2008-02-20 03:35:04 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32Initialize (
|
|
|
|
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
|
|
|
IN UINTN ExtraRxBufferSize OPTIONAL,
|
|
|
|
IN UINTN ExtraTxBufferSize OPTIONAL
|
2008-02-20 03:35:04 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS EfiStatus;
|
2008-11-13 04:42:21 +01:00
|
|
|
SNP_DRIVER *Snp;
|
2008-02-20 03:35:04 +01:00
|
|
|
EFI_TPL OldTpl;
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (This == NULL) {
|
2008-02-20 03:35:04 +01:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
|
2008-02-20 03:35:04 +01:00
|
|
|
|
|
|
|
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp == NULL) {
|
2008-02-20 03:35:04 +01:00
|
|
|
EfiStatus = EFI_INVALID_PARAMETER;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
switch (Snp->Mode.State) {
|
2008-02-20 03:35:04 +01:00
|
|
|
case EfiSimpleNetworkStarted:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiSimpleNetworkStopped:
|
|
|
|
EfiStatus = EFI_NOT_STARTED;
|
|
|
|
goto ON_EXIT;
|
|
|
|
|
|
|
|
default:
|
|
|
|
EfiStatus = EFI_DEVICE_ERROR;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
EfiStatus = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_WAIT,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
&SnpWaitForPacketNotify,
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp,
|
|
|
|
&Snp->Snp.WaitForPacket
|
2008-02-20 03:35:04 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (EfiStatus)) {
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Snp.WaitForPacket = NULL;
|
2008-02-20 03:35:04 +01:00
|
|
|
EfiStatus = EFI_DEVICE_ERROR;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.MCastFilterCount = 0;
|
|
|
|
Snp->Mode.ReceiveFilterSetting = 0;
|
|
|
|
ZeroMem (Snp->Mode.MCastFilter, sizeof Snp->Mode.MCastFilter);
|
2008-02-20 03:35:04 +01:00
|
|
|
CopyMem (
|
2008-11-13 04:42:21 +01:00
|
|
|
&Snp->Mode.CurrentAddress,
|
|
|
|
&Snp->Mode.PermanentAddress,
|
2008-02-20 03:35:04 +01:00
|
|
|
sizeof (EFI_MAC_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Compute tx/rx buffer sizes based on UNDI init info and parameters.
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->TxRxBufferSize = (UINT32) (Snp->InitInfo.MemoryRequired + ExtraRxBufferSize + ExtraTxBufferSize);
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp->Mode.MediaPresentSupported) {
|
|
|
|
if (PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) {
|
|
|
|
Snp->Mode.MediaPresent = TRUE;
|
2008-02-20 03:35:04 +01:00
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Mode.MediaPresent = FALSE;
|
2008-02-20 03:35:04 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
EfiStatus = PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE);
|
2008-02-20 03:35:04 +01:00
|
|
|
|
|
|
|
if (EFI_ERROR (EfiStatus)) {
|
2008-11-13 04:42:21 +01:00
|
|
|
gBS->CloseEvent (Snp->Snp.WaitForPacket);
|
2008-02-20 03:35:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
|
|
|
|
return EfiStatus;
|
|
|
|
}
|