1 From ef0cc7d01f3eeca37c6bf864903af1c0cf0a792d Mon Sep 17 00:00:00 2001
2 From: Ioana Radulescu <ruxandra.radulescu@nxp.com>
3 Date: Fri, 5 May 2017 18:11:08 +0300
4 Subject: [PATCH] dpaa2-eth: Add Tx shaping support
6 Add support in sysfs for controlling DPNI Tx shaping
7 parameters: rate limit (in Mbps) and max burst size (in bytes).
8 The settings are per port.
10 TODO: See how to integrate Tx shaping support using
11 standard Linux tools (ethtool)
13 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
14 Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
16 drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 80 ++++++++++++++++++++++++
17 drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h | 4 ++
18 2 files changed, 84 insertions(+)
20 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
21 +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
22 @@ -3778,6 +3778,83 @@ const struct dcbnl_rtnl_ops dpaa2_eth_dc
27 +static ssize_t dpaa2_eth_show_tx_shaping(struct device *dev,
28 + struct device_attribute *attr,
31 + struct dpaa2_eth_priv *priv = netdev_priv(to_net_dev(dev));
32 + /* No MC API for getting the shaping config. We're stateful. */
33 + struct dpni_tx_shaping_cfg *scfg = &priv->shaping_cfg;
35 + return sprintf(buf, "%u %hu\n", scfg->rate_limit, scfg->max_burst_size);
38 +static ssize_t dpaa2_eth_write_tx_shaping(struct device *dev,
39 + struct device_attribute *attr,
44 + struct dpaa2_eth_priv *priv = netdev_priv(to_net_dev(dev));
45 + struct dpni_tx_shaping_cfg scfg;
47 + items = sscanf(buf, "%u %hu", &scfg.rate_limit, &scfg.max_burst_size);
49 + pr_err("Expected format: \"rate_limit(Mbps) max_burst_size(bytes)\"\n");
52 + /* Size restriction as per MC API documentation */
53 + if (scfg.max_burst_size > DPAA2_ETH_MAX_BURST_SIZE) {
54 + pr_err("max_burst_size must be <= %d\n",
55 + DPAA2_ETH_MAX_BURST_SIZE);
59 + err = dpni_set_tx_shaping(priv->mc_io, 0, priv->mc_token, &scfg);
61 + dev_err(dev, "dpni_set_tx_shaping() failed\n");
64 + /* If successful, save the current configuration for future inquiries */
65 + priv->shaping_cfg = scfg;
70 +static struct device_attribute dpaa2_eth_attrs[] = {
73 + dpaa2_eth_show_tx_shaping,
74 + dpaa2_eth_write_tx_shaping),
77 +static void dpaa2_eth_sysfs_init(struct device *dev)
81 + for (i = 0; i < ARRAY_SIZE(dpaa2_eth_attrs); i++) {
82 + err = device_create_file(dev, &dpaa2_eth_attrs[i]);
84 + dev_err(dev, "ERROR creating sysfs file\n");
92 + device_remove_file(dev, &dpaa2_eth_attrs[--i]);
95 +static void dpaa2_eth_sysfs_remove(struct device *dev)
99 + for (i = 0; i < ARRAY_SIZE(dpaa2_eth_attrs); i++)
100 + device_remove_file(dev, &dpaa2_eth_attrs[i]);
103 static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
106 @@ -3897,6 +3974,7 @@ static int dpaa2_eth_probe(struct fsl_mc
107 #ifdef CONFIG_DEBUG_FS
110 + dpaa2_eth_sysfs_init(&net_dev->dev);
112 dev_info(dev, "Probed interface %s\n", net_dev->name);
114 @@ -3944,6 +4022,8 @@ static int dpaa2_eth_remove(struct fsl_m
115 #ifdef CONFIG_DEBUG_FS
116 dpaa2_dbg_remove(priv);
118 + dpaa2_eth_sysfs_remove(&net_dev->dev);
120 unregister_netdev(net_dev);
122 if (priv->do_link_poll)
123 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h
124 +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h
127 #define DPAA2_ETH_FQ_TAILDROP_THRESH (1024 * 1024)
129 +/* Maximum burst size value for Tx shaping */
130 +#define DPAA2_ETH_MAX_BURST_SIZE 0xF7FF
132 /* Maximum number of Tx confirmation frames to be processed
133 * in a single NAPI call
135 @@ -445,6 +448,7 @@ struct dpaa2_eth_priv {
136 #ifdef CONFIG_DEBUG_FS
137 struct dpaa2_debugfs dbg;
139 + struct dpni_tx_shaping_cfg shaping_cfg;
142 #define DPAA2_RXH_SUPPORTED (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \