Sun Jun 16 06:29:09 2013 UTC ()
 The bit location of link ability is different between 1000Base-X and others
(See annex 28B.2 and 28D). The old mii.h defined ANAR_X_PAUSE_* macros. Those
macros were named for 1000Base-X, but the bit definitions were not for
1000Base-X but for others (e.g. 1000BaseT). So there was bug in auto
negotiation for 1000Base-X, but there was no bug for other media. Define new
macro named ANAR_PAUSE_* and ANLPAR_PAUSE_* for other than 1000Base-X and fix
the bit definitions of ANAR_X_PAUSE_* and ANLPPAR_X_*. Change some PHY drivers
to use true macro.


(msaitoh)
diff -r1.14 -r1.15 src/sys/dev/mii/atphy.c
diff -r1.65 -r1.66 src/sys/dev/mii/brgphy.c
diff -r1.16 -r1.17 src/sys/dev/mii/mii.h
diff -r1.78 -r1.79 src/sys/dev/mii/mii_physubr.c
diff -r1.32 -r1.33 src/sys/dev/mii/rgephy.c

cvs diff -r1.14 -r1.15 src/sys/dev/mii/atphy.c (expand / switch to unified diff)

--- src/sys/dev/mii/atphy.c 2013/06/09 08:42:16 1.14
+++ src/sys/dev/mii/atphy.c 2013/06/16 06:29:08 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: atphy.c,v 1.14 2013/06/09 08:42:16 msaitoh Exp $ */ 1/* $NetBSD: atphy.c,v 1.15 2013/06/16 06:29:08 msaitoh Exp $ */
2/* $OpenBSD: atphy.c,v 1.1 2008/09/25 20:47:16 brad Exp $ */ 2/* $OpenBSD: atphy.c,v 1.1 2008/09/25 20:47:16 brad Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org> 5 * Copyright (c) 2008, Pyun YongHyeon <yongari@FreeBSD.org>
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following 12 * notice unmodified, this list of conditions, and the following
13 * disclaimer. 13 * disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE. 28 * SUCH DAMAGE.
29 */ 29 */
30 30
31/* 31/*
32 * Driver for the Attansic F1 10/100/1000 PHY. 32 * Driver for the Attansic F1 10/100/1000 PHY.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: atphy.c,v 1.14 2013/06/09 08:42:16 msaitoh Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: atphy.c,v 1.15 2013/06/16 06:29:08 msaitoh Exp $");
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/systm.h> 39#include <sys/systm.h>
40#include <sys/kernel.h> 40#include <sys/kernel.h>
41#include <sys/device.h> 41#include <sys/device.h>
42#include <sys/socket.h> 42#include <sys/socket.h>
43 43
44#include <net/if.h> 44#include <net/if.h>
45#include <net/if_media.h> 45#include <net/if_media.h>
46 46
47#include <dev/mii/mii.h> 47#include <dev/mii/mii.h>
48#include <dev/mii/miivar.h> 48#include <dev/mii/miivar.h>
49#include <dev/mii/miidevs.h> 49#include <dev/mii/miidevs.h>
@@ -223,27 +223,27 @@ atphy_service(struct mii_softc *sc, stru @@ -223,27 +223,27 @@ atphy_service(struct mii_softc *sc, stru
223 * Attansic/Atheros PHY hardwares. 223 * Attansic/Atheros PHY hardwares.
224 */ 224 */
225 PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_ISO); 225 PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_ISO);
226 goto done; 226 goto done;
227 default: 227 default:
228 return EINVAL; 228 return EINVAL;
229 } 229 }
230 230
231 anar = mii_anar(ife->ifm_media); 231 anar = mii_anar(ife->ifm_media);
232 if (((ife->ifm_media & IFM_GMASK) & IFM_FDX) != 0) { 232 if (((ife->ifm_media & IFM_GMASK) & IFM_FDX) != 0) {
233 bmcr |= BMCR_FDX; 233 bmcr |= BMCR_FDX;
234 /* Enable pause. */ 234 /* Enable pause. */
235 if (sc->mii_flags & MIIF_DOPAUSE) 235 if (sc->mii_flags & MIIF_DOPAUSE)
236 anar |= ANAR_X_PAUSE_TOWARDS; 236 anar |= ANAR_PAUSE_TOWARDS;
237 } 237 }
238 238
239 if ((sc->mii_extcapabilities & (EXTSR_1000TFDX | 239 if ((sc->mii_extcapabilities & (EXTSR_1000TFDX |
240 EXTSR_1000THDX)) != 0) 240 EXTSR_1000THDX)) != 0)
241 PHY_WRITE(sc, MII_100T2CR, 0); 241 PHY_WRITE(sc, MII_100T2CR, 0);
242 PHY_WRITE(sc, MII_ANAR, anar); 242 PHY_WRITE(sc, MII_ANAR, anar);
243 243
244 /* 244 /*
245 * Start autonegotiation. 245 * Start autonegotiation.
246 */ 246 */
247 PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_AUTOEN | BMCR_STARTNEG); 247 PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_AUTOEN | BMCR_STARTNEG);
248done: 248done:
249 break; 249 break;

