linux/drivers/net/ethernet/mediatek/mtk_eth_path.c

331 lines
6.9 KiB
C
Raw Permalink Normal View History

// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2018-2019 MediaTek Inc.
/* A library for configuring path from GMAC/GDM to target PHY
*
* Author: Sean Wang <sean.wang@mediatek.com>
*
*/
#include <linux/phy.h>
#include <linux/regmap.h>
#include "mtk_eth_soc.h"
struct mtk_eth_muxc {
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
const char *name;
net: ethernet: mtk_eth_soc: convert cap_bit in mtk_eth_muxc struct to u64 With commit 51a4df60db5c2 ("net: ethernet: mtk_eth_soc: convert caps in mtk_soc_data struct to u64") the capabilities bitfield was converted to a 64-bit value, but a cap_bit in struct mtk_eth_muxc which is used to store a full bitfield (rather than the bit number, as the name would suggest) still holds only a 32-bit value. Change the type of cap_bit to u64 in order to avoid truncating the bitfield which results in path selection to not work with capabilities above the 32-bit limit. The values currently stored in the cap_bit field are MTK_ETH_MUX_GDM1_TO_GMAC1_ESW: BIT_ULL(18) | BIT_ULL(5) MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY: BIT_ULL(19) | BIT_ULL(5) | BIT_ULL(6) MTK_ETH_MUX_U3_GMAC2_TO_QPHY: BIT_ULL(20) | BIT_ULL(5) | BIT_ULL(6) MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII: BIT_ULL(20) | BIT_ULL(5) | BIT_ULL(7) MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII: BIT_ULL(21) | BIT_ULL(5) While all those values are currently still within 32-bit boundaries, the addition of new capabilities of MT7988 as well as future SoC's like MT7987 will exceed them. Also, the use of a 32-bit 'int' type to store the result of a BIT_ULL(...) is misleading. Signed-off-by: Bo-Cun Chen <bc-bocun.chen@mediatek.com> Signed-off-by: Daniel Golle <daniel@makrotopia.org> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/ded98b0d716c3203017a7a92151516ec2bf1abee.1745369249.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-04-23 01:48:02 +01:00
u64 cap_bit;
int (*set_path)(struct mtk_eth *eth, u64 path);
};
static const char *mtk_eth_path_name(u64 path)
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
{
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_2P5GPHY:
return "gmac2_2p5gphy";
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
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, u64 path)
{
bool updated = true;
u32 mask, set, reg;
switch (path) {
case MTK_ETH_PATH_GMAC1_SGMII:
mask = ~(u32)MTK_MUX_TO_ESW;
set = 0;
break;
case MTK_ETH_PATH_GDM1_ESW:
mask = ~(u32)MTK_MUX_TO_ESW;
set = MTK_MUX_TO_ESW;
break;
default:
updated = false;
break;
}
if (mtk_is_netsys_v3_or_greater(eth))
reg = MTK_MAC_MISC_V3;
else
reg = MTK_MAC_MISC;
if (updated)
mtk_m32(eth, mask, set, reg);
dev_dbg(eth->dev, "path %s in %s updated = %d\n",
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
mtk_eth_path_name(path), __func__, updated);
return 0;
}
static int set_mux_gmac2_gmac0_to_gephy(struct mtk_eth *eth, u64 path)
{
unsigned int val = 0;
bool updated = true;
switch (path) {
case MTK_ETH_PATH_GMAC2_GEPHY:
val = ~(u32)GEPHY_MAC_SEL;
break;
default:
updated = false;
break;
}
if (updated)
regmap_update_bits(eth->infra, INFRA_MISC2, GEPHY_MAC_SEL, val);
dev_dbg(eth->dev, "path %s in %s updated = %d\n",
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
mtk_eth_path_name(path), __func__, updated);
return 0;
}
static int set_mux_u3_gmac2_to_qphy(struct mtk_eth *eth, u64 path)
{
unsigned int val = 0, mask = 0, reg = 0;
bool updated = true;
switch (path) {
case MTK_ETH_PATH_GMAC2_SGMII:
if (MTK_HAS_CAPS(eth->soc->caps, MTK_U3_COPHY_V2)) {
reg = USB_PHY_SWITCH_REG;
val = SGMII_QPHY_SEL;
mask = QPHY_SEL_MASK;
} else {
reg = INFRA_MISC2;
val = CO_QPHY_SEL;
mask = val;
}
break;
default:
updated = false;
break;
}
if (updated)
regmap_update_bits(eth->infra, reg, mask, val);
dev_dbg(eth->dev, "path %s in %s updated = %d\n",
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
mtk_eth_path_name(path), __func__, updated);
return 0;
}
static int set_mux_gmac2_to_2p5gphy(struct mtk_eth *eth, u64 path)
{
int ret;
if (path == MTK_ETH_PATH_GMAC2_2P5GPHY) {
ret = regmap_clear_bits(eth->ethsys, ETHSYS_SYSCFG0,
SYSCFG0_SGMII_GMAC2_V2);
if (ret)
return ret;
/* Setup mux to 2p5g PHY */
ret = regmap_clear_bits(eth->infra, TOP_MISC_NETSYS_PCS_MUX,
MUX_G2_USXGMII_SEL);
if (ret)
return ret;
dev_dbg(eth->dev, "path %s in %s updated\n",
mtk_eth_path_name(path), __func__);
}
return 0;
}
static int set_mux_gmac1_gmac2_to_sgmii_rgmii(struct mtk_eth *eth, u64 path)
{
unsigned int val = 0;
bool updated = true;
switch (path) {
case MTK_ETH_PATH_GMAC1_SGMII:
val = SYSCFG0_SGMII_GMAC1;
break;
case MTK_ETH_PATH_GMAC2_SGMII:
val = SYSCFG0_SGMII_GMAC2;
break;
case MTK_ETH_PATH_GMAC1_RGMII:
case MTK_ETH_PATH_GMAC2_RGMII:
regmap_read(eth->ethsys, ETHSYS_SYSCFG0, &val);
val &= SYSCFG0_SGMII_MASK;
if ((path == MTK_GMAC1_RGMII && val == SYSCFG0_SGMII_GMAC1) ||
(path == MTK_GMAC2_RGMII && val == SYSCFG0_SGMII_GMAC2))
val = 0;
else
updated = false;
break;
default:
updated = false;
break;
}
if (updated)
regmap_update_bits(eth->ethsys, ETHSYS_SYSCFG0,
SYSCFG0_SGMII_MASK, val);
dev_dbg(eth->dev, "path %s in %s updated = %d\n",
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
mtk_eth_path_name(path), __func__, updated);
return 0;
}
static int set_mux_gmac12_to_gephy_sgmii(struct mtk_eth *eth, u64 path)
{
unsigned int val = 0;
bool updated = true;
regmap_read(eth->ethsys, ETHSYS_SYSCFG0, &val);
switch (path) {
case MTK_ETH_PATH_GMAC1_SGMII:
val |= SYSCFG0_SGMII_GMAC1_V2;
break;
case MTK_ETH_PATH_GMAC2_GEPHY:
val &= ~(u32)SYSCFG0_SGMII_GMAC2_V2;
break;
case MTK_ETH_PATH_GMAC2_SGMII:
val |= SYSCFG0_SGMII_GMAC2_V2;
break;
default:
updated = false;
}
if (updated)
regmap_update_bits(eth->ethsys, ETHSYS_SYSCFG0,
SYSCFG0_SGMII_MASK, val);
dev_dbg(eth->dev, "path %s in %s updated = %d\n",
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
mtk_eth_path_name(path), __func__, updated);
return 0;
}
static const struct mtk_eth_muxc mtk_eth_muxc[] = {
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
{
.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_gmac2_to_2p5gphy",
.cap_bit = MTK_ETH_MUX_GMAC2_TO_2P5GPHY,
.set_path = set_mux_gmac2_to_2p5gphy,
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
}, {
.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, u64 path)
{
int i, err = 0;
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
if (!MTK_HAS_CAPS(eth->soc->caps, path)) {
dev_err(eth->dev, "path %s isn't support on the SoC\n",
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
mtk_eth_path_name(path));
return -EINVAL;
}
if (!MTK_HAS_CAPS(eth->soc->caps, MTK_MUX))
return 0;
/* Setup MUX in path fabric */
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
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",
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. Fixes: 8efaa653a8a5 ("net: ethernet: mediatek: Add MT7621 TRGMII mode support") Signed-off-by: René van Dorst <opensource@vdorst.com> 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 Signed-off-by: David S. Miller <davem@davemloft.net>
2019-07-03 20:42:04 +02:00
mtk_eth_muxc[i].name);
}
}
out:
return err;
}
int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id)
{
u64 path;
path = (mac_id == 0) ? MTK_ETH_PATH_GMAC1_SGMII :
MTK_ETH_PATH_GMAC2_SGMII;
/* Setup proper MUXes along the path */
return mtk_eth_mux_setup(eth, path);
}
int mtk_gmac_2p5gphy_path_setup(struct mtk_eth *eth, int mac_id)
{
u64 path = 0;
if (mac_id == MTK_GMAC2_ID)
path = MTK_ETH_PATH_GMAC2_2P5GPHY;
if (!path)
return -EINVAL;
/* Setup proper MUXes along the path */
return mtk_eth_mux_setup(eth, path);
}
int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id)
{
u64 path = 0;
if (mac_id == 1)
path = MTK_ETH_PATH_GMAC2_GEPHY;
if (!path)
return -EINVAL;
/* Setup proper MUXes along the path */
return mtk_eth_mux_setup(eth, path);
}
int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id)
{
u64 path;
path = (mac_id == 0) ? MTK_ETH_PATH_GMAC1_RGMII :
MTK_ETH_PATH_GMAC2_RGMII;
/* Setup proper MUXes along the path */
return mtk_eth_mux_setup(eth, path);
}