From: niry Date: Thu, 13 Nov 2008 03:42:21 +0000 (+0000) Subject: sync comments, fix function header, rename variable name to follow coding style. X-Git-Tag: edk2-stable201903~19758 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=4cda7726e5fd30aaf3e05c80207ae1b264bfa123 sync comments, fix function header, rename variable name to follow coding style. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6481 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Callback.c b/MdeModulePkg/Universal/Network/SnpDxe/Callback.c index 6dc9943cf6..c4789ba11d 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Callback.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Callback.c @@ -3,7 +3,7 @@ the callback routines for Undi3.1 have an extra parameter UniqueId which stores the interface context for the NIC that snp is trying to talk. -Copyright (c) 2006, Intel Corporation +Copyright (c) 2006 - 2008, Intel Corporation.
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 @@ -28,43 +28,38 @@ EFI_LOCK mLock; // // End Global variables // -extern EFI_PCI_IO_PROTOCOL *mPciIoFncs; +extern EFI_PCI_IO_PROTOCOL *mPciIo; +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine with a virtual or CPU address that SNP provided to + convert it to a physical or device address. Since EFI uses the identical + mapping, this routine returns the physical address same as the virtual address + for most of the addresses. an address above 4GB cannot generally be used as a + device address, it needs to be mapped to a lower physical address. This + routine does not call the map routine itself, but it assumes that the mapping + was done at the time of providing the address to UNDI. This routine just + looks up the address in a map table (which is the v2p structure chain). + + @param CpuAddr virtual address of a buffer. + @param DeviceAddrPtr pointer to the physical address. + The DeviceAddrPtr will contain 0 in case of any error. + +**/ VOID -snp_undi32_callback_v2p_30 ( +SnpUndi32CallbackV2p30 ( IN UINT64 CpuAddr, IN OUT UINT64 DeviceAddrPtr ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - UNDI call this routine with a virtual or CPU address that SNP provided - to convert it to a physical or device address. Since EFI uses the identical - mapping, this routine returns the physical address same as the virtual address - for most of the addresses. an address above 4GB cannot generally be used as a - device address, it needs to be mapped to a lower physical address. This routine - does not call the map routine itself, but it assumes that the mapping was done - at the time of providing the address to UNDI. This routine just looks up the - address in a map table (which is the v2p structure chain) - -Arguments: - CpuAddr - virtual address of a buffer - DeviceAddrPtr - pointer to the physical address - -Returns: - void - The DeviceAddrPtr will contain 0 in case of any error - ---*/ { - struct s_v2p *v2p; + V2P *V2p; // // Do nothing if virtual address is zero or physical pointer is NULL. // No need to map if the virtual address is within 4GB limit since // EFI uses identical mapping // if ((CpuAddr == 0) || (DeviceAddrPtr == 0)) { - DEBUG ((EFI_D_ERROR, "\nv2p: Null virtual address or physical pointer.\n")); + DEBUG ((EFI_D_NET, "\nv2p: Null virtual address or physical pointer.\n")); return ; } @@ -77,31 +72,26 @@ Returns: // big address, this callback routine just looks up in the v2p list and // returns the physical address for any given virtual address. // - if (find_v2p (&v2p, (VOID *) (UINTN) CpuAddr) != EFI_SUCCESS) { + if (FindV2p (&V2p, (VOID *) (UINTN) CpuAddr) != EFI_SUCCESS) { *(UINT64 *) (UINTN) DeviceAddrPtr = CpuAddr; } else { - *(UINT64 *) (UINTN) DeviceAddrPtr = v2p->paddr; + *(UINT64 *) (UINTN) DeviceAddrPtr = V2p->PhysicalAddress; } } +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine when it wants to have exclusive access to a critical + section of the code/data. + + @param Enable non-zero indicates acquire + zero indicates release + +**/ VOID -snp_undi32_callback_block_30 ( +SnpUndi32CallbackBlock30 ( IN UINT32 Enable ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - UNDI call this routine when it wants to have exclusive access to a critical - section of the code/data - -Arguments: - Enable - non-zero indicates acquire - zero indicates release - -Returns: - void ---*/ { // // tcpip was calling snp at tpl_notify and if we acquire a lock that was @@ -119,59 +109,49 @@ Returns: } } +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine with the number of micro seconds when it wants to + pause. + + @param MicroSeconds number of micro seconds to pause, ususlly multiple of 10. + +**/ VOID -snp_undi32_callback_delay_30 ( +SnpUndi32CallbackDelay30 ( IN UINT64 MicroSeconds ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - UNDI call this routine with the number of micro seconds when it wants to - pause. - -Arguments: - MicroSeconds - number of micro seconds to pause, ususlly multiple of 10 - -Returns: - void ---*/ { if (MicroSeconds != 0) { gBS->Stall ((UINTN) MicroSeconds); } } +/** + This is a callback routine supplied to UNDI at undi_start time. + This is the IO routine for UNDI. This is not currently being used by UNDI3.0 + because Undi3.0 uses io/mem offsets relative to the beginning of the device + io/mem address and so it needs to use the PCI_IO_FUNCTION that abstracts the + start of the device's io/mem addresses. Since SNP cannot retrive the context + of the undi3.0 interface it cannot use the PCI_IO_FUNCTION that specific for + that NIC and uses one global IO functions structure, this does not work. + This however works fine for EFI1.0 Undis because they use absolute addresses + for io/mem access. + + @param ReadOrWrite indicates read or write, IO or Memory + @param NumBytes number of bytes to read or write + @param Address IO or memory address to read from or write to + @param BufferAddr memory location to read into or that contains the bytes to + write + +**/ VOID -snp_undi32_callback_memio_30 ( +SnpUndi32CallbackMemio30 ( IN UINT8 ReadOrWrite, IN UINT8 NumBytes, IN UINT64 Address, IN OUT UINT64 BufferAddr ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - This is the IO routine for UNDI. This is not currently being used by UNDI3.0 - because Undi3.0 uses io/mem offsets relative to the beginning of the device - io/mem address and so it needs to use the PCI_IO_FUNCTION that abstracts the - start of the device's io/mem addresses. Since SNP cannot retrive the context - of the undi3.0 interface it cannot use the PCI_IO_FUNCTION that specific for - that NIC and uses one global IO functions structure, this does not work. - This however works fine for EFI1.0 Undis because they use absolute addresses - for io/mem access. - -Arguments: - ReadOrWrite - indicates read or write, IO or Memory - NumBytes - number of bytes to read or write - Address - IO or memory address to read from or write to - BufferAddr - memory location to read into or that contains the bytes - to write - -Returns: - ---*/ { EFI_PCI_IO_PROTOCOL_WIDTH Width; @@ -194,150 +174,134 @@ Returns: switch (ReadOrWrite) { case PXE_IO_READ: - mPciIoFncs->Io.Read ( - mPciIoFncs, - Width, - 1, // BAR 1, IO base address - Address, - 1, // count - (VOID *) (UINTN) BufferAddr - ); + mPciIo->Io.Read ( + mPciIo, + Width, + 1, // BAR 1, IO base address + Address, + 1, // count + (VOID *) (UINTN) BufferAddr + ); break; case PXE_IO_WRITE: - mPciIoFncs->Io.Write ( - mPciIoFncs, - Width, - 1, // BAR 1, IO base address - Address, - 1, // count - (VOID *) (UINTN) BufferAddr - ); + mPciIo->Io.Write ( + mPciIo, + Width, + 1, // BAR 1, IO base address + Address, + 1, // count + (VOID *) (UINTN) BufferAddr + ); break; case PXE_MEM_READ: - mPciIoFncs->Mem.Read ( - mPciIoFncs, - Width, - 0, // BAR 0, Memory base address - Address, - 1, // count - (VOID *) (UINTN) BufferAddr - ); + mPciIo->Mem.Read ( + mPciIo, + Width, + 0, // BAR 0, Memory base address + Address, + 1, // count + (VOID *) (UINTN) BufferAddr + ); break; case PXE_MEM_WRITE: - mPciIoFncs->Mem.Write ( - mPciIoFncs, - Width, - 0, // BAR 0, Memory base address - Address, - 1, // count - (VOID *) (UINTN) BufferAddr - ); + mPciIo->Mem.Write ( + mPciIo, + Width, + 0, // BAR 0, Memory base address + Address, + 1, // count + (VOID *) (UINTN) BufferAddr + ); break; } return ; } -// -// New callbacks for 3.1: -// there won't be a virtual2physical callback for UNDI 3.1 because undi3.1 uses -// the MemMap call to map the required address by itself! -// + +/** + This is a callback routine supplied to UNDI3.1 at undi_start time. + UNDI call this routine when it wants to have exclusive access to a critical + section of the code/data. + New callbacks for 3.1: + there won't be a virtual2physical callback for UNDI 3.1 because undi3.1 uses + the MemMap call to map the required address by itself! + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to + store Undi interface context (Undi does not read or write + this variable) + @param Enable non-zero indicates acquire + zero indicates release +**/ VOID -snp_undi32_callback_block ( +SnpUndi32CallbackBlock ( IN UINT64 UniqueId, IN UINT32 Enable ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI3.1 at undi_start time. - UNDI call this routine when it wants to have exclusive access to a critical - section of the code/data - -Arguments: - UniqueId - This was supplied to UNDI at Undi_Start, SNP uses this to store - Undi interface context (Undi does not read or write this variable) - Enable - non-zero indicates acquire - zero indicates release - -Returns: - void - ---*/ { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; - snp = (SNP_DRIVER *) (UINTN) UniqueId; + Snp = (SNP_DRIVER *) (UINTN) UniqueId; // // tcpip was calling snp at tpl_notify and when we acquire a lock that was // created at a lower level (TPL_CALLBACK) it gives an assert! // if (Enable != 0) { - EfiAcquireLock (&snp->lock); + EfiAcquireLock (&Snp->Lock); } else { - EfiReleaseLock (&snp->lock); + EfiReleaseLock (&Snp->Lock); } } +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine with the number of micro seconds when it wants to + pause. + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to + store Undi interface context (Undi does not read or write + this variable) + @param MicroSeconds number of micro seconds to pause, ususlly multiple of 10. +**/ VOID -snp_undi32_callback_delay ( +SnpUndi32CallbackDelay ( IN UINT64 UniqueId, IN UINT64 MicroSeconds ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - UNDI call this routine with the number of micro seconds when it wants to - pause. - -Arguments: - MicroSeconds - number of micro seconds to pause, ususlly multiple of 10 - -Returns: - void ---*/ { if (MicroSeconds != 0) { gBS->Stall ((UINTN) MicroSeconds); } } -/* - * IO routine for UNDI start CPB. - */ +/** + This is a callback routine supplied to UNDI at undi_start time. + This is the IO routine for UNDI3.1 to start CPB. + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this + to store Undi interface context (Undi does not read or + write this variable) + @param ReadOrWrite indicates read or write, IO or Memory. + @param NumBytes number of bytes to read or write. + @param MemOrPortAddr IO or memory address to read from or write to. + @param BufferPtr memory location to read into or that contains the bytes + to write. +**/ VOID -snp_undi32_callback_memio ( - UINT64 UniqueId, - UINT8 ReadOrWrite, - UINT8 NumBytes, - UINT64 Address, - UINT64 BufferAddr +SnpUndi32CallbackMemio ( + IN UINT64 UniqueId, + IN UINT8 ReadOrWrite, + IN UINT8 NumBytes, + IN UINT64 MemOrPortAddr, + IN OUT UINT64 BufferPtr ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - This is the IO routine for UNDI3.1. - -Arguments: - ReadOrWrite - indicates read or write, IO or Memory - NumBytes - number of bytes to read or write - Address - IO or memory address to read from or write to - BufferAddr - memory location to read into or that contains the bytes - to write - -Returns: - ---*/ { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_PCI_IO_PROTOCOL_WIDTH Width; - snp = (SNP_DRIVER *) (UINTN) UniqueId; + Snp = (SNP_DRIVER *) (UINTN) UniqueId; Width = (EFI_PCI_IO_PROTOCOL_WIDTH) 0; switch (NumBytes) { @@ -356,46 +320,46 @@ Returns: switch (ReadOrWrite) { case PXE_IO_READ: - snp->IoFncs->Io.Read ( - snp->IoFncs, - Width, - snp->IoBarIndex, // BAR 1 (for 32bit regs), IO base address - Address, - 1, // count - (VOID *) (UINTN) BufferAddr - ); + Snp->PciIo->Io.Read ( + Snp->PciIo, + Width, + Snp->IoBarIndex, // BAR 1 (for 32bit regs), IO base address + MemOrPortAddr, + 1, // count + (VOID *) (UINTN) BufferPtr + ); break; case PXE_IO_WRITE: - snp->IoFncs->Io.Write ( - snp->IoFncs, - Width, - snp->IoBarIndex, // BAR 1 (for 32bit regs), IO base address - Address, - 1, // count - (VOID *) (UINTN) BufferAddr - ); + Snp->PciIo->Io.Write ( + Snp->PciIo, + Width, + Snp->IoBarIndex, // BAR 1 (for 32bit regs), IO base address + MemOrPortAddr, + 1, // count + (VOID *) (UINTN) BufferPtr + ); break; case PXE_MEM_READ: - snp->IoFncs->Mem.Read ( - snp->IoFncs, + Snp->PciIo->Mem.Read ( + Snp->PciIo, Width, - snp->MemoryBarIndex, // BAR 0, Memory base address - Address, + Snp->MemoryBarIndex, // BAR 0, Memory base address + MemOrPortAddr, 1, // count - (VOID *) (UINTN) BufferAddr + (VOID *) (UINTN) BufferPtr ); break; case PXE_MEM_WRITE: - snp->IoFncs->Mem.Write ( - snp->IoFncs, + Snp->PciIo->Mem.Write ( + Snp->PciIo, Width, - snp->MemoryBarIndex, // BAR 0, Memory base address - Address, + Snp->MemoryBarIndex, // BAR 0, Memory base address + MemOrPortAddr, 1, // count - (VOID *) (UINTN) BufferAddr + (VOID *) (UINTN) BufferPtr ); break; } @@ -403,44 +367,38 @@ Returns: return ; } +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine when it has to map a CPU address to a device + address. + + @param UniqueId - This was supplied to UNDI at Undi_Start, SNP uses this to store + Undi interface context (Undi does not read or write this variable) + @param CpuAddr - Virtual address to be mapped! + @param NumBytes - size of memory to be mapped + @param Direction - direction of data flow for this memory's usage: + cpu->device, device->cpu or both ways + @param DeviceAddrPtr - pointer to return the mapped device address + +**/ VOID -snp_undi32_callback_map ( +SnpUndi32CallbackMap ( IN UINT64 UniqueId, IN UINT64 CpuAddr, IN UINT32 NumBytes, IN UINT32 Direction, IN OUT UINT64 DeviceAddrPtr ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - UNDI call this routine when it has to map a CPU address to a device - address. - -Arguments: - UniqueId - This was supplied to UNDI at Undi_Start, SNP uses this to store - Undi interface context (Undi does not read or write this variable) - CpuAddr - Virtual address to be mapped! - NumBytes - size of memory to be mapped - Direction - direction of data flow for this memory's usage: - cpu->device, device->cpu or both ways - DeviceAddrPtr - pointer to return the mapped device address - -Returns: - None - ---*/ { EFI_PHYSICAL_ADDRESS *DevAddrPtr; EFI_PCI_IO_PROTOCOL_OPERATION DirectionFlag; UINTN BuffSize; - SNP_DRIVER *snp; + SNP_DRIVER *Snp; UINTN Index; EFI_STATUS Status; BuffSize = (UINTN) NumBytes; - snp = (SNP_DRIVER *) (UINTN) UniqueId; + Snp = (SNP_DRIVER *) (UINTN) UniqueId; DevAddrPtr = (EFI_PHYSICAL_ADDRESS *) (UINTN) DeviceAddrPtr; if (CpuAddr == 0) { @@ -472,7 +430,7 @@ Returns: // find an unused map_list entry // for (Index = 0; Index < MAX_MAP_LENGTH; Index++) { - if (snp->map_list[Index].virt == 0) { + if (Snp->MapList[Index].VirtualAddress == 0) { break; } } @@ -483,59 +441,54 @@ Returns: return ; } - snp->map_list[Index].virt = (EFI_PHYSICAL_ADDRESS) CpuAddr; + Snp->MapList[Index].VirtualAddress = (EFI_PHYSICAL_ADDRESS) CpuAddr; - Status = snp->IoFncs->Map ( - snp->IoFncs, - DirectionFlag, - (VOID *) (UINTN) CpuAddr, - &BuffSize, - DevAddrPtr, - &(snp->map_list[Index].map_cookie) - ); + Status = Snp->PciIo->Map ( + Snp->PciIo, + DirectionFlag, + (VOID *) (UINTN) CpuAddr, + &BuffSize, + DevAddrPtr, + &(Snp->MapList[Index].MapCookie) + ); if (Status != EFI_SUCCESS) { - *DevAddrPtr = 0; - snp->map_list[Index].virt = 0; + *DevAddrPtr = 0; + Snp->MapList[Index].VirtualAddress = 0; } return ; } +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine when it wants to unmap an address that was previously + mapped using map callback. + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to store. + Undi interface context (Undi does not read or write this variable) + @param CpuAddr Virtual address that was mapped! + @param NumBytes size of memory mapped + @param Direction direction of data flow for this memory's usage: + cpu->device, device->cpu or both ways + @param DeviceAddr the mapped device address + +**/ VOID -snp_undi32_callback_unmap ( +SnpUndi32CallbackUnmap ( IN UINT64 UniqueId, IN UINT64 CpuAddr, IN UINT32 NumBytes, IN UINT32 Direction, IN UINT64 DeviceAddr ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - UNDI call this routine when it wants to unmap an address that was previously - mapped using map callback - -Arguments: - UniqueId - This was supplied to UNDI at Undi_Start, SNP uses this to store - Undi interface context (Undi does not read or write this variable) - CpuAddr - Virtual address that was mapped! - NumBytes - size of memory mapped - Direction- direction of data flow for this memory's usage: - cpu->device, device->cpu or both ways - DeviceAddr - the mapped device address - -Returns: - ---*/ { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; UINT16 Index; - snp = (SNP_DRIVER *) (UINTN) UniqueId; + Snp = (SNP_DRIVER *) (UINTN) UniqueId; for (Index = 0; Index < MAX_MAP_LENGTH; Index++) { - if (snp->map_list[Index].virt == CpuAddr) { + if (Snp->MapList[Index].VirtualAddress == CpuAddr) { break; } } @@ -546,46 +499,41 @@ Returns: return ; } - snp->IoFncs->Unmap (snp->IoFncs, snp->map_list[Index].map_cookie); - snp->map_list[Index].virt = 0; - snp->map_list[Index].map_cookie = NULL; + Snp->PciIo->Unmap (Snp->PciIo, Snp->MapList[Index].MapCookie); + Snp->MapList[Index].VirtualAddress = 0; + Snp->MapList[Index].MapCookie = NULL; return ; } +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine when it wants synchronize the virtual buffer contents + with the mapped buffer contents. The virtual and mapped buffers need not + correspond to the same physical memory (especially if the virtual address is + > 4GB). Depending on the direction for which the buffer is mapped, undi will + need to synchronize their contents whenever it writes to/reads from the buffer + using either the cpu address or the device address. + + EFI does not provide a sync call, since virt=physical, we sould just do + the synchronization ourself here! + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to store + Undi interface context (Undi does not read or write this variable) + @param CpuAddr Virtual address that was mapped! + @param NumBytes size of memory mapped. + @param Direction direction of data flow for this memory's usage: + cpu->device, device->cpu or both ways. + @param DeviceAddr the mapped device address. + +**/ VOID -snp_undi32_callback_sync ( - UINT64 UniqueId, - UINT64 CpuAddr, - UINT32 NumBytes, - UINT32 Direction, - UINT64 DeviceAddr +SnpUndi32CallbackSync ( + IN UINT64 UniqueId, + IN UINT64 CpuAddr, + IN UINT32 NumBytes, + IN UINT32 Direction, + IN UINT64 DeviceAddr ) -/*++ - -Routine Description: - This is a callback routine supplied to UNDI at undi_start time. - UNDI call this routine when it wants synchronize the virtual buffer contents - with the mapped buffer contents. The virtual and mapped buffers need not - correspond to the same physical memory (especially if the virtual address is - > 4GB). Depending on the direction for which the buffer is mapped, undi will - need to synchronize their contents whenever it writes to/reads from the buffer - using either the cpu address or the device address. - - EFI does not provide a sync call, since virt=physical, we sould just do - the synchronization ourself here! - -Arguments: - UniqueId - This was supplied to UNDI at Undi_Start, SNP uses this to store - Undi interface context (Undi does not read or write this variable) - CpuAddr - Virtual address that was mapped! - NumBytes - size of memory mapped - Direction- direction of data flow for this memory's usage: - cpu->device, device->cpu or both ways - DeviceAddr - the mapped device address - -Returns: - ---*/ { if ((CpuAddr == 0) || (DeviceAddr == 0) || (NumBytes == 0)) { return ; diff --git a/MdeModulePkg/Universal/Network/SnpDxe/ComponentName.c b/MdeModulePkg/Universal/Network/SnpDxe/ComponentName.c index e8da93010c..304e6205fd 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/ComponentName.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/ComponentName.c @@ -1,25 +1,18 @@ /** @file + UEFI Component Name(2) protocol implementation for SnpDxe driver. -Copyright (c) 2004 - 2007, Intel Corporation -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 +Copyright (c) 2004 - 2008, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - ComponentName.c - -Abstract: - - **/ - #include "Snp.h" // diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Get_status.c b/MdeModulePkg/Universal/Network/SnpDxe/Get_status.c index 9eaafb932c..17078c81cf 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Get_status.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Get_status.c @@ -1,21 +1,16 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of reading the current interrupt status and recycled transmit + buffer status from a network interface. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - get_status.c - -Abstract: - -Revision history: - 2000-Feb-03 M(f)J Genesis. - **/ #include "Snp.h" @@ -24,7 +19,7 @@ Revision history: this routine calls undi to get the status of the interrupts, get the list of transmit buffers that completed transmitting! - @param snp pointer to snp driver structure + @param Snp pointer to snp driver structure @param InterruptStatusPtr a non null pointer gets the interrupt status @param TransmitBufferListPtrs a non null ointer gets the list of pointers of previously transmitted buffers whose @@ -33,56 +28,56 @@ Revision history: **/ EFI_STATUS -pxe_getstatus ( - SNP_DRIVER *snp, +PxeGetStatus ( + SNP_DRIVER *Snp, UINT32 *InterruptStatusPtr, VOID **TransmitBufferListPtr ) { - PXE_DB_GET_STATUS *db; + PXE_DB_GET_STATUS *Db; UINT16 InterruptFlags; - db = snp->db; - snp->cdb.OpCode = PXE_OPCODE_GET_STATUS; + Db = Snp->Db; + Snp->Cdb.OpCode = PXE_OPCODE_GET_STATUS; - snp->cdb.OpFlags = 0; + Snp->Cdb.OpFlags = 0; if (TransmitBufferListPtr != NULL) { - snp->cdb.OpFlags |= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS; } if (InterruptStatusPtr != NULL) { - snp->cdb.OpFlags |= PXE_OPFLAGS_GET_INTERRUPT_STATUS; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_INTERRUPT_STATUS; } - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; // // size DB for return of one buffer // - snp->cdb.DBsize = (UINT16) (((UINT16) (sizeof (PXE_DB_GET_STATUS)) - (UINT16) (sizeof db->TxBuffer)) + (UINT16) (sizeof db->TxBuffer[0])); + Snp->Cdb.DBsize = (UINT16) ((sizeof (PXE_DB_GET_STATUS) - sizeof (Db->TxBuffer)) + sizeof (Db->TxBuffer[0])); - snp->cdb.DBaddr = (UINT64)(UINTN) db; + Snp->Cdb.DBaddr = (UINT64)(UINTN) Db; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; // // Issue UNDI command and check result. // - DEBUG ((EFI_D_NET, "\nsnp->undi.get_status() ")); + DEBUG ((EFI_D_NET, "\nSnp->undi.get_status() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != EFI_SUCCESS) { + if (Snp->Cdb.StatCode != EFI_SUCCESS) { DEBUG ( (EFI_D_NET, - "\nsnp->undi.get_status() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatFlags) + "\nSnp->undi.get_status() %xh:%xh\n", + Snp->Cdb.StatFlags, + Snp->Cdb.StatFlags) ); return EFI_DEVICE_ERROR; @@ -91,23 +86,23 @@ pxe_getstatus ( // report the values back.. // if (InterruptStatusPtr != NULL) { - InterruptFlags = (UINT16) (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK); + InterruptFlags = (UINT16) (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK); *InterruptStatusPtr = 0; - if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_RECEIVE) { + if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_RECEIVE) == PXE_STATFLAGS_GET_STATUS_RECEIVE) { *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; } - if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_TRANSMIT) { + if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_TRANSMIT) == PXE_STATFLAGS_GET_STATUS_TRANSMIT) { *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; } - if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_COMMAND) { + if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_COMMAND) == PXE_STATFLAGS_GET_STATUS_COMMAND) { *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT; } - if (InterruptFlags & PXE_STATFLAGS_GET_STATUS_SOFTWARE) { + if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_SOFTWARE) == PXE_STATFLAGS_GET_STATUS_SOFTWARE) { *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT; } @@ -116,58 +111,82 @@ pxe_getstatus ( if (TransmitBufferListPtr != NULL) { *TransmitBufferListPtr = ( - (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) || - (snp->cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY) - ) ? 0 : (VOID *) (UINTN) db->TxBuffer[0]; + (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) || + (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY) + ) ? 0 : (VOID *) (UINTN) Db->TxBuffer[0]; } return EFI_SUCCESS; } - /** - This is the SNP interface routine for getting the status - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_getstatus routine to actually get the undi status - - @param this context pointer - @param InterruptStatusPtr a non null pointer gets the interrupt status - @param TransmitBufferListPtrs a non null ointer gets the list of pointers of - previously transmitted buffers whose - transmission was completed asynchrnously. - + Reads the current interrupt status and recycled transmit buffer status from a + network interface. + + This function gets the current interrupt and recycled transmit buffer status + from the network interface. The interrupt status is returned as a bit mask in + InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be + read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved. + If a recycled transmit buffer address is returned in TxBuf, then the buffer has + been successfully transmitted, and the status for that buffer is cleared. If + the status of the network interface is successfully collected, EFI_SUCCESS + will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will + be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param InterruptStatus A pointer to the bit mask of the currently active + interrupts (see "Related Definitions"). If this is NULL, + the interrupt status will not be read from the device. + If this is not NULL, the interrupt status will be read + from the device. When the interrupt status is read, it + will also be cleared. Clearing the transmit interrupt does + not empty the recycled transmit buffer array. + @param TxBuf Recycled transmit buffer address. The network interface + will not transmit if its internal recycled transmit + buffer array is full. Reading the transmit buffer does + not clear the transmit interrupt. If this is NULL, then + the transmit buffer status will not be read. If there + are no transmit buffers to recycle and TxBuf is not NULL, + TxBuf will be set to NULL. + + @retval EFI_SUCCESS The status of the network interface was retrieved. + @retval EFI_NOT_STARTED The network interface has not been started. + @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. **/ EFI_STATUS EFIAPI -snp_undi32_get_status ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - OUT UINT32 *InterruptStatusPtr OPTIONAL, - OUT VOID **TransmitBufferListPtr OPTIONAL +SnpUndi32GetStatus ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + OUT UINT32 *InterruptStatus, OPTIONAL + OUT VOID **TxBuf OPTIONAL ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_TPL OldTpl; EFI_STATUS Status; - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - if (InterruptStatusPtr == NULL && TransmitBufferListPtr == NULL) { + if (InterruptStatus == NULL && TxBuf == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - if (snp == NULL) { + if (Snp == NULL) { return EFI_DEVICE_ERROR; } - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -180,7 +199,7 @@ snp_undi32_get_status ( goto ON_EXIT; } - Status = pxe_getstatus (snp, InterruptStatusPtr, TransmitBufferListPtr); + Status = PxeGetStatus (Snp, InterruptStatus, TxBuf); ON_EXIT: gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Initialize.c b/MdeModulePkg/Universal/Network/SnpDxe/Initialize.c index 69154fc0c7..5337b1cc2e 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Initialize.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Initialize.c @@ -1,68 +1,56 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of initializing a network adapter. + +Copyright (c) 2004 - 2008, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - initialize.c - -Abstract: - -Revision history: - 2000-Feb-09 M(f)J Genesis. - **/ #include "Snp.h" -VOID -EFIAPI -SnpWaitForPacketNotify ( - IN EFI_EVENT Event, - IN VOID *SnpPtr - ); - - /** this routine calls undi to initialize the interface. - @param snp pointer to snp driver structure - @param CableDetectFlag Do/don't detect the cable (depending on what undi - supports) - + @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 **/ EFI_STATUS -pxe_init ( - SNP_DRIVER *snp, +PxeInit ( + SNP_DRIVER *Snp, UINT16 CableDetectFlag ) { - PXE_CPB_INITIALIZE *cpb; - VOID *addr; + PXE_CPB_INITIALIZE *Cpb; + VOID *Addr; EFI_STATUS Status; - cpb = snp->cpb; - if (snp->tx_rx_bufsize != 0) { - Status = snp->IoFncs->AllocateBuffer ( - snp->IoFncs, - AllocateAnyPages, - EfiBootServicesData, - SNP_MEM_PAGES (snp->tx_rx_bufsize), - &addr, - 0 - ); + Cpb = Snp->Cpb; + if (Snp->TxRxBufferSize != 0) { + Status = Snp->PciIo->AllocateBuffer ( + Snp->PciIo, + AllocateAnyPages, + EfiBootServicesData, + SNP_MEM_PAGES (Snp->TxRxBufferSize), + &Addr, + 0 + ); if (Status != EFI_SUCCESS) { DEBUG ( (EFI_D_ERROR, - "\nsnp->pxe_init() AllocateBuffer %xh (%r)\n", + "\nSnp->PxeInit() AllocateBuffer %xh (%r)\n", Status, Status) ); @@ -70,69 +58,69 @@ pxe_init ( return Status; } - ASSERT (addr); + ASSERT (Addr); - snp->tx_rx_buffer = addr; + Snp->TxRxBuffer = Addr; } - cpb->MemoryAddr = (UINT64)(UINTN) snp->tx_rx_buffer; + Cpb->MemoryAddr = (UINT64)(UINTN) Snp->TxRxBuffer; - cpb->MemoryLength = snp->tx_rx_bufsize; + Cpb->MemoryLength = Snp->TxRxBufferSize; // // let UNDI decide/detect these values // - cpb->LinkSpeed = 0; - cpb->TxBufCnt = 0; - cpb->TxBufSize = 0; - cpb->RxBufCnt = 0; - cpb->RxBufSize = 0; + Cpb->LinkSpeed = 0; + Cpb->TxBufCnt = 0; + Cpb->TxBufSize = 0; + Cpb->RxBufCnt = 0; + Cpb->RxBufSize = 0; - cpb->DuplexMode = PXE_DUPLEX_DEFAULT; + Cpb->DuplexMode = PXE_DUPLEX_DEFAULT; - cpb->LoopBackMode = LOOPBACK_NORMAL; + Cpb->LoopBackMode = LOOPBACK_NORMAL; - snp->cdb.OpCode = PXE_OPCODE_INITIALIZE; - snp->cdb.OpFlags = CableDetectFlag; + Snp->Cdb.OpCode = PXE_OPCODE_INITIALIZE; + Snp->Cdb.OpFlags = CableDetectFlag; - snp->cdb.CPBsize = sizeof (PXE_CPB_INITIALIZE); - snp->cdb.DBsize = sizeof (PXE_DB_INITIALIZE); + Snp->Cdb.CPBsize = sizeof (PXE_CPB_INITIALIZE); + Snp->Cdb.DBsize = sizeof (PXE_DB_INITIALIZE); - snp->cdb.CPBaddr = (UINT64)(UINTN) snp->cpb; - snp->cdb.DBaddr = (UINT64)(UINTN) snp->db; + Snp->Cdb.CPBaddr = (UINT64)(UINTN) Snp->Cpb; + Snp->Cdb.DBaddr = (UINT64)(UINTN) Snp->Db; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; - DEBUG ((EFI_D_NET, "\nsnp->undi.initialize() ")); + DEBUG ((EFI_D_NET, "\nSnp->undi.initialize() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode == PXE_STATCODE_SUCCESS) { - snp->mode.State = EfiSimpleNetworkInitialized; + if (Snp->Cdb.StatCode == PXE_STATCODE_SUCCESS) { + Snp->Mode.State = EfiSimpleNetworkInitialized; Status = EFI_SUCCESS; } else { DEBUG ( (EFI_D_WARN, - "\nsnp->undi.initialize() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + "\nSnp->undi.initialize() %xh:%xh\n", + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); - if (snp->tx_rx_buffer != NULL) { - snp->IoFncs->FreeBuffer ( - snp->IoFncs, - SNP_MEM_PAGES (snp->tx_rx_bufsize), - (VOID *) snp->tx_rx_buffer + if (Snp->TxRxBuffer != NULL) { + Snp->PciIo->FreeBuffer ( + Snp->PciIo, + SNP_MEM_PAGES (Snp->TxRxBufferSize), + (VOID *) Snp->TxRxBuffer ); } - snp->tx_rx_buffer = NULL; + Snp->TxRxBuffer = NULL; - Status = EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; } return Status; @@ -140,47 +128,64 @@ pxe_init ( /** - This is the SNP interface routine for initializing the interface - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_initialize routine to actually do the undi initialization - - @param this context pointer - @param extra_rx_buffer_size optional parameter, indicates extra space for - rx_buffers - @param extra_tx_buffer_size optional parameter, indicates extra space for - tx_buffers - + 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. **/ EFI_STATUS EFIAPI -snp_undi32_initialize ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this, - IN UINTN extra_rx_buffer_size OPTIONAL, - IN UINTN extra_tx_buffer_size OPTIONAL +SnpUndi32Initialize ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN UINTN ExtraRxBufferSize OPTIONAL, + IN UINTN ExtraTxBufferSize OPTIONAL ) { EFI_STATUS EfiStatus; - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_TPL OldTpl; - // - // - // - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - if (snp == NULL) { + if (Snp == NULL) { EfiStatus = EFI_INVALID_PARAMETER; goto ON_EXIT; } - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkStarted: break; @@ -197,45 +202,45 @@ snp_undi32_initialize ( EVT_NOTIFY_WAIT, TPL_NOTIFY, &SnpWaitForPacketNotify, - snp, - &snp->snp.WaitForPacket + Snp, + &Snp->Snp.WaitForPacket ); if (EFI_ERROR (EfiStatus)) { - snp->snp.WaitForPacket = NULL; + Snp->Snp.WaitForPacket = NULL; EfiStatus = EFI_DEVICE_ERROR; goto ON_EXIT; } // // // - snp->mode.MCastFilterCount = 0; - snp->mode.ReceiveFilterSetting = 0; - ZeroMem (snp->mode.MCastFilter, sizeof snp->mode.MCastFilter); + Snp->Mode.MCastFilterCount = 0; + Snp->Mode.ReceiveFilterSetting = 0; + ZeroMem (Snp->Mode.MCastFilter, sizeof Snp->Mode.MCastFilter); CopyMem ( - &snp->mode.CurrentAddress, - &snp->mode.PermanentAddress, + &Snp->Mode.CurrentAddress, + &Snp->Mode.PermanentAddress, sizeof (EFI_MAC_ADDRESS) ); // // Compute tx/rx buffer sizes based on UNDI init info and parameters. // - snp->tx_rx_bufsize = (UINT32) (snp->init_info.MemoryRequired + extra_rx_buffer_size + extra_tx_buffer_size); + Snp->TxRxBufferSize = (UINT32) (Snp->InitInfo.MemoryRequired + ExtraRxBufferSize + ExtraTxBufferSize); - if (snp->mode.MediaPresentSupported) { - if (pxe_init (snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) { - snp->mode.MediaPresent = TRUE; + if (Snp->Mode.MediaPresentSupported) { + if (PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) == EFI_SUCCESS) { + Snp->Mode.MediaPresent = TRUE; goto ON_EXIT; } } - snp->mode.MediaPresent = FALSE; + Snp->Mode.MediaPresent = FALSE; - EfiStatus = pxe_init (snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE); + EfiStatus = PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE); if (EFI_ERROR (EfiStatus)) { - gBS->CloseEvent (snp->snp.WaitForPacket); + gBS->CloseEvent (Snp->Snp.WaitForPacket); } ON_EXIT: diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Mcast_ip_to_mac.c b/MdeModulePkg/Universal/Network/SnpDxe/Mcast_ip_to_mac.c index 6c5bf15e8b..00c80eb95f 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Mcast_ip_to_mac.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Mcast_ip_to_mac.c @@ -1,29 +1,24 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of converting an multicast IP address to multicast HW MAC + address. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - mcast_ip_to_mac.c - -Abstract: - -Revision history: - 2000-Feb-17 M(f)J Genesis. - **/ #include "Snp.h" /** - this routine calls undi to convert an multicast IP address to a MAC address + this routine calls undi to convert an multicast IP address to a MAC address. - @param snp pointer to snp driver structure + @param Snp pointer to snp driver structure @param IPv6 flag to indicate if this is an ipv6 address @param IP multicast IP address @param MAC pointer to hold the return MAC address @@ -31,41 +26,41 @@ Revision history: **/ EFI_STATUS -pxe_ip2mac ( - IN SNP_DRIVER *snp, +PxeIp2Mac ( + IN SNP_DRIVER *Snp, IN BOOLEAN IPv6, IN EFI_IP_ADDRESS *IP, IN OUT EFI_MAC_ADDRESS *MAC ) { - PXE_CPB_MCAST_IP_TO_MAC *cpb; - PXE_DB_MCAST_IP_TO_MAC *db; + PXE_CPB_MCAST_IP_TO_MAC *Cpb; + PXE_DB_MCAST_IP_TO_MAC *Db; - cpb = snp->cpb; - db = snp->db; - snp->cdb.OpCode = PXE_OPCODE_MCAST_IP_TO_MAC; - snp->cdb.OpFlags = (UINT16) (IPv6 ? PXE_OPFLAGS_MCAST_IPV6_TO_MAC : PXE_OPFLAGS_MCAST_IPV4_TO_MAC); - snp->cdb.CPBsize = sizeof (PXE_CPB_MCAST_IP_TO_MAC); - snp->cdb.DBsize = sizeof (PXE_DB_MCAST_IP_TO_MAC); + Cpb = Snp->Cpb; + Db = Snp->Db; + Snp->Cdb.OpCode = PXE_OPCODE_MCAST_IP_TO_MAC; + Snp->Cdb.OpFlags = (UINT16) (IPv6 ? PXE_OPFLAGS_MCAST_IPV6_TO_MAC : PXE_OPFLAGS_MCAST_IPV4_TO_MAC); + Snp->Cdb.CPBsize = sizeof (PXE_CPB_MCAST_IP_TO_MAC); + Snp->Cdb.DBsize = sizeof (PXE_DB_MCAST_IP_TO_MAC); - snp->cdb.CPBaddr = (UINT64)(UINTN) cpb; - snp->cdb.DBaddr = (UINT64)(UINTN) db; + Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb; + Snp->Cdb.DBaddr = (UINT64)(UINTN) Db; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; - CopyMem (&cpb->IP, IP, sizeof (PXE_IP_ADDR)); + CopyMem (&Cpb->IP, IP, sizeof (PXE_IP_ADDR)); // // Issue UNDI command and check result. // - DEBUG ((EFI_D_NET, "\nsnp->undi.mcast_ip_to_mac() ")); + DEBUG ((EFI_D_NET, "\nSnp->undi.mcast_ip_to_mac() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - switch (snp->cdb.StatCode) { + switch (Snp->Cdb.StatCode) { case PXE_STATCODE_SUCCESS: break; @@ -75,9 +70,9 @@ pxe_ip2mac ( case PXE_STATCODE_UNSUPPORTED: DEBUG ( (EFI_D_NET, - "\nsnp->undi.mcast_ip_to_mac() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + "\nSnp->undi.mcast_ip_to_mac() %xh:%xh\n", + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_UNSUPPORTED; @@ -88,49 +83,64 @@ pxe_ip2mac ( // DEBUG ( (EFI_D_NET, - "\nsnp->undi.mcast_ip_to_mac() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + "\nSnp->undi.mcast_ip_to_mac() %xh:%xh\n", + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_DEVICE_ERROR; } - CopyMem (MAC, &db->MAC, sizeof (PXE_MAC_ADDR)); + CopyMem (MAC, &Db->MAC, sizeof (PXE_MAC_ADDR)); return EFI_SUCCESS; } /** - This is the SNP interface routine for converting a multicast IP address to - a MAC address. - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_ip2mac routine to actually do the conversion - - @param this context pointer - @param IPv6 flag to indicate if this is an ipv6 address - @param IP multicast IP address - @param MAC pointer to hold the return MAC address - + Converts a multicast IP address to a multicast HW MAC address. + + This function converts a multicast IP address to a multicast HW MAC address + for all packet transactions. If the mapping is accepted, then EFI_SUCCESS will + be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. + Set to FALSE if the multicast IP address is IPv4 [RFC 791]. + @param IP The multicast IP address that is to be converted to a multicast + HW MAC address. + @param MAC The multicast HW MAC address that is to be generated from IP. + + @retval EFI_SUCCESS The multicast IP address was mapped to the + multicast HW MAC address. + @retval EFI_NOT_STARTED The Simple Network Protocol interface has not + been started by calling Start(). + @retval EFI_INVALID_PARAMETER IP is NULL. + @retval EFI_INVALID_PARAMETER MAC is NULL. + @retval EFI_INVALID_PARAMETER IP does not point to a valid IPv4 or IPv6 + multicast address. + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not + been initialized by calling Initialize(). + @retval EFI_UNSUPPORTED IPv6 is TRUE and the implementation does not + support IPv6 multicast to MAC address conversion. **/ EFI_STATUS EFIAPI -snp_undi32_mcast_ip_to_mac ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this, +SnpUndi32McastIpToMac ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN IPv6, IN EFI_IP_ADDRESS *IP, OUT EFI_MAC_ADDRESS *MAC ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_TPL OldTpl; EFI_STATUS Status; // // Get pointer to SNP driver instance for *this. // - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } @@ -138,11 +148,11 @@ snp_undi32_mcast_ip_to_mac ( return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -155,7 +165,7 @@ snp_undi32_mcast_ip_to_mac ( goto ON_EXIT; } - Status = pxe_ip2mac (snp, IPv6, IP, MAC); + Status = PxeIp2Mac (Snp, IPv6, IP, MAC); ON_EXIT: gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c b/MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c index 19d43be8bd..4b9259f87a 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c @@ -1,21 +1,16 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of reading and writing operations on the NVRAM device + attached to a network interface. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - nvdata.c - -Abstract: - -Revision history: - 2000-Feb-03 M(f)J Genesis. - **/ #include "Snp.h" @@ -24,47 +19,47 @@ Revision history: /** This routine calls Undi to read the desired number of eeprom bytes. - @param snp pointer to the snp driver structure - @param RegOffset eeprom register value relative to the base address - @param NumBytes number of bytes to read - @param BufferPtr pointer where to read into + @param Snp pointer to the snp driver structure + @param Offset eeprom register value relative to the base address + @param BufferSize number of bytes to read + @param Buffer pointer where to read into **/ EFI_STATUS -pxe_nvdata_read ( - IN SNP_DRIVER *snp, - IN UINTN RegOffset, - IN UINTN NumBytes, - IN OUT VOID *BufferPtr +PxeNvDataRead ( + IN SNP_DRIVER *Snp, + IN UINTN Offset, + IN UINTN BufferSize, + IN OUT VOID *Buffer ) { - PXE_DB_NVDATA *db; + PXE_DB_NVDATA *Db; - db = snp->db; - snp->cdb.OpCode = PXE_OPCODE_NVDATA; + Db = Snp->Db; + Snp->Cdb.OpCode = PXE_OPCODE_NVDATA; - snp->cdb.OpFlags = PXE_OPFLAGS_NVDATA_READ; + Snp->Cdb.OpFlags = PXE_OPFLAGS_NVDATA_READ; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.DBsize = sizeof (PXE_DB_NVDATA); - snp->cdb.DBaddr = (UINT64)(UINTN) db; + Snp->Cdb.DBsize = sizeof (PXE_DB_NVDATA); + Snp->Cdb.DBaddr = (UINT64)(UINTN) Db; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.nvdata () ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - switch (snp->cdb.StatCode) { + switch (Snp->Cdb.StatCode) { case PXE_STATCODE_SUCCESS: break; @@ -72,8 +67,8 @@ pxe_nvdata_read ( DEBUG ( (EFI_D_NET, "\nsnp->undi.nvdata() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_UNSUPPORTED; @@ -82,61 +77,99 @@ pxe_nvdata_read ( DEBUG ( (EFI_D_NET, "\nsnp->undi.nvdata() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_DEVICE_ERROR; } - CopyMem (BufferPtr, db->Data.Byte + RegOffset, NumBytes); + CopyMem (Buffer, Db->Data.Byte + Offset, BufferSize); return EFI_SUCCESS; } /** - This is an interface call provided by SNP. + Performs read and write operations on the NVRAM device attached to a network + interface. + + This function performs read and write operations on the NVRAM device attached + to a network interface. If ReadWrite is TRUE, a read operation is performed. + If ReadWrite is FALSE, a write operation is performed. Offset specifies the + byte offset at which to start either operation. Offset must be a multiple of + NvRamAccessSize , and it must have a value between zero and NvRamSize. + BufferSize specifies the length of the read or write operation. BufferSize must + also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed + NvRamSize. + If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be + returned. + If all the conditions are met and the operation is "read," the NVRAM device + attached to the network interface will be read into Buffer and EFI_SUCCESS + will be returned. If this is a write operation, the contents of Buffer will be + used to update the contents of the NVRAM device attached to the network + interface and EFI_SUCCESS will be returned. + It does the basic checking on the input parameters and retrieves snp structure and then calls the read_nvdata() call which does the actual reading - @param this context pointer - @param ReadOrWrite true for reading and false for writing - @param RegOffset eeprom register relative to the base - @param NumBytes how many bytes to read - @param BufferPtr address of memory to read into - + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param ReadWrite TRUE for read operations, FALSE for write operations. + @param Offset Byte offset in the NVRAM device at which to start the read or + write operation. This must be a multiple of NvRamAccessSize + and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE) + @param BufferSize The number of bytes to read or write from the NVRAM device. + This must also be a multiple of NvramAccessSize. + @param Buffer A pointer to the data buffer. + + @retval EFI_SUCCESS The NVRAM access was performed. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + * The This parameter is NULL + * The This parameter does not point to a valid + EFI_SIMPLE_NETWORK_PROTOCOL structure + * The Offset parameter is not a multiple of + EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize + * The Offset parameter is not less than + EFI_SIMPLE_NETWORK_MODE.NvRamSize + * The BufferSize parameter is not a multiple of + EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize + * The Buffer parameter is NULL + @retval EFI_DEVICE_ERROR The command could not be sent to the network + interface. + @retval EFI_UNSUPPORTED This function is not supported by the network + interface. **/ EFI_STATUS EFIAPI -snp_undi32_nvdata ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this, - IN BOOLEAN ReadOrWrite, - IN UINTN RegOffset, - IN UINTN NumBytes, - IN OUT VOID *BufferPtr +SnpUndi32NvData ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN BOOLEAN ReadWrite, + IN UINTN Offset, + IN UINTN BufferSize, + IN OUT VOID *Buffer ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_TPL OldTpl; EFI_STATUS Status; // // Get pointer to SNP driver instance for *this. // - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); // // Return error if the SNP is not initialized. // - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -151,19 +184,19 @@ snp_undi32_nvdata ( // // Return error if non-volatile memory variables are not valid. // - if (snp->mode.NvRamSize == 0 || snp->mode.NvRamAccessSize == 0) { + if (Snp->Mode.NvRamSize == 0 || Snp->Mode.NvRamAccessSize == 0) { Status = EFI_UNSUPPORTED; goto ON_EXIT; } // // Check for invalid parameter combinations. // - if ((NumBytes == 0) || - (BufferPtr == NULL) || - (RegOffset >= snp->mode.NvRamSize) || - (RegOffset + NumBytes > snp->mode.NvRamSize) || - (NumBytes % snp->mode.NvRamAccessSize != 0) || - (RegOffset % snp->mode.NvRamAccessSize != 0) + if ((BufferSize == 0) || + (Buffer == NULL) || + (Offset >= Snp->Mode.NvRamSize) || + (Offset + BufferSize > Snp->Mode.NvRamSize) || + (BufferSize % Snp->Mode.NvRamAccessSize != 0) || + (Offset % Snp->Mode.NvRamAccessSize != 0) ) { Status = EFI_INVALID_PARAMETER; goto ON_EXIT; @@ -171,10 +204,10 @@ snp_undi32_nvdata ( // // check the implementation flags of undi if we can write the nvdata! // - if (!ReadOrWrite) { + if (!ReadWrite) { Status = EFI_UNSUPPORTED; } else { - Status = pxe_nvdata_read (snp, RegOffset, NumBytes, BufferPtr); + Status = PxeNvDataRead (Snp, Offset, BufferSize, Buffer); } ON_EXIT: diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Receive.c b/MdeModulePkg/Universal/Network/SnpDxe/Receive.c index 48c47f15e0..bfabe11aa5 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Receive.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Receive.c @@ -1,21 +1,15 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of receiving a packet from a network interface. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - receive.c - -Abstract: - -Revision history: - 2000-Feb-03 M(f)J Genesis. - **/ @@ -25,66 +19,66 @@ Revision history: this routine calls undi to receive a packet and fills in the data in the input pointers! - @param snp pointer to snp driver structure - @param BufferPtr pointer to the memory for the received data - @param BuffSizePtr is a pointer to the length of the buffer on entry and + @param Snp pointer to snp driver structure + @param Buffer pointer to the memory for the received data + @param BufferSize is a pointer to the length of the buffer on entry and contains the length of the received data on return - @param HeaderSizePtr pointer to the header portion of the data received. - @param SourceAddrPtr optional parameter, is a pointer to contain the + @param HeaderSize pointer to the header portion of the data received. + @param SrcAddr optional parameter, is a pointer to contain the source ethernet address on return - @param DestinationAddrPtr optional parameter, is a pointer to contain the + @param DestAddr optional parameter, is a pointer to contain the destination ethernet address on return - @param ProtocolPtr optional parameter, is a pointer to contain the + @param Protocol optional parameter, is a pointer to contain the protocol type from the ethernet header on return **/ EFI_STATUS -pxe_receive ( - SNP_DRIVER *snp, - VOID *BufferPtr, - UINTN *BuffSizePtr, - UINTN *HeaderSizePtr, - EFI_MAC_ADDRESS *SourceAddrPtr, - EFI_MAC_ADDRESS *DestinationAddrPtr, - UINT16 *ProtocolPtr +PxeReceive ( + SNP_DRIVER *Snp, + VOID *Buffer, + UINTN *BufferSize, + UINTN *HeaderSize, + EFI_MAC_ADDRESS *SrcAddr, + EFI_MAC_ADDRESS *DestAddr, + UINT16 *Protocol ) { - PXE_CPB_RECEIVE *cpb; - PXE_DB_RECEIVE *db; - UINTN buf_size; + PXE_CPB_RECEIVE *Cpb; + PXE_DB_RECEIVE *Db; + UINTN BuffSize; - cpb = snp->cpb; - db = snp->db; - buf_size = *BuffSizePtr; + Cpb = Snp->Cpb; + Db = Snp->Db; + BuffSize = *BufferSize; - cpb->BufferAddr = (UINT64)(UINTN) BufferPtr; - cpb->BufferLen = (UINT32) *BuffSizePtr; + Cpb->BufferAddr = (UINT64)(UINTN) Buffer; + Cpb->BufferLen = (UINT32) *BufferSize; - cpb->reserved = 0; + Cpb->reserved = 0; - snp->cdb.OpCode = PXE_OPCODE_RECEIVE; - snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED; + Snp->Cdb.OpCode = PXE_OPCODE_RECEIVE; + Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED; - snp->cdb.CPBsize = sizeof (PXE_CPB_RECEIVE); - snp->cdb.CPBaddr = (UINT64)(UINTN) cpb; + Snp->Cdb.CPBsize = sizeof (PXE_CPB_RECEIVE); + Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb; - snp->cdb.DBsize = sizeof (PXE_DB_RECEIVE); - snp->cdb.DBaddr = (UINT64)(UINTN) db; + Snp->Cdb.DBsize = sizeof (PXE_DB_RECEIVE); + Snp->Cdb.DBaddr = (UINT64)(UINTN) Db; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.receive () ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - switch (snp->cdb.StatCode) { + switch (Snp->Cdb.StatCode) { case PXE_STATCODE_SUCCESS: break; @@ -92,8 +86,8 @@ pxe_receive ( DEBUG ( (EFI_D_NET, "\nsnp->undi.receive () %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_NOT_READY; @@ -102,80 +96,107 @@ pxe_receive ( DEBUG ( (EFI_D_ERROR, "\nsnp->undi.receive() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_DEVICE_ERROR; } - *BuffSizePtr = db->FrameLen; + *BufferSize = Db->FrameLen; - if (HeaderSizePtr != NULL) { - *HeaderSizePtr = db->MediaHeaderLen; + if (HeaderSize != NULL) { + *HeaderSize = Db->MediaHeaderLen; } - if (SourceAddrPtr != NULL) { - CopyMem (SourceAddrPtr, &db->SrcAddr, snp->mode.HwAddressSize); + if (SrcAddr != NULL) { + CopyMem (SrcAddr, &Db->SrcAddr, Snp->Mode.HwAddressSize); } - if (DestinationAddrPtr != NULL) { - CopyMem (DestinationAddrPtr, &db->DestAddr, snp->mode.HwAddressSize); + if (DestAddr != NULL) { + CopyMem (DestAddr, &Db->DestAddr, Snp->Mode.HwAddressSize); } - if (ProtocolPtr != NULL) { - *ProtocolPtr = (UINT16) PXE_SWAP_UINT16 (db->Protocol); /* we need to do the byte swapping */ + if (Protocol != NULL) { + *Protocol = (UINT16) PXE_SWAP_UINT16 (Db->Protocol); /* we need to do the byte swapping */ } - return (*BuffSizePtr <= buf_size) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL; + return (*BufferSize <= BuffSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL; } - /** - This is the SNP interface routine for receiving network data. - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_receive routine to actually do the receive! - - @param this context pointer - @param HeaderSizePtr optional parameter and is a pointer to the header - portion of the data received. - @param BuffSizePtr is a pointer to the length of the buffer on entry and - contains the length of the received data on return - @param BufferPtr pointer to the memory for the received data - @param SourceAddrPtr optional parameter, is a pointer to contain the - source ethernet address on return - @param DestinationAddrPtr optional parameter, is a pointer to contain the - destination ethernet address on return - @param ProtocolPtr optional parameter, is a pointer to contain the - protocol type from the ethernet header on return - + Receives a packet from a network interface. + + This function retrieves one packet from the receive queue of a network interface. + If there are no packets on the receive queue, then EFI_NOT_READY will be + returned. If there is a packet on the receive queue, and the size of the packet + is smaller than BufferSize, then the contents of the packet will be placed in + Buffer, and BufferSize will be updated with the actual size of the packet. + In addition, if SrcAddr, DestAddr, and Protocol are not NULL, then these values + will be extracted from the media header and returned. EFI_SUCCESS will be + returned if a packet was successfully received. + If BufferSize is smaller than the received packet, then the size of the receive + packet will be placed in BufferSize and EFI_BUFFER_TOO_SMALL will be returned. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param HeaderSize The size, in bytes, of the media header received on the network + interface. If this parameter is NULL, then the media header size + will not be returned. + @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in + bytes, of the packet that was received on the network interface. + @param Buffer A pointer to the data buffer to receive both the media + header and the data. + @param SrcAddr The source HW MAC address. If this parameter is NULL, the HW + MAC source address will not be extracted from the media header. + @param DestAddr The destination HW MAC address. If this parameter is NULL, + the HW MAC destination address will not be extracted from + the media header. + @param Protocol The media header type. If this parameter is NULL, then the + protocol will not be extracted from the media header. See + RFC 1700 section "Ether Types" for examples. + + @retval EFI_SUCCESS The received data was stored in Buffer, and + BufferSize has been updated to the number of + bytes received. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_NOT_READY No packets have been received on the network interface. + @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the received packets. + BufferSize has been updated to the required size. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + * The This parameter is NULL + * The This parameter does not point to a valid + EFI_SIMPLE_NETWORK_PROTOCOL structure. + * The BufferSize parameter is NULL + * The Buffer parameter is NULL + @retval EFI_DEVICE_ERROR The command could not be sent to the network interface. **/ EFI_STATUS EFIAPI -snp_undi32_receive ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - OUT UINTN *HeaderSizePtr OPTIONAL, - IN OUT UINTN *BuffSizePtr, - OUT VOID *BufferPtr, - OUT EFI_MAC_ADDRESS * SourceAddrPtr OPTIONAL, - OUT EFI_MAC_ADDRESS * DestinationAddrPtr OPTIONAL, - OUT UINT16 *ProtocolPtr OPTIONAL +SnpUndi32Receive ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + OUT UINTN *HeaderSize OPTIONAL, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer, + OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL, + OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL, + OUT UINT16 *Protocol OPTIONAL ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_TPL OldTpl; EFI_STATUS Status; - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -188,24 +209,24 @@ snp_undi32_receive ( goto ON_EXIT; } - if ((BuffSizePtr == NULL) || (BufferPtr == NULL)) { + if ((BufferSize == NULL) || (Buffer == NULL)) { Status = EFI_INVALID_PARAMETER; goto ON_EXIT; } - if (!snp->mode.ReceiveFilterSetting) { + if (!Snp->Mode.ReceiveFilterSetting) { Status = EFI_DEVICE_ERROR; goto ON_EXIT; } - Status = pxe_receive ( - snp, - BufferPtr, - BuffSizePtr, - HeaderSizePtr, - SourceAddrPtr, - DestinationAddrPtr, - ProtocolPtr + Status = PxeReceive ( + Snp, + Buffer, + BufferSize, + HeaderSize, + SrcAddr, + DestAddr, + Protocol ); ON_EXIT: diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Receive_filters.c b/MdeModulePkg/Universal/Network/SnpDxe/Receive_filters.c index 343b516d9e..db116330cd 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Receive_filters.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Receive_filters.c @@ -25,7 +25,7 @@ Revision history: /** this routine calls undi to enable the receive filters. - @param snp pointer to snp driver structure + @param Snp pointer to snp driver structure @param EnableFlags bit mask for enabling the receive filters @param MCastAddressCount multicast address count for a new multicast address list @@ -34,68 +34,68 @@ Revision history: **/ EFI_STATUS -pxe_rcvfilter_enable ( - SNP_DRIVER *snp, +PxeRecvFilterEnable ( + SNP_DRIVER *Snp, UINT32 EnableFlags, UINTN MCastAddressCount, EFI_MAC_ADDRESS *MCastAddressList ) { - snp->cdb.OpCode = PXE_OPCODE_RECEIVE_FILTERS; - snp->cdb.OpFlags = PXE_OPFLAGS_RECEIVE_FILTER_ENABLE; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + Snp->Cdb.OpCode = PXE_OPCODE_RECEIVE_FILTERS; + Snp->Cdb.OpFlags = PXE_OPFLAGS_RECEIVE_FILTER_ENABLE; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; + 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; if ((EnableFlags & EFI_SIMPLE_NETWORK_RECEIVE_UNICAST) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_UNICAST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_UNICAST; } if ((EnableFlags & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST; } if ((EnableFlags & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS; } if ((EnableFlags & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST; } if ((EnableFlags & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST; } if (MCastAddressCount != 0) { - snp->cdb.CPBsize = (UINT16) (MCastAddressCount * sizeof (EFI_MAC_ADDRESS)); - snp->cdb.CPBaddr = (UINT64)(UINTN) snp->cpb; - CopyMem (snp->cpb, MCastAddressList, snp->cdb.CPBsize); + Snp->Cdb.CPBsize = (UINT16) (MCastAddressCount * sizeof (EFI_MAC_ADDRESS)); + Snp->Cdb.CPBaddr = (UINT64)(UINTN)Snp->Cpb; + CopyMem (Snp->Cpb, MCastAddressList, Snp->Cdb.CPBsize); } // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.receive_filters() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != EFI_SUCCESS) { + if (Snp->Cdb.StatCode != EFI_SUCCESS) { // // UNDI command failed. Return UNDI status to caller. // DEBUG ( (EFI_D_ERROR, "\nsnp->undi.receive_filters() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); - switch (snp->cdb.StatCode) { + switch (Snp->Cdb.StatCode) { case PXE_STATCODE_INVALID_CDB: case PXE_STATCODE_INVALID_CPB: case PXE_STATCODE_INVALID_PARAMETER: @@ -114,70 +114,70 @@ pxe_rcvfilter_enable ( /** this routine calls undi to disable the receive filters. - @param snp pointer to snp driver structure + @param Snp pointer to snp driver structure @param DisableFlags bit mask for disabling the receive filters @param ResetMCastList boolean flag to reset/delete the multicast filter list **/ EFI_STATUS -pxe_rcvfilter_disable ( - SNP_DRIVER *snp, +PxeRecvFilterDisable ( + SNP_DRIVER *Snp, UINT32 DisableFlags, BOOLEAN ResetMCastList ) { - snp->cdb.OpCode = PXE_OPCODE_RECEIVE_FILTERS; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; - - snp->cdb.OpFlags = (UINT16) (DisableFlags ? PXE_OPFLAGS_RECEIVE_FILTER_DISABLE : PXE_OPFLAGS_NOT_USED); + Snp->Cdb.OpCode = PXE_OPCODE_RECEIVE_FILTERS; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; + 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; + + Snp->Cdb.OpFlags = (UINT16) ((DisableFlags != 0) ? PXE_OPFLAGS_RECEIVE_FILTER_DISABLE : PXE_OPFLAGS_NOT_USED); if (ResetMCastList) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST; } if ((DisableFlags & EFI_SIMPLE_NETWORK_RECEIVE_UNICAST) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_UNICAST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_UNICAST; } if ((DisableFlags & EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST; } if ((DisableFlags & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS; } if ((DisableFlags & EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST; } if ((DisableFlags & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0) { - snp->cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST; + Snp->Cdb.OpFlags |= PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST; } // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.receive_filters() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != EFI_SUCCESS) { + if (Snp->Cdb.StatCode != EFI_SUCCESS) { // // UNDI command failed. Return UNDI status to caller. // DEBUG ( (EFI_D_ERROR, "\nsnp->undi.receive_filters() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_DEVICE_ERROR; @@ -189,45 +189,45 @@ pxe_rcvfilter_disable ( /** this routine calls undi to read the receive filters. - @param snp pointer to snp driver structure + @param Snp pointer to snp driver structure **/ EFI_STATUS -pxe_rcvfilter_read ( - SNP_DRIVER *snp +PxeRecvFilterRead ( + SNP_DRIVER *Snp ) { - snp->cdb.OpCode = PXE_OPCODE_RECEIVE_FILTERS; - snp->cdb.OpFlags = PXE_OPFLAGS_RECEIVE_FILTER_READ; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.DBsize = (UINT16) (snp->mode.MaxMCastFilterCount * sizeof (EFI_MAC_ADDRESS)); - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - if (snp->cdb.DBsize == 0) { - snp->cdb.DBaddr = (UINT64)(UINTN) NULL; + Snp->Cdb.OpCode = PXE_OPCODE_RECEIVE_FILTERS; + Snp->Cdb.OpFlags = PXE_OPFLAGS_RECEIVE_FILTER_READ; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.DBsize = (UINT16) (Snp->Mode.MaxMCastFilterCount * sizeof (EFI_MAC_ADDRESS)); + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + if (Snp->Cdb.DBsize == 0) { + Snp->Cdb.DBaddr = (UINT64)(UINTN) NULL; } else { - snp->cdb.DBaddr = (UINT64)(UINTN) snp->db; - ZeroMem (snp->db, snp->cdb.DBsize); + Snp->Cdb.DBaddr = (UINT64)(UINTN) Snp->Db; + ZeroMem (Snp->Db, Snp->Cdb.DBsize); } - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; DEBUG ((EFI_D_NET, "\nsnp->undi.receive_filters() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != EFI_SUCCESS) { + if (Snp->Cdb.StatCode != EFI_SUCCESS) { // // UNDI command failed. Return UNDI status to caller. // DEBUG ( (EFI_D_ERROR, "\nsnp->undi.receive_filters() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_DEVICE_ERROR; @@ -235,29 +235,29 @@ pxe_rcvfilter_read ( // // Convert UNDI32 StatFlags to EFI SNP filter flags. // - snp->mode.ReceiveFilterSetting = 0; + Snp->Mode.ReceiveFilterSetting = 0; - if ((snp->cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_UNICAST) != 0) { - snp->mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST; + if ((Snp->Cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_UNICAST) != 0) { + Snp->Mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST; } - if ((snp->cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_BROADCAST) != 0) { - snp->mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST; + if ((Snp->Cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_BROADCAST) != 0) { + Snp->Mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST; } - if ((snp->cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_PROMISCUOUS) != 0) { - snp->mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; + if ((Snp->Cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_PROMISCUOUS) != 0) { + Snp->Mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; } - if ((snp->cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) { - snp->mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; + if ((Snp->Cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) { + Snp->Mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; } - if ((snp->cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) != 0) { - snp->mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST; + if ((Snp->Cdb.StatFlags & PXE_STATFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) != 0) { + Snp->Mode.ReceiveFilterSetting |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST; } - CopyMem (snp->mode.MCastFilter, snp->db, snp->cdb.DBsize); + CopyMem (Snp->Mode.MCastFilter, Snp->Db, Snp->Cdb.DBsize); // // Count number of active entries in multicast filter list. @@ -267,12 +267,12 @@ pxe_rcvfilter_read ( SetMem (&ZeroMacAddr, sizeof ZeroMacAddr, 0); - for (snp->mode.MCastFilterCount = 0; - snp->mode.MCastFilterCount < snp->mode.MaxMCastFilterCount; - snp->mode.MCastFilterCount++ + for (Snp->Mode.MCastFilterCount = 0; + Snp->Mode.MCastFilterCount < Snp->Mode.MaxMCastFilterCount; + Snp->Mode.MCastFilterCount++ ) { if (CompareMem ( - &snp->mode.MCastFilter[snp->mode.MCastFilterCount], + &Snp->Mode.MCastFilter[Snp->Mode.MCastFilterCount], &ZeroMacAddr, sizeof ZeroMacAddr ) == 0) { @@ -286,46 +286,123 @@ pxe_rcvfilter_read ( /** - This is the SNP interface routine for reading/enabling/disabling the - receive filters. - This routine basically retrieves snp structure, checks the SNP state and - checks the parameter validity, calls one of the above routines to actually - do the work - - @param this context pointer - @param EnableFlags bit mask for enabling the receive filters - @param DisableFlags bit mask for disabling the receive filters - @param ResetMCastList boolean flag to reset/delete the multicast filter list - @param MCastAddressCount multicast address count for a new multicast address - list - @param MCastAddressList list of new multicast addresses - + Manages the multicast receive filters of a network interface. + + This function is used enable and disable the hardware and software receive + filters for the underlying network device. + The receive filter change is broken down into three steps: + * The filter mask bits that are set (ON) in the Enable parameter are added to + the current receive filter settings. + * The filter mask bits that are set (ON) in the Disable parameter are subtracted + from the updated receive filter settings. + * If the resulting receive filter setting is not supported by the hardware a + more liberal setting is selected. + If the same bits are set in the Enable and Disable parameters, then the bits + in the Disable parameter takes precedence. + If the ResetMCastFilter parameter is TRUE, then the multicast address list + filter is disabled (irregardless of what other multicast bits are set in the + Enable and Disable parameters). The SNP->Mode->MCastFilterCount field is set + to zero. The Snp->Mode->MCastFilter contents are undefined. + After enabling or disabling receive filter settings, software should verify + the new settings by checking the Snp->Mode->ReceiveFilterSettings, + Snp->Mode->MCastFilterCount and Snp->Mode->MCastFilter fields. + Note: Some network drivers and/or devices will automatically promote receive + filter settings if the requested setting can not be honored. For example, if + a request for four multicast addresses is made and the underlying hardware + only supports two multicast addresses the driver might set the promiscuous + or promiscuous multicast receive filters instead. The receiving software is + responsible for discarding any extra packets that get through the hardware + receive filters. + Note: Note: To disable all receive filter hardware, the network driver must + be Shutdown() and Stopped(). Calling ReceiveFilters() with Disable set to + Snp->Mode->ReceiveFilterSettings will make it so no more packets are + returned by the Receive() function, but the receive hardware may still be + moving packets into system memory before inspecting and discarding them. + Unexpected system errors, reboots and hangs can occur if an OS is loaded + and the network devices are not Shutdown() and Stopped(). + If ResetMCastFilter is TRUE, then the multicast receive filter list on the + network interface will be reset to the default multicast receive filter list. + If ResetMCastFilter is FALSE, and this network interface allows the multicast + receive filter list to be modified, then the MCastFilterCnt and MCastFilter + are used to update the current multicast receive filter list. The modified + receive filter list settings can be found in the MCastFilter field of + EFI_SIMPLE_NETWORK_MODE. If the network interface does not allow the multicast + receive filter list to be modified, then EFI_INVALID_PARAMETER will be returned. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + If the receive filter mask and multicast receive filter list have been + successfully updated on the network interface, EFI_SUCCESS will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param Enable A bit mask of receive filters to enable on the network + interface. + @param Disable A bit mask of receive filters to disable on the network + interface. For backward compatibility with EFI 1.1 + platforms, the EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST bit + must be set when the ResetMCastFilter parameter is TRUE. + @param ResetMCastFilter Set to TRUE to reset the contents of the multicast + receive filters on the network interface to their + default values. + @param MCastFilterCnt Number of multicast HW MAC addresses in the new MCastFilter + list. This value must be less than or equal to the + MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. + This field is optional if ResetMCastFilter is TRUE. + @param MCastFilter A pointer to a list of new multicast receive filter HW + MAC addresses. This list will replace any existing + multicast HW MAC address list. This field is optional + if ResetMCastFilter is TRUE. + + @retval EFI_SUCCESS The multicast receive filter list was updated. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + * This is NULL + * There are bits set in Enable that are not set + in Snp->Mode->ReceiveFilterMask + * There are bits set in Disable that are not set + in Snp->Mode->ReceiveFilterMask + * Multicast is being enabled (the + EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST bit is + set in Enable, it is not set in Disable, and + ResetMCastFilter is FALSE) and MCastFilterCount + is zero + * Multicast is being enabled and MCastFilterCount + is greater than Snp->Mode->MaxMCastFilterCount + * Multicast is being enabled and MCastFilter is NULL + * Multicast is being enabled and one or more of + the addresses in the MCastFilter list are not + valid multicast MAC addresses + @retval EFI_DEVICE_ERROR One or more of the following conditions is TRUE: + * The network interface has been started but has + not been initialized + * An unexpected error was returned by the + underlying network driver or device + @retval EFI_UNSUPPORTED This function is not supported by the network + interface. **/ EFI_STATUS EFIAPI -snp_undi32_receive_filters ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - IN UINT32 EnableFlags, - IN UINT32 DisableFlags, - IN BOOLEAN ResetMCastList, - IN UINTN MCastAddressCount OPTIONAL, - IN EFI_MAC_ADDRESS * MCastAddressList OPTIONAL +SnpUndi32ReceiveFilters ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN UINT32 Enable, + IN UINT32 Disable, + IN BOOLEAN ResetMCastFilter, + IN UINTN MCastFilterCnt, OPTIONAL + IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_STATUS Status; EFI_TPL OldTpl; - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -341,21 +418,21 @@ snp_undi32_receive_filters ( // check if we are asked to enable or disable something that the UNDI // does not even support! // - if (((EnableFlags &~snp->mode.ReceiveFilterMask) != 0) || - ((DisableFlags &~snp->mode.ReceiveFilterMask) != 0)) { + if (((Enable &~Snp->Mode.ReceiveFilterMask) != 0) || + ((Disable &~Snp->Mode.ReceiveFilterMask) != 0)) { Status = EFI_INVALID_PARAMETER; goto ON_EXIT; } - if (ResetMCastList) { + if (ResetMCastFilter) { - DisableFlags |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST & snp->mode.ReceiveFilterMask; - MCastAddressCount = 0; - MCastAddressList = NULL; + Disable |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST & Snp->Mode.ReceiveFilterMask; + MCastFilterCnt = 0; + MCastFilter = NULL; } else { - if (MCastAddressCount != 0) { - if ((MCastAddressCount > snp->mode.MaxMCastFilterCount) || - (MCastAddressList == NULL)) { + if (MCastFilterCnt != 0) { + if ((MCastFilterCnt > Snp->Mode.MaxMCastFilterCount) || + (MCastFilter == NULL)) { Status = EFI_INVALID_PARAMETER; goto ON_EXIT; @@ -363,38 +440,38 @@ snp_undi32_receive_filters ( } } - if (EnableFlags == 0 && DisableFlags == 0 && !ResetMCastList && MCastAddressCount == 0) { + if (Enable == 0 && Disable == 0 && !ResetMCastFilter && MCastFilterCnt == 0) { Status = EFI_SUCCESS; goto ON_EXIT; } - if ((EnableFlags & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0 && MCastAddressCount == 0) { + if ((Enable & EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST) != 0 && MCastFilterCnt == 0) { Status = EFI_INVALID_PARAMETER; goto ON_EXIT; } - if ((EnableFlags != 0) || (MCastAddressCount != 0)) { - Status = pxe_rcvfilter_enable ( - snp, - EnableFlags, - MCastAddressCount, - MCastAddressList - ); + if ((Enable != 0) || (MCastFilterCnt != 0)) { + Status = PxeRecvFilterEnable ( + Snp, + Enable, + MCastFilterCnt, + MCastFilter + ); if (EFI_ERROR (Status)) { goto ON_EXIT; } } - if ((DisableFlags != 0) || ResetMCastList) { - Status = pxe_rcvfilter_disable (snp, DisableFlags, ResetMCastList); + if ((Disable != 0) || ResetMCastFilter) { + Status = PxeRecvFilterDisable (Snp, Disable, ResetMCastFilter); if (EFI_ERROR (Status)) { goto ON_EXIT; } } - Status = pxe_rcvfilter_read (snp); + Status = PxeRecvFilterRead (Snp); ON_EXIT: gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Reset.c b/MdeModulePkg/Universal/Network/SnpDxe/Reset.c index cd396bbb09..f616d43584 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Reset.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Reset.c @@ -24,41 +24,41 @@ Revision history: /** This routine calls undi to reset the nic. - @param snp pointer to the snp driver structure + @param Snp pointer to the snp driver structure @return EFI_SUCCESSFUL for a successful completion @return other for failed calls **/ EFI_STATUS -pxe_reset ( - SNP_DRIVER *snp +PxeReset ( + SNP_DRIVER *Snp ) { - snp->cdb.OpCode = PXE_OPCODE_RESET; - snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + Snp->Cdb.OpCode = PXE_OPCODE_RESET; + Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; + 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; // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.reset() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) { + if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) { DEBUG ( (EFI_D_WARN, "\nsnp->undi32.reset() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); // @@ -72,23 +72,37 @@ pxe_reset ( /** - This is the SNP interface routine for resetting the NIC - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_reset routine to actually do the reset! - - @param this context pointer - @param ExtendedVerification not implemented - + Resets a network adapter and reinitializes it with the parameters that were + provided in the previous call to Initialize(). + + This function resets a network adapter and reinitializes it with the parameters + that were provided in the previous call to Initialize(). The transmit and + receive queues are emptied and all pending interrupts are cleared. + Receive filters, the station address, the statistics, and the multicast-IP-to-HW + MAC addresses are not reset by this call. If the network interface was + successfully reset, then EFI_SUCCESS will be returned. If the driver has not + been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param ExtendedVerification Indicates that the driver may perform a more + exhaustive verification operation of the device + during reset. + + @retval EFI_SUCCESS The network interface was reset. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value. + @retval EFI_DEVICE_ERROR The command could not be sent to the network interface. + @retval EFI_UNSUPPORTED This function is not supported by the network interface. **/ EFI_STATUS EFIAPI -snp_undi32_reset ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this, +SnpUndi32Reset ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN ExtendedVerification ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_TPL OldTpl; EFI_STATUS Status; @@ -98,15 +112,15 @@ snp_undi32_reset ( ExtendedVerification = 0; DEBUG ((EFI_D_WARN, "ExtendedVerification = %d is not implemented!\n", ExtendedVerification)); - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -119,7 +133,7 @@ snp_undi32_reset ( goto ON_EXIT; } - Status = pxe_reset (snp); + Status = PxeReset (Snp); ON_EXIT: gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Shutdown.c b/MdeModulePkg/Universal/Network/SnpDxe/Shutdown.c index 8e0ae45503..a996c2c50a 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Shutdown.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Shutdown.c @@ -1,21 +1,15 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of shuting down a network adapter. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - shutdown.c - -Abstract: - -Revision history: - 2000-Feb-14 M(f)J Genesis. - **/ #include "Snp.h" @@ -24,93 +18,105 @@ Revision history: /** this routine calls undi to shut down the interface. - @param snp pointer to snp driver structure + @param Snp pointer to snp driver structure + @retval EFI_SUCCESS UNDI is shut down successfully + @retval EFI_DEVICE_ERROR UNDI could not be shut down **/ EFI_STATUS -pxe_shutdown ( - IN SNP_DRIVER *snp +PxeShutdown ( + IN SNP_DRIVER *Snp ) { - snp->cdb.OpCode = PXE_OPCODE_SHUTDOWN; - snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + Snp->Cdb.OpCode = PXE_OPCODE_SHUTDOWN; + Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; + 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; // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.shutdown() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) { + if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) { // // UNDI could not be shutdown. Return UNDI error. // - DEBUG ((EFI_D_WARN, "\nsnp->undi.shutdown() %xh:%xh\n", snp->cdb.StatFlags, snp->cdb.StatCode)); + DEBUG ((EFI_D_WARN, "\nsnp->undi.shutdown() %xh:%xh\n", Snp->Cdb.StatFlags, Snp->Cdb.StatCode)); return EFI_DEVICE_ERROR; } // // Free allocated memory. // - if (snp->tx_rx_buffer != NULL) { - snp->IoFncs->FreeBuffer ( - snp->IoFncs, - SNP_MEM_PAGES (snp->tx_rx_bufsize), - (VOID *) snp->tx_rx_buffer + if (Snp->TxRxBuffer != NULL) { + Snp->PciIo->FreeBuffer ( + Snp->PciIo, + SNP_MEM_PAGES (Snp->TxRxBufferSize), + (VOID *) Snp->TxRxBuffer ); } - snp->tx_rx_buffer = NULL; - snp->tx_rx_bufsize = 0; + Snp->TxRxBuffer = NULL; + Snp->TxRxBufferSize = 0; return EFI_SUCCESS; } /** - This is the SNP interface routine for shutting down the interface - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_shutdown routine to actually do the undi shutdown - - @param this context pointer - + Resets a network adapter and leaves it in a state that is safe for another + driver to initialize. + + This function releases the memory buffers assigned in the Initialize() call. + Pending transmits and receives are lost, and interrupts are cleared and disabled. + After this call, only the Initialize() and Stop() calls may be used. If the + network interface was successfully shutdown, then EFI_SUCCESS will be returned. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + + @retval EFI_SUCCESS The network interface was shutdown. + @retval EFI_NOT_STARTED The network interface has not been started. + @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. **/ EFI_STATUS EFIAPI -snp_undi32_shutdown ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this +SnpUndi32Shutdown ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_STATUS Status; EFI_TPL OldTpl; // + // Get pointer to SNP driver instance for *This. // - // - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); // + // Return error if the SNP is not initialized. // - // - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -122,24 +128,22 @@ snp_undi32_shutdown ( Status = EFI_DEVICE_ERROR; goto ON_EXIT; } - // - // - // - Status = pxe_shutdown (snp); + + Status = PxeShutdown (Snp); - snp->mode.State = EfiSimpleNetworkStarted; - snp->mode.ReceiveFilterSetting = 0; + Snp->Mode.State = EfiSimpleNetworkStarted; + Snp->Mode.ReceiveFilterSetting = 0; - snp->mode.MCastFilterCount = 0; - snp->mode.ReceiveFilterSetting = 0; - ZeroMem (snp->mode.MCastFilter, sizeof snp->mode.MCastFilter); + Snp->Mode.MCastFilterCount = 0; + Snp->Mode.ReceiveFilterSetting = 0; + ZeroMem (Snp->Mode.MCastFilter, sizeof Snp->Mode.MCastFilter); CopyMem ( - &snp->mode.CurrentAddress, - &snp->mode.PermanentAddress, + &Snp->Mode.CurrentAddress, + &Snp->Mode.PermanentAddress, sizeof (EFI_MAC_ADDRESS) ); - gBS->CloseEvent (snp->snp.WaitForPacket); + gBS->CloseEvent (Snp->Snp.WaitForPacket); ON_EXIT: gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Snp.c b/MdeModulePkg/Universal/Network/SnpDxe/Snp.c index 267dde67d5..80a05f102f 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Snp.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Snp.c @@ -1,264 +1,42 @@ /** @file -Copyright (c) 2004 - 2005, Intel Corporation -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 + Implementation of driver entry point and driver binding protocol. + +Copyright (c) 2004 - 2008, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - snp.c - -Abstract: - - **/ #include "Snp.h" -EFI_STATUS -pxe_start ( - SNP_DRIVER *snp - ); -EFI_STATUS -pxe_stop ( - SNP_DRIVER *snp - ); -EFI_STATUS -pxe_init ( - SNP_DRIVER *snp, - UINT16 OpFlags - ); -EFI_STATUS -pxe_shutdown ( - SNP_DRIVER *snp - ); -EFI_STATUS -pxe_get_stn_addr ( - SNP_DRIVER *snp - ); - -EFI_STATUS -EFIAPI -InitializeSnpNiiDriver ( - IN EFI_HANDLE image_handle, - IN EFI_SYSTEM_TABLE *system_table - ); - -EFI_STATUS -EFIAPI -SimpleNetworkDriverSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ); - -EFI_STATUS -EFIAPI -SimpleNetworkDriverStart ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath - ); - -EFI_STATUS -EFIAPI -SimpleNetworkDriverStop ( - IN EFI_DRIVER_BINDING_PROTOCOL *This, - IN EFI_HANDLE Controller, - IN UINTN NumberOfChildren, - IN EFI_HANDLE *ChildHandleBuffer - ); - -// -// Simple Network Protocol Driver Global Variables -// -EFI_DRIVER_BINDING_PROTOCOL mSimpleNetworkDriverBinding = { - SimpleNetworkDriverSupported, - SimpleNetworkDriverStart, - SimpleNetworkDriverStop, - 0xa, - NULL, - NULL -}; - // // Module global variables needed to support undi 3.0 interface // -EFI_PCI_IO_PROTOCOL *mPciIoFncs; -struct s_v2p *_v2p = NULL; // undi3.0 map_list head +EFI_PCI_IO_PROTOCOL *mPciIo; +V2P *mV2p = NULL; // undi3.0 map_list head // End Global variables // -/** - 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 vaddr virtual address (or CPU address) to be mapped - @param bsize size of the buffer to be mapped. - - @retval EFI_SUCEESS routine has completed the mapping - @retval other error as indicated. - -**/ -EFI_STATUS -add_v2p ( - IN OUT struct s_v2p **v2p, - EFI_PCI_IO_PROTOCOL_OPERATION type, - VOID *vaddr, - UINTN bsize - ) -{ - EFI_STATUS Status; - - if ((v2p == NULL) || (vaddr == NULL) || (bsize == 0)) { - return EFI_INVALID_PARAMETER; - } - - *v2p = AllocatePool (sizeof (struct s_v2p)); - if (*v2p != NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Status = mPciIoFncs->Map ( - mPciIoFncs, - type, - vaddr, - &bsize, - &(*v2p)->paddr, - &(*v2p)->unmap - ); - if (Status != EFI_SUCCESS) { - FreePool (*v2p); - return Status; - } - (*v2p)->vaddr = vaddr; - (*v2p)->bsize = bsize; - (*v2p)->next = _v2p; - _v2p = *v2p; - - 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 vaddr virtual address (or CPU address) to be searched in - the map list - - @retval EFI_SUCEESS if a match found! - @retval Other match not found + Unsupport currently. + + @param Cdb command to be sent to UNDI. **/ EFI_STATUS -find_v2p ( - struct s_v2p **v2p, - VOID *vaddr +IssueHwUndiCommand ( + UINT64 Cdb ) { - struct s_v2p *v; + DEBUG ((EFI_D_ERROR, "\nIssueHwUndiCommand() - This should not be called!")); - if (v2p == NULL || vaddr == NULL) { - return EFI_INVALID_PARAMETER; - } - - for (v = _v2p; v != NULL; v = v->next) { - if (v->vaddr == vaddr) { - *v2p = v; - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - - -/** - This routine unmaps the given virtual address and frees the memory allocated - for the map list node corresponding to that address. - - @param vaddr virtual address (or CPU address) to be unmapped - - @retval EFI_SUCEESS if successfully unmapped - @retval Other as indicated by the error - -**/ -EFI_STATUS -del_v2p ( - VOID *vaddr - ) -{ - struct s_v2p *v; - struct s_v2p *t; - EFI_STATUS Status; - - if (vaddr == NULL) { - return EFI_INVALID_PARAMETER; - } - - if (_v2p == NULL) { - return EFI_NOT_FOUND; - } - // - // Is our node at the head of the list?? - // - if ((v = _v2p)->vaddr == vaddr) { - _v2p = _v2p->next; - - Status = mPciIoFncs->Unmap (mPciIoFncs, v->unmap); - - FreePool (v); - - if (Status) { - DEBUG ((EFI_D_ERROR, "Unmap failed with status = %r\n", Status)); - } - return Status; - } - - for (; v->next != NULL; v = t) { - if ((t = v->next)->vaddr == vaddr) { - v->next = t->next; - Status = mPciIoFncs->Unmap (mPciIoFncs, t->unmap); - FreePool (t); - - if (Status) { - DEBUG ((EFI_D_ERROR, "Unmap failed with status = %r\n", Status)); - } - return Status; - } - } - - return EFI_NOT_FOUND; -} - -EFI_STATUS -issue_hwundi_command ( - UINT64 cdb - ) -/*++ - -Routine Description: - -Arguments: - -Returns: - ---*/ -{ - DEBUG ((EFI_D_ERROR, "\nissue_hwundi_command() - This should not be called!")); - - if (cdb == 0) { + if (Cdb == 0) { return EFI_INVALID_PARAMETER; } @@ -272,48 +50,52 @@ Returns: /** Compute 8-bit checksum of a buffer. - @param ptr Pointer to buffer. - @param len Length of buffer in bytes. + @param Buffer Pointer to buffer. + @param Length Length of buffer in bytes. @return 8-bit checksum of all bytes in buffer. @return If ptr is NULL or len is zero, zero is returned. **/ UINT8 -calc_8bit_cksum ( - VOID *ptr, - UINTN len +Calc8BitCksum ( + VOID *Buffer, + UINTN Length ) { - UINT8 *bptr; - UINT8 cksum; + UINT8 *Ptr; + UINT8 Cksum; - bptr = ptr; - cksum = 0; + Ptr = Buffer; + Cksum = 0; - if (ptr == NULL || len == 0) { + if (Ptr == NULL || Length == 0) { return 0; } - while (len--) { - cksum = (UINT8) (cksum +*bptr++); + while (Length-- != 0) { + Cksum = (UINT8) (Cksum + *Ptr++); } - return cksum; + return Cksum; } - /** - Test to see if this driver supports Controller. Any Controller - that contains a Nii protocol can be supported. - - @param This Protocol instance pointer. - @param Controller Handle of device to test. - @param RemainingDevicePath Not used. - - @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. + 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. + @param ControllerHandle Handle of device to test + @param RemainingDevicePath Optional parameter use to pick a specific child + device to start. + + @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 **/ EFI_STATUS @@ -326,7 +108,7 @@ SimpleNetworkDriverSupported ( { EFI_STATUS Status; EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *NiiProtocol; - PXE_UNDI *pxe; + PXE_UNDI *Pxe; Status = gBS->OpenProtocol ( Controller, @@ -374,30 +156,30 @@ SimpleNetworkDriverSupported ( goto Done; } - pxe = (PXE_UNDI *) (UINTN) (NiiProtocol->ID); + Pxe = (PXE_UNDI *) (UINTN) (NiiProtocol->ID); // // Verify !PXE revisions. // - if (pxe->hw.Signature != PXE_ROMID_SIGNATURE) { + if (Pxe->hw.Signature != PXE_ROMID_SIGNATURE) { DEBUG ((EFI_D_NET, "\n!PXE signature is not valid.\n")); Status = EFI_UNSUPPORTED; goto Done; } - if (pxe->hw.Rev < PXE_ROMID_REV) { + if (Pxe->hw.Rev < PXE_ROMID_REV) { DEBUG ((EFI_D_NET, "\n!PXE.Rev is not supported.\n")); Status = EFI_UNSUPPORTED; goto Done; } - if (pxe->hw.MajorVer < PXE_ROMID_MAJORVER) { + if (Pxe->hw.MajorVer < PXE_ROMID_MAJORVER) { DEBUG ((EFI_D_NET, "\n!PXE.MajorVer is not supported.\n")); Status = EFI_UNSUPPORTED; goto Done; - } else if (pxe->hw.MajorVer == PXE_ROMID_MAJORVER && pxe->hw.MinorVer < PXE_ROMID_MINORVER) { + } else if (Pxe->hw.MajorVer == PXE_ROMID_MAJORVER && Pxe->hw.MinorVer < PXE_ROMID_MINORVER) { DEBUG ((EFI_D_NET, "\n!PXE.MinorVer is not supported.")); Status = EFI_UNSUPPORTED; goto Done; @@ -405,14 +187,14 @@ SimpleNetworkDriverSupported ( // // Do S/W UNDI specific checks. // - if ((pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) == 0) { - if (pxe->sw.EntryPoint < pxe->sw.Len) { + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) == 0) { + if (Pxe->sw.EntryPoint < Pxe->sw.Len) { DEBUG ((EFI_D_NET, "\n!PXE S/W entry point is not valid.")); Status = EFI_UNSUPPORTED; goto Done; } - if (pxe->sw.BusCnt == 0) { + if (Pxe->sw.BusCnt == 0) { DEBUG ((EFI_D_NET, "\n!PXE.BusCnt is zero.")); Status = EFI_UNSUPPORTED; goto Done; @@ -433,16 +215,22 @@ Done: return Status; } - /** - called for any handle that we said "supported" in the above call! + 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. @param This Protocol instance pointer. - @param Controller Handle of device to start - @param RemainingDevicePath Not used. + @param ControllerHandle Handle of device to bind driver to. + @param RemainingDevicePath Optional parameter use to pick a specific child + device to start. - @retval EFI_SUCCESS This driver supports this device. - @retval other This driver failed to start this device. + @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 **/ EFI_STATUS @@ -456,9 +244,9 @@ SimpleNetworkDriverStart ( EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii; EFI_DEVICE_PATH_PROTOCOL *NiiDevicePath; EFI_STATUS Status; - PXE_UNDI *pxe; - SNP_DRIVER *snp; - VOID *addr; + PXE_UNDI *Pxe; + SNP_DRIVER *Snp; + VOID *Address; EFI_HANDLE Handle; PXE_PCI_CONFIG_INFO ConfigInfo; PCI_TYPE00 *ConfigHeader; @@ -494,7 +282,7 @@ SimpleNetworkDriverStart ( Status = gBS->OpenProtocol ( Handle, &gEfiPciIoProtocolGuid, - (VOID **) &mPciIoFncs, + (VOID **) &mPciIo, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL @@ -525,18 +313,18 @@ SimpleNetworkDriverStart ( DEBUG ((EFI_D_INFO, "Start(): UNDI3.1 found\n")); - pxe = (PXE_UNDI *) (UINTN) (Nii->ID); + Pxe = (PXE_UNDI *) (UINTN) (Nii->ID); - if (calc_8bit_cksum (pxe, pxe->hw.Len) != 0) { + if (Calc8BitCksum (Pxe, Pxe->hw.Len) != 0) { DEBUG ((EFI_D_NET, "\n!PXE checksum is not correct.\n")); goto NiiError; } - if ((pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) { + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) { // // We can get any packets. // - } else if ((pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) { + } else if ((Pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) { // // We need to be able to get broadcast packets for DHCP. // If we do not have promiscuous support, we must at least have @@ -550,12 +338,12 @@ SimpleNetworkDriverStart ( // 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. // - Status = mPciIoFncs->AllocateBuffer ( - mPciIoFncs, + Status = mPciIo->AllocateBuffer ( + mPciIo, AllocateAnyPages, EfiBootServicesData, SNP_MEM_PAGES (sizeof (SNP_DRIVER)), - &addr, + &Address, 0 ); @@ -564,48 +352,48 @@ SimpleNetworkDriverStart ( goto NiiError; } - snp = (SNP_DRIVER *) (UINTN) addr; + Snp = (SNP_DRIVER *) (UINTN) Address; - ZeroMem (snp, sizeof (SNP_DRIVER)); + ZeroMem (Snp, sizeof (SNP_DRIVER)); - snp->IoFncs = mPciIoFncs; - snp->Signature = SNP_DRIVER_SIGNATURE; + Snp->PciIo = mPciIo; + Snp->Signature = SNP_DRIVER_SIGNATURE; - EfiInitializeLock (&snp->lock, TPL_NOTIFY); + EfiInitializeLock (&Snp->Lock, TPL_NOTIFY); - snp->snp.Revision = EFI_SIMPLE_NETWORK_PROTOCOL_REVISION; - snp->snp.Start = snp_undi32_start; - snp->snp.Stop = snp_undi32_stop; - snp->snp.Initialize = snp_undi32_initialize; - snp->snp.Reset = snp_undi32_reset; - snp->snp.Shutdown = snp_undi32_shutdown; - snp->snp.ReceiveFilters = snp_undi32_receive_filters; - snp->snp.StationAddress = snp_undi32_station_address; - snp->snp.Statistics = snp_undi32_statistics; - snp->snp.MCastIpToMac = snp_undi32_mcast_ip_to_mac; - snp->snp.NvData = snp_undi32_nvdata; - snp->snp.GetStatus = snp_undi32_get_status; - snp->snp.Transmit = snp_undi32_transmit; - snp->snp.Receive = snp_undi32_receive; - snp->snp.WaitForPacket = NULL; + 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; - snp->snp.Mode = &snp->mode; + Snp->Snp.Mode = &Snp->Mode; - snp->tx_rx_bufsize = 0; - snp->tx_rx_buffer = NULL; + Snp->TxRxBufferSize = 0; + Snp->TxRxBuffer = NULL; - snp->if_num = Nii->IfNum; + Snp->IfNum = Nii->IfNum; - if ((pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) != 0) { - snp->is_swundi = FALSE; - snp->issue_undi32_command = &issue_hwundi_command; + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_HW_UNDI) != 0) { + Snp->IsSwUndi = FALSE; + Snp->IssueUndi32Command = &IssueHwUndiCommand; } else { - snp->is_swundi = TRUE; + Snp->IsSwUndi = TRUE; - if ((pxe->sw.Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR) != 0) { - snp->issue_undi32_command = (issue_undi32_command) (UINTN) pxe->sw.EntryPoint; + if ((Pxe->sw.Implementation & PXE_ROMID_IMP_SW_VIRT_ADDR) != 0) { + Snp->IssueUndi32Command = (ISSUE_UNDI32_COMMAND) (UINTN) Pxe->sw.EntryPoint; } else { - snp->issue_undi32_command = (issue_undi32_command) (UINTN) ((UINT8) (UINTN) pxe + pxe->sw.EntryPoint); + Snp->IssueUndi32Command = (ISSUE_UNDI32_COMMAND) (UINTN) ((UINT8) (UINTN) Pxe + Pxe->sw.EntryPoint); } } // @@ -624,12 +412,12 @@ SimpleNetworkDriverStart ( // -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! // - Status = mPciIoFncs->AllocateBuffer ( - mPciIoFncs, + Status = mPciIo->AllocateBuffer ( + mPciIo, AllocateAnyPages, EfiBootServicesData, SNP_MEM_PAGES (4096), - &addr, + &Address, 0 ); @@ -638,81 +426,81 @@ SimpleNetworkDriverStart ( goto Error_DeleteSNP; } - snp->cpb = (VOID *) (UINTN) addr; - snp->db = (VOID *) ((UINTN) addr + 2048); + Snp->Cpb = (VOID *) (UINTN) Address; + Snp->Db = (VOID *) ((UINTN) Address + 2048); // - // pxe_start call is going to give the callback functions to UNDI, these callback + // PxeStart call is going to give the callback functions to UNDI, these callback // functions use the BarIndex values from the snp structure, so these must be initialized - // with default values before doing a pxe_start. The correct values can be obtained after + // with default values before doing a PxeStart. The correct values can be obtained after // getting the config information from UNDI // - snp->MemoryBarIndex = 0; - snp->IoBarIndex = 1; + Snp->MemoryBarIndex = 0; + Snp->IoBarIndex = 1; // // 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. // - Status = pxe_start (snp); + Status = PxeStart (Snp); if (Status != EFI_SUCCESS) { goto Error_DeleteSNP; } - snp->cdb.OpCode = PXE_OPCODE_GET_INIT_INFO; - snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED; + Snp->Cdb.OpCode = PXE_OPCODE_GET_INIT_INFO; + Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_DBADDR_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.DBsize = sizeof snp->init_info; - snp->cdb.DBaddr = (UINT64)(UINTN) &snp->init_info; + Snp->Cdb.DBsize = sizeof Snp->InitInfo; + Snp->Cdb.DBaddr = (UINT64)(UINTN) &Snp->InitInfo; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; + Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE; + Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + Snp->Cdb.IFnum = Snp->IfNum; + Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; - DEBUG ((EFI_D_NET, "\nsnp->undi.get_init_info() ")); + DEBUG ((EFI_D_NET, "\nSnp->undi.get_init_info() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); // // Save the INIT Stat Code... // - InitStatFlags = snp->cdb.StatFlags; + InitStatFlags = Snp->Cdb.StatFlags; - if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) { - DEBUG ((EFI_D_NET, "\nsnp->undi.init_info() %xh:%xh\n", snp->cdb.StatFlags, snp->cdb.StatCode)); - pxe_stop (snp); + if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) { + DEBUG ((EFI_D_NET, "\nSnp->undi.init_info() %xh:%xh\n", Snp->Cdb.StatFlags, Snp->Cdb.StatCode)); + PxeStop (Snp); goto Error_DeleteSNP; } - snp->cdb.OpCode = PXE_OPCODE_GET_CONFIG_INFO; - snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED; + Snp->Cdb.OpCode = PXE_OPCODE_GET_CONFIG_INFO; + Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_DBADDR_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.DBsize = sizeof ConfigInfo; - snp->cdb.DBaddr = (UINT64)(UINTN) &ConfigInfo; + Snp->Cdb.DBsize = sizeof ConfigInfo; + Snp->Cdb.DBaddr = (UINT64)(UINTN) &ConfigInfo; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; + Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE; + Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + Snp->Cdb.IFnum = Snp->IfNum; + Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; - DEBUG ((EFI_D_NET, "\nsnp->undi.get_config_info() ")); + DEBUG ((EFI_D_NET, "\nSnp->undi.get_config_info() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) { - DEBUG ((EFI_D_NET, "\nsnp->undi.config_info() %xh:%xh\n", snp->cdb.StatFlags, snp->cdb.StatCode)); - pxe_stop (snp); + if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) { + DEBUG ((EFI_D_NET, "\nSnp->undi.config_info() %xh:%xh\n", Snp->Cdb.StatFlags, Snp->Cdb.StatCode)); + PxeStop (Snp); goto Error_DeleteSNP; } // @@ -735,7 +523,7 @@ SimpleNetworkDriverStart ( } if ((*TempBar & PCI_BAR_IO_MASK) == PCI_BAR_IO_MODE) { - snp->IoBarIndex = BarIndex; + Snp->IoBarIndex = BarIndex; break; } @@ -745,102 +533,102 @@ SimpleNetworkDriverStart ( // // Initialize simple network protocol mode structure // - snp->mode.State = EfiSimpleNetworkStopped; - snp->mode.HwAddressSize = snp->init_info.HWaddrLen; - snp->mode.MediaHeaderSize = snp->init_info.MediaHeaderLen; - snp->mode.MaxPacketSize = snp->init_info.FrameDataLen; - snp->mode.NvRamAccessSize = snp->init_info.NvWidth; - snp->mode.NvRamSize = snp->init_info.NvCount * snp->mode.NvRamAccessSize; - snp->mode.IfType = snp->init_info.IFtype; - snp->mode.MaxMCastFilterCount = snp->init_info.MCastFilterCnt; - snp->mode.MCastFilterCount = 0; + 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; switch (InitStatFlags & PXE_STATFLAGS_CABLE_DETECT_MASK) { case PXE_STATFLAGS_CABLE_DETECT_SUPPORTED: - snp->mode.MediaPresentSupported = TRUE; + Snp->Mode.MediaPresentSupported = TRUE; break; case PXE_STATFLAGS_CABLE_DETECT_NOT_SUPPORTED: default: - snp->mode.MediaPresentSupported = FALSE; + Snp->Mode.MediaPresentSupported = FALSE; } - if ((pxe->hw.Implementation & PXE_ROMID_IMP_STATION_ADDR_SETTABLE) != 0) { - snp->mode.MacAddressChangeable = TRUE; + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_STATION_ADDR_SETTABLE) != 0) { + Snp->Mode.MacAddressChangeable = TRUE; } else { - snp->mode.MacAddressChangeable = FALSE; + Snp->Mode.MacAddressChangeable = FALSE; } - if ((pxe->hw.Implementation & PXE_ROMID_IMP_MULTI_FRAME_SUPPORTED) != 0) { - snp->mode.MultipleTxSupported = TRUE; + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_MULTI_FRAME_SUPPORTED) != 0) { + Snp->Mode.MultipleTxSupported = TRUE; } else { - snp->mode.MultipleTxSupported = FALSE; + Snp->Mode.MultipleTxSupported = FALSE; } - snp->mode.ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST; + Snp->Mode.ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST; - if ((pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) != 0) { - snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) != 0) { + Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; } - if ((pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) { - snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED) != 0) { + Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; } - if ((pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) { - snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST; + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED) != 0) { + Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST; } - if ((pxe->hw.Implementation & PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED) != 0) { - snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST; + if ((Pxe->hw.Implementation & PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED) != 0) { + Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST; } - if (pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) { - snp->mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; + if (Pxe->hw.Implementation & PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED) { + Snp->Mode.ReceiveFilterMask |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST; } - snp->mode.ReceiveFilterSetting = 0; + Snp->Mode.ReceiveFilterSetting = 0; // // need to get the station address to save in the mode structure. we need to // initialize the UNDI first for this. // - snp->tx_rx_bufsize = snp->init_info.MemoryRequired; - Status = pxe_init (snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE); + Snp->TxRxBufferSize = Snp->InitInfo.MemoryRequired; + Status = PxeInit (Snp, PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE); - if (Status) { - pxe_stop (snp); + if (EFI_ERROR (Status)) { + PxeStop (Snp); goto Error_DeleteSNP; } - Status = pxe_get_stn_addr (snp); + Status = PxeGetStnAddr (Snp); if (Status != EFI_SUCCESS) { - DEBUG ((EFI_D_ERROR, "\nsnp->undi.get_station_addr() failed.\n")); - pxe_shutdown (snp); - pxe_stop (snp); + DEBUG ((EFI_D_ERROR, "\nSnp->undi.get_station_addr() failed.\n")); + PxeShutdown (Snp); + PxeStop (Snp); goto Error_DeleteSNP; } - snp->mode.MediaPresent = FALSE; + Snp->Mode.MediaPresent = FALSE; // // 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! - // The UNDI layer will be started when upper layers call snp->start. + // The UNDI layer will be started when upper layers call Snp->start. // 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! // - pxe_shutdown (snp); - pxe_stop (snp); + PxeShutdown (Snp); + PxeStop (Snp); // // add SNP to the undi handle @@ -849,25 +637,25 @@ SimpleNetworkDriverStart ( &Controller, &gEfiSimpleNetworkProtocolGuid, EFI_NATIVE_INTERFACE, - &(snp->snp) + &(Snp->Snp) ); if (!EFI_ERROR (Status)) { return Status; } - Status = mPciIoFncs->FreeBuffer ( - mPciIoFncs, + Status = mPciIo->FreeBuffer ( + mPciIo, SNP_MEM_PAGES (4096), - snp->cpb + Snp->Cpb ); Error_DeleteSNP: - mPciIoFncs->FreeBuffer ( - mPciIoFncs, + mPciIo->FreeBuffer ( + mPciIo, SNP_MEM_PAGES (sizeof (SNP_DRIVER)), - snp + Snp ); NiiError: gBS->CloseProtocol ( @@ -887,10 +675,22 @@ NiiError: return Status; } - /** - - + 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. + + @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 **/ EFI_STATUS @@ -927,7 +727,7 @@ SimpleNetworkDriverStop ( Status = gBS->UninstallProtocolInterface ( Controller, &gEfiSimpleNetworkProtocolGuid, - &Snp->snp + &Snp->Snp ); if (EFI_ERROR (Status)) { @@ -948,17 +748,17 @@ SimpleNetworkDriverStop ( Controller ); - pxe_shutdown (Snp); - pxe_stop (Snp); + PxeShutdown (Snp); + PxeStop (Snp); - mPciIoFncs->FreeBuffer ( - mPciIoFncs, + mPciIo->FreeBuffer ( + mPciIo, SNP_MEM_PAGES (4096), - Snp->cpb + Snp->Cpb ); - mPciIoFncs->FreeBuffer ( - mPciIoFncs, + mPciIo->FreeBuffer ( + mPciIo, SNP_MEM_PAGES (sizeof (SNP_DRIVER)), Snp ); @@ -966,18 +766,183 @@ SimpleNetworkDriverStop ( return Status; } +// +// 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; + } + + *V2p = AllocatePool (sizeof (V2P )); + if (*V2p != NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = mPciIo->Map ( + mPciIo, + Type, + VirtualAddress, + &BufferSize, + &(*V2p)->PhysicalAddress, + &(*V2p)->Unmap + ); + if (Status != EFI_SUCCESS) { + FreePool (*V2p); + return Status; + } + (*V2p)->VirtualAddress = VirtualAddress; + (*V2p)->BufferSize = BufferSize; + (*V2p)->Next = mV2p; + mV2p = *V2p; + + 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 + + @retval EFI_SUCEESS if a match found! + @retval Other match not found + +**/ +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; +} + + +/** + This routine unmaps the given virtual address and frees the memory allocated + for the map list node corresponding to that address. + + @param VirtualAddress virtual address (or CPU address) to be unmapped + + @retval EFI_SUCEESS if successfully unmapped + @retval Other as indicated by the error + +**/ +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; +} /** - Install all the driver protocol + The SNP driver entry point. - @param entry EFI_IMAGE_ENTRY_POINT) + @param ImageHandle The driver image handle. + @param SystemTable The system table. - @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 + @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 **/ EFI_STATUS diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Snp.h b/MdeModulePkg/Universal/Network/SnpDxe/Snp.h index 4532ab4796..8ef5f97a80 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Snp.h +++ b/MdeModulePkg/Universal/Network/SnpDxe/Snp.h @@ -1,25 +1,18 @@ /** @file + Declaration of strctures and functions for SnpDxe driver. -Copyright (c) 2004 - 2007, Intel Corporation -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 +Copyright (c) 2004 - 2008, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - snp.h - -Abstract: - -Revision history: - - **/ -#ifndef _SNP_H -#define _SNP_H +#ifndef _SNP_H_ +#define _SNP_H_ #include @@ -52,15 +45,21 @@ Revision history: #define PCI_BAR_MEM_MODE 0x00000000 #define PCI_BAR_MEM_64BIT 0x00000004 +typedef +EFI_STATUS +(*ISSUE_UNDI32_COMMAND) ( + UINT64 Cdb + ); + typedef struct { UINT32 Signature; - EFI_LOCK lock; + EFI_LOCK Lock; - EFI_SIMPLE_NETWORK_PROTOCOL snp; - EFI_SIMPLE_NETWORK_MODE mode; + EFI_SIMPLE_NETWORK_PROTOCOL Snp; + EFI_SIMPLE_NETWORK_MODE Mode; - EFI_HANDLE device_handle; - EFI_DEVICE_PATH_PROTOCOL *device_path; + EFI_HANDLE DeviceHandle; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; // // Local instance data needed by SNP driver @@ -68,31 +67,31 @@ typedef struct { // Pointer to S/W UNDI API entry point // This will be NULL for H/W UNDI // - EFI_STATUS (*issue_undi32_command) (UINT64 cdb); + ISSUE_UNDI32_COMMAND IssueUndi32Command; - BOOLEAN is_swundi; + BOOLEAN IsSwUndi; // // undi interface number, if one undi manages more nics // - PXE_IFNUM if_num; + PXE_IFNUM IfNum; // // Allocated tx/rx buffer that was passed to UNDI Initialize. // - UINT32 tx_rx_bufsize; - VOID *tx_rx_buffer; + UINT32 TxRxBufferSize; + VOID *TxRxBuffer; // // mappable buffers for receive and fill header for undi3.0 // these will be used if the user buffers are above 4GB limit (instead of // mapping the user buffers) // - UINT8 *receive_buf; - VOID *ReceiveBufUnmap; - UINT8 *fill_hdr_buf; - VOID *FillHdrBufUnmap; + UINT8 *ReceiveBufffer; + VOID *ReceiveBufferUnmap; + UINT8 *FillHeaderBuffer; + VOID *FillHeaderBufferUnmap; - EFI_PCI_IO_PROTOCOL *IoFncs; + EFI_PCI_IO_PROTOCOL *PciIo; UINT8 IoBarIndex; UINT8 MemoryBarIndex; @@ -100,29 +99,28 @@ typedef struct { // Buffers for command descriptor block, command parameter block // and data block. // - PXE_CDB cdb; - VOID *cpb; + PXE_CDB Cdb; + VOID *Cpb; VOID *CpbUnmap; - VOID *db; + VOID *Db; // // UNDI structure, we need to remember the init info for a long time! // - PXE_DB_GET_INIT_INFO init_info; + PXE_DB_GET_INIT_INFO InitInfo; VOID *SnpDriverUnmap; // // when ever we map an address, we must remember it's address and the un-map // cookie so that we can unmap later // - struct s_map_list { - EFI_PHYSICAL_ADDRESS virt; - VOID *map_cookie; - } map_list[MAX_MAP_LENGTH]; -} -SNP_DRIVER; + struct MAP_LIST { + EFI_PHYSICAL_ADDRESS VirtualAddress; + VOID *MapCookie; + } MapList[MAX_MAP_LENGTH]; +} SNP_DRIVER; -#define EFI_SIMPLE_NETWORK_DEV_FROM_THIS(a) CR (a, SNP_DRIVER, snp, SNP_DRIVER_SIGNATURE) +#define EFI_SIMPLE_NETWORK_DEV_FROM_THIS(a) CR (a, SNP_DRIVER, Snp, SNP_DRIVER_SIGNATURE) // // Global Variables @@ -133,79 +131,274 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gSimpleNetworkComponentName2; // // Virtual to physical mapping for all UNDI 3.0s. // -extern struct s_v2p { - struct s_v2p *next; - VOID *vaddr; - UINTN bsize; - EFI_PHYSICAL_ADDRESS paddr; - VOID *unmap; -} -*_v2p; +typedef struct _V2P { + struct _V2P *Next; + VOID *VirtualAddress; + UINTN BufferSize; + EFI_PHYSICAL_ADDRESS PhysicalAddress; + VOID *Unmap; +} V2P; + +/** + 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 other error as indicated. +**/ EFI_STATUS -add_v2p ( - struct s_v2p **v2p, - EFI_PCI_IO_PROTOCOL_OPERATION type, - VOID *vaddr, - UINTN bsize +AddV2p ( + V2P **V2p, + EFI_PCI_IO_PROTOCOL_OPERATION Type, + VOID *VirtualAddress, + UINTN BufferSize ); +/** + 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 VirtualAddress virtual address (or CPU address) to be searched in + the map list + + @retval EFI_SUCEESS if a match found! + @retval Other match not found + +**/ EFI_STATUS -find_v2p ( - struct s_v2p **v2p, - VOID *vaddr +FindV2p ( + V2P **V2p, + VOID *VirtualAddress ); +/** + this routine calls undi to start the interface and changes the snp state. + + @param Snp pointer to snp driver structure + + @retval EFI_DEVICE_ERROR UNDI could not be started + @retval EFI_SUCCESS UNDI is started successfully + +**/ +EFI_STATUS +PxeStart ( + IN SNP_DRIVER *Snp + ); + +/** + this routine calls undi to stop the interface and changes the snp state. + + @param Snp pointer to snp driver structure + + @retval EFI_INVALID_PARAMETER invalid parameter + @retval EFI_NOT_STARTED SNP is not started + @retval EFI_DEVICE_ERROR SNP is not initialized + @retval EFI_UNSUPPORTED operation unsupported + +**/ +EFI_STATUS +PxeStop ( + SNP_DRIVER *Snp + ); + +/** + this routine calls undi to initialize the interface. + + @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 + +**/ +EFI_STATUS +PxeInit ( + SNP_DRIVER *Snp, + UINT16 CableDetectFlag + ); + +/** + this routine calls undi to shut down the interface. + + @param Snp pointer to snp driver structure + + @retval EFI_SUCCESS UNDI is shut down successfully + @retval EFI_DEVICE_ERROR UNDI could not be shut down + +**/ EFI_STATUS -del_v2p ( - VOID *vaddr +PxeShutdown ( + IN SNP_DRIVER *Snp ); -extern -VOID -snp_undi32_callback_block_30 ( +/** + this routine calls undi to read the MAC address of the NIC and updates the + mode structure with the address. + + @param Snp pointer to snp driver structure. + + @retval EFI_SUCCESS the MAC address of the NIC is read successfully. + @retval EFI_DEVICE_ERROR failed to read the MAC address of the NIC. + +**/ +EFI_STATUS +PxeGetStnAddr ( + SNP_DRIVER *Snp + ); + +/** + This routine unmaps the given virtual address and frees the memory allocated + for the map list node corresponding to that address. + + @param VirtualAddress virtual address (or CPU address) to be unmapped + + @retval EFI_SUCEESS if successfully unmapped + @retval Other as indicated by the error + +**/ +EFI_STATUS +DelV2p ( + VOID *VirtualAddress + ); + +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine when it wants to have exclusive access to a critical + section of the code/data. + + @param Enable non-zero indicates acquire + zero indicates release + +**/ +VOID +SnpUndi32CallbackBlock30 ( IN UINT32 Enable ); -extern -VOID -snp_undi32_callback_delay_30 ( +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine with the number of micro seconds when it wants to + pause. + + @param MicroSeconds number of micro seconds to pause, ususlly multiple of 10. + +**/ +VOID +SnpUndi32CallbackDelay30 ( IN UINT64 MicroSeconds ); -extern -VOID -snp_undi32_callback_memio_30 ( +/** + This is a callback routine supplied to UNDI at undi_start time. + This is the IO routine for UNDI. This is not currently being used by UNDI3.0 + because Undi3.0 uses io/mem offsets relative to the beginning of the device + io/mem address and so it needs to use the PCI_IO_FUNCTION that abstracts the + start of the device's io/mem addresses. Since SNP cannot retrive the context + of the undi3.0 interface it cannot use the PCI_IO_FUNCTION that specific for + that NIC and uses one global IO functions structure, this does not work. + This however works fine for EFI1.0 Undis because they use absolute addresses + for io/mem access. + + @param ReadOrWrite indicates read or write, IO or Memory + @param NumBytes number of bytes to read or write + @param Address IO or memory address to read from or write to + @param BufferAddr memory location to read into or that contains the bytes to + write + +**/ +VOID +SnpUndi32CallbackMemio30 ( IN UINT8 ReadOrWrite, IN UINT8 NumBytes, - IN UINT64 MemOrPortAddress, - IN OUT UINT64 BufferPtr + IN UINT64 Address, + IN OUT UINT64 BufferAddr ); -extern -VOID -snp_undi32_callback_v2p_30 ( +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine with a virtual or CPU address that SNP provided to + convert it to a physical or device address. Since EFI uses the identical + mapping, this routine returns the physical address same as the virtual address + for most of the addresses. an address above 4GB cannot generally be used as a + device address, it needs to be mapped to a lower physical address. This + routine does not call the map routine itself, but it assumes that the mapping + was done at the time of providing the address to UNDI. This routine just + looks up the address in a map table (which is the v2p structure chain). + + @param CpuAddr virtual address of a buffer. + @param DeviceAddrPtr pointer to the physical address. + The DeviceAddrPtr will contain 0 in case of any error. + +**/ +VOID +SnpUndi32CallbackV2p30 ( IN UINT64 CpuAddr, IN OUT UINT64 DeviceAddrPtr ); -extern -VOID -snp_undi32_callback_block ( +/** + This is a callback routine supplied to UNDI3.1 at undi_start time. + UNDI call this routine when it wants to have exclusive access to a critical + section of the code/data. + New callbacks for 3.1: + there won't be a virtual2physical callback for UNDI 3.1 because undi3.1 uses + the MemMap call to map the required address by itself! + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to + store Undi interface context (Undi does not read or write + this variable) + @param Enable non-zero indicates acquire + zero indicates release +**/ +VOID +SnpUndi32CallbackBlock ( IN UINT64 UniqueId, IN UINT32 Enable ); -extern -VOID -snp_undi32_callback_delay ( +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine with the number of micro seconds when it wants to + pause. + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to + store Undi interface context (Undi does not read or write + this variable) + @param MicroSeconds number of micro seconds to pause, ususlly multiple of 10. +**/ +VOID +SnpUndi32CallbackDelay ( IN UINT64 UniqueId, IN UINT64 MicroSeconds ); -extern -VOID -snp_undi32_callback_memio ( +/** + This is a callback routine supplied to UNDI at undi_start time. + This is the IO routine for UNDI3.1 to start CPB. + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this + to store Undi interface context (Undi does not read or + write this variable) + @param ReadOrWrite indicates read or write, IO or Memory. + @param NumBytes number of bytes to read or write. + @param MemOrPortAddr IO or memory address to read from or write to. + @param BufferPtr memory location to read into or that contains the bytes + to write. +**/ +VOID +SnpUndi32CallbackMemio ( IN UINT64 UniqueId, IN UINT8 ReadOrWrite, IN UINT8 NumBytes, @@ -213,9 +406,22 @@ snp_undi32_callback_memio ( IN OUT UINT64 BufferPtr ); -extern -VOID -snp_undi32_callback_map ( +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine when it has to map a CPU address to a device + address. + + @param UniqueId - This was supplied to UNDI at Undi_Start, SNP uses this to store + Undi interface context (Undi does not read or write this variable) + @param CpuAddr - Virtual address to be mapped! + @param NumBytes - size of memory to be mapped + @param Direction - direction of data flow for this memory's usage: + cpu->device, device->cpu or both ways + @param DeviceAddrPtr - pointer to return the mapped device address + +**/ +VOID +SnpUndi32CallbackMap ( IN UINT64 UniqueId, IN UINT64 CpuAddr, IN UINT32 NumBytes, @@ -223,184 +429,688 @@ snp_undi32_callback_map ( IN OUT UINT64 DeviceAddrPtr ); -extern -VOID -snp_undi32_callback_unmap ( +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine when it wants to unmap an address that was previously + mapped using map callback. + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to store. + Undi interface context (Undi does not read or write this variable) + @param CpuAddr Virtual address that was mapped! + @param NumBytes size of memory mapped + @param Direction direction of data flow for this memory's usage: + cpu->device, device->cpu or both ways + @param DeviceAddr the mapped device address + +**/ +VOID +SnpUndi32CallbackUnmap ( IN UINT64 UniqueId, IN UINT64 CpuAddr, IN UINT32 NumBytes, IN UINT32 Direction, - IN UINT64 DeviceAddr // not a pointer to device address + IN UINT64 DeviceAddr ); -extern -VOID -snp_undi32_callback_sync ( +/** + This is a callback routine supplied to UNDI at undi_start time. + UNDI call this routine when it wants synchronize the virtual buffer contents + with the mapped buffer contents. The virtual and mapped buffers need not + correspond to the same physical memory (especially if the virtual address is + > 4GB). Depending on the direction for which the buffer is mapped, undi will + need to synchronize their contents whenever it writes to/reads from the buffer + using either the cpu address or the device address. + + EFI does not provide a sync call, since virt=physical, we sould just do + the synchronization ourself here! + + @param UniqueId This was supplied to UNDI at Undi_Start, SNP uses this to store + Undi interface context (Undi does not read or write this variable) + @param CpuAddr Virtual address that was mapped! + @param NumBytes size of memory mapped. + @param Direction direction of data flow for this memory's usage: + cpu->device, device->cpu or both ways. + @param DeviceAddr the mapped device address. + +**/ +VOID +SnpUndi32CallbackSync ( IN UINT64 UniqueId, IN UINT64 CpuAddr, IN UINT32 NumBytes, IN UINT32 Direction, - IN UINT64 DeviceAddr // not a pointer to device address + IN UINT64 DeviceAddr ); -extern -EFI_STATUS +/** + Changes the state of a network interface from "stopped" to "started". + + This function starts a network interface. If the network interface successfully + starts, then EFI_SUCCESS will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + + @retval EFI_SUCCESS The network interface was started. + @retval EFI_ALREADY_STARTED The network interface is already in the started state. + @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 This function is not supported by the network interface. + +**/ +EFI_STATUS EFIAPI -snp_undi32_start ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this +SnpUndi32Start ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This ); -extern -EFI_STATUS +/** + Changes the state of a network interface from "started" to "stopped". + + This function stops a network interface. This call is only valid if the network + interface is in the started state. If the network interface was successfully + stopped, then EFI_SUCCESS will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + + + @retval EFI_SUCCESS The network interface was stopped. + @retval EFI_NOT_STARTED The network interface has not been started. + @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 This function is not supported by the network interface. + +**/ +EFI_STATUS EFIAPI -snp_undi32_stop ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this +SnpUndi32Stop ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This ); -extern +/** + 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. + +**/ EFI_STATUS EFIAPI -snp_undi32_initialize ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this, - IN UINTN extra_rx_buffer_size OPTIONAL, - IN UINTN extra_tx_buffer_size OPTIONAL +SnpUndi32Initialize ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN UINTN ExtraRxBufferSize OPTIONAL, + IN UINTN ExtraTxBufferSize OPTIONAL ); -extern -EFI_STATUS +/** + Resets a network adapter and reinitializes it with the parameters that were + provided in the previous call to Initialize(). + + This function resets a network adapter and reinitializes it with the parameters + that were provided in the previous call to Initialize(). The transmit and + receive queues are emptied and all pending interrupts are cleared. + Receive filters, the station address, the statistics, and the multicast-IP-to-HW + MAC addresses are not reset by this call. If the network interface was + successfully reset, then EFI_SUCCESS will be returned. If the driver has not + been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param ExtendedVerification Indicates that the driver may perform a more + exhaustive verification operation of the device + during reset. + + @retval EFI_SUCCESS The network interface was reset. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value. + @retval EFI_DEVICE_ERROR The command could not be sent to the network interface. + @retval EFI_UNSUPPORTED This function is not supported by the network interface. + +**/ +EFI_STATUS EFIAPI -snp_undi32_reset ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this, +SnpUndi32Reset ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN ExtendedVerification ); -extern -EFI_STATUS +/** + Resets a network adapter and leaves it in a state that is safe for another + driver to initialize. + + This function releases the memory buffers assigned in the Initialize() call. + Pending transmits and receives are lost, and interrupts are cleared and disabled. + After this call, only the Initialize() and Stop() calls may be used. If the + network interface was successfully shutdown, then EFI_SUCCESS will be returned. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + + @retval EFI_SUCCESS The network interface was shutdown. + @retval EFI_NOT_STARTED The network interface has not been started. + @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. + +**/ +EFI_STATUS EFIAPI -snp_undi32_shutdown ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this +SnpUndi32Shutdown ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This ); -extern -EFI_STATUS +/** + Manages the multicast receive filters of a network interface. + + This function is used enable and disable the hardware and software receive + filters for the underlying network device. + The receive filter change is broken down into three steps: + * The filter mask bits that are set (ON) in the Enable parameter are added to + the current receive filter settings. + * The filter mask bits that are set (ON) in the Disable parameter are subtracted + from the updated receive filter settings. + * If the resulting receive filter setting is not supported by the hardware a + more liberal setting is selected. + If the same bits are set in the Enable and Disable parameters, then the bits + in the Disable parameter takes precedence. + If the ResetMCastFilter parameter is TRUE, then the multicast address list + filter is disabled (irregardless of what other multicast bits are set in the + Enable and Disable parameters). The SNP->Mode->MCastFilterCount field is set + to zero. The Snp->Mode->MCastFilter contents are undefined. + After enabling or disabling receive filter settings, software should verify + the new settings by checking the Snp->Mode->ReceiveFilterSettings, + Snp->Mode->MCastFilterCount and Snp->Mode->MCastFilter fields. + Note: Some network drivers and/or devices will automatically promote receive + filter settings if the requested setting can not be honored. For example, if + a request for four multicast addresses is made and the underlying hardware + only supports two multicast addresses the driver might set the promiscuous + or promiscuous multicast receive filters instead. The receiving software is + responsible for discarding any extra packets that get through the hardware + receive filters. + Note: Note: To disable all receive filter hardware, the network driver must + be Shutdown() and Stopped(). Calling ReceiveFilters() with Disable set to + Snp->Mode->ReceiveFilterSettings will make it so no more packets are + returned by the Receive() function, but the receive hardware may still be + moving packets into system memory before inspecting and discarding them. + Unexpected system errors, reboots and hangs can occur if an OS is loaded + and the network devices are not Shutdown() and Stopped(). + If ResetMCastFilter is TRUE, then the multicast receive filter list on the + network interface will be reset to the default multicast receive filter list. + If ResetMCastFilter is FALSE, and this network interface allows the multicast + receive filter list to be modified, then the MCastFilterCnt and MCastFilter + are used to update the current multicast receive filter list. The modified + receive filter list settings can be found in the MCastFilter field of + EFI_SIMPLE_NETWORK_MODE. If the network interface does not allow the multicast + receive filter list to be modified, then EFI_INVALID_PARAMETER will be returned. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + If the receive filter mask and multicast receive filter list have been + successfully updated on the network interface, EFI_SUCCESS will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param Enable A bit mask of receive filters to enable on the network + interface. + @param Disable A bit mask of receive filters to disable on the network + interface. For backward compatibility with EFI 1.1 + platforms, the EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST bit + must be set when the ResetMCastFilter parameter is TRUE. + @param ResetMCastFilter Set to TRUE to reset the contents of the multicast + receive filters on the network interface to their + default values. + @param MCastFilterCnt Number of multicast HW MAC addresses in the new MCastFilter + list. This value must be less than or equal to the + MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. + This field is optional if ResetMCastFilter is TRUE. + @param MCastFilter A pointer to a list of new multicast receive filter HW + MAC addresses. This list will replace any existing + multicast HW MAC address list. This field is optional + if ResetMCastFilter is TRUE. + + @retval EFI_SUCCESS The multicast receive filter list was updated. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + * This is NULL + * There are bits set in Enable that are not set + in Snp->Mode->ReceiveFilterMask + * There are bits set in Disable that are not set + in Snp->Mode->ReceiveFilterMask + * Multicast is being enabled (the + EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST bit is + set in Enable, it is not set in Disable, and + ResetMCastFilter is FALSE) and MCastFilterCount + is zero + * Multicast is being enabled and MCastFilterCount + is greater than Snp->Mode->MaxMCastFilterCount + * Multicast is being enabled and MCastFilter is NULL + * Multicast is being enabled and one or more of + the addresses in the MCastFilter list are not + valid multicast MAC addresses + @retval EFI_DEVICE_ERROR One or more of the following conditions is TRUE: + * The network interface has been started but has + not been initialized + * An unexpected error was returned by the + underlying network driver or device + @retval EFI_UNSUPPORTED This function is not supported by the network + interface. + +**/ +EFI_STATUS EFIAPI -snp_undi32_receive_filters ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - IN UINT32 enable, - IN UINT32 disable, - IN BOOLEAN reset_mcast_filter, - IN UINTN mcast_filter_count OPTIONAL, - IN EFI_MAC_ADDRESS * mcast_filter OPTIONAL +SnpUndi32ReceiveFilters ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN UINT32 Enable, + IN UINT32 Disable, + IN BOOLEAN ResetMCastFilter, + IN UINTN MCastFilterCnt, OPTIONAL + IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL ); -extern -EFI_STATUS +/** + Modifies or resets the current station address, if supported. + + This function modifies or resets the current station address of a network + interface, if supported. If Reset is TRUE, then the current station address is + set to the network interface's permanent address. If Reset is FALSE, and the + network interface allows its station address to be modified, then the current + station address is changed to the address specified by New. If the network + interface does not allow its station address to be modified, then + EFI_INVALID_PARAMETER will be returned. If the station address is successfully + updated on the network interface, EFI_SUCCESS will be returned. If the driver + has not been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param Reset Flag used to reset the station address to the network interface's + permanent address. + @param New New station address to be used for the network interface. + + + @retval EFI_SUCCESS The network interface's station address was updated. + @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been + started by calling Start(). + @retval EFI_INVALID_PARAMETER The New station address was not accepted by the NIC. + @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL. + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not + been initialized by calling Initialize(). + @retval EFI_DEVICE_ERROR An error occurred attempting to set the new + station address. + @retval EFI_UNSUPPORTED The NIC does not support changing the network + interface's station address. + +**/ +EFI_STATUS EFIAPI -snp_undi32_station_address ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - IN BOOLEAN reset, - IN EFI_MAC_ADDRESS *new OPTIONAL +SnpUndi32StationAddress ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN BOOLEAN Reset, + IN EFI_MAC_ADDRESS *New OPTIONAL ); -extern -EFI_STATUS +/** + Resets or collects the statistics on a network interface. + + This function resets or collects the statistics on a network interface. If the + size of the statistics table specified by StatisticsSize is not big enough for + all the statistics that are collected by the network interface, then a partial + buffer of statistics is returned in StatisticsTable, StatisticsSize is set to + the size required to collect all the available statistics, and + EFI_BUFFER_TOO_SMALL is returned. + If StatisticsSize is big enough for all the statistics, then StatisticsTable + will be filled, StatisticsSize will be set to the size of the returned + StatisticsTable structure, and EFI_SUCCESS is returned. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + If Reset is FALSE, and both StatisticsSize and StatisticsTable are NULL, then + no operations will be performed, and EFI_SUCCESS will be returned. + If Reset is TRUE, then all of the supported statistics counters on this network + interface will be reset to zero. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param Reset Set to TRUE to reset the statistics for the network interface. + @param StatisticsSize On input the size, in bytes, of StatisticsTable. On output + the size, in bytes, of the resulting table of statistics. + @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that + contains the statistics. Type EFI_NETWORK_STATISTICS is + defined in "Related Definitions" below. + + @retval EFI_SUCCESS The requested operation succeeded. + @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been + started by calling Start(). + @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is + NULL. The current buffer size that is needed to + hold all the statistics is returned in StatisticsSize. + @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is + not NULL. The current buffer size that is needed + to hold all the statistics is returned in + StatisticsSize. A partial set of statistics is + returned in StatisticsTable. + @retval EFI_INVALID_PARAMETER StatisticsSize is NULL and StatisticsTable is not + NULL. + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not + been initialized by calling Initialize(). + @retval EFI_DEVICE_ERROR An error was encountered collecting statistics + from the NIC. + @retval EFI_UNSUPPORTED The NIC does not support collecting statistics + from the network interface. + +**/ +EFI_STATUS EFIAPI -snp_undi32_statistics ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - IN BOOLEAN reset, - IN OUT UINTN *statistics_size OPTIONAL, - IN OUT EFI_NETWORK_STATISTICS * statistics_table OPTIONAL +SnpUndi32Statistics ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN BOOLEAN Reset, + IN OUT UINTN *StatisticsSize, OPTIONAL + IN OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL ); -extern -EFI_STATUS +/** + Converts a multicast IP address to a multicast HW MAC address. + + This function converts a multicast IP address to a multicast HW MAC address + for all packet transactions. If the mapping is accepted, then EFI_SUCCESS will + be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. + Set to FALSE if the multicast IP address is IPv4 [RFC 791]. + @param IP The multicast IP address that is to be converted to a multicast + HW MAC address. + @param MAC The multicast HW MAC address that is to be generated from IP. + + @retval EFI_SUCCESS The multicast IP address was mapped to the + multicast HW MAC address. + @retval EFI_NOT_STARTED The Simple Network Protocol interface has not + been started by calling Start(). + @retval EFI_INVALID_PARAMETER IP is NULL. + @retval EFI_INVALID_PARAMETER MAC is NULL. + @retval EFI_INVALID_PARAMETER IP does not point to a valid IPv4 or IPv6 + multicast address. + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not + been initialized by calling Initialize(). + @retval EFI_UNSUPPORTED IPv6 is TRUE and the implementation does not + support IPv6 multicast to MAC address conversion. + +**/ +EFI_STATUS EFIAPI -snp_undi32_mcast_ip_to_mac ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this, +SnpUndi32McastIpToMac ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN IPv6, IN EFI_IP_ADDRESS *IP, OUT EFI_MAC_ADDRESS *MAC ); -extern -EFI_STATUS -EFIAPI -snp_undi32_nvdata ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this, - IN BOOLEAN read_write, - IN UINTN offset, - IN UINTN buffer_size, - IN OUT VOID *buffer - ); +/** + Performs read and write operations on the NVRAM device attached to a network + interface. + + This function performs read and write operations on the NVRAM device attached + to a network interface. If ReadWrite is TRUE, a read operation is performed. + If ReadWrite is FALSE, a write operation is performed. Offset specifies the + byte offset at which to start either operation. Offset must be a multiple of + NvRamAccessSize , and it must have a value between zero and NvRamSize. + BufferSize specifies the length of the read or write operation. BufferSize must + also be a multiple of NvRamAccessSize, and Offset + BufferSize must not exceed + NvRamSize. + If any of the above conditions is not met, then EFI_INVALID_PARAMETER will be + returned. + If all the conditions are met and the operation is "read," the NVRAM device + attached to the network interface will be read into Buffer and EFI_SUCCESS + will be returned. If this is a write operation, the contents of Buffer will be + used to update the contents of the NVRAM device attached to the network + interface and EFI_SUCCESS will be returned. + + It does the basic checking on the input parameters and retrieves snp structure + and then calls the read_nvdata() call which does the actual reading + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param ReadWrite TRUE for read operations, FALSE for write operations. + @param Offset Byte offset in the NVRAM device at which to start the read or + write operation. This must be a multiple of NvRamAccessSize + and less than NvRamSize. (See EFI_SIMPLE_NETWORK_MODE) + @param BufferSize The number of bytes to read or write from the NVRAM device. + This must also be a multiple of NvramAccessSize. + @param Buffer A pointer to the data buffer. + + @retval EFI_SUCCESS The NVRAM access was performed. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + * The This parameter is NULL + * The This parameter does not point to a valid + EFI_SIMPLE_NETWORK_PROTOCOL structure + * The Offset parameter is not a multiple of + EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize + * The Offset parameter is not less than + EFI_SIMPLE_NETWORK_MODE.NvRamSize + * The BufferSize parameter is not a multiple of + EFI_SIMPLE_NETWORK_MODE.NvRamAccessSize + * The Buffer parameter is NULL + @retval EFI_DEVICE_ERROR The command could not be sent to the network + interface. + @retval EFI_UNSUPPORTED This function is not supported by the network + interface. -extern -EFI_STATUS +**/ +EFI_STATUS EFIAPI -snp_undi32_get_status ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - OUT UINT32 *interrupt_status OPTIONAL, - OUT VOID **tx_buffer OPTIONAL +SnpUndi32NvData ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN BOOLEAN ReadWrite, + IN UINTN Offset, + IN UINTN BufferSize, + IN OUT VOID *Buffer ); -extern -EFI_STATUS +/** + Reads the current interrupt status and recycled transmit buffer status from a + network interface. + + This function gets the current interrupt and recycled transmit buffer status + from the network interface. The interrupt status is returned as a bit mask in + InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be + read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved. + If a recycled transmit buffer address is returned in TxBuf, then the buffer has + been successfully transmitted, and the status for that buffer is cleared. If + the status of the network interface is successfully collected, EFI_SUCCESS + will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will + be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param InterruptStatus A pointer to the bit mask of the currently active + interrupts (see "Related Definitions"). If this is NULL, + the interrupt status will not be read from the device. + If this is not NULL, the interrupt status will be read + from the device. When the interrupt status is read, it + will also be cleared. Clearing the transmit interrupt does + not empty the recycled transmit buffer array. + @param TxBuf Recycled transmit buffer address. The network interface + will not transmit if its internal recycled transmit + buffer array is full. Reading the transmit buffer does + not clear the transmit interrupt. If this is NULL, then + the transmit buffer status will not be read. If there + are no transmit buffers to recycle and TxBuf is not NULL, + TxBuf will be set to NULL. + + @retval EFI_SUCCESS The status of the network interface was retrieved. + @retval EFI_NOT_STARTED The network interface has not been started. + @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. + +**/ +EFI_STATUS EFIAPI -snp_undi32_transmit ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - IN UINTN header_size, - IN UINTN buffer_size, - IN VOID *buffer, - IN EFI_MAC_ADDRESS * src_addr OPTIONAL, - IN EFI_MAC_ADDRESS * dest_addr OPTIONAL, - IN UINT16 *protocol OPTIONAL +SnpUndi32GetStatus ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + OUT UINT32 *InterruptStatus, OPTIONAL + OUT VOID **TxBuf OPTIONAL ); -extern +/** + Places a packet in the transmit queue of a network interface. + + This function places the packet specified by Header and Buffer on the transmit + queue. If HeaderSize is nonzero and HeaderSize is not equal to + This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If + BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL + will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be + returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then + EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network + interface is busy, then EFI_NOT_READY will be returned. If this packet can be + accepted by the transmit engine of the network interface, the packet contents + specified by Buffer will be placed on the transmit queue of the network + interface, and EFI_SUCCESS will be returned. GetStatus() can be used to + determine when the packet has actually been transmitted. The contents of the + Buffer must not be modified until the packet has actually been transmitted. + The Transmit() function performs nonblocking I/O. A caller who wants to perform + blocking I/O, should call Transmit(), and then GetStatus() until the + transmitted buffer shows up in the recycled transmit buffer. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param HeaderSize The size, in bytes, of the media header to be filled in by the + Transmit() function. If HeaderSize is nonzero, then it must + be equal to This->Mode->MediaHeaderSize and the DestAddr and + Protocol parameters must not be NULL. + @param BufferSize The size, in bytes, of the entire packet (media header and + data) to be transmitted through the network interface. + @param Buffer A pointer to the packet (media header followed by data) to be + transmitted. This parameter cannot be NULL. If HeaderSize is + zero, then the media header in Buffer must already be filled + in by the caller. If HeaderSize is nonzero, then the media + header will be filled in by the Transmit() function. + @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this + parameter is ignored. If HeaderSize is nonzero and SrcAddr + is NULL, then This->Mode->CurrentAddress is used for the + source HW MAC address. + @param DestAddr The destination HW MAC address. If HeaderSize is zero, then + this parameter is ignored. + @param Protocol The type of header to build. If HeaderSize is zero, then this + parameter is ignored. See RFC 1700, section "Ether Types," + for examples. + + @retval EFI_SUCCESS The packet was placed on the transmit queue. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_NOT_READY The network interface is too busy to accept this + transmit request. + @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small. + @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported + value. + @retval EFI_DEVICE_ERROR The command could not be sent to the network interface. + @retval EFI_UNSUPPORTED This function is not supported by the network interface. + +**/ EFI_STATUS EFIAPI -snp_undi32_receive ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - OUT UINTN *header_size OPTIONAL, - IN OUT UINTN *buffer_size, - OUT VOID *buffer, - OUT EFI_MAC_ADDRESS * src_addr OPTIONAL, - OUT EFI_MAC_ADDRESS * dest_addr OPTIONAL, - OUT UINT16 *protocol OPTIONAL +SnpUndi32Transmit ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN UINTN HeaderSize, + IN UINTN BufferSize, + IN VOID *Buffer, + IN EFI_MAC_ADDRESS *SrcAddr, OPTIONAL + IN EFI_MAC_ADDRESS *DestAddr, OPTIONAL + IN UINT16 *Protocol OPTIONAL ); -typedef +/** + Receives a packet from a network interface. + + This function retrieves one packet from the receive queue of a network interface. + If there are no packets on the receive queue, then EFI_NOT_READY will be + returned. If there is a packet on the receive queue, and the size of the packet + is smaller than BufferSize, then the contents of the packet will be placed in + Buffer, and BufferSize will be updated with the actual size of the packet. + In addition, if SrcAddr, DestAddr, and Protocol are not NULL, then these values + will be extracted from the media header and returned. EFI_SUCCESS will be + returned if a packet was successfully received. + If BufferSize is smaller than the received packet, then the size of the receive + packet will be placed in BufferSize and EFI_BUFFER_TOO_SMALL will be returned. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param HeaderSize The size, in bytes, of the media header received on the network + interface. If this parameter is NULL, then the media header size + will not be returned. + @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in + bytes, of the packet that was received on the network interface. + @param Buffer A pointer to the data buffer to receive both the media + header and the data. + @param SrcAddr The source HW MAC address. If this parameter is NULL, the HW + MAC source address will not be extracted from the media header. + @param DestAddr The destination HW MAC address. If this parameter is NULL, + the HW MAC destination address will not be extracted from + the media header. + @param Protocol The media header type. If this parameter is NULL, then the + protocol will not be extracted from the media header. See + RFC 1700 section "Ether Types" for examples. + + @retval EFI_SUCCESS The received data was stored in Buffer, and + BufferSize has been updated to the number of + bytes received. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_NOT_READY No packets have been received on the network interface. + @retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the received packets. + BufferSize has been updated to the required size. + @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE: + * The This parameter is NULL + * The This parameter does not point to a valid + EFI_SIMPLE_NETWORK_PROTOCOL structure. + * The BufferSize parameter is NULL + * The Buffer parameter is NULL + @retval EFI_DEVICE_ERROR The command could not be sent to the network interface. + +**/ EFI_STATUS -(*issue_undi32_command) ( - UINT64 cdb - ); -typedef -VOID -(*ptr) ( - VOID +EFIAPI +SnpUndi32Receive ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + OUT UINTN *HeaderSize OPTIONAL, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer, + OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL, + OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL, + OUT UINT16 *Protocol OPTIONAL ); - /** - Install all the driver protocol - - @param ImageHandle Driver image handle - @param SystemTable System services table + Nofication call back function for WaitForPacket event. - @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 + @param Event EFI Event. + @param SnpPtr Pointer to SNP_DRIVER structure. **/ -EFI_STATUS +VOID EFIAPI -InitializeSnpNiiDriver ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable +SnpWaitForPacketNotify ( + EFI_EVENT Event, + VOID *SnpPtr ); #define SNP_MEM_PAGES(x) (((x) - 1) / 4096 + 1) -#endif /* _SNP_H */ +#endif /* _SNP_H_ */ diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Start.c b/MdeModulePkg/Universal/Network/SnpDxe/Start.c index eaba03c57d..5c5daeaa60 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Start.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Start.c @@ -1,94 +1,90 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of starting a network adapter. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - start.c - -Abstract: - -Revision history: - 2000-Feb-07 M(f)J Genesis. - **/ #include "Snp.h" /** - this routine calls undi to start the interface and changes the snp state! - - @param snp pointer to snp driver structure + this routine calls undi to start the interface and changes the snp state. + @param Snp pointer to snp driver structure + @retval EFI_DEVICE_ERROR UNDI could not be started + @retval EFI_SUCCESS UNDI is started successfully + **/ EFI_STATUS -pxe_start ( - SNP_DRIVER *snp +PxeStart ( + IN SNP_DRIVER *Snp ) { - PXE_CPB_START_31 *cpb_31; + PXE_CPB_START_31 *Cpb31; - cpb_31 = snp->cpb; + Cpb31 = Snp->Cpb; // // Initialize UNDI Start CDB for H/W UNDI // - snp->cdb.OpCode = PXE_OPCODE_START; - snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + Snp->Cdb.OpCode = PXE_OPCODE_START; + Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; + 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; // // Make changes to H/W UNDI Start CDB if this is // a S/W UNDI. // - if (snp->is_swundi) { - snp->cdb.CPBsize = sizeof (PXE_CPB_START_31); - snp->cdb.CPBaddr = (UINT64)(UINTN) cpb_31; + if (Snp->IsSwUndi) { + Snp->Cdb.CPBsize = sizeof (PXE_CPB_START_31); + Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb31; - cpb_31->Delay = (UINT64)(UINTN) &snp_undi32_callback_delay; - cpb_31->Block = (UINT64)(UINTN) &snp_undi32_callback_block; + Cpb31->Delay = (UINT64)(UINTN) &SnpUndi32CallbackDelay; + Cpb31->Block = (UINT64)(UINTN) &SnpUndi32CallbackBlock; // // Virtual == Physical. This can be set to zero. // - cpb_31->Virt2Phys = (UINT64)(UINTN) 0; - cpb_31->Mem_IO = (UINT64)(UINTN) &snp_undi32_callback_memio; + Cpb31->Virt2Phys = (UINT64)(UINTN) 0; + Cpb31->Mem_IO = (UINT64)(UINTN) &SnpUndi32CallbackMemio; - cpb_31->Map_Mem = (UINT64)(UINTN) &snp_undi32_callback_map; - cpb_31->UnMap_Mem = (UINT64)(UINTN) &snp_undi32_callback_unmap; - cpb_31->Sync_Mem = (UINT64)(UINTN) &snp_undi32_callback_sync; + Cpb31->Map_Mem = (UINT64)(UINTN) &SnpUndi32CallbackMap; + Cpb31->UnMap_Mem = (UINT64)(UINTN) &SnpUndi32CallbackUnmap; + Cpb31->Sync_Mem = (UINT64)(UINTN) &SnpUndi32CallbackSync; - cpb_31->Unique_ID = (UINT64)(UINTN) snp; + Cpb31->Unique_ID = (UINT64)(UINTN) Snp; } // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.start() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) { + if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) { // // UNDI could not be started. Return UNDI error. // DEBUG ( (EFI_D_ERROR, "\nsnp->undi.start() %xh:%xh\n", - snp->cdb.StatCode, - snp->cdb.StatFlags) + Snp->Cdb.StatCode, + Snp->Cdb.StatFlags) ); return EFI_DEVICE_ERROR; @@ -96,34 +92,31 @@ pxe_start ( // // Set simple network state to Started and return success. // - snp->mode.State = EfiSimpleNetworkStarted; + Snp->Mode.State = EfiSimpleNetworkStarted; return EFI_SUCCESS; } /** - This is the SNP interface routine for starting the interface - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_start routine to actually do start undi interface - - @param This context pointer - - @retval EFI_INVALID_PARAMETER "This" is Null - @retval No SNP driver can be extracted from "This" - @retval EFI_ALREADY_STARTED The state of SNP is EfiSimpleNetworkStarted or - EfiSimpleNetworkInitialized - @retval EFI_DEVICE_ERROR The state of SNP is other than - EfiSimpleNetworkStarted, - EfiSimpleNetworkInitialized, and - EfiSimpleNetworkStopped - @retval EFI_SUCCESS UNDI interface is succesfully started - @retval Other Error occurs while calling pxe_start function. + Changes the state of a network interface from "stopped" to "started." + + This function starts a network interface. If the network interface successfully + starts, then EFI_SUCCESS will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + + @retval EFI_SUCCESS The network interface was started. + @retval EFI_ALREADY_STARTED The network interface is already in the started state. + @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 This function is not supported by the network interface. **/ EFI_STATUS EFIAPI -snp_undi32_start ( +SnpUndi32Start ( IN EFI_SIMPLE_NETWORK_PROTOCOL *This ) { @@ -140,7 +133,7 @@ snp_undi32_start ( OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - switch (Snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkStopped: break; @@ -154,7 +147,7 @@ snp_undi32_start ( goto ON_EXIT; } - Status = pxe_start (Snp); + Status = PxeStart (Snp); if (EFI_ERROR (Status)) { goto ON_EXIT; } @@ -162,11 +155,11 @@ snp_undi32_start ( // clear the map_list in SNP structure // for (Index = 0; Index < MAX_MAP_LENGTH; Index++) { - Snp->map_list[Index].virt = 0; - Snp->map_list[Index].map_cookie = 0; + Snp->MapList[Index].VirtualAddress = 0; + Snp->MapList[Index].MapCookie = 0; } - Snp->mode.MCastFilterCount = 0; + Snp->Mode.MCastFilterCount = 0; ON_EXIT: gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Station_address.c b/MdeModulePkg/Universal/Network/SnpDxe/Station_address.c index e4c268f575..07df584a07 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Station_address.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Station_address.c @@ -1,21 +1,15 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of reading the MAC address of a network adapter. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - station_address.c - -Abstract: - -Revision history: - 2000-Feb-17 M(f)J Genesis. - **/ #include "Snp.h" @@ -25,45 +19,47 @@ Revision history: this routine calls undi to read the MAC address of the NIC and updates the mode structure with the address. - @param snp pointer to snp driver structure - + @param Snp pointer to snp driver structure. + + @retval EFI_SUCCESS the MAC address of the NIC is read successfully. + @retval EFI_DEVICE_ERROR failed to read the MAC address of the NIC. **/ EFI_STATUS -pxe_get_stn_addr ( - SNP_DRIVER *snp +PxeGetStnAddr ( + SNP_DRIVER *Snp ) { - PXE_DB_STATION_ADDRESS *db; + PXE_DB_STATION_ADDRESS *Db; - db = snp->db; - snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS; - snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ; + Db = Snp->Db; + Snp->Cdb.OpCode = PXE_OPCODE_STATION_ADDRESS; + Snp->Cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS); - snp->cdb.DBaddr = (UINT64)(UINTN) db; + Snp->Cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS); + Snp->Cdb.DBaddr = (UINT64)(UINTN) Db; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) { + if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) { DEBUG ( (EFI_D_ERROR, "\nsnp->undi.station_addr() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_DEVICE_ERROR; @@ -72,21 +68,21 @@ pxe_get_stn_addr ( // Set new station address in SNP->Mode structure and return success. // CopyMem ( - &(snp->mode.CurrentAddress), - &db->StationAddr, - snp->mode.HwAddressSize + &(Snp->Mode.CurrentAddress), + &Db->StationAddr, + Snp->Mode.HwAddressSize ); CopyMem ( - &snp->mode.BroadcastAddress, - &db->BroadcastAddr, - snp->mode.HwAddressSize + &Snp->Mode.BroadcastAddress, + &Db->BroadcastAddr, + Snp->Mode.HwAddressSize ); CopyMem ( - &snp->mode.PermanentAddress, - &db->PermanentAddr, - snp->mode.HwAddressSize + &Snp->Mode.PermanentAddress, + &Db->PermanentAddr, + Snp->Mode.HwAddressSize ); return EFI_SUCCESS; @@ -96,7 +92,7 @@ pxe_get_stn_addr ( /** this routine calls undi to set a new MAC address for the NIC, - @param snp pointer to snp driver structure + @param Snp pointer to Snp driver structure @param NewMacAddr pointer to a mac address to be set for the nic, if this is NULL then this routine resets the mac address to the NIC's original address. @@ -104,55 +100,55 @@ pxe_get_stn_addr ( **/ EFI_STATUS -pxe_set_stn_addr ( - SNP_DRIVER *snp, +PxeSetStnAddr ( + SNP_DRIVER *Snp, EFI_MAC_ADDRESS *NewMacAddr ) { - PXE_CPB_STATION_ADDRESS *cpb; - PXE_DB_STATION_ADDRESS *db; + PXE_CPB_STATION_ADDRESS *Cpb; + PXE_DB_STATION_ADDRESS *Db; - cpb = snp->cpb; - db = snp->db; - snp->cdb.OpCode = PXE_OPCODE_STATION_ADDRESS; + Cpb = Snp->Cpb; + Db = Snp->Db; + Snp->Cdb.OpCode = PXE_OPCODE_STATION_ADDRESS; if (NewMacAddr == NULL) { - snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_RESET; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_RESET; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; } else { - snp->cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ; + Snp->Cdb.OpFlags = PXE_OPFLAGS_STATION_ADDRESS_READ; // // even though the OPFLAGS are set to READ, supplying a new address // in the CPB will make undi change the mac address to the new one. // - CopyMem (&cpb->StationAddr, NewMacAddr, snp->mode.HwAddressSize); + CopyMem (&Cpb->StationAddr, NewMacAddr, Snp->Mode.HwAddressSize); - snp->cdb.CPBsize = sizeof (PXE_CPB_STATION_ADDRESS); - snp->cdb.CPBaddr = (UINT64)(UINTN) cpb; + Snp->Cdb.CPBsize = sizeof (PXE_CPB_STATION_ADDRESS); + Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb; } - snp->cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS); - snp->cdb.DBaddr = (UINT64)(UINTN) db; + Snp->Cdb.DBsize = sizeof (PXE_DB_STATION_ADDRESS); + Snp->Cdb.DBaddr = (UINT64)(UINTN) Db; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.station_addr() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) { + if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) { DEBUG ( (EFI_D_ERROR, "\nsnp->undi.station_addr() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); // @@ -163,54 +159,72 @@ pxe_set_stn_addr ( // // read the changed address and save it in SNP->Mode structure // - pxe_get_stn_addr (snp); + PxeGetStnAddr (Snp); return EFI_SUCCESS; } /** - This is the SNP interface routine for changing the NIC's mac address. - This routine basically retrieves snp structure, checks the SNP state and - calls the above routines to actually do the work - - @param this context pointer - @param NewMacAddr pointer to a mac address to be set for the nic, if this is - NULL then this routine resets the mac address to the NIC's - original address. - @param ResetFlag If true, the mac address will change to NIC's original - address - + Modifies or resets the current station address, if supported. + + This function modifies or resets the current station address of a network + interface, if supported. If Reset is TRUE, then the current station address is + set to the network interface’s permanent address. If Reset is FALSE, and the + network interface allows its station address to be modified, then the current + station address is changed to the address specified by New. If the network + interface does not allow its station address to be modified, then + EFI_INVALID_PARAMETER will be returned. If the station address is successfully + updated on the network interface, EFI_SUCCESS will be returned. If the driver + has not been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param Reset Flag used to reset the station address to the network interface’s + permanent address. + @param New New station address to be used for the network interface. + + + @retval EFI_SUCCESS The network interface’s station address was updated. + @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been + started by calling Start(). + @retval EFI_INVALID_PARAMETER The New station address was not accepted by the NIC. + @retval EFI_INVALID_PARAMETER Reset is FALSE and New is NULL. + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not + been initialized by calling Initialize(). + @retval EFI_DEVICE_ERROR An error occurred attempting to set the new + station address. + @retval EFI_UNSUPPORTED The NIC does not support changing the network + interface’s station address. **/ EFI_STATUS EFIAPI -snp_undi32_station_address ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - IN BOOLEAN ResetFlag, - IN EFI_MAC_ADDRESS * NewMacAddr OPTIONAL +SnpUndi32StationAddress ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN BOOLEAN Reset, + IN EFI_MAC_ADDRESS *New OPTIONAL ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_STATUS Status; EFI_TPL OldTpl; // // Check for invalid parameter combinations. // - if ((this == NULL) || - (!ResetFlag && (NewMacAddr == NULL))) { + if ((This == NULL) || + (!Reset && (New == NULL))) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); // // Return error if the SNP is not initialized. // - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -223,10 +237,10 @@ snp_undi32_station_address ( goto ON_EXIT; } - if (ResetFlag) { - Status = pxe_set_stn_addr (snp, NULL); + if (Reset) { + Status = PxeSetStnAddr (Snp, NULL); } else { - Status = pxe_set_stn_addr (snp, NewMacAddr); + Status = PxeSetStnAddr (Snp, New); } ON_EXIT: diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Statistics.c b/MdeModulePkg/Universal/Network/SnpDxe/Statistics.c index 19f28239a5..c52fc23db3 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Statistics.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Statistics.c @@ -1,21 +1,15 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of collecting the statistics on a network interface. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - statistics.c - -Abstract: - -Revision history: - 2000-Feb-17 M(f)J Genesis. - **/ @@ -23,50 +17,85 @@ Revision history: /** - This is the SNP interface routine for getting the NIC's statistics. - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_ routine to actually do the - - @param this context pointer - @param ResetFlag true to reset the NIC's statistics counters to zero. - @param StatTableSizePtr pointer to the statistics table size - @param StatTablePtr pointer to the statistics table - + Resets or collects the statistics on a network interface. + + This function resets or collects the statistics on a network interface. If the + size of the statistics table specified by StatisticsSize is not big enough for + all the statistics that are collected by the network interface, then a partial + buffer of statistics is returned in StatisticsTable, StatisticsSize is set to + the size required to collect all the available statistics, and + EFI_BUFFER_TOO_SMALL is returned. + If StatisticsSize is big enough for all the statistics, then StatisticsTable + will be filled, StatisticsSize will be set to the size of the returned + StatisticsTable structure, and EFI_SUCCESS is returned. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + If Reset is FALSE, and both StatisticsSize and StatisticsTable are NULL, then + no operations will be performed, and EFI_SUCCESS will be returned. + If Reset is TRUE, then all of the supported statistics counters on this network + interface will be reset to zero. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param Reset Set to TRUE to reset the statistics for the network interface. + @param StatisticsSize On input the size, in bytes, of StatisticsTable. On output + the size, in bytes, of the resulting table of statistics. + @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that + contains the statistics. Type EFI_NETWORK_STATISTICS is + defined in "Related Definitions" below. + + @retval EFI_SUCCESS The requested operation succeeded. + @retval EFI_NOT_STARTED The Simple Network Protocol interface has not been + started by calling Start(). + @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is + NULL. The current buffer size that is needed to + hold all the statistics is returned in StatisticsSize. + @retval EFI_BUFFER_TOO_SMALL StatisticsSize is not NULL and StatisticsTable is + not NULL. The current buffer size that is needed + to hold all the statistics is returned in + StatisticsSize. A partial set of statistics is + returned in StatisticsTable. + @retval EFI_INVALID_PARAMETER StatisticsSize is NULL and StatisticsTable is not + NULL. + @retval EFI_DEVICE_ERROR The Simple Network Protocol interface has not + been initialized by calling Initialize(). + @retval EFI_DEVICE_ERROR An error was encountered collecting statistics + from the NIC. + @retval EFI_UNSUPPORTED The NIC does not support collecting statistics + from the network interface. **/ EFI_STATUS EFIAPI -snp_undi32_statistics ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - IN BOOLEAN ResetFlag, - IN OUT UINTN *StatTableSizePtr OPTIONAL, - IN OUT EFI_NETWORK_STATISTICS * StatTablePtr OPTIONAL +SnpUndi32Statistics ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN BOOLEAN Reset, + IN OUT UINTN *StatisticsSize, OPTIONAL + IN OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL ) { - SNP_DRIVER *snp; - PXE_DB_STATISTICS *db; - UINT64 *stp; - UINT64 mask; - UINTN size; - UINTN n; + SNP_DRIVER *Snp; + PXE_DB_STATISTICS *Db; + UINT64 *Stp; + UINT64 Mask; + UINTN Size; + UINTN Index; EFI_TPL OldTpl; EFI_STATUS Status; // - // Get pointer to SNP driver instance for *this. + // Get pointer to SNP driver instance for *This. // - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); // // Return error if the SNP is not initialized. // - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -82,39 +111,39 @@ snp_undi32_statistics ( // if we are not resetting the counters, we have to have a valid stat table // with >0 size. if no reset, no table and no size, return success. // - if (!ResetFlag && StatTableSizePtr == NULL) { - Status = StatTablePtr ? EFI_INVALID_PARAMETER : EFI_SUCCESS; + if (!Reset && StatisticsSize == NULL) { + Status = (StatisticsTable != NULL) ? EFI_INVALID_PARAMETER : EFI_SUCCESS; goto ON_EXIT; } // // Initialize UNDI Statistics CDB // - snp->cdb.OpCode = PXE_OPCODE_STATISTICS; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; - - if (ResetFlag) { - snp->cdb.OpFlags = PXE_OPFLAGS_STATISTICS_RESET; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; - db = snp->db; + Snp->Cdb.OpCode = PXE_OPCODE_STATISTICS; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + 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; + + if (Reset) { + Snp->Cdb.OpFlags = PXE_OPFLAGS_STATISTICS_RESET; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; + Db = Snp->Db; } else { - snp->cdb.OpFlags = PXE_OPFLAGS_STATISTICS_READ; - snp->cdb.DBsize = sizeof (PXE_DB_STATISTICS); - snp->cdb.DBaddr = (UINT64)(UINTN) (db = snp->db); + Snp->Cdb.OpFlags = PXE_OPFLAGS_STATISTICS_READ; + Snp->Cdb.DBsize = sizeof (PXE_DB_STATISTICS); + Snp->Cdb.DBaddr = (UINT64)(UINTN) (Db = Snp->Db); } // // Issue UNDI command and check result. // DEBUG ((EFI_D_NET, "\nsnp->undi.statistics() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - switch (snp->cdb.StatCode) { + switch (Snp->Cdb.StatCode) { case PXE_STATCODE_SUCCESS: break; @@ -122,8 +151,8 @@ snp_undi32_statistics ( DEBUG ( (EFI_D_ERROR, "\nsnp->undi.statistics() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); Status = EFI_UNSUPPORTED; @@ -133,21 +162,21 @@ snp_undi32_statistics ( DEBUG ( (EFI_D_ERROR, "\nsnp->undi.statistics() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); Status = EFI_DEVICE_ERROR; goto ON_EXIT; } - if (ResetFlag) { + if (Reset) { Status = EFI_SUCCESS; goto ON_EXIT; } - if (StatTablePtr == NULL) { - *StatTableSizePtr = sizeof (EFI_NETWORK_STATISTICS); + if (StatisticsTable == NULL) { + *StatisticsSize = sizeof (EFI_NETWORK_STATISTICS); Status = EFI_BUFFER_TOO_SMALL; goto ON_EXIT; } @@ -155,42 +184,42 @@ snp_undi32_statistics ( // Convert the UNDI statistics information to SNP statistics // information. // - ZeroMem (StatTablePtr, *StatTableSizePtr); - stp = (UINT64 *) StatTablePtr; - size = 0; + ZeroMem (StatisticsTable, *StatisticsSize); + Stp = (UINT64 *) StatisticsTable; + Size = 0; - for (n = 0, mask = 1; n < 64; n++, mask = LShiftU64 (mask, 1), stp++) { + for (Index = 0, Mask = 1; Index < 64; Index++, Mask = LShiftU64 (Mask, 1), Stp++) { // // There must be room for a full UINT64. Partial // numbers will not be stored. // - if ((n + 1) * sizeof (UINT64) > *StatTableSizePtr) { + if ((Index + 1) * sizeof (UINT64) > *StatisticsSize) { break; } - if (db->Supported & mask) { - *stp = db->Data[n]; - size = n + 1; + if (Db->Supported & Mask) { + *Stp = Db->Data[Index]; + Size = Index + 1; } else { - SetMem (stp, sizeof (UINT64), 0xFF); + SetMem (Stp, sizeof (UINT64), 0xFF); } } // // Compute size up to last supported statistic. // - while (++n < 64) { - if (db->Supported & (mask = LShiftU64 (mask, 1))) { - size = n; + while (++Index < 64) { + if (Db->Supported & (Mask = LShiftU64 (Mask, 1))) { + Size = Index; } } - size *= sizeof (UINT64); + Size *= sizeof (UINT64); - if (*StatTableSizePtr >= size) { - *StatTableSizePtr = size; + if (*StatisticsSize >= Size) { + *StatisticsSize = Size; Status = EFI_SUCCESS; } else { - *StatTableSizePtr = size; + *StatisticsSize = Size; Status = EFI_BUFFER_TOO_SMALL; } diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Stop.c b/MdeModulePkg/Universal/Network/SnpDxe/Stop.c index 63725237b7..2eedfcd726 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Stop.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Stop.c @@ -1,62 +1,60 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of stopping a network interface. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - stop.c - -Abstract: - -Revision history: - 2000-Feb-09 M(f)J Genesis. - **/ #include "Snp.h" /** - this routine calls undi to stop the interface and changes the snp state + this routine calls undi to stop the interface and changes the snp state. - @param snp pointer to snp driver structure + @param Snp pointer to snp driver structure + @retval EFI_INVALID_PARAMETER invalid parameter + @retval EFI_NOT_STARTED SNP is not started + @retval EFI_DEVICE_ERROR SNP is not initialized + @retval EFI_UNSUPPORTED operation unsupported **/ EFI_STATUS -pxe_stop ( - SNP_DRIVER *snp +PxeStop ( + SNP_DRIVER *Snp ) { - snp->cdb.OpCode = PXE_OPCODE_STOP; - snp->cdb.OpFlags = PXE_OPFLAGS_NOT_USED; - snp->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + Snp->Cdb.OpCode = PXE_OPCODE_STOP; + Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED; + Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; + 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; // // Issue UNDI command // DEBUG ((EFI_D_NET, "\nsnp->undi.stop() ")); - (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb); - if (snp->cdb.StatCode != PXE_STATCODE_SUCCESS) { + if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) { DEBUG ( (EFI_D_WARN, "\nsnp->undi.stop() %xh:%xh\n", - snp->cdb.StatCode, - snp->cdb.StatFlags) + Snp->Cdb.StatCode, + Snp->Cdb.StatFlags) ); return EFI_DEVICE_ERROR; @@ -64,39 +62,48 @@ pxe_stop ( // // Set simple network state to Started and return success. // - snp->mode.State = EfiSimpleNetworkStopped; + Snp->Mode.State = EfiSimpleNetworkStopped; return EFI_SUCCESS; } /** - This is the SNP interface routine for stopping the interface. - This routine basically retrieves snp structure, checks the SNP state and - calls the pxe_stop routine to actually stop the undi interface - - @param this context pointer - + Changes the state of a network interface from "started" to "stopped." + + This function stops a network interface. This call is only valid if the network + interface is in the started state. If the network interface was successfully + stopped, then EFI_SUCCESS will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + + + @retval EFI_SUCCESS The network interface was stopped. + @retval EFI_NOT_STARTED The network interface has not been started. + @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 This function is not supported by the network interface. **/ EFI_STATUS EFIAPI -snp_undi32_stop ( - IN EFI_SIMPLE_NETWORK_PROTOCOL *this +SnpUndi32Stop ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_TPL OldTpl; EFI_STATUS Status; - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkStarted: break; @@ -109,7 +116,7 @@ snp_undi32_stop ( goto ON_EXIT; } - Status = pxe_stop (snp); + Status = PxeStop (Snp); ON_EXIT: gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Universal/Network/SnpDxe/Transmit.c b/MdeModulePkg/Universal/Network/SnpDxe/Transmit.c index 72012fada4..c9d8e715aa 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/Transmit.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/Transmit.c @@ -1,22 +1,15 @@ /** @file -Copyright (c) 2004 - 2007, Intel Corporation -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 + Implementation of transmitting a packet. + +Copyright (c) 2004 - 2007, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - - transmit.c - -Abstract: - -Revision history: - 2000-Feb-03 M(f)J Genesis. - **/ #include "Snp.h" @@ -25,13 +18,13 @@ Revision history: /** This routine calls undi to create the meadia header for the given data buffer. - @param snp pointer to SNP driver structure + @param Snp pointer to SNP driver structure @param MacHeaderPtr address where the media header will be filled in. - @param MacHeaderSize size of the memory at MacHeaderPtr - @param BufferPtr data buffer pointer - @param BufferLength Size of data in the BufferPtr - @param DestinationAddrPtr address of the destination mac address buffer - @param SourceAddrPtr address of the source mac address buffer + @param HeaderSize size of the memory at MacHeaderPtr + @param Buffer data buffer pointer + @param BufferSize Size of data in the Buffer + @param DestAddr address of the destination mac address buffer + @param SrcAddr address of the source mac address buffer @param ProtocolPtr address of the protocol type @retval EFI_SUCCESS if successfully completed the undi call @@ -39,89 +32,89 @@ Revision history: **/ EFI_STATUS -pxe_fillheader ( - SNP_DRIVER *snp, +PxeFillHeader ( + SNP_DRIVER *Snp, VOID *MacHeaderPtr, - UINTN MacHeaderSize, - VOID *BufferPtr, - UINTN BufferLength, - EFI_MAC_ADDRESS *DestinationAddrPtr, - EFI_MAC_ADDRESS *SourceAddrPtr, + UINTN HeaderSize, + VOID *Buffer, + UINTN BufferSize, + EFI_MAC_ADDRESS *DestAddr, + EFI_MAC_ADDRESS *SrcAddr, UINT16 *ProtocolPtr ) { - PXE_CPB_FILL_HEADER_FRAGMENTED *cpb; + PXE_CPB_FILL_HEADER_FRAGMENTED *Cpb; - cpb = snp->cpb; - if (SourceAddrPtr) { + Cpb = Snp->Cpb; + if (SrcAddr != NULL) { CopyMem ( - (VOID *) cpb->SrcAddr, - (VOID *) SourceAddrPtr, - snp->mode.HwAddressSize + (VOID *) Cpb->SrcAddr, + (VOID *) SrcAddr, + Snp->Mode.HwAddressSize ); } else { CopyMem ( - (VOID *) cpb->SrcAddr, - (VOID *) &(snp->mode.CurrentAddress), - snp->mode.HwAddressSize + (VOID *) Cpb->SrcAddr, + (VOID *) &(Snp->Mode.CurrentAddress), + Snp->Mode.HwAddressSize ); } CopyMem ( - (VOID *) cpb->DestAddr, - (VOID *) DestinationAddrPtr, - snp->mode.HwAddressSize + (VOID *) Cpb->DestAddr, + (VOID *) DestAddr, + Snp->Mode.HwAddressSize ); // // we need to do the byte swapping // - cpb->Protocol = (UINT16) PXE_SWAP_UINT16 (*ProtocolPtr); + Cpb->Protocol = (UINT16) PXE_SWAP_UINT16 (*ProtocolPtr); - cpb->PacketLen = (UINT32) (BufferLength); - cpb->MediaHeaderLen = (UINT16) MacHeaderSize; + Cpb->PacketLen = (UINT32) (BufferSize); + Cpb->MediaHeaderLen = (UINT16) HeaderSize; - cpb->FragCnt = 2; - cpb->reserved = 0; + Cpb->FragCnt = 2; + Cpb->reserved = 0; - cpb->FragDesc[0].FragAddr = (UINT64)(UINTN) MacHeaderPtr; - cpb->FragDesc[0].FragLen = (UINT32) MacHeaderSize; - cpb->FragDesc[1].FragAddr = (UINT64)(UINTN) BufferPtr; - cpb->FragDesc[1].FragLen = (UINT32) BufferLength; + Cpb->FragDesc[0].FragAddr = (UINT64)(UINTN) MacHeaderPtr; + Cpb->FragDesc[0].FragLen = (UINT32) HeaderSize; + Cpb->FragDesc[1].FragAddr = (UINT64)(UINTN) Buffer; + Cpb->FragDesc[1].FragLen = (UINT32) BufferSize; - cpb->FragDesc[0].reserved = cpb->FragDesc[1].reserved = 0; + Cpb->FragDesc[0].reserved = Cpb->FragDesc[1].reserved = 0; - snp->cdb.OpCode = PXE_OPCODE_FILL_HEADER; - snp->cdb.OpFlags = PXE_OPFLAGS_FILL_HEADER_FRAGMENTED; + Snp->Cdb.OpCode = PXE_OPCODE_FILL_HEADER; + Snp->Cdb.OpFlags = PXE_OPFLAGS_FILL_HEADER_FRAGMENTED; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.CPBsize = sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED); - snp->cdb.CPBaddr = (UINT64)(UINTN) cpb; + Snp->Cdb.CPBsize = sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED); + Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; // // Issue UNDI command and check result. // - DEBUG ((EFI_D_NET, "\nsnp->undi.fill_header() ")); + DEBUG ((EFI_D_NET, "\nSnp->undi.fill_header() ")); - (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64) (UINTN) &Snp->Cdb); - switch (snp->cdb.StatCode) { + switch (Snp->Cdb.StatCode) { case PXE_STATCODE_SUCCESS: return EFI_SUCCESS; case PXE_STATCODE_INVALID_PARAMETER: DEBUG ( (EFI_D_ERROR, - "\nsnp->undi.fill_header() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + "\nSnp->undi.fill_header() %xh:%xh\n", + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_INVALID_PARAMETER; @@ -129,9 +122,9 @@ pxe_fillheader ( default: DEBUG ( (EFI_D_ERROR, - "\nsnp->undi.fill_header() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + "\nSnp->undi.fill_header() %xh:%xh\n", + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return EFI_DEVICE_ERROR; @@ -142,63 +135,63 @@ pxe_fillheader ( /** This routine calls undi to transmit the given data buffer - @param snp pointer to SNP driver structure - @param BufferPtr data buffer pointer - @param BufferLength Size of data in the BufferPtr + @param Snp pointer to SNP driver structure + @param Buffer data buffer pointer + @param BufferSize Size of data in the Buffer @retval EFI_SUCCESS if successfully completed the undi call @retval Other error return from undi call. **/ EFI_STATUS -pxe_transmit ( - SNP_DRIVER *snp, - VOID *BufferPtr, - UINTN BufferLength +PxeTransmit ( + SNP_DRIVER *Snp, + VOID *Buffer, + UINTN BufferSize ) { - PXE_CPB_TRANSMIT *cpb; + PXE_CPB_TRANSMIT *Cpb; EFI_STATUS Status; - cpb = snp->cpb; - cpb->FrameAddr = (UINT64) (UINTN) BufferPtr; - cpb->DataLen = (UINT32) BufferLength; + Cpb = Snp->Cpb; + Cpb->FrameAddr = (UINT64) (UINTN) Buffer; + Cpb->DataLen = (UINT32) BufferSize; - cpb->MediaheaderLen = 0; - cpb->reserved = 0; + Cpb->MediaheaderLen = 0; + Cpb->reserved = 0; - snp->cdb.OpFlags = PXE_OPFLAGS_TRANSMIT_WHOLE; + Snp->Cdb.OpFlags = PXE_OPFLAGS_TRANSMIT_WHOLE; - snp->cdb.CPBsize = sizeof (PXE_CPB_TRANSMIT); - snp->cdb.CPBaddr = (UINT64)(UINTN) cpb; + Snp->Cdb.CPBsize = sizeof (PXE_CPB_TRANSMIT); + Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb; - snp->cdb.OpCode = PXE_OPCODE_TRANSMIT; - snp->cdb.DBsize = PXE_DBSIZE_NOT_USED; - snp->cdb.DBaddr = PXE_DBADDR_NOT_USED; + Snp->Cdb.OpCode = PXE_OPCODE_TRANSMIT; + Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED; + Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED; - snp->cdb.StatCode = PXE_STATCODE_INITIALIZE; - snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - snp->cdb.IFnum = snp->if_num; - snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + 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; // // Issue UNDI command and check result. // - DEBUG ((EFI_D_NET, "\nsnp->undi.transmit() ")); - DEBUG ((EFI_D_NET, "\nsnp->cdb.OpCode == %x", snp->cdb.OpCode)); - DEBUG ((EFI_D_NET, "\nsnp->cdb.CPBaddr == %LX", snp->cdb.CPBaddr)); - DEBUG ((EFI_D_NET, "\nsnp->cdb.DBaddr == %LX", snp->cdb.DBaddr)); - DEBUG ((EFI_D_NET, "\ncpb->FrameAddr == %LX\n", cpb->FrameAddr)); + DEBUG ((EFI_D_NET, "\nSnp->undi.transmit() ")); + DEBUG ((EFI_D_NET, "\nSnp->Cdb.OpCode == %x", Snp->Cdb.OpCode)); + DEBUG ((EFI_D_NET, "\nSnp->Cdb.CPBaddr == %LX", Snp->Cdb.CPBaddr)); + DEBUG ((EFI_D_NET, "\nSnp->Cdb.DBaddr == %LX", Snp->Cdb.DBaddr)); + DEBUG ((EFI_D_NET, "\nCpb->FrameAddr == %LX\n", Cpb->FrameAddr)); - (*snp->issue_undi32_command) ((UINT64) (UINTN) &snp->cdb); + (*Snp->IssueUndi32Command) ((UINT64) (UINTN) &Snp->Cdb); - DEBUG ((EFI_D_NET, "\nexit snp->undi.transmit() ")); - DEBUG ((EFI_D_NET, "\nsnp->cdb.StatCode == %r", snp->cdb.StatCode)); + DEBUG ((EFI_D_NET, "\nexit Snp->undi.transmit() ")); + DEBUG ((EFI_D_NET, "\nSnp->Cdb.StatCode == %r", Snp->Cdb.StatCode)); // // we will unmap the buffers in get_status call, not here // - switch (snp->cdb.StatCode) { + switch (Snp->Cdb.StatCode) { case PXE_STATCODE_SUCCESS: return EFI_SUCCESS; @@ -213,61 +206,97 @@ pxe_transmit ( DEBUG ( (EFI_D_ERROR, - "\nsnp->undi.transmit() %xh:%xh\n", - snp->cdb.StatFlags, - snp->cdb.StatCode) + "\nSnp->undi.transmit() %xh:%xh\n", + Snp->Cdb.StatFlags, + Snp->Cdb.StatCode) ); return Status; } - /** - This is the snp interface routine for transmitting a packet. this routine - basically retrieves the snp structure, checks the snp state and calls - pxe_fill_header and pxe_transmit calls to complete the transmission. - - @param this pointer to SNP driver context - @param MacHeaderSize size of the memory at MacHeaderPtr - @param BufferLength Size of data in the BufferPtr - @param BufferPtr data buffer pointer - @param SourceAddrPtr address of the source mac address buffer - @param DestinationAddrPtr address of the destination mac address buffer - @param ProtocolPtr address of the protocol type - - @retval EFI_SUCCESS if successfully completed the undi call - @retval Other error return from undi call. + Places a packet in the transmit queue of a network interface. + + This function places the packet specified by Header and Buffer on the transmit + queue. If HeaderSize is nonzero and HeaderSize is not equal to + This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If + BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL + will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be + returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then + EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network + interface is busy, then EFI_NOT_READY will be returned. If this packet can be + accepted by the transmit engine of the network interface, the packet contents + specified by Buffer will be placed on the transmit queue of the network + interface, and EFI_SUCCESS will be returned. GetStatus() can be used to + determine when the packet has actually been transmitted. The contents of the + Buffer must not be modified until the packet has actually been transmitted. + The Transmit() function performs nonblocking I/O. A caller who wants to perform + blocking I/O, should call Transmit(), and then GetStatus() until the + transmitted buffer shows up in the recycled transmit buffer. + If the driver has not been initialized, EFI_DEVICE_ERROR will be returned. + + @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance. + @param HeaderSize The size, in bytes, of the media header to be filled in by the + Transmit() function. If HeaderSize is nonzero, then it must + be equal to This->Mode->MediaHeaderSize and the DestAddr and + Protocol parameters must not be NULL. + @param BufferSize The size, in bytes, of the entire packet (media header and + data) to be transmitted through the network interface. + @param Buffer A pointer to the packet (media header followed by data) to be + transmitted. This parameter cannot be NULL. If HeaderSize is + zero, then the media header in Buffer must already be filled + in by the caller. If HeaderSize is nonzero, then the media + header will be filled in by the Transmit() function. + @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this + parameter is ignored. If HeaderSize is nonzero and SrcAddr + is NULL, then This->Mode->CurrentAddress is used for the + source HW MAC address. + @param DestAddr The destination HW MAC address. If HeaderSize is zero, then + this parameter is ignored. + @param Protocol The type of header to build. If HeaderSize is zero, then this + parameter is ignored. See RFC 1700, section "Ether Types," + for examples. + + @retval EFI_SUCCESS The packet was placed on the transmit queue. + @retval EFI_NOT_STARTED The network interface has not been started. + @retval EFI_NOT_READY The network interface is too busy to accept this + transmit request. + @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small. + @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported + value. + @retval EFI_DEVICE_ERROR The command could not be sent to the network interface. + @retval EFI_UNSUPPORTED This function is not supported by the network interface. **/ EFI_STATUS EFIAPI -snp_undi32_transmit ( - IN EFI_SIMPLE_NETWORK_PROTOCOL * this, - IN UINTN MacHeaderSize, - IN UINTN BufferLength, - IN VOID *BufferPtr, - IN EFI_MAC_ADDRESS * SourceAddrPtr OPTIONAL, - IN EFI_MAC_ADDRESS * DestinationAddrPtr OPTIONAL, - IN UINT16 *ProtocolPtr OPTIONAL +SnpUndi32Transmit ( + IN EFI_SIMPLE_NETWORK_PROTOCOL *This, + IN UINTN HeaderSize, + IN UINTN BufferSize, + IN VOID *Buffer, + IN EFI_MAC_ADDRESS *SrcAddr, OPTIONAL + IN EFI_MAC_ADDRESS *DestAddr, OPTIONAL + IN UINT16 *Protocol OPTIONAL ) { - SNP_DRIVER *snp; + SNP_DRIVER *Snp; EFI_STATUS Status; EFI_TPL OldTpl; - if (this == NULL) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } - snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this); + Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This); OldTpl = gBS->RaiseTPL (TPL_CALLBACK); - if (snp == NULL) { + if (Snp == NULL) { return EFI_DEVICE_ERROR; } - switch (snp->mode.State) { + switch (Snp->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -280,35 +309,35 @@ snp_undi32_transmit ( goto ON_EXIT; } - if (BufferPtr == NULL) { + if (Buffer == NULL) { Status = EFI_INVALID_PARAMETER; goto ON_EXIT; } - if (BufferLength < snp->mode.MediaHeaderSize) { + if (BufferSize < Snp->Mode.MediaHeaderSize) { Status = EFI_BUFFER_TOO_SMALL; goto ON_EXIT; } // - // if the MacHeaderSize is non-zero, we need to fill up the header and for that + // if the HeaderSize is non-zero, we need to fill up the header and for that // we need the destination address and the protocol // - if (MacHeaderSize != 0) { - if (MacHeaderSize != snp->mode.MediaHeaderSize || DestinationAddrPtr == 0 || ProtocolPtr == 0) { + if (HeaderSize != 0) { + if (HeaderSize != Snp->Mode.MediaHeaderSize || DestAddr == 0 || Protocol == 0) { Status = EFI_INVALID_PARAMETER; goto ON_EXIT; } - Status = pxe_fillheader ( - snp, - BufferPtr, - MacHeaderSize, - (UINT8 *) BufferPtr + MacHeaderSize, - BufferLength - MacHeaderSize, - DestinationAddrPtr, - SourceAddrPtr, - ProtocolPtr + Status = PxeFillHeader ( + Snp, + Buffer, + HeaderSize, + (UINT8 *) Buffer + HeaderSize, + BufferSize - HeaderSize, + DestAddr, + SrcAddr, + Protocol ); if (EFI_ERROR (Status)) { @@ -316,7 +345,7 @@ snp_undi32_transmit ( } } - Status = pxe_transmit (snp, BufferPtr, BufferLength); + Status = PxeTransmit (Snp, Buffer, BufferSize); ON_EXIT: gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Universal/Network/SnpDxe/WaitForPacket.c b/MdeModulePkg/Universal/Network/SnpDxe/WaitForPacket.c index 57d82ea160..8dd8fd997e 100644 --- a/MdeModulePkg/Universal/Network/SnpDxe/WaitForPacket.c +++ b/MdeModulePkg/Universal/Network/SnpDxe/WaitForPacket.c @@ -1,28 +1,25 @@ /** @file -Copyright (c) 2004, Intel Corporation -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 + Event handler to check for available packet. + +Copyright (c) 2004 - 2008, Intel Corporation.
+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 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module name: - WaitForPacket.c - -Abstract: - Event handler to check for available packet. - - **/ #include "Snp.h" /** + Nofication call back function for WaitForPacket event. - + @param Event EFI Event. + @param SnpPtr Pointer to SNP_DRIVER structure. **/ VOID @@ -43,7 +40,7 @@ SnpWaitForPacketNotify ( // // Do nothing if the SNP interface is not initialized. // - switch (((SNP_DRIVER *) SnpPtr)->mode.State) { + switch (((SNP_DRIVER *) SnpPtr)->Mode.State) { case EfiSimpleNetworkInitialized: break; @@ -55,28 +52,28 @@ SnpWaitForPacketNotify ( // // Fill in CDB for UNDI GetStatus(). // - ((SNP_DRIVER *) SnpPtr)->cdb.OpCode = PXE_OPCODE_GET_STATUS; - ((SNP_DRIVER *) SnpPtr)->cdb.OpFlags = 0; - ((SNP_DRIVER *) SnpPtr)->cdb.CPBsize = PXE_CPBSIZE_NOT_USED; - ((SNP_DRIVER *) SnpPtr)->cdb.CPBaddr = PXE_CPBADDR_NOT_USED; - ((SNP_DRIVER *) SnpPtr)->cdb.DBsize = sizeof (UINT32) * 2; - ((SNP_DRIVER *) SnpPtr)->cdb.DBaddr = (UINT64)(UINTN) (((SNP_DRIVER *) SnpPtr)->db); - ((SNP_DRIVER *) SnpPtr)->cdb.StatCode = PXE_STATCODE_INITIALIZE; - ((SNP_DRIVER *) SnpPtr)->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; - ((SNP_DRIVER *) SnpPtr)->cdb.IFnum = ((SNP_DRIVER *) SnpPtr)->if_num; - ((SNP_DRIVER *) SnpPtr)->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; + ((SNP_DRIVER *) SnpPtr)->Cdb.OpCode = PXE_OPCODE_GET_STATUS; + ((SNP_DRIVER *) SnpPtr)->Cdb.OpFlags = 0; + ((SNP_DRIVER *) SnpPtr)->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED; + ((SNP_DRIVER *) SnpPtr)->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED; + ((SNP_DRIVER *) SnpPtr)->Cdb.DBsize = sizeof (UINT32) * 2; + ((SNP_DRIVER *) SnpPtr)->Cdb.DBaddr = (UINT64)(UINTN) (((SNP_DRIVER *) SnpPtr)->Db); + ((SNP_DRIVER *) SnpPtr)->Cdb.StatCode = PXE_STATCODE_INITIALIZE; + ((SNP_DRIVER *) SnpPtr)->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE; + ((SNP_DRIVER *) SnpPtr)->Cdb.IFnum = ((SNP_DRIVER *) SnpPtr)->IfNum; + ((SNP_DRIVER *) SnpPtr)->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST; // // Clear contents of DB buffer. // - ZeroMem (((SNP_DRIVER *) SnpPtr)->db, sizeof (UINT32) * 2); + ZeroMem (((SNP_DRIVER *) SnpPtr)->Db, sizeof (UINT32) * 2); // // Issue UNDI command and check result. // - (*((SNP_DRIVER *) SnpPtr)->issue_undi32_command) ((UINT64)(UINTN) &((SNP_DRIVER *) SnpPtr)->cdb); + (*((SNP_DRIVER *) SnpPtr)->IssueUndi32Command) ((UINT64)(UINTN) &((SNP_DRIVER *) SnpPtr)->Cdb); - if (((SNP_DRIVER *) SnpPtr)->cdb.StatCode != EFI_SUCCESS) { + if (((SNP_DRIVER *) SnpPtr)->Cdb.StatCode != EFI_SUCCESS) { return ; } // @@ -85,7 +82,7 @@ SnpWaitForPacketNotify ( // CopyMem ( &PxeDbGetStatus, - ((SNP_DRIVER *) SnpPtr)->db, + ((SNP_DRIVER *) SnpPtr)->Db, sizeof (UINT32) * 2 );