iPXE
Functions | Variables
intel.c File Reference

Intel 10/100/1000 network card driver. More...

#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/profile.h>
#include "intel.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int intel_read_eeprom (struct nvs_device *nvs, unsigned int address, void *data, size_t len)
 Read data from EEPROM.
static int intel_write_eeprom (struct nvs_device *nvs, unsigned int address __unused, const void *data __unused, size_t len __unused)
 Write data to EEPROM.
static int intel_init_eeprom (struct intel_nic *intel)
 Initialise EEPROM.
static int intel_fetch_mac_eeprom (struct intel_nic *intel, uint8_t *hw_addr)
 Fetch initial MAC address from EEPROM.
static int intel_fetch_mac (struct intel_nic *intel, uint8_t *hw_addr)
 Fetch initial MAC address.
static int intel_reset (struct intel_nic *intel)
 Reset hardware.
static void intel_check_link (struct net_device *netdev)
 Check link state.
void intel_describe_tx (struct intel_descriptor *tx, physaddr_t addr, size_t len)
 Populate transmit descriptor.
void intel_describe_tx_adv (struct intel_descriptor *tx, physaddr_t addr, size_t len)
 Populate advanced transmit descriptor.
void intel_describe_rx (struct intel_descriptor *rx, physaddr_t addr, size_t len __unused)
 Populate receive descriptor.
static int intel_disable_ring (struct intel_nic *intel, unsigned int reg)
 Disable descriptor ring.
void intel_reset_ring (struct intel_nic *intel, unsigned int reg)
 Reset descriptor ring.
int intel_create_ring (struct intel_nic *intel, struct intel_ring *ring)
 Create descriptor ring.
void intel_destroy_ring (struct intel_nic *intel, struct intel_ring *ring)
 Destroy descriptor ring.
void intel_refill_rx (struct intel_nic *intel)
 Refill receive descriptor ring.
void intel_empty_rx (struct intel_nic *intel)
 Discard unused receive I/O buffers.
static int intel_open (struct net_device *netdev)
 Open network device.
static void intel_close (struct net_device *netdev)
 Close network device.
int intel_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet.
void intel_poll_tx (struct net_device *netdev)
 Poll for completed packets.
void intel_poll_rx (struct net_device *netdev)
 Poll for received packets.
static void intel_poll (struct net_device *netdev)
 Poll for completed and received packets.
static void intel_irq (struct net_device *netdev, int enable)
 Enable or disable interrupts.
static int intel_probe (struct pci_device *pci)
 Probe PCI device.
static void intel_remove (struct pci_device *pci)
 Remove PCI device.

Variables

static struct profiler
intel_vm_tx_profiler 
__profiler
 VM transmit profiler.
static struct net_device_operations intel_operations
 Intel network device operations.
static struct pci_device_id intel_nics []
 Intel PCI device IDs.
struct pci_driver intel_driver __pci_driver
 Intel PCI driver.

Detailed Description

Intel 10/100/1000 network card driver.

Definition in file intel.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int intel_read_eeprom ( struct nvs_device nvs,
unsigned int  address,
void *  data,
size_t  len 
) [static]

Read data from EEPROM.

Parameters:
nvsNVS device
addressAddress from which to read
dataData buffer
lenLength of data buffer
Return values:
rcReturn status code

Definition at line 74 of file intel.c.

References assert, container_of, cpu_to_le16, data, DBGC, eeprom, ETIMEDOUT, INTEL_EEPROM_MAX_WAIT_MS, INTEL_EERD, INTEL_EERD_DATA, INTEL_EERD_START, mdelay(), readl(), value, and writel().

Referenced by intel_init_eeprom().

                                                        {
        struct intel_nic *intel =
                container_of ( nvs, struct intel_nic, eeprom );
        unsigned int i;
        uint32_t value;
        uint16_t *data_word = data;

        /* Sanity check.  We advertise a blocksize of one word, so
         * should only ever receive single-word requests.
         */
        assert ( len == sizeof ( *data_word ) );

        /* Initiate read */
        writel ( ( INTEL_EERD_START | ( address << intel->eerd_addr_shift ) ),
                 intel->regs + INTEL_EERD );

        /* Wait for read to complete */
        for ( i = 0 ; i < INTEL_EEPROM_MAX_WAIT_MS ; i++ ) {

                /* If read is not complete, delay 1ms and retry */
                value = readl ( intel->regs + INTEL_EERD );
                if ( ! ( value & intel->eerd_done ) ) {
                        mdelay ( 1 );
                        continue;
                }

                /* Extract data */
                *data_word = cpu_to_le16 ( INTEL_EERD_DATA ( value ) );
                return 0;
        }

        DBGC ( intel, "INTEL %p timed out waiting for EEPROM read\n", intel );
        return -ETIMEDOUT;
}
static int intel_write_eeprom ( struct nvs_device nvs,
unsigned int address  __unused,
const void *data  __unused,
size_t len  __unused 
) [static]

Write data to EEPROM.

Parameters:
nvsNVS device
addressAddress to which to write
dataData buffer
lenLength of data buffer
Return values:
rcReturn status code

Definition at line 119 of file intel.c.

References container_of, DBGC, eeprom, and ENOTSUP.

Referenced by intel_init_eeprom().

                                                      {
        struct intel_nic *intel =
                container_of ( nvs, struct intel_nic, eeprom );

        DBGC ( intel, "INTEL %p EEPROM write not supported\n", intel );
        return -ENOTSUP;
}
static int intel_init_eeprom ( struct intel_nic *  intel) [static]

Initialise EEPROM.

Parameters:
intelIntel device
Return values:
rcReturn status code

Definition at line 136 of file intel.c.