cvs diff -r1.65 -r1.66 src/sys/dev/mii/brgphy.c (expand / switch to unified diff)

--- src/sys/dev/mii/brgphy.c 2013/06/14 06:21:51 1.65
+++ src/sys/dev/mii/brgphy.c 2013/06/16 06:29:08 1.66
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: brgphy.c,v 1.65 2013/06/14 06:21:51 msaitoh Exp $ */ 1/* $NetBSD: brgphy.c,v 1.66 2013/06/16 06:29:08 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */ 55 */
56 56
57/* 57/*
58 * driver for the Broadcom BCM5400 and BCM5700 Gig-E PHYs. 58 * driver for the Broadcom BCM5400 and BCM5700 Gig-E PHYs.
59 * 59 *
60 * Programming information for this PHY was gleaned from FreeBSD 60 * Programming information for this PHY was gleaned from FreeBSD
61 * (they were apparently able to get a datasheet from Broadcom). 61 * (they were apparently able to get a datasheet from Broadcom).
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65__KERNEL_RCSID(0, "$NetBSD: brgphy.c,v 1.65 2013/06/14 06:21:51 msaitoh Exp $"); 65__KERNEL_RCSID(0, "$NetBSD: brgphy.c,v 1.66 2013/06/16 06:29:08 msaitoh Exp $");
66 66
67#include <sys/param.h> 67#include <sys/param.h>
68#include <sys/systm.h> 68#include <sys/systm.h>
69#include <sys/kernel.h> 69#include <sys/kernel.h>
70#include <sys/device.h> 70#include <sys/device.h>
71#include <sys/socket.h> 71#include <sys/socket.h>
72#include <sys/errno.h> 72#include <sys/errno.h>
73#include <prop/proplib.h> 73#include <prop/proplib.h>
74 74
75#include <net/if.h> 75#include <net/if.h>
76#include <net/if_media.h> 76#include <net/if_media.h>
77 77
78#include <dev/mii/mii.h> 78#include <dev/mii/mii.h>
@@ -590,27 +590,27 @@ brgphy_mii_phy_auto(struct mii_softc *sc @@ -590,27 +590,27 @@ brgphy_mii_phy_auto(struct mii_softc *sc
590 && (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5701)) 590 && (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5701))
591 ktcr |= GTCR_MAN_MS | GTCR_ADV_MS; 591 ktcr |= GTCR_MAN_MS | GTCR_ADV_MS;
592 PHY_WRITE(sc, MII_100T2CR, ktcr); 592 PHY_WRITE(sc, MII_100T2CR, ktcr);
593 ktcr = PHY_READ(sc, MII_100T2CR); 593 ktcr = PHY_READ(sc, MII_100T2CR);
594 DELAY(1000); 594 DELAY(1000);
595 595
596 if (sc->mii_flags & MIIF_HAVEFIBER) { 596 if (sc->mii_flags & MIIF_HAVEFIBER) {
597 anar = ANAR_X_FD | ANAR_X_HD; 597 anar = ANAR_X_FD | ANAR_X_HD;
598 if (sc->mii_flags & MIIF_DOPAUSE) 598 if (sc->mii_flags & MIIF_DOPAUSE)
599 anar |= BRGPHY_SERDES_ANAR_BOTH_PAUSE; 599 anar |= BRGPHY_SERDES_ANAR_BOTH_PAUSE;
600 } else { 600 } else {
601 anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA; 601 anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
602 if (sc->mii_flags & MIIF_DOPAUSE) 602 if (sc->mii_flags & MIIF_DOPAUSE)
603 anar |= ANAR_FC | ANAR_X_PAUSE_ASYM; 603 anar |= ANAR_FC | ANAR_PAUSE_ASYM;
604 } 604 }
605 PHY_WRITE(sc, MII_ANAR, anar); 605 PHY_WRITE(sc, MII_ANAR, anar);
606 DELAY(1000); 606 DELAY(1000);
607 607
608 /* Start autonegotiation */ 608 /* Start autonegotiation */
609 PHY_WRITE(sc, MII_BMCR, 609 PHY_WRITE(sc, MII_BMCR,
610 BMCR_AUTOEN | BMCR_STARTNEG); 610 BMCR_AUTOEN | BMCR_STARTNEG);
611 PHY_WRITE(sc, BRGPHY_MII_IMR, 0xFF00); 611 PHY_WRITE(sc, BRGPHY_MII_IMR, 0xFF00);
612 612
613 return (EJUSTRETURN); 613 return (EJUSTRETURN);
614} 614}
615 615
616void 616void

