iPXE
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)
 FILE_SECBOOT (PERMITTED)
int mii_restart (struct mii_device *mii)
 Restart autonegotiation.
int mii_reset (struct mii_device *mii)
 Reset MII device.
int mii_check_link (struct mii_device *mii, struct net_device *netdev)
 Update link status via MII.
int mii_find (struct mii_device *mii)
 Find PHY address.

Detailed Description

Media Independent Interface.

Definition in file mii.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ 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:3
#define MII_BMCR
Definition atl1e.h:871
static int mii_read(int phy_id, int location)
Definition epic100.c:500
#define DBGC(...)
Definition compiler.h:505
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition mii.h:105
#define BMCR_ANRESTART
Definition mii.h:47
#define BMCR_ANENABLE
Definition mii.h:50
static struct mii_phy mii
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79

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}
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670
#define MII_RESET_MAX_WAIT_MS
Maximum time to wait for a reset, in milliseconds.
Definition mii.h:143
int mii_restart(struct mii_device *mii)
Restart autonegotiation.
Definition mii.c:44
#define BMCR_RESET
Definition mii.h:53
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79

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}
u32 link
Link to next descriptor.
Definition ar9003_mac.h:1
#define MII_BMSR
Definition atl1e.h:872
static struct net_device * netdev
Definition gdbudp.c:53
#define BMSR_LSTATUS
Definition mii.h:58
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

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}
#define MII_PHYSID1
Definition atl1e.h:873
uint8_t id
Request identifier.
Definition ena.h:1
uint64_t address
Base address.
Definition ena.h:13
#define ENOENT
No such file or directory.
Definition errno.h:515
#define MII_MAX_PHY_ADDRESS
Maximum PHY address.
Definition mii.h:146

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().