nfp: extend flower matching capabilities
[linux-2.6-microblaze.git] / drivers / net / ethernet / netronome / nfp / flower / cmsg.h
1 /*
2  * Copyright (C) 2017 Netronome Systems, Inc.
3  *
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.
8  *
9  * The BSD 2-Clause License:
10  *
11  *     Redistribution and use in source and binary forms, with or
12  *     without modification, are permitted provided that the following
13  *     conditions are met:
14  *
15  *      1. Redistributions of source code must retain the above
16  *         copyright notice, this list of conditions and the following
17  *         disclaimer.
18  *
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.
23  *
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
31  * SOFTWARE.
32  */
33
34 #ifndef NFP_FLOWER_CMSG_H
35 #define NFP_FLOWER_CMSG_H
36
37 #include <linux/bitfield.h>
38 #include <linux/skbuff.h>
39 #include <linux/types.h>
40
41 #include "../nfp_app.h"
42
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)
51
52 #define NFP_FLOWER_LAYER_ETHER          BIT(3)
53 #define NFP_FLOWER_LAYER_ARP            BIT(4)
54
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)
58
59 /* Metadata without L2 (1W/4B)
60  * ----------------------------------------------------------------
61  *    3                   2                   1
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66  */
67 struct nfp_flower_meta_one {
68         u8 nfp_flow_key_layer;
69         u8 mask_id;
70         u16 reserved;
71 };
72
73 /* Metadata with L2 (1W/4B)
74  * ----------------------------------------------------------------
75  *    3                   2                   1
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80  *                                 ^                               ^
81  *                           NOTE: |             TCI               |
82  *                                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83  */
84 struct nfp_flower_meta_two {
85         u8 nfp_flow_key_layer;
86         u8 mask_id;
87         __be16 tci;
88 };
89
90 /* Port details (1W/4B)
91  * ----------------------------------------------------------------
92  *    3                   2                   1
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95  * |                         port_ingress                          |
96  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
97  */
98 struct nfp_flower_in_port {
99         __be32 in_port;
100 };
101
102 /* L2 details (4W/16B)
103  *    3                   2                   1
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114  */
115 struct nfp_flower_mac_mpls {
116         u8 mac_dst[6];
117         u8 mac_src[6];
118         __be32 mpls_lse;
119 };
120
121 /* L4 ports (for UDP, TCP, SCTP) (1W/4B)
122  *    3                   2                   1
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
127  */
128 struct nfp_flower_tp_ports {
129         __be16 port_src;
130         __be16 port_dst;
131 };
132
133 /* L3 IPv4 details (3W/12B)
134  *    3                   2                   1
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
139  * |                        ipv4_addr_src                          |
140  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
141  * |                        ipv4_addr_dst                          |
142  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
143  */
144 struct nfp_flower_ipv4 {
145         u8 tos;
146         u8 proto;
147         u8 ttl;
148         u8 reserved;
149         __be32 ipv4_src;
150         __be32 ipv4_dst;
151 };
152
153 /* L3 IPv6 details (10W/40B)
154  *    3                   2                   1
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  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
177  */
178 struct nfp_flower_ipv6 {
179         u8 tos;
180         u8 proto;
181         u8 ttl;
182         u8 reserved;
183         __be32 ipv6_flow_label_exthdr;
184         struct in6_addr ipv6_src;
185         struct in6_addr ipv6_dst;
186 };
187
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.
191  */
192 struct nfp_flower_cmsg_hdr {
193         __be16 pad;
194         u8 type;
195         u8 version;
196 };
197
198 #define NFP_FLOWER_CMSG_HLEN            sizeof(struct nfp_flower_cmsg_hdr)
199 #define NFP_FLOWER_CMSG_VER1            1
200
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,
206 };
207
208 /* NFP_FLOWER_CMSG_TYPE_PORT_MOD */
209 struct nfp_flower_cmsg_portmod {
210         __be32 portnum;
211         u8 reserved;
212         u8 info;
213         __be16 mtu;
214 };
215
216 #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK       BIT(0)
217
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,
222 };
223
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,
228 };
229
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)
238
239 static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
240 {
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);
244 }
245
246 static inline u32
247 nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
248                           u8 vnic, u8 q)
249 {
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);
256 }
257
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);
260
261 #endif