cvs diff -r1.16 -r1.17 src/sys/dev/mii/mii.h (expand / switch to unified diff)

--- src/sys/dev/mii/mii.h 2013/04/15 08:09:48 1.16
+++ src/sys/dev/mii/mii.h 2013/06/16 06:29:08 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mii.h,v 1.16 2013/04/15 08:09:48 msaitoh Exp $ */ 1/* $NetBSD: mii.h,v 1.17 2013/06/16 06:29:08 msaitoh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Manuel Bouyer. All rights reserved. 4 * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
5 * 5 *
6 * Modification to match BSD/OS 3.0 MII interface by Jason R. Thorpe, 6 * Modification to match BSD/OS 3.0 MII interface by Jason R. Thorpe,
7 * Numerical Aerospace Simulation Facility, NASA Ames Research Center. 7 * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -97,61 +97,72 @@ @@ -97,61 +97,72 @@
97 97
98#define MII_PHYIDR1 0x02 /* ID register 1 (ro) */ 98#define MII_PHYIDR1 0x02 /* ID register 1 (ro) */
99 99
100#define MII_PHYIDR2 0x03 /* ID register 2 (ro) */ 100#define MII_PHYIDR2 0x03 /* ID register 2 (ro) */
101#define IDR2_OUILSB 0xfc00 /* OUI LSB */ 101#define IDR2_OUILSB 0xfc00 /* OUI LSB */
102#define IDR2_MODEL 0x03f0 /* vendor model */ 102#define IDR2_MODEL 0x03f0 /* vendor model */
103#define IDR2_REV 0x000f /* vendor revision */ 103#define IDR2_REV 0x000f /* vendor revision */
104 104
105#define MII_ANAR 0x04 /* Autonegotiation advertisement (rw) */ 105#define MII_ANAR 0x04 /* Autonegotiation advertisement (rw) */
106 /* section 28.2.4.1 and 37.2.6.1 */ 106 /* section 28.2.4.1 and 37.2.6.1 */
107#define ANAR_NP 0x8000 /* Next page (ro) */ 107#define ANAR_NP 0x8000 /* Next page (ro) */
108#define ANAR_ACK 0x4000 /* link partner abilities acknowledged (ro) */ 108#define ANAR_ACK 0x4000 /* link partner abilities acknowledged (ro) */
109#define ANAR_RF 0x2000 /* remote fault (ro) */ 109#define ANAR_RF 0x2000 /* remote fault (ro) */
 110 /* Annex 28B.2 */
