Skip to content

Commit 1a1e586

Browse files
pjvuurendavem330
authored andcommitted
nfp: add basic action capabilities to flower offloads
Adds push vlan, pop vlan, output and drop action capabilities to flower offloads. Signed-off-by: Pieter Jansen van Vuuren <[email protected]> Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5571e8c commit 1a1e586

File tree

5 files changed

+271
-0
lines changed

5 files changed

+271
-0
lines changed

drivers/net/ethernet/netronome/nfp/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ nfp-objs := \
3131

3232
ifeq ($(CONFIG_NFP_APP_FLOWER),y)
3333
nfp-objs += \
34+
flower/action.o \
3435
flower/cmsg.o \
3536
flower/main.o \
3637
flower/match.o \
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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+
#include <linux/bitfield.h>
35+
#include <net/pkt_cls.h>
36+
#include <net/switchdev.h>
37+
#include <net/tc_act/tc_gact.h>
38+
#include <net/tc_act/tc_mirred.h>
39+
#include <net/tc_act/tc_vlan.h>
40+
41+
#include "cmsg.h"
42+
#include "main.h"
43+
#include "../nfp_net_repr.h"
44+
45+
static void nfp_fl_pop_vlan(struct nfp_fl_pop_vlan *pop_vlan)
46+
{
47+
size_t act_size = sizeof(struct nfp_fl_pop_vlan);
48+
u16 tmp_pop_vlan_op;
49+
50+
tmp_pop_vlan_op =
51+
FIELD_PREP(NFP_FL_ACT_LEN_LW, act_size >> NFP_FL_LW_SIZ) |
52+
FIELD_PREP(NFP_FL_ACT_JMP_ID, NFP_FL_ACTION_OPCODE_POP_VLAN);
53+
54+
pop_vlan->a_op = cpu_to_be16(tmp_pop_vlan_op);
55+
pop_vlan->reserved = 0;
56+
}
57+
58+
static void
59+
nfp_fl_push_vlan(struct nfp_fl_push_vlan *push_vlan,
60+
const struct tc_action *action)
61+
{
62+
size_t act_size = sizeof(struct nfp_fl_push_vlan);
63+
struct tcf_vlan *vlan = to_vlan(action);
64+
u16 tmp_push_vlan_tci;
65+
u16 tmp_push_vlan_op;
66+
67+
tmp_push_vlan_op =
68+
FIELD_PREP(NFP_FL_ACT_LEN_LW, act_size >> NFP_FL_LW_SIZ) |
69+
FIELD_PREP(NFP_FL_ACT_JMP_ID, NFP_FL_ACTION_OPCODE_PUSH_VLAN);
70+
71+
push_vlan->a_op = cpu_to_be16(tmp_push_vlan_op);
72+
/* Set action push vlan parameters. */
73+
push_vlan->reserved = 0;
74+
push_vlan->vlan_tpid = tcf_vlan_push_proto(action);
75+
76+
tmp_push_vlan_tci =
77+
FIELD_PREP(NFP_FL_PUSH_VLAN_PRIO, vlan->tcfv_push_prio) |
78+
FIELD_PREP(NFP_FL_PUSH_VLAN_VID, vlan->tcfv_push_vid) |
79+
NFP_FL_PUSH_VLAN_CFI;
80+
push_vlan->vlan_tci = cpu_to_be16(tmp_push_vlan_tci);
81+
}
82+
83+
static int
84+
nfp_fl_output(struct nfp_fl_output *output, const struct tc_action *action,
85+
struct nfp_fl_payload *nfp_flow, bool last,
86+
struct net_device *in_dev)
87+
{
88+
size_t act_size = sizeof(struct nfp_fl_output);
89+
struct net_device *out_dev;
90+
u16 tmp_output_op;
91+
int ifindex;
92+
93+
/* Set action opcode to output action. */
94+
tmp_output_op =
95+
FIELD_PREP(NFP_FL_ACT_LEN_LW, act_size >> NFP_FL_LW_SIZ) |
96+
FIELD_PREP(NFP_FL_ACT_JMP_ID, NFP_FL_ACTION_OPCODE_OUTPUT);
97+
98+
output->a_op = cpu_to_be16(tmp_output_op);
99+
100+
/* Set action output parameters. */
101+
output->flags = cpu_to_be16(last ? NFP_FL_OUT_FLAGS_LAST : 0);
102+
103+
ifindex = tcf_mirred_ifindex(action);
104+
out_dev = __dev_get_by_index(dev_net(in_dev), ifindex);
105+
if (!out_dev)
106+
return -EOPNOTSUPP;
107+
108+
/* Only offload egress ports are on the same device as the ingress
109+
* port.
110+
*/
111+
if (!switchdev_port_same_parent_id(in_dev, out_dev))
112+
return -EOPNOTSUPP;
113+
114+
output->port = cpu_to_be32(nfp_repr_get_port_id(out_dev));
115+
if (!output->port)
116+
return -EOPNOTSUPP;
117+
118+
nfp_flow->meta.shortcut = output->port;
119+
120+
return 0;
121+
}
122+
123+
static int
124+
nfp_flower_loop_action(const struct tc_action *a,
125+
struct nfp_fl_payload *nfp_fl, int *a_len,
126+
struct net_device *netdev)
127+
{
128+
struct nfp_fl_push_vlan *psh_v;
129+
struct nfp_fl_pop_vlan *pop_v;
130+
struct nfp_fl_output *output;
131+
int err;
132+
133+
if (is_tcf_gact_shot(a)) {
134+
nfp_fl->meta.shortcut = cpu_to_be32(NFP_FL_SC_ACT_DROP);
135+
} else if (is_tcf_mirred_egress_redirect(a)) {
136+
if (*a_len + sizeof(struct nfp_fl_output) > NFP_FL_MAX_A_SIZ)
137+
return -EOPNOTSUPP;
138+
139+
output = (struct nfp_fl_output *)&nfp_fl->action_data[*a_len];
140+
err = nfp_fl_output(output, a, nfp_fl, true, netdev);
141+
if (err)
142+
return err;
143+
144+
*a_len += sizeof(struct nfp_fl_output);
145+
} else if (is_tcf_mirred_egress_mirror(a)) {
146+
if (*a_len + sizeof(struct nfp_fl_output) > NFP_FL_MAX_A_SIZ)
147+
return -EOPNOTSUPP;
148+
149+
output = (struct nfp_fl_output *)&nfp_fl->action_data[*a_len];
150+
err = nfp_fl_output(output, a, nfp_fl, false, netdev);
151+
if (err)
152+
return err;
153+
154+
*a_len += sizeof(struct nfp_fl_output);
155+
} else if (is_tcf_vlan(a) && tcf_vlan_action(a) == TCA_VLAN_ACT_POP) {
156+
if (*a_len + sizeof(struct nfp_fl_pop_vlan) > NFP_FL_MAX_A_SIZ)
157+
return -EOPNOTSUPP;
158+
159+
pop_v = (struct nfp_fl_pop_vlan *)&nfp_fl->action_data[*a_len];
160+
nfp_fl->meta.shortcut = cpu_to_be32(NFP_FL_SC_ACT_POPV);
161+
162+
nfp_fl_pop_vlan(pop_v);
163+
*a_len += sizeof(struct nfp_fl_pop_vlan);
164+
} else if (is_tcf_vlan(a) && tcf_vlan_action(a) == TCA_VLAN_ACT_PUSH) {
165+
if (*a_len + sizeof(struct nfp_fl_push_vlan) > NFP_FL_MAX_A_SIZ)
166+
return -EOPNOTSUPP;
167+
168+
psh_v = (struct nfp_fl_push_vlan *)&nfp_fl->action_data[*a_len];
169+
nfp_fl->meta.shortcut = cpu_to_be32(NFP_FL_SC_ACT_NULL);
170+
171+
nfp_fl_push_vlan(psh_v, a);
172+
*a_len += sizeof(struct nfp_fl_push_vlan);
173+
} else {
174+
/* Currently we do not handle any other actions. */
175+
return -EOPNOTSUPP;
176+
}
177+
178+
return 0;
179+
}
180+
181+
int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
182+
struct net_device *netdev,
183+
struct nfp_fl_payload *nfp_flow)
184+
{
185+
int act_len, act_cnt, err;
186+
const struct tc_action *a;
187+
LIST_HEAD(actions);
188+
189+
memset(nfp_flow->action_data, 0, NFP_FL_MAX_A_SIZ);
190+
nfp_flow->meta.act_len = 0;
191+
act_len = 0;
192+
act_cnt = 0;
193+
194+
tcf_exts_to_list(flow->exts, &actions);
195+
list_for_each_entry(a, &actions, list) {
196+
err = nfp_flower_loop_action(a, nfp_flow, &act_len, netdev);
197+
if (err)
198+
return err;
199+
act_cnt++;
200+
}
201+
202+
/* We optimise when the action list is small, this can unfortunately
203+
* not happen once we have more than one action in the action list.
204+
*/
205+
if (act_cnt > 1)
206+
nfp_flow->meta.shortcut = cpu_to_be32(NFP_FL_SC_ACT_NULL);
207+
208+
nfp_flow->meta.act_len = act_len;
209+
210+
return 0;
211+
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,51 @@
5656
#define NFP_FLOWER_MASK_VLAN_CFI BIT(12)
5757
#define NFP_FLOWER_MASK_VLAN_VID GENMASK(11, 0)
5858

59+
#define NFP_FL_SC_ACT_DROP 0x80000000
60+
#define NFP_FL_SC_ACT_USER 0x7D000000
61+
#define NFP_FL_SC_ACT_POPV 0x6A000000
62+
#define NFP_FL_SC_ACT_NULL 0x00000000
63+
64+
/* The maximum action list size (in bytes) supported by the NFP.
65+
*/
66+
#define NFP_FL_MAX_A_SIZ 1216
67+
#define NFP_FL_LW_SIZ 2
68+
69+
/* Action opcodes */
70+
#define NFP_FL_ACTION_OPCODE_OUTPUT 0
71+
#define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1
72+
#define NFP_FL_ACTION_OPCODE_POP_VLAN 2
73+
#define NFP_FL_ACTION_OPCODE_NUM 32
74+
75+
#define NFP_FL_ACT_JMP_ID GENMASK(15, 8)
76+
#define NFP_FL_ACT_LEN_LW GENMASK(7, 0)
77+
78+
#define NFP_FL_OUT_FLAGS_LAST BIT(15)
79+
#define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
80+
#define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
81+
82+
#define NFP_FL_PUSH_VLAN_PRIO GENMASK(15, 13)
83+
#define NFP_FL_PUSH_VLAN_CFI BIT(12)
84+
#define NFP_FL_PUSH_VLAN_VID GENMASK(11, 0)
85+
86+
struct nfp_fl_output {
87+
__be16 a_op;
88+
__be16 flags;
89+
__be32 port;
90+
};
91+
92+
struct nfp_fl_push_vlan {
93+
__be16 a_op;
94+
__be16 reserved;
95+
__be16 vlan_tpid;
96+
__be16 vlan_tci;
97+
};
98+
99+
struct nfp_fl_pop_vlan {
100+
__be16 a_op;
101+
__be16 reserved;
102+
};
103+
59104
/* Metadata without L2 (1W/4B)
60105
* ----------------------------------------------------------------
61106
* 3 2 1

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,8 @@ int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
7070
struct nfp_fl_key_ls *key_ls,
7171
struct net_device *netdev,
7272
struct nfp_fl_payload *nfp_flow);
73+
int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
74+
struct net_device *netdev,
75+
struct nfp_fl_payload *nfp_flow);
7376

7477
#endif

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,16 @@ nfp_flower_allocate_new(struct nfp_fl_key_ls *key_layer)
165165
if (!flow_pay->mask_data)
166166
goto err_free_unmasked;
167167

168+
flow_pay->action_data = kmalloc(NFP_FL_MAX_A_SIZ, GFP_KERNEL);
169+
if (!flow_pay->action_data)
170+
goto err_free_mask;
171+
168172
flow_pay->meta.flags = 0;
169173

170174
return flow_pay;
171175

176+
err_free_mask:
177+
kfree(flow_pay->mask_data);
172178
err_free_unmasked:
173179
kfree(flow_pay->unmasked_data);
174180
err_free_flow:
@@ -212,10 +218,15 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
212218
if (err)
213219
goto err_destroy_flow;
214220

221+
err = nfp_flower_compile_action(flow, netdev, flow_pay);
222+
if (err)
223+
goto err_destroy_flow;
224+
215225
/* TODO: Complete flower_add_offload. */
216226
err = -EOPNOTSUPP;
217227

218228
err_destroy_flow:
229+
kfree(flow_pay->action_data);
219230
kfree(flow_pay->mask_data);
220231
kfree(flow_pay->unmasked_data);
221232
kfree(flow_pay);

0 commit comments

Comments
 (0)