iPXE
Data Structures | Macros | Functions
mii.h File Reference

Media Independent Interface. More...

#include <mii.h>
#include <ipxe/netdevice.h>

Go to the source code of this file.

Data Structures

struct  mii_operations
 MII interface operations. More...
 
struct  mii_interface
 An MII interface. More...
 
struct  mii_device
 An MII device. More...
 

Macros

#define MII_RESET_MAX_WAIT_MS   500
 Maximum time to wait for a reset, in milliseconds. More...
 
#define MII_MAX_PHY_ADDRESS   31
 Maximum PHY address. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void mdio_init (struct mii_interface *mdio, struct mii_operations *op)
 Initialise MII interface. More...
 
static void mii_init (struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
 Initialise MII device. More...
 
static int mii_read (struct mii_device *mii, unsigned int reg)
 Read from MII register. More...
 
static int mii_write (struct mii_device *mii, unsigned int reg, unsigned int data)
 Write to MII register. More...
 
static void mii_dump (struct mii_device *mii)
 Dump MII registers (for debugging) More...
 
int mii_restart (struct mii_device *mii)
 Restart autonegotiation. More...
 
int mii_reset (struct mii_device *mii)
 Reset MII device. More...
 
int mii_check_link (struct mii_device *mii, struct net_device *netdev)
 Update link status via MII. More...
 
int mii_find (struct mii_device *mii)
 Find PHY address. More...
 

Detailed Description

Media Independent Interface.

Definition in file mii.h.

Macro Definition Documentation

◆ MII_RESET_MAX_WAIT_MS

#define MII_RESET_MAX_WAIT_MS   500

Maximum time to wait for a reset, in milliseconds.

Definition at line 142 of file mii.h.

◆ MII_MAX_PHY_ADDRESS

#define MII_MAX_PHY_ADDRESS   31

Maximum PHY address.

Definition at line 145 of file mii.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ mdio_init()

static void mdio_init ( struct mii_interface mdio,
struct mii_operations op 
)
inlinestatic

Initialise MII interface.

Parameters
mdioMII interface
opMII interface operations

Definition at line 63 of file mii.h.

63  {
64  mdio->op = op;
65 }
struct mii_operations * op
Interface operations.
Definition: mii.h:45
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327

References mii_interface::op, and op.

Referenced by init_mii_bit_basher(), rdc_probe(), realtek_probe(), rhine_probe(), and velocity_probe().

◆ mii_init()

static void mii_init ( struct mii_device mii,
struct mii_interface mdio,
unsigned int  address 
)
inlinestatic

Initialise MII device.

Parameters
miiMII device
mdioMII interface
addressPHY address

Definition at line 75 of file mii.h.

76  {
77  mii->mdio = mdio;
78  mii->address = address;
79 }
static struct mii_phy mii
uint64_t address
Base address.
Definition: ena.h:24

References address, and mii.

Referenced by icplus_probe(), rdc_probe(), realtek_probe(), rhine_probe(), and velocity_probe().

◆ mii_read()

static int mii_read ( struct mii_device mii,
unsigned int  reg 
)
inlinestatic

Read from MII register.

Parameters
miiMII device
regRegister address
Return values
dataData read, or negative error

Definition at line 89 of file mii.h.

89  {
90  struct mii_interface *mdio = mii->mdio;
91 
92  return mdio->op->read ( mdio, mii->address, reg );
93 }
static struct mii_phy mii
struct mii_operations * op
Interface operations.
Definition: mii.h:45
static unsigned int unsigned int reg
Definition: myson.h:162
int(* read)(struct mii_interface *mdio, unsigned int phy, unsigned int reg)
Read from MII register.
Definition: mii.h:27
An MII interface.
Definition: mii.h:43

References mii, mii_interface::op, mii_operations::read, and reg.

Referenced by mii_dump().

◆ mii_write()

static int mii_write ( struct mii_device mii,
unsigned int  reg,
unsigned int  data 
)
inlinestatic

Write to MII register.

Parameters
miiMII device
regRegister address
dataData to write
Return values
rcReturn status code

Definition at line 104 of file mii.h.

104  {
105  struct mii_interface *mdio = mii->mdio;
106 
107  return mdio->op->write ( mdio, mii->address, reg, data );
108 }
static struct mii_phy mii
struct mii_operations * op
Interface operations.
Definition: mii.h:45
static unsigned int unsigned int reg
Definition: myson.h:162
An MII interface.
Definition: mii.h:43
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int(* write)(struct mii_interface *mdio, unsigned int phy, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:38

References data, mii, mii_interface::op, reg, and mii_operations::write.

Referenced by icplus_init_phy(), mii_reset(), mii_restart(), realtek_phy_reset(), realtek_phy_speed(), smscusb_mii_check_link(), smscusb_mii_open(), and velocity_set_link().

◆ mii_dump()

static void mii_dump ( struct mii_device mii)
inlinestatic

Dump MII registers (for debugging)

Parameters
miiMII device

Definition at line 116 of file mii.h.

116  {
117  unsigned int i;
118  int data;
119 
120  /* Do nothing unless debug output is enabled */
121  if ( ! DBG_LOG )
122  return;
123 
124  /* Dump basic MII register set */
125  for ( i = 0 ; i < 16 ; i++ ) {
126  if ( ( i % 8 ) == 0 ) {
127  DBGC ( mii, "MII %p registers %02x-%02x:",
128  mii, i, ( i + 7 ) );
129  }
130  data = mii_read ( mii, i );
131  if ( data >= 0 ) {
132  DBGC ( mii, " %04x", data );
133  } else {
134  DBGC ( mii, " XXXX" );
135  }
136  if ( ( i % 8 ) == 7 )
137  DBGC ( mii, "\n" );
138  }
139 }
static struct mii_phy mii
#define DBGC(...)
Definition: compiler.h:505
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static int mii_read(struct mii_device *mii, unsigned int reg)
Read from MII register.
Definition: mii.h:89
#define DBG_LOG
Definition: compiler.h:317

References data, DBG_LOG, DBGC, mii, and mii_read().

Referenced by realtek_check_link().

◆ mii_restart()

int mii_restart ( struct mii_device mii)

Restart autonegotiation.

Parameters
miiMII device
Return values
rcReturn status code

Definition at line 43 of file mii.c.

43  {
44  int bmcr;
45  int rc;
46 
47  /* Read BMCR */
48  bmcr = mii_read ( mii, MII_BMCR );
49  if ( bmcr < 0 ) {
50  rc = bmcr;
51  DBGC ( mii, "MII %p could not read BMCR: %s\n",
52  mii, strerror ( rc ) );
53  return rc;
54  }
55 
56  /* Enable and restart autonegotiation */
57  bmcr |= ( BMCR_ANENABLE | BMCR_ANRESTART );
58  if ( ( rc = mii_write ( mii, MII_BMCR, bmcr ) ) != 0 ) {
59  DBGC ( mii, "MII %p could not write BMCR: %s\n",
60  mii, strerror ( rc ) );
61  return rc;
62  }
63 
64  DBGC ( mii, "MII %p restarted autonegotiation\n", mii );
65  return 0;
66 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct mii_phy mii
#define DBGC(...)
Definition: compiler.h:505
#define BMCR_ANRESTART
Definition: mii.h:46
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define MII_BMCR
Definition: atl1e.h:871
static int mii_read(int phy_id, int location)
Definition: epic100.c:499
#define BMCR_ANENABLE
Definition: mii.h:49
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:104

References BMCR_ANENABLE, BMCR_ANRESTART, DBGC, mii, MII_BMCR, mii_read(), mii_write(), rc, and strerror().

Referenced by mii_reset(), and realtek_phy_reset().

◆ mii_reset()

int mii_reset ( struct mii_device mii)

Reset MII device.

Parameters
miiMII device
Return values
rcReturn status code

Definition at line 74 of file mii.c.

74  {
75  unsigned int i;
76  int bmcr;
77  int rc;
78 
79  /* Power-up, enable autonegotiation and initiate reset */
80  if ( ( rc = mii_write ( mii, MII_BMCR,
81  ( BMCR_RESET | BMCR_ANENABLE ) ) ) != 0 ) {
82  DBGC ( mii, "MII %p could not write BMCR: %s\n",
83  mii, strerror ( rc ) );
84  return rc;
85  }
86 
87  /* Wait for reset to complete */
88  for ( i = 0 ; i < MII_RESET_MAX_WAIT_MS ; i++ ) {
89 
90  /* Check if reset has completed */
91  bmcr = mii_read ( mii, MII_BMCR );
92  if ( bmcr < 0 ) {
93  rc = bmcr;
94  DBGC ( mii, "MII %p could not read BMCR: %s\n",
95  mii, strerror ( rc ) );
96  return rc;
97  }
98 
99  /* If reset is not complete, delay 1ms and retry */
100  if ( bmcr & BMCR_RESET ) {
101  mdelay ( 1 );
102  continue;
103  }
104 
105  /* Force autonegotation on again, in case it was
106  * cleared by the reset.
107  */
108  if ( ( rc = mii_restart ( mii ) ) != 0 )
109  return rc;
110 
111  DBGC ( mii, "MII %p reset after %dms\n", mii, i );
112  return 0;
113  }
114 
115  DBGC ( mii, "MII %p timed out waiting for reset\n", mii );
116  return -ETIMEDOUT;
117 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct mii_phy mii
#define DBGC(...)
Definition: compiler.h:505
int mii_restart(struct mii_device *mii)
Restart autonegotiation.
Definition: mii.c:43
#define MII_RESET_MAX_WAIT_MS
Maximum time to wait for a reset, in milliseconds.
Definition: mii.h:142
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define MII_BMCR
Definition: atl1e.h:871
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define BMCR_RESET
Definition: mii.h:52
static int mii_read(int phy_id, int location)
Definition: epic100.c:499
#define BMCR_ANENABLE
Definition: mii.h:49
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:104
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669

References BMCR_ANENABLE, BMCR_RESET, DBGC, ETIMEDOUT, mdelay(), mii, MII_BMCR, mii_read(), MII_RESET_MAX_WAIT_MS, mii_restart(), mii_write(), rc, and strerror().

Referenced by icplus_init_phy(), rdc_init_phy(), realtek_phy_reset(), rhine_probe(), and velocity_probe().

◆ mii_check_link()

int mii_check_link ( struct mii_device mii,
struct net_device netdev 
)

Update link status via MII.

Parameters
miiMII device
netdevNetwork device
Return values
rcReturn status code

Definition at line 126 of file mii.c.

126  {
127  int bmsr;
128  int link;
129  int rc;
130 
131  /* Read BMSR */
132  bmsr = mii_read ( mii, MII_BMSR );
133  if ( bmsr < 0 ) {
134  rc = bmsr;
135  return rc;
136  }
137 
138  /* Report link status */
139  link = ( bmsr & BMSR_LSTATUS );
140  DBGC ( mii, "MII %p link %s (BMSR %#04x)\n",
141  mii, ( link ? "up" : "down" ), bmsr );
142  if ( link ) {
144  } else {
146  }
147 
148  return 0;
149 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct mii_phy mii
#define DBGC(...)
Definition: compiler.h:505
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:774
static struct net_device * netdev
Definition: gdbudp.c:52
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:68
#define BMSR_LSTATUS
Definition: mii.h:57
static int mii_read(int phy_id, int location)
Definition: epic100.c:499
#define MII_BMSR
Definition: atl1e.h:872

References BMSR_LSTATUS, DBGC, link, mii, MII_BMSR, mii_read(), netdev, netdev_link_down(), netdev_link_up(), and rc.

Referenced by rdc_check_link(), and smscusb_mii_check_link().

◆ mii_find()

int mii_find ( struct mii_device mii)

Find PHY address.

Parameters
miiMII device
Return values
rcReturn status code

Definition at line 157 of file mii.c.

157  {
158  unsigned int address;
159  int id;
160 
161  /* Try all possible PHY addresses */
162  for ( address = 0 ; address <= MII_MAX_PHY_ADDRESS ; address++ ) {
163  mii->address = address;
164  id = mii_read ( mii, MII_PHYSID1 );
165  if ( ( id > 0x0000 ) && ( id < 0xffff ) ) {
166  DBGC ( mii, "MII %p found PHY at address %d\n",
167  mii, address );
168  return 0;
169  }
170  }
171 
172  DBGC ( mii, "MII %p failed to find an address\n", mii );
173  return -ENOENT;
174 }
static struct mii_phy mii
uint64_t address
Base address.
Definition: ena.h:24
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
uint8_t id
Request identifier.
Definition: ena.h:12
#define MII_MAX_PHY_ADDRESS
Maximum PHY address.
Definition: mii.h:145
static int mii_read(int phy_id, int location)
Definition: epic100.c:499
#define MII_PHYSID1
Definition: atl1e.h:873

References address, DBGC, ENOENT, id, mii, MII_MAX_PHY_ADDRESS, MII_PHYSID1, and mii_read().

Referenced by icplus_init_phy(), and rdc_init_phy().