]>
Commit | Line | Data |
---|---|---|
8f256622 PNA |
1 | #ifndef _NET_FLOW_OFFLOAD_H |
2 | #define _NET_FLOW_OFFLOAD_H | |
3 | ||
fa85999f | 4 | #include <linux/kernel.h> |
a7323311 | 5 | #include <linux/list.h> |
319a1d19 | 6 | #include <linux/netlink.h> |
8f256622 PNA |
7 | #include <net/flow_dissector.h> |
8 | ||
9 | struct flow_match { | |
10 | struct flow_dissector *dissector; | |
11 | void *mask; | |
12 | void *key; | |
13 | }; | |
14 | ||
9558a83a JP |
15 | struct flow_match_meta { |
16 | struct flow_dissector_key_meta *key, *mask; | |
17 | }; | |
18 | ||
8f256622 PNA |
19 | struct flow_match_basic { |
20 | struct flow_dissector_key_basic *key, *mask; | |
21 | }; | |
22 | ||
23 | struct flow_match_control { | |
24 | struct flow_dissector_key_control *key, *mask; | |
25 | }; | |
26 | ||
27 | struct flow_match_eth_addrs { | |
28 | struct flow_dissector_key_eth_addrs *key, *mask; | |
29 | }; | |
30 | ||
31 | struct flow_match_vlan { | |
32 | struct flow_dissector_key_vlan *key, *mask; | |
33 | }; | |
34 | ||
35 | struct flow_match_ipv4_addrs { | |
36 | struct flow_dissector_key_ipv4_addrs *key, *mask; | |
37 | }; | |
38 | ||
39 | struct flow_match_ipv6_addrs { | |
40 | struct flow_dissector_key_ipv6_addrs *key, *mask; | |
41 | }; | |
42 | ||
43 | struct flow_match_ip { | |
44 | struct flow_dissector_key_ip *key, *mask; | |
45 | }; | |
46 | ||
47 | struct flow_match_ports { | |
48 | struct flow_dissector_key_ports *key, *mask; | |
49 | }; | |
50 | ||
51 | struct flow_match_icmp { | |
52 | struct flow_dissector_key_icmp *key, *mask; | |
53 | }; | |
54 | ||
55 | struct flow_match_tcp { | |
56 | struct flow_dissector_key_tcp *key, *mask; | |
57 | }; | |
58 | ||
59 | struct flow_match_mpls { | |
60 | struct flow_dissector_key_mpls *key, *mask; | |
61 | }; | |
62 | ||
63 | struct flow_match_enc_keyid { | |
64 | struct flow_dissector_key_keyid *key, *mask; | |
65 | }; | |
66 | ||
67 | struct flow_match_enc_opts { | |
68 | struct flow_dissector_key_enc_opts *key, *mask; | |
69 | }; | |
70 | ||
ee1c45e8 PB |
71 | struct flow_match_ct { |
72 | struct flow_dissector_key_ct *key, *mask; | |
73 | }; | |
74 | ||
8f256622 PNA |
75 | struct flow_rule; |
76 | ||
9558a83a JP |
77 | void flow_rule_match_meta(const struct flow_rule *rule, |
78 | struct flow_match_meta *out); | |
8f256622 PNA |
79 | void flow_rule_match_basic(const struct flow_rule *rule, |
80 | struct flow_match_basic *out); | |
81 | void flow_rule_match_control(const struct flow_rule *rule, | |
82 | struct flow_match_control *out); | |
83 | void flow_rule_match_eth_addrs(const struct flow_rule *rule, | |
84 | struct flow_match_eth_addrs *out); | |
85 | void flow_rule_match_vlan(const struct flow_rule *rule, | |
86 | struct flow_match_vlan *out); | |
bae9ed69 EC |
87 | void flow_rule_match_cvlan(const struct flow_rule *rule, |
88 | struct flow_match_vlan *out); | |
8f256622 PNA |
89 | void flow_rule_match_ipv4_addrs(const struct flow_rule *rule, |
90 | struct flow_match_ipv4_addrs *out); | |
91 | void flow_rule_match_ipv6_addrs(const struct flow_rule *rule, | |
92 | struct flow_match_ipv6_addrs *out); | |
93 | void flow_rule_match_ip(const struct flow_rule *rule, | |
94 | struct flow_match_ip *out); | |
95 | void flow_rule_match_ports(const struct flow_rule *rule, | |
96 | struct flow_match_ports *out); | |
97 | void flow_rule_match_tcp(const struct flow_rule *rule, | |
98 | struct flow_match_tcp *out); | |
99 | void flow_rule_match_icmp(const struct flow_rule *rule, | |
100 | struct flow_match_icmp *out); | |
101 | void flow_rule_match_mpls(const struct flow_rule *rule, | |
102 | struct flow_match_mpls *out); | |
103 | void flow_rule_match_enc_control(const struct flow_rule *rule, | |
104 | struct flow_match_control *out); | |
105 | void flow_rule_match_enc_ipv4_addrs(const struct flow_rule *rule, | |
106 | struct flow_match_ipv4_addrs *out); | |
107 | void flow_rule_match_enc_ipv6_addrs(const struct flow_rule *rule, | |
108 | struct flow_match_ipv6_addrs *out); | |
109 | void flow_rule_match_enc_ip(const struct flow_rule *rule, | |
110 | struct flow_match_ip *out); | |
111 | void flow_rule_match_enc_ports(const struct flow_rule *rule, | |
112 | struct flow_match_ports *out); | |
113 | void flow_rule_match_enc_keyid(const struct flow_rule *rule, | |
114 | struct flow_match_enc_keyid *out); | |
115 | void flow_rule_match_enc_opts(const struct flow_rule *rule, | |
116 | struct flow_match_enc_opts *out); | |
ee1c45e8 PB |
117 | void flow_rule_match_ct(const struct flow_rule *rule, |
118 | struct flow_match_ct *out); | |
8f256622 | 119 | |
e3ab786b PNA |
120 | enum flow_action_id { |
121 | FLOW_ACTION_ACCEPT = 0, | |
122 | FLOW_ACTION_DROP, | |
123 | FLOW_ACTION_TRAP, | |
124 | FLOW_ACTION_GOTO, | |
125 | FLOW_ACTION_REDIRECT, | |
126 | FLOW_ACTION_MIRRED, | |
48e584ac JH |
127 | FLOW_ACTION_REDIRECT_INGRESS, |
128 | FLOW_ACTION_MIRRED_INGRESS, | |
e3ab786b PNA |
129 | FLOW_ACTION_VLAN_PUSH, |
130 | FLOW_ACTION_VLAN_POP, | |
131 | FLOW_ACTION_VLAN_MANGLE, | |
132 | FLOW_ACTION_TUNNEL_ENCAP, | |
133 | FLOW_ACTION_TUNNEL_DECAP, | |
134 | FLOW_ACTION_MANGLE, | |
135 | FLOW_ACTION_ADD, | |
136 | FLOW_ACTION_CSUM, | |
137 | FLOW_ACTION_MARK, | |
fb1b775a | 138 | FLOW_ACTION_PTYPE, |
2ce12410 | 139 | FLOW_ACTION_PRIORITY, |
8bec2833 PNA |
140 | FLOW_ACTION_WAKE, |
141 | FLOW_ACTION_QUEUE, | |
a7a7be60 | 142 | FLOW_ACTION_SAMPLE, |
8c8cfc6e | 143 | FLOW_ACTION_POLICE, |
b57dc7c1 | 144 | FLOW_ACTION_CT, |
9c26ba9b | 145 | FLOW_ACTION_CT_METADATA, |
6749d590 JH |
146 | FLOW_ACTION_MPLS_PUSH, |
147 | FLOW_ACTION_MPLS_POP, | |
148 | FLOW_ACTION_MPLS_MANGLE, | |
d29bdd69 | 149 | FLOW_ACTION_GATE, |
7a978759 | 150 | NUM_FLOW_ACTIONS, |
e3ab786b PNA |
151 | }; |
152 | ||
153 | /* This is mirroring enum pedit_header_type definition for easy mapping between | |
154 | * tc pedit action. Legacy TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK is mapped to | |
155 | * FLOW_ACT_MANGLE_UNSPEC, which is supported by no driver. | |
156 | */ | |
157 | enum flow_action_mangle_base { | |
158 | FLOW_ACT_MANGLE_UNSPEC = 0, | |
159 | FLOW_ACT_MANGLE_HDR_TYPE_ETH, | |
160 | FLOW_ACT_MANGLE_HDR_TYPE_IP4, | |
161 | FLOW_ACT_MANGLE_HDR_TYPE_IP6, | |
162 | FLOW_ACT_MANGLE_HDR_TYPE_TCP, | |
163 | FLOW_ACT_MANGLE_HDR_TYPE_UDP, | |
164 | }; | |
165 | ||
0dfb2d82 | 166 | enum flow_action_hw_stats_bit { |
53eca1f3 JK |
167 | FLOW_ACTION_HW_STATS_IMMEDIATE_BIT, |
168 | FLOW_ACTION_HW_STATS_DELAYED_BIT, | |
16f80360 | 169 | FLOW_ACTION_HW_STATS_DISABLED_BIT, |
060b6381 EC |
170 | |
171 | FLOW_ACTION_HW_STATS_NUM_BITS | |
42d5fe5f JP |
172 | }; |
173 | ||
0dfb2d82 | 174 | enum flow_action_hw_stats { |
53eca1f3 JK |
175 | FLOW_ACTION_HW_STATS_IMMEDIATE = |
176 | BIT(FLOW_ACTION_HW_STATS_IMMEDIATE_BIT), | |
177 | FLOW_ACTION_HW_STATS_DELAYED = BIT(FLOW_ACTION_HW_STATS_DELAYED_BIT), | |
178 | FLOW_ACTION_HW_STATS_ANY = FLOW_ACTION_HW_STATS_IMMEDIATE | | |
179 | FLOW_ACTION_HW_STATS_DELAYED, | |
16f80360 PNA |
180 | FLOW_ACTION_HW_STATS_DISABLED = |
181 | BIT(FLOW_ACTION_HW_STATS_DISABLED_BIT), | |
060b6381 | 182 | FLOW_ACTION_HW_STATS_DONT_CARE = BIT(FLOW_ACTION_HW_STATS_NUM_BITS) - 1, |
42d5fe5f | 183 | }; |
2514921e | 184 | |
1158958a VB |
185 | typedef void (*action_destr)(void *priv); |
186 | ||
2008495d JP |
187 | struct flow_action_cookie { |
188 | u32 cookie_len; | |
189 | u8 cookie[]; | |
190 | }; | |
191 | ||
192 | struct flow_action_cookie *flow_action_cookie_create(void *data, | |
193 | unsigned int len, | |
194 | gfp_t gfp); | |
195 | void flow_action_cookie_destroy(struct flow_action_cookie *cookie); | |
196 | ||
e3ab786b PNA |
197 | struct flow_action_entry { |
198 | enum flow_action_id id; | |
0dfb2d82 | 199 | enum flow_action_hw_stats hw_stats; |
1158958a VB |
200 | action_destr destructor; |
201 | void *destructor_priv; | |
e3ab786b PNA |
202 | union { |
203 | u32 chain_index; /* FLOW_ACTION_GOTO */ | |
204 | struct net_device *dev; /* FLOW_ACTION_REDIRECT */ | |
205 | struct { /* FLOW_ACTION_VLAN */ | |
206 | u16 vid; | |
207 | __be16 proto; | |
208 | u8 prio; | |
209 | } vlan; | |
1f40be6a PM |
210 | struct { /* FLOW_ACTION_MANGLE */ |
211 | /* FLOW_ACTION_ADD */ | |
e3ab786b PNA |
212 | enum flow_action_mangle_base htype; |
213 | u32 offset; | |
214 | u32 mask; | |
215 | u32 val; | |
216 | } mangle; | |
1158958a | 217 | struct ip_tunnel_info *tunnel; /* FLOW_ACTION_TUNNEL_ENCAP */ |
e3ab786b PNA |
218 | u32 csum_flags; /* FLOW_ACTION_CSUM */ |
219 | u32 mark; /* FLOW_ACTION_MARK */ | |
fb1b775a | 220 | u16 ptype; /* FLOW_ACTION_PTYPE */ |
2ce12410 | 221 | u32 priority; /* FLOW_ACTION_PRIORITY */ |
8bec2833 PNA |
222 | struct { /* FLOW_ACTION_QUEUE */ |
223 | u32 ctx; | |
224 | u32 index; | |
225 | u8 vf; | |
226 | } queue; | |
a7a7be60 PJV |
227 | struct { /* FLOW_ACTION_SAMPLE */ |
228 | struct psample_group *psample_group; | |
229 | u32 rate; | |
230 | u32 trunc_size; | |
231 | bool truncate; | |
232 | } sample; | |
8c8cfc6e | 233 | struct { /* FLOW_ACTION_POLICE */ |
627e39b1 | 234 | u32 index; |
5f035af7 | 235 | u32 burst; |
8c8cfc6e | 236 | u64 rate_bytes_ps; |
19e528dc | 237 | u32 mtu; |
8c8cfc6e | 238 | } police; |
b57dc7c1 PB |
239 | struct { /* FLOW_ACTION_CT */ |
240 | int action; | |
241 | u16 zone; | |
edd5861e | 242 | struct nf_flowtable *flow_table; |
b57dc7c1 | 243 | } ct; |
9c26ba9b | 244 | struct { |
30b0cf90 | 245 | unsigned long cookie; |
9c26ba9b PB |
246 | u32 mark; |
247 | u32 labels[4]; | |
248 | } ct_metadata; | |
6749d590 JH |
249 | struct { /* FLOW_ACTION_MPLS_PUSH */ |
250 | u32 label; | |
251 | __be16 proto; | |
252 | u8 tc; | |
253 | u8 bos; | |
254 | u8 ttl; | |
255 | } mpls_push; | |
256 | struct { /* FLOW_ACTION_MPLS_POP */ | |
257 | __be16 proto; | |
258 | } mpls_pop; | |
259 | struct { /* FLOW_ACTION_MPLS_MANGLE */ | |
260 | u32 label; | |
261 | u8 tc; | |
262 | u8 bos; | |
263 | u8 ttl; | |
264 | } mpls_mangle; | |
d29bdd69 PL |
265 | struct { |
266 | u32 index; | |
267 | s32 prio; | |
268 | u64 basetime; | |
269 | u64 cycletime; | |
270 | u64 cycletimeext; | |
271 | u32 num_entries; | |
272 | struct action_gate_entry *entries; | |
273 | } gate; | |
e3ab786b | 274 | }; |
2008495d | 275 | struct flow_action_cookie *cookie; /* user defined action cookie */ |
e3ab786b PNA |
276 | }; |
277 | ||
278 | struct flow_action { | |
279 | unsigned int num_entries; | |
8661b6e7 | 280 | struct flow_action_entry entries[]; |
e3ab786b PNA |
281 | }; |
282 | ||
283 | static inline bool flow_action_has_entries(const struct flow_action *action) | |
284 | { | |
285 | return action->num_entries; | |
286 | } | |
287 | ||
ab79af32 PJV |
288 | /** |
289 | * flow_action_has_one_action() - check if exactly one action is present | |
290 | * @action: tc filter flow offload action | |
291 | * | |
292 | * Returns true if exactly one action is present. | |
293 | */ | |
294 | static inline bool flow_offload_has_one_action(const struct flow_action *action) | |
295 | { | |
296 | return action->num_entries == 1; | |
297 | } | |
298 | ||
62751b68 JP |
299 | #define flow_action_for_each(__i, __act, __actions) \ |
300 | for (__i = 0, __act = &(__actions)->entries[0]; \ | |
301 | __i < (__actions)->num_entries; \ | |
302 | __act = &(__actions)->entries[++__i]) | |
303 | ||
319a1d19 | 304 | static inline bool |
53eca1f3 JK |
305 | flow_action_mixed_hw_stats_check(const struct flow_action *action, |
306 | struct netlink_ext_ack *extack) | |
319a1d19 JP |
307 | { |
308 | const struct flow_action_entry *action_entry; | |
3f649ab7 | 309 | u8 last_hw_stats; |
319a1d19 JP |
310 | int i; |
311 | ||
312 | if (flow_offload_has_one_action(action)) | |
313 | return true; | |
314 | ||
62751b68 | 315 | flow_action_for_each(i, action_entry, action) { |
0dfb2d82 | 316 | if (i && action_entry->hw_stats != last_hw_stats) { |
319a1d19 JP |
317 | NL_SET_ERR_MSG_MOD(extack, "Mixing HW stats types for actions is not supported"); |
318 | return false; | |
319 | } | |
0dfb2d82 | 320 | last_hw_stats = action_entry->hw_stats; |
319a1d19 JP |
321 | } |
322 | return true; | |
323 | } | |
324 | ||
325 | static inline const struct flow_action_entry * | |
326 | flow_action_first_entry_get(const struct flow_action *action) | |
327 | { | |
328 | WARN_ON(!flow_action_has_entries(action)); | |
329 | return &action->entries[0]; | |
330 | } | |
331 | ||
332 | static inline bool | |
53eca1f3 JK |
333 | __flow_action_hw_stats_check(const struct flow_action *action, |
334 | struct netlink_ext_ack *extack, | |
335 | bool check_allow_bit, | |
0dfb2d82 | 336 | enum flow_action_hw_stats_bit allow_bit) |
319a1d19 JP |
337 | { |
338 | const struct flow_action_entry *action_entry; | |
339 | ||
340 | if (!flow_action_has_entries(action)) | |
341 | return true; | |
53eca1f3 | 342 | if (!flow_action_mixed_hw_stats_check(action, extack)) |
319a1d19 | 343 | return false; |
16f80360 | 344 | |
319a1d19 | 345 | action_entry = flow_action_first_entry_get(action); |
060b6381 EC |
346 | |
347 | /* Zero is not a legal value for hw_stats, catch anyone passing it */ | |
348 | WARN_ON_ONCE(!action_entry->hw_stats); | |
16f80360 | 349 | |
a16fa289 | 350 | if (!check_allow_bit && |
060b6381 | 351 | ~action_entry->hw_stats & FLOW_ACTION_HW_STATS_ANY) { |
319a1d19 JP |
352 | NL_SET_ERR_MSG_MOD(extack, "Driver supports only default HW stats type \"any\""); |
353 | return false; | |
a16fa289 | 354 | } else if (check_allow_bit && |
0dfb2d82 | 355 | !(action_entry->hw_stats & BIT(allow_bit))) { |
319a1d19 JP |
356 | NL_SET_ERR_MSG_MOD(extack, "Driver does not support selected HW stats type"); |
357 | return false; | |
358 | } | |
359 | return true; | |
360 | } | |
361 | ||
a16fa289 | 362 | static inline bool |
53eca1f3 JK |
363 | flow_action_hw_stats_check(const struct flow_action *action, |
364 | struct netlink_ext_ack *extack, | |
0dfb2d82 | 365 | enum flow_action_hw_stats_bit allow_bit) |
a16fa289 | 366 | { |
53eca1f3 | 367 | return __flow_action_hw_stats_check(action, extack, true, allow_bit); |
a16fa289 JP |
368 | } |
369 | ||
319a1d19 | 370 | static inline bool |
53eca1f3 JK |
371 | flow_action_basic_hw_stats_check(const struct flow_action *action, |
372 | struct netlink_ext_ack *extack) | |
319a1d19 | 373 | { |
53eca1f3 | 374 | return __flow_action_hw_stats_check(action, extack, false, 0); |
319a1d19 JP |
375 | } |
376 | ||
8f256622 PNA |
377 | struct flow_rule { |
378 | struct flow_match match; | |
e3ab786b | 379 | struct flow_action action; |
8f256622 PNA |
380 | }; |
381 | ||
e3ab786b | 382 | struct flow_rule *flow_rule_alloc(unsigned int num_actions); |
8f256622 PNA |
383 | |
384 | static inline bool flow_rule_match_key(const struct flow_rule *rule, | |
385 | enum flow_dissector_key_id key) | |
386 | { | |
387 | return dissector_uses_key(rule->match.dissector, key); | |
388 | } | |
389 | ||
3b1903ef PNA |
390 | struct flow_stats { |
391 | u64 pkts; | |
392 | u64 bytes; | |
4b61d3e8 | 393 | u64 drops; |
3b1903ef | 394 | u64 lastused; |
93a129eb JP |
395 | enum flow_action_hw_stats used_hw_stats; |
396 | bool used_hw_stats_valid; | |
3b1903ef PNA |
397 | }; |
398 | ||
399 | static inline void flow_stats_update(struct flow_stats *flow_stats, | |
4b61d3e8 PL |
400 | u64 bytes, u64 pkts, |
401 | u64 drops, u64 lastused, | |
93a129eb | 402 | enum flow_action_hw_stats used_hw_stats) |
3b1903ef | 403 | { |
9f9dc493 JH |
404 | flow_stats->pkts += pkts; |
405 | flow_stats->bytes += bytes; | |
4b61d3e8 | 406 | flow_stats->drops += drops; |
9f9dc493 | 407 | flow_stats->lastused = max_t(u64, flow_stats->lastused, lastused); |
93a129eb JP |
408 | |
409 | /* The driver should pass value with a maximum of one bit set. | |
410 | * Passing FLOW_ACTION_HW_STATS_ANY is invalid. | |
411 | */ | |
412 | WARN_ON(used_hw_stats == FLOW_ACTION_HW_STATS_ANY); | |
413 | flow_stats->used_hw_stats |= used_hw_stats; | |
414 | flow_stats->used_hw_stats_valid = true; | |
3b1903ef PNA |
415 | } |
416 | ||
4e95bc26 | 417 | enum flow_block_command { |
9c0e189e PNA |
418 | FLOW_BLOCK_BIND, |
419 | FLOW_BLOCK_UNBIND, | |
4e95bc26 PNA |
420 | }; |
421 | ||
422 | enum flow_block_binder_type { | |
32f8c409 PNA |
423 | FLOW_BLOCK_BINDER_TYPE_UNSPEC, |
424 | FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS, | |
425 | FLOW_BLOCK_BINDER_TYPE_CLSACT_EGRESS, | |
aee9caa0 PM |
426 | FLOW_BLOCK_BINDER_TYPE_RED_EARLY_DROP, |
427 | FLOW_BLOCK_BINDER_TYPE_RED_MARK, | |
4e95bc26 PNA |
428 | }; |
429 | ||
14bfb13f PNA |
430 | struct flow_block { |
431 | struct list_head cb_list; | |
432 | }; | |
433 | ||
4e95bc26 PNA |
434 | struct netlink_ext_ack; |
435 | ||
436 | struct flow_block_offload { | |
437 | enum flow_block_command command; | |
438 | enum flow_block_binder_type binder_type; | |
955bcb6e | 439 | bool block_shared; |
c9f14470 | 440 | bool unlocked_driver_cb; |
da3eeb90 | 441 | struct net *net; |
14bfb13f | 442 | struct flow_block *block; |
da3eeb90 | 443 | struct list_head cb_list; |
4e95bc26 PNA |
444 | struct list_head *driver_block_list; |
445 | struct netlink_ext_ack *extack; | |
c40f4e50 | 446 | struct Qdisc *sch; |
4e95bc26 PNA |
447 | }; |
448 | ||
a7323311 PNA |
449 | enum tc_setup_type; |
450 | typedef int flow_setup_cb_t(enum tc_setup_type type, void *type_data, | |
451 | void *cb_priv); | |
452 | ||
1fac52da PNA |
453 | struct flow_block_cb; |
454 | ||
455 | struct flow_block_indr { | |
456 | struct list_head list; | |
457 | struct net_device *dev; | |
c40f4e50 | 458 | struct Qdisc *sch; |
1fac52da PNA |
459 | enum flow_block_binder_type binder_type; |
460 | void *data; | |
a1db2178 | 461 | void *cb_priv; |
1fac52da PNA |
462 | void (*cleanup)(struct flow_block_cb *block_cb); |
463 | }; | |
464 | ||
d63db30c | 465 | struct flow_block_cb { |
da3eeb90 | 466 | struct list_head driver_list; |
d63db30c | 467 | struct list_head list; |
a7323311 | 468 | flow_setup_cb_t *cb; |
d63db30c PNA |
469 | void *cb_ident; |
470 | void *cb_priv; | |
471 | void (*release)(void *cb_priv); | |
1fac52da | 472 | struct flow_block_indr indr; |
d63db30c PNA |
473 | unsigned int refcnt; |
474 | }; | |
475 | ||
a7323311 | 476 | struct flow_block_cb *flow_block_cb_alloc(flow_setup_cb_t *cb, |
d63db30c PNA |
477 | void *cb_ident, void *cb_priv, |
478 | void (*release)(void *cb_priv)); | |
26f2eb27 | 479 | struct flow_block_cb *flow_indr_block_cb_alloc(flow_setup_cb_t *cb, |
480 | void *cb_ident, void *cb_priv, | |
481 | void (*release)(void *cb_priv), | |
482 | struct flow_block_offload *bo, | |
c40f4e50 PM |
483 | struct net_device *dev, |
484 | struct Qdisc *sch, void *data, | |
a1db2178 | 485 | void *indr_cb_priv, |
26f2eb27 | 486 | void (*cleanup)(struct flow_block_cb *block_cb)); |
d63db30c PNA |
487 | void flow_block_cb_free(struct flow_block_cb *block_cb); |
488 | ||
14bfb13f | 489 | struct flow_block_cb *flow_block_cb_lookup(struct flow_block *block, |
a7323311 | 490 | flow_setup_cb_t *cb, void *cb_ident); |
da3eeb90 | 491 | |
67bd0d5e PNA |
492 | void *flow_block_cb_priv(struct flow_block_cb *block_cb); |
493 | void flow_block_cb_incref(struct flow_block_cb *block_cb); | |
494 | unsigned int flow_block_cb_decref(struct flow_block_cb *block_cb); | |
495 | ||
da3eeb90 PNA |
496 | static inline void flow_block_cb_add(struct flow_block_cb *block_cb, |
497 | struct flow_block_offload *offload) | |
498 | { | |
499 | list_add_tail(&block_cb->list, &offload->cb_list); | |
500 | } | |
501 | ||
502 | static inline void flow_block_cb_remove(struct flow_block_cb *block_cb, | |
503 | struct flow_block_offload *offload) | |
504 | { | |
505 | list_move(&block_cb->list, &offload->cb_list); | |
506 | } | |
507 | ||
26f2eb27 | 508 | static inline void flow_indr_block_cb_remove(struct flow_block_cb *block_cb, |
509 | struct flow_block_offload *offload) | |
510 | { | |
511 | list_del(&block_cb->indr.list); | |
512 | list_move(&block_cb->list, &offload->cb_list); | |
513 | } | |
514 | ||
a7323311 | 515 | bool flow_block_cb_is_busy(flow_setup_cb_t *cb, void *cb_ident, |
0d4fd02e PNA |
516 | struct list_head *driver_block_list); |
517 | ||
4e95bc26 | 518 | int flow_block_cb_setup_simple(struct flow_block_offload *f, |
a7323311 PNA |
519 | struct list_head *driver_list, |
520 | flow_setup_cb_t *cb, | |
4e95bc26 PNA |
521 | void *cb_ident, void *cb_priv, bool ingress_only); |
522 | ||
f9e30088 PNA |
523 | enum flow_cls_command { |
524 | FLOW_CLS_REPLACE, | |
525 | FLOW_CLS_DESTROY, | |
526 | FLOW_CLS_STATS, | |
527 | FLOW_CLS_TMPLT_CREATE, | |
528 | FLOW_CLS_TMPLT_DESTROY, | |
529 | }; | |
530 | ||
531 | struct flow_cls_common_offload { | |
532 | u32 chain_index; | |
533 | __be16 protocol; | |
534 | u32 prio; | |
535 | struct netlink_ext_ack *extack; | |
536 | }; | |
537 | ||
538 | struct flow_cls_offload { | |
539 | struct flow_cls_common_offload common; | |
540 | enum flow_cls_command command; | |
541 | unsigned long cookie; | |
542 | struct flow_rule *rule; | |
543 | struct flow_stats stats; | |
544 | u32 classid; | |
545 | }; | |
546 | ||
547 | static inline struct flow_rule * | |
548 | flow_cls_offload_flow_rule(struct flow_cls_offload *flow_cmd) | |
549 | { | |
550 | return flow_cmd->rule; | |
551 | } | |
552 | ||
14bfb13f PNA |
553 | static inline void flow_block_init(struct flow_block *flow_block) |
554 | { | |
555 | INIT_LIST_HEAD(&flow_block->cb_list); | |
556 | } | |
557 | ||
c40f4e50 | 558 | typedef int flow_indr_block_bind_cb_t(struct net_device *dev, struct Qdisc *sch, void *cb_priv, |
66f1939a | 559 | enum tc_setup_type type, void *type_data, |
560 | void *data, | |
561 | void (*cleanup)(struct flow_block_cb *block_cb)); | |
4e481908 | 562 | |
1fac52da PNA |
563 | int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv); |
564 | void flow_indr_dev_unregister(flow_indr_block_bind_cb_t *cb, void *cb_priv, | |
a1db2178 | 565 | void (*release)(void *cb_priv)); |
c40f4e50 | 566 | int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch, |
1fac52da PNA |
567 | enum tc_setup_type type, void *data, |
568 | struct flow_block_offload *bo, | |
569 | void (*cleanup)(struct flow_block_cb *block_cb)); | |
570 | ||
8f256622 | 571 | #endif /* _NET_FLOW_OFFLOAD_H */ |