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"
33 /* Supported Rx offloads */
34 static uint64_t dev_rx_offloads_sup =
35 DEV_RX_OFFLOAD_CHECKSUM |
36 DEV_RX_OFFLOAD_SCTP_CKSUM |
37 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
38 DEV_RX_OFFLOAD_OUTER_UDP_CKSUM |
39 DEV_RX_OFFLOAD_VLAN_STRIP |
40 DEV_RX_OFFLOAD_VLAN_FILTER |
41 DEV_RX_OFFLOAD_JUMBO_FRAME |
42 DEV_RX_OFFLOAD_TIMESTAMP;
44 /* Rx offloads which cannot be disabled */
45 static uint64_t dev_rx_offloads_nodis =
46 DEV_RX_OFFLOAD_SCATTER;
48 /* Supported Tx offloads */
49 static uint64_t dev_tx_offloads_sup =
50 DEV_TX_OFFLOAD_VLAN_INSERT |
51 DEV_TX_OFFLOAD_IPV4_CKSUM |
52 DEV_TX_OFFLOAD_UDP_CKSUM |
53 DEV_TX_OFFLOAD_TCP_CKSUM |
54 DEV_TX_OFFLOAD_SCTP_CKSUM |
55 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
56 DEV_TX_OFFLOAD_MT_LOCKFREE |
57 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
59 /* Tx offloads which cannot be disabled */
60 static uint64_t dev_tx_offloads_nodis =
61 DEV_TX_OFFLOAD_MULTI_SEGS;
63 /* enable timestamp in mbuf */
64 enum pmd_dpaa2_ts dpaa2_enable_ts;
66 struct rte_dpaa2_xstats_name_off {
67 char name[RTE_ETH_XSTATS_NAME_SIZE];
68 uint8_t page_id; /* dpni statistics page id */
69 uint8_t stats_id; /* stats id in the given page */
72 static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
73 {"ingress_multicast_frames", 0, 2},
74 {"ingress_multicast_bytes", 0, 3},
75 {"ingress_broadcast_frames", 0, 4},
76 {"ingress_broadcast_bytes", 0, 5},
77 {"egress_multicast_frames", 1, 2},
78 {"egress_multicast_bytes", 1, 3},
79 {"egress_broadcast_frames", 1, 4},
80 {"egress_broadcast_bytes", 1, 5},
81 {"ingress_filtered_frames", 2, 0},
82 {"ingress_discarded_frames", 2, 1},
83 {"ingress_nobuffer_discards", 2, 2},
84 {"egress_discarded_frames", 2, 3},
85 {"egress_confirmed_frames", 2, 4},
88 static const enum rte_filter_op dpaa2_supported_filter_ops[] = {
90 RTE_ETH_FILTER_DELETE,
91 RTE_ETH_FILTER_UPDATE,
96 static struct rte_dpaa2_driver rte_dpaa2_pmd;
97 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
98 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
99 int wait_to_complete);
100 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
101 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
102 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
104 int dpaa2_logtype_pmd;
107 rte_pmd_dpaa2_set_timestamp(enum pmd_dpaa2_ts enable)
109 dpaa2_enable_ts = enable;
113 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
116 struct dpaa2_dev_priv *priv = dev->data->dev_private;
117 struct fsl_mc_io *dpni = priv->hw;
119 PMD_INIT_FUNC_TRACE();
122 DPAA2_PMD_ERR("dpni is NULL");
127 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW,
128 priv->token, vlan_id);
130 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
131 priv->token, vlan_id);
134 DPAA2_PMD_ERR("ret = %d Unable to add/rem vlan %d hwid =%d",
135 ret, vlan_id, priv->hw_id);
141 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
143 struct dpaa2_dev_priv *priv = dev->data->dev_private;
144 struct fsl_mc_io *dpni = priv->hw;
147 PMD_INIT_FUNC_TRACE();
149 if (mask & ETH_VLAN_FILTER_MASK) {
150 /* VLAN Filter not avaialble */
151 if (!priv->max_vlan_filters) {
152 DPAA2_PMD_INFO("VLAN filter not available");
156 if (dev->data->dev_conf.rxmode.offloads &
157 DEV_RX_OFFLOAD_VLAN_FILTER)
158 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
161 ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
164 DPAA2_PMD_INFO("Unable to set vlan filter = %d", ret);
167 if (mask & ETH_VLAN_EXTEND_MASK) {
168 if (dev->data->dev_conf.rxmode.offloads &
169 DEV_RX_OFFLOAD_VLAN_EXTEND)
170 DPAA2_PMD_INFO("VLAN extend offload not supported");
177 dpaa2_vlan_tpid_set(struct rte_eth_dev *dev,
178 enum rte_vlan_type vlan_type __rte_unused,
181 struct dpaa2_dev_priv *priv = dev->data->dev_private;
182 struct fsl_mc_io *dpni = priv->hw;
185 PMD_INIT_FUNC_TRACE();
187 /* nothing to be done for standard vlan tpids */
188 if (tpid == 0x8100 || tpid == 0x88A8)
191 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
194 DPAA2_PMD_INFO("Unable to set vlan tpid = %d", ret);
195 /* if already configured tpids, remove them first */
197 struct dpni_custom_tpid_cfg tpid_list = {0};
199 ret = dpni_get_custom_tpid(dpni, CMD_PRI_LOW,
200 priv->token, &tpid_list);
203 ret = dpni_remove_custom_tpid(dpni, CMD_PRI_LOW,
204 priv->token, tpid_list.tpid1);
207 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
215 dpaa2_fw_version_get(struct rte_eth_dev *dev,
220 struct dpaa2_dev_priv *priv = dev->data->dev_private;
221 struct fsl_mc_io *dpni = priv->hw;
222 struct mc_soc_version mc_plat_info = {0};
223 struct mc_version mc_ver_info = {0};
225 PMD_INIT_FUNC_TRACE();
227 if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
228 DPAA2_PMD_WARN("\tmc_get_soc_version failed");
230 if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
231 DPAA2_PMD_WARN("\tmc_get_version failed");
233 ret = snprintf(fw_version, fw_size,
238 mc_ver_info.revision);
240 ret += 1; /* add the size of '\0' */
241 if (fw_size < (uint32_t)ret)
248 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
250 struct dpaa2_dev_priv *priv = dev->data->dev_private;
252 PMD_INIT_FUNC_TRACE();
254 dev_info->if_index = priv->hw_id;
256 dev_info->max_mac_addrs = priv->max_mac_filters;
257 dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
258 dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
259 dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
260 dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
261 dev_info->rx_offload_capa = dev_rx_offloads_sup |
262 dev_rx_offloads_nodis;
263 dev_info->tx_offload_capa = dev_tx_offloads_sup |
264 dev_tx_offloads_nodis;
265 dev_info->speed_capa = ETH_LINK_SPEED_1G |
266 ETH_LINK_SPEED_2_5G |
269 dev_info->max_hash_mac_addrs = 0;
270 dev_info->max_vfs = 0;
271 dev_info->max_vmdq_pools = ETH_16_POOLS;
272 dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
278 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
280 struct dpaa2_dev_priv *priv = dev->data->dev_private;
283 uint8_t num_rxqueue_per_tc;
284 struct dpaa2_queue *mc_q, *mcq;
287 struct dpaa2_queue *dpaa2_q;
289 PMD_INIT_FUNC_TRACE();
291 num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
292 tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
293 mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
294 RTE_CACHE_LINE_SIZE);
296 DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
300 for (i = 0; i < priv->nb_rx_queues; i++) {
301 mc_q->eth_data = dev->data;
302 priv->rx_vq[i] = mc_q++;
303 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
304 dpaa2_q->q_storage = rte_malloc("dq_storage",
305 sizeof(struct queue_storage_info_t),
306 RTE_CACHE_LINE_SIZE);
307 if (!dpaa2_q->q_storage)
310 memset(dpaa2_q->q_storage, 0,
311 sizeof(struct queue_storage_info_t));
312 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
316 for (i = 0; i < priv->nb_tx_queues; i++) {
317 mc_q->eth_data = dev->data;
318 mc_q->flow_id = 0xffff;
319 priv->tx_vq[i] = mc_q++;
320 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
321 dpaa2_q->cscn = rte_malloc(NULL,
322 sizeof(struct qbman_result), 16);
328 for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
329 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
330 mcq->tc_index = dist_idx / num_rxqueue_per_tc;
331 mcq->flow_id = dist_idx % num_rxqueue_per_tc;
339 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
340 rte_free(dpaa2_q->cscn);
341 priv->tx_vq[i--] = NULL;
343 i = priv->nb_rx_queues;
346 mc_q = priv->rx_vq[0];
348 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
349 dpaa2_free_dq_storage(dpaa2_q->q_storage);
350 rte_free(dpaa2_q->q_storage);
351 priv->rx_vq[i--] = NULL;
358 dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
360 struct dpaa2_dev_priv *priv = dev->data->dev_private;
361 struct dpaa2_queue *dpaa2_q;
364 PMD_INIT_FUNC_TRACE();
366 /* Queue allocation base */
367 if (priv->rx_vq[0]) {
368 /* cleaning up queue storage */
369 for (i = 0; i < priv->nb_rx_queues; i++) {
370 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
371 if (dpaa2_q->q_storage)
372 rte_free(dpaa2_q->q_storage);
374 /* cleanup tx queue cscn */
375 for (i = 0; i < priv->nb_tx_queues; i++) {
376 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
377 rte_free(dpaa2_q->cscn);
379 /*free memory for all queues (RX+TX) */
380 rte_free(priv->rx_vq[0]);
381 priv->rx_vq[0] = NULL;
386 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
388 struct dpaa2_dev_priv *priv = dev->data->dev_private;
389 struct fsl_mc_io *dpni = priv->hw;
390 struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
391 uint64_t rx_offloads = eth_conf->rxmode.offloads;
392 uint64_t tx_offloads = eth_conf->txmode.offloads;
393 int rx_l3_csum_offload = false;
394 int rx_l4_csum_offload = false;
395 int tx_l3_csum_offload = false;
396 int tx_l4_csum_offload = false;
399 PMD_INIT_FUNC_TRACE();
401 /* Rx offloads which are enabled by default */
402 if (dev_rx_offloads_nodis & ~rx_offloads) {
404 "Some of rx offloads enabled by default - requested 0x%" PRIx64
405 " fixed are 0x%" PRIx64,
406 rx_offloads, dev_rx_offloads_nodis);
409 /* Tx offloads which are enabled by default */
410 if (dev_tx_offloads_nodis & ~tx_offloads) {
412 "Some of tx offloads enabled by default - requested 0x%" PRIx64
413 " fixed are 0x%" PRIx64,
414 tx_offloads, dev_tx_offloads_nodis);
417 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
418 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
419 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
420 priv->token, eth_conf->rxmode.max_rx_pkt_len);
423 "Unable to set mtu. check config");
431 if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
432 ret = dpaa2_setup_flow_dist(dev,
433 eth_conf->rx_adv_conf.rss_conf.rss_hf);
435 DPAA2_PMD_ERR("Unable to set flow distribution."
436 "Check queue config");
441 if (rx_offloads & DEV_RX_OFFLOAD_IPV4_CKSUM)
442 rx_l3_csum_offload = true;
444 if ((rx_offloads & DEV_RX_OFFLOAD_UDP_CKSUM) ||
445 (rx_offloads & DEV_RX_OFFLOAD_TCP_CKSUM) ||
446 (rx_offloads & DEV_RX_OFFLOAD_SCTP_CKSUM))
447 rx_l4_csum_offload = true;
449 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
450 DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
452 DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
456 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
457 DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
459 DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
463 if (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP)
464 dpaa2_enable_ts = true;
466 if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
467 tx_l3_csum_offload = true;
469 if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ||
470 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
471 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
472 tx_l4_csum_offload = true;
474 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
475 DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
477 DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
481 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
482 DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
484 DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
488 /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
489 * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
490 * to 0 for LS2 in the hardware thus disabling data/annotation
491 * stashing. For LX2 this is fixed in hardware and thus hash result and
492 * parse results can be received in FD using this option.
494 if (dpaa2_svr_family == SVR_LX2160A) {
495 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
496 DPNI_FLCTYPE_HASH, true);
498 DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
503 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
504 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
506 /* update the current status */
507 dpaa2_dev_link_update(dev, 0);
512 /* Function to setup RX flow information. It contains traffic class ID,
513 * flow ID, destination configuration etc.
516 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
517 uint16_t rx_queue_id,
518 uint16_t nb_rx_desc __rte_unused,
519 unsigned int socket_id __rte_unused,
520 const struct rte_eth_rxconf *rx_conf __rte_unused,
521 struct rte_mempool *mb_pool)
523 struct dpaa2_dev_priv *priv = dev->data->dev_private;
524 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
525 struct dpaa2_queue *dpaa2_q;
526 struct dpni_queue cfg;
532 PMD_INIT_FUNC_TRACE();
534 DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
535 dev, rx_queue_id, mb_pool, rx_conf);
537 if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
538 bpid = mempool_to_bpid(mb_pool);
539 ret = dpaa2_attach_bp_list(priv,
540 rte_dpaa2_bpid_info[bpid].bp_list);
544 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
545 dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
546 dpaa2_q->bp_array = rte_dpaa2_bpid_info;
548 /*Get the flow id from given VQ id*/
549 flow_id = rx_queue_id % priv->nb_rx_queues;
550 memset(&cfg, 0, sizeof(struct dpni_queue));
552 options = options | DPNI_QUEUE_OPT_USER_CTX;
553 cfg.user_context = (size_t)(dpaa2_q);
555 /*if ls2088 or rev2 device, enable the stashing */
557 if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
558 options |= DPNI_QUEUE_OPT_FLC;
559 cfg.flc.stash_control = true;
560 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
561 /* 00 00 00 - last 6 bit represent annotation, context stashing,
562 * data stashing setting 01 01 00 (0x14)
563 * (in following order ->DS AS CS)
564 * to enable 1 line data, 1 line annotation.
565 * For LX2, this setting should be 01 00 00 (0x10)
567 if ((dpaa2_svr_family & 0xffff0000) == SVR_LX2160A)
568 cfg.flc.value |= 0x10;
570 cfg.flc.value |= 0x14;
572 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
573 dpaa2_q->tc_index, flow_id, options, &cfg);
575 DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
579 if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
580 struct dpni_taildrop taildrop;
583 /*enabling per rx queue congestion control */
584 taildrop.threshold = CONG_THRESHOLD_RX_Q;
585 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
586 taildrop.oal = CONG_RX_OAL;
587 DPAA2_PMD_DEBUG("Enabling Early Drop on queue = %d",
589 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
590 DPNI_CP_QUEUE, DPNI_QUEUE_RX,
591 dpaa2_q->tc_index, flow_id, &taildrop);
593 DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
599 dev->data->rx_queues[rx_queue_id] = dpaa2_q;
604 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
605 uint16_t tx_queue_id,
606 uint16_t nb_tx_desc __rte_unused,
607 unsigned int socket_id __rte_unused,
608 const struct rte_eth_txconf *tx_conf __rte_unused)
610 struct dpaa2_dev_priv *priv = dev->data->dev_private;
611 struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
612 priv->tx_vq[tx_queue_id];
613 struct fsl_mc_io *dpni = priv->hw;
614 struct dpni_queue tx_conf_cfg;
615 struct dpni_queue tx_flow_cfg;
616 uint8_t options = 0, flow_id;
620 PMD_INIT_FUNC_TRACE();
622 /* Return if queue already configured */
623 if (dpaa2_q->flow_id != 0xffff) {
624 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
628 memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
629 memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
634 ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
635 tc_id, flow_id, options, &tx_flow_cfg);
637 DPAA2_PMD_ERR("Error in setting the tx flow: "
638 "tc_id=%d, flow=%d err=%d",
639 tc_id, flow_id, ret);
643 dpaa2_q->flow_id = flow_id;
645 if (tx_queue_id == 0) {
646 /*Set tx-conf and error configuration*/
647 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
651 DPAA2_PMD_ERR("Error in set tx conf mode settings: "
656 dpaa2_q->tc_index = tc_id;
658 if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
659 struct dpni_congestion_notification_cfg cong_notif_cfg;
661 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
662 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
663 /* Notify that the queue is not congested when the data in
664 * the queue is below this thershold.
666 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
667 cong_notif_cfg.message_ctx = 0;
668 cong_notif_cfg.message_iova =
669 (size_t)DPAA2_VADDR_TO_IOVA(dpaa2_q->cscn);
670 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
671 cong_notif_cfg.notification_mode =
672 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
673 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
674 DPNI_CONG_OPT_COHERENT_WRITE;
675 cong_notif_cfg.cg_point = DPNI_CP_QUEUE;
677 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
684 "Error in setting tx congestion notification: "
689 dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
690 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
695 dpaa2_dev_rx_queue_release(void *q __rte_unused)
697 PMD_INIT_FUNC_TRACE();
701 dpaa2_dev_tx_queue_release(void *q __rte_unused)
703 PMD_INIT_FUNC_TRACE();
707 dpaa2_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
710 struct dpaa2_dev_priv *priv = dev->data->dev_private;
711 struct dpaa2_queue *dpaa2_q;
712 struct qbman_swp *swp;
713 struct qbman_fq_query_np_rslt state;
714 uint32_t frame_cnt = 0;
716 PMD_INIT_FUNC_TRACE();
718 if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
719 ret = dpaa2_affine_qbman_swp();
721 DPAA2_PMD_ERR("Failure in affining portal");
725 swp = DPAA2_PER_LCORE_PORTAL;
727 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
729 if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
730 frame_cnt = qbman_fq_state_frame_count(&state);
731 DPAA2_PMD_DEBUG("RX frame count for q(%d) is %u",
732 rx_queue_id, frame_cnt);
737 static const uint32_t *
738 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
740 static const uint32_t ptypes[] = {
741 /*todo -= add more types */
744 RTE_PTYPE_L3_IPV4_EXT,
746 RTE_PTYPE_L3_IPV6_EXT,
754 if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
755 dev->rx_pkt_burst == dpaa2_dev_loopback_rx)
761 * Dpaa2 link Interrupt handler
764 * The address of parameter (struct rte_eth_dev *) regsitered before.
770 dpaa2_interrupt_handler(void *param)
772 struct rte_eth_dev *dev = param;
773 struct dpaa2_dev_priv *priv = dev->data->dev_private;
774 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
776 int irq_index = DPNI_IRQ_INDEX;
777 unsigned int status = 0, clear = 0;
779 PMD_INIT_FUNC_TRACE();
782 DPAA2_PMD_ERR("dpni is NULL");
786 ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
789 DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
794 if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
795 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
796 dpaa2_dev_link_update(dev, 0);
797 /* calling all the apps registered for link status event */
798 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
802 ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
805 DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
809 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
812 struct dpaa2_dev_priv *priv = dev->data->dev_private;
813 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
814 int irq_index = DPNI_IRQ_INDEX;
815 unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
817 PMD_INIT_FUNC_TRACE();
819 err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
822 DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
827 err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
830 DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
837 dpaa2_dev_start(struct rte_eth_dev *dev)
839 struct rte_device *rdev = dev->device;
840 struct rte_dpaa2_device *dpaa2_dev;
841 struct rte_eth_dev_data *data = dev->data;
842 struct dpaa2_dev_priv *priv = data->dev_private;
843 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
844 struct dpni_queue cfg;
845 struct dpni_error_cfg err_cfg;
847 struct dpni_queue_id qid;
848 struct dpaa2_queue *dpaa2_q;
850 struct rte_intr_handle *intr_handle;
852 dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
853 intr_handle = &dpaa2_dev->intr_handle;
855 PMD_INIT_FUNC_TRACE();
857 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
859 DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
864 /* Power up the phy. Needed to make the link go UP */
865 dpaa2_dev_set_link_up(dev);
867 ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
868 DPNI_QUEUE_TX, &qdid);
870 DPAA2_PMD_ERR("Error in getting qdid: err=%d", ret);
875 for (i = 0; i < data->nb_rx_queues; i++) {
876 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
877 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
878 DPNI_QUEUE_RX, dpaa2_q->tc_index,
879 dpaa2_q->flow_id, &cfg, &qid);
881 DPAA2_PMD_ERR("Error in getting flow information: "
885 dpaa2_q->fqid = qid.fqid;
888 /*checksum errors, send them to normal path and set it in annotation */
889 err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
890 err_cfg.errors |= DPNI_ERROR_PHE;
892 err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
893 err_cfg.set_frame_annotation = true;
895 ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
896 priv->token, &err_cfg);
898 DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
903 /* if the interrupts were configured on this devices*/
904 if (intr_handle && (intr_handle->fd) &&
905 (dev->data->dev_conf.intr_conf.lsc != 0)) {
906 /* Registering LSC interrupt handler */
907 rte_intr_callback_register(intr_handle,
908 dpaa2_interrupt_handler,
911 /* enable vfio intr/eventfd mapping
912 * Interrupt index 0 is required, so we can not use
915 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
917 /* enable dpni_irqs */
918 dpaa2_eth_setup_irqs(dev, 1);
921 /* Change the tx burst function if ordered queues are used */
922 if (priv->en_ordered)
923 dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
929 * This routine disables all traffic on the adapter by issuing a
930 * global reset on the MAC.
933 dpaa2_dev_stop(struct rte_eth_dev *dev)
935 struct dpaa2_dev_priv *priv = dev->data->dev_private;
936 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
938 struct rte_eth_link link;
939 struct rte_intr_handle *intr_handle = dev->intr_handle;
941 PMD_INIT_FUNC_TRACE();
943 /* reset interrupt callback */
944 if (intr_handle && (intr_handle->fd) &&
945 (dev->data->dev_conf.intr_conf.lsc != 0)) {
946 /*disable dpni irqs */
947 dpaa2_eth_setup_irqs(dev, 0);
949 /* disable vfio intr before callback unregister */
950 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
952 /* Unregistering LSC interrupt handler */
953 rte_intr_callback_unregister(intr_handle,
954 dpaa2_interrupt_handler,
958 dpaa2_dev_set_link_down(dev);
960 ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
962 DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
967 /* clear the recorded link status */
968 memset(&link, 0, sizeof(link));
969 rte_eth_linkstatus_set(dev, &link);
973 dpaa2_dev_close(struct rte_eth_dev *dev)
975 struct dpaa2_dev_priv *priv = dev->data->dev_private;
976 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
978 struct rte_eth_link link;
980 PMD_INIT_FUNC_TRACE();
982 dpaa2_flow_clean(dev);
984 /* Clean the device first */
985 ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
987 DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
991 memset(&link, 0, sizeof(link));
992 rte_eth_linkstatus_set(dev, &link);
996 dpaa2_dev_promiscuous_enable(
997 struct rte_eth_dev *dev)
1000 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1001 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1003 PMD_INIT_FUNC_TRACE();
1006 DPAA2_PMD_ERR("dpni is NULL");
1010 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1012 DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
1014 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1016 DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
1022 dpaa2_dev_promiscuous_disable(
1023 struct rte_eth_dev *dev)
1026 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1027 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1029 PMD_INIT_FUNC_TRACE();
1032 DPAA2_PMD_ERR("dpni is NULL");
1036 ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1038 DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
1040 if (dev->data->all_multicast == 0) {
1041 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
1042 priv->token, false);
1044 DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
1052 dpaa2_dev_allmulticast_enable(
1053 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 PMD_INIT_FUNC_TRACE();
1062 DPAA2_PMD_ERR("dpni is NULL");
1066 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1068 DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
1074 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
1077 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1078 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1080 PMD_INIT_FUNC_TRACE();
1083 DPAA2_PMD_ERR("dpni is NULL");
1087 /* must remain on for all promiscuous */
1088 if (dev->data->promiscuous == 1)
1091 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1093 DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
1099 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1102 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1103 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1104 uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
1107 PMD_INIT_FUNC_TRACE();
1110 DPAA2_PMD_ERR("dpni is NULL");
1114 /* check that mtu is within the allowed range */
1115 if (mtu < RTE_ETHER_MIN_MTU || frame_size > DPAA2_MAX_RX_PKT_LEN)
1118 if (frame_size > RTE_ETHER_MAX_LEN)
1119 dev->data->dev_conf.rxmode.offloads &=
1120 DEV_RX_OFFLOAD_JUMBO_FRAME;
1122 dev->data->dev_conf.rxmode.offloads &=
1123 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1125 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1127 /* Set the Max Rx frame length as 'mtu' +
1128 * Maximum Ethernet header length
1130 ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
1133 DPAA2_PMD_ERR("Setting the max frame length failed");
1136 DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
1141 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
1142 struct rte_ether_addr *addr,
1143 __rte_unused uint32_t index,
1144 __rte_unused uint32_t pool)
1147 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1148 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1150 PMD_INIT_FUNC_TRACE();
1153 DPAA2_PMD_ERR("dpni is NULL");
1157 ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
1158 priv->token, addr->addr_bytes);
1161 "error: Adding the MAC ADDR failed: err = %d", ret);
1166 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1170 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1171 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1172 struct rte_eth_dev_data *data = dev->data;
1173 struct rte_ether_addr *macaddr;
1175 PMD_INIT_FUNC_TRACE();
1177 macaddr = &data->mac_addrs[index];
1180 DPAA2_PMD_ERR("dpni is NULL");
1184 ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1185 priv->token, macaddr->addr_bytes);
1188 "error: Removing the MAC ADDR failed: err = %d", ret);
1192 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1193 struct rte_ether_addr *addr)
1196 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1197 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1199 PMD_INIT_FUNC_TRACE();
1202 DPAA2_PMD_ERR("dpni is NULL");
1206 ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1207 priv->token, addr->addr_bytes);
1211 "error: Setting the MAC ADDR failed %d", ret);
1217 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1218 struct rte_eth_stats *stats)
1220 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1221 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1223 uint8_t page0 = 0, page1 = 1, page2 = 2;
1224 union dpni_statistics value;
1226 struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
1228 memset(&value, 0, sizeof(union dpni_statistics));
1230 PMD_INIT_FUNC_TRACE();
1233 DPAA2_PMD_ERR("dpni is NULL");
1238 DPAA2_PMD_ERR("stats is NULL");
1242 /*Get Counters from page_0*/
1243 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1248 stats->ipackets = value.page_0.ingress_all_frames;
1249 stats->ibytes = value.page_0.ingress_all_bytes;
1251 /*Get Counters from page_1*/
1252 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1257 stats->opackets = value.page_1.egress_all_frames;
1258 stats->obytes = value.page_1.egress_all_bytes;
1260 /*Get Counters from page_2*/
1261 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1266 /* Ingress drop frame count due to configured rules */
1267 stats->ierrors = value.page_2.ingress_filtered_frames;
1268 /* Ingress drop frame count due to error */
1269 stats->ierrors += value.page_2.ingress_discarded_frames;
1271 stats->oerrors = value.page_2.egress_discarded_frames;
1272 stats->imissed = value.page_2.ingress_nobuffer_discards;
1274 /* Fill in per queue stats */
1275 for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1276 (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
1277 dpaa2_rxq = (struct dpaa2_queue *)priv->rx_vq[i];
1278 dpaa2_txq = (struct dpaa2_queue *)priv->tx_vq[i];
1280 stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
1282 stats->q_opackets[i] = dpaa2_txq->tx_pkts;
1284 /* Byte counting is not implemented */
1285 stats->q_ibytes[i] = 0;
1286 stats->q_obytes[i] = 0;
1292 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1297 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1300 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1301 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1303 union dpni_statistics value[3] = {};
1304 unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1312 /* Get Counters from page_0*/
1313 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1318 /* Get Counters from page_1*/
1319 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1324 /* Get Counters from page_2*/
1325 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1330 for (i = 0; i < num; i++) {
1332 xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1333 raw.counter[dpaa2_xstats_strings[i].stats_id];
1337 DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
1342 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1343 struct rte_eth_xstat_name *xstats_names,
1346 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1348 if (limit < stat_cnt)
1351 if (xstats_names != NULL)
1352 for (i = 0; i < stat_cnt; i++)
1353 strlcpy(xstats_names[i].name,
1354 dpaa2_xstats_strings[i].name,
1355 sizeof(xstats_names[i].name));
1361 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1362 uint64_t *values, unsigned int n)
1364 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1365 uint64_t values_copy[stat_cnt];
1368 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1369 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1371 union dpni_statistics value[3] = {};
1379 /* Get Counters from page_0*/
1380 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1385 /* Get Counters from page_1*/
1386 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1391 /* Get Counters from page_2*/
1392 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1397 for (i = 0; i < stat_cnt; i++) {
1398 values[i] = value[dpaa2_xstats_strings[i].page_id].
1399 raw.counter[dpaa2_xstats_strings[i].stats_id];
1404 dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1406 for (i = 0; i < n; i++) {
1407 if (ids[i] >= stat_cnt) {
1408 DPAA2_PMD_ERR("xstats id value isn't valid");
1411 values[i] = values_copy[ids[i]];
1417 dpaa2_xstats_get_names_by_id(
1418 struct rte_eth_dev *dev,
1419 struct rte_eth_xstat_name *xstats_names,
1420 const uint64_t *ids,
1423 unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1424 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1427 return dpaa2_xstats_get_names(dev, xstats_names, limit);
1429 dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1431 for (i = 0; i < limit; i++) {
1432 if (ids[i] >= stat_cnt) {
1433 DPAA2_PMD_ERR("xstats id value isn't valid");
1436 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1442 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1444 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1445 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1448 struct dpaa2_queue *dpaa2_q;
1450 PMD_INIT_FUNC_TRACE();
1453 DPAA2_PMD_ERR("dpni is NULL");
1457 retcode = dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1461 /* Reset the per queue stats in dpaa2_queue structure */
1462 for (i = 0; i < priv->nb_rx_queues; i++) {
1463 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1465 dpaa2_q->rx_pkts = 0;
1468 for (i = 0; i < priv->nb_tx_queues; i++) {
1469 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
1471 dpaa2_q->tx_pkts = 0;
1477 DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1481 /* return 0 means link status changed, -1 means not changed */
1483 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1484 int wait_to_complete __rte_unused)
1487 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1488 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1489 struct rte_eth_link link;
1490 struct dpni_link_state state = {0};
1493 DPAA2_PMD_ERR("dpni is NULL");
1497 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1499 DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
1503 memset(&link, 0, sizeof(struct rte_eth_link));
1504 link.link_status = state.up;
1505 link.link_speed = state.rate;
1507 if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1508 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1510 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1512 ret = rte_eth_linkstatus_set(dev, &link);
1514 DPAA2_PMD_DEBUG("No change in status");
1516 DPAA2_PMD_INFO("Port %d Link is %s\n", dev->data->port_id,
1517 link.link_status ? "Up" : "Down");
1523 * Toggle the DPNI to enable, if not already enabled.
1524 * This is not strictly PHY up/down - it is more of logical toggling.
1527 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1530 struct dpaa2_dev_priv *priv;
1531 struct fsl_mc_io *dpni;
1533 struct dpni_link_state state = {0};
1535 priv = dev->data->dev_private;
1536 dpni = (struct fsl_mc_io *)priv->hw;
1539 DPAA2_PMD_ERR("dpni is NULL");
1543 /* Check if DPNI is currently enabled */
1544 ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1546 /* Unable to obtain dpni status; Not continuing */
1547 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1551 /* Enable link if not already enabled */
1553 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1555 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1559 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1561 DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
1565 /* changing tx burst function to start enqueues */
1566 dev->tx_pkt_burst = dpaa2_dev_tx;
1567 dev->data->dev_link.link_status = state.up;
1570 DPAA2_PMD_INFO("Port %d Link is Up", dev->data->port_id);
1572 DPAA2_PMD_INFO("Port %d Link is Down", dev->data->port_id);
1577 * Toggle the DPNI to disable, if not already disabled.
1578 * This is not strictly PHY up/down - it is more of logical toggling.
1581 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1584 struct dpaa2_dev_priv *priv;
1585 struct fsl_mc_io *dpni;
1586 int dpni_enabled = 0;
1589 PMD_INIT_FUNC_TRACE();
1591 priv = dev->data->dev_private;
1592 dpni = (struct fsl_mc_io *)priv->hw;
1595 DPAA2_PMD_ERR("Device has not yet been configured");
1599 /*changing tx burst function to avoid any more enqueues */
1600 dev->tx_pkt_burst = dummy_dev_tx;
1602 /* Loop while dpni_disable() attempts to drain the egress FQs
1603 * and confirm them back to us.
1606 ret = dpni_disable(dpni, 0, priv->token);
1608 DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
1611 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1613 DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
1617 /* Allow the MC some slack */
1618 rte_delay_us(100 * 1000);
1619 } while (dpni_enabled && --retries);
1622 DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
1623 /* todo- we may have to manually cleanup queues.
1626 DPAA2_PMD_INFO("Port %d Link DOWN successful",
1627 dev->data->port_id);
1630 dev->data->dev_link.link_status = 0;
1636 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1639 struct dpaa2_dev_priv *priv;
1640 struct fsl_mc_io *dpni;
1641 struct dpni_link_state state = {0};
1643 PMD_INIT_FUNC_TRACE();
1645 priv = dev->data->dev_private;
1646 dpni = (struct fsl_mc_io *)priv->hw;
1648 if (dpni == NULL || fc_conf == NULL) {
1649 DPAA2_PMD_ERR("device not configured");
1653 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1655 DPAA2_PMD_ERR("error: dpni_get_link_state %d", ret);
1659 memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1660 if (state.options & DPNI_LINK_OPT_PAUSE) {
1661 /* DPNI_LINK_OPT_PAUSE set
1662 * if ASYM_PAUSE not set,
1663 * RX Side flow control (handle received Pause frame)
1664 * TX side flow control (send Pause frame)
1665 * if ASYM_PAUSE set,
1666 * RX Side flow control (handle received Pause frame)
1667 * No TX side flow control (send Pause frame disabled)
1669 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1670 fc_conf->mode = RTE_FC_FULL;
1672 fc_conf->mode = RTE_FC_RX_PAUSE;
1674 /* DPNI_LINK_OPT_PAUSE not set
1675 * if ASYM_PAUSE set,
1676 * TX side flow control (send Pause frame)
1677 * No RX side flow control (No action on pause frame rx)
1678 * if ASYM_PAUSE not set,
1679 * Flow control disabled
1681 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1682 fc_conf->mode = RTE_FC_TX_PAUSE;
1684 fc_conf->mode = RTE_FC_NONE;
1691 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1694 struct dpaa2_dev_priv *priv;
1695 struct fsl_mc_io *dpni;
1696 struct dpni_link_state state = {0};
1697 struct dpni_link_cfg cfg = {0};
1699 PMD_INIT_FUNC_TRACE();
1701 priv = dev->data->dev_private;
1702 dpni = (struct fsl_mc_io *)priv->hw;
1705 DPAA2_PMD_ERR("dpni is NULL");
1709 /* It is necessary to obtain the current state before setting fc_conf
1710 * as MC would return error in case rate, autoneg or duplex values are
1713 ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1715 DPAA2_PMD_ERR("Unable to get link state (err=%d)", ret);
1719 /* Disable link before setting configuration */
1720 dpaa2_dev_set_link_down(dev);
1722 /* Based on fc_conf, update cfg */
1723 cfg.rate = state.rate;
1724 cfg.options = state.options;
1726 /* update cfg with fc_conf */
1727 switch (fc_conf->mode) {
1729 /* Full flow control;
1730 * OPT_PAUSE set, ASYM_PAUSE not set
1732 cfg.options |= DPNI_LINK_OPT_PAUSE;
1733 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1735 case RTE_FC_TX_PAUSE:
1736 /* Enable RX flow control
1737 * OPT_PAUSE not set;
1740 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1741 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1743 case RTE_FC_RX_PAUSE:
1744 /* Enable TX Flow control
1748 cfg.options |= DPNI_LINK_OPT_PAUSE;
1749 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1752 /* Disable Flow control
1754 * ASYM_PAUSE not set
1756 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1757 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1760 DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
1765 ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1767 DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
1771 dpaa2_dev_set_link_up(dev);
1777 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
1778 struct rte_eth_rss_conf *rss_conf)
1780 struct rte_eth_dev_data *data = dev->data;
1781 struct rte_eth_conf *eth_conf = &data->dev_conf;
1784 PMD_INIT_FUNC_TRACE();
1786 if (rss_conf->rss_hf) {
1787 ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf);
1789 DPAA2_PMD_ERR("Unable to set flow dist");
1793 ret = dpaa2_remove_flow_dist(dev, 0);
1795 DPAA2_PMD_ERR("Unable to remove flow dist");
1799 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1804 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1805 struct rte_eth_rss_conf *rss_conf)
1807 struct rte_eth_dev_data *data = dev->data;
1808 struct rte_eth_conf *eth_conf = &data->dev_conf;
1810 /* dpaa2 does not support rss_key, so length should be 0*/
1811 rss_conf->rss_key_len = 0;
1812 rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1816 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
1817 int eth_rx_queue_id,
1819 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1821 struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1822 struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1823 struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1824 uint8_t flow_id = dpaa2_ethq->flow_id;
1825 struct dpni_queue cfg;
1829 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
1830 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
1831 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
1832 dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
1833 else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
1834 dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
1838 memset(&cfg, 0, sizeof(struct dpni_queue));
1839 options = DPNI_QUEUE_OPT_DEST;
1840 cfg.destination.type = DPNI_DEST_DPCON;
1841 cfg.destination.id = dpcon_id;
1842 cfg.destination.priority = queue_conf->ev.priority;
1844 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
1845 options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
1846 cfg.destination.hold_active = 1;
1849 if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
1850 !eth_priv->en_ordered) {
1851 struct opr_cfg ocfg;
1853 /* Restoration window size = 256 frames */
1855 /* Restoration window size = 512 frames for LX2 */
1856 if (dpaa2_svr_family == SVR_LX2160A)
1858 /* Auto advance NESN window enabled */
1860 /* Late arrival window size disabled */
1862 /* ORL resource exhaustaion advance NESN disabled */
1864 /* Loose ordering enabled */
1866 eth_priv->en_loose_ordered = 1;
1867 /* Strict ordering enabled if explicitly set */
1868 if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
1870 eth_priv->en_loose_ordered = 0;
1873 ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
1874 dpaa2_ethq->tc_index, flow_id,
1875 OPR_OPT_CREATE, &ocfg);
1877 DPAA2_PMD_ERR("Error setting opr: ret: %d\n", ret);
1881 eth_priv->en_ordered = 1;
1884 options |= DPNI_QUEUE_OPT_USER_CTX;
1885 cfg.user_context = (size_t)(dpaa2_ethq);
1887 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1888 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1890 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1894 memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
1899 int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
1900 int eth_rx_queue_id)
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 memset(&cfg, 0, sizeof(struct dpni_queue));
1911 options = DPNI_QUEUE_OPT_DEST;
1912 cfg.destination.type = DPNI_DEST_NONE;
1914 ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1915 dpaa2_ethq->tc_index, flow_id, options, &cfg);
1917 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1923 dpaa2_dev_verify_filter_ops(enum rte_filter_op filter_op)
1927 for (i = 0; i < RTE_DIM(dpaa2_supported_filter_ops); i++) {
1928 if (dpaa2_supported_filter_ops[i] == filter_op)
1935 dpaa2_dev_flow_ctrl(struct rte_eth_dev *dev,
1936 enum rte_filter_type filter_type,
1937 enum rte_filter_op filter_op,
1945 switch (filter_type) {
1946 case RTE_ETH_FILTER_GENERIC:
1947 if (dpaa2_dev_verify_filter_ops(filter_op) < 0) {
1951 *(const void **)arg = &dpaa2_flow_ops;
1952 dpaa2_filter_type |= filter_type;
1955 RTE_LOG(ERR, PMD, "Filter type (%d) not supported",
1963 static struct eth_dev_ops dpaa2_ethdev_ops = {
1964 .dev_configure = dpaa2_eth_dev_configure,
1965 .dev_start = dpaa2_dev_start,
1966 .dev_stop = dpaa2_dev_stop,
1967 .dev_close = dpaa2_dev_close,
1968 .promiscuous_enable = dpaa2_dev_promiscuous_enable,
1969 .promiscuous_disable = dpaa2_dev_promiscuous_disable,
1970 .allmulticast_enable = dpaa2_dev_allmulticast_enable,
1971 .allmulticast_disable = dpaa2_dev_allmulticast_disable,
1972 .dev_set_link_up = dpaa2_dev_set_link_up,
1973 .dev_set_link_down = dpaa2_dev_set_link_down,
1974 .link_update = dpaa2_dev_link_update,
1975 .stats_get = dpaa2_dev_stats_get,
1976 .xstats_get = dpaa2_dev_xstats_get,
1977 .xstats_get_by_id = dpaa2_xstats_get_by_id,
1978 .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
1979 .xstats_get_names = dpaa2_xstats_get_names,
1980 .stats_reset = dpaa2_dev_stats_reset,
1981 .xstats_reset = dpaa2_dev_stats_reset,
1982 .fw_version_get = dpaa2_fw_version_get,
1983 .dev_infos_get = dpaa2_dev_info_get,
1984 .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
1985 .mtu_set = dpaa2_dev_mtu_set,
1986 .vlan_filter_set = dpaa2_vlan_filter_set,
1987 .vlan_offload_set = dpaa2_vlan_offload_set,
1988 .vlan_tpid_set = dpaa2_vlan_tpid_set,
1989 .rx_queue_setup = dpaa2_dev_rx_queue_setup,
1990 .rx_queue_release = dpaa2_dev_rx_queue_release,
1991 .tx_queue_setup = dpaa2_dev_tx_queue_setup,
1992 .tx_queue_release = dpaa2_dev_tx_queue_release,
1993 .rx_queue_count = dpaa2_dev_rx_queue_count,
1994 .flow_ctrl_get = dpaa2_flow_ctrl_get,
1995 .flow_ctrl_set = dpaa2_flow_ctrl_set,
1996 .mac_addr_add = dpaa2_dev_add_mac_addr,
1997 .mac_addr_remove = dpaa2_dev_remove_mac_addr,
1998 .mac_addr_set = dpaa2_dev_set_mac_addr,
1999 .rss_hash_update = dpaa2_dev_rss_hash_update,
2000 .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get,
2001 .filter_ctrl = dpaa2_dev_flow_ctrl,
2004 /* Populate the mac address from physically available (u-boot/firmware) and/or
2005 * one set by higher layers like MC (restool) etc.
2006 * Returns the table of MAC entries (multiple entries)
2009 populate_mac_addr(struct fsl_mc_io *dpni_dev, struct dpaa2_dev_priv *priv,
2010 struct rte_ether_addr *mac_entry)
2013 struct rte_ether_addr phy_mac, prime_mac;
2015 memset(&phy_mac, 0, sizeof(struct rte_ether_addr));
2016 memset(&prime_mac, 0, sizeof(struct rte_ether_addr));
2018 /* Get the physical device MAC address */
2019 ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2020 phy_mac.addr_bytes);
2022 DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
2026 ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2027 prime_mac.addr_bytes);
2029 DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
2033 /* Now that both MAC have been obtained, do:
2034 * if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
2036 * If empty_mac(phy), return prime.
2037 * if both are empty, create random MAC, set as prime and return
2039 if (!rte_is_zero_ether_addr(&phy_mac)) {
2040 /* If the addresses are not same, overwrite prime */
2041 if (!rte_is_same_ether_addr(&phy_mac, &prime_mac)) {
2042 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2044 phy_mac.addr_bytes);
2046 DPAA2_PMD_ERR("Unable to set MAC Address: %d",
2050 memcpy(&prime_mac, &phy_mac,
2051 sizeof(struct rte_ether_addr));
2053 } else if (rte_is_zero_ether_addr(&prime_mac)) {
2054 /* In case phys and prime, both are zero, create random MAC */
2055 rte_eth_random_addr(prime_mac.addr_bytes);
2056 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2058 prime_mac.addr_bytes);
2060 DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
2065 /* prime_mac the final MAC address */
2066 memcpy(mac_entry, &prime_mac, sizeof(struct rte_ether_addr));
2074 check_devargs_handler(__rte_unused const char *key, const char *value,
2075 __rte_unused void *opaque)
2077 if (strcmp(value, "1"))
2084 dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
2086 struct rte_kvargs *kvlist;
2091 kvlist = rte_kvargs_parse(devargs->args, NULL);
2095 if (!rte_kvargs_count(kvlist, key)) {
2096 rte_kvargs_free(kvlist);
2100 if (rte_kvargs_process(kvlist, key,
2101 check_devargs_handler, NULL) < 0) {
2102 rte_kvargs_free(kvlist);
2105 rte_kvargs_free(kvlist);
2111 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
2113 struct rte_device *dev = eth_dev->device;
2114 struct rte_dpaa2_device *dpaa2_dev;
2115 struct fsl_mc_io *dpni_dev;
2116 struct dpni_attr attr;
2117 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2118 struct dpni_buffer_layout layout;
2121 PMD_INIT_FUNC_TRACE();
2123 /* For secondary processes, the primary has done all the work */
2124 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2125 /* In case of secondary, only burst and ops API need to be
2128 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2129 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
2130 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2132 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2133 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2137 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2139 hw_id = dpaa2_dev->object_id;
2141 dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
2143 DPAA2_PMD_ERR("Memory allocation failed for dpni device");
2147 dpni_dev->regs = rte_mcp_ptr_list[0];
2148 ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
2151 "Failure in opening dpni@%d with err code %d",
2157 /* Clean the device first */
2158 ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
2160 DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
2165 ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
2168 "Failure in get dpni@%d attribute, err code %d",
2173 priv->num_rx_tc = attr.num_rx_tcs;
2175 for (i = 0; i < attr.num_rx_tcs; i++)
2176 priv->nb_rx_queues += attr.num_queues;
2178 /* Using number of TX queues as number of TX TCs */
2179 priv->nb_tx_queues = attr.num_tx_tcs;
2181 DPAA2_PMD_DEBUG("RX-TC= %d, nb_rx_queues= %d, nb_tx_queues=%d",
2182 priv->num_rx_tc, priv->nb_rx_queues,
2183 priv->nb_tx_queues);
2185 priv->hw = dpni_dev;
2186 priv->hw_id = hw_id;
2187 priv->options = attr.options;
2188 priv->max_mac_filters = attr.mac_filter_entries;
2189 priv->max_vlan_filters = attr.vlan_filter_entries;
2192 /* Allocate memory for hardware structure for queues */
2193 ret = dpaa2_alloc_rx_tx_queues(eth_dev);
2195 DPAA2_PMD_ERR("Queue allocation Failed");
2199 /* Allocate memory for storing MAC addresses.
2200 * Table of mac_filter_entries size is allocated so that RTE ether lib
2201 * can add MAC entries when rte_eth_dev_mac_addr_add is called.
2203 eth_dev->data->mac_addrs = rte_zmalloc("dpni",
2204 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
2205 if (eth_dev->data->mac_addrs == NULL) {
2207 "Failed to allocate %d bytes needed to store MAC addresses",
2208 RTE_ETHER_ADDR_LEN * attr.mac_filter_entries);
2213 ret = populate_mac_addr(dpni_dev, priv, ð_dev->data->mac_addrs[0]);
2215 DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
2216 rte_free(eth_dev->data->mac_addrs);
2217 eth_dev->data->mac_addrs = NULL;
2221 /* ... tx buffer layout ... */
2222 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2223 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2224 layout.pass_frame_status = 1;
2225 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2226 DPNI_QUEUE_TX, &layout);
2228 DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
2232 /* ... tx-conf and error buffer layout ... */
2233 memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2234 layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2235 layout.pass_frame_status = 1;
2236 ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2237 DPNI_QUEUE_TX_CONFIRM, &layout);
2239 DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
2244 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2246 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
2247 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2248 DPAA2_PMD_INFO("Loopback mode");
2250 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2252 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2254 /*Init fields w.r.t. classficaition*/
2255 memset(&priv->extract.qos_key_cfg, 0, sizeof(struct dpkg_profile_cfg));
2256 priv->extract.qos_extract_param = (size_t)rte_malloc(NULL, 256, 64);
2257 if (!priv->extract.qos_extract_param) {
2258 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow "
2259 " classificaiton ", ret);
2262 for (i = 0; i < MAX_TCS; i++) {
2263 memset(&priv->extract.fs_key_cfg[i], 0,
2264 sizeof(struct dpkg_profile_cfg));
2265 priv->extract.fs_extract_param[i] =
2266 (size_t)rte_malloc(NULL, 256, 64);
2267 if (!priv->extract.fs_extract_param[i]) {
2268 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow classificaiton",
2274 RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
2277 dpaa2_dev_uninit(eth_dev);
2282 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
2284 struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2285 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
2288 PMD_INIT_FUNC_TRACE();
2290 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2294 DPAA2_PMD_WARN("Already closed or not started");
2298 dpaa2_dev_close(eth_dev);
2300 dpaa2_free_rx_tx_queues(eth_dev);
2302 /* Close the device at underlying layer*/
2303 ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
2306 "Failure closing dpni device with err code %d",
2310 /* Free the allocated memory for ethernet private data and dpni*/
2314 for (i = 0; i < MAX_TCS; i++) {
2315 if (priv->extract.fs_extract_param[i])
2316 rte_free((void *)(size_t)priv->extract.fs_extract_param[i]);
2319 if (priv->extract.qos_extract_param)
2320 rte_free((void *)(size_t)priv->extract.qos_extract_param);
2322 eth_dev->dev_ops = NULL;
2323 eth_dev->rx_pkt_burst = NULL;
2324 eth_dev->tx_pkt_burst = NULL;
2326 DPAA2_PMD_INFO("%s: netdev deleted", eth_dev->data->name);
2331 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
2332 struct rte_dpaa2_device *dpaa2_dev)
2334 struct rte_eth_dev *eth_dev;
2337 if ((DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) >
2338 RTE_PKTMBUF_HEADROOM) {
2340 "RTE_PKTMBUF_HEADROOM(%d) shall be > DPAA2 Annotation req(%d)",
2341 RTE_PKTMBUF_HEADROOM,
2342 DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE);
2347 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2348 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
2351 eth_dev->data->dev_private = rte_zmalloc(
2352 "ethdev private structure",
2353 sizeof(struct dpaa2_dev_priv),
2354 RTE_CACHE_LINE_SIZE);
2355 if (eth_dev->data->dev_private == NULL) {
2357 "Unable to allocate memory for private data");
2358 rte_eth_dev_release_port(eth_dev);
2362 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
2367 eth_dev->device = &dpaa2_dev->device;
2369 dpaa2_dev->eth_dev = eth_dev;
2370 eth_dev->data->rx_mbuf_alloc_failed = 0;
2372 if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
2373 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
2375 /* Invoke PMD device initialization function */
2376 diag = dpaa2_dev_init(eth_dev);
2378 rte_eth_dev_probing_finish(eth_dev);
2382 rte_eth_dev_release_port(eth_dev);
2387 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
2389 struct rte_eth_dev *eth_dev;
2391 eth_dev = dpaa2_dev->eth_dev;
2392 dpaa2_dev_uninit(eth_dev);
2394 rte_eth_dev_release_port(eth_dev);
2399 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
2400 .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
2401 .drv_type = DPAA2_ETH,
2402 .probe = rte_dpaa2_probe,
2403 .remove = rte_dpaa2_remove,
2406 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);
2407 RTE_PMD_REGISTER_PARAM_STRING(net_dpaa2,
2408 DRIVER_LOOPBACK_MODE "=<int>");
2409 RTE_INIT(dpaa2_pmd_init_log)
2411 dpaa2_logtype_pmd = rte_log_register("pmd.net.dpaa2");
2412 if (dpaa2_logtype_pmd >= 0)
2413 rte_log_set_level(dpaa2_logtype_pmd, RTE_LOG_NOTICE);