Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
phy.h File Reference
#include <linux/spinlock.h>
#include <linux/ethtool.h>
#include <linux/mii.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/mod_devicetable.h>
#include <linux/atomic.h>

Go to the source code of this file.

Data Structures

struct  mii_bus
 
struct  phy_c45_device_ids
 
struct  phy_device
 
struct  phy_driver
 
struct  phy_fixup
 

Macros

#define PHY_BASIC_FEATURES
 
#define PHY_GBIT_FEATURES
 
#define PHY_POLL   -1
 
#define PHY_IGNORE_INTERRUPT   -2
 
#define PHY_HAS_INTERRUPT   0x00000001
 
#define PHY_HAS_MAGICANEG   0x00000002
 
#define PHY_INIT_TIMEOUT   100000
 
#define PHY_STATE_TIME   1
 
#define PHY_FORCE_TIMEOUT   10
 
#define PHY_AN_TIMEOUT   10
 
#define PHY_MAX_ADDR   32
 
#define PHY_ID_FMT   "%s:%02x"
 
#define MII_BUS_ID_SIZE   (20 - 3)
 
#define MII_ADDR_C45   (1<<30)
 
#define to_mii_bus(d)   container_of(d, struct mii_bus, dev)
 
#define PHY_INTERRUPT_DISABLED   0x0
 
#define PHY_INTERRUPT_ENABLED   0x80000000
 
#define to_phy_device(d)   container_of(d, struct phy_device, dev)
 
#define to_phy_driver(d)   container_of(d, struct phy_driver, driver)
 
#define PHY_ANY_ID   "MATCH ANY PHY"
 
#define PHY_ANY_UID   0xffffffff
 

Enumerations

enum  phy_interface_t {
  PHY_INTERFACE_MODE_NA, PHY_INTERFACE_MODE_MII, PHY_INTERFACE_MODE_GMII, PHY_INTERFACE_MODE_SGMII,
  PHY_INTERFACE_MODE_TBI, PHY_INTERFACE_MODE_RMII, PHY_INTERFACE_MODE_RGMII, PHY_INTERFACE_MODE_RGMII_ID,
  PHY_INTERFACE_MODE_RGMII_RXID, PHY_INTERFACE_MODE_RGMII_TXID, PHY_INTERFACE_MODE_RTBI, PHY_INTERFACE_MODE_SMII
}
 
enum  phy_state {
  PHY_DOWN =0, PHY_STARTING, PHY_READY, PHY_PENDING,
  PHY_UP, PHY_AN, PHY_RUNNING, PHY_NOLINK,
  PHY_FORCING, PHY_CHANGELINK, PHY_HALTED, PHY_RESUMING
}
 

Functions

struct mii_busmdiobus_alloc_size (size_t)
 
int mdiobus_register (struct mii_bus *bus)
 
void mdiobus_unregister (struct mii_bus *bus)
 
void mdiobus_free (struct mii_bus *bus)
 
struct phy_devicemdiobus_scan (struct mii_bus *bus, int addr)
 
int mdiobus_read (struct mii_bus *bus, int addr, u32 regnum)
 
int mdiobus_write (struct mii_bus *bus, int addr, u32 regnum, u16 val)
 
struct phy_devicephy_device_create (struct mii_bus *bus, int addr, int phy_id, bool is_c45, struct phy_c45_device_ids *c45_ids)
 
struct phy_deviceget_phy_device (struct mii_bus *bus, int addr, bool is_c45)
 
int phy_device_register (struct phy_device *phy)
 
int phy_init_hw (struct phy_device *phydev)
 
struct phy_devicephy_attach (struct net_device *dev, const char *bus_id, u32 flags, phy_interface_t interface)
 
struct phy_devicephy_find_first (struct mii_bus *bus)
 
int phy_connect_direct (struct net_device *dev, struct phy_device *phydev, void(*handler)(struct net_device *), u32 flags, phy_interface_t interface)
 
struct phy_devicephy_connect (struct net_device *dev, const char *bus_id, void(*handler)(struct net_device *), u32 flags, phy_interface_t interface)
 
void phy_disconnect (struct phy_device *phydev)
 
void phy_detach (struct phy_device *phydev)
 
void phy_start (struct phy_device *phydev)
 
void phy_stop (struct phy_device *phydev)
 
int phy_start_aneg (struct phy_device *phydev)
 
