iPXE
Functions | Variables
intelxvf.c File Reference

Intel 10 Gigabit Ethernet virtual function network card driver. More...

#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <ipxe/io.h>
#include <ipxe/pci.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include "intelx.h"
#include "intelxvf.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void intelxvf_stats (struct intel_nic *intel)
 Dump statistics.
static void intelxvf_reset (struct intel_nic *intel)
 Reset hardware.
static void intelxvf_check_link (struct net_device *netdev)
 Check link state.
static int intelxvf_mbox_version (struct intel_nic *intel, unsigned int version)
 Send negotiate API version message.
static int intelxvf_mbox_queues (struct intel_nic *intel, int *vlan_thing)
 Get queue configuration.
static int intelxvf_open (struct net_device *netdev)
 Open network device.
static void intelxvf_close (struct net_device *netdev)
 Close network device.
static void intelxvf_poll (struct net_device *netdev)
 Poll for completed and received packets.
static void intelxvf_irq (struct net_device *netdev, int enable)
 Enable or disable interrupts.
static int intelxvf_probe (struct pci_device *pci)
 Probe PCI device.
static void intelxvf_remove (struct pci_device *pci)
 Remove PCI device.

Variables

static struct net_device_operations intelxvf_operations
 Network device operations.
static struct pci_device_id intelxvf_nics []
 PCI device IDs.
struct pci_driver intelxvf_driver __pci_driver
 PCI driver.

Detailed Description

Intel 10 Gigabit Ethernet virtual function network card driver.

Definition in file intelxvf.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void intelxvf_stats ( struct intel_nic *  intel) [static]

Dump statistics.

Parameters:
intelIntel device

Definition at line 55 of file intelxvf.c.

References DBGC, INTELXVF_GORCH, INTELXVF_GORCL, INTELXVF_GOTCH, INTELXVF_GOTCL, INTELXVF_GPRC, INTELXVF_GPTC, INTELXVF_MPRC, and readl().

                                           {

        DBGC ( intel, "INTEL %p TX %d (%#x%08x) RX %d (%#x%08x) multi %d\n",
               intel, readl ( intel->regs + INTELXVF_GPTC ),
               readl ( intel->regs + INTELXVF_GOTCH ),
               readl ( intel->regs + INTELXVF_GOTCL ),
               readl ( intel->regs + INTELXVF_GPRC ),
               readl ( intel->regs + INTELXVF_GORCH ),
               readl ( intel->regs + INTELXVF_GORCL ),
               readl ( intel->regs + INTELXVF_MPRC ) );
}
static void intelxvf_reset ( struct intel_nic *  intel) [static]

Reset hardware.

Parameters:
intelIntel device

Definition at line 79 of file intelxvf.c.

References INTELXVF_CTRL, INTELXVF_CTRL_RST, and writel().

Referenced by intelxvf_close(), intelxvf_open(), intelxvf_probe(), and intelxvf_remove().

                                                       {

        /* Perform a function-level reset */
        writel ( INTELXVF_CTRL_RST, intel->regs + INTELXVF_CTRL );
}
static void intelxvf_check_link ( struct net_device netdev) [static]

Check link state.

Parameters:
netdevNetwork device

Definition at line 97 of file intelxvf.c.

References DBGC, INTELXVF_LINKS, INTELXVF_LINKS_UP, netdev_link_down(), netdev_link_up(), net_device::priv, and readl().

Referenced by intelxvf_open(), intelxvf_poll(), and intelxvf_probe().

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

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

        /* Update network device */
        if ( links & INTELXVF_LINKS_UP ) {
                netdev_link_up ( netdev );
        } else {
                netdev_link_down ( netdev );
        }
}
static int intelxvf_mbox_version ( struct intel_nic *  intel,
unsigned int  version 
) [static]

Send negotiate API version message.

Parameters:
intelIntel device
versionRequested version
Return values:
rcReturn status code

Definition at line 127 of file intelxvf.c.

References DBGC, DBGC_HDA, EPERM, EPROTO, intelvf_msg::hdr, intelvf_mbox_msg(), INTELVF_MSG_ACK, INTELVF_MSG_TYPE_MASK, INTELXVF_MSG_TYPE_VERSION, memset(), rc, strerror(), intelvf_msg_version::version, intelvf_msg::version, and version.

Referenced by intelxvf_open().

                                                          {
        union intelvf_msg msg;
        int rc;

        /* Send set MTU message */
        memset ( &msg, 0, sizeof ( msg ) );
        msg.hdr = INTELXVF_MSG_TYPE_VERSION;
        msg.version.version = version;
        if ( ( rc = intelvf_mbox_msg ( intel, &msg ) ) != 0 ) {
                DBGC ( intel, "INTEL %p negotiate API version failed: %s\n",
                       intel, strerror ( rc ) );
                return rc;
        }

        /* Check response */
        if ( ( msg.hdr & INTELVF_MSG_TYPE_MASK ) != INTELXVF_MSG_TYPE_VERSION ){
                DBGC ( intel, "INTEL %p negotiate API version unexpected "
                       "response:\n", intel );
                DBGC_HDA ( intel, 0, &msg, sizeof ( msg ) );
                return -EPROTO;
        }

        /* Check that this version is supported */
        if ( ! ( msg.hdr & INTELVF_MSG_ACK ) ) {
                DBGC ( intel, "INTEL %p negotiate API version failed\n",
                       intel );
                return -EPERM;
        }

        return 0;
}
static int intelxvf_mbox_queues ( struct intel_nic *  intel,
int *  vlan_thing 
) [static]

Get queue configuration.

Parameters:
intelIntel device
vlan_thingVLAN hand-waving thing to fill in
Return values:
rcReturn status code

Definition at line 167 of file intelxvf.c.

References DBGC, DBGC_HDA, EPERM, EPROTO, intelvf_msg::hdr, intelvf_mbox_msg(), INTELVF_MSG_ACK, INTELVF_MSG_TYPE_GET_QUEUES, INTELVF_MSG_TYPE_MASK, memset(), intelvf_msg::queues, rc, strerror(), and intelvf_msg_queues::vlan_thing.

Referenced by intelxvf_open().

                                                                             {
        union intelvf_msg msg;
        int rc;

        /* Send queue configuration message */
        memset ( &msg, 0, sizeof ( msg ) );
        msg.hdr = INTELVF_MSG_TYPE_GET_QUEUES;
        if ( ( rc = intelvf_mbox_msg ( intel, &msg ) ) != 0 ) {
                DBGC ( intel, "INTEL %p get queue configuration failed: %s\n",
                       intel, strerror ( rc ) );
                return rc;
        }

        /* Check response */
        if ( ( msg.hdr & INTELVF_MSG_TYPE_MASK ) !=INTELVF_MSG_TYPE_GET_QUEUES){
                DBGC ( intel, "INTEL %p get queue configuration unexpected "
                       "response:\n", intel );
                DBGC_HDA ( intel, 0, &msg, sizeof ( msg ) );
                return -EPROTO;
        }

        /* Check that we were allowed to get the queue configuration */
        if ( ! ( msg.hdr & INTELVF_MSG_ACK ) ) {
                DBGC ( intel, "INTEL %p get queue configuration refused\n",
                       intel );
                return -EPERM;
        }

        /* Extract VLAN hand-waving thing */
        *vlan_thing = msg.queues.vlan_thing;

        return 0;
}
static int intelxvf_open ( struct net_device netdev) [static]

Open network device.

Parameters:
netdevNetwork device
Return values:
rcReturn status code

Definition at line 214 of file intelxvf.c.

