This source file includes following definitions.
- acphymatch
- acphyattach
- acphy_service
- acphy_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 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/device.h>
47 #include <sys/socket.h>
48 #include <sys/errno.h>
49
50 #include <net/if.h>
51 #include <net/if_media.h>
52
53 #include <dev/mii/mii.h>
54 #include <dev/mii/miivar.h>
55 #include <dev/mii/miidevs.h>
56
57 #include <dev/mii/acphyreg.h>
58
59 int acphymatch(struct device *, void *, void *);
60 void acphyattach(struct device *, struct device *, void *);
61
62 struct cfattach acphy_ca = {
63 sizeof(struct mii_softc), acphymatch, acphyattach, mii_phy_detach,
64 mii_phy_activate
65 };
66
67 struct cfdriver acphy_cd = {
68 NULL, "acphy", DV_DULL
69 };
70
71 int acphy_service(struct mii_softc *, struct mii_data *, int);
72 void acphy_status(struct mii_softc *);
73
74 const struct mii_phy_funcs acphy_funcs = {
75 acphy_service, acphy_status, mii_phy_reset,
76 };
77
78 static const struct mii_phydesc acphys[] = {
79 { MII_OUI_xxALTIMA, MII_MODEL_xxALTIMA_AC101,
80 MII_STR_xxALTIMA_AC101 },
81 { MII_OUI_xxALTIMA, MII_MODEL_xxALTIMA_AC101L,
82 MII_STR_xxALTIMA_AC101L },
83 { MII_OUI_xxALTIMA, MII_MODEL_xxALTIMA_AC_UNKNOWN,
84 MII_STR_xxALTIMA_AC_UNKNOWN },
85
86 { 0, 0,
87 NULL },
88 };
89
90 int
91 acphymatch(struct device *parent, void *match, void *aux)
92 {
93 struct mii_attach_args *ma = aux;
94
95 if (mii_phy_match(ma, acphys) != NULL)
96 return (10);
97
98 return (0);
99 }
100
101 void
102 acphyattach(struct device *parent, struct device *self, void *aux)
103 {
104 struct mii_softc *sc = (struct mii_softc *)self;
105 struct mii_attach_args *ma = aux;
106 struct mii_data *mii = ma->mii_data;
107 const struct mii_phydesc *mpd;
108
109 mpd = mii_phy_match(ma, acphys);
110 printf(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
111
112 sc->mii_inst = mii->mii_instance;
113 sc->mii_phy = ma->mii_phyno;
114 sc->mii_funcs = &acphy_funcs;
115 sc->mii_pdata = mii;
116 sc->mii_flags = ma->mii_flags;
117 sc->mii_anegticks = MII_ANEGTICKS;
118
119 PHY_RESET(sc);
120
121
122
123
124
125 sc->mii_capabilities =
126 PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
127
128 #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
129 if (sc->mii_flags & MIIF_HAVEFIBER) {
130 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst),
131 MII_MEDIA_100_TX);
132 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, IFM_FDX, sc->mii_inst),
133 MII_MEDIA_100_TX);
134 }
135 #undef ADD
136
137 if (sc->mii_capabilities & BMSR_MEDIAMASK)
138 mii_phy_add_media(sc);
139 }
140
141 int
142 acphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
143 {
144 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
145 int reg;
146
147 switch (cmd) {
148 case MII_POLLSTAT:
149
150
151
152 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
153 return (0);
154 break;
155
156 case MII_MEDIACHG:
157
158
159
160
161 if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
162 reg = PHY_READ(sc, MII_BMCR);
163 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
164 return (0);
165 }
166
167
168
169
170 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
171 break;
172
173 mii_phy_setmedia(sc);
174 break;
175
176 case MII_TICK:
177
178
179
180 if (IFM_INST(ife->ifm_media) != sc->mii_inst)
181 return (0);
182
183 if (mii_phy_tick(sc) == EJUSTRETURN)
184 return (0);
185 break;
186
187 case MII_DOWN:
188 mii_phy_down(sc);
189 return (0);
190 }
191
192
193 mii_phy_status(sc);
194
195
196 mii_phy_update(sc, cmd);
197 return (0);
198 }
199
200 void
201 acphy_status(struct mii_softc *sc)
202 {
203 struct mii_data *mii = sc->mii_pdata;
204 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
205 int bmsr, bmcr, dr;
206
207 mii->mii_media_status = IFM_AVALID;
208 mii->mii_media_active = IFM_ETHER;
209
210 bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
211 dr = PHY_READ(sc, MII_ACPHY_DR);
212
213 if (bmsr & BMSR_LINK)
214 mii->mii_media_status |= IFM_ACTIVE;
215
216 bmcr = PHY_READ(sc, MII_BMCR);
217 if (bmcr & BMCR_ISO) {
218 mii->mii_media_active |= IFM_NONE;
219 mii->mii_media_status = 0;
220 return;
221 }
222
223 if (bmcr & BMCR_LOOP)
224 mii->mii_media_active |= IFM_LOOP;
225
226 if (bmcr & BMCR_AUTOEN) {
227
228
229
230
231 if ((bmsr & BMSR_ACOMP) == 0) {
232
233 mii->mii_media_active |= IFM_NONE;
234 return;
235 }
236
237 if (dr & DR_SPEED)
238 mii->mii_media_active |= IFM_100_TX;
239 else
240 mii->mii_media_active |= IFM_10_T;
241
242 if (dr & DR_DPLX)
243 mii->mii_media_active |= IFM_FDX;
244 else
245 mii->mii_media_active |= IFM_HDX;
246 } else
247 mii->mii_media_active = ife->ifm_media;
248 }