Skip to contentSkip to conversation

net: dsa: hellcreek: Add support for dumping tables

PATCH Applied Kurt Kanzenbach 4 participants 16 messages Mar 13, 2021 – Mar 20, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover net: dsa: hellcreek: Add support for dumping tables

Hi,

add support for dumping the VLAN and FDB table via devlink. As the driver uses internal VLANs and static FDB entries, this is a useful debugging feature.

Changes since v1:

* Drop memory reporting as there are better APIs to expose this
* Move comment to VLAN patch

Previous versions:

* https://lkml.kernel.org/netdev/[email protected]/

Thanks,
Kurt

Kurt Kanzenbach (4):
net: dsa: hellcreek: Add devlink VLAN region
net: dsa: hellcreek: Use boolean value
net: dsa: hellcreek: Move common code to helper
net: dsa: hellcreek: Add devlink FDB region

 drivers/net/dsa/hirschmann/hellcreek.c | 223 ++++++++++++++++++++-----
 drivers/net/dsa/hirschmann/hellcreek.h |   7 +
 2 files changed, 187 insertions(+), 43 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/4 net: dsa: hellcreek: Add devlink VLAN region

Allow to dump the VLAN table via devlink. This especially useful, because the driver internally leverages VLANs for the port separation. These are not visible via the bridge utility.

---
 drivers/net/dsa/hirschmann/hellcreek.c | 74 ++++++++++++++++++++++++++
 drivers/net/dsa/hirschmann/hellcreek.h |  6 +++
 2 files changed, 80 insertions(+)
drivers/net/dsa/hirschmann/hellcreek.c +74 -0
index 463137c39db2..4a14760e2680 100644
@@ -1082,6 +1082,67 @@ static int hellcreek_setup_devlink_resources(struct dsa_switch *ds)
 	return err;
 }
 
+static int hellcreek_devlink_region_vlan_snapshot(struct devlink *dl,
+						  const struct devlink_region_ops *ops,
+						  struct netlink_ext_ack *extack,
+						  u8 **data)
+{
+	struct hellcreek_devlink_vlan_entry *table, *entry;
+	struct dsa_switch *ds = dsa_devlink_to_ds(dl);
+	struct hellcreek *hellcreek = ds->priv;
+	int i;
+
+	table = kcalloc(VLAN_N_VID, sizeof(*entry), GFP_KERNEL);
+	if (!table)
+		return -ENOMEM;
+
+	entry = table;
+
+	mutex_lock(&hellcreek->reg_lock);
+	for (i = 0; i < VLAN_N_VID; ++i, ++entry) {
+		entry->member = hellcreek->vidmbrcfg[i];
+		entry->vid    = i;
+	}
+	mutex_unlock(&hellcreek->reg_lock);
+
+	*data = (u8 *)table;
+
+	return 0;
+}
+
+static struct devlink_region_ops hellcreek_region_vlan_ops = {
+	.name	    = "vlan",
+	.snapshot   = hellcreek_devlink_region_vlan_snapshot,
+	.destructor = kfree,
+};
+
+static int hellcreek_setup_devlink_regions(struct dsa_switch *ds)
+{
+	struct hellcreek *hellcreek = ds->priv;
+	struct devlink_region_ops *ops;
+	struct devlink_region *region;
+	u64 size;
+
+	/* VLAN table */
+	size = VLAN_N_VID * sizeof(struct hellcreek_devlink_vlan_entry);
+	ops  = &hellcreek_region_vlan_ops;
+
+	region = dsa_devlink_region_create(ds, ops, 1, size);
+	if (IS_ERR(region))
+		return PTR_ERR(region);
+
+	hellcreek->vlan_region = region;
+
+	return 0;
+}
+
+static void hellcreek_teardown_devlink_regions(struct dsa_switch *ds)
+{
+	struct hellcreek *hellcreek = ds->priv;
+
+	dsa_devlink_region_destroy(hellcreek->vlan_region);
+}
+
 static int hellcreek_setup(struct dsa_switch *ds)
 {
 	struct hellcreek *hellcreek = ds->priv;
@@ -1143,11 +1204,24 @@ static int hellcreek_setup(struct dsa_switch *ds)
 		return ret;
 	}
 
