Skip to content

Commit 62d3f60

Browse files
pjvuurendavem330
authored andcommitted
nfp: use struct fields for 8 bit-wide access
Use direct access struct fields rather than PREP_FIELD() macros to manipulate the jump ID and length, both of which are exactly 8-bits wide. This simplifies the code somewhat. Signed-off-by: Simon Horman <simon.horman@netronome.com> Signed-off-by: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com> Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0cea8e2 commit 62d3f60

File tree

2 files changed

+39
-74
lines changed

2 files changed

+39
-74
lines changed

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

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@
4747
static void nfp_fl_pop_vlan(struct nfp_fl_pop_vlan *pop_vlan)
4848
{
4949
size_t act_size = sizeof(struct nfp_fl_pop_vlan);
50-
u16 tmp_pop_vlan_op;
5150

52-
tmp_pop_vlan_op =
53-
FIELD_PREP(NFP_FL_ACT_LEN_LW, act_size >> NFP_FL_LW_SIZ) |
54-
FIELD_PREP(NFP_FL_ACT_JMP_ID, NFP_FL_ACTION_OPCODE_POP_VLAN);
55-
56-
pop_vlan->a_op = cpu_to_be16(tmp_pop_vlan_op);
51+
pop_vlan->head.jump_id = NFP_FL_ACTION_OPCODE_POP_VLAN;
52+
pop_vlan->head.len_lw = act_size >> NFP_FL_LW_SIZ;
5753
pop_vlan->reserved = 0;
5854
}
5955

