1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
12 #include <ethdev_pci.h>
13 #include <rte_alarm.h>
15 #include "txgbe_logs.h"
16 #include "base/txgbe.h"
17 #include "txgbe_ethdev.h"
18 #include "txgbe_rxtx.h"
19 #include "txgbe_regs_group.h"
21 static const struct reg_info txgbevf_regs_general[] = {
22 {TXGBE_VFRST, 1, 1, "TXGBE_VFRST"},
23 {TXGBE_VFSTATUS, 1, 1, "TXGBE_VFSTATUS"},
24 {TXGBE_VFMBCTL, 1, 1, "TXGBE_VFMAILBOX"},
25 {TXGBE_VFMBX, 16, 4, "TXGBE_VFMBX"},
26 {TXGBE_VFPBWRAP, 1, 1, "TXGBE_VFPBWRAP"},
30 static const struct reg_info txgbevf_regs_interrupt[] = {
34 static const struct reg_info txgbevf_regs_rxdma[] = {
38 static const struct reg_info txgbevf_regs_tx[] = {
43 static const struct reg_info *txgbevf_regs[] = {
45 txgbevf_regs_interrupt,
50 static int txgbevf_dev_xstats_get(struct rte_eth_dev *dev,
51 struct rte_eth_xstat *xstats, unsigned int n);
52 static int txgbevf_dev_info_get(struct rte_eth_dev *dev,
53 struct rte_eth_dev_info *dev_info);
54 static int txgbevf_dev_configure(struct rte_eth_dev *dev);
55 static int txgbevf_dev_start(struct rte_eth_dev *dev);
56 static int txgbevf_dev_link_update(struct rte_eth_dev *dev,
57 int wait_to_complete);
58 static int txgbevf_dev_stop(struct rte_eth_dev *dev);
59 static int txgbevf_dev_close(struct rte_eth_dev *dev);
60 static void txgbevf_intr_disable(struct rte_eth_dev *dev);
61 static void txgbevf_intr_enable(struct rte_eth_dev *dev);
62 static int txgbevf_dev_stats_reset(struct rte_eth_dev *dev);
63 static int txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
64 static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
65 static void txgbevf_configure_msix(struct rte_eth_dev *dev);
66 static int txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev);
67 static int txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev);
68 static void txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
69 static void txgbevf_dev_interrupt_handler(void *param);
72 * The set of PCI devices this driver supports (for VF)
74 static const struct rte_pci_id pci_id_txgbevf_map[] = {
75 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_SP1000_VF) },
76 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_WX1820_VF) },
77 { .vendor_id = 0, /* sentinel */ },
80 static const struct rte_eth_desc_lim rx_desc_lim = {
81 .nb_max = TXGBE_RING_DESC_MAX,
82 .nb_min = TXGBE_RING_DESC_MIN,
83 .nb_align = TXGBE_RXD_ALIGN,
86 static const struct rte_eth_desc_lim tx_desc_lim = {
87 .nb_max = TXGBE_RING_DESC_MAX,
88 .nb_min = TXGBE_RING_DESC_MIN,
89 .nb_align = TXGBE_TXD_ALIGN,
90 .nb_seg_max = TXGBE_TX_MAX_SEG,
91 .nb_mtu_seg_max = TXGBE_TX_MAX_SEG,
94 static const struct eth_dev_ops txgbevf_eth_dev_ops;
96 static const struct rte_txgbe_xstats_name_off rte_txgbevf_stats_strings[] = {
97 {"rx_multicast_packets_0",
98 offsetof(struct txgbevf_hw_stats, qp[0].vfmprc)},
99 {"rx_multicast_packets_1",
100 offsetof(struct txgbevf_hw_stats, qp[1].vfmprc)},
101 {"rx_multicast_packets_2",
102 offsetof(struct txgbevf_hw_stats, qp[2].vfmprc)},
103 {"rx_multicast_packets_3",
104 offsetof(struct txgbevf_hw_stats, qp[3].vfmprc)},
105 {"rx_multicast_packets_4",
106 offsetof(struct txgbevf_hw_stats, qp[4].vfmprc)},
107 {"rx_multicast_packets_5",
108 offsetof(struct txgbevf_hw_stats, qp[5].vfmprc)},
109 {"rx_multicast_packets_6",
110 offsetof(struct txgbevf_hw_stats, qp[6].vfmprc)},
111 {"rx_multicast_packets_7",
112 offsetof(struct txgbevf_hw_stats, qp[7].vfmprc)}
115 #define TXGBEVF_NB_XSTATS (sizeof(rte_txgbevf_stats_strings) / \
116 sizeof(rte_txgbevf_stats_strings[0]))
119 * Negotiate mailbox API version with the PF.
120 * After reset API version is always set to the basic one (txgbe_mbox_api_10).
121 * Then we try to negotiate starting with the most recent one.
122 * If all negotiation attempts fail, then we will proceed with
123 * the default one (txgbe_mbox_api_10).
126 txgbevf_negotiate_api(struct txgbe_hw *hw)
130 /* start with highest supported, proceed down */
131 static const int sup_ver[] = {
138 for (i = 0; i < ARRAY_SIZE(sup_ver); i++) {
139 if (txgbevf_negotiate_api_version(hw, sup_ver[i]) == 0)
145 generate_random_mac_addr(struct rte_ether_addr *mac_addr)
149 /* Set Organizationally Unique Identifier (OUI) prefix. */
150 mac_addr->addr_bytes[0] = 0x00;
151 mac_addr->addr_bytes[1] = 0x09;
152 mac_addr->addr_bytes[2] = 0xC0;
153 /* Force indication of locally assigned MAC address. */
154 mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
155 /* Generate the last 3 bytes of the MAC address with a random number. */
157 memcpy(&mac_addr->addr_bytes[3], &random, 3);
161 * Virtual Function device init
164 eth_txgbevf_dev_init(struct rte_eth_dev *eth_dev)
168 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
169 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
170 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
171 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(eth_dev);
172 struct txgbe_hwstrip *hwstrip = TXGBE_DEV_HWSTRIP(eth_dev);
173 struct rte_ether_addr *perm_addr =
174 (struct rte_ether_addr *)hw->mac.perm_addr;
176 PMD_INIT_FUNC_TRACE();
178 eth_dev->dev_ops = &txgbevf_eth_dev_ops;
179 eth_dev->rx_descriptor_status = txgbe_dev_rx_descriptor_status;
180 eth_dev->tx_descriptor_status = txgbe_dev_tx_descriptor_status;
181 eth_dev->rx_pkt_burst = &txgbe_recv_pkts;
182 eth_dev->tx_pkt_burst = &txgbe_xmit_pkts;
184 /* for secondary processes, we don't initialise any further as primary
185 * has already done this work. Only check we don't need a different
188 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
189 struct txgbe_tx_queue *txq;
190 uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
191 /* TX queue function in primary, set by last queue initialized
192 * Tx queue may not initialized by primary process
194 if (eth_dev->data->tx_queues) {
195 txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
196 txgbe_set_tx_function(eth_dev, txq);
198 /* Use default TX function if we get here */
200 "No TX queues configured yet. Using default TX function.");
203 txgbe_set_rx_function(eth_dev);
208 rte_eth_copy_pci_info(eth_dev, pci_dev);
210 hw->device_id = pci_dev->id.device_id;
211 hw->vendor_id = pci_dev->id.vendor_id;
212 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
213 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
214 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
216 /* initialize the vfta */
217 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
219 /* initialize the hw strip bitmap*/
220 memset(hwstrip, 0, sizeof(*hwstrip));
222 /* Initialize the shared code (base driver) */
223 err = txgbe_init_shared_code(hw);
226 "Shared code init failed for txgbevf: %d", err);
230 /* init_mailbox_params */
231 hw->mbx.init_params(hw);
233 /* Reset the hw statistics */
234 txgbevf_dev_stats_reset(eth_dev);
236 /* Disable the interrupts for VF */
237 txgbevf_intr_disable(eth_dev);
239 hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
240 err = hw->mac.reset_hw(hw);
243 * The VF reset operation returns the TXGBE_ERR_INVALID_MAC_ADDR when
244 * the underlying PF driver has not assigned a MAC address to the VF.
245 * In this case, assign a random MAC address.
247 if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
248 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
250 * This error code will be propagated to the app by
251 * rte_eth_dev_reset, so use a public error code rather than
252 * the internal-only TXGBE_ERR_RESET_FAILED
257 /* negotiate mailbox API version to use with the PF. */
258 txgbevf_negotiate_api(hw);
260 /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
261 txgbevf_get_queues(hw, &tcs, &tc);
263 /* Allocate memory for storing MAC addresses */
264 eth_dev->data->mac_addrs = rte_zmalloc("txgbevf", RTE_ETHER_ADDR_LEN *
265 hw->mac.num_rar_entries, 0);
266 if (eth_dev->data->mac_addrs == NULL) {
268 "Failed to allocate %u bytes needed to store "
270 RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
274 /* Generate a random MAC address, if none was assigned by PF. */
275 if (rte_is_zero_ether_addr(perm_addr)) {
276 generate_random_mac_addr(perm_addr);
277 err = txgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
279 rte_free(eth_dev->data->mac_addrs);
280 eth_dev->data->mac_addrs = NULL;
283 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
284 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
285 RTE_ETHER_ADDR_PRT_FMT,
286 RTE_ETHER_ADDR_BYTES(perm_addr));
289 /* Copy the permanent MAC address */
290 rte_ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
292 /* reset the hardware with the new settings */
293 err = hw->mac.start_hw(hw);
295 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
299 /* enter promiscuous mode */
300 txgbevf_dev_promiscuous_enable(eth_dev);
302 rte_intr_callback_register(intr_handle,
303 txgbevf_dev_interrupt_handler, eth_dev);
304 rte_intr_enable(intr_handle);
305 txgbevf_intr_enable(eth_dev);
307 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
308 eth_dev->data->port_id, pci_dev->id.vendor_id,
309 pci_dev->id.device_id, "txgbe_mac_raptor_vf");
314 /* Virtual Function device uninit */
316 eth_txgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
318 PMD_INIT_FUNC_TRACE();
320 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
323 txgbevf_dev_close(eth_dev);
328 static int eth_txgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
329 struct rte_pci_device *pci_dev)
331 return rte_eth_dev_pci_generic_probe(pci_dev,
332 sizeof(struct txgbe_adapter), eth_txgbevf_dev_init);
335 static int eth_txgbevf_pci_remove(struct rte_pci_device *pci_dev)
337 return rte_eth_dev_pci_generic_remove(pci_dev, eth_txgbevf_dev_uninit);
341 * virtual function driver struct
343 static struct rte_pci_driver rte_txgbevf_pmd = {
344 .id_table = pci_id_txgbevf_map,
345 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
346 .probe = eth_txgbevf_pci_probe,
347 .remove = eth_txgbevf_pci_remove,
350 static int txgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
351 struct rte_eth_xstat_name *xstats_names, unsigned int limit)
355 if (limit < TXGBEVF_NB_XSTATS && xstats_names != NULL)
358 if (xstats_names != NULL)
359 for (i = 0; i < TXGBEVF_NB_XSTATS; i++)
360 snprintf(xstats_names[i].name,
361 sizeof(xstats_names[i].name),
362 "%s", rte_txgbevf_stats_strings[i].name);
363 return TXGBEVF_NB_XSTATS;
367 txgbevf_update_stats(struct rte_eth_dev *dev)
369 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
370 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
371 TXGBE_DEV_STATS(dev);
374 for (i = 0; i < dev->data->nb_rx_queues; i++) {
375 /* Good Rx packet, include VF loopback */
376 TXGBE_UPDCNT32(TXGBE_QPRXPKT(i),
377 hw_stats->qp[i].last_vfgprc, hw_stats->qp[i].vfgprc);
379 /* Good Rx octets, include VF loopback */
380 TXGBE_UPDCNT36(TXGBE_QPRXOCTL(i),
381 hw_stats->qp[i].last_vfgorc, hw_stats->qp[i].vfgorc);
383 /* Rx Multicst Packet */
384 TXGBE_UPDCNT32(TXGBE_QPRXMPKT(i),
385 hw_stats->qp[i].last_vfmprc, hw_stats->qp[i].vfmprc);
389 for (i = 0; i < dev->data->nb_tx_queues; i++) {
390 /* Good Tx packet, include VF loopback */
391 TXGBE_UPDCNT32(TXGBE_QPTXPKT(i),
392 hw_stats->qp[i].last_vfgptc, hw_stats->qp[i].vfgptc);
394 /* Good Tx octets, include VF loopback */
395 TXGBE_UPDCNT36(TXGBE_QPTXOCTL(i),
396 hw_stats->qp[i].last_vfgotc, hw_stats->qp[i].vfgotc);
398 hw->offset_loaded = 0;
402 txgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
405 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
406 TXGBE_DEV_STATS(dev);
409 if (n < TXGBEVF_NB_XSTATS)
410 return TXGBEVF_NB_XSTATS;
412 txgbevf_update_stats(dev);
418 for (i = 0; i < TXGBEVF_NB_XSTATS; i++) {
420 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
421 rte_txgbevf_stats_strings[i].offset);
424 return TXGBEVF_NB_XSTATS;
428 txgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
430 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
431 TXGBE_DEV_STATS(dev);
434 txgbevf_update_stats(dev);
444 for (i = 0; i < 8; i++) {
445 stats->ipackets += hw_stats->qp[i].vfgprc;
446 stats->ibytes += hw_stats->qp[i].vfgorc;
447 stats->opackets += hw_stats->qp[i].vfgptc;
448 stats->obytes += hw_stats->qp[i].vfgotc;
455 txgbevf_dev_stats_reset(struct rte_eth_dev *dev)
457 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
458 TXGBE_DEV_STATS(dev);
461 /* Sync HW register to the last stats */
462 txgbevf_dev_stats_get(dev, NULL);
464 /* reset HW current stats*/
465 for (i = 0; i < 8; i++) {
466 hw_stats->qp[i].vfgprc = 0;
467 hw_stats->qp[i].vfgorc = 0;
468 hw_stats->qp[i].vfgptc = 0;
469 hw_stats->qp[i].vfgotc = 0;
476 txgbevf_dev_info_get(struct rte_eth_dev *dev,
477 struct rte_eth_dev_info *dev_info)
479 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
480 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
482 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
483 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
484 dev_info->min_rx_bufsize = 1024;
485 dev_info->max_rx_pktlen = TXGBE_FRAME_SIZE_MAX;
486 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
487 dev_info->max_hash_mac_addrs = TXGBE_VMDQ_NUM_UC_MAC;
488 dev_info->max_vfs = pci_dev->max_vfs;
489 dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
490 dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
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 = RTE_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 & RTE_ETH_MQ_RX_RSS_FLAG)
579 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_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 & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
587 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
588 conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
591 if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
592 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
593 conf->rxmode.offloads |= RTE_ETH_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_start(struct rte_eth_dev *dev)
609 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
610 uint32_t intr_vector = 0;
611 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
612 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
616 PMD_INIT_FUNC_TRACE();
618 /* Stop the link setup handler before resetting the HW. */
619 rte_eal_alarm_cancel(txgbe_dev_setup_link_alarm_handler, dev);
621 err = hw->mac.reset_hw(hw);
623 PMD_INIT_LOG(ERR, "Unable to reset vf hardware (%d)", err);
626 hw->mac.get_link_status = true;
627 hw->dev_start = true;
629 /* negotiate mailbox API version to use with the PF. */
630 txgbevf_negotiate_api(hw);
632 txgbevf_dev_tx_init(dev);
634 /* This can fail when allocating mbufs for descriptor rings */
635 err = txgbevf_dev_rx_init(dev);
638 * In this case, reuses the MAC address assigned by VF
641 if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
642 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
643 txgbe_dev_clear_queues(dev);
648 txgbevf_set_vfta_all(dev, 1);
651 mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
652 RTE_ETH_VLAN_EXTEND_MASK;
653 err = txgbevf_vlan_offload_config(dev, mask);
655 PMD_INIT_LOG(ERR, "Unable to set VLAN offload (%d)", err);
656 txgbe_dev_clear_queues(dev);
660 txgbevf_dev_rxtx_start(dev);
662 /* check and configure queue intr-vector mapping */
663 if (rte_intr_cap_multiple(intr_handle) &&
664 dev->data->dev_conf.intr_conf.rxq) {
665 /* According to datasheet, only vector 0/1/2 can be used,
666 * now only one vector is used for Rx queue
669 if (rte_intr_efd_enable(intr_handle, intr_vector))
673 if (rte_intr_dp_is_en(intr_handle)) {
674 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
675 dev->data->nb_rx_queues)) {
676 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
677 " intr_vec", dev->data->nb_rx_queues);
681 txgbevf_configure_msix(dev);
683 /* When a VF port is bound to VFIO-PCI, only miscellaneous interrupt
684 * is mapped to VFIO vector 0 in eth_txgbevf_dev_init( ).
685 * If previous VFIO interrupt mapping setting in eth_txgbevf_dev_init( )
686 * is not cleared, it will fail when following rte_intr_enable( ) tries
687 * to map Rx queue interrupt to other VFIO vectors.
688 * So clear uio/vfio intr/evevnfd first to avoid failure.
690 rte_intr_disable(intr_handle);
692 rte_intr_enable(intr_handle);
694 /* Re-enable interrupt for VF */
695 txgbevf_intr_enable(dev);
698 * Update link status right before return, because it may
699 * start link configuration process in a separate thread.
701 txgbevf_dev_link_update(dev, 0);
703 hw->adapter_stopped = false;
709 txgbevf_dev_stop(struct rte_eth_dev *dev)
711 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
712 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
713 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
714 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
716 if (hw->adapter_stopped)
719 PMD_INIT_FUNC_TRACE();
721 rte_eal_alarm_cancel(txgbe_dev_setup_link_alarm_handler, dev);
723 txgbevf_intr_disable(dev);
725 hw->adapter_stopped = 1;
729 * Clear what we set, but we still keep shadow_vfta to
730 * restore after device starts
732 txgbevf_set_vfta_all(dev, 0);
734 /* Clear stored conf */
735 dev->data->scattered_rx = 0;
737 txgbe_dev_clear_queues(dev);
739 /* Clean datapath event and queue/vec mapping */
740 rte_intr_efd_disable(intr_handle);
741 rte_intr_vec_list_free(intr_handle);
743 adapter->rss_reta_updated = 0;
744 hw->dev_start = false;
750 txgbevf_dev_close(struct rte_eth_dev *dev)
752 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
753 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
754 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
757 PMD_INIT_FUNC_TRACE();
758 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
761 hw->mac.reset_hw(hw);
763 ret = txgbevf_dev_stop(dev);
765 txgbe_dev_free_queues(dev);
768 * Remove the VF MAC address ro ensure
769 * that the VF traffic goes to the PF
770 * after stop, close and detach of the VF
772 txgbevf_remove_mac_addr(dev, 0);
774 dev->rx_pkt_burst = NULL;
775 dev->tx_pkt_burst = NULL;
777 /* Disable the interrupts for VF */
778 txgbevf_intr_disable(dev);
780 rte_free(dev->data->mac_addrs);
781 dev->data->mac_addrs = NULL;
783 rte_intr_disable(intr_handle);
784 rte_intr_callback_unregister(intr_handle,
785 txgbevf_dev_interrupt_handler, dev);
794 txgbevf_dev_reset(struct rte_eth_dev *dev)
798 ret = eth_txgbevf_dev_uninit(dev);
802 ret = eth_txgbevf_dev_init(dev);
807 static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
809 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
810 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
811 int i = 0, j = 0, vfta = 0, mask = 1;
813 for (i = 0; i < TXGBE_VFTA_SIZE; i++) {
814 vfta = shadow_vfta->vfta[i];
817 for (j = 0; j < 32; j++) {
819 hw->mac.set_vfta(hw, (i << 5) + j, 0,
828 txgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
830 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
831 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
832 uint32_t vid_idx = 0;
833 uint32_t vid_bit = 0;
836 PMD_INIT_FUNC_TRACE();
838 /* vind is not used in VF driver, set to 0, check txgbe_set_vfta_vf */
839 ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
841 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
844 vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
845 vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
847 /* Save what we set and restore it after device reset */
849 shadow_vfta->vfta[vid_idx] |= vid_bit;
851 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
857 txgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
859 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
862 PMD_INIT_FUNC_TRACE();
864 if (queue >= hw->mac.max_rx_queues)
867 ctrl = rd32(hw, TXGBE_RXCFG(queue));
868 txgbe_dev_save_rx_queue(hw, queue);
870 ctrl |= TXGBE_RXCFG_VLAN;
872 ctrl &= ~TXGBE_RXCFG_VLAN;
873 wr32(hw, TXGBE_RXCFG(queue), 0);
875 txgbe_dev_store_rx_queue(hw, queue);
876 wr32m(hw, TXGBE_RXCFG(queue),
877 TXGBE_RXCFG_VLAN | TXGBE_RXCFG_ENA, ctrl);
879 txgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
883 txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
885 struct txgbe_rx_queue *rxq;
889 /* VF function only support hw strip feature, others are not support */
890 if (mask & RTE_ETH_VLAN_STRIP_MASK) {
891 for (i = 0; i < dev->data->nb_rx_queues; i++) {
892 rxq = dev->data->rx_queues[i];
893 on = !!(rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
894 txgbevf_vlan_strip_queue_set(dev, i, on);
902 txgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
904 txgbe_config_vlan_strip_on_all_queues(dev, mask);
906 txgbevf_vlan_offload_config(dev, mask);
912 txgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
914 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
915 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
916 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
917 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
918 uint32_t vec = TXGBE_MISC_VEC_ID;
920 if (rte_intr_allow_others(intr_handle))
921 vec = TXGBE_RX_VEC_START;
922 intr->mask_misc &= ~(1 << vec);
923 RTE_SET_USED(queue_id);
924 wr32(hw, TXGBE_VFIMC, ~intr->mask_misc);
926 rte_intr_enable(intr_handle);
932 txgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
934 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
935 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
936 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
937 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
938 uint32_t vec = TXGBE_MISC_VEC_ID;
940 if (rte_intr_allow_others(intr_handle))
941 vec = TXGBE_RX_VEC_START;
942 intr->mask_misc |= (1 << vec);
943 RTE_SET_USED(queue_id);
944 wr32(hw, TXGBE_VFIMS, intr->mask_misc);
950 txgbevf_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
951 uint8_t queue, uint8_t msix_vector)
955 if (direction == -1) {
957 msix_vector |= TXGBE_VFIVAR_VLD;
958 tmp = rd32(hw, TXGBE_VFIVARMISC);
961 wr32(hw, TXGBE_VFIVARMISC, tmp);
964 /* Workaround for ICR lost */
965 idx = ((16 * (queue & 1)) + (8 * direction));
966 tmp = rd32(hw, TXGBE_VFIVAR(queue >> 1));
967 tmp &= ~(0xFF << idx);
968 tmp |= (msix_vector << idx);
969 wr32(hw, TXGBE_VFIVAR(queue >> 1), tmp);
974 txgbevf_configure_msix(struct rte_eth_dev *dev)
976 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
977 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
978 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
980 uint32_t vector_idx = TXGBE_MISC_VEC_ID;
981 uint32_t base = TXGBE_MISC_VEC_ID;
983 /* Configure VF other cause ivar */
984 txgbevf_set_ivar_map(hw, -1, 1, vector_idx);
986 /* won't configure msix register if no mapping is done
987 * between intr vector and event fd.
989 if (!rte_intr_dp_is_en(intr_handle))
992 if (rte_intr_allow_others(intr_handle)) {
993 base = TXGBE_RX_VEC_START;
994 vector_idx = TXGBE_RX_VEC_START;
997 /* Configure all RX queues of VF */
998 for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
999 /* Force all queue use vector 0,
1000 * as TXGBE_VF_MAXMSIVECTOR = 1
1002 txgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
1003 rte_intr_vec_list_index_set(intr_handle, q_idx,
1005 if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
1010 /* As RX queue setting above show, all queues use the vector 0.
1011 * Set only the ITR value of TXGBE_MISC_VEC_ID.
1013 wr32(hw, TXGBE_ITR(TXGBE_MISC_VEC_ID),
1014 TXGBE_ITR_IVAL(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
1019 txgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
1020 __rte_unused uint32_t index,
1021 __rte_unused uint32_t pool)
1023 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1027 * On a VF, adding again the same MAC addr is not an idempotent
1028 * operation. Trap this case to avoid exhausting the [very limited]
1029 * set of PF resources used to store VF MAC addresses.
1031 if (memcmp(hw->mac.perm_addr, mac_addr,
1032 sizeof(struct rte_ether_addr)) == 0)
1034 err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1036 PMD_DRV_LOG(ERR, "Unable to add MAC address "
1037 RTE_ETHER_ADDR_PRT_FMT " - err=%d",
1038 RTE_ETHER_ADDR_BYTES(mac_addr), err);
1043 txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
1045 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1046 struct rte_ether_addr *perm_addr =
1047 (struct rte_ether_addr *)hw->mac.perm_addr;
1048 struct rte_ether_addr *mac_addr;
1053 * The TXGBE_VF_SET_MACVLAN command of the txgbe-pf driver does
1054 * not support the deletion of a given MAC address.
1055 * Instead, it imposes to delete all MAC addresses, then to add again
1056 * all MAC addresses with the exception of the one to be deleted.
1058 (void)txgbevf_set_uc_addr_vf(hw, 0, NULL);
1061 * Add again all MAC addresses, with the exception of the deleted one
1062 * and of the permanent MAC address.
1064 for (i = 0, mac_addr = dev->data->mac_addrs;
1065 i < hw->mac.num_rar_entries; i++, mac_addr++) {
1066 /* Skip the deleted MAC address */
1069 /* Skip NULL MAC addresses */
1070 if (rte_is_zero_ether_addr(mac_addr))
1072 /* Skip the permanent MAC address */
1073 if (memcmp(perm_addr, mac_addr,
1074 sizeof(struct rte_ether_addr)) == 0)
1076 err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
1079 "Adding again MAC address "
1080 RTE_ETHER_ADDR_PRT_FMT " failed "
1082 RTE_ETHER_ADDR_BYTES(mac_addr), err);
1087 txgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
1088 struct rte_ether_addr *addr)
1090 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1092 hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
1098 txgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1100 struct txgbe_hw *hw;
1101 uint32_t max_frame = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1102 struct rte_eth_dev_data *dev_data = dev->data;
1104 hw = TXGBE_DEV_HW(dev);
1106 if (mtu < RTE_ETHER_MIN_MTU ||
1107 max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
1110 /* If device is started, refuse mtu that requires the support of
1111 * scattered packets when this feature has not been enabled before.
1113 if (dev_data->dev_started && !dev_data->scattered_rx &&
1114 (max_frame + 2 * RTE_VLAN_HLEN >
1115 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
1116 PMD_INIT_LOG(ERR, "Stop port first.");
1121 * When supported by the underlying PF driver, use the TXGBE_VF_SET_MTU
1122 * request of the version 2.0 of the mailbox API.
1123 * For now, use the TXGBE_VF_SET_LPE request of the version 1.0
1124 * of the mailbox API.
1126 if (txgbevf_rlpml_set_vf(hw, max_frame))
1133 txgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
1137 const struct reg_info *reg_group;
1139 while ((reg_group = txgbevf_regs[g_ind++]))
1140 count += txgbe_regs_group_count(reg_group);
1146 txgbevf_get_regs(struct rte_eth_dev *dev,
1147 struct rte_dev_reg_info *regs)
1149 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1150 uint32_t *data = regs->data;
1153 const struct reg_info *reg_group;
1156 regs->length = txgbevf_get_reg_length(dev);
1157 regs->width = sizeof(uint32_t);
1161 /* Support only full register dump */
1162 if (regs->length == 0 ||
1163 regs->length == (uint32_t)txgbevf_get_reg_length(dev)) {
1164 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
1166 while ((reg_group = txgbevf_regs[g_ind++]))
1167 count += txgbe_read_regs_group(dev, &data[count],
1176 txgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
1178 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1181 switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_PROMISC)) {
1185 case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1197 txgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
1199 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1202 switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_NONE)) {
1206 case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1218 txgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
1220 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1223 switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_ALLMULTI)) {
1227 case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1239 txgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
1241 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1244 switch (hw->mac.update_xcast_mode(hw, TXGBEVF_XCAST_MODE_MULTI)) {
1248 case TXGBE_ERR_FEATURE_NOT_SUPPORTED:
1259 static void txgbevf_mbx_process(struct rte_eth_dev *dev)
1261 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1264 /* peek the message first */
1265 in_msg = rd32(hw, TXGBE_VFMBX);
1267 /* PF reset VF event */
1268 if (in_msg == TXGBE_PF_CONTROL_MSG) {
1269 /* dummy mbx read to ack pf */
1270 if (txgbe_read_mbx(hw, &in_msg, 1, 0))
1272 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
1278 txgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
1281 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1282 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1283 txgbevf_intr_disable(dev);
1285 /* read-on-clear nic registers here */
1286 eicr = rd32(hw, TXGBE_VFICR);
1289 /* only one misc vector supported - mailbox */
1290 eicr &= TXGBE_VFICR_MASK;
1291 /* Workaround for ICR lost */
1292 intr->flags |= TXGBE_FLAG_MAILBOX;
1294 /* To avoid compiler warnings set eicr to used. */
1301 txgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
1303 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1305 if (intr->flags & TXGBE_FLAG_MAILBOX) {
1306 txgbevf_mbx_process(dev);
1307 intr->flags &= ~TXGBE_FLAG_MAILBOX;
1310 txgbevf_intr_enable(dev);
1316 txgbevf_dev_interrupt_handler(void *param)
1318 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1320 txgbevf_dev_interrupt_get_status(dev);
1321 txgbevf_dev_interrupt_action(dev);
1325 * dev_ops for virtual function, bare necessities for basic vf
1326 * operation have been implemented
1328 static const struct eth_dev_ops txgbevf_eth_dev_ops = {
1329 .dev_configure = txgbevf_dev_configure,
1330 .dev_start = txgbevf_dev_start,
1331 .dev_stop = txgbevf_dev_stop,
1332 .link_update = txgbevf_dev_link_update,
1333 .stats_get = txgbevf_dev_stats_get,
1334 .xstats_get = txgbevf_dev_xstats_get,
1335 .stats_reset = txgbevf_dev_stats_reset,
1336 .xstats_reset = txgbevf_dev_stats_reset,
1337 .xstats_get_names = txgbevf_dev_xstats_get_names,
1338 .dev_close = txgbevf_dev_close,
1339 .dev_reset = txgbevf_dev_reset,
1340 .promiscuous_enable = txgbevf_dev_promiscuous_enable,
1341 .promiscuous_disable = txgbevf_dev_promiscuous_disable,
1342 .allmulticast_enable = txgbevf_dev_allmulticast_enable,
1343 .allmulticast_disable = txgbevf_dev_allmulticast_disable,
1344 .dev_infos_get = txgbevf_dev_info_get,
1345 .dev_supported_ptypes_get = txgbe_dev_supported_ptypes_get,
1346 .mtu_set = txgbevf_dev_set_mtu,
1347 .vlan_filter_set = txgbevf_vlan_filter_set,
1348 .vlan_strip_queue_set = txgbevf_vlan_strip_queue_set,
1349 .vlan_offload_set = txgbevf_vlan_offload_set,
1350 .rx_queue_setup = txgbe_dev_rx_queue_setup,
1351 .rx_queue_release = txgbe_dev_rx_queue_release,
1352 .tx_queue_setup = txgbe_dev_tx_queue_setup,
1353 .tx_queue_release = txgbe_dev_tx_queue_release,
1354 .rx_queue_intr_enable = txgbevf_dev_rx_queue_intr_enable,
1355 .rx_queue_intr_disable = txgbevf_dev_rx_queue_intr_disable,
1356 .mac_addr_add = txgbevf_add_mac_addr,
1357 .mac_addr_remove = txgbevf_remove_mac_addr,
1358 .set_mc_addr_list = txgbe_dev_set_mc_addr_list,
1359 .rxq_info_get = txgbe_rxq_info_get,
1360 .txq_info_get = txgbe_txq_info_get,
1361 .mac_addr_set = txgbevf_set_default_mac_addr,
1362 .get_reg = txgbevf_get_regs,
1363 .reta_update = txgbe_dev_rss_reta_update,
1364 .reta_query = txgbe_dev_rss_reta_query,
1365 .rss_hash_update = txgbe_dev_rss_hash_update,
1366 .rss_hash_conf_get = txgbe_dev_rss_hash_conf_get,
1367 .tx_done_cleanup = txgbe_dev_tx_done_cleanup,
1370 RTE_PMD_REGISTER_PCI(net_txgbe_vf, rte_txgbevf_pmd);
1371 RTE_PMD_REGISTER_PCI_TABLE(net_txgbe_vf, pci_id_txgbevf_map);
1372 RTE_PMD_REGISTER_KMOD_DEP(net_txgbe_vf, "* igb_uio | vfio-pci");