Fri Oct 11 09:29:04 2019 UTC ()
- Indicat master mode if the negotiated result say so.
- KNF


(msaitoh)
diff -r1.34 -r1.35 src/sys/dev/mii/ciphy.c
diff -r1.56 -r1.57 src/sys/dev/mii/rgephy.c

cvs diff -r1.34 -r1.35 src/sys/dev/mii/ciphy.c (expand / switch to unified diff)

--- src/sys/dev/mii/ciphy.c 2019/04/11 09:14:07 1.34
+++ src/sys/dev/mii/ciphy.c 2019/10/11 09:29:04 1.35
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ciphy.c,v 1.34 2019/04/11 09:14:07 msaitoh Exp $ */ 1/* $NetBSD: ciphy.c,v 1.35 2019/10/11 09:29:04 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2004 4 * Copyright (c) 2004
5 * Bill Paul <wpaul@windriver.com>. All rights reserved. 5 * Bill Paul <wpaul@windriver.com>. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE. 32 * THE POSSIBILITY OF SUCH DAMAGE.
33 * 33 *
34 * FreeBSD: src/sys/dev/mii/ciphy.c,v 1.2 2005/01/06 01:42:55 imp Exp 34 * FreeBSD: src/sys/dev/mii/ciphy.c,v 1.2 2005/01/06 01:42:55 imp Exp
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: ciphy.c,v 1.34 2019/04/11 09:14:07 msaitoh Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: ciphy.c,v 1.35 2019/10/11 09:29:04 msaitoh Exp $");
39 39
40/* 40/*
41 * Driver for the Cicada CS8201 10/100/1000 copper PHY. 41 * Driver for the Cicada CS8201 10/100/1000 copper PHY.
42 */ 42 */
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/device.h> 46#include <sys/device.h>
47#include <sys/kernel.h> 47#include <sys/kernel.h>
48#include <sys/socket.h> 48#include <sys/socket.h>
49#include <sys/bus.h> 49#include <sys/bus.h>
50 50
51#include <net/if.h> 51#include <net/if.h>
@@ -287,27 +287,27 @@ setit: @@ -287,27 +287,27 @@ setit:
287 if (sc->mii_media_active != mii->mii_media_active || 287 if (sc->mii_media_active != mii->mii_media_active ||
288 sc->mii_media_status != mii->mii_media_status || 288 sc->mii_media_status != mii->mii_media_status ||
289 cmd == MII_MEDIACHG) { 289 cmd == MII_MEDIACHG) {
290 ciphy_fixup(sc); 290 ciphy_fixup(sc);
291 } 291 }
292 mii_phy_update(sc, cmd); 292 mii_phy_update(sc, cmd);
293 return 0; 293 return 0;
294} 294}
295 295
296static void 296static void
297ciphy_status(struct mii_softc *sc) 297ciphy_status(struct mii_softc *sc)
298{ 298{
299 struct mii_data *mii = sc->mii_pdata; 299 struct mii_data *mii = sc->mii_pdata;
300 uint16_t bmsr, bmcr; 300 uint16_t bmsr, bmcr, gtsr;
301 301
302 mii->mii_media_status = IFM_AVALID; 302 mii->mii_media_status = IFM_AVALID;
303 mii->mii_media_active = IFM_ETHER; 303 mii->mii_media_active = IFM_ETHER;
304 304
305 PHY_READ(sc, MII_BMSR, &bmsr); 305 PHY_READ(sc, MII_BMSR, &bmsr);
306 PHY_READ(sc, MII_BMSR, &bmsr); 306 PHY_READ(sc, MII_BMSR, &bmsr);
307 307
308 if (bmsr & BMSR_LINK) 308 if (bmsr & BMSR_LINK)
309 mii->mii_media_status |= IFM_ACTIVE; 309 mii->mii_media_status |= IFM_ACTIVE;
310 310
311 PHY_READ(sc, MII_BMCR, &bmcr); 311 PHY_READ(sc, MII_BMCR, &bmcr);
312 312
313 if (bmcr & BMCR_LOOP) 313 if (bmcr & BMCR_LOOP)
@@ -333,36 +333,39 @@ ciphy_status(struct mii_softc *sc) @@ -333,36 +333,39 @@ ciphy_status(struct mii_softc *sc)
333 mii->mii_media_active |= IFM_1000_T; 333 mii->mii_media_active |= IFM_1000_T;
334 break; 334 break;
335 default: 335 default:
336 aprint_error_dev(sc->mii_dev, "unknown PHY speed %x\n", 336 aprint_error_dev(sc->mii_dev, "unknown PHY speed %x\n",
337 bmsr & CIPHY_AUXCSR_SPEED); 337 bmsr & CIPHY_AUXCSR_SPEED);
338 break; 338 break;
339 } 339 }
340 340
341 if (bmsr & CIPHY_AUXCSR_FDX) 341 if (bmsr & CIPHY_AUXCSR_FDX)
342 mii->mii_media_active |= IFM_FDX; 342 mii->mii_media_active |= IFM_FDX;
343 else 343 else
344 mii->mii_media_active |= IFM_HDX; 344 mii->mii_media_active |= IFM_HDX;
345 345
346 return; 346 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T) {
 347 PHY_READ(sc, MII_GTSR, &gtsr);
 348 if ((gtsr & GTSR_MS_RES) != 0)
 349 mii->mii_media_active |= IFM_ETH_MASTER;
 350 }