References DBGC, intel_create_ring(), intel_destroy_ring(), intel_refill_rx(), intel_reset_ring(), INTEL_xDCTL, intelvf_mbox_reset(), intelvf_mbox_set_mac(), intelvf_mbox_set_mtu(), INTELX_RXDCTL_VME, intelxvf_check_link(), INTELXVF_DCA_RXCTRL, INTELXVF_DCA_RXCTRL_MUST_BE_ZERO, INTELXVF_IVAR, INTELXVF_IVAR_RX0_DEFAULT, INTELXVF_IVAR_RX0_VALID, INTELXVF_IVAR_TX0_DEFAULT, INTELXVF_IVAR_TX0_VALID, INTELXVF_IVARM, INTELXVF_IVARM_MBOX_DEFAULT, INTELXVF_IVARM_MBOX_VALID, intelxvf_mbox_queues(), intelxvf_mbox_version(), INTELXVF_MSG_VERSION_1_1, INTELXVF_NUM_RINGS, INTELXVF_PSRTYPE, INTELXVF_RD, intelxvf_reset(), INTELXVF_SRRCTL, INTELXVF_SRRCTL_BHDRSIZE_DEFAULT, INTELXVF_SRRCTL_BHDRSIZE_MASK, INTELXVF_SRRCTL_BSIZE_DEFAULT, INTELXVF_SRRCTL_BSIZE_MASK, INTELXVF_SRRCTL_DESCTYPE_DEFAULT, INTELXVF_SRRCTL_DESCTYPE_MASK, INTELXVF_SRRCTL_DROP_EN, INTELXVF_TD, net_device::ll_addr, net_device::max_pkt_len, NULL, net_device::priv, rc, readl(), strerror(), vlan_thing, and writel().

                                                       {
        struct intel_nic *intel = netdev->priv;
        uint32_t rxdctl;
        uint32_t srrctl;
        uint32_t dca_rxctrl;
        unsigned int i;
        int vlan_thing;
        int rc;

        /* Reset the function */
        intelxvf_reset ( intel );

        /* Notify PF that reset is complete */
        if ( ( rc = intelvf_mbox_reset ( intel, NULL ) ) != 0 ) {
                DBGC ( intel, "INTEL %p could not reset: %s\n",
                       intel, strerror ( rc ) );
                goto err_mbox_reset;
        }

        /* Negotiate API version 1.1.  If we do not negotiate at least
         * this version, then the RX datapath will remain disabled if
         * the PF has jumbo frames enabled.
         *
         * Ignore failures, since the host may not actually support
         * v1.1.
         */
        intelxvf_mbox_version ( intel, INTELXVF_MSG_VERSION_1_1 );

        /* Set MAC address */
        if ( ( rc = intelvf_mbox_set_mac ( intel, netdev->ll_addr ) ) != 0 ) {
                DBGC ( intel, "INTEL %p could not set MAC address: %s\n",
                       intel, strerror ( rc ) );
                goto err_mbox_set_mac;
        }

        /* Set MTU */
        if ( ( rc = intelvf_mbox_set_mtu ( intel, netdev->max_pkt_len ) ) != 0){
                DBGC ( intel, "INTEL %p could not set MTU %zd: %s\n",
                       intel, netdev->max_pkt_len, strerror ( rc ) );
                goto err_mbox_set_mtu;
        }

        /* Reset all descriptor rings */
        for ( i = 0 ; i < INTELXVF_NUM_RINGS ; i++ ) {
                intel_reset_ring ( intel, INTELXVF_TD ( i ) );
                intel_reset_ring ( intel, INTELXVF_RD ( i ) );
        }

        /* Reset packet split receive type register */
        writel ( 0, intel->regs + INTELXVF_PSRTYPE );

        /* Get queue configuration.  Ignore failures, since the host
         * may not support this message.
         */
        vlan_thing = 0;
        intelxvf_mbox_queues ( intel, &vlan_thing );
        if ( vlan_thing ) {
                DBGC ( intel, "INTEL %p stripping VLAN tags (thing=%d)\n",
                       intel, vlan_thing );
                rxdctl = readl ( intel->regs + INTELXVF_RD(0) + INTEL_xDCTL );
                rxdctl |= INTELX_RXDCTL_VME;
                writel ( rxdctl, intel->regs + INTELXVF_RD(0) + INTEL_xDCTL );
        }

        /* 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;

        /* Allocate interrupt vectors */
        writel ( ( INTELXVF_IVAR_RX0_DEFAULT | INTELXVF_IVAR_RX0_VALID |
                   INTELXVF_IVAR_TX0_DEFAULT | INTELXVF_IVAR_TX0_VALID ),
                 intel->regs + INTELXVF_IVAR );
        writel ( ( INTELXVF_IVARM_MBOX_DEFAULT | INTELXVF_IVARM_MBOX_VALID ),
                 intel->regs + INTELXVF_IVARM );

        /* Configure receive buffer sizes and set receive descriptor type */
        srrctl = readl ( intel->regs + INTELXVF_SRRCTL );
        srrctl &= ~( INTELXVF_SRRCTL_BSIZE_MASK |
                     INTELXVF_SRRCTL_BHDRSIZE_MASK |
                     INTELXVF_SRRCTL_DESCTYPE_MASK );
        srrctl |= ( INTELXVF_SRRCTL_BSIZE_DEFAULT |
                    INTELXVF_SRRCTL_BHDRSIZE_DEFAULT |
                    INTELXVF_SRRCTL_DESCTYPE_DEFAULT |
                    INTELXVF_SRRCTL_DROP_EN );
        writel ( srrctl, intel->regs + INTELXVF_SRRCTL );

        /* Clear "must-be-zero" bit for direct cache access (DCA).  We
         * leave DCA disabled anyway, but if we do not clear this bit
         * then the received packets contain garbage data.
         */
        dca_rxctrl = readl ( intel->regs + INTELXVF_DCA_RXCTRL );
        dca_rxctrl &= ~INTELXVF_DCA_RXCTRL_MUST_BE_ZERO;
        writel ( dca_rxctrl, intel->regs + INTELXVF_DCA_RXCTRL );

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

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

        return 0;

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

Close network device.

Parameters:
netdevNetwork device

Definition at line 336 of file intelxvf.c.

References intel_destroy_ring(), intel_empty_rx(), intelxvf_reset(), and net_device::priv.

                                                         {
        struct intel_nic *intel = netdev->priv;

        /* 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 function */
        intelxvf_reset ( intel );
}
static void intelxvf_poll ( struct net_device netdev) [static]

Poll for completed and received packets.

Parameters:
netdevNetwork device

Definition at line 357 of file intelxvf.c.

References DBGC, intel_poll_rx(), intel_poll_tx(), intel_refill_rx(), intelvf_mbox_poll(), intelxvf_check_link(), INTELXVF_EICR, INTELXVF_EIRQ_MBOX, INTELXVF_EIRQ_RX0, INTELXVF_EIRQ_TX0, netdev_rx_err(), NULL, net_device::priv, rc, and readl().

                                                        {
        struct intel_nic *intel = netdev->priv;
        uint32_t eicr;
        int rc;

        /* Check for and acknowledge interrupts */
        eicr = readl ( intel->regs + INTELXVF_EICR );
        if ( ! eicr )
                return;

        /* Poll for TX completions, if applicable */
        if ( eicr & INTELXVF_EIRQ_TX0 )
                intel_poll_tx ( netdev );

        /* Poll for RX completions, if applicable */
        if ( eicr & INTELXVF_EIRQ_RX0 )
                intel_poll_rx ( netdev );

        /* Poll for mailbox messages, if applicable */
        if ( eicr & INTELXVF_EIRQ_MBOX ) {

                /* Poll mailbox */
                if ( ( rc = intelvf_mbox_poll ( intel ) ) != 0 ) {
                        DBGC ( intel, "INTEL %p mailbox poll failed!\n",
                               intel );
                        netdev_rx_err ( netdev, NULL, rc );
                }

                /* Update link state */
                intelxvf_check_link ( netdev );
        }

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

Enable or disable interrupts.

Parameters:
netdevNetwork device
enableInterrupts should be enabled

Definition at line 399 of file intelxvf.c.

References INTELXVF_EIMC, INTELXVF_EIMS, INTELXVF_EIRQ_MBOX, INTELXVF_EIRQ_RX0, INTELXVF_EIRQ_TX0, net_device::priv, and writel().

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

        mask = ( INTELXVF_EIRQ_MBOX | INTELXVF_EIRQ_TX0 | INTELXVF_EIRQ_RX0 );
        if ( enable ) {
                writel ( mask, intel->regs + INTELXVF_EIMS );
        } else {
                writel ( mask, intel->regs + INTELXVF_EIMC );
        }
}
static int intelxvf_probe ( struct pci_device pci) [static]

Probe PCI device.

Parameters:
pciPCI device
Return values:
rcReturn status code

Definition at line 433 of file intelxvf.c.

References adjust_pci_device(), alloc_etherdev(), DBGC, pci_device::dev, net_device::dev, ENODEV, ENOMEM, net_device::hw_addr, intel_describe_rx(), intel_describe_tx_adv(), INTEL_NUM_RX_DESC, INTEL_NUM_TX_DESC, INTELVF_BAR_SIZE, intelvf_mbox_reset(), intelxvf_check_link(), INTELXVF_MBCTRL, INTELXVF_MBMEM, INTELXVF_RD, intelxvf_reset(), INTELXVF_TD, ioremap(), iounmap(), pci_device::membase, memset(), netdev, netdev_init(), netdev_nullify(), netdev_put(), pci_set_drvdata(), net_device::priv, rc, register_netdev(), strerror(), 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, &intelxvf_operations );
        intel = netdev->priv;
        pci_set_drvdata ( pci, netdev );
        netdev->dev = &pci->dev;
        memset ( intel, 0, sizeof ( *intel ) );
        intel_init_mbox ( &intel->mbox, INTELXVF_MBCTRL, INTELXVF_MBMEM );
        intel_init_ring ( &intel->tx, INTEL_NUM_TX_DESC, INTELXVF_TD(0),
                          intel_describe_tx_adv );
        intel_init_ring ( &intel->rx, INTEL_NUM_RX_DESC, INTELXVF_RD(0),
                          intel_describe_rx );

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

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

        /* Reset the function */
        intelxvf_reset ( intel );

        /* Send reset message and fetch MAC address */
        if ( ( rc = intelvf_mbox_reset ( intel, netdev->hw_addr ) ) != 0 ) {
                DBGC ( intel, "INTEL %p could not reset and fetch MAC: %s\n",
                       intel, strerror ( rc ) );
                goto err_mbox_reset;
        }

        /* Reset the function (since we will not respond to Control
         * ("ping") mailbox messages until the network device is opened.
         */
        intelxvf_reset ( intel );

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

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

        return 0;

        unregister_netdev ( netdev );
 err_register_netdev:
 err_mbox_reset:
        intelxvf_reset ( intel );
        iounmap ( intel->regs );
 err_ioremap:
        netdev_nullify ( netdev );
        netdev_put ( netdev );
 err_alloc:
        return rc;
}
static void intelxvf_remove ( struct pci_device pci) [static]

