1
2
3
4#ifndef __NFP_FLOWER_H__
5#define __NFP_FLOWER_H__ 1
6
7#include "cmsg.h"
8#include "../nfp_net.h"
9
10#include <linux/circ_buf.h>
11#include <linux/hashtable.h>
12#include <linux/rhashtable.h>
13#include <linux/time64.h>
14#include <linux/types.h>
15#include <net/pkt_cls.h>
16#include <net/tcp.h>
17#include <linux/workqueue.h>
18#include <linux/idr.h>
19
20struct nfp_fl_pre_lag;
21struct net_device;
22struct nfp_app;
23
24#define NFP_FL_STAT_ID_MU_NUM GENMASK(31, 22)
25#define NFP_FL_STAT_ID_STAT GENMASK(21, 0)
26
27#define NFP_FL_STATS_ELEM_RS sizeof_field(struct nfp_fl_stats_id, \
28 init_unalloc)
29#define NFP_FLOWER_MASK_ENTRY_RS 256
30#define NFP_FLOWER_MASK_ELEMENT_RS 1
31#define NFP_FLOWER_MASK_HASH_BITS 10
32
33#define NFP_FL_META_FLAG_MANAGE_MASK BIT(7)
34
35#define NFP_FL_MASK_REUSE_TIME_NS 40000
36#define NFP_FL_MASK_ID_LOCATION 1
37
38
39#define NFP_FL_FEATS_GENEVE BIT(0)
40#define NFP_FL_NBI_MTU_SETTING BIT(1)
41#define NFP_FL_FEATS_GENEVE_OPT BIT(2)
42#define NFP_FL_FEATS_VLAN_PCP BIT(3)
43#define NFP_FL_FEATS_VF_RLIM BIT(4)
44#define NFP_FL_FEATS_FLOW_MOD BIT(5)
45#define NFP_FL_FEATS_PRE_TUN_RULES BIT(6)
46#define NFP_FL_FEATS_IPV6_TUN BIT(7)
47#define NFP_FL_FEATS_HOST_ACK BIT(31)
48
49#define NFP_FL_ENABLE_FLOW_MERGE BIT(0)
50#define NFP_FL_ENABLE_LAG BIT(1)
51
52#define NFP_FL_FEATS_HOST \
53 (NFP_FL_FEATS_GENEVE | \
54 NFP_FL_NBI_MTU_SETTING | \
55 NFP_FL_FEATS_GENEVE_OPT | \
56 NFP_FL_FEATS_VLAN_PCP | \
57 NFP_FL_FEATS_VF_RLIM | \
58 NFP_FL_FEATS_FLOW_MOD | \
59 NFP_FL_FEATS_PRE_TUN_RULES | \
60 NFP_FL_FEATS_IPV6_TUN)
61
62struct nfp_fl_mask_id {
63 struct circ_buf mask_id_free_list;
64 ktime_t *last_used;
65 u8 init_unallocated;
66};
67
68struct nfp_fl_stats_id {
69 struct circ_buf free_list;
70 u32 init_unalloc;
71 u8 repeated_em_count;
72};
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88struct nfp_fl_tunnel_offloads {
89 struct rhashtable offloaded_macs;
90 struct list_head ipv4_off_list;
91 struct list_head ipv6_off_list;
92 struct list_head neigh_off_list_v4;
93 struct list_head neigh_off_list_v6;
94 struct mutex ipv4_off_lock;
95 struct mutex ipv6_off_lock;
96 spinlock_t neigh_off_lock_v4;
97 spinlock_t neigh_off_lock_v6;
98 struct ida mac_off_ids;
99 struct notifier_block neigh_nb;
100};
101
102
103
104
105
106
107
108
109
110struct nfp_mtu_conf {
111 u32 portnum;
112 unsigned int requested_val;
113 bool ack;
114 wait_queue_head_t wait_q;
115 spinlock_t lock;
116};
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131struct nfp_fl_lag {
132 struct delayed_work work;
133 struct mutex lock;
134 struct list_head group_list;
135 struct ida ida_handle;
136 unsigned int pkt_num;
137 unsigned int batch_ver;
138 u8 global_inst;
139 bool rst_cfg;
140 struct sk_buff_head retrans_skbs;
141};
142
143
144
145
146
147
148struct nfp_fl_internal_ports {
149 struct idr port_ids;
150 spinlock_t lock;
151};
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190struct nfp_flower_priv {
191 struct nfp_app *app;
192 struct nfp_net *nn;
193 u32 mask_id_seed;
194 u64 flower_version;
195 u64 flower_ext_feats;
196 u8 flower_en_feats;
197 struct nfp_fl_stats_id stats_ids;
198 struct nfp_fl_mask_id mask_ids;
199 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
200 u32 stats_ring_size;
201 struct rhashtable flow_table;
202 struct nfp_fl_stats *stats;
203 spinlock_t stats_lock;
204 struct rhashtable stats_ctx_table;
205 struct work_struct cmsg_work;
206 struct sk_buff_head cmsg_skbs_high;
207 struct sk_buff_head cmsg_skbs_low;
208 struct nfp_fl_tunnel_offloads tun;
209 atomic_t reify_replies;
210 wait_queue_head_t reify_wait_queue;
211 struct nfp_mtu_conf mtu_conf;
212 struct nfp_fl_lag nfp_lag;
213 struct list_head indr_block_cb_priv;
214 struct list_head non_repr_priv;
215 unsigned int active_mem_unit;
216 unsigned int total_mem_units;
217 struct nfp_fl_internal_ports internal_ports;
218 struct delayed_work qos_stats_work;
219 unsigned int qos_rate_limiters;
220 spinlock_t qos_stats_lock;
221 int pre_tun_rule_cnt;
222};
223
224
225
226
227
228
229
230
231struct nfp_fl_qos {
232 u32 netdev_port_id;
233 struct nfp_stat_pair curr_stats;
234 struct nfp_stat_pair prev_stats;
235 u64 last_update;
236};
237
238
239
240
241
242
243
244
245
246
247
248
249struct nfp_flower_repr_priv {
250 struct nfp_repr *nfp_repr;
251 unsigned long lag_port_flags;
252 bool mac_offloaded;
253 u8 offloaded_mac_addr[ETH_ALEN];
254 bool block_shared;
255 struct list_head mac_list;
256 struct nfp_fl_qos qos_table;
257 bool on_bridge;
258};
259
260
261
262
263
264
265
266
267
268struct nfp_flower_non_repr_priv {
269 struct list_head list;
270 struct net_device *netdev;
271 int ref_count;
272 bool mac_offloaded;
273 u8 offloaded_mac_addr[ETH_ALEN];
274};
275
276struct nfp_fl_key_ls {
277 u32 key_layer_two;
278 u8 key_layer;
279 int key_size;
280};
281
282struct nfp_fl_rule_metadata {
283 u8 key_len;
284 u8 mask_len;
285 u8 act_len;
286 u8 flags;
287 __be32 host_ctx_id;
288 __be64 host_cookie __packed;
289 __be64 flow_version __packed;
290 __be32 shortcut;
291};
292
293struct nfp_fl_stats {
294 u64 pkts;
295 u64 bytes;
296 u64 used;
297};
298
299
300
301
302
303
304
305struct nfp_ipv6_addr_entry {
306 struct in6_addr ipv6_addr;
307 int ref_count;
308 struct list_head list;
309};
310
311struct nfp_fl_payload {
312 struct nfp_fl_rule_metadata meta;
313 unsigned long tc_flower_cookie;
314 struct rhash_head fl_node;
315 struct rcu_head rcu;
316 __be32 nfp_tun_ipv4_addr;
317 struct nfp_ipv6_addr_entry *nfp_tun_ipv6;
318 struct net_device *ingress_dev;
319 char *unmasked_data;
320 char *mask_data;
321 char *action_data;
322 struct list_head linked_flows;
323 bool in_hw;
324 struct {
325 struct net_device *dev;
326 __be16 vlan_tci;
327 __be16 port_idx;
328 } pre_tun_rule;
329};
330
331struct nfp_fl_payload_link {
332
333
334
335
336
337
338
339
340
341
342 struct {
343 struct list_head list;
344 struct nfp_fl_payload *flow;
345 } merge_flow, sub_flow;
346};
347
348extern const struct rhashtable_params nfp_flower_table_params;
349
350struct nfp_fl_stats_frame {
351 __be32 stats_con_id;
352 __be32 pkt_count;
353 __be64 byte_count;
354 __be64 stats_cookie;
355};
356
357static inline bool
358nfp_flower_internal_port_can_offload(struct nfp_app *app,
359 struct net_device *netdev)
360{
361 struct nfp_flower_priv *app_priv = app->priv;
362
363 if (!(app_priv->flower_en_feats & NFP_FL_ENABLE_FLOW_MERGE))
364 return false;
365 if (!netdev->rtnl_link_ops)
366 return false;
367 if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))
368 return true;
369
370 return false;
371}
372
373
374
375
376
377static inline bool nfp_flower_is_merge_flow(struct nfp_fl_payload *flow_pay)
378{
379 return flow_pay->tc_flower_cookie == (unsigned long)flow_pay;
380}
381
382static inline bool nfp_flower_is_supported_bridge(struct net_device *netdev)
383{
384 return netif_is_ovs_master(netdev);
385}
386
387int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count,
388 unsigned int host_ctx_split);
389void nfp_flower_metadata_cleanup(struct nfp_app *app);
390
391int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
392 enum tc_setup_type type, void *type_data);
393int nfp_flower_merge_offloaded_flows(struct nfp_app *app,
394 struct nfp_fl_payload *sub_flow1,
395 struct nfp_fl_payload *sub_flow2);
396int nfp_flower_compile_flow_match(struct nfp_app *app,
397 struct flow_cls_offload *flow,
398 struct nfp_fl_key_ls *key_ls,
399 struct net_device *netdev,
400 struct nfp_fl_payload *nfp_flow,
401 enum nfp_flower_tun_type tun_type,
402 struct netlink_ext_ack *extack);
403int nfp_flower_compile_action(struct nfp_app *app,
404 struct flow_cls_offload *flow,
405 struct net_device *netdev,
406 struct nfp_fl_payload *nfp_flow,
407 struct netlink_ext_ack *extack);
408int nfp_compile_flow_metadata(struct nfp_app *app,
409 struct flow_cls_offload *flow,
410 struct nfp_fl_payload *nfp_flow,
411 struct net_device *netdev,
412 struct netlink_ext_ack *extack);
413void __nfp_modify_flow_metadata(struct nfp_flower_priv *priv,
414 struct nfp_fl_payload *nfp_flow);
415int nfp_modify_flow_metadata(struct nfp_app *app,
416 struct nfp_fl_payload *nfp_flow);
417
418struct nfp_fl_payload *
419nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
420 struct net_device *netdev);
421struct nfp_fl_payload *
422nfp_flower_get_fl_payload_from_ctx(struct nfp_app *app, u32 ctx_id);
423struct nfp_fl_payload *
424nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
425
426void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
427
428int nfp_tunnel_config_start(struct nfp_app *app);
429void nfp_tunnel_config_stop(struct nfp_app *app);
430int nfp_tunnel_mac_event_handler(struct nfp_app *app,
431 struct net_device *netdev,
432 unsigned long event, void *ptr);
433void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
434void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
435void
436nfp_tunnel_put_ipv6_off(struct nfp_app *app, struct nfp_ipv6_addr_entry *entry);
437struct nfp_ipv6_addr_entry *
438nfp_tunnel_add_ipv6_off(struct nfp_app *app, struct in6_addr *ipv6);
439void nfp_tunnel_request_route_v4(struct nfp_app *app, struct sk_buff *skb);
440void nfp_tunnel_request_route_v6(struct nfp_app *app, struct sk_buff *skb);
441void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
442void nfp_tunnel_keep_alive_v6(struct nfp_app *app, struct sk_buff *skb);
443void nfp_flower_lag_init(struct nfp_fl_lag *lag);
444void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
445int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
446int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv,
447 struct net_device *netdev,
448 unsigned long event, void *ptr);
449bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb);
450int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
451 struct net_device *master,
452 struct nfp_fl_pre_lag *pre_act,
453 struct netlink_ext_ack *extack);
454int nfp_flower_lag_get_output_id(struct nfp_app *app,
455 struct net_device *master);
456void nfp_flower_qos_init(struct nfp_app *app);
457void nfp_flower_qos_cleanup(struct nfp_app *app);
458int nfp_flower_setup_qos_offload(struct nfp_app *app, struct net_device *netdev,
459 struct tc_cls_matchall_offload *flow);
460void nfp_flower_stats_rlim_reply(struct nfp_app *app, struct sk_buff *skb);
461int nfp_flower_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch, void *cb_priv,
462 enum tc_setup_type type, void *type_data,
463 void *data,
464 void (*cleanup)(struct flow_block_cb *block_cb));
465void nfp_flower_setup_indr_tc_release(void *cb_priv);
466
467void
468__nfp_flower_non_repr_priv_get(struct nfp_flower_non_repr_priv *non_repr_priv);
469struct nfp_flower_non_repr_priv *
470nfp_flower_non_repr_priv_get(struct nfp_app *app, struct net_device *netdev);
471void
472__nfp_flower_non_repr_priv_put(struct nfp_flower_non_repr_priv *non_repr_priv);
473void
474nfp_flower_non_repr_priv_put(struct nfp_app *app, struct net_device *netdev);
475u32 nfp_flower_get_port_id_from_netdev(struct nfp_app *app,
476 struct net_device *netdev);
477int nfp_flower_xmit_pre_tun_flow(struct nfp_app *app,
478 struct nfp_fl_payload *flow);
479int nfp_flower_xmit_pre_tun_del_flow(struct nfp_app *app,
480 struct nfp_fl_payload *flow);
481#endif
482