Skip to content

Commit da83d8f

Browse files
pjvuurendavem330
authored andcommitted
nfp: add set ethernet header action flower offload
Previously we did not have offloading support for set ethernet actions. This patch enables TC flower offload of set ethernet actions. Signed-off-by: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Simon Horman <simon.horman@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fc53b4a commit da83d8f

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <net/switchdev.h>
3737
#include <net/tc_act/tc_gact.h>
3838
#include <net/tc_act/tc_mirred.h>
39+
#include <net/tc_act/tc_pedit.h>
3940
#include <net/tc_act/tc_vlan.h>
4041
#include <net/tc_act/tc_tunnel_key.h>
4142

@@ -223,6 +224,87 @@ nfp_fl_set_vxlan(struct nfp_fl_set_vxlan *set_vxlan,
223224
return 0;
224225
}
225226

227+
static void nfp_fl_set_helper32(u32 value, u32 mask, u8 *p_exact, u8 *p_mask)
228+
{
229+
u32 oldvalue = get_unaligned((u32 *)p_exact);
230+
u32 oldmask = get_unaligned((u32 *)p_mask);
231+
232+
value &= mask;
233+
value |= oldvalue & ~mask;
234+
235+
put_unaligned(oldmask | mask, (u32 *)p_mask);
236+
put_unaligned(value, (u32 *)p_exact);
237+
}
238+
239+
static int
240+
nfp_fl_set_eth(const struct tc_action *action, int idx, u32 off,
241+
struct nfp_fl_set_eth *set_eth)
242+
{
243+
u16 tmp_set_eth_op;
244+
u32 exact, mask;
245+
246+
if (off + 4 > ETH_ALEN * 2)
247+
return -EOPNOTSUPP;
248+
249+
mask = ~tcf_pedit_mask(action, idx);
250+
exact = tcf_pedit_val(action, idx);
251+
252+
if (exact & ~mask)
253+
return -EOPNOTSUPP;
254+
255+
nfp_fl_set_helper32(exact, mask, &set_eth->eth_addr_val[off],
256+
&set_eth->eth_addr_mask[off]);
257+
258+
set_eth->reserved = cpu_to_be16(0);
259+
tmp_set_eth_op = FIELD_PREP(NFP_FL_ACT_LEN_LW,
260+
sizeof(*set_eth) >> NFP_FL_LW_SIZ) |
261+
FIELD_PREP(NFP_FL_ACT_JMP_ID,
262+
NFP_FL_ACTION_OPCODE_SET_ETHERNET);
263+
set_eth->a_op = cpu_to_be16(tmp_set_eth_op);
264+
265+
return 0;
266+
}
267+
268+
static int
269+
nfp_fl_pedit(const struct tc_action *action, char *nfp_action, int *a_len)
270+
{
271+
struct nfp_fl_set_eth set_eth;
272+
enum pedit_header_type htype;
273+
int idx, nkeys, err;
274+
size_t act_size;
275+
u32 offset, cmd;
276+
277+
memset(&set_eth, 0, sizeof(set_eth));
278+
nkeys = tcf_pedit_nkeys(action);
279+
280+
for (idx = 0; idx < nkeys; idx++) {
281+
cmd = tcf_pedit_cmd(action, idx);
282+
htype = tcf_pedit_htype(action, idx);
283+
offset = tcf_pedit_offset(action, idx);
284+
285+
if (cmd != TCA_PEDIT_KEY_EX_CMD_SET)
286+
return -EOPNOTSUPP;
287+
288+
switch (htype) {
289+
case TCA_PEDIT_KEY_EX_HDR_TYPE_ETH:
290+
err = nfp_fl_set_eth(action, idx, offset, &set_eth);
291+
break;
292+
default:
293+
return -EOPNOTSUPP;
294+
}
295+
if (err)
296+
return err;
297+
}
298+
299+
if (set_eth.a_op) {
300+
act_size = sizeof(set_eth);
301+
memcpy(nfp_action, &set_eth, act_size);
302+
*a_len += act_size;
303+
}
304+
305+
return 0;
306+
}
307+
226308
static int
227309
nfp_flower_loop_action(const struct tc_action *a,
228310
struct nfp_fl_payload *nfp_fl, int *a_len,
@@ -301,6 +383,9 @@ nfp_flower_loop_action(const struct tc_action *a,
301383
} else if (is_tcf_tunnel_release(a)) {
302384
/* Tunnel decap is handled by default so accept action. */
303385
return 0;
386+
} else if (is_tcf_pedit(a)) {
387+
if (nfp_fl_pedit(a, &nfp_fl->action_data[*a_len], a_len))
388+
return -EOPNOTSUPP;
304389
} else {
305390
/* Currently we do not handle any other actions. */
306391
return -EOPNOTSUPP;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1
7878
#define NFP_FL_ACTION_OPCODE_POP_VLAN 2
7979
#define NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL 6
80+
#define NFP_FL_ACTION_OPCODE_SET_ETHERNET 7
8081
#define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17
8182
#define NFP_FL_ACTION_OPCODE_NUM 32
8283

@@ -107,6 +108,13 @@ enum nfp_flower_tun_type {
107108
NFP_FL_TUNNEL_VXLAN = 2,
108109
};
109110

111+
struct nfp_fl_set_eth {
112+
__be16 a_op;
113+
__be16 reserved;
114+
u8 eth_addr_mask[ETH_ALEN * 2];
115+
u8 eth_addr_val[ETH_ALEN * 2];
116+
};
117+
110118
struct nfp_fl_output {
111119
__be16 a_op;
112120
__be16 flags;

0 commit comments

Comments
 (0)