Skip to content

Commit c22ba07

Browse files
vladimirolteanPaolo Abeni
authored andcommitted
net: dsa: eliminate local type for tc policers
David Yang is saying that struct flow_action_entry in include/net/flow_offload.h has gained new fields and DSA's struct dsa_mall_policer_tc_entry, derived from that, isn't keeping up. This structure is passed to drivers and they are completely oblivious to the values of fields they don't see. This has happened before, and almost always the solution was to make the DSA layer thinner and use the upstream data structures. Here, the reason why we didn't do that is because struct flow_action_entry :: police is an anonymous structure. That is easily enough fixable, just name those fields "struct flow_action_police" and reference them from DSA. Make the according transformations to the two users (sja1105 and felix): "rate_bytes_per_sec" -> "rate_bytes_ps". Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Co-developed-by: David Yang <mmyangfl@gmail.com> Signed-off-by: David Yang <mmyangfl@gmail.com> Link: https://patch.msgid.link/20260206075427.44733-1-mmyangfl@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 86dbebf commit c22ba07

5 files changed

Lines changed: 24 additions & 29 deletions

File tree

drivers/net/dsa/ocelot/felix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,11 +2003,11 @@ static int felix_cls_flower_stats(struct dsa_switch *ds, int port,
20032003
}
20042004

20052005
static int felix_port_policer_add(struct dsa_switch *ds, int port,
2006-
struct dsa_mall_policer_tc_entry *policer)
2006+
const struct flow_action_police *policer)
20072007
{
20082008
struct ocelot *ocelot = ds->priv;
20092009
struct ocelot_policer pol = {
2010-
.rate = div_u64(policer->rate_bytes_per_sec, 1000) * 8,
2010+
.rate = div_u64(policer->rate_bytes_ps, 1000) * 8,
20112011
.burst = policer->burst,
20122012
};
20132013

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,7 @@ static void sja1105_mirror_del(struct dsa_switch *ds, int port,
28412841
}
28422842

28432843
static int sja1105_port_policer_add(struct dsa_switch *ds, int port,
2844-
struct dsa_mall_policer_tc_entry *policer)
2844+
const struct flow_action_police *policer)
28452845
{
28462846
struct sja1105_l2_policing_entry *policing;
28472847
struct sja1105_private *priv = ds->priv;
@@ -2852,7 +2852,7 @@ static int sja1105_port_policer_add(struct dsa_switch *ds, int port,
28522852
* the value of RATE bytes divided by 64, up to a maximum of SMAX
28532853
* bytes.
28542854
*/
2855-
policing[port].rate = div_u64(512 * policer->rate_bytes_per_sec,
2855+
policing[port].rate = div_u64(512 * policer->rate_bytes_ps,
28562856
1000000);
28572857
policing[port].smax = policer->burst;
28582858

include/net/dsa.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,14 @@ struct dsa_mall_mirror_tc_entry {
216216
bool ingress;
217217
};
218218

219-
/* TC port policer entry */
220-
struct dsa_mall_policer_tc_entry {
221-
u32 burst;
222-
u64 rate_bytes_per_sec;
223-
};
224-
225219
/* TC matchall entry */
226220
struct dsa_mall_tc_entry {
227221
struct list_head list;
228222
unsigned long cookie;
229223
enum dsa_port_mall_action_type type;
230224
union {
231225
struct dsa_mall_mirror_tc_entry mirror;
232-
struct dsa_mall_policer_tc_entry policer;
226+
struct flow_action_police policer;
233227
};
234228
};
235229

@@ -1110,7 +1104,7 @@ struct dsa_switch_ops {
11101104
void (*port_mirror_del)(struct dsa_switch *ds, int port,
11111105
struct dsa_mall_mirror_tc_entry *mirror);
11121106
int (*port_policer_add)(struct dsa_switch *ds, int port,
1113-
struct dsa_mall_policer_tc_entry *policer);
1107+
const struct flow_action_police *policer);
11141108
void (*port_policer_del)(struct dsa_switch *ds, int port);
11151109
int (*port_setup_tc)(struct dsa_switch *ds, int port,
11161110
enum tc_setup_type type, void *type_data);

include/net/flow_offload.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ struct flow_action_cookie *flow_action_cookie_create(void *data,
231231
gfp_t gfp);
232232
void flow_action_cookie_destroy(struct flow_action_cookie *cookie);
233233

234+
struct flow_action_police {
235+
u32 burst;
236+
u64 rate_bytes_ps;
237+
u64 peakrate_bytes_ps;
238+
u32 avrate;
239+
u16 overhead;
240+
u64 burst_pkt;
241+
u64 rate_pkt_ps;
242+
u32 mtu;
243+
struct {
244+
enum flow_action_id act_id;
245+
u32 extval;
246+
} exceed, notexceed;
247+
};
248+
234249
struct flow_action_entry {
235250
enum flow_action_id id;
236251
u32 hw_index;
@@ -275,20 +290,7 @@ struct flow_action_entry {
275290
u32 trunc_size;
276291
bool truncate;
277292
} sample;
278-
struct { /* FLOW_ACTION_POLICE */
279-
u32 burst;
280-
u64 rate_bytes_ps;
281-
u64 peakrate_bytes_ps;
282-
u32 avrate;
283-
u16 overhead;
284-
u64 burst_pkt;
285-
u64 rate_pkt_ps;
286-
u32 mtu;
287-
struct {
288-
enum flow_action_id act_id;
289-
u32 extval;
290-
} exceed, notexceed;
291-
} police;
293+
struct flow_action_police police; /* FLOW_ACTION_POLICE */
292294
struct { /* FLOW_ACTION_CT */
293295
int action;
294296
u16 zone;

net/dsa/user.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,8 @@ dsa_user_add_cls_matchall_police(struct net_device *dev,
14591459
struct netlink_ext_ack *extack = cls->common.extack;
14601460
struct dsa_port *dp = dsa_user_to_port(dev);
14611461
struct dsa_user_priv *p = netdev_priv(dev);
1462-
struct dsa_mall_policer_tc_entry *policer;
14631462
struct dsa_mall_tc_entry *mall_tc_entry;
1463+
struct flow_action_police *policer;
14641464
struct dsa_switch *ds = dp->ds;
14651465
struct flow_action_entry *act;
14661466
int err;
@@ -1497,8 +1497,7 @@ dsa_user_add_cls_matchall_police(struct net_device *dev,
14971497
mall_tc_entry->cookie = cls->cookie;
14981498
mall_tc_entry->type = DSA_PORT_MALL_POLICER;
14991499
policer = &mall_tc_entry->policer;
1500-
policer->rate_bytes_per_sec = act->police.rate_bytes_ps;
1501-
policer->burst = act->police.burst;
1500+
*policer = act->police;
15021501

15031502
err = ds->ops->port_policer_add(ds, dp->index, policer);
15041503
if (err) {

0 commit comments

Comments
 (0)