4 * Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
41 #include <sys/types.h>
42 #include <sys/syscall.h>
44 #include <rte_config.h>
45 #include <rte_byteorder.h>
46 #include <rte_common.h>
47 #include <rte_interrupts.h>
49 #include <rte_debug.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>
57 #include <rte_alarm.h>
58 #include <rte_ether.h>
59 #include <rte_ethdev.h>
60 #include <rte_malloc.h>
63 #include <rte_dpaa_bus.h>
64 #include <rte_dpaa_logs.h>
65 #include <dpaa_mempool.h>
67 #include <dpaa_ethdev.h>
68 #include <dpaa_rxtx.h>
75 /* Keep track of whether QMAN and BMAN have been globally initialized */
76 static int is_global_init;
79 dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
81 struct dpaa_if *dpaa_intf = dev->data->dev_private;
83 PMD_INIT_FUNC_TRACE();
85 if (mtu < ETHER_MIN_MTU)
87 if (mtu > ETHER_MAX_LEN)
88 dev->data->dev_conf.rxmode.jumbo_frame = 1;
90 dev->data->dev_conf.rxmode.jumbo_frame = 0;
92 dev->data->dev_conf.rxmode.max_rx_pkt_len = mtu;
94 fman_if_set_maxfrm(dpaa_intf->fif, mtu);
100 dpaa_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
102 PMD_INIT_FUNC_TRACE();
104 if (dev->data->dev_conf.rxmode.jumbo_frame == 1) {
105 if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
107 return dpaa_mtu_set(dev,
108 dev->data->dev_conf.rxmode.max_rx_pkt_len);
115 static int dpaa_eth_dev_start(struct rte_eth_dev *dev)
117 struct dpaa_if *dpaa_intf = dev->data->dev_private;
119 PMD_INIT_FUNC_TRACE();
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);
128 static void dpaa_eth_dev_stop(struct rte_eth_dev *dev)
130 struct dpaa_if *dpaa_intf = dev->data->dev_private;
132 PMD_INIT_FUNC_TRACE();
134 fman_if_disable_rx(dpaa_intf->fif);
135 dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
138 static void dpaa_eth_dev_close(struct rte_eth_dev *dev)
140 PMD_INIT_FUNC_TRACE();
142 dpaa_eth_dev_stop(dev);
145 static void dpaa_eth_dev_info(struct rte_eth_dev *dev,
146 struct rte_eth_dev_info *dev_info)
148 struct dpaa_if *dpaa_intf = dev->data->dev_private;
150 PMD_INIT_FUNC_TRACE();
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 |
164 static int dpaa_eth_link_update(struct rte_eth_dev *dev,
165 int wait_to_complete __rte_unused)
167 struct dpaa_if *dpaa_intf = dev->data->dev_private;
168 struct rte_eth_link *link = &dev->data->dev_link;
170 PMD_INIT_FUNC_TRACE();
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;
177 DPAA_PMD_ERR("invalid link_speed: %s, %d",
178 dpaa_intf->name, dpaa_intf->fif->mac_type);
180 link->link_status = dpaa_intf->valid;
181 link->link_duplex = ETH_LINK_FULL_DUPLEX;
182 link->link_autoneg = ETH_LINK_AUTONEG;
187 static void dpaa_eth_promiscuous_enable(struct rte_eth_dev *dev)
189 struct dpaa_if *dpaa_intf = dev->data->dev_private;
191 PMD_INIT_FUNC_TRACE();
193 fman_if_promiscuous_enable(dpaa_intf->fif);
196 static void dpaa_eth_promiscuous_disable(struct rte_eth_dev *dev)
198 struct dpaa_if *dpaa_intf = dev->data->dev_private;
200 PMD_INIT_FUNC_TRACE();
202 fman_if_promiscuous_disable(dpaa_intf->fif);
206 int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
207 uint16_t nb_desc __rte_unused,
208 unsigned int socket_id __rte_unused,
209 const struct rte_eth_rxconf *rx_conf __rte_unused,
210 struct rte_mempool *mp)
212 struct dpaa_if *dpaa_intf = dev->data->dev_private;
214 PMD_INIT_FUNC_TRACE();
216 DPAA_PMD_INFO("Rx queue setup for queue index: %d", queue_idx);
218 if (!dpaa_intf->bp_info || dpaa_intf->bp_info->mp != mp) {
219 struct fman_if_ic_params icp;
223 if (!mp->pool_data) {
224 DPAA_PMD_ERR("Not an offloaded buffer pool!");
227 dpaa_intf->bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
229 memset(&icp, 0, sizeof(icp));
230 /* set ICEOF for to the default value , which is 0*/
231 icp.iciof = DEFAULT_ICIOF;
232 icp.iceof = DEFAULT_RX_ICEOF;
233 icp.icsz = DEFAULT_ICSZ;
234 fman_if_set_ic_params(dpaa_intf->fif, &icp);
236 fd_offset = RTE_PKTMBUF_HEADROOM + DPAA_HW_BUF_RESERVE;
237 fman_if_set_fdoff(dpaa_intf->fif, fd_offset);
239 /* Buffer pool size should be equal to Dataroom Size*/
240 bp_size = rte_pktmbuf_data_room_size(mp);
241 fman_if_set_bp(dpaa_intf->fif, mp->size,
242 dpaa_intf->bp_info->bpid, bp_size);
243 dpaa_intf->valid = 1;
244 DPAA_PMD_INFO("if =%s - fd_offset = %d offset = %d",
245 dpaa_intf->name, fd_offset,
246 fman_if_get_fdoff(dpaa_intf->fif));
248 dev->data->rx_queues[queue_idx] = &dpaa_intf->rx_queues[queue_idx];
254 void dpaa_eth_rx_queue_release(void *rxq __rte_unused)
256 PMD_INIT_FUNC_TRACE();
260 int dpaa_eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
261 uint16_t nb_desc __rte_unused,
262 unsigned int socket_id __rte_unused,
263 const struct rte_eth_txconf *tx_conf __rte_unused)
265 struct dpaa_if *dpaa_intf = dev->data->dev_private;
267 PMD_INIT_FUNC_TRACE();
269 DPAA_PMD_INFO("Tx queue setup for queue index: %d", queue_idx);
270 dev->data->tx_queues[queue_idx] = &dpaa_intf->tx_queues[queue_idx];
274 static void dpaa_eth_tx_queue_release(void *txq __rte_unused)
276 PMD_INIT_FUNC_TRACE();
279 static int dpaa_link_down(struct rte_eth_dev *dev)
281 PMD_INIT_FUNC_TRACE();
283 dpaa_eth_dev_stop(dev);
287 static int dpaa_link_up(struct rte_eth_dev *dev)
289 PMD_INIT_FUNC_TRACE();
291 dpaa_eth_dev_start(dev);
295 static struct eth_dev_ops dpaa_devops = {
296 .dev_configure = dpaa_eth_dev_configure,
297 .dev_start = dpaa_eth_dev_start,
298 .dev_stop = dpaa_eth_dev_stop,
299 .dev_close = dpaa_eth_dev_close,
300 .dev_infos_get = dpaa_eth_dev_info,
302 .rx_queue_setup = dpaa_eth_rx_queue_setup,
303 .tx_queue_setup = dpaa_eth_tx_queue_setup,
304 .rx_queue_release = dpaa_eth_rx_queue_release,
305 .tx_queue_release = dpaa_eth_tx_queue_release,
307 .link_update = dpaa_eth_link_update,
308 .promiscuous_enable = dpaa_eth_promiscuous_enable,
309 .promiscuous_disable = dpaa_eth_promiscuous_disable,
310 .mtu_set = dpaa_mtu_set,
311 .dev_set_link_down = dpaa_link_down,
312 .dev_set_link_up = dpaa_link_up,
315 /* Initialise an Rx FQ */
316 static int dpaa_rx_queue_init(struct qman_fq *fq,
319 struct qm_mcc_initfq opts;
322 PMD_INIT_FUNC_TRACE();
324 ret = qman_reserve_fqid(fqid);
326 DPAA_PMD_ERR("reserve rx fqid %d failed with ret: %d",
331 DPAA_PMD_DEBUG("creating rx fq %p, fqid %d", fq, fqid);
332 ret = qman_create_fq(fqid, QMAN_FQ_FLAG_NO_ENQUEUE, fq);
334 DPAA_PMD_ERR("create rx fqid %d failed with ret: %d",
339 opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
340 QM_INITFQ_WE_CONTEXTA;
342 opts.fqd.dest.wq = DPAA_IF_RX_PRIORITY;
343 opts.fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK | QM_FQCTRL_CTXASTASHING |
344 QM_FQCTRL_PREFERINCACHE;
345 opts.fqd.context_a.stashing.exclusive = 0;
346 opts.fqd.context_a.stashing.annotation_cl = DPAA_IF_RX_ANNOTATION_STASH;
347 opts.fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
348 opts.fqd.context_a.stashing.context_cl = DPAA_IF_RX_CONTEXT_STASH;
350 /*Enable tail drop */
351 opts.we_mask = opts.we_mask | QM_INITFQ_WE_TDTHRESH;
352 opts.fqd.fq_ctrl = opts.fqd.fq_ctrl | QM_FQCTRL_TDE;
353 qm_fqd_taildrop_set(&opts.fqd.td, CONG_THRESHOLD_RX_Q, 1);
355 ret = qman_init_fq(fq, 0, &opts);
357 DPAA_PMD_ERR("init rx fqid %d failed with ret: %d", fqid, ret);
361 /* Initialise a Tx FQ */
362 static int dpaa_tx_queue_init(struct qman_fq *fq,
363 struct fman_if *fman_intf)
365 struct qm_mcc_initfq opts;
368 PMD_INIT_FUNC_TRACE();
370 ret = qman_create_fq(0, QMAN_FQ_FLAG_DYNAMIC_FQID |
371 QMAN_FQ_FLAG_TO_DCPORTAL, fq);
373 DPAA_PMD_ERR("create tx fq failed with ret: %d", ret);
376 opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
377 QM_INITFQ_WE_CONTEXTB | QM_INITFQ_WE_CONTEXTA;
378 opts.fqd.dest.channel = fman_intf->tx_channel_id;
379 opts.fqd.dest.wq = DPAA_IF_TX_PRIORITY;
380 opts.fqd.fq_ctrl = QM_FQCTRL_PREFERINCACHE;
381 opts.fqd.context_b = 0;
382 /* no tx-confirmation */
383 opts.fqd.context_a.hi = 0x80000000 | fman_dealloc_bufs_mask_hi;
384 opts.fqd.context_a.lo = 0 | fman_dealloc_bufs_mask_lo;
385 DPAA_PMD_DEBUG("init tx fq %p, fqid %d", fq, fq->fqid);
386 ret = qman_init_fq(fq, QMAN_INITFQ_FLAG_SCHED, &opts);
388 DPAA_PMD_ERR("init tx fqid %d failed %d", fq->fqid, ret);
392 /* Initialise a network interface */
394 dpaa_dev_init(struct rte_eth_dev *eth_dev)
396 int num_cores, num_rx_fqs, fqid;
399 struct rte_dpaa_device *dpaa_device;
400 struct dpaa_if *dpaa_intf;
401 struct fm_eth_port_cfg *cfg;
402 struct fman_if *fman_intf;
403 struct fman_if_bpool *bp, *tmp_bp;
405 PMD_INIT_FUNC_TRACE();
407 /* For secondary processes, the primary has done all the work */
408 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
411 dpaa_device = DEV_TO_DPAA_DEVICE(eth_dev->device);
412 dev_id = dpaa_device->id.dev_id;
413 dpaa_intf = eth_dev->data->dev_private;
414 cfg = &dpaa_netcfg->port_cfg[dev_id];
415 fman_intf = cfg->fman_if;
417 dpaa_intf->name = dpaa_device->name;
419 /* save fman_if & cfg in the interface struture */
420 dpaa_intf->fif = fman_intf;
421 dpaa_intf->ifid = dev_id;
422 dpaa_intf->cfg = cfg;
424 /* Initialize Rx FQ's */
425 if (getenv("DPAA_NUM_RX_QUEUES"))
426 num_rx_fqs = atoi(getenv("DPAA_NUM_RX_QUEUES"));
428 num_rx_fqs = DPAA_DEFAULT_NUM_PCD_QUEUES;
430 /* Each device can not have more than DPAA_PCD_FQID_MULTIPLIER RX
433 if (num_rx_fqs <= 0 || num_rx_fqs > DPAA_PCD_FQID_MULTIPLIER) {
434 DPAA_PMD_ERR("Invalid number of RX queues\n");
438 dpaa_intf->rx_queues = rte_zmalloc(NULL,
439 sizeof(struct qman_fq) * num_rx_fqs, MAX_CACHELINE);
440 for (loop = 0; loop < num_rx_fqs; loop++) {
441 fqid = DPAA_PCD_FQID_START + dpaa_intf->ifid *
442 DPAA_PCD_FQID_MULTIPLIER + loop;
443 ret = dpaa_rx_queue_init(&dpaa_intf->rx_queues[loop], fqid);
446 dpaa_intf->rx_queues[loop].dpaa_intf = dpaa_intf;
448 dpaa_intf->nb_rx_queues = num_rx_fqs;
450 /* Initialise Tx FQs. Have as many Tx FQ's as number of cores */
451 num_cores = rte_lcore_count();
452 dpaa_intf->tx_queues = rte_zmalloc(NULL, sizeof(struct qman_fq) *
453 num_cores, MAX_CACHELINE);
454 if (!dpaa_intf->tx_queues)
457 for (loop = 0; loop < num_cores; loop++) {
458 ret = dpaa_tx_queue_init(&dpaa_intf->tx_queues[loop],
462 dpaa_intf->tx_queues[loop].dpaa_intf = dpaa_intf;
464 dpaa_intf->nb_tx_queues = num_cores;
466 DPAA_PMD_DEBUG("All frame queues created");
468 /* reset bpool list, initialize bpool dynamically */
469 list_for_each_entry_safe(bp, tmp_bp, &cfg->fman_if->bpool_list, node) {
474 /* Populate ethdev structure */
475 eth_dev->dev_ops = &dpaa_devops;
476 eth_dev->rx_pkt_burst = dpaa_eth_queue_rx;
477 eth_dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
479 /* Allocate memory for storing MAC addresses */
480 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
481 ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER, 0);
482 if (eth_dev->data->mac_addrs == NULL) {
483 DPAA_PMD_ERR("Failed to allocate %d bytes needed to "
484 "store MAC addresses",
485 ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER);
486 rte_free(dpaa_intf->rx_queues);
487 rte_free(dpaa_intf->tx_queues);
488 dpaa_intf->rx_queues = NULL;
489 dpaa_intf->tx_queues = NULL;
490 dpaa_intf->nb_rx_queues = 0;
491 dpaa_intf->nb_tx_queues = 0;
495 /* copy the primary mac address */
496 ether_addr_copy(&fman_intf->mac_addr, ð_dev->data->mac_addrs[0]);
498 RTE_LOG(INFO, PMD, "net: dpaa: %s: %02x:%02x:%02x:%02x:%02x:%02x\n",
500 fman_intf->mac_addr.addr_bytes[0],
501 fman_intf->mac_addr.addr_bytes[1],
502 fman_intf->mac_addr.addr_bytes[2],
503 fman_intf->mac_addr.addr_bytes[3],
504 fman_intf->mac_addr.addr_bytes[4],
505 fman_intf->mac_addr.addr_bytes[5]);
507 /* Disable RX mode */
508 fman_if_discard_rx_errors(fman_intf);
509 fman_if_disable_rx(fman_intf);
510 /* Disable promiscuous mode */
511 fman_if_promiscuous_disable(fman_intf);
512 /* Disable multicast */
513 fman_if_reset_mcast_filter_table(fman_intf);
514 /* Reset interface statistics */
515 fman_if_stats_reset(fman_intf);
521 dpaa_dev_uninit(struct rte_eth_dev *dev)
523 struct dpaa_if *dpaa_intf = dev->data->dev_private;
525 PMD_INIT_FUNC_TRACE();
527 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
531 DPAA_PMD_WARN("Already closed or not started");
535 dpaa_eth_dev_close(dev);
537 /* release configuration memory */
538 if (dpaa_intf->fc_conf)
539 rte_free(dpaa_intf->fc_conf);
541 rte_free(dpaa_intf->rx_queues);
542 dpaa_intf->rx_queues = NULL;
544 rte_free(dpaa_intf->tx_queues);
545 dpaa_intf->tx_queues = NULL;
547 /* free memory for storing MAC addresses */
548 rte_free(dev->data->mac_addrs);
549 dev->data->mac_addrs = NULL;
552 dev->rx_pkt_burst = NULL;
553 dev->tx_pkt_burst = NULL;
559 rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv,
560 struct rte_dpaa_device *dpaa_dev)
564 struct rte_eth_dev *eth_dev;
566 PMD_INIT_FUNC_TRACE();
568 /* In case of secondary process, the device is already configured
569 * and no further action is required, except portal initialization
570 * and verifying secondary attachment to port name.
572 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
573 eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
579 if (!is_global_init) {
580 /* One time load of Qman/Bman drivers */
581 ret = qman_global_init();
583 DPAA_PMD_ERR("QMAN initialization failed: %d",
587 ret = bman_global_init();
589 DPAA_PMD_ERR("BMAN initialization failed: %d",
597 ret = rte_dpaa_portal_init((void *)1);
599 DPAA_PMD_ERR("Unable to initialize portal");
603 eth_dev = rte_eth_dev_allocate(dpaa_dev->name);
607 eth_dev->data->dev_private = rte_zmalloc(
608 "ethdev private structure",
609 sizeof(struct dpaa_if),
610 RTE_CACHE_LINE_SIZE);
611 if (!eth_dev->data->dev_private) {
612 DPAA_PMD_ERR("Cannot allocate memzone for port data");
613 rte_eth_dev_release_port(eth_dev);
617 eth_dev->device = &dpaa_dev->device;
618 eth_dev->device->driver = &dpaa_drv->driver;
619 dpaa_dev->eth_dev = eth_dev;
621 /* Invoke PMD device initialization function */
622 diag = dpaa_dev_init(eth_dev);
626 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
627 rte_free(eth_dev->data->dev_private);
629 rte_eth_dev_release_port(eth_dev);
634 rte_dpaa_remove(struct rte_dpaa_device *dpaa_dev)
636 struct rte_eth_dev *eth_dev;
638 PMD_INIT_FUNC_TRACE();
640 eth_dev = dpaa_dev->eth_dev;
641 dpaa_dev_uninit(eth_dev);
643 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
644 rte_free(eth_dev->data->dev_private);
646 rte_eth_dev_release_port(eth_dev);
651 static struct rte_dpaa_driver rte_dpaa_pmd = {
652 .drv_type = FSL_DPAA_ETH,
653 .probe = rte_dpaa_probe,
654 .remove = rte_dpaa_remove,
657 RTE_PMD_REGISTER_DPAA(net_dpaa, rte_dpaa_pmd);