diff mbox series

[net-next,1/6] net: dsa: hellcreek: Report RAM usage

Message ID 20210311175344.3084-2-kurt@kmk-computers.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: hellcreek: Add support for dumping tables | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 1 maintainers not CCed: kurt@linutronix.de
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 83 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Kurt Kanzenbach March 11, 2021, 5:53 p.m. UTC
Report the RAM usage via devlink. This is a useful debug feature. The actual
size depends on the used Hellcreek version:

|root@tsn:~# devlink resource show platform/ff240000.switch
|platform/ff240000.switch:
|  name VLAN size 4096 occ 3 unit entry dpipe_tables none
|  name FDB size 256 occ 6 unit entry dpipe_tables none
|  name RAM size 320 occ 14 unit entry dpipe_tables none

Signed-off-by: Kurt Kanzenbach <kurt@kmk-computers.de>
---
 drivers/net/dsa/hirschmann/hellcreek.c | 38 ++++++++++++++++++++++++--
 drivers/net/dsa/hirschmann/hellcreek.h |  2 ++
 2 files changed, 37 insertions(+), 3 deletions(-)

Comments

Jakub Kicinski March 11, 2021, 8:35 p.m. UTC | #1
On Thu, 11 Mar 2021 18:53:39 +0100 Kurt Kanzenbach wrote:
> Report the RAM usage via devlink. This is a useful debug feature. The actual
> size depends on the used Hellcreek version:
> 
> |root@tsn:~# devlink resource show platform/ff240000.switch
> |platform/ff240000.switch:
> |  name VLAN size 4096 occ 3 unit entry dpipe_tables none
> |  name FDB size 256 occ 6 unit entry dpipe_tables none
> |  name RAM size 320 occ 14 unit entry dpipe_tables none

What is stored in this RAM?
diff mbox series

Patch

diff --git a/drivers/net/dsa/hirschmann/hellcreek.c b/drivers/net/dsa/hirschmann/hellcreek.c
index 463137c39db2..c7a439336336 100644
--- a/drivers/net/dsa/hirschmann/hellcreek.c
+++ b/drivers/net/dsa/hirschmann/hellcreek.c
@@ -221,11 +221,13 @@  static void hellcreek_feature_detect(struct hellcreek *hellcreek)
 
 	features = hellcreek_read(hellcreek, HR_FEABITS0);
 
-	/* Only detect the size of the FDB table. The size and current
-	 * utilization can be queried via devlink.
+	/* Detect the FDB table size and the maximum RAM page count. The size
+	 * and current utilization can be queried via devlink.
 	 */
 	hellcreek->fdb_entries = ((features & HR_FEABITS0_FDBBINS_MASK) >>
-			       HR_FEABITS0_FDBBINS_SHIFT) * 32;
+				  HR_FEABITS0_FDBBINS_SHIFT) * 32;
+	hellcreek->page_count  = ((features & HR_FEABITS0_PCNT_MASK) >>
+				  HR_FEABITS0_PCNT_SHIFT) * 32;
 }
 
 static enum dsa_tag_protocol hellcreek_get_tag_protocol(struct dsa_switch *ds,
@@ -1034,10 +1036,23 @@  static u64 hellcreek_devlink_fdb_table_get(void *priv)
 	return count;
 }
 
+static u64 hellcreek_devlink_ram_usage_get(void *priv)
+{
+	struct hellcreek *hellcreek = priv;
+	u64 usage = 0;
+
+	/* Indicates how many free ram pages are available. */
+	usage = hellcreek_read(hellcreek, HR_PFREE);
+	usage = hellcreek->page_count - usage;
+
+	return usage;
+}
+
 static int hellcreek_setup_devlink_resources(struct dsa_switch *ds)
 {
 	struct devlink_resource_size_params size_vlan_params;
 	struct devlink_resource_size_params size_fdb_params;
+	struct devlink_resource_size_params size_ram_params;
 	struct hellcreek *hellcreek = ds->priv;
 	int err;
 
@@ -1050,6 +1065,11 @@  static int hellcreek_setup_devlink_resources(struct dsa_switch *ds)
 					  hellcreek->fdb_entries,
 					  1, DEVLINK_RESOURCE_UNIT_ENTRY);
 
+	devlink_resource_size_params_init(&size_ram_params,
+					  hellcreek->page_count,
+					  hellcreek->page_count,
+					  1, DEVLINK_RESOURCE_UNIT_ENTRY);
+
 	err = dsa_devlink_resource_register(ds, "VLAN", VLAN_N_VID,
 					    HELLCREEK_DEVLINK_PARAM_ID_VLAN_TABLE,
 					    DEVLINK_RESOURCE_ID_PARENT_TOP,
@@ -1064,6 +1084,13 @@  static int hellcreek_setup_devlink_resources(struct dsa_switch *ds)
 	if (err)
 		goto out;
 
+	err = dsa_devlink_resource_register(ds, "RAM", hellcreek->page_count,
+					    HELLCREEK_DEVLINK_PARAM_ID_RAM_USAGE,
+					    DEVLINK_RESOURCE_ID_PARENT_TOP,
+					    &size_ram_params);
+	if (err)
+		goto out;
+
 	dsa_devlink_resource_occ_get_register(ds,
 					      HELLCREEK_DEVLINK_PARAM_ID_VLAN_TABLE,
 					      hellcreek_devlink_vlan_table_get,
@@ -1074,6 +1101,11 @@  static int hellcreek_setup_devlink_resources(struct dsa_switch *ds)
 					      hellcreek_devlink_fdb_table_get,
 					      hellcreek);
 
+	dsa_devlink_resource_occ_get_register(ds,
+					      HELLCREEK_DEVLINK_PARAM_ID_RAM_USAGE,
+					      hellcreek_devlink_ram_usage_get,
+					      hellcreek);
+
 	return 0;
 
 out:
diff --git a/drivers/net/dsa/hirschmann/hellcreek.h b/drivers/net/dsa/hirschmann/hellcreek.h
index 305e76dab34d..9c08aeabbc24 100644
--- a/drivers/net/dsa/hirschmann/hellcreek.h
+++ b/drivers/net/dsa/hirschmann/hellcreek.h
@@ -286,6 +286,7 @@  struct hellcreek {
 	u64 last_ts;		/* Used for overflow detection */
 	u16 status_out;		/* ptp.status_out shadow */
 	size_t fdb_entries;
+	size_t page_count;
 };
 
 /* A Qbv schedule can only started up to 8 seconds in the future. If the delta
@@ -302,6 +303,7 @@  struct hellcreek {
 enum hellcreek_devlink_resource_id {
 	HELLCREEK_DEVLINK_PARAM_ID_VLAN_TABLE,
 	HELLCREEK_DEVLINK_PARAM_ID_FDB_TABLE,
+	HELLCREEK_DEVLINK_PARAM_ID_RAM_USAGE,
 };
 
 #endif /* _HELLCREEK_H_ */