ath79/mikrotik: use routerbootpart partitions
[oweals/openwrt.git] / target / linux / layerscape / patches-5.4 / 701-net-0204-dpaa2-eth-Add-Tx-shaping-support.patch
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
5
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.
9
10 TODO: See how to integrate Tx shaping support using
11 standard Linux tools (ethtool)
12
13 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
14 Signed-off-by: Bogdan Purcareata <bogdan.purcareata@nxp.com>
15 ---
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(+)
19
20 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
21 +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
22 @@ -3771,6 +3771,83 @@ const struct dcbnl_rtnl_ops dpaa2_eth_dc
23  };
24  #endif
25  
26 +/* SysFS support */
27 +static ssize_t dpaa2_eth_show_tx_shaping(struct device *dev,
28 +                                        struct device_attribute *attr,
29 +                                        char *buf)
30 +{
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;
34 +
35 +       return sprintf(buf, "%u %hu\n", scfg->rate_limit, scfg->max_burst_size);
36 +}
37 +
38 +static ssize_t dpaa2_eth_write_tx_shaping(struct device *dev,
39 +                                         struct device_attribute *attr,
40 +                                         const char *buf,
41 +                                         size_t count)
42 +{
43 +       int err, items;
44 +       struct dpaa2_eth_priv *priv = netdev_priv(to_net_dev(dev));
45 +       struct dpni_tx_shaping_cfg scfg;
46 +
47 +       items = sscanf(buf, "%u %hu", &scfg.rate_limit, &scfg.max_burst_size);
48 +       if (items != 2) {
49 +               pr_err("Expected format: \"rate_limit(Mbps) max_burst_size(bytes)\"\n");
50 +               return -EINVAL;
51 +       }
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);
56 +               return -EINVAL;
57 +       }
58 +
59 +       err = dpni_set_tx_shaping(priv->mc_io, 0, priv->mc_token, &scfg);
60 +       if (err) {
61 +               dev_err(dev, "dpni_set_tx_shaping() failed\n");
62 +               return -EPERM;
63 +       }
64 +       /* If successful, save the current configuration for future inquiries */
65 +       priv->shaping_cfg = scfg;
66 +
67 +       return count;
68 +}
69 +
70 +static struct device_attribute dpaa2_eth_attrs[] = {
71 +       __ATTR(tx_shaping,
72 +              0600,
73 +              dpaa2_eth_show_tx_shaping,
74 +              dpaa2_eth_write_tx_shaping),
75 +};
76 +
77 +static void dpaa2_eth_sysfs_init(struct device *dev)
78 +{
79 +       int i, err;
80 +
81 +       for (i = 0; i < ARRAY_SIZE(dpaa2_eth_attrs); i++) {
82 +               err = device_create_file(dev, &dpaa2_eth_attrs[i]);
83 +               if (err) {
84 +                       dev_err(dev, "ERROR creating sysfs file\n");
85 +                       goto undo;
86 +               }
87 +       }
88 +       return;
89 +
90 +undo:
91 +       while (i > 0)
92 +               device_remove_file(dev, &dpaa2_eth_attrs[--i]);
93 +}
94 +
95 +static void dpaa2_eth_sysfs_remove(struct device *dev)
96 +{
97 +       int i;
98 +
99 +       for (i = 0; i < ARRAY_SIZE(dpaa2_eth_attrs); i++)
100 +               device_remove_file(dev, &dpaa2_eth_attrs[i]);
101 +}
102 +
103  static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
104  {
105         struct device *dev;
106 @@ -3890,6 +3967,7 @@ static int dpaa2_eth_probe(struct fsl_mc
107  #ifdef CONFIG_DEBUG_FS
108         dpaa2_dbg_add(priv);
109  #endif
110 +       dpaa2_eth_sysfs_init(&net_dev->dev);
111  
112         dev_info(dev, "Probed interface %s\n", net_dev->name);
113         return 0;
114 @@ -3937,6 +4015,8 @@ static int dpaa2_eth_remove(struct fsl_m
115  #ifdef CONFIG_DEBUG_FS
116         dpaa2_dbg_remove(priv);
117  #endif
118 +       dpaa2_eth_sysfs_remove(&net_dev->dev);
119 +
120         unregister_netdev(net_dev);
121  
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
125 @@ -42,6 +42,9 @@
126   */
127  #define DPAA2_ETH_FQ_TAILDROP_THRESH   (1024 * 1024)
128  
129 +/* Maximum burst size value for Tx shaping */
130 +#define DPAA2_ETH_MAX_BURST_SIZE       0xF7FF
131 +
132  /* Maximum number of Tx confirmation frames to be processed
133   * in a single NAPI call
134   */
135 @@ -444,6 +447,7 @@ struct dpaa2_eth_priv {
136  #ifdef CONFIG_DEBUG_FS
137         struct dpaa2_debugfs dbg;
138  #endif
139 +       struct dpni_tx_shaping_cfg shaping_cfg;
140  };
141  
142  #define DPAA2_RXH_SUPPORTED    (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \