Use "struct undi_device" instead of "struct pxe_device", and use the

function prefix "undinet_" and the variable name "undinic" in undinet.c,
so that we can reserve the variable name "undi" for a struct undi_device.

The idea is that we preserve the Etherboot 5.4 convention that the "UNDI"
code refers to our using an underlying UNDI stack, while the "PXE" code
refers to our providing a PXE API.
This commit is contained in:
Michael Brown
2007-01-08 02:24:53 +00:00
parent 36c1e1aa57
commit 675fe200e5
3 changed files with 208 additions and 151 deletions

View File

@@ -26,6 +26,9 @@
#include <gpxe/netdevice.h> #include <gpxe/netdevice.h>
#include <gpxe/if_ether.h> #include <gpxe/if_ether.h>
#include <gpxe/ethernet.h> #include <gpxe/ethernet.h>
#include <undi.h>
#include <undinet.h>
/** @file /** @file
* *
@@ -41,7 +44,7 @@ struct undi_nic {
unsigned int irq; unsigned int irq;
}; };
static void undi_close ( struct net_device *netdev ); static void undinet_close ( struct net_device *netdev );
/***************************************************************************** /*****************************************************************************
* *
@@ -57,40 +60,12 @@ static void undi_close ( struct net_device *netdev );
* @ret name API call name * @ret name API call name
*/ */
static inline __attribute__ (( always_inline )) const char * static inline __attribute__ (( always_inline )) const char *
undi_function_name ( unsigned int function ) { undinet_function_name ( unsigned int function ) {
switch ( function ) { switch ( function ) {
case PXENV_UNLOAD_STACK:
return "PXENV_UNLOAD_STACK";
case PXENV_GET_CACHED_INFO:
return "PXENV_GET_CACHED_INFO";
case PXENV_RESTART_TFTP:
return "PXENV_RESTART_TFTP";
case PXENV_START_UNDI: case PXENV_START_UNDI:
return "PXENV_START_UNDI"; return "PXENV_START_UNDI";
case PXENV_STOP_UNDI: case PXENV_STOP_UNDI:
return "PXENV_STOP_UNDI"; return "PXENV_STOP_UNDI";
case PXENV_START_BASE:
return "PXENV_START_BASE";
case PXENV_STOP_BASE:
return "PXENV_STOP_BASE";
case PXENV_TFTP_OPEN:
return "PXENV_TFTP_OPEN";
case PXENV_TFTP_CLOSE:
return "PXENV_TFTP_CLOSE";
case PXENV_TFTP_READ:
return "PXENV_TFTP_READ";
case PXENV_TFTP_READ_FILE:
return "PXENV_TFTP_READ_FILE";
case PXENV_TFTP_GET_FSIZE:
return "PXENV_TFTP_GET_FSIZE";
case PXENV_UDP_OPEN:
return "PXENV_UDP_OPEN";
case PXENV_UDP_CLOSE:
return "PXENV_UDP_CLOSE";
case PXENV_UDP_WRITE:
return "PXENV_UDP_WRITE";
case PXENV_UDP_READ:
return "PXENV_UDP_READ";
case PXENV_UNDI_STARTUP: case PXENV_UNDI_STARTUP:
return "PXENV_UNDI_STARTUP"; return "PXENV_UNDI_STARTUP";
case PXENV_UNDI_CLEANUP: case PXENV_UNDI_CLEANUP:
@@ -148,37 +123,37 @@ undi_function_name ( unsigned int function ) {
* Used as the paramter block for all UNDI API calls. Resides in base * Used as the paramter block for all UNDI API calls. Resides in base
* memory. * memory.
*/ */
static union u_PXENV_ANY __data16 ( undi_params ); static union u_PXENV_ANY __data16 ( undinet_params );
#define undi_params __use_data16 ( undi_params ) #define undinet_params __use_data16 ( undinet_params )
/** UNDI entry point /** UNDI entry point
* *
* Used as the indirection vector for all UNDI API calls. Resides in * Used as the indirection vector for all UNDI API calls. Resides in
* base memory. * base memory.
*/ */
static SEGOFF16_t __data16 ( undi_entry_point ); static SEGOFF16_t __data16 ( undinet_entry_point );
#define undi_entry_point __use_data16 ( undi_entry_point ) #define undinet_entry_point __use_data16 ( undinet_entry_point )
/** /**
* Issue UNDI API call * Issue UNDI API call
* *
* @v undi UNDI NIC * @v undinic UNDI NIC
* @v function API call number * @v function API call number
* @v params UNDI parameter block * @v params UNDI parameter block
* @v params_len Length of UNDI parameter block * @v params_len Length of UNDI parameter block
* @ret rc Return status code * @ret rc Return status code
*/ */
static int undi_call ( struct undi_nic *undi, unsigned int function, static int undinet_call ( struct undi_nic *undinic, unsigned int function,
void *params, size_t params_len ) { void *params, size_t params_len ) {
union u_PXENV_ANY *pxenv_any = params; union u_PXENV_ANY *pxenv_any = params;
PXENV_EXIT_t exit; PXENV_EXIT_t exit;
int discard_b, discard_D; int discard_b, discard_D;
int rc; int rc;
/* Copy parameter block and entry point */ /* Copy parameter block and entry point */
assert ( params_len <= sizeof ( undi_params ) ); assert ( params_len <= sizeof ( undinet_params ) );
memcpy ( &undi_params, params, params_len ); memcpy ( &undinet_params, params, params_len );
undi_entry_point = undi->entry; undinet_entry_point = undinic->entry;
/* Call real-mode entry point. This calling convention will /* Call real-mode entry point. This calling convention will
* work with both the !PXE and the PXENV+ entry points. * work with both the !PXE and the PXENV+ entry points.
@@ -190,9 +165,9 @@ static int undi_call ( struct undi_nic *undi, unsigned int function,
"addw $6, %%sp\n\t" ) "addw $6, %%sp\n\t" )
: "=a" ( exit ), "=b" ( discard_b ), : "=a" ( exit ), "=b" ( discard_b ),
"=D" ( discard_D ) "=D" ( discard_D )
: "p" ( & __from_data16 ( undi_entry_point ) ), : "p" ( &__from_data16 ( undinet_entry_point )),
"b" ( function ), "b" ( function ),
"D" ( & __from_data16 ( undi_params ) ) "D" ( &__from_data16 ( undinet_params ) )
: "ecx", "edx", "esi", "ebp" ); : "ecx", "edx", "esi", "ebp" );
/* UNDI API calls may rudely change the status of A20 and not /* UNDI API calls may rudely change the status of A20 and not
@@ -206,7 +181,7 @@ static int undi_call ( struct undi_nic *undi, unsigned int function,
gateA20_set(); gateA20_set();
/* Copy parameter block back */ /* Copy parameter block back */
memcpy ( params, &undi_params, params_len ); memcpy ( params, &undinet_params, params_len );
/* Determine return status code based on PXENV_EXIT and /* Determine return status code based on PXENV_EXIT and
* PXENV_STATUS * PXENV_STATUS
@@ -223,8 +198,8 @@ static int undi_call ( struct undi_nic *undi, unsigned int function,
} }
if ( rc != 0 ) { if ( rc != 0 ) {
DBGC ( undi, "UNDI %p %s failed: %s\n", undi, DBGC ( undinic, "UNDINIC %p %s failed: %s\n", undinic,
undi_function_name ( function ), strerror ( rc ) ); undinet_function_name ( function ), strerror ( rc ) );
} }
return rc; return rc;
} }
@@ -242,7 +217,7 @@ static int undi_call ( struct undi_nic *undi, unsigned int function,
* The UNDI ISR simply increments a counter (@c trigger_count) and * The UNDI ISR simply increments a counter (@c trigger_count) and
* exits. * exits.
*/ */
extern void undi_isr ( void ); extern void undinet_isr ( void );
/** Dummy chain vector */ /** Dummy chain vector */
static struct segoff prev_handler[ IRQ_MAX + 1 ]; static struct segoff prev_handler[ IRQ_MAX + 1 ];
@@ -263,16 +238,17 @@ static volatile uint8_t __text16 ( trigger_count ) = 0;
* interrupting device) and some disable the interrupt at the PIC (and * interrupting device) and some disable the interrupt at the PIC (and
* so will bring our own interrupts to a shuddering halt). * so will bring our own interrupts to a shuddering halt).
*/ */
static void undi_hook_isr ( unsigned int irq ) { static void undinet_hook_isr ( unsigned int irq ) {
assert ( irq <= IRQ_MAX ); assert ( irq <= IRQ_MAX );
__asm__ __volatile__ ( TEXT16_CODE ( "\nundi_isr:\n\t" __asm__ __volatile__ ( TEXT16_CODE ( "\nundinet_isr:\n\t"
"incb %%cs:%c0\n\t" "incb %%cs:%c0\n\t"
"iret\n\t" ) "iret\n\t" )
: : "p" ( & __from_text16 ( trigger_count ) ) ); : : "p" ( & __from_text16 ( trigger_count ) ) );
hook_bios_interrupt ( IRQ_INT ( irq ), ( ( unsigned int ) undi_isr ), hook_bios_interrupt ( IRQ_INT ( irq ),
( ( unsigned int ) undinet_isr ),
&prev_handler[irq] ); &prev_handler[irq] );
} }
@@ -282,11 +258,12 @@ static void undi_hook_isr ( unsigned int irq ) {
* *
* @v irq IRQ number * @v irq IRQ number
*/ */
static void undi_unhook_isr ( unsigned int irq ) { static void undinet_unhook_isr ( unsigned int irq ) {
assert ( irq <= IRQ_MAX ); assert ( irq <= IRQ_MAX );
unhook_bios_interrupt ( IRQ_INT ( irq ), ( ( unsigned int ) undi_isr ), unhook_bios_interrupt ( IRQ_INT ( irq ),
( ( unsigned int ) undinet_isr ),
&prev_handler[irq] ); &prev_handler[irq] );
} }
@@ -295,7 +272,7 @@ static void undi_unhook_isr ( unsigned int irq ) {
* *
* @ret triggered ISR has been triggered since last check * @ret triggered ISR has been triggered since last check
*/ */
static int undi_isr_triggered ( void ) { static int undinet_isr_triggered ( void ) {
static unsigned int last_trigger_count = 0; static unsigned int last_trigger_count = 0;
unsigned int this_trigger_count; unsigned int this_trigger_count;
@@ -328,12 +305,12 @@ struct undi_packet {
}; };
/** UNDI packet buffer */ /** UNDI packet buffer */
static struct undi_packet __data16 ( undi_pkb ); static struct undi_packet __data16 ( undinet_pkb );
#define undi_pkb __use_data16 ( undi_pkb ) #define undinet_pkb __use_data16 ( undinet_pkb )
/** UNDI transmit buffer descriptor */ /** UNDI transmit buffer descriptor */
static struct s_PXENV_UNDI_TBD __data16 ( undi_tbd ); static struct s_PXENV_UNDI_TBD __data16 ( undinet_tbd );
#define undi_tbd __use_data16 ( undi_tbd ) #define undinet_tbd __use_data16 ( undinet_tbd )
/** /**
* Transmit packet * Transmit packet
@@ -342,35 +319,36 @@ static struct s_PXENV_UNDI_TBD __data16 ( undi_tbd );
* @v pkb Packet buffer * @v pkb Packet buffer
* @ret rc Return status code * @ret rc Return status code
*/ */
static int undi_transmit ( struct net_device *netdev, struct pk_buff *pkb ) { static int undinet_transmit ( struct net_device *netdev,
struct undi_nic *undi = netdev->priv; struct pk_buff *pkb ) {
struct undi_nic *undinic = netdev->priv;
struct s_PXENV_UNDI_TRANSMIT undi_transmit; struct s_PXENV_UNDI_TRANSMIT undi_transmit;
size_t len = pkb_len ( pkb ); size_t len = pkb_len ( pkb );
int rc; int rc;
/* Copy packet to UNDI packet buffer */ /* Copy packet to UNDI packet buffer */
if ( len > sizeof ( undi_pkb ) ) if ( len > sizeof ( undinet_pkb ) )
len = sizeof ( undi_pkb ); len = sizeof ( undinet_pkb );
memcpy ( &undi_pkb, pkb->data, len ); memcpy ( &undinet_pkb, pkb->data, len );
/* Create PXENV_UNDI_TRANSMIT data structure */ /* Create PXENV_UNDI_TRANSMIT data structure */
memset ( &undi_transmit, 0, sizeof ( undi_transmit ) ); memset ( &undi_transmit, 0, sizeof ( undi_transmit ) );
undi_transmit.DestAddr.segment = rm_ds; undi_transmit.DestAddr.segment = rm_ds;
undi_transmit.DestAddr.offset undi_transmit.DestAddr.offset
= ( ( unsigned ) & __from_data16 ( undi_tbd ) ); = ( ( unsigned ) & __from_data16 ( undinet_tbd ) );
undi_transmit.TBD.segment = rm_ds; undi_transmit.TBD.segment = rm_ds;
undi_transmit.TBD.offset undi_transmit.TBD.offset
= ( ( unsigned ) & __from_data16 ( undi_tbd ) ); = ( ( unsigned ) & __from_data16 ( undinet_tbd ) );
/* Create PXENV_UNDI_TBD data structure */ /* Create PXENV_UNDI_TBD data structure */
undi_tbd.ImmedLength = len; undinet_tbd.ImmedLength = len;
undi_tbd.Xmit.segment = rm_ds; undinet_tbd.Xmit.segment = rm_ds;
undi_tbd.Xmit.offset undinet_tbd.Xmit.offset
= ( ( unsigned ) & __from_data16 ( undi_pkb ) ); = ( ( unsigned ) & __from_data16 ( undinet_pkb ) );
/* Issue PXE API call */ /* Issue PXE API call */
rc = undi_call ( undi, PXENV_UNDI_TRANSMIT, &undi_transmit, rc = undinet_call ( undinic, PXENV_UNDI_TRANSMIT, &undi_transmit,
sizeof ( undi_transmit ) ); sizeof ( undi_transmit ) );
/* Free packet buffer and return */ /* Free packet buffer and return */
free_pkb ( pkb ); free_pkb ( pkb );
@@ -384,22 +362,22 @@ static int undi_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
* *
* Fun, fun, fun. UNDI drivers don't use polling; they use * Fun, fun, fun. UNDI drivers don't use polling; they use
* interrupts. We therefore cheat and pretend that an interrupt has * interrupts. We therefore cheat and pretend that an interrupt has
* occurred every time undi_poll() is called. This isn't too much of * occurred every time undinet_poll() is called. This isn't too much
* a hack; PCI devices share IRQs and so the first thing that a proper * of a hack; PCI devices share IRQs and so the first thing that a
* ISR should do is call PXENV_UNDI_ISR to determine whether or not * proper ISR should do is call PXENV_UNDI_ISR to determine whether or
* the UNDI NIC generated the interrupt; there is no harm done by * not the UNDI NIC generated the interrupt; there is no harm done by
* spurious calls to PXENV_UNDI_ISR. Similarly, we wouldn't be * spurious calls to PXENV_UNDI_ISR. Similarly, we wouldn't be
* handling them any more rapidly than the usual rate of undi_poll() * handling them any more rapidly than the usual rate of
* being called even if we did implement a full ISR. So it should * undinet_poll() being called even if we did implement a full ISR.
* work. Ha! * So it should work. Ha!
* *
* Addendum (21/10/03). Some cards don't play nicely with this trick, * Addendum (21/10/03). Some cards don't play nicely with this trick,
* so instead of doing it the easy way we have to go to all the hassle * so instead of doing it the easy way we have to go to all the hassle
* of installing a genuine interrupt service routine and dealing with * of installing a genuine interrupt service routine and dealing with
* the wonderful 8259 Programmable Interrupt Controller. Joy. * the wonderful 8259 Programmable Interrupt Controller. Joy.
*/ */
static void undi_poll ( struct net_device *netdev ) { static void undinet_poll ( struct net_device *netdev ) {
struct undi_nic *undi = netdev->priv; struct undi_nic *undinic = netdev->priv;
struct s_PXENV_UNDI_ISR undi_isr; struct s_PXENV_UNDI_ISR undi_isr;
struct pk_buff *pkb = NULL; struct pk_buff *pkb = NULL;
size_t len; size_t len;
@@ -407,26 +385,26 @@ static void undi_poll ( struct net_device *netdev ) {
int rc; int rc;
/* Do nothing unless ISR has been triggered */ /* Do nothing unless ISR has been triggered */
if ( ! undi_isr_triggered() ) if ( ! undinet_isr_triggered() )
return; return;
/* See if this was our interrupt */ /* See if this was our interrupt */
memset ( &undi_isr, 0, sizeof ( undi_isr ) ); memset ( &undi_isr, 0, sizeof ( undi_isr ) );
undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_START; undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_START;
if ( ( rc = undi_call ( undi, PXENV_UNDI_ISR, &undi_isr, if ( ( rc = undinet_call ( undinic, PXENV_UNDI_ISR, &undi_isr,
sizeof ( undi_isr ) ) ) != 0 ) sizeof ( undi_isr ) ) ) != 0 )
return; return;
if ( undi_isr.FuncFlag != PXENV_UNDI_ISR_OUT_OURS ) if ( undi_isr.FuncFlag != PXENV_UNDI_ISR_OUT_OURS )
return; return;
/* Send EOI */ /* Send EOI */
send_eoi ( undi->irq ); send_eoi ( undinic->irq );
/* Run through the ISR loop */ /* Run through the ISR loop */
undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_PROCESS; undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_PROCESS;
while ( 1 ) { while ( 1 ) {
if ( ( rc = undi_call ( undi, PXENV_UNDI_ISR, &undi_isr, if ( ( rc = undinet_call ( undinic, PXENV_UNDI_ISR, &undi_isr,
sizeof ( undi_isr ) ) ) != 0 ) sizeof ( undi_isr ) ) ) != 0 )
break; break;
switch ( undi_isr.FuncFlag ) { switch ( undi_isr.FuncFlag ) {
case PXENV_UNDI_ISR_OUT_TRANSMIT: case PXENV_UNDI_ISR_OUT_TRANSMIT:
@@ -439,14 +417,14 @@ static void undi_poll ( struct net_device *netdev ) {
if ( ! pkb ) if ( ! pkb )
pkb = alloc_pkb ( len ); pkb = alloc_pkb ( len );
if ( ! pkb ) { if ( ! pkb ) {
DBGC ( undi, "UNDI %p could not allocate %zd " DBGC ( undinic, "UNDINIC %p could not "
"bytes for receive buffer\n", "allocate %zd bytes for RX buffer\n",
undi, len ); undinic, len );
break; break;
} }
if ( frag_len > pkb_available ( pkb ) ) { if ( frag_len > pkb_available ( pkb ) ) {
DBGC ( undi, "UNDI %p fragment too large\n", DBGC ( undinic, "UNDINIC %p fragment too "
undi ); "large\n", undinic );
frag_len = pkb_available ( pkb ); frag_len = pkb_available ( pkb );
} }
copy_from_real ( pkb_put ( pkb, frag_len ), copy_from_real ( pkb_put ( pkb, frag_len ),
@@ -462,8 +440,8 @@ static void undi_poll ( struct net_device *netdev ) {
goto done; goto done;
default: default:
/* Should never happen */ /* Should never happen */
DBGC ( undi, "UNDI %p ISR returned invalid FuncFlag " DBGC ( undinic, "UNDINIC %p ISR returned invalid "
"%04x\n", undi, undi_isr.FuncFlag ); "FuncFlag %04x\n", undinic, undi_isr.FuncFlag );
goto done; goto done;
} }
undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT; undi_isr.FuncFlag = PXENV_UNDI_ISR_IN_GET_NEXT;
@@ -471,7 +449,8 @@ static void undi_poll ( struct net_device *netdev ) {
done: done:
if ( pkb ) { if ( pkb ) {
DBGC ( undi, "UNDI %p returned incomplete packet\n", undi ); DBGC ( undinic, "UNDINIC %p returned incomplete packet\n",
undinic );
netdev_rx ( netdev, pkb ); netdev_rx ( netdev, pkb );
} }
} }
@@ -482,15 +461,15 @@ static void undi_poll ( struct net_device *netdev ) {
* @v netdev Net device * @v netdev Net device
* @ret rc Return status code * @ret rc Return status code
*/ */
static int undi_open ( struct net_device *netdev ) { static int undinet_open ( struct net_device *netdev ) {
struct undi_nic *undi = netdev->priv; struct undi_nic *undinic = netdev->priv;
struct s_PXENV_UNDI_SET_STATION_ADDRESS set_address; struct s_PXENV_UNDI_SET_STATION_ADDRESS set_address;
struct s_PXENV_UNDI_OPEN open; struct s_PXENV_UNDI_OPEN open;
int rc; int rc;
/* Hook interrupt service routine and enable interrupt */ /* Hook interrupt service routine and enable interrupt */
undi_hook_isr ( undi->irq ); undinet_hook_isr ( undinic->irq );
enable_irq ( undi->irq ); enable_irq ( undinic->irq );
/* Set station address. Required for some PXE stacks; will /* Set station address. Required for some PXE stacks; will
* spuriously fail on others. Ignore failures. We only ever * spuriously fail on others. Ignore failures. We only ever
@@ -499,20 +478,20 @@ static int undi_open ( struct net_device *netdev ) {
*/ */
memcpy ( set_address.StationAddress, netdev->ll_addr, memcpy ( set_address.StationAddress, netdev->ll_addr,
sizeof ( set_address.StationAddress ) ); sizeof ( set_address.StationAddress ) );
undi_call ( undi, PXENV_UNDI_SET_STATION_ADDRESS, undinet_call ( undinic, PXENV_UNDI_SET_STATION_ADDRESS,
&set_address, sizeof ( set_address ) ); &set_address, sizeof ( set_address ) );
/* Open NIC */ /* Open NIC */
memset ( &open, 0, sizeof ( open ) ); memset ( &open, 0, sizeof ( open ) );
open.PktFilter = ( FLTR_DIRECTED | FLTR_BRDCST ); open.PktFilter = ( FLTR_DIRECTED | FLTR_BRDCST );
if ( ( rc = undi_call ( undi, PXENV_UNDI_OPEN, &open, if ( ( rc = undinet_call ( undinic, PXENV_UNDI_OPEN, &open,
sizeof ( open ) ) ) != 0 ) sizeof ( open ) ) ) != 0 )
goto err; goto err;
return 0; return 0;
err: err:
undi_close ( netdev ); undinet_close ( netdev );
return rc; return rc;
} }
@@ -521,27 +500,27 @@ static int undi_open ( struct net_device *netdev ) {
* *
* @v netdev Net device * @v netdev Net device
*/ */
static void undi_close ( struct net_device *netdev ) { static void undinet_close ( struct net_device *netdev ) {
struct undi_nic *undi = netdev->priv; struct undi_nic *undinic = netdev->priv;
struct s_PXENV_UNDI_CLOSE close; struct s_PXENV_UNDI_CLOSE close;
/* Close NIC */ /* Close NIC */
undi_call ( undi, PXENV_UNDI_CLOSE, &close, sizeof ( close ) ); undinet_call ( undinic, PXENV_UNDI_CLOSE, &close, sizeof ( close ) );
/* Disable interrupt and unhook ISR */ /* Disable interrupt and unhook ISR */
disable_irq ( undi->irq ); disable_irq ( undinic->irq );
undi_unhook_isr ( undi->irq ); undinet_unhook_isr ( undinic->irq );
} }
/** /**
* Probe PXE device * Probe UNDI device
* *
* @v pxe PXE device * @v undi UNDI device
* @ret rc Return status code * @ret rc Return status code
*/ */
int undi_probe ( struct pxe_device *pxe ) { int undinet_probe ( struct undi_device *undi ) {
struct net_device *netdev; struct net_device *netdev;
struct undi_nic *undi; struct undi_nic *undinic;
struct s_PXENV_START_UNDI start_undi; struct s_PXENV_START_UNDI start_undi;
struct s_PXENV_UNDI_STARTUP undi_startup; struct s_PXENV_UNDI_STARTUP undi_startup;
struct s_PXENV_UNDI_INITIALIZE undi_initialize; struct s_PXENV_UNDI_INITIALIZE undi_initialize;
@@ -552,54 +531,56 @@ int undi_probe ( struct pxe_device *pxe ) {
int rc; int rc;
/* Allocate net device */ /* Allocate net device */
netdev = alloc_etherdev ( sizeof ( *undi ) ); netdev = alloc_etherdev ( sizeof ( *undinic ) );
if ( ! netdev ) if ( ! netdev )
return -ENOMEM; return -ENOMEM;
undi = netdev->priv; undinic = netdev->priv;
pxe_set_drvdata ( pxe, netdev ); undi_set_drvdata ( undi, netdev );
memset ( undi, 0, sizeof ( *undi ) ); memset ( undinic, 0, sizeof ( *undinic ) );
undi->entry = pxe->entry; undinic->entry = undi->entry;
/* Hook in UNDI stack */ /* Hook in UNDI stack */
memset ( &start_undi, 0, sizeof ( start_undi ) ); memset ( &start_undi, 0, sizeof ( start_undi ) );
start_undi.AX = pxe->pci_busdevfn; start_undi.AX = undi->pci_busdevfn;
start_undi.BX = pxe->isapnp_csn; start_undi.BX = undi->isapnp_csn;
start_undi.DX = pxe->isapnp_read_port; start_undi.DX = undi->isapnp_read_port;
start_undi.ES = BIOS_SEG; start_undi.ES = BIOS_SEG;
start_undi.DI = find_pnp_bios(); start_undi.DI = find_pnp_bios();
if ( ( rc = undi_call ( undi, PXENV_START_UNDI, &start_undi, if ( ( rc = undinet_call ( undinic, PXENV_START_UNDI, &start_undi,
sizeof ( start_undi ) ) ) != 0 ) sizeof ( start_undi ) ) ) != 0 )
goto err_start_undi; goto err_start_undi;
/* Bring up UNDI stack */ /* Bring up UNDI stack */
memset ( &undi_startup, 0, sizeof ( undi_startup ) ); memset ( &undi_startup, 0, sizeof ( undi_startup ) );
if ( ( rc = undi_call ( undi, PXENV_UNDI_STARTUP, &undi_startup, if ( ( rc = undinet_call ( undinic, PXENV_UNDI_STARTUP, &undi_startup,
sizeof ( undi_startup ) ) ) != 0 ) sizeof ( undi_startup ) ) ) != 0 )
goto err_undi_startup; goto err_undi_startup;
memset ( &undi_initialize, 0, sizeof ( undi_initialize ) ); memset ( &undi_initialize, 0, sizeof ( undi_initialize ) );
if ( ( rc = undi_call ( undi, PXENV_UNDI_INITIALIZE, &undi_initialize, if ( ( rc = undinet_call ( undinic, PXENV_UNDI_INITIALIZE,
sizeof ( undi_initialize ) ) ) != 0 ) &undi_initialize,
sizeof ( undi_initialize ) ) ) != 0 )
goto err_undi_initialize; goto err_undi_initialize;
/* Get device information */ /* Get device information */
memset ( &undi_info, 0, sizeof ( undi_info ) ); memset ( &undi_info, 0, sizeof ( undi_info ) );
if ( ( rc = undi_call ( undi, PXENV_UNDI_GET_INFORMATION, &undi_info, if ( ( rc = undinet_call ( undinic, PXENV_UNDI_GET_INFORMATION,
sizeof ( undi_info ) ) ) != 0 ) &undi_info, sizeof ( undi_info ) ) ) != 0 )
goto err_undi_get_information; goto err_undi_get_information;
memcpy ( netdev->ll_addr, undi_info.PermNodeAddress, ETH_ALEN ); memcpy ( netdev->ll_addr, undi_info.PermNodeAddress, ETH_ALEN );
undi->irq = undi_info.IntNumber; undinic->irq = undi_info.IntNumber;
if ( undi->irq > IRQ_MAX ) { if ( undinic->irq > IRQ_MAX ) {
DBGC ( undi, "UNDI %p invalid IRQ %d\n", undi, undi->irq ); DBGC ( undinic, "UNDINIC %p invalid IRQ %d\n",
undinic, undinic->irq );
goto err_bad_irq; goto err_bad_irq;
} }
DBGC ( undi, "UNDI %p (%s) using IRQ %d\n", DBGC ( undinic, "UNDINIC %p (%s) using IRQ %d\n",
undi, eth_ntoa ( netdev->ll_addr ), undi->irq ); undinic, eth_ntoa ( netdev->ll_addr ), undinic->irq );
/* Point to NIC specific routines */ /* Point to NIC specific routines */
netdev->open = undi_open; netdev->open = undinet_open;
netdev->close = undi_close; netdev->close = undinet_close;
netdev->transmit = undi_transmit; netdev->transmit = undinet_transmit;
netdev->poll = undi_poll; netdev->poll = undinet_poll;
/* Register network device */ /* Register network device */
if ( ( rc = register_netdev ( netdev ) ) != 0 ) if ( ( rc = register_netdev ( netdev ) ) != 0 )
@@ -613,29 +594,30 @@ int undi_probe ( struct pxe_device *pxe ) {
err_undi_initialize: err_undi_initialize:
/* Shut down UNDI stack */ /* Shut down UNDI stack */
memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) ); memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
undi_call ( undi, PXENV_UNDI_SHUTDOWN, &undi_shutdown, undinet_call ( undinic, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
sizeof ( undi_shutdown ) ); sizeof ( undi_shutdown ) );
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) ); memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
undi_call ( undi, PXENV_UNDI_CLEANUP, &undi_cleanup, undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
sizeof ( undi_cleanup ) ); sizeof ( undi_cleanup ) );
err_undi_startup: err_undi_startup:
/* Unhook UNDI stack */ /* Unhook UNDI stack */
memset ( &stop_undi, 0, sizeof ( stop_undi ) ); memset ( &stop_undi, 0, sizeof ( stop_undi ) );
undi_call ( undi, PXENV_STOP_UNDI, &stop_undi, sizeof ( stop_undi ) ); undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
sizeof ( stop_undi ) );
err_start_undi: err_start_undi:
free_netdev ( netdev ); free_netdev ( netdev );
pxe_set_drvdata ( pxe, NULL ); undi_set_drvdata ( undi, NULL );
return rc; return rc;
} }
/** /**
* Remove PXE device * Remove UNDI device
* *
* @v pxe PXE device * @v undi UNDI device
*/ */
void undi_remove ( struct pxe_device *pxe ) { void undinet_remove ( struct undi_device *undi ) {
struct net_device *netdev = pxe_get_drvdata ( pxe ); struct net_device *netdev = undi_get_drvdata ( undi );
struct undi_nic *undi = netdev->priv; struct undi_nic *undinic = netdev->priv;
struct s_PXENV_UNDI_SHUTDOWN undi_shutdown; struct s_PXENV_UNDI_SHUTDOWN undi_shutdown;
struct s_PXENV_UNDI_CLEANUP undi_cleanup; struct s_PXENV_UNDI_CLEANUP undi_cleanup;
struct s_PXENV_STOP_UNDI stop_undi; struct s_PXENV_STOP_UNDI stop_undi;
@@ -645,15 +627,16 @@ void undi_remove ( struct pxe_device *pxe ) {
/* Shut down UNDI stack */ /* Shut down UNDI stack */
memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) ); memset ( &undi_shutdown, 0, sizeof ( undi_shutdown ) );
undi_call ( undi, PXENV_UNDI_SHUTDOWN, &undi_shutdown, undinet_call ( undinic, PXENV_UNDI_SHUTDOWN, &undi_shutdown,
sizeof ( undi_shutdown ) ); sizeof ( undi_shutdown ) );
memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) ); memset ( &undi_cleanup, 0, sizeof ( undi_cleanup ) );
undi_call ( undi, PXENV_UNDI_CLEANUP, &undi_cleanup, undinet_call ( undinic, PXENV_UNDI_CLEANUP, &undi_cleanup,
sizeof ( undi_cleanup ) ); sizeof ( undi_cleanup ) );
/* Unhook UNDI stack */ /* Unhook UNDI stack */
memset ( &stop_undi, 0, sizeof ( stop_undi ) ); memset ( &stop_undi, 0, sizeof ( stop_undi ) );
undi_call ( undi, PXENV_STOP_UNDI, &stop_undi, sizeof ( stop_undi ) ); undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
sizeof ( stop_undi ) );
/* Free network device */ /* Free network device */
free_netdev ( netdev ); free_netdev ( netdev );

View File

@@ -0,0 +1,59 @@
#ifndef _UNDI_H
#define _UNDI_H
/** @file
*
* UNDI driver
*
*/
/** An UNDI device */
struct undi_device {
/** Generic device */
struct device dev;
/** Driver-private data
*
* Use undi_set_drvdata() and undi_get_drvdata() to access this
* field.
*/
void *priv;
/** PXENV+ structure address */
SEGOFF16_t pxenv;
/** !PXE structure address */
SEGOFF16_t ppxe;
/** Entry point */
SEGOFF16_t entry;
/** PCI bus:dev.fn, or 0 */
unsigned int pci_busdevfn;
/** ISAPnP card select number, or -1U */
unsigned int isapnp_csn;
/** ISAPnP read port, or -1U */
unsigned int isapnp_read_port;
/** Free base memory prior to load */
unsigned int restore_fbms;
/** Free base memory after load */
unsigned int fbms;
};
/**
* Set UNDI driver-private data
*
* @v undi UNDI device
* @v priv Private data
*/
static inline void undi_set_drvdata ( struct undi_device *undi, void *priv ) {
undi->priv = priv;
}
/**
* Get UNDI driver-private data
*
* @v undi UNDI device
* @ret priv Private data
*/
static inline void * undi_get_drvdata ( struct undi_device *undi ) {
return undi->priv;
}
#endif /* _UNDI_H */

View File

@@ -0,0 +1,15 @@
#ifndef _UNDINET_H
#define _UNDINET_H
/** @file
*
* UNDI network device driver
*
*/
struct undi_device;
extern int undinet_probe ( struct undi_device *undi );
extern void undinet_remove ( struct undi_device *undi );
#endif /* _UNDINET_H */