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"
17 * The set of PCI devices this driver supports
19 static struct rte_pci_id pci_id_bnx2x_map[] = {
20 #define RTE_PCI_DEV_ID_DECL_BNX2X(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
21 #include "rte_pci_dev_ids.h"
25 static struct rte_pci_id pci_id_bnx2xvf_map[] = {
26 #define RTE_PCI_DEV_ID_DECL_BNX2XVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
27 #include "rte_pci_dev_ids.h"
32 bnx2x_link_update(struct rte_eth_dev *dev)
34 struct bnx2x_softc *sc = dev->data->dev_private;
36 PMD_INIT_FUNC_TRACE();
37 bnx2x_link_status_update(sc);
39 dev->data->dev_link.link_speed = sc->link_vars.line_speed;
40 switch (sc->link_vars.duplex) {
42 dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
45 dev->data->dev_link.link_duplex = ETH_LINK_HALF_DUPLEX;
48 dev->data->dev_link.link_duplex = ETH_LINK_AUTONEG_DUPLEX;
50 dev->data->dev_link.link_status = sc->link_vars.link_up;
54 bnx2x_interrupt_action(struct rte_eth_dev *dev)
56 struct bnx2x_softc *sc = dev->data->dev_private;
59 PMD_DEBUG_PERIODIC_LOG(INFO, "Interrupt handled");
61 if (bnx2x_intr_legacy(sc, 0))
63 if (sc->periodic_flags & PERIODIC_GO)
64 bnx2x_periodic_callout(sc);
65 link_status = REG_RD(sc, sc->link_params.shmem_base +
66 offsetof(struct shmem_region,
67 port_mb[sc->link_params.port].link_status));
68 if ((link_status & LINK_STATUS_LINK_UP) != dev->data->dev_link.link_status)
69 bnx2x_link_update(dev);
72 static __rte_unused void
73 bnx2x_interrupt_handler(__rte_unused struct rte_intr_handle *handle, void *param)
75 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
77 bnx2x_interrupt_action(dev);
78 rte_intr_enable(&(dev->pci_dev->intr_handle));
82 * Devops - helper functions can be called from user application
86 bnx2x_dev_configure(struct rte_eth_dev *dev)
88 struct bnx2x_softc *sc = dev->data->dev_private;
89 int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF);
92 PMD_INIT_FUNC_TRACE();
94 if (dev->data->dev_conf.rxmode.jumbo_frame)
95 sc->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len;
97 if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) {
98 PMD_DRV_LOG(ERR, "The number of TX queues is greater than number of RX queues");
102 sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
103 if (sc->num_queues > mp_ncpus) {
104 PMD_DRV_LOG(ERR, "The number of queues is more than number of CPUs");
108 PMD_DRV_LOG(DEBUG, "num_queues=%d, mtu=%d",
109 sc->num_queues, sc->mtu);
112 if (bnx2x_alloc_ilt_mem(sc) != 0) {
113 PMD_DRV_LOG(ERR, "bnx2x_alloc_ilt_mem was failed");
117 /* allocate the host hardware/software hsi structures */
118 if (bnx2x_alloc_hsi_mem(sc) != 0) {
119 PMD_DRV_LOG(ERR, "bnx2x_alloc_hsi_mem was failed");
120 bnx2x_free_ilt_mem(sc);
125 if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg),
126 &sc->vf2pf_mbox_mapping, "vf2pf_mbox",
127 RTE_CACHE_LINE_SIZE) != 0)
130 sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *)sc->vf2pf_mbox_mapping.vaddr;
131 if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin),
132 &sc->pf2vf_bulletin_mapping, "vf2pf_bull",
133 RTE_CACHE_LINE_SIZE) != 0)
136 sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *)sc->pf2vf_bulletin_mapping.vaddr;
138 ret = bnx2x_vf_get_resources(sc, sc->num_queues, sc->num_queues);
147 bnx2x_dev_start(struct rte_eth_dev *dev)
149 struct bnx2x_softc *sc = dev->data->dev_private;
152 PMD_INIT_FUNC_TRACE();
154 ret = bnx2x_init(sc);
156 PMD_DRV_LOG(DEBUG, "bnx2x_init failed (%d)", ret);
161 rte_intr_callback_register(&(dev->pci_dev->intr_handle),
162 bnx2x_interrupt_handler, (void *)dev);
164 if(rte_intr_enable(&(dev->pci_dev->intr_handle)))
165 PMD_DRV_LOG(ERR, "rte_intr_enable failed");
168 ret = bnx2x_dev_rx_init(dev);
170 PMD_DRV_LOG(DEBUG, "bnx2x_dev_rx_init returned error code");
174 /* Print important adapter info for the user. */
175 bnx2x_print_adapter_info(sc);
183 bnx2x_dev_stop(struct rte_eth_dev *dev)
185 struct bnx2x_softc *sc = dev->data->dev_private;
188 PMD_INIT_FUNC_TRACE();
191 rte_intr_disable(&(dev->pci_dev->intr_handle));
192 rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
193 bnx2x_interrupt_handler, (void *)dev);
196 ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE);
198 PMD_DRV_LOG(DEBUG, "bnx2x_nic_unload failed (%d)", ret);
206 bnx2x_dev_close(struct rte_eth_dev *dev)
208 struct bnx2x_softc *sc = dev->data->dev_private;
210 PMD_INIT_FUNC_TRACE();
215 bnx2x_dev_clear_queues(dev);
216 memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link));
218 /* free the host hardware/software hsi structures */
219 bnx2x_free_hsi_mem(sc);
222 bnx2x_free_ilt_mem(sc);
226 bnx2x_promisc_enable(struct rte_eth_dev *dev)
228 struct bnx2x_softc *sc = dev->data->dev_private;
230 PMD_INIT_FUNC_TRACE();
231 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
232 bnx2x_set_rx_mode(sc);
236 bnx2x_promisc_disable(struct rte_eth_dev *dev)
238 struct bnx2x_softc *sc = dev->data->dev_private;
240 PMD_INIT_FUNC_TRACE();
241 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
242 bnx2x_set_rx_mode(sc);
246 bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev)
248 struct bnx2x_softc *sc = dev->data->dev_private;
250 PMD_INIT_FUNC_TRACE();
251 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
252 bnx2x_set_rx_mode(sc);
256 bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev)
258 struct bnx2x_softc *sc = dev->data->dev_private;
260 PMD_INIT_FUNC_TRACE();
261 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
262 bnx2x_set_rx_mode(sc);
266 bnx2x_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
268 PMD_INIT_FUNC_TRACE();
270 int old_link_status = dev->data->dev_link.link_status;
272 bnx2x_link_update(dev);
274 return old_link_status == dev->data->dev_link.link_status ? -1 : 0;
278 bnx2xvf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
280 int old_link_status = dev->data->dev_link.link_status;
281 struct bnx2x_softc *sc = dev->data->dev_private;
283 bnx2x_link_update(dev);
285 bnx2x_check_bull(sc);
286 if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
287 PMD_DRV_LOG(ERR, "PF indicated channel is down."
288 "VF device is no longer operational");
289 dev->data->dev_link.link_status = 0;
292 return old_link_status == dev->data->dev_link.link_status ? -1 : 0;
296 bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
298 struct bnx2x_softc *sc = dev->data->dev_private;
300 PMD_INIT_FUNC_TRACE();
302 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
304 memset(stats, 0, sizeof (struct rte_eth_stats));
307 HILO_U64(sc->eth_stats.total_unicast_packets_received_hi,
308 sc->eth_stats.total_unicast_packets_received_lo) +
309 HILO_U64(sc->eth_stats.total_multicast_packets_received_hi,
310 sc->eth_stats.total_multicast_packets_received_lo) +
311 HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi,
312 sc->eth_stats.total_broadcast_packets_received_lo);
315 HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi,
316 sc->eth_stats.total_unicast_packets_transmitted_lo) +
317 HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi,
318 sc->eth_stats.total_multicast_packets_transmitted_lo) +
319 HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi,
320 sc->eth_stats.total_broadcast_packets_transmitted_lo);
323 HILO_U64(sc->eth_stats.total_bytes_received_hi,
324 sc->eth_stats.total_bytes_received_lo);
327 HILO_U64(sc->eth_stats.total_bytes_transmitted_hi,
328 sc->eth_stats.total_bytes_transmitted_lo);
331 HILO_U64(sc->eth_stats.error_bytes_received_hi,
332 sc->eth_stats.error_bytes_received_lo);
337 HILO_U64(sc->eth_stats.no_buff_discard_hi,
338 sc->eth_stats.no_buff_discard_lo);
342 bnx2x_dev_infos_get(struct rte_eth_dev *dev, __rte_unused struct rte_eth_dev_info *dev_info)
344 struct bnx2x_softc *sc = dev->data->dev_private;
345 dev_info->max_rx_queues = sc->max_rx_queues;
346 dev_info->max_tx_queues = sc->max_tx_queues;
347 dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
348 dev_info->max_rx_pktlen = BNX2X_MAX_RX_PKT_LEN;
349 dev_info->max_mac_addrs = BNX2X_MAX_MAC_ADDRS;
353 bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
354 uint32_t index, uint32_t pool)
356 struct bnx2x_softc *sc = dev->data->dev_private;
358 if (sc->mac_ops.mac_addr_add)
359 sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool);
363 bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
365 struct bnx2x_softc *sc = dev->data->dev_private;
367 if (sc->mac_ops.mac_addr_remove)
368 sc->mac_ops.mac_addr_remove(dev, index);
371 static struct eth_dev_ops bnx2x_eth_dev_ops = {
372 .dev_configure = bnx2x_dev_configure,
373 .dev_start = bnx2x_dev_start,
374 .dev_stop = bnx2x_dev_stop,
375 .dev_close = bnx2x_dev_close,
376 .promiscuous_enable = bnx2x_promisc_enable,
377 .promiscuous_disable = bnx2x_promisc_disable,
378 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
379 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
380 .link_update = bnx2x_dev_link_update,
381 .stats_get = bnx2x_dev_stats_get,
382 .dev_infos_get = bnx2x_dev_infos_get,
383 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
384 .rx_queue_release = bnx2x_dev_rx_queue_release,
385 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
386 .tx_queue_release = bnx2x_dev_tx_queue_release,
387 .mac_addr_add = bnx2x_mac_addr_add,
388 .mac_addr_remove = bnx2x_mac_addr_remove,
392 * dev_ops for virtual function
394 static struct eth_dev_ops bnx2xvf_eth_dev_ops = {
395 .dev_configure = bnx2x_dev_configure,
396 .dev_start = bnx2x_dev_start,
397 .dev_stop = bnx2x_dev_stop,
398 .dev_close = bnx2x_dev_close,
399 .promiscuous_enable = bnx2x_promisc_enable,
400 .promiscuous_disable = bnx2x_promisc_disable,
401 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
402 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
403 .link_update = bnx2xvf_dev_link_update,
404 .stats_get = bnx2x_dev_stats_get,
405 .dev_infos_get = bnx2x_dev_infos_get,
406 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
407 .rx_queue_release = bnx2x_dev_rx_queue_release,
408 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
409 .tx_queue_release = bnx2x_dev_tx_queue_release,
410 .mac_addr_add = bnx2x_mac_addr_add,
411 .mac_addr_remove = bnx2x_mac_addr_remove,
416 bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
419 struct rte_pci_device *pci_dev;
420 struct bnx2x_softc *sc;
422 PMD_INIT_FUNC_TRACE();
424 eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
425 pci_dev = eth_dev->pci_dev;
427 rte_eth_copy_pci_info(eth_dev, pci_dev);
429 sc = eth_dev->data->dev_private;
430 sc->pcie_bus = pci_dev->addr.bus;
431 sc->pcie_device = pci_dev->addr.devid;
434 sc->flags = BNX2X_IS_VF_FLAG;
436 sc->devinfo.vendor_id = pci_dev->id.vendor_id;
437 sc->devinfo.device_id = pci_dev->id.device_id;
438 sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id;
439 sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id;
441 sc->pcie_func = pci_dev->addr.function;
442 sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr;
444 sc->bar[BAR1].base_addr = (void *)
445 ((uint64_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START);
447 sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr;
449 assert(sc->bar[BAR0].base_addr);
450 assert(sc->bar[BAR1].base_addr);
452 bnx2x_load_firmware(sc);
453 assert(sc->firmware);
455 if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
458 sc->rx_budget = BNX2X_RX_BUDGET;
459 sc->hc_rx_ticks = BNX2X_RX_TICKS;
460 sc->hc_tx_ticks = BNX2X_TX_TICKS;
462 sc->interrupt_mode = INTR_MODE_SINGLE_MSIX;
463 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
465 sc->pci_dev = pci_dev;
466 ret = bnx2x_attach(sc);
468 PMD_DRV_LOG(ERR, "bnx2x_attach failed (%d)", ret);
471 eth_dev->data->mac_addrs = (struct ether_addr *)sc->link_params.mac_addr;
473 PMD_DRV_LOG(INFO, "pcie_bus=%d, pcie_device=%d",
474 sc->pcie_bus, sc->pcie_device);
475 PMD_DRV_LOG(INFO, "bar0.addr=%p, bar1.addr=%p",
476 sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr);
477 PMD_DRV_LOG(INFO, "port=%d, path=%d, vnic=%d, func=%d",
478 PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc));
479 PMD_DRV_LOG(INFO, "portID=%d vendorID=0x%x deviceID=0x%x",
480 eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id);
486 eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev)
488 PMD_INIT_FUNC_TRACE();
489 return bnx2x_common_dev_init(eth_dev, 0);
493 eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev)
495 PMD_INIT_FUNC_TRACE();
496 return bnx2x_common_dev_init(eth_dev, 1);
499 static struct eth_driver rte_bnx2x_pmd = {
501 .name = "rte_bnx2x_pmd",
502 .id_table = pci_id_bnx2x_map,
503 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
505 .eth_dev_init = eth_bnx2x_dev_init,
506 .dev_private_size = sizeof(struct bnx2x_softc),
510 * virtual function driver struct
512 static struct eth_driver rte_bnx2xvf_pmd = {
514 .name = "rte_bnx2xvf_pmd",
515 .id_table = pci_id_bnx2xvf_map,
516 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
518 .eth_dev_init = eth_bnx2xvf_dev_init,
519 .dev_private_size = sizeof(struct bnx2x_softc),
522 static int rte_bnx2x_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
524 PMD_INIT_FUNC_TRACE();
525 rte_eth_driver_register(&rte_bnx2x_pmd);
530 static int rte_bnx2xvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
532 PMD_INIT_FUNC_TRACE();
533 rte_eth_driver_register(&rte_bnx2xvf_pmd);
538 static struct rte_driver rte_bnx2x_driver = {
540 .init = rte_bnx2x_pmd_init,
543 static struct rte_driver rte_bnx2xvf_driver = {
545 .init = rte_bnx2xvf_pmd_init,
548 PMD_REGISTER_DRIVER(rte_bnx2x_driver);
549 PMD_REGISTER_DRIVER(rte_bnx2xvf_driver);