1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
11 #include <ethdev_pci.h>
13 #include "txgbe_logs.h"
14 #include "base/txgbe.h"
15 #include "txgbe_ethdev.h"
16 #include "txgbe_rxtx.h"
17 #include "txgbe_regs_group.h"
19 static const struct reg_info txgbevf_regs_general[] = {
20 {TXGBE_VFRST, 1, 1, "TXGBE_VFRST"},
21 {TXGBE_VFSTATUS, 1, 1, "TXGBE_VFSTATUS"},
22 {TXGBE_VFMBCTL, 1, 1, "TXGBE_VFMAILBOX"},
23 {TXGBE_VFMBX, 16, 4, "TXGBE_VFMBX"},
24 {TXGBE_VFPBWRAP, 1, 1, "TXGBE_VFPBWRAP"},
28 static const struct reg_info txgbevf_regs_interrupt[] = {
32 static const struct reg_info txgbevf_regs_rxdma[] = {
36 static const struct reg_info txgbevf_regs_tx[] = {
41 static const struct reg_info *txgbevf_regs[] = {
43 txgbevf_regs_interrupt,
48 static int txgbevf_dev_xstats_get(struct rte_eth_dev *dev,
49 struct rte_eth_xstat *xstats, unsigned int n);
50 static int txgbevf_dev_info_get(struct rte_eth_dev *dev,
51 struct rte_eth_dev_info *dev_info);
52 static int txgbevf_dev_configure(struct rte_eth_dev *dev);
53 static int txgbevf_dev_link_update(struct rte_eth_dev *dev,
54 int wait_to_complete);
55 static int txgbevf_dev_close(struct rte_eth_dev *dev);
56 static void txgbevf_intr_disable(struct rte_eth_dev *dev);
57 static void txgbevf_intr_enable(struct rte_eth_dev *dev);
58 static int txgbevf_dev_stats_reset(struct rte_eth_dev *dev);
59 static int txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
60 static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
61 static void txgbevf_configure_msix(struct rte_eth_dev *dev);
62 static int txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev);
63 static int txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev);
64 static void txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
65 static void txgbevf_dev_interrupt_handler(void *param);
68 * The set of PCI devices this driver supports (for VF)
70 static const struct rte_pci_id pci_id_txgbevf_map[] = {
71 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_VF) },
72 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_VF_HV) },
73 { .vendor_id = 0, /* sentinel */ },
76 static const struct rte_eth_desc_lim rx_desc_lim = {
77 .nb_max = TXGBE_RING_DESC_MAX,
78 .nb_min = TXGBE_RING_DESC_MIN,
79 .nb_align = TXGBE_RXD_ALIGN,
82 static const struct rte_eth_desc_lim tx_desc_lim = {
83 .nb_max = TXGBE_RING_DESC_MAX,
84 .nb_min = TXGBE_RING_DESC_MIN,
85 .nb_align = TXGBE_TXD_ALIGN,
86 .nb_seg_max = TXGBE_TX_MAX_SEG,
87 .nb_mtu_seg_max = TXGBE_TX_MAX_SEG,
90 static const struct eth_dev_ops txgbevf_eth_dev_ops;
92 static const struct rte_txgbe_xstats_name_off rte_txgbevf_stats_strings[] = {
93 {"rx_multicast_packets_0",
94 offsetof(struct txgbevf_hw_stats, qp[0].vfmprc)},
95 {"rx_multicast_packets_1",
96 offsetof(struct txgbevf_hw_stats, qp[1].vfmprc)},
97 {"rx_multicast_packets_2",
98 offsetof(struct txgbevf_hw_stats, qp[2].vfmprc)},
99 {"rx_multicast_packets_3",
100 offsetof(struct txgbevf_hw_stats, qp[3].vfmprc)},
101 {"rx_multicast_packets_4",
102 offsetof(struct txgbevf_hw_stats, qp[4].vfmprc)},
103 {"rx_multicast_packets_5",
104 offsetof(struct txgbevf_hw_stats, qp[5].vfmprc)},
105 {"rx_multicast_packets_6",
106 offsetof(struct txgbevf_hw_stats, qp[6].vfmprc)},
107 {"rx_multicast_packets_7",
108 offsetof(struct txgbevf_hw_stats, qp[7].vfmprc)}
111 #define TXGBEVF_NB_XSTATS (sizeof(rte_txgbevf_stats_strings) / \
112 sizeof(rte_txgbevf_stats_strings[0]))
115 * Negotiate mailbox API version with the PF.
116 * After reset API version is always set to the basic one (txgbe_mbox_api_10).
117 * Then we try to negotiate starting with the most recent one.
118 * If all negotiation attempts fail, then we will proceed with
119 * the default one (txgbe_mbox_api_10).
122 txgbevf_negotiate_api(struct txgbe_hw *hw)
126 /* start with highest supported, proceed down */
127 static const int sup_ver[] = {
134 for (i = 0; i < ARRAY_SIZE(sup_ver); i++) {
135 if (txgbevf_negotiate_api_version(hw, sup_ver[i]) == 0)
141 generate_random_mac_addr(struct rte_ether_addr *mac_addr)
145 /* Set Organizationally Unique Identifier (OUI) prefix. */
146 mac_addr->addr_bytes[0] = 0x00;
147 mac_addr->addr_bytes[1] = 0x09;
148 mac_addr->addr_bytes[2] = 0xC0;
149 /* Force indication of locally assigned MAC address. */
150 mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
151 /* Generate the last 3 bytes of the MAC address with a random number. */
153 memcpy(&mac_addr->addr_bytes[3], &random, 3);
157 * Virtual Function device init
160 eth_txgbevf_dev_init(struct rte_eth_dev *eth_dev)
164 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
165 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
166 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
167 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(eth_dev);
168 struct txgbe_hwstrip *hwstrip = TXGBE_DEV_HWSTRIP(eth_dev);
169 struct rte_ether_addr *perm_addr =
170 (struct rte_ether_addr *)hw->mac.perm_addr;
172 PMD_INIT_FUNC_TRACE();
174 eth_dev->dev_ops = &txgbevf_eth_dev_ops;
175 eth_dev->rx_descriptor_status = txgbe_dev_rx_descriptor_status;
176 eth_dev->tx_descriptor_status = txgbe_dev_tx_descriptor_status;
177 eth_dev->rx_pkt_burst = &txgbe_recv_pkts;
178 eth_dev->tx_pkt_burst = &txgbe_xmit_pkts;
180 /* for secondary processes, we don't initialise any further as primary
181 * has already done this work. Only check we don't need a different
184 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
185 struct txgbe_tx_queue *txq;
186 uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
187 /* TX queue function in primary, set by last queue initialized
188 * Tx queue may not initialized by primary process
190 if (eth_dev->data->tx_queues) {
191 txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
192 txgbe_set_tx_function(eth_dev, txq);
194 /* Use default TX function if we get here */
196 "No TX queues configured yet. Using default TX function.");
199 txgbe_set_rx_function(eth_dev);
204 rte_eth_copy_pci_info(eth_dev, pci_dev);
206 hw->device_id = pci_dev->id.device_id;
207 hw->vendor_id = pci_dev->id.vendor_id;
208 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
209 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
210 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
212 /* initialize the vfta */
213 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
215 /* initialize the hw strip bitmap*/
216 memset(hwstrip, 0, sizeof(*hwstrip));
218 /* Initialize the shared code (base driver) */
219 err = txgbe_init_shared_code(hw);
222 "Shared code init failed for txgbevf: %d", err);
226 /* init_mailbox_params */
227 hw->mbx.init_params(hw);
229 /* Reset the hw statistics */
230 txgbevf_dev_stats_reset(eth_dev);
232 /* Disable the interrupts for VF */
233 txgbevf_intr_disable(eth_dev);
235 hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
236 err = hw->mac.reset_hw(hw);
239 * The VF reset operation returns the TXGBE_ERR_INVALID_MAC_ADDR when
240 * the underlying PF driver has not assigned a MAC address to the VF.
241 * In this case, assign a random MAC address.
243 if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
244 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
246 * This error code will be propagated to the app by
247 * rte_eth_dev_reset, so use a public error code rather than
248 * the internal-only TXGBE_ERR_RESET_FAILED
253 /* negotiate mailbox API version to use with the PF. */
254 txgbevf_negotiate_api(hw);
256 /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
257 txgbevf_get_queues(hw, &tcs, &tc);
259 /* Allocate memory for storing MAC addresses */
260 eth_dev->data->mac_addrs = rte_zmalloc("txgbevf", RTE_ETHER_ADDR_LEN *
261 hw->mac.num_rar_entries, 0);
262 if (eth_dev->data->mac_addrs == NULL) {
264 "Failed to allocate %u bytes needed to store "
266 RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
270 /* Generate a random MAC address, if none was assigned by PF. */
271 if (rte_is_zero_ether_addr(perm_addr)) {
272 generate_random_mac_addr(perm_addr);
273 err = txgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
275 rte_free(eth_dev->data->mac_addrs);
276 eth_dev->data->mac_addrs = NULL;
279 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
280 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
281 "%02x:%02x:%02x:%02x:%02x:%02x",
282 perm_addr->addr_bytes[0],
283 perm_addr->addr_bytes[1],
284 perm_addr->addr_bytes[2],
285 perm_addr->addr_bytes[3],
286 perm_addr->addr_bytes[4],
287 perm_addr->addr_bytes[5]);
290 /* Copy the permanent MAC address */
291 rte_ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
293 /* reset the hardware with the new settings */
294 err = hw->mac.start_hw(hw);
296 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
300 /* enter promiscuous mode */
301 txgbevf_dev_promiscuous_enable(eth_dev);
303 rte_intr_callback_register(intr_handle,
304 txgbevf_dev_interrupt_handler, eth_dev);
305 rte_intr_enable(intr_handle);
306 txgbevf_intr_enable(eth_dev);
308 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
309 eth_dev->data->port_id, pci_dev->id.vendor_id,
310 pci_dev->id.device_id, "txgbe_mac_raptor_vf");
315 /* Virtual Function device uninit */
317 eth_txgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
319 PMD_INIT_FUNC_TRACE();
321 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
324 txgbevf_dev_close(eth_dev);
329 static int eth_txgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
330 struct rte_pci_device *pci_dev)
332 return rte_eth_dev_pci_generic_probe(pci_dev,
333 sizeof(struct txgbe_adapter), eth_txgbevf_dev_init);
336 static int eth_txgbevf_pci_remove(struct rte_pci_device *pci_dev)
338 return rte_eth_dev_pci_generic_remove(pci_dev, eth_txgbevf_dev_uninit);
342 * virtual function driver struct
344 static struct rte_pci_driver rte_txgbevf_pmd = {
345 .id_table = pci_id_txgbevf_map,
346 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
347 .probe = eth_txgbevf_pci_probe,
348 .remove = eth_txgbevf_pci_remove,
351 static int txgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
352 struct rte_eth_xstat_name *xstats_names, unsigned int limit)
356 if (limit < TXGBEVF_NB_XSTATS && xstats_names != NULL)
359 if (xstats_names != NULL)
360 for (i = 0; i < TXGBEVF_NB_XSTATS; i++)
361 snprintf(xstats_names[i].name,
362 sizeof(xstats_names[i].name),
363 "%s", rte_txgbevf_stats_strings[i].name);
364 return TXGBEVF_NB_XSTATS;
368 txgbevf_update_stats(struct rte_eth_dev *dev)
370 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
371 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
372 TXGBE_DEV_STATS(dev);
375 for (i = 0; i < dev->data->nb_rx_queues; i++) {
376 /* Good Rx packet, include VF loopback */
377 TXGBE_UPDCNT32(TXGBE_QPRXPKT(i),
378 hw_stats->qp[i].last_vfgprc, hw_stats->qp[i].vfgprc);
380 /* Good Rx octets, include VF loopback */
381 TXGBE_UPDCNT36(TXGBE_QPRXOCTL(i),
382 hw_stats->qp[i].last_vfgorc, hw_stats->qp[i].vfgorc);
384 /* Rx Multicst Packet */
385 TXGBE_UPDCNT32(TXGBE_QPRXMPKT(i),
386 hw_stats->qp[i].last_vfmprc, hw_stats->qp[i].vfmprc);
390 for (i = 0; i < dev->data->nb_tx_queues; i++) {
391 /* Good Tx packet, include VF loopback */
392 TXGBE_UPDCNT32(TXGBE_QPTXPKT(i),
393 hw_stats->qp[i].last_vfgptc, hw_stats->qp[i].vfgptc);
395 /* Good Tx octets, include VF loopback */
396 TXGBE_UPDCNT36(TXGBE_QPTXOCTL(i),
397 hw_stats->qp[i].last_vfgotc, hw_stats->qp[i].vfgotc);
399 hw->offset_loaded = 0;
403 txgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
406 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
407 TXGBE_DEV_STATS(dev);
410 if (n < TXGBEVF_NB_XSTATS)
411 return TXGBEVF_NB_XSTATS;
413 txgbevf_update_stats(dev);
419 for (i = 0; i < TXGBEVF_NB_XSTATS; i++) {
421 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
422 rte_txgbevf_stats_strings[i].offset);
425 return TXGBEVF_NB_XSTATS;
429 txgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
431 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
432 TXGBE_DEV_STATS(dev);
435 txgbevf_update_stats(dev);
445 for (i = 0; i < 8; i++) {
446 stats->ipackets += hw_stats->qp[i].vfgprc;
447 stats->ibytes += hw_stats->qp[i].vfgorc;
448 stats->opackets += hw_stats->qp[i].vfgptc;
449 stats->obytes += hw_stats->qp[i].vfgotc;
456 txgbevf_dev_stats_reset(struct rte_eth_dev *dev)
458 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
459 TXGBE_DEV_STATS(dev);
462 /* Sync HW register to the last stats */
463 txgbevf_dev_stats_get(dev, NULL);
465 /* reset HW current stats*/
466 for (i = 0; i < 8; i++) {
467 hw_stats->qp[i].vfgprc = 0;
468 hw_stats->qp[i].vfgorc = 0;
469 hw_stats->qp[i].vfgptc = 0;
470 hw_stats->qp[i].vfgotc = 0;
477 txgbevf_dev_info_get(struct rte_eth_dev *dev,
478 struct rte_eth_dev_info *dev_info)
480 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
481 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
483 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
484 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
485 dev_info->min_rx_bufsize = 1024;
486 dev_info->max_rx_pktlen = TXGBE_FRAME_SIZE_MAX;
487 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
488 dev_info->max_hash_mac_addrs = TXGBE_VMDQ_NUM_UC_MAC;
489 dev_info->max_vfs = pci_dev->max_vfs;
490 dev_info->max_vmdq_pools = ETH_64_POOLS;
491 dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
492 dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
493 dev_info->rx_queue_offload_capa);
494 dev_info->tx_queue_offload_capa = txgbe_get_tx_queue_offloads(dev);
495 dev_info->tx_offload_capa = txgbe_get_tx_port_offloads(dev);
496 dev_info->hash_key_size = TXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
497 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
498 dev_info->flow_type_rss_offloads = TXGBE_RSS_OFFLOAD_ALL;
500 dev_info->default_rxconf = (struct rte_eth_rxconf) {
502 .pthresh = TXGBE_DEFAULT_RX_PTHRESH,
503 .hthresh = TXGBE_DEFAULT_RX_HTHRESH,
504 .wthresh = TXGBE_DEFAULT_RX_WTHRESH,
506 .rx_free_thresh = TXGBE_DEFAULT_RX_FREE_THRESH,
511 dev_info->default_txconf = (struct rte_eth_txconf) {
513 .pthresh = TXGBE_DEFAULT_TX_PTHRESH,
514 .hthresh = TXGBE_DEFAULT_TX_HTHRESH,
515 .wthresh = TXGBE_DEFAULT_TX_WTHRESH,
517 .tx_free_thresh = TXGBE_DEFAULT_TX_FREE_THRESH,
521 dev_info->rx_desc_lim = rx_desc_lim;
522 dev_info->tx_desc_lim = tx_desc_lim;
528 txgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
530 return txgbe_dev_link_update_share(dev, wait_to_complete);
534 * Virtual Function operations
537 txgbevf_intr_disable(struct rte_eth_dev *dev)
539 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
540 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
542 PMD_INIT_FUNC_TRACE();
544 /* Clear interrupt mask to stop from interrupts being generated */
545 wr32(hw, TXGBE_VFIMS, TXGBE_VFIMS_MASK);
549 /* Clear mask value. */
550 intr->mask_misc = TXGBE_VFIMS_MASK;
554 txgbevf_intr_enable(struct rte_eth_dev *dev)
556 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
557 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
559 PMD_INIT_FUNC_TRACE();
561 /* VF enable interrupt autoclean */
562 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
570 txgbevf_dev_configure(struct rte_eth_dev *dev)
572 struct rte_eth_conf *conf = &dev->data->dev_conf;
573 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
575 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
578 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
579 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
582 * VF has no ability to enable/disable HW CRC
583 * Keep the persistent behavior the same as Host PF
585 #ifndef RTE_LIBRTE_TXGBE_PF_DISABLE_STRIP_CRC
586 if (conf->rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC) {
587 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
588 conf->rxmode.offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
591 if (!(conf->rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)) {
592 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
593 conf->rxmode.offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
598 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
599 * allocation or vector Rx preconditions we will reset it.
601 adapter->rx_bulk_alloc_allowed = true;
607 txgbevf_dev_close(struct rte_eth_dev *dev)
609 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
610 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
611 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
612 PMD_INIT_FUNC_TRACE();
613 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
616 hw->mac.reset_hw(hw);
618 txgbe_dev_free_queues(dev);
621 * Remove the VF MAC address ro ensure
622 * that the VF traffic goes to the PF
623 * after stop, close and detach of the VF
625 txgbevf_remove_mac_addr(dev, 0);
627 dev->rx_pkt_burst = NULL;
628 dev->tx_pkt_burst = NULL;
630 /* Disable the interrupts for VF */
631 txgbevf_intr_disable(dev);
633 rte_free(dev->data->mac_addrs);
634 dev->data->mac_addrs = NULL;
636 rte_intr_disable(intr_handle);
637 rte_intr_callback_unregister(intr_handle,
638 txgbevf_dev_interrupt_handler, dev);
643 static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
645 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
646 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
647 int i = 0, j = 0, vfta = 0, mask = 1;
649 for (i = 0; i < TXGBE_VFTA_SIZE; i++) {
650 vfta = shadow_vfta->vfta[i];
653 for (j = 0; j < 32; j++) {
655 txgbe_set_vfta(hw, (i << 5) + j, 0,
664 txgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
666 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
667 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
668 uint32_t vid_idx = 0;
669 uint32_t vid_bit = 0;
672 PMD_INIT_FUNC_TRACE();
674 /* vind is not used in VF driver, set to 0, check txgbe_set_vfta_vf */
675 ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
677 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
680 vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
681 vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
683 /* Save what we set and restore it after device reset */
685 shadow_vfta->vfta[vid_idx] |= vid_bit;
687 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
693 txgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
695 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
698 PMD_INIT_FUNC_TRACE();
700 if (queue >= hw->mac.max_rx_queues)
703 ctrl = rd32(hw, TXGBE_RXCFG(queue));
704 txgbe_dev_save_rx_queue(hw, queue);
706 ctrl |= TXGBE_RXCFG_VLAN;
708 ctrl &= ~TXGBE_RXCFG_VLAN;
709 wr32(hw, TXGBE_RXCFG(queue), 0);
711 txgbe_dev_store_rx_queue(hw, queue);
712 wr32m(hw, TXGBE_RXCFG(queue),
713 TXGBE_RXCFG_VLAN | TXGBE_RXCFG_ENA, ctrl);
715 txgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
719 txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
721 struct txgbe_rx_queue *rxq;
725 /* VF function only support hw strip feature, others are not support */
726 if (mask & ETH_VLAN_STRIP_MASK) {
727 for (i = 0; i < dev->data->nb_rx_queues; i++) {
728 rxq = dev->data->rx_queues[i];
729 on = !!(rxq->offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
730 txgbevf_vlan_strip_queue_set(dev, i, on);
738 txgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
740 txgbe_config_vlan_strip_on_all_queues(dev, mask);
742 txgbevf_vlan_offload_config(dev, mask);
748 txgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
750 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
751 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
752 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
753 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
754 uint32_t vec = TXGBE_MISC_VEC_ID;
756 if (rte_intr_allow_others(intr_handle))
757 vec = TXGBE_RX_VEC_START;
758 intr->mask_misc &= ~(1 << vec);
759 RTE_SET_USED(queue_id);
760 wr32(hw, TXGBE_VFIMC, ~intr->mask_misc);
762 rte_intr_enable(intr_handle);
768 txgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
770 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
771 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
772 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
773 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
774 uint32_t vec = TXGBE_MISC_VEC_ID;
776 if (rte_intr_allow_others(intr_handle))
777 vec = TXGBE_RX_VEC_START;
778 intr->mask_misc |= (1 << vec);
779 RTE_SET_USED(queue_id);
780 wr32(hw, TXGBE_VFIMS, intr->mask_misc);
786 txgbevf_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
787 uint8_t queue, uint8_t msix_vector)
791 if (direction == -1) {
793 msix_vector |= TXGBE_VFIVAR_VLD;
794 tmp = rd32(hw, TXGBE_VFIVARMISC);
797 wr32(hw, TXGBE_VFIVARMISC, tmp);
800 /* Workround for ICR lost */
801 idx = ((16 * (queue & 1)) + (8 * direction));
802 tmp = rd32(hw, TXGBE_VFIVAR(queue >> 1));
803 tmp &= ~(0xFF << idx);
804 tmp |= (msix_vector << idx);
805 wr32(hw, TXGBE_VFIVAR(queue >> 1), tmp);
810 txgbevf_configure_msix(struct rte_eth_dev *dev)
812 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
813 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
814 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
816 uint32_t vector_idx = TXGBE_MISC_VEC_ID;
817 uint32_t base = TXGBE_MISC_VEC_ID;
819 /* Configure VF other cause ivar */
820 txgbevf_set_ivar_map(hw, -1, 1, vector_idx);
822 /* won't configure msix register if no mapping is done
823 * between intr vector and event fd.
825 if (!rte_intr_dp_is_en(intr_handle))
828 if (rte_intr_allow_others(intr_handle)) {
829 base = TXGBE_RX_VEC_START;
830 vector_idx = TXGBE_RX_VEC_START;
833 /* Configure all RX queues of VF */
834 for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
835 /* Force all queue use vector 0,
836 * as TXGBE_VF_MAXMSIVECOTR = 1
838 txgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
839 intr_handle->intr_vec[q_idx] = vector_idx;
840 if (vector_idx < base + intr_handle->nb_efd - 1)
844 /* As RX queue setting above show, all queues use the vector 0.
845 * Set only the ITR value of TXGBE_MISC_VEC_ID.
847 wr32(hw, TXGBE_ITR(TXGBE_MISC_VEC_ID),
848 TXGBE_ITR_IVAL(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
853 txgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
854 __rte_unused uint32_t index,
855 __rte_unused uint32_t pool)
857 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
861 * On a VF, adding again the same MAC addr is not an idempotent
862 * operation. Trap this case to avoid exhausting the [very limited]
863 * set of PF resources used to store VF MAC addresses.
865 if (memcmp(hw->mac.perm_addr, mac_addr,
866 sizeof(struct rte_ether_addr)) == 0)
868 err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
870 PMD_DRV_LOG(ERR, "Unable to add MAC address "
871 "%02x:%02x:%02x:%02x:%02x:%02x - err=%d",
872 mac_addr->addr_bytes[0],
873 mac_addr->addr_bytes[1],
874 mac_addr->addr_bytes[2],
875 mac_addr->addr_bytes[3],
876 mac_addr->addr_bytes[4],
877 mac_addr->addr_bytes[5],
883 txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
885 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
886 struct rte_ether_addr *perm_addr =
887 (struct rte_ether_addr *)hw->mac.perm_addr;
888 struct rte_ether_addr *mac_addr;
893 * The TXGBE_VF_SET_MACVLAN command of the txgbe-pf driver does
894 * not support the deletion of a given MAC address.
895 * Instead, it imposes to delete all MAC addresses, then to add again
896 * all MAC addresses with the exception of the one to be deleted.
898 (void)txgbevf_set_uc_addr_vf(hw, 0, NULL);
901 * Add again all MAC addresses, with the exception of the deleted one
902 * and of the permanent MAC address.
904 for (i = 0, mac_addr = dev->data->mac_addrs;
905 i < hw->mac.num_rar_entries; i++, mac_addr++) {
906 /* Skip the deleted MAC address */
909 /* Skip NULL MAC addresses */
910 if (rte_is_zero_ether_addr(mac_addr))
912 /* Skip the permanent MAC address */
913 if (memcmp(perm_addr, mac_addr,
914 sizeof(struct rte_ether_addr)) == 0)
916 err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
919 "Adding again MAC address "
920 "%02x:%02x:%02x:%02x:%02x:%02x failed "
922 mac_addr->addr_bytes[0],
923 mac_addr->addr_bytes[1],
924 mac_addr->addr_bytes[2],
925 mac_addr->addr_bytes[3],
926 mac_addr->addr_bytes[4],
927 mac_addr->addr_bytes[5],
933 txgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
934 struct rte_ether_addr *addr)
936 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
938 hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
944 txgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
947 uint32_t max_frame = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
948 struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
950 hw = TXGBE_DEV_HW(dev);
952 if (mtu < RTE_ETHER_MIN_MTU ||
953 max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
956 /* refuse mtu that requires the support of scattered packets when this
957 * feature has not been enabled before.
959 if (!(rx_conf->offloads & DEV_RX_OFFLOAD_SCATTER) &&
960 (max_frame + 2 * TXGBE_VLAN_TAG_SIZE >
961 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM))
965 * When supported by the underlying PF driver, use the TXGBE_VF_SET_MTU
966 * request of the version 2.0 of the mailbox API.
967 * For now, use the TXGBE_VF_SET_LPE request of the version 1.0
968 * of the mailbox API.
970 if (txgbevf_rlpml_set_vf(hw, max_frame))
973 /* update max frame size */
974 dev->data->dev_conf.rxmode.max_rx_pkt_len = max_frame;
979 txgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
983 const struct reg_info *reg_group;
985 while ((reg_group = txgbevf_regs[g_ind++]))
986 count += txgbe_regs_group_count(reg_group);
992 txgbevf_get_regs(struct rte_eth_dev *dev,
993 struct rte_dev_reg_info *regs)
995 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
996 uint32_t *data = regs->data;
999 const struct reg_info *reg_group;
1002 regs->length = txgbevf_get_reg_length(dev);
1003 regs->width = sizeof(uint32_t);
1007 /* Support only full register dump */
1008 if (regs->length == 0 ||
1009 regs->length == (uint32_t)txgbevf_get_reg_length(dev)) {
1010 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
1012 while ((reg_group = txgbevf_regs[g_ind++]))
1013 count += txgbe_read_regs_group(dev, &data[count],
1022 txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1024 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1027 switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_PROMISC)) {
1031 case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1043 txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1045 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1048 switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_NONE)) {
1052 case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1064 txgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1066 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1069 switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_ALLMULTI)) {
1073 case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1085 txgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1087 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1090 switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_MULTI)) {
1094 case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1105 static void txgbevf_mbx_process(struct rte_eth_dev *dev)
1107 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1110 /* peek the message first */
1111 in_msg = rd32(hw, TXGBE_VFMBX);
1113 /* PF reset VF event */
1114 if (in_msg == TXGBE_PF_CONTROL_MSG) {
1115 /* dummy mbx read to ack pf */
1116 if (txgbe_read_mbx(hw, &in_msg, 1, 0))
1118 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
1124 txgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
1127 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1128 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1129 txgbevf_intr_disable(dev);
1131 /* read-on-clear nic registers here */
1132 eicr = rd32(hw, TXGBE_VFICR);
1135 /* only one misc vector supported - mailbox */
1136 eicr &= TXGBE_VFICR_MASK;
1137 /* Workround for ICR lost */
1138 intr->flags |= TXGBE_FLAG_MAILBOX;
1144 txgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
1146 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1148 if (intr->flags & TXGBE_FLAG_MAILBOX) {
1149 txgbevf_mbx_process(dev);
1150 intr->flags &= ~TXGBE_FLAG_MAILBOX;
1153 txgbevf_intr_enable(dev);
1159 txgbevf_dev_interrupt_handler(void *param)
1161 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1163 txgbevf_dev_interrupt_get_status(dev);
1164 txgbevf_dev_interrupt_action(dev);
1168 * dev_ops for virtual function, bare necessities for basic vf
1169 * operation have been implemented
1171 static const struct eth_dev_ops txgbevf_eth_dev_ops = {
1172 .dev_configure = txgbevf_dev_configure,
1173 .link_update = txgbevf_dev_link_update,
1174 .stats_get = txgbevf_dev_stats_get,
1175 .xstats_get = txgbevf_dev_xstats_get,
1176 .stats_reset = txgbevf_dev_stats_reset,
1177 .xstats_reset = txgbevf_dev_stats_reset,
1178 .xstats_get_names = txgbevf_dev_xstats_get_names,
1179 .promiscuous_enable = txgbevf_dev_promiscuous_enable,
1180 .promiscuous_disable = txgbevf_dev_promiscuous_disable,
1181 .allmulticast_enable = txgbevf_dev_allmulticast_enable,
1182 .allmulticast_disable = txgbevf_dev_allmulticast_disable,
1183 .dev_infos_get = txgbevf_dev_info_get,
1184 .mtu_set = txgbevf_dev_set_mtu,
1185 .vlan_filter_set = txgbevf_vlan_filter_set,
1186 .vlan_strip_queue_set = txgbevf_vlan_strip_queue_set,
1187 .vlan_offload_set = txgbevf_vlan_offload_set,
1188 .rx_queue_intr_enable = txgbevf_dev_rx_queue_intr_enable,
1189 .rx_queue_intr_disable = txgbevf_dev_rx_queue_intr_disable,
1190 .mac_addr_add = txgbevf_add_mac_addr,
1191 .mac_addr_remove = txgbevf_remove_mac_addr,
1192 .set_mc_addr_list = txgbe_dev_set_mc_addr_list,
1193 .rxq_info_get = txgbe_rxq_info_get,
1194 .txq_info_get = txgbe_txq_info_get,
1195 .mac_addr_set = txgbevf_set_default_mac_addr,
1196 .get_reg = txgbevf_get_regs,
1197 .reta_update = txgbe_dev_rss_reta_update,
1198 .reta_query = txgbe_dev_rss_reta_query,
1199 .rss_hash_update = txgbe_dev_rss_hash_update,
1200 .rss_hash_conf_get = txgbe_dev_rss_hash_conf_get,
1203 RTE_PMD_REGISTER_PCI(net_txgbe_vf, rte_txgbevf_pmd);
1204 RTE_PMD_REGISTER_PCI_TABLE(net_txgbe_vf, pci_id_txgbevf_map);
1205 RTE_PMD_REGISTER_KMOD_DEP(net_txgbe_vf, "* igb_uio | vfio-pci");