ath79/mikrotik: use routerbootpart partitions
[oweals/openwrt.git] / target / linux / layerscape / patches-5.4 / 701-net-0245-net-mscc-ocelot-refactor-ethtool-callbacks.patch
1 From a155893c9c272b2ed1dc3b236d55ca8f651a6ea1 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Sat, 9 Nov 2019 15:02:54 +0200
4 Subject: [PATCH] net: mscc: ocelot: refactor ethtool callbacks
5
6 Convert them into an implementation that can be called from DSA as well.
7
8 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
9 Signed-off-by: David S. Miller <davem@davemloft.net>
10 ---
11  drivers/net/ethernet/mscc/ocelot.c | 64 ++++++++++++++++++++++++++++----------
12  1 file changed, 47 insertions(+), 17 deletions(-)
13
14 --- a/drivers/net/ethernet/mscc/ocelot.c
15 +++ b/drivers/net/ethernet/mscc/ocelot.c
16 @@ -1191,10 +1191,9 @@ static const struct net_device_ops ocelo
17         .ndo_do_ioctl                   = ocelot_ioctl,
18  };
19  
20 -static void ocelot_get_strings(struct net_device *netdev, u32 sset, u8 *data)
21 +static void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset,
22 +                              u8 *data)
23  {
24 -       struct ocelot_port_private *priv = netdev_priv(netdev);
25 -       struct ocelot *ocelot = priv->port.ocelot;
26         int i;
27  
28         if (sset != ETH_SS_STATS)
29 @@ -1205,6 +1204,16 @@ static void ocelot_get_strings(struct ne
30                        ETH_GSTRING_LEN);
31  }
32  
33 +static void ocelot_port_get_strings(struct net_device *netdev, u32 sset,
34 +                                   u8 *data)
35 +{
36 +       struct ocelot_port_private *priv = netdev_priv(netdev);
37 +       struct ocelot *ocelot = priv->port.ocelot;
38 +       int port = priv->chip_port;
39 +
40 +       ocelot_get_strings(ocelot, port, sset, data);
41 +}
42 +
43  static void ocelot_update_stats(struct ocelot *ocelot)
44  {
45         int i, j;
46 @@ -1245,12 +1254,8 @@ static void ocelot_check_stats_work(stru
47                            OCELOT_STATS_CHECK_DELAY);
48  }
49  
50 -static void ocelot_get_ethtool_stats(struct net_device *dev,
51 -                                    struct ethtool_stats *stats, u64 *data)
52 +static void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data)
53  {
54 -       struct ocelot_port_private *priv = netdev_priv(dev);
55 -       struct ocelot *ocelot = priv->port.ocelot;
56 -       int port = priv->chip_port;
57         int i;
58  
59         /* check and update now */
60 @@ -1261,25 +1266,37 @@ static void ocelot_get_ethtool_stats(str
61                 *data++ = ocelot->stats[port * ocelot->num_stats + i];
62  }
63  
64 -static int ocelot_get_sset_count(struct net_device *dev, int sset)
65 +static void ocelot_port_get_ethtool_stats(struct net_device *dev,
66 +                                         struct ethtool_stats *stats,
67 +                                         u64 *data)
68  {
69         struct ocelot_port_private *priv = netdev_priv(dev);
70         struct ocelot *ocelot = priv->port.ocelot;
71 +       int port = priv->chip_port;
72  
73 +       ocelot_get_ethtool_stats(ocelot, port, data);
74 +}
75 +
76 +static int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset)
77 +{
78         if (sset != ETH_SS_STATS)
79                 return -EOPNOTSUPP;
80 +
81         return ocelot->num_stats;
82  }
83  
84 -static int ocelot_get_ts_info(struct net_device *dev,
85 -                             struct ethtool_ts_info *info)
86 +static int ocelot_port_get_sset_count(struct net_device *dev, int sset)
87  {
88         struct ocelot_port_private *priv = netdev_priv(dev);
89         struct ocelot *ocelot = priv->port.ocelot;
90 +       int port = priv->chip_port;
91  
92 -       if (!ocelot->ptp)
93 -               return ethtool_op_get_ts_info(dev, info);
94 +       return ocelot_get_sset_count(ocelot, port, sset);
95 +}
96  
97 +static int ocelot_get_ts_info(struct ocelot *ocelot, int port,
98 +                             struct ethtool_ts_info *info)
99 +{
100         info->phc_index = ocelot->ptp_clock ?
101                           ptp_clock_index(ocelot->ptp_clock) : -1;
102         info->so_timestamping |= SOF_TIMESTAMPING_TX_SOFTWARE |
103 @@ -1295,13 +1312,26 @@ static int ocelot_get_ts_info(struct net
104         return 0;
105  }
106  
107 +static int ocelot_port_get_ts_info(struct net_device *dev,
108 +                                  struct ethtool_ts_info *info)
109 +{
110 +       struct ocelot_port_private *priv = netdev_priv(dev);
111 +       struct ocelot *ocelot = priv->port.ocelot;
112 +       int port = priv->chip_port;
113 +
114 +       if (!ocelot->ptp)
115 +               return ethtool_op_get_ts_info(dev, info);
116 +
117 +       return ocelot_get_ts_info(ocelot, port, info);
118 +}
119 +
120  static const struct ethtool_ops ocelot_ethtool_ops = {
121 -       .get_strings            = ocelot_get_strings,
122 -       .get_ethtool_stats      = ocelot_get_ethtool_stats,
123 -       .get_sset_count         = ocelot_get_sset_count,
124 +       .get_strings            = ocelot_port_get_strings,
125 +       .get_ethtool_stats      = ocelot_port_get_ethtool_stats,
126 +       .get_sset_count         = ocelot_port_get_sset_count,
127         .get_link_ksettings     = phy_ethtool_get_link_ksettings,
128         .set_link_ksettings     = phy_ethtool_set_link_ksettings,
129 -       .get_ts_info            = ocelot_get_ts_info,
130 +       .get_ts_info            = ocelot_port_get_ts_info,
131  };
132  
133  static void ocelot_bridge_stp_state_set(struct ocelot *ocelot, int port,