[PATCH v1 10/26] net: dsa: microchip: ksz8: refactor ksz8_fdb_dump()
From: Oleksij Rempel
Date: Mon Nov 28 2022 - 07:04:26 EST
After fixing different bugs we can refactor this function:
- be paranoid - read only max possibly amount of entries supported by
the HW.
- pass error values returned by regmap
Signed-off-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
---
drivers/net/dsa/microchip/ksz8795.c | 41 ++++++++++++++-----------
drivers/net/dsa/microchip/ksz8795_reg.h | 1 +
2 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 736cf4e54333..308b46bb2ce5 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -949,26 +949,31 @@ void ksz8_flush_dyn_mac_table(struct ksz_device *dev, int port)
int ksz8_fdb_dump(struct ksz_device *dev, int port,
dsa_fdb_dump_cb_t *cb, void *data)
{
- int ret = 0;
- u16 i = 0;
- u16 entries = 0;
- u8 src_port;
- u8 mac[ETH_ALEN];
+ u16 i, entries = 0;
+ int ret;
- do {
- ret = ksz8_r_dyn_mac_table(dev, i, mac, &src_port,
- &entries);
- if (!ret && port == src_port) {
- ret = cb(mac, 0, false, data);
- if (ret)
- break;
- }
- i++;
- } while (i < entries);
- if (i >= entries)
- ret = 0;
+ for (i = 0; i < KSZ8_DYN_MAC_ENTRIES; i++) {
+ u8 mac[ETH_ALEN];
+ u8 src_port;
- return ret;
+ ret = ksz8_r_dyn_mac_table(dev, i, mac, &src_port, &entries);
+ if (ret == -ENXIO)
+ return 0;
+ if (ret)
+ return ret;
+
+ if (i >= entries)
+ return 0;
+
+ if (port != src_port)
+ continue;
+
+ ret = cb(mac, 0, false, data);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
}
int ksz8_mdb_add(struct ksz_device *dev, int port,
diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h
index 7a57c6088f80..0bdceb534192 100644
--- a/drivers/net/dsa/microchip/ksz8795_reg.h
+++ b/drivers/net/dsa/microchip/ksz8795_reg.h
@@ -811,5 +811,6 @@
#define TAIL_TAG_LOOKUP BIT(7)
#define FID_ENTRIES 128
+#define KSZ8_DYN_MAC_ENTRIES 1024
#endif
--
2.30.2