diff options
author | Yu Pei <pei.yu@intel.com> | 2013-06-27 05:07:29 +0000 |
---|---|---|
committer | qianouyang <qianouyang@6f19259b-4bc3-4df7-8a09-765794883524> | 2013-06-27 05:07:29 +0000 |
commit | 4986bbaf1151d1cccc1f2589bd13a86b539676b2 (patch) | |
tree | 978f1316e6cd66d885ed3de0974d860bb196ae4e /OptionRomPkg/Bus/Usb | |
parent | ca243131657ba03f58206a417b938aa14cff585c (diff) | |
download | edk2-4986bbaf1151d1cccc1f2589bd13a86b539676b2.tar.gz edk2-4986bbaf1151d1cccc1f2589bd13a86b539676b2.tar.bz2 edk2-4986bbaf1151d1cccc1f2589bd13a86b539676b2.zip |
Ax88772: Add logic to separate packet, fix MTU issue. Ax88772b: Fix driver model unload function, fix SCT test failures.
Signed-off-by: Yu Pei <pei.yu@intel.com>
Reviewed-by: Ouyang Qian <qian.ouyang@intel.com>
Reviewed-by: Leahy, Leroy P <Leroy.P.Leahy@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14443 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'OptionRomPkg/Bus/Usb')
8 files changed, 341 insertions, 207 deletions
diff --git a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.c b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.c index 746a509b79..dd18a957b8 100644 --- a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.c +++ b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.c @@ -656,6 +656,78 @@ Ax88772Reset ( }
+VOID
+FillPkt2Queue (
+ IN NIC_DEVICE * pNicDevice,
+ IN UINTN BufLength)
+{
+
+ UINT16 * pLength;
+ UINT16 * pLengthBar;
+ UINT8* pData;
+ UINT32 offset;
+ RX_TX_PACKET * pRxPacket;
+ UINTN LengthInBytes;
+ EFI_STATUS Status;
+
+ for ( offset = 0; offset < BufLength; ){
+ pLength = (UINT16*) (pNicDevice->pBulkInBuff + offset);
+ pLengthBar = (UINT16*) (pNicDevice->pBulkInBuff + offset +2);
+
+ *pLength &= 0x7ff;
+ *pLengthBar &= 0x7ff;
+ *pLengthBar |= 0xf800;
+
+ if ((*pLength ^ *pLengthBar ) != 0xFFFF) {
+ DEBUG (( EFI_D_ERROR , "Pkt length error. BufLength = %d\n", BufLength));
+ return;
+ }
+
+ pRxPacket = pNicDevice->pRxFree;
+ LengthInBytes = sizeof ( *pRxPacket ) - sizeof ( pRxPacket->pNext );
+ if ( NULL == pRxPacket ) {
+ Status = gBS->AllocatePool ( EfiRuntimeServicesData,
+ sizeof( RX_TX_PACKET ),
+ (VOID **) &pRxPacket );
+ if ( !EFI_ERROR ( Status )) {
+ //
+ // Add this packet to the free packet list
+ //
+ pNicDevice->pRxFree = pRxPacket;
+ pRxPacket->pNext = NULL;
+ }
+ else {
+ //
+ // Use the discard packet buffer
+ //
+ //pRxPacket = &Packet;
+ }
+ }
+
+
+ pData = pNicDevice->pBulkInBuff + offset + 4;
+ pRxPacket->Length = *pLength;
+ pRxPacket->LengthBar = *(UINT16*) (pNicDevice->pBulkInBuff + offset +2);
+ CopyMem (&pRxPacket->Data[0], pData, *pLength);
+ //DEBUG((DEBUG_INFO, "Packet [%d]\n", *pLength));
+
+ pNicDevice->pRxFree = pRxPacket->pNext;
+ pRxPacket->pNext = NULL;
+
+ if ( NULL == pNicDevice->pRxTail ) {
+ pNicDevice->pRxHead = pRxPacket;
+ }
+ else {
+ pNicDevice->pRxTail->pNext = pRxPacket;
+ }
+ pNicDevice->pRxTail = pRxPacket;
+ offset += (*pLength + 4);
+
+ }
+}
+
+
+
/**
Receive a frame from the network.
@@ -760,10 +832,10 @@ Ax88772Rx ( // Locate a packet for use
//
pRxPacket = pNicDevice->pRxFree;
- LengthInBytes = sizeof ( *pRxPacket ) - sizeof ( pRxPacket->pNext );
+ LengthInBytes = MAX_BULKIN_SIZE;
if ( NULL == pRxPacket ) {
Status = gBS->AllocatePool ( EfiRuntimeServicesData,
- LengthInBytes,
+ sizeof ( *pRxPacket ),
(VOID **) &pRxPacket );
if ( !EFI_ERROR ( Status )) {
//
@@ -783,16 +855,22 @@ Ax88772Rx ( //
// Attempt to receive a packet
//
+ SetMem (&pNicDevice->pBulkInBuff[0], MAX_BULKIN_SIZE, 0);
pUsbIo = pNicDevice->pUsbIo;
Status = pUsbIo->UsbBulkTransfer ( pUsbIo,
USB_ENDPOINT_DIR_IN | BULK_IN_ENDPOINT,
- &pRxPacket->Length,
+ &pNicDevice->pBulkInBuff[0],
&LengthInBytes,
2,
&TransferStatus );
+ if ( LengthInBytes > 0 ) {
+ FillPkt2Queue(pNicDevice, LengthInBytes);
+ }
+ pRxPacket = pNicDevice->pRxHead;
if (( !EFI_ERROR ( Status ))
&& ( 0 < pRxPacket->Length )
- && ( pRxPacket->Length <= sizeof ( pRxPacket->Data ))) {
+ && ( pRxPacket->Length <= sizeof ( pRxPacket->Data ))
+ && ( LengthInBytes > 0)) {
//
// Determine if the packet should be received
@@ -869,22 +947,6 @@ Ax88772Rx ( LengthInBytes ));
}
- //
- // Remove this packet from the free packet list
- //
- pNicDevice->pRxFree = pRxPacket->pNext;
- pRxPacket->pNext = NULL;
-
- //
- // Append this packet to the receive list
- //
- if ( NULL == pNicDevice->pRxTail ) {
- pNicDevice->pRxHead = pRxPacket;
- }
- else {
- pNicDevice->pRxTail->pNext = pRxPacket;
- }
- pNicDevice->pRxTail = pRxPacket;
}
else {
//
diff --git a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.h b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.h index fa4008c2cf..3c02725bdc 100644 --- a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.h +++ b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.h @@ -39,22 +39,24 @@ //------------------------------------------------------------------------------
// Macros
//------------------------------------------------------------------------------
-
-#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
-#define DBG_ENTER() DEBUG (( DEBUG_INFO, "Entering " __FUNCTION__ "\n" )) ///< Display routine entry
-#define DBG_EXIT() DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ "\n" )) ///< Display routine exit
-#define DBG_EXIT_DEC(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %d\n", Status )) ///< Display routine exit with decimal value
-#define DBG_EXIT_HEX(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: 0x%08x\n", Status )) ///< Display routine exit with hex value
-#define DBG_EXIT_STATUS(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %r\n", Status )) ///< Display routine exit with status value
-#define DBG_EXIT_TF(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", returning %s\n", (FALSE == Status) ? L"FALSE" : L"TRUE" )) ///< Display routine with TRUE/FALSE value
-#else // _MSC_VER
+//
+//Too many output debug info hangs system in Debug tip
+//
+//#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
+//#define DBG_ENTER() DEBUG (( DEBUG_INFO, "Entering " __FUNCTION__ "\n" )) ///< Display routine entry
+//#define DBG_EXIT() DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ "\n" )) ///< Display routine exit
+//#define DBG_EXIT_DEC(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %d\n", Status )) ///< Display routine exit with decimal value
+//#define DBG_EXIT_HEX(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: 0x%08x\n", Status )) ///< Display routine exit with hex value
+//#define DBG_EXIT_STATUS(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %r\n", Status )) ///< Display routine exit with status value
+//#define DBG_EXIT_TF(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", returning %s\n", (FALSE == Status) ? L"FALSE" : L"TRUE" )) ///< Display routine with TRUE/FALSE value
+//#else // _MSC_VER
#define DBG_ENTER() ///< Display routine entry
#define DBG_EXIT() ///< Display routine exit
#define DBG_EXIT_DEC(Status) ///< Display routine exit with decimal value
#define DBG_EXIT_HEX(Status) ///< Display routine exit with hex value
#define DBG_EXIT_STATUS(Status) ///< Display routine exit with status value
#define DBG_EXIT_TF(Status) ///< Display routine with TRUE/FALSE value
-#endif // _MSC_VER
+//#endif // _MSC_VER
#define USB_IS_IN_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) != 0) ///< Return TRUE/FALSE for IN direction
#define USB_IS_OUT_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == 0) ///< Return TRUE/FALSE for OUT direction
@@ -80,6 +82,8 @@ #define ETHERNET_HEADER_SIZE sizeof ( ETHERNET_HEADER ) ///< Size in bytes of the Ethernet header
#define MIN_ETHERNET_PKT_SIZE 60 ///< Minimum packet size including Ethernet header
#define MAX_ETHERNET_PKT_SIZE 1500 ///< Ethernet spec 3.1.1: Minimum packet size
+#define MAX_BULKIN_SIZE 2048 ///< Maximum size of one UsbBulk
+
#define USB_NETWORK_CLASS 0x09 ///< USB Network class code
#define USB_BUS_TIMEOUT 1000 ///< USB timeout in milliseconds
@@ -340,6 +344,7 @@ typedef struct { RX_TX_PACKET * pRxTail; ///< Tail of receive packet list
RX_TX_PACKET * pRxFree; ///< Free packet list
INT32 MulticastHash[2]; ///< Hash table for multicast destination addresses
+ UINT8 * pBulkInBuff; ///< Buffer for Usb Bulk
} NIC_DEVICE;
#define DEV_FROM_SIMPLE_NETWORK(a) CR (a, NIC_DEVICE, SimpleNetwork, DEV_SIGNATURE) ///< Locate NIC_DEVICE from Simple Network Protocol
diff --git a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.inf b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.inf index 6a5de95914..5507cbbf3b 100644 --- a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.inf +++ b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/Ax88772.inf @@ -2,7 +2,7 @@ # Component description file for ASIX AX88772 USB/Ethernet driver.
#
# This module provides support for the ASIX AX88772 USB/Ethernet adapter.
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011-2013, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -15,7 +15,7 @@ ##
[Defines]
- INF_VERSION = 0x00010005
+ INF_VERSION = 0x00010018
BASE_NAME = Ax88772
FILE_GUID = B15239D6-6A01-4808-A0F7-B7F20F073555
MODULE_TYPE = DXE_RUNTIME_DRIVER
@@ -48,15 +48,10 @@ UefiDriverEntryPoint
[Protocols]
- gEfiDevicePathProtocolGuid
- gEfiSimpleNetworkProtocolGuid
+ gEfiDevicePathProtocolGuid ## BY_START
+ gEfiSimpleNetworkProtocolGuid ## BY_START
gEfiUsbIoProtocolGuid ## TO_START
-[Guids]
- gEfiEventExitBootServicesGuid ## PRODUCES ## Event
- gEfiEventVirtualAddressChangeGuid ## PRODUCES ## Event
- gEfiNicIp4ConfigVariableGuid
-
[Depex]
gEfiBdsArchProtocolGuid AND
gEfiCpuArchProtocolGuid AND
diff --git a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/DriverBinding.c b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/DriverBinding.c index 794b87e7f3..a04abee3cd 100644 --- a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/DriverBinding.c +++ b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/DriverBinding.c @@ -1,7 +1,7 @@ /** @file
Implement the driver binding protocol for Asix AX88772 Ethernet driver.
- Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2011-2013, Intel Corporation. All rights reserved.<BR>
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
@@ -481,24 +481,11 @@ EntryPoint ( IN EFI_SYSTEM_TABLE * pSystemTable
)
{
- EFI_LOADED_IMAGE_PROTOCOL * pLoadedImage;
EFI_STATUS Status;
DBG_ENTER ( );
//
- // Enable unload support
- //
- Status = gBS->HandleProtocol (
- gImageHandle,
- &gEfiLoadedImageProtocolGuid,
- (VOID **)&pLoadedImage
- );
- if (!EFI_ERROR (Status)) {
- pLoadedImage->Unload = DriverUnload;
- }
-
- //
// Add the driver to the list of drivers
//
Status = EfiLibInstallDriverBindingComponentName2 (
diff --git a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/SimpleNetwork.c b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/SimpleNetwork.c index 1b9e26195f..a341f3bfce 100644 --- a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/SimpleNetwork.c +++ b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772/SimpleNetwork.c @@ -858,7 +858,7 @@ SN_Setup ( pMode->State = EfiSimpleNetworkStopped;
pMode->HwAddressSize = PXE_HWADDR_LEN_ETHER;
pMode->MediaHeaderSize = sizeof ( ETHERNET_HEADER );
- pMode->MaxPacketSize = AX88772_MAX_PKT_SIZE;
+ pMode->MaxPacketSize = MAX_ETHERNET_PKT_SIZE;
pMode->NvRamSize = 0;
pMode->NvRamAccessSize = 0;
pMode->ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
@@ -885,6 +885,15 @@ SN_Setup ( pNicDevice->PhyId = PHY_ID_INTERNAL;
pNicDevice->b100Mbps = TRUE;
pNicDevice->bFullDuplex = TRUE;
+
+ Status = gBS->AllocatePool ( EfiRuntimeServicesData,
+ MAX_BULKIN_SIZE,
+ (VOID **) &pNicDevice->pBulkInBuff);
+ if ( EFI_ERROR(Status)) {
+ DEBUG (( EFI_D_ERROR, "Memory are not enough\n"));
+ return Status;
+ }
+
Status = Ax88772MacAddressGet (
pNicDevice,
&pMode->PermanentAddress.Addr[0]);
@@ -958,7 +967,7 @@ SN_Start ( pMode->State = EfiSimpleNetworkStarted;
pMode->HwAddressSize = PXE_HWADDR_LEN_ETHER;
pMode->MediaHeaderSize = sizeof ( ETHERNET_HEADER );
- pMode->MaxPacketSize = AX88772_MAX_PKT_SIZE;
+ pMode->MaxPacketSize = MAX_ETHERNET_PKT_SIZE;
pMode->ReceiveFilterMask = EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
| EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
| EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
@@ -1360,7 +1369,11 @@ SN_Transmit ( // Update the link status
//
pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
- Ax88772Rx ( pNicDevice, FALSE );
+
+ //
+ //No need to call receive to receive packet
+ //
+ //Ax88772Rx ( pNicDevice, FALSE );
pMode->MediaPresent = pNicDevice->bLinkUp;
//
diff --git a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf index b1cf562171..32a62f620d 100644 --- a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf +++ b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/Ax88772b.inf @@ -1,10 +1,10 @@ -#/** @file
+## @file
# Component description file for ASIX AX88772 USB/Ethernet driver.
#
# This module provides support for the ASIX AX88772 USB/Ethernet adapter.
-# Copyright (c) 2011, Intel Corporation
+# Copyright (c) 2011-2013, Intel Corporation. All rights reserved.<BR>
#
-# All rights reserved. This program and the accompanying materials
+# 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
@@ -12,10 +12,10 @@ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
-#**/
+##
[Defines]
- INF_VERSION = 0x00010005
+ INF_VERSION = 0x00010018
BASE_NAME = Ax88772b
FILE_GUID = 95C8D770-E1A4-4422-B263-E32F14FD8186
MODULE_TYPE = DXE_RUNTIME_DRIVER
@@ -47,16 +47,11 @@ UefiRuntimeLib
UefiDriverEntryPoint
-[Protocols]
- gEfiDevicePathProtocolGuid
- gEfiSimpleNetworkProtocolGuid
+[Protocols]
+ gEfiDevicePathProtocolGuid ## BY_START
+ gEfiSimpleNetworkProtocolGuid ## BY_START
gEfiUsbIoProtocolGuid ## TO_START
-[Guids]
- gEfiEventExitBootServicesGuid ## PRODUCES ## Event
- gEfiEventVirtualAddressChangeGuid ## PRODUCES ## Event
- gEfiNicIp4ConfigVariableGuid
-
[Depex]
gEfiBdsArchProtocolGuid AND
gEfiCpuArchProtocolGuid AND
diff --git a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/DriverBinding.c b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/DriverBinding.c index 076b639638..3b73040478 100644 --- a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/DriverBinding.c +++ b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/DriverBinding.c @@ -1,7 +1,7 @@ /** @file
Implement the driver binding protocol for Asix AX88772 Ethernet driver.
- Copyright (c) 2011, Intel Corporation
+ Copyright (c) 2011-2013, 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
@@ -632,22 +632,9 @@ EntryPoint ( IN EFI_SYSTEM_TABLE * pSystemTable
)
{
- EFI_LOADED_IMAGE_PROTOCOL * pLoadedImage;
EFI_STATUS Status;
//
- // Enable unload support
- //
- Status = gBS->HandleProtocol (
- gImageHandle,
- &gEfiLoadedImageProtocolGuid,
- (VOID **)&pLoadedImage
- );
- if (!EFI_ERROR (Status)) {
- pLoadedImage->Unload = DriverUnload;
- }
-
- //
// Add the driver to the list of drivers
//
Status = EfiLibInstallDriverBindingComponentName2 (
@@ -659,13 +646,12 @@ EntryPoint ( &gComponentName2
);
if ( !EFI_ERROR ( Status )) {
-
- AsciiPrint ("Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",
- ImageHandle );
- AsciiPrint("Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",
- ImageHandle );
- AsciiPrint("Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",
- ImageHandle );
+ DEBUG ((EFI_D_INFO, "Installed: gEfiDriverBindingProtocolGuid on 0x%08x\r\n",
+ ImageHandle));
+ DEBUG ((EFI_D_INFO, "Installed: gEfiComponentNameProtocolGuid on 0x%08x\r\n",
+ ImageHandle));
+ DEBUG ((EFI_D_INFO,"Installed: gEfiComponentName2ProtocolGuid on 0x%08x\r\n",
+ ImageHandle ));
}
return Status;
diff --git a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/SimpleNetwork.c b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/SimpleNetwork.c index be75161835..9eeb61f87b 100644 --- a/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/SimpleNetwork.c +++ b/OptionRomPkg/Bus/Usb/UsbNetworking/Ax88772b/SimpleNetwork.c @@ -1,7 +1,7 @@ /** @file
Provides the Simple Network functions.
- Copyright (c) 2011, Intel Corporation
+ Copyright (c) 2011 - 2013, 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
@@ -203,7 +203,12 @@ SN_GetStatus ( Status = EFI_SUCCESS;
}
else {
- Status = EFI_NOT_STARTED;
+ if ( EfiSimpleNetworkStarted == pMode->State ) {
+ Status = EFI_DEVICE_ERROR;
+ }
+ else {
+ Status = EFI_NOT_STARTED;
+ }
}
}
@@ -317,7 +322,7 @@ SN_MCastIPtoMAC ( IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
IN BOOLEAN bIPv6,
IN EFI_IP_ADDRESS * pIP,
- IN EFI_MAC_ADDRESS * pMAC
+ OUT EFI_MAC_ADDRESS * pMAC
)
{
EFI_STATUS Status;
@@ -349,13 +354,22 @@ SN_MCastIPtoMAC ( return EFI_INVALID_PARAMETER;
}
else {
- pMAC->Addr[0] = 0x01;
- pMAC->Addr[1] = 0x00;
- pMAC->Addr[2] = 0x5e;
- pMAC->Addr[3] = (UINT8) (pIP->v4.Addr[1] & 0x7f);
- pMAC->Addr[4] = (UINT8) pIP->v4.Addr[2];
- pMAC->Addr[5] = (UINT8) pIP->v4.Addr[3];
- Status = EFI_SUCCESS;
+ if (pSimpleNetwork->Mode->State == EfiSimpleNetworkInitialized)
+ {
+ pMAC->Addr[0] = 0x01;
+ pMAC->Addr[1] = 0x00;
+ pMAC->Addr[2] = 0x5e;
+ pMAC->Addr[3] = (UINT8) (pIP->v4.Addr[1] & 0x7f);
+ pMAC->Addr[4] = (UINT8) pIP->v4.Addr[2];
+ pMAC->Addr[5] = (UINT8) pIP->v4.Addr[3];
+ Status = EFI_SUCCESS;
+ }
+ else if (pSimpleNetwork->Mode->State == EfiSimpleNetworkStarted) {
+ Status = EFI_DEVICE_ERROR;
+ }
+ else {
+ Status = EFI_NOT_STARTED;
+ }
gBS->RestoreTPL(TplPrevious);
}
}
@@ -471,7 +485,10 @@ SN_Receive ( //
// Verify the parameters
//
- if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
+ if (( NULL != pSimpleNetwork ) &&
+ ( NULL != pSimpleNetwork->Mode ) &&
+ (NULL != pBufferSize) &&
+ (NULL != pBuffer)) {
//
// The interface must be running
//
@@ -576,7 +593,12 @@ SN_Receive ( }
else {
- Status = EFI_NOT_STARTED;
+ if (EfiSimpleNetworkStarted == pMode->State) {
+ Status = EFI_DEVICE_ERROR;
+ }
+ else {
+ Status = EFI_NOT_STARTED;
+ }
}
}
else {
@@ -852,7 +874,12 @@ SN_Reset ( }
}
else {
- Status = EFI_NOT_STARTED;
+ if (EfiSimpleNetworkStarted == pMode->State) {
+ Status = EFI_DEVICE_ERROR;
+ }
+ else {
+ Status = EFI_NOT_STARTED;
+ }
}
}
else {
@@ -1148,13 +1175,13 @@ SN_StationAddress ( //
if (( NULL != pSimpleNetwork )
&& ( NULL != pSimpleNetwork->Mode )
- && (( !bReset ) || ( bReset && ( NULL != pNew )))) {
+ && (( bReset ) || ( ( !bReset) && ( NULL != pNew )))) {
//
// Verify that the adapter is already started
//
pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
pMode = pSimpleNetwork->Mode;
- if ( EfiSimpleNetworkStarted == pMode->State ) {
+ if ( EfiSimpleNetworkInitialized == pMode->State ) {
//
// Determine the adapter MAC address
//
@@ -1181,7 +1208,12 @@ SN_StationAddress ( Status = Ax88772MacAddressSet ( pNicDevice, &pMode->CurrentAddress.Addr[0]);
}
else {
- Status = EFI_NOT_STARTED;
+ if (EfiSimpleNetworkStarted == pMode->State) {
+ Status = EFI_DEVICE_ERROR;
+ }
+ else {
+ Status = EFI_NOT_STARTED;
+ }
}
}
else {
@@ -1249,8 +1281,43 @@ SN_Statistics ( )
{
EFI_STATUS Status;
-
- Status = EFI_UNSUPPORTED;
+ EFI_SIMPLE_NETWORK_MODE * pMode;
+ //
+ // Verify the prarameters
+ //
+ if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
+ pMode = pSimpleNetwork->Mode;
+ //
+ // Determine if the interface is started
+ //
+ if (EfiSimpleNetworkInitialized == pMode->State){
+ //
+ // Determine if the StatisticsSize is big enough
+ //
+ if (sizeof (EFI_NETWORK_STATISTICS) <= *pStatisticsSize){
+ if (bReset) {
+ Status = EFI_SUCCESS;
+ }
+ else {
+ Status = EFI_UNSUPPORTED;
+ }
+ }
+ else {
+ Status = EFI_BUFFER_TOO_SMALL;
+ }
+ }
+ else{
+ if (EfiSimpleNetworkStarted == pMode->State) {
+ Status = EFI_DEVICE_ERROR;
+ }
+ else {
+ Status = EFI_NOT_STARTED;
+ }
+ }
+ }
+ else {
+ Status = EFI_INVALID_PARAMETER;
+ }
return Status;
}
@@ -1441,127 +1508,151 @@ SN_Transmit ( // Verify the parameters
//
- if (( NULL != pSimpleNetwork ) && ( NULL != pSimpleNetwork->Mode )) {
+ if (( NULL != pSimpleNetwork ) &&
+ ( NULL != pSimpleNetwork->Mode ) &&
+ ( NULL != pBuffer) &&
+ ( (HeaderSize == 0) || ( (NULL != pDestAddr) && (NULL != pProtocol) ))) {
//
// The interface must be running
//
pMode = pSimpleNetwork->Mode;
- if ( EfiSimpleNetworkInitialized == pMode->State ) {
+ //
+ // Verify parameter of HeaderSize
+ //
+ if ((HeaderSize == 0) || (HeaderSize == pMode->MediaHeaderSize)){
//
- // Update the link status
+ // Determine if BufferSize is big enough
//
- pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
- pMode->MediaPresent = pNicDevice->bLinkUp;
+ if (BufferSize >= pMode->MediaHeaderSize){
+ if ( EfiSimpleNetworkInitialized == pMode->State ) {
+ //
+ // Update the link status
+ //
+ pNicDevice = DEV_FROM_SIMPLE_NETWORK ( pSimpleNetwork );
+ pMode->MediaPresent = pNicDevice->bLinkUp;
- //
- // Release the synchronization with Ax88772Timer
- //
- if ( pMode->MediaPresent && pNicDevice->bComplete) {
- //
- // Copy the packet into the USB buffer
- //
+ //
+ // Release the synchronization with Ax88772Timer
+ //
+ if ( pMode->MediaPresent && pNicDevice->bComplete) {
+ //
+ // Copy the packet into the USB buffer
+ //
- CopyMem ( &pNicDevice->pTxTest->Data[0], pBuffer, BufferSize );
- pNicDevice->pTxTest->Length = (UINT16) BufferSize;
+ CopyMem ( &pNicDevice->pTxTest->Data[0], pBuffer, BufferSize );
+ pNicDevice->pTxTest->Length = (UINT16) BufferSize;
- //
- // Transmit the packet
- //
- pHeader = (ETHERNET_HEADER *) &pNicDevice->pTxTest->Data[0];
- if ( 0 != HeaderSize ) {
- if ( NULL != pDestAddr ) {
- CopyMem ( &pHeader->dest_addr, pDestAddr, PXE_HWADDR_LEN_ETHER );
- }
- if ( NULL != pSrcAddr ) {
- CopyMem ( &pHeader->src_addr, pSrcAddr, PXE_HWADDR_LEN_ETHER );
- }
- else {
- CopyMem ( &pHeader->src_addr, &pMode->CurrentAddress.Addr[0], PXE_HWADDR_LEN_ETHER );
- }
- if ( NULL != pProtocol ) {
- Type = *pProtocol;
+ //
+ // Transmit the packet
+ //
+ pHeader = (ETHERNET_HEADER *) &pNicDevice->pTxTest->Data[0];
+ if ( 0 != HeaderSize ) {
+ if ( NULL != pDestAddr ) {
+ CopyMem ( &pHeader->dest_addr, pDestAddr, PXE_HWADDR_LEN_ETHER );
+ }
+ if ( NULL != pSrcAddr ) {
+ CopyMem ( &pHeader->src_addr, pSrcAddr, PXE_HWADDR_LEN_ETHER );
+ }
+ else {
+ CopyMem ( &pHeader->src_addr, &pMode->CurrentAddress.Addr[0], PXE_HWADDR_LEN_ETHER );
+ }
+ if ( NULL != pProtocol ) {
+ Type = *pProtocol;
+ }
+ else {
+ Type = pNicDevice->pTxTest->Length;
+ }
+ Type = (UINT16)(( Type >> 8 ) | ( Type << 8 ));
+ pHeader->type = Type;
+ }
+ if ( pNicDevice->pTxTest->Length < MIN_ETHERNET_PKT_SIZE ) {
+ pNicDevice->pTxTest->Length = MIN_ETHERNET_PKT_SIZE;
+ ZeroMem ( &pNicDevice->pTxTest->Data[ BufferSize ],
+ pNicDevice->pTxTest->Length - BufferSize );
+ }
+
+ DEBUG ((EFI_D_INFO, "TX: %02x-%02x-%02x-%02x-%02x-%02x %02x-%02x-%02x-%02x-%02x-%02x"
+ " %02x-%02x %d bytes\r\n",
+ pNicDevice->pTxTest->Data[0],
+ pNicDevice->pTxTest->Data[1],
+ pNicDevice->pTxTest->Data[2],
+ pNicDevice->pTxTest->Data[3],
+ pNicDevice->pTxTest->Data[4],
+ pNicDevice->pTxTest->Data[5],
+ pNicDevice->pTxTest->Data[6],
+ pNicDevice->pTxTest->Data[7],
+ pNicDevice->pTxTest->Data[8],
+ pNicDevice->pTxTest->Data[9],
+ pNicDevice->pTxTest->Data[10],
+ pNicDevice->pTxTest->Data[11],
+ pNicDevice->pTxTest->Data[12],
+ pNicDevice->pTxTest->Data[13],
+ pNicDevice->pTxTest->Length ));
+
+ pNicDevice->pTxTest->LengthBar = ~(pNicDevice->pTxTest->Length);
+ TransferLength = sizeof ( pNicDevice->pTxTest->Length )
+ + sizeof ( pNicDevice->pTxTest->LengthBar )
+ + pNicDevice->pTxTest->Length;
+
+ if (TransferLength % 512 == 0 || TransferLength % 1024 == 0)
+ TransferLength +=4;
+
+ //
+ // Work around USB bus driver bug where a timeout set by receive
+ // succeeds but the timeout expires immediately after, causing the
+ // transmit operation to timeout.
+ //
+ pUsbIo = pNicDevice->pUsbIo;
+ Status = pUsbIo->UsbBulkTransfer ( pUsbIo,
+ BULK_OUT_ENDPOINT,
+ &pNicDevice->pTxTest->Length,
+ &TransferLength,
+ 0xfffffffe,
+ &TransferStatus );
+ if ( !EFI_ERROR ( Status )) {
+ Status = TransferStatus;
+ }
+
+ if ( !EFI_ERROR ( Status )) {
+ pNicDevice->pTxBuffer = pBuffer;
+ }
+ else {
+ if ((TransferLength != (UINTN)( pNicDevice->pTxTest->Length + 4 )) &&
+ (TransferLength != (UINTN)(( pNicDevice->pTxTest->Length + 4 ) + 4))) {
+ DEBUG ((EFI_D_INFO, "TransferLength didn't match Packet Length\n"));
+ }
+ //
+ // Reset the controller to fix the error
+ //
+ if ( EFI_DEVICE_ERROR == Status ) {
+ SN_Reset ( pSimpleNetwork, FALSE );
+ }
+ Status = EFI_NOT_READY;
+ }
}
else {
- Type = pNicDevice->pTxTest->Length;
+ //
+ // No packets available.
+ //
+ Status = EFI_NOT_READY;
}
- Type = (UINT16)(( Type >> 8 ) | ( Type << 8 ));
- pHeader->type = Type;
- }
- if ( pNicDevice->pTxTest->Length < MIN_ETHERNET_PKT_SIZE ) {
- pNicDevice->pTxTest->Length = MIN_ETHERNET_PKT_SIZE;
- ZeroMem ( &pNicDevice->pTxTest->Data[ BufferSize ],
- pNicDevice->pTxTest->Length - BufferSize );
- }
-
- DEBUG ((EFI_D_INFO, "TX: %02x-%02x-%02x-%02x-%02x-%02x %02x-%02x-%02x-%02x-%02x-%02x"
- " %02x-%02x %d bytes\r\n",
- pNicDevice->pTxTest->Data[0],
- pNicDevice->pTxTest->Data[1],
- pNicDevice->pTxTest->Data[2],
- pNicDevice->pTxTest->Data[3],
- pNicDevice->pTxTest->Data[4],
- pNicDevice->pTxTest->Data[5],
- pNicDevice->pTxTest->Data[6],
- pNicDevice->pTxTest->Data[7],
- pNicDevice->pTxTest->Data[8],
- pNicDevice->pTxTest->Data[9],
- pNicDevice->pTxTest->Data[10],
- pNicDevice->pTxTest->Data[11],
- pNicDevice->pTxTest->Data[12],
- pNicDevice->pTxTest->Data[13],
- pNicDevice->pTxTest->Length ));
-
- pNicDevice->pTxTest->LengthBar = ~(pNicDevice->pTxTest->Length);
- TransferLength = sizeof ( pNicDevice->pTxTest->Length )
- + sizeof ( pNicDevice->pTxTest->LengthBar )
- + pNicDevice->pTxTest->Length;
-
- if (TransferLength % 512 == 0 || TransferLength % 1024 == 0)
- TransferLength +=4;
-
- //
- // Work around USB bus driver bug where a timeout set by receive
- // succeeds but the timeout expires immediately after, causing the
- // transmit operation to timeout.
- //
- pUsbIo = pNicDevice->pUsbIo;
- Status = pUsbIo->UsbBulkTransfer ( pUsbIo,
- BULK_OUT_ENDPOINT,
- &pNicDevice->pTxTest->Length,
- &TransferLength,
- 0xfffffffe,
- &TransferStatus );
- if ( !EFI_ERROR ( Status )) {
- Status = TransferStatus;
- }
-
- if ( !EFI_ERROR ( Status )) {
- pNicDevice->pTxBuffer = pBuffer;
+
}
else {
- if ((TransferLength != (UINTN)( pNicDevice->pTxTest->Length + 4 )) &&
- (TransferLength != (UINTN)(( pNicDevice->pTxTest->Length + 4 ) + 4))) {
- DEBUG ((EFI_D_INFO, "TransferLength didn't match Packet Length\n"));
+ if (EfiSimpleNetworkStarted == pMode->State) {
+ Status = EFI_DEVICE_ERROR;
}
- //
- // Reset the controller to fix the error
- //
- if ( EFI_DEVICE_ERROR == Status ) {
- SN_Reset ( pSimpleNetwork, FALSE );
+ else {
+ Status = EFI_NOT_STARTED ;
}
- Status = EFI_NOT_READY;
}
}
else {
- //
- // No packets available.
- //
- Status = EFI_NOT_READY;
+ Status = EFI_BUFFER_TOO_SMALL;
}
-
}
else {
- Status = EFI_NOT_STARTED ;
+ Status = EFI_INVALID_PARAMETER;
}
}
else {
|