Skip to content

Commit ffa6120

Browse files
pjvuurendavem330
authored andcommitted
nfp: flower: implement tcp flag match offload
Implement tcp flag match offloading. Current tcp flag match support include FIN, SYN, RST, PSH and URG flags, other flags are unsupported. The PSH and URG flags are only set in the hardware fast path when used in combination with the SYN, RST and PSH flags. Signed-off-by: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com> Reviewed-by: John Hurley <john.hurley@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 014f900 commit ffa6120

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@
6161
#define NFP_FLOWER_MASK_MPLS_BOS BIT(8)
6262
#define NFP_FLOWER_MASK_MPLS_Q BIT(0)
6363

64+
/* Compressed HW representation of TCP Flags */
65+
#define NFP_FL_TCP_FLAG_URG BIT(4)
66+
#define NFP_FL_TCP_FLAG_PSH BIT(3)
67+
#define NFP_FL_TCP_FLAG_RST BIT(2)
68+
#define NFP_FL_TCP_FLAG_SYN BIT(1)
69+
#define NFP_FL_TCP_FLAG_FIN BIT(0)
70+
6471
#define NFP_FL_SC_ACT_DROP 0x80000000
6572
#define NFP_FL_SC_ACT_USER 0x7D000000
6673
#define NFP_FL_SC_ACT_POPV 0x6A000000
@@ -257,7 +264,7 @@ struct nfp_flower_tp_ports {
257264
* 3 2 1
258265
* 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
259266
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
260-
* | DSCP |ECN| protocol | reserved |
267+
* | DSCP |ECN| protocol | ttl | flags |
261268
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
262269
* | ipv4_addr_src |
263270
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -268,7 +275,7 @@ struct nfp_flower_ipv4 {
268275
u8 tos;
269276
u8 proto;
270277
u8 ttl;
271-
u8 reserved;
278+
u8 flags;
272279
__be32 ipv4_src;
273280
__be32 ipv4_dst;
274281
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <linux/time64.h>
4242
#include <linux/types.h>
4343
#include <net/pkt_cls.h>
44+
#include <net/tcp.h>
4445
#include <linux/workqueue.h>
4546

4647
struct net_device;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,26 @@ nfp_flower_compile_ipv4(struct nfp_flower_ipv4 *frame,
181181
frame->tos = flow_ip->tos;
182182
frame->ttl = flow_ip->ttl;
183183
}
184+
185+
if (dissector_uses_key(flow->dissector, FLOW_DISSECTOR_KEY_TCP)) {
186+
struct flow_dissector_key_tcp *tcp;
187+
u32 tcp_flags;
188+
189+
tcp = skb_flow_dissector_target(flow->dissector,
190+
FLOW_DISSECTOR_KEY_TCP, target);
191+
tcp_flags = be16_to_cpu(tcp->flags);
192+
193+
if (tcp_flags & TCPHDR_FIN)
194+
frame->flags |= NFP_FL_TCP_FLAG_FIN;
195+
if (tcp_flags & TCPHDR_SYN)
196+
frame->flags |= NFP_FL_TCP_FLAG_SYN;
197+
if (tcp_flags & TCPHDR_RST)
198+
frame->flags |= NFP_FL_TCP_FLAG_RST;
199+
if (tcp_flags & TCPHDR_PSH)
200+
frame->flags |= NFP_FL_TCP_FLAG_PSH;
201+
if (tcp_flags & TCPHDR_URG)
202+
frame->flags |= NFP_FL_TCP_FLAG_URG;
203+
}
184204
}
185205

186206
static void

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@
4444
#include "../nfp_net.h"
4545
#include "../nfp_port.h"
4646

47+
#define NFP_FLOWER_SUPPORTED_TCPFLAGS \
48+
(TCPHDR_FIN | TCPHDR_SYN | TCPHDR_RST | \
49+
TCPHDR_PSH | TCPHDR_URG)
50+
4751
#define NFP_FLOWER_WHITELIST_DISSECTOR \
4852
(BIT(FLOW_DISSECTOR_KEY_CONTROL) | \
4953
BIT(FLOW_DISSECTOR_KEY_BASIC) | \
5054
BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) | \
5155
BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) | \
56+
BIT(FLOW_DISSECTOR_KEY_TCP) | \
5257
BIT(FLOW_DISSECTOR_KEY_PORTS) | \
5358
BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) | \
5459
BIT(FLOW_DISSECTOR_KEY_VLAN) | \
@@ -288,6 +293,35 @@ nfp_flower_calculate_key_layers(struct nfp_app *app,
288293
}
289294
}
290295

296+
if (dissector_uses_key(flow->dissector, FLOW_DISSECTOR_KEY_TCP)) {
297+
struct flow_dissector_key_tcp *tcp;
298+
u32 tcp_flags;
299+
300+
tcp = skb_flow_dissector_target(flow->dissector,
301+
FLOW_DISSECTOR_KEY_TCP,
302+
flow->key);
303+
tcp_flags = be16_to_cpu(tcp->flags);
304+
305+
if (tcp_flags & ~NFP_FLOWER_SUPPORTED_TCPFLAGS)
306+
return -EOPNOTSUPP;
307+
308+
/* We only support PSH and URG flags when either
309+
* FIN, SYN or RST is present as well.
310+
*/
311+
if ((tcp_flags & (TCPHDR_PSH | TCPHDR_URG)) &&
312+
!(tcp_flags & (TCPHDR_FIN | TCPHDR_SYN | TCPHDR_RST)))
313+
return -EOPNOTSUPP;
314+
315+
/* We need to store TCP flags in the IPv4 key space, thus
316+
* we need to ensure we include a IPv4 key layer if we have
317+
* not done so already.
318+
*/
319+
if (!(key_layer & NFP_FLOWER_LAYER_IPV4)) {
320+
key_layer |= NFP_FLOWER_LAYER_IPV4;
321+
key_size += sizeof(struct nfp_flower_ipv4);
322+
}
323+
}
324+
291325
ret_key_ls->key_layer = key_layer;
292326
ret_key_ls->key_layer_two = key_layer_two;
293327
ret_key_ls->key_size = key_size;

0 commit comments

Comments
 (0)