c790ba1bd50680fb0fe40d8b2f06260f024805c3
[openwrt/staging/jow.git] /
1 From ce44b6ed9ee65efa9b3025552c513842eabcab88 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Tue, 29 Nov 2022 16:12:16 +0200
4 Subject: [PATCH 09/14] net: dpaa2: publish MAC stringset to ethtool -S even if
5 MAC is missing
6
7 DPNIs and DPSW objects can connect and disconnect at runtime from DPMAC
8 objects on the same fsl-mc bus. The DPMAC object also holds "ethtool -S"
9 unstructured counters. Those counters are only shown for the entity
10 owning the netdev (DPNI, DPSW) if it's connected to a DPMAC.
11
12 The ethtool stringset code path is split into multiple callbacks, but
13 currently, connecting and disconnecting the DPMAC takes the rtnl_lock().
14 This blocks the entire ethtool code path from running, see
15 ethnl_default_doit() -> rtnl_lock() -> ops->prepare_data() ->
16 strset_prepare_data().
17
18 This is going to be a problem if we are going to no longer require
19 rtnl_lock() when connecting/disconnecting the DPMAC, because the DPMAC
20 could appear between ops->get_sset_count() and ops->get_strings().
21 If it appears out of the blue, we will provide a stringset into an array
22 that was dimensioned thinking the DPMAC wouldn't be there => array
23 accessed out of bounds.
24
25 There isn't really a good way to work around that, and I don't want to
26 put too much pressure on the ethtool framework by playing locking games.
27 Just make the DPMAC counters be always available. They'll be zeroes if
28 the DPNI or DPSW isn't connected to a DPMAC.
29
30 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
31 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
32 Reviewed-by: Ioana Ciornei <ioana.ciornei@nxp.com>
33 Tested-by: Ioana Ciornei <ioana.ciornei@nxp.com>
34 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
35 ---
36 drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c | 12 +++---------
37 .../ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c | 11 ++---------
38 2 files changed, 5 insertions(+), 18 deletions(-)
39
40 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c
41 +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-ethtool.c
42 @@ -186,7 +186,6 @@ static int dpaa2_eth_set_pauseparam(stru
43 static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset,
44 u8 *data)
45 {
46 - struct dpaa2_eth_priv *priv = netdev_priv(netdev);
47 u8 *p = data;
48 int i;
49
50 @@ -200,22 +199,17 @@ static void dpaa2_eth_get_strings(struct
51 strscpy(p, dpaa2_ethtool_extras[i], ETH_GSTRING_LEN);
52 p += ETH_GSTRING_LEN;
53 }
54 - if (dpaa2_eth_has_mac(priv))
55 - dpaa2_mac_get_strings(p);
56 + dpaa2_mac_get_strings(p);
57 break;
58 }
59 }
60
61 static int dpaa2_eth_get_sset_count(struct net_device *net_dev, int sset)
62 {
63 - int num_ss_stats = DPAA2_ETH_NUM_STATS + DPAA2_ETH_NUM_EXTRA_STATS;
64 - struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
65 -
66 switch (sset) {
67 case ETH_SS_STATS: /* ethtool_get_stats(), ethtool_get_drvinfo() */
68 - if (dpaa2_eth_has_mac(priv))
69 - num_ss_stats += dpaa2_mac_get_sset_count();
70 - return num_ss_stats;
71 + return DPAA2_ETH_NUM_STATS + DPAA2_ETH_NUM_EXTRA_STATS +
72 + dpaa2_mac_get_sset_count();
73 default:
74 return -EOPNOTSUPP;
75 }
76 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c
77 +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch-ethtool.c
78 @@ -145,14 +145,9 @@ dpaa2_switch_set_link_ksettings(struct n
79 static int
80 dpaa2_switch_ethtool_get_sset_count(struct net_device *netdev, int sset)
81 {
82 - struct ethsw_port_priv *port_priv = netdev_priv(netdev);
83 - int num_ss_stats = DPAA2_SWITCH_NUM_COUNTERS;
84 -
85 switch (sset) {
86 case ETH_SS_STATS:
87 - if (port_priv->mac)
88 - num_ss_stats += dpaa2_mac_get_sset_count();
89 - return num_ss_stats;
90 + return DPAA2_SWITCH_NUM_COUNTERS + dpaa2_mac_get_sset_count();
91 default:
92 return -EOPNOTSUPP;
93 }
94 @@ -161,7 +156,6 @@ dpaa2_switch_ethtool_get_sset_count(stru
95 static void dpaa2_switch_ethtool_get_strings(struct net_device *netdev,
96 u32 stringset, u8 *data)
97 {
98 - struct ethsw_port_priv *port_priv = netdev_priv(netdev);
99 u8 *p = data;
100 int i;
101
102 @@ -172,8 +166,7 @@ static void dpaa2_switch_ethtool_get_str
103 ETH_GSTRING_LEN);
104 p += ETH_GSTRING_LEN;
105 }
106 - if (port_priv->mac)
107 - dpaa2_mac_get_strings(p);
108 + dpaa2_mac_get_strings(p);
109 break;
110 }
111 }