xref: /dpdk/drivers/net/dpaa2/dpaa2_ethdev.c (revision 3da59f30a23f2e795d2315f3d949e1b3e0ce0c3d)
1 /* * SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4  *   Copyright 2016-2021 NXP
5  *
6  */
7 
8 #include <time.h>
9 #include <net/if.h>
10 
11 #include <rte_mbuf.h>
12 #include <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>
18 #include <dev_driver.h>
19 #include <bus_fslmc_driver.h>
20 #include <rte_flow_driver.h>
21 #include "rte_dpaa2_mempool.h"
22 
23 #include "dpaa2_pmd_logs.h"
24 #include <fslmc_vfio.h>
25 #include <dpaa2_hw_pvt.h>
26 #include <dpaa2_hw_mempool.h>
27 #include <dpaa2_hw_dpio.h>
28 #include <mc/fsl_dpmng.h>
29 #include "dpaa2_ethdev.h"
30 #include "dpaa2_sparser.h"
31 #include <fsl_qbman_debug.h>
32 
33 #define DRIVER_LOOPBACK_MODE "drv_loopback"
34 #define DRIVER_NO_PREFETCH_MODE "drv_no_prefetch"
35 #define DRIVER_TX_CONF "drv_tx_conf"
36 #define DRIVER_ERROR_QUEUE  "drv_err_queue"
37 #define CHECK_INTERVAL         100  /* 100ms */
38 #define MAX_REPEAT_TIME        90   /* 9s (90 * 100ms) in total */
39 
40 /* Supported Rx offloads */
41 static uint64_t dev_rx_offloads_sup =
42 		RTE_ETH_RX_OFFLOAD_CHECKSUM |
43 		RTE_ETH_RX_OFFLOAD_SCTP_CKSUM |
44 		RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
45 		RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM |
46 		RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
47 		RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
48 		RTE_ETH_RX_OFFLOAD_TIMESTAMP;
49 
50 /* Rx offloads which cannot be disabled */
51 static uint64_t dev_rx_offloads_nodis =
52 		RTE_ETH_RX_OFFLOAD_RSS_HASH |
53 		RTE_ETH_RX_OFFLOAD_SCATTER;
54 
55 /* Supported Tx offloads */
56 static uint64_t dev_tx_offloads_sup =
57 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
58 		RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
59 		RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
60 		RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
61 		RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
62 		RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
63 		RTE_ETH_TX_OFFLOAD_MT_LOCKFREE |
64 		RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
65 
66 /* Tx offloads which cannot be disabled */
67 static uint64_t dev_tx_offloads_nodis =
68 		RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
69 
70 /* enable timestamp in mbuf */
71 bool dpaa2_enable_ts[RTE_MAX_ETHPORTS];
72 uint64_t dpaa2_timestamp_rx_dynflag;
73 int dpaa2_timestamp_dynfield_offset = -1;
74 
75 /* Enable error queue */
76 bool dpaa2_enable_err_queue;
77 
78 #define MAX_NB_RX_DESC		11264
79 int total_nb_rx_desc;
80 
81 int dpaa2_valid_dev;
82 struct rte_mempool *dpaa2_tx_sg_pool;
83 
84 struct rte_dpaa2_xstats_name_off {
85 	char name[RTE_ETH_XSTATS_NAME_SIZE];
86 	uint8_t page_id; /* dpni statistics page id */
87 	uint8_t stats_id; /* stats id in the given page */
88 };
89 
90 static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
91 	{"ingress_multicast_frames", 0, 2},
92 	{"ingress_multicast_bytes", 0, 3},
93 	{"ingress_broadcast_frames", 0, 4},
94 	{"ingress_broadcast_bytes", 0, 5},
95 	{"egress_multicast_frames", 1, 2},
96 	{"egress_multicast_bytes", 1, 3},
97 	{"egress_broadcast_frames", 1, 4},
98 	{"egress_broadcast_bytes", 1, 5},
99 	{"ingress_filtered_frames", 2, 0},
100 	{"ingress_discarded_frames", 2, 1},
101 	{"ingress_nobuffer_discards", 2, 2},
102 	{"egress_discarded_frames", 2, 3},
103 	{"egress_confirmed_frames", 2, 4},
104 	{"cgr_reject_frames", 4, 0},
105 	{"cgr_reject_bytes", 4, 1},
106 };
107 
108 static struct rte_dpaa2_driver rte_dpaa2_pmd;
109 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
110 				 int wait_to_complete);
111 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
112 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
113 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
114 
115 static int
116 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
117 {
118 	int ret;
119 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
120 	struct fsl_mc_io *dpni = dev->process_private;
121 
122 	PMD_INIT_FUNC_TRACE();
123 
124 	if (dpni == NULL) {
125 		DPAA2_PMD_ERR("dpni is NULL");
126 		return -1;
127 	}
128 
129 	if (on)
130 		ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW, priv->token,
131 				       vlan_id, 0, 0, 0);
132 	else
133 		ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
134 					  priv->token, vlan_id);
135 
136 	if (ret < 0)
137 		DPAA2_PMD_ERR("ret = %d Unable to add/rem vlan %d hwid =%d",
138 			      ret, vlan_id, priv->hw_id);
139 
140 	return ret;
141 }
142 
143 static int
144 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
145 {
146 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
147 	struct fsl_mc_io *dpni = dev->process_private;
148 	int ret = 0;
149 
150 	PMD_INIT_FUNC_TRACE();
151 
152 	if (mask & RTE_ETH_VLAN_FILTER_MASK) {
153 		/* VLAN Filter not available */
154 		if (!priv->max_vlan_filters) {
155 			DPAA2_PMD_INFO("VLAN filter not available");
156 			return -ENOTSUP;
157 		}
158 
159 		if (dev->data->dev_conf.rxmode.offloads &
160 			RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
161 			ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
162 						      priv->token, true);
163 		else
164 			ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
165 						      priv->token, false);
166 		if (ret < 0)
167 			DPAA2_PMD_INFO("Unable to set vlan filter = %d", ret);
168 	}
169 
170 	return ret;
171 }
172 
173 static int
174 dpaa2_vlan_tpid_set(struct rte_eth_dev *dev,
175 		      enum rte_vlan_type vlan_type __rte_unused,
176 		      uint16_t tpid)
177 {
178 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
179 	struct fsl_mc_io *dpni = dev->process_private;
180 	int ret = -ENOTSUP;
181 
182 	PMD_INIT_FUNC_TRACE();
183 
184 	/* nothing to be done for standard vlan tpids */
185 	if (tpid == 0x8100 || tpid == 0x88A8)
186 		return 0;
187 
188 	ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
189 				   priv->token, tpid);
190 	if (ret < 0)
191 		DPAA2_PMD_INFO("Unable to set vlan tpid = %d", ret);
192 	/* if already configured tpids, remove them first */
193 	if (ret == -EBUSY) {
194 		struct dpni_custom_tpid_cfg tpid_list = {0};
195 
196 		ret = dpni_get_custom_tpid(dpni, CMD_PRI_LOW,
197 				   priv->token, &tpid_list);
198 		if (ret < 0)
199 			goto fail;
200 		ret = dpni_remove_custom_tpid(dpni, CMD_PRI_LOW,
201 				   priv->token, tpid_list.tpid1);
202 		if (ret < 0)
203 			goto fail;
204 		ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
205 					   priv->token, tpid);
206 	}
207 fail:
208 	return ret;
209 }
210 
211 static int
212 dpaa2_fw_version_get(struct rte_eth_dev *dev,
213 		     char *fw_version,
214 		     size_t fw_size)
215 {
216 	int ret;
217 	struct fsl_mc_io *dpni = dev->process_private;
218 	struct mc_soc_version mc_plat_info = {0};
219 	struct mc_version mc_ver_info = {0};
220 
221 	PMD_INIT_FUNC_TRACE();
222 
223 	if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
224 		DPAA2_PMD_WARN("\tmc_get_soc_version failed");
225 
226 	if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
227 		DPAA2_PMD_WARN("\tmc_get_version failed");
228 
229 	ret = snprintf(fw_version, fw_size,
230 		       "%x-%d.%d.%d",
231 		       mc_plat_info.svr,
232 		       mc_ver_info.major,
233 		       mc_ver_info.minor,
234 		       mc_ver_info.revision);
235 	if (ret < 0)
236 		return -EINVAL;
237 
238 	ret += 1; /* add the size of '\0' */
239 	if (fw_size < (size_t)ret)
240 		return ret;
241 	else
242 		return 0;
243 }
244 
245 static int
246 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
247 {
248 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
249 
250 	PMD_INIT_FUNC_TRACE();
251 
252 	dev_info->max_mac_addrs = priv->max_mac_filters;
253 	dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
254 	dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
255 	dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
256 	dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
257 	dev_info->rx_offload_capa = dev_rx_offloads_sup |
258 					dev_rx_offloads_nodis;
259 	dev_info->tx_offload_capa = dev_tx_offloads_sup |
260 					dev_tx_offloads_nodis;
261 	dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G |
262 			RTE_ETH_LINK_SPEED_2_5G |
263 			RTE_ETH_LINK_SPEED_10G;
264 	dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
265 
266 	dev_info->max_hash_mac_addrs = 0;
267 	dev_info->max_vfs = 0;
268 	dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
269 	dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
270 
271 	dev_info->default_rxportconf.burst_size = dpaa2_dqrr_size;
272 	/* same is rx size for best perf */
273 	dev_info->default_txportconf.burst_size = dpaa2_dqrr_size;
274 
275 	dev_info->default_rxportconf.nb_queues = 1;
276 	dev_info->default_txportconf.nb_queues = 1;
277 	dev_info->default_txportconf.ring_size = CONG_ENTER_TX_THRESHOLD;
278 	dev_info->default_rxportconf.ring_size = DPAA2_RX_DEFAULT_NBDESC;
279 
280 	if (dpaa2_svr_family == SVR_LX2160A) {
281 		dev_info->speed_capa |= RTE_ETH_LINK_SPEED_25G |
282 				RTE_ETH_LINK_SPEED_40G |
283 				RTE_ETH_LINK_SPEED_50G |
284 				RTE_ETH_LINK_SPEED_100G;
285 	}
286 
287 	return 0;
288 }
289 
290 static int
291 dpaa2_dev_rx_burst_mode_get(struct rte_eth_dev *dev,
292 			__rte_unused uint16_t queue_id,
293 			struct rte_eth_burst_mode *mode)
294 {
295 	struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
296 	int ret = -EINVAL;
297 	unsigned int i;
298 	const struct burst_info {
299 		uint64_t flags;
300 		const char *output;
301 	} rx_offload_map[] = {
302 			{RTE_ETH_RX_OFFLOAD_CHECKSUM, " Checksum,"},
303 			{RTE_ETH_RX_OFFLOAD_SCTP_CKSUM, " SCTP csum,"},
304 			{RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
305 			{RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM, " Outer UDP csum,"},
306 			{RTE_ETH_RX_OFFLOAD_VLAN_STRIP, " VLAN strip,"},
307 			{RTE_ETH_RX_OFFLOAD_VLAN_FILTER, " VLAN filter,"},
308 			{RTE_ETH_RX_OFFLOAD_TIMESTAMP, " Timestamp,"},
309 			{RTE_ETH_RX_OFFLOAD_RSS_HASH, " RSS,"},
310 			{RTE_ETH_RX_OFFLOAD_SCATTER, " Scattered,"}
311 	};
312 
313 	/* Update Rx offload info */
314 	for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
315 		if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) {
316 			snprintf(mode->info, sizeof(mode->info), "%s",
317 				rx_offload_map[i].output);
318 			ret = 0;
319 			break;
320 		}
321 	}
322 	return ret;
323 }
324 
325 static int
326 dpaa2_dev_tx_burst_mode_get(struct rte_eth_dev *dev,
327 			__rte_unused uint16_t queue_id,
328 			struct rte_eth_burst_mode *mode)
329 {
330 	struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
331 	int ret = -EINVAL;
332 	unsigned int i;
333 	const struct burst_info {
334 		uint64_t flags;
335 		const char *output;
336 	} tx_offload_map[] = {
337 			{RTE_ETH_TX_OFFLOAD_VLAN_INSERT, " VLAN Insert,"},
338 			{RTE_ETH_TX_OFFLOAD_IPV4_CKSUM, " IPV4 csum,"},
339 			{RTE_ETH_TX_OFFLOAD_UDP_CKSUM, " UDP csum,"},
340 			{RTE_ETH_TX_OFFLOAD_TCP_CKSUM, " TCP csum,"},
341 			{RTE_ETH_TX_OFFLOAD_SCTP_CKSUM, " SCTP csum,"},
342 			{RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM, " Outer IPV4 csum,"},
343 			{RTE_ETH_TX_OFFLOAD_MT_LOCKFREE, " MT lockfree,"},
344 			{RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE, " MBUF free disable,"},
345 			{RTE_ETH_TX_OFFLOAD_MULTI_SEGS, " Scattered,"}
346 	};
347 
348 	/* Update Tx offload info */
349 	for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
350 		if (eth_conf->txmode.offloads & tx_offload_map[i].flags) {
351 			snprintf(mode->info, sizeof(mode->info), "%s",
352 				tx_offload_map[i].output);
353 			ret = 0;
354 			break;
355 		}
356 	}
357 	return ret;
358 }
359 
360 static int
361 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
362 {
363 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
364 	uint16_t dist_idx;
365 	uint32_t vq_id;
366 	uint8_t num_rxqueue_per_tc;
367 	struct dpaa2_queue *mc_q, *mcq;
368 	uint32_t tot_queues;
369 	int i;
370 	struct dpaa2_queue *dpaa2_q;
371 
372 	PMD_INIT_FUNC_TRACE();
373 
374 	num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
375 	if (priv->flags & DPAA2_TX_CONF_ENABLE)
376 		tot_queues = priv->nb_rx_queues + 2 * priv->nb_tx_queues;
377 	else
378 		tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
379 	mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
380 			  RTE_CACHE_LINE_SIZE);
381 	if (!mc_q) {
382 		DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
383 		return -1;
384 	}
385 
386 	for (i = 0; i < priv->nb_rx_queues; i++) {
387 		mc_q->eth_data = dev->data;
388 		priv->rx_vq[i] = mc_q++;
389 		dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
390 		dpaa2_q->q_storage = rte_malloc("dq_storage",
391 					sizeof(struct queue_storage_info_t),
392 					RTE_CACHE_LINE_SIZE);
393 		if (!dpaa2_q->q_storage)
394 			goto fail;
395 
396 		memset(dpaa2_q->q_storage, 0,
397 		       sizeof(struct queue_storage_info_t));
398 		if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
399 			goto fail;
400 	}
401 
402 	if (dpaa2_enable_err_queue) {
403 		priv->rx_err_vq = rte_zmalloc("dpni_rx_err",
404 			sizeof(struct dpaa2_queue), 0);
405 		if (!priv->rx_err_vq)
406 			goto fail;
407 
408 		dpaa2_q = (struct dpaa2_queue *)priv->rx_err_vq;
409 		dpaa2_q->q_storage = rte_malloc("err_dq_storage",
410 					sizeof(struct queue_storage_info_t) *
411 					RTE_MAX_LCORE,
412 					RTE_CACHE_LINE_SIZE);
413 		if (!dpaa2_q->q_storage)
414 			goto fail;
415 
416 		memset(dpaa2_q->q_storage, 0,
417 		       sizeof(struct queue_storage_info_t));
418 		for (i = 0; i < RTE_MAX_LCORE; i++)
419 			if (dpaa2_alloc_dq_storage(&dpaa2_q->q_storage[i]))
420 				goto fail;
421 	}
422 
423 	for (i = 0; i < priv->nb_tx_queues; i++) {
424 		mc_q->eth_data = dev->data;
425 		mc_q->flow_id = 0xffff;
426 		priv->tx_vq[i] = mc_q++;
427 		dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
428 		dpaa2_q->cscn = rte_malloc(NULL,
429 					   sizeof(struct qbman_result), 16);
430 		if (!dpaa2_q->cscn)
431 			goto fail_tx;
432 	}
433 
434 	if (priv->flags & DPAA2_TX_CONF_ENABLE) {
435 		/*Setup tx confirmation queues*/
436 		for (i = 0; i < priv->nb_tx_queues; i++) {
437 			mc_q->eth_data = dev->data;
438 			mc_q->tc_index = i;
439 			mc_q->flow_id = 0;
440 			priv->tx_conf_vq[i] = mc_q++;
441 			dpaa2_q = (struct dpaa2_queue *)priv->tx_conf_vq[i];
442 			dpaa2_q->q_storage =
443 				rte_malloc("dq_storage",
444 					sizeof(struct queue_storage_info_t),
445 					RTE_CACHE_LINE_SIZE);
446 			if (!dpaa2_q->q_storage)
447 				goto fail_tx_conf;
448 
449 			memset(dpaa2_q->q_storage, 0,
450 			       sizeof(struct queue_storage_info_t));
451 			if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
452 				goto fail_tx_conf;
453 		}
454 	}
455 
456 	vq_id = 0;
457 	for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
458 		mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
459 		mcq->tc_index = dist_idx / num_rxqueue_per_tc;
460 		mcq->flow_id = dist_idx % num_rxqueue_per_tc;
461 		vq_id++;
462 	}
463 
464 	return 0;
465 fail_tx_conf:
466 	i -= 1;
467 	while (i >= 0) {
468 		dpaa2_q = (struct dpaa2_queue *)priv->tx_conf_vq[i];
469 		rte_free(dpaa2_q->q_storage);
470 		priv->tx_conf_vq[i--] = NULL;
471 	}
472 	i = priv->nb_tx_queues;
473 fail_tx:
474 	i -= 1;
475 	while (i >= 0) {
476 		dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
477 		rte_free(dpaa2_q->cscn);
478 		priv->tx_vq[i--] = NULL;
479 	}
480 	i = priv->nb_rx_queues;
481 fail:
482 	i -= 1;
483 	mc_q = priv->rx_vq[0];
484 	while (i >= 0) {
485 		dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
486 		dpaa2_free_dq_storage(dpaa2_q->q_storage);
487 		rte_free(dpaa2_q->q_storage);
488 		priv->rx_vq[i--] = NULL;
489 	}
490 
491 	if (dpaa2_enable_err_queue) {
492 		dpaa2_q = (struct dpaa2_queue *)priv->rx_err_vq;
493 		if (dpaa2_q->q_storage)
494 			dpaa2_free_dq_storage(dpaa2_q->q_storage);
495 		rte_free(dpaa2_q->q_storage);
496 	}
497 
498 	rte_free(mc_q);
499 	return -1;
500 }
501 
502 static void
503 dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
504 {
505 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
506 	struct dpaa2_queue *dpaa2_q;
507 	int i;
508 
509 	PMD_INIT_FUNC_TRACE();
510 
511 	/* Queue allocation base */
512 	if (priv->rx_vq[0]) {
513 		/* cleaning up queue storage */
514 		for (i = 0; i < priv->nb_rx_queues; i++) {
515 			dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
516 			rte_free(dpaa2_q->q_storage);
517 		}
518 		/* cleanup tx queue cscn */
519 		for (i = 0; i < priv->nb_tx_queues; i++) {
520 			dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
521 			rte_free(dpaa2_q->cscn);
522 		}
523 		if (priv->flags & DPAA2_TX_CONF_ENABLE) {
524 			/* cleanup tx conf queue storage */
525 			for (i = 0; i < priv->nb_tx_queues; i++) {
526 				dpaa2_q = (struct dpaa2_queue *)
527 						priv->tx_conf_vq[i];
528 				rte_free(dpaa2_q->q_storage);
529 			}
530 		}
531 		/*free memory for all queues (RX+TX) */
532 		rte_free(priv->rx_vq[0]);
533 		priv->rx_vq[0] = NULL;
534 	}
535 }
536 
537 static int
538 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
539 {
540 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
541 	struct fsl_mc_io *dpni = dev->process_private;
542 	struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
543 	uint64_t rx_offloads = eth_conf->rxmode.offloads;
544 	uint64_t tx_offloads = eth_conf->txmode.offloads;
545 	int rx_l3_csum_offload = false;
546 	int rx_l4_csum_offload = false;
547 	int tx_l3_csum_offload = false;
548 	int tx_l4_csum_offload = false;
549 	int ret, tc_index;
550 	uint32_t max_rx_pktlen;
551 
552 	PMD_INIT_FUNC_TRACE();
553 
554 	/* Rx offloads which are enabled by default */
555 	if (dev_rx_offloads_nodis & ~rx_offloads) {
556 		DPAA2_PMD_INFO(
557 		"Some of rx offloads enabled by default - requested 0x%" PRIx64
558 		" fixed are 0x%" PRIx64,
559 		rx_offloads, dev_rx_offloads_nodis);
560 	}
561 
562 	/* Tx offloads which are enabled by default */
563 	if (dev_tx_offloads_nodis & ~tx_offloads) {
564 		DPAA2_PMD_INFO(
565 		"Some of tx offloads enabled by default - requested 0x%" PRIx64
566 		" fixed are 0x%" PRIx64,
567 		tx_offloads, dev_tx_offloads_nodis);
568 	}
569 
570 	max_rx_pktlen = eth_conf->rxmode.mtu + RTE_ETHER_HDR_LEN +
571 				RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
572 	if (max_rx_pktlen <= DPAA2_MAX_RX_PKT_LEN) {
573 		ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
574 			priv->token, max_rx_pktlen - RTE_ETHER_CRC_LEN);
575 		if (ret != 0) {
576 			DPAA2_PMD_ERR("Unable to set mtu. check config");
577 			return ret;
578 		}
579 		DPAA2_PMD_INFO("MTU configured for the device: %d",
580 				dev->data->mtu);
581 	} else {
582 		return -1;
583 	}
584 
585 	if (eth_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) {
586 		for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
587 			ret = dpaa2_setup_flow_dist(dev,
588 					eth_conf->rx_adv_conf.rss_conf.rss_hf,
589 					tc_index);
590 			if (ret) {
591 				DPAA2_PMD_ERR(
592 					"Unable to set flow distribution on tc%d."
593 					"Check queue config", tc_index);
594 				return ret;
595 			}
596 		}
597 	}
598 
599 	if (rx_offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
600 		rx_l3_csum_offload = true;
601 
602 	if ((rx_offloads & RTE_ETH_RX_OFFLOAD_UDP_CKSUM) ||
603 		(rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_CKSUM) ||
604 		(rx_offloads & RTE_ETH_RX_OFFLOAD_SCTP_CKSUM))
605 		rx_l4_csum_offload = true;
606 
607 	ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
608 			       DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
609 	if (ret) {
610 		DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
611 		return ret;
612 	}
613 
614 	ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
615 			       DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
616 	if (ret) {
617 		DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
618 		return ret;
619 	}
620 
621 #if !defined(RTE_LIBRTE_IEEE1588)
622 	if (rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
623 #endif
624 	{
625 		ret = rte_mbuf_dyn_rx_timestamp_register(
626 				&dpaa2_timestamp_dynfield_offset,
627 				&dpaa2_timestamp_rx_dynflag);
628 		if (ret != 0) {
629 			DPAA2_PMD_ERR("Error to register timestamp field/flag");
630 			return -rte_errno;
631 		}
632 		dpaa2_enable_ts[dev->data->port_id] = true;
633 	}
634 
635 	if (tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)
636 		tx_l3_csum_offload = true;
637 
638 	if ((tx_offloads & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) ||
639 		(tx_offloads & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) ||
640 		(tx_offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM))
641 		tx_l4_csum_offload = true;
642 
643 	ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
644 			       DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
645 	if (ret) {
646 		DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
647 		return ret;
648 	}
649 
650 	ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
651 			       DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
652 	if (ret) {
653 		DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
654 		return ret;
655 	}
656 
657 	/* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
658 	 * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
659 	 * to 0 for LS2 in the hardware thus disabling data/annotation
660 	 * stashing. For LX2 this is fixed in hardware and thus hash result and
661 	 * parse results can be received in FD using this option.
662 	 */
663 	if (dpaa2_svr_family == SVR_LX2160A) {
664 		ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
665 				       DPNI_FLCTYPE_HASH, true);
666 		if (ret) {
667 			DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
668 			return ret;
669 		}
670 	}
671 
672 	if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
673 		dpaa2_vlan_offload_set(dev, RTE_ETH_VLAN_FILTER_MASK);
674 
675 	if (eth_conf->lpbk_mode) {
676 		ret = dpaa2_dev_recycle_config(dev);
677 		if (ret) {
678 			DPAA2_PMD_ERR("Error to configure %s to recycle port.",
679 				dev->data->name);
680 
681 			return ret;
682 		}
683 	} else {
684 		/** User may disable loopback mode by calling
685 		 * "dev_configure" with lpbk_mode cleared.
686 		 * No matter the port was configured recycle or not,
687 		 * recycle de-configure is called here.
688 		 * If port is not recycled, the de-configure will return directly.
689 		 */
690 		ret = dpaa2_dev_recycle_deconfig(dev);
691 		if (ret) {
692 			DPAA2_PMD_ERR("Error to de-configure recycle port %s.",
693 				dev->data->name);
694 
695 			return ret;
696 		}
697 	}
698 
699 	dpaa2_tm_init(dev);
700 
701 	return 0;
702 }
703 
704 /* Function to setup RX flow information. It contains traffic class ID,
705  * flow ID, destination configuration etc.
706  */
707 static int
708 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
709 			 uint16_t rx_queue_id,
710 			 uint16_t nb_rx_desc,
711 			 unsigned int socket_id __rte_unused,
712 			 const struct rte_eth_rxconf *rx_conf,
713 			 struct rte_mempool *mb_pool)
714 {
715 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
716 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
717 	struct dpaa2_queue *dpaa2_q;
718 	struct dpni_queue cfg;
719 	uint8_t options = 0;
720 	uint8_t flow_id;
721 	uint32_t bpid;
722 	int i, ret;
723 
724 	PMD_INIT_FUNC_TRACE();
725 
726 	DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
727 			dev, rx_queue_id, mb_pool, rx_conf);
728 
729 	total_nb_rx_desc += nb_rx_desc;
730 	if (total_nb_rx_desc > MAX_NB_RX_DESC) {
731 		DPAA2_PMD_WARN("\nTotal nb_rx_desc exceeds %d limit. Please use Normal buffers",
732 			       MAX_NB_RX_DESC);
733 		DPAA2_PMD_WARN("To use Normal buffers, run 'export DPNI_NORMAL_BUF=1' before running dynamic_dpl.sh script");
734 	}
735 
736 	/* Rx deferred start is not supported */
737 	if (rx_conf->rx_deferred_start) {
738 		DPAA2_PMD_ERR("%p:Rx deferred start not supported",
739 				(void *)dev);
740 		return -EINVAL;
741 	}
742 
743 	if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
744 		if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
745 			ret = rte_dpaa2_bpid_info_init(mb_pool);
746 			if (ret)
747 				return ret;
748 		}
749 		bpid = mempool_to_bpid(mb_pool);
750 		ret = dpaa2_attach_bp_list(priv, dpni,
751 				rte_dpaa2_bpid_info[bpid].bp_list);
752 		if (ret)
753 			return ret;
754 	}
755 	dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
756 	dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
757 	dpaa2_q->bp_array = rte_dpaa2_bpid_info;
758 	dpaa2_q->nb_desc = UINT16_MAX;
759 	dpaa2_q->offloads = rx_conf->offloads;
760 
761 	/*Get the flow id from given VQ id*/
762 	flow_id = dpaa2_q->flow_id;
763 	memset(&cfg, 0, sizeof(struct dpni_queue));
764 
765 	options = options | DPNI_QUEUE_OPT_USER_CTX;
766 	cfg.user_context = (size_t)(dpaa2_q);
767 
768 	/* check if a private cgr available. */
769 	for (i = 0; i < priv->max_cgs; i++) {
770 		if (!priv->cgid_in_use[i]) {
771 			priv->cgid_in_use[i] = 1;
772 			break;
773 		}
774 	}
775 
776 	if (i < priv->max_cgs) {
777 		options |= DPNI_QUEUE_OPT_SET_CGID;
778 		cfg.cgid = i;
779 		dpaa2_q->cgid = cfg.cgid;
780 	} else {
781 		dpaa2_q->cgid = 0xff;
782 	}
783 
784 	/*if ls2088 or rev2 device, enable the stashing */
785 
786 	if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
787 		options |= DPNI_QUEUE_OPT_FLC;
788 		cfg.flc.stash_control = true;
789 		cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
790 		/* 00 00 00 - last 6 bit represent annotation, context stashing,
791 		 * data stashing setting 01 01 00 (0x14)
792 		 * (in following order ->DS AS CS)
793 		 * to enable 1 line data, 1 line annotation.
794 		 * For LX2, this setting should be 01 00 00 (0x10)
795 		 */
796 		if ((dpaa2_svr_family & 0xffff0000) == SVR_LX2160A)
797 			cfg.flc.value |= 0x10;
798 		else
799 			cfg.flc.value |= 0x14;
800 	}
801 	ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
802 			     dpaa2_q->tc_index, flow_id, options, &cfg);
803 	if (ret) {
804 		DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
805 		return -1;
806 	}
807 
808 	if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
809 		struct dpni_taildrop taildrop;
810 
811 		taildrop.enable = 1;
812 		dpaa2_q->nb_desc = nb_rx_desc;
813 		/* Private CGR will use tail drop length as nb_rx_desc.
814 		 * for rest cases we can use standard byte based tail drop.
815 		 * There is no HW restriction, but number of CGRs are limited,
816 		 * hence this restriction is placed.
817 		 */
818 		if (dpaa2_q->cgid != 0xff) {
819 			/*enabling per rx queue congestion control */
820 			taildrop.threshold = nb_rx_desc;
821 			taildrop.units = DPNI_CONGESTION_UNIT_FRAMES;
822 			taildrop.oal = 0;
823 			DPAA2_PMD_DEBUG("Enabling CG Tail Drop on queue = %d",
824 					rx_queue_id);
825 			ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
826 						DPNI_CP_CONGESTION_GROUP,
827 						DPNI_QUEUE_RX,
828 						dpaa2_q->tc_index,
829 						dpaa2_q->cgid, &taildrop);
830 		} else {
831 			/*enabling per rx queue congestion control */
832 			taildrop.threshold = CONG_THRESHOLD_RX_BYTES_Q;
833 			taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
834 			taildrop.oal = CONG_RX_OAL;
835 			DPAA2_PMD_DEBUG("Enabling Byte based Drop on queue= %d",
836 					rx_queue_id);
837 			ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
838 						DPNI_CP_QUEUE, DPNI_QUEUE_RX,
839 						dpaa2_q->tc_index, flow_id,
840 						&taildrop);
841 		}
842 		if (ret) {
843 			DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
844 				      ret);
845 			return -1;
846 		}
847 	} else { /* Disable tail Drop */
848 		struct dpni_taildrop taildrop = {0};
849 		DPAA2_PMD_INFO("Tail drop is disabled on queue");
850 
851 		taildrop.enable = 0;
852 		if (dpaa2_q->cgid != 0xff) {
853 			ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
854 					DPNI_CP_CONGESTION_GROUP, DPNI_QUEUE_RX,
855 					dpaa2_q->tc_index,
856 					dpaa2_q->cgid, &taildrop);
857 		} else {
858 			ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
859 					DPNI_CP_QUEUE, DPNI_QUEUE_RX,
860 					dpaa2_q->tc_index, flow_id, &taildrop);
861 		}
862 		if (ret) {
863 			DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
864 				      ret);
865 			return -1;
866 		}
867 	}
868 
869 	dev->data->rx_queues[rx_queue_id] = dpaa2_q;
870 	return 0;
871 }
872 
873 static int
874 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
875 			 uint16_t tx_queue_id,
876 			 uint16_t nb_tx_desc,
877 			 unsigned int socket_id __rte_unused,
878 			 const struct rte_eth_txconf *tx_conf)
879 {
880 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
881 	struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
882 		priv->tx_vq[tx_queue_id];
883 	struct dpaa2_queue *dpaa2_tx_conf_q = (struct dpaa2_queue *)
884 		priv->tx_conf_vq[tx_queue_id];
885 	struct fsl_mc_io *dpni = dev->process_private;
886 	struct dpni_queue tx_conf_cfg;
887 	struct dpni_queue tx_flow_cfg;
888 	uint8_t options = 0, flow_id;
889 	uint16_t channel_id;
890 	struct dpni_queue_id qid;
891 	uint32_t tc_id;
892 	int ret;
893 
894 	PMD_INIT_FUNC_TRACE();
895 
896 	/* Tx deferred start is not supported */
897 	if (tx_conf->tx_deferred_start) {
898 		DPAA2_PMD_ERR("%p:Tx deferred start not supported",
899 				(void *)dev);
900 		return -EINVAL;
901 	}
902 
903 	dpaa2_q->nb_desc = UINT16_MAX;
904 	dpaa2_q->offloads = tx_conf->offloads;
905 
906 	/* Return if queue already configured */
907 	if (dpaa2_q->flow_id != 0xffff) {
908 		dev->data->tx_queues[tx_queue_id] = dpaa2_q;
909 		return 0;
910 	}
911 
912 	memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
913 	memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
914 
915 	if (tx_queue_id == 0) {
916 		/*Set tx-conf and error configuration*/
917 		if (priv->flags & DPAA2_TX_CONF_ENABLE)
918 			ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
919 							    priv->token,
920 							    DPNI_CONF_AFFINE);
921 		else
922 			ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
923 							    priv->token,
924 							    DPNI_CONF_DISABLE);
925 		if (ret) {
926 			DPAA2_PMD_ERR("Error in set tx conf mode settings: "
927 				      "err=%d", ret);
928 			return -1;
929 		}
930 	}
931 
932 	tc_id = tx_queue_id % priv->num_tx_tc;
933 	channel_id = (uint8_t)(tx_queue_id / priv->num_tx_tc) % priv->num_channels;
934 	flow_id = 0;
935 
936 	ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
937 			((channel_id << 8) | tc_id), flow_id, options, &tx_flow_cfg);
938 	if (ret) {
939 		DPAA2_PMD_ERR("Error in setting the tx flow: "
940 			"tc_id=%d, flow=%d err=%d",
941 			tc_id, flow_id, ret);
942 			return -1;
943 	}
944 
945 	dpaa2_q->flow_id = flow_id;
946 
947 	dpaa2_q->tc_index = tc_id;
948 
949 	ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
950 			     DPNI_QUEUE_TX, ((channel_id << 8) | dpaa2_q->tc_index),
951 			     dpaa2_q->flow_id, &tx_flow_cfg, &qid);
952 	if (ret) {
953 		DPAA2_PMD_ERR("Error in getting LFQID err=%d", ret);
954 		return -1;
955 	}
956 	dpaa2_q->fqid = qid.fqid;
957 
958 	if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
959 		struct dpni_congestion_notification_cfg cong_notif_cfg = {0};
960 
961 		dpaa2_q->nb_desc = nb_tx_desc;
962 
963 		cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
964 		cong_notif_cfg.threshold_entry = nb_tx_desc;
965 		/* Notify that the queue is not congested when the data in
966 		 * the queue is below this threshold.(90% of value)
967 		 */
968 		cong_notif_cfg.threshold_exit = (nb_tx_desc * 9) / 10;
969 		cong_notif_cfg.message_ctx = 0;
970 		cong_notif_cfg.message_iova =
971 				(size_t)DPAA2_VADDR_TO_IOVA(dpaa2_q->cscn);
972 		cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
973 		cong_notif_cfg.notification_mode =
974 					 DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
975 					 DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
976 					 DPNI_CONG_OPT_COHERENT_WRITE;
977 		cong_notif_cfg.cg_point = DPNI_CP_QUEUE;
978 
979 		ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
980 						       priv->token,
981 						       DPNI_QUEUE_TX,
982 						       ((channel_id << 8) | tc_id),
983 						       &cong_notif_cfg);
984 		if (ret) {
985 			DPAA2_PMD_ERR(
986 			   "Error in setting tx congestion notification: "
987 			   "err=%d", ret);
988 			return -ret;
989 		}
990 	}
991 	dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
992 	dev->data->tx_queues[tx_queue_id] = dpaa2_q;
993 
994 	if (priv->flags & DPAA2_TX_CONF_ENABLE) {
995 		dpaa2_q->tx_conf_queue = dpaa2_tx_conf_q;
996 		options = options | DPNI_QUEUE_OPT_USER_CTX;
997 		tx_conf_cfg.user_context = (size_t)(dpaa2_q);
998 		ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token,
999 			     DPNI_QUEUE_TX_CONFIRM, ((channel_id << 8) | dpaa2_tx_conf_q->tc_index),
1000 			     dpaa2_tx_conf_q->flow_id, options, &tx_conf_cfg);
1001 		if (ret) {
1002 			DPAA2_PMD_ERR("Error in setting the tx conf flow: "
1003 			      "tc_index=%d, flow=%d err=%d",
1004 			      dpaa2_tx_conf_q->tc_index,
1005 			      dpaa2_tx_conf_q->flow_id, ret);
1006 			return -1;
1007 		}
1008 
1009 		ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
1010 			     DPNI_QUEUE_TX_CONFIRM, ((channel_id << 8) | dpaa2_tx_conf_q->tc_index),
1011 			     dpaa2_tx_conf_q->flow_id, &tx_conf_cfg, &qid);
1012 		if (ret) {
1013 			DPAA2_PMD_ERR("Error in getting LFQID err=%d", ret);
1014 			return -1;
1015 		}
1016 		dpaa2_tx_conf_q->fqid = qid.fqid;
1017 	}
1018 	return 0;
1019 }
1020 
1021 static void
1022 dpaa2_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1023 {
1024 	struct dpaa2_queue *dpaa2_q = dev->data->rx_queues[rx_queue_id];
1025 	struct dpaa2_dev_priv *priv = dpaa2_q->eth_data->dev_private;
1026 	struct fsl_mc_io *dpni =
1027 		(struct fsl_mc_io *)priv->eth_dev->process_private;
1028 	uint8_t options = 0;
1029 	int ret;
1030 	struct dpni_queue cfg;
1031 
1032 	memset(&cfg, 0, sizeof(struct dpni_queue));
1033 	PMD_INIT_FUNC_TRACE();
1034 
1035 	total_nb_rx_desc -= dpaa2_q->nb_desc;
1036 
1037 	if (dpaa2_q->cgid != 0xff) {
1038 		options = DPNI_QUEUE_OPT_CLEAR_CGID;
1039 		cfg.cgid = dpaa2_q->cgid;
1040 
1041 		ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token,
1042 				     DPNI_QUEUE_RX,
1043 				     dpaa2_q->tc_index, dpaa2_q->flow_id,
1044 				     options, &cfg);
1045 		if (ret)
1046 			DPAA2_PMD_ERR("Unable to clear CGR from q=%u err=%d",
1047 					dpaa2_q->fqid, ret);
1048 		priv->cgid_in_use[dpaa2_q->cgid] = 0;
1049 		dpaa2_q->cgid = 0xff;
1050 	}
1051 }
1052 
1053 static uint32_t
1054 dpaa2_dev_rx_queue_count(void *rx_queue)
1055 {
1056 	int32_t ret;
1057 	struct dpaa2_queue *dpaa2_q;
1058 	struct qbman_swp *swp;
1059 	struct qbman_fq_query_np_rslt state;
1060 	uint32_t frame_cnt = 0;
1061 
1062 	if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
1063 		ret = dpaa2_affine_qbman_swp();
1064 		if (ret) {
1065 			DPAA2_PMD_ERR(
1066 				"Failed to allocate IO portal, tid: %d\n",
1067 				rte_gettid());
1068 			return -EINVAL;
1069 		}
1070 	}
1071 	swp = DPAA2_PER_LCORE_PORTAL;
1072 
1073 	dpaa2_q = rx_queue;
1074 
1075 	if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
1076 		frame_cnt = qbman_fq_state_frame_count(&state);
1077 		DPAA2_PMD_DP_DEBUG("RX frame count for q(%p) is %u",
1078 				rx_queue, frame_cnt);
1079 	}
1080 	return frame_cnt;
1081 }
1082 
1083 static const uint32_t *
1084 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
1085 {
1086 	static const uint32_t ptypes[] = {
1087 		/*todo -= add more types */
1088 		RTE_PTYPE_L2_ETHER,
1089 		RTE_PTYPE_L3_IPV4,
1090 		RTE_PTYPE_L3_IPV4_EXT,
1091 		RTE_PTYPE_L3_IPV6,
1092 		RTE_PTYPE_L3_IPV6_EXT,
1093 		RTE_PTYPE_L4_TCP,
1094 		RTE_PTYPE_L4_UDP,
1095 		RTE_PTYPE_L4_SCTP,
1096 		RTE_PTYPE_L4_ICMP,
1097 		RTE_PTYPE_UNKNOWN
1098 	};
1099 
1100 	if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
1101 		dev->rx_pkt_burst == dpaa2_dev_rx ||
1102 		dev->rx_pkt_burst == dpaa2_dev_loopback_rx)
1103 		return ptypes;
1104 	return NULL;
1105 }
1106 
1107 /**
1108  * Dpaa2 link Interrupt handler
1109  *
1110  * @param param
1111  *  The address of parameter (struct rte_eth_dev *) registered before.
1112  *
1113  * @return
1114  *  void
1115  */
1116 static void
1117 dpaa2_interrupt_handler(void *param)
1118 {
1119 	struct rte_eth_dev *dev = param;
1120 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1121 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1122 	int ret;
1123 	int irq_index = DPNI_IRQ_INDEX;
1124 	unsigned int status = 0, clear = 0;
1125 
1126 	PMD_INIT_FUNC_TRACE();
1127 
1128 	if (dpni == NULL) {
1129 		DPAA2_PMD_ERR("dpni is NULL");
1130 		return;
1131 	}
1132 
1133 	ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
1134 				  irq_index, &status);
1135 	if (unlikely(ret)) {
1136 		DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
1137 		clear = 0xffffffff;
1138 		goto out;
1139 	}
1140 
1141 	if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
1142 		clear = DPNI_IRQ_EVENT_LINK_CHANGED;
1143 		dpaa2_dev_link_update(dev, 0);
1144 		/* calling all the apps registered for link status event */
1145 		rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1146 	}
1147 out:
1148 	ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
1149 				    irq_index, clear);
1150 	if (unlikely(ret))
1151 		DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
1152 }
1153 
1154 static int
1155 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
1156 {
1157 	int err = 0;
1158 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1159 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1160 	int irq_index = DPNI_IRQ_INDEX;
1161 	unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
1162 
1163 	PMD_INIT_FUNC_TRACE();
1164 
1165 	err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
1166 				irq_index, mask);
1167 	if (err < 0) {
1168 		DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
1169 			      strerror(-err));
1170 		return err;
1171 	}
1172 
1173 	err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
1174 				  irq_index, enable);
1175 	if (err < 0)
1176 		DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
1177 			      strerror(-err));
1178 
1179 	return err;
1180 }
1181 
1182 static int
1183 dpaa2_dev_start(struct rte_eth_dev *dev)
1184 {
1185 	struct rte_device *rdev = dev->device;
1186 	struct rte_dpaa2_device *dpaa2_dev;
1187 	struct rte_eth_dev_data *data = dev->data;
1188 	struct dpaa2_dev_priv *priv = data->dev_private;
1189 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1190 	struct dpni_queue cfg;
1191 	struct dpni_error_cfg	err_cfg;
1192 	struct dpni_queue_id qid;
1193 	struct dpaa2_queue *dpaa2_q;
1194 	int ret, i;
1195 	struct rte_intr_handle *intr_handle;
1196 
1197 	dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
1198 	intr_handle = dpaa2_dev->intr_handle;
1199 
1200 	PMD_INIT_FUNC_TRACE();
1201 	ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1202 	if (ret) {
1203 		DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
1204 			      priv->hw_id, ret);
1205 		return ret;
1206 	}
1207 
1208 	/* Power up the phy. Needed to make the link go UP */
1209 	dpaa2_dev_set_link_up(dev);
1210 
1211 	for (i = 0; i < data->nb_rx_queues; i++) {
1212 		dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
1213 		ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
1214 				     DPNI_QUEUE_RX, dpaa2_q->tc_index,
1215 				       dpaa2_q->flow_id, &cfg, &qid);
1216 		if (ret) {
1217 			DPAA2_PMD_ERR("Error in getting flow information: "
1218 				      "err=%d", ret);
1219 			return ret;
1220 		}
1221 		dpaa2_q->fqid = qid.fqid;
1222 	}
1223 
1224 	if (dpaa2_enable_err_queue) {
1225 		ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
1226 				     DPNI_QUEUE_RX_ERR, 0, 0, &cfg, &qid);
1227 		if (ret) {
1228 			DPAA2_PMD_ERR("Error getting rx err flow information: err=%d",
1229 						ret);
1230 			return ret;
1231 		}
1232 		dpaa2_q = (struct dpaa2_queue *)priv->rx_err_vq;
1233 		dpaa2_q->fqid = qid.fqid;
1234 		dpaa2_q->eth_data = dev->data;
1235 
1236 		err_cfg.errors =  DPNI_ERROR_DISC;
1237 		err_cfg.error_action = DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE;
1238 	} else {
1239 		/* checksum errors, send them to normal path
1240 		 * and set it in annotation
1241 		 */
1242 		err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
1243 
1244 		/* if packet with parse error are not to be dropped */
1245 		err_cfg.errors |= DPNI_ERROR_PHE;
1246 
1247 		err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
1248 	}
1249 	err_cfg.set_frame_annotation = true;
1250 
1251 	ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
1252 				       priv->token, &err_cfg);
1253 	if (ret) {
1254 		DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
1255 			      ret);
1256 		return ret;
1257 	}
1258 
1259 	/* if the interrupts were configured on this devices*/
1260 	if (intr_handle && rte_intr_fd_get(intr_handle) &&
1261 	    dev->data->dev_conf.intr_conf.lsc != 0) {
1262 		/* Registering LSC interrupt handler */
1263 		rte_intr_callback_register(intr_handle,
1264 					   dpaa2_interrupt_handler,
1265 					   (void *)dev);
1266 
1267 		/* enable vfio intr/eventfd mapping
1268 		 * Interrupt index 0 is required, so we can not use
1269 		 * rte_intr_enable.
1270 		 */
1271 		rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
1272 
1273 		/* enable dpni_irqs */
1274 		dpaa2_eth_setup_irqs(dev, 1);
1275 	}
1276 
1277 	/* Change the tx burst function if ordered queues are used */
1278 	if (priv->en_ordered)
1279 		dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
1280 
1281 	for (i = 0; i < dev->data->nb_rx_queues; i++)
1282 		dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1283 	for (i = 0; i < dev->data->nb_tx_queues; i++)
1284 		dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1285 
1286 	return 0;
1287 }
1288 
1289 /**
1290  *  This routine disables all traffic on the adapter by issuing a
1291  *  global reset on the MAC.
1292  */
1293 static int
1294 dpaa2_dev_stop(struct rte_eth_dev *dev)
1295 {
1296 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1297 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1298 	int ret;
1299 	struct rte_eth_link link;
1300 	struct rte_device *rdev = dev->device;
1301 	struct rte_intr_handle *intr_handle;
1302 	struct rte_dpaa2_device *dpaa2_dev;
1303 	uint16_t i;
1304 
1305 	dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
1306 	intr_handle = dpaa2_dev->intr_handle;
1307 
1308 	PMD_INIT_FUNC_TRACE();
1309 
1310 	/* reset interrupt callback  */
1311 	if (intr_handle && rte_intr_fd_get(intr_handle) &&
1312 	    dev->data->dev_conf.intr_conf.lsc != 0) {
1313 		/*disable dpni irqs */
1314 		dpaa2_eth_setup_irqs(dev, 0);
1315 
1316 		/* disable vfio intr before callback unregister */
1317 		rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
1318 
1319 		/* Unregistering LSC interrupt handler */
1320 		rte_intr_callback_unregister(intr_handle,
1321 					     dpaa2_interrupt_handler,
1322 					     (void *)dev);
1323 	}
1324 
1325 	dpaa2_dev_set_link_down(dev);
1326 
1327 	ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
1328 	if (ret) {
1329 		DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
1330 			      ret, priv->hw_id);
1331 		return ret;
1332 	}
1333 
1334 	/* clear the recorded link status */
1335 	memset(&link, 0, sizeof(link));
1336 	rte_eth_linkstatus_set(dev, &link);
1337 
1338 	for (i = 0; i < dev->data->nb_rx_queues; i++)
1339 		dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1340 	for (i = 0; i < dev->data->nb_tx_queues; i++)
1341 		dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1342 
1343 	return 0;
1344 }
1345 
1346 static int
1347 dpaa2_dev_close(struct rte_eth_dev *dev)
1348 {
1349 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1350 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1351 	int i, ret;
1352 	struct rte_eth_link link;
1353 
1354 	PMD_INIT_FUNC_TRACE();
1355 
1356 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1357 		return 0;
1358 
1359 	if (!dpni) {
1360 		DPAA2_PMD_WARN("Already closed or not started");
1361 		return -1;
1362 	}
1363 
1364 	dpaa2_tm_deinit(dev);
1365 	dpaa2_flow_clean(dev);
1366 	/* Clean the device first */
1367 	ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
1368 	if (ret) {
1369 		DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
1370 		return -1;
1371 	}
1372 
1373 	memset(&link, 0, sizeof(link));
1374 	rte_eth_linkstatus_set(dev, &link);
1375 
1376 	/* Free private queues memory */
1377 	dpaa2_free_rx_tx_queues(dev);
1378 	/* Close the device at underlying layer*/
1379 	ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
1380 	if (ret) {
1381 		DPAA2_PMD_ERR("Failure closing dpni device with err code %d",
1382 			      ret);
1383 	}
1384 
1385 	/* Free the allocated memory for ethernet private data and dpni*/
1386 	priv->hw = NULL;
1387 	dev->process_private = NULL;
1388 	rte_free(dpni);
1389 
1390 	for (i = 0; i < MAX_TCS; i++)
1391 		rte_free((void *)(size_t)priv->extract.tc_extract_param[i]);
1392 
1393 	if (priv->extract.qos_extract_param)
1394 		rte_free((void *)(size_t)priv->extract.qos_extract_param);
1395 
1396 	DPAA2_PMD_INFO("%s: netdev deleted", dev->data->name);
1397 	return 0;
1398 }
1399 
1400 static int
1401 dpaa2_dev_promiscuous_enable(
1402 		struct rte_eth_dev *dev)
1403 {
1404 	int ret;
1405 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1406 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1407 
1408 	PMD_INIT_FUNC_TRACE();
1409 
1410 	if (dpni == NULL) {
1411 		DPAA2_PMD_ERR("dpni is NULL");
1412 		return -ENODEV;
1413 	}
1414 
1415 	ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1416 	if (ret < 0)
1417 		DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
1418 
1419 	ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1420 	if (ret < 0)
1421 		DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
1422 
1423 	return ret;
1424 }
1425 
1426 static int
1427 dpaa2_dev_promiscuous_disable(
1428 		struct rte_eth_dev *dev)
1429 {
1430 	int ret;
1431 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1432 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1433 
1434 	PMD_INIT_FUNC_TRACE();
1435 
1436 	if (dpni == NULL) {
1437 		DPAA2_PMD_ERR("dpni is NULL");
1438 		return -ENODEV;
1439 	}
1440 
1441 	ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1442 	if (ret < 0)
1443 		DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
1444 
1445 	if (dev->data->all_multicast == 0) {
1446 		ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
1447 						 priv->token, false);
1448 		if (ret < 0)
1449 			DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
1450 				      ret);
1451 	}
1452 
1453 	return ret;
1454 }
1455 
1456 static int
1457 dpaa2_dev_allmulticast_enable(
1458 		struct rte_eth_dev *dev)
1459 {
1460 	int ret;
1461 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1462 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1463 
1464 	PMD_INIT_FUNC_TRACE();
1465 
1466 	if (dpni == NULL) {
1467 		DPAA2_PMD_ERR("dpni is NULL");
1468 		return -ENODEV;
1469 	}
1470 
1471 	ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1472 	if (ret < 0)
1473 		DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
1474 
1475 	return ret;
1476 }
1477 
1478 static int
1479 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
1480 {
1481 	int ret;
1482 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1483 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1484 
1485 	PMD_INIT_FUNC_TRACE();
1486 
1487 	if (dpni == NULL) {
1488 		DPAA2_PMD_ERR("dpni is NULL");
1489 		return -ENODEV;
1490 	}
1491 
1492 	/* must remain on for all promiscuous */
1493 	if (dev->data->promiscuous == 1)
1494 		return 0;
1495 
1496 	ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1497 	if (ret < 0)
1498 		DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
1499 
1500 	return ret;
1501 }
1502 
1503 static int
1504 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1505 {
1506 	int ret;
1507 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1508 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1509 	uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
1510 				+ VLAN_TAG_SIZE;
1511 
1512 	PMD_INIT_FUNC_TRACE();
1513 
1514 	if (dpni == NULL) {
1515 		DPAA2_PMD_ERR("dpni is NULL");
1516 		return -EINVAL;
1517 	}
1518 
1519 	/* Set the Max Rx frame length as 'mtu' +
1520 	 * Maximum Ethernet header length
1521 	 */
1522 	ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
1523 					frame_size - RTE_ETHER_CRC_LEN);
1524 	if (ret) {
1525 		DPAA2_PMD_ERR("Setting the max frame length failed");
1526 		return -1;
1527 	}
1528 	DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
1529 	return 0;
1530 }
1531 
1532 static int
1533 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
1534 		       struct rte_ether_addr *addr,
1535 		       __rte_unused uint32_t index,
1536 		       __rte_unused uint32_t pool)
1537 {
1538 	int ret;
1539 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1540 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1541 
1542 	PMD_INIT_FUNC_TRACE();
1543 
1544 	if (dpni == NULL) {
1545 		DPAA2_PMD_ERR("dpni is NULL");
1546 		return -1;
1547 	}
1548 
1549 	ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW, priv->token,
1550 				addr->addr_bytes, 0, 0, 0);
1551 	if (ret)
1552 		DPAA2_PMD_ERR(
1553 			"error: Adding the MAC ADDR failed: err = %d", ret);
1554 	return 0;
1555 }
1556 
1557 static void
1558 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1559 			  uint32_t index)
1560 {
1561 	int ret;
1562 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1563 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1564 	struct rte_eth_dev_data *data = dev->data;
1565 	struct rte_ether_addr *macaddr;
1566 
1567 	PMD_INIT_FUNC_TRACE();
1568 
1569 	macaddr = &data->mac_addrs[index];
1570 
1571 	if (dpni == NULL) {
1572 		DPAA2_PMD_ERR("dpni is NULL");
1573 		return;
1574 	}
1575 
1576 	ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1577 				   priv->token, macaddr->addr_bytes);
1578 	if (ret)
1579 		DPAA2_PMD_ERR(
1580 			"error: Removing the MAC ADDR failed: err = %d", ret);
1581 }
1582 
1583 static int
1584 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1585 		       struct rte_ether_addr *addr)
1586 {
1587 	int ret;
1588 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1589 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1590 
1591 	PMD_INIT_FUNC_TRACE();
1592 
1593 	if (dpni == NULL) {
1594 		DPAA2_PMD_ERR("dpni is NULL");
1595 		return -EINVAL;
1596 	}
1597 
1598 	ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1599 					priv->token, addr->addr_bytes);
1600 
1601 	if (ret)
1602 		DPAA2_PMD_ERR(
1603 			"error: Setting the MAC ADDR failed %d", ret);
1604 
1605 	return ret;
1606 }
1607 
1608 static
1609 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1610 			 struct rte_eth_stats *stats)
1611 {
1612 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1613 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1614 	int32_t  retcode;
1615 	uint8_t page0 = 0, page1 = 1, page2 = 2;
1616 	union dpni_statistics value;
1617 	int i;
1618 	struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
1619 
1620 	memset(&value, 0, sizeof(union dpni_statistics));
1621 
1622 	PMD_INIT_FUNC_TRACE();
1623 
1624 	if (!dpni) {
1625 		DPAA2_PMD_ERR("dpni is NULL");
1626 		return -EINVAL;
1627 	}
1628 
1629 	if (!stats) {
1630 		DPAA2_PMD_ERR("stats is NULL");
1631 		return -EINVAL;
1632 	}
1633 
1634 	/*Get Counters from page_0*/
1635 	retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1636 				      page0, 0, &value);
1637 	if (retcode)
1638 		goto err;
1639 
1640 	stats->ipackets = value.page_0.ingress_all_frames;
1641 	stats->ibytes = value.page_0.ingress_all_bytes;
1642 
1643 	/*Get Counters from page_1*/
1644 	retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1645 				      page1, 0, &value);
1646 	if (retcode)
1647 		goto err;
1648 
1649 	stats->opackets = value.page_1.egress_all_frames;
1650 	stats->obytes = value.page_1.egress_all_bytes;
1651 
1652 	/*Get Counters from page_2*/
1653 	retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1654 				      page2, 0, &value);
1655 	if (retcode)
1656 		goto err;
1657 
1658 	/* Ingress drop frame count due to configured rules */
1659 	stats->ierrors = value.page_2.ingress_filtered_frames;
1660 	/* Ingress drop frame count due to error */
1661 	stats->ierrors += value.page_2.ingress_discarded_frames;
1662 
1663 	stats->oerrors = value.page_2.egress_discarded_frames;
1664 	stats->imissed = value.page_2.ingress_nobuffer_discards;
1665 
1666 	/* Fill in per queue stats */
1667 	for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1668 		(i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
1669 		dpaa2_rxq = (struct dpaa2_queue *)priv->rx_vq[i];
1670 		dpaa2_txq = (struct dpaa2_queue *)priv->tx_vq[i];
1671 		if (dpaa2_rxq)
1672 			stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
1673 		if (dpaa2_txq)
1674 			stats->q_opackets[i] = dpaa2_txq->tx_pkts;
1675 
1676 		/* Byte counting is not implemented */
1677 		stats->q_ibytes[i]   = 0;
1678 		stats->q_obytes[i]   = 0;
1679 	}
1680 
1681 	return 0;
1682 
1683 err:
1684 	DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1685 	return retcode;
1686 };
1687 
1688 static int
1689 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1690 		     unsigned int n)
1691 {
1692 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1693 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1694 	int32_t  retcode;
1695 	union dpni_statistics value[5] = {};
1696 	unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1697 
1698 	if (n < num)
1699 		return num;
1700 
1701 	if (xstats == NULL)
1702 		return 0;
1703 
1704 	/* Get Counters from page_0*/
1705 	retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1706 				      0, 0, &value[0]);
1707 	if (retcode)
1708 		goto err;
1709 
1710 	/* Get Counters from page_1*/
1711 	retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1712 				      1, 0, &value[1]);
1713 	if (retcode)
1714 		goto err;
1715 
1716 	/* Get Counters from page_2*/
1717 	retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1718 				      2, 0, &value[2]);
1719 	if (retcode)
1720 		goto err;
1721 
1722 	for (i = 0; i < priv->max_cgs; i++) {
1723 		if (!priv->cgid_in_use[i]) {
1724 			/* Get Counters from page_4*/
1725 			retcode = dpni_get_statistics(dpni, CMD_PRI_LOW,
1726 						      priv->token,
1727 						      4, 0, &value[4]);
1728 			if (retcode)
1729 				goto err;
1730 			break;
1731 		}
1732 	}
1733 
1734 	for (i = 0; i < num; i++) {
1735 		xstats[i].id = i;
1736 		xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1737 			raw.counter[dpaa2_xstats_strings[i].stats_id];
1738 	}
1739 	return i;
1740 err:
1741 	DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
1742 	return retcode;
1743 }
1744 
1745 static int
1746 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1747 		       struct rte_eth_xstat_name *xstats_names,
1748 		       unsigned int limit)
1749 {
1750 	unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1751 
1752 	if (limit < stat_cnt)
1753 		return stat_cnt;
1754 
1755 	if (xstats_names != NULL)
1756 		for (i = 0; i < stat_cnt; i++)
1757 			strlcpy(xstats_names[i].name,
1758 				dpaa2_xstats_strings[i].name,
1759 				sizeof(xstats_names[i].name));
1760 
1761 	return stat_cnt;
1762 }
1763 
1764 static int
1765 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1766 		       uint64_t *values, unsigned int n)
1767 {
1768 	unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1769 	uint64_t values_copy[stat_cnt];
1770 
1771 	if (!ids) {
1772 		struct dpaa2_dev_priv *priv = dev->data->dev_private;
1773 		struct fsl_mc_io *dpni =
1774 			(struct fsl_mc_io *)dev->process_private;
1775 		int32_t  retcode;
1776 		union dpni_statistics value[5] = {};
1777 
1778 		if (n < stat_cnt)
1779 			return stat_cnt;
1780 
1781 		if (!values)
1782 			return 0;
1783 
1784 		/* Get Counters from page_0*/
1785 		retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1786 					      0, 0, &value[0]);
1787 		if (retcode)
1788 			return 0;
1789 
1790 		/* Get Counters from page_1*/
1791 		retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1792 					      1, 0, &value[1]);
1793 		if (retcode)
1794 			return 0;
1795 
1796 		/* Get Counters from page_2*/
1797 		retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1798 					      2, 0, &value[2]);
1799 		if (retcode)
1800 			return 0;
1801 
1802 		/* Get Counters from page_4*/
1803 		retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1804 					      4, 0, &value[4]);
1805 		if (retcode)
1806 			return 0;
1807 
1808 		for (i = 0; i < stat_cnt; i++) {
1809 			values[i] = value[dpaa2_xstats_strings[i].page_id].
1810 				raw.counter[dpaa2_xstats_strings[i].stats_id];
1811 		}
1812 		return stat_cnt;
1813 	}
1814 
1815 	dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1816 
1817 	for (i = 0; i < n; i++) {
1818 		if (ids[i] >= stat_cnt) {
1819 			DPAA2_PMD_ERR("xstats id value isn't valid");
1820 			return -1;
1821 		}
1822 		values[i] = values_copy[ids[i]];
1823 	}
1824 	return n;
1825 }
1826 
1827 static int
1828 dpaa2_xstats_get_names_by_id(
1829 	struct rte_eth_dev *dev,
1830 	const uint64_t *ids,
1831 	struct rte_eth_xstat_name *xstats_names,
1832 	unsigned int limit)
1833 {
1834 	unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1835 	struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1836 
1837 	if (!ids)
1838 		return dpaa2_xstats_get_names(dev, xstats_names, limit);
1839 
1840 	dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1841 
1842 	for (i = 0; i < limit; i++) {
1843 		if (ids[i] >= stat_cnt) {
1844 			DPAA2_PMD_ERR("xstats id value isn't valid");
1845 			return -1;
1846 		}
1847 		strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1848 	}
1849 	return limit;
1850 }
1851 
1852 static int
1853 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1854 {
1855 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1856 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1857 	int retcode;
1858 	int i;
1859 	struct dpaa2_queue *dpaa2_q;
1860 
1861 	PMD_INIT_FUNC_TRACE();
1862 
1863 	if (dpni == NULL) {
1864 		DPAA2_PMD_ERR("dpni is NULL");
1865 		return -EINVAL;
1866 	}
1867 
1868 	retcode =  dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1869 	if (retcode)
1870 		goto error;
1871 
1872 	/* Reset the per queue stats in dpaa2_queue structure */
1873 	for (i = 0; i < priv->nb_rx_queues; i++) {
1874 		dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1875 		if (dpaa2_q)
1876 			dpaa2_q->rx_pkts = 0;
1877 	}
1878 
1879 	for (i = 0; i < priv->nb_tx_queues; i++) {
1880 		dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
1881 		if (dpaa2_q)
1882 			dpaa2_q->tx_pkts = 0;
1883 	}
1884 
1885 	return 0;
1886 
1887 error:
1888 	DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1889 	return retcode;
1890 };
1891 
1892 /* return 0 means link status changed, -1 means not changed */
1893 static int
1894 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1895 		      int wait_to_complete)
1896 {
1897 	int ret;
1898 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
1899 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
1900 	struct rte_eth_link link;
1901 	struct dpni_link_state state = {0};
1902 	uint8_t count;
1903 
1904 	if (dpni == NULL) {
1905 		DPAA2_PMD_ERR("dpni is NULL");
1906 		return 0;
1907 	}
1908 
1909 	for (count = 0; count <= MAX_REPEAT_TIME; count++) {
1910 		ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token,
1911 					  &state);
1912 		if (ret < 0) {
1913 			DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
1914 			return -1;
1915 		}
1916 		if (state.up == RTE_ETH_LINK_DOWN &&
1917 		    wait_to_complete)
1918 			rte_delay_ms(CHECK_INTERVAL);
1919 		else
1920 			break;
1921 	}
1922 
1923 	memset(&link, 0, sizeof(struct rte_eth_link));
1924 	link.link_status = state.up;
1925 	link.link_speed = state.rate;
1926 
1927 	if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1928 		link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
1929 	else
1930 		link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1931 
1932 	ret = rte_eth_linkstatus_set(dev, &link);
1933 	if (ret == -1)
1934 		DPAA2_PMD_DEBUG("No change in status");
1935 	else
1936 		DPAA2_PMD_INFO("Port %d Link is %s\n", dev->data->port_id,
1937 			       link.link_status ? "Up" : "Down");
1938 
1939 	return ret;
1940 }
1941 
1942 /**
1943  * Toggle the DPNI to enable, if not already enabled.
1944  * This is not strictly PHY up/down - it is more of logical toggling.
1945  */
1946 static int
1947 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1948 {
1949 	int ret = -EINVAL;
1950 	struct dpaa2_dev_priv *priv;
1951 	struct fsl_mc_io *dpni;
1952 	int en = 0;
1953 	struct dpni_link_state state = {0};
1954 
1955 	priv = dev->data->dev_private;
1956 	dpni = (struct fsl_mc_io *)dev->process_private;
1957 
1958 	if (dpni == NULL) {
1959 		DPAA2_PMD_ERR("dpni is NULL");
1960 		return ret;
1961 	}
1962 
1963 	/* Check if DPNI is currently enabled */
1964 	ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1965 	if (ret) {
1966 		/* Unable to obtain dpni status; Not continuing */
1967 		DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1968 		return -EINVAL;
1969 	}
1970 
1971 	/* Enable link if not already enabled */
1972 	if (!en) {
1973 		ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1974 		if (ret) {
1975 			DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1976 			return -EINVAL;
1977 		}
1978 	}
1979 	ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1980 	if (ret < 0) {
1981 		DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
1982 		return -1;
1983 	}
1984 
1985 	/* changing tx burst function to start enqueues */
1986 	dev->tx_pkt_burst = dpaa2_dev_tx;
1987 	dev->data->dev_link.link_status = state.up;
1988 	dev->data->dev_link.link_speed = state.rate;
1989 
1990 	if (state.up)
1991 		DPAA2_PMD_INFO("Port %d Link is Up", dev->data->port_id);
1992 	else
1993 		DPAA2_PMD_INFO("Port %d Link is Down", dev->data->port_id);
1994 	return ret;
1995 }
1996 
1997 /**
1998  * Toggle the DPNI to disable, if not already disabled.
1999  * This is not strictly PHY up/down - it is more of logical toggling.
2000  */
2001 static int
2002 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
2003 {
2004 	int ret = -EINVAL;
2005 	struct dpaa2_dev_priv *priv;
2006 	struct fsl_mc_io *dpni;
2007 	int dpni_enabled = 0;
2008 	int retries = 10;
2009 
2010 	PMD_INIT_FUNC_TRACE();
2011 
2012 	priv = dev->data->dev_private;
2013 	dpni = (struct fsl_mc_io *)dev->process_private;
2014 
2015 	if (dpni == NULL) {
2016 		DPAA2_PMD_ERR("Device has not yet been configured");
2017 		return ret;
2018 	}
2019 
2020 	/*changing  tx burst function to avoid any more enqueues */
2021 	dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
2022 
2023 	/* Loop while dpni_disable() attempts to drain the egress FQs
2024 	 * and confirm them back to us.
2025 	 */
2026 	do {
2027 		ret = dpni_disable(dpni, 0, priv->token);
2028 		if (ret) {
2029 			DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
2030 			return ret;
2031 		}
2032 		ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
2033 		if (ret) {
2034 			DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
2035 			return ret;
2036 		}
2037 		if (dpni_enabled)
2038 			/* Allow the MC some slack */
2039 			rte_delay_us(100 * 1000);
2040 	} while (dpni_enabled && --retries);
2041 
2042 	if (!retries) {
2043 		DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
2044 		/* todo- we may have to manually cleanup queues.
2045 		 */
2046 	} else {
2047 		DPAA2_PMD_INFO("Port %d Link DOWN successful",
2048 			       dev->data->port_id);
2049 	}
2050 
2051 	dev->data->dev_link.link_status = 0;
2052 
2053 	return ret;
2054 }
2055 
2056 static int
2057 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2058 {
2059 	int ret = -EINVAL;
2060 	struct dpaa2_dev_priv *priv;
2061 	struct fsl_mc_io *dpni;
2062 	struct dpni_link_state state = {0};
2063 
2064 	PMD_INIT_FUNC_TRACE();
2065 
2066 	priv = dev->data->dev_private;
2067 	dpni = (struct fsl_mc_io *)dev->process_private;
2068 
2069 	if (dpni == NULL || fc_conf == NULL) {
2070 		DPAA2_PMD_ERR("device not configured");
2071 		return ret;
2072 	}
2073 
2074 	ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
2075 	if (ret) {
2076 		DPAA2_PMD_ERR("error: dpni_get_link_state %d", ret);
2077 		return ret;
2078 	}
2079 
2080 	memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
2081 	if (state.options & DPNI_LINK_OPT_PAUSE) {
2082 		/* DPNI_LINK_OPT_PAUSE set
2083 		 *  if ASYM_PAUSE not set,
2084 		 *	RX Side flow control (handle received Pause frame)
2085 		 *	TX side flow control (send Pause frame)
2086 		 *  if ASYM_PAUSE set,
2087 		 *	RX Side flow control (handle received Pause frame)
2088 		 *	No TX side flow control (send Pause frame disabled)
2089 		 */
2090 		if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
2091 			fc_conf->mode = RTE_ETH_FC_FULL;
2092 		else
2093 			fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
2094 	} else {
2095 		/* DPNI_LINK_OPT_PAUSE not set
2096 		 *  if ASYM_PAUSE set,
2097 		 *	TX side flow control (send Pause frame)
2098 		 *	No RX side flow control (No action on pause frame rx)
2099 		 *  if ASYM_PAUSE not set,
2100 		 *	Flow control disabled
2101 		 */
2102 		if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
2103 			fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
2104 		else
2105 			fc_conf->mode = RTE_ETH_FC_NONE;
2106 	}
2107 
2108 	return ret;
2109 }
2110 
2111 static int
2112 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2113 {
2114 	int ret = -EINVAL;
2115 	struct dpaa2_dev_priv *priv;
2116 	struct fsl_mc_io *dpni;
2117 	struct dpni_link_state state = {0};
2118 	struct dpni_link_cfg cfg = {0};
2119 
2120 	PMD_INIT_FUNC_TRACE();
2121 
2122 	priv = dev->data->dev_private;
2123 	dpni = (struct fsl_mc_io *)dev->process_private;
2124 
2125 	if (dpni == NULL) {
2126 		DPAA2_PMD_ERR("dpni is NULL");
2127 		return ret;
2128 	}
2129 
2130 	/* It is necessary to obtain the current state before setting fc_conf
2131 	 * as MC would return error in case rate, autoneg or duplex values are
2132 	 * different.
2133 	 */
2134 	ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
2135 	if (ret) {
2136 		DPAA2_PMD_ERR("Unable to get link state (err=%d)", ret);
2137 		return -1;
2138 	}
2139 
2140 	/* Disable link before setting configuration */
2141 	dpaa2_dev_set_link_down(dev);
2142 
2143 	/* Based on fc_conf, update cfg */
2144 	cfg.rate = state.rate;
2145 	cfg.options = state.options;
2146 
2147 	/* update cfg with fc_conf */
2148 	switch (fc_conf->mode) {
2149 	case RTE_ETH_FC_FULL:
2150 		/* Full flow control;
2151 		 * OPT_PAUSE set, ASYM_PAUSE not set
2152 		 */
2153 		cfg.options |= DPNI_LINK_OPT_PAUSE;
2154 		cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
2155 		break;
2156 	case RTE_ETH_FC_TX_PAUSE:
2157 		/* Enable RX flow control
2158 		 * OPT_PAUSE not set;
2159 		 * ASYM_PAUSE set;
2160 		 */
2161 		cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
2162 		cfg.options &= ~DPNI_LINK_OPT_PAUSE;
2163 		break;
2164 	case RTE_ETH_FC_RX_PAUSE:
2165 		/* Enable TX Flow control
2166 		 * OPT_PAUSE set
2167 		 * ASYM_PAUSE set
2168 		 */
2169 		cfg.options |= DPNI_LINK_OPT_PAUSE;
2170 		cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
2171 		break;
2172 	case RTE_ETH_FC_NONE:
2173 		/* Disable Flow control
2174 		 * OPT_PAUSE not set
2175 		 * ASYM_PAUSE not set
2176 		 */
2177 		cfg.options &= ~DPNI_LINK_OPT_PAUSE;
2178 		cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
2179 		break;
2180 	default:
2181 		DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
2182 			      fc_conf->mode);
2183 		return -1;
2184 	}
2185 
2186 	ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
2187 	if (ret)
2188 		DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
2189 			      ret);
2190 
2191 	/* Enable link */
2192 	dpaa2_dev_set_link_up(dev);
2193 
2194 	return ret;
2195 }
2196 
2197 static int
2198 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
2199 			  struct rte_eth_rss_conf *rss_conf)
2200 {
2201 	struct rte_eth_dev_data *data = dev->data;
2202 	struct dpaa2_dev_priv *priv = data->dev_private;
2203 	struct rte_eth_conf *eth_conf = &data->dev_conf;
2204 	int ret, tc_index;
2205 
2206 	PMD_INIT_FUNC_TRACE();
2207 
2208 	if (rss_conf->rss_hf) {
2209 		for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
2210 			ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf,
2211 				tc_index);
2212 			if (ret) {
2213 				DPAA2_PMD_ERR("Unable to set flow dist on tc%d",
2214 					tc_index);
2215 				return ret;
2216 			}
2217 		}
2218 	} else {
2219 		for (tc_index = 0; tc_index < priv->num_rx_tc; tc_index++) {
2220 			ret = dpaa2_remove_flow_dist(dev, tc_index);
2221 			if (ret) {
2222 				DPAA2_PMD_ERR(
2223 					"Unable to remove flow dist on tc%d",
2224 					tc_index);
2225 				return ret;
2226 			}
2227 		}
2228 	}
2229 	eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
2230 	return 0;
2231 }
2232 
2233 static int
2234 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
2235 			    struct rte_eth_rss_conf *rss_conf)
2236 {
2237 	struct rte_eth_dev_data *data = dev->data;
2238 	struct rte_eth_conf *eth_conf = &data->dev_conf;
2239 
2240 	/* dpaa2 does not support rss_key, so length should be 0*/
2241 	rss_conf->rss_key_len = 0;
2242 	rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
2243 	return 0;
2244 }
2245 
2246 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
2247 		int eth_rx_queue_id,
2248 		struct dpaa2_dpcon_dev *dpcon,
2249 		const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
2250 {
2251 	struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
2252 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
2253 	struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
2254 	uint8_t flow_id = dpaa2_ethq->flow_id;
2255 	struct dpni_queue cfg;
2256 	uint8_t options, priority;
2257 	int ret;
2258 
2259 	if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
2260 		dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
2261 	else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
2262 		dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
2263 	else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
2264 		dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
2265 	else
2266 		return -EINVAL;
2267 
2268 	priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / queue_conf->ev.priority) *
2269 		   (dpcon->num_priorities - 1);
2270 
2271 	memset(&cfg, 0, sizeof(struct dpni_queue));
2272 	options = DPNI_QUEUE_OPT_DEST;
2273 	cfg.destination.type = DPNI_DEST_DPCON;
2274 	cfg.destination.id = dpcon->dpcon_id;
2275 	cfg.destination.priority = priority;
2276 
2277 	if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
2278 		options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
2279 		cfg.destination.hold_active = 1;
2280 	}
2281 
2282 	if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
2283 			!eth_priv->en_ordered) {
2284 		struct opr_cfg ocfg;
2285 
2286 		/* Restoration window size = 256 frames */
2287 		ocfg.oprrws = 3;
2288 		/* Restoration window size = 512 frames for LX2 */
2289 		if (dpaa2_svr_family == SVR_LX2160A)
2290 			ocfg.oprrws = 4;
2291 		/* Auto advance NESN window enabled */
2292 		ocfg.oa = 1;
2293 		/* Late arrival window size disabled */
2294 		ocfg.olws = 0;
2295 		/* ORL resource exhaustion advance NESN disabled */
2296 		ocfg.oeane = 0;
2297 		/* Loose ordering enabled */
2298 		ocfg.oloe = 1;
2299 		eth_priv->en_loose_ordered = 1;
2300 		/* Strict ordering enabled if explicitly set */
2301 		if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
2302 			ocfg.oloe = 0;
2303 			eth_priv->en_loose_ordered = 0;
2304 		}
2305 
2306 		ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
2307 				   dpaa2_ethq->tc_index, flow_id,
2308 				   OPR_OPT_CREATE, &ocfg, 0);
2309 		if (ret) {
2310 			DPAA2_PMD_ERR("Error setting opr: ret: %d\n", ret);
2311 			return ret;
2312 		}
2313 
2314 		eth_priv->en_ordered = 1;
2315 	}
2316 
2317 	options |= DPNI_QUEUE_OPT_USER_CTX;
2318 	cfg.user_context = (size_t)(dpaa2_ethq);
2319 
2320 	ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
2321 			     dpaa2_ethq->tc_index, flow_id, options, &cfg);
2322 	if (ret) {
2323 		DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
2324 		return ret;
2325 	}
2326 
2327 	memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
2328 
2329 	return 0;
2330 }
2331 
2332 int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
2333 		int eth_rx_queue_id)
2334 {
2335 	struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
2336 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
2337 	struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
2338 	uint8_t flow_id = dpaa2_ethq->flow_id;
2339 	struct dpni_queue cfg;
2340 	uint8_t options;
2341 	int ret;
2342 
2343 	memset(&cfg, 0, sizeof(struct dpni_queue));
2344 	options = DPNI_QUEUE_OPT_DEST;
2345 	cfg.destination.type = DPNI_DEST_NONE;
2346 
2347 	ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
2348 			     dpaa2_ethq->tc_index, flow_id, options, &cfg);
2349 	if (ret)
2350 		DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
2351 
2352 	return ret;
2353 }
2354 
2355 static int
2356 dpaa2_dev_flow_ops_get(struct rte_eth_dev *dev,
2357 		       const struct rte_flow_ops **ops)
2358 {
2359 	if (!dev)
2360 		return -ENODEV;
2361 
2362 	*ops = &dpaa2_flow_ops;
2363 	return 0;
2364 }
2365 
2366 static void
2367 dpaa2_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2368 	struct rte_eth_rxq_info *qinfo)
2369 {
2370 	struct dpaa2_queue *rxq;
2371 	struct dpaa2_dev_priv *priv = dev->data->dev_private;
2372 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
2373 	uint16_t max_frame_length;
2374 
2375 	rxq = (struct dpaa2_queue *)dev->data->rx_queues[queue_id];
2376 
2377 	qinfo->mp = rxq->mb_pool;
2378 	qinfo->scattered_rx = dev->data->scattered_rx;
2379 	qinfo->nb_desc = rxq->nb_desc;
2380 	if (dpni_get_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
2381 				&max_frame_length) == 0)
2382 		qinfo->rx_buf_size = max_frame_length;
2383 
2384 	qinfo->conf.rx_free_thresh = 1;
2385 	qinfo->conf.rx_drop_en = 1;
2386 	qinfo->conf.rx_deferred_start = 0;
2387 	qinfo->conf.offloads = rxq->offloads;
2388 }
2389 
2390 static void
2391 dpaa2_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
2392 	struct rte_eth_txq_info *qinfo)
2393 {
2394 	struct dpaa2_queue *txq;
2395 
2396 	txq = dev->data->tx_queues[queue_id];
2397 
2398 	qinfo->nb_desc = txq->nb_desc;
2399 	qinfo->conf.tx_thresh.pthresh = 0;
2400 	qinfo->conf.tx_thresh.hthresh = 0;
2401 	qinfo->conf.tx_thresh.wthresh = 0;
2402 
2403 	qinfo->conf.tx_free_thresh = 0;
2404 	qinfo->conf.tx_rs_thresh = 0;
2405 	qinfo->conf.offloads = txq->offloads;
2406 	qinfo->conf.tx_deferred_start = 0;
2407 }
2408 
2409 static int
2410 dpaa2_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *ops)
2411 {
2412 	*(const void **)ops = &dpaa2_tm_ops;
2413 
2414 	return 0;
2415 }
2416 
2417 void
2418 rte_pmd_dpaa2_thread_init(void)
2419 {
2420 	int ret;
2421 
2422 	if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
2423 		ret = dpaa2_affine_qbman_swp();
2424 		if (ret) {
2425 			DPAA2_PMD_ERR(
2426 				"Failed to allocate IO portal, tid: %d\n",
2427 				rte_gettid());
2428 			return;
2429 		}
2430 	}
2431 }
2432 
2433 static struct eth_dev_ops dpaa2_ethdev_ops = {
2434 	.dev_configure	  = dpaa2_eth_dev_configure,
2435 	.dev_start	      = dpaa2_dev_start,
2436 	.dev_stop	      = dpaa2_dev_stop,
2437 	.dev_close	      = dpaa2_dev_close,
2438 	.promiscuous_enable   = dpaa2_dev_promiscuous_enable,
2439 	.promiscuous_disable  = dpaa2_dev_promiscuous_disable,
2440 	.allmulticast_enable  = dpaa2_dev_allmulticast_enable,
2441 	.allmulticast_disable = dpaa2_dev_allmulticast_disable,
2442 	.dev_set_link_up      = dpaa2_dev_set_link_up,
2443 	.dev_set_link_down    = dpaa2_dev_set_link_down,
2444 	.link_update	   = dpaa2_dev_link_update,
2445 	.stats_get	       = dpaa2_dev_stats_get,
2446 	.xstats_get	       = dpaa2_dev_xstats_get,
2447 	.xstats_get_by_id     = dpaa2_xstats_get_by_id,
2448 	.xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
2449 	.xstats_get_names      = dpaa2_xstats_get_names,
2450 	.stats_reset	   = dpaa2_dev_stats_reset,
2451 	.xstats_reset	      = dpaa2_dev_stats_reset,
2452 	.fw_version_get	   = dpaa2_fw_version_get,
2453 	.dev_infos_get	   = dpaa2_dev_info_get,
2454 	.dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
2455 	.mtu_set           = dpaa2_dev_mtu_set,
2456 	.vlan_filter_set      = dpaa2_vlan_filter_set,
2457 	.vlan_offload_set     = dpaa2_vlan_offload_set,
2458 	.vlan_tpid_set	      = dpaa2_vlan_tpid_set,
2459 	.rx_queue_setup    = dpaa2_dev_rx_queue_setup,
2460 	.rx_queue_release  = dpaa2_dev_rx_queue_release,
2461 	.tx_queue_setup    = dpaa2_dev_tx_queue_setup,
2462 	.rx_burst_mode_get = dpaa2_dev_rx_burst_mode_get,
2463 	.tx_burst_mode_get = dpaa2_dev_tx_burst_mode_get,
2464 	.flow_ctrl_get	      = dpaa2_flow_ctrl_get,
2465 	.flow_ctrl_set	      = dpaa2_flow_ctrl_set,
2466 	.mac_addr_add         = dpaa2_dev_add_mac_addr,
2467 	.mac_addr_remove      = dpaa2_dev_remove_mac_addr,
2468 	.mac_addr_set         = dpaa2_dev_set_mac_addr,
2469 	.rss_hash_update      = dpaa2_dev_rss_hash_update,
2470 	.rss_hash_conf_get    = dpaa2_dev_rss_hash_conf_get,
2471 	.flow_ops_get         = dpaa2_dev_flow_ops_get,
2472 	.rxq_info_get	      = dpaa2_rxq_info_get,
2473 	.txq_info_get	      = dpaa2_txq_info_get,
2474 	.tm_ops_get	      = dpaa2_tm_ops_get,
2475 #if defined(RTE_LIBRTE_IEEE1588)
2476 	.timesync_enable      = dpaa2_timesync_enable,
2477 	.timesync_disable     = dpaa2_timesync_disable,
2478 	.timesync_read_time   = dpaa2_timesync_read_time,
2479 	.timesync_write_time  = dpaa2_timesync_write_time,
2480 	.timesync_adjust_time = dpaa2_timesync_adjust_time,
2481 	.timesync_read_rx_timestamp = dpaa2_timesync_read_rx_timestamp,
2482 	.timesync_read_tx_timestamp = dpaa2_timesync_read_tx_timestamp,
2483 #endif
2484 };
2485 
2486 /* Populate the mac address from physically available (u-boot/firmware) and/or
2487  * one set by higher layers like MC (restool) etc.
2488  * Returns the table of MAC entries (multiple entries)
2489  */
2490 static int
2491 populate_mac_addr(struct fsl_mc_io *dpni_dev, struct dpaa2_dev_priv *priv,
2492 		  struct rte_ether_addr *mac_entry)
2493 {
2494 	int ret;
2495 	struct rte_ether_addr phy_mac, prime_mac;
2496 
2497 	memset(&phy_mac, 0, sizeof(struct rte_ether_addr));
2498 	memset(&prime_mac, 0, sizeof(struct rte_ether_addr));
2499 
2500 	/* Get the physical device MAC address */
2501 	ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2502 				     phy_mac.addr_bytes);
2503 	if (ret) {
2504 		DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
2505 		goto cleanup;
2506 	}
2507 
2508 	ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2509 					prime_mac.addr_bytes);
2510 	if (ret) {
2511 		DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
2512 		goto cleanup;
2513 	}
2514 
2515 	/* Now that both MAC have been obtained, do:
2516 	 *  if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
2517 	 *     and return phy
2518 	 *  If empty_mac(phy), return prime.
2519 	 *  if both are empty, create random MAC, set as prime and return
2520 	 */
2521 	if (!rte_is_zero_ether_addr(&phy_mac)) {
2522 		/* If the addresses are not same, overwrite prime */
2523 		if (!rte_is_same_ether_addr(&phy_mac, &prime_mac)) {
2524 			ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2525 							priv->token,
2526 							phy_mac.addr_bytes);
2527 			if (ret) {
2528 				DPAA2_PMD_ERR("Unable to set MAC Address: %d",
2529 					      ret);
2530 				goto cleanup;
2531 			}
2532 			memcpy(&prime_mac, &phy_mac,
2533 				sizeof(struct rte_ether_addr));
2534 		}
2535 	} else if (rte_is_zero_ether_addr(&prime_mac)) {
2536 		/* In case phys and prime, both are zero, create random MAC */
2537 		rte_eth_random_addr(prime_mac.addr_bytes);
2538 		ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2539 						priv->token,
2540 						prime_mac.addr_bytes);
2541 		if (ret) {
2542 			DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
2543 			goto cleanup;
2544 		}
2545 	}
2546 
2547 	/* prime_mac the final MAC address */
2548 	memcpy(mac_entry, &prime_mac, sizeof(struct rte_ether_addr));
2549 	return 0;
2550 
2551 cleanup:
2552 	return -1;
2553 }
2554 
2555 static int
2556 check_devargs_handler(__rte_unused const char *key, const char *value,
2557 		      __rte_unused void *opaque)
2558 {
2559 	if (strcmp(value, "1"))
2560 		return -1;
2561 
2562 	return 0;
2563 }
2564 
2565 static int
2566 dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
2567 {
2568 	struct rte_kvargs *kvlist;
2569 
2570 	if (!devargs)
2571 		return 0;
2572 
2573 	kvlist = rte_kvargs_parse(devargs->args, NULL);
2574 	if (!kvlist)
2575 		return 0;
2576 
2577 	if (!rte_kvargs_count(kvlist, key)) {
2578 		rte_kvargs_free(kvlist);
2579 		return 0;
2580 	}
2581 
2582 	if (rte_kvargs_process(kvlist, key,
2583 			       check_devargs_handler, NULL) < 0) {
2584 		rte_kvargs_free(kvlist);
2585 		return 0;
2586 	}
2587 	rte_kvargs_free(kvlist);
2588 
2589 	return 1;
2590 }
2591 
2592 static int
2593 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
2594 {
2595 	struct rte_device *dev = eth_dev->device;
2596 	struct rte_dpaa2_device *dpaa2_dev;
2597 	struct fsl_mc_io *dpni_dev;
2598 	struct dpni_attr attr;
2599 	struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2600 	struct dpni_buffer_layout layout;
2601 	int ret, hw_id, i;
2602 
2603 	PMD_INIT_FUNC_TRACE();
2604 
2605 	dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
2606 	if (!dpni_dev) {
2607 		DPAA2_PMD_ERR("Memory allocation failed for dpni device");
2608 		return -1;
2609 	}
2610 	dpni_dev->regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
2611 	eth_dev->process_private = (void *)dpni_dev;
2612 
2613 	/* For secondary processes, the primary has done all the work */
2614 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2615 		/* In case of secondary, only burst and ops API need to be
2616 		 * plugged.
2617 		 */
2618 		eth_dev->dev_ops = &dpaa2_ethdev_ops;
2619 		eth_dev->rx_queue_count = dpaa2_dev_rx_queue_count;
2620 		if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
2621 			eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2622 		else if (dpaa2_get_devargs(dev->devargs,
2623 					DRIVER_NO_PREFETCH_MODE))
2624 			eth_dev->rx_pkt_burst = dpaa2_dev_rx;
2625 		else
2626 			eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2627 		eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2628 		return 0;
2629 	}
2630 
2631 	dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2632 
2633 	hw_id = dpaa2_dev->object_id;
2634 	ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
2635 	if (ret) {
2636 		DPAA2_PMD_ERR(
2637 			     "Failure in opening dpni@%d with err code %d",
2638 			     hw_id, ret);
2639 		rte_free(dpni_dev);
2640 		return -1;
2641 	}
2642 
2643 	if (eth_dev->data->dev_conf.lpbk_mode)
2644 		dpaa2_dev_recycle_deconfig(eth_dev);
2645 
2646 	/* Clean the device first */
2647 	ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
2648 	if (ret) {
2649 		DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
2650 			      hw_id, ret);
2651 		goto init_err;
2652 	}
2653 
2654 	ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
2655 	if (ret) {
2656 		DPAA2_PMD_ERR(
2657 			     "Failure in get dpni@%d attribute, err code %d",
2658 			     hw_id, ret);
2659 		goto init_err;
2660 	}
2661 
2662 	priv->num_rx_tc = attr.num_rx_tcs;
2663 	priv->num_tx_tc = attr.num_tx_tcs;
2664 	priv->qos_entries = attr.qos_entries;
2665 	priv->fs_entries = attr.fs_entries;
2666 	priv->dist_queues = attr.num_queues;
2667 	priv->num_channels = attr.num_channels;
2668 	priv->channel_inuse = 0;
2669 	rte_spinlock_init(&priv->lpbk_qp_lock);
2670 
2671 	/* only if the custom CG is enabled */
2672 	if (attr.options & DPNI_OPT_CUSTOM_CG)
2673 		priv->max_cgs = attr.num_cgs;
2674 	else
2675 		priv->max_cgs = 0;
2676 
2677 	for (i = 0; i < priv->max_cgs; i++)
2678 		priv->cgid_in_use[i] = 0;
2679 
2680 	for (i = 0; i < attr.num_rx_tcs; i++)
2681 		priv->nb_rx_queues += attr.num_queues;
2682 
2683 	priv->nb_tx_queues = attr.num_tx_tcs * attr.num_channels;
2684 
2685 	DPAA2_PMD_DEBUG("RX-TC= %d, rx_queues= %d, tx_queues=%d, max_cgs=%d",
2686 			priv->num_rx_tc, priv->nb_rx_queues,
2687 			priv->nb_tx_queues, priv->max_cgs);
2688 
2689 	priv->hw = dpni_dev;
2690 	priv->hw_id = hw_id;
2691 	priv->options = attr.options;
2692 	priv->max_mac_filters = attr.mac_filter_entries;
2693 	priv->max_vlan_filters = attr.vlan_filter_entries;
2694 	priv->flags = 0;
2695 #if defined(RTE_LIBRTE_IEEE1588)
2696 	printf("DPDK IEEE1588 is enabled\n");
2697 	priv->flags |= DPAA2_TX_CONF_ENABLE;
2698 #endif
2699 	/* Used with ``fslmc:dpni.1,drv_tx_conf=1`` */
2700 	if (dpaa2_get_devargs(dev->devargs, DRIVER_TX_CONF)) {
2701 		priv->flags |= DPAA2_TX_CONF_ENABLE;
2702 		DPAA2_PMD_INFO("TX_CONF Enabled");
2703 	}
2704 
2705 	if (dpaa2_get_devargs(dev->devargs, DRIVER_ERROR_QUEUE)) {
2706 		dpaa2_enable_err_queue = 1;
2707 		DPAA2_PMD_INFO("Enable error queue");
2708 	}
2709 
2710 	/* Allocate memory for hardware structure for queues */
2711 	ret = dpaa2_alloc_rx_tx_queues(eth_dev);
2712 	if (ret) {
2713 		DPAA2_PMD_ERR("Queue allocation Failed");
2714 		goto init_err;
2715 	}
2716 
2717 	/* Allocate memory for storing MAC addresses.
2718 	 * Table of mac_filter_entries size is allocated so that RTE ether lib
2719 	 * can add MAC entries when rte_eth_dev_mac_addr_add is called.
2720 	 */
2721 	eth_dev->data->mac_addrs = rte_zmalloc("dpni",
2722 		RTE_ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
2723 	if (eth_dev->data->mac_addrs == NULL) {
2724 		DPAA2_PMD_ERR(
2725 		   "Failed to allocate %d bytes needed to store MAC addresses",
2726 		   RTE_ETHER_ADDR_LEN * attr.mac_filter_entries);
2727 		ret = -ENOMEM;
2728 		goto init_err;
2729 	}
2730 
2731 	ret = populate_mac_addr(dpni_dev, priv, &eth_dev->data->mac_addrs[0]);
2732 	if (ret) {
2733 		DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
2734 		rte_free(eth_dev->data->mac_addrs);
2735 		eth_dev->data->mac_addrs = NULL;
2736 		goto init_err;
2737 	}
2738 
2739 	/* ... tx buffer layout ... */
2740 	memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2741 	if (priv->flags & DPAA2_TX_CONF_ENABLE) {
2742 		layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
2743 				 DPNI_BUF_LAYOUT_OPT_TIMESTAMP;
2744 		layout.pass_timestamp = true;
2745 	} else {
2746 		layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2747 	}
2748 	layout.pass_frame_status = 1;
2749 	ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2750 				     DPNI_QUEUE_TX, &layout);
2751 	if (ret) {
2752 		DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
2753 		goto init_err;
2754 	}
2755 
2756 	/* ... tx-conf and error buffer layout ... */
2757 	memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2758 	if (priv->flags & DPAA2_TX_CONF_ENABLE) {
2759 		layout.options = DPNI_BUF_LAYOUT_OPT_TIMESTAMP;
2760 		layout.pass_timestamp = true;
2761 	}
2762 	layout.options |= DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2763 	layout.pass_frame_status = 1;
2764 	ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2765 				     DPNI_QUEUE_TX_CONFIRM, &layout);
2766 	if (ret) {
2767 		DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
2768 			     ret);
2769 		goto init_err;
2770 	}
2771 
2772 	eth_dev->dev_ops = &dpaa2_ethdev_ops;
2773 
2774 	if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
2775 		eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2776 		DPAA2_PMD_INFO("Loopback mode");
2777 	} else if (dpaa2_get_devargs(dev->devargs, DRIVER_NO_PREFETCH_MODE)) {
2778 		eth_dev->rx_pkt_burst = dpaa2_dev_rx;
2779 		DPAA2_PMD_INFO("No Prefetch mode");
2780 	} else {
2781 		eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2782 	}
2783 	eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2784 
2785 	/* Init fields w.r.t. classification */
2786 	memset(&priv->extract.qos_key_extract, 0,
2787 		sizeof(struct dpaa2_key_extract));
2788 	priv->extract.qos_extract_param = (size_t)rte_malloc(NULL, 256, 64);
2789 	if (!priv->extract.qos_extract_param) {
2790 		DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow "
2791 			    " classification ", ret);
2792 		goto init_err;
2793 	}
2794 	priv->extract.qos_key_extract.key_info.ipv4_src_offset =
2795 		IP_ADDRESS_OFFSET_INVALID;
2796 	priv->extract.qos_key_extract.key_info.ipv4_dst_offset =
2797 		IP_ADDRESS_OFFSET_INVALID;
2798 	priv->extract.qos_key_extract.key_info.ipv6_src_offset =
2799 		IP_ADDRESS_OFFSET_INVALID;
2800 	priv->extract.qos_key_extract.key_info.ipv6_dst_offset =
2801 		IP_ADDRESS_OFFSET_INVALID;
2802 
2803 	for (i = 0; i < MAX_TCS; i++) {
2804 		memset(&priv->extract.tc_key_extract[i], 0,
2805 			sizeof(struct dpaa2_key_extract));
2806 		priv->extract.tc_extract_param[i] =
2807 			(size_t)rte_malloc(NULL, 256, 64);
2808 		if (!priv->extract.tc_extract_param[i]) {
2809 			DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow classification",
2810 				     ret);
2811 			goto init_err;
2812 		}
2813 		priv->extract.tc_key_extract[i].key_info.ipv4_src_offset =
2814 			IP_ADDRESS_OFFSET_INVALID;
2815 		priv->extract.tc_key_extract[i].key_info.ipv4_dst_offset =
2816 			IP_ADDRESS_OFFSET_INVALID;
2817 		priv->extract.tc_key_extract[i].key_info.ipv6_src_offset =
2818 			IP_ADDRESS_OFFSET_INVALID;
2819 		priv->extract.tc_key_extract[i].key_info.ipv6_dst_offset =
2820 			IP_ADDRESS_OFFSET_INVALID;
2821 	}
2822 
2823 	ret = dpni_set_max_frame_length(dpni_dev, CMD_PRI_LOW, priv->token,
2824 					RTE_ETHER_MAX_LEN - RTE_ETHER_CRC_LEN
2825 					+ VLAN_TAG_SIZE);
2826 	if (ret) {
2827 		DPAA2_PMD_ERR("Unable to set mtu. check config");
2828 		goto init_err;
2829 	}
2830 
2831 	/*TODO To enable soft parser support DPAA2 driver needs to integrate
2832 	 * with external entity to receive byte code for software sequence
2833 	 * and same will be offload to the H/W using MC interface.
2834 	 * Currently it is assumed that DPAA2 driver has byte code by some
2835 	 * mean and same if offloaded to H/W.
2836 	 */
2837 	if (getenv("DPAA2_ENABLE_SOFT_PARSER")) {
2838 		WRIOP_SS_INITIALIZER(priv);
2839 		ret = dpaa2_eth_load_wriop_soft_parser(priv, DPNI_SS_INGRESS);
2840 		if (ret < 0) {
2841 			DPAA2_PMD_ERR(" Error(%d) in loading softparser\n",
2842 				      ret);
2843 			return ret;
2844 		}
2845 
2846 		ret = dpaa2_eth_enable_wriop_soft_parser(priv,
2847 							 DPNI_SS_INGRESS);
2848 		if (ret < 0) {
2849 			DPAA2_PMD_ERR(" Error(%d) in enabling softparser\n",
2850 				      ret);
2851 			return ret;
2852 		}
2853 	}
2854 	DPAA2_PMD_INFO("%s: netdev created, connected to %s",
2855 		eth_dev->data->name, dpaa2_dev->ep_name);
2856 
2857 	return 0;
2858 init_err:
2859 	dpaa2_dev_close(eth_dev);
2860 
2861 	return ret;
2862 }
2863 
2864 int dpaa2_dev_is_dpaa2(struct rte_eth_dev *dev)
2865 {
2866 	return dev->device->driver == &rte_dpaa2_pmd.driver;
2867 }
2868 
2869 static int
2870 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
2871 		struct rte_dpaa2_device *dpaa2_dev)
2872 {
2873 	struct rte_eth_dev *eth_dev;
2874 	struct dpaa2_dev_priv *dev_priv;
2875 	int diag;
2876 
2877 	if ((DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE) >
2878 		RTE_PKTMBUF_HEADROOM) {
2879 		DPAA2_PMD_ERR(
2880 		"RTE_PKTMBUF_HEADROOM(%d) shall be > DPAA2 Annotation req(%d)",
2881 		RTE_PKTMBUF_HEADROOM,
2882 		DPAA2_MBUF_HW_ANNOTATION + DPAA2_FD_PTA_SIZE);
2883 
2884 		return -1;
2885 	}
2886 
2887 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2888 		eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
2889 		if (!eth_dev)
2890 			return -ENODEV;
2891 		dev_priv = rte_zmalloc("ethdev private structure",
2892 				       sizeof(struct dpaa2_dev_priv),
2893 				       RTE_CACHE_LINE_SIZE);
2894 		if (dev_priv == NULL) {
2895 			DPAA2_PMD_CRIT(
2896 				"Unable to allocate memory for private data");
2897 			rte_eth_dev_release_port(eth_dev);
2898 			return -ENOMEM;
2899 		}
2900 		eth_dev->data->dev_private = (void *)dev_priv;
2901 		/* Store a pointer to eth_dev in dev_private */
2902 		dev_priv->eth_dev = eth_dev;
2903 	} else {
2904 		eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
2905 		if (!eth_dev) {
2906 			DPAA2_PMD_DEBUG("returning enodev");
2907 			return -ENODEV;
2908 		}
2909 	}
2910 
2911 	eth_dev->device = &dpaa2_dev->device;
2912 
2913 	dpaa2_dev->eth_dev = eth_dev;
2914 	eth_dev->data->rx_mbuf_alloc_failed = 0;
2915 
2916 	if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
2917 		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
2918 
2919 	eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2920 
2921 	/* Invoke PMD device initialization function */
2922 	diag = dpaa2_dev_init(eth_dev);
2923 	if (diag == 0) {
2924 		if (!dpaa2_tx_sg_pool) {
2925 			dpaa2_tx_sg_pool =
2926 				rte_pktmbuf_pool_create("dpaa2_mbuf_tx_sg_pool",
2927 				DPAA2_POOL_SIZE,
2928 				DPAA2_POOL_CACHE_SIZE, 0,
2929 				DPAA2_MAX_SGS * sizeof(struct qbman_sge),
2930 				rte_socket_id());
2931 			if (dpaa2_tx_sg_pool == NULL) {
2932 				DPAA2_PMD_ERR("SG pool creation failed\n");
2933 				return -ENOMEM;
2934 			}
2935 		}
2936 		rte_eth_dev_probing_finish(eth_dev);
2937 		dpaa2_valid_dev++;
2938 		return 0;
2939 	}
2940 
2941 	rte_eth_dev_release_port(eth_dev);
2942 	return diag;
2943 }
2944 
2945 static int
2946 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
2947 {
2948 	struct rte_eth_dev *eth_dev;
2949 	int ret;
2950 
2951 	eth_dev = dpaa2_dev->eth_dev;
2952 	dpaa2_dev_close(eth_dev);
2953 	dpaa2_valid_dev--;
2954 	if (!dpaa2_valid_dev)
2955 		rte_mempool_free(dpaa2_tx_sg_pool);
2956 	ret = rte_eth_dev_release_port(eth_dev);
2957 
2958 	return ret;
2959 }
2960 
2961 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
2962 	.drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
2963 	.drv_type = DPAA2_ETH,
2964 	.probe = rte_dpaa2_probe,
2965 	.remove = rte_dpaa2_remove,
2966 };
2967 
2968 RTE_PMD_REGISTER_DPAA2(NET_DPAA2_PMD_DRIVER_NAME, rte_dpaa2_pmd);
2969 RTE_PMD_REGISTER_PARAM_STRING(NET_DPAA2_PMD_DRIVER_NAME,
2970 		DRIVER_LOOPBACK_MODE "=<int> "
2971 		DRIVER_NO_PREFETCH_MODE "=<int>"
2972 		DRIVER_TX_CONF "=<int>"
2973 		DRIVER_ERROR_QUEUE "=<int>");
2974 RTE_LOG_REGISTER_DEFAULT(dpaa2_logtype_pmd, NOTICE);
2975