2 * Copyright (C) 2017 Netronome Systems, Inc.
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
9 * The BSD 2-Clause License:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #ifndef NFP_FLOWER_CMSG_H
35 #define NFP_FLOWER_CMSG_H
37 #include <linux/bitfield.h>
38 #include <linux/skbuff.h>
39 #include <linux/types.h>
41 #include "../nfp_app.h"
42 #include "../nfpcore/nfp_cpp.h"
44 #define NFP_FLOWER_LAYER_EXT_META BIT(0)
45 #define NFP_FLOWER_LAYER_PORT BIT(1)
46 #define NFP_FLOWER_LAYER_MAC BIT(2)
47 #define NFP_FLOWER_LAYER_TP BIT(3)
48 #define NFP_FLOWER_LAYER_IPV4 BIT(4)
49 #define NFP_FLOWER_LAYER_IPV6 BIT(5)
50 #define NFP_FLOWER_LAYER_CT BIT(6)
51 #define NFP_FLOWER_LAYER_VXLAN BIT(7)
53 #define NFP_FLOWER_LAYER2_GENEVE BIT(5)
55 #define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13)
56 #define NFP_FLOWER_MASK_VLAN_CFI BIT(12)
57 #define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0)
59 #define NFP_FLOWER_MASK_MPLS_LB GENMASK(31, 12)
60 #define NFP_FLOWER_MASK_MPLS_TC GENMASK(11, 9)
61 #define NFP_FLOWER_MASK_MPLS_BOS BIT(8)
62 #define NFP_FLOWER_MASK_MPLS_Q BIT(0)
64 #define NFP_FL_IP_FRAG_FIRST BIT(7)
65 #define NFP_FL_IP_FRAGMENTED BIT(6)
67 /* Compressed HW representation of TCP Flags */
68 #define NFP_FL_TCP_FLAG_URG BIT(4)
69 #define NFP_FL_TCP_FLAG_PSH BIT(3)
70 #define NFP_FL_TCP_FLAG_RST BIT(2)
71 #define NFP_FL_TCP_FLAG_SYN BIT(1)
72 #define NFP_FL_TCP_FLAG_FIN BIT(0)
74 #define NFP_FL_SC_ACT_DROP 0x80000000
75 #define NFP_FL_SC_ACT_USER 0x7D000000
76 #define NFP_FL_SC_ACT_POPV 0x6A000000
77 #define NFP_FL_SC_ACT_NULL 0x00000000
79 /* The maximum action list size (in bytes) supported by the NFP.
81 #define NFP_FL_MAX_A_SIZ 1216
82 #define NFP_FL_LW_SIZ 2
85 #define NFP_FL_ACTION_OPCODE_OUTPUT 0
86 #define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1
87 #define NFP_FL_ACTION_OPCODE_POP_VLAN 2
88 #define NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL 6
89 #define NFP_FL_ACTION_OPCODE_SET_ETHERNET 7
90 #define NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS 9
91 #define NFP_FL_ACTION_OPCODE_SET_IPV6_SRC 11
92 #define NFP_FL_ACTION_OPCODE_SET_IPV6_DST 12
93 #define NFP_FL_ACTION_OPCODE_SET_UDP 14
94 #define NFP_FL_ACTION_OPCODE_SET_TCP 15
95 #define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17
96 #define NFP_FL_ACTION_OPCODE_NUM 32
98 #define NFP_FL_OUT_FLAGS_LAST BIT(15)
99 #define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
100 #define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
102 #define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13)
103 #define NFP_FL_PUSH_VLAN_CFI BIT(12)
104 #define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0)
107 #define NFP_FL_PORT_TYPE_TUN 0x50000000
108 #define NFP_FL_IPV4_TUNNEL_TYPE GENMASK(7, 4)
109 #define NFP_FL_IPV4_PRE_TUN_INDEX GENMASK(2, 0)
111 #define NFP_FLOWER_WORKQ_MAX_SKBS 30000
113 #define nfp_flower_cmsg_warn(app, fmt, args...) \
115 if (net_ratelimit()) \
116 nfp_warn((app)->cpp, fmt, ## args); \
119 enum nfp_flower_tun_type {
120 NFP_FL_TUNNEL_NONE = 0,
121 NFP_FL_TUNNEL_VXLAN = 2,
122 NFP_FL_TUNNEL_GENEVE = 4,
125 struct nfp_fl_act_head {
130 struct nfp_fl_set_eth {
131 struct nfp_fl_act_head head;
133 u8 eth_addr_mask[ETH_ALEN * 2];
134 u8 eth_addr_val[ETH_ALEN * 2];
137 struct nfp_fl_set_ip4_addrs {
138 struct nfp_fl_act_head head;
140 __be32 ipv4_src_mask;
142 __be32 ipv4_dst_mask;
146 struct nfp_fl_set_ipv6_addr {
147 struct nfp_fl_act_head head;
155 struct nfp_fl_set_tport {
156 struct nfp_fl_act_head head;
162 struct nfp_fl_output {
163 struct nfp_fl_act_head head;
168 struct nfp_fl_push_vlan {
169 struct nfp_fl_act_head head;
175 struct nfp_fl_pop_vlan {
176 struct nfp_fl_act_head head;
180 struct nfp_fl_pre_tunnel {
181 struct nfp_fl_act_head head;
184 /* reserved for use with IPv6 addresses */
188 struct nfp_fl_set_ipv4_udp_tun {
189 struct nfp_fl_act_head head;
191 __be64 tun_id __packed;
192 __be32 tun_type_index;
199 /* Metadata with L2 (1W/4B)
200 * ----------------------------------------------------------------
202 * 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
203 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
204 * | key_type | mask_id | PCP |p| vlan outermost VID |
205 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
208 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
210 struct nfp_flower_meta_tci {
211 u8 nfp_flow_key_layer;
216 /* Extended metadata for additional key_layers (1W/4B)
217 * ----------------------------------------------------------------
219 * 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
220 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
221 * | nfp_flow_key_layer2 |
222 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
224 struct nfp_flower_ext_meta {
225 __be32 nfp_flow_key_layer2;
228 /* Port details (1W/4B)
229 * ----------------------------------------------------------------
231 * 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
232 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
234 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
236 struct nfp_flower_in_port {
240 /* L2 details (4W/16B)
242 * 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
243 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
244 * | mac_addr_dst, 31 - 0 |
245 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
246 * | mac_addr_dst, 47 - 32 | mac_addr_src, 15 - 0 |
247 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248 * | mac_addr_src, 47 - 16 |
249 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
250 * | mpls outermost label | TC |B| reserved |q|
251 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
253 struct nfp_flower_mac_mpls {
259 /* L4 ports (for UDP, TCP, SCTP) (1W/4B)
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 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
263 * | port_src | port_dst |
264 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
266 struct nfp_flower_tp_ports {
271 struct nfp_flower_ip_ext {
278 /* L3 IPv4 details (3W/12B)
280 * 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
281 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
282 * | DSCP |ECN| protocol | ttl | flags |
283 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
285 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
287 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
289 struct nfp_flower_ipv4 {
290 struct nfp_flower_ip_ext ip_ext;
295 /* L3 IPv6 details (10W/40B)
297 * 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
298 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
299 * | DSCP |ECN| protocol | ttl | flags |
300 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
301 * | ipv6_exthdr | res | ipv6_flow_label |
302 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
303 * | ipv6_addr_src, 31 - 0 |
304 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
305 * | ipv6_addr_src, 63 - 32 |
306 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
307 * | ipv6_addr_src, 95 - 64 |
308 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
309 * | ipv6_addr_src, 127 - 96 |
310 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
311 * | ipv6_addr_dst, 31 - 0 |
312 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
313 * | ipv6_addr_dst, 63 - 32 |
314 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
315 * | ipv6_addr_dst, 95 - 64 |
316 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
317 * | ipv6_addr_dst, 127 - 96 |
318 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
320 struct nfp_flower_ipv6 {
321 struct nfp_flower_ip_ext ip_ext;
322 __be32 ipv6_flow_label_exthdr;
323 struct in6_addr ipv6_src;
324 struct in6_addr ipv6_dst;
327 /* Flow Frame IPv4 UDP TUNNEL --> Tunnel details (4W/16B)
328 * -----------------------------------------------------------------
330 * 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
331 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
333 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
335 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
337 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
339 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
341 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
343 struct nfp_flower_ipv4_udp_tun {
350 #define NFP_FL_TUN_VNI_OFFSET 8
352 /* The base header for a control message packet.
353 * Defines an 8-bit version, and an 8-bit type, padded
354 * to a 32-bit word. Rest of the packet is type-specific.
356 struct nfp_flower_cmsg_hdr {
362 #define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr)
363 #define NFP_FLOWER_CMSG_VER1 1
365 /* Types defined for port related control messages */
366 enum nfp_flower_cmsg_type_port {
367 NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0,
368 NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2,
369 NFP_FLOWER_CMSG_TYPE_LAG_CONFIG = 4,
370 NFP_FLOWER_CMSG_TYPE_PORT_REIFY = 6,
371 NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7,
372 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
373 NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10,
374 NFP_FLOWER_CMSG_TYPE_TUN_MAC = 11,
375 NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS = 12,
376 NFP_FLOWER_CMSG_TYPE_TUN_NEIGH = 13,
377 NFP_FLOWER_CMSG_TYPE_TUN_IPS = 14,
378 NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15,
379 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16,
380 NFP_FLOWER_CMSG_TYPE_MAX = 32,
383 /* NFP_FLOWER_CMSG_TYPE_MAC_REPR */
384 struct nfp_flower_cmsg_mac_repr {
395 #define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0)
397 /* NFP_FLOWER_CMSG_TYPE_PORT_MOD */
398 struct nfp_flower_cmsg_portmod {
405 #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
406 #define NFP_FLOWER_CMSG_PORTMOD_MTU_CHANGE_ONLY BIT(1)
408 /* NFP_FLOWER_CMSG_TYPE_PORT_REIFY */
409 struct nfp_flower_cmsg_portreify {
415 #define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST BIT(0)
417 enum nfp_flower_cmsg_port_type {
418 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
419 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
420 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2,
421 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT = 0x3,
424 enum nfp_flower_cmsg_port_vnic_type {
425 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0,
426 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1,
427 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2,
430 #define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28)
431 #define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24)
432 #define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22)
433 #define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14)
434 #define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12)
435 #define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6)
436 #define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0)
437 #define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0)
439 static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
441 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
442 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
443 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
447 nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
450 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
451 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
452 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
453 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
454 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
455 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
458 static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)
460 return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;
463 static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)
465 return skb->len - NFP_FLOWER_CMSG_HLEN;
469 nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
471 nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
472 unsigned int nbi, unsigned int nbi_port,
473 unsigned int phys_port);
474 int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok,
475 unsigned int mtu, bool mtu_only);
476 int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists);
477 void nfp_flower_cmsg_process_rx(struct work_struct *work);
478 void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
480 nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,
481 enum nfp_flower_cmsg_type_port type, gfp_t flag);