1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017-2021 Marvell International Ltd. 3 * Copyright(c) 2017-2021 Semihalf. 4 * All rights reserved. 5 */ 6 7 #include <rte_string_fns.h> 8 #include <ethdev_driver.h> 9 #include <rte_kvargs.h> 10 #include <rte_log.h> 11 #include <rte_malloc.h> 12 #include <bus_vdev_driver.h> 13 14 #include <fcntl.h> 15 #include <linux/ethtool.h> 16 #include <linux/sockios.h> 17 #include <net/if.h> 18 #include <net/if_arp.h> 19 #include <sys/ioctl.h> 20 #include <sys/socket.h> 21 #include <sys/stat.h> 22 #include <sys/types.h> 23 24 #include <rte_mvep_common.h> 25 #include "mrvl_ethdev.h" 26 #include "mrvl_qos.h" 27 #include "mrvl_flow.h" 28 #include "mrvl_mtr.h" 29 #include "mrvl_tm.h" 30 31 /* bitmask with reserved hifs */ 32 #define MRVL_MUSDK_HIFS_RESERVED 0x0F 33 /* bitmask with reserved bpools */ 34 #define MRVL_MUSDK_BPOOLS_RESERVED 0x07 35 /* bitmask with reserved kernel RSS tables */ 36 #define MRVL_MUSDK_RSS_RESERVED 0x0F 37 /* maximum number of available hifs */ 38 #define MRVL_MUSDK_HIFS_MAX 9 39 40 /* prefetch shift */ 41 #define MRVL_MUSDK_PREFETCH_SHIFT 2 42 43 /* TCAM has 25 entries reserved for uc/mc filter entries 44 * + 1 for primary mac address 45 */ 46 #define MRVL_MAC_ADDRS_MAX (1 + 25) 47 #define MRVL_MATCH_LEN 16 48 #define MRVL_PKT_EFFEC_OFFS (MRVL_PKT_OFFS + MV_MH_SIZE) 49 /* Maximum allowable packet size */ 50 #define MRVL_PKT_SIZE_MAX (10240 - MV_MH_SIZE) 51 52 #define MRVL_IFACE_NAME_ARG "iface" 53 #define MRVL_CFG_ARG "cfg" 54 55 #define MRVL_ARP_LENGTH 28 56 57 #define MRVL_COOKIE_ADDR_INVALID ~0ULL 58 #define MRVL_COOKIE_HIGH_ADDR_MASK 0xffffff0000000000 59 60 /** Port Rx offload capabilities */ 61 #define MRVL_RX_OFFLOADS (RTE_ETH_RX_OFFLOAD_VLAN_FILTER | \ 62 RTE_ETH_RX_OFFLOAD_CHECKSUM) 63 64 /** Port Tx offloads capabilities */ 65 #define MRVL_TX_OFFLOAD_CHECKSUM (RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | \ 66 RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \ 67 RTE_ETH_TX_OFFLOAD_TCP_CKSUM) 68 #define MRVL_TX_OFFLOADS (MRVL_TX_OFFLOAD_CHECKSUM | \ 69 RTE_ETH_TX_OFFLOAD_MULTI_SEGS) 70 71 #define MRVL_TX_PKT_OFFLOADS (RTE_MBUF_F_TX_IP_CKSUM | \ 72 RTE_MBUF_F_TX_TCP_CKSUM | \ 73 RTE_MBUF_F_TX_UDP_CKSUM) 74 75 static const char * const valid_args[] = { 76 MRVL_IFACE_NAME_ARG, 77 MRVL_CFG_ARG, 78 NULL 79 }; 80 81 static int used_hifs = MRVL_MUSDK_HIFS_RESERVED; 82 static struct pp2_hif *hifs[RTE_MAX_LCORE]; 83 static int used_bpools[PP2_NUM_PKT_PROC] = { 84 [0 ... PP2_NUM_PKT_PROC - 1] = MRVL_MUSDK_BPOOLS_RESERVED 85 }; 86 87 static struct pp2_bpool *mrvl_port_to_bpool_lookup[RTE_MAX_ETHPORTS]; 88 static int mrvl_port_bpool_size[PP2_NUM_PKT_PROC][PP2_BPOOL_NUM_POOLS][RTE_MAX_LCORE]; 89 static uint64_t cookie_addr_high = MRVL_COOKIE_ADDR_INVALID; 90 static int dummy_pool_id[PP2_NUM_PKT_PROC]; 91 struct pp2_bpool *dummy_pool[PP2_NUM_PKT_PROC] = {0}; 92 93 struct mrvl_ifnames { 94 const char *names[PP2_NUM_ETH_PPIO * PP2_NUM_PKT_PROC]; 95 int idx; 96 }; 97 98 /* 99 * To use buffer harvesting based on loopback port shadow queue structure 100 * was introduced for buffers information bookkeeping. 101 * 102 * Before sending the packet, related buffer information (pp2_buff_inf) is 103 * stored in shadow queue. After packet is transmitted no longer used 104 * packet buffer is released back to it's original hardware pool, 105 * on condition it originated from interface. 106 * In case it was generated by application itself i.e: mbuf->port field is 107 * 0xff then its released to software mempool. 108 */ 109 struct mrvl_shadow_txq { 110 int head; /* write index - used when sending buffers */ 111 int tail; /* read index - used when releasing buffers */ 112 u16 size; /* queue occupied size */ 113 u16 num_to_release; /* number of descriptors sent, that can be 114 * released 115 */ 116 struct buff_release_entry ent[MRVL_PP2_TX_SHADOWQ_SIZE]; /* q entries */ 117 }; 118 119 struct mrvl_rxq { 120 struct mrvl_priv *priv; 121 struct rte_mempool *mp; 122 int queue_id; 123 int port_id; 124 int cksum_enabled; 125 uint64_t bytes_recv; 126 uint64_t drop_mac; 127 }; 128 129 struct mrvl_txq { 130 struct mrvl_priv *priv; 131 int queue_id; 132 int port_id; 133 uint64_t bytes_sent; 134 struct mrvl_shadow_txq shadow_txqs[RTE_MAX_LCORE]; 135 int tx_deferred_start; 136 }; 137 138 static int mrvl_lcore_first; 139 static int mrvl_lcore_last; 140 static int mrvl_dev_num; 141 142 static int mrvl_fill_bpool(struct mrvl_rxq *rxq, int num); 143 static inline void mrvl_free_sent_buffers(struct pp2_ppio *ppio, 144 struct pp2_hif *hif, unsigned int core_id, 145 struct mrvl_shadow_txq *sq, int qid, int force); 146 147 static uint16_t mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, 148 uint16_t nb_pkts); 149 static uint16_t mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, 150 uint16_t nb_pkts); 151 static int rte_pmd_mrvl_remove(struct rte_vdev_device *vdev); 152 static void mrvl_deinit_pp2(void); 153 static void mrvl_deinit_hifs(void); 154 155 static int 156 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr, 157 uint32_t index, uint32_t vmdq __rte_unused); 158 static int 159 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr); 160 static int 161 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on); 162 static int mrvl_promiscuous_enable(struct rte_eth_dev *dev); 163 static int mrvl_allmulticast_enable(struct rte_eth_dev *dev); 164 static int 165 mrvl_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf); 166 167 #define MRVL_XSTATS_TBL_ENTRY(name) { \ 168 #name, offsetof(struct pp2_ppio_statistics, name), \ 169 sizeof(((struct pp2_ppio_statistics *)0)->name) \ 170 } 171 172 /* Table with xstats data */ 173 static struct { 174 const char *name; 175 unsigned int offset; 176 unsigned int size; 177 } mrvl_xstats_tbl[] = { 178 MRVL_XSTATS_TBL_ENTRY(rx_bytes), 179 MRVL_XSTATS_TBL_ENTRY(rx_packets), 180 MRVL_XSTATS_TBL_ENTRY(rx_unicast_packets), 181 MRVL_XSTATS_TBL_ENTRY(rx_errors), 182 MRVL_XSTATS_TBL_ENTRY(rx_fullq_dropped), 183 MRVL_XSTATS_TBL_ENTRY(rx_bm_dropped), 184 MRVL_XSTATS_TBL_ENTRY(rx_early_dropped), 185 MRVL_XSTATS_TBL_ENTRY(rx_fifo_dropped), 186 MRVL_XSTATS_TBL_ENTRY(rx_cls_dropped), 187 MRVL_XSTATS_TBL_ENTRY(tx_bytes), 188 MRVL_XSTATS_TBL_ENTRY(tx_packets), 189 MRVL_XSTATS_TBL_ENTRY(tx_unicast_packets), 190 MRVL_XSTATS_TBL_ENTRY(tx_errors) 191 }; 192 193 static inline int 194 mrvl_reserve_bit(int *bitmap, int max) 195 { 196 int n = sizeof(*bitmap) * 8 - rte_clz32(*bitmap); 197 198 if (n >= max) 199 return -1; 200 201 *bitmap |= 1 << n; 202 203 return n; 204 } 205 206 static int 207 mrvl_pp2_fixup_init(void) 208 { 209 struct pp2_bpool_params bpool_params; 210 char name[15]; 211 int err, i; 212 213 memset(dummy_pool, 0, sizeof(dummy_pool)); 214 for (i = 0; i < pp2_get_num_inst(); i++) { 215 dummy_pool_id[i] = mrvl_reserve_bit(&used_bpools[i], 216 PP2_BPOOL_NUM_POOLS); 217 if (dummy_pool_id[i] < 0) { 218 MRVL_LOG(ERR, "Can't find free pool"); 219 return -1; 220 } 221 222 memset(name, 0, sizeof(name)); 223 snprintf(name, sizeof(name), "pool-%d:%d", i, dummy_pool_id[i]); 224 memset(&bpool_params, 0, sizeof(bpool_params)); 225 bpool_params.match = name; 226 bpool_params.buff_len = MRVL_PKT_OFFS; 227 bpool_params.dummy_short_pool = 1; 228 err = pp2_bpool_init(&bpool_params, &dummy_pool[i]); 229 if (err != 0 || !dummy_pool[i]) { 230 MRVL_LOG(ERR, "BPool init failed!"); 231 used_bpools[i] &= ~(1 << dummy_pool_id[i]); 232 return -1; 233 } 234 } 235 236 return 0; 237 } 238 239 /** 240 * Initialize packet processor. 241 * 242 * @return 243 * 0 on success, negative error value otherwise. 244 */ 245 static int 246 mrvl_init_pp2(void) 247 { 248 struct pp2_init_params init_params; 249 int err; 250 251 memset(&init_params, 0, sizeof(init_params)); 252 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED; 253 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED; 254 init_params.rss_tbl_reserved_map = MRVL_MUSDK_RSS_RESERVED; 255 if (mrvl_cfg && mrvl_cfg->pp2_cfg.prs_udfs.num_udfs) 256 memcpy(&init_params.prs_udfs, &mrvl_cfg->pp2_cfg.prs_udfs, 257 sizeof(struct pp2_parse_udfs)); 258 err = pp2_init(&init_params); 259 if (err != 0) { 260 MRVL_LOG(ERR, "PP2 init failed"); 261 return -1; 262 } 263 264 err = mrvl_pp2_fixup_init(); 265 if (err != 0) { 266 MRVL_LOG(ERR, "PP2 fixup init failed"); 267 return -1; 268 } 269 270 return 0; 271 } 272 273 static void 274 mrvl_pp2_fixup_deinit(void) 275 { 276 int i; 277 278 for (i = 0; i < PP2_NUM_PKT_PROC; i++) { 279 if (!dummy_pool[i]) 280 continue; 281 pp2_bpool_deinit(dummy_pool[i]); 282 used_bpools[i] &= ~(1 << dummy_pool_id[i]); 283 } 284 } 285 286 /** 287 * Deinitialize packet processor. 288 * 289 * @return 290 * 0 on success, negative error value otherwise. 291 */ 292 static void 293 mrvl_deinit_pp2(void) 294 { 295 mrvl_pp2_fixup_deinit(); 296 pp2_deinit(); 297 } 298 299 static inline void 300 mrvl_fill_shadowq(struct mrvl_shadow_txq *sq, struct rte_mbuf *buf) 301 { 302 sq->ent[sq->head].buff.cookie = (uint64_t)buf; 303 sq->ent[sq->head].buff.addr = buf ? 304 rte_mbuf_data_iova_default(buf) : 0; 305 306 sq->ent[sq->head].bpool = 307 (unlikely(!buf || buf->port >= RTE_MAX_ETHPORTS || 308 buf->refcnt > 1)) ? NULL : 309 mrvl_port_to_bpool_lookup[buf->port]; 310 311 sq->head = (sq->head + 1) & MRVL_PP2_TX_SHADOWQ_MASK; 312 sq->size++; 313 } 314 315 /** 316 * Deinitialize per-lcore MUSDK hardware interfaces (hifs). 317 */ 318 static void 319 mrvl_deinit_hifs(void) 320 { 321 int i; 322 323 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) { 324 if (hifs[i]) 325 pp2_hif_deinit(hifs[i]); 326 } 327 used_hifs = MRVL_MUSDK_HIFS_RESERVED; 328 memset(hifs, 0, sizeof(hifs)); 329 } 330 331 static inline void 332 mrvl_fill_desc(struct pp2_ppio_desc *desc, struct rte_mbuf *buf) 333 { 334 pp2_ppio_outq_desc_reset(desc); 335 pp2_ppio_outq_desc_set_phys_addr(desc, rte_pktmbuf_iova(buf)); 336 pp2_ppio_outq_desc_set_pkt_offset(desc, 0); 337 pp2_ppio_outq_desc_set_pkt_len(desc, rte_pktmbuf_data_len(buf)); 338 } 339 340 static inline int 341 mrvl_get_bpool_size(int pp2_id, int pool_id) 342 { 343 int i; 344 int size = 0; 345 346 for (i = mrvl_lcore_first; i <= mrvl_lcore_last; i++) 347 size += mrvl_port_bpool_size[pp2_id][pool_id][i]; 348 349 return size; 350 } 351 352 static int 353 mrvl_init_hif(int core_id) 354 { 355 struct pp2_hif_params params; 356 char match[MRVL_MATCH_LEN]; 357 int ret; 358 359 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX); 360 if (ret < 0) { 361 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id); 362 return ret; 363 } 364 365 snprintf(match, sizeof(match), "hif-%d", ret); 366 memset(¶ms, 0, sizeof(params)); 367 params.match = match; 368 params.out_size = MRVL_PP2_AGGR_TXQD_MAX; 369 ret = pp2_hif_init(¶ms, &hifs[core_id]); 370 if (ret) { 371 MRVL_LOG(ERR, "Failed to initialize hif %d", core_id); 372 return ret; 373 } 374 375 return 0; 376 } 377 378 static inline struct pp2_hif* 379 mrvl_get_hif(struct mrvl_priv *priv, int core_id) 380 { 381 int ret; 382 383 if (likely(hifs[core_id] != NULL)) 384 return hifs[core_id]; 385 386 rte_spinlock_lock(&priv->lock); 387 388 ret = mrvl_init_hif(core_id); 389 if (ret < 0) { 390 MRVL_LOG(ERR, "Failed to allocate hif %d", core_id); 391 goto out; 392 } 393 394 if (core_id < mrvl_lcore_first) 395 mrvl_lcore_first = core_id; 396 397 if (core_id > mrvl_lcore_last) 398 mrvl_lcore_last = core_id; 399 out: 400 rte_spinlock_unlock(&priv->lock); 401 402 return hifs[core_id]; 403 } 404 405 /** 406 * Set tx burst function according to offload flag 407 * 408 * @param dev 409 * Pointer to Ethernet device structure. 410 */ 411 static void 412 mrvl_set_tx_function(struct rte_eth_dev *dev) 413 { 414 struct mrvl_priv *priv = dev->data->dev_private; 415 416 /* Use a simple Tx queue (no offloads, no multi segs) if possible */ 417 if (priv->multiseg) { 418 MRVL_LOG(INFO, "Using multi-segment tx callback"); 419 dev->tx_pkt_burst = mrvl_tx_sg_pkt_burst; 420 } else { 421 MRVL_LOG(INFO, "Using single-segment tx callback"); 422 dev->tx_pkt_burst = mrvl_tx_pkt_burst; 423 } 424 } 425 426 /** 427 * Configure rss based on dpdk rss configuration. 428 * 429 * @param priv 430 * Pointer to private structure. 431 * @param rss_conf 432 * Pointer to RSS configuration. 433 * 434 * @return 435 * 0 on success, negative error value otherwise. 436 */ 437 static int 438 mrvl_configure_rss(struct mrvl_priv *priv, struct rte_eth_rss_conf *rss_conf) 439 { 440 if (rss_conf->rss_key) 441 MRVL_LOG(WARNING, "Changing hash key is not supported"); 442 443 if (rss_conf->rss_hf == 0) { 444 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE; 445 } else if (rss_conf->rss_hf & RTE_ETH_RSS_IPV4) { 446 priv->ppio_params.inqs_params.hash_type = 447 PP2_PPIO_HASH_T_2_TUPLE; 448 } else if (rss_conf->rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) { 449 priv->ppio_params.inqs_params.hash_type = 450 PP2_PPIO_HASH_T_5_TUPLE; 451 priv->rss_hf_tcp = 1; 452 } else if (rss_conf->rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) { 453 priv->ppio_params.inqs_params.hash_type = 454 PP2_PPIO_HASH_T_5_TUPLE; 455 priv->rss_hf_tcp = 0; 456 } else { 457 return -EINVAL; 458 } 459 460 return 0; 461 } 462 463 /** 464 * Ethernet device configuration. 465 * 466 * Prepare the driver for a given number of TX and RX queues and 467 * configure RSS. 468 * 469 * @param dev 470 * Pointer to Ethernet device structure. 471 * 472 * @return 473 * 0 on success, negative error value otherwise. 474 */ 475 static int 476 mrvl_dev_configure(struct rte_eth_dev *dev) 477 { 478 struct mrvl_priv *priv = dev->data->dev_private; 479 int ret; 480 481 if (priv->ppio) { 482 MRVL_LOG(INFO, "Device reconfiguration is not supported"); 483 return -EINVAL; 484 } 485 486 if (dev->data->dev_conf.rxmode.mq_mode != RTE_ETH_MQ_RX_NONE && 487 dev->data->dev_conf.rxmode.mq_mode != RTE_ETH_MQ_RX_RSS) { 488 MRVL_LOG(INFO, "Unsupported rx multi queue mode %d", 489 dev->data->dev_conf.rxmode.mq_mode); 490 return -EINVAL; 491 } 492 493 if (dev->data->dev_conf.rxmode.mtu > priv->max_mtu) { 494 MRVL_LOG(ERR, "MTU %u is larger than max_mtu %u", 495 dev->data->dev_conf.rxmode.mtu, 496 priv->max_mtu); 497 return -EINVAL; 498 } 499 500 if (dev->data->dev_conf.txmode.offloads & RTE_ETH_TX_OFFLOAD_MULTI_SEGS) 501 priv->multiseg = 1; 502 503 ret = mrvl_configure_rxqs(priv, dev->data->port_id, 504 dev->data->nb_rx_queues); 505 if (ret < 0) 506 return ret; 507 508 ret = mrvl_configure_txqs(priv, dev->data->port_id, 509 dev->data->nb_tx_queues); 510 if (ret < 0) 511 return ret; 512 513 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues; 514 priv->ppio_params.maintain_stats = 1; 515 priv->nb_rx_queues = dev->data->nb_rx_queues; 516 517 ret = mrvl_tm_init(dev); 518 if (ret < 0) 519 return ret; 520 521 if (dev->data->nb_rx_queues == 1 && 522 dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) { 523 MRVL_LOG(WARNING, "Disabling hash for 1 rx queue"); 524 priv->ppio_params.inqs_params.hash_type = PP2_PPIO_HASH_T_NONE; 525 priv->configured = 1; 526 return 0; 527 } 528 529 ret = mrvl_configure_rss(priv, 530 &dev->data->dev_conf.rx_adv_conf.rss_conf); 531 if (ret < 0) 532 return ret; 533 534 priv->configured = 1; 535 536 return 0; 537 } 538 539 /** 540 * DPDK callback to change the MTU. 541 * 542 * Setting the MTU affects hardware MRU (packets larger than the MRU 543 * will be dropped). 544 * 545 * @param dev 546 * Pointer to Ethernet device structure. 547 * @param mtu 548 * New MTU. 549 * 550 * @return 551 * 0 on success, negative error value otherwise. 552 */ 553 static int 554 mrvl_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) 555 { 556 struct mrvl_priv *priv = dev->data->dev_private; 557 uint16_t mru; 558 uint16_t mbuf_data_size = 0; /* SW buffer size */ 559 int ret; 560 561 mru = MRVL_PP2_MTU_TO_MRU(mtu); 562 /* 563 * min_rx_buf_size is equal to mbuf data size 564 * if pmd didn't set it differently 565 */ 566 mbuf_data_size = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM; 567 /* Prevent PMD from: 568 * - setting mru greater than the mbuf size resulting in 569 * hw and sw buffer size mismatch 570 * - setting mtu that requires the support of scattered packets 571 * when this feature has not been enabled/supported so far 572 * (TODO check scattered_rx flag here once scattered RX is supported). 573 */ 574 if (mru - RTE_ETHER_CRC_LEN + MRVL_PKT_OFFS > mbuf_data_size) { 575 mru = mbuf_data_size + RTE_ETHER_CRC_LEN - MRVL_PKT_OFFS; 576 mtu = MRVL_PP2_MRU_TO_MTU(mru); 577 MRVL_LOG(WARNING, "MTU too big, max MTU possible limited " 578 "by current mbuf size: %u. Set MTU to %u, MRU to %u", 579 mbuf_data_size, mtu, mru); 580 } 581 582 if (mtu < RTE_ETHER_MIN_MTU || mru > MRVL_PKT_SIZE_MAX) { 583 MRVL_LOG(ERR, "Invalid MTU [%u] or MRU [%u]", mtu, mru); 584 return -EINVAL; 585 } 586 587 if (!priv->ppio) 588 return 0; 589 590 ret = pp2_ppio_set_mru(priv->ppio, mru); 591 if (ret) { 592 MRVL_LOG(ERR, "Failed to change MRU"); 593 return ret; 594 } 595 596 ret = pp2_ppio_set_mtu(priv->ppio, mtu); 597 if (ret) { 598 MRVL_LOG(ERR, "Failed to change MTU"); 599 return ret; 600 } 601 602 return 0; 603 } 604 605 /** 606 * DPDK callback to bring the link up. 607 * 608 * @param dev 609 * Pointer to Ethernet device structure. 610 * 611 * @return 612 * 0 on success, negative error value otherwise. 613 */ 614 static int 615 mrvl_dev_set_link_up(struct rte_eth_dev *dev) 616 { 617 struct mrvl_priv *priv = dev->data->dev_private; 618 int ret; 619 620 if (!priv->ppio) { 621 dev->data->dev_link.link_status = RTE_ETH_LINK_UP; 622 return 0; 623 } 624 625 ret = pp2_ppio_enable(priv->ppio); 626 if (ret) 627 return ret; 628 629 /* 630 * mtu/mru can be updated if pp2_ppio_enable() was called at least once 631 * as pp2_ppio_enable() changes port->t_mode from default 0 to 632 * PP2_TRAFFIC_INGRESS_EGRESS. 633 * 634 * Set mtu to default DPDK value here. 635 */ 636 ret = mrvl_mtu_set(dev, dev->data->mtu); 637 if (ret) { 638 pp2_ppio_disable(priv->ppio); 639 return ret; 640 } 641 642 dev->data->dev_link.link_status = RTE_ETH_LINK_UP; 643 return 0; 644 } 645 646 /** 647 * DPDK callback to bring the link down. 648 * 649 * @param dev 650 * Pointer to Ethernet device structure. 651 * 652 * @return 653 * 0 on success, negative error value otherwise. 654 */ 655 static int 656 mrvl_dev_set_link_down(struct rte_eth_dev *dev) 657 { 658 struct mrvl_priv *priv = dev->data->dev_private; 659 int ret; 660 661 if (!priv->ppio) { 662 dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN; 663 return 0; 664 } 665 ret = pp2_ppio_disable(priv->ppio); 666 if (ret) 667 return ret; 668 669 dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN; 670 return 0; 671 } 672 673 /** 674 * DPDK callback to start tx queue. 675 * 676 * @param dev 677 * Pointer to Ethernet device structure. 678 * @param queue_id 679 * Transmit queue index. 680 * 681 * @return 682 * 0 on success, negative error value otherwise. 683 */ 684 static int 685 mrvl_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id) 686 { 687 struct mrvl_priv *priv = dev->data->dev_private; 688 int ret; 689 690 if (!priv) 691 return -EPERM; 692 693 /* passing 1 enables given tx queue */ 694 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 1); 695 if (ret) { 696 MRVL_LOG(ERR, "Failed to start txq %d", queue_id); 697 return ret; 698 } 699 700 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STARTED; 701 702 return 0; 703 } 704 705 /** 706 * DPDK callback to stop tx queue. 707 * 708 * @param dev 709 * Pointer to Ethernet device structure. 710 * @param queue_id 711 * Transmit queue index. 712 * 713 * @return 714 * 0 on success, negative error value otherwise. 715 */ 716 static int 717 mrvl_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id) 718 { 719 struct mrvl_priv *priv = dev->data->dev_private; 720 int ret; 721 722 if (!priv->ppio) 723 return -EPERM; 724 725 /* passing 0 disables given tx queue */ 726 ret = pp2_ppio_set_outq_state(priv->ppio, queue_id, 0); 727 if (ret) { 728 MRVL_LOG(ERR, "Failed to stop txq %d", queue_id); 729 return ret; 730 } 731 732 dev->data->tx_queue_state[queue_id] = RTE_ETH_QUEUE_STATE_STOPPED; 733 734 return 0; 735 } 736 737 /** 738 * Populate VLAN Filter configuration. 739 * 740 * @param dev 741 * Pointer to Ethernet device structure. 742 * @param on 743 * Toggle filter. 744 * 745 * @return 746 * 0 on success, negative error value otherwise. 747 */ 748 static int mrvl_populate_vlan_table(struct rte_eth_dev *dev, int on) 749 { 750 uint32_t j; 751 int ret; 752 struct rte_vlan_filter_conf *vfc; 753 754 vfc = &dev->data->vlan_filter_conf; 755 for (j = 0; j < RTE_DIM(vfc->ids); j++) { 756 uint64_t vlan; 757 uint64_t vbit; 758 uint64_t ids = vfc->ids[j]; 759 760 if (ids == 0) 761 continue; 762 763 while (ids) { 764 vlan = 64 * j; 765 /* count trailing zeroes */ 766 vbit = ~ids & (ids - 1); 767 /* clear least significant bit set */ 768 ids ^= (ids ^ (ids - 1)) ^ vbit; 769 for (; vbit; vlan++) 770 vbit >>= 1; 771 ret = mrvl_vlan_filter_set(dev, vlan, on); 772 if (ret) { 773 MRVL_LOG(ERR, "Failed to setup VLAN filter"); 774 return ret; 775 } 776 } 777 } 778 779 return 0; 780 } 781 782 /** 783 * DPDK callback to start the device. 784 * 785 * @param dev 786 * Pointer to Ethernet device structure. 787 * 788 * @return 789 * 0 on success, negative errno value on failure. 790 */ 791 static int 792 mrvl_dev_start(struct rte_eth_dev *dev) 793 { 794 struct mrvl_priv *priv = dev->data->dev_private; 795 char match[MRVL_MATCH_LEN]; 796 int ret = 0, i, def_init_size; 797 struct rte_ether_addr *mac_addr; 798 799 if (priv->ppio) 800 return mrvl_dev_set_link_up(dev); 801 802 snprintf(match, sizeof(match), "ppio-%d:%d", 803 priv->pp_id, priv->ppio_id); 804 priv->ppio_params.match = match; 805 priv->ppio_params.eth_start_hdr = PP2_PPIO_HDR_ETH; 806 priv->forward_bad_frames = 0; 807 priv->fill_bpool_buffs = MRVL_BURST_SIZE; 808 809 if (mrvl_cfg) { 810 priv->ppio_params.eth_start_hdr = 811 mrvl_cfg->port[dev->data->port_id].eth_start_hdr; 812 priv->forward_bad_frames = 813 mrvl_cfg->port[dev->data->port_id].forward_bad_frames; 814 priv->fill_bpool_buffs = 815 mrvl_cfg->port[dev->data->port_id].fill_bpool_buffs; 816 } 817 818 /* 819 * Calculate the minimum bpool size for refill feature as follows: 820 * 2 default burst sizes multiply by number of rx queues. 821 * If the bpool size will be below this value, new buffers will 822 * be added to the pool. 823 */ 824 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2; 825 826 /* In case initial bpool size configured in queues setup is 827 * smaller than minimum size add more buffers 828 */ 829 def_init_size = priv->bpool_min_size + MRVL_BURST_SIZE * 2; 830 if (priv->bpool_init_size < def_init_size) { 831 int buffs_to_add = def_init_size - priv->bpool_init_size; 832 833 priv->bpool_init_size += buffs_to_add; 834 ret = mrvl_fill_bpool(dev->data->rx_queues[0], buffs_to_add); 835 if (ret) 836 MRVL_LOG(ERR, "Failed to add buffers to bpool"); 837 } 838 839 /* 840 * Calculate the maximum bpool size for refill feature as follows: 841 * maximum number of descriptors in rx queue multiply by number 842 * of rx queues plus minimum bpool size. 843 * In case the bpool size will exceed this value, superfluous buffers 844 * will be removed 845 */ 846 priv->bpool_max_size = (priv->nb_rx_queues * MRVL_PP2_RXD_MAX) + 847 priv->bpool_min_size; 848 849 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio); 850 if (ret) { 851 MRVL_LOG(ERR, "Failed to init ppio"); 852 return ret; 853 } 854 855 /* 856 * In case there are some stale uc/mc mac addresses flush them 857 * here. It cannot be done during mrvl_dev_close() as port information 858 * is already gone at that point (due to pp2_ppio_deinit() in 859 * mrvl_dev_stop()). 860 */ 861 if (!priv->uc_mc_flushed) { 862 ret = pp2_ppio_flush_mac_addrs(priv->ppio, 1, 1); 863 if (ret) { 864 MRVL_LOG(ERR, 865 "Failed to flush uc/mc filter list"); 866 goto out; 867 } 868 priv->uc_mc_flushed = 1; 869 } 870 871 ret = mrvl_mtu_set(dev, dev->data->mtu); 872 if (ret) 873 MRVL_LOG(ERR, "Failed to set MTU to %d", dev->data->mtu); 874 875 if (!rte_is_zero_ether_addr(&dev->data->mac_addrs[0])) 876 mrvl_mac_addr_set(dev, &dev->data->mac_addrs[0]); 877 878 for (i = 1; i < MRVL_MAC_ADDRS_MAX; i++) { 879 mac_addr = &dev->data->mac_addrs[i]; 880 881 /* skip zero address */ 882 if (rte_is_zero_ether_addr(mac_addr)) 883 continue; 884 885 mrvl_mac_addr_add(dev, mac_addr, i, 0); 886 } 887 888 if (dev->data->all_multicast == 1) 889 mrvl_allmulticast_enable(dev); 890 891 if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) { 892 ret = mrvl_populate_vlan_table(dev, 1); 893 if (ret) { 894 MRVL_LOG(ERR, "Failed to populate VLAN table"); 895 goto out; 896 } 897 } 898 899 /* For default QoS config, don't start classifier. */ 900 if (mrvl_cfg && 901 mrvl_cfg->port[dev->data->port_id].use_qos_global_defaults == 0) { 902 ret = mrvl_start_qos_mapping(priv); 903 if (ret) { 904 MRVL_LOG(ERR, "Failed to setup QoS mapping"); 905 goto out; 906 } 907 } 908 909 ret = pp2_ppio_set_loopback(priv->ppio, dev->data->dev_conf.lpbk_mode); 910 if (ret) { 911 MRVL_LOG(ERR, "Failed to set loopback"); 912 goto out; 913 } 914 915 if (dev->data->promiscuous == 1) 916 mrvl_promiscuous_enable(dev); 917 918 if (priv->flow_ctrl) { 919 ret = mrvl_flow_ctrl_set(dev, &priv->fc_conf); 920 if (ret) { 921 MRVL_LOG(ERR, "Failed to configure flow control"); 922 goto out; 923 } 924 priv->flow_ctrl = 0; 925 } 926 927 if (dev->data->dev_link.link_status == RTE_ETH_LINK_UP) { 928 ret = mrvl_dev_set_link_up(dev); 929 if (ret) { 930 MRVL_LOG(ERR, "Failed to set link up"); 931 dev->data->dev_link.link_status = RTE_ETH_LINK_DOWN; 932 goto out; 933 } 934 } 935 936 /* start tx queues */ 937 for (i = 0; i < dev->data->nb_tx_queues; i++) { 938 struct mrvl_txq *txq = dev->data->tx_queues[i]; 939 940 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; 941 942 if (!txq->tx_deferred_start) 943 continue; 944 945 /* 946 * All txqs are started by default. Stop them 947 * so that tx_deferred_start works as expected. 948 */ 949 ret = mrvl_tx_queue_stop(dev, i); 950 if (ret) 951 goto out; 952 } 953 954 for (i = 0; i < dev->data->nb_rx_queues; i++) 955 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; 956 957 mrvl_flow_init(dev); 958 mrvl_mtr_init(dev); 959 mrvl_set_tx_function(dev); 960 961 return 0; 962 out: 963 MRVL_LOG(ERR, "Failed to start device"); 964 pp2_ppio_deinit(priv->ppio); 965 return ret; 966 } 967 968 /** 969 * Flush receive queues. 970 * 971 * @param dev 972 * Pointer to Ethernet device structure. 973 */ 974 static void 975 mrvl_flush_rx_queues(struct rte_eth_dev *dev) 976 { 977 int i; 978 979 MRVL_LOG(INFO, "Flushing rx queues"); 980 for (i = 0; i < dev->data->nb_rx_queues; i++) { 981 int ret, num; 982 983 do { 984 struct mrvl_rxq *q = dev->data->rx_queues[i]; 985 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX]; 986 987 num = MRVL_PP2_RXD_MAX; 988 ret = pp2_ppio_recv(q->priv->ppio, 989 q->priv->rxq_map[q->queue_id].tc, 990 q->priv->rxq_map[q->queue_id].inq, 991 descs, (uint16_t *)&num); 992 } while (ret == 0 && num); 993 } 994 } 995 996 /** 997 * Flush transmit shadow queues. 998 * 999 * @param dev 1000 * Pointer to Ethernet device structure. 1001 */ 1002 static void 1003 mrvl_flush_tx_shadow_queues(struct rte_eth_dev *dev) 1004 { 1005 int i, j; 1006 struct mrvl_txq *txq; 1007 1008 MRVL_LOG(INFO, "Flushing tx shadow queues"); 1009 for (i = 0; i < dev->data->nb_tx_queues; i++) { 1010 txq = (struct mrvl_txq *)dev->data->tx_queues[i]; 1011 1012 for (j = 0; j < RTE_MAX_LCORE; j++) { 1013 struct mrvl_shadow_txq *sq; 1014 1015 if (!hifs[j]) 1016 continue; 1017 1018 sq = &txq->shadow_txqs[j]; 1019 mrvl_free_sent_buffers(txq->priv->ppio, 1020 hifs[j], j, sq, txq->queue_id, 1); 1021 while (sq->tail != sq->head) { 1022 uint64_t addr = cookie_addr_high | 1023 sq->ent[sq->tail].buff.cookie; 1024 rte_pktmbuf_free( 1025 (struct rte_mbuf *)addr); 1026 sq->tail = (sq->tail + 1) & 1027 MRVL_PP2_TX_SHADOWQ_MASK; 1028 } 1029 memset(sq, 0, sizeof(*sq)); 1030 } 1031 } 1032 } 1033 1034 /** 1035 * Flush hardware bpool (buffer-pool). 1036 * 1037 * @param dev 1038 * Pointer to Ethernet device structure. 1039 */ 1040 static void 1041 mrvl_flush_bpool(struct rte_eth_dev *dev) 1042 { 1043 struct mrvl_priv *priv = dev->data->dev_private; 1044 struct pp2_hif *hif; 1045 uint32_t num; 1046 int ret; 1047 unsigned int core_id = rte_lcore_id(); 1048 1049 if (core_id == LCORE_ID_ANY) 1050 core_id = rte_get_main_lcore(); 1051 1052 hif = mrvl_get_hif(priv, core_id); 1053 1054 ret = pp2_bpool_get_num_buffs(priv->bpool, &num); 1055 if (ret) { 1056 MRVL_LOG(ERR, "Failed to get bpool buffers number"); 1057 return; 1058 } 1059 1060 while (num--) { 1061 struct pp2_buff_inf inf; 1062 uint64_t addr; 1063 1064 ret = pp2_bpool_get_buff(hif, priv->bpool, &inf); 1065 if (ret) 1066 break; 1067 1068 addr = cookie_addr_high | inf.cookie; 1069 rte_pktmbuf_free((struct rte_mbuf *)addr); 1070 } 1071 } 1072 1073 /** 1074 * DPDK callback to stop the device. 1075 * 1076 * @param dev 1077 * Pointer to Ethernet device structure. 1078 */ 1079 static int 1080 mrvl_dev_stop(struct rte_eth_dev *dev) 1081 { 1082 uint16_t i; 1083 1084 for (i = 0; i < dev->data->nb_rx_queues; i++) 1085 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; 1086 for (i = 0; i < dev->data->nb_tx_queues; i++) 1087 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; 1088 1089 return mrvl_dev_set_link_down(dev); 1090 } 1091 1092 /** 1093 * DPDK callback to close the device. 1094 * 1095 * @param dev 1096 * Pointer to Ethernet device structure. 1097 */ 1098 static int 1099 mrvl_dev_close(struct rte_eth_dev *dev) 1100 { 1101 struct mrvl_priv *priv = dev->data->dev_private; 1102 size_t i; 1103 1104 if (rte_eal_process_type() != RTE_PROC_PRIMARY) 1105 return 0; 1106 1107 mrvl_flush_rx_queues(dev); 1108 mrvl_flush_tx_shadow_queues(dev); 1109 mrvl_flow_deinit(dev); 1110 mrvl_mtr_deinit(dev); 1111 1112 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) { 1113 struct pp2_ppio_tc_params *tc_params = 1114 &priv->ppio_params.inqs_params.tcs_params[i]; 1115 1116 if (tc_params->inqs_params) { 1117 rte_free(tc_params->inqs_params); 1118 tc_params->inqs_params = NULL; 1119 } 1120 } 1121 1122 if (priv->cls_tbl) { 1123 pp2_cls_tbl_deinit(priv->cls_tbl); 1124 priv->cls_tbl = NULL; 1125 } 1126 1127 if (priv->qos_tbl) { 1128 pp2_cls_qos_tbl_deinit(priv->qos_tbl); 1129 priv->qos_tbl = NULL; 1130 } 1131 1132 mrvl_flush_bpool(dev); 1133 mrvl_tm_deinit(dev); 1134 1135 if (priv->ppio) { 1136 pp2_ppio_deinit(priv->ppio); 1137 priv->ppio = NULL; 1138 } 1139 1140 /* policer must be released after ppio deinitialization */ 1141 if (priv->default_policer) { 1142 pp2_cls_plcr_deinit(priv->default_policer); 1143 priv->default_policer = NULL; 1144 } 1145 1146 1147 if (priv->bpool) { 1148 pp2_bpool_deinit(priv->bpool); 1149 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit); 1150 priv->bpool = NULL; 1151 } 1152 1153 mrvl_dev_num--; 1154 1155 if (mrvl_dev_num == 0) { 1156 MRVL_LOG(INFO, "Perform MUSDK deinit"); 1157 mrvl_deinit_hifs(); 1158 mrvl_deinit_pp2(); 1159 rte_mvep_deinit(MVEP_MOD_T_PP2); 1160 } 1161 1162 return 0; 1163 } 1164 1165 /** 1166 * DPDK callback to retrieve physical link information. 1167 * 1168 * @param dev 1169 * Pointer to Ethernet device structure. 1170 * @param wait_to_complete 1171 * Wait for request completion (ignored). 1172 * 1173 * @return 1174 * 0 on success, negative error value otherwise. 1175 */ 1176 static int 1177 mrvl_link_update(struct rte_eth_dev *dev, int wait_to_complete __rte_unused) 1178 { 1179 /* 1180 * TODO 1181 * once MUSDK provides necessary API use it here 1182 */ 1183 struct mrvl_priv *priv = dev->data->dev_private; 1184 struct ethtool_cmd edata; 1185 struct ifreq req; 1186 int ret, fd, link_up; 1187 1188 if (!priv->ppio) 1189 return -EPERM; 1190 1191 edata.cmd = ETHTOOL_GSET; 1192 1193 strcpy(req.ifr_name, dev->data->name); 1194 req.ifr_data = (void *)&edata; 1195 1196 fd = socket(AF_INET, SOCK_DGRAM, 0); 1197 if (fd == -1) 1198 return -EFAULT; 1199 1200 ret = ioctl(fd, SIOCETHTOOL, &req); 1201 if (ret == -1) { 1202 close(fd); 1203 return -EFAULT; 1204 } 1205 1206 close(fd); 1207 1208 switch (ethtool_cmd_speed(&edata)) { 1209 case SPEED_10: 1210 dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_10M; 1211 break; 1212 case SPEED_100: 1213 dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_100M; 1214 break; 1215 case SPEED_1000: 1216 dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_1G; 1217 break; 1218 case SPEED_2500: 1219 dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_2_5G; 1220 break; 1221 case SPEED_10000: 1222 dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_10G; 1223 break; 1224 default: 1225 dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_NONE; 1226 } 1227 1228 dev->data->dev_link.link_duplex = edata.duplex ? RTE_ETH_LINK_FULL_DUPLEX : 1229 RTE_ETH_LINK_HALF_DUPLEX; 1230 dev->data->dev_link.link_autoneg = edata.autoneg ? RTE_ETH_LINK_AUTONEG : 1231 RTE_ETH_LINK_FIXED; 1232 pp2_ppio_get_link_state(priv->ppio, &link_up); 1233 dev->data->dev_link.link_status = link_up ? RTE_ETH_LINK_UP : RTE_ETH_LINK_DOWN; 1234 1235 return 0; 1236 } 1237 1238 /** 1239 * DPDK callback to enable promiscuous mode. 1240 * 1241 * @param dev 1242 * Pointer to Ethernet device structure. 1243 * 1244 * @return 1245 * 0 on success, negative error value otherwise. 1246 */ 1247 static int 1248 mrvl_promiscuous_enable(struct rte_eth_dev *dev) 1249 { 1250 struct mrvl_priv *priv = dev->data->dev_private; 1251 int ret; 1252 1253 if (priv->isolated) 1254 return -ENOTSUP; 1255 1256 if (!priv->ppio) 1257 return 0; 1258 1259 ret = pp2_ppio_set_promisc(priv->ppio, 1); 1260 if (ret) { 1261 MRVL_LOG(ERR, "Failed to enable promiscuous mode"); 1262 return -EAGAIN; 1263 } 1264 1265 return 0; 1266 } 1267 1268 /** 1269 * DPDK callback to enable allmulti mode. 1270 * 1271 * @param dev 1272 * Pointer to Ethernet device structure. 1273 * 1274 * @return 1275 * 0 on success, negative error value otherwise. 1276 */ 1277 static int 1278 mrvl_allmulticast_enable(struct rte_eth_dev *dev) 1279 { 1280 struct mrvl_priv *priv = dev->data->dev_private; 1281 int ret; 1282 1283 if (priv->isolated) 1284 return -ENOTSUP; 1285 1286 if (!priv->ppio) 1287 return 0; 1288 1289 ret = pp2_ppio_set_mc_promisc(priv->ppio, 1); 1290 if (ret) { 1291 MRVL_LOG(ERR, "Failed enable all-multicast mode"); 1292 return -EAGAIN; 1293 } 1294 1295 return 0; 1296 } 1297 1298 /** 1299 * DPDK callback to disable promiscuous mode. 1300 * 1301 * @param dev 1302 * Pointer to Ethernet device structure. 1303 * 1304 * @return 1305 * 0 on success, negative error value otherwise. 1306 */ 1307 static int 1308 mrvl_promiscuous_disable(struct rte_eth_dev *dev) 1309 { 1310 struct mrvl_priv *priv = dev->data->dev_private; 1311 int ret; 1312 1313 if (priv->isolated) 1314 return -ENOTSUP; 1315 1316 if (!priv->ppio) 1317 return 0; 1318 1319 ret = pp2_ppio_set_promisc(priv->ppio, 0); 1320 if (ret) { 1321 MRVL_LOG(ERR, "Failed to disable promiscuous mode"); 1322 return -EAGAIN; 1323 } 1324 1325 return 0; 1326 } 1327 1328 /** 1329 * DPDK callback to disable allmulticast mode. 1330 * 1331 * @param dev 1332 * Pointer to Ethernet device structure. 1333 * 1334 * @return 1335 * 0 on success, negative error value otherwise. 1336 */ 1337 static int 1338 mrvl_allmulticast_disable(struct rte_eth_dev *dev) 1339 { 1340 struct mrvl_priv *priv = dev->data->dev_private; 1341 int ret; 1342 1343 if (priv->isolated) 1344 return -ENOTSUP; 1345 1346 if (!priv->ppio) 1347 return 0; 1348 1349 ret = pp2_ppio_set_mc_promisc(priv->ppio, 0); 1350 if (ret) { 1351 MRVL_LOG(ERR, "Failed to disable all-multicast mode"); 1352 return -EAGAIN; 1353 } 1354 1355 return 0; 1356 } 1357 1358 /** 1359 * DPDK callback to remove a MAC address. 1360 * 1361 * @param dev 1362 * Pointer to Ethernet device structure. 1363 * @param index 1364 * MAC address index. 1365 */ 1366 static void 1367 mrvl_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) 1368 { 1369 struct mrvl_priv *priv = dev->data->dev_private; 1370 char buf[RTE_ETHER_ADDR_FMT_SIZE]; 1371 int ret; 1372 1373 if (priv->isolated) 1374 return; 1375 1376 if (!priv->ppio) 1377 return; 1378 1379 ret = pp2_ppio_remove_mac_addr(priv->ppio, 1380 dev->data->mac_addrs[index].addr_bytes); 1381 if (ret) { 1382 rte_ether_format_addr(buf, sizeof(buf), 1383 &dev->data->mac_addrs[index]); 1384 MRVL_LOG(ERR, "Failed to remove mac %s", buf); 1385 } 1386 } 1387 1388 /** 1389 * DPDK callback to add a MAC address. 1390 * 1391 * @param dev 1392 * Pointer to Ethernet device structure. 1393 * @param mac_addr 1394 * MAC address to register. 1395 * @param index 1396 * MAC address index. 1397 * @param vmdq 1398 * VMDq pool index to associate address with (unused). 1399 * 1400 * @return 1401 * 0 on success, negative error value otherwise. 1402 */ 1403 static int 1404 mrvl_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr, 1405 uint32_t index, uint32_t vmdq __rte_unused) 1406 { 1407 struct mrvl_priv *priv = dev->data->dev_private; 1408 char buf[RTE_ETHER_ADDR_FMT_SIZE]; 1409 int ret; 1410 1411 if (priv->isolated) 1412 return -ENOTSUP; 1413 1414 if (!priv->ppio) 1415 return 0; 1416 1417 if (index == 0) 1418 /* For setting index 0, mrvl_mac_addr_set() should be used.*/ 1419 return -1; 1420 1421 /* 1422 * Maximum number of uc addresses can be tuned via kernel module mvpp2x 1423 * parameter uc_filter_max. Maximum number of mc addresses is then 1424 * MRVL_MAC_ADDRS_MAX - uc_filter_max. Currently it defaults to 4 and 1425 * 21 respectively. 1426 * 1427 * If more than uc_filter_max uc addresses were added to filter list 1428 * then NIC will switch to promiscuous mode automatically. 1429 * 1430 * If more than MRVL_MAC_ADDRS_MAX - uc_filter_max number mc addresses 1431 * were added to filter list then NIC will switch to all-multicast mode 1432 * automatically. 1433 */ 1434 ret = pp2_ppio_add_mac_addr(priv->ppio, mac_addr->addr_bytes); 1435 if (ret) { 1436 rte_ether_format_addr(buf, sizeof(buf), mac_addr); 1437 MRVL_LOG(ERR, "Failed to add mac %s", buf); 1438 return -1; 1439 } 1440 1441 return 0; 1442 } 1443 1444 /** 1445 * DPDK callback to set the primary MAC address. 1446 * 1447 * @param dev 1448 * Pointer to Ethernet device structure. 1449 * @param mac_addr 1450 * MAC address to register. 1451 * 1452 * @return 1453 * 0 on success, negative error value otherwise. 1454 */ 1455 static int 1456 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) 1457 { 1458 struct mrvl_priv *priv = dev->data->dev_private; 1459 int ret; 1460 1461 if (priv->isolated) 1462 return -ENOTSUP; 1463 1464 if (!priv->ppio) 1465 return 0; 1466 1467 ret = pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes); 1468 if (ret) { 1469 char buf[RTE_ETHER_ADDR_FMT_SIZE]; 1470 rte_ether_format_addr(buf, sizeof(buf), mac_addr); 1471 MRVL_LOG(ERR, "Failed to set mac to %s", buf); 1472 } 1473 1474 return ret; 1475 } 1476 1477 /** 1478 * DPDK callback to get device statistics. 1479 * 1480 * @param dev 1481 * Pointer to Ethernet device structure. 1482 * @param stats 1483 * Stats structure output buffer. 1484 * 1485 * @return 1486 * 0 on success, negative error value otherwise. 1487 */ 1488 static int 1489 mrvl_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) 1490 { 1491 struct mrvl_priv *priv = dev->data->dev_private; 1492 struct pp2_ppio_statistics ppio_stats; 1493 uint64_t drop_mac = 0; 1494 unsigned int i, idx, ret; 1495 1496 if (!priv->ppio) 1497 return -EPERM; 1498 1499 for (i = 0; i < dev->data->nb_rx_queues; i++) { 1500 struct mrvl_rxq *rxq = dev->data->rx_queues[i]; 1501 struct pp2_ppio_inq_statistics rx_stats; 1502 1503 if (!rxq) 1504 continue; 1505 1506 idx = rxq->queue_id; 1507 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) { 1508 MRVL_LOG(ERR, 1509 "rx queue %d stats out of range (0 - %d)", 1510 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1); 1511 continue; 1512 } 1513 1514 ret = pp2_ppio_inq_get_statistics(priv->ppio, 1515 priv->rxq_map[idx].tc, 1516 priv->rxq_map[idx].inq, 1517 &rx_stats, 0); 1518 if (unlikely(ret)) { 1519 MRVL_LOG(ERR, 1520 "Failed to update rx queue %d stats", idx); 1521 break; 1522 } 1523 1524 stats->q_ibytes[idx] = rxq->bytes_recv; 1525 stats->q_ipackets[idx] = rx_stats.enq_desc - rxq->drop_mac; 1526 stats->q_errors[idx] = rx_stats.drop_early + 1527 rx_stats.drop_fullq + 1528 rx_stats.drop_bm + 1529 rxq->drop_mac; 1530 stats->ibytes += rxq->bytes_recv; 1531 drop_mac += rxq->drop_mac; 1532 } 1533 1534 for (i = 0; i < dev->data->nb_tx_queues; i++) { 1535 struct mrvl_txq *txq = dev->data->tx_queues[i]; 1536 struct pp2_ppio_outq_statistics tx_stats; 1537 1538 if (!txq) 1539 continue; 1540 1541 idx = txq->queue_id; 1542 if (unlikely(idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)) { 1543 MRVL_LOG(ERR, 1544 "tx queue %d stats out of range (0 - %d)", 1545 idx, RTE_ETHDEV_QUEUE_STAT_CNTRS - 1); 1546 } 1547 1548 ret = pp2_ppio_outq_get_statistics(priv->ppio, idx, 1549 &tx_stats, 0); 1550 if (unlikely(ret)) { 1551 MRVL_LOG(ERR, 1552 "Failed to update tx queue %d stats", idx); 1553 break; 1554 } 1555 1556 stats->q_opackets[idx] = tx_stats.deq_desc; 1557 stats->q_obytes[idx] = txq->bytes_sent; 1558 stats->obytes += txq->bytes_sent; 1559 } 1560 1561 ret = pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0); 1562 if (unlikely(ret)) { 1563 MRVL_LOG(ERR, "Failed to update port statistics"); 1564 return ret; 1565 } 1566 1567 stats->ipackets += ppio_stats.rx_packets - drop_mac; 1568 stats->opackets += ppio_stats.tx_packets; 1569 stats->imissed += ppio_stats.rx_fullq_dropped + 1570 ppio_stats.rx_bm_dropped + 1571 ppio_stats.rx_early_dropped + 1572 ppio_stats.rx_fifo_dropped + 1573 ppio_stats.rx_cls_dropped; 1574 stats->ierrors = drop_mac; 1575 1576 return 0; 1577 } 1578 1579 /** 1580 * DPDK callback to clear device statistics. 1581 * 1582 * @param dev 1583 * Pointer to Ethernet device structure. 1584 * 1585 * @return 1586 * 0 on success, negative error value otherwise. 1587 */ 1588 static int 1589 mrvl_stats_reset(struct rte_eth_dev *dev) 1590 { 1591 struct mrvl_priv *priv = dev->data->dev_private; 1592 int i; 1593 1594 if (!priv->ppio) 1595 return 0; 1596 1597 for (i = 0; i < dev->data->nb_rx_queues; i++) { 1598 struct mrvl_rxq *rxq = dev->data->rx_queues[i]; 1599 1600 pp2_ppio_inq_get_statistics(priv->ppio, priv->rxq_map[i].tc, 1601 priv->rxq_map[i].inq, NULL, 1); 1602 rxq->bytes_recv = 0; 1603 rxq->drop_mac = 0; 1604 } 1605 1606 for (i = 0; i < dev->data->nb_tx_queues; i++) { 1607 struct mrvl_txq *txq = dev->data->tx_queues[i]; 1608 1609 pp2_ppio_outq_get_statistics(priv->ppio, i, NULL, 1); 1610 txq->bytes_sent = 0; 1611 } 1612 1613 return pp2_ppio_get_statistics(priv->ppio, NULL, 1); 1614 } 1615 1616 /** 1617 * DPDK callback to get extended statistics. 1618 * 1619 * @param dev 1620 * Pointer to Ethernet device structure. 1621 * @param stats 1622 * Pointer to xstats table. 1623 * @param n 1624 * Number of entries in xstats table. 1625 * @return 1626 * Negative value on error, number of read xstats otherwise. 1627 */ 1628 static int 1629 mrvl_xstats_get(struct rte_eth_dev *dev, 1630 struct rte_eth_xstat *stats, unsigned int n) 1631 { 1632 struct mrvl_priv *priv = dev->data->dev_private; 1633 struct pp2_ppio_statistics ppio_stats; 1634 unsigned int i, count; 1635 1636 count = RTE_DIM(mrvl_xstats_tbl); 1637 if (n < count) 1638 return count; 1639 1640 pp2_ppio_get_statistics(priv->ppio, &ppio_stats, 0); 1641 for (i = 0; i < count; i++) { 1642 uint64_t val; 1643 1644 if (mrvl_xstats_tbl[i].size == sizeof(uint32_t)) 1645 val = *(uint32_t *)((uint8_t *)&ppio_stats + 1646 mrvl_xstats_tbl[i].offset); 1647 else if (mrvl_xstats_tbl[i].size == sizeof(uint64_t)) 1648 val = *(uint64_t *)((uint8_t *)&ppio_stats + 1649 mrvl_xstats_tbl[i].offset); 1650 else 1651 return -EINVAL; 1652 1653 stats[i].id = i; 1654 stats[i].value = val; 1655 } 1656 1657 return count; 1658 } 1659 1660 /** 1661 * DPDK callback to reset extended statistics. 1662 * 1663 * @param dev 1664 * Pointer to Ethernet device structure. 1665 * 1666 * @return 1667 * 0 on success, negative error value otherwise. 1668 */ 1669 static int 1670 mrvl_xstats_reset(struct rte_eth_dev *dev) 1671 { 1672 return mrvl_stats_reset(dev); 1673 } 1674 1675 /** 1676 * DPDK callback to get extended statistics names. 1677 * 1678 * @param dev (unused) 1679 * Pointer to Ethernet device structure. 1680 * @param xstats_names 1681 * Pointer to xstats names table. 1682 * @param size 1683 * Size of the xstats names table. 1684 * @return 1685 * Number of read names. 1686 */ 1687 static int 1688 mrvl_xstats_get_names(struct rte_eth_dev *dev __rte_unused, 1689 struct rte_eth_xstat_name *xstats_names, 1690 unsigned int size) 1691 { 1692 unsigned int i; 1693 1694 if (!xstats_names) 1695 return RTE_DIM(mrvl_xstats_tbl); 1696 1697 for (i = 0; i < size && i < RTE_DIM(mrvl_xstats_tbl); i++) 1698 strlcpy(xstats_names[i].name, mrvl_xstats_tbl[i].name, 1699 RTE_ETH_XSTATS_NAME_SIZE); 1700 1701 return size; 1702 } 1703 1704 /** 1705 * DPDK callback to get information about the device. 1706 * 1707 * @param dev 1708 * Pointer to Ethernet device structure (unused). 1709 * @param info 1710 * Info structure output buffer. 1711 */ 1712 static int 1713 mrvl_dev_infos_get(struct rte_eth_dev *dev, 1714 struct rte_eth_dev_info *info) 1715 { 1716 struct mrvl_priv *priv = dev->data->dev_private; 1717 1718 info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP; 1719 1720 info->speed_capa = RTE_ETH_LINK_SPEED_10M | 1721 RTE_ETH_LINK_SPEED_100M | 1722 RTE_ETH_LINK_SPEED_1G | 1723 RTE_ETH_LINK_SPEED_2_5G | 1724 RTE_ETH_LINK_SPEED_10G; 1725 1726 info->max_rx_queues = MRVL_PP2_RXQ_MAX; 1727 info->max_tx_queues = MRVL_PP2_TXQ_MAX; 1728 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX; 1729 1730 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX; 1731 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN; 1732 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN; 1733 1734 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX; 1735 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN; 1736 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN; 1737 1738 info->rx_offload_capa = MRVL_RX_OFFLOADS; 1739 info->rx_queue_offload_capa = MRVL_RX_OFFLOADS; 1740 1741 info->tx_offload_capa = MRVL_TX_OFFLOADS; 1742 info->tx_queue_offload_capa = MRVL_TX_OFFLOADS; 1743 1744 info->flow_type_rss_offloads = RTE_ETH_RSS_IPV4 | 1745 RTE_ETH_RSS_NONFRAG_IPV4_TCP | 1746 RTE_ETH_RSS_NONFRAG_IPV4_UDP; 1747 1748 /* By default packets are dropped if no descriptors are available */ 1749 info->default_rxconf.rx_drop_en = 1; 1750 1751 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX; 1752 info->max_mtu = priv->max_mtu; 1753 1754 return 0; 1755 } 1756 1757 /** 1758 * Return supported packet types. 1759 * 1760 * @param dev 1761 * Pointer to Ethernet device structure (unused). 1762 * 1763 * @return 1764 * Const pointer to the table with supported packet types. 1765 */ 1766 static const uint32_t * 1767 mrvl_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused, 1768 size_t *no_of_elements) 1769 { 1770 static const uint32_t ptypes[] = { 1771 RTE_PTYPE_L2_ETHER, 1772 RTE_PTYPE_L2_ETHER_VLAN, 1773 RTE_PTYPE_L2_ETHER_QINQ, 1774 RTE_PTYPE_L3_IPV4, 1775 RTE_PTYPE_L3_IPV4_EXT, 1776 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN, 1777 RTE_PTYPE_L3_IPV6, 1778 RTE_PTYPE_L3_IPV6_EXT, 1779 RTE_PTYPE_L2_ETHER_ARP, 1780 RTE_PTYPE_L4_TCP, 1781 RTE_PTYPE_L4_UDP, 1782 }; 1783 1784 *no_of_elements = RTE_DIM(ptypes); 1785 return ptypes; 1786 } 1787 1788 /** 1789 * DPDK callback to get information about specific receive queue. 1790 * 1791 * @param dev 1792 * Pointer to Ethernet device structure. 1793 * @param rx_queue_id 1794 * Receive queue index. 1795 * @param qinfo 1796 * Receive queue information structure. 1797 */ 1798 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id, 1799 struct rte_eth_rxq_info *qinfo) 1800 { 1801 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id]; 1802 struct mrvl_priv *priv = dev->data->dev_private; 1803 int inq = priv->rxq_map[rx_queue_id].inq; 1804 int tc = priv->rxq_map[rx_queue_id].tc; 1805 struct pp2_ppio_tc_params *tc_params = 1806 &priv->ppio_params.inqs_params.tcs_params[tc]; 1807 1808 qinfo->mp = q->mp; 1809 qinfo->nb_desc = tc_params->inqs_params[inq].size; 1810 } 1811 1812 /** 1813 * DPDK callback to get information about specific transmit queue. 1814 * 1815 * @param dev 1816 * Pointer to Ethernet device structure. 1817 * @param tx_queue_id 1818 * Transmit queue index. 1819 * @param qinfo 1820 * Transmit queue information structure. 1821 */ 1822 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id, 1823 struct rte_eth_txq_info *qinfo) 1824 { 1825 struct mrvl_priv *priv = dev->data->dev_private; 1826 struct mrvl_txq *txq = dev->data->tx_queues[tx_queue_id]; 1827 1828 qinfo->nb_desc = 1829 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size; 1830 qinfo->conf.tx_deferred_start = txq->tx_deferred_start; 1831 } 1832 1833 /** 1834 * DPDK callback to Configure a VLAN filter. 1835 * 1836 * @param dev 1837 * Pointer to Ethernet device structure. 1838 * @param vlan_id 1839 * VLAN ID to filter. 1840 * @param on 1841 * Toggle filter. 1842 * 1843 * @return 1844 * 0 on success, negative error value otherwise. 1845 */ 1846 static int 1847 mrvl_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on) 1848 { 1849 struct mrvl_priv *priv = dev->data->dev_private; 1850 1851 if (priv->isolated) 1852 return -ENOTSUP; 1853 1854 if (!priv->ppio) 1855 return 0; 1856 1857 return on ? pp2_ppio_add_vlan(priv->ppio, vlan_id) : 1858 pp2_ppio_remove_vlan(priv->ppio, vlan_id); 1859 } 1860 1861 /** 1862 * DPDK callback to Configure VLAN offload. 1863 * 1864 * @param dev 1865 * Pointer to Ethernet device structure. 1866 * @param mask 1867 * VLAN offload mask. 1868 * 1869 * @return 1870 * 0 on success, negative error value otherwise. 1871 */ 1872 static int mrvl_vlan_offload_set(struct rte_eth_dev *dev, int mask) 1873 { 1874 uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads; 1875 int ret; 1876 1877 if (mask & RTE_ETH_VLAN_STRIP_MASK) { 1878 MRVL_LOG(ERR, "VLAN stripping is not supported"); 1879 return -ENOTSUP; 1880 } 1881 1882 if (mask & RTE_ETH_VLAN_FILTER_MASK) { 1883 if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) 1884 ret = mrvl_populate_vlan_table(dev, 1); 1885 else 1886 ret = mrvl_populate_vlan_table(dev, 0); 1887 1888 if (ret) 1889 return ret; 1890 } 1891 1892 if (mask & RTE_ETH_VLAN_EXTEND_MASK) { 1893 MRVL_LOG(ERR, "Extend VLAN not supported"); 1894 return -ENOTSUP; 1895 } 1896 1897 return 0; 1898 } 1899 1900 /** 1901 * Release buffers to hardware bpool (buffer-pool) 1902 * 1903 * @param rxq 1904 * Receive queue pointer. 1905 * @param num 1906 * Number of buffers to release to bpool. 1907 * 1908 * @return 1909 * 0 on success, negative error value otherwise. 1910 */ 1911 static int 1912 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num) 1913 { 1914 struct buff_release_entry entries[num]; 1915 struct rte_mbuf *mbufs[num]; 1916 int i, ret; 1917 unsigned int core_id; 1918 struct pp2_hif *hif; 1919 struct pp2_bpool *bpool; 1920 1921 core_id = rte_lcore_id(); 1922 if (core_id == LCORE_ID_ANY) 1923 core_id = rte_get_main_lcore(); 1924 1925 hif = mrvl_get_hif(rxq->priv, core_id); 1926 if (!hif) 1927 return -1; 1928 1929 bpool = rxq->priv->bpool; 1930 1931 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num); 1932 if (ret) 1933 return ret; 1934 1935 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID) 1936 cookie_addr_high = 1937 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK; 1938 1939 for (i = 0; i < num; i++) { 1940 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK) 1941 != cookie_addr_high) { 1942 MRVL_LOG(ERR, 1943 "mbuf virtual addr high is out of range " 1944 "0x%x instead of 0x%x", 1945 (uint32_t)((uint64_t)mbufs[i] >> 32), 1946 (uint32_t)(cookie_addr_high >> 32)); 1947 goto out; 1948 } 1949 1950 entries[i].buff.addr = 1951 rte_mbuf_data_iova_default(mbufs[i]); 1952 entries[i].buff.cookie = (uintptr_t)mbufs[i]; 1953 entries[i].bpool = bpool; 1954 } 1955 1956 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i); 1957 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] += i; 1958 1959 if (i != num) 1960 goto out; 1961 1962 return 0; 1963 out: 1964 for (; i < num; i++) 1965 rte_pktmbuf_free(mbufs[i]); 1966 1967 return -1; 1968 } 1969 1970 /** 1971 * DPDK callback to configure the receive queue. 1972 * 1973 * @param dev 1974 * Pointer to Ethernet device structure. 1975 * @param idx 1976 * RX queue index. 1977 * @param desc 1978 * Number of descriptors to configure in queue. 1979 * @param socket 1980 * NUMA socket on which memory must be allocated. 1981 * @param conf 1982 * Thresholds parameters. 1983 * @param mp 1984 * Memory pool for buffer allocations. 1985 * 1986 * @return 1987 * 0 on success, negative error value otherwise. 1988 */ 1989 static int 1990 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, 1991 unsigned int socket, 1992 const struct rte_eth_rxconf *conf, 1993 struct rte_mempool *mp) 1994 { 1995 struct mrvl_priv *priv = dev->data->dev_private; 1996 struct mrvl_rxq *rxq; 1997 uint32_t frame_size, buf_size = rte_pktmbuf_data_room_size(mp); 1998 uint32_t max_rx_pktlen = dev->data->mtu + RTE_ETHER_HDR_LEN; 1999 int ret, tc, inq; 2000 uint64_t offloads; 2001 2002 offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads; 2003 2004 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) { 2005 /* 2006 * Unknown TC mapping, mapping will not have a correct queue. 2007 */ 2008 MRVL_LOG(ERR, "Unknown TC mapping for queue %hu eth%hhu", 2009 idx, priv->ppio_id); 2010 return -EFAULT; 2011 } 2012 2013 frame_size = buf_size - RTE_PKTMBUF_HEADROOM - MRVL_PKT_EFFEC_OFFS; 2014 if (frame_size < max_rx_pktlen) { 2015 MRVL_LOG(WARNING, 2016 "Mbuf size must be increased to %u bytes to hold up " 2017 "to %u bytes of data.", 2018 max_rx_pktlen + buf_size - frame_size, 2019 max_rx_pktlen); 2020 dev->data->mtu = frame_size - RTE_ETHER_HDR_LEN; 2021 MRVL_LOG(INFO, "Setting MTU to %u", dev->data->mtu); 2022 } 2023 2024 if (dev->data->rx_queues[idx]) { 2025 rte_free(dev->data->rx_queues[idx]); 2026 dev->data->rx_queues[idx] = NULL; 2027 } 2028 2029 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket); 2030 if (!rxq) 2031 return -ENOMEM; 2032 2033 rxq->priv = priv; 2034 rxq->mp = mp; 2035 rxq->cksum_enabled = offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM; 2036 rxq->queue_id = idx; 2037 rxq->port_id = dev->data->port_id; 2038 mrvl_port_to_bpool_lookup[rxq->port_id] = priv->bpool; 2039 2040 tc = priv->rxq_map[rxq->queue_id].tc, 2041 inq = priv->rxq_map[rxq->queue_id].inq; 2042 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size = 2043 desc; 2044 2045 ret = mrvl_fill_bpool(rxq, desc); 2046 if (ret) { 2047 rte_free(rxq); 2048 return ret; 2049 } 2050 2051 priv->bpool_init_size += desc; 2052 2053 dev->data->rx_queues[idx] = rxq; 2054 2055 return 0; 2056 } 2057 2058 /** 2059 * DPDK callback to release the receive queue. 2060 * 2061 * @param dev 2062 * Pointer to Ethernet device structure. 2063 * @param qid 2064 * Receive queue index. 2065 */ 2066 static void 2067 mrvl_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid) 2068 { 2069 struct mrvl_rxq *q = dev->data->rx_queues[qid]; 2070 struct pp2_ppio_tc_params *tc_params; 2071 int i, num, tc, inq; 2072 struct pp2_hif *hif; 2073 unsigned int core_id = rte_lcore_id(); 2074 2075 if (core_id == LCORE_ID_ANY) 2076 core_id = rte_get_main_lcore(); 2077 2078 if (!q) 2079 return; 2080 2081 hif = mrvl_get_hif(q->priv, core_id); 2082 2083 if (!hif) 2084 return; 2085 2086 tc = q->priv->rxq_map[q->queue_id].tc; 2087 inq = q->priv->rxq_map[q->queue_id].inq; 2088 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc]; 2089 num = tc_params->inqs_params[inq].size; 2090 for (i = 0; i < num; i++) { 2091 struct pp2_buff_inf inf; 2092 uint64_t addr; 2093 2094 pp2_bpool_get_buff(hif, q->priv->bpool, &inf); 2095 addr = cookie_addr_high | inf.cookie; 2096 rte_pktmbuf_free((struct rte_mbuf *)addr); 2097 } 2098 2099 rte_free(q); 2100 } 2101 2102 /** 2103 * DPDK callback to configure the transmit queue. 2104 * 2105 * @param dev 2106 * Pointer to Ethernet device structure. 2107 * @param idx 2108 * Transmit queue index. 2109 * @param desc 2110 * Number of descriptors to configure in the queue. 2111 * @param socket 2112 * NUMA socket on which memory must be allocated. 2113 * @param conf 2114 * Tx queue configuration parameters. 2115 * 2116 * @return 2117 * 0 on success, negative error value otherwise. 2118 */ 2119 static int 2120 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, 2121 unsigned int socket, 2122 const struct rte_eth_txconf *conf) 2123 { 2124 struct mrvl_priv *priv = dev->data->dev_private; 2125 struct mrvl_txq *txq; 2126 2127 if (dev->data->tx_queues[idx]) { 2128 rte_free(dev->data->tx_queues[idx]); 2129 dev->data->tx_queues[idx] = NULL; 2130 } 2131 2132 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket); 2133 if (!txq) 2134 return -ENOMEM; 2135 2136 txq->priv = priv; 2137 txq->queue_id = idx; 2138 txq->port_id = dev->data->port_id; 2139 txq->tx_deferred_start = conf->tx_deferred_start; 2140 dev->data->tx_queues[idx] = txq; 2141 2142 priv->ppio_params.outqs_params.outqs_params[idx].size = desc; 2143 2144 return 0; 2145 } 2146 2147 /** 2148 * DPDK callback to release the transmit queue. 2149 * 2150 * @param dev 2151 * Pointer to Ethernet device structure. 2152 * @param qid 2153 * Transmit queue index. 2154 */ 2155 static void 2156 mrvl_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid) 2157 { 2158 struct mrvl_txq *q = dev->data->tx_queues[qid]; 2159 2160 if (!q) 2161 return; 2162 2163 rte_free(q); 2164 } 2165 2166 /** 2167 * DPDK callback to get flow control configuration. 2168 * 2169 * @param dev 2170 * Pointer to Ethernet device structure. 2171 * @param fc_conf 2172 * Pointer to the flow control configuration. 2173 * 2174 * @return 2175 * 0 on success, negative error value otherwise. 2176 */ 2177 static int 2178 mrvl_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) 2179 { 2180 struct mrvl_priv *priv = dev->data->dev_private; 2181 int ret, en; 2182 2183 if (!priv->ppio) { 2184 memcpy(fc_conf, &priv->fc_conf, sizeof(struct rte_eth_fc_conf)); 2185 return 0; 2186 } 2187 2188 fc_conf->autoneg = 1; 2189 ret = pp2_ppio_get_rx_pause(priv->ppio, &en); 2190 if (ret) { 2191 MRVL_LOG(ERR, "Failed to read rx pause state"); 2192 return ret; 2193 } 2194 2195 fc_conf->mode = en ? RTE_ETH_FC_RX_PAUSE : RTE_ETH_FC_NONE; 2196 2197 ret = pp2_ppio_get_tx_pause(priv->ppio, &en); 2198 if (ret) { 2199 MRVL_LOG(ERR, "Failed to read tx pause state"); 2200 return ret; 2201 } 2202 2203 if (en) { 2204 if (fc_conf->mode == RTE_ETH_FC_NONE) 2205 fc_conf->mode = RTE_ETH_FC_TX_PAUSE; 2206 else 2207 fc_conf->mode = RTE_ETH_FC_FULL; 2208 } 2209 2210 return 0; 2211 } 2212 2213 /** 2214 * DPDK callback to set flow control configuration. 2215 * 2216 * @param dev 2217 * Pointer to Ethernet device structure. 2218 * @param fc_conf 2219 * Pointer to the flow control configuration. 2220 * 2221 * @return 2222 * 0 on success, negative error value otherwise. 2223 */ 2224 static int 2225 mrvl_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) 2226 { 2227 struct mrvl_priv *priv = dev->data->dev_private; 2228 struct pp2_ppio_tx_pause_params mrvl_pause_params; 2229 int ret; 2230 int rx_en, tx_en; 2231 2232 if (fc_conf->high_water || 2233 fc_conf->low_water || 2234 fc_conf->pause_time || 2235 fc_conf->mac_ctrl_frame_fwd) { 2236 MRVL_LOG(ERR, "Flowctrl parameter is not supported"); 2237 2238 return -EINVAL; 2239 } 2240 2241 if (fc_conf->autoneg == 0) { 2242 MRVL_LOG(ERR, "Flowctrl Autoneg disable is not supported"); 2243 return -EINVAL; 2244 } 2245 2246 if (!priv->ppio) { 2247 memcpy(&priv->fc_conf, fc_conf, sizeof(struct rte_eth_fc_conf)); 2248 priv->flow_ctrl = 1; 2249 return 0; 2250 } 2251 2252 switch (fc_conf->mode) { 2253 case RTE_ETH_FC_FULL: 2254 rx_en = 1; 2255 tx_en = 1; 2256 break; 2257 case RTE_ETH_FC_TX_PAUSE: 2258 rx_en = 0; 2259 tx_en = 1; 2260 break; 2261 case RTE_ETH_FC_RX_PAUSE: 2262 rx_en = 1; 2263 tx_en = 0; 2264 break; 2265 case RTE_ETH_FC_NONE: 2266 rx_en = 0; 2267 tx_en = 0; 2268 break; 2269 default: 2270 MRVL_LOG(ERR, "Incorrect Flow control flag (%d)", 2271 fc_conf->mode); 2272 return -EINVAL; 2273 } 2274 2275 /* Set RX flow control */ 2276 ret = pp2_ppio_set_rx_pause(priv->ppio, rx_en); 2277 if (ret) { 2278 MRVL_LOG(ERR, "Failed to change RX flowctrl"); 2279 return ret; 2280 } 2281 2282 /* Set TX flow control */ 2283 mrvl_pause_params.en = tx_en; 2284 /* all inqs participate in xon/xoff decision */ 2285 mrvl_pause_params.use_tc_pause_inqs = 0; 2286 ret = pp2_ppio_set_tx_pause(priv->ppio, &mrvl_pause_params); 2287 if (ret) { 2288 MRVL_LOG(ERR, "Failed to change TX flowctrl"); 2289 return ret; 2290 } 2291 2292 return 0; 2293 } 2294 2295 /** 2296 * Update RSS hash configuration 2297 * 2298 * @param dev 2299 * Pointer to Ethernet device structure. 2300 * @param rss_conf 2301 * Pointer to RSS configuration. 2302 * 2303 * @return 2304 * 0 on success, negative error value otherwise. 2305 */ 2306 static int 2307 mrvl_rss_hash_update(struct rte_eth_dev *dev, 2308 struct rte_eth_rss_conf *rss_conf) 2309 { 2310 struct mrvl_priv *priv = dev->data->dev_private; 2311 2312 if (priv->isolated) 2313 return -ENOTSUP; 2314 2315 return mrvl_configure_rss(priv, rss_conf); 2316 } 2317 2318 /** 2319 * DPDK callback to get RSS hash configuration. 2320 * 2321 * @param dev 2322 * Pointer to Ethernet device structure. 2323 * @rss_conf 2324 * Pointer to RSS configuration. 2325 * 2326 * @return 2327 * Always 0. 2328 */ 2329 static int 2330 mrvl_rss_hash_conf_get(struct rte_eth_dev *dev, 2331 struct rte_eth_rss_conf *rss_conf) 2332 { 2333 struct mrvl_priv *priv = dev->data->dev_private; 2334 enum pp2_ppio_hash_type hash_type = 2335 priv->ppio_params.inqs_params.hash_type; 2336 2337 rss_conf->rss_key = NULL; 2338 2339 if (hash_type == PP2_PPIO_HASH_T_NONE) 2340 rss_conf->rss_hf = 0; 2341 else if (hash_type == PP2_PPIO_HASH_T_2_TUPLE) 2342 rss_conf->rss_hf = RTE_ETH_RSS_IPV4; 2343 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && priv->rss_hf_tcp) 2344 rss_conf->rss_hf = RTE_ETH_RSS_NONFRAG_IPV4_TCP; 2345 else if (hash_type == PP2_PPIO_HASH_T_5_TUPLE && !priv->rss_hf_tcp) 2346 rss_conf->rss_hf = RTE_ETH_RSS_NONFRAG_IPV4_UDP; 2347 2348 return 0; 2349 } 2350 2351 /** 2352 * DPDK callback to get rte_flow callbacks. 2353 * 2354 * @param dev 2355 * Pointer to the device structure. 2356 * @param ops 2357 * Pointer to pass the flow ops. 2358 * 2359 * @return 2360 * 0 on success, negative error value otherwise. 2361 */ 2362 static int 2363 mrvl_eth_flow_ops_get(struct rte_eth_dev *dev __rte_unused, 2364 const struct rte_flow_ops **ops) 2365 { 2366 *ops = &mrvl_flow_ops; 2367 return 0; 2368 } 2369 2370 /** 2371 * DPDK callback to get rte_mtr callbacks. 2372 * 2373 * @param dev 2374 * Pointer to the device structure. 2375 * @param ops 2376 * Pointer to pass the mtr ops. 2377 * 2378 * @return 2379 * Always 0. 2380 */ 2381 static int 2382 mrvl_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops) 2383 { 2384 *(const void **)ops = &mrvl_mtr_ops; 2385 2386 return 0; 2387 } 2388 2389 /** 2390 * DPDK callback to get rte_tm callbacks. 2391 * 2392 * @param dev 2393 * Pointer to the device structure. 2394 * @param ops 2395 * Pointer to pass the tm ops. 2396 * 2397 * @return 2398 * Always 0. 2399 */ 2400 static int 2401 mrvl_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops) 2402 { 2403 *(const void **)ops = &mrvl_tm_ops; 2404 2405 return 0; 2406 } 2407 2408 static const struct eth_dev_ops mrvl_ops = { 2409 .dev_configure = mrvl_dev_configure, 2410 .dev_start = mrvl_dev_start, 2411 .dev_stop = mrvl_dev_stop, 2412 .dev_set_link_up = mrvl_dev_set_link_up, 2413 .dev_set_link_down = mrvl_dev_set_link_down, 2414 .dev_close = mrvl_dev_close, 2415 .link_update = mrvl_link_update, 2416 .promiscuous_enable = mrvl_promiscuous_enable, 2417 .allmulticast_enable = mrvl_allmulticast_enable, 2418 .promiscuous_disable = mrvl_promiscuous_disable, 2419 .allmulticast_disable = mrvl_allmulticast_disable, 2420 .mac_addr_remove = mrvl_mac_addr_remove, 2421 .mac_addr_add = mrvl_mac_addr_add, 2422 .mac_addr_set = mrvl_mac_addr_set, 2423 .mtu_set = mrvl_mtu_set, 2424 .stats_get = mrvl_stats_get, 2425 .stats_reset = mrvl_stats_reset, 2426 .xstats_get = mrvl_xstats_get, 2427 .xstats_reset = mrvl_xstats_reset, 2428 .xstats_get_names = mrvl_xstats_get_names, 2429 .dev_infos_get = mrvl_dev_infos_get, 2430 .dev_supported_ptypes_get = mrvl_dev_supported_ptypes_get, 2431 .rxq_info_get = mrvl_rxq_info_get, 2432 .txq_info_get = mrvl_txq_info_get, 2433 .vlan_filter_set = mrvl_vlan_filter_set, 2434 .vlan_offload_set = mrvl_vlan_offload_set, 2435 .tx_queue_start = mrvl_tx_queue_start, 2436 .tx_queue_stop = mrvl_tx_queue_stop, 2437 .rx_queue_setup = mrvl_rx_queue_setup, 2438 .rx_queue_release = mrvl_rx_queue_release, 2439 .tx_queue_setup = mrvl_tx_queue_setup, 2440 .tx_queue_release = mrvl_tx_queue_release, 2441 .flow_ctrl_get = mrvl_flow_ctrl_get, 2442 .flow_ctrl_set = mrvl_flow_ctrl_set, 2443 .rss_hash_update = mrvl_rss_hash_update, 2444 .rss_hash_conf_get = mrvl_rss_hash_conf_get, 2445 .flow_ops_get = mrvl_eth_flow_ops_get, 2446 .mtr_ops_get = mrvl_mtr_ops_get, 2447 .tm_ops_get = mrvl_tm_ops_get, 2448 }; 2449 2450 /** 2451 * Return packet type information and l3/l4 offsets. 2452 * 2453 * @param desc 2454 * Pointer to the received packet descriptor. 2455 * @param l3_offset 2456 * l3 packet offset. 2457 * @param l4_offset 2458 * l4 packet offset. 2459 * 2460 * @return 2461 * Packet type information. 2462 */ 2463 static inline uint64_t 2464 mrvl_desc_to_packet_type_and_offset(struct pp2_ppio_desc *desc, 2465 uint8_t *l3_offset, uint8_t *l4_offset) 2466 { 2467 enum pp2_inq_l3_type l3_type; 2468 enum pp2_inq_l4_type l4_type; 2469 enum pp2_inq_vlan_tag vlan_tag; 2470 uint64_t packet_type; 2471 2472 pp2_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset); 2473 pp2_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset); 2474 pp2_ppio_inq_desc_get_vlan_tag(desc, &vlan_tag); 2475 2476 packet_type = RTE_PTYPE_L2_ETHER; 2477 2478 switch (vlan_tag) { 2479 case PP2_INQ_VLAN_TAG_SINGLE: 2480 packet_type |= RTE_PTYPE_L2_ETHER_VLAN; 2481 break; 2482 case PP2_INQ_VLAN_TAG_DOUBLE: 2483 case PP2_INQ_VLAN_TAG_TRIPLE: 2484 packet_type |= RTE_PTYPE_L2_ETHER_QINQ; 2485 break; 2486 default: 2487 break; 2488 } 2489 2490 switch (l3_type) { 2491 case PP2_INQ_L3_TYPE_IPV4_NO_OPTS: 2492 packet_type |= RTE_PTYPE_L3_IPV4; 2493 break; 2494 case PP2_INQ_L3_TYPE_IPV4_OK: 2495 packet_type |= RTE_PTYPE_L3_IPV4_EXT; 2496 break; 2497 case PP2_INQ_L3_TYPE_IPV4_TTL_ZERO: 2498 packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN; 2499 break; 2500 case PP2_INQ_L3_TYPE_IPV6_NO_EXT: 2501 packet_type |= RTE_PTYPE_L3_IPV6; 2502 break; 2503 case PP2_INQ_L3_TYPE_IPV6_EXT: 2504 packet_type |= RTE_PTYPE_L3_IPV6_EXT; 2505 break; 2506 case PP2_INQ_L3_TYPE_ARP: 2507 packet_type |= RTE_PTYPE_L2_ETHER_ARP; 2508 /* 2509 * In case of ARP l4_offset is set to wrong value. 2510 * Set it to proper one so that later on mbuf->l3_len can be 2511 * calculated subtracting l4_offset and l3_offset. 2512 */ 2513 *l4_offset = *l3_offset + MRVL_ARP_LENGTH; 2514 break; 2515 default: 2516 break; 2517 } 2518 2519 switch (l4_type) { 2520 case PP2_INQ_L4_TYPE_TCP: 2521 packet_type |= RTE_PTYPE_L4_TCP; 2522 break; 2523 case PP2_INQ_L4_TYPE_UDP: 2524 packet_type |= RTE_PTYPE_L4_UDP; 2525 break; 2526 default: 2527 break; 2528 } 2529 2530 return packet_type; 2531 } 2532 2533 /** 2534 * Get offload information from the received packet descriptor. 2535 * 2536 * @param desc 2537 * Pointer to the received packet descriptor. 2538 * 2539 * @return 2540 * Mbuf offload flags. 2541 */ 2542 static inline uint64_t 2543 mrvl_desc_to_ol_flags(struct pp2_ppio_desc *desc, uint64_t packet_type) 2544 { 2545 uint64_t flags = 0; 2546 enum pp2_inq_desc_status status; 2547 2548 if (RTE_ETH_IS_IPV4_HDR(packet_type)) { 2549 status = pp2_ppio_inq_desc_get_l3_pkt_error(desc); 2550 if (unlikely(status != PP2_DESC_ERR_OK)) 2551 flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD; 2552 else 2553 flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD; 2554 } 2555 2556 if (((packet_type & RTE_PTYPE_L4_UDP) == RTE_PTYPE_L4_UDP) || 2557 ((packet_type & RTE_PTYPE_L4_TCP) == RTE_PTYPE_L4_TCP)) { 2558 status = pp2_ppio_inq_desc_get_l4_pkt_error(desc); 2559 if (unlikely(status != PP2_DESC_ERR_OK)) 2560 flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD; 2561 else 2562 flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD; 2563 } 2564 2565 return flags; 2566 } 2567 2568 /** 2569 * DPDK callback for receive. 2570 * 2571 * @param rxq 2572 * Generic pointer to the receive queue. 2573 * @param rx_pkts 2574 * Array to store received packets. 2575 * @param nb_pkts 2576 * Maximum number of packets in array. 2577 * 2578 * @return 2579 * Number of packets successfully received. 2580 */ 2581 static uint16_t 2582 mrvl_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) 2583 { 2584 struct mrvl_rxq *q = rxq; 2585 struct pp2_ppio_desc descs[nb_pkts]; 2586 struct pp2_bpool *bpool; 2587 int i, ret, rx_done = 0; 2588 int num; 2589 struct pp2_hif *hif; 2590 unsigned int core_id = rte_lcore_id(); 2591 2592 hif = mrvl_get_hif(q->priv, core_id); 2593 2594 if (unlikely(!q->priv->ppio || !hif)) 2595 return 0; 2596 2597 bpool = q->priv->bpool; 2598 2599 ret = pp2_ppio_recv(q->priv->ppio, q->priv->rxq_map[q->queue_id].tc, 2600 q->priv->rxq_map[q->queue_id].inq, descs, &nb_pkts); 2601 if (unlikely(ret < 0)) 2602 return 0; 2603 2604 mrvl_port_bpool_size[bpool->pp2_id][bpool->id][core_id] -= nb_pkts; 2605 2606 for (i = 0; i < nb_pkts; i++) { 2607 struct rte_mbuf *mbuf; 2608 uint8_t l3_offset, l4_offset; 2609 enum pp2_inq_desc_status status; 2610 uint64_t addr; 2611 2612 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) { 2613 struct pp2_ppio_desc *pref_desc; 2614 u64 pref_addr; 2615 2616 pref_desc = &descs[i + MRVL_MUSDK_PREFETCH_SHIFT]; 2617 pref_addr = cookie_addr_high | 2618 pp2_ppio_inq_desc_get_cookie(pref_desc); 2619 rte_mbuf_prefetch_part1((struct rte_mbuf *)(pref_addr)); 2620 rte_mbuf_prefetch_part2((struct rte_mbuf *)(pref_addr)); 2621 } 2622 2623 addr = cookie_addr_high | 2624 pp2_ppio_inq_desc_get_cookie(&descs[i]); 2625 mbuf = (struct rte_mbuf *)addr; 2626 rte_pktmbuf_reset(mbuf); 2627 2628 /* drop packet in case of mac, overrun or resource error */ 2629 status = pp2_ppio_inq_desc_get_l2_pkt_error(&descs[i]); 2630 if ((unlikely(status != PP2_DESC_ERR_OK)) && 2631 !(q->priv->forward_bad_frames)) { 2632 struct pp2_buff_inf binf = { 2633 .addr = rte_mbuf_data_iova_default(mbuf), 2634 .cookie = (uint64_t)mbuf, 2635 }; 2636 2637 pp2_bpool_put_buff(hif, bpool, &binf); 2638 mrvl_port_bpool_size 2639 [bpool->pp2_id][bpool->id][core_id]++; 2640 q->drop_mac++; 2641 continue; 2642 } 2643 2644 mbuf->data_off += MRVL_PKT_EFFEC_OFFS; 2645 mbuf->pkt_len = pp2_ppio_inq_desc_get_pkt_len(&descs[i]); 2646 mbuf->data_len = mbuf->pkt_len; 2647 mbuf->port = q->port_id; 2648 mbuf->packet_type = 2649 mrvl_desc_to_packet_type_and_offset(&descs[i], 2650 &l3_offset, 2651 &l4_offset); 2652 mbuf->l2_len = l3_offset; 2653 mbuf->l3_len = l4_offset - l3_offset; 2654 2655 if (likely(q->cksum_enabled)) 2656 mbuf->ol_flags = 2657 mrvl_desc_to_ol_flags(&descs[i], 2658 mbuf->packet_type); 2659 2660 rx_pkts[rx_done++] = mbuf; 2661 q->bytes_recv += mbuf->pkt_len; 2662 } 2663 2664 if (rte_spinlock_trylock(&q->priv->lock) == 1) { 2665 num = mrvl_get_bpool_size(bpool->pp2_id, bpool->id); 2666 2667 if (unlikely(num <= q->priv->bpool_min_size || 2668 (!rx_done && num < q->priv->bpool_init_size))) { 2669 mrvl_fill_bpool(q, q->priv->fill_bpool_buffs); 2670 } else if (unlikely(num > q->priv->bpool_max_size)) { 2671 int i; 2672 int pkt_to_remove = num - q->priv->bpool_init_size; 2673 struct rte_mbuf *mbuf; 2674 struct pp2_buff_inf buff; 2675 2676 for (i = 0; i < pkt_to_remove; i++) { 2677 ret = pp2_bpool_get_buff(hif, bpool, &buff); 2678 if (ret) 2679 break; 2680 mbuf = (struct rte_mbuf *) 2681 (cookie_addr_high | buff.cookie); 2682 rte_pktmbuf_free(mbuf); 2683 } 2684 mrvl_port_bpool_size 2685 [bpool->pp2_id][bpool->id][core_id] -= i; 2686 } 2687 rte_spinlock_unlock(&q->priv->lock); 2688 } 2689 2690 return rx_done; 2691 } 2692 2693 /** 2694 * Prepare offload information. 2695 * 2696 * @param ol_flags 2697 * Offload flags. 2698 * @param l3_type 2699 * Pointer to the pp2_ouq_l3_type structure. 2700 * @param l4_type 2701 * Pointer to the pp2_outq_l4_type structure. 2702 * @param gen_l3_cksum 2703 * Will be set to 1 in case l3 checksum is computed. 2704 * @param l4_cksum 2705 * Will be set to 1 in case l4 checksum is computed. 2706 */ 2707 static inline void 2708 mrvl_prepare_proto_info(uint64_t ol_flags, 2709 enum pp2_outq_l3_type *l3_type, 2710 enum pp2_outq_l4_type *l4_type, 2711 int *gen_l3_cksum, 2712 int *gen_l4_cksum) 2713 { 2714 /* 2715 * Based on ol_flags prepare information 2716 * for pp2_ppio_outq_desc_set_proto_info() which setups descriptor 2717 * for offloading. 2718 * in most of the checksum cases ipv4 must be set, so this is the 2719 * default value 2720 */ 2721 *l3_type = PP2_OUTQ_L3_TYPE_IPV4; 2722 *gen_l3_cksum = ol_flags & RTE_MBUF_F_TX_IP_CKSUM ? 1 : 0; 2723 2724 if (ol_flags & RTE_MBUF_F_TX_IPV6) { 2725 *l3_type = PP2_OUTQ_L3_TYPE_IPV6; 2726 /* no checksum for ipv6 header */ 2727 *gen_l3_cksum = 0; 2728 } 2729 2730 if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_TCP_CKSUM) { 2731 *l4_type = PP2_OUTQ_L4_TYPE_TCP; 2732 *gen_l4_cksum = 1; 2733 } else if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_UDP_CKSUM) { 2734 *l4_type = PP2_OUTQ_L4_TYPE_UDP; 2735 *gen_l4_cksum = 1; 2736 } else { 2737 *l4_type = PP2_OUTQ_L4_TYPE_OTHER; 2738 /* no checksum for other type */ 2739 *gen_l4_cksum = 0; 2740 } 2741 } 2742 2743 /** 2744 * Release already sent buffers to bpool (buffer-pool). 2745 * 2746 * @param ppio 2747 * Pointer to the port structure. 2748 * @param hif 2749 * Pointer to the MUSDK hardware interface. 2750 * @param sq 2751 * Pointer to the shadow queue. 2752 * @param qid 2753 * Queue id number. 2754 * @param force 2755 * Force releasing packets. 2756 */ 2757 static inline void 2758 mrvl_free_sent_buffers(struct pp2_ppio *ppio, struct pp2_hif *hif, 2759 unsigned int core_id, struct mrvl_shadow_txq *sq, 2760 int qid, int force) 2761 { 2762 struct buff_release_entry *entry; 2763 uint16_t nb_done = 0, num = 0, skip_bufs = 0; 2764 int i; 2765 2766 pp2_ppio_get_num_outq_done(ppio, hif, qid, &nb_done); 2767 2768 sq->num_to_release += nb_done; 2769 2770 if (likely(!force && 2771 sq->num_to_release < MRVL_PP2_BUF_RELEASE_BURST_SIZE)) 2772 return; 2773 2774 nb_done = sq->num_to_release; 2775 sq->num_to_release = 0; 2776 2777 for (i = 0; i < nb_done; i++) { 2778 entry = &sq->ent[sq->tail + num]; 2779 if (unlikely(!entry->buff.addr)) { 2780 MRVL_LOG(ERR, 2781 "Shadow memory @%d: cookie(%lx), pa(%lx)!", 2782 sq->tail, (u64)entry->buff.cookie, 2783 (u64)entry->buff.addr); 2784 skip_bufs = 1; 2785 goto skip; 2786 } 2787 2788 if (unlikely(!entry->bpool)) { 2789 struct rte_mbuf *mbuf; 2790 2791 mbuf = (struct rte_mbuf *)entry->buff.cookie; 2792 rte_pktmbuf_free(mbuf); 2793 skip_bufs = 1; 2794 goto skip; 2795 } 2796 2797 mrvl_port_bpool_size 2798 [entry->bpool->pp2_id][entry->bpool->id][core_id]++; 2799 num++; 2800 if (unlikely(sq->tail + num == MRVL_PP2_TX_SHADOWQ_SIZE)) 2801 goto skip; 2802 continue; 2803 skip: 2804 if (likely(num)) 2805 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num); 2806 num += skip_bufs; 2807 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK; 2808 sq->size -= num; 2809 num = 0; 2810 skip_bufs = 0; 2811 } 2812 2813 if (likely(num)) { 2814 pp2_bpool_put_buffs(hif, &sq->ent[sq->tail], &num); 2815 sq->tail = (sq->tail + num) & MRVL_PP2_TX_SHADOWQ_MASK; 2816 sq->size -= num; 2817 } 2818 } 2819 2820 /** 2821 * DPDK callback for transmit. 2822 * 2823 * @param txq 2824 * Generic pointer transmit queue. 2825 * @param tx_pkts 2826 * Packets to transmit. 2827 * @param nb_pkts 2828 * Number of packets in array. 2829 * 2830 * @return 2831 * Number of packets successfully transmitted. 2832 */ 2833 static uint16_t 2834 mrvl_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) 2835 { 2836 struct mrvl_txq *q = txq; 2837 struct mrvl_shadow_txq *sq; 2838 struct pp2_hif *hif; 2839 struct pp2_ppio_desc descs[nb_pkts]; 2840 unsigned int core_id = rte_lcore_id(); 2841 int i, bytes_sent = 0; 2842 uint16_t num, sq_free_size; 2843 uint64_t addr; 2844 2845 hif = mrvl_get_hif(q->priv, core_id); 2846 sq = &q->shadow_txqs[core_id]; 2847 2848 if (unlikely(!q->priv->ppio || !hif)) 2849 return 0; 2850 2851 if (sq->size) 2852 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id, 2853 sq, q->queue_id, 0); 2854 2855 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1; 2856 if (unlikely(nb_pkts > sq_free_size)) 2857 nb_pkts = sq_free_size; 2858 2859 for (i = 0; i < nb_pkts; i++) { 2860 struct rte_mbuf *mbuf = tx_pkts[i]; 2861 int gen_l3_cksum, gen_l4_cksum; 2862 enum pp2_outq_l3_type l3_type; 2863 enum pp2_outq_l4_type l4_type; 2864 2865 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) { 2866 struct rte_mbuf *pref_pkt_hdr; 2867 2868 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT]; 2869 rte_mbuf_prefetch_part1(pref_pkt_hdr); 2870 rte_mbuf_prefetch_part2(pref_pkt_hdr); 2871 } 2872 2873 mrvl_fill_shadowq(sq, mbuf); 2874 mrvl_fill_desc(&descs[i], mbuf); 2875 2876 bytes_sent += rte_pktmbuf_pkt_len(mbuf); 2877 /* 2878 * in case unsupported ol_flags were passed 2879 * do not update descriptor offload information 2880 */ 2881 if (!(mbuf->ol_flags & MRVL_TX_PKT_OFFLOADS)) 2882 continue; 2883 mrvl_prepare_proto_info(mbuf->ol_flags, &l3_type, &l4_type, 2884 &gen_l3_cksum, &gen_l4_cksum); 2885 2886 pp2_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type, 2887 mbuf->l2_len, 2888 mbuf->l2_len + mbuf->l3_len, 2889 gen_l3_cksum, gen_l4_cksum); 2890 } 2891 2892 num = nb_pkts; 2893 pp2_ppio_send(q->priv->ppio, hif, q->queue_id, descs, &nb_pkts); 2894 /* number of packets that were not sent */ 2895 if (unlikely(num > nb_pkts)) { 2896 for (i = nb_pkts; i < num; i++) { 2897 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) & 2898 MRVL_PP2_TX_SHADOWQ_MASK; 2899 addr = sq->ent[sq->head].buff.cookie; 2900 bytes_sent -= 2901 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr); 2902 } 2903 sq->size -= num - nb_pkts; 2904 } 2905 2906 q->bytes_sent += bytes_sent; 2907 2908 return nb_pkts; 2909 } 2910 2911 /** DPDK callback for S/G transmit. 2912 * 2913 * @param txq 2914 * Generic pointer transmit queue. 2915 * @param tx_pkts 2916 * Packets to transmit. 2917 * @param nb_pkts 2918 * Number of packets in array. 2919 * 2920 * @return 2921 * Number of packets successfully transmitted. 2922 */ 2923 static uint16_t 2924 mrvl_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, 2925 uint16_t nb_pkts) 2926 { 2927 struct mrvl_txq *q = txq; 2928 struct mrvl_shadow_txq *sq; 2929 struct pp2_hif *hif; 2930 struct pp2_ppio_desc descs[nb_pkts * PP2_PPIO_DESC_NUM_FRAGS]; 2931 struct pp2_ppio_sg_pkts pkts; 2932 uint8_t frags[nb_pkts]; 2933 unsigned int core_id = rte_lcore_id(); 2934 int i, j, bytes_sent = 0; 2935 int tail, tail_first; 2936 uint16_t num, sq_free_size; 2937 uint16_t nb_segs, total_descs = 0; 2938 uint64_t addr; 2939 2940 hif = mrvl_get_hif(q->priv, core_id); 2941 sq = &q->shadow_txqs[core_id]; 2942 pkts.frags = frags; 2943 pkts.num = 0; 2944 2945 if (unlikely(!q->priv->ppio || !hif)) 2946 return 0; 2947 2948 if (sq->size) 2949 mrvl_free_sent_buffers(q->priv->ppio, hif, core_id, 2950 sq, q->queue_id, 0); 2951 2952 /* Save shadow queue free size */ 2953 sq_free_size = MRVL_PP2_TX_SHADOWQ_SIZE - sq->size - 1; 2954 2955 tail = 0; 2956 for (i = 0; i < nb_pkts; i++) { 2957 struct rte_mbuf *mbuf = tx_pkts[i]; 2958 struct rte_mbuf *seg = NULL; 2959 int gen_l3_cksum, gen_l4_cksum; 2960 enum pp2_outq_l3_type l3_type; 2961 enum pp2_outq_l4_type l4_type; 2962 2963 nb_segs = mbuf->nb_segs; 2964 tail_first = tail; 2965 total_descs += nb_segs; 2966 2967 /* 2968 * Check if total_descs does not exceed 2969 * shadow queue free size 2970 */ 2971 if (unlikely(total_descs > sq_free_size)) { 2972 total_descs -= nb_segs; 2973 break; 2974 } 2975 2976 /* Check if nb_segs does not exceed the max nb of desc per 2977 * fragmented packet 2978 */ 2979 if (nb_segs > PP2_PPIO_DESC_NUM_FRAGS) { 2980 total_descs -= nb_segs; 2981 MRVL_LOG(ERR, "Too many segments. Packet won't be sent."); 2982 break; 2983 } 2984 2985 if (likely(nb_pkts - i > MRVL_MUSDK_PREFETCH_SHIFT)) { 2986 struct rte_mbuf *pref_pkt_hdr; 2987 2988 pref_pkt_hdr = tx_pkts[i + MRVL_MUSDK_PREFETCH_SHIFT]; 2989 rte_mbuf_prefetch_part1(pref_pkt_hdr); 2990 rte_mbuf_prefetch_part2(pref_pkt_hdr); 2991 } 2992 2993 pkts.frags[pkts.num] = nb_segs; 2994 pkts.num++; 2995 2996 seg = mbuf; 2997 for (j = 0; j < nb_segs - 1; j++) { 2998 /* For the subsequent segments, set shadow queue 2999 * buffer to NULL 3000 */ 3001 mrvl_fill_shadowq(sq, NULL); 3002 mrvl_fill_desc(&descs[tail], seg); 3003 3004 tail++; 3005 seg = seg->next; 3006 } 3007 /* Put first mbuf info in last shadow queue entry */ 3008 mrvl_fill_shadowq(sq, mbuf); 3009 /* Update descriptor with last segment */ 3010 mrvl_fill_desc(&descs[tail++], seg); 3011 3012 bytes_sent += rte_pktmbuf_pkt_len(mbuf); 3013 /* In case unsupported ol_flags were passed 3014 * do not update descriptor offload information 3015 */ 3016 if (!(mbuf->ol_flags & MRVL_TX_PKT_OFFLOADS)) 3017 continue; 3018 mrvl_prepare_proto_info(mbuf->ol_flags, &l3_type, &l4_type, 3019 &gen_l3_cksum, &gen_l4_cksum); 3020 3021 pp2_ppio_outq_desc_set_proto_info(&descs[tail_first], l3_type, 3022 l4_type, mbuf->l2_len, 3023 mbuf->l2_len + mbuf->l3_len, 3024 gen_l3_cksum, gen_l4_cksum); 3025 } 3026 3027 num = total_descs; 3028 pp2_ppio_send_sg(q->priv->ppio, hif, q->queue_id, descs, 3029 &total_descs, &pkts); 3030 /* number of packets that were not sent */ 3031 if (unlikely(num > total_descs)) { 3032 for (i = total_descs; i < num; i++) { 3033 sq->head = (MRVL_PP2_TX_SHADOWQ_SIZE + sq->head - 1) & 3034 MRVL_PP2_TX_SHADOWQ_MASK; 3035 3036 addr = sq->ent[sq->head].buff.cookie; 3037 if (addr) 3038 bytes_sent -= 3039 rte_pktmbuf_pkt_len((struct rte_mbuf *) 3040 (cookie_addr_high | addr)); 3041 } 3042 sq->size -= num - total_descs; 3043 nb_pkts = pkts.num; 3044 } 3045 3046 q->bytes_sent += bytes_sent; 3047 3048 return nb_pkts; 3049 } 3050 3051 /** 3052 * Create private device structure. 3053 * 3054 * @param dev_name 3055 * Pointer to the port name passed in the initialization parameters. 3056 * 3057 * @return 3058 * Pointer to the newly allocated private device structure. 3059 */ 3060 static struct mrvl_priv * 3061 mrvl_priv_create(const char *dev_name) 3062 { 3063 struct pp2_bpool_params bpool_params; 3064 char match[MRVL_MATCH_LEN]; 3065 struct mrvl_priv *priv; 3066 uint16_t max_frame_size; 3067 int ret, bpool_bit; 3068 3069 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id()); 3070 if (!priv) 3071 return NULL; 3072 3073 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name, 3074 &priv->pp_id, &priv->ppio_id); 3075 if (ret) 3076 goto out_free_priv; 3077 3078 ret = pp2_ppio_get_l4_cksum_max_frame_size(priv->pp_id, priv->ppio_id, 3079 &max_frame_size); 3080 if (ret) 3081 goto out_free_priv; 3082 3083 priv->max_mtu = max_frame_size + RTE_ETHER_CRC_LEN - 3084 MRVL_PP2_ETH_HDRS_LEN; 3085 3086 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id], 3087 PP2_BPOOL_NUM_POOLS); 3088 if (bpool_bit < 0) 3089 goto out_free_priv; 3090 priv->bpool_bit = bpool_bit; 3091 3092 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id, 3093 priv->bpool_bit); 3094 memset(&bpool_params, 0, sizeof(bpool_params)); 3095 bpool_params.match = match; 3096 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS; 3097 ret = pp2_bpool_init(&bpool_params, &priv->bpool); 3098 if (ret) 3099 goto out_clear_bpool_bit; 3100 3101 priv->ppio_params.type = PP2_PPIO_T_NIC; 3102 rte_spinlock_init(&priv->lock); 3103 3104 return priv; 3105 out_clear_bpool_bit: 3106 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit); 3107 out_free_priv: 3108 rte_free(priv); 3109 return NULL; 3110 } 3111 3112 /** 3113 * Create device representing Ethernet port. 3114 * 3115 * @param name 3116 * Pointer to the port's name. 3117 * 3118 * @return 3119 * 0 on success, negative error value otherwise. 3120 */ 3121 static int 3122 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name) 3123 { 3124 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0); 3125 struct rte_eth_dev *eth_dev; 3126 struct mrvl_priv *priv; 3127 struct ifreq req; 3128 3129 eth_dev = rte_eth_dev_allocate(name); 3130 if (!eth_dev) 3131 return -ENOMEM; 3132 3133 priv = mrvl_priv_create(name); 3134 if (!priv) { 3135 ret = -ENOMEM; 3136 goto out_free; 3137 } 3138 eth_dev->data->dev_private = priv; 3139 3140 eth_dev->data->mac_addrs = 3141 rte_zmalloc("mac_addrs", 3142 RTE_ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0); 3143 if (!eth_dev->data->mac_addrs) { 3144 MRVL_LOG(ERR, "Failed to allocate space for eth addrs"); 3145 ret = -ENOMEM; 3146 goto out_free; 3147 } 3148 3149 memset(&req, 0, sizeof(req)); 3150 strcpy(req.ifr_name, name); 3151 ret = ioctl(fd, SIOCGIFHWADDR, &req); 3152 if (ret) 3153 goto out_free; 3154 3155 memcpy(eth_dev->data->mac_addrs[0].addr_bytes, 3156 req.ifr_addr.sa_data, RTE_ETHER_ADDR_LEN); 3157 3158 eth_dev->device = &vdev->device; 3159 eth_dev->rx_pkt_burst = mrvl_rx_pkt_burst; 3160 mrvl_set_tx_function(eth_dev); 3161 eth_dev->dev_ops = &mrvl_ops; 3162 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; 3163 3164 eth_dev->data->dev_link.link_status = RTE_ETH_LINK_UP; 3165 3166 rte_eth_dev_probing_finish(eth_dev); 3167 return 0; 3168 out_free: 3169 rte_eth_dev_release_port(eth_dev); 3170 3171 return ret; 3172 } 3173 3174 /** 3175 * Callback used by rte_kvargs_process() during argument parsing. 3176 * 3177 * @param key 3178 * Pointer to the parsed key (unused). 3179 * @param value 3180 * Pointer to the parsed value. 3181 * @param extra_args 3182 * Pointer to the extra arguments which contains address of the 3183 * table of pointers to parsed interface names. 3184 * 3185 * @return 3186 * Always 0. 3187 */ 3188 static int 3189 mrvl_get_ifnames(const char *key __rte_unused, const char *value, 3190 void *extra_args) 3191 { 3192 struct mrvl_ifnames *ifnames = extra_args; 3193 3194 ifnames->names[ifnames->idx++] = value; 3195 3196 return 0; 3197 } 3198 3199 /** 3200 * DPDK callback to register the virtual device. 3201 * 3202 * @param vdev 3203 * Pointer to the virtual device. 3204 * 3205 * @return 3206 * 0 on success, negative error value otherwise. 3207 */ 3208 static int 3209 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev) 3210 { 3211 struct rte_kvargs *kvlist; 3212 struct mrvl_ifnames ifnames; 3213 int ret = -EINVAL; 3214 uint32_t i, ifnum, cfgnum; 3215 const char *params; 3216 3217 params = rte_vdev_device_args(vdev); 3218 if (!params) 3219 return -EINVAL; 3220 3221 kvlist = rte_kvargs_parse(params, valid_args); 3222 if (!kvlist) 3223 return -EINVAL; 3224 3225 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG); 3226 if (ifnum > RTE_DIM(ifnames.names)) 3227 goto out_free_kvlist; 3228 3229 ifnames.idx = 0; 3230 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG, 3231 mrvl_get_ifnames, &ifnames); 3232 3233 3234 /* 3235 * The below system initialization should be done only once, 3236 * on the first provided configuration file 3237 */ 3238 if (!mrvl_cfg) { 3239 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG); 3240 MRVL_LOG(INFO, "Parsing config file!"); 3241 if (cfgnum > 1) { 3242 MRVL_LOG(ERR, "Cannot handle more than one config file!"); 3243 goto out_free_kvlist; 3244 } else if (cfgnum == 1) { 3245 rte_kvargs_process(kvlist, MRVL_CFG_ARG, 3246 mrvl_get_cfg, &mrvl_cfg); 3247 } 3248 } 3249 3250 if (mrvl_dev_num) 3251 goto init_devices; 3252 3253 MRVL_LOG(INFO, "Perform MUSDK initializations"); 3254 3255 ret = rte_mvep_init(MVEP_MOD_T_PP2, kvlist); 3256 if (ret) 3257 goto out_free_kvlist; 3258 3259 ret = mrvl_init_pp2(); 3260 if (ret) { 3261 MRVL_LOG(ERR, "Failed to init PP!"); 3262 rte_mvep_deinit(MVEP_MOD_T_PP2); 3263 goto out_free_kvlist; 3264 } 3265 3266 memset(mrvl_port_bpool_size, 0, sizeof(mrvl_port_bpool_size)); 3267 memset(mrvl_port_to_bpool_lookup, 0, sizeof(mrvl_port_to_bpool_lookup)); 3268 3269 mrvl_lcore_first = RTE_MAX_LCORE; 3270 mrvl_lcore_last = 0; 3271 3272 init_devices: 3273 for (i = 0; i < ifnum; i++) { 3274 MRVL_LOG(INFO, "Creating %s", ifnames.names[i]); 3275 ret = mrvl_eth_dev_create(vdev, ifnames.names[i]); 3276 if (ret) 3277 goto out_cleanup; 3278 mrvl_dev_num++; 3279 } 3280 3281 rte_kvargs_free(kvlist); 3282 3283 return 0; 3284 out_cleanup: 3285 rte_pmd_mrvl_remove(vdev); 3286 3287 out_free_kvlist: 3288 rte_kvargs_free(kvlist); 3289 3290 return ret; 3291 } 3292 3293 /** 3294 * DPDK callback to remove virtual device. 3295 * 3296 * @param vdev 3297 * Pointer to the removed virtual device. 3298 * 3299 * @return 3300 * 0 on success, negative error value otherwise. 3301 */ 3302 static int 3303 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev) 3304 { 3305 uint16_t port_id; 3306 int ret = 0; 3307 3308 RTE_ETH_FOREACH_DEV(port_id) { 3309 if (rte_eth_devices[port_id].device != &vdev->device) 3310 continue; 3311 ret |= rte_eth_dev_close(port_id); 3312 } 3313 3314 return ret == 0 ? 0 : -EIO; 3315 } 3316 3317 static struct rte_vdev_driver pmd_mrvl_drv = { 3318 .probe = rte_pmd_mrvl_probe, 3319 .remove = rte_pmd_mrvl_remove, 3320 }; 3321 3322 RTE_PMD_REGISTER_VDEV(net_mvpp2, pmd_mrvl_drv); 3323 RTE_PMD_REGISTER_ALIAS(net_mvpp2, eth_mvpp2); 3324 RTE_LOG_REGISTER_DEFAULT(mrvl_logtype, NOTICE); 3325