Commit 31c491e5 authored by John Hurley's avatar John Hurley Committed by David S. Miller

nfp: flower: pass flow rule pointer directly to match functions

In kernel 5.1, the flow offload API was introduced along with a helper
function to extract the flow_rule from the TC offload struct. Each of the
match helper functions are passed the offload struct and extract the flow
rule to a local variable.

Simplify the code while also removing the extra compat and local variable
calls by extracting the rule once in the main match handler, and passing
a reference to the rule direct to each helper.

This patch does not change driver functionality.
Signed-off-by: default avatarJohn Hurley <john.hurley@netronome.com>
Reviewed-by: default avatarSimon Horman <simon.horman@netronome.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a886ca6f
...@@ -10,9 +10,8 @@ ...@@ -10,9 +10,8 @@
static void static void
nfp_flower_compile_meta_tci(struct nfp_flower_meta_tci *ext, nfp_flower_compile_meta_tci(struct nfp_flower_meta_tci *ext,
struct nfp_flower_meta_tci *msk, struct nfp_flower_meta_tci *msk,
struct flow_cls_offload *flow, u8 key_type) struct flow_rule *rule, u8 key_type)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
u16 tmp_tci; u16 tmp_tci;
memset(ext, 0, sizeof(struct nfp_flower_meta_tci)); memset(ext, 0, sizeof(struct nfp_flower_meta_tci));
...@@ -77,11 +76,8 @@ nfp_flower_compile_port(struct nfp_flower_in_port *frame, u32 cmsg_port, ...@@ -77,11 +76,8 @@ nfp_flower_compile_port(struct nfp_flower_in_port *frame, u32 cmsg_port,
static void static void
nfp_flower_compile_mac(struct nfp_flower_mac_mpls *ext, nfp_flower_compile_mac(struct nfp_flower_mac_mpls *ext,
struct nfp_flower_mac_mpls *msk, struct nfp_flower_mac_mpls *msk, struct flow_rule *rule)
struct flow_cls_offload *flow)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
memset(ext, 0, sizeof(struct nfp_flower_mac_mpls)); memset(ext, 0, sizeof(struct nfp_flower_mac_mpls));
memset(msk, 0, sizeof(struct nfp_flower_mac_mpls)); memset(msk, 0, sizeof(struct nfp_flower_mac_mpls));
...@@ -130,10 +126,8 @@ nfp_flower_compile_mac(struct nfp_flower_mac_mpls *ext, ...@@ -130,10 +126,8 @@ nfp_flower_compile_mac(struct nfp_flower_mac_mpls *ext,
static void static void
nfp_flower_compile_tport(struct nfp_flower_tp_ports *ext, nfp_flower_compile_tport(struct nfp_flower_tp_ports *ext,
struct nfp_flower_tp_ports *msk, struct nfp_flower_tp_ports *msk,
struct flow_cls_offload *flow) struct flow_rule *rule)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
memset(ext, 0, sizeof(struct nfp_flower_tp_ports)); memset(ext, 0, sizeof(struct nfp_flower_tp_ports));
memset(msk, 0, sizeof(struct nfp_flower_tp_ports)); memset(msk, 0, sizeof(struct nfp_flower_tp_ports));
...@@ -150,11 +144,8 @@ nfp_flower_compile_tport(struct nfp_flower_tp_ports *ext, ...@@ -150,11 +144,8 @@ nfp_flower_compile_tport(struct nfp_flower_tp_ports *ext,
static void static void
nfp_flower_compile_ip_ext(struct nfp_flower_ip_ext *ext, nfp_flower_compile_ip_ext(struct nfp_flower_ip_ext *ext,
struct nfp_flower_ip_ext *msk, struct nfp_flower_ip_ext *msk, struct flow_rule *rule)
struct flow_cls_offload *flow)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) { if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
struct flow_match_basic match; struct flow_match_basic match;
...@@ -224,10 +215,8 @@ nfp_flower_compile_ip_ext(struct nfp_flower_ip_ext *ext, ...@@ -224,10 +215,8 @@ nfp_flower_compile_ip_ext(struct nfp_flower_ip_ext *ext,
static void static void
nfp_flower_compile_ipv4(struct nfp_flower_ipv4 *ext, nfp_flower_compile_ipv4(struct nfp_flower_ipv4 *ext,
struct nfp_flower_ipv4 *msk, struct nfp_flower_ipv4 *msk, struct flow_rule *rule)
struct flow_cls_offload *flow)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
struct flow_match_ipv4_addrs match; struct flow_match_ipv4_addrs match;
memset(ext, 0, sizeof(struct nfp_flower_ipv4)); memset(ext, 0, sizeof(struct nfp_flower_ipv4));
...@@ -241,16 +230,13 @@ nfp_flower_compile_ipv4(struct nfp_flower_ipv4 *ext, ...@@ -241,16 +230,13 @@ nfp_flower_compile_ipv4(struct nfp_flower_ipv4 *ext,
msk->ipv4_dst = match.mask->dst; msk->ipv4_dst = match.mask->dst;
} }
nfp_flower_compile_ip_ext(&ext->ip_ext, &msk->ip_ext, flow); nfp_flower_compile_ip_ext(&ext->ip_ext, &msk->ip_ext, rule);
} }
static void static void
nfp_flower_compile_ipv6(struct nfp_flower_ipv6 *ext, nfp_flower_compile_ipv6(struct nfp_flower_ipv6 *ext,
struct nfp_flower_ipv6 *msk, struct nfp_flower_ipv6 *msk, struct flow_rule *rule)
struct flow_cls_offload *flow)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
memset(ext, 0, sizeof(struct nfp_flower_ipv6)); memset(ext, 0, sizeof(struct nfp_flower_ipv6));
memset(msk, 0, sizeof(struct nfp_flower_ipv6)); memset(msk, 0, sizeof(struct nfp_flower_ipv6));
...@@ -264,16 +250,15 @@ nfp_flower_compile_ipv6(struct nfp_flower_ipv6 *ext, ...@@ -264,16 +250,15 @@ nfp_flower_compile_ipv6(struct nfp_flower_ipv6 *ext,
msk->ipv6_dst = match.mask->dst; msk->ipv6_dst = match.mask->dst;
} }
nfp_flower_compile_ip_ext(&ext->ip_ext, &msk->ip_ext, flow); nfp_flower_compile_ip_ext(&ext->ip_ext, &msk->ip_ext, rule);
} }
static int static int
nfp_flower_compile_geneve_opt(void *ext, void *msk, nfp_flower_compile_geneve_opt(void *ext, void *msk, struct flow_rule *rule)
struct flow_cls_offload *flow)
{ {
struct flow_match_enc_opts match; struct flow_match_enc_opts match;
flow_rule_match_enc_opts(flow->rule, &match); flow_rule_match_enc_opts(rule, &match);
memcpy(ext, match.key->data, match.key->len); memcpy(ext, match.key->data, match.key->len);
memcpy(msk, match.mask->data, match.mask->len); memcpy(msk, match.mask->data, match.mask->len);
...@@ -283,10 +268,8 @@ nfp_flower_compile_geneve_opt(void *ext, void *msk, ...@@ -283,10 +268,8 @@ nfp_flower_compile_geneve_opt(void *ext, void *msk,
static void static void
nfp_flower_compile_tun_ipv4_addrs(struct nfp_flower_tun_ipv4 *ext, nfp_flower_compile_tun_ipv4_addrs(struct nfp_flower_tun_ipv4 *ext,
struct nfp_flower_tun_ipv4 *msk, struct nfp_flower_tun_ipv4 *msk,
struct flow_cls_offload *flow) struct flow_rule *rule)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) { if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) {
struct flow_match_ipv4_addrs match; struct flow_match_ipv4_addrs match;
...@@ -301,10 +284,8 @@ nfp_flower_compile_tun_ipv4_addrs(struct nfp_flower_tun_ipv4 *ext, ...@@ -301,10 +284,8 @@ nfp_flower_compile_tun_ipv4_addrs(struct nfp_flower_tun_ipv4 *ext,
static void static void
nfp_flower_compile_tun_ip_ext(struct nfp_flower_tun_ip_ext *ext, nfp_flower_compile_tun_ip_ext(struct nfp_flower_tun_ip_ext *ext,
struct nfp_flower_tun_ip_ext *msk, struct nfp_flower_tun_ip_ext *msk,
struct flow_cls_offload *flow) struct flow_rule *rule)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IP)) { if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IP)) {
struct flow_match_ip match; struct flow_match_ip match;
...@@ -319,10 +300,8 @@ nfp_flower_compile_tun_ip_ext(struct nfp_flower_tun_ip_ext *ext, ...@@ -319,10 +300,8 @@ nfp_flower_compile_tun_ip_ext(struct nfp_flower_tun_ip_ext *ext,
static void static void
nfp_flower_compile_ipv4_gre_tun(struct nfp_flower_ipv4_gre_tun *ext, nfp_flower_compile_ipv4_gre_tun(struct nfp_flower_ipv4_gre_tun *ext,
struct nfp_flower_ipv4_gre_tun *msk, struct nfp_flower_ipv4_gre_tun *msk,
struct flow_cls_offload *flow) struct flow_rule *rule)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
memset(ext, 0, sizeof(struct nfp_flower_ipv4_gre_tun)); memset(ext, 0, sizeof(struct nfp_flower_ipv4_gre_tun));
memset(msk, 0, sizeof(struct nfp_flower_ipv4_gre_tun)); memset(msk, 0, sizeof(struct nfp_flower_ipv4_gre_tun));
...@@ -341,17 +320,15 @@ nfp_flower_compile_ipv4_gre_tun(struct nfp_flower_ipv4_gre_tun *ext, ...@@ -341,17 +320,15 @@ nfp_flower_compile_ipv4_gre_tun(struct nfp_flower_ipv4_gre_tun *ext,
msk->tun_flags = cpu_to_be16(NFP_FL_GRE_FLAG_KEY); msk->tun_flags = cpu_to_be16(NFP_FL_GRE_FLAG_KEY);
} }
nfp_flower_compile_tun_ipv4_addrs(&ext->ipv4, &msk->ipv4, flow); nfp_flower_compile_tun_ipv4_addrs(&ext->ipv4, &msk->ipv4, rule);
nfp_flower_compile_tun_ip_ext(&ext->ip_ext, &msk->ip_ext, flow); nfp_flower_compile_tun_ip_ext(&ext->ip_ext, &msk->ip_ext, rule);
} }
static void static void
nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *ext, nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *ext,
struct nfp_flower_ipv4_udp_tun *msk, struct nfp_flower_ipv4_udp_tun *msk,
struct flow_cls_offload *flow) struct flow_rule *rule)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
memset(ext, 0, sizeof(struct nfp_flower_ipv4_udp_tun)); memset(ext, 0, sizeof(struct nfp_flower_ipv4_udp_tun));
memset(msk, 0, sizeof(struct nfp_flower_ipv4_udp_tun)); memset(msk, 0, sizeof(struct nfp_flower_ipv4_udp_tun));
...@@ -366,8 +343,8 @@ nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *ext, ...@@ -366,8 +343,8 @@ nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *ext,
msk->tun_id = cpu_to_be32(temp_vni); msk->tun_id = cpu_to_be32(temp_vni);
} }
nfp_flower_compile_tun_ipv4_addrs(&ext->ipv4, &msk->ipv4, flow); nfp_flower_compile_tun_ipv4_addrs(&ext->ipv4, &msk->ipv4, rule);
nfp_flower_compile_tun_ip_ext(&ext->ip_ext, &msk->ip_ext, flow); nfp_flower_compile_tun_ip_ext(&ext->ip_ext, &msk->ip_ext, rule);
} }
int nfp_flower_compile_flow_match(struct nfp_app *app, int nfp_flower_compile_flow_match(struct nfp_app *app,
...@@ -378,6 +355,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -378,6 +355,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
enum nfp_flower_tun_type tun_type, enum nfp_flower_tun_type tun_type,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct flow_rule *rule = flow_cls_offload_flow_rule(flow);
u32 port_id; u32 port_id;
int err; int err;
u8 *ext; u8 *ext;
...@@ -393,7 +371,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -393,7 +371,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
nfp_flower_compile_meta_tci((struct nfp_flower_meta_tci *)ext, nfp_flower_compile_meta_tci((struct nfp_flower_meta_tci *)ext,
(struct nfp_flower_meta_tci *)msk, (struct nfp_flower_meta_tci *)msk,
flow, key_ls->key_layer); rule, key_ls->key_layer);
ext += sizeof(struct nfp_flower_meta_tci); ext += sizeof(struct nfp_flower_meta_tci);
msk += sizeof(struct nfp_flower_meta_tci); msk += sizeof(struct nfp_flower_meta_tci);
...@@ -425,7 +403,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -425,7 +403,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
if (NFP_FLOWER_LAYER_MAC & key_ls->key_layer) { if (NFP_FLOWER_LAYER_MAC & key_ls->key_layer) {
nfp_flower_compile_mac((struct nfp_flower_mac_mpls *)ext, nfp_flower_compile_mac((struct nfp_flower_mac_mpls *)ext,
(struct nfp_flower_mac_mpls *)msk, (struct nfp_flower_mac_mpls *)msk,
flow); rule);
ext += sizeof(struct nfp_flower_mac_mpls); ext += sizeof(struct nfp_flower_mac_mpls);
msk += sizeof(struct nfp_flower_mac_mpls); msk += sizeof(struct nfp_flower_mac_mpls);
} }
...@@ -433,7 +411,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -433,7 +411,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
if (NFP_FLOWER_LAYER_TP & key_ls->key_layer) { if (NFP_FLOWER_LAYER_TP & key_ls->key_layer) {
nfp_flower_compile_tport((struct nfp_flower_tp_ports *)ext, nfp_flower_compile_tport((struct nfp_flower_tp_ports *)ext,
(struct nfp_flower_tp_ports *)msk, (struct nfp_flower_tp_ports *)msk,
flow); rule);
ext += sizeof(struct nfp_flower_tp_ports); ext += sizeof(struct nfp_flower_tp_ports);
msk += sizeof(struct nfp_flower_tp_ports); msk += sizeof(struct nfp_flower_tp_ports);
} }
...@@ -441,7 +419,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -441,7 +419,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
if (NFP_FLOWER_LAYER_IPV4 & key_ls->key_layer) { if (NFP_FLOWER_LAYER_IPV4 & key_ls->key_layer) {
nfp_flower_compile_ipv4((struct nfp_flower_ipv4 *)ext, nfp_flower_compile_ipv4((struct nfp_flower_ipv4 *)ext,
(struct nfp_flower_ipv4 *)msk, (struct nfp_flower_ipv4 *)msk,
flow); rule);
ext += sizeof(struct nfp_flower_ipv4); ext += sizeof(struct nfp_flower_ipv4);
msk += sizeof(struct nfp_flower_ipv4); msk += sizeof(struct nfp_flower_ipv4);
} }
...@@ -449,7 +427,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -449,7 +427,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
if (NFP_FLOWER_LAYER_IPV6 & key_ls->key_layer) { if (NFP_FLOWER_LAYER_IPV6 & key_ls->key_layer) {
nfp_flower_compile_ipv6((struct nfp_flower_ipv6 *)ext, nfp_flower_compile_ipv6((struct nfp_flower_ipv6 *)ext,
(struct nfp_flower_ipv6 *)msk, (struct nfp_flower_ipv6 *)msk,
flow); rule);
ext += sizeof(struct nfp_flower_ipv6); ext += sizeof(struct nfp_flower_ipv6);
msk += sizeof(struct nfp_flower_ipv6); msk += sizeof(struct nfp_flower_ipv6);
} }
...@@ -457,7 +435,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -457,7 +435,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
if (key_ls->key_layer_two & NFP_FLOWER_LAYER2_GRE) { if (key_ls->key_layer_two & NFP_FLOWER_LAYER2_GRE) {
__be32 tun_dst; __be32 tun_dst;
nfp_flower_compile_ipv4_gre_tun((void *)ext, (void *)msk, flow); nfp_flower_compile_ipv4_gre_tun((void *)ext, (void *)msk, rule);
tun_dst = ((struct nfp_flower_ipv4_gre_tun *)ext)->ipv4.dst; tun_dst = ((struct nfp_flower_ipv4_gre_tun *)ext)->ipv4.dst;
ext += sizeof(struct nfp_flower_ipv4_gre_tun); ext += sizeof(struct nfp_flower_ipv4_gre_tun);
msk += sizeof(struct nfp_flower_ipv4_gre_tun); msk += sizeof(struct nfp_flower_ipv4_gre_tun);
...@@ -473,7 +451,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -473,7 +451,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
key_ls->key_layer_two & NFP_FLOWER_LAYER2_GENEVE) { key_ls->key_layer_two & NFP_FLOWER_LAYER2_GENEVE) {
__be32 tun_dst; __be32 tun_dst;
nfp_flower_compile_ipv4_udp_tun((void *)ext, (void *)msk, flow); nfp_flower_compile_ipv4_udp_tun((void *)ext, (void *)msk, rule);
tun_dst = ((struct nfp_flower_ipv4_udp_tun *)ext)->ipv4.dst; tun_dst = ((struct nfp_flower_ipv4_udp_tun *)ext)->ipv4.dst;
ext += sizeof(struct nfp_flower_ipv4_udp_tun); ext += sizeof(struct nfp_flower_ipv4_udp_tun);
msk += sizeof(struct nfp_flower_ipv4_udp_tun); msk += sizeof(struct nfp_flower_ipv4_udp_tun);
...@@ -485,7 +463,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -485,7 +463,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
nfp_tunnel_add_ipv4_off(app, tun_dst); nfp_tunnel_add_ipv4_off(app, tun_dst);
if (key_ls->key_layer_two & NFP_FLOWER_LAYER2_GENEVE_OP) { if (key_ls->key_layer_two & NFP_FLOWER_LAYER2_GENEVE_OP) {
err = nfp_flower_compile_geneve_opt(ext, msk, flow); err = nfp_flower_compile_geneve_opt(ext, msk, rule);
if (err) if (err)
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment