Updated to new PCI bus interface.

pull/1/head
Michael Brown 2005-04-15 16:08:10 +00:00
parent a26edc2eec
commit 38ea910098
1 changed files with 100 additions and 89 deletions

View File

@ -14,18 +14,45 @@ Skeleton NIC driver for Etherboot
#include "etherboot.h" #include "etherboot.h"
/* to get the interface to the body of the program */ /* to get the interface to the body of the program */
#include "nic.h" #include "nic.h"
/* to get the PCI support functions, if this is a PCI NIC */ /* Drag in support for whichever bus(es) we want for this NIC */
#include "pci.h" #include "pci.h"
/* to get the ISA support functions, if this is an ISA NIC */
#include "isa.h" #include "isa.h"
#include "eisa.h"
#include "isapnp.h"
#include "mca.h"
/* NIC specific static variables go here */ /* NIC specific static variables go here. Try to avoid using static
* variables wherever possible. In particular, the I/O address can
* always be accessed via nic->ioaddr.
*/
/*
* Don't forget to remove "__unused" from all the function parameters!
*
*/
/************************************************************************** /**************************************************************************
POLL - Wait for a frame * CONNECT - Connect to the network
***************************************************************************/ **************************************************************************
static int skel_poll(struct nic *nic, int retrieve) */
{ static int skel_connect ( struct nic *nic __unused ) {
/*
* Connect to the network. For most NICs, this will probably
* be a no-op. For wireless NICs, this should be the point at
* which you attempt to join to an access point.
*
* Return 0 if the connection failed (e.g. no cable plugged
* in), 1 for success.
*
*/
return 1;
}
/**************************************************************************
* POLL - Wait for a frame
**************************************************************************
*/
static int skel_poll ( struct nic *nic __unused, int retrieve __unused ) {
/* Work out whether or not there's an ethernet packet ready to /* Work out whether or not there's an ethernet packet ready to
* read. Return 0 if not. * read. Return 0 if not.
*/ */
@ -55,15 +82,14 @@ static int skel_poll(struct nic *nic, int retrieve)
} }
/************************************************************************** /**************************************************************************
TRANSMIT - Transmit a frame * TRANSMIT - Transmit a frame
***************************************************************************/ **************************************************************************
static void skel_transmit( */
struct nic *nic, static void skel_transmit ( struct nic *nic __unused,
const char *dest, /* Destination */ const char *dest __unused,
unsigned int type, /* Type */ unsigned int type __unused,
unsigned int size, /* size */ unsigned int size __unused,
const char *packet) /* Packet */ const char *packet __unused ) {
{
/* Transmit packet to dest MAC address. You will need to /* Transmit packet to dest MAC address. You will need to
* construct the link-layer header (dest MAC, source MAC, * construct the link-layer header (dest MAC, source MAC,
* type). * type).
@ -79,9 +105,10 @@ static void skel_transmit(
} }
/************************************************************************** /**************************************************************************
DISABLE - Turn off ethernet interface * DISABLE - Turn off ethernet interface
***************************************************************************/ **************************************************************************
static void skel_disable ( struct nic *nic ) { */
static void skel_disable ( struct nic *nic __unused ) {
/* put the card in its initial state */ /* put the card in its initial state */
/* This function serves 3 purposes. /* This function serves 3 purposes.
* This disables DMA and interrupts so we don't receive * This disables DMA and interrupts so we don't receive
@ -95,10 +122,10 @@ static void skel_disable ( struct nic *nic ) {
} }
/************************************************************************** /**************************************************************************
IRQ - handle interrupts * IRQ - handle interrupts
***************************************************************************/ **************************************************************************
static void skel_irq(struct nic *nic, irq_action_t action) */
{ static void skel_irq ( struct nic *nic __unused, irq_action_t action ) {
/* This routine is somewhat optional. Etherboot itself /* This routine is somewhat optional. Etherboot itself
* doesn't use interrupts, but they are required under some * doesn't use interrupts, but they are required under some
* circumstances when we're acting as a PXE stack. * circumstances when we're acting as a PXE stack.
@ -127,8 +154,12 @@ static void skel_irq(struct nic *nic, irq_action_t action)
} }
} }
/**************************************************************************
* OPERATIONS TABLE - Pointers to all the above methods
**************************************************************************
*/
static struct nic_operations skel_operations = { static struct nic_operations skel_operations = {
.connect = dummy_connect, .connect = skel_connect,
.poll = skel_poll, .poll = skel_poll,
.transmit = skel_transmit, .transmit = skel_transmit,
.irq = skel_irq, .irq = skel_irq,
@ -136,70 +167,50 @@ static struct nic_operations skel_operations = {
}; };
/************************************************************************** /**************************************************************************
PROBE - Look for an adapter, this routine's visible to the outside * PROBE - Look for an adapter
***************************************************************************/ *
* You need to define a probe routine for each bus type that your
#define board_found 1 * driver supports, together with tables that enable Etherboot to
#define valid_link 0 * identify that your driver should be used for a particular device.
static int skel_probe ( struct dev *dev, struct pci_device *pci ) { *
* Delete whichever of the following sections you don't need. For
* example, most PCI devices will only need the PCI probing section;
* ISAPnP, EISA, etc. can all be deleted.
*
**************************************************************************
*/
/**************************************************************************
* PCI PROBE - Look for an adapter
**************************************************************************
*/
static int skel_pci_probe ( struct dev *dev, struct pci_device *pci ) {
struct nic *nic = nic_device ( dev ); struct nic *nic = nic_device ( dev );
if (board_found && valid_link)
{
/* store NIC parameters */ /* store NIC parameters */
nic->ioaddr = pci->ioaddr; nic->ioaddr = pci->ioaddr;
nic->irqno = pci->irq; nic->irqno = pci->irq;
/* Test for physical presence of NIC */
/*
if ( ! my_tests ) {
DBG ( "Could not find NIC: my explanation\n" );
return 0;
}
*/
/* point to NIC specific routines */ /* point to NIC specific routines */
nic->nic_op = &skel_operations; nic->nic_op = &skel_operations;
return 1; return 1;
}
/* else */
return 0;
} }
static struct pci_id skel_nics[] = { static struct pci_id skel_pci_nics[] = {
PCI_ROM(0x0000, 0x0000, "skel-pci", "Skeleton PCI Adaptor"), PCI_ROM ( 0x0000, 0x0000, "skel-pci", "Skeleton PCI Adaptor" ),
}; };
static struct pci_driver skel_driver = static struct pci_driver skel_pci_driver =
PCI_DRIVER ( "SKELETON/PCI", skel_nics, PCI_NO_CLASS ); PCI_DRIVER ( "SKELETON/PCI", skel_pci_nics, PCI_NO_CLASS );
BOOT_DRIVER ( "SKELETON/PCI", find_pci_boot_device, skel_driver, skel_probe ); BOOT_DRIVER ( "SKELETON/PCI", find_pci_boot_device,
skel_pci_driver, skel_pci_probe );
/**************************************************************************
PROBE - Look for an adapter, this routine's visible to the outside
***************************************************************************/
static int skel_isa_probe(struct dev *dev, unsigned short *probe_addrs)
{
struct nic *nic = (struct nic *)dev;
/* if probe_addrs is 0, then routine can use a hardwired default */
if (board_found && valid_link)
{
/* point to NIC specific routines */
static struct nic_operations skel_operations;
static struct nic_operations skel_operations = {
.connect = dummy_connect,
.poll = skel_poll,
.transmit = skel_transmit,
.irq = skel_irq,
.disable = skel_disable,
}; nic->nic_op = &skel_operations;
/* Report the ISA pnp id of the board */
dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
dev->devid.vendor_id = htons(0x1234);
return 1;
}
/* else */
return 0;
}
ISA_ROM("skel-isa", "Skeleton ISA driver")
static struct isa_driver skel_isa_driver __isa_driver = {
.type = NIC_DRIVER,
.name = "SKELETON/ISA",
.probe = skel_isa_probe,
.ioaddrs = 0,
};