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
6 PLA_BP_0 ~ PLA_BP_15 (0xfc28 ~ 0xfc46) are continuous registers, so we
7 could combine the control transfers into one control transfer.
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>
13 drivers/net/usb/r8152.c | 75 ++++++++++++++---------------------------
14 1 file changed, 25 insertions(+), 50 deletions(-)
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)
22 - switch (tp->version) {
31 - ocp_write_byte(tp, type, PLA_BP_EN, 0);
34 - ocp_write_word(tp, type, USB_BP2_EN, 0);
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);
47 + switch (tp->version) {
51 @@ -4013,32 +3994,31 @@ static void rtl_clear_bp(struct r8152 *t
56 if (type == MCU_TYPE_USB) {
57 ocp_write_word(tp, MCU_TYPE_USB, USB_BP2_EN, 0);
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);
68 - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0);
77 + ocp_write_byte(tp, type, PLA_BP_EN, 0);
86 + ocp_write_word(tp, type, USB_BP2_EN, 0);
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);
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
105 static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac)
107 - u16 bp_en_addr, bp_index, type, bp_num, fw_ver_reg;
108 + u16 bp_en_addr, type, fw_ver_reg;
113 switch (__le32_to_cpu(mac->blk_hdr.type)) {
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));
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]));
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);
128 bp_en_addr = __le16_to_cpu(mac->bp_en_addr);