[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>
This commit is contained in:
+18
-24
@@ -177,7 +177,7 @@ efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
|
||||
DBGC ( snpdev, "SNPDEV %p could not open %s: %s\n",
|
||||
snpdev, snpdev->netdev->name, strerror ( rc ) );
|
||||
return RC_TO_EFIRC ( rc );
|
||||
return EFIRC ( rc );
|
||||
}
|
||||
|
||||
snpdev->mode.State = EfiSimpleNetworkInitialized;
|
||||
@@ -206,7 +206,7 @@ efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
|
||||
if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
|
||||
DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n",
|
||||
snpdev, snpdev->netdev->name, strerror ( rc ) );
|
||||
return RC_TO_EFIRC ( rc );
|
||||
return EFIRC ( rc );
|
||||
}
|
||||
|
||||
snpdev->mode.State = EfiSimpleNetworkInitialized;
|
||||
@@ -366,7 +366,7 @@ efi_snp_mcast_ip_to_mac ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ipv6,
|
||||
ip, mac ) ) != 0 ) {
|
||||
DBGC ( snpdev, "SNPDEV %p could not hash %s: %s\n",
|
||||
snpdev, ip_str, strerror ( rc ) );
|
||||
return RC_TO_EFIRC ( rc );
|
||||
return EFIRC ( rc );
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -490,7 +490,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
struct io_buffer *iobuf;
|
||||
size_t payload_len;
|
||||
int rc;
|
||||
EFI_STATUS efirc;
|
||||
|
||||
DBGC2 ( snpdev, "SNPDEV %p TRANSMIT %p+%lx", snpdev, data,
|
||||
( ( unsigned long ) len ) );
|
||||
@@ -515,25 +514,25 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
DBGC ( snpdev, "SNPDEV %p TX invalid header length "
|
||||
"%ld\n", snpdev,
|
||||
( ( unsigned long ) ll_header_len ) );
|
||||
efirc = EFI_INVALID_PARAMETER;
|
||||
rc = -EINVAL;
|
||||
goto err_sanity;
|
||||
}
|
||||
if ( len < ll_header_len ) {
|
||||
DBGC ( snpdev, "SNPDEV %p invalid packet length %ld\n",
|
||||
snpdev, ( ( unsigned long ) len ) );
|
||||
efirc = EFI_BUFFER_TOO_SMALL;
|
||||
rc = -EINVAL;
|
||||
goto err_sanity;
|
||||
}
|
||||
if ( ! ll_dest ) {
|
||||
DBGC ( snpdev, "SNPDEV %p TX missing destination "
|
||||
"address\n", snpdev );
|
||||
efirc = EFI_INVALID_PARAMETER;
|
||||
rc = -EINVAL;
|
||||
goto err_sanity;
|
||||
}
|
||||
if ( ! net_proto ) {
|
||||
DBGC ( snpdev, "SNPDEV %p TX missing network "
|
||||
"protocol\n", snpdev );
|
||||
efirc = EFI_INVALID_PARAMETER;
|
||||
rc = -EINVAL;
|
||||
goto err_sanity;
|
||||
}
|
||||
if ( ! ll_src )
|
||||
@@ -547,7 +546,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
if ( ! iobuf ) {
|
||||
DBGC ( snpdev, "SNPDEV %p TX could not allocate %ld-byte "
|
||||
"buffer\n", snpdev, ( ( unsigned long ) len ) );
|
||||
efirc = EFI_DEVICE_ERROR;
|
||||
rc = -ENOMEM;
|
||||
goto err_alloc_iob;
|
||||
}
|
||||
iob_reserve ( iobuf, ( MAX_LL_HEADER_LEN -
|
||||
@@ -562,7 +561,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
htons ( *net_proto ) )) != 0 ){
|
||||
DBGC ( snpdev, "SNPDEV %p TX could not construct "
|
||||
"header: %s\n", snpdev, strerror ( rc ) );
|
||||
efirc = RC_TO_EFIRC ( rc );
|
||||
goto err_ll_push;
|
||||
}
|
||||
}
|
||||
@@ -571,7 +569,6 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
if ( ( rc = netdev_tx ( snpdev->netdev, iob_disown ( iobuf ) ) ) != 0){
|
||||
DBGC ( snpdev, "SNPDEV %p TX could not transmit: %s\n",
|
||||
snpdev, strerror ( rc ) );
|
||||
efirc = RC_TO_EFIRC ( rc );
|
||||
goto err_tx;
|
||||
}
|
||||
|
||||
@@ -586,7 +583,7 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
free_iob ( iobuf );
|
||||
err_alloc_iob:
|
||||
err_sanity:
|
||||
return efirc;
|
||||
return EFIRC ( rc );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -615,7 +612,6 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
uint16_t iob_net_proto;
|
||||
unsigned int iob_flags;
|
||||
int rc;
|
||||
EFI_STATUS efirc;
|
||||
|
||||
DBGC2 ( snpdev, "SNPDEV %p RECEIVE %p(+%lx)", snpdev, data,
|
||||
( ( unsigned long ) *len ) );
|
||||
@@ -627,7 +623,7 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
iobuf = netdev_rx_dequeue ( snpdev->netdev );
|
||||
if ( ! iobuf ) {
|
||||
DBGC2 ( snpdev, "\n" );
|
||||
efirc = EFI_NOT_READY;
|
||||
rc = -EAGAIN;
|
||||
goto out_no_packet;
|
||||
}
|
||||
DBGC2 ( snpdev, "+%zx\n", iob_len ( iobuf ) );
|
||||
@@ -642,7 +638,6 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
&iob_flags ) ) != 0 ) {
|
||||
DBGC ( snpdev, "SNPDEV %p could not parse header: %s\n",
|
||||
snpdev, strerror ( rc ) );
|
||||
efirc = RC_TO_EFIRC ( rc );
|
||||
goto out_bad_ll_header;
|
||||
}
|
||||
|
||||
@@ -656,12 +651,12 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
|
||||
if ( net_proto )
|
||||
*net_proto = ntohs ( iob_net_proto );
|
||||
|
||||
efirc = 0;
|
||||
rc = 0;
|
||||
|
||||
out_bad_ll_header:
|
||||
free_iob ( iobuf );
|
||||
out_no_packet:
|
||||
return efirc;
|
||||
return EFIRC ( rc );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -879,9 +874,9 @@ static int efi_snp_probe ( struct net_device *netdev ) {
|
||||
if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
|
||||
efi_snp_wait_for_packet, snpdev,
|
||||
&snpdev->snp.WaitForPacket ) ) != 0 ){
|
||||
rc = -EEFI ( efirc );
|
||||
DBGC ( snpdev, "SNPDEV %p could not create event: %s\n",
|
||||
snpdev, efi_strerror ( efirc ) );
|
||||
rc = EFIRC_TO_RC ( efirc );
|
||||
snpdev, strerror ( rc ) );
|
||||
goto err_create_event;
|
||||
}
|
||||
|
||||
@@ -944,18 +939,17 @@ static int efi_snp_probe ( struct net_device *netdev ) {
|
||||
&efi_component_name2_protocol_guid, &snpdev->name2,
|
||||
&efi_load_file_protocol_guid, &snpdev->load_file,
|
||||
NULL ) ) != 0 ) {
|
||||
rc = -EEFI ( efirc );
|
||||
DBGC ( snpdev, "SNPDEV %p could not install protocols: "
|
||||
"%s\n", snpdev, efi_strerror ( efirc ) );
|
||||
rc = EFIRC_TO_RC ( efirc );
|
||||
"%s\n", snpdev, strerror ( rc ) );
|
||||
goto err_install_protocol_interface;
|
||||
}
|
||||
|
||||
/* Add as child of PCI device */
|
||||
if ( ( efirc = efipci_child_add ( efipci, snpdev->handle ) ) != 0 ) {
|
||||
if ( ( rc = efipci_child_add ( efipci, snpdev->handle ) ) != 0 ) {
|
||||
DBGC ( snpdev, "SNPDEV %p could not become child of " PCI_FMT
|
||||
": %s\n", snpdev, PCI_ARGS ( &efipci->pci ),
|
||||
efi_strerror ( efirc ) );
|
||||
rc = EFIRC_TO_RC ( efirc );
|
||||
strerror ( rc ) );
|
||||
goto err_efipci_child_add;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user