mirror of https://github.com/ipxe/ipxe.git
Updated to new device API.
parent
1218698e01
commit
27a55b514c
|
@ -22,11 +22,6 @@ Bochs Pseudo NIC driver for Etherboot
|
||||||
/* PNIC API */
|
/* PNIC API */
|
||||||
#include "pnic_api.h"
|
#include "pnic_api.h"
|
||||||
|
|
||||||
/* Private data structure */
|
|
||||||
typedef struct {
|
|
||||||
uint16_t api_version;
|
|
||||||
} pnic_priv_data_t;
|
|
||||||
|
|
||||||
/* Function prototypes */
|
/* Function prototypes */
|
||||||
static int pnic_api_check ( uint16_t api_version );
|
static int pnic_api_check ( uint16_t api_version );
|
||||||
|
|
||||||
|
@ -96,7 +91,6 @@ static uint16_t pnic_command ( struct nic *nic, uint16_t command,
|
||||||
void *input, uint16_t input_length,
|
void *input, uint16_t input_length,
|
||||||
void *output, uint16_t output_max_length,
|
void *output, uint16_t output_max_length,
|
||||||
uint16_t *output_length ) {
|
uint16_t *output_length ) {
|
||||||
pnic_priv_data_t *priv = (pnic_priv_data_t*)nic->priv_data;
|
|
||||||
uint16_t status = pnic_command_quiet ( nic, command,
|
uint16_t status = pnic_command_quiet ( nic, command,
|
||||||
input, input_length,
|
input, input_length,
|
||||||
output, output_max_length,
|
output, output_max_length,
|
||||||
|
@ -104,7 +98,6 @@ static uint16_t pnic_command ( struct nic *nic, uint16_t command,
|
||||||
if ( status == PNIC_STATUS_OK ) return status;
|
if ( status == PNIC_STATUS_OK ) return status;
|
||||||
printf ( "PNIC command %#hx (len %#hx) failed with status %#hx\n",
|
printf ( "PNIC command %#hx (len %#hx) failed with status %#hx\n",
|
||||||
command, input_length, status );
|
command, input_length, status );
|
||||||
if ( priv->api_version ) pnic_api_check(priv->api_version);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,11 +115,18 @@ static int pnic_api_check ( uint16_t api_version ) {
|
||||||
return ( api_version == PNIC_API_VERSION );
|
return ( api_version == PNIC_API_VERSION );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
CONNECT - connect adapter to the network
|
||||||
|
***************************************************************************/
|
||||||
|
static int pnic_connect ( struct nic *nic __unused ) {
|
||||||
|
/* Nothing to do */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
POLL - Wait for a frame
|
POLL - Wait for a frame
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static int pnic_poll(struct nic *nic, int retrieve)
|
static int pnic_poll ( struct nic *nic, int retrieve ) {
|
||||||
{
|
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
uint16_t qlen;
|
uint16_t qlen;
|
||||||
|
|
||||||
|
@ -153,13 +153,9 @@ static int pnic_poll(struct nic *nic, int retrieve)
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
TRANSMIT - Transmit a frame
|
TRANSMIT - Transmit a frame
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void pnic_transmit(
|
static void pnic_transmit ( struct nic *nic, const char *dest,
|
||||||
struct nic *nic,
|
unsigned int type, unsigned int size,
|
||||||
const char *dest, /* Destination */
|
const char *data ) {
|
||||||
unsigned int type, /* Type */
|
|
||||||
unsigned int size, /* size */
|
|
||||||
const char *data) /* Packet */
|
|
||||||
{
|
|
||||||
unsigned int nstype = htons ( type );
|
unsigned int nstype = htons ( type );
|
||||||
|
|
||||||
if ( ( ETH_HLEN + size ) >= ETH_FRAME_LEN ) {
|
if ( ( ETH_HLEN + size ) >= ETH_FRAME_LEN ) {
|
||||||
|
@ -180,17 +176,14 @@ static void pnic_transmit(
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
DISABLE - Turn off ethernet interface
|
DISABLE - Turn off ethernet interface
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void pnic_disable(struct dev *dev)
|
static void pnic_disable ( struct nic *nic ) {
|
||||||
{
|
|
||||||
struct nic *nic = (struct nic *)dev;
|
|
||||||
pnic_command ( nic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
|
pnic_command ( nic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
IRQ - Handle card interrupt status
|
IRQ - Handle card interrupt status
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void pnic_irq ( struct nic *nic, irq_action_t action )
|
static void pnic_irq ( struct nic *nic, irq_action_t action ) {
|
||||||
{
|
|
||||||
uint8_t enabled;
|
uint8_t enabled;
|
||||||
|
|
||||||
switch ( action ) {
|
switch ( action ) {
|
||||||
|
@ -208,60 +201,60 @@ static void pnic_irq ( struct nic *nic, irq_action_t action )
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
PROBE - Look for an adapter, this routine's visible to the outside
|
NIC operations table
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
static struct nic_operations pnic_operations = {
|
||||||
static int pnic_probe(struct dev *dev, struct pci_device *pci)
|
.connect = pnic_connect,
|
||||||
{
|
.poll = pnic_poll,
|
||||||
struct nic *nic = (struct nic *)dev;
|
.transmit = pnic_transmit,
|
||||||
static pnic_priv_data_t priv;
|
.irq = pnic_irq,
|
||||||
uint16_t status;
|
.disable = pnic_disable,
|
||||||
|
};
|
||||||
printf(" - ");
|
|
||||||
|
|
||||||
/* Clear private data structure and chain it in */
|
|
||||||
memset ( &priv, 0, sizeof(priv) );
|
|
||||||
nic->priv_data = &priv;
|
|
||||||
|
|
||||||
/* Mask the bit that says "this is an io addr" */
|
|
||||||
nic->ioaddr = pci->ioaddr & ~3;
|
|
||||||
nic->irqno = pci->irq;
|
|
||||||
/* Not sure what this does, but the rtl8139 driver does it */
|
|
||||||
adjust_pci_device(pci);
|
|
||||||
|
|
||||||
status = pnic_command_quiet( nic, PNIC_CMD_API_VER, NULL, 0,
|
|
||||||
&priv.api_version,
|
|
||||||
sizeof(priv.api_version), NULL );
|
|
||||||
if ( status != PNIC_STATUS_OK ) {
|
|
||||||
printf ( "PNIC failed installation check, code %#hx\n",
|
|
||||||
status );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
pnic_api_check(priv.api_version);
|
|
||||||
status = pnic_command ( nic, PNIC_CMD_READ_MAC, NULL, 0,
|
|
||||||
nic->node_addr, ETH_ALEN, NULL );
|
|
||||||
printf ( "Detected Bochs Pseudo NIC MAC %! (API v%d.%d) at %#hx\n",
|
|
||||||
nic->node_addr, priv.api_version>>8, priv.api_version&0xff,
|
|
||||||
nic->ioaddr );
|
|
||||||
|
|
||||||
/* point to NIC specific routines */
|
|
||||||
dev->disable = pnic_disable;
|
|
||||||
nic->poll = pnic_poll;
|
|
||||||
nic->transmit = pnic_transmit;
|
|
||||||
nic->irq = pnic_irq;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct pci_id pnic_nics[] = {
|
static struct pci_id pnic_nics[] = {
|
||||||
/* genrules.pl doesn't let us use macros for PCI IDs...*/
|
/* genrules.pl doesn't let us use macros for PCI IDs...*/
|
||||||
PCI_ROM ( 0xfefe, 0xefef, "pnic", "Bochs Pseudo NIC Adaptor" ),
|
PCI_ROM ( 0xfefe, 0xefef, "pnic", "Bochs Pseudo NIC Adaptor" ),
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct pci_driver pnic_driver __pci_driver = {
|
static struct pci_driver pnic_driver =
|
||||||
.type = NIC_DRIVER,
|
PCI_DRIVER ( "PNIC", pnic_nics, PCI_NO_CLASS );
|
||||||
.name = "PNIC",
|
|
||||||
.probe = pnic_probe,
|
/**************************************************************************
|
||||||
.ids = pnic_nics,
|
PROBE - Look for an adapter, this routine's visible to the outside
|
||||||
.id_count = sizeof(pnic_nics)/sizeof(pnic_nics[0]),
|
***************************************************************************/
|
||||||
.class = 0,
|
|
||||||
};
|
static int pnic_probe ( struct dev *dev ) {
|
||||||
|
struct nic *nic = nic_device ( dev );
|
||||||
|
struct pci_device *pci = pci_device ( dev );
|
||||||
|
uint16_t api_version;
|
||||||
|
uint16_t status;
|
||||||
|
|
||||||
|
/* Scan PCI bus for a PNIC device */
|
||||||
|
if ( ! find_pci_device ( pci, &pnic_driver ) )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Retrieve relevant information about PCI device */
|
||||||
|
nic->ioaddr = pci->ioaddr;
|
||||||
|
nic->irqno = pci->irq;
|
||||||
|
|
||||||
|
/* API version check */
|
||||||
|
status = pnic_command_quiet( nic, PNIC_CMD_API_VER, NULL, 0,
|
||||||
|
&api_version,
|
||||||
|
sizeof(api_version), NULL );
|
||||||
|
if ( status != PNIC_STATUS_OK ) {
|
||||||
|
printf ( "PNIC failed installation check, code %#hx\n",
|
||||||
|
status );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
pnic_api_check(api_version);
|
||||||
|
|
||||||
|
/* Get MAC address */
|
||||||
|
status = pnic_command ( nic, PNIC_CMD_READ_MAC, NULL, 0,
|
||||||
|
nic->node_addr, ETH_ALEN, NULL );
|
||||||
|
|
||||||
|
/* point to NIC specific routines */
|
||||||
|
nic->nic_op = &pnic_operations;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOT_DRIVER ( "PNIC", pnic_probe );
|
||||||
|
|
Loading…
Reference in New Issue