iPXE
Functions | Variables
vmxnet3.c File Reference

VMware vmxnet3 virtual NIC driver. More...

#include <stdint.h>
#include <errno.h>
#include <assert.h>
#include <byteswap.h>
#include <ipxe/pci.h>
#include <ipxe/io.h>
#include <ipxe/malloc.h>
#include <ipxe/profile.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/if_ether.h>
#include <ipxe/ethernet.h>
#include "vmxnet3.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static uint32_t vmxnet3_command (struct vmxnet3_nic *vmxnet, uint32_t command)
 Issue command.
static int vmxnet3_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet.
static void vmxnet3_poll_tx (struct net_device *netdev)
 Poll for completed transmissions.
static void vmxnet3_flush_tx (struct net_device *netdev)
 Flush any uncompleted transmit buffers.
static void vmxnet3_refill_rx (struct net_device *netdev)
 Refill receive ring.
static void vmxnet3_poll_rx (struct net_device *netdev)
 Poll for received packets.
static void vmxnet3_flush_rx (struct net_device *netdev)
 Flush any uncompleted receive buffers.
static void vmxnet3_check_link (struct net_device *netdev)
 Check link state.
static void vmxnet3_poll_events (struct net_device *netdev)
 Poll for events.
static void vmxnet3_poll (struct net_device *netdev)
 Poll network device.
static void vmxnet3_irq (struct net_device *netdev, int enable)
 Enable/disable interrupts.
static void vmxnet3_set_ll_addr (struct vmxnet3_nic *vmxnet, const void *ll_addr)
 Set MAC address.
static int vmxnet3_open (struct net_device *netdev)
 Open NIC.
static void vmxnet3_close (struct net_device *netdev)
 Close NIC.
static int vmxnet3_check_version (struct vmxnet3_nic *vmxnet)
 Check version.
static void vmxnet3_get_hw_addr (struct vmxnet3_nic *vmxnet, void *hw_addr)
 Get permanent MAC address.
static int vmxnet3_probe (struct pci_device *pci)
 Probe PCI device.
static void vmxnet3_remove (struct pci_device *pci)
 Remove PCI device.

Variables

static struct profiler
vmxnet3_vm_command_profiler 
__profiler
 VM command profiler.
static struct net_device_operations vmxnet3_operations
 vmxnet3 net device operations
static struct pci_device_id vmxnet3_nics []
 vmxnet3 PCI IDs
struct pci_driver vmxnet3_driver __pci_driver
 vmxnet3 PCI driver

Detailed Description

VMware vmxnet3 virtual NIC driver.

Definition in file vmxnet3.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static uint32_t vmxnet3_command ( struct vmxnet3_nic vmxnet,
uint32_t  command 
) [inline, static]

Issue command.

Parameters:
vmxnetvmxnet3 NIC
commandCommand to issue
Return values:
resultCommand result

Definition at line 70 of file vmxnet3.c.

References profile_exclude(), profile_start(), profile_stop(), readl(), vmxnet3_nic::vd, VMXNET3_VD_CMD, and writel().

                                                            {
        uint32_t result;

        /* Issue command */
        profile_start ( &vmxnet3_vm_command_profiler );
        writel ( command, ( vmxnet->vd + VMXNET3_VD_CMD ) );
        result = readl ( vmxnet->vd + VMXNET3_VD_CMD );
        profile_stop ( &vmxnet3_vm_command_profiler );
        profile_exclude ( &vmxnet3_vm_command_profiler );

        return result;
}
static int vmxnet3_transmit ( struct net_device netdev,
struct io_buffer iobuf 
) [static]

Transmit packet.

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

Definition at line 91 of file vmxnet3.c.

