1 From 6ec4d0cf0b0e5e41abc91012db4ebff7d415a92b Mon Sep 17 00:00:00 2001
2 From: Biwen Li <biwen.li@nxp.com>
3 Date: Tue, 30 Oct 2018 18:26:13 +0800
4 Subject: [PATCH 08/40] dpaa2-ethernet: support layerscape
5 This is an integrated patch of dpaa2-ethernet for
8 Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
9 Signed-off-by: Camelia Groza <camelia.groza@nxp.com>
10 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
11 Signed-off-by: Guanhua Gao <guanhua.gao@nxp.com>
12 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
13 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
14 Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
15 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
16 Signed-off-by: Biwen Li <biwen.li@nxp.com>
18 drivers/staging/fsl-dpaa2/Kconfig | 7 +
19 drivers/staging/fsl-dpaa2/ethernet/Makefile | 2 +
20 .../fsl-dpaa2/ethernet/dpaa2-eth-ceetm.c | 1240 +++++++++
21 .../fsl-dpaa2/ethernet/dpaa2-eth-ceetm.h | 183 ++
22 .../fsl-dpaa2/ethernet/dpaa2-eth-debugfs.c | 357 +++
23 .../fsl-dpaa2/ethernet/dpaa2-eth-debugfs.h | 60 +
24 .../staging/fsl-dpaa2/ethernet/dpaa2-eth.c | 2335 +++++++++++++----
25 .../staging/fsl-dpaa2/ethernet/dpaa2-eth.h | 388 ++-
26 .../fsl-dpaa2/ethernet/dpaa2-ethtool.c | 625 ++++-
27 drivers/staging/fsl-dpaa2/ethernet/dpni-cmd.h | 192 +-
28 drivers/staging/fsl-dpaa2/ethernet/dpni.c | 604 ++++-
29 drivers/staging/fsl-dpaa2/ethernet/dpni.h | 344 ++-
30 12 files changed, 5723 insertions(+), 614 deletions(-)
31 create mode 100644 drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-ceetm.c
32 create mode 100644 drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-ceetm.h
33 create mode 100644 drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-debugfs.c
34 create mode 100644 drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-debugfs.h
36 --- a/drivers/staging/fsl-dpaa2/Kconfig
37 +++ b/drivers/staging/fsl-dpaa2/Kconfig
38 @@ -17,6 +17,13 @@ config FSL_DPAA2_ETH
39 Ethernet driver for Freescale DPAA2 SoCs, using the
40 Freescale MC bus driver
42 +config FSL_DPAA2_ETH_CEETM
43 + depends on NET_SCHED
44 + bool "DPAA2 Ethernet CEETM QoS"
47 + Enable QoS offloading support through the CEETM hardware block.
50 config FSL_DPAA2_ETH_USE_ERR_QUEUE
51 bool "Enable Rx error queue"
52 --- a/drivers/staging/fsl-dpaa2/ethernet/Makefile
53 +++ b/drivers/staging/fsl-dpaa2/ethernet/Makefile
55 obj-$(CONFIG_FSL_DPAA2_ETH) += fsl-dpaa2-eth.o
57 fsl-dpaa2-eth-objs := dpaa2-eth.o dpaa2-ethtool.o dpni.o
58 +fsl-dpaa2-eth-${CONFIG_FSL_DPAA2_ETH_DEBUGFS} += dpaa2-eth-debugfs.o
59 +fsl-dpaa2-eth-${CONFIG_FSL_DPAA2_ETH_CEETM} += dpaa2-eth-ceetm.o
61 # Needed by the tracing framework
62 CFLAGS_dpaa2-eth.o := -I$(src)
64 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-ceetm.c
66 +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
68 + * Copyright 2017 NXP
72 +#include <linux/init.h>
73 +#include <linux/module.h>
75 +#include "dpaa2-eth-ceetm.h"
76 +#include "dpaa2-eth.h"
78 +#define DPAA2_CEETM_DESCRIPTION "FSL DPAA2 CEETM qdisc"
79 +/* Conversion formula from userspace passed Bps to expected Mbit */
80 +#define dpaa2_eth_bps_to_mbit(rate) (rate >> 17)
82 +static const struct nla_policy dpaa2_ceetm_policy[DPAA2_CEETM_TCA_MAX] = {
83 + [DPAA2_CEETM_TCA_COPT] = { .len = sizeof(struct dpaa2_ceetm_tc_copt) },
84 + [DPAA2_CEETM_TCA_QOPS] = { .len = sizeof(struct dpaa2_ceetm_tc_qopt) },
87 +struct Qdisc_ops dpaa2_ceetm_qdisc_ops;
89 +static inline int dpaa2_eth_set_ch_shaping(struct dpaa2_eth_priv *priv,
90 + struct dpni_tx_shaping_cfg *scfg,
91 + struct dpni_tx_shaping_cfg *ecfg,
92 + int coupled, int ch_id)
96 + netdev_dbg(priv->net_dev, "%s: ch_id %d rate %d mbps\n", __func__,
97 + ch_id, scfg->rate_limit);
98 + err = dpni_set_tx_shaping(priv->mc_io, 0, priv->mc_token, scfg,
101 + netdev_err(priv->net_dev, "dpni_set_tx_shaping err\n");
106 +static inline int dpaa2_eth_reset_ch_shaping(struct dpaa2_eth_priv *priv,
109 + struct dpni_tx_shaping_cfg cfg = { 0 };
111 + return dpaa2_eth_set_ch_shaping(priv, &cfg, &cfg, 0, ch_id);
115 +dpaa2_eth_update_shaping_cfg(struct net_device *dev,
116 + struct dpaa2_ceetm_shaping_cfg cfg,
117 + struct dpni_tx_shaping_cfg *scfg,
118 + struct dpni_tx_shaping_cfg *ecfg)
120 + scfg->rate_limit = dpaa2_eth_bps_to_mbit(cfg.cir);
121 + ecfg->rate_limit = dpaa2_eth_bps_to_mbit(cfg.eir);
123 + if (cfg.cbs > DPAA2_ETH_MAX_BURST_SIZE) {
124 + netdev_err(dev, "Committed burst size must be under %d\n",
125 + DPAA2_ETH_MAX_BURST_SIZE);
129 + scfg->max_burst_size = cfg.cbs;
131 + if (cfg.ebs > DPAA2_ETH_MAX_BURST_SIZE) {
132 + netdev_err(dev, "Excess burst size must be under %d\n",
133 + DPAA2_ETH_MAX_BURST_SIZE);
137 + ecfg->max_burst_size = cfg.ebs;
139 + if ((!cfg.cir || !cfg.eir) && cfg.coupled) {
140 + netdev_err(dev, "Coupling can be set when both CIR and EIR are finite\n");
147 +enum update_tx_prio {
152 +/* Normalize weights based on max passed value */
153 +static inline int dpaa2_eth_normalize_tx_prio(struct dpaa2_ceetm_qdisc *priv)
155 + struct dpni_tx_schedule_cfg *sched_cfg;
156 + struct dpaa2_ceetm_class *cl;
158 + u16 weight_max = 0, increment;
161 + /* Check the boundaries of the provided values */
162 + for (i = 0; i < priv->clhash.hashsize; i++)
163 + hlist_for_each_entry(cl, &priv->clhash.hash[i], common.hnode)
164 + weight_max = (weight_max == 0 ? cl->prio.weight :
165 + (weight_max < cl->prio.weight ?
166 + cl->prio.weight : weight_max));
168 + /* If there are no elements, there's nothing to do */
169 + if (weight_max == 0)
172 + increment = (DPAA2_CEETM_MAX_WEIGHT - DPAA2_CEETM_MIN_WEIGHT) /
175 + for (i = 0; i < priv->clhash.hashsize; i++) {
176 + hlist_for_each_entry(cl, &priv->clhash.hash[i], common.hnode) {
177 + if (cl->prio.mode == STRICT_PRIORITY)
180 + qpri = cl->prio.qpri;
181 + sched_cfg = &priv->prio.tx_prio_cfg.tc_sched[qpri];
183 + sched_cfg->delta_bandwidth =
184 + DPAA2_CEETM_MIN_WEIGHT +
185 + (cl->prio.weight * increment);
187 + pr_debug("%s: Normalized CQ qpri %d weight to %d\n",
188 + __func__, qpri, sched_cfg->delta_bandwidth);
195 +static inline int dpaa2_eth_update_tx_prio(struct dpaa2_eth_priv *priv,
196 + struct dpaa2_ceetm_class *cl,
197 + enum update_tx_prio type)
199 + struct dpaa2_ceetm_qdisc *sch = qdisc_priv(cl->parent);
200 + struct dpni_congestion_notification_cfg notif_cfg = {0};
201 + struct dpni_tx_schedule_cfg *sched_cfg;
202 + struct dpni_taildrop td = {0};
203 + u8 ch_id = 0, tc_id = 0;
207 + qpri = cl->prio.qpri;
208 + tc_id = DPNI_BUILD_CH_TC(ch_id, qpri);
211 + case DPAA2_ETH_ADD_CQ:
212 + /* Disable congestion notifications */
213 + notif_cfg.threshold_entry = 0;
214 + notif_cfg.threshold_exit = 0;
215 + err = dpni_set_congestion_notification(priv->mc_io, 0,
217 + DPNI_QUEUE_TX, tc_id,
220 + netdev_err(priv->net_dev, "Error disabling congestion notifications %d\n",
224 + /* Enable taildrop */
226 + td.units = DPNI_CONGESTION_UNIT_FRAMES;
227 + td.threshold = DPAA2_CEETM_TD_THRESHOLD;
228 + err = dpni_set_taildrop(priv->mc_io, 0, priv->mc_token,
229 + DPNI_CP_GROUP, DPNI_QUEUE_TX, tc_id,
232 + netdev_err(priv->net_dev, "Error enabling Tx taildrop %d\n",
237 + case DPAA2_ETH_DEL_CQ:
238 + /* Disable taildrop */
240 + err = dpni_set_taildrop(priv->mc_io, 0, priv->mc_token,
241 + DPNI_CP_GROUP, DPNI_QUEUE_TX, tc_id,
244 + netdev_err(priv->net_dev, "Error disabling Tx taildrop %d\n",
248 + /* Enable congestion notifications */
249 + notif_cfg.units = DPNI_CONGESTION_UNIT_BYTES;
250 + notif_cfg.threshold_entry = DPAA2_ETH_TX_CONG_ENTRY_THRESH;
251 + notif_cfg.threshold_exit = DPAA2_ETH_TX_CONG_EXIT_THRESH;
252 + notif_cfg.message_ctx = (u64)priv;
253 + notif_cfg.message_iova = priv->cscn_dma;
254 + notif_cfg.notification_mode = DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
255 + DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
256 + DPNI_CONG_OPT_COHERENT_WRITE;
257 + err = dpni_set_congestion_notification(priv->mc_io, 0,
259 + DPNI_QUEUE_TX, tc_id,
262 + netdev_err(priv->net_dev, "Error enabling congestion notifications %d\n",
269 + /* We can zero out the structure in the tx_prio_conf array */
270 + if (type == DPAA2_ETH_DEL_CQ) {
271 + sched_cfg = &sch->prio.tx_prio_cfg.tc_sched[qpri];
272 + memset(sched_cfg, 0, sizeof(*sched_cfg));
275 + /* Normalize priorities */
276 + err = dpaa2_eth_normalize_tx_prio(sch);
278 + /* Debug print goes here */
279 + print_hex_dump_debug("tx_prio: ", DUMP_PREFIX_OFFSET, 16, 1,
280 + &sch->prio.tx_prio_cfg,
281 + sizeof(sch->prio.tx_prio_cfg), 0);
283 + /* Call dpni_set_tx_priorities for the entire prio qdisc */
284 + err = dpni_set_tx_priorities(priv->mc_io, 0, priv->mc_token,
285 + &sch->prio.tx_prio_cfg);
287 + netdev_err(priv->net_dev, "dpni_set_tx_priorities err %d\n",
293 +static void dpaa2_eth_ceetm_enable(struct dpaa2_eth_priv *priv)
295 + priv->ceetm_en = true;
298 +static void dpaa2_eth_ceetm_disable(struct dpaa2_eth_priv *priv)
300 + priv->ceetm_en = false;
303 +/* Find class in qdisc hash table using given handle */
304 +static inline struct dpaa2_ceetm_class *dpaa2_ceetm_find(u32 handle,
307 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
308 + struct Qdisc_class_common *clc;
310 + pr_debug(KBUILD_BASENAME " : %s : find class %X in qdisc %X\n",
311 + __func__, handle, sch->handle);
313 + clc = qdisc_class_find(&priv->clhash, handle);
314 + return clc ? container_of(clc, struct dpaa2_ceetm_class, common) : NULL;
317 +/* Insert a class in the qdisc's class hash */
318 +static void dpaa2_ceetm_link_class(struct Qdisc *sch,
319 + struct Qdisc_class_hash *clhash,
320 + struct Qdisc_class_common *common)
322 + sch_tree_lock(sch);
323 + qdisc_class_hash_insert(clhash, common);
324 + sch_tree_unlock(sch);
325 + qdisc_class_hash_grow(sch, clhash);
328 +/* Destroy a ceetm class */
329 +static void dpaa2_ceetm_cls_destroy(struct Qdisc *sch,
330 + struct dpaa2_ceetm_class *cl)
332 + struct net_device *dev = qdisc_dev(sch);
333 + struct dpaa2_eth_priv *priv = netdev_priv(dev);
338 + pr_debug(KBUILD_BASENAME " : %s : destroy class %X from under %X\n",
339 + __func__, cl->common.classid, sch->handle);
341 + /* Recurse into child first */
343 + qdisc_destroy(cl->child);
347 + switch (cl->type) {
349 + if (dpaa2_eth_reset_ch_shaping(priv, cl->root.ch_id))
350 + netdev_err(dev, "Error resetting channel shaping\n");
355 + if (dpaa2_eth_update_tx_prio(priv, cl, DPAA2_ETH_DEL_CQ))
356 + netdev_err(dev, "Error resetting tx_priorities\n");
358 + if (cl->prio.cstats)
359 + free_percpu(cl->prio.cstats);
364 + tcf_block_put(cl->block);
368 +/* Destroy a ceetm qdisc */
369 +static void dpaa2_ceetm_destroy(struct Qdisc *sch)
372 + struct hlist_node *next;
373 + struct dpaa2_ceetm_class *cl;
374 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
375 + struct net_device *dev = qdisc_dev(sch);
376 + struct dpaa2_eth_priv *priv_eth = netdev_priv(dev);
378 + pr_debug(KBUILD_BASENAME " : %s : destroy qdisc %X\n",
379 + __func__, sch->handle);
381 + /* All filters need to be removed before destroying the classes */
382 + tcf_block_put(priv->block);
384 + for (i = 0; i < priv->clhash.hashsize; i++) {
385 + hlist_for_each_entry(cl, &priv->clhash.hash[i], common.hnode)
386 + tcf_block_put(cl->block);
389 + for (i = 0; i < priv->clhash.hashsize; i++) {
390 + hlist_for_each_entry_safe(cl, next, &priv->clhash.hash[i],
392 + dpaa2_ceetm_cls_destroy(sch, cl);
395 + qdisc_class_hash_destroy(&priv->clhash);
397 + switch (priv->type) {
399 + dpaa2_eth_ceetm_disable(priv_eth);
401 + if (priv->root.qstats)
402 + free_percpu(priv->root.qstats);
404 + if (!priv->root.qdiscs)
407 + /* Destroy the pfifo qdiscs in case they haven't been attached
408 + * to the netdev queues yet.
410 + for (i = 0; i < dev->num_tx_queues; i++)
411 + if (priv->root.qdiscs[i])
412 + qdisc_destroy(priv->root.qdiscs[i]);
414 + kfree(priv->root.qdiscs);
418 + if (priv->prio.parent)
419 + priv->prio.parent->child = NULL;
424 +static int dpaa2_ceetm_dump(struct Qdisc *sch, struct sk_buff *skb)
426 + struct Qdisc *qdisc;
427 + unsigned int ntx, i;
428 + struct nlattr *nest;
429 + struct dpaa2_ceetm_tc_qopt qopt;
430 + struct dpaa2_ceetm_qdisc_stats *qstats;
431 + struct net_device *dev = qdisc_dev(sch);
432 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
434 + pr_debug(KBUILD_BASENAME " : %s : qdisc %X\n", __func__, sch->handle);
436 + sch_tree_lock(sch);
437 + memset(&qopt, 0, sizeof(qopt));
438 + qopt.type = priv->type;
439 + qopt.shaped = priv->shaped;
441 + switch (priv->type) {
443 + /* Gather statistics from the underlying pfifo qdiscs */
445 + memset(&sch->bstats, 0, sizeof(sch->bstats));
446 + memset(&sch->qstats, 0, sizeof(sch->qstats));
448 + for (ntx = 0; ntx < dev->num_tx_queues; ntx++) {
449 + qdisc = netdev_get_tx_queue(dev, ntx)->qdisc_sleeping;
450 + sch->q.qlen += qdisc->q.qlen;
451 + sch->bstats.bytes += qdisc->bstats.bytes;
452 + sch->bstats.packets += qdisc->bstats.packets;
453 + sch->qstats.qlen += qdisc->qstats.qlen;
454 + sch->qstats.backlog += qdisc->qstats.backlog;
455 + sch->qstats.drops += qdisc->qstats.drops;
456 + sch->qstats.requeues += qdisc->qstats.requeues;
457 + sch->qstats.overlimits += qdisc->qstats.overlimits;
460 + for_each_online_cpu(i) {
461 + qstats = per_cpu_ptr(priv->root.qstats, i);
462 + sch->qstats.drops += qstats->drops;
468 + qopt.prio_group_A = priv->prio.tx_prio_cfg.prio_group_A;
469 + qopt.prio_group_B = priv->prio.tx_prio_cfg.prio_group_B;
470 + qopt.separate_groups = priv->prio.tx_prio_cfg.separate_groups;
474 + pr_err(KBUILD_BASENAME " : %s : invalid qdisc\n", __func__);
475 + sch_tree_unlock(sch);
479 + nest = nla_nest_start(skb, TCA_OPTIONS);
481 + goto nla_put_failure;
482 + if (nla_put(skb, DPAA2_CEETM_TCA_QOPS, sizeof(qopt), &qopt))
483 + goto nla_put_failure;
484 + nla_nest_end(skb, nest);
486 + sch_tree_unlock(sch);
490 + sch_tree_unlock(sch);
491 + nla_nest_cancel(skb, nest);
495 +static int dpaa2_ceetm_change_prio(struct Qdisc *sch,
496 + struct dpaa2_ceetm_qdisc *priv,
497 + struct dpaa2_ceetm_tc_qopt *qopt)
499 + /* TODO: Once LX2 support is added */
500 + /* priv->shaped = parent_cl->shaped; */
501 + priv->prio.tx_prio_cfg.prio_group_A = qopt->prio_group_A;
502 + priv->prio.tx_prio_cfg.prio_group_B = qopt->prio_group_B;
503 + priv->prio.tx_prio_cfg.separate_groups = qopt->separate_groups;
508 +/* Edit a ceetm qdisc */
509 +static int dpaa2_ceetm_change(struct Qdisc *sch, struct nlattr *opt)
511 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
512 + struct nlattr *tb[DPAA2_CEETM_TCA_QOPS + 1];
513 + struct dpaa2_ceetm_tc_qopt *qopt;
516 + pr_debug(KBUILD_BASENAME " : %s : qdisc %X\n", __func__, sch->handle);
518 + err = nla_parse_nested(tb, DPAA2_CEETM_TCA_QOPS, opt,
519 + dpaa2_ceetm_policy, NULL);
521 + pr_err(KBUILD_BASENAME " : %s : tc error in %s\n", __func__,
522 + "nla_parse_nested");
526 + if (!tb[DPAA2_CEETM_TCA_QOPS]) {
527 + pr_err(KBUILD_BASENAME " : %s : tc error in %s\n", __func__,
532 + if (TC_H_MIN(sch->handle)) {
533 + pr_err("CEETM: a qdisc should not have a minor\n");
537 + qopt = nla_data(tb[DPAA2_CEETM_TCA_QOPS]);
539 + if (priv->type != qopt->type) {
540 + pr_err("CEETM: qdisc %X is not of the provided type\n",
545 + switch (priv->type) {
547 + err = dpaa2_ceetm_change_prio(sch, priv, qopt);
550 + pr_err(KBUILD_BASENAME " : %s : invalid qdisc\n", __func__);
557 +/* Configure a root ceetm qdisc */
558 +static int dpaa2_ceetm_init_root(struct Qdisc *sch,
559 + struct dpaa2_ceetm_qdisc *priv,
560 + struct dpaa2_ceetm_tc_qopt *qopt)
562 + struct net_device *dev = qdisc_dev(sch);
563 + struct dpaa2_eth_priv *priv_eth = netdev_priv(dev);
564 + struct netdev_queue *dev_queue;
565 + unsigned int i, parent_id;
566 + struct Qdisc *qdisc;
569 + pr_debug(KBUILD_BASENAME " : %s : qdisc %X\n", __func__, sch->handle);
571 + /* Validate inputs */
572 + if (sch->parent != TC_H_ROOT) {
573 + pr_err("CEETM: a root ceetm qdisc can not be attached to a class\n");
574 + tcf_block_put(priv->block);
575 + qdisc_class_hash_destroy(&priv->clhash);
579 + /* Pre-allocate underlying pfifo qdiscs.
581 + * We want to offload shaping and scheduling decisions to the hardware.
582 + * The pfifo qdiscs will be attached to the netdev queues and will
583 + * guide the traffic from the IP stack down to the driver with minimum
586 + * The CEETM qdiscs and classes will be crossed when the traffic
587 + * reaches the driver.
589 + priv->root.qdiscs = kcalloc(dev->num_tx_queues,
590 + sizeof(priv->root.qdiscs[0]),
592 + if (!priv->root.qdiscs) {
594 + goto err_init_root;
597 + for (i = 0; i < dev->num_tx_queues; i++) {
598 + dev_queue = netdev_get_tx_queue(dev, i);
599 + parent_id = TC_H_MAKE(TC_H_MAJ(sch->handle),
600 + TC_H_MIN(i + PFIFO_MIN_OFFSET));
602 + qdisc = qdisc_create_dflt(dev_queue, &pfifo_qdisc_ops,
606 + goto err_init_root;
609 + priv->root.qdiscs[i] = qdisc;
610 + qdisc->flags |= TCQ_F_ONETXQUEUE;
613 + sch->flags |= TCQ_F_MQROOT;
615 + priv->root.qstats = alloc_percpu(struct dpaa2_ceetm_qdisc_stats);
616 + if (!priv->root.qstats) {
617 + pr_err(KBUILD_BASENAME " : %s : alloc_percpu() failed\n",
620 + goto err_init_root;
623 + dpaa2_eth_ceetm_enable(priv_eth);
627 + dpaa2_ceetm_destroy(sch);
631 +/* Configure a prio ceetm qdisc */
632 +static int dpaa2_ceetm_init_prio(struct Qdisc *sch,
633 + struct dpaa2_ceetm_qdisc *priv,
634 + struct dpaa2_ceetm_tc_qopt *qopt)
636 + struct net_device *dev = qdisc_dev(sch);
637 + struct dpaa2_ceetm_class *parent_cl;
638 + struct Qdisc *parent_qdisc;
641 + pr_debug(KBUILD_BASENAME " : %s : qdisc %X\n", __func__, sch->handle);
643 + if (sch->parent == TC_H_ROOT) {
644 + pr_err("CEETM: a prio ceetm qdisc can not be root\n");
646 + goto err_init_prio;
649 + parent_qdisc = qdisc_lookup(dev, TC_H_MAJ(sch->parent));
650 + if (strcmp(parent_qdisc->ops->id, dpaa2_ceetm_qdisc_ops.id)) {
651 + pr_err("CEETM: a ceetm qdisc can not be attached to other qdisc/class types\n");
653 + goto err_init_prio;
656 + /* Obtain the parent root ceetm_class */
657 + parent_cl = dpaa2_ceetm_find(sch->parent, parent_qdisc);
659 + if (!parent_cl || parent_cl->type != CEETM_ROOT) {
660 + pr_err("CEETM: a prio ceetm qdiscs can be added only under a root ceetm class\n");
662 + goto err_init_prio;
665 + priv->prio.parent = parent_cl;
666 + parent_cl->child = sch;
668 + err = dpaa2_ceetm_change_prio(sch, priv, qopt);
673 + dpaa2_ceetm_destroy(sch);
677 +/* Configure a generic ceetm qdisc */
678 +static int dpaa2_ceetm_init(struct Qdisc *sch, struct nlattr *opt)
680 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
681 + struct net_device *dev = qdisc_dev(sch);
682 + struct nlattr *tb[DPAA2_CEETM_TCA_QOPS + 1];
683 + struct dpaa2_ceetm_tc_qopt *qopt;
686 + pr_debug(KBUILD_BASENAME " : %s : qdisc %X\n", __func__, sch->handle);
688 + if (!netif_is_multiqueue(dev))
689 + return -EOPNOTSUPP;
691 + err = tcf_block_get(&priv->block, &priv->filter_list);
693 + pr_err("CEETM: unable to get tcf_block\n");
698 + pr_err(KBUILD_BASENAME " : %s : tc error - opt = NULL\n",
703 + err = nla_parse_nested(tb, DPAA2_CEETM_TCA_QOPS, opt,
704 + dpaa2_ceetm_policy, NULL);
706 + pr_err(KBUILD_BASENAME " : %s : tc error in %s\n", __func__,
707 + "nla_parse_nested");
711 + if (!tb[DPAA2_CEETM_TCA_QOPS]) {
712 + pr_err(KBUILD_BASENAME " : %s : tc error in %s\n", __func__,
717 + if (TC_H_MIN(sch->handle)) {
718 + pr_err("CEETM: a qdisc should not have a minor\n");
722 + qopt = nla_data(tb[DPAA2_CEETM_TCA_QOPS]);
724 + /* Initialize the class hash list. Each qdisc has its own class hash */
725 + err = qdisc_class_hash_init(&priv->clhash);
727 + pr_err(KBUILD_BASENAME " : %s : qdisc_class_hash_init failed\n",
732 + priv->type = qopt->type;
733 + priv->shaped = qopt->shaped;
735 + switch (priv->type) {
737 + err = dpaa2_ceetm_init_root(sch, priv, qopt);
740 + err = dpaa2_ceetm_init_prio(sch, priv, qopt);
743 + pr_err(KBUILD_BASENAME " : %s : invalid qdisc\n", __func__);
744 + dpaa2_ceetm_destroy(sch);
751 +/* Attach the underlying pfifo qdiscs */
752 +static void dpaa2_ceetm_attach(struct Qdisc *sch)
754 + struct net_device *dev = qdisc_dev(sch);
755 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
756 + struct Qdisc *qdisc, *old_qdisc;
759 + pr_debug(KBUILD_BASENAME " : %s : qdisc %X\n", __func__, sch->handle);
761 + for (i = 0; i < dev->num_tx_queues; i++) {
762 + qdisc = priv->root.qdiscs[i];
763 + old_qdisc = dev_graft_qdisc(qdisc->dev_queue, qdisc);
765 + qdisc_destroy(old_qdisc);
768 + /* Remove the references to the pfifo qdiscs since the kernel will
769 + * destroy them when needed. No cleanup from our part is required from
772 + kfree(priv->root.qdiscs);
773 + priv->root.qdiscs = NULL;
776 +static unsigned long dpaa2_ceetm_cls_find(struct Qdisc *sch, u32 classid)
778 + struct dpaa2_ceetm_class *cl;
780 + pr_debug(KBUILD_BASENAME " : %s : classid %X from qdisc %X\n",
781 + __func__, classid, sch->handle);
782 + cl = dpaa2_ceetm_find(classid, sch);
784 + return (unsigned long)cl;
787 +static int dpaa2_ceetm_cls_change_root(struct dpaa2_ceetm_class *cl,
788 + struct dpaa2_ceetm_tc_copt *copt,
789 + struct net_device *dev)
791 + struct dpaa2_eth_priv *priv = netdev_priv(dev);
792 + struct dpni_tx_shaping_cfg scfg = { 0 }, ecfg = { 0 };
795 + pr_debug(KBUILD_BASENAME " : %s : class %X\n", __func__,
796 + cl->common.classid);
801 + if (dpaa2_eth_update_shaping_cfg(dev, copt->shaping_cfg,
805 + err = dpaa2_eth_set_ch_shaping(priv, &scfg, &ecfg,
806 + copt->shaping_cfg.coupled,
811 + memcpy(&cl->root.shaping_cfg, &copt->shaping_cfg,
812 + sizeof(struct dpaa2_ceetm_shaping_cfg));
817 +static int dpaa2_ceetm_cls_change_prio(struct dpaa2_ceetm_class *cl,
818 + struct dpaa2_ceetm_tc_copt *copt,
819 + struct net_device *dev)
821 + struct dpaa2_ceetm_qdisc *sch = qdisc_priv(cl->parent);
822 + struct dpni_tx_schedule_cfg *sched_cfg;
823 + struct dpaa2_eth_priv *priv = netdev_priv(dev);
826 + pr_debug(KBUILD_BASENAME " : %s : class %X mode %d weight %d\n",
827 + __func__, cl->common.classid, copt->mode, copt->weight);
829 + if (!cl->prio.cstats) {
830 + cl->prio.cstats = alloc_percpu(struct dpaa2_ceetm_class_stats);
831 + if (!cl->prio.cstats) {
832 + pr_err(KBUILD_BASENAME " : %s : alloc_percpu() failed\n",
838 + cl->prio.mode = copt->mode;
839 + cl->prio.weight = copt->weight;
841 + sched_cfg = &sch->prio.tx_prio_cfg.tc_sched[cl->prio.qpri];
843 + switch (copt->mode) {
844 + case STRICT_PRIORITY:
845 + sched_cfg->mode = DPNI_TX_SCHED_STRICT_PRIORITY;
848 + sched_cfg->mode = DPNI_TX_SCHED_WEIGHTED_A;
851 + sched_cfg->mode = DPNI_TX_SCHED_WEIGHTED_B;
855 + err = dpaa2_eth_update_tx_prio(priv, cl, DPAA2_ETH_ADD_CQ);
860 +/* Add a new ceetm class */
861 +static int dpaa2_ceetm_cls_add(struct Qdisc *sch, u32 classid,
862 + struct dpaa2_ceetm_tc_copt *copt,
863 + unsigned long *arg)
865 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
866 + struct net_device *dev = qdisc_dev(sch);
867 + struct dpaa2_eth_priv *priv_eth = netdev_priv(dev);
868 + struct dpaa2_ceetm_class *cl;
871 + if (copt->type == CEETM_ROOT &&
872 + priv->clhash.hashelems == dpaa2_eth_ch_count(priv_eth)) {
873 + pr_err("CEETM: only %d channel%s per DPNI allowed, sorry\n",
874 + dpaa2_eth_ch_count(priv_eth),
875 + dpaa2_eth_ch_count(priv_eth) == 1 ? "" : "s");
879 + if (copt->type == CEETM_PRIO &&
880 + priv->clhash.hashelems == dpaa2_eth_tc_count(priv_eth)) {
881 + pr_err("CEETM: only %d queue%s per channel allowed, sorry\n",
882 + dpaa2_eth_tc_count(priv_eth),
883 + dpaa2_eth_tc_count(priv_eth) == 1 ? "" : "s");
887 + cl = kzalloc(sizeof(*cl), GFP_KERNEL);
891 + err = tcf_block_get(&cl->block, &cl->filter_list);
893 + pr_err("%s: Unable to set new root class\n", __func__);
897 + cl->common.classid = classid;
901 + /* Add class handle in Qdisc */
902 + dpaa2_ceetm_link_class(sch, &priv->clhash, &cl->common);
904 + cl->shaped = copt->shaped;
905 + cl->type = copt->type;
907 + /* Claim a CEETM channel / tc - DPAA2. will assume transition from
908 + * classid to qdid/qpri, starting from qdid / qpri 0
910 + switch (copt->type) {
912 + cl->root.ch_id = classid - sch->handle - 1;
913 + err = dpaa2_ceetm_cls_change_root(cl, copt, dev);
916 + cl->prio.qpri = classid - sch->handle - 1;
917 + err = dpaa2_ceetm_cls_change_prio(cl, copt, dev);
922 + pr_err("%s: Unable to set new %s class\n", __func__,
923 + (copt->type == CEETM_ROOT ? "root" : "prio"));
927 + switch (copt->type) {
929 + pr_debug(KBUILD_BASENAME " : %s : configured root class %X associated with channel qdid %d\n",
930 + __func__, classid, cl->root.ch_id);
933 + pr_debug(KBUILD_BASENAME " : %s : configured prio class %X associated with queue qpri %d\n",
934 + __func__, classid, cl->prio.qpri);
938 + *arg = (unsigned long)cl;
946 +/* Add or configure a ceetm class */
947 +static int dpaa2_ceetm_cls_change(struct Qdisc *sch, u32 classid, u32 parentid,
948 + struct nlattr **tca, unsigned long *arg)
950 + struct dpaa2_ceetm_qdisc *priv;
951 + struct dpaa2_ceetm_class *cl = (struct dpaa2_ceetm_class *)*arg;
952 + struct nlattr *opt = tca[TCA_OPTIONS];
953 + struct nlattr *tb[DPAA2_CEETM_TCA_MAX];
954 + struct dpaa2_ceetm_tc_copt *copt;
955 + struct net_device *dev = qdisc_dev(sch);
958 + pr_debug(KBUILD_BASENAME " : %s : classid %X under qdisc %X\n",
959 + __func__, classid, sch->handle);
961 + if (strcmp(sch->ops->id, dpaa2_ceetm_qdisc_ops.id)) {
962 + pr_err("CEETM: a ceetm class can not be attached to other qdisc/class types\n");
966 + priv = qdisc_priv(sch);
969 + pr_err(KBUILD_BASENAME " : %s : tc error NULL opt\n", __func__);
973 + err = nla_parse_nested(tb, DPAA2_CEETM_TCA_COPT, opt,
974 + dpaa2_ceetm_policy, NULL);
976 + pr_err(KBUILD_BASENAME " : %s : tc error in %s\n", __func__,
977 + "nla_parse_nested");
981 + if (!tb[DPAA2_CEETM_TCA_COPT]) {
982 + pr_err(KBUILD_BASENAME " : %s : tc error in %s\n", __func__,
987 + copt = nla_data(tb[DPAA2_CEETM_TCA_COPT]);
989 + /* Configure an existing ceetm class */
991 + if (copt->type != cl->type) {
992 + pr_err("CEETM: class %X is not of the provided type\n",
993 + cl->common.classid);
997 + switch (copt->type) {
999 + return dpaa2_ceetm_cls_change_root(cl, copt, dev);
1001 + return dpaa2_ceetm_cls_change_prio(cl, copt, dev);
1004 + pr_err(KBUILD_BASENAME " : %s : invalid class\n",
1010 + return dpaa2_ceetm_cls_add(sch, classid, copt, arg);
1013 +static void dpaa2_ceetm_cls_walk(struct Qdisc *sch, struct qdisc_walker *arg)
1015 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
1016 + struct dpaa2_ceetm_class *cl;
1019 + pr_debug(KBUILD_BASENAME " : %s : qdisc %X\n", __func__, sch->handle);
1024 + for (i = 0; i < priv->clhash.hashsize; i++) {
1025 + hlist_for_each_entry(cl, &priv->clhash.hash[i], common.hnode) {
1026 + if (arg->count < arg->skip) {
1030 + if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
1039 +static int dpaa2_ceetm_cls_dump(struct Qdisc *sch, unsigned long arg,
1040 + struct sk_buff *skb, struct tcmsg *tcm)
1042 + struct dpaa2_ceetm_class *cl = (struct dpaa2_ceetm_class *)arg;
1043 + struct nlattr *nest;
1044 + struct dpaa2_ceetm_tc_copt copt;
1046 + pr_debug(KBUILD_BASENAME " : %s : class %X under qdisc %X\n",
1047 + __func__, cl->common.classid, sch->handle);
1049 + sch_tree_lock(sch);
1051 + tcm->tcm_parent = ((struct Qdisc *)cl->parent)->handle;
1052 + tcm->tcm_handle = cl->common.classid;
1054 + memset(&copt, 0, sizeof(copt));
1056 + copt.shaped = cl->shaped;
1057 + copt.type = cl->type;
1059 + switch (cl->type) {
1062 + tcm->tcm_info = cl->child->handle;
1064 + memcpy(&copt.shaping_cfg, &cl->root.shaping_cfg,
1065 + sizeof(struct dpaa2_ceetm_shaping_cfg));
1071 + tcm->tcm_info = cl->child->handle;
1073 + copt.mode = cl->prio.mode;
1074 + copt.weight = cl->prio.weight;
1079 + nest = nla_nest_start(skb, TCA_OPTIONS);
1081 + goto nla_put_failure;
1082 + if (nla_put(skb, DPAA2_CEETM_TCA_COPT, sizeof(copt), &copt))
1083 + goto nla_put_failure;
1084 + nla_nest_end(skb, nest);
1085 + sch_tree_unlock(sch);
1089 + sch_tree_unlock(sch);
1090 + nla_nest_cancel(skb, nest);
1094 +static int dpaa2_ceetm_cls_delete(struct Qdisc *sch, unsigned long arg)
1096 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
1097 + struct dpaa2_ceetm_class *cl = (struct dpaa2_ceetm_class *)arg;
1099 + pr_debug(KBUILD_BASENAME " : %s : class %X under qdisc %X\n",
1100 + __func__, cl->common.classid, sch->handle);
1102 + sch_tree_lock(sch);
1103 + qdisc_class_hash_remove(&priv->clhash, &cl->common);
1104 + sch_tree_unlock(sch);
1108 +/* Get the class' child qdisc, if any */
1109 +static struct Qdisc *dpaa2_ceetm_cls_leaf(struct Qdisc *sch, unsigned long arg)
1111 + struct dpaa2_ceetm_class *cl = (struct dpaa2_ceetm_class *)arg;
1113 + pr_debug(KBUILD_BASENAME " : %s : class %X under qdisc %X\n",
1114 + __func__, cl->common.classid, sch->handle);
1116 + switch (cl->type) {
1125 +static int dpaa2_ceetm_cls_graft(struct Qdisc *sch, unsigned long arg,
1126 + struct Qdisc *new, struct Qdisc **old)
1128 + if (new && strcmp(new->ops->id, dpaa2_ceetm_qdisc_ops.id)) {
1129 + pr_err("CEETM: only ceetm qdiscs can be attached to ceetm classes\n");
1130 + return -EOPNOTSUPP;
1136 +static int dpaa2_ceetm_cls_dump_stats(struct Qdisc *sch, unsigned long arg,
1137 + struct gnet_dump *d)
1139 + struct dpaa2_ceetm_class *cl = (struct dpaa2_ceetm_class *)arg;
1140 + struct gnet_stats_basic_packed tmp_bstats;
1141 + struct dpaa2_ceetm_tc_xstats xstats;
1142 + union dpni_statistics dpni_stats;
1143 + struct net_device *dev = qdisc_dev(sch);
1144 + struct dpaa2_eth_priv *priv_eth = netdev_priv(dev);
1148 + memset(&xstats, 0, sizeof(xstats));
1149 + memset(&tmp_bstats, 0, sizeof(tmp_bstats));
1151 + if (cl->type == CEETM_ROOT)
1154 + err = dpni_get_statistics(priv_eth->mc_io, 0, priv_eth->mc_token, 3,
1155 + DPNI_BUILD_CH_TC(ch_id, cl->prio.qpri),
1158 + netdev_warn(dev, "dpni_get_stats(%d) failed - %d\n", 3, err);
1160 + xstats.ceetm_dequeue_bytes = dpni_stats.page_3.ceetm_dequeue_bytes;
1161 + xstats.ceetm_dequeue_frames = dpni_stats.page_3.ceetm_dequeue_frames;
1162 + xstats.ceetm_reject_bytes = dpni_stats.page_3.ceetm_reject_bytes;
1163 + xstats.ceetm_reject_frames = dpni_stats.page_3.ceetm_reject_frames;
1165 + return gnet_stats_copy_app(d, &xstats, sizeof(xstats));
1168 +static struct tcf_block *dpaa2_ceetm_tcf_block(struct Qdisc *sch,
1169 + unsigned long arg)
1171 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
1172 + struct dpaa2_ceetm_class *cl = (struct dpaa2_ceetm_class *)arg;
1174 + pr_debug(KBUILD_BASENAME " : %s : class %X under qdisc %X\n", __func__,
1175 + cl ? cl->common.classid : 0, sch->handle);
1176 + return cl ? cl->block : priv->block;
1179 +static unsigned long dpaa2_ceetm_tcf_bind(struct Qdisc *sch,
1180 + unsigned long parent,
1183 + struct dpaa2_ceetm_class *cl = dpaa2_ceetm_find(classid, sch);
1185 + pr_debug(KBUILD_BASENAME " : %s : class %X under qdisc %X\n", __func__,
1186 + cl ? cl->common.classid : 0, sch->handle);
1187 + return (unsigned long)cl;
1190 +static void dpaa2_ceetm_tcf_unbind(struct Qdisc *sch, unsigned long arg)
1192 + struct dpaa2_ceetm_class *cl = (struct dpaa2_ceetm_class *)arg;
1194 + pr_debug(KBUILD_BASENAME " : %s : class %X under qdisc %X\n", __func__,
1195 + cl ? cl->common.classid : 0, sch->handle);
1198 +const struct Qdisc_class_ops dpaa2_ceetm_cls_ops = {
1199 + .graft = dpaa2_ceetm_cls_graft,
1200 + .leaf = dpaa2_ceetm_cls_leaf,
1201 + .find = dpaa2_ceetm_cls_find,
1202 + .change = dpaa2_ceetm_cls_change,
1203 + .delete = dpaa2_ceetm_cls_delete,
1204 + .walk = dpaa2_ceetm_cls_walk,
1205 + .tcf_block = dpaa2_ceetm_tcf_block,
1206 + .bind_tcf = dpaa2_ceetm_tcf_bind,
1207 + .unbind_tcf = dpaa2_ceetm_tcf_unbind,
1208 + .dump = dpaa2_ceetm_cls_dump,
1209 + .dump_stats = dpaa2_ceetm_cls_dump_stats,
1212 +struct Qdisc_ops dpaa2_ceetm_qdisc_ops __read_mostly = {
1214 + .priv_size = sizeof(struct dpaa2_ceetm_qdisc),
1215 + .cl_ops = &dpaa2_ceetm_cls_ops,
1216 + .init = dpaa2_ceetm_init,
1217 + .destroy = dpaa2_ceetm_destroy,
1218 + .change = dpaa2_ceetm_change,
1219 + .dump = dpaa2_ceetm_dump,
1220 + .attach = dpaa2_ceetm_attach,
1221 + .owner = THIS_MODULE,
1224 +/* Run the filters and classifiers attached to the qdisc on the provided skb */
1225 +int dpaa2_ceetm_classify(struct sk_buff *skb, struct Qdisc *sch,
1226 + int *qdid, u8 *qpri)
1228 + struct dpaa2_ceetm_qdisc *priv = qdisc_priv(sch);
1229 + struct dpaa2_ceetm_class *cl = NULL;
1230 + struct tcf_result res;
1231 + struct tcf_proto *tcf;
1234 + tcf = rcu_dereference_bh(priv->filter_list);
1235 + while (tcf && (result = tcf_classify(skb, tcf, &res, false)) >= 0) {
1236 +#ifdef CONFIG_NET_CLS_ACT
1238 + case TC_ACT_QUEUED:
1239 + case TC_ACT_STOLEN:
1241 + /* No valid class found due to action */
1245 + cl = (void *)res.class;
1247 + /* The filter leads to the qdisc */
1248 + if (res.classid == sch->handle)
1251 + cl = dpaa2_ceetm_find(res.classid, sch);
1252 + /* The filter leads to an invalid class */
1257 + /* The class might have its own filters attached */
1258 + tcf = rcu_dereference_bh(cl->filter_list);
1261 + /* No valid class found */
1265 + switch (cl->type) {
1267 + *qdid = cl->root.ch_id;
1269 + /* The root class does not have a child prio qdisc */
1273 + /* Run the prio qdisc classifiers */
1274 + return dpaa2_ceetm_classify(skb, cl->child, qdid, qpri);
1277 + *qpri = cl->prio.qpri;
1284 +int __init dpaa2_ceetm_register(void)
1288 + pr_debug(KBUILD_MODNAME ": " DPAA2_CEETM_DESCRIPTION "\n");
1290 + err = register_qdisc(&dpaa2_ceetm_qdisc_ops);
1291 + if (unlikely(err))
1292 + pr_err(KBUILD_MODNAME
1293 + ": %s:%hu:%s(): register_qdisc() = %d\n",
1294 + KBUILD_BASENAME ".c", __LINE__, __func__, err);
1299 +void __exit dpaa2_ceetm_unregister(void)
1301 + pr_debug(KBUILD_MODNAME ": %s:%s() ->\n",
1302 + KBUILD_BASENAME ".c", __func__);
1304 + unregister_qdisc(&dpaa2_ceetm_qdisc_ops);
1307 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-ceetm.h
1309 +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1311 + * Copyright 2017 NXP
1315 +#ifndef __DPAA2_ETH_CEETM_H
1316 +#define __DPAA2_ETH_CEETM_H
1318 +#include <net/pkt_sched.h>
1319 +#include <net/pkt_cls.h>
1320 +#include <net/netlink.h>
1322 +#include "dpaa2-eth.h"
1324 +/* For functional purposes, there are num_tx_queues pfifo qdiscs through which
1325 + * frames reach the driver. Their handles start from 1:21. Handles 1:1 to 1:20
1326 + * are reserved for the maximum 32 CEETM channels (majors and minors are in
1329 +#define PFIFO_MIN_OFFSET 0x21
1331 +#define DPAA2_CEETM_MIN_WEIGHT 100
1332 +#define DPAA2_CEETM_MAX_WEIGHT 24800
1334 +#define DPAA2_CEETM_TD_THRESHOLD 1000
1336 +enum wbfs_group_type {
1343 + DPAA2_CEETM_TCA_UNSPEC,
1344 + DPAA2_CEETM_TCA_COPT,
1345 + DPAA2_CEETM_TCA_QOPS,
1346 + DPAA2_CEETM_TCA_MAX,
1349 +/* CEETM configuration types */
1350 +enum dpaa2_ceetm_type {
1356 + STRICT_PRIORITY = 0,
1361 +struct dpaa2_ceetm_shaping_cfg {
1362 + __u64 cir; /* committed information rate */
1363 + __u64 eir; /* excess information rate */
1364 + __u16 cbs; /* committed burst size */
1365 + __u16 ebs; /* excess burst size */
1366 + __u8 coupled; /* shaper coupling */
1369 +extern const struct nla_policy ceetm_policy[DPAA2_CEETM_TCA_MAX];
1371 +struct dpaa2_ceetm_class;
1372 +struct dpaa2_ceetm_qdisc_stats;
1373 +struct dpaa2_ceetm_class_stats;
1375 +/* corresponds to CEETM shaping at LNI level */
1376 +struct dpaa2_root_q {
1377 + struct Qdisc **qdiscs;
1378 + struct dpaa2_ceetm_qdisc_stats __percpu *qstats;
1381 +/* corresponds to the number of priorities a channel serves */
1382 +struct dpaa2_prio_q {
1383 + struct dpaa2_ceetm_class *parent;
1384 + struct dpni_tx_priorities_cfg tx_prio_cfg;
1387 +struct dpaa2_ceetm_qdisc {
1388 + struct Qdisc_class_hash clhash;
1389 + struct tcf_proto *filter_list; /* qdisc attached filters */
1390 + struct tcf_block *block;
1392 + enum dpaa2_ceetm_type type; /* ROOT/PRIO */
1395 + struct dpaa2_root_q root;
1396 + struct dpaa2_prio_q prio;
1400 +/* CEETM Qdisc configuration parameters */
1401 +struct dpaa2_ceetm_tc_qopt {
1402 + enum dpaa2_ceetm_type type;
1404 + __u8 prio_group_A;
1405 + __u8 prio_group_B;
1406 + __u8 separate_groups;
1409 +/* root class - corresponds to a channel */
1410 +struct dpaa2_root_c {
1411 + struct dpaa2_ceetm_shaping_cfg shaping_cfg;
1415 +/* prio class - corresponds to a strict priority queue (group) */
1416 +struct dpaa2_prio_c {
1417 + struct dpaa2_ceetm_class_stats __percpu *cstats;
1423 +struct dpaa2_ceetm_class {
1424 + struct Qdisc_class_common common;
1425 + struct tcf_proto *filter_list; /* class attached filters */
1426 + struct tcf_block *block;
1427 + struct Qdisc *parent;
1428 + struct Qdisc *child;
1430 + enum dpaa2_ceetm_type type; /* ROOT/PRIO */
1433 + struct dpaa2_root_c root;
1434 + struct dpaa2_prio_c prio;
1438 +/* CEETM Class configuration parameters */
1439 +struct dpaa2_ceetm_tc_copt {
1440 + enum dpaa2_ceetm_type type;
1441 + struct dpaa2_ceetm_shaping_cfg shaping_cfg;
1448 +struct dpaa2_ceetm_qdisc_stats {
1452 +struct dpaa2_ceetm_class_stats {
1453 + /* Software counters */
1454 + struct gnet_stats_basic_packed bstats;
1455 + __u32 ern_drop_count;
1456 + __u32 congested_count;
1459 +struct dpaa2_ceetm_tc_xstats {
1460 + __u64 ceetm_dequeue_bytes;
1461 + __u64 ceetm_dequeue_frames;
1462 + __u64 ceetm_reject_bytes;
1463 + __u64 ceetm_reject_frames;
1466 +#ifdef CONFIG_FSL_DPAA2_ETH_CEETM
1467 +int __init dpaa2_ceetm_register(void);
1468 +void __exit dpaa2_ceetm_unregister(void);
1469 +int dpaa2_ceetm_classify(struct sk_buff *skb, struct Qdisc *sch,
1470 + int *qdid, u8 *qpri);
1472 +static inline int dpaa2_ceetm_register(void)
1477 +static inline void dpaa2_ceetm_unregister(void) {}
1479 +static inline int dpaa2_ceetm_classify(struct sk_buff *skb, struct Qdisc *sch,
1480 + int *qdid, u8 *qpri)
1486 +static inline bool dpaa2_eth_ceetm_is_enabled(struct dpaa2_eth_priv *priv)
1488 + return priv->ceetm_en;
1493 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-debugfs.c
1496 +/* Copyright 2015 Freescale Semiconductor Inc.
1498 + * Redistribution and use in source and binary forms, with or without
1499 + * modification, are permitted provided that the following conditions are met:
1500 + * * Redistributions of source code must retain the above copyright
1501 + * notice, this list of conditions and the following disclaimer.
1502 + * * Redistributions in binary form must reproduce the above copyright
1503 + * notice, this list of conditions and the following disclaimer in the
1504 + * documentation and/or other materials provided with the distribution.
1505 + * * Neither the name of Freescale Semiconductor nor the
1506 + * names of its contributors may be used to endorse or promote products
1507 + * derived from this software without specific prior written permission.
1510 + * ALTERNATIVELY, this software may be distributed under the terms of the
1511 + * GNU General Public License ("GPL") as published by the Free Software
1512 + * Foundation, either version 2 of that License or (at your option) any
1515 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
1516 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1517 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1518 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
1519 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1520 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1521 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1522 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1523 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1524 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1527 +#include <linux/module.h>
1528 +#include <linux/debugfs.h>
1529 +#include "dpaa2-eth.h"
1530 +#include "dpaa2-eth-debugfs.h"
1532 +#define DPAA2_ETH_DBG_ROOT "dpaa2-eth"
1534 +static struct dentry *dpaa2_dbg_root;
1536 +static int dpaa2_dbg_cpu_show(struct seq_file *file, void *offset)
1538 + struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
1539 + struct rtnl_link_stats64 *stats;
1540 + struct dpaa2_eth_drv_stats *extras;
1543 + seq_printf(file, "Per-CPU stats for %s\n", priv->net_dev->name);
1544 + seq_printf(file, "%s%16s%16s%16s%16s%16s%16s%16s%16s%16s\n",
1545 + "CPU", "Rx", "Rx Err", "Rx SG", "Tx", "Tx Err", "Tx conf",
1546 + "Tx SG", "Tx realloc", "Enq busy");
1548 + for_each_online_cpu(i) {
1549 + stats = per_cpu_ptr(priv->percpu_stats, i);
1550 + extras = per_cpu_ptr(priv->percpu_extras, i);
1551 + seq_printf(file, "%3d%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu%16llu\n",
1553 + stats->rx_packets,
1555 + extras->rx_sg_frames,
1556 + stats->tx_packets,
1558 + extras->tx_conf_frames,
1559 + extras->tx_sg_frames,
1560 + extras->tx_reallocs,
1561 + extras->tx_portal_busy);
1567 +static int dpaa2_dbg_cpu_open(struct inode *inode, struct file *file)
1570 + struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;
1572 + err = single_open(file, dpaa2_dbg_cpu_show, priv);
1574 + netdev_err(priv->net_dev, "single_open() failed\n");
1579 +static const struct file_operations dpaa2_dbg_cpu_ops = {
1580 + .open = dpaa2_dbg_cpu_open,
1582 + .llseek = seq_lseek,
1583 + .release = single_release,
1586 +static char *fq_type_to_str(struct dpaa2_eth_fq *fq)
1588 + switch (fq->type) {
1591 + case DPAA2_TX_CONF_FQ:
1593 + case DPAA2_RX_ERR_FQ:
1600 +static int dpaa2_dbg_fqs_show(struct seq_file *file, void *offset)
1602 + struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
1603 + struct dpaa2_eth_fq *fq;
1607 + seq_printf(file, "non-zero FQ stats for %s:\n", priv->net_dev->name);
1608 + seq_printf(file, "%s%16s%16s%16s%16s%16s%16s\n",
1609 + "VFQID", "CPU", "Traffic Class", "Type", "Frames",
1610 + "Pending frames", "Congestion");
1612 + for (i = 0; i < priv->num_fqs; i++) {
1613 + fq = &priv->fq[i];
1614 + err = dpaa2_io_query_fq_count(NULL, fq->fqid, &fcnt, &bcnt);
1618 + /* A lot of queues, no use displaying zero traffic ones */
1619 + if (!fq->stats.frames && !fcnt)
1622 + seq_printf(file, "%5d%16d%16d%16s%16llu%16u%16llu\n",
1626 + fq_type_to_str(fq),
1629 + fq->stats.congestion_entry);
1635 +static int dpaa2_dbg_fqs_open(struct inode *inode, struct file *file)
1638 + struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;
1640 + err = single_open(file, dpaa2_dbg_fqs_show, priv);
1642 + netdev_err(priv->net_dev, "single_open() failed\n");
1647 +static const struct file_operations dpaa2_dbg_fq_ops = {
1648 + .open = dpaa2_dbg_fqs_open,
1650 + .llseek = seq_lseek,
1651 + .release = single_release,
1654 +static int dpaa2_dbg_ch_show(struct seq_file *file, void *offset)
1656 + struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)file->private;
1657 + struct dpaa2_eth_channel *ch;
1660 + seq_printf(file, "Channel stats for %s:\n", priv->net_dev->name);
1661 + seq_printf(file, "%s%16s%16s%16s%16s%16s%16s\n",
1662 + "CHID", "CPU", "Deq busy", "Frames", "CDANs",
1663 + "Avg frm/CDAN", "Buf count");
1665 + for (i = 0; i < priv->num_channels; i++) {
1666 + ch = priv->channel[i];
1667 + seq_printf(file, "%4d%16d%16llu%16llu%16llu%16llu%16d\n",
1669 + ch->nctx.desired_cpu,
1670 + ch->stats.dequeue_portal_busy,
1673 + ch->stats.frames / ch->stats.cdan,
1680 +static int dpaa2_dbg_ch_open(struct inode *inode, struct file *file)
1683 + struct dpaa2_eth_priv *priv = (struct dpaa2_eth_priv *)inode->i_private;
1685 + err = single_open(file, dpaa2_dbg_ch_show, priv);
1687 + netdev_err(priv->net_dev, "single_open() failed\n");
1692 +static const struct file_operations dpaa2_dbg_ch_ops = {
1693 + .open = dpaa2_dbg_ch_open,
1695 + .llseek = seq_lseek,
1696 + .release = single_release,
1699 +static ssize_t dpaa2_dbg_reset_write(struct file *file, const char __user *buf,
1700 + size_t count, loff_t *offset)
1702 + struct dpaa2_eth_priv *priv = file->private_data;
1703 + struct rtnl_link_stats64 *percpu_stats;
1704 + struct dpaa2_eth_drv_stats *percpu_extras;
1705 + struct dpaa2_eth_fq *fq;
1706 + struct dpaa2_eth_channel *ch;
1709 + for_each_online_cpu(i) {
1710 + percpu_stats = per_cpu_ptr(priv->percpu_stats, i);
1711 + memset(percpu_stats, 0, sizeof(*percpu_stats));
1713 + percpu_extras = per_cpu_ptr(priv->percpu_extras, i);
1714 + memset(percpu_extras, 0, sizeof(*percpu_extras));
1717 + for (i = 0; i < priv->num_fqs; i++) {
1718 + fq = &priv->fq[i];
1719 + memset(&fq->stats, 0, sizeof(fq->stats));
1722 + for (i = 0; i < priv->num_channels; i++) {
1723 + ch = priv->channel[i];
1724 + memset(&ch->stats, 0, sizeof(ch->stats));
1730 +static const struct file_operations dpaa2_dbg_reset_ops = {
1731 + .open = simple_open,
1732 + .write = dpaa2_dbg_reset_write,
1735 +static ssize_t dpaa2_dbg_reset_mc_write(struct file *file,
1736 + const char __user *buf,
1737 + size_t count, loff_t *offset)
1739 + struct dpaa2_eth_priv *priv = file->private_data;
1742 + err = dpni_reset_statistics(priv->mc_io, 0, priv->mc_token);
1744 + netdev_err(priv->net_dev,
1745 + "dpni_reset_statistics() failed %d\n", err);
1750 +static const struct file_operations dpaa2_dbg_reset_mc_ops = {
1751 + .open = simple_open,
1752 + .write = dpaa2_dbg_reset_mc_write,
1755 +void dpaa2_dbg_add(struct dpaa2_eth_priv *priv)
1757 + if (!dpaa2_dbg_root)
1760 + /* Create a directory for the interface */
1761 + priv->dbg.dir = debugfs_create_dir(priv->net_dev->name,
1763 + if (!priv->dbg.dir) {
1764 + netdev_err(priv->net_dev, "debugfs_create_dir() failed\n");
1768 + /* per-cpu stats file */
1769 + priv->dbg.cpu_stats = debugfs_create_file("cpu_stats", 0444,
1770 + priv->dbg.dir, priv,
1771 + &dpaa2_dbg_cpu_ops);
1772 + if (!priv->dbg.cpu_stats) {
1773 + netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
1774 + goto err_cpu_stats;
1777 + /* per-fq stats file */
1778 + priv->dbg.fq_stats = debugfs_create_file("fq_stats", 0444,
1779 + priv->dbg.dir, priv,
1780 + &dpaa2_dbg_fq_ops);
1781 + if (!priv->dbg.fq_stats) {
1782 + netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
1783 + goto err_fq_stats;
1786 + /* per-fq stats file */
1787 + priv->dbg.ch_stats = debugfs_create_file("ch_stats", 0444,
1788 + priv->dbg.dir, priv,
1789 + &dpaa2_dbg_ch_ops);
1790 + if (!priv->dbg.fq_stats) {
1791 + netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
1792 + goto err_ch_stats;
1796 + priv->dbg.reset_stats = debugfs_create_file("reset_stats", 0200,
1797 + priv->dbg.dir, priv,
1798 + &dpaa2_dbg_reset_ops);
1799 + if (!priv->dbg.reset_stats) {
1800 + netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
1801 + goto err_reset_stats;
1804 + /* reset MC stats */
1805 + priv->dbg.reset_mc_stats = debugfs_create_file("reset_mc_stats",
1806 + 0222, priv->dbg.dir, priv,
1807 + &dpaa2_dbg_reset_mc_ops);
1808 + if (!priv->dbg.reset_mc_stats) {
1809 + netdev_err(priv->net_dev, "debugfs_create_file() failed\n");
1810 + goto err_reset_mc_stats;
1815 +err_reset_mc_stats:
1816 + debugfs_remove(priv->dbg.reset_stats);
1818 + debugfs_remove(priv->dbg.ch_stats);
1820 + debugfs_remove(priv->dbg.fq_stats);
1822 + debugfs_remove(priv->dbg.cpu_stats);
1824 + debugfs_remove(priv->dbg.dir);
1827 +void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv)
1829 + debugfs_remove(priv->dbg.reset_mc_stats);
1830 + debugfs_remove(priv->dbg.reset_stats);
1831 + debugfs_remove(priv->dbg.fq_stats);
1832 + debugfs_remove(priv->dbg.ch_stats);
1833 + debugfs_remove(priv->dbg.cpu_stats);
1834 + debugfs_remove(priv->dbg.dir);
1837 +void dpaa2_eth_dbg_init(void)
1839 + dpaa2_dbg_root = debugfs_create_dir(DPAA2_ETH_DBG_ROOT, NULL);
1840 + if (!dpaa2_dbg_root) {
1841 + pr_err("DPAA2-ETH: debugfs create failed\n");
1845 + pr_info("DPAA2-ETH: debugfs created\n");
1848 +void __exit dpaa2_eth_dbg_exit(void)
1850 + debugfs_remove(dpaa2_dbg_root);
1853 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth-debugfs.h
1855 +/* Copyright 2015 Freescale Semiconductor Inc.
1857 + * Redistribution and use in source and binary forms, with or without
1858 + * modification, are permitted provided that the following conditions are met:
1859 + * * Redistributions of source code must retain the above copyright
1860 + * notice, this list of conditions and the following disclaimer.
1861 + * * Redistributions in binary form must reproduce the above copyright
1862 + * notice, this list of conditions and the following disclaimer in the
1863 + * documentation and/or other materials provided with the distribution.
1864 + * * Neither the name of Freescale Semiconductor nor the
1865 + * names of its contributors may be used to endorse or promote products
1866 + * derived from this software without specific prior written permission.
1869 + * ALTERNATIVELY, this software may be distributed under the terms of the
1870 + * GNU General Public License ("GPL") as published by the Free Software
1871 + * Foundation, either version 2 of that License or (at your option) any
1874 + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
1875 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1876 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1877 + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
1878 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1879 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1880 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1881 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1882 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1883 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1886 +#ifndef DPAA2_ETH_DEBUGFS_H
1887 +#define DPAA2_ETH_DEBUGFS_H
1889 +#include <linux/dcache.h>
1891 +struct dpaa2_eth_priv;
1893 +struct dpaa2_debugfs {
1894 + struct dentry *dir;
1895 + struct dentry *fq_stats;
1896 + struct dentry *ch_stats;
1897 + struct dentry *cpu_stats;
1898 + struct dentry *reset_stats;
1899 + struct dentry *reset_mc_stats;
1902 +#ifdef CONFIG_FSL_DPAA2_ETH_DEBUGFS
1903 +void dpaa2_eth_dbg_init(void);
1904 +void dpaa2_eth_dbg_exit(void);
1905 +void dpaa2_dbg_add(struct dpaa2_eth_priv *priv);
1906 +void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv);
1908 +static inline void dpaa2_eth_dbg_init(void) {}
1909 +static inline void dpaa2_eth_dbg_exit(void) {}
1910 +static inline void dpaa2_dbg_add(struct dpaa2_eth_priv *priv) {}
1911 +static inline void dpaa2_dbg_remove(struct dpaa2_eth_priv *priv) {}
1912 +#endif /* CONFIG_FSL_DPAA2_ETH_DEBUGFS */
1914 +#endif /* DPAA2_ETH_DEBUGFS_H */
1915 --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
1916 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
1918 #include <linux/msi.h>
1919 #include <linux/kthread.h>
1920 #include <linux/iommu.h>
1922 +#include <linux/net_tstamp.h>
1923 +#include <linux/bpf.h>
1924 +#include <linux/filter.h>
1925 +#include <linux/atomic.h>
1926 +#include <net/sock.h>
1927 #include "../../fsl-mc/include/mc.h"
1928 #include "dpaa2-eth.h"
1929 +#include "dpaa2-eth-ceetm.h"
1931 /* CREATE_TRACE_POINTS only needs to be defined once. Other dpa files
1932 * using trace events only need to #include <trace/events/sched.h>
1933 @@ -104,13 +109,15 @@ static void free_rx_fd(struct dpaa2_eth_
1934 /* We don't support any other format */
1937 - /* For S/G frames, we first need to free all SG entries */
1938 + /* For S/G frames, we first need to free all SG entries
1939 + * except the first one, which was taken care of already
1941 sgt = vaddr + dpaa2_fd_get_offset(fd);
1942 - for (i = 0; i < DPAA2_ETH_MAX_SG_ENTRIES; i++) {
1943 + for (i = 1; i < DPAA2_ETH_MAX_SG_ENTRIES; i++) {
1944 addr = dpaa2_sg_get_addr(&sgt[i]);
1945 sg_vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr);
1946 dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE,
1948 + DMA_BIDIRECTIONAL);
1950 skb_free_frag(sg_vaddr);
1951 if (dpaa2_sg_is_final(&sgt[i]))
1952 @@ -133,8 +140,7 @@ static struct sk_buff *build_linear_skb(
1956 - skb = build_skb(fd_vaddr, DPAA2_ETH_RX_BUF_SIZE +
1957 - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
1958 + skb = build_skb(fd_vaddr, DPAA2_ETH_SKB_SIZE);
1962 @@ -170,15 +176,19 @@ static struct sk_buff *build_frag_skb(st
1963 sg_addr = dpaa2_sg_get_addr(sge);
1964 sg_vaddr = dpaa2_iova_to_virt(priv->iommu_domain, sg_addr);
1965 dma_unmap_single(dev, sg_addr, DPAA2_ETH_RX_BUF_SIZE,
1967 + DMA_BIDIRECTIONAL);
1969 sg_length = dpaa2_sg_get_len(sge);
1972 /* We build the skb around the first data buffer */
1973 - skb = build_skb(sg_vaddr, DPAA2_ETH_RX_BUF_SIZE +
1974 - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
1975 + skb = build_skb(sg_vaddr, DPAA2_ETH_SKB_SIZE);
1976 if (unlikely(!skb)) {
1977 + /* Free the first SG entry now, since we already
1978 + * unmapped it and obtained the virtual address
1980 + skb_free_frag(sg_vaddr);
1982 /* We still need to subtract the buffers used
1983 * by this FD from our software counter
1985 @@ -213,17 +223,173 @@ static struct sk_buff *build_frag_skb(st
1989 + WARN_ONCE(i == DPAA2_ETH_MAX_SG_ENTRIES, "Final bit not set in SGT");
1991 /* Count all data buffers + SG table buffer */
1992 ch->buf_count -= i + 2;
1997 +static int dpaa2_eth_xdp_tx(struct dpaa2_eth_priv *priv,
1998 + struct dpaa2_fd *fd,
2002 + struct dpaa2_eth_fq *fq;
2003 + struct rtnl_link_stats64 *percpu_stats;
2004 + struct dpaa2_eth_drv_stats *percpu_extras;
2005 + struct dpaa2_faead *faead;
2009 + /* Mark the egress frame annotation area as valid */
2010 + frc = dpaa2_fd_get_frc(fd);
2011 + dpaa2_fd_set_frc(fd, frc | DPAA2_FD_FRC_FAEADV);
2012 + dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_ASAL);
2014 + ctrl = DPAA2_FAEAD_A4V | DPAA2_FAEAD_A2V | DPAA2_FAEAD_EBDDV;
2015 + faead = dpaa2_get_faead(buf_start, false);
2016 + faead->ctrl = cpu_to_le32(ctrl);
2017 + faead->conf_fqid = 0;
2019 + percpu_stats = this_cpu_ptr(priv->percpu_stats);
2020 + percpu_extras = this_cpu_ptr(priv->percpu_extras);
2022 + fq = &priv->fq[queue_id];
2023 + for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) {
2024 + err = dpaa2_io_service_enqueue_qd(fq->channel->dpio,
2026 + fq->tx_qdbin, fd);
2027 + if (err != -EBUSY)
2031 + percpu_extras->tx_portal_busy += i;
2032 + if (unlikely(err)) {
2033 + percpu_stats->tx_errors++;
2035 + percpu_stats->tx_packets++;
2036 + percpu_stats->tx_bytes += dpaa2_fd_get_len(fd);
2042 +static void free_bufs(struct dpaa2_eth_priv *priv, u64 *buf_array, int count)
2044 + struct device *dev = priv->net_dev->dev.parent;
2048 + for (i = 0; i < count; i++) {
2049 + /* Same logic as on regular Rx path */
2050 + vaddr = dpaa2_iova_to_virt(priv->iommu_domain, buf_array[i]);
2051 + dma_unmap_single(dev, buf_array[i], DPAA2_ETH_RX_BUF_SIZE,
2052 + DMA_BIDIRECTIONAL);
2053 + skb_free_frag(vaddr);
2057 +static void release_fd_buf(struct dpaa2_eth_priv *priv,
2058 + struct dpaa2_eth_channel *ch,
2063 + ch->rel_buf_array[ch->rel_buf_cnt++] = addr;
2064 + if (likely(ch->rel_buf_cnt < DPAA2_ETH_BUFS_PER_CMD))
2067 + while ((err = dpaa2_io_service_release(ch->dpio, priv->bpid,
2068 + ch->rel_buf_array,
2069 + ch->rel_buf_cnt)) == -EBUSY)
2073 + free_bufs(priv, ch->rel_buf_array, ch->rel_buf_cnt);
2075 + ch->rel_buf_cnt = 0;
2078 +static u32 dpaa2_eth_run_xdp(struct dpaa2_eth_priv *priv,
2079 + struct dpaa2_eth_channel *ch,
2080 + struct dpaa2_fd *fd,
2084 + struct device *dev = priv->net_dev->dev.parent;
2085 + dma_addr_t addr = dpaa2_fd_get_addr(fd);
2086 + struct rtnl_link_stats64 *percpu_stats;
2087 + struct bpf_prog *xdp_prog;
2088 + struct xdp_buff xdp;
2089 + u32 xdp_act = XDP_PASS;
2091 + xdp_prog = READ_ONCE(ch->xdp_prog);
2095 + percpu_stats = this_cpu_ptr(priv->percpu_stats);
2097 + xdp.data = vaddr + dpaa2_fd_get_offset(fd);
2098 + xdp.data_end = xdp.data + dpaa2_fd_get_len(fd);
2099 + /* Allow the XDP program to use the specially reserved headroom */
2100 + xdp.data_hard_start = xdp.data - XDP_PACKET_HEADROOM;
2103 + xdp_act = bpf_prog_run_xdp(xdp_prog, &xdp);
2105 + /* xdp.data pointer may have changed */
2106 + dpaa2_fd_set_offset(fd, xdp.data - vaddr);
2107 + dpaa2_fd_set_len(fd, xdp.data_end - xdp.data);
2109 + switch (xdp_act) {
2113 + bpf_warn_invalid_xdp_action(xdp_act);
2116 + /* This is our buffer, so we can release it back to hardware */
2117 + release_fd_buf(priv, ch, addr);
2118 + percpu_stats->rx_dropped++;
2121 + if (dpaa2_eth_xdp_tx(priv, fd, vaddr, queue_id)) {
2122 + dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE,
2123 + DMA_BIDIRECTIONAL);
2124 + free_rx_fd(priv, fd, vaddr);
2128 + case XDP_REDIRECT:
2129 + dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE,
2130 + DMA_BIDIRECTIONAL);
2133 + /* Mark the actual start of the data buffer */
2134 + xdp.data_hard_start = vaddr;
2135 + if (xdp_do_redirect(priv->net_dev, &xdp, xdp_prog))
2136 + free_rx_fd(priv, fd, vaddr);
2140 + if (xdp_act == XDP_TX || xdp_act == XDP_REDIRECT) {
2141 + percpu_stats->rx_packets++;
2142 + percpu_stats->rx_bytes += dpaa2_fd_get_len(fd);
2145 + rcu_read_unlock();
2150 /* Main Rx frame processing routine */
2151 static void dpaa2_eth_rx(struct dpaa2_eth_priv *priv,
2152 struct dpaa2_eth_channel *ch,
2153 const struct dpaa2_fd *fd,
2154 - struct napi_struct *napi)
2155 + struct napi_struct *napi,
2158 dma_addr_t addr = dpaa2_fd_get_addr(fd);
2159 u8 fd_format = dpaa2_fd_get_format(fd);
2160 @@ -235,14 +401,16 @@ static void dpaa2_eth_rx(struct dpaa2_et
2161 struct dpaa2_fas *fas;
2167 trace_dpaa2_rx_fd(priv->net_dev, fd);
2169 vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr);
2170 - dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE, DMA_FROM_DEVICE);
2171 + dma_sync_single_for_cpu(dev, addr, DPAA2_ETH_RX_BUF_SIZE,
2172 + DMA_BIDIRECTIONAL);
2174 - fas = dpaa2_get_fas(vaddr);
2175 + fas = dpaa2_get_fas(vaddr, false);
2177 buf_data = vaddr + dpaa2_fd_get_offset(fd);
2179 @@ -251,22 +419,41 @@ static void dpaa2_eth_rx(struct dpaa2_et
2180 percpu_extras = this_cpu_ptr(priv->percpu_extras);
2182 if (fd_format == dpaa2_fd_single) {
2183 + xdp_act = dpaa2_eth_run_xdp(priv, ch, (struct dpaa2_fd *)fd,
2185 + if (xdp_act != XDP_PASS)
2188 + dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE,
2189 + DMA_BIDIRECTIONAL);
2190 skb = build_linear_skb(priv, ch, fd, vaddr);
2191 } else if (fd_format == dpaa2_fd_sg) {
2192 + dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE,
2193 + DMA_BIDIRECTIONAL);
2194 skb = build_frag_skb(priv, ch, buf_data);
2195 skb_free_frag(vaddr);
2196 percpu_extras->rx_sg_frames++;
2197 percpu_extras->rx_sg_bytes += dpaa2_fd_get_len(fd);
2199 /* We don't support any other format */
2200 - goto err_frame_format;
2205 - goto err_build_skb;
2208 prefetch(skb->data);
2210 + /* Get the timestamp value */
2211 + if (priv->ts_rx_en) {
2212 + struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
2213 + u64 *ns = dpaa2_get_ts(vaddr, false);
2215 + *ns = DPAA2_PTP_NOMINAL_FREQ_PERIOD_NS * le64_to_cpup(ns);
2216 + memset(shhwtstamps, 0, sizeof(*shhwtstamps));
2217 + shhwtstamps->hwtstamp = ns_to_ktime(*ns);
2220 /* Check if we need to validate the L4 csum */
2221 if (likely(dpaa2_fd_get_frc(fd) & DPAA2_FD_FRC_FASV)) {
2222 status = le32_to_cpu(fas->status);
2223 @@ -275,6 +462,12 @@ static void dpaa2_eth_rx(struct dpaa2_et
2225 skb->protocol = eth_type_trans(skb, priv->net_dev);
2227 + /* Record Rx queue - this will be used when picking a Tx queue to
2228 + * forward the frames. We're keeping flow affinity through the
2231 + skb_record_rx_queue(skb, queue_id);
2233 percpu_stats->rx_packets++;
2234 percpu_stats->rx_bytes += dpaa2_fd_get_len(fd);
2236 @@ -282,22 +475,74 @@ static void dpaa2_eth_rx(struct dpaa2_et
2242 free_rx_fd(priv, fd, vaddr);
2245 percpu_stats->rx_dropped++;
2248 +#ifdef CONFIG_FSL_DPAA2_ETH_USE_ERR_QUEUE
2249 +/* Processing of Rx frames received on the error FQ
2250 + * We check and print the error bits and then free the frame
2252 +static void dpaa2_eth_rx_err(struct dpaa2_eth_priv *priv,
2253 + struct dpaa2_eth_channel *ch,
2254 + const struct dpaa2_fd *fd,
2255 + struct napi_struct *napi __always_unused,
2256 + u16 queue_id __always_unused)
2258 + struct device *dev = priv->net_dev->dev.parent;
2259 + dma_addr_t addr = dpaa2_fd_get_addr(fd);
2261 + struct rtnl_link_stats64 *percpu_stats;
2262 + struct dpaa2_fas *fas;
2265 + bool has_fas_errors = false;
2267 + vaddr = dpaa2_iova_to_virt(priv->iommu_domain, addr);
2268 + dma_unmap_single(dev, addr, DPAA2_ETH_RX_BUF_SIZE, DMA_BIDIRECTIONAL);
2270 + /* check frame errors in the FD field */
2271 + fd_errors = dpaa2_fd_get_ctrl(fd) & DPAA2_FD_RX_ERR_MASK;
2272 + if (likely(fd_errors)) {
2273 + has_fas_errors = (fd_errors & FD_CTRL_FAERR) &&
2274 + !!(dpaa2_fd_get_frc(fd) & DPAA2_FD_FRC_FASV);
2275 + if (net_ratelimit())
2276 + netdev_dbg(priv->net_dev, "RX frame FD err: %08x\n",
2280 + /* check frame errors in the FAS field */
2281 + if (has_fas_errors) {
2282 + fas = dpaa2_get_fas(vaddr, false);
2283 + status = le32_to_cpu(fas->status);
2284 + if (net_ratelimit())
2285 + netdev_dbg(priv->net_dev, "Rx frame FAS err: 0x%08x\n",
2286 + status & DPAA2_FAS_RX_ERR_MASK);
2288 + free_rx_fd(priv, fd, vaddr);
2290 + percpu_stats = this_cpu_ptr(priv->percpu_stats);
2291 + percpu_stats->rx_errors++;
2296 /* Consume all frames pull-dequeued into the store. This is the simplest way to
2297 * make sure we don't accidentally issue another volatile dequeue which would
2298 * overwrite (leak) frames already in the store.
2300 + * The number of frames is returned using the last 2 output arguments,
2301 + * separately for Rx and Tx confirmations.
2303 * Observance of NAPI budget is not our concern, leaving that to the caller.
2305 -static int consume_frames(struct dpaa2_eth_channel *ch)
2306 +static bool consume_frames(struct dpaa2_eth_channel *ch, int *rx_cleaned,
2307 + int *tx_conf_cleaned)
2309 struct dpaa2_eth_priv *priv = ch->priv;
2310 - struct dpaa2_eth_fq *fq;
2311 + struct dpaa2_eth_fq *fq = NULL;
2312 struct dpaa2_dq *dq;
2313 const struct dpaa2_fd *fd;
2315 @@ -315,14 +560,60 @@ static int consume_frames(struct dpaa2_e
2318 fd = dpaa2_dq_fd(dq);
2319 - fq = (struct dpaa2_eth_fq *)(uintptr_t)dpaa2_dq_fqd_ctx(dq);
2320 - fq->stats.frames++;
2323 - fq->consume(priv, ch, fd, &ch->napi);
2324 + fq = (struct dpaa2_eth_fq *)(uintptr_t)dpaa2_dq_fqd_ctx(dq);
2325 + fq->consume(priv, ch, fd, &ch->napi, fq->flowid);
2333 + /* All frames brought in store by a volatile dequeue
2334 + * come from the same queue
2336 + if (fq->type == DPAA2_TX_CONF_FQ) {
2337 + *tx_conf_cleaned += cleaned;
2339 + *rx_cleaned += cleaned;
2340 + /* If we processed XDP_REDIRECT frames, flush them now */
2341 + /* FIXME: Since we don't actually do anything inside
2342 + * ndo_xdp_flush, we call it here simply for compliance
2346 + xdp_do_flush_map();
2347 + ch->flush = false;
2351 + fq->stats.frames += cleaned;
2352 + ch->stats.frames += cleaned;
2357 +/* Configure the egress frame annotation for timestamp update */
2358 +static void enable_tx_tstamp(struct dpaa2_fd *fd, void *buf_start)
2360 + struct dpaa2_faead *faead;
2363 + /* Mark the egress frame annotation area as valid */
2364 + frc = dpaa2_fd_get_frc(fd);
2365 + dpaa2_fd_set_frc(fd, frc | DPAA2_FD_FRC_FAEADV);
2367 + /* Set hardware annotation size */
2368 + ctrl = dpaa2_fd_get_ctrl(fd);
2369 + dpaa2_fd_set_ctrl(fd, ctrl | DPAA2_FD_CTRL_ASAL);
2371 + /* enable UPD (update prepanded data) bit in FAEAD field of
2372 + * hardware frame annotation area
2374 + ctrl = DPAA2_FAEAD_A2V | DPAA2_FAEAD_UPDV | DPAA2_FAEAD_UPD;
2375 + faead = dpaa2_get_faead(buf_start, true);
2376 + faead->ctrl = cpu_to_le32(ctrl);
2379 /* Create a frame descriptor based on a fragmented skb */
2380 @@ -341,7 +632,6 @@ static int build_sg_fd(struct dpaa2_eth_
2383 struct dpaa2_eth_swa *swa;
2384 - struct dpaa2_fas *fas;
2386 /* Create and map scatterlist.
2387 * We don't advertise NETIF_F_FRAGLIST, so skb_to_sgvec() will not have
2388 @@ -365,21 +655,14 @@ static int build_sg_fd(struct dpaa2_eth_
2390 /* Prepare the HW SGT structure */
2391 sgt_buf_size = priv->tx_data_offset +
2392 - sizeof(struct dpaa2_sg_entry) * (1 + num_dma_bufs);
2393 - sgt_buf = kzalloc(sgt_buf_size + DPAA2_ETH_TX_BUF_ALIGN, GFP_ATOMIC);
2394 + sizeof(struct dpaa2_sg_entry) * num_dma_bufs;
2395 + sgt_buf = netdev_alloc_frag(sgt_buf_size + DPAA2_ETH_TX_BUF_ALIGN);
2396 if (unlikely(!sgt_buf)) {
2398 goto sgt_buf_alloc_failed;
2400 sgt_buf = PTR_ALIGN(sgt_buf, DPAA2_ETH_TX_BUF_ALIGN);
2402 - /* PTA from egress side is passed as is to the confirmation side so
2403 - * we need to clear some fields here in order to find consistent values
2404 - * on TX confirmation. We are clearing FAS (Frame Annotation Status)
2405 - * field from the hardware annotation area
2407 - fas = dpaa2_get_fas(sgt_buf);
2408 - memset(fas, 0, DPAA2_FAS_SIZE);
2409 + memset(sgt_buf, 0, sgt_buf_size);
2411 sgt = (struct dpaa2_sg_entry *)(sgt_buf + priv->tx_data_offset);
2413 @@ -402,10 +685,11 @@ static int build_sg_fd(struct dpaa2_eth_
2414 * all of them on Tx Conf.
2416 swa = (struct dpaa2_eth_swa *)sgt_buf;
2419 - swa->num_sg = num_sg;
2420 - swa->num_dma_bufs = num_dma_bufs;
2421 + swa->type = DPAA2_ETH_SWA_SG;
2422 + swa->sg.skb = skb;
2423 + swa->sg.scl = scl;
2424 + swa->sg.num_sg = num_sg;
2425 + swa->sg.sgt_size = sgt_buf_size;
2427 /* Separately map the SGT buffer */
2428 addr = dma_map_single(dev, sgt_buf, sgt_buf_size, DMA_BIDIRECTIONAL);
2429 @@ -417,13 +701,15 @@ static int build_sg_fd(struct dpaa2_eth_
2430 dpaa2_fd_set_format(fd, dpaa2_fd_sg);
2431 dpaa2_fd_set_addr(fd, addr);
2432 dpaa2_fd_set_len(fd, skb->len);
2433 - dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_ASAL | DPAA2_FD_CTRL_PTA |
2434 - DPAA2_FD_CTRL_PTV1);
2435 + dpaa2_fd_set_ctrl(fd, FD_CTRL_PTA);
2437 + if (priv->ts_tx_en && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
2438 + enable_tx_tstamp(fd, sgt_buf);
2442 dma_map_single_failed:
2444 + skb_free_frag(sgt_buf);
2445 sgt_buf_alloc_failed:
2446 dma_unmap_sg(dev, scl, num_sg, DMA_BIDIRECTIONAL);
2448 @@ -437,29 +723,27 @@ static int build_single_fd(struct dpaa2_
2449 struct dpaa2_fd *fd)
2451 struct device *dev = priv->net_dev->dev.parent;
2453 - struct dpaa2_fas *fas;
2454 - struct sk_buff **skbh;
2455 + u8 *buffer_start, *aligned_start;
2456 + struct dpaa2_eth_swa *swa;
2459 - buffer_start = PTR_ALIGN(skb->data - priv->tx_data_offset -
2460 - DPAA2_ETH_TX_BUF_ALIGN,
2461 - DPAA2_ETH_TX_BUF_ALIGN);
2463 - /* PTA from egress side is passed as is to the confirmation side so
2464 - * we need to clear some fields here in order to find consistent values
2465 - * on TX confirmation. We are clearing FAS (Frame Annotation Status)
2466 - * field from the hardware annotation area
2467 + buffer_start = skb->data - dpaa2_eth_needed_headroom(priv, skb);
2469 + /* If there's enough room to align the FD address, do it.
2470 + * It will help hardware optimize accesses.
2472 - fas = dpaa2_get_fas(buffer_start);
2473 - memset(fas, 0, DPAA2_FAS_SIZE);
2474 + aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN,
2475 + DPAA2_ETH_TX_BUF_ALIGN);
2476 + if (aligned_start >= skb->head)
2477 + buffer_start = aligned_start;
2479 /* Store a backpointer to the skb at the beginning of the buffer
2480 * (in the private data area) such that we can release it
2483 - skbh = (struct sk_buff **)buffer_start;
2485 + swa = (struct dpaa2_eth_swa *)buffer_start;
2486 + swa->type = DPAA2_ETH_SWA_SINGLE;
2487 + swa->single.skb = skb;
2489 addr = dma_map_single(dev, buffer_start,
2490 skb_tail_pointer(skb) - buffer_start,
2491 @@ -471,8 +755,10 @@ static int build_single_fd(struct dpaa2_
2492 dpaa2_fd_set_offset(fd, (u16)(skb->data - buffer_start));
2493 dpaa2_fd_set_len(fd, skb->len);
2494 dpaa2_fd_set_format(fd, dpaa2_fd_single);
2495 - dpaa2_fd_set_ctrl(fd, DPAA2_FD_CTRL_ASAL | DPAA2_FD_CTRL_PTA |
2496 - DPAA2_FD_CTRL_PTV1);
2497 + dpaa2_fd_set_ctrl(fd, FD_CTRL_PTA);
2499 + if (priv->ts_tx_en && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
2500 + enable_tx_tstamp(fd, buffer_start);
2504 @@ -486,92 +772,128 @@ static int build_single_fd(struct dpaa2_
2505 * Optionally, return the frame annotation status word (FAS), which needs
2506 * to be checked if we're on the confirmation path.
2508 -static void free_tx_fd(const struct dpaa2_eth_priv *priv,
2509 +static void free_tx_fd(struct dpaa2_eth_priv *priv,
2510 const struct dpaa2_fd *fd,
2514 struct device *dev = priv->net_dev->dev.parent;
2516 - struct sk_buff **skbh, *skb;
2517 + struct sk_buff *skb = NULL;
2518 unsigned char *buffer_start;
2520 - struct scatterlist *scl;
2521 - int num_sg, num_dma_bufs;
2522 struct dpaa2_eth_swa *swa;
2523 u8 fd_format = dpaa2_fd_get_format(fd);
2524 - struct dpaa2_fas *fas;
2526 fd_addr = dpaa2_fd_get_addr(fd);
2527 - skbh = dpaa2_iova_to_virt(priv->iommu_domain, fd_addr);
2528 - fas = dpaa2_get_fas(skbh);
2529 + buffer_start = dpaa2_iova_to_virt(priv->iommu_domain, fd_addr);
2530 + swa = (struct dpaa2_eth_swa *)buffer_start;
2532 if (fd_format == dpaa2_fd_single) {
2534 - buffer_start = (unsigned char *)skbh;
2535 - /* Accessing the skb buffer is safe before dma unmap, because
2536 - * we didn't map the actual skb shell.
2538 - dma_unmap_single(dev, fd_addr,
2539 - skb_tail_pointer(skb) - buffer_start,
2540 - DMA_BIDIRECTIONAL);
2541 + if (swa->type == DPAA2_ETH_SWA_SINGLE) {
2542 + skb = swa->single.skb;
2543 + /* Accessing the skb buffer is safe before dma unmap,
2544 + * because we didn't map the actual skb shell.
2546 + dma_unmap_single(dev, fd_addr,
2547 + skb_tail_pointer(skb) - buffer_start,
2548 + DMA_BIDIRECTIONAL);
2550 + WARN_ONCE(swa->type != DPAA2_ETH_SWA_XDP,
2551 + "Wrong SWA type");
2552 + dma_unmap_single(dev, fd_addr, swa->xdp.dma_size,
2553 + DMA_BIDIRECTIONAL);
2555 } else if (fd_format == dpaa2_fd_sg) {
2556 - swa = (struct dpaa2_eth_swa *)skbh;
2559 - num_sg = swa->num_sg;
2560 - num_dma_bufs = swa->num_dma_bufs;
2561 + skb = swa->sg.skb;
2563 /* Unmap the scatterlist */
2564 - dma_unmap_sg(dev, scl, num_sg, DMA_BIDIRECTIONAL);
2566 + dma_unmap_sg(dev, swa->sg.scl, swa->sg.num_sg, DMA_BIDIRECTIONAL);
2567 + kfree(swa->sg.scl);
2569 /* Unmap the SGT buffer */
2570 - unmap_size = priv->tx_data_offset +
2571 - sizeof(struct dpaa2_sg_entry) * (1 + num_dma_bufs);
2572 - dma_unmap_single(dev, fd_addr, unmap_size, DMA_BIDIRECTIONAL);
2573 + dma_unmap_single(dev, fd_addr, swa->sg.sgt_size,
2574 + DMA_BIDIRECTIONAL);
2576 - /* Unsupported format, mark it as errored and give up */
2579 + netdev_dbg(priv->net_dev, "Invalid FD format\n");
2583 - /* Read the status from the Frame Annotation after we unmap the first
2584 - * buffer but before we free it. The caller function is responsible
2585 - * for checking the status value.
2588 - *status = le32_to_cpu(fas->status);
2589 + if (swa->type == DPAA2_ETH_SWA_XDP) {
2590 + page_frag_free(buffer_start);
2594 + /* Get the timestamp value */
2595 + if (priv->ts_tx_en && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) {
2596 + struct skb_shared_hwtstamps shhwtstamps;
2599 + memset(&shhwtstamps, 0, sizeof(shhwtstamps));
2601 + ns = dpaa2_get_ts(buffer_start, true);
2602 + *ns = DPAA2_PTP_NOMINAL_FREQ_PERIOD_NS * le64_to_cpup(ns);
2603 + shhwtstamps.hwtstamp = ns_to_ktime(*ns);
2604 + skb_tstamp_tx(skb, &shhwtstamps);
2607 - /* Free SGT buffer kmalloc'ed on tx */
2608 + /* Free SGT buffer allocated on tx */
2609 if (fd_format != dpaa2_fd_single)
2611 + skb_free_frag(buffer_start);
2613 /* Move on with skb release */
2614 - dev_kfree_skb(skb);
2615 + napi_consume_skb(skb, in_napi);
2618 static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, struct net_device *net_dev)
2620 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
2621 + struct device *dev = net_dev->dev.parent;
2623 struct rtnl_link_stats64 *percpu_stats;
2624 struct dpaa2_eth_drv_stats *percpu_extras;
2625 struct dpaa2_eth_fq *fq;
2628 + unsigned int needed_headroom;
2630 + int err, i, ch_id = 0;
2632 + queue_mapping = skb_get_queue_mapping(skb);
2633 + prio = netdev_txq_to_tc(net_dev, queue_mapping);
2635 + /* Hardware interprets priority level 0 as being the highest,
2636 + * so we need to do a reverse mapping to the netdev tc index
2638 + if (net_dev->num_tc)
2639 + prio = net_dev->num_tc - prio - 1;
2641 + queue_mapping %= dpaa2_eth_queue_count(priv);
2642 + fq = &priv->fq[queue_mapping];
2644 + /* If we're congested, stop this tx queue; transmission of
2645 + * the current skb happens regardless of congestion state
2647 + dma_sync_single_for_cpu(dev, priv->cscn_dma,
2648 + DPAA2_CSCN_SIZE, DMA_FROM_DEVICE);
2649 + if (unlikely(dpaa2_cscn_state_congested(priv->cscn_mem))) {
2650 + netif_stop_subqueue(net_dev, queue_mapping);
2651 + fq->stats.congestion_entry++;
2654 percpu_stats = this_cpu_ptr(priv->percpu_stats);
2655 percpu_extras = this_cpu_ptr(priv->percpu_extras);
2657 - if (unlikely(skb_headroom(skb) < DPAA2_ETH_NEEDED_HEADROOM(priv))) {
2658 + /* For non-linear skb we don't need a minimum headroom */
2659 + needed_headroom = dpaa2_eth_needed_headroom(priv, skb);
2660 + if (skb_headroom(skb) < needed_headroom) {
2663 - ns = skb_realloc_headroom(skb, DPAA2_ETH_NEEDED_HEADROOM(priv));
2664 + ns = skb_realloc_headroom(skb, needed_headroom);
2665 if (unlikely(!ns)) {
2666 percpu_stats->tx_dropped++;
2667 goto err_alloc_headroom;
2669 + percpu_extras->tx_reallocs++;
2671 + skb_set_owner_w(ns, skb->sk);
2675 @@ -605,13 +927,15 @@ static netdev_tx_t dpaa2_eth_tx(struct s
2677 trace_dpaa2_tx_fd(net_dev, &fd);
2679 - /* TxConf FQ selection primarily based on cpu affinity; this is
2680 - * non-migratable context, so it's safe to call smp_processor_id().
2682 - queue_mapping = smp_processor_id() % dpaa2_eth_queue_count(priv);
2683 - fq = &priv->fq[queue_mapping];
2684 + if (dpaa2_eth_ceetm_is_enabled(priv)) {
2685 + err = dpaa2_ceetm_classify(skb, net_dev->qdisc, &ch_id, &prio);
2687 + goto err_ceetm_classify;
2690 for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) {
2691 - err = dpaa2_io_service_enqueue_qd(NULL, priv->tx_qdid, 0,
2692 + err = dpaa2_io_service_enqueue_qd(fq->channel->dpio,
2693 + priv->tx_qdid, prio,
2697 @@ -620,7 +944,7 @@ static netdev_tx_t dpaa2_eth_tx(struct s
2698 if (unlikely(err < 0)) {
2699 percpu_stats->tx_errors++;
2700 /* Clean up everything, including freeing the skb */
2701 - free_tx_fd(priv, &fd, NULL);
2702 + free_tx_fd(priv, &fd, false);
2704 percpu_stats->tx_packets++;
2705 percpu_stats->tx_bytes += dpaa2_fd_get_len(&fd);
2706 @@ -628,6 +952,8 @@ static netdev_tx_t dpaa2_eth_tx(struct s
2708 return NETDEV_TX_OK;
2710 +err_ceetm_classify:
2711 + free_tx_fd(priv, &fd, false);
2715 @@ -639,13 +965,13 @@ err_alloc_headroom:
2716 static void dpaa2_eth_tx_conf(struct dpaa2_eth_priv *priv,
2717 struct dpaa2_eth_channel *ch,
2718 const struct dpaa2_fd *fd,
2719 - struct napi_struct *napi __always_unused)
2720 + struct napi_struct *napi __always_unused,
2723 + struct device *dev = priv->net_dev->dev.parent;
2724 struct rtnl_link_stats64 *percpu_stats;
2725 struct dpaa2_eth_drv_stats *percpu_extras;
2728 - bool has_fas_errors = false;
2731 trace_dpaa2_tx_conf_fd(priv->net_dev, fd);
2732 @@ -654,31 +980,28 @@ static void dpaa2_eth_tx_conf(struct dpa
2733 percpu_extras->tx_conf_frames++;
2734 percpu_extras->tx_conf_bytes += dpaa2_fd_get_len(fd);
2736 - /* Check frame errors in the FD field */
2737 - fd_errors = dpaa2_fd_get_ctrl(fd) & DPAA2_FD_TX_ERR_MASK;
2738 - if (unlikely(fd_errors)) {
2739 - /* We only check error bits in the FAS field if corresponding
2740 - * FAERR bit is set in FD and the FAS field is marked as valid
2742 - has_fas_errors = (fd_errors & DPAA2_FD_CTRL_FAERR) &&
2743 - !!(dpaa2_fd_get_frc(fd) & DPAA2_FD_FRC_FASV);
2744 - if (net_ratelimit())
2745 - netdev_dbg(priv->net_dev, "TX frame FD error: 0x%08x\n",
2747 + /* Check congestion state and wake all queues if necessary */
2748 + if (unlikely(__netif_subqueue_stopped(priv->net_dev, queue_id))) {
2749 + dma_sync_single_for_cpu(dev, priv->cscn_dma,
2750 + DPAA2_CSCN_SIZE, DMA_FROM_DEVICE);
2751 + if (!dpaa2_cscn_state_congested(priv->cscn_mem))
2752 + netif_tx_wake_all_queues(priv->net_dev);
2755 - free_tx_fd(priv, fd, has_fas_errors ? &status : NULL);
2756 + /* Check frame errors in the FD field */
2757 + fd_errors = dpaa2_fd_get_ctrl(fd) & DPAA2_FD_TX_ERR_MASK;
2758 + free_tx_fd(priv, fd, true);
2760 if (likely(!fd_errors))
2763 + if (net_ratelimit())
2764 + netdev_dbg(priv->net_dev, "TX frame FD error: 0x%08x\n",
2767 percpu_stats = this_cpu_ptr(priv->percpu_stats);
2768 /* Tx-conf logically pertains to the egress path. */
2769 percpu_stats->tx_errors++;
2771 - if (has_fas_errors && net_ratelimit())
2772 - netdev_dbg(priv->net_dev, "TX frame FAS error: 0x%08x\n",
2773 - status & DPAA2_FAS_TX_ERR_MASK);
2776 static int set_rx_csum(struct dpaa2_eth_priv *priv, bool enable)
2777 @@ -728,26 +1051,27 @@ static int set_tx_csum(struct dpaa2_eth_
2778 /* Perform a single release command to add buffers
2779 * to the specified buffer pool
2781 -static int add_bufs(struct dpaa2_eth_priv *priv, u16 bpid)
2782 +static int add_bufs(struct dpaa2_eth_priv *priv,
2783 + struct dpaa2_eth_channel *ch, u16 bpid)
2785 struct device *dev = priv->net_dev->dev.parent;
2786 u64 buf_array[DPAA2_ETH_BUFS_PER_CMD];
2792 for (i = 0; i < DPAA2_ETH_BUFS_PER_CMD; i++) {
2793 /* Allocate buffer visible to WRIOP + skb shared info +
2796 - buf = napi_alloc_frag(DPAA2_ETH_BUF_RAW_SIZE);
2797 + buf = napi_alloc_frag(dpaa2_eth_buf_raw_size(priv));
2801 - buf = PTR_ALIGN(buf, DPAA2_ETH_RX_BUF_ALIGN);
2802 + buf = PTR_ALIGN(buf, priv->rx_buf_align);
2804 addr = dma_map_single(dev, buf, DPAA2_ETH_RX_BUF_SIZE,
2806 + DMA_BIDIRECTIONAL);
2807 if (unlikely(dma_mapping_error(dev, addr)))
2810 @@ -755,28 +1079,31 @@ static int add_bufs(struct dpaa2_eth_pri
2813 trace_dpaa2_eth_buf_seed(priv->net_dev,
2814 - buf, DPAA2_ETH_BUF_RAW_SIZE,
2815 + buf, dpaa2_eth_buf_raw_size(priv),
2816 addr, DPAA2_ETH_RX_BUF_SIZE,
2821 - /* In case the portal is busy, retry until successful.
2822 - * The buffer release function would only fail if the QBMan portal
2823 - * was busy, which implies portal contention (i.e. more CPUs than
2824 - * portals, i.e. GPPs w/o affine DPIOs). For all practical purposes,
2825 - * there is little we can realistically do, short of giving up -
2826 - * in which case we'd risk depleting the buffer pool and never again
2827 - * receiving the Rx interrupt which would kick-start the refill logic.
2828 - * So just keep retrying, at the risk of being moved to ksoftirqd.
2830 - while (dpaa2_io_service_release(NULL, bpid, buf_array, i))
2831 + /* In case the portal is busy, retry until successful */
2832 + while ((err = dpaa2_io_service_release(ch->dpio, bpid,
2833 + buf_array, i)) == -EBUSY)
2836 + /* If release command failed, clean up and bail out; not much
2837 + * else we can do about it
2840 + free_bufs(priv, buf_array, i);
2849 + /* If we managed to allocate at least some buffers, release them */
2853 @@ -796,9 +1123,10 @@ static int seed_pool(struct dpaa2_eth_pr
2856 for (j = 0; j < priv->num_channels; j++) {
2857 - for (i = 0; i < DPAA2_ETH_NUM_BUFS;
2858 + priv->channel[j]->buf_count = 0;
2859 + for (i = 0; i < priv->max_bufs_per_ch;
2860 i += DPAA2_ETH_BUFS_PER_CMD) {
2861 - new_count = add_bufs(priv, bpid);
2862 + new_count = add_bufs(priv, priv->channel[j], bpid);
2863 priv->channel[j]->buf_count += new_count;
2865 if (new_count < DPAA2_ETH_BUFS_PER_CMD) {
2866 @@ -818,10 +1146,8 @@ static int seed_pool(struct dpaa2_eth_pr
2868 static void drain_bufs(struct dpaa2_eth_priv *priv, int count)
2870 - struct device *dev = priv->net_dev->dev.parent;
2871 u64 buf_array[DPAA2_ETH_BUFS_PER_CMD];
2877 ret = dpaa2_io_service_acquire(NULL, priv->bpid,
2878 @@ -830,27 +1156,16 @@ static void drain_bufs(struct dpaa2_eth_
2879 netdev_err(priv->net_dev, "dpaa2_io_service_acquire() failed\n");
2882 - for (i = 0; i < ret; i++) {
2883 - /* Same logic as on regular Rx path */
2884 - vaddr = dpaa2_iova_to_virt(priv->iommu_domain,
2886 - dma_unmap_single(dev, buf_array[i],
2887 - DPAA2_ETH_RX_BUF_SIZE,
2889 - skb_free_frag(vaddr);
2891 + free_bufs(priv, buf_array, ret);
2895 static void drain_pool(struct dpaa2_eth_priv *priv)
2899 + preempt_disable();
2900 drain_bufs(priv, DPAA2_ETH_BUFS_PER_CMD);
2901 drain_bufs(priv, 1);
2903 - for (i = 0; i < priv->num_channels; i++)
2904 - priv->channel[i]->buf_count = 0;
2908 /* Function is called from softirq context only, so we don't need to guard
2909 @@ -862,19 +1177,19 @@ static int refill_pool(struct dpaa2_eth_
2913 - if (likely(ch->buf_count >= DPAA2_ETH_REFILL_THRESH))
2914 + if (likely(ch->buf_count >= priv->refill_thresh))
2918 - new_count = add_bufs(priv, bpid);
2919 + new_count = add_bufs(priv, ch, bpid);
2920 if (unlikely(!new_count)) {
2921 /* Out of memory; abort for now, we'll try later on */
2924 ch->buf_count += new_count;
2925 - } while (ch->buf_count < DPAA2_ETH_NUM_BUFS);
2926 + } while (ch->buf_count < priv->max_bufs_per_ch);
2928 - if (unlikely(ch->buf_count < DPAA2_ETH_NUM_BUFS))
2929 + if (unlikely(ch->buf_count < priv->max_bufs_per_ch))
2933 @@ -887,7 +1202,8 @@ static int pull_channel(struct dpaa2_eth
2935 /* Retry while portal is busy */
2937 - err = dpaa2_io_service_pull_channel(NULL, ch->ch_id, ch->store);
2938 + err = dpaa2_io_service_pull_channel(ch->dpio, ch->ch_id,
2942 } while (err == -EBUSY);
2943 @@ -902,20 +1218,21 @@ static int pull_channel(struct dpaa2_eth
2944 /* NAPI poll routine
2946 * Frames are dequeued from the QMan channel associated with this NAPI context.
2947 - * Rx, Tx confirmation and (if configured) Rx error frames all count
2948 - * towards the NAPI budget.
2949 + * Rx and (if configured) Rx error frames count towards the NAPI budget. Tx
2950 + * confirmation frames are limited by a threshold per NAPI poll cycle.
2952 static int dpaa2_eth_poll(struct napi_struct *napi, int budget)
2954 struct dpaa2_eth_channel *ch;
2955 - int cleaned = 0, store_cleaned;
2956 + int rx_cleaned = 0, tx_conf_cleaned = 0;
2957 + bool store_cleaned;
2958 struct dpaa2_eth_priv *priv;
2961 ch = container_of(napi, struct dpaa2_eth_channel, napi);
2964 - while (cleaned < budget) {
2966 err = pull_channel(ch);
2969 @@ -923,29 +1240,29 @@ static int dpaa2_eth_poll(struct napi_st
2970 /* Refill pool if appropriate */
2971 refill_pool(priv, ch, priv->bpid);
2973 - store_cleaned = consume_frames(ch);
2974 - cleaned += store_cleaned;
2975 + store_cleaned = consume_frames(ch, &rx_cleaned,
2976 + &tx_conf_cleaned);
2978 - /* If we have enough budget left for a full store,
2979 - * try a new pull dequeue, otherwise we're done here
2980 + /* If we've either consumed the budget with Rx frames,
2981 + * or reached the Tx conf threshold, we're done.
2983 - if (store_cleaned == 0 ||
2984 - cleaned > budget - DPAA2_ETH_STORE_SIZE)
2988 - if (cleaned < budget) {
2989 - napi_complete_done(napi, cleaned);
2990 - /* Re-enable data available notifications */
2992 - err = dpaa2_io_service_rearm(NULL, &ch->nctx);
2994 - } while (err == -EBUSY);
2996 + if (rx_cleaned >= budget ||
2997 + tx_conf_cleaned >= TX_CONF_PER_NAPI_POLL)
2999 + } while (store_cleaned);
3001 - ch->stats.frames += cleaned;
3002 + /* We didn't consume the entire budget, finish napi and
3003 + * re-enable data availability notifications
3005 + napi_complete(napi);
3007 + err = dpaa2_io_service_rearm(ch->dpio, &ch->nctx);
3009 + } while (err == -EBUSY);
3010 + WARN_ONCE(err, "CDAN notifications rearm failed on core %d",
3011 + ch->nctx.desired_cpu);
3014 + return max(rx_cleaned, 1);
3017 static void enable_ch_napi(struct dpaa2_eth_priv *priv)
3018 @@ -1006,28 +1323,30 @@ static int dpaa2_eth_open(struct net_dev
3019 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
3022 - err = seed_pool(priv, priv->bpid);
3024 - /* Not much to do; the buffer pool, though not filled up,
3025 - * may still contain some buffers which would enable us
3028 - netdev_err(net_dev, "Buffer seeding failed for DPBP %d (bpid=%d)\n",
3029 - priv->dpbp_dev->obj_desc.id, priv->bpid);
3032 /* We'll only start the txqs when the link is actually ready; make sure
3033 * we don't race against the link up notification, which may come
3034 * immediately after dpni_enable();
3036 netif_tx_stop_all_queues(net_dev);
3037 - enable_ch_napi(priv);
3039 /* Also, explicitly set carrier off, otherwise netif_carrier_ok() will
3040 * return true and cause 'ip link show' to report the LOWER_UP flag,
3041 * even though the link notification wasn't even received.
3043 netif_carrier_off(net_dev);
3045 + err = seed_pool(priv, priv->bpid);
3047 + /* Not much to do; the buffer pool, though not filled up,
3048 + * may still contain some buffers which would enable us
3051 + netdev_err(net_dev, "Buffer seeding failed for DPBP %d (bpid=%d)\n",
3052 + priv->dpbp_dev->obj_desc.id, priv->bpid);
3055 + priv->refill_thresh = DPAA2_ETH_REFILL_THRESH(priv);
3057 err = dpni_enable(priv->mc_io, 0, priv->mc_token);
3059 netdev_err(net_dev, "dpni_enable() failed\n");
3060 @@ -1047,48 +1366,17 @@ static int dpaa2_eth_open(struct net_dev
3064 - disable_ch_napi(priv);
3065 + priv->refill_thresh = 0;
3070 -/* The DPIO store must be empty when we call this,
3071 - * at the end of every NAPI cycle.
3073 -static u32 drain_channel(struct dpaa2_eth_priv *priv,
3074 - struct dpaa2_eth_channel *ch)
3076 - u32 drained = 0, total = 0;
3080 - drained = consume_frames(ch);
3082 - } while (drained);
3087 -static u32 drain_ingress_frames(struct dpaa2_eth_priv *priv)
3089 - struct dpaa2_eth_channel *ch;
3093 - for (i = 0; i < priv->num_channels; i++) {
3094 - ch = priv->channel[i];
3095 - drained += drain_channel(priv, ch);
3101 static int dpaa2_eth_stop(struct net_device *net_dev)
3103 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
3107 + int retries = 10, i;
3110 netif_tx_stop_all_queues(net_dev);
3111 netif_carrier_off(net_dev);
3112 @@ -1105,56 +1393,24 @@ static int dpaa2_eth_stop(struct net_dev
3113 } while (dpni_enabled && --retries);
3115 netdev_warn(net_dev, "Retry count exceeded disabling DPNI\n");
3116 - /* Must go on and disable NAPI nonetheless, so we don't crash at
3117 - * the next "ifconfig up"
3118 + /* Must go on and finish processing pending frames, so we don't
3119 + * crash at the next "ifconfig up"
3124 - /* Wait for NAPI to complete on every core and disable it.
3125 - * In particular, this will also prevent NAPI from being rescheduled if
3126 - * a new CDAN is serviced, effectively discarding the CDAN. We therefore
3127 - * don't even need to disarm the channels, except perhaps for the case
3128 - * of a huge coalescing value.
3130 - disable_ch_napi(priv);
3131 + priv->refill_thresh = 0;
3133 - /* Manually drain the Rx and TxConf queues */
3134 - drained = drain_ingress_frames(priv);
3136 - netdev_dbg(net_dev, "Drained %d frames.\n", drained);
3137 + /* Wait for all running napi poll routines to finish, so that no
3138 + * new refill operations are started
3140 + for (i = 0; i < priv->num_channels; i++)
3141 + napi_synchronize(&priv->channel[i]->napi);
3143 /* Empty the buffer pool */
3149 -static int dpaa2_eth_init(struct net_device *net_dev)
3151 - u64 supported = 0;
3152 - u64 not_supported = 0;
3153 - struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
3154 - u32 options = priv->dpni_attrs.options;
3156 - /* Capabilities listing */
3157 - supported |= IFF_LIVE_ADDR_CHANGE;
3159 - if (options & DPNI_OPT_NO_MAC_FILTER)
3160 - not_supported |= IFF_UNICAST_FLT;
3162 - supported |= IFF_UNICAST_FLT;
3164 - net_dev->priv_flags |= supported;
3165 - net_dev->priv_flags &= ~not_supported;
3168 - net_dev->features = NETIF_F_RXCSUM |
3169 - NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3170 - NETIF_F_SG | NETIF_F_HIGHDMA |
3172 - net_dev->hw_features = net_dev->features;
3178 static int dpaa2_eth_set_addr(struct net_device *net_dev, void *addr)
3179 @@ -1200,25 +1456,6 @@ static void dpaa2_eth_get_stats(struct n
3183 -static int dpaa2_eth_change_mtu(struct net_device *net_dev, int mtu)
3185 - struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
3188 - /* Set the maximum Rx frame length to match the transmit side;
3189 - * account for L2 headers when computing the MFL
3191 - err = dpni_set_max_frame_length(priv->mc_io, 0, priv->mc_token,
3192 - (u16)DPAA2_ETH_L2_MAX_FRM(mtu));
3194 - netdev_err(net_dev, "dpni_set_max_frame_length() failed\n");
3198 - net_dev->mtu = mtu;
3202 /* Copy mac unicast addresses from @net_dev to @priv.
3203 * Its sole purpose is to make dpaa2_eth_set_rx_mode() more readable.
3205 @@ -1380,16 +1617,363 @@ static int dpaa2_eth_set_features(struct
3209 +static int dpaa2_eth_ts_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3211 + struct dpaa2_eth_priv *priv = netdev_priv(dev);
3212 + struct hwtstamp_config config;
3214 + if (copy_from_user(&config, rq->ifr_data, sizeof(config)))
3217 + switch (config.tx_type) {
3218 + case HWTSTAMP_TX_OFF:
3219 + priv->ts_tx_en = false;
3221 + case HWTSTAMP_TX_ON:
3222 + priv->ts_tx_en = true;
3228 + if (config.rx_filter == HWTSTAMP_FILTER_NONE) {
3229 + priv->ts_rx_en = false;
3231 + priv->ts_rx_en = true;
3232 + /* TS is set for all frame types, not only those requested */
3233 + config.rx_filter = HWTSTAMP_FILTER_ALL;
3236 + return copy_to_user(rq->ifr_data, &config, sizeof(config)) ?
3240 +static int dpaa2_eth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3242 + if (cmd == SIOCSHWTSTAMP)
3243 + return dpaa2_eth_ts_ioctl(dev, rq, cmd);
3248 +static int set_buffer_layout(struct dpaa2_eth_priv *priv)
3250 + struct device *dev = priv->net_dev->dev.parent;
3251 + struct dpni_buffer_layout buf_layout = {0};
3254 + /* We need to check for WRIOP version 1.0.0, but depending on the MC
3255 + * version, this number is not always provided correctly on rev1.
3256 + * We need to check for both alternatives in this situation.
3258 + if (priv->dpni_attrs.wriop_version == DPAA2_WRIOP_VERSION(0, 0, 0) ||
3259 + priv->dpni_attrs.wriop_version == DPAA2_WRIOP_VERSION(1, 0, 0))
3260 + priv->rx_buf_align = DPAA2_ETH_RX_BUF_ALIGN_REV1;
3262 + priv->rx_buf_align = DPAA2_ETH_RX_BUF_ALIGN;
3265 + buf_layout.pass_timestamp = true;
3266 + buf_layout.private_data_size = DPAA2_ETH_SWA_SIZE;
3267 + buf_layout.options = DPNI_BUF_LAYOUT_OPT_TIMESTAMP |
3268 + DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
3269 + err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token,
3270 + DPNI_QUEUE_TX, &buf_layout);
3272 + dev_err(dev, "dpni_set_buffer_layout(TX) failed\n");
3276 + /* tx-confirm buffer */
3277 + buf_layout.options = DPNI_BUF_LAYOUT_OPT_TIMESTAMP;
3278 + err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token,
3279 + DPNI_QUEUE_TX_CONFIRM, &buf_layout);
3281 + dev_err(dev, "dpni_set_buffer_layout(TX_CONF) failed\n");
3285 + /* Now that we've set our tx buffer layout, retrieve the minimum
3286 + * required tx data offset.
3288 + err = dpni_get_tx_data_offset(priv->mc_io, 0, priv->mc_token,
3289 + &priv->tx_data_offset);
3291 + dev_err(dev, "dpni_get_tx_data_offset() failed\n");
3295 + if ((priv->tx_data_offset % 64) != 0)
3296 + dev_warn(dev, "Tx data offset (%d) not a multiple of 64B\n",
3297 + priv->tx_data_offset);
3300 + buf_layout.pass_frame_status = true;
3301 + buf_layout.pass_parser_result = true;
3302 + buf_layout.data_align = priv->rx_buf_align;
3303 + buf_layout.private_data_size = 0;
3304 + buf_layout.data_head_room = dpaa2_eth_rx_headroom(priv);
3305 + /* If XDP program is attached, reserve extra space for
3306 + * potential header expansions
3308 + if (priv->has_xdp_prog)
3309 + buf_layout.data_head_room += XDP_PACKET_HEADROOM;
3310 + buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
3311 + DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
3312 + DPNI_BUF_LAYOUT_OPT_DATA_ALIGN |
3313 + DPNI_BUF_LAYOUT_OPT_DATA_HEAD_ROOM |
3314 + DPNI_BUF_LAYOUT_OPT_TIMESTAMP;
3315 + err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token,
3316 + DPNI_QUEUE_RX, &buf_layout);
3318 + dev_err(dev, "dpni_set_buffer_layout(RX) failed\n");
3325 +static int dpaa2_eth_set_xdp(struct net_device *net_dev, struct bpf_prog *prog)
3327 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
3328 + struct dpaa2_eth_channel *ch;
3329 + struct bpf_prog *old_prog = NULL;
3332 + /* No support for SG frames */
3333 + if (DPAA2_ETH_L2_MAX_FRM(net_dev->mtu) > DPAA2_ETH_RX_BUF_SIZE)
3336 + if (netif_running(net_dev)) {
3337 + err = dpaa2_eth_stop(net_dev);
3343 + prog = bpf_prog_add(prog, priv->num_channels - 1);
3345 + return PTR_ERR(prog);
3348 + priv->has_xdp_prog = !!prog;
3350 + for (i = 0; i < priv->num_channels; i++) {
3351 + ch = priv->channel[i];
3352 + old_prog = xchg(&ch->xdp_prog, prog);
3354 + bpf_prog_put(old_prog);
3357 + /* When turning XDP on/off we need to do some reconfiguring
3358 + * of the Rx buffer layout. Buffer pool was drained on dpaa2_eth_stop,
3359 + * so we are sure no old format buffers will be used from now on
3361 + if (priv->has_xdp_prog != !!old_prog)
3362 + set_buffer_layout(priv);
3364 + if (netif_running(net_dev)) {
3365 + err = dpaa2_eth_open(net_dev);
3373 +static int dpaa2_eth_xdp(struct net_device *dev, struct netdev_xdp *xdp)
3375 + struct dpaa2_eth_priv *priv = netdev_priv(dev);
3377 + switch (xdp->command) {
3378 + case XDP_SETUP_PROG:
3379 + return dpaa2_eth_set_xdp(dev, xdp->prog);
3380 + case XDP_QUERY_PROG:
3381 + xdp->prog_attached = priv->has_xdp_prog;
3388 +static int dpaa2_eth_xdp_xmit(struct net_device *net_dev, struct xdp_buff *xdp)
3390 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
3391 + struct device *dev = net_dev->dev.parent;
3392 + struct rtnl_link_stats64 *percpu_stats;
3393 + struct dpaa2_eth_drv_stats *percpu_extras;
3394 + unsigned int needed_headroom;
3395 + struct dpaa2_eth_swa *swa;
3396 + struct dpaa2_eth_fq *fq;
3397 + struct dpaa2_fd fd;
3398 + void *buffer_start, *aligned_start;
3402 + if (!netif_running(net_dev))
3405 + /* We require a minimum headroom to be able to transmit the frame.
3406 + * Otherwise return an error and let the original net_device handle it
3408 + /* TODO: Do we update i/f counters here or just on the Rx device? */
3409 + needed_headroom = dpaa2_eth_needed_headroom(priv, NULL);
3410 + if (xdp->data < xdp->data_hard_start ||
3411 + xdp->data - xdp->data_hard_start < needed_headroom) {
3412 + percpu_stats->tx_dropped++;
3416 + percpu_stats = this_cpu_ptr(priv->percpu_stats);
3417 + percpu_extras = this_cpu_ptr(priv->percpu_extras);
3419 + /* Setup the FD fields */
3420 + memset(&fd, 0, sizeof(fd));
3422 + /* Align FD address, if possible */
3423 + buffer_start = xdp->data - needed_headroom;
3424 + aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN,
3425 + DPAA2_ETH_TX_BUF_ALIGN);
3426 + if (aligned_start >= xdp->data_hard_start)
3427 + buffer_start = aligned_start;
3429 + swa = (struct dpaa2_eth_swa *)buffer_start;
3430 + /* fill in necessary fields here */
3431 + swa->type = DPAA2_ETH_SWA_XDP;
3432 + swa->xdp.dma_size = xdp->data_end - buffer_start;
3434 + addr = dma_map_single(dev, buffer_start,
3435 + xdp->data_end - buffer_start,
3436 + DMA_BIDIRECTIONAL);
3437 + if (unlikely(dma_mapping_error(dev, addr))) {
3438 + percpu_stats->tx_dropped++;
3442 + dpaa2_fd_set_addr(&fd, addr);
3443 + dpaa2_fd_set_offset(&fd, xdp->data - buffer_start);
3444 + dpaa2_fd_set_len(&fd, xdp->data_end - xdp->data);
3445 + dpaa2_fd_set_format(&fd, dpaa2_fd_single);
3446 + dpaa2_fd_set_ctrl(&fd, FD_CTRL_PTA);
3448 + fq = &priv->fq[smp_processor_id()];
3449 + for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) {
3450 + err = dpaa2_io_service_enqueue_qd(NULL, priv->tx_qdid, 0,
3451 + fq->tx_qdbin, &fd);
3452 + if (err != -EBUSY)
3455 + percpu_extras->tx_portal_busy += i;
3456 + if (unlikely(err < 0)) {
3457 + percpu_stats->tx_errors++;
3458 + /* let the Rx device handle the cleanup */
3462 + percpu_stats->tx_packets++;
3463 + percpu_stats->tx_bytes += dpaa2_fd_get_len(&fd);
3468 +static void dpaa2_eth_xdp_flush(struct net_device *net_dev)
3470 + /* We don't have hardware support for Tx batching,
3471 + * so we do the actual frame enqueue in ndo_xdp_xmit
3475 +static int dpaa2_eth_update_xps(struct dpaa2_eth_priv *priv)
3477 + struct net_device *net_dev = priv->net_dev;
3478 + unsigned int i, num_queues;
3479 + struct cpumask xps_mask;
3480 + struct dpaa2_eth_fq *fq;
3483 + num_queues = (net_dev->num_tc ? : 1) * dpaa2_eth_queue_count(priv);
3484 + for (i = 0; i < num_queues; i++) {
3485 + fq = &priv->fq[i % dpaa2_eth_queue_count(priv)];
3486 + cpumask_clear(&xps_mask);
3487 + cpumask_set_cpu(fq->target_cpu, &xps_mask);
3488 + err = netif_set_xps_queue(net_dev, &xps_mask, i);
3490 + dev_info_once(net_dev->dev.parent,
3491 + "Error setting XPS queue\n");
3499 +static int dpaa2_eth_setup_tc(struct net_device *net_dev,
3500 + enum tc_setup_type type,
3503 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
3504 + struct tc_mqprio_qopt *mqprio = (struct tc_mqprio_qopt *)type_data;
3507 + if (type != TC_SETUP_MQPRIO)
3510 + if (mqprio->num_tc > dpaa2_eth_tc_count(priv)) {
3511 + netdev_err(net_dev, "Max %d traffic classes supported\n",
3512 + dpaa2_eth_tc_count(priv));
3516 + if (mqprio->num_tc == net_dev->num_tc)
3519 + mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
3521 + if (!mqprio->num_tc) {
3522 + netdev_reset_tc(net_dev);
3523 + err = netif_set_real_num_tx_queues(net_dev,
3524 + dpaa2_eth_queue_count(priv));
3531 + err = netdev_set_num_tc(net_dev, mqprio->num_tc);
3535 + err = netif_set_real_num_tx_queues(net_dev, mqprio->num_tc *
3536 + dpaa2_eth_queue_count(priv));
3540 + for (i = 0; i < mqprio->num_tc; i++) {
3541 + err = netdev_set_tc_queue(net_dev, i,
3542 + dpaa2_eth_queue_count(priv),
3543 + i * dpaa2_eth_queue_count(priv));
3549 + err = dpaa2_eth_update_xps(priv);
3553 static const struct net_device_ops dpaa2_eth_ops = {
3554 .ndo_open = dpaa2_eth_open,
3555 .ndo_start_xmit = dpaa2_eth_tx,
3556 .ndo_stop = dpaa2_eth_stop,
3557 - .ndo_init = dpaa2_eth_init,
3558 .ndo_set_mac_address = dpaa2_eth_set_addr,
3559 .ndo_get_stats64 = dpaa2_eth_get_stats,
3560 - .ndo_change_mtu = dpaa2_eth_change_mtu,
3561 .ndo_set_rx_mode = dpaa2_eth_set_rx_mode,
3562 .ndo_set_features = dpaa2_eth_set_features,
3563 + .ndo_do_ioctl = dpaa2_eth_ioctl,
3564 + .ndo_xdp = dpaa2_eth_xdp,
3565 + .ndo_xdp_xmit = dpaa2_eth_xdp_xmit,
3566 + .ndo_xdp_flush = dpaa2_eth_xdp_flush,
3567 + .ndo_setup_tc = dpaa2_eth_setup_tc,
3570 static void cdan_cb(struct dpaa2_io_notification_ctx *ctx)
3571 @@ -1422,34 +2006,32 @@ static struct fsl_mc_device *setup_dpcon
3572 err = dpcon_open(priv->mc_io, 0, dpcon->obj_desc.id, &dpcon->mc_handle);
3574 dev_err(dev, "dpcon_open() failed\n");
3579 err = dpcon_reset(priv->mc_io, 0, dpcon->mc_handle);
3581 dev_err(dev, "dpcon_reset() failed\n");
3586 err = dpcon_get_attributes(priv->mc_io, 0, dpcon->mc_handle, &attrs);
3588 dev_err(dev, "dpcon_get_attributes() failed\n");
3589 - goto err_get_attr;
3593 err = dpcon_enable(priv->mc_io, 0, dpcon->mc_handle);
3595 dev_err(dev, "dpcon_enable() failed\n");
3606 dpcon_close(priv->mc_io, 0, dpcon->mc_handle);
3609 fsl_mc_object_free(dpcon);
3612 @@ -1502,7 +2084,14 @@ err_setup:
3613 static void free_channel(struct dpaa2_eth_priv *priv,
3614 struct dpaa2_eth_channel *channel)
3616 + struct bpf_prog *prog;
3618 free_dpcon(priv, channel->dpcon);
3620 + prog = READ_ONCE(channel->xdp_prog);
3622 + bpf_prog_put(prog);
3627 @@ -1546,7 +2135,8 @@ static int setup_dpio(struct dpaa2_eth_p
3628 nctx->desired_cpu = i;
3630 /* Register the new context */
3631 - err = dpaa2_io_service_register(NULL, nctx);
3632 + channel->dpio = dpaa2_io_service_select(i);
3633 + err = dpaa2_io_service_register(channel->dpio, nctx);
3635 dev_dbg(dev, "No affine DPIO for cpu %d\n", i);
3636 /* If no affine DPIO for this core, there's probably
3637 @@ -1586,7 +2176,7 @@ static int setup_dpio(struct dpaa2_eth_p
3641 - dpaa2_io_service_deregister(NULL, nctx);
3642 + dpaa2_io_service_deregister(channel->dpio, nctx);
3644 free_channel(priv, channel);
3646 @@ -1609,7 +2199,7 @@ static void free_dpio(struct dpaa2_eth_p
3647 /* deregister CDAN notifications and free channels */
3648 for (i = 0; i < priv->num_channels; i++) {
3649 ch = priv->channel[i];
3650 - dpaa2_io_service_deregister(NULL, &ch->nctx);
3651 + dpaa2_io_service_deregister(ch->dpio, &ch->nctx);
3652 free_channel(priv, ch);
3655 @@ -1636,8 +2226,7 @@ static void set_fq_affinity(struct dpaa2
3657 struct device *dev = priv->net_dev->dev.parent;
3658 struct dpaa2_eth_fq *fq;
3659 - int rx_cpu, txc_cpu;
3661 + int rx_cpu, txc_cpu, i;
3663 /* For each FQ, pick one channel/CPU to deliver frames to.
3664 * This may well change at runtime, either through irqbalance or
3665 @@ -1649,6 +2238,7 @@ static void set_fq_affinity(struct dpaa2
3669 + case DPAA2_RX_ERR_FQ:
3670 fq->target_cpu = rx_cpu;
3671 rx_cpu = cpumask_next(rx_cpu, &priv->dpio_cpumask);
3672 if (rx_cpu >= nr_cpu_ids)
3673 @@ -1656,6 +2246,7 @@ static void set_fq_affinity(struct dpaa2
3675 case DPAA2_TX_CONF_FQ:
3676 fq->target_cpu = txc_cpu;
3678 txc_cpu = cpumask_next(txc_cpu, &priv->dpio_cpumask);
3679 if (txc_cpu >= nr_cpu_ids)
3680 txc_cpu = cpumask_first(&priv->dpio_cpumask);
3681 @@ -1665,11 +2256,13 @@ static void set_fq_affinity(struct dpaa2
3683 fq->channel = get_affine_channel(priv, fq->target_cpu);
3686 + dpaa2_eth_update_xps(priv);
3689 static void setup_fqs(struct dpaa2_eth_priv *priv)
3694 /* We have one TxConf FQ per Tx flow.
3695 * The number of Tx and Rx queues is the same.
3696 @@ -1681,11 +2274,19 @@ static void setup_fqs(struct dpaa2_eth_p
3697 priv->fq[priv->num_fqs++].flowid = (u16)i;
3700 - for (i = 0; i < dpaa2_eth_queue_count(priv); i++) {
3701 - priv->fq[priv->num_fqs].type = DPAA2_RX_FQ;
3702 - priv->fq[priv->num_fqs].consume = dpaa2_eth_rx;
3703 - priv->fq[priv->num_fqs++].flowid = (u16)i;
3705 + for (i = 0; i < dpaa2_eth_tc_count(priv); i++)
3706 + for (j = 0; j < dpaa2_eth_queue_count(priv); j++) {
3707 + priv->fq[priv->num_fqs].type = DPAA2_RX_FQ;
3708 + priv->fq[priv->num_fqs].consume = dpaa2_eth_rx;
3709 + priv->fq[priv->num_fqs].tc = (u8)i;
3710 + priv->fq[priv->num_fqs++].flowid = (u16)j;
3713 +#ifdef CONFIG_FSL_DPAA2_ETH_USE_ERR_QUEUE
3714 + /* We have exactly one Rx error queue per DPNI */
3715 + priv->fq[priv->num_fqs].type = DPAA2_RX_ERR_FQ;
3716 + priv->fq[priv->num_fqs++].consume = dpaa2_eth_rx_err;
3719 /* For each FQ, decide on which core to process incoming frames */
3720 set_fq_affinity(priv);
3721 @@ -1735,6 +2336,9 @@ static int setup_dpbp(struct dpaa2_eth_p
3723 priv->bpid = dpbp_attrs.bpid;
3725 + /* By default we start with flow control enabled */
3726 + priv->max_bufs_per_ch = DPAA2_ETH_NUM_BUFS_FC / priv->num_channels;
3731 @@ -1756,13 +2360,59 @@ static void free_dpbp(struct dpaa2_eth_p
3732 fsl_mc_object_free(priv->dpbp_dev);
3735 +static int setup_tx_congestion(struct dpaa2_eth_priv *priv)
3737 + struct dpni_congestion_notification_cfg notif_cfg = {0};
3738 + struct device *dev = priv->net_dev->dev.parent;
3741 + priv->cscn_unaligned = kzalloc(DPAA2_CSCN_SIZE + DPAA2_CSCN_ALIGN,
3744 + if (!priv->cscn_unaligned)
3747 + priv->cscn_mem = PTR_ALIGN(priv->cscn_unaligned, DPAA2_CSCN_ALIGN);
3748 + priv->cscn_dma = dma_map_single(dev, priv->cscn_mem, DPAA2_CSCN_SIZE,
3750 + if (dma_mapping_error(dev, priv->cscn_dma)) {
3751 + dev_err(dev, "Error mapping CSCN memory area\n");
3756 + notif_cfg.units = DPNI_CONGESTION_UNIT_BYTES;
3757 + notif_cfg.threshold_entry = DPAA2_ETH_TX_CONG_ENTRY_THRESH;
3758 + notif_cfg.threshold_exit = DPAA2_ETH_TX_CONG_EXIT_THRESH;
3759 + notif_cfg.message_ctx = (u64)priv;
3760 + notif_cfg.message_iova = priv->cscn_dma;
3761 + notif_cfg.notification_mode = DPNI_CONG_OPT_WRITE_MEM_ON_ENTER |
3762 + DPNI_CONG_OPT_WRITE_MEM_ON_EXIT |
3763 + DPNI_CONG_OPT_COHERENT_WRITE;
3764 + err = dpni_set_congestion_notification(priv->mc_io, 0, priv->mc_token,
3765 + DPNI_QUEUE_TX, 0, ¬if_cfg);
3767 + dev_err(dev, "dpni_set_congestion_notification failed\n");
3768 + goto err_set_cong;
3774 + dma_unmap_single(dev, priv->cscn_dma, DPAA2_CSCN_SIZE, DMA_FROM_DEVICE);
3776 + kfree(priv->cscn_unaligned);
3781 /* Configure the DPNI object this interface is associated with */
3782 static int setup_dpni(struct fsl_mc_device *ls_dev)
3784 struct device *dev = &ls_dev->dev;
3785 struct dpaa2_eth_priv *priv;
3786 struct net_device *net_dev;
3787 - struct dpni_buffer_layout buf_layout = {0};
3788 + struct dpni_link_cfg cfg = {0};
3791 net_dev = dev_get_drvdata(dev);
3792 @@ -1772,7 +2422,22 @@ static int setup_dpni(struct fsl_mc_devi
3793 err = dpni_open(priv->mc_io, 0, ls_dev->obj_desc.id, &priv->mc_token);
3795 dev_err(dev, "dpni_open() failed\n");
3800 + /* Check if we can work with this DPNI object */
3801 + err = dpni_get_api_version(priv->mc_io, 0, &priv->dpni_ver_major,
3802 + &priv->dpni_ver_minor);
3804 + dev_err(dev, "dpni_get_api_version() failed\n");
3807 + if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_VER_MAJOR, DPNI_VER_MINOR) < 0) {
3808 + dev_err(dev, "DPNI version %u.%u not supported, need >= %u.%u\n",
3809 + priv->dpni_ver_major, priv->dpni_ver_minor,
3810 + DPNI_VER_MAJOR, DPNI_VER_MINOR);
3815 ls_dev->mc_io = priv->mc_io;
3816 @@ -1781,82 +2446,53 @@ static int setup_dpni(struct fsl_mc_devi
3817 err = dpni_reset(priv->mc_io, 0, priv->mc_token);
3819 dev_err(dev, "dpni_reset() failed\n");
3824 err = dpni_get_attributes(priv->mc_io, 0, priv->mc_token,
3827 dev_err(dev, "dpni_get_attributes() failed (err=%d)\n", err);
3828 - goto err_get_attr;
3832 - /* Configure buffer layouts */
3834 - buf_layout.pass_parser_result = true;
3835 - buf_layout.pass_frame_status = true;
3836 - buf_layout.private_data_size = DPAA2_ETH_SWA_SIZE;
3837 - buf_layout.data_align = DPAA2_ETH_RX_BUF_ALIGN;
3838 - buf_layout.options = DPNI_BUF_LAYOUT_OPT_PARSER_RESULT |
3839 - DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
3840 - DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE |
3841 - DPNI_BUF_LAYOUT_OPT_DATA_ALIGN;
3842 - err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token,
3843 - DPNI_QUEUE_RX, &buf_layout);
3845 - dev_err(dev, "dpni_set_buffer_layout(RX) failed\n");
3846 - goto err_buf_layout;
3848 + err = set_buffer_layout(priv);
3853 - buf_layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS |
3854 - DPNI_BUF_LAYOUT_OPT_PRIVATE_DATA_SIZE;
3855 - err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token,
3856 - DPNI_QUEUE_TX, &buf_layout);
3858 - dev_err(dev, "dpni_set_buffer_layout(TX) failed\n");
3859 - goto err_buf_layout;
3861 + /* Enable congestion notifications for Tx queues */
3862 + err = setup_tx_congestion(priv);
3866 - /* tx-confirm buffer */
3867 - buf_layout.options = DPNI_BUF_LAYOUT_OPT_FRAME_STATUS;
3868 - err = dpni_set_buffer_layout(priv->mc_io, 0, priv->mc_token,
3869 - DPNI_QUEUE_TX_CONFIRM, &buf_layout);
3871 - dev_err(dev, "dpni_set_buffer_layout(TX_CONF) failed\n");
3872 - goto err_buf_layout;
3874 + /* allocate classification rule space */
3875 + priv->cls_rule = kzalloc(sizeof(*priv->cls_rule) *
3876 + dpaa2_eth_fs_count(priv), GFP_KERNEL);
3877 + if (!priv->cls_rule)
3880 - /* Now that we've set our tx buffer layout, retrieve the minimum
3881 - * required tx data offset.
3883 - err = dpni_get_tx_data_offset(priv->mc_io, 0, priv->mc_token,
3884 - &priv->tx_data_offset);
3885 + /* Enable flow control */
3886 + cfg.options = DPNI_LINK_OPT_AUTONEG | DPNI_LINK_OPT_PAUSE;
3887 + priv->tx_pause_frames = true;
3888 + err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &cfg);
3890 - dev_err(dev, "dpni_get_tx_data_offset() failed\n");
3891 - goto err_data_offset;
3892 + dev_err(dev, "dpni_set_link_cfg() failed\n");
3896 - if ((priv->tx_data_offset % 64) != 0)
3897 - dev_warn(dev, "Tx data offset (%d) not a multiple of 64B\n",
3898 - priv->tx_data_offset);
3900 - /* Accommodate software annotation space (SWA) */
3901 - priv->tx_data_offset += DPAA2_ETH_SWA_SIZE;
3910 + kfree(priv->cls_rule);
3912 dpni_close(priv->mc_io, 0, priv->mc_token);
3918 static void free_dpni(struct dpaa2_eth_priv *priv)
3920 + struct device *dev = priv->net_dev->dev.parent;
3923 err = dpni_reset(priv->mc_io, 0, priv->mc_token);
3924 @@ -1865,6 +2501,11 @@ static void free_dpni(struct dpaa2_eth_p
3927 dpni_close(priv->mc_io, 0, priv->mc_token);
3929 + kfree(priv->cls_rule);
3931 + dma_unmap_single(dev, priv->cscn_dma, DPAA2_CSCN_SIZE, DMA_FROM_DEVICE);
3932 + kfree(priv->cscn_unaligned);
3935 static int setup_rx_flow(struct dpaa2_eth_priv *priv,
3936 @@ -1873,11 +2514,10 @@ static int setup_rx_flow(struct dpaa2_et
3937 struct device *dev = priv->net_dev->dev.parent;
3938 struct dpni_queue queue;
3939 struct dpni_queue_id qid;
3940 - struct dpni_taildrop td;
3943 err = dpni_get_queue(priv->mc_io, 0, priv->mc_token,
3944 - DPNI_QUEUE_RX, 0, fq->flowid, &queue, &qid);
3945 + DPNI_QUEUE_RX, fq->tc, fq->flowid, &queue, &qid);
3947 dev_err(dev, "dpni_get_queue(RX) failed\n");
3949 @@ -1890,7 +2530,7 @@ static int setup_rx_flow(struct dpaa2_et
3950 queue.destination.priority = 1;
3951 queue.user_context = (u64)(uintptr_t)fq;
3952 err = dpni_set_queue(priv->mc_io, 0, priv->mc_token,
3953 - DPNI_QUEUE_RX, 0, fq->flowid,
3954 + DPNI_QUEUE_RX, fq->tc, fq->flowid,
3955 DPNI_QUEUE_OPT_USER_CTX | DPNI_QUEUE_OPT_DEST,
3958 @@ -1898,15 +2538,121 @@ static int setup_rx_flow(struct dpaa2_et
3963 - td.threshold = DPAA2_ETH_TAILDROP_THRESH;
3964 - err = dpni_set_taildrop(priv->mc_io, 0, priv->mc_token, DPNI_CP_QUEUE,
3965 - DPNI_QUEUE_RX, 0, fq->flowid, &td);
3967 - dev_err(dev, "dpni_set_threshold() failed\n");
3972 +static int set_queue_taildrop(struct dpaa2_eth_priv *priv,
3973 + struct dpni_taildrop *td)
3975 + struct device *dev = priv->net_dev->dev.parent;
3978 + for (i = 0; i < priv->num_fqs; i++) {
3979 + if (priv->fq[i].type != DPAA2_RX_FQ)
3982 + err = dpni_set_taildrop(priv->mc_io, 0, priv->mc_token,
3983 + DPNI_CP_QUEUE, DPNI_QUEUE_RX,
3984 + priv->fq[i].tc, priv->fq[i].flowid,
3987 + dev_err(dev, "dpni_set_taildrop() failed (%d)\n", err);
3991 + dev_dbg(dev, "%s taildrop for Rx queue id %d tc %d\n",
3992 + (td->enable ? "Enabled" : "Disabled"),
3993 + priv->fq[i].flowid, priv->fq[i].tc);
3999 +static int set_group_taildrop(struct dpaa2_eth_priv *priv,
4000 + struct dpni_taildrop *td)
4002 + struct device *dev = priv->net_dev->dev.parent;
4003 + struct dpni_taildrop disable_td, *tc_td;
4006 + memset(&disable_td, 0, sizeof(struct dpni_taildrop));
4007 + for (i = 0; i < dpaa2_eth_tc_count(priv); i++) {
4008 + if (td->enable && dpaa2_eth_is_pfc_enabled(priv, i))
4009 + /* Do not set taildrop thresholds for PFC-enabled
4010 + * traffic classes. We will enable congestion
4011 + * notifications for them.
4013 + tc_td = &disable_td;
4017 + err = dpni_set_taildrop(priv->mc_io, 0, priv->mc_token,
4018 + DPNI_CP_GROUP, DPNI_QUEUE_RX,
4021 + dev_err(dev, "dpni_set_taildrop() failed (%d)\n", err);
4025 + dev_dbg(dev, "%s taildrop for Rx group tc %d\n",
4026 + (tc_td->enable ? "Enabled" : "Disabled"),
4033 +/* Enable/disable Rx FQ taildrop
4035 + * Rx FQ taildrop is mutually exclusive with flow control and it only gets
4036 + * disabled when FC is active. Depending on FC status, we need to compute
4037 + * the maximum number of buffers in the pool differently, so use the
4038 + * opportunity to update max number of buffers as well.
4040 +int set_rx_taildrop(struct dpaa2_eth_priv *priv)
4042 + enum dpaa2_eth_td_cfg cfg = dpaa2_eth_get_td_type(priv);
4043 + struct dpni_taildrop td_queue, td_group;
4047 + case DPAA2_ETH_TD_NONE:
4048 + memset(&td_queue, 0, sizeof(struct dpni_taildrop));
4049 + memset(&td_group, 0, sizeof(struct dpni_taildrop));
4050 + priv->max_bufs_per_ch = DPAA2_ETH_NUM_BUFS_FC /
4051 + priv->num_channels;
4053 + case DPAA2_ETH_TD_QUEUE:
4054 + memset(&td_group, 0, sizeof(struct dpni_taildrop));
4055 + td_queue.enable = 1;
4056 + td_queue.units = DPNI_CONGESTION_UNIT_BYTES;
4057 + td_queue.threshold = DPAA2_ETH_TAILDROP_THRESH /
4058 + dpaa2_eth_tc_count(priv);
4059 + priv->max_bufs_per_ch = DPAA2_ETH_NUM_BUFS_PER_CH;
4061 + case DPAA2_ETH_TD_GROUP:
4062 + memset(&td_queue, 0, sizeof(struct dpni_taildrop));
4063 + td_group.enable = 1;
4064 + td_group.units = DPNI_CONGESTION_UNIT_FRAMES;
4065 + td_group.threshold = NAPI_POLL_WEIGHT *
4066 + dpaa2_eth_queue_count(priv);
4067 + priv->max_bufs_per_ch = NAPI_POLL_WEIGHT *
4068 + dpaa2_eth_tc_count(priv);
4074 + err = set_queue_taildrop(priv, &td_queue);
4078 + err = set_group_taildrop(priv, &td_group);
4082 + priv->refill_thresh = DPAA2_ETH_REFILL_THRESH(priv);
4087 @@ -1953,23 +2699,88 @@ static int setup_tx_flow(struct dpaa2_et
4091 -/* Hash key is a 5-tuple: IPsrc, IPdst, IPnextproto, L4src, L4dst */
4092 -static const struct dpaa2_eth_hash_fields hash_fields[] = {
4093 +#ifdef CONFIG_FSL_DPAA2_ETH_USE_ERR_QUEUE
4094 +static int setup_rx_err_flow(struct dpaa2_eth_priv *priv,
4095 + struct dpaa2_eth_fq *fq)
4097 + struct device *dev = priv->net_dev->dev.parent;
4098 + struct dpni_queue q = { { 0 } };
4099 + struct dpni_queue_id qid;
4100 + u8 q_opt = DPNI_QUEUE_OPT_USER_CTX | DPNI_QUEUE_OPT_DEST;
4103 + err = dpni_get_queue(priv->mc_io, 0, priv->mc_token,
4104 + DPNI_QUEUE_RX_ERR, 0, 0, &q, &qid);
4106 + dev_err(dev, "dpni_get_queue() failed (%d)\n", err);
4110 + fq->fqid = qid.fqid;
4112 + q.destination.id = fq->channel->dpcon_id;
4113 + q.destination.type = DPNI_DEST_DPCON;
4114 + q.destination.priority = 1;
4115 + q.user_context = (u64)fq;
4116 + err = dpni_set_queue(priv->mc_io, 0, priv->mc_token,
4117 + DPNI_QUEUE_RX_ERR, 0, 0, q_opt, &q);
4119 + dev_err(dev, "dpni_set_queue() failed (%d)\n", err);
4127 +/* default hash key fields */
4128 +static struct dpaa2_eth_dist_fields default_dist_fields[] = {
4131 + .rxnfc_field = RXH_L2DA,
4132 + .cls_prot = NET_PROT_ETH,
4133 + .cls_field = NH_FLD_ETH_DA,
4134 + .id = DPAA2_ETH_DIST_ETHDST,
4137 + .cls_prot = NET_PROT_ETH,
4138 + .cls_field = NH_FLD_ETH_SA,
4139 + .id = DPAA2_ETH_DIST_ETHSRC,
4142 + /* This is the last ethertype field parsed:
4143 + * depending on frame format, it can be the MAC ethertype
4144 + * or the VLAN etype.
4146 + .cls_prot = NET_PROT_ETH,
4147 + .cls_field = NH_FLD_ETH_TYPE,
4148 + .id = DPAA2_ETH_DIST_ETHTYPE,
4152 + .rxnfc_field = RXH_VLAN,
4153 + .cls_prot = NET_PROT_VLAN,
4154 + .cls_field = NH_FLD_VLAN_TCI,
4155 + .id = DPAA2_ETH_DIST_VLAN,
4159 .rxnfc_field = RXH_IP_SRC,
4160 .cls_prot = NET_PROT_IP,
4161 .cls_field = NH_FLD_IP_SRC,
4162 + .id = DPAA2_ETH_DIST_IPSRC,
4165 .rxnfc_field = RXH_IP_DST,
4166 .cls_prot = NET_PROT_IP,
4167 .cls_field = NH_FLD_IP_DST,
4168 + .id = DPAA2_ETH_DIST_IPDST,
4171 .rxnfc_field = RXH_L3_PROTO,
4172 .cls_prot = NET_PROT_IP,
4173 .cls_field = NH_FLD_IP_PROTO,
4174 + .id = DPAA2_ETH_DIST_IPPROTO,
4177 /* Using UDP ports, this is functionally equivalent to raw
4178 @@ -1978,90 +2789,182 @@ static const struct dpaa2_eth_hash_field
4179 .rxnfc_field = RXH_L4_B_0_1,
4180 .cls_prot = NET_PROT_UDP,
4181 .cls_field = NH_FLD_UDP_PORT_SRC,
4182 + .id = DPAA2_ETH_DIST_L4SRC,
4185 .rxnfc_field = RXH_L4_B_2_3,
4186 .cls_prot = NET_PROT_UDP,
4187 .cls_field = NH_FLD_UDP_PORT_DST,
4188 + .id = DPAA2_ETH_DIST_L4DST,
4193 -/* Set RX hash options
4194 - * flags is a combination of RXH_ bits
4196 -static int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags)
4197 +static int legacy_config_dist_key(struct dpaa2_eth_priv *priv,
4198 + dma_addr_t key_iova)
4200 - struct device *dev = net_dev->dev.parent;
4201 - struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
4202 - struct dpkg_profile_cfg cls_cfg;
4203 + struct device *dev = priv->net_dev->dev.parent;
4204 struct dpni_rx_tc_dist_cfg dist_cfg;
4210 - if (!dpaa2_eth_hash_enabled(priv)) {
4211 - dev_dbg(dev, "Hashing support is not enabled\n");
4213 + /* In legacy mode, we can't configure flow steering independently */
4214 + if (!dpaa2_eth_hash_enabled(priv))
4215 + return -EOPNOTSUPP;
4217 + memset(&dist_cfg, 0, sizeof(dist_cfg));
4219 + dist_cfg.key_cfg_iova = key_iova;
4220 + dist_cfg.dist_size = dpaa2_eth_queue_count(priv);
4221 + if (dpaa2_eth_fs_enabled(priv)) {
4222 + dist_cfg.dist_mode = DPNI_DIST_MODE_FS;
4223 + dist_cfg.fs_cfg.miss_action = DPNI_FS_MISS_HASH;
4225 + dist_cfg.dist_mode = DPNI_DIST_MODE_HASH;
4228 - memset(&cls_cfg, 0, sizeof(cls_cfg));
4229 + for (i = 0; i < dpaa2_eth_tc_count(priv); i++) {
4230 + err = dpni_set_rx_tc_dist(priv->mc_io, 0, priv->mc_token, i,
4233 + dev_err(dev, "dpni_set_rx_tc_dist failed\n");
4241 +static int config_hash_key(struct dpaa2_eth_priv *priv, dma_addr_t key_iova)
4243 + struct device *dev = priv->net_dev->dev.parent;
4244 + struct dpni_rx_dist_cfg dist_cfg;
4247 - for (i = 0; i < ARRAY_SIZE(hash_fields); i++) {
4248 - struct dpkg_extract *key =
4249 - &cls_cfg.extracts[cls_cfg.num_extracts];
4250 + if (!dpaa2_eth_hash_enabled(priv))
4251 + return -EOPNOTSUPP;
4253 - if (!(flags & hash_fields[i].rxnfc_field))
4255 + memset(&dist_cfg, 0, sizeof(dist_cfg));
4257 + dist_cfg.key_cfg_iova = key_iova;
4258 + dist_cfg.dist_size = dpaa2_eth_queue_count(priv);
4259 + dist_cfg.enable = true;
4261 + for (i = 0; i < dpaa2_eth_tc_count(priv); i++) {
4264 + err = dpni_set_rx_hash_dist(priv->mc_io, 0,
4265 + priv->mc_token, &dist_cfg);
4267 + dev_err(dev, "dpni_set_rx_hash_dist failed\n");
4275 +static int config_fs_key(struct dpaa2_eth_priv *priv, dma_addr_t key_iova)
4277 + struct device *dev = priv->net_dev->dev.parent;
4278 + struct dpni_rx_dist_cfg dist_cfg;
4281 - if (cls_cfg.num_extracts >= DPKG_MAX_NUM_OF_EXTRACTS) {
4282 - dev_err(dev, "error adding key extraction rule, too many rules?\n");
4284 + if (!dpaa2_eth_fs_enabled(priv))
4285 + return -EOPNOTSUPP;
4287 + memset(&dist_cfg, 0, sizeof(dist_cfg));
4289 + dist_cfg.key_cfg_iova = key_iova;
4290 + dist_cfg.dist_size = dpaa2_eth_queue_count(priv);
4291 + dist_cfg.enable = true;
4293 + for (i = 0; i < dpaa2_eth_tc_count(priv); i++) {
4296 + err = dpni_set_rx_fs_dist(priv->mc_io, 0,
4297 + priv->mc_token, &dist_cfg);
4299 + dev_err(dev, "dpni_set_rx_fs_dist failed\n");
4307 +int dpaa2_eth_set_dist_key(struct dpaa2_eth_priv *priv,
4308 + enum dpaa2_eth_rx_dist type, u32 key_fields)
4310 + struct device *dev = priv->net_dev->dev.parent;
4311 + struct dpkg_profile_cfg cls_cfg;
4312 + struct dpkg_extract *key;
4313 + u32 hash_fields = 0;
4314 + dma_addr_t key_iova;
4318 + memset(&cls_cfg, 0, sizeof(cls_cfg));
4320 + for (i = 0; i < priv->num_dist_fields; i++) {
4321 + if (!(key_fields & priv->dist_fields[i].id))
4324 + key = &cls_cfg.extracts[cls_cfg.num_extracts];
4325 key->type = DPKG_EXTRACT_FROM_HDR;
4326 - key->extract.from_hdr.prot = hash_fields[i].cls_prot;
4327 + key->extract.from_hdr.prot = priv->dist_fields[i].cls_prot;
4328 key->extract.from_hdr.type = DPKG_FULL_FIELD;
4329 - key->extract.from_hdr.field = hash_fields[i].cls_field;
4330 + key->extract.from_hdr.field = priv->dist_fields[i].cls_field;
4331 cls_cfg.num_extracts++;
4333 - priv->rx_hash_fields |= hash_fields[i].rxnfc_field;
4334 + hash_fields |= priv->dist_fields[i].rxnfc_field;
4337 - dma_mem = kzalloc(DPAA2_CLASSIFIER_DMA_SIZE, GFP_KERNEL);
4339 + key_mem = kzalloc(DPAA2_CLASSIFIER_DMA_SIZE, GFP_KERNEL);
4343 - err = dpni_prepare_key_cfg(&cls_cfg, dma_mem);
4344 + err = dpni_prepare_key_cfg(&cls_cfg, key_mem);
4346 dev_err(dev, "dpni_prepare_key_cfg error %d\n", err);
4347 - goto err_prep_key;
4351 - memset(&dist_cfg, 0, sizeof(dist_cfg));
4353 - /* Prepare for setting the rx dist */
4354 - dist_cfg.key_cfg_iova = dma_map_single(dev, dma_mem,
4355 - DPAA2_CLASSIFIER_DMA_SIZE,
4357 - if (dma_mapping_error(dev, dist_cfg.key_cfg_iova)) {
4358 + key_iova = dma_map_single(dev, key_mem, DPAA2_CLASSIFIER_DMA_SIZE,
4360 + if (dma_mapping_error(dev, key_iova)) {
4361 dev_err(dev, "DMA mapping failed\n");
4367 - dist_cfg.dist_size = dpaa2_eth_queue_count(priv);
4368 - dist_cfg.dist_mode = DPNI_DIST_MODE_HASH;
4370 + case DPAA2_ETH_RX_DIST_LEGACY:
4371 + err = legacy_config_dist_key(priv, key_iova);
4373 + case DPAA2_ETH_RX_DIST_HASH:
4374 + err = config_hash_key(priv, key_iova);
4376 + case DPAA2_ETH_RX_DIST_FS:
4377 + err = config_fs_key(priv, key_iova);
4384 - err = dpni_set_rx_tc_dist(priv->mc_io, 0, priv->mc_token, 0, &dist_cfg);
4385 - dma_unmap_single(dev, dist_cfg.key_cfg_iova,
4386 - DPAA2_CLASSIFIER_DMA_SIZE, DMA_TO_DEVICE);
4388 - dev_err(dev, "dpni_set_rx_tc_dist() error %d\n", err);
4389 + dma_unmap_single(dev, key_iova, DPAA2_CLASSIFIER_DMA_SIZE,
4392 + if (err != -EOPNOTSUPP)
4393 + dev_err(dev, "Distribution key config failed\n");
4400 + if (type != DPAA2_ETH_RX_DIST_FS)
4401 + priv->rx_hash_fields = hash_fields;
4408 @@ -2080,6 +2983,7 @@ static int bind_dpni(struct dpaa2_eth_pr
4409 pools_params.num_dpbp = 1;
4410 pools_params.pools[0].dpbp_id = priv->dpbp_dev->obj_desc.id;
4411 pools_params.pools[0].backup_pool = 0;
4412 + pools_params.pools[0].priority_mask = 0xff;
4413 pools_params.pools[0].buffer_size = DPAA2_ETH_RX_BUF_SIZE;
4414 err = dpni_set_pools(priv->mc_io, 0, priv->mc_token, &pools_params);
4416 @@ -2087,17 +2991,36 @@ static int bind_dpni(struct dpaa2_eth_pr
4420 - /* have the interface implicitly distribute traffic based on supported
4422 + /* Verify classification options and disable hashing and/or
4423 + * flow steering support in case of invalid configuration values
4425 - err = dpaa2_eth_set_hash(net_dev, DPAA2_RXH_SUPPORTED);
4427 - netdev_err(net_dev, "Failed to configure hashing\n");
4428 + priv->dist_fields = default_dist_fields;
4429 + priv->num_dist_fields = ARRAY_SIZE(default_dist_fields);
4430 + check_cls_support(priv);
4432 + /* have the interface implicitly distribute traffic based on
4433 + * a static hash key. Also configure flow steering key, if supported.
4434 + * Errors here are not blocking, so just let the called function
4435 + * print its error message and move along.
4437 + if (dpaa2_eth_has_legacy_dist(priv)) {
4438 + dpaa2_eth_set_dist_key(priv, DPAA2_ETH_RX_DIST_LEGACY,
4439 + DPAA2_ETH_DIST_ALL);
4441 + dpaa2_eth_set_dist_key(priv, DPAA2_ETH_RX_DIST_HASH,
4442 + DPAA2_ETH_DIST_DEFAULT_HASH);
4443 + dpaa2_eth_set_dist_key(priv, DPAA2_ETH_RX_DIST_FS,
4444 + DPAA2_ETH_DIST_ALL);
4447 /* Configure handling of error frames */
4448 err_cfg.errors = DPAA2_FAS_RX_ERR_MASK;
4449 err_cfg.set_frame_annotation = 1;
4450 +#ifdef CONFIG_FSL_DPAA2_ETH_USE_ERR_QUEUE
4451 + err_cfg.error_action = DPNI_ERROR_ACTION_SEND_TO_ERROR_QUEUE;
4453 err_cfg.error_action = DPNI_ERROR_ACTION_DISCARD;
4455 err = dpni_set_errors_behavior(priv->mc_io, 0, priv->mc_token,
4458 @@ -2114,6 +3037,11 @@ static int bind_dpni(struct dpaa2_eth_pr
4459 case DPAA2_TX_CONF_FQ:
4460 err = setup_tx_flow(priv, &priv->fq[i]);
4462 +#ifdef CONFIG_FSL_DPAA2_ETH_USE_ERR_QUEUE
4463 + case DPAA2_RX_ERR_FQ:
4464 + err = setup_rx_err_flow(priv, &priv->fq[i]);
4468 dev_err(dev, "Invalid FQ type %d\n", priv->fq[i].type);
4470 @@ -2237,11 +3165,14 @@ static int netdev_init(struct net_device
4472 struct device *dev = net_dev->dev.parent;
4473 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
4474 + u32 options = priv->dpni_attrs.options;
4475 + u64 supported = 0, not_supported = 0;
4476 u8 bcast_addr[ETH_ALEN];
4480 net_dev->netdev_ops = &dpaa2_eth_ops;
4481 + net_dev->ethtool_ops = &dpaa2_ethtool_ops;
4483 err = set_mac_addr(priv);
4485 @@ -2255,14 +3186,14 @@ static int netdev_init(struct net_device
4489 - /* Reserve enough space to align buffer as per hardware requirement;
4490 - * NOTE: priv->tx_data_offset MUST be initialized at this point.
4492 - net_dev->needed_headroom = DPAA2_ETH_NEEDED_HEADROOM(priv);
4494 - /* Set MTU limits */
4495 - net_dev->min_mtu = 68;
4496 + /* Set MTU upper limit; lower limit is default (68B) */
4497 net_dev->max_mtu = DPAA2_ETH_MAX_MTU;
4498 + err = dpni_set_max_frame_length(priv->mc_io, 0, priv->mc_token,
4499 + (u16)DPAA2_ETH_MFL);
4501 + dev_err(dev, "dpni_set_max_frame_length() failed\n");
4505 /* Set actual number of queues in the net device */
4506 num_queues = dpaa2_eth_queue_count(priv);
4507 @@ -2277,12 +3208,23 @@ static int netdev_init(struct net_device
4511 - /* Our .ndo_init will be called herein */
4512 - err = register_netdev(net_dev);
4514 - dev_err(dev, "register_netdev() failed\n");
4517 + /* Capabilities listing */
4518 + supported |= IFF_LIVE_ADDR_CHANGE;
4520 + if (options & DPNI_OPT_NO_MAC_FILTER)
4521 + not_supported |= IFF_UNICAST_FLT;
4523 + supported |= IFF_UNICAST_FLT;
4525 + net_dev->priv_flags |= supported;
4526 + net_dev->priv_flags &= ~not_supported;
4529 + net_dev->features = NETIF_F_RXCSUM |
4530 + NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4531 + NETIF_F_SG | NETIF_F_HIGHDMA |
4533 + net_dev->hw_features = net_dev->features;
4537 @@ -2303,14 +3245,9 @@ static int poll_link_state(void *arg)
4541 -static irqreturn_t dpni_irq0_handler(int irq_num, void *arg)
4543 - return IRQ_WAKE_THREAD;
4546 static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg)
4548 - u32 status = 0, clear = 0;
4550 struct device *dev = (struct device *)arg;
4551 struct fsl_mc_device *dpni_dev = to_fsl_mc_device(dev);
4552 struct net_device *net_dev = dev_get_drvdata(dev);
4553 @@ -2320,18 +3257,12 @@ static irqreturn_t dpni_irq0_handler_thr
4554 DPNI_IRQ_INDEX, &status);
4555 if (unlikely(err)) {
4556 netdev_err(net_dev, "Can't get irq status (err %d)\n", err);
4557 - clear = 0xffffffff;
4559 + return IRQ_HANDLED;
4562 - if (status & DPNI_IRQ_EVENT_LINK_CHANGED) {
4563 - clear |= DPNI_IRQ_EVENT_LINK_CHANGED;
4564 + if (status & DPNI_IRQ_EVENT_LINK_CHANGED)
4565 link_state_update(netdev_priv(net_dev));
4569 - dpni_clear_irq_status(dpni_dev->mc_io, 0, dpni_dev->mc_handle,
4570 - DPNI_IRQ_INDEX, clear);
4574 @@ -2348,8 +3279,7 @@ static int setup_irqs(struct fsl_mc_devi
4576 irq = ls_dev->irqs[0];
4577 err = devm_request_threaded_irq(&ls_dev->dev, irq->msi_desc->irq,
4578 - dpni_irq0_handler,
4579 - dpni_irq0_handler_thread,
4580 + NULL, dpni_irq0_handler_thread,
4581 IRQF_NO_SUSPEND | IRQF_ONESHOT,
4582 dev_name(&ls_dev->dev), &ls_dev->dev);
4584 @@ -2405,6 +3335,393 @@ static void del_ch_napi(struct dpaa2_eth
4588 +/* SysFS support */
4589 +static ssize_t dpaa2_eth_show_tx_shaping(struct device *dev,
4590 + struct device_attribute *attr,
4593 + struct dpaa2_eth_priv *priv = netdev_priv(to_net_dev(dev));
4594 + /* No MC API for getting the shaping config. We're stateful. */
4595 + struct dpni_tx_shaping_cfg *scfg = &priv->shaping_cfg;
4597 + return sprintf(buf, "%u %hu\n", scfg->rate_limit, scfg->max_burst_size);
4600 +static ssize_t dpaa2_eth_write_tx_shaping(struct device *dev,
4601 + struct device_attribute *attr,
4606 + struct dpaa2_eth_priv *priv = netdev_priv(to_net_dev(dev));
4607 + struct dpni_tx_shaping_cfg scfg, ercfg = { 0 };
4609 + items = sscanf(buf, "%u %hu", &scfg.rate_limit, &scfg.max_burst_size);
4611 + pr_err("Expected format: \"rate_limit(Mbps) max_burst_size(bytes)\"\n");
4614 + /* Size restriction as per MC API documentation */
4615 + if (scfg.max_burst_size > DPAA2_ETH_MAX_BURST_SIZE) {
4616 + pr_err("max_burst_size must be <= %d\n",
4617 + DPAA2_ETH_MAX_BURST_SIZE);
4621 + err = dpni_set_tx_shaping(priv->mc_io, 0, priv->mc_token, &scfg,
4624 + dev_err(dev, "dpni_set_tx_shaping() failed\n");
4627 + /* If successful, save the current configuration for future inquiries */
4628 + priv->shaping_cfg = scfg;
4633 +static struct device_attribute dpaa2_eth_attrs[] = {
4634 + __ATTR(tx_shaping,
4636 + dpaa2_eth_show_tx_shaping,
4637 + dpaa2_eth_write_tx_shaping),
4640 +static void dpaa2_eth_sysfs_init(struct device *dev)
4644 + for (i = 0; i < ARRAY_SIZE(dpaa2_eth_attrs); i++) {
4645 + err = device_create_file(dev, &dpaa2_eth_attrs[i]);
4647 + dev_err(dev, "ERROR creating sysfs file\n");
4655 + device_remove_file(dev, &dpaa2_eth_attrs[--i]);
4658 +static void dpaa2_eth_sysfs_remove(struct device *dev)
4662 + for (i = 0; i < ARRAY_SIZE(dpaa2_eth_attrs); i++)
4663 + device_remove_file(dev, &dpaa2_eth_attrs[i]);
4666 +#ifdef CONFIG_FSL_DPAA2_ETH_DCB
4667 +static int dpaa2_eth_dcbnl_ieee_getpfc(struct net_device *net_dev,
4668 + struct ieee_pfc *pfc)
4670 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
4671 + struct dpni_congestion_notification_cfg notification_cfg;
4672 + struct dpni_link_state state;
4675 + priv->pfc.pfc_cap = dpaa2_eth_tc_count(priv);
4677 + err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state);
4679 + netdev_err(net_dev, "ERROR %d getting link state", err);
4683 + if (!(state.options & DPNI_LINK_OPT_PFC_PAUSE))
4686 + priv->pfc.pfc_en = 0;
4687 + for (i = 0; i < dpaa2_eth_tc_count(priv); i++) {
4688 + err = dpni_get_congestion_notification(priv->mc_io, 0,
4691 + i, ¬ification_cfg);
4693 + netdev_err(net_dev, "Error %d getting congestion notif",
4698 + if (notification_cfg.threshold_entry)
4699 + priv->pfc.pfc_en |= 1 << i;
4702 + memcpy(pfc, &priv->pfc, sizeof(priv->pfc));
4707 +/* Configure ingress classification based on VLAN PCP */
4708 +static int set_vlan_qos(struct dpaa2_eth_priv *priv)
4710 + struct device *dev = priv->net_dev->dev.parent;
4711 + struct dpkg_profile_cfg kg_cfg = {0};
4712 + struct dpni_qos_tbl_cfg qos_cfg = {0};
4713 + struct dpni_rule_cfg key_params;
4714 + u8 *params_iova, *key, *mask = NULL;
4715 + /* We only need the trailing 16 bits, without the TPID */
4716 + u8 key_size = VLAN_HLEN / 2;
4717 + int err = 0, i, j = 0;
4719 + if (priv->vlan_clsf_set)
4722 + params_iova = kzalloc(DPAA2_CLASSIFIER_DMA_SIZE, GFP_KERNEL);
4726 + kg_cfg.num_extracts = 1;
4727 + kg_cfg.extracts[0].type = DPKG_EXTRACT_FROM_HDR;
4728 + kg_cfg.extracts[0].extract.from_hdr.prot = NET_PROT_VLAN;
4729 + kg_cfg.extracts[0].extract.from_hdr.type = DPKG_FULL_FIELD;
4730 + kg_cfg.extracts[0].extract.from_hdr.field = NH_FLD_VLAN_TCI;
4732 + err = dpni_prepare_key_cfg(&kg_cfg, params_iova);
4734 + dev_err(dev, "dpkg_prepare_key_cfg failed: %d\n", err);
4738 + /* Set QoS table */
4739 + qos_cfg.default_tc = 0;
4740 + qos_cfg.discard_on_miss = 0;
4741 + qos_cfg.key_cfg_iova = dma_map_single(dev, params_iova,
4742 + DPAA2_CLASSIFIER_DMA_SIZE,
4744 + if (dma_mapping_error(dev, qos_cfg.key_cfg_iova)) {
4745 + dev_err(dev, "%s: DMA mapping failed\n", __func__);
4749 + err = dpni_set_qos_table(priv->mc_io, 0, priv->mc_token, &qos_cfg);
4750 + dma_unmap_single(dev, qos_cfg.key_cfg_iova,
4751 + DPAA2_CLASSIFIER_DMA_SIZE, DMA_TO_DEVICE);
4754 + dev_err(dev, "dpni_set_qos_table failed: %d\n", err);
4758 + key_params.key_size = key_size;
4760 + if (dpaa2_eth_fs_mask_enabled(priv)) {
4761 + mask = kzalloc(key_size, GFP_KERNEL);
4765 + *mask = cpu_to_be16(VLAN_PRIO_MASK);
4767 + key_params.mask_iova = dma_map_single(dev, mask, key_size,
4769 + if (dma_mapping_error(dev, key_params.mask_iova)) {
4770 + dev_err(dev, "DMA mapping failed %s\n", __func__);
4772 + goto out_free_mask;
4775 + key_params.mask_iova = 0;
4778 + key = kzalloc(key_size, GFP_KERNEL);
4780 + goto out_cleanup_mask;
4782 + key_params.key_iova = dma_map_single(dev, key, key_size,
4784 + if (dma_mapping_error(dev, key_params.key_iova)) {
4785 + dev_err(dev, "%s: DMA mapping failed\n", __func__);
4787 + goto out_free_key;
4790 + for (i = 0; i < dpaa2_eth_tc_count(priv); i++) {
4791 + *key = cpu_to_be16(i << VLAN_PRIO_SHIFT);
4793 + dma_sync_single_for_device(dev, key_params.key_iova,
4794 + key_size, DMA_TO_DEVICE);
4796 + err = dpni_add_qos_entry(priv->mc_io, 0, priv->mc_token,
4797 + &key_params, i, j++);
4799 + dev_err(dev, "dpni_add_qos_entry failed: %d\n", err);
4804 + priv->vlan_clsf_set = true;
4805 + dev_dbg(dev, "Vlan PCP QoS classification set\n");
4809 + for (j = 0; j < i; j++) {
4810 + *key = cpu_to_be16(j << VLAN_PRIO_SHIFT);
4812 + dma_sync_single_for_device(dev, key_params.key_iova, key_size,
4815 + err = dpni_remove_qos_entry(priv->mc_io, 0, priv->mc_token,
4818 + dev_err(dev, "dpni_remove_qos_entry failed: %d\n", err);
4822 + dma_unmap_single(dev, key_params.key_iova, key_size, DMA_TO_DEVICE);
4826 + if (key_params.mask_iova)
4827 + dma_unmap_single(dev, key_params.mask_iova, key_size,
4832 + kfree(params_iova);
4836 +static int dpaa2_eth_dcbnl_ieee_setpfc(struct net_device *net_dev,
4837 + struct ieee_pfc *pfc)
4839 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
4840 + struct dpni_congestion_notification_cfg notification_cfg = {0};
4841 + struct dpni_link_state state = {0};
4842 + struct dpni_link_cfg cfg = {0};
4843 + struct ieee_pfc old_pfc;
4846 + if (dpaa2_eth_tc_count(priv) == 1) {
4847 + netdev_dbg(net_dev, "DPNI has 1 TC, PFC configuration N/A\n");
4851 + /* Zero out pfc_enabled prios greater than tc_count */
4852 + pfc->pfc_en &= (1 << dpaa2_eth_tc_count(priv)) - 1;
4854 + if (priv->pfc.pfc_en == pfc->pfc_en)
4855 + /* Same enabled mask, nothing to be done */
4858 + err = set_vlan_qos(priv);
4862 + err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state);
4864 + netdev_err(net_dev, "ERROR %d getting link state", err);
4868 + cfg.rate = state.rate;
4869 + cfg.options = state.options;
4871 + cfg.options |= DPNI_LINK_OPT_PFC_PAUSE;
4873 + cfg.options &= ~DPNI_LINK_OPT_PFC_PAUSE;
4875 + err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &cfg);
4877 + netdev_err(net_dev, "ERROR %d setting link cfg", err);
4881 + memcpy(&old_pfc, &priv->pfc, sizeof(priv->pfc));
4882 + memcpy(&priv->pfc, pfc, sizeof(priv->pfc));
4884 + err = set_rx_taildrop(priv);
4886 + goto out_restore_config;
4888 + /* configure congestion notifications */
4889 + notification_cfg.notification_mode = DPNI_CONG_OPT_FLOW_CONTROL;
4890 + notification_cfg.units = DPNI_CONGESTION_UNIT_FRAMES;
4891 + notification_cfg.message_iova = 0ULL;
4892 + notification_cfg.message_ctx = 0ULL;
4894 + for (i = 0; i < dpaa2_eth_tc_count(priv); i++) {
4895 + if (dpaa2_eth_is_pfc_enabled(priv, i)) {
4896 + notification_cfg.threshold_entry = NAPI_POLL_WEIGHT;
4897 + notification_cfg.threshold_exit = NAPI_POLL_WEIGHT / 2;
4899 + notification_cfg.threshold_entry = 0;
4900 + notification_cfg.threshold_exit = 0;
4903 + err = dpni_set_congestion_notification(priv->mc_io, 0,
4906 + i, ¬ification_cfg);
4908 + netdev_err(net_dev, "Error %d setting congestion notif",
4910 + goto out_restore_config;
4913 + netdev_dbg(net_dev, "%s congestion notifications for tc %d\n",
4914 + (notification_cfg.threshold_entry ?
4915 + "Enabled" : "Disabled"), i);
4920 +out_restore_config:
4921 + memcpy(&priv->pfc, &old_pfc, sizeof(priv->pfc));
4925 +static u8 dpaa2_eth_dcbnl_getdcbx(struct net_device *net_dev)
4927 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
4929 + return priv->dcbx_mode;
4932 +static u8 dpaa2_eth_dcbnl_setdcbx(struct net_device *net_dev, u8 mode)
4934 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
4936 + priv->dcbx_mode = mode;
4940 +static u8 dpaa2_eth_dcbnl_getcap(struct net_device *net_dev, int capid, u8 *cap)
4942 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
4945 + case DCB_CAP_ATTR_PFC:
4948 + case DCB_CAP_ATTR_PFC_TCS:
4949 + /* bitmap where each bit represents a number of traffic
4950 + * classes the device can be configured to use for Priority
4953 + *cap = 1 << (dpaa2_eth_tc_count(priv) - 1);
4955 + case DCB_CAP_ATTR_DCBX:
4956 + *cap = priv->dcbx_mode;
4966 +const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops = {
4967 + .ieee_getpfc = dpaa2_eth_dcbnl_ieee_getpfc,
4968 + .ieee_setpfc = dpaa2_eth_dcbnl_ieee_setpfc,
4969 + .getdcbx = dpaa2_eth_dcbnl_getdcbx,
4970 + .setdcbx = dpaa2_eth_dcbnl_setdcbx,
4971 + .getcap = dpaa2_eth_dcbnl_getcap,
4975 static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
4978 @@ -2415,7 +3732,7 @@ static int dpaa2_eth_probe(struct fsl_mc
4979 dev = &dpni_dev->dev;
4982 - net_dev = alloc_etherdev_mq(sizeof(*priv), DPAA2_ETH_MAX_TX_QUEUES);
4983 + net_dev = alloc_etherdev_mq(sizeof(*priv), DPAA2_ETH_MAX_NETDEV_QUEUES);
4985 dev_err(dev, "alloc_etherdev_mq() failed\n");
4987 @@ -2433,7 +3750,10 @@ static int dpaa2_eth_probe(struct fsl_mc
4988 err = fsl_mc_portal_allocate(dpni_dev, FSL_MC_IO_ATOMIC_CONTEXT_PORTAL,
4991 - dev_err(dev, "MC portal allocation failed\n");
4992 + if (err == -ENXIO)
4993 + err = -EPROBE_DEFER;
4995 + dev_err(dev, "MC portal allocation failed\n");
4996 goto err_portal_alloc;
4999 @@ -2456,9 +3776,6 @@ static int dpaa2_eth_probe(struct fsl_mc
5003 - /* Add a NAPI context for each channel */
5004 - add_ch_napi(priv);
5006 /* Percpu statistics */
5007 priv->percpu_stats = alloc_percpu(*priv->percpu_stats);
5008 if (!priv->percpu_stats) {
5009 @@ -2491,7 +3808,14 @@ static int dpaa2_eth_probe(struct fsl_mc
5011 goto err_alloc_rings;
5013 - net_dev->ethtool_ops = &dpaa2_ethtool_ops;
5014 +#ifdef CONFIG_FSL_DPAA2_ETH_DCB
5015 + net_dev->dcbnl_ops = &dpaa2_eth_dcbnl_ops;
5016 + priv->dcbx_mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
5019 + /* Add a NAPI context for each channel */
5020 + add_ch_napi(priv);
5021 + enable_ch_napi(priv);
5023 err = setup_irqs(dpni_dev);
5025 @@ -2499,25 +3823,41 @@ static int dpaa2_eth_probe(struct fsl_mc
5026 priv->poll_thread = kthread_run(poll_link_state, priv,
5027 "%s_poll_link", net_dev->name);
5028 if (IS_ERR(priv->poll_thread)) {
5029 - netdev_err(net_dev, "Error starting polling thread\n");
5030 + dev_err(dev, "Error starting polling thread\n");
5031 goto err_poll_thread;
5033 priv->do_link_poll = true;
5036 + err = register_netdev(net_dev);
5038 + dev_err(dev, "register_netdev() failed\n");
5039 + goto err_netdev_reg;
5042 + dpaa2_eth_sysfs_init(&net_dev->dev);
5043 +#ifdef CONFIG_FSL_DPAA2_ETH_DEBUGFS
5044 + dpaa2_dbg_add(priv);
5047 dev_info(dev, "Probed interface %s\n", net_dev->name);
5051 + if (priv->do_link_poll)
5052 + kthread_stop(priv->poll_thread);
5054 + fsl_mc_free_irqs(dpni_dev);
5059 - unregister_netdev(net_dev);
5061 free_percpu(priv->percpu_extras);
5062 err_alloc_percpu_extras:
5063 free_percpu(priv->percpu_stats);
5064 err_alloc_percpu_stats:
5065 + disable_ch_napi(priv);
5069 @@ -2544,8 +3884,15 @@ static int dpaa2_eth_remove(struct fsl_m
5070 net_dev = dev_get_drvdata(dev);
5071 priv = netdev_priv(net_dev);
5073 +#ifdef CONFIG_FSL_DPAA2_ETH_DEBUGFS
5074 + dpaa2_dbg_remove(priv);
5076 + dpaa2_eth_sysfs_remove(&net_dev->dev);
5078 unregister_netdev(net_dev);
5079 - dev_info(net_dev->dev.parent, "Removed interface %s\n", net_dev->name);
5081 + disable_ch_napi(priv);
5082 + del_ch_napi(priv);
5084 if (priv->do_link_poll)
5085 kthread_stop(priv->poll_thread);
5086 @@ -2555,8 +3902,6 @@ static int dpaa2_eth_remove(struct fsl_m
5088 free_percpu(priv->percpu_stats);
5089 free_percpu(priv->percpu_extras);
5091 - del_ch_napi(priv);
5095 @@ -2566,6 +3911,8 @@ static int dpaa2_eth_remove(struct fsl_m
5096 dev_set_drvdata(dev, NULL);
5097 free_netdev(net_dev);
5099 + dev_dbg(net_dev->dev.parent, "Removed interface %s\n", net_dev->name);
5104 @@ -2588,4 +3935,34 @@ static struct fsl_mc_driver dpaa2_eth_dr
5105 .match_id_table = dpaa2_eth_match_id_table
5108 -module_fsl_mc_driver(dpaa2_eth_driver);
5109 +static int __init dpaa2_eth_driver_init(void)
5113 + dpaa2_eth_dbg_init();
5114 + err = fsl_mc_driver_register(&dpaa2_eth_driver);
5116 + goto out_debugfs_err;
5118 + err = dpaa2_ceetm_register();
5120 + goto out_ceetm_err;
5125 + fsl_mc_driver_unregister(&dpaa2_eth_driver);
5127 + dpaa2_eth_dbg_exit();
5131 +static void __exit dpaa2_eth_driver_exit(void)
5133 + dpaa2_ceetm_unregister();
5134 + fsl_mc_driver_unregister(&dpaa2_eth_driver);
5135 + dpaa2_eth_dbg_exit();
5138 +module_init(dpaa2_eth_driver_init);
5139 +module_exit(dpaa2_eth_driver_exit);
5140 --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h
5141 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h
5143 #ifndef __DPAA2_ETH_H
5144 #define __DPAA2_ETH_H
5146 +#include <linux/dcbnl.h>
5147 #include <linux/netdevice.h>
5148 #include <linux/if_vlan.h>
5151 #include "dpni-cmd.h"
5153 #include "dpaa2-eth-trace.h"
5154 +#include "dpaa2-eth-debugfs.h"
5156 +#define DPAA2_WRIOP_VERSION(x, y, z) ((x) << 10 | (y) << 5 | (z) << 0)
5158 #define DPAA2_ETH_STORE_SIZE 16
5160 +/* We set a max threshold for how many Tx confirmations we should process
5161 + * on a NAPI poll call, they take less processing time.
5163 +#define TX_CONF_PER_NAPI_POLL 256
5165 /* Maximum number of scatter-gather entries in an ingress frame,
5166 * considering the maximum receive frame size is 64K
5169 /* Convert L3 MTU to L2 MFL */
5170 #define DPAA2_ETH_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN)
5172 +/* Maximum burst size value for Tx shaping */
5173 +#define DPAA2_ETH_MAX_BURST_SIZE 0xF7FF
5175 +/* Maximum number of buffers that can be acquired/released through a single
5178 +#define DPAA2_ETH_BUFS_PER_CMD 7
5180 /* Set the taildrop threshold (in bytes) to allow the enqueue of several jumbo
5181 * frames in the Rx queues (length of the current frame is not
5182 * taken into account when making the taildrop decision)
5184 * to accommodate the buffer refill delay.
5186 #define DPAA2_ETH_MAX_FRAMES_PER_QUEUE (DPAA2_ETH_TAILDROP_THRESH / 64)
5187 -#define DPAA2_ETH_NUM_BUFS (DPAA2_ETH_MAX_FRAMES_PER_QUEUE + 256)
5188 -#define DPAA2_ETH_REFILL_THRESH DPAA2_ETH_MAX_FRAMES_PER_QUEUE
5189 +#define DPAA2_ETH_NUM_BUFS_PER_CH (DPAA2_ETH_MAX_FRAMES_PER_QUEUE + 256)
5190 +#define DPAA2_ETH_REFILL_THRESH(priv) \
5191 + ((priv)->max_bufs_per_ch - DPAA2_ETH_BUFS_PER_CMD)
5193 -/* Maximum number of buffers that can be acquired/released through a single
5196 -#define DPAA2_ETH_BUFS_PER_CMD 7
5197 +/* Global buffer quota in case flow control is enabled */
5198 +#define DPAA2_ETH_NUM_BUFS_FC 256
5200 +/* Hardware requires alignment for ingress/egress buffer addresses */
5201 +#define DPAA2_ETH_TX_BUF_ALIGN 64
5203 -/* Hardware requires alignment for ingress/egress buffer addresses
5204 - * and ingress buffer lengths.
5205 +/* Due to a limitation in WRIOP 1.0.0, the RX buffer data must be aligned
5206 + * to 256B. For newer revisions, the requirement is only for 64B alignment
5208 +#define DPAA2_ETH_RX_BUF_ALIGN_REV1 256
5209 +#define DPAA2_ETH_RX_BUF_ALIGN 64
5211 #define DPAA2_ETH_RX_BUF_SIZE 2048
5212 -#define DPAA2_ETH_TX_BUF_ALIGN 64
5213 -#define DPAA2_ETH_RX_BUF_ALIGN 256
5214 -#define DPAA2_ETH_NEEDED_HEADROOM(p_priv) \
5215 - ((p_priv)->tx_data_offset + DPAA2_ETH_TX_BUF_ALIGN)
5217 -/* Hardware only sees DPAA2_ETH_RX_BUF_SIZE, but we need to allocate ingress
5218 - * buffers large enough to allow building an skb around them and also account
5219 - * for alignment restrictions
5221 -#define DPAA2_ETH_BUF_RAW_SIZE \
5222 - (DPAA2_ETH_RX_BUF_SIZE + \
5223 - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + \
5224 - DPAA2_ETH_RX_BUF_ALIGN)
5225 +#define DPAA2_ETH_SKB_SIZE \
5226 + (DPAA2_ETH_RX_BUF_SIZE + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
5228 +/* PTP nominal frequency 1GHz */
5229 +#define DPAA2_PTP_NOMINAL_FREQ_PERIOD_NS 1
5231 +/* Hardware annotation area in RX/TX buffers */
5232 +#define DPAA2_ETH_RX_HWA_SIZE 64
5233 +#define DPAA2_ETH_TX_HWA_SIZE 128
5235 /* We are accommodating a skb backpointer and some S/G info
5236 * in the frame's software annotation. The hardware
5237 @@ -104,12 +122,32 @@
5239 #define DPAA2_ETH_SWA_SIZE 64
5241 +/* We store different information in the software annotation area of a Tx frame
5242 + * based on what type of frame it is
5244 +enum dpaa2_eth_swa_type {
5245 + DPAA2_ETH_SWA_SINGLE,
5247 + DPAA2_ETH_SWA_XDP,
5250 /* Must keep this struct smaller than DPAA2_ETH_SWA_SIZE */
5251 struct dpaa2_eth_swa {
5252 - struct sk_buff *skb;
5253 - struct scatterlist *scl;
5256 + enum dpaa2_eth_swa_type type;
5259 + struct sk_buff *skb;
5262 + struct sk_buff *skb;
5263 + struct scatterlist *scl;
5273 /* Annotation valid bits in FD FRC */
5274 @@ -120,23 +158,14 @@ struct dpaa2_eth_swa {
5275 #define DPAA2_FD_FRC_FASWOV 0x0800
5276 #define DPAA2_FD_FRC_FAICFDV 0x0400
5278 -/* Error bits in FD CTRL */
5279 -#define DPAA2_FD_CTRL_UFD 0x00000004
5280 -#define DPAA2_FD_CTRL_SBE 0x00000008
5281 -#define DPAA2_FD_CTRL_FSE 0x00000020
5282 -#define DPAA2_FD_CTRL_FAERR 0x00000040
5284 -#define DPAA2_FD_RX_ERR_MASK (DPAA2_FD_CTRL_SBE | \
5285 - DPAA2_FD_CTRL_FAERR)
5286 -#define DPAA2_FD_TX_ERR_MASK (DPAA2_FD_CTRL_UFD | \
5287 - DPAA2_FD_CTRL_SBE | \
5288 - DPAA2_FD_CTRL_FSE | \
5289 - DPAA2_FD_CTRL_FAERR)
5290 +#define DPAA2_FD_RX_ERR_MASK (FD_CTRL_SBE | FD_CTRL_FAERR)
5291 +#define DPAA2_FD_TX_ERR_MASK (FD_CTRL_UFD | \
5296 /* Annotation bits in FD CTRL */
5297 #define DPAA2_FD_CTRL_ASAL 0x00020000 /* ASAL = 128 */
5298 -#define DPAA2_FD_CTRL_PTA 0x00800000
5299 -#define DPAA2_FD_CTRL_PTV1 0x00400000
5301 /* Frame annotation status */
5303 @@ -144,7 +173,7 @@ struct dpaa2_fas {
5310 /* Frame annotation status word is located in the first 8 bytes
5311 * of the buffer's hardware annoatation area
5312 @@ -152,11 +181,45 @@ struct dpaa2_fas {
5313 #define DPAA2_FAS_OFFSET 0
5314 #define DPAA2_FAS_SIZE (sizeof(struct dpaa2_fas))
5316 +/* Timestamp is located in the next 8 bytes of the buffer's
5317 + * hardware annotation area
5319 +#define DPAA2_TS_OFFSET 0x8
5321 +/* Frame annotation egress action descriptor */
5322 +#define DPAA2_FAEAD_OFFSET 0x58
5324 +struct dpaa2_faead {
5329 +#define DPAA2_FAEAD_A2V 0x20000000
5330 +#define DPAA2_FAEAD_A4V 0x08000000
5331 +#define DPAA2_FAEAD_UPDV 0x00001000
5332 +#define DPAA2_FAEAD_EBDDV 0x00002000
5333 +#define DPAA2_FAEAD_UPD 0x00000010
5335 /* Accessors for the hardware annotation fields that we use */
5336 -#define dpaa2_get_hwa(buf_addr) \
5337 - ((void *)(buf_addr) + DPAA2_ETH_SWA_SIZE)
5338 -#define dpaa2_get_fas(buf_addr) \
5339 - (struct dpaa2_fas *)(dpaa2_get_hwa(buf_addr) + DPAA2_FAS_OFFSET)
5340 +static inline void *dpaa2_get_hwa(void *buf_addr, bool swa)
5342 + return buf_addr + (swa ? DPAA2_ETH_SWA_SIZE : 0);
5345 +static inline struct dpaa2_fas *dpaa2_get_fas(void *buf_addr, bool swa)
5347 + return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAS_OFFSET;
5350 +static inline u64 *dpaa2_get_ts(void *buf_addr, bool swa)
5352 + return dpaa2_get_hwa(buf_addr, swa) + DPAA2_TS_OFFSET;
5355 +static inline struct dpaa2_faead *dpaa2_get_faead(void *buf_addr, bool swa)
5357 + return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAEAD_OFFSET;
5360 /* Error and status bits in the frame annotation status word */
5361 /* Debug frame, otherwise supposed to be discarded */
5362 @@ -203,11 +266,6 @@ struct dpaa2_fas {
5367 -#define DPAA2_FAS_TX_ERR_MASK (DPAA2_FAS_KSE | \
5368 - DPAA2_FAS_EOFHE | \
5369 - DPAA2_FAS_MNLE | \
5372 /* Time in milliseconds between link state updates */
5373 #define DPAA2_ETH_LINK_STATE_REFRESH 1000
5374 @@ -218,6 +276,14 @@ struct dpaa2_fas {
5376 #define DPAA2_ETH_ENQUEUE_RETRIES 10
5378 +/* Tx congestion entry & exit thresholds, in number of bytes.
5379 + * We allow a maximum of 512KB worth of frames pending processing on the Tx
5380 + * queues of an interface
5382 +#define DPAA2_ETH_TX_CONG_ENTRY_THRESH (512 * 1024)
5383 +#define DPAA2_ETH_TX_CONG_EXIT_THRESH \
5384 + (DPAA2_ETH_TX_CONG_ENTRY_THRESH * 9 / 10)
5386 /* Driver statistics, other than those in struct rtnl_link_stats64.
5387 * These are usually collected per-CPU and aggregated by ethtool.
5389 @@ -226,6 +292,7 @@ struct dpaa2_eth_drv_stats {
5390 __u64 tx_conf_bytes;
5393 + __u64 tx_reallocs;
5396 /* Enqueues retried due to portal busy */
5397 @@ -236,6 +303,8 @@ struct dpaa2_eth_drv_stats {
5398 struct dpaa2_eth_fq_stats {
5399 /* Number of frames received on this queue */
5401 + /* Number of times this queue entered congestion */
5402 + __u64 congestion_entry;
5405 /* Per-channel statistics */
5406 @@ -250,17 +319,23 @@ struct dpaa2_eth_ch_stats {
5410 +#define DPAA2_ETH_MAX_TCS 8
5412 /* Maximum number of queues associated with a DPNI */
5413 -#define DPAA2_ETH_MAX_RX_QUEUES 16
5414 -#define DPAA2_ETH_MAX_TX_QUEUES NR_CPUS
5415 +#define DPAA2_ETH_MAX_RX_QUEUES (DPNI_MAX_DIST_SIZE * DPAA2_ETH_MAX_TCS)
5416 +#define DPAA2_ETH_MAX_TX_QUEUES DPNI_MAX_SENDERS
5417 +#define DPAA2_ETH_MAX_RX_ERR_QUEUES 1
5418 #define DPAA2_ETH_MAX_QUEUES (DPAA2_ETH_MAX_RX_QUEUES + \
5419 - DPAA2_ETH_MAX_TX_QUEUES)
5420 + DPAA2_ETH_MAX_TX_QUEUES + \
5421 + DPAA2_ETH_MAX_RX_ERR_QUEUES)
5422 +#define DPAA2_ETH_MAX_NETDEV_QUEUES (DPNI_MAX_DIST_SIZE * DPAA2_ETH_MAX_TCS)
5424 -#define DPAA2_ETH_MAX_DPCONS NR_CPUS
5425 +#define DPAA2_ETH_MAX_DPCONS 16
5427 enum dpaa2_eth_fq_type {
5433 struct dpaa2_eth_priv;
5434 @@ -269,6 +344,7 @@ struct dpaa2_eth_fq {
5440 struct dpaa2_eth_channel *channel;
5441 enum dpaa2_eth_fq_type type;
5442 @@ -276,7 +352,8 @@ struct dpaa2_eth_fq {
5443 void (*consume)(struct dpaa2_eth_priv *,
5444 struct dpaa2_eth_channel *,
5445 const struct dpaa2_fd *,
5446 - struct napi_struct *);
5447 + struct napi_struct *,
5449 struct dpaa2_eth_fq_stats stats;
5452 @@ -285,24 +362,53 @@ struct dpaa2_eth_channel {
5453 struct fsl_mc_device *dpcon;
5457 struct napi_struct napi;
5458 + struct dpaa2_io *dpio;
5459 struct dpaa2_io_store *store;
5460 struct dpaa2_eth_priv *priv;
5462 struct dpaa2_eth_ch_stats stats;
5463 + struct bpf_prog *xdp_prog;
5464 + u64 rel_buf_array[DPAA2_ETH_BUFS_PER_CMD];
5469 +struct dpaa2_eth_cls_rule {
5470 + struct ethtool_rx_flow_spec fs;
5474 -struct dpaa2_eth_hash_fields {
5475 +struct dpaa2_eth_dist_fields {
5477 enum net_prot cls_prot;
5484 /* Driver private data */
5485 struct dpaa2_eth_priv {
5486 struct net_device *net_dev;
5487 + /* Standard statistics */
5488 + struct rtnl_link_stats64 __percpu *percpu_stats;
5489 + /* Extra stats, in addition to the ones known by the kernel */
5490 + struct dpaa2_eth_drv_stats __percpu *percpu_extras;
5491 + bool ts_tx_en; /* Tx timestamping enabled */
5492 + bool ts_rx_en; /* Rx timestamping enabled */
5493 + u16 tx_data_offset;
5497 + struct iommu_domain *iommu_domain;
5498 + int max_bufs_per_ch;
5499 + int refill_thresh;
5500 + bool has_xdp_prog;
5502 + void *cscn_mem; /* Tx congestion notifications are written here */
5503 + void *cscn_unaligned;
5504 + dma_addr_t cscn_dma;
5507 struct dpaa2_eth_fq fq[DPAA2_ETH_MAX_QUEUES];
5508 @@ -311,51 +417,193 @@ struct dpaa2_eth_priv {
5509 struct dpaa2_eth_channel *channel[DPAA2_ETH_MAX_DPCONS];
5511 struct dpni_attr dpni_attrs;
5512 - u16 tx_data_offset;
5514 + u16 dpni_ver_major;
5515 + u16 dpni_ver_minor;
5516 struct fsl_mc_device *dpbp_dev;
5518 - struct iommu_domain *iommu_domain;
5521 struct fsl_mc_io *mc_io;
5522 /* Cores which have an affine DPIO/DPCON.
5523 * This is the cpu set on which Rx and Tx conf frames are processed
5525 struct cpumask dpio_cpumask;
5527 - /* Standard statistics */
5528 - struct rtnl_link_stats64 __percpu *percpu_stats;
5529 - /* Extra stats, in addition to the ones known by the kernel */
5530 - struct dpaa2_eth_drv_stats __percpu *percpu_extras;
5534 struct dpni_link_state link_state;
5536 struct task_struct *poll_thread;
5538 + /* Rx distribution (hash and flow steering) header fields
5539 + * supported by the driver
5541 + struct dpaa2_eth_dist_fields *dist_fields;
5542 + u8 num_dist_fields;
5543 /* enabled ethtool hashing bits */
5545 +#ifdef CONFIG_FSL_DPAA2_ETH_DEBUGFS
5546 + struct dpaa2_debugfs dbg;
5548 + /* array of classification rules */
5549 + struct dpaa2_eth_cls_rule *cls_rule;
5550 + struct dpni_tx_shaping_cfg shaping_cfg;
5553 + struct ieee_pfc pfc;
5554 + bool vlan_clsf_set;
5555 + bool tx_pause_frames;
5560 +enum dpaa2_eth_rx_dist {
5561 + DPAA2_ETH_RX_DIST_HASH,
5562 + DPAA2_ETH_RX_DIST_FS,
5563 + DPAA2_ETH_RX_DIST_LEGACY
5566 -/* default Rx hash options, set during probing */
5567 -#define DPAA2_RXH_SUPPORTED (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \
5568 - | RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 \
5570 +/* Supported Rx distribution field ids */
5571 +#define DPAA2_ETH_DIST_ETHSRC BIT(0)
5572 +#define DPAA2_ETH_DIST_ETHDST BIT(1)
5573 +#define DPAA2_ETH_DIST_ETHTYPE BIT(2)
5574 +#define DPAA2_ETH_DIST_VLAN BIT(3)
5575 +#define DPAA2_ETH_DIST_IPSRC BIT(4)
5576 +#define DPAA2_ETH_DIST_IPDST BIT(5)
5577 +#define DPAA2_ETH_DIST_IPPROTO BIT(6)
5578 +#define DPAA2_ETH_DIST_L4SRC BIT(7)
5579 +#define DPAA2_ETH_DIST_L4DST BIT(8)
5580 +#define DPAA2_ETH_DIST_ALL (~0U)
5582 +/* Default Rx hash key */
5583 +#define DPAA2_ETH_DIST_DEFAULT_HASH \
5584 + (DPAA2_ETH_DIST_IPPROTO | \
5585 + DPAA2_ETH_DIST_IPSRC | DPAA2_ETH_DIST_IPDST | \
5586 + DPAA2_ETH_DIST_L4SRC | DPAA2_ETH_DIST_L4DST)
5588 #define dpaa2_eth_hash_enabled(priv) \
5589 ((priv)->dpni_attrs.num_queues > 1)
5591 +#define dpaa2_eth_fs_enabled(priv) \
5592 + (!((priv)->dpni_attrs.options & DPNI_OPT_NO_FS))
5594 +#define dpaa2_eth_fs_mask_enabled(priv) \
5595 + ((priv)->dpni_attrs.options & DPNI_OPT_HAS_KEY_MASKING)
5597 +#define dpaa2_eth_fs_count(priv) \
5598 + ((priv)->dpni_attrs.fs_entries)
5600 /* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */
5601 #define DPAA2_CLASSIFIER_DMA_SIZE 256
5603 extern const struct ethtool_ops dpaa2_ethtool_ops;
5604 extern const char dpaa2_eth_drv_version[];
5606 -static int dpaa2_eth_queue_count(struct dpaa2_eth_priv *priv)
5607 +static inline int dpaa2_eth_cmp_dpni_ver(struct dpaa2_eth_priv *priv,
5608 + u16 ver_major, u16 ver_minor)
5610 + if (priv->dpni_ver_major == ver_major)
5611 + return priv->dpni_ver_minor - ver_minor;
5612 + return priv->dpni_ver_major - ver_major;
5615 +#define DPNI_DIST_KEY_VER_MAJOR 7
5616 +#define DPNI_DIST_KEY_VER_MINOR 5
5618 +static inline bool dpaa2_eth_has_legacy_dist(struct dpaa2_eth_priv *priv)
5620 + return (dpaa2_eth_cmp_dpni_ver(priv, DPNI_DIST_KEY_VER_MAJOR,
5621 + DPNI_DIST_KEY_VER_MINOR) < 0);
5624 +/* Hardware only sees DPAA2_ETH_RX_BUF_SIZE, but the skb built around
5625 + * the buffer also needs space for its shared info struct, and we need
5626 + * to allocate enough to accommodate hardware alignment restrictions
5628 +static inline unsigned int dpaa2_eth_buf_raw_size(struct dpaa2_eth_priv *priv)
5630 + return DPAA2_ETH_SKB_SIZE + priv->rx_buf_align;
5633 +/* Total headroom needed by the hardware in Tx frame buffers */
5634 +static inline unsigned int
5635 +dpaa2_eth_needed_headroom(struct dpaa2_eth_priv *priv, struct sk_buff *skb)
5637 + unsigned int headroom = DPAA2_ETH_SWA_SIZE;
5639 + /* If we don't have an skb (e.g. XDP buffer), we only need space for
5640 + * the software annotation area
5645 + /* For non-linear skbs we have no headroom requirement, as we build a
5646 + * SG frame with a newly allocated SGT buffer
5648 + if (skb_is_nonlinear(skb))
5651 + /* If we have Tx timestamping, need 128B hardware annotation */
5652 + if (priv->ts_tx_en && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)
5653 + headroom += DPAA2_ETH_TX_HWA_SIZE;
5658 +/* Extra headroom space requested to hardware, in order to make sure there's
5659 + * no realloc'ing in forwarding scenarios. We need to reserve enough space
5660 + * such that we can accommodate the maximum required Tx offset and alignment
5661 + * in the ingress frame buffer
5663 +static inline unsigned int dpaa2_eth_rx_headroom(struct dpaa2_eth_priv *priv)
5665 + return priv->tx_data_offset + DPAA2_ETH_TX_BUF_ALIGN -
5666 + DPAA2_ETH_RX_HWA_SIZE;
5669 +static inline int dpaa2_eth_queue_count(struct dpaa2_eth_priv *priv)
5671 return priv->dpni_attrs.num_queues;
5674 +static inline int dpaa2_eth_tc_count(struct dpaa2_eth_priv *priv)
5676 + return priv->dpni_attrs.num_tcs;
5679 +static inline bool dpaa2_eth_is_pfc_enabled(struct dpaa2_eth_priv *priv,
5680 + int traffic_class)
5682 + return priv->pfc.pfc_en & (1 << traffic_class);
5685 +enum dpaa2_eth_td_cfg {
5686 + DPAA2_ETH_TD_NONE,
5687 + DPAA2_ETH_TD_QUEUE,
5688 + DPAA2_ETH_TD_GROUP
5691 +static inline enum dpaa2_eth_td_cfg
5692 +dpaa2_eth_get_td_type(struct dpaa2_eth_priv *priv)
5694 + bool pfc_enabled = !!(priv->pfc.pfc_en);
5697 + return DPAA2_ETH_TD_GROUP;
5698 + else if (priv->tx_pause_frames)
5699 + return DPAA2_ETH_TD_NONE;
5701 + return DPAA2_ETH_TD_QUEUE;
5704 +static inline int dpaa2_eth_ch_count(struct dpaa2_eth_priv *priv)
5709 +void check_cls_support(struct dpaa2_eth_priv *priv);
5711 +int set_rx_taildrop(struct dpaa2_eth_priv *priv);
5713 +int dpaa2_eth_set_dist_key(struct dpaa2_eth_priv *priv,
5714 + enum dpaa2_eth_rx_dist type, u32 key_fields);
5716 #endif /* __DPAA2_H */
5717 --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c
5718 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c
5720 /* Copyright 2014-2016 Freescale Semiconductor Inc.
5721 - * Copyright 2016 NXP
5722 + * Copyright 2016-2017 NXP
5724 * Redistribution and use in source and binary forms, with or without
5725 * modification, are permitted provided that the following conditions are met:
5726 @@ -62,6 +62,7 @@ static char dpaa2_ethtool_extras[][ETH_G
5727 "[drv] tx conf bytes",
5728 "[drv] tx sg frames",
5729 "[drv] tx sg bytes",
5730 + "[drv] tx realloc frames",
5731 "[drv] rx sg frames",
5732 "[drv] rx sg bytes",
5733 "[drv] enqueue portal busy",
5734 @@ -69,6 +70,15 @@ static char dpaa2_ethtool_extras[][ETH_G
5735 "[drv] dequeue portal busy",
5736 "[drv] channel pull errors",
5738 + "[drv] tx congestion state",
5739 +#ifdef CONFIG_FSL_QBMAN_DEBUG
5741 + "rx pending frames",
5742 + "rx pending bytes",
5743 + "tx conf pending frames",
5744 + "tx conf pending bytes",
5749 #define DPAA2_ETH_NUM_EXTRA_STATS ARRAY_SIZE(dpaa2_ethtool_extras)
5750 @@ -76,10 +86,15 @@ static char dpaa2_ethtool_extras[][ETH_G
5751 static void dpaa2_eth_get_drvinfo(struct net_device *net_dev,
5752 struct ethtool_drvinfo *drvinfo)
5754 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
5756 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
5757 strlcpy(drvinfo->version, dpaa2_eth_drv_version,
5758 sizeof(drvinfo->version));
5759 - strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
5761 + snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
5762 + "%u.%u", priv->dpni_ver_major, priv->dpni_ver_minor);
5764 strlcpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent),
5765 sizeof(drvinfo->bus_info));
5767 @@ -113,25 +128,37 @@ out:
5771 +#define DPNI_DYNAMIC_LINK_SET_VER_MAJOR 7
5772 +#define DPNI_DYNAMIC_LINK_SET_VER_MINOR 1
5774 dpaa2_eth_set_link_ksettings(struct net_device *net_dev,
5775 const struct ethtool_link_ksettings *link_settings)
5777 - struct dpni_link_cfg cfg = {0};
5778 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
5779 + struct dpni_link_state state = {0};
5780 + struct dpni_link_cfg cfg = {0};
5783 - netdev_dbg(net_dev, "Setting link parameters...");
5784 + /* If using an older MC version, the DPNI must be down
5785 + * in order to be able to change link settings. Taking steps to let
5786 + * the user know that.
5788 + if (dpaa2_eth_cmp_dpni_ver(priv, DPNI_DYNAMIC_LINK_SET_VER_MAJOR,
5789 + DPNI_DYNAMIC_LINK_SET_VER_MINOR) < 0) {
5790 + if (netif_running(net_dev)) {
5791 + netdev_info(net_dev, "Interface must be brought down first.\n");
5796 - /* Due to a temporary MC limitation, the DPNI must be down
5797 - * in order to be able to change link settings. Taking steps to let
5798 - * the user know that.
5800 - if (netif_running(net_dev)) {
5801 - netdev_info(net_dev, "Sorry, interface must be brought down first.\n");
5803 + /* Need to interrogate link state to get flow control params */
5804 + err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state);
5806 + netdev_err(net_dev, "Error getting link state\n");
5810 + cfg.options = state.options;
5811 cfg.rate = link_settings->base.speed;
5812 if (link_settings->base.autoneg == AUTONEG_ENABLE)
5813 cfg.options |= DPNI_LINK_OPT_AUTONEG;
5814 @@ -149,6 +176,81 @@ dpaa2_eth_set_link_ksettings(struct net_
5816 netdev_dbg(net_dev, "ERROR %d setting link cfg\n", err);
5822 +static void dpaa2_eth_get_pauseparam(struct net_device *net_dev,
5823 + struct ethtool_pauseparam *pause)
5825 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
5826 + struct dpni_link_state state = {0};
5829 + err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state);
5831 + netdev_dbg(net_dev, "Error getting link state\n");
5833 + /* Report general port autonegotiation status */
5834 + pause->autoneg = !!(state.options & DPNI_LINK_OPT_AUTONEG);
5835 + pause->rx_pause = !!(state.options & DPNI_LINK_OPT_PAUSE);
5836 + pause->tx_pause = pause->rx_pause ^
5837 + !!(state.options & DPNI_LINK_OPT_ASYM_PAUSE);
5840 +static int dpaa2_eth_set_pauseparam(struct net_device *net_dev,
5841 + struct ethtool_pauseparam *pause)
5843 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
5844 + struct dpni_link_state state = {0};
5845 + struct dpni_link_cfg cfg = {0};
5846 + u32 current_tx_pause;
5849 + err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state);
5851 + netdev_dbg(net_dev, "Error getting link state\n");
5855 + cfg.rate = state.rate;
5856 + cfg.options = state.options;
5857 + current_tx_pause = !!(cfg.options & DPNI_LINK_OPT_PAUSE) ^
5858 + !!(cfg.options & DPNI_LINK_OPT_ASYM_PAUSE);
5860 + /* We don't support changing pause frame autonegotiation separately
5861 + * from general port autoneg
5863 + if (pause->autoneg != !!(state.options & DPNI_LINK_OPT_AUTONEG))
5864 + netdev_warn(net_dev,
5865 + "Cannot change pause frame autoneg separately\n");
5867 + if (pause->rx_pause)
5868 + cfg.options |= DPNI_LINK_OPT_PAUSE;
5870 + cfg.options &= ~DPNI_LINK_OPT_PAUSE;
5872 + if (pause->rx_pause ^ pause->tx_pause)
5873 + cfg.options |= DPNI_LINK_OPT_ASYM_PAUSE;
5875 + cfg.options &= ~DPNI_LINK_OPT_ASYM_PAUSE;
5877 + err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &cfg);
5879 + netdev_dbg(net_dev, "Error setting link\n");
5883 + /* Enable/disable Rx FQ taildrop if Tx pause frames have changed */
5884 + if (current_tx_pause == pause->tx_pause)
5887 + priv->tx_pause_frames = pause->tx_pause;
5888 + err = set_rx_taildrop(priv);
5890 + netdev_dbg(net_dev, "Error configuring taildrop\n");
5896 @@ -192,6 +294,13 @@ static void dpaa2_eth_get_ethtool_stats(
5899 union dpni_statistics dpni_stats;
5901 +#ifdef CONFIG_FSL_QBMAN_DEBUG
5903 + u32 fcnt_rx_total = 0, fcnt_tx_total = 0;
5904 + u32 bcnt_rx_total = 0, bcnt_tx_total = 0;
5908 u64 portal_busy = 0, pull_err = 0;
5909 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
5910 @@ -204,7 +313,7 @@ static void dpaa2_eth_get_ethtool_stats(
5911 /* Print standard counters, from DPNI statistics */
5912 for (j = 0; j <= 2; j++) {
5913 err = dpni_get_statistics(priv->mc_io, 0, priv->mc_token,
5915 + j, 0, &dpni_stats);
5917 netdev_warn(net_dev, "dpni_get_stats(%d) failed\n", j);
5919 @@ -240,12 +349,474 @@ static void dpaa2_eth_get_ethtool_stats(
5920 *(data + i++) = portal_busy;
5921 *(data + i++) = pull_err;
5922 *(data + i++) = cdan;
5924 + *(data + i++) = dpaa2_cscn_state_congested(priv->cscn_mem);
5926 +#ifdef CONFIG_FSL_QBMAN_DEBUG
5927 + for (j = 0; j < priv->num_fqs; j++) {
5928 + /* Print FQ instantaneous counts */
5929 + err = dpaa2_io_query_fq_count(NULL, priv->fq[j].fqid,
5932 + netdev_warn(net_dev, "FQ query error %d", err);
5936 + if (priv->fq[j].type == DPAA2_TX_CONF_FQ) {
5937 + fcnt_tx_total += fcnt;
5938 + bcnt_tx_total += bcnt;
5940 + fcnt_rx_total += fcnt;
5941 + bcnt_rx_total += bcnt;
5945 + *(data + i++) = fcnt_rx_total;
5946 + *(data + i++) = bcnt_rx_total;
5947 + *(data + i++) = fcnt_tx_total;
5948 + *(data + i++) = bcnt_tx_total;
5950 + err = dpaa2_io_query_bp_count(NULL, priv->bpid, &buf_cnt);
5952 + netdev_warn(net_dev, "Buffer count query error %d\n", err);
5955 + *(data + i++) = buf_cnt;
5959 +static int cls_key_off(struct dpaa2_eth_priv *priv, int prot, int field)
5963 + for (i = 0; i < priv->num_dist_fields; i++) {
5964 + if (priv->dist_fields[i].cls_prot == prot &&
5965 + priv->dist_fields[i].cls_field == field)
5967 + off += priv->dist_fields[i].size;
5973 +static u8 cls_key_size(struct dpaa2_eth_priv *priv)
5977 + for (i = 0; i < priv->num_dist_fields; i++)
5978 + size += priv->dist_fields[i].size;
5983 +void check_cls_support(struct dpaa2_eth_priv *priv)
5985 + u8 key_size = cls_key_size(priv);
5986 + struct device *dev = priv->net_dev->dev.parent;
5988 + if (dpaa2_eth_hash_enabled(priv)) {
5989 + if (priv->dpni_attrs.fs_key_size < key_size) {
5990 + dev_info(dev, "max_dist_key_size = %d, expected %d. Hashing and steering are disabled\n",
5991 + priv->dpni_attrs.fs_key_size,
5995 + if (priv->num_dist_fields > DPKG_MAX_NUM_OF_EXTRACTS) {
5996 + dev_info(dev, "Too many key fields (max = %d). Hashing and steering are disabled\n",
5997 + DPKG_MAX_NUM_OF_EXTRACTS);
6002 + if (dpaa2_eth_fs_enabled(priv)) {
6003 + if (!dpaa2_eth_hash_enabled(priv)) {
6004 + dev_info(dev, "Insufficient queues. Steering is disabled\n");
6008 + if (!dpaa2_eth_fs_mask_enabled(priv)) {
6009 + dev_info(dev, "Key masks not supported. Steering is disabled\n");
6017 + priv->dpni_attrs.options |= DPNI_OPT_NO_FS;
6018 + priv->dpni_attrs.options &= ~DPNI_OPT_HAS_KEY_MASKING;
6021 +static int prep_l4_rule(struct dpaa2_eth_priv *priv,
6022 + struct ethtool_tcpip4_spec *l4_value,
6023 + struct ethtool_tcpip4_spec *l4_mask,
6024 + void *key, void *mask, u8 l4_proto)
6028 + if (l4_mask->tos) {
6029 + netdev_err(priv->net_dev, "ToS is not supported for IPv4 L4\n");
6030 + return -EOPNOTSUPP;
6033 + if (l4_mask->ip4src) {
6034 + offset = cls_key_off(priv, NET_PROT_IP, NH_FLD_IP_SRC);
6035 + *(u32 *)(key + offset) = l4_value->ip4src;
6036 + *(u32 *)(mask + offset) = l4_mask->ip4src;
6039 + if (l4_mask->ip4dst) {
6040 + offset = cls_key_off(priv, NET_PROT_IP, NH_FLD_IP_DST);
6041 + *(u32 *)(key + offset) = l4_value->ip4dst;
6042 + *(u32 *)(mask + offset) = l4_mask->ip4dst;
6045 + if (l4_mask->psrc) {
6046 + offset = cls_key_off(priv, NET_PROT_UDP, NH_FLD_UDP_PORT_SRC);
6047 + *(u32 *)(key + offset) = l4_value->psrc;
6048 + *(u32 *)(mask + offset) = l4_mask->psrc;
6051 + if (l4_mask->pdst) {
6052 + offset = cls_key_off(priv, NET_PROT_UDP, NH_FLD_UDP_PORT_DST);
6053 + *(u32 *)(key + offset) = l4_value->pdst;
6054 + *(u32 *)(mask + offset) = l4_mask->pdst;
6057 + /* Only apply the rule for the user-specified L4 protocol
6058 + * and if ethertype matches IPv4
6060 + offset = cls_key_off(priv, NET_PROT_ETH, NH_FLD_ETH_TYPE);
6061 + *(u16 *)(key + offset) = htons(ETH_P_IP);
6062 + *(u16 *)(mask + offset) = 0xFFFF;
6064 + offset = cls_key_off(priv, NET_PROT_IP, NH_FLD_IP_PROTO);
6065 + *(u8 *)(key + offset) = l4_proto;
6066 + *(u8 *)(mask + offset) = 0xFF;
6068 + /* TODO: check IP version */
6073 +static int prep_eth_rule(struct dpaa2_eth_priv *priv,
6074 + struct ethhdr *eth_value, struct ethhdr *eth_mask,
6075 + void *key, void *mask)
6079 + if (eth_mask->h_proto) {
6080 + netdev_err(priv->net_dev, "Ethertype is not supported!\n");
6081 + return -EOPNOTSUPP;
6084 + if (!is_zero_ether_addr(eth_mask->h_source)) {
6085 + offset = cls_key_off(priv, NET_PROT_ETH, NH_FLD_ETH_SA);
6086 + ether_addr_copy(key + offset, eth_value->h_source);
6087 + ether_addr_copy(mask + offset, eth_mask->h_source);
6090 + if (!is_zero_ether_addr(eth_mask->h_dest)) {
6091 + offset = cls_key_off(priv, NET_PROT_ETH, NH_FLD_ETH_DA);
6092 + ether_addr_copy(key + offset, eth_value->h_dest);
6093 + ether_addr_copy(mask + offset, eth_mask->h_dest);
6099 +static int prep_user_ip_rule(struct dpaa2_eth_priv *priv,
6100 + struct ethtool_usrip4_spec *uip_value,
6101 + struct ethtool_usrip4_spec *uip_mask,
6102 + void *key, void *mask)
6106 + if (uip_mask->tos)
6107 + return -EOPNOTSUPP;
6109 + if (uip_mask->ip4src) {
6110 + offset = cls_key_off(priv, NET_PROT_IP, NH_FLD_IP_SRC);
6111 + *(u32 *)(key + offset) = uip_value->ip4src;
6112 + *(u32 *)(mask + offset) = uip_mask->ip4src;
6115 + if (uip_mask->ip4dst) {
6116 + offset = cls_key_off(priv, NET_PROT_IP, NH_FLD_IP_DST);
6117 + *(u32 *)(key + offset) = uip_value->ip4dst;
6118 + *(u32 *)(mask + offset) = uip_mask->ip4dst;
6121 + if (uip_mask->proto) {
6122 + offset = cls_key_off(priv, NET_PROT_IP, NH_FLD_IP_PROTO);
6123 + *(u32 *)(key + offset) = uip_value->proto;
6124 + *(u32 *)(mask + offset) = uip_mask->proto;
6126 + if (uip_mask->l4_4_bytes) {
6127 + offset = cls_key_off(priv, NET_PROT_UDP, NH_FLD_UDP_PORT_SRC);
6128 + *(u16 *)(key + offset) = uip_value->l4_4_bytes << 16;
6129 + *(u16 *)(mask + offset) = uip_mask->l4_4_bytes << 16;
6131 + offset = cls_key_off(priv, NET_PROT_UDP, NH_FLD_UDP_PORT_DST);
6132 + *(u16 *)(key + offset) = uip_value->l4_4_bytes & 0xFFFF;
6133 + *(u16 *)(mask + offset) = uip_mask->l4_4_bytes & 0xFFFF;
6136 + /* Ethertype must be IP */
6137 + offset = cls_key_off(priv, NET_PROT_ETH, NH_FLD_ETH_TYPE);
6138 + *(u16 *)(key + offset) = htons(ETH_P_IP);
6139 + *(u16 *)(mask + offset) = 0xFFFF;
6144 +static int prep_ext_rule(struct dpaa2_eth_priv *priv,
6145 + struct ethtool_flow_ext *ext_value,
6146 + struct ethtool_flow_ext *ext_mask,
6147 + void *key, void *mask)
6151 + if (ext_mask->vlan_etype)
6152 + return -EOPNOTSUPP;
6154 + if (ext_mask->vlan_tci) {
6155 + offset = cls_key_off(priv, NET_PROT_VLAN, NH_FLD_VLAN_TCI);
6156 + *(u16 *)(key + offset) = ext_value->vlan_tci;
6157 + *(u16 *)(mask + offset) = ext_mask->vlan_tci;
6163 +static int prep_mac_ext_rule(struct dpaa2_eth_priv *priv,
6164 + struct ethtool_flow_ext *ext_value,
6165 + struct ethtool_flow_ext *ext_mask,
6166 + void *key, void *mask)
6170 + if (!is_zero_ether_addr(ext_mask->h_dest)) {
6171 + offset = cls_key_off(priv, NET_PROT_ETH, NH_FLD_ETH_DA);
6172 + ether_addr_copy(key + offset, ext_value->h_dest);
6173 + ether_addr_copy(mask + offset, ext_mask->h_dest);
6179 +static int prep_cls_rule(struct net_device *net_dev,
6180 + struct ethtool_rx_flow_spec *fs,
6183 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
6184 + const u8 key_size = cls_key_size(priv);
6185 + void *msk = key + key_size;
6188 + memset(key, 0, key_size * 2);
6190 + switch (fs->flow_type & 0xff) {
6192 + err = prep_l4_rule(priv, &fs->h_u.tcp_ip4_spec,
6193 + &fs->m_u.tcp_ip4_spec, key, msk,
6197 + err = prep_l4_rule(priv, &fs->h_u.udp_ip4_spec,
6198 + &fs->m_u.udp_ip4_spec, key, msk,
6201 + case SCTP_V4_FLOW:
6202 + err = prep_l4_rule(priv, &fs->h_u.sctp_ip4_spec,
6203 + &fs->m_u.sctp_ip4_spec, key, msk,
6207 + err = prep_eth_rule(priv, &fs->h_u.ether_spec,
6208 + &fs->m_u.ether_spec, key, msk);
6210 + case IP_USER_FLOW:
6211 + err = prep_user_ip_rule(priv, &fs->h_u.usr_ip4_spec,
6212 + &fs->m_u.usr_ip4_spec, key, msk);
6215 + /* TODO: AH, ESP */
6216 + return -EOPNOTSUPP;
6221 + if (fs->flow_type & FLOW_EXT) {
6222 + err = prep_ext_rule(priv, &fs->h_ext, &fs->m_ext, key, msk);
6227 + if (fs->flow_type & FLOW_MAC_EXT) {
6228 + err = prep_mac_ext_rule(priv, &fs->h_ext, &fs->m_ext, key, msk);
6236 +static int del_cls(struct net_device *net_dev, int location);
6238 +static int do_cls(struct net_device *net_dev,
6239 + struct ethtool_rx_flow_spec *fs,
6242 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
6243 + struct device *dev = net_dev->dev.parent;
6244 + const int rule_cnt = dpaa2_eth_fs_count(priv);
6245 + struct dpni_rule_cfg rule_cfg;
6246 + struct dpni_fs_action_cfg fs_act = { 0 };
6250 + if (!dpaa2_eth_fs_enabled(priv)) {
6251 + netdev_err(net_dev, "dev does not support steering!\n");
6252 + /* dev doesn't support steering */
6253 + return -EOPNOTSUPP;
6256 + if ((fs->ring_cookie != RX_CLS_FLOW_DISC &&
6257 + fs->ring_cookie >= dpaa2_eth_queue_count(priv)) ||
6258 + fs->location >= rule_cnt)
6261 + /* When adding a new rule, check if location if available
6262 + * and if not, free the existing table entry before inserting
6265 + if (add && (priv->cls_rule[fs->location].in_use == true))
6266 + del_cls(net_dev, fs->location);
6268 + memset(&rule_cfg, 0, sizeof(rule_cfg));
6269 + rule_cfg.key_size = cls_key_size(priv);
6271 + /* allocate twice the key size, for the actual key and for mask */
6272 + dma_mem = kzalloc(rule_cfg.key_size * 2, GFP_DMA | GFP_KERNEL);
6276 + err = prep_cls_rule(net_dev, fs, dma_mem);
6278 + goto err_free_mem;
6280 + rule_cfg.key_iova = dma_map_single(dev, dma_mem,
6281 + rule_cfg.key_size * 2,
6284 + rule_cfg.mask_iova = rule_cfg.key_iova + rule_cfg.key_size;
6286 + if (fs->ring_cookie == RX_CLS_FLOW_DISC)
6287 + fs_act.options |= DPNI_FS_OPT_DISCARD;
6289 + fs_act.flow_id = fs->ring_cookie;
6291 + for (tc = 0; tc < dpaa2_eth_tc_count(priv); tc++) {
6293 + err = dpni_add_fs_entry(priv->mc_io, 0, priv->mc_token,
6294 + tc, fs->location, &rule_cfg,
6297 + err = dpni_remove_fs_entry(priv->mc_io, 0,
6298 + priv->mc_token, tc,
6305 + dma_unmap_single(dev, rule_cfg.key_iova,
6306 + rule_cfg.key_size * 2, DMA_TO_DEVICE);
6309 + netdev_err(net_dev, "dpaa2_add/remove_cls() error %d\n", err);
6317 +static int add_cls(struct net_device *net_dev,
6318 + struct ethtool_rx_flow_spec *fs)
6320 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
6323 + err = do_cls(net_dev, fs, true);
6327 + priv->cls_rule[fs->location].in_use = true;
6328 + priv->cls_rule[fs->location].fs = *fs;
6333 +static int del_cls(struct net_device *net_dev, int location)
6335 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
6338 + err = do_cls(net_dev, &priv->cls_rule[location].fs, false);
6342 + priv->cls_rule[location].in_use = false;
6347 +static int set_hash(struct net_device *net_dev, u64 data)
6349 + struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
6353 + if (data & RXH_DISCARD)
6354 + return -EOPNOTSUPP;
6356 + for (i = 0; i < priv->num_dist_fields; i++)
6357 + if (priv->dist_fields[i].rxnfc_field & data)
6358 + key |= priv->dist_fields[i].id;
6360 + return dpaa2_eth_set_dist_key(priv, DPAA2_ETH_RX_DIST_HASH, key);
6363 +static int dpaa2_eth_set_rxnfc(struct net_device *net_dev,
6364 + struct ethtool_rxnfc *rxnfc)
6368 + switch (rxnfc->cmd) {
6369 + case ETHTOOL_SRXCLSRLINS:
6370 + err = add_cls(net_dev, &rxnfc->fs);
6372 + case ETHTOOL_SRXCLSRLDEL:
6373 + err = del_cls(net_dev, rxnfc->fs.location);
6375 + case ETHTOOL_SRXFH:
6376 + err = set_hash(net_dev, rxnfc->data);
6379 + err = -EOPNOTSUPP;
6385 static int dpaa2_eth_get_rxnfc(struct net_device *net_dev,
6386 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
6388 struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
6389 + const int rule_cnt = dpaa2_eth_fs_count(priv);
6392 switch (rxnfc->cmd) {
6394 @@ -258,6 +829,33 @@ static int dpaa2_eth_get_rxnfc(struct ne
6395 case ETHTOOL_GRXRINGS:
6396 rxnfc->data = dpaa2_eth_queue_count(priv);
6399 + case ETHTOOL_GRXCLSRLCNT:
6400 + for (i = 0, rxnfc->rule_cnt = 0; i < rule_cnt; i++)
6401 + if (priv->cls_rule[i].in_use)
6402 + rxnfc->rule_cnt++;
6403 + rxnfc->data = rule_cnt;
6406 + case ETHTOOL_GRXCLSRULE:
6407 + if (!priv->cls_rule[rxnfc->fs.location].in_use)
6410 + rxnfc->fs = priv->cls_rule[rxnfc->fs.location].fs;
6413 + case ETHTOOL_GRXCLSRLALL:
6414 + for (i = 0, j = 0; i < rule_cnt; i++) {
6415 + if (!priv->cls_rule[i].in_use)
6417 + if (j == rxnfc->rule_cnt)
6419 + rule_locs[j++] = i;
6421 + rxnfc->rule_cnt = j;
6422 + rxnfc->data = rule_cnt;
6428 @@ -270,8 +868,11 @@ const struct ethtool_ops dpaa2_ethtool_o
6429 .get_link = ethtool_op_get_link,
6430 .get_link_ksettings = dpaa2_eth_get_link_ksettings,
6431 .set_link_ksettings = dpaa2_eth_set_link_ksettings,
6432 + .get_pauseparam = dpaa2_eth_get_pauseparam,
6433 + .set_pauseparam = dpaa2_eth_set_pauseparam,
6434 .get_sset_count = dpaa2_eth_get_sset_count,
6435 .get_ethtool_stats = dpaa2_eth_get_ethtool_stats,
6436 .get_strings = dpaa2_eth_get_strings,
6437 .get_rxnfc = dpaa2_eth_get_rxnfc,
6438 + .set_rxnfc = dpaa2_eth_set_rxnfc,
6440 --- a/drivers/staging/fsl-dpaa2/ethernet/dpni-cmd.h
6441 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpni-cmd.h
6443 #define DPNI_VER_MAJOR 7
6444 #define DPNI_VER_MINOR 0
6445 #define DPNI_CMD_BASE_VERSION 1
6446 +#define DPNI_CMD_2ND_VERSION 2
6447 #define DPNI_CMD_ID_OFFSET 4
6449 #define DPNI_CMD(id) (((id) << DPNI_CMD_ID_OFFSET) | DPNI_CMD_BASE_VERSION)
6450 +#define DPNI_CMD_V2(id) (((id) << DPNI_CMD_ID_OFFSET) | DPNI_CMD_2ND_VERSION)
6452 #define DPNI_CMDID_OPEN DPNI_CMD(0x801)
6453 #define DPNI_CMDID_CLOSE DPNI_CMD(0x800)
6455 #define DPNI_CMDID_GET_IRQ_STATUS DPNI_CMD(0x016)
6456 #define DPNI_CMDID_CLEAR_IRQ_STATUS DPNI_CMD(0x017)
6458 -#define DPNI_CMDID_SET_POOLS DPNI_CMD(0x200)
6459 +#define DPNI_CMDID_SET_POOLS DPNI_CMD_V2(0x200)
6460 #define DPNI_CMDID_SET_ERRORS_BEHAVIOR DPNI_CMD(0x20B)
6462 #define DPNI_CMDID_GET_QDID DPNI_CMD(0x210)
6464 #define DPNI_CMDID_SET_MAX_FRAME_LENGTH DPNI_CMD(0x216)
6465 #define DPNI_CMDID_GET_MAX_FRAME_LENGTH DPNI_CMD(0x217)
6466 #define DPNI_CMDID_SET_LINK_CFG DPNI_CMD(0x21A)
6467 -#define DPNI_CMDID_SET_TX_SHAPING DPNI_CMD(0x21B)
6468 +#define DPNI_CMDID_SET_TX_SHAPING DPNI_CMD_V2(0x21B)
6470 #define DPNI_CMDID_SET_MCAST_PROMISC DPNI_CMD(0x220)
6471 #define DPNI_CMDID_GET_MCAST_PROMISC DPNI_CMD(0x221)
6474 #define DPNI_CMDID_SET_RX_TC_DIST DPNI_CMD(0x235)
6476 +#define DPNI_CMDID_SET_QOS_TBL DPNI_CMD(0x240)
6477 +#define DPNI_CMDID_ADD_QOS_ENT DPNI_CMD(0x241)
6478 +#define DPNI_CMDID_REMOVE_QOS_ENT DPNI_CMD(0x242)
6479 #define DPNI_CMDID_ADD_FS_ENT DPNI_CMD(0x244)
6480 #define DPNI_CMDID_REMOVE_FS_ENT DPNI_CMD(0x245)
6481 #define DPNI_CMDID_CLR_FS_ENT DPNI_CMD(0x246)
6483 -#define DPNI_CMDID_GET_STATISTICS DPNI_CMD(0x25D)
6484 +#define DPNI_CMDID_SET_TX_PRIORITIES DPNI_CMD_V2(0x250)
6485 +#define DPNI_CMDID_GET_STATISTICS DPNI_CMD_V2(0x25D)
6486 +#define DPNI_CMDID_RESET_STATISTICS DPNI_CMD(0x25E)
6487 #define DPNI_CMDID_GET_QUEUE DPNI_CMD(0x25F)
6488 #define DPNI_CMDID_SET_QUEUE DPNI_CMD(0x260)
6489 #define DPNI_CMDID_GET_TAILDROP DPNI_CMD(0x261)
6491 #define DPNI_CMDID_GET_OFFLOAD DPNI_CMD(0x26B)
6492 #define DPNI_CMDID_SET_OFFLOAD DPNI_CMD(0x26C)
6494 +#define DPNI_CMDID_SET_RX_FS_DIST DPNI_CMD(0x273)
6495 +#define DPNI_CMDID_SET_RX_HASH_DIST DPNI_CMD(0x274)
6497 /* Macros for accessing command fields smaller than 1byte */
6498 #define DPNI_MASK(field) \
6499 GENMASK(DPNI_##field##_SHIFT + DPNI_##field##_SIZE - 1, \
6500 @@ -126,13 +136,14 @@ struct dpni_cmd_open {
6502 #define DPNI_BACKUP_POOL(val, order) (((val) & 0x1) << (order))
6503 struct dpni_cmd_set_pools {
6506 u8 backup_pool_mask;
6508 - /* cmd word 0..4 */
6509 - __le32 dpbp_id[DPNI_MAX_DPBP];
6510 - /* cmd word 4..6 */
6515 + } pool[DPNI_MAX_DPBP];
6516 __le16 buffer_size[DPNI_MAX_DPBP];
6519 @@ -303,6 +314,7 @@ struct dpni_rsp_get_tx_data_offset {
6521 struct dpni_cmd_get_statistics {
6526 struct dpni_rsp_get_statistics {
6527 @@ -335,6 +347,22 @@ struct dpni_rsp_get_link_state {
6531 +#define DPNI_COUPLED_SHIFT 0
6532 +#define DPNI_COUPLED_SIZE 1
6534 +struct dpni_cmd_set_tx_shaping {
6536 + __le16 tx_cr_max_burst_size;
6537 + __le16 tx_er_max_burst_size;
6540 + __le32 tx_cr_rate_limit;
6541 + __le32 tx_er_rate_limit;
6543 + /* from LSB: coupled:1 */
6547 struct dpni_cmd_set_max_frame_length {
6548 __le16 max_frame_length;
6550 @@ -394,6 +422,24 @@ struct dpni_cmd_clear_mac_filters {
6554 +#define DPNI_SEPARATE_GRP_SHIFT 0
6555 +#define DPNI_SEPARATE_GRP_SIZE 1
6556 +#define DPNI_MODE_1_SHIFT 0
6557 +#define DPNI_MODE_1_SIZE 4
6558 +#define DPNI_MODE_2_SHIFT 4
6559 +#define DPNI_MODE_2_SIZE 4
6561 +struct dpni_cmd_set_tx_priorities {
6569 + __le16 delta_bandwidth[8];
6572 #define DPNI_DIST_MODE_SHIFT 0
6573 #define DPNI_DIST_MODE_SIZE 4
6574 #define DPNI_MISS_ACTION_SHIFT 4
6575 @@ -503,6 +549,63 @@ struct dpni_cmd_set_queue {
6576 __le64 user_context;
6579 +#define DPNI_DISCARD_ON_MISS_SHIFT 0
6580 +#define DPNI_DISCARD_ON_MISS_SIZE 1
6582 +struct dpni_cmd_set_qos_table {
6585 + /* only the LSB */
6586 + u8 discard_on_miss;
6588 + __le64 key_cfg_iova;
6591 +struct dpni_cmd_add_qos_entry {
6601 +struct dpni_cmd_remove_qos_entry {
6609 +struct dpni_cmd_add_fs_entry {
6624 +struct dpni_cmd_remove_fs_entry {
6636 struct dpni_cmd_set_taildrop {
6638 u8 congestion_point;
6639 @@ -538,4 +641,79 @@ struct dpni_rsp_get_taildrop {
6643 +struct dpni_rsp_get_api_version {
6648 +#define DPNI_DEST_TYPE_SHIFT 0
6649 +#define DPNI_DEST_TYPE_SIZE 4
6650 +#define DPNI_CONG_UNITS_SHIFT 4
6651 +#define DPNI_CONG_UNITS_SIZE 2
6653 +struct dpni_cmd_set_congestion_notification {
6660 + __le16 notification_mode;
6662 + /* from LSB: dest_type: 4 units:2 */
6665 + __le64 message_iova;
6667 + __le64 message_ctx;
6669 + __le32 threshold_entry;
6670 + __le32 threshold_exit;
6673 +struct dpni_cmd_get_congestion_notification {
6679 +struct dpni_rsp_get_congestion_notification {
6684 + __le16 notification_mode;
6686 + /* from LSB: dest_type: 4 units:2 */
6689 + __le64 message_iova;
6691 + __le64 message_ctx;
6693 + __le32 threshold_entry;
6694 + __le32 threshold_exit;
6697 +#define DPNI_RX_FS_DIST_ENABLE_SHIFT 0
6698 +#define DPNI_RX_FS_DIST_ENABLE_SIZE 1
6699 +struct dpni_cmd_set_rx_fs_dist {
6703 + __le16 miss_flow_id;
6705 + __le64 key_cfg_iova;
6708 +#define DPNI_RX_HASH_DIST_ENABLE_SHIFT 0
6709 +#define DPNI_RX_HASH_DIST_ENABLE_SIZE 1
6710 +struct dpni_cmd_set_rx_hash_dist {
6715 + __le64 key_cfg_iova;
6718 #endif /* _FSL_DPNI_CMD_H */
6719 --- a/drivers/staging/fsl-dpaa2/ethernet/dpni.c
6720 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpni.c
6721 @@ -122,7 +122,7 @@ int dpni_open(struct fsl_mc_io *mc_io,
6725 - struct mc_command cmd = { 0 };
6726 + struct fsl_mc_command cmd = { 0 };
6727 struct dpni_cmd_open *cmd_params;
6730 @@ -160,7 +160,7 @@ int dpni_close(struct fsl_mc_io *mc_io,
6734 - struct mc_command cmd = { 0 };
6735 + struct fsl_mc_command cmd = { 0 };
6737 /* prepare command */
6738 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
6739 @@ -188,7 +188,7 @@ int dpni_set_pools(struct fsl_mc_io *mc_
6741 const struct dpni_pools_cfg *cfg)
6743 - struct mc_command cmd = { 0 };
6744 + struct fsl_mc_command cmd = { 0 };
6745 struct dpni_cmd_set_pools *cmd_params;
6748 @@ -199,7 +199,10 @@ int dpni_set_pools(struct fsl_mc_io *mc_
6749 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
6750 cmd_params->num_dpbp = cfg->num_dpbp;
6751 for (i = 0; i < DPNI_MAX_DPBP; i++) {
6752 - cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
6753 + cmd_params->pool[i].dpbp_id =
6754 + cpu_to_le16(cfg->pools[i].dpbp_id);
6755 + cmd_params->pool[i].priority_mask =
6756 + cfg->pools[i].priority_mask;
6757 cmd_params->buffer_size[i] =
6758 cpu_to_le16(cfg->pools[i].buffer_size);
6759 cmd_params->backup_pool_mask |=
6760 @@ -222,7 +225,7 @@ int dpni_enable(struct fsl_mc_io *mc_io,
6764 - struct mc_command cmd = { 0 };
6765 + struct fsl_mc_command cmd = { 0 };
6767 /* prepare command */
6768 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
6769 @@ -245,7 +248,7 @@ int dpni_disable(struct fsl_mc_io *mc_io
6773 - struct mc_command cmd = { 0 };
6774 + struct fsl_mc_command cmd = { 0 };
6776 /* prepare command */
6777 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
6778 @@ -270,7 +273,7 @@ int dpni_is_enabled(struct fsl_mc_io *mc
6782 - struct mc_command cmd = { 0 };
6783 + struct fsl_mc_command cmd = { 0 };
6784 struct dpni_rsp_is_enabled *rsp_params;
6787 @@ -303,7 +306,7 @@ int dpni_reset(struct fsl_mc_io *mc_io,
6791 - struct mc_command cmd = { 0 };
6792 + struct fsl_mc_command cmd = { 0 };
6794 /* prepare command */
6795 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
6796 @@ -335,7 +338,7 @@ int dpni_set_irq_enable(struct fsl_mc_io
6800 - struct mc_command cmd = { 0 };
6801 + struct fsl_mc_command cmd = { 0 };
6802 struct dpni_cmd_set_irq_enable *cmd_params;
6804 /* prepare command */
6805 @@ -366,7 +369,7 @@ int dpni_get_irq_enable(struct fsl_mc_io
6809 - struct mc_command cmd = { 0 };
6810 + struct fsl_mc_command cmd = { 0 };
6811 struct dpni_cmd_get_irq_enable *cmd_params;
6812 struct dpni_rsp_get_irq_enable *rsp_params;
6814 @@ -413,7 +416,7 @@ int dpni_set_irq_mask(struct fsl_mc_io *
6818 - struct mc_command cmd = { 0 };
6819 + struct fsl_mc_command cmd = { 0 };
6820 struct dpni_cmd_set_irq_mask *cmd_params;
6822 /* prepare command */
6823 @@ -447,7 +450,7 @@ int dpni_get_irq_mask(struct fsl_mc_io *
6827 - struct mc_command cmd = { 0 };
6828 + struct fsl_mc_command cmd = { 0 };
6829 struct dpni_cmd_get_irq_mask *cmd_params;
6830 struct dpni_rsp_get_irq_mask *rsp_params;
6832 @@ -489,7 +492,7 @@ int dpni_get_irq_status(struct fsl_mc_io
6836 - struct mc_command cmd = { 0 };
6837 + struct fsl_mc_command cmd = { 0 };
6838 struct dpni_cmd_get_irq_status *cmd_params;
6839 struct dpni_rsp_get_irq_status *rsp_params;
6841 @@ -532,7 +535,7 @@ int dpni_clear_irq_status(struct fsl_mc_
6845 - struct mc_command cmd = { 0 };
6846 + struct fsl_mc_command cmd = { 0 };
6847 struct dpni_cmd_clear_irq_status *cmd_params;
6849 /* prepare command */
6850 @@ -561,7 +564,7 @@ int dpni_get_attributes(struct fsl_mc_io
6852 struct dpni_attr *attr)
6854 - struct mc_command cmd = { 0 };
6855 + struct fsl_mc_command cmd = { 0 };
6856 struct dpni_rsp_get_attr *rsp_params;
6859 @@ -609,7 +612,7 @@ int dpni_set_errors_behavior(struct fsl_
6861 struct dpni_error_cfg *cfg)
6863 - struct mc_command cmd = { 0 };
6864 + struct fsl_mc_command cmd = { 0 };
6865 struct dpni_cmd_set_errors_behavior *cmd_params;
6867 /* prepare command */
6868 @@ -641,7 +644,7 @@ int dpni_get_buffer_layout(struct fsl_mc
6869 enum dpni_queue_type qtype,
6870 struct dpni_buffer_layout *layout)
6872 - struct mc_command cmd = { 0 };
6873 + struct fsl_mc_command cmd = { 0 };
6874 struct dpni_cmd_get_buffer_layout *cmd_params;
6875 struct dpni_rsp_get_buffer_layout *rsp_params;
6877 @@ -689,7 +692,7 @@ int dpni_set_buffer_layout(struct fsl_mc
6878 enum dpni_queue_type qtype,
6879 const struct dpni_buffer_layout *layout)
6881 - struct mc_command cmd = { 0 };
6882 + struct fsl_mc_command cmd = { 0 };
6883 struct dpni_cmd_set_buffer_layout *cmd_params;
6885 /* prepare command */
6886 @@ -731,7 +734,7 @@ int dpni_set_offload(struct fsl_mc_io *m
6887 enum dpni_offload type,
6890 - struct mc_command cmd = { 0 };
6891 + struct fsl_mc_command cmd = { 0 };
6892 struct dpni_cmd_set_offload *cmd_params;
6894 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
6895 @@ -750,7 +753,7 @@ int dpni_get_offload(struct fsl_mc_io *m
6896 enum dpni_offload type,
6899 - struct mc_command cmd = { 0 };
6900 + struct fsl_mc_command cmd = { 0 };
6901 struct dpni_cmd_get_offload *cmd_params;
6902 struct dpni_rsp_get_offload *rsp_params;
6904 @@ -792,7 +795,7 @@ int dpni_get_qdid(struct fsl_mc_io *mc_i
6905 enum dpni_queue_type qtype,
6908 - struct mc_command cmd = { 0 };
6909 + struct fsl_mc_command cmd = { 0 };
6910 struct dpni_cmd_get_qdid *cmd_params;
6911 struct dpni_rsp_get_qdid *rsp_params;
6913 @@ -830,7 +833,7 @@ int dpni_get_tx_data_offset(struct fsl_m
6917 - struct mc_command cmd = { 0 };
6918 + struct fsl_mc_command cmd = { 0 };
6919 struct dpni_rsp_get_tx_data_offset *rsp_params;
6922 @@ -865,7 +868,7 @@ int dpni_set_link_cfg(struct fsl_mc_io *
6924 const struct dpni_link_cfg *cfg)
6926 - struct mc_command cmd = { 0 };
6927 + struct fsl_mc_command cmd = { 0 };
6928 struct dpni_cmd_set_link_cfg *cmd_params;
6930 /* prepare command */
6931 @@ -894,7 +897,7 @@ int dpni_get_link_state(struct fsl_mc_io
6933 struct dpni_link_state *state)
6935 - struct mc_command cmd = { 0 };
6936 + struct fsl_mc_command cmd = { 0 };
6937 struct dpni_rsp_get_link_state *rsp_params;
6940 @@ -918,6 +921,44 @@ int dpni_get_link_state(struct fsl_mc_io
6944 + * dpni_set_tx_shaping() - Set the transmit shaping
6945 + * @mc_io: Pointer to MC portal's I/O object
6946 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6947 + * @token: Token of DPNI object
6948 + * @tx_cr_shaper: TX committed rate shaping configuration
6949 + * @tx_er_shaper: TX excess rate shaping configuration
6950 + * @coupled: Committed and excess rate shapers are coupled
6952 + * Return: '0' on Success; Error code otherwise.
6954 +int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
6957 + const struct dpni_tx_shaping_cfg *tx_cr_shaper,
6958 + const struct dpni_tx_shaping_cfg *tx_er_shaper,
6961 + struct fsl_mc_command cmd = { 0 };
6962 + struct dpni_cmd_set_tx_shaping *cmd_params;
6964 + /* prepare command */
6965 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
6968 + cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
6969 + cmd_params->tx_cr_max_burst_size =
6970 + cpu_to_le16(tx_cr_shaper->max_burst_size);
6971 + cmd_params->tx_er_max_burst_size =
6972 + cpu_to_le16(tx_er_shaper->max_burst_size);
6973 + cmd_params->tx_cr_rate_limit = cpu_to_le32(tx_cr_shaper->rate_limit);
6974 + cmd_params->tx_er_rate_limit = cpu_to_le32(tx_er_shaper->rate_limit);
6975 + dpni_set_field(cmd_params->coupled, COUPLED, coupled);
6977 + /* send command to mc*/
6978 + return mc_send_command(mc_io, &cmd);
6982 * dpni_set_max_frame_length() - Set the maximum received frame length.
6983 * @mc_io: Pointer to MC portal's I/O object
6984 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
6985 @@ -933,7 +974,7 @@ int dpni_set_max_frame_length(struct fsl
6987 u16 max_frame_length)
6989 - struct mc_command cmd = { 0 };
6990 + struct fsl_mc_command cmd = { 0 };
6991 struct dpni_cmd_set_max_frame_length *cmd_params;
6993 /* prepare command */
6994 @@ -963,7 +1004,7 @@ int dpni_get_max_frame_length(struct fsl
6996 u16 *max_frame_length)
6998 - struct mc_command cmd = { 0 };
6999 + struct fsl_mc_command cmd = { 0 };
7000 struct dpni_rsp_get_max_frame_length *rsp_params;
7003 @@ -998,7 +1039,7 @@ int dpni_set_multicast_promisc(struct fs
7007 - struct mc_command cmd = { 0 };
7008 + struct fsl_mc_command cmd = { 0 };
7009 struct dpni_cmd_set_multicast_promisc *cmd_params;
7011 /* prepare command */
7012 @@ -1026,7 +1067,7 @@ int dpni_get_multicast_promisc(struct fs
7016 - struct mc_command cmd = { 0 };
7017 + struct fsl_mc_command cmd = { 0 };
7018 struct dpni_rsp_get_multicast_promisc *rsp_params;
7021 @@ -1061,7 +1102,7 @@ int dpni_set_unicast_promisc(struct fsl_
7025 - struct mc_command cmd = { 0 };
7026 + struct fsl_mc_command cmd = { 0 };
7027 struct dpni_cmd_set_unicast_promisc *cmd_params;
7029 /* prepare command */
7030 @@ -1089,7 +1130,7 @@ int dpni_get_unicast_promisc(struct fsl_
7034 - struct mc_command cmd = { 0 };
7035 + struct fsl_mc_command cmd = { 0 };
7036 struct dpni_rsp_get_unicast_promisc *rsp_params;
7039 @@ -1124,7 +1165,7 @@ int dpni_set_primary_mac_addr(struct fsl
7041 const u8 mac_addr[6])
7043 - struct mc_command cmd = { 0 };
7044 + struct fsl_mc_command cmd = { 0 };
7045 struct dpni_cmd_set_primary_mac_addr *cmd_params;
7048 @@ -1154,7 +1195,7 @@ int dpni_get_primary_mac_addr(struct fsl
7052 - struct mc_command cmd = { 0 };
7053 + struct fsl_mc_command cmd = { 0 };
7054 struct dpni_rsp_get_primary_mac_addr *rsp_params;
7057 @@ -1193,7 +1234,7 @@ int dpni_get_port_mac_addr(struct fsl_mc
7061 - struct mc_command cmd = { 0 };
7062 + struct fsl_mc_command cmd = { 0 };
7063 struct dpni_rsp_get_port_mac_addr *rsp_params;
7066 @@ -1229,7 +1270,7 @@ int dpni_add_mac_addr(struct fsl_mc_io *
7068 const u8 mac_addr[6])
7070 - struct mc_command cmd = { 0 };
7071 + struct fsl_mc_command cmd = { 0 };
7072 struct dpni_cmd_add_mac_addr *cmd_params;
7075 @@ -1259,7 +1300,7 @@ int dpni_remove_mac_addr(struct fsl_mc_i
7077 const u8 mac_addr[6])
7079 - struct mc_command cmd = { 0 };
7080 + struct fsl_mc_command cmd = { 0 };
7081 struct dpni_cmd_remove_mac_addr *cmd_params;
7084 @@ -1293,7 +1334,7 @@ int dpni_clear_mac_filters(struct fsl_mc
7088 - struct mc_command cmd = { 0 };
7089 + struct fsl_mc_command cmd = { 0 };
7090 struct dpni_cmd_clear_mac_filters *cmd_params;
7092 /* prepare command */
7093 @@ -1309,6 +1350,55 @@ int dpni_clear_mac_filters(struct fsl_mc
7097 + * dpni_set_tx_priorities() - Set transmission TC priority configuration
7098 + * @mc_io: Pointer to MC portal's I/O object
7099 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7100 + * @token: Token of DPNI object
7101 + * @cfg: Transmission selection configuration
7103 + * warning: Allowed only when DPNI is disabled
7105 + * Return: '0' on Success; Error code otherwise.
7107 +int dpni_set_tx_priorities(struct fsl_mc_io *mc_io,
7110 + const struct dpni_tx_priorities_cfg *cfg)
7112 + struct dpni_cmd_set_tx_priorities *cmd_params;
7113 + struct fsl_mc_command cmd = { 0 };
7116 + /* prepare command */
7117 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_PRIORITIES,
7120 + cmd_params = (struct dpni_cmd_set_tx_priorities *)cmd.params;
7121 + dpni_set_field(cmd_params->flags,
7123 + cfg->separate_groups);
7124 + cmd_params->prio_group_A = cfg->prio_group_A;
7125 + cmd_params->prio_group_B = cfg->prio_group_B;
7127 + for (i = 0; i + 1 < DPNI_MAX_TC; i += 2) {
7128 + dpni_set_field(cmd_params->modes[i / 2],
7130 + cfg->tc_sched[i].mode);
7131 + dpni_set_field(cmd_params->modes[i / 2],
7133 + cfg->tc_sched[i + 1].mode);
7136 + for (i = 0; i < DPNI_MAX_TC; i++) {
7137 + cmd_params->delta_bandwidth[i] =
7138 + cpu_to_le16(cfg->tc_sched[i].delta_bandwidth);
7141 + /* send command to mc*/
7142 + return mc_send_command(mc_io, &cmd);
7146 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
7147 * @mc_io: Pointer to MC portal's I/O object
7148 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7149 @@ -1327,7 +1417,7 @@ int dpni_set_rx_tc_dist(struct fsl_mc_io
7151 const struct dpni_rx_tc_dist_cfg *cfg)
7153 - struct mc_command cmd = { 0 };
7154 + struct fsl_mc_command cmd = { 0 };
7155 struct dpni_cmd_set_rx_tc_dist *cmd_params;
7157 /* prepare command */
7158 @@ -1346,6 +1436,293 @@ int dpni_set_rx_tc_dist(struct fsl_mc_io
7159 return mc_send_command(mc_io, &cmd);
7163 + * dpni_set_qos_table() - Set QoS mapping table
7164 + * @mc_io: Pointer to MC portal's I/O object
7165 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7166 + * @token: Token of DPNI object
7167 + * @cfg: QoS table configuration
7169 + * This function and all QoS-related functions require that
7170 + *'max_tcs > 1' was set at DPNI creation.
7172 + * warning: Before calling this function, call dpkg_prepare_key_cfg() to
7173 + * prepare the key_cfg_iova parameter
7175 + * Return: '0' on Success; Error code otherwise.
7177 +int dpni_set_qos_table(struct fsl_mc_io *mc_io,
7180 + const struct dpni_qos_tbl_cfg *cfg)
7182 + struct dpni_cmd_set_qos_table *cmd_params;
7183 + struct fsl_mc_command cmd = { 0 };
7185 + /* prepare command */
7186 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
7189 + cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
7190 + cmd_params->default_tc = cfg->default_tc;
7191 + cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
7192 + dpni_set_field(cmd_params->discard_on_miss,
7194 + cfg->discard_on_miss);
7196 + /* send command to mc*/
7197 + return mc_send_command(mc_io, &cmd);
7201 + * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
7202 + * @mc_io: Pointer to MC portal's I/O object
7203 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7204 + * @token: Token of DPNI object
7205 + * @cfg: QoS rule to add
7206 + * @tc_id: Traffic class selection (0-7)
7207 + * @index: Location in the QoS table where to insert the entry.
7208 + * Only relevant if MASKING is enabled for QoS classification on
7209 + * this DPNI, it is ignored for exact match.
7211 + * Return: '0' on Success; Error code otherwise.
7213 +int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
7216 + const struct dpni_rule_cfg *cfg,
7220 + struct dpni_cmd_add_qos_entry *cmd_params;
7221 + struct fsl_mc_command cmd = { 0 };
7223 + /* prepare command */
7224 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
7227 + cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
7228 + cmd_params->tc_id = tc_id;
7229 + cmd_params->key_size = cfg->key_size;
7230 + cmd_params->index = cpu_to_le16(index);
7231 + cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
7232 + cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
7234 + /* send command to mc*/
7235 + return mc_send_command(mc_io, &cmd);
7239 + * dpni_remove_qos_entry() - Remove QoS mapping entry
7240 + * @mc_io: Pointer to MC portal's I/O object
7241 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7242 + * @token: Token of DPNI object
7243 + * @cfg: QoS rule to remove
7245 + * Return: '0' on Success; Error code otherwise.
7247 +int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
7250 + const struct dpni_rule_cfg *cfg)
7252 + struct dpni_cmd_remove_qos_entry *cmd_params;
7253 + struct fsl_mc_command cmd = { 0 };
7255 + /* prepare command */
7256 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
7259 + cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
7260 + cmd_params->key_size = cfg->key_size;
7261 + cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
7262 + cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
7264 + /* send command to mc*/
7265 + return mc_send_command(mc_io, &cmd);
7269 + * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
7270 + * (to select a flow ID)
7271 + * @mc_io: Pointer to MC portal's I/O object
7272 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7273 + * @token: Token of DPNI object
7274 + * @tc_id: Traffic class selection (0-7)
7275 + * @index: Location in the QoS table where to insert the entry.
7276 + * Only relevant if MASKING is enabled for QoS
7277 + * classification on this DPNI, it is ignored for exact match.
7278 + * @cfg: Flow steering rule to add
7279 + * @action: Action to be taken as result of a classification hit
7281 + * Return: '0' on Success; Error code otherwise.
7283 +int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
7288 + const struct dpni_rule_cfg *cfg,
7289 + const struct dpni_fs_action_cfg *action)
7291 + struct dpni_cmd_add_fs_entry *cmd_params;
7292 + struct fsl_mc_command cmd = { 0 };
7294 + /* prepare command */
7295 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
7298 + cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
7299 + cmd_params->tc_id = tc_id;
7300 + cmd_params->key_size = cfg->key_size;
7301 + cmd_params->index = cpu_to_le16(index);
7302 + cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
7303 + cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
7304 + cmd_params->options = cpu_to_le16(action->options);
7305 + cmd_params->flow_id = cpu_to_le16(action->flow_id);
7306 + cmd_params->flc = cpu_to_le64(action->flc);
7308 + /* send command to mc*/
7309 + return mc_send_command(mc_io, &cmd);
7313 + * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
7315 + * @mc_io: Pointer to MC portal's I/O object
7316 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7317 + * @token: Token of DPNI object
7318 + * @tc_id: Traffic class selection (0-7)
7319 + * @cfg: Flow steering rule to remove
7321 + * Return: '0' on Success; Error code otherwise.
7323 +int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
7327 + const struct dpni_rule_cfg *cfg)
7329 + struct dpni_cmd_remove_fs_entry *cmd_params;
7330 + struct fsl_mc_command cmd = { 0 };
7332 + /* prepare command */
7333 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
7336 + cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
7337 + cmd_params->tc_id = tc_id;
7338 + cmd_params->key_size = cfg->key_size;
7339 + cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
7340 + cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
7342 + /* send command to mc*/
7343 + return mc_send_command(mc_io, &cmd);
7347 + * dpni_set_congestion_notification() - Set traffic class congestion
7348 + * notification configuration
7349 + * @mc_io: Pointer to MC portal's I/O object
7350 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7351 + * @token: Token of DPNI object
7352 + * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
7353 + * @tc_id: Traffic class selection (0-7)
7354 + * @cfg: Congestion notification configuration
7356 + * Return: '0' on Success; error code otherwise.
7358 +int dpni_set_congestion_notification(
7359 + struct fsl_mc_io *mc_io,
7362 + enum dpni_queue_type qtype,
7364 + const struct dpni_congestion_notification_cfg *cfg)
7366 + struct dpni_cmd_set_congestion_notification *cmd_params;
7367 + struct fsl_mc_command cmd = { 0 };
7369 + /* prepare command */
7370 + cmd.header = mc_encode_cmd_header(
7371 + DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
7374 + cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
7375 + cmd_params->qtype = qtype;
7376 + cmd_params->tc = tc_id;
7377 + cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
7378 + cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
7379 + cmd_params->dest_priority = cfg->dest_cfg.priority;
7380 + dpni_set_field(cmd_params->type_units, DEST_TYPE,
7381 + cfg->dest_cfg.dest_type);
7382 + dpni_set_field(cmd_params->type_units, CONG_UNITS, cfg->units);
7383 + cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
7384 + cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
7385 + cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
7386 + cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
7388 + /* send command to mc*/
7389 + return mc_send_command(mc_io, &cmd);
7393 + * dpni_get_congestion_notification() - Get traffic class congestion
7394 + * notification configuration
7395 + * @mc_io: Pointer to MC portal's I/O object
7396 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7397 + * @token: Token of DPNI object
7398 + * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
7399 + * @tc_id: bits 7-4 contain ceetm channel index (valid only for TX);
7400 + * bits 3-0 contain traffic class.
7401 + * Use macro DPNI_BUILD_CH_TC() to build correct value for
7402 + * tc_id parameter.
7403 + * @cfg: congestion notification configuration
7405 + * Return: '0' on Success; error code otherwise.
7407 +int dpni_get_congestion_notification(
7408 + struct fsl_mc_io *mc_io,
7411 + enum dpni_queue_type qtype,
7413 + struct dpni_congestion_notification_cfg *cfg)
7415 + struct dpni_rsp_get_congestion_notification *rsp_params;
7416 + struct dpni_cmd_get_congestion_notification *cmd_params;
7417 + struct fsl_mc_command cmd = { 0 };
7420 + /* prepare command */
7421 + cmd.header = mc_encode_cmd_header(
7422 + DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
7425 + cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
7426 + cmd_params->qtype = qtype;
7427 + cmd_params->tc = tc_id;
7429 + /* send command to mc*/
7430 + err = mc_send_command(mc_io, &cmd);
7434 + rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
7435 + cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
7436 + cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
7437 + cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
7438 + cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
7439 + cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
7440 + cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
7441 + cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
7442 + cfg->dest_cfg.priority = rsp_params->dest_priority;
7443 + cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
7450 * dpni_set_queue() - Set queue parameters
7451 * @mc_io: Pointer to MC portal's I/O object
7452 @@ -1371,7 +1748,7 @@ int dpni_set_queue(struct fsl_mc_io *mc_
7454 const struct dpni_queue *queue)
7456 - struct mc_command cmd = { 0 };
7457 + struct fsl_mc_command cmd = { 0 };
7458 struct dpni_cmd_set_queue *cmd_params;
7460 /* prepare command */
7461 @@ -1419,7 +1796,7 @@ int dpni_get_queue(struct fsl_mc_io *mc_
7462 struct dpni_queue *queue,
7463 struct dpni_queue_id *qid)
7465 - struct mc_command cmd = { 0 };
7466 + struct fsl_mc_command cmd = { 0 };
7467 struct dpni_cmd_get_queue *cmd_params;
7468 struct dpni_rsp_get_queue *rsp_params;
7470 @@ -1463,6 +1840,8 @@ int dpni_get_queue(struct fsl_mc_io *mc_
7471 * @token: Token of DPNI object
7472 * @page: Selects the statistics page to retrieve, see
7473 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 2.
7474 + * @param: Custom parameter for some pages used to select a certain
7475 + * statistic source, for example the TC.
7476 * @stat: Structure containing the statistics
7478 * Return: '0' on Success; Error code otherwise.
7479 @@ -1471,9 +1850,10 @@ int dpni_get_statistics(struct fsl_mc_io
7484 union dpni_statistics *stat)
7486 - struct mc_command cmd = { 0 };
7487 + struct fsl_mc_command cmd = { 0 };
7488 struct dpni_cmd_get_statistics *cmd_params;
7489 struct dpni_rsp_get_statistics *rsp_params;
7491 @@ -1484,6 +1864,7 @@ int dpni_get_statistics(struct fsl_mc_io
7493 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
7494 cmd_params->page_number = page;
7495 + cmd_params->param = param;
7497 /* send command to mc */
7498 err = mc_send_command(mc_io, &cmd);
7499 @@ -1499,6 +1880,29 @@ int dpni_get_statistics(struct fsl_mc_io
7503 + * dpni_reset_statistics() - Clears DPNI statistics
7504 + * @mc_io: Pointer to MC portal's I/O object
7505 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7506 + * @token: Token of DPNI object
7508 + * Return: '0' on Success; Error code otherwise.
7510 +int dpni_reset_statistics(struct fsl_mc_io *mc_io,
7514 + struct fsl_mc_command cmd = { 0 };
7516 + /* prepare command */
7517 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
7521 + /* send command to mc*/
7522 + return mc_send_command(mc_io, &cmd);
7526 * dpni_set_taildrop() - Set taildrop per queue or TC
7527 * @mc_io: Pointer to MC portal's I/O object
7528 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7529 @@ -1506,7 +1910,10 @@ int dpni_get_statistics(struct fsl_mc_io
7530 * @cg_point: Congestion point
7531 * @q_type: Queue type on which the taildrop is configured.
7532 * Only Rx queues are supported for now
7533 - * @tc: Traffic class to apply this taildrop to
7534 + * @tc: bits 7-4 contain ceetm channel index (valid only for TX);
7535 + * bits 3-0 contain traffic class.
7536 + * Use macro DPNI_BUILD_CH_TC() to build correct value for
7538 * @q_index: Index of the queue if the DPNI supports multiple queues for
7539 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
7540 * @taildrop: Taildrop structure
7541 @@ -1522,7 +1929,7 @@ int dpni_set_taildrop(struct fsl_mc_io *
7543 struct dpni_taildrop *taildrop)
7545 - struct mc_command cmd = { 0 };
7546 + struct fsl_mc_command cmd = { 0 };
7547 struct dpni_cmd_set_taildrop *cmd_params;
7549 /* prepare command */
7550 @@ -1550,7 +1957,10 @@ int dpni_set_taildrop(struct fsl_mc_io *
7551 * @cg_point: Congestion point
7552 * @q_type: Queue type on which the taildrop is configured.
7553 * Only Rx queues are supported for now
7554 - * @tc: Traffic class to apply this taildrop to
7555 + * @tc: bits 7-4 contain ceetm channel index (valid only for TX);
7556 + * bits 3-0 contain traffic class.
7557 + * Use macro DPNI_BUILD_CH_TC() to build correct value for
7559 * @q_index: Index of the queue if the DPNI supports multiple queues for
7560 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
7561 * @taildrop: Taildrop structure
7562 @@ -1566,7 +1976,7 @@ int dpni_get_taildrop(struct fsl_mc_io *
7564 struct dpni_taildrop *taildrop)
7566 - struct mc_command cmd = { 0 };
7567 + struct fsl_mc_command cmd = { 0 };
7568 struct dpni_cmd_get_taildrop *cmd_params;
7569 struct dpni_rsp_get_taildrop *rsp_params;
7571 @@ -1594,3 +2004,109 @@ int dpni_get_taildrop(struct fsl_mc_io *
7577 + * dpni_get_api_version() - Get Data Path Network Interface API version
7578 + * @mc_io: Pointer to MC portal's I/O object
7579 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7580 + * @major_ver: Major version of data path network interface API
7581 + * @minor_ver: Minor version of data path network interface API
7583 + * Return: '0' on Success; Error code otherwise.
7585 +int dpni_get_api_version(struct fsl_mc_io *mc_io,
7590 + struct dpni_rsp_get_api_version *rsp_params;
7591 + struct fsl_mc_command cmd = { 0 };
7594 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
7597 + err = mc_send_command(mc_io, &cmd);
7601 + rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
7602 + *major_ver = le16_to_cpu(rsp_params->major);
7603 + *minor_ver = le16_to_cpu(rsp_params->minor);
7609 + * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
7610 + * @mc_io: Pointer to MC portal's I/O object
7611 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7612 + * @token: Token of DPNI object
7613 + * @cfg: Distribution configuration
7614 + * If the FS is already enabled with a previous call the classification
7615 + * key will be changed but all the table rules are kept. If the
7616 + * existing rules do not match the key the results will not be
7617 + * predictable. It is the user responsibility to keep key integrity.
7618 + * If cfg.enable is set to 1 the command will create a flow steering table
7619 + * and will classify packets according to this table. The packets that
7620 + * miss all the table rules will be classified according to settings
7621 + * made in dpni_set_rx_hash_dist()
7622 + * If cfg.enable is set to 0 the command will clear flow steering table.
7623 + * The packets will be classified according to settings made in
7624 + * dpni_set_rx_hash_dist()
7626 +int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io,
7629 + const struct dpni_rx_dist_cfg *cfg)
7631 + struct dpni_cmd_set_rx_fs_dist *cmd_params;
7632 + struct fsl_mc_command cmd = { 0 };
7634 + /* prepare command */
7635 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
7638 + cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
7639 + cmd_params->dist_size = le16_to_cpu(cfg->dist_size);
7640 + dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
7641 + cmd_params->tc = cfg->tc;
7642 + cmd_params->miss_flow_id = le16_to_cpu(cfg->fs_miss_flow_id);
7643 + cmd_params->key_cfg_iova = le64_to_cpu(cfg->key_cfg_iova);
7645 + /* send command to mc*/
7646 + return mc_send_command(mc_io, &cmd);
7650 + * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
7651 + * @mc_io: Pointer to MC portal's I/O object
7652 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7653 + * @token: Token of DPNI object
7654 + * @cfg: Distribution configuration
7655 + * If cfg.enable is set to 1 the packets will be classified using a hash
7656 + * function based on the key received in cfg.key_cfg_iova parameter.
7657 + * If cfg.enable is set to 0 the packets will be sent to the queue configured
7658 + * in dpni_set_rx_dist_default_queue() call
7660 +int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io,
7663 + const struct dpni_rx_dist_cfg *cfg)
7665 + struct dpni_cmd_set_rx_hash_dist *cmd_params;
7666 + struct fsl_mc_command cmd = { 0 };
7668 + /* prepare command */
7669 + cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
7672 + cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
7673 + cmd_params->dist_size = le16_to_cpu(cfg->dist_size);
7674 + dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
7675 + cmd_params->tc = cfg->tc;
7676 + cmd_params->key_cfg_iova = le64_to_cpu(cfg->key_cfg_iova);
7678 + /* send command to mc*/
7679 + return mc_send_command(mc_io, &cmd);
7681 --- a/drivers/staging/fsl-dpaa2/ethernet/dpni.h
7682 +++ b/drivers/staging/fsl-dpaa2/ethernet/dpni.h
7683 @@ -52,6 +52,14 @@ struct fsl_mc_io;
7684 * Maximum number of buffer pools per DPNI
7686 #define DPNI_MAX_DPBP 8
7688 + * Maximum number of senders
7690 +#define DPNI_MAX_SENDERS 16
7692 + * Maximum distribution size
7694 +#define DPNI_MAX_DIST_SIZE 16
7697 * All traffic classes considered; see dpni_set_queue()
7698 @@ -123,13 +131,15 @@ struct dpni_pools_cfg {
7700 * struct pools - Buffer pools parameters
7701 * @dpbp_id: DPBP object ID
7702 + * @priority_mask: priorities served by DPBP
7703 * @buffer_size: Buffer size
7704 * @backup_pool: Backup pool
7713 } pools[DPNI_MAX_DPBP];
7716 @@ -476,6 +486,24 @@ union dpni_statistics {
7717 u64 egress_confirmed_frames;
7720 + * struct page_3 - Page_3 statistics structure with values for the
7722 + * @ceetm_dequeue_bytes: Cumulative count of the number of bytes
7724 + * @ceetm_dequeue_frames: Cumulative count of the number of frames
7726 + * @ceetm_reject_bytes: Cumulative count of the number of bytes in all
7727 + * frames whose enqueue was rejected
7728 + * @ceetm_reject_frames: Cumulative count of all frame enqueues
7732 + u64 ceetm_dequeue_bytes;
7733 + u64 ceetm_dequeue_frames;
7734 + u64 ceetm_reject_bytes;
7735 + u64 ceetm_reject_frames;
7738 * struct raw - raw statistics structure
7741 @@ -487,8 +515,13 @@ int dpni_get_statistics(struct fsl_mc_io
7746 union dpni_statistics *stat);
7748 +int dpni_reset_statistics(struct fsl_mc_io *mc_io,
7753 * Enable auto-negotiation
7755 @@ -505,6 +538,10 @@ int dpni_get_statistics(struct fsl_mc_io
7756 * Enable a-symmetric pause frames
7758 #define DPNI_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
7760 + * Enable priority flow control pause frames
7762 +#define DPNI_LINK_OPT_PFC_PAUSE 0x0000000000000010ULL
7765 * struct - Structure representing DPNI link configuration
7766 @@ -538,6 +575,23 @@ int dpni_get_link_state(struct fsl_mc_io
7768 struct dpni_link_state *state);
7771 + * struct dpni_tx_shaping - Structure representing DPNI tx shaping configuration
7772 + * @rate_limit: rate in Mbps
7773 + * @max_burst_size: burst size in bytes (up to 64KB)
7775 +struct dpni_tx_shaping_cfg {
7777 + u16 max_burst_size;
7780 +int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
7783 + const struct dpni_tx_shaping_cfg *tx_cr_shaper,
7784 + const struct dpni_tx_shaping_cfg *tx_er_shaper,
7787 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
7790 @@ -639,6 +693,70 @@ int dpni_prepare_key_cfg(const struct dp
7794 + * struct dpni_qos_tbl_cfg - Structure representing QOS table configuration
7795 + * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
7796 + * key extractions to be used as the QoS criteria by calling
7797 + * dpkg_prepare_key_cfg()
7798 + * @discard_on_miss: Set to '1' to discard frames in case of no match (miss);
7799 + * '0' to use the 'default_tc' in such cases
7800 + * @default_tc: Used in case of no-match and 'discard_on_miss'= 0
7802 +struct dpni_qos_tbl_cfg {
7804 + int discard_on_miss;
7808 +int dpni_set_qos_table(struct fsl_mc_io *mc_io,
7811 + const struct dpni_qos_tbl_cfg *cfg);
7814 + * enum dpni_tx_schedule_mode - DPNI Tx scheduling mode
7815 + * @DPNI_TX_SCHED_STRICT_PRIORITY: strict priority
7816 + * @DPNI_TX_SCHED_WEIGHTED_A: weighted based scheduling in group A
7817 + * @DPNI_TX_SCHED_WEIGHTED_B: weighted based scheduling in group B
7819 +enum dpni_tx_schedule_mode {
7820 + DPNI_TX_SCHED_STRICT_PRIORITY = 0,
7821 + DPNI_TX_SCHED_WEIGHTED_A,
7822 + DPNI_TX_SCHED_WEIGHTED_B,
7826 + * struct dpni_tx_schedule_cfg - Structure representing Tx scheduling conf
7827 + * @mode: Scheduling mode
7828 + * @delta_bandwidth: Bandwidth represented in weights from 100 to 10000;
7829 + * not applicable for 'strict-priority' mode;
7831 +struct dpni_tx_schedule_cfg {
7832 + enum dpni_tx_schedule_mode mode;
7833 + u16 delta_bandwidth;
7837 + * struct dpni_tx_priorities_cfg - Structure representing transmission
7838 + * priorities for DPNI TCs
7839 + * @tc_sched: An array of traffic-classes
7840 + * @prio_group_A: Priority of group A
7841 + * @prio_group_B: Priority of group B
7842 + * @separate_groups: Treat A and B groups as separate
7843 + * @ceetm_ch_idx: ceetm channel index to apply the changes
7845 +struct dpni_tx_priorities_cfg {
7846 + struct dpni_tx_schedule_cfg tc_sched[DPNI_MAX_TC];
7849 + u8 separate_groups;
7852 +int dpni_set_tx_priorities(struct fsl_mc_io *mc_io,
7855 + const struct dpni_tx_priorities_cfg *cfg);
7858 * struct dpni_rx_tc_dist_cfg - Rx traffic class distribution configuration
7859 * @dist_size: Set the distribution size;
7860 * supported values: 1,2,3,4,6,7,8,12,14,16,24,28,32,48,56,64,96,
7861 @@ -784,6 +902,108 @@ enum dpni_congestion_point {
7865 + * struct dpni_dest_cfg - Structure representing DPNI destination parameters
7866 + * @dest_type: Destination type
7867 + * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
7868 + * @priority: Priority selection within the DPIO or DPCON channel; valid
7869 + * values are 0-1 or 0-7, depending on the number of priorities
7870 + * in that channel; not relevant for 'DPNI_DEST_NONE' option
7872 +struct dpni_dest_cfg {
7873 + enum dpni_dest dest_type;
7878 +/* DPNI congestion options */
7881 + * CSCN message is written to message_iova once entering a
7882 + * congestion state (see 'threshold_entry')
7884 +#define DPNI_CONG_OPT_WRITE_MEM_ON_ENTER 0x00000001
7886 + * CSCN message is written to message_iova once exiting a
7887 + * congestion state (see 'threshold_exit')
7889 +#define DPNI_CONG_OPT_WRITE_MEM_ON_EXIT 0x00000002
7891 + * CSCN write will attempt to allocate into a cache (coherent write);
7892 + * valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>' is selected
7894 +#define DPNI_CONG_OPT_COHERENT_WRITE 0x00000004
7896 + * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
7897 + * DPIO/DPCON's WQ channel once entering a congestion state
7898 + * (see 'threshold_entry')
7900 +#define DPNI_CONG_OPT_NOTIFY_DEST_ON_ENTER 0x00000008
7902 + * if 'dest_cfg.dest_type != DPNI_DEST_NONE' CSCN message is sent to
7903 + * DPIO/DPCON's WQ channel once exiting a congestion state
7904 + * (see 'threshold_exit')
7906 +#define DPNI_CONG_OPT_NOTIFY_DEST_ON_EXIT 0x00000010
7908 + * if 'dest_cfg.dest_type != DPNI_DEST_NONE' when the CSCN is written to the
7909 + * sw-portal's DQRR, the DQRI interrupt is asserted immediately (if enabled)
7911 +#define DPNI_CONG_OPT_INTR_COALESCING_DISABLED 0x00000020
7913 + * This congestion will trigger flow control or priority flow control.
7914 + * This will have effect only if flow control is enabled with
7915 + * dpni_set_link_cfg().
7917 +#define DPNI_CONG_OPT_FLOW_CONTROL 0x00000040
7920 + * struct dpni_congestion_notification_cfg - congestion notification
7922 + * @units: Units type
7923 + * @threshold_entry: Above this threshold we enter a congestion state.
7924 + * set it to '0' to disable it
7925 + * @threshold_exit: Below this threshold we exit the congestion state.
7926 + * @message_ctx: The context that will be part of the CSCN message
7927 + * @message_iova: I/O virtual address (must be in DMA-able memory),
7928 + * must be 16B aligned; valid only if 'DPNI_CONG_OPT_WRITE_MEM_<X>'
7929 + * is contained in 'options'
7930 + * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
7931 + * @notification_mode: Mask of available options; use 'DPNI_CONG_OPT_<X>' values
7934 +struct dpni_congestion_notification_cfg {
7935 + enum dpni_congestion_unit units;
7936 + u32 threshold_entry;
7937 + u32 threshold_exit;
7940 + struct dpni_dest_cfg dest_cfg;
7941 + u16 notification_mode;
7944 +/** Compose TC parameter for function dpni_set_congestion_notification()
7945 + * and dpni_get_congestion_notification().
7947 +#define DPNI_BUILD_CH_TC(ceetm_ch_idx, tc) \
7948 + ((((ceetm_ch_idx) & 0x0F) << 4) | ((tc) & 0x0F))
7950 +int dpni_set_congestion_notification(
7951 + struct fsl_mc_io *mc_io,
7954 + enum dpni_queue_type qtype,
7956 + const struct dpni_congestion_notification_cfg *cfg);
7958 +int dpni_get_congestion_notification(
7959 + struct fsl_mc_io *mc_io,
7962 + enum dpni_queue_type qtype,
7964 + struct dpni_congestion_notification_cfg *cfg);
7967 * struct dpni_taildrop - Structure representing the taildrop
7968 * @enable: Indicates whether the taildrop is active or not.
7969 * @units: Indicates the unit of THRESHOLD. Queue taildrop only supports
7970 @@ -829,4 +1049,124 @@ struct dpni_rule_cfg {
7974 +int dpni_get_api_version(struct fsl_mc_io *mc_io,
7979 +int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
7982 + const struct dpni_rule_cfg *cfg,
7986 +int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
7989 + const struct dpni_rule_cfg *cfg);
7991 +int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
7996 + * Discard matching traffic. If set, this takes precedence over any other
7997 + * configuration and matching traffic is always discarded.
7999 + #define DPNI_FS_OPT_DISCARD 0x1
8002 + * Set FLC value. If set, flc member of struct dpni_fs_action_cfg is used to
8003 + * override the FLC value set per queue.
8004 + * For more details check the Frame Descriptor section in the hardware
8007 +#define DPNI_FS_OPT_SET_FLC 0x2
8010 + * Indicates whether the 6 lowest significant bits of FLC are used for stash
8011 + * control. If set, the 6 least significant bits in value are interpreted as
8013 + * - bits 0-1: indicates the number of 64 byte units of context that are
8014 + * stashed. FLC value is interpreted as a memory address in this case,
8015 + * excluding the 6 LS bits.
8016 + * - bits 2-3: indicates the number of 64 byte units of frame annotation
8017 + * to be stashed. Annotation is placed at FD[ADDR].
8018 + * - bits 4-5: indicates the number of 64 byte units of frame data to be
8019 + * stashed. Frame data is placed at FD[ADDR] + FD[OFFSET].
8020 + * This flag is ignored if DPNI_FS_OPT_SET_FLC is not specified.
8022 +#define DPNI_FS_OPT_SET_STASH_CONTROL 0x4
8025 + * struct dpni_fs_action_cfg - Action configuration for table look-up
8026 + * @flc: FLC value for traffic matching this rule. Please check the
8027 + * Frame Descriptor section in the hardware documentation for
8028 + * more information.
8029 + * @flow_id: Identifies the Rx queue used for matching traffic. Supported
8030 + * values are in range 0 to num_queue-1.
8031 + * @options: Any combination of DPNI_FS_OPT_ values.
8033 +struct dpni_fs_action_cfg {
8039 +int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
8044 + const struct dpni_rule_cfg *cfg,
8045 + const struct dpni_fs_action_cfg *action);
8047 +int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
8051 + const struct dpni_rule_cfg *cfg);
8054 + * When used for queue_idx in function dpni_set_rx_dist_default_queue
8055 + * will signal to dpni to drop all unclassified frames
8057 +#define DPNI_FS_MISS_DROP ((uint16_t)-1)
8060 + * struct dpni_rx_dist_cfg - distribution configuration
8061 + * @dist_size: distribution size; supported values: 1,2,3,4,6,7,8,
8062 + * 12,14,16,24,28,32,48,56,64,96,112,128,192,224,256,384,448,
8063 + * 512,768,896,1024
8064 + * @key_cfg_iova: I/O virtual address of 256 bytes DMA-able memory filled with
8065 + * the extractions to be used for the distribution key by calling
8066 + * dpkg_prepare_key_cfg() relevant only when enable!=0 otherwise
8068 + * @enable: enable/disable the distribution.
8069 + * @tc: TC id for which distribution is set
8070 + * @fs_miss_flow_id: when packet misses all rules from flow steering table and
8071 + * hash is disabled it will be put into this queue id; use
8072 + * DPNI_FS_MISS_DROP to drop frames. The value of this field is
8073 + * used only when flow steering distribution is enabled and hash
8074 + * distribution is disabled
8076 +struct dpni_rx_dist_cfg {
8081 + u16 fs_miss_flow_id;
8084 +int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io,
8087 + const struct dpni_rx_dist_cfg *cfg);
8089 +int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io,
8092 + const struct dpni_rx_dist_cfg *cfg);
8094 #endif /* __FSL_DPNI_H */