Skip to content

Commit bedeca1

Browse files
jahurleydavem330
authored andcommitted
nfp: flower: compile Geneve match fields
Compile Geneve match fields for offloading to the NFP. The addition of Geneve overflows the 8 bit key_layer field, so apply extended metadata to the match cmsg allowing up to 32 more key_layer fields. Rather than adding new Geneve blocks, move the vxlan code to generic ipv4 udp tunnel structs and use these for both vxlan and Geneve. Matches are only supported when specifically mentioning well known port 6081. Geneve tunnel options are not yet included in the match. Only offload Geneve if the fw supports it - include check for this. Signed-off-by: John Hurley <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7399734 commit bedeca1

File tree

4 files changed

+91
-42
lines changed

4 files changed

+91
-42
lines changed

drivers/net/ethernet/netronome/nfp/flower/cmsg.h

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "../nfp_app.h"
4242
#include "../nfpcore/nfp_cpp.h"
4343

44-
#define NFP_FLOWER_LAYER_META BIT(0)
44+
#define NFP_FLOWER_LAYER_EXT_META BIT(0)
4545
#define NFP_FLOWER_LAYER_PORT BIT(1)
4646
#define NFP_FLOWER_LAYER_MAC BIT(2)
4747
#define NFP_FLOWER_LAYER_TP BIT(3)
@@ -50,6 +50,8 @@
5050
#define NFP_FLOWER_LAYER_CT BIT(6)
5151
#define NFP_FLOWER_LAYER_VXLAN BIT(7)
5252

53+
#define NFP_FLOWER_LAYER2_GENEVE BIT(5)
54+
5355
#define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13)
5456
#define NFP_FLOWER_MASK_VLAN_CFI BIT(12)
5557
#define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0)
@@ -105,6 +107,7 @@
105107
enum nfp_flower_tun_type {
106108
NFP_FL_TUNNEL_NONE = 0,
107109
NFP_FL_TUNNEL_VXLAN = 2,
110+
NFP_FL_TUNNEL_GENEVE = 4,
108111
};
109112

110113
struct nfp_fl_act_head {
@@ -198,6 +201,18 @@ struct nfp_flower_meta_tci {
198201
__be16 tci;
199202
};
200203

204+
/* Extended metadata for additional key_layers (1W/4B)
205+
* ----------------------------------------------------------------
206+
* 3 2 1
207+
* 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
208+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
209+
* | nfp_flow_key_layer2 |
210+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
211+
*/
212+
struct nfp_flower_ext_meta {
213+
__be32 nfp_flow_key_layer2;
214+
};
215+
201216
/* Port details (1W/4B)
202217
* ----------------------------------------------------------------
203218
* 3 2 1
@@ -296,7 +311,7 @@ struct nfp_flower_ipv6 {
296311
struct in6_addr ipv6_dst;
297312
};
298313

299-
/* Flow Frame VXLAN --> Tunnel details (4W/16B)
314+
/* Flow Frame IPv4 UDP TUNNEL --> Tunnel details (4W/16B)
300315
* -----------------------------------------------------------------
301316
* 3 2 1
302317
* 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
@@ -305,22 +320,17 @@ struct nfp_flower_ipv6 {
305320
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
306321
* | ipv4_addr_dst |
307322
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
308-
* | tun_flags | tos | ttl |
323+
* | Reserved |
309324
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
310-
* | gpe_flags | Reserved | Next Protocol |
325+
* | Reserved |
311326
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
312327
* | VNI | Reserved |
313328
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
314329
*/
315-
struct nfp_flower_vxlan {
330+
struct nfp_flower_ipv4_udp_tun {
316331
__be32 ip_src;
317332
__be32 ip_dst;
318-
__be16 tun_flags;
319-
u8 tos;
320-
u8 ttl;
321-
u8 gpe_flags;
322-
u8 reserved[2];
323-
u8 nxt_proto;
333+
__be32 reserved[2];
324334
__be32 tun_id;
325335
};
326336

drivers/net/ethernet/netronome/nfp/flower/main.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#ifndef __NFP_FLOWER_H__
3535
#define __NFP_FLOWER_H__ 1
3636

37+
#include "cmsg.h"
38+
3739
#include <linux/circ_buf.h>
3840
#include <linux/hashtable.h>
3941
#include <linux/time64.h>
@@ -58,6 +60,10 @@ struct nfp_app;
5860
#define NFP_FL_MASK_ID_LOCATION 1
5961

6062
#define NFP_FL_VXLAN_PORT 4789
63+
#define NFP_FL_GENEVE_PORT 6081
64+
65+
/* Extra features bitmap. */
66+
#define NFP_FL_FEATS_GENEVE BIT(0)
6167

6268
struct nfp_fl_mask_id {
6369
struct circ_buf mask_id_free_list;
@@ -174,7 +180,8 @@ int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
174180
int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
175181
struct nfp_fl_key_ls *key_ls,
176182
struct net_device *netdev,
177-
struct nfp_fl_payload *nfp_flow);
183+
struct nfp_fl_payload *nfp_flow,
184+
enum nfp_flower_tun_type tun_type);
178185
int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
179186
struct net_device *netdev,
180187
struct nfp_fl_payload *nfp_flow);

