2 * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
4 * Copyright (c) 2015 QLogic Corporation.
8 * See LICENSE.bnx2x_pmd for copyright and licensing details.
12 #include "bnx2x_rxtx.h"
15 #include <rte_ethdev_pci.h>
16 #include <rte_alarm.h>
17 #include <rte_atomic.h>
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 * Atomically reads the link status information from global
85 * structure rte_eth_dev.
88 * - Pointer to the structure rte_eth_dev to read from.
89 * - Pointer to the buffer to be saved with the link status.
93 * - On failure, negative value.
96 bnx2x_dev_atomic_read_link_status(struct rte_eth_dev *dev,
97 struct rte_eth_link *link)
99 struct rte_eth_link *dst = link;
100 struct rte_eth_link *src = &dev->data->dev_link;
102 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
103 *(uint64_t *)src) == 0)
110 * Atomically writes the link status information into global
111 * structure rte_eth_dev.
114 * - Pointer to the structure rte_eth_dev to read from.
115 * - Pointer to the buffer to be saved with the link status.
118 * - On success, zero.
119 * - On failure, negative value.
122 bnx2x_dev_atomic_write_link_status(struct rte_eth_dev *dev,
123 struct rte_eth_link *link)
125 struct rte_eth_link *dst = &dev->data->dev_link;
126 struct rte_eth_link *src = link;
128 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
129 *(uint64_t *)src) == 0)
136 bnx2x_link_update(struct rte_eth_dev *dev)
138 struct bnx2x_softc *sc = dev->data->dev_private;
139 struct rte_eth_link orig;
140 struct rte_eth_link link;
142 PMD_INIT_FUNC_TRACE();
144 bnx2x_link_status_update(sc);
145 memset(&orig, 0, sizeof(orig));
146 memset(&link, 0, sizeof(link));
147 bnx2x_dev_atomic_read_link_status(dev, &orig);
149 link.link_speed = sc->link_vars.line_speed;
150 switch (sc->link_vars.duplex) {
152 link.link_duplex = ETH_LINK_FULL_DUPLEX;
155 link.link_duplex = ETH_LINK_HALF_DUPLEX;
158 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
159 ETH_LINK_SPEED_FIXED);
160 link.link_status = sc->link_vars.link_up;
161 bnx2x_dev_atomic_write_link_status(dev, &link);
163 return (link.link_status == orig.link_status) ? -1 : 0;
167 bnx2x_interrupt_action(struct rte_eth_dev *dev)
169 struct bnx2x_softc *sc = dev->data->dev_private;
170 uint32_t link_status;
172 bnx2x_intr_legacy(sc, 0);
174 if (sc->periodic_flags & PERIODIC_GO)
175 bnx2x_periodic_callout(sc);
176 link_status = REG_RD(sc, sc->link_params.shmem_base +
177 offsetof(struct shmem_region,
178 port_mb[sc->link_params.port].link_status));
179 if ((link_status & LINK_STATUS_LINK_UP) != dev->data->dev_link.link_status)
180 bnx2x_link_update(dev);
184 bnx2x_interrupt_handler(void *param)
186 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
187 struct bnx2x_softc *sc = dev->data->dev_private;
189 PMD_DEBUG_PERIODIC_LOG(INFO, "Interrupt handled");
191 bnx2x_interrupt_action(dev);
192 rte_intr_enable(&sc->pci_dev->intr_handle);
195 static void bnx2x_periodic_start(void *param)
197 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
198 struct bnx2x_softc *sc = dev->data->dev_private;
201 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
202 bnx2x_interrupt_action(dev);
204 ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD,
205 bnx2x_periodic_start, (void *)dev);
207 PMD_DRV_LOG(ERR, "Unable to start periodic"
208 " timer rc %d", ret);
209 assert(false && "Unable to start periodic timer");
214 void bnx2x_periodic_stop(void *param)
216 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
217 struct bnx2x_softc *sc = dev->data->dev_private;
219 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
221 rte_eal_alarm_cancel(bnx2x_periodic_start, (void *)dev);
225 * Devops - helper functions can be called from user application
229 bnx2x_dev_link_update(struct rte_eth_dev *dev,
230 __rte_unused int wait_to_complete)
232 PMD_INIT_FUNC_TRACE();
234 return bnx2x_link_update(dev);
238 bnx2xvf_dev_link_update(struct rte_eth_dev *dev,
239 __rte_unused int wait_to_complete)
241 struct bnx2x_softc *sc = dev->data->dev_private;
244 ret = bnx2x_link_update(dev);
246 bnx2x_check_bull(sc);
247 if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
248 PMD_DRV_LOG(ERR, "PF indicated channel is down."
249 "VF device is no longer operational");
250 dev->data->dev_link.link_status = ETH_LINK_DOWN;
257 bnx2x_dev_configure(struct rte_eth_dev *dev)
259 struct bnx2x_softc *sc = dev->data->dev_private;
260 int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF);
262 PMD_INIT_FUNC_TRACE();
264 if (dev->data->dev_conf.rxmode.jumbo_frame)
265 sc->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len;
267 if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) {
268 PMD_DRV_LOG(ERR, "The number of TX queues is greater than number of RX queues");
272 sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
273 if (sc->num_queues > mp_ncpus) {
274 PMD_DRV_LOG(ERR, "The number of queues is more than number of CPUs");
278 PMD_DRV_LOG(DEBUG, "num_queues=%d, mtu=%d",
279 sc->num_queues, sc->mtu);
282 if (bnx2x_alloc_ilt_mem(sc) != 0) {
283 PMD_DRV_LOG(ERR, "bnx2x_alloc_ilt_mem was failed");
287 /* allocate the host hardware/software hsi structures */
288 if (bnx2x_alloc_hsi_mem(sc) != 0) {
289 PMD_DRV_LOG(ERR, "bnx2x_alloc_hsi_mem was failed");
290 bnx2x_free_ilt_mem(sc);
298 bnx2x_dev_start(struct rte_eth_dev *dev)
300 struct bnx2x_softc *sc = dev->data->dev_private;
303 PMD_INIT_FUNC_TRACE();
305 /* start the periodic callout */
306 if (sc->periodic_flags & PERIODIC_STOP)
307 bnx2x_periodic_start(dev);
309 ret = bnx2x_init(sc);
311 PMD_DRV_LOG(DEBUG, "bnx2x_init failed (%d)", ret);
316 rte_intr_callback_register(&sc->pci_dev->intr_handle,
317 bnx2x_interrupt_handler, (void *)dev);
319 if (rte_intr_enable(&sc->pci_dev->intr_handle))
320 PMD_DRV_LOG(ERR, "rte_intr_enable failed");
323 ret = bnx2x_dev_rx_init(dev);
325 PMD_DRV_LOG(DEBUG, "bnx2x_dev_rx_init returned error code");
329 /* Print important adapter info for the user. */
330 bnx2x_print_adapter_info(sc);
336 bnx2x_dev_stop(struct rte_eth_dev *dev)
338 struct bnx2x_softc *sc = dev->data->dev_private;
341 PMD_INIT_FUNC_TRACE();
344 rte_intr_disable(&sc->pci_dev->intr_handle);
345 rte_intr_callback_unregister(&sc->pci_dev->intr_handle,
346 bnx2x_interrupt_handler, (void *)dev);
349 /* stop the periodic callout */
350 bnx2x_periodic_stop(dev);
352 ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE);
354 PMD_DRV_LOG(DEBUG, "bnx2x_nic_unload failed (%d)", ret);
358 /* Update device link status */
360 bnx2x_dev_link_update(dev, 0);
362 bnx2xvf_dev_link_update(dev, 0);
368 bnx2x_dev_close(struct rte_eth_dev *dev)
370 struct bnx2x_softc *sc = dev->data->dev_private;
372 PMD_INIT_FUNC_TRACE();
377 bnx2x_dev_clear_queues(dev);
378 memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link));
380 /* free the host hardware/software hsi structures */
381 bnx2x_free_hsi_mem(sc);
384 bnx2x_free_ilt_mem(sc);
388 bnx2x_promisc_enable(struct rte_eth_dev *dev)
390 struct bnx2x_softc *sc = dev->data->dev_private;
392 PMD_INIT_FUNC_TRACE();
393 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
394 if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
395 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
396 bnx2x_set_rx_mode(sc);
400 bnx2x_promisc_disable(struct rte_eth_dev *dev)
402 struct bnx2x_softc *sc = dev->data->dev_private;
404 PMD_INIT_FUNC_TRACE();
405 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
406 if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
407 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
408 bnx2x_set_rx_mode(sc);
412 bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev)
414 struct bnx2x_softc *sc = dev->data->dev_private;
416 PMD_INIT_FUNC_TRACE();
417 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
418 if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
419 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
420 bnx2x_set_rx_mode(sc);
424 bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev)
426 struct bnx2x_softc *sc = dev->data->dev_private;
428 PMD_INIT_FUNC_TRACE();
429 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
430 if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
431 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
432 bnx2x_set_rx_mode(sc);
436 bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
438 struct bnx2x_softc *sc = dev->data->dev_private;
439 uint32_t brb_truncate_discard;
441 uint64_t brb_truncates;
443 PMD_INIT_FUNC_TRACE();
445 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
447 memset(stats, 0, sizeof (struct rte_eth_stats));
450 HILO_U64(sc->eth_stats.total_unicast_packets_received_hi,
451 sc->eth_stats.total_unicast_packets_received_lo) +
452 HILO_U64(sc->eth_stats.total_multicast_packets_received_hi,
453 sc->eth_stats.total_multicast_packets_received_lo) +
454 HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi,
455 sc->eth_stats.total_broadcast_packets_received_lo);
458 HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi,
459 sc->eth_stats.total_unicast_packets_transmitted_lo) +
460 HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi,
461 sc->eth_stats.total_multicast_packets_transmitted_lo) +
462 HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi,
463 sc->eth_stats.total_broadcast_packets_transmitted_lo);
466 HILO_U64(sc->eth_stats.total_bytes_received_hi,
467 sc->eth_stats.total_bytes_received_lo);
470 HILO_U64(sc->eth_stats.total_bytes_transmitted_hi,
471 sc->eth_stats.total_bytes_transmitted_lo);
474 HILO_U64(sc->eth_stats.error_bytes_received_hi,
475 sc->eth_stats.error_bytes_received_lo);
480 HILO_U64(sc->eth_stats.no_buff_discard_hi,
481 sc->eth_stats.no_buff_discard_lo);
484 HILO_U64(sc->eth_stats.brb_drop_hi,
485 sc->eth_stats.brb_drop_lo);
488 HILO_U64(sc->eth_stats.brb_truncate_hi,
489 sc->eth_stats.brb_truncate_lo);
491 brb_truncate_discard = sc->eth_stats.brb_truncate_discard;
493 stats->imissed = brb_drops + brb_truncates +
494 brb_truncate_discard + stats->rx_nombuf;
500 bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev,
501 struct rte_eth_xstat_name *xstats_names,
502 __rte_unused unsigned limit)
504 unsigned int i, stat_cnt = RTE_DIM(bnx2x_xstats_strings);
506 if (xstats_names != NULL)
507 for (i = 0; i < stat_cnt; i++)
508 snprintf(xstats_names[i].name,
509 sizeof(xstats_names[i].name),
511 bnx2x_xstats_strings[i].name);
517 bnx2x_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
520 struct bnx2x_softc *sc = dev->data->dev_private;
521 unsigned int num = RTE_DIM(bnx2x_xstats_strings);
526 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
528 for (num = 0; num < n; num++) {
529 if (bnx2x_xstats_strings[num].offset_hi !=
530 bnx2x_xstats_strings[num].offset_lo)
531 xstats[num].value = HILO_U64(
532 *(uint32_t *)((char *)&sc->eth_stats +
533 bnx2x_xstats_strings[num].offset_hi),
534 *(uint32_t *)((char *)&sc->eth_stats +
535 bnx2x_xstats_strings[num].offset_lo));
538 *(uint64_t *)((char *)&sc->eth_stats +
539 bnx2x_xstats_strings[num].offset_lo);
540 xstats[num].id = num;
547 bnx2x_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
549 struct bnx2x_softc *sc = dev->data->dev_private;
550 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
551 dev_info->max_rx_queues = sc->max_rx_queues;
552 dev_info->max_tx_queues = sc->max_tx_queues;
553 dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
554 dev_info->max_rx_pktlen = BNX2X_MAX_RX_PKT_LEN;
555 dev_info->max_mac_addrs = BNX2X_MAX_MAC_ADDRS;
556 dev_info->speed_capa = ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G;
560 bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
561 uint32_t index, uint32_t pool)
563 struct bnx2x_softc *sc = dev->data->dev_private;
565 if (sc->mac_ops.mac_addr_add) {
566 sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool);
573 bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
575 struct bnx2x_softc *sc = dev->data->dev_private;
577 if (sc->mac_ops.mac_addr_remove)
578 sc->mac_ops.mac_addr_remove(dev, index);
581 static const struct eth_dev_ops bnx2x_eth_dev_ops = {
582 .dev_configure = bnx2x_dev_configure,
583 .dev_start = bnx2x_dev_start,
584 .dev_stop = bnx2x_dev_stop,
585 .dev_close = bnx2x_dev_close,
586 .promiscuous_enable = bnx2x_promisc_enable,
587 .promiscuous_disable = bnx2x_promisc_disable,
588 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
589 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
590 .link_update = bnx2x_dev_link_update,
591 .stats_get = bnx2x_dev_stats_get,
592 .xstats_get = bnx2x_dev_xstats_get,
593 .xstats_get_names = bnx2x_get_xstats_names,
594 .dev_infos_get = bnx2x_dev_infos_get,
595 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
596 .rx_queue_release = bnx2x_dev_rx_queue_release,
597 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
598 .tx_queue_release = bnx2x_dev_tx_queue_release,
599 .mac_addr_add = bnx2x_mac_addr_add,
600 .mac_addr_remove = bnx2x_mac_addr_remove,
604 * dev_ops for virtual function
606 static const struct eth_dev_ops bnx2xvf_eth_dev_ops = {
607 .dev_configure = bnx2x_dev_configure,
608 .dev_start = bnx2x_dev_start,
609 .dev_stop = bnx2x_dev_stop,
610 .dev_close = bnx2x_dev_close,
611 .promiscuous_enable = bnx2x_promisc_enable,
612 .promiscuous_disable = bnx2x_promisc_disable,
613 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
614 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
615 .link_update = bnx2xvf_dev_link_update,
616 .stats_get = bnx2x_dev_stats_get,
617 .xstats_get = bnx2x_dev_xstats_get,
618 .xstats_get_names = bnx2x_get_xstats_names,
619 .dev_infos_get = bnx2x_dev_infos_get,
620 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
621 .rx_queue_release = bnx2x_dev_rx_queue_release,
622 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
623 .tx_queue_release = bnx2x_dev_tx_queue_release,
624 .mac_addr_add = bnx2x_mac_addr_add,
625 .mac_addr_remove = bnx2x_mac_addr_remove,
630 bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
633 struct rte_pci_device *pci_dev;
634 struct bnx2x_softc *sc;
636 PMD_INIT_FUNC_TRACE();
638 eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
639 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
641 rte_eth_copy_pci_info(eth_dev, pci_dev);
643 sc = eth_dev->data->dev_private;
644 sc->pcie_bus = pci_dev->addr.bus;
645 sc->pcie_device = pci_dev->addr.devid;
648 sc->flags = BNX2X_IS_VF_FLAG;
650 sc->devinfo.vendor_id = pci_dev->id.vendor_id;
651 sc->devinfo.device_id = pci_dev->id.device_id;
652 sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id;
653 sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id;
655 sc->pcie_func = pci_dev->addr.function;
656 sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr;
658 sc->bar[BAR1].base_addr = (void *)
659 ((uintptr_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START);
661 sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr;
663 assert(sc->bar[BAR0].base_addr);
664 assert(sc->bar[BAR1].base_addr);
666 bnx2x_load_firmware(sc);
667 assert(sc->firmware);
669 if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
672 sc->rx_budget = BNX2X_RX_BUDGET;
673 sc->hc_rx_ticks = BNX2X_RX_TICKS;
674 sc->hc_tx_ticks = BNX2X_TX_TICKS;
676 sc->interrupt_mode = INTR_MODE_SINGLE_MSIX;
677 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
679 sc->pci_dev = pci_dev;
680 ret = bnx2x_attach(sc);
682 PMD_DRV_LOG(ERR, "bnx2x_attach failed (%d)", ret);
686 /* schedule periodic poll for slowpath link events */
688 ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD,
689 bnx2x_periodic_start, (void *)eth_dev);
691 PMD_DRV_LOG(ERR, "Unable to start periodic"
692 " timer rc %d", ret);
697 eth_dev->data->mac_addrs = (struct ether_addr *)sc->link_params.mac_addr;
699 PMD_DRV_LOG(INFO, "pcie_bus=%d, pcie_device=%d",
700 sc->pcie_bus, sc->pcie_device);
701 PMD_DRV_LOG(INFO, "bar0.addr=%p, bar1.addr=%p",
702 sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr);
703 PMD_DRV_LOG(INFO, "port=%d, path=%d, vnic=%d, func=%d",
704 PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc));
705 PMD_DRV_LOG(INFO, "portID=%d vendorID=0x%x deviceID=0x%x",
706 eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id);
709 rte_spinlock_init(&sc->vf2pf_lock);
711 ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg),
712 &sc->vf2pf_mbox_mapping, "vf2pf_mbox",
713 RTE_CACHE_LINE_SIZE);
717 sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *)
718 sc->vf2pf_mbox_mapping.vaddr;
720 ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin),
721 &sc->pf2vf_bulletin_mapping, "vf2pf_bull",
722 RTE_CACHE_LINE_SIZE);
726 sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *)
727 sc->pf2vf_bulletin_mapping.vaddr;
729 ret = bnx2x_vf_get_resources(sc, sc->max_tx_queues,
738 bnx2x_periodic_stop(eth_dev);
743 eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev)
745 PMD_INIT_FUNC_TRACE();
746 return bnx2x_common_dev_init(eth_dev, 0);
750 eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev)
752 PMD_INIT_FUNC_TRACE();
753 return bnx2x_common_dev_init(eth_dev, 1);
756 static struct rte_pci_driver rte_bnx2x_pmd;
757 static struct rte_pci_driver rte_bnx2xvf_pmd;
759 static int eth_bnx2x_pci_probe(struct rte_pci_driver *pci_drv,
760 struct rte_pci_device *pci_dev)
762 struct rte_eth_dev *eth_dev;
765 eth_dev = rte_eth_dev_pci_allocate(pci_dev, sizeof(struct bnx2x_softc));
769 if (pci_drv == &rte_bnx2x_pmd)
770 ret = eth_bnx2x_dev_init(eth_dev);
771 else if (pci_drv == &rte_bnx2xvf_pmd)
772 ret = eth_bnx2xvf_dev_init(eth_dev);
777 rte_eth_dev_pci_release(eth_dev);
782 static int eth_bnx2x_pci_remove(struct rte_pci_device *pci_dev)
784 return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
787 static struct rte_pci_driver rte_bnx2x_pmd = {
788 .id_table = pci_id_bnx2x_map,
789 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
790 .probe = eth_bnx2x_pci_probe,
791 .remove = eth_bnx2x_pci_remove,
795 * virtual function driver struct
797 static struct rte_pci_driver rte_bnx2xvf_pmd = {
798 .id_table = pci_id_bnx2xvf_map,
799 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
800 .probe = eth_bnx2x_pci_probe,
801 .remove = eth_bnx2x_pci_remove,
804 RTE_PMD_REGISTER_PCI(net_bnx2x, rte_bnx2x_pmd);
805 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2x, pci_id_bnx2x_map);
806 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2x, "* igb_uio | uio_pci_generic | vfio-pci");
807 RTE_PMD_REGISTER_PCI(net_bnx2xvf, rte_bnx2xvf_pmd);
808 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2xvf, pci_id_bnx2xvf_map);
809 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2xvf, "* igb_uio | vfio-pci");