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
This commit is contained in:
Yu Pei
2013-06-27 05:07:29 +00:00
committed by qianouyang
parent ca24313165
commit 4986bbaf11
8 changed files with 341 additions and 207 deletions

View File

@@ -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

View File

@@ -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,21 +632,8 @@ 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
//
@@ -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;

View File

@@ -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 );
//
// 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 {
CopyMem ( &pHeader->src_addr, &pMode->CurrentAddress.Addr[0], PXE_HWADDR_LEN_ETHER );
//
// No packets available.
//
Status = EFI_NOT_READY;
}
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"));
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 {