References vmxnet3_tx_desc::address, assert, vmxnet3_nic::count, cpu_to_le32, cpu_to_le64, io_buffer::data, DBGC, vmxnet3_nic::dma, ENOBUFS, fill, vmxnet3_tx_desc::flags, iob_len(), netdev_priv(), NULL, profile_exclude(), profile_start(), profile_stop(), vmxnet3_nic::pt, vmxnet3_counters::tx_cons, vmxnet3_dma::tx_desc, vmxnet3_nic::tx_iobuf, vmxnet3_counters::tx_prod, virt_to_bus(), VMXNET3_NUM_TX_DESC, VMXNET3_PT_TXPROD, VMXNET3_TX_FILL, VMXNET3_TXF_CQ, VMXNET3_TXF_EOP, VMXNET3_TXF_GEN, wmb, and writel().

                                                        {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        struct vmxnet3_tx_desc *tx_desc;
        unsigned int fill;
        unsigned int desc_idx;
        unsigned int generation;

        /* Check that we have a free transmit descriptor */
        fill = ( vmxnet->count.tx_prod - vmxnet->count.tx_cons );
        if ( fill >= VMXNET3_TX_FILL ) {
                DBGC ( vmxnet, "VMXNET3 %p out of transmit descriptors\n",
                       vmxnet );
                return -ENOBUFS;
        }

        /* Locate transmit descriptor */
        desc_idx = ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC );
        generation = ( ( vmxnet->count.tx_prod & VMXNET3_NUM_TX_DESC ) ?
                       0 : cpu_to_le32 ( VMXNET3_TXF_GEN ) );
        assert ( vmxnet->tx_iobuf[desc_idx] == NULL );

        /* Increment producer counter */
        vmxnet->count.tx_prod++;

        /* Store I/O buffer for later completion */
        vmxnet->tx_iobuf[desc_idx] = iobuf;

        /* Populate transmit descriptor */
        tx_desc = &vmxnet->dma->tx_desc[desc_idx];
        tx_desc->address = cpu_to_le64 ( virt_to_bus ( iobuf->data ) );
        tx_desc->flags[0] = ( generation | cpu_to_le32 ( iob_len ( iobuf ) ) );
        tx_desc->flags[1] = cpu_to_le32 ( VMXNET3_TXF_CQ | VMXNET3_TXF_EOP );

        /* Hand over descriptor to NIC */
        wmb();
        profile_start ( &vmxnet3_vm_tx_profiler );
        writel ( ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC ),
                 ( vmxnet->pt + VMXNET3_PT_TXPROD ) );
        profile_stop ( &vmxnet3_vm_tx_profiler );
        profile_exclude ( &vmxnet3_vm_tx_profiler );

        return 0;
}
static void vmxnet3_poll_tx ( struct net_device netdev) [static]

Poll for completed transmissions.

Parameters:
netdevNetwork device

Definition at line 141 of file vmxnet3.c.

References vmxnet3_nic::count, cpu_to_le32, DBGC, DBGC2, vmxnet3_nic::dma, ENOTTY, vmxnet3_tx_comp::flags, vmxnet3_tx_comp::index, iob_len(), le32_to_cpu, netdev_priv(), netdev_tx_complete(), netdev_tx_err(), NULL, vmxnet3_dma::tx_comp, vmxnet3_counters::tx_cons, vmxnet3_nic::tx_iobuf, VMXNET3_NUM_TX_COMP, VMXNET3_NUM_TX_DESC, and VMXNET3_TXCF_GEN.

Referenced by vmxnet3_poll().

                                                          {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        struct vmxnet3_tx_comp *tx_comp;
        struct io_buffer *iobuf;
        unsigned int comp_idx;
        unsigned int desc_idx;
        unsigned int generation;

        while ( 1 ) {

                /* Look for completed descriptors */
                comp_idx = ( vmxnet->count.tx_cons % VMXNET3_NUM_TX_COMP );
                generation = ( ( vmxnet->count.tx_cons & VMXNET3_NUM_TX_COMP ) ?
                               0 : cpu_to_le32 ( VMXNET3_TXCF_GEN ) );
                tx_comp = &vmxnet->dma->tx_comp[comp_idx];
                if ( generation != ( tx_comp->flags &
                                     cpu_to_le32 ( VMXNET3_TXCF_GEN ) ) ) {
                        break;
                }

                /* Increment consumer counter */
                vmxnet->count.tx_cons++;

                /* Locate corresponding transmit descriptor */
                desc_idx = ( le32_to_cpu ( tx_comp->index ) %
                             VMXNET3_NUM_TX_DESC );
                iobuf = vmxnet->tx_iobuf[desc_idx];
                if ( ! iobuf ) {
                        DBGC ( vmxnet, "VMXNET3 %p completed on empty transmit "
                               "buffer %#x/%#x\n", vmxnet, comp_idx, desc_idx );
                        netdev_tx_err ( netdev, NULL, -ENOTTY );
                        continue;
                }

                /* Remove I/O buffer from transmit queue */
                vmxnet->tx_iobuf[desc_idx] = NULL;

                /* Report transmission completion to network layer */
                DBGC2 ( vmxnet, "VMXNET3 %p completed TX %#x/%#x (len %#zx)\n",
                        vmxnet, comp_idx, desc_idx, iob_len ( iobuf ) );
                netdev_tx_complete ( netdev, iobuf );
        }
}
static void vmxnet3_flush_tx ( struct net_device netdev) [static]

Flush any uncompleted transmit buffers.

Parameters:
netdevNetwork device

Definition at line 190 of file vmxnet3.c.

References ECANCELED, netdev_priv(), netdev_tx_complete_err(), NULL, vmxnet3_nic::tx_iobuf, and VMXNET3_NUM_TX_DESC.