347} 351}
348 352
349static void 353static void
350ciphy_reset(struct mii_softc *sc) 354ciphy_reset(struct mii_softc *sc)
351{ 355{
 356
352 mii_phy_reset(sc); 357 mii_phy_reset(sc);
353 DELAY(1000); 358 DELAY(1000);
354 
355 return; 
356} 359}
357 360
358static inline int 361static inline int
359PHY_SETBIT(struct mii_softc *sc, int y, uint16_t z) 362PHY_SETBIT(struct mii_softc *sc, int y, uint16_t z)
360{ 363{
361 uint16_t _tmp; 364 uint16_t _tmp;
362 int rv; 365 int rv;
363 366
364 if ((rv = PHY_READ(sc, y, &_tmp)) != 0) 367 if ((rv = PHY_READ(sc, y, &_tmp)) != 0)
365 return rv; 368 return rv;
366 return PHY_WRITE(sc, y, _tmp | z); 369 return PHY_WRITE(sc, y, _tmp | z);
367} 370}
368 371
@@ -427,16 +430,14 @@ ciphy_fixup(struct mii_softc *sc) @@ -427,16 +430,14 @@ ciphy_fixup(struct mii_softc *sc)
427 else 430 else
428 PHY_CLRBIT(sc, CIPHY_MII_10BTCSR, CIPHY_10BTCSR_ECHO); 431 PHY_CLRBIT(sc, CIPHY_MII_10BTCSR, CIPHY_10BTCSR_ECHO);
429 432
430 break; 433 break;
431 case MII_MODEL_CICADA_VSC8211: 434 case MII_MODEL_CICADA_VSC8211:
432 case MII_MODEL_CICADA_CS8244: 435 case MII_MODEL_CICADA_CS8244:
433 case MII_MODEL_VITESSE_VSC8601: 436 case MII_MODEL_VITESSE_VSC8601:
434 break; 437 break;
435 default: 438 default:
436 aprint_error_dev(sc->mii_dev, "unknown CICADA PHY model %x\n", 439 aprint_error_dev(sc->mii_dev, "unknown CICADA PHY model %x\n",
437 model); 440 model);
438 break; 441 break;
439 } 442 }
440 
441 return; 
442} 443}

cvs diff -r1.56 -r1.57 src/sys/dev/mii/rgephy.c (expand / switch to unified diff)

