net/dpaa: support multicast toggle
[dpdk.git] / drivers / net / dpaa / dpaa_ethdev.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
5  *   Copyright 2017 NXP.
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 /* System headers */
34 #include <stdio.h>
35 #include <inttypes.h>
36 #include <unistd.h>
37 #include <limits.h>
38 #include <sched.h>
39 #include <signal.h>
40 #include <pthread.h>
41 #include <sys/types.h>
42 #include <sys/syscall.h>
43
44 #include <rte_config.h>
45 #include <rte_byteorder.h>
46 #include <rte_common.h>
47 #include <rte_interrupts.h>
48 #include <rte_log.h>
49 #include <rte_debug.h>
50 #include <rte_pci.h>
51 #include <rte_atomic.h>
52 #include <rte_branch_prediction.h>
53 #include <rte_memory.h>
54 #include <rte_memzone.h>
55 #include <rte_tailq.h>
56 #include <rte_eal.h>
57 #include <rte_alarm.h>
58 #include <rte_ether.h>
59 #include <rte_ethdev.h>
60 #include <rte_malloc.h>
61 #include <rte_ring.h>
62
63 #include <rte_dpaa_bus.h>
64 #include <rte_dpaa_logs.h>
65 #include <dpaa_mempool.h>
66
67 #include <dpaa_ethdev.h>
68 #include <dpaa_rxtx.h>
69
70 #include <fsl_usd.h>
71 #include <fsl_qman.h>
72 #include <fsl_bman.h>
73 #include <fsl_fman.h>
74
75 /* Keep track of whether QMAN and BMAN have been globally initialized */
76 static int is_global_init;
77
78 static int
79 dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
80 {
81         struct dpaa_if *dpaa_intf = dev->data->dev_private;
82
83         PMD_INIT_FUNC_TRACE();
84
85         if (mtu < ETHER_MIN_MTU)
86                 return -EINVAL;
87         if (mtu > ETHER_MAX_LEN)
88                 dev->data->dev_conf.rxmode.jumbo_frame = 1;
89         else
90                 dev->data->dev_conf.rxmode.jumbo_frame = 0;
91
92         dev->data->dev_conf.rxmode.max_rx_pkt_len = mtu;
93
94         fman_if_set_maxfrm(dpaa_intf->fif, mtu);
95
96         return 0;
97 }
98
99 static int
100 dpaa_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
101 {
102         PMD_INIT_FUNC_TRACE();
103
104         if (dev->data->dev_conf.rxmode.jumbo_frame == 1) {
105                 if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
106                     DPAA_MAX_RX_PKT_LEN)
107                         return dpaa_mtu_set(dev,
108                                 dev->data->dev_conf.rxmode.max_rx_pkt_len);
109                 else
110                         return -1;
111         }
112         return 0;
113 }
114
115 static int dpaa_eth_dev_start(struct rte_eth_dev *dev)
116 {
117         struct dpaa_if *dpaa_intf = dev->data->dev_private;
118
119         PMD_INIT_FUNC_TRACE();
120
121         /* Change tx callback to the real one */
122         dev->tx_pkt_burst = dpaa_eth_queue_tx;
123         fman_if_enable_rx(dpaa_intf->fif);
124
125         return 0;
126 }
127
128 static void dpaa_eth_dev_stop(struct rte_eth_dev *dev)
129 {
130         struct dpaa_if *dpaa_intf = dev->data->dev_private;
131
132         PMD_INIT_FUNC_TRACE();
133
134         fman_if_disable_rx(dpaa_intf->fif);
135         dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
136 }
137
138 static void dpaa_eth_dev_close(struct rte_eth_dev *dev)
139 {
140         PMD_INIT_FUNC_TRACE();
141
142         dpaa_eth_dev_stop(dev);
143 }
144
145 static void dpaa_eth_dev_info(struct rte_eth_dev *dev,
146                               struct rte_eth_dev_info *dev_info)
147 {
148         struct dpaa_if *dpaa_intf = dev->data->dev_private;
149
150         PMD_INIT_FUNC_TRACE();
151
152         dev_info->max_rx_queues = dpaa_intf->nb_rx_queues;
153         dev_info->max_tx_queues = dpaa_intf->nb_tx_queues;
154         dev_info->min_rx_bufsize = DPAA_MIN_RX_BUF_SIZE;
155         dev_info->max_rx_pktlen = DPAA_MAX_RX_PKT_LEN;
156         dev_info->max_mac_addrs = DPAA_MAX_MAC_FILTER;
157         dev_info->max_hash_mac_addrs = 0;
158         dev_info->max_vfs = 0;
159         dev_info->max_vmdq_pools = ETH_16_POOLS;
160         dev_info->speed_capa = (ETH_LINK_SPEED_1G |
161                                 ETH_LINK_SPEED_10G);
162 }
163
164 static int dpaa_eth_link_update(struct rte_eth_dev *dev,
165                                 int wait_to_complete __rte_unused)
166 {
167         struct dpaa_if *dpaa_intf = dev->data->dev_private;
168         struct rte_eth_link *link = &dev->data->dev_link;
169
170         PMD_INIT_FUNC_TRACE();
171
172         if (dpaa_intf->fif->mac_type == fman_mac_1g)
173                 link->link_speed = 1000;
174         else if (dpaa_intf->fif->mac_type == fman_mac_10g)
175                 link->link_speed = 10000;
176         else
177                 DPAA_PMD_ERR("invalid link_speed: %s, %d",
178                              dpaa_intf->name, dpaa_intf->fif->mac_type);
179
180         link->link_status = dpaa_intf->valid;
181         link->link_duplex = ETH_LINK_FULL_DUPLEX;
182         link->link_autoneg = ETH_LINK_AUTONEG;
183         return 0;
184 }
185
186
187 static void dpaa_eth_promiscuous_enable(struct rte_eth_dev *dev)
188 {
189         struct dpaa_if *dpaa_intf = dev->data->dev_private;
190
191         PMD_INIT_FUNC_TRACE();
192
193         fman_if_promiscuous_enable(dpaa_intf->fif);
194 }
195
196 static void dpaa_eth_promiscuous_disable(struct rte_eth_dev *dev)
197 {
198         struct dpaa_if *dpaa_intf = dev->data->dev_private;
199
200         PMD_INIT_FUNC_TRACE();
201
202         fman_if_promiscuous_disable(dpaa_intf->fif);
203 }
204
205 static void dpaa_eth_multicast_enable(struct rte_eth_dev *dev)
206 {
207         struct dpaa_if *dpaa_intf = dev->data->dev_private;
208
209         PMD_INIT_FUNC_TRACE();
210
211         fman_if_set_mcast_filter_table(dpaa_intf->fif);
212 }
213
214 static void dpaa_eth_multicast_disable(struct rte_eth_dev *dev)
215 {
216         struct dpaa_if *dpaa_intf = dev->data->dev_private;
217
218         PMD_INIT_FUNC_TRACE();
219
220         fman_if_reset_mcast_filter_table(dpaa_intf->fif);
221 }
222
223 static
224 int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
225                             uint16_t nb_desc __rte_unused,
226                             unsigned int socket_id __rte_unused,
227                             const struct rte_eth_rxconf *rx_conf __rte_unused,
228                             struct rte_mempool *mp)
229 {
230         struct dpaa_if *dpaa_intf = dev->data->dev_private;
231
232         PMD_INIT_FUNC_TRACE();
233
234         DPAA_PMD_INFO("Rx queue setup for queue index: %d", queue_idx);
235
236         if (!dpaa_intf->bp_info || dpaa_intf->bp_info->mp != mp) {
237                 struct fman_if_ic_params icp;
238                 uint32_t fd_offset;
239                 uint32_t bp_size;
240
241                 if (!mp->pool_data) {
242                         DPAA_PMD_ERR("Not an offloaded buffer pool!");
243                         return -1;
244                 }
245                 dpaa_intf->bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
246
247                 memset(&icp, 0, sizeof(icp));
248                 /* set ICEOF for to the default value , which is 0*/
249                 icp.iciof = DEFAULT_ICIOF;
250                 icp.iceof = DEFAULT_RX_ICEOF;
251                 icp.icsz = DEFAULT_ICSZ;
252                 fman_if_set_ic_params(dpaa_intf->fif, &icp);
253
254                 fd_offset = RTE_PKTMBUF_HEADROOM + DPAA_HW_BUF_RESERVE;
255                 fman_if_set_fdoff(dpaa_intf->fif, fd_offset);
256
257                 /* Buffer pool size should be equal to Dataroom Size*/
258                 bp_size = rte_pktmbuf_data_room_size(mp);
259                 fman_if_set_bp(dpaa_intf->fif, mp->size,
260                                dpaa_intf->bp_info->bpid, bp_size);
261                 dpaa_intf->valid = 1;
262                 DPAA_PMD_INFO("if =%s - fd_offset = %d offset = %d",
263                             dpaa_intf->name, fd_offset,
264                         fman_if_get_fdoff(dpaa_intf->fif));
265         }
266         dev->data->rx_queues[queue_idx] = &dpaa_intf->rx_queues[queue_idx];
267
268         return 0;
269 }
270
271 static
272 void dpaa_eth_rx_queue_release(void *rxq __rte_unused)
273 {
274         PMD_INIT_FUNC_TRACE();
275 }
276
277 static
278 int dpaa_eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
279                             uint16_t nb_desc __rte_unused,
280                 unsigned int socket_id __rte_unused,
281                 const struct rte_eth_txconf *tx_conf __rte_unused)
282 {
283         struct dpaa_if *dpaa_intf = dev->data->dev_private;
284
285         PMD_INIT_FUNC_TRACE();
286
287         DPAA_PMD_INFO("Tx queue setup for queue index: %d", queue_idx);
288         dev->data->tx_queues[queue_idx] = &dpaa_intf->tx_queues[queue_idx];
289         return 0;
290 }
291
292 static void dpaa_eth_tx_queue_release(void *txq __rte_unused)
293 {
294         PMD_INIT_FUNC_TRACE();
295 }
296
297 static int dpaa_link_down(struct rte_eth_dev *dev)
298 {
299         PMD_INIT_FUNC_TRACE();
300
301         dpaa_eth_dev_stop(dev);
302         return 0;
303 }
304
305 static int dpaa_link_up(struct rte_eth_dev *dev)
306 {
307         PMD_INIT_FUNC_TRACE();
308
309         dpaa_eth_dev_start(dev);
310         return 0;
311 }
312
313 static struct eth_dev_ops dpaa_devops = {
314         .dev_configure            = dpaa_eth_dev_configure,
315         .dev_start                = dpaa_eth_dev_start,
316         .dev_stop                 = dpaa_eth_dev_stop,
317         .dev_close                = dpaa_eth_dev_close,
318         .dev_infos_get            = dpaa_eth_dev_info,
319
320         .rx_queue_setup           = dpaa_eth_rx_queue_setup,
321         .tx_queue_setup           = dpaa_eth_tx_queue_setup,
322         .rx_queue_release         = dpaa_eth_rx_queue_release,
323         .tx_queue_release         = dpaa_eth_tx_queue_release,
324
325         .link_update              = dpaa_eth_link_update,
326         .promiscuous_enable       = dpaa_eth_promiscuous_enable,
327         .promiscuous_disable      = dpaa_eth_promiscuous_disable,
328         .allmulticast_enable      = dpaa_eth_multicast_enable,
329         .allmulticast_disable     = dpaa_eth_multicast_disable,
330         .mtu_set                  = dpaa_mtu_set,
331         .dev_set_link_down        = dpaa_link_down,
332         .dev_set_link_up          = dpaa_link_up,
333 };
334
335 /* Initialise an Rx FQ */
336 static int dpaa_rx_queue_init(struct qman_fq *fq,
337                               uint32_t fqid)
338 {
339         struct qm_mcc_initfq opts;
340         int ret;
341
342         PMD_INIT_FUNC_TRACE();
343
344         ret = qman_reserve_fqid(fqid);
345         if (ret) {
346                 DPAA_PMD_ERR("reserve rx fqid %d failed with ret: %d",
347                              fqid, ret);
348                 return -EINVAL;
349         }
350
351         DPAA_PMD_DEBUG("creating rx fq %p, fqid %d", fq, fqid);
352         ret = qman_create_fq(fqid, QMAN_FQ_FLAG_NO_ENQUEUE, fq);
353         if (ret) {
354                 DPAA_PMD_ERR("create rx fqid %d failed with ret: %d",
355                         fqid, ret);
356                 return ret;
357         }
358
359         opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
360                        QM_INITFQ_WE_CONTEXTA;
361
362         opts.fqd.dest.wq = DPAA_IF_RX_PRIORITY;
363         opts.fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK | QM_FQCTRL_CTXASTASHING |
364                            QM_FQCTRL_PREFERINCACHE;
365         opts.fqd.context_a.stashing.exclusive = 0;
366         opts.fqd.context_a.stashing.annotation_cl = DPAA_IF_RX_ANNOTATION_STASH;
367         opts.fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
368         opts.fqd.context_a.stashing.context_cl = DPAA_IF_RX_CONTEXT_STASH;
369
370         /*Enable tail drop */
371         opts.we_mask = opts.we_mask | QM_INITFQ_WE_TDTHRESH;
372         opts.fqd.fq_ctrl = opts.fqd.fq_ctrl | QM_FQCTRL_TDE;
373         qm_fqd_taildrop_set(&opts.fqd.td, CONG_THRESHOLD_RX_Q, 1);
374
375         ret = qman_init_fq(fq, 0, &opts);
376         if (ret)
377                 DPAA_PMD_ERR("init rx fqid %d failed with ret: %d", fqid, ret);
378         return ret;
379 }
380
381 /* Initialise a Tx FQ */
382 static int dpaa_tx_queue_init(struct qman_fq *fq,
383                               struct fman_if *fman_intf)
384 {
385         struct qm_mcc_initfq opts;
386         int ret;
387
388         PMD_INIT_FUNC_TRACE();
389
390         ret = qman_create_fq(0, QMAN_FQ_FLAG_DYNAMIC_FQID |
391                              QMAN_FQ_FLAG_TO_DCPORTAL, fq);
392         if (ret) {
393                 DPAA_PMD_ERR("create tx fq failed with ret: %d", ret);
394                 return ret;
395         }
396         opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
397                        QM_INITFQ_WE_CONTEXTB | QM_INITFQ_WE_CONTEXTA;
398         opts.fqd.dest.channel = fman_intf->tx_channel_id;
399         opts.fqd.dest.wq = DPAA_IF_TX_PRIORITY;
400         opts.fqd.fq_ctrl = QM_FQCTRL_PREFERINCACHE;
401         opts.fqd.context_b = 0;
402         /* no tx-confirmation */
403         opts.fqd.context_a.hi = 0x80000000 | fman_dealloc_bufs_mask_hi;
404         opts.fqd.context_a.lo = 0 | fman_dealloc_bufs_mask_lo;
405         DPAA_PMD_DEBUG("init tx fq %p, fqid %d", fq, fq->fqid);
406         ret = qman_init_fq(fq, QMAN_INITFQ_FLAG_SCHED, &opts);
407         if (ret)
408                 DPAA_PMD_ERR("init tx fqid %d failed %d", fq->fqid, ret);
409         return ret;
410 }
411
412 /* Initialise a network interface */
413 static int
414 dpaa_dev_init(struct rte_eth_dev *eth_dev)
415 {
416         int num_cores, num_rx_fqs, fqid;
417         int loop, ret = 0;
418         int dev_id;
419         struct rte_dpaa_device *dpaa_device;
420         struct dpaa_if *dpaa_intf;
421         struct fm_eth_port_cfg *cfg;
422         struct fman_if *fman_intf;
423         struct fman_if_bpool *bp, *tmp_bp;
424
425         PMD_INIT_FUNC_TRACE();
426
427         /* For secondary processes, the primary has done all the work */
428         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
429                 return 0;
430
431         dpaa_device = DEV_TO_DPAA_DEVICE(eth_dev->device);
432         dev_id = dpaa_device->id.dev_id;
433         dpaa_intf = eth_dev->data->dev_private;
434         cfg = &dpaa_netcfg->port_cfg[dev_id];
435         fman_intf = cfg->fman_if;
436
437         dpaa_intf->name = dpaa_device->name;
438
439         /* save fman_if & cfg in the interface struture */
440         dpaa_intf->fif = fman_intf;
441         dpaa_intf->ifid = dev_id;
442         dpaa_intf->cfg = cfg;
443
444         /* Initialize Rx FQ's */
445         if (getenv("DPAA_NUM_RX_QUEUES"))
446                 num_rx_fqs = atoi(getenv("DPAA_NUM_RX_QUEUES"));
447         else
448                 num_rx_fqs = DPAA_DEFAULT_NUM_PCD_QUEUES;
449
450         /* Each device can not have more than DPAA_PCD_FQID_MULTIPLIER RX
451          * queues.
452          */
453         if (num_rx_fqs <= 0 || num_rx_fqs > DPAA_PCD_FQID_MULTIPLIER) {
454                 DPAA_PMD_ERR("Invalid number of RX queues\n");
455                 return -EINVAL;
456         }
457
458         dpaa_intf->rx_queues = rte_zmalloc(NULL,
459                 sizeof(struct qman_fq) * num_rx_fqs, MAX_CACHELINE);
460         for (loop = 0; loop < num_rx_fqs; loop++) {
461                 fqid = DPAA_PCD_FQID_START + dpaa_intf->ifid *
462                         DPAA_PCD_FQID_MULTIPLIER + loop;
463                 ret = dpaa_rx_queue_init(&dpaa_intf->rx_queues[loop], fqid);
464                 if (ret)
465                         return ret;
466                 dpaa_intf->rx_queues[loop].dpaa_intf = dpaa_intf;
467         }
468         dpaa_intf->nb_rx_queues = num_rx_fqs;
469
470         /* Initialise Tx FQs. Have as many Tx FQ's as number of cores */
471         num_cores = rte_lcore_count();
472         dpaa_intf->tx_queues = rte_zmalloc(NULL, sizeof(struct qman_fq) *
473                 num_cores, MAX_CACHELINE);
474         if (!dpaa_intf->tx_queues)
475                 return -ENOMEM;
476
477         for (loop = 0; loop < num_cores; loop++) {
478                 ret = dpaa_tx_queue_init(&dpaa_intf->tx_queues[loop],
479                                          fman_intf);
480                 if (ret)
481                         return ret;
482                 dpaa_intf->tx_queues[loop].dpaa_intf = dpaa_intf;
483         }
484         dpaa_intf->nb_tx_queues = num_cores;
485
486         DPAA_PMD_DEBUG("All frame queues created");
487
488         /* reset bpool list, initialize bpool dynamically */
489         list_for_each_entry_safe(bp, tmp_bp, &cfg->fman_if->bpool_list, node) {
490                 list_del(&bp->node);
491                 rte_free(bp);
492         }
493
494         /* Populate ethdev structure */
495         eth_dev->dev_ops = &dpaa_devops;
496         eth_dev->rx_pkt_burst = dpaa_eth_queue_rx;
497         eth_dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
498
499         /* Allocate memory for storing MAC addresses */
500         eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
501                 ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER, 0);
502         if (eth_dev->data->mac_addrs == NULL) {
503                 DPAA_PMD_ERR("Failed to allocate %d bytes needed to "
504                                                 "store MAC addresses",
505                                 ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER);
506                 rte_free(dpaa_intf->rx_queues);
507                 rte_free(dpaa_intf->tx_queues);
508                 dpaa_intf->rx_queues = NULL;
509                 dpaa_intf->tx_queues = NULL;
510                 dpaa_intf->nb_rx_queues = 0;
511                 dpaa_intf->nb_tx_queues = 0;
512                 return -ENOMEM;
513         }
514
515         /* copy the primary mac address */
516         ether_addr_copy(&fman_intf->mac_addr, &eth_dev->data->mac_addrs[0]);
517
518         RTE_LOG(INFO, PMD, "net: dpaa: %s: %02x:%02x:%02x:%02x:%02x:%02x\n",
519                 dpaa_device->name,
520                 fman_intf->mac_addr.addr_bytes[0],
521                 fman_intf->mac_addr.addr_bytes[1],
522                 fman_intf->mac_addr.addr_bytes[2],
523                 fman_intf->mac_addr.addr_bytes[3],
524                 fman_intf->mac_addr.addr_bytes[4],
525                 fman_intf->mac_addr.addr_bytes[5]);
526
527         /* Disable RX mode */
528         fman_if_discard_rx_errors(fman_intf);
529         fman_if_disable_rx(fman_intf);
530         /* Disable promiscuous mode */
531         fman_if_promiscuous_disable(fman_intf);
532         /* Disable multicast */
533         fman_if_reset_mcast_filter_table(fman_intf);
534         /* Reset interface statistics */
535         fman_if_stats_reset(fman_intf);
536
537         return 0;
538 }
539
540 static int
541 dpaa_dev_uninit(struct rte_eth_dev *dev)
542 {
543         struct dpaa_if *dpaa_intf = dev->data->dev_private;
544
545         PMD_INIT_FUNC_TRACE();
546
547         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
548                 return -EPERM;
549
550         if (!dpaa_intf) {
551                 DPAA_PMD_WARN("Already closed or not started");
552                 return -1;
553         }
554
555         dpaa_eth_dev_close(dev);
556
557         /* release configuration memory */
558         if (dpaa_intf->fc_conf)
559                 rte_free(dpaa_intf->fc_conf);
560
561         rte_free(dpaa_intf->rx_queues);
562         dpaa_intf->rx_queues = NULL;
563
564         rte_free(dpaa_intf->tx_queues);
565         dpaa_intf->tx_queues = NULL;
566
567         /* free memory for storing MAC addresses */
568         rte_free(dev->data->mac_addrs);
569         dev->data->mac_addrs = NULL;
570
571         dev->dev_ops = NULL;
572         dev->rx_pkt_burst = NULL;
573         dev->tx_pkt_burst = NULL;
574
575         return 0;
576 }
577
578 static int
579 rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv,
580                struct rte_dpaa_device *dpaa_dev)
581 {
582         int diag;
583         int ret;
584         struct rte_eth_dev *eth_dev;
585
586         PMD_INIT_FUNC_TRACE();
587
588         /* In case of secondary process, the device is already configured
589          * and no further action is required, except portal initialization
590          * and verifying secondary attachment to port name.
591          */
592         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
593                 eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
594                 if (!eth_dev)
595                         return -ENOMEM;
596                 return 0;
597         }
598
599         if (!is_global_init) {
600                 /* One time load of Qman/Bman drivers */
601                 ret = qman_global_init();
602                 if (ret) {
603                         DPAA_PMD_ERR("QMAN initialization failed: %d",
604                                      ret);
605                         return ret;
606                 }
607                 ret = bman_global_init();
608                 if (ret) {
609                         DPAA_PMD_ERR("BMAN initialization failed: %d",
610                                      ret);
611                         return ret;
612                 }
613
614                 is_global_init = 1;
615         }
616
617         ret = rte_dpaa_portal_init((void *)1);
618         if (ret) {
619                 DPAA_PMD_ERR("Unable to initialize portal");
620                 return ret;
621         }
622
623         eth_dev = rte_eth_dev_allocate(dpaa_dev->name);
624         if (eth_dev == NULL)
625                 return -ENOMEM;
626
627         eth_dev->data->dev_private = rte_zmalloc(
628                                         "ethdev private structure",
629                                         sizeof(struct dpaa_if),
630                                         RTE_CACHE_LINE_SIZE);
631         if (!eth_dev->data->dev_private) {
632                 DPAA_PMD_ERR("Cannot allocate memzone for port data");
633                 rte_eth_dev_release_port(eth_dev);
634                 return -ENOMEM;
635         }
636
637         eth_dev->device = &dpaa_dev->device;
638         eth_dev->device->driver = &dpaa_drv->driver;
639         dpaa_dev->eth_dev = eth_dev;
640
641         /* Invoke PMD device initialization function */
642         diag = dpaa_dev_init(eth_dev);
643         if (diag == 0)
644                 return 0;
645
646         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
647                 rte_free(eth_dev->data->dev_private);
648
649         rte_eth_dev_release_port(eth_dev);
650         return diag;
651 }
652
653 static int
654 rte_dpaa_remove(struct rte_dpaa_device *dpaa_dev)
655 {
656         struct rte_eth_dev *eth_dev;
657
658         PMD_INIT_FUNC_TRACE();
659
660         eth_dev = dpaa_dev->eth_dev;
661         dpaa_dev_uninit(eth_dev);
662
663         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
664                 rte_free(eth_dev->data->dev_private);
665
666         rte_eth_dev_release_port(eth_dev);
667
668         return 0;
669 }
670
671 static struct rte_dpaa_driver rte_dpaa_pmd = {
672         .drv_type = FSL_DPAA_ETH,
673         .probe = rte_dpaa_probe,
674         .remove = rte_dpaa_remove,
675 };
676
677 RTE_PMD_REGISTER_DPAA(net_dpaa, rte_dpaa_pmd);