a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncEtherboot - BOOTP/TFTP Bootstrap Program
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncBochs Pseudo NIC driver for Etherboot
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/*
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * This program is free software; you can redistribute it and/or
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * modify it under the terms of the GNU General Public License as
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * published by the Free Software Foundation; either version 2, or (at
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * your option) any later version.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync *
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * See pnic_api.h for an explanation of the Bochs Pseudo NIC.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/*
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * the General Public License version 2 (GPLv2) at this time for any software where
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * a choice of GPL license versions is made available with the language indicating
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * that GPLv2 or any later version may be used, or where a choice of which version
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * of the GPL is applied is otherwise unspecified.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncFILE_LICENCE ( GPL2_OR_LATER );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <stdint.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <stdio.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <ipxe/io.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <errno.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <ipxe/pci.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <ipxe/if_ether.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <ipxe/ethernet.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <ipxe/iobuf.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include <ipxe/netdevice.h>
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync#include "pnic_api.h"
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstruct pnic {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync unsigned short ioaddr;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync};
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/*
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Utility functions: issue a PNIC command, retrieve result. Use
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * pnic_command_quiet if you don't want failure codes to be
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * automatically printed. Returns the PNIC status code.
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync *
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * Set output_length to NULL only if you expect to receive exactly
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * output_max_length bytes, otherwise it'll complain that you didn't
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * get enough data (on the assumption that if you not interested in
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * discovering the output length then you're expecting a fixed amount
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync * of data).
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic uint16_t pnic_command_quiet ( struct pnic *pnic, uint16_t command,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync const void *input, uint16_t input_length,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync void *output, uint16_t output_max_length,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t *output_length ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t status;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t _output_length;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( input != NULL ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Write input length */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync outw ( input_length, pnic->ioaddr + PNIC_REG_LEN );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Write input data */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync outsb ( pnic->ioaddr + PNIC_REG_DATA, input, input_length );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Write command */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync outw ( command, pnic->ioaddr + PNIC_REG_CMD );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Retrieve status */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync status = inw ( pnic->ioaddr + PNIC_REG_STAT );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Retrieve output length */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync _output_length = inw ( pnic->ioaddr + PNIC_REG_LEN );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( output_length == NULL ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( _output_length != output_max_length ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "pnic_command %#hx: wrong data length "
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync "returned (expected %d, got %d)\n", command,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync output_max_length, _output_length );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync } else {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync *output_length = _output_length;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( output != NULL ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( _output_length > output_max_length ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "pnic_command %#hx: output buffer too small "
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync "(have %d, need %d)\n", command,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync output_max_length, _output_length );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync _output_length = output_max_length;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Retrieve output data */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync insb ( pnic->ioaddr + PNIC_REG_DATA, output, _output_length );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return status;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic uint16_t pnic_command ( struct pnic *pnic, uint16_t command,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync const void *input, uint16_t input_length,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync void *output, uint16_t output_max_length,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t *output_length ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t status = pnic_command_quiet ( pnic, command,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync input, input_length,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync output, output_max_length,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync output_length );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( status == PNIC_STATUS_OK ) return status;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "PNIC command %#hx (len %#hx) failed with status %#hx\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync command, input_length, status );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return status;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* Check API version matches that of NIC */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int pnic_api_check ( uint16_t api_version ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( api_version != PNIC_API_VERSION ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "Warning: API version mismatch! "
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync "(NIC's is %d.%d, ours is %d.%d)\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync api_version >> 8, api_version & 0xff,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync PNIC_API_VERSION >> 8, PNIC_API_VERSION & 0xff );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( api_version < PNIC_API_VERSION ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "** You may need to update your copy of Bochs **\n" );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return ( api_version == PNIC_API_VERSION );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncPOLL - Wait for a frame
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic void pnic_poll ( struct net_device *netdev ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct pnic *pnic = netdev->priv;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct io_buffer *iobuf;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t length;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t qlen;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Fetch all available packets */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync while ( 1 ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( pnic_command ( pnic, PNIC_CMD_RECV_QLEN, NULL, 0,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync &qlen, sizeof ( qlen ), NULL )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync != PNIC_STATUS_OK )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( qlen == 0 )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync iobuf = alloc_iob ( ETH_FRAME_LEN );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ! iobuf ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync DBG ( "could not allocate buffer\n" );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_rx_err ( netdev, NULL, -ENOMEM );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( pnic_command ( pnic, PNIC_CMD_RECV, NULL, 0,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync iobuf->data, ETH_FRAME_LEN, &length )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync != PNIC_STATUS_OK ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_rx_err ( netdev, iobuf, -EIO );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync iob_put ( iobuf, length );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_rx ( netdev, iobuf );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncTRANSMIT - Transmit a frame
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int pnic_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct pnic *pnic = netdev->priv;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Pad the packet */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync iob_pad ( iobuf, ETH_ZLEN );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Send packet */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pnic_command ( pnic, PNIC_CMD_XMIT, iobuf->data, iob_len ( iobuf ),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync NULL, 0, NULL );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_tx_complete ( netdev, iobuf );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return 0;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncOPEN - Open network device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int pnic_open ( struct net_device *netdev __unused ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Nothing to do */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return 0;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncCLOSE - Close network device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic void pnic_close ( struct net_device *netdev __unused ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Nothing to do */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncIRQ - Enable/disable interrupts
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic void pnic_irq ( struct net_device *netdev, int enable ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct pnic *pnic = netdev->priv;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint8_t mask = ( enable ? 1 : 0 );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pnic_command ( pnic, PNIC_CMD_MASK_IRQ, &mask, sizeof ( mask ),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync NULL, 0, NULL );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncOPERATIONS TABLE
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic struct net_device_operations pnic_operations = {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .open = pnic_open,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .close = pnic_close,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .transmit = pnic_transmit,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .poll = pnic_poll,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .irq = pnic_irq,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync};
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncDISABLE - Turn off ethernet interface
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic void pnic_remove ( struct pci_device *pci ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct net_device *netdev = pci_get_drvdata ( pci );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct pnic *pnic = netdev->priv;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync unregister_netdev ( netdev );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pnic_command ( pnic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_nullify ( netdev );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_put ( netdev );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncPROBE - Look for an adapter, this routine's visible to the outside
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int pnic_probe ( struct pci_device *pci ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct net_device *netdev;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync struct pnic *pnic;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t api_version;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t status;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync int rc;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Allocate net device */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev = alloc_etherdev ( sizeof ( *pnic ) );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ! netdev )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return -ENOMEM;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_init ( netdev, &pnic_operations );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pnic = netdev->priv;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pci_set_drvdata ( pci, netdev );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev->dev = &pci->dev;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pnic->ioaddr = pci->ioaddr;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Fix up PCI device */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync adjust_pci_device ( pci );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* API version check */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync status = pnic_command_quiet ( pnic, PNIC_CMD_API_VER, NULL, 0,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync &api_version,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync sizeof ( api_version ), NULL );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( status != PNIC_STATUS_OK ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "PNIC failed installation check, code %#hx\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync status );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync rc = -EIO;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync goto err;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync }
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pnic_api_check ( api_version );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Get MAC address */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync status = pnic_command ( pnic, PNIC_CMD_READ_MAC, NULL, 0,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev->hw_addr, ETH_ALEN, NULL );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Register network device */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( ( rc = register_netdev ( netdev ) ) != 0 )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync goto err;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Mark as link up; PNIC has no concept of link state */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_link_up ( netdev );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return 0;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync err:
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Free net device */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_nullify ( netdev );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync netdev_put ( netdev );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync return rc;
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync}
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic struct pci_device_id pnic_nics[] = {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* genrules.pl doesn't let us use macros for PCI IDs...*/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncPCI_ROM ( 0xfefe, 0xefef, "pnic", "Bochs Pseudo NIC Adaptor", 0 ),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync};
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstruct pci_driver pnic_driver __pci_driver = {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .ids = pnic_nics,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .id_count = ( sizeof ( pnic_nics ) / sizeof ( pnic_nics[0] ) ),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .probe = pnic_probe,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .remove = pnic_remove,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync};