This source file includes following definitions.
- gentbimatch
- gentbiattach
- gentbi_service
- gentbi_status
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
76
77 #if 0
78 #include <sys/cdefs.h>
79 __KERNEL_RCSID(0, "$NetBSD: gentbi.c,v 1.12 2004/04/11 15:40:56 thorpej Exp $");
80 #endif
81
82 #include <sys/param.h>
83 #include <sys/systm.h>
84 #include <sys/kernel.h>
85 #include <sys/device.h>
86 #include <sys/socket.h>
87 #include <sys/errno.h>
88
89 #include <net/if.h>
90 #include <net/if_media.h>
91
92 #include <dev/mii/mii.h>
93 #include <dev/mii/miivar.h>
94 #include <dev/mii/miidevs.h>
95
96 int gentbimatch(struct device *, void *, void *);
97 void gentbiattach(struct device *, struct device *, void *);
98
99 struct cfattach gentbi_ca = {
100 sizeof(struct mii_softc), gentbimatch, gentbiattach,
101 mii_phy_detach, mii_phy_activate
102 };
103
104 struct cfdriver gentbi_cd = {
105 NULL, "gentbi", DV_DULL
106 };
107
108 int gentbi_service(struct mii_softc *, struct mii_data *, int);
109 void gentbi_status(struct mii_softc *);
110
111 const struct mii_phy_funcs gentbi_funcs = {
112 gentbi_service, gentbi_status, mii_phy_reset,
113 };
114
115 int
116 gentbimatch(struct device *parent, void *match, void *aux)
117 {
118 struct mii_attach_args *ma = aux;
119 struct mii_data *mii = ma->mii_data;
120 int bmsr, extsr;
121
122
123
124
125
126
127
128 bmsr = (*mii->mii_readreg)(parent, ma->mii_phyno, MII_BMSR);
129 if ((bmsr & BMSR_EXTSTAT) == 0 || (bmsr & BMSR_MEDIAMASK) != 0)
130 return (0);
131
132 extsr = (*mii->mii_readreg)(parent, ma->mii_phyno, MII_EXTSR);
133 if (extsr & (EXTSR_1000TFDX|EXTSR_1000THDX))
134 return (0);
135
136 if (extsr & (EXTSR_1000XFDX|EXTSR_1000XHDX)) {
137
138
139
140
141
142 return (2);
143 }
144
145 return (0);
146 }
147
148 void
149 gentbiattach(struct device *parent, struct device *self, void *aux)
150 {
151 struct mii_softc *sc = (struct mii_softc *)self;
152 struct mii_attach_args *ma = aux;
153 struct mii_data *mii = ma->mii_data;
154
155 printf(": Generic ten-bit interface, rev. %d\n",
156 MII_REV(ma->mii_id2));
157
158 sc->mii_inst = mii->mii_instance;
159 sc->mii_phy = ma->mii_phyno;
160 sc->mii_funcs = &gentbi_funcs;
161 sc->mii_pdata = mii;
162 sc->mii_flags = ma->mii_flags;
163 sc->mii_anegticks = MII_ANEGTICKS;
164
165 PHY_RESET(sc);
166
167
168
169
170
171 sc->mii_capabilities =
172 PHY_READ(sc, MII_BMSR) & ma->mii_capmask & ~BMSR_MEDIAMASK;
173 if (sc->mii_capabilities & BMSR_EXTSTAT)
174 sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
175
176 if ((sc->mii_capabilities & BMSR_MEDIAMASK) ||
177 (sc->mii_extcapabilities & EXTSR_MEDIAMASK))
178 mii_phy_add_media(sc);
179 }
180
181 int
182 gentbi_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
183 {
184 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
185 int reg;
186
187 switch (cmd) {
188 case MII_POLLSTAT:
189
190
191
192 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
193 return (0);
194 break;
195
196 case MII_MEDIACHG:
197
198
199
200
201 if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
202 reg = PHY_READ(sc, MII_BMCR);
203 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
204 return (0);
205 }
206
207
208
209
210 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
211 break;
212
213 mii_phy_setmedia(sc);
214 break;
215
216 case MII_TICK:
217
218
219
220 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
221 return (0);
222
223 if (mii_phy_tick(sc) == EJUSTRETURN)
224 return (0);
225 break;
226
227 case MII_DOWN:
228 mii_phy_down(sc);
229 return (0);
230 }
231
232
233 mii_phy_status(sc);
234
235
236 mii_phy_update(sc, cmd);
237 return (0);
238 }
239
240 void
241 gentbi_status(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 bmsr, bmcr, anlpar;
246
247 mii->mii_media_status = IFM_AVALID;
248 mii->mii_media_active = IFM_ETHER;
249
250 bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
251
252 if (bmsr & BMSR_LINK)
253 mii->mii_media_status |= IFM_ACTIVE;
254
255 bmcr = PHY_READ(sc, MII_BMCR);
256 if (bmcr & BMCR_ISO) {
257 mii->mii_media_active |= IFM_NONE;
258 mii->mii_media_status = 0;
259 return;
260 }
261
262 if (bmcr & BMCR_LOOP)
263 mii->mii_media_active |= IFM_LOOP;
264
265 if (bmcr & BMCR_AUTOEN) {
266
267
268
269
270 if ((bmsr & BMSR_ACOMP) == 0) {
271
272 mii->mii_media_active |= IFM_NONE;
273 return;
274 }
275
276
277
278
279
280 mii->mii_media_active |= IFM_1000_SX;
281
282 anlpar = PHY_READ(sc, MII_ANLPAR);
283 if ((sc->mii_extcapabilities & EXTSR_1000XFDX) != 0 &&
284 (anlpar & ANLPAR_X_FD) != 0)
285 mii->mii_media_active |=
286 IFM_FDX;
287 } else
288 mii->mii_media_active = ife->ifm_media;
289 }