References DBGC, ETIMEDOUT, INTEL_EEPROM_MAX_WAIT_MS, INTEL_EEPROM_MIN_SIZE_WORDS, INTEL_EEPROM_WORD_LEN_LOG2, INTEL_EERD, INTEL_EERD_ADDR_SHIFT_LARGE, INTEL_EERD_ADDR_SHIFT_SMALL, INTEL_EERD_DONE_LARGE, INTEL_EERD_DONE_SMALL, INTEL_EERD_START, intel_read_eeprom(), intel_write_eeprom(), mdelay(), readl(), value, and writel().

Referenced by intel_fetch_mac_eeprom().

                                                         {
        unsigned int i;
        uint32_t value;

        /* The NIC automatically detects the type of attached EEPROM.
         * The EERD register provides access to only a single word at
         * a time, so we pretend to have a single-word block size.
         *
         * The EEPROM size may be larger than the minimum size, but
         * this doesn't matter to us since we access only the first
         * few words.
         */
        intel->eeprom.word_len_log2 = INTEL_EEPROM_WORD_LEN_LOG2;
        intel->eeprom.size = INTEL_EEPROM_MIN_SIZE_WORDS;
        intel->eeprom.block_size = 1;
        intel->eeprom.read = intel_read_eeprom;
        intel->eeprom.write = intel_write_eeprom;

        /* The layout of the EERD register was changed at some point
         * to accommodate larger EEPROMs.  Read from address zero (for
         * which the request layouts are compatible) to determine
         * which type of register we have.
         */
        writel ( INTEL_EERD_START, intel->regs + INTEL_EERD );
        for ( i = 0 ; i < INTEL_EEPROM_MAX_WAIT_MS ; i++ ) {
                value = readl ( intel->regs + INTEL_EERD );
                if ( value & INTEL_EERD_DONE_LARGE ) {
                        DBGC ( intel, "INTEL %p has large-format EERD\n",
                               intel );
                        intel->eerd_done = INTEL_EERD_DONE_LARGE;
                        intel->eerd_addr_shift = INTEL_EERD_ADDR_SHIFT_LARGE;
                        return 0;
                }
                if ( value & INTEL_EERD_DONE_SMALL ) {
                        DBGC ( intel, "INTEL %p has small-format EERD\n",
                               intel );
                        intel->eerd_done = INTEL_EERD_DONE_SMALL;
                        intel->eerd_addr_shift = INTEL_EERD_ADDR_SHIFT_SMALL;
                        return 0;
                }
                mdelay ( 1 );
        }

        DBGC ( intel, "INTEL %p timed out waiting for initial EEPROM read "
               "(value %08x)\n", intel, value );
        return -ETIMEDOUT;
}
static int intel_fetch_mac_eeprom ( struct intel_nic *  intel,
uint8_t hw_addr 
) [static]

Fetch initial MAC address from EEPROM.

Parameters:
intelIntel device
hw_addrHardware address to fill in
Return values:
rcReturn status code

Definition at line 198 of file intel.c.

References DBGC, ETH_ALEN, eth_ntoa(), INTEL_EEPROM_MAC, intel_init_eeprom(), nvs_read(), rc, and strerror().

Referenced by intel_fetch_mac().

                                                       {
        int rc;

        /* Initialise EEPROM */
        if ( ( rc = intel_init_eeprom ( intel ) ) != 0 )
                return rc;

        /* Read base MAC address from EEPROM */
        if ( ( rc = nvs_read ( &intel->eeprom, INTEL_EEPROM_MAC,
                               hw_addr, ETH_ALEN ) ) != 0 ) {
                DBGC ( intel, "INTEL %p could not read EEPROM base MAC "
                       "address: %s\n", intel, strerror ( rc ) );
                return rc;
        }

        /* Adjust MAC address for multi-port devices */
        hw_addr[ETH_ALEN-1] ^= intel->port;

        DBGC ( intel, "INTEL %p has EEPROM MAC address %s (port %d)\n",
               intel, eth_ntoa ( hw_addr ), intel->port );
        return 0;
}
static int intel_fetch_mac ( struct intel_nic *  intel,
uint8_t hw_addr 
) [static]

Fetch initial MAC address.

Parameters:
intelIntel device
hw_addrHardware address to fill in
Return values:
rcReturn status code

Definition at line 229 of file intel.c.

References cpu_to_le32, DBGC, ENOENT, ETH_ALEN, eth_ntoa(), intel_receive_address::high, intel_fetch_mac_eeprom(), INTEL_RAH0, INTEL_RAL0, is_valid_ether_addr(), intel_receive_address::low, memcpy(), intel_receive_address::raw, rc, and readl().

Referenced by intel_probe().

                                                                         {
        union intel_receive_address mac;
        int rc;

        /* Read current address from RAL0/RAH0 */
        mac.reg.low = cpu_to_le32 ( readl ( intel->regs + INTEL_RAL0 ) );
        mac.reg.high = cpu_to_le32 ( readl ( intel->regs + INTEL_RAH0 ) );
        DBGC ( intel, "INTEL %p has autoloaded MAC address %s\n",
               intel, eth_ntoa ( mac.raw ) );

        /* Use current address if valid */
        if ( is_valid_ether_addr ( mac.raw ) ) {
                memcpy ( hw_addr, mac.raw, ETH_ALEN );
                return 0;
        }

        /* Otherwise, try to read address from EEPROM */
        if ( ( rc = intel_fetch_mac_eeprom ( intel, hw_addr ) ) == 0 )
                return 0;

        DBGC ( intel, "INTEL %p has no MAC address to use\n", intel );
        return -ENOENT;
}
static int intel_reset ( struct intel_nic *  intel) [static]

Reset hardware.

Parameters:
intelIntel device
Return values:
rcReturn status code

