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"
18 static int txgbevf_dev_xstats_get(struct rte_eth_dev *dev,
19 struct rte_eth_xstat *xstats, unsigned int n);
20 static int txgbevf_dev_info_get(struct rte_eth_dev *dev,
21 struct rte_eth_dev_info *dev_info);
22 static int txgbevf_dev_configure(struct rte_eth_dev *dev);
23 static int txgbevf_dev_link_update(struct rte_eth_dev *dev,
24 int wait_to_complete);
25 static int txgbevf_dev_close(struct rte_eth_dev *dev);
26 static void txgbevf_intr_disable(struct rte_eth_dev *dev);
27 static void txgbevf_intr_enable(struct rte_eth_dev *dev);
28 static int txgbevf_dev_stats_reset(struct rte_eth_dev *dev);
29 static int txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
30 static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
31 static void txgbevf_configure_msix(struct rte_eth_dev *dev);
32 static void txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
33 static void txgbevf_dev_interrupt_handler(void *param);
36 * The set of PCI devices this driver supports (for VF)
38 static const struct rte_pci_id pci_id_txgbevf_map[] = {
39 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_VF) },
40 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_VF_HV) },
41 { .vendor_id = 0, /* sentinel */ },
44 static const struct rte_eth_desc_lim rx_desc_lim = {
45 .nb_max = TXGBE_RING_DESC_MAX,
46 .nb_min = TXGBE_RING_DESC_MIN,
47 .nb_align = TXGBE_RXD_ALIGN,
50 static const struct rte_eth_desc_lim tx_desc_lim = {
51 .nb_max = TXGBE_RING_DESC_MAX,
52 .nb_min = TXGBE_RING_DESC_MIN,
53 .nb_align = TXGBE_TXD_ALIGN,
54 .nb_seg_max = TXGBE_TX_MAX_SEG,
55 .nb_mtu_seg_max = TXGBE_TX_MAX_SEG,
58 static const struct eth_dev_ops txgbevf_eth_dev_ops;
60 static const struct rte_txgbe_xstats_name_off rte_txgbevf_stats_strings[] = {
61 {"rx_multicast_packets_0",
62 offsetof(struct txgbevf_hw_stats, qp[0].vfmprc)},
63 {"rx_multicast_packets_1",
64 offsetof(struct txgbevf_hw_stats, qp[1].vfmprc)},
65 {"rx_multicast_packets_2",
66 offsetof(struct txgbevf_hw_stats, qp[2].vfmprc)},
67 {"rx_multicast_packets_3",
68 offsetof(struct txgbevf_hw_stats, qp[3].vfmprc)},
69 {"rx_multicast_packets_4",
70 offsetof(struct txgbevf_hw_stats, qp[4].vfmprc)},
71 {"rx_multicast_packets_5",
72 offsetof(struct txgbevf_hw_stats, qp[5].vfmprc)},
73 {"rx_multicast_packets_6",
74 offsetof(struct txgbevf_hw_stats, qp[6].vfmprc)},
75 {"rx_multicast_packets_7",
76 offsetof(struct txgbevf_hw_stats, qp[7].vfmprc)}
79 #define TXGBEVF_NB_XSTATS (sizeof(rte_txgbevf_stats_strings) / \
80 sizeof(rte_txgbevf_stats_strings[0]))
83 * Negotiate mailbox API version with the PF.
84 * After reset API version is always set to the basic one (txgbe_mbox_api_10).
85 * Then we try to negotiate starting with the most recent one.
86 * If all negotiation attempts fail, then we will proceed with
87 * the default one (txgbe_mbox_api_10).
90 txgbevf_negotiate_api(struct txgbe_hw *hw)
94 /* start with highest supported, proceed down */
95 static const int sup_ver[] = {
102 for (i = 0; i < ARRAY_SIZE(sup_ver); i++) {
103 if (txgbevf_negotiate_api_version(hw, sup_ver[i]) == 0)
109 generate_random_mac_addr(struct rte_ether_addr *mac_addr)
113 /* Set Organizationally Unique Identifier (OUI) prefix. */
114 mac_addr->addr_bytes[0] = 0x00;
115 mac_addr->addr_bytes[1] = 0x09;
116 mac_addr->addr_bytes[2] = 0xC0;
117 /* Force indication of locally assigned MAC address. */
118 mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
119 /* Generate the last 3 bytes of the MAC address with a random number. */
121 memcpy(&mac_addr->addr_bytes[3], &random, 3);
125 * Virtual Function device init
128 eth_txgbevf_dev_init(struct rte_eth_dev *eth_dev)
132 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
133 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
134 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
135 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(eth_dev);
136 struct txgbe_hwstrip *hwstrip = TXGBE_DEV_HWSTRIP(eth_dev);
137 struct rte_ether_addr *perm_addr =
138 (struct rte_ether_addr *)hw->mac.perm_addr;
140 PMD_INIT_FUNC_TRACE();
142 eth_dev->dev_ops = &txgbevf_eth_dev_ops;
143 eth_dev->rx_descriptor_status = txgbe_dev_rx_descriptor_status;
144 eth_dev->tx_descriptor_status = txgbe_dev_tx_descriptor_status;
145 eth_dev->rx_pkt_burst = &txgbe_recv_pkts;
146 eth_dev->tx_pkt_burst = &txgbe_xmit_pkts;
148 /* for secondary processes, we don't initialise any further as primary
149 * has already done this work. Only check we don't need a different
152 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
153 struct txgbe_tx_queue *txq;
154 uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
155 /* TX queue function in primary, set by last queue initialized
156 * Tx queue may not initialized by primary process
158 if (eth_dev->data->tx_queues) {
159 txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
160 txgbe_set_tx_function(eth_dev, txq);
162 /* Use default TX function if we get here */
164 "No TX queues configured yet. Using default TX function.");
167 txgbe_set_rx_function(eth_dev);
172 rte_eth_copy_pci_info(eth_dev, pci_dev);
174 hw->device_id = pci_dev->id.device_id;
175 hw->vendor_id = pci_dev->id.vendor_id;
176 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
177 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
178 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
180 /* initialize the vfta */
181 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
183 /* initialize the hw strip bitmap*/
184 memset(hwstrip, 0, sizeof(*hwstrip));
186 /* Initialize the shared code (base driver) */
187 err = txgbe_init_shared_code(hw);
190 "Shared code init failed for txgbevf: %d", err);
194 /* init_mailbox_params */
195 hw->mbx.init_params(hw);
197 /* Reset the hw statistics */
198 txgbevf_dev_stats_reset(eth_dev);
200 /* Disable the interrupts for VF */
201 txgbevf_intr_disable(eth_dev);
203 hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
204 err = hw->mac.reset_hw(hw);
207 * The VF reset operation returns the TXGBE_ERR_INVALID_MAC_ADDR when
208 * the underlying PF driver has not assigned a MAC address to the VF.
209 * In this case, assign a random MAC address.
211 if (err != 0 && err != TXGBE_ERR_INVALID_MAC_ADDR) {
212 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
214 * This error code will be propagated to the app by
215 * rte_eth_dev_reset, so use a public error code rather than
216 * the internal-only TXGBE_ERR_RESET_FAILED
221 /* negotiate mailbox API version to use with the PF. */
222 txgbevf_negotiate_api(hw);
224 /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
225 txgbevf_get_queues(hw, &tcs, &tc);
227 /* Allocate memory for storing MAC addresses */
228 eth_dev->data->mac_addrs = rte_zmalloc("txgbevf", RTE_ETHER_ADDR_LEN *
229 hw->mac.num_rar_entries, 0);
230 if (eth_dev->data->mac_addrs == NULL) {
232 "Failed to allocate %u bytes needed to store "
234 RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
238 /* Generate a random MAC address, if none was assigned by PF. */
239 if (rte_is_zero_ether_addr(perm_addr)) {
240 generate_random_mac_addr(perm_addr);
241 err = txgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
243 rte_free(eth_dev->data->mac_addrs);
244 eth_dev->data->mac_addrs = NULL;
247 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
248 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
249 "%02x:%02x:%02x:%02x:%02x:%02x",
250 perm_addr->addr_bytes[0],
251 perm_addr->addr_bytes[1],
252 perm_addr->addr_bytes[2],
253 perm_addr->addr_bytes[3],
254 perm_addr->addr_bytes[4],
255 perm_addr->addr_bytes[5]);
258 /* Copy the permanent MAC address */
259 rte_ether_addr_copy(perm_addr, ð_dev->data->mac_addrs[0]);
261 /* reset the hardware with the new settings */
262 err = hw->mac.start_hw(hw);
264 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", err);
268 rte_intr_callback_register(intr_handle,
269 txgbevf_dev_interrupt_handler, eth_dev);
270 rte_intr_enable(intr_handle);
271 txgbevf_intr_enable(eth_dev);
273 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
274 eth_dev->data->port_id, pci_dev->id.vendor_id,
275 pci_dev->id.device_id, "txgbe_mac_raptor_vf");
280 /* Virtual Function device uninit */
282 eth_txgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
284 PMD_INIT_FUNC_TRACE();
286 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
289 txgbevf_dev_close(eth_dev);
294 static int eth_txgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
295 struct rte_pci_device *pci_dev)
297 return rte_eth_dev_pci_generic_probe(pci_dev,
298 sizeof(struct txgbe_adapter), eth_txgbevf_dev_init);
301 static int eth_txgbevf_pci_remove(struct rte_pci_device *pci_dev)
303 return rte_eth_dev_pci_generic_remove(pci_dev, eth_txgbevf_dev_uninit);
307 * virtual function driver struct
309 static struct rte_pci_driver rte_txgbevf_pmd = {
310 .id_table = pci_id_txgbevf_map,
311 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
312 .probe = eth_txgbevf_pci_probe,
313 .remove = eth_txgbevf_pci_remove,
316 static int txgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
317 struct rte_eth_xstat_name *xstats_names, unsigned int limit)
321 if (limit < TXGBEVF_NB_XSTATS && xstats_names != NULL)
324 if (xstats_names != NULL)
325 for (i = 0; i < TXGBEVF_NB_XSTATS; i++)
326 snprintf(xstats_names[i].name,
327 sizeof(xstats_names[i].name),
328 "%s", rte_txgbevf_stats_strings[i].name);
329 return TXGBEVF_NB_XSTATS;
333 txgbevf_update_stats(struct rte_eth_dev *dev)
335 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
336 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
337 TXGBE_DEV_STATS(dev);
340 for (i = 0; i < dev->data->nb_rx_queues; i++) {
341 /* Good Rx packet, include VF loopback */
342 TXGBE_UPDCNT32(TXGBE_QPRXPKT(i),
343 hw_stats->qp[i].last_vfgprc, hw_stats->qp[i].vfgprc);
345 /* Good Rx octets, include VF loopback */
346 TXGBE_UPDCNT36(TXGBE_QPRXOCTL(i),
347 hw_stats->qp[i].last_vfgorc, hw_stats->qp[i].vfgorc);
349 /* Rx Multicst Packet */
350 TXGBE_UPDCNT32(TXGBE_QPRXMPKT(i),
351 hw_stats->qp[i].last_vfmprc, hw_stats->qp[i].vfmprc);
355 for (i = 0; i < dev->data->nb_tx_queues; i++) {
356 /* Good Tx packet, include VF loopback */
357 TXGBE_UPDCNT32(TXGBE_QPTXPKT(i),
358 hw_stats->qp[i].last_vfgptc, hw_stats->qp[i].vfgptc);
360 /* Good Tx octets, include VF loopback */
361 TXGBE_UPDCNT36(TXGBE_QPTXOCTL(i),
362 hw_stats->qp[i].last_vfgotc, hw_stats->qp[i].vfgotc);
364 hw->offset_loaded = 0;
368 txgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
371 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
372 TXGBE_DEV_STATS(dev);
375 if (n < TXGBEVF_NB_XSTATS)
376 return TXGBEVF_NB_XSTATS;
378 txgbevf_update_stats(dev);
384 for (i = 0; i < TXGBEVF_NB_XSTATS; i++) {
386 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
387 rte_txgbevf_stats_strings[i].offset);
390 return TXGBEVF_NB_XSTATS;
394 txgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
396 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
397 TXGBE_DEV_STATS(dev);
400 txgbevf_update_stats(dev);
410 for (i = 0; i < 8; i++) {
411 stats->ipackets += hw_stats->qp[i].vfgprc;
412 stats->ibytes += hw_stats->qp[i].vfgorc;
413 stats->opackets += hw_stats->qp[i].vfgptc;
414 stats->obytes += hw_stats->qp[i].vfgotc;
421 txgbevf_dev_stats_reset(struct rte_eth_dev *dev)
423 struct txgbevf_hw_stats *hw_stats = (struct txgbevf_hw_stats *)
424 TXGBE_DEV_STATS(dev);
427 /* Sync HW register to the last stats */
428 txgbevf_dev_stats_get(dev, NULL);
430 /* reset HW current stats*/
431 for (i = 0; i < 8; i++) {
432 hw_stats->qp[i].vfgprc = 0;
433 hw_stats->qp[i].vfgorc = 0;
434 hw_stats->qp[i].vfgptc = 0;
435 hw_stats->qp[i].vfgotc = 0;
442 txgbevf_dev_info_get(struct rte_eth_dev *dev,
443 struct rte_eth_dev_info *dev_info)
445 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
446 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
448 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
449 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
450 dev_info->min_rx_bufsize = 1024;
451 dev_info->max_rx_pktlen = TXGBE_FRAME_SIZE_MAX;
452 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
453 dev_info->max_hash_mac_addrs = TXGBE_VMDQ_NUM_UC_MAC;
454 dev_info->max_vfs = pci_dev->max_vfs;
455 dev_info->max_vmdq_pools = ETH_64_POOLS;
456 dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
457 dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
458 dev_info->rx_queue_offload_capa);
459 dev_info->tx_queue_offload_capa = txgbe_get_tx_queue_offloads(dev);
460 dev_info->tx_offload_capa = txgbe_get_tx_port_offloads(dev);
461 dev_info->hash_key_size = TXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
462 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
463 dev_info->flow_type_rss_offloads = TXGBE_RSS_OFFLOAD_ALL;
465 dev_info->default_rxconf = (struct rte_eth_rxconf) {
467 .pthresh = TXGBE_DEFAULT_RX_PTHRESH,
468 .hthresh = TXGBE_DEFAULT_RX_HTHRESH,
469 .wthresh = TXGBE_DEFAULT_RX_WTHRESH,
471 .rx_free_thresh = TXGBE_DEFAULT_RX_FREE_THRESH,
476 dev_info->default_txconf = (struct rte_eth_txconf) {
478 .pthresh = TXGBE_DEFAULT_TX_PTHRESH,
479 .hthresh = TXGBE_DEFAULT_TX_HTHRESH,
480 .wthresh = TXGBE_DEFAULT_TX_WTHRESH,
482 .tx_free_thresh = TXGBE_DEFAULT_TX_FREE_THRESH,
486 dev_info->rx_desc_lim = rx_desc_lim;
487 dev_info->tx_desc_lim = tx_desc_lim;
493 txgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
495 return txgbe_dev_link_update_share(dev, wait_to_complete);
499 * Virtual Function operations
502 txgbevf_intr_disable(struct rte_eth_dev *dev)
504 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
505 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
507 PMD_INIT_FUNC_TRACE();
509 /* Clear interrupt mask to stop from interrupts being generated */
510 wr32(hw, TXGBE_VFIMS, TXGBE_VFIMS_MASK);
514 /* Clear mask value. */
515 intr->mask_misc = TXGBE_VFIMS_MASK;
519 txgbevf_intr_enable(struct rte_eth_dev *dev)
521 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
522 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
524 PMD_INIT_FUNC_TRACE();
526 /* VF enable interrupt autoclean */
527 wr32(hw, TXGBE_VFIMC, TXGBE_VFIMC_MASK);
535 txgbevf_dev_configure(struct rte_eth_dev *dev)
537 struct rte_eth_conf *conf = &dev->data->dev_conf;
538 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
540 PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
543 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
544 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
547 * VF has no ability to enable/disable HW CRC
548 * Keep the persistent behavior the same as Host PF
550 #ifndef RTE_LIBRTE_TXGBE_PF_DISABLE_STRIP_CRC
551 if (conf->rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC) {
552 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
553 conf->rxmode.offloads &= ~DEV_RX_OFFLOAD_KEEP_CRC;
556 if (!(conf->rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)) {
557 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
558 conf->rxmode.offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
563 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
564 * allocation or vector Rx preconditions we will reset it.
566 adapter->rx_bulk_alloc_allowed = true;
572 txgbevf_dev_close(struct rte_eth_dev *dev)
574 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
575 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
576 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
577 PMD_INIT_FUNC_TRACE();
578 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
581 hw->mac.reset_hw(hw);
583 txgbe_dev_free_queues(dev);
586 * Remove the VF MAC address ro ensure
587 * that the VF traffic goes to the PF
588 * after stop, close and detach of the VF
590 txgbevf_remove_mac_addr(dev, 0);
592 dev->rx_pkt_burst = NULL;
593 dev->tx_pkt_burst = NULL;
595 /* Disable the interrupts for VF */
596 txgbevf_intr_disable(dev);
598 rte_free(dev->data->mac_addrs);
599 dev->data->mac_addrs = NULL;
601 rte_intr_disable(intr_handle);
602 rte_intr_callback_unregister(intr_handle,
603 txgbevf_dev_interrupt_handler, dev);
608 static void txgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
610 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
611 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
612 int i = 0, j = 0, vfta = 0, mask = 1;
614 for (i = 0; i < TXGBE_VFTA_SIZE; i++) {
615 vfta = shadow_vfta->vfta[i];
618 for (j = 0; j < 32; j++) {
620 txgbe_set_vfta(hw, (i << 5) + j, 0,
629 txgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
631 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
632 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
633 uint32_t vid_idx = 0;
634 uint32_t vid_bit = 0;
637 PMD_INIT_FUNC_TRACE();
639 /* vind is not used in VF driver, set to 0, check txgbe_set_vfta_vf */
640 ret = hw->mac.set_vfta(hw, vlan_id, 0, !!on, false);
642 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
645 vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
646 vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
648 /* Save what we set and restore it after device reset */
650 shadow_vfta->vfta[vid_idx] |= vid_bit;
652 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
658 txgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
660 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
663 PMD_INIT_FUNC_TRACE();
665 if (queue >= hw->mac.max_rx_queues)
668 ctrl = rd32(hw, TXGBE_RXCFG(queue));
669 txgbe_dev_save_rx_queue(hw, queue);
671 ctrl |= TXGBE_RXCFG_VLAN;
673 ctrl &= ~TXGBE_RXCFG_VLAN;
674 wr32(hw, TXGBE_RXCFG(queue), 0);
676 txgbe_dev_store_rx_queue(hw, queue);
677 wr32m(hw, TXGBE_RXCFG(queue),
678 TXGBE_RXCFG_VLAN | TXGBE_RXCFG_ENA, ctrl);
680 txgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
684 txgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
686 struct txgbe_rx_queue *rxq;
690 /* VF function only support hw strip feature, others are not support */
691 if (mask & ETH_VLAN_STRIP_MASK) {
692 for (i = 0; i < dev->data->nb_rx_queues; i++) {
693 rxq = dev->data->rx_queues[i];
694 on = !!(rxq->offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
695 txgbevf_vlan_strip_queue_set(dev, i, on);
703 txgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
705 txgbe_config_vlan_strip_on_all_queues(dev, mask);
707 txgbevf_vlan_offload_config(dev, mask);
713 txgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
715 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
716 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
717 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
718 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
719 uint32_t vec = TXGBE_MISC_VEC_ID;
721 if (rte_intr_allow_others(intr_handle))
722 vec = TXGBE_RX_VEC_START;
723 intr->mask_misc &= ~(1 << vec);
724 RTE_SET_USED(queue_id);
725 wr32(hw, TXGBE_VFIMC, ~intr->mask_misc);
727 rte_intr_enable(intr_handle);
733 txgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
735 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
736 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
737 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
738 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
739 uint32_t vec = TXGBE_MISC_VEC_ID;
741 if (rte_intr_allow_others(intr_handle))
742 vec = TXGBE_RX_VEC_START;
743 intr->mask_misc |= (1 << vec);
744 RTE_SET_USED(queue_id);
745 wr32(hw, TXGBE_VFIMS, intr->mask_misc);
751 txgbevf_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
752 uint8_t queue, uint8_t msix_vector)
756 if (direction == -1) {
758 msix_vector |= TXGBE_VFIVAR_VLD;
759 tmp = rd32(hw, TXGBE_VFIVARMISC);
762 wr32(hw, TXGBE_VFIVARMISC, tmp);
765 /* Workround for ICR lost */
766 idx = ((16 * (queue & 1)) + (8 * direction));
767 tmp = rd32(hw, TXGBE_VFIVAR(queue >> 1));
768 tmp &= ~(0xFF << idx);
769 tmp |= (msix_vector << idx);
770 wr32(hw, TXGBE_VFIVAR(queue >> 1), tmp);
775 txgbevf_configure_msix(struct rte_eth_dev *dev)
777 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
778 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
779 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
781 uint32_t vector_idx = TXGBE_MISC_VEC_ID;
782 uint32_t base = TXGBE_MISC_VEC_ID;
784 /* Configure VF other cause ivar */
785 txgbevf_set_ivar_map(hw, -1, 1, vector_idx);
787 /* won't configure msix register if no mapping is done
788 * between intr vector and event fd.
790 if (!rte_intr_dp_is_en(intr_handle))
793 if (rte_intr_allow_others(intr_handle)) {
794 base = TXGBE_RX_VEC_START;
795 vector_idx = TXGBE_RX_VEC_START;
798 /* Configure all RX queues of VF */
799 for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
800 /* Force all queue use vector 0,
801 * as TXGBE_VF_MAXMSIVECOTR = 1
803 txgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
804 intr_handle->intr_vec[q_idx] = vector_idx;
805 if (vector_idx < base + intr_handle->nb_efd - 1)
809 /* As RX queue setting above show, all queues use the vector 0.
810 * Set only the ITR value of TXGBE_MISC_VEC_ID.
812 wr32(hw, TXGBE_ITR(TXGBE_MISC_VEC_ID),
813 TXGBE_ITR_IVAL(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
818 txgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
819 __rte_unused uint32_t index,
820 __rte_unused uint32_t pool)
822 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
826 * On a VF, adding again the same MAC addr is not an idempotent
827 * operation. Trap this case to avoid exhausting the [very limited]
828 * set of PF resources used to store VF MAC addresses.
830 if (memcmp(hw->mac.perm_addr, mac_addr,
831 sizeof(struct rte_ether_addr)) == 0)
833 err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
835 PMD_DRV_LOG(ERR, "Unable to add MAC address "
836 "%02x:%02x:%02x:%02x:%02x:%02x - err=%d",
837 mac_addr->addr_bytes[0],
838 mac_addr->addr_bytes[1],
839 mac_addr->addr_bytes[2],
840 mac_addr->addr_bytes[3],
841 mac_addr->addr_bytes[4],
842 mac_addr->addr_bytes[5],
848 txgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
850 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
851 struct rte_ether_addr *perm_addr =
852 (struct rte_ether_addr *)hw->mac.perm_addr;
853 struct rte_ether_addr *mac_addr;
858 * The TXGBE_VF_SET_MACVLAN command of the txgbe-pf driver does
859 * not support the deletion of a given MAC address.
860 * Instead, it imposes to delete all MAC addresses, then to add again
861 * all MAC addresses with the exception of the one to be deleted.
863 (void)txgbevf_set_uc_addr_vf(hw, 0, NULL);
866 * Add again all MAC addresses, with the exception of the deleted one
867 * and of the permanent MAC address.
869 for (i = 0, mac_addr = dev->data->mac_addrs;
870 i < hw->mac.num_rar_entries; i++, mac_addr++) {
871 /* Skip the deleted MAC address */
874 /* Skip NULL MAC addresses */
875 if (rte_is_zero_ether_addr(mac_addr))
877 /* Skip the permanent MAC address */
878 if (memcmp(perm_addr, mac_addr,
879 sizeof(struct rte_ether_addr)) == 0)
881 err = txgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
884 "Adding again MAC address "
885 "%02x:%02x:%02x:%02x:%02x:%02x failed "
887 mac_addr->addr_bytes[0],
888 mac_addr->addr_bytes[1],
889 mac_addr->addr_bytes[2],
890 mac_addr->addr_bytes[3],
891 mac_addr->addr_bytes[4],
892 mac_addr->addr_bytes[5],
898 txgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
899 struct rte_ether_addr *addr)
901 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
903 hw->mac.set_rar(hw, 0, (void *)addr, 0, 0);
908 static void txgbevf_mbx_process(struct rte_eth_dev *dev)
910 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
913 /* peek the message first */
914 in_msg = rd32(hw, TXGBE_VFMBX);
916 /* PF reset VF event */
917 if (in_msg == TXGBE_PF_CONTROL_MSG) {
918 /* dummy mbx read to ack pf */
919 if (txgbe_read_mbx(hw, &in_msg, 1, 0))
921 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
927 txgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
930 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
931 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
932 txgbevf_intr_disable(dev);
934 /* read-on-clear nic registers here */
935 eicr = rd32(hw, TXGBE_VFICR);
938 /* only one misc vector supported - mailbox */
939 eicr &= TXGBE_VFICR_MASK;
940 /* Workround for ICR lost */
941 intr->flags |= TXGBE_FLAG_MAILBOX;
947 txgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
949 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
951 if (intr->flags & TXGBE_FLAG_MAILBOX) {
952 txgbevf_mbx_process(dev);
953 intr->flags &= ~TXGBE_FLAG_MAILBOX;
956 txgbevf_intr_enable(dev);
962 txgbevf_dev_interrupt_handler(void *param)
964 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
966 txgbevf_dev_interrupt_get_status(dev);
967 txgbevf_dev_interrupt_action(dev);
971 * dev_ops for virtual function, bare necessities for basic vf
972 * operation have been implemented
974 static const struct eth_dev_ops txgbevf_eth_dev_ops = {
975 .dev_configure = txgbevf_dev_configure,
976 .link_update = txgbevf_dev_link_update,
977 .stats_get = txgbevf_dev_stats_get,
978 .xstats_get = txgbevf_dev_xstats_get,
979 .stats_reset = txgbevf_dev_stats_reset,
980 .xstats_reset = txgbevf_dev_stats_reset,
981 .xstats_get_names = txgbevf_dev_xstats_get_names,
982 .dev_infos_get = txgbevf_dev_info_get,
983 .vlan_filter_set = txgbevf_vlan_filter_set,
984 .vlan_strip_queue_set = txgbevf_vlan_strip_queue_set,
985 .vlan_offload_set = txgbevf_vlan_offload_set,
986 .rx_queue_intr_enable = txgbevf_dev_rx_queue_intr_enable,
987 .rx_queue_intr_disable = txgbevf_dev_rx_queue_intr_disable,
988 .mac_addr_add = txgbevf_add_mac_addr,
989 .mac_addr_remove = txgbevf_remove_mac_addr,
990 .rxq_info_get = txgbe_rxq_info_get,
991 .txq_info_get = txgbe_txq_info_get,
992 .mac_addr_set = txgbevf_set_default_mac_addr,
995 RTE_PMD_REGISTER_PCI(net_txgbe_vf, rte_txgbevf_pmd);
996 RTE_PMD_REGISTER_PCI_TABLE(net_txgbe_vf, pci_id_txgbevf_map);
997 RTE_PMD_REGISTER_KMOD_DEP(net_txgbe_vf, "* igb_uio | vfio-pci");