Referenced by vmxnet3_close(), and vmxnet3_open().

                                                           {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        unsigned int i;

        for ( i = 0 ; i < VMXNET3_NUM_TX_DESC ; i++ ) {
                if ( vmxnet->tx_iobuf[i] ) {
                        netdev_tx_complete_err ( netdev, vmxnet->tx_iobuf[i],
                                                 -ECANCELED );
                        vmxnet->tx_iobuf[i] = NULL;
                }
        }
}
static void vmxnet3_refill_rx ( struct net_device netdev) [static]

Refill receive ring.

Parameters:
netdevNetwork device

Definition at line 208 of file vmxnet3.c.

References vmxnet3_rx_desc::address, alloc_iob(), assert, vmxnet3_nic::count, cpu_to_le32, cpu_to_le64, io_buffer::data, vmxnet3_nic::dma, vmxnet3_rx_desc::flags, iob_reserve, NET_IP_ALIGN, netdev_priv(), NULL, profile_exclude(), profile_start(), profile_stop(), vmxnet3_nic::pt, vmxnet3_dma::rx_desc, vmxnet3_counters::rx_fill, vmxnet3_nic::rx_iobuf, vmxnet3_counters::rx_prod, virt_to_bus(), VMXNET3_MTU, VMXNET3_NUM_RX_DESC, VMXNET3_PT_RXPROD, VMXNET3_RX_FILL, VMXNET3_RXF_GEN, wmb, and writel().

Referenced by vmxnet3_open(), and vmxnet3_poll().

                                                            {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        struct vmxnet3_rx_desc *rx_desc;
        struct io_buffer *iobuf;
        unsigned int orig_rx_prod = vmxnet->count.rx_prod;
        unsigned int desc_idx;
        unsigned int generation;

        /* Fill receive ring to specified fill level */
        while ( vmxnet->count.rx_fill < VMXNET3_RX_FILL ) {

                /* Locate receive descriptor */
                desc_idx = ( vmxnet->count.rx_prod % VMXNET3_NUM_RX_DESC );
                generation = ( ( vmxnet->count.rx_prod & VMXNET3_NUM_RX_DESC ) ?
                               0 : cpu_to_le32 ( VMXNET3_RXF_GEN ) );
                assert ( vmxnet->rx_iobuf[desc_idx] == NULL );

                /* Allocate I/O buffer */
                iobuf = alloc_iob ( VMXNET3_MTU + NET_IP_ALIGN );
                if ( ! iobuf ) {
                        /* Non-fatal low memory condition */
                        break;
                }
                iob_reserve ( iobuf, NET_IP_ALIGN );

                /* Increment producer counter and fill level */
                vmxnet->count.rx_prod++;
                vmxnet->count.rx_fill++;

                /* Store I/O buffer for later completion */
                vmxnet->rx_iobuf[desc_idx] = iobuf;

                /* Populate receive descriptor */
                rx_desc = &vmxnet->dma->rx_desc[desc_idx];
                rx_desc->address = cpu_to_le64 ( virt_to_bus ( iobuf->data ) );
                rx_desc->flags = ( generation | cpu_to_le32 ( VMXNET3_MTU ) );

        }

        /* Hand over any new descriptors to NIC */
        if ( vmxnet->count.rx_prod != orig_rx_prod ) {
                wmb();
                profile_start ( &vmxnet3_vm_refill_profiler );
                writel ( ( vmxnet->count.rx_prod % VMXNET3_NUM_RX_DESC ),
                         ( vmxnet->pt + VMXNET3_PT_RXPROD ) );
                profile_stop ( &vmxnet3_vm_refill_profiler );
                profile_exclude ( &vmxnet3_vm_refill_profiler );
        }
}
static void vmxnet3_poll_rx ( struct net_device netdev) [static]

Poll for received packets.

Parameters:
netdevNetwork device

Definition at line 263 of file vmxnet3.c.

References vmxnet3_nic::count, cpu_to_le32, DBGC, DBGC2, vmxnet3_nic::dma, ENOTTY, vmxnet3_rx_comp::flags, vmxnet3_rx_comp::index, iob_put, le32_to_cpu, len, vmxnet3_rx_comp::len, netdev_priv(), netdev_rx(), netdev_rx_err(), NULL, vmxnet3_dma::rx_comp, vmxnet3_counters::rx_cons, vmxnet3_counters::rx_fill, vmxnet3_nic::rx_iobuf, VMXNET3_MAX_PACKET_LEN, VMXNET3_NUM_RX_COMP, VMXNET3_NUM_RX_DESC, and VMXNET3_RXCF_GEN.

