net: ethernet: mediatek: Fix overlapping capability bits.
Subsystems (5)
PATCH v2 1/1 net: ethernet: mediatek: Fix overlapping capability bits.
Both MTK_TRGMII_MT7621_CLK and MTK_PATH_BIT are defined as bit 10.
This can causes issues on non-MT7621 devices which has the MTK_PATH_BIT(MTK_ETH_PATH_GMAC1_RGMII) and MTK_TRGMII capability set. The wrong TRGMII setup code can be executed. The current wrongly executed code doesn’t do any harm on MT7623 and the TRGMII setup for the MT7623 SOC side is done in MT7530 driver So it wasn’t noticed in the test.
Move all capability bits in one enum so that they are all unique and easy to expand in the future.
Because mtk_eth_path enum is merged in to mkt_eth_capabilities, the variable path value is no longer between 0 to number of paths, mtk_eth_path_name can’t be used anymore in this form. Convert the mtk_eth_path_name array to a function to lookup the pathname.
The old code walked thru the mtk_eth_path enum, which is also merged with mkt_eth_capabilities. Expand array mtk_eth_muxc so it can store the name and capability bit of the mux. Convert the code so it can walk thru the mtk_eth_muxc array.
support")
v1->v2:
- Move all capability bits in one enum, suggested by Willem de Bruijn
- Convert the mtk_eth_path_name array to a function to lookup the pathname
- Expand array mtk_eth_muxc so it can also store the name and capability bit of the mux
- Updated commit message
--- drivers/net/ethernet/mediatek/mtk_eth_path.c | 81 ++++++++---- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 129 ++++++++++--------- 2 files changed, 125 insertions(+), 85 deletions(-)
drivers/net/ethernet/mediatek/mtk_eth_path.c +55 -26
@@ -13,19 +13,32 @@#include "mtk_eth_soc.h" struct mtk_eth_muxc { -int (*set_path)(struct mtk_eth *eth,int path); +const char *name; +int cap_bit; +int (*set_path)(struct mtk_eth *eth,int path); }; -static const char *const mtk_eth_mux_name[] = { -"mux_gdm1_to_gmac1_esw" ,"mux_gmac2_gmac0_to_gephy" , -"mux_u3_gmac2_to_qphy" ,"mux_gmac1_gmac2_to_sgmii_rgmii" , -"mux_gmac12_to_gephy_sgmii" , -}; - -static const char *const mtk_eth_path_name[] = { -"gmac1_rgmii" ,"gmac1_trgmii" ,"gmac1_sgmii" ,"gmac2_rgmii" , -"gmac2_sgmii" ,"gmac2_gephy" ,"gdm1_esw" , -}; +static const char *mtk_eth_path_name (int path) +{ +switch (path) { +case MTK_ETH_PATH_GMAC1_RGMII : +return "gmac1_rgmii" ; +case MTK_ETH_PATH_GMAC1_TRGMII : +return "gmac1_trgmii" ; +case MTK_ETH_PATH_GMAC1_SGMII : +return "gmac1_sgmii" ; +case MTK_ETH_PATH_GMAC2_RGMII : +return "gmac2_rgmii" ; +case MTK_ETH_PATH_GMAC2_SGMII : +return "gmac2_sgmii" ; +case MTK_ETH_PATH_GMAC2_GEPHY : +return "gmac2_gephy" ; +case MTK_ETH_PATH_GDM1_ESW : +return "gdm1_esw" ; +default : +return "unknown path" ; + } +}static int set_mux_gdm1_to_gmac1_esw (struct mtk_eth *eth,int path) {
@@ -53,7 +66,7 @@ static int set_mux_gdm1_to_gmac1_esw(struct mtk_eth *eth, int path) }dev_dbg (eth->dev,"path %s in %s updated = %d\n" , - mtk_eth_path_name[path], __func__, updated); +mtk_eth_path_name (path), __func__, updated);return 0 ; }
@@ -76,7 +89,7 @@ static int set_mux_gmac2_gmac0_to_gephy(struct mtk_eth *eth, int path)regmap_update_bits (eth->infra,INFRA_MISC2 ,GEPHY_MAC_SEL , val);dev_dbg (eth->dev,"path %s in %s updated = %d\n" , - mtk_eth_path_name[path], __func__, updated); +mtk_eth_path_name (path), __func__, updated);return 0 ; }
@@ -99,7 +112,7 @@ static int set_mux_u3_gmac2_to_qphy(struct mtk_eth *eth, int path)regmap_update_bits (eth->infra,INFRA_MISC2 ,CO_QPHY_SEL , val);dev_dbg (eth->dev,"path %s in %s updated = %d\n" , - mtk_eth_path_name[path], __func__, updated); +mtk_eth_path_name (path), __func__, updated);return 0 ; }
@@ -137,7 +150,7 @@ static int set_mux_gmac1_gmac2_to_sgmii_rgmii(struct mtk_eth *eth, int path) SYSCFG0_SGMII_MASK, val);dev_dbg (eth->dev,"path %s in %s updated = %d\n" , - mtk_eth_path_name[path], __func__, updated); +mtk_eth_path_name (path), __func__, updated);return 0 ; }
@@ -168,26 +181,42 @@ static int set_mux_gmac12_to_gephy_sgmii(struct mtk_eth *eth, int path) SYSCFG0_SGMII_MASK, val);dev_dbg (eth->dev,"path %s in %s updated = %d\n" , - mtk_eth_path_name[path], __func__, updated); +mtk_eth_path_name (path), __func__, updated);return 0 ; }static const struct mtk_eth_muxc mtk_eth_muxc[] = { - { .set_path = set_mux_gdm1_to_gmac1_esw, }, - { .set_path = set_mux_gmac2_gmac0_to_gephy, }, - { .set_path = set_mux_u3_gmac2_to_qphy, }, - { .set_path = set_mux_gmac1_gmac2_to_sgmii_rgmii, }, - { .set_path = set_mux_gmac12_to_gephy_sgmii, } + { + .name ="mux_gdm1_to_gmac1_esw" , + .cap_bit =MTK_ETH_MUX_GDM1_TO_GMAC1_ESW , + .set_path = set_mux_gdm1_to_gmac1_esw, + }, { + .name ="mux_gmac2_gmac0_to_gephy" , + .cap_bit =MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY , + .set_path = set_mux_gmac2_gmac0_to_gephy, + }, { + .name ="mux_u3_gmac2_to_qphy" , + .cap_bit =MTK_ETH_MUX_U3_GMAC2_TO_QPHY , + .set_path = set_mux_u3_gmac2_to_qphy, + }, { + .name ="mux_gmac1_gmac2_to_sgmii_rgmii" , + .cap_bit =MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII , + .set_path = set_mux_gmac1_gmac2_to_sgmii_rgmii, + }, { + .name ="mux_gmac12_to_gephy_sgmii" , + .cap_bit =MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII , + .set_path = set_mux_gmac12_to_gephy_sgmii, + }, };static int mtk_eth_mux_setup (struct mtk_eth *eth,int path) {int i, err =0 ; -if (!MTK_HAS_CAPS (eth->soc->caps,MTK_PATH_BIT (path))) { +if (!MTK_HAS_CAPS (eth->soc->caps, path)) {dev_err (eth->dev,"path %s isn't support on the SoC\n" , - mtk_eth_path_name[path]); +mtk_eth_path_name (path));return -EINVAL ; }
@@ -195,14 +224,14 @@ static int mtk_eth_mux_setup(struct mtk_eth *eth, int path)return 0 ;/* Setup MUX in path fabric */ -for (i =0 ; i <MTK_ETH_MUX_MAX ; i++) { -if (MTK_HAS_CAPS (eth->soc->caps,MTK_MUX_BIT (i))) { +for (i =0 ; i <ARRAY_SIZE (mtk_eth_muxc); i++) { +if (MTK_HAS_CAPS (eth->soc->caps, mtk_eth_muxc[i].cap_bit)) { err = mtk_eth_muxc[i].set_path (eth, path);if (err) goto out; }else {dev_dbg (eth->dev,"mux %s isn't present on the SoC\n" , - mtk_eth_mux_name[i]); + mtk_eth_muxc[i].name); } }
drivers/net/ethernet/mediatek/mtk_eth_soc.h +70 -59
156 lines not on this page · raw message
Signature · 1 line
2.20.1
From: René van Dorst <[email protected]>
Date: Wed, 3 Jul 2019 20:42:04 +0200
Quoted 16 lines
Both
MTK_TRGMII_MT7621_CLKandMTK_PATH_BITare defined as bit 10.This can causes issues on non-MT7621 devices which has the
MTK_PATH_BIT(MTK_ETH_PATH_GMAC1_RGMII)andMTK_TRGMIIcapability set. The wrong TRGMII setup code can be executed. The current wrongly executed code doesn’t do any harm on MT7623 and the TRGMII setup for the MT7623 SOC side is done in MT7530 driver So it wasn’t noticed in the test.Move all capability bits in one enum so that they are all unique and easy to expand in the future.
Because
mtk_eth_pathenum is merged in tomkt_eth_capabilities, the variable path value is no longer between 0 to number of paths,mtk_eth_path_namecan’t be used anymore in this form. Convert themtk_eth_path_namearray to a function to lookup the pathname.
Quoted 7 lines
The old code walked thru the
mtk_eth_pathenum, which is also merged withmkt_eth_capabilities. Expand arraymtk_eth_muxcso it can store the name and capability bit of the mux. Convert the code so it can walk thru themtk_eth_muxcarray.Fixes 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII modesupport")
Please in the future do not split Fixes: tags onto mutliple lines, it must be one contiguous line no matter how long. I fixed it up this time.
Quoted 1 line
Signed-off-by René van Dorst <[email protected]>
Applied, thank you.