Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added a very quick and dirty compatibility layer, to allow
not-yet-updated drivers to at least function.
  • Loading branch information
Michael Brown committed Jun 5, 2006
1 parent c3e41e6 commit 286bf68
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 49 deletions.
11 changes: 2 additions & 9 deletions src/core/nic.c
Expand Up @@ -388,6 +388,7 @@ struct type_driver nic_driver = {
.load = nic_load,
};

#if 0
/* Careful. We need an aligned buffer to avoid problems on machines
* that care about alignment. To trivally align the ethernet data
* (the ip hdr and arp requests) we offset the packet by 2 bytes.
Expand All @@ -400,17 +401,9 @@ struct nic nic = {
.node_addr = arptable[ARP_CLIENT].node,
.packet = packet + ETH_DATA_ALIGN,
};
#endif



int dummy_connect ( struct nic *nic __unused ) {
return 1;
}

void dummy_irq ( struct nic *nic __unused, irq_action_t irq_action __unused ) {
return;
}

/**************************************************************************
DEFAULT_NETMASK - Return default netmask for IP address
**************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/drivers/net/3c509.c
Expand Up @@ -9,6 +9,7 @@
#include "timer.h"
#include "string.h"
#include "console.h"
#include "dev.h"
#include "3c509.h"

/*
Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/3c595.c
Expand Up @@ -32,7 +32,6 @@
#include "timer.h"

static struct nic_operations t595_operations;
static struct pci_driver t595_driver;

static unsigned short eth_nic_base;
static unsigned short vx_connector, vx_connectors;
Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/3c90x.c
Expand Up @@ -43,7 +43,6 @@
#include "timer.h"

static struct nic_operations a3c90x_operations;
static struct pci_driver a3c90x_driver;

#define XCVR_MAGIC (0x5A00)
/** any single transmission fails after 16 collisions or other errors
Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/davicom.c
Expand Up @@ -123,7 +123,6 @@ struct rxdesc {
/*********************************************************************/

static struct nic_operations davicom_operations;
static struct pci_driver davicom_driver;

/* PCI Bus parameters */
static unsigned short vendor, dev_id;
Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/dmfe.c
Expand Up @@ -189,7 +189,6 @@ enum dmfe_CR6_bits {

/* Global variable declaration ----------------------------- */
static struct nic_operations dmfe_operations;
static struct pci_driver dmfe_driver;

static unsigned char dmfe_media_mode = DMFE_AUTO;
static u32 dmfe_cr6_user_set;
Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/e1000.c
Expand Up @@ -89,7 +89,6 @@ typedef enum {

/* NIC specific static variables go here */
static struct nic_operations e1000_operations;
static struct pci_driver e1000_driver;

static struct e1000_hw hw;

Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/eepro100.c
Expand Up @@ -252,7 +252,6 @@ struct RxFD { /* Receive frame descriptor. */
};

static struct nic_operations eepro100_operations;
static struct pci_driver eepro100_driver;

#define RXFD_COUNT 4
struct {
Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/epic100.c
Expand Up @@ -61,7 +61,6 @@ static int mii_read(int phy_id, int location);
static void epic100_irq(struct nic *nic, irq_action_t action);

static struct nic_operations epic100_operations;
static struct pci_driver epic100_driver;

static int ioaddr;

Expand Down
104 changes: 104 additions & 0 deletions src/drivers/net/legacy.c
@@ -0,0 +1,104 @@
#include <stdint.h>
#include <errno.h>
#include <gpxe/if_ether.h>
#include <gpxe/netdevice.h>
#include <gpxe/ethernet.h>
#include <gpxe/pkbuff.h>
#include <nic.h>

/*
* Quick and dirty compatibility layer
*
* This should allow old-API PCI drivers to at least function until
* they are updated. It will not help non-PCI drivers.
*
* No drivers should rely on this code. It will be removed asap.
*
*/

struct nic nic;

static int legacy_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
struct nic *nic = netdev->priv;
struct ethhdr *ethhdr = pkb->data;

pkb_pull ( pkb, sizeof ( *ethhdr ) );
nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
ntohs ( ethhdr->h_protocol ),
pkb_len ( pkb ), pkb->data );
free_pkb ( pkb );
return 0;
}

static void legacy_poll ( struct net_device *netdev ) {
struct nic *nic = netdev->priv;
struct pk_buff *pkb;

pkb = alloc_pkb ( ETH_FRAME_LEN );
if ( ! pkb )
return;

nic->packet = pkb->data;
if ( nic->nic_op->poll ( nic, 1 ) ) {
pkb_put ( pkb, nic->packetlen );
netdev_rx ( netdev, pkb );
} else {
free_pkb ( pkb );
}
}

int legacy_probe ( struct pci_device *pci,
const struct pci_device_id *id __unused,
int ( * probe ) ( struct nic *nic,
struct pci_device *pci ),
void ( * disable ) ( struct nic *nic ) ) {
struct net_device *netdev;
int rc;

netdev = alloc_etherdev ( 0 );
if ( ! netdev )
return -ENOMEM;
netdev->priv = &nic;
memset ( &nic, 0, sizeof ( nic ) );
pci_set_drvdata ( pci, netdev );

netdev->transmit = legacy_transmit;
netdev->poll = legacy_poll;
nic.node_addr = netdev->ll_addr;

if ( ! probe ( &nic, pci ) ) {
free_netdev ( netdev );
return -ENODEV;
}

if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
disable ( &nic );
free_netdev ( netdev );
return rc;
}

return 0;
}