Referenced by vmxnet3_poll().

                                                          {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        struct vmxnet3_rx_comp *rx_comp;
        struct io_buffer *iobuf;
        unsigned int comp_idx;
        unsigned int desc_idx;
        unsigned int generation;
        size_t len;

        while ( 1 ) {

                /* Look for completed descriptors */
                comp_idx = ( vmxnet->count.rx_cons % VMXNET3_NUM_RX_COMP );
                generation = ( ( vmxnet->count.rx_cons & VMXNET3_NUM_RX_COMP ) ?
                               0 : cpu_to_le32 ( VMXNET3_RXCF_GEN ) );
                rx_comp = &vmxnet->dma->rx_comp[comp_idx];
                if ( generation != ( rx_comp->flags &
                                     cpu_to_le32 ( VMXNET3_RXCF_GEN ) ) ) {
                        break;
                }

                /* Increment consumer counter */
                vmxnet->count.rx_cons++;

                /* Locate corresponding receive descriptor */
                desc_idx = ( le32_to_cpu ( rx_comp->index ) %
                             VMXNET3_NUM_RX_DESC );
                iobuf = vmxnet->rx_iobuf[desc_idx];
                if ( ! iobuf ) {
                        DBGC ( vmxnet, "VMXNET3 %p completed on empty receive "
                               "buffer %#x/%#x\n", vmxnet, comp_idx, desc_idx );
                        netdev_rx_err ( netdev, NULL, -ENOTTY );
                        continue;
                }

                /* Remove I/O buffer from receive queue */
                vmxnet->rx_iobuf[desc_idx] = NULL;
                vmxnet->count.rx_fill--;

                /* Deliver packet to network layer */
                len = ( le32_to_cpu ( rx_comp->len ) &
                        ( VMXNET3_MAX_PACKET_LEN - 1 ) );
                DBGC2 ( vmxnet, "VMXNET3 %p completed RX %#x/%#x (len %#zx)\n",
                        vmxnet, comp_idx, desc_idx, len );
                iob_put ( iobuf, len );
                netdev_rx ( netdev, iobuf );
        }
}
static void vmxnet3_flush_rx ( struct net_device netdev) [static]

Flush any uncompleted receive buffers.

Parameters:
netdevNetwork device

Definition at line 317 of file vmxnet3.c.

References ECANCELED, netdev_priv(), netdev_rx_err(), NULL, vmxnet3_nic::rx_iobuf, and VMXNET3_NUM_RX_DESC.

Referenced by vmxnet3_close(), and vmxnet3_open().

                                                           {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        struct io_buffer *iobuf;
        unsigned int i;

        for ( i = 0 ; i < VMXNET3_NUM_RX_DESC ; i++ ) {
                if ( ( iobuf = vmxnet->rx_iobuf[i] ) != NULL ) {
                        netdev_rx_err ( netdev, iobuf, -ECANCELED );
                        vmxnet->rx_iobuf[i] = NULL;
                }
        }
}
static void vmxnet3_check_link ( struct net_device netdev) [static]

Check link state.

Parameters:
netdevNetwork device

Definition at line 335 of file vmxnet3.c.

References DBGC, netdev_link_down(), netdev_link_up(), netdev_priv(), state, and VMXNET3_CMD_GET_LINK.

Referenced by vmxnet3_poll_events(), and vmxnet3_probe().

                                                             {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        uint32_t state;
        int link_up;
        unsigned int link_speed;

        /* Get link state */
        state = vmxnet3_command ( vmxnet, VMXNET3_CMD_GET_LINK );
        link_up = ( state & 1 );
        link_speed = ( state >> 16 );

        /* Report link state to network device */
        if ( link_up ) {
                DBGC ( vmxnet, "VMXNET3 %p link is up at %d Mbps\n",
                       vmxnet, link_speed );
                netdev_link_up ( netdev );
        } else {
                DBGC ( vmxnet, "VMXNET3 %p link is down\n", vmxnet );
                netdev_link_down ( netdev );
        }
}
static void vmxnet3_poll_events ( struct net_device netdev) [static]

Poll for events.

Parameters:
netdevNetwork device

Definition at line 362 of file vmxnet3.c.

References DBGC, vmxnet3_nic::dma, vmxnet3_shared::ecr, ENODEV, EPIPE, vmxnet3_queue_status::error, le32_to_cpu, netdev_priv(), netdev_rx_err(), netdev_tx_err(), NULL, profile_exclude(), profile_start(), profile_stop(), vmxnet3_dma::queues, vmxnet3_queues::rx, vmxnet3_dma::shared, vmxnet3_tx_queue::status, vmxnet3_rx_queue::status, vmxnet3_queues::tx, vmxnet3_nic::vd, vmxnet3_check_link(), VMXNET3_CMD_GET_QUEUE_STATUS, VMXNET3_ECR_LINK, VMXNET3_ECR_RQERR, VMXNET3_ECR_TQERR, VMXNET3_VD_ECR, and writel().

