net: phy: move PHY package code to its own source file
Subsystems (6)
Heiner Kallweit
maintainercover net: phy: move PHY package code to its own source file
This series contributes to cleaning up phylib by moving PHY package related code to its own source file.
Heiner Kallweit (8):
net: phy: move PHY package code from phy_device.c to own source file
net: phy: move PHY package related code from phy.h to phy_package.c
net: phy: add getters for public members in struct phy_package_shared
net: phy: qca807x: use new phy_package_shared getters
net: phy: micrel: use new phy_package_shared getters
net: phy: mtk-ge-soc: use new phy_package_shared getters
net: phy: mscc: use new phy_package_shared getters
net: phy: make struct phy_package_shared private to phylib
drivers/net/phy/Makefile | 3 +- drivers/net/phy/mediatek/mtk-ge-soc.c | 10 +- drivers/net/phy/micrel.c | 12 +- drivers/net/phy/mscc/mscc_ptp.c | 15 +- drivers/net/phy/phy_device.c | 237 ------------------ drivers/net/phy/phy_package.c | 348 ++++++++++++++++++++++++++ drivers/net/phy/qcom/qca807x.c | 20 +- include/linux/phy.h | 125 +-------- 8 files changed, 396 insertions(+), 374 deletions(-) create mode 100644 drivers/net/phy/phy_package.c
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH 1/8 net: phy: move PHY package code from phy_device.c to own source file
This patch is the first step in moving the PHY package related code to its own source file. No functional change intended.
--- drivers/net/phy/Makefile | 3 +- drivers/net/phy/phy_device.c | 237 --------------------------------- drivers/net/phy/phy_package.c | 244 ++++++++++++++++++++++++++++++++++ 3 files changed, 246 insertions(+), 238 deletions(-) create mode 100644 drivers/net/phy/phy_package.c
drivers/net/phy/Makefile +2 -1
@@ -2,7 +2,8 @@ # Makefile for Linux PHY drivers libphy-y := phy.o phy-c45.o phy-core.o phy_device.o \ - linkmode.o phy_link_topology.o + linkmode.o phy_link_topology.o \ + phy_package.o mdio-bus-y += mdio_bus.o mdio_device.o ifdef CONFIG_MDIO_DEVICE
drivers/net/phy/phy_device.c +0 -237
243 lines not on this page · raw message
drivers/net/phy/phy_package.c new file +244 -0
244 lines not on this page · raw message
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH 2/8 net: phy: move PHY package related code from phy.h to phy_package.c
In reply to Heiner KallweitMove PHY package related inline functions from phy.h to phy_package.c. While doing so remove locked versions phy_package_read() and phy_package_write() which have no user.
--- drivers/net/phy/phy_package.c | 61 +++++++++++++++++++++++ include/linux/phy.h | 91 +++-------------------------------- 2 files changed, 68 insertions(+), 84 deletions(-)
drivers/net/phy/phy_package.c +61 -0
@@ -6,6 +6,67 @@#include <linux/of.h> #include <linux/phy.h> +int phy_package_address (struct phy_device *phydev,unsigned int addr_offset) +{ +struct phy_package_shared *shared = phydev->shared; +u8 base_addr = shared->base_addr; + +if (addr_offset >=PHY_MAX_ADDR - base_addr) +return -EIO ; + +/* we know that addr will be in the range 0..31 and thus the +* implicit cast to a signed int is not a problem. +*/ +return base_addr + addr_offset; +} +EXPORT_SYMBOL_GPL (phy_package_address); + +int __phy_package_read (struct phy_device *phydev,unsigned int addr_offset, +u32 regnum) +{ +int addr =phy_package_address (phydev, addr_offset); + +if (addr <0 ) +return addr; + +return __mdiobus_read (phydev->mdio.bus, addr, regnum); +} +EXPORT_SYMBOL_GPL (__phy_package_read); + +int __phy_package_write (struct phy_device *phydev,unsigned int addr_offset, +u32 regnum,u16 val) +{ +int addr =phy_package_address (phydev, addr_offset); + +if (addr <0 ) +return addr; + +return __mdiobus_write (phydev->mdio.bus, addr, regnum, val); +} +EXPORT_SYMBOL_GPL (__phy_package_write); + +static bool __phy_package_set_once (struct phy_device *phydev,unsigned int b) +{ +struct phy_package_shared *shared = phydev->shared; + +if (!shared) +return false; + +return !test_and_set_bit (b, &shared->flags); +} + +bool phy_package_init_once (struct phy_device *phydev) +{ +return __phy_package_set_once (phydev,0 ); +} +EXPORT_SYMBOL_GPL (phy_package_init_once); + +bool phy_package_probe_once (struct phy_device *phydev) +{ +return __phy_package_set_once (phydev,1 ); +} +EXPORT_SYMBOL_GPL (phy_package_probe_once); +/** * phy_package_join - join a common PHY group * @phydev: target phy_device struct
include/linux/phy.h +7 -84
109 lines not on this page · raw message
Signature · 1 line
2.48.1
Andrew Lunn
maintainerRe: [PATCH net-next 2/8] net: phy: move PHY package related code from phy.h to phy_package.c
Quoted 3 lines · Heiner Kallweit
Move PHY package related inline functions from
phy.htophy_package.c. While doing so remove locked versionsphy_package_read()andphy_package_write()which have no user.
What combination of builtin and modules have you tried? Code like this is often in the header because we get linker errors in some configurations. It might be worth checking the versions of the original patches from Christian to see if there was such issues.
Andrew
Heiner Kallweit
maintainerRe: [PATCH net-next 2/8] net: phy: move PHY package related code from phy.h to phy_package.c
Quoted 10 lines · Andrew Lunn
Quoted 3 lines · Heiner Kallweit
Move PHY package related inline functions from
phy.htophy_package.c. While doing so remove locked versionsphy_package_read()andphy_package_write()which have no user.What combination of builtin and modules have you tried? Code like this is often in the header because we get linker errors in some configurations. It might be worth checking the versions of the original patches from Christian to see if there was such issues.
The PHY package functions are used by PHY drivers only, all of them have a Kconfig dependency on PHYLIB. I don't see a scenario where we could have the problem you're mentioning. But right, the PHY package function declarations are a candidate for a new header file not to be used outside drivers/net/phy.
Quoted 1 line
Andrew
Heiner
Paolo Abeni
maintainerRe: [PATCH net-next 2/8] net: phy: move PHY package related code from phy.h to phy_package.c
Quoted 11 lines · Heiner Kallweit
Quoted 10 lines · Andrew Lunn
Quoted 3 lines · Heiner Kallweit
Move PHY package related inline functions from
phy.htophy_package.c. While doing so remove locked versionsphy_package_read()andphy_package_write()which have no user.What combination of builtin and modules have you tried? Code like this is often in the header because we get linker errors in some configurations. It might be worth checking the versions of the original patches from Christian to see if there was such issues.
Quoted 5 lines
The PHY package functions are used by PHY drivers only, all of them have a
Kconfigdependency on PHYLIB. I don't see a scenario where we could have the problem you're mentioning. But right, the PHY package function declarations are a candidate for a new header file not to be used outsidedrivers/net/phy.
IMHO it's easy that some corner case will pass unnoticed until some build breakage is reported. I suggest to keep such functions in a (private) header from the start.
Thanks,
Paolo
Heiner Kallweit
maintainerPATCH 3/8 net: phy: add getters for public members of struct phy_package_shared
In reply to Heiner KallweitAdd getters for public members, this prepares for making struct phy_package_shared private to phylib.
--- drivers/net/phy/phy_package.c | 12 ++++++++++++ include/linux/phy.h | 3 +++ 2 files changed, 15 insertions(+)
drivers/net/phy/phy_package.c +12 -0
@@ -6,6 +6,18 @@#include <linux/of.h> #include <linux/phy.h> +struct device_node *phy_package_shared_get_node (struct phy_device *phydev) +{ +return phydev->shared->np; +} +EXPORT_SYMBOL_GPL (phy_package_shared_get_node); + +void *phy_package_shared_get_priv (struct phy_device *phydev) +{ +return phydev->shared->priv; +} +EXPORT_SYMBOL_GPL (phy_package_shared_get_priv); +int phy_package_address (struct phy_device *phydev,unsigned int addr_offset) {struct phy_package_shared *shared = phydev->shared;
include/linux/phy.h +3 -0
@@ -2095,6 +2095,9 @@ int phy_ethtool_get_link_ksettings(struct net_device *ndev,int phy_ethtool_set_link_ksettings (struct net_device *ndev,const struct ethtool_link_ksettings *cmd);int phy_ethtool_nway_reset (struct net_device *ndev); + +struct device_node *phy_package_shared_get_node (struct phy_device *phydev); +void *phy_package_shared_get_priv (struct phy_device *phydev);int phy_package_join (struct phy_device *phydev,int base_addr,size_t priv_size);int of_phy_package_join (struct phy_device *phydev,size_t priv_size);void phy_package_leave (struct phy_device *phydev);
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerRe: [PATCH net-next 3/8] net: phy: add getters for public members of struct phy_package_shared
include/linux/phy.h int phy_ethtool_get_link_ksettings(struct net_device *ndev, · line 2100
Quoted 2 lines · On Wed, 19 Feb 2025 22:04:47 +0100 Heiner Kallweit wrote:
include/linux/phy.h +2
-0+struct device_node *phy_package_shared_get_node (struct phy_device *phydev); +void *phy_package_shared_get_priv (struct phy_device *phydev);
A bit sad that none of the users can fit in a line with this naming. Isn't "shared" implied by "package" here ?
How would you feel about phy_package_get_priv() ?
Paolo Abeni
maintainerRe: [PATCH net-next 3/8] net: phy: add getters for public members of struct phy_package_shared
Quoted 7 lines · Jakub Kicinski
include/linux/phy.h int phy_ethtool_get_link_ksettings(struct net_device *ndev, · line 2100
Quoted 2 lines · On Wed, 19 Feb 2025 22:04:47 +0100 Heiner Kallweit wrote:
include/linux/phy.h +2
-0+struct device_node *phy_package_shared_get_node (struct phy_device *phydev); +void *phy_package_shared_get_priv (struct phy_device *phydev);A bit sad that none of the users can fit in a line with this naming. Isn't "shared" implied by "package" here ?
How would you feel aboutphy_package_get_priv()?
FWIW I personally agree the latter would be a better name.
@Heiner: could you please give that naming schema a shot here?
/P
Heiner Kallweit
maintainerRe: [PATCH net-next 3/8] net: phy: add getters for public members of struct phy_package_shared
Quoted 9 lines · Paolo Abeni
Quoted 7 lines · Jakub Kicinski
include/linux/phy.h int phy_ethtool_get_link_ksettings(struct net_device *ndev, · line 2100
Quoted 2 lines · On Wed, 19 Feb 2025 22:04:47 +0100 Heiner Kallweit wrote:
include/linux/phy.h +2
-0+struct device_node *phy_package_shared_get_node (struct phy_device *phydev); +void *phy_package_shared_get_priv (struct phy_device *phydev);A bit sad that none of the users can fit in a line with this naming. Isn't "shared" implied by "package" here ?
How would you feel aboutphy_package_get_priv()?
Quoted 6 lines
FWIW I personally agree the latter would be a better name.
@Heiner: could you please give that naming schema a shot here?
/P
Sure. I'll submit a v2 with the suggested changes.
Heiner Kallweit
maintainerPATCH 4/8 net: phy: qca807x: use new phy_package_shared getters
In reply to Heiner KallweitUse the new getters for members of struct phy_package_shared.
--- drivers/net/phy/qcom/qca807x.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/net/phy/qcom/qca807x.c +11 -9
@@ -486,13 +486,16 @@ static int qca807x_read_status(struct phy_device *phydev)static int qca807x_phy_package_probe_once (struct phy_device *phydev) { -struct phy_package_shared *shared = phydev->shared; -struct qca807x_shared_priv *priv = shared->priv; +struct qca807x_shared_priv *priv;unsigned int tx_drive_strength;const char *package_mode_name; +struct device_node *np; + + priv =phy_package_shared_get_priv (phydev); + np =phy_package_shared_get_node (phydev);/* Default to 600mw if not defined */ -if (of_property_read_u32 (shared->np,"qcom,tx-drive-strength-milliwatt" , +if (of_property_read_u32 (np,"qcom,tx-drive-strength-milliwatt" , &tx_drive_strength)) tx_drive_strength =600 ;
@@ -541,7 +544,7 @@ static int qca807x_phy_package_probe_once(struct phy_device *phydev) } priv->package_mode =PHY_INTERFACE_MODE_NA ; -if (!of_property_read_string (shared->np,"qcom,package-mode" , +if (!of_property_read_string (np,"qcom,package-mode" , &package_mode_name)) {if (!strcasecmp (package_mode_name,phy_modes (PHY_INTERFACE_MODE_PSGMII )))
@@ -558,10 +561,11 @@ static int qca807x_phy_package_probe_once(struct phy_device *phydev)static int qca807x_phy_package_config_init_once (struct phy_device *phydev) { -struct phy_package_shared *shared = phydev->shared; -struct qca807x_shared_priv *priv = shared->priv; +struct qca807x_shared_priv *priv;int val, ret; + priv =phy_package_shared_get_priv (phydev); +/* Make sure PHY follow PHY package mode if enforced */ if (priv->package_mode !=PHY_INTERFACE_MODE_NA && phydev->interface != priv->package_mode)
@@ -708,7 +712,6 @@ static int qca807x_probe(struct phy_device *phydev)struct device_node *node = phydev->mdio.dev.of_node;struct qca807x_shared_priv *shared_priv;struct device *dev = &phydev->mdio.dev; -struct phy_package_shared *shared;struct qca807x_priv *priv;int ret;
@@ -722,8 +725,7 @@ static int qca807x_probe(struct phy_device *phydev)return ret; } - shared = phydev->shared; - shared_priv = shared->priv; + shared_priv =phy_package_shared_get_priv (phydev); priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv)
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH 5/8 net: phy: micrel: use new phy_package_shared getters
In reply to Heiner KallweitUse the new getters for members of struct phy_package_shared.
--- drivers/net/phy/micrel.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/phy/micrel.c +9 -3
@@ -2632,7 +2632,9 @@ static int lan8814_ts_info(struct mii_timestamper *mii_ts, struct kernel_ethtool { struct kszphy_ptp_priv *ptp_priv = container_of(mii_ts, struct kszphy_ptp_priv, mii_ts);struct phy_device *phydev = ptp_priv->phydev; -struct lan8814_shared_priv *shared = phydev->shared->priv; +struct lan8814_shared_priv *shared; + + shared =phy_package_shared_get_priv (phydev); info->so_timestamping =SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE |
@@ -3653,9 +3655,11 @@ static int lan8814_gpio_process_cap(struct lan8814_shared_priv *shared)static int lan8814_handle_gpio_interrupt (struct phy_device *phydev,u16 status) { -struct lan8814_shared_priv *shared = phydev->shared->priv; +struct lan8814_shared_priv *shared;int ret; + shared =phy_package_shared_get_priv (phydev); +mutex_lock (&shared->shared_lock); ret =lan8814_gpio_process_cap (shared);mutex_unlock (&shared->shared_lock);
@@ -3864,7 +3868,9 @@ static void lan8814_ptp_init(struct phy_device *phydev)static int lan8814_ptp_probe_once (struct phy_device *phydev) { -struct lan8814_shared_priv *shared = phydev->shared->priv; +struct lan8814_shared_priv *shared; + + shared =phy_package_shared_get_priv (phydev);/* Initialise shared lock for clock*/ mutex_init (&shared->shared_lock);
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH 6/8 net: phy: mtk-ge-soc: use new phy_package_shared getters
In reply to Heiner KallweitUse the new getters for members of struct phy_package_shared.
--- drivers/net/phy/mediatek/mtk-ge-soc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/phy/mediatek/mtk-ge-soc.c +7 -3
@@ -1190,9 +1190,11 @@ static int mt798x_phy_led_hw_control_set(struct phy_device *phydev, u8 index,static bool mt7988_phy_led_get_polarity (struct phy_device *phydev,int led_num) { -struct mtk_socphy_shared *priv = phydev->shared->priv; +struct mtk_socphy_shared *priv;u32 polarities; + priv =phy_package_shared_get_priv (phydev); +if (led_num ==0 ) polarities = ~(priv->boottrap);else
@@ -1229,11 +1231,13 @@ static int mt7988_phy_fix_leds_polarities(struct phy_device *phydev)static int mt7988_phy_probe_shared (struct phy_device *phydev) {struct device_node *np =dev_of_node (&phydev->mdio.bus->dev); -struct mtk_socphy_shared *shared = phydev->shared->priv; +struct mtk_socphy_shared *shared;struct regmap *regmap;u32 reg;int ret; + shared =phy_package_shared_get_priv (phydev); +/* The LED0 of the 4 PHYs in MT7988 are wired to SoC pins LED_A, LED_B, * LED_C and LED_D respectively. At the same time those pins are used to * bootstrap configuration of the reference clock source (LED_A),
@@ -1280,7 +1284,7 @@ static int mt7988_phy_probe(struct phy_device *phydev)return err; } - shared = phydev->shared->priv; + shared =phy_package_shared_get_priv (phydev); priv = &shared->priv[phydev->mdio.addr]; phydev->priv = priv;
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH 7/8 net: phy: mscc: use new phy_package_shared getters
In reply to Heiner KallweitUse the new getters for members of struct phy_package_shared.
--- drivers/net/phy/mscc/mscc_ptp.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/net/phy/mscc/mscc_ptp.c +9 -6
@@ -645,11 +645,12 @@ static int __vsc85xx_gettime(struct ptp_clock_info *info, struct timespec64 *ts) { struct vsc85xx_ptp *ptp = container_of(info, struct vsc85xx_ptp, caps);struct phy_device *phydev = ptp->phydev; -struct vsc85xx_shared_private *shared = - (struct vsc85xx_shared_private *)phydev->shared->priv;struct vsc8531_private *priv = phydev->priv; +struct vsc85xx_shared_private *shared;u32 val; + shared =phy_package_shared_get_priv (phydev); + val =vsc85xx_ts_read_csr (phydev,PROCESSOR ,MSCC_PHY_PTP_LTC_CTRL ); val |=PTP_LTC_CTRL_SAVE_ENA ;vsc85xx_ts_write_csr (phydev,PROCESSOR ,MSCC_PHY_PTP_LTC_CTRL , val);
@@ -696,11 +697,12 @@ static int __vsc85xx_settime(struct ptp_clock_info *info, { struct vsc85xx_ptp *ptp = container_of(info, struct vsc85xx_ptp, caps);struct phy_device *phydev = ptp->phydev; -struct vsc85xx_shared_private *shared = - (struct vsc85xx_shared_private *)phydev->shared->priv;struct vsc8531_private *priv = phydev->priv; +struct vsc85xx_shared_private *shared;u32 val; + shared =phy_package_shared_get_priv (phydev); +vsc85xx_ts_write_csr (phydev,PROCESSOR ,MSCC_PHY_PTP_LTC_LOAD_SEC_MSB ,PTP_LTC_LOAD_SEC_MSB (ts->tv_sec)); vsc85xx_ts_write_csr(phydev, PROCESSOR, MSCC_PHY_PTP_LTC_LOAD_SEC_LSB,
@@ -1580,8 +1582,9 @@ int vsc8584_ptp_probe(struct phy_device *phydev)int vsc8584_ptp_probe_once (struct phy_device *phydev) { -struct vsc85xx_shared_private *shared = - (struct vsc85xx_shared_private *)phydev->shared->priv; +struct vsc85xx_shared_private *shared; + + shared =phy_package_shared_get_priv (phydev);/* Initialize shared GPIO lock */ mutex_init (&shared->gpio_lock);
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH 8/8 net: phy: make struct phy_package_shared private to phylib
In reply to Heiner KallweitMove definition of struct phy_package_shared to phy_package.c to make it private to phylib.
--- drivers/net/phy/phy_package.c | 31 +++++++++++++++++++++++++++++++ include/linux/phy.h | 31 ------------------------------- 2 files changed, 31 insertions(+), 31 deletions(-)
drivers/net/phy/phy_package.c +31 -0
@@ -6,6 +6,37 @@#include <linux/of.h> #include <linux/phy.h> +/** +* struct phy_package_shared - Shared information in PHY packages +* @base_addr: Base PHY address of PHY package used to combine PHYs +* in one package and for offset calculation of phy_package_read/write +* @np: Pointer to the Device Node if PHY package defined in DT +* @refcnt: Number of PHYs connected to this shared data +* @flags: Initialization of PHY package +* @priv_size: Size of the shared private data @priv +* @priv: Driver private data shared across a PHY package +* +* Represents a shared structure between different phydev's in the same +* package, for example a quad PHY. See phy_package_join() and +* phy_package_leave(). +*/ +struct phy_package_shared { +u8 base_addr; +/* With PHY package defined in DT this points to the PHY package node */ +struct device_node *np; +refcount_t refcnt; +unsigned long flags; +size_t priv_size; + +/* private data pointer */ +/* note that this pointer is shared between different phydevs and +* the user has to take care of appropriate locking. It is allocated +* and freed automatically by phy_package_join() and +* phy_package_leave(). +*/ +void *priv; +}; +struct device_node *phy_package_shared_get_node (struct phy_device *phydev) {return phydev->shared->np;
include/linux/phy.h +0 -31
@@ -322,37 +322,6 @@ struct mdio_bus_stats {struct u64_stats_sync syncp; }; -/** -* struct phy_package_shared - Shared information in PHY packages -* @base_addr: Base PHY address of PHY package used to combine PHYs -* in one package and for offset calculation of phy_package_read/write -* @np: Pointer to the Device Node if PHY package defined in DT -* @refcnt: Number of PHYs connected to this shared data -* @flags: Initialization of PHY package -* @priv_size: Size of the shared private data @priv -* @priv: Driver private data shared across a PHY package -* -* Represents a shared structure between different phydev's in the same -* package, for example a quad PHY. See phy_package_join() and -* phy_package_leave(). -*/ -struct phy_package_shared { -u8 base_addr; -/* With PHY package defined in DT this points to the PHY package node */ -struct device_node *np; -refcount_t refcnt; -unsigned long flags; -size_t priv_size; - -/* private data pointer */ -/* note that this pointer is shared between different phydevs and -* the user has to take care of appropriate locking. It is allocated -* and freed automatically by phy_package_join() and -* phy_package_leave(). -*/ -void *priv; -}; -/** * struct mii_bus - Represents an MDIO bus *
Signature · 1 line
2.48.1