a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncEtherboot - BOOTP/TFTP Bootstrap Program
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncBochs Pseudo NIC driver for Etherboot
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 * See pnic_api.h for an explanation of the Bochs Pseudo NIC.
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 * 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 * 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).
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic uint16_t pnic_command_quiet ( struct pnic *pnic, uint16_t command,
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 /* Write command */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Retrieve status */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Retrieve output length */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync _output_length = inw ( pnic->ioaddr + PNIC_REG_LEN );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "pnic_command %#hx: output buffer too small "
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Retrieve output data */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync insb ( pnic->ioaddr + PNIC_REG_DATA, output, _output_length );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic uint16_t pnic_command ( struct pnic *pnic, uint16_t command,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync uint16_t status = pnic_command_quiet ( pnic, command,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "PNIC command %#hx (len %#hx) failed with status %#hx\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* Check API version matches that of NIC */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int pnic_api_check ( uint16_t api_version ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync "(NIC's is %d.%d, ours is %d.%d)\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "** You may need to update your copy of Bochs **\n" );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncPOLL - Wait for a frame
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic void pnic_poll ( struct net_device *netdev ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Fetch all available packets */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync while ( 1 ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( pnic_command ( pnic, PNIC_CMD_RECV_QLEN, NULL, 0,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync if ( qlen == 0 )
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncTRANSMIT - Transmit a frame
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int pnic_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Pad the packet */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Send packet */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pnic_command ( pnic, PNIC_CMD_XMIT, iobuf->data, iob_len ( iobuf ),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncOPEN - Open network device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic int pnic_open ( struct net_device *netdev __unused ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Nothing to do */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncCLOSE - Close network device
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic void pnic_close ( struct net_device *netdev __unused ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Nothing to do */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncIRQ - Enable/disable interrupts
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic void pnic_irq ( struct net_device *netdev, int enable ) {
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync pnic_command ( pnic, PNIC_CMD_MASK_IRQ, &mask, sizeof ( mask ),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncOPERATIONS TABLE
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncstatic struct net_device_operations pnic_operations = {
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 pnic_command ( pnic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/**************************************************************************
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncPROBE - Look for an adapter, this routine's visible to the outside
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync***************************************************************************/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Allocate net device */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Fix up PCI device */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* API version check */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync status = pnic_command_quiet ( pnic, PNIC_CMD_API_VER, NULL, 0,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync printf ( "PNIC failed installation check, code %#hx\n",
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Get MAC address */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync status = pnic_command ( pnic, PNIC_CMD_READ_MAC, NULL, 0,
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Register network device */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Mark as link up; PNIC has no concept of link state */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync /* Free net device */
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync/* genrules.pl doesn't let us use macros for PCI IDs...*/
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsyncPCI_ROM ( 0xfefe, 0xefef, "pnic", "Bochs Pseudo NIC Adaptor", 0 ),
a734c64bff58bda2fa48c2795453e092167b0ff7vboxsync .id_count = ( sizeof ( pnic_nics ) / sizeof ( pnic_nics[0] ) ),