Remove PCI device.

Parameters:
pciPCI device

Definition at line 506 of file intelxvf.c.

References intelxvf_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 */
        intelxvf_reset ( intel );

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

Variable Documentation

Initial value:
 {
        .open           = intelxvf_open,
        .close          = intelxvf_close,
        .transmit       = intel_transmit,
        .poll           = intelxvf_poll,
        .irq            = intelxvf_irq,
}

Network device operations.

Definition at line 412 of file intelxvf.c.

struct pci_device_id intelxvf_nics[] [static]
Initial value:
 {
        PCI_ROM ( 0x8086, 0x10ed, "82599-vf", "82599 VF", 0 ),
        PCI_ROM ( 0x8086, 0x1515, "x540-vf", "X540 VF", 0 ),
        PCI_ROM ( 0x8086, 0x1565, "x550-vf", "X550 VF", 0 ),
        PCI_ROM ( 0x8086, 0x15a8, "x552-vf", "X552 VF", 0 ),
}

PCI device IDs.

Definition at line 523 of file intelxvf.c.

struct pci_driver intelxvf_driver __pci_driver
Initial value:
 {
        .ids = intelxvf_nics,
        .id_count = ( sizeof ( intelxvf_nics ) / sizeof ( intelxvf_nics[0] ) ),
        .probe = intelxvf_probe,
        .remove = intelxvf_remove,
}

PCI driver.

Definition at line 531 of file intelxvf.c.