kernel: 5.15: update Aquantia PHY driver to v6.1 code
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 795-v6.6-09-r8152-set-bp-in-bulk.patch
1 From e5c266a61186b462c388c53a3564c375e72f2244 Mon Sep 17 00:00:00 2001
2 From: Hayes Wang <hayeswang@realtek.com>
3 Date: Wed, 26 Jul 2023 11:08:08 +0800
4 Subject: [PATCH] r8152: set bp in bulk
5
6 PLA_BP_0 ~ PLA_BP_15 (0xfc28 ~ 0xfc46) are continuous registers, so we
7 could combine the control transfers into one control transfer.
8
9 Signed-off-by: Hayes Wang <hayeswang@realtek.com>
10 Link: https://lore.kernel.org/r/20230726030808.9093-419-nic_swsd@realtek.com
11 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
12 ---
13 drivers/net/usb/r8152.c | 75 ++++++++++++++---------------------------
14 1 file changed, 25 insertions(+), 50 deletions(-)
15
16 --- a/drivers/net/usb/r8152.c
17 +++ b/drivers/net/usb/r8152.c
18 @@ -3983,29 +3983,10 @@ static void rtl_reset_bmu(struct r8152 *
19 /* Clear the bp to stop the firmware before loading a new one */
20 static void rtl_clear_bp(struct r8152 *tp, u16 type)
21 {
22 - switch (tp->version) {
23 - case RTL_VER_01:
24 - case RTL_VER_02:
25 - case RTL_VER_07:
26 - break;
27 - case RTL_VER_03:
28 - case RTL_VER_04:
29 - case RTL_VER_05:
30 - case RTL_VER_06:
31 - ocp_write_byte(tp, type, PLA_BP_EN, 0);
32 - break;
33 - case RTL_VER_14:
34 - ocp_write_word(tp, type, USB_BP2_EN, 0);
35 + u16 bp[16] = {0};
36 + u16 bp_num;
37
38 - ocp_write_word(tp, type, USB_BP_8, 0);
39 - ocp_write_word(tp, type, USB_BP_9, 0);
40 - ocp_write_word(tp, type, USB_BP_10, 0);
41 - ocp_write_word(tp, type, USB_BP_11, 0);
42 - ocp_write_word(tp, type, USB_BP_12, 0);
43 - ocp_write_word(tp, type, USB_BP_13, 0);
44 - ocp_write_word(tp, type, USB_BP_14, 0);
45 - ocp_write_word(tp, type, USB_BP_15, 0);
46 - break;
47 + switch (tp->version) {
48 case RTL_VER_08:
49 case RTL_VER_09:
50 case RTL_VER_10:
51 @@ -4013,32 +3994,31 @@ static void rtl_clear_bp(struct r8152 *t
52 case RTL_VER_12:
53 case RTL_VER_13:
54 case RTL_VER_15:
55 - default:
56 if (type == MCU_TYPE_USB) {
57 ocp_write_word(tp, MCU_TYPE_USB, USB_BP2_EN, 0);
58 -
59 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_8, 0);
60 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_9, 0);
61 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_10, 0);
62 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_11, 0);
63 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_12, 0);
64 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_13, 0);
65 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_14, 0);
66 - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_15, 0);
67 - } else {
68 - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0);
69 + bp_num = 16;
70 + break;
71 }
72 + fallthrough;
73 + case RTL_VER_03:
74 + case RTL_VER_04:
75 + case RTL_VER_05:
76 + case RTL_VER_06:
77 + ocp_write_byte(tp, type, PLA_BP_EN, 0);
78 + fallthrough;
79 + case RTL_VER_01:
80 + case RTL_VER_02:
81 + case RTL_VER_07:
82 + bp_num = 8;
83 + break;
84 + case RTL_VER_14:
85 + default:
86 + ocp_write_word(tp, type, USB_BP2_EN, 0);
87 + bp_num = 16;
88 break;
89 }
90
91 - ocp_write_word(tp, type, PLA_BP_0, 0);
92 - ocp_write_word(tp, type, PLA_BP_1, 0);
93 - ocp_write_word(tp, type, PLA_BP_2, 0);
94 - ocp_write_word(tp, type, PLA_BP_3, 0);
95 - ocp_write_word(tp, type, PLA_BP_4, 0);
96 - ocp_write_word(tp, type, PLA_BP_5, 0);
97 - ocp_write_word(tp, type, PLA_BP_6, 0);
98 - ocp_write_word(tp, type, PLA_BP_7, 0);
99 + generic_ocp_write(tp, PLA_BP_0, BYTE_EN_DWORD, bp_num << 1, bp, type);
100
101 /* wait 3 ms to make sure the firmware is stopped */
102 usleep_range(3000, 6000);
103 @@ -5015,10 +4995,9 @@ static void rtl8152_fw_phy_nc_apply(stru
104
105 static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac)
106 {
107 - u16 bp_en_addr, bp_index, type, bp_num, fw_ver_reg;
108 + u16 bp_en_addr, type, fw_ver_reg;
109 u32 length;
110 u8 *data;
111 - int i;
112
113 switch (__le32_to_cpu(mac->blk_hdr.type)) {
114 case RTL_FW_PLA:
115 @@ -5060,12 +5039,8 @@ static void rtl8152_fw_mac_apply(struct
116 ocp_write_word(tp, type, __le16_to_cpu(mac->bp_ba_addr),
117 __le16_to_cpu(mac->bp_ba_value));
118
119 - bp_index = __le16_to_cpu(mac->bp_start);
120 - bp_num = __le16_to_cpu(mac->bp_num);
121 - for (i = 0; i < bp_num; i++) {
122 - ocp_write_word(tp, type, bp_index, __le16_to_cpu(mac->bp[i]));
123 - bp_index += 2;
124 - }
125 + generic_ocp_write(tp, __le16_to_cpu(mac->bp_start), BYTE_EN_DWORD,
126 + __le16_to_cpu(mac->bp_num) << 1, mac->bp, type);
127
128 bp_en_addr = __le16_to_cpu(mac->bp_en_addr);
129 if (bp_en_addr)