1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
3 * Copyright (c) 2015-2018 Cavium Inc.
9 #include "bnx2x_rxtx.h"
11 #include <rte_string_fns.h>
13 #include <rte_ethdev_pci.h>
14 #include <rte_alarm.h>
16 int bnx2x_logtype_init;
17 int bnx2x_logtype_driver;
20 * The set of PCI devices this driver supports
22 #define BROADCOM_PCI_VENDOR_ID 0x14E4
23 static const struct rte_pci_id pci_id_bnx2x_map[] = {
24 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57800) },
25 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57711) },
26 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810) },
27 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811) },
28 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_OBS) },
29 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_4_10) },
30 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_2_20) },
31 #ifdef RTE_LIBRTE_BNX2X_MF_SUPPORT
32 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810_MF) },
33 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811_MF) },
34 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_MF) },
39 static const struct rte_pci_id pci_id_bnx2xvf_map[] = {
40 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57800_VF) },
41 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810_VF) },
42 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811_VF) },
43 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_VF) },
47 struct rte_bnx2x_xstats_name_off {
48 char name[RTE_ETH_XSTATS_NAME_SIZE];
53 static const struct rte_bnx2x_xstats_name_off bnx2x_xstats_strings[] = {
55 offsetof(struct bnx2x_eth_stats, brb_drop_hi),
56 offsetof(struct bnx2x_eth_stats, brb_drop_lo)},
57 {"rx_buffer_truncates",
58 offsetof(struct bnx2x_eth_stats, brb_truncate_hi),
59 offsetof(struct bnx2x_eth_stats, brb_truncate_lo)},
60 {"rx_buffer_truncate_discard",
61 offsetof(struct bnx2x_eth_stats, brb_truncate_discard),
62 offsetof(struct bnx2x_eth_stats, brb_truncate_discard)},
63 {"mac_filter_discard",
64 offsetof(struct bnx2x_eth_stats, mac_filter_discard),
65 offsetof(struct bnx2x_eth_stats, mac_filter_discard)},
66 {"no_match_vlan_tag_discard",
67 offsetof(struct bnx2x_eth_stats, mf_tag_discard),
68 offsetof(struct bnx2x_eth_stats, mf_tag_discard)},
70 offsetof(struct bnx2x_eth_stats, pause_frames_sent_hi),
71 offsetof(struct bnx2x_eth_stats, pause_frames_sent_lo)},
73 offsetof(struct bnx2x_eth_stats, pause_frames_received_hi),
74 offsetof(struct bnx2x_eth_stats, pause_frames_received_lo)},
75 {"tx_priority_flow_control",
76 offsetof(struct bnx2x_eth_stats, pfc_frames_sent_hi),
77 offsetof(struct bnx2x_eth_stats, pfc_frames_sent_lo)},
78 {"rx_priority_flow_control",
79 offsetof(struct bnx2x_eth_stats, pfc_frames_received_hi),
80 offsetof(struct bnx2x_eth_stats, pfc_frames_received_lo)}
84 bnx2x_link_update(struct rte_eth_dev *dev)
86 struct bnx2x_softc *sc = dev->data->dev_private;
87 struct rte_eth_link link;
89 PMD_INIT_FUNC_TRACE(sc);
91 memset(&link, 0, sizeof(link));
93 link.link_speed = sc->link_vars.line_speed;
94 switch (sc->link_vars.duplex) {
96 link.link_duplex = ETH_LINK_FULL_DUPLEX;
99 link.link_duplex = ETH_LINK_HALF_DUPLEX;
102 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
103 ETH_LINK_SPEED_FIXED);
104 link.link_status = sc->link_vars.link_up;
106 return rte_eth_linkstatus_set(dev, &link);
110 bnx2x_interrupt_action(struct rte_eth_dev *dev, int intr_cxt)
112 struct bnx2x_softc *sc = dev->data->dev_private;
113 uint32_t link_status;
115 bnx2x_intr_legacy(sc);
117 if ((atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO) &&
119 bnx2x_periodic_callout(sc);
120 link_status = REG_RD(sc, sc->link_params.shmem_base +
121 offsetof(struct shmem_region,
122 port_mb[sc->link_params.port].link_status));
123 if ((link_status & LINK_STATUS_LINK_UP) != dev->data->dev_link.link_status)
124 bnx2x_link_update(dev);
128 bnx2x_interrupt_handler(void *param)
130 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
131 struct bnx2x_softc *sc = dev->data->dev_private;
133 PMD_DEBUG_PERIODIC_LOG(INFO, sc, "Interrupt handled");
135 bnx2x_interrupt_action(dev, 1);
136 rte_intr_ack(&sc->pci_dev->intr_handle);
139 static void bnx2x_periodic_start(void *param)
141 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
142 struct bnx2x_softc *sc = dev->data->dev_private;
145 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
146 bnx2x_interrupt_action(dev, 0);
148 ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD,
149 bnx2x_periodic_start, (void *)dev);
151 PMD_DRV_LOG(ERR, sc, "Unable to start periodic"
152 " timer rc %d", ret);
157 void bnx2x_periodic_stop(void *param)
159 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
160 struct bnx2x_softc *sc = dev->data->dev_private;
162 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
164 rte_eal_alarm_cancel(bnx2x_periodic_start, (void *)dev);
166 PMD_DRV_LOG(DEBUG, sc, "Periodic poll stopped");
170 * Devops - helper functions can be called from user application
174 bnx2x_dev_configure(struct rte_eth_dev *dev)
176 struct bnx2x_softc *sc = dev->data->dev_private;
177 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
179 int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF);
181 PMD_INIT_FUNC_TRACE(sc);
183 if (rxmode->offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
184 sc->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len;
185 dev->data->mtu = sc->mtu;
188 if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) {
189 PMD_DRV_LOG(ERR, sc, "The number of TX queues is greater than number of RX queues");
193 sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
194 if (sc->num_queues > mp_ncpus) {
195 PMD_DRV_LOG(ERR, sc, "The number of queues is more than number of CPUs");
199 PMD_DRV_LOG(DEBUG, sc, "num_queues=%d, mtu=%d",
200 sc->num_queues, sc->mtu);
203 if (bnx2x_alloc_ilt_mem(sc) != 0) {
204 PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_ilt_mem was failed");
208 bnx2x_dev_rxtx_init_dummy(dev);
213 bnx2x_dev_start(struct rte_eth_dev *dev)
215 struct bnx2x_softc *sc = dev->data->dev_private;
218 PMD_INIT_FUNC_TRACE(sc);
220 /* start the periodic callout */
222 if (atomic_load_acq_long(&sc->periodic_flags) ==
224 bnx2x_periodic_start(dev);
225 PMD_DRV_LOG(DEBUG, sc, "Periodic poll re-started");
229 ret = bnx2x_init(sc);
231 PMD_DRV_LOG(DEBUG, sc, "bnx2x_init failed (%d)", ret);
236 rte_intr_callback_register(&sc->pci_dev->intr_handle,
237 bnx2x_interrupt_handler, (void *)dev);
239 if (rte_intr_enable(&sc->pci_dev->intr_handle))
240 PMD_DRV_LOG(ERR, sc, "rte_intr_enable failed");
243 /* Configure the previously stored Multicast address list */
245 bnx2x_vfpf_set_mcast(sc, sc->mc_addrs, sc->mc_addrs_num);
246 bnx2x_dev_rxtx_init(dev);
248 bnx2x_print_device_info(sc);
254 bnx2x_dev_stop(struct rte_eth_dev *dev)
256 struct bnx2x_softc *sc = dev->data->dev_private;
259 PMD_INIT_FUNC_TRACE(sc);
261 bnx2x_dev_rxtx_init_dummy(dev);
264 rte_intr_disable(&sc->pci_dev->intr_handle);
265 rte_intr_callback_unregister(&sc->pci_dev->intr_handle,
266 bnx2x_interrupt_handler, (void *)dev);
268 /* stop the periodic callout */
269 bnx2x_periodic_stop(dev);
271 /* Remove the configured Multicast list
272 * Sending NULL for the list of address and the
273 * Number is set to 0 denoting DEL_CMD
276 bnx2x_vfpf_set_mcast(sc, NULL, 0);
277 ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE);
279 PMD_DRV_LOG(DEBUG, sc, "bnx2x_nic_unload failed (%d)", ret);
287 bnx2x_dev_close(struct rte_eth_dev *dev)
289 struct bnx2x_softc *sc = dev->data->dev_private;
291 PMD_INIT_FUNC_TRACE(sc);
296 bnx2x_dev_clear_queues(dev);
297 memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link));
300 bnx2x_free_ilt_mem(sc);
304 bnx2x_promisc_enable(struct rte_eth_dev *dev)
306 struct bnx2x_softc *sc = dev->data->dev_private;
308 PMD_INIT_FUNC_TRACE(sc);
309 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
310 if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
311 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
312 bnx2x_set_rx_mode(sc);
318 bnx2x_promisc_disable(struct rte_eth_dev *dev)
320 struct bnx2x_softc *sc = dev->data->dev_private;
322 PMD_INIT_FUNC_TRACE(sc);
323 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
324 if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
325 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
326 bnx2x_set_rx_mode(sc);
332 bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev)
334 struct bnx2x_softc *sc = dev->data->dev_private;
336 PMD_INIT_FUNC_TRACE(sc);
337 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
338 if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
339 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
340 bnx2x_set_rx_mode(sc);
346 bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev)
348 struct bnx2x_softc *sc = dev->data->dev_private;
350 PMD_INIT_FUNC_TRACE(sc);
351 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
352 if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
353 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
354 bnx2x_set_rx_mode(sc);
360 bnx2x_dev_set_mc_addr_list(struct rte_eth_dev *dev,
361 struct rte_ether_addr *mc_addrs, uint32_t mc_addrs_num)
363 struct bnx2x_softc *sc = dev->data->dev_private;
365 PMD_INIT_FUNC_TRACE(sc);
366 /* flush previous addresses */
367 err = bnx2x_vfpf_set_mcast(sc, NULL, 0);
370 sc->mc_addrs_num = 0;
373 err = bnx2x_vfpf_set_mcast(sc, mc_addrs, mc_addrs_num);
377 sc->mc_addrs_num = mc_addrs_num;
378 memcpy(sc->mc_addrs, mc_addrs, mc_addrs_num * sizeof(*mc_addrs));
384 bnx2x_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
386 struct bnx2x_softc *sc = dev->data->dev_private;
388 PMD_INIT_FUNC_TRACE(sc);
390 return bnx2x_link_update(dev);
394 bnx2xvf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
396 struct bnx2x_softc *sc = dev->data->dev_private;
399 ret = bnx2x_link_update(dev);
401 bnx2x_check_bull(sc);
402 if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
403 PMD_DRV_LOG(ERR, sc, "PF indicated channel is down."
404 "VF device is no longer operational");
405 dev->data->dev_link.link_status = ETH_LINK_DOWN;
412 bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
414 struct bnx2x_softc *sc = dev->data->dev_private;
415 uint32_t brb_truncate_discard;
417 uint64_t brb_truncates;
419 PMD_INIT_FUNC_TRACE(sc);
421 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
423 memset(stats, 0, sizeof (struct rte_eth_stats));
426 HILO_U64(sc->eth_stats.total_unicast_packets_received_hi,
427 sc->eth_stats.total_unicast_packets_received_lo) +
428 HILO_U64(sc->eth_stats.total_multicast_packets_received_hi,
429 sc->eth_stats.total_multicast_packets_received_lo) +
430 HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi,
431 sc->eth_stats.total_broadcast_packets_received_lo);
434 HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi,
435 sc->eth_stats.total_unicast_packets_transmitted_lo) +
436 HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi,
437 sc->eth_stats.total_multicast_packets_transmitted_lo) +
438 HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi,
439 sc->eth_stats.total_broadcast_packets_transmitted_lo);
442 HILO_U64(sc->eth_stats.total_bytes_received_hi,
443 sc->eth_stats.total_bytes_received_lo);
446 HILO_U64(sc->eth_stats.total_bytes_transmitted_hi,
447 sc->eth_stats.total_bytes_transmitted_lo);
450 HILO_U64(sc->eth_stats.error_bytes_received_hi,
451 sc->eth_stats.error_bytes_received_lo);
456 HILO_U64(sc->eth_stats.no_buff_discard_hi,
457 sc->eth_stats.no_buff_discard_lo);
460 HILO_U64(sc->eth_stats.brb_drop_hi,
461 sc->eth_stats.brb_drop_lo);
464 HILO_U64(sc->eth_stats.brb_truncate_hi,
465 sc->eth_stats.brb_truncate_lo);
467 brb_truncate_discard = sc->eth_stats.brb_truncate_discard;
469 stats->imissed = brb_drops + brb_truncates +
470 brb_truncate_discard + stats->rx_nombuf;
476 bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev,
477 struct rte_eth_xstat_name *xstats_names,
478 __rte_unused unsigned limit)
480 unsigned int i, stat_cnt = RTE_DIM(bnx2x_xstats_strings);
482 if (xstats_names != NULL)
483 for (i = 0; i < stat_cnt; i++)
484 strlcpy(xstats_names[i].name,
485 bnx2x_xstats_strings[i].name,
486 sizeof(xstats_names[i].name));
492 bnx2x_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
495 struct bnx2x_softc *sc = dev->data->dev_private;
496 unsigned int num = RTE_DIM(bnx2x_xstats_strings);
501 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
503 for (num = 0; num < n; num++) {
504 if (bnx2x_xstats_strings[num].offset_hi !=
505 bnx2x_xstats_strings[num].offset_lo)
506 xstats[num].value = HILO_U64(
507 *(uint32_t *)((char *)&sc->eth_stats +
508 bnx2x_xstats_strings[num].offset_hi),
509 *(uint32_t *)((char *)&sc->eth_stats +
510 bnx2x_xstats_strings[num].offset_lo));
513 *(uint64_t *)((char *)&sc->eth_stats +
514 bnx2x_xstats_strings[num].offset_lo);
515 xstats[num].id = num;
522 bnx2x_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
524 struct bnx2x_softc *sc = dev->data->dev_private;
526 dev_info->max_rx_queues = sc->max_rx_queues;
527 dev_info->max_tx_queues = sc->max_tx_queues;
528 dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
529 dev_info->max_rx_pktlen = BNX2X_MAX_RX_PKT_LEN;
530 dev_info->max_mac_addrs = BNX2X_MAX_MAC_ADDRS;
531 dev_info->speed_capa = ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G;
532 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_JUMBO_FRAME;
534 dev_info->rx_desc_lim.nb_max = MAX_RX_AVAIL;
535 dev_info->rx_desc_lim.nb_min = MIN_RX_SIZE_NONTPA;
536 dev_info->rx_desc_lim.nb_mtu_seg_max = 1;
537 dev_info->tx_desc_lim.nb_max = MAX_TX_AVAIL;
543 bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
544 uint32_t index, uint32_t pool)
546 struct bnx2x_softc *sc = dev->data->dev_private;
548 if (sc->mac_ops.mac_addr_add) {
549 sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool);
556 bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
558 struct bnx2x_softc *sc = dev->data->dev_private;
560 if (sc->mac_ops.mac_addr_remove)
561 sc->mac_ops.mac_addr_remove(dev, index);
564 static const struct eth_dev_ops bnx2x_eth_dev_ops = {
565 .dev_configure = bnx2x_dev_configure,
566 .dev_start = bnx2x_dev_start,
567 .dev_stop = bnx2x_dev_stop,
568 .dev_close = bnx2x_dev_close,
569 .promiscuous_enable = bnx2x_promisc_enable,
570 .promiscuous_disable = bnx2x_promisc_disable,
571 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
572 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
573 .link_update = bnx2x_dev_link_update,
574 .stats_get = bnx2x_dev_stats_get,
575 .xstats_get = bnx2x_dev_xstats_get,
576 .xstats_get_names = bnx2x_get_xstats_names,
577 .dev_infos_get = bnx2x_dev_infos_get,
578 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
579 .rx_queue_release = bnx2x_dev_rx_queue_release,
580 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
581 .tx_queue_release = bnx2x_dev_tx_queue_release,
582 .mac_addr_add = bnx2x_mac_addr_add,
583 .mac_addr_remove = bnx2x_mac_addr_remove,
587 * dev_ops for virtual function
589 static const struct eth_dev_ops bnx2xvf_eth_dev_ops = {
590 .dev_configure = bnx2x_dev_configure,
591 .dev_start = bnx2x_dev_start,
592 .dev_stop = bnx2x_dev_stop,
593 .dev_close = bnx2x_dev_close,
594 .promiscuous_enable = bnx2x_promisc_enable,
595 .promiscuous_disable = bnx2x_promisc_disable,
596 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
597 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
598 .set_mc_addr_list = bnx2x_dev_set_mc_addr_list,
599 .link_update = bnx2xvf_dev_link_update,
600 .stats_get = bnx2x_dev_stats_get,
601 .xstats_get = bnx2x_dev_xstats_get,
602 .xstats_get_names = bnx2x_get_xstats_names,
603 .dev_infos_get = bnx2x_dev_infos_get,
604 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
605 .rx_queue_release = bnx2x_dev_rx_queue_release,
606 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
607 .tx_queue_release = bnx2x_dev_tx_queue_release,
608 .mac_addr_add = bnx2x_mac_addr_add,
609 .mac_addr_remove = bnx2x_mac_addr_remove,
614 bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
617 struct rte_pci_device *pci_dev;
618 struct rte_pci_addr pci_addr;
619 struct bnx2x_softc *sc;
620 static bool adapter_info = true;
622 /* Extract key data structures */
623 sc = eth_dev->data->dev_private;
624 pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
625 pci_addr = pci_dev->addr;
627 snprintf(sc->devinfo.name, NAME_SIZE, PCI_SHORT_PRI_FMT ":dpdk-port-%u",
628 pci_addr.bus, pci_addr.devid, pci_addr.function,
629 eth_dev->data->port_id);
631 PMD_INIT_FUNC_TRACE(sc);
633 eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
635 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
636 PMD_DRV_LOG(ERR, sc, "Skipping device init from secondary process");
640 rte_eth_copy_pci_info(eth_dev, pci_dev);
642 sc->pcie_bus = pci_dev->addr.bus;
643 sc->pcie_device = pci_dev->addr.devid;
645 sc->devinfo.vendor_id = pci_dev->id.vendor_id;
646 sc->devinfo.device_id = pci_dev->id.device_id;
647 sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id;
648 sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id;
651 sc->flags = BNX2X_IS_VF_FLAG;
653 sc->pcie_func = pci_dev->addr.function;
654 sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr;
656 sc->bar[BAR1].base_addr = (void *)
657 ((uintptr_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START);
659 sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr;
661 assert(sc->bar[BAR0].base_addr);
662 assert(sc->bar[BAR1].base_addr);
664 bnx2x_load_firmware(sc);
665 assert(sc->firmware);
667 if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
670 sc->rx_budget = BNX2X_RX_BUDGET;
671 sc->hc_rx_ticks = BNX2X_RX_TICKS;
672 sc->hc_tx_ticks = BNX2X_TX_TICKS;
674 sc->interrupt_mode = INTR_MODE_SINGLE_MSIX;
675 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
677 sc->pci_dev = pci_dev;
678 ret = bnx2x_attach(sc);
680 PMD_DRV_LOG(ERR, sc, "bnx2x_attach failed (%d)", ret);
684 /* Print important adapter info for the user. */
686 bnx2x_print_adapter_info(sc);
687 adapter_info = false;
690 /* schedule periodic poll for slowpath link events */
692 PMD_DRV_LOG(DEBUG, sc, "Scheduling periodic poll for slowpath link events");
693 ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD,
694 bnx2x_periodic_start, (void *)eth_dev);
696 PMD_DRV_LOG(ERR, sc, "Unable to start periodic"
697 " timer rc %d", ret);
702 eth_dev->data->mac_addrs =
703 (struct rte_ether_addr *)sc->link_params.mac_addr;
706 rte_spinlock_init(&sc->vf2pf_lock);
708 ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg),
709 &sc->vf2pf_mbox_mapping, "vf2pf_mbox",
710 RTE_CACHE_LINE_SIZE);
714 sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *)
715 sc->vf2pf_mbox_mapping.vaddr;
717 ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin),
718 &sc->pf2vf_bulletin_mapping, "vf2pf_bull",
719 RTE_CACHE_LINE_SIZE);
723 sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *)
724 sc->pf2vf_bulletin_mapping.vaddr;
726 ret = bnx2x_vf_get_resources(sc, sc->max_tx_queues,
736 bnx2x_periodic_stop(eth_dev);
742 eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev)
744 struct bnx2x_softc *sc = eth_dev->data->dev_private;
745 PMD_INIT_FUNC_TRACE(sc);
746 return bnx2x_common_dev_init(eth_dev, 0);
750 eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev)
752 struct bnx2x_softc *sc = eth_dev->data->dev_private;
753 PMD_INIT_FUNC_TRACE(sc);
754 return bnx2x_common_dev_init(eth_dev, 1);
757 static int eth_bnx2x_dev_uninit(struct rte_eth_dev *eth_dev)
759 /* mac_addrs must not be freed alone because part of dev_private */
760 eth_dev->data->mac_addrs = NULL;
764 static struct rte_pci_driver rte_bnx2x_pmd;
765 static struct rte_pci_driver rte_bnx2xvf_pmd;
767 static int eth_bnx2x_pci_probe(struct rte_pci_driver *pci_drv,
768 struct rte_pci_device *pci_dev)
770 if (pci_drv == &rte_bnx2x_pmd)
771 return rte_eth_dev_pci_generic_probe(pci_dev,
772 sizeof(struct bnx2x_softc), eth_bnx2x_dev_init);
773 else if (pci_drv == &rte_bnx2xvf_pmd)
774 return rte_eth_dev_pci_generic_probe(pci_dev,
775 sizeof(struct bnx2x_softc), eth_bnx2xvf_dev_init);
780 static int eth_bnx2x_pci_remove(struct rte_pci_device *pci_dev)
782 return rte_eth_dev_pci_generic_remove(pci_dev, eth_bnx2x_dev_uninit);
785 static struct rte_pci_driver rte_bnx2x_pmd = {
786 .id_table = pci_id_bnx2x_map,
787 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
788 .probe = eth_bnx2x_pci_probe,
789 .remove = eth_bnx2x_pci_remove,
793 * virtual function driver struct
795 static struct rte_pci_driver rte_bnx2xvf_pmd = {
796 .id_table = pci_id_bnx2xvf_map,
797 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
798 .probe = eth_bnx2x_pci_probe,
799 .remove = eth_bnx2x_pci_remove,
802 RTE_PMD_REGISTER_PCI(net_bnx2x, rte_bnx2x_pmd);
803 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2x, pci_id_bnx2x_map);
804 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2x, "* igb_uio | uio_pci_generic | vfio-pci");
805 RTE_PMD_REGISTER_PCI(net_bnx2xvf, rte_bnx2xvf_pmd);
806 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2xvf, pci_id_bnx2xvf_map);
807 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2xvf, "* igb_uio | vfio-pci");
809 RTE_INIT(bnx2x_init_log)
811 bnx2x_logtype_init = rte_log_register("pmd.net.bnx2x.init");
812 if (bnx2x_logtype_init >= 0)
813 rte_log_set_level(bnx2x_logtype_init, RTE_LOG_NOTICE);
814 bnx2x_logtype_driver = rte_log_register("pmd.net.bnx2x.driver");
815 if (bnx2x_logtype_driver >= 0)
816 rte_log_set_level(bnx2x_logtype_driver, RTE_LOG_NOTICE);