int phy_stop_interrupts (struct phy_device *phydev)
 
int genphy_restart_aneg (struct phy_device *phydev)
 
int genphy_config_aneg (struct phy_device *phydev)
 
int genphy_update_link (struct phy_device *phydev)
 
int genphy_read_status (struct phy_device *phydev)
 
int genphy_suspend (struct phy_device *phydev)
 
int genphy_resume (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)
 
void phy_state_machine (struct work_struct *work)
 
void phy_start_machine (struct phy_device *phydev, void(*handler)(struct net_device *))
 
void phy_stop_machine (struct phy_device *phydev)
 
int phy_ethtool_sset (struct phy_device *phydev, struct ethtool_cmd *cmd)
 
int phy_ethtool_gset (struct phy_device *phydev, struct ethtool_cmd *cmd)
 
int phy_mii_ioctl (struct phy_device *phydev, struct ifreq *ifr, int cmd)
 
int phy_start_interrupts (struct phy_device *phydev)
 
void phy_print_status (struct phy_device *phydev)
 
void phy_device_free (struct phy_device *phydev)
 
int phy_register_fixup (const char *bus_id, u32 phy_uid, u32 phy_uid_mask, int(*run)(struct phy_device *))
 
int phy_register_fixup_for_id (const char *bus_id, int(*run)(struct phy_device *))
 
int phy_register_fixup_for_uid (u32 phy_uid, u32 phy_uid_mask, int(*run)(struct phy_device *))
 
int phy_scan_fixups (struct phy_device *phydev)
 
int phy_init_eee (struct phy_device *phydev, bool clk_stop_enable)
 
int phy_get_eee_err (struct phy_device *phydev)
 
int phy_ethtool_set_eee (struct phy_device *phydev, struct ethtool_eee *data)
 
int phy_ethtool_get_eee (struct phy_device *phydev, struct ethtool_eee *data)
 
int __init mdio_bus_init (void)
 
void mdio_bus_exit (void)
 

Variables

struct bus_type mdio_bus_type
 

Macro Definition Documentation

#define MII_ADDR_C45   (1<<30)

Definition at line 88 of file phy.h.

#define MII_BUS_ID_SIZE   (20 - 3)

Definition at line 84 of file phy.h.

#define PHY_AN_TIMEOUT   10

Definition at line 73 of file phy.h.

#define PHY_ANY_ID   "MATCH ANY PHY"

Definition at line 462 of file phy.h.

#define PHY_ANY_UID   0xffffffff

Definition at line 463 of file phy.h.

#define PHY_BASIC_FEATURES
Value:
SUPPORTED_10baseT_Full | \
SUPPORTED_100baseT_Half | \
SUPPORTED_100baseT_Full | \
SUPPORTED_Autoneg | \
SUPPORTED_TP | \
SUPPORTED_MII)

Definition at line 30 of file phy.h.

#define PHY_FORCE_TIMEOUT   10

Definition at line 72 of file phy.h.

#define PHY_GBIT_FEATURES
Value:
SUPPORTED_1000baseT_Half | \
SUPPORTED_1000baseT_Full)

Definition at line 38 of file phy.h.

#define PHY_HAS_INTERRUPT   0x00000001

Definition at line 50 of file phy.h.

#define PHY_HAS_MAGICANEG   0x00000002

Definition at line 51 of file phy.h.

#define PHY_ID_FMT   "%s:%02x"

Definition at line 78 of file phy.h.

#define PHY_IGNORE_INTERRUPT   -2

Definition at line 48 of file phy.h.

#define PHY_INIT_TIMEOUT   100000

Definition at line 70 of file phy.h.

#define PHY_INTERRUPT_DISABLED   0x0

Definition at line 148 of file phy.h.

#define PHY_INTERRUPT_ENABLED   0x80000000

Definition at line 149 of file phy.h.

#define PHY_MAX_ADDR   32

Definition at line 75 of file phy.h.

#define PHY_POLL   -1

Definition at line 47 of file phy.h.

#define PHY_STATE_TIME   1

Definition at line 71 of file phy.h.

#define to_mii_bus (   d)    container_of(d, struct mii_bus, dev)

Definition at line 132 of file phy.h.

#define to_phy_device (   d)    container_of(d, struct phy_device, dev)

Definition at line 358 of file phy.h.

#define to_phy_driver (   d)    container_of(d, struct phy_driver, driver)