Definition at line 266 of file intel.c.

References ctrl, DBGC, INTEL_CTRL, INTEL_CTRL_ASDE, INTEL_CTRL_FRCDPLX, INTEL_CTRL_FRCSPD, INTEL_CTRL_LRST, INTEL_CTRL_PHY_RST, INTEL_CTRL_RST, INTEL_CTRL_SLU, INTEL_NO_ASDE, INTEL_NO_PHY_RST, INTEL_PBA, INTEL_PBS, INTEL_PBS_ERRATA, INTEL_RESET_DELAY_MS, INTEL_STATUS, INTEL_STATUS_LU, mdelay(), readl(), status, and writel().

Referenced by intel_close(), intel_probe(), and intel_remove().

                                                   {
        uint32_t pbs;
        uint32_t pba;
        uint32_t ctrl;
        uint32_t status;
        uint32_t orig_ctrl;
        uint32_t orig_status;

        /* Record initial control and status register values */
        orig_ctrl = ctrl = readl ( intel->regs + INTEL_CTRL );
        orig_status = readl ( intel->regs + INTEL_STATUS );

        /* Force RX and TX packet buffer allocation, to work around an
         * errata in ICH devices.
         */
        if ( intel->flags & INTEL_PBS_ERRATA ) {
                DBGC ( intel, "INTEL %p WARNING: applying ICH PBS/PBA errata\n",
                       intel );
                pbs = readl ( intel->regs + INTEL_PBS );
                pba = readl ( intel->regs + INTEL_PBA );
                writel ( 0x08, intel->regs + INTEL_PBA );
                writel ( 0x10, intel->regs + INTEL_PBS );
                DBGC ( intel, "INTEL %p PBS %#08x->%#08x PBA %#08x->%#08x\n",
                       intel, pbs, readl ( intel->regs + INTEL_PBS ),
                       pba, readl ( intel->regs + INTEL_PBA ) );
        }

        /* Always reset MAC.  Required to reset the TX and RX rings. */
        writel ( ( ctrl | INTEL_CTRL_RST ), intel->regs + INTEL_CTRL );
        mdelay ( INTEL_RESET_DELAY_MS );

        /* Set a sensible default configuration */
        if ( ! ( intel->flags & INTEL_NO_ASDE ) )
                ctrl |= INTEL_CTRL_ASDE;
        ctrl |= INTEL_CTRL_SLU;
        ctrl &= ~( INTEL_CTRL_LRST | INTEL_CTRL_FRCSPD | INTEL_CTRL_FRCDPLX );
        writel ( ctrl, intel->regs + INTEL_CTRL );
        mdelay ( INTEL_RESET_DELAY_MS );

        /* On some models (notably ICH), the PHY reset mechanism
         * appears to be broken.  In particular, the PHY_CTRL register
         * will be correctly loaded from NVM but the values will not
         * be propagated to the "OEM bits" PHY register.  This
         * typically has the effect of dropping the link speed to
         * 10Mbps.
         *
         * Work around this problem by skipping the PHY reset if
         * either (a) the link is already up, or (b) this particular
         * NIC is known to be broken.
         */
        status = readl ( intel->regs + INTEL_STATUS );
        if ( ( intel->flags & INTEL_NO_PHY_RST ) ||
             ( status & INTEL_STATUS_LU ) ) {
                DBGC ( intel, "INTEL %p %sMAC reset (%08x/%08x was "
                       "%08x/%08x)\n", intel,
                       ( ( intel->flags & INTEL_NO_PHY_RST ) ? "forced " : "" ),
                       ctrl, status, orig_ctrl, orig_status );
                return 0;
        }

        /* Reset PHY and MAC simultaneously */
        writel ( ( ctrl | INTEL_CTRL_RST | INTEL_CTRL_PHY_RST ),
                 intel->regs + INTEL_CTRL );
        mdelay ( INTEL_RESET_DELAY_MS );

        /* PHY reset is not self-clearing on all models */
        writel ( ctrl, intel->regs + INTEL_CTRL );
        mdelay ( INTEL_RESET_DELAY_MS );
        status = readl ( intel->regs + INTEL_STATUS );

        DBGC ( intel, "INTEL %p MAC+PHY reset (%08x/%08x was %08x/%08x)\n",
               intel, ctrl, status, orig_ctrl, orig_status );
        return 0;
}
static void intel_check_link ( struct net_device netdev) [static]

Check link state.

Parameters:
netdevNetwork device

Definition at line 353 of file intel.c.

References DBGC, INTEL_STATUS, INTEL_STATUS_LU, netdev_link_down(), netdev_link_up(), net_device::priv, readl(), and status.

Referenced by intel_open(), intel_poll(), and intel_probe().

                                                           {
        struct intel_nic *intel = netdev->priv;
        uint32_t status;

        /* Read link status */
        status = readl ( intel->regs + INTEL_STATUS );
        DBGC ( intel, "INTEL %p link status is %08x\n", intel, status );

        /* Update network device */
        if ( status & INTEL_STATUS_LU ) {
                netdev_link_up ( netdev );
        } else {
                netdev_link_down ( netdev );
        }
}
void intel_describe_tx ( struct intel_descriptor tx,
physaddr_t  addr,
size_t  len 
)

Populate transmit descriptor.

Parameters:
txTransmit descriptor
addrData buffer address
lenLength of data

Definition at line 383 of file intel.c.

References intel_descriptor::address, intel_descriptor::command, cpu_to_le16, cpu_to_le64, intel_descriptor::flags, INTEL_DESC_CMD_EOP, INTEL_DESC_CMD_IFCS, INTEL_DESC_CMD_RS, intel_descriptor::length, and intel_descriptor::status.

