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 
12 #include <mii.h>
13 #include <ipxe/netdevice.h>
14 
15 struct mii_interface;
16 
17 /** MII interface operations */
19  /**
20  * Read from MII register
21  *
22  * @v mdio MII interface
23  * @v phy PHY address
24  * @v reg Register address
25  * @ret data Data read, or negative error
26  */
27  int ( * read ) ( struct mii_interface *mdio, unsigned int phy,
28  unsigned int reg );
29  /**
30  * Write to MII register
31  *
32  * @v mdio MII interface
33  * @v phy PHY address
34  * @v reg Register address
35  * @v data Data to write
36  * @ret rc Return status code
37  */
38  int ( * write ) ( struct mii_interface *mdio, unsigned int phy,
39  unsigned int reg, unsigned int data );
40 };
41 
42 /** An MII interface */
43 struct mii_interface {
44  /** Interface operations */
45  struct mii_operations *op;
46 };
47 
48 /** An MII device */
49 struct mii_device {
50  /** MII interface */
52  /** PHY address */
53  unsigned int address;
54 };
55 
56 /**
57  * Initialise MII interface
58  *
59  * @v mdio MII interface
60  * @v op MII interface operations
61  */
62 static inline __attribute__ (( always_inline )) void
63 mdio_init ( struct mii_interface *mdio, struct mii_operations *op ) {
64  mdio->op = op;
65 }
66 
67 /**
68  * Initialise MII device
69  *
70  * @v mii MII device
71  * @v mdio MII interface
72  * @v address PHY address
73  */
74 static inline __attribute__ (( always_inline )) void
75 mii_init ( struct mii_device *mii, struct mii_interface *mdio,
76  unsigned int address ) {
77  mii->mdio = mdio;
78  mii->address = address;
79 }
80 
81 /**
82  * Read from MII register
83  *
84  * @v mii MII device
85  * @v reg Register address
86  * @ret data Data read, or negative error
87  */
88 static inline __attribute__ (( always_inline )) int
89 mii_read ( struct mii_device *mii, unsigned int reg ) {
90  struct mii_interface *mdio = mii->mdio;
91 
92  return mdio->op->read ( mdio, mii->address, reg );
93 }
94 
95 /**
96  * Write to MII register
97  *
98  * @v mii MII device
99  * @v reg Register address
100  * @v data Data to write
101  * @ret rc Return status code
102  */
103 static inline __attribute__ (( always_inline )) int
104 mii_write ( struct mii_device *mii, unsigned int reg, unsigned int data ) {
105  struct mii_interface *mdio = mii->mdio;
106 
107  return mdio->op->write ( mdio, mii->address, reg, data );
108 }
109 
110 /**
111  * Dump MII registers (for debugging)
112  *
113  * @v mii MII device
114  */
115 static inline void
116 mii_dump ( struct mii_device *mii ) {
117  unsigned int i;
118  int data;
119 
120  /* Do nothing unless debug output is enabled */
121  if ( ! DBG_LOG )
122  return;
123 
124  /* Dump basic MII register set */
125  for ( i = 0 ; i < 16 ; i++ ) {
126  if ( ( i % 8 ) == 0 ) {
127  DBGC ( mii, "MII %p registers %02x-%02x:",
128  mii, i, ( i + 7 ) );
129  }
130  data = mii_read ( mii, i );
131  if ( data >= 0 ) {
132  DBGC ( mii, " %04x", data );
133  } else {
134  DBGC ( mii, " XXXX" );
135  }
136  if ( ( i % 8 ) == 7 )
137  DBGC ( mii, "\n" );
138  }
139 }
140 
141 /** Maximum time to wait for a reset, in milliseconds */
142 #define MII_RESET_MAX_WAIT_MS 500
143 
144 /** Maximum PHY address */
145 #define MII_MAX_PHY_ADDRESS 31
146 
147 extern int mii_restart ( struct mii_device *mii );
148 extern int mii_reset ( struct mii_device *mii );
149 extern int mii_check_link ( struct mii_device *mii,
150  struct net_device *netdev );
151 extern int mii_find ( struct mii_device *mii );
152 
153 #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:45
uint64_t address
Base address.
Definition: ena.h:24
int mii_restart(struct mii_device *mii)
Restart autonegotiation.
Definition: mii.c:43
int(* read)(struct mii_interface *mdio, unsigned int phy, unsigned int reg)
Read from MII register.
Definition: mii.h:27
struct mii_interface * mdio
MII interface.
Definition: mii.h:51
#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:126
int mii_reset(struct mii_device *mii)
Reset MII device.
Definition: mii.c:74
static void mdio_init(struct mii_interface *mdio, struct mii_operations *op)
Initialise MII interface.
Definition: mii.h:63
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
An MII device.
Definition: mii.h:49
static struct net_device * netdev
Definition: gdbudp.c:52
static unsigned int unsigned int reg
Definition: intel.h:245
int mii_find(struct mii_device *mii)
Find PHY address.
Definition: mii.c:157
A network device.
Definition: netdevice.h:348
Media Independent Interface.
static void mii_dump(struct mii_device *mii)
Dump MII registers (for debugging)
Definition: mii.h:116
static void mii_init(struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
Initialise MII device.
Definition: mii.h:75
Network device management.
MII interface operations.
Definition: mii.h:18
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
An MII interface.
Definition: mii.h:43
unsigned int address
PHY address.
Definition: mii.h:53
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
static int mii_read(struct mii_device *mii, unsigned int reg)
Read from MII register.
Definition: mii.h:89
#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:104
int(* write)(struct mii_interface *mdio, unsigned int phy, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:38