Definition at line 460 of file phy.h.

Enumeration Type Documentation

Enumerator:
PHY_INTERFACE_MODE_NA 
PHY_INTERFACE_MODE_MII 
PHY_INTERFACE_MODE_GMII 
PHY_INTERFACE_MODE_SGMII 
PHY_INTERFACE_MODE_TBI 
PHY_INTERFACE_MODE_RMII 
PHY_INTERFACE_MODE_RGMII 
PHY_INTERFACE_MODE_RGMII_ID 
PHY_INTERFACE_MODE_RGMII_RXID 
PHY_INTERFACE_MODE_RGMII_TXID 
PHY_INTERFACE_MODE_RTBI 
PHY_INTERFACE_MODE_SMII 

Definition at line 54 of file phy.h.

enum phy_state
Enumerator:
PHY_DOWN 
PHY_STARTING 
PHY_READY 
PHY_PENDING 
PHY_UP 
PHY_AN 
PHY_RUNNING 
PHY_NOLINK 
PHY_FORCING 
PHY_CHANGELINK 
PHY_HALTED 
PHY_RESUMING 

Definition at line 231 of file phy.h.

Function Documentation

int genphy_config_aneg ( struct phy_device phydev)

genphy_config_aneg - restart auto-negotiation or write BMCR : target phy_device struct

Description: If auto-negotiation is enabled, we configure the advertising, and then restart auto-negotiation. If it is not enabled, then we write the BMCR.

Definition at line 754 of file phy_device.c.

int genphy_read_status ( struct phy_device phydev)

genphy_read_status - check the link status and update current link state : target phy_device struct

Description: Check the link, then figure out the current state by comparing what we advertise with what the link partner advertises. Start by checking the gigabit possibilities, then move on to 10/100.

Definition at line 829 of file phy_device.c.

int genphy_restart_aneg ( struct phy_device phydev)

genphy_restart_aneg - Enable and Restart Autonegotiation : target phy_device struct

Definition at line 725 of file phy_device.c.

int genphy_resume ( struct phy_device phydev)

Definition at line 977 of file phy_device.c.

int genphy_suspend ( struct phy_device phydev)

Definition at line 962 of file phy_device.c.

int genphy_update_link ( struct phy_device phydev)

genphy_update_link - update link status in : target phy_device struct

Description: Update the value in phydev->link to reflect the current link value. In order to do this, we need to read the status register twice, keeping the second value.

Definition at line 795 of file phy_device.c.

struct phy_device* get_phy_device ( struct mii_bus bus,
int  addr,
bool  is_c45 
)
read

get_phy_device - reads the specified PHY device and returns its struct : the target MII bus : PHY address on the MII bus : If true the PHY uses the 802.3 clause 45 protocol

Description: Reads the ID registers of the PHY at on the , then allocates and returns the phy_device to represent it.

Definition at line 328 of file phy_device.c.

void mdio_bus_exit ( void  )

Definition at line 455 of file mdio_bus.c.

int __init mdio_bus_init ( void  )

Definition at line 441 of file mdio_bus.c.

struct mii_bus* mdiobus_alloc_size ( size_t  size)
read

mdiobus_alloc_size - allocate a mii_bus structure : extra amount of memory to allocate for private storage. If non-zero, then bus->priv is points to that memory.

Description: called by a bus driver to allocate an mii_bus structure to fill in.

Definition at line 52 of file mdio_bus.c.

void mdiobus_free ( struct mii_bus bus)

mdiobus_free - free a struct mii_bus : mii_bus to free

This function releases the reference to the underlying device object in the mii_bus. If this is the last reference, the mii_bus will be freed.

Definition at line 215 of file mdio_bus.c.

int mdiobus_read ( struct mii_bus bus,
int  addr,
u32  regnum 
)

mdiobus_read - Convenience function for reading a given MII mgmt register : the mii_bus struct : the phy address : register number to read

NOTE: MUST NOT be called from interrupt context, because the bus read/write functions may wait for an interrupt to conclude the operation.

Definition at line 261 of file mdio_bus.c.

int mdiobus_register ( struct mii_bus bus)

mdiobus_register - bring up all the PHYs on a given bus and attach them to bus : target mii_bus

Description: Called by a bus driver to bring up all the PHYs on a given bus, and attach them to the bus.

Returns 0 on success or < 0 on error.

Definition at line 137 of file mdio_bus.c.

struct phy_device* mdiobus_scan ( struct mii_bus bus,
int  addr 
)
read

Definition at line 232 of file mdio_bus.c.

void mdiobus_unregister ( struct mii_bus bus)

Definition at line 191 of file mdio_bus.c.

int mdiobus_write ( struct mii_bus bus,
int  addr,
u32  regnum,
u16  val 
)

mdiobus_write - Convenience function for writing a given MII mgmt register : the mii_bus struct : the phy address : register number to write : value to write to

NOTE: MUST NOT be called from interrupt context, because the bus read/write functions may wait for an interrupt to conclude the operation.

Definition at line 286 of file mdio_bus.c.

struct phy_device* phy_attach ( struct net_device dev,
const char bus_id,
u32  flags,
phy_interface_t  interface 
)
read

Definition at line 585 of file phy_device.c.

struct phy_device* phy_connect ( struct net_device dev,
const char bus_id,
void(*)(struct net_device *)  handler,
u32  flags,
phy_interface_t  interface 
)
read

Definition at line 457 of file phy_device.c.

int phy_connect_direct ( struct net_device dev,
struct phy_device phydev,
void(*)(struct net_device *)  handler,
u32  flags,
phy_interface_t  interface 
)

Definition at line 422 of file phy_device.c.

void phy_detach ( struct phy_device phydev)

phy_detach - detach a PHY device from its network device : target phy_device struct

Definition at line 614 of file phy_device.c.

struct phy_device* phy_device_create ( struct mii_bus bus,
int  addr,
int  phy_id,
bool  is_c45,
struct phy_c45_device_ids c45_ids 
)
read

Definition at line 155 of file phy_device.c.

void phy_device_free ( struct phy_device phydev)

Definition at line 45 of file phy_device.c.

int phy_device_register ( struct phy_device phydev)

phy_device_register - Register the phy device on the MDIO bus : phy_device structure to be added to the MDIO bus

Definition at line 353 of file phy_device.c.

void phy_disconnect ( struct phy_device phydev)

phy_disconnect - disable interrupts, stop state machine, and detach a PHY device : target phy_device struct

Definition at line 486 of file phy_device.c.

int phy_driver_register ( struct phy_driver new_driver)

phy_driver_register - register a phy_driver with the PHY layer : new phy_driver to register

Definition at line 1058 of file phy_device.c.

void phy_driver_unregister ( struct phy_driver drv)

Definition at line 1098 of file phy_device.c.

int phy_drivers_register ( struct phy_driver new_driver,
int  n 
)

Definition at line 1082 of file phy_device.c.

void phy_drivers_unregister ( struct phy_driver drv,
int  n 
)

Definition at line 1104 of file phy_device.c.

int phy_ethtool_get_eee ( struct phy_device phydev,
struct ethtool_eee data 
)

phy_ethtool_get_eee - get EEE supported and status : target phy_device struct : ethtool_eee data

Description: it reportes the Supported/Advertisement/LP Advertisement capabilities.

Definition at line 1144 of file phy.c.

int phy_ethtool_gset ( struct phy_device phydev,
struct ethtool_cmd cmd 
)

Definition at line 287 of file phy.c.

int phy_ethtool_set_eee ( struct phy_device phydev,
struct ethtool_eee data 
)

phy_ethtool_set_eee - set EEE supported and status : target phy_device struct : ethtool_eee data

Description: it is to program the Advertisement EEE register.

Definition at line 1180 of file phy.c.

int phy_ethtool_sset ( struct phy_device phydev,
struct ethtool_cmd cmd 
)

phy_ethtool_sset - generic ethtool sset function, handles all the details : target phy_device struct : ethtool_cmd

A few notes about parameter checking:

  • We don't set port or transceiver, so we don't care what they were set to.
  • phy_start_aneg() will make sure forced settings are sane, and choose the next best ones from the ones selected, so we don't care if ethtool tries to give us bad values.

Definition at line 241 of file phy.c.

struct phy_device* phy_find_first ( struct mii_bus bus)
read

phy_find_first - finds the first PHY device on the bus : the target MII bus

Definition at line 384 of file phy_device.c.

int phy_get_eee_err ( struct phy_device phydev)

phy_get_eee_err - report the EEE wake error count : target phy_device struct

Description: it is to report the number of time where the PHY failed to complete its normal wake sequence.

