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 }
static const void const void void * result
Definition: crypto.h:335
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
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;
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 }
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 * 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: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:155
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:48
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:321
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 141 of file vmxnet3.c.

141  {
142  struct vmxnet3_nic *vmxnet = netdev->priv;
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_tx_complete(struct net_device *netdev, struct io_buffer *iobuf)
Complete network transmission.
Definition: netdevice.h:752
#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:155
#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:33

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

190  {
191  struct vmxnet3_nic *vmxnet = netdev->priv;
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 }
#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 208 of file vmxnet3.c.

208  {
209  struct vmxnet3_nic *vmxnet = netdev->priv;
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
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:129
#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: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:67
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:48
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:321
A vmxnet3 NIC.
Definition: vmxnet3.h:471
A persistent I/O buffer.
Definition: iobuf.h:33

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

263  {
264  struct vmxnet3_nic *vmxnet = netdev->priv;
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 }
#define iob_put(iobuf, len)
Definition: iobuf.h:120
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
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
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: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:33

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

317  {
318  struct vmxnet3_nic *vmxnet = netdev->priv;
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 }
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:33

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

335  {
336  struct vmxnet3_nic *vmxnet = netdev->priv;
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 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: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:774
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 362 of file vmxnet3.c.

362  {
363  struct vmxnet3_nic *vmxnet = netdev->priv;
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 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: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:171
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: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: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 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;
428 
429  DBGC ( vmxnet, "VMXNET3 %p %s IRQ not implemented\n",
430  vmxnet, ( enable ? "enable" : "disable" ) );
431 }
#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 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
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 458 of file vmxnet3.c.

458  {
459  struct vmxnet3_nic *vmxnet = netdev->priv;
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_phys ( sizeof ( *vmxnet->dma ),
470  if ( ! vmxnet->dma ) {
471  DBGC ( vmxnet, "VMXNET3 %p could not allocate DMA area\n",
472  vmxnet );
473  rc = -ENOMEM;
474  goto err_alloc_dma;
475  }
476  memset ( vmxnet->dma, 0, sizeof ( *vmxnet->dma ) );
477 
478  /* Populate queue descriptors */
479  queues = &vmxnet->dma->queues;
480  queues->tx.cfg.desc_address =
481  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->tx_desc ) );
482  queues->tx.cfg.comp_address =
483  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->tx_comp ) );
486  queues->rx.cfg.desc_address[0] =
487  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->rx_desc ) );
488  queues->rx.cfg.comp_address =
489  cpu_to_le64 ( virt_to_bus ( &vmxnet->dma->rx_comp ) );
490  queues->rx.cfg.num_desc[0] = cpu_to_le32 ( VMXNET3_NUM_RX_DESC );
492  queues_bus = virt_to_bus ( queues );
493  DBGC ( vmxnet, "VMXNET3 %p queue descriptors at %08llx+%zx\n",
494  vmxnet, queues_bus, sizeof ( *queues ) );
495 
496  /* Populate shared area */
497  shared = &vmxnet->dma->shared;
498  shared->magic = cpu_to_le32 ( VMXNET3_SHARED_MAGIC );
501  shared->misc.upt_version_support =
503  shared->misc.queue_desc_address = cpu_to_le64 ( queues_bus );
504  shared->misc.queue_desc_len = cpu_to_le32 ( sizeof ( *queues ) );
505  shared->misc.mtu = cpu_to_le32 ( VMXNET3_MTU );
506  shared->misc.num_tx_queues = 1;
507  shared->misc.num_rx_queues = 1;
508  shared->interrupt.num_intrs = 1;
513  shared_bus = virt_to_bus ( shared );
514  DBGC ( vmxnet, "VMXNET3 %p shared area at %08llx+%zx\n",
515  vmxnet, shared_bus, sizeof ( *shared ) );
516 
517  /* Zero counters */
518  memset ( &vmxnet->count, 0, sizeof ( vmxnet->count ) );
519 
520  /* Set MAC address */
521  vmxnet3_set_ll_addr ( vmxnet, &netdev->ll_addr );
522 
523  /* Pass shared area to device */
524  writel ( ( shared_bus >> 0 ), ( vmxnet->vd + VMXNET3_VD_DSAL ) );
525  writel ( ( shared_bus >> 32 ), ( vmxnet->vd + VMXNET3_VD_DSAH ) );
526 
527  /* Activate device */
528  if ( ( status = vmxnet3_command ( vmxnet,
529  VMXNET3_CMD_ACTIVATE_DEV ) ) != 0 ) {
530  DBGC ( vmxnet, "VMXNET3 %p could not activate (status %#x)\n",
531  vmxnet, status );
532  rc = -EIO;
533  goto err_activate;
534  }
535 
536  /* Fill receive ring */
538 
539  return 0;
540 
543  err_activate:
546  free_phys ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
547  err_alloc_dma:
548  return rc;
549 }
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
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
static void *__malloc malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.h:62
#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 * 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 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
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 free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
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: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
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_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_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, net_device::priv, 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 556 of file vmxnet3.c.

556  {
557  struct vmxnet3_nic *vmxnet = netdev->priv;
558 
563  free_phys ( vmxnet->dma, sizeof ( *vmxnet->dma ) );
564 }
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
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:190
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77
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 581 of file vmxnet3.c.

581  {
583  uint32_t upt_version;
584 
585  /* Read version */
586  version = readl ( vmxnet->vd + VMXNET3_VD_VRRS );
587  upt_version = readl ( vmxnet->vd + VMXNET3_VD_UVRS );
588  DBGC ( vmxnet, "VMXNET3 %p is version %d (UPT version %d)\n",
589  vmxnet, version, upt_version );
590 
591  /* Inform NIC of driver version */
592  writel ( VMXNET3_VERSION_SELECT, ( vmxnet->vd + VMXNET3_VD_VRRS ) );
594 
595  return 0;
596 }
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
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
u32 version
Driver version.
Definition: ath9k_hw.c:1983

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

604  {
605  struct {
606  uint32_t low;
607  uint32_t high;
608  } __attribute__ (( packed )) mac;
609 
610  mac.low = le32_to_cpu ( vmxnet3_command ( vmxnet,
612  mac.high = le32_to_cpu ( vmxnet3_command ( vmxnet,
614  memcpy ( hw_addr, &mac, ETH_ALEN );
615 }
#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 624 of file vmxnet3.c.

624  {
625  struct net_device *netdev;
626  struct vmxnet3_nic *vmxnet;
627  int rc;
628 
629  /* Allocate network device */
630  netdev = alloc_etherdev ( sizeof ( *vmxnet ) );
631  if ( ! netdev ) {
632  rc = -ENOMEM;
633  goto err_alloc_etherdev;
634  }
636  vmxnet = netdev->priv;
637  pci_set_drvdata ( pci, netdev );
638  netdev->dev = &pci->dev;
639  memset ( vmxnet, 0, sizeof ( *vmxnet ) );
640 
641  /* Fix up PCI device */
642  adjust_pci_device ( pci );
643 
644  /* Map PCI BARs */
645  vmxnet->pt = pci_ioremap ( pci, pci_bar_start ( pci, VMXNET3_PT_BAR ),
646  VMXNET3_PT_LEN );
647  if ( ! vmxnet->pt ) {
648  rc = -ENODEV;
649  goto err_ioremap_pt;
650  }
651  vmxnet->vd = pci_ioremap ( pci, pci_bar_start ( pci, VMXNET3_VD_BAR ),
652  VMXNET3_VD_LEN );
653  if ( ! vmxnet->vd ) {
654  rc = -ENODEV;
655  goto err_ioremap_vd;
656  }
657 
658  /* Version check */
659  if ( ( rc = vmxnet3_check_version ( vmxnet ) ) != 0 )
660  goto err_check_version;
661 
662  /* Reset device */
663  if ( ( rc = vmxnet3_command ( vmxnet, VMXNET3_CMD_RESET_DEV ) ) != 0 )
664  goto err_reset;
665 
666  /* Read initial MAC address */
667  vmxnet3_get_hw_addr ( vmxnet, &netdev->hw_addr );
668 
669  /* Register network device */
670  if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
671  DBGC ( vmxnet, "VMXNET3 %p could not register net device: "
672  "%s\n", vmxnet, strerror ( rc ) );
673  goto err_register_netdev;
674  }
675 
676  /* Get initial link state */
678 
679  return 0;
680 
682  err_register_netdev:
683  err_reset:
684  err_check_version:
685  iounmap ( vmxnet->vd );
686  err_ioremap_vd:
687  iounmap ( vmxnet->pt );
688  err_ioremap_pt:
690  netdev_put ( netdev );
691  err_alloc_etherdev:
692  return rc;
693 }
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:581
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:154
struct device dev
Generic device.
Definition: pci.h:208
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:359
#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:572
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:604
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:528
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: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:567
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 700 of file vmxnet3.c.

700  {
701  struct net_device *netdev = pci_get_drvdata ( pci );
702  struct vmxnet3_nic *vmxnet = netdev->priv;
703 
705  iounmap ( vmxnet->vd );
706  iounmap ( vmxnet->pt );
708  netdev_put ( netdev );
709 }
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:572
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:528
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:369
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 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:556

vmxnet3 net device operations

Definition at line 567 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:303

vmxnet3 PCI IDs

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

vmxnet3 PCI driver

Definition at line 717 of file vmxnet3.c.