Referenced by intel_probe(), and intelx_probe().

                                      {

        /* Populate transmit descriptor */
        tx->address = cpu_to_le64 ( addr );
        tx->length = cpu_to_le16 ( len );
        tx->flags = 0;
        tx->command = ( INTEL_DESC_CMD_RS | INTEL_DESC_CMD_IFCS |
                        INTEL_DESC_CMD_EOP );
        tx->status = 0;
}
void intel_describe_tx_adv ( struct intel_descriptor tx,
physaddr_t  addr,
size_t  len 
)

Populate advanced transmit descriptor.

Parameters:
txTransmit descriptor
addrData buffer address
lenLength of data

Definition at line 402 of file intel.c.

References intel_descriptor::address, intel_descriptor::command, cpu_to_le16, cpu_to_le32, cpu_to_le64, intel_descriptor::flags, INTEL_DESC_CMD_DEXT, INTEL_DESC_CMD_EOP, INTEL_DESC_CMD_IFCS, INTEL_DESC_CMD_RS, INTEL_DESC_FL_DTYP_DATA, INTEL_DESC_STATUS_PAYLEN, intel_descriptor::length, and intel_descriptor::status.

Referenced by intelxvf_probe().

void intel_describe_rx ( struct intel_descriptor rx,
physaddr_t  addr,
size_t len  __unused 
)

Populate receive descriptor.

Parameters:
rxReceive descriptor
addrData buffer address
lenLength of data

Definition at line 421 of file intel.c.

References intel_descriptor::address, cpu_to_le64, intel_descriptor::length, and intel_descriptor::status.

Referenced by intel_probe(), intelx_probe(), and intelxvf_probe().

                                               {

        /* Populate transmit descriptor */
        rx->address = cpu_to_le64 ( addr );
        rx->length = 0;
        rx->status = 0;
}
static int intel_disable_ring ( struct intel_nic *  intel,
unsigned int  reg 
) [static]

Disable descriptor ring.

Parameters:
intelIntel device
regRegister block
Return values:
rcReturn status code

Definition at line 444 of file intel.c.

References DBGC, ETIMEDOUT, INTEL_DISABLE_MAX_WAIT_MS, INTEL_xDCTL, INTEL_xDCTL_ENABLE, mdelay(), readl(), and writel().

Referenced by intel_reset_ring().

                                                                            {
        uint32_t dctl;
        unsigned int i;

        /* Disable ring */
        writel ( 0, ( intel->regs + reg + INTEL_xDCTL ) );

        /* Wait for disable to complete */
        for ( i = 0 ; i < INTEL_DISABLE_MAX_WAIT_MS ; i++ ) {

                /* Check if ring is disabled */
                dctl = readl ( intel->regs + reg + INTEL_xDCTL );
                if ( ! ( dctl & INTEL_xDCTL_ENABLE ) )
                        return 0;

                /* Delay */
                mdelay ( 1 );
        }

        DBGC ( intel, "INTEL %p ring %05x timed out waiting for disable "
               "(dctl %08x)\n", intel, reg, dctl );
        return -ETIMEDOUT;
}
void intel_reset_ring ( struct intel_nic *  intel,
unsigned int  reg 
)

Reset descriptor ring.

Parameters:
intelIntel device
regRegister block
Return values:
rcReturn status code

Definition at line 475 of file intel.c.

References intel_disable_ring(), INTEL_xDBAH, INTEL_xDBAL, INTEL_xDH, INTEL_xDLEN, INTEL_xDT, and writel().

Referenced by intel_destroy_ring(), and intelxvf_open().

                                                                    {

        /* Disable ring.  Ignore errors and continue to reset the ring anyway */
        intel_disable_ring ( intel, reg );

        /* Clear ring length */
        writel ( 0, ( intel->regs + reg + INTEL_xDLEN ) );

        /* Clear ring address */
        writel ( 0, ( intel->regs + reg + INTEL_xDBAH ) );
        writel ( 0, ( intel->regs + reg + INTEL_xDBAL ) );

        /* Reset head and tail pointers */
        writel ( 0, ( intel->regs + reg + INTEL_xDH ) );
        writel ( 0, ( intel->regs + reg + INTEL_xDT ) );
}
int intel_create_ring ( struct intel_nic *  intel,
struct intel_ring ring 
)

Create descriptor ring.

Parameters:
intelIntel device
ringDescriptor ring
Return values:
rcReturn status code

Definition at line 499 of file intel.c.

References address, DBGC, intel_ring::desc, ENOMEM, INTEL_xDBAH, INTEL_xDBAL, INTEL_xDCTL, INTEL_xDCTL_ENABLE, INTEL_xDH, INTEL_xDLEN, INTEL_xDT, intel_ring::len, malloc_dma(), memset(), readl(), intel_ring::reg, virt_to_bus(), and writel().

Referenced by intel_open(), intelx_open(), and intelxvf_open().

                                                                           {
        physaddr_t address;
        uint32_t dctl;

        /* Allocate descriptor ring.  Align ring on its own size to
         * prevent any possible page-crossing errors due to hardware
         * errata.
         */
        ring->desc = malloc_dma ( ring->len, ring->len );
        if ( ! ring->desc )
                return -ENOMEM;

        /* Initialise descriptor ring */
        memset ( ring->desc, 0, ring->len );

        /* Program ring address */
        address = virt_to_bus ( ring->desc );
        writel ( ( address & 0xffffffffUL ),
                 ( intel->regs + ring->reg + INTEL_xDBAL ) );
        if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
                writel ( ( ( ( uint64_t ) address ) >> 32 ),
                         ( intel->regs + ring->reg + INTEL_xDBAH ) );
        } else {
                writel ( 0, intel->regs + ring->reg + INTEL_xDBAH );
        }

        /* Program ring length */
        writel ( ring->len, ( intel->regs + ring->reg + INTEL_xDLEN ) );

        /* Reset head and tail pointers */
        writel ( 0, ( intel->regs + ring->reg + INTEL_xDH ) );
        writel ( 0, ( intel->regs + ring->reg + INTEL_xDT ) );

        /* Enable ring */
        dctl = readl ( intel->regs + ring->reg + INTEL_xDCTL );
        dctl |= INTEL_xDCTL_ENABLE;
        writel ( dctl, intel->regs + ring->reg + INTEL_xDCTL );

        DBGC ( intel, "INTEL %p ring %05x is at [%08llx,%08llx)\n",
               intel, ring->reg, ( ( unsigned long long ) address ),
               ( ( unsigned long long ) address + ring->len ) );

        return 0;
}
void intel_destroy_ring ( struct intel_nic *  intel,
struct intel_ring ring 
)

