net/dpaa2: add support for VLAN filter and offload
[dpdk.git] / drivers / net / dpaa2 / dpaa2_ethdev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5  *   Copyright (c) 2016 NXP. All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Freescale Semiconductor, Inc nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <time.h>
35 #include <net/if.h>
36
37 #include <rte_mbuf.h>
38 #include <rte_ethdev.h>
39 #include <rte_malloc.h>
40 #include <rte_memcpy.h>
41 #include <rte_string_fns.h>
42 #include <rte_cycles.h>
43 #include <rte_kvargs.h>
44 #include <rte_dev.h>
45 #include <rte_ethdev.h>
46 #include <rte_fslmc.h>
47
48 #include <fslmc_logs.h>
49 #include <fslmc_vfio.h>
50 #include <dpaa2_hw_pvt.h>
51 #include <dpaa2_hw_mempool.h>
52 #include <dpaa2_hw_dpio.h>
53
54 #include "dpaa2_ethdev.h"
55
56 static struct rte_dpaa2_driver rte_dpaa2_pmd;
57 static int dpaa2_dev_uninit(struct rte_eth_dev *eth_dev);
58
59 /**
60  * Atomically reads the link status information from global
61  * structure rte_eth_dev.
62  *
63  * @param dev
64  *   - Pointer to the structure rte_eth_dev to read from.
65  *   - Pointer to the buffer to be saved with the link status.
66  *
67  * @return
68  *   - On success, zero.
69  *   - On failure, negative value.
70  */
71 static inline int
72 dpaa2_dev_atomic_read_link_status(struct rte_eth_dev *dev,
73                                   struct rte_eth_link *link)
74 {
75         struct rte_eth_link *dst = link;
76         struct rte_eth_link *src = &dev->data->dev_link;
77
78         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
79                                 *(uint64_t *)src) == 0)
80                 return -1;
81
82         return 0;
83 }
84
85 /**
86  * Atomically writes the link status information into global
87  * structure rte_eth_dev.
88  *
89  * @param dev
90  *   - Pointer to the structure rte_eth_dev to read from.
91  *   - Pointer to the buffer to be saved with the link status.
92  *
93  * @return
94  *   - On success, zero.
95  *   - On failure, negative value.
96  */
97 static inline int
98 dpaa2_dev_atomic_write_link_status(struct rte_eth_dev *dev,
99                                    struct rte_eth_link *link)
100 {
101         struct rte_eth_link *dst = &dev->data->dev_link;
102         struct rte_eth_link *src = link;
103
104         if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
105                                 *(uint64_t *)src) == 0)
106                 return -1;
107
108         return 0;
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                 RTE_LOG(ERR, PMD, "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                 PMD_DRV_LOG(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 void
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                 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
150                         ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
151                                                       priv->token, true);
152                 else
153                         ret = dpni_enable_vlan_filter(dpni, CMD_PRI_LOW,
154                                                       priv->token, false);
155                 if (ret < 0)
156                         RTE_LOG(ERR, PMD, "Unable to set vlan filter ret = %d",
157                                 ret);
158         }
159 }
160
161 static void
162 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
163 {
164         struct dpaa2_dev_priv *priv = dev->data->dev_private;
165
166         PMD_INIT_FUNC_TRACE();
167
168         dev_info->if_index = priv->hw_id;
169
170         dev_info->max_mac_addrs = priv->max_mac_filters;
171         dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
172         dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
173         dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
174         dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
175         dev_info->rx_offload_capa =
176                 DEV_RX_OFFLOAD_IPV4_CKSUM |
177                 DEV_RX_OFFLOAD_UDP_CKSUM |
178                 DEV_RX_OFFLOAD_TCP_CKSUM |
179                 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM;
180         dev_info->tx_offload_capa =
181                 DEV_TX_OFFLOAD_IPV4_CKSUM |
182                 DEV_TX_OFFLOAD_UDP_CKSUM |
183                 DEV_TX_OFFLOAD_TCP_CKSUM |
184                 DEV_TX_OFFLOAD_SCTP_CKSUM |
185                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM;
186         dev_info->speed_capa = ETH_LINK_SPEED_1G |
187                         ETH_LINK_SPEED_2_5G |
188                         ETH_LINK_SPEED_10G;
189 }
190
191 static int
192 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
193 {
194         struct dpaa2_dev_priv *priv = dev->data->dev_private;
195         uint16_t dist_idx;
196         uint32_t vq_id;
197         struct dpaa2_queue *mc_q, *mcq;
198         uint32_t tot_queues;
199         int i;
200         struct dpaa2_queue *dpaa2_q;
201
202         PMD_INIT_FUNC_TRACE();
203
204         tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
205         mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
206                           RTE_CACHE_LINE_SIZE);
207         if (!mc_q) {
208                 PMD_INIT_LOG(ERR, "malloc failed for rx/tx queues\n");
209                 return -1;
210         }
211
212         for (i = 0; i < priv->nb_rx_queues; i++) {
213                 mc_q->dev = dev;
214                 priv->rx_vq[i] = mc_q++;
215                 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
216                 dpaa2_q->q_storage = rte_malloc("dq_storage",
217                                         sizeof(struct queue_storage_info_t),
218                                         RTE_CACHE_LINE_SIZE);
219                 if (!dpaa2_q->q_storage)
220                         goto fail;
221
222                 memset(dpaa2_q->q_storage, 0,
223                        sizeof(struct queue_storage_info_t));
224                 if (dpaa2_alloc_dq_storage(dpaa2_q->q_storage))
225                         goto fail;
226         }
227
228         for (i = 0; i < priv->nb_tx_queues; i++) {
229                 mc_q->dev = dev;
230                 mc_q->flow_id = 0xffff;
231                 priv->tx_vq[i] = mc_q++;
232                 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
233                 dpaa2_q->cscn = rte_malloc(NULL,
234                                            sizeof(struct qbman_result), 16);
235                 if (!dpaa2_q->cscn)
236                         goto fail_tx;
237         }
238
239         vq_id = 0;
240         for (dist_idx = 0; dist_idx < priv->num_dist_per_tc[DPAA2_DEF_TC];
241              dist_idx++) {
242                 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
243                 mcq->tc_index = DPAA2_DEF_TC;
244                 mcq->flow_id = dist_idx;
245                 vq_id++;
246         }
247
248         return 0;
249 fail_tx:
250         i -= 1;
251         while (i >= 0) {
252                 dpaa2_q = (struct dpaa2_queue *)priv->tx_vq[i];
253                 rte_free(dpaa2_q->cscn);
254                 priv->tx_vq[i--] = NULL;
255         }
256         i = priv->nb_rx_queues;
257 fail:
258         i -= 1;
259         mc_q = priv->rx_vq[0];
260         while (i >= 0) {
261                 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
262                 dpaa2_free_dq_storage(dpaa2_q->q_storage);
263                 rte_free(dpaa2_q->q_storage);
264                 priv->rx_vq[i--] = NULL;
265         }
266         rte_free(mc_q);
267         return -1;
268 }
269
270 static int
271 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
272 {
273         struct rte_eth_dev_data *data = dev->data;
274         struct rte_eth_conf *eth_conf = &data->dev_conf;
275         int ret;
276
277         PMD_INIT_FUNC_TRACE();
278
279         /* Check for correct configuration */
280         if (eth_conf->rxmode.mq_mode != ETH_MQ_RX_RSS &&
281             data->nb_rx_queues > 1) {
282                 PMD_INIT_LOG(ERR, "Distribution is not enabled, "
283                             "but Rx queues more than 1\n");
284                 return -1;
285         }
286
287         if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
288                 /* Return in case number of Rx queues is 1 */
289                 if (data->nb_rx_queues == 1)
290                         return 0;
291                 ret = dpaa2_setup_flow_dist(dev,
292                                 eth_conf->rx_adv_conf.rss_conf.rss_hf);
293                 if (ret) {
294                         PMD_INIT_LOG(ERR, "unable to set flow distribution."
295                                      "please check queue config\n");
296                         return ret;
297                 }
298         }
299         return 0;
300 }
301
302 /* Function to setup RX flow information. It contains traffic class ID,
303  * flow ID, destination configuration etc.
304  */
305 static int
306 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
307                          uint16_t rx_queue_id,
308                          uint16_t nb_rx_desc __rte_unused,
309                          unsigned int socket_id __rte_unused,
310                          const struct rte_eth_rxconf *rx_conf __rte_unused,
311                          struct rte_mempool *mb_pool)
312 {
313         struct dpaa2_dev_priv *priv = dev->data->dev_private;
314         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
315         struct dpaa2_queue *dpaa2_q;
316         struct dpni_queue cfg;
317         uint8_t options = 0;
318         uint8_t flow_id;
319         uint32_t bpid;
320         int ret;
321
322         PMD_INIT_FUNC_TRACE();
323
324         PMD_INIT_LOG(DEBUG, "dev =%p, queue =%d, pool = %p, conf =%p",
325                      dev, rx_queue_id, mb_pool, rx_conf);
326
327         if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
328                 bpid = mempool_to_bpid(mb_pool);
329                 ret = dpaa2_attach_bp_list(priv,
330                                            rte_dpaa2_bpid_info[bpid].bp_list);
331                 if (ret)
332                         return ret;
333         }
334         dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
335         dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
336
337         /*Get the tc id and flow id from given VQ id*/
338         flow_id = rx_queue_id % priv->num_dist_per_tc[dpaa2_q->tc_index];
339         memset(&cfg, 0, sizeof(struct dpni_queue));
340
341         options = options | DPNI_QUEUE_OPT_USER_CTX;
342         cfg.user_context = (uint64_t)(dpaa2_q);
343
344         /*if ls2088 or rev2 device, enable the stashing */
345         if ((qbman_get_version() & 0xFFFF0000) > QMAN_REV_4000) {
346                 options |= DPNI_QUEUE_OPT_FLC;
347                 cfg.flc.stash_control = true;
348                 cfg.flc.value &= 0xFFFFFFFFFFFFFFC0;
349                 /* 00 00 00 - last 6 bit represent annotation, context stashing,
350                  * data stashing setting 01 01 00 (0x14) to enable
351                  * 1 line data, 1 line annotation
352                  */
353                 cfg.flc.value |= 0x14;
354         }
355         ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
356                              dpaa2_q->tc_index, flow_id, options, &cfg);
357         if (ret) {
358                 PMD_INIT_LOG(ERR, "Error in setting the rx flow: = %d\n", ret);
359                 return -1;
360         }
361
362         if (!(priv->flags & DPAA2_RX_TAILDROP_OFF)) {
363                 struct dpni_taildrop taildrop;
364
365                 taildrop.enable = 1;
366                 /*enabling per rx queue congestion control */
367                 taildrop.threshold = CONG_THRESHOLD_RX_Q;
368                 taildrop.units = DPNI_CONGESTION_UNIT_BYTES;
369                 PMD_INIT_LOG(DEBUG, "Enabling Early Drop on queue = %d",
370                              rx_queue_id);
371                 ret = dpni_set_taildrop(dpni, CMD_PRI_LOW, priv->token,
372                                         DPNI_CP_QUEUE, DPNI_QUEUE_RX,
373                                         dpaa2_q->tc_index, flow_id, &taildrop);
374                 if (ret) {
375                         PMD_INIT_LOG(ERR, "Error in setting the rx flow"
376                                      " err : = %d\n", ret);
377                         return -1;
378                 }
379         }
380
381         dev->data->rx_queues[rx_queue_id] = dpaa2_q;
382         return 0;
383 }
384
385 static int
386 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
387                          uint16_t tx_queue_id,
388                          uint16_t nb_tx_desc __rte_unused,
389                          unsigned int socket_id __rte_unused,
390                          const struct rte_eth_txconf *tx_conf __rte_unused)
391 {
392         struct dpaa2_dev_priv *priv = dev->data->dev_private;
393         struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
394                 priv->tx_vq[tx_queue_id];
395         struct fsl_mc_io *dpni = priv->hw;
396         struct dpni_queue tx_conf_cfg;
397         struct dpni_queue tx_flow_cfg;
398         uint8_t options = 0, flow_id;
399         uint32_t tc_id;
400         int ret;
401
402         PMD_INIT_FUNC_TRACE();
403
404         /* Return if queue already configured */
405         if (dpaa2_q->flow_id != 0xffff)
406                 return 0;
407
408         memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
409         memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
410
411         if (priv->num_tc == 1) {
412                 tc_id = 0;
413                 flow_id = tx_queue_id % priv->num_dist_per_tc[tc_id];
414         } else {
415                 tc_id = tx_queue_id;
416                 flow_id = 0;
417         }
418
419         ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
420                              tc_id, flow_id, options, &tx_flow_cfg);
421         if (ret) {
422                 PMD_INIT_LOG(ERR, "Error in setting the tx flow: "
423                              "tc_id=%d, flow =%d ErrorCode = %x\n",
424                              tc_id, flow_id, -ret);
425                         return -1;
426         }
427
428         dpaa2_q->flow_id = flow_id;
429
430         if (tx_queue_id == 0) {
431                 /*Set tx-conf and error configuration*/
432                 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
433                                                     priv->token,
434                                                     DPNI_CONF_DISABLE);
435                 if (ret) {
436                         PMD_INIT_LOG(ERR, "Error in set tx conf mode settings"
437                                      " ErrorCode = %x", ret);
438                         return -1;
439                 }
440         }
441         dpaa2_q->tc_index = tc_id;
442
443         if (priv->flags & DPAA2_TX_CGR_SUPPORT) {
444                 struct dpni_congestion_notification_cfg cong_notif_cfg;
445
446                 cong_notif_cfg.units = DPNI_CONGESTION_UNIT_BYTES;
447                 /* Notify about congestion when the queue size is 32 KB */
448                 cong_notif_cfg.threshold_entry = CONG_ENTER_TX_THRESHOLD;
449                 /* Notify that the queue is not congested when the data in
450                  * the queue is below this thershold.
451                  */
452                 cong_notif_cfg.threshold_exit = CONG_EXIT_TX_THRESHOLD;
453                 cong_notif_cfg.message_ctx = 0;
454                 cong_notif_cfg.message_iova = (uint64_t)dpaa2_q->cscn;
455                 cong_notif_cfg.dest_cfg.dest_type = DPNI_DEST_NONE;
456                 cong_notif_cfg.notification_mode =
457                                          DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
458                                          DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
459                                          DPNI_CONG_OPT_COHERENT_WRITE;
460
461                 ret = dpni_set_congestion_notification(dpni, CMD_PRI_LOW,
462                                                        priv->token,
463                                                        DPNI_QUEUE_TX,
464                                                        tc_id,
465                                                        &cong_notif_cfg);
466                 if (ret) {
467                         PMD_INIT_LOG(ERR,
468                            "Error in setting tx congestion notification: = %d",
469                            -ret);
470                         return -ret;
471                 }
472         }
473         dev->data->tx_queues[tx_queue_id] = dpaa2_q;
474         return 0;
475 }
476
477 static void
478 dpaa2_dev_rx_queue_release(void *q __rte_unused)
479 {
480         PMD_INIT_FUNC_TRACE();
481 }
482
483 static void
484 dpaa2_dev_tx_queue_release(void *q __rte_unused)
485 {
486         PMD_INIT_FUNC_TRACE();
487 }
488
489 static const uint32_t *
490 dpaa2_supported_ptypes_get(struct rte_eth_dev *dev)
491 {
492         static const uint32_t ptypes[] = {
493                 /*todo -= add more types */
494                 RTE_PTYPE_L2_ETHER,
495                 RTE_PTYPE_L3_IPV4,
496                 RTE_PTYPE_L3_IPV4_EXT,
497                 RTE_PTYPE_L3_IPV6,
498                 RTE_PTYPE_L3_IPV6_EXT,
499                 RTE_PTYPE_L4_TCP,
500                 RTE_PTYPE_L4_UDP,
501                 RTE_PTYPE_L4_SCTP,
502                 RTE_PTYPE_L4_ICMP,
503                 RTE_PTYPE_UNKNOWN
504         };
505
506         if (dev->rx_pkt_burst == dpaa2_dev_prefetch_rx)
507                 return ptypes;
508         return NULL;
509 }
510
511 static int
512 dpaa2_dev_start(struct rte_eth_dev *dev)
513 {
514         struct rte_eth_dev_data *data = dev->data;
515         struct dpaa2_dev_priv *priv = data->dev_private;
516         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
517         struct dpni_queue cfg;
518         struct dpni_error_cfg   err_cfg;
519         uint16_t qdid;
520         struct dpni_queue_id qid;
521         struct dpaa2_queue *dpaa2_q;
522         int ret, i;
523
524         PMD_INIT_FUNC_TRACE();
525
526         ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
527         if (ret) {
528                 PMD_INIT_LOG(ERR, "Failure %d in enabling dpni %d device\n",
529                              ret, priv->hw_id);
530                 return ret;
531         }
532
533         ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
534                             DPNI_QUEUE_TX, &qdid);
535         if (ret) {
536                 PMD_INIT_LOG(ERR, "Error to get qdid:ErrorCode = %d\n", ret);
537                 return ret;
538         }
539         priv->qdid = qdid;
540
541         for (i = 0; i < data->nb_rx_queues; i++) {
542                 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
543                 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
544                                      DPNI_QUEUE_RX, dpaa2_q->tc_index,
545                                        dpaa2_q->flow_id, &cfg, &qid);
546                 if (ret) {
547                         PMD_INIT_LOG(ERR, "Error to get flow "
548                                      "information Error code = %d\n", ret);
549                         return ret;
550                 }
551                 dpaa2_q->fqid = qid.fqid;
552         }
553
554         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
555                                DPNI_OFF_RX_L3_CSUM, true);
556         if (ret) {
557                 PMD_INIT_LOG(ERR, "Error to set RX l3 csum:Error = %d\n", ret);
558                 return ret;
559         }
560
561         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
562                                DPNI_OFF_RX_L4_CSUM, true);
563         if (ret) {
564                 PMD_INIT_LOG(ERR, "Error to get RX l4 csum:Error = %d\n", ret);
565                 return ret;
566         }
567
568         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
569                                DPNI_OFF_TX_L3_CSUM, true);
570         if (ret) {
571                 PMD_INIT_LOG(ERR, "Error to set TX l3 csum:Error = %d\n", ret);
572                 return ret;
573         }
574
575         ret = dpni_set_offload(dpni, CMD_PRI_LOW, priv->token,
576                                DPNI_OFF_TX_L4_CSUM, true);
577         if (ret) {
578                 PMD_INIT_LOG(ERR, "Error to get TX l4 csum:Error = %d\n", ret);
579                 return ret;
580         }
581
582         /*checksum errors, send them to normal path and set it in annotation */
583         err_cfg.errors = DPNI_ERROR_L3CE | DPNI_ERROR_L4CE;
584
585         err_cfg.error_action = DPNI_ERROR_ACTION_CONTINUE;
586         err_cfg.set_frame_annotation = true;
587
588         ret = dpni_set_errors_behavior(dpni, CMD_PRI_LOW,
589                                        priv->token, &err_cfg);
590         if (ret) {
591                 PMD_INIT_LOG(ERR, "Error to dpni_set_errors_behavior:"
592                              "code = %d\n", ret);
593                 return ret;
594         }
595         /* VLAN Offload Settings */
596         if (priv->max_vlan_filters)
597                 dpaa2_vlan_offload_set(dev, ETH_VLAN_FILTER_MASK);
598
599         return 0;
600 }
601
602 /**
603  *  This routine disables all traffic on the adapter by issuing a
604  *  global reset on the MAC.
605  */
606 static void
607 dpaa2_dev_stop(struct rte_eth_dev *dev)
608 {
609         struct dpaa2_dev_priv *priv = dev->data->dev_private;
610         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
611         int ret;
612         struct rte_eth_link link;
613
614         PMD_INIT_FUNC_TRACE();
615
616         ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
617         if (ret) {
618                 PMD_INIT_LOG(ERR, "Failure (ret %d) in disabling dpni %d dev\n",
619                              ret, priv->hw_id);
620                 return;
621         }
622
623         /* clear the recorded link status */
624         memset(&link, 0, sizeof(link));
625         dpaa2_dev_atomic_write_link_status(dev, &link);
626 }
627
628 static void
629 dpaa2_dev_close(struct rte_eth_dev *dev)
630 {
631         struct rte_eth_dev_data *data = dev->data;
632         struct dpaa2_dev_priv *priv = dev->data->dev_private;
633         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
634         int i, ret;
635         struct dpaa2_queue *dpaa2_q;
636
637         PMD_INIT_FUNC_TRACE();
638
639         for (i = 0; i < data->nb_tx_queues; i++) {
640                 dpaa2_q = (struct dpaa2_queue *)data->tx_queues[i];
641                 if (!dpaa2_q->cscn) {
642                         rte_free(dpaa2_q->cscn);
643                         dpaa2_q->cscn = NULL;
644                 }
645         }
646
647         /* Clean the device first */
648         ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
649         if (ret) {
650                 PMD_INIT_LOG(ERR, "Failure cleaning dpni device with"
651                              " error code %d\n", ret);
652                 return;
653         }
654 }
655
656 static void
657 dpaa2_dev_promiscuous_enable(
658                 struct rte_eth_dev *dev)
659 {
660         int ret;
661         struct dpaa2_dev_priv *priv = dev->data->dev_private;
662         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
663
664         PMD_INIT_FUNC_TRACE();
665
666         if (dpni == NULL) {
667                 RTE_LOG(ERR, PMD, "dpni is NULL");
668                 return;
669         }
670
671         ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
672         if (ret < 0)
673                 RTE_LOG(ERR, PMD, "Unable to enable U promisc mode %d", ret);
674
675         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
676         if (ret < 0)
677                 RTE_LOG(ERR, PMD, "Unable to enable M promisc mode %d", ret);
678 }
679
680 static void
681 dpaa2_dev_promiscuous_disable(
682                 struct rte_eth_dev *dev)
683 {
684         int ret;
685         struct dpaa2_dev_priv *priv = dev->data->dev_private;
686         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
687
688         PMD_INIT_FUNC_TRACE();
689
690         if (dpni == NULL) {
691                 RTE_LOG(ERR, PMD, "dpni is NULL");
692                 return;
693         }
694
695         ret = dpni_set_unicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
696         if (ret < 0)
697                 RTE_LOG(ERR, PMD, "Unable to disable U promisc mode %d", ret);
698
699         if (dev->data->all_multicast == 0) {
700                 ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW,
701                                                  priv->token, false);
702                 if (ret < 0)
703                         RTE_LOG(ERR, PMD, "Unable to disable M promisc mode %d",
704                                 ret);
705         }
706 }
707
708 static void
709 dpaa2_dev_allmulticast_enable(
710                 struct rte_eth_dev *dev)
711 {
712         int ret;
713         struct dpaa2_dev_priv *priv = dev->data->dev_private;
714         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
715
716         PMD_INIT_FUNC_TRACE();
717
718         if (dpni == NULL) {
719                 RTE_LOG(ERR, PMD, "dpni is NULL");
720                 return;
721         }
722
723         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, true);
724         if (ret < 0)
725                 RTE_LOG(ERR, PMD, "Unable to enable multicast mode %d", ret);
726 }
727
728 static void
729 dpaa2_dev_allmulticast_disable(struct rte_eth_dev *dev)
730 {
731         int ret;
732         struct dpaa2_dev_priv *priv = dev->data->dev_private;
733         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
734
735         PMD_INIT_FUNC_TRACE();
736
737         if (dpni == NULL) {
738                 RTE_LOG(ERR, PMD, "dpni is NULL");
739                 return;
740         }
741
742         /* must remain on for all promiscuous */
743         if (dev->data->promiscuous == 1)
744                 return;
745
746         ret = dpni_set_multicast_promisc(dpni, CMD_PRI_LOW, priv->token, false);
747         if (ret < 0)
748                 RTE_LOG(ERR, PMD, "Unable to disable multicast mode %d", ret);
749 }
750
751 static int
752 dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
753 {
754         int ret;
755         struct dpaa2_dev_priv *priv = dev->data->dev_private;
756         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
757         uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
758
759         PMD_INIT_FUNC_TRACE();
760
761         if (dpni == NULL) {
762                 RTE_LOG(ERR, PMD, "dpni is NULL");
763                 return -EINVAL;
764         }
765
766         /* check that mtu is within the allowed range */
767         if ((mtu < ETHER_MIN_MTU) || (frame_size > DPAA2_MAX_RX_PKT_LEN))
768                 return -EINVAL;
769
770         /* Set the Max Rx frame length as 'mtu' +
771          * Maximum Ethernet header length
772          */
773         ret = dpni_set_max_frame_length(dpni, CMD_PRI_LOW, priv->token,
774                                         mtu + ETH_VLAN_HLEN);
775         if (ret) {
776                 PMD_DRV_LOG(ERR, "setting the max frame length failed");
777                 return -1;
778         }
779         PMD_DRV_LOG(INFO, "MTU is configured %d for the device\n", mtu);
780         return 0;
781 }
782
783 static int
784 dpaa2_dev_add_mac_addr(struct rte_eth_dev *dev,
785                        struct ether_addr *addr,
786                        __rte_unused uint32_t index,
787                        __rte_unused uint32_t pool)
788 {
789         int ret;
790         struct dpaa2_dev_priv *priv = dev->data->dev_private;
791         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
792
793         PMD_INIT_FUNC_TRACE();
794
795         if (dpni == NULL) {
796                 RTE_LOG(ERR, PMD, "dpni is NULL");
797                 return -1;
798         }
799
800         ret = dpni_add_mac_addr(dpni, CMD_PRI_LOW,
801                                 priv->token, addr->addr_bytes);
802         if (ret)
803                 RTE_LOG(ERR, PMD, "error: Adding the MAC ADDR failed:"
804                         " err = %d", ret);
805         return 0;
806 }
807
808 static void
809 dpaa2_dev_remove_mac_addr(struct rte_eth_dev *dev,
810                           uint32_t index)
811 {
812         int ret;
813         struct dpaa2_dev_priv *priv = dev->data->dev_private;
814         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
815         struct rte_eth_dev_data *data = dev->data;
816         struct ether_addr *macaddr;
817
818         PMD_INIT_FUNC_TRACE();
819
820         macaddr = &data->mac_addrs[index];
821
822         if (dpni == NULL) {
823                 RTE_LOG(ERR, PMD, "dpni is NULL");
824                 return;
825         }
826
827         ret = dpni_remove_mac_addr(dpni, CMD_PRI_LOW,
828                                    priv->token, macaddr->addr_bytes);
829         if (ret)
830                 RTE_LOG(ERR, PMD, "error: Removing the MAC ADDR failed:"
831                         " err = %d", ret);
832 }
833
834 static void
835 dpaa2_dev_set_mac_addr(struct rte_eth_dev *dev,
836                        struct ether_addr *addr)
837 {
838         int ret;
839         struct dpaa2_dev_priv *priv = dev->data->dev_private;
840         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
841
842         PMD_INIT_FUNC_TRACE();
843
844         if (dpni == NULL) {
845                 RTE_LOG(ERR, PMD, "dpni is NULL");
846                 return;
847         }
848
849         ret = dpni_set_primary_mac_addr(dpni, CMD_PRI_LOW,
850                                         priv->token, addr->addr_bytes);
851
852         if (ret)
853                 RTE_LOG(ERR, PMD, "error: Setting the MAC ADDR failed %d", ret);
854 }
855 static
856 void dpaa2_dev_stats_get(struct rte_eth_dev *dev,
857                          struct rte_eth_stats *stats)
858 {
859         struct dpaa2_dev_priv *priv = dev->data->dev_private;
860         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
861         int32_t  retcode;
862         uint8_t page0 = 0, page1 = 1, page2 = 2;
863         union dpni_statistics value;
864
865         memset(&value, 0, sizeof(union dpni_statistics));
866
867         PMD_INIT_FUNC_TRACE();
868
869         if (!dpni) {
870                 RTE_LOG(ERR, PMD, "dpni is NULL");
871                 return;
872         }
873
874         if (!stats) {
875                 RTE_LOG(ERR, PMD, "stats is NULL");
876                 return;
877         }
878
879         /*Get Counters from page_0*/
880         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
881                                       page0, &value);
882         if (retcode)
883                 goto err;
884
885         stats->ipackets = value.page_0.ingress_all_frames;
886         stats->ibytes = value.page_0.ingress_all_bytes;
887
888         /*Get Counters from page_1*/
889         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
890                                       page1, &value);
891         if (retcode)
892                 goto err;
893
894         stats->opackets = value.page_1.egress_all_frames;
895         stats->obytes = value.page_1.egress_all_bytes;
896
897         /*Get Counters from page_2*/
898         retcode = dpni_get_statistics(dpni, CMD_PRI_LOW, priv->token,
899                                       page2, &value);
900         if (retcode)
901                 goto err;
902
903         /* Ingress drop frame count due to configured rules */
904         stats->ierrors = value.page_2.ingress_filtered_frames;
905         /* Ingress drop frame count due to error */
906         stats->ierrors += value.page_2.ingress_discarded_frames;
907
908         stats->oerrors = value.page_2.egress_discarded_frames;
909         stats->imissed = value.page_2.ingress_nobuffer_discards;
910
911         return;
912
913 err:
914         RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
915         return;
916 };
917
918 static
919 void dpaa2_dev_stats_reset(struct rte_eth_dev *dev)
920 {
921         struct dpaa2_dev_priv *priv = dev->data->dev_private;
922         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
923         int32_t  retcode;
924
925         PMD_INIT_FUNC_TRACE();
926
927         if (dpni == NULL) {
928                 RTE_LOG(ERR, PMD, "dpni is NULL");
929                 return;
930         }
931
932         retcode =  dpni_reset_statistics(dpni, CMD_PRI_LOW, priv->token);
933         if (retcode)
934                 goto error;
935
936         return;
937
938 error:
939         RTE_LOG(ERR, PMD, "Operation not completed:Error Code = %d\n", retcode);
940         return;
941 };
942
943 /* return 0 means link status changed, -1 means not changed */
944 static int
945 dpaa2_dev_link_update(struct rte_eth_dev *dev,
946                         int wait_to_complete __rte_unused)
947 {
948         int ret;
949         struct dpaa2_dev_priv *priv = dev->data->dev_private;
950         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
951         struct rte_eth_link link, old;
952         struct dpni_link_state state = {0};
953
954         PMD_INIT_FUNC_TRACE();
955
956         if (dpni == NULL) {
957                 RTE_LOG(ERR, PMD, "error : dpni is NULL");
958                 return 0;
959         }
960         memset(&old, 0, sizeof(old));
961         dpaa2_dev_atomic_read_link_status(dev, &old);
962
963         ret = dpni_get_link_state(dpni, CMD_PRI_LOW, priv->token, &state);
964         if (ret < 0) {
965                 RTE_LOG(ERR, PMD, "error: dpni_get_link_state %d", ret);
966                 return -1;
967         }
968
969         if ((old.link_status == state.up) && (old.link_speed == state.rate)) {
970                 RTE_LOG(DEBUG, PMD, "No change in status\n");
971                 return -1;
972         }
973
974         memset(&link, 0, sizeof(struct rte_eth_link));
975         link.link_status = state.up;
976         link.link_speed = state.rate;
977
978         if (state.options & DPNI_LINK_OPT_HALF_DUPLEX)
979                 link.link_duplex = ETH_LINK_HALF_DUPLEX;
980         else
981                 link.link_duplex = ETH_LINK_FULL_DUPLEX;
982
983         dpaa2_dev_atomic_write_link_status(dev, &link);
984
985         if (link.link_status)
986                 PMD_DRV_LOG(INFO, "Port %d Link is Up\n", dev->data->port_id);
987         else
988                 PMD_DRV_LOG(INFO, "Port %d Link is Down\n", dev->data->port_id);
989         return 0;
990 }
991
992 static struct eth_dev_ops dpaa2_ethdev_ops = {
993         .dev_configure    = dpaa2_eth_dev_configure,
994         .dev_start            = dpaa2_dev_start,
995         .dev_stop             = dpaa2_dev_stop,
996         .dev_close            = dpaa2_dev_close,
997         .promiscuous_enable   = dpaa2_dev_promiscuous_enable,
998         .promiscuous_disable  = dpaa2_dev_promiscuous_disable,
999         .allmulticast_enable  = dpaa2_dev_allmulticast_enable,
1000         .allmulticast_disable = dpaa2_dev_allmulticast_disable,
1001         .link_update       = dpaa2_dev_link_update,
1002         .stats_get             = dpaa2_dev_stats_get,
1003         .stats_reset       = dpaa2_dev_stats_reset,
1004         .dev_infos_get     = dpaa2_dev_info_get,
1005         .dev_supported_ptypes_get = dpaa2_supported_ptypes_get,
1006         .mtu_set           = dpaa2_dev_mtu_set,
1007         .vlan_filter_set      = dpaa2_vlan_filter_set,
1008         .vlan_offload_set     = dpaa2_vlan_offload_set,
1009         .rx_queue_setup    = dpaa2_dev_rx_queue_setup,
1010         .rx_queue_release  = dpaa2_dev_rx_queue_release,
1011         .tx_queue_setup    = dpaa2_dev_tx_queue_setup,
1012         .tx_queue_release  = dpaa2_dev_tx_queue_release,
1013         .mac_addr_add         = dpaa2_dev_add_mac_addr,
1014         .mac_addr_remove      = dpaa2_dev_remove_mac_addr,
1015         .mac_addr_set         = dpaa2_dev_set_mac_addr,
1016 };
1017
1018 static int
1019 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
1020 {
1021         struct rte_device *dev = eth_dev->device;
1022         struct rte_dpaa2_device *dpaa2_dev;
1023         struct fsl_mc_io *dpni_dev;
1024         struct dpni_attr attr;
1025         struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1026         struct dpni_buffer_layout layout;
1027         int i, ret, hw_id;
1028
1029         PMD_INIT_FUNC_TRACE();
1030
1031         /* For secondary processes, the primary has done all the work */
1032         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1033                 return 0;
1034
1035         dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
1036
1037         hw_id = dpaa2_dev->object_id;
1038
1039         dpni_dev = rte_malloc(NULL, sizeof(struct fsl_mc_io), 0);
1040         if (!dpni_dev) {
1041                 PMD_INIT_LOG(ERR, "malloc failed for dpni device\n");
1042                 return -1;
1043         }
1044
1045         dpni_dev->regs = rte_mcp_ptr_list[0];
1046         ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
1047         if (ret) {
1048                 PMD_INIT_LOG(ERR,
1049                              "Failure in opening dpni@%d with err code %d\n",
1050                              hw_id, ret);
1051                 rte_free(dpni_dev);
1052                 return -1;
1053         }
1054
1055         /* Clean the device first */
1056         ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
1057         if (ret) {
1058                 PMD_INIT_LOG(ERR,
1059                              "Failure cleaning dpni@%d with err code %d\n",
1060                              hw_id, ret);
1061                 goto init_err;
1062         }
1063
1064         ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
1065         if (ret) {
1066                 PMD_INIT_LOG(ERR,
1067                              "Failure in get dpni@%d attribute, err code %d\n",
1068                              hw_id, ret);
1069                 goto init_err;
1070         }
1071
1072         priv->num_tc = attr.num_tcs;
1073         for (i = 0; i < attr.num_tcs; i++) {
1074                 priv->num_dist_per_tc[i] = attr.num_queues;
1075                 break;
1076         }
1077
1078         /* Distribution is per Tc only,
1079          * so choosing RX queues from default TC only
1080          */
1081         priv->nb_rx_queues = priv->num_dist_per_tc[DPAA2_DEF_TC];
1082
1083         if (attr.num_tcs == 1)
1084                 priv->nb_tx_queues = attr.num_queues;
1085         else
1086                 priv->nb_tx_queues = attr.num_tcs;
1087
1088         PMD_INIT_LOG(DEBUG, "num_tc %d", priv->num_tc);
1089         PMD_INIT_LOG(DEBUG, "nb_rx_queues %d", priv->nb_rx_queues);
1090
1091         priv->hw = dpni_dev;
1092         priv->hw_id = hw_id;
1093         priv->options = attr.options;
1094         priv->max_mac_filters = attr.mac_filter_entries;
1095         priv->max_vlan_filters = attr.vlan_filter_entries;
1096         priv->flags = 0;
1097
1098         priv->flags |= DPAA2_TX_CGR_SUPPORT;
1099         PMD_INIT_LOG(INFO, "Enable the tx congestion control support");
1100
1101         /* Allocate memory for hardware structure for queues */
1102         ret = dpaa2_alloc_rx_tx_queues(eth_dev);
1103         if (ret) {
1104                 PMD_INIT_LOG(ERR, "dpaa2_alloc_rx_tx_queuesFailed\n");
1105                 goto init_err;
1106         }
1107
1108         /* Allocate memory for storing MAC addresses */
1109         eth_dev->data->mac_addrs = rte_zmalloc("dpni",
1110                 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
1111         if (eth_dev->data->mac_addrs == NULL) {
1112                 PMD_INIT_LOG(ERR,
1113                    "Failed to allocate %d bytes needed to store MAC addresses",
1114                              ETHER_ADDR_LEN * attr.mac_filter_entries);
1115                 ret = -ENOMEM;
1116                 goto init_err;
1117         }
1118
1119         ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
1120                                         priv->token,
1121                         (uint8_t *)(eth_dev->data->mac_addrs[0].addr_bytes));
1122         if (ret) {
1123                 PMD_INIT_LOG(ERR, "DPNI get mac address failed:Err Code = %d\n",
1124                              ret);
1125                 goto init_err;
1126         }
1127
1128         /* ... tx buffer layout ... */
1129         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1130         layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1131         layout.pass_frame_status = 1;
1132         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1133                                      DPNI_QUEUE_TX, &layout);
1134         if (ret) {
1135                 PMD_INIT_LOG(ERR, "Error (%d) in setting tx buffer layout",
1136                              ret);
1137                 goto init_err;
1138         }
1139
1140         /* ... tx-conf and error buffer layout ... */
1141         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
1142         layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
1143         layout.pass_frame_status = 1;
1144         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
1145                                      DPNI_QUEUE_TX_CONFIRM, &layout);
1146         if (ret) {
1147                 PMD_INIT_LOG(ERR, "Error (%d) in setting tx-conf buffer layout",
1148                              ret);
1149                 goto init_err;
1150         }
1151
1152         eth_dev->dev_ops = &dpaa2_ethdev_ops;
1153         eth_dev->data->drv_name = rte_dpaa2_pmd.driver.name;
1154
1155         eth_dev->rx_pkt_burst = dpaa2_dev_prefetch_rx;
1156         eth_dev->tx_pkt_burst = dpaa2_dev_tx;
1157         rte_fslmc_vfio_dmamap();
1158
1159         return 0;
1160 init_err:
1161         dpaa2_dev_uninit(eth_dev);
1162         return ret;
1163 }
1164
1165 static int
1166 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
1167 {
1168         struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
1169         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
1170         int i, ret;
1171         struct dpaa2_queue *dpaa2_q;
1172
1173         PMD_INIT_FUNC_TRACE();
1174
1175         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1176                 return -EPERM;
1177
1178         if (!dpni) {
1179                 PMD_INIT_LOG(WARNING, "Already closed or not started");
1180                 return -1;
1181         }
1182
1183         dpaa2_dev_close(eth_dev);
1184
1185         if (priv->rx_vq[0]) {
1186                 /* cleaning up queue storage */
1187                 for (i = 0; i < priv->nb_rx_queues; i++) {
1188                         dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
1189                         if (dpaa2_q->q_storage)
1190                                 rte_free(dpaa2_q->q_storage);
1191                 }
1192                 /*free the all queue memory */
1193                 rte_free(priv->rx_vq[0]);
1194                 priv->rx_vq[0] = NULL;
1195         }
1196
1197         /* free memory for storing MAC addresses */
1198         if (eth_dev->data->mac_addrs) {
1199                 rte_free(eth_dev->data->mac_addrs);
1200                 eth_dev->data->mac_addrs = NULL;
1201         }
1202
1203         /* Close the device at underlying layer*/
1204         ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
1205         if (ret) {
1206                 PMD_INIT_LOG(ERR,
1207                              "Failure closing dpni device with err code %d\n",
1208                              ret);
1209         }
1210
1211         /* Free the allocated memory for ethernet private data and dpni*/
1212         priv->hw = NULL;
1213         rte_free(dpni);
1214
1215         eth_dev->dev_ops = NULL;
1216         eth_dev->rx_pkt_burst = NULL;
1217         eth_dev->tx_pkt_burst = NULL;
1218
1219         return 0;
1220 }
1221
1222 static int
1223 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
1224                 struct rte_dpaa2_device *dpaa2_dev)
1225 {
1226         struct rte_eth_dev *eth_dev;
1227         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
1228
1229         int diag;
1230
1231         sprintf(ethdev_name, "dpni-%d", dpaa2_dev->object_id);
1232
1233         eth_dev = rte_eth_dev_allocate(ethdev_name);
1234         if (eth_dev == NULL)
1235                 return -ENOMEM;
1236
1237         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1238                 eth_dev->data->dev_private = rte_zmalloc(
1239                                                 "ethdev private structure",
1240                                                 sizeof(struct dpaa2_dev_priv),
1241                                                 RTE_CACHE_LINE_SIZE);
1242                 if (eth_dev->data->dev_private == NULL) {
1243                         PMD_INIT_LOG(CRIT, "Cannot allocate memzone for"
1244                                      " private port data\n");
1245                         rte_eth_dev_release_port(eth_dev);
1246                         return -ENOMEM;
1247                 }
1248         }
1249         eth_dev->device = &dpaa2_dev->device;
1250         dpaa2_dev->eth_dev = eth_dev;
1251         eth_dev->data->rx_mbuf_alloc_failed = 0;
1252
1253         /* Invoke PMD device initialization function */
1254         diag = dpaa2_dev_init(eth_dev);
1255         if (diag == 0)
1256                 return 0;
1257
1258         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1259                 rte_free(eth_dev->data->dev_private);
1260         rte_eth_dev_release_port(eth_dev);
1261         return diag;
1262 }
1263
1264 static int
1265 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
1266 {
1267         struct rte_eth_dev *eth_dev;
1268
1269         eth_dev = dpaa2_dev->eth_dev;
1270         dpaa2_dev_uninit(eth_dev);
1271
1272         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1273                 rte_free(eth_dev->data->dev_private);
1274         rte_eth_dev_release_port(eth_dev);
1275
1276         return 0;
1277 }
1278
1279 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
1280         .drv_type = DPAA2_MC_DPNI_DEVID,
1281         .probe = rte_dpaa2_probe,
1282         .remove = rte_dpaa2_remove,
1283 };
1284
1285 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);