Commit | Line | Data |
---|---|---|
96de2506 JK |
1 | /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ |
2 | /* Copyright (C) 2017-2018 Netronome Systems, Inc. */ | |
8a276873 PJV |
3 | |
4 | #ifndef __NFP_FLOWER_H__ | |
5 | #define __NFP_FLOWER_H__ 1 | |
6 | ||
bedeca15 JH |
7 | #include "cmsg.h" |
8 | ||
43f84b72 PJV |
9 | #include <linux/circ_buf.h> |
10 | #include <linux/hashtable.h> | |
c01d0efa | 11 | #include <linux/rhashtable.h> |
43f84b72 | 12 | #include <linux/time64.h> |
8a276873 | 13 | #include <linux/types.h> |
de4784ca | 14 | #include <net/pkt_cls.h> |
ffa61202 | 15 | #include <net/tcp.h> |
b985f870 | 16 | #include <linux/workqueue.h> |
bb9a8d03 | 17 | #include <linux/idr.h> |
8a276873 | 18 | |
7e24a593 | 19 | struct nfp_fl_pre_lag; |
8a276873 PJV |
20 | struct net_device; |
21 | struct nfp_app; | |
22 | ||
467322e2 PJV |
23 | #define NFP_FL_STAT_ID_MU_NUM GENMASK(31, 22) |
24 | #define NFP_FL_STAT_ID_STAT GENMASK(21, 0) | |
25 | ||
12ecf615 PJV |
26 | #define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \ |
27 | init_unalloc) | |
43f84b72 PJV |
28 | #define NFP_FLOWER_MASK_ENTRY_RS 256 |
29 | #define NFP_FLOWER_MASK_ELEMENT_RS 1 | |
30 | #define NFP_FLOWER_MASK_HASH_BITS 10 | |
31 | ||
6c3ab204 | 32 | #define NFP_FL_META_FLAG_MANAGE_MASK BIT(7) |
43f84b72 PJV |
33 | |
34 | #define NFP_FL_MASK_REUSE_TIME_NS 40000 | |
35 | #define NFP_FL_MASK_ID_LOCATION 1 | |
36 | ||
bedeca15 JH |
37 | /* Extra features bitmap. */ |
38 | #define NFP_FL_FEATS_GENEVE BIT(0) | |
29a5dcae | 39 | #define NFP_FL_NBI_MTU_SETTING BIT(1) |
9e7c32fe | 40 | #define NFP_FL_FEATS_GENEVE_OPT BIT(2) |
db191db8 | 41 | #define NFP_FL_FEATS_VLAN_PCP BIT(3) |
2f2622f5 JH |
42 | #define NFP_FL_FEATS_FLOW_MOD BIT(5) |
43 | #define NFP_FL_FEATS_FLOW_MERGE BIT(30) | |
898bc7d6 | 44 | #define NFP_FL_FEATS_LAG BIT(31) |
611aec10 | 45 | |
43f84b72 PJV |
46 | struct nfp_fl_mask_id { |
47 | struct circ_buf mask_id_free_list; | |
51bef926 | 48 | ktime_t *last_used; |
43f84b72 PJV |
49 | u8 init_unallocated; |
50 | }; | |
51 | ||
abfcdc1d PJV |
52 | struct nfp_fl_stats_id { |
53 | struct circ_buf free_list; | |
54 | u32 init_unalloc; | |
55 | u8 repeated_em_count; | |
56 | }; | |
57 | ||
f3b97577 JH |
58 | /** |
59 | * struct nfp_fl_tunnel_offloads - priv data for tunnel offloads | |
20cce886 | 60 | * @offloaded_macs: Hashtable of the offloaded MAC addresses |
f3b97577 JH |
61 | * @ipv4_off_list: List of IPv4 addresses to offload |
62 | * @neigh_off_list: List of neighbour offloads | |
f3b97577 JH |
63 | * @ipv4_off_lock: Lock for the IPv4 address list |
64 | * @neigh_off_lock: Lock for the neighbour address list | |
65 | * @mac_off_ids: IDA to manage id assignment for offloaded MACs | |
f3b97577 JH |
66 | * @neigh_nb: Notifier to monitor neighbour state |
67 | */ | |
68 | struct nfp_fl_tunnel_offloads { | |
20cce886 | 69 | struct rhashtable offloaded_macs; |
f3b97577 JH |
70 | struct list_head ipv4_off_list; |
71 | struct list_head neigh_off_list; | |
f3b97577 JH |
72 | struct mutex ipv4_off_lock; |
73 | spinlock_t neigh_off_lock; | |
74 | struct ida mac_off_ids; | |
f3b97577 JH |
75 | struct notifier_block neigh_nb; |
76 | }; | |
77 | ||
29a5dcae JH |
78 | /** |
79 | * struct nfp_mtu_conf - manage MTU setting | |
80 | * @portnum: NFP port number of repr with requested MTU change | |
81 | * @requested_val: MTU value requested for repr | |
82 | * @ack: Received ack that MTU has been correctly set | |
83 | * @wait_q: Wait queue for MTU acknowledgements | |
84 | * @lock: Lock for setting/reading MTU variables | |
85 | */ | |
86 | struct nfp_mtu_conf { | |
87 | u32 portnum; | |
88 | unsigned int requested_val; | |
89 | bool ack; | |
90 | wait_queue_head_t wait_q; | |
91 | spinlock_t lock; | |
92 | }; | |
93 | ||
bb9a8d03 JH |
94 | /** |
95 | * struct nfp_fl_lag - Flower APP priv data for link aggregation | |
bb9a8d03 JH |
96 | * @work: Work queue for writing configs to the HW |
97 | * @lock: Lock to protect lag_group_list | |
98 | * @group_list: List of all master/slave groups offloaded | |
99 | * @ida_handle: IDA to handle group ids | |
100 | * @pkt_num: Incremented for each config packet sent | |
101 | * @batch_ver: Incremented for each batch of config packets | |
102 | * @global_inst: Instance allocator for groups | |
103 | * @rst_cfg: Marker to reset HW LAG config | |
2e1cc522 JH |
104 | * @retrans_skbs: Cmsgs that could not be processed by HW and require |
105 | * retransmission | |
bb9a8d03 JH |
106 | */ |
107 | struct nfp_fl_lag { | |
bb9a8d03 JH |
108 | struct delayed_work work; |
109 | struct mutex lock; | |
110 | struct list_head group_list; | |
111 | struct ida ida_handle; | |
112 | unsigned int pkt_num; | |
113 | unsigned int batch_ver; | |
114 | u8 global_inst; | |
115 | bool rst_cfg; | |
2e1cc522 | 116 | struct sk_buff_head retrans_skbs; |
bb9a8d03 JH |
117 | }; |
118 | ||
4d12ba42 JH |
119 | /** |
120 | * struct nfp_fl_internal_ports - Flower APP priv data for additional ports | |
121 | * @port_ids: Assignment of ids to any additional ports | |
122 | * @lock: Lock for extra ports list | |
123 | */ | |
124 | struct nfp_fl_internal_ports { | |
125 | struct idr port_ids; | |
126 | spinlock_t lock; | |
127 | }; | |
128 | ||
43f84b72 PJV |
129 | /** |
130 | * struct nfp_flower_priv - Flower APP per-vNIC priv data | |
c496291c | 131 | * @app: Back pointer to app |
43f84b72 PJV |
132 | * @nn: Pointer to vNIC |
133 | * @mask_id_seed: Seed used for mask hash table | |
134 | * @flower_version: HW version of flower | |
73997348 | 135 | * @flower_ext_feats: Bitmap of extra features the HW supports |
abfcdc1d | 136 | * @stats_ids: List of free stats ids |
43f84b72 PJV |
137 | * @mask_ids: List of free mask ids |
138 | * @mask_table: Hash table used to store masks | |
12ecf615 | 139 | * @stats_ring_size: Maximum number of allowed stats ids |
43f84b72 | 140 | * @flow_table: Hash table used to store flower rules |
7fade107 PJV |
141 | * @stats: Stored stats updates for flower rules |
142 | * @stats_lock: Lock for flower rule stats updates | |
b985f870 | 143 | * @cmsg_work: Workqueue for control messages processing |
cf2cbadc PJV |
144 | * @cmsg_skbs_high: List of higher priority skbs for control message |
145 | * processing | |
146 | * @cmsg_skbs_low: List of lower priority skbs for control message | |
147 | * processing | |
f3b97577 | 148 | * @tun: Tunnel offload data |
d2c2928d DM |
149 | * @reify_replies: atomically stores the number of replies received |
150 | * from firmware for repr reify | |
151 | * @reify_wait_queue: wait queue for repr reify response counting | |
29a5dcae | 152 | * @mtu_conf: Configuration of repr MTU value |
bb9a8d03 | 153 | * @nfp_lag: Link aggregation data block |
3166dd07 | 154 | * @indr_block_cb_priv: List of priv data passed to indirect block cbs |
05d2bee6 | 155 | * @non_repr_priv: List of offloaded non-repr ports and their priv data |
467322e2 PJV |
156 | * @active_mem_unit: Current active memory unit for flower rules |
157 | * @total_mem_units: Total number of available memory units for flower rules | |
4d12ba42 | 158 | * @internal_ports: Internal port ids used in offloaded rules |
43f84b72 PJV |
159 | */ |
160 | struct nfp_flower_priv { | |
c496291c | 161 | struct nfp_app *app; |
43f84b72 PJV |
162 | struct nfp_net *nn; |
163 | u32 mask_id_seed; | |
164 | u64 flower_version; | |
73997348 | 165 | u64 flower_ext_feats; |
abfcdc1d | 166 | struct nfp_fl_stats_id stats_ids; |
43f84b72 PJV |
167 | struct nfp_fl_mask_id mask_ids; |
168 | DECLARE_HASHTABLE(mask_table, NFP_FLOWER_MASK_HASH_BITS); | |
12ecf615 | 169 | u32 stats_ring_size; |
c01d0efa | 170 | struct rhashtable flow_table; |
7fade107 PJV |
171 | struct nfp_fl_stats *stats; |
172 | spinlock_t stats_lock; /* lock stats */ | |
b985f870 | 173 | struct work_struct cmsg_work; |
cf2cbadc PJV |
174 | struct sk_buff_head cmsg_skbs_high; |
175 | struct sk_buff_head cmsg_skbs_low; | |
f3b97577 | 176 | struct nfp_fl_tunnel_offloads tun; |
d2c2928d DM |
177 | atomic_t reify_replies; |
178 | wait_queue_head_t reify_wait_queue; | |
29a5dcae | 179 | struct nfp_mtu_conf mtu_conf; |
bb9a8d03 | 180 | struct nfp_fl_lag nfp_lag; |
3166dd07 | 181 | struct list_head indr_block_cb_priv; |
05d2bee6 | 182 | struct list_head non_repr_priv; |
467322e2 PJV |
183 | unsigned int active_mem_unit; |
184 | unsigned int total_mem_units; | |
4d12ba42 | 185 | struct nfp_fl_internal_ports internal_ports; |
43f84b72 PJV |
186 | }; |
187 | ||
b9452452 JH |
188 | /** |
189 | * struct nfp_flower_repr_priv - Flower APP per-repr priv data | |
20cce886 | 190 | * @nfp_repr: Back pointer to nfp_repr |
b9452452 | 191 | * @lag_port_flags: Extended port flags to record lag state of repr |
13cf7103 JH |
192 | * @mac_offloaded: Flag indicating a MAC address is offloaded for repr |
193 | * @offloaded_mac_addr: MAC address that has been offloaded for repr | |
20cce886 | 194 | * @mac_list: List entry of reprs that share the same offloaded MAC |
b9452452 JH |
195 | */ |
196 | struct nfp_flower_repr_priv { | |
20cce886 | 197 | struct nfp_repr *nfp_repr; |
b9452452 | 198 | unsigned long lag_port_flags; |
13cf7103 JH |
199 | bool mac_offloaded; |
200 | u8 offloaded_mac_addr[ETH_ALEN]; | |
20cce886 | 201 | struct list_head mac_list; |
b9452452 JH |
202 | }; |
203 | ||
05d2bee6 JH |
204 | /** |
205 | * struct nfp_flower_non_repr_priv - Priv data for non-repr offloaded ports | |
206 | * @list: List entry of offloaded reprs | |
207 | * @netdev: Pointer to non-repr net_device | |
208 | * @ref_count: Number of references held for this priv data | |
13cf7103 JH |
209 | * @mac_offloaded: Flag indicating a MAC address is offloaded for device |
210 | * @offloaded_mac_addr: MAC address that has been offloaded for dev | |
05d2bee6 JH |
211 | */ |
212 | struct nfp_flower_non_repr_priv { | |
213 | struct list_head list; | |
214 | struct net_device *netdev; | |
215 | int ref_count; | |
13cf7103 JH |
216 | bool mac_offloaded; |
217 | u8 offloaded_mac_addr[ETH_ALEN]; | |
05d2bee6 JH |
218 | }; |
219 | ||
af9d842c PJV |
220 | struct nfp_fl_key_ls { |
221 | u32 key_layer_two; | |
222 | u8 key_layer; | |
223 | int key_size; | |
224 | }; | |
225 | ||
226 | struct nfp_fl_rule_metadata { | |
227 | u8 key_len; | |
228 | u8 mask_len; | |
229 | u8 act_len; | |
230 | u8 flags; | |
231 | __be32 host_ctx_id; | |
232 | __be64 host_cookie __packed; | |
233 | __be64 flow_version __packed; | |
234 | __be32 shortcut; | |
235 | }; | |
236 | ||
abfcdc1d PJV |
237 | struct nfp_fl_stats { |
238 | u64 pkts; | |
239 | u64 bytes; | |
240 | u64 used; | |
241 | }; | |
242 | ||
af9d842c PJV |
243 | struct nfp_fl_payload { |
244 | struct nfp_fl_rule_metadata meta; | |
43f84b72 | 245 | unsigned long tc_flower_cookie; |
c01d0efa | 246 | struct rhash_head fl_node; |
43f84b72 | 247 | struct rcu_head rcu; |
2d9ad71a | 248 | __be32 nfp_tun_ipv4_addr; |
54a4a034 | 249 | struct net_device *ingress_dev; |
af9d842c PJV |
250 | char *unmasked_data; |
251 | char *mask_data; | |
252 | char *action_data; | |
253 | }; | |
254 | ||
c01d0efa PJV |
255 | extern const struct rhashtable_params nfp_flower_table_params; |
256 | ||
abfcdc1d PJV |
257 | struct nfp_fl_stats_frame { |
258 | __be32 stats_con_id; | |
259 | __be32 pkt_count; | |
260 | __be64 byte_count; | |
261 | __be64 stats_cookie; | |
262 | }; | |
263 | ||
4d12ba42 JH |
264 | static inline bool |
265 | nfp_flower_internal_port_can_offload(struct nfp_app *app, | |
266 | struct net_device *netdev) | |
267 | { | |
268 | struct nfp_flower_priv *app_priv = app->priv; | |
269 | ||
270 | if (!(app_priv->flower_ext_feats & NFP_FL_FEATS_FLOW_MERGE)) | |
271 | return false; | |
272 | if (!netdev->rtnl_link_ops) | |
273 | return false; | |
274 | if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch")) | |
275 | return true; | |
276 | ||
277 | return false; | |
278 | } | |
279 | ||
467322e2 PJV |
280 | int nfp_flower_metadata_init(struct nfp_app *app, u64 host_ctx_count, |
281 | unsigned int host_ctx_split); | |
43f84b72 PJV |
282 | void nfp_flower_metadata_cleanup(struct nfp_app *app); |
283 | ||
8a276873 | 284 | int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev, |
de4784ca | 285 | enum tc_setup_type type, void *type_data); |
7885b4fc JH |
286 | int nfp_flower_compile_flow_match(struct nfp_app *app, |
287 | struct tc_cls_flower_offload *flow, | |
5571e8c9 PJV |
288 | struct nfp_fl_key_ls *key_ls, |
289 | struct net_device *netdev, | |
bedeca15 JH |
290 | struct nfp_fl_payload *nfp_flow, |
291 | enum nfp_flower_tun_type tun_type); | |
7e24a593 JH |
292 | int nfp_flower_compile_action(struct nfp_app *app, |
293 | struct tc_cls_flower_offload *flow, | |
1a1e586f PJV |
294 | struct net_device *netdev, |
295 | struct nfp_fl_payload *nfp_flow); | |
43f84b72 PJV |
296 | int nfp_compile_flow_metadata(struct nfp_app *app, |
297 | struct tc_cls_flower_offload *flow, | |
54a4a034 JH |
298 | struct nfp_fl_payload *nfp_flow, |
299 | struct net_device *netdev); | |
43f84b72 PJV |
300 | int nfp_modify_flow_metadata(struct nfp_app *app, |
301 | struct nfp_fl_payload *nfp_flow); | |
302 | ||
303 | struct nfp_fl_payload * | |
54a4a034 | 304 | nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie, |
d4b69bad | 305 | struct net_device *netdev); |
43f84b72 PJV |
306 | struct nfp_fl_payload * |
307 | nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie); | |
5571e8c9 | 308 | |
abfcdc1d PJV |
309 | void nfp_flower_rx_flow_stats(struct nfp_app *app, struct sk_buff *skb); |
310 | ||
fd0dd1ab JH |
311 | int nfp_tunnel_config_start(struct nfp_app *app); |
312 | void nfp_tunnel_config_stop(struct nfp_app *app); | |
0c665e2b JK |
313 | int nfp_tunnel_mac_event_handler(struct nfp_app *app, |
314 | struct net_device *netdev, | |
315 | unsigned long event, void *ptr); | |
2d9ad71a JH |
316 | void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4); |
317 | void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4); | |
8e6a9046 | 318 | void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb); |
856f5b13 | 319 | void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb); |
bb9a8d03 JH |
320 | void nfp_flower_lag_init(struct nfp_fl_lag *lag); |
321 | void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag); | |
322 | int nfp_flower_lag_reset(struct nfp_fl_lag *lag); | |
0c665e2b JK |
323 | int nfp_flower_lag_netdev_event(struct nfp_flower_priv *priv, |
324 | struct net_device *netdev, | |
325 | unsigned long event, void *ptr); | |
2e1cc522 | 326 | bool nfp_flower_lag_unprocessed_msg(struct nfp_app *app, struct sk_buff *skb); |
7e24a593 JH |
327 | int nfp_flower_lag_populate_pre_action(struct nfp_app *app, |
328 | struct net_device *master, | |
329 | struct nfp_fl_pre_lag *pre_act); | |
330 | int nfp_flower_lag_get_output_id(struct nfp_app *app, | |
331 | struct net_device *master); | |
3166dd07 JH |
332 | int nfp_flower_reg_indir_block_handler(struct nfp_app *app, |
333 | struct net_device *netdev, | |
334 | unsigned long event); | |
fd0dd1ab | 335 | |
05d2bee6 JH |
336 | void |
337 | __nfp_flower_non_repr_priv_get(struct nfp_flower_non_repr_priv *non_repr_priv); | |
338 | struct nfp_flower_non_repr_priv * | |
339 | nfp_flower_non_repr_priv_get(struct nfp_app *app, struct net_device *netdev); | |
340 | void | |
341 | __nfp_flower_non_repr_priv_put(struct nfp_flower_non_repr_priv *non_repr_priv); | |
342 | void | |
343 | nfp_flower_non_repr_priv_put(struct nfp_app *app, struct net_device *netdev); | |
4d12ba42 JH |
344 | u32 nfp_flower_get_port_id_from_netdev(struct nfp_app *app, |
345 | struct net_device *netdev); | |
8a276873 | 346 | #endif |