Destroy descriptor ring.

Parameters:
intelIntel device
ringDescriptor ring

Definition at line 550 of file intel.c.

References intel_ring::cons, intel_ring::desc, free_dma(), intel_reset_ring(), intel_ring::len, NULL, intel_ring::prod, and intel_ring::reg.

Referenced by intel_close(), intel_open(), intelx_close(), intelx_open(), intelxvf_close(), and intelxvf_open().

                                                                             {

        /* Reset ring */
        intel_reset_ring ( intel, ring->reg );

        /* Free descriptor ring */
        free_dma ( ring->desc, ring->len );
        ring->desc = NULL;
        ring->prod = 0;
        ring->cons = 0;
}
void intel_refill_rx ( struct intel_nic *  intel)

Refill receive descriptor ring.

Parameters:
intelIntel device

Definition at line 567 of file intel.c.

References address, alloc_iob(), assert, io_buffer::data, DBGC2, INTEL_NUM_RX_DESC, INTEL_RX_FILL, INTEL_RX_MAX_LEN, INTEL_xDT, NULL, profile_exclude(), profile_start(), profile_stop(), rx, virt_to_bus(), wmb, and writel().

Referenced by intel_open(), intel_poll(), intelx_open(), intelx_poll(), intelxvf_open(), and intelxvf_poll().

                                                 {
        struct intel_descriptor *rx;
        struct io_buffer *iobuf;
        unsigned int rx_idx;
        unsigned int rx_tail;
        physaddr_t address;
        unsigned int refilled = 0;

        /* Refill ring */
        while ( ( intel->rx.prod - intel->rx.cons ) < INTEL_RX_FILL ) {

                /* Allocate I/O buffer */
                iobuf = alloc_iob ( INTEL_RX_MAX_LEN );
                if ( ! iobuf ) {
                        /* Wait for next refill */
                        break;
                }

                /* Get next receive descriptor */
                rx_idx = ( intel->rx.prod++ % INTEL_NUM_RX_DESC );
                rx = &intel->rx.desc[rx_idx];

                /* Populate receive descriptor */
                address = virt_to_bus ( iobuf->data );
                intel->rx.describe ( rx, address, 0 );

                /* Record I/O buffer */
                assert ( intel->rx_iobuf[rx_idx] == NULL );
                intel->rx_iobuf[rx_idx] = iobuf;

                DBGC2 ( intel, "INTEL %p RX %d is [%llx,%llx)\n", intel, rx_idx,
                        ( ( unsigned long long ) address ),
                        ( ( unsigned long long ) address + INTEL_RX_MAX_LEN ) );
                refilled++;
        }

        /* Push descriptors to card, if applicable */
        if ( refilled ) {
                wmb();
                rx_tail = ( intel->rx.prod % INTEL_NUM_RX_DESC );
                profile_start ( &intel_vm_refill_profiler );
                writel ( rx_tail, intel->regs + intel->rx.reg + INTEL_xDT );
                profile_stop ( &intel_vm_refill_profiler );
                profile_exclude ( &intel_vm_refill_profiler );
        }
}
void intel_empty_rx ( struct intel_nic *  intel)

Discard unused receive I/O buffers.

Parameters:
intelIntel device

Definition at line 619 of file intel.c.

References free_iob(), INTEL_NUM_RX_DESC, and NULL.

Referenced by intel_close(), intelx_close(), and intelxvf_close().

                                                {
        unsigned int i;

        for ( i = 0 ; i < INTEL_NUM_RX_DESC ; i++ ) {
                if ( intel->rx_iobuf[i] )
                        free_iob ( intel->rx_iobuf[i] );
                intel->rx_iobuf[i] = NULL;
        }
}
static int intel_open ( struct net_device netdev) [static]

Open network device.

Parameters:
netdevNetwork device
Return values:
rcReturn status code

Definition at line 635 of file intel.c.