Referenced by vmxnet3_poll().

                                                              {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        uint32_t events;

        /* Do nothing unless there are events to process */
        if ( ! vmxnet->dma->shared.ecr )
                return;
        events = le32_to_cpu ( vmxnet->dma->shared.ecr );

        /* Acknowledge these events */
        profile_start ( &vmxnet3_vm_event_profiler );
        writel ( events, ( vmxnet->vd + VMXNET3_VD_ECR ) );
        profile_stop ( &vmxnet3_vm_event_profiler );
        profile_exclude ( &vmxnet3_vm_event_profiler );

        /* Check for link state change */
        if ( events & VMXNET3_ECR_LINK ) {
                vmxnet3_check_link ( netdev );
                events &= ~VMXNET3_ECR_LINK;
        }

        /* Check for queue errors */
        if ( events & ( VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR ) ) {
                vmxnet3_command ( vmxnet, VMXNET3_CMD_GET_QUEUE_STATUS );
                DBGC ( vmxnet, "VMXNET3 %p queue error status (TX %08x, RX "
                       "%08x)\n", vmxnet,
                       le32_to_cpu ( vmxnet->dma->queues.tx.status.error ),
                       le32_to_cpu ( vmxnet->dma->queues.rx.status.error ) );
                /* Report errors to allow for visibility via "ifstat" */
                if ( events & VMXNET3_ECR_TQERR )
                        netdev_tx_err ( netdev, NULL, -EPIPE );
                if ( events & VMXNET3_ECR_RQERR )
                        netdev_rx_err ( netdev, NULL, -EPIPE );
                events &= ~( VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR );
        }

        /* Check for unknown events */
        if ( events ) {
                DBGC ( vmxnet, "VMXNET3 %p unknown events %08x\n",
                       vmxnet, events );
                /* Report error to allow for visibility via "ifstat" */
                netdev_rx_err ( netdev, NULL, -ENODEV );
        }
}
static void vmxnet3_poll ( struct net_device netdev) [static]

Poll network device.

Parameters:
netdevNetwork device

Definition at line 412 of file vmxnet3.c.

References vmxnet3_poll_events(), vmxnet3_poll_rx(), vmxnet3_poll_tx(), and vmxnet3_refill_rx().

                                                       {

        vmxnet3_poll_events ( netdev );
        vmxnet3_poll_tx ( netdev );
        vmxnet3_poll_rx ( netdev );
        vmxnet3_refill_rx ( netdev );
}
static void vmxnet3_irq ( struct net_device netdev,
int  enable 
) [static]

Enable/disable interrupts.

Parameters:
netdevNetwork device
enableInterrupts should be enabled

Definition at line 426 of file vmxnet3.c.

References DBGC, and netdev_priv().

                                                                  {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );

        DBGC ( vmxnet, "VMXNET3 %p %s IRQ not implemented\n",
               vmxnet, ( enable ? "enable" : "disable" ) );
}
static void vmxnet3_set_ll_addr ( struct vmxnet3_nic vmxnet,
const void *  ll_addr 
) [static]

Set MAC address.

Parameters:
vmxnetvmxnet3 NIC
ll_addrLink-layer address to set

Definition at line 439 of file vmxnet3.c.

References __attribute__, cpu_to_le32, ETH_ALEN, high, low, mac, memcpy(), memset(), vmxnet3_nic::vd, VMXNET3_VD_MACH, VMXNET3_VD_MACL, and writel().

Referenced by vmxnet3_open().

                                                        {
        struct {
                uint32_t low;
                uint32_t high;
        } __attribute__ (( packed )) mac;

        memset ( &mac, 0, sizeof ( mac ) );
        memcpy ( &mac, ll_addr, ETH_ALEN );
        writel ( cpu_to_le32 ( mac.low ), ( vmxnet->vd + VMXNET3_VD_MACL ) );
        writel ( cpu_to_le32 ( mac.high ), ( vmxnet->vd + VMXNET3_VD_MACH ) );
}
static int vmxnet3_open ( struct net_device netdev) [static]

Open NIC.

Parameters:
netdevNetwork device
Return values:
rcReturn status code

Definition at line 458 of file vmxnet3.c.

