iPXE
mii.h
Go to the documentation of this file.
1 #ifndef _IPXE_MII_H
2 #define _IPXE_MII_H
3 
4 /** @file
5  *
6  * Media Independent Interface
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <mii.h>
14 #include <ipxe/netdevice.h>
15 
16 struct mii_interface;
17 
18 /** MII interface operations */
20  /**
21  * Read from MII register
22  *
23  * @v mdio MII interface
24  * @v phy PHY address
25  * @v reg Register address
26  * @ret data Data read, or negative error
27  */
28  int ( * read ) ( struct mii_interface *mdio, unsigned int phy,
29  unsigned int reg );
30  /**
31  * Write to MII register
32  *
33  * @v mdio MII interface
34  * @v phy PHY address
35  * @v reg Register address
36  * @v data Data to write
37  * @ret rc Return status code
38  */
39  int ( * write ) ( struct mii_interface *mdio, unsigned int phy,
40  unsigned int reg, unsigned int data );
41 };
42 
43 /** An MII interface */
44 struct mii_interface {
45  /** Interface operations */
46  struct mii_operations *op;
47 };
48 
49 /** An MII device */
50 struct mii_device {
51  /** MII interface */
53  /** PHY address */
54  unsigned int address;
55 };
56 
57 /**
58  * Initialise MII interface
59  *
60  * @v mdio MII interface
61  * @v op MII interface operations
62  */
63 static inline __attribute__ (( always_inline )) void
64 mdio_init ( struct mii_interface *mdio, struct mii_operations *op ) {
65  mdio->op = op;
66 }
67 
68 /**
69  * Initialise MII device
70  *
71  * @v mii MII device
72  * @v mdio MII interface
73  * @v address PHY address
74  */
75 static inline __attribute__ (( always_inline )) void
76 mii_init ( struct mii_device *mii, struct mii_interface *mdio,
77  unsigned int address ) {
78  mii->mdio = mdio;
79  mii->address = address;
80 }
81 
82 /**
83  * Read from MII register
84  *
85  * @v mii MII device
86  * @v reg Register address
87  * @ret data Data read, or negative error
88  */
89 static inline __attribute__ (( always_inline )) int
90 mii_read ( struct mii_device *mii, unsigned int reg ) {
91  struct mii_interface *mdio = mii->mdio;
92 
93  return mdio->op->read ( mdio, mii->address, reg );
94 }
95 
96 /**
97  * Write to MII register
98  *
99  * @v mii MII device
100  * @v reg Register address
101  * @v data Data to write
102  * @ret rc Return status code
103  */
104 static inline __attribute__ (( always_inline )) int
105 mii_write ( struct mii_device *mii, unsigned int reg, unsigned int data ) {
106  struct mii_interface *mdio = mii->mdio;
107 
108  return mdio->op->write ( mdio, mii->address, reg, data );
109 }
110 
111 /**
112  * Dump MII registers (for debugging)
113  *
114  * @v mii MII device
115  */
116 static inline void
117 mii_dump ( struct mii_device *mii ) {
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 }
141 
142 /** Maximum time to wait for a reset, in milliseconds */
143 #define MII_RESET_MAX_WAIT_MS 500
144 
145 /** Maximum PHY address */
146 #define MII_MAX_PHY_ADDRESS 31
147 
148 extern int mii_restart ( struct mii_device *mii );
149 extern int mii_reset ( struct mii_device *mii );
150 extern int mii_check_link ( struct mii_device *mii,
151  struct net_device *netdev );
152 extern int mii_find ( struct mii_device *mii );
153 
154 #endif /* _IPXE_MII_H */
#define __attribute__(x)
Definition: compiler.h:10
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
uint64_t address
Base address.
Definition: ena.h:24
int mii_restart(struct mii_device *mii)
Restart autonegotiation.
Definition: mii.c:44
int(* read)(struct mii_interface *mdio, unsigned int phy, unsigned int reg)
Read from MII register.
Definition: mii.h:28
struct mii_interface * mdio
MII interface.
Definition: mii.h:52
#define DBGC(...)
Definition: compiler.h:505
int mii_check_link(struct mii_device *mii, struct net_device *netdev)
Update link status via MII.
Definition: mii.c:127
int mii_reset(struct mii_device *mii)
Reset MII device.
Definition: mii.c:75
static void mdio_init(struct mii_interface *mdio, struct mii_operations *op)
Initialise MII interface.
Definition: mii.h:64
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
An MII device.
Definition: mii.h:50
FILE_SECBOOT(PERMITTED)
static struct net_device * netdev
Definition: gdbudp.c:52
int mii_find(struct mii_device *mii)
Find PHY address.
Definition: mii.c:158
A network device.
Definition: netdevice.h:353
Media Independent Interface.
static void mii_dump(struct mii_device *mii)
Dump MII registers (for debugging)
Definition: mii.h:117
static void mii_init(struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
Initialise MII device.
Definition: mii.h:76
Network device management.
MII interface operations.
Definition: mii.h:19
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
An MII interface.
Definition: mii.h:44
uint8_t data[48]
Additional event data.
Definition: ena.h:22
unsigned int address
PHY address.
Definition: mii.h:54
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
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:105
int(* write)(struct mii_interface *mdio, unsigned int phy, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:39