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_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
45#define NFP_FL_GRE_FLAG_KEY BIT(2)
46
47
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
60
61#define NFP_FL_MAX_A_SIZ 1216
62#define NFP_FL_LW_SIZ 2
63
64
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
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_PUSH_GENEVE 26
89#define NFP_FL_ACTION_OPCODE_NUM 32
90
91#define NFP_FL_OUT_FLAGS_LAST BIT(15)
92#define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
93#define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
94
95#define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13)
96#define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0)
97
98#define IPV6_FLOW_LABEL_MASK cpu_to_be32(0x000fffff)
99
100
101#define NFP_FL_LAG_OUT 0xC0DE0000
102
103
104#define NFP_FL_PORT_TYPE_TUN 0x50000000
105#define NFP_FL_TUNNEL_TYPE GENMASK(7, 4)
106#define NFP_FL_PRE_TUN_INDEX GENMASK(2, 0)
107
108#define NFP_FLOWER_WORKQ_MAX_SKBS 30000
109
110
111#define NFP_FL_REPLY_TIMEOUT msecs_to_jiffies(40)
112
113#define nfp_flower_cmsg_warn(app, fmt, args...) \
114 do { \
115 if (net_ratelimit()) \
116 nfp_warn((app)->cpp, fmt, ## args); \
117 } while (0)
118
119enum nfp_flower_tun_type {
120 NFP_FL_TUNNEL_NONE = 0,
121 NFP_FL_TUNNEL_GRE = 1,
122 NFP_FL_TUNNEL_VXLAN = 2,
123 NFP_FL_TUNNEL_GENEVE = 4,
124};
125
126struct nfp_fl_act_head {
127 u8 jump_id;
128 u8 len_lw;
129};
130
131struct nfp_fl_set_eth {
132 struct nfp_fl_act_head head;
133 __be16 reserved;
134 u8 eth_addr_mask[ETH_ALEN * 2];
135 u8 eth_addr_val[ETH_ALEN * 2];
136};
137
138struct nfp_fl_set_ip4_addrs {
139 struct nfp_fl_act_head head;
140 __be16 reserved;
141 __be32 ipv4_src_mask;
142 __be32 ipv4_src;
143 __be32 ipv4_dst_mask;
144 __be32 ipv4_dst;
145};
146
147struct nfp_fl_set_ip4_ttl_tos {
148 struct nfp_fl_act_head head;
149 u8 ipv4_ttl_mask;
150 u8 ipv4_tos_mask;
151 u8 ipv4_ttl;
152 u8 ipv4_tos;
153 __be16 reserved;
154};
155
156struct nfp_fl_set_ipv6_tc_hl_fl {
157 struct nfp_fl_act_head head;
158 u8 ipv6_tc_mask;
159 u8 ipv6_hop_limit_mask;
160 __be16 reserved;
161 u8 ipv6_tc;
162 u8 ipv6_hop_limit;
163 __be32 ipv6_label_mask;
164 __be32 ipv6_label;
165};
166
167struct nfp_fl_set_ipv6_addr {
168 struct nfp_fl_act_head head;
169 __be16 reserved;
170 struct {
171 __be32 mask;
172 __be32 exact;
173 } ipv6[4];
174};
175
176struct nfp_fl_set_tport {
177 struct nfp_fl_act_head head;
178 __be16 reserved;
179 u8 tp_port_mask[4];
180 u8 tp_port_val[4];
181};
182
183struct nfp_fl_output {
184 struct nfp_fl_act_head head;
185 __be16 flags;
186 __be32 port;
187};
188
189struct nfp_fl_push_vlan {
190 struct nfp_fl_act_head head;
191 __be16 reserved;
192 __be16 vlan_tpid;
193 __be16 vlan_tci;
194};
195
196struct nfp_fl_pop_vlan {
197 struct nfp_fl_act_head head;
198 __be16 reserved;
199};
200
201struct nfp_fl_pre_lag {
202 struct nfp_fl_act_head head;
203 __be16 group_id;
204 u8 lag_version[3];
205 u8 instance;
206};
207
208#define NFP_FL_PRE_LAG_VER_OFF 8
209
210struct nfp_fl_pre_tunnel {
211 struct nfp_fl_act_head head;
212 __be16 flags;
213 union {
214 __be32 ipv4_dst;
215 struct in6_addr ipv6_dst;
216 };
217};
218
219#define NFP_FL_PRE_TUN_IPV6 BIT(0)
220
221struct nfp_fl_set_tun {
222 struct nfp_fl_act_head head;
223 __be16 reserved;
224 __be64 tun_id __packed;
225 __be32 tun_type_index;
226 __be16 tun_flags;
227 u8 ttl;
228 u8 tos;
229 __be16 outer_vlan_tpid;
230 __be16 outer_vlan_tci;
231 u8 tun_len;
232 u8 res2;
233 __be16 tun_proto;
234};
235
236struct nfp_fl_push_geneve {
237 struct nfp_fl_act_head head;
238 __be16 reserved;
239 __be16 class;
240 u8 type;
241 u8 length;
242 u8 opt_data[];
243};
244
245struct nfp_fl_push_mpls {
246 struct nfp_fl_act_head head;
247 __be16 ethtype;
248 __be32 lse;
249};
250
251struct nfp_fl_pop_mpls {
252 struct nfp_fl_act_head head;
253 __be16 ethtype;
254};
255
256struct nfp_fl_set_mpls {
257 struct nfp_fl_act_head head;
258 __be16 reserved;
259 __be32 lse_mask;
260 __be32 lse;
261};
262
263
264
265
266
267
268
269
270
271
272
273
274struct nfp_flower_meta_tci {
275 u8 nfp_flow_key_layer;
276 u8 mask_id;
277 __be16 tci;
278};
279
280
281
282
283
284
285
286
287
288struct nfp_flower_ext_meta {
289 __be32 nfp_flow_key_layer2;
290};
291
292
293
294
295
296
297
298
299
300struct nfp_flower_in_port {
301 __be32 in_port;
302};
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317struct nfp_flower_mac_mpls {
318 u8 mac_dst[6];
319 u8 mac_src[6];
320 __be32 mpls_lse;
321};
322
323
324
325
326
327
328
329
330
331
332struct nfp_flower_vlan {
333 __be16 outer_tpid;
334 __be16 outer_tci;
335 __be16 inner_tpid;
336 __be16 inner_tci;
337};
338
339
340
341
342
343
344
345
346struct nfp_flower_tp_ports {
347 __be16 port_src;
348 __be16 port_dst;
349};
350
351struct nfp_flower_ip_ext {
352 u8 tos;
353 u8 proto;
354 u8 ttl;
355 u8 flags;
356};
357
358
359
360
361
362
363
364
365
366
367
368
369struct nfp_flower_ipv4 {
370 struct nfp_flower_ip_ext ip_ext;
371 __be32 ipv4_src;
372 __be32 ipv4_dst;
373};
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400struct nfp_flower_ipv6 {
401 struct nfp_flower_ip_ext ip_ext;
402 __be32 ipv6_flow_label_exthdr;
403 struct in6_addr ipv6_src;
404 struct in6_addr ipv6_dst;
405};
406
407struct nfp_flower_tun_ipv4 {
408 __be32 src;
409 __be32 dst;
410};
411
412struct nfp_flower_tun_ipv6 {
413 struct in6_addr src;
414 struct in6_addr dst;
415};
416
417struct nfp_flower_tun_ip_ext {
418 u8 tos;
419 u8 ttl;
420};
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438struct nfp_flower_ipv4_udp_tun {
439 struct nfp_flower_tun_ipv4 ipv4;
440 __be16 reserved1;
441 struct nfp_flower_tun_ip_ext ip_ext;
442 __be32 reserved2;
443 __be32 tun_id;
444};
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474struct nfp_flower_ipv6_udp_tun {
475 struct nfp_flower_tun_ipv6 ipv6;
476 __be16 reserved1;
477 struct nfp_flower_tun_ip_ext ip_ext;
478 __be32 reserved2;
479 __be32 tun_id;
480};
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501struct nfp_flower_ipv4_gre_tun {
502 struct nfp_flower_tun_ipv4 ipv4;
503 __be16 tun_flags;
504 struct nfp_flower_tun_ip_ext ip_ext;
505 __be16 reserved1;
506 __be16 ethertype;
507 __be32 tun_key;
508 __be32 reserved2;
509};
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541struct nfp_flower_ipv6_gre_tun {
542 struct nfp_flower_tun_ipv6 ipv6;
543 __be16 tun_flags;
544 struct nfp_flower_tun_ip_ext ip_ext;
545 __be16 reserved1;
546 __be16 ethertype;
547 __be32 tun_key;
548 __be32 reserved2;
549};
550
551struct nfp_flower_geneve_options {
552 u8 data[NFP_FL_MAX_GENEVE_OPT_KEY];
553};
554
555#define NFP_FL_TUN_VNI_OFFSET 8
556
557
558
559
560
561struct nfp_flower_cmsg_hdr {
562 __be16 pad;
563 u8 type;
564 u8 version;
565};
566
567#define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr)
568#define NFP_FLOWER_CMSG_VER1 1
569
570
571enum nfp_flower_cmsg_type_port {
572 NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0,
573 NFP_FLOWER_CMSG_TYPE_FLOW_MOD = 1,
574 NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2,
575 NFP_FLOWER_CMSG_TYPE_LAG_CONFIG = 4,
576 NFP_FLOWER_CMSG_TYPE_PORT_REIFY = 6,
577 NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7,
578 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
579 NFP_FLOWER_CMSG_TYPE_MERGE_HINT = 9,
580 NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10,
581 NFP_FLOWER_CMSG_TYPE_TUN_MAC = 11,
582 NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS = 12,
583 NFP_FLOWER_CMSG_TYPE_TUN_NEIGH = 13,
584 NFP_FLOWER_CMSG_TYPE_TUN_IPS = 14,
585 NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15,
586 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16,
587 NFP_FLOWER_CMSG_TYPE_QOS_MOD = 18,
588 NFP_FLOWER_CMSG_TYPE_QOS_DEL = 19,
589 NFP_FLOWER_CMSG_TYPE_QOS_STATS = 20,
590 NFP_FLOWER_CMSG_TYPE_PRE_TUN_RULE = 21,
591 NFP_FLOWER_CMSG_TYPE_TUN_IPS_V6 = 22,
592 NFP_FLOWER_CMSG_TYPE_NO_NEIGH_V6 = 23,
593 NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V6 = 24,
594 NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS_V6 = 25,
595 NFP_FLOWER_CMSG_TYPE_MAX = 32,
596};
597
598
599struct nfp_flower_cmsg_mac_repr {
600 u8 reserved[3];
601 u8 num_ports;
602 struct {
603 u8 idx;
604 u8 info;
605 u8 nbi_port;
606 u8 phys_port;
607 } ports[];
608};
609
610#define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0)
611
612
613struct nfp_flower_cmsg_portmod {
614 __be32 portnum;
615 u8 reserved;
616 u8 info;
617 __be16 mtu;
618};
619
620#define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
621#define NFP_FLOWER_CMSG_PORTMOD_MTU_CHANGE_ONLY BIT(1)
622
623
624struct nfp_flower_cmsg_portreify {
625 __be32 portnum;
626 u16 reserved;
627 __be16 info;
628};
629
630#define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST BIT(0)
631
632
633struct nfp_flower_cmsg_merge_hint {
634 u8 reserved[3];
635 u8 count;
636 struct {
637 __be32 host_ctx;
638 __be64 host_cookie;
639 } __packed flow[];
640};
641
642enum nfp_flower_cmsg_port_type {
643 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
644 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
645 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2,
646 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT = 0x3,
647};
648
649enum nfp_flower_cmsg_port_vnic_type {
650 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0,
651 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1,
652 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2,
653};
654
655#define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28)
656#define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24)
657#define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22)
658#define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14)
659#define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12)
660#define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6)
661#define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0)
662#define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0)
663
664static inline u32 nfp_flower_internal_port_get_port_id(u8 internal_port)
665{
666 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, internal_port) |
667 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
668 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT);
669}
670
671static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
672{
673 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
674 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
675 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
676}
677
678static inline u32
679nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
680 u8 vnic, u8 q)
681{
682 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
683 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
684 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
685 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
686 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
687 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
688}
689
690static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)
691{
692 return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;
693}
694
695static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)
696{
697 return skb->len - NFP_FLOWER_CMSG_HLEN;
698}
699
700static inline bool
701nfp_fl_netdev_is_tunnel_type(struct net_device *netdev,
702 enum nfp_flower_tun_type tun_type)
703{
704 if (netif_is_vxlan(netdev))
705 return tun_type == NFP_FL_TUNNEL_VXLAN;
706 if (netif_is_gretap(netdev))
707 return tun_type == NFP_FL_TUNNEL_GRE;
708 if (netif_is_geneve(netdev))
709 return tun_type == NFP_FL_TUNNEL_GENEVE;
710
711 return false;
712}
713
714static inline bool nfp_fl_is_netdev_to_offload(struct net_device *netdev)
715{
716 if (!netdev->rtnl_link_ops)
717 return false;
718 if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))
719 return true;
720 if (netif_is_vxlan(netdev))
721 return true;
722 if (netif_is_geneve(netdev))
723 return true;
724 if (netif_is_gretap(netdev))
725 return true;
726
727 return false;
728}
729
730struct sk_buff *
731nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
732void
733nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
734 unsigned int nbi, unsigned int nbi_port,
735 unsigned int phys_port);
736int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok,
737 unsigned int mtu, bool mtu_only);
738int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists);
739void nfp_flower_cmsg_process_rx(struct work_struct *work);
740void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
741struct sk_buff *
742nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,
743 enum nfp_flower_cmsg_type_port type, gfp_t flag);
744
745#endif
746