drivers/net/ethernet/netronome/nfp/flower/match.c

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ nfp_flower_compile_meta_tci(struct nfp_flower_meta_tci *frame,
6767
}
6868
}
6969

70+
static void
71+
nfp_flower_compile_ext_meta(struct nfp_flower_ext_meta *frame, u32 key_ext)
72+
{
73+
frame->nfp_flow_key_layer2 = cpu_to_be32(key_ext);
74+
}
75+
7076
static int
7177
nfp_flower_compile_port(struct nfp_flower_in_port *frame, u32 cmsg_port,
7278
bool mask_version, enum nfp_flower_tun_type tun_type)
@@ -216,16 +222,15 @@ nfp_flower_compile_ipv6(struct nfp_flower_ipv6 *frame,
216222
}
217223

218224
static void
219-
nfp_flower_compile_vxlan(struct nfp_flower_vxlan *frame,
220-
struct tc_cls_flower_offload *flow,
221-
bool mask_version)
225+
nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *frame,
226+
struct tc_cls_flower_offload *flow,
227+
bool mask_version)
222228
{
223229
struct fl_flow_key *target = mask_version ? flow->mask : flow->key;
224-
struct flow_dissector_key_ipv4_addrs *vxlan_ips;
230+
struct flow_dissector_key_ipv4_addrs *tun_ips;
225231
struct flow_dissector_key_keyid *vni;
226232

227-
/* Wildcard TOS/TTL/GPE_FLAGS/NXT_PROTO for now. */
228-
memset(frame, 0, sizeof(struct nfp_flower_vxlan));
233+
memset(frame, 0, sizeof(struct nfp_flower_ipv4_udp_tun));
229234

230235
if (dissector_uses_key(flow->dissector,
231236
FLOW_DISSECTOR_KEY_ENC_KEYID)) {
@@ -240,29 +245,26 @@ nfp_flower_compile_vxlan(struct nfp_flower_vxlan *frame,
240245

241246
if (dissector_uses_key(flow->dissector,
242247
FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) {
243-
vxlan_ips =
248+
tun_ips =
244249
skb_flow_dissector_target(flow->dissector,
245250
FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS,
246251
target);
247-
frame->ip_src = vxlan_ips->src;
248-
frame->ip_dst = vxlan_ips->dst;
252+
frame->ip_src = tun_ips->src;
253+
frame->ip_dst = tun_ips->dst;
249254
}
250255
}
251256

252257
int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
253258
struct nfp_fl_key_ls *key_ls,
254259
struct net_device *netdev,
255-
struct nfp_fl_payload *nfp_flow)
260+
struct nfp_fl_payload *nfp_flow,
261+
enum nfp_flower_tun_type tun_type)
256262
{
257-
enum nfp_flower_tun_type tun_type = NFP_FL_TUNNEL_NONE;
258263
struct nfp_repr *netdev_repr;
259264
int err;
260265
u8 *ext;
261266
u8 *msk;
262267

263-
if (key_ls->key_layer & NFP_FLOWER_LAYER_VXLAN)
264-
tun_type = NFP_FL_TUNNEL_VXLAN;
265-
266268
memset(nfp_flow->unmasked_data, 0, key_ls->key_size);
267269
memset(nfp_flow->mask_data, 0, key_ls->key_size);
268270

@@ -278,6 +280,16 @@ int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
278280
ext += sizeof(struct nfp_flower_meta_tci);
279281
msk += sizeof(struct nfp_flower_meta_tci);
280282

283+
/* Populate Extended Metadata if Required. */
284+
if (NFP_FLOWER_LAYER_EXT_META & key_ls->key_layer) {
285+
nfp_flower_compile_ext_meta((struct nfp_flower_ext_meta *)ext,
286+
key_ls->key_layer_two);
287+
nfp_flower_compile_ext_meta((struct nfp_flower_ext_meta *)msk,
288+
key_ls->key_layer_two);
289+
ext += sizeof(struct nfp_flower_ext_meta);
290+
msk += sizeof(struct nfp_flower_ext_meta);
291+
}
292+
281293
/* Populate Exact Port data. */
282294
err = nfp_flower_compile_port((struct nfp_flower_in_port *)ext,
283295
nfp_repr_get_port_id(netdev),
@@ -339,18 +351,17 @@ int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
339351
msk += sizeof(struct nfp_flower_ipv6);
340352
}
341353

342-
if (key_ls->key_layer & NFP_FLOWER_LAYER_VXLAN) {
354+
if (key_ls->key_layer & NFP_FLOWER_LAYER_VXLAN ||
355+
key_ls->key_layer_two & NFP_FLOWER_LAYER2_GENEVE) {
343356
__be32 tun_dst;
344357

345358
/* Populate Exact VXLAN Data. */
346-
nfp_flower_compile_vxlan((struct nfp_flower_vxlan *)ext,
347-
flow, false);
359+
nfp_flower_compile_ipv4_udp_tun((void *)ext, flow, false);
348360
/* Populate Mask VXLAN Data. */
349-
nfp_flower_compile_vxlan((struct nfp_flower_vxlan *)msk,
350-
flow, true);
351-
tun_dst = ((struct nfp_flower_vxlan *)ext)->ip_dst;
352-
ext += sizeof(struct nfp_flower_vxlan);
353-
msk += sizeof(struct nfp_flower_vxlan);
361+
nfp_flower_compile_ipv4_udp_tun((void *)msk, flow, true);
362+
tun_dst = ((struct nfp_flower_ipv4_udp_tun *)ext)->ip_dst;
363+
ext += sizeof(struct nfp_flower_ipv4_udp_tun);
364+
msk += sizeof(struct nfp_flower_ipv4_udp_tun);
354365

355366
/* Configure tunnel end point MAC. */
356367
if (nfp_netdev_is_nfp_repr(netdev)) {

drivers/net/ethernet/netronome/nfp/flower/offload.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,15 @@ static bool nfp_flower_check_higher_than_mac(struct tc_cls_flower_offload *f)
130130
}
131131

132132
static int
133-
nfp_flower_calculate_key_layers(struct nfp_fl_key_ls *ret_key_ls,
133+
nfp_flower_calculate_key_layers(struct nfp_app *app,
134+
struct nfp_fl_key_ls *ret_key_ls,
134135
struct tc_cls_flower_offload *flow,
135-
bool egress)
136+
bool egress,
137+
enum nfp_flower_tun_type *tun_type)
136138
{
137139
struct flow_dissector_key_basic *mask_basic = NULL;
138140
struct flow_dissector_key_basic *key_basic = NULL;
141+
struct nfp_flower_priv *priv = app->priv;
139142
u32 key_layer_two;
140143
u8 key_layer;
141144
int key_size;
@@ -197,12 +200,27 @@ nfp_flower_calculate_key_layers(struct nfp_fl_key_ls *ret_key_ls,
197200
FLOW_DISSECTOR_KEY_ENC_PORTS,
198201
flow->key);
199202

200-
if (mask_enc_ports->dst != cpu_to_be16(~0) ||
201-
enc_ports->dst != htons(NFP_FL_VXLAN_PORT))
203+
if (mask_enc_ports->dst != cpu_to_be16(~0))
202204
return -EOPNOTSUPP;
203205

204-
key_layer |= NFP_FLOWER_LAYER_VXLAN;
205-
key_size += sizeof(struct nfp_flower_vxlan);
206+
switch (enc_ports->dst) {
207+
case htons(NFP_FL_VXLAN_PORT):
208+
*tun_type = NFP_FL_TUNNEL_VXLAN;
209+
key_layer |= NFP_FLOWER_LAYER_VXLAN;
210+
key_size += sizeof(struct nfp_flower_ipv4_udp_tun);
211+
break;
212+
case htons(NFP_FL_GENEVE_PORT):
213+
if (!(priv->flower_ext_feats & NFP_FL_FEATS_GENEVE))
214+
return -EOPNOTSUPP;
215+
*tun_type = NFP_FL_TUNNEL_GENEVE;
216+
key_layer |= NFP_FLOWER_LAYER_EXT_META;
217+
key_size += sizeof(struct nfp_flower_ext_meta);
218+
key_layer_two |= NFP_FLOWER_LAYER2_GENEVE;
219+
key_size += sizeof(struct nfp_flower_ipv4_udp_tun);
220+
break;
221+
default:
222+
return -EOPNOTSUPP;
223+
}
206224
} else if (egress) {
207225
/* Reject non tunnel matches offloaded to egress repr. */
208226
return -EOPNOTSUPP;
@@ -330,6 +348,7 @@ static int
330348
nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
331349
struct tc_cls_flower_offload *flow, bool egress)
332350
{
351+
enum nfp_flower_tun_type tun_type = NFP_FL_TUNNEL_NONE;
333352
struct nfp_flower_priv *priv = app->priv;
334353
struct nfp_fl_payload *flow_pay;
335354
struct nfp_fl_key_ls *key_layer;
@@ -339,7 +358,8 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
339358
if (!key_layer)
340359
return -ENOMEM;
341360

342-
err = nfp_flower_calculate_key_layers(key_layer, flow, egress);
361+
err = nfp_flower_calculate_key_layers(app, key_layer, flow, egress,
362+
&tun_type);
343363
if (err)
344364
goto err_free_key_ls;
345365

@@ -349,7 +369,8 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
349369
goto err_free_key_ls;
350370
}
351371

352-
err = nfp_flower_compile_flow_match(flow, key_layer, netdev, flow_pay);
372+
err = nfp_flower_compile_flow_match(flow, key_layer, netdev, flow_pay,
373+
tun_type);
353374
if (err)
354375
goto err_destroy_flow;
355376

0 commit comments

Comments
 (0)