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"
17 static int ngbe_dev_close(struct rte_eth_dev *dev);
18 static int ngbe_dev_link_update(struct rte_eth_dev *dev,
19 int wait_to_complete);
21 static void ngbe_dev_link_status_print(struct rte_eth_dev *dev);
22 static int ngbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
23 static int ngbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev);
24 static int ngbe_dev_misc_interrupt_setup(struct rte_eth_dev *dev);
25 static int ngbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
26 static void ngbe_dev_interrupt_handler(void *param);
27 static void ngbe_dev_interrupt_delayed_handler(void *param);
28 static void ngbe_configure_msix(struct rte_eth_dev *dev);
31 * The set of PCI devices this driver supports
33 static const struct rte_pci_id pci_id_ngbe_map[] = {
34 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2) },
35 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A2S) },
36 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4) },
37 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A4S) },
38 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2) },
39 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL2S) },
40 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4) },
41 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL4S) },
42 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860NCSI) },
43 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1) },
44 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860A1L) },
45 { RTE_PCI_DEVICE(PCI_VENDOR_ID_WANGXUN, NGBE_DEV_ID_EM_WX1860AL_W) },
46 { .vendor_id = 0, /* sentinel */ },
49 static const struct rte_eth_desc_lim rx_desc_lim = {
50 .nb_max = NGBE_RING_DESC_MAX,
51 .nb_min = NGBE_RING_DESC_MIN,
52 .nb_align = NGBE_RXD_ALIGN,
55 static const struct rte_eth_desc_lim tx_desc_lim = {
56 .nb_max = NGBE_RING_DESC_MAX,
57 .nb_min = NGBE_RING_DESC_MIN,
58 .nb_align = NGBE_TXD_ALIGN,
59 .nb_seg_max = NGBE_TX_MAX_SEG,
60 .nb_mtu_seg_max = NGBE_TX_MAX_SEG,
63 static const struct eth_dev_ops ngbe_eth_dev_ops;
66 ngbe_pf_reset_hw(struct ngbe_hw *hw)
71 status = hw->mac.reset_hw(hw);
73 ctrl_ext = rd32(hw, NGBE_PORTCTL);
74 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
75 ctrl_ext |= NGBE_PORTCTL_RSTDONE;
76 wr32(hw, NGBE_PORTCTL, ctrl_ext);
79 if (status == NGBE_ERR_SFP_NOT_PRESENT)
85 ngbe_enable_intr(struct rte_eth_dev *dev)
87 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
88 struct ngbe_hw *hw = ngbe_dev_hw(dev);
90 wr32(hw, NGBE_IENMISC, intr->mask_misc);
91 wr32(hw, NGBE_IMC(0), intr->mask & BIT_MASK32);
96 ngbe_disable_intr(struct ngbe_hw *hw)
98 PMD_INIT_FUNC_TRACE();
100 wr32(hw, NGBE_IMS(0), NGBE_IMS_MASK);
105 * Ensure that all locks are released before first NVM or PHY access
108 ngbe_swfw_lock_reset(struct ngbe_hw *hw)
113 * These ones are more tricky since they are common to all ports; but
114 * swfw_sync retries last long enough (1s) to be almost sure that if
115 * lock can not be taken it is due to an improper lock of the
118 mask = NGBE_MNGSEM_SWPHY |
121 if (hw->mac.acquire_swfw_sync(hw, mask) < 0)
122 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
124 hw->mac.release_swfw_sync(hw, mask);
128 eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
130 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
131 struct ngbe_hw *hw = ngbe_dev_hw(eth_dev);
132 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
133 const struct rte_memzone *mz;
137 PMD_INIT_FUNC_TRACE();
139 eth_dev->dev_ops = &ngbe_eth_dev_ops;
141 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
144 rte_eth_copy_pci_info(eth_dev, pci_dev);
146 /* Vendor and Device ID need to be set before init of shared code */
147 hw->device_id = pci_dev->id.device_id;
148 hw->vendor_id = pci_dev->id.vendor_id;
149 hw->sub_system_id = pci_dev->id.subsystem_device_id;
150 ngbe_map_device_id(hw);
151 hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
153 /* Reserve memory for interrupt status block */
154 mz = rte_eth_dma_zone_reserve(eth_dev, "ngbe_driver", -1,
155 NGBE_ISB_SIZE, NGBE_ALIGN, SOCKET_ID_ANY);
159 hw->isb_dma = TMZ_PADDR(mz);
160 hw->isb_mem = TMZ_VADDR(mz);
162 /* Initialize the shared code (base driver) */
163 err = ngbe_init_shared_code(hw);
165 PMD_INIT_LOG(ERR, "Shared code init failed: %d", err);
169 /* Unlock any pending hardware semaphore */
170 ngbe_swfw_lock_reset(hw);
172 err = hw->rom.init_params(hw);
174 PMD_INIT_LOG(ERR, "The EEPROM init failed: %d", err);
178 /* Make sure we have a good EEPROM before we read from it */
179 err = hw->rom.validate_checksum(hw, NULL);
181 PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", err);
185 err = hw->mac.init_hw(hw);
187 PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", err);
191 /* disable interrupt */
192 ngbe_disable_intr(hw);
194 /* Allocate memory for storing MAC addresses */
195 eth_dev->data->mac_addrs = rte_zmalloc("ngbe", RTE_ETHER_ADDR_LEN *
196 hw->mac.num_rar_entries, 0);
197 if (eth_dev->data->mac_addrs == NULL) {
199 "Failed to allocate %u bytes needed to store MAC addresses",
200 RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
204 /* Copy the permanent MAC address */
205 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
206 ð_dev->data->mac_addrs[0]);
208 /* Allocate memory for storing hash filter MAC addresses */
209 eth_dev->data->hash_mac_addrs = rte_zmalloc("ngbe",
210 RTE_ETHER_ADDR_LEN * NGBE_VMDQ_NUM_UC_MAC, 0);
211 if (eth_dev->data->hash_mac_addrs == NULL) {
213 "Failed to allocate %d bytes needed to store MAC addresses",
214 RTE_ETHER_ADDR_LEN * NGBE_VMDQ_NUM_UC_MAC);
215 rte_free(eth_dev->data->mac_addrs);
216 eth_dev->data->mac_addrs = NULL;
220 ctrl_ext = rd32(hw, NGBE_PORTCTL);
221 /* let hardware know driver is loaded */
222 ctrl_ext |= NGBE_PORTCTL_DRVLOAD;
223 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
224 ctrl_ext |= NGBE_PORTCTL_RSTDONE;
225 wr32(hw, NGBE_PORTCTL, ctrl_ext);
228 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
229 (int)hw->mac.type, (int)hw->phy.type);
231 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
232 eth_dev->data->port_id, pci_dev->id.vendor_id,
233 pci_dev->id.device_id);
235 rte_intr_callback_register(intr_handle,
236 ngbe_dev_interrupt_handler, eth_dev);
238 /* enable uio/vfio intr/eventfd mapping */
239 rte_intr_enable(intr_handle);
241 /* enable support intr */
242 ngbe_enable_intr(eth_dev);
248 eth_ngbe_dev_uninit(struct rte_eth_dev *eth_dev)
250 PMD_INIT_FUNC_TRACE();
252 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
255 ngbe_dev_close(eth_dev);
261 eth_ngbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
262 struct rte_pci_device *pci_dev)
264 return rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
265 sizeof(struct ngbe_adapter),
266 eth_dev_pci_specific_init, pci_dev,
267 eth_ngbe_dev_init, NULL);
270 static int eth_ngbe_pci_remove(struct rte_pci_device *pci_dev)
272 struct rte_eth_dev *ethdev;
274 ethdev = rte_eth_dev_allocated(pci_dev->device.name);
278 return rte_eth_dev_destroy(ethdev, eth_ngbe_dev_uninit);
281 static struct rte_pci_driver rte_ngbe_pmd = {
282 .id_table = pci_id_ngbe_map,
283 .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
284 RTE_PCI_DRV_INTR_LSC,
285 .probe = eth_ngbe_pci_probe,
286 .remove = eth_ngbe_pci_remove,
290 ngbe_dev_configure(struct rte_eth_dev *dev)
292 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
293 struct ngbe_adapter *adapter = ngbe_dev_adapter(dev);
295 PMD_INIT_FUNC_TRACE();
297 /* set flag to update link status after init */
298 intr->flags |= NGBE_FLAG_NEED_LINK_UPDATE;
301 * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
302 * allocation Rx preconditions we will reset it.
304 adapter->rx_bulk_alloc_allowed = true;
310 ngbe_dev_phy_intr_setup(struct rte_eth_dev *dev)
312 struct ngbe_hw *hw = ngbe_dev_hw(dev);
313 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
315 wr32(hw, NGBE_GPIODIR, NGBE_GPIODIR_DDR(1));
316 wr32(hw, NGBE_GPIOINTEN, NGBE_GPIOINTEN_INT(3));
317 wr32(hw, NGBE_GPIOINTTYPE, NGBE_GPIOINTTYPE_LEVEL(0));
318 if (hw->phy.type == ngbe_phy_yt8521s_sfi)
319 wr32(hw, NGBE_GPIOINTPOL, NGBE_GPIOINTPOL_ACT(0));
321 wr32(hw, NGBE_GPIOINTPOL, NGBE_GPIOINTPOL_ACT(3));
323 intr->mask_misc |= NGBE_ICRMISC_GPIO;
327 * Configure device link speed and setup link.
328 * It returns 0 on success.
331 ngbe_dev_start(struct rte_eth_dev *dev)
333 struct ngbe_hw *hw = ngbe_dev_hw(dev);
334 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
335 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
336 uint32_t intr_vector = 0;
338 bool link_up = false, negotiate = false;
340 uint32_t allowed_speeds = 0;
342 uint32_t *link_speeds;
344 PMD_INIT_FUNC_TRACE();
346 /* disable uio/vfio intr/eventfd mapping */
347 rte_intr_disable(intr_handle);
350 hw->adapter_stopped = 0;
353 /* reinitialize adapter, this calls reset and start */
354 hw->nb_rx_queues = dev->data->nb_rx_queues;
355 hw->nb_tx_queues = dev->data->nb_tx_queues;
356 status = ngbe_pf_reset_hw(hw);
359 hw->mac.start_hw(hw);
360 hw->mac.get_link_status = true;
362 ngbe_dev_phy_intr_setup(dev);
364 /* check and configure queue intr-vector mapping */
365 if ((rte_intr_cap_multiple(intr_handle) ||
366 !RTE_ETH_DEV_SRIOV(dev).active) &&
367 dev->data->dev_conf.intr_conf.rxq != 0) {
368 intr_vector = dev->data->nb_rx_queues;
369 if (rte_intr_efd_enable(intr_handle, intr_vector))
373 if (rte_intr_dp_is_en(intr_handle) && intr_handle->intr_vec == NULL) {
374 intr_handle->intr_vec =
375 rte_zmalloc("intr_vec",
376 dev->data->nb_rx_queues * sizeof(int), 0);
377 if (intr_handle->intr_vec == NULL) {
379 "Failed to allocate %d rx_queues intr_vec",
380 dev->data->nb_rx_queues);
385 /* confiugre MSI-X for sleep until Rx interrupt */
386 ngbe_configure_msix(dev);
388 /* initialize transmission unit */
389 ngbe_dev_tx_init(dev);
391 /* This can fail when allocating mbufs for descriptor rings */
392 err = ngbe_dev_rx_init(dev);
394 PMD_INIT_LOG(ERR, "Unable to initialize Rx hardware");
398 err = ngbe_dev_rxtx_start(dev);
400 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
404 err = hw->mac.check_link(hw, &speed, &link_up, 0);
407 dev->data->dev_link.link_status = link_up;
409 link_speeds = &dev->data->dev_conf.link_speeds;
410 if (*link_speeds == ETH_LINK_SPEED_AUTONEG)
413 err = hw->mac.get_link_capabilities(hw, &speed, &negotiate);
418 if (hw->mac.default_speeds & NGBE_LINK_SPEED_1GB_FULL)
419 allowed_speeds |= ETH_LINK_SPEED_1G;
420 if (hw->mac.default_speeds & NGBE_LINK_SPEED_100M_FULL)
421 allowed_speeds |= ETH_LINK_SPEED_100M;
422 if (hw->mac.default_speeds & NGBE_LINK_SPEED_10M_FULL)
423 allowed_speeds |= ETH_LINK_SPEED_10M;
425 if (*link_speeds & ~allowed_speeds) {
426 PMD_INIT_LOG(ERR, "Invalid link setting");
431 if (*link_speeds == ETH_LINK_SPEED_AUTONEG) {
432 speed = hw->mac.default_speeds;
434 if (*link_speeds & ETH_LINK_SPEED_1G)
435 speed |= NGBE_LINK_SPEED_1GB_FULL;
436 if (*link_speeds & ETH_LINK_SPEED_100M)
437 speed |= NGBE_LINK_SPEED_100M_FULL;
438 if (*link_speeds & ETH_LINK_SPEED_10M)
439 speed |= NGBE_LINK_SPEED_10M_FULL;
443 err = hw->mac.setup_link(hw, speed, link_up);
447 if (rte_intr_allow_others(intr_handle)) {
448 ngbe_dev_misc_interrupt_setup(dev);
449 /* check if lsc interrupt is enabled */
450 if (dev->data->dev_conf.intr_conf.lsc != 0)
451 ngbe_dev_lsc_interrupt_setup(dev, TRUE);
453 ngbe_dev_lsc_interrupt_setup(dev, FALSE);
454 ngbe_dev_macsec_interrupt_setup(dev);
455 ngbe_set_ivar_map(hw, -1, 1, NGBE_MISC_VEC_ID);
457 rte_intr_callback_unregister(intr_handle,
458 ngbe_dev_interrupt_handler, dev);
459 if (dev->data->dev_conf.intr_conf.lsc != 0)
461 "LSC won't enable because of no intr multiplex");
464 /* check if rxq interrupt is enabled */
465 if (dev->data->dev_conf.intr_conf.rxq != 0 &&
466 rte_intr_dp_is_en(intr_handle))
467 ngbe_dev_rxq_interrupt_setup(dev);
469 /* enable UIO/VFIO intr/eventfd mapping */
470 rte_intr_enable(intr_handle);
472 /* resume enabled intr since HW reset */
473 ngbe_enable_intr(dev);
475 if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
476 (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
477 /* gpio0 is used to power on/off control*/
478 wr32(hw, NGBE_GPIODATA, 0);
482 * Update link status right before return, because it may
483 * start link configuration process in a separate thread.
485 ngbe_dev_link_update(dev, 0);
490 PMD_INIT_LOG(ERR, "failure in dev start: %d", err);
491 ngbe_dev_clear_queues(dev);
496 * Stop device: disable rx and tx functions to allow for reconfiguring.
499 ngbe_dev_stop(struct rte_eth_dev *dev)
501 struct rte_eth_link link;
502 struct ngbe_hw *hw = ngbe_dev_hw(dev);
503 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
504 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
506 if (hw->adapter_stopped)
509 PMD_INIT_FUNC_TRACE();
511 if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
512 (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
513 /* gpio0 is used to power on/off control*/
514 wr32(hw, NGBE_GPIODATA, NGBE_GPIOBIT_0);
517 /* disable interrupts */
518 ngbe_disable_intr(hw);
521 ngbe_pf_reset_hw(hw);
522 hw->adapter_stopped = 0;
527 ngbe_dev_clear_queues(dev);
529 /* Clear recorded link status */
530 memset(&link, 0, sizeof(link));
531 rte_eth_linkstatus_set(dev, &link);
533 if (!rte_intr_allow_others(intr_handle))
534 /* resume to the default handler */
535 rte_intr_callback_register(intr_handle,
536 ngbe_dev_interrupt_handler,
539 /* Clean datapath event and queue/vec mapping */
540 rte_intr_efd_disable(intr_handle);
541 if (intr_handle->intr_vec != NULL) {
542 rte_free(intr_handle->intr_vec);
543 intr_handle->intr_vec = NULL;
546 hw->adapter_stopped = true;
547 dev->data->dev_started = 0;
553 * Reset and stop device.
556 ngbe_dev_close(struct rte_eth_dev *dev)
558 PMD_INIT_FUNC_TRACE();
566 ngbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
568 struct ngbe_hw *hw = ngbe_dev_hw(dev);
570 dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
571 dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
572 dev_info->min_rx_bufsize = 1024;
573 dev_info->max_rx_pktlen = 15872;
575 dev_info->default_rxconf = (struct rte_eth_rxconf) {
577 .pthresh = NGBE_DEFAULT_RX_PTHRESH,
578 .hthresh = NGBE_DEFAULT_RX_HTHRESH,
579 .wthresh = NGBE_DEFAULT_RX_WTHRESH,
581 .rx_free_thresh = NGBE_DEFAULT_RX_FREE_THRESH,
586 dev_info->default_txconf = (struct rte_eth_txconf) {
588 .pthresh = NGBE_DEFAULT_TX_PTHRESH,
589 .hthresh = NGBE_DEFAULT_TX_HTHRESH,
590 .wthresh = NGBE_DEFAULT_TX_WTHRESH,
592 .tx_free_thresh = NGBE_DEFAULT_TX_FREE_THRESH,
596 dev_info->rx_desc_lim = rx_desc_lim;
597 dev_info->tx_desc_lim = tx_desc_lim;
599 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_100M |
602 /* Driver-preferred Rx/Tx parameters */
603 dev_info->default_rxportconf.burst_size = 32;
604 dev_info->default_txportconf.burst_size = 32;
605 dev_info->default_rxportconf.nb_queues = 1;
606 dev_info->default_txportconf.nb_queues = 1;
607 dev_info->default_rxportconf.ring_size = 256;
608 dev_info->default_txportconf.ring_size = 256;
613 /* return 0 means link status changed, -1 means not changed */
615 ngbe_dev_link_update_share(struct rte_eth_dev *dev,
616 int wait_to_complete)
618 struct ngbe_hw *hw = ngbe_dev_hw(dev);
619 struct rte_eth_link link;
620 u32 link_speed = NGBE_LINK_SPEED_UNKNOWN;
622 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
627 memset(&link, 0, sizeof(link));
628 link.link_status = ETH_LINK_DOWN;
629 link.link_speed = ETH_SPEED_NUM_NONE;
630 link.link_duplex = ETH_LINK_HALF_DUPLEX;
631 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
632 ~ETH_LINK_SPEED_AUTONEG);
634 hw->mac.get_link_status = true;
636 if (intr->flags & NGBE_FLAG_NEED_LINK_CONFIG)
637 return rte_eth_linkstatus_set(dev, &link);
639 /* check if it needs to wait to complete, if lsc interrupt is enabled */
640 if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
643 err = hw->mac.check_link(hw, &link_speed, &link_up, wait);
645 link.link_speed = ETH_SPEED_NUM_NONE;
646 link.link_duplex = ETH_LINK_FULL_DUPLEX;
647 return rte_eth_linkstatus_set(dev, &link);
651 return rte_eth_linkstatus_set(dev, &link);
653 intr->flags &= ~NGBE_FLAG_NEED_LINK_CONFIG;
654 link.link_status = ETH_LINK_UP;
655 link.link_duplex = ETH_LINK_FULL_DUPLEX;
657 switch (link_speed) {
659 case NGBE_LINK_SPEED_UNKNOWN:
660 link.link_speed = ETH_SPEED_NUM_NONE;
663 case NGBE_LINK_SPEED_10M_FULL:
664 link.link_speed = ETH_SPEED_NUM_10M;
668 case NGBE_LINK_SPEED_100M_FULL:
669 link.link_speed = ETH_SPEED_NUM_100M;
673 case NGBE_LINK_SPEED_1GB_FULL:
674 link.link_speed = ETH_SPEED_NUM_1G;
680 wr32m(hw, NGBE_LAN_SPEED, NGBE_LAN_SPEED_MASK, lan_speed);
681 if (link_speed & (NGBE_LINK_SPEED_1GB_FULL |
682 NGBE_LINK_SPEED_100M_FULL |
683 NGBE_LINK_SPEED_10M_FULL)) {
684 wr32m(hw, NGBE_MACTXCFG, NGBE_MACTXCFG_SPEED_MASK,
685 NGBE_MACTXCFG_SPEED_1G | NGBE_MACTXCFG_TE);
689 return rte_eth_linkstatus_set(dev, &link);
693 ngbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
695 return ngbe_dev_link_update_share(dev, wait_to_complete);
699 * It clears the interrupt causes and enables the interrupt.
700 * It will be called once only during NIC initialized.
703 * Pointer to struct rte_eth_dev.
708 * - On success, zero.
709 * - On failure, a negative value.
712 ngbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
714 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
716 ngbe_dev_link_status_print(dev);
718 intr->mask_misc |= NGBE_ICRMISC_PHY;
719 intr->mask_misc |= NGBE_ICRMISC_GPIO;
721 intr->mask_misc &= ~NGBE_ICRMISC_PHY;
722 intr->mask_misc &= ~NGBE_ICRMISC_GPIO;
729 * It clears the interrupt causes and enables the interrupt.
730 * It will be called once only during NIC initialized.
733 * Pointer to struct rte_eth_dev.
736 * - On success, zero.
737 * - On failure, a negative value.
740 ngbe_dev_misc_interrupt_setup(struct rte_eth_dev *dev)
742 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
745 mask = NGBE_ICR_MASK;
746 mask &= (1ULL << NGBE_MISC_VEC_ID);
748 intr->mask_misc |= NGBE_ICRMISC_GPIO;
754 * It clears the interrupt causes and enables the interrupt.
755 * It will be called once only during NIC initialized.
758 * Pointer to struct rte_eth_dev.
761 * - On success, zero.
762 * - On failure, a negative value.
765 ngbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
767 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
770 mask = NGBE_ICR_MASK;
771 mask &= ~((1ULL << NGBE_RX_VEC_START) - 1);
778 * It clears the interrupt causes and enables the interrupt.
779 * It will be called once only during NIC initialized.
782 * Pointer to struct rte_eth_dev.
785 * - On success, zero.
786 * - On failure, a negative value.
789 ngbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev)
791 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
793 intr->mask_misc |= NGBE_ICRMISC_LNKSEC;
799 * It reads ICR and sets flag for the link_update.
802 * Pointer to struct rte_eth_dev.
805 * - On success, zero.
806 * - On failure, a negative value.
809 ngbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
812 struct ngbe_hw *hw = ngbe_dev_hw(dev);
813 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
815 /* clear all cause mask */
816 ngbe_disable_intr(hw);
818 /* read-on-clear nic registers here */
819 eicr = ((u32 *)hw->isb_mem)[NGBE_ISB_MISC];
820 PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
824 /* set flag for async link update */
825 if (eicr & NGBE_ICRMISC_PHY)
826 intr->flags |= NGBE_FLAG_NEED_LINK_UPDATE;
828 if (eicr & NGBE_ICRMISC_VFMBX)
829 intr->flags |= NGBE_FLAG_MAILBOX;
831 if (eicr & NGBE_ICRMISC_LNKSEC)
832 intr->flags |= NGBE_FLAG_MACSEC;
834 if (eicr & NGBE_ICRMISC_GPIO)
835 intr->flags |= NGBE_FLAG_NEED_LINK_UPDATE;
841 * It gets and then prints the link status.
844 * Pointer to struct rte_eth_dev.
847 * - On success, zero.
848 * - On failure, a negative value.
851 ngbe_dev_link_status_print(struct rte_eth_dev *dev)
853 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
854 struct rte_eth_link link;
856 rte_eth_linkstatus_get(dev, &link);
858 if (link.link_status == ETH_LINK_UP) {
859 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
860 (int)(dev->data->port_id),
861 (unsigned int)link.link_speed,
862 link.link_duplex == ETH_LINK_FULL_DUPLEX ?
863 "full-duplex" : "half-duplex");
865 PMD_INIT_LOG(INFO, " Port %d: Link Down",
866 (int)(dev->data->port_id));
868 PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
869 pci_dev->addr.domain,
872 pci_dev->addr.function);
876 * It executes link_update after knowing an interrupt occurred.
879 * Pointer to struct rte_eth_dev.
882 * - On success, zero.
883 * - On failure, a negative value.
886 ngbe_dev_interrupt_action(struct rte_eth_dev *dev)
888 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
891 PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
893 if (intr->flags & NGBE_FLAG_NEED_LINK_UPDATE) {
894 struct rte_eth_link link;
896 /*get the link status before link update, for predicting later*/
897 rte_eth_linkstatus_get(dev, &link);
899 ngbe_dev_link_update(dev, 0);
902 if (link.link_status != ETH_LINK_UP)
903 /* handle it 1 sec later, wait it being stable */
904 timeout = NGBE_LINK_UP_CHECK_TIMEOUT;
907 /* handle it 4 sec later, wait it being stable */
908 timeout = NGBE_LINK_DOWN_CHECK_TIMEOUT;
910 ngbe_dev_link_status_print(dev);
911 if (rte_eal_alarm_set(timeout * 1000,
912 ngbe_dev_interrupt_delayed_handler,
914 PMD_DRV_LOG(ERR, "Error setting alarm");
916 /* remember original mask */
917 intr->mask_misc_orig = intr->mask_misc;
918 /* only disable lsc interrupt */
919 intr->mask_misc &= ~NGBE_ICRMISC_PHY;
921 intr->mask_orig = intr->mask;
922 /* only disable all misc interrupts */
923 intr->mask &= ~(1ULL << NGBE_MISC_VEC_ID);
927 PMD_DRV_LOG(DEBUG, "enable intr immediately");
928 ngbe_enable_intr(dev);
934 * Interrupt handler which shall be registered for alarm callback for delayed
935 * handling specific interrupt to wait for the stable nic state. As the
936 * NIC interrupt state is not stable for ngbe after link is just down,
937 * it needs to wait 4 seconds to get the stable status.
940 * The address of parameter (struct rte_eth_dev *) registered before.
943 ngbe_dev_interrupt_delayed_handler(void *param)
945 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
946 struct ngbe_interrupt *intr = ngbe_dev_intr(dev);
947 struct ngbe_hw *hw = ngbe_dev_hw(dev);
950 ngbe_disable_intr(hw);
952 eicr = ((u32 *)hw->isb_mem)[NGBE_ISB_MISC];
954 if (intr->flags & NGBE_FLAG_NEED_LINK_UPDATE) {
955 ngbe_dev_link_update(dev, 0);
956 intr->flags &= ~NGBE_FLAG_NEED_LINK_UPDATE;
957 ngbe_dev_link_status_print(dev);
958 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
962 if (intr->flags & NGBE_FLAG_MACSEC) {
963 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_MACSEC,
965 intr->flags &= ~NGBE_FLAG_MACSEC;
968 /* restore original mask */
969 intr->mask_misc = intr->mask_misc_orig;
970 intr->mask_misc_orig = 0;
971 intr->mask = intr->mask_orig;
974 PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
975 ngbe_enable_intr(dev);
979 * Interrupt handler triggered by NIC for handling
980 * specific interrupt.
983 * The address of parameter (struct rte_eth_dev *) registered before.
986 ngbe_dev_interrupt_handler(void *param)
988 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
990 ngbe_dev_interrupt_get_status(dev);
991 ngbe_dev_interrupt_action(dev);
995 * Set the IVAR registers, mapping interrupt causes to vectors
997 * pointer to ngbe_hw struct
999 * 0 for Rx, 1 for Tx, -1 for other causes
1001 * queue to map the corresponding interrupt to
1003 * the vector to map to the corresponding queue
1006 ngbe_set_ivar_map(struct ngbe_hw *hw, int8_t direction,
1007 uint8_t queue, uint8_t msix_vector)
1011 if (direction == -1) {
1013 msix_vector |= NGBE_IVARMISC_VLD;
1015 tmp = rd32(hw, NGBE_IVARMISC);
1016 tmp &= ~(0xFF << idx);
1017 tmp |= (msix_vector << idx);
1018 wr32(hw, NGBE_IVARMISC, tmp);
1020 /* rx or tx causes */
1021 /* Workround for ICR lost */
1022 idx = ((16 * (queue & 1)) + (8 * direction));
1023 tmp = rd32(hw, NGBE_IVAR(queue >> 1));
1024 tmp &= ~(0xFF << idx);
1025 tmp |= (msix_vector << idx);
1026 wr32(hw, NGBE_IVAR(queue >> 1), tmp);
1031 * Sets up the hardware to properly generate MSI-X interrupts
1033 * board private structure
1036 ngbe_configure_msix(struct rte_eth_dev *dev)
1038 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1039 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1040 struct ngbe_hw *hw = ngbe_dev_hw(dev);
1041 uint32_t queue_id, base = NGBE_MISC_VEC_ID;
1042 uint32_t vec = NGBE_MISC_VEC_ID;
1046 * Won't configure MSI-X register if no mapping is done
1047 * between intr vector and event fd
1048 * but if MSI-X has been enabled already, need to configure
1049 * auto clean, auto mask and throttling.
1051 gpie = rd32(hw, NGBE_GPIE);
1052 if (!rte_intr_dp_is_en(intr_handle) &&
1053 !(gpie & NGBE_GPIE_MSIX))
1056 if (rte_intr_allow_others(intr_handle)) {
1057 base = NGBE_RX_VEC_START;
1061 /* setup GPIE for MSI-X mode */
1062 gpie = rd32(hw, NGBE_GPIE);
1063 gpie |= NGBE_GPIE_MSIX;
1064 wr32(hw, NGBE_GPIE, gpie);
1066 /* Populate the IVAR table and set the ITR values to the
1067 * corresponding register.
1069 if (rte_intr_dp_is_en(intr_handle)) {
1070 for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
1072 /* by default, 1:1 mapping */
1073 ngbe_set_ivar_map(hw, 0, queue_id, vec);
1074 intr_handle->intr_vec[queue_id] = vec;
1075 if (vec < base + intr_handle->nb_efd - 1)
1079 ngbe_set_ivar_map(hw, -1, 1, NGBE_MISC_VEC_ID);
1081 wr32(hw, NGBE_ITR(NGBE_MISC_VEC_ID),
1082 NGBE_ITR_IVAL_1G(NGBE_QUEUE_ITR_INTERVAL_DEFAULT)
1086 static const struct eth_dev_ops ngbe_eth_dev_ops = {
1087 .dev_configure = ngbe_dev_configure,
1088 .dev_infos_get = ngbe_dev_info_get,
1089 .dev_start = ngbe_dev_start,
1090 .dev_stop = ngbe_dev_stop,
1091 .link_update = ngbe_dev_link_update,
1092 .rx_queue_start = ngbe_dev_rx_queue_start,
1093 .rx_queue_stop = ngbe_dev_rx_queue_stop,
1094 .tx_queue_start = ngbe_dev_tx_queue_start,
1095 .tx_queue_stop = ngbe_dev_tx_queue_stop,
1096 .rx_queue_setup = ngbe_dev_rx_queue_setup,
1097 .rx_queue_release = ngbe_dev_rx_queue_release,
1098 .tx_queue_setup = ngbe_dev_tx_queue_setup,
1099 .tx_queue_release = ngbe_dev_tx_queue_release,
1102 RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
1103 RTE_PMD_REGISTER_PCI_TABLE(net_ngbe, pci_id_ngbe_map);
1104 RTE_PMD_REGISTER_KMOD_DEP(net_ngbe, "* igb_uio | uio_pci_generic | vfio-pci");
1106 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_init, init, NOTICE);
1107 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_driver, driver, NOTICE);
1109 #ifdef RTE_ETHDEV_DEBUG_RX
1110 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_rx, rx, DEBUG);
1112 #ifdef RTE_ETHDEV_DEBUG_TX
1113 RTE_LOG_REGISTER_SUFFIX(ngbe_logtype_tx, tx, DEBUG);