kernel: backport ethtool_puts
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 795-v6.6-08-r8152-adjust-generic_ocp_write-function.patch
1 From 57df0fb9d511f91202114813e90128d65c0589f0 Mon Sep 17 00:00:00 2001
2 From: Hayes Wang <hayeswang@realtek.com>
3 Date: Wed, 26 Jul 2023 11:08:07 +0800
4 Subject: [PATCH] r8152: adjust generic_ocp_write function
5
6 Reduce the control transfer if all bytes of first or the last DWORD are
7 written.
8
9 The original method is to split the control transfer into three parts
10 (the first DWORD, middle continuous data, and the last DWORD). However,
11 they could be combined if whole bytes of the first DWORD or last DWORD
12 are written. That is, the first DWORD or the last DWORD could be combined
13 with the middle continuous data, if the byte_en is 0xff.
14
15 Signed-off-by: Hayes Wang <hayeswang@realtek.com>
16 Link: https://lore.kernel.org/r/20230726030808.9093-418-nic_swsd@realtek.com
17 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
18 ---
19 drivers/net/usb/r8152.c | 29 ++++++++++++++++++-----------
20 1 file changed, 18 insertions(+), 11 deletions(-)
21
22 --- a/drivers/net/usb/r8152.c
23 +++ b/drivers/net/usb/r8152.c
24 @@ -1310,16 +1310,24 @@ static int generic_ocp_write(struct r815
25 byteen_end = byteen & BYTE_EN_END_MASK;
26
27 byen = byteen_start | (byteen_start << 4);
28 - ret = set_registers(tp, index, type | byen, 4, data);
29 - if (ret < 0)
30 - goto error1;
31 -
32 - index += 4;
33 - data += 4;
34 - size -= 4;
35
36 - if (size) {
37 + /* Split the first DWORD if the byte_en is not 0xff */
38 + if (byen != BYTE_EN_DWORD) {
39 + ret = set_registers(tp, index, type | byen, 4, data);
40 + if (ret < 0)
41 + goto error1;
42 +
43 + index += 4;
44 + data += 4;
45 size -= 4;
46 + }
47 +
48 + if (size) {
49 + byen = byteen_end | (byteen_end >> 4);
50 +
51 + /* Split the last DWORD if the byte_en is not 0xff */
52 + if (byen != BYTE_EN_DWORD)
53 + size -= 4;
54
55 while (size) {
56 if (size > limit) {
57 @@ -1346,10 +1354,9 @@ static int generic_ocp_write(struct r815
58 }
59 }
60
61 - byen = byteen_end | (byteen_end >> 4);
62 - ret = set_registers(tp, index, type | byen, 4, data);
63 - if (ret < 0)
64 - goto error1;
65 + /* Set the last DWORD */
66 + if (byen != BYTE_EN_DWORD)
67 + ret = set_registers(tp, index, type | byen, 4, data);
68 }
69
70 error1: