Skip to content

Commit 4e1db4a

Browse files
committed
Merge branch 'r8152-reduce-control-transfer'
Hayes Wang says: ==================== r8152: reduce control transfer The two patches are used to reduce the number of control transfer when access the registers in bulk. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 3bdd85e + e5c266a commit 4e1db4a

File tree

1 file changed

+43
-61
lines changed

1 file changed

+43
-61
lines changed

drivers/net/usb/r8152.c

Lines changed: 43 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,16 +1314,24 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
13141314
byteen_end = byteen & BYTE_EN_END_MASK;
13151315

13161316
byen = byteen_start | (byteen_start << 4);
1317-
ret = set_registers(tp, index, type | byen, 4, data);
1318-
if (ret < 0)
1319-
goto error1;
13201317

1321-
index += 4;
1322-
data += 4;
1323-
size -= 4;
1318+
/* Split the first DWORD if the byte_en is not 0xff */
1319+
if (byen != BYTE_EN_DWORD) {
1320+
ret = set_registers(tp, index, type | byen, 4, data);
1321+
if (ret < 0)
1322+
goto error1;
13241323

1325-
if (size) {
1324+
index += 4;
1325+
data += 4;
13261326
size -= 4;
1327+
}
1328+
1329+
if (size) {
1330+
byen = byteen_end | (byteen_end >> 4);
1331+
1332+
/* Split the last DWORD if the byte_en is not 0xff */
1333+
if (byen != BYTE_EN_DWORD)
1334+
size -= 4;
13271335

13281336
while (size) {
13291337
if (size > limit) {
@@ -1350,10 +1358,9 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
13501358
}
13511359
}
13521360

1353-
byen = byteen_end | (byteen_end >> 4);
1354-
ret = set_registers(tp, index, type | byen, 4, data);
1355-
if (ret < 0)
1356-
goto error1;
1361+
/* Set the last DWORD */
1362+
if (byen != BYTE_EN_DWORD)
1363+
ret = set_registers(tp, index, type | byen, 4, data);
13571364
}
13581365

13591366
error1:
@@ -3971,62 +3978,42 @@ static void rtl_reset_bmu(struct r8152 *tp)
39713978
/* Clear the bp to stop the firmware before loading a new one */
39723979
static void rtl_clear_bp(struct r8152 *tp, u16 type)
39733980
{
3974-
switch (tp->version) {
3975-
case RTL_VER_01:
3976-
case RTL_VER_02:
3977-
case RTL_VER_07:
3978-
break;
3979-
case RTL_VER_03:
3980-
case RTL_VER_04:
3981-
case RTL_VER_05:
3982-
case RTL_VER_06:
3983-
ocp_write_byte(tp, type, PLA_BP_EN, 0);
3984-
break;
3985-
case RTL_VER_14:
3986-
ocp_write_word(tp, type, USB_BP2_EN, 0);
3981+
u16 bp[16] = {0};
3982+
u16 bp_num;
39873983

3988-
ocp_write_word(tp, type, USB_BP_8, 0);
3989-
ocp_write_word(tp, type, USB_BP_9, 0);
3990-
ocp_write_word(tp, type, USB_BP_10, 0);
3991-
ocp_write_word(tp, type, USB_BP_11, 0);
3992-
ocp_write_word(tp, type, USB_BP_12, 0);
3993-
ocp_write_word(tp, type, USB_BP_13, 0);
3994-
ocp_write_word(tp, type, USB_BP_14, 0);
3995-
ocp_write_word(tp, type, USB_BP_15, 0);
3996-
break;
3984+
switch (tp->version) {
39973985
case RTL_VER_08:
39983986
case RTL_VER_09:
39993987
case RTL_VER_10:
40003988
case RTL_VER_11:
40013989
case RTL_VER_12:
40023990
case RTL_VER_13:
40033991
case RTL_VER_15:
4004-
default:
40053992
if (type == MCU_TYPE_USB) {
40063993
ocp_write_word(tp, MCU_TYPE_USB, USB_BP2_EN, 0);
4007-
4008-
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_8, 0);
4009-
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_9, 0);
4010-
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_10, 0);
4011-
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_11, 0);
4012-
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_12, 0);
4013-
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_13, 0);
4014-
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_14, 0);
4015-
ocp_write_word(tp, MCU_TYPE_USB, USB_BP_15, 0);
4016-
} else {
4017-
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0);
3994+
bp_num = 16;
3995+
break;
40183996
}
3997+
fallthrough;
3998+
case RTL_VER_03:
3999+
case RTL_VER_04:
4000+
case RTL_VER_05:
4001+
case RTL_VER_06:
4002+
ocp_write_byte(tp, type, PLA_BP_EN, 0);
4003+
fallthrough;
4004+
case RTL_VER_01:
4005+
case RTL_VER_02:
4006+
case RTL_VER_07:
4007+
bp_num = 8;
4008+
break;
4009+
case RTL_VER_14:
4010+
default:
4011+
ocp_write_word(tp, type, USB_BP2_EN, 0);
4012+
bp_num = 16;
40194013
break;
40204014
}
40214015

4022-
ocp_write_word(tp, type, PLA_BP_0, 0);
4023-
ocp_write_word(tp, type, PLA_BP_1, 0);
4024-
ocp_write_word(tp, type, PLA_BP_2, 0);
4025-
ocp_write_word(tp, type, PLA_BP_3, 0);
4026-
ocp_write_word(tp, type, PLA_BP_4, 0);
4027-
ocp_write_word(tp, type, PLA_BP_5, 0);
4028-
ocp_write_word(tp, type, PLA_BP_6, 0);
4029-
ocp_write_word(tp, type, PLA_BP_7, 0);
4016+
generic_ocp_write(tp, PLA_BP_0, BYTE_EN_DWORD, bp_num << 1, bp, type);
40304017

40314018
/* wait 3 ms to make sure the firmware is stopped */
40324019
usleep_range(3000, 6000);
@@ -5000,10 +4987,9 @@ static void rtl8152_fw_phy_nc_apply(struct r8152 *tp, struct fw_phy_nc *phy)
50004987

50014988
static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac)
50024989
{
5003-
u16 bp_en_addr, bp_index, type, bp_num, fw_ver_reg;
4990+
u16 bp_en_addr, type, fw_ver_reg;
50044991
u32 length;
50054992
u8 *data;
5006-
int i;
50074993

50084994
switch (__le32_to_cpu(mac->blk_hdr.type)) {
50094995
case RTL_FW_PLA:
@@ -5045,12 +5031,8 @@ static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac)
50455031
ocp_write_word(tp, type, __le16_to_cpu(mac->bp_ba_addr),
50465032
__le16_to_cpu(mac->bp_ba_value));
50475033

5048-
bp_index = __le16_to_cpu(mac->bp_start);
5049-
bp_num = __le16_to_cpu(mac->bp_num);
5050-
for (i = 0; i < bp_num; i++) {
5051-
ocp_write_word(tp, type, bp_index, __le16_to_cpu(mac->bp[i]));
5052-
bp_index += 2;
5053-
}
5034+
generic_ocp_write(tp, __le16_to_cpu(mac->bp_start), BYTE_EN_DWORD,
5035+
__le16_to_cpu(mac->bp_num) << 1, mac->bp, type);
50545036

50555037
bp_en_addr = __le16_to_cpu(mac->bp_en_addr);
50565038
if (bp_en_addr)

0 commit comments

Comments
 (0)