@@ -221,12 +221,11 @@ static void hellcreek_feature_detect(struct hellcreek *hellcreek)
221
221
222
222
features = hellcreek_read (hellcreek , HR_FEABITS0 );
223
223
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
+ */
225
227
hellcreek -> fdb_entries = ((features & HR_FEABITS0_FDBBINS_MASK ) >>
226
228
HR_FEABITS0_FDBBINS_SHIFT ) * 32 ;
227
-
228
- dev_info (hellcreek -> dev , "Feature detect: FDB entries=%zu\n" ,
229
- hellcreek -> fdb_entries );
230
229
}
231
230
232
231
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)
1000
999
return ret ;
1001
1000
}
1002
1001
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
+
1003
1080
static int hellcreek_setup (struct dsa_switch * ds )
1004
1081
{
1005
1082
struct hellcreek * hellcreek = ds -> priv ;
@@ -1053,9 +1130,22 @@ static int hellcreek_setup(struct dsa_switch *ds)
1053
1130
return ret ;
1054
1131
}
1055
1132
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
+
1056
1141
return 0 ;
1057
1142
}
1058
1143
1144
+ static void hellcreek_teardown (struct dsa_switch * ds )
1145
+ {
1146
+ dsa_devlink_resources_unregister (ds );
1147
+ }
1148
+
1059
1149
static void hellcreek_phylink_validate (struct dsa_switch * ds , int port ,
1060
1150
unsigned long * supported ,
1061
1151
struct phylink_link_state * state )
@@ -1447,6 +1537,7 @@ static const struct dsa_switch_ops hellcreek_ds_ops = {
1447
1537
.port_vlan_del = hellcreek_vlan_del ,
1448
1538
.port_vlan_filtering = hellcreek_vlan_filtering ,
1449
1539
.setup = hellcreek_setup ,
1540
+ .teardown = hellcreek_teardown ,
1450
1541
};
1451
1542
1452
1543
static int hellcreek_probe (struct platform_device * pdev )
0 commit comments