1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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#include "../nfpcore/nfp_cpp.h"
43
44#define NFP_FLOWER_LAYER_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)
52
53#define NFP_FLOWER_LAYER_ETHER BIT(3)
54#define NFP_FLOWER_LAYER_ARP BIT(4)
55
56#define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13)
57#define NFP_FLOWER_MASK_VLAN_CFI BIT(12)
58#define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0)
59
60#define NFP_FLOWER_MASK_MPLS_LB GENMASK(31, 12)
61#define NFP_FLOWER_MASK_MPLS_TC GENMASK(11, 9)
62#define NFP_FLOWER_MASK_MPLS_BOS BIT(8)
63#define NFP_FLOWER_MASK_MPLS_Q BIT(0)
64
65#define NFP_FL_SC_ACT_DROP 0x80000000
66#define NFP_FL_SC_ACT_USER 0x7D000000
67#define NFP_FL_SC_ACT_POPV 0x6A000000
68#define NFP_FL_SC_ACT_NULL 0x00000000
69
70
71
72#define NFP_FL_MAX_A_SIZ 1216
73#define NFP_FL_LW_SIZ 2
74
75
76#define NFP_FL_ACTION_OPCODE_OUTPUT 0
77#define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1
78#define NFP_FL_ACTION_OPCODE_POP_VLAN 2
79#define NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL 6
80#define NFP_FL_ACTION_OPCODE_SET_ETHERNET 7
81#define NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS 9
82#define NFP_FL_ACTION_OPCODE_SET_IPV6_SRC 11
83#define NFP_FL_ACTION_OPCODE_SET_IPV6_DST 12
84#define NFP_FL_ACTION_OPCODE_SET_UDP 14
85#define NFP_FL_ACTION_OPCODE_SET_TCP 15
86#define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17
87#define NFP_FL_ACTION_OPCODE_NUM 32
88
89#define NFP_FL_OUT_FLAGS_LAST BIT(15)
90#define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
91#define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
92
93#define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13)
94#define NFP_FL_PUSH_VLAN_CFI BIT(12)
95#define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0)
96
97
98#define NFP_FL_PORT_TYPE_TUN 0x50000000
99#define NFP_FL_IPV4_TUNNEL_TYPE GENMASK(7, 4)
100#define NFP_FL_IPV4_PRE_TUN_INDEX GENMASK(2, 0)
101
102#define nfp_flower_cmsg_warn(app, fmt, args...) \
103 do { \
104 if (net_ratelimit()) \
105 nfp_warn((app)->cpp, fmt, ## args); \
106 } while (0)
107
108enum nfp_flower_tun_type {
109 NFP_FL_TUNNEL_NONE = 0,
110 NFP_FL_TUNNEL_VXLAN = 2,
111};
112
113struct nfp_fl_act_head {
114 u8 jump_id;
115 u8 len_lw;
116};
117
118struct nfp_fl_set_eth {
119 struct nfp_fl_act_head head;
120 __be16 reserved;
121 u8 eth_addr_mask[ETH_ALEN * 2];
122 u8 eth_addr_val[ETH_ALEN * 2];
123};
124
125struct nfp_fl_set_ip4_addrs {
126 struct nfp_fl_act_head head;
127 __be16 reserved;
128 __be32 ipv4_src_mask;
129 __be32 ipv4_src;
130 __be32 ipv4_dst_mask;
131 __be32 ipv4_dst;
132};
133
134struct nfp_fl_set_ipv6_addr {
135 struct nfp_fl_act_head head;
136 __be16 reserved;
137 struct {
138 __be32 mask;
139 __be32 exact;
140 } ipv6[4];
141};
142
143struct nfp_fl_set_tport {
144 struct nfp_fl_act_head head;
145 __be16 reserved;
146 u8 tp_port_mask[4];
147 u8 tp_port_val[4];
148};
149
150struct nfp_fl_output {
151 struct nfp_fl_act_head head;
152 __be16 flags;
153 __be32 port;
154};
155
156struct nfp_fl_push_vlan {
157 struct nfp_fl_act_head head;
158 __be16 reserved;
159 __be16 vlan_tpid;
160 __be16 vlan_tci;
161};
162
163struct nfp_fl_pop_vlan {
164 struct nfp_fl_act_head head;
165 __be16 reserved;
166};
167
168
169
170
171
172
173
174
175
176struct nfp_flower_meta_one {
177 u8 nfp_flow_key_layer;
178 u8 mask_id;
179 u16 reserved;
180};
181
182struct nfp_fl_pre_tunnel {
183 struct nfp_fl_act_head head;
184 __be16 reserved;
185 __be32 ipv4_dst;
186
187 __be32 extra[3];
188};
189
190struct nfp_fl_set_vxlan {
191 struct nfp_fl_act_head head;
192 __be16 reserved;
193 __be64 tun_id;
194 __be32 tun_type_index;
195 __be16 tun_flags;
196 u8 ipv4_ttl;
197 u8 ipv4_tos;
198 __be32 extra[2];
199} __packed;
200
201
202
203
204
205
206
207
208
209
210
211
212struct nfp_flower_meta_two {
213 u8 nfp_flow_key_layer;
214 u8 mask_id;
215 __be16 tci;
216};
217
218
219
220
221
222
223
224
225
226struct nfp_flower_in_port {
227 __be32 in_port;
228};
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243struct nfp_flower_mac_mpls {
244 u8 mac_dst[6];
245 u8 mac_src[6];
246 __be32 mpls_lse;
247};
248
249
250
251
252
253
254
255
256struct nfp_flower_tp_ports {
257 __be16 port_src;
258 __be16 port_dst;
259};
260
261
262
263
264
265
266
267
268
269
270
271
272struct nfp_flower_ipv4 {
273 u8 tos;
274 u8 proto;
275 u8 ttl;
276 u8 reserved;
277 __be32 ipv4_src;
278 __be32 ipv4_dst;
279};
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306struct nfp_flower_ipv6 {
307 u8 tos;
308 u8 proto;
309 u8 ttl;
310 u8 reserved;
311 __be32 ipv6_flow_label_exthdr;
312 struct in6_addr ipv6_src;
313 struct in6_addr ipv6_dst;
314};
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332struct nfp_flower_vxlan {
333 __be32 ip_src;
334 __be32 ip_dst;
335 __be16 tun_flags;
336 u8 tos;
337 u8 ttl;
338 u8 gpe_flags;
339 u8 reserved[2];
340 u8 nxt_proto;
341 __be32 tun_id;
342};
343
344#define NFP_FL_TUN_VNI_OFFSET 8
345
346
347
348
349
350struct nfp_flower_cmsg_hdr {
351 __be16 pad;
352 u8 type;
353 u8 version;
354};
355
356#define NFP_FLOWER_CMSG_HLEN sizeof(struct nfp_flower_cmsg_hdr)
357#define NFP_FLOWER_CMSG_VER1 1
358
359
360enum nfp_flower_cmsg_type_port {
361 NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0,
362 NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2,
363 NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7,
364 NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
365 NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10,
366 NFP_FLOWER_CMSG_TYPE_TUN_MAC = 11,
367 NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS = 12,
368 NFP_FLOWER_CMSG_TYPE_TUN_NEIGH = 13,
369 NFP_FLOWER_CMSG_TYPE_TUN_IPS = 14,
370 NFP_FLOWER_CMSG_TYPE_FLOW_STATS = 15,
371 NFP_FLOWER_CMSG_TYPE_PORT_ECHO = 16,
372 NFP_FLOWER_CMSG_TYPE_MAX = 32,
373};
374
375
376struct nfp_flower_cmsg_mac_repr {
377 u8 reserved[3];
378 u8 num_ports;
379 struct {
380 u8 idx;
381 u8 info;
382 u8 nbi_port;
383 u8 phys_port;
384 } ports[0];
385};
386
387#define NFP_FLOWER_CMSG_MAC_REPR_NBI GENMASK(1, 0)
388
389
390struct nfp_flower_cmsg_portmod {
391 __be32 portnum;
392 u8 reserved;
393 u8 info;
394 __be16 mtu;
395};
396
397#define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
398
399enum nfp_flower_cmsg_port_type {
400 NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
401 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
402 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT = 0x2,
403 NFP_FLOWER_CMSG_PORT_TYPE_OTHER_PORT = 0x3,
404};
405
406enum nfp_flower_cmsg_port_vnic_type {
407 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_VF = 0x0,
408 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_PF = 0x1,
409 NFP_FLOWER_CMSG_PORT_VNIC_TYPE_CTRL = 0x2,
410};
411
412#define NFP_FLOWER_CMSG_PORT_TYPE GENMASK(31, 28)
413#define NFP_FLOWER_CMSG_PORT_SYS_ID GENMASK(27, 24)
414#define NFP_FLOWER_CMSG_PORT_NFP_ID GENMASK(23, 22)
415#define NFP_FLOWER_CMSG_PORT_PCI GENMASK(15, 14)
416#define NFP_FLOWER_CMSG_PORT_VNIC_TYPE GENMASK(13, 12)
417#define NFP_FLOWER_CMSG_PORT_VNIC GENMASK(11, 6)
418#define NFP_FLOWER_CMSG_PORT_PCIE_Q GENMASK(5, 0)
419#define NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM GENMASK(7, 0)
420
421static inline u32 nfp_flower_cmsg_phys_port(u8 phys_port)
422{
423 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PHYS_PORT_NUM, phys_port) |
424 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
425 NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT);
426}
427
428static inline u32
429nfp_flower_cmsg_pcie_port(u8 nfp_pcie, enum nfp_flower_cmsg_port_vnic_type type,
430 u8 vnic, u8 q)
431{
432 return FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCI, nfp_pcie) |
433 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC_TYPE, type) |
434 FIELD_PREP(NFP_FLOWER_CMSG_PORT_VNIC, vnic) |
435 FIELD_PREP(NFP_FLOWER_CMSG_PORT_PCIE_Q, q) |
436 FIELD_PREP(NFP_FLOWER_CMSG_PORT_TYPE,
437 NFP_FLOWER_CMSG_PORT_TYPE_PCIE_PORT);
438}
439
440static inline void *nfp_flower_cmsg_get_data(struct sk_buff *skb)
441{
442 return (unsigned char *)skb->data + NFP_FLOWER_CMSG_HLEN;
443}
444
445static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)
446{
447 return skb->len - NFP_FLOWER_CMSG_HLEN;
448}
449
450struct sk_buff *
451nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
452void
453nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
454 unsigned int nbi, unsigned int nbi_port,
455 unsigned int phys_port);
456int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok);
457void nfp_flower_cmsg_process_rx(struct work_struct *work);
458void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
459struct sk_buff *
460nfp_flower_cmsg_alloc(struct nfp_app *app, unsigned int size,
461 enum nfp_flower_cmsg_type_port type, gfp_t flag);
462
463#endif
464