Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Change MII PHY read/write API from:
details: https://anonhg.NetBSD.org/src/rev/6c2738fd7fce
branches: trunk
changeset: 447707:6c2738fd7fce
user: msaitoh <msaitoh%NetBSD.org@localhost>
date: Tue Jan 22 03:42:24 2019 +0000
description:
Change MII PHY read/write API from:
int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:
int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);
Now we can test if a read/write operation failed or not by the return value.
In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.
Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:
arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c
Tested with the following device:
axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)
Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url
Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
diffstat:
sys/arch/arm/at91/at91emac.c | 22 +-
sys/arch/arm/ep93xx/epe.c | 22 +-
sys/arch/arm/gemini/gemini_gmac.c | 22 +-
sys/arch/arm/imx/if_enet.c | 31 +-
sys/arch/arm/omap/if_cpsw.c | 31 +-
sys/arch/arm/omap/omapl1x_emac.c | 21 +-
sys/arch/arm/sunxi/sun4i_emac.c | 28 +-
sys/arch/arm/sunxi/sunxi_emac.c | 28 +-
sys/arch/arm/ti/if_cpsw.c | 31 +-
sys/arch/arm/xscale/ixp425_if_npe.c | 37 +-
sys/arch/evbppc/virtex/dev/if_temac.c | 30 +-
sys/arch/macppc/dev/if_bm.c | 23 +-
sys/arch/macppc/dev/if_gm.c | 25 +-
sys/arch/mips/alchemy/dev/if_aumac.c | 37 +-
sys/arch/mips/atheros/dev/if_ae.c | 25 +-
sys/arch/mips/cavium/dev/if_cnmac.c | 18 +-
sys/arch/mips/cavium/dev/octeon_smi.c | 37 +-
sys/arch/mips/cavium/dev/octeon_smivar.h | 6 +-
sys/arch/mips/ralink/ralink_eth.c | 28 +-
sys/arch/mips/sibyte/dev/sbmac.c | 16 +-
sys/arch/playstation2/dev/emac3.c | 34 +-
sys/arch/playstation2/dev/emac3var.h | 6 +-
sys/arch/powerpc/booke/dev/pq3etsec.c | 16 +-
sys/arch/powerpc/ibm4xx/dev/if_emac.c | 45 +-
sys/arch/sgimips/mace/if_mec.c | 43 +-
sys/dev/cadence/if_cemac.c | 19 +-
sys/dev/ic/aic6915.c | 24 +-
sys/dev/ic/ax88190.c | 21 +-
sys/dev/ic/dl10019.c | 39 +-
sys/dev/ic/dwc_gmac.c | 27 +-
sys/dev/ic/elink3.c | 25 +-
sys/dev/ic/elinkxl.c | 27 +-
sys/dev/ic/gem.c | 25 +-
sys/dev/ic/hme.c | 48 +-
sys/dev/ic/i82557.c | 34 +-
sys/dev/ic/lan9118.c | 31 +-
sys/dev/ic/mtd803.c | 20 +-
sys/dev/ic/rtl8169.c | 96 ++--
sys/dev/ic/rtl81x9.c | 126 +++--
sys/dev/ic/smc83c170.c | 42 +-
sys/dev/ic/smc91cxx.c | 27 +-
sys/dev/ic/tulip.c | 80 ++-
sys/dev/marvell/if_gfe.c | 32 +-
sys/dev/marvell/if_mvgbe.c | 57 +-
sys/dev/marvell/if_mvxpe.c | 63 +-
sys/dev/mii/acphy.c | 20 +-
sys/dev/mii/amhphy.c | 20 +-
sys/dev/mii/atphy.c | 37 +-
sys/dev/mii/bmtphy.c | 30 +-
sys/dev/mii/brgphy.c | 159 ++++---
sys/dev/mii/ciphy.c | 62 ++-
sys/dev/mii/dmphy.c | 21 +-
sys/dev/mii/etphy.c | 47 +-
sys/dev/mii/exphy.c | 7 +-
sys/dev/mii/gentbi.c | 34 +-
sys/dev/mii/glxtphy.c | 21 +-
sys/dev/mii/gphyter.c | 35 +-
sys/dev/mii/icsphy.c | 19 +-
sys/dev/mii/igphy.c | 45 +-
sys/dev/mii/igphyreg.h | 29 +-
sys/dev/mii/ihphy.c | 32 +-
sys/dev/mii/ikphy.c | 41 +-
sys/dev/mii/inphy.c | 21 +-
sys/dev/mii/iophy.c | 20 +-
sys/dev/mii/lxtphy.c | 34 +-
sys/dev/mii/makphy.c | 43 +-
sys/dev/mii/mii.c | 25 +-
sys/dev/mii/mii_bitbang.c | 29 +-
sys/dev/mii/mii_bitbang.h | 8 +-
sys/dev/mii/mii_physubr.c | 30 +-
sys/dev/mii/miivar.h | 20 +-
sys/dev/mii/nsphy.c | 49 +-
sys/dev/mii/nsphyter.c | 25 +-
sys/dev/mii/pnaphy.c | 18 +-
sys/dev/mii/qsphy.c | 23 +-
sys/dev/mii/rdcphy.c | 18 +-
sys/dev/mii/rgephy.c | 97 ++-
sys/dev/mii/rlphy.c | 24 +-
sys/dev/mii/sqphy.c | 30 +-
sys/dev/mii/tlphy.c | 37 +-
sys/dev/mii/tqphy.c | 21 +-
sys/dev/mii/ukphy.c | 13 +-
sys/dev/mii/ukphy_subr.c | 29 +-
sys/dev/mii/urlphy.c | 22 +-
sys/dev/pci/if_age.c | 38 +-
sys/dev/pci/if_alc.c | 216 +++++----
sys/dev/pci/if_ale.c | 32 +-
sys/dev/pci/if_bce.c | 57 +-
sys/dev/pci/if_bge.c | 54 +-
sys/dev/pci/if_bnx.c | 49 +-
sys/dev/pci/if_cas.c | 49 +-
sys/dev/pci/if_et.c | 50 +-
sys/dev/pci/if_jme.c | 37 +-
sys/dev/pci/if_lii.c | 64 +-
sys/dev/pci/if_msk.c | 47 +-
sys/dev/pci/if_nfe.c | 39 +-
sys/dev/pci/if_pcn.c | 25 +-
sys/dev/pci/if_sip.c | 105 ++--
sys/dev/pci/if_sk.c | 87 ++-
sys/dev/pci/if_ste.c | 18 +-
sys/dev/pci/if_stge.c | 19 +-
sys/dev/pci/if_tl.c | 26 +-
sys/dev/pci/if_vge.c | 37 +-
sys/dev/pci/if_vr.c | 18 +-
sys/dev/pci/if_vte.c | 24 +-
sys/dev/pci/if_wm.c | 635 +++++++++++++++++-------------
sys/dev/pcmcia/if_xi.c | 37 +-
sys/dev/sbus/be.c | 58 +-
sys/dev/usb/if_aue.c | 47 +-
sys/dev/usb/if_axe.c | 65 +-
sys/dev/usb/if_axen.c | 49 +-
sys/dev/usb/if_mue.c | 50 +-
sys/dev/usb/if_smsc.c | 37 +-
sys/dev/usb/if_udav.c | 53 +-
sys/dev/usb/if_url.c | 54 +-
115 files changed, 2783 insertions(+), 2213 deletions(-)
diffs (truncated from 13652 to 300 lines):
diff -r 4c7b6ad3ab31 -r 6c2738fd7fce sys/arch/arm/at91/at91emac.c
--- a/sys/arch/arm/at91/at91emac.c Tue Jan 22 03:11:32 2019 +0000
+++ b/sys/arch/arm/at91/at91emac.c Tue Jan 22 03:42:24 2019 +0000
@@ -1,5 +1,5 @@
-/* $Id: at91emac.c,v 1.22 2018/07/15 05:16:41 maxv Exp $ */
-/* $NetBSD: at91emac.c,v 1.22 2018/07/15 05:16:41 maxv Exp $ */
+/* $Id: at91emac.c,v 1.23 2019/01/22 03:42:24 msaitoh Exp $ */
+/* $NetBSD: at91emac.c,v 1.23 2019/01/22 03:42:24 msaitoh Exp $ */
/*
* Copyright (c) 2007 Embedtronics Oy
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: at91emac.c,v 1.22 2018/07/15 05:16:41 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at91emac.c,v 1.23 2019/01/22 03:42:24 msaitoh Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -96,8 +96,8 @@
static int emac_gctx(struct emac_softc *);
static int emac_mediachange(struct ifnet *);
static void emac_mediastatus(struct ifnet *, struct ifmediareq *);
-int emac_mii_readreg (device_t, int, int);
-void emac_mii_writereg (device_t, int, int, int);
+int emac_mii_readreg (device_t, int, int, uint16_t *);
+int emac_mii_writereg (device_t, int, int, uint16_t);
void emac_statchg (struct ifnet *);
void emac_tick (void *);
static int emac_ifioctl (struct ifnet *, u_long, void *);
@@ -513,7 +513,7 @@
int
-emac_mii_readreg(device_t self, int phy, int reg)
+emac_mii_readreg(device_t self, int phy, int reg, uint16_t *val)
{
#ifndef EMAC_FAST
struct emac_softc *sc = device_private(self);
@@ -524,11 +524,13 @@
| ((reg << ETH_MAN_REGA_SHIFT) & ETH_MAN_REGA)
| ETH_MAN_CODE_IEEE802_3));
while (!(EMAC_READ(ETH_SR) & ETH_SR_IDLE)) ;
- return (EMAC_READ(ETH_MAN) & ETH_MAN_DATA);
+ *val = EMAC_READ(ETH_MAN) & ETH_MAN_DATA;
+
+ return 0;
}
-void
-emac_mii_writereg(device_t self, int phy, int reg, int val)
+int
+emac_mii_writereg(device_t self, int phy, int reg, uint16_t val)
{
#ifndef EMAC_FAST
struct emac_softc *sc = device_private(self);
@@ -540,6 +542,8 @@
| ETH_MAN_CODE_IEEE802_3
| (val & ETH_MAN_DATA)));
while (!(EMAC_READ(ETH_SR) & ETH_SR_IDLE)) ;
+
+ return 0;
}
diff -r 4c7b6ad3ab31 -r 6c2738fd7fce sys/arch/arm/ep93xx/epe.c
--- a/sys/arch/arm/ep93xx/epe.c Tue Jan 22 03:11:32 2019 +0000
+++ b/sys/arch/arm/ep93xx/epe.c Tue Jan 22 03:42:24 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: epe.c,v 1.38 2018/06/26 06:47:57 msaitoh Exp $ */
+/* $NetBSD: epe.c,v 1.39 2019/01/22 03:42:25 msaitoh Exp $ */
/*
* Copyright (c) 2004 Jesse Off
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: epe.c,v 1.38 2018/06/26 06:47:57 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: epe.c,v 1.39 2019/01/22 03:42:25 msaitoh Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -97,8 +97,8 @@
static int epe_intr(void* arg);
static int epe_gctx(struct epe_softc *);
static int epe_mediachange(struct ifnet *);
-int epe_mii_readreg (device_t, int, int);
-void epe_mii_writereg (device_t, int, int, int);
+int epe_mii_readreg (device_t, int, int, uint16_t *);
+int epe_mii_writereg (device_t, int, int, uint16_t);
void epe_statchg (struct ifnet *);
void epe_tick (void *);
static int epe_ifioctl (struct ifnet *, u_long, void *);
@@ -452,21 +452,21 @@
}
int
-epe_mii_readreg(device_t self, int phy, int reg)
+epe_mii_readreg(device_t self, int phy, int reg, uint16_t *val)
{
- uint32_t d, v;
+ uint32_t d;
d = EPE_READ(SelfCtl);
EPE_WRITE(SelfCtl, d & ~SelfCtl_PSPRS); /* no preamble suppress */
EPE_WRITE(MIICmd, (MIICmd_READ | (phy << 5) | reg));
while(EPE_READ(MIISts) & MIISts_BUSY);
- v = EPE_READ(MIIData);
+ *val = EPE_READ(MIIData) & 0xffff;
EPE_WRITE(SelfCtl, d); /* restore old value */
- return v;
+ return 0;
}
-void
-epe_mii_writereg(device_t self, int phy, int reg, int val)
+int
+epe_mii_writereg(device_t self, int phy, int reg, uint16_t val)
{
uint32_t d;
@@ -476,6 +476,8 @@
EPE_WRITE(MIICmd, (MIICmd_WRITE | (phy << 5) | reg));
while(EPE_READ(MIISts) & MIISts_BUSY);
EPE_WRITE(SelfCtl, d); /* restore old value */
+
+ return 0;
}
diff -r 4c7b6ad3ab31 -r 6c2738fd7fce sys/arch/arm/gemini/gemini_gmac.c
--- a/sys/arch/arm/gemini/gemini_gmac.c Tue Jan 22 03:11:32 2019 +0000
+++ b/sys/arch/arm/gemini/gemini_gmac.c Tue Jan 22 03:42:24 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gemini_gmac.c,v 1.16 2018/06/26 06:47:57 msaitoh Exp $ */
+/* $NetBSD: gemini_gmac.c,v 1.17 2019/01/22 03:42:25 msaitoh Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -49,7 +49,7 @@
#include <sys/gpio.h>
-__KERNEL_RCSID(0, "$NetBSD: gemini_gmac.c,v 1.16 2018/06/26 06:47:57 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gemini_gmac.c,v 1.17 2019/01/22 03:42:25 msaitoh Exp $");
#define SWFREEQ_DESCS 256 /* one page worth */
#define HWFREEQ_DESCS 256 /* one page worth */
@@ -59,8 +59,8 @@
static int geminigmac_find(device_t, cfdata_t, const int *, void *);
static int geminigmac_print(void *aux, const char *name);
-static int geminigmac_mii_readreg(device_t, int, int);
-static void geminigmac_mii_writereg(device_t, int, int, int);
+static int geminigmac_mii_readreg(device_t, int, int, uint16_t *);
+static int geminigmac_mii_writereg(device_t, int, int, uint16_t);
#define GPIO_MDIO 21
#define GPIO_MDCLK 22
@@ -385,14 +385,15 @@
};
int
-geminigmac_mii_readreg(device_t dv, int phy, int reg)
+geminigmac_mii_readreg(device_t dv, int phy, int reg, uint16_t *val)
{
device_t parent = device_parent(dv);
struct gmac_softc * const sc = device_private(parent);
int rv;
mutex_enter(&sc->sc_mdiolock);
- rv = mii_bitbang_readreg(parent, &geminigmac_mii_bitbang_ops, phy, reg);
+ rv = mii_bitbang_readreg(parent, &geminigmac_mii_bitbang_ops, phy,
+ reg, val);
mutex_exit(&sc->sc_mdiolock);
//aprint_debug_dev(dv, "mii_readreg(%d, %d): %#x\n", phy, reg, rv);
@@ -400,8 +401,8 @@
return rv;
}
-void
-geminigmac_mii_writereg(device_t dv, int phy, int reg, int val)
+int
+geminigmac_mii_writereg(device_t dv, int phy, int reg, uint16_t val)
{
device_t parent = device_parent(dv);
struct gmac_softc * const sc = device_private(parent);
@@ -409,8 +410,11 @@
//aprint_debug_dev(dv, "mii_writereg(%d, %d, %#x)\n", phy, reg, val);
mutex_enter(&sc->sc_mdiolock);
- mii_bitbang_writereg(parent, &geminigmac_mii_bitbang_ops, phy, reg, val);
+ rv = mii_bitbang_writereg(parent, &geminigmac_mii_bitbang_ops, phy,
+ reg, val);
mutex_exit(&sc->sc_mdiolock);
+
+ return rv;
}
diff -r 4c7b6ad3ab31 -r 6c2738fd7fce sys/arch/arm/imx/if_enet.c
--- a/sys/arch/arm/imx/if_enet.c Tue Jan 22 03:11:32 2019 +0000
+++ b/sys/arch/arm/imx/if_enet.c Tue Jan 22 03:42:24 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_enet.c,v 1.16 2018/12/22 13:11:37 maxv Exp $ */
+/* $NetBSD: if_enet.c,v 1.17 2019/01/22 03:42:25 msaitoh Exp $ */
/*
* Copyright (c) 2014 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_enet.c,v 1.16 2018/12/22 13:11:37 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_enet.c,v 1.17 2019/01/22 03:42:25 msaitoh Exp $");
#include "vlan.h"
@@ -147,8 +147,8 @@
static void enet_watchdog(struct ifnet *);
static void enet_mediastatus(struct ifnet *, struct ifmediareq *);
-static int enet_miibus_readreg(device_t, int, int);
-static void enet_miibus_writereg(device_t, int, int, int);
+static int enet_miibus_readreg(device_t, int, int, uint16_t *);
+static int enet_miibus_writereg(device_t, int, int, uint16_t);
static void enet_miibus_statchg(struct ifnet *);
static void enet_gethwaddr(struct enet_softc *, uint8_t *);
@@ -1085,11 +1085,11 @@
* for MII
*/
static int
-enet_miibus_readreg(device_t dev, int phy, int reg)
+enet_miibus_readreg(device_t dev, int phy, int reg, uint16_t *val)
{
struct enet_softc *sc;
int timeout;
- uint32_t val, status;
+ uint32_t status;
sc = device_private(dev);
@@ -1110,16 +1110,15 @@
if (timeout <= 0) {
DEVICE_DPRINTF("MII read timeout: reg=0x%02x\n",
reg);
- val = -1;
- } else {
- val = ENET_REG_READ(sc, ENET_MMFR) & ENET_MMFR_DATAMASK;
- }
+ return ETIMEDOUT;
+ } else
+ *val = ENET_REG_READ(sc, ENET_MMFR) & ENET_MMFR_DATAMASK;
- return val;
+ return 0;
}
-static void
-enet_miibus_writereg(device_t dev, int phy, int reg, int val)
+static int
+enet_miibus_writereg(device_t dev, int phy, int reg, uint16_t val)
{
struct enet_softc *sc;
int timeout;
@@ -1141,9 +1140,11 @@
break;
}
if (timeout <= 0) {
- DEVICE_DPRINTF("MII write timeout: reg=0x%02x\n",
- reg);
+ DEVICE_DPRINTF("MII write timeout: reg=0x%02x\n", reg);
+ return ETIMEDOUT;
}
+
+ return 0;
}
static void
diff -r 4c7b6ad3ab31 -r 6c2738fd7fce sys/arch/arm/omap/if_cpsw.c
--- a/sys/arch/arm/omap/if_cpsw.c Tue Jan 22 03:11:32 2019 +0000
+++ b/sys/arch/arm/omap/if_cpsw.c Tue Jan 22 03:42:24 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_cpsw.c,v 1.21 2018/06/26 06:47:57 msaitoh Exp $ */
+/* $NetBSD: if_cpsw.c,v 1.22 2019/01/22 03:42:25 msaitoh Exp $ */
/*
* Copyright (c) 2013 Jonathan A. Kollasch
@@ -53,7 +53,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: if_cpsw.c,v 1.21 2018/06/26 06:47:57 msaitoh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: if_cpsw.c,v 1.22 2019/01/22 03:42:25 msaitoh Exp $");
#include <sys/param.h>
Home |
Main Index |
Thread Index |
Old Index