iPXE
Functions | Variables
vmxnet3.c File Reference

VMware vmxnet3 virtual NIC driver. More...

#include <stdint.h>
#include <string.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. More...
 
static int vmxnet3_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void vmxnet3_poll_tx (struct net_device *netdev)
 Poll for completed transmissions. More...
 
static void vmxnet3_flush_tx (struct net_device *netdev)
 Flush any uncompleted transmit buffers. More...
 
static void vmxnet3_refill_rx (struct net_device *netdev)
 Refill receive ring. More...
 
static void vmxnet3_poll_rx (struct net_device *netdev)
 Poll for received packets. More...
 
static void vmxnet3_flush_rx (struct net_device *netdev)
 Flush any uncompleted receive buffers. More...
 
static void vmxnet3_check_link (struct net_device *netdev)
 Check link state. More...
 
static void vmxnet3_poll_events (struct net_device *netdev)
 Poll for events. More...
 
static void vmxnet3_poll (struct net_device *netdev)
 Poll network device. More...
 
static void vmxnet3_irq (struct net_device *netdev, int enable)
 Enable/disable interrupts. More...
 
static void vmxnet3_set_ll_addr (struct vmxnet3_nic *vmxnet, const void *ll_addr)
 Set MAC address. More...
 
static int vmxnet3_open (struct net_device *netdev)
 Open NIC. More...
 
static void vmxnet3_close (struct net_device *netdev)
 Close NIC. More...
 
static int vmxnet3_check_version (struct vmxnet3_nic *vmxnet)
 Check version. More...
 
static void vmxnet3_get_hw_addr (struct vmxnet3_nic *vmxnet, void *hw_addr)
 Get permanent MAC address. More...
 
static int vmxnet3_probe (struct pci_device *pci)
 Probe PCI device. More...
 
static void vmxnet3_remove (struct pci_device *pci)
 Remove PCI device. More...
 

Variables

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

Detailed Description

VMware vmxnet3 virtual NIC driver.

Definition in file vmxnet3.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ vmxnet3_command()

static uint32_t vmxnet3_command ( struct vmxnet3_nic vmxnet,
uint32_t  command 
)
inlinestatic

Issue command.

Parameters
vmxnetvmxnet3 NIC
commandCommand to issue
Return values
resultCommand result

Definition at line 71 of file vmxnet3.c.

72  {
74 
75  /* Issue command */
76  profile_start ( &vmxnet3_vm_command_profiler );
77  writel ( command, ( vmxnet->vd + VMXNET3_VD_CMD ) );
78  result = readl ( vmxnet->vd + VMXNET3_VD_CMD );
79  profile_stop ( &vmxnet3_vm_command_profiler );
80  profile_exclude ( &vmxnet3_vm_command_profiler );
81 
82  return result;
83 }
void * vd
"VD" register base address
Definition: vmxnet3.h:475
A command-line command.
Definition: command.h:9
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
unsigned int uint32_t
Definition: stdint.h:12
uint16_t result
Definition: hyperv.h:33
static void profile_exclude(struct profiler *profiler)
Exclude time from other ongoing profiling results.
Definition: profile.h:186
#define VMXNET3_VD_CMD
Command.
Definition: vmxnet3.h:87

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

Referenced by vmxnet3_check_link(), vmxnet3_close(), vmxnet3_open(), and vmxnet3_poll_events().

◆ vmxnet3_transmit()

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 92 of file vmxnet3.c.

93  {
94  struct vmxnet3_nic *vmxnet = netdev->priv;
95  struct vmxnet3_tx_desc *tx_desc;
96  unsigned int fill;
97  unsigned int desc_idx;
98  unsigned int generation;
99 
100  /* Check that we have a free transmit descriptor */
101  fill = ( vmxnet->count.tx_prod - vmxnet->count.tx_cons );
102  if ( fill >= VMXNET3_TX_FILL ) {
103  DBGC ( vmxnet, "VMXNET3 %p out of transmit descriptors\n",
104  vmxnet );
105  return -ENOBUFS;
106  }
107 
108  /* Locate transmit descriptor */
109  desc_idx = ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC );
110  generation = ( ( vmxnet->count.tx_prod & VMXNET3_NUM_TX_DESC ) ?
111  0 : cpu_to_le32 ( VMXNET3_TXF_GEN ) );
112  assert ( vmxnet->tx_iobuf[desc_idx] == NULL );
113 
114  /* Increment producer counter */
115  vmxnet->count.tx_prod++;
116 
117  /* Store I/O buffer for later completion */
118  vmxnet->tx_iobuf[desc_idx] = iobuf;
119 
120  /* Populate transmit descriptor */
121  tx_desc = &vmxnet->dma->tx_desc[desc_idx];
122  tx_desc->address = cpu_to_le64 ( virt_to_bus ( iobuf->data ) );
123  tx_desc->flags[0] = ( generation | cpu_to_le32 ( iob_len ( iobuf ) ) );
125 
126  /* Hand over descriptor to NIC */
127  wmb();
128  profile_start ( &vmxnet3_vm_tx_profiler );
129  writel ( ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC ),
130  ( vmxnet->pt + VMXNET3_PT_TXPROD ) );
131  profile_stop ( &vmxnet3_vm_tx_profiler );
132  profile_exclude ( &vmxnet3_vm_tx_profiler );
133 
134  return 0;
135 }
wmb()
Transmit descriptor.
Definition: vmxnet3.h:246
#define DBGC(...)
Definition: compiler.h:505
#define VMXNET3_TX_FILL
Transmit ring maximum fill level.
Definition: vmxnet3.h:497
#define VMXNET3_NUM_TX_DESC
Number of TX descriptors.
Definition: vmxnet3.h:421
unsigned int tx_prod
Transmit producer counter.
Definition: vmxnet3.h:459
#define cpu_to_le64(value)
Definition: byteswap.h:108
struct vmxnet3_dma * dma
DMA area.
Definition: vmxnet3.h:478
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * priv
Driver private data.
Definition: netdevice.h:431
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static struct net_device * netdev
Definition: gdbudp.c:52
struct io_buffer * tx_iobuf[VMXNET3_NUM_TX_DESC]
Transmit I/O buffers.
Definition: vmxnet3.h:482
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define VMXNET3_TXF_CQ
Transmit completion request flag.
Definition: vmxnet3.h:260
#define VMXNET3_TXF_GEN
Transmit generation flag.
Definition: vmxnet3.h:254
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
Definition: dmfe.c:137
void * pt
"PT" register base address
Definition: vmxnet3.h:473
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define VMXNET3_TXF_EOP
Transmit end-of-packet flag.
Definition: vmxnet3.h:257
void * data
Start of data.
Definition: iobuf.h:52
unsigned int tx_cons
Transmit completion consumer counter.
Definition: vmxnet3.h:461
static void profile_exclude(struct profiler *profiler)
Exclude time from other ongoing profiling results.
Definition: profile.h:186
struct vmxnet3_tx_desc tx_desc[VMXNET3_NUM_TX_DESC]
TX descriptor ring.
Definition: vmxnet3.h:440
struct vmxnet3_counters count
Producer and consumer counters.
Definition: vmxnet3.h:480
#define VMXNET3_PT_TXPROD
Transmit producer index.
Definition: vmxnet3.h:60
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static int fill
Definition: string.h:208
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References assert(), vmxnet3_nic::count, cpu_to_le32, cpu_to_le64, io_buffer::data, DBGC, vmxnet3_nic::dma, ENOBUFS, fill, iob_len(), netdev, NULL, net_device::priv, 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().

