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#define NFP_FLOWER_LAYER2_TUN_IPV6 BIT(7)
30
31#define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13)
32#define NFP_FLOWER_MASK_VLAN_PRESENT BIT(12)
33#define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0)
34
35#define NFP_FLOWER_MASK_MPLS_LB GENMASK(31, 12)
36#define NFP_FLOWER_MASK_MPLS_TC GENMASK(11, 9)
37#define NFP_FLOWER_MASK_MPLS_BOS BIT(8)
38#define NFP_FLOWER_MASK_MPLS_Q BIT(0)
39
40#define NFP_FL_IP_FRAG_FIRST BIT(7)
41#define NFP_FL_IP_FRAGMENTED BIT(6)
42
43
44#define NFP_FL_GRE_FLAG_KEY BIT(2)
45
46
47#define NFP_FL_TCP_FLAG_URG BIT(4)
48#define NFP_FL_TCP_FLAG_PSH BIT(3)
49#define NFP_FL_TCP_FLAG_RST BIT(2)
50#define NFP_FL_TCP_FLAG_SYN BIT(1)
51#define NFP_FL_TCP_FLAG_FIN BIT(0)
52
53#define NFP_FL_SC_ACT_DROP 0x80000000
54#define NFP_FL_SC_ACT_USER 0x7D000000
55#define NFP_FL_SC_ACT_POPV 0x6A000000
56#define NFP_FL_SC_ACT_NULL 0x00000000
57
58
59
60#define NFP_FL_MAX_A_SIZ 1216
61#define NFP_FL_LW_SIZ 2
62
63
64#define NFP_FL_MAX_GENEVE_OPT_ACT 32
65#define NFP_FL_MAX_GENEVE_OPT_CNT 64
66#define NFP_FL_MAX_GENEVE_OPT_KEY 32
67#define NFP_FL_MAX_GENEVE_OPT_KEY_V6 8
68
69
70#define NFP_FL_ACTION_OPCODE_OUTPUT 0
71#define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1
72#define NFP_FL_ACTION_OPCODE_POP_VLAN 2
73#define NFP_FL_ACTION_OPCODE_PUSH_MPLS 3
74#define NFP_FL_ACTION_OPCODE_POP_MPLS 4
75#define NFP_FL_ACTION_OPCODE_SET_TUNNEL 6
76#define NFP_FL_ACTION_OPCODE_SET_ETHERNET 7
77#define NFP_FL_ACTION_OPCODE_SET_MPLS 8
78#define NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS 9
79#define NFP_FL_ACTION_OPCODE_SET_IPV4_TTL_TOS 10
80#define NFP_FL_ACTION_OPCODE_SET_IPV6_SRC 11
81#define NFP_FL_ACTION_OPCODE_SET_IPV6_DST 12
82#define NFP_FL_ACTION_OPCODE_SET_IPV6_TC_HL_FL 13
83#define NFP_FL_ACTION_OPCODE_SET_UDP 14
84#define NFP_FL_ACTION_OPCODE_SET_TCP 15
85#define NFP_FL_ACTION_OPCODE_PRE_LAG 16
86#define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17
87#define NFP_FL_ACTION_OPCODE_PUSH_GENEVE 26
88#define NFP_FL_ACTION_OPCODE_NUM 32
89
90#define NFP_FL_OUT_FLAGS_LAST BIT(15)
91#define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
92#define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
93
94#define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13)
95#define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0)
96
97#define IPV6_FLOW_LABEL_MASK cpu_to_be32(0x000fffff)
98
99
100#define NFP_FL_LAG_OUT 0xC0DE0000
101
102
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
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
118enum 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
125struct nfp_fl_act_head {
126 u8 jump_id;
127 u8 len_lw;
128};
129
130struct 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
137struct 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
146struct 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
155struct 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
166struct 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
175struct 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
182struct nfp_fl_output {
183 struct nfp_fl_act_head head;
184 __be16 flags;
185 __be32 port;
186};
187
188struct nfp_fl_push_vlan {
189 struct nfp_fl_act_head head;
190 __be16 reserved;
191 __be16 vlan_tpid;
192 __be16 vlan_tci;
193};
194
195struct nfp_fl_pop_vlan {
196 struct nfp_fl_act_head head;
197 __be16 reserved;
198};
199
200struct 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
209struct 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
220struct 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
235struct 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
244struct nfp_fl_push_mpls {
245 struct nfp_fl_act_head head;
246 __be16 ethtype;
247 __be32 lse;
248};
249
250struct nfp_fl_pop_mpls {
251 struct nfp_fl_act_head head;
252 __be16 ethtype;
253};
254
255struct nfp_fl_set_mpls {
256 struct nfp_fl_act_head head;
257 __be16 reserved;
258 __be32 lse_mask;
259 __be32 lse;
260};
261
262
263
264
265
266
267
268
269
270
271
272
273struct nfp_flower_meta_tci {
274 u8 nfp_flow_key_layer;
275 u8 mask_id;
276 __be16 tci;
277};
278
279
280
281
282
283
284
285
286
287struct nfp_flower_ext_meta {
288 __be32 nfp_flow_key_layer2;
289};
290
291
292
293
294
295
296
297
298
299struct nfp_flower_in_port {
300 __be32 in_port;
301};
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316struct nfp_flower_mac_mpls {
317 u8 mac_dst[6];
318 u8 mac_src[6];
319 __be32 mpls_lse;
320};
321
322
323
324
325
326
327
328
329struct nfp_flower_tp_ports {
330 __be16 port_src;
331 __be16 port_dst;
332};
333
334struct nfp_flower_ip_ext {
335 u8 tos;
336 u8 proto;
337 u8 ttl;
338 u8 flags;
339};
340
341
342
343
344
345
346
347
348
349
350
351
352struct nfp_flower_ipv4 {
353 struct nfp_flower_ip_ext ip_ext;
354 __be32 ipv4_src;
355 __be32 ipv4_dst;
356};
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383struct nfp_flower_ipv6 {
384 struct nfp_flower_ip_ext ip_ext;
385 __be32 ipv6_flow_label_exthdr;
386 struct in6_addr ipv6_src;
387 struct in6_addr ipv6_dst;
388};
389
390struct nfp_flower_tun_ipv4 {
391 __be32 src;
392 __be32 dst;
393};
394
395struct nfp_flower_tun_ipv6 {
396 struct in6_addr src;
397 struct in6_addr dst;
398};
399
400struct nfp_flower_tun_ip_ext {
401 u8 tos;
402 u8 ttl;
403};
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421struct nfp_flower_ipv4_udp_tun {
422 struct nfp_flower_tun_ipv4 ipv4;
423 __be16 reserved1;
424 struct nfp_flower_tun_ip_ext ip_ext;
425 __be32 reserved2;
426 __be32 tun_id;
427};
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457struct nfp_flower_ipv6_udp_tun {
458 struct nfp_flower_tun_ipv6 ipv6;
459 __be16 reserved1;
460 struct nfp_flower_tun_ip_ext ip_ext;
461 __be32 reserved2;
462 __be32 tun_id;
463};
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484struct nfp_flower_ipv4_gre_tun {
485 struct nfp_flower_tun_ipv4 ipv4;
486 __be16 tun_flags;
487 struct nfp_flower_tun_ip_ext ip_ext;
488 __be16 reserved1;
489 __be16 ethertype;
490 __be32 tun_key;
491 __be32 reserved2;
492};
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524struct nfp_flower_ipv6_gre_tun {
525 struct nfp_flower_tun_ipv6 ipv6;
526 __be16 tun_flags;
527 struct nfp_flower_tun_ip_ext ip_ext;
528 __be16 reserved1;
529 __be16 ethertype;
530 __be32 tun_key;
531 __be32 reserved2;
532};
533
534struct nfp_flower_geneve_options {
535 u8 data[NFP_FL_MAX_GENEVE_OPT_KEY];
536};
537
538#define NFP_FL_TUN_VNI_OFFSET 8
539
540
541
542
543
544struct nfp_flower_cmsg_hdr {
545 __be16 pad;
546 u8 type;
547 u8 version;
548};
549
550#define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr)
551#define NFP_FLOWER_CMSG_VER1 1
552
553
554enum nfp_flower_cmsg_type_port {
555 NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0,
556 NFP_FLOWER_CMSG_TYPE_FLOW_MOD = 1,
557 NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2,
558 NFP_FLOWER_CMSG_TYPE_LAG_CONFIG = 4,
559 NFP_FLOWER_CMSG_TYPE_PORT_REIFY = 6,
560 NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7,
561 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
562 NFP_FLOWER_CMSG_TYPE_MERGE_HINT = 9,
563 NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10,
564 NFP_FLOWER_CMSG_TYPE_TUN_MAC = 11,
565 NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS = 12,
566 NFP_FLOWER_CMSG_TYPE_TUN_NEIGH = 13,
567 NFP_FLOWER_CMSG_TYPE_TUN_IPS = 14,
568 NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15,
569 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16,
570 NFP_FLOWER_CMSG_TYPE_QOS_MOD = 18,
571 NFP_FLOWER_CMSG_TYPE_QOS_DEL = 19,
572 NFP_FLOWER_CMSG_TYPE_QOS_STATS = 20,
573 NFP_FLOWER_CMSG_TYPE_PRE_TUN_RULE = 21,
574 NFP_FLOWER_CMSG_TYPE_TUN_IPS_V6 = 22,
575 NFP_FLOWER_CMSG_TYPE_NO_NEIGH_V6 = 23,
576 NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V6 = 24,
577 NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS_V6 = 25,
578 NFP_FLOWER_CMSG_TYPE_MAX = 32,
579};
580
581
582struct nfp_flower_cmsg_mac_repr {
583 u8 reserved[3];
584 u8 num_ports;
585 struct {
586 u8 idx;
587 u8 info;
588 u8 nbi_port;
589 u8 phys_port;
590 } ports[];
591};
592
593#define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0)
594
595
596struct nfp_flower_cmsg_portmod {
597 __be32 portnum;
598 u8 reserved;
599 u8 info;
600 __be16 mtu;
601};
602
603#define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
604#define NFP_FLOWER_CMSG_PORTMOD_MTU_CHANGE_ONLY BIT(1)
605
606
607struct nfp_flower_cmsg_portreify {
608 __be32 portnum;
609 u16 reserved;
610 __be16 info;
611};
612
613#define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST BIT(0)
614
615
616struct nfp_flower_cmsg_merge_hint {
617 u8 reserved[3];
618 u8 count;
619 struct {
620 __be32 host_ctx;
621 __be64 host_cookie;
622 } __packed flow[];
623};
624
625enum nfp_flower_cmsg_port_type {
626 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
627 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
628 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2,
629 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT = 0x3,
630};
631
632enum nfp_flower_cmsg_port_vnic_type {
633 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0,
634 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1,
635 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2,
636};
637
638#define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28)
639#define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24)
640#define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22)
641#define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14)
642#define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12)
643#define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6)
644#define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0)
645#define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0)
646
647static inline u32 nfp_flower_internal_port_get_port_id(u8 internal_port)
648{
649 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, internal_port) |
650 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
651 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT);
652}
653
654static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
655{
656 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
657 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
658 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
659}
660
661static inline u32
662nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
663 u8 vnic, u8 q)
664{
665 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
666 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
667 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
668 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
669 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
670 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
671}
672
673static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)
674{
675 return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;
676}
677
678static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)
679{
680 return skb->len - NFP_FLOWER_CMSG_HLEN;
681}
682
683static inline bool
684nfp_fl_netdev_is_tunnel_type(struct net_device *netdev,
685 enum nfp_flower_tun_type tun_type)
686{
687 if (netif_is_vxlan(netdev))
688 return tun_type == NFP_FL_TUNNEL_VXLAN;
689 if (netif_is_gretap(netdev))
690 return tun_type == NFP_FL_TUNNEL_GRE;
691 if (netif_is_geneve(netdev))
692 return tun_type == NFP_FL_TUNNEL_GENEVE;
693
694 return false;
695}
696
697static inline bool nfp_fl_is_netdev_to_offload(struct net_device *netdev)
698{
699 if (!netdev->rtnl_link_ops)
700 return false;
701 if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))
702 return true;
703 if (netif_is_vxlan(netdev))
704 return true;
705 if (netif_is_geneve(netdev))
706 return true;
707 if (netif_is_gretap(netdev))
708 return true;
709
710 return false;
711}
712
713struct sk_buff *
714nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
715void
716nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
717 unsigned int nbi, unsigned int nbi_port,
718 unsigned int phys_port);
719int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok,
720 unsigned int mtu, bool mtu_only);
721int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists);
722void nfp_flower_cmsg_process_rx(struct work_struct *work);
723void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
724struct sk_buff *
725nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,
726 enum nfp_flower_cmsg_type_port type, gfp_t flag);
727
728#endif
729