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 /* Metadata without L2 (1W/4B)
60 * ----------------------------------------------------------------
62 * 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
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 * | key_layers | mask_id | reserved |
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 struct nfp_flower_meta_one {
68 u8 nfp_flow_key_layer;
73 /* Metadata with L2 (1W/4B)
74 * ----------------------------------------------------------------
76 * 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
77 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 * | key_type | mask_id | PCP |p| vlan outermost VID |
79 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
84 struct nfp_flower_meta_two {
85 u8 nfp_flow_key_layer;
90 /* Port details (1W/4B)
91 * ----------------------------------------------------------------
93 * 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
94 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
96 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
98 struct nfp_flower_in_port {
102 /* L2 details (4W/16B)
104 * 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
105 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106 * | mac_addr_dst, 31 - 0 |
107 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108 * | mac_addr_dst, 47 - 32 | mac_addr_src, 15 - 0 |
109 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110 * | mac_addr_src, 47 - 16 |
111 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112 * | mpls outermost label | TC |B| reserved |q|
113 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
115 struct nfp_flower_mac_mpls {
121 /* L4 ports (for UDP, TCP, SCTP) (1W/4B)
123 * 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
124 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
125 * | port_src | port_dst |
126 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128 struct nfp_flower_tp_ports {
133 /* L3 IPv4 details (3W/12B)
135 * 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
136 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
137 * | DSCP |ECN| protocol | reserved |
138 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144 struct nfp_flower_ipv4 {
153 /* L3 IPv6 details (10W/40B)
155 * 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
156 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
157 * | DSCP |ECN| protocol | reserved |
158 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
159 * | ipv6_exthdr | res | ipv6_flow_label |
160 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
161 * | ipv6_addr_src, 31 - 0 |
162 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
163 * | ipv6_addr_src, 63 - 32 |
164 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
165 * | ipv6_addr_src, 95 - 64 |
166 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
167 * | ipv6_addr_src, 127 - 96 |
168 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169 * | ipv6_addr_dst, 31 - 0 |
170 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
171 * | ipv6_addr_dst, 63 - 32 |
172 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173 * | ipv6_addr_dst, 95 - 64 |
174 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
175 * | ipv6_addr_dst, 127 - 96 |
176 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
178 struct nfp_flower_ipv6 {
183 __be32 ipv6_flow_label_exthdr;
184 struct in6_addr ipv6_src;
185 struct in6_addr ipv6_dst;
188 /* The base header for a control message packet.
189 * Defines an 8-bit version, and an 8-bit type, padded
190 * to a 32-bit word. Rest of the packet is type-specific.
192 struct nfp_flower_cmsg_hdr {
198 #define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr)
199 #define NFP_FLOWER_CMSG_VER1 1
201 /* Types defined for port related control messages */
202 enum nfp_flower_cmsg_type_port {
203 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
204 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16,
205 NFP_FLOWER_CMSG_TYPE_MAX = 32,
208 /* NFP_FLOWER_CMSG_TYPE_PORT_MOD */
209 struct nfp_flower_cmsg_portmod {
216 #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
218 enum nfp_flower_cmsg_port_type {
219 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
220 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
221 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2,
224 enum nfp_flower_cmsg_port_vnic_type {
225 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0,
226 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1,
227 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2,
230 #define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28)
231 #define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24)
232 #define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22)
233 #define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14)
234 #define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12)
235 #define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6)
236 #define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0)
237 #define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0)
239 static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
241 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
242 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
243 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
247 nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
250 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
251 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
252 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
253 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
254 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
255 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
258 int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok);
259 void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);