[net-next PATCH v2 01/15] net: dsa: qca8k: make mib autocast feature optional

Christian Marangi
2022-07-19T01:15:48Z

Some switch may not support mib autocast feature and require the legacy
way of reading the regs directly.
Make the mib autocast feature optional and permit to declare support for
it using match_data struct.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/dsa/qca/qca8k.c | 11 +++++++----
drivers/net/dsa/qca/qca8k.h | 1 +
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/dsa/qca/qca8k.c b/drivers/net/dsa/qca/qca8k.c
index 1cbb05b0323f..a57c53ce2f0c 100644
--- a/drivers/net/dsa/qca/qca8k.c
+++ b/drivers/net/dsa/qca/qca8k.c
@@ -2112,12 +2112,12 @@ qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
u32 hi = 0;
int ret;

- if (priv->mgmt_master &&
- qca8k_get_ethtool_stats_eth(ds, port, data) > 0)
- return;
-
match_data = of_device_get_match_data(priv->dev);

+ if (priv->mgmt_master && match_data->autocast_mib &&
+ match_data->autocast_mib(ds, port, data) > 0)
+ return;
+
for (i = 0; i < match_data->mib_count; i++) {
mib = &ar8327_mib[i];
reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
@@ -3260,16 +3260,19 @@ static const struct qca8k_match_data qca8327 = {
.id = QCA8K_ID_QCA8327,
.reduced_package = true,
.mib_count = QCA8K_QCA832X_MIB_COUNT,
+ .autocast_mib = qca8k_get_ethtool_stats_eth,
};

static const struct qca8k_match_data qca8328 = {
.id = QCA8K_ID_QCA8327,
.mib_count = QCA8K_QCA832X_MIB_COUNT,
+ .autocast_mib = qca8k_get_ethtool_stats_eth,
};

static const struct qca8k_match_data qca833x = {
.id = QCA8K_ID_QCA8337,
.mib_count = QCA8K_QCA833X_MIB_COUNT,
+ .autocast_mib = qca8k_get_ethtool_stats_eth,
};

static const struct of_device_id qca8k_of_match[] = {
diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h
index ec58d0e80a70..c3df0a56cda4 100644
--- a/drivers/net/dsa/qca/qca8k.h
+++ b/drivers/net/dsa/qca/qca8k.h
@@ -328,6 +328,7 @@ struct qca8k_match_data {
u8 id;
bool reduced_package;
u8 mib_count;
+ int (*autocast_mib)(struct dsa_switch *ds, int port, u64 *data);
};

enum {
--
2.36.1