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