110#define ANAR_FC 0x0400 /* local device supports PAUSE */ 111#define ANAR_FC 0x0400 /* local device supports PAUSE */
111#define ANAR_T4 0x0200 /* local device supports 100bT4 */ 112#define ANAR_T4 0x0200 /* local device supports 100bT4 */
112#define ANAR_TX_FD 0x0100 /* local device supports 100bTx FD */ 113#define ANAR_TX_FD 0x0100 /* local device supports 100bTx FD */
113#define ANAR_TX 0x0080 /* local device supports 100bTx */ 114#define ANAR_TX 0x0080 /* local device supports 100bTx */
114#define ANAR_10_FD 0x0040 /* local device supports 10bT FD */ 115#define ANAR_10_FD 0x0040 /* local device supports 10bT FD */
115#define ANAR_10 0x0020 /* local device supports 10bT */ 116#define ANAR_10 0x0020 /* local device supports 10bT */
116#define ANAR_CSMA 0x0001 /* protocol selector CSMA/CD */ 117#define ANAR_CSMA 0x0001 /* protocol selector CSMA/CD */
 118#define ANAR_PAUSE_NONE (0 << 10)
 119#define ANAR_PAUSE_SYM (1 << 10)
 120#define ANAR_PAUSE_ASYM (2 << 10)
 121#define ANAR_PAUSE_TOWARDS (3 << 10)
117 122
 123 /* Annex 28D */
118#define ANAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */ 124#define ANAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */
119#define ANAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */ 125#define ANAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */
120#define ANAR_X_PAUSE_NONE (0 << 10) 126#define ANAR_X_PAUSE_NONE (0 << 7)
121#define ANAR_X_PAUSE_SYM (1 << 10) 127#define ANAR_X_PAUSE_SYM (1 << 7)
122#define ANAR_X_PAUSE_ASYM (2 << 10) 128#define ANAR_X_PAUSE_ASYM (2 << 7)
123#define ANAR_X_PAUSE_TOWARDS (3 << 10) 129#define ANAR_X_PAUSE_TOWARDS (3 << 7)
124 130
125#define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */ 131#define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */
126 /* section 28.2.4.1 and 37.2.6.1 */ 132 /* section 28.2.4.1 and 37.2.6.1 */
127#define ANLPAR_NP 0x8000 /* Next page (ro) */ 133#define ANLPAR_NP 0x8000 /* Next page (ro) */
128#define ANLPAR_ACK 0x4000 /* link partner accepted ACK (ro) */ 134#define ANLPAR_ACK 0x4000 /* link partner accepted ACK (ro) */
129#define ANLPAR_RF 0x2000 /* remote fault (ro) */ 135#define ANLPAR_RF 0x2000 /* remote fault (ro) */
130#define ANLPAR_FC 0x0400 /* link partner supports PAUSE */ 136#define ANLPAR_FC 0x0400 /* link partner supports PAUSE */
131#define ANLPAR_T4 0x0200 /* link partner supports 100bT4 */ 137#define ANLPAR_T4 0x0200 /* link partner supports 100bT4 */
132#define ANLPAR_TX_FD 0x0100 /* link partner supports 100bTx FD */ 138#define ANLPAR_TX_FD 0x0100 /* link partner supports 100bTx FD */
133#define ANLPAR_TX 0x0080 /* link partner supports 100bTx */ 139#define ANLPAR_TX 0x0080 /* link partner supports 100bTx */
134#define ANLPAR_10_FD 0x0040 /* link partner supports 10bT FD */ 140#define ANLPAR_10_FD 0x0040 /* link partner supports 10bT FD */
135#define ANLPAR_10 0x0020 /* link partner supports 10bT */ 141#define ANLPAR_10 0x0020 /* link partner supports 10bT */
136#define ANLPAR_CSMA 0x0001 /* protocol selector CSMA/CD */ 142#define ANLPAR_CSMA 0x0001 /* protocol selector CSMA/CD */
 143#define ANLPAR_PAUSE_MASK (3 << 10)
 144#define ANLPAR_PAUSE_NONE (0 << 10)
 145#define ANLPAR_PAUSE_SYM (1 << 10)
 146#define ANLPAR_PAUSE_ASYM (2 << 10)
 147#define ANLPAR_PAUSE_TOWARDS (3 << 10)
