Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mscc: ocelot: establish functions for handling VCAP aux resources

Some VCAP filters utilize resources which are global to the switch, like
for example VCAP IS2 policers take an index into a global policer pool.

In commit c9a7fe1238e5 ("net: mscc: ocelot: add action of police on
vcap_is2"), Xiaoliang expressed this by hooking into the low-level
ocelot_vcap_filter_add_to_block() and ocelot_vcap_block_remove_filter()
functions, and allocating/freeing the policers from there.

Evaluating the code, there probably isn't a better place, but we'll need
to do something similar for the mirror ports, and the code will start to
look even more hacked up than it is right now.

Create two ocelot_vcap_filter_{add,del}_aux_resources() functions to
contain the madness, and pollute less the body of other functions such
as ocelot_vcap_filter_add_to_block().

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
c3d427ea ccb6ed42

+30 -11
+30 -11
drivers/net/ethernet/mscc/ocelot_vcap.c
··· 955 955 } 956 956 EXPORT_SYMBOL(ocelot_vcap_policer_del); 957 957 958 - static int ocelot_vcap_filter_add_to_block(struct ocelot *ocelot, 959 - struct ocelot_vcap_block *block, 960 - struct ocelot_vcap_filter *filter) 958 + static int 959 + ocelot_vcap_filter_add_aux_resources(struct ocelot *ocelot, 960 + struct ocelot_vcap_filter *filter, 961 + struct netlink_ext_ack *extack) 961 962 { 962 - struct ocelot_vcap_filter *tmp; 963 - struct list_head *pos, *n; 964 963 int ret; 965 964 966 965 if (filter->block_id == VCAP_IS2 && filter->action.police_ena) { ··· 968 969 if (ret) 969 970 return ret; 970 971 } 972 + 973 + return 0; 974 + } 975 + 976 + static void 977 + ocelot_vcap_filter_del_aux_resources(struct ocelot *ocelot, 978 + struct ocelot_vcap_filter *filter) 979 + { 980 + if (filter->block_id == VCAP_IS2 && filter->action.police_ena) 981 + ocelot_vcap_policer_del(ocelot, filter->action.pol_ix); 982 + } 983 + 984 + static int ocelot_vcap_filter_add_to_block(struct ocelot *ocelot, 985 + struct ocelot_vcap_block *block, 986 + struct ocelot_vcap_filter *filter, 987 + struct netlink_ext_ack *extack) 988 + { 989 + struct ocelot_vcap_filter *tmp; 990 + struct list_head *pos, *n; 991 + int ret; 992 + 993 + ret = ocelot_vcap_filter_add_aux_resources(ocelot, filter, extack); 994 + if (ret) 995 + return ret; 971 996 972 997 block->count++; 973 998 ··· 1191 1168 } 1192 1169 1193 1170 /* Add filter to the linked list */ 1194 - ret = ocelot_vcap_filter_add_to_block(ocelot, block, filter); 1171 + ret = ocelot_vcap_filter_add_to_block(ocelot, block, filter, extack); 1195 1172 if (ret) 1196 1173 return ret; 1197 1174 ··· 1222 1199 1223 1200 list_for_each_entry_safe(tmp, n, &block->rules, list) { 1224 1201 if (ocelot_vcap_filter_equal(filter, tmp)) { 1225 - if (tmp->block_id == VCAP_IS2 && 1226 - tmp->action.police_ena) 1227 - ocelot_vcap_policer_del(ocelot, 1228 - tmp->action.pol_ix); 1229 - 1202 + ocelot_vcap_filter_del_aux_resources(ocelot, tmp); 1230 1203 list_del(&tmp->list); 1231 1204 kfree(tmp); 1232 1205 }