1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2017-2020 NXP
15 #include <sys/types.h>
16 #include <sys/syscall.h>
18 #include <rte_string_fns.h>
19 #include <rte_byteorder.h>
20 #include <rte_common.h>
21 #include <rte_interrupts.h>
23 #include <rte_debug.h>
25 #include <rte_atomic.h>
26 #include <rte_branch_prediction.h>
27 #include <rte_memory.h>
28 #include <rte_tailq.h>
30 #include <rte_alarm.h>
31 #include <rte_ether.h>
32 #include <rte_ethdev_driver.h>
33 #include <rte_malloc.h>
36 #include <rte_dpaa_bus.h>
37 #include <rte_dpaa_logs.h>
38 #include <dpaa_mempool.h>
40 #include <dpaa_ethdev.h>
41 #include <dpaa_rxtx.h>
42 #include <rte_pmd_dpaa.h>
49 /* Supported Rx offloads */
50 static uint64_t dev_rx_offloads_sup =
51 DEV_RX_OFFLOAD_JUMBO_FRAME |
52 DEV_RX_OFFLOAD_SCATTER;
54 /* Rx offloads which cannot be disabled */
55 static uint64_t dev_rx_offloads_nodis =
56 DEV_RX_OFFLOAD_IPV4_CKSUM |
57 DEV_RX_OFFLOAD_UDP_CKSUM |
58 DEV_RX_OFFLOAD_TCP_CKSUM |
59 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
60 DEV_RX_OFFLOAD_RSS_HASH;
62 /* Supported Tx offloads */
63 static uint64_t dev_tx_offloads_sup =
64 DEV_TX_OFFLOAD_MT_LOCKFREE |
65 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
67 /* Tx offloads which cannot be disabled */
68 static uint64_t dev_tx_offloads_nodis =
69 DEV_TX_OFFLOAD_IPV4_CKSUM |
70 DEV_TX_OFFLOAD_UDP_CKSUM |
71 DEV_TX_OFFLOAD_TCP_CKSUM |
72 DEV_TX_OFFLOAD_SCTP_CKSUM |
73 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
74 DEV_TX_OFFLOAD_MULTI_SEGS;
76 /* Keep track of whether QMAN and BMAN have been globally initialized */
77 static int is_global_init;
78 static int default_q; /* use default queue - FMC is not executed*/
79 /* At present we only allow up to 4 push mode queues as default - as each of
80 * this queue need dedicated portal and we are short of portals.
82 #define DPAA_MAX_PUSH_MODE_QUEUE 8
83 #define DPAA_DEFAULT_PUSH_MODE_QUEUE 4
85 static int dpaa_push_mode_max_queue = DPAA_DEFAULT_PUSH_MODE_QUEUE;
86 static int dpaa_push_queue_idx; /* Queue index which are in push mode*/
89 /* Per RX FQ Taildrop in frame count */
90 static unsigned int td_threshold = CGR_RX_PERFQ_THRESH;
92 /* Per TX FQ Taildrop in frame count, disabled by default */
93 static unsigned int td_tx_threshold;
95 struct rte_dpaa_xstats_name_off {
96 char name[RTE_ETH_XSTATS_NAME_SIZE];
100 static const struct rte_dpaa_xstats_name_off dpaa_xstats_strings[] = {
102 offsetof(struct dpaa_if_stats, raln)},
104 offsetof(struct dpaa_if_stats, rxpf)},
106 offsetof(struct dpaa_if_stats, rfcs)},
108 offsetof(struct dpaa_if_stats, rvlan)},
110 offsetof(struct dpaa_if_stats, rerr)},
112 offsetof(struct dpaa_if_stats, rdrp)},
114 offsetof(struct dpaa_if_stats, rund)},
116 offsetof(struct dpaa_if_stats, rovr)},
118 offsetof(struct dpaa_if_stats, rfrg)},
120 offsetof(struct dpaa_if_stats, txpf)},
122 offsetof(struct dpaa_if_stats, terr)},
124 offsetof(struct dpaa_if_stats, tvlan)},
126 offsetof(struct dpaa_if_stats, tund)},
129 static struct rte_dpaa_driver rte_dpaa_pmd;
132 dpaa_eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info);
135 dpaa_poll_queue_default_config(struct qm_mcc_initfq *opts)
137 memset(opts, 0, sizeof(struct qm_mcc_initfq));
138 opts->we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
139 opts->fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK | QM_FQCTRL_CTXASTASHING |
140 QM_FQCTRL_PREFERINCACHE;
141 opts->fqd.context_a.stashing.exclusive = 0;
142 if (dpaa_svr_family != SVR_LS1046A_FAMILY)
143 opts->fqd.context_a.stashing.annotation_cl =
144 DPAA_IF_RX_ANNOTATION_STASH;
145 opts->fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
146 opts->fqd.context_a.stashing.context_cl = DPAA_IF_RX_CONTEXT_STASH;
150 dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
152 struct dpaa_if *dpaa_intf = dev->data->dev_private;
153 uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN
155 uint32_t buffsz = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
157 PMD_INIT_FUNC_TRACE();
159 if (mtu < RTE_ETHER_MIN_MTU || frame_size > DPAA_MAX_RX_PKT_LEN)
162 * Refuse mtu that requires the support of scattered packets
163 * when this feature has not been enabled before.
165 if (dev->data->min_rx_buf_size &&
166 !dev->data->scattered_rx && frame_size > buffsz) {
167 DPAA_PMD_ERR("SG not enabled, will not fit in one buffer");
171 /* check <seg size> * <max_seg> >= max_frame */
172 if (dev->data->min_rx_buf_size && dev->data->scattered_rx &&
173 (frame_size > buffsz * DPAA_SGT_MAX_ENTRIES)) {
174 DPAA_PMD_ERR("Too big to fit for Max SG list %d",
175 buffsz * DPAA_SGT_MAX_ENTRIES);
179 if (frame_size > RTE_ETHER_MAX_LEN)
180 dev->data->dev_conf.rxmode.offloads |=
181 DEV_RX_OFFLOAD_JUMBO_FRAME;
183 dev->data->dev_conf.rxmode.offloads &=
184 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
186 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
188 fman_if_set_maxfrm(dpaa_intf->fif, frame_size);
194 dpaa_eth_dev_configure(struct rte_eth_dev *dev)
196 struct dpaa_if *dpaa_intf = dev->data->dev_private;
197 struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
198 uint64_t rx_offloads = eth_conf->rxmode.offloads;
199 uint64_t tx_offloads = eth_conf->txmode.offloads;
201 PMD_INIT_FUNC_TRACE();
203 /* Rx offloads which are enabled by default */
204 if (dev_rx_offloads_nodis & ~rx_offloads) {
206 "Some of rx offloads enabled by default - requested 0x%" PRIx64
207 " fixed are 0x%" PRIx64,
208 rx_offloads, dev_rx_offloads_nodis);
211 /* Tx offloads which are enabled by default */
212 if (dev_tx_offloads_nodis & ~tx_offloads) {
214 "Some of tx offloads enabled by default - requested 0x%" PRIx64
215 " fixed are 0x%" PRIx64,
216 tx_offloads, dev_tx_offloads_nodis);
219 if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
222 DPAA_PMD_DEBUG("enabling jumbo");
224 if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
226 max_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
228 DPAA_PMD_INFO("enabling jumbo override conf max len=%d "
230 dev->data->dev_conf.rxmode.max_rx_pkt_len,
231 DPAA_MAX_RX_PKT_LEN);
232 max_len = DPAA_MAX_RX_PKT_LEN;
235 fman_if_set_maxfrm(dpaa_intf->fif, max_len);
236 dev->data->mtu = max_len
237 - RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN - VLAN_TAG_SIZE;
240 if (rx_offloads & DEV_RX_OFFLOAD_SCATTER) {
241 DPAA_PMD_DEBUG("enabling scatter mode");
242 fman_if_set_sg(dpaa_intf->fif, 1);
243 dev->data->scattered_rx = 1;
249 static const uint32_t *
250 dpaa_supported_ptypes_get(struct rte_eth_dev *dev)
252 static const uint32_t ptypes[] = {
254 RTE_PTYPE_L2_ETHER_VLAN,
255 RTE_PTYPE_L2_ETHER_ARP,
256 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
257 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
267 PMD_INIT_FUNC_TRACE();
269 if (dev->rx_pkt_burst == dpaa_eth_queue_rx)
274 static int dpaa_eth_dev_start(struct rte_eth_dev *dev)
276 struct dpaa_if *dpaa_intf = dev->data->dev_private;
278 PMD_INIT_FUNC_TRACE();
280 /* Change tx callback to the real one */
281 if (dpaa_intf->cgr_tx)
282 dev->tx_pkt_burst = dpaa_eth_queue_tx_slow;
284 dev->tx_pkt_burst = dpaa_eth_queue_tx;
286 fman_if_enable_rx(dpaa_intf->fif);
291 static void dpaa_eth_dev_stop(struct rte_eth_dev *dev)
293 struct dpaa_if *dpaa_intf = dev->data->dev_private;
295 PMD_INIT_FUNC_TRACE();
297 fman_if_disable_rx(dpaa_intf->fif);
298 dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
301 static void dpaa_eth_dev_close(struct rte_eth_dev *dev)
303 PMD_INIT_FUNC_TRACE();
305 dpaa_eth_dev_stop(dev);
309 dpaa_fw_version_get(struct rte_eth_dev *dev __rte_unused,
314 FILE *svr_file = NULL;
315 unsigned int svr_ver = 0;
317 PMD_INIT_FUNC_TRACE();
319 svr_file = fopen(DPAA_SOC_ID_FILE, "r");
321 DPAA_PMD_ERR("Unable to open SoC device");
322 return -ENOTSUP; /* Not supported on this infra */
324 if (fscanf(svr_file, "svr:%x", &svr_ver) > 0)
325 dpaa_svr_family = svr_ver & SVR_MASK;
327 DPAA_PMD_ERR("Unable to read SoC device");
331 ret = snprintf(fw_version, fw_size, "SVR:%x-fman-v%x",
332 svr_ver, fman_ip_rev);
333 ret += 1; /* add the size of '\0' */
335 if (fw_size < (uint32_t)ret)
341 static int dpaa_eth_dev_info(struct rte_eth_dev *dev,
342 struct rte_eth_dev_info *dev_info)
344 struct dpaa_if *dpaa_intf = dev->data->dev_private;
346 DPAA_PMD_DEBUG(": %s", dpaa_intf->name);
348 dev_info->max_rx_queues = dpaa_intf->nb_rx_queues;
349 dev_info->max_tx_queues = dpaa_intf->nb_tx_queues;
350 dev_info->max_rx_pktlen = DPAA_MAX_RX_PKT_LEN;
351 dev_info->max_mac_addrs = DPAA_MAX_MAC_FILTER;
352 dev_info->max_hash_mac_addrs = 0;
353 dev_info->max_vfs = 0;
354 dev_info->max_vmdq_pools = ETH_16_POOLS;
355 dev_info->flow_type_rss_offloads = DPAA_RSS_OFFLOAD_ALL;
357 if (dpaa_intf->fif->mac_type == fman_mac_1g) {
358 dev_info->speed_capa = ETH_LINK_SPEED_1G;
359 } else if (dpaa_intf->fif->mac_type == fman_mac_10g) {
360 dev_info->speed_capa = (ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G);
362 DPAA_PMD_ERR("invalid link_speed: %s, %d",
363 dpaa_intf->name, dpaa_intf->fif->mac_type);
367 dev_info->rx_offload_capa = dev_rx_offloads_sup |
368 dev_rx_offloads_nodis;
369 dev_info->tx_offload_capa = dev_tx_offloads_sup |
370 dev_tx_offloads_nodis;
371 dev_info->default_rxportconf.burst_size = DPAA_DEF_RX_BURST_SIZE;
372 dev_info->default_txportconf.burst_size = DPAA_DEF_TX_BURST_SIZE;
373 dev_info->default_rxportconf.nb_queues = 1;
374 dev_info->default_txportconf.nb_queues = 1;
375 dev_info->default_txportconf.ring_size = CGR_TX_CGR_THRESH;
376 dev_info->default_rxportconf.ring_size = CGR_RX_PERFQ_THRESH;
381 static int dpaa_eth_link_update(struct rte_eth_dev *dev,
382 int wait_to_complete __rte_unused)
384 struct dpaa_if *dpaa_intf = dev->data->dev_private;
385 struct rte_eth_link *link = &dev->data->dev_link;
387 PMD_INIT_FUNC_TRACE();
389 if (dpaa_intf->fif->mac_type == fman_mac_1g)
390 link->link_speed = ETH_SPEED_NUM_1G;
391 else if (dpaa_intf->fif->mac_type == fman_mac_10g)
392 link->link_speed = ETH_SPEED_NUM_10G;
394 DPAA_PMD_ERR("invalid link_speed: %s, %d",
395 dpaa_intf->name, dpaa_intf->fif->mac_type);
397 link->link_status = dpaa_intf->valid;
398 link->link_duplex = ETH_LINK_FULL_DUPLEX;
399 link->link_autoneg = ETH_LINK_AUTONEG;
403 static int dpaa_eth_stats_get(struct rte_eth_dev *dev,
404 struct rte_eth_stats *stats)
406 struct dpaa_if *dpaa_intf = dev->data->dev_private;
408 PMD_INIT_FUNC_TRACE();
410 fman_if_stats_get(dpaa_intf->fif, stats);
414 static int dpaa_eth_stats_reset(struct rte_eth_dev *dev)
416 struct dpaa_if *dpaa_intf = dev->data->dev_private;
418 PMD_INIT_FUNC_TRACE();
420 fman_if_stats_reset(dpaa_intf->fif);
426 dpaa_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
429 struct dpaa_if *dpaa_intf = dev->data->dev_private;
430 unsigned int i = 0, num = RTE_DIM(dpaa_xstats_strings);
431 uint64_t values[sizeof(struct dpaa_if_stats) / 8];
439 fman_if_stats_get_all(dpaa_intf->fif, values,
440 sizeof(struct dpaa_if_stats) / 8);
442 for (i = 0; i < num; i++) {
444 xstats[i].value = values[dpaa_xstats_strings[i].offset / 8];
450 dpaa_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
451 struct rte_eth_xstat_name *xstats_names,
454 unsigned int i, stat_cnt = RTE_DIM(dpaa_xstats_strings);
456 if (limit < stat_cnt)
459 if (xstats_names != NULL)
460 for (i = 0; i < stat_cnt; i++)
461 strlcpy(xstats_names[i].name,
462 dpaa_xstats_strings[i].name,
463 sizeof(xstats_names[i].name));
469 dpaa_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
470 uint64_t *values, unsigned int n)
472 unsigned int i, stat_cnt = RTE_DIM(dpaa_xstats_strings);
473 uint64_t values_copy[sizeof(struct dpaa_if_stats) / 8];
476 struct dpaa_if *dpaa_intf = dev->data->dev_private;
484 fman_if_stats_get_all(dpaa_intf->fif, values_copy,
485 sizeof(struct dpaa_if_stats) / 8);
487 for (i = 0; i < stat_cnt; i++)
489 values_copy[dpaa_xstats_strings[i].offset / 8];
494 dpaa_xstats_get_by_id(dev, NULL, values_copy, stat_cnt);
496 for (i = 0; i < n; i++) {
497 if (ids[i] >= stat_cnt) {
498 DPAA_PMD_ERR("id value isn't valid");
501 values[i] = values_copy[ids[i]];
507 dpaa_xstats_get_names_by_id(
508 struct rte_eth_dev *dev,
509 struct rte_eth_xstat_name *xstats_names,
513 unsigned int i, stat_cnt = RTE_DIM(dpaa_xstats_strings);
514 struct rte_eth_xstat_name xstats_names_copy[stat_cnt];
517 return dpaa_xstats_get_names(dev, xstats_names, limit);
519 dpaa_xstats_get_names(dev, xstats_names_copy, limit);
521 for (i = 0; i < limit; i++) {
522 if (ids[i] >= stat_cnt) {
523 DPAA_PMD_ERR("id value isn't valid");
526 strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
531 static int dpaa_eth_promiscuous_enable(struct rte_eth_dev *dev)
533 struct dpaa_if *dpaa_intf = dev->data->dev_private;
535 PMD_INIT_FUNC_TRACE();
537 fman_if_promiscuous_enable(dpaa_intf->fif);
542 static int dpaa_eth_promiscuous_disable(struct rte_eth_dev *dev)
544 struct dpaa_if *dpaa_intf = dev->data->dev_private;
546 PMD_INIT_FUNC_TRACE();
548 fman_if_promiscuous_disable(dpaa_intf->fif);
553 static int dpaa_eth_multicast_enable(struct rte_eth_dev *dev)
555 struct dpaa_if *dpaa_intf = dev->data->dev_private;
557 PMD_INIT_FUNC_TRACE();
559 fman_if_set_mcast_filter_table(dpaa_intf->fif);
564 static int dpaa_eth_multicast_disable(struct rte_eth_dev *dev)
566 struct dpaa_if *dpaa_intf = dev->data->dev_private;
568 PMD_INIT_FUNC_TRACE();
570 fman_if_reset_mcast_filter_table(dpaa_intf->fif);
576 int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
578 unsigned int socket_id __rte_unused,
579 const struct rte_eth_rxconf *rx_conf __rte_unused,
580 struct rte_mempool *mp)
582 struct dpaa_if *dpaa_intf = dev->data->dev_private;
583 struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_idx];
584 struct qm_mcc_initfq opts = {0};
587 u32 buffsz = rte_pktmbuf_data_room_size(mp) - RTE_PKTMBUF_HEADROOM;
589 PMD_INIT_FUNC_TRACE();
591 if (queue_idx >= dev->data->nb_rx_queues) {
592 rte_errno = EOVERFLOW;
593 DPAA_PMD_ERR("%p: queue index out of range (%u >= %u)",
594 (void *)dev, queue_idx, dev->data->nb_rx_queues);
598 DPAA_PMD_INFO("Rx queue setup for queue index: %d fq_id (0x%x)",
599 queue_idx, rxq->fqid);
601 /* Max packet can fit in single buffer */
602 if (dev->data->dev_conf.rxmode.max_rx_pkt_len <= buffsz) {
604 } else if (dev->data->dev_conf.rxmode.offloads &
605 DEV_RX_OFFLOAD_SCATTER) {
606 if (dev->data->dev_conf.rxmode.max_rx_pkt_len >
607 buffsz * DPAA_SGT_MAX_ENTRIES) {
608 DPAA_PMD_ERR("max RxPkt size %d too big to fit "
610 dev->data->dev_conf.rxmode.max_rx_pkt_len,
611 buffsz * DPAA_SGT_MAX_ENTRIES);
612 rte_errno = EOVERFLOW;
616 DPAA_PMD_WARN("The requested maximum Rx packet size (%u) is"
617 " larger than a single mbuf (%u) and scattered"
618 " mode has not been requested",
619 dev->data->dev_conf.rxmode.max_rx_pkt_len,
620 buffsz - RTE_PKTMBUF_HEADROOM);
623 if (!dpaa_intf->bp_info || dpaa_intf->bp_info->mp != mp) {
624 struct fman_if_ic_params icp;
628 if (!mp->pool_data) {
629 DPAA_PMD_ERR("Not an offloaded buffer pool!");
632 dpaa_intf->bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
634 memset(&icp, 0, sizeof(icp));
635 /* set ICEOF for to the default value , which is 0*/
636 icp.iciof = DEFAULT_ICIOF;
637 icp.iceof = DEFAULT_RX_ICEOF;
638 icp.icsz = DEFAULT_ICSZ;
639 fman_if_set_ic_params(dpaa_intf->fif, &icp);
641 fd_offset = RTE_PKTMBUF_HEADROOM + DPAA_HW_BUF_RESERVE;
642 fman_if_set_fdoff(dpaa_intf->fif, fd_offset);
644 /* Buffer pool size should be equal to Dataroom Size*/
645 bp_size = rte_pktmbuf_data_room_size(mp);
646 fman_if_set_bp(dpaa_intf->fif, mp->size,
647 dpaa_intf->bp_info->bpid, bp_size);
648 dpaa_intf->valid = 1;
649 DPAA_PMD_DEBUG("if:%s fd_offset = %d offset = %d",
650 dpaa_intf->name, fd_offset,
651 fman_if_get_fdoff(dpaa_intf->fif));
653 DPAA_PMD_DEBUG("if:%s sg_on = %d, max_frm =%d", dpaa_intf->name,
654 fman_if_get_sg_enable(dpaa_intf->fif),
655 dev->data->dev_conf.rxmode.max_rx_pkt_len);
656 /* checking if push mode only, no error check for now */
657 if (!rxq->is_static &&
658 dpaa_push_mode_max_queue > dpaa_push_queue_idx) {
659 struct qman_portal *qp;
662 dpaa_push_queue_idx++;
663 opts.we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
664 opts.fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK |
665 QM_FQCTRL_CTXASTASHING |
666 QM_FQCTRL_PREFERINCACHE;
667 opts.fqd.context_a.stashing.exclusive = 0;
668 /* In muticore scenario stashing becomes a bottleneck on LS1046.
669 * So do not enable stashing in this case
671 if (dpaa_svr_family != SVR_LS1046A_FAMILY)
672 opts.fqd.context_a.stashing.annotation_cl =
673 DPAA_IF_RX_ANNOTATION_STASH;
674 opts.fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
675 opts.fqd.context_a.stashing.context_cl =
676 DPAA_IF_RX_CONTEXT_STASH;
678 /*Create a channel and associate given queue with the channel*/
679 qman_alloc_pool_range((u32 *)&rxq->ch_id, 1, 1, 0);
680 opts.we_mask = opts.we_mask | QM_INITFQ_WE_DESTWQ;
681 opts.fqd.dest.channel = rxq->ch_id;
682 opts.fqd.dest.wq = DPAA_IF_RX_PRIORITY;
683 flags = QMAN_INITFQ_FLAG_SCHED;
685 /* Configure tail drop */
686 if (dpaa_intf->cgr_rx) {
687 opts.we_mask |= QM_INITFQ_WE_CGID;
688 opts.fqd.cgid = dpaa_intf->cgr_rx[queue_idx].cgrid;
689 opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
691 ret = qman_init_fq(rxq, flags, &opts);
693 DPAA_PMD_ERR("Channel/Q association failed. fqid 0x%x "
694 "ret:%d(%s)", rxq->fqid, ret, strerror(ret));
697 if (dpaa_svr_family == SVR_LS1043A_FAMILY) {
698 rxq->cb.dqrr_dpdk_pull_cb = dpaa_rx_cb_no_prefetch;
700 rxq->cb.dqrr_dpdk_pull_cb = dpaa_rx_cb;
701 rxq->cb.dqrr_prepare = dpaa_rx_cb_prepare;
704 rxq->is_static = true;
706 /* Allocate qman specific portals */
707 qp = fsl_qman_fq_portal_create(&q_fd);
709 DPAA_PMD_ERR("Unable to alloc fq portal");
714 /* Set up the device interrupt handler */
715 if (!dev->intr_handle) {
716 struct rte_dpaa_device *dpaa_dev;
717 struct rte_device *rdev = dev->device;
719 dpaa_dev = container_of(rdev, struct rte_dpaa_device,
721 dev->intr_handle = &dpaa_dev->intr_handle;
722 dev->intr_handle->intr_vec = rte_zmalloc(NULL,
723 dpaa_push_mode_max_queue, 0);
724 if (!dev->intr_handle->intr_vec) {
725 DPAA_PMD_ERR("intr_vec alloc failed");
728 dev->intr_handle->nb_efd = dpaa_push_mode_max_queue;
729 dev->intr_handle->max_intr = dpaa_push_mode_max_queue;
732 dev->intr_handle->type = RTE_INTR_HANDLE_EXT;
733 dev->intr_handle->intr_vec[queue_idx] = queue_idx + 1;
734 dev->intr_handle->efds[queue_idx] = q_fd;
737 rxq->bp_array = rte_dpaa_bpid_info;
738 dev->data->rx_queues[queue_idx] = rxq;
740 /* configure the CGR size as per the desc size */
741 if (dpaa_intf->cgr_rx) {
742 struct qm_mcc_initcgr cgr_opts = {0};
744 /* Enable tail drop with cgr on this queue */
745 qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres, nb_desc, 0);
746 ret = qman_modify_cgr(dpaa_intf->cgr_rx, 0, &cgr_opts);
749 "rx taildrop modify fail on fqid %d (ret=%d)",
758 dpaa_eth_eventq_attach(const struct rte_eth_dev *dev,
761 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
765 struct dpaa_if *dpaa_intf = dev->data->dev_private;
766 struct qman_fq *rxq = &dpaa_intf->rx_queues[eth_rx_queue_id];
767 struct qm_mcc_initfq opts = {0};
769 if (dpaa_push_mode_max_queue)
770 DPAA_PMD_WARN("PUSH mode q and EVENTDEV are not compatible\n"
771 "PUSH mode already enabled for first %d queues.\n"
772 "To disable set DPAA_PUSH_QUEUES_NUMBER to 0\n",
773 dpaa_push_mode_max_queue);
775 dpaa_poll_queue_default_config(&opts);
777 switch (queue_conf->ev.sched_type) {
778 case RTE_SCHED_TYPE_ATOMIC:
779 opts.fqd.fq_ctrl |= QM_FQCTRL_HOLDACTIVE;
780 /* Reset FQCTRL_AVOIDBLOCK bit as it is unnecessary
781 * configuration with HOLD_ACTIVE setting
783 opts.fqd.fq_ctrl &= (~QM_FQCTRL_AVOIDBLOCK);
784 rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb_atomic;
786 case RTE_SCHED_TYPE_ORDERED:
787 DPAA_PMD_ERR("Ordered queue schedule type is not supported\n");
790 opts.fqd.fq_ctrl |= QM_FQCTRL_AVOIDBLOCK;
791 rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb_parallel;
795 opts.we_mask = opts.we_mask | QM_INITFQ_WE_DESTWQ;
796 opts.fqd.dest.channel = ch_id;
797 opts.fqd.dest.wq = queue_conf->ev.priority;
799 if (dpaa_intf->cgr_rx) {
800 opts.we_mask |= QM_INITFQ_WE_CGID;
801 opts.fqd.cgid = dpaa_intf->cgr_rx[eth_rx_queue_id].cgrid;
802 opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
805 flags = QMAN_INITFQ_FLAG_SCHED;
807 ret = qman_init_fq(rxq, flags, &opts);
809 DPAA_PMD_ERR("Ev-Channel/Q association failed. fqid 0x%x "
810 "ret:%d(%s)", rxq->fqid, ret, strerror(ret));
814 /* copy configuration which needs to be filled during dequeue */
815 memcpy(&rxq->ev, &queue_conf->ev, sizeof(struct rte_event));
816 dev->data->rx_queues[eth_rx_queue_id] = rxq;
822 dpaa_eth_eventq_detach(const struct rte_eth_dev *dev,
825 struct qm_mcc_initfq opts;
828 struct dpaa_if *dpaa_intf = dev->data->dev_private;
829 struct qman_fq *rxq = &dpaa_intf->rx_queues[eth_rx_queue_id];
831 dpaa_poll_queue_default_config(&opts);
833 if (dpaa_intf->cgr_rx) {
834 opts.we_mask |= QM_INITFQ_WE_CGID;
835 opts.fqd.cgid = dpaa_intf->cgr_rx[eth_rx_queue_id].cgrid;
836 opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
839 ret = qman_init_fq(rxq, flags, &opts);
841 DPAA_PMD_ERR("init rx fqid %d failed with ret: %d",
845 rxq->cb.dqrr_dpdk_cb = NULL;
846 dev->data->rx_queues[eth_rx_queue_id] = NULL;
852 void dpaa_eth_rx_queue_release(void *rxq __rte_unused)
854 PMD_INIT_FUNC_TRACE();
858 int dpaa_eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
859 uint16_t nb_desc __rte_unused,
860 unsigned int socket_id __rte_unused,
861 const struct rte_eth_txconf *tx_conf __rte_unused)
863 struct dpaa_if *dpaa_intf = dev->data->dev_private;
865 PMD_INIT_FUNC_TRACE();
867 if (queue_idx >= dev->data->nb_tx_queues) {
868 rte_errno = EOVERFLOW;
869 DPAA_PMD_ERR("%p: queue index out of range (%u >= %u)",
870 (void *)dev, queue_idx, dev->data->nb_tx_queues);
874 DPAA_PMD_INFO("Tx queue setup for queue index: %d fq_id (0x%x)",
875 queue_idx, dpaa_intf->tx_queues[queue_idx].fqid);
876 dev->data->tx_queues[queue_idx] = &dpaa_intf->tx_queues[queue_idx];
881 static void dpaa_eth_tx_queue_release(void *txq __rte_unused)
883 PMD_INIT_FUNC_TRACE();
887 dpaa_dev_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
889 struct dpaa_if *dpaa_intf = dev->data->dev_private;
890 struct qman_fq *rxq = &dpaa_intf->rx_queues[rx_queue_id];
893 PMD_INIT_FUNC_TRACE();
895 if (qman_query_fq_frm_cnt(rxq, &frm_cnt) == 0) {
896 DPAA_PMD_DEBUG("RX frame count for q(%d) is %u",
897 rx_queue_id, frm_cnt);
902 static int dpaa_link_down(struct rte_eth_dev *dev)
904 PMD_INIT_FUNC_TRACE();
906 dpaa_eth_dev_stop(dev);
910 static int dpaa_link_up(struct rte_eth_dev *dev)
912 PMD_INIT_FUNC_TRACE();
914 dpaa_eth_dev_start(dev);
919 dpaa_flow_ctrl_set(struct rte_eth_dev *dev,
920 struct rte_eth_fc_conf *fc_conf)
922 struct dpaa_if *dpaa_intf = dev->data->dev_private;
923 struct rte_eth_fc_conf *net_fc;
925 PMD_INIT_FUNC_TRACE();
927 if (!(dpaa_intf->fc_conf)) {
928 dpaa_intf->fc_conf = rte_zmalloc(NULL,
929 sizeof(struct rte_eth_fc_conf), MAX_CACHELINE);
930 if (!dpaa_intf->fc_conf) {
931 DPAA_PMD_ERR("unable to save flow control info");
935 net_fc = dpaa_intf->fc_conf;
937 if (fc_conf->high_water < fc_conf->low_water) {
938 DPAA_PMD_ERR("Incorrect Flow Control Configuration");
942 if (fc_conf->mode == RTE_FC_NONE) {
944 } else if (fc_conf->mode == RTE_FC_TX_PAUSE ||
945 fc_conf->mode == RTE_FC_FULL) {
946 fman_if_set_fc_threshold(dpaa_intf->fif, fc_conf->high_water,
948 dpaa_intf->bp_info->bpid);
949 if (fc_conf->pause_time)
950 fman_if_set_fc_quanta(dpaa_intf->fif,
951 fc_conf->pause_time);
954 /* Save the information in dpaa device */
955 net_fc->pause_time = fc_conf->pause_time;
956 net_fc->high_water = fc_conf->high_water;
957 net_fc->low_water = fc_conf->low_water;
958 net_fc->send_xon = fc_conf->send_xon;
959 net_fc->mac_ctrl_frame_fwd = fc_conf->mac_ctrl_frame_fwd;
960 net_fc->mode = fc_conf->mode;
961 net_fc->autoneg = fc_conf->autoneg;
967 dpaa_flow_ctrl_get(struct rte_eth_dev *dev,
968 struct rte_eth_fc_conf *fc_conf)
970 struct dpaa_if *dpaa_intf = dev->data->dev_private;
971 struct rte_eth_fc_conf *net_fc = dpaa_intf->fc_conf;
974 PMD_INIT_FUNC_TRACE();
977 fc_conf->pause_time = net_fc->pause_time;
978 fc_conf->high_water = net_fc->high_water;
979 fc_conf->low_water = net_fc->low_water;
980 fc_conf->send_xon = net_fc->send_xon;
981 fc_conf->mac_ctrl_frame_fwd = net_fc->mac_ctrl_frame_fwd;
982 fc_conf->mode = net_fc->mode;
983 fc_conf->autoneg = net_fc->autoneg;
986 ret = fman_if_get_fc_threshold(dpaa_intf->fif);
988 fc_conf->mode = RTE_FC_TX_PAUSE;
989 fc_conf->pause_time = fman_if_get_fc_quanta(dpaa_intf->fif);
991 fc_conf->mode = RTE_FC_NONE;
998 dpaa_dev_add_mac_addr(struct rte_eth_dev *dev,
999 struct rte_ether_addr *addr,
1001 __rte_unused uint32_t pool)
1004 struct dpaa_if *dpaa_intf = dev->data->dev_private;
1006 PMD_INIT_FUNC_TRACE();
1008 ret = fman_if_add_mac_addr(dpaa_intf->fif, addr->addr_bytes, index);
1011 DPAA_PMD_ERR("Adding the MAC ADDR failed: err = %d", ret);
1016 dpaa_dev_remove_mac_addr(struct rte_eth_dev *dev,
1019 struct dpaa_if *dpaa_intf = dev->data->dev_private;
1021 PMD_INIT_FUNC_TRACE();
1023 fman_if_clear_mac_addr(dpaa_intf->fif, index);
1027 dpaa_dev_set_mac_addr(struct rte_eth_dev *dev,
1028 struct rte_ether_addr *addr)
1031 struct dpaa_if *dpaa_intf = dev->data->dev_private;
1033 PMD_INIT_FUNC_TRACE();
1035 ret = fman_if_add_mac_addr(dpaa_intf->fif, addr->addr_bytes, 0);
1037 DPAA_PMD_ERR("Setting the MAC ADDR failed %d", ret);
1042 static int dpaa_dev_queue_intr_enable(struct rte_eth_dev *dev,
1045 struct dpaa_if *dpaa_intf = dev->data->dev_private;
1046 struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_id];
1048 if (!rxq->is_static)
1051 return qman_fq_portal_irqsource_add(rxq->qp, QM_PIRQ_DQRI);
1054 static int dpaa_dev_queue_intr_disable(struct rte_eth_dev *dev,
1057 struct dpaa_if *dpaa_intf = dev->data->dev_private;
1058 struct qman_fq *rxq = &dpaa_intf->rx_queues[queue_id];
1062 if (!rxq->is_static)
1065 qman_fq_portal_irqsource_remove(rxq->qp, ~0);
1067 temp1 = read(rxq->q_fd, &temp, sizeof(temp));
1068 if (temp1 != sizeof(temp))
1069 DPAA_PMD_ERR("irq read error");
1071 qman_fq_portal_thread_irq(rxq->qp);
1076 static struct eth_dev_ops dpaa_devops = {
1077 .dev_configure = dpaa_eth_dev_configure,
1078 .dev_start = dpaa_eth_dev_start,
1079 .dev_stop = dpaa_eth_dev_stop,
1080 .dev_close = dpaa_eth_dev_close,
1081 .dev_infos_get = dpaa_eth_dev_info,
1082 .dev_supported_ptypes_get = dpaa_supported_ptypes_get,
1084 .rx_queue_setup = dpaa_eth_rx_queue_setup,
1085 .tx_queue_setup = dpaa_eth_tx_queue_setup,
1086 .rx_queue_release = dpaa_eth_rx_queue_release,
1087 .tx_queue_release = dpaa_eth_tx_queue_release,
1088 .rx_queue_count = dpaa_dev_rx_queue_count,
1090 .flow_ctrl_get = dpaa_flow_ctrl_get,
1091 .flow_ctrl_set = dpaa_flow_ctrl_set,
1093 .link_update = dpaa_eth_link_update,
1094 .stats_get = dpaa_eth_stats_get,
1095 .xstats_get = dpaa_dev_xstats_get,
1096 .xstats_get_by_id = dpaa_xstats_get_by_id,
1097 .xstats_get_names_by_id = dpaa_xstats_get_names_by_id,
1098 .xstats_get_names = dpaa_xstats_get_names,
1099 .xstats_reset = dpaa_eth_stats_reset,
1100 .stats_reset = dpaa_eth_stats_reset,
1101 .promiscuous_enable = dpaa_eth_promiscuous_enable,
1102 .promiscuous_disable = dpaa_eth_promiscuous_disable,
1103 .allmulticast_enable = dpaa_eth_multicast_enable,
1104 .allmulticast_disable = dpaa_eth_multicast_disable,
1105 .mtu_set = dpaa_mtu_set,
1106 .dev_set_link_down = dpaa_link_down,
1107 .dev_set_link_up = dpaa_link_up,
1108 .mac_addr_add = dpaa_dev_add_mac_addr,
1109 .mac_addr_remove = dpaa_dev_remove_mac_addr,
1110 .mac_addr_set = dpaa_dev_set_mac_addr,
1112 .fw_version_get = dpaa_fw_version_get,
1114 .rx_queue_intr_enable = dpaa_dev_queue_intr_enable,
1115 .rx_queue_intr_disable = dpaa_dev_queue_intr_disable,
1119 is_device_supported(struct rte_eth_dev *dev, struct rte_dpaa_driver *drv)
1121 if (strcmp(dev->device->driver->name,
1129 is_dpaa_supported(struct rte_eth_dev *dev)
1131 return is_device_supported(dev, &rte_dpaa_pmd);
1135 rte_pmd_dpaa_set_tx_loopback(uint8_t port, uint8_t on)
1137 struct rte_eth_dev *dev;
1138 struct dpaa_if *dpaa_intf;
1140 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1142 dev = &rte_eth_devices[port];
1144 if (!is_dpaa_supported(dev))
1147 dpaa_intf = dev->data->dev_private;
1150 fman_if_loopback_enable(dpaa_intf->fif);
1152 fman_if_loopback_disable(dpaa_intf->fif);
1157 static int dpaa_fc_set_default(struct dpaa_if *dpaa_intf)
1159 struct rte_eth_fc_conf *fc_conf;
1162 PMD_INIT_FUNC_TRACE();
1164 if (!(dpaa_intf->fc_conf)) {
1165 dpaa_intf->fc_conf = rte_zmalloc(NULL,
1166 sizeof(struct rte_eth_fc_conf), MAX_CACHELINE);
1167 if (!dpaa_intf->fc_conf) {
1168 DPAA_PMD_ERR("unable to save flow control info");
1172 fc_conf = dpaa_intf->fc_conf;
1173 ret = fman_if_get_fc_threshold(dpaa_intf->fif);
1175 fc_conf->mode = RTE_FC_TX_PAUSE;
1176 fc_conf->pause_time = fman_if_get_fc_quanta(dpaa_intf->fif);
1178 fc_conf->mode = RTE_FC_NONE;
1184 /* Initialise an Rx FQ */
1185 static int dpaa_rx_queue_init(struct qman_fq *fq, struct qman_cgr *cgr_rx,
1188 struct qm_mcc_initfq opts = {0};
1190 u32 flags = QMAN_FQ_FLAG_NO_ENQUEUE;
1191 struct qm_mcc_initcgr cgr_opts = {
1192 .we_mask = QM_CGR_WE_CS_THRES |
1196 .cstd_en = QM_CGR_EN,
1197 .mode = QMAN_CGR_MODE_FRAME
1202 ret = qman_reserve_fqid(fqid);
1204 DPAA_PMD_ERR("reserve rx fqid 0x%x failed with ret: %d",
1209 flags |= QMAN_FQ_FLAG_DYNAMIC_FQID;
1211 DPAA_PMD_DEBUG("creating rx fq %p, fqid 0x%x", fq, fqid);
1212 ret = qman_create_fq(fqid, flags, fq);
1214 DPAA_PMD_ERR("create rx fqid 0x%x failed with ret: %d",
1218 fq->is_static = false;
1220 dpaa_poll_queue_default_config(&opts);
1223 /* Enable tail drop with cgr on this queue */
1224 qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres, td_threshold, 0);
1226 ret = qman_create_cgr(cgr_rx, QMAN_CGR_FLAG_USE_INIT,
1230 "rx taildrop init fail on rx fqid 0x%x(ret=%d)",
1234 opts.we_mask |= QM_INITFQ_WE_CGID;
1235 opts.fqd.cgid = cgr_rx->cgrid;
1236 opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
1239 ret = qman_init_fq(fq, 0, &opts);
1241 DPAA_PMD_ERR("init rx fqid 0x%x failed with ret:%d", fqid, ret);
1245 /* Initialise a Tx FQ */
1246 static int dpaa_tx_queue_init(struct qman_fq *fq,
1247 struct fman_if *fman_intf,
1248 struct qman_cgr *cgr_tx)
1250 struct qm_mcc_initfq opts = {0};
1251 struct qm_mcc_initcgr cgr_opts = {
1252 .we_mask = QM_CGR_WE_CS_THRES |
1256 .cstd_en = QM_CGR_EN,
1257 .mode = QMAN_CGR_MODE_FRAME
1262 ret = qman_create_fq(0, QMAN_FQ_FLAG_DYNAMIC_FQID |
1263 QMAN_FQ_FLAG_TO_DCPORTAL, fq);
1265 DPAA_PMD_ERR("create tx fq failed with ret: %d", ret);
1268 opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
1269 QM_INITFQ_WE_CONTEXTB | QM_INITFQ_WE_CONTEXTA;
1270 opts.fqd.dest.channel = fman_intf->tx_channel_id;
1271 opts.fqd.dest.wq = DPAA_IF_TX_PRIORITY;
1272 opts.fqd.fq_ctrl = QM_FQCTRL_PREFERINCACHE;
1273 opts.fqd.context_b = 0;
1274 /* no tx-confirmation */
1275 opts.fqd.context_a.hi = 0x80000000 | fman_dealloc_bufs_mask_hi;
1276 opts.fqd.context_a.lo = 0 | fman_dealloc_bufs_mask_lo;
1277 DPAA_PMD_DEBUG("init tx fq %p, fqid 0x%x", fq, fq->fqid);
1280 /* Enable tail drop with cgr on this queue */
1281 qm_cgr_cs_thres_set64(&cgr_opts.cgr.cs_thres,
1282 td_tx_threshold, 0);
1284 ret = qman_create_cgr(cgr_tx, QMAN_CGR_FLAG_USE_INIT,
1288 "rx taildrop init fail on rx fqid 0x%x(ret=%d)",
1292 opts.we_mask |= QM_INITFQ_WE_CGID;
1293 opts.fqd.cgid = cgr_tx->cgrid;
1294 opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
1295 DPAA_PMD_DEBUG("Tx FQ tail drop enabled, threshold = %d\n",
1299 ret = qman_init_fq(fq, QMAN_INITFQ_FLAG_SCHED, &opts);
1301 DPAA_PMD_ERR("init tx fqid 0x%x failed %d", fq->fqid, ret);
1305 #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
1306 /* Initialise a DEBUG FQ ([rt]x_error, rx_default). */
1307 static int dpaa_debug_queue_init(struct qman_fq *fq, uint32_t fqid)
1309 struct qm_mcc_initfq opts = {0};
1312 PMD_INIT_FUNC_TRACE();
1314 ret = qman_reserve_fqid(fqid);
1316 DPAA_PMD_ERR("Reserve debug fqid %d failed with ret: %d",
1320 /* "map" this Rx FQ to one of the interfaces Tx FQID */
1321 DPAA_PMD_DEBUG("Creating debug fq %p, fqid %d", fq, fqid);
1322 ret = qman_create_fq(fqid, QMAN_FQ_FLAG_NO_ENQUEUE, fq);
1324 DPAA_PMD_ERR("create debug fqid %d failed with ret: %d",
1328 opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL;
1329 opts.fqd.dest.wq = DPAA_IF_DEBUG_PRIORITY;
1330 ret = qman_init_fq(fq, 0, &opts);
1332 DPAA_PMD_ERR("init debug fqid %d failed with ret: %d",
1338 /* Initialise a network interface */
1340 dpaa_dev_init(struct rte_eth_dev *eth_dev)
1342 int num_rx_fqs, fqid;
1345 struct rte_dpaa_device *dpaa_device;
1346 struct dpaa_if *dpaa_intf;
1347 struct fm_eth_port_cfg *cfg;
1348 struct fman_if *fman_intf;
1349 struct fman_if_bpool *bp, *tmp_bp;
1350 uint32_t cgrid[DPAA_MAX_NUM_PCD_QUEUES];
1351 uint32_t cgrid_tx[MAX_DPAA_CORES];
1352 char eth_buf[RTE_ETHER_ADDR_FMT_SIZE];
1354 PMD_INIT_FUNC_TRACE();
1356 dpaa_intf = eth_dev->data->dev_private;
1357 /* For secondary processes, the primary has done all the work */
1358 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1359 eth_dev->dev_ops = &dpaa_devops;
1360 /* Plugging of UCODE burst API not supported in Secondary */
1361 eth_dev->rx_pkt_burst = dpaa_eth_queue_rx;
1362 if (dpaa_intf->cgr_tx)
1363 eth_dev->tx_pkt_burst = dpaa_eth_queue_tx_slow;
1365 eth_dev->tx_pkt_burst = dpaa_eth_queue_tx;
1366 #ifdef CONFIG_FSL_QMAN_FQ_LOOKUP
1367 qman_set_fq_lookup_table(
1368 dpaa_intf->rx_queues->qman_fq_lookup_table);
1373 dpaa_device = DEV_TO_DPAA_DEVICE(eth_dev->device);
1374 dev_id = dpaa_device->id.dev_id;
1375 dpaa_intf = eth_dev->data->dev_private;
1376 cfg = dpaa_get_eth_port_cfg(dev_id);
1377 fman_intf = cfg->fman_if;
1379 dpaa_intf->name = dpaa_device->name;
1381 /* save fman_if & cfg in the interface struture */
1382 dpaa_intf->fif = fman_intf;
1383 dpaa_intf->ifid = dev_id;
1384 dpaa_intf->cfg = cfg;
1386 /* Initialize Rx FQ's */
1388 num_rx_fqs = DPAA_DEFAULT_NUM_PCD_QUEUES;
1390 if (getenv("DPAA_NUM_RX_QUEUES"))
1391 num_rx_fqs = atoi(getenv("DPAA_NUM_RX_QUEUES"));
1393 num_rx_fqs = DPAA_DEFAULT_NUM_PCD_QUEUES;
1397 /* Each device can not have more than DPAA_MAX_NUM_PCD_QUEUES RX
1400 if (num_rx_fqs <= 0 || num_rx_fqs > DPAA_MAX_NUM_PCD_QUEUES) {
1401 DPAA_PMD_ERR("Invalid number of RX queues\n");
1405 dpaa_intf->rx_queues = rte_zmalloc(NULL,
1406 sizeof(struct qman_fq) * num_rx_fqs, MAX_CACHELINE);
1407 if (!dpaa_intf->rx_queues) {
1408 DPAA_PMD_ERR("Failed to alloc mem for RX queues\n");
1412 memset(cgrid, 0, sizeof(cgrid));
1413 memset(cgrid_tx, 0, sizeof(cgrid_tx));
1415 /* if DPAA_TX_TAILDROP_THRESHOLD is set, use that value; if 0, it means
1416 * Tx tail drop is disabled.
1418 if (getenv("DPAA_TX_TAILDROP_THRESHOLD")) {
1419 td_tx_threshold = atoi(getenv("DPAA_TX_TAILDROP_THRESHOLD"));
1420 DPAA_PMD_DEBUG("Tail drop threshold env configured: %u",
1422 /* if a very large value is being configured */
1423 if (td_tx_threshold > UINT16_MAX)
1424 td_tx_threshold = CGR_RX_PERFQ_THRESH;
1427 /* If congestion control is enabled globally*/
1429 dpaa_intf->cgr_rx = rte_zmalloc(NULL,
1430 sizeof(struct qman_cgr) * num_rx_fqs, MAX_CACHELINE);
1431 if (!dpaa_intf->cgr_rx) {
1432 DPAA_PMD_ERR("Failed to alloc mem for cgr_rx\n");
1437 ret = qman_alloc_cgrid_range(&cgrid[0], num_rx_fqs, 1, 0);
1438 if (ret != num_rx_fqs) {
1439 DPAA_PMD_WARN("insufficient CGRIDs available");
1444 dpaa_intf->cgr_rx = NULL;
1447 for (loop = 0; loop < num_rx_fqs; loop++) {
1451 fqid = DPAA_PCD_FQID_START + dpaa_intf->fif->mac_idx *
1452 DPAA_PCD_FQID_MULTIPLIER + loop;
1454 if (dpaa_intf->cgr_rx)
1455 dpaa_intf->cgr_rx[loop].cgrid = cgrid[loop];
1457 ret = dpaa_rx_queue_init(&dpaa_intf->rx_queues[loop],
1458 dpaa_intf->cgr_rx ? &dpaa_intf->cgr_rx[loop] : NULL,
1462 dpaa_intf->rx_queues[loop].dpaa_intf = dpaa_intf;
1464 dpaa_intf->nb_rx_queues = num_rx_fqs;
1466 /* Initialise Tx FQs.free_rx Have as many Tx FQ's as number of cores */
1467 dpaa_intf->tx_queues = rte_zmalloc(NULL, sizeof(struct qman_fq) *
1468 MAX_DPAA_CORES, MAX_CACHELINE);
1469 if (!dpaa_intf->tx_queues) {
1470 DPAA_PMD_ERR("Failed to alloc mem for TX queues\n");
1475 /* If congestion control is enabled globally*/
1476 if (td_tx_threshold) {
1477 dpaa_intf->cgr_tx = rte_zmalloc(NULL,
1478 sizeof(struct qman_cgr) * MAX_DPAA_CORES,
1480 if (!dpaa_intf->cgr_tx) {
1481 DPAA_PMD_ERR("Failed to alloc mem for cgr_tx\n");
1486 ret = qman_alloc_cgrid_range(&cgrid_tx[0], MAX_DPAA_CORES,
1488 if (ret != MAX_DPAA_CORES) {
1489 DPAA_PMD_WARN("insufficient CGRIDs available");
1494 dpaa_intf->cgr_tx = NULL;
1498 for (loop = 0; loop < MAX_DPAA_CORES; loop++) {
1499 if (dpaa_intf->cgr_tx)
1500 dpaa_intf->cgr_tx[loop].cgrid = cgrid_tx[loop];
1502 ret = dpaa_tx_queue_init(&dpaa_intf->tx_queues[loop],
1504 dpaa_intf->cgr_tx ? &dpaa_intf->cgr_tx[loop] : NULL);
1507 dpaa_intf->tx_queues[loop].dpaa_intf = dpaa_intf;
1509 dpaa_intf->nb_tx_queues = MAX_DPAA_CORES;
1511 #ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
1512 dpaa_debug_queue_init(&dpaa_intf->debug_queues[
1513 DPAA_DEBUG_FQ_RX_ERROR], fman_intf->fqid_rx_err);
1514 dpaa_intf->debug_queues[DPAA_DEBUG_FQ_RX_ERROR].dpaa_intf = dpaa_intf;
1515 dpaa_debug_queue_init(&dpaa_intf->debug_queues[
1516 DPAA_DEBUG_FQ_TX_ERROR], fman_intf->fqid_tx_err);
1517 dpaa_intf->debug_queues[DPAA_DEBUG_FQ_TX_ERROR].dpaa_intf = dpaa_intf;
1520 DPAA_PMD_DEBUG("All frame queues created");
1522 /* Get the initial configuration for flow control */
1523 dpaa_fc_set_default(dpaa_intf);
1525 /* reset bpool list, initialize bpool dynamically */
1526 list_for_each_entry_safe(bp, tmp_bp, &cfg->fman_if->bpool_list, node) {
1527 list_del(&bp->node);
1531 /* Populate ethdev structure */
1532 eth_dev->dev_ops = &dpaa_devops;
1533 eth_dev->rx_pkt_burst = dpaa_eth_queue_rx;
1534 eth_dev->tx_pkt_burst = dpaa_eth_tx_drop_all;
1536 /* Allocate memory for storing MAC addresses */
1537 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
1538 RTE_ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER, 0);
1539 if (eth_dev->data->mac_addrs == NULL) {
1540 DPAA_PMD_ERR("Failed to allocate %d bytes needed to "
1541 "store MAC addresses",
1542 RTE_ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER);
1547 /* copy the primary mac address */
1548 rte_ether_addr_copy(&fman_intf->mac_addr, ð_dev->data->mac_addrs[0]);
1549 rte_ether_format_addr(eth_buf, sizeof(eth_buf), &fman_intf->mac_addr);
1551 DPAA_PMD_INFO("net: dpaa: %s: %s", dpaa_device->name, eth_buf);
1553 /* Disable RX mode */
1554 fman_if_discard_rx_errors(fman_intf);
1555 fman_if_disable_rx(fman_intf);
1556 /* Disable promiscuous mode */
1557 fman_if_promiscuous_disable(fman_intf);
1558 /* Disable multicast */
1559 fman_if_reset_mcast_filter_table(fman_intf);
1560 /* Reset interface statistics */
1561 fman_if_stats_reset(fman_intf);
1562 /* Disable SG by default */
1563 fman_if_set_sg(fman_intf, 0);
1564 fman_if_set_maxfrm(fman_intf, RTE_ETHER_MAX_LEN + VLAN_TAG_SIZE);
1569 rte_free(dpaa_intf->tx_queues);
1570 dpaa_intf->tx_queues = NULL;
1571 dpaa_intf->nb_tx_queues = 0;
1574 rte_free(dpaa_intf->cgr_rx);
1575 rte_free(dpaa_intf->cgr_tx);
1576 rte_free(dpaa_intf->rx_queues);
1577 dpaa_intf->rx_queues = NULL;
1578 dpaa_intf->nb_rx_queues = 0;
1583 dpaa_dev_uninit(struct rte_eth_dev *dev)
1585 struct dpaa_if *dpaa_intf = dev->data->dev_private;
1588 PMD_INIT_FUNC_TRACE();
1590 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1594 DPAA_PMD_WARN("Already closed or not started");
1598 dpaa_eth_dev_close(dev);
1600 /* release configuration memory */
1601 if (dpaa_intf->fc_conf)
1602 rte_free(dpaa_intf->fc_conf);
1604 /* Release RX congestion Groups */
1605 if (dpaa_intf->cgr_rx) {
1606 for (loop = 0; loop < dpaa_intf->nb_rx_queues; loop++)
1607 qman_delete_cgr(&dpaa_intf->cgr_rx[loop]);
1609 qman_release_cgrid_range(dpaa_intf->cgr_rx[loop].cgrid,
1610 dpaa_intf->nb_rx_queues);
1613 rte_free(dpaa_intf->cgr_rx);
1614 dpaa_intf->cgr_rx = NULL;
1616 /* Release TX congestion Groups */
1617 if (dpaa_intf->cgr_tx) {
1618 for (loop = 0; loop < MAX_DPAA_CORES; loop++)
1619 qman_delete_cgr(&dpaa_intf->cgr_tx[loop]);
1621 qman_release_cgrid_range(dpaa_intf->cgr_tx[loop].cgrid,
1623 rte_free(dpaa_intf->cgr_tx);
1624 dpaa_intf->cgr_tx = NULL;
1627 rte_free(dpaa_intf->rx_queues);
1628 dpaa_intf->rx_queues = NULL;
1630 rte_free(dpaa_intf->tx_queues);
1631 dpaa_intf->tx_queues = NULL;
1633 dev->dev_ops = NULL;
1634 dev->rx_pkt_burst = NULL;
1635 dev->tx_pkt_burst = NULL;
1641 rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,
1642 struct rte_dpaa_device *dpaa_dev)
1646 struct rte_eth_dev *eth_dev;
1648 PMD_INIT_FUNC_TRACE();
1650 if ((DPAA_MBUF_HW_ANNOTATION + DPAA_FD_PTA_SIZE) >
1651 RTE_PKTMBUF_HEADROOM) {
1653 "RTE_PKTMBUF_HEADROOM(%d) shall be > DPAA Annotation req(%d)",
1654 RTE_PKTMBUF_HEADROOM,
1655 DPAA_MBUF_HW_ANNOTATION + DPAA_FD_PTA_SIZE);
1660 /* In case of secondary process, the device is already configured
1661 * and no further action is required, except portal initialization
1662 * and verifying secondary attachment to port name.
1664 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1665 eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
1668 eth_dev->device = &dpaa_dev->device;
1669 eth_dev->dev_ops = &dpaa_devops;
1670 rte_eth_dev_probing_finish(eth_dev);
1674 if (!is_global_init && (rte_eal_process_type() == RTE_PROC_PRIMARY)) {
1675 if (access("/tmp/fmc.bin", F_OK) == -1) {
1676 DPAA_PMD_INFO("* FMC not configured.Enabling default mode");
1680 /* disabling the default push mode for LS1043 */
1681 if (dpaa_svr_family == SVR_LS1043A_FAMILY)
1682 dpaa_push_mode_max_queue = 0;
1684 /* if push mode queues to be enabled. Currenly we are allowing
1685 * only one queue per thread.
1687 if (getenv("DPAA_PUSH_QUEUES_NUMBER")) {
1688 dpaa_push_mode_max_queue =
1689 atoi(getenv("DPAA_PUSH_QUEUES_NUMBER"));
1690 if (dpaa_push_mode_max_queue > DPAA_MAX_PUSH_MODE_QUEUE)
1691 dpaa_push_mode_max_queue = DPAA_MAX_PUSH_MODE_QUEUE;
1697 if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
1698 ret = rte_dpaa_portal_init((void *)1);
1700 DPAA_PMD_ERR("Unable to initialize portal");
1705 /* In case of secondary process, the device is already configured
1706 * and no further action is required, except portal initialization
1707 * and verifying secondary attachment to port name.
1709 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1710 eth_dev = rte_eth_dev_attach_secondary(dpaa_dev->name);
1714 eth_dev = rte_eth_dev_allocate(dpaa_dev->name);
1715 if (eth_dev == NULL)
1718 eth_dev->data->dev_private = rte_zmalloc(
1719 "ethdev private structure",
1720 sizeof(struct dpaa_if),
1721 RTE_CACHE_LINE_SIZE);
1722 if (!eth_dev->data->dev_private) {
1723 DPAA_PMD_ERR("Cannot allocate memzone for port data");
1724 rte_eth_dev_release_port(eth_dev);
1728 eth_dev->device = &dpaa_dev->device;
1729 dpaa_dev->eth_dev = eth_dev;
1731 qman_ern_register_cb(dpaa_free_mbuf);
1733 /* Invoke PMD device initialization function */
1734 diag = dpaa_dev_init(eth_dev);
1736 rte_eth_dev_probing_finish(eth_dev);
1740 rte_eth_dev_release_port(eth_dev);
1745 rte_dpaa_remove(struct rte_dpaa_device *dpaa_dev)
1747 struct rte_eth_dev *eth_dev;
1749 PMD_INIT_FUNC_TRACE();
1751 eth_dev = dpaa_dev->eth_dev;
1752 dpaa_dev_uninit(eth_dev);
1754 rte_eth_dev_release_port(eth_dev);
1759 static struct rte_dpaa_driver rte_dpaa_pmd = {
1760 .drv_type = FSL_DPAA_ETH,
1761 .probe = rte_dpaa_probe,
1762 .remove = rte_dpaa_remove,
1765 RTE_PMD_REGISTER_DPAA(net_dpaa, rte_dpaa_pmd);
1766 RTE_LOG_REGISTER(dpaa_logtype_pmd, pmd.net.dpaa, NOTICE);