net: phy: Add support for new Aeonsemi PHYs
Subsystems (8)
Christian Marangi
maintainerv7 cover net: phy: Add support for new Aeonsemi PHYs
Add support for new Aeonsemi 10G C45 PHYs. These PHYs intergate an IPC to setup some configuration and require special handling to sync with the parity bit. The parity bit is a way the IPC use to follow correct order of command sent.
Supported PHYs AS21011JB1, AS21011PB1, AS21010JB1, AS21010PB1, AS21511JB1, AS21511PB1, AS21510JB1, AS21510PB1, AS21210JB1, AS21210PB1 that all register with the PHY ID 0x7500 0x7500 before the firmware is loaded.
The big special thing about this PHY is that it does provide a generic PHY ID in C45 register that change to the correct one one the firmware is loaded.
In practice:
- MMD 0x7 ID 0x7500 0x9410 -> FW LOAD -> ID 0x7500 0x9422
To handle this, we operate on .match_phy_device where we check the PHY ID, if the ID match the generic one, we load the firmware and we return 0 (PHY driver doesn't match). Then PHY core will try the next PHY driver in the list and this time the PHY is correctly filled in and we register for it.
To help in the matching and not modify part of the PHY device struct, .match_phy_device is extended to provide also the current phy_driver is trying to match for. This add the extra benefits that some other PHY can simplify their .match_phy_device OP.
Changes v7:
- Make sure fw_version is NULL terminated
- Better describe logic for .match_phy_device
Changes v6:
- Out of RFC
- Add Reviewed-by tag from Russell
Changes v5:
- Add Reviewed-by tag from Rob
- Fix subject in DT patch
- Fix wrong Suggested-by tag in patch 1
- Rework nxp patch to 80 column
Changes v4:
- Add Reviewed-by tag
- Better handle PHY ID scan in as21xxx
- Also simplify nxp driver and fix .match_phy_device
Changes v3:
- Correct typo intergate->integrate
- Try to reduce to 80 column (where possible... define become unreasable if split)
- Rework to new .match_phy_device implementation
- Init active_low_led and fix other minor smatch war
- Drop inline tag (kbot doesn't like it but not reported by checkpatch???) Changes v2:
- Move to RFC as net-next closed :(
- Add lock for IPC command
- Better check size values from IPC
- Add PHY ID for all supported PHYs
- Drop .get_feature (correct values are exported by standard regs)
- Rework LED event to enum
- Update .yaml with changes requested (firmware-name required for generic PHY ID)
- Better document C22 in C45
- Document PHY name logic
- Introduce patch to load PHY 2 times
Christian Marangi (6):
net: phy: pass PHY driver to .match_phy_device OP
net: phy: bcm87xx: simplify .match_phy_device OP
net: phy: nxp-c45-tja11xx: simplify .match_phy_device OP
net: phy: introduce genphy_match_phy_device()
net: phy: Add support for Aeonsemi AS21xxx PHYs
dt-bindings: net: Document support for Aeonsemi PHYs
.../bindings/net/aeonsemi,as21xxx.yaml | 122 ++ MAINTAINERS | 7 + drivers/net/phy/Kconfig | 12 + drivers/net/phy/Makefile | 1 + drivers/net/phy/as21xxx.c | 1076 +++++++++++++++++ drivers/net/phy/bcm87xx.c | 14 +- drivers/net/phy/icplus.c | 6 +- drivers/net/phy/marvell10g.c | 12 +- drivers/net/phy/micrel.c | 6 +- drivers/net/phy/nxp-c45-tja11xx.c | 41 +- drivers/net/phy/nxp-tja11xx.c | 6 +- drivers/net/phy/phy_device.c | 52 +- drivers/net/phy/realtek/realtek_main.c | 27 +- drivers/net/phy/teranetics.c | 3 +- include/linux/phy.h | 6 +- 15 files changed, 1325 insertions(+), 66 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/aeonsemi,as21xxx.yaml create mode 100644 drivers/net/phy/as21xxx.c
Signature · 1 line
2.48.1
Christian Marangi
maintainerPATCH v7 1/6 net: phy: pass PHY driver to .match_phy_device OP
Pass PHY driver pointer to .match_phy_device OP in addition to phydev. Having access to the PHY driver struct might be useful to check the PHY ID of the driver is being matched for in case the PHY ID scanned in the phydev is not consistent.
A scenario for this is a PHY that change PHY ID after a firmware is loaded, in such case, the PHY ID stored in PHY device struct is not valid anymore and PHY will manually scan the ID in the match_phy_device function.
Having the PHY driver info is also useful for those PHY driver that implement multiple simple .match_phy_device OP to match specific MMD PHY ID. With this extra info if the parsing logic is the same, the matching function can be generalized by using the phy_id in the PHY driver instead of hardcoding.
--- drivers/net/phy/bcm87xx.c | 6 ++++-- drivers/net/phy/icplus.c | 6 ++++-- drivers/net/phy/marvell10g.c | 12 ++++++++---- drivers/net/phy/micrel.c | 6 ++++-- drivers/net/phy/nxp-c45-tja11xx.c | 12 ++++++++---- drivers/net/phy/nxp-tja11xx.c | 6 ++++-- drivers/net/phy/phy_device.c | 2 +- drivers/net/phy/realtek/realtek_main.c | 27 +++++++++++++++++--------- drivers/net/phy/teranetics.c | 3 ++- include/linux/phy.h | 3 ++- 10 files changed, 55 insertions(+), 28 deletions(-)
drivers/net/phy/bcm87xx.c +4 -2
@@ -185,12 +185,14 @@ static irqreturn_t bcm87xx_handle_interrupt(struct phy_device *phydev)return IRQ_HANDLED ; } -static int bcm8706_match_phy_device (struct phy_device *phydev) +static int bcm8706_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phydev->c45_ids.device_ids[4 ] ==PHY_ID_BCM8706 ; } -static int bcm8727_match_phy_device (struct phy_device *phydev) +static int bcm8727_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phydev->c45_ids.device_ids[4 ] ==PHY_ID_BCM8727 ; }
drivers/net/phy/icplus.c +4 -2
@@ -520,12 +520,14 @@ static int ip101a_g_match_phy_device(struct phy_device *phydev, bool ip101a)return ip101a == !ret; } -static int ip101a_match_phy_device (struct phy_device *phydev) +static int ip101a_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return ip101a_g_match_phy_device (phydev, true); } -static int ip101g_match_phy_device (struct phy_device *phydev) +static int ip101g_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return ip101a_g_match_phy_device (phydev, false); }
drivers/net/phy/marvell10g.c +8 -4
@@ -1264,7 +1264,8 @@ static int mv3310_get_number_of_ports(struct phy_device *phydev)return ret +1 ; } -static int mv3310_match_phy_device (struct phy_device *phydev) +static int mv3310_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {if ((phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD ] &MARVELL_PHY_ID_MASK ) !=MARVELL_PHY_ID_88X3310 )
@@ -1273,7 +1274,8 @@ static int mv3310_match_phy_device(struct phy_device *phydev)return mv3310_get_number_of_ports (phydev) ==1 ; } -static int mv3340_match_phy_device (struct phy_device *phydev) +static int mv3340_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {if ((phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD ] &MARVELL_PHY_ID_MASK ) !=MARVELL_PHY_ID_88X3310 )
@@ -1297,12 +1299,14 @@ static int mv211x_match_phy_device(struct phy_device *phydev, bool has_5g)return !!(val &MDIO_PCS_SPEED_5G ) == has_5g; } -static int mv2110_match_phy_device (struct phy_device *phydev) +static int mv2110_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return mv211x_match_phy_device (phydev, true); } -static int mv2111_match_phy_device (struct phy_device *phydev) +static int mv2111_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return mv211x_match_phy_device (phydev, false); }
drivers/net/phy/micrel.c +4 -2
@@ -768,7 +768,8 @@ static int ksz8051_ksz8795_match_phy_device(struct phy_device *phydev,return !ret; } -static int ksz8051_match_phy_device (struct phy_device *phydev) +static int ksz8051_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return ksz8051_ksz8795_match_phy_device (phydev, true); }
@@ -888,7 +889,8 @@ static int ksz8061_config_init(struct phy_device *phydev)return kszphy_config_init (phydev); } -static int ksz8795_match_phy_device (struct phy_device *phydev) +static int ksz8795_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return ksz8051_ksz8795_match_phy_device (phydev, false); }
drivers/net/phy/nxp-c45-tja11xx.c +8 -4
@@ -1971,25 +1971,29 @@ static int nxp_c45_macsec_ability(struct phy_device *phydev)return macsec_ability; } -static int tja1103_match_phy_device (struct phy_device *phydev) +static int tja1103_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1103 ,PHY_ID_MASK ) && !nxp_c45_macsec_ability (phydev); } -static int tja1104_match_phy_device (struct phy_device *phydev) +static int tja1104_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1103 ,PHY_ID_MASK ) &&nxp_c45_macsec_ability (phydev); } -static int tja1120_match_phy_device (struct phy_device *phydev) +static int tja1120_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1120 ,PHY_ID_MASK ) && !nxp_c45_macsec_ability (phydev); } -static int tja1121_match_phy_device (struct phy_device *phydev) +static int tja1121_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1120 ,PHY_ID_MASK ) &&nxp_c45_macsec_ability (phydev);
drivers/net/phy/nxp-tja11xx.c +4 -2
@@ -651,12 +651,14 @@ static int tja1102_match_phy_device(struct phy_device *phydev, bool port0)return !ret; } -static int tja1102_p0_match_phy_device (struct phy_device *phydev) +static int tja1102_p0_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return tja1102_match_phy_device (phydev, true); } -static int tja1102_p1_match_phy_device (struct phy_device *phydev) +static int tja1102_p1_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return tja1102_match_phy_device (phydev, false); }
drivers/net/phy/phy_device.c +1 -1
@@ -514,7 +514,7 @@ static int phy_bus_match(struct device *dev, const struct device_driver *drv)return 0 ;if (phydrv->match_phy_device) -return phydrv->match_phy_device (phydev); +return phydrv->match_phy_device (phydev, phydrv);if (phydev->is_c45) {for (i =1 ; i < num_ids; i++) {
drivers/net/phy/realtek/realtek_main.c +18 -9
@@ -1117,13 +1117,15 @@ static bool rtlgen_supports_mmd(struct phy_device *phydev)return val >0 ; } -static int rtlgen_match_phy_device (struct phy_device *phydev) +static int rtlgen_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phydev->phy_id ==RTL_GENERIC_PHYID && !rtlgen_supports_2_5gbps (phydev); } -static int rtl8226_match_phy_device (struct phy_device *phydev) +static int rtl8226_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phydev->phy_id ==RTL_GENERIC_PHYID && rtlgen_supports_2_5gbps(phydev) &&
@@ -1139,32 +1141,38 @@ static int rtlgen_is_c45_match(struct phy_device *phydev, unsigned int id,return !is_c45 && (id == phydev->phy_id); } -static int rtl8221b_match_phy_device (struct phy_device *phydev) +static int rtl8221b_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phydev->phy_id ==RTL_8221B &&rtlgen_supports_mmd (phydev); } -static int rtl8221b_vb_cg_c22_match_phy_device (struct phy_device *phydev) +static int rtl8221b_vb_cg_c22_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return rtlgen_is_c45_match (phydev,RTL_8221B_VB_CG , false); } -static int rtl8221b_vb_cg_c45_match_phy_device (struct phy_device *phydev) +static int rtl8221b_vb_cg_c45_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return rtlgen_is_c45_match (phydev,RTL_8221B_VB_CG , true); } -static int rtl8221b_vn_cg_c22_match_phy_device (struct phy_device *phydev) +static int rtl8221b_vn_cg_c22_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return rtlgen_is_c45_match (phydev,RTL_8221B_VN_CG , false); } -static int rtl8221b_vn_cg_c45_match_phy_device (struct phy_device *phydev) +static int rtl8221b_vn_cg_c45_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return rtlgen_is_c45_match (phydev,RTL_8221B_VN_CG , true); } -static int rtl_internal_nbaset_match_phy_device (struct phy_device *phydev) +static int rtl_internal_nbaset_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {if (phydev->is_c45)return false;
@@ -1182,7 +1190,8 @@ static int rtl_internal_nbaset_match_phy_device(struct phy_device *phydev)return rtlgen_supports_2_5gbps (phydev) && !rtlgen_supports_mmd (phydev); } -static int rtl8251b_c45_match_phy_device (struct phy_device *phydev) +static int rtl8251b_c45_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return rtlgen_is_c45_match (phydev,RTL_8251B , true); }
drivers/net/phy/teranetics.c +2 -1
@@ -67,7 +67,8 @@ static int teranetics_read_status(struct phy_device *phydev)return 0 ; } -static int teranetics_match_phy_device (struct phy_device *phydev) +static int teranetics_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) {return phydev->c45_ids.device_ids[3 ] ==PHY_ID_TN2020 ; }
include/linux/phy.h +2 -1
@@ -990,7 +990,8 @@ struct phy_driver {* driver for the given phydev. If NULL, matching is based on * phy_id and phy_id_mask. */ -int (*match_phy_device)(struct phy_device *phydev); +int (*match_phy_device)(struct phy_device *phydev, +const struct phy_driver *phydrv);/** * @set_wol: Some devices (e.g. qnap TS-119P II) require PHY
Signature · 1 line
2.48.1
Christian Marangi
maintainerPATCH v7 2/6 net: phy: bcm87xx: simplify .match_phy_device OP
In reply to Christian MarangiSimplify .match_phy_device OP by using a generic function and using the new phy_id PHY driver info instead of hardcoding the matching PHY ID.
--- drivers/net/phy/bcm87xx.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/net/phy/bcm87xx.c +4 -10
@@ -185,16 +185,10 @@ static irqreturn_t bcm87xx_handle_interrupt(struct phy_device *phydev)return IRQ_HANDLED ; } -static int bcm8706_match_phy_device (struct phy_device *phydev, +static int bcm87xx_match_phy_device (struct phy_device *phydev,const struct phy_driver *phydrv) { -return phydev->c45_ids.device_ids[4 ] ==PHY_ID_BCM8706 ; -} - -static int bcm8727_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) -{ -return phydev->c45_ids.device_ids[4 ] ==PHY_ID_BCM8727 ; +return phydev->c45_ids.device_ids[4 ] == phydrv->phy_id; }static struct phy_driver bcm87xx_driver[] = {
@@ -208,7 +202,7 @@ static struct phy_driver bcm87xx_driver[] = { .read_status = bcm87xx_read_status, .config_intr = bcm87xx_config_intr, .handle_interrupt = bcm87xx_handle_interrupt, - .match_phy_device = bcm8706_match_phy_device, + .match_phy_device = bcm87xx_match_phy_device, }, { .phy_id = PHY_ID_BCM8727, .phy_id_mask = 0xffffffff,
@@ -219,7 +213,7 @@ static struct phy_driver bcm87xx_driver[] = { .read_status = bcm87xx_read_status, .config_intr = bcm87xx_config_intr, .handle_interrupt = bcm87xx_handle_interrupt, - .match_phy_device = bcm8727_match_phy_device, + .match_phy_device = bcm87xx_match_phy_device, } };module_phy_driver (bcm87xx_driver);
Signature · 1 line
2.48.1
Christian Marangi
maintainerPATCH v7 3/6 net: phy: nxp-c45-tja11xx: simplify .match_phy_device OP
In reply to Christian MarangiSimplify .match_phy_device OP by using a generic function and using the new phy_id PHY driver info instead of hardcoding the matching PHY ID with new variant for macsec and no_macsec PHYs.
Also make use of PHY_ID_MATCH_MODEL macro and drop PHY_ID_MASK define to introduce phy_id and phy_id_mask again in phy_driver struct.
--- drivers/net/phy/nxp-c45-tja11xx.c | 45 ++++++++++++++----------------- 1 file changed, 20 insertions(+), 25 deletions(-)
drivers/net/phy/nxp-c45-tja11xx.c +20 -25
@@ -19,7 +19,6 @@#include "nxp-c45-tja11xx.h" -#define PHY_ID_MASK GENMASK(31, 4)/* Same id: TJA1103, TJA1104 */ #define PHY_ID_TJA_1103 0x001BB010/* Same id: TJA1120, TJA1121 */
@@ -1971,32 +1970,24 @@ static int nxp_c45_macsec_ability(struct phy_device *phydev)return macsec_ability; } -static int tja1103_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) +static int tja11xx_no_macsec_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) { -return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1103 ,PHY_ID_MASK ) && - !nxp_c45_macsec_ability (phydev); -} +if (!phy_id_compare (phydev->phy_id, phydrv->phy_id, + phydrv->phy_id_mask)) +return 0 ; -static int tja1104_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) -{ -return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1103 ,PHY_ID_MASK ) && -nxp_c45_macsec_ability (phydev); +return !nxp_c45_macsec_ability (phydev); } -static int tja1120_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) +static int tja11xx_macsec_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) { -return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1120 ,PHY_ID_MASK ) && - !nxp_c45_macsec_ability (phydev); -} +if (!phy_id_compare (phydev->phy_id, phydrv->phy_id, + phydrv->phy_id_mask)) +return 0 ; -static int tja1121_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) -{ -return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1120 ,PHY_ID_MASK ) && -nxp_c45_macsec_ability (phydev); +return nxp_c45_macsec_ability (phydev); }static const struct nxp_c45_regmap tja1120_regmap = {
@@ -2069,6 +2060,7 @@ static const struct nxp_c45_phy_data tja1120_phy_data = {static struct phy_driver nxp_c45_driver[] = { { +PHY_ID_MATCH_MODEL (PHY_ID_TJA_1103 ), .name ="NXP C45 TJA1103" , .get_features = nxp_c45_get_features, .driver_data = &tja1103_phy_data,
@@ -2090,9 +2082,10 @@ static struct phy_driver nxp_c45_driver[] = { .get_sqi = nxp_c45_get_sqi, .get_sqi_max = nxp_c45_get_sqi_max, .remove = nxp_c45_remove, - .match_phy_device = tja1103_match_phy_device, + .match_phy_device = tja11xx_no_macsec_match_phy_device, }, { + PHY_ID_MATCH_MODEL(PHY_ID_TJA_1103), .name = "NXP C45 TJA1104", .get_features = nxp_c45_get_features, .driver_data = &tja1103_phy_data,
@@ -2114,9 +2107,10 @@ static struct phy_driver nxp_c45_driver[] = { .get_sqi = nxp_c45_get_sqi, .get_sqi_max = nxp_c45_get_sqi_max, .remove = nxp_c45_remove, - .match_phy_device = tja1104_match_phy_device, + .match_phy_device = tja11xx_macsec_match_phy_device, }, { + PHY_ID_MATCH_MODEL(PHY_ID_TJA_1120), .name = "NXP C45 TJA1120", .get_features = nxp_c45_get_features, .driver_data = &tja1120_phy_data,
@@ -2139,9 +2133,10 @@ static struct phy_driver nxp_c45_driver[] = { .get_sqi = nxp_c45_get_sqi, .get_sqi_max = nxp_c45_get_sqi_max, .remove = nxp_c45_remove, - .match_phy_device = tja1120_match_phy_device, + .match_phy_device = tja11xx_no_macsec_match_phy_device, }, { + PHY_ID_MATCH_MODEL(PHY_ID_TJA_1120), .name = "NXP C45 TJA1121", .get_features = nxp_c45_get_features, .driver_data = &tja1120_phy_data,
@@ -2164,7 +2159,7 @@ static struct phy_driver nxp_c45_driver[] = { .get_sqi = nxp_c45_get_sqi, .get_sqi_max = nxp_c45_get_sqi_max, .remove = nxp_c45_remove, - .match_phy_device = tja1121_match_phy_device, + .match_phy_device = tja11xx_macsec_match_phy_device, }, };
Signature · 1 line
2.48.1
Christian Marangi
maintainerPATCH v7 4/6 net: phy: introduce genphy_match_phy_device()
In reply to Christian MarangiIntroduce new API, genphy_match_phy_device(), to provide a way to check to match a PHY driver for a PHY device based on the info stored in the PHY device struct.
The function generalize the logic used in phy_bus_match() to check the PHY ID whether if C45 or C22 ID should be used for matching.
This is useful for custom .match_phy_device function that wants to use the generic logic under some condition. (example a PHY is already setup and provide the correct PHY ID)
--- drivers/net/phy/phy_device.c | 52 +++++++++++++++++++++++++----------- include/linux/phy.h | 3 +++ 2 files changed, 40 insertions(+), 15 deletions(-)
drivers/net/phy/phy_device.c +37 -15
@@ -503,20 +503,26 @@ static int phy_scan_fixups(struct phy_device *phydev)return 0 ; } -static int phy_bus_match (struct device *dev,const struct device_driver *drv) +/** +* genphy_match_phy_device - match a PHY device with a PHY driver +* @phydev: target phy_device struct +* @phydrv: target phy_driver struct +* +* Description: Checks whether the given PHY device matches the specified +* PHY driver. For Clause 45 PHYs, iterates over the available device +* identifiers and compares them against the driver's expected PHY ID, +* applying the provided mask. For Clause 22 PHYs, a direct ID comparison +* is performed. +* +* Return: 1 if the PHY device matches the driver, 0 otherwise. +*/ +int genphy_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) { -struct phy_device *phydev =to_phy_device (dev); -const struct phy_driver *phydrv =to_phy_driver (drv); -const int num_ids =ARRAY_SIZE (phydev->c45_ids.device_ids); -int i; - -if (!(phydrv->mdiodrv.flags &MDIO_DEVICE_IS_PHY )) -return 0 ; - -if (phydrv->match_phy_device) -return phydrv->match_phy_device (phydev, phydrv); -if (phydev->is_c45) { +const int num_ids =ARRAY_SIZE (phydev->c45_ids.device_ids); +int i; +for (i =1 ; i < num_ids; i++) {if (phydev->c45_ids.device_ids[i] ==0xffffffff )continue ;
@@ -525,11 +531,27 @@ static int phy_bus_match(struct device *dev, const struct device_driver *drv) phydrv->phy_id, phydrv->phy_id_mask))return 1 ; } +return 0 ; - }else { -return phy_id_compare (phydev->phy_id, phydrv->phy_id, - phydrv->phy_id_mask); } + +return phy_id_compare (phydev->phy_id, phydrv->phy_id, + phydrv->phy_id_mask); +} +EXPORT_SYMBOL_GPL (genphy_match_phy_device); + +static int phy_bus_match (struct device *dev,const struct device_driver *drv) +{ +struct phy_device *phydev =to_phy_device (dev); +const struct phy_driver *phydrv =to_phy_driver (drv); + +if (!(phydrv->mdiodrv.flags &MDIO_DEVICE_IS_PHY )) +return 0 ; + +if (phydrv->match_phy_device) +return phydrv->match_phy_device (phydev, phydrv); + +return genphy_match_phy_device (phydev, phydrv); } static ssize_t
include/linux/phy.h +3 -0
@@ -1911,6 +1911,9 @@ char *phy_attached_info_irq(struct phy_device *phydev) __malloc;void phy_attached_info (struct phy_device *phydev); +int genphy_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv); +/* Clause 22 PHY */ int genphy_read_abilities (struct phy_device *phydev);int genphy_setup_forced (struct phy_device *phydev);
Signature · 1 line
2.48.1
Christian Marangi
maintainerPATCH v7 5/6 net: phy: Add support for Aeonsemi AS21xxx PHYs
In reply to Christian MarangiAdd support for Aeonsemi AS21xxx 10G C45 PHYs. These PHYs integrate an IPC to setup some configuration and require special handling to sync with the parity bit. The parity bit is a way the IPC use to follow correct order of command sent.
Supported PHYs AS21011JB1, AS21011PB1, AS21010JB1, AS21010PB1, AS21511JB1, AS21511PB1, AS21510JB1, AS21510PB1, AS21210JB1, AS21210PB1 that all register with the PHY ID 0x7500 0x7510 before the firmware is loaded.
They all support up to 5 LEDs with various HW mode supported.
While implementing it was found some strange coincidence with using the same logic for implementing C22 in MMD regs in Broadcom PHYs.
For reference here the AS21xxx PHY name logic:
AS21x1xxB1
^ ^^
| |J: Supports SyncE/PTP
| |P: No SyncE/PTP support
| 1: Supports 2nd Serdes
| 2: Not 2nd Serdes support
0: 10G, 5G, 2.5G
5: 5G, 2.5G
2: 2.5G
--- MAINTAINERS | 6 + drivers/net/phy/Kconfig | 12 + drivers/net/phy/Makefile | 1 + drivers/net/phy/as21xxx.c | 1076 +++++++++++++++++++++++++++++++++++++ 4 files changed, 1095 insertions(+) create mode 100644 drivers/net/phy/as21xxx.c
MAINTAINERS +6 -0
@@ -646,6 +646,12 @@ F: drivers/iio/accel/adxl380.h F: drivers/iio/accel/adxl380_i2c.c F: drivers/iio/accel/adxl380_spi.c +AEONSEMI PHY DRIVER +M: Christian Marangi <[email protected]> +L: [email protected] +S: Maintained +F: drivers/net/phy/as21xxx.c + AF8133J THREE-AXIS MAGNETOMETER DRIVER M: Ondřej Jirman <[email protected]> S: Maintained
drivers/net/phy/Kconfig +12 -0
@@ -119,6 +119,18 @@ config AMCC_QT2025_PHY help Adds support for the Applied Micro Circuits Corporation QT2025 PHY. +config AS21XXX_PHY + tristate "Aeonsemi AS21xxx PHYs" + help + Currently supports the Aeonsemi AS21xxx PHY. + + These are C45 PHYs 10G that require all a generic firmware. + + Supported PHYs AS21011JB1, AS21011PB1, AS21010JB1, AS21010PB1, + AS21511JB1, AS21511PB1, AS21510JB1, AS21510PB1, AS21210JB1, + AS21210PB1 that all register with the PHY ID 0x7500 0x7500 + before the firmware is loaded. + source "drivers/net/phy/aquantia/Kconfig" config AX88796B_PHY
drivers/net/phy/Makefile +1 -0
@@ -40,6 +40,7 @@ obj-$(CONFIG_AIR_EN8811H_PHY) += air_en8811h.o obj-$(CONFIG_AMD_PHY) += amd.o obj-$(CONFIG_AMCC_QT2025_PHY) += qt2025.o obj-$(CONFIG_AQUANTIA_PHY) += aquantia/ +obj-$(CONFIG_AS21XXX_PHY) += as21xxx.o ifdef CONFIG_AX88796B_RUST_PHY obj-$(CONFIG_AX88796B_PHY) += ax88796b_rust.o else
drivers/net/phy/as21xxx.c new file +1076 -0
1,076 lines not on this page · raw message
Signature · 1 line
2.48.1
Christian Marangi
maintainerPATCH v7 6/6 dt-bindings: net: Document support for Aeonsemi PHYs
In reply to Christian MarangiAdd Aeonsemi PHYs and the requirement of a firmware to correctly work. Also document the max number of LEDs supported and what PHY ID expose when no firmware is loaded.
Supported PHYs AS21011JB1, AS21011PB1, AS21010JB1, AS21010PB1, AS21511JB1, AS21511PB1, AS21510JB1, AS21510PB1, AS21210JB1, AS21210PB1 that all register with the PHY ID 0x7500 0x9410 on C45 registers before the firmware is loaded.
--- .../bindings/net/aeonsemi,as21xxx.yaml | 122 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/aeonsemi,as21xxx.yaml
Documentation/devicetree/bindings/net/aeonsemi,as21xxx.yaml new file +122 -0
@@ -0,0 +1,122 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/aeonsemi,as21xxx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Aeonsemi AS21XXX Ethernet PHY + +maintainers: + - Christian Marangi <[email protected]> + +description: | + Aeonsemi AS21xxx Ethernet PHYs requires a firmware to be loaded to actually + work. The same firmware is compatible with various PHYs of the same family. + + A PHY with not firmware loaded will be exposed on the MDIO bus with ID + 0x7500 0x7500 or 0x7500 0x9410 on C45 registers. + + This can be done and is implemented by OEM in 2 different way: + - Attached SPI flash directly to the PHY with the firmware. The PHY + will self load the firmware in the presence of this configuration. + - Manually provided firmware loaded from a file in the filesystem. + + Each PHY can support up to 5 LEDs. + + AS2xxx PHY Name logic: + + AS21x1xxB1 + ^ ^^ + | |J: Supports SyncE/PTP + | |P: No SyncE/PTP support + | 1: Supports 2nd Serdes + | 2: Not 2nd Serdes support + 0: 10G, 5G, 2.5G + 5: 5G, 2.5G + 2: 2.5G + +allOf: + - $ref: ethernet-phy.yaml# + +select: + properties: + compatible: + contains: + enum: + - ethernet-phy-id7500.9410 + - ethernet-phy-id7500.9402 + - ethernet-phy-id7500.9412 + - ethernet-phy-id7500.9422 + - ethernet-phy-id7500.9432 + - ethernet-phy-id7500.9442 + - ethernet-phy-id7500.9452 + - ethernet-phy-id7500.9462 + - ethernet-phy-id7500.9472 + - ethernet-phy-id7500.9482 + - ethernet-phy-id7500.9492 + required: + - compatible + +properties: + reg: + maxItems: 1 + + firmware-name: + description: specify the name of PHY firmware to load + maxItems: 1 + +required: + - compatible + - reg + +if: + properties: + compatible: + contains: + const: ethernet-phy-id7500.9410 +then: + required: + - firmware-name +else: + properties: + firmware-name: false + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/leds/common.h> + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy@1f { + compatible = "ethernet-phy-id7500.9410", + "ethernet-phy-ieee802.3-c45"; + + reg = <31>; + firmware-name = "as21x1x_fw.bin"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_LAN; + function-enumerator = <0>; + default-state = "keep"; + }; + + led@1 { + reg = <1>; + color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_LAN; + function-enumerator = <1>; + default-state = "keep"; + }; + }; + }; + };
MAINTAINERS +1 -0
@@ -650,6 +650,7 @@ AEONSEMI PHY DRIVER M: Christian Marangi <[email protected]> L: [email protected] S: Maintained +F: Documentation/devicetree/bindings/net/aeonsemi,as21xxx.yaml F: drivers/net/phy/as21xxx.c AF8133J THREE-AXIS MAGNETOMETER DRIVER
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerRe: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
In reply to Christian MarangiQuoted 10 lines · On Thu, 10 Apr 2025 11:53:35 +0200 Christian Marangi wrote:
Add support for Aeonsemi AS21xxx 10G C45 PHYs. These PHYs integrate an IPC to setup some configuration and require special handling to sync with the parity bit. The parity bit is a way the IPC use to follow correct order of command sent.
Supported PHYs AS21011JB1, AS21011PB1, AS21010JB1, AS21010PB1, AS21511JB1, AS21511PB1, AS21510JB1, AS21510PB1, AS21210JB1, AS21210PB1 that all register with the PHY ID
0x75000x7510before the firmware is loaded.
Quoted 6 lines
They all support up to 5 LEDs with various HW mode supported.
While implementing it was found some strange coincidence with using the same logic for implementing C22 in MMD regs in Broadcom PHYs.
For reference here the AS21xxx PHY name logic:
Would any of the PHY maintainers be willing to cast their review tag upon this patch? :)
Andrew Lunn
maintainerRe: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
In reply to Christian MarangiQuoted 1 line
+#define
AEON_MAX_LDES5
AEON_MAX_LEDS?
drivers/net/phy/as21xxx.c line 191
Quoted 9 lines
drivers/net/phy/as21xxx.c new file +7
-0+#define AEON_IPC_DELAY 10000 +#define AEON_IPC_TIMEOUT (AEON_IPC_DELAY * 100) +#define AEON_IPC_DATA_MAX (8 * sizeof(u16)) + +static int aeon_ipc_rcv_msg (struct phy_device *phydev, +u16 ret_sts,u16 *data) +{
It would be good to add a comment here about what the return value means. I'm having to work hard to figure out if it is bytes, or number of u16s.
drivers/net/phy/as21xxx.c line 486
Quoted 12 lines
drivers/net/phy/as21xxx.c new file +12
-0+struct as21xxx_priv *priv = phydev->priv; +unsigned int size; +int ret; +int i; + +if ((ret_sts &AEON_IPC_STS_STATUS ) ==AEON_IPC_STS_STATUS_ERROR ) +return -EINVAL ; + +/* Prevent IPC from stack smashing the kernel */ + size =FIELD_GET (AEON_IPC_STS_SIZE , ret_sts); +if (size >AEON_IPC_DATA_MAX ) +return -EINVAL ;
This suggests size is bytes, and can be upto 16?
drivers/net/phy/as21xxx.c line 497
Quoted 11 lines
drivers/net/phy/as21xxx.c new file +11
-0+ +mutex_lock (&priv->ipc_lock); + +for (i =0 ; i <DIV_ROUND_UP (size,sizeof (u16)); i++) { + ret =phy_read_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_DATA (i)); +if (ret <0 ) { + size = ret; + goto out; + } + + data[i] = ret;
and this is looping up to 8 times reading words.
drivers/net/phy/as21xxx.c line 557
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+static int aeon_ipc_get_fw_version (struct phy_device *phydev) +{ +char fw_version[AEON_IPC_DATA_MAX +1 ]; +u16 ret_data[8 ], data[1 ];
I think there should be a #define for this 8. It is pretty fundamental to these message transfers.
drivers/net/phy/as21xxx.c line 561
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+u16 ret_sts; +int ret; + + data[0 ] =IPC_INFO_VERSION ;
Not a normal question i would ask for MDIO, but are there any endianness issues here? Since everything is in u16, the base size for MDIO, i doubt there is.
drivers/net/phy/as21xxx.c line 570
Quoted 9 lines
drivers/net/phy/as21xxx.c new file +8
-0+ ret =aeon_ipc_send_msg (phydev,IPC_CMD_INFO , data, +sizeof (data), &ret_sts); +if (ret) +return ret; + ret =aeon_ipc_rcv_msg (phydev, ret_sts, ret_data); +if (ret <0 ) +return ret; +
but ret is in bytes, not words, so we start getting into odd situations. Have you seen the firmware return an add number of bytes in its message? If it does, is it clear which part of the last word should be used.
drivers/net/phy/as21xxx.c line 573
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+ +/* Make sure FW version is NULL terminated */ +memcpy (fw_version, ret_data, ret); + fw_version[ret] ='\0' ;
Given that ret is bytes, this works, despite ret_data being words.
Andrew
Russell King (Oracle)
maintainerRe: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
In reply to Christian Marangidrivers/net/phy/as21xxx.c line 86
Quoted 8 lines · Christian Marangi
drivers/net/phy/as21xxx.c new file +8
-0+#define VEND1_IPC_DATA0 0x5808 +#define VEND1_IPC_DATA1 0x5809 +#define VEND1_IPC_DATA2 0x580a +#define VEND1_IPC_DATA3 0x580b +#define VEND1_IPC_DATA4 0x580c +#define VEND1_IPC_DATA5 0x580d +#define VEND1_IPC_DATA6 0x580e +#define VEND1_IPC_DATA7 0x580f
Do you use any of these other than the first? If not, please remove them, maybe adding a comment before the first stating that there are 8 registers.
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+static int aeon_ipcs_wait_cmd (struct phy_device *phydev,bool parity_status) +{ +u16 val; +
drivers/net/phy/as21xxx.c line 390
Quoted 10 lines
drivers/net/phy/as21xxx.c new file +10
-0+/* Exit condition logic: +* - Wait for parity bit equal +* - Wait for status success, error OR ready +*/ +return phy_read_mmd_poll_timeout (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_STS , val, +FIELD_GET (AEON_IPC_STS_PARITY , val) == parity_status && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_RCVD && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_PROCESS && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_BUSY , +AEON_IPC_DELAY ,AEON_IPC_TIMEOUT , false);
Hmm. I'm wondering whether:
static bool aeon_ipc_ready(u16 val, bool parity_status)
{
u16 status;
if (FIELD_GET(AEON_IPC_STS_PARITY, val) != parity_status)
return false;
status = val & AEON_IPC_STS_STATUS;
return status != AEON_IPC_STS_STATUS_RCVD &&
status != AEON_IPC_STS_STATUS_PROCESS &&
status != AEON_IPC_STS_STATUS_BUSY;
}would be better, and then maybe you can fit the code into less than 80 columns. I'm not a fan of FIELD_PREP_CONST() when it causes differing usage patterns like the above (FIELD_GET(AEON_IPC_STS_STATUS, val) would match the coding style, and probably makes no difference to the code emitted.)
Quoted 101 lines
drivers/net/phy/as21xxx.c new file +101
-0+} + +static int aeon_ipc_send_cmd (struct phy_device *phydev, +struct as21xxx_priv *priv, +u16 cmd,u16 *ret_sts) +{ +bool curr_parity; +int ret; + +/* The IPC sync by using a single parity bit. +* Each CMD have alternately this bit set or clear +* to understand correct flow and packet order. +*/ + curr_parity = priv->parity_status; +if (priv->parity_status) + cmd |=AEON_IPC_CMD_PARITY ; + +/* Always update parity for next packet */ + priv->parity_status = !priv->parity_status; + + ret =phy_write_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_CMD , cmd); +if (ret) +return ret; + +/* Wait for packet to be processed */ +usleep_range (AEON_IPC_DELAY ,AEON_IPC_DELAY +5000 ); + +/* With no ret_sts, ignore waiting for packet completion +* (ipc parity bit sync) +*/ +if (!ret_sts) +return 0 ; + + ret =aeon_ipcs_wait_cmd (phydev, curr_parity); +if (ret) +return ret; + + ret =phy_read_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_STS ); +if (ret <0 ) +return ret; + + *ret_sts = ret; +if ((*ret_sts &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_SUCCESS ) +return -EINVAL ; + +return 0 ; +} + +static int aeon_ipc_send_msg (struct phy_device *phydev, +u16 opcode,u16 *data,unsigned int data_len, +u16 *ret_sts) +{ +struct as21xxx_priv *priv = phydev->priv; +u16 cmd; +int ret; +int i; + +/* IPC have a max of 8 register to transfer data, +* make sure we never exceed this. +*/ +if (data_len >AEON_IPC_DATA_MAX ) +return -EINVAL ; + +mutex_lock (&priv->ipc_lock); + +for (i =0 ; i < data_len /sizeof (u16); i++) +phy_write_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_DATA (i), + data[i]); + + cmd =FIELD_PREP (AEON_IPC_CMD_SIZE , data_len) | +FIELD_PREP (AEON_IPC_CMD_OPCODE , opcode); + ret =aeon_ipc_send_cmd (phydev, priv, cmd, ret_sts); +if (ret) +phydev_err (phydev,"failed to send ipc msg for %x: %d\n" , + opcode, ret); + +mutex_unlock (&priv->ipc_lock); + +return ret; +} + +static int aeon_ipc_rcv_msg (struct phy_device *phydev, +u16 ret_sts,u16 *data) +{ +struct as21xxx_priv *priv = phydev->priv; +unsigned int size; +int ret; +int i; + +if ((ret_sts &AEON_IPC_STS_STATUS ) ==AEON_IPC_STS_STATUS_ERROR ) +return -EINVAL ; + +/* Prevent IPC from stack smashing the kernel */ + size =FIELD_GET (AEON_IPC_STS_SIZE , ret_sts); +if (size >AEON_IPC_DATA_MAX ) +return -EINVAL ; + +mutex_lock (&priv->ipc_lock); + +for (i =0 ; i <DIV_ROUND_UP (size,sizeof (u16)); i++) { + ret =phy_read_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_DATA (i));
drivers/net/phy/as21xxx.c line 501
Quoted 10 lines
drivers/net/phy/as21xxx.c new file +10
-0+if (ret <0 ) { + size = ret; + goto out; + } + + data[i] = ret; + } + +out: +mutex_unlock (&priv->ipc_lock);
I think the locking here is suspicious.
aeon_ipc_send_msg() takes the lock, writes the registers, and waits for the success signal, returning the status, and then drops the lock.
Time passes.
aeon_ipc_rcv_msg() is then called, which extracts the number of bytes to be read from the returned status, takes the lock, reads the registers, and then drops the lock.
So, what can happen is:
Thread 1 Thread 2 aeon_ipc_send_msg() aeon_ipc_send_msg() aeon_ipc_rcv_msg() aeon_ipc_rcv_msg()
Which means thread 1 reads the reply from thread 2's message.
So, this lock does nothing to really protect against the IPC mechanism against races.
I think you need to combine both into a single function that takes the lock once and releases it once.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Russell King (Oracle)
maintainerI'm sure you know, but your email address for linux-kernel is wrong.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Re: [net-next PATCH v7 3/6] net: phy: nxp-c45-tja11xx: simplify .match_phy_device OP
In reply to Christian MarangiQuoted 115 lines · Christian Marangi
Simplify .match_phy_device OP by using a generic function and using the new
phy_idPHY driver info instead of hardcoding the matching PHY ID with new variant for macsec andno_macsecPHYs.Also make use of
PHY_ID_MATCH_MODELmacro and dropPHY_ID_MASKdefine to introducephy_idandphy_id_maskagain inphy_driverstruct.Reviewed-by Russell King (Oracle) <[email protected]>Signed-off-by Christian Marangi <[email protected]>--- drivers/net/phy/nxp-c45-tja11xx.c | 45 ++++++++++++++----------------- 1 file changed, 20 insertions(+), 25 deletions(-)drivers/net/phy/nxp-c45-tja11xx.c +19
-24@@ -19,7 +19,6 @@#include "nxp-c45-tja11xx.h" -#define PHY_ID_MASK GENMASK(31, 4)/* Same id: TJA1103, TJA1104 */ #define PHY_ID_TJA_1103 0x001BB010/* Same id: TJA1120, TJA1121 */ @@ -1971,32 +1970,24 @@ static int nxp_c45_macsec_ability(struct phy_device *phydev)return macsec_ability; } -static int tja1103_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) +static int tja11xx_no_macsec_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) { -return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1103 ,PHY_ID_MASK ) && - !nxp_c45_macsec_ability (phydev); -} +if (!phy_id_compare (phydev->phy_id, phydrv->phy_id, + phydrv->phy_id_mask)) +return 0 ; -static int tja1104_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) -{ -return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1103 ,PHY_ID_MASK ) && -nxp_c45_macsec_ability (phydev); +return !nxp_c45_macsec_ability (phydev); } -static int tja1120_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) +static int tja11xx_macsec_match_phy_device (struct phy_device *phydev, +const struct phy_driver *phydrv) { -return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1120 ,PHY_ID_MASK ) && - !nxp_c45_macsec_ability (phydev); -} +if (!phy_id_compare (phydev->phy_id, phydrv->phy_id, + phydrv->phy_id_mask)) +return 0 ; -static int tja1121_match_phy_device (struct phy_device *phydev, -const struct phy_driver *phydrv) -{ -return phy_id_compare (phydev->phy_id,PHY_ID_TJA_1120 ,PHY_ID_MASK ) && -nxp_c45_macsec_ability (phydev); +return nxp_c45_macsec_ability (phydev); }static const struct nxp_c45_regmap tja1120_regmap = {@@ -2069,6 +2060,7 @@ static const struct nxp_c45_phy_data tja1120_phy_data = {static struct phy_driver nxp_c45_driver[] = { { +PHY_ID_MATCH_MODEL (PHY_ID_TJA_1103 ), .name ="NXP C45 TJA1103" , .get_features = nxp_c45_get_features, .driver_data = &tja1103_phy_data,@@ -2090,9 +2082,10 @@ static struct phy_driver nxp_c45_driver[] = { .get_sqi = nxp_c45_get_sqi, .get_sqi_max = nxp_c45_get_sqi_max, .remove = nxp_c45_remove, - .match_phy_device = tja1103_match_phy_device, + .match_phy_device = tja11xx_no_macsec_match_phy_device, }, { + PHY_ID_MATCH_MODEL(PHY_ID_TJA_1103), .name = "NXP C45 TJA1104", .get_features = nxp_c45_get_features, .driver_data = &tja1103_phy_data,@@ -2114,9 +2107,10 @@ static struct phy_driver nxp_c45_driver[] = { .get_sqi = nxp_c45_get_sqi, .get_sqi_max = nxp_c45_get_sqi_max, .remove = nxp_c45_remove, - .match_phy_device = tja1104_match_phy_device, + .match_phy_device = tja11xx_macsec_match_phy_device, }, { + PHY_ID_MATCH_MODEL(PHY_ID_TJA_1120), .name = "NXP C45 TJA1120", .get_features = nxp_c45_get_features, .driver_data = &tja1120_phy_data,@@ -2139,9 +2133,10 @@ static struct phy_driver nxp_c45_driver[] = { .get_sqi = nxp_c45_get_sqi, .get_sqi_max = nxp_c45_get_sqi_max, .remove = nxp_c45_remove, - .match_phy_device = tja1120_match_phy_device, + .match_phy_device = tja11xx_no_macsec_match_phy_device, }, { + PHY_ID_MATCH_MODEL(PHY_ID_TJA_1120), .name = "NXP C45 TJA1121", .get_features = nxp_c45_get_features, .driver_data = &tja1120_phy_data,
drivers/net/phy/nxp-c45-tja11xx.c static struct phy_driver nxp_c45_driver[] = { · line 2165
Quoted 8 lines
drivers/net/phy/nxp-c45-tja11xx.c +1
-1@@ -2164,7 +2159,7 @@ static struct phy_driver nxp_c45_driver[] = { .get_sqi = nxp_c45_get_sqi, .get_sqi_max = nxp_c45_get_sqi_max, .remove = nxp_c45_remove, - .match_phy_device = tja1121_match_phy_device, + .match_phy_device = tja11xx_macsec_match_phy_device, }, };
Christian Marangi
maintainerRe: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
In reply to Andrew LunnQuoted 55 lines · Andrew Lunn
Quoted 1 line
+#define
AEON_MAX_LDES5
AEON_MAX_LEDS?drivers/net/phy/as21xxx.c line 191
Quoted 9 lines
drivers/net/phy/as21xxx.c new file +7
-0+#define AEON_IPC_DELAY 10000 +#define AEON_IPC_TIMEOUT (AEON_IPC_DELAY * 100) +#define AEON_IPC_DATA_MAX (8 * sizeof(u16)) + +static int aeon_ipc_rcv_msg (struct phy_device *phydev, +u16 ret_sts,u16 *data) +{It would be good to add a comment here about what the return value means. I'm having to work hard to figure out if it is bytes, or number of u16s.
drivers/net/phy/as21xxx.c line 486
Quoted 12 lines
drivers/net/phy/as21xxx.c new file +12
-0+struct as21xxx_priv *priv = phydev->priv; +unsigned int size; +int ret; +int i; + +if ((ret_sts &AEON_IPC_STS_STATUS ) ==AEON_IPC_STS_STATUS_ERROR ) +return -EINVAL ; + +/* Prevent IPC from stack smashing the kernel */ + size =FIELD_GET (AEON_IPC_STS_SIZE , ret_sts); +if (size >AEON_IPC_DATA_MAX ) +return -EINVAL ;This suggests size is bytes, and can be upto 16?
drivers/net/phy/as21xxx.c line 497
Quoted 11 lines
drivers/net/phy/as21xxx.c new file +11
-0+ +mutex_lock (&priv->ipc_lock); + +for (i =0 ; i <DIV_ROUND_UP (size,sizeof (u16)); i++) { + ret =phy_read_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_DATA (i)); +if (ret <0 ) { + size = ret; + goto out; + } + + data[i] = ret;and this is looping up to 8 times reading words.
drivers/net/phy/as21xxx.c line 557
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+static int aeon_ipc_get_fw_version (struct phy_device *phydev) +{ +char fw_version[AEON_IPC_DATA_MAX +1 ]; +u16 ret_data[8 ], data[1 ];I think there should be a #define for this 8. It is pretty fundamental to these message transfers.
Quoted 9 lines
drivers/net/phy/as21xxx.c line 561
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+u16 ret_sts; +int ret; + + data[0 ] =IPC_INFO_VERSION ;Not a normal question i would ask for MDIO, but are there any endianness issues here? Since everything is in u16, the base size for MDIO, i doubt there is.
In theory not, anything comes to mine that might be problematic?
Quoted 5 lines
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+ ret =aeon_ipc_send_msg (phydev,IPC_CMD_INFO , data, +sizeof (data), &ret_sts); +if (ret) +return ret;
Quoted 10 lines
drivers/net/phy/as21xxx.c line 570
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+ ret =aeon_ipc_rcv_msg (phydev, ret_sts, ret_data); +if (ret <0 ) +return ret; +but ret is in bytes, not words, so we start getting into odd situations. Have you seen the firmware return an add number of bytes in its message? If it does, is it clear which part of the last word should be used.
ret is size from IPC STATUS that return the transmitted data in bytes. I use u16 to follow the fact that there are 8 rw IPC data register.
The returned firmware value is 1.8.2 for example and that is 5 bytes.
We allocate 17 bytes for the firmware string and we pass a buffer of 8 u16 (16 bytes)
Am I missing something?
Quoted 9 lines
drivers/net/phy/as21xxx.c line 573
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+ +/* Make sure FW version is NULL terminated */ +memcpy (fw_version, ret_data, ret); + fw_version[ret] ='\0' ;Given that ret is bytes, this works, despite
ret_databeing words.Andrew
Signature · 1 line
Ansuel
Christian Marangi
maintainerRe: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
In reply to Russell King (Oracle)Quoted 14 lines · Russell King (Oracle)
drivers/net/phy/as21xxx.c line 86
Quoted 8 lines · Christian Marangi
drivers/net/phy/as21xxx.c new file +8
-0+#define VEND1_IPC_DATA0 0x5808 +#define VEND1_IPC_DATA1 0x5809 +#define VEND1_IPC_DATA2 0x580a +#define VEND1_IPC_DATA3 0x580b +#define VEND1_IPC_DATA4 0x580c +#define VEND1_IPC_DATA5 0x580d +#define VEND1_IPC_DATA6 0x580e +#define VEND1_IPC_DATA7 0x580fDo you use any of these other than the first? If not, please remove them, maybe adding a comment before the first stating that there are 8 registers.
No since the macro is used. Also from Andrew request I will declare the max number of IPC data register so yes I can drop.
Quoted 31 lines
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+static int aeon_ipcs_wait_cmd (struct phy_device *phydev,bool parity_status) +{ +u16 val; +drivers/net/phy/as21xxx.c line 390
Quoted 10 lines
drivers/net/phy/as21xxx.c new file +10
-0+/* Exit condition logic: +* - Wait for parity bit equal +* - Wait for status success, error OR ready +*/ +return phy_read_mmd_poll_timeout (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_STS , val, +FIELD_GET (AEON_IPC_STS_PARITY , val) == parity_status && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_RCVD && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_PROCESS && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_BUSY , +AEON_IPC_DELAY ,AEON_IPC_TIMEOUT , false);Hmm. I'm wondering whether:
static bool
aeon_ipc_ready(u16 val, bool parity_status){ u16 status; if (FIELD_GET(AEON_IPC_STS_PARITY, val) != parity_status) return false; status = val & AEON_IPC_STS_STATUS; return status != AEON_IPC_STS_STATUS_RCVD && status != AEON_IPC_STS_STATUS_PROCESS && status != AEON_IPC_STS_STATUS_BUSY; }
Quoted 6 lines
would be better, and then maybe you can fit the code into less than 80 columns. I'm not a fan of
FIELD_PREP_CONST()when it causes differing usage patterns like the above (FIELD_GET(AEON_IPC_STS_STATUS, val)would match the coding style, and probably makes no difference to the code emitted.)
You are suggesting to use a generic readx function or use a while + sleep to use the suggested _ready function?
Quoted 131 lines
Quoted 101 lines
drivers/net/phy/as21xxx.c new file +101
-0+} + +static int aeon_ipc_send_cmd (struct phy_device *phydev, +struct as21xxx_priv *priv, +u16 cmd,u16 *ret_sts) +{ +bool curr_parity; +int ret; + +/* The IPC sync by using a single parity bit. +* Each CMD have alternately this bit set or clear +* to understand correct flow and packet order. +*/ + curr_parity = priv->parity_status; +if (priv->parity_status) + cmd |=AEON_IPC_CMD_PARITY ; + +/* Always update parity for next packet */ + priv->parity_status = !priv->parity_status; + + ret =phy_write_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_CMD , cmd); +if (ret) +return ret; + +/* Wait for packet to be processed */ +usleep_range (AEON_IPC_DELAY ,AEON_IPC_DELAY +5000 ); + +/* With no ret_sts, ignore waiting for packet completion +* (ipc parity bit sync) +*/ +if (!ret_sts) +return 0 ; + + ret =aeon_ipcs_wait_cmd (phydev, curr_parity); +if (ret) +return ret; + + ret =phy_read_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_STS ); +if (ret <0 ) +return ret; + + *ret_sts = ret; +if ((*ret_sts &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_SUCCESS ) +return -EINVAL ; + +return 0 ; +} + +static int aeon_ipc_send_msg (struct phy_device *phydev, +u16 opcode,u16 *data,unsigned int data_len, +u16 *ret_sts) +{ +struct as21xxx_priv *priv = phydev->priv; +u16 cmd; +int ret; +int i; + +/* IPC have a max of 8 register to transfer data, +* make sure we never exceed this. +*/ +if (data_len >AEON_IPC_DATA_MAX ) +return -EINVAL ; + +mutex_lock (&priv->ipc_lock); + +for (i =0 ; i < data_len /sizeof (u16); i++) +phy_write_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_DATA (i), + data[i]); + + cmd =FIELD_PREP (AEON_IPC_CMD_SIZE , data_len) | +FIELD_PREP (AEON_IPC_CMD_OPCODE , opcode); + ret =aeon_ipc_send_cmd (phydev, priv, cmd, ret_sts); +if (ret) +phydev_err (phydev,"failed to send ipc msg for %x: %d\n" , + opcode, ret); + +mutex_unlock (&priv->ipc_lock); + +return ret; +} + +static int aeon_ipc_rcv_msg (struct phy_device *phydev, +u16 ret_sts,u16 *data) +{ +struct as21xxx_priv *priv = phydev->priv; +unsigned int size; +int ret; +int i; + +if ((ret_sts &AEON_IPC_STS_STATUS ) ==AEON_IPC_STS_STATUS_ERROR ) +return -EINVAL ; + +/* Prevent IPC from stack smashing the kernel */ + size =FIELD_GET (AEON_IPC_STS_SIZE , ret_sts); +if (size >AEON_IPC_DATA_MAX ) +return -EINVAL ; + +mutex_lock (&priv->ipc_lock); + +for (i =0 ; i <DIV_ROUND_UP (size,sizeof (u16)); i++) { + ret =phy_read_mmd (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_DATA (i));drivers/net/phy/as21xxx.c line 501
Quoted 10 lines
drivers/net/phy/as21xxx.c new file +10
-0+if (ret <0 ) { + size = ret; + goto out; + } + + data[i] = ret; + } + +out: +mutex_unlock (&priv->ipc_lock);I think the locking here is suspicious.
aeon_ipc_send_msg()takes the lock, writes the registers, and waits for the success signal, returning the status, and then drops the lock.Time passes.
aeon_ipc_rcv_msg()is then called, which extracts the number of bytes to be read from the returned status, takes the lock, reads the registers, and then drops the lock.So, what can happen is:
Thread 1 Thread 2 aeon_ipc_send_msg() aeon_ipc_send_msg() aeon_ipc_rcv_msg() aeon_ipc_rcv_msg()
Quoted 8 lines
Which means thread 1 reads the reply from thread 2's message.
So, this lock does nothing to really protect against the IPC mechanism against races.
I think you need to combine both into a single function that takes the lock once and releases it once.
Mhhh I think I will have to create __ function for locked and non-locked variant. I think I woulkd just handle the lock in the function using send and rcv and maybe add some smatch tag to make sure the lock is taken when entering those functions.
Signature · 1 line
Ansuel
Andrew Lunn
maintainerRe: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
Quoted 21 lines
Quoted 14 lines
static bool
aeon_ipc_ready(u16 val, bool parity_status){ u16 status; if (FIELD_GET(AEON_IPC_STS_PARITY, val) != parity_status) return false; status = val & AEON_IPC_STS_STATUS; return status != AEON_IPC_STS_STATUS_RCVD && status != AEON_IPC_STS_STATUS_PROCESS && status != AEON_IPC_STS_STATUS_BUSY; }Quoted 6 lines
would be better, and then maybe you can fit the code into less than 80 columns. I'm not a fan of
FIELD_PREP_CONST()when it causes differing usage patterns like the above (FIELD_GET(AEON_IPC_STS_STATUS, val)would match the coding style, and probably makes no difference to the code emitted.)
Quoted 2 lines
You are suggesting to use a generic readx function or use a while + sleep to use the suggested
_readyfunction?
#define phy_read_mmd_poll_timeout(phydev, devaddr, regnum, val, cond, \
sleep_us, timeout_us, sleep_before_read) \
({ \
int __ret, __val; \
__ret = read_poll_timeout(__val = phy_read_mmd, val, \
__val < 0 || (cond), \The macro magic probably allows you to make cond a function call.
Andrew
Russell King (Oracle)
maintainerRe: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
In reply to Christian MarangiQuoted 39 lines · Christian Marangi
Quoted 31 lines · Russell King (Oracle)
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+static int aeon_ipcs_wait_cmd (struct phy_device *phydev,bool parity_status) +{ +u16 val; +drivers/net/phy/as21xxx.c line 390
Quoted 10 lines
drivers/net/phy/as21xxx.c new file +10
-0+/* Exit condition logic: +* - Wait for parity bit equal +* - Wait for status success, error OR ready +*/ +return phy_read_mmd_poll_timeout (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_STS , val, +FIELD_GET (AEON_IPC_STS_PARITY , val) == parity_status && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_RCVD && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_PROCESS && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_BUSY , +AEON_IPC_DELAY ,AEON_IPC_TIMEOUT , false);Hmm. I'm wondering whether:
static bool
aeon_ipc_ready(u16 val, bool parity_status){ u16 status; if (FIELD_GET(AEON_IPC_STS_PARITY, val) != parity_status) return false; status = val & AEON_IPC_STS_STATUS; return status != AEON_IPC_STS_STATUS_RCVD && status != AEON_IPC_STS_STATUS_PROCESS && status != AEON_IPC_STS_STATUS_BUSY; }Quoted 6 lines
would be better, and then maybe you can fit the code into less than 80 columns. I'm not a fan of
FIELD_PREP_CONST()when it causes differing usage patterns like the above (FIELD_GET(AEON_IPC_STS_STATUS, val)would match the coding style, and probably makes no difference to the code emitted.)
Quoted 2 lines
You are suggesting to use a generic readx function or use a while + sleep to use the suggested
_readyfunction?
To write the other part of it (I thought this would be obvious!):
+ return phy_read_mmd_poll_timeout(phydev, MDIO_MMD_VEND1, VEND1_IPC_STS, val,
+ aeon_ipc_ready(val, parity_status),
+ AEON_IPC_DELAY, AEON_IPC_TIMEOUT, false);
Quoted 4 lines
Mhhh I think I will have to create __ function for locked and non-locked variant. I think I woulkd just handle the lock in the function using send and rcv and maybe add some smatch tag to make sure the lock is taken when entering those functions.
If you don't need the receive part, then pass NULL in for the receive data pointer, and use that to conditionalise that part?
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
Christian Marangi
maintainerRe: [net-next PATCH v7 5/6] net: phy: Add support for Aeonsemi AS21xxx PHYs
Quoted 46 lines · Russell King (Oracle)
Quoted 39 lines · Christian Marangi
Quoted 31 lines · Russell King (Oracle)
Quoted 4 lines
drivers/net/phy/as21xxx.c new file +4
-0+static int aeon_ipcs_wait_cmd (struct phy_device *phydev,bool parity_status) +{ +u16 val; +drivers/net/phy/as21xxx.c line 390
Quoted 10 lines
drivers/net/phy/as21xxx.c new file +10
-0+/* Exit condition logic: +* - Wait for parity bit equal +* - Wait for status success, error OR ready +*/ +return phy_read_mmd_poll_timeout (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_STS , val, +FIELD_GET (AEON_IPC_STS_PARITY , val) == parity_status && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_RCVD && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_PROCESS && + (val &AEON_IPC_STS_STATUS ) !=AEON_IPC_STS_STATUS_BUSY , +AEON_IPC_DELAY ,AEON_IPC_TIMEOUT , false);Hmm. I'm wondering whether:
static bool
aeon_ipc_ready(u16 val, bool parity_status){ u16 status; if (FIELD_GET(AEON_IPC_STS_PARITY, val) != parity_status) return false; status = val & AEON_IPC_STS_STATUS; return status != AEON_IPC_STS_STATUS_RCVD && status != AEON_IPC_STS_STATUS_PROCESS && status != AEON_IPC_STS_STATUS_BUSY; }Quoted 6 lines
would be better, and then maybe you can fit the code into less than 80 columns. I'm not a fan of
FIELD_PREP_CONST()when it causes differing usage patterns like the above (FIELD_GET(AEON_IPC_STS_STATUS, val)would match the coding style, and probably makes no difference to the code emitted.)Quoted 2 lines
You are suggesting to use a generic readx function or use a while + sleep to use the suggested
_readyfunction?To write the other part of it (I thought this would be obvious!):
drivers/net/phy/as21xxx.c line 390
Quoted 3 lines
drivers/net/phy/as21xxx.c new file +3
-0+return phy_read_mmd_poll_timeout (phydev,MDIO_MMD_VEND1 ,VEND1_IPC_STS , val, +aeon_ipc_ready (val, parity_status), +AEON_IPC_DELAY ,AEON_IPC_TIMEOUT , false);
Eh I never considered that I could totally pass entire function in the condition part.
Quoted 8 lines
Quoted 4 lines
Mhhh I think I will have to create __ function for locked and non-locked variant. I think I woulkd just handle the lock in the function using send and rcv and maybe add some smatch tag to make sure the lock is taken when entering those functions.
If you don't need the receive part, then pass NULL in for the receive data pointer, and use that to conditionalise that part?
Ok yes that can also work.
Signature · 1 line
Ansuel