@@ -1314,16 +1314,24 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
1314
1314
byteen_end = byteen & BYTE_EN_END_MASK ;
1315
1315
1316
1316
byen = byteen_start | (byteen_start << 4 );
1317
- ret = set_registers (tp , index , type | byen , 4 , data );
1318
- if (ret < 0 )
1319
- goto error1 ;
1320
1317
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 ;
1324
1323
1325
- if (size ) {
1324
+ index += 4 ;
1325
+ data += 4 ;
1326
1326
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 ;
1327
1335
1328
1336
while (size ) {
1329
1337
if (size > limit ) {
@@ -1350,10 +1358,9 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
1350
1358
}
1351
1359
}
1352
1360
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 );
1357
1364
}
1358
1365
1359
1366
error1 :
@@ -3971,62 +3978,42 @@ static void rtl_reset_bmu(struct r8152 *tp)
3971
3978
/* Clear the bp to stop the firmware before loading a new one */
3972
3979
static void rtl_clear_bp (struct r8152 * tp , u16 type )
3973
3980
{
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 ;
3987
3983
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 ) {
3997
3985
case RTL_VER_08 :
3998
3986
case RTL_VER_09 :
3999
3987
case RTL_VER_10 :
4000
3988
case RTL_VER_11 :
4001
3989
case RTL_VER_12 :
4002
3990
case RTL_VER_13 :
4003
3991
case RTL_VER_15 :
4004
- default :
4005
3992
if (type == MCU_TYPE_USB ) {
4006
3993
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 ;
4018
3996
}
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 ;
4019
4013
break ;
4020
4014
}
4021
4015
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 );
4030
4017
4031
4018
/* wait 3 ms to make sure the firmware is stopped */
4032
4019
usleep_range (3000 , 6000 );
@@ -5000,10 +4987,9 @@ static void rtl8152_fw_phy_nc_apply(struct r8152 *tp, struct fw_phy_nc *phy)
5000
4987
5001
4988
static void rtl8152_fw_mac_apply (struct r8152 * tp , struct fw_mac * mac )
5002
4989
{
5003
- u16 bp_en_addr , bp_index , type , bp_num , fw_ver_reg ;
4990
+ u16 bp_en_addr , type , fw_ver_reg ;
5004
4991
u32 length ;
5005
4992
u8 * data ;
5006
- int i ;
5007
4993
5008
4994
switch (__le32_to_cpu (mac -> blk_hdr .type )) {
5009
4995
case RTL_FW_PLA :
@@ -5045,12 +5031,8 @@ static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac)
5045
5031
ocp_write_word (tp , type , __le16_to_cpu (mac -> bp_ba_addr ),
5046
5032
__le16_to_cpu (mac -> bp_ba_value ));
5047
5033
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 );
5054
5036
5055
5037
bp_en_addr = __le16_to_cpu (mac -> bp_en_addr );
5056
5038
if (bp_en_addr )
0 commit comments