1 /* * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
12 #include <rte_ethdev_driver.h>
13 #include <rte_malloc.h>
14 #include <rte_memcpy.h>
15 #include <rte_string_fns.h>
16 #include <rte_cycles.h>
17 #include <rte_kvargs.h>
19 #include <rte_fslmc.h>
20 #include <rte_flow_driver.h>
22 #include "dpaa2_pmd_logs.h"
23 #include <fslmc_vfio.h>
24 #include <dpaa2_hw_pvt.h>
25 #include <dpaa2_hw_mempool.h>
26 #include <dpaa2_hw_dpio.h>
27 #include <mc/fsl_dpmng.h>
28 #include "dpaa2_ethdev.h"
29 #include <fsl_qbman_debug.h>
31 #define DRIVER_LOOPBACK_MODE "drv_loopback"
32 #define DRIVER_NO_PREFETCH_MODE "drv_no_prefetch"
34 /* Supported Rx offloads */
35 static uint64_t dev_rx_offloads_sup =
36 DEV_RX_OFFLOAD_CHECKSUM |
37 DEV_RX_OFFLOAD_SCTP_CKSUM |
38 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
39 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM |
40 DEV_RX_OFFLOAD_VLAN_STRIP |
41 DEV_RX_OFFLOAD_VLAN_FILTER |
42 DEV_RX_OFFLOAD_JUMBO_FRAME |
43 DEV_RX_OFFLOAD_TIMESTAMP;
45 /* Rx offloads which cannot be disabled */
46 static uint64_t dev_rx_offloads_nodis =
47 DEV_RX_OFFLOAD_SCATTER;
49 /* Supported Tx offloads */
50 static uint64_t dev_tx_offloads_sup =
51 DEV_TX_OFFLOAD_VLAN_INSERT |
52 DEV_TX_OFFLOAD_IPV4_CKSUM |
53 DEV_TX_OFFLOAD_UDP_CKSUM |
54 DEV_TX_OFFLOAD_TCP_CKSUM |
55 DEV_TX_OFFLOAD_SCTP_CKSUM |
56 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
57 DEV_TX_OFFLOAD_MT_LOCKFREE |
58 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
60 /* Tx offloads which cannot be disabled */
61 static uint64_t dev_tx_offloads_nodis =
62 DEV_TX_OFFLOAD_MULTI_SEGS;
64 /* enable timestamp in mbuf */
65 enum pmd_dpaa2_ts dpaa2_enable_ts;
67 struct rte_dpaa2_xstats_name_off {
68 char name[RTE_ETH_XSTATS_NAME_SIZE];
69 uint8_t page_id; /* dpni statistics page id */
70 uint8_t stats_id; /* stats id in the given page */
73 static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
74 {"ingress_multicast_frames", 0, 2},
75 {"ingress_multicast_bytes", 0, 3},
76 {"ingress_broadcast_frames", 0, 4},
77 {"ingress_broadcast_bytes", 0, 5},
78 {"egress_multicast_frames", 1, 2},
79 {"egress_multicast_bytes", 1, 3},
80 {"egress_broadcast_frames", 1, 4},
81 {"egress_broadcast_bytes", 1, 5},
82 {"ingress_filtered_frames", 2, 0},
83 {"ingress_discarded_frames", 2, 1},
84 {"ingress_nobuffer_discards", 2, 2},
85 {"egress_discarded_frames", 2, 3},
86 {"egress_confirmed_frames", 2, 4},
87 {"cgr_reject_frames", 4, 0},
88 {"cgr_reject_bytes", 4, 1},
91 static const enum rte_filter_op dpaa2_supported_filter_ops[] = {
93 RTE_ETH_FILTER_DELETE,
94 RTE_ETH_FILTER_UPDATE,
99 static struct rte_dpaa2_driver rte_dpaa2_pmd;
100 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
101 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
102 int wait_to_complete);
103 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
104 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
105 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
107 int dpaa2_logtype_pmd;
110 rte_pmd_dpaa2_set_timestamp(enum pmd_dpaa2_ts enable)
112 dpaa2_enable_ts = enable;
116 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
119 struct dpaa2_dev_priv *priv = dev->data->dev_private;
120 struct fsl_mc_io *dpni = priv->hw;
122 PMD_INIT_FUNC_TRACE();
125 DPAA2_PMD_ERR("dpni is NULL");
130 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW,
131 priv->token, vlan_id);
133 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
134 priv->token, vlan_id);
137 DPAA2_PMD_ERR("ret = %d Unable to add/rem vlan %d hwid =%d",
138 ret, vlan_id, priv->hw_id);
144 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
146 struct dpaa2_dev_priv *priv = dev->data->dev_private;
147 struct fsl_mc_io *dpni = priv->hw;
150 PMD_INIT_FUNC_TRACE();
152 if (mask & ETH_VLAN_FILTER_MASK) {
153 /* VLAN Filter not avaialble */
154 if (!priv->max_vlan_filters) {
155 DPAA2_PMD_INFO("VLAN filter not available");
159 if (dev->data->dev_conf.rxmode.offloads &
160 DEV_RX_OFFLOAD_VLAN_FILTER)
161 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
164 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
167 DPAA2_PMD_INFO("Unable to set vlan filter = %d", ret);
170 if (mask & ETH_VLAN_EXTEND_MASK) {
171 if (dev->data->dev_conf.rxmode.offloads &
172 DEV_RX_OFFLOAD_VLAN_EXTEND)
173 DPAA2_PMD_INFO("VLAN extend offload not supported");
180 dpaa2_vlan_tpid_set(struct rte_eth_dev *dev,
181 enum rte_vlan_type vlan_type __rte_unused,
184 struct dpaa2_dev_priv *priv = dev->data->dev_private;
185 struct fsl_mc_io *dpni = priv->hw;
188 PMD_INIT_FUNC_TRACE();
190 /* nothing to be done for standard vlan tpids */
191 if (tpid == 0x8100 || tpid == 0x88A8)
194 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
197 DPAA2_PMD_INFO("Unable to set vlan tpid = %d", ret);
198 /* if already configured tpids, remove them first */
200 struct dpni_custom_tpid_cfg tpid_list = {0};
202 ret = dpni_get_custom_tpid(dpni, CMD_PRI_LOW,
203 priv->token, &tpid_list);
206 ret = dpni_remove_custom_tpid(dpni, CMD_PRI_LOW,
207 priv->token, tpid_list.tpid1);
210 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
218 dpaa2_fw_version_get(struct rte_eth_dev *dev,
223 struct dpaa2_dev_priv *priv = dev->data->dev_private;
224 struct fsl_mc_io *dpni = priv->hw;
225 struct mc_soc_version mc_plat_info = {0};
226 struct mc_version mc_ver_info = {0};
228 PMD_INIT_FUNC_TRACE();
230 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
231 DPAA2_PMD_WARN("\tmc_get_soc_version failed");
233 if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
234 DPAA2_PMD_WARN("\tmc_get_version failed");
236 ret = snprintf(fw_version, fw_size,
241 mc_ver_info.revision);
243 ret += 1; /* add the size of '\0' */
244 if (fw_size < (uint32_t)ret)
251 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
253 struct dpaa2_dev_priv *priv = dev->data->dev_private;
255 PMD_INIT_FUNC_TRACE();
257 dev_info->if_index = priv->hw_id;
259 dev_info->max_mac_addrs = priv->max_mac_filters;
260 dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
261 dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
262 dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
263 dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
264 dev_info->rx_offload_capa = dev_rx_offloads_sup |
265 dev_rx_offloads_nodis;
266 dev_info->tx_offload_capa = dev_tx_offloads_sup |
267 dev_tx_offloads_nodis;
268 dev_info->speed_capa = ETH_LINK_SPEED_1G |
269 ETH_LINK_SPEED_2_5G |
272 dev_info->max_hash_mac_addrs = 0;
273 dev_info->max_vfs = 0;
274 dev_info->max_vmdq_pools = ETH_16_POOLS;
275 dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
281 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
283 struct dpaa2_dev_priv *priv = dev->data->dev_private;
286 uint8_t num_rxqueue_per_tc;
287 struct dpaa2_queue *mc_q, *mcq;
290 struct dpaa2_queue *dpaa2_q;
292 PMD_INIT_FUNC_TRACE();
294 num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
295 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
296 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
297 RTE_CACHE_LINE_SIZE);
299 DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
303 for (i = 0; i < priv->nb_rx_queues; i++) {
304 mc_q->eth_data = dev->data;
305 priv->rx_vq[i] = mc_q++;
306 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
307 dpaa2_q->q_storage = rte_malloc("dq_storage",
308 sizeof(struct queue_storage_info_t),
309 RTE_CACHE_LINE_SIZE);
310 if (!dpaa2_q->q_storage)
313 memset(dpaa2_q->q_storage, 0,
314 sizeof(struct queue_storage_info_t));
315 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
319 for (i = 0; i < priv->nb_tx_queues; i++) {
320 mc_q->eth_data = dev->data;
321 mc_q->flow_id = 0xffff;
322 priv->tx_vq[i] = mc_q++;
323 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
324 dpaa2_q->cscn = rte_malloc(NULL,
325 sizeof(struct qbman_result), 16);
331 for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
332 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
333 mcq->tc_index = dist_idx / num_rxqueue_per_tc;
334 mcq->flow_id = dist_idx % num_rxqueue_per_tc;
342 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
343 rte_free(dpaa2_q->cscn);
344 priv->tx_vq[i--] = NULL;
346 i = priv->nb_rx_queues;
349 mc_q = priv->rx_vq[0];
351 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
352 dpaa2_free_dq_storage(dpaa2_q->q_storage);
353 rte_free(dpaa2_q->q_storage);
354 priv->rx_vq[i--] = NULL;
361 dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
363 struct dpaa2_dev_priv *priv = dev->data->dev_private;
364 struct dpaa2_queue *dpaa2_q;
367 PMD_INIT_FUNC_TRACE();
369 /* Queue allocation base */
370 if (priv->rx_vq[0]) {
371 /* cleaning up queue storage */
372 for (i = 0; i < priv->nb_rx_queues; i++) {
373 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
374 if (dpaa2_q->q_storage)
375 rte_free(dpaa2_q->q_storage);
377 /* cleanup tx queue cscn */
378 for (i = 0; i < priv->nb_tx_queues; i++) {
379 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
380 rte_free(dpaa2_q->cscn);
382 /*free memory for all queues (RX+TX) */
383 rte_free(priv->rx_vq[0]);
384 priv->rx_vq[0] = NULL;
389 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
391 struct dpaa2_dev_priv *priv = dev->data->dev_private;
392 struct fsl_mc_io *dpni = priv->hw;
393 struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
394 uint64_t rx_offloads = eth_conf->rxmode.offloads;
395 uint64_t tx_offloads = eth_conf->txmode.offloads;
396 int rx_l3_csum_offload = false;
397 int rx_l4_csum_offload = false;
398 int tx_l3_csum_offload = false;
399 int tx_l4_csum_offload = false;
402 PMD_INIT_FUNC_TRACE();
404 /* Rx offloads which are enabled by default */
405 if (dev_rx_offloads_nodis & ~rx_offloads) {
407 "Some of rx offloads enabled by default - requested 0x%" PRIx64
408 " fixed are 0x%" PRIx64,
409 rx_offloads, dev_rx_offloads_nodis);
412 /* Tx offloads which are enabled by default */
413 if (dev_tx_offloads_nodis & ~tx_offloads) {
415 "Some of tx offloads enabled by default - requested 0x%" PRIx64
416 " fixed are 0x%" PRIx64,
417 tx_offloads, dev_tx_offloads_nodis);
420 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
421 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
422 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
423 priv->token, eth_conf->rxmode.max_rx_pkt_len
424 - RTE_ETHER_CRC_LEN);
427 "Unable to set mtu. check config");
431 dev->data->dev_conf.rxmode.max_rx_pkt_len -
432 RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN -
439 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
440 ret = dpaa2_setup_flow_dist(dev,
441 eth_conf->rx_adv_conf.rss_conf.rss_hf);
443 DPAA2_PMD_ERR("Unable to set flow distribution."
444 "Check queue config");
449 if (rx_offloads & DEV_RX_OFFLOAD_IPV4_CKSUM)
450 rx_l3_csum_offload = true;
452 if ((rx_offloads & DEV_RX_OFFLOAD_UDP_CKSUM) ||
453 (rx_offloads & DEV_RX_OFFLOAD_TCP_CKSUM) ||
454 (rx_offloads & DEV_RX_OFFLOAD_SCTP_CKSUM))
455 rx_l4_csum_offload = true;
457 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
458 DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
460 DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
464 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
465 DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
467 DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
471 if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
472 dpaa2_enable_ts = true;
474 if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
475 tx_l3_csum_offload = true;
477 if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ||
478 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
479 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
480 tx_l4_csum_offload = true;
482 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
483 DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
485 DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
489 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
490 DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
492 DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
496 /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
497 * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
498 * to 0 for LS2 in the hardware thus disabling data/annotation
499 * stashing. For LX2 this is fixed in hardware and thus hash result and
500 * parse results can be received in FD using this option.
502 if (dpaa2_svr_family == SVR_LX2160A) {
503 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
504 DPNI_FLCTYPE_HASH, true);
506 DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
511 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
512 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
514 /* update the current status */
515 dpaa2_dev_link_update(dev, 0);
520 /* Function to setup RX flow information. It contains traffic class ID,
521 * flow ID, destination configuration etc.
524 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
525 uint16_t rx_queue_id,
527 unsigned int socket_id __rte_unused,
528 const struct rte_eth_rxconf *rx_conf __rte_unused,
529 struct rte_mempool *mb_pool)
531 struct dpaa2_dev_priv *priv = dev->data->dev_private;
532 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
533 struct dpaa2_queue *dpaa2_q;
534 struct dpni_queue cfg;
540 PMD_INIT_FUNC_TRACE();
542 DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
543 dev, rx_queue_id, mb_pool, rx_conf);
545 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
546 bpid = mempool_to_bpid(mb_pool);
547 ret = dpaa2_attach_bp_list(priv,
548 rte_dpaa2_bpid_info[bpid].bp_list);
552 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
553 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
554 dpaa2_q->bp_array = rte_dpaa2_bpid_info;
556 /*Get the flow id from given VQ id*/
557 flow_id = dpaa2_q->flow_id;
558 memset(&cfg, 0, sizeof(struct dpni_queue));
560 options = options | DPNI_QUEUE_OPT_USER_CTX;
561 cfg.user_context = (size_t)(dpaa2_q);
563 /* check if a private cgr available. */
564 for (i = 0; i < priv->max_cgs; i++) {
565 if (!priv->cgid_in_use[i]) {
566 priv->cgid_in_use[i] = 1;
571 if (i < priv->max_cgs) {
572 options |= DPNI_QUEUE_OPT_SET_CGID;
574 dpaa2_q->cgid = cfg.cgid;
576 dpaa2_q->cgid = 0xff;
579 /*if ls2088 or rev2 device, enable the stashing */
581 if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
582 options |= DPNI_QUEUE_OPT_FLC;
583 cfg.flc.stash_control = true;
584 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
585 /* 00 00 00 - last 6 bit represent annotation, context stashing,
586 * data stashing setting 01 01 00 (0x14)
587 * (in following order ->DS AS CS)
588 * to enable 1 line data, 1 line annotation.
589 * For LX2, this setting should be 01 00 00 (0x10)
591 if ((dpaa2_svr_family & 0xffff0000) == SVR_LX2160A)
592 cfg.flc.value |= 0x10;
594 cfg.flc.value |= 0x14;
596 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
597 dpaa2_q->tc_index, flow_id, options, &cfg);
599 DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
603 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
604 struct dpni_taildrop taildrop;
608 /* Private CGR will use tail drop length as nb_rx_desc.
609 * for rest cases we can use standard byte based tail drop.
610 * There is no HW restriction, but number of CGRs are limited,
611 * hence this restriction is placed.
613 if (dpaa2_q->cgid != 0xff) {
614 /*enabling per rx queue congestion control */
615 taildrop.threshold = nb_rx_desc;
616 taildrop.units = DPNI_CONGESTION_UNIT_FRAMES;
618 DPAA2_PMD_DEBUG("Enabling CG Tail Drop on queue = %d",
620 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
621 DPNI_CP_CONGESTION_GROUP,
626 /*enabling per rx queue congestion control */
627 taildrop.threshold = CONG_THRESHOLD_RX_BYTES_Q;
628 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
629 taildrop.oal = CONG_RX_OAL;
630 DPAA2_PMD_DEBUG("Enabling Byte based Drop on queue= %d",
632 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
633 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
634 dpaa2_q->tc_index, flow_id,
638 DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
642 } else { /* Disable tail Drop */
643 struct dpni_taildrop taildrop = {0};
644 DPAA2_PMD_INFO("Tail drop is disabled on queue");
647 if (dpaa2_q->cgid != 0xff) {
648 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
649 DPNI_CP_CONGESTION_GROUP, DPNI_QUEUE_RX,
653 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
654 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
655 dpaa2_q->tc_index, flow_id, &taildrop);
658 DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
664 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
669 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
670 uint16_t tx_queue_id,
671 uint16_t nb_tx_desc __rte_unused,
672 unsigned int socket_id __rte_unused,
673 const struct rte_eth_txconf *tx_conf __rte_unused)
675 struct dpaa2_dev_priv *priv = dev->data->dev_private;
676 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
677 priv->tx_vq[tx_queue_id];
678 struct fsl_mc_io *dpni = priv->hw;
679 struct dpni_queue tx_conf_cfg;
680 struct dpni_queue tx_flow_cfg;
681 uint8_t options = 0, flow_id;
682 struct dpni_queue_id qid;
686 PMD_INIT_FUNC_TRACE();
688 /* Return if queue already configured */
689 if (dpaa2_q->flow_id != 0xffff) {
690 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
694 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
695 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
700 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
701 tc_id, flow_id, options, &tx_flow_cfg);
703 DPAA2_PMD_ERR("Error in setting the tx flow: "
704 "tc_id=%d, flow=%d err=%d",
705 tc_id, flow_id, ret);
709 dpaa2_q->flow_id = flow_id;
711 if (tx_queue_id == 0) {
712 /*Set tx-conf and error configuration*/
713 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
717 DPAA2_PMD_ERR("Error in set tx conf mode settings: "
722 dpaa2_q->tc_index = tc_id;
724 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
725 DPNI_QUEUE_TX, dpaa2_q->tc_index,
726 dpaa2_q->flow_id, &tx_flow_cfg, &qid);
728 DPAA2_PMD_ERR("Error in getting LFQID err=%d", ret);
731 dpaa2_q->fqid = qid.fqid;
733 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
734 struct dpni_congestion_notification_cfg cong_notif_cfg = {0};
736 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
737 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
738 /* Notify that the queue is not congested when the data in
739 * the queue is below this thershold.
741 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
742 cong_notif_cfg.message_ctx = 0;
743 cong_notif_cfg.message_iova =
744 (size_t)DPAA2_VADDR_TO_IOVA(dpaa2_q->cscn);
745 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
746 cong_notif_cfg.notification_mode =
747 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
748 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
749 DPNI_CONG_OPT_COHERENT_WRITE;
750 cong_notif_cfg.cg_point = DPNI_CP_QUEUE;
752 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
759 "Error in setting tx congestion notification: "
764 dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
765 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
770 dpaa2_dev_rx_queue_release(void *q __rte_unused)
772 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)q;
773 struct dpaa2_dev_priv *priv = dpaa2_q->eth_data->dev_private;
774 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
777 struct dpni_queue cfg;
779 memset(&cfg, 0, sizeof(struct dpni_queue));
780 PMD_INIT_FUNC_TRACE();
781 if (dpaa2_q->cgid != 0xff) {
782 options = DPNI_QUEUE_OPT_CLEAR_CGID;
783 cfg.cgid = dpaa2_q->cgid;
785 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token,
787 dpaa2_q->tc_index, dpaa2_q->flow_id,
790 DPAA2_PMD_ERR("Unable to clear CGR from q=%u err=%d",
792 priv->cgid_in_use[dpaa2_q->cgid] = 0;
793 dpaa2_q->cgid = 0xff;
798 dpaa2_dev_tx_queue_release(void *q __rte_unused)
800 PMD_INIT_FUNC_TRACE();
804 dpaa2_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
807 struct dpaa2_dev_priv *priv = dev->data->dev_private;
808 struct dpaa2_queue *dpaa2_q;
809 struct qbman_swp *swp;
810 struct qbman_fq_query_np_rslt state;
811 uint32_t frame_cnt = 0;
813 PMD_INIT_FUNC_TRACE();
815 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
816 ret = dpaa2_affine_qbman_swp();
818 DPAA2_PMD_ERR("Failure in affining portal");
822 swp = DPAA2_PER_LCORE_PORTAL;
824 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
826 if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
827 frame_cnt = qbman_fq_state_frame_count(&state);
828 DPAA2_PMD_DEBUG("RX frame count for q(%d) is %u",
829 rx_queue_id, frame_cnt);
834 static const uint32_t *
835 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
837 static const uint32_t ptypes[] = {
838 /*todo -= add more types */
841 RTE_PTYPE_L3_IPV4_EXT,
843 RTE_PTYPE_L3_IPV6_EXT,
851 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
852 dev->rx_pkt_burst == dpaa2_dev_rx ||
853 dev->rx_pkt_burst == dpaa2_dev_loopback_rx)
859 * Dpaa2 link Interrupt handler
862 * The address of parameter (struct rte_eth_dev *) regsitered before.
868 dpaa2_interrupt_handler(void *param)
870 struct rte_eth_dev *dev = param;
871 struct dpaa2_dev_priv *priv = dev->data->dev_private;
872 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
874 int irq_index = DPNI_IRQ_INDEX;
875 unsigned int status = 0, clear = 0;
877 PMD_INIT_FUNC_TRACE();
880 DPAA2_PMD_ERR("dpni is NULL");
884 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
887 DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
892 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
893 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
894 dpaa2_dev_link_update(dev, 0);
895 /* calling all the apps registered for link status event */
896 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
900 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
903 DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
907 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
910 struct dpaa2_dev_priv *priv = dev->data->dev_private;
911 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
912 int irq_index = DPNI_IRQ_INDEX;
913 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
915 PMD_INIT_FUNC_TRACE();
917 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
920 DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
925 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
928 DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
935 dpaa2_dev_start(struct rte_eth_dev *dev)
937 struct rte_device *rdev = dev->device;
938 struct rte_dpaa2_device *dpaa2_dev;
939 struct rte_eth_dev_data *data = dev->data;
940 struct dpaa2_dev_priv *priv = data->dev_private;
941 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
942 struct dpni_queue cfg;
943 struct dpni_error_cfg err_cfg;
945 struct dpni_queue_id qid;
946 struct dpaa2_queue *dpaa2_q;
948 struct rte_intr_handle *intr_handle;
950 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
951 intr_handle = &dpaa2_dev->intr_handle;
953 PMD_INIT_FUNC_TRACE();
955 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
957 DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
962 /* Power up the phy. Needed to make the link go UP */
963 dpaa2_dev_set_link_up(dev);
965 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
966 DPNI_QUEUE_TX, &qdid);
968 DPAA2_PMD_ERR("Error in getting qdid: err=%d", ret);
973 for (i = 0; i < data->nb_rx_queues; i++) {
974 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
975 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
976 DPNI_QUEUE_RX, dpaa2_q->tc_index,
977 dpaa2_q->flow_id, &cfg, &qid);
979 DPAA2_PMD_ERR("Error in getting flow information: "
983 dpaa2_q->fqid = qid.fqid;
986 /*checksum errors, send them to normal path and set it in annotation */
987 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
988 err_cfg.errors |= DPNI_ERROR_PHE;
990 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
991 err_cfg.set_frame_annotation = true;
993 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
994 priv->token, &err_cfg);
996 DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
1001 /* if the interrupts were configured on this devices*/
1002 if (intr_handle && (intr_handle->fd) &&
1003 (dev->data->dev_conf.intr_conf.lsc != 0)) {
1004 /* Registering LSC interrupt handler */
1005 rte_intr_callback_register(intr_handle,
1006 dpaa2_interrupt_handler,
1009 /* enable vfio intr/eventfd mapping
1010 * Interrupt index 0 is required, so we can not use
1013 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
1015 /* enable dpni_irqs */
1016 dpaa2_eth_setup_irqs(dev, 1);
1019 /* Change the tx burst function if ordered queues are used */
1020 if (priv->en_ordered)
1021 dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
1027 * This routine disables all traffic on the adapter by issuing a
1028 * global reset on the MAC.
1031 dpaa2_dev_stop(struct rte_eth_dev *dev)
1033 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1034 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1036 struct rte_eth_link link;
1037 struct rte_intr_handle *intr_handle = dev->intr_handle;
1039 PMD_INIT_FUNC_TRACE();
1041 /* reset interrupt callback */
1042 if (intr_handle && (intr_handle->fd) &&
1043 (dev->data->dev_conf.intr_conf.lsc != 0)) {
1044 /*disable dpni irqs */
1045 dpaa2_eth_setup_irqs(dev, 0);
1047 /* disable vfio intr before callback unregister */
1048 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
1050 /* Unregistering LSC interrupt handler */
1051 rte_intr_callback_unregister(intr_handle,
1052 dpaa2_interrupt_handler,
1056 dpaa2_dev_set_link_down(dev);
1058 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
1060 DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
1065 /* clear the recorded link status */
1066 memset(&link, 0, sizeof(link));
1067 rte_eth_linkstatus_set(dev, &link);
1071 dpaa2_dev_close(struct rte_eth_dev *dev)
1073 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1074 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1076 struct rte_eth_link link;
1078 PMD_INIT_FUNC_TRACE();
1080 dpaa2_flow_clean(dev);
1082 /* Clean the device first */
1083 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
1085 DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
1089 memset(&link, 0, sizeof(link));
1090 rte_eth_linkstatus_set(dev, &link);
1094 dpaa2_dev_promiscuous_enable(
1095 struct rte_eth_dev *dev)
1098 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1099 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1101 PMD_INIT_FUNC_TRACE();
1104 DPAA2_PMD_ERR("dpni is NULL");
1108 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1110 DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
1112 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1114 DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
1120 dpaa2_dev_promiscuous_disable(
1121 struct rte_eth_dev *dev)
1124 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1125 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1127 PMD_INIT_FUNC_TRACE();
1130 DPAA2_PMD_ERR("dpni is NULL");
1134 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1136 DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
1138 if (dev->data->all_multicast == 0) {
1139 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
1140 priv->token, false);
1142 DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
1150 dpaa2_dev_allmulticast_enable(
1151 struct rte_eth_dev *dev)
1154 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1155 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1157 PMD_INIT_FUNC_TRACE();
1160 DPAA2_PMD_ERR("dpni is NULL");
1164 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1166 DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
1172 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
1175 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1176 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1178 PMD_INIT_FUNC_TRACE();
1181 DPAA2_PMD_ERR("dpni is NULL");
1185 /* must remain on for all promiscuous */
1186 if (dev->data->promiscuous == 1)
1189 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1191 DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
1197 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1200 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1201 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1202 uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
1205 PMD_INIT_FUNC_TRACE();
1208 DPAA2_PMD_ERR("dpni is NULL");
1212 /* check that mtu is within the allowed range */
1213 if (mtu < RTE_ETHER_MIN_MTU || frame_size > DPAA2_MAX_RX_PKT_LEN)
1216 if (frame_size > RTE_ETHER_MAX_LEN)
1217 dev->data->dev_conf.rxmode.offloads &=
1218 DEV_RX_OFFLOAD_JUMBO_FRAME;
1220 dev->data->dev_conf.rxmode.offloads &=
1221 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1223 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1225 /* Set the Max Rx frame length as 'mtu' +
1226 * Maximum Ethernet header length
1228 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
1229 frame_size - RTE_ETHER_CRC_LEN);
1231 DPAA2_PMD_ERR("Setting the max frame length failed");
1234 DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
1239 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
1240 struct rte_ether_addr *addr,
1241 __rte_unused uint32_t index,
1242 __rte_unused uint32_t pool)
1245 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1246 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1248 PMD_INIT_FUNC_TRACE();
1251 DPAA2_PMD_ERR("dpni is NULL");
1255 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
1256 priv->token, addr->addr_bytes);
1259 "error: Adding the MAC ADDR failed: err = %d", ret);
1264 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1268 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1269 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1270 struct rte_eth_dev_data *data = dev->data;
1271 struct rte_ether_addr *macaddr;
1273 PMD_INIT_FUNC_TRACE();
1275 macaddr = &data->mac_addrs[index];
1278 DPAA2_PMD_ERR("dpni is NULL");
1282 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1283 priv->token, macaddr->addr_bytes);
1286 "error: Removing the MAC ADDR failed: err = %d", ret);
1290 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1291 struct rte_ether_addr *addr)
1294 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1295 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1297 PMD_INIT_FUNC_TRACE();
1300 DPAA2_PMD_ERR("dpni is NULL");
1304 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1305 priv->token, addr->addr_bytes);
1309 "error: Setting the MAC ADDR failed %d", ret);
1315 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1316 struct rte_eth_stats *stats)
1318 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1319 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1321 uint8_t page0 = 0, page1 = 1, page2 = 2;
1322 union dpni_statistics value;
1324 struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
1326 memset(&value, 0, sizeof(union dpni_statistics));
1328 PMD_INIT_FUNC_TRACE();
1331 DPAA2_PMD_ERR("dpni is NULL");
1336 DPAA2_PMD_ERR("stats is NULL");
1340 /*Get Counters from page_0*/
1341 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1346 stats->ipackets = value.page_0.ingress_all_frames;
1347 stats->ibytes = value.page_0.ingress_all_bytes;
1349 /*Get Counters from page_1*/
1350 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1355 stats->opackets = value.page_1.egress_all_frames;
1356 stats->obytes = value.page_1.egress_all_bytes;
1358 /*Get Counters from page_2*/
1359 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1364 /* Ingress drop frame count due to configured rules */
1365 stats->ierrors = value.page_2.ingress_filtered_frames;
1366 /* Ingress drop frame count due to error */
1367 stats->ierrors += value.page_2.ingress_discarded_frames;
1369 stats->oerrors = value.page_2.egress_discarded_frames;
1370 stats->imissed = value.page_2.ingress_nobuffer_discards;
1372 /* Fill in per queue stats */
1373 for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1374 (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
1375 dpaa2_rxq = (struct dpaa2_queue *)priv->rx_vq[i];
1376 dpaa2_txq = (struct dpaa2_queue *)priv->tx_vq[i];
1378 stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
1380 stats->q_opackets[i] = dpaa2_txq->tx_pkts;
1382 /* Byte counting is not implemented */
1383 stats->q_ibytes[i] = 0;
1384 stats->q_obytes[i] = 0;
1390 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1395 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1398 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1399 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1401 union dpni_statistics value[5] = {};
1402 unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1410 /* Get Counters from page_0*/
1411 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1416 /* Get Counters from page_1*/
1417 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1422 /* Get Counters from page_2*/
1423 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1428 for (i = 0; i < priv->max_cgs; i++) {
1429 if (!priv->cgid_in_use[i]) {
1430 /* Get Counters from page_4*/
1431 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW,
1440 for (i = 0; i < num; i++) {
1442 xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1443 raw.counter[dpaa2_xstats_strings[i].stats_id];
1447 DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
1452 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1453 struct rte_eth_xstat_name *xstats_names,
1456 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1458 if (limit < stat_cnt)
1461 if (xstats_names != NULL)
1462 for (i = 0; i < stat_cnt; i++)
1463 strlcpy(xstats_names[i].name,
1464 dpaa2_xstats_strings[i].name,
1465 sizeof(xstats_names[i].name));
1471 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1472 uint64_t *values, unsigned int n)
1474 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1475 uint64_t values_copy[stat_cnt];
1478 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1479 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1481 union dpni_statistics value[5] = {};
1489 /* Get Counters from page_0*/
1490 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1495 /* Get Counters from page_1*/
1496 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1501 /* Get Counters from page_2*/
1502 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1507 /* Get Counters from page_4*/
1508 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1513 for (i = 0; i < stat_cnt; i++) {
1514 values[i] = value[dpaa2_xstats_strings[i].page_id].
1515 raw.counter[dpaa2_xstats_strings[i].stats_id];
1520 dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1522 for (i = 0; i < n; i++) {
1523 if (ids[i] >= stat_cnt) {
1524 DPAA2_PMD_ERR("xstats id value isn't valid");
1527 values[i] = values_copy[ids[i]];
1533 dpaa2_xstats_get_names_by_id(
1534 struct rte_eth_dev *dev,
1535 struct rte_eth_xstat_name *xstats_names,
1536 const uint64_t *ids,
1539 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1540 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1543 return dpaa2_xstats_get_names(dev, xstats_names, limit);
1545 dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1547 for (i = 0; i < limit; i++) {
1548 if (ids[i] >= stat_cnt) {
1549 DPAA2_PMD_ERR("xstats id value isn't valid");
1552 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1558 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1560 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1561 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1564 struct dpaa2_queue *dpaa2_q;
1566 PMD_INIT_FUNC_TRACE();
1569 DPAA2_PMD_ERR("dpni is NULL");
1573 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1577 /* Reset the per queue stats in dpaa2_queue structure */
1578 for (i = 0; i < priv->nb_rx_queues; i++) {
1579 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1581 dpaa2_q->rx_pkts = 0;
1584 for (i = 0; i < priv->nb_tx_queues; i++) {
1585 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
1587 dpaa2_q->tx_pkts = 0;
1593 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1597 /* return 0 means link status changed, -1 means not changed */
1599 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1600 int wait_to_complete __rte_unused)
1603 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1604 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1605 struct rte_eth_link link;
1606 struct dpni_link_state state = {0};
1609 DPAA2_PMD_ERR("dpni is NULL");
1613 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1615 DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
1619 memset(&link, 0, sizeof(struct rte_eth_link));
1620 link.link_status = state.up;
1621 link.link_speed = state.rate;
1623 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1624 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1626 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1628 ret = rte_eth_linkstatus_set(dev, &link);
1630 DPAA2_PMD_DEBUG("No change in status");
1632 DPAA2_PMD_INFO("Port %d Link is %s\n", dev->data->port_id,
1633 link.link_status ? "Up" : "Down");
1639 * Toggle the DPNI to enable, if not already enabled.
1640 * This is not strictly PHY up/down - it is more of logical toggling.
1643 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1646 struct dpaa2_dev_priv *priv;
1647 struct fsl_mc_io *dpni;
1649 struct dpni_link_state state = {0};
1651 priv = dev->data->dev_private;
1652 dpni = (struct fsl_mc_io *)priv->hw;
1655 DPAA2_PMD_ERR("dpni is NULL");
1659 /* Check if DPNI is currently enabled */
1660 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1662 /* Unable to obtain dpni status; Not continuing */
1663 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1667 /* Enable link if not already enabled */
1669 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1671 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1675 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1677 DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
1681 /* changing tx burst function to start enqueues */
1682 dev->tx_pkt_burst = dpaa2_dev_tx;
1683 dev->data->dev_link.link_status = state.up;
1686 DPAA2_PMD_INFO("Port %d Link is Up", dev->data->port_id);
1688 DPAA2_PMD_INFO("Port %d Link is Down", dev->data->port_id);
1693 * Toggle the DPNI to disable, if not already disabled.
1694 * This is not strictly PHY up/down - it is more of logical toggling.
1697 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1700 struct dpaa2_dev_priv *priv;
1701 struct fsl_mc_io *dpni;
1702 int dpni_enabled = 0;
1705 PMD_INIT_FUNC_TRACE();
1707 priv = dev->data->dev_private;
1708 dpni = (struct fsl_mc_io *)priv->hw;
1711 DPAA2_PMD_ERR("Device has not yet been configured");
1715 /*changing tx burst function to avoid any more enqueues */
1716 dev->tx_pkt_burst = dummy_dev_tx;
1718 /* Loop while dpni_disable() attempts to drain the egress FQs
1719 * and confirm them back to us.
1722 ret = dpni_disable(dpni, 0, priv->token);
1724 DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
1727 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1729 DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
1733 /* Allow the MC some slack */
1734 rte_delay_us(100 * 1000);
1735 } while (dpni_enabled && --retries);
1738 DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
1739 /* todo- we may have to manually cleanup queues.
1742 DPAA2_PMD_INFO("Port %d Link DOWN successful",
1743 dev->data->port_id);
1746 dev->data->dev_link.link_status = 0;
1752 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1755 struct dpaa2_dev_priv *priv;
1756 struct fsl_mc_io *dpni;
1757 struct dpni_link_state state = {0};
1759 PMD_INIT_FUNC_TRACE();
1761 priv = dev->data->dev_private;
1762 dpni = (struct fsl_mc_io *)priv->hw;
1764 if (dpni == NULL || fc_conf == NULL) {
1765 DPAA2_PMD_ERR("device not configured");
1769 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1771 DPAA2_PMD_ERR("error: dpni_get_link_state %d", ret);
1775 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1776 if (state.options & DPNI_LINK_OPT_PAUSE) {
1777 /* DPNI_LINK_OPT_PAUSE set
1778 * if ASYM_PAUSE not set,
1779 * RX Side flow control (handle received Pause frame)
1780 * TX side flow control (send Pause frame)
1781 * if ASYM_PAUSE set,
1782 * RX Side flow control (handle received Pause frame)
1783 * No TX side flow control (send Pause frame disabled)
1785 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1786 fc_conf->mode = RTE_FC_FULL;
1788 fc_conf->mode = RTE_FC_RX_PAUSE;
1790 /* DPNI_LINK_OPT_PAUSE not set
1791 * if ASYM_PAUSE set,
1792 * TX side flow control (send Pause frame)
1793 * No RX side flow control (No action on pause frame rx)
1794 * if ASYM_PAUSE not set,
1795 * Flow control disabled
1797 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1798 fc_conf->mode = RTE_FC_TX_PAUSE;
1800 fc_conf->mode = RTE_FC_NONE;
1807 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1810 struct dpaa2_dev_priv *priv;
1811 struct fsl_mc_io *dpni;
1812 struct dpni_link_state state = {0};
1813 struct dpni_link_cfg cfg = {0};
1815 PMD_INIT_FUNC_TRACE();
1817 priv = dev->data->dev_private;
1818 dpni = (struct fsl_mc_io *)priv->hw;
1821 DPAA2_PMD_ERR("dpni is NULL");
1825 /* It is necessary to obtain the current state before setting fc_conf
1826 * as MC would return error in case rate, autoneg or duplex values are
1829 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1831 DPAA2_PMD_ERR("Unable to get link state (err=%d)", ret);
1835 /* Disable link before setting configuration */
1836 dpaa2_dev_set_link_down(dev);
1838 /* Based on fc_conf, update cfg */
1839 cfg.rate = state.rate;
1840 cfg.options = state.options;
1842 /* update cfg with fc_conf */
1843 switch (fc_conf->mode) {
1845 /* Full flow control;
1846 * OPT_PAUSE set, ASYM_PAUSE not set
1848 cfg.options |= DPNI_LINK_OPT_PAUSE;
1849 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1851 case RTE_FC_TX_PAUSE:
1852 /* Enable RX flow control
1853 * OPT_PAUSE not set;
1856 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1857 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1859 case RTE_FC_RX_PAUSE:
1860 /* Enable TX Flow control
1864 cfg.options |= DPNI_LINK_OPT_PAUSE;
1865 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1868 /* Disable Flow control
1870 * ASYM_PAUSE not set
1872 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1873 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1876 DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
1881 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1883 DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
1887 dpaa2_dev_set_link_up(dev);
1893 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
1894 struct rte_eth_rss_conf *rss_conf)
1896 struct rte_eth_dev_data *data = dev->data;
1897 struct rte_eth_conf *eth_conf = &data->dev_conf;
1900 PMD_INIT_FUNC_TRACE();
1902 if (rss_conf->rss_hf) {
1903 ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf);
1905 DPAA2_PMD_ERR("Unable to set flow dist");
1909 ret = dpaa2_remove_flow_dist(dev, 0);
1911 DPAA2_PMD_ERR("Unable to remove flow dist");
1915 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1920 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1921 struct rte_eth_rss_conf *rss_conf)
1923 struct rte_eth_dev_data *data = dev->data;
1924 struct rte_eth_conf *eth_conf = &data->dev_conf;
1926 /* dpaa2 does not support rss_key, so length should be 0*/
1927 rss_conf->rss_key_len = 0;
1928 rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1932 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
1933 int eth_rx_queue_id,
1935 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1937 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1938 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1939 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1940 uint8_t flow_id = dpaa2_ethq->flow_id;
1941 struct dpni_queue cfg;
1945 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
1946 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
1947 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
1948 dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
1949 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
1950 dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
1954 memset(&cfg, 0, sizeof(struct dpni_queue));
1955 options = DPNI_QUEUE_OPT_DEST;
1956 cfg.destination.type = DPNI_DEST_DPCON;
1957 cfg.destination.id = dpcon_id;
1958 cfg.destination.priority = queue_conf->ev.priority;
1960 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
1961 options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
1962 cfg.destination.hold_active = 1;
1965 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
1966 !eth_priv->en_ordered) {
1967 struct opr_cfg ocfg;
1969 /* Restoration window size = 256 frames */
1971 /* Restoration window size = 512 frames for LX2 */
1972 if (dpaa2_svr_family == SVR_LX2160A)
1974 /* Auto advance NESN window enabled */
1976 /* Late arrival window size disabled */
1978 /* ORL resource exhaustaion advance NESN disabled */
1980 /* Loose ordering enabled */
1982 eth_priv->en_loose_ordered = 1;
1983 /* Strict ordering enabled if explicitly set */
1984 if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
1986 eth_priv->en_loose_ordered = 0;
1989 ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
1990 dpaa2_ethq->tc_index, flow_id,
1991 OPR_OPT_CREATE, &ocfg);
1993 DPAA2_PMD_ERR("Error setting opr: ret: %d\n", ret);
1997 eth_priv->en_ordered = 1;
2000 options |= DPNI_QUEUE_OPT_USER_CTX;
2001 cfg.user_context = (size_t)(dpaa2_ethq);
2003 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
2004 dpaa2_ethq->tc_index, flow_id, options, &cfg);
2006 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
2010 memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
2015 int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
2016 int eth_rx_queue_id)
2018 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
2019 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
2020 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
2021 uint8_t flow_id = dpaa2_ethq->flow_id;
2022 struct dpni_queue cfg;
2026 memset(&cfg, 0, sizeof(struct dpni_queue));
2027 options = DPNI_QUEUE_OPT_DEST;
2028 cfg.destination.type = DPNI_DEST_NONE;
2030 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
2031 dpaa2_ethq->tc_index, flow_id, options, &cfg);
2033 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
2039 dpaa2_dev_verify_filter_ops(enum rte_filter_op filter_op)
2043 for (i = 0; i < RTE_DIM(dpaa2_supported_filter_ops); i++) {
2044 if (dpaa2_supported_filter_ops[i] == filter_op)
2051 dpaa2_dev_flow_ctrl(struct rte_eth_dev *dev,
2052 enum rte_filter_type filter_type,
2053 enum rte_filter_op filter_op,
2061 switch (filter_type) {
2062 case RTE_ETH_FILTER_GENERIC:
2063 if (dpaa2_dev_verify_filter_ops(filter_op) < 0) {
2067 *(const void **)arg = &dpaa2_flow_ops;
2068 dpaa2_filter_type |= filter_type;
2071 RTE_LOG(ERR, PMD, "Filter type (%d) not supported",
2079 static struct eth_dev_ops dpaa2_ethdev_ops = {
2080 .dev_configure = dpaa2_eth_dev_configure,
2081 .dev_start = dpaa2_dev_start,
2082 .dev_stop = dpaa2_dev_stop,
2083 .dev_close = dpaa2_dev_close,
2084 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
2085 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
2086 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
2087 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
2088 .dev_set_link_up = dpaa2_dev_set_link_up,
2089 .dev_set_link_down = dpaa2_dev_set_link_down,
2090 .link_update = dpaa2_dev_link_update,
2091 .stats_get = dpaa2_dev_stats_get,
2092 .xstats_get = dpaa2_dev_xstats_get,
2093 .xstats_get_by_id = dpaa2_xstats_get_by_id,
2094 .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
2095 .xstats_get_names = dpaa2_xstats_get_names,
2096 .stats_reset = dpaa2_dev_stats_reset,
2097 .xstats_reset = dpaa2_dev_stats_reset,
2098 .fw_version_get = dpaa2_fw_version_get,
2099 .dev_infos_get = dpaa2_dev_info_get,
2100 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
2101 .mtu_set = dpaa2_dev_mtu_set,
2102 .vlan_filter_set = dpaa2_vlan_filter_set,
2103 .vlan_offload_set = dpaa2_vlan_offload_set,
2104 .vlan_tpid_set = dpaa2_vlan_tpid_set,
2105 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
2106 .rx_queue_release = dpaa2_dev_rx_queue_release,
2107 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
2108 .tx_queue_release = dpaa2_dev_tx_queue_release,
2109 .rx_queue_count = dpaa2_dev_rx_queue_count,
2110 .flow_ctrl_get = dpaa2_flow_ctrl_get,
2111 .flow_ctrl_set = dpaa2_flow_ctrl_set,
2112 .mac_addr_add = dpaa2_dev_add_mac_addr,
2113 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
2114 .mac_addr_set = dpaa2_dev_set_mac_addr,
2115 .rss_hash_update = dpaa2_dev_rss_hash_update,
2116 .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get,
2117 .filter_ctrl = dpaa2_dev_flow_ctrl,
2120 /* Populate the mac address from physically available (u-boot/firmware) and/or
2121 * one set by higher layers like MC (restool) etc.
2122 * Returns the table of MAC entries (multiple entries)
2125 populate_mac_addr(struct fsl_mc_io *dpni_dev, struct dpaa2_dev_priv *priv,
2126 struct rte_ether_addr *mac_entry)
2129 struct rte_ether_addr phy_mac, prime_mac;
2131 memset(&phy_mac, 0, sizeof(struct rte_ether_addr));
2132 memset(&prime_mac, 0, sizeof(struct rte_ether_addr));
2134 /* Get the physical device MAC address */
2135 ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2136 phy_mac.addr_bytes);
2138 DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
2142 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2143 prime_mac.addr_bytes);
2145 DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
2149 /* Now that both MAC have been obtained, do:
2150 * if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
2152 * If empty_mac(phy), return prime.
2153 * if both are empty, create random MAC, set as prime and return
2155 if (!rte_is_zero_ether_addr(&phy_mac)) {
2156 /* If the addresses are not same, overwrite prime */
2157 if (!rte_is_same_ether_addr(&phy_mac, &prime_mac)) {
2158 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2160 phy_mac.addr_bytes);
2162 DPAA2_PMD_ERR("Unable to set MAC Address: %d",
2166 memcpy(&prime_mac, &phy_mac,
2167 sizeof(struct rte_ether_addr));
2169 } else if (rte_is_zero_ether_addr(&prime_mac)) {
2170 /* In case phys and prime, both are zero, create random MAC */
2171 rte_eth_random_addr(prime_mac.addr_bytes);
2172 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2174 prime_mac.addr_bytes);
2176 DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
2181 /* prime_mac the final MAC address */
2182 memcpy(mac_entry, &prime_mac, sizeof(struct rte_ether_addr));
2190 check_devargs_handler(__rte_unused const char *key, const char *value,
2191 __rte_unused void *opaque)
2193 if (strcmp(value, "1"))
2200 dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
2202 struct rte_kvargs *kvlist;
2207 kvlist = rte_kvargs_parse(devargs->args, NULL);
2211 if (!rte_kvargs_count(kvlist, key)) {
2212 rte_kvargs_free(kvlist);
2216 if (rte_kvargs_process(kvlist, key,
2217 check_devargs_handler, NULL) < 0) {
2218 rte_kvargs_free(kvlist);
2221 rte_kvargs_free(kvlist);
2227 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
2229 struct rte_device *dev = eth_dev->device;
2230 struct rte_dpaa2_device *dpaa2_dev;
2231 struct fsl_mc_io *dpni_dev;
2232 struct dpni_attr attr;
2233 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2234 struct dpni_buffer_layout layout;
2237 PMD_INIT_FUNC_TRACE();
2239 /* For secondary processes, the primary has done all the work */
2240 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2241 /* In case of secondary, only burst and ops API need to be
2244 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2245 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
2246 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2247 else if (dpaa2_get_devargs(dev->devargs,
2248 DRIVER_NO_PREFETCH_MODE))
2249 eth_dev->rx_pkt_burst = dpaa2_dev_rx;
2251 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2252 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2256 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2258 hw_id = dpaa2_dev->object_id;
2260 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
2262 DPAA2_PMD_ERR("Memory allocation failed for dpni device");
2266 dpni_dev->regs = rte_mcp_ptr_list[0];
2267 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
2270 "Failure in opening dpni@%d with err code %d",
2276 /* Clean the device first */
2277 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
2279 DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
2284 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
2287 "Failure in get dpni@%d attribute, err code %d",
2292 priv->num_rx_tc = attr.num_rx_tcs;
2293 /* only if the custom CG is enabled */
2294 if (attr.options & DPNI_OPT_CUSTOM_CG)
2295 priv->max_cgs = attr.num_cgs;
2299 for (i = 0; i < priv->max_cgs; i++)
2300 priv->cgid_in_use[i] = 0;
2302 for (i = 0; i < attr.num_rx_tcs; i++)
2303 priv->nb_rx_queues += attr.num_queues;
2305 /* Using number of TX queues as number of TX TCs */
2306 priv->nb_tx_queues = attr.num_tx_tcs;
2308 DPAA2_PMD_DEBUG("RX-TC= %d, rx_queues= %d, tx_queues=%d, max_cgs=%d",
2309 priv->num_rx_tc, priv->nb_rx_queues,
2310 priv->nb_tx_queues, priv->max_cgs);
2312 priv->hw = dpni_dev;
2313 priv->hw_id = hw_id;
2314 priv->options = attr.options;
2315 priv->max_mac_filters = attr.mac_filter_entries;
2316 priv->max_vlan_filters = attr.vlan_filter_entries;
2319 /* Allocate memory for hardware structure for queues */
2320 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
2322 DPAA2_PMD_ERR("Queue allocation Failed");
2326 /* Allocate memory for storing MAC addresses.
2327 * Table of mac_filter_entries size is allocated so that RTE ether lib
2328 * can add MAC entries when rte_eth_dev_mac_addr_add is called.
2330 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
2331 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
2332 if (eth_dev->data->mac_addrs == NULL) {
2334 "Failed to allocate %d bytes needed to store MAC addresses",
2335 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries);
2340 ret = populate_mac_addr(dpni_dev, priv, ð_dev->data->mac_addrs[0]);
2342 DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
2343 rte_free(eth_dev->data->mac_addrs);
2344 eth_dev->data->mac_addrs = NULL;
2348 /* ... tx buffer layout ... */
2349 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2350 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2351 layout.pass_frame_status = 1;
2352 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2353 DPNI_QUEUE_TX, &layout);
2355 DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
2359 /* ... tx-conf and error buffer layout ... */
2360 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2361 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2362 layout.pass_frame_status = 1;
2363 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2364 DPNI_QUEUE_TX_CONFIRM, &layout);
2366 DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
2371 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2373 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
2374 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2375 DPAA2_PMD_INFO("Loopback mode");
2376 } else if (dpaa2_get_devargs(dev->devargs, DRIVER_NO_PREFETCH_MODE)) {
2377 eth_dev->rx_pkt_burst = dpaa2_dev_rx;
2378 DPAA2_PMD_INFO("No Prefetch mode");
2380 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2382 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2384 /*Init fields w.r.t. classficaition*/
2385 memset(&priv->extract.qos_key_cfg, 0, sizeof(struct dpkg_profile_cfg));
2386 priv->extract.qos_extract_param = (size_t)rte_malloc(NULL, 256, 64);
2387 if (!priv->extract.qos_extract_param) {
2388 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow "
2389 " classificaiton ", ret);
2392 for (i = 0; i < MAX_TCS; i++) {
2393 memset(&priv->extract.fs_key_cfg[i], 0,
2394 sizeof(struct dpkg_profile_cfg));
2395 priv->extract.fs_extract_param[i] =
2396 (size_t)rte_malloc(NULL, 256, 64);
2397 if (!priv->extract.fs_extract_param[i]) {
2398 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow classificaiton",
2404 ret = dpni_set_max_frame_length(dpni_dev, CMD_PRI_LOW, priv->token,
2405 RTE_ETHER_MAX_LEN - RTE_ETHER_CRC_LEN
2408 DPAA2_PMD_ERR("Unable to set mtu. check config");
2412 RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
2415 dpaa2_dev_uninit(eth_dev);
2420 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
2422 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2423 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
2426 PMD_INIT_FUNC_TRACE();
2428 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2432 DPAA2_PMD_WARN("Already closed or not started");
2436 dpaa2_dev_close(eth_dev);
2438 dpaa2_free_rx_tx_queues(eth_dev);
2440 /* Close the device at underlying layer*/
2441 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
2444 "Failure closing dpni device with err code %d",
2448 /* Free the allocated memory for ethernet private data and dpni*/
2452 for (i = 0; i < MAX_TCS; i++) {
2453 if (priv->extract.fs_extract_param[i])
2454 rte_free((void *)(size_t)priv->extract.fs_extract_param[i]);
2457 if (priv->extract.qos_extract_param)
2458 rte_free((void *)(size_t)priv->extract.qos_extract_param);
2460 eth_dev->dev_ops = NULL;
2461 eth_dev->rx_pkt_burst = NULL;
2462 eth_dev->tx_pkt_burst = NULL;
2464 DPAA2_PMD_INFO("%s: netdev deleted", eth_dev->data->name);
2469 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
2470 struct rte_dpaa2_device *dpaa2_dev)
2472 struct rte_eth_dev *eth_dev;
2475 if ((DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) >
2476 RTE_PKTMBUF_HEADROOM) {
2478 "RTE_PKTMBUF_HEADROOM(%d) shall be > DPAA2 Annotation req(%d)",
2479 RTE_PKTMBUF_HEADROOM,
2480 DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE);
2485 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2486 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
2489 eth_dev->data->dev_private = rte_zmalloc(
2490 "ethdev private structure",
2491 sizeof(struct dpaa2_dev_priv),
2492 RTE_CACHE_LINE_SIZE);
2493 if (eth_dev->data->dev_private == NULL) {
2495 "Unable to allocate memory for private data");
2496 rte_eth_dev_release_port(eth_dev);
2500 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
2505 eth_dev->device = &dpaa2_dev->device;
2507 dpaa2_dev->eth_dev = eth_dev;
2508 eth_dev->data->rx_mbuf_alloc_failed = 0;
2510 if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
2511 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
2513 /* Invoke PMD device initialization function */
2514 diag = dpaa2_dev_init(eth_dev);
2516 rte_eth_dev_probing_finish(eth_dev);
2520 rte_eth_dev_release_port(eth_dev);
2525 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
2527 struct rte_eth_dev *eth_dev;
2529 eth_dev = dpaa2_dev->eth_dev;
2530 dpaa2_dev_uninit(eth_dev);
2532 rte_eth_dev_release_port(eth_dev);
2537 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
2538 .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
2539 .drv_type = DPAA2_ETH,
2540 .probe = rte_dpaa2_probe,
2541 .remove = rte_dpaa2_remove,
2544 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);
2545 RTE_PMD_REGISTER_PARAM_STRING(net_dpaa2,
2546 DRIVER_LOOPBACK_MODE "=<int> "
2547 DRIVER_NO_PREFETCH_MODE "=<int>");
2548 RTE_INIT(dpaa2_pmd_init_log)
2550 dpaa2_logtype_pmd = rte_log_register("pmd.net.dpaa2");
2551 if (dpaa2_logtype_pmd >= 0)
2552 rte_log_set_level(dpaa2_logtype_pmd, RTE_LOG_NOTICE);