1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
7 #include <rte_common.h>
8 #include <ethdev_pci.h>
10 #include <rte_alarm.h>
12 #include "ngbe_logs.h"
14 #include "ngbe_ethdev.h"
15 #include "ngbe_rxtx.h"
16 #include "ngbe_regs_group.h"
18 static const struct reg_info ngbe_regs_general[] = {
19 {NGBE_RST, 1, 1, "NGBE_RST"},
20 {NGBE_STAT, 1, 1, "NGBE_STAT"},
21 {NGBE_PORTCTL, 1, 1, "NGBE_PORTCTL"},
22 {NGBE_GPIODATA, 1, 1, "NGBE_GPIODATA"},
23 {NGBE_GPIOCTL, 1, 1, "NGBE_GPIOCTL"},
24 {NGBE_LEDCTL, 1, 1, "NGBE_LEDCTL"},
28 static const struct reg_info ngbe_regs_nvm[] = {
32 static const struct reg_info ngbe_regs_interrupt[] = {
36 static const struct reg_info ngbe_regs_fctl_others[] = {
40 static const struct reg_info ngbe_regs_rxdma[] = {
44 static const struct reg_info ngbe_regs_rx[] = {
48 static struct reg_info ngbe_regs_tx[] = {
52 static const struct reg_info ngbe_regs_wakeup[] = {
56 static const struct reg_info ngbe_regs_mac[] = {
60 static const struct reg_info ngbe_regs_diagnostic[] = {
65 static const struct reg_info *ngbe_regs_others[] = {
69 ngbe_regs_fctl_others,
78 static int ngbe_dev_close(struct rte_eth_dev *dev);
79 static int ngbe_dev_link_update(struct rte_eth_dev *dev,
80 int wait_to_complete);
81 static int ngbe_dev_stats_reset(struct rte_eth_dev *dev);
82 static void ngbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue);
83 static void ngbe_vlan_hw_strip_disable(struct rte_eth_dev *dev,
86 static void ngbe_dev_link_status_print(struct rte_eth_dev *dev);
87 static int ngbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
88 static int ngbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev);
89 static int ngbe_dev_misc_interrupt_setup(struct rte_eth_dev *dev);
90 static int ngbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
91 static void ngbe_dev_interrupt_handler(void *param);
92 static void ngbe_configure_msix(struct rte_eth_dev *dev);
94 #define NGBE_SET_HWSTRIP(h, q) do {\
95 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
96 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
97 (h)->bitmap[idx] |= 1 << bit;\
100 #define NGBE_CLEAR_HWSTRIP(h, q) do {\
101 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
102 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
103 (h)->bitmap[idx] &= ~(1 << bit);\
106 #define NGBE_GET_HWSTRIP(h, q, r) do {\
107 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
108 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
109 (r) = (h)->bitmap[idx] >> bit & 1;\
113 * The set of PCI devices this driver supports
115 static const struct rte_pci_id pci_id_ngbe_map[] = {
116 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2) },
117 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2S) },
118 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4) },
119 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4S) },
120 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2) },
121 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2S) },
122 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4) },
123 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4S) },
124 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860NCSI) },
125 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1) },
126 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1L) },
127 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL_W) },
128 { .vendor_id = 0, /* sentinel */ },
131 static const struct rte_eth_desc_lim rx_desc_lim = {
132 .nb_max = NGBE_RING_DESC_MAX,
133 .nb_min = NGBE_RING_DESC_MIN,
134 .nb_align = NGBE_RXD_ALIGN,
137 static const struct rte_eth_desc_lim tx_desc_lim = {
138 .nb_max = NGBE_RING_DESC_MAX,
139 .nb_min = NGBE_RING_DESC_MIN,
140 .nb_align = NGBE_TXD_ALIGN,
141 .nb_seg_max = NGBE_TX_MAX_SEG,
142 .nb_mtu_seg_max = NGBE_TX_MAX_SEG,
145 static const struct eth_dev_ops ngbe_eth_dev_ops;
147 #define HW_XSTAT(m) {#m, offsetof(struct ngbe_hw_stats, m)}
148 #define HW_XSTAT_NAME(m, n) {n, offsetof(struct ngbe_hw_stats, m)}
149 static const struct rte_ngbe_xstats_name_off rte_ngbe_stats_strings[] = {
151 HW_XSTAT(mng_bmc2host_packets),
152 HW_XSTAT(mng_host2bmc_packets),
154 HW_XSTAT(rx_packets),
155 HW_XSTAT(tx_packets),
158 HW_XSTAT(rx_total_bytes),
159 HW_XSTAT(rx_total_packets),
160 HW_XSTAT(tx_total_packets),
161 HW_XSTAT(rx_total_missed_packets),
162 HW_XSTAT(rx_broadcast_packets),
163 HW_XSTAT(rx_multicast_packets),
164 HW_XSTAT(rx_management_packets),
165 HW_XSTAT(tx_management_packets),
166 HW_XSTAT(rx_management_dropped),
169 HW_XSTAT(rx_crc_errors),
170 HW_XSTAT(rx_illegal_byte_errors),
171 HW_XSTAT(rx_error_bytes),
172 HW_XSTAT(rx_mac_short_packet_dropped),
173 HW_XSTAT(rx_length_errors),
174 HW_XSTAT(rx_undersize_errors),
175 HW_XSTAT(rx_fragment_errors),
176 HW_XSTAT(rx_oversize_errors),
177 HW_XSTAT(rx_jabber_errors),
178 HW_XSTAT(rx_l3_l4_xsum_error),
179 HW_XSTAT(mac_local_errors),
180 HW_XSTAT(mac_remote_errors),
183 HW_XSTAT(tx_macsec_pkts_untagged),
184 HW_XSTAT(tx_macsec_pkts_encrypted),
185 HW_XSTAT(tx_macsec_pkts_protected),
186 HW_XSTAT(tx_macsec_octets_encrypted),
187 HW_XSTAT(tx_macsec_octets_protected),
188 HW_XSTAT(rx_macsec_pkts_untagged),
189 HW_XSTAT(rx_macsec_pkts_badtag),
190 HW_XSTAT(rx_macsec_pkts_nosci),
191 HW_XSTAT(rx_macsec_pkts_unknownsci),
192 HW_XSTAT(rx_macsec_octets_decrypted),
193 HW_XSTAT(rx_macsec_octets_validated),
194 HW_XSTAT(rx_macsec_sc_pkts_unchecked),
195 HW_XSTAT(rx_macsec_sc_pkts_delayed),
196 HW_XSTAT(rx_macsec_sc_pkts_late),
197 HW_XSTAT(rx_macsec_sa_pkts_ok),
198 HW_XSTAT(rx_macsec_sa_pkts_invalid),
199 HW_XSTAT(rx_macsec_sa_pkts_notvalid),
200 HW_XSTAT(rx_macsec_sa_pkts_unusedsa),
201 HW_XSTAT(rx_macsec_sa_pkts_notusingsa),
204 HW_XSTAT(rx_size_64_packets),
205 HW_XSTAT(rx_size_65_to_127_packets),
206 HW_XSTAT(rx_size_128_to_255_packets),
207 HW_XSTAT(rx_size_256_to_511_packets),
208 HW_XSTAT(rx_size_512_to_1023_packets),
209 HW_XSTAT(rx_size_1024_to_max_packets),
210 HW_XSTAT(tx_size_64_packets),
211 HW_XSTAT(tx_size_65_to_127_packets),
212 HW_XSTAT(tx_size_128_to_255_packets),
213 HW_XSTAT(tx_size_256_to_511_packets),
214 HW_XSTAT(tx_size_512_to_1023_packets),
215 HW_XSTAT(tx_size_1024_to_max_packets),
218 HW_XSTAT(tx_xon_packets),
219 HW_XSTAT(rx_xon_packets),
220 HW_XSTAT(tx_xoff_packets),
221 HW_XSTAT(rx_xoff_packets),
223 HW_XSTAT_NAME(tx_xon_packets, "tx_flow_control_xon_packets"),
224 HW_XSTAT_NAME(rx_xon_packets, "rx_flow_control_xon_packets"),
225 HW_XSTAT_NAME(tx_xoff_packets, "tx_flow_control_xoff_packets"),
226 HW_XSTAT_NAME(rx_xoff_packets, "rx_flow_control_xoff_packets"),
229 #define NGBE_NB_HW_STATS (sizeof(rte_ngbe_stats_strings) / \
230 sizeof(rte_ngbe_stats_strings[0]))
232 /* Per-queue statistics */
233 #define QP_XSTAT(m) {#m, offsetof(struct ngbe_hw_stats, qp[0].m)}
234 static const struct rte_ngbe_xstats_name_off rte_ngbe_qp_strings[] = {
235 QP_XSTAT(rx_qp_packets),
236 QP_XSTAT(tx_qp_packets),
237 QP_XSTAT(rx_qp_bytes),
238 QP_XSTAT(tx_qp_bytes),
239 QP_XSTAT(rx_qp_mc_packets),
242 #define NGBE_NB_QP_STATS (sizeof(rte_ngbe_qp_strings) / \
243 sizeof(rte_ngbe_qp_strings[0]))
245 static inline int32_t
246 ngbe_pf_reset_hw(struct ngbe_hw *hw)
251 status = hw->mac.reset_hw(hw);
253 ctrl_ext = rd32(hw, NGBE_PORTCTL);
254 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
255 ctrl_ext |= NGBE_PORTCTL_RSTDONE;
256 wr32(hw, NGBE_PORTCTL, ctrl_ext);
259 if (status == NGBE_ERR_SFP_NOT_PRESENT)
265 ngbe_enable_intr(struct rte_eth_dev *dev)
267 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
268 struct ngbe_hw *hw = ngbe_dev_hw(dev);
270 wr32(hw, NGBE_IENMISC, intr->mask_misc);
271 wr32(hw, NGBE_IMC(0), intr->mask & BIT_MASK32);
276 ngbe_disable_intr(struct ngbe_hw *hw)
278 PMD_INIT_FUNC_TRACE();
280 wr32(hw, NGBE_IMS(0), NGBE_IMS_MASK);
285 * Ensure that all locks are released before first NVM or PHY access
288 ngbe_swfw_lock_reset(struct ngbe_hw *hw)
293 * These ones are more tricky since they are common to all ports; but
294 * swfw_sync retries last long enough (1s) to be almost sure that if
295 * lock can not be taken it is due to an improper lock of the
298 mask = NGBE_MNGSEM_SWPHY |
301 if (hw->mac.acquire_swfw_sync(hw, mask) < 0)
302 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
304 hw->mac.release_swfw_sync(hw, mask);
308 eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
310 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
311 struct ngbe_hw *hw = ngbe_dev_hw(eth_dev);
312 struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(eth_dev);
313 struct ngbe_hwstrip *hwstrip = NGBE_DEV_HWSTRIP(eth_dev);
314 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
315 const struct rte_memzone *mz;
319 PMD_INIT_FUNC_TRACE();
321 eth_dev->dev_ops = &ngbe_eth_dev_ops;
322 eth_dev->rx_queue_count = ngbe_dev_rx_queue_count;
323 eth_dev->rx_descriptor_status = ngbe_dev_rx_descriptor_status;
324 eth_dev->tx_descriptor_status = ngbe_dev_tx_descriptor_status;
325 eth_dev->rx_pkt_burst = &ngbe_recv_pkts;
326 eth_dev->tx_pkt_burst = &ngbe_xmit_pkts;
327 eth_dev->tx_pkt_prepare = &ngbe_prep_pkts;
330 * For secondary processes, we don't initialise any further as primary
331 * has already done this work. Only check we don't need a different
332 * Rx and Tx function.
334 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
335 struct ngbe_tx_queue *txq;
336 /* Tx queue function in primary, set by last queue initialized
337 * Tx queue may not initialized by primary process
339 if (eth_dev->data->tx_queues) {
340 uint16_t nb_tx_queues = eth_dev->data->nb_tx_queues;
341 txq = eth_dev->data->tx_queues[nb_tx_queues - 1];
342 ngbe_set_tx_function(eth_dev, txq);
344 /* Use default Tx function if we get here */
346 "No Tx queues configured yet. Using default Tx function.");
349 ngbe_set_rx_function(eth_dev);
354 rte_eth_copy_pci_info(eth_dev, pci_dev);
355 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
357 /* Vendor and Device ID need to be set before init of shared code */
358 hw->device_id = pci_dev->id.device_id;
359 hw->vendor_id = pci_dev->id.vendor_id;
360 hw->sub_system_id = pci_dev->id.subsystem_device_id;
361 ngbe_map_device_id(hw);
362 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
364 /* Reserve memory for interrupt status block */
365 mz = rte_eth_dma_zone_reserve(eth_dev, "ngbe_driver", -1,
366 NGBE_ISB_SIZE, NGBE_ALIGN, SOCKET_ID_ANY);
370 hw->isb_dma = TMZ_PADDR(mz);
371 hw->isb_mem = TMZ_VADDR(mz);
373 /* Initialize the shared code (base driver) */
374 err = ngbe_init_shared_code(hw);
376 PMD_INIT_LOG(ERR, "Shared code init failed: %d", err);
380 /* Unlock any pending hardware semaphore */
381 ngbe_swfw_lock_reset(hw);
383 /* Get Hardware Flow Control setting */
384 hw->fc.requested_mode = ngbe_fc_full;
385 hw->fc.current_mode = ngbe_fc_full;
386 hw->fc.pause_time = NGBE_FC_PAUSE_TIME;
387 hw->fc.low_water = NGBE_FC_XON_LOTH;
388 hw->fc.high_water = NGBE_FC_XOFF_HITH;
391 err = hw->rom.init_params(hw);
393 PMD_INIT_LOG(ERR, "The EEPROM init failed: %d", err);
397 /* Make sure we have a good EEPROM before we read from it */
398 err = hw->rom.validate_checksum(hw, NULL);
400 PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", err);
404 err = hw->mac.init_hw(hw);
406 PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", err);
410 /* Reset the hw statistics */
411 ngbe_dev_stats_reset(eth_dev);
413 /* disable interrupt */
414 ngbe_disable_intr(hw);
416 /* Allocate memory for storing MAC addresses */
417 eth_dev->data->mac_addrs = rte_zmalloc("ngbe", RTE_ETHER_ADDR_LEN *
418 hw->mac.num_rar_entries, 0);
419 if (eth_dev->data->mac_addrs == NULL) {
421 "Failed to allocate %u bytes needed to store MAC addresses",
422 RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
426 /* Copy the permanent MAC address */
427 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
428 ð_dev->data->mac_addrs[0]);
430 /* Allocate memory for storing hash filter MAC addresses */
431 eth_dev->data->hash_mac_addrs = rte_zmalloc("ngbe",
432 RTE_ETHER_ADDR_LEN * NGBE_VMDQ_NUM_UC_MAC, 0);
433 if (eth_dev->data->hash_mac_addrs == NULL) {
435 "Failed to allocate %d bytes needed to store MAC addresses",
436 RTE_ETHER_ADDR_LEN * NGBE_VMDQ_NUM_UC_MAC);
437 rte_free(eth_dev->data->mac_addrs);
438 eth_dev->data->mac_addrs = NULL;
442 /* initialize the vfta */
443 memset(shadow_vfta, 0, sizeof(*shadow_vfta));
445 /* initialize the hw strip bitmap*/
446 memset(hwstrip, 0, sizeof(*hwstrip));
448 /* initialize PF if max_vfs not zero */
449 ret = ngbe_pf_host_init(eth_dev);
451 rte_free(eth_dev->data->mac_addrs);
452 eth_dev->data->mac_addrs = NULL;
453 rte_free(eth_dev->data->hash_mac_addrs);
454 eth_dev->data->hash_mac_addrs = NULL;
458 ctrl_ext = rd32(hw, NGBE_PORTCTL);
459 /* let hardware know driver is loaded */
460 ctrl_ext |= NGBE_PORTCTL_DRVLOAD;
461 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
462 ctrl_ext |= NGBE_PORTCTL_RSTDONE;
463 wr32(hw, NGBE_PORTCTL, ctrl_ext);
466 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
467 (int)hw->mac.type, (int)hw->phy.type);
469 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
470 eth_dev->data->port_id, pci_dev->id.vendor_id,
471 pci_dev->id.device_id);
473 rte_intr_callback_register(intr_handle,
474 ngbe_dev_interrupt_handler, eth_dev);
476 /* enable uio/vfio intr/eventfd mapping */
477 rte_intr_enable(intr_handle);
479 /* enable support intr */
480 ngbe_enable_intr(eth_dev);
486 eth_ngbe_dev_uninit(struct rte_eth_dev *eth_dev)
488 PMD_INIT_FUNC_TRACE();
490 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
493 ngbe_dev_close(eth_dev);
499 eth_ngbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
500 struct rte_pci_device *pci_dev)
502 return rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
503 sizeof(struct ngbe_adapter),
504 eth_dev_pci_specific_init, pci_dev,
505 eth_ngbe_dev_init, NULL);
508 static int eth_ngbe_pci_remove(struct rte_pci_device *pci_dev)
510 struct rte_eth_dev *ethdev;
512 ethdev = rte_eth_dev_allocated(pci_dev->device.name);
516 return rte_eth_dev_destroy(ethdev, eth_ngbe_dev_uninit);
519 static struct rte_pci_driver rte_ngbe_pmd = {
520 .id_table = pci_id_ngbe_map,
521 .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
522 RTE_PCI_DRV_INTR_LSC,
523 .probe = eth_ngbe_pci_probe,
524 .remove = eth_ngbe_pci_remove,
528 ngbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
530 struct ngbe_hw *hw = ngbe_dev_hw(dev);
531 struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(dev);
536 vid_idx = (uint32_t)((vlan_id >> 5) & 0x7F);
537 vid_bit = (uint32_t)(1 << (vlan_id & 0x1F));
538 vfta = rd32(hw, NGBE_VLANTBL(vid_idx));
543 wr32(hw, NGBE_VLANTBL(vid_idx), vfta);
545 /* update local VFTA copy */
546 shadow_vfta->vfta[vid_idx] = vfta;
552 ngbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
554 struct ngbe_hw *hw = ngbe_dev_hw(dev);
555 struct ngbe_rx_queue *rxq;
557 uint32_t rxcfg, rxbal, rxbah;
560 ngbe_vlan_hw_strip_enable(dev, queue);
562 ngbe_vlan_hw_strip_disable(dev, queue);
564 rxq = dev->data->rx_queues[queue];
565 rxbal = rd32(hw, NGBE_RXBAL(rxq->reg_idx));
566 rxbah = rd32(hw, NGBE_RXBAH(rxq->reg_idx));
567 rxcfg = rd32(hw, NGBE_RXCFG(rxq->reg_idx));
568 if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
569 restart = (rxcfg & NGBE_RXCFG_ENA) &&
570 !(rxcfg & NGBE_RXCFG_VLAN);
571 rxcfg |= NGBE_RXCFG_VLAN;
573 restart = (rxcfg & NGBE_RXCFG_ENA) &&
574 (rxcfg & NGBE_RXCFG_VLAN);
575 rxcfg &= ~NGBE_RXCFG_VLAN;
577 rxcfg &= ~NGBE_RXCFG_ENA;
580 /* set vlan strip for ring */
581 ngbe_dev_rx_queue_stop(dev, queue);
582 wr32(hw, NGBE_RXBAL(rxq->reg_idx), rxbal);
583 wr32(hw, NGBE_RXBAH(rxq->reg_idx), rxbah);
584 wr32(hw, NGBE_RXCFG(rxq->reg_idx), rxcfg);
585 ngbe_dev_rx_queue_start(dev, queue);
590 ngbe_vlan_tpid_set(struct rte_eth_dev *dev,
591 enum rte_vlan_type vlan_type,
594 struct ngbe_hw *hw = ngbe_dev_hw(dev);
596 uint32_t portctrl, vlan_ext, qinq;
598 portctrl = rd32(hw, NGBE_PORTCTL);
600 vlan_ext = (portctrl & NGBE_PORTCTL_VLANEXT);
601 qinq = vlan_ext && (portctrl & NGBE_PORTCTL_QINQ);
603 case RTE_ETH_VLAN_TYPE_INNER:
605 wr32m(hw, NGBE_VLANCTL,
606 NGBE_VLANCTL_TPID_MASK,
607 NGBE_VLANCTL_TPID(tpid));
608 wr32m(hw, NGBE_DMATXCTRL,
609 NGBE_DMATXCTRL_TPID_MASK,
610 NGBE_DMATXCTRL_TPID(tpid));
614 "Inner type is not supported by single VLAN");
618 wr32m(hw, NGBE_TAGTPID(0),
619 NGBE_TAGTPID_LSB_MASK,
620 NGBE_TAGTPID_LSB(tpid));
623 case RTE_ETH_VLAN_TYPE_OUTER:
625 /* Only the high 16-bits is valid */
626 wr32m(hw, NGBE_EXTAG,
627 NGBE_EXTAG_VLAN_MASK,
628 NGBE_EXTAG_VLAN(tpid));
630 wr32m(hw, NGBE_VLANCTL,
631 NGBE_VLANCTL_TPID_MASK,
632 NGBE_VLANCTL_TPID(tpid));
633 wr32m(hw, NGBE_DMATXCTRL,
634 NGBE_DMATXCTRL_TPID_MASK,
635 NGBE_DMATXCTRL_TPID(tpid));
639 wr32m(hw, NGBE_TAGTPID(0),
640 NGBE_TAGTPID_MSB_MASK,
641 NGBE_TAGTPID_MSB(tpid));
645 PMD_DRV_LOG(ERR, "Unsupported VLAN type %d", vlan_type);
653 ngbe_vlan_hw_filter_disable(struct rte_eth_dev *dev)
655 struct ngbe_hw *hw = ngbe_dev_hw(dev);
658 PMD_INIT_FUNC_TRACE();
660 /* Filter Table Disable */
661 vlnctrl = rd32(hw, NGBE_VLANCTL);
662 vlnctrl &= ~NGBE_VLANCTL_VFE;
663 wr32(hw, NGBE_VLANCTL, vlnctrl);
667 ngbe_vlan_hw_filter_enable(struct rte_eth_dev *dev)
669 struct ngbe_hw *hw = ngbe_dev_hw(dev);
670 struct ngbe_vfta *shadow_vfta = NGBE_DEV_VFTA(dev);
674 PMD_INIT_FUNC_TRACE();
676 /* Filter Table Enable */
677 vlnctrl = rd32(hw, NGBE_VLANCTL);
678 vlnctrl &= ~NGBE_VLANCTL_CFIENA;
679 vlnctrl |= NGBE_VLANCTL_VFE;
680 wr32(hw, NGBE_VLANCTL, vlnctrl);
682 /* write whatever is in local vfta copy */
683 for (i = 0; i < NGBE_VFTA_SIZE; i++)
684 wr32(hw, NGBE_VLANTBL(i), shadow_vfta->vfta[i]);
688 ngbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev, uint16_t queue, bool on)
690 struct ngbe_hwstrip *hwstrip = NGBE_DEV_HWSTRIP(dev);
691 struct ngbe_rx_queue *rxq;
693 if (queue >= NGBE_MAX_RX_QUEUE_NUM)
697 NGBE_SET_HWSTRIP(hwstrip, queue);
699 NGBE_CLEAR_HWSTRIP(hwstrip, queue);
701 if (queue >= dev->data->nb_rx_queues)
704 rxq = dev->data->rx_queues[queue];
707 rxq->vlan_flags = RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
708 rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
710 rxq->vlan_flags = RTE_MBUF_F_RX_VLAN;
711 rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
716 ngbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue)
718 struct ngbe_hw *hw = ngbe_dev_hw(dev);
721 PMD_INIT_FUNC_TRACE();
723 ctrl = rd32(hw, NGBE_RXCFG(queue));
724 ctrl &= ~NGBE_RXCFG_VLAN;
725 wr32(hw, NGBE_RXCFG(queue), ctrl);
727 /* record those setting for HW strip per queue */
728 ngbe_vlan_hw_strip_bitmap_set(dev, queue, 0);
732 ngbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue)
734 struct ngbe_hw *hw = ngbe_dev_hw(dev);
737 PMD_INIT_FUNC_TRACE();
739 ctrl = rd32(hw, NGBE_RXCFG(queue));
740 ctrl |= NGBE_RXCFG_VLAN;
741 wr32(hw, NGBE_RXCFG(queue), ctrl);
743 /* record those setting for HW strip per queue */
744 ngbe_vlan_hw_strip_bitmap_set(dev, queue, 1);
748 ngbe_vlan_hw_extend_disable(struct rte_eth_dev *dev)
750 struct ngbe_hw *hw = ngbe_dev_hw(dev);
753 PMD_INIT_FUNC_TRACE();
755 ctrl = rd32(hw, NGBE_PORTCTL);
756 ctrl &= ~NGBE_PORTCTL_VLANEXT;
757 ctrl &= ~NGBE_PORTCTL_QINQ;
758 wr32(hw, NGBE_PORTCTL, ctrl);
762 ngbe_vlan_hw_extend_enable(struct rte_eth_dev *dev)
764 struct ngbe_hw *hw = ngbe_dev_hw(dev);
767 PMD_INIT_FUNC_TRACE();
769 ctrl = rd32(hw, NGBE_PORTCTL);
770 ctrl |= NGBE_PORTCTL_VLANEXT | NGBE_PORTCTL_QINQ;
771 wr32(hw, NGBE_PORTCTL, ctrl);
775 ngbe_qinq_hw_strip_disable(struct rte_eth_dev *dev)
777 struct ngbe_hw *hw = ngbe_dev_hw(dev);
780 PMD_INIT_FUNC_TRACE();
782 ctrl = rd32(hw, NGBE_PORTCTL);
783 ctrl &= ~NGBE_PORTCTL_QINQ;
784 wr32(hw, NGBE_PORTCTL, ctrl);
788 ngbe_qinq_hw_strip_enable(struct rte_eth_dev *dev)
790 struct ngbe_hw *hw = ngbe_dev_hw(dev);
793 PMD_INIT_FUNC_TRACE();
795 ctrl = rd32(hw, NGBE_PORTCTL);
796 ctrl |= NGBE_PORTCTL_QINQ | NGBE_PORTCTL_VLANEXT;
797 wr32(hw, NGBE_PORTCTL, ctrl);
801 ngbe_vlan_hw_strip_config(struct rte_eth_dev *dev)
803 struct ngbe_rx_queue *rxq;
806 PMD_INIT_FUNC_TRACE();
808 for (i = 0; i < dev->data->nb_rx_queues; i++) {
809 rxq = dev->data->rx_queues[i];
811 if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
812 ngbe_vlan_hw_strip_enable(dev, i);
814 ngbe_vlan_hw_strip_disable(dev, i);
819 ngbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev, int mask)
822 struct rte_eth_rxmode *rxmode;
823 struct ngbe_rx_queue *rxq;
825 if (mask & RTE_ETH_VLAN_STRIP_MASK) {
826 rxmode = &dev->data->dev_conf.rxmode;
827 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
828 for (i = 0; i < dev->data->nb_rx_queues; i++) {
829 rxq = dev->data->rx_queues[i];
830 rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
833 for (i = 0; i < dev->data->nb_rx_queues; i++) {
834 rxq = dev->data->rx_queues[i];
835 rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
841 ngbe_vlan_offload_config(struct rte_eth_dev *dev, int mask)
843 struct rte_eth_rxmode *rxmode;
844 rxmode = &dev->data->dev_conf.rxmode;
846 if (mask & RTE_ETH_VLAN_STRIP_MASK)
847 ngbe_vlan_hw_strip_config(dev);
849 if (mask & RTE_ETH_VLAN_FILTER_MASK) {
850 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
851 ngbe_vlan_hw_filter_enable(dev);
853 ngbe_vlan_hw_filter_disable(dev);
856 if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
857 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
858 ngbe_vlan_hw_extend_enable(dev);
860 ngbe_vlan_hw_extend_disable(dev);
863 if (mask & RTE_ETH_QINQ_STRIP_MASK) {
864 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
865 ngbe_qinq_hw_strip_enable(dev);
867 ngbe_qinq_hw_strip_disable(dev);
874 ngbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
876 ngbe_config_vlan_strip_on_all_queues(dev, mask);
878 ngbe_vlan_offload_config(dev, mask);
884 ngbe_dev_configure(struct rte_eth_dev *dev)
886 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
887 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
889 PMD_INIT_FUNC_TRACE();
891 if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
892 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
894 /* set flag to update link status after init */
895 intr->flags |= NGBE_FLAG_NEED_LINK_UPDATE;
898 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
899 * allocation Rx preconditions we will reset it.
901 adapter->rx_bulk_alloc_allowed = true;
907 ngbe_dev_phy_intr_setup(struct rte_eth_dev *dev)
909 struct ngbe_hw *hw = ngbe_dev_hw(dev);
910 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
912 wr32(hw, NGBE_GPIODIR, NGBE_GPIODIR_DDR(1));
913 wr32(hw, NGBE_GPIOINTEN, NGBE_GPIOINTEN_INT(3));
914 wr32(hw, NGBE_GPIOINTTYPE, NGBE_GPIOINTTYPE_LEVEL(0));
915 if (hw->phy.type == ngbe_phy_yt8521s_sfi)
916 wr32(hw, NGBE_GPIOINTPOL, NGBE_GPIOINTPOL_ACT(0));
918 wr32(hw, NGBE_GPIOINTPOL, NGBE_GPIOINTPOL_ACT(3));
920 intr->mask_misc |= NGBE_ICRMISC_GPIO;
924 * Configure device link speed and setup link.
925 * It returns 0 on success.
928 ngbe_dev_start(struct rte_eth_dev *dev)
930 struct ngbe_hw *hw = ngbe_dev_hw(dev);
931 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
932 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
933 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
934 uint32_t intr_vector = 0;
936 bool link_up = false, negotiate = false;
938 uint32_t allowed_speeds = 0;
941 uint32_t *link_speeds;
943 PMD_INIT_FUNC_TRACE();
945 /* Stop the link setup handler before resetting the HW. */
946 rte_eal_alarm_cancel(ngbe_dev_setup_link_alarm_handler, dev);
948 /* disable uio/vfio intr/eventfd mapping */
949 rte_intr_disable(intr_handle);
952 hw->adapter_stopped = 0;
954 /* reinitialize adapter, this calls reset and start */
955 hw->nb_rx_queues = dev->data->nb_rx_queues;
956 hw->nb_tx_queues = dev->data->nb_tx_queues;
957 status = ngbe_pf_reset_hw(hw);
960 hw->mac.start_hw(hw);
961 hw->mac.get_link_status = true;
963 ngbe_set_pcie_master(hw, true);
965 /* configure PF module if SRIOV enabled */
966 ngbe_pf_host_configure(dev);
968 ngbe_dev_phy_intr_setup(dev);
970 /* check and configure queue intr-vector mapping */
971 if ((rte_intr_cap_multiple(intr_handle) ||
972 !RTE_ETH_DEV_SRIOV(dev).active) &&
973 dev->data->dev_conf.intr_conf.rxq != 0) {
974 intr_vector = dev->data->nb_rx_queues;
975 if (rte_intr_efd_enable(intr_handle, intr_vector))
979 if (rte_intr_dp_is_en(intr_handle)) {
980 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
981 dev->data->nb_rx_queues)) {
983 "Failed to allocate %d rx_queues intr_vec",
984 dev->data->nb_rx_queues);
989 /* configure MSI-X for sleep until Rx interrupt */
990 ngbe_configure_msix(dev);
992 /* initialize transmission unit */
993 ngbe_dev_tx_init(dev);
995 /* This can fail when allocating mbufs for descriptor rings */
996 err = ngbe_dev_rx_init(dev);
998 PMD_INIT_LOG(ERR, "Unable to initialize Rx hardware");
1002 mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
1003 RTE_ETH_VLAN_EXTEND_MASK;
1004 err = ngbe_vlan_offload_config(dev, mask);
1006 PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
1010 hw->mac.setup_pba(hw);
1011 ngbe_configure_port(dev);
1013 err = ngbe_dev_rxtx_start(dev);
1015 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
1019 /* Skip link setup if loopback mode is enabled. */
1020 if (hw->is_pf && dev->data->dev_conf.lpbk_mode)
1021 goto skip_link_setup;
1023 err = hw->mac.check_link(hw, &speed, &link_up, 0);
1026 dev->data->dev_link.link_status = link_up;
1028 link_speeds = &dev->data->dev_conf.link_speeds;
1029 if (*link_speeds == RTE_ETH_LINK_SPEED_AUTONEG)
1032 err = hw->mac.get_link_capabilities(hw, &speed, &negotiate);
1037 if (hw->mac.default_speeds & NGBE_LINK_SPEED_1GB_FULL)
1038 allowed_speeds |= RTE_ETH_LINK_SPEED_1G;
1039 if (hw->mac.default_speeds & NGBE_LINK_SPEED_100M_FULL)
1040 allowed_speeds |= RTE_ETH_LINK_SPEED_100M;
1041 if (hw->mac.default_speeds & NGBE_LINK_SPEED_10M_FULL)
1042 allowed_speeds |= RTE_ETH_LINK_SPEED_10M;
1044 if (*link_speeds & ~allowed_speeds) {
1045 PMD_INIT_LOG(ERR, "Invalid link setting");
1050 if (*link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
1051 speed = hw->mac.default_speeds;
1053 if (*link_speeds & RTE_ETH_LINK_SPEED_1G)
1054 speed |= NGBE_LINK_SPEED_1GB_FULL;
1055 if (*link_speeds & RTE_ETH_LINK_SPEED_100M)
1056 speed |= NGBE_LINK_SPEED_100M_FULL;
1057 if (*link_speeds & RTE_ETH_LINK_SPEED_10M)
1058 speed |= NGBE_LINK_SPEED_10M_FULL;
1061 hw->phy.init_hw(hw);
1062 err = hw->mac.setup_link(hw, speed, link_up);
1068 if (rte_intr_allow_others(intr_handle)) {
1069 ngbe_dev_misc_interrupt_setup(dev);
1070 /* check if lsc interrupt is enabled */
1071 if (dev->data->dev_conf.intr_conf.lsc != 0)
1072 ngbe_dev_lsc_interrupt_setup(dev, TRUE);
1074 ngbe_dev_lsc_interrupt_setup(dev, FALSE);
1075 ngbe_dev_macsec_interrupt_setup(dev);
1076 ngbe_set_ivar_map(hw, -1, 1, NGBE_MISC_VEC_ID);
1078 rte_intr_callback_unregister(intr_handle,
1079 ngbe_dev_interrupt_handler, dev);
1080 if (dev->data->dev_conf.intr_conf.lsc != 0)
1082 "LSC won't enable because of no intr multiplex");
1085 /* check if rxq interrupt is enabled */
1086 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1087 rte_intr_dp_is_en(intr_handle))
1088 ngbe_dev_rxq_interrupt_setup(dev);
1090 /* enable UIO/VFIO intr/eventfd mapping */
1091 rte_intr_enable(intr_handle);
1093 /* resume enabled intr since HW reset */
1094 ngbe_enable_intr(dev);
1096 if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
1097 (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
1098 /* gpio0 is used to power on/off control*/
1099 wr32(hw, NGBE_GPIODATA, 0);
1103 * Update link status right before return, because it may
1104 * start link configuration process in a separate thread.
1106 ngbe_dev_link_update(dev, 0);
1108 ngbe_read_stats_registers(hw, hw_stats);
1109 hw->offset_loaded = 1;
1114 PMD_INIT_LOG(ERR, "failure in dev start: %d", err);
1115 ngbe_dev_clear_queues(dev);
1120 * Stop device: disable rx and tx functions to allow for reconfiguring.
1123 ngbe_dev_stop(struct rte_eth_dev *dev)
1125 struct rte_eth_link link;
1126 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
1127 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1128 struct ngbe_vf_info *vfinfo = *NGBE_DEV_VFDATA(dev);
1129 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1130 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1133 if (hw->adapter_stopped)
1136 PMD_INIT_FUNC_TRACE();
1138 rte_eal_alarm_cancel(ngbe_dev_setup_link_alarm_handler, dev);
1140 if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
1141 (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
1142 /* gpio0 is used to power on/off control*/
1143 wr32(hw, NGBE_GPIODATA, NGBE_GPIOBIT_0);
1146 /* disable interrupts */
1147 ngbe_disable_intr(hw);
1150 ngbe_pf_reset_hw(hw);
1151 hw->adapter_stopped = 0;
1156 for (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)
1157 vfinfo[vf].clear_to_send = false;
1159 ngbe_dev_clear_queues(dev);
1161 /* Clear stored conf */
1162 dev->data->scattered_rx = 0;
1164 /* Clear recorded link status */
1165 memset(&link, 0, sizeof(link));
1166 rte_eth_linkstatus_set(dev, &link);
1168 if (!rte_intr_allow_others(intr_handle))
1169 /* resume to the default handler */
1170 rte_intr_callback_register(intr_handle,
1171 ngbe_dev_interrupt_handler,
1174 /* Clean datapath event and queue/vec mapping */
1175 rte_intr_efd_disable(intr_handle);
1176 rte_intr_vec_list_free(intr_handle);
1178 ngbe_set_pcie_master(hw, true);
1180 adapter->rss_reta_updated = 0;
1182 hw->adapter_stopped = true;
1183 dev->data->dev_started = 0;
1189 * Reset and stop device.
1192 ngbe_dev_close(struct rte_eth_dev *dev)
1194 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1195 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1196 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1200 PMD_INIT_FUNC_TRACE();
1202 ngbe_pf_reset_hw(hw);
1206 ngbe_dev_free_queues(dev);
1208 ngbe_set_pcie_master(hw, false);
1210 /* reprogram the RAR[0] in case user changed it. */
1211 ngbe_set_rar(hw, 0, hw->mac.addr, 0, true);
1213 /* Unlock any pending hardware semaphore */
1214 ngbe_swfw_lock_reset(hw);
1216 /* disable uio intr before callback unregister */
1217 rte_intr_disable(intr_handle);
1220 ret = rte_intr_callback_unregister(intr_handle,
1221 ngbe_dev_interrupt_handler, dev);
1222 if (ret >= 0 || ret == -ENOENT) {
1224 } else if (ret != -EAGAIN) {
1226 "intr callback unregister failed: %d",
1230 } while (retries++ < (10 + NGBE_LINK_UP_TIME));
1232 /* uninitialize PF if max_vfs not zero */
1233 ngbe_pf_host_uninit(dev);
1235 rte_free(dev->data->mac_addrs);
1236 dev->data->mac_addrs = NULL;
1238 rte_free(dev->data->hash_mac_addrs);
1239 dev->data->hash_mac_addrs = NULL;
1248 ngbe_dev_reset(struct rte_eth_dev *dev)
1252 /* When a DPDK PMD PF begin to reset PF port, it should notify all
1253 * its VF to make them align with it. The detailed notification
1254 * mechanism is PMD specific. As to ngbe PF, it is rather complex.
1255 * To avoid unexpected behavior in VF, currently reset of PF with
1256 * SR-IOV activation is not supported. It might be supported later.
1258 if (dev->data->sriov.active)
1261 ret = eth_ngbe_dev_uninit(dev);
1265 ret = eth_ngbe_dev_init(dev, NULL);
1270 #define UPDATE_QP_COUNTER_32bit(reg, last_counter, counter) \
1272 uint32_t current_counter = rd32(hw, reg); \
1273 if (current_counter < last_counter) \
1274 current_counter += 0x100000000LL; \
1275 if (!hw->offset_loaded) \
1276 last_counter = current_counter; \
1277 counter = current_counter - last_counter; \
1278 counter &= 0xFFFFFFFFLL; \
1281 #define UPDATE_QP_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
1283 uint64_t current_counter_lsb = rd32(hw, reg_lsb); \
1284 uint64_t current_counter_msb = rd32(hw, reg_msb); \
1285 uint64_t current_counter = (current_counter_msb << 32) | \
1286 current_counter_lsb; \
1287 if (current_counter < last_counter) \
1288 current_counter += 0x1000000000LL; \
1289 if (!hw->offset_loaded) \
1290 last_counter = current_counter; \
1291 counter = current_counter - last_counter; \
1292 counter &= 0xFFFFFFFFFLL; \
1296 ngbe_read_stats_registers(struct ngbe_hw *hw,
1297 struct ngbe_hw_stats *hw_stats)
1302 for (i = 0; i < hw->nb_rx_queues; i++) {
1303 UPDATE_QP_COUNTER_32bit(NGBE_QPRXPKT(i),
1304 hw->qp_last[i].rx_qp_packets,
1305 hw_stats->qp[i].rx_qp_packets);
1306 UPDATE_QP_COUNTER_36bit(NGBE_QPRXOCTL(i), NGBE_QPRXOCTH(i),
1307 hw->qp_last[i].rx_qp_bytes,
1308 hw_stats->qp[i].rx_qp_bytes);
1309 UPDATE_QP_COUNTER_32bit(NGBE_QPRXMPKT(i),
1310 hw->qp_last[i].rx_qp_mc_packets,
1311 hw_stats->qp[i].rx_qp_mc_packets);
1312 UPDATE_QP_COUNTER_32bit(NGBE_QPRXBPKT(i),
1313 hw->qp_last[i].rx_qp_bc_packets,
1314 hw_stats->qp[i].rx_qp_bc_packets);
1317 for (i = 0; i < hw->nb_tx_queues; i++) {
1318 UPDATE_QP_COUNTER_32bit(NGBE_QPTXPKT(i),
1319 hw->qp_last[i].tx_qp_packets,
1320 hw_stats->qp[i].tx_qp_packets);
1321 UPDATE_QP_COUNTER_36bit(NGBE_QPTXOCTL(i), NGBE_QPTXOCTH(i),
1322 hw->qp_last[i].tx_qp_bytes,
1323 hw_stats->qp[i].tx_qp_bytes);
1324 UPDATE_QP_COUNTER_32bit(NGBE_QPTXMPKT(i),
1325 hw->qp_last[i].tx_qp_mc_packets,
1326 hw_stats->qp[i].tx_qp_mc_packets);
1327 UPDATE_QP_COUNTER_32bit(NGBE_QPTXBPKT(i),
1328 hw->qp_last[i].tx_qp_bc_packets,
1329 hw_stats->qp[i].tx_qp_bc_packets);
1333 hw_stats->rx_up_dropped += rd32(hw, NGBE_PBRXMISS);
1334 hw_stats->rdb_pkt_cnt += rd32(hw, NGBE_PBRXPKT);
1335 hw_stats->rdb_repli_cnt += rd32(hw, NGBE_PBRXREP);
1336 hw_stats->rdb_drp_cnt += rd32(hw, NGBE_PBRXDROP);
1337 hw_stats->tx_xoff_packets += rd32(hw, NGBE_PBTXLNKXOFF);
1338 hw_stats->tx_xon_packets += rd32(hw, NGBE_PBTXLNKXON);
1340 hw_stats->rx_xon_packets += rd32(hw, NGBE_PBRXLNKXON);
1341 hw_stats->rx_xoff_packets += rd32(hw, NGBE_PBRXLNKXOFF);
1344 hw_stats->rx_drop_packets += rd32(hw, NGBE_DMARXDROP);
1345 hw_stats->tx_drop_packets += rd32(hw, NGBE_DMATXDROP);
1346 hw_stats->rx_dma_drop += rd32(hw, NGBE_DMARXDROP);
1347 hw_stats->tx_secdrp_packets += rd32(hw, NGBE_DMATXSECDROP);
1348 hw_stats->rx_packets += rd32(hw, NGBE_DMARXPKT);
1349 hw_stats->tx_packets += rd32(hw, NGBE_DMATXPKT);
1350 hw_stats->rx_bytes += rd64(hw, NGBE_DMARXOCTL);
1351 hw_stats->tx_bytes += rd64(hw, NGBE_DMATXOCTL);
1354 hw_stats->rx_crc_errors += rd64(hw, NGBE_MACRXERRCRCL);
1355 hw_stats->rx_multicast_packets += rd64(hw, NGBE_MACRXMPKTL);
1356 hw_stats->tx_multicast_packets += rd64(hw, NGBE_MACTXMPKTL);
1358 hw_stats->rx_total_packets += rd64(hw, NGBE_MACRXPKTL);
1359 hw_stats->tx_total_packets += rd64(hw, NGBE_MACTXPKTL);
1360 hw_stats->rx_total_bytes += rd64(hw, NGBE_MACRXGBOCTL);
1362 hw_stats->rx_broadcast_packets += rd64(hw, NGBE_MACRXOCTL);
1363 hw_stats->tx_broadcast_packets += rd32(hw, NGBE_MACTXOCTL);
1365 hw_stats->rx_size_64_packets += rd64(hw, NGBE_MACRX1TO64L);
1366 hw_stats->rx_size_65_to_127_packets += rd64(hw, NGBE_MACRX65TO127L);
1367 hw_stats->rx_size_128_to_255_packets += rd64(hw, NGBE_MACRX128TO255L);
1368 hw_stats->rx_size_256_to_511_packets += rd64(hw, NGBE_MACRX256TO511L);
1369 hw_stats->rx_size_512_to_1023_packets +=
1370 rd64(hw, NGBE_MACRX512TO1023L);
1371 hw_stats->rx_size_1024_to_max_packets +=
1372 rd64(hw, NGBE_MACRX1024TOMAXL);
1373 hw_stats->tx_size_64_packets += rd64(hw, NGBE_MACTX1TO64L);
1374 hw_stats->tx_size_65_to_127_packets += rd64(hw, NGBE_MACTX65TO127L);
1375 hw_stats->tx_size_128_to_255_packets += rd64(hw, NGBE_MACTX128TO255L);
1376 hw_stats->tx_size_256_to_511_packets += rd64(hw, NGBE_MACTX256TO511L);
1377 hw_stats->tx_size_512_to_1023_packets +=
1378 rd64(hw, NGBE_MACTX512TO1023L);
1379 hw_stats->tx_size_1024_to_max_packets +=
1380 rd64(hw, NGBE_MACTX1024TOMAXL);
1382 hw_stats->rx_undersize_errors += rd64(hw, NGBE_MACRXERRLENL);
1383 hw_stats->rx_oversize_errors += rd32(hw, NGBE_MACRXOVERSIZE);
1384 hw_stats->rx_jabber_errors += rd32(hw, NGBE_MACRXJABBER);
1387 hw_stats->mng_bmc2host_packets = rd32(hw, NGBE_MNGBMC2OS);
1388 hw_stats->mng_host2bmc_packets = rd32(hw, NGBE_MNGOS2BMC);
1389 hw_stats->rx_management_packets = rd32(hw, NGBE_DMARXMNG);
1390 hw_stats->tx_management_packets = rd32(hw, NGBE_DMATXMNG);
1393 hw_stats->tx_macsec_pkts_untagged += rd32(hw, NGBE_LSECTX_UTPKT);
1394 hw_stats->tx_macsec_pkts_encrypted +=
1395 rd32(hw, NGBE_LSECTX_ENCPKT);
1396 hw_stats->tx_macsec_pkts_protected +=
1397 rd32(hw, NGBE_LSECTX_PROTPKT);
1398 hw_stats->tx_macsec_octets_encrypted +=
1399 rd32(hw, NGBE_LSECTX_ENCOCT);
1400 hw_stats->tx_macsec_octets_protected +=
1401 rd32(hw, NGBE_LSECTX_PROTOCT);
1402 hw_stats->rx_macsec_pkts_untagged += rd32(hw, NGBE_LSECRX_UTPKT);
1403 hw_stats->rx_macsec_pkts_badtag += rd32(hw, NGBE_LSECRX_BTPKT);
1404 hw_stats->rx_macsec_pkts_nosci += rd32(hw, NGBE_LSECRX_NOSCIPKT);
1405 hw_stats->rx_macsec_pkts_unknownsci += rd32(hw, NGBE_LSECRX_UNSCIPKT);
1406 hw_stats->rx_macsec_octets_decrypted += rd32(hw, NGBE_LSECRX_DECOCT);
1407 hw_stats->rx_macsec_octets_validated += rd32(hw, NGBE_LSECRX_VLDOCT);
1408 hw_stats->rx_macsec_sc_pkts_unchecked +=
1409 rd32(hw, NGBE_LSECRX_UNCHKPKT);
1410 hw_stats->rx_macsec_sc_pkts_delayed += rd32(hw, NGBE_LSECRX_DLYPKT);
1411 hw_stats->rx_macsec_sc_pkts_late += rd32(hw, NGBE_LSECRX_LATEPKT);
1412 for (i = 0; i < 2; i++) {
1413 hw_stats->rx_macsec_sa_pkts_ok +=
1414 rd32(hw, NGBE_LSECRX_OKPKT(i));
1415 hw_stats->rx_macsec_sa_pkts_invalid +=
1416 rd32(hw, NGBE_LSECRX_INVPKT(i));
1417 hw_stats->rx_macsec_sa_pkts_notvalid +=
1418 rd32(hw, NGBE_LSECRX_BADPKT(i));
1420 for (i = 0; i < 4; i++) {
1421 hw_stats->rx_macsec_sa_pkts_unusedsa +=
1422 rd32(hw, NGBE_LSECRX_INVSAPKT(i));
1423 hw_stats->rx_macsec_sa_pkts_notusingsa +=
1424 rd32(hw, NGBE_LSECRX_BADSAPKT(i));
1426 hw_stats->rx_total_missed_packets =
1427 hw_stats->rx_up_dropped;
1431 ngbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1433 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1434 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1435 struct ngbe_stat_mappings *stat_mappings =
1436 NGBE_DEV_STAT_MAPPINGS(dev);
1439 ngbe_read_stats_registers(hw, hw_stats);
1444 /* Fill out the rte_eth_stats statistics structure */
1445 stats->ipackets = hw_stats->rx_packets;
1446 stats->ibytes = hw_stats->rx_bytes;
1447 stats->opackets = hw_stats->tx_packets;
1448 stats->obytes = hw_stats->tx_bytes;
1450 memset(&stats->q_ipackets, 0, sizeof(stats->q_ipackets));
1451 memset(&stats->q_opackets, 0, sizeof(stats->q_opackets));
1452 memset(&stats->q_ibytes, 0, sizeof(stats->q_ibytes));
1453 memset(&stats->q_obytes, 0, sizeof(stats->q_obytes));
1454 memset(&stats->q_errors, 0, sizeof(stats->q_errors));
1455 for (i = 0; i < NGBE_MAX_QP; i++) {
1456 uint32_t n = i / NB_QMAP_FIELDS_PER_QSM_REG;
1457 uint32_t offset = (i % NB_QMAP_FIELDS_PER_QSM_REG) * 8;
1460 q_map = (stat_mappings->rqsm[n] >> offset)
1461 & QMAP_FIELD_RESERVED_BITS_MASK;
1462 j = (q_map < RTE_ETHDEV_QUEUE_STAT_CNTRS
1463 ? q_map : q_map % RTE_ETHDEV_QUEUE_STAT_CNTRS);
1464 stats->q_ipackets[j] += hw_stats->qp[i].rx_qp_packets;
1465 stats->q_ibytes[j] += hw_stats->qp[i].rx_qp_bytes;
1467 q_map = (stat_mappings->tqsm[n] >> offset)
1468 & QMAP_FIELD_RESERVED_BITS_MASK;
1469 j = (q_map < RTE_ETHDEV_QUEUE_STAT_CNTRS
1470 ? q_map : q_map % RTE_ETHDEV_QUEUE_STAT_CNTRS);
1471 stats->q_opackets[j] += hw_stats->qp[i].tx_qp_packets;
1472 stats->q_obytes[j] += hw_stats->qp[i].tx_qp_bytes;
1476 stats->imissed = hw_stats->rx_total_missed_packets +
1477 hw_stats->rx_dma_drop;
1478 stats->ierrors = hw_stats->rx_crc_errors +
1479 hw_stats->rx_mac_short_packet_dropped +
1480 hw_stats->rx_length_errors +
1481 hw_stats->rx_undersize_errors +
1482 hw_stats->rx_oversize_errors +
1483 hw_stats->rx_illegal_byte_errors +
1484 hw_stats->rx_error_bytes +
1485 hw_stats->rx_fragment_errors;
1493 ngbe_dev_stats_reset(struct rte_eth_dev *dev)
1495 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1496 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1498 /* HW registers are cleared on read */
1499 hw->offset_loaded = 0;
1500 ngbe_dev_stats_get(dev, NULL);
1501 hw->offset_loaded = 1;
1503 /* Reset software totals */
1504 memset(hw_stats, 0, sizeof(*hw_stats));
1509 /* This function calculates the number of xstats based on the current config */
1511 ngbe_xstats_calc_num(struct rte_eth_dev *dev)
1513 int nb_queues = max(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
1514 return NGBE_NB_HW_STATS +
1515 NGBE_NB_QP_STATS * nb_queues;
1519 ngbe_get_name_by_id(uint32_t id, char *name, uint32_t size)
1523 /* Extended stats from ngbe_hw_stats */
1524 if (id < NGBE_NB_HW_STATS) {
1525 snprintf(name, size, "[hw]%s",
1526 rte_ngbe_stats_strings[id].name);
1529 id -= NGBE_NB_HW_STATS;
1532 if (id < NGBE_NB_QP_STATS * NGBE_MAX_QP) {
1533 nb = id / NGBE_NB_QP_STATS;
1534 st = id % NGBE_NB_QP_STATS;
1535 snprintf(name, size, "[q%u]%s", nb,
1536 rte_ngbe_qp_strings[st].name);
1539 id -= NGBE_NB_QP_STATS * NGBE_MAX_QP;
1541 return -(int)(id + 1);
1545 ngbe_get_offset_by_id(uint32_t id, uint32_t *offset)
1549 /* Extended stats from ngbe_hw_stats */
1550 if (id < NGBE_NB_HW_STATS) {
1551 *offset = rte_ngbe_stats_strings[id].offset;
1554 id -= NGBE_NB_HW_STATS;
1557 if (id < NGBE_NB_QP_STATS * NGBE_MAX_QP) {
1558 nb = id / NGBE_NB_QP_STATS;
1559 st = id % NGBE_NB_QP_STATS;
1560 *offset = rte_ngbe_qp_strings[st].offset +
1561 nb * (NGBE_NB_QP_STATS * sizeof(uint64_t));
1568 static int ngbe_dev_xstats_get_names(struct rte_eth_dev *dev,
1569 struct rte_eth_xstat_name *xstats_names, unsigned int limit)
1571 unsigned int i, count;
1573 count = ngbe_xstats_calc_num(dev);
1574 if (xstats_names == NULL)
1577 /* Note: limit >= cnt_stats checked upstream
1578 * in rte_eth_xstats_names()
1580 limit = min(limit, count);
1582 /* Extended stats from ngbe_hw_stats */
1583 for (i = 0; i < limit; i++) {
1584 if (ngbe_get_name_by_id(i, xstats_names[i].name,
1585 sizeof(xstats_names[i].name))) {
1586 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1594 static int ngbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
1595 const uint64_t *ids,
1596 struct rte_eth_xstat_name *xstats_names,
1602 return ngbe_dev_xstats_get_names(dev, xstats_names, limit);
1604 for (i = 0; i < limit; i++) {
1605 if (ngbe_get_name_by_id(ids[i], xstats_names[i].name,
1606 sizeof(xstats_names[i].name))) {
1607 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1616 ngbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1619 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1620 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1621 unsigned int i, count;
1623 ngbe_read_stats_registers(hw, hw_stats);
1625 /* If this is a reset xstats is NULL, and we have cleared the
1626 * registers by reading them.
1628 count = ngbe_xstats_calc_num(dev);
1632 limit = min(limit, ngbe_xstats_calc_num(dev));
1634 /* Extended stats from ngbe_hw_stats */
1635 for (i = 0; i < limit; i++) {
1636 uint32_t offset = 0;
1638 if (ngbe_get_offset_by_id(i, &offset)) {
1639 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1642 xstats[i].value = *(uint64_t *)(((char *)hw_stats) + offset);
1650 ngbe_dev_xstats_get_(struct rte_eth_dev *dev, uint64_t *values,
1653 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1654 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1655 unsigned int i, count;
1657 ngbe_read_stats_registers(hw, hw_stats);
1659 /* If this is a reset xstats is NULL, and we have cleared the
1660 * registers by reading them.
1662 count = ngbe_xstats_calc_num(dev);
1666 limit = min(limit, ngbe_xstats_calc_num(dev));
1668 /* Extended stats from ngbe_hw_stats */
1669 for (i = 0; i < limit; i++) {
1672 if (ngbe_get_offset_by_id(i, &offset)) {
1673 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1676 values[i] = *(uint64_t *)(((char *)hw_stats) + offset);
1683 ngbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1684 uint64_t *values, unsigned int limit)
1686 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1690 return ngbe_dev_xstats_get_(dev, values, limit);
1692 for (i = 0; i < limit; i++) {
1695 if (ngbe_get_offset_by_id(ids[i], &offset)) {
1696 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1699 values[i] = *(uint64_t *)(((char *)hw_stats) + offset);
1706 ngbe_dev_xstats_reset(struct rte_eth_dev *dev)
1708 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1709 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1711 /* HW registers are cleared on read */
1712 hw->offset_loaded = 0;
1713 ngbe_read_stats_registers(hw, hw_stats);
1714 hw->offset_loaded = 1;
1716 /* Reset software totals */
1717 memset(hw_stats, 0, sizeof(*hw_stats));
1723 ngbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
1725 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1728 ret = snprintf(fw_version, fw_size, "0x%08x", hw->eeprom_id);
1733 ret += 1; /* add the size of '\0' */
1734 if (fw_size < (size_t)ret)
1741 ngbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1743 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1744 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1746 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
1747 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
1748 dev_info->min_rx_bufsize = 1024;
1749 dev_info->max_rx_pktlen = 15872;
1750 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
1751 dev_info->max_hash_mac_addrs = NGBE_VMDQ_NUM_UC_MAC;
1752 dev_info->max_vfs = pci_dev->max_vfs;
1753 dev_info->rx_queue_offload_capa = ngbe_get_rx_queue_offloads(dev);
1754 dev_info->rx_offload_capa = (ngbe_get_rx_port_offloads(dev) |
1755 dev_info->rx_queue_offload_capa);
1756 dev_info->tx_queue_offload_capa = 0;
1757 dev_info->tx_offload_capa = ngbe_get_tx_port_offloads(dev);
1759 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1761 .pthresh = NGBE_DEFAULT_RX_PTHRESH,
1762 .hthresh = NGBE_DEFAULT_RX_HTHRESH,
1763 .wthresh = NGBE_DEFAULT_RX_WTHRESH,
1765 .rx_free_thresh = NGBE_DEFAULT_RX_FREE_THRESH,
1770 dev_info->default_txconf = (struct rte_eth_txconf) {
1772 .pthresh = NGBE_DEFAULT_TX_PTHRESH,
1773 .hthresh = NGBE_DEFAULT_TX_HTHRESH,
1774 .wthresh = NGBE_DEFAULT_TX_WTHRESH,
1776 .tx_free_thresh = NGBE_DEFAULT_TX_FREE_THRESH,
1780 dev_info->rx_desc_lim = rx_desc_lim;
1781 dev_info->tx_desc_lim = tx_desc_lim;
1783 dev_info->hash_key_size = NGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
1784 dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
1785 dev_info->flow_type_rss_offloads = NGBE_RSS_OFFLOAD_ALL;
1787 dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_100M |
1788 RTE_ETH_LINK_SPEED_10M;
1790 /* Driver-preferred Rx/Tx parameters */
1791 dev_info->default_rxportconf.burst_size = 32;
1792 dev_info->default_txportconf.burst_size = 32;
1793 dev_info->default_rxportconf.nb_queues = 1;
1794 dev_info->default_txportconf.nb_queues = 1;
1795 dev_info->default_rxportconf.ring_size = 256;
1796 dev_info->default_txportconf.ring_size = 256;
1802 ngbe_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1804 if (dev->rx_pkt_burst == ngbe_recv_pkts ||
1805 dev->rx_pkt_burst == ngbe_recv_pkts_sc_single_alloc ||
1806 dev->rx_pkt_burst == ngbe_recv_pkts_sc_bulk_alloc ||
1807 dev->rx_pkt_burst == ngbe_recv_pkts_bulk_alloc)
1808 return ngbe_get_supported_ptypes();
1814 ngbe_dev_setup_link_alarm_handler(void *param)
1816 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1817 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1818 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1820 bool autoneg = false;
1822 speed = hw->phy.autoneg_advertised;
1824 hw->mac.get_link_capabilities(hw, &speed, &autoneg);
1826 hw->mac.setup_link(hw, speed, true);
1828 intr->flags &= ~NGBE_FLAG_NEED_LINK_CONFIG;
1831 /* return 0 means link status changed, -1 means not changed */
1833 ngbe_dev_link_update_share(struct rte_eth_dev *dev,
1834 int wait_to_complete)
1836 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1837 struct rte_eth_link link;
1838 u32 link_speed = NGBE_LINK_SPEED_UNKNOWN;
1840 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1845 memset(&link, 0, sizeof(link));
1846 link.link_status = RTE_ETH_LINK_DOWN;
1847 link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1848 link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1849 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1850 ~RTE_ETH_LINK_SPEED_AUTONEG);
1852 hw->mac.get_link_status = true;
1854 if (intr->flags & NGBE_FLAG_NEED_LINK_CONFIG)
1855 return rte_eth_linkstatus_set(dev, &link);
1857 /* check if it needs to wait to complete, if lsc interrupt is enabled */
1858 if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
1861 err = hw->mac.check_link(hw, &link_speed, &link_up, wait);
1863 link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1864 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1865 return rte_eth_linkstatus_set(dev, &link);
1869 if (hw->phy.media_type == ngbe_media_type_fiber &&
1870 hw->phy.type != ngbe_phy_mvl_sfi) {
1871 intr->flags |= NGBE_FLAG_NEED_LINK_CONFIG;
1872 rte_eal_alarm_set(10,
1873 ngbe_dev_setup_link_alarm_handler, dev);
1876 return rte_eth_linkstatus_set(dev, &link);
1879 intr->flags &= ~NGBE_FLAG_NEED_LINK_CONFIG;
1880 link.link_status = RTE_ETH_LINK_UP;
1881 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1883 switch (link_speed) {
1885 case NGBE_LINK_SPEED_UNKNOWN:
1886 link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1889 case NGBE_LINK_SPEED_10M_FULL:
1890 link.link_speed = RTE_ETH_SPEED_NUM_10M;
1894 case NGBE_LINK_SPEED_100M_FULL:
1895 link.link_speed = RTE_ETH_SPEED_NUM_100M;
1899 case NGBE_LINK_SPEED_1GB_FULL:
1900 link.link_speed = RTE_ETH_SPEED_NUM_1G;
1906 wr32m(hw, NGBE_LAN_SPEED, NGBE_LAN_SPEED_MASK, lan_speed);
1907 if (link_speed & (NGBE_LINK_SPEED_1GB_FULL |
1908 NGBE_LINK_SPEED_100M_FULL |
1909 NGBE_LINK_SPEED_10M_FULL)) {
1910 wr32m(hw, NGBE_MACTXCFG, NGBE_MACTXCFG_SPEED_MASK,
1911 NGBE_MACTXCFG_SPEED_1G | NGBE_MACTXCFG_TE);
1915 return rte_eth_linkstatus_set(dev, &link);
1919 ngbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1921 return ngbe_dev_link_update_share(dev, wait_to_complete);
1925 ngbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
1927 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1930 fctrl = rd32(hw, NGBE_PSRCTL);
1931 fctrl |= (NGBE_PSRCTL_UCP | NGBE_PSRCTL_MCP);
1932 wr32(hw, NGBE_PSRCTL, fctrl);
1938 ngbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
1940 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1943 fctrl = rd32(hw, NGBE_PSRCTL);
1944 fctrl &= (~NGBE_PSRCTL_UCP);
1945 if (dev->data->all_multicast == 1)
1946 fctrl |= NGBE_PSRCTL_MCP;
1948 fctrl &= (~NGBE_PSRCTL_MCP);
1949 wr32(hw, NGBE_PSRCTL, fctrl);
1955 ngbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
1957 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1960 fctrl = rd32(hw, NGBE_PSRCTL);
1961 fctrl |= NGBE_PSRCTL_MCP;
1962 wr32(hw, NGBE_PSRCTL, fctrl);
1968 ngbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
1970 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1973 if (dev->data->promiscuous == 1)
1974 return 0; /* must remain in all_multicast mode */
1976 fctrl = rd32(hw, NGBE_PSRCTL);
1977 fctrl &= (~NGBE_PSRCTL_MCP);
1978 wr32(hw, NGBE_PSRCTL, fctrl);
1984 * It clears the interrupt causes and enables the interrupt.
1985 * It will be called once only during NIC initialized.
1988 * Pointer to struct rte_eth_dev.
1990 * Enable or Disable.
1993 * - On success, zero.
1994 * - On failure, a negative value.
1997 ngbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
1999 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2001 ngbe_dev_link_status_print(dev);
2003 intr->mask_misc |= NGBE_ICRMISC_PHY;
2004 intr->mask_misc |= NGBE_ICRMISC_GPIO;
2006 intr->mask_misc &= ~NGBE_ICRMISC_PHY;
2007 intr->mask_misc &= ~NGBE_ICRMISC_GPIO;
2014 * It clears the interrupt causes and enables the interrupt.
2015 * It will be called once only during NIC initialized.
2018 * Pointer to struct rte_eth_dev.
2021 * - On success, zero.
2022 * - On failure, a negative value.
2025 ngbe_dev_misc_interrupt_setup(struct rte_eth_dev *dev)
2027 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2030 mask = NGBE_ICR_MASK;
2031 mask &= (1ULL << NGBE_MISC_VEC_ID);
2033 intr->mask_misc |= NGBE_ICRMISC_GPIO;
2039 * It clears the interrupt causes and enables the interrupt.
2040 * It will be called once only during NIC initialized.
2043 * Pointer to struct rte_eth_dev.
2046 * - On success, zero.
2047 * - On failure, a negative value.
2050 ngbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
2052 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2055 mask = NGBE_ICR_MASK;
2056 mask &= ~((1ULL << NGBE_RX_VEC_START) - 1);
2063 * It clears the interrupt causes and enables the interrupt.
2064 * It will be called once only during NIC initialized.
2067 * Pointer to struct rte_eth_dev.
2070 * - On success, zero.
2071 * - On failure, a negative value.
2074 ngbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev)
2076 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2078 intr->mask_misc |= NGBE_ICRMISC_LNKSEC;
2084 * It reads ICR and sets flag for the link_update.
2087 * Pointer to struct rte_eth_dev.
2090 * - On success, zero.
2091 * - On failure, a negative value.
2094 ngbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
2097 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2098 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2100 /* read-on-clear nic registers here */
2101 eicr = ((u32 *)hw->isb_mem)[NGBE_ISB_MISC];
2102 PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
2106 /* set flag for async link update */
2107 if (eicr & NGBE_ICRMISC_PHY)
2108 intr->flags |= NGBE_FLAG_NEED_LINK_UPDATE;
2110 if (eicr & NGBE_ICRMISC_VFMBX)
2111 intr->flags |= NGBE_FLAG_MAILBOX;
2113 if (eicr & NGBE_ICRMISC_LNKSEC)
2114 intr->flags |= NGBE_FLAG_MACSEC;
2116 if (eicr & NGBE_ICRMISC_GPIO)
2117 intr->flags |= NGBE_FLAG_NEED_LINK_UPDATE;
2119 ((u32 *)hw->isb_mem)[NGBE_ISB_MISC] = 0;
2125 * It gets and then prints the link status.
2128 * Pointer to struct rte_eth_dev.
2131 * - On success, zero.
2132 * - On failure, a negative value.
2135 ngbe_dev_link_status_print(struct rte_eth_dev *dev)
2137 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2138 struct rte_eth_link link;
2140 rte_eth_linkstatus_get(dev, &link);
2142 if (link.link_status == RTE_ETH_LINK_UP) {
2143 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
2144 (int)(dev->data->port_id),
2145 (unsigned int)link.link_speed,
2146 link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
2147 "full-duplex" : "half-duplex");
2149 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2150 (int)(dev->data->port_id));
2152 PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
2153 pci_dev->addr.domain,
2155 pci_dev->addr.devid,
2156 pci_dev->addr.function);
2160 * It executes link_update after knowing an interrupt occurred.
2163 * Pointer to struct rte_eth_dev.
2166 * - On success, zero.
2167 * - On failure, a negative value.
2170 ngbe_dev_interrupt_action(struct rte_eth_dev *dev)
2172 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2174 PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
2176 if (intr->flags & NGBE_FLAG_MAILBOX) {
2177 ngbe_pf_mbx_process(dev);
2178 intr->flags &= ~NGBE_FLAG_MAILBOX;
2181 if (intr->flags & NGBE_FLAG_NEED_LINK_UPDATE) {
2182 struct rte_eth_link link;
2184 /*get the link status before link update, for predicting later*/
2185 rte_eth_linkstatus_get(dev, &link);
2187 ngbe_dev_link_update(dev, 0);
2188 intr->flags &= ~NGBE_FLAG_NEED_LINK_UPDATE;
2189 ngbe_dev_link_status_print(dev);
2190 if (dev->data->dev_link.link_speed != link.link_speed)
2191 rte_eth_dev_callback_process(dev,
2192 RTE_ETH_EVENT_INTR_LSC, NULL);
2195 PMD_DRV_LOG(DEBUG, "enable intr immediately");
2196 ngbe_enable_intr(dev);
2202 * Interrupt handler triggered by NIC for handling
2203 * specific interrupt.
2206 * The address of parameter (struct rte_eth_dev *) registered before.
2209 ngbe_dev_interrupt_handler(void *param)
2211 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2213 ngbe_dev_interrupt_get_status(dev);
2214 ngbe_dev_interrupt_action(dev);
2218 ngbe_dev_led_on(struct rte_eth_dev *dev)
2220 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2221 return hw->mac.led_on(hw, 0) == 0 ? 0 : -ENOTSUP;
2225 ngbe_dev_led_off(struct rte_eth_dev *dev)
2227 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2228 return hw->mac.led_off(hw, 0) == 0 ? 0 : -ENOTSUP;
2232 ngbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2234 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2240 fc_conf->pause_time = hw->fc.pause_time;
2241 fc_conf->high_water = hw->fc.high_water;
2242 fc_conf->low_water = hw->fc.low_water;
2243 fc_conf->send_xon = hw->fc.send_xon;
2244 fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
2247 * Return rx_pause status according to actual setting of
2250 mflcn_reg = rd32(hw, NGBE_RXFCCFG);
2251 if (mflcn_reg & NGBE_RXFCCFG_FC)
2257 * Return tx_pause status according to actual setting of
2260 fccfg_reg = rd32(hw, NGBE_TXFCCFG);
2261 if (fccfg_reg & NGBE_TXFCCFG_FC)
2266 if (rx_pause && tx_pause)
2267 fc_conf->mode = RTE_ETH_FC_FULL;
2269 fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
2271 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
2273 fc_conf->mode = RTE_ETH_FC_NONE;
2279 ngbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2281 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2283 uint32_t rx_buf_size;
2284 uint32_t max_high_water;
2285 enum ngbe_fc_mode rte_fcmode_2_ngbe_fcmode[] = {
2292 PMD_INIT_FUNC_TRACE();
2294 rx_buf_size = rd32(hw, NGBE_PBRXSIZE);
2295 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2298 * At least reserve one Ethernet frame for watermark
2299 * high_water/low_water in kilo bytes for ngbe
2301 max_high_water = (rx_buf_size - RTE_ETHER_MAX_LEN) >> 10;
2302 if (fc_conf->high_water > max_high_water ||
2303 fc_conf->high_water < fc_conf->low_water) {
2304 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
2305 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
2309 hw->fc.requested_mode = rte_fcmode_2_ngbe_fcmode[fc_conf->mode];
2310 hw->fc.pause_time = fc_conf->pause_time;
2311 hw->fc.high_water = fc_conf->high_water;
2312 hw->fc.low_water = fc_conf->low_water;
2313 hw->fc.send_xon = fc_conf->send_xon;
2314 hw->fc.disable_fc_autoneg = !fc_conf->autoneg;
2316 err = hw->mac.fc_enable(hw);
2318 /* Not negotiated is not an error case */
2319 if (err == 0 || err == NGBE_ERR_FC_NOT_NEGOTIATED) {
2320 wr32m(hw, NGBE_MACRXFLT, NGBE_MACRXFLT_CTL_MASK,
2321 (fc_conf->mac_ctrl_frame_fwd
2322 ? NGBE_MACRXFLT_CTL_NOPS : NGBE_MACRXFLT_CTL_DROP));
2328 PMD_INIT_LOG(ERR, "ngbe_fc_enable = 0x%x", err);
2333 ngbe_dev_rss_reta_update(struct rte_eth_dev *dev,
2334 struct rte_eth_rss_reta_entry64 *reta_conf,
2339 uint16_t idx, shift;
2340 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2341 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2343 PMD_INIT_FUNC_TRACE();
2346 PMD_DRV_LOG(ERR, "RSS reta update is not supported on this "
2351 if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
2352 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2353 "(%d) doesn't match the number hardware can supported "
2354 "(%d)", reta_size, RTE_ETH_RSS_RETA_SIZE_128);
2358 for (i = 0; i < reta_size; i += 4) {
2359 idx = i / RTE_ETH_RETA_GROUP_SIZE;
2360 shift = i % RTE_ETH_RETA_GROUP_SIZE;
2361 mask = (uint8_t)RS64(reta_conf[idx].mask, shift, 0xF);
2365 reta = rd32a(hw, NGBE_REG_RSSTBL, i >> 2);
2366 for (j = 0; j < 4; j++) {
2367 if (RS8(mask, j, 0x1)) {
2368 reta &= ~(MS32(8 * j, 0xFF));
2369 reta |= LS32(reta_conf[idx].reta[shift + j],
2373 wr32a(hw, NGBE_REG_RSSTBL, i >> 2, reta);
2375 adapter->rss_reta_updated = 1;
2381 ngbe_dev_rss_reta_query(struct rte_eth_dev *dev,
2382 struct rte_eth_rss_reta_entry64 *reta_conf,
2385 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2388 uint16_t idx, shift;
2390 PMD_INIT_FUNC_TRACE();
2392 if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
2393 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2394 "(%d) doesn't match the number hardware can supported "
2395 "(%d)", reta_size, RTE_ETH_RSS_RETA_SIZE_128);
2399 for (i = 0; i < reta_size; i += 4) {
2400 idx = i / RTE_ETH_RETA_GROUP_SIZE;
2401 shift = i % RTE_ETH_RETA_GROUP_SIZE;
2402 mask = (uint8_t)RS64(reta_conf[idx].mask, shift, 0xF);
2406 reta = rd32a(hw, NGBE_REG_RSSTBL, i >> 2);
2407 for (j = 0; j < 4; j++) {
2408 if (RS8(mask, j, 0x1))
2409 reta_conf[idx].reta[shift + j] =
2410 (uint16_t)RS32(reta, 8 * j, 0xFF);
2418 ngbe_add_rar(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
2419 uint32_t index, uint32_t pool)
2421 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2422 uint32_t enable_addr = 1;
2424 return ngbe_set_rar(hw, index, mac_addr->addr_bytes,
2429 ngbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
2431 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2433 ngbe_clear_rar(hw, index);
2437 ngbe_set_default_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
2439 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2441 ngbe_remove_rar(dev, 0);
2442 ngbe_add_rar(dev, addr, 0, pci_dev->max_vfs);
2448 ngbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
2450 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2451 uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + 4;
2452 struct rte_eth_dev_data *dev_data = dev->data;
2454 /* If device is started, refuse mtu that requires the support of
2455 * scattered packets when this feature has not been enabled before.
2457 if (dev_data->dev_started && !dev_data->scattered_rx &&
2458 (frame_size + 2 * RTE_VLAN_HLEN >
2459 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
2460 PMD_INIT_LOG(ERR, "Stop port first.");
2465 wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
2466 NGBE_FRAME_SIZE_MAX);
2468 wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
2469 NGBE_FRMSZ_MAX(frame_size));
2475 ngbe_uta_vector(struct ngbe_hw *hw, struct rte_ether_addr *uc_addr)
2477 uint32_t vector = 0;
2479 switch (hw->mac.mc_filter_type) {
2480 case 0: /* use bits [47:36] of the address */
2481 vector = ((uc_addr->addr_bytes[4] >> 4) |
2482 (((uint16_t)uc_addr->addr_bytes[5]) << 4));
2484 case 1: /* use bits [46:35] of the address */
2485 vector = ((uc_addr->addr_bytes[4] >> 3) |
2486 (((uint16_t)uc_addr->addr_bytes[5]) << 5));
2488 case 2: /* use bits [45:34] of the address */
2489 vector = ((uc_addr->addr_bytes[4] >> 2) |
2490 (((uint16_t)uc_addr->addr_bytes[5]) << 6));
2492 case 3: /* use bits [43:32] of the address */
2493 vector = ((uc_addr->addr_bytes[4]) |
2494 (((uint16_t)uc_addr->addr_bytes[5]) << 8));
2496 default: /* Invalid mc_filter_type */
2500 /* vector can only be 12-bits or boundary will be exceeded */
2506 ngbe_uc_hash_table_set(struct rte_eth_dev *dev,
2507 struct rte_ether_addr *mac_addr, uint8_t on)
2515 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2516 struct ngbe_uta_info *uta_info = NGBE_DEV_UTA_INFO(dev);
2518 vector = ngbe_uta_vector(hw, mac_addr);
2519 uta_idx = (vector >> 5) & 0x7F;
2520 uta_mask = 0x1UL << (vector & 0x1F);
2522 if (!!on == !!(uta_info->uta_shadow[uta_idx] & uta_mask))
2525 reg_val = rd32(hw, NGBE_UCADDRTBL(uta_idx));
2527 uta_info->uta_in_use++;
2528 reg_val |= uta_mask;
2529 uta_info->uta_shadow[uta_idx] |= uta_mask;
2531 uta_info->uta_in_use--;
2532 reg_val &= ~uta_mask;
2533 uta_info->uta_shadow[uta_idx] &= ~uta_mask;
2536 wr32(hw, NGBE_UCADDRTBL(uta_idx), reg_val);
2538 psrctl = rd32(hw, NGBE_PSRCTL);
2539 if (uta_info->uta_in_use > 0)
2540 psrctl |= NGBE_PSRCTL_UCHFENA;
2542 psrctl &= ~NGBE_PSRCTL_UCHFENA;
2544 psrctl &= ~NGBE_PSRCTL_ADHF12_MASK;
2545 psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
2546 wr32(hw, NGBE_PSRCTL, psrctl);
2552 ngbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
2554 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2555 struct ngbe_uta_info *uta_info = NGBE_DEV_UTA_INFO(dev);
2560 for (i = 0; i < RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
2561 uta_info->uta_shadow[i] = ~0;
2562 wr32(hw, NGBE_UCADDRTBL(i), ~0);
2565 for (i = 0; i < RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
2566 uta_info->uta_shadow[i] = 0;
2567 wr32(hw, NGBE_UCADDRTBL(i), 0);
2571 psrctl = rd32(hw, NGBE_PSRCTL);
2573 psrctl |= NGBE_PSRCTL_UCHFENA;
2575 psrctl &= ~NGBE_PSRCTL_UCHFENA;
2577 psrctl &= ~NGBE_PSRCTL_ADHF12_MASK;
2578 psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
2579 wr32(hw, NGBE_PSRCTL, psrctl);
2585 * Set the IVAR registers, mapping interrupt causes to vectors
2587 * pointer to ngbe_hw struct
2589 * 0 for Rx, 1 for Tx, -1 for other causes
2591 * queue to map the corresponding interrupt to
2593 * the vector to map to the corresponding queue
2596 ngbe_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
2597 uint8_t queue, uint8_t msix_vector)
2601 if (direction == -1) {
2603 msix_vector |= NGBE_IVARMISC_VLD;
2605 tmp = rd32(hw, NGBE_IVARMISC);
2606 tmp &= ~(0xFF << idx);
2607 tmp |= (msix_vector << idx);
2608 wr32(hw, NGBE_IVARMISC, tmp);
2610 /* rx or tx causes */
2611 /* Workaround for ICR lost */
2612 idx = ((16 * (queue & 1)) + (8 * direction));
2613 tmp = rd32(hw, NGBE_IVAR(queue >> 1));
2614 tmp &= ~(0xFF << idx);
2615 tmp |= (msix_vector << idx);
2616 wr32(hw, NGBE_IVAR(queue >> 1), tmp);
2621 * Sets up the hardware to properly generate MSI-X interrupts
2623 * board private structure
2626 ngbe_configure_msix(struct rte_eth_dev *dev)
2628 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2629 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2630 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2631 uint32_t queue_id, base = NGBE_MISC_VEC_ID;
2632 uint32_t vec = NGBE_MISC_VEC_ID;
2636 * Won't configure MSI-X register if no mapping is done
2637 * between intr vector and event fd
2638 * but if MSI-X has been enabled already, need to configure
2639 * auto clean, auto mask and throttling.
2641 gpie = rd32(hw, NGBE_GPIE);
2642 if (!rte_intr_dp_is_en(intr_handle) &&
2643 !(gpie & NGBE_GPIE_MSIX))
2646 if (rte_intr_allow_others(intr_handle)) {
2647 base = NGBE_RX_VEC_START;
2651 /* setup GPIE for MSI-X mode */
2652 gpie = rd32(hw, NGBE_GPIE);
2653 gpie |= NGBE_GPIE_MSIX;
2654 wr32(hw, NGBE_GPIE, gpie);
2656 /* Populate the IVAR table and set the ITR values to the
2657 * corresponding register.
2659 if (rte_intr_dp_is_en(intr_handle)) {
2660 for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
2662 /* by default, 1:1 mapping */
2663 ngbe_set_ivar_map(hw, 0, queue_id, vec);
2664 rte_intr_vec_list_index_set(intr_handle,
2666 if (vec < base + rte_intr_nb_efd_get(intr_handle)
2671 ngbe_set_ivar_map(hw, -1, 1, NGBE_MISC_VEC_ID);
2673 wr32(hw, NGBE_ITR(NGBE_MISC_VEC_ID),
2674 NGBE_ITR_IVAL_1G(NGBE_QUEUE_ITR_INTERVAL_DEFAULT)
2679 ngbe_dev_addr_list_itr(__rte_unused struct ngbe_hw *hw,
2680 u8 **mc_addr_ptr, u32 *vmdq)
2685 mc_addr = *mc_addr_ptr;
2686 *mc_addr_ptr = (mc_addr + sizeof(struct rte_ether_addr));
2691 ngbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
2692 struct rte_ether_addr *mc_addr_set,
2693 uint32_t nb_mc_addr)
2695 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2698 mc_addr_list = (u8 *)mc_addr_set;
2699 return hw->mac.update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
2700 ngbe_dev_addr_list_itr, TRUE);
2704 ngbe_read_systime_cyclecounter(struct rte_eth_dev *dev)
2706 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2707 uint64_t systime_cycles;
2709 systime_cycles = (uint64_t)rd32(hw, NGBE_TSTIMEL);
2710 systime_cycles |= (uint64_t)rd32(hw, NGBE_TSTIMEH) << 32;
2712 return systime_cycles;
2716 ngbe_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
2718 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2719 uint64_t rx_tstamp_cycles;
2721 /* TSRXSTMPL stores ns and TSRXSTMPH stores seconds. */
2722 rx_tstamp_cycles = (uint64_t)rd32(hw, NGBE_TSRXSTMPL);
2723 rx_tstamp_cycles |= (uint64_t)rd32(hw, NGBE_TSRXSTMPH) << 32;
2725 return rx_tstamp_cycles;
2729 ngbe_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
2731 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2732 uint64_t tx_tstamp_cycles;
2734 /* TSTXSTMPL stores ns and TSTXSTMPH stores seconds. */
2735 tx_tstamp_cycles = (uint64_t)rd32(hw, NGBE_TSTXSTMPL);
2736 tx_tstamp_cycles |= (uint64_t)rd32(hw, NGBE_TSTXSTMPH) << 32;
2738 return tx_tstamp_cycles;
2742 ngbe_start_timecounters(struct rte_eth_dev *dev)
2744 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2745 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2746 uint32_t incval = 0;
2749 incval = NGBE_INCVAL_1GB;
2750 shift = NGBE_INCVAL_SHIFT_1GB;
2752 wr32(hw, NGBE_TSTIMEINC, NGBE_TSTIMEINC_IV(incval));
2754 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
2755 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
2756 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
2758 adapter->systime_tc.cc_mask = NGBE_CYCLECOUNTER_MASK;
2759 adapter->systime_tc.cc_shift = shift;
2760 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
2762 adapter->rx_tstamp_tc.cc_mask = NGBE_CYCLECOUNTER_MASK;
2763 adapter->rx_tstamp_tc.cc_shift = shift;
2764 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
2766 adapter->tx_tstamp_tc.cc_mask = NGBE_CYCLECOUNTER_MASK;
2767 adapter->tx_tstamp_tc.cc_shift = shift;
2768 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
2772 ngbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
2774 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2776 adapter->systime_tc.nsec += delta;
2777 adapter->rx_tstamp_tc.nsec += delta;
2778 adapter->tx_tstamp_tc.nsec += delta;
2784 ngbe_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
2787 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2789 ns = rte_timespec_to_ns(ts);
2790 /* Set the timecounters to a new value. */
2791 adapter->systime_tc.nsec = ns;
2792 adapter->rx_tstamp_tc.nsec = ns;
2793 adapter->tx_tstamp_tc.nsec = ns;
2799 ngbe_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
2801 uint64_t ns, systime_cycles;
2802 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2804 systime_cycles = ngbe_read_systime_cyclecounter(dev);
2805 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
2806 *ts = rte_ns_to_timespec(ns);
2812 ngbe_timesync_enable(struct rte_eth_dev *dev)
2814 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2817 /* Stop the timesync system time. */
2818 wr32(hw, NGBE_TSTIMEINC, 0x0);
2819 /* Reset the timesync system time value. */
2820 wr32(hw, NGBE_TSTIMEL, 0x0);
2821 wr32(hw, NGBE_TSTIMEH, 0x0);
2823 ngbe_start_timecounters(dev);
2825 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
2826 wr32(hw, NGBE_ETFLT(NGBE_ETF_ID_1588),
2827 RTE_ETHER_TYPE_1588 | NGBE_ETFLT_ENA | NGBE_ETFLT_1588);
2829 /* Enable timestamping of received PTP packets. */
2830 tsync_ctl = rd32(hw, NGBE_TSRXCTL);
2831 tsync_ctl |= NGBE_TSRXCTL_ENA;
2832 wr32(hw, NGBE_TSRXCTL, tsync_ctl);
2834 /* Enable timestamping of transmitted PTP packets. */
2835 tsync_ctl = rd32(hw, NGBE_TSTXCTL);
2836 tsync_ctl |= NGBE_TSTXCTL_ENA;
2837 wr32(hw, NGBE_TSTXCTL, tsync_ctl);
2845 ngbe_timesync_disable(struct rte_eth_dev *dev)
2847 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2850 /* Disable timestamping of transmitted PTP packets. */
2851 tsync_ctl = rd32(hw, NGBE_TSTXCTL);
2852 tsync_ctl &= ~NGBE_TSTXCTL_ENA;
2853 wr32(hw, NGBE_TSTXCTL, tsync_ctl);
2855 /* Disable timestamping of received PTP packets. */
2856 tsync_ctl = rd32(hw, NGBE_TSRXCTL);
2857 tsync_ctl &= ~NGBE_TSRXCTL_ENA;
2858 wr32(hw, NGBE_TSRXCTL, tsync_ctl);
2860 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
2861 wr32(hw, NGBE_ETFLT(NGBE_ETF_ID_1588), 0);
2863 /* Stop incrementing the System Time registers. */
2864 wr32(hw, NGBE_TSTIMEINC, 0);
2870 ngbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
2871 struct timespec *timestamp,
2872 uint32_t flags __rte_unused)
2874 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2875 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2876 uint32_t tsync_rxctl;
2877 uint64_t rx_tstamp_cycles;
2880 tsync_rxctl = rd32(hw, NGBE_TSRXCTL);
2881 if ((tsync_rxctl & NGBE_TSRXCTL_VLD) == 0)
2884 rx_tstamp_cycles = ngbe_read_rx_tstamp_cyclecounter(dev);
2885 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
2886 *timestamp = rte_ns_to_timespec(ns);
2892 ngbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
2893 struct timespec *timestamp)
2895 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2896 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2897 uint32_t tsync_txctl;
2898 uint64_t tx_tstamp_cycles;
2901 tsync_txctl = rd32(hw, NGBE_TSTXCTL);
2902 if ((tsync_txctl & NGBE_TSTXCTL_VLD) == 0)
2905 tx_tstamp_cycles = ngbe_read_tx_tstamp_cyclecounter(dev);
2906 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
2907 *timestamp = rte_ns_to_timespec(ns);
2913 ngbe_get_reg_length(struct rte_eth_dev *dev __rte_unused)
2917 const struct reg_info *reg_group;
2918 const struct reg_info **reg_set = ngbe_regs_others;
2920 while ((reg_group = reg_set[g_ind++]))
2921 count += ngbe_regs_group_count(reg_group);
2927 ngbe_get_regs(struct rte_eth_dev *dev,
2928 struct rte_dev_reg_info *regs)
2930 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2931 uint32_t *data = regs->data;
2934 const struct reg_info *reg_group;
2935 const struct reg_info **reg_set = ngbe_regs_others;
2938 regs->length = ngbe_get_reg_length(dev);
2939 regs->width = sizeof(uint32_t);
2943 /* Support only full register dump */
2944 if (regs->length == 0 ||
2945 regs->length == (uint32_t)ngbe_get_reg_length(dev)) {
2946 regs->version = hw->mac.type << 24 |
2947 hw->revision_id << 16 |
2949 while ((reg_group = reg_set[g_ind++]))
2950 count += ngbe_read_regs_group(dev, &data[count],
2959 ngbe_get_eeprom_length(struct rte_eth_dev *dev)
2961 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2963 /* Return unit is byte count */
2964 return hw->rom.word_size * 2;
2968 ngbe_get_eeprom(struct rte_eth_dev *dev,
2969 struct rte_dev_eeprom_info *in_eeprom)
2971 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2972 struct ngbe_rom_info *eeprom = &hw->rom;
2973 uint16_t *data = in_eeprom->data;
2976 first = in_eeprom->offset >> 1;
2977 length = in_eeprom->length >> 1;
2978 if (first > hw->rom.word_size ||
2979 ((first + length) > hw->rom.word_size))
2982 in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
2984 return eeprom->readw_buffer(hw, first, length, data);
2988 ngbe_set_eeprom(struct rte_eth_dev *dev,
2989 struct rte_dev_eeprom_info *in_eeprom)
2991 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2992 struct ngbe_rom_info *eeprom = &hw->rom;
2993 uint16_t *data = in_eeprom->data;
2996 first = in_eeprom->offset >> 1;
2997 length = in_eeprom->length >> 1;
2998 if (first > hw->rom.word_size ||
2999 ((first + length) > hw->rom.word_size))
3002 in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
3004 return eeprom->writew_buffer(hw, first, length, data);
3007 static const struct eth_dev_ops ngbe_eth_dev_ops = {
3008 .dev_configure = ngbe_dev_configure,
3009 .dev_infos_get = ngbe_dev_info_get,
3010 .dev_start = ngbe_dev_start,
3011 .dev_stop = ngbe_dev_stop,
3012 .dev_close = ngbe_dev_close,
3013 .dev_reset = ngbe_dev_reset,
3014 .promiscuous_enable = ngbe_dev_promiscuous_enable,
3015 .promiscuous_disable = ngbe_dev_promiscuous_disable,
3016 .allmulticast_enable = ngbe_dev_allmulticast_enable,
3017 .allmulticast_disable = ngbe_dev_allmulticast_disable,
3018 .link_update = ngbe_dev_link_update,
3019 .stats_get = ngbe_dev_stats_get,
3020 .xstats_get = ngbe_dev_xstats_get,
3021 .xstats_get_by_id = ngbe_dev_xstats_get_by_id,
3022 .stats_reset = ngbe_dev_stats_reset,
3023 .xstats_reset = ngbe_dev_xstats_reset,
3024 .xstats_get_names = ngbe_dev_xstats_get_names,
3025 .xstats_get_names_by_id = ngbe_dev_xstats_get_names_by_id,
3026 .fw_version_get = ngbe_fw_version_get,
3027 .dev_supported_ptypes_get = ngbe_dev_supported_ptypes_get,
3028 .mtu_set = ngbe_dev_mtu_set,
3029 .vlan_filter_set = ngbe_vlan_filter_set,
3030 .vlan_tpid_set = ngbe_vlan_tpid_set,
3031 .vlan_offload_set = ngbe_vlan_offload_set,
3032 .vlan_strip_queue_set = ngbe_vlan_strip_queue_set,
3033 .rx_queue_start = ngbe_dev_rx_queue_start,
3034 .rx_queue_stop = ngbe_dev_rx_queue_stop,
3035 .tx_queue_start = ngbe_dev_tx_queue_start,
3036 .tx_queue_stop = ngbe_dev_tx_queue_stop,
3037 .rx_queue_setup = ngbe_dev_rx_queue_setup,
3038 .rx_queue_release = ngbe_dev_rx_queue_release,
3039 .tx_queue_setup = ngbe_dev_tx_queue_setup,
3040 .tx_queue_release = ngbe_dev_tx_queue_release,
3041 .dev_led_on = ngbe_dev_led_on,
3042 .dev_led_off = ngbe_dev_led_off,
3043 .flow_ctrl_get = ngbe_flow_ctrl_get,
3044 .flow_ctrl_set = ngbe_flow_ctrl_set,
3045 .mac_addr_add = ngbe_add_rar,
3046 .mac_addr_remove = ngbe_remove_rar,
3047 .mac_addr_set = ngbe_set_default_mac_addr,
3048 .uc_hash_table_set = ngbe_uc_hash_table_set,
3049 .uc_all_hash_table_set = ngbe_uc_all_hash_table_set,
3050 .reta_update = ngbe_dev_rss_reta_update,
3051 .reta_query = ngbe_dev_rss_reta_query,
3052 .rss_hash_update = ngbe_dev_rss_hash_update,
3053 .rss_hash_conf_get = ngbe_dev_rss_hash_conf_get,
3054 .set_mc_addr_list = ngbe_dev_set_mc_addr_list,
3055 .rxq_info_get = ngbe_rxq_info_get,
3056 .txq_info_get = ngbe_txq_info_get,
3057 .rx_burst_mode_get = ngbe_rx_burst_mode_get,
3058 .tx_burst_mode_get = ngbe_tx_burst_mode_get,
3059 .timesync_enable = ngbe_timesync_enable,
3060 .timesync_disable = ngbe_timesync_disable,
3061 .timesync_read_rx_timestamp = ngbe_timesync_read_rx_timestamp,
3062 .timesync_read_tx_timestamp = ngbe_timesync_read_tx_timestamp,
3063 .get_reg = ngbe_get_regs,
3064 .get_eeprom_length = ngbe_get_eeprom_length,
3065 .get_eeprom = ngbe_get_eeprom,
3066 .set_eeprom = ngbe_set_eeprom,
3067 .timesync_adjust_time = ngbe_timesync_adjust_time,
3068 .timesync_read_time = ngbe_timesync_read_time,
3069 .timesync_write_time = ngbe_timesync_write_time,
3070 .tx_done_cleanup = ngbe_dev_tx_done_cleanup,
3073 RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
3074 RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
3075 RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic | vfio-pci");
3077 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_init, init, NOTICE);
3078 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_driver, driver, NOTICE);
3080 #ifdef RTE_ETHDEV_DEBUG_RX
3081 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_rx, rx, DEBUG);
3083 #ifdef RTE_ETHDEV_DEBUG_TX
3084 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_tx, tx, DEBUG);