1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
9 #include <rte_common.h>
10 #include <rte_ethdev_pci.h>
12 #include <rte_interrupts.h>
14 #include <rte_debug.h>
16 #include <rte_memory.h>
18 #include <rte_alarm.h>
20 #include "txgbe_logs.h"
21 #include "base/txgbe.h"
22 #include "txgbe_ethdev.h"
23 #include "txgbe_rxtx.h"
25 static int txgbe_dev_set_link_up(struct rte_eth_dev *dev);
26 static int txgbe_dev_set_link_down(struct rte_eth_dev *dev);
27 static int txgbe_dev_close(struct rte_eth_dev *dev);
28 static int txgbe_dev_link_update(struct rte_eth_dev *dev,
29 int wait_to_complete);
30 static int txgbe_dev_stats_reset(struct rte_eth_dev *dev);
31 static void txgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue);
32 static void txgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev,
35 static void txgbe_dev_link_status_print(struct rte_eth_dev *dev);
36 static int txgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
37 static int txgbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev);
38 static int txgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
39 static int txgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
40 static int txgbe_dev_interrupt_action(struct rte_eth_dev *dev,
41 struct rte_intr_handle *handle);
42 static void txgbe_dev_interrupt_handler(void *param);
43 static void txgbe_dev_interrupt_delayed_handler(void *param);
44 static void txgbe_configure_msix(struct rte_eth_dev *dev);
46 #define TXGBE_SET_HWSTRIP(h, q) do {\
47 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
48 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
49 (h)->bitmap[idx] |= 1 << bit;\
52 #define TXGBE_CLEAR_HWSTRIP(h, q) do {\
53 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
54 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
55 (h)->bitmap[idx] &= ~(1 << bit);\
58 #define TXGBE_GET_HWSTRIP(h, q, r) do {\
59 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
60 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
61 (r) = (h)->bitmap[idx] >> bit & 1;\
65 * The set of PCI devices this driver supports
67 static const struct rte_pci_id pci_id_txgbe_map[] = {
68 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_RAPTOR_SFP) },
69 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, TXGBE_DEV_ID_WX1820_SFP) },
70 { .vendor_id = 0, /* sentinel */ },
73 static const struct rte_eth_desc_lim rx_desc_lim = {
74 .nb_max = TXGBE_RING_DESC_MAX,
75 .nb_min = TXGBE_RING_DESC_MIN,
76 .nb_align = TXGBE_RXD_ALIGN,
79 static const struct rte_eth_desc_lim tx_desc_lim = {
80 .nb_max = TXGBE_RING_DESC_MAX,
81 .nb_min = TXGBE_RING_DESC_MIN,
82 .nb_align = TXGBE_TXD_ALIGN,
83 .nb_seg_max = TXGBE_TX_MAX_SEG,
84 .nb_mtu_seg_max = TXGBE_TX_MAX_SEG,
87 static const struct eth_dev_ops txgbe_eth_dev_ops;
89 #define HW_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, m)}
90 #define HW_XSTAT_NAME(m, n) {n, offsetof(struct txgbe_hw_stats, m)}
91 static const struct rte_txgbe_xstats_name_off rte_txgbe_stats_strings[] = {
93 HW_XSTAT(mng_bmc2host_packets),
94 HW_XSTAT(mng_host2bmc_packets),
100 HW_XSTAT(rx_total_bytes),
101 HW_XSTAT(rx_total_packets),
102 HW_XSTAT(tx_total_packets),
103 HW_XSTAT(rx_total_missed_packets),
104 HW_XSTAT(rx_broadcast_packets),
105 HW_XSTAT(rx_multicast_packets),
106 HW_XSTAT(rx_management_packets),
107 HW_XSTAT(tx_management_packets),
108 HW_XSTAT(rx_management_dropped),
111 HW_XSTAT(rx_crc_errors),
112 HW_XSTAT(rx_illegal_byte_errors),
113 HW_XSTAT(rx_error_bytes),
114 HW_XSTAT(rx_mac_short_packet_dropped),
115 HW_XSTAT(rx_length_errors),
116 HW_XSTAT(rx_undersize_errors),
117 HW_XSTAT(rx_fragment_errors),
118 HW_XSTAT(rx_oversize_errors),
119 HW_XSTAT(rx_jabber_errors),
120 HW_XSTAT(rx_l3_l4_xsum_error),
121 HW_XSTAT(mac_local_errors),
122 HW_XSTAT(mac_remote_errors),
125 HW_XSTAT(flow_director_added_filters),
126 HW_XSTAT(flow_director_removed_filters),
127 HW_XSTAT(flow_director_filter_add_errors),
128 HW_XSTAT(flow_director_filter_remove_errors),
129 HW_XSTAT(flow_director_matched_filters),
130 HW_XSTAT(flow_director_missed_filters),
133 HW_XSTAT(rx_fcoe_crc_errors),
134 HW_XSTAT(rx_fcoe_mbuf_allocation_errors),
135 HW_XSTAT(rx_fcoe_dropped),
136 HW_XSTAT(rx_fcoe_packets),
137 HW_XSTAT(tx_fcoe_packets),
138 HW_XSTAT(rx_fcoe_bytes),
139 HW_XSTAT(tx_fcoe_bytes),
140 HW_XSTAT(rx_fcoe_no_ddp),
141 HW_XSTAT(rx_fcoe_no_ddp_ext_buff),
144 HW_XSTAT(tx_macsec_pkts_untagged),
145 HW_XSTAT(tx_macsec_pkts_encrypted),
146 HW_XSTAT(tx_macsec_pkts_protected),
147 HW_XSTAT(tx_macsec_octets_encrypted),
148 HW_XSTAT(tx_macsec_octets_protected),
149 HW_XSTAT(rx_macsec_pkts_untagged),
150 HW_XSTAT(rx_macsec_pkts_badtag),
151 HW_XSTAT(rx_macsec_pkts_nosci),
152 HW_XSTAT(rx_macsec_pkts_unknownsci),
153 HW_XSTAT(rx_macsec_octets_decrypted),
154 HW_XSTAT(rx_macsec_octets_validated),
155 HW_XSTAT(rx_macsec_sc_pkts_unchecked),
156 HW_XSTAT(rx_macsec_sc_pkts_delayed),
157 HW_XSTAT(rx_macsec_sc_pkts_late),
158 HW_XSTAT(rx_macsec_sa_pkts_ok),
159 HW_XSTAT(rx_macsec_sa_pkts_invalid),
160 HW_XSTAT(rx_macsec_sa_pkts_notvalid),
161 HW_XSTAT(rx_macsec_sa_pkts_unusedsa),
162 HW_XSTAT(rx_macsec_sa_pkts_notusingsa),
165 HW_XSTAT(rx_size_64_packets),
166 HW_XSTAT(rx_size_65_to_127_packets),
167 HW_XSTAT(rx_size_128_to_255_packets),
168 HW_XSTAT(rx_size_256_to_511_packets),
169 HW_XSTAT(rx_size_512_to_1023_packets),
170 HW_XSTAT(rx_size_1024_to_max_packets),
171 HW_XSTAT(tx_size_64_packets),
172 HW_XSTAT(tx_size_65_to_127_packets),
173 HW_XSTAT(tx_size_128_to_255_packets),
174 HW_XSTAT(tx_size_256_to_511_packets),
175 HW_XSTAT(tx_size_512_to_1023_packets),
176 HW_XSTAT(tx_size_1024_to_max_packets),
179 HW_XSTAT(tx_xon_packets),
180 HW_XSTAT(rx_xon_packets),
181 HW_XSTAT(tx_xoff_packets),
182 HW_XSTAT(rx_xoff_packets),
184 HW_XSTAT_NAME(tx_xon_packets, "tx_flow_control_xon_packets"),
185 HW_XSTAT_NAME(rx_xon_packets, "rx_flow_control_xon_packets"),
186 HW_XSTAT_NAME(tx_xoff_packets, "tx_flow_control_xoff_packets"),
187 HW_XSTAT_NAME(rx_xoff_packets, "rx_flow_control_xoff_packets"),
190 #define TXGBE_NB_HW_STATS (sizeof(rte_txgbe_stats_strings) / \
191 sizeof(rte_txgbe_stats_strings[0]))
193 /* Per-priority statistics */
194 #define UP_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, up[0].m)}
195 static const struct rte_txgbe_xstats_name_off rte_txgbe_up_strings[] = {
196 UP_XSTAT(rx_up_packets),
197 UP_XSTAT(tx_up_packets),
198 UP_XSTAT(rx_up_bytes),
199 UP_XSTAT(tx_up_bytes),
200 UP_XSTAT(rx_up_drop_packets),
202 UP_XSTAT(tx_up_xon_packets),
203 UP_XSTAT(rx_up_xon_packets),
204 UP_XSTAT(tx_up_xoff_packets),
205 UP_XSTAT(rx_up_xoff_packets),
206 UP_XSTAT(rx_up_dropped),
207 UP_XSTAT(rx_up_mbuf_alloc_errors),
208 UP_XSTAT(tx_up_xon2off_packets),
211 #define TXGBE_NB_UP_STATS (sizeof(rte_txgbe_up_strings) / \
212 sizeof(rte_txgbe_up_strings[0]))
214 /* Per-queue statistics */
215 #define QP_XSTAT(m) {#m, offsetof(struct txgbe_hw_stats, qp[0].m)}
216 static const struct rte_txgbe_xstats_name_off rte_txgbe_qp_strings[] = {
217 QP_XSTAT(rx_qp_packets),
218 QP_XSTAT(tx_qp_packets),
219 QP_XSTAT(rx_qp_bytes),
220 QP_XSTAT(tx_qp_bytes),
221 QP_XSTAT(rx_qp_mc_packets),
224 #define TXGBE_NB_QP_STATS (sizeof(rte_txgbe_qp_strings) / \
225 sizeof(rte_txgbe_qp_strings[0]))
228 txgbe_is_sfp(struct txgbe_hw *hw)
230 switch (hw->phy.type) {
231 case txgbe_phy_sfp_avago:
232 case txgbe_phy_sfp_ftl:
233 case txgbe_phy_sfp_intel:
234 case txgbe_phy_sfp_unknown:
235 case txgbe_phy_sfp_tyco_passive:
236 case txgbe_phy_sfp_unknown_passive:
243 static inline int32_t
244 txgbe_pf_reset_hw(struct txgbe_hw *hw)
249 status = hw->mac.reset_hw(hw);
251 ctrl_ext = rd32(hw, TXGBE_PORTCTL);
252 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
253 ctrl_ext |= TXGBE_PORTCTL_RSTDONE;
254 wr32(hw, TXGBE_PORTCTL, ctrl_ext);
257 if (status == TXGBE_ERR_SFP_NOT_PRESENT)
263 txgbe_enable_intr(struct rte_eth_dev *dev)
265 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
266 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
268 wr32(hw, TXGBE_IENMISC, intr->mask_misc);
269 wr32(hw, TXGBE_IMC(0), TXGBE_IMC_MASK);
270 wr32(hw, TXGBE_IMC(1), TXGBE_IMC_MASK);
275 txgbe_disable_intr(struct txgbe_hw *hw)
277 PMD_INIT_FUNC_TRACE();
279 wr32(hw, TXGBE_IENMISC, ~BIT_MASK32);
280 wr32(hw, TXGBE_IMS(0), TXGBE_IMC_MASK);
281 wr32(hw, TXGBE_IMS(1), TXGBE_IMC_MASK);
286 txgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
291 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
292 struct txgbe_stat_mappings *stat_mappings =
293 TXGBE_DEV_STAT_MAPPINGS(eth_dev);
294 uint32_t qsmr_mask = 0;
295 uint32_t clearing_mask = QMAP_FIELD_RESERVED_BITS_MASK;
299 if (hw->mac.type != txgbe_mac_raptor)
302 if (stat_idx & !QMAP_FIELD_RESERVED_BITS_MASK)
305 PMD_INIT_LOG(DEBUG, "Setting port %d, %s queue_id %d to stat index %d",
306 (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
309 n = (uint8_t)(queue_id / NB_QMAP_FIELDS_PER_QSM_REG);
310 if (n >= TXGBE_NB_STAT_MAPPING) {
311 PMD_INIT_LOG(ERR, "Nb of stat mapping registers exceeded");
314 offset = (uint8_t)(queue_id % NB_QMAP_FIELDS_PER_QSM_REG);
316 /* Now clear any previous stat_idx set */
317 clearing_mask <<= (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
319 stat_mappings->tqsm[n] &= ~clearing_mask;
321 stat_mappings->rqsm[n] &= ~clearing_mask;
323 q_map = (uint32_t)stat_idx;
324 q_map &= QMAP_FIELD_RESERVED_BITS_MASK;
325 qsmr_mask = q_map << (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
327 stat_mappings->tqsm[n] |= qsmr_mask;
329 stat_mappings->rqsm[n] |= qsmr_mask;
331 PMD_INIT_LOG(DEBUG, "Set port %d, %s queue_id %d to stat index %d",
332 (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
334 PMD_INIT_LOG(DEBUG, "%s[%d] = 0x%08x", is_rx ? "RQSMR" : "TQSM", n,
335 is_rx ? stat_mappings->rqsm[n] : stat_mappings->tqsm[n]);
340 * Ensure that all locks are released before first NVM or PHY access
343 txgbe_swfw_lock_reset(struct txgbe_hw *hw)
348 * These ones are more tricky since they are common to all ports; but
349 * swfw_sync retries last long enough (1s) to be almost sure that if
350 * lock can not be taken it is due to an improper lock of the
353 mask = TXGBE_MNGSEM_SWPHY |
355 TXGBE_MNGSEM_SWFLASH;
356 if (hw->mac.acquire_swfw_sync(hw, mask) < 0)
357 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
359 hw->mac.release_swfw_sync(hw, mask);
363 eth_txgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
365 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
366 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
367 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(eth_dev);
368 struct txgbe_hwstrip *hwstrip = TXGBE_DEV_HWSTRIP(eth_dev);
369 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
370 const struct rte_memzone *mz;
375 PMD_INIT_FUNC_TRACE();
377 eth_dev->dev_ops = &txgbe_eth_dev_ops;
378 eth_dev->rx_pkt_burst = &txgbe_recv_pkts;
379 eth_dev->tx_pkt_burst = &txgbe_xmit_pkts;
380 eth_dev->tx_pkt_prepare = &txgbe_prep_pkts;
383 * For secondary processes, we don't initialise any further as primary
384 * has already done this work. Only check we don't need a different
385 * RX and TX function.
387 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
388 struct txgbe_tx_queue *txq;
389 /* TX queue function in primary, set by last queue initialized
390 * Tx queue may not initialized by primary process
392 if (eth_dev->data->tx_queues) {
393 uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
394 txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
395 txgbe_set_tx_function(eth_dev, txq);
397 /* Use default TX function if we get here */
398 PMD_INIT_LOG(NOTICE, "No TX queues configured yet. "
399 "Using default TX function.");
402 txgbe_set_rx_function(eth_dev);
407 rte_eth_copy_pci_info(eth_dev, pci_dev);
409 /* Vendor and Device ID need to be set before init of shared code */
410 hw->device_id = pci_dev->id.device_id;
411 hw->vendor_id = pci_dev->id.vendor_id;
412 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
413 hw->allow_unsupported_sfp = 1;
415 /* Reserve memory for interrupt status block */
416 mz = rte_eth_dma_zone_reserve(eth_dev, "txgbe_driver", -1,
417 16, TXGBE_ALIGN, SOCKET_ID_ANY);
421 hw->isb_dma = TMZ_PADDR(mz);
422 hw->isb_mem = TMZ_VADDR(mz);
424 /* Initialize the shared code (base driver) */
425 err = txgbe_init_shared_code(hw);
427 PMD_INIT_LOG(ERR, "Shared code init failed: %d", err);
431 /* Unlock any pending hardware semaphore */
432 txgbe_swfw_lock_reset(hw);
434 err = hw->rom.init_params(hw);
436 PMD_INIT_LOG(ERR, "The EEPROM init failed: %d", err);
440 /* Make sure we have a good EEPROM before we read from it */
441 err = hw->rom.validate_checksum(hw, &csum);
443 PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", err);
447 err = hw->mac.init_hw(hw);
450 * Devices with copper phys will fail to initialise if txgbe_init_hw()
451 * is called too soon after the kernel driver unbinding/binding occurs.
452 * The failure occurs in txgbe_identify_phy() for all devices,
453 * but for non-copper devies, txgbe_identify_sfp_module() is
454 * also called. See txgbe_identify_phy(). The reason for the
455 * failure is not known, and only occuts when virtualisation features
456 * are disabled in the bios. A delay of 200ms was found to be enough by
457 * trial-and-error, and is doubled to be safe.
459 if (err && hw->phy.media_type == txgbe_media_type_copper) {
461 err = hw->mac.init_hw(hw);
464 if (err == TXGBE_ERR_SFP_NOT_PRESENT)
467 if (err == TXGBE_ERR_EEPROM_VERSION) {
468 PMD_INIT_LOG(ERR, "This device is a pre-production adapter/"
469 "LOM. Please be aware there may be issues associated "
470 "with your hardware.");
471 PMD_INIT_LOG(ERR, "If you are experiencing problems "
472 "please contact your hardware representative "
473 "who provided you with this hardware.");
474 } else if (err == TXGBE_ERR_SFP_NOT_SUPPORTED) {
475 PMD_INIT_LOG(ERR, "Unsupported SFP+ Module");
478 PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", err);
482 /* Reset the hw statistics */
483 txgbe_dev_stats_reset(eth_dev);
485 /* disable interrupt */
486 txgbe_disable_intr(hw);
488 /* Allocate memory for storing MAC addresses */
489 eth_dev->data->mac_addrs = rte_zmalloc("txgbe", RTE_ETHER_ADDR_LEN *
490 hw->mac.num_rar_entries, 0);
491 if (eth_dev->data->mac_addrs == NULL) {
493 "Failed to allocate %u bytes needed to store "
495 RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
499 /* Copy the permanent MAC address */
500 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
501 ð_dev->data->mac_addrs[0]);
503 /* Allocate memory for storing hash filter MAC addresses */
504 eth_dev->data->hash_mac_addrs = rte_zmalloc("txgbe",
505 RTE_ETHER_ADDR_LEN * TXGBE_VMDQ_NUM_UC_MAC, 0);
506 if (eth_dev->data->hash_mac_addrs == NULL) {
508 "Failed to allocate %d bytes needed to store MAC addresses",
509 RTE_ETHER_ADDR_LEN * TXGBE_VMDQ_NUM_UC_MAC);
513 /* initialize the vfta */
514 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
516 /* initialize the hw strip bitmap*/
517 memset(hwstrip, 0, sizeof(*hwstrip));
519 /* initialize PF if max_vfs not zero */
520 txgbe_pf_host_init(eth_dev);
522 ctrl_ext = rd32(hw, TXGBE_PORTCTL);
523 /* let hardware know driver is loaded */
524 ctrl_ext |= TXGBE_PORTCTL_DRVLOAD;
525 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
526 ctrl_ext |= TXGBE_PORTCTL_RSTDONE;
527 wr32(hw, TXGBE_PORTCTL, ctrl_ext);
530 if (txgbe_is_sfp(hw) && hw->phy.sfp_type != txgbe_sfp_type_not_present)
531 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d, SFP+: %d",
532 (int)hw->mac.type, (int)hw->phy.type,
533 (int)hw->phy.sfp_type);
535 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
536 (int)hw->mac.type, (int)hw->phy.type);
538 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
539 eth_dev->data->port_id, pci_dev->id.vendor_id,
540 pci_dev->id.device_id);
542 rte_intr_callback_register(intr_handle,
543 txgbe_dev_interrupt_handler, eth_dev);
545 /* enable uio/vfio intr/eventfd mapping */
546 rte_intr_enable(intr_handle);
548 /* enable support intr */
549 txgbe_enable_intr(eth_dev);
555 eth_txgbe_dev_uninit(struct rte_eth_dev *eth_dev)
557 PMD_INIT_FUNC_TRACE();
559 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
562 txgbe_dev_close(eth_dev);
568 eth_txgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
569 struct rte_pci_device *pci_dev)
571 struct rte_eth_dev *pf_ethdev;
572 struct rte_eth_devargs eth_da;
575 if (pci_dev->device.devargs) {
576 retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
581 memset(ð_da, 0, sizeof(eth_da));
584 retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
585 sizeof(struct txgbe_adapter),
586 eth_dev_pci_specific_init, pci_dev,
587 eth_txgbe_dev_init, NULL);
589 if (retval || eth_da.nb_representor_ports < 1)
592 pf_ethdev = rte_eth_dev_allocated(pci_dev->device.name);
593 if (pf_ethdev == NULL)
599 static int eth_txgbe_pci_remove(struct rte_pci_device *pci_dev)
601 struct rte_eth_dev *ethdev;
603 ethdev = rte_eth_dev_allocated(pci_dev->device.name);
607 return rte_eth_dev_destroy(ethdev, eth_txgbe_dev_uninit);
610 static struct rte_pci_driver rte_txgbe_pmd = {
611 .id_table = pci_id_txgbe_map,
612 .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
613 RTE_PCI_DRV_INTR_LSC,
614 .probe = eth_txgbe_pci_probe,
615 .remove = eth_txgbe_pci_remove,
619 txgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
621 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
622 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
627 vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
628 vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
629 vfta = rd32(hw, TXGBE_VLANTBL(vid_idx));
634 wr32(hw, TXGBE_VLANTBL(vid_idx), vfta);
636 /* update local VFTA copy */
637 shadow_vfta->vfta[vid_idx] = vfta;
643 txgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
645 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
646 struct txgbe_rx_queue *rxq;
648 uint32_t rxcfg, rxbal, rxbah;
651 txgbe_vlan_hw_strip_enable(dev, queue);
653 txgbe_vlan_hw_strip_disable(dev, queue);
655 rxq = dev->data->rx_queues[queue];
656 rxbal = rd32(hw, TXGBE_RXBAL(rxq->reg_idx));
657 rxbah = rd32(hw, TXGBE_RXBAH(rxq->reg_idx));
658 rxcfg = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
659 if (rxq->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
660 restart = (rxcfg & TXGBE_RXCFG_ENA) &&
661 !(rxcfg & TXGBE_RXCFG_VLAN);
662 rxcfg |= TXGBE_RXCFG_VLAN;
664 restart = (rxcfg & TXGBE_RXCFG_ENA) &&
665 (rxcfg & TXGBE_RXCFG_VLAN);
666 rxcfg &= ~TXGBE_RXCFG_VLAN;
668 rxcfg &= ~TXGBE_RXCFG_ENA;
671 /* set vlan strip for ring */
672 txgbe_dev_rx_queue_stop(dev, queue);
673 wr32(hw, TXGBE_RXBAL(rxq->reg_idx), rxbal);
674 wr32(hw, TXGBE_RXBAH(rxq->reg_idx), rxbah);
675 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), rxcfg);
676 txgbe_dev_rx_queue_start(dev, queue);
681 txgbe_vlan_tpid_set(struct rte_eth_dev *dev,
682 enum rte_vlan_type vlan_type,
685 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
687 uint32_t portctrl, vlan_ext, qinq;
689 portctrl = rd32(hw, TXGBE_PORTCTL);
691 vlan_ext = (portctrl & TXGBE_PORTCTL_VLANEXT);
692 qinq = vlan_ext && (portctrl & TXGBE_PORTCTL_QINQ);
694 case ETH_VLAN_TYPE_INNER:
696 wr32m(hw, TXGBE_VLANCTL,
697 TXGBE_VLANCTL_TPID_MASK,
698 TXGBE_VLANCTL_TPID(tpid));
699 wr32m(hw, TXGBE_DMATXCTRL,
700 TXGBE_DMATXCTRL_TPID_MASK,
701 TXGBE_DMATXCTRL_TPID(tpid));
704 PMD_DRV_LOG(ERR, "Inner type is not supported"
709 wr32m(hw, TXGBE_TAGTPID(0),
710 TXGBE_TAGTPID_LSB_MASK,
711 TXGBE_TAGTPID_LSB(tpid));
714 case ETH_VLAN_TYPE_OUTER:
716 /* Only the high 16-bits is valid */
717 wr32m(hw, TXGBE_EXTAG,
718 TXGBE_EXTAG_VLAN_MASK,
719 TXGBE_EXTAG_VLAN(tpid));
721 wr32m(hw, TXGBE_VLANCTL,
722 TXGBE_VLANCTL_TPID_MASK,
723 TXGBE_VLANCTL_TPID(tpid));
724 wr32m(hw, TXGBE_DMATXCTRL,
725 TXGBE_DMATXCTRL_TPID_MASK,
726 TXGBE_DMATXCTRL_TPID(tpid));
730 wr32m(hw, TXGBE_TAGTPID(0),
731 TXGBE_TAGTPID_MSB_MASK,
732 TXGBE_TAGTPID_MSB(tpid));
736 PMD_DRV_LOG(ERR, "Unsupported VLAN type %d", vlan_type);
744 txgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev)
746 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
749 PMD_INIT_FUNC_TRACE();
751 /* Filter Table Disable */
752 vlnctrl = rd32(hw, TXGBE_VLANCTL);
753 vlnctrl &= ~TXGBE_VLANCTL_VFE;
754 wr32(hw, TXGBE_VLANCTL, vlnctrl);
758 txgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev)
760 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
761 struct txgbe_vfta *shadow_vfta = TXGBE_DEV_VFTA(dev);
765 PMD_INIT_FUNC_TRACE();
767 /* Filter Table Enable */
768 vlnctrl = rd32(hw, TXGBE_VLANCTL);
769 vlnctrl &= ~TXGBE_VLANCTL_CFIENA;
770 vlnctrl |= TXGBE_VLANCTL_VFE;
771 wr32(hw, TXGBE_VLANCTL, vlnctrl);
773 /* write whatever is in local vfta copy */
774 for (i = 0; i < TXGBE_VFTA_SIZE; i++)
775 wr32(hw, TXGBE_VLANTBL(i), shadow_vfta->vfta[i]);
779 txgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev, uint16_t queue, bool on)
781 struct txgbe_hwstrip *hwstrip = TXGBE_DEV_HWSTRIP(dev);
782 struct txgbe_rx_queue *rxq;
784 if (queue >= TXGBE_MAX_RX_QUEUE_NUM)
788 TXGBE_SET_HWSTRIP(hwstrip, queue);
790 TXGBE_CLEAR_HWSTRIP(hwstrip, queue);
792 if (queue >= dev->data->nb_rx_queues)
795 rxq = dev->data->rx_queues[queue];
798 rxq->vlan_flags = PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
799 rxq->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
801 rxq->vlan_flags = PKT_RX_VLAN;
802 rxq->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
807 txgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue)
809 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
812 PMD_INIT_FUNC_TRACE();
814 ctrl = rd32(hw, TXGBE_RXCFG(queue));
815 ctrl &= ~TXGBE_RXCFG_VLAN;
816 wr32(hw, TXGBE_RXCFG(queue), ctrl);
818 /* record those setting for HW strip per queue */
819 txgbe_vlan_hw_strip_bitmap_set(dev, queue, 0);
823 txgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue)
825 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
828 PMD_INIT_FUNC_TRACE();
830 ctrl = rd32(hw, TXGBE_RXCFG(queue));
831 ctrl |= TXGBE_RXCFG_VLAN;
832 wr32(hw, TXGBE_RXCFG(queue), ctrl);
834 /* record those setting for HW strip per queue */
835 txgbe_vlan_hw_strip_bitmap_set(dev, queue, 1);
839 txgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev)
841 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
844 PMD_INIT_FUNC_TRACE();
846 ctrl = rd32(hw, TXGBE_PORTCTL);
847 ctrl &= ~TXGBE_PORTCTL_VLANEXT;
848 ctrl &= ~TXGBE_PORTCTL_QINQ;
849 wr32(hw, TXGBE_PORTCTL, ctrl);
853 txgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev)
855 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
856 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
857 struct rte_eth_txmode *txmode = &dev->data->dev_conf.txmode;
860 PMD_INIT_FUNC_TRACE();
862 ctrl = rd32(hw, TXGBE_PORTCTL);
863 ctrl |= TXGBE_PORTCTL_VLANEXT;
864 if (rxmode->offloads & DEV_RX_OFFLOAD_QINQ_STRIP ||
865 txmode->offloads & DEV_TX_OFFLOAD_QINQ_INSERT)
866 ctrl |= TXGBE_PORTCTL_QINQ;
867 wr32(hw, TXGBE_PORTCTL, ctrl);
871 txgbe_vlan_hw_strip_config(struct rte_eth_dev *dev)
873 struct txgbe_rx_queue *rxq;
876 PMD_INIT_FUNC_TRACE();
878 for (i = 0; i < dev->data->nb_rx_queues; i++) {
879 rxq = dev->data->rx_queues[i];
881 if (rxq->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
882 txgbe_vlan_strip_queue_set(dev, i, 1);
884 txgbe_vlan_strip_queue_set(dev, i, 0);
889 txgbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev, int mask)
892 struct rte_eth_rxmode *rxmode;
893 struct txgbe_rx_queue *rxq;
895 if (mask & ETH_VLAN_STRIP_MASK) {
896 rxmode = &dev->data->dev_conf.rxmode;
897 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
898 for (i = 0; i < dev->data->nb_rx_queues; i++) {
899 rxq = dev->data->rx_queues[i];
900 rxq->offloads |= DEV_RX_OFFLOAD_VLAN_STRIP;
903 for (i = 0; i < dev->data->nb_rx_queues; i++) {
904 rxq = dev->data->rx_queues[i];
905 rxq->offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP;
911 txgbe_vlan_offload_config(struct rte_eth_dev *dev, int mask)
913 struct rte_eth_rxmode *rxmode;
914 rxmode = &dev->data->dev_conf.rxmode;
916 if (mask & ETH_VLAN_STRIP_MASK)
917 txgbe_vlan_hw_strip_config(dev);
919 if (mask & ETH_VLAN_FILTER_MASK) {
920 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
921 txgbe_vlan_hw_filter_enable(dev);
923 txgbe_vlan_hw_filter_disable(dev);
926 if (mask & ETH_VLAN_EXTEND_MASK) {
927 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
928 txgbe_vlan_hw_extend_enable(dev);
930 txgbe_vlan_hw_extend_disable(dev);
937 txgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
939 txgbe_config_vlan_strip_on_all_queues(dev, mask);
941 txgbe_vlan_offload_config(dev, mask);
947 txgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
949 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
954 RTE_ETH_DEV_SRIOV(dev).active = ETH_64_POOLS;
957 RTE_ETH_DEV_SRIOV(dev).active = ETH_32_POOLS;
963 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool =
964 TXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
965 RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
966 pci_dev->max_vfs * RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
971 txgbe_check_mq_mode(struct rte_eth_dev *dev)
973 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
974 uint16_t nb_rx_q = dev->data->nb_rx_queues;
975 uint16_t nb_tx_q = dev->data->nb_tx_queues;
977 if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
978 /* check multi-queue mode */
979 switch (dev_conf->rxmode.mq_mode) {
980 case ETH_MQ_RX_VMDQ_DCB:
981 PMD_INIT_LOG(INFO, "ETH_MQ_RX_VMDQ_DCB mode supported in SRIOV");
983 case ETH_MQ_RX_VMDQ_DCB_RSS:
984 /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
985 PMD_INIT_LOG(ERR, "SRIOV active,"
986 " unsupported mq_mode rx %d.",
987 dev_conf->rxmode.mq_mode);
990 case ETH_MQ_RX_VMDQ_RSS:
991 dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
992 if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
993 if (txgbe_check_vf_rss_rxq_num(dev, nb_rx_q)) {
994 PMD_INIT_LOG(ERR, "SRIOV is active,"
995 " invalid queue number"
996 " for VMDQ RSS, allowed"
997 " value are 1, 2 or 4.");
1001 case ETH_MQ_RX_VMDQ_ONLY:
1002 case ETH_MQ_RX_NONE:
1003 /* if nothing mq mode configure, use default scheme */
1004 dev->data->dev_conf.rxmode.mq_mode =
1005 ETH_MQ_RX_VMDQ_ONLY;
1007 default: /* ETH_MQ_RX_DCB, ETH_MQ_RX_DCB_RSS or ETH_MQ_TX_DCB*/
1008 /* SRIOV only works in VMDq enable mode */
1009 PMD_INIT_LOG(ERR, "SRIOV is active,"
1010 " wrong mq_mode rx %d.",
1011 dev_conf->rxmode.mq_mode);
1015 switch (dev_conf->txmode.mq_mode) {
1016 case ETH_MQ_TX_VMDQ_DCB:
1017 PMD_INIT_LOG(INFO, "ETH_MQ_TX_VMDQ_DCB mode supported in SRIOV");
1018 dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_DCB;
1020 default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
1021 dev->data->dev_conf.txmode.mq_mode =
1022 ETH_MQ_TX_VMDQ_ONLY;
1026 /* check valid queue number */
1027 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
1028 (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
1029 PMD_INIT_LOG(ERR, "SRIOV is active,"
1030 " nb_rx_q=%d nb_tx_q=%d queue number"
1031 " must be less than or equal to %d.",
1033 RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
1037 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB_RSS) {
1038 PMD_INIT_LOG(ERR, "VMDQ+DCB+RSS mq_mode is"
1042 /* check configuration for vmdb+dcb mode */
1043 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_VMDQ_DCB) {
1044 const struct rte_eth_vmdq_dcb_conf *conf;
1046 if (nb_rx_q != TXGBE_VMDQ_DCB_NB_QUEUES) {
1047 PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_rx_q != %d.",
1048 TXGBE_VMDQ_DCB_NB_QUEUES);
1051 conf = &dev_conf->rx_adv_conf.vmdq_dcb_conf;
1052 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1053 conf->nb_queue_pools == ETH_32_POOLS)) {
1054 PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
1055 " nb_queue_pools must be %d or %d.",
1056 ETH_16_POOLS, ETH_32_POOLS);
1060 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
1061 const struct rte_eth_vmdq_dcb_tx_conf *conf;
1063 if (nb_tx_q != TXGBE_VMDQ_DCB_NB_QUEUES) {
1064 PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_tx_q != %d",
1065 TXGBE_VMDQ_DCB_NB_QUEUES);
1068 conf = &dev_conf->tx_adv_conf.vmdq_dcb_tx_conf;
1069 if (!(conf->nb_queue_pools == ETH_16_POOLS ||
1070 conf->nb_queue_pools == ETH_32_POOLS)) {
1071 PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
1072 " nb_queue_pools != %d and"
1073 " nb_queue_pools != %d.",
1074 ETH_16_POOLS, ETH_32_POOLS);
1079 /* For DCB mode check our configuration before we go further */
1080 if (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) {
1081 const struct rte_eth_dcb_rx_conf *conf;
1083 conf = &dev_conf->rx_adv_conf.dcb_rx_conf;
1084 if (!(conf->nb_tcs == ETH_4_TCS ||
1085 conf->nb_tcs == ETH_8_TCS)) {
1086 PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
1087 " and nb_tcs != %d.",
1088 ETH_4_TCS, ETH_8_TCS);
1093 if (dev_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
1094 const struct rte_eth_dcb_tx_conf *conf;
1096 conf = &dev_conf->tx_adv_conf.dcb_tx_conf;
1097 if (!(conf->nb_tcs == ETH_4_TCS ||
1098 conf->nb_tcs == ETH_8_TCS)) {
1099 PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
1100 " and nb_tcs != %d.",
1101 ETH_4_TCS, ETH_8_TCS);
1110 txgbe_dev_configure(struct rte_eth_dev *dev)
1112 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1113 struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
1116 PMD_INIT_FUNC_TRACE();
1118 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
1119 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
1121 /* multiple queue mode checking */
1122 ret = txgbe_check_mq_mode(dev);
1124 PMD_DRV_LOG(ERR, "txgbe_check_mq_mode fails with %d.",
1129 /* set flag to update link status after init */
1130 intr->flags |= TXGBE_FLAG_NEED_LINK_UPDATE;
1133 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
1134 * allocation Rx preconditions we will reset it.
1136 adapter->rx_bulk_alloc_allowed = true;
1142 txgbe_dev_phy_intr_setup(struct rte_eth_dev *dev)
1144 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1145 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
1148 gpie = rd32(hw, TXGBE_GPIOINTEN);
1149 gpie |= TXGBE_GPIOBIT_6;
1150 wr32(hw, TXGBE_GPIOINTEN, gpie);
1151 intr->mask_misc |= TXGBE_ICRMISC_GPIO;
1155 txgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
1156 uint16_t tx_rate, uint64_t q_msk)
1158 struct txgbe_hw *hw;
1159 struct txgbe_vf_info *vfinfo;
1160 struct rte_eth_link link;
1161 uint8_t nb_q_per_pool;
1162 uint32_t queue_stride;
1163 uint32_t queue_idx, idx = 0, vf_idx;
1165 uint16_t total_rate = 0;
1166 struct rte_pci_device *pci_dev;
1169 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1170 ret = rte_eth_link_get_nowait(dev->data->port_id, &link);
1174 if (vf >= pci_dev->max_vfs)
1177 if (tx_rate > link.link_speed)
1183 hw = TXGBE_DEV_HW(dev);
1184 vfinfo = *(TXGBE_DEV_VFDATA(dev));
1185 nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
1186 queue_stride = TXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
1187 queue_idx = vf * queue_stride;
1188 queue_end = queue_idx + nb_q_per_pool - 1;
1189 if (queue_end >= hw->mac.max_tx_queues)
1193 for (vf_idx = 0; vf_idx < pci_dev->max_vfs; vf_idx++) {
1196 for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
1198 total_rate += vfinfo[vf_idx].tx_rate[idx];
1204 /* Store tx_rate for this vf. */
1205 for (idx = 0; idx < nb_q_per_pool; idx++) {
1206 if (((uint64_t)0x1 << idx) & q_msk) {
1207 if (vfinfo[vf].tx_rate[idx] != tx_rate)
1208 vfinfo[vf].tx_rate[idx] = tx_rate;
1209 total_rate += tx_rate;
1213 if (total_rate > dev->data->dev_link.link_speed) {
1214 /* Reset stored TX rate of the VF if it causes exceed
1217 memset(vfinfo[vf].tx_rate, 0, sizeof(vfinfo[vf].tx_rate));
1221 /* Set ARBTXRATE of each queue/pool for vf X */
1222 for (; queue_idx <= queue_end; queue_idx++) {
1224 txgbe_set_queue_rate_limit(dev, queue_idx, tx_rate);
1232 * Configure device link speed and setup link.
1233 * It returns 0 on success.
1236 txgbe_dev_start(struct rte_eth_dev *dev)
1238 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1239 struct txgbe_hw_stats *hw_stats = TXGBE_DEV_STATS(dev);
1240 struct txgbe_vf_info *vfinfo = *TXGBE_DEV_VFDATA(dev);
1241 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1242 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1243 uint32_t intr_vector = 0;
1245 bool link_up = false, negotiate = 0;
1247 uint32_t allowed_speeds = 0;
1251 uint32_t *link_speeds;
1253 PMD_INIT_FUNC_TRACE();
1255 /* TXGBE devices don't support:
1256 * - half duplex (checked afterwards for valid speeds)
1257 * - fixed speed: TODO implement
1259 if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
1261 "Invalid link_speeds for port %u, fix speed not supported",
1262 dev->data->port_id);
1266 /* Stop the link setup handler before resetting the HW. */
1267 rte_eal_alarm_cancel(txgbe_dev_setup_link_alarm_handler, dev);
1269 /* disable uio/vfio intr/eventfd mapping */
1270 rte_intr_disable(intr_handle);
1273 hw->adapter_stopped = 0;
1276 /* reinitialize adapter
1277 * this calls reset and start
1279 hw->nb_rx_queues = dev->data->nb_rx_queues;
1280 hw->nb_tx_queues = dev->data->nb_tx_queues;
1281 status = txgbe_pf_reset_hw(hw);
1284 hw->mac.start_hw(hw);
1285 hw->mac.get_link_status = true;
1287 /* configure PF module if SRIOV enabled */
1288 txgbe_pf_host_configure(dev);
1290 txgbe_dev_phy_intr_setup(dev);
1292 /* check and configure queue intr-vector mapping */
1293 if ((rte_intr_cap_multiple(intr_handle) ||
1294 !RTE_ETH_DEV_SRIOV(dev).active) &&
1295 dev->data->dev_conf.intr_conf.rxq != 0) {
1296 intr_vector = dev->data->nb_rx_queues;
1297 if (rte_intr_efd_enable(intr_handle, intr_vector))
1301 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1302 intr_handle->intr_vec =
1303 rte_zmalloc("intr_vec",
1304 dev->data->nb_rx_queues * sizeof(int), 0);
1305 if (intr_handle->intr_vec == NULL) {
1306 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1307 " intr_vec", dev->data->nb_rx_queues);
1312 /* confiugre msix for sleep until rx interrupt */
1313 txgbe_configure_msix(dev);
1315 /* initialize transmission unit */
1316 txgbe_dev_tx_init(dev);
1318 /* This can fail when allocating mbufs for descriptor rings */
1319 err = txgbe_dev_rx_init(dev);
1321 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
1325 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK |
1326 ETH_VLAN_EXTEND_MASK;
1327 err = txgbe_vlan_offload_config(dev, mask);
1329 PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
1333 /* Restore vf rate limit */
1334 if (vfinfo != NULL) {
1335 for (vf = 0; vf < pci_dev->max_vfs; vf++)
1336 for (idx = 0; idx < TXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
1337 if (vfinfo[vf].tx_rate[idx] != 0)
1338 txgbe_set_vf_rate_limit(dev, vf,
1339 vfinfo[vf].tx_rate[idx],
1343 err = txgbe_dev_rxtx_start(dev);
1345 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
1349 /* Skip link setup if loopback mode is enabled. */
1350 if (hw->mac.type == txgbe_mac_raptor &&
1351 dev->data->dev_conf.lpbk_mode)
1352 goto skip_link_setup;
1354 if (txgbe_is_sfp(hw) && hw->phy.multispeed_fiber) {
1355 err = hw->mac.setup_sfp(hw);
1360 if (hw->phy.media_type == txgbe_media_type_copper) {
1361 /* Turn on the copper */
1362 hw->phy.set_phy_power(hw, true);
1364 /* Turn on the laser */
1365 hw->mac.enable_tx_laser(hw);
1368 err = hw->mac.check_link(hw, &speed, &link_up, 0);
1371 dev->data->dev_link.link_status = link_up;
1373 err = hw->mac.get_link_capabilities(hw, &speed, &negotiate);
1377 allowed_speeds = ETH_LINK_SPEED_100M | ETH_LINK_SPEED_1G |
1380 link_speeds = &dev->data->dev_conf.link_speeds;
1381 if (*link_speeds & ~allowed_speeds) {
1382 PMD_INIT_LOG(ERR, "Invalid link setting");
1387 if (*link_speeds == ETH_LINK_SPEED_AUTONEG) {
1388 speed = (TXGBE_LINK_SPEED_100M_FULL |
1389 TXGBE_LINK_SPEED_1GB_FULL |
1390 TXGBE_LINK_SPEED_10GB_FULL);
1392 if (*link_speeds & ETH_LINK_SPEED_10G)
1393 speed |= TXGBE_LINK_SPEED_10GB_FULL;
1394 if (*link_speeds & ETH_LINK_SPEED_5G)
1395 speed |= TXGBE_LINK_SPEED_5GB_FULL;
1396 if (*link_speeds & ETH_LINK_SPEED_2_5G)
1397 speed |= TXGBE_LINK_SPEED_2_5GB_FULL;
1398 if (*link_speeds & ETH_LINK_SPEED_1G)
1399 speed |= TXGBE_LINK_SPEED_1GB_FULL;
1400 if (*link_speeds & ETH_LINK_SPEED_100M)
1401 speed |= TXGBE_LINK_SPEED_100M_FULL;
1404 err = hw->mac.setup_link(hw, speed, link_up);
1410 if (rte_intr_allow_others(intr_handle)) {
1411 /* check if lsc interrupt is enabled */
1412 if (dev->data->dev_conf.intr_conf.lsc != 0)
1413 txgbe_dev_lsc_interrupt_setup(dev, TRUE);
1415 txgbe_dev_lsc_interrupt_setup(dev, FALSE);
1416 txgbe_dev_macsec_interrupt_setup(dev);
1417 txgbe_set_ivar_map(hw, -1, 1, TXGBE_MISC_VEC_ID);
1419 rte_intr_callback_unregister(intr_handle,
1420 txgbe_dev_interrupt_handler, dev);
1421 if (dev->data->dev_conf.intr_conf.lsc != 0)
1422 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1423 " no intr multiplex");
1426 /* check if rxq interrupt is enabled */
1427 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1428 rte_intr_dp_is_en(intr_handle))
1429 txgbe_dev_rxq_interrupt_setup(dev);
1431 /* enable uio/vfio intr/eventfd mapping */
1432 rte_intr_enable(intr_handle);
1434 /* resume enabled intr since hw reset */
1435 txgbe_enable_intr(dev);
1438 * Update link status right before return, because it may
1439 * start link configuration process in a separate thread.
1441 txgbe_dev_link_update(dev, 0);
1443 wr32m(hw, TXGBE_LEDCTL, 0xFFFFFFFF, TXGBE_LEDCTL_ORD_MASK);
1445 txgbe_read_stats_registers(hw, hw_stats);
1446 hw->offset_loaded = 1;
1451 PMD_INIT_LOG(ERR, "failure in dev start: %d", err);
1452 txgbe_dev_clear_queues(dev);
1457 * Stop device: disable rx and tx functions to allow for reconfiguring.
1460 txgbe_dev_stop(struct rte_eth_dev *dev)
1462 struct rte_eth_link link;
1463 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1464 struct txgbe_vf_info *vfinfo = *TXGBE_DEV_VFDATA(dev);
1465 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1466 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1469 if (hw->adapter_stopped)
1472 PMD_INIT_FUNC_TRACE();
1474 rte_eal_alarm_cancel(txgbe_dev_setup_link_alarm_handler, dev);
1476 /* disable interrupts */
1477 txgbe_disable_intr(hw);
1480 txgbe_pf_reset_hw(hw);
1481 hw->adapter_stopped = 0;
1486 for (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)
1487 vfinfo[vf].clear_to_send = false;
1489 if (hw->phy.media_type == txgbe_media_type_copper) {
1490 /* Turn off the copper */
1491 hw->phy.set_phy_power(hw, false);
1493 /* Turn off the laser */
1494 hw->mac.disable_tx_laser(hw);
1497 txgbe_dev_clear_queues(dev);
1499 /* Clear stored conf */
1500 dev->data->scattered_rx = 0;
1503 /* Clear recorded link status */
1504 memset(&link, 0, sizeof(link));
1505 rte_eth_linkstatus_set(dev, &link);
1507 if (!rte_intr_allow_others(intr_handle))
1508 /* resume to the default handler */
1509 rte_intr_callback_register(intr_handle,
1510 txgbe_dev_interrupt_handler,
1513 /* Clean datapath event and queue/vec mapping */
1514 rte_intr_efd_disable(intr_handle);
1515 if (intr_handle->intr_vec != NULL) {
1516 rte_free(intr_handle->intr_vec);
1517 intr_handle->intr_vec = NULL;
1520 wr32m(hw, TXGBE_LEDCTL, 0xFFFFFFFF, TXGBE_LEDCTL_SEL_MASK);
1522 hw->adapter_stopped = true;
1523 dev->data->dev_started = 0;
1529 * Set device link up: enable tx.
1532 txgbe_dev_set_link_up(struct rte_eth_dev *dev)
1534 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1536 if (hw->phy.media_type == txgbe_media_type_copper) {
1537 /* Turn on the copper */
1538 hw->phy.set_phy_power(hw, true);
1540 /* Turn on the laser */
1541 hw->mac.enable_tx_laser(hw);
1542 txgbe_dev_link_update(dev, 0);
1549 * Set device link down: disable tx.
1552 txgbe_dev_set_link_down(struct rte_eth_dev *dev)
1554 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1556 if (hw->phy.media_type == txgbe_media_type_copper) {
1557 /* Turn off the copper */
1558 hw->phy.set_phy_power(hw, false);
1560 /* Turn off the laser */
1561 hw->mac.disable_tx_laser(hw);
1562 txgbe_dev_link_update(dev, 0);
1569 * Reset and stop device.
1572 txgbe_dev_close(struct rte_eth_dev *dev)
1574 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1575 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1576 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1580 PMD_INIT_FUNC_TRACE();
1582 txgbe_pf_reset_hw(hw);
1584 ret = txgbe_dev_stop(dev);
1586 txgbe_dev_free_queues(dev);
1588 /* reprogram the RAR[0] in case user changed it. */
1589 txgbe_set_rar(hw, 0, hw->mac.addr, 0, true);
1591 /* Unlock any pending hardware semaphore */
1592 txgbe_swfw_lock_reset(hw);
1594 /* disable uio intr before callback unregister */
1595 rte_intr_disable(intr_handle);
1598 ret = rte_intr_callback_unregister(intr_handle,
1599 txgbe_dev_interrupt_handler, dev);
1600 if (ret >= 0 || ret == -ENOENT) {
1602 } else if (ret != -EAGAIN) {
1604 "intr callback unregister failed: %d",
1608 } while (retries++ < (10 + TXGBE_LINK_UP_TIME));
1610 /* cancel the delay handler before remove dev */
1611 rte_eal_alarm_cancel(txgbe_dev_interrupt_delayed_handler, dev);
1613 /* uninitialize PF if max_vfs not zero */
1614 txgbe_pf_host_uninit(dev);
1616 rte_free(dev->data->mac_addrs);
1617 dev->data->mac_addrs = NULL;
1619 rte_free(dev->data->hash_mac_addrs);
1620 dev->data->hash_mac_addrs = NULL;
1629 txgbe_dev_reset(struct rte_eth_dev *dev)
1633 /* When a DPDK PMD PF begin to reset PF port, it should notify all
1634 * its VF to make them align with it. The detailed notification
1635 * mechanism is PMD specific. As to txgbe PF, it is rather complex.
1636 * To avoid unexpected behavior in VF, currently reset of PF with
1637 * SR-IOV activation is not supported. It might be supported later.
1639 if (dev->data->sriov.active)
1642 ret = eth_txgbe_dev_uninit(dev);
1646 ret = eth_txgbe_dev_init(dev, NULL);
1651 #define UPDATE_QP_COUNTER_32bit(reg, last_counter, counter) \
1653 uint32_t current_counter = rd32(hw, reg); \
1654 if (current_counter < last_counter) \
1655 current_counter += 0x100000000LL; \
1656 if (!hw->offset_loaded) \
1657 last_counter = current_counter; \
1658 counter = current_counter - last_counter; \
1659 counter &= 0xFFFFFFFFLL; \
1662 #define UPDATE_QP_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
1664 uint64_t current_counter_lsb = rd32(hw, reg_lsb); \
1665 uint64_t current_counter_msb = rd32(hw, reg_msb); \
1666 uint64_t current_counter = (current_counter_msb << 32) | \
1667 current_counter_lsb; \
1668 if (current_counter < last_counter) \
1669 current_counter += 0x1000000000LL; \
1670 if (!hw->offset_loaded) \
1671 last_counter = current_counter; \
1672 counter = current_counter - last_counter; \
1673 counter &= 0xFFFFFFFFFLL; \
1677 txgbe_read_stats_registers(struct txgbe_hw *hw,
1678 struct txgbe_hw_stats *hw_stats)
1683 for (i = 0; i < hw->nb_rx_queues; i++) {
1684 UPDATE_QP_COUNTER_32bit(TXGBE_QPRXPKT(i),
1685 hw->qp_last[i].rx_qp_packets,
1686 hw_stats->qp[i].rx_qp_packets);
1687 UPDATE_QP_COUNTER_36bit(TXGBE_QPRXOCTL(i), TXGBE_QPRXOCTH(i),
1688 hw->qp_last[i].rx_qp_bytes,
1689 hw_stats->qp[i].rx_qp_bytes);
1690 UPDATE_QP_COUNTER_32bit(TXGBE_QPRXMPKT(i),
1691 hw->qp_last[i].rx_qp_mc_packets,
1692 hw_stats->qp[i].rx_qp_mc_packets);
1695 for (i = 0; i < hw->nb_tx_queues; i++) {
1696 UPDATE_QP_COUNTER_32bit(TXGBE_QPTXPKT(i),
1697 hw->qp_last[i].tx_qp_packets,
1698 hw_stats->qp[i].tx_qp_packets);
1699 UPDATE_QP_COUNTER_36bit(TXGBE_QPTXOCTL(i), TXGBE_QPTXOCTH(i),
1700 hw->qp_last[i].tx_qp_bytes,
1701 hw_stats->qp[i].tx_qp_bytes);
1704 for (i = 0; i < TXGBE_MAX_UP; i++) {
1705 hw_stats->up[i].rx_up_xon_packets +=
1706 rd32(hw, TXGBE_PBRXUPXON(i));
1707 hw_stats->up[i].rx_up_xoff_packets +=
1708 rd32(hw, TXGBE_PBRXUPXOFF(i));
1709 hw_stats->up[i].tx_up_xon_packets +=
1710 rd32(hw, TXGBE_PBTXUPXON(i));
1711 hw_stats->up[i].tx_up_xoff_packets +=
1712 rd32(hw, TXGBE_PBTXUPXOFF(i));
1713 hw_stats->up[i].tx_up_xon2off_packets +=
1714 rd32(hw, TXGBE_PBTXUPOFF(i));
1715 hw_stats->up[i].rx_up_dropped +=
1716 rd32(hw, TXGBE_PBRXMISS(i));
1718 hw_stats->rx_xon_packets += rd32(hw, TXGBE_PBRXLNKXON);
1719 hw_stats->rx_xoff_packets += rd32(hw, TXGBE_PBRXLNKXOFF);
1720 hw_stats->tx_xon_packets += rd32(hw, TXGBE_PBTXLNKXON);
1721 hw_stats->tx_xoff_packets += rd32(hw, TXGBE_PBTXLNKXOFF);
1724 hw_stats->rx_packets += rd32(hw, TXGBE_DMARXPKT);
1725 hw_stats->tx_packets += rd32(hw, TXGBE_DMATXPKT);
1727 hw_stats->rx_bytes += rd64(hw, TXGBE_DMARXOCTL);
1728 hw_stats->tx_bytes += rd64(hw, TXGBE_DMATXOCTL);
1729 hw_stats->rx_drop_packets += rd32(hw, TXGBE_PBRXDROP);
1732 hw_stats->rx_crc_errors += rd64(hw, TXGBE_MACRXERRCRCL);
1733 hw_stats->rx_multicast_packets += rd64(hw, TXGBE_MACRXMPKTL);
1734 hw_stats->tx_multicast_packets += rd64(hw, TXGBE_MACTXMPKTL);
1736 hw_stats->rx_total_packets += rd64(hw, TXGBE_MACRXPKTL);
1737 hw_stats->tx_total_packets += rd64(hw, TXGBE_MACTXPKTL);
1738 hw_stats->rx_total_bytes += rd64(hw, TXGBE_MACRXGBOCTL);
1740 hw_stats->rx_broadcast_packets += rd64(hw, TXGBE_MACRXOCTL);
1741 hw_stats->tx_broadcast_packets += rd32(hw, TXGBE_MACTXOCTL);
1743 hw_stats->rx_size_64_packets += rd64(hw, TXGBE_MACRX1TO64L);
1744 hw_stats->rx_size_65_to_127_packets += rd64(hw, TXGBE_MACRX65TO127L);
1745 hw_stats->rx_size_128_to_255_packets += rd64(hw, TXGBE_MACRX128TO255L);
1746 hw_stats->rx_size_256_to_511_packets += rd64(hw, TXGBE_MACRX256TO511L);
1747 hw_stats->rx_size_512_to_1023_packets +=
1748 rd64(hw, TXGBE_MACRX512TO1023L);
1749 hw_stats->rx_size_1024_to_max_packets +=
1750 rd64(hw, TXGBE_MACRX1024TOMAXL);
1751 hw_stats->tx_size_64_packets += rd64(hw, TXGBE_MACTX1TO64L);
1752 hw_stats->tx_size_65_to_127_packets += rd64(hw, TXGBE_MACTX65TO127L);
1753 hw_stats->tx_size_128_to_255_packets += rd64(hw, TXGBE_MACTX128TO255L);
1754 hw_stats->tx_size_256_to_511_packets += rd64(hw, TXGBE_MACTX256TO511L);
1755 hw_stats->tx_size_512_to_1023_packets +=
1756 rd64(hw, TXGBE_MACTX512TO1023L);
1757 hw_stats->tx_size_1024_to_max_packets +=
1758 rd64(hw, TXGBE_MACTX1024TOMAXL);
1760 hw_stats->rx_undersize_errors += rd64(hw, TXGBE_MACRXERRLENL);
1761 hw_stats->rx_oversize_errors += rd32(hw, TXGBE_MACRXOVERSIZE);
1762 hw_stats->rx_jabber_errors += rd32(hw, TXGBE_MACRXJABBER);
1765 hw_stats->mng_bmc2host_packets = rd32(hw, TXGBE_MNGBMC2OS);
1766 hw_stats->mng_host2bmc_packets = rd32(hw, TXGBE_MNGOS2BMC);
1767 hw_stats->rx_management_packets = rd32(hw, TXGBE_DMARXMNG);
1768 hw_stats->tx_management_packets = rd32(hw, TXGBE_DMATXMNG);
1771 hw_stats->rx_fcoe_crc_errors += rd32(hw, TXGBE_FCOECRC);
1772 hw_stats->rx_fcoe_mbuf_allocation_errors += rd32(hw, TXGBE_FCOELAST);
1773 hw_stats->rx_fcoe_dropped += rd32(hw, TXGBE_FCOERPDC);
1774 hw_stats->rx_fcoe_packets += rd32(hw, TXGBE_FCOEPRC);
1775 hw_stats->tx_fcoe_packets += rd32(hw, TXGBE_FCOEPTC);
1776 hw_stats->rx_fcoe_bytes += rd32(hw, TXGBE_FCOEDWRC);
1777 hw_stats->tx_fcoe_bytes += rd32(hw, TXGBE_FCOEDWTC);
1779 /* Flow Director Stats */
1780 hw_stats->flow_director_matched_filters += rd32(hw, TXGBE_FDIRMATCH);
1781 hw_stats->flow_director_missed_filters += rd32(hw, TXGBE_FDIRMISS);
1782 hw_stats->flow_director_added_filters +=
1783 TXGBE_FDIRUSED_ADD(rd32(hw, TXGBE_FDIRUSED));
1784 hw_stats->flow_director_removed_filters +=
1785 TXGBE_FDIRUSED_REM(rd32(hw, TXGBE_FDIRUSED));
1786 hw_stats->flow_director_filter_add_errors +=
1787 TXGBE_FDIRFAIL_ADD(rd32(hw, TXGBE_FDIRFAIL));
1788 hw_stats->flow_director_filter_remove_errors +=
1789 TXGBE_FDIRFAIL_REM(rd32(hw, TXGBE_FDIRFAIL));
1792 hw_stats->tx_macsec_pkts_untagged += rd32(hw, TXGBE_LSECTX_UTPKT);
1793 hw_stats->tx_macsec_pkts_encrypted +=
1794 rd32(hw, TXGBE_LSECTX_ENCPKT);
1795 hw_stats->tx_macsec_pkts_protected +=
1796 rd32(hw, TXGBE_LSECTX_PROTPKT);
1797 hw_stats->tx_macsec_octets_encrypted +=
1798 rd32(hw, TXGBE_LSECTX_ENCOCT);
1799 hw_stats->tx_macsec_octets_protected +=
1800 rd32(hw, TXGBE_LSECTX_PROTOCT);
1801 hw_stats->rx_macsec_pkts_untagged += rd32(hw, TXGBE_LSECRX_UTPKT);
1802 hw_stats->rx_macsec_pkts_badtag += rd32(hw, TXGBE_LSECRX_BTPKT);
1803 hw_stats->rx_macsec_pkts_nosci += rd32(hw, TXGBE_LSECRX_NOSCIPKT);
1804 hw_stats->rx_macsec_pkts_unknownsci += rd32(hw, TXGBE_LSECRX_UNSCIPKT);
1805 hw_stats->rx_macsec_octets_decrypted += rd32(hw, TXGBE_LSECRX_DECOCT);
1806 hw_stats->rx_macsec_octets_validated += rd32(hw, TXGBE_LSECRX_VLDOCT);
1807 hw_stats->rx_macsec_sc_pkts_unchecked +=
1808 rd32(hw, TXGBE_LSECRX_UNCHKPKT);
1809 hw_stats->rx_macsec_sc_pkts_delayed += rd32(hw, TXGBE_LSECRX_DLYPKT);
1810 hw_stats->rx_macsec_sc_pkts_late += rd32(hw, TXGBE_LSECRX_LATEPKT);
1811 for (i = 0; i < 2; i++) {
1812 hw_stats->rx_macsec_sa_pkts_ok +=
1813 rd32(hw, TXGBE_LSECRX_OKPKT(i));
1814 hw_stats->rx_macsec_sa_pkts_invalid +=
1815 rd32(hw, TXGBE_LSECRX_INVPKT(i));
1816 hw_stats->rx_macsec_sa_pkts_notvalid +=
1817 rd32(hw, TXGBE_LSECRX_BADPKT(i));
1819 hw_stats->rx_macsec_sa_pkts_unusedsa +=
1820 rd32(hw, TXGBE_LSECRX_INVSAPKT);
1821 hw_stats->rx_macsec_sa_pkts_notusingsa +=
1822 rd32(hw, TXGBE_LSECRX_BADSAPKT);
1824 hw_stats->rx_total_missed_packets = 0;
1825 for (i = 0; i < TXGBE_MAX_UP; i++) {
1826 hw_stats->rx_total_missed_packets +=
1827 hw_stats->up[i].rx_up_dropped;
1832 txgbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1834 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1835 struct txgbe_hw_stats *hw_stats = TXGBE_DEV_STATS(dev);
1836 struct txgbe_stat_mappings *stat_mappings =
1837 TXGBE_DEV_STAT_MAPPINGS(dev);
1840 txgbe_read_stats_registers(hw, hw_stats);
1845 /* Fill out the rte_eth_stats statistics structure */
1846 stats->ipackets = hw_stats->rx_packets;
1847 stats->ibytes = hw_stats->rx_bytes;
1848 stats->opackets = hw_stats->tx_packets;
1849 stats->obytes = hw_stats->tx_bytes;
1851 memset(&stats->q_ipackets, 0, sizeof(stats->q_ipackets));
1852 memset(&stats->q_opackets, 0, sizeof(stats->q_opackets));
1853 memset(&stats->q_ibytes, 0, sizeof(stats->q_ibytes));
1854 memset(&stats->q_obytes, 0, sizeof(stats->q_obytes));
1855 memset(&stats->q_errors, 0, sizeof(stats->q_errors));
1856 for (i = 0; i < TXGBE_MAX_QP; i++) {
1857 uint32_t n = i / NB_QMAP_FIELDS_PER_QSM_REG;
1858 uint32_t offset = (i % NB_QMAP_FIELDS_PER_QSM_REG) * 8;
1861 q_map = (stat_mappings->rqsm[n] >> offset)
1862 & QMAP_FIELD_RESERVED_BITS_MASK;
1863 j = (q_map < RTE_ETHDEV_QUEUE_STAT_CNTRS
1864 ? q_map : q_map % RTE_ETHDEV_QUEUE_STAT_CNTRS);
1865 stats->q_ipackets[j] += hw_stats->qp[i].rx_qp_packets;
1866 stats->q_ibytes[j] += hw_stats->qp[i].rx_qp_bytes;
1868 q_map = (stat_mappings->tqsm[n] >> offset)
1869 & QMAP_FIELD_RESERVED_BITS_MASK;
1870 j = (q_map < RTE_ETHDEV_QUEUE_STAT_CNTRS
1871 ? q_map : q_map % RTE_ETHDEV_QUEUE_STAT_CNTRS);
1872 stats->q_opackets[j] += hw_stats->qp[i].tx_qp_packets;
1873 stats->q_obytes[j] += hw_stats->qp[i].tx_qp_bytes;
1877 stats->imissed = hw_stats->rx_total_missed_packets;
1878 stats->ierrors = hw_stats->rx_crc_errors +
1879 hw_stats->rx_mac_short_packet_dropped +
1880 hw_stats->rx_length_errors +
1881 hw_stats->rx_undersize_errors +
1882 hw_stats->rx_oversize_errors +
1883 hw_stats->rx_drop_packets +
1884 hw_stats->rx_illegal_byte_errors +
1885 hw_stats->rx_error_bytes +
1886 hw_stats->rx_fragment_errors +
1887 hw_stats->rx_fcoe_crc_errors +
1888 hw_stats->rx_fcoe_mbuf_allocation_errors;
1896 txgbe_dev_stats_reset(struct rte_eth_dev *dev)
1898 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
1899 struct txgbe_hw_stats *hw_stats = TXGBE_DEV_STATS(dev);
1901 /* HW registers are cleared on read */
1902 hw->offset_loaded = 0;
1903 txgbe_dev_stats_get(dev, NULL);
1904 hw->offset_loaded = 1;
1906 /* Reset software totals */
1907 memset(hw_stats, 0, sizeof(*hw_stats));
1912 /* This function calculates the number of xstats based on the current config */
1914 txgbe_xstats_calc_num(struct rte_eth_dev *dev)
1916 int nb_queues = max(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
1917 return TXGBE_NB_HW_STATS +
1918 TXGBE_NB_UP_STATS * TXGBE_MAX_UP +
1919 TXGBE_NB_QP_STATS * nb_queues;
1923 txgbe_get_name_by_id(uint32_t id, char *name, uint32_t size)
1927 /* Extended stats from txgbe_hw_stats */
1928 if (id < TXGBE_NB_HW_STATS) {
1929 snprintf(name, size, "[hw]%s",
1930 rte_txgbe_stats_strings[id].name);
1933 id -= TXGBE_NB_HW_STATS;
1935 /* Priority Stats */
1936 if (id < TXGBE_NB_UP_STATS * TXGBE_MAX_UP) {
1937 nb = id / TXGBE_NB_UP_STATS;
1938 st = id % TXGBE_NB_UP_STATS;
1939 snprintf(name, size, "[p%u]%s", nb,
1940 rte_txgbe_up_strings[st].name);
1943 id -= TXGBE_NB_UP_STATS * TXGBE_MAX_UP;
1946 if (id < TXGBE_NB_QP_STATS * TXGBE_MAX_QP) {
1947 nb = id / TXGBE_NB_QP_STATS;
1948 st = id % TXGBE_NB_QP_STATS;
1949 snprintf(name, size, "[q%u]%s", nb,
1950 rte_txgbe_qp_strings[st].name);
1953 id -= TXGBE_NB_QP_STATS * TXGBE_MAX_QP;
1955 return -(int)(id + 1);
1959 txgbe_get_offset_by_id(uint32_t id, uint32_t *offset)
1963 /* Extended stats from txgbe_hw_stats */
1964 if (id < TXGBE_NB_HW_STATS) {
1965 *offset = rte_txgbe_stats_strings[id].offset;
1968 id -= TXGBE_NB_HW_STATS;
1970 /* Priority Stats */
1971 if (id < TXGBE_NB_UP_STATS * TXGBE_MAX_UP) {
1972 nb = id / TXGBE_NB_UP_STATS;
1973 st = id % TXGBE_NB_UP_STATS;
1974 *offset = rte_txgbe_up_strings[st].offset +
1975 nb * (TXGBE_NB_UP_STATS * sizeof(uint64_t));
1978 id -= TXGBE_NB_UP_STATS * TXGBE_MAX_UP;
1981 if (id < TXGBE_NB_QP_STATS * TXGBE_MAX_QP) {
1982 nb = id / TXGBE_NB_QP_STATS;
1983 st = id % TXGBE_NB_QP_STATS;
1984 *offset = rte_txgbe_qp_strings[st].offset +
1985 nb * (TXGBE_NB_QP_STATS * sizeof(uint64_t));
1988 id -= TXGBE_NB_QP_STATS * TXGBE_MAX_QP;
1990 return -(int)(id + 1);
1993 static int txgbe_dev_xstats_get_names(struct rte_eth_dev *dev,
1994 struct rte_eth_xstat_name *xstats_names, unsigned int limit)
1996 unsigned int i, count;
1998 count = txgbe_xstats_calc_num(dev);
1999 if (xstats_names == NULL)
2002 /* Note: limit >= cnt_stats checked upstream
2003 * in rte_eth_xstats_names()
2005 limit = min(limit, count);
2007 /* Extended stats from txgbe_hw_stats */
2008 for (i = 0; i < limit; i++) {
2009 if (txgbe_get_name_by_id(i, xstats_names[i].name,
2010 sizeof(xstats_names[i].name))) {
2011 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
2019 static int txgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
2020 struct rte_eth_xstat_name *xstats_names,
2021 const uint64_t *ids,
2027 return txgbe_dev_xstats_get_names(dev, xstats_names, limit);
2029 for (i = 0; i < limit; i++) {
2030 if (txgbe_get_name_by_id(ids[i], xstats_names[i].name,
2031 sizeof(xstats_names[i].name))) {
2032 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
2041 txgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2044 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2045 struct txgbe_hw_stats *hw_stats = TXGBE_DEV_STATS(dev);
2046 unsigned int i, count;
2048 txgbe_read_stats_registers(hw, hw_stats);
2050 /* If this is a reset xstats is NULL, and we have cleared the
2051 * registers by reading them.
2053 count = txgbe_xstats_calc_num(dev);
2057 limit = min(limit, txgbe_xstats_calc_num(dev));
2059 /* Extended stats from txgbe_hw_stats */
2060 for (i = 0; i < limit; i++) {
2061 uint32_t offset = 0;
2063 if (txgbe_get_offset_by_id(i, &offset)) {
2064 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
2067 xstats[i].value = *(uint64_t *)(((char *)hw_stats) + offset);
2075 txgbe_dev_xstats_get_(struct rte_eth_dev *dev, uint64_t *values,
2078 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2079 struct txgbe_hw_stats *hw_stats = TXGBE_DEV_STATS(dev);
2080 unsigned int i, count;
2082 txgbe_read_stats_registers(hw, hw_stats);
2084 /* If this is a reset xstats is NULL, and we have cleared the
2085 * registers by reading them.
2087 count = txgbe_xstats_calc_num(dev);
2091 limit = min(limit, txgbe_xstats_calc_num(dev));
2093 /* Extended stats from txgbe_hw_stats */
2094 for (i = 0; i < limit; i++) {
2097 if (txgbe_get_offset_by_id(i, &offset)) {
2098 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
2101 values[i] = *(uint64_t *)(((char *)hw_stats) + offset);
2108 txgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
2109 uint64_t *values, unsigned int limit)
2111 struct txgbe_hw_stats *hw_stats = TXGBE_DEV_STATS(dev);
2115 return txgbe_dev_xstats_get_(dev, values, limit);
2117 for (i = 0; i < limit; i++) {
2120 if (txgbe_get_offset_by_id(ids[i], &offset)) {
2121 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
2124 values[i] = *(uint64_t *)(((char *)hw_stats) + offset);
2131 txgbe_dev_xstats_reset(struct rte_eth_dev *dev)
2133 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2134 struct txgbe_hw_stats *hw_stats = TXGBE_DEV_STATS(dev);
2136 /* HW registers are cleared on read */
2137 hw->offset_loaded = 0;
2138 txgbe_read_stats_registers(hw, hw_stats);
2139 hw->offset_loaded = 1;
2141 /* Reset software totals */
2142 memset(hw_stats, 0, sizeof(*hw_stats));
2148 txgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2150 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2151 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2153 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
2154 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
2155 dev_info->min_rx_bufsize = 1024;
2156 dev_info->max_rx_pktlen = 15872;
2157 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
2158 dev_info->max_hash_mac_addrs = TXGBE_VMDQ_NUM_UC_MAC;
2159 dev_info->max_vfs = pci_dev->max_vfs;
2160 dev_info->max_vmdq_pools = ETH_64_POOLS;
2161 dev_info->vmdq_queue_num = dev_info->max_rx_queues;
2162 dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
2163 dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
2164 dev_info->rx_queue_offload_capa);
2165 dev_info->tx_queue_offload_capa = txgbe_get_tx_queue_offloads(dev);
2166 dev_info->tx_offload_capa = txgbe_get_tx_port_offloads(dev);
2168 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2170 .pthresh = TXGBE_DEFAULT_RX_PTHRESH,
2171 .hthresh = TXGBE_DEFAULT_RX_HTHRESH,
2172 .wthresh = TXGBE_DEFAULT_RX_WTHRESH,
2174 .rx_free_thresh = TXGBE_DEFAULT_RX_FREE_THRESH,
2179 dev_info->default_txconf = (struct rte_eth_txconf) {
2181 .pthresh = TXGBE_DEFAULT_TX_PTHRESH,
2182 .hthresh = TXGBE_DEFAULT_TX_HTHRESH,
2183 .wthresh = TXGBE_DEFAULT_TX_WTHRESH,
2185 .tx_free_thresh = TXGBE_DEFAULT_TX_FREE_THRESH,
2189 dev_info->rx_desc_lim = rx_desc_lim;
2190 dev_info->tx_desc_lim = tx_desc_lim;
2192 dev_info->hash_key_size = TXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
2193 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
2194 dev_info->flow_type_rss_offloads = TXGBE_RSS_OFFLOAD_ALL;
2196 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
2197 dev_info->speed_capa |= ETH_LINK_SPEED_100M;
2199 /* Driver-preferred Rx/Tx parameters */
2200 dev_info->default_rxportconf.burst_size = 32;
2201 dev_info->default_txportconf.burst_size = 32;
2202 dev_info->default_rxportconf.nb_queues = 1;
2203 dev_info->default_txportconf.nb_queues = 1;
2204 dev_info->default_rxportconf.ring_size = 256;
2205 dev_info->default_txportconf.ring_size = 256;
2211 txgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev)
2213 if (dev->rx_pkt_burst == txgbe_recv_pkts ||
2214 dev->rx_pkt_burst == txgbe_recv_pkts_lro_single_alloc ||
2215 dev->rx_pkt_burst == txgbe_recv_pkts_lro_bulk_alloc ||
2216 dev->rx_pkt_burst == txgbe_recv_pkts_bulk_alloc)
2217 return txgbe_get_supported_ptypes();
2223 txgbe_dev_setup_link_alarm_handler(void *param)
2225 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2226 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2227 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
2229 bool autoneg = false;
2231 speed = hw->phy.autoneg_advertised;
2233 hw->mac.get_link_capabilities(hw, &speed, &autoneg);
2235 hw->mac.setup_link(hw, speed, true);
2237 intr->flags &= ~TXGBE_FLAG_NEED_LINK_CONFIG;
2240 /* return 0 means link status changed, -1 means not changed */
2242 txgbe_dev_link_update_share(struct rte_eth_dev *dev,
2243 int wait_to_complete)
2245 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2246 struct rte_eth_link link;
2247 u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
2248 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
2253 memset(&link, 0, sizeof(link));
2254 link.link_status = ETH_LINK_DOWN;
2255 link.link_speed = ETH_SPEED_NUM_NONE;
2256 link.link_duplex = ETH_LINK_HALF_DUPLEX;
2257 link.link_autoneg = ETH_LINK_AUTONEG;
2259 hw->mac.get_link_status = true;
2261 if (intr->flags & TXGBE_FLAG_NEED_LINK_CONFIG)
2262 return rte_eth_linkstatus_set(dev, &link);
2264 /* check if it needs to wait to complete, if lsc interrupt is enabled */
2265 if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
2268 err = hw->mac.check_link(hw, &link_speed, &link_up, wait);
2271 link.link_speed = ETH_SPEED_NUM_100M;
2272 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2273 return rte_eth_linkstatus_set(dev, &link);
2277 if (hw->phy.media_type == txgbe_media_type_fiber) {
2278 intr->flags |= TXGBE_FLAG_NEED_LINK_CONFIG;
2279 rte_eal_alarm_set(10,
2280 txgbe_dev_setup_link_alarm_handler, dev);
2282 return rte_eth_linkstatus_set(dev, &link);
2285 intr->flags &= ~TXGBE_FLAG_NEED_LINK_CONFIG;
2286 link.link_status = ETH_LINK_UP;
2287 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2289 switch (link_speed) {
2291 case TXGBE_LINK_SPEED_UNKNOWN:
2292 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2293 link.link_speed = ETH_SPEED_NUM_100M;
2296 case TXGBE_LINK_SPEED_100M_FULL:
2297 link.link_speed = ETH_SPEED_NUM_100M;
2300 case TXGBE_LINK_SPEED_1GB_FULL:
2301 link.link_speed = ETH_SPEED_NUM_1G;
2304 case TXGBE_LINK_SPEED_2_5GB_FULL:
2305 link.link_speed = ETH_SPEED_NUM_2_5G;
2308 case TXGBE_LINK_SPEED_5GB_FULL:
2309 link.link_speed = ETH_SPEED_NUM_5G;
2312 case TXGBE_LINK_SPEED_10GB_FULL:
2313 link.link_speed = ETH_SPEED_NUM_10G;
2317 return rte_eth_linkstatus_set(dev, &link);
2321 txgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
2323 return txgbe_dev_link_update_share(dev, wait_to_complete);
2327 * It clears the interrupt causes and enables the interrupt.
2328 * It will be called once only during nic initialized.
2331 * Pointer to struct rte_eth_dev.
2333 * Enable or Disable.
2336 * - On success, zero.
2337 * - On failure, a negative value.
2340 txgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
2342 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
2344 txgbe_dev_link_status_print(dev);
2346 intr->mask_misc |= TXGBE_ICRMISC_LSC;
2348 intr->mask_misc &= ~TXGBE_ICRMISC_LSC;
2354 * It clears the interrupt causes and enables the interrupt.
2355 * It will be called once only during nic initialized.
2358 * Pointer to struct rte_eth_dev.
2361 * - On success, zero.
2362 * - On failure, a negative value.
2365 txgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
2367 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
2369 intr->mask[0] |= TXGBE_ICR_MASK;
2370 intr->mask[1] |= TXGBE_ICR_MASK;
2376 * It clears the interrupt causes and enables the interrupt.
2377 * It will be called once only during nic initialized.
2380 * Pointer to struct rte_eth_dev.
2383 * - On success, zero.
2384 * - On failure, a negative value.
2387 txgbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev)
2389 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
2391 intr->mask_misc |= TXGBE_ICRMISC_LNKSEC;
2397 * It reads ICR and sets flag (TXGBE_ICRMISC_LSC) for the link_update.
2400 * Pointer to struct rte_eth_dev.
2403 * - On success, zero.
2404 * - On failure, a negative value.
2407 txgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
2410 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2411 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
2413 /* clear all cause mask */
2414 txgbe_disable_intr(hw);
2416 /* read-on-clear nic registers here */
2417 eicr = ((u32 *)hw->isb_mem)[TXGBE_ISB_MISC];
2418 PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
2422 /* set flag for async link update */
2423 if (eicr & TXGBE_ICRMISC_LSC)
2424 intr->flags |= TXGBE_FLAG_NEED_LINK_UPDATE;
2426 if (eicr & TXGBE_ICRMISC_VFMBX)
2427 intr->flags |= TXGBE_FLAG_MAILBOX;
2429 if (eicr & TXGBE_ICRMISC_LNKSEC)
2430 intr->flags |= TXGBE_FLAG_MACSEC;
2432 if (eicr & TXGBE_ICRMISC_GPIO)
2433 intr->flags |= TXGBE_FLAG_PHY_INTERRUPT;
2439 * It gets and then prints the link status.
2442 * Pointer to struct rte_eth_dev.
2445 * - On success, zero.
2446 * - On failure, a negative value.
2449 txgbe_dev_link_status_print(struct rte_eth_dev *dev)
2451 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2452 struct rte_eth_link link;
2454 rte_eth_linkstatus_get(dev, &link);
2456 if (link.link_status) {
2457 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
2458 (int)(dev->data->port_id),
2459 (unsigned int)link.link_speed,
2460 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
2461 "full-duplex" : "half-duplex");
2463 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2464 (int)(dev->data->port_id));
2466 PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
2467 pci_dev->addr.domain,
2469 pci_dev->addr.devid,
2470 pci_dev->addr.function);
2474 * It executes link_update after knowing an interrupt occurred.
2477 * Pointer to struct rte_eth_dev.
2480 * - On success, zero.
2481 * - On failure, a negative value.
2484 txgbe_dev_interrupt_action(struct rte_eth_dev *dev,
2485 struct rte_intr_handle *intr_handle)
2487 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
2489 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2491 PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
2493 if (intr->flags & TXGBE_FLAG_MAILBOX) {
2494 txgbe_pf_mbx_process(dev);
2495 intr->flags &= ~TXGBE_FLAG_MAILBOX;
2498 if (intr->flags & TXGBE_FLAG_PHY_INTERRUPT) {
2499 hw->phy.handle_lasi(hw);
2500 intr->flags &= ~TXGBE_FLAG_PHY_INTERRUPT;
2503 if (intr->flags & TXGBE_FLAG_NEED_LINK_UPDATE) {
2504 struct rte_eth_link link;
2506 /*get the link status before link update, for predicting later*/
2507 rte_eth_linkstatus_get(dev, &link);
2509 txgbe_dev_link_update(dev, 0);
2512 if (!link.link_status)
2513 /* handle it 1 sec later, wait it being stable */
2514 timeout = TXGBE_LINK_UP_CHECK_TIMEOUT;
2515 /* likely to down */
2517 /* handle it 4 sec later, wait it being stable */
2518 timeout = TXGBE_LINK_DOWN_CHECK_TIMEOUT;
2520 txgbe_dev_link_status_print(dev);
2521 if (rte_eal_alarm_set(timeout * 1000,
2522 txgbe_dev_interrupt_delayed_handler,
2524 PMD_DRV_LOG(ERR, "Error setting alarm");
2526 /* remember original mask */
2527 intr->mask_misc_orig = intr->mask_misc;
2528 /* only disable lsc interrupt */
2529 intr->mask_misc &= ~TXGBE_ICRMISC_LSC;
2533 PMD_DRV_LOG(DEBUG, "enable intr immediately");
2534 txgbe_enable_intr(dev);
2535 rte_intr_enable(intr_handle);
2541 * Interrupt handler which shall be registered for alarm callback for delayed
2542 * handling specific interrupt to wait for the stable nic state. As the
2543 * NIC interrupt state is not stable for txgbe after link is just down,
2544 * it needs to wait 4 seconds to get the stable status.
2547 * Pointer to interrupt handle.
2549 * The address of parameter (struct rte_eth_dev *) registered before.
2555 txgbe_dev_interrupt_delayed_handler(void *param)
2557 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2558 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2559 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2560 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
2561 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2564 txgbe_disable_intr(hw);
2566 eicr = ((u32 *)hw->isb_mem)[TXGBE_ISB_MISC];
2567 if (eicr & TXGBE_ICRMISC_VFMBX)
2568 txgbe_pf_mbx_process(dev);
2570 if (intr->flags & TXGBE_FLAG_PHY_INTERRUPT) {
2571 hw->phy.handle_lasi(hw);
2572 intr->flags &= ~TXGBE_FLAG_PHY_INTERRUPT;
2575 if (intr->flags & TXGBE_FLAG_NEED_LINK_UPDATE) {
2576 txgbe_dev_link_update(dev, 0);
2577 intr->flags &= ~TXGBE_FLAG_NEED_LINK_UPDATE;
2578 txgbe_dev_link_status_print(dev);
2579 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
2583 if (intr->flags & TXGBE_FLAG_MACSEC) {
2584 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_MACSEC,
2586 intr->flags &= ~TXGBE_FLAG_MACSEC;
2589 /* restore original mask */
2590 intr->mask_misc = intr->mask_misc_orig;
2591 intr->mask_misc_orig = 0;
2593 PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
2594 txgbe_enable_intr(dev);
2595 rte_intr_enable(intr_handle);
2599 * Interrupt handler triggered by NIC for handling
2600 * specific interrupt.
2603 * Pointer to interrupt handle.
2605 * The address of parameter (struct rte_eth_dev *) registered before.
2611 txgbe_dev_interrupt_handler(void *param)
2613 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2615 txgbe_dev_interrupt_get_status(dev);
2616 txgbe_dev_interrupt_action(dev, dev->intr_handle);
2620 txgbe_add_rar(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
2621 uint32_t index, uint32_t pool)
2623 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2624 uint32_t enable_addr = 1;
2626 return txgbe_set_rar(hw, index, mac_addr->addr_bytes,
2631 txgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
2633 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2635 txgbe_clear_rar(hw, index);
2639 txgbe_set_default_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
2641 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2643 txgbe_remove_rar(dev, 0);
2644 txgbe_add_rar(dev, addr, 0, pci_dev->max_vfs);
2650 txgbe_uta_vector(struct txgbe_hw *hw, struct rte_ether_addr *uc_addr)
2652 uint32_t vector = 0;
2654 switch (hw->mac.mc_filter_type) {
2655 case 0: /* use bits [47:36] of the address */
2656 vector = ((uc_addr->addr_bytes[4] >> 4) |
2657 (((uint16_t)uc_addr->addr_bytes[5]) << 4));
2659 case 1: /* use bits [46:35] of the address */
2660 vector = ((uc_addr->addr_bytes[4] >> 3) |
2661 (((uint16_t)uc_addr->addr_bytes[5]) << 5));
2663 case 2: /* use bits [45:34] of the address */
2664 vector = ((uc_addr->addr_bytes[4] >> 2) |
2665 (((uint16_t)uc_addr->addr_bytes[5]) << 6));
2667 case 3: /* use bits [43:32] of the address */
2668 vector = ((uc_addr->addr_bytes[4]) |
2669 (((uint16_t)uc_addr->addr_bytes[5]) << 8));
2671 default: /* Invalid mc_filter_type */
2675 /* vector can only be 12-bits or boundary will be exceeded */
2681 txgbe_uc_hash_table_set(struct rte_eth_dev *dev,
2682 struct rte_ether_addr *mac_addr, uint8_t on)
2690 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2691 struct txgbe_uta_info *uta_info = TXGBE_DEV_UTA_INFO(dev);
2693 /* The UTA table only exists on pf hardware */
2694 if (hw->mac.type < txgbe_mac_raptor)
2697 vector = txgbe_uta_vector(hw, mac_addr);
2698 uta_idx = (vector >> 5) & 0x7F;
2699 uta_mask = 0x1UL << (vector & 0x1F);
2701 if (!!on == !!(uta_info->uta_shadow[uta_idx] & uta_mask))
2704 reg_val = rd32(hw, TXGBE_UCADDRTBL(uta_idx));
2706 uta_info->uta_in_use++;
2707 reg_val |= uta_mask;
2708 uta_info->uta_shadow[uta_idx] |= uta_mask;
2710 uta_info->uta_in_use--;
2711 reg_val &= ~uta_mask;
2712 uta_info->uta_shadow[uta_idx] &= ~uta_mask;
2715 wr32(hw, TXGBE_UCADDRTBL(uta_idx), reg_val);
2717 psrctl = rd32(hw, TXGBE_PSRCTL);
2718 if (uta_info->uta_in_use > 0)
2719 psrctl |= TXGBE_PSRCTL_UCHFENA;
2721 psrctl &= ~TXGBE_PSRCTL_UCHFENA;
2723 psrctl &= ~TXGBE_PSRCTL_ADHF12_MASK;
2724 psrctl |= TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
2725 wr32(hw, TXGBE_PSRCTL, psrctl);
2731 txgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
2733 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2734 struct txgbe_uta_info *uta_info = TXGBE_DEV_UTA_INFO(dev);
2738 /* The UTA table only exists on pf hardware */
2739 if (hw->mac.type < txgbe_mac_raptor)
2743 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
2744 uta_info->uta_shadow[i] = ~0;
2745 wr32(hw, TXGBE_UCADDRTBL(i), ~0);
2748 for (i = 0; i < ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
2749 uta_info->uta_shadow[i] = 0;
2750 wr32(hw, TXGBE_UCADDRTBL(i), 0);
2754 psrctl = rd32(hw, TXGBE_PSRCTL);
2756 psrctl |= TXGBE_PSRCTL_UCHFENA;
2758 psrctl &= ~TXGBE_PSRCTL_UCHFENA;
2760 psrctl &= ~TXGBE_PSRCTL_ADHF12_MASK;
2761 psrctl |= TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
2762 wr32(hw, TXGBE_PSRCTL, psrctl);
2768 txgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
2770 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2771 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2773 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2775 if (queue_id < 32) {
2776 mask = rd32(hw, TXGBE_IMS(0));
2777 mask &= (1 << queue_id);
2778 wr32(hw, TXGBE_IMS(0), mask);
2779 } else if (queue_id < 64) {
2780 mask = rd32(hw, TXGBE_IMS(1));
2781 mask &= (1 << (queue_id - 32));
2782 wr32(hw, TXGBE_IMS(1), mask);
2784 rte_intr_enable(intr_handle);
2790 txgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
2793 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2795 if (queue_id < 32) {
2796 mask = rd32(hw, TXGBE_IMS(0));
2797 mask &= ~(1 << queue_id);
2798 wr32(hw, TXGBE_IMS(0), mask);
2799 } else if (queue_id < 64) {
2800 mask = rd32(hw, TXGBE_IMS(1));
2801 mask &= ~(1 << (queue_id - 32));
2802 wr32(hw, TXGBE_IMS(1), mask);
2809 * set the IVAR registers, mapping interrupt causes to vectors
2811 * pointer to txgbe_hw struct
2813 * 0 for Rx, 1 for Tx, -1 for other causes
2815 * queue to map the corresponding interrupt to
2817 * the vector to map to the corresponding queue
2820 txgbe_set_ivar_map(struct txgbe_hw *hw, int8_t direction,
2821 uint8_t queue, uint8_t msix_vector)
2825 if (direction == -1) {
2827 msix_vector |= TXGBE_IVARMISC_VLD;
2829 tmp = rd32(hw, TXGBE_IVARMISC);
2830 tmp &= ~(0xFF << idx);
2831 tmp |= (msix_vector << idx);
2832 wr32(hw, TXGBE_IVARMISC, tmp);
2834 /* rx or tx causes */
2835 /* Workround for ICR lost */
2836 idx = ((16 * (queue & 1)) + (8 * direction));
2837 tmp = rd32(hw, TXGBE_IVAR(queue >> 1));
2838 tmp &= ~(0xFF << idx);
2839 tmp |= (msix_vector << idx);
2840 wr32(hw, TXGBE_IVAR(queue >> 1), tmp);
2845 * Sets up the hardware to properly generate MSI-X interrupts
2847 * board private structure
2850 txgbe_configure_msix(struct rte_eth_dev *dev)
2852 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2853 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2854 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2855 uint32_t queue_id, base = TXGBE_MISC_VEC_ID;
2856 uint32_t vec = TXGBE_MISC_VEC_ID;
2859 /* won't configure msix register if no mapping is done
2860 * between intr vector and event fd
2861 * but if misx has been enabled already, need to configure
2862 * auto clean, auto mask and throttling.
2864 gpie = rd32(hw, TXGBE_GPIE);
2865 if (!rte_intr_dp_is_en(intr_handle) &&
2866 !(gpie & TXGBE_GPIE_MSIX))
2869 if (rte_intr_allow_others(intr_handle)) {
2870 base = TXGBE_RX_VEC_START;
2874 /* setup GPIE for MSI-x mode */
2875 gpie = rd32(hw, TXGBE_GPIE);
2876 gpie |= TXGBE_GPIE_MSIX;
2877 wr32(hw, TXGBE_GPIE, gpie);
2879 /* Populate the IVAR table and set the ITR values to the
2880 * corresponding register.
2882 if (rte_intr_dp_is_en(intr_handle)) {
2883 for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
2885 /* by default, 1:1 mapping */
2886 txgbe_set_ivar_map(hw, 0, queue_id, vec);
2887 intr_handle->intr_vec[queue_id] = vec;
2888 if (vec < base + intr_handle->nb_efd - 1)
2892 txgbe_set_ivar_map(hw, -1, 1, TXGBE_MISC_VEC_ID);
2894 wr32(hw, TXGBE_ITR(TXGBE_MISC_VEC_ID),
2895 TXGBE_ITR_IVAL_10G(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
2900 txgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
2901 uint16_t queue_idx, uint16_t tx_rate)
2903 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2906 if (queue_idx >= hw->mac.max_tx_queues)
2910 bcnrc_val = TXGBE_ARBTXRATE_MAX(tx_rate);
2911 bcnrc_val |= TXGBE_ARBTXRATE_MIN(tx_rate / 2);
2917 * Set global transmit compensation time to the MMW_SIZE in ARBTXMMW
2918 * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported.
2920 wr32(hw, TXGBE_ARBTXMMW, 0x14);
2922 /* Set ARBTXRATE of queue X */
2923 wr32(hw, TXGBE_ARBPOOLIDX, queue_idx);
2924 wr32(hw, TXGBE_ARBTXRATE, bcnrc_val);
2931 txgbe_dev_addr_list_itr(__rte_unused struct txgbe_hw *hw,
2932 u8 **mc_addr_ptr, u32 *vmdq)
2937 mc_addr = *mc_addr_ptr;
2938 *mc_addr_ptr = (mc_addr + sizeof(struct rte_ether_addr));
2943 txgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
2944 struct rte_ether_addr *mc_addr_set,
2945 uint32_t nb_mc_addr)
2947 struct txgbe_hw *hw;
2950 hw = TXGBE_DEV_HW(dev);
2951 mc_addr_list = (u8 *)mc_addr_set;
2952 return txgbe_update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
2953 txgbe_dev_addr_list_itr, TRUE);
2956 static const struct eth_dev_ops txgbe_eth_dev_ops = {
2957 .dev_configure = txgbe_dev_configure,
2958 .dev_infos_get = txgbe_dev_info_get,
2959 .dev_start = txgbe_dev_start,
2960 .dev_stop = txgbe_dev_stop,
2961 .dev_set_link_up = txgbe_dev_set_link_up,
2962 .dev_set_link_down = txgbe_dev_set_link_down,
2963 .dev_close = txgbe_dev_close,
2964 .dev_reset = txgbe_dev_reset,
2965 .link_update = txgbe_dev_link_update,
2966 .stats_get = txgbe_dev_stats_get,
2967 .xstats_get = txgbe_dev_xstats_get,
2968 .xstats_get_by_id = txgbe_dev_xstats_get_by_id,
2969 .stats_reset = txgbe_dev_stats_reset,
2970 .xstats_reset = txgbe_dev_xstats_reset,
2971 .xstats_get_names = txgbe_dev_xstats_get_names,
2972 .xstats_get_names_by_id = txgbe_dev_xstats_get_names_by_id,
2973 .queue_stats_mapping_set = txgbe_dev_queue_stats_mapping_set,
2974 .dev_supported_ptypes_get = txgbe_dev_supported_ptypes_get,
2975 .vlan_filter_set = txgbe_vlan_filter_set,
2976 .vlan_tpid_set = txgbe_vlan_tpid_set,
2977 .vlan_offload_set = txgbe_vlan_offload_set,
2978 .vlan_strip_queue_set = txgbe_vlan_strip_queue_set,
2979 .rx_queue_start = txgbe_dev_rx_queue_start,
2980 .rx_queue_stop = txgbe_dev_rx_queue_stop,
2981 .tx_queue_start = txgbe_dev_tx_queue_start,
2982 .tx_queue_stop = txgbe_dev_tx_queue_stop,
2983 .rx_queue_setup = txgbe_dev_rx_queue_setup,
2984 .rx_queue_intr_enable = txgbe_dev_rx_queue_intr_enable,
2985 .rx_queue_intr_disable = txgbe_dev_rx_queue_intr_disable,
2986 .rx_queue_release = txgbe_dev_rx_queue_release,
2987 .tx_queue_setup = txgbe_dev_tx_queue_setup,
2988 .tx_queue_release = txgbe_dev_tx_queue_release,
2989 .mac_addr_add = txgbe_add_rar,
2990 .mac_addr_remove = txgbe_remove_rar,
2991 .mac_addr_set = txgbe_set_default_mac_addr,
2992 .uc_hash_table_set = txgbe_uc_hash_table_set,
2993 .uc_all_hash_table_set = txgbe_uc_all_hash_table_set,
2994 .set_queue_rate_limit = txgbe_set_queue_rate_limit,
2995 .set_mc_addr_list = txgbe_dev_set_mc_addr_list,
2996 .rxq_info_get = txgbe_rxq_info_get,
2997 .txq_info_get = txgbe_txq_info_get,
3000 RTE_PMD_REGISTER_PCI(net_txgbe, rte_txgbe_pmd);
3001 RTE_PMD_REGISTER_PCI_TABLE(net_txgbe, pci_id_txgbe_map);
3002 RTE_PMD_REGISTER_KMOD_DEP(net_txgbe, "* igb_uio | uio_pci_generic | vfio-pci");
3004 RTE_LOG_REGISTER(txgbe_logtype_init, pmd.net.txgbe.init, NOTICE);
3005 RTE_LOG_REGISTER(txgbe_logtype_driver, pmd.net.txgbe.driver, NOTICE);
3007 #ifdef RTE_LIBRTE_TXGBE_DEBUG_RX
3008 RTE_LOG_REGISTER(txgbe_logtype_rx, pmd.net.txgbe.rx, DEBUG);
3010 #ifdef RTE_LIBRTE_TXGBE_DEBUG_TX
3011 RTE_LOG_REGISTER(txgbe_logtype_tx, pmd.net.txgbe.tx, DEBUG);
3014 #ifdef RTE_LIBRTE_TXGBE_DEBUG_TX_FREE
3015 RTE_LOG_REGISTER(txgbe_logtype_tx_free, pmd.net.txgbe.tx_free, DEBUG);