Skip to content

Commit b8cd583

Browse files
Jianbo Liudavem330
authored andcommitted
net: flow_offload: add tc police action parameters
The current police offload action entry is missing exceed/notexceed actions and parameters that can be configured by tc police action. Add the missing parameters as a pre-step for offloading police actions to hardware. Signed-off-by: Jianbo Liu <[email protected]> Signed-off-by: Roi Dayan <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b42a738 commit b8cd583

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

include/net/flow_offload.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ enum flow_action_id {
148148
FLOW_ACTION_MPLS_MANGLE,
149149
FLOW_ACTION_GATE,
150150
FLOW_ACTION_PPPOE_PUSH,
151+
FLOW_ACTION_JUMP,
152+
FLOW_ACTION_PIPE,
151153
NUM_FLOW_ACTIONS,
152154
};
153155

@@ -235,9 +237,16 @@ struct flow_action_entry {
235237
struct { /* FLOW_ACTION_POLICE */
236238
u32 burst;
237239
u64 rate_bytes_ps;
240+
u64 peakrate_bytes_ps;
241+
u32 avrate;
242+
u16 overhead;
238243
u64 burst_pkt;
239244
u64 rate_pkt_ps;
240245
u32 mtu;
246+
struct {
247+
enum flow_action_id act_id;
248+
u32 extval;
249+
} exceed, notexceed;
241250
} police;
242251
struct { /* FLOW_ACTION_CT */
243252
int action;

include/net/tc_act/tc_police.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,34 @@ static inline u32 tcf_police_tcfp_mtu(const struct tc_action *act)
159159
return params->tcfp_mtu;
160160
}
161161

162+
static inline u64 tcf_police_peakrate_bytes_ps(const struct tc_action *act)
163+
{
164+
struct tcf_police *police = to_police(act);
165+
struct tcf_police_params *params;
166+
167+
params = rcu_dereference_protected(police->params,
168+
lockdep_is_held(&police->tcf_lock));
169+
return params->peak.rate_bytes_ps;
170+
}
171+
172+
static inline u32 tcf_police_tcfp_ewma_rate(const struct tc_action *act)
173+
{
174+
struct tcf_police *police = to_police(act);
175+
struct tcf_police_params *params;
176+
177+
params = rcu_dereference_protected(police->params,
178+
lockdep_is_held(&police->tcf_lock));
179+
return params->tcfp_ewma_rate;
180+
}
181+
182+
static inline u16 tcf_police_rate_overhead(const struct tc_action *act)
183+
{
184+
struct tcf_police *police = to_police(act);
185+
struct tcf_police_params *params;
186+
187+
params = rcu_dereference_protected(police->params,
188+
lockdep_is_held(&police->tcf_lock));
189+
return params->rate.overhead;
190+
}
191+
162192
#endif /* __NET_TC_POLICE_H */

net/sched/act_police.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,20 +419,66 @@ static int tcf_police_search(struct net *net, struct tc_action **a, u32 index)
419419
return tcf_idr_search(tn, a, index);
420420
}
421421

422+
static int tcf_police_act_to_flow_act(int tc_act, u32 *extval)
423+
{
424+
int act_id = -EOPNOTSUPP;
425+
426+
if (!TC_ACT_EXT_OPCODE(tc_act)) {
427+
if (tc_act == TC_ACT_OK)
428+
act_id = FLOW_ACTION_ACCEPT;
429+
else if (tc_act == TC_ACT_SHOT)
430+
act_id = FLOW_ACTION_DROP;
431+
else if (tc_act == TC_ACT_PIPE)
432+
act_id = FLOW_ACTION_PIPE;
433+
} else if (TC_ACT_EXT_CMP(tc_act, TC_ACT_GOTO_CHAIN)) {
434+
act_id = FLOW_ACTION_GOTO;
435+
*extval = tc_act & TC_ACT_EXT_VAL_MASK;
436+
} else if (TC_ACT_EXT_CMP(tc_act, TC_ACT_JUMP)) {
437+
act_id = FLOW_ACTION_JUMP;
438+
*extval = tc_act & TC_ACT_EXT_VAL_MASK;
439+
}
440+
441+
return act_id;
442+
}
443+
422444
static int tcf_police_offload_act_setup(struct tc_action *act, void *entry_data,
423445
u32 *index_inc, bool bind)
424446
{
425447
if (bind) {
426448
struct flow_action_entry *entry = entry_data;
449+
struct tcf_police *police = to_police(act);
450+
struct tcf_police_params *p;
451+
int act_id;
452+
453+
p = rcu_dereference_protected(police->params,
454+
lockdep_is_held(&police->tcf_lock));
427455

428456
entry->id = FLOW_ACTION_POLICE;
429457
entry->police.burst = tcf_police_burst(act);
430458
entry->police.rate_bytes_ps =
431459
tcf_police_rate_bytes_ps(act);
460+
entry->police.peakrate_bytes_ps = tcf_police_peakrate_bytes_ps(act);
461+
entry->police.avrate = tcf_police_tcfp_ewma_rate(act);
462+
entry->police.overhead = tcf_police_rate_overhead(act);
432463
entry->police.burst_pkt = tcf_police_burst_pkt(act);
433464
entry->police.rate_pkt_ps =
434465
tcf_police_rate_pkt_ps(act);
435466
entry->police.mtu = tcf_police_tcfp_mtu(act);
467+
468+
act_id = tcf_police_act_to_flow_act(police->tcf_action,
469+
&entry->police.exceed.extval);
470+
if (act_id < 0)
471+
return act_id;
472+
473+
entry->police.exceed.act_id = act_id;
474+
475+
act_id = tcf_police_act_to_flow_act(p->tcfp_result,
476+
&entry->police.notexceed.extval);
477+
if (act_id < 0)
478+
return act_id;
479+
480+
entry->police.notexceed.act_id = act_id;
481+
436482
*index_inc = 1;
437483
} else {
438484
struct flow_offload_action *fl_action = entry_data;

0 commit comments

Comments
 (0)