net/dpaa2: attach the buffer pool to dpni
[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
53 #include "dpaa2_ethdev.h"
54
55 static struct rte_dpaa2_driver rte_dpaa2_pmd;
56
57 static void
58 dpaa2_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
59 {
60         struct dpaa2_dev_priv *priv = dev->data->dev_private;
61
62         PMD_INIT_FUNC_TRACE();
63
64         dev_info->if_index = priv->hw_id;
65
66         dev_info->max_mac_addrs = priv->max_mac_filters;
67         dev_info->max_rx_pktlen = DPAA2_MAX_RX_PKT_LEN;
68         dev_info->min_rx_bufsize = DPAA2_MIN_RX_BUF_SIZE;
69         dev_info->max_rx_queues = (uint16_t)priv->nb_rx_queues;
70         dev_info->max_tx_queues = (uint16_t)priv->nb_tx_queues;
71
72         dev_info->speed_capa = ETH_LINK_SPEED_1G |
73                         ETH_LINK_SPEED_2_5G |
74                         ETH_LINK_SPEED_10G;
75 }
76
77 static int
78 dpaa2_alloc_rx_tx_queues(struct rte_eth_dev *dev)
79 {
80         struct dpaa2_dev_priv *priv = dev->data->dev_private;
81         uint16_t dist_idx;
82         uint32_t vq_id;
83         struct dpaa2_queue *mc_q, *mcq;
84         uint32_t tot_queues;
85         int i;
86         struct dpaa2_queue *dpaa2_q;
87
88         PMD_INIT_FUNC_TRACE();
89
90         tot_queues = priv->nb_rx_queues + priv->nb_tx_queues;
91         mc_q = rte_malloc(NULL, sizeof(struct dpaa2_queue) * tot_queues,
92                           RTE_CACHE_LINE_SIZE);
93         if (!mc_q) {
94                 PMD_INIT_LOG(ERR, "malloc failed for rx/tx queues\n");
95                 return -1;
96         }
97
98         for (i = 0; i < priv->nb_rx_queues; i++) {
99                 mc_q->dev = dev;
100                 priv->rx_vq[i] = mc_q++;
101                 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
102                 dpaa2_q->q_storage = rte_malloc("dq_storage",
103                                         sizeof(struct queue_storage_info_t),
104                                         RTE_CACHE_LINE_SIZE);
105                 if (!dpaa2_q->q_storage)
106                         goto fail;
107
108                 memset(dpaa2_q->q_storage, 0,
109                        sizeof(struct queue_storage_info_t));
110                 dpaa2_q->q_storage->dq_storage[0] = rte_malloc(NULL,
111                         DPAA2_DQRR_RING_SIZE * sizeof(struct qbman_result),
112                         RTE_CACHE_LINE_SIZE);
113         }
114
115         for (i = 0; i < priv->nb_tx_queues; i++) {
116                 mc_q->dev = dev;
117                 mc_q->flow_id = DPNI_NEW_FLOW_ID;
118                 priv->tx_vq[i] = mc_q++;
119         }
120
121         vq_id = 0;
122         for (dist_idx = 0; dist_idx < priv->num_dist_per_tc[DPAA2_DEF_TC];
123              dist_idx++) {
124                 mcq = (struct dpaa2_queue *)priv->rx_vq[vq_id];
125                 mcq->tc_index = DPAA2_DEF_TC;
126                 mcq->flow_id = dist_idx;
127                 vq_id++;
128         }
129
130         return 0;
131 fail:
132         i -= 1;
133         mc_q = priv->rx_vq[0];
134         while (i >= 0) {
135                 dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
136                 rte_free(dpaa2_q->q_storage->dq_storage[0]);
137                 rte_free(dpaa2_q->q_storage);
138                 priv->rx_vq[i--] = NULL;
139         }
140         rte_free(mc_q);
141         return -1;
142 }
143
144 static int
145 dpaa2_eth_dev_configure(struct rte_eth_dev *dev)
146 {
147         struct rte_eth_dev_data *data = dev->data;
148         struct rte_eth_conf *eth_conf = &data->dev_conf;
149         int ret;
150
151         PMD_INIT_FUNC_TRACE();
152
153         /* Check for correct configuration */
154         if (eth_conf->rxmode.mq_mode != ETH_MQ_RX_RSS &&
155             data->nb_rx_queues > 1) {
156                 PMD_INIT_LOG(ERR, "Distribution is not enabled, "
157                             "but Rx queues more than 1\n");
158                 return -1;
159         }
160
161         if (eth_conf->rxmode.mq_mode == ETH_MQ_RX_RSS) {
162                 /* Return in case number of Rx queues is 1 */
163                 if (data->nb_rx_queues == 1)
164                         return 0;
165                 ret = dpaa2_setup_flow_dist(dev,
166                                 eth_conf->rx_adv_conf.rss_conf.rss_hf);
167                 if (ret) {
168                         PMD_INIT_LOG(ERR, "unable to set flow distribution."
169                                      "please check queue config\n");
170                         return ret;
171                 }
172         }
173         return 0;
174 }
175
176 /* Function to setup RX flow information. It contains traffic class ID,
177  * flow ID, destination configuration etc.
178  */
179 static int
180 dpaa2_dev_rx_queue_setup(struct rte_eth_dev *dev,
181                          uint16_t rx_queue_id,
182                          uint16_t nb_rx_desc __rte_unused,
183                          unsigned int socket_id __rte_unused,
184                          const struct rte_eth_rxconf *rx_conf __rte_unused,
185                          struct rte_mempool *mb_pool)
186 {
187         struct dpaa2_dev_priv *priv = dev->data->dev_private;
188         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
189         struct dpaa2_queue *dpaa2_q;
190         struct dpni_queue cfg;
191         uint8_t options = 0;
192         uint8_t flow_id;
193         uint32_t bpid;
194         int ret;
195
196         PMD_INIT_FUNC_TRACE();
197
198         PMD_INIT_LOG(DEBUG, "dev =%p, queue =%d, pool = %p, conf =%p",
199                      dev, rx_queue_id, mb_pool, rx_conf);
200
201         if (!priv->bp_list || priv->bp_list->mp != mb_pool) {
202                 bpid = mempool_to_bpid(mb_pool);
203                 ret = dpaa2_attach_bp_list(priv,
204                                            rte_dpaa2_bpid_info[bpid].bp_list);
205                 if (ret)
206                         return ret;
207         }
208         dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[rx_queue_id];
209         dpaa2_q->mb_pool = mb_pool; /**< mbuf pool to populate RX ring. */
210
211         /*Get the tc id and flow id from given VQ id*/
212         flow_id = rx_queue_id % priv->num_dist_per_tc[dpaa2_q->tc_index];
213         memset(&cfg, 0, sizeof(struct dpni_queue));
214
215         options = options | DPNI_QUEUE_OPT_USER_CTX;
216         cfg.user_context = (uint64_t)(dpaa2_q);
217
218         ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_RX,
219                              dpaa2_q->tc_index, flow_id, options, &cfg);
220         if (ret) {
221                 PMD_INIT_LOG(ERR, "Error in setting the rx flow: = %d\n", ret);
222                 return -1;
223         }
224
225         dev->data->rx_queues[rx_queue_id] = dpaa2_q;
226         return 0;
227 }
228
229 static int
230 dpaa2_dev_tx_queue_setup(struct rte_eth_dev *dev,
231                          uint16_t tx_queue_id,
232                          uint16_t nb_tx_desc __rte_unused,
233                          unsigned int socket_id __rte_unused,
234                          const struct rte_eth_txconf *tx_conf __rte_unused)
235 {
236         struct dpaa2_dev_priv *priv = dev->data->dev_private;
237         struct dpaa2_queue *dpaa2_q = (struct dpaa2_queue *)
238                 priv->tx_vq[tx_queue_id];
239         struct fsl_mc_io *dpni = priv->hw;
240         struct dpni_queue tx_conf_cfg;
241         struct dpni_queue tx_flow_cfg;
242         uint8_t options = 0, flow_id;
243         uint32_t tc_id;
244         int ret;
245
246         PMD_INIT_FUNC_TRACE();
247
248         /* Return if queue already configured */
249         if (dpaa2_q->flow_id != DPNI_NEW_FLOW_ID)
250                 return 0;
251
252         memset(&tx_conf_cfg, 0, sizeof(struct dpni_queue));
253         memset(&tx_flow_cfg, 0, sizeof(struct dpni_queue));
254
255         tc_id = 0;
256         flow_id = tx_queue_id;
257
258         ret = dpni_set_queue(dpni, CMD_PRI_LOW, priv->token, DPNI_QUEUE_TX,
259                              tc_id, flow_id, options, &tx_flow_cfg);
260         if (ret) {
261                 PMD_INIT_LOG(ERR, "Error in setting the tx flow: "
262                              "tc_id=%d, flow =%d ErrorCode = %x\n",
263                              tc_id, flow_id, -ret);
264                         return -1;
265         }
266
267         dpaa2_q->flow_id = flow_id;
268
269         if (tx_queue_id == 0) {
270                 /*Set tx-conf and error configuration*/
271                 ret = dpni_set_tx_confirmation_mode(dpni, CMD_PRI_LOW,
272                                                     priv->token,
273                                                     DPNI_CONF_DISABLE);
274                 if (ret) {
275                         PMD_INIT_LOG(ERR, "Error in set tx conf mode settings"
276                                      " ErrorCode = %x", ret);
277                         return -1;
278                 }
279         }
280         dpaa2_q->tc_index = tc_id;
281
282         dev->data->tx_queues[tx_queue_id] = dpaa2_q;
283         return 0;
284 }
285
286 static void
287 dpaa2_dev_rx_queue_release(void *q __rte_unused)
288 {
289         PMD_INIT_FUNC_TRACE();
290 }
291
292 static void
293 dpaa2_dev_tx_queue_release(void *q __rte_unused)
294 {
295         PMD_INIT_FUNC_TRACE();
296 }
297
298 static int
299 dpaa2_dev_start(struct rte_eth_dev *dev)
300 {
301         struct rte_eth_dev_data *data = dev->data;
302         struct dpaa2_dev_priv *priv = data->dev_private;
303         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
304         struct dpni_queue cfg;
305         uint16_t qdid;
306         struct dpni_queue_id qid;
307         struct dpaa2_queue *dpaa2_q;
308         int ret, i;
309
310         PMD_INIT_FUNC_TRACE();
311
312         ret = dpni_enable(dpni, CMD_PRI_LOW, priv->token);
313         if (ret) {
314                 PMD_INIT_LOG(ERR, "Failure %d in enabling dpni %d device\n",
315                              ret, priv->hw_id);
316                 return ret;
317         }
318
319         ret = dpni_get_qdid(dpni, CMD_PRI_LOW, priv->token,
320                             DPNI_QUEUE_TX, &qdid);
321         if (ret) {
322                 PMD_INIT_LOG(ERR, "Error to get qdid:ErrorCode = %d\n", ret);
323                 return ret;
324         }
325         priv->qdid = qdid;
326
327         for (i = 0; i < data->nb_rx_queues; i++) {
328                 dpaa2_q = (struct dpaa2_queue *)data->rx_queues[i];
329                 ret = dpni_get_queue(dpni, CMD_PRI_LOW, priv->token,
330                                      DPNI_QUEUE_RX, dpaa2_q->tc_index,
331                                        dpaa2_q->flow_id, &cfg, &qid);
332                 if (ret) {
333                         PMD_INIT_LOG(ERR, "Error to get flow "
334                                      "information Error code = %d\n", ret);
335                         return ret;
336                 }
337                 dpaa2_q->fqid = qid.fqid;
338         }
339
340         return 0;
341 }
342
343 /**
344  *  This routine disables all traffic on the adapter by issuing a
345  *  global reset on the MAC.
346  */
347 static void
348 dpaa2_dev_stop(struct rte_eth_dev *dev)
349 {
350         struct dpaa2_dev_priv *priv = dev->data->dev_private;
351         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
352         int ret;
353
354         PMD_INIT_FUNC_TRACE();
355
356         ret = dpni_disable(dpni, CMD_PRI_LOW, priv->token);
357         if (ret) {
358                 PMD_INIT_LOG(ERR, "Failure (ret %d) in disabling dpni %d dev\n",
359                              ret, priv->hw_id);
360                 return;
361         }
362 }
363
364 static void
365 dpaa2_dev_close(struct rte_eth_dev *dev)
366 {
367         struct dpaa2_dev_priv *priv = dev->data->dev_private;
368         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
369         int ret;
370
371         PMD_INIT_FUNC_TRACE();
372
373         /* Clean the device first */
374         ret = dpni_reset(dpni, CMD_PRI_LOW, priv->token);
375         if (ret) {
376                 PMD_INIT_LOG(ERR, "Failure cleaning dpni device with"
377                              " error code %d\n", ret);
378                 return;
379         }
380 }
381
382 static struct eth_dev_ops dpaa2_ethdev_ops = {
383         .dev_configure    = dpaa2_eth_dev_configure,
384         .dev_start            = dpaa2_dev_start,
385         .dev_stop             = dpaa2_dev_stop,
386         .dev_close            = dpaa2_dev_close,
387         .dev_infos_get     = dpaa2_dev_info_get,
388         .rx_queue_setup    = dpaa2_dev_rx_queue_setup,
389         .rx_queue_release  = dpaa2_dev_rx_queue_release,
390         .tx_queue_setup    = dpaa2_dev_tx_queue_setup,
391         .tx_queue_release  = dpaa2_dev_tx_queue_release,
392 };
393
394 static int
395 dpaa2_dev_init(struct rte_eth_dev *eth_dev)
396 {
397         struct rte_device *dev = eth_dev->device;
398         struct rte_dpaa2_device *dpaa2_dev;
399         struct fsl_mc_io *dpni_dev;
400         struct dpni_attr attr;
401         struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
402         struct dpni_buffer_layout layout;
403         int i, ret, hw_id;
404         int tot_size;
405
406         PMD_INIT_FUNC_TRACE();
407
408         /* For secondary processes, the primary has done all the work */
409         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
410                 return 0;
411
412         dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
413
414         hw_id = dpaa2_dev->object_id;
415
416         dpni_dev = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io));
417         if (!dpni_dev) {
418                 PMD_INIT_LOG(ERR, "malloc failed for dpni device\n");
419                 return -1;
420         }
421
422         dpni_dev->regs = rte_mcp_ptr_list[0];
423         ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
424         if (ret) {
425                 PMD_INIT_LOG(ERR, "Failure in opening dpni@%d device with"
426                         " error code %d\n", hw_id, ret);
427                 return -1;
428         }
429
430         /* Clean the device first */
431         ret = dpni_reset(dpni_dev, CMD_PRI_LOW, priv->token);
432         if (ret) {
433                 PMD_INIT_LOG(ERR, "Failure cleaning dpni@%d device with"
434                         " error code %d\n", hw_id, ret);
435                 return -1;
436         }
437
438         ret = dpni_get_attributes(dpni_dev, CMD_PRI_LOW, priv->token, &attr);
439         if (ret) {
440                 PMD_INIT_LOG(ERR, "Failure in getting dpni@%d attribute, "
441                         " error code %d\n", hw_id, ret);
442                 return -1;
443         }
444
445         priv->num_tc = attr.num_tcs;
446         for (i = 0; i < attr.num_tcs; i++) {
447                 priv->num_dist_per_tc[i] = attr.num_queues;
448                 break;
449         }
450
451         /* Distribution is per Tc only,
452          * so choosing RX queues from default TC only
453          */
454         priv->nb_rx_queues = priv->num_dist_per_tc[DPAA2_DEF_TC];
455
456         priv->nb_tx_queues = attr.num_queues;
457
458         priv->hw = dpni_dev;
459         priv->hw_id = hw_id;
460         priv->options = attr.options;
461         priv->max_mac_filters = attr.mac_filter_entries;
462         priv->max_vlan_filters = attr.vlan_filter_entries;
463         priv->flags = 0;
464
465         /* Allocate memory for hardware structure for queues */
466         ret = dpaa2_alloc_rx_tx_queues(eth_dev);
467         if (ret) {
468                 PMD_INIT_LOG(ERR, "dpaa2_alloc_rx_tx_queuesFailed\n");
469                 return -ret;
470         }
471
472         /* Allocate memory for storing MAC addresses */
473         eth_dev->data->mac_addrs = rte_zmalloc("dpni",
474                 ETHER_ADDR_LEN * attr.mac_filter_entries, 0);
475         if (eth_dev->data->mac_addrs == NULL) {
476                 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
477                                                 "store MAC addresses",
478                                 ETHER_ADDR_LEN * attr.mac_filter_entries);
479                 return -ENOMEM;
480         }
481
482         ret = dpni_get_primary_mac_addr(dpni_dev, CMD_PRI_LOW,
483                                         priv->token,
484                         (uint8_t *)(eth_dev->data->mac_addrs[0].addr_bytes));
485         if (ret) {
486                 PMD_INIT_LOG(ERR, "DPNI get mac address failed:"
487                                         " Error Code = %d\n", ret);
488                 return -ret;
489         }
490
491         /* ... rx buffer layout ... */
492         tot_size = DPAA2_HW_BUF_RESERVE + RTE_PKTMBUF_HEADROOM;
493         tot_size = RTE_ALIGN_CEIL(tot_size,
494                                   DPAA2_PACKET_LAYOUT_ALIGN);
495
496         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
497         layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
498                                 DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
499                                 DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM |
500                                 DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
501
502         layout.pass_frame_status = 1;
503         layout.data_head_room = tot_size
504                 - DPAA2_FD_PTA_SIZE - DPAA2_MBUF_HW_ANNOTATION;
505         layout.private_data_size = DPAA2_FD_PTA_SIZE;
506         layout.pass_parser_result = 1;
507         PMD_INIT_LOG(DEBUG, "Tot_size = %d, head room = %d, private = %d",
508                      tot_size, layout.data_head_room, layout.private_data_size);
509         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
510                                      DPNI_QUEUE_RX, &layout);
511         if (ret) {
512                 PMD_INIT_LOG(ERR, "Err(%d) in setting rx buffer layout", ret);
513                 return -1;
514         }
515
516         /* ... tx buffer layout ... */
517         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
518         layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
519         layout.pass_frame_status = 1;
520         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
521                                      DPNI_QUEUE_TX, &layout);
522         if (ret) {
523                 PMD_INIT_LOG(ERR, "Error (%d) in setting tx buffer"
524                                   " layout", ret);
525                 return -1;
526         }
527
528         /* ... tx-conf and error buffer layout ... */
529         memset(&layout, 0, sizeof(struct dpni_buffer_layout));
530         layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
531         layout.pass_frame_status = 1;
532         ret = dpni_set_buffer_layout(dpni_dev, CMD_PRI_LOW, priv->token,
533                                      DPNI_QUEUE_TX_CONFIRM, &layout);
534         if (ret) {
535                 PMD_INIT_LOG(ERR, "Error (%d) in setting tx-conf buffer"
536                                   " layout", ret);
537                 return -1;
538         }
539
540         eth_dev->dev_ops = &dpaa2_ethdev_ops;
541         eth_dev->data->drv_name = rte_dpaa2_pmd.driver.name;
542
543         return 0;
544 }
545
546 static int
547 dpaa2_dev_uninit(struct rte_eth_dev *eth_dev)
548 {
549         struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
550         struct fsl_mc_io *dpni = (struct fsl_mc_io *)priv->hw;
551         int i, ret;
552         struct dpaa2_queue *dpaa2_q;
553
554         PMD_INIT_FUNC_TRACE();
555
556         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
557                 return -EPERM;
558
559         if (!dpni) {
560                 PMD_INIT_LOG(WARNING, "Already closed or not started");
561                 return -1;
562         }
563
564         dpaa2_dev_close(eth_dev);
565
566         if (priv->rx_vq[0]) {
567                 /* cleaning up queue storage */
568                 for (i = 0; i < priv->nb_rx_queues; i++) {
569                         dpaa2_q = (struct dpaa2_queue *)priv->rx_vq[i];
570                         if (dpaa2_q->q_storage)
571                                 rte_free(dpaa2_q->q_storage);
572                 }
573                 /*free the all queue memory */
574                 rte_free(priv->rx_vq[0]);
575                 priv->rx_vq[0] = NULL;
576         }
577
578         /* Allocate memory for storing MAC addresses */
579         if (eth_dev->data->mac_addrs) {
580                 rte_free(eth_dev->data->mac_addrs);
581                 eth_dev->data->mac_addrs = NULL;
582         }
583
584         /*Close the device at underlying layer*/
585         ret = dpni_close(dpni, CMD_PRI_LOW, priv->token);
586         if (ret) {
587                 PMD_INIT_LOG(ERR, "Failure closing dpni device with"
588                         " error code %d\n", ret);
589         }
590
591         /*Free the allocated memory for ethernet private data and dpni*/
592         priv->hw = NULL;
593         free(dpni);
594
595         eth_dev->dev_ops = NULL;
596
597         return 0;
598 }
599
600 static int
601 rte_dpaa2_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
602                 struct rte_dpaa2_device *dpaa2_dev)
603 {
604         struct rte_eth_dev *eth_dev;
605         char ethdev_name[RTE_ETH_NAME_MAX_LEN];
606
607         int diag;
608
609         sprintf(ethdev_name, "dpni-%d", dpaa2_dev->object_id);
610
611         eth_dev = rte_eth_dev_allocate(ethdev_name);
612         if (eth_dev == NULL)
613                 return -ENOMEM;
614
615         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
616                 eth_dev->data->dev_private = rte_zmalloc(
617                                                 "ethdev private structure",
618                                                 sizeof(struct dpaa2_dev_priv),
619                                                 RTE_CACHE_LINE_SIZE);
620                 if (eth_dev->data->dev_private == NULL) {
621                         PMD_INIT_LOG(CRIT, "Cannot allocate memzone for"
622                                      " private port data\n");
623                         rte_eth_dev_release_port(eth_dev);
624                         return -ENOMEM;
625                 }
626         }
627         eth_dev->device = &dpaa2_dev->device;
628         dpaa2_dev->eth_dev = eth_dev;
629         eth_dev->data->rx_mbuf_alloc_failed = 0;
630
631         /* Invoke PMD device initialization function */
632         diag = dpaa2_dev_init(eth_dev);
633         if (diag == 0)
634                 return 0;
635
636         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
637                 rte_free(eth_dev->data->dev_private);
638         rte_eth_dev_release_port(eth_dev);
639         return diag;
640 }
641
642 static int
643 rte_dpaa2_remove(struct rte_dpaa2_device *dpaa2_dev)
644 {
645         struct rte_eth_dev *eth_dev;
646
647         eth_dev = dpaa2_dev->eth_dev;
648         dpaa2_dev_uninit(eth_dev);
649
650         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
651                 rte_free(eth_dev->data->dev_private);
652         rte_eth_dev_release_port(eth_dev);
653
654         return 0;
655 }
656
657 static struct rte_dpaa2_driver rte_dpaa2_pmd = {
658         .drv_type = DPAA2_MC_DPNI_DEVID,
659         .probe = rte_dpaa2_probe,
660         .remove = rte_dpaa2_remove,
661 };
662
663 RTE_PMD_REGISTER_DPAA2(net_dpaa2, rte_dpaa2_pmd);