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

71  {
73 
74  /* Issue command */
75  profile_start ( &vmxnet3_vm_command_profiler );
76  writel ( command, ( vmxnet->vd + VMXNET3_VD_CMD ) );
77  result = readl ( vmxnet->vd + VMXNET3_VD_CMD );
78  profile_stop ( &vmxnet3_vm_command_profiler );
79  profile_exclude ( &vmxnet3_vm_command_profiler );
80 
81  return result;
82 }
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:171
int result
Definition: bigint.h:148
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:158
unsigned int uint32_t
Definition: stdint.h:12
static void profile_exclude(struct profiler *profiler)
Exclude time from other ongoing profiling results.
Definition: profile.h:184
#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 91 of file vmxnet3.c.

92  {
93  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
94  struct vmxnet3_tx_desc *tx_desc;
95  unsigned int fill;
96  unsigned int desc_idx;
97  unsigned int generation;
98 
99  /* Check that we have a free transmit descriptor */
100  fill = ( vmxnet->count.tx_prod - vmxnet->count.tx_cons );
101  if ( fill >= VMXNET3_TX_FILL ) {
102  DBGC ( vmxnet, "VMXNET3 %p out of transmit descriptors\n",
103  vmxnet );
104  return -ENOBUFS;
105  }
106 
107  /* Locate transmit descriptor */
108  desc_idx = ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC );
109  generation = ( ( vmxnet->count.tx_prod & VMXNET3_NUM_TX_DESC ) ?
110  0 : cpu_to_le32 ( VMXNET3_TXF_GEN ) );
111  assert ( vmxnet->tx_iobuf[desc_idx] == NULL );
112 
113  /* Increment producer counter */
114  vmxnet->count.tx_prod++;
115 
116  /* Store I/O buffer for later completion */
117  vmxnet->tx_iobuf[desc_idx] = iobuf;
118 
119  /* Populate transmit descriptor */
120  tx_desc = &vmxnet->dma->tx_desc[desc_idx];
121  tx_desc->address = cpu_to_le64 ( virt_to_bus ( iobuf->data ) );
122  tx_desc->flags[0] = ( generation | cpu_to_le32 ( iob_len ( iobuf ) ) );
124 
125  /* Hand over descriptor to NIC */
126  wmb();
127  profile_start ( &vmxnet3_vm_tx_profiler );
128  writel ( ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC ),
129  ( vmxnet->pt + VMXNET3_PT_TXPROD ) );
130  profile_stop ( &vmxnet3_vm_tx_profiler );
131  profile_exclude ( &vmxnet3_vm_tx_profiler );
132 
133  return 0;
134 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
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:171
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 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:158
#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:151
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:44
uint8_t fill
Length pair.
Definition: deflate.h:12
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:184
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:362
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, 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().

◆ vmxnet3_poll_tx()

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.