Definition at line 1128 of file phy.c.

int phy_init_eee ( struct phy_device phydev,
bool  clk_stop_enable 
)

phy_init_eee - init and check the EEE feature : target phy_device struct : PHY may stop the clock during LPI

Description: it checks if the Energy-Efficient Ethernet (EEE) is supported by looking at the MMD registers 3.20 and 7.60/61 and it programs the MMD register 3.0 setting the "Clock stop enable" bit if required.

Definition at line 1048 of file phy.c.

int phy_init_hw ( struct phy_device phydev)

Definition at line 499 of file phy_device.c.

int phy_mii_ioctl ( struct phy_device phydev,
struct ifreq ifr,
int  cmd 
)

phy_mii_ioctl - generic PHY MII ioctl interface : the phy_device struct : &struct ifreq for socket ioctl's : ioctl cmd to execute

Note that this function is currently incompatible with the PHYCONTROL layer. It changes registers without regard to current state. Use at own risk.

Definition at line 314 of file phy.c.

void phy_print_status ( struct phy_device phydev)

phy_print_status - Convenience function to print out the current phy status : the phy_device struct

Definition at line 49 of file phy.c.

int phy_register_fixup ( const char bus_id,
u32  phy_uid,
u32  phy_uid_mask,
int(*)(struct phy_device *)  run 
)

Definition at line 75 of file phy_device.c.

int phy_register_fixup_for_id ( const char bus_id,
int(*)(struct phy_device *)  run 
)

Definition at line 106 of file phy_device.c.

int phy_register_fixup_for_uid ( u32  phy_uid,
u32  phy_uid_mask,
int(*)(struct phy_device *)  run 
)

Definition at line 98 of file phy_device.c.

int phy_scan_fixups ( struct phy_device phydev)

Definition at line 132 of file phy_device.c.

void phy_start ( struct phy_device phydev)

phy_start - start or restart a PHY device : target phy_device struct

Description: Indicates the attached device's readiness to handle PHY-related work. Used during startup to start the PHY, and after a call to phy_stop() to resume operation. Also used to indicate the MDIO bus has cleared an error condition.

Definition at line 743 of file phy.c.

int phy_start_aneg ( struct phy_device phydev)

phy_start_aneg - start auto-negotiation for this PHY device : the phy_device struct

Description: Sanitizes the settings (if we're not autonegotiating them), and then calls the driver's config_aneg function. If the PHYCONTROL Layer is operating, we change the state to reflect the beginning of Auto-negotiation or forcing.

Definition at line 391 of file phy.c.

int phy_start_interrupts ( struct phy_device phydev)

phy_start_interrupts - request and enable interrupts for a PHY device : target phy_device struct

Description: Request the interrupt for the given PHY. If this fails, then we set irq to PHY_POLL. Otherwise, we enable the interrupts in the PHY. This should only be called with a valid IRQ number. Returns 0 on success or < 0 on error.

Definition at line 591 of file phy.c.

void phy_start_machine ( struct phy_device phydev,
void(*)(struct net_device *)  handler 
)

phy_start_machine - start PHY state machine tracking : the phy_device struct : callback function for state change notifications

Description: The PHY infrastructure can run a state machine which tracks whether the PHY is starting up, negotiating, etc. This function starts the timer which tracks the state of the PHY. If you want to be notified when the state changes, pass in the callback , otherwise, pass NULL. If you want to maintain your own state machine, do not call this function.

Definition at line 437 of file phy.c.

void phy_state_machine ( struct work_struct work)

phy_state_machine - Handle the state machine : work_struct that describes the work to be done

Definition at line 768 of file phy.c.

void phy_stop ( struct phy_device phydev)

phy_stop - Bring down the PHY link, and stop checking the status : target phy_device struct

Definition at line 705 of file phy.c.

int phy_stop_interrupts ( struct phy_device phydev)

phy_stop_interrupts - disable interrupts from a PHY device : target phy_device struct

Definition at line 618 of file phy.c.

void phy_stop_machine ( struct phy_device phydev)

phy_stop_machine - stop the PHY state machine tracking : target phy_device struct

Description: Stops the state machine timer, sets the state to UP (unless it wasn't up yet). This function must be called BEFORE phy_detach.

Definition at line 453 of file phy.c.

Variable Documentation

struct bus_type mdio_bus_type

Definition at line 434 of file mdio_bus.c.