137 148
138#define ANLPAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */ 149#define ANLPAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */
139#define ANLPAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */ 150#define ANLPAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */
140#define ANLPAR_X_PAUSE_MASK (3 << 10) 151#define ANLPAR_X_PAUSE_MASK (3 << 7)
141#define ANLPAR_X_PAUSE_NONE (0 << 10) 152#define ANLPAR_X_PAUSE_NONE (0 << 7)
142#define ANLPAR_X_PAUSE_SYM (1 << 10) 153#define ANLPAR_X_PAUSE_SYM (1 << 7)
143#define ANLPAR_X_PAUSE_ASYM (2 << 10) 154#define ANLPAR_X_PAUSE_ASYM (2 << 7)
144#define ANLPAR_X_PAUSE_TOWARDS (3 << 10) 155#define ANLPAR_X_PAUSE_TOWARDS (3 << 7)
145 156
146#define MII_ANER 0x06 /* Autonegotiation expansion (ro) */ 157#define MII_ANER 0x06 /* Autonegotiation expansion (ro) */
147 /* section 28.2.4.1 and 37.2.6.1 */ 158 /* section 28.2.4.1 and 37.2.6.1 */
148#define ANER_MLF 0x0010 /* multiple link detection fault */ 159#define ANER_MLF 0x0010 /* multiple link detection fault */
149#define ANER_LPNP 0x0008 /* link parter next page-able */ 160#define ANER_LPNP 0x0008 /* link parter next page-able */
150#define ANER_NP 0x0004 /* next page-able */ 161#define ANER_NP 0x0004 /* next page-able */
151#define ANER_PAGE_RX 0x0002 /* Page received */ 162#define ANER_PAGE_RX 0x0002 /* Page received */
152#define ANER_LPAN 0x0001 /* link parter autoneg-able */ 163#define ANER_LPAN 0x0001 /* link parter autoneg-able */
153 164
154#define MII_ANNP 0x07 /* Autonegotiation next page */ 165#define MII_ANNP 0x07 /* Autonegotiation next page */
155 /* section 28.2.4.1 and 37.2.6.1 */ 166 /* section 28.2.4.1 and 37.2.6.1 */
156 167
157#define MII_ANLPRNP 0x08 /* Autonegotiation link partner rx next page */ 168#define MII_ANLPRNP 0x08 /* Autonegotiation link partner rx next page */

cvs diff -r1.78 -r1.79 src/sys/dev/mii/mii_physubr.c (expand / switch to unified diff)

