Skip to content

Commit f222a99

Browse files
committed
Merge branch 'net-dsa-hellcreek-report-tables-sizes'
Kurt Kanzenbach says: ==================== net: dsa: hellcreek: Report tables sizes Florian, Andrew and Vladimir suggested at some point to use devlink for reporting tables, features and debugging counters instead of using debugfs and printk. So, start by reporting the VLAN and FDB table sizes. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 14e8e0f + 8486e83 commit f222a99

File tree

2 files changed

+101
-4
lines changed

2 files changed

+101
-4
lines changed

drivers/net/dsa/hirschmann/hellcreek.c

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,11 @@ static void hellcreek_feature_detect(struct hellcreek *hellcreek)
221221

222222
features = hellcreek_read(hellcreek, HR_FEABITS0);
223223

224-
/* Currently we only detect the size of the FDB table */
224+
/* Only detect the size of the FDB table. The size and current
225+
* utilization can be queried via devlink.
226+
*/
225227
hellcreek->fdb_entries = ((features & HR_FEABITS0_FDBBINS_MASK) >>
226228
HR_FEABITS0_FDBBINS_SHIFT) * 32;
227-
228-
dev_info(hellcreek->dev, "Feature detect: FDB entries=%zu\n",
229-
hellcreek->fdb_entries);
230229
}
231230

232231
static enum dsa_tag_protocol hellcreek_get_tag_protocol(struct dsa_switch *ds,
@@ -1000,6 +999,84 @@ static int hellcreek_setup_fdb(struct hellcreek *hellcreek)
1000999
return ret;
10011000
}
10021001

1002+
static u64 hellcreek_devlink_vlan_table_get(void *priv)
1003+
{
1004+
struct hellcreek *hellcreek = priv;
1005+
u64 count = 0;
1006+
int i;
1007+
1008+
mutex_lock(&hellcreek->reg_lock);
1009+
for (i = 0; i < VLAN_N_VID; ++i)
1010+
if (hellcreek->vidmbrcfg[i])
1011+
count++;
1012+
mutex_unlock(&hellcreek->reg_lock);
1013+
1014+
return count;
1015+
}
1016+
1017+
static u64 hellcreek_devlink_fdb_table_get(void *priv)
1018+
{
1019+
struct hellcreek *hellcreek = priv;
1020+
u64 count = 0;
1021+
1022+
/* Reading this register has side effects. Synchronize against the other
1023+
* FDB operations.
1024+
*/
1025+
mutex_lock(&hellcreek->reg_lock);
1026+
count = hellcreek_read(hellcreek, HR_FDBMAX);
1027+
mutex_unlock(&hellcreek->reg_lock);
1028+
1029+
return count;
1030+
}
1031+
1032+
static int hellcreek_setup_devlink_resources(struct dsa_switch *ds)
1033+
{
1034+
struct devlink_resource_size_params size_vlan_params;
1035+
struct devlink_resource_size_params size_fdb_params;
1036+
struct hellcreek *hellcreek = ds->priv;
1037+
int err;
1038+
1039+
devlink_resource_size_params_init(&size_vlan_params, VLAN_N_VID,
1040+
VLAN_N_VID,
1041+
1, DEVLINK_RESOURCE_UNIT_ENTRY);
1042+
1043+
devlink_resource_size_params_init(&size_fdb_params,
1044+
hellcreek->fdb_entries,
1045+
hellcreek->fdb_entries,
1046+
1, DEVLINK_RESOURCE_UNIT_ENTRY);
1047+
1048+
err = dsa_devlink_resource_register(ds, "VLAN", VLAN_N_VID,
1049+
HELLCREEK_DEVLINK_PARAM_ID_VLAN_TABLE,
1050+
DEVLINK_RESOURCE_ID_PARENT_TOP,
1051+
&size_vlan_params);
1052+
if (err)
1053+
goto out;
1054+
1055+
err = dsa_devlink_resource_register(ds, "FDB", hellcreek->fdb_entries,
1056+
HELLCREEK_DEVLINK_PARAM_ID_FDB_TABLE,
1057+
DEVLINK_RESOURCE_ID_PARENT_TOP,
1058+
&size_fdb_params);
1059+
if (err)
1060+
goto out;
1061+
1062+
dsa_devlink_resource_occ_get_register(ds,
1063+
HELLCREEK_DEVLINK_PARAM_ID_VLAN_TABLE,
1064+
hellcreek_devlink_vlan_table_get,
1065+
hellcreek);
1066+
1067+
dsa_devlink_resource_occ_get_register(ds,
1068+
HELLCREEK_DEVLINK_PARAM_ID_FDB_TABLE,
1069+
hellcreek_devlink_fdb_table_get,
1070+
hellcreek);
1071+
1072+
return 0;
1073+
1074+
out:
1075+
dsa_devlink_resources_unregister(ds);
1076+
1077+
return err;
1078+
}
1079+
10031080
static int hellcreek_setup(struct dsa_switch *ds)
10041081
{
10051082
struct hellcreek *hellcreek = ds->priv;
@@ -1053,9 +1130,22 @@ static int hellcreek_setup(struct dsa_switch *ds)
10531130
return ret;
10541131
}
10551132

1133+
/* Register devlink resources with DSA */
1134+
ret = hellcreek_setup_devlink_resources(ds);
1135+
if (ret) {
1136+
dev_err(hellcreek->dev,
1137+
"Failed to setup devlink resources!\n");
1138+
return ret;
1139+
}
1140+
10561141
return 0;
10571142
}
10581143

1144+
static void hellcreek_teardown(struct dsa_switch *ds)
1145+
{
1146+
dsa_devlink_resources_unregister(ds);
1147+
}
1148+
10591149
static void hellcreek_phylink_validate(struct dsa_switch *ds, int port,
10601150
unsigned long *supported,
10611151
struct phylink_link_state *state)
@@ -1447,6 +1537,7 @@ static const struct dsa_switch_ops hellcreek_ds_ops = {
14471537
.port_vlan_del = hellcreek_vlan_del,
14481538
.port_vlan_filtering = hellcreek_vlan_filtering,
14491539
.setup = hellcreek_setup,
1540+
.teardown = hellcreek_teardown,
14501541
};
14511542

14521543
static int hellcreek_probe(struct platform_device *pdev)

drivers/net/dsa/hirschmann/hellcreek.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,10 @@ struct hellcreek {
298298
#define dw_to_hellcreek_port(dw) \
299299
container_of(dw, struct hellcreek_port, schedule_work)
300300

301+
/* Devlink resources */
302+
enum hellcreek_devlink_resource_id {
303+
HELLCREEK_DEVLINK_PARAM_ID_VLAN_TABLE,
304+
HELLCREEK_DEVLINK_PARAM_ID_FDB_TABLE,
305+
};
306+
301307
#endif /* _HELLCREEK_H_ */

0 commit comments

Comments
 (0)