+	ret = hellcreek_setup_devlink_regions(ds);
+	if (ret) {
+		dev_err(hellcreek->dev,
+			"Failed to setup devlink regions!\n");
+		goto err_regions;
+	}
+
 	return 0;
+
+err_regions:
+	dsa_devlink_resources_unregister(ds);
+
+	return ret;
 }
 
 static void hellcreek_teardown(struct dsa_switch *ds)
 {
+	hellcreek_teardown_devlink_regions(ds);
 	dsa_devlink_resources_unregister(ds);
 }
 
drivers/net/dsa/hirschmann/hellcreek.h +6 -0
index 305e76dab34d..42339f9359d9 100644
@@ -278,6 +278,7 @@ struct hellcreek {
 	struct mutex reg_lock;	/* Switch IP register lock */
 	struct mutex vlan_lock;	/* VLAN bitmaps lock */
 	struct mutex ptp_lock;	/* PTP IP register lock */
+	struct devlink_region *vlan_region;
 	void __iomem *base;
 	void __iomem *ptp_base;
 	u16 swcfg;		/* swcfg shadow */
@@ -304,4 +305,9 @@ enum hellcreek_devlink_resource_id {
 	HELLCREEK_DEVLINK_PARAM_ID_FDB_TABLE,
 };
 
+struct hellcreek_devlink_vlan_entry {
+	u16 vid;
+	u16 member;
+};
+
 #endif /* _HELLCREEK_H_ */
Signature · 1 line
2.30.2
Reviewed-by on v2 1/4
#3 lore raw

Re: [PATCH net-next v2 1/4] net: dsa: hellcreek: Add devlink VLAN region

In reply to Kurt Kanzenbach
Quoted 5 lines · Kurt Kanzenbach

Allow to dump the VLAN table via devlink. This especially useful, because the driver internally leverages VLANs for the port separation. These are not visible via the bridge utility.

Signature · 1 line
Florian
#4 lore raw

PATCH v2 2/4 net: dsa: hellcreek: Use boolean value

In reply to Kurt Kanzenbach

hellcreek_select_vlan() takes a boolean instead of an integer. So, use false accordingly.

---
 drivers/net/dsa/hirschmann/hellcreek.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/hirschmann/hellcreek.c +1 -1
index 4a14760e2680..edac39462a07 100644
@@ -433,7 +433,7 @@ static void hellcreek_unapply_vlan(struct hellcreek *hellcreek, int port,
 
 	mutex_lock(&hellcreek->reg_lock);
 
-	hellcreek_select_vlan(hellcreek, vid, 0);
+	hellcreek_select_vlan(hellcreek, vid, false);
 
 	/* Setup port vlan membership */
 	hellcreek_select_vlan_params(hellcreek, port, &shift, &mask);
Signature · 1 line
2.30.2
#7 lore raw

PATCH v2 3/4 net: dsa: hellcreek: Move common code to helper

In reply to Kurt Kanzenbach

There are two functions which need to populate fdb entries. Move that to a helper function.

---
 drivers/net/dsa/hirschmann/hellcreek.c | 85 +++++++++++++-------------
 1 file changed, 43 insertions(+), 42 deletions(-)
drivers/net/dsa/hirschmann/hellcreek.c +43 -42
index edac39462a07..38ff0f12e8a4 100644
@@ -670,6 +670,40 @@ static int __hellcreek_fdb_del(struct hellcreek *hellcreek,
 	return hellcreek_wait_fdb_ready(hellcreek);
 }
 
+static void hellcreek_populate_fdb_entry(struct hellcreek *hellcreek,
+					 struct hellcreek_fdb_entry *entry,
+					 size_t idx)
+{
+	unsigned char addr[ETH_ALEN];
+	u16 meta, mac;
+
+	/* Read values */
+	meta	= hellcreek_read(hellcreek, HR_FDBMDRD);
+	mac	= hellcreek_read(hellcreek, HR_FDBRDL);
+	addr[5] = mac & 0xff;
+	addr[4] = (mac & 0xff00) >> 8;
+	mac	= hellcreek_read(hellcreek, HR_FDBRDM);
+	addr[3] = mac & 0xff;
+	addr[2] = (mac & 0xff00) >> 8;
+	mac	= hellcreek_read(hellcreek, HR_FDBRDH);
+	addr[1] = mac & 0xff;
+	addr[0] = (mac & 0xff00) >> 8;
+
+	/* Populate @entry */
+	memcpy(entry->mac, addr, sizeof(addr));
+	entry->idx	    = idx;
+	entry->portmask	    = (meta & HR_FDBMDRD_PORTMASK_MASK) >>
+		HR_FDBMDRD_PORTMASK_SHIFT;
+	entry->age	    = (meta & HR_FDBMDRD_AGE_MASK) >>
+		HR_FDBMDRD_AGE_SHIFT;
+	entry->is_obt	    = !!(meta & HR_FDBMDRD_OBT);
+	entry->pass_blocked = !!(meta & HR_FDBMDRD_PASS_BLOCKED);
+	entry->is_static    = !!(meta & HR_FDBMDRD_STATIC);
+	entry->reprio_tc    = (meta & HR_FDBMDRD_REPRIO_TC_MASK) >>
+		HR_FDBMDRD_REPRIO_TC_SHIFT;
+	entry->reprio_en    = !!(meta & HR_FDBMDRD_REPRIO_EN);
+}
+
 /* Retrieve the index of a FDB entry by mac address. Currently we search through
  * the complete table in hardware. If that's too slow, we might have to cache
  * the complete FDB table in software.
@@ -691,39 +725,19 @@ static int hellcreek_fdb_get(struct hellcreek *hellcreek,
 	 * enter new entries anywhere.
 	 */
 	for (i = 0; i < hellcreek->fdb_entries; ++i) {
-		unsigned char addr[ETH_ALEN];
-		u16 meta, mac;
-
-		meta	= hellcreek_read(hellcreek, HR_FDBMDRD);
-		mac	= hellcreek_read(hellcreek, HR_FDBRDL);
-		addr[5] = mac & 0xff;
-		addr[4] = (mac & 0xff00) >> 8;
-		mac	= hellcreek_read(hellcreek, HR_FDBRDM);
-		addr[3] = mac & 0xff;
-		addr[2] = (mac & 0xff00) >> 8;
-		mac	= hellcreek_read(hellcreek, HR_FDBRDH);
-		addr[1] = mac & 0xff;
-		addr[0] = (mac & 0xff00) >> 8;
+		struct hellcreek_fdb_entry tmp = { 0 };
+
+		/* Read entry */
+		hellcreek_populate_fdb_entry(hellcreek, &tmp, i);
 
 		/* Force next entry */
 		hellcreek_write(hellcreek, 0x00, HR_FDBRDH);
 
-		if (memcmp(addr, dest, ETH_ALEN))
+		if (memcmp(tmp.mac, dest, ETH_ALEN))
 			continue;
 
 		/* Match found */
-		entry->idx	    = i;
-		entry->portmask	    = (meta & HR_FDBMDRD_PORTMASK_MASK) >>
-			HR_FDBMDRD_PORTMASK_SHIFT;
-		entry->age	    = (meta & HR_FDBMDRD_AGE_MASK) >>
-			HR_FDBMDRD_AGE_SHIFT;
-		entry->is_obt	    = !!(meta & HR_FDBMDRD_OBT);
-		entry->pass_blocked = !!(meta & HR_FDBMDRD_PASS_BLOCKED);
-		entry->is_static    = !!(meta & HR_FDBMDRD_STATIC);
-		entry->reprio_tc    = (meta & HR_FDBMDRD_REPRIO_TC_MASK) >>
-			HR_FDBMDRD_REPRIO_TC_SHIFT;
-		entry->reprio_en    = !!(meta & HR_FDBMDRD_REPRIO_EN);
-		memcpy(entry->mac, addr, sizeof(addr));
+		memcpy(entry, &tmp, sizeof(*entry));
 
 		return 0;
 	}
@@ -838,18 +852,9 @@ static int hellcreek_fdb_dump(struct dsa_switch *ds, int port,
 	for (i = 0; i < hellcreek->fdb_entries; ++i) {
 		unsigned char null_addr[ETH_ALEN] = { 0 };
 		struct hellcreek_fdb_entry entry = { 0 };
-		u16 meta, mac;
-
-		meta	= hellcreek_read(hellcreek, HR_FDBMDRD);
-		mac	= hellcreek_read(hellcreek, HR_FDBRDL);
-		entry.mac[5] = mac & 0xff;
-		entry.mac[4] = (mac & 0xff00) >> 8;
-		mac	= hellcreek_read(hellcreek, HR_FDBRDM);
-		entry.mac[3] = mac & 0xff;
-		entry.mac[2] = (mac & 0xff00) >> 8;
-		mac	= hellcreek_read(hellcreek, HR_FDBRDH);
-		entry.mac[1] = mac & 0xff;
-		entry.mac[0] = (mac & 0xff00) >> 8;
+
+		/* Read entry */
+		hellcreek_populate_fdb_entry(hellcreek, &entry, i);
 
 		/* Force next entry */
 		hellcreek_write(hellcreek, 0x00, HR_FDBRDH);
@@ -858,10 +863,6 @@ static int hellcreek_fdb_dump(struct dsa_switch *ds, int port,
 		if (!memcmp(entry.mac, null_addr, ETH_ALEN))
 			continue;
 
-		entry.portmask	= (meta & HR_FDBMDRD_PORTMASK_MASK) >>
-			HR_FDBMDRD_PORTMASK_SHIFT;
-		entry.is_static	= !!(meta & HR_FDBMDRD_STATIC);
-
 		/* Check port mask */
 		if (!(entry.portmask & BIT(port)))
 			continue;
Signature · 1 line
2.30.2
maintainer Reviewed-by on v2 3/4
#8 lore raw

Re: [PATCH net-next v2 3/4] net: dsa: hellcreek: Move common code to helper

Quoted 14 lines · Kurt Kanzenbach

There are two functions which need to populate fdb entries. Move that to a helper function.

---
 drivers/net/dsa/hirschmann/hellcreek.c | 85 +++++++++++++-------------
 1 file changed, 43 insertions(+), 42 deletions(-)
drivers/net/dsa/hirschmann/hellcreek.c +0 -0
index edac39462a07..38ff0f12e8a4 100644

drivers/net/dsa/hirschmann/hellcreek.c static int __hellcreek_fdb_del(struct hellcreek *hellcreek, · line 677

Quoted 8 lines
drivers/net/dsa/hirschmann/hellcreek.c +5 -0
@@ -670,6 +670,40 @@ static int __hellcreek_fdb_del(struct hellcreek *hellcreek,
 	return hellcreek_wait_fdb_ready(hellcreek);
 }
 
+static void hellcreek_populate_fdb_entry(struct hellcreek *hellcreek,
+					 struct hellcreek_fdb_entry *entry,
+					 size_t idx)
+{
+	unsigned char addr[ETH_ALEN];

You could have assigned:

	unsigned char *addr = entry->mac;

and avoided the memcpy, but it doesn't really matter much.

Quoted 19 lines
drivers/net/dsa/hirschmann/hellcreek.c +19 -0
+	u16 meta, mac;
+
+	/* Read values */
+	meta	= hellcreek_read(hellcreek, HR_FDBMDRD);
+	mac	= hellcreek_read(hellcreek, HR_FDBRDL);
+	addr[5] = mac & 0xff;
+	addr[4] = (mac & 0xff00) >> 8;
+	mac	= hellcreek_read(hellcreek, HR_FDBRDM);
+	addr[3] = mac & 0xff;
+	addr[2] = (mac & 0xff00) >> 8;
+	mac	= hellcreek_read(hellcreek, HR_FDBRDH);
+	addr[1] = mac & 0xff;
+	addr[0] = (mac & 0xff00) >> 8;
+
+	/* Populate @entry */
+	memcpy(entry->mac, addr, sizeof(addr));
+	entry->idx	    = idx;
+	entry->portmask	    = (meta & HR_FDBMDRD_PORTMASK_MASK) >>
+		HR_FDBMDRD_PORTMASK_SHIFT;

drivers/net/dsa/hirschmann/hellcreek.c static int __hellcreek_fdb_del(struct hellcreek *hellcreek, · line 706

Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek.c +10 -0
+	entry->age	    = (meta & HR_FDBMDRD_AGE_MASK) >>
+		HR_FDBMDRD_AGE_SHIFT;
+	entry->is_obt	    = !!(meta & HR_FDBMDRD_OBT);
+	entry->pass_blocked = !!(meta & HR_FDBMDRD_PASS_BLOCKED);
+	entry->is_static    = !!(meta & HR_FDBMDRD_STATIC);
+	entry->reprio_tc    = (meta & HR_FDBMDRD_REPRIO_TC_MASK) >>
+		HR_FDBMDRD_REPRIO_TC_SHIFT;
+	entry->reprio_en    = !!(meta & HR_FDBMDRD_REPRIO_EN);
+}
+
#10 lore raw

PATCH v2 4/4 net: dsa: hellcreek: Add devlink FDB region

In reply to Kurt Kanzenbach

Allow to dump the FDB table via devlink. This is a useful debugging feature.

---
 drivers/net/dsa/hirschmann/hellcreek.c | 62 ++++++++++++++++++++++++++
 drivers/net/dsa/hirschmann/hellcreek.h |  1 +
 2 files changed, 63 insertions(+)
drivers/net/dsa/hirschmann/hellcreek.c +62 -0
index 38ff0f12e8a4..02d8bcb37f31 100644
@@ -1111,18 +1111,62 @@ static int hellcreek_devlink_region_vlan_snapshot(struct devlink *dl,
 	return 0;
 }
 
+static int hellcreek_devlink_region_fdb_snapshot(struct devlink *dl,
+						 const struct devlink_region_ops *ops,
+						 struct netlink_ext_ack *extack,
+						 u8 **data)
+{
+	struct dsa_switch *ds = dsa_devlink_to_ds(dl);
+	struct hellcreek_fdb_entry *table, *entry;
+	struct hellcreek *hellcreek = ds->priv;
+	size_t i;
+
+	table = kcalloc(hellcreek->fdb_entries, sizeof(*entry), GFP_KERNEL);
+	if (!table)
+		return -ENOMEM;
+
+	entry = table;
+
+	mutex_lock(&hellcreek->reg_lock);
+
+	/* Start table read */
+	hellcreek_read(hellcreek, HR_FDBMAX);
+	hellcreek_write(hellcreek, 0x00, HR_FDBMAX);
+
+	for (i = 0; i < hellcreek->fdb_entries; ++i, ++entry) {
+		/* Read current entry */
+		hellcreek_populate_fdb_entry(hellcreek, entry, i);
+
+		/* Advance read pointer */
+		hellcreek_write(hellcreek, 0x00, HR_FDBRDH);
+	}
+
+	mutex_unlock(&hellcreek->reg_lock);
+
+	*data = (u8 *)table;
+
+	return 0;
+}
+
 static struct devlink_region_ops hellcreek_region_vlan_ops = {
 	.name	    = "vlan",
 	.snapshot   = hellcreek_devlink_region_vlan_snapshot,
 	.destructor = kfree,
 };
 
+static struct devlink_region_ops hellcreek_region_fdb_ops = {
+	.name	    = "fdb",
+	.snapshot   = hellcreek_devlink_region_fdb_snapshot,
+	.destructor = kfree,
+};
+
 static int hellcreek_setup_devlink_regions(struct dsa_switch *ds)
 {
 	struct hellcreek *hellcreek = ds->priv;
 	struct devlink_region_ops *ops;
 	struct devlink_region *region;
 	u64 size;
+	int ret;
 
 	/* VLAN table */
 	size = VLAN_N_VID * sizeof(struct hellcreek_devlink_vlan_entry);
@@ -1134,13 +1178,31 @@ static int hellcreek_setup_devlink_regions(struct dsa_switch *ds)
 
 	hellcreek->vlan_region = region;
 
+	/* FDB table */
+	size = hellcreek->fdb_entries * sizeof(struct hellcreek_fdb_entry);
+	ops  = &hellcreek_region_fdb_ops;
+
+	region = dsa_devlink_region_create(ds, ops, 1, size);
+	if (IS_ERR(region)) {
+		ret = PTR_ERR(region);
+		goto err_fdb;
+	}
+
+	hellcreek->fdb_region = region;
+
 	return 0;
+
+err_fdb:
+	dsa_devlink_region_destroy(hellcreek->vlan_region);
+
+	return ret;
 }
 
 static void hellcreek_teardown_devlink_regions(struct dsa_switch *ds)
 {
 	struct hellcreek *hellcreek = ds->priv;
 
+	dsa_devlink_region_destroy(hellcreek->fdb_region);
 	dsa_devlink_region_destroy(hellcreek->vlan_region);
 }
 
drivers/net/dsa/hirschmann/hellcreek.h +1 -0
index 42339f9359d9..9e303b8ab13c 100644
@@ -279,6 +279,7 @@ struct hellcreek {
 	struct mutex vlan_lock;	/* VLAN bitmaps lock */
 	struct mutex ptp_lock;	/* PTP IP register lock */
 	struct devlink_region *vlan_region;
+	struct devlink_region *fdb_region;
 	void __iomem *base;
 	void __iomem *ptp_base;
 	u16 swcfg;		/* swcfg shadow */
Signature · 1 line
2.30.2
maintainer Reviewed-by on v2 4/4
#11 lore raw

Re: [PATCH net-next v2 4/4] net: dsa: hellcreek: Add devlink FDB region

Quoted 5 lines · Kurt Kanzenbach

Allow to dump the FDB table via devlink. This is a useful debugging feature.

---

By the way, what user space program do you use to dump these? Did you derive something from Andrew's mv88e6xxx_dump too? Maybe we should work on something common?

#12 lore raw

Re: [PATCH net-next v2 4/4] net: dsa: hellcreek: Add devlink FDB region

Quoted 7 lines · Vladimir Oltean
Quoted 5 lines · Kurt Kanzenbach

Allow to dump the FDB table via devlink. This is a useful debugging feature.

---

Quoted 5 lines

By the way, what user space program do you use to dump these? Did you derive something from Andrew's mv88e6xxx_dump too? Maybe we should work on something common?

Actually there is no user space tooling, yet. My original approach to debugging was different using debugfs and tracing. I played a bit with mv88e6xxx_dump today. Having a common tool would be quite nice.

Thanks,
Kurt

#13 lore raw

Re: [PATCH net-next v2 4/4] net: dsa: hellcreek: Add devlink FDB region

Quoted 10 lines · Kurt Kanzenbach
Quoted 9 lines · Vladimir Oltean
Quoted 5 lines · Kurt Kanzenbach

Allow to dump the FDB table via devlink. This is a useful debugging feature.

---

Quoted 7 lines
Quoted 3 lines

By the way, what user space program do you use to dump these? Did you derive something from Andrew's mv88e6xxx_dump too? Maybe we should work on something common?

Actually there is no user space tooling, yet. My original approach to debugging was different using debugfs and tracing. I played a bit with mv88e6xxx_dump today. Having a common tool would be quite nice.

Thanks for the pointer to mv88e6xxx_dump. Just needed to implement .devlink_info_get() callback, so that the tool can distinguish between the Marvell and Hellcreek devices (and implement some hellcreek specifics).

Thanks,
Kurt

#15 lore raw
In reply to Kurt Kanzenbach
This series was applied to netdev/net-next.git (refs/heads/master):

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Sat, 13 Mar 2021 10:39:35 +0100 you wrote:

Hi,

add support for dumping the VLAN and FDB table via devlink. As the driver uses internal VLANs and static FDB entries, this is a useful debugging feature.

Changes since v1:

[...]

Here is the summary with links:
- [net-next,v2,1/4] net: dsa: hellcreek: Add devlink VLAN region

    https://git.kernel.org/netdev/net-next/c/ba2d1c28886c
  - [net-next,v2,2/4] net: dsa: hellcreek: Use boolean value
    https://git.kernel.org/netdev/net-next/c/e81813fb5635
  - [net-next,v2,3/4] net: dsa: hellcreek: Move common code to helper
    https://git.kernel.org/netdev/net-next/c/eb5f3d314180
  - [net-next,v2,4/4] net: dsa: hellcreek: Add devlink FDB region
    https://git.kernel.org/netdev/net-next/c/292cd449fee3

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html