Deleted Added
full compact
ip1000phy.c (213893) ip1000phy.c (215297)
1/*-
2 * Copyright (c) 2006, Pyun YongHyeon <yongari@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006, Pyun YongHyeon <yongari@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/dev/mii/ip1000phy.c 213893 2010-10-15 14:52:11Z marius $");
30__FBSDID("$FreeBSD: head/sys/dev/mii/ip1000phy.c 215297 2010-11-14 13:26:10Z marius $");
31
32/*
33 * Driver for the IC Plus IP1000A/IP1001 10/100/1000 PHY.
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>

--- 40 unchanged lines hidden (view full) ---

79 sizeof (struct mii_softc)
80};
81
82DRIVER_MODULE(ip1000phy, miibus, ip1000phy_driver, ip1000phy_devclass, 0, 0);
83
84static int ip1000phy_service(struct mii_softc *, struct mii_data *, int);
85static void ip1000phy_status(struct mii_softc *);
86static void ip1000phy_reset(struct mii_softc *);
31
32/*
33 * Driver for the IC Plus IP1000A/IP1001 10/100/1000 PHY.
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>

--- 40 unchanged lines hidden (view full) ---

79 sizeof (struct mii_softc)
80};
81
82DRIVER_MODULE(ip1000phy, miibus, ip1000phy_driver, ip1000phy_devclass, 0, 0);
83
84static int ip1000phy_service(struct mii_softc *, struct mii_data *, int);
85static void ip1000phy_status(struct mii_softc *);
86static void ip1000phy_reset(struct mii_softc *);
87static int ip1000phy_mii_phy_auto(struct mii_softc *);
87static int ip1000phy_mii_phy_auto(struct mii_softc *, int);
88
89static const struct mii_phydesc ip1000phys[] = {
90 MII_PHY_DESC(ICPLUS, IP1000A),
91 MII_PHY_DESC(ICPLUS, IP1001),
92 MII_PHY_END
93};
94
95static int

--- 19 unchanged lines hidden (view full) ---

115 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
116
117 sc->mii_flags = miibus_get_flags(dev);
118 sc->mii_inst = mii->mii_instance++;
119 sc->mii_phy = ma->mii_phyno;
120 sc->mii_service = ip1000phy_service;
121 sc->mii_pdata = mii;
122
88
89static const struct mii_phydesc ip1000phys[] = {
90 MII_PHY_DESC(ICPLUS, IP1000A),
91 MII_PHY_DESC(ICPLUS, IP1001),
92 MII_PHY_END
93};
94
95static int

--- 19 unchanged lines hidden (view full) ---

115 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
116
117 sc->mii_flags = miibus_get_flags(dev);
118 sc->mii_inst = mii->mii_instance++;
119 sc->mii_phy = ma->mii_phyno;
120 sc->mii_service = ip1000phy_service;
121 sc->mii_pdata = mii;
122
123 sc->mii_flags |= MIIF_NOISOLATE;
123 sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOMANPAUSE;
124
125 isc->model = MII_MODEL(ma->mii_id2);
126 isc->revision = MII_REV(ma->mii_id2);
127 if (isc->model == MII_MODEL_ICPLUS_IP1000A &&
128 strcmp(mii->mii_ifp->if_dname, "stge") == 0 &&
129 (sc->mii_flags & MIIF_MACPRIV0) != 0)
130 sc->mii_flags |= MIIF_PHYPRIV0;
131

--- 26 unchanged lines hidden (view full) ---

158 */
159 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) {
160 break;
161 }
162
163 ip1000phy_reset(sc);
164 switch (IFM_SUBTYPE(ife->ifm_media)) {
165 case IFM_AUTO:
124
125 isc->model = MII_MODEL(ma->mii_id2);
126 isc->revision = MII_REV(ma->mii_id2);
127 if (isc->model == MII_MODEL_ICPLUS_IP1000A &&
128 strcmp(mii->mii_ifp->if_dname, "stge") == 0 &&
129 (sc->mii_flags & MIIF_MACPRIV0) != 0)
130 sc->mii_flags |= MIIF_PHYPRIV0;
131

--- 26 unchanged lines hidden (view full) ---

158 */
159 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) {
160 break;
161 }
162
163 ip1000phy_reset(sc);
164 switch (IFM_SUBTYPE(ife->ifm_media)) {
165 case IFM_AUTO:
166 (void)ip1000phy_mii_phy_auto(sc);
166 (void)ip1000phy_mii_phy_auto(sc, ife->ifm_media);
167 goto done;
167 goto done;
168 break;
169
170 case IFM_1000_T:
171 /*
172 * XXX
173 * Manual 1000baseT setting doesn't seem to work.
174 */
175 speed = IP1000PHY_BMCR_1000;
176 break;

--- 17 unchanged lines hidden (view full) ---

194 gig = IP1000PHY_1000CR_1000T;
195
196 PHY_WRITE(sc, IP1000PHY_MII_1000CR, 0);
197 PHY_WRITE(sc, IP1000PHY_MII_BMCR, speed);
198
199 if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)
200 break;
201
168
169 case IFM_1000_T:
170 /*
171 * XXX
172 * Manual 1000baseT setting doesn't seem to work.
173 */
174 speed = IP1000PHY_BMCR_1000;
175 break;

