diff options
Diffstat (limited to 'include/linux/phy.h')
| -rw-r--r-- | include/linux/phy.h | 80 | 
1 files changed, 46 insertions, 34 deletions
| diff --git a/include/linux/phy.h b/include/linux/phy.h index 05fde31b6dc6..d6f3641e7933 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -16,8 +16,10 @@  #ifndef __PHY_H  #define __PHY_H +#include <linux/compiler.h>  #include <linux/spinlock.h>  #include <linux/ethtool.h> +#include <linux/mdio.h>  #include <linux/mii.h>  #include <linux/module.h>  #include <linux/timer.h> @@ -58,6 +60,7 @@  #define PHY_HAS_INTERRUPT	0x00000001  #define PHY_HAS_MAGICANEG	0x00000002  #define PHY_IS_INTERNAL		0x00000004 +#define MDIO_DEVICE_IS_PHY	0x80000000  /* Interface Mode definitions */  typedef enum { @@ -158,8 +161,8 @@ struct mii_bus {  	const char *name;  	char id[MII_BUS_ID_SIZE];  	void *priv; -	int (*read)(struct mii_bus *bus, int phy_id, int regnum); -	int (*write)(struct mii_bus *bus, int phy_id, int regnum, u16 val); +	int (*read)(struct mii_bus *bus, int addr, int regnum); +	int (*write)(struct mii_bus *bus, int addr, int regnum, u16 val);  	int (*reset)(struct mii_bus *bus);  	/* @@ -178,7 +181,7 @@ struct mii_bus {  	struct device dev;  	/* list of all PHYs on bus */ -	struct phy_device *phy_map[PHY_MAX_ADDR]; +	struct mdio_device *mdio_map[PHY_MAX_ADDR];  	/* PHY addresses to be ignored when probing */  	u32 phy_mask; @@ -187,10 +190,10 @@ struct mii_bus {  	u32 phy_ignore_ta_mask;  	/* -	 * Pointer to an array of interrupts, each PHY's -	 * interrupt at the index matching its address +	 * An array of interrupts, each PHY's interrupt at the index +	 * matching its address  	 */ -	int *irq; +	int irq[PHY_MAX_ADDR];  };  #define to_mii_bus(d) container_of(d, struct mii_bus, dev) @@ -212,11 +215,6 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)  void devm_mdiobus_free(struct device *dev, struct mii_bus *bus);  struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr); -int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum); -int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum); -int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val); -int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val); -  #define PHY_INTERRUPT_DISABLED	0x0  #define PHY_INTERRUPT_ENABLED	0x80000000 @@ -361,14 +359,12 @@ struct phy_c45_device_ids {   * handling, as well as handling shifts in PHY hardware state   */  struct phy_device { +	struct mdio_device mdio; +  	/* Information about the PHY type */  	/* And management functions */  	struct phy_driver *drv; -	struct mii_bus *bus; - -	struct device dev; -  	u32 phy_id;  	struct phy_c45_device_ids c45_ids; @@ -384,9 +380,6 @@ struct phy_device {  	phy_interface_t interface; -	/* Bus address of the PHY (0-31) */ -	int addr; -  	/*  	 * forced speed & duplex (no autoneg)  	 * partner speed & duplex & pause (autoneg) @@ -435,10 +428,12 @@ struct phy_device {  	void (*adjust_link)(struct net_device *dev);  }; -#define to_phy_device(d) container_of(d, struct phy_device, dev) +#define to_phy_device(d) container_of(to_mdio_device(d), \ +				      struct phy_device, mdio)  /* struct phy_driver: Driver structure for a particular PHY type   * + * driver_data: static driver data   * phy_id: The result of reading the UID registers of this PHY   *   type, and ANDing them with the phy_id_mask.  This driver   *   only works for PHYs with IDs which match this field @@ -448,7 +443,6 @@ struct phy_device {   *   by this PHY   * flags: A bitfield defining certain other features this PHY   *   supports (like interrupts) - * driver_data: static driver data   *   * The drivers must implement config_aneg and read_status.  All   * other functions are optional. Note that none of these @@ -459,6 +453,7 @@ struct phy_device {   * supported in the driver).   */  struct phy_driver { +	struct mdio_driver_common mdiodrv;  	u32 phy_id;  	char *name;  	unsigned int phy_id_mask; @@ -589,9 +584,14 @@ struct phy_driver {  	int (*module_eeprom)(struct phy_device *dev,  			     struct ethtool_eeprom *ee, u8 *data); -	struct device_driver driver; +	/* Get statistics from the phy using ethtool */ +	int (*get_sset_count)(struct phy_device *dev); +	void (*get_strings)(struct phy_device *dev, u8 *data); +	void (*get_stats)(struct phy_device *dev, +			  struct ethtool_stats *stats, u64 *data);  }; -#define to_phy_driver(d) container_of(d, struct phy_driver, driver) +#define to_phy_driver(d) container_of(to_mdio_common_driver(d),		\ +				      struct phy_driver, mdiodrv)  #define PHY_ANY_ID "MATCH ANY PHY"  #define PHY_ANY_UID 0xffffffff @@ -619,7 +619,7 @@ static inline int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)  	if (!phydev->is_c45)  		return -EOPNOTSUPP; -	return mdiobus_read(phydev->bus, phydev->addr, +	return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr,  			    MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff));  } @@ -627,14 +627,12 @@ static inline int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)   * phy_read_mmd_indirect - reads data from the MMD registers   * @phydev: The PHY device bus   * @prtad: MMD Address - * @devad: MMD DEVAD   * @addr: PHY address on the MII bus   *   * Description: it reads data from the MMD registers (clause 22 to access to   * clause 45) of the specified phy address.   */ -int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, -			  int devad, int addr); +int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, int devad);  /**   * phy_read - Convenience function for reading a given PHY register @@ -647,7 +645,7 @@ int phy_read_mmd_indirect(struct phy_device *phydev, int prtad,   */  static inline int phy_read(struct phy_device *phydev, u32 regnum)  { -	return mdiobus_read(phydev->bus, phydev->addr, regnum); +	return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);  }  /** @@ -662,7 +660,7 @@ static inline int phy_read(struct phy_device *phydev, u32 regnum)   */  static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val)  { -	return mdiobus_write(phydev->bus, phydev->addr, regnum, val); +	return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);  }  /** @@ -725,7 +723,7 @@ static inline int phy_write_mmd(struct phy_device *phydev, int devad,  	regnum = MII_ADDR_C45 | ((devad & 0x1f) << 16) | (regnum & 0xffff); -	return mdiobus_write(phydev->bus, phydev->addr, regnum, val); +	return mdiobus_write(phydev->mdio.bus, phydev->mdio.addr, regnum, val);  }  /** @@ -733,14 +731,13 @@ static inline int phy_write_mmd(struct phy_device *phydev, int devad,   * @phydev: The PHY device   * @prtad: MMD Address   * @devad: MMD DEVAD - * @addr: PHY address on the MII bus   * @data: data to write in the MMD register   *   * Description: Write data from the MMD registers of the specified   * phy address.   */  void phy_write_mmd_indirect(struct phy_device *phydev, int prtad, -			    int devad, int addr, u32 data); +			    int devad, u32 data);  struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,  				     bool is_c45, @@ -775,6 +772,20 @@ static inline int phy_read_status(struct phy_device *phydev)  	return phydev->drv->read_status(phydev);  } +#define phydev_err(_phydev, format, args...)	\ +	dev_err(&_phydev->mdio.dev, format, ##args) + +#define phydev_dbg(_phydev, format, args...)	\ +	dev_dbg(&_phydev->mdio.dev, format, ##args); + +static inline const char *phydev_name(const struct phy_device *phydev) +{ +	return dev_name(&phydev->mdio.dev); +} + +void phy_attached_print(struct phy_device *phydev, const char *fmt, ...) +	__printf(2, 3); +void phy_attached_info(struct phy_device *phydev);  int genphy_config_init(struct phy_device *phydev);  int genphy_setup_forced(struct phy_device *phydev);  int genphy_restart_aneg(struct phy_device *phydev); @@ -787,8 +798,9 @@ int genphy_resume(struct phy_device *phydev);  int genphy_soft_reset(struct phy_device *phydev);  void phy_driver_unregister(struct phy_driver *drv);  void phy_drivers_unregister(struct phy_driver *drv, int n); -int phy_driver_register(struct phy_driver *new_driver); -int phy_drivers_register(struct phy_driver *new_driver, int n); +int phy_driver_register(struct phy_driver *new_driver, struct module *owner); +int phy_drivers_register(struct phy_driver *new_driver, int n, +			 struct module *owner);  void phy_state_machine(struct work_struct *work);  void phy_change(struct work_struct *work);  void phy_mac_interrupt(struct phy_device *phydev, int new_link); @@ -833,7 +845,7 @@ extern struct bus_type mdio_bus_type;  #define phy_module_driver(__phy_drivers, __count)			\  static int __init phy_module_init(void)					\  {									\ -	return phy_drivers_register(__phy_drivers, __count);		\ +	return phy_drivers_register(__phy_drivers, __count, THIS_MODULE); \  }									\  module_init(phy_module_init);						\  static void __exit phy_module_exit(void)				\ | 
