iPXE
Functions
mii.c File Reference

Media Independent Interface. More...

#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <ipxe/mii.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
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.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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:44
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:47
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:50
static int mii_read(int phy_id, int location)
Definition: epic100.c:499
#define BMCR_ANENABLE
Definition: mii.h:47
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(), 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:186
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
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:55
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 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().