1 From 0d4636f7d72df3179b20a2d32b647881917a5e2a Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Wed, 12 Oct 2022 19:18:37 +0200
4 Subject: [PATCH 2/2] net: dsa: qca8k: fix ethtool autocast mib for big-endian
7 The switch sends autocast mib in little-endian. This is problematic for
8 big-endian system as the values needs to be converted.
10 Fix this by converting each mib value to cpu byte order.
12 Fixes: 5c957c7ca78c ("net: dsa: qca8k: add support for mib autocast in Ethernet packet")
13 Tested-by: Pawel Dembicki <paweldembicki@gmail.com>
14 Tested-by: Lech Perczak <lech.perczak@gmail.com>
15 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
18 drivers/net/dsa/qca/qca8k-8xxx.c | 20 ++++++++------------
19 include/linux/dsa/tag_qca.h | 2 +-
20 2 files changed, 9 insertions(+), 13 deletions(-)
22 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
23 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
24 @@ -1668,9 +1668,9 @@ static void qca8k_mib_autocast_handler(s
25 struct qca8k_priv *priv = ds->priv;
26 const struct qca8k_mib_desc *mib;
27 struct mib_ethhdr *mib_ethhdr;
28 - int i, mib_len, offset = 0;
34 mib_ethhdr = (struct mib_ethhdr *)skb_mac_header(skb);
35 mib_eth_data = &priv->mib_eth_data;
36 @@ -1682,28 +1682,24 @@ static void qca8k_mib_autocast_handler(s
37 if (port != mib_eth_data->req_port)
40 - data = mib_eth_data->data;
41 + data2 = (__le32 *)skb->data;
43 for (i = 0; i < priv->info->mib_count; i++) {
46 /* First 3 mib are present in the skb head */
48 - data[i] = mib_ethhdr->data[i];
49 + mib_eth_data->data[i] = get_unaligned_le32(mib_ethhdr->data + i);
53 - mib_len = sizeof(uint32_t);
55 /* Some mib are 64 bit wide */
57 - mib_len = sizeof(uint64_t);
59 - /* Copy the mib value from packet to the */
60 - memcpy(data + i, skb->data + offset, mib_len);
61 + mib_eth_data->data[i] = get_unaligned_le64((__le64 *)data2);
63 + mib_eth_data->data[i] = get_unaligned_le32(data2);
65 - /* Set the offset for the next mib */
71 --- a/include/linux/dsa/tag_qca.h
72 +++ b/include/linux/dsa/tag_qca.h
73 @@ -68,7 +68,7 @@ enum mdio_cmd {
77 - u32 data[3]; /* first 3 mib counter */
78 + __le32 data[3]; /* first 3 mib counter */
79 __be16 hdr; /* qca hdr */