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;
955 /* reinitialize adapter, this calls reset and start */
956 hw->nb_rx_queues = dev->data->nb_rx_queues;
957 hw->nb_tx_queues = dev->data->nb_tx_queues;
958 status = ngbe_pf_reset_hw(hw);
961 hw->mac.start_hw(hw);
962 hw->mac.get_link_status = true;
964 /* configure PF module if SRIOV enabled */
965 ngbe_pf_host_configure(dev);
967 ngbe_dev_phy_intr_setup(dev);
969 /* check and configure queue intr-vector mapping */
970 if ((rte_intr_cap_multiple(intr_handle) ||
971 !RTE_ETH_DEV_SRIOV(dev).active) &&
972 dev->data->dev_conf.intr_conf.rxq != 0) {
973 intr_vector = dev->data->nb_rx_queues;
974 if (rte_intr_efd_enable(intr_handle, intr_vector))
978 if (rte_intr_dp_is_en(intr_handle)) {
979 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
980 dev->data->nb_rx_queues)) {
982 "Failed to allocate %d rx_queues intr_vec",
983 dev->data->nb_rx_queues);
988 /* configure MSI-X for sleep until Rx interrupt */
989 ngbe_configure_msix(dev);
991 /* initialize transmission unit */
992 ngbe_dev_tx_init(dev);
994 /* This can fail when allocating mbufs for descriptor rings */
995 err = ngbe_dev_rx_init(dev);
997 PMD_INIT_LOG(ERR, "Unable to initialize Rx hardware");
1001 mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
1002 RTE_ETH_VLAN_EXTEND_MASK;
1003 err = ngbe_vlan_offload_config(dev, mask);
1005 PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
1009 hw->mac.setup_pba(hw);
1010 ngbe_configure_port(dev);
1012 err = ngbe_dev_rxtx_start(dev);
1014 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
1018 /* Skip link setup if loopback mode is enabled. */
1019 if (hw->is_pf && dev->data->dev_conf.lpbk_mode)
1020 goto skip_link_setup;
1022 err = hw->mac.check_link(hw, &speed, &link_up, 0);
1025 dev->data->dev_link.link_status = link_up;
1027 link_speeds = &dev->data->dev_conf.link_speeds;
1028 if (*link_speeds == RTE_ETH_LINK_SPEED_AUTONEG)
1031 err = hw->mac.get_link_capabilities(hw, &speed, &negotiate);
1036 if (hw->mac.default_speeds & NGBE_LINK_SPEED_1GB_FULL)
1037 allowed_speeds |= RTE_ETH_LINK_SPEED_1G;
1038 if (hw->mac.default_speeds & NGBE_LINK_SPEED_100M_FULL)
1039 allowed_speeds |= RTE_ETH_LINK_SPEED_100M;
1040 if (hw->mac.default_speeds & NGBE_LINK_SPEED_10M_FULL)
1041 allowed_speeds |= RTE_ETH_LINK_SPEED_10M;
1043 if (*link_speeds & ~allowed_speeds) {
1044 PMD_INIT_LOG(ERR, "Invalid link setting");
1049 if (*link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
1050 speed = hw->mac.default_speeds;
1052 if (*link_speeds & RTE_ETH_LINK_SPEED_1G)
1053 speed |= NGBE_LINK_SPEED_1GB_FULL;
1054 if (*link_speeds & RTE_ETH_LINK_SPEED_100M)
1055 speed |= NGBE_LINK_SPEED_100M_FULL;
1056 if (*link_speeds & RTE_ETH_LINK_SPEED_10M)
1057 speed |= NGBE_LINK_SPEED_10M_FULL;
1060 hw->phy.init_hw(hw);
1061 err = hw->mac.setup_link(hw, speed, link_up);
1067 if (rte_intr_allow_others(intr_handle)) {
1068 ngbe_dev_misc_interrupt_setup(dev);
1069 /* check if lsc interrupt is enabled */
1070 if (dev->data->dev_conf.intr_conf.lsc != 0)
1071 ngbe_dev_lsc_interrupt_setup(dev, TRUE);
1073 ngbe_dev_lsc_interrupt_setup(dev, FALSE);
1074 ngbe_dev_macsec_interrupt_setup(dev);
1075 ngbe_set_ivar_map(hw, -1, 1, NGBE_MISC_VEC_ID);
1077 rte_intr_callback_unregister(intr_handle,
1078 ngbe_dev_interrupt_handler, dev);
1079 if (dev->data->dev_conf.intr_conf.lsc != 0)
1081 "LSC won't enable because of no intr multiplex");
1084 /* check if rxq interrupt is enabled */
1085 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
1086 rte_intr_dp_is_en(intr_handle))
1087 ngbe_dev_rxq_interrupt_setup(dev);
1089 /* enable UIO/VFIO intr/eventfd mapping */
1090 rte_intr_enable(intr_handle);
1092 /* resume enabled intr since HW reset */
1093 ngbe_enable_intr(dev);
1095 if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
1096 (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
1097 /* gpio0 is used to power on/off control*/
1098 wr32(hw, NGBE_GPIODATA, 0);
1102 * Update link status right before return, because it may
1103 * start link configuration process in a separate thread.
1105 ngbe_dev_link_update(dev, 0);
1107 ngbe_read_stats_registers(hw, hw_stats);
1108 hw->offset_loaded = 1;
1113 PMD_INIT_LOG(ERR, "failure in dev start: %d", err);
1114 ngbe_dev_clear_queues(dev);
1119 * Stop device: disable rx and tx functions to allow for reconfiguring.
1122 ngbe_dev_stop(struct rte_eth_dev *dev)
1124 struct rte_eth_link link;
1125 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
1126 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1127 struct ngbe_vf_info *vfinfo = *NGBE_DEV_VFDATA(dev);
1128 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1129 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1132 if (hw->adapter_stopped)
1135 PMD_INIT_FUNC_TRACE();
1137 rte_eal_alarm_cancel(ngbe_dev_setup_link_alarm_handler, dev);
1139 if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
1140 (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
1141 /* gpio0 is used to power on/off control*/
1142 wr32(hw, NGBE_GPIODATA, NGBE_GPIOBIT_0);
1145 /* disable interrupts */
1146 ngbe_disable_intr(hw);
1149 ngbe_pf_reset_hw(hw);
1150 hw->adapter_stopped = 0;
1155 for (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)
1156 vfinfo[vf].clear_to_send = false;
1158 ngbe_dev_clear_queues(dev);
1160 /* Clear stored conf */
1161 dev->data->scattered_rx = 0;
1163 /* Clear recorded link status */
1164 memset(&link, 0, sizeof(link));
1165 rte_eth_linkstatus_set(dev, &link);
1167 if (!rte_intr_allow_others(intr_handle))
1168 /* resume to the default handler */
1169 rte_intr_callback_register(intr_handle,
1170 ngbe_dev_interrupt_handler,
1173 /* Clean datapath event and queue/vec mapping */
1174 rte_intr_efd_disable(intr_handle);
1175 rte_intr_vec_list_free(intr_handle);
1177 adapter->rss_reta_updated = 0;
1179 hw->adapter_stopped = true;
1180 dev->data->dev_started = 0;
1186 * Reset and stop device.
1189 ngbe_dev_close(struct rte_eth_dev *dev)
1191 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1192 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1193 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1197 PMD_INIT_FUNC_TRACE();
1199 ngbe_pf_reset_hw(hw);
1203 ngbe_dev_free_queues(dev);
1205 /* reprogram the RAR[0] in case user changed it. */
1206 ngbe_set_rar(hw, 0, hw->mac.addr, 0, true);
1208 /* Unlock any pending hardware semaphore */
1209 ngbe_swfw_lock_reset(hw);
1211 /* disable uio intr before callback unregister */
1212 rte_intr_disable(intr_handle);
1215 ret = rte_intr_callback_unregister(intr_handle,
1216 ngbe_dev_interrupt_handler, dev);
1217 if (ret >= 0 || ret == -ENOENT) {
1219 } else if (ret != -EAGAIN) {
1221 "intr callback unregister failed: %d",
1225 } while (retries++ < (10 + NGBE_LINK_UP_TIME));
1227 /* uninitialize PF if max_vfs not zero */
1228 ngbe_pf_host_uninit(dev);
1230 rte_free(dev->data->mac_addrs);
1231 dev->data->mac_addrs = NULL;
1233 rte_free(dev->data->hash_mac_addrs);
1234 dev->data->hash_mac_addrs = NULL;
1243 ngbe_dev_reset(struct rte_eth_dev *dev)
1247 /* When a DPDK PMD PF begin to reset PF port, it should notify all
1248 * its VF to make them align with it. The detailed notification
1249 * mechanism is PMD specific. As to ngbe PF, it is rather complex.
1250 * To avoid unexpected behavior in VF, currently reset of PF with
1251 * SR-IOV activation is not supported. It might be supported later.
1253 if (dev->data->sriov.active)
1256 ret = eth_ngbe_dev_uninit(dev);
1260 ret = eth_ngbe_dev_init(dev, NULL);
1265 #define UPDATE_QP_COUNTER_32bit(reg, last_counter, counter) \
1267 uint32_t current_counter = rd32(hw, reg); \
1268 if (current_counter < last_counter) \
1269 current_counter += 0x100000000LL; \
1270 if (!hw->offset_loaded) \
1271 last_counter = current_counter; \
1272 counter = current_counter - last_counter; \
1273 counter &= 0xFFFFFFFFLL; \
1276 #define UPDATE_QP_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \
1278 uint64_t current_counter_lsb = rd32(hw, reg_lsb); \
1279 uint64_t current_counter_msb = rd32(hw, reg_msb); \
1280 uint64_t current_counter = (current_counter_msb << 32) | \
1281 current_counter_lsb; \
1282 if (current_counter < last_counter) \
1283 current_counter += 0x1000000000LL; \
1284 if (!hw->offset_loaded) \
1285 last_counter = current_counter; \
1286 counter = current_counter - last_counter; \
1287 counter &= 0xFFFFFFFFFLL; \
1291 ngbe_read_stats_registers(struct ngbe_hw *hw,
1292 struct ngbe_hw_stats *hw_stats)
1297 for (i = 0; i < hw->nb_rx_queues; i++) {
1298 UPDATE_QP_COUNTER_32bit(NGBE_QPRXPKT(i),
1299 hw->qp_last[i].rx_qp_packets,
1300 hw_stats->qp[i].rx_qp_packets);
1301 UPDATE_QP_COUNTER_36bit(NGBE_QPRXOCTL(i), NGBE_QPRXOCTH(i),
1302 hw->qp_last[i].rx_qp_bytes,
1303 hw_stats->qp[i].rx_qp_bytes);
1304 UPDATE_QP_COUNTER_32bit(NGBE_QPRXMPKT(i),
1305 hw->qp_last[i].rx_qp_mc_packets,
1306 hw_stats->qp[i].rx_qp_mc_packets);
1307 UPDATE_QP_COUNTER_32bit(NGBE_QPRXBPKT(i),
1308 hw->qp_last[i].rx_qp_bc_packets,
1309 hw_stats->qp[i].rx_qp_bc_packets);
1312 for (i = 0; i < hw->nb_tx_queues; i++) {
1313 UPDATE_QP_COUNTER_32bit(NGBE_QPTXPKT(i),
1314 hw->qp_last[i].tx_qp_packets,
1315 hw_stats->qp[i].tx_qp_packets);
1316 UPDATE_QP_COUNTER_36bit(NGBE_QPTXOCTL(i), NGBE_QPTXOCTH(i),
1317 hw->qp_last[i].tx_qp_bytes,
1318 hw_stats->qp[i].tx_qp_bytes);
1319 UPDATE_QP_COUNTER_32bit(NGBE_QPTXMPKT(i),
1320 hw->qp_last[i].tx_qp_mc_packets,
1321 hw_stats->qp[i].tx_qp_mc_packets);
1322 UPDATE_QP_COUNTER_32bit(NGBE_QPTXBPKT(i),
1323 hw->qp_last[i].tx_qp_bc_packets,
1324 hw_stats->qp[i].tx_qp_bc_packets);
1328 hw_stats->rx_up_dropped += rd32(hw, NGBE_PBRXMISS);
1329 hw_stats->rdb_pkt_cnt += rd32(hw, NGBE_PBRXPKT);
1330 hw_stats->rdb_repli_cnt += rd32(hw, NGBE_PBRXREP);
1331 hw_stats->rdb_drp_cnt += rd32(hw, NGBE_PBRXDROP);
1332 hw_stats->tx_xoff_packets += rd32(hw, NGBE_PBTXLNKXOFF);
1333 hw_stats->tx_xon_packets += rd32(hw, NGBE_PBTXLNKXON);
1335 hw_stats->rx_xon_packets += rd32(hw, NGBE_PBRXLNKXON);
1336 hw_stats->rx_xoff_packets += rd32(hw, NGBE_PBRXLNKXOFF);
1339 hw_stats->rx_drop_packets += rd32(hw, NGBE_DMARXDROP);
1340 hw_stats->tx_drop_packets += rd32(hw, NGBE_DMATXDROP);
1341 hw_stats->rx_dma_drop += rd32(hw, NGBE_DMARXDROP);
1342 hw_stats->tx_secdrp_packets += rd32(hw, NGBE_DMATXSECDROP);
1343 hw_stats->rx_packets += rd32(hw, NGBE_DMARXPKT);
1344 hw_stats->tx_packets += rd32(hw, NGBE_DMATXPKT);
1345 hw_stats->rx_bytes += rd64(hw, NGBE_DMARXOCTL);
1346 hw_stats->tx_bytes += rd64(hw, NGBE_DMATXOCTL);
1349 hw_stats->rx_crc_errors += rd64(hw, NGBE_MACRXERRCRCL);
1350 hw_stats->rx_multicast_packets += rd64(hw, NGBE_MACRXMPKTL);
1351 hw_stats->tx_multicast_packets += rd64(hw, NGBE_MACTXMPKTL);
1353 hw_stats->rx_total_packets += rd64(hw, NGBE_MACRXPKTL);
1354 hw_stats->tx_total_packets += rd64(hw, NGBE_MACTXPKTL);
1355 hw_stats->rx_total_bytes += rd64(hw, NGBE_MACRXGBOCTL);
1357 hw_stats->rx_broadcast_packets += rd64(hw, NGBE_MACRXOCTL);
1358 hw_stats->tx_broadcast_packets += rd32(hw, NGBE_MACTXOCTL);
1360 hw_stats->rx_size_64_packets += rd64(hw, NGBE_MACRX1TO64L);
1361 hw_stats->rx_size_65_to_127_packets += rd64(hw, NGBE_MACRX65TO127L);
1362 hw_stats->rx_size_128_to_255_packets += rd64(hw, NGBE_MACRX128TO255L);
1363 hw_stats->rx_size_256_to_511_packets += rd64(hw, NGBE_MACRX256TO511L);
1364 hw_stats->rx_size_512_to_1023_packets +=
1365 rd64(hw, NGBE_MACRX512TO1023L);
1366 hw_stats->rx_size_1024_to_max_packets +=
1367 rd64(hw, NGBE_MACRX1024TOMAXL);
1368 hw_stats->tx_size_64_packets += rd64(hw, NGBE_MACTX1TO64L);
1369 hw_stats->tx_size_65_to_127_packets += rd64(hw, NGBE_MACTX65TO127L);
1370 hw_stats->tx_size_128_to_255_packets += rd64(hw, NGBE_MACTX128TO255L);
1371 hw_stats->tx_size_256_to_511_packets += rd64(hw, NGBE_MACTX256TO511L);
1372 hw_stats->tx_size_512_to_1023_packets +=
1373 rd64(hw, NGBE_MACTX512TO1023L);
1374 hw_stats->tx_size_1024_to_max_packets +=
1375 rd64(hw, NGBE_MACTX1024TOMAXL);
1377 hw_stats->rx_undersize_errors += rd64(hw, NGBE_MACRXERRLENL);
1378 hw_stats->rx_oversize_errors += rd32(hw, NGBE_MACRXOVERSIZE);
1379 hw_stats->rx_jabber_errors += rd32(hw, NGBE_MACRXJABBER);
1382 hw_stats->mng_bmc2host_packets = rd32(hw, NGBE_MNGBMC2OS);
1383 hw_stats->mng_host2bmc_packets = rd32(hw, NGBE_MNGOS2BMC);
1384 hw_stats->rx_management_packets = rd32(hw, NGBE_DMARXMNG);
1385 hw_stats->tx_management_packets = rd32(hw, NGBE_DMATXMNG);
1388 hw_stats->tx_macsec_pkts_untagged += rd32(hw, NGBE_LSECTX_UTPKT);
1389 hw_stats->tx_macsec_pkts_encrypted +=
1390 rd32(hw, NGBE_LSECTX_ENCPKT);
1391 hw_stats->tx_macsec_pkts_protected +=
1392 rd32(hw, NGBE_LSECTX_PROTPKT);
1393 hw_stats->tx_macsec_octets_encrypted +=
1394 rd32(hw, NGBE_LSECTX_ENCOCT);
1395 hw_stats->tx_macsec_octets_protected +=
1396 rd32(hw, NGBE_LSECTX_PROTOCT);
1397 hw_stats->rx_macsec_pkts_untagged += rd32(hw, NGBE_LSECRX_UTPKT);
1398 hw_stats->rx_macsec_pkts_badtag += rd32(hw, NGBE_LSECRX_BTPKT);
1399 hw_stats->rx_macsec_pkts_nosci += rd32(hw, NGBE_LSECRX_NOSCIPKT);
1400 hw_stats->rx_macsec_pkts_unknownsci += rd32(hw, NGBE_LSECRX_UNSCIPKT);
1401 hw_stats->rx_macsec_octets_decrypted += rd32(hw, NGBE_LSECRX_DECOCT);
1402 hw_stats->rx_macsec_octets_validated += rd32(hw, NGBE_LSECRX_VLDOCT);
1403 hw_stats->rx_macsec_sc_pkts_unchecked +=
1404 rd32(hw, NGBE_LSECRX_UNCHKPKT);
1405 hw_stats->rx_macsec_sc_pkts_delayed += rd32(hw, NGBE_LSECRX_DLYPKT);
1406 hw_stats->rx_macsec_sc_pkts_late += rd32(hw, NGBE_LSECRX_LATEPKT);
1407 for (i = 0; i < 2; i++) {
1408 hw_stats->rx_macsec_sa_pkts_ok +=
1409 rd32(hw, NGBE_LSECRX_OKPKT(i));
1410 hw_stats->rx_macsec_sa_pkts_invalid +=
1411 rd32(hw, NGBE_LSECRX_INVPKT(i));
1412 hw_stats->rx_macsec_sa_pkts_notvalid +=
1413 rd32(hw, NGBE_LSECRX_BADPKT(i));
1415 for (i = 0; i < 4; i++) {
1416 hw_stats->rx_macsec_sa_pkts_unusedsa +=
1417 rd32(hw, NGBE_LSECRX_INVSAPKT(i));
1418 hw_stats->rx_macsec_sa_pkts_notusingsa +=
1419 rd32(hw, NGBE_LSECRX_BADSAPKT(i));
1421 hw_stats->rx_total_missed_packets =
1422 hw_stats->rx_up_dropped;
1426 ngbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1428 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1429 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1430 struct ngbe_stat_mappings *stat_mappings =
1431 NGBE_DEV_STAT_MAPPINGS(dev);
1434 ngbe_read_stats_registers(hw, hw_stats);
1439 /* Fill out the rte_eth_stats statistics structure */
1440 stats->ipackets = hw_stats->rx_packets;
1441 stats->ibytes = hw_stats->rx_bytes;
1442 stats->opackets = hw_stats->tx_packets;
1443 stats->obytes = hw_stats->tx_bytes;
1445 memset(&stats->q_ipackets, 0, sizeof(stats->q_ipackets));
1446 memset(&stats->q_opackets, 0, sizeof(stats->q_opackets));
1447 memset(&stats->q_ibytes, 0, sizeof(stats->q_ibytes));
1448 memset(&stats->q_obytes, 0, sizeof(stats->q_obytes));
1449 memset(&stats->q_errors, 0, sizeof(stats->q_errors));
1450 for (i = 0; i < NGBE_MAX_QP; i++) {
1451 uint32_t n = i / NB_QMAP_FIELDS_PER_QSM_REG;
1452 uint32_t offset = (i % NB_QMAP_FIELDS_PER_QSM_REG) * 8;
1455 q_map = (stat_mappings->rqsm[n] >> offset)
1456 & QMAP_FIELD_RESERVED_BITS_MASK;
1457 j = (q_map < RTE_ETHDEV_QUEUE_STAT_CNTRS
1458 ? q_map : q_map % RTE_ETHDEV_QUEUE_STAT_CNTRS);
1459 stats->q_ipackets[j] += hw_stats->qp[i].rx_qp_packets;
1460 stats->q_ibytes[j] += hw_stats->qp[i].rx_qp_bytes;
1462 q_map = (stat_mappings->tqsm[n] >> offset)
1463 & QMAP_FIELD_RESERVED_BITS_MASK;
1464 j = (q_map < RTE_ETHDEV_QUEUE_STAT_CNTRS
1465 ? q_map : q_map % RTE_ETHDEV_QUEUE_STAT_CNTRS);
1466 stats->q_opackets[j] += hw_stats->qp[i].tx_qp_packets;
1467 stats->q_obytes[j] += hw_stats->qp[i].tx_qp_bytes;
1471 stats->imissed = hw_stats->rx_total_missed_packets +
1472 hw_stats->rx_dma_drop;
1473 stats->ierrors = hw_stats->rx_crc_errors +
1474 hw_stats->rx_mac_short_packet_dropped +
1475 hw_stats->rx_length_errors +
1476 hw_stats->rx_undersize_errors +
1477 hw_stats->rx_oversize_errors +
1478 hw_stats->rx_illegal_byte_errors +
1479 hw_stats->rx_error_bytes +
1480 hw_stats->rx_fragment_errors;
1488 ngbe_dev_stats_reset(struct rte_eth_dev *dev)
1490 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1491 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1493 /* HW registers are cleared on read */
1494 hw->offset_loaded = 0;
1495 ngbe_dev_stats_get(dev, NULL);
1496 hw->offset_loaded = 1;
1498 /* Reset software totals */
1499 memset(hw_stats, 0, sizeof(*hw_stats));
1504 /* This function calculates the number of xstats based on the current config */
1506 ngbe_xstats_calc_num(struct rte_eth_dev *dev)
1508 int nb_queues = max(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
1509 return NGBE_NB_HW_STATS +
1510 NGBE_NB_QP_STATS * nb_queues;
1514 ngbe_get_name_by_id(uint32_t id, char *name, uint32_t size)
1518 /* Extended stats from ngbe_hw_stats */
1519 if (id < NGBE_NB_HW_STATS) {
1520 snprintf(name, size, "[hw]%s",
1521 rte_ngbe_stats_strings[id].name);
1524 id -= NGBE_NB_HW_STATS;
1527 if (id < NGBE_NB_QP_STATS * NGBE_MAX_QP) {
1528 nb = id / NGBE_NB_QP_STATS;
1529 st = id % NGBE_NB_QP_STATS;
1530 snprintf(name, size, "[q%u]%s", nb,
1531 rte_ngbe_qp_strings[st].name);
1534 id -= NGBE_NB_QP_STATS * NGBE_MAX_QP;
1536 return -(int)(id + 1);
1540 ngbe_get_offset_by_id(uint32_t id, uint32_t *offset)
1544 /* Extended stats from ngbe_hw_stats */
1545 if (id < NGBE_NB_HW_STATS) {
1546 *offset = rte_ngbe_stats_strings[id].offset;
1549 id -= NGBE_NB_HW_STATS;
1552 if (id < NGBE_NB_QP_STATS * NGBE_MAX_QP) {
1553 nb = id / NGBE_NB_QP_STATS;
1554 st = id % NGBE_NB_QP_STATS;
1555 *offset = rte_ngbe_qp_strings[st].offset +
1556 nb * (NGBE_NB_QP_STATS * sizeof(uint64_t));
1563 static int ngbe_dev_xstats_get_names(struct rte_eth_dev *dev,
1564 struct rte_eth_xstat_name *xstats_names, unsigned int limit)
1566 unsigned int i, count;
1568 count = ngbe_xstats_calc_num(dev);
1569 if (xstats_names == NULL)
1572 /* Note: limit >= cnt_stats checked upstream
1573 * in rte_eth_xstats_names()
1575 limit = min(limit, count);
1577 /* Extended stats from ngbe_hw_stats */
1578 for (i = 0; i < limit; i++) {
1579 if (ngbe_get_name_by_id(i, xstats_names[i].name,
1580 sizeof(xstats_names[i].name))) {
1581 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1589 static int ngbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
1590 const uint64_t *ids,
1591 struct rte_eth_xstat_name *xstats_names,
1597 return ngbe_dev_xstats_get_names(dev, xstats_names, limit);
1599 for (i = 0; i < limit; i++) {
1600 if (ngbe_get_name_by_id(ids[i], xstats_names[i].name,
1601 sizeof(xstats_names[i].name))) {
1602 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1611 ngbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1614 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1615 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1616 unsigned int i, count;
1618 ngbe_read_stats_registers(hw, hw_stats);
1620 /* If this is a reset xstats is NULL, and we have cleared the
1621 * registers by reading them.
1623 count = ngbe_xstats_calc_num(dev);
1627 limit = min(limit, ngbe_xstats_calc_num(dev));
1629 /* Extended stats from ngbe_hw_stats */
1630 for (i = 0; i < limit; i++) {
1631 uint32_t offset = 0;
1633 if (ngbe_get_offset_by_id(i, &offset)) {
1634 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1637 xstats[i].value = *(uint64_t *)(((char *)hw_stats) + offset);
1645 ngbe_dev_xstats_get_(struct rte_eth_dev *dev, uint64_t *values,
1648 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1649 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1650 unsigned int i, count;
1652 ngbe_read_stats_registers(hw, hw_stats);
1654 /* If this is a reset xstats is NULL, and we have cleared the
1655 * registers by reading them.
1657 count = ngbe_xstats_calc_num(dev);
1661 limit = min(limit, ngbe_xstats_calc_num(dev));
1663 /* Extended stats from ngbe_hw_stats */
1664 for (i = 0; i < limit; i++) {
1667 if (ngbe_get_offset_by_id(i, &offset)) {
1668 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1671 values[i] = *(uint64_t *)(((char *)hw_stats) + offset);
1678 ngbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1679 uint64_t *values, unsigned int limit)
1681 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1685 return ngbe_dev_xstats_get_(dev, values, limit);
1687 for (i = 0; i < limit; i++) {
1690 if (ngbe_get_offset_by_id(ids[i], &offset)) {
1691 PMD_INIT_LOG(WARNING, "id value %d isn't valid", i);
1694 values[i] = *(uint64_t *)(((char *)hw_stats) + offset);
1701 ngbe_dev_xstats_reset(struct rte_eth_dev *dev)
1703 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1704 struct ngbe_hw_stats *hw_stats = NGBE_DEV_STATS(dev);
1706 /* HW registers are cleared on read */
1707 hw->offset_loaded = 0;
1708 ngbe_read_stats_registers(hw, hw_stats);
1709 hw->offset_loaded = 1;
1711 /* Reset software totals */
1712 memset(hw_stats, 0, sizeof(*hw_stats));
1718 ngbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
1720 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1723 ret = snprintf(fw_version, fw_size, "0x%08x", hw->eeprom_id);
1728 ret += 1; /* add the size of '\0' */
1729 if (fw_size < (size_t)ret)
1736 ngbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1738 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1739 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1741 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
1742 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
1743 dev_info->min_rx_bufsize = 1024;
1744 dev_info->max_rx_pktlen = 15872;
1745 dev_info->max_mac_addrs = hw->mac.num_rar_entries;
1746 dev_info->max_hash_mac_addrs = NGBE_VMDQ_NUM_UC_MAC;
1747 dev_info->max_vfs = pci_dev->max_vfs;
1748 dev_info->rx_queue_offload_capa = ngbe_get_rx_queue_offloads(dev);
1749 dev_info->rx_offload_capa = (ngbe_get_rx_port_offloads(dev) |
1750 dev_info->rx_queue_offload_capa);
1751 dev_info->tx_queue_offload_capa = 0;
1752 dev_info->tx_offload_capa = ngbe_get_tx_port_offloads(dev);
1754 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1756 .pthresh = NGBE_DEFAULT_RX_PTHRESH,
1757 .hthresh = NGBE_DEFAULT_RX_HTHRESH,
1758 .wthresh = NGBE_DEFAULT_RX_WTHRESH,
1760 .rx_free_thresh = NGBE_DEFAULT_RX_FREE_THRESH,
1765 dev_info->default_txconf = (struct rte_eth_txconf) {
1767 .pthresh = NGBE_DEFAULT_TX_PTHRESH,
1768 .hthresh = NGBE_DEFAULT_TX_HTHRESH,
1769 .wthresh = NGBE_DEFAULT_TX_WTHRESH,
1771 .tx_free_thresh = NGBE_DEFAULT_TX_FREE_THRESH,
1775 dev_info->rx_desc_lim = rx_desc_lim;
1776 dev_info->tx_desc_lim = tx_desc_lim;
1778 dev_info->hash_key_size = NGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
1779 dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
1780 dev_info->flow_type_rss_offloads = NGBE_RSS_OFFLOAD_ALL;
1782 dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_100M |
1783 RTE_ETH_LINK_SPEED_10M;
1785 /* Driver-preferred Rx/Tx parameters */
1786 dev_info->default_rxportconf.burst_size = 32;
1787 dev_info->default_txportconf.burst_size = 32;
1788 dev_info->default_rxportconf.nb_queues = 1;
1789 dev_info->default_txportconf.nb_queues = 1;
1790 dev_info->default_rxportconf.ring_size = 256;
1791 dev_info->default_txportconf.ring_size = 256;
1797 ngbe_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1799 if (dev->rx_pkt_burst == ngbe_recv_pkts ||
1800 dev->rx_pkt_burst == ngbe_recv_pkts_sc_single_alloc ||
1801 dev->rx_pkt_burst == ngbe_recv_pkts_sc_bulk_alloc ||
1802 dev->rx_pkt_burst == ngbe_recv_pkts_bulk_alloc)
1803 return ngbe_get_supported_ptypes();
1809 ngbe_dev_setup_link_alarm_handler(void *param)
1811 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1812 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1813 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1815 bool autoneg = false;
1817 speed = hw->phy.autoneg_advertised;
1819 hw->mac.get_link_capabilities(hw, &speed, &autoneg);
1821 hw->mac.setup_link(hw, speed, true);
1823 intr->flags &= ~NGBE_FLAG_NEED_LINK_CONFIG;
1826 /* return 0 means link status changed, -1 means not changed */
1828 ngbe_dev_link_update_share(struct rte_eth_dev *dev,
1829 int wait_to_complete)
1831 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1832 struct rte_eth_link link;
1833 u32 link_speed = NGBE_LINK_SPEED_UNKNOWN;
1835 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1840 memset(&link, 0, sizeof(link));
1841 link.link_status = RTE_ETH_LINK_DOWN;
1842 link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1843 link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1844 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
1845 ~RTE_ETH_LINK_SPEED_AUTONEG);
1847 hw->mac.get_link_status = true;
1849 if (intr->flags & NGBE_FLAG_NEED_LINK_CONFIG)
1850 return rte_eth_linkstatus_set(dev, &link);
1852 /* check if it needs to wait to complete, if lsc interrupt is enabled */
1853 if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
1856 err = hw->mac.check_link(hw, &link_speed, &link_up, wait);
1858 link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1859 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1860 return rte_eth_linkstatus_set(dev, &link);
1864 if (hw->phy.media_type == ngbe_media_type_fiber &&
1865 hw->phy.type != ngbe_phy_mvl_sfi) {
1866 intr->flags |= NGBE_FLAG_NEED_LINK_CONFIG;
1867 rte_eal_alarm_set(10,
1868 ngbe_dev_setup_link_alarm_handler, dev);
1871 return rte_eth_linkstatus_set(dev, &link);
1874 intr->flags &= ~NGBE_FLAG_NEED_LINK_CONFIG;
1875 link.link_status = RTE_ETH_LINK_UP;
1876 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1878 switch (link_speed) {
1880 case NGBE_LINK_SPEED_UNKNOWN:
1881 link.link_speed = RTE_ETH_SPEED_NUM_NONE;
1884 case NGBE_LINK_SPEED_10M_FULL:
1885 link.link_speed = RTE_ETH_SPEED_NUM_10M;
1889 case NGBE_LINK_SPEED_100M_FULL:
1890 link.link_speed = RTE_ETH_SPEED_NUM_100M;
1894 case NGBE_LINK_SPEED_1GB_FULL:
1895 link.link_speed = RTE_ETH_SPEED_NUM_1G;
1901 wr32m(hw, NGBE_LAN_SPEED, NGBE_LAN_SPEED_MASK, lan_speed);
1902 if (link_speed & (NGBE_LINK_SPEED_1GB_FULL |
1903 NGBE_LINK_SPEED_100M_FULL |
1904 NGBE_LINK_SPEED_10M_FULL)) {
1905 wr32m(hw, NGBE_MACTXCFG, NGBE_MACTXCFG_SPEED_MASK,
1906 NGBE_MACTXCFG_SPEED_1G | NGBE_MACTXCFG_TE);
1910 return rte_eth_linkstatus_set(dev, &link);
1914 ngbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1916 return ngbe_dev_link_update_share(dev, wait_to_complete);
1920 ngbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
1922 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1925 fctrl = rd32(hw, NGBE_PSRCTL);
1926 fctrl |= (NGBE_PSRCTL_UCP | NGBE_PSRCTL_MCP);
1927 wr32(hw, NGBE_PSRCTL, fctrl);
1933 ngbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
1935 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1938 fctrl = rd32(hw, NGBE_PSRCTL);
1939 fctrl &= (~NGBE_PSRCTL_UCP);
1940 if (dev->data->all_multicast == 1)
1941 fctrl |= NGBE_PSRCTL_MCP;
1943 fctrl &= (~NGBE_PSRCTL_MCP);
1944 wr32(hw, NGBE_PSRCTL, fctrl);
1950 ngbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
1952 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1955 fctrl = rd32(hw, NGBE_PSRCTL);
1956 fctrl |= NGBE_PSRCTL_MCP;
1957 wr32(hw, NGBE_PSRCTL, fctrl);
1963 ngbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
1965 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1968 if (dev->data->promiscuous == 1)
1969 return 0; /* must remain in all_multicast mode */
1971 fctrl = rd32(hw, NGBE_PSRCTL);
1972 fctrl &= (~NGBE_PSRCTL_MCP);
1973 wr32(hw, NGBE_PSRCTL, fctrl);
1979 * It clears the interrupt causes and enables the interrupt.
1980 * It will be called once only during NIC initialized.
1983 * Pointer to struct rte_eth_dev.
1985 * Enable or Disable.
1988 * - On success, zero.
1989 * - On failure, a negative value.
1992 ngbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
1994 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
1996 ngbe_dev_link_status_print(dev);
1998 intr->mask_misc |= NGBE_ICRMISC_PHY;
1999 intr->mask_misc |= NGBE_ICRMISC_GPIO;
2001 intr->mask_misc &= ~NGBE_ICRMISC_PHY;
2002 intr->mask_misc &= ~NGBE_ICRMISC_GPIO;
2009 * It clears the interrupt causes and enables the interrupt.
2010 * It will be called once only during NIC initialized.
2013 * Pointer to struct rte_eth_dev.
2016 * - On success, zero.
2017 * - On failure, a negative value.
2020 ngbe_dev_misc_interrupt_setup(struct rte_eth_dev *dev)
2022 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2025 mask = NGBE_ICR_MASK;
2026 mask &= (1ULL << NGBE_MISC_VEC_ID);
2028 intr->mask_misc |= NGBE_ICRMISC_GPIO;
2034 * It clears the interrupt causes and enables the interrupt.
2035 * It will be called once only during NIC initialized.
2038 * Pointer to struct rte_eth_dev.
2041 * - On success, zero.
2042 * - On failure, a negative value.
2045 ngbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
2047 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2050 mask = NGBE_ICR_MASK;
2051 mask &= ~((1ULL << NGBE_RX_VEC_START) - 1);
2058 * It clears the interrupt causes and enables the interrupt.
2059 * It will be called once only during NIC initialized.
2062 * Pointer to struct rte_eth_dev.
2065 * - On success, zero.
2066 * - On failure, a negative value.
2069 ngbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev)
2071 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2073 intr->mask_misc |= NGBE_ICRMISC_LNKSEC;
2079 * It reads ICR and sets flag for the link_update.
2082 * Pointer to struct rte_eth_dev.
2085 * - On success, zero.
2086 * - On failure, a negative value.
2089 ngbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
2092 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2093 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2095 /* read-on-clear nic registers here */
2096 eicr = ((u32 *)hw->isb_mem)[NGBE_ISB_MISC];
2097 PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
2101 /* set flag for async link update */
2102 if (eicr & NGBE_ICRMISC_PHY)
2103 intr->flags |= NGBE_FLAG_NEED_LINK_UPDATE;
2105 if (eicr & NGBE_ICRMISC_VFMBX)
2106 intr->flags |= NGBE_FLAG_MAILBOX;
2108 if (eicr & NGBE_ICRMISC_LNKSEC)
2109 intr->flags |= NGBE_FLAG_MACSEC;
2111 if (eicr & NGBE_ICRMISC_GPIO)
2112 intr->flags |= NGBE_FLAG_NEED_LINK_UPDATE;
2114 ((u32 *)hw->isb_mem)[NGBE_ISB_MISC] = 0;
2120 * It gets and then prints the link status.
2123 * Pointer to struct rte_eth_dev.
2126 * - On success, zero.
2127 * - On failure, a negative value.
2130 ngbe_dev_link_status_print(struct rte_eth_dev *dev)
2132 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2133 struct rte_eth_link link;
2135 rte_eth_linkstatus_get(dev, &link);
2137 if (link.link_status == RTE_ETH_LINK_UP) {
2138 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
2139 (int)(dev->data->port_id),
2140 (unsigned int)link.link_speed,
2141 link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
2142 "full-duplex" : "half-duplex");
2144 PMD_INIT_LOG(INFO, " Port %d: Link Down",
2145 (int)(dev->data->port_id));
2147 PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
2148 pci_dev->addr.domain,
2150 pci_dev->addr.devid,
2151 pci_dev->addr.function);
2155 * It executes link_update after knowing an interrupt occurred.
2158 * Pointer to struct rte_eth_dev.
2161 * - On success, zero.
2162 * - On failure, a negative value.
2165 ngbe_dev_interrupt_action(struct rte_eth_dev *dev)
2167 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
2169 PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
2171 if (intr->flags & NGBE_FLAG_MAILBOX) {
2172 ngbe_pf_mbx_process(dev);
2173 intr->flags &= ~NGBE_FLAG_MAILBOX;
2176 if (intr->flags & NGBE_FLAG_NEED_LINK_UPDATE) {
2177 struct rte_eth_link link;
2179 /*get the link status before link update, for predicting later*/
2180 rte_eth_linkstatus_get(dev, &link);
2182 ngbe_dev_link_update(dev, 0);
2183 intr->flags &= ~NGBE_FLAG_NEED_LINK_UPDATE;
2184 ngbe_dev_link_status_print(dev);
2185 if (dev->data->dev_link.link_speed != link.link_speed)
2186 rte_eth_dev_callback_process(dev,
2187 RTE_ETH_EVENT_INTR_LSC, NULL);
2190 PMD_DRV_LOG(DEBUG, "enable intr immediately");
2191 ngbe_enable_intr(dev);
2197 * Interrupt handler triggered by NIC for handling
2198 * specific interrupt.
2201 * The address of parameter (struct rte_eth_dev *) registered before.
2204 ngbe_dev_interrupt_handler(void *param)
2206 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2208 ngbe_dev_interrupt_get_status(dev);
2209 ngbe_dev_interrupt_action(dev);
2213 ngbe_dev_led_on(struct rte_eth_dev *dev)
2215 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2216 return hw->mac.led_on(hw, 0) == 0 ? 0 : -ENOTSUP;
2220 ngbe_dev_led_off(struct rte_eth_dev *dev)
2222 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2223 return hw->mac.led_off(hw, 0) == 0 ? 0 : -ENOTSUP;
2227 ngbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2229 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2235 fc_conf->pause_time = hw->fc.pause_time;
2236 fc_conf->high_water = hw->fc.high_water;
2237 fc_conf->low_water = hw->fc.low_water;
2238 fc_conf->send_xon = hw->fc.send_xon;
2239 fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
2242 * Return rx_pause status according to actual setting of
2245 mflcn_reg = rd32(hw, NGBE_RXFCCFG);
2246 if (mflcn_reg & NGBE_RXFCCFG_FC)
2252 * Return tx_pause status according to actual setting of
2255 fccfg_reg = rd32(hw, NGBE_TXFCCFG);
2256 if (fccfg_reg & NGBE_TXFCCFG_FC)
2261 if (rx_pause && tx_pause)
2262 fc_conf->mode = RTE_ETH_FC_FULL;
2264 fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
2266 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
2268 fc_conf->mode = RTE_ETH_FC_NONE;
2274 ngbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2276 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2278 uint32_t rx_buf_size;
2279 uint32_t max_high_water;
2280 enum ngbe_fc_mode rte_fcmode_2_ngbe_fcmode[] = {
2287 PMD_INIT_FUNC_TRACE();
2289 rx_buf_size = rd32(hw, NGBE_PBRXSIZE);
2290 PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
2293 * At least reserve one Ethernet frame for watermark
2294 * high_water/low_water in kilo bytes for ngbe
2296 max_high_water = (rx_buf_size - RTE_ETHER_MAX_LEN) >> 10;
2297 if (fc_conf->high_water > max_high_water ||
2298 fc_conf->high_water < fc_conf->low_water) {
2299 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
2300 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
2304 hw->fc.requested_mode = rte_fcmode_2_ngbe_fcmode[fc_conf->mode];
2305 hw->fc.pause_time = fc_conf->pause_time;
2306 hw->fc.high_water = fc_conf->high_water;
2307 hw->fc.low_water = fc_conf->low_water;
2308 hw->fc.send_xon = fc_conf->send_xon;
2309 hw->fc.disable_fc_autoneg = !fc_conf->autoneg;
2311 err = hw->mac.fc_enable(hw);
2313 /* Not negotiated is not an error case */
2314 if (err == 0 || err == NGBE_ERR_FC_NOT_NEGOTIATED) {
2315 wr32m(hw, NGBE_MACRXFLT, NGBE_MACRXFLT_CTL_MASK,
2316 (fc_conf->mac_ctrl_frame_fwd
2317 ? NGBE_MACRXFLT_CTL_NOPS : NGBE_MACRXFLT_CTL_DROP));
2323 PMD_INIT_LOG(ERR, "ngbe_fc_enable = 0x%x", err);
2328 ngbe_dev_rss_reta_update(struct rte_eth_dev *dev,
2329 struct rte_eth_rss_reta_entry64 *reta_conf,
2334 uint16_t idx, shift;
2335 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2336 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2338 PMD_INIT_FUNC_TRACE();
2341 PMD_DRV_LOG(ERR, "RSS reta update is not supported on this "
2346 if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
2347 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2348 "(%d) doesn't match the number hardware can supported "
2349 "(%d)", reta_size, RTE_ETH_RSS_RETA_SIZE_128);
2353 for (i = 0; i < reta_size; i += 4) {
2354 idx = i / RTE_ETH_RETA_GROUP_SIZE;
2355 shift = i % RTE_ETH_RETA_GROUP_SIZE;
2356 mask = (uint8_t)RS64(reta_conf[idx].mask, shift, 0xF);
2360 reta = rd32a(hw, NGBE_REG_RSSTBL, i >> 2);
2361 for (j = 0; j < 4; j++) {
2362 if (RS8(mask, j, 0x1)) {
2363 reta &= ~(MS32(8 * j, 0xFF));
2364 reta |= LS32(reta_conf[idx].reta[shift + j],
2368 wr32a(hw, NGBE_REG_RSSTBL, i >> 2, reta);
2370 adapter->rss_reta_updated = 1;
2376 ngbe_dev_rss_reta_query(struct rte_eth_dev *dev,
2377 struct rte_eth_rss_reta_entry64 *reta_conf,
2380 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2383 uint16_t idx, shift;
2385 PMD_INIT_FUNC_TRACE();
2387 if (reta_size != RTE_ETH_RSS_RETA_SIZE_128) {
2388 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2389 "(%d) doesn't match the number hardware can supported "
2390 "(%d)", reta_size, RTE_ETH_RSS_RETA_SIZE_128);
2394 for (i = 0; i < reta_size; i += 4) {
2395 idx = i / RTE_ETH_RETA_GROUP_SIZE;
2396 shift = i % RTE_ETH_RETA_GROUP_SIZE;
2397 mask = (uint8_t)RS64(reta_conf[idx].mask, shift, 0xF);
2401 reta = rd32a(hw, NGBE_REG_RSSTBL, i >> 2);
2402 for (j = 0; j < 4; j++) {
2403 if (RS8(mask, j, 0x1))
2404 reta_conf[idx].reta[shift + j] =
2405 (uint16_t)RS32(reta, 8 * j, 0xFF);
2413 ngbe_add_rar(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
2414 uint32_t index, uint32_t pool)
2416 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2417 uint32_t enable_addr = 1;
2419 return ngbe_set_rar(hw, index, mac_addr->addr_bytes,
2424 ngbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
2426 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2428 ngbe_clear_rar(hw, index);
2432 ngbe_set_default_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
2434 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2436 ngbe_remove_rar(dev, 0);
2437 ngbe_add_rar(dev, addr, 0, pci_dev->max_vfs);
2443 ngbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
2445 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2446 uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + 4;
2447 struct rte_eth_dev_data *dev_data = dev->data;
2449 /* If device is started, refuse mtu that requires the support of
2450 * scattered packets when this feature has not been enabled before.
2452 if (dev_data->dev_started && !dev_data->scattered_rx &&
2453 (frame_size + 2 * RTE_VLAN_HLEN >
2454 dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
2455 PMD_INIT_LOG(ERR, "Stop port first.");
2460 wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
2461 NGBE_FRAME_SIZE_MAX);
2463 wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
2464 NGBE_FRMSZ_MAX(frame_size));
2470 ngbe_uta_vector(struct ngbe_hw *hw, struct rte_ether_addr *uc_addr)
2472 uint32_t vector = 0;
2474 switch (hw->mac.mc_filter_type) {
2475 case 0: /* use bits [47:36] of the address */
2476 vector = ((uc_addr->addr_bytes[4] >> 4) |
2477 (((uint16_t)uc_addr->addr_bytes[5]) << 4));
2479 case 1: /* use bits [46:35] of the address */
2480 vector = ((uc_addr->addr_bytes[4] >> 3) |
2481 (((uint16_t)uc_addr->addr_bytes[5]) << 5));
2483 case 2: /* use bits [45:34] of the address */
2484 vector = ((uc_addr->addr_bytes[4] >> 2) |
2485 (((uint16_t)uc_addr->addr_bytes[5]) << 6));
2487 case 3: /* use bits [43:32] of the address */
2488 vector = ((uc_addr->addr_bytes[4]) |
2489 (((uint16_t)uc_addr->addr_bytes[5]) << 8));
2491 default: /* Invalid mc_filter_type */
2495 /* vector can only be 12-bits or boundary will be exceeded */
2501 ngbe_uc_hash_table_set(struct rte_eth_dev *dev,
2502 struct rte_ether_addr *mac_addr, uint8_t on)
2510 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2511 struct ngbe_uta_info *uta_info = NGBE_DEV_UTA_INFO(dev);
2513 vector = ngbe_uta_vector(hw, mac_addr);
2514 uta_idx = (vector >> 5) & 0x7F;
2515 uta_mask = 0x1UL << (vector & 0x1F);
2517 if (!!on == !!(uta_info->uta_shadow[uta_idx] & uta_mask))
2520 reg_val = rd32(hw, NGBE_UCADDRTBL(uta_idx));
2522 uta_info->uta_in_use++;
2523 reg_val |= uta_mask;
2524 uta_info->uta_shadow[uta_idx] |= uta_mask;
2526 uta_info->uta_in_use--;
2527 reg_val &= ~uta_mask;
2528 uta_info->uta_shadow[uta_idx] &= ~uta_mask;
2531 wr32(hw, NGBE_UCADDRTBL(uta_idx), reg_val);
2533 psrctl = rd32(hw, NGBE_PSRCTL);
2534 if (uta_info->uta_in_use > 0)
2535 psrctl |= NGBE_PSRCTL_UCHFENA;
2537 psrctl &= ~NGBE_PSRCTL_UCHFENA;
2539 psrctl &= ~NGBE_PSRCTL_ADHF12_MASK;
2540 psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
2541 wr32(hw, NGBE_PSRCTL, psrctl);
2547 ngbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
2549 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2550 struct ngbe_uta_info *uta_info = NGBE_DEV_UTA_INFO(dev);
2555 for (i = 0; i < RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
2556 uta_info->uta_shadow[i] = ~0;
2557 wr32(hw, NGBE_UCADDRTBL(i), ~0);
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);
2566 psrctl = rd32(hw, NGBE_PSRCTL);
2568 psrctl |= NGBE_PSRCTL_UCHFENA;
2570 psrctl &= ~NGBE_PSRCTL_UCHFENA;
2572 psrctl &= ~NGBE_PSRCTL_ADHF12_MASK;
2573 psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
2574 wr32(hw, NGBE_PSRCTL, psrctl);
2580 * Set the IVAR registers, mapping interrupt causes to vectors
2582 * pointer to ngbe_hw struct
2584 * 0 for Rx, 1 for Tx, -1 for other causes
2586 * queue to map the corresponding interrupt to
2588 * the vector to map to the corresponding queue
2591 ngbe_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
2592 uint8_t queue, uint8_t msix_vector)
2596 if (direction == -1) {
2598 msix_vector |= NGBE_IVARMISC_VLD;
2600 tmp = rd32(hw, NGBE_IVARMISC);
2601 tmp &= ~(0xFF << idx);
2602 tmp |= (msix_vector << idx);
2603 wr32(hw, NGBE_IVARMISC, tmp);
2605 /* rx or tx causes */
2606 /* Workaround for ICR lost */
2607 idx = ((16 * (queue & 1)) + (8 * direction));
2608 tmp = rd32(hw, NGBE_IVAR(queue >> 1));
2609 tmp &= ~(0xFF << idx);
2610 tmp |= (msix_vector << idx);
2611 wr32(hw, NGBE_IVAR(queue >> 1), tmp);
2616 * Sets up the hardware to properly generate MSI-X interrupts
2618 * board private structure
2621 ngbe_configure_msix(struct rte_eth_dev *dev)
2623 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2624 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2625 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2626 uint32_t queue_id, base = NGBE_MISC_VEC_ID;
2627 uint32_t vec = NGBE_MISC_VEC_ID;
2631 * Won't configure MSI-X register if no mapping is done
2632 * between intr vector and event fd
2633 * but if MSI-X has been enabled already, need to configure
2634 * auto clean, auto mask and throttling.
2636 gpie = rd32(hw, NGBE_GPIE);
2637 if (!rte_intr_dp_is_en(intr_handle) &&
2638 !(gpie & NGBE_GPIE_MSIX))
2641 if (rte_intr_allow_others(intr_handle)) {
2642 base = NGBE_RX_VEC_START;
2646 /* setup GPIE for MSI-X mode */
2647 gpie = rd32(hw, NGBE_GPIE);
2648 gpie |= NGBE_GPIE_MSIX;
2649 wr32(hw, NGBE_GPIE, gpie);
2651 /* Populate the IVAR table and set the ITR values to the
2652 * corresponding register.
2654 if (rte_intr_dp_is_en(intr_handle)) {
2655 for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
2657 /* by default, 1:1 mapping */
2658 ngbe_set_ivar_map(hw, 0, queue_id, vec);
2659 rte_intr_vec_list_index_set(intr_handle,
2661 if (vec < base + rte_intr_nb_efd_get(intr_handle)
2666 ngbe_set_ivar_map(hw, -1, 1, NGBE_MISC_VEC_ID);
2668 wr32(hw, NGBE_ITR(NGBE_MISC_VEC_ID),
2669 NGBE_ITR_IVAL_1G(NGBE_QUEUE_ITR_INTERVAL_DEFAULT)
2674 ngbe_dev_addr_list_itr(__rte_unused struct ngbe_hw *hw,
2675 u8 **mc_addr_ptr, u32 *vmdq)
2680 mc_addr = *mc_addr_ptr;
2681 *mc_addr_ptr = (mc_addr + sizeof(struct rte_ether_addr));
2686 ngbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
2687 struct rte_ether_addr *mc_addr_set,
2688 uint32_t nb_mc_addr)
2690 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2693 mc_addr_list = (u8 *)mc_addr_set;
2694 return hw->mac.update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
2695 ngbe_dev_addr_list_itr, TRUE);
2699 ngbe_read_systime_cyclecounter(struct rte_eth_dev *dev)
2701 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2702 uint64_t systime_cycles;
2704 systime_cycles = (uint64_t)rd32(hw, NGBE_TSTIMEL);
2705 systime_cycles |= (uint64_t)rd32(hw, NGBE_TSTIMEH) << 32;
2707 return systime_cycles;
2711 ngbe_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
2713 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2714 uint64_t rx_tstamp_cycles;
2716 /* TSRXSTMPL stores ns and TSRXSTMPH stores seconds. */
2717 rx_tstamp_cycles = (uint64_t)rd32(hw, NGBE_TSRXSTMPL);
2718 rx_tstamp_cycles |= (uint64_t)rd32(hw, NGBE_TSRXSTMPH) << 32;
2720 return rx_tstamp_cycles;
2724 ngbe_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
2726 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2727 uint64_t tx_tstamp_cycles;
2729 /* TSTXSTMPL stores ns and TSTXSTMPH stores seconds. */
2730 tx_tstamp_cycles = (uint64_t)rd32(hw, NGBE_TSTXSTMPL);
2731 tx_tstamp_cycles |= (uint64_t)rd32(hw, NGBE_TSTXSTMPH) << 32;
2733 return tx_tstamp_cycles;
2737 ngbe_start_timecounters(struct rte_eth_dev *dev)
2739 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2740 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2741 uint32_t incval = 0;
2744 incval = NGBE_INCVAL_1GB;
2745 shift = NGBE_INCVAL_SHIFT_1GB;
2747 wr32(hw, NGBE_TSTIMEINC, NGBE_TSTIMEINC_IV(incval));
2749 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
2750 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
2751 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
2753 adapter->systime_tc.cc_mask = NGBE_CYCLECOUNTER_MASK;
2754 adapter->systime_tc.cc_shift = shift;
2755 adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
2757 adapter->rx_tstamp_tc.cc_mask = NGBE_CYCLECOUNTER_MASK;
2758 adapter->rx_tstamp_tc.cc_shift = shift;
2759 adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
2761 adapter->tx_tstamp_tc.cc_mask = NGBE_CYCLECOUNTER_MASK;
2762 adapter->tx_tstamp_tc.cc_shift = shift;
2763 adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
2767 ngbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
2769 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2771 adapter->systime_tc.nsec += delta;
2772 adapter->rx_tstamp_tc.nsec += delta;
2773 adapter->tx_tstamp_tc.nsec += delta;
2779 ngbe_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
2782 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2784 ns = rte_timespec_to_ns(ts);
2785 /* Set the timecounters to a new value. */
2786 adapter->systime_tc.nsec = ns;
2787 adapter->rx_tstamp_tc.nsec = ns;
2788 adapter->tx_tstamp_tc.nsec = ns;
2794 ngbe_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
2796 uint64_t ns, systime_cycles;
2797 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2799 systime_cycles = ngbe_read_systime_cyclecounter(dev);
2800 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
2801 *ts = rte_ns_to_timespec(ns);
2807 ngbe_timesync_enable(struct rte_eth_dev *dev)
2809 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2812 /* Stop the timesync system time. */
2813 wr32(hw, NGBE_TSTIMEINC, 0x0);
2814 /* Reset the timesync system time value. */
2815 wr32(hw, NGBE_TSTIMEL, 0x0);
2816 wr32(hw, NGBE_TSTIMEH, 0x0);
2818 ngbe_start_timecounters(dev);
2820 /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
2821 wr32(hw, NGBE_ETFLT(NGBE_ETF_ID_1588),
2822 RTE_ETHER_TYPE_1588 | NGBE_ETFLT_ENA | NGBE_ETFLT_1588);
2824 /* Enable timestamping of received PTP packets. */
2825 tsync_ctl = rd32(hw, NGBE_TSRXCTL);
2826 tsync_ctl |= NGBE_TSRXCTL_ENA;
2827 wr32(hw, NGBE_TSRXCTL, tsync_ctl);
2829 /* Enable timestamping of transmitted PTP packets. */
2830 tsync_ctl = rd32(hw, NGBE_TSTXCTL);
2831 tsync_ctl |= NGBE_TSTXCTL_ENA;
2832 wr32(hw, NGBE_TSTXCTL, tsync_ctl);
2840 ngbe_timesync_disable(struct rte_eth_dev *dev)
2842 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2845 /* Disable timestamping of transmitted PTP packets. */
2846 tsync_ctl = rd32(hw, NGBE_TSTXCTL);
2847 tsync_ctl &= ~NGBE_TSTXCTL_ENA;
2848 wr32(hw, NGBE_TSTXCTL, tsync_ctl);
2850 /* Disable timestamping of received PTP packets. */
2851 tsync_ctl = rd32(hw, NGBE_TSRXCTL);
2852 tsync_ctl &= ~NGBE_TSRXCTL_ENA;
2853 wr32(hw, NGBE_TSRXCTL, tsync_ctl);
2855 /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
2856 wr32(hw, NGBE_ETFLT(NGBE_ETF_ID_1588), 0);
2858 /* Stop incrementing the System Time registers. */
2859 wr32(hw, NGBE_TSTIMEINC, 0);
2865 ngbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
2866 struct timespec *timestamp,
2867 uint32_t flags __rte_unused)
2869 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2870 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2871 uint32_t tsync_rxctl;
2872 uint64_t rx_tstamp_cycles;
2875 tsync_rxctl = rd32(hw, NGBE_TSRXCTL);
2876 if ((tsync_rxctl & NGBE_TSRXCTL_VLD) == 0)
2879 rx_tstamp_cycles = ngbe_read_rx_tstamp_cyclecounter(dev);
2880 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
2881 *timestamp = rte_ns_to_timespec(ns);
2887 ngbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
2888 struct timespec *timestamp)
2890 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2891 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
2892 uint32_t tsync_txctl;
2893 uint64_t tx_tstamp_cycles;
2896 tsync_txctl = rd32(hw, NGBE_TSTXCTL);
2897 if ((tsync_txctl & NGBE_TSTXCTL_VLD) == 0)
2900 tx_tstamp_cycles = ngbe_read_tx_tstamp_cyclecounter(dev);
2901 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
2902 *timestamp = rte_ns_to_timespec(ns);
2908 ngbe_get_reg_length(struct rte_eth_dev *dev __rte_unused)
2912 const struct reg_info *reg_group;
2913 const struct reg_info **reg_set = ngbe_regs_others;
2915 while ((reg_group = reg_set[g_ind++]))
2916 count += ngbe_regs_group_count(reg_group);
2922 ngbe_get_regs(struct rte_eth_dev *dev,
2923 struct rte_dev_reg_info *regs)
2925 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2926 uint32_t *data = regs->data;
2929 const struct reg_info *reg_group;
2930 const struct reg_info **reg_set = ngbe_regs_others;
2933 regs->length = ngbe_get_reg_length(dev);
2934 regs->width = sizeof(uint32_t);
2938 /* Support only full register dump */
2939 if (regs->length == 0 ||
2940 regs->length == (uint32_t)ngbe_get_reg_length(dev)) {
2941 regs->version = hw->mac.type << 24 |
2942 hw->revision_id << 16 |
2944 while ((reg_group = reg_set[g_ind++]))
2945 count += ngbe_read_regs_group(dev, &data[count],
2954 ngbe_get_eeprom_length(struct rte_eth_dev *dev)
2956 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2958 /* Return unit is byte count */
2959 return hw->rom.word_size * 2;
2963 ngbe_get_eeprom(struct rte_eth_dev *dev,
2964 struct rte_dev_eeprom_info *in_eeprom)
2966 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2967 struct ngbe_rom_info *eeprom = &hw->rom;
2968 uint16_t *data = in_eeprom->data;
2971 first = in_eeprom->offset >> 1;
2972 length = in_eeprom->length >> 1;
2973 if (first > hw->rom.word_size ||
2974 ((first + length) > hw->rom.word_size))
2977 in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
2979 return eeprom->readw_buffer(hw, first, length, data);
2983 ngbe_set_eeprom(struct rte_eth_dev *dev,
2984 struct rte_dev_eeprom_info *in_eeprom)
2986 struct ngbe_hw *hw = ngbe_dev_hw(dev);
2987 struct ngbe_rom_info *eeprom = &hw->rom;
2988 uint16_t *data = in_eeprom->data;
2991 first = in_eeprom->offset >> 1;
2992 length = in_eeprom->length >> 1;
2993 if (first > hw->rom.word_size ||
2994 ((first + length) > hw->rom.word_size))
2997 in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
2999 return eeprom->writew_buffer(hw, first, length, data);
3002 static const struct eth_dev_ops ngbe_eth_dev_ops = {
3003 .dev_configure = ngbe_dev_configure,
3004 .dev_infos_get = ngbe_dev_info_get,
3005 .dev_start = ngbe_dev_start,
3006 .dev_stop = ngbe_dev_stop,
3007 .dev_close = ngbe_dev_close,
3008 .dev_reset = ngbe_dev_reset,
3009 .promiscuous_enable = ngbe_dev_promiscuous_enable,
3010 .promiscuous_disable = ngbe_dev_promiscuous_disable,
3011 .allmulticast_enable = ngbe_dev_allmulticast_enable,
3012 .allmulticast_disable = ngbe_dev_allmulticast_disable,
3013 .link_update = ngbe_dev_link_update,
3014 .stats_get = ngbe_dev_stats_get,
3015 .xstats_get = ngbe_dev_xstats_get,
3016 .xstats_get_by_id = ngbe_dev_xstats_get_by_id,
3017 .stats_reset = ngbe_dev_stats_reset,
3018 .xstats_reset = ngbe_dev_xstats_reset,
3019 .xstats_get_names = ngbe_dev_xstats_get_names,
3020 .xstats_get_names_by_id = ngbe_dev_xstats_get_names_by_id,
3021 .fw_version_get = ngbe_fw_version_get,
3022 .dev_supported_ptypes_get = ngbe_dev_supported_ptypes_get,
3023 .mtu_set = ngbe_dev_mtu_set,
3024 .vlan_filter_set = ngbe_vlan_filter_set,
3025 .vlan_tpid_set = ngbe_vlan_tpid_set,
3026 .vlan_offload_set = ngbe_vlan_offload_set,
3027 .vlan_strip_queue_set = ngbe_vlan_strip_queue_set,
3028 .rx_queue_start = ngbe_dev_rx_queue_start,
3029 .rx_queue_stop = ngbe_dev_rx_queue_stop,
3030 .tx_queue_start = ngbe_dev_tx_queue_start,
3031 .tx_queue_stop = ngbe_dev_tx_queue_stop,
3032 .rx_queue_setup = ngbe_dev_rx_queue_setup,
3033 .rx_queue_release = ngbe_dev_rx_queue_release,
3034 .tx_queue_setup = ngbe_dev_tx_queue_setup,
3035 .tx_queue_release = ngbe_dev_tx_queue_release,
3036 .dev_led_on = ngbe_dev_led_on,
3037 .dev_led_off = ngbe_dev_led_off,
3038 .flow_ctrl_get = ngbe_flow_ctrl_get,
3039 .flow_ctrl_set = ngbe_flow_ctrl_set,
3040 .mac_addr_add = ngbe_add_rar,
3041 .mac_addr_remove = ngbe_remove_rar,
3042 .mac_addr_set = ngbe_set_default_mac_addr,
3043 .uc_hash_table_set = ngbe_uc_hash_table_set,
3044 .uc_all_hash_table_set = ngbe_uc_all_hash_table_set,
3045 .reta_update = ngbe_dev_rss_reta_update,
3046 .reta_query = ngbe_dev_rss_reta_query,
3047 .rss_hash_update = ngbe_dev_rss_hash_update,
3048 .rss_hash_conf_get = ngbe_dev_rss_hash_conf_get,
3049 .set_mc_addr_list = ngbe_dev_set_mc_addr_list,
3050 .rxq_info_get = ngbe_rxq_info_get,
3051 .txq_info_get = ngbe_txq_info_get,
3052 .rx_burst_mode_get = ngbe_rx_burst_mode_get,
3053 .tx_burst_mode_get = ngbe_tx_burst_mode_get,
3054 .timesync_enable = ngbe_timesync_enable,
3055 .timesync_disable = ngbe_timesync_disable,
3056 .timesync_read_rx_timestamp = ngbe_timesync_read_rx_timestamp,
3057 .timesync_read_tx_timestamp = ngbe_timesync_read_tx_timestamp,
3058 .get_reg = ngbe_get_regs,
3059 .get_eeprom_length = ngbe_get_eeprom_length,
3060 .get_eeprom = ngbe_get_eeprom,
3061 .set_eeprom = ngbe_set_eeprom,
3062 .timesync_adjust_time = ngbe_timesync_adjust_time,
3063 .timesync_read_time = ngbe_timesync_read_time,
3064 .timesync_write_time = ngbe_timesync_write_time,
3065 .tx_done_cleanup = ngbe_dev_tx_done_cleanup,
3068 RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
3069 RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
3070 RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic | vfio-pci");
3072 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_init, init, NOTICE);
3073 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_driver, driver, NOTICE);
3075 #ifdef RTE_ETHDEV_DEBUG_RX
3076 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_rx, rx, DEBUG);
3078 #ifdef RTE_ETHDEV_DEBUG_TX
3079 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_tx, tx, DEBUG);