1 | /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ |
2 | /* Copyright (C) 2017-2018 Netronome Systems, Inc. */ |
3 | |
4 | #ifndef NFP_FLOWER_CMSG_H |
5 | #define NFP_FLOWER_CMSG_H |
6 | |
7 | #include <linux/bitfield.h> |
8 | #include <linux/skbuff.h> |
9 | #include <linux/types.h> |
10 | #include <net/geneve.h> |
11 | #include <net/gre.h> |
12 | #include <net/vxlan.h> |
13 | |
14 | #include "../nfp_app.h" |
15 | #include "../nfpcore/nfp_cpp.h" |
16 | |
17 | #define NFP_FLOWER_LAYER_EXT_META BIT(0) |
18 | #define NFP_FLOWER_LAYER_PORT BIT(1) |
19 | #define NFP_FLOWER_LAYER_MAC BIT(2) |
20 | #define NFP_FLOWER_LAYER_TP BIT(3) |
21 | #define NFP_FLOWER_LAYER_IPV4 BIT(4) |
22 | #define NFP_FLOWER_LAYER_IPV6 BIT(5) |
23 | #define NFP_FLOWER_LAYER_CT BIT(6) |
24 | #define NFP_FLOWER_LAYER_VXLAN BIT(7) |
25 | |
26 | #define NFP_FLOWER_LAYER2_GRE BIT(0) |
27 | #define NFP_FLOWER_LAYER2_QINQ BIT(4) |
28 | #define NFP_FLOWER_LAYER2_GENEVE BIT(5) |
29 | #define NFP_FLOWER_LAYER2_GENEVE_OP BIT(6) |
30 | #define NFP_FLOWER_LAYER2_TUN_IPV6 BIT(7) |
31 | |
32 | #define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13) |
33 | #define NFP_FLOWER_MASK_VLAN_PRESENT BIT(12) |
34 | #define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0) |
35 | |
36 | #define NFP_FLOWER_MASK_MPLS_LB GENMASK(31, 12) |
37 | #define NFP_FLOWER_MASK_MPLS_TC GENMASK(11, 9) |
38 | #define NFP_FLOWER_MASK_MPLS_BOS BIT(8) |
39 | #define NFP_FLOWER_MASK_MPLS_Q BIT(0) |
40 | |
41 | #define NFP_FL_IP_FRAG_FIRST BIT(7) |
42 | #define NFP_FL_IP_FRAGMENTED BIT(6) |
43 | |
44 | /* GRE Tunnel flags */ |
45 | #define NFP_FL_GRE_FLAG_KEY BIT(2) |
46 | |
47 | /* Compressed HW representation of TCP Flags */ |
48 | #define NFP_FL_TCP_FLAG_URG BIT(4) |
49 | #define NFP_FL_TCP_FLAG_PSH BIT(3) |
50 | #define NFP_FL_TCP_FLAG_RST BIT(2) |
51 | #define NFP_FL_TCP_FLAG_SYN BIT(1) |
52 | #define NFP_FL_TCP_FLAG_FIN BIT(0) |
53 | |
54 | #define NFP_FL_SC_ACT_DROP 0x80000000 |
55 | #define NFP_FL_SC_ACT_USER 0x7D000000 |
56 | #define NFP_FL_SC_ACT_POPV 0x6A000000 |
57 | #define NFP_FL_SC_ACT_NULL 0x00000000 |
58 | |
59 | /* The maximum action list size (in bytes) supported by the NFP. |
60 | */ |
61 | #define NFP_FL_MAX_A_SIZ 1216 |
62 | #define NFP_FL_LW_SIZ 2 |
63 | |
64 | /* Maximum allowed geneve options */ |
65 | #define NFP_FL_MAX_GENEVE_OPT_ACT 32 |
66 | #define NFP_FL_MAX_GENEVE_OPT_CNT 64 |
67 | #define NFP_FL_MAX_GENEVE_OPT_KEY 32 |
68 | #define NFP_FL_MAX_GENEVE_OPT_KEY_V6 8 |
69 | |
70 | /* Action opcodes */ |
71 | #define NFP_FL_ACTION_OPCODE_OUTPUT 0 |
72 | #define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1 |
73 | #define NFP_FL_ACTION_OPCODE_POP_VLAN 2 |
74 | #define NFP_FL_ACTION_OPCODE_PUSH_MPLS 3 |
75 | #define NFP_FL_ACTION_OPCODE_POP_MPLS 4 |
76 | #define NFP_FL_ACTION_OPCODE_SET_TUNNEL 6 |
77 | #define NFP_FL_ACTION_OPCODE_SET_ETHERNET 7 |
78 | #define NFP_FL_ACTION_OPCODE_SET_MPLS 8 |
79 | #define NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS 9 |
80 | #define NFP_FL_ACTION_OPCODE_SET_IPV4_TTL_TOS 10 |
81 | #define NFP_FL_ACTION_OPCODE_SET_IPV6_SRC 11 |
82 | #define NFP_FL_ACTION_OPCODE_SET_IPV6_DST 12 |
83 | #define NFP_FL_ACTION_OPCODE_SET_IPV6_TC_HL_FL 13 |
84 | #define NFP_FL_ACTION_OPCODE_SET_UDP 14 |
85 | #define NFP_FL_ACTION_OPCODE_SET_TCP 15 |
86 | #define NFP_FL_ACTION_OPCODE_PRE_LAG 16 |
87 | #define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17 |
88 | #define NFP_FL_ACTION_OPCODE_METER 24 |
89 | #define NFP_FL_ACTION_OPCODE_PUSH_GENEVE 26 |
90 | #define NFP_FL_ACTION_OPCODE_NUM 32 |
91 | |
92 | #define NFP_FL_OUT_FLAGS_LAST BIT(15) |
93 | #define NFP_FL_OUT_FLAGS_USE_TUN BIT(4) |
94 | #define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0) |
95 | |
96 | #define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13) |
97 | #define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0) |
98 | |
99 | /* LAG ports */ |
100 | #define NFP_FL_LAG_OUT 0xC0DE0000 |
101 | |
102 | /* Tunnel ports */ |
103 | #define NFP_FL_PORT_TYPE_TUN 0x50000000 |
104 | #define NFP_FL_TUNNEL_TYPE GENMASK(7, 4) |
105 | #define NFP_FL_PRE_TUN_INDEX GENMASK(2, 0) |
106 | |
107 | #define NFP_FLOWER_WORKQ_MAX_SKBS 30000 |
108 | |
109 | /* Cmesg reply (empirical) timeout*/ |
110 | #define NFP_FL_REPLY_TIMEOUT msecs_to_jiffies(40) |
111 | |
112 | #define nfp_flower_cmsg_warn(app, fmt, args...) \ |
113 | do { \ |
114 | if (net_ratelimit()) \ |
115 | nfp_warn((app)->cpp, fmt, ## args); \ |
116 | } while (0) |
117 | |
118 | enum nfp_flower_tun_type { |
119 | NFP_FL_TUNNEL_NONE = 0, |
120 | NFP_FL_TUNNEL_GRE = 1, |
121 | NFP_FL_TUNNEL_VXLAN = 2, |
122 | NFP_FL_TUNNEL_GENEVE = 4, |
123 | }; |
124 | |
125 | struct nfp_fl_act_head { |
126 | u8 jump_id; |
127 | u8 len_lw; |
128 | }; |
129 | |
130 | struct nfp_fl_set_eth { |
131 | struct nfp_fl_act_head head; |
132 | __be16 reserved; |
133 | u8 eth_addr_mask[ETH_ALEN * 2]; |
134 | u8 eth_addr_val[ETH_ALEN * 2]; |
135 | }; |
136 | |
137 | struct nfp_fl_set_ip4_addrs { |
138 | struct nfp_fl_act_head head; |
139 | __be16 reserved; |
140 | __be32 ipv4_src_mask; |
141 | __be32 ipv4_src; |
142 | __be32 ipv4_dst_mask; |
143 | __be32 ipv4_dst; |
144 | }; |
145 | |
146 | struct nfp_fl_set_ip4_ttl_tos { |
147 | struct nfp_fl_act_head head; |
148 | u8 ipv4_ttl_mask; |
149 | u8 ipv4_tos_mask; |
150 | u8 ipv4_ttl; |
151 | u8 ipv4_tos; |
152 | __be16 reserved; |
153 | }; |
154 | |
155 | struct nfp_fl_set_ipv6_tc_hl_fl { |
156 | struct nfp_fl_act_head head; |
157 | u8 ipv6_tc_mask; |
158 | u8 ipv6_hop_limit_mask; |
159 | __be16 reserved; |
160 | u8 ipv6_tc; |
161 | u8 ipv6_hop_limit; |
162 | __be32 ipv6_label_mask; |
163 | __be32 ipv6_label; |
164 | }; |
165 | |
166 | struct nfp_fl_set_ipv6_addr { |
167 | struct nfp_fl_act_head head; |
168 | __be16 reserved; |
169 | struct { |
170 | __be32 mask; |
171 | __be32 exact; |
172 | } ipv6[4]; |
173 | }; |
174 | |
175 | struct nfp_fl_set_tport { |
176 | struct nfp_fl_act_head head; |
177 | __be16 reserved; |
178 | u8 tp_port_mask[4]; |
179 | u8 tp_port_val[4]; |
180 | }; |
181 | |
182 | struct nfp_fl_output { |
183 | struct nfp_fl_act_head head; |
184 | __be16 flags; |
185 | __be32 port; |
186 | }; |
187 | |
188 | struct nfp_fl_push_vlan { |
189 | struct nfp_fl_act_head head; |
190 | __be16 reserved; |
191 | __be16 vlan_tpid; |
192 | __be16 vlan_tci; |
193 | }; |
194 | |
195 | struct nfp_fl_pop_vlan { |
196 | struct nfp_fl_act_head head; |
197 | __be16 reserved; |
198 | }; |
199 | |
200 | struct nfp_fl_pre_lag { |
201 | struct nfp_fl_act_head head; |
202 | __be16 group_id; |
203 | u8 lag_version[3]; |
204 | u8 instance; |
205 | }; |
206 | |
207 | #define NFP_FL_PRE_LAG_VER_OFF 8 |
208 | |
209 | struct nfp_fl_pre_tunnel { |
210 | struct nfp_fl_act_head head; |
211 | __be16 flags; |
212 | union { |
213 | __be32 ipv4_dst; |
214 | struct in6_addr ipv6_dst; |
215 | }; |
216 | }; |
217 | |
218 | #define NFP_FL_PRE_TUN_IPV6 BIT(0) |
219 | |
220 | struct nfp_fl_set_tun { |
221 | struct nfp_fl_act_head head; |
222 | __be16 reserved; |
223 | __be64 tun_id __packed; |
224 | __be32 tun_type_index; |
225 | __be16 tun_flags; |
226 | u8 ttl; |
227 | u8 tos; |
228 | __be16 outer_vlan_tpid; |
229 | __be16 outer_vlan_tci; |
230 | u8 tun_len; |
231 | u8 res2; |
232 | __be16 tun_proto; |
233 | }; |
234 | |
235 | struct nfp_fl_push_geneve { |
236 | struct nfp_fl_act_head head; |
237 | __be16 reserved; |
238 | __be16 class; |
239 | u8 type; |
240 | u8 length; |
241 | u8 opt_data[]; |
242 | }; |
243 | |
244 | struct nfp_fl_push_mpls { |
245 | struct nfp_fl_act_head head; |
246 | __be16 ethtype; |
247 | __be32 lse; |
248 | }; |
249 | |
250 | struct nfp_fl_pop_mpls { |
251 | struct nfp_fl_act_head head; |
252 | __be16 ethtype; |
253 | }; |
254 | |
255 | struct nfp_fl_set_mpls { |
256 | struct nfp_fl_act_head head; |
257 | __be16 reserved; |
258 | __be32 lse_mask; |
259 | __be32 lse; |
260 | }; |
261 | |
262 | struct nfp_fl_meter { |
263 | struct nfp_fl_act_head head; |
264 | __be16 reserved; |
265 | __be32 meter_id; |
266 | }; |
267 | |
268 | /* Metadata with L2 (1W/4B) |
269 | * ---------------------------------------------------------------- |
270 | * 3 2 1 |
271 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
272 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
273 | * | key_type | mask_id | PCP |p| vlan outermost VID | |
274 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
275 | * ^ ^ |
276 | * NOTE: | TCI | |
277 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
278 | */ |
279 | struct nfp_flower_meta_tci { |
280 | u8 nfp_flow_key_layer; |
281 | u8 mask_id; |
282 | __be16 tci; |
283 | }; |
284 | |
285 | /* Extended metadata for additional key_layers (1W/4B) |
286 | * ---------------------------------------------------------------- |
287 | * 3 2 1 |
288 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
289 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
290 | * | nfp_flow_key_layer2 | |
291 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
292 | */ |
293 | struct nfp_flower_ext_meta { |
294 | __be32 nfp_flow_key_layer2; |
295 | }; |
296 | |
297 | /* Port details (1W/4B) |
298 | * ---------------------------------------------------------------- |
299 | * 3 2 1 |
300 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
301 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
302 | * | port_ingress | |
303 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
304 | */ |
305 | struct nfp_flower_in_port { |
306 | __be32 in_port; |
307 | }; |
308 | |
309 | /* L2 details (4W/16B) |
310 | * 3 2 1 |
311 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
312 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
313 | * | mac_addr_dst, 31 - 0 | |
314 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
315 | * | mac_addr_dst, 47 - 32 | mac_addr_src, 15 - 0 | |
316 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
317 | * | mac_addr_src, 47 - 16 | |
318 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
319 | * | mpls outermost label | TC |B| reserved |q| |
320 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
321 | */ |
322 | struct nfp_flower_mac_mpls { |
323 | u8 mac_dst[6]; |
324 | u8 mac_src[6]; |
325 | __be32 mpls_lse; |
326 | }; |
327 | |
328 | /* VLAN details (2W/8B) |
329 | * 3 2 1 |
330 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
331 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
332 | * | outer_tpid | outer_tci | |
333 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
334 | * | inner_tpid | inner_tci | |
335 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
336 | */ |
337 | struct nfp_flower_vlan { |
338 | __be16 outer_tpid; |
339 | __be16 outer_tci; |
340 | __be16 inner_tpid; |
341 | __be16 inner_tci; |
342 | }; |
343 | |
344 | /* L4 ports (for UDP, TCP, SCTP) (1W/4B) |
345 | * 3 2 1 |
346 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
347 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
348 | * | port_src | port_dst | |
349 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
350 | */ |
351 | struct nfp_flower_tp_ports { |
352 | __be16 port_src; |
353 | __be16 port_dst; |
354 | }; |
355 | |
356 | struct nfp_flower_ip_ext { |
357 | u8 tos; |
358 | u8 proto; |
359 | u8 ttl; |
360 | u8 flags; |
361 | }; |
362 | |
363 | /* L3 IPv4 details (3W/12B) |
364 | * 3 2 1 |
365 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
366 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
367 | * | DSCP |ECN| protocol | ttl | flags | |
368 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
369 | * | ipv4_addr_src | |
370 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
371 | * | ipv4_addr_dst | |
372 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
373 | */ |
374 | struct nfp_flower_ipv4 { |
375 | struct nfp_flower_ip_ext ip_ext; |
376 | __be32 ipv4_src; |
377 | __be32 ipv4_dst; |
378 | }; |
379 | |
380 | /* L3 IPv6 details (10W/40B) |
381 | * 3 2 1 |
382 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
383 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
384 | * | DSCP |ECN| protocol | ttl | flags | |
385 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
386 | * | ipv6_exthdr | res | ipv6_flow_label | |
387 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
388 | * | ipv6_addr_src, 31 - 0 | |
389 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
390 | * | ipv6_addr_src, 63 - 32 | |
391 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
392 | * | ipv6_addr_src, 95 - 64 | |
393 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
394 | * | ipv6_addr_src, 127 - 96 | |
395 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
396 | * | ipv6_addr_dst, 31 - 0 | |
397 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
398 | * | ipv6_addr_dst, 63 - 32 | |
399 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
400 | * | ipv6_addr_dst, 95 - 64 | |
401 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
402 | * | ipv6_addr_dst, 127 - 96 | |
403 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
404 | */ |
405 | struct nfp_flower_ipv6 { |
406 | struct nfp_flower_ip_ext ip_ext; |
407 | __be32 ipv6_flow_label_exthdr; |
408 | struct in6_addr ipv6_src; |
409 | struct in6_addr ipv6_dst; |
410 | }; |
411 | |
412 | struct nfp_flower_tun_ipv4 { |
413 | __be32 src; |
414 | __be32 dst; |
415 | }; |
416 | |
417 | struct nfp_flower_tun_ipv6 { |
418 | struct in6_addr src; |
419 | struct in6_addr dst; |
420 | }; |
421 | |
422 | struct nfp_flower_tun_ip_ext { |
423 | u8 tos; |
424 | u8 ttl; |
425 | }; |
426 | |
427 | /* Flow Frame IPv4 UDP TUNNEL --> Tunnel details (4W/16B) |
428 | * ----------------------------------------------------------------- |
429 | * 3 2 1 |
430 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
431 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
432 | * | ipv4_addr_src | |
433 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
434 | * | ipv4_addr_dst | |
435 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
436 | * | Reserved | tos | ttl | |
437 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
438 | * | Reserved | |
439 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
440 | * | VNI | Reserved | |
441 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
442 | */ |
443 | struct nfp_flower_ipv4_udp_tun { |
444 | struct nfp_flower_tun_ipv4 ipv4; |
445 | __be16 reserved1; |
446 | struct nfp_flower_tun_ip_ext ip_ext; |
447 | __be32 reserved2; |
448 | __be32 tun_id; |
449 | }; |
450 | |
451 | /* Flow Frame IPv6 UDP TUNNEL --> Tunnel details (11W/44B) |
452 | * ----------------------------------------------------------------- |
453 | * 3 2 1 |
454 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
455 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
456 | * | ipv6_addr_src, 31 - 0 | |
457 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
458 | * | ipv6_addr_src, 63 - 32 | |
459 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
460 | * | ipv6_addr_src, 95 - 64 | |
461 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
462 | * | ipv6_addr_src, 127 - 96 | |
463 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
464 | * | ipv6_addr_dst, 31 - 0 | |
465 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
466 | * | ipv6_addr_dst, 63 - 32 | |
467 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
468 | * | ipv6_addr_dst, 95 - 64 | |
469 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
470 | * | ipv6_addr_dst, 127 - 96 | |
471 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
472 | * | Reserved | tos | ttl | |
473 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
474 | * | Reserved | |
475 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
476 | * | VNI | Reserved | |
477 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
478 | */ |
479 | struct nfp_flower_ipv6_udp_tun { |
480 | struct nfp_flower_tun_ipv6 ipv6; |
481 | __be16 reserved1; |
482 | struct nfp_flower_tun_ip_ext ip_ext; |
483 | __be32 reserved2; |
484 | __be32 tun_id; |
485 | }; |
486 | |
487 | /* Flow Frame GRE TUNNEL --> Tunnel details (6W/24B) |
488 | * ----------------------------------------------------------------- |
489 | * 3 2 1 |
490 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
491 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
492 | * | ipv4_addr_src | |
493 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
494 | * | ipv4_addr_dst | |
495 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
496 | * | tun_flags | tos | ttl | |
497 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
498 | * | Reserved | Ethertype | |
499 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
500 | * | Key | |
501 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
502 | * | Reserved | |
503 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
504 | */ |
505 | |
506 | struct nfp_flower_ipv4_gre_tun { |
507 | struct nfp_flower_tun_ipv4 ipv4; |
508 | __be16 tun_flags; |
509 | struct nfp_flower_tun_ip_ext ip_ext; |
510 | __be16 reserved1; |
511 | __be16 ethertype; |
512 | __be32 tun_key; |
513 | __be32 reserved2; |
514 | }; |
515 | |
516 | /* Flow Frame GRE TUNNEL V6 --> Tunnel details (12W/48B) |
517 | * ----------------------------------------------------------------- |
518 | * 3 2 1 |
519 | * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
520 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
521 | * | ipv6_addr_src, 31 - 0 | |
522 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
523 | * | ipv6_addr_src, 63 - 32 | |
524 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
525 | * | ipv6_addr_src, 95 - 64 | |
526 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
527 | * | ipv6_addr_src, 127 - 96 | |
528 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
529 | * | ipv6_addr_dst, 31 - 0 | |
530 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
531 | * | ipv6_addr_dst, 63 - 32 | |
532 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
533 | * | ipv6_addr_dst, 95 - 64 | |
534 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
535 | * | ipv6_addr_dst, 127 - 96 | |
536 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
537 | * | tun_flags | tos | ttl | |
538 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
539 | * | Reserved | Ethertype | |
540 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
541 | * | Key | |
542 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
543 | * | Reserved | |
544 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
545 | */ |
546 | struct nfp_flower_ipv6_gre_tun { |
547 | struct nfp_flower_tun_ipv6 ipv6; |
548 | __be16 tun_flags; |
549 | struct nfp_flower_tun_ip_ext ip_ext; |
550 | __be16 reserved1; |
551 | __be16 ethertype; |
552 | __be32 tun_key; |
553 | __be32 reserved2; |
554 | }; |
555 | |
556 | struct nfp_flower_geneve_options { |
557 | u8 data[NFP_FL_MAX_GENEVE_OPT_KEY]; |
558 | }; |
559 | |
560 | #define NFP_FL_TUN_VNI_OFFSET 8 |
561 | |
562 | /* The base header for a control message packet. |
563 | * Defines an 8-bit version, and an 8-bit type, padded |
564 | * to a 32-bit word. Rest of the packet is type-specific. |
565 | */ |
566 | struct nfp_flower_cmsg_hdr { |
567 | __be16 pad; |
568 | u8 type; |
569 | u8 version; |
570 | }; |
571 | |
572 | #define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr) |
573 | #define NFP_FLOWER_CMSG_VER1 1 |
574 | |
575 | /* Types defined for port related control messages */ |
576 | enum nfp_flower_cmsg_type_port { |
577 | NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0, |
578 | NFP_FLOWER_CMSG_TYPE_FLOW_MOD = 1, |
579 | NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2, |
580 | NFP_FLOWER_CMSG_TYPE_LAG_CONFIG = 4, |
581 | NFP_FLOWER_CMSG_TYPE_PORT_REIFY = 6, |
582 | NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7, |
583 | NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8, |
584 | NFP_FLOWER_CMSG_TYPE_MERGE_HINT = 9, |
585 | NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10, |
586 | NFP_FLOWER_CMSG_TYPE_TUN_MAC = 11, |
587 | NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS = 12, |
588 | NFP_FLOWER_CMSG_TYPE_TUN_NEIGH = 13, |
589 | NFP_FLOWER_CMSG_TYPE_TUN_IPS = 14, |
590 | NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15, |
591 | NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16, |
592 | NFP_FLOWER_CMSG_TYPE_QOS_MOD = 18, |
593 | NFP_FLOWER_CMSG_TYPE_QOS_DEL = 19, |
594 | NFP_FLOWER_CMSG_TYPE_QOS_STATS = 20, |
595 | NFP_FLOWER_CMSG_TYPE_PRE_TUN_RULE = 21, |
596 | NFP_FLOWER_CMSG_TYPE_TUN_IPS_V6 = 22, |
597 | NFP_FLOWER_CMSG_TYPE_NO_NEIGH_V6 = 23, |
598 | NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V6 = 24, |
599 | NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS_V6 = 25, |
600 | NFP_FLOWER_CMSG_TYPE_MAX = 32, |
601 | }; |
602 | |
603 | /* NFP_FLOWER_CMSG_TYPE_MAC_REPR */ |
604 | struct nfp_flower_cmsg_mac_repr { |
605 | u8 reserved[3]; |
606 | u8 num_ports; |
607 | struct { |
608 | u8 idx; |
609 | u8 info; |
610 | u8 nbi_port; |
611 | u8 phys_port; |
612 | } ports[]; |
613 | }; |
614 | |
615 | #define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0) |
616 | |
617 | /* NFP_FLOWER_CMSG_TYPE_PORT_MOD */ |
618 | struct nfp_flower_cmsg_portmod { |
619 | __be32 portnum; |
620 | u8 reserved; |
621 | u8 info; |
622 | __be16 mtu; |
623 | }; |
624 | |
625 | #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0) |
626 | #define NFP_FLOWER_CMSG_PORTMOD_MTU_CHANGE_ONLY BIT(1) |
627 | |
628 | /* NFP_FLOWER_CMSG_TYPE_PORT_REIFY */ |
629 | struct nfp_flower_cmsg_portreify { |
630 | __be32 portnum; |
631 | u16 reserved; |
632 | __be16 info; |
633 | }; |
634 | |
635 | #define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST BIT(0) |
636 | |
637 | /* NFP_FLOWER_CMSG_TYPE_FLOW_MERGE_HINT */ |
638 | struct nfp_flower_cmsg_merge_hint { |
639 | u8 reserved[3]; |
640 | u8 count; |
641 | struct { |
642 | __be32 host_ctx; |
643 | __be64 host_cookie; |
644 | } __packed flow[]; |
645 | }; |
646 | |
647 | enum nfp_flower_cmsg_port_type { |
648 | NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0, |
649 | NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1, |
650 | NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2, |
651 | NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT = 0x3, |
652 | }; |
653 | |
654 | enum nfp_flower_cmsg_port_vnic_type { |
655 | NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0, |
656 | NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1, |
657 | NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2, |
658 | }; |
659 | |
660 | #define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28) |
661 | #define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24) |
662 | #define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22) |
663 | #define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14) |
664 | #define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12) |
665 | #define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6) |
666 | #define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0) |
667 | #define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0) |
668 | |
669 | static inline u32 nfp_flower_internal_port_get_port_id(u8 internal_port) |
670 | { |
671 | return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, internal_port) | |
672 | FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE, |
673 | NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT); |
674 | } |
675 | |
676 | static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port) |
677 | { |
678 | return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) | |
679 | FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE, |
680 | NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT); |
681 | } |
682 | |
683 | static inline u32 |
684 | nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type, |
685 | u8 vnic, u8 q) |
686 | { |
687 | return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) | |
688 | FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) | |
689 | FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) | |
690 | FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) | |
691 | FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE, |
692 | NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT); |
693 | } |
694 | |
695 | static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb) |
696 | { |
697 | return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN; |
698 | } |
699 | |
700 | static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb) |
701 | { |
702 | return skb->len - NFP_FLOWER_CMSG_HLEN; |
703 | } |
704 | |
705 | static inline bool |
706 | nfp_fl_netdev_is_tunnel_type(struct net_device *netdev, |
707 | enum nfp_flower_tun_type tun_type) |
708 | { |
709 | if (netif_is_vxlan(dev: netdev)) |
710 | return tun_type == NFP_FL_TUNNEL_VXLAN; |
711 | if (netif_is_gretap(dev: netdev) || netif_is_ip6gretap(dev: netdev)) |
712 | return tun_type == NFP_FL_TUNNEL_GRE; |
713 | if (netif_is_geneve(dev: netdev)) |
714 | return tun_type == NFP_FL_TUNNEL_GENEVE; |
715 | |
716 | return false; |
717 | } |
718 | |
719 | static inline bool nfp_fl_is_netdev_to_offload(struct net_device *netdev) |
720 | { |
721 | if (!netdev->rtnl_link_ops) |
722 | return false; |
723 | if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch" )) |
724 | return true; |
725 | if (netif_is_vxlan(dev: netdev)) |
726 | return true; |
727 | if (netif_is_geneve(dev: netdev)) |
728 | return true; |
729 | if (netif_is_gretap(dev: netdev)) |
730 | return true; |
731 | if (netif_is_ip6gretap(dev: netdev)) |
732 | return true; |
733 | |
734 | return false; |
735 | } |
736 | |
737 | struct sk_buff * |
738 | nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports); |
739 | void |
740 | nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx, |
741 | unsigned int nbi, unsigned int nbi_port, |
742 | unsigned int phys_port); |
743 | int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok, |
744 | unsigned int mtu, bool mtu_only); |
745 | int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists); |
746 | void nfp_flower_cmsg_process_rx(struct work_struct *work); |
747 | void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb); |
748 | struct sk_buff * |
749 | nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size, |
750 | enum nfp_flower_cmsg_type_port type, gfp_t flag); |
751 | |
752 | #endif |
753 | |