@@ -64,14 +60,9 @@ nfp_fl_push_vlan(struct nfp_fl_push_vlan *push_vlan,
6460
size_t act_size = sizeof(struct nfp_fl_push_vlan);
6561
struct tcf_vlan *vlan = to_vlan(action);
6662
u16 tmp_push_vlan_tci;
67-
u16 tmp_push_vlan_op;
68-
69-
tmp_push_vlan_op =
70-
FIELD_PREP(NFP_FL_ACT_LEN_LW, act_size >> NFP_FL_LW_SIZ) |
71-
FIELD_PREP(NFP_FL_ACT_JMP_ID, NFP_FL_ACTION_OPCODE_PUSH_VLAN);
7263

73-
push_vlan->a_op = cpu_to_be16(tmp_push_vlan_op);
74-
/* Set action push vlan parameters. */
64+
push_vlan->head.jump_id = NFP_FL_ACTION_OPCODE_PUSH_VLAN;
65+
push_vlan->head.len_lw = act_size >> NFP_FL_LW_SIZ;
7566
push_vlan->reserved = 0;
7667
push_vlan->vlan_tpid = tcf_vlan_push_proto(action);
7768

@@ -101,16 +92,12 @@ nfp_fl_output(struct nfp_fl_output *output, const struct tc_action *action,
10192
int *tun_out_cnt)
10293
{
10394
size_t act_size = sizeof(struct nfp_fl_output);
104-
u16 tmp_output_op, tmp_flags;
10595
struct net_device *out_dev;
96+
u16 tmp_flags;
10697
int ifindex;
10798

108-
/* Set action opcode to output action. */
109-
tmp_output_op =
110-
FIELD_PREP(NFP_FL_ACT_LEN_LW, act_size >> NFP_FL_LW_SIZ) |
111-
FIELD_PREP(NFP_FL_ACT_JMP_ID, NFP_FL_ACTION_OPCODE_OUTPUT);
112-
113-
output->a_op = cpu_to_be16(tmp_output_op);
99+
output->head.jump_id = NFP_FL_ACTION_OPCODE_OUTPUT;
100+
output->head.len_lw = act_size >> NFP_FL_LW_SIZ;
114101

115102
ifindex = tcf_mirred_ifindex(action);
116103
out_dev = __dev_get_by_index(dev_net(in_dev), ifindex);
@@ -161,7 +148,6 @@ static struct nfp_fl_pre_tunnel *nfp_fl_pre_tunnel(char *act_data, int act_len)
161148
{
162149
size_t act_size = sizeof(struct nfp_fl_pre_tunnel);
163150
struct nfp_fl_pre_tunnel *pre_tun_act;
164-
u16 tmp_pre_tun_op;
165151

166152
/* Pre_tunnel action must be first on action list.
167153
* If other actions already exist they need pushed forward.
@@ -173,11 +159,8 @@ static struct nfp_fl_pre_tunnel *nfp_fl_pre_tunnel(char *act_data, int act_len)
173159

174160
memset(pre_tun_act, 0, act_size);
175161

176-
tmp_pre_tun_op =
177-
FIELD_PREP(NFP_FL_ACT_LEN_LW, act_size >> NFP_FL_LW_SIZ) |
178-
FIELD_PREP(NFP_FL_ACT_JMP_ID, NFP_FL_ACTION_OPCODE_PRE_TUNNEL);
179-
180-
pre_tun_act->a_op = cpu_to_be16(tmp_pre_tun_op);
162+
pre_tun_act->head.jump_id = NFP_FL_ACTION_OPCODE_PRE_TUNNEL;
163+
pre_tun_act->head.len_lw = act_size >> NFP_FL_LW_SIZ;
181164

182165
return pre_tun_act;
183166
}
@@ -190,7 +173,6 @@ nfp_fl_set_vxlan(struct nfp_fl_set_vxlan *set_vxlan,
190173
struct ip_tunnel_info *vxlan = tcf_tunnel_info(action);
191174
size_t act_size = sizeof(struct nfp_fl_set_vxlan);
192175
u32 tmp_set_vxlan_type_index = 0;
193-
u16 tmp_set_vxlan_op;
194176
/* Currently support one pre-tunnel so index is always 0. */
195177
int pretun_idx = 0;
196178

@@ -199,12 +181,8 @@ nfp_fl_set_vxlan(struct nfp_fl_set_vxlan *set_vxlan,
199181
return -EOPNOTSUPP;
200182
}
201183

202-
tmp_set_vxlan_op =
203-
FIELD_PREP(NFP_FL_ACT_LEN_LW, act_size >> NFP_FL_LW_SIZ) |
204-
FIELD_PREP(NFP_FL_ACT_JMP_ID,
205-
NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL);
206-
207-
set_vxlan->a_op = cpu_to_be16(tmp_set_vxlan_op);
184+
set_vxlan->head.jump_id = NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL;
185+
set_vxlan->head.len_lw = act_size >> NFP_FL_LW_SIZ;
208186

209187
/* Set tunnel type and pre-tunnel index. */
210188
tmp_set_vxlan_type_index |=
@@ -240,7 +218,6 @@ static int
240218
nfp_fl_set_eth(const struct tc_action *action, int idx, u32 off,
241219
struct nfp_fl_set_eth *set_eth)
242220
{
243-
u16 tmp_set_eth_op;
244221
u32 exact, mask;
245222

246223
if (off + 4 > ETH_ALEN * 2)
@@ -256,11 +233,8 @@ nfp_fl_set_eth(const struct tc_action *action, int idx, u32 off,
256233
&set_eth->eth_addr_mask[off]);
257234

258235
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);
236+
set_eth->head.jump_id = NFP_FL_ACTION_OPCODE_SET_ETHERNET;
237+
set_eth->head.len_lw = sizeof(*set_eth) >> NFP_FL_LW_SIZ;
264238

265239
return 0;
266240
}
@@ -269,7 +243,6 @@ static int
269243
nfp_fl_set_ip4(const struct tc_action *action, int idx, u32 off,
270244
struct nfp_fl_set_ip4_addrs *set_ip_addr)
271245
{
272-
u16 tmp_set_ipv4_op;
273246
__be32 exact, mask;
274247

275248
/* We are expecting tcf_pedit to return a big endian value */
@@ -293,11 +266,8 @@ nfp_fl_set_ip4(const struct tc_action *action, int idx, u32 off,
293266
}
294267

295268
set_ip_addr->reserved = cpu_to_be16(0);
296-
tmp_set_ipv4_op = FIELD_PREP(NFP_FL_ACT_LEN_LW,
297-
sizeof(*set_ip_addr) >> NFP_FL_LW_SIZ) |
298-
FIELD_PREP(NFP_FL_ACT_JMP_ID,
299-
NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS);
300-
set_ip_addr->a_op = cpu_to_be16(tmp_set_ipv4_op);
269+
set_ip_addr->head.jump_id = NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS;
270+
set_ip_addr->head.len_lw = sizeof(*set_ip_addr) >> NFP_FL_LW_SIZ;
301271

302272
return 0;
303273
}
@@ -306,16 +276,12 @@ static void
306276
nfp_fl_set_ip6_helper(int opcode_tag, int idx, __be32 exact, __be32 mask,
307277
struct nfp_fl_set_ipv6_addr *ip6)
308278
{
309-
u16 tmp_set_op;
310-
311279
ip6->ipv6[idx % 4].mask = mask;
312280
ip6->ipv6[idx % 4].exact = exact;
313281

314282
ip6->reserved = cpu_to_be16(0);
315-
tmp_set_op = FIELD_PREP(NFP_FL_ACT_LEN_LW, sizeof(*ip6) >>
316-
NFP_FL_LW_SIZ) |
317-
FIELD_PREP(NFP_FL_ACT_JMP_ID, opcode_tag);
318-
ip6->a_op = cpu_to_be16(tmp_set_op);
283+
ip6->head.jump_id = opcode_tag;
284+
ip6->head.len_lw = sizeof(*ip6) >> NFP_FL_LW_SIZ;
319285
}
320286

321287
static int
@@ -352,7 +318,6 @@ nfp_fl_set_tport(const struct tc_action *action, int idx, u32 off,
352318
struct nfp_fl_set_tport *set_tport, int opcode)
353319
{
354320
u32 exact, mask;
355-
u16 tmp_set_op;
356321

357322
if (off)
358323
return -EOPNOTSUPP;
@@ -367,10 +332,8 @@ nfp_fl_set_tport(const struct tc_action *action, int idx, u32 off,
367332
set_tport->tp_port_mask);
368333

369334
set_tport->reserved = cpu_to_be16(0);
370-
tmp_set_op = FIELD_PREP(NFP_FL_ACT_LEN_LW,
371-
sizeof(*set_tport) >> NFP_FL_LW_SIZ);
372-
tmp_set_op |= FIELD_PREP(NFP_FL_ACT_JMP_ID, opcode);
373-
set_tport->a_op = cpu_to_be16(tmp_set_op);
335+
set_tport->head.jump_id = opcode;
336+
set_tport->head.len_lw = sizeof(*set_tport) >> NFP_FL_LW_SIZ;
374337

375338
return 0;
376339
}
@@ -428,15 +391,15 @@ nfp_fl_pedit(const struct tc_action *action, char *nfp_action, int *a_len)
428391
return err;
429392
}
430393

431-
if (set_eth.a_op) {
394+
if (set_eth.head.len_lw) {
432395
act_size = sizeof(set_eth);
433396
memcpy(nfp_action, &set_eth, act_size);
434397
*a_len += act_size;
435-
} else if (set_ip_addr.a_op) {
398+
} else if (set_ip_addr.head.len_lw) {
436399
act_size = sizeof(set_ip_addr);
437400
memcpy(nfp_action, &set_ip_addr, act_size);
438401
*a_len += act_size;
439-
} else if (set_ip6_dst.a_op && set_ip6_src.a_op) {
402+
} else if (set_ip6_dst.head.len_lw && set_ip6_src.head.len_lw) {
440403
/* TC compiles set src and dst IPv6 address as a single action,
441404
* the hardware requires this to be 2 separate actions.
442405
*/
@@ -448,15 +411,15 @@ nfp_fl_pedit(const struct tc_action *action, char *nfp_action, int *a_len)
448411
memcpy(&nfp_action[sizeof(set_ip6_src)], &set_ip6_dst,
449412
act_size);
450413
*a_len += act_size;
451-
} else if (set_ip6_dst.a_op) {
414+
} else if (set_ip6_dst.head.len_lw) {
452415
act_size = sizeof(set_ip6_dst);
453416
memcpy(nfp_action, &set_ip6_dst, act_size);
454417
*a_len += act_size;
455-
} else if (set_ip6_src.a_op) {
418+
} else if (set_ip6_src.head.len_lw) {
456419
act_size = sizeof(set_ip6_src);
457420
memcpy(nfp_action, &set_ip6_src, act_size);
458421
*a_len += act_size;
459-
} else if (set_tport.a_op) {
422+
} else if (set_tport.head.len_lw) {
460423
act_size = sizeof(set_tport);
461424
memcpy(nfp_action, &set_tport, act_size);
462425
*a_len += act_size;

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@
8686
#define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17
8787
#define NFP_FL_ACTION_OPCODE_NUM 32
8888

89-
#define NFP_FL_ACT_JMP_ID GENMASK(15, 8)
90-
#define NFP_FL_ACT_LEN_LW GENMASK(7, 0)
91-
9289
#define NFP_FL_OUT_FLAGS_LAST BIT(15)
9390
#define NFP_FL_OUT_FLAGS_USE_TUN BIT(4)
9491
#define NFP_FL_OUT_FLAGS_TYPE_IDX GENMASK(2, 0)
@@ -113,15 +110,20 @@ enum nfp_flower_tun_type {
113110
NFP_FL_TUNNEL_VXLAN = 2,
114111
};
115112

113+
struct nfp_fl_act_head {
114+
u8 jump_id;
115+
u8 len_lw;
116+
};
117+
116118
struct nfp_fl_set_eth {
117-
__be16 a_op;
119+
struct nfp_fl_act_head head;
118120
__be16 reserved;
119121
u8 eth_addr_mask[ETH_ALEN * 2];
120122
u8 eth_addr_val[ETH_ALEN * 2];
121123
};
122124

123125
struct nfp_fl_set_ip4_addrs {
124-
__be16 a_op;
126+
struct nfp_fl_act_head head;
125127
__be16 reserved;
126128
__be32 ipv4_src_mask;
127129
__be32 ipv4_src;
@@ -130,7 +132,7 @@ struct nfp_fl_set_ip4_addrs {
130132
};
131133

132134
struct nfp_fl_set_ipv6_addr {
133-
__be16 a_op;
135+
struct nfp_fl_act_head head;
134136
__be16 reserved;
135137
struct {
136138
__be32 mask;
@@ -139,27 +141,27 @@ struct nfp_fl_set_ipv6_addr {
139141
};
140142

141143
struct nfp_fl_set_tport {
142-
__be16 a_op;
144+
struct nfp_fl_act_head head;
143145
__be16 reserved;
144146
u8 tp_port_mask[4];
145147
u8 tp_port_val[4];
146148
};
147149

148150
struct nfp_fl_output {
149-
__be16 a_op;
151+
struct nfp_fl_act_head head;
150152
__be16 flags;
151153
__be32 port;
152154
};
153155

154156
struct nfp_fl_push_vlan {
155-
__be16 a_op;
157+
struct nfp_fl_act_head head;
156158
__be16 reserved;
157159
__be16 vlan_tpid;
158160
__be16 vlan_tci;
159161
};
160162

161163
struct nfp_fl_pop_vlan {
162-
__be16 a_op;
164+
struct nfp_fl_act_head head;
163165
__be16 reserved;
164166
};
165167

@@ -178,15 +180,15 @@ struct nfp_flower_meta_one {
178180
};
179181

180182
struct nfp_fl_pre_tunnel {
181-
__be16 a_op;
183+
struct nfp_fl_act_head head;
182184
__be16 reserved;
183185
__be32 ipv4_dst;
184186
/* reserved for use with IPv6 addresses */
185187
__be32 extra[3];
186188
};
187189

188190
struct nfp_fl_set_vxlan {
189-
__be16 a_op;
191+
struct nfp_fl_act_head head;
190192
__be16 reserved;
191193
__be64 tun_id;
192194
__be32 tun_type_index;

0 commit comments

Comments
 (0)