PebbleOS v4.47.0-1312-gf1984a001
Loading...
Searching...
No Matches
Ethernet PHY

Ethernet PHY class. More...

Modules

 Generic Ethernet PHY
 Ethernet PHY driven through the IEEE 802.3 clause 22 registers alone.
 

Data Structures

struct  pbl_net_phy_listener
 Ethernet PHY listener. More...
 
struct  pbl_net_phy_ops
 Ethernet PHY driver operations, called with the device lock held. More...
 
struct  pbl_net_phy
 Ethernet PHY. More...
 

Macros

#define PBL_NET_PHY_ADV_10_HALF   PBL_BIT(0)
 Advertise 10BASE-T half duplex.
 
#define PBL_NET_PHY_ADV_10_FULL   PBL_BIT(1)
 Advertise 10BASE-T full duplex.
 
#define PBL_NET_PHY_ADV_100_HALF   PBL_BIT(2)
 Advertise 100BASE-TX half duplex.
 
#define PBL_NET_PHY_ADV_100_FULL   PBL_BIT(3)
 Advertise 100BASE-TX full duplex.
 
#define PBL_NET_PHY_ADV_ALL
 Advertise every mode the PHY has.
 
#define PBL_NET_PHY_STATE_DEFINE(sym)
 Define the runtime state of an Ethernet PHY.
 
#define PBL_NET_PHY_INIT(sym, _name, _parent, _ops)
 Initialize a struct pbl_net_phy.
 

Enumerations

enum  pbl_net_phy_speed { PBL_NET_PHY_SPEED_10 , PBL_NET_PHY_SPEED_100 }
 Link speeds. More...
 

Functions

int pbl_net_phy_start (const struct pbl_net_phy *phy, uint32_t adv)
 Power a PHY up and start negotiating a link.
 
int pbl_net_phy_stop (const struct pbl_net_phy *phy)
 Stop a PHY and power it down.
 
void pbl_net_phy_get_link (const struct pbl_net_phy *phy, struct pbl_net_phy_link *link)
 Get the link state last reported to the listeners.
 
void pbl_net_phy_add_listener (const struct pbl_net_phy *phy, struct pbl_net_phy_listener *listener)
 Add a listener to a PHY.
 

Detailed Description

Ethernet PHY class.

The transceiver between an Ethernet MAC and the wire. The MAC takes it from its devicetree phy-handle, starts it with the link modes to advertise when its interface goes up and stops it, powered down, when it goes down.

While started, the class polls the link every second and reports it coming up or going down to the listeners, from thread context, with the speed and duplex it negotiated: the MAC configures itself to match. Listeners do not start or stop the PHY.

pbl_net_phy_add_listener(phy, &mac->listener);
...
ret = pbl_net_phy_stop(phy);
int pbl_net_phy_start(const struct pbl_net_phy *phy, uint32_t adv)
Power a PHY up and start negotiating a link.
int pbl_net_phy_stop(const struct pbl_net_phy *phy)
Stop a PHY and power it down.
#define PBL_NET_PHY_ADV_ALL
Advertise every mode the PHY has.
Definition phy.h:45
void pbl_net_phy_add_listener(const struct pbl_net_phy *phy, struct pbl_net_phy_listener *listener)
Add a listener to a PHY.

Data Structure Documentation

◆ pbl_net_phy_link

struct pbl_net_phy_link

Link state.

Data Fields
bool full_duplex Full duplex, else half.
enum pbl_net_phy_speed speed Speed.
bool up The link is up; the other fields only mean something then.

◆ pbl_net_phy

struct pbl_net_phy

Ethernet PHY.

Data Fields
struct pbl_device dev Device.
const struct pbl_net_phy_ops * ops Driver operations.
struct pbl_net_phy_state * state Runtime state.

Macro Definition Documentation

◆ PBL_NET_PHY_ADV_100_FULL

#define PBL_NET_PHY_ADV_100_FULL   PBL_BIT(3)

Advertise 100BASE-TX full duplex.

◆ PBL_NET_PHY_ADV_100_HALF

#define PBL_NET_PHY_ADV_100_HALF   PBL_BIT(2)

Advertise 100BASE-TX half duplex.

◆ PBL_NET_PHY_ADV_10_FULL

#define PBL_NET_PHY_ADV_10_FULL   PBL_BIT(1)

Advertise 10BASE-T full duplex.

◆ PBL_NET_PHY_ADV_10_HALF

#define PBL_NET_PHY_ADV_10_HALF   PBL_BIT(0)

Advertise 10BASE-T half duplex.

◆ PBL_NET_PHY_ADV_ALL

#define PBL_NET_PHY_ADV_ALL
Value:
#define PBL_NET_PHY_ADV_100_FULL
Advertise 100BASE-TX full duplex.
Definition phy.h:43
#define PBL_NET_PHY_ADV_10_FULL
Advertise 10BASE-T full duplex.
Definition phy.h:39
#define PBL_NET_PHY_ADV_100_HALF
Advertise 100BASE-TX half duplex.
Definition phy.h:41
#define PBL_NET_PHY_ADV_10_HALF
Advertise 10BASE-T half duplex.
Definition phy.h:37

Advertise every mode the PHY has.

◆ PBL_NET_PHY_INIT

#define PBL_NET_PHY_INIT (   sym,
  _name,
  _parent,
  _ops 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, pbl_net_phy_dev_init, _parent, &pbl_net_phy_class), \
.ops = (_ops), \
.state = &sym##_net_phy_state, \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153

Initialize a struct pbl_net_phy.

Parameters
symSymbol of the instance, as passed to PBL_NET_PHY_STATE_DEFINE().
_nameDevice name.
_parentParent device, the MDIO bus, or NULL.
_opsDriver operations.

◆ PBL_NET_PHY_STATE_DEFINE

#define PBL_NET_PHY_STATE_DEFINE (   sym)
Value:
static struct pbl_net_phy_state sym##_net_phy_state
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132

Define the runtime state of an Ethernet PHY.

Parameters
symSymbol of the instance.

Enumeration Type Documentation

◆ pbl_net_phy_speed

Link speeds.

Enumerator
PBL_NET_PHY_SPEED_10 

10 Mb/s.

PBL_NET_PHY_SPEED_100 

100 Mb/s.

Function Documentation

◆ pbl_net_phy_add_listener()

void pbl_net_phy_add_listener ( const struct pbl_net_phy *  phy,
struct pbl_net_phy_listener *  listener 
)

Add a listener to a PHY.

Parameters
phyEthernet PHY.
listenerListener, not added yet, which stays in use.

◆ pbl_net_phy_get_link()

void pbl_net_phy_get_link ( const struct pbl_net_phy *  phy,
struct pbl_net_phy_link *  link 
)

Get the link state last reported to the listeners.

Parameters
phyEthernet PHY.
[out]linkLink state, down while the PHY is stopped.

◆ pbl_net_phy_start()

int pbl_net_phy_start ( const struct pbl_net_phy *  phy,
uint32_t  adv 
)

Power a PHY up and start negotiating a link.

Parameters
phyEthernet PHY.
advModes to advertise, PBL_NET_PHY_ADV_* flags; those the PHY lacks are left out.
Returns
0, -EALREADY if started, -EINVAL if adv has no mode, or another negative errno.

◆ pbl_net_phy_stop()

int pbl_net_phy_stop ( const struct pbl_net_phy *  phy)

Stop a PHY and power it down.

A link that was up is reported down.

Parameters
phyEthernet PHY.
Returns
0, -EALREADY if stopped, or another negative errno.