replace snprintf with strlcpy without adding extra include
[dpdk.git] / drivers / net / dpaa2 / dpaa2_ethdev.c
1 /* * SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4  *   Copyright 2016 NXP
5  *
6  */
7
8 #include <time.h>
9 #include <net/if.h>
10
11 #include <rte_mbuf.h>
12 #include <rte_ethdev_driver.h>
13 #include <rte_malloc.h>
14 #include <rte_memcpy.h>
15 #include <rte_string_fns.h>
16 #include <rte_cycles.h>
17 #include <rte_kvargs.h>
18 #include <rte_dev.h>
19 #include <rte_fslmc.h>
20 #include <rte_flow_driver.h>
21
22 #include "dpaa2_pmd_logs.h"
23 #include <fslmc_vfio.h>
24 #include <dpaa2_hw_pvt.h>
25 #include <dpaa2_hw_mempool.h>
26 #include <dpaa2_hw_dpio.h>
27 #include <mc/fsl_dpmng.h>
28 #include "dpaa2_ethdev.h"
29 #include <fsl_qbman_debug.h>
30
31 #define DRIVER_LOOPBACK_MODE "drv_looback"
32
33 /* Supported Rx offloads */
34 static uint64_t dev_rx_offloads_sup =
35                 DEV_RX_OFFLOAD_VLAN_STRIP |
36                 DEV_RX_OFFLOAD_IPV4_CKSUM |
37                 DEV_RX_OFFLOAD_UDP_CKSUM |
38                 DEV_RX_OFFLOAD_TCP_CKSUM |
39                 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
40                 DEV_RX_OFFLOAD_VLAN_FILTER |
41                 DEV_RX_OFFLOAD_JUMBO_FRAME;
42
43 /* Rx offloads which cannot be disabled */
44 static uint64_t dev_rx_offloads_nodis =
45                 DEV_RX_OFFLOAD_SCATTER;
46
47 /* Supported Tx offloads */
48 static uint64_t dev_tx_offloads_sup =
49                 DEV_TX_OFFLOAD_VLAN_INSERT |
50                 DEV_TX_OFFLOAD_IPV4_CKSUM |
51                 DEV_TX_OFFLOAD_UDP_CKSUM |
52                 DEV_TX_OFFLOAD_TCP_CKSUM |
53                 DEV_TX_OFFLOAD_SCTP_CKSUM |
54                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
55
56 /* Tx offloads which cannot be disabled */
57 static uint64_t dev_tx_offloads_nodis =
58                 DEV_TX_OFFLOAD_MULTI_SEGS |
59                 DEV_TX_OFFLOAD_MT_LOCKFREE |
60                 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
61
62 /* enable timestamp in mbuf */
63 enum pmd_dpaa2_ts dpaa2_enable_ts;
64
65 struct rte_dpaa2_xstats_name_off {
66         char name[RTE_ETH_XSTATS_NAME_SIZE];
67         uint8_t page_id; /* dpni statistics page id */
68         uint8_t stats_id; /* stats id in the given page */
69 };
70
71 static const struct rte_dpaa2_xstats_name_off dpaa2_xstats_strings[] = {
72         {"ingress_multicast_frames", 0, 2},
73         {"ingress_multicast_bytes", 0, 3},
74         {"ingress_broadcast_frames", 0, 4},
75         {"ingress_broadcast_bytes", 0, 5},
76         {"egress_multicast_frames", 1, 2},
77         {"egress_multicast_bytes", 1, 3},
78         {"egress_broadcast_frames", 1, 4},
79         {"egress_broadcast_bytes", 1, 5},
80         {"ingress_filtered_frames", 2, 0},
81         {"ingress_discarded_frames", 2, 1},
82         {"ingress_nobuffer_discards", 2, 2},
83         {"egress_discarded_frames", 2, 3},
84         {"egress_confirmed_frames", 2, 4},
85 };
86
87 static const enum rte_filter_op dpaa2_supported_filter_ops[] = {
88         RTE_ETH_FILTER_ADD,
89         RTE_ETH_FILTER_DELETE,
90         RTE_ETH_FILTER_UPDATE,
91         RTE_ETH_FILTER_FLUSH,
92         RTE_ETH_FILTER_GET
93 };
94
95 static struct rte_dpaa2_driver rte_dpaa2_pmd;
96 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
97 static int dpaa2_dev_link_update(struct rte_eth_dev *dev,
98                                  int wait_to_complete);
99 static int dpaa2_dev_set_link_up(struct rte_eth_dev *dev);
100 static int dpaa2_dev_set_link_down(struct rte_eth_dev *dev);
101 static int dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
102
103 int dpaa2_logtype_pmd;
104
105 __rte_experimental void
106 rte_pmd_dpaa2_set_timestamp(enum pmd_dpaa2_ts enable)
107 {
108         dpaa2_enable_ts = enable;
109 }
110
111 static int
112 dpaa2_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
113 {
114         int ret;
115         struct dpaa2_dev_priv *priv = dev->data->dev_private;
116         struct fsl_mc_io *dpni = priv->hw;
117
118         PMD_INIT_FUNC_TRACE();
119
120         if (dpni == NULL) {
121                 DPAA2_PMD_ERR("dpni is NULL");
122                 return -1;
123         }
124
125         if (on)
126                 ret = dpni_add_vlan_id(dpni, CMD_PRI_LOW,
127                                        priv->token, vlan_id);
128         else
129                 ret = dpni_remove_vlan_id(dpni, CMD_PRI_LOW,
130                                           priv->token, vlan_id);
131
132         if (ret < 0)
133                 DPAA2_PMD_ERR("ret = %d Unable to add/rem vlan %d hwid =%d",
134                               ret, vlan_id, priv->hw_id);
135
136         return ret;
137 }
138
139 static int
140 dpaa2_vlan_offload_set(struct rte_eth_dev *dev, int mask)
141 {
142         struct dpaa2_dev_priv *priv = dev->data->dev_private;
143         struct fsl_mc_io *dpni = priv->hw;
144         int ret;
145
146         PMD_INIT_FUNC_TRACE();
147
148         if (mask & ETH_VLAN_FILTER_MASK) {
149                 /* VLAN Filter not avaialble */
150                 if (!priv->max_vlan_filters) {
151                         DPAA2_PMD_INFO("VLAN filter not available");
152                         goto next_mask;
153                 }
154
155                 if (dev->data->dev_conf.rxmode.offloads &
156                         DEV_RX_OFFLOAD_VLAN_FILTER)
157                         ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
158                                                       priv->token, true);
159                 else
160                         ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
161                                                       priv->token, false);
162                 if (ret < 0)
163                         DPAA2_PMD_INFO("Unable to set vlan filter = %d", ret);
164         }
165 next_mask:
166         if (mask & ETH_VLAN_EXTEND_MASK) {
167                 if (dev->data->dev_conf.rxmode.offloads &
168                         DEV_RX_OFFLOAD_VLAN_EXTEND)
169                         DPAA2_PMD_INFO("VLAN extend offload not supported");
170         }
171
172         return 0;
173 }
174
175 static int
176 dpaa2_vlan_tpid_set(struct rte_eth_dev *dev,
177                       enum rte_vlan_type vlan_type __rte_unused,
178                       uint16_t tpid)
179 {
180         struct dpaa2_dev_priv *priv = dev->data->dev_private;
181         struct fsl_mc_io *dpni = priv->hw;
182         int ret = -ENOTSUP;
183
184         PMD_INIT_FUNC_TRACE();
185
186         /* nothing to be done for standard vlan tpids */
187         if (tpid == 0x8100 || tpid == 0x88A8)
188                 return 0;
189
190         ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
191                                    priv->token, tpid);
192         if (ret < 0)
193                 DPAA2_PMD_INFO("Unable to set vlan tpid = %d", ret);
194         /* if already configured tpids, remove them first */
195         if (ret == -EBUSY) {
196                 struct dpni_custom_tpid_cfg tpid_list = {0};
197
198                 ret = dpni_get_custom_tpid(dpni, CMD_PRI_LOW,
199                                    priv->token, &tpid_list);
200                 if (ret < 0)
201                         goto fail;
202                 ret = dpni_remove_custom_tpid(dpni, CMD_PRI_LOW,
203                                    priv->token, tpid_list.tpid1);
204                 if (ret < 0)
205                         goto fail;
206                 ret = dpni_add_custom_tpid(dpni, CMD_PRI_LOW,
207                                            priv->token, tpid);
208         }
209 fail:
210         return ret;
211 }
212
213 static int
214 dpaa2_fw_version_get(struct rte_eth_dev *dev,
215                      char *fw_version,
216                      size_t fw_size)
217 {
218         int ret;
219         struct dpaa2_dev_priv *priv = dev->data->dev_private;
220         struct fsl_mc_io *dpni = priv->hw;
221         struct mc_soc_version mc_plat_info = {0};
222         struct mc_version mc_ver_info = {0};
223
224         PMD_INIT_FUNC_TRACE();
225
226         if (mc_get_soc_version(dpni, CMD_PRI_LOW, &mc_plat_info))
227                 DPAA2_PMD_WARN("\tmc_get_soc_version failed");
228
229         if (mc_get_version(dpni, CMD_PRI_LOW, &mc_ver_info))
230                 DPAA2_PMD_WARN("\tmc_get_version failed");
231
232         ret = snprintf(fw_version, fw_size,
233                        "%x-%d.%d.%d",
234                        mc_plat_info.svr,
235                        mc_ver_info.major,
236                        mc_ver_info.minor,
237                        mc_ver_info.revision);
238
239         ret += 1; /* add the size of '\0' */
240         if (fw_size < (uint32_t)ret)
241                 return ret;
242         else
243                 return 0;
244 }
245
246 static void
247 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
248 {
249         struct dpaa2_dev_priv *priv = dev->data->dev_private;
250
251         PMD_INIT_FUNC_TRACE();
252
253         dev_info->if_index = priv->hw_id;
254
255         dev_info->max_mac_addrs = priv->max_mac_filters;
256         dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
257         dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
258         dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
259         dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
260         dev_info->rx_offload_capa = dev_rx_offloads_sup |
261                                         dev_rx_offloads_nodis;
262         dev_info->tx_offload_capa = dev_tx_offloads_sup |
263                                         dev_tx_offloads_nodis;
264         dev_info->speed_capa = ETH_LINK_SPEED_1G |
265                         ETH_LINK_SPEED_2_5G |
266                         ETH_LINK_SPEED_10G;
267
268         dev_info->max_hash_mac_addrs = 0;
269         dev_info->max_vfs = 0;
270         dev_info->max_vmdq_pools = ETH_16_POOLS;
271         dev_info->flow_type_rss_offloads = DPAA2_RSS_OFFLOAD_ALL;
272 }
273
274 static int
275 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
276 {
277         struct dpaa2_dev_priv *priv = dev->data->dev_private;
278         uint16_t dist_idx;
279         uint32_t vq_id;
280         uint8_t num_rxqueue_per_tc;
281         struct dpaa2_queue *mc_q, *mcq;
282         uint32_t tot_queues;
283         int i;
284         struct dpaa2_queue *dpaa2_q;
285
286         PMD_INIT_FUNC_TRACE();
287
288         num_rxqueue_per_tc = (priv->nb_rx_queues / priv->num_rx_tc);
289         tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
290         mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
291                           RTE_CACHE_LINE_SIZE);
292         if (!mc_q) {
293                 DPAA2_PMD_ERR("Memory allocation failed for rx/tx queues");
294                 return -1;
295         }
296
297         for (i = 0; i < priv->nb_rx_queues; i++) {
298                 mc_q->eth_data = dev->data;
299                 priv->rx_vq[i] = mc_q++;
300                 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
301                 dpaa2_q->q_storage = rte_malloc("dq_storage",
302                                         sizeof(struct queue_storage_info_t),
303                                         RTE_CACHE_LINE_SIZE);
304                 if (!dpaa2_q->q_storage)
305                         goto fail;
306
307                 memset(dpaa2_q->q_storage, 0,
308                        sizeof(struct queue_storage_info_t));
309                 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
310                         goto fail;
311         }
312
313         for (i = 0; i < priv->nb_tx_queues; i++) {
314                 mc_q->eth_data = dev->data;
315                 mc_q->flow_id = 0xffff;
316                 priv->tx_vq[i] = mc_q++;
317                 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
318                 dpaa2_q->cscn = rte_malloc(NULL,
319                                            sizeof(struct qbman_result), 16);
320                 if (!dpaa2_q->cscn)
321                         goto fail_tx;
322         }
323
324         vq_id = 0;
325         for (dist_idx = 0; dist_idx < priv->nb_rx_queues; dist_idx++) {
326                 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
327                 mcq->tc_index = dist_idx / num_rxqueue_per_tc;
328                 mcq->flow_id = dist_idx % num_rxqueue_per_tc;
329                 vq_id++;
330         }
331
332         return 0;
333 fail_tx:
334         i -= 1;
335         while (i >= 0) {
336                 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
337                 rte_free(dpaa2_q->cscn);
338                 priv->tx_vq[i--] = NULL;
339         }
340         i = priv->nb_rx_queues;
341 fail:
342         i -= 1;
343         mc_q = priv->rx_vq[0];
344         while (i >= 0) {
345                 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
346                 dpaa2_free_dq_storage(dpaa2_q->q_storage);
347                 rte_free(dpaa2_q->q_storage);
348                 priv->rx_vq[i--] = NULL;
349         }
350         rte_free(mc_q);
351         return -1;
352 }
353
354 static void
355 dpaa2_free_rx_tx_queues(struct rte_eth_dev *dev)
356 {
357         struct dpaa2_dev_priv *priv = dev->data->dev_private;
358         struct dpaa2_queue *dpaa2_q;
359         int i;
360
361         PMD_INIT_FUNC_TRACE();
362
363         /* Queue allocation base */
364         if (priv->rx_vq[0]) {
365                 /* cleaning up queue storage */
366                 for (i = 0; i < priv->nb_rx_queues; i++) {
367                         dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
368                         if (dpaa2_q->q_storage)
369                                 rte_free(dpaa2_q->q_storage);
370                 }
371                 /* cleanup tx queue cscn */
372                 for (i = 0; i < priv->nb_tx_queues; i++) {
373                         dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
374                         rte_free(dpaa2_q->cscn);
375                 }
376                 /*free memory for all queues (RX+TX) */
377                 rte_free(priv->rx_vq[0]);
378                 priv->rx_vq[0] = NULL;
379         }
380 }
381
382 static int
383 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
384 {
385         struct dpaa2_dev_priv *priv = dev->data->dev_private;
386         struct fsl_mc_io *dpni = priv->hw;
387         struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
388         uint64_t rx_offloads = eth_conf->rxmode.offloads;
389         uint64_t tx_offloads = eth_conf->txmode.offloads;
390         int rx_l3_csum_offload = false;
391         int rx_l4_csum_offload = false;
392         int tx_l3_csum_offload = false;
393         int tx_l4_csum_offload = false;
394         int ret;
395
396         PMD_INIT_FUNC_TRACE();
397
398         /* Rx offloads validation */
399         if (dev_rx_offloads_nodis & ~rx_offloads) {
400                 DPAA2_PMD_WARN(
401                 "Rx offloads non configurable - requested 0x%" PRIx64
402                 " ignored 0x%" PRIx64,
403                         rx_offloads, dev_rx_offloads_nodis);
404         }
405
406         /* Tx offloads validation */
407         if (dev_tx_offloads_nodis & ~tx_offloads) {
408                 DPAA2_PMD_WARN(
409                 "Tx offloads non configurable - requested 0x%" PRIx64
410                 " ignored 0x%" PRIx64,
411                         tx_offloads, dev_tx_offloads_nodis);
412         }
413
414         if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
415                 if (eth_conf->rxmode.max_rx_pkt_len <= DPAA2_MAX_RX_PKT_LEN) {
416                         ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW,
417                                 priv->token, eth_conf->rxmode.max_rx_pkt_len);
418                         if (ret) {
419                                 DPAA2_PMD_ERR(
420                                         "Unable to set mtu. check config");
421                                 return ret;
422                         }
423                 } else {
424                         return -1;
425                 }
426         }
427
428         if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
429                 ret = dpaa2_setup_flow_dist(dev,
430                                 eth_conf->rx_adv_conf.rss_conf.rss_hf);
431                 if (ret) {
432                         DPAA2_PMD_ERR("Unable to set flow distribution."
433                                       "Check queue config");
434                         return ret;
435                 }
436         }
437
438         if (rx_offloads & DEV_RX_OFFLOAD_IPV4_CKSUM)
439                 rx_l3_csum_offload = true;
440
441         if ((rx_offloads & DEV_RX_OFFLOAD_UDP_CKSUM) ||
442                 (rx_offloads & DEV_RX_OFFLOAD_TCP_CKSUM))
443                 rx_l4_csum_offload = true;
444
445         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
446                                DPNI_OFF_RX_L3_CSUM, rx_l3_csum_offload);
447         if (ret) {
448                 DPAA2_PMD_ERR("Error to set RX l3 csum:Error = %d", ret);
449                 return ret;
450         }
451
452         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
453                                DPNI_OFF_RX_L4_CSUM, rx_l4_csum_offload);
454         if (ret) {
455                 DPAA2_PMD_ERR("Error to get RX l4 csum:Error = %d", ret);
456                 return ret;
457         }
458
459         if (tx_offloads & DEV_TX_OFFLOAD_IPV4_CKSUM)
460                 tx_l3_csum_offload = true;
461
462         if ((tx_offloads & DEV_TX_OFFLOAD_UDP_CKSUM) ||
463                 (tx_offloads & DEV_TX_OFFLOAD_TCP_CKSUM) ||
464                 (tx_offloads & DEV_TX_OFFLOAD_SCTP_CKSUM))
465                 tx_l4_csum_offload = true;
466
467         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
468                                DPNI_OFF_TX_L3_CSUM, tx_l3_csum_offload);
469         if (ret) {
470                 DPAA2_PMD_ERR("Error to set TX l3 csum:Error = %d", ret);
471                 return ret;
472         }
473
474         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
475                                DPNI_OFF_TX_L4_CSUM, tx_l4_csum_offload);
476         if (ret) {
477                 DPAA2_PMD_ERR("Error to get TX l4 csum:Error = %d", ret);
478                 return ret;
479         }
480
481         /* Enabling hash results in FD requires setting DPNI_FLCTYPE_HASH in
482          * dpni_set_offload API. Setting this FLCTYPE for DPNI sets the FD[SC]
483          * to 0 for LS2 in the hardware thus disabling data/annotation
484          * stashing. For LX2 this is fixed in hardware and thus hash result and
485          * parse results can be received in FD using this option.
486          */
487         if (dpaa2_svr_family == SVR_LX2160A) {
488                 ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
489                                        DPNI_FLCTYPE_HASH, true);
490                 if (ret) {
491                         DPAA2_PMD_ERR("Error setting FLCTYPE: Err = %d", ret);
492                         return ret;
493                 }
494         }
495
496         if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
497                 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
498
499         /* update the current status */
500         dpaa2_dev_link_update(dev, 0);
501
502         return 0;
503 }
504
505 /* Function to setup RX flow information. It contains traffic class ID,
506  * flow ID, destination configuration etc.
507  */
508 static int
509 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
510                          uint16_t rx_queue_id,
511                          uint16_t nb_rx_desc __rte_unused,
512                          unsigned int socket_id __rte_unused,
513                          const struct rte_eth_rxconf *rx_conf __rte_unused,
514                          struct rte_mempool *mb_pool)
515 {
516         struct dpaa2_dev_priv *priv = dev->data->dev_private;
517         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
518         struct dpaa2_queue *dpaa2_q;
519         struct dpni_queue cfg;
520         uint8_t options = 0;
521         uint8_t flow_id;
522         uint32_t bpid;
523         int ret;
524
525         PMD_INIT_FUNC_TRACE();
526
527         DPAA2_PMD_DEBUG("dev =%p, queue =%d, pool = %p, conf =%p",
528                         dev, rx_queue_id, mb_pool, rx_conf);
529
530         if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
531                 bpid = mempool_to_bpid(mb_pool);
532                 ret = dpaa2_attach_bp_list(priv,
533                                            rte_dpaa2_bpid_info[bpid].bp_list);
534                 if (ret)
535                         return ret;
536         }
537         dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
538         dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
539         dpaa2_q->bp_array = rte_dpaa2_bpid_info;
540
541         /*Get the flow id from given VQ id*/
542         flow_id = rx_queue_id % priv->nb_rx_queues;
543         memset(&cfg, 0, sizeof(struct dpni_queue));
544
545         options = options | DPNI_QUEUE_OPT_USER_CTX;
546         cfg.user_context = (size_t)(dpaa2_q);
547
548         /*if ls2088 or rev2 device, enable the stashing */
549
550         if ((dpaa2_svr_family & 0xffff0000) != SVR_LS2080A) {
551                 options |= DPNI_QUEUE_OPT_FLC;
552                 cfg.flc.stash_control = true;
553                 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
554                 /* 00 00 00 - last 6 bit represent annotation, context stashing,
555                  * data stashing setting 01 01 00 (0x14)
556                  * (in following order ->DS AS CS)
557                  * to enable 1 line data, 1 line annotation.
558                  * For LX2, this setting should be 01 00 00 (0x10)
559                  */
560                 if ((dpaa2_svr_family & 0xffff0000) == SVR_LX2160A)
561                         cfg.flc.value |= 0x10;
562                 else
563                         cfg.flc.value |= 0x14;
564         }
565         ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
566                              dpaa2_q->tc_index, flow_id, options, &cfg);
567         if (ret) {
568                 DPAA2_PMD_ERR("Error in setting the rx flow: = %d", ret);
569                 return -1;
570         }
571
572         if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
573                 struct dpni_taildrop taildrop;
574
575                 taildrop.enable = 1;
576                 /*enabling per rx queue congestion control */
577                 taildrop.threshold = CONG_THRESHOLD_RX_Q;
578                 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
579                 taildrop.oal = CONG_RX_OAL;
580                 DPAA2_PMD_DEBUG("Enabling Early Drop on queue = %d",
581                                 rx_queue_id);
582                 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
583                                         DPNI_CP_QUEUE, DPNI_QUEUE_RX,
584                                         dpaa2_q->tc_index, flow_id, &taildrop);
585                 if (ret) {
586                         DPAA2_PMD_ERR("Error in setting taildrop. err=(%d)",
587                                       ret);
588                         return -1;
589                 }
590         }
591
592         dev->data->rx_queues[rx_queue_id] = dpaa2_q;
593         return 0;
594 }
595
596 static int
597 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
598                          uint16_t tx_queue_id,
599                          uint16_t nb_tx_desc __rte_unused,
600                          unsigned int socket_id __rte_unused,
601                          const struct rte_eth_txconf *tx_conf __rte_unused)
602 {
603         struct dpaa2_dev_priv *priv = dev->data->dev_private;
604         struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
605                 priv->tx_vq[tx_queue_id];
606         struct fsl_mc_io *dpni = priv->hw;
607         struct dpni_queue tx_conf_cfg;
608         struct dpni_queue tx_flow_cfg;
609         uint8_t options = 0, flow_id;
610         uint32_t tc_id;
611         int ret;
612
613         PMD_INIT_FUNC_TRACE();
614
615         /* Return if queue already configured */
616         if (dpaa2_q->flow_id != 0xffff) {
617                 dev->data->tx_queues[tx_queue_id] = dpaa2_q;
618                 return 0;
619         }
620
621         memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
622         memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
623
624         tc_id = tx_queue_id;
625         flow_id = 0;
626
627         ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
628                              tc_id, flow_id, options, &tx_flow_cfg);
629         if (ret) {
630                 DPAA2_PMD_ERR("Error in setting the tx flow: "
631                               "tc_id=%d, flow=%d err=%d",
632                               tc_id, flow_id, ret);
633                         return -1;
634         }
635
636         dpaa2_q->flow_id = flow_id;
637
638         if (tx_queue_id == 0) {
639                 /*Set tx-conf and error configuration*/
640                 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
641                                                     priv->token,
642                                                     DPNI_CONF_DISABLE);
643                 if (ret) {
644                         DPAA2_PMD_ERR("Error in set tx conf mode settings: "
645                                       "err=%d", ret);
646                         return -1;
647                 }
648         }
649         dpaa2_q->tc_index = tc_id;
650
651         if (!(priv->flags & DPAA2_TX_CGR_OFF)) {
652                 struct dpni_congestion_notification_cfg cong_notif_cfg;
653
654                 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
655                 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
656                 /* Notify that the queue is not congested when the data in
657                  * the queue is below this thershold.
658                  */
659                 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
660                 cong_notif_cfg.message_ctx = 0;
661                 cong_notif_cfg.message_iova =
662                                 (size_t)DPAA2_VADDR_TO_IOVA(dpaa2_q->cscn);
663                 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
664                 cong_notif_cfg.notification_mode =
665                                          DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
666                                          DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
667                                          DPNI_CONG_OPT_COHERENT_WRITE;
668
669                 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
670                                                        priv->token,
671                                                        DPNI_QUEUE_TX,
672                                                        tc_id,
673                                                        &cong_notif_cfg);
674                 if (ret) {
675                         DPAA2_PMD_ERR(
676                            "Error in setting tx congestion notification: "
677                            "err=%d", ret);
678                         return -ret;
679                 }
680         }
681         dpaa2_q->cb_eqresp_free = dpaa2_dev_free_eqresp_buf;
682         dev->data->tx_queues[tx_queue_id] = dpaa2_q;
683         return 0;
684 }
685
686 static void
687 dpaa2_dev_rx_queue_release(void *q __rte_unused)
688 {
689         PMD_INIT_FUNC_TRACE();
690 }
691
692 static void
693 dpaa2_dev_tx_queue_release(void *q __rte_unused)
694 {
695         PMD_INIT_FUNC_TRACE();
696 }
697
698 static uint32_t
699 dpaa2_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
700 {
701         int32_t ret;
702         struct dpaa2_dev_priv *priv = dev->data->dev_private;
703         struct dpaa2_queue *dpaa2_q;
704         struct qbman_swp *swp;
705         struct qbman_fq_query_np_rslt state;
706         uint32_t frame_cnt = 0;
707
708         PMD_INIT_FUNC_TRACE();
709
710         if (unlikely(!DPAA2_PER_LCORE_DPIO)) {
711                 ret = dpaa2_affine_qbman_swp();
712                 if (ret) {
713                         DPAA2_PMD_ERR("Failure in affining portal");
714                         return -EINVAL;
715                 }
716         }
717         swp = DPAA2_PER_LCORE_PORTAL;
718
719         dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
720
721         if (qbman_fq_query_state(swp, dpaa2_q->fqid, &state) == 0) {
722                 frame_cnt = qbman_fq_state_frame_count(&state);
723                 DPAA2_PMD_DEBUG("RX frame count for q(%d) is %u",
724                                 rx_queue_id, frame_cnt);
725         }
726         return frame_cnt;
727 }
728
729 static const uint32_t *
730 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
731 {
732         static const uint32_t ptypes[] = {
733                 /*todo -= add more types */
734                 RTE_PTYPE_L2_ETHER,
735                 RTE_PTYPE_L3_IPV4,
736                 RTE_PTYPE_L3_IPV4_EXT,
737                 RTE_PTYPE_L3_IPV6,
738                 RTE_PTYPE_L3_IPV6_EXT,
739                 RTE_PTYPE_L4_TCP,
740                 RTE_PTYPE_L4_UDP,
741                 RTE_PTYPE_L4_SCTP,
742                 RTE_PTYPE_L4_ICMP,
743                 RTE_PTYPE_UNKNOWN
744         };
745
746         if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx ||
747                 dev->rx_pkt_burst == dpaa2_dev_loopback_rx)
748                 return ptypes;
749         return NULL;
750 }
751
752 /**
753  * Dpaa2 link Interrupt handler
754  *
755  * @param param
756  *  The address of parameter (struct rte_eth_dev *) regsitered before.
757  *
758  * @return
759  *  void
760  */
761 static void
762 dpaa2_interrupt_handler(void *param)
763 {
764         struct rte_eth_dev *dev = param;
765         struct dpaa2_dev_priv *priv = dev->data->dev_private;
766         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
767         int ret;
768         int irq_index = DPNI_IRQ_INDEX;
769         unsigned int status = 0, clear = 0;
770
771         PMD_INIT_FUNC_TRACE();
772
773         if (dpni == NULL) {
774                 DPAA2_PMD_ERR("dpni is NULL");
775                 return;
776         }
777
778         ret = dpni_get_irq_status(dpni, CMD_PRI_LOW, priv->token,
779                                   irq_index, &status);
780         if (unlikely(ret)) {
781                 DPAA2_PMD_ERR("Can't get irq status (err %d)", ret);
782                 clear = 0xffffffff;
783                 goto out;
784         }
785
786         if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
787                 clear = DPNI_IRQ_EVENT_LINK_CHANGED;
788                 dpaa2_dev_link_update(dev, 0);
789                 /* calling all the apps registered for link status event */
790                 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC,
791                                               NULL);
792         }
793 out:
794         ret = dpni_clear_irq_status(dpni, CMD_PRI_LOW, priv->token,
795                                     irq_index, clear);
796         if (unlikely(ret))
797                 DPAA2_PMD_ERR("Can't clear irq status (err %d)", ret);
798 }
799
800 static int
801 dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
802 {
803         int err = 0;
804         struct dpaa2_dev_priv *priv = dev->data->dev_private;
805         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
806         int irq_index = DPNI_IRQ_INDEX;
807         unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
808
809         PMD_INIT_FUNC_TRACE();
810
811         err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
812                                 irq_index, mask);
813         if (err < 0) {
814                 DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
815                               strerror(-err));
816                 return err;
817         }
818
819         err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
820                                   irq_index, enable);
821         if (err < 0)
822                 DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
823                               strerror(-err));
824
825         return err;
826 }
827
828 static int
829 dpaa2_dev_start(struct rte_eth_dev *dev)
830 {
831         struct rte_device *rdev = dev->device;
832         struct rte_dpaa2_device *dpaa2_dev;
833         struct rte_eth_dev_data *data = dev->data;
834         struct dpaa2_dev_priv *priv = data->dev_private;
835         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
836         struct dpni_queue cfg;
837         struct dpni_error_cfg   err_cfg;
838         uint16_t qdid;
839         struct dpni_queue_id qid;
840         struct dpaa2_queue *dpaa2_q;
841         int ret, i;
842         struct rte_intr_handle *intr_handle;
843
844         dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
845         intr_handle = &dpaa2_dev->intr_handle;
846
847         PMD_INIT_FUNC_TRACE();
848
849         ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
850         if (ret) {
851                 DPAA2_PMD_ERR("Failure in enabling dpni %d device: err=%d",
852                               priv->hw_id, ret);
853                 return ret;
854         }
855
856         /* Power up the phy. Needed to make the link go UP */
857         dpaa2_dev_set_link_up(dev);
858
859         ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
860                             DPNI_QUEUE_TX, &qdid);
861         if (ret) {
862                 DPAA2_PMD_ERR("Error in getting qdid: err=%d", ret);
863                 return ret;
864         }
865         priv->qdid = qdid;
866
867         for (i = 0; i < data->nb_rx_queues; i++) {
868                 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
869                 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
870                                      DPNI_QUEUE_RX, dpaa2_q->tc_index,
871                                        dpaa2_q->flow_id, &cfg, &qid);
872                 if (ret) {
873                         DPAA2_PMD_ERR("Error in getting flow information: "
874                                       "err=%d", ret);
875                         return ret;
876                 }
877                 dpaa2_q->fqid = qid.fqid;
878         }
879
880         /*checksum errors, send them to normal path and set it in annotation */
881         err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
882         err_cfg.errors |= DPNI_ERROR_PHE;
883
884         err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
885         err_cfg.set_frame_annotation = true;
886
887         ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
888                                        priv->token, &err_cfg);
889         if (ret) {
890                 DPAA2_PMD_ERR("Error to dpni_set_errors_behavior: code = %d",
891                               ret);
892                 return ret;
893         }
894
895         /* if the interrupts were configured on this devices*/
896         if (intr_handle && (intr_handle->fd) &&
897             (dev->data->dev_conf.intr_conf.lsc != 0)) {
898                 /* Registering LSC interrupt handler */
899                 rte_intr_callback_register(intr_handle,
900                                            dpaa2_interrupt_handler,
901                                            (void *)dev);
902
903                 /* enable vfio intr/eventfd mapping
904                  * Interrupt index 0 is required, so we can not use
905                  * rte_intr_enable.
906                  */
907                 rte_dpaa2_intr_enable(intr_handle, DPNI_IRQ_INDEX);
908
909                 /* enable dpni_irqs */
910                 dpaa2_eth_setup_irqs(dev, 1);
911         }
912
913         /* Change the tx burst function if ordered queues are used */
914         if (priv->en_ordered)
915                 dev->tx_pkt_burst = dpaa2_dev_tx_ordered;
916
917         return 0;
918 }
919
920 /**
921  *  This routine disables all traffic on the adapter by issuing a
922  *  global reset on the MAC.
923  */
924 static void
925 dpaa2_dev_stop(struct rte_eth_dev *dev)
926 {
927         struct dpaa2_dev_priv *priv = dev->data->dev_private;
928         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
929         int ret;
930         struct rte_eth_link link;
931         struct rte_intr_handle *intr_handle = dev->intr_handle;
932
933         PMD_INIT_FUNC_TRACE();
934
935         /* reset interrupt callback  */
936         if (intr_handle && (intr_handle->fd) &&
937             (dev->data->dev_conf.intr_conf.lsc != 0)) {
938                 /*disable dpni irqs */
939                 dpaa2_eth_setup_irqs(dev, 0);
940
941                 /* disable vfio intr before callback unregister */
942                 rte_dpaa2_intr_disable(intr_handle, DPNI_IRQ_INDEX);
943
944                 /* Unregistering LSC interrupt handler */
945                 rte_intr_callback_unregister(intr_handle,
946                                              dpaa2_interrupt_handler,
947                                              (void *)dev);
948         }
949
950         dpaa2_dev_set_link_down(dev);
951
952         ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
953         if (ret) {
954                 DPAA2_PMD_ERR("Failure (ret %d) in disabling dpni %d dev",
955                               ret, priv->hw_id);
956                 return;
957         }
958
959         /* clear the recorded link status */
960         memset(&link, 0, sizeof(link));
961         rte_eth_linkstatus_set(dev, &link);
962 }
963
964 static void
965 dpaa2_dev_close(struct rte_eth_dev *dev)
966 {
967         struct dpaa2_dev_priv *priv = dev->data->dev_private;
968         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
969         int ret;
970         struct rte_eth_link link;
971
972         PMD_INIT_FUNC_TRACE();
973
974         dpaa2_flow_clean(dev);
975
976         /* Clean the device first */
977         ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
978         if (ret) {
979                 DPAA2_PMD_ERR("Failure cleaning dpni device: err=%d", ret);
980                 return;
981         }
982
983         memset(&link, 0, sizeof(link));
984         rte_eth_linkstatus_set(dev, &link);
985 }
986
987 static void
988 dpaa2_dev_promiscuous_enable(
989                 struct rte_eth_dev *dev)
990 {
991         int ret;
992         struct dpaa2_dev_priv *priv = dev->data->dev_private;
993         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
994
995         PMD_INIT_FUNC_TRACE();
996
997         if (dpni == NULL) {
998                 DPAA2_PMD_ERR("dpni is NULL");
999                 return;
1000         }
1001
1002         ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1003         if (ret < 0)
1004                 DPAA2_PMD_ERR("Unable to enable U promisc mode %d", ret);
1005
1006         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1007         if (ret < 0)
1008                 DPAA2_PMD_ERR("Unable to enable M promisc mode %d", ret);
1009 }
1010
1011 static void
1012 dpaa2_dev_promiscuous_disable(
1013                 struct rte_eth_dev *dev)
1014 {
1015         int ret;
1016         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1017         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1018
1019         PMD_INIT_FUNC_TRACE();
1020
1021         if (dpni == NULL) {
1022                 DPAA2_PMD_ERR("dpni is NULL");
1023                 return;
1024         }
1025
1026         ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1027         if (ret < 0)
1028                 DPAA2_PMD_ERR("Unable to disable U promisc mode %d", ret);
1029
1030         if (dev->data->all_multicast == 0) {
1031                 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
1032                                                  priv->token, false);
1033                 if (ret < 0)
1034                         DPAA2_PMD_ERR("Unable to disable M promisc mode %d",
1035                                       ret);
1036         }
1037 }
1038
1039 static void
1040 dpaa2_dev_allmulticast_enable(
1041                 struct rte_eth_dev *dev)
1042 {
1043         int ret;
1044         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1045         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1046
1047         PMD_INIT_FUNC_TRACE();
1048
1049         if (dpni == NULL) {
1050                 DPAA2_PMD_ERR("dpni is NULL");
1051                 return;
1052         }
1053
1054         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
1055         if (ret < 0)
1056                 DPAA2_PMD_ERR("Unable to enable multicast mode %d", ret);
1057 }
1058
1059 static void
1060 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
1061 {
1062         int ret;
1063         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1064         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1065
1066         PMD_INIT_FUNC_TRACE();
1067
1068         if (dpni == NULL) {
1069                 DPAA2_PMD_ERR("dpni is NULL");
1070                 return;
1071         }
1072
1073         /* must remain on for all promiscuous */
1074         if (dev->data->promiscuous == 1)
1075                 return;
1076
1077         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
1078         if (ret < 0)
1079                 DPAA2_PMD_ERR("Unable to disable multicast mode %d", ret);
1080 }
1081
1082 static int
1083 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1084 {
1085         int ret;
1086         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1087         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1088         uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN
1089                                 + VLAN_TAG_SIZE;
1090
1091         PMD_INIT_FUNC_TRACE();
1092
1093         if (dpni == NULL) {
1094                 DPAA2_PMD_ERR("dpni is NULL");
1095                 return -EINVAL;
1096         }
1097
1098         /* check that mtu is within the allowed range */
1099         if ((mtu < ETHER_MIN_MTU) || (frame_size > DPAA2_MAX_RX_PKT_LEN))
1100                 return -EINVAL;
1101
1102         if (frame_size > ETHER_MAX_LEN)
1103                 dev->data->dev_conf.rxmode.offloads &=
1104                                                 DEV_RX_OFFLOAD_JUMBO_FRAME;
1105         else
1106                 dev->data->dev_conf.rxmode.offloads &=
1107                                                 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1108
1109         dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
1110
1111         /* Set the Max Rx frame length as 'mtu' +
1112          * Maximum Ethernet header length
1113          */
1114         ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
1115                                         frame_size);
1116         if (ret) {
1117                 DPAA2_PMD_ERR("Setting the max frame length failed");
1118                 return -1;
1119         }
1120         DPAA2_PMD_INFO("MTU configured for the device: %d", mtu);
1121         return 0;
1122 }
1123
1124 static int
1125 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
1126                        struct ether_addr *addr,
1127                        __rte_unused uint32_t index,
1128                        __rte_unused uint32_t pool)
1129 {
1130         int ret;
1131         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1132         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1133
1134         PMD_INIT_FUNC_TRACE();
1135
1136         if (dpni == NULL) {
1137                 DPAA2_PMD_ERR("dpni is NULL");
1138                 return -1;
1139         }
1140
1141         ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
1142                                 priv->token, addr->addr_bytes);
1143         if (ret)
1144                 DPAA2_PMD_ERR(
1145                         "error: Adding the MAC ADDR failed: err = %d", ret);
1146         return 0;
1147 }
1148
1149 static void
1150 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
1151                           uint32_t index)
1152 {
1153         int ret;
1154         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1155         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1156         struct rte_eth_dev_data *data = dev->data;
1157         struct ether_addr *macaddr;
1158
1159         PMD_INIT_FUNC_TRACE();
1160
1161         macaddr = &data->mac_addrs[index];
1162
1163         if (dpni == NULL) {
1164                 DPAA2_PMD_ERR("dpni is NULL");
1165                 return;
1166         }
1167
1168         ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
1169                                    priv->token, macaddr->addr_bytes);
1170         if (ret)
1171                 DPAA2_PMD_ERR(
1172                         "error: Removing the MAC ADDR failed: err = %d", ret);
1173 }
1174
1175 static int
1176 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
1177                        struct ether_addr *addr)
1178 {
1179         int ret;
1180         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1181         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1182
1183         PMD_INIT_FUNC_TRACE();
1184
1185         if (dpni == NULL) {
1186                 DPAA2_PMD_ERR("dpni is NULL");
1187                 return -EINVAL;
1188         }
1189
1190         ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
1191                                         priv->token, addr->addr_bytes);
1192
1193         if (ret)
1194                 DPAA2_PMD_ERR(
1195                         "error: Setting the MAC ADDR failed %d", ret);
1196
1197         return ret;
1198 }
1199
1200 static
1201 int dpaa2_dev_stats_get(struct rte_eth_dev *dev,
1202                          struct rte_eth_stats *stats)
1203 {
1204         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1205         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1206         int32_t  retcode;
1207         uint8_t page0 = 0, page1 = 1, page2 = 2;
1208         union dpni_statistics value;
1209         int i;
1210         struct dpaa2_queue *dpaa2_rxq, *dpaa2_txq;
1211
1212         memset(&value, 0, sizeof(union dpni_statistics));
1213
1214         PMD_INIT_FUNC_TRACE();
1215
1216         if (!dpni) {
1217                 DPAA2_PMD_ERR("dpni is NULL");
1218                 return -EINVAL;
1219         }
1220
1221         if (!stats) {
1222                 DPAA2_PMD_ERR("stats is NULL");
1223                 return -EINVAL;
1224         }
1225
1226         /*Get Counters from page_0*/
1227         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1228                                       page0, 0, &value);
1229         if (retcode)
1230                 goto err;
1231
1232         stats->ipackets = value.page_0.ingress_all_frames;
1233         stats->ibytes = value.page_0.ingress_all_bytes;
1234
1235         /*Get Counters from page_1*/
1236         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1237                                       page1, 0, &value);
1238         if (retcode)
1239                 goto err;
1240
1241         stats->opackets = value.page_1.egress_all_frames;
1242         stats->obytes = value.page_1.egress_all_bytes;
1243
1244         /*Get Counters from page_2*/
1245         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1246                                       page2, 0, &value);
1247         if (retcode)
1248                 goto err;
1249
1250         /* Ingress drop frame count due to configured rules */
1251         stats->ierrors = value.page_2.ingress_filtered_frames;
1252         /* Ingress drop frame count due to error */
1253         stats->ierrors += value.page_2.ingress_discarded_frames;
1254
1255         stats->oerrors = value.page_2.egress_discarded_frames;
1256         stats->imissed = value.page_2.ingress_nobuffer_discards;
1257
1258         /* Fill in per queue stats */
1259         for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1260                 (i < priv->nb_rx_queues || i < priv->nb_tx_queues); ++i) {
1261                 dpaa2_rxq = (struct dpaa2_queue *)priv->rx_vq[i];
1262                 dpaa2_txq = (struct dpaa2_queue *)priv->tx_vq[i];
1263                 if (dpaa2_rxq)
1264                         stats->q_ipackets[i] = dpaa2_rxq->rx_pkts;
1265                 if (dpaa2_txq)
1266                         stats->q_opackets[i] = dpaa2_txq->tx_pkts;
1267
1268                 /* Byte counting is not implemented */
1269                 stats->q_ibytes[i]   = 0;
1270                 stats->q_obytes[i]   = 0;
1271         }
1272
1273         return 0;
1274
1275 err:
1276         DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1277         return retcode;
1278 };
1279
1280 static int
1281 dpaa2_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1282                      unsigned int n)
1283 {
1284         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1285         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1286         int32_t  retcode;
1287         union dpni_statistics value[3] = {};
1288         unsigned int i = 0, num = RTE_DIM(dpaa2_xstats_strings);
1289
1290         if (n < num)
1291                 return num;
1292
1293         if (xstats == NULL)
1294                 return 0;
1295
1296         /* Get Counters from page_0*/
1297         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1298                                       0, 0, &value[0]);
1299         if (retcode)
1300                 goto err;
1301
1302         /* Get Counters from page_1*/
1303         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1304                                       1, 0, &value[1]);
1305         if (retcode)
1306                 goto err;
1307
1308         /* Get Counters from page_2*/
1309         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1310                                       2, 0, &value[2]);
1311         if (retcode)
1312                 goto err;
1313
1314         for (i = 0; i < num; i++) {
1315                 xstats[i].id = i;
1316                 xstats[i].value = value[dpaa2_xstats_strings[i].page_id].
1317                         raw.counter[dpaa2_xstats_strings[i].stats_id];
1318         }
1319         return i;
1320 err:
1321         DPAA2_PMD_ERR("Error in obtaining extended stats (%d)", retcode);
1322         return retcode;
1323 }
1324
1325 static int
1326 dpaa2_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1327                        struct rte_eth_xstat_name *xstats_names,
1328                        unsigned int limit)
1329 {
1330         unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1331
1332         if (limit < stat_cnt)
1333                 return stat_cnt;
1334
1335         if (xstats_names != NULL)
1336                 for (i = 0; i < stat_cnt; i++)
1337                         strlcpy(xstats_names[i].name,
1338                                 dpaa2_xstats_strings[i].name,
1339                                 sizeof(xstats_names[i].name));
1340
1341         return stat_cnt;
1342 }
1343
1344 static int
1345 dpaa2_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1346                        uint64_t *values, unsigned int n)
1347 {
1348         unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1349         uint64_t values_copy[stat_cnt];
1350
1351         if (!ids) {
1352                 struct dpaa2_dev_priv *priv = dev->data->dev_private;
1353                 struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1354                 int32_t  retcode;
1355                 union dpni_statistics value[3] = {};
1356
1357                 if (n < stat_cnt)
1358                         return stat_cnt;
1359
1360                 if (!values)
1361                         return 0;
1362
1363                 /* Get Counters from page_0*/
1364                 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1365                                               0, 0, &value[0]);
1366                 if (retcode)
1367                         return 0;
1368
1369                 /* Get Counters from page_1*/
1370                 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1371                                               1, 0, &value[1]);
1372                 if (retcode)
1373                         return 0;
1374
1375                 /* Get Counters from page_2*/
1376                 retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
1377                                               2, 0, &value[2]);
1378                 if (retcode)
1379                         return 0;
1380
1381                 for (i = 0; i < stat_cnt; i++) {
1382                         values[i] = value[dpaa2_xstats_strings[i].page_id].
1383                                 raw.counter[dpaa2_xstats_strings[i].stats_id];
1384                 }
1385                 return stat_cnt;
1386         }
1387
1388         dpaa2_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
1389
1390         for (i = 0; i < n; i++) {
1391                 if (ids[i] >= stat_cnt) {
1392                         DPAA2_PMD_ERR("xstats id value isn't valid");
1393                         return -1;
1394                 }
1395                 values[i] = values_copy[ids[i]];
1396         }
1397         return n;
1398 }
1399
1400 static int
1401 dpaa2_xstats_get_names_by_id(
1402         struct rte_eth_dev *dev,
1403         struct rte_eth_xstat_name *xstats_names,
1404         const uint64_t *ids,
1405         unsigned int limit)
1406 {
1407         unsigned int i, stat_cnt = RTE_DIM(dpaa2_xstats_strings);
1408         struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
1409
1410         if (!ids)
1411                 return dpaa2_xstats_get_names(dev, xstats_names, limit);
1412
1413         dpaa2_xstats_get_names(dev, xstats_names_copy, limit);
1414
1415         for (i = 0; i < limit; i++) {
1416                 if (ids[i] >= stat_cnt) {
1417                         DPAA2_PMD_ERR("xstats id value isn't valid");
1418                         return -1;
1419                 }
1420                 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
1421         }
1422         return limit;
1423 }
1424
1425 static void
1426 dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
1427 {
1428         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1429         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1430         int32_t  retcode;
1431         int i;
1432         struct dpaa2_queue *dpaa2_q;
1433
1434         PMD_INIT_FUNC_TRACE();
1435
1436         if (dpni == NULL) {
1437                 DPAA2_PMD_ERR("dpni is NULL");
1438                 return;
1439         }
1440
1441         retcode =  dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
1442         if (retcode)
1443                 goto error;
1444
1445         /* Reset the per queue stats in dpaa2_queue structure */
1446         for (i = 0; i < priv->nb_rx_queues; i++) {
1447                 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1448                 if (dpaa2_q)
1449                         dpaa2_q->rx_pkts = 0;
1450         }
1451
1452         for (i = 0; i < priv->nb_tx_queues; i++) {
1453                 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
1454                 if (dpaa2_q)
1455                         dpaa2_q->tx_pkts = 0;
1456         }
1457
1458         return;
1459
1460 error:
1461         DPAA2_PMD_ERR("Operation not completed:Error Code = %d", retcode);
1462         return;
1463 };
1464
1465 /* return 0 means link status changed, -1 means not changed */
1466 static int
1467 dpaa2_dev_link_update(struct rte_eth_dev *dev,
1468                         int wait_to_complete __rte_unused)
1469 {
1470         int ret;
1471         struct dpaa2_dev_priv *priv = dev->data->dev_private;
1472         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1473         struct rte_eth_link link;
1474         struct dpni_link_state state = {0};
1475
1476         if (dpni == NULL) {
1477                 DPAA2_PMD_ERR("dpni is NULL");
1478                 return 0;
1479         }
1480
1481         ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1482         if (ret < 0) {
1483                 DPAA2_PMD_DEBUG("error: dpni_get_link_state %d", ret);
1484                 return -1;
1485         }
1486
1487         memset(&link, 0, sizeof(struct rte_eth_link));
1488         link.link_status = state.up;
1489         link.link_speed = state.rate;
1490
1491         if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
1492                 link.link_duplex = ETH_LINK_HALF_DUPLEX;
1493         else
1494                 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1495
1496         ret = rte_eth_linkstatus_set(dev, &link);
1497         if (ret == -1)
1498                 DPAA2_PMD_DEBUG("No change in status");
1499         else
1500                 DPAA2_PMD_INFO("Port %d Link is %s\n", dev->data->port_id,
1501                                link.link_status ? "Up" : "Down");
1502
1503         return ret;
1504 }
1505
1506 /**
1507  * Toggle the DPNI to enable, if not already enabled.
1508  * This is not strictly PHY up/down - it is more of logical toggling.
1509  */
1510 static int
1511 dpaa2_dev_set_link_up(struct rte_eth_dev *dev)
1512 {
1513         int ret = -EINVAL;
1514         struct dpaa2_dev_priv *priv;
1515         struct fsl_mc_io *dpni;
1516         int en = 0;
1517         struct dpni_link_state state = {0};
1518
1519         priv = dev->data->dev_private;
1520         dpni = (struct fsl_mc_io *)priv->hw;
1521
1522         if (dpni == NULL) {
1523                 DPAA2_PMD_ERR("dpni is NULL");
1524                 return ret;
1525         }
1526
1527         /* Check if DPNI is currently enabled */
1528         ret = dpni_is_enabled(dpni, CMD_PRI_LOW, priv->token, &en);
1529         if (ret) {
1530                 /* Unable to obtain dpni status; Not continuing */
1531                 DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1532                 return -EINVAL;
1533         }
1534
1535         /* Enable link if not already enabled */
1536         if (!en) {
1537                 ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
1538                 if (ret) {
1539                         DPAA2_PMD_ERR("Interface Link UP failed (%d)", ret);
1540                         return -EINVAL;
1541                 }
1542         }
1543         ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1544         if (ret < 0) {
1545                 DPAA2_PMD_DEBUG("Unable to get link state (%d)", ret);
1546                 return -1;
1547         }
1548
1549         /* changing tx burst function to start enqueues */
1550         dev->tx_pkt_burst = dpaa2_dev_tx;
1551         dev->data->dev_link.link_status = state.up;
1552
1553         if (state.up)
1554                 DPAA2_PMD_INFO("Port %d Link is Up", dev->data->port_id);
1555         else
1556                 DPAA2_PMD_INFO("Port %d Link is Down", dev->data->port_id);
1557         return ret;
1558 }
1559
1560 /**
1561  * Toggle the DPNI to disable, if not already disabled.
1562  * This is not strictly PHY up/down - it is more of logical toggling.
1563  */
1564 static int
1565 dpaa2_dev_set_link_down(struct rte_eth_dev *dev)
1566 {
1567         int ret = -EINVAL;
1568         struct dpaa2_dev_priv *priv;
1569         struct fsl_mc_io *dpni;
1570         int dpni_enabled = 0;
1571         int retries = 10;
1572
1573         PMD_INIT_FUNC_TRACE();
1574
1575         priv = dev->data->dev_private;
1576         dpni = (struct fsl_mc_io *)priv->hw;
1577
1578         if (dpni == NULL) {
1579                 DPAA2_PMD_ERR("Device has not yet been configured");
1580                 return ret;
1581         }
1582
1583         /*changing  tx burst function to avoid any more enqueues */
1584         dev->tx_pkt_burst = dummy_dev_tx;
1585
1586         /* Loop while dpni_disable() attempts to drain the egress FQs
1587          * and confirm them back to us.
1588          */
1589         do {
1590                 ret = dpni_disable(dpni, 0, priv->token);
1591                 if (ret) {
1592                         DPAA2_PMD_ERR("dpni disable failed (%d)", ret);
1593                         return ret;
1594                 }
1595                 ret = dpni_is_enabled(dpni, 0, priv->token, &dpni_enabled);
1596                 if (ret) {
1597                         DPAA2_PMD_ERR("dpni enable check failed (%d)", ret);
1598                         return ret;
1599                 }
1600                 if (dpni_enabled)
1601                         /* Allow the MC some slack */
1602                         rte_delay_us(100 * 1000);
1603         } while (dpni_enabled && --retries);
1604
1605         if (!retries) {
1606                 DPAA2_PMD_WARN("Retry count exceeded disabling dpni");
1607                 /* todo- we may have to manually cleanup queues.
1608                  */
1609         } else {
1610                 DPAA2_PMD_INFO("Port %d Link DOWN successful",
1611                                dev->data->port_id);
1612         }
1613
1614         dev->data->dev_link.link_status = 0;
1615
1616         return ret;
1617 }
1618
1619 static int
1620 dpaa2_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1621 {
1622         int ret = -EINVAL;
1623         struct dpaa2_dev_priv *priv;
1624         struct fsl_mc_io *dpni;
1625         struct dpni_link_state state = {0};
1626
1627         PMD_INIT_FUNC_TRACE();
1628
1629         priv = dev->data->dev_private;
1630         dpni = (struct fsl_mc_io *)priv->hw;
1631
1632         if (dpni == NULL || fc_conf == NULL) {
1633                 DPAA2_PMD_ERR("device not configured");
1634                 return ret;
1635         }
1636
1637         ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1638         if (ret) {
1639                 DPAA2_PMD_ERR("error: dpni_get_link_state %d", ret);
1640                 return ret;
1641         }
1642
1643         memset(fc_conf, 0, sizeof(struct rte_eth_fc_conf));
1644         if (state.options & DPNI_LINK_OPT_PAUSE) {
1645                 /* DPNI_LINK_OPT_PAUSE set
1646                  *  if ASYM_PAUSE not set,
1647                  *      RX Side flow control (handle received Pause frame)
1648                  *      TX side flow control (send Pause frame)
1649                  *  if ASYM_PAUSE set,
1650                  *      RX Side flow control (handle received Pause frame)
1651                  *      No TX side flow control (send Pause frame disabled)
1652                  */
1653                 if (!(state.options & DPNI_LINK_OPT_ASYM_PAUSE))
1654                         fc_conf->mode = RTE_FC_FULL;
1655                 else
1656                         fc_conf->mode = RTE_FC_RX_PAUSE;
1657         } else {
1658                 /* DPNI_LINK_OPT_PAUSE not set
1659                  *  if ASYM_PAUSE set,
1660                  *      TX side flow control (send Pause frame)
1661                  *      No RX side flow control (No action on pause frame rx)
1662                  *  if ASYM_PAUSE not set,
1663                  *      Flow control disabled
1664                  */
1665                 if (state.options & DPNI_LINK_OPT_ASYM_PAUSE)
1666                         fc_conf->mode = RTE_FC_TX_PAUSE;
1667                 else
1668                         fc_conf->mode = RTE_FC_NONE;
1669         }
1670
1671         return ret;
1672 }
1673
1674 static int
1675 dpaa2_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1676 {
1677         int ret = -EINVAL;
1678         struct dpaa2_dev_priv *priv;
1679         struct fsl_mc_io *dpni;
1680         struct dpni_link_state state = {0};
1681         struct dpni_link_cfg cfg = {0};
1682
1683         PMD_INIT_FUNC_TRACE();
1684
1685         priv = dev->data->dev_private;
1686         dpni = (struct fsl_mc_io *)priv->hw;
1687
1688         if (dpni == NULL) {
1689                 DPAA2_PMD_ERR("dpni is NULL");
1690                 return ret;
1691         }
1692
1693         /* It is necessary to obtain the current state before setting fc_conf
1694          * as MC would return error in case rate, autoneg or duplex values are
1695          * different.
1696          */
1697         ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
1698         if (ret) {
1699                 DPAA2_PMD_ERR("Unable to get link state (err=%d)", ret);
1700                 return -1;
1701         }
1702
1703         /* Disable link before setting configuration */
1704         dpaa2_dev_set_link_down(dev);
1705
1706         /* Based on fc_conf, update cfg */
1707         cfg.rate = state.rate;
1708         cfg.options = state.options;
1709
1710         /* update cfg with fc_conf */
1711         switch (fc_conf->mode) {
1712         case RTE_FC_FULL:
1713                 /* Full flow control;
1714                  * OPT_PAUSE set, ASYM_PAUSE not set
1715                  */
1716                 cfg.options |= DPNI_LINK_OPT_PAUSE;
1717                 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1718                 break;
1719         case RTE_FC_TX_PAUSE:
1720                 /* Enable RX flow control
1721                  * OPT_PAUSE not set;
1722                  * ASYM_PAUSE set;
1723                  */
1724                 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1725                 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1726                 break;
1727         case RTE_FC_RX_PAUSE:
1728                 /* Enable TX Flow control
1729                  * OPT_PAUSE set
1730                  * ASYM_PAUSE set
1731                  */
1732                 cfg.options |= DPNI_LINK_OPT_PAUSE;
1733                 cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
1734                 break;
1735         case RTE_FC_NONE:
1736                 /* Disable Flow control
1737                  * OPT_PAUSE not set
1738                  * ASYM_PAUSE not set
1739                  */
1740                 cfg.options &= ~DPNI_LINK_OPT_PAUSE;
1741                 cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
1742                 break;
1743         default:
1744                 DPAA2_PMD_ERR("Incorrect Flow control flag (%d)",
1745                               fc_conf->mode);
1746                 return -1;
1747         }
1748
1749         ret = dpni_set_link_cfg(dpni, CMD_PRI_LOW, priv->token, &cfg);
1750         if (ret)
1751                 DPAA2_PMD_ERR("Unable to set Link configuration (err=%d)",
1752                               ret);
1753
1754         /* Enable link */
1755         dpaa2_dev_set_link_up(dev);
1756
1757         return ret;
1758 }
1759
1760 static int
1761 dpaa2_dev_rss_hash_update(struct rte_eth_dev *dev,
1762                           struct rte_eth_rss_conf *rss_conf)
1763 {
1764         struct rte_eth_dev_data *data = dev->data;
1765         struct rte_eth_conf *eth_conf = &data->dev_conf;
1766         int ret;
1767
1768         PMD_INIT_FUNC_TRACE();
1769
1770         if (rss_conf->rss_hf) {
1771                 ret = dpaa2_setup_flow_dist(dev, rss_conf->rss_hf);
1772                 if (ret) {
1773                         DPAA2_PMD_ERR("Unable to set flow dist");
1774                         return ret;
1775                 }
1776         } else {
1777                 ret = dpaa2_remove_flow_dist(dev, 0);
1778                 if (ret) {
1779                         DPAA2_PMD_ERR("Unable to remove flow dist");
1780                         return ret;
1781                 }
1782         }
1783         eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_conf->rss_hf;
1784         return 0;
1785 }
1786
1787 static int
1788 dpaa2_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1789                             struct rte_eth_rss_conf *rss_conf)
1790 {
1791         struct rte_eth_dev_data *data = dev->data;
1792         struct rte_eth_conf *eth_conf = &data->dev_conf;
1793
1794         /* dpaa2 does not support rss_key, so length should be 0*/
1795         rss_conf->rss_key_len = 0;
1796         rss_conf->rss_hf = eth_conf->rx_adv_conf.rss_conf.rss_hf;
1797         return 0;
1798 }
1799
1800 int dpaa2_eth_eventq_attach(const struct rte_eth_dev *dev,
1801                 int eth_rx_queue_id,
1802                 uint16_t dpcon_id,
1803                 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
1804 {
1805         struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1806         struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1807         struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1808         uint8_t flow_id = dpaa2_ethq->flow_id;
1809         struct dpni_queue cfg;
1810         uint8_t options;
1811         int ret;
1812
1813         if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
1814                 dpaa2_ethq->cb = dpaa2_dev_process_parallel_event;
1815         else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC)
1816                 dpaa2_ethq->cb = dpaa2_dev_process_atomic_event;
1817         else if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED)
1818                 dpaa2_ethq->cb = dpaa2_dev_process_ordered_event;
1819         else
1820                 return -EINVAL;
1821
1822         memset(&cfg, 0, sizeof(struct dpni_queue));
1823         options = DPNI_QUEUE_OPT_DEST;
1824         cfg.destination.type = DPNI_DEST_DPCON;
1825         cfg.destination.id = dpcon_id;
1826         cfg.destination.priority = queue_conf->ev.priority;
1827
1828         if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ATOMIC) {
1829                 options |= DPNI_QUEUE_OPT_HOLD_ACTIVE;
1830                 cfg.destination.hold_active = 1;
1831         }
1832
1833         if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_ORDERED &&
1834                         !eth_priv->en_ordered) {
1835                 struct opr_cfg ocfg;
1836
1837                 /* Restoration window size = 256 frames */
1838                 ocfg.oprrws = 3;
1839                 /* Restoration window size = 512 frames for LX2 */
1840                 if (dpaa2_svr_family == SVR_LX2160A)
1841                         ocfg.oprrws = 4;
1842                 /* Auto advance NESN window enabled */
1843                 ocfg.oa = 1;
1844                 /* Late arrival window size disabled */
1845                 ocfg.olws = 0;
1846                 /* ORL resource exhaustaion advance NESN disabled */
1847                 ocfg.oeane = 0;
1848                 /* Loose ordering enabled */
1849                 ocfg.oloe = 1;
1850                 eth_priv->en_loose_ordered = 1;
1851                 /* Strict ordering enabled if explicitly set */
1852                 if (getenv("DPAA2_STRICT_ORDERING_ENABLE")) {
1853                         ocfg.oloe = 0;
1854                         eth_priv->en_loose_ordered = 0;
1855                 }
1856
1857                 ret = dpni_set_opr(dpni, CMD_PRI_LOW, eth_priv->token,
1858                                    dpaa2_ethq->tc_index, flow_id,
1859                                    OPR_OPT_CREATE, &ocfg);
1860                 if (ret) {
1861                         DPAA2_PMD_ERR("Error setting opr: ret: %d\n", ret);
1862                         return ret;
1863                 }
1864
1865                 eth_priv->en_ordered = 1;
1866         }
1867
1868         options |= DPNI_QUEUE_OPT_USER_CTX;
1869         cfg.user_context = (size_t)(dpaa2_ethq);
1870
1871         ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1872                              dpaa2_ethq->tc_index, flow_id, options, &cfg);
1873         if (ret) {
1874                 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1875                 return ret;
1876         }
1877
1878         memcpy(&dpaa2_ethq->ev, &queue_conf->ev, sizeof(struct rte_event));
1879
1880         return 0;
1881 }
1882
1883 int dpaa2_eth_eventq_detach(const struct rte_eth_dev *dev,
1884                 int eth_rx_queue_id)
1885 {
1886         struct dpaa2_dev_priv *eth_priv = dev->data->dev_private;
1887         struct fsl_mc_io *dpni = (struct fsl_mc_io *)eth_priv->hw;
1888         struct dpaa2_queue *dpaa2_ethq = eth_priv->rx_vq[eth_rx_queue_id];
1889         uint8_t flow_id = dpaa2_ethq->flow_id;
1890         struct dpni_queue cfg;
1891         uint8_t options;
1892         int ret;
1893
1894         memset(&cfg, 0, sizeof(struct dpni_queue));
1895         options = DPNI_QUEUE_OPT_DEST;
1896         cfg.destination.type = DPNI_DEST_NONE;
1897
1898         ret = dpni_set_queue(dpni, CMD_PRI_LOW, eth_priv->token, DPNI_QUEUE_RX,
1899                              dpaa2_ethq->tc_index, flow_id, options, &cfg);
1900         if (ret)
1901                 DPAA2_PMD_ERR("Error in dpni_set_queue: ret: %d", ret);
1902
1903         return ret;
1904 }
1905
1906 static inline int
1907 dpaa2_dev_verify_filter_ops(enum rte_filter_op filter_op)
1908 {
1909         unsigned int i;
1910
1911         for (i = 0; i < RTE_DIM(dpaa2_supported_filter_ops); i++) {
1912                 if (dpaa2_supported_filter_ops[i] == filter_op)
1913                         return 0;
1914         }
1915         return -ENOTSUP;
1916 }
1917
1918 static int
1919 dpaa2_dev_flow_ctrl(struct rte_eth_dev *dev,
1920                     enum rte_filter_type filter_type,
1921                                  enum rte_filter_op filter_op,
1922                                  void *arg)
1923 {
1924         int ret = 0;
1925
1926         if (!dev)
1927                 return -ENODEV;
1928
1929         switch (filter_type) {
1930         case RTE_ETH_FILTER_GENERIC:
1931                 if (dpaa2_dev_verify_filter_ops(filter_op) < 0) {
1932                         ret = -ENOTSUP;
1933                         break;
1934                 }
1935                 *(const void **)arg = &dpaa2_flow_ops;
1936                 dpaa2_filter_type |= filter_type;
1937                 break;
1938         default:
1939                 RTE_LOG(ERR, PMD, "Filter type (%d) not supported",
1940                         filter_type);
1941                 ret = -ENOTSUP;
1942                 break;
1943         }
1944         return ret;
1945 }
1946
1947 static struct eth_dev_ops dpaa2_ethdev_ops = {
1948         .dev_configure    = dpaa2_eth_dev_configure,
1949         .dev_start            = dpaa2_dev_start,
1950         .dev_stop             = dpaa2_dev_stop,
1951         .dev_close            = dpaa2_dev_close,
1952         .promiscuous_enable   = dpaa2_dev_promiscuous_enable,
1953         .promiscuous_disable  = dpaa2_dev_promiscuous_disable,
1954         .allmulticast_enable  = dpaa2_dev_allmulticast_enable,
1955         .allmulticast_disable = dpaa2_dev_allmulticast_disable,
1956         .dev_set_link_up      = dpaa2_dev_set_link_up,
1957         .dev_set_link_down    = dpaa2_dev_set_link_down,
1958         .link_update       = dpaa2_dev_link_update,
1959         .stats_get             = dpaa2_dev_stats_get,
1960         .xstats_get            = dpaa2_dev_xstats_get,
1961         .xstats_get_by_id     = dpaa2_xstats_get_by_id,
1962         .xstats_get_names_by_id = dpaa2_xstats_get_names_by_id,
1963         .xstats_get_names      = dpaa2_xstats_get_names,
1964         .stats_reset       = dpaa2_dev_stats_reset,
1965         .xstats_reset         = dpaa2_dev_stats_reset,
1966         .fw_version_get    = dpaa2_fw_version_get,
1967         .dev_infos_get     = dpaa2_dev_info_get,
1968         .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
1969         .mtu_set           = dpaa2_dev_mtu_set,
1970         .vlan_filter_set      = dpaa2_vlan_filter_set,
1971         .vlan_offload_set     = dpaa2_vlan_offload_set,
1972         .vlan_tpid_set        = dpaa2_vlan_tpid_set,
1973         .rx_queue_setup    = dpaa2_dev_rx_queue_setup,
1974         .rx_queue_release  = dpaa2_dev_rx_queue_release,
1975         .tx_queue_setup    = dpaa2_dev_tx_queue_setup,
1976         .tx_queue_release  = dpaa2_dev_tx_queue_release,
1977         .rx_queue_count       = dpaa2_dev_rx_queue_count,
1978         .flow_ctrl_get        = dpaa2_flow_ctrl_get,
1979         .flow_ctrl_set        = dpaa2_flow_ctrl_set,
1980         .mac_addr_add         = dpaa2_dev_add_mac_addr,
1981         .mac_addr_remove      = dpaa2_dev_remove_mac_addr,
1982         .mac_addr_set         = dpaa2_dev_set_mac_addr,
1983         .rss_hash_update      = dpaa2_dev_rss_hash_update,
1984         .rss_hash_conf_get    = dpaa2_dev_rss_hash_conf_get,
1985         .filter_ctrl          = dpaa2_dev_flow_ctrl,
1986 };
1987
1988 /* Populate the mac address from physically available (u-boot/firmware) and/or
1989  * one set by higher layers like MC (restool) etc.
1990  * Returns the table of MAC entries (multiple entries)
1991  */
1992 static int
1993 populate_mac_addr(struct fsl_mc_io *dpni_dev, struct dpaa2_dev_priv *priv,
1994                   struct ether_addr *mac_entry)
1995 {
1996         int ret;
1997         struct ether_addr phy_mac, prime_mac;
1998
1999         memset(&phy_mac, 0, sizeof(struct ether_addr));
2000         memset(&prime_mac, 0, sizeof(struct ether_addr));
2001
2002         /* Get the physical device MAC address */
2003         ret = dpni_get_port_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2004                                      phy_mac.addr_bytes);
2005         if (ret) {
2006                 DPAA2_PMD_ERR("DPNI get physical port MAC failed: %d", ret);
2007                 goto cleanup;
2008         }
2009
2010         ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW, priv->token,
2011                                         prime_mac.addr_bytes);
2012         if (ret) {
2013                 DPAA2_PMD_ERR("DPNI get Prime port MAC failed: %d", ret);
2014                 goto cleanup;
2015         }
2016
2017         /* Now that both MAC have been obtained, do:
2018          *  if not_empty_mac(phy) && phy != Prime, overwrite prime with Phy
2019          *     and return phy
2020          *  If empty_mac(phy), return prime.
2021          *  if both are empty, create random MAC, set as prime and return
2022          */
2023         if (!is_zero_ether_addr(&phy_mac)) {
2024                 /* If the addresses are not same, overwrite prime */
2025                 if (!is_same_ether_addr(&phy_mac, &prime_mac)) {
2026                         ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2027                                                         priv->token,
2028                                                         phy_mac.addr_bytes);
2029                         if (ret) {
2030                                 DPAA2_PMD_ERR("Unable to set MAC Address: %d",
2031                                               ret);
2032                                 goto cleanup;
2033                         }
2034                         memcpy(&prime_mac, &phy_mac, sizeof(struct ether_addr));
2035                 }
2036         } else if (is_zero_ether_addr(&prime_mac)) {
2037                 /* In case phys and prime, both are zero, create random MAC */
2038                 eth_random_addr(prime_mac.addr_bytes);
2039                 ret = dpni_set_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
2040                                                 priv->token,
2041                                                 prime_mac.addr_bytes);
2042                 if (ret) {
2043                         DPAA2_PMD_ERR("Unable to set MAC Address: %d", ret);
2044                         goto cleanup;
2045                 }
2046         }
2047
2048         /* prime_mac the final MAC address */
2049         memcpy(mac_entry, &prime_mac, sizeof(struct ether_addr));
2050         return 0;
2051
2052 cleanup:
2053         return -1;
2054 }
2055
2056 static int
2057 check_devargs_handler(__rte_unused const char *key, const char *value,
2058                       __rte_unused void *opaque)
2059 {
2060         if (strcmp(value, "1"))
2061                 return -1;
2062
2063         return 0;
2064 }
2065
2066 static int
2067 dpaa2_get_devargs(struct rte_devargs *devargs, const char *key)
2068 {
2069         struct rte_kvargs *kvlist;
2070
2071         if (!devargs)
2072                 return 0;
2073
2074         kvlist = rte_kvargs_parse(devargs->args, NULL);
2075         if (!kvlist)
2076                 return 0;
2077
2078         if (!rte_kvargs_count(kvlist, key)) {
2079                 rte_kvargs_free(kvlist);
2080                 return 0;
2081         }
2082
2083         if (rte_kvargs_process(kvlist, key,
2084                                check_devargs_handler, NULL) < 0) {
2085                 rte_kvargs_free(kvlist);
2086                 return 0;
2087         }
2088         rte_kvargs_free(kvlist);
2089
2090         return 1;
2091 }
2092
2093 static int
2094 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
2095 {
2096         struct rte_device *dev = eth_dev->device;
2097         struct rte_dpaa2_device *dpaa2_dev;
2098         struct fsl_mc_io *dpni_dev;
2099         struct dpni_attr attr;
2100         struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2101         struct dpni_buffer_layout layout;
2102         int ret, hw_id, i;
2103
2104         PMD_INIT_FUNC_TRACE();
2105
2106         /* For secondary processes, the primary has done all the work */
2107         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2108                 /* In case of secondary, only burst and ops API need to be
2109                  * plugged.
2110                  */
2111                 eth_dev->dev_ops = &dpaa2_ethdev_ops;
2112                 if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE))
2113                         eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2114                 else
2115                         eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2116                 eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2117                 return 0;
2118         }
2119
2120         dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2121
2122         hw_id = dpaa2_dev->object_id;
2123
2124         dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
2125         if (!dpni_dev) {
2126                 DPAA2_PMD_ERR("Memory allocation failed for dpni device");
2127                 return -1;
2128         }
2129
2130         dpni_dev->regs = rte_mcp_ptr_list[0];
2131         ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
2132         if (ret) {
2133                 DPAA2_PMD_ERR(
2134                              "Failure in opening dpni@%d with err code %d",
2135                              hw_id, ret);
2136                 rte_free(dpni_dev);
2137                 return -1;
2138         }
2139
2140         /* Clean the device first */
2141         ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
2142         if (ret) {
2143                 DPAA2_PMD_ERR("Failure cleaning dpni@%d with err code %d",
2144                               hw_id, ret);
2145                 goto init_err;
2146         }
2147
2148         ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
2149         if (ret) {
2150                 DPAA2_PMD_ERR(
2151                              "Failure in get dpni@%d attribute, err code %d",
2152                              hw_id, ret);
2153                 goto init_err;
2154         }
2155
2156         priv->num_rx_tc = attr.num_rx_tcs;
2157
2158         for (i = 0; i < attr.num_rx_tcs; i++)
2159                 priv->nb_rx_queues += attr.num_queues;
2160
2161         /* Using number of TX queues as number of TX TCs */
2162         priv->nb_tx_queues = attr.num_tx_tcs;
2163
2164         DPAA2_PMD_DEBUG("RX-TC= %d, nb_rx_queues= %d, nb_tx_queues=%d",
2165                         priv->num_rx_tc, priv->nb_rx_queues,
2166                         priv->nb_tx_queues);
2167
2168         priv->hw = dpni_dev;
2169         priv->hw_id = hw_id;
2170         priv->options = attr.options;
2171         priv->max_mac_filters = attr.mac_filter_entries;
2172         priv->max_vlan_filters = attr.vlan_filter_entries;
2173         priv->flags = 0;
2174
2175         /* Allocate memory for hardware structure for queues */
2176         ret = dpaa2_alloc_rx_tx_queues(eth_dev);
2177         if (ret) {
2178                 DPAA2_PMD_ERR("Queue allocation Failed");
2179                 goto init_err;
2180         }
2181
2182         /* Allocate memory for storing MAC addresses.
2183          * Table of mac_filter_entries size is allocated so that RTE ether lib
2184          * can add MAC entries when rte_eth_dev_mac_addr_add is called.
2185          */
2186         eth_dev->data->mac_addrs = rte_zmalloc("dpni",
2187                 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
2188         if (eth_dev->data->mac_addrs == NULL) {
2189                 DPAA2_PMD_ERR(
2190                    "Failed to allocate %d bytes needed to store MAC addresses",
2191                    ETHER_ADDR_LEN * attr.mac_filter_entries);
2192                 ret = -ENOMEM;
2193                 goto init_err;
2194         }
2195
2196         ret = populate_mac_addr(dpni_dev, priv, &eth_dev->data->mac_addrs[0]);
2197         if (ret) {
2198                 DPAA2_PMD_ERR("Unable to fetch MAC Address for device");
2199                 rte_free(eth_dev->data->mac_addrs);
2200                 eth_dev->data->mac_addrs = NULL;
2201                 goto init_err;
2202         }
2203
2204         /* ... tx buffer layout ... */
2205         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2206         layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2207         layout.pass_frame_status = 1;
2208         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2209                                      DPNI_QUEUE_TX, &layout);
2210         if (ret) {
2211                 DPAA2_PMD_ERR("Error (%d) in setting tx buffer layout", ret);
2212                 goto init_err;
2213         }
2214
2215         /* ... tx-conf and error buffer layout ... */
2216         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
2217         layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
2218         layout.pass_frame_status = 1;
2219         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
2220                                      DPNI_QUEUE_TX_CONFIRM, &layout);
2221         if (ret) {
2222                 DPAA2_PMD_ERR("Error (%d) in setting tx-conf buffer layout",
2223                              ret);
2224                 goto init_err;
2225         }
2226
2227         eth_dev->dev_ops = &dpaa2_ethdev_ops;
2228
2229         if (dpaa2_get_devargs(dev->devargs, DRIVER_LOOPBACK_MODE)) {
2230                 eth_dev->rx_pkt_burst = dpaa2_dev_loopback_rx;
2231                 DPAA2_PMD_INFO("Loopback mode");
2232         } else {
2233                 eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
2234         }
2235         eth_dev->tx_pkt_burst = dpaa2_dev_tx;
2236
2237         /*Init fields w.r.t. classficaition*/
2238         memset(&priv->extract.qos_key_cfg, 0, sizeof(struct dpkg_profile_cfg));
2239         priv->extract.qos_extract_param = (size_t)rte_malloc(NULL, 256, 64);
2240         if (!priv->extract.qos_extract_param) {
2241                 DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow "
2242                             " classificaiton ", ret);
2243                 goto init_err;
2244         }
2245         for (i = 0; i < MAX_TCS; i++) {
2246                 memset(&priv->extract.fs_key_cfg[i], 0,
2247                         sizeof(struct dpkg_profile_cfg));
2248                 priv->extract.fs_extract_param[i] =
2249                         (size_t)rte_malloc(NULL, 256, 64);
2250                 if (!priv->extract.fs_extract_param[i]) {
2251                         DPAA2_PMD_ERR(" Error(%d) in allocation resources for flow classificaiton",
2252                                      ret);
2253                         goto init_err;
2254                 }
2255         }
2256
2257         RTE_LOG(INFO, PMD, "%s: netdev created\n", eth_dev->data->name);
2258         return 0;
2259 init_err:
2260         dpaa2_dev_uninit(eth_dev);
2261         return ret;
2262 }
2263
2264 static int
2265 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
2266 {
2267         struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
2268         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
2269         int i, ret;
2270
2271         PMD_INIT_FUNC_TRACE();
2272
2273         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2274                 return 0;
2275
2276         if (!dpni) {
2277                 DPAA2_PMD_WARN("Already closed or not started");
2278                 return -1;
2279         }
2280
2281         dpaa2_dev_close(eth_dev);
2282
2283         dpaa2_free_rx_tx_queues(eth_dev);
2284
2285         /* Close the device at underlying layer*/
2286         ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
2287         if (ret) {
2288                 DPAA2_PMD_ERR(
2289                              "Failure closing dpni device with err code %d",
2290                              ret);
2291         }
2292
2293         /* Free the allocated memory for ethernet private data and dpni*/
2294         priv->hw = NULL;
2295         rte_free(dpni);
2296
2297         for (i = 0; i < MAX_TCS; i++) {
2298                 if (priv->extract.fs_extract_param[i])
2299                         rte_free((void *)(size_t)priv->extract.fs_extract_param[i]);
2300         }
2301
2302         if (priv->extract.qos_extract_param)
2303                 rte_free((void *)(size_t)priv->extract.qos_extract_param);
2304
2305         eth_dev->dev_ops = NULL;
2306         eth_dev->rx_pkt_burst = NULL;
2307         eth_dev->tx_pkt_burst = NULL;
2308
2309         DPAA2_PMD_INFO("%s: netdev deleted", eth_dev->data->name);
2310         return 0;
2311 }
2312
2313 static int
2314 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv,
2315                 struct rte_dpaa2_device *dpaa2_dev)
2316 {
2317         struct rte_eth_dev *eth_dev;
2318         int diag;
2319
2320         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2321                 eth_dev = rte_eth_dev_allocate(dpaa2_dev->device.name);
2322                 if (!eth_dev)
2323                         return -ENODEV;
2324                 eth_dev->data->dev_private = rte_zmalloc(
2325                                                 "ethdev private structure",
2326                                                 sizeof(struct dpaa2_dev_priv),
2327                                                 RTE_CACHE_LINE_SIZE);
2328                 if (eth_dev->data->dev_private == NULL) {
2329                         DPAA2_PMD_CRIT(
2330                                 "Unable to allocate memory for private data");
2331                         rte_eth_dev_release_port(eth_dev);
2332                         return -ENOMEM;
2333                 }
2334         } else {
2335                 eth_dev = rte_eth_dev_attach_secondary(dpaa2_dev->device.name);
2336                 if (!eth_dev)
2337                         return -ENODEV;
2338         }
2339
2340         eth_dev->device = &dpaa2_dev->device;
2341
2342         dpaa2_dev->eth_dev = eth_dev;
2343         eth_dev->data->rx_mbuf_alloc_failed = 0;
2344
2345         if (dpaa2_drv->drv_flags & RTE_DPAA2_DRV_INTR_LSC)
2346                 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
2347
2348         /* Invoke PMD device initialization function */
2349         diag = dpaa2_dev_init(eth_dev);
2350         if (diag == 0) {
2351                 rte_eth_dev_probing_finish(eth_dev);
2352                 return 0;
2353         }
2354
2355         rte_eth_dev_release_port(eth_dev);
2356         return diag;
2357 }
2358
2359 static int
2360 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
2361 {
2362         struct rte_eth_dev *eth_dev;
2363
2364         eth_dev = dpaa2_dev->eth_dev;
2365         dpaa2_dev_uninit(eth_dev);
2366
2367         rte_eth_dev_release_port(eth_dev);
2368
2369         return 0;
2370 }
2371
2372 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
2373         .drv_flags = RTE_DPAA2_DRV_INTR_LSC | RTE_DPAA2_DRV_IOVA_AS_VA,
2374         .drv_type = DPAA2_ETH,
2375         .probe = rte_dpaa2_probe,
2376         .remove = rte_dpaa2_remove,
2377 };
2378
2379 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);
2380 RTE_PMD_REGISTER_PARAM_STRING(net_dpaa2,
2381                 DRIVER_LOOPBACK_MODE "=<int>");
2382 RTE_INIT(dpaa2_pmd_init_log)
2383 {
2384         dpaa2_logtype_pmd = rte_log_register("pmd.net.dpaa2");
2385         if (dpaa2_logtype_pmd >= 0)
2386                 rte_log_set_level(dpaa2_logtype_pmd, RTE_LOG_NOTICE);
2387 }