void legacy_remove ( struct pci_device *pci,
void ( * disable ) ( struct nic *nic ) ) {
struct net_device *netdev = pci_get_drvdata ( pci );
struct nic *nic = netdev->priv;

unregister_netdev ( netdev );
disable ( nic );
free_netdev ( netdev );
}

void pci_fill_nic ( struct nic *nic, struct pci_device *pci ) {
nic->ioaddr = pci->ioaddr;
nic->irqno = pci->irq;
}

int dummy_connect ( struct nic *nic __unused ) {
return 1;
}

void dummy_irq ( struct nic *nic __unused, irq_action_t irq_action __unused ) {
return;
}
1 change: 0 additions & 1 deletion src/drivers/net/natsemi.c
Expand Up @@ -175,7 +175,6 @@ enum desc_status_bits {
/* Globals */

static struct nic_operations natsemi_operations;
static struct pci_driver natsemi_driver;

static int natsemi_debug = 1; /* 1 normal messages, 0 quiet .. 7 verbose. */

Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/pcnet32.c
Expand Up @@ -56,7 +56,6 @@

static u32 ioaddr; /* Globally used for the card's io address */
static struct nic_operations pcnet32_operations;
static struct pci_driver pcnet32_driver;

#ifdef EDEBUG
#define dprintf(x) printf x
Expand Down
1 change: 1 addition & 0 deletions src/drivers/net/sis900.c
Expand Up @@ -47,6 +47,7 @@
#include "nic.h"
#include <gpxe/pci.h>
#include "timer.h"
#include "dev.h"

#include "sis900.h"

Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/sundance.c
Expand Up @@ -572,7 +572,6 @@ static struct nic_operations sundance_operations = {
.irq = sundance_irq,

};
static struct pci_driver sundance_driver;

/**************************************************************************
PROBE - Look for an adapter, this routine's visible to the outside
Expand Down
2 changes: 0 additions & 2 deletions src/drivers/net/tlan.c
Expand Up @@ -65,8 +65,6 @@
#define dprintf(x)
#endif

static struct pci_driver tlan_driver;

static void TLan_ResetLists(struct nic *nic __unused);
static void TLan_ResetAdapter(struct nic *nic __unused);
static void TLan_FinishReset(struct nic *nic __unused);
Expand Down
1 change: 0 additions & 1 deletion src/drivers/net/via-rhine.c
Expand Up @@ -957,7 +957,6 @@ void rhine_irq ( struct nic *nic, irq_action_t action ) {
}

static struct nic_operations rhine_operations;
static struct pci_driver rhine_driver;

static int
rhine_probe ( struct nic *nic, struct pci_device *pci ) {
Expand Down
64 changes: 37 additions & 27 deletions src/include/nic.h
Expand Up @@ -8,8 +8,8 @@
#ifndef NIC_H
#define NIC_H

#include "dev.h"
#include "byteswap.h"
#include <byteswap.h>
#include <gpxe/pci.h>
#include "dhcp.h"

typedef enum {
Expand Down Expand Up @@ -49,27 +49,8 @@ struct nic_operations {
void ( *irq ) ( struct nic *, irq_action_t );
};

extern struct type_driver nic_driver;

/*
* Function prototypes
*
*/
extern int dummy_connect ( struct nic *nic );
extern void dummy_irq ( struct nic *nic, irq_action_t irq_action );
extern void nic_disable ( struct nic *nic );

/*
* Functions that implicitly operate on the current boot device
*
*/

extern struct nic nic;

static inline int eth_connect ( void ) {
return nic.nic_op->connect ( &nic );
}

static inline int eth_poll ( int retrieve ) {
return nic.nic_op->poll ( &nic, retrieve );
}
Expand All @@ -79,11 +60,40 @@ static inline void eth_transmit ( const char *dest, unsigned int type,
nic.nic_op->transmit ( &nic, dest, type, size, packet );
}

static inline void eth_irq ( irq_action_t action ) {
nic.nic_op->irq ( &nic, action );
}

/* Should be using disable() rather than eth_disable() */
extern void eth_disable ( void ) __attribute__ (( deprecated ));
/*
* Function prototypes
*
*/
extern int dummy_connect ( struct nic *nic );
extern void dummy_irq ( struct nic *nic, irq_action_t irq_action );
extern int legacy_probe ( struct pci_device *pci,
const struct pci_device_id *id,
int ( * probe ) ( struct nic *nic,
struct pci_device *pci ),
void ( * disable ) ( struct nic *nic ) );
extern void legacy_remove ( struct pci_device *pci,
void ( * disable ) ( struct nic *nic ) );
extern void pci_fill_nic ( struct nic *nic, struct pci_device *pci );

#define PCI_DRIVER(_name,_ids,_class) \
static int _name ## _legacy_probe ( struct pci_device *pci, \
const struct pci_device_id *id ); \
static void _name ## _legacy_remove ( struct pci_device *pci ); \
struct pci_driver _name __pci_driver = { \
.ids = _ids, \
.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
.probe = _name ## _legacy_probe, \
.remove = _name ## _legacy_remove, \
};

#undef DRIVER
#define DRIVER(_unused1,_unused2,_unused3,_name,_probe,_disable) \
static int _name ## _legacy_probe ( struct pci_device *pci, \
const struct pci_device_id *id ) {\
return legacy_probe ( pci, id, _probe, _disable ); \
} \
static void _name ## _legacy_remove ( struct pci_device *pci ) {\
return legacy_remove ( pci, _disable ); \
}

#endif /* NIC_H */

0 comments on commit 286bf68

Please sign in to comment.