Skip to content

Commit 27f78cb

Browse files
chelsiocudbgdavem330
authored andcommitted
cxgb4: parse TC-U32 key values and masks natively
TC-U32 passes all keys values and masks in __be32 format. The parser already expects this and hence pass the value and masks in __be32 natively to the parser. Fixes following sparse warnings in several places: cxgb4_tc_u32.c:57:21: warning: incorrect type in assignment (different base types) cxgb4_tc_u32.c:57:21: expected unsigned int [usertype] val cxgb4_tc_u32.c:57:21: got restricted __be32 [usertype] val cxgb4_tc_u32_parse.h:48:24: warning: cast to restricted __be32 Fixes: 2e8aad7 ("cxgb4: add parser to translate u32 filters to internal spec") Signed-off-by: Rahul Lakkireddy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 589b1c9 commit 27f78cb

File tree

2 files changed

+91
-49
lines changed

2 files changed

+91
-49
lines changed

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int fill_match_fields(struct adapter *adap,
4848
bool next_header)
4949
{
5050
unsigned int i, j;
51-
u32 val, mask;
51+
__be32 val, mask;
5252
int off, err;
5353
bool found;
5454

@@ -228,7 +228,7 @@ int cxgb4_config_knode(struct net_device *dev, struct tc_cls_u32_offload *cls)
228228
const struct cxgb4_next_header *next;
229229
bool found = false;
230230
unsigned int i, j;
231-
u32 val, mask;
231+
__be32 val, mask;
232232
int off;
233233

234234
if (t->table[link_uhtid - 1].link_handle) {
@@ -242,10 +242,10 @@ int cxgb4_config_knode(struct net_device *dev, struct tc_cls_u32_offload *cls)
242242

243243
/* Try to find matches that allow jumps to next header. */
244244
for (i = 0; next[i].jump; i++) {
245-
if (next[i].offoff != cls->knode.sel->offoff ||
246-
next[i].shift != cls->knode.sel->offshift ||
247-
next[i].mask != cls->knode.sel->offmask ||
248-
next[i].offset != cls->knode.sel->off)
245+
if (next[i].sel.offoff != cls->knode.sel->offoff ||
246+
next[i].sel.offshift != cls->knode.sel->offshift ||
247+
next[i].sel.offmask != cls->knode.sel->offmask ||
248+
next[i].sel.off != cls->knode.sel->off)
249249
continue;
250250

251251
/* Found a possible candidate. Find a key that
@@ -257,9 +257,9 @@ int cxgb4_config_knode(struct net_device *dev, struct tc_cls_u32_offload *cls)
257257
val = cls->knode.sel->keys[j].val;
258258
mask = cls->knode.sel->keys[j].mask;
259259

260-
if (next[i].match_off == off &&
261-
next[i].match_val == val &&
262-
next[i].match_mask == mask) {
260+
if (next[i].key.off == off &&
261+
next[i].key.val == val &&
262+
next[i].key.mask == mask) {
263263
found = true;
264264
break;
265265
}

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32_parse.h

Lines changed: 82 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
struct cxgb4_match_field {
3939
int off; /* Offset from the beginning of the header to match */
4040
/* Fill the value/mask pair in the spec if matched */
41-
int (*val)(struct ch_filter_specification *f, u32 val, u32 mask);
41+
int (*val)(struct ch_filter_specification *f, __be32 val, __be32 mask);
4242
};
4343

4444
/* IPv4 match fields */
4545
static inline int cxgb4_fill_ipv4_tos(struct ch_filter_specification *f,
46-
u32 val, u32 mask)
46+
__be32 val, __be32 mask)
4747
{
4848
f->val.tos = (ntohl(val) >> 16) & 0x000000FF;
4949
f->mask.tos = (ntohl(mask) >> 16) & 0x000000FF;
@@ -52,7 +52,7 @@ static inline int cxgb4_fill_ipv4_tos(struct ch_filter_specification *f,
5252
}
5353

5454
static inline int cxgb4_fill_ipv4_frag(struct ch_filter_specification *f,
55-
u32 val, u32 mask)
55+
__be32 val, __be32 mask)
5656
{
5757
u32 mask_val;
5858
u8 frag_val;
@@ -74,7 +74,7 @@ static inline int cxgb4_fill_ipv4_frag(struct ch_filter_specification *f,
7474
}
7575

7676
static inline int cxgb4_fill_ipv4_proto(struct ch_filter_specification *f,
77-
u32 val, u32 mask)
77+
__be32 val, __be32 mask)
7878
{
7979
f->val.proto = (ntohl(val) >> 16) & 0x000000FF;
8080
f->mask.proto = (ntohl(mask) >> 16) & 0x000000FF;
@@ -83,7 +83,7 @@ static inline int cxgb4_fill_ipv4_proto(struct ch_filter_specification *f,
8383
}
8484

8585
static inline int cxgb4_fill_ipv4_src_ip(struct ch_filter_specification *f,
86-
u32 val, u32 mask)
86+
__be32 val, __be32 mask)
8787
{
8888
memcpy(&f->val.fip[0], &val, sizeof(u32));
8989
memcpy(&f->mask.fip[0], &mask, sizeof(u32));
@@ -92,7 +92,7 @@ static inline int cxgb4_fill_ipv4_src_ip(struct ch_filter_specification *f,
9292
}
9393

9494
static inline int cxgb4_fill_ipv4_dst_ip(struct ch_filter_specification *f,
95-
u32 val, u32 mask)
95+
__be32 val, __be32 mask)
9696
{
9797
memcpy(&f->val.lip[0], &val, sizeof(u32));
9898
memcpy(&f->mask.lip[0], &mask, sizeof(u32));
@@ -111,7 +111,7 @@ static const struct cxgb4_match_field cxgb4_ipv4_fields[] = {
111111

112112
/* IPv6 match fields */
113113
static inline int cxgb4_fill_ipv6_tos(struct ch_filter_specification *f,
114-
u32 val, u32 mask)
114+
__be32 val, __be32 mask)
115115
{
116116
f->val.tos = (ntohl(val) >> 20) & 0x000000FF;
117117
f->mask.tos = (ntohl(mask) >> 20) & 0x000000FF;
@@ -120,7 +120,7 @@ static inline int cxgb4_fill_ipv6_tos(struct ch_filter_specification *f,
120120
}
121121

122122
static inline int cxgb4_fill_ipv6_proto(struct ch_filter_specification *f,
123-
u32 val, u32 mask)
123+
__be32 val, __be32 mask)
124124
{
125125
f->val.proto = (ntohl(val) >> 8) & 0x000000FF;
126126
f->mask.proto = (ntohl(mask) >> 8) & 0x000000FF;
@@ -129,7 +129,7 @@ static inline int cxgb4_fill_ipv6_proto(struct ch_filter_specification *f,
129129
}
130130

131131
static inline int cxgb4_fill_ipv6_src_ip0(struct ch_filter_specification *f,
132-
u32 val, u32 mask)
132+
__be32 val, __be32 mask)
133133
{
134134
memcpy(&f->val.fip[0], &val, sizeof(u32));
135135
memcpy(&f->mask.fip[0], &mask, sizeof(u32));
@@ -138,7 +138,7 @@ static inline int cxgb4_fill_ipv6_src_ip0(struct ch_filter_specification *f,
138138
}
139139

140140
static inline int cxgb4_fill_ipv6_src_ip1(struct ch_filter_specification *f,
141-
u32 val, u32 mask)
141+
__be32 val, __be32 mask)
142142
{
143143
memcpy(&f->val.fip[4], &val, sizeof(u32));
144144
memcpy(&f->mask.fip[4], &mask, sizeof(u32));
@@ -147,7 +147,7 @@ static inline int cxgb4_fill_ipv6_src_ip1(struct ch_filter_specification *f,
147147
}
148148

149149
static inline int cxgb4_fill_ipv6_src_ip2(struct ch_filter_specification *f,
150-
u32 val, u32 mask)
150+
__be32 val, __be32 mask)
151151
{
152152
memcpy(&f->val.fip[8], &val, sizeof(u32));
153153
memcpy(&f->mask.fip[8], &mask, sizeof(u32));
@@ -156,7 +156,7 @@ static inline int cxgb4_fill_ipv6_src_ip2(struct ch_filter_specification *f,
156156
}
157157

158158
static inline int cxgb4_fill_ipv6_src_ip3(struct ch_filter_specification *f,
159-
u32 val, u32 mask)
159+
__be32 val, __be32 mask)
160160
{
161161
memcpy(&f->val.fip[12], &val, sizeof(u32));
162162
memcpy(&f->mask.fip[12], &mask, sizeof(u32));
@@ -165,7 +165,7 @@ static inline int cxgb4_fill_ipv6_src_ip3(struct ch_filter_specification *f,
165165
}
166166

167167
static inline int cxgb4_fill_ipv6_dst_ip0(struct ch_filter_specification *f,
168-
u32 val, u32 mask)
168+
__be32 val, __be32 mask)
169169
{
170170
memcpy(&f->val.lip[0], &val, sizeof(u32));
171171
memcpy(&f->mask.lip[0], &mask, sizeof(u32));
@@ -174,7 +174,7 @@ static inline int cxgb4_fill_ipv6_dst_ip0(struct ch_filter_specification *f,
174174
}
175175

176176
static inline int cxgb4_fill_ipv6_dst_ip1(struct ch_filter_specification *f,
177-
u32 val, u32 mask)
177+
__be32 val, __be32 mask)
178178
{
179179
memcpy(&f->val.lip[4], &val, sizeof(u32));
180180
memcpy(&f->mask.lip[4], &mask, sizeof(u32));
@@ -183,7 +183,7 @@ static inline int cxgb4_fill_ipv6_dst_ip1(struct ch_filter_specification *f,
183183
}
184184

185185
static inline int cxgb4_fill_ipv6_dst_ip2(struct ch_filter_specification *f,
186-
u32 val, u32 mask)
186+
__be32 val, __be32 mask)
187187
{
188188
memcpy(&f->val.lip[8], &val, sizeof(u32));
189189
memcpy(&f->mask.lip[8], &mask, sizeof(u32));
@@ -192,7 +192,7 @@ static inline int cxgb4_fill_ipv6_dst_ip2(struct ch_filter_specification *f,
192192
}
193193

194194
static inline int cxgb4_fill_ipv6_dst_ip3(struct ch_filter_specification *f,
195-
u32 val, u32 mask)
195+
__be32 val, __be32 mask)
196196
{
197197
memcpy(&f->val.lip[12], &val, sizeof(u32));
198198
memcpy(&f->mask.lip[12], &mask, sizeof(u32));
@@ -216,7 +216,7 @@ static const struct cxgb4_match_field cxgb4_ipv6_fields[] = {
216216

217217
/* TCP/UDP match */
218218
static inline int cxgb4_fill_l4_ports(struct ch_filter_specification *f,
219-
u32 val, u32 mask)
219+
__be32 val, __be32 mask)
220220
{
221221
f->val.fport = ntohl(val) >> 16;
222222
f->mask.fport = ntohl(mask) >> 16;
@@ -237,19 +237,13 @@ static const struct cxgb4_match_field cxgb4_udp_fields[] = {
237237
};
238238

239239
struct cxgb4_next_header {
240-
unsigned int offset; /* Offset to next header */
241-
/* offset, shift, and mask added to offset above
240+
/* Offset, shift, and mask added to beginning of the header
242241
* to get to next header. Useful when using a header
243242
* field's value to jump to next header such as IHL field
244243
* in IPv4 header.
245244
*/
246-
unsigned int offoff;
247-
u32 shift;
248-
u32 mask;
249-
/* match criteria to make this jump */
250-
unsigned int match_off;
251-
u32 match_val;
252-
u32 match_mask;
245+
struct tc_u32_sel sel;
246+
struct tc_u32_key key;
253247
/* location of jump to make */
254248
const struct cxgb4_match_field *jump;
255249
};
@@ -258,26 +252,74 @@ struct cxgb4_next_header {
258252
* IPv4 header.
259253
*/
260254
static const struct cxgb4_next_header cxgb4_ipv4_jumps[] = {
261-
{ .offset = 0, .offoff = 0, .shift = 6, .mask = 0xF,
262-
.match_off = 8, .match_val = 0x600, .match_mask = 0xFF00,
263-
.jump = cxgb4_tcp_fields },
264-
{ .offset = 0, .offoff = 0, .shift = 6, .mask = 0xF,
265-
.match_off = 8, .match_val = 0x1100, .match_mask = 0xFF00,
266-
.jump = cxgb4_udp_fields },
267-
{ .jump = NULL }
255+
{
256+
/* TCP Jump */
257+
.sel = {
258+
.off = 0,
259+
.offoff = 0,
260+
.offshift = 6,
261+
.offmask = cpu_to_be16(0x0f00),
262+
},
263+
.key = {
264+
.off = 8,
265+
.val = cpu_to_be32(0x00060000),
266+
.mask = cpu_to_be32(0x00ff0000),
267+
},
268+
.jump = cxgb4_tcp_fields,
269+
},
270+
{
271+
/* UDP Jump */
272+
.sel = {
273+
.off = 0,
274+
.offoff = 0,
275+
.offshift = 6,
276+
.offmask = cpu_to_be16(0x0f00),
277+
},
278+
.key = {
279+
.off = 8,
280+
.val = cpu_to_be32(0x00110000),
281+
.mask = cpu_to_be32(0x00ff0000),
282+
},
283+
.jump = cxgb4_udp_fields,
284+
},
285+
{ .jump = NULL },
268286
};
269287

270288
/* Accept a rule with a jump directly past the 40 Bytes of IPv6 fixed header
271289
* to get to transport layer header.
272290
*/
273291
static const struct cxgb4_next_header cxgb4_ipv6_jumps[] = {
274-
{ .offset = 0x28, .offoff = 0, .shift = 0, .mask = 0,
275-
.match_off = 4, .match_val = 0x60000, .match_mask = 0xFF0000,
276-
.jump = cxgb4_tcp_fields },
277-
{ .offset = 0x28, .offoff = 0, .shift = 0, .mask = 0,
278-
.match_off = 4, .match_val = 0x110000, .match_mask = 0xFF0000,
279-
.jump = cxgb4_udp_fields },
280-
{ .jump = NULL }
292+
{
293+
/* TCP Jump */
294+
.sel = {
295+
.off = 40,
296+
.offoff = 0,
297+
.offshift = 0,
298+
.offmask = 0,
299+
},
300+
.key = {
301+
.off = 4,
302+
.val = cpu_to_be32(0x00000600),
303+
.mask = cpu_to_be32(0x0000ff00),
304+
},
305+
.jump = cxgb4_tcp_fields,
306+
},
307+
{
308+
/* UDP Jump */
309+
.sel = {
310+
.off = 40,
311+
.offoff = 0,
312+
.offshift = 0,
313+
.offmask = 0,
314+
},
315+
.key = {
316+
.off = 4,
317+
.val = cpu_to_be32(0x00001100),
318+
.mask = cpu_to_be32(0x0000ff00),
319+
},
320+
.jump = cxgb4_udp_fields,
321+
},
322+
{ .jump = NULL },
281323
};
282324

283325
struct cxgb4_link {

0 commit comments

Comments
 (0)