d13014bf93bdf90f7ca055d02b5ff57e018c3159
[openwrt/staging/ldir.git] /
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
5 systems
6
7 The switch sends autocast mib in little-endian. This is problematic for
8 big-endian system as the values needs to be converted.
9
10 Fix this by converting each mib value to cpu byte order.
11
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>
17 ---
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(-)
21
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;
29 - u64 *data;
30 + __le32 *data2;
31 u8 port;
32 + int i;
33
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)
38 goto exit;
39
40 - data = mib_eth_data->data;
41 + data2 = (__le32 *)skb->data;
42
43 for (i = 0; i < priv->info->mib_count; i++) {
44 mib = &ar8327_mib[i];
45
46 /* First 3 mib are present in the skb head */
47 if (i < 3) {
48 - data[i] = mib_ethhdr->data[i];
49 + mib_eth_data->data[i] = get_unaligned_le32(mib_ethhdr->data + i);
50 continue;
51 }
52
53 - mib_len = sizeof(uint32_t);
54 -
55 /* Some mib are 64 bit wide */
56 if (mib->size == 2)
57 - mib_len = sizeof(uint64_t);
58 -
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);
62 + else
63 + mib_eth_data->data[i] = get_unaligned_le32(data2);
64
65 - /* Set the offset for the next mib */
66 - offset += mib_len;
67 + data2 += mib->size;
68 }
69
70 exit:
71 --- a/include/linux/dsa/tag_qca.h
72 +++ b/include/linux/dsa/tag_qca.h
73 @@ -68,7 +68,7 @@ enum mdio_cmd {
74 };
75
76 struct mib_ethhdr {
77 - u32 data[3]; /* first 3 mib counter */
78 + __le32 data[3]; /* first 3 mib counter */
79 __be16 hdr; /* qca hdr */
80 } __packed;
81