◆ vmxnet3_poll_tx()

static void vmxnet3_poll_tx ( struct net_device netdev)
static

Poll for completed transmissions.

Parameters
netdevNetwork device

Definition at line 142 of file vmxnet3.c.

142  {
143  struct vmxnet3_nic *vmxnet = netdev->priv;
144  struct vmxnet3_tx_comp *tx_comp;
145  struct io_buffer *iobuf;
146  unsigned int comp_idx;
147  unsigned int desc_idx;
148  unsigned int generation;
149 
150  while ( 1 ) {
151 
152  /* Look for completed descriptors */
153  comp_idx = ( vmxnet->count.tx_cons % VMXNET3_NUM_TX_COMP );
154  generation = ( ( vmxnet->count.tx_cons & VMXNET3_NUM_TX_COMP ) ?
155  0 : cpu_to_le32 ( VMXNET3_TXCF_GEN ) );
156  tx_comp = &vmxnet->dma->tx_comp[comp_idx];
157  if ( generation != ( tx_comp->flags &
158  cpu_to_le32 ( VMXNET3_TXCF_GEN ) ) ) {
159  break;
160  }
161 
162  /* Increment consumer counter */
163  vmxnet->count.tx_cons++;
164 
165  /* Locate corresponding transmit descriptor */
166  desc_idx = ( le32_to_cpu ( tx_comp->index ) %
168  iobuf = vmxnet->tx_iobuf[desc_idx];
169  if ( ! iobuf ) {
170  DBGC ( vmxnet, "VMXNET3 %p completed on empty transmit "
171  "buffer %#x/%#x\n", vmxnet, comp_idx, desc_idx );
173  continue;
174  }
175 
176  /* Remove I/O buffer from transmit queue */
177  vmxnet->tx_iobuf[desc_idx] = NULL;
178 
179  /* Report transmission completion to network layer */
180  DBGC2 ( vmxnet, "VMXNET3 %p completed TX %#x/%#x (len %#zx)\n",
181  vmxnet, comp_idx, desc_idx, iob_len ( iobuf ) );
182  netdev_tx_complete ( netdev, iobuf );
183  }
184 }
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:766
#define le32_to_cpu(value)
Definition: byteswap.h:113
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:440
#define DBGC(...)
Definition: compiler.h:505
#define VMXNET3_NUM_TX_DESC
Number of TX descriptors.
Definition: vmxnet3.h:421
struct vmxnet3_dma * dma
DMA area.
Definition: vmxnet3.h:478
uint32_t flags
Flags.
Definition: vmxnet3.h:269
uint32_t index
Index of the end-of-packet descriptor.
Definition: vmxnet3.h:265
#define VMXNET3_NUM_TX_COMP
Number of TX completion descriptors.
Definition: vmxnet3.h:424
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
struct io_buffer * tx_iobuf[VMXNET3_NUM_TX_DESC]
Transmit I/O buffers.
Definition: vmxnet3.h:482
#define cpu_to_le32(value)
Definition: byteswap.h:107
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
#define VMXNET3_TXCF_GEN
Transmit completion generation flag.
Definition: vmxnet3.h:273
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
unsigned int tx_cons
Transmit completion consumer counter.
Definition: vmxnet3.h:461
struct vmxnet3_tx_comp tx_comp[VMXNET3_NUM_TX_COMP]
TX completion ring.
Definition: vmxnet3.h:442
Transmit completion descriptor.
Definition: vmxnet3.h:263
struct vmxnet3_counters count
Producer and consumer counters.
Definition: vmxnet3.h:480
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A vmxnet3 NIC.
Definition: vmxnet3.h:471
A persistent I/O buffer.
Definition: iobuf.h:37

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, netdev_tx_complete(), netdev_tx_err(), NULL, net_device::priv, 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().

◆ vmxnet3_flush_tx()

static void vmxnet3_flush_tx ( struct net_device netdev)
static

Flush any uncompleted transmit buffers.

Parameters
netdevNetwork device

Definition at line 191 of file vmxnet3.c.

191  {
192  struct vmxnet3_nic *vmxnet = netdev->priv;
193  unsigned int i;
194 
195  for ( i = 0 ; i < VMXNET3_NUM_TX_DESC ; i++ ) {
196  if ( vmxnet->tx_iobuf[i] ) {
197  netdev_tx_complete_err ( netdev, vmxnet->tx_iobuf[i],
198  -ECANCELED );
199  vmxnet->tx_iobuf[i] = NULL;
200  }
201  }
202 }
#define VMXNET3_NUM_TX_DESC
Number of TX descriptors.
Definition: vmxnet3.h:421
#define ECANCELED
Operation canceled.
Definition: errno.h:343
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
struct io_buffer * tx_iobuf[VMXNET3_NUM_TX_DESC]
Transmit I/O buffers.
Definition: vmxnet3.h:482
void netdev_tx_complete_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Complete network transmission.
Definition: netdevice.c:470
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References ECANCELED, netdev, netdev_tx_complete_err(), NULL, net_device::priv, vmxnet3_nic::tx_iobuf, and VMXNET3_NUM_TX_DESC.

Referenced by vmxnet3_close(), and vmxnet3_open().

◆ vmxnet3_refill_rx()

static void vmxnet3_refill_rx ( struct net_device netdev)
static

Refill receive ring.

Parameters
netdevNetwork device

Definition at line 209 of file vmxnet3.c.

209  {
210  struct vmxnet3_nic *vmxnet = netdev->priv;
211  struct vmxnet3_rx_desc *rx_desc;
212  struct io_buffer *iobuf;
213  unsigned int orig_rx_prod = vmxnet->count.rx_prod;
214  unsigned int desc_idx;
215  unsigned int generation;
216 
217  /* Fill receive ring to specified fill level */
218  while ( vmxnet->count.rx_fill < VMXNET3_RX_FILL ) {
219 
220  /* Locate receive descriptor */
221  desc_idx = ( vmxnet->count.rx_prod % VMXNET3_NUM_RX_DESC );
222  generation = ( ( vmxnet->count.rx_prod & VMXNET3_NUM_RX_DESC ) ?
223  0 : cpu_to_le32 ( VMXNET3_RXF_GEN ) );
224  assert ( vmxnet->rx_iobuf[desc_idx] == NULL );
225 
226  /* Allocate I/O buffer */
227  iobuf = alloc_iob ( VMXNET3_MTU + NET_IP_ALIGN );
228  if ( ! iobuf ) {
229  /* Non-fatal low memory condition */
230  break;
231  }
232  iob_reserve ( iobuf, NET_IP_ALIGN );
233 
234  /* Increment producer counter and fill level */
235  vmxnet->count.rx_prod++;
236  vmxnet->count.rx_fill++;
237 
238  /* Store I/O buffer for later completion */
239  vmxnet->rx_iobuf[desc_idx] = iobuf;
240 
241  /* Populate receive descriptor */
242  rx_desc = &vmxnet->dma->rx_desc[desc_idx];
243  rx_desc->address = cpu_to_le64 ( virt_to_bus ( iobuf->data ) );
244  rx_desc->flags = ( generation | cpu_to_le32 ( VMXNET3_MTU ) );
245 
246  }
247 
248  /* Hand over any new descriptors to NIC */
249  if ( vmxnet->count.rx_prod != orig_rx_prod ) {
250  wmb();
251  profile_start ( &vmxnet3_vm_refill_profiler );
252  writel ( ( vmxnet->count.rx_prod % VMXNET3_NUM_RX_DESC ),
253  ( vmxnet->pt + VMXNET3_PT_RXPROD ) );
254  profile_stop ( &vmxnet3_vm_refill_profiler );
255  profile_exclude ( &vmxnet3_vm_refill_profiler );
256  }
257 }
#define NET_IP_ALIGN
Definition: atl1e.h:47
#define VMXNET3_RX_FILL
Receive ring maximum fill level.
Definition: vmxnet3.h:500
wmb()
Receive descriptor.
Definition: vmxnet3.h:315
#define VMXNET3_MTU
MTU size.
Definition: vmxnet3.h:494
unsigned int rx_fill
Receive fill level.
Definition: vmxnet3.h:465
#define cpu_to_le64(value)
Definition: byteswap.h:108
struct vmxnet3_dma * dma
DMA area.
Definition: vmxnet3.h:478
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:130
#define VMXNET3_PT_RXPROD
Rx producer index for ring 1.
Definition: vmxnet3.h:63
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * priv
Driver private data.
Definition: netdevice.h:431
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static struct net_device * netdev
Definition: gdbudp.c:52
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define VMXNET3_RXF_GEN
Receive generation flag.
Definition: vmxnet3.h:325
void * pt
"PT" register base address
Definition: vmxnet3.h:473
struct io_buffer * rx_iobuf[VMXNET3_NUM_RX_DESC]
Receive I/O buffers.
Definition: vmxnet3.h:484
#define iob_reserve(iobuf, len)
Definition: iobuf.h:71
struct vmxnet3_rx_desc rx_desc[VMXNET3_NUM_RX_DESC]
RX descriptor ring.
Definition: vmxnet3.h:444
unsigned int rx_prod
Receive producer counter.
Definition: vmxnet3.h:463
Definition: dmfe.c:143
void * data
Start of data.
Definition: iobuf.h:52
static void profile_exclude(struct profiler *profiler)
Exclude time from other ongoing profiling results.
Definition: profile.h:186
struct vmxnet3_counters count
Producer and consumer counters.
Definition: vmxnet3.h:480
#define VMXNET3_NUM_RX_DESC
Number of RX descriptors.
Definition: vmxnet3.h:427
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A vmxnet3 NIC.
Definition: vmxnet3.h:471
A persistent I/O buffer.
Definition: iobuf.h:37

References alloc_iob(), assert(), vmxnet3_nic::count, cpu_to_le32, cpu_to_le64, io_buffer::data, vmxnet3_nic::dma, iob_reserve, NET_IP_ALIGN, netdev, NULL, net_device::priv, 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().

◆ vmxnet3_poll_rx()

static void vmxnet3_poll_rx ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 264 of file vmxnet3.c.

264  {
265  struct vmxnet3_nic *vmxnet = netdev->priv;
266  struct vmxnet3_rx_comp *rx_comp;
267  struct io_buffer *iobuf;
268  unsigned int comp_idx;
269  unsigned int desc_idx;
270  unsigned int generation;
271  size_t len;
272 
273  while ( 1 ) {
274 
275  /* Look for completed descriptors */
276  comp_idx = ( vmxnet->count.rx_cons % VMXNET3_NUM_RX_COMP );
277  generation = ( ( vmxnet->count.rx_cons & VMXNET3_NUM_RX_COMP ) ?
278  0 : cpu_to_le32 ( VMXNET3_RXCF_GEN ) );
279  rx_comp = &vmxnet->dma->rx_comp[comp_idx];
280  if ( generation != ( rx_comp->flags &
281  cpu_to_le32 ( VMXNET3_RXCF_GEN ) ) ) {
282  break;
283  }
284 
285  /* Increment consumer counter */
286  vmxnet->count.rx_cons++;
287 
288  /* Locate corresponding receive descriptor */
289  desc_idx = ( le32_to_cpu ( rx_comp->index ) %
291  iobuf = vmxnet->rx_iobuf[desc_idx];
292  if ( ! iobuf ) {
293  DBGC ( vmxnet, "VMXNET3 %p completed on empty receive "
294  "buffer %#x/%#x\n", vmxnet, comp_idx, desc_idx );
296  continue;
297  }
298 
299  /* Remove I/O buffer from receive queue */
300  vmxnet->rx_iobuf[desc_idx] = NULL;
301  vmxnet->count.rx_fill--;
302 
303  /* Deliver packet to network layer */
304  len = ( le32_to_cpu ( rx_comp->len ) &
305  ( VMXNET3_MAX_PACKET_LEN - 1 ) );
306  DBGC2 ( vmxnet, "VMXNET3 %p completed RX %#x/%#x (len %#zx)\n",
307  vmxnet, comp_idx, desc_idx, len );
308  iob_put ( iobuf, len );
309  netdev_rx ( netdev, iobuf );
310  }
311 }
#define iob_put(iobuf, len)
Definition: iobuf.h:124
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define le32_to_cpu(value)
Definition: byteswap.h:113
struct vmxnet3_rx_comp rx_comp[VMXNET3_NUM_RX_COMP]
RX completion ring.
Definition: vmxnet3.h:446
#define DBGC(...)
Definition: compiler.h:505
unsigned int rx_fill
Receive fill level.
Definition: vmxnet3.h:465
struct vmxnet3_dma * dma
DMA area.
Definition: vmxnet3.h:478
#define VMXNET3_RXCF_GEN
Receive completion generation flag.
Definition: vmxnet3.h:340
void * priv
Driver private data.
Definition: netdevice.h:431
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define VMXNET3_MAX_PACKET_LEN
Maximum packet size.
Definition: vmxnet3.h:48
uint32_t flags
Flags.
Definition: vmxnet3.h:336
#define VMXNET3_NUM_RX_COMP
Number of RX completion descriptors.
Definition: vmxnet3.h:430
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
unsigned int rx_cons
Receive consumer counter.
Definition: vmxnet3.h:467
struct io_buffer * rx_iobuf[VMXNET3_NUM_RX_DESC]
Receive I/O buffers.
Definition: vmxnet3.h:484
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
uint32_t index
Descriptor index.
Definition: vmxnet3.h:330
struct vmxnet3_counters count
Producer and consumer counters.
Definition: vmxnet3.h:480
#define VMXNET3_NUM_RX_DESC
Number of RX descriptors.
Definition: vmxnet3.h:427
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A vmxnet3 NIC.
Definition: vmxnet3.h:471
uint32_t len
Length.
Definition: vmxnet3.h:334
Receive completion descriptor.
Definition: vmxnet3.h:328
A persistent I/O buffer.
Definition: iobuf.h:37

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, netdev_rx(), netdev_rx_err(), NULL, net_device::priv, 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().

◆ vmxnet3_flush_rx()

static void vmxnet3_flush_rx ( struct net_device netdev)
static

Flush any uncompleted receive buffers.

Parameters
netdevNetwork device

Definition at line 318 of file vmxnet3.c.

318  {
319  struct vmxnet3_nic *vmxnet = netdev->priv;
320  struct io_buffer *iobuf;
321  unsigned int i;
322 
323  for ( i = 0 ; i < VMXNET3_NUM_RX_DESC ; i++ ) {
324  if ( ( iobuf = vmxnet->rx_iobuf[i] ) != NULL ) {
325  netdev_rx_err ( netdev, iobuf, -ECANCELED );
326  vmxnet->rx_iobuf[i] = NULL;
327  }
328  }
329 }
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define ECANCELED
Operation canceled.
Definition: errno.h:343
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
struct io_buffer * rx_iobuf[VMXNET3_NUM_RX_DESC]
Receive I/O buffers.
Definition: vmxnet3.h:484
#define VMXNET3_NUM_RX_DESC
Number of RX descriptors.
Definition: vmxnet3.h:427
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A vmxnet3 NIC.
Definition: vmxnet3.h:471
A persistent I/O buffer.
Definition: iobuf.h:37

References ECANCELED, netdev, netdev_rx_err(), NULL, net_device::priv, vmxnet3_nic::rx_iobuf, and VMXNET3_NUM_RX_DESC.

Referenced by vmxnet3_close(), and vmxnet3_open().

◆ vmxnet3_check_link()

static void vmxnet3_check_link ( struct net_device netdev)
static

Check link state.

Parameters
netdevNetwork device

Definition at line 336 of file vmxnet3.c.

336  {
337  struct vmxnet3_nic *vmxnet = netdev->priv;
338  uint32_t state;
339  int link_up;
340  unsigned int link_speed;
341 
342  /* Get link state */
344  link_up = ( state & 1 );
345  link_speed = ( state >> 16 );
346 
347  /* Report link state to network device */
348  if ( link_up ) {
349  DBGC ( vmxnet, "VMXNET3 %p link is up at %d Mbps\n",
350  vmxnet, link_speed );
352  } else {
353  DBGC ( vmxnet, "VMXNET3 %p link is down\n", vmxnet );
355  }
356 }
static uint32_t vmxnet3_command(struct vmxnet3_nic *vmxnet, uint32_t command)
Issue command.
Definition: vmxnet3.c:71
uint8_t state
State.
Definition: eth_slow.h:47
#define DBGC(...)
Definition: compiler.h:505
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
void * priv
Driver private data.
Definition: netdevice.h:431
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:788
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned int uint32_t
Definition: stdint.h:12
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References DBGC, netdev, netdev_link_down(), netdev_link_up(), net_device::priv, state, VMXNET3_CMD_GET_LINK, and vmxnet3_command().

Referenced by vmxnet3_poll_events(), and vmxnet3_probe().

◆ vmxnet3_poll_events()

static void vmxnet3_poll_events ( struct net_device netdev)
static

Poll for events.

Parameters
netdevNetwork device

Definition at line 363 of file vmxnet3.c.

363  {
364  struct vmxnet3_nic *vmxnet = netdev->priv;
365  uint32_t events;
366 
367  /* Do nothing unless there are events to process */
368  if ( ! vmxnet->dma->shared.ecr )
369  return;
370  events = le32_to_cpu ( vmxnet->dma->shared.ecr );
371 
372  /* Acknowledge these events */
373  profile_start ( &vmxnet3_vm_event_profiler );
374  writel ( events, ( vmxnet->vd + VMXNET3_VD_ECR ) );
375  profile_stop ( &vmxnet3_vm_event_profiler );
376  profile_exclude ( &vmxnet3_vm_event_profiler );
377 
378  /* Check for link state change */
379  if ( events & VMXNET3_ECR_LINK ) {
381  events &= ~VMXNET3_ECR_LINK;
382  }
383 
384  /* Check for queue errors */
385  if ( events & ( VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR ) ) {
387  DBGC ( vmxnet, "VMXNET3 %p queue error status (TX %08x, RX "
388  "%08x)\n", vmxnet,
389  le32_to_cpu ( vmxnet->dma->queues.tx.status.error ),
390  le32_to_cpu ( vmxnet->dma->queues.rx.status.error ) );
391  /* Report errors to allow for visibility via "ifstat" */
392  if ( events & VMXNET3_ECR_TQERR )
394  if ( events & VMXNET3_ECR_RQERR )
396  events &= ~( VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR );
397  }
398 
399  /* Check for unknown events */
400  if ( events ) {
401  DBGC ( vmxnet, "VMXNET3 %p unknown events %08x\n",
402  vmxnet, events );
403  /* Report error to allow for visibility via "ifstat" */
405  }
406 }
static uint32_t vmxnet3_command(struct vmxnet3_nic *vmxnet, uint32_t command)
Issue command.
Definition: vmxnet3.c:71
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
void * vd
"VD" register base address
Definition: vmxnet3.h:475
#define le32_to_cpu(value)
Definition: byteswap.h:113
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:440
#define EPIPE
Broken pipe.
Definition: errno.h:619
#define DBGC(...)
Definition: compiler.h:505
struct vmxnet3_dma * dma
DMA area.
Definition: vmxnet3.h:478
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:173
void * priv
Driver private data.
Definition: netdevice.h:431
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static struct net_device * netdev
Definition: gdbudp.c:52
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:160
struct vmxnet3_queues queues
Queue descriptors.
Definition: vmxnet3.h:448
struct vmxnet3_queue_status status
Definition: vmxnet3.h:397
#define ENODEV
No such device.
Definition: errno.h:509
struct vmxnet3_queue_status status
Definition: vmxnet3.h:388
static void vmxnet3_check_link(struct net_device *netdev)
Check link state.
Definition: vmxnet3.c:336
unsigned int uint32_t
Definition: stdint.h:12
struct vmxnet3_rx_queue rx
Receive queue descriptor(s)
Definition: vmxnet3.h:411
#define VMXNET3_VD_ECR
Event Cause Register.
Definition: vmxnet3.h:99
struct vmxnet3_tx_queue tx
Transmit queue descriptor(s)
Definition: vmxnet3.h:409
static void profile_exclude(struct profiler *profiler)
Exclude time from other ongoing profiling results.
Definition: profile.h:186
struct vmxnet3_shared shared
Shared area.
Definition: vmxnet3.h:450
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint32_t ecr
Event notifications.
Definition: vmxnet3.h:234
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References DBGC, vmxnet3_nic::dma, vmxnet3_shared::ecr, ENODEV, EPIPE, vmxnet3_queue_status::error, le32_to_cpu, netdev, netdev_rx_err(), netdev_tx_err(), NULL, net_device::priv, 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_command(), VMXNET3_ECR_LINK, VMXNET3_ECR_RQERR, VMXNET3_ECR_TQERR, VMXNET3_VD_ECR, and writel().

Referenced by vmxnet3_poll().

◆ vmxnet3_poll()

static void vmxnet3_poll ( struct net_device netdev)
static

Poll network device.

Parameters
netdevNetwork device

Definition at line 413 of file vmxnet3.c.

413  {
414 
419 }
static void vmxnet3_poll_events(struct net_device *netdev)
Poll for events.
Definition: vmxnet3.c:363
static void vmxnet3_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: vmxnet3.c:264
static void vmxnet3_poll_tx(struct net_device *netdev)
Poll for completed transmissions.
Definition: vmxnet3.c:142
static struct net_device * netdev
Definition: gdbudp.c:52
static void vmxnet3_refill_rx(struct net_device *netdev)
Refill receive ring.
Definition: vmxnet3.c:209

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

◆ vmxnet3_irq()

static void vmxnet3_irq ( struct net_device netdev,
int  enable 
)
static

Enable/disable interrupts.

Parameters
netdevNetwork device
enableInterrupts should be enabled

Definition at line 427 of file vmxnet3.c.

427  {
428  struct vmxnet3_nic *vmxnet = netdev->priv;
429 
430  DBGC ( vmxnet, "VMXNET3 %p %s IRQ not implemented\n",
431  vmxnet, ( enable ? "enable" : "disable" ) );
432 }
#define DBGC(...)
Definition: compiler.h:505
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References DBGC, netdev, and net_device::priv.

◆ vmxnet3_set_ll_addr()

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 440 of file vmxnet3.c.

441  {
442  struct {
443  uint32_t low;
444  uint32_t high;
445  } __attribute__ (( packed )) mac;
446 
447  memset ( &mac, 0, sizeof ( mac ) );
448  memcpy ( &mac, ll_addr, ETH_ALEN );
449  writel ( cpu_to_le32 ( mac.low ), ( vmxnet->vd + VMXNET3_VD_MACL ) );
450  writel ( cpu_to_le32 ( mac.high ), ( vmxnet->vd + VMXNET3_VD_MACH ) );
451 }
#define __attribute__(x)
Definition: compiler.h:10
uint32_t low
Low 16 bits of address.
Definition: myson.h:19
void * vd
"VD" register base address
Definition: vmxnet3.h:475
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define VMXNET3_VD_MACL
MAC Address Low.
Definition: vmxnet3.h:90
#define cpu_to_le32(value)
Definition: byteswap.h:107
uint32_t high
High 32 bits of address.
Definition: myson.h:20
#define ETH_ALEN
Definition: if_ether.h:8
unsigned int uint32_t
Definition: stdint.h:12
#define VMXNET3_VD_MACH
MAC Address High.
Definition: vmxnet3.h:93
void * memset(void *dest, int character, size_t len) __nonnull

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().

◆ vmxnet3_open()

static int vmxnet3_open ( struct net_device netdev)
static

Open NIC.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 459 of file vmxnet3.c.

459  {
460  struct vmxnet3_nic *vmxnet = netdev->priv;
461  struct vmxnet3_shared *shared;
462  struct vmxnet3_queues *queues;
463  uint64_t shared_bus;
464  uint64_t queues_bus;
466  int rc;
467 
468  /* Allocate DMA areas */
469  vmxnet->dma = malloc_phys ( sizeof ( *vmxnet->dma ),
471  if ( ! vmxnet->dma ) {
472  DBGC ( vmxnet, "VMXNET3 %p could not allocate DMA area\n",
473  vmxnet );
474  rc = -ENOMEM;
475  goto err_alloc_dma;
476  }
477  memset ( vmxnet->dma, 0, sizeof ( *vmxnet->dma ) );
478 
479  /* Populate queue descriptors */
480  queues = &vmxnet->dma->queues;
481  queues->tx.cfg.desc_address =
482  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->tx_desc ) );
483  queues->tx.cfg.comp_address =
484  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->tx_comp ) );
485  queues->tx.cfg.num_desc = cpu_to_le32 ( VMXNET3_NUM_TX_DESC );
486  queues->tx.cfg.num_comp = cpu_to_le32 ( VMXNET3_NUM_TX_COMP );
487  queues->rx.cfg.desc_address[0] =
488  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->rx_desc ) );
489  queues->rx.cfg.comp_address =
490  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->rx_comp ) );
491  queues->rx.cfg.num_desc[0] = cpu_to_le32 ( VMXNET3_NUM_RX_DESC );
492  queues->rx.cfg.num_comp = cpu_to_le32 ( VMXNET3_NUM_RX_COMP );
493  queues_bus = virt_to_bus ( queues );
494  DBGC ( vmxnet, "VMXNET3 %p queue descriptors at %08llx+%zx\n",
495  vmxnet, queues_bus, sizeof ( *queues ) );
496 
497  /* Populate shared area */
498  shared = &vmxnet->dma->shared;
499  shared->magic = cpu_to_le32 ( VMXNET3_SHARED_MAGIC );
502  shared->misc.upt_version_support =
504  shared->misc.queue_desc_address = cpu_to_le64 ( queues_bus );
505  shared->misc.queue_desc_len = cpu_to_le32 ( sizeof ( *queues ) );
506  shared->misc.mtu = cpu_to_le32 ( VMXNET3_MTU );
507  shared->misc.num_tx_queues = 1;
508  shared->misc.num_rx_queues = 1;
509  shared->interrupt.num_intrs = 1;
514  shared_bus = virt_to_bus ( shared );
515  DBGC ( vmxnet, "VMXNET3 %p shared area at %08llx+%zx\n",
516  vmxnet, shared_bus, sizeof ( *shared ) );
517 
518  /* Zero counters */
519  memset ( &vmxnet->count, 0, sizeof ( vmxnet->count ) );
520 
521  /* Set MAC address */
522  vmxnet3_set_ll_addr ( vmxnet, &netdev->ll_addr );
523 
524  /* Pass shared area to device */
525  writel ( ( shared_bus >> 0 ), ( vmxnet->vd + VMXNET3_VD_DSAL ) );
526  writel ( ( shared_bus >> 32 ), ( vmxnet->vd + VMXNET3_VD_DSAH ) );
527 
528  /* Activate device */
529  if ( ( status = vmxnet3_command ( vmxnet,
530  VMXNET3_CMD_ACTIVATE_DEV ) ) != 0 ) {
531  DBGC ( vmxnet, "VMXNET3 %p could not activate (status %#x)\n",
532  vmxnet, status );
533  rc = -EIO;
534  goto err_activate;
535  }
536 
537  /* Fill receive ring */
539 
540  return 0;
541 
544  err_activate:
547  free_phys ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
548  err_alloc_dma:
549  return rc;
550 }
#define VMXNET3_DMA_ALIGN
DMA area alignment.
Definition: vmxnet3.h:454
Driver shared area.
Definition: vmxnet3.h:216
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static uint32_t vmxnet3_command(struct vmxnet3_nic *vmxnet, uint32_t command)
Issue command.
Definition: vmxnet3.c:71
#define VMXNET3_VD_DSAH
Driver Shared Address High.
Definition: vmxnet3.h:84
Broadcast only.
Definition: vmxnet3.h:203
void * vd
"VD" register base address
Definition: vmxnet3.h:475
uint32_t version_support
Version supported.
Definition: vmxnet3.h:144
struct vmxnet3_rx_comp rx_comp[VMXNET3_NUM_RX_COMP]
RX completion ring.
Definition: vmxnet3.h:446
Unicast only.
Definition: vmxnet3.h:201
#define VMXNET3_MTU
MTU size.
Definition: vmxnet3.h:494
uint8_t num_rx_queues
Number of RX queues.
Definition: vmxnet3.h:164
struct vmxnet3_interrupt_config interrupt
Interrupt configuration.
Definition: vmxnet3.h:224
#define DBGC(...)
Definition: compiler.h:505
#define VMXNET3_NUM_TX_DESC
Number of TX descriptors.
Definition: vmxnet3.h:421
unsigned long long uint64_t
Definition: stdint.h:13
#define cpu_to_le64(value)
Definition: byteswap.h:108
struct vmxnet3_dma * dma
DMA area.
Definition: vmxnet3.h:478
#define VMXNET3_VERSION_SELECT
vmxnet3 version that we support
Definition: vmxnet3.h:488
static void vmxnet3_flush_rx(struct net_device *netdev)
Flush any uncompleted receive buffers.
Definition: vmxnet3.c:318
#define ENOMEM
Not enough space.
Definition: errno.h:534
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
uint32_t upt_version_support
UPT version supported.
Definition: vmxnet3.h:146
uint32_t mtu
Maximum transmission unit.
Definition: vmxnet3.h:158
#define VMXNET3_NUM_TX_COMP
Number of TX completion descriptors.
Definition: vmxnet3.h:424
void * priv
Driver private data.
Definition: netdevice.h:431
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
uint64_t queue_desc_address
Queue descriptors data address.
Definition: vmxnet3.h:152
uint32_t queue_desc_len
Queue descriptors data length.
Definition: vmxnet3.h:156
static struct net_device * netdev
Definition: gdbudp.c:52
#define VMXNET3_UPT_VERSION_SELECT
UPT version that we support.
Definition: vmxnet3.h:491
All multicast.
Definition: vmxnet3.h:204
struct vmxnet3_queues queues
Queue descriptors.
Definition: vmxnet3.h:448
uint32_t mode
Receive filter mode.
Definition: vmxnet3.h:188
#define cpu_to_le32(value)
Definition: byteswap.h:107
static void vmxnet3_flush_tx(struct net_device *netdev)
Flush any uncompleted transmit buffers.
Definition: vmxnet3.c:191
vmxnet3_command
Commands.
Definition: vmxnet3.h:102
struct vmxnet3_rx_filter_config rx_filter
Receive filter configuration.
Definition: vmxnet3.h:226
#define VMXNET3_VERSION_MAGIC
Driver version magic.
Definition: vmxnet3.h:170
#define VMXNET3_IC_DISABLE_ALL
Interrupt control - disable all interrupts.
Definition: vmxnet3.h:183
static void vmxnet3_refill_rx(struct net_device *netdev)
Refill receive ring.
Definition: vmxnet3.c:209
unsigned int uint32_t
Definition: stdint.h:12
#define VMXNET3_NUM_RX_COMP
Number of RX completion descriptors.
Definition: vmxnet3.h:430
uint8_t status
Status.
Definition: ena.h:16
Queue descriptor set.
Definition: vmxnet3.h:407
struct vmxnet3_rx_desc rx_desc[VMXNET3_NUM_RX_DESC]
RX descriptor ring.
Definition: vmxnet3.h:444
struct vmxnet3_misc_config misc
Miscellaneous configuration.
Definition: vmxnet3.h:222
#define EIO
Input/output error.
Definition: errno.h:433
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:722
#define VMXNET3_SHARED_MAGIC
Driver shared area magic.
Definition: vmxnet3.h:243
uint8_t num_tx_queues
Number of TX queues.
Definition: vmxnet3.h:162
uint32_t queues
Maximum number of low latency queues.
Definition: ena.h:12
struct vmxnet3_tx_comp tx_comp[VMXNET3_NUM_TX_COMP]
TX completion ring.
Definition: vmxnet3.h:442
uint32_t magic
Magic signature.
Definition: vmxnet3.h:218
static void vmxnet3_set_ll_addr(struct vmxnet3_nic *vmxnet, const void *ll_addr)
Set MAC address.
Definition: vmxnet3.c:440
#define VMXNET3_VD_DSAL
Driver Shared Address Low.
Definition: vmxnet3.h:81
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
struct vmxnet3_tx_desc tx_desc[VMXNET3_NUM_TX_DESC]
TX descriptor ring.
Definition: vmxnet3.h:440
struct vmxnet3_counters count
Producer and consumer counters.
Definition: vmxnet3.h:480
#define VMXNET3_NUM_RX_DESC
Number of RX descriptors.
Definition: vmxnet3.h:427
struct vmxnet3_shared shared
Shared area.
Definition: vmxnet3.h:450
A vmxnet3 NIC.
Definition: vmxnet3.h:471
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.c:706
void * memset(void *dest, int character, size_t len) __nonnull
uint32_t version
Driver version.
Definition: vmxnet3.h:140

