Skip to content

Commit d8c964d

Browse files
atenartdavem330
authored andcommitted
net: mscc: improve the frame header parsing readability
This cosmetic patch improves the frame header parsing readability by introducing a new macro to access and mask its fields. Signed-off-by: Antoine Tenart <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 45bce17 commit d8c964d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

drivers/net/ethernet/mscc/ocelot_board.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@
1616

1717
#include "ocelot.h"
1818

19-
static int ocelot_parse_ifh(u32 *ifh, struct frame_info *info)
19+
#define IFH_EXTRACT_BITFIELD64(x, o, w) (((x) >> (o)) & GENMASK_ULL((w) - 1, 0))
20+
21+
static int ocelot_parse_ifh(u32 *_ifh, struct frame_info *info)
2022
{
21-
int i;
2223
u8 llen, wlen;
24+
u64 ifh[2];
25+
26+
ifh[0] = be64_to_cpu(((__force __be64 *)_ifh)[0]);
27+
ifh[1] = be64_to_cpu(((__force __be64 *)_ifh)[1]);
2328

24-
/* The IFH is in network order, switch to CPU order */
25-
for (i = 0; i < IFH_LEN; i++)
26-
ifh[i] = ntohl((__force __be32)ifh[i]);
29+
wlen = IFH_EXTRACT_BITFIELD64(ifh[0], 7, 8);
30+
llen = IFH_EXTRACT_BITFIELD64(ifh[0], 15, 6);
2731

28-
wlen = (ifh[1] >> 7) & 0xff;
29-
llen = (ifh[1] >> 15) & 0x3f;
3032
info->len = OCELOT_BUFFER_CELL_SZ * wlen + llen - 80;
3133

32-
info->port = (ifh[2] & GENMASK(14, 11)) >> 11;
34+
info->port = IFH_EXTRACT_BITFIELD64(ifh[1], 43, 4);
3335

34-
info->cpuq = (ifh[3] & GENMASK(27, 20)) >> 20;
35-
info->tag_type = (ifh[3] & BIT(16)) >> 16;
36-
info->vid = ifh[3] & GENMASK(11, 0);
36+
info->cpuq = IFH_EXTRACT_BITFIELD64(ifh[1], 20, 8);
37+
info->tag_type = IFH_EXTRACT_BITFIELD64(ifh[1], 16, 1);
38+
info->vid = IFH_EXTRACT_BITFIELD64(ifh[1], 0, 12);
3739

3840
return 0;
3941
}

0 commit comments

Comments
 (0)