--- src/sys/dev/mii/rgephy.c 2019/10/11 03:40:01 1.56
+++ src/sys/dev/mii/rgephy.c 2019/10/11 09:29:04 1.57
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rgephy.c,v 1.56 2019/10/11 03:40:01 msaitoh Exp $ */ 1/* $NetBSD: rgephy.c,v 1.57 2019/10/11 09:29:04 msaitoh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2003 4 * Copyright (c) 2003
5 * Bill Paul <wpaul@windriver.com>. All rights reserved. 5 * Bill Paul <wpaul@windriver.com>. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE. 32 * THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: rgephy.c,v 1.56 2019/10/11 03:40:01 msaitoh Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: rgephy.c,v 1.57 2019/10/11 09:29:04 msaitoh Exp $");
37 37
38 38
39/* 39/*
40 * Driver for the RealTek 8169S/8110S internal 10/100/1000 PHY. 40 * Driver for the RealTek 8169S/8110S internal 10/100/1000 PHY.
41 */ 41 */
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/device.h> 46#include <sys/device.h>
47#include <sys/socket.h> 47#include <sys/socket.h>
48 48
49 49
@@ -346,27 +346,27 @@ rgephy_linkup(struct mii_softc *sc) @@ -346,27 +346,27 @@ rgephy_linkup(struct mii_softc *sc)
346 } else { 346 } else {
347 PHY_READ(sc, RTK_GMEDIASTAT, &reg); 347 PHY_READ(sc, RTK_GMEDIASTAT, &reg);
348 if ((reg & RTK_GMEDIASTAT_LINK) != 0) 348 if ((reg & RTK_GMEDIASTAT_LINK) != 0)
349 linkup = true; 349 linkup = true;
350 } 350 }
351 351
352 return linkup; 352 return linkup;
353} 353}
354 354
355static void 355static void
356rgephy_status(struct mii_softc *sc) 356rgephy_status(struct mii_softc *sc)
357{ 357{
358 struct mii_data *mii = sc->mii_pdata; 358 struct mii_data *mii = sc->mii_pdata;
359 uint16_t gstat, bmsr, bmcr, physr, ssr; 359 uint16_t gstat, bmsr, bmcr, gtsr, physr, ssr;
360 360
361 mii->mii_media_status = IFM_AVALID; 361 mii->mii_media_status = IFM_AVALID;
362 mii->mii_media_active = IFM_ETHER; 362 mii->mii_media_active = IFM_ETHER;
363 363
364 if (rgephy_linkup(sc)) 364 if (rgephy_linkup(sc))
365 mii->mii_media_status |= IFM_ACTIVE; 365 mii->mii_media_status |= IFM_ACTIVE;
366 366
367 PHY_READ(sc, MII_BMSR, &bmsr); 367 PHY_READ(sc, MII_BMSR, &bmsr);
368 PHY_READ(sc, MII_BMCR, &bmcr); 368 PHY_READ(sc, MII_BMCR, &bmcr);
369 369
370 if ((bmcr & BMCR_ISO) != 0) { 370 if ((bmcr & BMCR_ISO) != 0) {
371 mii->mii_media_active |= IFM_NONE; 371 mii->mii_media_active |= IFM_NONE;
372 mii->mii_media_status = 0; 372 mii->mii_media_status = 0;
@@ -432,26 +432,32 @@ rgephy_status(struct mii_softc *sc) @@ -432,26 +432,32 @@ rgephy_status(struct mii_softc *sc)
432 mii->mii_media_active |= IFM_1000_T; 432 mii->mii_media_active |= IFM_1000_T;
433 else if ((gstat & RTK_GMEDIASTAT_100MBPS) != 0) 433 else if ((gstat & RTK_GMEDIASTAT_100MBPS) != 0)
434 mii->mii_media_active |= IFM_100_TX; 434 mii->mii_media_active |= IFM_100_TX;
435 else if ((gstat & RTK_GMEDIASTAT_10MBPS) != 0) 435 else if ((gstat & RTK_GMEDIASTAT_10MBPS) != 0)
436 mii->mii_media_active |= IFM_10_T; 436 mii->mii_media_active |= IFM_10_T;
437 else 437 else
438 mii->mii_media_active |= IFM_NONE; 438 mii->mii_media_active |= IFM_NONE;
439 if ((gstat & RTK_GMEDIASTAT_FDX) != 0) 439 if ((gstat & RTK_GMEDIASTAT_FDX) != 0)
440 mii->mii_media_active |= mii_phy_flowstatus(sc) | 440 mii->mii_media_active |= mii_phy_flowstatus(sc) |
441 IFM_FDX; 441 IFM_FDX;
442 else 442 else
443 mii->mii_media_active |= IFM_HDX; 443 mii->mii_media_active |= IFM_HDX;
444 } 444 }
 445
 446 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T) {
 447 PHY_READ(sc, MII_GTSR, &gtsr);
 448 if ((gtsr & GTSR_MS_RES) != 0)
 449 mii->mii_media_active |= IFM_ETH_MASTER;
 450 }
445} 451}
446 452
447static int 453static int
448rgephy_mii_phy_auto(struct mii_softc *mii) 454rgephy_mii_phy_auto(struct mii_softc *mii)
449{ 455{
450 int anar; 456 int anar;
451 457
452 mii->mii_ticks = 0; 458 mii->mii_ticks = 0;
453 rgephy_loop(mii); 459 rgephy_loop(mii);
454 rgephy_reset(mii); 460 rgephy_reset(mii);
455 461
456 anar = BMSR_MEDIA_TO_ANAR(mii->mii_capabilities) | ANAR_CSMA; 462 anar = BMSR_MEDIA_TO_ANAR(mii->mii_capabilities) | ANAR_CSMA;
457 if (mii->mii_flags & MIIF_DOPAUSE) 463 if (mii->mii_flags & MIIF_DOPAUSE)