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"
43 #define NFP_FLOWER_LAYER_META BIT(0)
44 #define NFP_FLOWER_LAYER_PORT BIT(1)
45 #define NFP_FLOWER_LAYER_MAC BIT(2)
46 #define NFP_FLOWER_LAYER_TP BIT(3)
47 #define NFP_FLOWER_LAYER_IPV4 BIT(4)
48 #define NFP_FLOWER_LAYER_IPV6 BIT(5)
49 #define NFP_FLOWER_LAYER_CT BIT(6)
50 #define NFP_FLOWER_LAYER_VXLAN BIT(7)
52 #define NFP_FLOWER_LAYER_ETHER BIT(3)
53 #define NFP_FLOWER_LAYER_ARP BIT(4)
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_FL_SC_ACT_DROP 0x80000000
60 #define NFP_FL_SC_ACT_USER 0x7D000000
61 #define NFP_FL_SC_ACT_POPV 0x6A000000
62 #define NFP_FL_SC_ACT_NULL 0x00000000
64 /* The maximum action list size (in bytes) supported by the NFP.
66 #define NFP_FL_MAX_A_SIZ 1216
67 #define NFP_FL_LW_SIZ 2
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_NUM 32
75 #define NFP_FL_ACT_JMP_ID GENMASK(15, 8)
76 #define NFP_FL_ACT_LEN_LW GENMASK(7, 0)
78 #define NFP_FL_OUT_FLAGS_LAST BIT(15)
79 #define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
80 #define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
82 #define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13)
83 #define NFP_FL_PUSH_VLAN_CFI BIT(12)
84 #define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0)
86 struct nfp_fl_output {
92 struct nfp_fl_push_vlan {
99 struct nfp_fl_pop_vlan {
104 /* Metadata without L2 (1W/4B)
105 * ----------------------------------------------------------------
107 * 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
108 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
109 * | key_layers | mask_id | reserved |
110 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112 struct nfp_flower_meta_one {
113 u8 nfp_flow_key_layer;
118 /* Metadata with L2 (1W/4B)
119 * ----------------------------------------------------------------
121 * 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
122 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123 * | key_type | mask_id | PCP |p| vlan outermost VID |
124 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
127 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
129 struct nfp_flower_meta_two {
130 u8 nfp_flow_key_layer;
135 /* Port details (1W/4B)
136 * ----------------------------------------------------------------
138 * 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
139 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143 struct nfp_flower_in_port {
147 /* L2 details (4W/16B)
149 * 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
150 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151 * | mac_addr_dst, 31 - 0 |
152 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 * | mac_addr_dst, 47 - 32 | mac_addr_src, 15 - 0 |
154 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155 * | mac_addr_src, 47 - 16 |
156 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
157 * | mpls outermost label | TC |B| reserved |q|
158 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
160 struct nfp_flower_mac_mpls {
166 /* L4 ports (for UDP, TCP, SCTP) (1W/4B)
168 * 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
169 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
170 * | port_src | port_dst |
171 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173 struct nfp_flower_tp_ports {
178 /* L3 IPv4 details (3W/12B)
180 * 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
181 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
182 * | DSCP |ECN| protocol | reserved |
183 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
185 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
187 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
189 struct nfp_flower_ipv4 {
198 /* L3 IPv6 details (10W/40B)
200 * 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
201 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
202 * | DSCP |ECN| protocol | reserved |
203 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
204 * | ipv6_exthdr | res | ipv6_flow_label |
205 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
206 * | ipv6_addr_src, 31 - 0 |
207 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
208 * | ipv6_addr_src, 63 - 32 |
209 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
210 * | ipv6_addr_src, 95 - 64 |
211 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
212 * | ipv6_addr_src, 127 - 96 |
213 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
214 * | ipv6_addr_dst, 31 - 0 |
215 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
216 * | ipv6_addr_dst, 63 - 32 |
217 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
218 * | ipv6_addr_dst, 95 - 64 |
219 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
220 * | ipv6_addr_dst, 127 - 96 |
221 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
223 struct nfp_flower_ipv6 {
228 __be32 ipv6_flow_label_exthdr;
229 struct in6_addr ipv6_src;
230 struct in6_addr ipv6_dst;
233 /* The base header for a control message packet.
234 * Defines an 8-bit version, and an 8-bit type, padded
235 * to a 32-bit word. Rest of the packet is type-specific.
237 struct nfp_flower_cmsg_hdr {
243 #define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr)
244 #define NFP_FLOWER_CMSG_VER1 1
246 /* Types defined for port related control messages */
247 enum nfp_flower_cmsg_type_port {
248 NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0,
249 NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2,
250 NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7,
251 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
252 NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15,
253 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16,
254 NFP_FLOWER_CMSG_TYPE_MAX = 32,
257 /* NFP_FLOWER_CMSG_TYPE_MAC_REPR */
258 struct nfp_flower_cmsg_mac_repr {
269 #define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0)
271 /* NFP_FLOWER_CMSG_TYPE_PORT_MOD */
272 struct nfp_flower_cmsg_portmod {
279 #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
281 enum nfp_flower_cmsg_port_type {
282 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
283 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
284 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2,
287 enum nfp_flower_cmsg_port_vnic_type {
288 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0,
289 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1,
290 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2,
293 #define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28)
294 #define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24)
295 #define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22)
296 #define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14)
297 #define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12)
298 #define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6)
299 #define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0)
300 #define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0)
302 static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
304 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
305 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
306 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
310 nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
313 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
314 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
315 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
316 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
317 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
318 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
321 static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)
323 return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;
327 nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
329 nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
330 unsigned int nbi, unsigned int nbi_port,
331 unsigned int phys_port);
332 int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok);
333 void nfp_flower_cmsg_process_rx(struct work_struct *work);
334 void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
336 nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,
337 enum nfp_flower_cmsg_type_port type);