4 * Copyright(c) 2017 Semihalf. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Semihalf nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_ethdev.h>
34 #include <rte_kvargs.h>
36 #include <rte_malloc.h>
39 /* Unluckily, container_of is defined by both DPDK and MUSDK,
40 * we'll declare only one version.
42 * Note that it is not used in this PMD anyway.
48 #include <drivers/mv_pp2.h>
49 #include <drivers/mv_pp2_bpool.h>
50 #include <drivers/mv_pp2_hif.h>
53 #include <linux/ethtool.h>
54 #include <linux/sockios.h>
56 #include <net/if_arp.h>
57 #include <sys/ioctl.h>
58 #include <sys/socket.h>
60 #include <sys/types.h>
62 #include "mrvl_ethdev.h"
65 /* bitmask with reserved hifs */
66 #define MRVL_MUSDK_HIFS_RESERVED 0x0F
67 /* bitmask with reserved bpools */
68 #define MRVL_MUSDK_BPOOLS_RESERVED 0x07
69 /* maximum number of available hifs */
70 #define MRVL_MUSDK_HIFS_MAX 9
72 #define MRVL_MAC_ADDRS_MAX 1
73 #define MRVL_MATCH_LEN 16
74 #define MRVL_PKT_EFFEC_OFFS (MRVL_PKT_OFFS + MV_MH_SIZE)
75 /* Maximum allowable packet size */
76 #define MRVL_PKT_SIZE_MAX (10240 - MV_MH_SIZE)
78 #define MRVL_IFACE_NAME_ARG "iface"
79 #define MRVL_CFG_ARG "cfg"
81 #define MRVL_BURST_SIZE 64
83 #define MRVL_ARP_LENGTH 28
85 #define MRVL_COOKIE_ADDR_INVALID ~0ULL
87 #define MRVL_COOKIE_HIGH_ADDR_SHIFT (sizeof(pp2_cookie_t) * 8)
88 #define MRVL_COOKIE_HIGH_ADDR_MASK (~0ULL << MRVL_COOKIE_HIGH_ADDR_SHIFT)
90 static const char * const valid_args[] = {
96 static int used_hifs = MRVL_MUSDK_HIFS_RESERVED;
97 static struct pp2_hif *hifs[RTE_MAX_LCORE];
98 static int used_bpools[PP2_NUM_PKT_PROC] = {
99 MRVL_MUSDK_BPOOLS_RESERVED,
100 MRVL_MUSDK_BPOOLS_RESERVED
103 uint64_t cookie_addr_high = MRVL_COOKIE_ADDR_INVALID;
106 struct mrvl_priv *priv;
107 struct rte_mempool *mp;
113 struct mrvl_priv *priv;
118 /** Number of ports configured. */
122 mrvl_reserve_bit(int *bitmap, int max)
124 int n = sizeof(*bitmap) * 8 - __builtin_clz(*bitmap);
135 * Ethernet device configuration.
137 * Prepare the driver for a given number of TX and RX queues.
140 * Pointer to Ethernet device structure.
143 * 0 on success, negative error value otherwise.
146 mrvl_dev_configure(struct rte_eth_dev *dev)
148 struct mrvl_priv *priv = dev->data->dev_private;
151 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_NONE) {
152 RTE_LOG(INFO, PMD, "Unsupported rx multi queue mode %d\n",
153 dev->data->dev_conf.rxmode.mq_mode);
157 if (!dev->data->dev_conf.rxmode.hw_strip_crc) {
159 "L2 CRC stripping is always enabled in hw\n");
160 dev->data->dev_conf.rxmode.hw_strip_crc = 1;
163 if (dev->data->dev_conf.rxmode.hw_vlan_strip) {
164 RTE_LOG(INFO, PMD, "VLAN stripping not supported\n");
168 if (dev->data->dev_conf.rxmode.split_hdr_size) {
169 RTE_LOG(INFO, PMD, "Split headers not supported\n");
173 if (dev->data->dev_conf.rxmode.enable_scatter) {
174 RTE_LOG(INFO, PMD, "RX Scatter/Gather not supported\n");
178 if (dev->data->dev_conf.rxmode.enable_lro) {
179 RTE_LOG(INFO, PMD, "LRO not supported\n");
183 ret = mrvl_configure_rxqs(priv, dev->data->port_id,
184 dev->data->nb_rx_queues);
188 priv->ppio_params.outqs_params.num_outqs = dev->data->nb_tx_queues;
189 priv->nb_rx_queues = dev->data->nb_rx_queues;
195 * DPDK callback to bring the link up.
198 * Pointer to Ethernet device structure.
201 * 0 on success, negative error value otherwise.
204 mrvl_dev_set_link_up(struct rte_eth_dev *dev)
206 struct mrvl_priv *priv = dev->data->dev_private;
209 ret = pp2_ppio_enable(priv->ppio);
213 dev->data->dev_link.link_status = ETH_LINK_UP;
219 * DPDK callback to bring the link down.
222 * Pointer to Ethernet device structure.
225 * 0 on success, negative error value otherwise.
228 mrvl_dev_set_link_down(struct rte_eth_dev *dev)
230 struct mrvl_priv *priv = dev->data->dev_private;
233 ret = pp2_ppio_disable(priv->ppio);
237 dev->data->dev_link.link_status = ETH_LINK_DOWN;
243 * DPDK callback to start the device.
246 * Pointer to Ethernet device structure.
249 * 0 on success, negative errno value on failure.
252 mrvl_dev_start(struct rte_eth_dev *dev)
254 struct mrvl_priv *priv = dev->data->dev_private;
255 char match[MRVL_MATCH_LEN];
258 snprintf(match, sizeof(match), "ppio-%d:%d",
259 priv->pp_id, priv->ppio_id);
260 priv->ppio_params.match = match;
263 * Calculate the maximum bpool size for refill feature to 1.5 of the
264 * configured size. In case the bpool size will exceed this value,
265 * superfluous buffers will be removed
267 priv->bpool_max_size = priv->bpool_init_size +
268 (priv->bpool_init_size >> 1);
270 * Calculate the minimum bpool size for refill feature as follows:
271 * 2 default burst sizes multiply by number of rx queues.
272 * If the bpool size will be below this value, new buffers will
273 * be added to the pool.
275 priv->bpool_min_size = priv->nb_rx_queues * MRVL_BURST_SIZE * 2;
277 ret = pp2_ppio_init(&priv->ppio_params, &priv->ppio);
281 /* For default QoS config, don't start classifier. */
283 ret = mrvl_start_qos_mapping(priv);
285 pp2_ppio_deinit(priv->ppio);
290 ret = mrvl_dev_set_link_up(dev);
296 pp2_ppio_deinit(priv->ppio);
301 * Flush receive queues.
304 * Pointer to Ethernet device structure.
307 mrvl_flush_rx_queues(struct rte_eth_dev *dev)
311 RTE_LOG(INFO, PMD, "Flushing rx queues\n");
312 for (i = 0; i < dev->data->nb_rx_queues; i++) {
316 struct mrvl_rxq *q = dev->data->rx_queues[i];
317 struct pp2_ppio_desc descs[MRVL_PP2_RXD_MAX];
319 num = MRVL_PP2_RXD_MAX;
320 ret = pp2_ppio_recv(q->priv->ppio,
321 q->priv->rxq_map[q->queue_id].tc,
322 q->priv->rxq_map[q->queue_id].inq,
323 descs, (uint16_t *)&num);
324 } while (ret == 0 && num);
329 * Flush hardware bpool (buffer-pool).
332 * Pointer to Ethernet device structure.
335 mrvl_flush_bpool(struct rte_eth_dev *dev)
337 struct mrvl_priv *priv = dev->data->dev_private;
341 ret = pp2_bpool_get_num_buffs(priv->bpool, &num);
343 RTE_LOG(ERR, PMD, "Failed to get bpool buffers number\n");
348 struct pp2_buff_inf inf;
351 ret = pp2_bpool_get_buff(hifs[rte_lcore_id()], priv->bpool,
356 addr = cookie_addr_high | inf.cookie;
357 rte_pktmbuf_free((struct rte_mbuf *)addr);
362 * DPDK callback to stop the device.
365 * Pointer to Ethernet device structure.
368 mrvl_dev_stop(struct rte_eth_dev *dev)
370 struct mrvl_priv *priv = dev->data->dev_private;
372 mrvl_dev_set_link_down(dev);
373 mrvl_flush_rx_queues(dev);
375 pp2_cls_qos_tbl_deinit(priv->qos_tbl);
376 pp2_ppio_deinit(priv->ppio);
381 * DPDK callback to close the device.
384 * Pointer to Ethernet device structure.
387 mrvl_dev_close(struct rte_eth_dev *dev)
389 struct mrvl_priv *priv = dev->data->dev_private;
392 for (i = 0; i < priv->ppio_params.inqs_params.num_tcs; ++i) {
393 struct pp2_ppio_tc_params *tc_params =
394 &priv->ppio_params.inqs_params.tcs_params[i];
396 if (tc_params->inqs_params) {
397 rte_free(tc_params->inqs_params);
398 tc_params->inqs_params = NULL;
402 mrvl_flush_bpool(dev);
406 * DPDK callback to set the primary MAC address.
409 * Pointer to Ethernet device structure.
411 * MAC address to register.
414 mrvl_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
416 struct mrvl_priv *priv = dev->data->dev_private;
418 pp2_ppio_set_mac_addr(priv->ppio, mac_addr->addr_bytes);
421 * Port stops sending packets if pp2_ppio_set_mac_addr()
422 * was called after pp2_ppio_enable(). As a quick fix issue
423 * enable port once again.
425 pp2_ppio_enable(priv->ppio);
429 * DPDK callback to get information about the device.
432 * Pointer to Ethernet device structure (unused).
434 * Info structure output buffer.
437 mrvl_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
438 struct rte_eth_dev_info *info)
440 info->max_rx_queues = MRVL_PP2_RXQ_MAX;
441 info->max_tx_queues = MRVL_PP2_TXQ_MAX;
442 info->max_mac_addrs = MRVL_MAC_ADDRS_MAX;
444 info->rx_desc_lim.nb_max = MRVL_PP2_RXD_MAX;
445 info->rx_desc_lim.nb_min = MRVL_PP2_RXD_MIN;
446 info->rx_desc_lim.nb_align = MRVL_PP2_RXD_ALIGN;
448 info->tx_desc_lim.nb_max = MRVL_PP2_TXD_MAX;
449 info->tx_desc_lim.nb_min = MRVL_PP2_TXD_MIN;
450 info->tx_desc_lim.nb_align = MRVL_PP2_TXD_ALIGN;
452 /* By default packets are dropped if no descriptors are available */
453 info->default_rxconf.rx_drop_en = 1;
455 info->max_rx_pktlen = MRVL_PKT_SIZE_MAX;
459 * DPDK callback to get information about specific receive queue.
462 * Pointer to Ethernet device structure.
464 * Receive queue index.
466 * Receive queue information structure.
468 static void mrvl_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
469 struct rte_eth_rxq_info *qinfo)
471 struct mrvl_rxq *q = dev->data->rx_queues[rx_queue_id];
472 struct mrvl_priv *priv = dev->data->dev_private;
473 int inq = priv->rxq_map[rx_queue_id].inq;
474 int tc = priv->rxq_map[rx_queue_id].tc;
475 struct pp2_ppio_tc_params *tc_params =
476 &priv->ppio_params.inqs_params.tcs_params[tc];
479 qinfo->nb_desc = tc_params->inqs_params[inq].size;
483 * DPDK callback to get information about specific transmit queue.
486 * Pointer to Ethernet device structure.
488 * Transmit queue index.
490 * Transmit queue information structure.
492 static void mrvl_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
493 struct rte_eth_txq_info *qinfo)
495 struct mrvl_priv *priv = dev->data->dev_private;
498 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;
502 * Release buffers to hardware bpool (buffer-pool)
505 * Receive queue pointer.
507 * Number of buffers to release to bpool.
510 * 0 on success, negative error value otherwise.
513 mrvl_fill_bpool(struct mrvl_rxq *rxq, int num)
515 struct buff_release_entry entries[MRVL_PP2_TXD_MAX];
516 struct rte_mbuf *mbufs[MRVL_PP2_TXD_MAX];
518 unsigned int core_id = rte_lcore_id();
519 struct pp2_hif *hif = hifs[core_id];
520 struct pp2_bpool *bpool = rxq->priv->bpool;
522 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, num);
526 if (cookie_addr_high == MRVL_COOKIE_ADDR_INVALID)
528 (uint64_t)mbufs[0] & MRVL_COOKIE_HIGH_ADDR_MASK;
530 for (i = 0; i < num; i++) {
531 if (((uint64_t)mbufs[i] & MRVL_COOKIE_HIGH_ADDR_MASK)
532 != cookie_addr_high) {
534 "mbuf virtual addr high 0x%lx out of range\n",
535 (uint64_t)mbufs[i] >> 32);
539 entries[i].buff.addr =
540 rte_mbuf_data_dma_addr_default(mbufs[i]);
541 entries[i].buff.cookie = (pp2_cookie_t)(uint64_t)mbufs[i];
542 entries[i].bpool = bpool;
545 pp2_bpool_put_buffs(hif, entries, (uint16_t *)&i);
553 rte_pktmbuf_free(mbufs[i]);
559 * DPDK callback to configure the receive queue.
562 * Pointer to Ethernet device structure.
566 * Number of descriptors to configure in queue.
568 * NUMA socket on which memory must be allocated.
570 * Thresholds parameters (unused_).
572 * Memory pool for buffer allocations.
575 * 0 on success, negative error value otherwise.
578 mrvl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
580 const struct rte_eth_rxconf *conf __rte_unused,
581 struct rte_mempool *mp)
583 struct mrvl_priv *priv = dev->data->dev_private;
584 struct mrvl_rxq *rxq;
586 max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
589 if (priv->rxq_map[idx].tc == MRVL_UNKNOWN_TC) {
591 * Unknown TC mapping, mapping will not have a correct queue.
593 RTE_LOG(ERR, PMD, "Unknown TC mapping for queue %hu eth%hhu\n",
598 min_size = rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM -
600 if (min_size < max_rx_pkt_len) {
602 "Mbuf size must be increased to %u bytes to hold up to %u bytes of data.\n",
603 max_rx_pkt_len + RTE_PKTMBUF_HEADROOM +
609 if (dev->data->rx_queues[idx]) {
610 rte_free(dev->data->rx_queues[idx]);
611 dev->data->rx_queues[idx] = NULL;
614 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
621 rxq->port_id = dev->data->port_id;
623 tc = priv->rxq_map[rxq->queue_id].tc,
624 inq = priv->rxq_map[rxq->queue_id].inq;
625 priv->ppio_params.inqs_params.tcs_params[tc].inqs_params[inq].size =
628 ret = mrvl_fill_bpool(rxq, desc);
634 priv->bpool_init_size += desc;
636 dev->data->rx_queues[idx] = rxq;
642 * DPDK callback to release the receive queue.
645 * Generic receive queue pointer.
648 mrvl_rx_queue_release(void *rxq)
650 struct mrvl_rxq *q = rxq;
651 struct pp2_ppio_tc_params *tc_params;
657 tc = q->priv->rxq_map[q->queue_id].tc;
658 inq = q->priv->rxq_map[q->queue_id].inq;
659 tc_params = &q->priv->ppio_params.inqs_params.tcs_params[tc];
660 num = tc_params->inqs_params[inq].size;
661 for (i = 0; i < num; i++) {
662 struct pp2_buff_inf inf;
665 pp2_bpool_get_buff(hifs[rte_lcore_id()], q->priv->bpool, &inf);
666 addr = cookie_addr_high | inf.cookie;
667 rte_pktmbuf_free((struct rte_mbuf *)addr);
674 * DPDK callback to configure the transmit queue.
677 * Pointer to Ethernet device structure.
679 * Transmit queue index.
681 * Number of descriptors to configure in the queue.
683 * NUMA socket on which memory must be allocated.
685 * Thresholds parameters (unused).
688 * 0 on success, negative error value otherwise.
691 mrvl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
693 const struct rte_eth_txconf *conf __rte_unused)
695 struct mrvl_priv *priv = dev->data->dev_private;
696 struct mrvl_txq *txq;
698 if (dev->data->tx_queues[idx]) {
699 rte_free(dev->data->tx_queues[idx]);
700 dev->data->tx_queues[idx] = NULL;
703 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
709 txq->port_id = dev->data->port_id;
710 dev->data->tx_queues[idx] = txq;
712 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
713 priv->ppio_params.outqs_params.outqs_params[idx].weight = 1;
719 * DPDK callback to release the transmit queue.
722 * Generic transmit queue pointer.
725 mrvl_tx_queue_release(void *txq)
727 struct mrvl_txq *q = txq;
735 static const struct eth_dev_ops mrvl_ops = {
736 .dev_configure = mrvl_dev_configure,
737 .dev_start = mrvl_dev_start,
738 .dev_stop = mrvl_dev_stop,
739 .dev_set_link_up = mrvl_dev_set_link_up,
740 .dev_set_link_down = mrvl_dev_set_link_down,
741 .dev_close = mrvl_dev_close,
742 .mac_addr_set = mrvl_mac_addr_set,
743 .dev_infos_get = mrvl_dev_infos_get,
744 .rxq_info_get = mrvl_rxq_info_get,
745 .txq_info_get = mrvl_txq_info_get,
746 .rx_queue_setup = mrvl_rx_queue_setup,
747 .rx_queue_release = mrvl_rx_queue_release,
748 .tx_queue_setup = mrvl_tx_queue_setup,
749 .tx_queue_release = mrvl_tx_queue_release,
753 * Initialize packet processor.
756 * 0 on success, negative error value otherwise.
761 struct pp2_init_params init_params;
763 memset(&init_params, 0, sizeof(init_params));
764 init_params.hif_reserved_map = MRVL_MUSDK_HIFS_RESERVED;
765 init_params.bm_pool_reserved_map = MRVL_MUSDK_BPOOLS_RESERVED;
767 return pp2_init(&init_params);
771 * Deinitialize packet processor.
774 * 0 on success, negative error value otherwise.
777 mrvl_deinit_pp2(void)
783 * Create private device structure.
786 * Pointer to the port name passed in the initialization parameters.
789 * Pointer to the newly allocated private device structure.
791 static struct mrvl_priv *
792 mrvl_priv_create(const char *dev_name)
794 struct pp2_bpool_params bpool_params;
795 char match[MRVL_MATCH_LEN];
796 struct mrvl_priv *priv;
799 priv = rte_zmalloc_socket(dev_name, sizeof(*priv), 0, rte_socket_id());
803 ret = pp2_netdev_get_ppio_info((char *)(uintptr_t)dev_name,
804 &priv->pp_id, &priv->ppio_id);
808 bpool_bit = mrvl_reserve_bit(&used_bpools[priv->pp_id],
809 PP2_BPOOL_NUM_POOLS);
812 priv->bpool_bit = bpool_bit;
814 snprintf(match, sizeof(match), "pool-%d:%d", priv->pp_id,
816 memset(&bpool_params, 0, sizeof(bpool_params));
817 bpool_params.match = match;
818 bpool_params.buff_len = MRVL_PKT_SIZE_MAX + MRVL_PKT_EFFEC_OFFS;
819 ret = pp2_bpool_init(&bpool_params, &priv->bpool);
821 goto out_clear_bpool_bit;
823 priv->ppio_params.type = PP2_PPIO_T_NIC;
827 used_bpools[priv->pp_id] &= ~(1 << priv->bpool_bit);
834 * Create device representing Ethernet port.
837 * Pointer to the port's name.
840 * 0 on success, negative error value otherwise.
843 mrvl_eth_dev_create(struct rte_vdev_device *vdev, const char *name)
845 int ret, fd = socket(AF_INET, SOCK_DGRAM, 0);
846 struct rte_eth_dev *eth_dev;
847 struct mrvl_priv *priv;
850 eth_dev = rte_eth_dev_allocate(name);
854 priv = mrvl_priv_create(name);
860 eth_dev->data->mac_addrs =
861 rte_zmalloc("mac_addrs",
862 ETHER_ADDR_LEN * MRVL_MAC_ADDRS_MAX, 0);
863 if (!eth_dev->data->mac_addrs) {
864 RTE_LOG(ERR, PMD, "Failed to allocate space for eth addrs\n");
869 memset(&req, 0, sizeof(req));
870 strcpy(req.ifr_name, name);
871 ret = ioctl(fd, SIOCGIFHWADDR, &req);
875 memcpy(eth_dev->data->mac_addrs[0].addr_bytes,
876 req.ifr_addr.sa_data, ETHER_ADDR_LEN);
878 eth_dev->data->dev_private = priv;
879 eth_dev->device = &vdev->device;
880 eth_dev->dev_ops = &mrvl_ops;
884 rte_free(eth_dev->data->mac_addrs);
886 rte_eth_dev_release_port(eth_dev);
894 * Cleanup previously created device representing Ethernet port.
897 * Pointer to the port name.
900 mrvl_eth_dev_destroy(const char *name)
902 struct rte_eth_dev *eth_dev;
903 struct mrvl_priv *priv;
905 eth_dev = rte_eth_dev_allocated(name);
909 priv = eth_dev->data->dev_private;
910 pp2_bpool_deinit(priv->bpool);
912 rte_free(eth_dev->data->mac_addrs);
913 rte_eth_dev_release_port(eth_dev);
917 * Callback used by rte_kvargs_process() during argument parsing.
920 * Pointer to the parsed key (unused).
922 * Pointer to the parsed value.
924 * Pointer to the extra arguments which contains address of the
925 * table of pointers to parsed interface names.
931 mrvl_get_ifnames(const char *key __rte_unused, const char *value,
934 const char **ifnames = extra_args;
936 ifnames[mrvl_ports_nb++] = value;
942 * Initialize per-lcore MUSDK hardware interfaces (hifs).
945 * 0 on success, negative error value otherwise.
950 struct pp2_hif_params params;
951 char match[MRVL_MATCH_LEN];
954 RTE_LCORE_FOREACH(i) {
955 ret = mrvl_reserve_bit(&used_hifs, MRVL_MUSDK_HIFS_MAX);
959 snprintf(match, sizeof(match), "hif-%d", ret);
960 memset(¶ms, 0, sizeof(params));
961 params.match = match;
962 params.out_size = MRVL_PP2_AGGR_TXQD_MAX;
963 ret = pp2_hif_init(¶ms, &hifs[i]);
965 RTE_LOG(ERR, PMD, "Failed to initialize hif %d\n", i);
974 * Deinitialize per-lcore MUSDK hardware interfaces (hifs).
977 mrvl_deinit_hifs(void)
981 RTE_LCORE_FOREACH(i) {
983 pp2_hif_deinit(hifs[i]);
988 * DPDK callback to register the virtual device.
991 * Pointer to the virtual device.
994 * 0 on success, negative error value otherwise.
997 rte_pmd_mrvl_probe(struct rte_vdev_device *vdev)
999 struct rte_kvargs *kvlist;
1000 const char *ifnames[PP2_NUM_ETH_PPIO * PP2_NUM_PKT_PROC];
1002 uint32_t i, ifnum, cfgnum;
1005 params = rte_vdev_device_args(vdev);
1009 kvlist = rte_kvargs_parse(params, valid_args);
1013 ifnum = rte_kvargs_count(kvlist, MRVL_IFACE_NAME_ARG);
1014 if (ifnum > RTE_DIM(ifnames))
1015 goto out_free_kvlist;
1017 rte_kvargs_process(kvlist, MRVL_IFACE_NAME_ARG,
1018 mrvl_get_ifnames, &ifnames);
1020 cfgnum = rte_kvargs_count(kvlist, MRVL_CFG_ARG);
1022 RTE_LOG(ERR, PMD, "Cannot handle more than one config file!\n");
1023 goto out_free_kvlist;
1024 } else if (cfgnum == 1) {
1025 rte_kvargs_process(kvlist, MRVL_CFG_ARG,
1026 mrvl_get_qoscfg, &mrvl_qos_cfg);
1030 * ret == -EEXIST is correct, it means DMA
1031 * has been already initialized (by another PMD).
1033 ret = mv_sys_dma_mem_init(RTE_MRVL_MUSDK_DMA_MEMSIZE);
1034 if (ret < 0 && ret != -EEXIST)
1035 goto out_free_kvlist;
1037 ret = mrvl_init_pp2();
1039 RTE_LOG(ERR, PMD, "Failed to init PP!\n");
1040 goto out_deinit_dma;
1043 ret = mrvl_init_hifs();
1045 goto out_deinit_hifs;
1047 for (i = 0; i < ifnum; i++) {
1048 RTE_LOG(INFO, PMD, "Creating %s\n", ifnames[i]);
1049 ret = mrvl_eth_dev_create(vdev, ifnames[i]);
1054 rte_kvargs_free(kvlist);
1059 mrvl_eth_dev_destroy(ifnames[i]);
1064 mv_sys_dma_mem_destroy();
1066 rte_kvargs_free(kvlist);
1072 * DPDK callback to remove virtual device.
1075 * Pointer to the removed virtual device.
1078 * 0 on success, negative error value otherwise.
1081 rte_pmd_mrvl_remove(struct rte_vdev_device *vdev)
1086 name = rte_vdev_device_name(vdev);
1090 RTE_LOG(INFO, PMD, "Removing %s\n", name);
1092 for (i = 0; i < rte_eth_dev_count(); i++) {
1093 char ifname[RTE_ETH_NAME_MAX_LEN];
1095 rte_eth_dev_get_name_by_port(i, ifname);
1096 mrvl_eth_dev_destroy(ifname);
1101 mv_sys_dma_mem_destroy();
1106 static struct rte_vdev_driver pmd_mrvl_drv = {
1107 .probe = rte_pmd_mrvl_probe,
1108 .remove = rte_pmd_mrvl_remove,
1111 RTE_PMD_REGISTER_VDEV(net_mrvl, pmd_mrvl_drv);
1112 RTE_PMD_REGISTER_ALIAS(net_mrvl, eth_mrvl);