References DBGC, intel_receive_address::high, intel_check_link(), intel_create_ring(), intel_destroy_ring(), INTEL_FEXTNVM11, INTEL_FEXTNVM11_WTF, INTEL_IRQ_RXT0, INTEL_RAH0, INTEL_RAH0_AV, INTEL_RAL0, INTEL_RCTL, INTEL_RCTL_BAM, INTEL_RCTL_BSIZE_2048, INTEL_RCTL_BSIZE_BSEX_MASK, INTEL_RCTL_EN, INTEL_RCTL_MPE, INTEL_RCTL_SECRC, INTEL_RCTL_UPE, intel_refill_rx(), INTEL_RST_HANG, INTEL_TCTL, INTEL_TCTL_COLD_DEFAULT, INTEL_TCTL_COLD_MASK, INTEL_TCTL_CT_DEFAULT, INTEL_TCTL_CT_MASK, INTEL_TCTL_EN, INTEL_TCTL_PSP, INTEL_VMWARE, le32_to_cpu, net_device::ll_addr, intel_receive_address::low, memcpy(), memset(), net_device::priv, intel_receive_address::raw, rc, readl(), and writel().

                                                    {
        struct intel_nic *intel = netdev->priv;
        union intel_receive_address mac;
        uint32_t fextnvm11;
        uint32_t tctl;
        uint32_t rctl;
        int rc;

        /* Set undocumented bit in FEXTNVM11 to work around an errata
         * in i219 devices that will otherwise cause a complete
         * datapath hang at the next device reset.
         */
        if ( intel->flags & INTEL_RST_HANG ) {
                DBGC ( intel, "INTEL %p WARNING: applying reset hang "
                       "workaround\n", intel );
                fextnvm11 = readl ( intel->regs + INTEL_FEXTNVM11 );
                fextnvm11 |= INTEL_FEXTNVM11_WTF;
                writel ( fextnvm11, intel->regs + INTEL_FEXTNVM11 );
        }

        /* Create transmit descriptor ring */
        if ( ( rc = intel_create_ring ( intel, &intel->tx ) ) != 0 )
                goto err_create_tx;

        /* Create receive descriptor ring */
        if ( ( rc = intel_create_ring ( intel, &intel->rx ) ) != 0 )
                goto err_create_rx;

        /* Program MAC address */
        memset ( &mac, 0, sizeof ( mac ) );
        memcpy ( mac.raw, netdev->ll_addr, sizeof ( mac.raw ) );
        writel ( le32_to_cpu ( mac.reg.low ), intel->regs + INTEL_RAL0 );
        writel ( ( le32_to_cpu ( mac.reg.high ) | INTEL_RAH0_AV ),
                 intel->regs + INTEL_RAH0 );

        /* Enable transmitter  */
        tctl = readl ( intel->regs + INTEL_TCTL );
        tctl &= ~( INTEL_TCTL_CT_MASK | INTEL_TCTL_COLD_MASK );
        tctl |= ( INTEL_TCTL_EN | INTEL_TCTL_PSP | INTEL_TCTL_CT_DEFAULT |
                  INTEL_TCTL_COLD_DEFAULT );
        writel ( tctl, intel->regs + INTEL_TCTL );

        /* Enable receiver */
        rctl = readl ( intel->regs + INTEL_RCTL );
        rctl &= ~( INTEL_RCTL_BSIZE_BSEX_MASK );
        rctl |= ( INTEL_RCTL_EN | INTEL_RCTL_UPE | INTEL_RCTL_MPE |
                  INTEL_RCTL_BAM | INTEL_RCTL_BSIZE_2048 | INTEL_RCTL_SECRC );
        writel ( rctl, intel->regs + INTEL_RCTL );

        /* Fill receive ring */
        intel_refill_rx ( intel );

        /* Update link state */
        intel_check_link ( netdev );

        /* Apply required errata */
        if ( intel->flags & INTEL_VMWARE ) {
                DBGC ( intel, "INTEL %p applying VMware errata workaround\n",
                       intel );
                intel->force_icr = INTEL_IRQ_RXT0;
        }

        return 0;

        intel_destroy_ring ( intel, &intel->rx );
 err_create_rx:
        intel_destroy_ring ( intel, &intel->tx );
 err_create_tx:
        return rc;
}
static void intel_close ( struct net_device netdev) [static]

Close network device.

Parameters:
netdevNetwork device

Definition at line 711 of file intel.c.

References intel_destroy_ring(), intel_empty_rx(), INTEL_RCTL, intel_reset(), INTEL_TCTL, net_device::priv, and writel().

                                                      {
        struct intel_nic *intel = netdev->priv;

        /* Disable receiver */
        writel ( 0, intel->regs + INTEL_RCTL );

        /* Disable transmitter  */
        writel ( 0, intel->regs + INTEL_TCTL );

        /* Destroy receive descriptor ring */
        intel_destroy_ring ( intel, &intel->rx );

        /* Discard any unused receive buffers */
        intel_empty_rx ( intel );

        /* Destroy transmit descriptor ring */
        intel_destroy_ring ( intel, &intel->tx );

        /* Reset the NIC, to flush the transmit and receive FIFOs */
        intel_reset ( intel );
}
int intel_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)

Transmit packet.

Parameters:
netdevNetwork device
iobufI/O buffer
Return values:
rcReturn status code

Definition at line 740 of file intel.c.

References address, io_buffer::data, DBGC, DBGC2, ENOBUFS, INTEL_NUM_TX_DESC, INTEL_TX_FILL, INTEL_xDT, iob_len(), len, net_device::priv, profile_exclude(), profile_start(), profile_stop(), tx, virt_to_bus(), wmb, and writel().

                                                                          {
        struct intel_nic *intel = netdev->priv;
        struct intel_descriptor *tx;
        unsigned int tx_idx;
        unsigned int tx_tail;
        physaddr_t address;
        size_t len;

        /* Get next transmit descriptor */
        if ( ( intel->tx.prod - intel->tx.cons ) >= INTEL_TX_FILL ) {
                DBGC ( intel, "INTEL %p out of transmit descriptors\n", intel );
                return -ENOBUFS;
        }
        tx_idx = ( intel->tx.prod++ % INTEL_NUM_TX_DESC );
        tx_tail = ( intel->tx.prod % INTEL_NUM_TX_DESC );
        tx = &intel->tx.desc[tx_idx];

        /* Populate transmit descriptor */
        address = virt_to_bus ( iobuf->data );
        len = iob_len ( iobuf );
        intel->tx.describe ( tx, address, len );
        wmb();

        /* Notify card that there are packets ready to transmit */
        profile_start ( &intel_vm_tx_profiler );
        writel ( tx_tail, intel->regs + intel->tx.reg + INTEL_xDT );
        profile_stop ( &intel_vm_tx_profiler );
        profile_exclude ( &intel_vm_tx_profiler );

        DBGC2 ( intel, "INTEL %p TX %d is [%llx,%llx)\n", intel, tx_idx,
                ( ( unsigned long long ) address ),
                ( ( unsigned long long ) address + len ) );

        return 0;
}
void intel_poll_tx ( struct net_device netdev)

