This source file includes following definitions.
- lxtphymatch
- lxtphyattach
- lxtphy_service
- lxtphy_status
- lxtphy_reset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/kernel.h>
78 #include <sys/device.h>
79 #include <sys/socket.h>
80 #include <sys/errno.h>
81
82 #include <net/if.h>
83 #include <net/if_media.h>
84
85 #include <dev/mii/mii.h>
86 #include <dev/mii/miivar.h>
87 #include <dev/mii/miidevs.h>
88
89 #include <dev/mii/lxtphyreg.h>
90
91 int lxtphymatch(struct device *, void *, void *);
92 void lxtphyattach(struct device *, struct device *, void *);
93
94 struct cfattach lxtphy_ca = {
95 sizeof(struct mii_softc), lxtphymatch, lxtphyattach, mii_phy_detach,
96 mii_phy_activate
97 };
98
99 struct cfdriver lxtphy_cd = {
100 NULL, "lxtphy", DV_DULL
101 };
102
103 int lxtphy_service(struct mii_softc *, struct mii_data *, int);
104 void lxtphy_status(struct mii_softc *);
105 void lxtphy_reset(struct mii_softc *);
106
107 const struct mii_phy_funcs lxtphy_funcs = {
108 lxtphy_service, lxtphy_status, lxtphy_reset,
109 };
110
111 const struct mii_phy_funcs lxtphy971_funcs = {
112 lxtphy_service, ukphy_status, lxtphy_reset,
113 };
114
115 static const struct mii_phydesc lxtphys[] = {
116 { MII_OUI_xxLEVEL1, MII_MODEL_xxLEVEL1_LXT970,
117 MII_STR_xxLEVEL1_LXT970 },
118 { MII_OUI_xxLEVEL1a, MII_MODEL_xxLEVEL1a_LXT971,
119 MII_STR_xxLEVEL1a_LXT971 },
120
121 { 0, 0,
122 NULL },
123 };
124
125 int
126 lxtphymatch(parent, match, aux)
127 struct device *parent;
128 void *match;
129 void *aux;
130 {
131 struct mii_attach_args *ma = aux;
132
133 if (mii_phy_match(ma, lxtphys) != NULL)
134 return (10);
135
136 return (0);
137 }
138
139 void
140 lxtphyattach(parent, self, aux)
141 struct device *parent, *self;
142 void *aux;
143 {
144 struct mii_softc *sc = (struct mii_softc *)self;
145 struct mii_attach_args *ma = aux;
146 struct mii_data *mii = ma->mii_data;
147 const struct mii_phydesc *mpd;
148
149 if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_xxLEVEL1 &&
150 MII_MODEL(ma->mii_id2) == MII_MODEL_xxLEVEL1_LXT970) {
151 sc->mii_funcs = &lxtphy_funcs;
152 }
153 if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_xxLEVEL1a &&
154 MII_MODEL(ma->mii_id2) == MII_MODEL_xxLEVEL1a_LXT971) {
155 sc->mii_funcs = &lxtphy971_funcs;
156 }
157
158 mpd = mii_phy_match(ma, lxtphys);
159 printf(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
160
161 sc->mii_inst = mii->mii_instance;
162 sc->mii_phy = ma->mii_phyno;
163 sc->mii_pdata = mii;
164 sc->mii_flags = ma->mii_flags;
165
166 PHY_RESET(sc);
167
168 sc->mii_capabilities =
169 PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
170 if (sc->mii_capabilities & BMSR_MEDIAMASK)
171 mii_phy_add_media(sc);
172 }
173
174 int
175 lxtphy_service(sc, mii, cmd)
176 struct mii_softc *sc;
177 struct mii_data *mii;
178 int cmd;
179 {
180 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
181 int reg;
182
183 if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0)
184 return (ENXIO);
185
186 switch (cmd) {
187 case MII_POLLSTAT:
188
189
190
191 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
192 return (0);
193 break;
194
195 case MII_MEDIACHG:
196
197
198
199
200 if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
201 reg = PHY_READ(sc, MII_BMCR);
202 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
203 return (0);
204 }
205
206
207
208
209 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
210 break;
211
212 mii_phy_setmedia(sc);
213 break;
214
215 case MII_TICK:
216
217
218
219 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
220 return (0);
221
222 if (mii_phy_tick(sc) == EJUSTRETURN)
223 return (0);
224 break;
225
226 case MII_DOWN:
227 mii_phy_down(sc);
228 return (0);
229 }
230
231
232 mii_phy_status(sc);
233
234
235 mii_phy_update(sc, cmd);
236 return (0);
237 }
238
239 void
240 lxtphy_status(sc)
241 struct mii_softc *sc;
242 {
243 struct mii_data *mii = sc->mii_pdata;
244 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
245 int bmcr, bmsr, csr;
246
247 mii->mii_media_status = IFM_AVALID;
248 mii->mii_media_active = IFM_ETHER;
249
250
251
252
253
254
255 csr = PHY_READ(sc, MII_LXTPHY_CSR);
256 if (csr & CSR_LINK)
257 mii->mii_media_status |= IFM_ACTIVE;
258
259 bmcr = PHY_READ(sc, MII_BMCR);
260 if (bmcr & BMCR_ISO) {
261 mii->mii_media_active |= IFM_NONE;
262 mii->mii_media_status = 0;
263 return;
264 }
265
266 if (bmcr & BMCR_LOOP)
267 mii->mii_media_active |= IFM_LOOP;
268
269 if (bmcr & BMCR_AUTOEN) {
270 bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
271 if ((bmsr & BMSR_ACOMP) == 0) {
272
273 mii->mii_media_active |= IFM_NONE;
274 return;
275 }
276 if (csr & CSR_SPEED)
277 mii->mii_media_active |= IFM_100_TX;
278 else
279 mii->mii_media_active |= IFM_10_T;
280
281 if (csr & CSR_DUPLEX)
282 mii->mii_media_active |= IFM_FDX;
283 else
284 mii->mii_media_active |= IFM_HDX;
285 } else
286 mii->mii_media_active = ife->ifm_media;
287 }
288
289 void
290 lxtphy_reset(sc)
291 struct mii_softc *sc;
292 {
293 mii_phy_reset(sc);
294 PHY_WRITE(sc, MII_LXTPHY_IER,
295 PHY_READ(sc, MII_LXTPHY_IER) & ~IER_INTEN);
296 }