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)
 
 FILE_SECBOOT (PERMITTED)
 
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 143 of file mii.h.

◆ MII_MAX_PHY_ADDRESS

#define MII_MAX_PHY_ADDRESS   31

Maximum PHY address.

Definition at line 146 of file mii.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 64 of file mii.h.

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

References mii_interface::op, and op.

Referenced by cgem_probe(), 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 76 of file mii.h.

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

References address, and mii.

Referenced by cgem_probe(), 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 90 of file mii.h.

90  {
91  struct mii_interface *mdio = mii->mdio;
92 
93  return mdio->op->read ( mdio, mii->address, reg );
94 }
static struct mii_phy mii
struct mii_operations * op
Interface operations.
Definition: mii.h:46
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:28
An MII interface.
Definition: mii.h:44

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 105 of file mii.h.

105  {
106  struct mii_interface *mdio = mii->mdio;
107 
108  return mdio->op->write ( mdio, mii->address, reg, data );
109 }
static struct mii_phy mii
struct mii_operations * op
Interface operations.
Definition: mii.h:46
static unsigned int unsigned int reg
Definition: myson.h:162
An MII interface.
Definition: mii.h:44
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:39

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 117 of file mii.h.

117  {
118  unsigned int i;
119  int data;
120 
121  /* Do nothing unless debug output is enabled */
122  if ( ! DBG_LOG )
123  return;
124 
125  /* Dump basic MII register set */
126  for ( i = 0 ; i < 16 ; i++ ) {
127  if ( ( i % 8 ) == 0 ) {
128  DBGC ( mii, "MII %p registers %02x-%02x:",
129  mii, i, ( i + 7 ) );
130  }
131  data = mii_read ( mii, i );
132  if ( data >= 0 ) {
133  DBGC ( mii, " %04x", data );
134  } else {
135  DBGC ( mii, " XXXX" );
136  }
137  if ( ( i % 8 ) == 7 )
138  DBGC ( mii, "\n" );
139  }
140 }
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:90
#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 44 of file mii.c.

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

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 75 of file mii.c.

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

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 cgem_init_phy(), 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 127 of file mii.c.

127  {
128  int bmsr;
129  int link;
130  int rc;
131 
132  /* Read BMSR */
133  bmsr = mii_read ( mii, MII_BMSR );
134  if ( bmsr < 0 ) {
135  rc = bmsr;
136  return rc;
137  }
138 
139  /* Report link status */
140  link = ( bmsr & BMSR_LSTATUS );
141  DBGC ( mii, "MII %p link %s (BMSR %#04x)\n",
142  mii, ( link ? "up" : "down" ), bmsr );
143  if ( link ) {
145  } else {
147  }
148 
149  return 0;
150 }
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:231
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:789
static struct net_device * netdev
Definition: gdbudp.c:53
u32 link
Link to next descriptor.
Definition: ar9003_mac.h:25
#define BMSR_LSTATUS
Definition: mii.h:58
static int mii_read(int phy_id, int location)
Definition: epic100.c:500
#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 cgem_check_link(), 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 158 of file mii.c.

158  {
159  unsigned int address;
160  int id;
161 
162  /* Try all possible PHY addresses */
163  for ( address = 0 ; address <= MII_MAX_PHY_ADDRESS ; address++ ) {
164  mii->address = address;
165  id = mii_read ( mii, MII_PHYSID1 );
166  if ( ( id > 0x0000 ) && ( id < 0xffff ) ) {
167  DBGC ( mii, "MII %p found PHY at address %d\n",
168  mii, address );
169  return 0;
170  }
171  }
172 
173  DBGC ( mii, "MII %p failed to find an address\n", mii );
174  return -ENOENT;
175 }
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:515
uint8_t id
Request identifier.
Definition: ena.h:12
#define MII_MAX_PHY_ADDRESS
Maximum PHY address.
Definition: mii.h:146
static int mii_read(int phy_id, int location)
Definition: epic100.c:500
#define MII_PHYSID1
Definition: atl1e.h:873

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

Referenced by cgem_init_phy(), icplus_init_phy(), and rdc_init_phy().