References vmxnet3_interrupt_config::control, vmxnet3_nic::count, cpu_to_le32, cpu_to_le64, DBGC, vmxnet3_nic::dma, EIO, ENOMEM, free_phys(), vmxnet3_shared::interrupt, net_device::ll_addr, vmxnet3_shared::magic, malloc_phys(), memset(), vmxnet3_shared::misc, vmxnet3_rx_filter_config::mode, vmxnet3_misc_config::mtu, netdev, vmxnet3_interrupt_config::num_intrs, vmxnet3_misc_config::num_rx_queues, vmxnet3_misc_config::num_tx_queues, net_device::priv, vmxnet3_misc_config::queue_desc_address, vmxnet3_misc_config::queue_desc_len, queues, vmxnet3_dma::queues, rc, vmxnet3_dma::rx_comp, vmxnet3_dma::rx_desc, vmxnet3_shared::rx_filter, vmxnet3_dma::shared, status, 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_command(), 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().

◆ vmxnet3_close()

static void vmxnet3_close ( struct net_device netdev)
static

Close NIC.

Parameters
netdevNetwork device

Definition at line 557 of file vmxnet3.c.

557  {
558  struct vmxnet3_nic *vmxnet = netdev->priv;
559 
564  free_phys ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
565 }
static uint32_t vmxnet3_command(struct vmxnet3_nic *vmxnet, uint32_t command)
Issue command.
Definition: vmxnet3.c:71
struct vmxnet3_dma * dma
DMA area.
Definition: vmxnet3.h:478
static void vmxnet3_flush_rx(struct net_device *netdev)
Flush any uncompleted receive buffers.
Definition: vmxnet3.c:318
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
static void vmxnet3_flush_tx(struct net_device *netdev)
Flush any uncompleted transmit buffers.
Definition: vmxnet3.c:191
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:722
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References vmxnet3_nic::dma, free_phys(), netdev, net_device::priv, VMXNET3_CMD_QUIESCE_DEV, VMXNET3_CMD_RESET_DEV, vmxnet3_command(), vmxnet3_flush_rx(), and vmxnet3_flush_tx().

