net: phy: move PHY package code to its own source file
Subsystems (7)
Heiner Kallweit
maintainerv3 cover 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.
v2:
- rename the getters
- add a new header file phylib.h, which is used by PHY drivers only v3:
- include phylib.h in bcm54140.c
Heiner Kallweit (8):
net: phy: move PHY package code from phy_device.c to own source file
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: mediatek: use new phy_package_shared getters
net: phy: mscc: use new phy_package_shared getters
net: phy: move PHY package related code from phy.h to phy_package.c
net: phy: remove remaining PHY package related definitions from phy.h
drivers/net/phy/Makefile | 3 +- drivers/net/phy/bcm54140.c | 1 + drivers/net/phy/mediatek/mtk-ge-soc.c | 7 +- drivers/net/phy/micrel.c | 9 +- drivers/net/phy/mscc/mscc_main.c | 2 + drivers/net/phy/mscc/mscc_ptp.c | 14 +- drivers/net/phy/phy-core.c | 1 + drivers/net/phy/phy_device.c | 237 ----------------- drivers/net/phy/phy_package.c | 350 ++++++++++++++++++++++++++ drivers/net/phy/phylib-internal.h | 2 + drivers/net/phy/phylib.h | 28 +++ drivers/net/phy/qcom/qca807x.c | 16 +- include/linux/phy.h | 124 --------- 13 files changed, 410 insertions(+), 384 deletions(-) create mode 100644 drivers/net/phy/phy_package.c create mode 100644 drivers/net/phy/phylib.h
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH v3 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 v3 2/8 net: phy: add getters for public members in struct phy_package_shared
In reply to Heiner KallweitAdd getters for public members, this prepares for making struct phy_package_shared private to phylib. Declare the getters in a new header file phylib.h, which will be used by PHY drivers only.
---
v2:
- rename getters
--- drivers/net/phy/phy_package.c | 14 ++++++++++++++ drivers/net/phy/phylib.h | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 drivers/net/phy/phylib.h
drivers/net/phy/phy_package.c +14 -0
@@ -6,6 +6,20 @@#include <linux/of.h> #include <linux/phy.h> +#include "phylib.h" + +struct device_node *phy_package_get_node (struct phy_device *phydev) +{ +return phydev->shared->np; +} +EXPORT_SYMBOL_GPL (phy_package_get_node); + +void *phy_package_get_priv (struct phy_device *phydev) +{ +return phydev->shared->priv; +} +EXPORT_SYMBOL_GPL (phy_package_get_priv); +/** * phy_package_join - join a common PHY group * @phydev: target phy_device struct
drivers/net/phy/phylib.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* phylib header +*/ + +#ifndef __PHYLIB_H +#define __PHYLIB_H + +struct device_node ; +struct phy_device ; + +struct device_node *phy_package_get_node (struct phy_device *phydev); +void *phy_package_get_priv (struct phy_device *phydev); + +#endif /* __PHYLIB_H */
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH v3 3/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 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/net/phy/qcom/qca807x.c +7 -9
@@ -15,6 +15,7 @@#include <linux/gpio/driver.h> #include <linux/sfp.h> +#include "../phylib.h" #include "qcom.h" #define QCA807X_CHIP_CONFIGURATION 0x1f
@@ -486,13 +487,13 @@ 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 =phy_package_get_priv (phydev); +struct device_node *np =phy_package_get_node (phydev);unsigned int tx_drive_strength;const char *package_mode_name;/* 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 +542,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,8 +559,7 @@ 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 =phy_package_get_priv (phydev);int val, ret;/* Make sure PHY follow PHY package mode if enforced */
@@ -708,7 +708,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 +721,7 @@ static int qca807x_probe(struct phy_device *phydev)return ret; } - shared = phydev->shared; - shared_priv = shared->priv; + shared_priv =phy_package_get_priv (phydev); priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv)
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH v3 4/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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/phy/micrel.c +5 -4
@@ -34,6 +34,8 @@#include <linux/net_tstamp.h> #include <linux/gpio/consumer.h> +#include "phylib.h" +/* Operation Mode Strap Override */ #define MII_KSZPHY_OMSO 0x16#define KSZPHY_OMSO_FACTORY_TEST BIT(15)
@@ -2631,8 +2633,7 @@ static void lan8814_ptp_tx_ts_get(struct phy_device *phydev,static int lan8814_ts_info (struct mii_timestamper *mii_ts,struct kernel_ethtool_ts_info *info) { 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 =phy_package_get_priv (ptp_priv->phydev); info->so_timestamping =SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_RX_HARDWARE |
@@ -3653,7 +3654,7 @@ 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 =phy_package_get_priv (phydev);int ret;mutex_lock (&shared->shared_lock);
@@ -3864,7 +3865,7 @@ 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 =phy_package_get_priv (phydev);/* Initialise shared lock for clock*/ mutex_init (&shared->shared_lock);
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH v3 5/8 net: phy: mediatek: 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/phy/mediatek/mtk-ge-soc.c +4 -3
@@ -8,6 +8,7 @@#include <linux/phy.h> #include <linux/regmap.h> +#include "../phylib.h" #include "mtk.h" #define MTK_GPHY_ID_MT7981 0x03a29461
@@ -1278,7 +1279,7 @@ 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 =phy_package_get_priv (phydev);u32 polarities;if (led_num ==0 )
@@ -1317,7 +1318,7 @@ 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 =phy_package_get_priv (phydev);struct regmap *regmap;u32 reg;int ret;
@@ -1368,7 +1369,7 @@ static int mt7988_phy_probe(struct phy_device *phydev)return err; } - shared = phydev->shared->priv; + shared =phy_package_get_priv (phydev); priv = &shared->priv[phydev->mdio.addr]; phydev->priv = priv;
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH v3 6/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 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/phy/mscc/mscc_ptp.c +8 -6
@@ -17,6 +17,7 @@#include <linux/udp.h> #include <linux/unaligned.h> +#include "../phylib.h" #include "mscc.h" #include "mscc_ptp.h"
@@ -645,11 +646,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_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 +698,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_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 +1583,7 @@ 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 =phy_package_get_priv (phydev);/* Initialize shared GPIO lock */ mutex_init (&shared->gpio_lock);
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH v3 7/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/bcm54140.c | 1 + drivers/net/phy/mscc/mscc_main.c | 2 + drivers/net/phy/phy-core.c | 1 + drivers/net/phy/phy_package.c | 61 ++++++++++++++++++++++ drivers/net/phy/phylib-internal.h | 2 + drivers/net/phy/phylib.h | 6 +++ include/linux/phy.h | 86 ------------------------------- 7 files changed, 73 insertions(+), 86 deletions(-)
drivers/net/phy/bcm54140.c +1 -0
@@ -10,6 +10,7 @@#include <linux/module.h> #include <linux/phy.h> +#include "phylib.h" #include "bcm-phy-lib.h" /* RDB per-port registers
drivers/net/phy/mscc/mscc_main.c +2 -0
@@ -17,6 +17,8 @@#include <linux/of.h> #include <linux/netdevice.h> #include <dt-bindings/net/mscc-phy-vsc8531.h> + +#include "../phylib.h" #include "mscc_serdes.h" #include "mscc.h"
drivers/net/phy/phy-core.c +1 -0
@@ -6,6 +6,7 @@#include <linux/phy.h> #include <linux/of.h> +#include "phylib.h" #include "phylib-internal.h" /**
drivers/net/phy/phy_package.c +61 -0
73 lines not on this page · raw message
drivers/net/phy/phylib-internal.h +2 -0
@@ -20,6 +20,8 @@ void of_set_phy_timing_role(struct phy_device *phydev);int phy_speed_down_core (struct phy_device *phydev);void phy_check_downshift (struct phy_device *phydev); +int phy_package_address (struct phy_device *phydev,unsigned int addr_offset); +int genphy_c45_read_eee_adv (struct phy_device *phydev,unsigned long *adv);#endif /* __PHYLIB_INTERNAL_H */
drivers/net/phy/phylib.h +6 -0
@@ -11,5 +11,11 @@ struct phy_device;struct device_node *phy_package_get_node (struct phy_device *phydev);void *phy_package_get_priv (struct phy_device *phydev); +int __phy_package_read (struct phy_device *phydev,unsigned int addr_offset, +u32 regnum); +int __phy_package_write (struct phy_device *phydev,unsigned int addr_offset, +u32 regnum,u16 val); +bool phy_package_init_once (struct phy_device *phydev); +bool phy_package_probe_once (struct phy_device *phydev);#endif /* __PHYLIB_H */
include/linux/phy.h +0 -86
104 lines not on this page · raw message
Signature · 1 line
2.48.1
Heiner Kallweit
maintainerPATCH v3 8/8 net: phy: remove remaining PHY package related definitions from phy.h
In reply to Heiner KallweitMove definition of struct phy_package_shared to phy_package.c, and move remaining PHY package related declarations from phy.h to phylib.h, thus making them accessible for PHY drivers only.
--- drivers/net/phy/phy_package.c | 31 ++++++++++++++++++++++++++++ drivers/net/phy/phylib.h | 7 +++++++ include/linux/phy.h | 38 ----------------------------------- 3 files changed, 38 insertions(+), 38 deletions(-)
drivers/net/phy/phy_package.c +31 -0
@@ -9,6 +9,37 @@#include "phylib.h" #include "phylib-internal.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_get_node (struct phy_device *phydev) {return phydev->shared->np;
drivers/net/phy/phylib.h +7 -0
@@ -17,5 +17,12 @@ int __phy_package_write(struct phy_device *phydev, unsigned int addr_offset, u32 regnum, u16 val);bool phy_package_init_once (struct phy_device *phydev);bool phy_package_probe_once (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); +int devm_phy_package_join (struct device *dev,struct phy_device *phydev, +int base_addr,size_t priv_size); +int devm_of_phy_package_join (struct device *dev,struct phy_device *phydev, +size_t priv_size);#endif /* __PHYLIB_H */
include/linux/phy.h +0 -38
@@ -319,37 +319,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 *
@@ -2109,13 +2078,6 @@ 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); -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); -int devm_phy_package_join (struct device *dev,struct phy_device *phydev, -int base_addr,size_t priv_size); -int devm_of_phy_package_join (struct device *dev,struct phy_device *phydev, -size_t priv_size);int __init mdio_bus_init (void );void mdio_bus_exit (void );
Signature · 1 line
2.48.1
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Mon, 3 Mar 2025 21:13:05 +0100 you wrote:
This series contributes to cleaning up phylib by moving PHY package related code to its own source file.
v2:
- rename the getters
- add a new header filephylib.h, which is used by PHY drivers only v3:
- includephylib.hinbcm54140.c[...]
Here is the summary with links:
- [net-next,v3,1/8] net: phy: move PHY package code from phy_device.c to own source file
https://git.kernel.org/netdev/net-next/c/61dc9cae8727 - [net-next,v3,2/8] net: phy: add getters for public members in struct phy_package_shared https://git.kernel.org/netdev/net-next/c/2c8cd9783f46 - [net-next,v3,3/8] net: phy: qca807x: use new phy_package_shared getters https://git.kernel.org/netdev/net-next/c/947030f3c32b - [net-next,v3,4/8] net: phy: micrel: use new phy_package_shared getters https://git.kernel.org/netdev/net-next/c/890fe6841d81 - [net-next,v3,5/8] net: phy: mediatek: use new phy_package_shared getters https://git.kernel.org/netdev/net-next/c/dc5a6164feda - [net-next,v3,6/8] net: phy: mscc: use new phy_package_shared getters https://git.kernel.org/netdev/net-next/c/e0327e9f8597 - [net-next,v3,7/8] net: phy: move PHY package related code from phy.h to phy_package.c https://git.kernel.org/netdev/net-next/c/e7f984e925d2 - [net-next,v3,8/8] net: phy: remove remaining PHY package related definitions from phy.h https://git.kernel.org/netdev/net-next/c/a40028497769
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html