References vmxnet3_tx_queue::cfg, vmxnet3_rx_queue::cfg, vmxnet3_tx_queue_config::comp_address, vmxnet3_rx_queue_config::comp_address, vmxnet3_interrupt_config::control, vmxnet3_nic::count, cpu_to_le32, cpu_to_le64, DBGC, vmxnet3_tx_queue_config::desc_address, vmxnet3_rx_queue_config::desc_address, vmxnet3_nic::dma, EIO, ENOMEM, free_dma(), vmxnet3_shared::interrupt, net_device::ll_addr, vmxnet3_shared::magic, malloc_dma(), memset(), vmxnet3_shared::misc, vmxnet3_rx_filter_config::mode, vmxnet3_misc_config::mtu, netdev_priv(), vmxnet3_tx_queue_config::num_comp, vmxnet3_rx_queue_config::num_comp, vmxnet3_tx_queue_config::num_desc, vmxnet3_rx_queue_config::num_desc, vmxnet3_interrupt_config::num_intrs, vmxnet3_misc_config::num_rx_queues, vmxnet3_misc_config::num_tx_queues, vmxnet3_misc_config::queue_desc_address, vmxnet3_misc_config::queue_desc_len, vmxnet3_dma::queues, rc, vmxnet3_queues::rx, vmxnet3_dma::rx_comp, vmxnet3_dma::rx_desc, vmxnet3_shared::rx_filter, vmxnet3_dma::shared, status, vmxnet3_queues::tx, vmxnet3_dma::tx_comp, vmxnet3_dma::tx_desc, vmxnet3_misc_config::upt_version_support, vmxnet3_nic::vd, vmxnet3_misc_config::version, vmxnet3_misc_config::version_support, virt_to_bus(), VMXNET3_CMD_ACTIVATE_DEV, VMXNET3_CMD_QUIESCE_DEV, VMXNET3_CMD_RESET_DEV, VMXNET3_DMA_ALIGN, vmxnet3_flush_rx(), vmxnet3_flush_tx(), VMXNET3_IC_DISABLE_ALL, VMXNET3_MTU, VMXNET3_NUM_RX_COMP, VMXNET3_NUM_RX_DESC, VMXNET3_NUM_TX_COMP, VMXNET3_NUM_TX_DESC, vmxnet3_refill_rx(), VMXNET3_RXM_ALL_MULTI, VMXNET3_RXM_BCAST, VMXNET3_RXM_UCAST, vmxnet3_set_ll_addr(), VMXNET3_SHARED_MAGIC, VMXNET3_UPT_VERSION_SELECT, VMXNET3_VD_DSAH, VMXNET3_VD_DSAL, VMXNET3_VERSION_MAGIC, VMXNET3_VERSION_SELECT, and writel().

                                                      {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
        struct vmxnet3_shared *shared;
        struct vmxnet3_queues *queues;
        uint64_t shared_bus;
        uint64_t queues_bus;
        uint32_t status;
        int rc;

        /* Allocate DMA areas */
        vmxnet->dma = malloc_dma ( sizeof ( *vmxnet->dma ), VMXNET3_DMA_ALIGN );
        if ( ! vmxnet->dma ) {
                DBGC ( vmxnet, "VMXNET3 %p could not allocate DMA area\n",
                       vmxnet );
                rc = -ENOMEM;
                goto err_alloc_dma;
        }
        memset ( vmxnet->dma, 0, sizeof ( *vmxnet->dma ) );

        /* Populate queue descriptors */
        queues = &vmxnet->dma->queues;
        queues->tx.cfg.desc_address =
                cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->tx_desc ) );
        queues->tx.cfg.comp_address =
                cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->tx_comp ) );
        queues->tx.cfg.num_desc = cpu_to_le32 ( VMXNET3_NUM_TX_DESC );
        queues->tx.cfg.num_comp = cpu_to_le32 ( VMXNET3_NUM_TX_COMP );
        queues->rx.cfg.desc_address[0] =
                cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->rx_desc ) );
        queues->rx.cfg.comp_address =
                cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->rx_comp ) );
        queues->rx.cfg.num_desc[0] = cpu_to_le32 ( VMXNET3_NUM_RX_DESC );
        queues->rx.cfg.num_comp = cpu_to_le32 ( VMXNET3_NUM_RX_COMP );
        queues_bus = virt_to_bus ( queues );
        DBGC ( vmxnet, "VMXNET3 %p queue descriptors at %08llx+%zx\n",
               vmxnet, queues_bus, sizeof ( *queues ) );

        /* Populate shared area */
        shared = &vmxnet->dma->shared;
        shared->magic = cpu_to_le32 ( VMXNET3_SHARED_MAGIC );
        shared->misc.version = cpu_to_le32 ( VMXNET3_VERSION_MAGIC );
        shared->misc.version_support = cpu_to_le32 ( VMXNET3_VERSION_SELECT );
        shared->misc.upt_version_support =
                cpu_to_le32 ( VMXNET3_UPT_VERSION_SELECT );
        shared->misc.queue_desc_address = cpu_to_le64 ( queues_bus );
        shared->misc.queue_desc_len = cpu_to_le32 ( sizeof ( *queues ) );
        shared->misc.mtu = cpu_to_le32 ( VMXNET3_MTU );
        shared->misc.num_tx_queues = 1;
        shared->misc.num_rx_queues = 1;
        shared->interrupt.num_intrs = 1;
        shared->interrupt.control = cpu_to_le32 ( VMXNET3_IC_DISABLE_ALL );
        shared->rx_filter.mode = cpu_to_le32 ( VMXNET3_RXM_UCAST |
                                               VMXNET3_RXM_BCAST |
                                               VMXNET3_RXM_ALL_MULTI );
        shared_bus = virt_to_bus ( shared );
        DBGC ( vmxnet, "VMXNET3 %p shared area at %08llx+%zx\n",
               vmxnet, shared_bus, sizeof ( *shared ) );

        /* Zero counters */
        memset ( &vmxnet->count, 0, sizeof ( vmxnet->count ) );

        /* Set MAC address */
        vmxnet3_set_ll_addr ( vmxnet, &netdev->ll_addr );

        /* Pass shared area to device */
        writel ( ( shared_bus >> 0 ), ( vmxnet->vd + VMXNET3_VD_DSAL ) );
        writel ( ( shared_bus >> 32 ), ( vmxnet->vd + VMXNET3_VD_DSAH ) );

        /* Activate device */
        if ( ( status = vmxnet3_command ( vmxnet,
                                          VMXNET3_CMD_ACTIVATE_DEV ) ) != 0 ) {
                DBGC ( vmxnet, "VMXNET3 %p could not activate (status %#x)\n",
                       vmxnet, status );
                rc = -EIO;
                goto err_activate;
        }

        /* Fill receive ring */
        vmxnet3_refill_rx ( netdev );

        return 0;

        vmxnet3_command ( vmxnet, VMXNET3_CMD_QUIESCE_DEV );
        vmxnet3_command ( vmxnet, VMXNET3_CMD_RESET_DEV );
 err_activate:
        vmxnet3_flush_tx ( netdev );
        vmxnet3_flush_rx ( netdev );
        free_dma ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
 err_alloc_dma:
        return rc;
}
static void vmxnet3_close ( struct net_device netdev) [static]

