This source file includes following definitions.
- nfp_flower_internal_port_get_port_id
- nfp_flower_cmsg_phys_port
- nfp_flower_cmsg_pcie_port
- nfp_flower_cmsg_get_data
- nfp_flower_cmsg_get_data_len
- nfp_fl_netdev_is_tunnel_type
- nfp_fl_is_netdev_to_offload
1
2
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_GENEVE BIT(5)
28 #define NFP_FLOWER_LAYER2_GENEVE_OP BIT(6)
29
30 #define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13)
31 #define NFP_FLOWER_MASK_VLAN_PRESENT BIT(12)
32 #define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0)
33
34 #define NFP_FLOWER_MASK_MPLS_LB GENMASK(31, 12)
35 #define NFP_FLOWER_MASK_MPLS_TC GENMASK(11, 9)
36 #define NFP_FLOWER_MASK_MPLS_BOS BIT(8)
37 #define NFP_FLOWER_MASK_MPLS_Q BIT(0)
38
39 #define NFP_FL_IP_FRAG_FIRST BIT(7)
40 #define NFP_FL_IP_FRAGMENTED BIT(6)
41
42
43 #define NFP_FL_GRE_FLAG_KEY BIT(2)
44
45
46 #define NFP_FL_TCP_FLAG_URG BIT(4)
47 #define NFP_FL_TCP_FLAG_PSH BIT(3)
48 #define NFP_FL_TCP_FLAG_RST BIT(2)
49 #define NFP_FL_TCP_FLAG_SYN BIT(1)
50 #define NFP_FL_TCP_FLAG_FIN BIT(0)
51
52 #define NFP_FL_SC_ACT_DROP 0x80000000
53 #define NFP_FL_SC_ACT_USER 0x7D000000
54 #define NFP_FL_SC_ACT_POPV 0x6A000000
55 #define NFP_FL_SC_ACT_NULL 0x00000000
56
57
58
59 #define NFP_FL_MAX_A_SIZ 1216
60 #define NFP_FL_LW_SIZ 2
61
62
63 #define NFP_FL_MAX_GENEVE_OPT_ACT 32
64 #define NFP_FL_MAX_GENEVE_OPT_CNT 64
65 #define NFP_FL_MAX_GENEVE_OPT_KEY 32
66
67
68 #define NFP_FL_ACTION_OPCODE_OUTPUT 0
69 #define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1
70 #define NFP_FL_ACTION_OPCODE_POP_VLAN 2
71 #define NFP_FL_ACTION_OPCODE_PUSH_MPLS 3
72 #define NFP_FL_ACTION_OPCODE_POP_MPLS 4
73 #define NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL 6
74 #define NFP_FL_ACTION_OPCODE_SET_ETHERNET 7
75 #define NFP_FL_ACTION_OPCODE_SET_MPLS 8
76 #define NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS 9
77 #define NFP_FL_ACTION_OPCODE_SET_IPV4_TTL_TOS 10
78 #define NFP_FL_ACTION_OPCODE_SET_IPV6_SRC 11
79 #define NFP_FL_ACTION_OPCODE_SET_IPV6_DST 12
80 #define NFP_FL_ACTION_OPCODE_SET_IPV6_TC_HL_FL 13
81 #define NFP_FL_ACTION_OPCODE_SET_UDP 14
82 #define NFP_FL_ACTION_OPCODE_SET_TCP 15
83 #define NFP_FL_ACTION_OPCODE_PRE_LAG 16
84 #define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17
85 #define NFP_FL_ACTION_OPCODE_PUSH_GENEVE 26
86 #define NFP_FL_ACTION_OPCODE_NUM 32
87
88 #define NFP_FL_OUT_FLAGS_LAST BIT(15)
89 #define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
90 #define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
91
92 #define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13)
93 #define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0)
94
95 #define IPV6_FLOW_LABEL_MASK cpu_to_be32(0x000fffff)
96
97
98 #define NFP_FL_LAG_OUT 0xC0DE0000
99
100
101 #define NFP_FL_PORT_TYPE_TUN 0x50000000
102 #define NFP_FL_IPV4_TUNNEL_TYPE GENMASK(7, 4)
103 #define NFP_FL_IPV4_PRE_TUN_INDEX GENMASK(2, 0)
104
105 #define NFP_FLOWER_WORKQ_MAX_SKBS 30000
106
107
108 #define NFP_FL_REPLY_TIMEOUT msecs_to_jiffies(40)
109
110 #define nfp_flower_cmsg_warn(app, fmt, args...) \
111 do { \
112 if (net_ratelimit()) \
113 nfp_warn((app)->cpp, fmt, ## args); \
114 } while (0)
115
116 enum nfp_flower_tun_type {
117 NFP_FL_TUNNEL_NONE = 0,
118 NFP_FL_TUNNEL_GRE = 1,
119 NFP_FL_TUNNEL_VXLAN = 2,
120 NFP_FL_TUNNEL_GENEVE = 4,
121 };
122
123 struct nfp_fl_act_head {
124 u8 jump_id;
125 u8 len_lw;
126 };
127
128 struct nfp_fl_set_eth {
129 struct nfp_fl_act_head head;
130 __be16 reserved;
131 u8 eth_addr_mask[ETH_ALEN * 2];
132 u8 eth_addr_val[ETH_ALEN * 2];
133 };
134
135 struct nfp_fl_set_ip4_addrs {
136 struct nfp_fl_act_head head;
137 __be16 reserved;
138 __be32 ipv4_src_mask;
139 __be32 ipv4_src;
140 __be32 ipv4_dst_mask;
141 __be32 ipv4_dst;
142 };
143
144 struct nfp_fl_set_ip4_ttl_tos {
145 struct nfp_fl_act_head head;
146 u8 ipv4_ttl_mask;
147 u8 ipv4_tos_mask;
148 u8 ipv4_ttl;
149 u8 ipv4_tos;
150 __be16 reserved;
151 };
152
153 struct nfp_fl_set_ipv6_tc_hl_fl {
154 struct nfp_fl_act_head head;
155 u8 ipv6_tc_mask;
156 u8 ipv6_hop_limit_mask;
157 __be16 reserved;
158 u8 ipv6_tc;
159 u8 ipv6_hop_limit;
160 __be32 ipv6_label_mask;
161 __be32 ipv6_label;
162 };
163
164 struct nfp_fl_set_ipv6_addr {
165 struct nfp_fl_act_head head;
166 __be16 reserved;
167 struct {
168 __be32 mask;
169 __be32 exact;
170 } ipv6[4];
171 };
172
173 struct nfp_fl_set_tport {
174 struct nfp_fl_act_head head;
175 __be16 reserved;
176 u8 tp_port_mask[4];
177 u8 tp_port_val[4];
178 };
179
180 struct nfp_fl_output {
181 struct nfp_fl_act_head head;
182 __be16 flags;
183 __be32 port;
184 };
185
186 struct nfp_fl_push_vlan {
187 struct nfp_fl_act_head head;
188 __be16 reserved;
189 __be16 vlan_tpid;
190 __be16 vlan_tci;
191 };
192
193 struct nfp_fl_pop_vlan {
194 struct nfp_fl_act_head head;
195 __be16 reserved;
196 };
197
198 struct nfp_fl_pre_lag {
199 struct nfp_fl_act_head head;
200 __be16 group_id;
201 u8 lag_version[3];
202 u8 instance;
203 };
204
205 #define NFP_FL_PRE_LAG_VER_OFF 8
206
207 struct nfp_fl_pre_tunnel {
208 struct nfp_fl_act_head head;
209 __be16 reserved;
210 __be32 ipv4_dst;
211
212 __be32 extra[3];
213 };
214
215 struct nfp_fl_set_ipv4_tun {
216 struct nfp_fl_act_head head;
217 __be16 reserved;
218 __be64 tun_id __packed;
219 __be32 tun_type_index;
220 __be16 tun_flags;
221 u8 ttl;
222 u8 tos;
223 __be16 outer_vlan_tpid;
224 __be16 outer_vlan_tci;
225 u8 tun_len;
226 u8 res2;
227 __be16 tun_proto;
228 };
229
230 struct nfp_fl_push_geneve {
231 struct nfp_fl_act_head head;
232 __be16 reserved;
233 __be16 class;
234 u8 type;
235 u8 length;
236 u8 opt_data[];
237 };
238
239 struct nfp_fl_push_mpls {
240 struct nfp_fl_act_head head;
241 __be16 ethtype;
242 __be32 lse;
243 };
244
245 struct nfp_fl_pop_mpls {
246 struct nfp_fl_act_head head;
247 __be16 ethtype;
248 };
249
250 struct nfp_fl_set_mpls {
251 struct nfp_fl_act_head head;
252 __be16 reserved;
253 __be32 lse_mask;
254 __be32 lse;
255 };
256
257
258
259
260
261
262
263
264
265
266
267
268 struct nfp_flower_meta_tci {
269 u8 nfp_flow_key_layer;
270 u8 mask_id;
271 __be16 tci;
272 };
273
274
275
276
277
278
279
280
281
282 struct nfp_flower_ext_meta {
283 __be32 nfp_flow_key_layer2;
284 };
285
286
287
288
289
290
291
292
293
294 struct nfp_flower_in_port {
295 __be32 in_port;
296 };
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311 struct nfp_flower_mac_mpls {
312 u8 mac_dst[6];
313 u8 mac_src[6];
314 __be32 mpls_lse;
315 };
316
317
318
319
320
321
322
323
324 struct nfp_flower_tp_ports {
325 __be16 port_src;
326 __be16 port_dst;
327 };
328
329 struct nfp_flower_ip_ext {
330 u8 tos;
331 u8 proto;
332 u8 ttl;
333 u8 flags;
334 };
335
336
337
338
339
340
341
342
343
344
345
346
347 struct nfp_flower_ipv4 {
348 struct nfp_flower_ip_ext ip_ext;
349 __be32 ipv4_src;
350 __be32 ipv4_dst;
351 };
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378 struct nfp_flower_ipv6 {
379 struct nfp_flower_ip_ext ip_ext;
380 __be32 ipv6_flow_label_exthdr;
381 struct in6_addr ipv6_src;
382 struct in6_addr ipv6_dst;
383 };
384
385 struct nfp_flower_tun_ipv4 {
386 __be32 src;
387 __be32 dst;
388 };
389
390 struct nfp_flower_tun_ip_ext {
391 u8 tos;
392 u8 ttl;
393 };
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411 struct nfp_flower_ipv4_udp_tun {
412 struct nfp_flower_tun_ipv4 ipv4;
413 __be16 reserved1;
414 struct nfp_flower_tun_ip_ext ip_ext;
415 __be32 reserved2;
416 __be32 tun_id;
417 };
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438 struct nfp_flower_ipv4_gre_tun {
439 struct nfp_flower_tun_ipv4 ipv4;
440 __be16 tun_flags;
441 struct nfp_flower_tun_ip_ext ip_ext;
442 __be16 reserved1;
443 __be16 ethertype;
444 __be32 tun_key;
445 __be32 reserved2;
446 };
447
448 struct nfp_flower_geneve_options {
449 u8 data[NFP_FL_MAX_GENEVE_OPT_KEY];
450 };
451
452 #define NFP_FL_TUN_VNI_OFFSET 8
453
454
455
456
457
458 struct nfp_flower_cmsg_hdr {
459 __be16 pad;
460 u8 type;
461 u8 version;
462 };
463
464 #define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr)
465 #define NFP_FLOWER_CMSG_VER1 1
466
467
468 enum nfp_flower_cmsg_type_port {
469 NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0,
470 NFP_FLOWER_CMSG_TYPE_FLOW_MOD = 1,
471 NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2,
472 NFP_FLOWER_CMSG_TYPE_LAG_CONFIG = 4,
473 NFP_FLOWER_CMSG_TYPE_PORT_REIFY = 6,
474 NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7,
475 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
476 NFP_FLOWER_CMSG_TYPE_MERGE_HINT = 9,
477 NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10,
478 NFP_FLOWER_CMSG_TYPE_TUN_MAC = 11,
479 NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS = 12,
480 NFP_FLOWER_CMSG_TYPE_TUN_NEIGH = 13,
481 NFP_FLOWER_CMSG_TYPE_TUN_IPS = 14,
482 NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15,
483 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16,
484 NFP_FLOWER_CMSG_TYPE_QOS_MOD = 18,
485 NFP_FLOWER_CMSG_TYPE_QOS_DEL = 19,
486 NFP_FLOWER_CMSG_TYPE_QOS_STATS = 20,
487 NFP_FLOWER_CMSG_TYPE_PRE_TUN_RULE = 21,
488 NFP_FLOWER_CMSG_TYPE_MAX = 32,
489 };
490
491
492 struct nfp_flower_cmsg_mac_repr {
493 u8 reserved[3];
494 u8 num_ports;
495 struct {
496 u8 idx;
497 u8 info;
498 u8 nbi_port;
499 u8 phys_port;
500 } ports[0];
501 };
502
503 #define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0)
504
505
506 struct nfp_flower_cmsg_portmod {
507 __be32 portnum;
508 u8 reserved;
509 u8 info;
510 __be16 mtu;
511 };
512
513 #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
514 #define NFP_FLOWER_CMSG_PORTMOD_MTU_CHANGE_ONLY BIT(1)
515
516
517 struct nfp_flower_cmsg_portreify {
518 __be32 portnum;
519 u16 reserved;
520 __be16 info;
521 };
522
523 #define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST BIT(0)
524
525
526 struct nfp_flower_cmsg_merge_hint {
527 u8 reserved[3];
528 u8 count;
529 struct {
530 __be32 host_ctx;
531 __be64 host_cookie;
532 } __packed flow[0];
533 };
534
535 enum nfp_flower_cmsg_port_type {
536 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
537 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
538 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2,
539 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT = 0x3,
540 };
541
542 enum nfp_flower_cmsg_port_vnic_type {
543 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0,
544 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1,
545 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2,
546 };
547
548 #define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28)
549 #define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24)
550 #define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22)
551 #define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14)
552 #define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12)
553 #define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6)
554 #define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0)
555 #define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0)
556
557 static inline u32 nfp_flower_internal_port_get_port_id(u8 internal_port)
558 {
559 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, internal_port) |
560 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
561 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT);
562 }
563
564 static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
565 {
566 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
567 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
568 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
569 }
570
571 static inline u32
572 nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
573 u8 vnic, u8 q)
574 {
575 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
576 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
577 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
578 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
579 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
580 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
581 }
582
583 static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)
584 {
585 return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;
586 }
587
588 static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)
589 {
590 return skb->len - NFP_FLOWER_CMSG_HLEN;
591 }
592
593 static inline bool
594 nfp_fl_netdev_is_tunnel_type(struct net_device *netdev,
595 enum nfp_flower_tun_type tun_type)
596 {
597 if (netif_is_vxlan(netdev))
598 return tun_type == NFP_FL_TUNNEL_VXLAN;
599 if (netif_is_gretap(netdev))
600 return tun_type == NFP_FL_TUNNEL_GRE;
601 if (netif_is_geneve(netdev))
602 return tun_type == NFP_FL_TUNNEL_GENEVE;
603
604 return false;
605 }
606
607 static inline bool nfp_fl_is_netdev_to_offload(struct net_device *netdev)
608 {
609 if (!netdev->rtnl_link_ops)
610 return false;
611 if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))
612 return true;
613 if (netif_is_vxlan(netdev))
614 return true;
615 if (netif_is_geneve(netdev))
616 return true;
617 if (netif_is_gretap(netdev))
618 return true;
619
620 return false;
621 }
622
623 struct sk_buff *
624 nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
625 void
626 nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
627 unsigned int nbi, unsigned int nbi_port,
628 unsigned int phys_port);
629 int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok,
630 unsigned int mtu, bool mtu_only);
631 int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists);
632 void nfp_flower_cmsg_process_rx(struct work_struct *work);
633 void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
634 struct sk_buff *
635 nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,
636 enum nfp_flower_cmsg_type_port type, gfp_t flag);
637
638 #endif