6 * Media Independent Interface
10 FILE_LICENCE ( GPL2_OR_LATER );
13 #include <ipxe/netdevice.h>
17 /** MII interface operations */
18 struct mii_operations {
20 * Read from MII register
22 * @v mii MII interface
23 * @v reg Register address
24 * @ret data Data read, or negative error
26 int ( * read ) ( struct mii_interface *mii, unsigned int reg );
28 * Write to MII register
30 * @v mii MII interface
31 * @v reg Register address
32 * @v data Data to write
33 * @ret rc Return status code
35 int ( * write ) ( struct mii_interface *mii, unsigned int reg,
39 /** An MII interface */
40 struct mii_interface {
41 /** Interface operations */
42 struct mii_operations *op;
46 * Initialise MII interface
48 * @v mii MII interface
49 * @v op MII interface operations
51 static inline __attribute__ (( always_inline )) void
52 mii_init ( struct mii_interface *mii, struct mii_operations *op ) {
57 * Read from MII register
59 * @v mii MII interface
60 * @v reg Register address
61 * @ret data Data read, or negative error
63 static inline __attribute__ (( always_inline )) int
64 mii_read ( struct mii_interface *mii, unsigned int reg ) {
65 return mii->op->read ( mii, reg );
69 * Write to MII register
71 * @v mii MII interface
72 * @v reg Register address
73 * @v data Data to write
74 * @ret rc Return status code
76 static inline __attribute__ (( always_inline )) int
77 mii_write ( struct mii_interface *mii, unsigned int reg, unsigned int data ) {
78 return mii->op->write ( mii, reg, data );
82 * Dump MII registers (for debugging)
84 * @v mii MII interface
87 mii_dump ( struct mii_interface *mii ) {
91 /* Do nothing unless debug output is enabled */
95 /* Dump basic MII register set */
96 for ( i = 0 ; i < 16 ; i++ ) {
97 if ( ( i % 8 ) == 0 ) {
98 DBGC ( mii, "MII %p registers %02x-%02x:",
101 data = mii_read ( mii, i );
103 DBGC ( mii, " %04x", data );
105 DBGC ( mii, " XXXX" );
107 if ( ( i % 8 ) == 7 )
112 /** Maximum time to wait for a reset, in milliseconds */
113 #define MII_RESET_MAX_WAIT_MS 500
115 extern int mii_restart ( struct mii_interface *mii );
116 extern int mii_reset ( struct mii_interface *mii );
118 #endif /* _IPXE_MII_H */