Close NIC.

Parameters:
netdevNetwork device

Definition at line 555 of file vmxnet3.c.

References vmxnet3_nic::dma, free_dma(), netdev_priv(), VMXNET3_CMD_QUIESCE_DEV, VMXNET3_CMD_RESET_DEV, vmxnet3_flush_rx(), and vmxnet3_flush_tx().

                                                        {
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );

        vmxnet3_command ( vmxnet, VMXNET3_CMD_QUIESCE_DEV );
        vmxnet3_command ( vmxnet, VMXNET3_CMD_RESET_DEV );
        vmxnet3_flush_tx ( netdev );
        vmxnet3_flush_rx ( netdev );
        free_dma ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
}
static int vmxnet3_check_version ( struct vmxnet3_nic vmxnet) [static]

Check version.

Parameters:
vmxnetvmxnet3 NIC
Return values:
rcReturn status code

Definition at line 580 of file vmxnet3.c.

References DBGC, readl(), vmxnet3_nic::vd, version, VMXNET3_UPT_VERSION_SELECT, VMXNET3_VD_UVRS, VMXNET3_VD_VRRS, VMXNET3_VERSION_SELECT, and writel().

Referenced by vmxnet3_probe().

                                                                {
        uint32_t version;
        uint32_t upt_version;

        /* Read version */
        version = readl ( vmxnet->vd + VMXNET3_VD_VRRS );
        upt_version = readl ( vmxnet->vd + VMXNET3_VD_UVRS );
        DBGC ( vmxnet, "VMXNET3 %p is version %d (UPT version %d)\n",
               vmxnet, version, upt_version );

        /* Inform NIC of driver version */
        writel ( VMXNET3_VERSION_SELECT, ( vmxnet->vd + VMXNET3_VD_VRRS ) );
        writel ( VMXNET3_UPT_VERSION_SELECT, ( vmxnet->vd + VMXNET3_VD_UVRS ) );

        return 0;
}
static void vmxnet3_get_hw_addr ( struct vmxnet3_nic vmxnet,
void *  hw_addr 
) [static]

Get permanent MAC address.

Parameters:
vmxnetvmxnet3 NIC
hw_addrHardware address to fill in

Definition at line 603 of file vmxnet3.c.

References __attribute__, ETH_ALEN, high, le32_to_cpu, low, mac, memcpy(), VMXNET3_CMD_GET_PERM_MAC_HI, and VMXNET3_CMD_GET_PERM_MAC_LO.

Referenced by vmxnet3_probe().

                                                                              {
        struct {
                uint32_t low;
                uint32_t high;
        } __attribute__ (( packed )) mac;

        mac.low = le32_to_cpu ( vmxnet3_command ( vmxnet,
                                               VMXNET3_CMD_GET_PERM_MAC_LO ) );
        mac.high = le32_to_cpu ( vmxnet3_command ( vmxnet,
                                               VMXNET3_CMD_GET_PERM_MAC_HI ) );
        memcpy ( hw_addr, &mac, ETH_ALEN );
}
static int vmxnet3_probe ( struct pci_device pci) [static]

Probe PCI device.

Parameters:
pciPCI device
idPCI ID
Return values:
rcReturn status code

Definition at line 623 of file vmxnet3.c.

