ath79/mikrotik: use routerbootpart partitions
[oweals/openwrt.git] / target / linux / layerscape / patches-5.4 / 701-net-0199-dpaa2-eth-Add-DCB-ops.patch
1 From a893019278e8030fbe251cdaa9d93b8257d1c083 Mon Sep 17 00:00:00 2001
2 From: Ioana Radulescu <ruxandra.radulescu@nxp.com>
3 Date: Thu, 5 Sep 2019 19:31:32 +0300
4 Subject: [PATCH] dpaa2-eth: Add DCB ops
5
6 Add a skeleton implementation of DCB PFC ops. Actual hardware
7 configuration to be added in further commits.
8
9 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
10 ---
11  drivers/net/ethernet/freescale/dpaa2/Kconfig     |  9 +++
12  drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 84 ++++++++++++++++++++++++
13  drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h |  5 ++
14  3 files changed, 98 insertions(+)
15
16 --- a/drivers/net/ethernet/freescale/dpaa2/Kconfig
17 +++ b/drivers/net/ethernet/freescale/dpaa2/Kconfig
18 @@ -8,6 +8,15 @@ config FSL_DPAA2_ETH
19           The driver manages network objects discovered on the Freescale
20           MC bus.
21  
22 +if FSL_DPAA2_ETH
23 +config FSL_DPAA2_ETH_DCB
24 +       bool "Data Center Bridging (DCB) Support"
25 +       default n
26 +       depends on DCB
27 +       help
28 +         Enable Priority-Based Flow Control (PFC) support in the driver
29 +endif
30 +
31  config FSL_DPAA2_PTP_CLOCK
32         tristate "Freescale DPAA2 PTP Clock"
33         depends on FSL_DPAA2_ETH && PTP_1588_CLOCK_QORIQ
34 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
35 +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
36 @@ -3607,6 +3607,81 @@ static void del_ch_napi(struct dpaa2_eth
37         }
38  }
39  
40 +#ifdef CONFIG_FSL_DPAA2_ETH_DCB
41 +static int dpaa2_eth_dcbnl_ieee_getpfc(struct net_device *net_dev,
42 +                                      struct ieee_pfc *pfc)
43 +{
44 +       struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
45 +
46 +       memcpy(pfc, &priv->pfc, sizeof(priv->pfc));
47 +       pfc->pfc_cap = dpaa2_eth_tc_count(priv);
48 +
49 +       return 0;
50 +}
51 +
52 +static int dpaa2_eth_dcbnl_ieee_setpfc(struct net_device *net_dev,
53 +                                      struct ieee_pfc *pfc)
54 +{
55 +       struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
56 +
57 +       if (pfc->mbc || pfc->delay)
58 +               return -EOPNOTSUPP;
59 +
60 +       /* If same PFC enabled mask, nothing to do */
61 +       if (priv->pfc.pfc_en == pfc->pfc_en)
62 +               return 0;
63 +
64 +       memcpy(&priv->pfc, pfc, sizeof(priv->pfc));
65 +
66 +       return 0;
67 +}
68 +
69 +static u8 dpaa2_eth_dcbnl_getdcbx(struct net_device *net_dev)
70 +{
71 +       struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
72 +
73 +       return priv->dcbx_mode;
74 +}
75 +
76 +static u8 dpaa2_eth_dcbnl_setdcbx(struct net_device *net_dev, u8 mode)
77 +{
78 +       struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
79 +
80 +       priv->dcbx_mode = mode;
81 +       return 0;
82 +}
83 +
84 +static u8 dpaa2_eth_dcbnl_getcap(struct net_device *net_dev, int capid, u8 *cap)
85 +{
86 +       struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
87 +
88 +       switch (capid) {
89 +       case DCB_CAP_ATTR_PFC:
90 +               *cap = true;
91 +               break;
92 +       case DCB_CAP_ATTR_PFC_TCS:
93 +               *cap = 1 << (dpaa2_eth_tc_count(priv) - 1);
94 +               break;
95 +       case DCB_CAP_ATTR_DCBX:
96 +               *cap = priv->dcbx_mode;
97 +               break;
98 +       default:
99 +               *cap = false;
100 +               break;
101 +       }
102 +
103 +       return 0;
104 +}
105 +
106 +const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops = {
107 +       .ieee_getpfc    = dpaa2_eth_dcbnl_ieee_getpfc,
108 +       .ieee_setpfc    = dpaa2_eth_dcbnl_ieee_setpfc,
109 +       .getdcbx        = dpaa2_eth_dcbnl_getdcbx,
110 +       .setdcbx        = dpaa2_eth_dcbnl_setdcbx,
111 +       .getcap         = dpaa2_eth_dcbnl_getcap,
112 +};
113 +#endif
114 +
115  static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev)
116  {
117         struct device *dev;
118 @@ -3696,6 +3771,15 @@ static int dpaa2_eth_probe(struct fsl_mc
119         if (err)
120                 goto err_alloc_rings;
121  
122 +#ifdef CONFIG_FSL_DPAA2_ETH_DCB
123 +       if (dpaa2_eth_has_pause_support(priv) && priv->vlan_cls_enabled) {
124 +               priv->dcbx_mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
125 +               net_dev->dcbnl_ops = &dpaa2_eth_dcbnl_ops;
126 +       } else {
127 +               dev_dbg(dev, "PFC not supported\n");
128 +       }
129 +#endif
130 +
131         err = setup_irqs(dpni_dev);
132         if (err) {
133                 netdev_warn(net_dev, "Failed to set link interrupt, fall back to polling\n");
134 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h
135 +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.h
136 @@ -6,6 +6,7 @@
137  #ifndef __DPAA2_ETH_H
138  #define __DPAA2_ETH_H
139  
140 +#include <linux/dcbnl.h>
141  #include <linux/netdevice.h>
142  #include <linux/if_vlan.h>
143  #include <linux/fsl/mc.h>
144 @@ -422,6 +423,10 @@ struct dpaa2_eth_priv {
145         struct dpaa2_eth_cls_rule *cls_rules;
146         u8 rx_cls_enabled;
147         u8 vlan_cls_enabled;
148 +#ifdef CONFIG_FSL_DPAA2_ETH_DCB
149 +       u8 dcbx_mode;
150 +       struct ieee_pfc pfc;
151 +#endif
152         struct bpf_prog *xdp_prog;
153  #ifdef CONFIG_DEBUG_FS
154         struct dpaa2_debugfs dbg;