4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/queue.h>
43 #include <rte_byteorder.h>
44 #include <rte_common.h>
45 #include <rte_cycles.h>
47 #include <rte_interrupts.h>
49 #include <rte_debug.h>
51 #include <rte_bus_pci.h>
52 #include <rte_atomic.h>
53 #include <rte_branch_prediction.h>
54 #include <rte_memory.h>
55 #include <rte_memzone.h>
57 #include <rte_alarm.h>
58 #include <rte_ether.h>
59 #include <rte_ethdev.h>
60 #include <rte_ethdev_pci.h>
61 #include <rte_string_fns.h>
62 #include <rte_malloc.h>
65 #include "base/vmxnet3_defs.h"
67 #include "vmxnet3_ring.h"
68 #include "vmxnet3_logs.h"
69 #include "vmxnet3_ethdev.h"
71 #define PROCESS_SYS_EVENTS 0
73 #define VMXNET3_TX_MAX_SEG UINT8_MAX
75 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
76 static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
77 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
78 static int vmxnet3_dev_start(struct rte_eth_dev *dev);
79 static void vmxnet3_dev_stop(struct rte_eth_dev *dev);
80 static void vmxnet3_dev_close(struct rte_eth_dev *dev);
81 static void vmxnet3_dev_set_rxmode(struct vmxnet3_hw *hw, uint32_t feature, int set);
82 static void vmxnet3_dev_promiscuous_enable(struct rte_eth_dev *dev);
83 static void vmxnet3_dev_promiscuous_disable(struct rte_eth_dev *dev);
84 static void vmxnet3_dev_allmulticast_enable(struct rte_eth_dev *dev);
85 static void vmxnet3_dev_allmulticast_disable(struct rte_eth_dev *dev);
86 static int __vmxnet3_dev_link_update(struct rte_eth_dev *dev,
87 int wait_to_complete);
88 static int vmxnet3_dev_link_update(struct rte_eth_dev *dev,
89 int wait_to_complete);
90 static void vmxnet3_hw_stats_save(struct vmxnet3_hw *hw);
91 static int vmxnet3_dev_stats_get(struct rte_eth_dev *dev,
92 struct rte_eth_stats *stats);
93 static int vmxnet3_dev_xstats_get_names(struct rte_eth_dev *dev,
94 struct rte_eth_xstat_name *xstats,
96 static int vmxnet3_dev_xstats_get(struct rte_eth_dev *dev,
97 struct rte_eth_xstat *xstats, unsigned int n);
98 static void vmxnet3_dev_info_get(struct rte_eth_dev *dev,
99 struct rte_eth_dev_info *dev_info);
100 static const uint32_t *
101 vmxnet3_dev_supported_ptypes_get(struct rte_eth_dev *dev);
102 static int vmxnet3_dev_vlan_filter_set(struct rte_eth_dev *dev,
103 uint16_t vid, int on);
104 static int vmxnet3_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
105 static void vmxnet3_mac_addr_set(struct rte_eth_dev *dev,
106 struct ether_addr *mac_addr);
107 static void vmxnet3_interrupt_handler(void *param);
110 * The set of PCI devices this driver supports
112 #define VMWARE_PCI_VENDOR_ID 0x15AD
113 #define VMWARE_DEV_ID_VMXNET3 0x07B0
114 static const struct rte_pci_id pci_id_vmxnet3_map[] = {
115 { RTE_PCI_DEVICE(VMWARE_PCI_VENDOR_ID, VMWARE_DEV_ID_VMXNET3) },
116 { .vendor_id = 0, /* sentinel */ },
119 static const struct eth_dev_ops vmxnet3_eth_dev_ops = {
120 .dev_configure = vmxnet3_dev_configure,
121 .dev_start = vmxnet3_dev_start,
122 .dev_stop = vmxnet3_dev_stop,
123 .dev_close = vmxnet3_dev_close,
124 .promiscuous_enable = vmxnet3_dev_promiscuous_enable,
125 .promiscuous_disable = vmxnet3_dev_promiscuous_disable,
126 .allmulticast_enable = vmxnet3_dev_allmulticast_enable,
127 .allmulticast_disable = vmxnet3_dev_allmulticast_disable,
128 .link_update = vmxnet3_dev_link_update,
129 .stats_get = vmxnet3_dev_stats_get,
130 .xstats_get_names = vmxnet3_dev_xstats_get_names,
131 .xstats_get = vmxnet3_dev_xstats_get,
132 .mac_addr_set = vmxnet3_mac_addr_set,
133 .dev_infos_get = vmxnet3_dev_info_get,
134 .dev_supported_ptypes_get = vmxnet3_dev_supported_ptypes_get,
135 .vlan_filter_set = vmxnet3_dev_vlan_filter_set,
136 .vlan_offload_set = vmxnet3_dev_vlan_offload_set,
137 .rx_queue_setup = vmxnet3_dev_rx_queue_setup,
138 .rx_queue_release = vmxnet3_dev_rx_queue_release,
139 .tx_queue_setup = vmxnet3_dev_tx_queue_setup,
140 .tx_queue_release = vmxnet3_dev_tx_queue_release,
143 struct vmxnet3_xstats_name_off {
144 char name[RTE_ETH_XSTATS_NAME_SIZE];
148 /* tx_qX_ is prepended to the name string here */
149 static const struct vmxnet3_xstats_name_off vmxnet3_txq_stat_strings[] = {
150 {"drop_total", offsetof(struct vmxnet3_txq_stats, drop_total)},
151 {"drop_too_many_segs", offsetof(struct vmxnet3_txq_stats, drop_too_many_segs)},
152 {"drop_tso", offsetof(struct vmxnet3_txq_stats, drop_tso)},
153 {"tx_ring_full", offsetof(struct vmxnet3_txq_stats, tx_ring_full)},
156 /* rx_qX_ is prepended to the name string here */
157 static const struct vmxnet3_xstats_name_off vmxnet3_rxq_stat_strings[] = {
158 {"drop_total", offsetof(struct vmxnet3_rxq_stats, drop_total)},
159 {"drop_err", offsetof(struct vmxnet3_rxq_stats, drop_err)},
160 {"drop_fcs", offsetof(struct vmxnet3_rxq_stats, drop_fcs)},
161 {"rx_buf_alloc_failure", offsetof(struct vmxnet3_rxq_stats, rx_buf_alloc_failure)},
164 static const struct rte_memzone *
165 gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size,
166 const char *post_string, int socket_id,
167 uint16_t align, bool reuse)
169 char z_name[RTE_MEMZONE_NAMESIZE];
170 const struct rte_memzone *mz;
172 snprintf(z_name, sizeof(z_name), "%s_%d_%s",
173 dev->device->driver->name, dev->data->port_id, post_string);
175 mz = rte_memzone_lookup(z_name);
178 rte_memzone_free(mz);
179 return rte_memzone_reserve_aligned(z_name, size, socket_id,
186 return rte_memzone_reserve_aligned(z_name, size, socket_id, 0, align);
190 * Atomically reads the link status information from global
191 * structure rte_eth_dev.
194 * - Pointer to the structure rte_eth_dev to read from.
195 * - Pointer to the buffer to be saved with the link status.
198 * - On success, zero.
199 * - On failure, negative value.
203 vmxnet3_dev_atomic_read_link_status(struct rte_eth_dev *dev,
204 struct rte_eth_link *link)
206 struct rte_eth_link *dst = link;
207 struct rte_eth_link *src = &(dev->data->dev_link);
209 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
210 *(uint64_t *)src) == 0)
217 * Atomically writes the link status information into global
218 * structure rte_eth_dev.
221 * - Pointer to the structure rte_eth_dev to write to.
222 * - Pointer to the buffer to be saved with the link status.
225 * - On success, zero.
226 * - On failure, negative value.
229 vmxnet3_dev_atomic_write_link_status(struct rte_eth_dev *dev,
230 struct rte_eth_link *link)
232 struct rte_eth_link *dst = &(dev->data->dev_link);
233 struct rte_eth_link *src = link;
235 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
236 *(uint64_t *)src) == 0)
243 * This function is based on vmxnet3_disable_intr()
246 vmxnet3_disable_intr(struct vmxnet3_hw *hw)
250 PMD_INIT_FUNC_TRACE();
252 hw->shared->devRead.intrConf.intrCtrl |= VMXNET3_IC_DISABLE_ALL;
253 for (i = 0; i < hw->num_intrs; i++)
254 VMXNET3_WRITE_BAR0_REG(hw, VMXNET3_REG_IMR + i * 8, 1);
258 vmxnet3_enable_intr(struct vmxnet3_hw *hw)
262 PMD_INIT_FUNC_TRACE();
264 hw->shared->devRead.intrConf.intrCtrl &= ~VMXNET3_IC_DISABLE_ALL;
265 for (i = 0; i < hw->num_intrs; i++)
266 VMXNET3_WRITE_BAR0_REG(hw, VMXNET3_REG_IMR + i * 8, 0);
270 * Gets tx data ring descriptor size.
273 eth_vmxnet3_txdata_get(struct vmxnet3_hw *hw)
275 uint16 txdata_desc_size;
277 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
278 VMXNET3_CMD_GET_TXDATA_DESC_SIZE);
279 txdata_desc_size = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
281 return (txdata_desc_size < VMXNET3_TXDATA_DESC_MIN_SIZE ||
282 txdata_desc_size > VMXNET3_TXDATA_DESC_MAX_SIZE ||
283 txdata_desc_size & VMXNET3_TXDATA_DESC_SIZE_MASK) ?
284 sizeof(struct Vmxnet3_TxDataDesc) : txdata_desc_size;
288 * It returns 0 on success.
291 eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
293 struct rte_pci_device *pci_dev;
294 struct vmxnet3_hw *hw = eth_dev->data->dev_private;
295 uint32_t mac_hi, mac_lo, ver;
297 PMD_INIT_FUNC_TRACE();
299 eth_dev->dev_ops = &vmxnet3_eth_dev_ops;
300 eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
301 eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
302 eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
303 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
306 * for secondary processes, we don't initialize any further as primary
307 * has already done this work.
309 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
312 rte_eth_copy_pci_info(eth_dev, pci_dev);
314 /* Vendor and Device ID need to be set before init of shared code */
315 hw->device_id = pci_dev->id.device_id;
316 hw->vendor_id = pci_dev->id.vendor_id;
317 hw->hw_addr0 = (void *)pci_dev->mem_resource[0].addr;
318 hw->hw_addr1 = (void *)pci_dev->mem_resource[1].addr;
320 hw->num_rx_queues = 1;
321 hw->num_tx_queues = 1;
322 hw->bufs_per_pkt = 1;
324 /* Check h/w version compatibility with driver. */
325 ver = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_VRRS);
326 PMD_INIT_LOG(DEBUG, "Hardware version : %d", ver);
328 if (ver & (1 << VMXNET3_REV_3)) {
329 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
331 hw->version = VMXNET3_REV_3 + 1;
332 } else if (ver & (1 << VMXNET3_REV_2)) {
333 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
335 hw->version = VMXNET3_REV_2 + 1;
336 } else if (ver & (1 << VMXNET3_REV_1)) {
337 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
339 hw->version = VMXNET3_REV_1 + 1;
341 PMD_INIT_LOG(ERR, "Incompatible hardware version: %d", ver);
345 PMD_INIT_LOG(DEBUG, "Using device version %d\n", hw->version);
347 /* Check UPT version compatibility with driver. */
348 ver = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_UVRS);
349 PMD_INIT_LOG(DEBUG, "UPT hardware version : %d", ver);
351 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_UVRS, 1);
353 PMD_INIT_LOG(ERR, "Incompatible UPT version.");
357 /* Getting MAC Address */
358 mac_lo = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_MACL);
359 mac_hi = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_MACH);
360 memcpy(hw->perm_addr, &mac_lo, 4);
361 memcpy(hw->perm_addr + 4, &mac_hi, 2);
363 /* Allocate memory for storing MAC addresses */
364 eth_dev->data->mac_addrs = rte_zmalloc("vmxnet3", ETHER_ADDR_LEN *
365 VMXNET3_MAX_MAC_ADDRS, 0);
366 if (eth_dev->data->mac_addrs == NULL) {
368 "Failed to allocate %d bytes needed to store MAC addresses",
369 ETHER_ADDR_LEN * VMXNET3_MAX_MAC_ADDRS);
372 /* Copy the permanent MAC address */
373 ether_addr_copy((struct ether_addr *) hw->perm_addr,
374 ð_dev->data->mac_addrs[0]);
376 PMD_INIT_LOG(DEBUG, "MAC Address : %02x:%02x:%02x:%02x:%02x:%02x",
377 hw->perm_addr[0], hw->perm_addr[1], hw->perm_addr[2],
378 hw->perm_addr[3], hw->perm_addr[4], hw->perm_addr[5]);
380 /* Put device in Quiesce Mode */
381 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
383 /* allow untagged pkts */
384 VMXNET3_SET_VFTABLE_ENTRY(hw->shadow_vfta, 0);
386 hw->txdata_desc_size = VMXNET3_VERSION_GE_3(hw) ?
387 eth_vmxnet3_txdata_get(hw) : sizeof(struct Vmxnet3_TxDataDesc);
389 hw->rxdata_desc_size = VMXNET3_VERSION_GE_3(hw) ?
390 VMXNET3_DEF_RXDATA_DESC_SIZE : 0;
391 RTE_ASSERT((hw->rxdata_desc_size & ~VMXNET3_RXDATA_DESC_SIZE_MASK) ==
392 hw->rxdata_desc_size);
394 /* clear shadow stats */
395 memset(hw->saved_tx_stats, 0, sizeof(hw->saved_tx_stats));
396 memset(hw->saved_rx_stats, 0, sizeof(hw->saved_rx_stats));
402 eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev)
404 struct vmxnet3_hw *hw = eth_dev->data->dev_private;
406 PMD_INIT_FUNC_TRACE();
408 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
411 if (hw->adapter_stopped == 0)
412 vmxnet3_dev_close(eth_dev);
414 eth_dev->dev_ops = NULL;
415 eth_dev->rx_pkt_burst = NULL;
416 eth_dev->tx_pkt_burst = NULL;
417 eth_dev->tx_pkt_prepare = NULL;
419 rte_free(eth_dev->data->mac_addrs);
420 eth_dev->data->mac_addrs = NULL;
425 static int eth_vmxnet3_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
426 struct rte_pci_device *pci_dev)
428 return rte_eth_dev_pci_generic_probe(pci_dev,
429 sizeof(struct vmxnet3_hw), eth_vmxnet3_dev_init);
432 static int eth_vmxnet3_pci_remove(struct rte_pci_device *pci_dev)
434 return rte_eth_dev_pci_generic_remove(pci_dev, eth_vmxnet3_dev_uninit);
437 static struct rte_pci_driver rte_vmxnet3_pmd = {
438 .id_table = pci_id_vmxnet3_map,
439 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
440 .probe = eth_vmxnet3_pci_probe,
441 .remove = eth_vmxnet3_pci_remove,
445 vmxnet3_dev_configure(struct rte_eth_dev *dev)
447 const struct rte_memzone *mz;
448 struct vmxnet3_hw *hw = dev->data->dev_private;
451 PMD_INIT_FUNC_TRACE();
453 if (dev->data->nb_tx_queues > VMXNET3_MAX_TX_QUEUES ||
454 dev->data->nb_rx_queues > VMXNET3_MAX_RX_QUEUES) {
455 PMD_INIT_LOG(ERR, "ERROR: Number of queues not supported");
459 if (!rte_is_power_of_2(dev->data->nb_rx_queues)) {
460 PMD_INIT_LOG(ERR, "ERROR: Number of rx queues not power of 2");
464 size = dev->data->nb_rx_queues * sizeof(struct Vmxnet3_TxQueueDesc) +
465 dev->data->nb_tx_queues * sizeof(struct Vmxnet3_RxQueueDesc);
467 if (size > UINT16_MAX)
470 hw->num_rx_queues = (uint8_t)dev->data->nb_rx_queues;
471 hw->num_tx_queues = (uint8_t)dev->data->nb_tx_queues;
474 * Allocate a memzone for Vmxnet3_DriverShared - Vmxnet3_DSDevRead
477 mz = gpa_zone_reserve(dev, sizeof(struct Vmxnet3_DriverShared),
478 "shared", rte_socket_id(), 8, 1);
481 PMD_INIT_LOG(ERR, "ERROR: Creating shared zone");
484 memset(mz->addr, 0, mz->len);
486 hw->shared = mz->addr;
487 hw->sharedPA = mz->iova;
490 * Allocate a memzone for Vmxnet3_RxQueueDesc - Vmxnet3_TxQueueDesc
493 * We cannot reuse this memzone from previous allocation as its size
494 * depends on the number of tx and rx queues, which could be different
495 * from one config to another.
497 mz = gpa_zone_reserve(dev, size, "queuedesc", rte_socket_id(),
498 VMXNET3_QUEUE_DESC_ALIGN, 0);
500 PMD_INIT_LOG(ERR, "ERROR: Creating queue descriptors zone");
503 memset(mz->addr, 0, mz->len);
505 hw->tqd_start = (Vmxnet3_TxQueueDesc *)mz->addr;
506 hw->rqd_start = (Vmxnet3_RxQueueDesc *)(hw->tqd_start + hw->num_tx_queues);
508 hw->queueDescPA = mz->iova;
509 hw->queue_desc_len = (uint16_t)size;
511 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
512 /* Allocate memory structure for UPT1_RSSConf and configure */
513 mz = gpa_zone_reserve(dev, sizeof(struct VMXNET3_RSSConf),
514 "rss_conf", rte_socket_id(),
515 RTE_CACHE_LINE_SIZE, 1);
518 "ERROR: Creating rss_conf structure zone");
521 memset(mz->addr, 0, mz->len);
523 hw->rss_conf = mz->addr;
524 hw->rss_confPA = mz->iova;
531 vmxnet3_write_mac(struct vmxnet3_hw *hw, const uint8_t *addr)
536 "Writing MAC Address : %02x:%02x:%02x:%02x:%02x:%02x",
537 addr[0], addr[1], addr[2],
538 addr[3], addr[4], addr[5]);
540 memcpy(&val, addr, 4);
541 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACL, val);
543 memcpy(&val, addr + 4, 2);
544 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACH, val);
548 vmxnet3_dev_setup_memreg(struct rte_eth_dev *dev)
550 struct vmxnet3_hw *hw = dev->data->dev_private;
551 Vmxnet3_DriverShared *shared = hw->shared;
552 Vmxnet3_CmdInfo *cmdInfo;
553 struct rte_mempool *mp[VMXNET3_MAX_RX_QUEUES];
554 uint8_t index[VMXNET3_MAX_RX_QUEUES + VMXNET3_MAX_TX_QUEUES];
555 uint32_t num, i, j, size;
557 if (hw->memRegsPA == 0) {
558 const struct rte_memzone *mz;
560 size = sizeof(Vmxnet3_MemRegs) +
561 (VMXNET3_MAX_RX_QUEUES + VMXNET3_MAX_TX_QUEUES) *
562 sizeof(Vmxnet3_MemoryRegion);
564 mz = gpa_zone_reserve(dev, size, "memRegs", rte_socket_id(), 8,
567 PMD_INIT_LOG(ERR, "ERROR: Creating memRegs zone");
570 memset(mz->addr, 0, mz->len);
571 hw->memRegs = mz->addr;
572 hw->memRegsPA = mz->iova;
575 num = hw->num_rx_queues;
577 for (i = 0; i < num; i++) {
578 vmxnet3_rx_queue_t *rxq = dev->data->rx_queues[i];
585 * The same mempool could be used by multiple queues. In such a case,
586 * remove duplicate mempool entries. Only one entry is kept with
587 * bitmask indicating queues that are using this mempool.
589 for (i = 1; i < num; i++) {
590 for (j = 0; j < i; j++) {
591 if (mp[i] == mp[j]) {
600 for (i = 0; i < num; i++) {
604 Vmxnet3_MemoryRegion *mr = &hw->memRegs->memRegs[j];
607 (uintptr_t)STAILQ_FIRST(&mp[i]->mem_list)->iova;
608 mr->length = STAILQ_FIRST(&mp[i]->mem_list)->len <= INT32_MAX ?
609 STAILQ_FIRST(&mp[i]->mem_list)->len : INT32_MAX;
610 mr->txQueueBits = index[i];
611 mr->rxQueueBits = index[i];
614 "index: %u startPA: %" PRIu64 " length: %u, "
616 j, mr->startPA, mr->length, mr->rxQueueBits);
619 hw->memRegs->numRegs = j;
620 PMD_INIT_LOG(INFO, "numRegs: %u", j);
622 size = sizeof(Vmxnet3_MemRegs) +
623 (j - 1) * sizeof(Vmxnet3_MemoryRegion);
625 cmdInfo = &shared->cu.cmdInfo;
626 cmdInfo->varConf.confVer = 1;
627 cmdInfo->varConf.confLen = size;
628 cmdInfo->varConf.confPA = hw->memRegsPA;
634 vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)
636 struct rte_eth_conf port_conf = dev->data->dev_conf;
637 struct vmxnet3_hw *hw = dev->data->dev_private;
638 uint32_t mtu = dev->data->mtu;
639 Vmxnet3_DriverShared *shared = hw->shared;
640 Vmxnet3_DSDevRead *devRead = &shared->devRead;
644 shared->magic = VMXNET3_REV1_MAGIC;
645 devRead->misc.driverInfo.version = VMXNET3_DRIVER_VERSION_NUM;
647 /* Setting up Guest OS information */
648 devRead->misc.driverInfo.gos.gosBits = sizeof(void *) == 4 ?
649 VMXNET3_GOS_BITS_32 : VMXNET3_GOS_BITS_64;
650 devRead->misc.driverInfo.gos.gosType = VMXNET3_GOS_TYPE_LINUX;
651 devRead->misc.driverInfo.vmxnet3RevSpt = 1;
652 devRead->misc.driverInfo.uptVerSpt = 1;
654 devRead->misc.mtu = rte_le_to_cpu_32(mtu);
655 devRead->misc.queueDescPA = hw->queueDescPA;
656 devRead->misc.queueDescLen = hw->queue_desc_len;
657 devRead->misc.numTxQueues = hw->num_tx_queues;
658 devRead->misc.numRxQueues = hw->num_rx_queues;
661 * Set number of interrupts to 1
662 * PMD by default disables all the interrupts but this is MUST
663 * to activate device. It needs at least one interrupt for
664 * link events to handle
666 hw->num_intrs = devRead->intrConf.numIntrs = 1;
667 devRead->intrConf.intrCtrl |= VMXNET3_IC_DISABLE_ALL;
669 for (i = 0; i < hw->num_tx_queues; i++) {
670 Vmxnet3_TxQueueDesc *tqd = &hw->tqd_start[i];
671 vmxnet3_tx_queue_t *txq = dev->data->tx_queues[i];
673 txq->shared = &hw->tqd_start[i];
675 tqd->ctrl.txNumDeferred = 0;
676 tqd->ctrl.txThreshold = 1;
677 tqd->conf.txRingBasePA = txq->cmd_ring.basePA;
678 tqd->conf.compRingBasePA = txq->comp_ring.basePA;
679 tqd->conf.dataRingBasePA = txq->data_ring.basePA;
681 tqd->conf.txRingSize = txq->cmd_ring.size;
682 tqd->conf.compRingSize = txq->comp_ring.size;
683 tqd->conf.dataRingSize = txq->data_ring.size;
684 tqd->conf.txDataRingDescSize = txq->txdata_desc_size;
685 tqd->conf.intrIdx = txq->comp_ring.intr_idx;
686 tqd->status.stopped = TRUE;
687 tqd->status.error = 0;
688 memset(&tqd->stats, 0, sizeof(tqd->stats));
691 for (i = 0; i < hw->num_rx_queues; i++) {
692 Vmxnet3_RxQueueDesc *rqd = &hw->rqd_start[i];
693 vmxnet3_rx_queue_t *rxq = dev->data->rx_queues[i];
695 rxq->shared = &hw->rqd_start[i];
697 rqd->conf.rxRingBasePA[0] = rxq->cmd_ring[0].basePA;
698 rqd->conf.rxRingBasePA[1] = rxq->cmd_ring[1].basePA;
699 rqd->conf.compRingBasePA = rxq->comp_ring.basePA;
701 rqd->conf.rxRingSize[0] = rxq->cmd_ring[0].size;
702 rqd->conf.rxRingSize[1] = rxq->cmd_ring[1].size;
703 rqd->conf.compRingSize = rxq->comp_ring.size;
704 rqd->conf.intrIdx = rxq->comp_ring.intr_idx;
705 if (VMXNET3_VERSION_GE_3(hw)) {
706 rqd->conf.rxDataRingBasePA = rxq->data_ring.basePA;
707 rqd->conf.rxDataRingDescSize = rxq->data_desc_size;
709 rqd->status.stopped = TRUE;
710 rqd->status.error = 0;
711 memset(&rqd->stats, 0, sizeof(rqd->stats));
714 /* RxMode set to 0 of VMXNET3_RXM_xxx */
715 devRead->rxFilterConf.rxMode = 0;
717 /* Setting up feature flags */
718 if (dev->data->dev_conf.rxmode.hw_ip_checksum)
719 devRead->misc.uptFeatures |= VMXNET3_F_RXCSUM;
721 if (dev->data->dev_conf.rxmode.enable_lro) {
722 devRead->misc.uptFeatures |= VMXNET3_F_LRO;
723 devRead->misc.maxNumRxSG = 0;
726 if (port_conf.rxmode.mq_mode == ETH_MQ_RX_RSS) {
727 ret = vmxnet3_rss_configure(dev);
728 if (ret != VMXNET3_SUCCESS)
731 devRead->misc.uptFeatures |= VMXNET3_F_RSS;
732 devRead->rssConfDesc.confVer = 1;
733 devRead->rssConfDesc.confLen = sizeof(struct VMXNET3_RSSConf);
734 devRead->rssConfDesc.confPA = hw->rss_confPA;
737 ret = vmxnet3_dev_vlan_offload_set(dev,
738 ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK);
742 vmxnet3_write_mac(hw, dev->data->mac_addrs->addr_bytes);
744 return VMXNET3_SUCCESS;
748 * Configure device link speed and setup link.
749 * Must be called after eth_vmxnet3_dev_init. Other wise it might fail
750 * It returns 0 on success.
753 vmxnet3_dev_start(struct rte_eth_dev *dev)
756 struct vmxnet3_hw *hw = dev->data->dev_private;
758 PMD_INIT_FUNC_TRACE();
760 /* Save stats before it is reset by CMD_ACTIVATE */
761 vmxnet3_hw_stats_save(hw);
763 ret = vmxnet3_setup_driver_shared(dev);
764 if (ret != VMXNET3_SUCCESS)
767 /* check if lsc interrupt feature is enabled */
768 if (dev->data->dev_conf.intr_conf.lsc) {
769 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
771 /* Setup interrupt callback */
772 rte_intr_callback_register(&pci_dev->intr_handle,
773 vmxnet3_interrupt_handler, dev);
775 if (rte_intr_enable(&pci_dev->intr_handle) < 0) {
776 PMD_INIT_LOG(ERR, "interrupt enable failed");
781 /* Exchange shared data with device */
782 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DSAL,
783 VMXNET3_GET_ADDR_LO(hw->sharedPA));
784 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DSAH,
785 VMXNET3_GET_ADDR_HI(hw->sharedPA));
787 /* Activate device by register write */
788 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_ACTIVATE_DEV);
789 ret = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
792 PMD_INIT_LOG(ERR, "Device activation: UNSUCCESSFUL");
796 /* Setup memory region for rx buffers */
797 ret = vmxnet3_dev_setup_memreg(dev);
799 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
800 VMXNET3_CMD_REGISTER_MEMREGS);
801 ret = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
804 "Failed in setup memory region cmd\n");
807 PMD_INIT_LOG(DEBUG, "Failed to setup memory region\n");
810 /* Disable interrupts */
811 vmxnet3_disable_intr(hw);
814 * Load RX queues with blank mbufs and update next2fill index for device
815 * Update RxMode of the device
817 ret = vmxnet3_dev_rxtx_init(dev);
818 if (ret != VMXNET3_SUCCESS) {
819 PMD_INIT_LOG(ERR, "Device queue init: UNSUCCESSFUL");
823 hw->adapter_stopped = FALSE;
825 /* Setting proper Rx Mode and issue Rx Mode Update command */
826 vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_UCAST | VMXNET3_RXM_BCAST, 1);
828 if (dev->data->dev_conf.intr_conf.lsc) {
829 vmxnet3_enable_intr(hw);
832 * Update link state from device since this won't be
833 * done upon starting with lsc in use. This is done
834 * only after enabling interrupts to avoid any race
835 * where the link state could change without an
836 * interrupt being fired.
838 __vmxnet3_dev_link_update(dev, 0);
841 return VMXNET3_SUCCESS;
845 * Stop device: disable rx and tx functions to allow for reconfiguring.
848 vmxnet3_dev_stop(struct rte_eth_dev *dev)
850 struct rte_eth_link link;
851 struct vmxnet3_hw *hw = dev->data->dev_private;
853 PMD_INIT_FUNC_TRACE();
855 if (hw->adapter_stopped == 1) {
856 PMD_INIT_LOG(DEBUG, "Device already closed.");
860 /* disable interrupts */
861 vmxnet3_disable_intr(hw);
863 if (dev->data->dev_conf.intr_conf.lsc) {
864 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
866 rte_intr_disable(&pci_dev->intr_handle);
868 rte_intr_callback_unregister(&pci_dev->intr_handle,
869 vmxnet3_interrupt_handler, dev);
872 /* quiesce the device first */
873 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
874 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DSAL, 0);
875 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DSAH, 0);
877 /* reset the device */
878 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
879 PMD_INIT_LOG(DEBUG, "Device reset.");
880 hw->adapter_stopped = 0;
882 vmxnet3_dev_clear_queues(dev);
884 /* Clear recorded link status */
885 memset(&link, 0, sizeof(link));
886 vmxnet3_dev_atomic_write_link_status(dev, &link);
890 * Reset and stop device.
893 vmxnet3_dev_close(struct rte_eth_dev *dev)
895 struct vmxnet3_hw *hw = dev->data->dev_private;
897 PMD_INIT_FUNC_TRACE();
899 vmxnet3_dev_stop(dev);
900 hw->adapter_stopped = 1;
904 vmxnet3_hw_tx_stats_get(struct vmxnet3_hw *hw, unsigned int q,
905 struct UPT1_TxStats *res)
907 #define VMXNET3_UPDATE_TX_STAT(h, i, f, r) \
908 ((r)->f = (h)->tqd_start[(i)].stats.f + \
909 (h)->saved_tx_stats[(i)].f)
911 VMXNET3_UPDATE_TX_STAT(hw, q, ucastPktsTxOK, res);
912 VMXNET3_UPDATE_TX_STAT(hw, q, mcastPktsTxOK, res);
913 VMXNET3_UPDATE_TX_STAT(hw, q, bcastPktsTxOK, res);
914 VMXNET3_UPDATE_TX_STAT(hw, q, ucastBytesTxOK, res);
915 VMXNET3_UPDATE_TX_STAT(hw, q, mcastBytesTxOK, res);
916 VMXNET3_UPDATE_TX_STAT(hw, q, bcastBytesTxOK, res);
917 VMXNET3_UPDATE_TX_STAT(hw, q, pktsTxError, res);
918 VMXNET3_UPDATE_TX_STAT(hw, q, pktsTxDiscard, res);
920 #undef VMXNET3_UPDATE_TX_STAT
924 vmxnet3_hw_rx_stats_get(struct vmxnet3_hw *hw, unsigned int q,
925 struct UPT1_RxStats *res)
927 #define VMXNET3_UPDATE_RX_STAT(h, i, f, r) \
928 ((r)->f = (h)->rqd_start[(i)].stats.f + \
929 (h)->saved_rx_stats[(i)].f)
931 VMXNET3_UPDATE_RX_STAT(hw, q, ucastPktsRxOK, res);
932 VMXNET3_UPDATE_RX_STAT(hw, q, mcastPktsRxOK, res);
933 VMXNET3_UPDATE_RX_STAT(hw, q, bcastPktsRxOK, res);
934 VMXNET3_UPDATE_RX_STAT(hw, q, ucastBytesRxOK, res);
935 VMXNET3_UPDATE_RX_STAT(hw, q, mcastBytesRxOK, res);
936 VMXNET3_UPDATE_RX_STAT(hw, q, bcastBytesRxOK, res);
937 VMXNET3_UPDATE_RX_STAT(hw, q, pktsRxError, res);
938 VMXNET3_UPDATE_RX_STAT(hw, q, pktsRxOutOfBuf, res);
940 #undef VMXNET3_UPDATE_RX_STATS
944 vmxnet3_hw_stats_save(struct vmxnet3_hw *hw)
948 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
950 RTE_BUILD_BUG_ON(RTE_ETHDEV_QUEUE_STAT_CNTRS < VMXNET3_MAX_TX_QUEUES);
952 for (i = 0; i < hw->num_tx_queues; i++)
953 vmxnet3_hw_tx_stats_get(hw, i, &hw->saved_tx_stats[i]);
954 for (i = 0; i < hw->num_rx_queues; i++)
955 vmxnet3_hw_rx_stats_get(hw, i, &hw->saved_rx_stats[i]);
959 vmxnet3_dev_xstats_get_names(struct rte_eth_dev *dev,
960 struct rte_eth_xstat_name *xstats_names,
963 unsigned int i, t, count = 0;
964 unsigned int nstats =
965 dev->data->nb_tx_queues * RTE_DIM(vmxnet3_txq_stat_strings) +
966 dev->data->nb_rx_queues * RTE_DIM(vmxnet3_rxq_stat_strings);
968 if (!xstats_names || n < nstats)
971 for (i = 0; i < dev->data->nb_rx_queues; i++) {
972 if (!dev->data->rx_queues[i])
975 for (t = 0; t < RTE_DIM(vmxnet3_rxq_stat_strings); t++) {
976 snprintf(xstats_names[count].name,
977 sizeof(xstats_names[count].name),
979 vmxnet3_rxq_stat_strings[t].name);
984 for (i = 0; i < dev->data->nb_tx_queues; i++) {
985 if (!dev->data->tx_queues[i])
988 for (t = 0; t < RTE_DIM(vmxnet3_txq_stat_strings); t++) {
989 snprintf(xstats_names[count].name,
990 sizeof(xstats_names[count].name),
992 vmxnet3_txq_stat_strings[t].name);
1001 vmxnet3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1004 unsigned int i, t, count = 0;
1005 unsigned int nstats =
1006 dev->data->nb_tx_queues * RTE_DIM(vmxnet3_txq_stat_strings) +
1007 dev->data->nb_rx_queues * RTE_DIM(vmxnet3_rxq_stat_strings);
1012 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1013 struct vmxnet3_rx_queue *rxq = dev->data->rx_queues[i];
1018 for (t = 0; t < RTE_DIM(vmxnet3_rxq_stat_strings); t++) {
1019 xstats[count].value = *(uint64_t *)(((char *)&rxq->stats) +
1020 vmxnet3_rxq_stat_strings[t].offset);
1021 xstats[count].id = count;
1026 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1027 struct vmxnet3_tx_queue *txq = dev->data->tx_queues[i];
1032 for (t = 0; t < RTE_DIM(vmxnet3_txq_stat_strings); t++) {
1033 xstats[count].value = *(uint64_t *)(((char *)&txq->stats) +
1034 vmxnet3_txq_stat_strings[t].offset);
1035 xstats[count].id = count;
1044 vmxnet3_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1047 struct vmxnet3_hw *hw = dev->data->dev_private;
1048 struct UPT1_TxStats txStats;
1049 struct UPT1_RxStats rxStats;
1051 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
1053 RTE_BUILD_BUG_ON(RTE_ETHDEV_QUEUE_STAT_CNTRS < VMXNET3_MAX_TX_QUEUES);
1054 for (i = 0; i < hw->num_tx_queues; i++) {
1055 vmxnet3_hw_tx_stats_get(hw, i, &txStats);
1057 stats->q_opackets[i] = txStats.ucastPktsTxOK +
1058 txStats.mcastPktsTxOK +
1059 txStats.bcastPktsTxOK;
1061 stats->q_obytes[i] = txStats.ucastBytesTxOK +
1062 txStats.mcastBytesTxOK +
1063 txStats.bcastBytesTxOK;
1065 stats->opackets += stats->q_opackets[i];
1066 stats->obytes += stats->q_obytes[i];
1067 stats->oerrors += txStats.pktsTxError + txStats.pktsTxDiscard;
1070 RTE_BUILD_BUG_ON(RTE_ETHDEV_QUEUE_STAT_CNTRS < VMXNET3_MAX_RX_QUEUES);
1071 for (i = 0; i < hw->num_rx_queues; i++) {
1072 vmxnet3_hw_rx_stats_get(hw, i, &rxStats);
1074 stats->q_ipackets[i] = rxStats.ucastPktsRxOK +
1075 rxStats.mcastPktsRxOK +
1076 rxStats.bcastPktsRxOK;
1078 stats->q_ibytes[i] = rxStats.ucastBytesRxOK +
1079 rxStats.mcastBytesRxOK +
1080 rxStats.bcastBytesRxOK;
1082 stats->ipackets += stats->q_ipackets[i];
1083 stats->ibytes += stats->q_ibytes[i];
1085 stats->q_errors[i] = rxStats.pktsRxError;
1086 stats->ierrors += rxStats.pktsRxError;
1087 stats->rx_nombuf += rxStats.pktsRxOutOfBuf;
1094 vmxnet3_dev_info_get(struct rte_eth_dev *dev,
1095 struct rte_eth_dev_info *dev_info)
1097 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1099 dev_info->max_rx_queues = VMXNET3_MAX_RX_QUEUES;
1100 dev_info->max_tx_queues = VMXNET3_MAX_TX_QUEUES;
1101 dev_info->min_rx_bufsize = 1518 + RTE_PKTMBUF_HEADROOM;
1102 dev_info->max_rx_pktlen = 16384; /* includes CRC, cf MAXFRS register */
1103 dev_info->speed_capa = ETH_LINK_SPEED_10G;
1104 dev_info->max_mac_addrs = VMXNET3_MAX_MAC_ADDRS;
1106 dev_info->default_txconf.txq_flags = ETH_TXQ_FLAGS_NOXSUMSCTP;
1107 dev_info->flow_type_rss_offloads = VMXNET3_RSS_OFFLOAD_ALL;
1109 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1110 .nb_max = VMXNET3_RX_RING_MAX_SIZE,
1111 .nb_min = VMXNET3_DEF_RX_RING_SIZE,
1115 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1116 .nb_max = VMXNET3_TX_RING_MAX_SIZE,
1117 .nb_min = VMXNET3_DEF_TX_RING_SIZE,
1119 .nb_seg_max = VMXNET3_TX_MAX_SEG,
1120 .nb_mtu_seg_max = VMXNET3_MAX_TXD_PER_PKT,
1123 dev_info->rx_offload_capa =
1124 DEV_RX_OFFLOAD_VLAN_STRIP |
1125 DEV_RX_OFFLOAD_UDP_CKSUM |
1126 DEV_RX_OFFLOAD_TCP_CKSUM |
1127 DEV_RX_OFFLOAD_TCP_LRO;
1129 dev_info->tx_offload_capa =
1130 DEV_TX_OFFLOAD_VLAN_INSERT |
1131 DEV_TX_OFFLOAD_TCP_CKSUM |
1132 DEV_TX_OFFLOAD_UDP_CKSUM |
1133 DEV_TX_OFFLOAD_TCP_TSO;
1136 static const uint32_t *
1137 vmxnet3_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1139 static const uint32_t ptypes[] = {
1140 RTE_PTYPE_L3_IPV4_EXT,
1145 if (dev->rx_pkt_burst == vmxnet3_recv_pkts)
1151 vmxnet3_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
1153 struct vmxnet3_hw *hw = dev->data->dev_private;
1155 ether_addr_copy(mac_addr, (struct ether_addr *)(hw->perm_addr));
1156 ether_addr_copy(mac_addr, &dev->data->mac_addrs[0]);
1157 vmxnet3_write_mac(hw, mac_addr->addr_bytes);
1160 /* return 0 means link status changed, -1 means not changed */
1162 __vmxnet3_dev_link_update(struct rte_eth_dev *dev,
1163 __rte_unused int wait_to_complete)
1165 struct vmxnet3_hw *hw = dev->data->dev_private;
1166 struct rte_eth_link old = { 0 }, link;
1169 memset(&link, 0, sizeof(link));
1170 vmxnet3_dev_atomic_read_link_status(dev, &old);
1172 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
1173 ret = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
1176 link.link_status = ETH_LINK_UP;
1177 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1178 link.link_speed = ETH_SPEED_NUM_10G;
1179 link.link_autoneg = ETH_LINK_AUTONEG;
1182 vmxnet3_dev_atomic_write_link_status(dev, &link);
1184 return (old.link_status == link.link_status) ? -1 : 0;
1188 vmxnet3_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1190 /* Link status doesn't change for stopped dev */
1191 if (dev->data->dev_started == 0)
1194 return __vmxnet3_dev_link_update(dev, wait_to_complete);
1197 /* Updating rxmode through Vmxnet3_DriverShared structure in adapter */
1199 vmxnet3_dev_set_rxmode(struct vmxnet3_hw *hw, uint32_t feature, int set)
1201 struct Vmxnet3_RxFilterConf *rxConf = &hw->shared->devRead.rxFilterConf;
1204 rxConf->rxMode = rxConf->rxMode | feature;
1206 rxConf->rxMode = rxConf->rxMode & (~feature);
1208 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_UPDATE_RX_MODE);
1211 /* Promiscuous supported only if Vmxnet3_DriverShared is initialized in adapter */
1213 vmxnet3_dev_promiscuous_enable(struct rte_eth_dev *dev)
1215 struct vmxnet3_hw *hw = dev->data->dev_private;
1216 uint32_t *vf_table = hw->shared->devRead.rxFilterConf.vfTable;
1218 memset(vf_table, 0, VMXNET3_VFT_TABLE_SIZE);
1219 vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_PROMISC, 1);
1221 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1222 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1225 /* Promiscuous supported only if Vmxnet3_DriverShared is initialized in adapter */
1227 vmxnet3_dev_promiscuous_disable(struct rte_eth_dev *dev)
1229 struct vmxnet3_hw *hw = dev->data->dev_private;
1230 uint32_t *vf_table = hw->shared->devRead.rxFilterConf.vfTable;
1232 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1233 memcpy(vf_table, hw->shadow_vfta, VMXNET3_VFT_TABLE_SIZE);
1235 memset(vf_table, 0xff, VMXNET3_VFT_TABLE_SIZE);
1236 vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_PROMISC, 0);
1237 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1238 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1241 /* Allmulticast supported only if Vmxnet3_DriverShared is initialized in adapter */
1243 vmxnet3_dev_allmulticast_enable(struct rte_eth_dev *dev)
1245 struct vmxnet3_hw *hw = dev->data->dev_private;
1247 vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_ALL_MULTI, 1);
1250 /* Allmulticast supported only if Vmxnet3_DriverShared is initialized in adapter */
1252 vmxnet3_dev_allmulticast_disable(struct rte_eth_dev *dev)
1254 struct vmxnet3_hw *hw = dev->data->dev_private;
1256 vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_ALL_MULTI, 0);
1259 /* Enable/disable filter on vlan */
1261 vmxnet3_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on)
1263 struct vmxnet3_hw *hw = dev->data->dev_private;
1264 struct Vmxnet3_RxFilterConf *rxConf = &hw->shared->devRead.rxFilterConf;
1265 uint32_t *vf_table = rxConf->vfTable;
1267 /* save state for restore */
1269 VMXNET3_SET_VFTABLE_ENTRY(hw->shadow_vfta, vid);
1271 VMXNET3_CLEAR_VFTABLE_ENTRY(hw->shadow_vfta, vid);
1273 /* don't change active filter if in promiscuous mode */
1274 if (rxConf->rxMode & VMXNET3_RXM_PROMISC)
1277 /* set in hardware */
1279 VMXNET3_SET_VFTABLE_ENTRY(vf_table, vid);
1281 VMXNET3_CLEAR_VFTABLE_ENTRY(vf_table, vid);
1283 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1284 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1289 vmxnet3_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1291 struct vmxnet3_hw *hw = dev->data->dev_private;
1292 Vmxnet3_DSDevRead *devRead = &hw->shared->devRead;
1293 uint32_t *vf_table = devRead->rxFilterConf.vfTable;
1295 if (mask & ETH_VLAN_STRIP_MASK) {
1296 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
1297 devRead->misc.uptFeatures |= UPT1_F_RXVLAN;
1299 devRead->misc.uptFeatures &= ~UPT1_F_RXVLAN;
1301 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1302 VMXNET3_CMD_UPDATE_FEATURE);
1305 if (mask & ETH_VLAN_FILTER_MASK) {
1306 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
1307 memcpy(vf_table, hw->shadow_vfta, VMXNET3_VFT_TABLE_SIZE);
1309 memset(vf_table, 0xff, VMXNET3_VFT_TABLE_SIZE);
1311 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1312 VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1319 vmxnet3_process_events(struct rte_eth_dev *dev)
1321 struct vmxnet3_hw *hw = dev->data->dev_private;
1322 uint32_t events = hw->shared->ecr;
1328 * ECR bits when written with 1b are cleared. Hence write
1329 * events back to ECR so that the bits which were set will be reset.
1331 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_ECR, events);
1333 /* Check if link state has changed */
1334 if (events & VMXNET3_ECR_LINK) {
1335 PMD_DRV_LOG(DEBUG, "Process events: VMXNET3_ECR_LINK event");
1336 if (vmxnet3_dev_link_update(dev, 0) == 0)
1337 _rte_eth_dev_callback_process(dev,
1338 RTE_ETH_EVENT_INTR_LSC,
1342 /* Check if there is an error on xmit/recv queues */
1343 if (events & (VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR)) {
1344 VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1345 VMXNET3_CMD_GET_QUEUE_STATUS);
1347 if (hw->tqd_start->status.stopped)
1348 PMD_DRV_LOG(ERR, "tq error 0x%x",
1349 hw->tqd_start->status.error);
1351 if (hw->rqd_start->status.stopped)
1352 PMD_DRV_LOG(ERR, "rq error 0x%x",
1353 hw->rqd_start->status.error);
1355 /* Reset the device */
1356 /* Have to reset the device */
1359 if (events & VMXNET3_ECR_DIC)
1360 PMD_DRV_LOG(DEBUG, "Device implementation change event.");
1362 if (events & VMXNET3_ECR_DEBUG)
1363 PMD_DRV_LOG(DEBUG, "Debug event generated by device.");
1367 vmxnet3_interrupt_handler(void *param)
1369 struct rte_eth_dev *dev = param;
1370 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
1372 vmxnet3_process_events(dev);
1374 if (rte_intr_enable(&pci_dev->intr_handle) < 0)
1375 PMD_DRV_LOG(ERR, "interrupt enable failed");
1378 RTE_PMD_REGISTER_PCI(net_vmxnet3, rte_vmxnet3_pmd);
1379 RTE_PMD_REGISTER_PCI_TABLE(net_vmxnet3, pci_id_vmxnet3_map);
1380 RTE_PMD_REGISTER_KMOD_DEP(net_vmxnet3, "* igb_uio | uio_pci_generic | vfio-pci");