--- src/sys/dev/mii/mii_physubr.c 2013/06/09 09:56:17 1.78
+++ src/sys/dev/mii/mii_physubr.c 2013/06/16 06:29:08 1.79
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mii_physubr.c,v 1.78 2013/06/09 09:56:17 msaitoh Exp $ */ 1/* $NetBSD: mii_physubr.c,v 1.79 2013/06/16 06:29:08 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Subroutines common to all PHYs. 34 * Subroutines common to all PHYs.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.78 2013/06/09 09:56:17 msaitoh Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.79 2013/06/16 06:29:08 msaitoh Exp $");
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/device.h> 41#include <sys/device.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/socket.h> 44#include <sys/socket.h>
45#include <sys/errno.h> 45#include <sys/errno.h>
46#include <sys/module.h> 46#include <sys/module.h>
47#include <sys/proc.h> 47#include <sys/proc.h>
48 48
49#include <net/if.h> 49#include <net/if.h>
50#include <net/if_media.h> 50#include <net/if_media.h>
51#include <net/route.h> 51#include <net/route.h>
@@ -167,28 +167,28 @@ mii_phy_setmedia(struct mii_softc *sc) @@ -167,28 +167,28 @@ mii_phy_setmedia(struct mii_softc *sc)
167 default: 167 default:
168 panic("mii_phy_setmedia: MASTER on wrong media"); 168 panic("mii_phy_setmedia: MASTER on wrong media");
169 } 169 }
170 } 170 }
171 171
172 if (mii->mii_media.ifm_media & IFM_FLOW) { 172 if (mii->mii_media.ifm_media & IFM_FLOW) {
173 if (sc->mii_flags & MIIF_IS_1000X) 173 if (sc->mii_flags & MIIF_IS_1000X)
174 anar |= ANAR_X_PAUSE_SYM | ANAR_X_PAUSE_ASYM; 174 anar |= ANAR_X_PAUSE_SYM | ANAR_X_PAUSE_ASYM;
175 else { 175 else {
176 anar |= ANAR_FC; 176 anar |= ANAR_FC;
177 /* XXX Only 1000BASE-T has PAUSE_ASYM? */ 177 /* XXX Only 1000BASE-T has PAUSE_ASYM? */
178 if ((sc->mii_flags & MIIF_HAVE_GTCR) && 178 if ((sc->mii_flags & MIIF_HAVE_GTCR) &&
179 (sc->mii_extcapabilities & 179 (sc->mii_extcapabilities &
180 (EXTSR_1000THDX|EXTSR_1000TFDX))) 180 (EXTSR_1000THDX | EXTSR_1000TFDX)))
181 anar |= ANAR_X_PAUSE_ASYM; 181 anar |= ANAR_PAUSE_ASYM;
182 } 182 }
183 } 183 }
184 184
185 if (ife->ifm_media & IFM_LOOP) 185 if (ife->ifm_media & IFM_LOOP)
186 bmcr |= BMCR_LOOP; 186 bmcr |= BMCR_LOOP;
187 187
188 PHY_WRITE(sc, MII_ANAR, anar); 188 PHY_WRITE(sc, MII_ANAR, anar);
189 if (sc->mii_flags & MIIF_HAVE_GTCR) 189 if (sc->mii_flags & MIIF_HAVE_GTCR)
190 PHY_WRITE(sc, MII_100T2CR, gtcr); 190 PHY_WRITE(sc, MII_100T2CR, gtcr);
191 if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) { 191 if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) {
192 mii_phy_auto(sc, 0); 192 mii_phy_auto(sc, 0);
193 } else { 193 } else {
194 PHY_WRITE(sc, MII_BMCR, bmcr); 194 PHY_WRITE(sc, MII_BMCR, bmcr);
@@ -222,28 +222,28 @@ mii_phy_auto(struct mii_softc *sc, int w @@ -222,28 +222,28 @@ mii_phy_auto(struct mii_softc *sc, int w
222 } 222 }
223 223
224 PHY_WRITE(sc, MII_ANAR, anar); 224 PHY_WRITE(sc, MII_ANAR, anar);
225 } else { 225 } else {
226 uint16_t anar; 226 uint16_t anar;
227 227
228 anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | 228 anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) |
229 ANAR_CSMA; 229 ANAR_CSMA;
230 if (sc->mii_flags & MIIF_DOPAUSE) { 230 if (sc->mii_flags & MIIF_DOPAUSE) {
231 anar |= ANAR_FC; 231 anar |= ANAR_FC;
232 /* XXX Only 1000BASE-T has PAUSE_ASYM? */ 232 /* XXX Only 1000BASE-T has PAUSE_ASYM? */
233 if ((sc->mii_flags & MIIF_HAVE_GTCR) && 233 if ((sc->mii_flags & MIIF_HAVE_GTCR) &&
234 (sc->mii_extcapabilities & 234 (sc->mii_extcapabilities &
235 (EXTSR_1000THDX|EXTSR_1000TFDX))) 235 (EXTSR_1000THDX | EXTSR_1000TFDX)))
236 anar |= ANAR_X_PAUSE_ASYM; 236 anar |= ANAR_PAUSE_ASYM;
237 } 237 }
238 238
239 /* 239 /*
240 *for 1000-base-T, autonegotiation mus be enabled, but  240 *for 1000-base-T, autonegotiation mus be enabled, but
241 *if we're not set to auto, only advertise 241 *if we're not set to auto, only advertise
242 *1000-base-T with the link partner. 242 *1000-base-T with the link partner.
243 */ 243 */
244 if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) { 244 if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) {
245 anar &= ~(ANAR_T4|ANAR_TX_FD|ANAR_TX|ANAR_10_FD|ANAR_10); 245 anar &= ~(ANAR_T4|ANAR_TX_FD|ANAR_TX|ANAR_10_FD|ANAR_10);
246 } 246 }
247  247
248 PHY_WRITE(sc, MII_ANAR, anar); 248 PHY_WRITE(sc, MII_ANAR, anar);
249 if (sc->mii_flags & MIIF_HAVE_GTCR) { 249 if (sc->mii_flags & MIIF_HAVE_GTCR) {
@@ -637,50 +637,55 @@ mii_phy_match(const struct mii_attach_ar @@ -637,50 +637,55 @@ mii_phy_match(const struct mii_attach_ar
637 * Return the flow control status flag from MII_ANAR & MII_ANLPAR. 637 * Return the flow control status flag from MII_ANAR & MII_ANLPAR.
638 */ 638 */
639u_int 639u_int
640mii_phy_flowstatus(struct mii_softc *sc) 640mii_phy_flowstatus(struct mii_softc *sc)
641{ 641{
642 u_int anar, anlpar; 642 u_int anar, anlpar;
643 643
644 if ((sc->mii_flags & MIIF_DOPAUSE) == 0) 644 if ((sc->mii_flags & MIIF_DOPAUSE) == 0)
645 return (0); 645 return (0);
646 646
647 anar = PHY_READ(sc, MII_ANAR); 647 anar = PHY_READ(sc, MII_ANAR);
648 anlpar = PHY_READ(sc, MII_ANLPAR); 648 anlpar = PHY_READ(sc, MII_ANLPAR);
649 649
650 if ((anar & ANAR_X_PAUSE_SYM) & (anlpar & ANLPAR_X_PAUSE_SYM)) 650 /* For 1000baseX, the bits are in a different location. */
 651 if (sc->mii_flags & MIIF_IS_1000X) {
 652 anar <<= 3;
 653 anlpar <<= 3;
 654 }
 655
 656 if ((anar & ANAR_PAUSE_SYM) & (anlpar & ANLPAR_PAUSE_SYM))
651 return (IFM_FLOW|IFM_ETH_TXPAUSE|IFM_ETH_RXPAUSE); 657 return (IFM_FLOW|IFM_ETH_TXPAUSE|IFM_ETH_RXPAUSE);
652 658
653 if ((anar & ANAR_X_PAUSE_SYM) == 0) { 659 if ((anar & ANAR_PAUSE_SYM) == 0) {
654 if ((anar & ANAR_X_PAUSE_ASYM) && 660 if ((anar & ANAR_PAUSE_ASYM) &&
655 ((anlpar & 661 ((anlpar & ANLPAR_PAUSE_TOWARDS) == ANLPAR_PAUSE_TOWARDS))
656 ANLPAR_X_PAUSE_TOWARDS) == ANLPAR_X_PAUSE_TOWARDS)) 
657 return (IFM_FLOW|IFM_ETH_TXPAUSE); 662 return (IFM_FLOW|IFM_ETH_TXPAUSE);
658 else 663 else
659 return (0); 664 return (0);
660 } 665 }
661 666
662 if ((anar & ANAR_X_PAUSE_ASYM) == 0) { 667 if ((anar & ANAR_PAUSE_ASYM) == 0) {
663 if (anlpar & ANLPAR_X_PAUSE_SYM) 668 if (anlpar & ANLPAR_PAUSE_SYM)
664 return (IFM_FLOW|IFM_ETH_TXPAUSE|IFM_ETH_RXPAUSE); 669 return (IFM_FLOW|IFM_ETH_TXPAUSE|IFM_ETH_RXPAUSE);
665 else 670 else
666 return (0); 671 return (0);
667 } 672 }
668 673
669 switch ((anlpar & ANLPAR_X_PAUSE_TOWARDS)) { 674 switch ((anlpar & ANLPAR_PAUSE_TOWARDS)) {
670 case ANLPAR_X_PAUSE_NONE: 675 case ANLPAR_PAUSE_NONE:
671 return (0); 676 return (0);
672 677
673 case ANLPAR_X_PAUSE_ASYM: 678 case ANLPAR_PAUSE_ASYM:
674 return (IFM_FLOW|IFM_ETH_RXPAUSE); 679 return (IFM_FLOW|IFM_ETH_RXPAUSE);
675 680
676 default: 681 default:
677 return (IFM_FLOW|IFM_ETH_RXPAUSE|IFM_ETH_TXPAUSE); 682 return (IFM_FLOW|IFM_ETH_RXPAUSE|IFM_ETH_TXPAUSE);
678 } 683 }
679 /* NOTREACHED */ 684 /* NOTREACHED */
680} 685}
681 686
682bool 687bool
683mii_phy_resume(device_t dv, const pmf_qual_t *qual) 688mii_phy_resume(device_t dv, const pmf_qual_t *qual)
684{ 689{
685 struct mii_softc *sc = device_private(dv); 690 struct mii_softc *sc = device_private(dv);
686 691

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

--- src/sys/dev/mii/rgephy.c 2013/06/09 09:31:32 1.32
+++ src/sys/dev/mii/rgephy.c 2013/06/16 06:29:08 1.33
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rgephy.c,v 1.32 2013/06/09 09:31:32 msaitoh Exp $ */ 1/* $NetBSD: rgephy.c,v 1.33 2013/06/16 06:29:08 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.32 2013/06/09 09:31:32 msaitoh Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: rgephy.c,v 1.33 2013/06/16 06:29:08 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
@@ -430,27 +430,27 @@ rgephy_status(struct mii_softc *sc) @@ -430,27 +430,27 @@ rgephy_status(struct mii_softc *sc)
430 430
431 431
432static int 432static int
433rgephy_mii_phy_auto(struct mii_softc *mii) 433rgephy_mii_phy_auto(struct mii_softc *mii)
434{ 434{
435 int anar; 435 int anar;
436 436
437 mii->mii_ticks = 0; 437 mii->mii_ticks = 0;
438 rgephy_loop(mii); 438 rgephy_loop(mii);
439 rgephy_reset(mii); 439 rgephy_reset(mii);
440 440
441 anar = BMSR_MEDIA_TO_ANAR(mii->mii_capabilities) | ANAR_CSMA; 441 anar = BMSR_MEDIA_TO_ANAR(mii->mii_capabilities) | ANAR_CSMA;
442 if (mii->mii_flags & MIIF_DOPAUSE) 442 if (mii->mii_flags & MIIF_DOPAUSE)
443 anar |= ANAR_FC | ANAR_X_PAUSE_ASYM; 443 anar |= ANAR_FC | ANAR_PAUSE_ASYM;
444 444
445 PHY_WRITE(mii, MII_ANAR, anar); 445 PHY_WRITE(mii, MII_ANAR, anar);
446 DELAY(1000); 446 DELAY(1000);
447 PHY_WRITE(mii, MII_100T2CR, GTCR_ADV_1000THDX | GTCR_ADV_1000TFDX); 447 PHY_WRITE(mii, MII_100T2CR, GTCR_ADV_1000THDX | GTCR_ADV_1000TFDX);
448 DELAY(1000); 448 DELAY(1000);
449 PHY_WRITE(mii, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG); 449 PHY_WRITE(mii, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG);
450 DELAY(100); 450 DELAY(100);
451 451
452 return EJUSTRETURN; 452 return EJUSTRETURN;
453} 453}
454 454
455static void 455static void
456rgephy_loop(struct mii_softc *sc) 456rgephy_loop(struct mii_softc *sc)