Module Name: src Committed By: msaitoh Date: Wed Nov 20 08:51:00 UTC 2019
Modified Files: src/sys/dev/mii: atphy.c mii_physubr.c miivar.h Log Message: Fix a bug that atphy(4) can't negotiate correctly when the media setting is neither auto nor 1000baseT. Use correct index for mii_media_table[]. History: mii_anar() is first added in OpenBSD and ported to NetBSD. On NetBSD, only atphy(4) use this function. mii_physubr.c rev. 1.75 changed mii_anar() for simplify. It changed the argument from the ifmedia word to ifm_data used in our MII API, but the caller have not been changed. And then, PR kern/50206 was reported and the caller was modified by me to prevent panic but it was not correct fix. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/sys/dev/mii/atphy.c cvs rdiff -u -r1.87 -r1.88 src/sys/dev/mii/mii_physubr.c cvs rdiff -u -r1.68 -r1.69 src/sys/dev/mii/miivar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/mii/atphy.c diff -u src/sys/dev/mii/atphy.c:1.24 src/sys/dev/mii/atphy.c:1.25 --- src/sys/dev/mii/atphy.c:1.24 Fri Oct 18 12:53:08 2019 +++ src/sys/dev/mii/atphy.c Wed Nov 20 08:50:59 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: atphy.c,v 1.24 2019/10/18 12:53:08 hkenken Exp $ */ +/* $NetBSD: atphy.c,v 1.25 2019/11/20 08:50:59 msaitoh Exp $ */ /* $OpenBSD: atphy.c,v 1.1 2008/09/25 20:47:16 brad Exp $ */ /*- @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: atphy.c,v 1.24 2019/10/18 12:53:08 hkenken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: atphy.c,v 1.25 2019/11/20 08:50:59 msaitoh Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -273,7 +273,7 @@ atphy_service(struct mii_softc *sc, stru return EINVAL; } - anar = mii_anar(IFM_SUBTYPE(ife->ifm_media)); + anar = mii_anar(ife); if ((ife->ifm_media & IFM_FDX) != 0) { bmcr |= BMCR_FDX; /* Enable pause. */ Index: src/sys/dev/mii/mii_physubr.c diff -u src/sys/dev/mii/mii_physubr.c:1.87 src/sys/dev/mii/mii_physubr.c:1.88 --- src/sys/dev/mii/mii_physubr.c:1.87 Tue Apr 9 11:28:45 2019 +++ src/sys/dev/mii/mii_physubr.c Wed Nov 20 08:50:59 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mii_physubr.c,v 1.87 2019/04/09 11:28:45 msaitoh Exp $ */ +/* $NetBSD: mii_physubr.c,v 1.88 2019/11/20 08:50:59 msaitoh Exp $ */ /*- * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.87 2019/04/09 11:28:45 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mii_physubr.c,v 1.88 2019/11/20 08:50:59 msaitoh Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -697,19 +697,16 @@ mii_phy_resume(device_t dv, const pmf_qu /* - * Given an ifmedia word, return the corresponding ANAR value. + * Given an ifmedia_entry, return the corresponding ANAR value. */ uint16_t -mii_anar(int media) +mii_anar(struct ifmedia_entry *ife) { - int rv; #ifdef DIAGNOSTIC - if (/* media < 0 || */ media >= MII_NMEDIA) + if (ife->ifm_data >= MII_NMEDIA) panic("mii_anar"); #endif - rv = mii_media_table[media].mm_anar; - - return rv; + return mii_media_table[ife->ifm_data].mm_anar; } Index: src/sys/dev/mii/miivar.h diff -u src/sys/dev/mii/miivar.h:1.68 src/sys/dev/mii/miivar.h:1.69 --- src/sys/dev/mii/miivar.h:1.68 Thu Apr 11 09:14:07 2019 +++ src/sys/dev/mii/miivar.h Wed Nov 20 08:50:59 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: miivar.h,v 1.68 2019/04/11 09:14:07 msaitoh Exp $ */ +/* $NetBSD: miivar.h,v 1.69 2019/11/20 08:50:59 msaitoh Exp $ */ /*- * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. @@ -287,7 +287,7 @@ int mii_mediachg(struct mii_data *); void mii_tick(struct mii_data *); void mii_pollstat(struct mii_data *); void mii_down(struct mii_data *); -uint16_t mii_anar(int); +uint16_t mii_anar(struct ifmedia_entry *); int mii_ifmedia_change(struct mii_data *);