--- 17 unchanged lines hidden (view full) ---

193 gig = IP1000PHY_1000CR_1000T;
194
195 PHY_WRITE(sc, IP1000PHY_MII_1000CR, 0);
196 PHY_WRITE(sc, IP1000PHY_MII_BMCR, speed);
197
198 if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)
199 break;
200
201 gig |= IP1000PHY_1000CR_MASTER | IP1000PHY_1000CR_MANUAL;
202 if ((ife->ifm_media & IFM_ETH_MASTER) != 0)
203 gig |= IP1000PHY_1000CR_MMASTER;
202 PHY_WRITE(sc, IP1000PHY_MII_1000CR, gig);
204 PHY_WRITE(sc, IP1000PHY_MII_1000CR, gig);
203 PHY_WRITE(sc, IP1000PHY_MII_BMCR, speed);
204
205
205 /*
206 * When setting the link manually, one side must
207 * be the master and the other the slave. However
208 * ifmedia doesn't give us a good way to specify
209 * this, so we fake it by using one of the LINK
210 * flags. If LINK0 is set, we program the PHY to
211 * be a master, otherwise it's a slave.
212 */
213 if ((mii->mii_ifp->if_flags & IFF_LINK0))
214 PHY_WRITE(sc, IP1000PHY_MII_1000CR, gig |
215 IP1000PHY_1000CR_MASTER |
216 IP1000PHY_1000CR_MMASTER |
217 IP1000PHY_1000CR_MANUAL);
218 else
219 PHY_WRITE(sc, IP1000PHY_MII_1000CR, gig |
220 IP1000PHY_1000CR_MASTER |
221 IP1000PHY_1000CR_MANUAL);
222
223done:
224 break;
225
226 case MII_TICK:
227 /*
228 * Is the interface even up?
229 */
230 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)

--- 22 unchanged lines hidden (view full) ---

253
254 /*
255 * Only retry autonegotiation every mii_anegticks seconds.
256 */
257 if (sc->mii_ticks <= sc->mii_anegticks)
258 break;
259
260 sc->mii_ticks = 0;
206done:
207 break;
208
209 case MII_TICK:
210 /*
211 * Is the interface even up?
212 */
213 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)

--- 22 unchanged lines hidden (view full) ---

236
237 /*
238 * Only retry autonegotiation every mii_anegticks seconds.
239 */
240 if (sc->mii_ticks <= sc->mii_anegticks)
241 break;
242
243 sc->mii_ticks = 0;
261 ip1000phy_mii_phy_auto(sc);
244 ip1000phy_mii_phy_auto(sc, ife->ifm_media);
262 break;
263 }
264
265 /* Update the media status. */
266 ip1000phy_status(sc);
267
268 /* Callback if something changed. */
269 mii_phy_update(sc, cmd);
270 return (0);
271}
272
273static void
274ip1000phy_status(struct mii_softc *sc)
275{
276 struct ip1000phy_softc *isc;
277 struct mii_data *mii = sc->mii_pdata;
278 uint32_t bmsr, bmcr, stat;
245 break;
246 }
247
248 /* Update the media status. */
249 ip1000phy_status(sc);
250
251 /* Callback if something changed. */
252 mii_phy_update(sc, cmd);
253 return (0);
254}
255
256static void
257ip1000phy_status(struct mii_softc *sc)
258{
259 struct ip1000phy_softc *isc;
260 struct mii_data *mii = sc->mii_pdata;
261 uint32_t bmsr, bmcr, stat;
279 uint32_t ar, lpar;
280
281 isc = (struct ip1000phy_softc *)sc;
282
283 mii->mii_media_status = IFM_AVALID;
284 mii->mii_media_active = IFM_ETHER;
285
286 bmsr = PHY_READ(sc, IP1000PHY_MII_BMSR) |
287 PHY_READ(sc, IP1000PHY_MII_BMSR);

--- 52 unchanged lines hidden (view full) ---

340 return;
341 }
342 if ((stat & PC_PhyDuplexStatus) != 0)
343 mii->mii_media_active |= IFM_FDX;
344 else
345 mii->mii_media_active |= IFM_HDX;
346 }
347
262
263 isc = (struct ip1000phy_softc *)sc;
264
265 mii->mii_media_status = IFM_AVALID;
266 mii->mii_media_active = IFM_ETHER;
267
268 bmsr = PHY_READ(sc, IP1000PHY_MII_BMSR) |
269 PHY_READ(sc, IP1000PHY_MII_BMSR);

--- 52 unchanged lines hidden (view full) ---

