GNU Linux-libre 4.19.281-gnu1
[releases.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 #include <net/geneve.h>
41
42 #include "../nfp_app.h"
43 #include "../nfpcore/nfp_cpp.h"
44
45 #define NFP_FLOWER_LAYER_EXT_META       BIT(0)
46 #define NFP_FLOWER_LAYER_PORT           BIT(1)
47 #define NFP_FLOWER_LAYER_MAC            BIT(2)
48 #define NFP_FLOWER_LAYER_TP             BIT(3)
49 #define NFP_FLOWER_LAYER_IPV4           BIT(4)
50 #define NFP_FLOWER_LAYER_IPV6           BIT(5)
51 #define NFP_FLOWER_LAYER_CT             BIT(6)
52 #define NFP_FLOWER_LAYER_VXLAN          BIT(7)
53
54 #define NFP_FLOWER_LAYER2_GENEVE        BIT(5)
55 #define NFP_FLOWER_LAYER2_GENEVE_OP     BIT(6)
56
57 #define NFP_FLOWER_MASK_VLAN_PRIO       GENMASK(15, 13)
58 #define NFP_FLOWER_MASK_VLAN_PRESENT    BIT(12)
59 #define NFP_FLOWER_MASK_VLAN_VID        GENMASK(11, 0)
60
61 #define NFP_FLOWER_MASK_MPLS_LB         GENMASK(31, 12)
62 #define NFP_FLOWER_MASK_MPLS_TC         GENMASK(11, 9)
63 #define NFP_FLOWER_MASK_MPLS_BOS        BIT(8)
64 #define NFP_FLOWER_MASK_MPLS_Q          BIT(0)
65
66 #define NFP_FL_IP_FRAG_FIRST            BIT(7)
67 #define NFP_FL_IP_FRAGMENTED            BIT(6)
68
69 /* Compressed HW representation of TCP Flags */
70 #define NFP_FL_TCP_FLAG_URG             BIT(4)
71 #define NFP_FL_TCP_FLAG_PSH             BIT(3)
72 #define NFP_FL_TCP_FLAG_RST             BIT(2)
73 #define NFP_FL_TCP_FLAG_SYN             BIT(1)
74 #define NFP_FL_TCP_FLAG_FIN             BIT(0)
75
76 #define NFP_FL_SC_ACT_DROP              0x80000000
77 #define NFP_FL_SC_ACT_USER              0x7D000000
78 #define NFP_FL_SC_ACT_POPV              0x6A000000
79 #define NFP_FL_SC_ACT_NULL              0x00000000
80
81 /* The maximum action list size (in bytes) supported by the NFP.
82  */
83 #define NFP_FL_MAX_A_SIZ                1216
84 #define NFP_FL_LW_SIZ                   2
85
86 /* Maximum allowed geneve options */
87 #define NFP_FL_MAX_GENEVE_OPT_ACT       32
88 #define NFP_FL_MAX_GENEVE_OPT_CNT       64
89 #define NFP_FL_MAX_GENEVE_OPT_KEY       32
90
91 /* Action opcodes */
92 #define NFP_FL_ACTION_OPCODE_OUTPUT             0
93 #define NFP_FL_ACTION_OPCODE_PUSH_VLAN          1
94 #define NFP_FL_ACTION_OPCODE_POP_VLAN           2
95 #define NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL    6
96 #define NFP_FL_ACTION_OPCODE_SET_ETHERNET       7
97 #define NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS     9
98 #define NFP_FL_ACTION_OPCODE_SET_IPV6_SRC       11
99 #define NFP_FL_ACTION_OPCODE_SET_IPV6_DST       12
100 #define NFP_FL_ACTION_OPCODE_SET_UDP            14
101 #define NFP_FL_ACTION_OPCODE_SET_TCP            15
102 #define NFP_FL_ACTION_OPCODE_PRE_LAG            16
103 #define NFP_FL_ACTION_OPCODE_PRE_TUNNEL         17
104 #define NFP_FL_ACTION_OPCODE_PUSH_GENEVE        26
105 #define NFP_FL_ACTION_OPCODE_NUM                32
106
107 #define NFP_FL_OUT_FLAGS_LAST           BIT(15)
108 #define NFP_FL_OUT_FLAGS_USE_TUN        BIT(4)
109 #define NFP_FL_OUT_FLAGS_TYPE_IDX       GENMASK(2, 0)
110
111 #define NFP_FL_PUSH_VLAN_PRIO           GENMASK(15, 13)
112 #define NFP_FL_PUSH_VLAN_VID            GENMASK(11, 0)
113
114 /* LAG ports */
115 #define NFP_FL_LAG_OUT                  0xC0DE0000
116
117 /* Tunnel ports */
118 #define NFP_FL_PORT_TYPE_TUN            0x50000000
119 #define NFP_FL_IPV4_TUNNEL_TYPE         GENMASK(7, 4)
120 #define NFP_FL_IPV4_PRE_TUN_INDEX       GENMASK(2, 0)
121
122 #define NFP_FLOWER_WORKQ_MAX_SKBS       30000
123
124 #define nfp_flower_cmsg_warn(app, fmt, args...)                         \
125         do {                                                            \
126                 if (net_ratelimit())                                    \
127                         nfp_warn((app)->cpp, fmt, ## args);             \
128         } while (0)
129
130 enum nfp_flower_tun_type {
131         NFP_FL_TUNNEL_NONE =    0,
132         NFP_FL_TUNNEL_VXLAN =   2,
133         NFP_FL_TUNNEL_GENEVE =  4,
134 };
135
136 struct nfp_fl_act_head {
137         u8 jump_id;
138         u8 len_lw;
139 };
140
141 struct nfp_fl_set_eth {
142         struct nfp_fl_act_head head;
143         __be16 reserved;
144         u8 eth_addr_mask[ETH_ALEN * 2];
145         u8 eth_addr_val[ETH_ALEN * 2];
146 };
147
148 struct nfp_fl_set_ip4_addrs {
149         struct nfp_fl_act_head head;
150         __be16 reserved;
151         __be32 ipv4_src_mask;
152         __be32 ipv4_src;
153         __be32 ipv4_dst_mask;
154         __be32 ipv4_dst;
155 };
156
157 struct nfp_fl_set_ipv6_addr {
158         struct nfp_fl_act_head head;
159         __be16 reserved;
160         struct {
161                 __be32 mask;
162                 __be32 exact;
163         } ipv6[4];
164 };
165
166 struct nfp_fl_set_tport {
167         struct nfp_fl_act_head head;
168         __be16 reserved;
169         u8 tp_port_mask[4];
170         u8 tp_port_val[4];
171 };
172
173 struct nfp_fl_output {
174         struct nfp_fl_act_head head;
175         __be16 flags;
176         __be32 port;
177 };
178
179 struct nfp_fl_push_vlan {
180         struct nfp_fl_act_head head;
181         __be16 reserved;
182         __be16 vlan_tpid;
183         __be16 vlan_tci;
184 };
185
186 struct nfp_fl_pop_vlan {
187         struct nfp_fl_act_head head;
188         __be16 reserved;
189 };
190
191 struct nfp_fl_pre_lag {
192         struct nfp_fl_act_head head;
193         __be16 group_id;
194         u8 lag_version[3];
195         u8 instance;
196 };
197
198 #define NFP_FL_PRE_LAG_VER_OFF  8
199
200 struct nfp_fl_pre_tunnel {
201         struct nfp_fl_act_head head;
202         __be16 reserved;
203         __be32 ipv4_dst;
204         /* reserved for use with IPv6 addresses */
205         __be32 extra[3];
206 };
207
208 struct nfp_fl_set_ipv4_udp_tun {
209         struct nfp_fl_act_head head;
210         __be16 reserved;
211         __be64 tun_id __packed;
212         __be32 tun_type_index;
213         __be16 tun_flags;
214         u8 ttl;
215         u8 tos;
216         __be32 extra;
217         u8 tun_len;
218         u8 res2;
219         __be16 tun_proto;
220 };
221
222 struct nfp_fl_push_geneve {
223         struct nfp_fl_act_head head;
224         __be16 reserved;
225         __be16 class;
226         u8 type;
227         u8 length;
228         u8 opt_data[];
229 };
230
231 /* Metadata with L2 (1W/4B)
232  * ----------------------------------------------------------------
233  *    3                   2                   1
234  *  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
235  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
236  * |    key_type   |    mask_id    | PCP |p|   vlan outermost VID  |
237  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
238  *                                 ^                               ^
239  *                           NOTE: |             TCI               |
240  *                                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
241  */
242 struct nfp_flower_meta_tci {
243         u8 nfp_flow_key_layer;
244         u8 mask_id;
245         __be16 tci;
246 };
247
248 /* Extended metadata for additional key_layers (1W/4B)
249  * ----------------------------------------------------------------
250  *    3                   2                   1
251  *  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
252  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
253  * |                      nfp_flow_key_layer2                      |
254  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
255  */
256 struct nfp_flower_ext_meta {
257         __be32 nfp_flow_key_layer2;
258 };
259
260 /* Port details (1W/4B)
261  * ----------------------------------------------------------------
262  *    3                   2                   1
263  *  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
264  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
265  * |                         port_ingress                          |
266  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
267  */
268 struct nfp_flower_in_port {
269         __be32 in_port;
270 };
271
272 /* L2 details (4W/16B)
273  *    3                   2                   1
274  *  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
275  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
276  * |                     mac_addr_dst, 31 - 0                      |
277  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
278  * |      mac_addr_dst, 47 - 32    |     mac_addr_src, 15 - 0      |
279  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
280  * |                     mac_addr_src, 47 - 16                     |
281  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
282  * |       mpls outermost label            |  TC |B|   reserved  |q|
283  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
284  */
285 struct nfp_flower_mac_mpls {
286         u8 mac_dst[6];
287         u8 mac_src[6];
288         __be32 mpls_lse;
289 };
290
291 /* L4 ports (for UDP, TCP, SCTP) (1W/4B)
292  *    3                   2                   1
293  *  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
294  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
295  * |            port_src           |           port_dst            |
296  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
297  */
298 struct nfp_flower_tp_ports {
299         __be16 port_src;
300         __be16 port_dst;
301 };
302
303 struct nfp_flower_ip_ext {
304         u8 tos;
305         u8 proto;
306         u8 ttl;
307         u8 flags;
308 };
309
310 /* L3 IPv4 details (3W/12B)
311  *    3                   2                   1
312  *  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
313  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
314  * |    DSCP   |ECN|   protocol    |      ttl      |     flags     |
315  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
316  * |                        ipv4_addr_src                          |
317  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
318  * |                        ipv4_addr_dst                          |
319  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
320  */
321 struct nfp_flower_ipv4 {
322         struct nfp_flower_ip_ext ip_ext;
323         __be32 ipv4_src;
324         __be32 ipv4_dst;
325 };
326
327 /* L3 IPv6 details (10W/40B)
328  *    3                   2                   1
329  *  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
330  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
331  * |    DSCP   |ECN|   protocol    |      ttl      |     flags     |
332  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
333  * |   ipv6_exthdr   | res |            ipv6_flow_label            |
334  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
335  * |                  ipv6_addr_src,   31 - 0                      |
336  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
337  * |                  ipv6_addr_src,  63 - 32                      |
338  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
339  * |                  ipv6_addr_src,  95 - 64                      |
340  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
341  * |                  ipv6_addr_src, 127 - 96                      |
342  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
343  * |                  ipv6_addr_dst,   31 - 0                      |
344  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
345  * |                  ipv6_addr_dst,  63 - 32                      |
346  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
347  * |                  ipv6_addr_dst,  95 - 64                      |
348  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
349  * |                  ipv6_addr_dst, 127 - 96                      |
350  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
351  */
352 struct nfp_flower_ipv6 {
353         struct nfp_flower_ip_ext ip_ext;
354         __be32 ipv6_flow_label_exthdr;
355         struct in6_addr ipv6_src;
356         struct in6_addr ipv6_dst;
357 };
358
359 /* Flow Frame IPv4 UDP TUNNEL --> Tunnel details (4W/16B)
360  * -----------------------------------------------------------------
361  *    3                   2                   1
362  *  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
363  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
364  * |                         ipv4_addr_src                         |
365  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
366  * |                         ipv4_addr_dst                         |
367  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
368  * |           Reserved            |      tos      |      ttl      |
369  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
370  * |                            Reserved                           |
371  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
372  * |                     VNI                       |   Reserved    |
373  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
374  */
375 struct nfp_flower_ipv4_udp_tun {
376         __be32 ip_src;
377         __be32 ip_dst;
378         __be16 reserved1;
379         u8 tos;
380         u8 ttl;
381         __be32 reserved2;
382         __be32 tun_id;
383 };
384
385 struct nfp_flower_geneve_options {
386         u8 data[NFP_FL_MAX_GENEVE_OPT_KEY];
387 };
388
389 #define NFP_FL_TUN_VNI_OFFSET 8
390
391 /* The base header for a control message packet.
392  * Defines an 8-bit version, and an 8-bit type, padded
393  * to a 32-bit word. Rest of the packet is type-specific.
394  */
395 struct nfp_flower_cmsg_hdr {
396         __be16 pad;
397         u8 type;
398         u8 version;
399 };
400
401 #define NFP_FLOWER_CMSG_HLEN            sizeof(struct nfp_flower_cmsg_hdr)
402 #define NFP_FLOWER_CMSG_VER1            1
403
404 /* Types defined for port related control messages  */
405 enum nfp_flower_cmsg_type_port {
406         NFP_FLOWER_CMSG_TYPE_FLOW_ADD =         0,
407         NFP_FLOWER_CMSG_TYPE_FLOW_DEL =         2,
408         NFP_FLOWER_CMSG_TYPE_LAG_CONFIG =       4,
409         NFP_FLOWER_CMSG_TYPE_PORT_REIFY =       6,
410         NFP_FLOWER_CMSG_TYPE_MAC_REPR =         7,
411         NFP_FLOWER_CMSG_TYPE_PORT_MOD =         8,
412         NFP_FLOWER_CMSG_TYPE_NO_NEIGH =         10,
413         NFP_FLOWER_CMSG_TYPE_TUN_MAC =          11,
414         NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS =      12,
415         NFP_FLOWER_CMSG_TYPE_TUN_NEIGH =        13,
416         NFP_FLOWER_CMSG_TYPE_TUN_IPS =          14,
417         NFP_FLOWER_CMSG_TYPE_FLOW_STATS =       15,
418         NFP_FLOWER_CMSG_TYPE_PORT_ECHO =        16,
419         NFP_FLOWER_CMSG_TYPE_MAX =              32,
420 };
421
422 /* NFP_FLOWER_CMSG_TYPE_MAC_REPR */
423 struct nfp_flower_cmsg_mac_repr {
424         u8 reserved[3];
425         u8 num_ports;
426         struct {
427                 u8 idx;
428                 u8 info;
429                 u8 nbi_port;
430                 u8 phys_port;
431         } ports[0];
432 };
433
434 #define NFP_FLOWER_CMSG_MAC_REPR_NBI            GENMASK(1, 0)
435
436 /* NFP_FLOWER_CMSG_TYPE_PORT_MOD */
437 struct nfp_flower_cmsg_portmod {
438         __be32 portnum;
439         u8 reserved;
440         u8 info;
441         __be16 mtu;
442 };
443
444 #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK       BIT(0)
445 #define NFP_FLOWER_CMSG_PORTMOD_MTU_CHANGE_ONLY BIT(1)
446
447 /* NFP_FLOWER_CMSG_TYPE_PORT_REIFY */
448 struct nfp_flower_cmsg_portreify {
449         __be32 portnum;
450         u16 reserved;
451         __be16 info;
452 };
453
454 #define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST    BIT(0)
455
456 enum nfp_flower_cmsg_port_type {
457         NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC =      0x0,
458         NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT =   0x1,
459         NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT =   0x2,
460         NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT =  0x3,
461 };
462
463 enum nfp_flower_cmsg_port_vnic_type {
464         NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF =     0x0,
465         NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF =     0x1,
466         NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL =   0x2,
467 };
468
469 #define NFP_FLOWER_CMSG_PORT_TYPE               GENMASK(31, 28)
470 #define NFP_FLOWER_CMSG_PORT_SYS_ID             GENMASK(27, 24)
471 #define NFP_FLOWER_CMSG_PORT_NFP_ID             GENMASK(23, 22)
472 #define NFP_FLOWER_CMSG_PORT_PCI                GENMASK(15, 14)
473 #define NFP_FLOWER_CMSG_PORT_VNIC_TYPE          GENMASK(13, 12)
474 #define NFP_FLOWER_CMSG_PORT_VNIC               GENMASK(11, 6)
475 #define NFP_FLOWER_CMSG_PORT_PCIE_Q             GENMASK(5, 0)
476 #define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM      GENMASK(7, 0)
477
478 static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
479 {
480         return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
481                 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
482                            NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
483 }
484
485 static inline u32
486 nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
487                           u8 vnic, u8 q)
488 {
489         return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
490                 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
491                 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
492                 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
493                 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
494                            NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
495 }
496
497 static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)
498 {
499         return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;
500 }
501
502 static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)
503 {
504         return skb->len - NFP_FLOWER_CMSG_HLEN;
505 }
506
507 struct sk_buff *
508 nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
509 void
510 nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
511                              unsigned int nbi, unsigned int nbi_port,
512                              unsigned int phys_port);
513 int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok,
514                             unsigned int mtu, bool mtu_only);
515 int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists);
516 void nfp_flower_cmsg_process_rx(struct work_struct *work);
517 void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
518 struct sk_buff *
519 nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,
520                       enum nfp_flower_cmsg_type_port type, gfp_t flag);
521
522 #endif