1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2017-2018 Netronome Systems, Inc. */
4 #ifndef NFP_FLOWER_CMSG_H
5 #define NFP_FLOWER_CMSG_H
7 #include <linux/bitfield.h>
8 #include <linux/skbuff.h>
9 #include <linux/types.h>
10 #include <net/geneve.h>
11 #include <net/vxlan.h>
13 #include "../nfp_app.h"
14 #include "../nfpcore/nfp_cpp.h"
16 #define NFP_FLOWER_LAYER_EXT_META BIT(0)
17 #define NFP_FLOWER_LAYER_PORT BIT(1)
18 #define NFP_FLOWER_LAYER_MAC BIT(2)
19 #define NFP_FLOWER_LAYER_TP BIT(3)
20 #define NFP_FLOWER_LAYER_IPV4 BIT(4)
21 #define NFP_FLOWER_LAYER_IPV6 BIT(5)
22 #define NFP_FLOWER_LAYER_CT BIT(6)
23 #define NFP_FLOWER_LAYER_VXLAN BIT(7)
25 #define NFP_FLOWER_LAYER2_GENEVE BIT(5)
26 #define NFP_FLOWER_LAYER2_GENEVE_OP BIT(6)
28 #define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13)
29 #define NFP_FLOWER_MASK_VLAN_PRESENT BIT(12)
30 #define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0)
32 #define NFP_FLOWER_MASK_MPLS_LB GENMASK(31, 12)
33 #define NFP_FLOWER_MASK_MPLS_TC GENMASK(11, 9)
34 #define NFP_FLOWER_MASK_MPLS_BOS BIT(8)
35 #define NFP_FLOWER_MASK_MPLS_Q BIT(0)
37 #define NFP_FL_IP_FRAG_FIRST BIT(7)
38 #define NFP_FL_IP_FRAGMENTED BIT(6)
40 /* Compressed HW representation of TCP Flags */
41 #define NFP_FL_TCP_FLAG_URG BIT(4)
42 #define NFP_FL_TCP_FLAG_PSH BIT(3)
43 #define NFP_FL_TCP_FLAG_RST BIT(2)
44 #define NFP_FL_TCP_FLAG_SYN BIT(1)
45 #define NFP_FL_TCP_FLAG_FIN BIT(0)
47 #define NFP_FL_SC_ACT_DROP 0x80000000
48 #define NFP_FL_SC_ACT_USER 0x7D000000
49 #define NFP_FL_SC_ACT_POPV 0x6A000000
50 #define NFP_FL_SC_ACT_NULL 0x00000000
52 /* The maximum action list size (in bytes) supported by the NFP.
54 #define NFP_FL_MAX_A_SIZ 1216
55 #define NFP_FL_LW_SIZ 2
57 /* Maximum allowed geneve options */
58 #define NFP_FL_MAX_GENEVE_OPT_ACT 32
59 #define NFP_FL_MAX_GENEVE_OPT_CNT 64
60 #define NFP_FL_MAX_GENEVE_OPT_KEY 32
63 #define NFP_FL_ACTION_OPCODE_OUTPUT 0
64 #define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1
65 #define NFP_FL_ACTION_OPCODE_POP_VLAN 2
66 #define NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL 6
67 #define NFP_FL_ACTION_OPCODE_SET_ETHERNET 7
68 #define NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS 9
69 #define NFP_FL_ACTION_OPCODE_SET_IPV4_TTL_TOS 10
70 #define NFP_FL_ACTION_OPCODE_SET_IPV6_SRC 11
71 #define NFP_FL_ACTION_OPCODE_SET_IPV6_DST 12
72 #define NFP_FL_ACTION_OPCODE_SET_IPV6_TC_HL_FL 13
73 #define NFP_FL_ACTION_OPCODE_SET_UDP 14
74 #define NFP_FL_ACTION_OPCODE_SET_TCP 15
75 #define NFP_FL_ACTION_OPCODE_PRE_LAG 16
76 #define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17
77 #define NFP_FL_ACTION_OPCODE_PUSH_GENEVE 26
78 #define NFP_FL_ACTION_OPCODE_NUM 32
80 #define NFP_FL_OUT_FLAGS_LAST BIT(15)
81 #define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
82 #define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
84 #define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13)
85 #define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0)
87 #define IPV6_FLOW_LABEL_MASK cpu_to_be32(0x000fffff)
90 #define NFP_FL_LAG_OUT 0xC0DE0000
93 #define NFP_FL_PORT_TYPE_TUN 0x50000000
94 #define NFP_FL_IPV4_TUNNEL_TYPE GENMASK(7, 4)
95 #define NFP_FL_IPV4_PRE_TUN_INDEX GENMASK(2, 0)
97 #define NFP_FLOWER_WORKQ_MAX_SKBS 30000
99 /* Cmesg reply (empirical) timeout*/
100 #define NFP_FL_REPLY_TIMEOUT msecs_to_jiffies(40)
102 #define nfp_flower_cmsg_warn(app, fmt, args...) \
104 if (net_ratelimit()) \
105 nfp_warn((app)->cpp, fmt, ## args); \
108 enum nfp_flower_tun_type {
109 NFP_FL_TUNNEL_NONE = 0,
110 NFP_FL_TUNNEL_VXLAN = 2,
111 NFP_FL_TUNNEL_GENEVE = 4,
114 struct nfp_fl_act_head {
119 struct nfp_fl_set_eth {
120 struct nfp_fl_act_head head;
122 u8 eth_addr_mask[ETH_ALEN * 2];
123 u8 eth_addr_val[ETH_ALEN * 2];
126 struct nfp_fl_set_ip4_addrs {
127 struct nfp_fl_act_head head;
129 __be32 ipv4_src_mask;
131 __be32 ipv4_dst_mask;
135 struct nfp_fl_set_ip4_ttl_tos {
136 struct nfp_fl_act_head head;
144 struct nfp_fl_set_ipv6_tc_hl_fl {
145 struct nfp_fl_act_head head;
147 u8 ipv6_hop_limit_mask;
151 __be32 ipv6_label_mask;
155 struct nfp_fl_set_ipv6_addr {
156 struct nfp_fl_act_head head;
164 struct nfp_fl_set_tport {
165 struct nfp_fl_act_head head;
171 struct nfp_fl_output {
172 struct nfp_fl_act_head head;
177 struct nfp_fl_push_vlan {
178 struct nfp_fl_act_head head;
184 struct nfp_fl_pop_vlan {
185 struct nfp_fl_act_head head;
189 struct nfp_fl_pre_lag {
190 struct nfp_fl_act_head head;
196 #define NFP_FL_PRE_LAG_VER_OFF 8
198 struct nfp_fl_pre_tunnel {
199 struct nfp_fl_act_head head;
202 /* reserved for use with IPv6 addresses */
206 struct nfp_fl_set_ipv4_udp_tun {
207 struct nfp_fl_act_head head;
209 __be64 tun_id __packed;
210 __be32 tun_type_index;
220 struct nfp_fl_push_geneve {
221 struct nfp_fl_act_head head;
229 /* Metadata with L2 (1W/4B)
230 * ----------------------------------------------------------------
232 * 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
233 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
234 * | key_type | mask_id | PCP |p| vlan outermost VID |
235 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
238 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240 struct nfp_flower_meta_tci {
241 u8 nfp_flow_key_layer;
246 /* Extended metadata for additional key_layers (1W/4B)
247 * ----------------------------------------------------------------
249 * 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
250 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
251 * | nfp_flow_key_layer2 |
252 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
254 struct nfp_flower_ext_meta {
255 __be32 nfp_flow_key_layer2;
258 /* Port details (1W/4B)
259 * ----------------------------------------------------------------
261 * 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
262 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
264 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
266 struct nfp_flower_in_port {
270 /* L2 details (4W/16B)
272 * 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
273 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
274 * | mac_addr_dst, 31 - 0 |
275 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
276 * | mac_addr_dst, 47 - 32 | mac_addr_src, 15 - 0 |
277 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
278 * | mac_addr_src, 47 - 16 |
279 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
280 * | mpls outermost label | TC |B| reserved |q|
281 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
283 struct nfp_flower_mac_mpls {
289 /* L4 ports (for UDP, TCP, SCTP) (1W/4B)
291 * 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
292 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
293 * | port_src | port_dst |
294 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
296 struct nfp_flower_tp_ports {
301 struct nfp_flower_ip_ext {
308 /* L3 IPv4 details (3W/12B)
310 * 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
311 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
312 * | DSCP |ECN| protocol | ttl | flags |
313 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
315 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
317 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
319 struct nfp_flower_ipv4 {
320 struct nfp_flower_ip_ext ip_ext;
325 /* L3 IPv6 details (10W/40B)
327 * 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
328 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
329 * | DSCP |ECN| protocol | ttl | flags |
330 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
331 * | ipv6_exthdr | res | ipv6_flow_label |
332 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
333 * | ipv6_addr_src, 31 - 0 |
334 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
335 * | ipv6_addr_src, 63 - 32 |
336 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
337 * | ipv6_addr_src, 95 - 64 |
338 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
339 * | ipv6_addr_src, 127 - 96 |
340 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
341 * | ipv6_addr_dst, 31 - 0 |
342 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
343 * | ipv6_addr_dst, 63 - 32 |
344 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
345 * | ipv6_addr_dst, 95 - 64 |
346 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
347 * | ipv6_addr_dst, 127 - 96 |
348 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
350 struct nfp_flower_ipv6 {
351 struct nfp_flower_ip_ext ip_ext;
352 __be32 ipv6_flow_label_exthdr;
353 struct in6_addr ipv6_src;
354 struct in6_addr ipv6_dst;
357 /* Flow Frame IPv4 UDP TUNNEL --> Tunnel details (4W/16B)
358 * -----------------------------------------------------------------
360 * 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
361 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
363 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
365 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
366 * | Reserved | tos | ttl |
367 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
369 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
371 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
373 struct nfp_flower_ipv4_udp_tun {
383 struct nfp_flower_geneve_options {
384 u8 data[NFP_FL_MAX_GENEVE_OPT_KEY];
387 #define NFP_FL_TUN_VNI_OFFSET 8
389 /* The base header for a control message packet.
390 * Defines an 8-bit version, and an 8-bit type, padded
391 * to a 32-bit word. Rest of the packet is type-specific.
393 struct nfp_flower_cmsg_hdr {
399 #define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr)
400 #define NFP_FLOWER_CMSG_VER1 1
402 /* Types defined for port related control messages */
403 enum nfp_flower_cmsg_type_port {
404 NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0,
405 NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2,
406 NFP_FLOWER_CMSG_TYPE_LAG_CONFIG = 4,
407 NFP_FLOWER_CMSG_TYPE_PORT_REIFY = 6,
408 NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7,
409 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
410 NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10,
411 NFP_FLOWER_CMSG_TYPE_TUN_MAC = 11,
412 NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS = 12,
413 NFP_FLOWER_CMSG_TYPE_TUN_NEIGH = 13,
414 NFP_FLOWER_CMSG_TYPE_TUN_IPS = 14,
415 NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15,
416 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16,
417 NFP_FLOWER_CMSG_TYPE_MAX = 32,
420 /* NFP_FLOWER_CMSG_TYPE_MAC_REPR */
421 struct nfp_flower_cmsg_mac_repr {
432 #define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0)
434 /* NFP_FLOWER_CMSG_TYPE_PORT_MOD */
435 struct nfp_flower_cmsg_portmod {
442 #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
443 #define NFP_FLOWER_CMSG_PORTMOD_MTU_CHANGE_ONLY BIT(1)
445 /* NFP_FLOWER_CMSG_TYPE_PORT_REIFY */
446 struct nfp_flower_cmsg_portreify {
452 #define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST BIT(0)
454 enum nfp_flower_cmsg_port_type {
455 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
456 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
457 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2,
458 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT = 0x3,
461 enum nfp_flower_cmsg_port_vnic_type {
462 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0,
463 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1,
464 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2,
467 #define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28)
468 #define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24)
469 #define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22)
470 #define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14)
471 #define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12)
472 #define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6)
473 #define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0)
474 #define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0)
476 static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
478 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
479 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
480 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
484 nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
487 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
488 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
489 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
490 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
491 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
492 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
495 static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)
497 return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;
500 static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)
502 return skb->len - NFP_FLOWER_CMSG_HLEN;
506 nfp_fl_netdev_is_tunnel_type(struct net_device *netdev,
507 enum nfp_flower_tun_type tun_type)
509 if (netif_is_vxlan(netdev))
510 return tun_type == NFP_FL_TUNNEL_VXLAN;
511 if (netif_is_geneve(netdev))
512 return tun_type == NFP_FL_TUNNEL_GENEVE;
517 static inline bool nfp_fl_is_netdev_to_offload(struct net_device *netdev)
519 if (!netdev->rtnl_link_ops)
521 if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))
523 if (netif_is_vxlan(netdev))
525 if (netif_is_geneve(netdev))
532 nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
534 nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
535 unsigned int nbi, unsigned int nbi_port,
536 unsigned int phys_port);
537 int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok,
538 unsigned int mtu, bool mtu_only);
539 int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists);
540 void nfp_flower_cmsg_process_rx(struct work_struct *work);
541 void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
543 nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,
544 enum nfp_flower_cmsg_type_port type, gfp_t flag);