1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2013-2015 Brocade Communications Systems, Inc. 3 * Copyright (c) 2015-2018 Cavium Inc. 4 * All rights reserved. 5 * www.cavium.com 6 */ 7 8 #include "bnx2x.h" 9 #include "bnx2x_rxtx.h" 10 11 #include <rte_string_fns.h> 12 #include <dev_driver.h> 13 #include <ethdev_pci.h> 14 #include <rte_alarm.h> 15 16 /* 17 * The set of PCI devices this driver supports 18 */ 19 #define BROADCOM_PCI_VENDOR_ID 0x14E4 20 #define QLOGIC_PCI_VENDOR_ID 0x1077 21 static const struct rte_pci_id pci_id_bnx2x_map[] = { 22 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57800) }, 23 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57711) }, 24 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810) }, 25 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811) }, 26 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_OBS) }, 27 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_4_10) }, 28 { RTE_PCI_DEVICE(QLOGIC_PCI_VENDOR_ID, CHIP_NUM_57840_4_10) }, 29 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_2_20) }, 30 #ifdef RTE_LIBRTE_BNX2X_MF_SUPPORT 31 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57810_MF) }, 32 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57811_MF) }, 33 { RTE_PCI_DEVICE(BROADCOM_PCI_VENDOR_ID, CHIP_NUM_57840_MF) }, 34 { RTE_PCI_DEVICE(QLOGIC_PCI_VENDOR_ID, CHIP_NUM_57840_MF) }, 35 #endif 36 { .vendor_id = 0, } 37 }; 38 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) }, 44 { RTE_PCI_DEVICE(QLOGIC_PCI_VENDOR_ID, CHIP_NUM_57840_VF) }, 45 { .vendor_id = 0, } 46 }; 47 48 struct rte_bnx2x_xstats_name_off { 49 char name[RTE_ETH_XSTATS_NAME_SIZE]; 50 uint32_t offset_hi; 51 uint32_t offset_lo; 52 }; 53 54 static const struct rte_bnx2x_xstats_name_off bnx2x_xstats_strings[] = { 55 {"rx_buffer_drops", 56 offsetof(struct bnx2x_eth_stats, brb_drop_hi), 57 offsetof(struct bnx2x_eth_stats, brb_drop_lo)}, 58 {"rx_buffer_truncates", 59 offsetof(struct bnx2x_eth_stats, brb_truncate_hi), 60 offsetof(struct bnx2x_eth_stats, brb_truncate_lo)}, 61 {"rx_buffer_truncate_discard", 62 offsetof(struct bnx2x_eth_stats, brb_truncate_discard), 63 offsetof(struct bnx2x_eth_stats, brb_truncate_discard)}, 64 {"mac_filter_discard", 65 offsetof(struct bnx2x_eth_stats, mac_filter_discard), 66 offsetof(struct bnx2x_eth_stats, mac_filter_discard)}, 67 {"no_match_vlan_tag_discard", 68 offsetof(struct bnx2x_eth_stats, mf_tag_discard), 69 offsetof(struct bnx2x_eth_stats, mf_tag_discard)}, 70 {"tx_pause", 71 offsetof(struct bnx2x_eth_stats, pause_frames_sent_hi), 72 offsetof(struct bnx2x_eth_stats, pause_frames_sent_lo)}, 73 {"rx_pause", 74 offsetof(struct bnx2x_eth_stats, pause_frames_received_hi), 75 offsetof(struct bnx2x_eth_stats, pause_frames_received_lo)}, 76 {"tx_priority_flow_control", 77 offsetof(struct bnx2x_eth_stats, pfc_frames_sent_hi), 78 offsetof(struct bnx2x_eth_stats, pfc_frames_sent_lo)}, 79 {"rx_priority_flow_control", 80 offsetof(struct bnx2x_eth_stats, pfc_frames_received_hi), 81 offsetof(struct bnx2x_eth_stats, pfc_frames_received_lo)} 82 }; 83 84 static int 85 bnx2x_link_update(struct rte_eth_dev *dev) 86 { 87 struct bnx2x_softc *sc = dev->data->dev_private; 88 struct rte_eth_link link; 89 90 PMD_INIT_FUNC_TRACE(sc); 91 92 memset(&link, 0, sizeof(link)); 93 mb(); 94 link.link_speed = sc->link_vars.line_speed; 95 switch (sc->link_vars.duplex) { 96 case DUPLEX_FULL: 97 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX; 98 break; 99 case DUPLEX_HALF: 100 link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX; 101 break; 102 } 103 link.link_autoneg = !(dev->data->dev_conf.link_speeds & 104 RTE_ETH_LINK_SPEED_FIXED); 105 link.link_status = sc->link_vars.link_up; 106 107 return rte_eth_linkstatus_set(dev, &link); 108 } 109 110 static void 111 bnx2x_interrupt_action(struct rte_eth_dev *dev, int intr_cxt) 112 { 113 struct bnx2x_softc *sc = dev->data->dev_private; 114 uint32_t link_status; 115 116 bnx2x_intr_legacy(sc); 117 118 if ((atomic_load_acq_long(&sc->periodic_flags) == PERIODIC_GO) && 119 !intr_cxt) 120 bnx2x_periodic_callout(sc); 121 link_status = REG_RD(sc, sc->link_params.shmem_base + 122 offsetof(struct shmem_region, 123 port_mb[sc->link_params.port].link_status)); 124 if ((link_status & LINK_STATUS_LINK_UP) != dev->data->dev_link.link_status) 125 bnx2x_link_update(dev); 126 } 127 128 static void 129 bnx2x_interrupt_handler(void *param) 130 { 131 struct rte_eth_dev *dev = (struct rte_eth_dev *)param; 132 struct bnx2x_softc *sc = dev->data->dev_private; 133 134 PMD_DEBUG_PERIODIC_LOG(INFO, sc, "Interrupt handled"); 135 136 bnx2x_interrupt_action(dev, 1); 137 rte_intr_ack(sc->pci_dev->intr_handle); 138 } 139 140 static void bnx2x_periodic_start(void *param) 141 { 142 struct rte_eth_dev *dev = (struct rte_eth_dev *)param; 143 struct bnx2x_softc *sc = dev->data->dev_private; 144 int ret = 0; 145 146 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_GO); 147 bnx2x_interrupt_action(dev, 0); 148 if (IS_PF(sc)) { 149 ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD, 150 bnx2x_periodic_start, (void *)dev); 151 if (ret) { 152 PMD_DRV_LOG(ERR, sc, "Unable to start periodic" 153 " timer rc %d", ret); 154 } 155 } 156 } 157 158 void bnx2x_periodic_stop(void *param) 159 { 160 struct rte_eth_dev *dev = (struct rte_eth_dev *)param; 161 struct bnx2x_softc *sc = dev->data->dev_private; 162 163 atomic_store_rel_long(&sc->periodic_flags, PERIODIC_STOP); 164 165 rte_eal_alarm_cancel(bnx2x_periodic_start, (void *)dev); 166 167 PMD_DRV_LOG(DEBUG, sc, "Periodic poll stopped"); 168 } 169 170 /* 171 * Devops - helper functions can be called from user application 172 */ 173 174 static int 175 bnx2x_dev_configure(struct rte_eth_dev *dev) 176 { 177 struct bnx2x_softc *sc = dev->data->dev_private; 178 179 int mp_ncpus = sysconf(_SC_NPROCESSORS_CONF); 180 181 PMD_INIT_FUNC_TRACE(sc); 182 183 sc->mtu = dev->data->dev_conf.rxmode.mtu; 184 185 if (dev->data->nb_tx_queues > dev->data->nb_rx_queues) { 186 PMD_DRV_LOG(ERR, sc, "The number of TX queues is greater than number of RX queues"); 187 return -EINVAL; 188 } 189 190 sc->num_queues = MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues); 191 if (sc->num_queues > mp_ncpus) { 192 PMD_DRV_LOG(ERR, sc, "The number of queues is more than number of CPUs"); 193 return -EINVAL; 194 } 195 196 PMD_DRV_LOG(DEBUG, sc, "num_queues=%d, mtu=%d", 197 sc->num_queues, sc->mtu); 198 199 /* allocate ilt */ 200 if (bnx2x_alloc_ilt_mem(sc) != 0) { 201 PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_ilt_mem was failed"); 202 return -ENXIO; 203 } 204 205 bnx2x_dev_rxtx_init_dummy(dev); 206 return 0; 207 } 208 209 static int 210 bnx2x_dev_start(struct rte_eth_dev *dev) 211 { 212 struct bnx2x_softc *sc = dev->data->dev_private; 213 int ret = 0; 214 uint16_t i; 215 216 PMD_INIT_FUNC_TRACE(sc); 217 218 /* start the periodic callout */ 219 if (IS_PF(sc)) { 220 if (atomic_load_acq_long(&sc->periodic_flags) == 221 PERIODIC_STOP) { 222 bnx2x_periodic_start(dev); 223 PMD_DRV_LOG(DEBUG, sc, "Periodic poll re-started"); 224 } 225 } 226 227 ret = bnx2x_init(sc); 228 if (ret) { 229 PMD_DRV_LOG(DEBUG, sc, "bnx2x_init failed (%d)", ret); 230 return -1; 231 } 232 233 if (IS_PF(sc)) { 234 rte_intr_callback_register(sc->pci_dev->intr_handle, 235 bnx2x_interrupt_handler, (void *)dev); 236 237 if (rte_intr_enable(sc->pci_dev->intr_handle)) 238 PMD_DRV_LOG(ERR, sc, "rte_intr_enable failed"); 239 } 240 241 /* Configure the previously stored Multicast address list */ 242 if (IS_VF(sc)) 243 bnx2x_vfpf_set_mcast(sc, sc->mc_addrs, sc->mc_addrs_num); 244 bnx2x_dev_rxtx_init(dev); 245 246 bnx2x_print_device_info(sc); 247 248 for (i = 0; i < dev->data->nb_tx_queues; i++) 249 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; 250 for (i = 0; i < dev->data->nb_rx_queues; i++) 251 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; 252 253 return ret; 254 } 255 256 static int 257 bnx2x_dev_stop(struct rte_eth_dev *dev) 258 { 259 struct bnx2x_softc *sc = dev->data->dev_private; 260 int ret = 0; 261 uint16_t i; 262 263 PMD_INIT_FUNC_TRACE(sc); 264 265 bnx2x_dev_rxtx_init_dummy(dev); 266 267 if (IS_PF(sc)) { 268 rte_intr_disable(sc->pci_dev->intr_handle); 269 rte_intr_callback_unregister(sc->pci_dev->intr_handle, 270 bnx2x_interrupt_handler, (void *)dev); 271 272 /* stop the periodic callout */ 273 bnx2x_periodic_stop(dev); 274 } 275 /* Remove the configured Multicast list 276 * Sending NULL for the list of address and the 277 * Number is set to 0 denoting DEL_CMD 278 */ 279 if (IS_VF(sc)) 280 bnx2x_vfpf_set_mcast(sc, NULL, 0); 281 ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE); 282 if (ret) { 283 PMD_DRV_LOG(DEBUG, sc, "bnx2x_nic_unload failed (%d)", ret); 284 return ret; 285 } 286 287 for (i = 0; i < dev->data->nb_tx_queues; i++) 288 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; 289 for (i = 0; i < dev->data->nb_rx_queues; i++) 290 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; 291 292 return 0; 293 } 294 295 static int 296 bnx2x_dev_close(struct rte_eth_dev *dev) 297 { 298 struct bnx2x_softc *sc = dev->data->dev_private; 299 300 PMD_INIT_FUNC_TRACE(sc); 301 302 /* only close in case of the primary process */ 303 if (rte_eal_process_type() != RTE_PROC_PRIMARY) 304 return 0; 305 306 if (IS_VF(sc)) 307 bnx2x_vf_close(sc); 308 309 bnx2x_dev_clear_queues(dev); 310 memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link)); 311 312 /* free ilt */ 313 bnx2x_free_ilt_mem(sc); 314 315 /* mac_addrs must not be freed alone because part of dev_private */ 316 dev->data->mac_addrs = NULL; 317 318 return 0; 319 } 320 321 static int 322 bnx2x_promisc_enable(struct rte_eth_dev *dev) 323 { 324 struct bnx2x_softc *sc = dev->data->dev_private; 325 326 PMD_INIT_FUNC_TRACE(sc); 327 sc->rx_mode = BNX2X_RX_MODE_PROMISC; 328 if (rte_eth_allmulticast_get(dev->data->port_id) == 1) 329 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC; 330 bnx2x_set_rx_mode(sc); 331 332 return 0; 333 } 334 335 static int 336 bnx2x_promisc_disable(struct rte_eth_dev *dev) 337 { 338 struct bnx2x_softc *sc = dev->data->dev_private; 339 340 PMD_INIT_FUNC_TRACE(sc); 341 sc->rx_mode = BNX2X_RX_MODE_NORMAL; 342 if (rte_eth_allmulticast_get(dev->data->port_id) == 1) 343 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI; 344 bnx2x_set_rx_mode(sc); 345 346 return 0; 347 } 348 349 static int 350 bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev) 351 { 352 struct bnx2x_softc *sc = dev->data->dev_private; 353 354 PMD_INIT_FUNC_TRACE(sc); 355 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI; 356 if (rte_eth_promiscuous_get(dev->data->port_id) == 1) 357 sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC; 358 bnx2x_set_rx_mode(sc); 359 360 return 0; 361 } 362 363 static int 364 bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev) 365 { 366 struct bnx2x_softc *sc = dev->data->dev_private; 367 368 PMD_INIT_FUNC_TRACE(sc); 369 sc->rx_mode = BNX2X_RX_MODE_NORMAL; 370 if (rte_eth_promiscuous_get(dev->data->port_id) == 1) 371 sc->rx_mode = BNX2X_RX_MODE_PROMISC; 372 bnx2x_set_rx_mode(sc); 373 374 return 0; 375 } 376 377 static int 378 bnx2x_dev_set_mc_addr_list(struct rte_eth_dev *dev, 379 struct rte_ether_addr *mc_addrs, uint32_t mc_addrs_num) 380 { 381 struct bnx2x_softc *sc = dev->data->dev_private; 382 int err; 383 PMD_INIT_FUNC_TRACE(sc); 384 /* flush previous addresses */ 385 err = bnx2x_vfpf_set_mcast(sc, NULL, 0); 386 if (err) 387 return err; 388 sc->mc_addrs_num = 0; 389 390 /* Add new ones */ 391 err = bnx2x_vfpf_set_mcast(sc, mc_addrs, mc_addrs_num); 392 if (err) 393 return err; 394 395 sc->mc_addrs_num = mc_addrs_num; 396 memcpy(sc->mc_addrs, mc_addrs, mc_addrs_num * sizeof(*mc_addrs)); 397 398 return 0; 399 } 400 401 static int 402 bnx2x_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete) 403 { 404 struct bnx2x_softc *sc = dev->data->dev_private; 405 406 PMD_INIT_FUNC_TRACE(sc); 407 408 return bnx2x_link_update(dev); 409 } 410 411 static int 412 bnx2xvf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete) 413 { 414 struct bnx2x_softc *sc = dev->data->dev_private; 415 int ret = 0; 416 417 ret = bnx2x_link_update(dev); 418 419 bnx2x_check_bull(sc); 420 if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) { 421 PMD_DRV_LOG(ERR, sc, "PF indicated channel is down." 422 "VF device is no longer operational"); 423 dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN; 424 } 425 426 return ret; 427 } 428 429 static int 430 bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) 431 { 432 struct bnx2x_softc *sc = dev->data->dev_private; 433 uint32_t brb_truncate_discard; 434 uint64_t brb_drops; 435 uint64_t brb_truncates; 436 437 PMD_INIT_FUNC_TRACE(sc); 438 439 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE); 440 441 memset(stats, 0, sizeof (struct rte_eth_stats)); 442 443 stats->ipackets = 444 HILO_U64(sc->eth_stats.total_unicast_packets_received_hi, 445 sc->eth_stats.total_unicast_packets_received_lo) + 446 HILO_U64(sc->eth_stats.total_multicast_packets_received_hi, 447 sc->eth_stats.total_multicast_packets_received_lo) + 448 HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi, 449 sc->eth_stats.total_broadcast_packets_received_lo); 450 451 stats->opackets = 452 HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi, 453 sc->eth_stats.total_unicast_packets_transmitted_lo) + 454 HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi, 455 sc->eth_stats.total_multicast_packets_transmitted_lo) + 456 HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi, 457 sc->eth_stats.total_broadcast_packets_transmitted_lo); 458 459 stats->ibytes = 460 HILO_U64(sc->eth_stats.total_bytes_received_hi, 461 sc->eth_stats.total_bytes_received_lo); 462 463 stats->obytes = 464 HILO_U64(sc->eth_stats.total_bytes_transmitted_hi, 465 sc->eth_stats.total_bytes_transmitted_lo); 466 467 stats->ierrors = 468 HILO_U64(sc->eth_stats.error_bytes_received_hi, 469 sc->eth_stats.error_bytes_received_lo); 470 471 stats->oerrors = 0; 472 473 stats->rx_nombuf = 474 HILO_U64(sc->eth_stats.no_buff_discard_hi, 475 sc->eth_stats.no_buff_discard_lo); 476 477 brb_drops = 478 HILO_U64(sc->eth_stats.brb_drop_hi, 479 sc->eth_stats.brb_drop_lo); 480 481 brb_truncates = 482 HILO_U64(sc->eth_stats.brb_truncate_hi, 483 sc->eth_stats.brb_truncate_lo); 484 485 brb_truncate_discard = sc->eth_stats.brb_truncate_discard; 486 487 stats->imissed = brb_drops + brb_truncates + 488 brb_truncate_discard + stats->rx_nombuf; 489 490 return 0; 491 } 492 493 static int 494 bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev, 495 struct rte_eth_xstat_name *xstats_names, 496 __rte_unused unsigned limit) 497 { 498 unsigned int i, stat_cnt = RTE_DIM(bnx2x_xstats_strings); 499 500 if (xstats_names != NULL) 501 for (i = 0; i < stat_cnt; i++) 502 strlcpy(xstats_names[i].name, 503 bnx2x_xstats_strings[i].name, 504 sizeof(xstats_names[i].name)); 505 506 return stat_cnt; 507 } 508 509 static int 510 bnx2x_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, 511 unsigned int n) 512 { 513 struct bnx2x_softc *sc = dev->data->dev_private; 514 unsigned int num = RTE_DIM(bnx2x_xstats_strings); 515 516 if (n < num) 517 return num; 518 519 bnx2x_stats_handle(sc, STATS_EVENT_UPDATE); 520 521 for (num = 0; num < n; num++) { 522 if (bnx2x_xstats_strings[num].offset_hi != 523 bnx2x_xstats_strings[num].offset_lo) 524 xstats[num].value = HILO_U64( 525 *(uint32_t *)((char *)&sc->eth_stats + 526 bnx2x_xstats_strings[num].offset_hi), 527 *(uint32_t *)((char *)&sc->eth_stats + 528 bnx2x_xstats_strings[num].offset_lo)); 529 else 530 xstats[num].value = 531 *(uint64_t *)((char *)&sc->eth_stats + 532 bnx2x_xstats_strings[num].offset_lo); 533 xstats[num].id = num; 534 } 535 536 return num; 537 } 538 539 static int 540 bnx2x_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) 541 { 542 struct bnx2x_softc *sc = dev->data->dev_private; 543 544 dev_info->max_rx_queues = sc->max_rx_queues; 545 dev_info->max_tx_queues = sc->max_tx_queues; 546 dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE; 547 dev_info->max_rx_pktlen = BNX2X_MAX_RX_PKT_LEN; 548 dev_info->max_mac_addrs = BNX2X_MAX_MAC_ADDRS; 549 dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_20G; 550 551 dev_info->rx_desc_lim.nb_max = MAX_RX_AVAIL; 552 dev_info->rx_desc_lim.nb_min = MIN_RX_SIZE_NONTPA; 553 dev_info->rx_desc_lim.nb_mtu_seg_max = 1; 554 dev_info->tx_desc_lim.nb_max = MAX_TX_AVAIL; 555 556 return 0; 557 } 558 559 static int 560 bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr, 561 uint32_t index, uint32_t pool) 562 { 563 struct bnx2x_softc *sc = dev->data->dev_private; 564 565 if (sc->mac_ops.mac_addr_add) { 566 sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool); 567 return 0; 568 } 569 return -ENOTSUP; 570 } 571 572 static void 573 bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) 574 { 575 struct bnx2x_softc *sc = dev->data->dev_private; 576 577 if (sc->mac_ops.mac_addr_remove) 578 sc->mac_ops.mac_addr_remove(dev, index); 579 } 580 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, 601 }; 602 603 /* 604 * dev_ops for virtual function 605 */ 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 .set_mc_addr_list = bnx2x_dev_set_mc_addr_list, 616 .link_update = bnx2xvf_dev_link_update, 617 .stats_get = bnx2x_dev_stats_get, 618 .xstats_get = bnx2x_dev_xstats_get, 619 .xstats_get_names = bnx2x_get_xstats_names, 620 .dev_infos_get = bnx2x_dev_infos_get, 621 .rx_queue_setup = bnx2x_dev_rx_queue_setup, 622 .rx_queue_release = bnx2x_dev_rx_queue_release, 623 .tx_queue_setup = bnx2x_dev_tx_queue_setup, 624 .tx_queue_release = bnx2x_dev_tx_queue_release, 625 .mac_addr_add = bnx2x_mac_addr_add, 626 .mac_addr_remove = bnx2x_mac_addr_remove, 627 }; 628 629 630 static int 631 bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf) 632 { 633 int ret = 0; 634 struct rte_pci_device *pci_dev; 635 struct rte_pci_addr pci_addr; 636 struct bnx2x_softc *sc; 637 static bool adapter_info = true; 638 639 /* Extract key data structures */ 640 sc = eth_dev->data->dev_private; 641 pci_dev = RTE_DEV_TO_PCI(eth_dev->device); 642 pci_addr = pci_dev->addr; 643 644 snprintf(sc->devinfo.name, NAME_SIZE, PCI_SHORT_PRI_FMT ":dpdk-port-%u", 645 pci_addr.bus, pci_addr.devid, pci_addr.function, 646 eth_dev->data->port_id); 647 648 PMD_INIT_FUNC_TRACE(sc); 649 650 eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops; 651 652 if (rte_eal_process_type() != RTE_PROC_PRIMARY) { 653 PMD_DRV_LOG(ERR, sc, "Skipping device init from secondary process"); 654 return 0; 655 } 656 657 rte_eth_copy_pci_info(eth_dev, pci_dev); 658 659 sc->pcie_bus = pci_dev->addr.bus; 660 sc->pcie_device = pci_dev->addr.devid; 661 662 sc->devinfo.vendor_id = pci_dev->id.vendor_id; 663 sc->devinfo.device_id = pci_dev->id.device_id; 664 sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id; 665 sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id; 666 667 if (is_vf) 668 sc->flags = BNX2X_IS_VF_FLAG; 669 670 sc->pcie_func = pci_dev->addr.function; 671 sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr; 672 if (is_vf) 673 sc->bar[BAR1].base_addr = (void *) 674 ((uintptr_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START); 675 else 676 sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr; 677 678 assert(sc->bar[BAR0].base_addr); 679 assert(sc->bar[BAR1].base_addr); 680 681 bnx2x_load_firmware(sc); 682 assert(sc->firmware); 683 684 if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) 685 sc->udp_rss = 1; 686 687 sc->rx_budget = BNX2X_RX_BUDGET; 688 sc->hc_rx_ticks = BNX2X_RX_TICKS; 689 sc->hc_tx_ticks = BNX2X_TX_TICKS; 690 691 sc->interrupt_mode = INTR_MODE_SINGLE_MSIX; 692 sc->rx_mode = BNX2X_RX_MODE_NORMAL; 693 694 sc->pci_dev = pci_dev; 695 ret = bnx2x_attach(sc); 696 if (ret) { 697 PMD_DRV_LOG(ERR, sc, "bnx2x_attach failed (%d)", ret); 698 return ret; 699 } 700 701 /* Print important adapter info for the user. */ 702 if (adapter_info) { 703 bnx2x_print_adapter_info(sc); 704 adapter_info = false; 705 } 706 707 /* schedule periodic poll for slowpath link events */ 708 if (IS_PF(sc)) { 709 PMD_DRV_LOG(DEBUG, sc, "Scheduling periodic poll for slowpath link events"); 710 ret = rte_eal_alarm_set(BNX2X_SP_TIMER_PERIOD, 711 bnx2x_periodic_start, (void *)eth_dev); 712 if (ret) { 713 PMD_DRV_LOG(ERR, sc, "Unable to start periodic" 714 " timer rc %d", ret); 715 return -EINVAL; 716 } 717 } 718 719 eth_dev->data->mac_addrs = 720 (struct rte_ether_addr *)sc->link_params.mac_addr; 721 722 if (IS_VF(sc)) { 723 rte_spinlock_init(&sc->vf2pf_lock); 724 725 ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg), 726 &sc->vf2pf_mbox_mapping, "vf2pf_mbox", 727 RTE_CACHE_LINE_SIZE); 728 if (ret) 729 goto out; 730 731 sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *) 732 sc->vf2pf_mbox_mapping.vaddr; 733 734 ret = bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin), 735 &sc->pf2vf_bulletin_mapping, "vf2pf_bull", 736 RTE_CACHE_LINE_SIZE); 737 if (ret) 738 goto out; 739 740 sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *) 741 sc->pf2vf_bulletin_mapping.vaddr; 742 743 ret = bnx2x_vf_get_resources(sc, sc->max_tx_queues, 744 sc->max_rx_queues); 745 if (ret) 746 goto out; 747 } 748 749 return 0; 750 751 out: 752 if (IS_PF(sc)) 753 bnx2x_periodic_stop(eth_dev); 754 755 return ret; 756 } 757 758 static int 759 eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev) 760 { 761 struct bnx2x_softc *sc = eth_dev->data->dev_private; 762 PMD_INIT_FUNC_TRACE(sc); 763 return bnx2x_common_dev_init(eth_dev, 0); 764 } 765 766 static int 767 eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev) 768 { 769 struct bnx2x_softc *sc = eth_dev->data->dev_private; 770 PMD_INIT_FUNC_TRACE(sc); 771 return bnx2x_common_dev_init(eth_dev, 1); 772 } 773 774 static int eth_bnx2x_dev_uninit(struct rte_eth_dev *eth_dev) 775 { 776 struct bnx2x_softc *sc = eth_dev->data->dev_private; 777 PMD_INIT_FUNC_TRACE(sc); 778 bnx2x_dev_close(eth_dev); 779 return 0; 780 } 781 782 static struct rte_pci_driver rte_bnx2x_pmd; 783 static struct rte_pci_driver rte_bnx2xvf_pmd; 784 785 static int eth_bnx2x_pci_probe(struct rte_pci_driver *pci_drv, 786 struct rte_pci_device *pci_dev) 787 { 788 if (pci_drv == &rte_bnx2x_pmd) 789 return rte_eth_dev_pci_generic_probe(pci_dev, 790 sizeof(struct bnx2x_softc), eth_bnx2x_dev_init); 791 else if (pci_drv == &rte_bnx2xvf_pmd) 792 return rte_eth_dev_pci_generic_probe(pci_dev, 793 sizeof(struct bnx2x_softc), eth_bnx2xvf_dev_init); 794 else 795 return -EINVAL; 796 } 797 798 static int eth_bnx2x_pci_remove(struct rte_pci_device *pci_dev) 799 { 800 return rte_eth_dev_pci_generic_remove(pci_dev, eth_bnx2x_dev_uninit); 801 } 802 803 static struct rte_pci_driver rte_bnx2x_pmd = { 804 .id_table = pci_id_bnx2x_map, 805 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC, 806 .probe = eth_bnx2x_pci_probe, 807 .remove = eth_bnx2x_pci_remove, 808 }; 809 810 /* 811 * virtual function driver struct 812 */ 813 static struct rte_pci_driver rte_bnx2xvf_pmd = { 814 .id_table = pci_id_bnx2xvf_map, 815 .drv_flags = RTE_PCI_DRV_NEED_MAPPING, 816 .probe = eth_bnx2x_pci_probe, 817 .remove = eth_bnx2x_pci_remove, 818 }; 819 820 RTE_PMD_REGISTER_PCI(net_bnx2x, rte_bnx2x_pmd); 821 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2x, pci_id_bnx2x_map); 822 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2x, "* igb_uio | uio_pci_generic | vfio-pci"); 823 RTE_PMD_REGISTER_PCI(net_bnx2xvf, rte_bnx2xvf_pmd); 824 RTE_PMD_REGISTER_PCI_TABLE(net_bnx2xvf, pci_id_bnx2xvf_map); 825 RTE_PMD_REGISTER_KMOD_DEP(net_bnx2xvf, "* igb_uio | vfio-pci"); 826 RTE_LOG_REGISTER_SUFFIX(bnx2x_logtype_init, init, NOTICE); 827 RTE_LOG_REGISTER_SUFFIX(bnx2x_logtype_driver, driver, NOTICE); 828