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 FIELD_SIZEOF(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_FLOW_MERGE BIT(30)
46#define NFP_FL_FEATS_LAG BIT(31)
47
48struct nfp_fl_mask_id {
49 struct circ_buf mask_id_free_list;
50 ktime_t *last_used;
51 u8 init_unallocated;
52};
53
54struct nfp_fl_stats_id {
55 struct circ_buf free_list;
56 u32 init_unalloc;
57 u8 repeated_em_count;
58};
59
60
61
62
63
64
65
66
67
68
69
70struct nfp_fl_tunnel_offloads {
71 struct rhashtable offloaded_macs;
72 struct list_head ipv4_off_list;
73 struct list_head neigh_off_list;
74 struct mutex ipv4_off_lock;
75 spinlock_t neigh_off_lock;
76 struct ida mac_off_ids;
77 struct notifier_block neigh_nb;
78};
79
80
81
82
83
84
85
86
87
88struct nfp_mtu_conf {
89 u32 portnum;
90 unsigned int requested_val;
91 bool ack;
92 wait_queue_head_t wait_q;
93 spinlock_t lock;
94};
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109struct nfp_fl_lag {
110 struct delayed_work work;
111 struct mutex lock;
112 struct list_head group_list;
113 struct ida ida_handle;
114 unsigned int pkt_num;
115 unsigned int batch_ver;
116 u8 global_inst;
117 bool rst_cfg;
118 struct sk_buff_head retrans_skbs;
119};
120
121
122
123
124
125
126struct nfp_fl_internal_ports {
127 struct idr port_ids;
128 spinlock_t lock;
129};
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166struct nfp_flower_priv {
167 struct nfp_app *app;
168 struct nfp_net *nn;
169 u32 mask_id_seed;
170 u64 flower_version;
171 u64 flower_ext_feats;
172 struct nfp_fl_stats_id stats_ids;
173 struct nfp_fl_mask_id mask_ids;
174 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
175 u32 stats_ring_size;
176 struct rhashtable flow_table;
177 struct nfp_fl_stats *stats;
178 spinlock_t stats_lock;
179 struct rhashtable stats_ctx_table;
180 struct work_struct cmsg_work;
181 struct sk_buff_head cmsg_skbs_high;
182 struct sk_buff_head cmsg_skbs_low;
183 struct nfp_fl_tunnel_offloads tun;
184 atomic_t reify_replies;
185 wait_queue_head_t reify_wait_queue;
186 struct nfp_mtu_conf mtu_conf;
187 struct nfp_fl_lag nfp_lag;
188 struct list_head indr_block_cb_priv;
189 struct list_head non_repr_priv;
190 unsigned int active_mem_unit;
191 unsigned int total_mem_units;
192 struct nfp_fl_internal_ports internal_ports;
193 struct delayed_work qos_stats_work;
194 unsigned int qos_rate_limiters;
195 spinlock_t qos_stats_lock;
196};
197
198
199
200
201
202
203
204
205struct nfp_fl_qos {
206 u32 netdev_port_id;
207 struct nfp_stat_pair curr_stats;
208 struct nfp_stat_pair prev_stats;
209 u64 last_update;
210};
211
212
213
214
215
216
217
218
219
220
221
222struct nfp_flower_repr_priv {
223 struct nfp_repr *nfp_repr;
224 unsigned long lag_port_flags;
225 bool mac_offloaded;
226 u8 offloaded_mac_addr[ETH_ALEN];
227 bool block_shared;
228 struct list_head mac_list;
229 struct nfp_fl_qos qos_table;
230};
231
232
233
234
235
236
237
238
239
240struct nfp_flower_non_repr_priv {
241 struct list_head list;
242 struct net_device *netdev;
243 int ref_count;
244 bool mac_offloaded;
245 u8 offloaded_mac_addr[ETH_ALEN];
246};
247
248struct nfp_fl_key_ls {
249 u32 key_layer_two;
250 u8 key_layer;
251 int key_size;
252};
253
254struct nfp_fl_rule_metadata {
255 u8 key_len;
256 u8 mask_len;
257 u8 act_len;
258 u8 flags;
259 __be32 host_ctx_id;
260 __be64 host_cookie __packed;
261 __be64 flow_version __packed;
262 __be32 shortcut;
263};
264
265struct nfp_fl_stats {
266 u64 pkts;
267 u64 bytes;
268 u64 used;
269};
270
271struct nfp_fl_payload {
272 struct nfp_fl_rule_metadata meta;
273 unsigned long tc_flower_cookie;
274 struct rhash_head fl_node;
275 struct rcu_head rcu;
276 __be32 nfp_tun_ipv4_addr;
277 struct net_device *ingress_dev;
278 char *unmasked_data;
279 char *mask_data;
280 char *action_data;
281 struct list_head linked_flows;
282 bool in_hw;
283};
284
285struct nfp_fl_payload_link {
286
287
288
289
290
291
292
293
294
295
296 struct {
297 struct list_head list;
298 struct nfp_fl_payload *flow;
299 } merge_flow, sub_flow;
300};
301
302extern const struct rhashtable_params nfp_flower_table_params;
303
304struct nfp_fl_stats_frame {
305 __be32 stats_con_id;
306 __be32 pkt_count;
307 __be64 byte_count;
308 __be64 stats_cookie;
309};
310
311static inline bool
312nfp_flower_internal_port_can_offload(struct nfp_app *app,
313 struct net_device *netdev)
314{
315 struct nfp_flower_priv *app_priv = app->priv;
316
317 if (!(app_priv->flower_ext_feats & NFP_FL_FEATS_FLOW_MERGE))
318 return false;
319 if (!netdev->rtnl_link_ops)
320 return false;
321 if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))
322 return true;
323
324 return false;
325}
326
327
328
329
330
331static inline bool nfp_flower_is_merge_flow(struct nfp_fl_payload *flow_pay)
332{
333 return flow_pay->tc_flower_cookie == (unsigned long)flow_pay;
334}
335
336int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count,
337 unsigned int host_ctx_split);
338void nfp_flower_metadata_cleanup(struct nfp_app *app);
339
340int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
341 enum tc_setup_type type, void *type_data);
342int nfp_flower_merge_offloaded_flows(struct nfp_app *app,
343 struct nfp_fl_payload *sub_flow1,
344 struct nfp_fl_payload *sub_flow2);
345int nfp_flower_compile_flow_match(struct nfp_app *app,
346 struct flow_cls_offload *flow,
347 struct nfp_fl_key_ls *key_ls,
348 struct net_device *netdev,
349 struct nfp_fl_payload *nfp_flow,
350 enum nfp_flower_tun_type tun_type,
351 struct netlink_ext_ack *extack);
352int nfp_flower_compile_action(struct nfp_app *app,
353 struct flow_cls_offload *flow,
354 struct net_device *netdev,
355 struct nfp_fl_payload *nfp_flow,
356 struct netlink_ext_ack *extack);
357int nfp_compile_flow_metadata(struct nfp_app *app,
358 struct flow_cls_offload *flow,
359 struct nfp_fl_payload *nfp_flow,
360 struct net_device *netdev,
361 struct netlink_ext_ack *extack);
362void __nfp_modify_flow_metadata(struct nfp_flower_priv *priv,
363 struct nfp_fl_payload *nfp_flow);
364int nfp_modify_flow_metadata(struct nfp_app *app,
365 struct nfp_fl_payload *nfp_flow);
366
367struct nfp_fl_payload *
368nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
369 struct net_device *netdev);
370struct nfp_fl_payload *
371nfp_flower_get_fl_payload_from_ctx(struct nfp_app *app, u32 ctx_id);
372struct nfp_fl_payload *
373nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
374
375void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
376
377int nfp_tunnel_config_start(struct nfp_app *app);
378void nfp_tunnel_config_stop(struct nfp_app *app);
379int nfp_tunnel_mac_event_handler(struct nfp_app *app,
380 struct net_device *netdev,
381 unsigned long event, void *ptr);
382void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
383void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
384void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
385void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
386void nfp_flower_lag_init(struct nfp_fl_lag *lag);
387void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
388int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
389int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv,
390 struct net_device *netdev,
391 unsigned long event, void *ptr);
392bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb);
393int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
394 struct net_device *master,
395 struct nfp_fl_pre_lag *pre_act,
396 struct netlink_ext_ack *extack);
397int nfp_flower_lag_get_output_id(struct nfp_app *app,
398 struct net_device *master);
399void nfp_flower_qos_init(struct nfp_app *app);
400void nfp_flower_qos_cleanup(struct nfp_app *app);
401int nfp_flower_setup_qos_offload(struct nfp_app *app, struct net_device *netdev,
402 struct tc_cls_matchall_offload *flow);
403void nfp_flower_stats_rlim_reply(struct nfp_app *app, struct sk_buff *skb);
404int nfp_flower_reg_indir_block_handler(struct nfp_app *app,
405 struct net_device *netdev,
406 unsigned long event);
407
408void
409__nfp_flower_non_repr_priv_get(struct nfp_flower_non_repr_priv *non_repr_priv);
410struct nfp_flower_non_repr_priv *
411nfp_flower_non_repr_priv_get(struct nfp_app *app, struct net_device *netdev);
412void
413__nfp_flower_non_repr_priv_put(struct nfp_flower_non_repr_priv *non_repr_priv);
414void
415nfp_flower_non_repr_priv_put(struct nfp_app *app, struct net_device *netdev);
416u32 nfp_flower_get_port_id_from_netdev(struct nfp_app *app,
417 struct net_device *netdev);
418#endif
419