1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#ifndef __NFP_FLOWER_H__
35#define __NFP_FLOWER_H__ 1
36
37#include <linux/circ_buf.h>
38#include <linux/hashtable.h>
39#include <linux/time64.h>
40#include <linux/types.h>
41#include <net/pkt_cls.h>
42#include <linux/workqueue.h>
43
44struct net_device;
45struct nfp_app;
46
47#define NFP_FL_STATS_ENTRY_RS BIT(20)
48#define NFP_FL_STATS_ELEM_RS 4
49#define NFP_FL_REPEATED_HASH_MAX BIT(17)
50#define NFP_FLOWER_HASH_BITS 19
51#define NFP_FLOWER_MASK_ENTRY_RS 256
52#define NFP_FLOWER_MASK_ELEMENT_RS 1
53#define NFP_FLOWER_MASK_HASH_BITS 10
54
55#define NFP_FL_META_FLAG_NEW_MASK 128
56#define NFP_FL_META_FLAG_LAST_MASK 1
57
58#define NFP_FL_MASK_REUSE_TIME_NS 40000
59#define NFP_FL_MASK_ID_LOCATION 1
60
61struct nfp_fl_mask_id {
62 struct circ_buf mask_id_free_list;
63 struct timespec64 *last_used;
64 u8 init_unallocated;
65};
66
67struct nfp_fl_stats_id {
68 struct circ_buf free_list;
69 u32 init_unalloc;
70 u8 repeated_em_count;
71};
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86struct nfp_flower_priv {
87 struct nfp_app *app;
88 struct nfp_net *nn;
89 u32 mask_id_seed;
90 u64 flower_version;
91 struct nfp_fl_stats_id stats_ids;
92 struct nfp_fl_mask_id mask_ids;
93 DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS);
94 DECLARE_HASHTABLE(flow_table, NFP_FLOWER_HASH_BITS);
95 struct work_struct cmsg_work;
96 struct sk_buff_head cmsg_skbs;
97};
98
99struct nfp_fl_key_ls {
100 u32 key_layer_two;
101 u8 key_layer;
102 int key_size;
103};
104
105struct nfp_fl_rule_metadata {
106 u8 key_len;
107 u8 mask_len;
108 u8 act_len;
109 u8 flags;
110 __be32 host_ctx_id;
111 __be64 host_cookie __packed;
112 __be64 flow_version __packed;
113 __be32 shortcut;
114};
115
116struct nfp_fl_stats {
117 u64 pkts;
118 u64 bytes;
119 u64 used;
120};
121
122struct nfp_fl_payload {
123 struct nfp_fl_rule_metadata meta;
124 unsigned long tc_flower_cookie;
125 struct hlist_node link;
126 struct rcu_head rcu;
127 spinlock_t lock;
128 struct nfp_fl_stats stats;
129 char *unmasked_data;
130 char *mask_data;
131 char *action_data;
132};
133
134struct nfp_fl_stats_frame {
135 __be32 stats_con_id;
136 __be32 pkt_count;
137 __be64 byte_count;
138 __be64 stats_cookie;
139};
140
141int nfp_flower_metadata_init(struct nfp_app *app);
142void nfp_flower_metadata_cleanup(struct nfp_app *app);
143
144int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
145 enum tc_setup_type type, void *type_data);
146int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
147 struct nfp_fl_key_ls *key_ls,
148 struct net_device *netdev,
149 struct nfp_fl_payload *nfp_flow);
150int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
151 struct net_device *netdev,
152 struct nfp_fl_payload *nfp_flow);
153int nfp_compile_flow_metadata(struct nfp_app *app,
154 struct tc_cls_flower_offload *flow,
155 struct nfp_fl_payload *nfp_flow);
156int nfp_modify_flow_metadata(struct nfp_app *app,
157 struct nfp_fl_payload *nfp_flow);
158
159struct nfp_fl_payload *
160nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
161struct nfp_fl_payload *
162nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
163
164void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb);
165
166#endif
167