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},
89 static const enum rte_filter_op dpaa2_supported_filter_ops[] = {
91 RTE_ETH_FILTER_DELETE,
92 RTE_ETH_FILTER_UPDATE,
97 static struct rte_dpaa2_driver rte_dpaa2_pmd;
98 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
99 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
100 int wait_to_complete);
101 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
102 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
103 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
105 int dpaa2_logtype_pmd;
108 rte_pmd_dpaa2_set_timestamp(enum pmd_dpaa2_ts enable)
110 dpaa2_enable_ts = enable;
114 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
117 struct dpaa2_dev_priv *priv = dev->data->dev_private;
118 struct fsl_mc_io *dpni = priv->hw;
120 PMD_INIT_FUNC_TRACE();
123 DPAA2_PMD_ERR("dpni is NULL");
128 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW,
129 priv->token, vlan_id);
131 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
132 priv->token, vlan_id);
135 DPAA2_PMD_ERR("ret = %d Unable to add/rem vlan %d hwid =%d",
136 ret, vlan_id, priv->hw_id);
142 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
144 struct dpaa2_dev_priv *priv = dev->data->dev_private;
145 struct fsl_mc_io *dpni = priv->hw;
148 PMD_INIT_FUNC_TRACE();
150 if (mask & ETH_VLAN_FILTER_MASK) {
151 /* VLAN Filter not avaialble */
152 if (!priv->max_vlan_filters) {
153 DPAA2_PMD_INFO("VLAN filter not available");
157 if (dev->data->dev_conf.rxmode.offloads &
158 DEV_RX_OFFLOAD_VLAN_FILTER)
159 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
162 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
165 DPAA2_PMD_INFO("Unable to set vlan filter = %d", ret);
168 if (mask & ETH_VLAN_EXTEND_MASK) {
169 if (dev->data->dev_conf.rxmode.offloads &
170 DEV_RX_OFFLOAD_VLAN_EXTEND)
171 DPAA2_PMD_INFO("VLAN extend offload not supported");
178 dpaa2_vlan_tpid_set(struct rte_eth_dev *dev,
179 enum rte_vlan_type vlan_type __rte_unused,
182 struct dpaa2_dev_priv *priv = dev->data->dev_private;
183 struct fsl_mc_io *dpni = priv->hw;
186 PMD_INIT_FUNC_TRACE();
188 /* nothing to be done for standard vlan tpids */
189 if (tpid == 0x8100 || tpid == 0x88A8)
192 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
195 DPAA2_PMD_INFO("Unable to set vlan tpid = %d", ret);
196 /* if already configured tpids, remove them first */
198 struct dpni_custom_tpid_cfg tpid_list = {0};
200 ret = dpni_get_custom_tpid(dpni, CMD_PRI_LOW,
201 priv->token, &tpid_list);
204 ret = dpni_remove_custom_tpid(dpni, CMD_PRI_LOW,
205 priv->token, tpid_list.tpid1);
208 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
216 dpaa2_fw_version_get(struct rte_eth_dev *dev,
221 struct dpaa2_dev_priv *priv = dev->data->dev_private;
222 struct fsl_mc_io *dpni = priv->hw;
223 struct mc_soc_version mc_plat_info = {0};
224 struct mc_version mc_ver_info = {0};
226 PMD_INIT_FUNC_TRACE();
228 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
229 DPAA2_PMD_WARN("\tmc_get_soc_version failed");
231 if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
232 DPAA2_PMD_WARN("\tmc_get_version failed");
234 ret = snprintf(fw_version, fw_size,
239 mc_ver_info.revision);
241 ret += 1; /* add the size of '\0' */
242 if (fw_size < (uint32_t)ret)
249 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
251 struct dpaa2_dev_priv *priv = dev->data->dev_private;
253 PMD_INIT_FUNC_TRACE();
255 dev_info->if_index = priv->hw_id;
257 dev_info->max_mac_addrs = priv->max_mac_filters;
258 dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
259 dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
260 dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
261 dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
262 dev_info->rx_offload_capa = dev_rx_offloads_sup |
263 dev_rx_offloads_nodis;
264 dev_info->tx_offload_capa = dev_tx_offloads_sup |
265 dev_tx_offloads_nodis;
266 dev_info->speed_capa = ETH_LINK_SPEED_1G |
267 ETH_LINK_SPEED_2_5G |
270 dev_info->max_hash_mac_addrs = 0;
271 dev_info->max_vfs = 0;
272 dev_info->max_vmdq_pools = ETH_16_POOLS;
273 dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
279 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
281 struct dpaa2_dev_priv *priv = dev->data->dev_private;
284 uint8_t num_rxqueue_per_tc;
285 struct dpaa2_queue *mc_q, *mcq;
288 struct dpaa2_queue *dpaa2_q;
290 PMD_INIT_FUNC_TRACE();
292 num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
293 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
294 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
295 RTE_CACHE_LINE_SIZE);
297 DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
301 for (i = 0; i < priv->nb_rx_queues; i++) {
302 mc_q->eth_data = dev->data;
303 priv->rx_vq[i] = mc_q++;
304 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
305 dpaa2_q->q_storage = rte_malloc("dq_storage",
306 sizeof(struct queue_storage_info_t),
307 RTE_CACHE_LINE_SIZE);
308 if (!dpaa2_q->q_storage)
311 memset(dpaa2_q->q_storage, 0,
312 sizeof(struct queue_storage_info_t));
313 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
317 for (i = 0; i < priv->nb_tx_queues; i++) {
318 mc_q->eth_data = dev->data;
319 mc_q->flow_id = 0xffff;
320 priv->tx_vq[i] = mc_q++;
321 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
322 dpaa2_q->cscn = rte_malloc(NULL,
323 sizeof(struct qbman_result), 16);
329 for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
330 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
331 mcq->tc_index = dist_idx / num_rxqueue_per_tc;
332 mcq->flow_id = dist_idx % num_rxqueue_per_tc;
340 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
341 rte_free(dpaa2_q->cscn);
342 priv->tx_vq[i--] = NULL;
344 i = priv->nb_rx_queues;
347 mc_q = priv->rx_vq[0];
349 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
350 dpaa2_free_dq_storage(dpaa2_q->q_storage);
351 rte_free(dpaa2_q->q_storage);
352 priv->rx_vq[i--] = NULL;
359 dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
361 struct dpaa2_dev_priv *priv = dev->data->dev_private;
362 struct dpaa2_queue *dpaa2_q;
365 PMD_INIT_FUNC_TRACE();
367 /* Queue allocation base */
368 if (priv->rx_vq[0]) {
369 /* cleaning up queue storage */
370 for (i = 0; i < priv->nb_rx_queues; i++) {
371 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
372 if (dpaa2_q->q_storage)
373 rte_free(dpaa2_q->q_storage);
375 /* cleanup tx queue cscn */
376 for (i = 0; i < priv->nb_tx_queues; i++) {
377 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
378 rte_free(dpaa2_q->cscn);
380 /*free memory for all queues (RX+TX) */
381 rte_free(priv->rx_vq[0]);
382 priv->rx_vq[0] = NULL;
387 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
389 struct dpaa2_dev_priv *priv = dev->data->dev_private;
390 struct fsl_mc_io *dpni = priv->hw;
391 struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
392 uint64_t rx_offloads = eth_conf->rxmode.offloads;
393 uint64_t tx_offloads = eth_conf->txmode.offloads;
394 int rx_l3_csum_offload = false;
395 int rx_l4_csum_offload = false;
396 int tx_l3_csum_offload = false;
397 int tx_l4_csum_offload = false;
400 PMD_INIT_FUNC_TRACE();
402 /* Rx offloads which are enabled by default */
403 if (dev_rx_offloads_nodis & ~rx_offloads) {
405 "Some of rx offloads enabled by default - requested 0x%" PRIx64
406 " fixed are 0x%" PRIx64,
407 rx_offloads, dev_rx_offloads_nodis);
410 /* Tx offloads which are enabled by default */
411 if (dev_tx_offloads_nodis & ~tx_offloads) {
413 "Some of tx offloads enabled by default - requested 0x%" PRIx64
414 " fixed are 0x%" PRIx64,
415 tx_offloads, dev_tx_offloads_nodis);
418 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
419 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
420 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
421 priv->token, eth_conf->rxmode.max_rx_pkt_len);
424 "Unable to set mtu. check config");
432 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
433 ret = dpaa2_setup_flow_dist(dev,
434 eth_conf->rx_adv_conf.rss_conf.rss_hf);
436 DPAA2_PMD_ERR("Unable to set flow distribution."
437 "Check queue config");
442 if (rx_offloads & DEV_RX_OFFLOAD_IPV4_CKSUM)
443 rx_l3_csum_offload = true;
445 if ((rx_offloads & DEV_RX_OFFLOAD_UDP_CKSUM) ||
446 (rx_offloads & DEV_RX_OFFLOAD_TCP_CKSUM) ||
447 (rx_offloads & DEV_RX_OFFLOAD_SCTP_CKSUM))
448 rx_l4_csum_offload = true;
450 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
451 DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
453 DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
457 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
458 DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
460 DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
464 if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
465 dpaa2_enable_ts = true;
467 if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
468 tx_l3_csum_offload = true;
470 if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ||
471 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
472 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
473 tx_l4_csum_offload = true;
475 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
476 DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
478 DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
482 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
483 DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
485 DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
489 /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
490 * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
491 * to 0 for LS2 in the hardware thus disabling data/annotation
492 * stashing. For LX2 this is fixed in hardware and thus hash result and
493 * parse results can be received in FD using this option.
495 if (dpaa2_svr_family == SVR_LX2160A) {
496 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
497 DPNI_FLCTYPE_HASH, true);
499 DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
504 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
505 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
507 /* update the current status */
508 dpaa2_dev_link_update(dev, 0);
513 /* Function to setup RX flow information. It contains traffic class ID,
514 * flow ID, destination configuration etc.
517 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
518 uint16_t rx_queue_id,
520 unsigned int socket_id __rte_unused,
521 const struct rte_eth_rxconf *rx_conf __rte_unused,
522 struct rte_mempool *mb_pool)
524 struct dpaa2_dev_priv *priv = dev->data->dev_private;
525 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
526 struct dpaa2_queue *dpaa2_q;
527 struct dpni_queue cfg;
533 PMD_INIT_FUNC_TRACE();
535 DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
536 dev, rx_queue_id, mb_pool, rx_conf);
538 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
539 bpid = mempool_to_bpid(mb_pool);
540 ret = dpaa2_attach_bp_list(priv,
541 rte_dpaa2_bpid_info[bpid].bp_list);
545 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
546 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
547 dpaa2_q->bp_array = rte_dpaa2_bpid_info;
549 /*Get the flow id from given VQ id*/
550 flow_id = dpaa2_q->flow_id;
551 memset(&cfg, 0, sizeof(struct dpni_queue));
553 options = options | DPNI_QUEUE_OPT_USER_CTX;
554 cfg.user_context = (size_t)(dpaa2_q);
556 /* check if a private cgr available. */
557 for (i = 0; i < priv->max_cgs; i++) {
558 if (!priv->cgid_in_use[i]) {
559 priv->cgid_in_use[i] = 1;
564 if (i < priv->max_cgs) {
565 options |= DPNI_QUEUE_OPT_SET_CGID;
567 dpaa2_q->cgid = cfg.cgid;
569 dpaa2_q->cgid = 0xff;
572 /*if ls2088 or rev2 device, enable the stashing */
574 if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
575 options |= DPNI_QUEUE_OPT_FLC;
576 cfg.flc.stash_control = true;
577 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
578 /* 00 00 00 - last 6 bit represent annotation, context stashing,
579 * data stashing setting 01 01 00 (0x14)
580 * (in following order ->DS AS CS)
581 * to enable 1 line data, 1 line annotation.
582 * For LX2, this setting should be 01 00 00 (0x10)
584 if ((dpaa2_svr_family & 0xffff0000) == SVR_LX2160A)
585 cfg.flc.value |= 0x10;
587 cfg.flc.value |= 0x14;
589 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
590 dpaa2_q->tc_index, flow_id, options, &cfg);
592 DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
596 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
597 struct dpni_taildrop taildrop;
601 /* Private CGR will use tail drop length as nb_rx_desc.
602 * for rest cases we can use standard byte based tail drop.
603 * There is no HW restriction, but number of CGRs are limited,
604 * hence this restriction is placed.
606 if (dpaa2_q->cgid != 0xff) {
607 /*enabling per rx queue congestion control */
608 taildrop.threshold = nb_rx_desc;
609 taildrop.units = DPNI_CONGESTION_UNIT_FRAMES;
611 DPAA2_PMD_DEBUG("Enabling CG Tail Drop on queue = %d",
613 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
614 DPNI_CP_CONGESTION_GROUP,
619 /*enabling per rx queue congestion control */
620 taildrop.threshold = CONG_THRESHOLD_RX_BYTES_Q;
621 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
622 taildrop.oal = CONG_RX_OAL;
623 DPAA2_PMD_DEBUG("Enabling Byte based Drop on queue= %d",
625 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
626 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
627 dpaa2_q->tc_index, flow_id,
631 DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
635 } else { /* Disable tail Drop */
636 struct dpni_taildrop taildrop = {0};
637 DPAA2_PMD_INFO("Tail drop is disabled on queue");
640 if (dpaa2_q->cgid != 0xff) {
641 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
642 DPNI_CP_CONGESTION_GROUP, DPNI_QUEUE_RX,
646 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
647 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
648 dpaa2_q->tc_index, flow_id, &taildrop);
651 DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
657 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
662 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
663 uint16_t tx_queue_id,
664 uint16_t nb_tx_desc __rte_unused,
665 unsigned int socket_id __rte_unused,
666 const struct rte_eth_txconf *tx_conf __rte_unused)
668 struct dpaa2_dev_priv *priv = dev->data->dev_private;
669 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
670 priv->tx_vq[tx_queue_id];
671 struct fsl_mc_io *dpni = priv->hw;
672 struct dpni_queue tx_conf_cfg;
673 struct dpni_queue tx_flow_cfg;
674 uint8_t options = 0, flow_id;
678 PMD_INIT_FUNC_TRACE();
680 /* Return if queue already configured */
681 if (dpaa2_q->flow_id != 0xffff) {
682 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
686 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
687 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
692 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
693 tc_id, flow_id, options, &tx_flow_cfg);
695 DPAA2_PMD_ERR("Error in setting the tx flow: "
696 "tc_id=%d, flow=%d err=%d",
697 tc_id, flow_id, ret);
701 dpaa2_q->flow_id = flow_id;
703 if (tx_queue_id == 0) {
704 /*Set tx-conf and error configuration*/
705 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
709 DPAA2_PMD_ERR("Error in set tx conf mode settings: "
714 dpaa2_q->tc_index = tc_id;
716 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
717 struct dpni_congestion_notification_cfg cong_notif_cfg = {0};
719 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
720 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
721 /* Notify that the queue is not congested when the data in
722 * the queue is below this thershold.
724 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
725 cong_notif_cfg.message_ctx = 0;
726 cong_notif_cfg.message_iova =
727 (size_t)DPAA2_VADDR_TO_IOVA(dpaa2_q->cscn);
728 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
729 cong_notif_cfg.notification_mode =
730 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
731 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
732 DPNI_CONG_OPT_COHERENT_WRITE;
733 cong_notif_cfg.cg_point = DPNI_CP_QUEUE;
735 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
742 "Error in setting tx congestion notification: "
747 dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
748 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
753 dpaa2_dev_rx_queue_release(void *q __rte_unused)
755 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)q;
756 struct dpaa2_dev_priv *priv = dpaa2_q->eth_data->dev_private;
757 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
760 struct dpni_queue cfg;
762 memset(&cfg, 0, sizeof(struct dpni_queue));
763 PMD_INIT_FUNC_TRACE();
764 if (dpaa2_q->cgid != 0xff) {
765 options = DPNI_QUEUE_OPT_CLEAR_CGID;
766 cfg.cgid = dpaa2_q->cgid;
768 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token,
770 dpaa2_q->tc_index, dpaa2_q->flow_id,
773 DPAA2_PMD_ERR("Unable to clear CGR from q=%u err=%d",
775 priv->cgid_in_use[dpaa2_q->cgid] = 0;
776 dpaa2_q->cgid = 0xff;
781 dpaa2_dev_tx_queue_release(void *q __rte_unused)
783 PMD_INIT_FUNC_TRACE();
787 dpaa2_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
790 struct dpaa2_dev_priv *priv = dev->data->dev_private;
791 struct dpaa2_queue *dpaa2_q;
792 struct qbman_swp *swp;
793 struct qbman_fq_query_np_rslt state;
794 uint32_t frame_cnt = 0;
796 PMD_INIT_FUNC_TRACE();
798 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
799 ret = dpaa2_affine_qbman_swp();
801 DPAA2_PMD_ERR("Failure in affining portal");
805 swp = DPAA2_PER_LCORE_PORTAL;
807 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
809 if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
810 frame_cnt = qbman_fq_state_frame_count(&state);
811 DPAA2_PMD_DEBUG("RX frame count for q(%d) is %u",
812 rx_queue_id, frame_cnt);
817 static const uint32_t *
818 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
820 static const uint32_t ptypes[] = {
821 /*todo -= add more types */
824 RTE_PTYPE_L3_IPV4_EXT,
826 RTE_PTYPE_L3_IPV6_EXT,
834 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
835 dev->rx_pkt_burst == dpaa2_dev_rx ||
836 dev->rx_pkt_burst == dpaa2_dev_loopback_rx)
842 * Dpaa2 link Interrupt handler
845 * The address of parameter (struct rte_eth_dev *) regsitered before.
851 dpaa2_interrupt_handler(void *param)
853 struct rte_eth_dev *dev = param;
854 struct dpaa2_dev_priv *priv = dev->data->dev_private;
855 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
857 int irq_index = DPNI_IRQ_INDEX;
858 unsigned int status = 0, clear = 0;
860 PMD_INIT_FUNC_TRACE();
863 DPAA2_PMD_ERR("dpni is NULL");
867 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
870 DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
875 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
876 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
877 dpaa2_dev_link_update(dev, 0);
878 /* calling all the apps registered for link status event */
879 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
883 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
886 DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
890 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
893 struct dpaa2_dev_priv *priv = dev->data->dev_private;
894 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
895 int irq_index = DPNI_IRQ_INDEX;
896 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
898 PMD_INIT_FUNC_TRACE();
900 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
903 DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
908 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
911 DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
918 dpaa2_dev_start(struct rte_eth_dev *dev)
920 struct rte_device *rdev = dev->device;
921 struct rte_dpaa2_device *dpaa2_dev;
922 struct rte_eth_dev_data *data = dev->data;
923 struct dpaa2_dev_priv *priv = data->dev_private;
924 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
925 struct dpni_queue cfg;
926 struct dpni_error_cfg err_cfg;
928 struct dpni_queue_id qid;
929 struct dpaa2_queue *dpaa2_q;
931 struct rte_intr_handle *intr_handle;
933 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
934 intr_handle = &dpaa2_dev->intr_handle;
936 PMD_INIT_FUNC_TRACE();
938 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
940 DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
945 /* Power up the phy. Needed to make the link go UP */
946 dpaa2_dev_set_link_up(dev);
948 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
949 DPNI_QUEUE_TX, &qdid);
951 DPAA2_PMD_ERR("Error in getting qdid: err=%d", ret);
956 for (i = 0; i < data->nb_rx_queues; i++) {
957 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
958 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
959 DPNI_QUEUE_RX, dpaa2_q->tc_index,
960 dpaa2_q->flow_id, &cfg, &qid);
962 DPAA2_PMD_ERR("Error in getting flow information: "
966 dpaa2_q->fqid = qid.fqid;
969 /*checksum errors, send them to normal path and set it in annotation */
970 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
971 err_cfg.errors |= DPNI_ERROR_PHE;
973 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
974 err_cfg.set_frame_annotation = true;
976 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
977 priv->token, &err_cfg);
979 DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
984 /* if the interrupts were configured on this devices*/
985 if (intr_handle && (intr_handle->fd) &&
986 (dev->data->dev_conf.intr_conf.lsc != 0)) {
987 /* Registering LSC interrupt handler */
988 rte_intr_callback_register(intr_handle,
989 dpaa2_interrupt_handler,
992 /* enable vfio intr/eventfd mapping
993 * Interrupt index 0 is required, so we can not use
996 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
998 /* enable dpni_irqs */
999 dpaa2_eth_setup_irqs(dev, 1);
1002 /* Change the tx burst function if ordered queues are used */
1003 if (priv->en_ordered)
1004 dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
1010 * This routine disables all traffic on the adapter by issuing a
1011 * global reset on the MAC.
1014 dpaa2_dev_stop(struct rte_eth_dev *dev)
1016 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1017 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1019 struct rte_eth_link link;
1020 struct rte_intr_handle *intr_handle = dev->intr_handle;
1022 PMD_INIT_FUNC_TRACE();
1024 /* reset interrupt callback */
1025 if (intr_handle && (intr_handle->fd) &&
1026 (dev->data->dev_conf.intr_conf.lsc != 0)) {
1027 /*disable dpni irqs */
1028 dpaa2_eth_setup_irqs(dev, 0);
1030 /* disable vfio intr before callback unregister */
1031 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
1033 /* Unregistering LSC interrupt handler */
1034 rte_intr_callback_unregister(intr_handle,
1035 dpaa2_interrupt_handler,
1039 dpaa2_dev_set_link_down(dev);
1041 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
1043 DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
1048 /* clear the recorded link status */
1049 memset(&link, 0, sizeof(link));
1050 rte_eth_linkstatus_set(dev, &link);
1054 dpaa2_dev_close(struct rte_eth_dev *dev)
1056 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1057 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1059 struct rte_eth_link link;
1061 PMD_INIT_FUNC_TRACE();
1063 dpaa2_flow_clean(dev);
1065 /* Clean the device first */
1066 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
1068 DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
1072 memset(&link, 0, sizeof(link));
1073 rte_eth_linkstatus_set(dev, &link);
1077 dpaa2_dev_promiscuous_enable(
1078 struct rte_eth_dev *dev)
1081 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1082 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1084 PMD_INIT_FUNC_TRACE();
1087 DPAA2_PMD_ERR("dpni is NULL");
1091 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1093 DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
1095 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1097 DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
1103 dpaa2_dev_promiscuous_disable(
1104 struct rte_eth_dev *dev)
1107 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1108 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1110 PMD_INIT_FUNC_TRACE();
1113 DPAA2_PMD_ERR("dpni is NULL");
1117 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1119 DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
1121 if (dev->data->all_multicast == 0) {
1122 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
1123 priv->token, false);
1125 DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
1133 dpaa2_dev_allmulticast_enable(
1134 struct rte_eth_dev *dev)
1137 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1138 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1140 PMD_INIT_FUNC_TRACE();
1143 DPAA2_PMD_ERR("dpni is NULL");
1147 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1149 DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
1155 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
1158 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1159 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1161 PMD_INIT_FUNC_TRACE();
1164 DPAA2_PMD_ERR("dpni is NULL");
1168 /* must remain on for all promiscuous */
1169 if (dev->data->promiscuous == 1)
1172 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1174 DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
1180 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1183 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1184 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1185 uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
1188 PMD_INIT_FUNC_TRACE();
1191 DPAA2_PMD_ERR("dpni is NULL");
1195 /* check that mtu is within the allowed range */
1196 if (mtu < RTE_ETHER_MIN_MTU || frame_size > DPAA2_MAX_RX_PKT_LEN)
1199 if (frame_size > RTE_ETHER_MAX_LEN)
1200 dev->data->dev_conf.rxmode.offloads &=
1201 DEV_RX_OFFLOAD_JUMBO_FRAME;
1203 dev->data->dev_conf.rxmode.offloads &=
1204 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1206 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1208 /* Set the Max Rx frame length as 'mtu' +
1209 * Maximum Ethernet header length
1211 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
1214 DPAA2_PMD_ERR("Setting the max frame length failed");
1217 DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
1222 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
1223 struct rte_ether_addr *addr,
1224 __rte_unused uint32_t index,
1225 __rte_unused uint32_t pool)
1228 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1229 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1231 PMD_INIT_FUNC_TRACE();
1234 DPAA2_PMD_ERR("dpni is NULL");
1238 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
1239 priv->token, addr->addr_bytes);
1242 "error: Adding the MAC ADDR failed: err = %d", ret);
1247 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1251 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1252 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1253 struct rte_eth_dev_data *data = dev->data;
1254 struct rte_ether_addr *macaddr;
1256 PMD_INIT_FUNC_TRACE();
1258 macaddr = &data->mac_addrs[index];
1261 DPAA2_PMD_ERR("dpni is NULL");
1265 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1266 priv->token, macaddr->addr_bytes);
1269 "error: Removing the MAC ADDR failed: err = %d", ret);
1273 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1274 struct rte_ether_addr *addr)
1277 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1278 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1280 PMD_INIT_FUNC_TRACE();
1283 DPAA2_PMD_ERR("dpni is NULL");
1287 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1288 priv->token, addr->addr_bytes);
1292 "error: Setting the MAC ADDR failed %d", ret);
1298 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1299 struct rte_eth_stats *stats)
1301 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1302 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1304 uint8_t page0 = 0, page1 = 1, page2 = 2;
1305 union dpni_statistics value;
1307 struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
1309 memset(&value, 0, sizeof(union dpni_statistics));
1311 PMD_INIT_FUNC_TRACE();
1314 DPAA2_PMD_ERR("dpni is NULL");
1319 DPAA2_PMD_ERR("stats is NULL");
1323 /*Get Counters from page_0*/
1324 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1329 stats->ipackets = value.page_0.ingress_all_frames;
1330 stats->ibytes = value.page_0.ingress_all_bytes;
1332 /*Get Counters from page_1*/
1333 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1338 stats->opackets = value.page_1.egress_all_frames;
1339 stats->obytes = value.page_1.egress_all_bytes;
1341 /*Get Counters from page_2*/
1342 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1347 /* Ingress drop frame count due to configured rules */
1348 stats->ierrors = value.page_2.ingress_filtered_frames;
1349 /* Ingress drop frame count due to error */
1350 stats->ierrors += value.page_2.ingress_discarded_frames;
1352 stats->oerrors = value.page_2.egress_discarded_frames;
1353 stats->imissed = value.page_2.ingress_nobuffer_discards;
1355 /* Fill in per queue stats */
1356 for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1357 (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
1358 dpaa2_rxq = (struct dpaa2_queue *)priv->rx_vq[i];
1359 dpaa2_txq = (struct dpaa2_queue *)priv->tx_vq[i];
1361 stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
1363 stats->q_opackets[i] = dpaa2_txq->tx_pkts;
1365 /* Byte counting is not implemented */
1366 stats->q_ibytes[i] = 0;
1367 stats->q_obytes[i] = 0;
1373 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1378 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1381 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1382 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1384 union dpni_statistics value[3] = {};
1385 unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1393 /* Get Counters from page_0*/
1394 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1399 /* Get Counters from page_1*/
1400 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1405 /* Get Counters from page_2*/
1406 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1411 for (i = 0; i < num; i++) {
1413 xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1414 raw.counter[dpaa2_xstats_strings[i].stats_id];
1418 DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
1423 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1424 struct rte_eth_xstat_name *xstats_names,
1427 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1429 if (limit < stat_cnt)
1432 if (xstats_names != NULL)
1433 for (i = 0; i < stat_cnt; i++)
1434 strlcpy(xstats_names[i].name,
1435 dpaa2_xstats_strings[i].name,
1436 sizeof(xstats_names[i].name));
1442 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1443 uint64_t *values, unsigned int n)
1445 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1446 uint64_t values_copy[stat_cnt];
1449 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1450 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1452 union dpni_statistics value[3] = {};
1460 /* Get Counters from page_0*/
1461 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1466 /* Get Counters from page_1*/
1467 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1472 /* Get Counters from page_2*/
1473 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1478 for (i = 0; i < stat_cnt; i++) {
1479 values[i] = value[dpaa2_xstats_strings[i].page_id].
1480 raw.counter[dpaa2_xstats_strings[i].stats_id];
1485 dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1487 for (i = 0; i < n; i++) {
1488 if (ids[i] >= stat_cnt) {
1489 DPAA2_PMD_ERR("xstats id value isn't valid");
1492 values[i] = values_copy[ids[i]];
1498 dpaa2_xstats_get_names_by_id(
1499 struct rte_eth_dev *dev,
1500 struct rte_eth_xstat_name *xstats_names,
1501 const uint64_t *ids,
1504 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1505 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1508 return dpaa2_xstats_get_names(dev, xstats_names, limit);
1510 dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1512 for (i = 0; i < limit; i++) {
1513 if (ids[i] >= stat_cnt) {
1514 DPAA2_PMD_ERR("xstats id value isn't valid");
1517 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1523 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1525 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1526 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1529 struct dpaa2_queue *dpaa2_q;
1531 PMD_INIT_FUNC_TRACE();
1534 DPAA2_PMD_ERR("dpni is NULL");
1538 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1542 /* Reset the per queue stats in dpaa2_queue structure */
1543 for (i = 0; i < priv->nb_rx_queues; i++) {
1544 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1546 dpaa2_q->rx_pkts = 0;
1549 for (i = 0; i < priv->nb_tx_queues; i++) {
1550 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
1552 dpaa2_q->tx_pkts = 0;
1558 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1562 /* return 0 means link status changed, -1 means not changed */
1564 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1565 int wait_to_complete __rte_unused)
1568 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1569 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1570 struct rte_eth_link link;
1571 struct dpni_link_state state = {0};
1574 DPAA2_PMD_ERR("dpni is NULL");
1578 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1580 DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
1584 memset(&link, 0, sizeof(struct rte_eth_link));
1585 link.link_status = state.up;
1586 link.link_speed = state.rate;
1588 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1589 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1591 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1593 ret = rte_eth_linkstatus_set(dev, &link);
1595 DPAA2_PMD_DEBUG("No change in status");
1597 DPAA2_PMD_INFO("Port %d Link is %s\n", dev->data->port_id,
1598 link.link_status ? "Up" : "Down");
1604 * Toggle the DPNI to enable, if not already enabled.
1605 * This is not strictly PHY up/down - it is more of logical toggling.
1608 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1611 struct dpaa2_dev_priv *priv;
1612 struct fsl_mc_io *dpni;
1614 struct dpni_link_state state = {0};
1616 priv = dev->data->dev_private;
1617 dpni = (struct fsl_mc_io *)priv->hw;
1620 DPAA2_PMD_ERR("dpni is NULL");
1624 /* Check if DPNI is currently enabled */
1625 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1627 /* Unable to obtain dpni status; Not continuing */
1628 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1632 /* Enable link if not already enabled */
1634 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1636 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1640 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1642 DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
1646 /* changing tx burst function to start enqueues */
1647 dev->tx_pkt_burst = dpaa2_dev_tx;
1648 dev->data->dev_link.link_status = state.up;
1651 DPAA2_PMD_INFO("Port %d Link is Up", dev->data->port_id);
1653 DPAA2_PMD_INFO("Port %d Link is Down", dev->data->port_id);
1658 * Toggle the DPNI to disable, if not already disabled.
1659 * This is not strictly PHY up/down - it is more of logical toggling.
1662 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1665 struct dpaa2_dev_priv *priv;
1666 struct fsl_mc_io *dpni;
1667 int dpni_enabled = 0;
1670 PMD_INIT_FUNC_TRACE();
1672 priv = dev->data->dev_private;
1673 dpni = (struct fsl_mc_io *)priv->hw;
1676 DPAA2_PMD_ERR("Device has not yet been configured");
1680 /*changing tx burst function to avoid any more enqueues */
1681 dev->tx_pkt_burst = dummy_dev_tx;
1683 /* Loop while dpni_disable() attempts to drain the egress FQs
1684 * and confirm them back to us.
1687 ret = dpni_disable(dpni, 0, priv->token);
1689 DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
1692 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1694 DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
1698 /* Allow the MC some slack */
1699 rte_delay_us(100 * 1000);
1700 } while (dpni_enabled && --retries);
1703 DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
1704 /* todo- we may have to manually cleanup queues.
1707 DPAA2_PMD_INFO("Port %d Link DOWN successful",
1708 dev->data->port_id);
1711 dev->data->dev_link.link_status = 0;
1717 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1720 struct dpaa2_dev_priv *priv;
1721 struct fsl_mc_io *dpni;
1722 struct dpni_link_state state = {0};
1724 PMD_INIT_FUNC_TRACE();
1726 priv = dev->data->dev_private;
1727 dpni = (struct fsl_mc_io *)priv->hw;
1729 if (dpni == NULL || fc_conf == NULL) {
1730 DPAA2_PMD_ERR("device not configured");
1734 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1736 DPAA2_PMD_ERR("error: dpni_get_link_state %d", ret);
1740 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1741 if (state.options & DPNI_LINK_OPT_PAUSE) {
1742 /* DPNI_LINK_OPT_PAUSE set
1743 * if ASYM_PAUSE not set,
1744 * RX Side flow control (handle received Pause frame)
1745 * TX side flow control (send Pause frame)
1746 * if ASYM_PAUSE set,
1747 * RX Side flow control (handle received Pause frame)
1748 * No TX side flow control (send Pause frame disabled)
1750 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1751 fc_conf->mode = RTE_FC_FULL;
1753 fc_conf->mode = RTE_FC_RX_PAUSE;
1755 /* DPNI_LINK_OPT_PAUSE not set
1756 * if ASYM_PAUSE set,
1757 * TX side flow control (send Pause frame)
1758 * No RX side flow control (No action on pause frame rx)
1759 * if ASYM_PAUSE not set,
1760 * Flow control disabled
1762 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1763 fc_conf->mode = RTE_FC_TX_PAUSE;
1765 fc_conf->mode = RTE_FC_NONE;
1772 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1775 struct dpaa2_dev_priv *priv;
1776 struct fsl_mc_io *dpni;
1777 struct dpni_link_state state = {0};
1778 struct dpni_link_cfg cfg = {0};
1780 PMD_INIT_FUNC_TRACE();
1782 priv = dev->data->dev_private;
1783 dpni = (struct fsl_mc_io *)priv->hw;
1786 DPAA2_PMD_ERR("dpni is NULL");
1790 /* It is necessary to obtain the current state before setting fc_conf
1791 * as MC would return error in case rate, autoneg or duplex values are
1794 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1796 DPAA2_PMD_ERR("Unable to get link state (err=%d)", ret);
1800 /* Disable link before setting configuration */
1801 dpaa2_dev_set_link_down(dev);
1803 /* Based on fc_conf, update cfg */
1804 cfg.rate = state.rate;
1805 cfg.options = state.options;
1807 /* update cfg with fc_conf */
1808 switch (fc_conf->mode) {
1810 /* Full flow control;
1811 * OPT_PAUSE set, ASYM_PAUSE not set
1813 cfg.options |= DPNI_LINK_OPT_PAUSE;
1814 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1816 case RTE_FC_TX_PAUSE:
1817 /* Enable RX flow control
1818 * OPT_PAUSE not set;
1821 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1822 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1824 case RTE_FC_RX_PAUSE:
1825 /* Enable TX Flow control
1829 cfg.options |= DPNI_LINK_OPT_PAUSE;
1830 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1833 /* Disable Flow control
1835 * ASYM_PAUSE not set
1837 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1838 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1841 DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
1846 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1848 DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
1852 dpaa2_dev_set_link_up(dev);
1858 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
1859 struct rte_eth_rss_conf *rss_conf)
1861 struct rte_eth_dev_data *data = dev->data;
1862 struct rte_eth_conf *eth_conf = &data->dev_conf;
1865 PMD_INIT_FUNC_TRACE();
1867 if (rss_conf->rss_hf) {
1868 ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf);
1870 DPAA2_PMD_ERR("Unable to set flow dist");
1874 ret = dpaa2_remove_flow_dist(dev, 0);
1876 DPAA2_PMD_ERR("Unable to remove flow dist");
1880 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1885 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1886 struct rte_eth_rss_conf *rss_conf)
1888 struct rte_eth_dev_data *data = dev->data;
1889 struct rte_eth_conf *eth_conf = &data->dev_conf;
1891 /* dpaa2 does not support rss_key, so length should be 0*/
1892 rss_conf->rss_key_len = 0;
1893 rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1897 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
1898 int eth_rx_queue_id,
1900 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1902 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1903 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1904 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1905 uint8_t flow_id = dpaa2_ethq->flow_id;
1906 struct dpni_queue cfg;
1910 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
1911 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
1912 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
1913 dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
1914 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
1915 dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
1919 memset(&cfg, 0, sizeof(struct dpni_queue));
1920 options = DPNI_QUEUE_OPT_DEST;
1921 cfg.destination.type = DPNI_DEST_DPCON;
1922 cfg.destination.id = dpcon_id;
1923 cfg.destination.priority = queue_conf->ev.priority;
1925 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
1926 options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
1927 cfg.destination.hold_active = 1;
1930 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
1931 !eth_priv->en_ordered) {
1932 struct opr_cfg ocfg;
1934 /* Restoration window size = 256 frames */
1936 /* Restoration window size = 512 frames for LX2 */
1937 if (dpaa2_svr_family == SVR_LX2160A)
1939 /* Auto advance NESN window enabled */
1941 /* Late arrival window size disabled */
1943 /* ORL resource exhaustaion advance NESN disabled */
1945 /* Loose ordering enabled */
1947 eth_priv->en_loose_ordered = 1;
1948 /* Strict ordering enabled if explicitly set */
1949 if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
1951 eth_priv->en_loose_ordered = 0;
1954 ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
1955 dpaa2_ethq->tc_index, flow_id,
1956 OPR_OPT_CREATE, &ocfg);
1958 DPAA2_PMD_ERR("Error setting opr: ret: %d\n", ret);
1962 eth_priv->en_ordered = 1;
1965 options |= DPNI_QUEUE_OPT_USER_CTX;
1966 cfg.user_context = (size_t)(dpaa2_ethq);
1968 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1969 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1971 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1975 memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
1980 int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
1981 int eth_rx_queue_id)
1983 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1984 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1985 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1986 uint8_t flow_id = dpaa2_ethq->flow_id;
1987 struct dpni_queue cfg;
1991 memset(&cfg, 0, sizeof(struct dpni_queue));
1992 options = DPNI_QUEUE_OPT_DEST;
1993 cfg.destination.type = DPNI_DEST_NONE;
1995 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1996 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1998 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
2004 dpaa2_dev_verify_filter_ops(enum rte_filter_op filter_op)
2008 for (i = 0; i < RTE_DIM(dpaa2_supported_filter_ops); i++) {
2009 if (dpaa2_supported_filter_ops[i] == filter_op)
2016 dpaa2_dev_flow_ctrl(struct rte_eth_dev *dev,
2017 enum rte_filter_type filter_type,
2018 enum rte_filter_op filter_op,
2026 switch (filter_type) {
2027 case RTE_ETH_FILTER_GENERIC:
2028 if (dpaa2_dev_verify_filter_ops(filter_op) < 0) {
2032 *(const void **)arg = &dpaa2_flow_ops;
2033 dpaa2_filter_type |= filter_type;
2036 RTE_LOG(ERR, PMD, "Filter type (%d) not supported",
2044 static struct eth_dev_ops dpaa2_ethdev_ops = {
2045 .dev_configure = dpaa2_eth_dev_configure,
2046 .dev_start = dpaa2_dev_start,
2047 .dev_stop = dpaa2_dev_stop,
2048 .dev_close = dpaa2_dev_close,
2049 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
2050 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
2051 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
2052 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
2053 .dev_set_link_up = dpaa2_dev_set_link_up,
2054 .dev_set_link_down = dpaa2_dev_set_link_down,
2055 .link_update = dpaa2_dev_link_update,
2056 .stats_get = dpaa2_dev_stats_get,
2057 .xstats_get = dpaa2_dev_xstats_get,
2058 .xstats_get_by_id = dpaa2_xstats_get_by_id,
2059 .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
2060 .xstats_get_names = dpaa2_xstats_get_names,
2061 .stats_reset = dpaa2_dev_stats_reset,
2062 .xstats_reset = dpaa2_dev_stats_reset,
2063 .fw_version_get = dpaa2_fw_version_get,
2064 .dev_infos_get = dpaa2_dev_info_get,
2065 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
2066 .mtu_set = dpaa2_dev_mtu_set,
2067 .vlan_filter_set = dpaa2_vlan_filter_set,
2068 .vlan_offload_set = dpaa2_vlan_offload_set,
2069 .vlan_tpid_set = dpaa2_vlan_tpid_set,
2070 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
2071 .rx_queue_release = dpaa2_dev_rx_queue_release,
2072 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
2073 .tx_queue_release = dpaa2_dev_tx_queue_release,
2074 .rx_queue_count = dpaa2_dev_rx_queue_count,
2075 .flow_ctrl_get = dpaa2_flow_ctrl_get,
2076 .flow_ctrl_set = dpaa2_flow_ctrl_set,
2077 .mac_addr_add = dpaa2_dev_add_mac_addr,
2078 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
2079 .mac_addr_set = dpaa2_dev_set_mac_addr,
2080 .rss_hash_update = dpaa2_dev_rss_hash_update,
2081 .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get,
2082 .filter_ctrl = dpaa2_dev_flow_ctrl,
2085 /* Populate the mac address from physically available (u-boot/firmware) and/or
2086 * one set by higher layers like MC (restool) etc.
2087 * Returns the table of MAC entries (multiple entries)
2090 populate_mac_addr(struct fsl_mc_io *dpni_dev, struct dpaa2_dev_priv *priv,
2091 struct rte_ether_addr *mac_entry)
2094 struct rte_ether_addr phy_mac, prime_mac;
2096 memset(&phy_mac, 0, sizeof(struct rte_ether_addr));
2097 memset(&prime_mac, 0, sizeof(struct rte_ether_addr));
2099 /* Get the physical device MAC address */
2100 ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2101 phy_mac.addr_bytes);
2103 DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
2107 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2108 prime_mac.addr_bytes);
2110 DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
2114 /* Now that both MAC have been obtained, do:
2115 * if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
2117 * If empty_mac(phy), return prime.
2118 * if both are empty, create random MAC, set as prime and return
2120 if (!rte_is_zero_ether_addr(&phy_mac)) {
2121 /* If the addresses are not same, overwrite prime */
2122 if (!rte_is_same_ether_addr(&phy_mac, &prime_mac)) {
2123 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2125 phy_mac.addr_bytes);
2127 DPAA2_PMD_ERR("Unable to set MAC Address: %d",
2131 memcpy(&prime_mac, &phy_mac,
2132 sizeof(struct rte_ether_addr));
2134 } else if (rte_is_zero_ether_addr(&prime_mac)) {
2135 /* In case phys and prime, both are zero, create random MAC */
2136 rte_eth_random_addr(prime_mac.addr_bytes);
2137 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2139 prime_mac.addr_bytes);
2141 DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
2146 /* prime_mac the final MAC address */
2147 memcpy(mac_entry, &prime_mac, sizeof(struct rte_ether_addr));
2155 check_devargs_handler(__rte_unused const char *key, const char *value,
2156 __rte_unused void *opaque)
2158 if (strcmp(value, "1"))
2165 dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
2167 struct rte_kvargs *kvlist;
2172 kvlist = rte_kvargs_parse(devargs->args, NULL);
2176 if (!rte_kvargs_count(kvlist, key)) {
2177 rte_kvargs_free(kvlist);
2181 if (rte_kvargs_process(kvlist, key,
2182 check_devargs_handler, NULL) < 0) {
2183 rte_kvargs_free(kvlist);
2186 rte_kvargs_free(kvlist);
2192 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
2194 struct rte_device *dev = eth_dev->device;
2195 struct rte_dpaa2_device *dpaa2_dev;
2196 struct fsl_mc_io *dpni_dev;
2197 struct dpni_attr attr;
2198 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2199 struct dpni_buffer_layout layout;
2202 PMD_INIT_FUNC_TRACE();
2204 /* For secondary processes, the primary has done all the work */
2205 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2206 /* In case of secondary, only burst and ops API need to be
2209 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2210 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
2211 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2212 else if (dpaa2_get_devargs(dev->devargs,
2213 DRIVER_NO_PREFETCH_MODE))
2214 eth_dev->rx_pkt_burst = dpaa2_dev_rx;
2216 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2217 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2221 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2223 hw_id = dpaa2_dev->object_id;
2225 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
2227 DPAA2_PMD_ERR("Memory allocation failed for dpni device");
2231 dpni_dev->regs = rte_mcp_ptr_list[0];
2232 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
2235 "Failure in opening dpni@%d with err code %d",
2241 /* Clean the device first */
2242 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
2244 DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
2249 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
2252 "Failure in get dpni@%d attribute, err code %d",
2257 priv->num_rx_tc = attr.num_rx_tcs;
2258 /* only if the custom CG is enabled */
2259 if (attr.options & DPNI_OPT_CUSTOM_CG)
2260 priv->max_cgs = attr.num_cgs;
2264 for (i = 0; i < priv->max_cgs; i++)
2265 priv->cgid_in_use[i] = 0;
2267 for (i = 0; i < attr.num_rx_tcs; i++)
2268 priv->nb_rx_queues += attr.num_queues;
2270 /* Using number of TX queues as number of TX TCs */
2271 priv->nb_tx_queues = attr.num_tx_tcs;
2273 DPAA2_PMD_DEBUG("RX-TC= %d, rx_queues= %d, tx_queues=%d, max_cgs=%d",
2274 priv->num_rx_tc, priv->nb_rx_queues,
2275 priv->nb_tx_queues, priv->max_cgs);
2277 priv->hw = dpni_dev;
2278 priv->hw_id = hw_id;
2279 priv->options = attr.options;
2280 priv->max_mac_filters = attr.mac_filter_entries;
2281 priv->max_vlan_filters = attr.vlan_filter_entries;
2284 /* Allocate memory for hardware structure for queues */
2285 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
2287 DPAA2_PMD_ERR("Queue allocation Failed");
2291 /* Allocate memory for storing MAC addresses.
2292 * Table of mac_filter_entries size is allocated so that RTE ether lib
2293 * can add MAC entries when rte_eth_dev_mac_addr_add is called.
2295 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
2296 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
2297 if (eth_dev->data->mac_addrs == NULL) {
2299 "Failed to allocate %d bytes needed to store MAC addresses",
2300 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries);
2305 ret = populate_mac_addr(dpni_dev, priv, ð_dev->data->mac_addrs[0]);
2307 DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
2308 rte_free(eth_dev->data->mac_addrs);
2309 eth_dev->data->mac_addrs = NULL;
2313 /* ... tx buffer layout ... */
2314 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2315 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2316 layout.pass_frame_status = 1;
2317 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2318 DPNI_QUEUE_TX, &layout);
2320 DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
2324 /* ... tx-conf and error buffer layout ... */
2325 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2326 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2327 layout.pass_frame_status = 1;
2328 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2329 DPNI_QUEUE_TX_CONFIRM, &layout);
2331 DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
2336 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2338 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
2339 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2340 DPAA2_PMD_INFO("Loopback mode");
2341 } else if (dpaa2_get_devargs(dev->devargs, DRIVER_NO_PREFETCH_MODE)) {
2342 eth_dev->rx_pkt_burst = dpaa2_dev_rx;
2343 DPAA2_PMD_INFO("No Prefetch mode");
2345 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2347 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2349 /*Init fields w.r.t. classficaition*/
2350 memset(&priv->extract.qos_key_cfg, 0, sizeof(struct dpkg_profile_cfg));
2351 priv->extract.qos_extract_param = (size_t)rte_malloc(NULL, 256, 64);
2352 if (!priv->extract.qos_extract_param) {
2353 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow "
2354 " classificaiton ", ret);
2357 for (i = 0; i < MAX_TCS; i++) {
2358 memset(&priv->extract.fs_key_cfg[i], 0,
2359 sizeof(struct dpkg_profile_cfg));
2360 priv->extract.fs_extract_param[i] =
2361 (size_t)rte_malloc(NULL, 256, 64);
2362 if (!priv->extract.fs_extract_param[i]) {
2363 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow classificaiton",
2369 RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
2372 dpaa2_dev_uninit(eth_dev);
2377 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
2379 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2380 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
2383 PMD_INIT_FUNC_TRACE();
2385 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2389 DPAA2_PMD_WARN("Already closed or not started");
2393 dpaa2_dev_close(eth_dev);
2395 dpaa2_free_rx_tx_queues(eth_dev);
2397 /* Close the device at underlying layer*/
2398 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
2401 "Failure closing dpni device with err code %d",
2405 /* Free the allocated memory for ethernet private data and dpni*/
2409 for (i = 0; i < MAX_TCS; i++) {
2410 if (priv->extract.fs_extract_param[i])
2411 rte_free((void *)(size_t)priv->extract.fs_extract_param[i]);
2414 if (priv->extract.qos_extract_param)
2415 rte_free((void *)(size_t)priv->extract.qos_extract_param);
2417 eth_dev->dev_ops = NULL;
2418 eth_dev->rx_pkt_burst = NULL;
2419 eth_dev->tx_pkt_burst = NULL;
2421 DPAA2_PMD_INFO("%s: netdev deleted", eth_dev->data->name);
2426 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
2427 struct rte_dpaa2_device *dpaa2_dev)
2429 struct rte_eth_dev *eth_dev;
2432 if ((DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) >
2433 RTE_PKTMBUF_HEADROOM) {
2435 "RTE_PKTMBUF_HEADROOM(%d) shall be > DPAA2 Annotation req(%d)",
2436 RTE_PKTMBUF_HEADROOM,
2437 DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE);
2442 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2443 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
2446 eth_dev->data->dev_private = rte_zmalloc(
2447 "ethdev private structure",
2448 sizeof(struct dpaa2_dev_priv),
2449 RTE_CACHE_LINE_SIZE);
2450 if (eth_dev->data->dev_private == NULL) {
2452 "Unable to allocate memory for private data");
2453 rte_eth_dev_release_port(eth_dev);
2457 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
2462 eth_dev->device = &dpaa2_dev->device;
2464 dpaa2_dev->eth_dev = eth_dev;
2465 eth_dev->data->rx_mbuf_alloc_failed = 0;
2467 if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
2468 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
2470 /* Invoke PMD device initialization function */
2471 diag = dpaa2_dev_init(eth_dev);
2473 rte_eth_dev_probing_finish(eth_dev);
2477 rte_eth_dev_release_port(eth_dev);
2482 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
2484 struct rte_eth_dev *eth_dev;
2486 eth_dev = dpaa2_dev->eth_dev;
2487 dpaa2_dev_uninit(eth_dev);
2489 rte_eth_dev_release_port(eth_dev);
2494 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
2495 .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
2496 .drv_type = DPAA2_ETH,
2497 .probe = rte_dpaa2_probe,
2498 .remove = rte_dpaa2_remove,
2501 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);
2502 RTE_PMD_REGISTER_PARAM_STRING(net_dpaa2,
2503 DRIVER_LOOPBACK_MODE "=<int> "
2504 DRIVER_NO_PREFETCH_MODE "=<int>");
2505 RTE_INIT(dpaa2_pmd_init_log)
2507 dpaa2_logtype_pmd = rte_log_register("pmd.net.dpaa2");
2508 if (dpaa2_logtype_pmd >= 0)
2509 rte_log_set_level(dpaa2_logtype_pmd, RTE_LOG_NOTICE);