References adjust_pci_device(), alloc_etherdev(), DBGC, pci_device::dev, net_device::dev, ENODEV, ENOMEM, net_device::hw_addr, ioremap(), iounmap(), memset(), netdev, netdev_init(), netdev_nullify(), netdev_priv(), netdev_put(), pci_bar_start(), pci_set_drvdata(), vmxnet3_nic::pt, rc, register_netdev(), strerror(), unregister_netdev(), vmxnet3_nic::vd, vmxnet3_check_link(), vmxnet3_check_version(), VMXNET3_CMD_RESET_DEV, vmxnet3_get_hw_addr(), VMXNET3_PT_BAR, VMXNET3_PT_LEN, VMXNET3_VD_BAR, and VMXNET3_VD_LEN.

                                                    {
        struct net_device *netdev;
        struct vmxnet3_nic *vmxnet;
        int rc;

        /* Allocate network device */
        netdev = alloc_etherdev ( sizeof ( *vmxnet ) );
        if ( ! netdev ) {
                rc = -ENOMEM;
                goto err_alloc_etherdev;
        }
        netdev_init ( netdev, &vmxnet3_operations );
        vmxnet = netdev_priv ( netdev );
        pci_set_drvdata ( pci, netdev );
        netdev->dev = &pci->dev;
        memset ( vmxnet, 0, sizeof ( *vmxnet ) );

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

        /* Map PCI BARs */
        vmxnet->pt = ioremap ( pci_bar_start ( pci, VMXNET3_PT_BAR ),
                               VMXNET3_PT_LEN );
        if ( ! vmxnet->pt ) {
                rc = -ENODEV;
                goto err_ioremap_pt;
        }
        vmxnet->vd = ioremap ( pci_bar_start ( pci, VMXNET3_VD_BAR ),
                               VMXNET3_VD_LEN );
        if ( ! vmxnet->vd ) {
                rc = -ENODEV;
                goto err_ioremap_vd;
        }

        /* Version check */
        if ( ( rc = vmxnet3_check_version ( vmxnet ) ) != 0 )
                goto err_check_version;

        /* Reset device */
        if ( ( rc = vmxnet3_command ( vmxnet, VMXNET3_CMD_RESET_DEV ) ) != 0 )
                goto err_reset;

        /* Read initial MAC address */
        vmxnet3_get_hw_addr ( vmxnet, &netdev->hw_addr );

        /* Register network device */
        if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
                DBGC ( vmxnet, "VMXNET3 %p could not register net device: "
                       "%s\n", vmxnet, strerror ( rc ) );
                goto err_register_netdev;
        }

        /* Get initial link state */
        vmxnet3_check_link ( netdev );

        return 0;

        unregister_netdev ( netdev );
 err_register_netdev:
 err_reset:
 err_check_version:
        iounmap ( vmxnet->vd );
 err_ioremap_vd:
        iounmap ( vmxnet->pt );
 err_ioremap_pt:
        netdev_nullify ( netdev );
        netdev_put ( netdev );
 err_alloc_etherdev:
        return rc;
}
static void vmxnet3_remove ( struct pci_device pci) [static]

Remove PCI device.

Parameters:
pciPCI device

Definition at line 699 of file vmxnet3.c.

References iounmap(), netdev, netdev_nullify(), netdev_priv(), netdev_put(), pci_get_drvdata(), vmxnet3_nic::pt, unregister_netdev(), and vmxnet3_nic::vd.

                                                      {
        struct net_device *netdev = pci_get_drvdata ( pci );
        struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );

        unregister_netdev ( netdev );
        iounmap ( vmxnet->vd );
        iounmap ( vmxnet->pt );
        netdev_nullify ( netdev );
        netdev_put ( netdev );
}

Variable Documentation

struct profiler vmxnet3_vm_event_profiler __profiler [static]
Initial value:
        { .name = "vmxnet3.vm_command" }

VM command profiler.

VM event profiler.

VM receive refill profiler.

VM transmit profiler.

Definition at line 48 of file vmxnet3.c.

Initial value:
 {
        .open           = vmxnet3_open,
        .close          = vmxnet3_close,
        .transmit       = vmxnet3_transmit,
        .poll           = vmxnet3_poll,
        .irq            = vmxnet3_irq,
}

vmxnet3 net device operations

Definition at line 566 of file vmxnet3.c.

struct pci_device_id vmxnet3_nics[] [static]
Initial value:
 {
        PCI_ROM ( 0x15ad, 0x07b0, "vmxnet3", "vmxnet3 virtual NIC", 0 ),
}

vmxnet3 PCI IDs

Definition at line 711 of file vmxnet3.c.

struct pci_driver vmxnet3_driver __pci_driver
Initial value:
 {
        .ids = vmxnet3_nics,
        .id_count = ( sizeof ( vmxnet3_nics ) / sizeof ( vmxnet3_nics[0] ) ),
        .probe = vmxnet3_probe,
        .remove = vmxnet3_remove,
}

vmxnet3 PCI driver

Definition at line 716 of file vmxnet3.c.