322 return;
323 }
324 if ((stat & PC_PhyDuplexStatus) != 0)
325 mii->mii_media_active |= IFM_FDX;
326 else
327 mii->mii_media_active |= IFM_HDX;
328 }
329
348 ar = PHY_READ(sc, IP1000PHY_MII_ANAR);
349 lpar = PHY_READ(sc, IP1000PHY_MII_ANLPAR);
330 if ((mii->mii_media_active & IFM_FDX) != 0)
331 mii->mii_media_active |= mii_phy_flowstatus(sc);
350
332
351 /*
352 * FLAG0 : Rx flow-control
353 * FLAG1 : Tx flow-control
354 */
355 if ((ar & IP1000PHY_ANAR_PAUSE) && (lpar & IP1000PHY_ANLPAR_PAUSE))
356 mii->mii_media_active |= IFM_FLAG0 | IFM_FLAG1;
357 else if (!(ar & IP1000PHY_ANAR_PAUSE) && (ar & IP1000PHY_ANAR_APAUSE) &&
358 (lpar & IP1000PHY_ANLPAR_PAUSE) && (lpar & IP1000PHY_ANLPAR_APAUSE))
359 mii->mii_media_active |= IFM_FLAG1;
360 else if ((ar & IP1000PHY_ANAR_PAUSE) && (ar & IP1000PHY_ANAR_APAUSE) &&
361 !(lpar & IP1000PHY_ANLPAR_PAUSE) &&
362 (lpar & IP1000PHY_ANLPAR_APAUSE)) {
363 mii->mii_media_active |= IFM_FLAG0;
364 }
365
366 /*
367 * FLAG2 : local PHY resolved to MASTER
368 */
369 if ((mii->mii_media_active & IFM_1000_T) != 0) {
370 stat = PHY_READ(sc, IP1000PHY_MII_1000SR);
371 if ((stat & IP1000PHY_1000SR_MASTER) != 0)
333 if ((mii->mii_media_active & IFM_1000_T) != 0) {
334 stat = PHY_READ(sc, IP1000PHY_MII_1000SR);
335 if ((stat & IP1000PHY_1000SR_MASTER) != 0)
372 mii->mii_media_active |= IFM_FLAG2;
336 mii->mii_media_active |= IFM_ETH_MASTER;
373 }
374}
375
376static int
337 }
338}
339
340static int
377ip1000phy_mii_phy_auto(struct mii_softc *sc)
341ip1000phy_mii_phy_auto(struct mii_softc *sc, int media)
378{
379 struct ip1000phy_softc *isc;
380 uint32_t reg;
381
382 isc = (struct ip1000phy_softc *)sc;
383 reg = 0;
384 if (isc->model == MII_MODEL_ICPLUS_IP1001) {
385 reg = PHY_READ(sc, IP1000PHY_MII_ANAR);
386 reg |= IP1000PHY_ANAR_NP;
387 }
388 reg |= IP1000PHY_ANAR_10T | IP1000PHY_ANAR_10T_FDX |
342{
343 struct ip1000phy_softc *isc;
344 uint32_t reg;
345
346 isc = (struct ip1000phy_softc *)sc;
347 reg = 0;
348 if (isc->model == MII_MODEL_ICPLUS_IP1001) {
349 reg = PHY_READ(sc, IP1000PHY_MII_ANAR);
350 reg |= IP1000PHY_ANAR_NP;
351 }
352 reg |= IP1000PHY_ANAR_10T | IP1000PHY_ANAR_10T_FDX |
389 IP1000PHY_ANAR_100TX | IP1000PHY_ANAR_100TX_FDX |
390 IP1000PHY_ANAR_PAUSE | IP1000PHY_ANAR_APAUSE;
353 IP1000PHY_ANAR_100TX | IP1000PHY_ANAR_100TX_FDX;
354 if ((media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0)
355 reg |= IP1000PHY_ANAR_PAUSE | IP1000PHY_ANAR_APAUSE;
391 PHY_WRITE(sc, IP1000PHY_MII_ANAR, reg | IP1000PHY_ANAR_CSMA);
392
393 reg = IP1000PHY_1000CR_1000T | IP1000PHY_1000CR_1000T_FDX;
394 reg |= IP1000PHY_1000CR_MASTER;
395 PHY_WRITE(sc, IP1000PHY_MII_1000CR, reg);
396 PHY_WRITE(sc, IP1000PHY_MII_BMCR, (IP1000PHY_BMCR_FDX |
397 IP1000PHY_BMCR_AUTOEN | IP1000PHY_BMCR_STARTNEG));
398

--- 33 unchanged lines hidden ---
356 PHY_WRITE(sc, IP1000PHY_MII_ANAR, reg | IP1000PHY_ANAR_CSMA);
357
358 reg = IP1000PHY_1000CR_1000T | IP1000PHY_1000CR_1000T_FDX;
359 reg |= IP1000PHY_1000CR_MASTER;
360 PHY_WRITE(sc, IP1000PHY_MII_1000CR, reg);
361 PHY_WRITE(sc, IP1000PHY_MII_BMCR, (IP1000PHY_BMCR_FDX |
362 IP1000PHY_BMCR_AUTOEN | IP1000PHY_BMCR_STARTNEG));
363

--- 33 unchanged lines hidden ---