1 From c126f118b330ccf0db0dda4a4bd6c729865a205f Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Mon, 22 Nov 2021 16:23:45 +0100
4 Subject: net: dsa: qca8k: add additional MIB counter and make it dynamic
6 We are currently missing 2 additionals MIB counter present in QCA833x
8 QC832x switch have 39 MIB counter and QCA833X have 41 MIB counter.
9 Add the additional MIB counter and rework the MIB function to print the
10 correct supported counter from the match_data struct.
12 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
13 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
16 drivers/net/dsa/qca8k.c | 23 ++++++++++++++++++++---
17 drivers/net/dsa/qca8k.h | 4 ++++
18 2 files changed, 24 insertions(+), 3 deletions(-)
20 --- a/drivers/net/dsa/qca8k.c
21 +++ b/drivers/net/dsa/qca8k.c
22 @@ -70,6 +70,8 @@ static const struct qca8k_mib_desc ar832
23 MIB_DESC(1, 0x9c, "TxExcDefer"),
24 MIB_DESC(1, 0xa0, "TxDefer"),
25 MIB_DESC(1, 0xa4, "TxLateCol"),
26 + MIB_DESC(1, 0xa8, "RXUnicast"),
27 + MIB_DESC(1, 0xac, "TXUnicast"),
30 /* The 32bit switch registers are accessed indirectly. To achieve this we need
31 @@ -1605,12 +1607,16 @@ qca8k_phylink_mac_link_up(struct dsa_swi
33 qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data)
35 + const struct qca8k_match_data *match_data;
36 + struct qca8k_priv *priv = ds->priv;
39 if (stringset != ETH_SS_STATS)
42 - for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++)
43 + match_data = of_device_get_match_data(priv->dev);
45 + for (i = 0; i < match_data->mib_count; i++)
46 strncpy(data + i * ETH_GSTRING_LEN, ar8327_mib[i].name,
49 @@ -1620,12 +1626,15 @@ qca8k_get_ethtool_stats(struct dsa_switc
52 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
53 + const struct qca8k_match_data *match_data;
54 const struct qca8k_mib_desc *mib;
59 - for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++) {
60 + match_data = of_device_get_match_data(priv->dev);
62 + for (i = 0; i < match_data->mib_count; i++) {
64 reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
66 @@ -1648,10 +1657,15 @@ qca8k_get_ethtool_stats(struct dsa_switc
68 qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset)
70 + const struct qca8k_match_data *match_data;
71 + struct qca8k_priv *priv = ds->priv;
73 if (sset != ETH_SS_STATS)
76 - return ARRAY_SIZE(ar8327_mib);
77 + match_data = of_device_get_match_data(priv->dev);
79 + return match_data->mib_count;
83 @@ -2173,14 +2187,17 @@ static SIMPLE_DEV_PM_OPS(qca8k_pm_ops,
84 static const struct qca8k_match_data qca8327 = {
85 .id = QCA8K_ID_QCA8327,
86 .reduced_package = true,
87 + .mib_count = QCA8K_QCA832X_MIB_COUNT,
90 static const struct qca8k_match_data qca8328 = {
91 .id = QCA8K_ID_QCA8327,
92 + .mib_count = QCA8K_QCA832X_MIB_COUNT,
95 static const struct qca8k_match_data qca833x = {
96 .id = QCA8K_ID_QCA8337,
97 + .mib_count = QCA8K_QCA833X_MIB_COUNT,
100 static const struct of_device_id qca8k_of_match[] = {
101 --- a/drivers/net/dsa/qca8k.h
102 +++ b/drivers/net/dsa/qca8k.h
104 #define PHY_ID_QCA8337 0x004dd036
105 #define QCA8K_ID_QCA8337 0x13
107 +#define QCA8K_QCA832X_MIB_COUNT 39
108 +#define QCA8K_QCA833X_MIB_COUNT 41
110 #define QCA8K_BUSY_WAIT_TIMEOUT 2000
112 #define QCA8K_NUM_FDB_RECORDS 2048
113 @@ -279,6 +282,7 @@ struct ar8xxx_port_status {
114 struct qca8k_match_data {
116 bool reduced_package;