summaryrefslogtreecommitdiffstats
path: root/src/arch/i386/drivers/net/undinet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/i386/drivers/net/undinet.c')
-rw-r--r--src/arch/i386/drivers/net/undinet.c261
1 files changed, 47 insertions, 214 deletions
diff --git a/src/arch/i386/drivers/net/undinet.c b/src/arch/i386/drivers/net/undinet.c
index 0c7f6697..83b79e7f 100644
--- a/src/arch/i386/drivers/net/undinet.c
+++ b/src/arch/i386/drivers/net/undinet.c
@@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <gpxe/ethernet.h>
#include <undi.h>
#include <undinet.h>
+#include <pxeparent.h>
/** @file
@@ -62,178 +63,8 @@ struct undi_nic {
static void undinet_close ( struct net_device *netdev );
-/*****************************************************************************
- *
- * UNDI API call
- *
- *****************************************************************************
- */
-
-/**
- * Name UNDI API call
- *
- * @v function API call number
- * @ret name API call name
- */
-static inline __attribute__ (( always_inline )) const char *
-undinet_function_name ( unsigned int function ) {
- switch ( function ) {
- case PXENV_START_UNDI:
- return "PXENV_START_UNDI";
- case PXENV_STOP_UNDI:
- return "PXENV_STOP_UNDI";
- case PXENV_UNDI_STARTUP:
- return "PXENV_UNDI_STARTUP";
- case PXENV_UNDI_CLEANUP:
- return "PXENV_UNDI_CLEANUP";
- case PXENV_UNDI_INITIALIZE:
- return "PXENV_UNDI_INITIALIZE";
- case PXENV_UNDI_RESET_ADAPTER:
- return "PXENV_UNDI_RESET_ADAPTER";
- case PXENV_UNDI_SHUTDOWN:
- return "PXENV_UNDI_SHUTDOWN";
- case PXENV_UNDI_OPEN:
- return "PXENV_UNDI_OPEN";
- case PXENV_UNDI_CLOSE:
- return "PXENV_UNDI_CLOSE";
- case PXENV_UNDI_TRANSMIT:
- return "PXENV_UNDI_TRANSMIT";
- case PXENV_UNDI_SET_MCAST_ADDRESS:
- return "PXENV_UNDI_SET_MCAST_ADDRESS";
- case PXENV_UNDI_SET_STATION_ADDRESS:
- return "PXENV_UNDI_SET_STATION_ADDRESS";
- case PXENV_UNDI_SET_PACKET_FILTER:
- return "PXENV_UNDI_SET_PACKET_FILTER";
- case PXENV_UNDI_GET_INFORMATION:
- return "PXENV_UNDI_GET_INFORMATION";
- case PXENV_UNDI_GET_STATISTICS:
- return "PXENV_UNDI_GET_STATISTICS";
- case PXENV_UNDI_CLEAR_STATISTICS:
- return "PXENV_UNDI_CLEAR_STATISTICS";
- case PXENV_UNDI_INITIATE_DIAGS:
- return "PXENV_UNDI_INITIATE_DIAGS";
- case PXENV_UNDI_FORCE_INTERRUPT:
- return "PXENV_UNDI_FORCE_INTERRUPT";
- case PXENV_UNDI_GET_MCAST_ADDRESS:
- return "PXENV_UNDI_GET_MCAST_ADDRESS";
- case PXENV_UNDI_GET_NIC_TYPE:
- return "PXENV_UNDI_GET_NIC_TYPE";
- case PXENV_UNDI_GET_IFACE_INFO:
- return "PXENV_UNDI_GET_IFACE_INFO";
- /*
- * Duplicate case value; this is a bug in the PXE specification.
- *
- * case PXENV_UNDI_GET_STATE:
- * return "PXENV_UNDI_GET_STATE";
- */
- case PXENV_UNDI_ISR:
- return "PXENV_UNDI_ISR";
- default:
- return "UNKNOWN API CALL";
- }
-}
-
-/**
- * UNDI parameter block
- *
- * Used as the paramter block for all UNDI API calls. Resides in base
- * memory.
- */
-static union u_PXENV_ANY __bss16 ( undinet_params );
-#define undinet_params __use_data16 ( undinet_params )
-
-/** UNDI entry point
- *
- * Used as the indirection vector for all UNDI API calls. Resides in
- * base memory.
- */
-SEGOFF16_t __bss16 ( undinet_entry_point );
-#define undinet_entry_point __use_data16 ( undinet_entry_point )
-
-/**
- * Issue UNDI API call
- *
- * @v undinic UNDI NIC
- * @v function API call number
- * @v params UNDI parameter block
- * @v params_len Length of UNDI parameter block
- * @ret rc Return status code
- */
-static int undinet_call ( struct undi_nic *undinic, unsigned int function,
- void *params, size_t params_len ) {
- PXENV_EXIT_t exit;
- int discard_b, discard_D;
- int rc;
-
- /* Copy parameter block and entry point */
- assert ( params_len <= sizeof ( undinet_params ) );
- memcpy ( &undinet_params, params, params_len );
-
- /* Call real-mode entry point. This calling convention will
- * work with both the !PXE and the PXENV+ entry points.
- */
- __asm__ __volatile__ ( REAL_CODE ( "pushw %%es\n\t"
- "pushw %%di\n\t"
- "pushw %%bx\n\t"
- "lcall *undinet_entry_point\n\t"
- "addw $6, %%sp\n\t" )
- : "=a" ( exit ), "=b" ( discard_b ),
- "=D" ( discard_D )
- : "b" ( function ),
- "D" ( __from_data16 ( &undinet_params ) )
- : "ecx", "edx", "esi", "ebp" );
-
- /* UNDI API calls may rudely change the status of A20 and not
- * bother to restore it afterwards. Intel is known to be
- * guilty of this.
- *
- * Note that we will return to this point even if A20 gets
- * screwed up by the UNDI driver, because Etherboot always
- * resides in an even megabyte of RAM.
- */
- gateA20_set();
-
- /* Determine return status code based on PXENV_EXIT and
- * PXENV_STATUS
- */
- if ( exit == PXENV_EXIT_SUCCESS ) {
- rc = 0;
- } else {
- rc = -undinet_params.Status;
- /* Paranoia; don't return success for the combination
- * of PXENV_EXIT_FAILURE but PXENV_STATUS_SUCCESS
- */
- if ( rc == 0 )
- rc = -EIO;
- }
-
- /* If anything goes wrong, print as much debug information as
- * it's possible to give.
- */
- if ( rc != 0 ) {
- SEGOFF16_t rm_params = {
- .segment = rm_ds,
- .offset = __from_data16 ( &undinet_params ),
- };
-
- DBGC ( undinic, "UNDINIC %p %s failed: %s\n", undinic,
- undinet_function_name ( function ), strerror ( rc ) );
- DBGC ( undinic, "UNDINIC %p parameters at %04x:%04x length "
- "%#02zx, entry point at %04x:%04x\n", undinic,
- rm_params.segment, rm_params.offset, params_len,
- undinet_entry_point.segment,
- undinet_entry_point.offset );
- DBGC ( undinic, "UNDINIC %p parameters provided:\n", undinic );
- DBGC_HDA ( undinic, rm_params, params, params_len );
- DBGC ( undinic, "UNDINIC %p parameters returned:\n", undinic );
- DBGC_HDA ( undinic, rm_params, &undinet_params, params_len );
- }
-
- /* Copy parameter block back */
- memcpy ( params, &undinet_params, params_len );
-
- return rc;
-}
+/** Address of UNDI entry point */
+static SEGOFF16_t undinet_entry;
/*****************************************************************************
*
@@ -336,7 +167,6 @@ static struct s_PXENV_UNDI_TBD __data16 ( undinet_tbd );
*/
static int undinet_transmit ( struct net_device *netdev,
struct io_buffer *iobuf ) {
- struct undi_nic *undinic = netdev->priv;
struct s_PXENV_UNDI_TRANSMIT undi_transmit;
size_t len = iob_len ( iobuf );
int rc;
@@ -369,9 +199,9 @@ static int undinet_transmit ( struct net_device *netdev,
undinet_tbd.Xmit.offset = __from_data16 ( basemem_packet );
/* Issue PXE API call */
- if ( ( rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT,
- &undi_transmit,
- sizeof ( undi_transmit ) ) ) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_TRANSMIT,
+ &undi_transmit,
+ sizeof ( undi_transmit ) ) ) != 0 )
goto done;
/* Free I/O buffer */
@@ -441,8 +271,9 @@ static void undinet_poll ( struct net_device *netdev ) {
/* Run through the ISR loop */
while ( 1 ) {
- if ( ( rc = undinet_call ( undinic, PXENV_UNDI_ISR, &undi_isr,
- sizeof ( undi_isr ) ) ) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_ISR,
+ &undi_isr,
+ sizeof ( undi_isr ) ) ) != 0 )
break;
switch ( undi_isr.FuncFlag ) {
case PXENV_UNDI_ISR_OUT_TRANSMIT:
@@ -538,8 +369,8 @@ static int undinet_open ( struct net_device *netdev ) {
*/
memcpy ( undi_set_address.StationAddress, netdev->ll_addr,
sizeof ( undi_set_address.StationAddress ) );
- undinet_call ( undinic, PXENV_UNDI_SET_STATION_ADDRESS,
- &undi_set_address, sizeof ( undi_set_address ) );
+ pxeparent_call ( undinet_entry, PXENV_UNDI_SET_STATION_ADDRESS,
+ &undi_set_address, sizeof ( undi_set_address ) );
/* Open NIC. We ask for promiscuous operation, since it's the
* only way to ask for all multicast addresses. On any
@@ -548,8 +379,8 @@ static int undinet_open ( struct net_device *netdev ) {
*/
memset ( &undi_open, 0, sizeof ( undi_open ) );
undi_open.PktFilter = ( FLTR_DIRECTED | FLTR_BRDCST | FLTR_PRMSCS );
- if ( ( rc = undinet_call ( undinic, PXENV_UNDI_OPEN, &undi_open,
- sizeof ( undi_open ) ) ) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_OPEN,
+ &undi_open, sizeof ( undi_open ) ) ) != 0 )
goto err;
DBGC ( undinic, "UNDINIC %p opened\n", undinic );
@@ -574,8 +405,9 @@ static void undinet_close ( struct net_device *netdev ) {
/* Ensure ISR has exited cleanly */
while ( undinic->isr_processing ) {
undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT;
- if ( ( rc = undinet_call ( undinic, PXENV_UNDI_ISR, &undi_isr,
- sizeof ( undi_isr ) ) ) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_ISR,
+ &undi_isr,
+ sizeof ( undi_isr ) ) ) != 0 )
break;
switch ( undi_isr.FuncFlag ) {
case PXENV_UNDI_ISR_OUT_TRANSMIT:
@@ -590,8 +422,8 @@ static void undinet_close ( struct net_device *netdev ) {
}
/* Close NIC */
- undinet_call ( undinic, PXENV_UNDI_CLOSE, &undi_close,
- sizeof ( undi_close ) );
+ pxeparent_call ( undinet_entry, PXENV_UNDI_CLOSE,
+ &undi_close, sizeof ( undi_close ) );
/* Disable interrupt and unhook ISR */
disable_irq ( undinic->irq );
@@ -651,7 +483,7 @@ int undinet_probe ( struct undi_device *undi ) {
undi_set_drvdata ( undi, netdev );
netdev->dev = &undi->dev;
memset ( undinic, 0, sizeof ( *undinic ) );
- undinet_entry_point = undi->entry;
+ undinet_entry = undi->entry;
DBGC ( undinic, "UNDINIC %p using UNDI %p\n", undinic, undi );
/* Hook in UNDI stack */
@@ -662,9 +494,9 @@ int undinet_probe ( struct undi_device *undi ) {
start_undi.DX = undi->isapnp_read_port;
start_undi.ES = BIOS_SEG;
start_undi.DI = find_pnp_bios();
- if ( ( rc = undinet_call ( undinic, PXENV_START_UNDI,
- &start_undi,
- sizeof ( start_undi ) ) ) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry, PXENV_START_UNDI,
+ &start_undi,
+ sizeof ( start_undi ) ) ) != 0 )
goto err_start_undi;
}
undi->flags |= UNDI_FL_STARTED;
@@ -672,22 +504,23 @@ int undinet_probe ( struct undi_device *undi ) {
/* Bring up UNDI stack */
if ( ! ( undi->flags & UNDI_FL_INITIALIZED ) ) {
memset ( &undi_startup, 0, sizeof ( undi_startup ) );
- if ( ( rc = undinet_call ( undinic, PXENV_UNDI_STARTUP,
- &undi_startup,
- sizeof ( undi_startup ) ) ) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_STARTUP,
+ &undi_startup,
+ sizeof ( undi_startup ) ) ) != 0 )
goto err_undi_startup;
memset ( &undi_initialize, 0, sizeof ( undi_initialize ) );
- if ( ( rc = undinet_call ( undinic, PXENV_UNDI_INITIALIZE,
- &undi_initialize,
- sizeof ( undi_initialize ))) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry,
+ PXENV_UNDI_INITIALIZE,
+ &undi_initialize,
+ sizeof ( undi_initialize ))) != 0 )
goto err_undi_initialize;
}
undi->flags |= UNDI_FL_INITIALIZED;
/* Get device information */
memset ( &undi_info, 0, sizeof ( undi_info ) );
- if ( ( rc = undinet_call ( undinic, PXENV_UNDI_GET_INFORMATION,
- &undi_info, sizeof ( undi_info ) ) ) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_GET_INFORMATION,
+ &undi_info, sizeof ( undi_info ) ) ) != 0 )
goto err_undi_get_information;
memcpy ( netdev->hw_addr, undi_info.PermNodeAddress, ETH_ALEN );
undinic->irq = undi_info.IntNumber;
@@ -701,9 +534,9 @@ int undinet_probe ( struct undi_device *undi ) {
/* Get interface information */
memset ( &undi_iface, 0, sizeof ( undi_iface ) );
- if ( ( rc = undinet_call ( undinic, PXENV_UNDI_GET_IFACE_INFO,
- &undi_iface,
- sizeof ( undi_iface ) ) ) != 0 )
+ if ( ( rc = pxeparent_call ( undinet_entry, PXENV_UNDI_GET_IFACE_INFO,
+ &undi_iface,
+ sizeof ( undi_iface ) ) ) != 0 )
goto err_undi_get_iface_info;
DBGC ( undinic, "UNDINIC %p has type %s, speed %d, flags %08x\n",
undinic, undi_iface.IfaceType, undi_iface.LinkSpeed,
@@ -732,17 +565,17 @@ int undinet_probe ( struct undi_device *undi ) {
err_undi_initialize:
/* Shut down UNDI stack */
memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
- undinet_call ( undinic, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
- sizeof ( undi_shutdown ) );
+ pxeparent_call ( undinet_entry, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
+ sizeof ( undi_shutdown ) );
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
- undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
- sizeof ( undi_cleanup ) );
+ pxeparent_call ( undinet_entry, PXENV_UNDI_CLEANUP, &undi_cleanup,
+ sizeof ( undi_cleanup ) );
undi->flags &= ~UNDI_FL_INITIALIZED;
err_undi_startup:
/* Unhook UNDI stack */
memset ( &stop_undi, 0, sizeof ( stop_undi ) );
- undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
- sizeof ( stop_undi ) );
+ pxeparent_call ( undinet_entry, PXENV_STOP_UNDI, &stop_undi,
+ sizeof ( stop_undi ) );
undi->flags &= ~UNDI_FL_STARTED;
err_start_undi:
netdev_nullify ( netdev );
@@ -773,22 +606,22 @@ void undinet_remove ( struct undi_device *undi ) {
/* Shut down UNDI stack */
memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
- undinet_call ( undinic, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
- sizeof ( undi_shutdown ) );
+ pxeparent_call ( undinet_entry, PXENV_UNDI_SHUTDOWN,
+ &undi_shutdown, sizeof ( undi_shutdown ) );
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
- undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
- sizeof ( undi_cleanup ) );
+ pxeparent_call ( undinet_entry, PXENV_UNDI_CLEANUP,
+ &undi_cleanup, sizeof ( undi_cleanup ) );
undi->flags &= ~UNDI_FL_INITIALIZED;
/* Unhook UNDI stack */
memset ( &stop_undi, 0, sizeof ( stop_undi ) );
- undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
- sizeof ( stop_undi ) );
+ pxeparent_call ( undinet_entry, PXENV_STOP_UNDI, &stop_undi,
+ sizeof ( stop_undi ) );
undi->flags &= ~UNDI_FL_STARTED;
}
/* Clear entry point */
- memset ( &undinet_entry_point, 0, sizeof ( undinet_entry_point ) );
+ memset ( &undinet_entry, 0, sizeof ( undinet_entry ) );
/* Free network device */
netdev_nullify ( netdev );