Poll for completed packets.

Parameters:
netdevNetwork device

Definition at line 781 of file intel.c.

References cpu_to_le32, DBGC2, INTEL_DESC_STATUS_DD, INTEL_NUM_TX_DESC, netdev_tx_complete_next(), net_device::priv, intel_descriptor::status, and tx.

Referenced by intel_poll(), intelx_poll(), and intelxvf_poll().

                                                 {
        struct intel_nic *intel = netdev->priv;
        struct intel_descriptor *tx;
        unsigned int tx_idx;

        /* Check for completed packets */
        while ( intel->tx.cons != intel->tx.prod ) {

                /* Get next transmit descriptor */
                tx_idx = ( intel->tx.cons % INTEL_NUM_TX_DESC );
                tx = &intel->tx.desc[tx_idx];

                /* Stop if descriptor is still in use */
                if ( ! ( tx->status & cpu_to_le32 ( INTEL_DESC_STATUS_DD ) ) )
                        return;

                DBGC2 ( intel, "INTEL %p TX %d complete\n", intel, tx_idx );

                /* Complete TX descriptor */
                netdev_tx_complete_next ( netdev );
                intel->tx.cons++;
        }
}
void intel_poll_rx ( struct net_device netdev)

Poll for received packets.

Parameters:
netdevNetwork device

Definition at line 810 of file intel.c.

References cpu_to_le32, DBGC, DBGC2, EIO, INTEL_DESC_STATUS_DD, INTEL_DESC_STATUS_RXE, INTEL_NUM_RX_DESC, iob_put, le16_to_cpu, le32_to_cpu, len, intel_descriptor::length, netdev_rx(), netdev_rx_err(), NULL, net_device::priv, rx, and intel_descriptor::status.

Referenced by intel_poll(), intelx_poll(), and intelxvf_poll().

                                                 {
        struct intel_nic *intel = netdev->priv;
        struct intel_descriptor *rx;
        struct io_buffer *iobuf;
        unsigned int rx_idx;
        size_t len;

        /* Check for received packets */
        while ( intel->rx.cons != intel->rx.prod ) {

                /* Get next receive descriptor */
                rx_idx = ( intel->rx.cons % INTEL_NUM_RX_DESC );
                rx = &intel->rx.desc[rx_idx];

                /* Stop if descriptor is still in use */
                if ( ! ( rx->status & cpu_to_le32 ( INTEL_DESC_STATUS_DD ) ) )
                        return;

                /* Populate I/O buffer */
                iobuf = intel->rx_iobuf[rx_idx];
                intel->rx_iobuf[rx_idx] = NULL;
                len = le16_to_cpu ( rx->length );
                iob_put ( iobuf, len );

                /* Hand off to network stack */
                if ( rx->status & cpu_to_le32 ( INTEL_DESC_STATUS_RXE ) ) {
                        DBGC ( intel, "INTEL %p RX %d error (length %zd, "
                               "status %08x)\n", intel, rx_idx, len,
                               le32_to_cpu ( rx->status ) );
                        netdev_rx_err ( netdev, iobuf, -EIO );
                } else {
                        DBGC2 ( intel, "INTEL %p RX %d complete (length %zd)\n",
                                intel, rx_idx, len );
                        netdev_rx ( netdev, iobuf );
                }
                intel->rx.cons++;
        }
}
static void intel_poll ( struct net_device netdev) [static]

Poll for completed and received packets.

Parameters:
netdevNetwork device

Definition at line 854 of file intel.c.

References DBGC, ENOBUFS, ENOTSUP, intel_check_link(), INTEL_ICR, INTEL_IRQ_LSC, INTEL_IRQ_RXDMT0, INTEL_IRQ_RXO, INTEL_IRQ_RXT0, INTEL_IRQ_TXDW, INTEL_IRQ_TXQE, intel_poll_rx(), intel_poll_tx(), intel_refill_rx(), netdev_rx_err(), netdev_tx_err(), NULL, net_device::priv, profile_exclude(), profile_start(), profile_stop(), and readl().

                                                     {
        struct intel_nic *intel = netdev->priv;
        uint32_t icr;

        /* Check for and acknowledge interrupts */
        profile_start ( &intel_vm_poll_profiler );
        icr = readl ( intel->regs + INTEL_ICR );
        profile_stop ( &intel_vm_poll_profiler );
        profile_exclude ( &intel_vm_poll_profiler );
        icr |= intel->force_icr;
        if ( ! icr )
                return;

        /* Poll for TX completions, if applicable */
        if ( icr & INTEL_IRQ_TXDW )
                intel_poll_tx ( netdev );

        /* Poll for RX completions, if applicable */
        if ( icr & ( INTEL_IRQ_RXT0 | INTEL_IRQ_RXO ) )
                intel_poll_rx ( netdev );

        /* Report receive overruns */
        if ( icr & INTEL_IRQ_RXO )
                netdev_rx_err ( netdev, NULL, -ENOBUFS );

        /* Check link state, if applicable */
        if ( icr & INTEL_IRQ_LSC )
                intel_check_link ( netdev );

        /* Check for unexpected interrupts */
        if ( icr & ~( INTEL_IRQ_TXDW | INTEL_IRQ_TXQE | INTEL_IRQ_LSC |
                      INTEL_IRQ_RXDMT0 | INTEL_IRQ_RXT0 | INTEL_IRQ_RXO ) ) {
                DBGC ( intel, "INTEL %p unexpected ICR %08x\n", intel, icr );
                /* Report as a TX error */
                netdev_tx_err ( netdev, NULL, -ENOTSUP );
        }

        /* Refill RX ring */
        intel_refill_rx ( intel );
}
static void intel_irq ( struct net_device netdev,
int  enable 
) [static]