◆ vmxnet3_check_version()

static int vmxnet3_check_version ( struct vmxnet3_nic vmxnet)
static

Check version.

Parameters
vmxnetvmxnet3 NIC
Return values
rcReturn status code

Definition at line 582 of file vmxnet3.c.

582  {
584  uint32_t upt_version;
585 
586  /* Read version */
587  version = readl ( vmxnet->vd + VMXNET3_VD_VRRS );
588  upt_version = readl ( vmxnet->vd + VMXNET3_VD_UVRS );
589  DBGC ( vmxnet, "VMXNET3 %p is version %d (UPT version %d)\n",
590  vmxnet, version, upt_version );
591 
592  /* Inform NIC of driver version */
593  writel ( VMXNET3_VERSION_SELECT, ( vmxnet->vd + VMXNET3_VD_VRRS ) );
595 
596  return 0;
597 }
void * vd
"VD" register base address
Definition: vmxnet3.h:475
#define VMXNET3_VD_VRRS
vmxnet3 Revision Report Selection
Definition: vmxnet3.h:75
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define VMXNET3_VERSION_SELECT
vmxnet3 version that we support
Definition: vmxnet3.h:488
u32 version
Driver version.
Definition: ath9k_hw.c:1983
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define VMXNET3_UPT_VERSION_SELECT
UPT version that we support.
Definition: vmxnet3.h:491
#define VMXNET3_VD_UVRS
UPT Version Report Selection.
Definition: vmxnet3.h:78
unsigned int uint32_t
Definition: stdint.h:12

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().

