kernel: 5.15: update Aquantia PHY driver to v6.1 code
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 777-v6.2-01-net-dsa-qca8k-fix-wrong-length-value-for-mgmt-eth-pa.patch
1 From 9807ae69746196ee4bbffe7d22d22ab2b61c6ed0 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Thu, 29 Dec 2022 17:33:32 +0100
4 Subject: [PATCH 1/5] net: dsa: qca8k: fix wrong length value for mgmt eth
5 packet
6
7 The assumption that Documentation was right about how this value work was
8 wrong. It was discovered that the length value of the mgmt header is in
9 step of word size.
10
11 As an example to process 4 byte of data the correct length to set is 2.
12 To process 8 byte 4, 12 byte 6, 16 byte 8...
13
14 Odd values will always return the next size on the ack packet.
15 (length of 3 (6 byte) will always return 8 bytes of data)
16
17 This means that a value of 15 (0xf) actually means reading/writing 32 bytes
18 of data instead of 16 bytes. This behaviour is totally absent and not
19 documented in the switch Documentation.
20
21 In fact from Documentation the max value that mgmt eth can process is
22 16 byte of data while in reality it can process 32 bytes at once.
23
24 To handle this we always round up the length after deviding it for word
25 size. We check if the result is odd and we round another time to align
26 to what the switch will provide in the ack packet.
27 The workaround for the length limit of 15 is still needed as the length
28 reg max value is 0xf(15)
29
30 Reported-by: Ronald Wahl <ronald.wahl@raritan.com>
31 Tested-by: Ronald Wahl <ronald.wahl@raritan.com>
32 Fixes: 90386223f44e ("net: dsa: qca8k: add support for larger read/write size with mgmt Ethernet")
33 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
34 Cc: stable@vger.kernel.org # v5.18+
35 Signed-off-by: David S. Miller <davem@davemloft.net>
36 ---
37 drivers/net/dsa/qca/qca8k-8xxx.c | 45 +++++++++++++++++++++++++-------
38 1 file changed, 35 insertions(+), 10 deletions(-)
39
40 --- a/drivers/net/dsa/qca/qca8k-8xxx.c
41 +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
42 @@ -146,7 +146,16 @@ static void qca8k_rw_reg_ack_handler(str
43
44 command = get_unaligned_le32(&mgmt_ethhdr->command);
45 cmd = FIELD_GET(QCA_HDR_MGMT_CMD, command);
46 +
47 len = FIELD_GET(QCA_HDR_MGMT_LENGTH, command);
48 + /* Special case for len of 15 as this is the max value for len and needs to
49 + * be increased before converting it from word to dword.
50 + */
51 + if (len == 15)
52 + len++;
53 +
54 + /* We can ignore odd value, we always round up them in the alloc function. */
55 + len *= sizeof(u16);
56
57 /* Make sure the seq match the requested packet */
58 if (get_unaligned_le32(&mgmt_ethhdr->seq) == mgmt_eth_data->seq)
59 @@ -193,17 +202,33 @@ static struct sk_buff *qca8k_alloc_mdio_
60 if (!skb)
61 return NULL;
62
63 - /* Max value for len reg is 15 (0xf) but the switch actually return 16 byte
64 - * Actually for some reason the steps are:
65 - * 0: nothing
66 - * 1-4: first 4 byte
67 - * 5-6: first 12 byte
68 - * 7-15: all 16 byte
69 + /* Hdr mgmt length value is in step of word size.
70 + * As an example to process 4 byte of data the correct length to set is 2.
71 + * To process 8 byte 4, 12 byte 6, 16 byte 8...
72 + *
73 + * Odd values will always return the next size on the ack packet.
74 + * (length of 3 (6 byte) will always return 8 bytes of data)
75 + *
76 + * This means that a value of 15 (0xf) actually means reading/writing 32 bytes
77 + * of data.
78 + *
79 + * To correctly calculate the length we devide the requested len by word and
80 + * round up.
81 + * On the ack function we can skip the odd check as we already handle the
82 + * case here.
83 */
84 - if (len == 16)
85 - real_len = 15;
86 - else
87 - real_len = len;
88 + real_len = DIV_ROUND_UP(len, sizeof(u16));
89 +
90 + /* We check if the result len is odd and we round up another time to
91 + * the next size. (length of 3 will be increased to 4 as switch will always
92 + * return 8 bytes)
93 + */
94 + if (real_len % sizeof(u16) != 0)
95 + real_len++;
96 +
97 + /* Max reg value is 0xf(15) but switch will always return the next size (32 byte) */
98 + if (real_len == 16)
99 + real_len--;
100
101 skb_reset_mac_header(skb);
102 skb_set_network_header(skb, skb->len);