141  {
142  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
143  struct vmxnet3_tx_comp *tx_comp;
144  struct io_buffer *iobuf;
145  unsigned int comp_idx;
146  unsigned int desc_idx;
147  unsigned int generation;
148 
149  while ( 1 ) {
150 
151  /* Look for completed descriptors */
152  comp_idx = ( vmxnet->count.tx_cons % VMXNET3_NUM_TX_COMP );
153  generation = ( ( vmxnet->count.tx_cons & VMXNET3_NUM_TX_COMP ) ?
154  0 : cpu_to_le32 ( VMXNET3_TXCF_GEN ) );
155  tx_comp = &vmxnet->dma->tx_comp[comp_idx];
156  if ( generation != ( tx_comp->flags &
157  cpu_to_le32 ( VMXNET3_TXCF_GEN ) ) ) {
158  break;
159  }
160 
161  /* Increment consumer counter */
162  vmxnet->count.tx_cons++;
163 
164  /* Locate corresponding transmit descriptor */
165  desc_idx = ( le32_to_cpu ( tx_comp->index ) %
167  iobuf = vmxnet->tx_iobuf[desc_idx];
168  if ( ! iobuf ) {
169  DBGC ( vmxnet, "VMXNET3 %p completed on empty transmit "
170  "buffer %#x/%#x\n", vmxnet, comp_idx, desc_idx );
172  continue;
173  }
174 
175  /* Remove I/O buffer from transmit queue */
176  vmxnet->tx_iobuf[desc_idx] = NULL;
177 
178  /* Report transmission completion to network layer */
179  DBGC2 ( vmxnet, "VMXNET3 %p completed TX %#x/%#x (len %#zx)\n",
180  vmxnet, comp_idx, desc_idx, iob_len ( iobuf ) );
181  netdev_tx_complete ( netdev, iobuf );
182  }
183 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
static void netdev_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:746
#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:369
#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
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:151
#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:362
A vmxnet3 NIC.
Definition: vmxnet3.h:471
A persistent I/O buffer.
Definition: iobuf.h:32

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

◆ vmxnet3_flush_tx()

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.

190  {
191  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
192  unsigned int i;
193 
194  for ( i = 0 ; i < VMXNET3_NUM_TX_DESC ; i++ ) {
195  if ( vmxnet->tx_iobuf[i] ) {
196  netdev_tx_complete_err ( netdev, vmxnet->tx_iobuf[i],
197  -ECANCELED );
198  vmxnet->tx_iobuf[i] = NULL;
199  }
200  }
201 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
#define VMXNET3_NUM_TX_DESC
Number of TX descriptors.
Definition: vmxnet3.h:421
#define ECANCELED
Operation canceled.
Definition: errno.h:343
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:395
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References ECANCELED, netdev, netdev_priv(), netdev_tx_complete_err(), NULL, 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 208 of file vmxnet3.c.

208  {
209  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
210  struct vmxnet3_rx_desc *rx_desc;
211  struct io_buffer *iobuf;
212  unsigned int orig_rx_prod = vmxnet->count.rx_prod;
213  unsigned int desc_idx;
214  unsigned int generation;
215 
216  /* Fill receive ring to specified fill level */
217  while ( vmxnet->count.rx_fill < VMXNET3_RX_FILL ) {
218 
219  /* Locate receive descriptor */
220  desc_idx = ( vmxnet->count.rx_prod % VMXNET3_NUM_RX_DESC );
221  generation = ( ( vmxnet->count.rx_prod & VMXNET3_NUM_RX_DESC ) ?
222  0 : cpu_to_le32 ( VMXNET3_RXF_GEN ) );
223  assert ( vmxnet->rx_iobuf[desc_idx] == NULL );
224 
225  /* Allocate I/O buffer */
226  iobuf = alloc_iob ( VMXNET3_MTU + NET_IP_ALIGN );
227  if ( ! iobuf ) {
228  /* Non-fatal low memory condition */
229  break;
230  }
231  iob_reserve ( iobuf, NET_IP_ALIGN );
232 
233  /* Increment producer counter and fill level */
234  vmxnet->count.rx_prod++;
235  vmxnet->count.rx_fill++;
236 
237  /* Store I/O buffer for later completion */
238  vmxnet->rx_iobuf[desc_idx] = iobuf;
239 
240  /* Populate receive descriptor */
241  rx_desc = &vmxnet->dma->rx_desc[desc_idx];
242  rx_desc->address = cpu_to_le64 ( virt_to_bus ( iobuf->data ) );
243  rx_desc->flags = ( generation | cpu_to_le32 ( VMXNET3_MTU ) );
244 
245  }
246 
247  /* Hand over any new descriptors to NIC */
248  if ( vmxnet->count.rx_prod != orig_rx_prod ) {
249  wmb();
250  profile_start ( &vmxnet3_vm_refill_profiler );
251  writel ( ( vmxnet->count.rx_prod % VMXNET3_NUM_RX_DESC ),
252  ( vmxnet->pt + VMXNET3_PT_RXPROD ) );
253  profile_stop ( &vmxnet3_vm_refill_profiler );
254  profile_exclude ( &vmxnet3_vm_refill_profiler );
255  }
256 }
#define NET_IP_ALIGN
Definition: atl1e.h:47
#define VMXNET3_RX_FILL
Receive ring maximum fill level.
Definition: vmxnet3.h:500
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
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:171
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#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 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:158
#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:63
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:44
static void profile_exclude(struct profiler *profiler)
Exclude time from other ongoing profiling results.
Definition: profile.h:184
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:362
A vmxnet3 NIC.
Definition: vmxnet3.h:471
A persistent I/O buffer.
Definition: iobuf.h:32

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

◆ vmxnet3_poll_rx()

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.

263  {
264  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
265  struct vmxnet3_rx_comp *rx_comp;
266  struct io_buffer *iobuf;
267  unsigned int comp_idx;
268  unsigned int desc_idx;
269  unsigned int generation;
270  size_t len;
271 
272  while ( 1 ) {
273 
274  /* Look for completed descriptors */
275  comp_idx = ( vmxnet->count.rx_cons % VMXNET3_NUM_RX_COMP );
276  generation = ( ( vmxnet->count.rx_cons & VMXNET3_NUM_RX_COMP ) ?
277  0 : cpu_to_le32 ( VMXNET3_RXCF_GEN ) );
278  rx_comp = &vmxnet->dma->rx_comp[comp_idx];
279  if ( generation != ( rx_comp->flags &
280  cpu_to_le32 ( VMXNET3_RXCF_GEN ) ) ) {
281  break;
282  }
283 
284  /* Increment consumer counter */
285  vmxnet->count.rx_cons++;
286 
287  /* Locate corresponding receive descriptor */
288  desc_idx = ( le32_to_cpu ( rx_comp->index ) %
290  iobuf = vmxnet->rx_iobuf[desc_idx];
291  if ( ! iobuf ) {
292  DBGC ( vmxnet, "VMXNET3 %p completed on empty receive "
293  "buffer %#x/%#x\n", vmxnet, comp_idx, desc_idx );
295  continue;
296  }
297 
298  /* Remove I/O buffer from receive queue */
299  vmxnet->rx_iobuf[desc_idx] = NULL;
300  vmxnet->count.rx_fill--;
301 
302  /* Deliver packet to network layer */
303  len = ( le32_to_cpu ( rx_comp->len ) &
304  ( VMXNET3_MAX_PACKET_LEN - 1 ) );
305  DBGC2 ( vmxnet, "VMXNET3 %p completed RX %#x/%#x (len %#zx)\n",
306  vmxnet, comp_idx, desc_idx, len );
307  iob_put ( iobuf, len );
308  netdev_rx ( netdev, iobuf );
309  }
310 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
#define iob_put(iobuf, len)
Definition: iobuf.h:116
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
#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
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:470
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
uint32_t len
Length.
Definition: ena.h:14
#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:362
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:32

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

◆ vmxnet3_flush_rx()

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.

317  {
318  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
319  struct io_buffer *iobuf;
320  unsigned int i;
321 
322  for ( i = 0 ; i < VMXNET3_NUM_RX_DESC ; i++ ) {
323  if ( ( iobuf = vmxnet->rx_iobuf[i] ) != NULL ) {
324  netdev_rx_err ( netdev, iobuf, -ECANCELED );
325  vmxnet->rx_iobuf[i] = NULL;
326  }
327  }
328 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
#define ECANCELED
Operation canceled.
Definition: errno.h:343
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:362
A vmxnet3 NIC.
Definition: vmxnet3.h:471
A persistent I/O buffer.
Definition: iobuf.h:32

References ECANCELED, netdev, netdev_priv(), netdev_rx_err(), NULL, 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 335 of file vmxnet3.c.

335  {
336  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
337  uint32_t state;
338  int link_up;
339  unsigned int link_speed;
340 
341  /* Get link state */
343  link_up = ( state & 1 );
344  link_speed = ( state >> 16 );
345 
346  /* Report link state to network device */
347  if ( link_up ) {
348  DBGC ( vmxnet, "VMXNET3 %p link is up at %d Mbps\n",
349  vmxnet, link_speed );
351  } else {
352  DBGC ( vmxnet, "VMXNET3 %p link is down\n", vmxnet );
354  }
355 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
static uint32_t vmxnet3_command(struct vmxnet3_nic *vmxnet, uint32_t command)
Issue command.
Definition: vmxnet3.c:70
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:186
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
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(), netdev_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 362 of file vmxnet3.c.

362  {
363  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
364  uint32_t events;
365 
366  /* Do nothing unless there are events to process */
367  if ( ! vmxnet->dma->shared.ecr )
368  return;
369  events = le32_to_cpu ( vmxnet->dma->shared.ecr );
370 
371  /* Acknowledge these events */
372  profile_start ( &vmxnet3_vm_event_profiler );
373  writel ( events, ( vmxnet->vd + VMXNET3_VD_ECR ) );
374  profile_stop ( &vmxnet3_vm_event_profiler );
375  profile_exclude ( &vmxnet3_vm_event_profiler );
376 
377  /* Check for link state change */
378  if ( events & VMXNET3_ECR_LINK ) {
380  events &= ~VMXNET3_ECR_LINK;
381  }
382 
383  /* Check for queue errors */
384  if ( events & ( VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR ) ) {
386  DBGC ( vmxnet, "VMXNET3 %p queue error status (TX %08x, RX "
387  "%08x)\n", vmxnet,
388  le32_to_cpu ( vmxnet->dma->queues.tx.status.error ),
389  le32_to_cpu ( vmxnet->dma->queues.rx.status.error ) );
390  /* Report errors to allow for visibility via "ifstat" */
391  if ( events & VMXNET3_ECR_TQERR )
393  if ( events & VMXNET3_ECR_RQERR )
395  events &= ~( VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR );
396  }
397 
398  /* Check for unknown events */
399  if ( events ) {
400  DBGC ( vmxnet, "VMXNET3 %p unknown events %08x\n",
401  vmxnet, events );
402  /* Report error to allow for visibility via "ifstat" */
404  }
405 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
static uint32_t vmxnet3_command(struct vmxnet3_nic *vmxnet, uint32_t command)
Issue command.
Definition: vmxnet3.c:70
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
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:369
#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:171
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:158
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:335
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:184
struct vmxnet3_shared shared
Shared area.
Definition: vmxnet3.h:450
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
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_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_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 412 of file vmxnet3.c.

412  {
413 
418 }
static void vmxnet3_poll_events(struct net_device *netdev)
Poll for events.
Definition: vmxnet3.c:362
static void vmxnet3_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: vmxnet3.c:263
static void vmxnet3_poll_tx(struct net_device *netdev)
Poll for completed transmissions.
Definition: vmxnet3.c:141
static struct net_device * netdev
Definition: gdbudp.c:52
static void vmxnet3_refill_rx(struct net_device *netdev)
Refill receive ring.
Definition: vmxnet3.c:208

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

426  {
427  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
428 
429  DBGC ( vmxnet, "VMXNET3 %p %s IRQ not implemented\n",
430  vmxnet, ( enable ? "enable" : "disable" ) );
431 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
#define DBGC(...)
Definition: compiler.h:505
static struct net_device * netdev
Definition: gdbudp.c:52
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References DBGC, netdev, and netdev_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 439 of file vmxnet3.c.

440  {
441  struct {
442  uint32_t low;
443  uint32_t high;
444  } __attribute__ (( packed )) mac;
445 
446  memset ( &mac, 0, sizeof ( mac ) );
447  memcpy ( &mac, ll_addr, ETH_ALEN );
448  writel ( cpu_to_le32 ( mac.low ), ( vmxnet->vd + VMXNET3_VD_MACL ) );
449  writel ( cpu_to_le32 ( mac.high ), ( vmxnet->vd + VMXNET3_VD_MACH ) );
450 }
#define __attribute__(x)
Definition: compiler.h:10
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
uint32_t low
Low 16 bits of address.
Definition: intel.h:21
#define cpu_to_le32(value)
Definition: byteswap.h:107
#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
uint32_t high
High 32 bits of address.
Definition: intel.h:22
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 458 of file vmxnet3.c.

458  {
459  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
460  struct vmxnet3_shared *shared;
461  struct vmxnet3_queues *queues;
462  uint64_t shared_bus;
463  uint64_t queues_bus;
465  int rc;
466 
467  /* Allocate DMA areas */
468  vmxnet->dma = malloc_dma ( sizeof ( *vmxnet->dma ), VMXNET3_DMA_ALIGN );
469  if ( ! vmxnet->dma ) {
470  DBGC ( vmxnet, "VMXNET3 %p could not allocate DMA area\n",
471  vmxnet );
472  rc = -ENOMEM;
473  goto err_alloc_dma;
474  }
475  memset ( vmxnet->dma, 0, sizeof ( *vmxnet->dma ) );
476 
477  /* Populate queue descriptors */
478  queues = &vmxnet->dma->queues;
479  queues->tx.cfg.desc_address =
480  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->tx_desc ) );
481  queues->tx.cfg.comp_address =
482  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->tx_comp ) );
485  queues->rx.cfg.desc_address[0] =
486  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->rx_desc ) );
487  queues->rx.cfg.comp_address =
488  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->rx_comp ) );
489  queues->rx.cfg.num_desc[0] = cpu_to_le32 ( VMXNET3_NUM_RX_DESC );
491  queues_bus = virt_to_bus ( queues );
492  DBGC ( vmxnet, "VMXNET3 %p queue descriptors at %08llx+%zx\n",
493  vmxnet, queues_bus, sizeof ( *queues ) );
494 
495  /* Populate shared area */
496  shared = &vmxnet->dma->shared;
497  shared->magic = cpu_to_le32 ( VMXNET3_SHARED_MAGIC );
500  shared->misc.upt_version_support =
502  shared->misc.queue_desc_address = cpu_to_le64 ( queues_bus );
503  shared->misc.queue_desc_len = cpu_to_le32 ( sizeof ( *queues ) );
504  shared->misc.mtu = cpu_to_le32 ( VMXNET3_MTU );
505  shared->misc.num_tx_queues = 1;
506  shared->misc.num_rx_queues = 1;
507  shared->interrupt.num_intrs = 1;
512  shared_bus = virt_to_bus ( shared );
513  DBGC ( vmxnet, "VMXNET3 %p shared area at %08llx+%zx\n",
514  vmxnet, shared_bus, sizeof ( *shared ) );
515 
516  /* Zero counters */
517  memset ( &vmxnet->count, 0, sizeof ( vmxnet->count ) );
518 
519  /* Set MAC address */
520  vmxnet3_set_ll_addr ( vmxnet, &netdev->ll_addr );
521 
522  /* Pass shared area to device */
523  writel ( ( shared_bus >> 0 ), ( vmxnet->vd + VMXNET3_VD_DSAL ) );
524  writel ( ( shared_bus >> 32 ), ( vmxnet->vd + VMXNET3_VD_DSAH ) );
525 
526  /* Activate device */
527  if ( ( status = vmxnet3_command ( vmxnet,
528  VMXNET3_CMD_ACTIVATE_DEV ) ) != 0 ) {
529  DBGC ( vmxnet, "VMXNET3 %p could not activate (status %#x)\n",
530  vmxnet, status );
531  rc = -EIO;
532  goto err_activate;
533  }
534 
535  /* Fill receive ring */
537 
538  return 0;
539 
542  err_activate:
545  free_dma ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
546  err_alloc_dma:
547  return rc;
548 }
struct vmxnet3_tx_queue_config cfg
Definition: vmxnet3.h:387
struct vmxnet3_rx_queue_config cfg
Definition: vmxnet3.h:396
#define VMXNET3_DMA_ALIGN
DMA area alignment.
Definition: vmxnet3.h:454
Driver shared area.
Definition: vmxnet3.h:216
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
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:70
#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
uint64_t desc_address
Descriptor ring address.
Definition: vmxnet3.h:285
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:317
uint32_t num_desc
Number of descriptors.
Definition: vmxnet3.h:295
uint8_t status
Status.
Definition: ena.h:16
#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 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 num_desc[2]
Number of descriptors.
Definition: vmxnet3.h:360
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:190
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
uint32_t num_comp
Number of completion descriptors.
Definition: vmxnet3.h:299
static void vmxnet3_refill_rx(struct net_device *netdev)
Refill receive ring.
Definition: vmxnet3.c:208
uint64_t comp_address
Completion ring address.
Definition: vmxnet3.h:289
unsigned int uint32_t
Definition: stdint.h:12
#define VMXNET3_NUM_RX_COMP
Number of RX completion descriptors.
Definition: vmxnet3.h:430
struct vmxnet3_rx_queue rx
Receive queue descriptor(s)
Definition: vmxnet3.h:411
uint64_t desc_address[2]
Descriptor ring addresses.
Definition: vmxnet3.h:352
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_tx_queue tx
Transmit queue descriptor(s)
Definition: vmxnet3.h:409
struct vmxnet3_misc_config misc
Miscellaneous configuration.
Definition: vmxnet3.h:222
#define EIO
Input/output error.
Definition: errno.h:433
#define VMXNET3_SHARED_MAGIC
Driver shared area magic.
Definition: vmxnet3.h:243
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
uint8_t num_tx_queues
Number of TX queues.
Definition: vmxnet3.h:162
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:439
#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:381
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
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
struct vmxnet3_shared shared
Shared area.
Definition: vmxnet3.h:450
A vmxnet3 NIC.
Definition: vmxnet3.h:471
uint32_t num_comp
Number of completion descriptors.
Definition: vmxnet3.h:362
void * memset(void *dest, int character, size_t len) __nonnull
uint32_t version
Driver version.
Definition: vmxnet3.h:140
uint64_t comp_address
Completion ring address.
Definition: vmxnet3.h:354

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, 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_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 555 of file vmxnet3.c.

555  {
556  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
557 
562  free_dma ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
563 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
static uint32_t vmxnet3_command(struct vmxnet3_nic *vmxnet, uint32_t command)
Issue command.
Definition: vmxnet3.c:70
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:317
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:190
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References vmxnet3_nic::dma, free_dma(), netdev, netdev_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 580 of file vmxnet3.c.

580  {
582  uint32_t upt_version;
583 
584  /* Read version */
585  version = readl ( vmxnet->vd + VMXNET3_VD_VRRS );
586  upt_version = readl ( vmxnet->vd + VMXNET3_VD_UVRS );
587  DBGC ( vmxnet, "VMXNET3 %p is version %d (UPT version %d)\n",
588  vmxnet, version, upt_version );
589 
590  /* Inform NIC of driver version */
591  writel ( VMXNET3_VERSION_SELECT, ( vmxnet->vd + VMXNET3_VD_VRRS ) );
593 
594  return 0;
595 }
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
Version number.
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 603 of file vmxnet3.c.

603  {
604  struct {
605  uint32_t low;
606  uint32_t high;
607  } __attribute__ (( packed )) mac;
608 
609  mac.low = le32_to_cpu ( vmxnet3_command ( vmxnet,
611  mac.high = le32_to_cpu ( vmxnet3_command ( vmxnet,
613  memcpy ( hw_addr, &mac, ETH_ALEN );
614 }
#define __attribute__(x)
Definition: compiler.h:10
#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 low
Low 16 bits of address.
Definition: intel.h:21
vmxnet3_command
Commands.
Definition: vmxnet3.h:102
#define ETH_ALEN
Definition: if_ether.h:8
unsigned int uint32_t
Definition: stdint.h:12
uint32_t high
High 32 bits of address.
Definition: intel.h:22

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

623  {
624  struct net_device *netdev;
625  struct vmxnet3_nic *vmxnet;
626  int rc;
627 
628  /* Allocate network device */
629  netdev = alloc_etherdev ( sizeof ( *vmxnet ) );
630  if ( ! netdev ) {
631  rc = -ENOMEM;
632  goto err_alloc_etherdev;
633  }
635  vmxnet = netdev_priv ( netdev );
636  pci_set_drvdata ( pci, netdev );
637  netdev->dev = &pci->dev;
638  memset ( vmxnet, 0, sizeof ( *vmxnet ) );
639 
640  /* Fix up PCI device */
641  adjust_pci_device ( pci );
642 
643  /* Map PCI BARs */
644  vmxnet->pt = ioremap ( pci_bar_start ( pci, VMXNET3_PT_BAR ),
645  VMXNET3_PT_LEN );
646  if ( ! vmxnet->pt ) {
647  rc = -ENODEV;
648  goto err_ioremap_pt;
649  }
650  vmxnet->vd = ioremap ( pci_bar_start ( pci, VMXNET3_VD_BAR ),
651  VMXNET3_VD_LEN );
652  if ( ! vmxnet->vd ) {
653  rc = -ENODEV;
654  goto err_ioremap_vd;
655  }
656 
657  /* Version check */
658  if ( ( rc = vmxnet3_check_version ( vmxnet ) ) != 0 )
659  goto err_check_version;
660 
661  /* Reset device */
662  if ( ( rc = vmxnet3_command ( vmxnet, VMXNET3_CMD_RESET_DEV ) ) != 0 )
663  goto err_reset;
664 
665  /* Read initial MAC address */
666  vmxnet3_get_hw_addr ( vmxnet, &netdev->hw_addr );
667 
668  /* Register network device */
669  if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
670  DBGC ( vmxnet, "VMXNET3 %p could not register net device: "
671  "%s\n", vmxnet, strerror ( rc ) );
672  goto err_register_netdev;
673  }
674 
675  /* Get initial link state */
677 
678  return 0;
679 
681  err_register_netdev:
682  err_reset:
683  err_check_version:
684  iounmap ( vmxnet->vd );
685  err_ioremap_vd:
686  iounmap ( vmxnet->pt );
687  err_ioremap_pt:
689  netdev_put ( netdev );
690  err_alloc_etherdev:
691  return rc;
692 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
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:580
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct device dev
Generic device.
Definition: pci.h:189
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#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:555
static void vmxnet3_get_hw_addr(struct vmxnet3_nic *vmxnet, void *hw_addr)
Get permanent MAC address.
Definition: vmxnet3.c:603
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:844
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:667
#define VMXNET3_VD_LEN
"VD" PCI BAR size
Definition: vmxnet3.h:72
A network device.
Definition: netdevice.h:348
#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:511
static void vmxnet3_check_link(struct net_device *netdev)
Check link state.
Definition: vmxnet3.c:335
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
void * pt
"PT" register base address
Definition: vmxnet3.h:473
static struct net_device_operations vmxnet3_operations
vmxnet3 net device operations
Definition: vmxnet3.c:566
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 * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
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, 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_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 699 of file vmxnet3.c.

699  {
700  struct net_device *netdev = pci_get_drvdata ( pci );
701  struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
702 
704  iounmap ( vmxnet->vd );
705  iounmap ( vmxnet->pt );
707  netdev_put ( netdev );
708 }
static void * netdev_priv(struct net_device *netdev)
Get driver private area for this network device.
Definition: netdevice.h:566
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:555
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
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:348
void iounmap(volatile const void *io_addr)
Unmap I/O address.
A vmxnet3 NIC.
Definition: vmxnet3.h:471

References iounmap(), netdev, netdev_nullify(), netdev_priv(), netdev_put(), pci_get_drvdata(), 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 48 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:91
static void vmxnet3_poll(struct net_device *netdev)
Poll network device.
Definition: vmxnet3.c:412
static int vmxnet3_open(struct net_device *netdev)
Open NIC.
Definition: vmxnet3.c:458
static void vmxnet3_irq(struct net_device *netdev, int enable)
Enable/disable interrupts.
Definition: vmxnet3.c:426
static void vmxnet3_close(struct net_device *netdev)
Close NIC.
Definition: vmxnet3.c:555

vmxnet3 net device operations

Definition at line 566 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:283

vmxnet3 PCI IDs

Definition at line 711 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:711
static int vmxnet3_probe(struct pci_device *pci)
Probe PCI device.
Definition: vmxnet3.c:623
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:699

vmxnet3 PCI driver

Definition at line 716 of file vmxnet3.c.