Skip to content

Commit 9efcc52

Browse files
jonasjelonekrobimarko
authored andcommitted
realtek: pcs: rtl931x: streamline hardware mode setting
The SDK and our code for finally applying the hardware mode are quite confusing. There are two different "places" where a mode can be set, in a SerDes register and in a global SerDes mode register. Neither the SDK nor any of the datasheet/documentation serve any explanation for that. The functions are just named "fiber_mode_set" and "mii_mode_set" which is basically as useless as it can be to understand it. Try to get rid off this confusion by naming the functions 'sds_set_mac_mode' and 'sds_set_ip_mode' to make clear where the mode is set. While at it, also clarify the naming of 'config_mode' by renaming it to 'config_hw_mode'. The naming is based on the following assumption: > Realtek uses an SerDes IP core design (probably from another vendor) > in their switch. This supports a variety of modes and must be > configured properly for each mode. Usually, changing the mode in the > MAC's registers triggers a proper configuration of the SerDes IP block > in the background. > However, for some modes this seems to be incomplete, at least missing > important parts so it doesn't work on its own in the end. In this > case, the SerDes IP block needs to be configured manually with the > missing bits to make it work. There are several places in the SDK that support this assumption, both for RTL931X and RTL930X (as they are somewhat similar), e.g. [1]. [1] https://github.com/plappermaul/realtek-doc/blob/f7f85ffc14c6e575ad94f2b427106de533b888fe/sources/rtk-dms1250/src/dal/longan/dal_longan_sds.c#L1746 Signed-off-by: Jonas Jelonek <[email protected]> Link: openwrt/openwrt#20736 Signed-off-by: Robert Marko <[email protected]>
1 parent d5a4387 commit 9efcc52

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

target/linux/realtek/files-6.12/drivers/net/pcs/pcs-rtl-otto.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,7 +2377,12 @@ static int rtpcs_931x_sds_power(struct rtpcs_serdes *sds, bool power_on)
23772377
BIT(sds->id), en_val);
23782378
}
23792379

2380-
static int rtpcs_931x_sds_mii_mode_set(struct rtpcs_serdes *sds,
2380+
/*
2381+
* rtpcs_931x_sds_set_mac_mode
2382+
*
2383+
* Set the SerDes mode in the MAC's registers.
2384+
*/
2385+
static int rtpcs_931x_sds_set_mac_mode(struct rtpcs_serdes *sds,
23812386
enum rtpcs_sds_mode hw_mode)
23822387
{
23832388
u32 mode_val;
@@ -2417,14 +2422,19 @@ static int rtpcs_931x_sds_mii_mode_set(struct rtpcs_serdes *sds,
24172422
0xff << shift, mode_val << shift);
24182423
}
24192424

2420-
static int rtpcs_931x_sds_fiber_mode_set(struct rtpcs_serdes *sds,
2421-
enum rtpcs_sds_mode hw_mode)
2425+
/*
2426+
* rtpcs_931x_sds_set_ip_mode
2427+
*
2428+
* Set the SerDes mode in the SerDes IP block's registers.
2429+
*/
2430+
static int rtpcs_931x_sds_set_ip_mode(struct rtpcs_serdes *sds,
2431+
enum rtpcs_sds_mode hw_mode)
24222432
{
24232433
u32 mode_val;
24242434

24252435
/* clear symbol error count before changing mode */
24262436
rtpcs_931x_sds_clear_symerr(sds, hw_mode);
2427-
rtpcs_931x_sds_mii_mode_set(sds, RTPCS_SDS_MODE_OFF);
2437+
rtpcs_931x_sds_set_mac_mode(sds, RTPCS_SDS_MODE_OFF);
24282438

24292439
switch (hw_mode) {
24302440
case RTPCS_SDS_MODE_OFF:
@@ -2735,8 +2745,9 @@ static int rtpcs_931x_sds_config_fiber_1g(struct rtpcs_serdes *sds)
27352745
return 0;
27362746
}
27372747

2738-
static int rtpcs_931x_sds_config_mode(struct rtpcs_serdes *sds,
2739-
enum rtpcs_sds_mode hw_mode, int chiptype)
2748+
static int rtpcs_931x_sds_config_hw_mode(struct rtpcs_serdes *sds,
2749+
enum rtpcs_sds_mode hw_mode,
2750+
int chiptype)
27402751
{
27412752
struct rtpcs_serdes *even_sds = rtpcs_sds_get_even(sds);
27422753

@@ -2912,7 +2923,7 @@ static int rtpcs_931x_setup_serdes(struct rtpcs_serdes *sds,
29122923
return -ENOTSUPP;
29132924
}
29142925

2915-
ret = rtpcs_931x_sds_config_mode(sds, hw_mode, chiptype);
2926+
ret = rtpcs_931x_sds_config_hw_mode(sds, hw_mode, chiptype);
29162927
if (ret < 0)
29172928
return ret;
29182929

@@ -2945,9 +2956,9 @@ static int rtpcs_931x_setup_serdes(struct rtpcs_serdes *sds,
29452956
mode == PHY_INTERFACE_MODE_SGMII ||
29462957
mode == PHY_INTERFACE_MODE_USXGMII) {
29472958
if (mode == PHY_INTERFACE_MODE_XGMII)
2948-
ret = rtpcs_931x_sds_mii_mode_set(sds, hw_mode);
2959+
ret = rtpcs_931x_sds_set_mac_mode(sds, hw_mode);
29492960
else
2950-
ret = rtpcs_931x_sds_fiber_mode_set(sds, hw_mode);
2961+
ret = rtpcs_931x_sds_set_ip_mode(sds, hw_mode);
29512962
}
29522963

29532964
if (ret < 0)

0 commit comments

Comments
 (0)