Deleted Added
full compact
e1000phy.c (95722) e1000phy.c (96026)
1/* $FreeBSD: head/sys/dev/mii/e1000phy.c 95722 2002-04-29 13:07:38Z phk $ */
1/* $FreeBSD: head/sys/dev/mii/e1000phy.c 96026 2002-05-04 11:00:30Z phk $ */
2/*
3 * Principal Author: Parag Patel
4 * Copyright (c) 2001
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

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

70static driver_t e1000phy_driver = {
71 "e1000phy", e1000phy_methods, sizeof (struct mii_softc)
72};
73DRIVER_MODULE(e1000phy, miibus, e1000phy_driver, e1000phy_devclass, 0, 0);
74
75static int e1000phy_service(struct mii_softc *, struct mii_data *, int);
76static void e1000phy_status(struct mii_softc *);
77static void e1000phy_reset(struct mii_softc *);
2/*
3 * Principal Author: Parag Patel
4 * Copyright (c) 2001
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:

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

70static driver_t e1000phy_driver = {
71 "e1000phy", e1000phy_methods, sizeof (struct mii_softc)
72};
73DRIVER_MODULE(e1000phy, miibus, e1000phy_driver, e1000phy_devclass, 0, 0);
74
75static int e1000phy_service(struct mii_softc *, struct mii_data *, int);
76static void e1000phy_status(struct mii_softc *);
77static void e1000phy_reset(struct mii_softc *);
78static int e1000phy_mii_phy_auto(struct mii_softc *, int);
78static int e1000phy_mii_phy_auto(struct mii_softc *);
79
79
80extern void mii_phy_auto_timeout(void *);
81
82static int e1000phy_debug = 0;
83
84static int
85e1000phy_probe(device_t dev)
86{
87 struct mii_attach_args *ma;
88 u_int32_t id;
89

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

227 * If the interface is not up, don't do anything.
228 */
229 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) {
230 break;
231 }
232
233 switch (IFM_SUBTYPE(ife->ifm_media)) {
234 case IFM_AUTO:
80static int e1000phy_debug = 0;
81
82static int
83e1000phy_probe(device_t dev)
84{
85 struct mii_attach_args *ma;
86 u_int32_t id;
87

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

225 * If the interface is not up, don't do anything.
226 */
227 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) {
228 break;
229 }
230
231 switch (IFM_SUBTYPE(ife->ifm_media)) {
232 case IFM_AUTO:
235 /*
236 * If we're already in auto mode, just return.
237 */
238 if (sc->mii_flags & MIIF_DOINGAUTO) {
239 return (0);
240 }
241 e1000phy_reset(sc);
233 e1000phy_reset(sc);
242 (void)e1000phy_mii_phy_auto(sc, 1);
234 (void)e1000phy_mii_phy_auto(sc);
243 break;
244
245 case IFM_1000_T:
235 break;
236
237 case IFM_1000_T:
246 if (sc->mii_flags & MIIF_DOINGAUTO)
247 return (0);
248
249 e1000phy_reset(sc);
250
251 /* TODO - any other way to force 1000BT? */
238 e1000phy_reset(sc);
239
240 /* TODO - any other way to force 1000BT? */
252 (void)e1000phy_mii_phy_auto(sc, 1);
241 (void)e1000phy_mii_phy_auto(sc);
253 break;
254
255 case IFM_100_TX:
256 e1000phy_reset(sc);
257
258 if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
259 PHY_WRITE(sc, E1000_CR,
260 E1000_CR_FULL_DUPLEX | E1000_CR_SPEED_100);

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

316 /*
317 * Only retry autonegotiation every 5 seconds.
318 */
319 if (++sc->mii_ticks != 5)
320 return (0);
321
322 sc->mii_ticks = 0;
323 e1000phy_reset(sc);
242 break;
243
244 case IFM_100_TX:
245 e1000phy_reset(sc);
246
247 if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
248 PHY_WRITE(sc, E1000_CR,
249 E1000_CR_FULL_DUPLEX | E1000_CR_SPEED_100);

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

305 /*
306 * Only retry autonegotiation every 5 seconds.
307 */
308 if (++sc->mii_ticks != 5)
309 return (0);
310
311 sc->mii_ticks = 0;
312 e1000phy_reset(sc);
324 if (e1000phy_mii_phy_auto(sc, 0) == EJUSTRETURN)
325 return (0);
326 break;
313 e1000phy_mii_phy_auto(sc);
314 return (0);
327 }
328
329 /* Update the media status. */
330 e1000phy_status(sc);
331
332 /* Callback if something changed. */
333 mii_phy_update(sc, cmd);
334 return (0);

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

352 lpar = PHY_READ(sc, E1000_LPAR);
353
354 if (bmsr & E1000_SR_LINK_STATUS)
355 mii->mii_media_status |= IFM_ACTIVE;
356
357 if (bmcr & E1000_CR_LOOPBACK)
358 mii->mii_media_active |= IFM_LOOP;
359
315 }
316
317 /* Update the media status. */
318 e1000phy_status(sc);
319
320 /* Callback if something changed. */
321 mii_phy_update(sc, cmd);
322 return (0);

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

