diff options
author | Michael Brown | 2013-04-18 22:29:53 +0200 |
---|---|---|
committer | Michael Brown | 2013-04-19 14:34:19 +0200 |
commit | 54409583e29c481556e94a99dc73316d18aafc74 (patch) | |
tree | 150a8ceb85c1b523dc8dd8dd36daf8f6260e6538 /src/drivers/net/efi/snpnet.c | |
parent | [libc] Redefine low 8 bits of error code as "platform error code" (diff) | |
download | ipxe-54409583e29c481556e94a99dc73316d18aafc74.tar.gz ipxe-54409583e29c481556e94a99dc73316d18aafc74.tar.xz ipxe-54409583e29c481556e94a99dc73316d18aafc74.zip |
[efi] Perform meaningful error code conversions
Exploit the redefinition of iPXE error codes to include a "platform
error code" to allow for meaningful conversion of EFI_STATUS values to
iPXE errors and vice versa.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/drivers/net/efi/snpnet.c')
-rw-r--r-- | src/drivers/net/efi/snpnet.c | 83 |
1 files changed, 45 insertions, 38 deletions
diff --git a/src/drivers/net/efi/snpnet.c b/src/drivers/net/efi/snpnet.c index 97790815..cd9e7e38 100644 --- a/src/drivers/net/efi/snpnet.c +++ b/src/drivers/net/efi/snpnet.c @@ -56,20 +56,21 @@ static int snpnet_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) { struct snpnet_device *snpnetdev = netdev->priv; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp; - EFI_STATUS efirc; void *txbuf=NULL; size_t len = iob_len ( iobuf ); + EFI_STATUS efirc; + int rc; - efirc = snp->Transmit ( snp, 0, len, iobuf->data, NULL, NULL, NULL ); - if (efirc) { - return EFIRC_TO_RC ( efirc ); + if ( ( efirc = snp->Transmit ( snp, 0, len, iobuf->data, NULL, NULL, + NULL ) ) != 0 ) { + return -EEFI ( efirc ); } /* since GetStatus is so inconsistent, don't try more than one outstanding transmit at a time */ while ( txbuf == NULL ) { - efirc = snp->GetStatus ( snp, NULL, &txbuf ); - if ( efirc ) { + if ( ( efirc = snp->GetStatus ( snp, NULL, &txbuf ) ) != 0 ) { + rc = -EEFI ( efirc ); DBGC ( snp, "SNP %p could not get status %s\n", snp, - efi_strerror ( efirc ) ); + strerror ( rc ) ); break; } @@ -86,9 +87,10 @@ static int snpnet_transmit ( struct net_device *netdev, static void snpnet_poll ( struct net_device *netdev ) { struct snpnet_device *snpnetdev = netdev->priv; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp; - EFI_STATUS efirc; struct io_buffer *iobuf = NULL; UINTN len; + EFI_STATUS efirc; + int rc; /* Process received packets */ while ( 1 ) { @@ -115,12 +117,13 @@ static void snpnet_poll ( struct net_device *netdev ) { } /* Other error? */ - if ( efirc ) { + if ( efirc != 0 ) { + rc = -EEFI ( efirc ); DBGC ( snp, "SNP %p receive packet error: %s " "(len was %zd, is now %zd)\n", - snp, efi_strerror ( efirc ), iob_len(iobuf), + snp, strerror ( rc ), iob_len(iobuf), (size_t)len ); - netdev_rx_err ( netdev, iobuf, efirc ); + netdev_rx_err ( netdev, iobuf, rc ); break; } @@ -139,25 +142,27 @@ static void snpnet_poll ( struct net_device *netdev ) { static int snpnet_open ( struct net_device *netdev ) { struct snpnet_device *snpnetdev = netdev->priv; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp; - EFI_STATUS efirc; + EFI_MAC_ADDRESS *mac; UINT32 enableFlags, disableFlags; + EFI_STATUS efirc; + int rc; snpnetdev->close_state = snp->Mode->State; if ( snp->Mode->State != EfiSimpleNetworkInitialized ) { - efirc = snp->Initialize ( snp, 0, 0 ); - if ( efirc ) { + if ( ( efirc = snp->Initialize ( snp, 0, 0 ) ) != 0 ) { + rc = -EEFI ( efirc ); DBGC ( snp, "SNP %p could not initialize: %s\n", - snp, efi_strerror ( efirc ) ); - return EFIRC_TO_RC ( efirc ); + snp, strerror ( rc ) ); + return rc; } } /* Use the default MAC address */ - efirc = snp->StationAddress ( snp, FALSE, - (EFI_MAC_ADDRESS *)netdev->ll_addr ); - if ( efirc ) { + mac = ( ( void * ) netdev->ll_addr ); + if ( ( efirc = snp->StationAddress ( snp, FALSE, mac ) ) != 0 ) { + rc = -EEFI ( efirc ); DBGC ( snp, "SNP %p could not reset station address: %s\n", - snp, efi_strerror ( efirc ) ); + snp, strerror ( rc ) ); } /* Set up receive filters to receive unicast and broadcast packets @@ -179,11 +184,11 @@ static int snpnet_open ( struct net_device *netdev ) { enableFlags |= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS; } disableFlags &= ~enableFlags; - efirc = snp->ReceiveFilters ( snp, enableFlags, disableFlags, - FALSE, 0, NULL ); - if ( efirc ) { + if ( ( efirc = snp->ReceiveFilters ( snp, enableFlags, disableFlags, + FALSE, 0, NULL ) ) != 0 ) { + rc = -EEFI ( efirc ); DBGC ( snp, "SNP %p could not set receive filters: %s\n", - snp, efi_strerror ( efirc ) ); + snp, strerror ( rc ) ); } DBGC ( snp, "SNP %p opened\n", snp ); @@ -199,12 +204,13 @@ static void snpnet_close ( struct net_device *netdev ) { struct snpnet_device *snpnetdev = netdev->priv; EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpnetdev->snp; EFI_STATUS efirc; + int rc; if ( snpnetdev->close_state != EfiSimpleNetworkInitialized ) { - efirc = snp->Shutdown ( snp ); - if ( efirc ) { + if ( ( efirc = snp->Shutdown ( snp ) ) != 0 ) { + rc = -EEFI ( efirc ); DBGC ( snp, "SNP %p could not shut down: %s\n", - snp, efi_strerror ( efirc ) ); + snp, strerror ( rc ) ); } } } @@ -264,11 +270,10 @@ int snpnet_probe ( struct snp_device *snpdev ) { /* Start the interface */ if ( snp->Mode->State == EfiSimpleNetworkStopped ) { - efirc = snp->Start ( snp ); - if ( efirc ) { + if ( ( efirc = snp->Start ( snp ) ) != 0 ) { + rc = -EEFI ( efirc ); DBGC ( snp, "SNP %p could not start: %s\n", snp, - efi_strerror ( efirc ) ); - rc = EFIRC_TO_RC ( efirc ); + strerror ( rc ) ); goto err_start; } } @@ -310,25 +315,27 @@ err_start: */ void snpnet_remove ( struct snp_device *snpdev ) { EFI_SIMPLE_NETWORK_PROTOCOL *snp = snpdev->snp; - EFI_STATUS efirc; struct net_device *netdev = snpdev->netdev; + EFI_STATUS efirc; + int rc; if ( snp->Mode->State == EfiSimpleNetworkInitialized && snpdev->removal_state != EfiSimpleNetworkInitialized ) { DBGC ( snp, "SNP %p shutting down\n", snp ); - efirc = snp->Shutdown ( snp ); - if ( efirc ) { + if ( ( efirc = snp->Shutdown ( snp ) ) != 0 ) { + rc = -EEFI ( efirc ); DBGC ( snp, "SNP %p could not shut down: %s\n", - snp, efi_strerror ( efirc ) ); + snp, strerror ( rc ) ); } } if ( snp->Mode->State == EfiSimpleNetworkStarted && snpdev->removal_state == EfiSimpleNetworkStopped ) { DBGC ( snp, "SNP %p stopping\n", snp ); - efirc = snp->Stop ( snp ); - if ( efirc ) { - DBGC ( snp, "SNP %p could not be stopped\n", snp ); + if ( ( efirc = snp->Stop ( snp ) ) != 0 ) { + rc = -EEFI ( efirc ); + DBGC ( snp, "SNP %p could not be stopped: %s\n", + snp, strerror ( rc ) ); } } |