Enable or disable interrupts.

Parameters:
netdevNetwork device
enableInterrupts should be enabled

Definition at line 901 of file intel.c.

References INTEL_IMC, INTEL_IMS, INTEL_IRQ_LSC, INTEL_IRQ_RXT0, INTEL_IRQ_TXDW, net_device::priv, and writel().

                                                                {
        struct intel_nic *intel = netdev->priv;
        uint32_t mask;

        mask = ( INTEL_IRQ_TXDW | INTEL_IRQ_LSC | INTEL_IRQ_RXT0 );
        if ( enable ) {
                writel ( mask, intel->regs + INTEL_IMS );
        } else {
                writel ( mask, intel->regs + INTEL_IMC );
        }
}
static int intel_probe ( struct pci_device pci) [static]

Probe PCI device.

Parameters:
pciPCI device
Return values:
rcReturn status code

Definition at line 935 of file intel.c.

References adjust_pci_device(), alloc_etherdev(), pci_device::busdevfn, pci_device::dev, net_device::dev, pci_device_id::driver_data, ENODEV, ENOMEM, net_device::hw_addr, pci_device::id, INTEL_BAR_SIZE, intel_check_link(), intel_describe_rx(), intel_describe_tx(), intel_fetch_mac(), INTEL_NUM_RX_DESC, INTEL_NUM_TX_DESC, INTEL_RD, intel_reset(), INTEL_TD, ioremap(), iounmap(), pci_device::membase, memset(), netdev, netdev_init(), netdev_nullify(), netdev_put(), PCI_FUNC, pci_set_drvdata(), net_device::priv, rc, register_netdev(), and unregister_netdev().

                                                  {
        struct net_device *netdev;
        struct intel_nic *intel;
        int rc;

        /* Allocate and initialise net device */
        netdev = alloc_etherdev ( sizeof ( *intel ) );
        if ( ! netdev ) {
                rc = -ENOMEM;
                goto err_alloc;
        }
        netdev_init ( netdev, &intel_operations );
        intel = netdev->priv;
        pci_set_drvdata ( pci, netdev );
        netdev->dev = &pci->dev;
        memset ( intel, 0, sizeof ( *intel ) );
        intel->port = PCI_FUNC ( pci->busdevfn );
        intel->flags = pci->id->driver_data;
        intel_init_ring ( &intel->tx, INTEL_NUM_TX_DESC, INTEL_TD,
                          intel_describe_tx );
        intel_init_ring ( &intel->rx, INTEL_NUM_RX_DESC, INTEL_RD,
                          intel_describe_rx );

        /* Fix up PCI device */
        adjust_pci_device ( pci );

        /* Map registers */
        intel->regs = ioremap ( pci->membase, INTEL_BAR_SIZE );
        if ( ! intel->regs ) {
                rc = -ENODEV;
                goto err_ioremap;
        }

        /* Reset the NIC */
        if ( ( rc = intel_reset ( intel ) ) != 0 )
                goto err_reset;

        /* Fetch MAC address */
        if ( ( rc = intel_fetch_mac ( intel, netdev->hw_addr ) ) != 0 )
                goto err_fetch_mac;

        /* Register network device */
        if ( ( rc = register_netdev ( netdev ) ) != 0 )
                goto err_register_netdev;

        /* Set initial link state */
        intel_check_link ( netdev );

        return 0;

        unregister_netdev ( netdev );
 err_register_netdev:
 err_fetch_mac:
        intel_reset ( intel );
 err_reset:
        iounmap ( intel->regs );
 err_ioremap:
        netdev_nullify ( netdev );
        netdev_put ( netdev );
 err_alloc:
        return rc;
}
static void intel_remove ( struct pci_device pci) [static]

Remove PCI device.

Parameters:
pciPCI device

Definition at line 1003 of file intel.c.

References intel_reset(), iounmap(), netdev, netdev_nullify(), netdev_put(), pci_get_drvdata(), net_device::priv, and unregister_netdev().

                                                    {
        struct net_device *netdev = pci_get_drvdata ( pci );
        struct intel_nic *intel = netdev->priv;

        /* Unregister network device */
        unregister_netdev ( netdev );

        /* Reset the NIC */
        intel_reset ( intel );

        /* Free network device */
        iounmap ( intel->regs );
        netdev_nullify ( netdev );
        netdev_put ( netdev );
}

Variable Documentation

struct profiler intel_vm_poll_profiler __profiler [static]
Initial value:
        { .name = "intel.vm_tx" }

VM transmit profiler.

VM poll profiler.

VM receive refill profiler.

Definition at line 47 of file intel.c.

Initial value:
 {
        .open           = intel_open,
        .close          = intel_close,
        .transmit       = intel_transmit,
        .poll           = intel_poll,
        .irq            = intel_irq,
}

Intel network device operations.

Definition at line 914 of file intel.c.

struct pci_device_id intel_nics[] [static]

Intel PCI device IDs.

Definition at line 1020 of file intel.c.

struct pci_driver intel_driver __pci_driver
Initial value:
 {
        .ids = intel_nics,
        .id_count = ( sizeof ( intel_nics ) / sizeof ( intel_nics[0] ) ),
        .probe = intel_probe,
        .remove = intel_remove,
}

Intel PCI driver.

Definition at line 1159 of file intel.c.