Skip to content

Commit

Permalink
net: phy: move PHY package related code from phy.h to phy_package.c
Browse files Browse the repository at this point in the history
Move 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.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://patch.msgid.link/a4518379-7a5d-45f3-831c-b7fde6512c65@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Heiner Kallweit authored and Jakub Kicinski committed Mar 6, 2025
1 parent e0327e9 commit e7f984e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 86 deletions.
1 change: 1 addition & 0 deletions drivers/net/phy/bcm54140.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/module.h>
#include <linux/phy.h>

#include "phylib.h"
#include "bcm-phy-lib.h"

/* RDB per-port registers
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/phy/mscc/mscc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions drivers/net/phy/phy-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/phy.h>
#include <linux/of.h>

#include "phylib.h"
#include "phylib-internal.h"

/**
Expand Down
61 changes: 61 additions & 0 deletions drivers/net/phy/phy_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <linux/phy.h>

#include "phylib.h"
#include "phylib-internal.h"

struct device_node *phy_package_get_node(struct phy_device *phydev)
{
Expand All @@ -20,6 +21,66 @@ void *phy_package_get_priv(struct phy_device *phydev)
}
EXPORT_SYMBOL_GPL(phy_package_get_priv);

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;
}

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
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/phy/phylib-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
6 changes: 6 additions & 0 deletions drivers/net/phy/phylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
86 changes: 0 additions & 86 deletions include/linux/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,6 @@ struct phy_package_shared {
void *priv;
};

/* used as bit number in atomic bitops */
#define PHY_SHARED_F_INIT_DONE 0
#define PHY_SHARED_F_PROBE_DONE 1

/**
* struct mii_bus - Represents an MDIO bus
*
Expand Down Expand Up @@ -2149,67 +2145,6 @@ int __phy_hwtstamp_set(struct phy_device *phydev,
struct kernel_hwtstamp_config *config,
struct netlink_ext_ack *extack);

static inline 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;
}

static inline 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);
}

static inline 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);
}

static inline 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);
}

static inline 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);
}

int __phy_package_read_mmd(struct phy_device *phydev,
unsigned int addr_offset, int devad,
u32 regnum);
Expand All @@ -2226,27 +2161,6 @@ int phy_package_write_mmd(struct phy_device *phydev,
unsigned int addr_offset, int devad,
u32 regnum, u16 val);

static inline 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);
}

static inline bool phy_package_init_once(struct phy_device *phydev)
{
return __phy_package_set_once(phydev, PHY_SHARED_F_INIT_DONE);
}

static inline bool phy_package_probe_once(struct phy_device *phydev)
{
return __phy_package_set_once(phydev, PHY_SHARED_F_PROBE_DONE);
}

extern const struct bus_type mdio_bus_type;

struct mdio_board_info {
Expand Down

0 comments on commit e7f984e

Please sign in to comment.