Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[efi] Raise TPL within EFI_SIMPLE_NETWORK_PROTOCOL entry points
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Feb 20, 2018
1 parent c89a446 commit a272b7c
Showing 1 changed file with 81 additions and 12 deletions.
93 changes: 81 additions & 12 deletions src/interface/efi/efi_snp.c
Expand Up @@ -233,26 +233,37 @@ efi_snp_stop ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
static EFI_STATUS EFIAPI
efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN extra_rx_bufsize, UINTN extra_tx_bufsize ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
EFI_TPL saved_tpl;
int rc;

DBGC ( snpdev, "SNPDEV %p INITIALIZE (%ld extra RX, %ld extra TX)\n",
snpdev, ( ( unsigned long ) extra_rx_bufsize ),
( ( unsigned long ) extra_tx_bufsize ) );

/* Fail if net device is currently claimed for use by iPXE */
if ( efi_snp_claimed )
return EFI_NOT_READY;
if ( efi_snp_claimed ) {
rc = -EAGAIN;
goto err_claimed;
}

/* Raise TPL */
saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );

/* Open network device */
if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not open %s: %s\n",
snpdev, snpdev->netdev->name, strerror ( rc ) );
return EFIRC ( rc );
goto err_open;
}
efi_snp_set_state ( snpdev );

return 0;
err_open:
bs->RestoreTPL ( saved_tpl );
err_claimed:
return EFIRC ( rc );
}

/**
Expand All @@ -264,29 +275,41 @@ efi_snp_initialize ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
*/
static EFI_STATUS EFIAPI
efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
EFI_TPL saved_tpl;
int rc;

DBGC ( snpdev, "SNPDEV %p RESET (%s extended verification)\n",
snpdev, ( ext_verify ? "with" : "without" ) );

/* Fail if net device is currently claimed for use by iPXE */
if ( efi_snp_claimed )
return EFI_NOT_READY;
if ( efi_snp_claimed ) {
rc = -EAGAIN;
goto err_claimed;
}

/* Raise TPL */
saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );

/* Close network device */
netdev_close ( snpdev->netdev );
efi_snp_set_state ( snpdev );
efi_snp_flush ( snpdev );

/* Reopen network device */
if ( ( rc = netdev_open ( snpdev->netdev ) ) != 0 ) {
DBGC ( snpdev, "SNPDEV %p could not reopen %s: %s\n",
snpdev, snpdev->netdev->name, strerror ( rc ) );
return EFIRC ( rc );
goto err_open;
}
efi_snp_set_state ( snpdev );

return 0;
err_open:
bs->RestoreTPL ( saved_tpl );
err_claimed:
return EFIRC ( rc );
}

/**
Expand All @@ -297,19 +320,28 @@ efi_snp_reset ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN ext_verify ) {
*/
static EFI_STATUS EFIAPI
efi_snp_shutdown ( EFI_SIMPLE_NETWORK_PROTOCOL *snp ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
EFI_TPL saved_tpl;

DBGC ( snpdev, "SNPDEV %p SHUTDOWN\n", snpdev );

/* Fail if net device is currently claimed for use by iPXE */
if ( efi_snp_claimed )
return EFI_NOT_READY;

/* Raise TPL */
saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );

/* Close network device */
netdev_close ( snpdev->netdev );
efi_snp_set_state ( snpdev );
efi_snp_flush ( snpdev );

/* Restore TPL */
bs->RestoreTPL ( saved_tpl );

return 0;
}

Expand Down Expand Up @@ -512,8 +544,10 @@ efi_snp_nvdata ( EFI_SIMPLE_NETWORK_PROTOCOL *snp, BOOLEAN read,
static EFI_STATUS EFIAPI
efi_snp_get_status ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINT32 *interrupts, VOID **txbuf ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
EFI_TPL saved_tpl;

DBGC2 ( snpdev, "SNPDEV %p GET_STATUS", snpdev );

Expand All @@ -523,6 +557,9 @@ efi_snp_get_status ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
return EFI_NOT_READY;
}

/* Raise TPL */
saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );

/* Poll the network device */
efi_snp_poll ( snpdev );

Expand All @@ -545,6 +582,9 @@ efi_snp_get_status ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
DBGC2 ( snpdev, " TX:%p", *txbuf );
}

/* Restore TPL */
bs->RestoreTPL ( saved_tpl );

DBGC2 ( snpdev, "\n" );
return 0;
}
Expand All @@ -566,12 +606,14 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN ll_header_len, UINTN len, VOID *data,
EFI_MAC_ADDRESS *ll_src, EFI_MAC_ADDRESS *ll_dest,
UINT16 *net_proto ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol;
struct io_buffer *iobuf;
size_t payload_len;
unsigned int tx_fill;
EFI_TPL saved_tpl;
int rc;

DBGC2 ( snpdev, "SNPDEV %p TRANSMIT %p+%lx", snpdev, data,
Expand All @@ -592,8 +634,13 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
DBGC2 ( snpdev, "\n" );

/* Fail if net device is currently claimed for use by iPXE */
if ( efi_snp_claimed )
return EFI_NOT_READY;
if ( efi_snp_claimed ) {
rc = -EAGAIN;
goto err_claimed;
}

/* Raise TPL */
saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );

/* Sanity checks */
if ( ll_header_len ) {
Expand Down Expand Up @@ -677,6 +724,9 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
snpdev->tx[ snpdev->tx_prod++ % EFI_SNP_NUM_TX ] = data;
snpdev->interrupts |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;

/* Restore TPL */
bs->RestoreTPL ( saved_tpl );

return 0;

err_ring_full:
Expand All @@ -685,6 +735,8 @@ efi_snp_transmit ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
free_iob ( iobuf );
err_alloc_iob:
err_sanity:
bs->RestoreTPL ( saved_tpl );
err_claimed:
return EFIRC ( rc );
}

Expand All @@ -705,6 +757,7 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
UINTN *ll_header_len, UINTN *len, VOID *data,
EFI_MAC_ADDRESS *ll_src, EFI_MAC_ADDRESS *ll_dest,
UINT16 *net_proto ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev =
container_of ( snp, struct efi_snp_device, snp );
struct ll_protocol *ll_protocol = snpdev->netdev->ll_protocol;
Expand All @@ -714,14 +767,20 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
uint16_t iob_net_proto;
unsigned int iob_flags;
size_t copy_len;
EFI_TPL saved_tpl;
int rc;

DBGC2 ( snpdev, "SNPDEV %p RECEIVE %p(+%lx)", snpdev, data,
( ( unsigned long ) *len ) );

/* Fail if net device is currently claimed for use by iPXE */
if ( efi_snp_claimed )
return EFI_NOT_READY;
if ( efi_snp_claimed ) {
rc = -EAGAIN;
goto err_claimed;
}

/* Raise TPL */
saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );

/* Poll the network device */
efi_snp_poll ( snpdev );
Expand Down Expand Up @@ -770,6 +829,8 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
out_bad_ll_header:
free_iob ( iobuf );
out_no_packet:
bs->RestoreTPL ( saved_tpl );
err_claimed:
return EFIRC ( rc );
}

Expand All @@ -781,7 +842,9 @@ efi_snp_receive ( EFI_SIMPLE_NETWORK_PROTOCOL *snp,
*/
static VOID EFIAPI efi_snp_wait_for_packet ( EFI_EVENT event __unused,
VOID *context ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev = context;
EFI_TPL saved_tpl;

DBGCP ( snpdev, "SNPDEV %p WAIT_FOR_PACKET\n", snpdev );

Expand All @@ -793,8 +856,14 @@ static VOID EFIAPI efi_snp_wait_for_packet ( EFI_EVENT event __unused,
if ( efi_snp_claimed )
return;

/* Raise TPL */
saved_tpl = bs->RaiseTPL ( TPL_CALLBACK );

/* Poll the network device */
efi_snp_poll ( snpdev );

/* Restore TPL */
bs->RestoreTPL ( saved_tpl );
}

/** SNP interface */
Expand Down

0 comments on commit a272b7c

Please sign in to comment.