◆ vmxnet3_get_hw_addr()

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 605 of file vmxnet3.c.

605  {
606  struct {
607  uint32_t low;
608  uint32_t high;
609  } __attribute__ (( packed )) mac;
610 
611  mac.low = le32_to_cpu ( vmxnet3_command ( vmxnet,
613  mac.high = le32_to_cpu ( vmxnet3_command ( vmxnet,
615  memcpy ( hw_addr, &mac, ETH_ALEN );
616 }
#define __attribute__(x)
Definition: compiler.h:10
uint32_t low
Low 16 bits of address.
Definition: myson.h:19
#define le32_to_cpu(value)
Definition: byteswap.h:113
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint32_t high
High 32 bits of address.
Definition: myson.h:20
vmxnet3_command
Commands.
Definition: vmxnet3.h:102
#define ETH_ALEN
Definition: if_ether.h:8
unsigned int uint32_t
Definition: stdint.h:12

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().

◆ vmxnet3_probe()

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 625 of file vmxnet3.c.

625  {
626  struct net_device *netdev;
627  struct vmxnet3_nic *vmxnet;
628  int rc;
629 
630  /* Allocate network device */
631  netdev = alloc_etherdev ( sizeof ( *vmxnet ) );
632  if ( ! netdev ) {
633  rc = -ENOMEM;
634  goto err_alloc_etherdev;
635  }
637  vmxnet = netdev->priv;
638  pci_set_drvdata ( pci, netdev );
639  netdev->dev = &pci->dev;
640  memset ( vmxnet, 0, sizeof ( *vmxnet ) );
641 
642  /* Fix up PCI device */
643  adjust_pci_device ( pci );
644 
645  /* Map PCI BARs */
646  vmxnet->pt = pci_ioremap ( pci, pci_bar_start ( pci, VMXNET3_PT_BAR ),
647  VMXNET3_PT_LEN );
648  if ( ! vmxnet->pt ) {
649  rc = -ENODEV;
650  goto err_ioremap_pt;
651  }
652  vmxnet->vd = pci_ioremap ( pci, pci_bar_start ( pci, VMXNET3_VD_BAR ),
653  VMXNET3_VD_LEN );
654  if ( ! vmxnet->vd ) {
655  rc = -ENODEV;
656  goto err_ioremap_vd;
657  }
658 
659  /* Version check */
660  if ( ( rc = vmxnet3_check_version ( vmxnet ) ) != 0 )
661  goto err_check_version;
662 
663  /* Reset device */
664  if ( ( rc = vmxnet3_command ( vmxnet, VMXNET3_CMD_RESET_DEV ) ) != 0 )
665  goto err_reset;
666 
667  /* Read initial MAC address */
668  vmxnet3_get_hw_addr ( vmxnet, &netdev->hw_addr );
669 
670  /* Register network device */
671  if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
672  DBGC ( vmxnet, "VMXNET3 %p could not register net device: "
673  "%s\n", vmxnet, strerror ( rc ) );
674  goto err_register_netdev;
675  }
676 
677  /* Get initial link state */
679 
680  return 0;
681 
683  err_register_netdev:
684  err_reset:
685  err_check_version:
686  iounmap ( vmxnet->vd );
687  err_ioremap_vd:
688  iounmap ( vmxnet->pt );
689  err_ioremap_pt:
691  netdev_put ( netdev );
692  err_alloc_etherdev:
693  return rc;
694 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void * vd
"VD" register base address
Definition: vmxnet3.h:475
#define VMXNET3_PT_BAR
"PT" PCI BAR address
Definition: vmxnet3.h:51
#define VMXNET3_PT_LEN
"PT" PCI BAR size
Definition: vmxnet3.h:54
#define DBGC(...)
Definition: compiler.h:505
static int vmxnet3_check_version(struct vmxnet3_nic *vmxnet)
Check version.
Definition: vmxnet3.c:582
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:240
struct device dev
Generic device.
Definition: pci.h:212
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:518
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:365
#define ENOMEM
Not enough space.
Definition: errno.h:534
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
void * priv
Driver private data.
Definition: netdevice.h:431
static void vmxnet3_get_hw_addr(struct vmxnet3_nic *vmxnet, void *hw_addr)
Get permanent MAC address.
Definition: vmxnet3.c:605
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition: pci.c:96
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
vmxnet3_command
Commands.
Definition: vmxnet3.h:102
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
#define VMXNET3_VD_LEN
"VD" PCI BAR size
Definition: vmxnet3.h:72
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
static void vmxnet3_check_link(struct net_device *netdev)
Check link state.
Definition: vmxnet3.c:336
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
void * pt
"PT" register base address
Definition: vmxnet3.h:473
static struct net_device_operations vmxnet3_operations
vmxnet3 net device operations
Definition: vmxnet3.c:568
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
A vmxnet3 NIC.
Definition: vmxnet3.h:471
void * memset(void *dest, int character, size_t len) __nonnull
#define VMXNET3_VD_BAR
"VD" PCI BAR address
Definition: vmxnet3.h:69

References adjust_pci_device(), alloc_etherdev(), DBGC, pci_device::dev, net_device::dev, ENODEV, ENOMEM, net_device::hw_addr, iounmap(), memset(), netdev, netdev_init(), netdev_nullify(), netdev_put(), pci_bar_start(), pci_ioremap(), pci_set_drvdata(), net_device::priv, 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_operations, VMXNET3_PT_BAR, VMXNET3_PT_LEN, VMXNET3_VD_BAR, and VMXNET3_VD_LEN.

◆ vmxnet3_remove()

static void vmxnet3_remove ( struct pci_device pci)
static

Remove PCI device.

Parameters
pciPCI device

Definition at line 701 of file vmxnet3.c.

701  {
702  struct net_device *netdev = pci_get_drvdata ( pci );
703  struct vmxnet3_nic *vmxnet = netdev->priv;
704 
706  iounmap ( vmxnet->vd );
707  iounmap ( vmxnet->pt );
709  netdev_put ( netdev );
710 }
void * vd
"VD" register base address
Definition: vmxnet3.h:475
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
void * priv
Driver private data.
Definition: netdevice.h:431
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
void * pt
"PT" register base address
Definition: vmxnet3.h:473
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:375
void iounmap(volatile const void *io_addr)
Unmap I/O address.
A vmxnet3 NIC.
Definition: vmxnet3.h:471

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

Variable Documentation

◆ __profiler

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 49 of file vmxnet3.c.

◆ vmxnet3_operations

struct net_device_operations vmxnet3_operations
static
Initial value:
= {
.open = vmxnet3_open,
.close = vmxnet3_close,
.transmit = vmxnet3_transmit,
.poll = vmxnet3_poll,
.irq = vmxnet3_irq,
}
static int vmxnet3_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: vmxnet3.c:92
static void vmxnet3_poll(struct net_device *netdev)
Poll network device.
Definition: vmxnet3.c:413
static int vmxnet3_open(struct net_device *netdev)
Open NIC.
Definition: vmxnet3.c:459
static void vmxnet3_irq(struct net_device *netdev, int enable)
Enable/disable interrupts.
Definition: vmxnet3.c:427
static void vmxnet3_close(struct net_device *netdev)
Close NIC.
Definition: vmxnet3.c:557

vmxnet3 net device operations

Definition at line 568 of file vmxnet3.c.

Referenced by vmxnet3_probe().

◆ vmxnet3_nics

struct pci_device_id vmxnet3_nics[]
static
Initial value:
= {
PCI_ROM ( 0x15ad, 0x07b0, "vmxnet3", "vmxnet3 virtual NIC", 0 ),
}
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:307

vmxnet3 PCI IDs

Definition at line 713 of file vmxnet3.c.

◆ __pci_driver

struct pci_driver vmxnet3_driver __pci_driver
Initial value:
= {
.ids = vmxnet3_nics,
.id_count = ( sizeof ( vmxnet3_nics ) / sizeof ( vmxnet3_nics[0] ) ),
.probe = vmxnet3_probe,
}
static struct pci_device_id vmxnet3_nics[]
vmxnet3 PCI IDs
Definition: vmxnet3.c:713
static int vmxnet3_probe(struct pci_device *pci)
Probe PCI device.
Definition: vmxnet3.c:625
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
static void vmxnet3_remove(struct pci_device *pci)
Remove PCI device.
Definition: vmxnet3.c:701

vmxnet3 PCI driver

Definition at line 718 of file vmxnet3.c.