340 lpar = PHY_READ(sc, E1000_LPAR);
341
342 if (bmsr & E1000_SR_LINK_STATUS)
343 mii->mii_media_status |= IFM_ACTIVE;
344
345 if (bmcr & E1000_CR_LOOPBACK)
346 mii->mii_media_active |= IFM_LOOP;
347
360 if ((sc->mii_flags & MIIF_DOINGAUTO) &&
361 (!(bmsr & E1000_SR_AUTO_NEG_COMPLETE) || !(ssr & E1000_SSR_LINK) ||
348 if ((!(bmsr & E1000_SR_AUTO_NEG_COMPLETE) || !(ssr & E1000_SSR_LINK) ||
362 !(ssr & E1000_SSR_SPD_DPLX_RESOLVED))) {
363 /* Erg, still trying, I guess... */
364 mii->mii_media_active |= IFM_NONE;
365 return;
366 }
367
368 if (ssr & E1000_SSR_1000MBS)
369 mii->mii_media_active |= IFM_1000_T;

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

385 mii->mii_media_active |= IFM_FLAG1;
386 } else if ((ar & E1000_AR_PAUSE) && (ar & E1000_AR_ASM_DIR) &&
387 !(lpar & E1000_LPAR_PAUSE) && (lpar & E1000_LPAR_ASM_DIR)) {
388 mii->mii_media_active |= IFM_FLAG0;
389 }
390}
391
392static int
349 !(ssr & E1000_SSR_SPD_DPLX_RESOLVED))) {
350 /* Erg, still trying, I guess... */
351 mii->mii_media_active |= IFM_NONE;
352 return;
353 }
354
355 if (ssr & E1000_SSR_1000MBS)
356 mii->mii_media_active |= IFM_1000_T;

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

372 mii->mii_media_active |= IFM_FLAG1;
373 } else if ((ar & E1000_AR_PAUSE) && (ar & E1000_AR_ASM_DIR) &&
374 !(lpar & E1000_LPAR_PAUSE) && (lpar & E1000_LPAR_ASM_DIR)) {
375 mii->mii_media_active |= IFM_FLAG0;
376 }
377}
378
379static int
393e1000phy_mii_phy_auto(struct mii_softc *mii, int waitfor)
380e1000phy_mii_phy_auto(struct mii_softc *mii)
394{
381{
395 int bmsr, i;
396
382
397 if ((mii->mii_flags & MIIF_DOINGAUTO) == 0) {
398 PHY_WRITE(mii, E1000_AR, E1000_AR_10T | E1000_AR_10T_FD |
399 E1000_AR_100TX | E1000_AR_100TX_FD |
400 E1000_AR_PAUSE | E1000_AR_ASM_DIR);
401 PHY_WRITE(mii, E1000_1GCR, E1000_1GCR_1000T_FD);
402 PHY_WRITE(mii, E1000_CR,
403 E1000_CR_AUTO_NEG_ENABLE | E1000_CR_RESTART_AUTO_NEG);
404 }
383 PHY_WRITE(mii, E1000_AR, E1000_AR_10T | E1000_AR_10T_FD |
384 E1000_AR_100TX | E1000_AR_100TX_FD |
385 E1000_AR_PAUSE | E1000_AR_ASM_DIR);
386 PHY_WRITE(mii, E1000_1GCR, E1000_1GCR_1000T_FD);
387 PHY_WRITE(mii, E1000_CR,
388 E1000_CR_AUTO_NEG_ENABLE | E1000_CR_RESTART_AUTO_NEG);
405
389
406 if (waitfor) {
407 /* Wait 500ms for it to complete. */
408 for (i = 0; i < 500; i++) {
409 bmsr =
410 PHY_READ(mii, E1000_SR) | PHY_READ(mii, E1000_SR);
411
412 if (bmsr & E1000_SR_AUTO_NEG_COMPLETE) {
413 return (0);
414 }
415 DELAY(1000);
416 }
417
418 /*
419 * Don't need to worry about clearing MIIF_DOINGAUTO.
420 * If that's set, a timeout is pending, and it will
421 * clear the flag. [do it anyway]
422 */
423 }
424
425 /*
426 * Just let it finish asynchronously. This is for the benefit of
427 * the tick handler driving autonegotiation. Don't want 500ms
428 * delays all the time while the system is running!
429 */
430 if ((mii->mii_flags & MIIF_DOINGAUTO) == 0) {
431 mii->mii_flags |= MIIF_DOINGAUTO;
432 mii->mii_ticks = 0;
433 mii->mii_auto_ch = timeout(mii_phy_auto_timeout, mii, hz >> 1);
434 }
435 return (EJUSTRETURN);
436}
390 return (EJUSTRETURN);
391}