2 * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
8 #include "bnx2x_rxtx.h"
13 * The set of PCI devices this driver supports
15 static struct rte_pci_id pci_id_bnx2x_map[] = {
16 #define RTE_PCI_DEV_ID_DECL_BNX2X(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
17 #include "rte_pci_dev_ids.h"
21 static struct rte_pci_id pci_id_bnx2xvf_map[] = {
22 #define RTE_PCI_DEV_ID_DECL_BNX2XVF(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
23 #include "rte_pci_dev_ids.h"
28 bnx2x_link_update(struct rte_eth_dev *dev)
30 struct bnx2x_softc *sc = dev->data->dev_private;
32 PMD_INIT_FUNC_TRACE();
33 bnx2x_link_status_update(sc);
35 dev->data->dev_link.link_speed = sc->link_vars.line_speed;
36 switch (sc->link_vars.duplex) {
38 dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
41 dev->data->dev_link.link_duplex = ETH_LINK_HALF_DUPLEX;
44 dev->data->dev_link.link_duplex = ETH_LINK_AUTONEG_DUPLEX;
46 dev->data->dev_link.link_status = sc->link_vars.link_up;
50 bnx2x_interrupt_action(struct rte_eth_dev *dev)
52 struct bnx2x_softc *sc = dev->data->dev_private;
55 PMD_DRV_LOG(INFO, "Interrupt handled");
57 if (bnx2x_intr_legacy(sc, 0))
59 if (sc->periodic_flags & PERIODIC_GO)
60 bnx2x_periodic_callout(sc);
61 link_status = REG_RD(sc, sc->link_params.shmem_base +
62 offsetof(struct shmem_region,
63 port_mb[sc->link_params.port].link_status));
64 if ((link_status & LINK_STATUS_LINK_UP) != dev->data->dev_link.link_status)
65 bnx2x_link_update(dev);
68 static __rte_unused void
69 bnx2x_interrupt_handler(__rte_unused struct rte_intr_handle *handle, void *param)
71 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
73 bnx2x_interrupt_action(dev);
74 rte_intr_enable(&(dev->pci_dev->intr_handle));
78 * Devops - helper functions can be called from user application
82 bnx2x_dev_configure(struct rte_eth_dev *dev)
84 struct bnx2x_softc *sc = dev->data->dev_private;
85 int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF);
88 PMD_INIT_FUNC_TRACE();
90 if (dev->data->dev_conf.rxmode.jumbo_frame)
91 sc->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len;
93 if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) {
94 PMD_DRV_LOG(ERR, "The number of TX queues is greater than number of RX queues");
98 sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
99 if (sc->num_queues > mp_ncpus) {
100 PMD_DRV_LOG(ERR, "The number of queues is more than number of CPUs");
104 PMD_DRV_LOG(DEBUG, "num_queues=%d, mtu=%d",
105 sc->num_queues, sc->mtu);
108 if (bnx2x_alloc_ilt_mem(sc) != 0) {
109 PMD_DRV_LOG(ERR, "bnx2x_alloc_ilt_mem was failed");
113 /* allocate the host hardware/software hsi structures */
114 if (bnx2x_alloc_hsi_mem(sc) != 0) {
115 PMD_DRV_LOG(ERR, "bnx2x_alloc_hsi_mem was failed");
116 bnx2x_free_ilt_mem(sc);
121 if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg),
122 &sc->vf2pf_mbox_mapping, "vf2pf_mbox",
123 RTE_CACHE_LINE_SIZE) != 0)
126 sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *)sc->vf2pf_mbox_mapping.vaddr;
127 if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin),
128 &sc->pf2vf_bulletin_mapping, "vf2pf_bull",
129 RTE_CACHE_LINE_SIZE) != 0)
132 sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *)sc->pf2vf_bulletin_mapping.vaddr;
134 ret = bnx2x_vf_get_resources(sc, sc->num_queues, sc->num_queues);
143 bnx2x_dev_start(struct rte_eth_dev *dev)
145 struct bnx2x_softc *sc = dev->data->dev_private;
148 PMD_INIT_FUNC_TRACE();
150 ret = bnx2x_init(sc);
152 PMD_DRV_LOG(DEBUG, "bnx2x_init failed (%d)", ret);
157 rte_intr_callback_register(&(dev->pci_dev->intr_handle),
158 bnx2x_interrupt_handler, (void *)dev);
160 if(rte_intr_enable(&(dev->pci_dev->intr_handle)))
161 PMD_DRV_LOG(ERR, "rte_intr_enable failed");
164 ret = bnx2x_dev_rx_init(dev);
166 PMD_DRV_LOG(DEBUG, "bnx2x_dev_rx_init returned error code");
170 /* Print important adapter info for the user. */
171 bnx2x_print_adapter_info(sc);
179 bnx2x_dev_stop(struct rte_eth_dev *dev)
181 struct bnx2x_softc *sc = dev->data->dev_private;
184 PMD_INIT_FUNC_TRACE();
187 rte_intr_disable(&(dev->pci_dev->intr_handle));
188 rte_intr_callback_unregister(&(dev->pci_dev->intr_handle),
189 bnx2x_interrupt_handler, (void *)dev);
192 ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE);
194 PMD_DRV_LOG(DEBUG, "bnx2x_nic_unload failed (%d)", ret);
202 bnx2x_dev_close(struct rte_eth_dev *dev)
204 struct bnx2x_softc *sc = dev->data->dev_private;
206 PMD_INIT_FUNC_TRACE();
211 bnx2x_dev_clear_queues(dev);
212 memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link));
214 /* free the host hardware/software hsi structures */
215 bnx2x_free_hsi_mem(sc);
218 bnx2x_free_ilt_mem(sc);
222 bnx2x_promisc_enable(struct rte_eth_dev *dev)
224 struct bnx2x_softc *sc = dev->data->dev_private;
226 PMD_INIT_FUNC_TRACE();
227 sc->rx_mode = BNX2X_RX_MODE_PROMISC;
228 bnx2x_set_rx_mode(sc);
232 bnx2x_promisc_disable(struct rte_eth_dev *dev)
234 struct bnx2x_softc *sc = dev->data->dev_private;
236 PMD_INIT_FUNC_TRACE();
237 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
238 bnx2x_set_rx_mode(sc);
242 bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev)
244 struct bnx2x_softc *sc = dev->data->dev_private;
246 PMD_INIT_FUNC_TRACE();
247 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI;
248 bnx2x_set_rx_mode(sc);
252 bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev)
254 struct bnx2x_softc *sc = dev->data->dev_private;
256 PMD_INIT_FUNC_TRACE();
257 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
258 bnx2x_set_rx_mode(sc);
262 bnx2x_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
264 PMD_INIT_FUNC_TRACE();
266 int old_link_status = dev->data->dev_link.link_status;
268 bnx2x_link_update(dev);
270 return old_link_status == dev->data->dev_link.link_status ? -1 : 0;
274 bnx2xvf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
276 int old_link_status = dev->data->dev_link.link_status;
277 struct bnx2x_softc *sc = dev->data->dev_private;
279 bnx2x_link_update(dev);
281 bnx2x_check_bull(sc);
282 if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
283 PMD_DRV_LOG(ERR, "PF indicated channel is down."
284 "VF device is no longer operational");
285 dev->data->dev_link.link_status = 0;
288 return old_link_status == dev->data->dev_link.link_status ? -1 : 0;
292 bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
294 struct bnx2x_softc *sc = dev->data->dev_private;
296 PMD_INIT_FUNC_TRACE();
298 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE);
300 memset(stats, 0, sizeof (struct rte_eth_stats));
303 HILO_U64(sc->eth_stats.total_unicast_packets_received_hi,
304 sc->eth_stats.total_unicast_packets_received_lo) +
305 HILO_U64(sc->eth_stats.total_multicast_packets_received_hi,
306 sc->eth_stats.total_multicast_packets_received_lo) +
307 HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi,
308 sc->eth_stats.total_broadcast_packets_received_lo);
311 HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi,
312 sc->eth_stats.total_unicast_packets_transmitted_lo) +
313 HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi,
314 sc->eth_stats.total_multicast_packets_transmitted_lo) +
315 HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi,
316 sc->eth_stats.total_broadcast_packets_transmitted_lo);
319 HILO_U64(sc->eth_stats.total_bytes_received_hi,
320 sc->eth_stats.total_bytes_received_lo);
323 HILO_U64(sc->eth_stats.total_bytes_transmitted_hi,
324 sc->eth_stats.total_bytes_transmitted_lo);
327 HILO_U64(sc->eth_stats.error_bytes_received_hi,
328 sc->eth_stats.error_bytes_received_lo);
333 HILO_U64(sc->eth_stats.no_buff_discard_hi,
334 sc->eth_stats.no_buff_discard_lo);
338 bnx2x_dev_infos_get(struct rte_eth_dev *dev, __rte_unused struct rte_eth_dev_info *dev_info)
340 struct bnx2x_softc *sc = dev->data->dev_private;
341 dev_info->max_rx_queues = sc->max_rx_queues;
342 dev_info->max_tx_queues = sc->max_tx_queues;
343 dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE;
344 dev_info->max_rx_pktlen = BNX2X_MAX_RX_PKT_LEN;
345 dev_info->max_mac_addrs = BNX2X_MAX_MAC_ADDRS;
349 bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
350 uint32_t index, uint32_t pool)
352 struct bnx2x_softc *sc = dev->data->dev_private;
354 if (sc->mac_ops.mac_addr_add)
355 sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool);
359 bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
361 struct bnx2x_softc *sc = dev->data->dev_private;
363 if (sc->mac_ops.mac_addr_remove)
364 sc->mac_ops.mac_addr_remove(dev, index);
367 static struct eth_dev_ops bnx2x_eth_dev_ops = {
368 .dev_configure = bnx2x_dev_configure,
369 .dev_start = bnx2x_dev_start,
370 .dev_stop = bnx2x_dev_stop,
371 .dev_close = bnx2x_dev_close,
372 .promiscuous_enable = bnx2x_promisc_enable,
373 .promiscuous_disable = bnx2x_promisc_disable,
374 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
375 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
376 .link_update = bnx2x_dev_link_update,
377 .stats_get = bnx2x_dev_stats_get,
378 .dev_infos_get = bnx2x_dev_infos_get,
379 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
380 .rx_queue_release = bnx2x_dev_rx_queue_release,
381 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
382 .tx_queue_release = bnx2x_dev_tx_queue_release,
383 .mac_addr_add = bnx2x_mac_addr_add,
384 .mac_addr_remove = bnx2x_mac_addr_remove,
388 * dev_ops for virtual function
390 static struct eth_dev_ops bnx2xvf_eth_dev_ops = {
391 .dev_configure = bnx2x_dev_configure,
392 .dev_start = bnx2x_dev_start,
393 .dev_stop = bnx2x_dev_stop,
394 .dev_close = bnx2x_dev_close,
395 .promiscuous_enable = bnx2x_promisc_enable,
396 .promiscuous_disable = bnx2x_promisc_disable,
397 .allmulticast_enable = bnx2x_dev_allmulticast_enable,
398 .allmulticast_disable = bnx2x_dev_allmulticast_disable,
399 .link_update = bnx2xvf_dev_link_update,
400 .stats_get = bnx2x_dev_stats_get,
401 .dev_infos_get = bnx2x_dev_infos_get,
402 .rx_queue_setup = bnx2x_dev_rx_queue_setup,
403 .rx_queue_release = bnx2x_dev_rx_queue_release,
404 .tx_queue_setup = bnx2x_dev_tx_queue_setup,
405 .tx_queue_release = bnx2x_dev_tx_queue_release,
406 .mac_addr_add = bnx2x_mac_addr_add,
407 .mac_addr_remove = bnx2x_mac_addr_remove,
412 bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
415 struct rte_pci_device *pci_dev;
416 struct bnx2x_softc *sc;
418 PMD_INIT_FUNC_TRACE();
420 eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops;
421 pci_dev = eth_dev->pci_dev;
422 sc = eth_dev->data->dev_private;
423 sc->pcie_bus = pci_dev->addr.bus;
424 sc->pcie_device = pci_dev->addr.devid;
427 sc->flags = BNX2X_IS_VF_FLAG;
429 sc->devinfo.vendor_id = pci_dev->id.vendor_id;
430 sc->devinfo.device_id = pci_dev->id.device_id;
431 sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id;
432 sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id;
434 sc->pcie_func = pci_dev->addr.function;
435 sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr;
437 sc->bar[BAR1].base_addr = (void *)
438 ((uint64_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START);
440 sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr;
442 assert(sc->bar[BAR0].base_addr);
443 assert(sc->bar[BAR1].base_addr);
445 bnx2x_load_firmware(sc);
446 assert(sc->firmware);
448 if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
451 sc->rx_budget = BNX2X_RX_BUDGET;
452 sc->hc_rx_ticks = BNX2X_RX_TICKS;
453 sc->hc_tx_ticks = BNX2X_TX_TICKS;
455 sc->interrupt_mode = INTR_MODE_SINGLE_MSIX;
456 sc->rx_mode = BNX2X_RX_MODE_NORMAL;
458 sc->pci_dev = pci_dev;
459 ret = bnx2x_attach(sc);
461 PMD_DRV_LOG(ERR, "bnx2x_attach failed (%d)", ret);
464 eth_dev->data->mac_addrs = (struct ether_addr *)sc->link_params.mac_addr;
466 PMD_DRV_LOG(INFO, "pcie_bus=%d, pcie_device=%d",
467 sc->pcie_bus, sc->pcie_device);
468 PMD_DRV_LOG(INFO, "bar0.addr=%p, bar1.addr=%p",
469 sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr);
470 PMD_DRV_LOG(INFO, "port=%d, path=%d, vnic=%d, func=%d",
471 PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc));
472 PMD_DRV_LOG(INFO, "portID=%d vendorID=0x%x deviceID=0x%x",
473 eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id);
479 eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev)
481 PMD_INIT_FUNC_TRACE();
482 return bnx2x_common_dev_init(eth_dev, 0);
486 eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev)
488 PMD_INIT_FUNC_TRACE();
489 return bnx2x_common_dev_init(eth_dev, 1);
492 static struct eth_driver rte_bnx2x_pmd = {
494 .name = "rte_bnx2x_pmd",
495 .id_table = pci_id_bnx2x_map,
496 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
498 .eth_dev_init = eth_bnx2x_dev_init,
499 .dev_private_size = sizeof(struct bnx2x_softc),
503 * virtual function driver struct
505 static struct eth_driver rte_bnx2xvf_pmd = {
507 .name = "rte_bnx2xvf_pmd",
508 .id_table = pci_id_bnx2xvf_map,
509 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
511 .eth_dev_init = eth_bnx2xvf_dev_init,
512 .dev_private_size = sizeof(struct bnx2x_softc),
515 static int rte_bnx2x_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
517 PMD_INIT_FUNC_TRACE();
518 rte_eth_driver_register(&rte_bnx2x_pmd);
523 static int rte_bnx2xvf_pmd_init(const char *name __rte_unused, const char *params __rte_unused)
525 PMD_INIT_FUNC_TRACE();
526 rte_eth_driver_register(&rte_bnx2xvf_pmd);
531 static struct rte_driver rte_bnx2x_driver = {
533 .init = rte_bnx2x_pmd_init,
536 static struct rte_driver rte_bnx2xvf_driver = {
538 .init = rte_bnx2xvf_pmd_init,
541 PMD_REGISTER_DRIVER(rte_bnx2x_driver);
542 PMD_REGISTER_DRIVER(rte_bnx2xvf_driver);