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(sc);
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, sc, "Interrupt handled");
191 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
192 bnx2x_interrupt_action(dev);
193 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
194 rte_intr_enable(&sc->pci_dev->intr_handle);
197 static void bnx2x_periodic_start(void *param)
199 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
200 struct bnx2x_softc *sc = dev->data->dev_private;
203 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO);
204 bnx2x_interrupt_action(dev);
206 ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD,
207 bnx2x_periodic_start, (void *)dev);
209 PMD_DRV_LOG(ERR, sc, "Unable to start periodic"
210 " timer rc %d", ret);
211 assert(false && "Unable to start periodic timer");
216 void bnx2x_periodic_stop(void *param)
218 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
219 struct bnx2x_softc *sc = dev->data->dev_private;
221 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP);
223 rte_eal_alarm_cancel(bnx2x_periodic_start, (void *)dev);
227 * Devops - helper functions can be called from user application
231 bnx2x_dev_link_update(struct rte_eth_dev *dev,
232 __rte_unused int wait_to_complete)
234 #ifdef RTE_LIBRTE_BNX2X_DEBUG_INIT
235 struct bnx2x_softc *sc = dev->data->dev_private;
238 PMD_INIT_FUNC_TRACE(sc);
240 return bnx2x_link_update(dev);
244 bnx2xvf_dev_link_update(struct rte_eth_dev *dev,
245 __rte_unused int wait_to_complete)
247 struct bnx2x_softc *sc = dev->data->dev_private;
250 ret = bnx2x_link_update(dev);
252 bnx2x_check_bull(sc);
253 if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
254 PMD_DRV_LOG(ERR, sc, "PF indicated channel is down."
255 "VF device is no longer operational");
256 dev->data->dev_link.link_status = ETH_LINK_DOWN;
263 bnx2x_dev_configure(struct rte_eth_dev *dev)
265 struct bnx2x_softc *sc = dev->data->dev_private;
266 int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF);
268 PMD_INIT_FUNC_TRACE(sc);
270 if (dev->data->dev_conf.rxmode.jumbo_frame)
271 sc->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len;
273 if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) {
274 PMD_DRV_LOG(ERR, sc, "The number of TX queues is greater than number of RX queues");
278 sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
279 if (sc->num_queues > mp_ncpus) {
280 PMD_DRV_LOG(ERR, sc, "The number of queues is more than number of CPUs");
284 PMD_DRV_LOG(DEBUG, sc, "num_queues=%d, mtu=%d",
285 sc->num_queues, sc->mtu);
288 if (bnx2x_alloc_ilt_mem(sc) != 0) {
289 PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_ilt_mem was failed");
293 /* allocate the host hardware/software hsi structures */
294 if (bnx2x_alloc_hsi_mem(sc) != 0) {
295 PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_hsi_mem was failed");
296 bnx2x_free_ilt_mem(sc);
304 bnx2x_dev_start(struct rte_eth_dev *dev)
306 struct bnx2x_softc *sc = dev->data->dev_private;
309 PMD_INIT_FUNC_TRACE(sc);
311 /* start the periodic callout */
312 if (sc->periodic_flags & PERIODIC_STOP)
313 bnx2x_periodic_start(dev);
315 ret = bnx2x_init(sc);
317 PMD_DRV_LOG(DEBUG, sc, "bnx2x_init failed (%d)", ret);
322 rte_intr_callback_register(&sc->pci_dev->intr_handle,
323 bnx2x_interrupt_handler, (void *)dev);
325 if (rte_intr_enable(&sc->pci_dev->intr_handle))
326 PMD_DRV_LOG(ERR, sc, "rte_intr_enable failed");
329 ret = bnx2x_dev_rx_init(dev);
331 PMD_DRV_LOG(DEBUG, sc, "bnx2x_dev_rx_init returned error code");
335 /* Print important adapter info for the user. */
336 bnx2x_print_adapter_info(sc);
342 bnx2x_dev_stop(struct rte_eth_dev *dev)
344 struct bnx2x_softc *sc = dev->data->dev_private;
347 PMD_INIT_FUNC_TRACE(sc);
350 rte_intr_disable(&sc->pci_dev->intr_handle);
351 rte_intr_callback_unregister(&sc->pci_dev->intr_handle,
352 bnx2x_interrupt_handler, (void *)dev);
355 /* stop the periodic callout */
356 bnx2x_periodic_stop(dev);
358 ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE);
360 PMD_DRV_LOG(DEBUG, sc, "bnx2x_nic_unload failed (%d)", ret);
364 /* Update device link status */
366 bnx2x_dev_link_update(dev, 0);
368 bnx2xvf_dev_link_update(dev, 0);
374 bnx2x_dev_close(struct rte_eth_dev *dev)
376 struct bnx2x_softc *sc = dev->data->dev_private;
378 PMD_INIT_FUNC_TRACE(sc);
383 bnx2x_dev_clear_queues(dev);
384 memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link));
386 /* free the host hardware/software hsi structures */
387 bnx2x_free_hsi_mem(sc);
390 bnx2x_free_ilt_mem(sc);
394 bnx2x_promisc_enable(struct rte_eth_dev *dev)
396 struct bnx2x_softc *sc = dev->data->dev_private;
398 PMD_INIT_FUNC_TRACE(sc);
399 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
400 if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
401 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
402 bnx2x_set_rx_mode(sc);
406 bnx2x_promisc_disable(struct rte_eth_dev *dev)
408 struct bnx2x_softc *sc = dev->data->dev_private;
410 PMD_INIT_FUNC_TRACE(sc);
411 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
412 if (rte_eth_allmulticast_get(dev->data->port_id) == 1)
413 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
414 bnx2x_set_rx_mode(sc);
418 bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev)
420 struct bnx2x_softc *sc = dev->data->dev_private;
422 PMD_INIT_FUNC_TRACE(sc);
423 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
424 if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
425 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC;
426 bnx2x_set_rx_mode(sc);
430 bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev)
432 struct bnx2x_softc *sc = dev->data->dev_private;
434 PMD_INIT_FUNC_TRACE(sc);
435 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
436 if (rte_eth_promiscuous_get(dev->data->port_id) == 1)
437 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
438 bnx2x_set_rx_mode(sc);
442 bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
444 struct bnx2x_softc *sc = dev->data->dev_private;
445 uint32_t brb_truncate_discard;
447 uint64_t brb_truncates;
449 PMD_INIT_FUNC_TRACE(sc);
451 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
453 memset(stats, 0, sizeof (struct rte_eth_stats));
456 HILO_U64(sc->eth_stats.total_unicast_packets_received_hi,
457 sc->eth_stats.total_unicast_packets_received_lo) +
458 HILO_U64(sc->eth_stats.total_multicast_packets_received_hi,
459 sc->eth_stats.total_multicast_packets_received_lo) +
460 HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi,
461 sc->eth_stats.total_broadcast_packets_received_lo);
464 HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi,
465 sc->eth_stats.total_unicast_packets_transmitted_lo) +
466 HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi,
467 sc->eth_stats.total_multicast_packets_transmitted_lo) +
468 HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi,
469 sc->eth_stats.total_broadcast_packets_transmitted_lo);
472 HILO_U64(sc->eth_stats.total_bytes_received_hi,
473 sc->eth_stats.total_bytes_received_lo);
476 HILO_U64(sc->eth_stats.total_bytes_transmitted_hi,
477 sc->eth_stats.total_bytes_transmitted_lo);
480 HILO_U64(sc->eth_stats.error_bytes_received_hi,
481 sc->eth_stats.error_bytes_received_lo);
486 HILO_U64(sc->eth_stats.no_buff_discard_hi,
487 sc->eth_stats.no_buff_discard_lo);
490 HILO_U64(sc->eth_stats.brb_drop_hi,
491 sc->eth_stats.brb_drop_lo);
494 HILO_U64(sc->eth_stats.brb_truncate_hi,
495 sc->eth_stats.brb_truncate_lo);
497 brb_truncate_discard = sc->eth_stats.brb_truncate_discard;
499 stats->imissed = brb_drops + brb_truncates +
500 brb_truncate_discard + stats->rx_nombuf;
506 bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev,
507 struct rte_eth_xstat_name *xstats_names,
508 __rte_unused unsigned limit)
510 unsigned int i, stat_cnt = RTE_DIM(bnx2x_xstats_strings);
512 if (xstats_names != NULL)
513 for (i = 0; i < stat_cnt; i++)
514 snprintf(xstats_names[i].name,
515 sizeof(xstats_names[i].name),
517 bnx2x_xstats_strings[i].name);
523 bnx2x_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
526 struct bnx2x_softc *sc = dev->data->dev_private;
527 unsigned int num = RTE_DIM(bnx2x_xstats_strings);
532 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
534 for (num = 0; num < n; num++) {
535 if (bnx2x_xstats_strings[num].offset_hi !=
536 bnx2x_xstats_strings[num].offset_lo)
537 xstats[num].value = HILO_U64(
538 *(uint32_t *)((char *)&sc->eth_stats +
539 bnx2x_xstats_strings[num].offset_hi),
540 *(uint32_t *)((char *)&sc->eth_stats +
541 bnx2x_xstats_strings[num].offset_lo));
544 *(uint64_t *)((char *)&sc->eth_stats +
545 bnx2x_xstats_strings[num].offset_lo);
546 xstats[num].id = num;
553 bnx2x_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
555 struct bnx2x_softc *sc = dev->data->dev_private;
556 dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
557 dev_info->max_rx_queues = sc->max_rx_queues;
558 dev_info->max_tx_queues = sc->max_tx_queues;
559 dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
560 dev_info->max_rx_pktlen = BNX2X_MAX_RX_PKT_LEN;
561 dev_info->max_mac_addrs = BNX2X_MAX_MAC_ADDRS;
562 dev_info->speed_capa = ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G;
566 bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
567 uint32_t index, uint32_t pool)
569 struct bnx2x_softc *sc = dev->data->dev_private;
571 if (sc->mac_ops.mac_addr_add) {
572 sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool);
579 bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
581 struct bnx2x_softc *sc = dev->data->dev_private;
583 if (sc->mac_ops.mac_addr_remove)
584 sc->mac_ops.mac_addr_remove(dev, index);
587 static const struct eth_dev_ops bnx2x_eth_dev_ops = {
588 .dev_configure = bnx2x_dev_configure,
589 .dev_start = bnx2x_dev_start,
590 .dev_stop = bnx2x_dev_stop,
591 .dev_close = bnx2x_dev_close,
592 .promiscuous_enable = bnx2x_promisc_enable,
593 .promiscuous_disable = bnx2x_promisc_disable,
594 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
595 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
596 .link_update = bnx2x_dev_link_update,
597 .stats_get = bnx2x_dev_stats_get,
598 .xstats_get = bnx2x_dev_xstats_get,
599 .xstats_get_names = bnx2x_get_xstats_names,
600 .dev_infos_get = bnx2x_dev_infos_get,
601 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
602 .rx_queue_release = bnx2x_dev_rx_queue_release,
603 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
604 .tx_queue_release = bnx2x_dev_tx_queue_release,
605 .mac_addr_add = bnx2x_mac_addr_add,
606 .mac_addr_remove = bnx2x_mac_addr_remove,
610 * dev_ops for virtual function
612 static const struct eth_dev_ops bnx2xvf_eth_dev_ops = {
613 .dev_configure = bnx2x_dev_configure,
614 .dev_start = bnx2x_dev_start,
615 .dev_stop = bnx2x_dev_stop,
616 .dev_close = bnx2x_dev_close,
617 .promiscuous_enable = bnx2x_promisc_enable,
618 .promiscuous_disable = bnx2x_promisc_disable,
619 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
620 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
621 .link_update = bnx2xvf_dev_link_update,
622 .stats_get = bnx2x_dev_stats_get,
623 .xstats_get = bnx2x_dev_xstats_get,
624 .xstats_get_names = bnx2x_get_xstats_names,
625 .dev_infos_get = bnx2x_dev_infos_get,
626 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
627 .rx_queue_release = bnx2x_dev_rx_queue_release,
628 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
629 .tx_queue_release = bnx2x_dev_tx_queue_release,
630 .mac_addr_add = bnx2x_mac_addr_add,
631 .mac_addr_remove = bnx2x_mac_addr_remove,
636 bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
639 struct rte_pci_device *pci_dev;
640 struct rte_pci_addr pci_addr;
641 struct bnx2x_softc *sc;
643 /* Extract key data structures */
644 sc = eth_dev->data->dev_private;
645 pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
646 pci_addr = pci_dev->addr;
648 snprintf(sc->devinfo.name, NAME_SIZE, PCI_SHORT_PRI_FMT ":dpdk-port-%u",
649 pci_addr.bus, pci_addr.devid, pci_addr.function,
650 eth_dev->data->port_id);
652 PMD_INIT_FUNC_TRACE(sc);
654 eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
656 rte_eth_copy_pci_info(eth_dev, pci_dev);
658 sc->pcie_bus = pci_dev->addr.bus;
659 sc->pcie_device = pci_dev->addr.devid;
661 sc->devinfo.vendor_id = pci_dev->id.vendor_id;
662 sc->devinfo.device_id = pci_dev->id.device_id;
663 sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id;
664 sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id;
667 sc->flags = BNX2X_IS_VF_FLAG;
669 sc->pcie_func = pci_dev->addr.function;
670 sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr;
672 sc->bar[BAR1].base_addr = (void *)
673 ((uintptr_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START);
675 sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr;
677 assert(sc->bar[BAR0].base_addr);
678 assert(sc->bar[BAR1].base_addr);
680 bnx2x_load_firmware(sc);
681 assert(sc->firmware);
683 if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
686 sc->rx_budget = BNX2X_RX_BUDGET;
687 sc->hc_rx_ticks = BNX2X_RX_TICKS;
688 sc->hc_tx_ticks = BNX2X_TX_TICKS;
690 sc->interrupt_mode = INTR_MODE_SINGLE_MSIX;
691 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
693 sc->pci_dev = pci_dev;
694 ret = bnx2x_attach(sc);
696 PMD_DRV_LOG(ERR, sc, "bnx2x_attach failed (%d)", ret);
700 /* schedule periodic poll for slowpath link events */
702 ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD,
703 bnx2x_periodic_start, (void *)eth_dev);
705 PMD_DRV_LOG(ERR, sc, "Unable to start periodic"
706 " timer rc %d", ret);
711 eth_dev->data->mac_addrs = (struct ether_addr *)sc->link_params.mac_addr;
713 PMD_DRV_LOG(INFO, sc, "pcie_bus=%d, pcie_device=%d",
714 sc->pcie_bus, sc->pcie_device);
715 PMD_DRV_LOG(INFO, sc, "bar0.addr=%p, bar1.addr=%p",
716 sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr);
717 PMD_DRV_LOG(INFO, sc, "port=%d, path=%d, vnic=%d, func=%d",
718 PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc));
719 PMD_DRV_LOG(INFO, sc, "portID=%d vendorID=0x%x deviceID=0x%x",
720 eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id);
723 rte_spinlock_init(&sc->vf2pf_lock);
725 ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg),
726 &sc->vf2pf_mbox_mapping, "vf2pf_mbox",
727 RTE_CACHE_LINE_SIZE);
731 sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *)
732 sc->vf2pf_mbox_mapping.vaddr;
734 ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin),
735 &sc->pf2vf_bulletin_mapping, "vf2pf_bull",
736 RTE_CACHE_LINE_SIZE);
740 sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *)
741 sc->pf2vf_bulletin_mapping.vaddr;
743 ret = bnx2x_vf_get_resources(sc, sc->max_tx_queues,
752 bnx2x_periodic_stop(eth_dev);
757 eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev)
759 #ifdef RTE_LIBRTE_BNX2X_DEBUG_INIT
760 struct bnx2x_softc *sc = eth_dev->data->dev_private;
762 PMD_INIT_FUNC_TRACE(sc);
763 return bnx2x_common_dev_init(eth_dev, 0);
767 eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev)
769 #ifdef RTE_LIBRTE_BNX2X_DEBUG_INIT
770 struct bnx2x_softc *sc = eth_dev->data->dev_private;
772 PMD_INIT_FUNC_TRACE(sc);
773 return bnx2x_common_dev_init(eth_dev, 1);
776 static struct rte_pci_driver rte_bnx2x_pmd;
777 static struct rte_pci_driver rte_bnx2xvf_pmd;
779 static int eth_bnx2x_pci_probe(struct rte_pci_driver *pci_drv,
780 struct rte_pci_device *pci_dev)
782 struct rte_eth_dev *eth_dev;
785 eth_dev = rte_eth_dev_pci_allocate(pci_dev, sizeof(struct bnx2x_softc));
789 if (pci_drv == &rte_bnx2x_pmd)
790 ret = eth_bnx2x_dev_init(eth_dev);
791 else if (pci_drv == &rte_bnx2xvf_pmd)
792 ret = eth_bnx2xvf_dev_init(eth_dev);
797 rte_eth_dev_pci_release(eth_dev);
802 static int eth_bnx2x_pci_remove(struct rte_pci_device *pci_dev)
804 return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
807 static struct rte_pci_driver rte_bnx2x_pmd = {
808 .id_table = pci_id_bnx2x_map,
809 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
810 .probe = eth_bnx2x_pci_probe,
811 .remove = eth_bnx2x_pci_remove,
815 * virtual function driver struct
817 static struct rte_pci_driver rte_bnx2xvf_pmd = {
818 .id_table = pci_id_bnx2xvf_map,
819 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
820 .probe = eth_bnx2x_pci_probe,
821 .remove = eth_bnx2x_pci_remove,
824 RTE_PMD_REGISTER_PCI(net_bnx2x, rte_bnx2x_pmd);
825 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2x, pci_id_bnx2x_map);
826 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2x, "* igb_uio | uio_pci_generic | vfio-pci");
827 RTE_PMD_REGISTER_PCI(net_bnx2xvf, rte_bnx2xvf_pmd);
828 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2xvf, pci_id_bnx2xvf_map);
829 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2xvf, "* igb_uio | vfio-pci");