Skip to content

Commit 0d4636f

Browse files
Ansueldavem330
authored andcommitted
net: dsa: qca8k: fix ethtool autocast mib for big-endian systems
The switch sends autocast mib in little-endian. This is problematic for big-endian system as the values needs to be converted. Fix this by converting each mib value to cpu byte order. Fixes: 5c957c7 ("net: dsa: qca8k: add support for mib autocast in Ethernet packet") Tested-by: Pawel Dembicki <[email protected]> Tested-by: Lech Perczak <[email protected]> Signed-off-by: Christian Marangi <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a2550d3 commit 0d4636f

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

drivers/net/dsa/qca/qca8k-8xxx.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,9 +1518,9 @@ static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *sk
15181518
struct qca8k_priv *priv = ds->priv;
15191519
const struct qca8k_mib_desc *mib;
15201520
struct mib_ethhdr *mib_ethhdr;
1521-
int i, mib_len, offset = 0;
1522-
u64 *data;
1521+
__le32 *data2;
15231522
u8 port;
1523+
int i;
15241524

15251525
mib_ethhdr = (struct mib_ethhdr *)skb_mac_header(skb);
15261526
mib_eth_data = &priv->mib_eth_data;
@@ -1532,28 +1532,24 @@ static void qca8k_mib_autocast_handler(struct dsa_switch *ds, struct sk_buff *sk
15321532
if (port != mib_eth_data->req_port)
15331533
goto exit;
15341534

1535-
data = mib_eth_data->data;
1535+
data2 = (__le32 *)skb->data;
15361536

15371537
for (i = 0; i < priv->info->mib_count; i++) {
15381538
mib = &ar8327_mib[i];
15391539

15401540
/* First 3 mib are present in the skb head */
15411541
if (i < 3) {
1542-
data[i] = mib_ethhdr->data[i];
1542+
mib_eth_data->data[i] = get_unaligned_le32(mib_ethhdr->data + i);
15431543
continue;
15441544
}
15451545

1546-
mib_len = sizeof(uint32_t);
1547-
15481546
/* Some mib are 64 bit wide */
15491547
if (mib->size == 2)
1550-
mib_len = sizeof(uint64_t);
1551-
1552-
/* Copy the mib value from packet to the */
1553-
memcpy(data + i, skb->data + offset, mib_len);
1548+
mib_eth_data->data[i] = get_unaligned_le64((__le64 *)data2);
1549+
else
1550+
mib_eth_data->data[i] = get_unaligned_le32(data2);
15541551

1555-
/* Set the offset for the next mib */
1556-
offset += mib_len;
1552+
data2 += mib->size;
15571553
}
15581554

15591555
exit:

include/linux/dsa/tag_qca.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum mdio_cmd {
7373
};
7474

7575
struct mib_ethhdr {
76-
u32 data[3]; /* first 3 mib counter */
76+
__le32 data[3]; /* first 3 mib counter */
7777
__be16 hdr; /* qca hdr */
7878
} __packed;
7979

0 commit comments

Comments
 (0)