Module Name: src
Committed By: matt
Date: Sun Jul 22 23:46:11 UTC 2012
Modified Files:
src/sys/arch/evbppc/conf: MPC8536DS MPC8548CDS P2020DS P2020RDB RB800
TWRP1025
src/sys/arch/evbppc/mpc85xx: machdep.c
src/sys/arch/powerpc/booke/dev: pq3etsec.c
src/sys/arch/powerpc/conf: files.booke
Log Message:
Split mdio/mii access into its own "device" and update accordingly.
(on the P1025 the mdio functionality is separate from the etsec functions).
Provide locking for mii access.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/evbppc/conf/MPC8536DS
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/evbppc/conf/MPC8548CDS
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/evbppc/conf/P2020DS
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/evbppc/conf/P2020RDB
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/evbppc/conf/RB800
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/evbppc/conf/TWRP1025
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/evbppc/mpc85xx/machdep.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/powerpc/booke/dev/pq3etsec.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/powerpc/conf/files.booke
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/evbppc/conf/MPC8536DS
diff -u src/sys/arch/evbppc/conf/MPC8536DS:1.10 src/sys/arch/evbppc/conf/MPC8536DS:1.11
--- src/sys/arch/evbppc/conf/MPC8536DS:1.10 Sun Dec 18 05:49:26 2011
+++ src/sys/arch/evbppc/conf/MPC8536DS Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-# $NetBSD: MPC8536DS,v 1.10 2011/12/18 05:49:26 dholland Exp $
+# $NetBSD: MPC8536DS,v 1.11 2012/07/22 23:46:10 matt Exp $
#
# MPC8536DS -- everything that's currently supported
#
@@ -7,7 +7,7 @@ include "arch/evbppc/conf/std.mpc85xx"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-ident "MPC8536DS-$Revision: 1.10 $"
+ident "MPC8536DS-$Revision: 1.11 $"
maxusers 32
@@ -163,8 +163,9 @@ com* at duart? port ?
options CONSPEED=9600
options CONSADDR="DUART1_BASE"
-tsec0 at cpunode? flags 0x002 # Enhanced 3-Speed Ethernet Controller
-tsec1 at cpunode? flags 0x101 # Enhanced 3-Speed Ethernet Controller
+tsec0 at cpunode? phy 1 # Enhanced 3-Speed Ethernet Controller
+mdio0 at tsec0
+tsec1 at cpunode? mdio 0 phy 0 # Enhanced 3-Speed Ethernet Controller
ciphy* at mii? # Cicada PHY
ukphy* at mii?
#options ETSEC_EVENT_COUNTERS
Index: src/sys/arch/evbppc/conf/MPC8548CDS
diff -u src/sys/arch/evbppc/conf/MPC8548CDS:1.9 src/sys/arch/evbppc/conf/MPC8548CDS:1.10
--- src/sys/arch/evbppc/conf/MPC8548CDS:1.9 Sun Dec 18 05:49:26 2011
+++ src/sys/arch/evbppc/conf/MPC8548CDS Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-# $NetBSD: MPC8548CDS,v 1.9 2011/12/18 05:49:26 dholland Exp $
+# $NetBSD: MPC8548CDS,v 1.10 2012/07/22 23:46:10 matt Exp $
#
# MPC8548CDS -- everything that's currently supported
#
@@ -7,7 +7,7 @@ include "arch/evbppc/conf/std.mpc85xx"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-ident "MPC8548CDS-$Revision: 1.9 $"
+ident "MPC8548CDS-$Revision: 1.10 $"
maxusers 32
@@ -157,8 +157,9 @@ duart* at cpunode?
com* at duart? port ?
options CONSPEED=115200
-tsec0 at cpunode? flags 1 # Enhanced 3-Speed Ethernet Controller
-tsec1 at cpunode? flags 1 # Enhanced 3-Speed Ethernet Controller
+tsec0 at cpunode? phy 0 # Enhanced 3-Speed Ethernet Controller
+mdio0 at tsec0
+tsec1 at cpunode? mdio 0 phy 1 # Enhanced 3-Speed Ethernet Controller
makphy* at mii? # Marvell PHY
ukphy* at mii?
#options ETSEC_EVENT_COUNTERS
Index: src/sys/arch/evbppc/conf/P2020DS
diff -u src/sys/arch/evbppc/conf/P2020DS:1.11 src/sys/arch/evbppc/conf/P2020DS:1.12
--- src/sys/arch/evbppc/conf/P2020DS:1.11 Sun Dec 18 05:49:26 2011
+++ src/sys/arch/evbppc/conf/P2020DS Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-# $NetBSD: P2020DS,v 1.11 2011/12/18 05:49:26 dholland Exp $
+# $NetBSD: P2020DS,v 1.12 2012/07/22 23:46:10 matt Exp $
#
# P2020DS -- everything that's currently supported
#
@@ -8,7 +8,7 @@ include "arch/evbppc/conf/std.mpc85xx"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-ident "P2020DS-$Revision: 1.11 $"
+ident "P2020DS-$Revision: 1.12 $"
maxusers 32
@@ -20,13 +20,16 @@ options PIXIS
#options SYS_CLK=100000000
#options HZ=1000
#options MEMSIZE=0x40000000
+#options PMAP_MINIMALTLB
+#makeoptions KERNLDSCRIPT="${POWERPC}/conf/kern-mb.ldscript"
makeoptions NEED_BINARY="yes"
makeoptions NEED_UBOOTIMAGE="yes"
-#options INSECURE # disable kernel security levels
+options INSECURE # disable kernel security levels
#options NTP # NTP phase/frequency locked loop
options KTRACE # system call tracing via ktrace(1)
+options MODULAR # new style module(7) framework
options SYSVMSG # System V message queues
options SYSVSEM # System V semaphores
@@ -43,7 +46,7 @@ options DEBUG # expensive debugging ch
options DDB # in-kernel debugger
options DDB_HISTORY_SIZE=512 # enable history editing in DDB
options TRAP_PANICWAIT
-options SYMTAB_SPACE=410000 # size for embedded symbol table
+options SYMTAB_SPACE=425000 # size for embedded symbol table
makeoptions DEBUG="-g" # compile full symbol table
@@ -78,7 +81,7 @@ file-system TMPFS # efficient memory f
file-system KERNFS # /kern
file-system NULLFS # loopback file system
#file-system OVERLAY # overlay file system
-#file-system PUFFS # Userspace file systems (e.g. ntfs-3g & sshfs)
+file-system PUFFS # Userspace file systems (e.g. ntfs-3g & sshfs)
file-system PROCFS # /proc
#file-system UMAPFS # NULLFS + uid and gid remapping
#file-system UNION # union file system
@@ -102,7 +105,7 @@ options INET # IP + ICMP + TCP + UDP
options INET_CSUM_COUNTERS
options TCP_CSUM_COUNTERS
options UDP_CSUM_COUNTERS
-#options INET6 # IPV6
+options INET6 # IPV6
#options IPSEC # IP security
#options IPSEC_ESP # IP security (encryption part; define w/IPSEC)
#options IPSEC_NAT_T # IPsec NAT traversal (NAT-T)
@@ -167,9 +170,10 @@ com* at duart? port ?
options CONSPEED=115200
options CONSADDR="DUART1_BASE"
-tsec0 at cpunode? flags 0x001 # Enhanced 3-Speed Ethernet Controller
-tsec1 at cpunode? flags 0x102 # Enhanced 3-Speed Ethernet Controller
-tsec2 at cpunode? flags 0x103 # Enhanced 3-Speed Ethernet Controller
+tsec0 at cpunode? phy 0 # Enhanced 3-Speed Ethernet Controller
+mdio0 at tsec0
+tsec1 at cpunode? mdio 0 phy 1 # Enhanced 3-Speed Ethernet Controller
+tsec2 at cpunode? mdio 0 phy 2 # Enhanced 3-Speed Ethernet Controller
options ETSEC_EVENT_COUNTERS
ehci* at cpunode? # usb
@@ -177,7 +181,7 @@ ehci* at cpunode? # usb
diic* at cpunode? # i2c bus
iic* at diic?
spdmem* at iic0 addr 0x51 # DDR
-dsrtc* at iic1 addr 0x68 # RTC
+dsrtc* at iic1 addr 0x68 flags 3232 # RTC - DS3232
pq3pcie* at cpunode? # PCI-Express controller
pq3pci* at cpunode? # PCI(X)
@@ -233,3 +237,5 @@ pseudo-device ksyms # /dev/ksyms
pseudo-device pty # pseudo-terminals
pseudo-device kttcp # kernel ttcp
pseudo-device vlan # 802.1Q VLANs
+pseudo-device putter # for puffs and pud
+pseudo-device vnd # disk-like interface to files
Index: src/sys/arch/evbppc/conf/P2020RDB
diff -u src/sys/arch/evbppc/conf/P2020RDB:1.12 src/sys/arch/evbppc/conf/P2020RDB:1.13
--- src/sys/arch/evbppc/conf/P2020RDB:1.12 Sun Dec 18 05:49:26 2011
+++ src/sys/arch/evbppc/conf/P2020RDB Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-# $NetBSD: P2020RDB,v 1.12 2011/12/18 05:49:26 dholland Exp $
+# $NetBSD: P2020RDB,v 1.13 2012/07/22 23:46:10 matt Exp $
#
# P2020RBD -- everything that's currently supported
#
@@ -7,7 +7,7 @@ include "arch/evbppc/conf/std.mpc85xx"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-ident "P2020RBD-$Revision: 1.12 $"
+ident "P2020RBD-$Revision: 1.13 $"
maxusers 32
@@ -21,6 +21,8 @@ options P2020
options SYS_CLK=100000000
#options HZ=1000
+#options SDHC_DEBUG
+
#options INSECURE # disable kernel security levels
#options NTP # NTP phase/frequency locked loop
options KTRACE # system call tracing via ktrace(1)
@@ -165,15 +167,16 @@ duart* at cpunode?
com* at duart? port ?
options CONSADDR="DUART1_BASE"
-tsec0 at cpunode? flags 0x021 # Enhanced 3-Speed Ethernet Controller
-tsec1 at cpunode? flags 0x101 # Enhanced 3-Speed Ethernet Controller
-tsec2 at cpunode? flags 0x102 # Enhanced 3-Speed Ethernet Controller
+tsec0 at cpunode? phy 32 # Enhanced 3-Speed Ethernet Controller
+mdio0 at tsec0
+tsec1 at cpunode? mdio 0 phy 0 # Enhanced 3-Speed Ethernet Controller
+tsec2 at cpunode? mdio 0 phy 1 # Enhanced 3-Speed Ethernet Controller
ukphy* at mii?
#options ETSEC_EVENT_COUNTERS
diic* at cpunode? # i2c bus
iic* at diic?
-dsrtc* at iic1 addr 0x68 # RTC
+dsrtc* at iic1 addr 0x68 flags 1339 # RTC DS1339
pq3pcie* at cpunode? # PCI-Express controller
pq3pci* at cpunode? # PCI(X)
@@ -194,9 +197,9 @@ umass* at uhub? port ?
scsibus* at umass? channel ?
sd* at scsibus? target ? lun ?
-#sdhc* at cpunode? # sdmmc
-#sdmmc* at sdhc? # SD/MMC bus
-#ld* at sdmmc?
+sdhc* at cpunode? # sdmmc
+sdmmc* at sdhc? # SD/MMC bus
+ld* at sdmmc?
#siisata* at pci? dev ? function ?
#atabus* at siisata? channel ?
Index: src/sys/arch/evbppc/conf/RB800
diff -u src/sys/arch/evbppc/conf/RB800:1.16 src/sys/arch/evbppc/conf/RB800:1.17
--- src/sys/arch/evbppc/conf/RB800:1.16 Thu Jan 19 23:37:23 2012
+++ src/sys/arch/evbppc/conf/RB800 Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-# $NetBSD: RB800,v 1.16 2012/01/19 23:37:23 matt Exp $
+# $NetBSD: RB800,v 1.17 2012/07/22 23:46:10 matt Exp $
#
# RB800 -- everything that's currently supported
#
@@ -7,7 +7,7 @@ include "arch/evbppc/conf/std.mpc85xx"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-ident "RB800-$Revision: 1.16 $"
+ident "RB800-$Revision: 1.17 $"
maxusers 32
@@ -169,8 +169,9 @@ com* at duart? port ?
options CONSPEED=115200
options CONSADDR="DUART1_BASE"
-tsec0 at cpunode? flags 0x003 # 3-Speed Ethernet Controller (phy 2)
-tsec1 at cpunode? flags 0x102 # 3-Speed Ethernet Controller (phy 1)
+tsec0 at cpunode? phy 2 # 3-Speed Ethernet Controller (phy 2)
+mdio0 at tsec0
+tsec1 at cpunode? mdio 0 phy 1 # 3-Speed Ethernet Controller (phy 1)
atphy* at mii? # Attansic PHY
ukphy* at mii?
#options TSEC_EVENT_COUNTERS
Index: src/sys/arch/evbppc/conf/TWRP1025
diff -u src/sys/arch/evbppc/conf/TWRP1025:1.4 src/sys/arch/evbppc/conf/TWRP1025:1.5
--- src/sys/arch/evbppc/conf/TWRP1025:1.4 Wed Jul 18 19:39:54 2012
+++ src/sys/arch/evbppc/conf/TWRP1025 Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-# $NetBSD: TWRP1025,v 1.4 2012/07/18 19:39:54 matt Exp $
+# $NetBSD: TWRP1025,v 1.5 2012/07/22 23:46:10 matt Exp $
#
# TWRP1025 -- everything that's currently supported
#
@@ -7,7 +7,7 @@ include "arch/evbppc/conf/std.mpc85xx"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-ident "TWRP1025-$Revision: 1.4 $"
+ident "TWRP1025-$Revision: 1.5 $"
maxusers 32
@@ -21,8 +21,6 @@ options P1025
options SYS_CLK=66666667
#options HZ=1000
-#options SDHC_DEBUG
-
#options INSECURE # disable kernel security levels
#options NTP # NTP phase/frequency locked loop
options KTRACE # system call tracing via ktrace(1)
@@ -171,8 +169,10 @@ duart* at cpunode?
com* at duart? port ?
options CONSADDR="DUART1_BASE"
-tsec0 at cpunode? instance 1 flags 0x003 # Enhanced 3-Speed Ethernet Controller
-tsec1 at cpunode? instance 3 flags 0x102 # Enhanced 3-Speed Ethernet Controller
+mdio0 at cpunode? instance 1
+tsec0 at cpunode? instance 1 mdio 0 phy 2 # Enhanced 3-Speed Ethernet Controller
+tsec1 at cpunode? instance 3 mdio 0 phy 1 # Enhanced 3-Speed Ethernet Controller
+atphy* at mii?
ukphy* at mii?
#options ETSEC_EVENT_COUNTERS
@@ -198,6 +198,8 @@ umass* at uhub? port ?
scsibus* at umass? channel ?
sd* at scsibus? target ? lun ?
+#options SDHC_DEBUG
+#options SDMMC_DEBUG
sdhc* at cpunode? # sdmmc
sdmmc* at sdhc? # SD/MMC bus
ld* at sdmmc?
Index: src/sys/arch/evbppc/mpc85xx/machdep.c
diff -u src/sys/arch/evbppc/mpc85xx/machdep.c:1.27 src/sys/arch/evbppc/mpc85xx/machdep.c:1.28
--- src/sys/arch/evbppc/mpc85xx/machdep.c:1.27 Wed Jul 18 19:38:26 2012
+++ src/sys/arch/evbppc/mpc85xx/machdep.c Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.27 2012/07/18 19:38:26 matt Exp $ */
+/* $NetBSD: machdep.c,v 1.28 2012/07/22 23:46:10 matt Exp $ */
/*-
* Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -224,6 +224,10 @@ static const struct cpunode_locators mpc
1 + ilog2(DEVDISR_TSEC1),
{ 0xffff, SVR_P1025v1 >> 16 } },
#if defined(P1025)
+ { "mdio", ETSEC1_BASE, ETSEC_SIZE, 1,
+ 0, { },
+ 1 + ilog2(DEVDISR_TSEC1),
+ { SVR_P1025v1 >> 16 } },
{ "tsec", ETSEC1_G0_BASE, ETSEC_SIZE, 1,
3, { ISOURCE_ETSEC1_TX, ISOURCE_ETSEC1_RX, ISOURCE_ETSEC1_ERR },
1 + ilog2(DEVDISR_TSEC1),
@@ -246,6 +250,10 @@ static const struct cpunode_locators mpc
SVR_P1025v1 >> 16 } },
#endif
#if defined(P1025)
+ { "mdio", ETSEC2_BASE, ETSEC_SIZE, 2,
+ 0, { },
+ 1 + ilog2(DEVDISR_TSEC2),
+ { SVR_P1025v1 >> 16 } },
{ "tsec", ETSEC2_G0_BASE, ETSEC_SIZE, 2,
3, { ISOURCE_ETSEC2_TX, ISOURCE_ETSEC2_RX, ISOURCE_ETSEC2_ERR },
1 + ilog2(DEVDISR_TSEC2),
@@ -272,6 +280,10 @@ static const struct cpunode_locators mpc
SVR_P2020v2 >> 16 } },
#endif
#if defined(P1025)
+ { "mdio", ETSEC3_BASE, ETSEC_SIZE, 3,
+ 0, { },
+ 1 + ilog2(DEVDISR_TSEC3),
+ { SVR_P1025v1 >> 16 } },
{ "tsec", ETSEC3_G0_BASE, ETSEC_SIZE, 3,
3, { ISOURCE_ETSEC3_TX, ISOURCE_ETSEC3_RX, ISOURCE_ETSEC3_ERR },
1 + ilog2(DEVDISR_TSEC3),
Index: src/sys/arch/powerpc/booke/dev/pq3etsec.c
diff -u src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.15 src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.16
--- src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.15 Tue Jul 17 01:36:13 2012
+++ src/sys/arch/powerpc/booke/dev/pq3etsec.c Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: pq3etsec.c,v 1.15 2012/07/17 01:36:13 matt Exp $ */
+/* $NetBSD: pq3etsec.c,v 1.16 2012/07/22 23:46:10 matt Exp $ */
/*-
* Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -39,7 +39,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.15 2012/07/17 01:36:13 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.16 2012/07/22 23:46:10 matt Exp $");
#include <sys/param.h>
#include <sys/cpu.h>
@@ -61,8 +61,6 @@ __KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v
#include <dev/mii/miivar.h>
-#include "ioconf.h"
-
#include <net/bpf.h>
#ifdef INET
@@ -166,6 +164,7 @@ struct pq3etsec_mapcache {
struct pq3etsec_softc {
device_t sc_dev;
+ device_t sc_mdio_dev;
struct ethercom sc_ec;
#define sc_if sc_ec.ec_if
struct mii_data sc_mii;
@@ -232,9 +231,21 @@ struct pq3etsec_softc {
struct pq3etsec_mapcache *sc_tx_mapcache;
};
+struct pq3mdio_softc {
+ device_t mdio_dev;
+
+ kmutex_t *mdio_lock;
+
+ bus_space_tag_t mdio_bst;
+ bus_space_handle_t mdio_bsh;
+};
+
static int pq3etsec_match(device_t, cfdata_t, void *);
static void pq3etsec_attach(device_t, device_t, void *);
+static int pq3mdio_match(device_t, cfdata_t, void *);
+static void pq3mdio_attach(device_t, device_t, void *);
+
static void pq3etsec_ifstart(struct ifnet *);
static void pq3etsec_ifwatchdog(struct ifnet *);
static int pq3etsec_ifinit(struct ifnet *);
@@ -283,14 +294,22 @@ static void pq3etsec_soft_intr(void *);
CFATTACH_DECL_NEW(pq3etsec, sizeof(struct pq3etsec_softc),
pq3etsec_match, pq3etsec_attach, NULL, NULL);
-static int
-pq3etsec_match(device_t parent, cfdata_t cf, void *aux)
-{
+CFATTACH_DECL_NEW(pq3mdio_tsec, sizeof(struct pq3mdio_softc),
+ pq3mdio_match, pq3mdio_attach, NULL, NULL);
- if (!e500_cpunode_submatch(parent, cf, cf->cf_name, aux))
- return 0;
+CFATTACH_DECL_NEW(pq3mdio_cpunode, sizeof(struct pq3mdio_softc),
+ pq3mdio_match, pq3mdio_attach, NULL, NULL);
- return 1;
+static inline uint32_t
+etsec_mdio_read(struct pq3mdio_softc *mdio, bus_size_t off)
+{
+ return bus_space_read_4(mdio->mdio_bst, mdio->mdio_bsh, off);
+}
+
+static inline void
+etsec_mdio_write(struct pq3mdio_softc *mdio, bus_size_t off, uint32_t data)
+{
+ bus_space_write_4(mdio->mdio_bst, mdio->mdio_bsh, off, data);
}
static inline uint32_t
@@ -299,98 +318,145 @@ etsec_read(struct pq3etsec_softc *sc, bu
return bus_space_read_4(sc->sc_bst, sc->sc_bsh, off);
}
-static inline void
-etsec_write(struct pq3etsec_softc *sc, bus_size_t off, uint32_t data)
+static int
+pq3mdio_find(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
{
- bus_space_write_4(sc->sc_bst, sc->sc_bsh, off, data);
+ return strcmp(cf->cf_name, "mdio") == 0;
}
-static inline uint32_t
-etsec_mdio_read(struct pq3etsec_softc *sc, bus_size_t off)
+static int
+pq3mdio_match(device_t parent, cfdata_t cf, void *aux)
{
- return bus_space_read_4(sc->sc_bst, sc->sc_mdio_bsh, off);
+ const uint16_t svr = (mfspr(SPR_SVR) & ~0x80000) >> 16;
+ const bool p1025_p = (svr == (SVR_P1025v1 >> 16)
+ || svr == (SVR_P1016v1 >> 16));
+
+ if (device_is_a(parent, "cpunode")) {
+ if (!p1025_p
+ || !e500_cpunode_submatch(parent, cf, cf->cf_name, aux))
+ return 0;
+
+ return 1;
+ }
+
+ if (device_is_a(parent, "tsec")) {
+ if (p1025_p
+ || !e500_cpunode_submatch(parent, cf, cf->cf_name, aux))
+ return 0;
+
+ return 1;
+ }
+
+ return 0;
}
-static inline void
-etsec_mdio_write(struct pq3etsec_softc *sc, bus_size_t off, uint32_t data)
+static void
+pq3mdio_attach(device_t parent, device_t self, void *aux)
{
- bus_space_write_4(sc->sc_bst, sc->sc_mdio_bsh, off, data);
+ struct pq3mdio_softc * const mdio = device_private(self);
+ struct cpunode_attach_args * const cna = aux;
+ struct cpunode_locators * const cnl = &cna->cna_locs;
+
+ mdio->mdio_dev = self;
+ mdio->mdio_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET);
+
+ if (device_is_a(parent, "cpunode")) {
+ struct cpunode_softc * const psc = device_private(parent);
+ psc->sc_children |= cna->cna_childmask;
+
+ mdio->mdio_bst = cna->cna_memt;
+ if (bus_space_map(mdio->mdio_bst, cnl->cnl_addr,
+ cnl->cnl_size, 0, &mdio->mdio_bsh) != 0) {
+ aprint_error(": error mapping registers @ %#x\n",
+ cnl->cnl_addr);
+ return;
+ }
+ } else {
+ struct pq3etsec_softc * const sc = device_private(parent);
+
+ KASSERT(device_is_a(parent, "tsec"));
+ KASSERTMSG(cnl->cnl_addr == ETSEC1_BASE
+ || cnl->cnl_addr == ETSEC2_BASE
+ || cnl->cnl_addr == ETSEC3_BASE
+ || cnl->cnl_addr == ETSEC4_BASE,
+ "unknown tsec addr %x", cnl->cnl_addr);
+
+ mdio->mdio_bst = sc->sc_bst;
+ mdio->mdio_bsh = sc->sc_bsh;
+ }
+
+ aprint_normal("\n");
}
static int
-pq3etsec_mii_readreg(device_t self, int phy, int reg)
+pq3mdio_mii_readreg(device_t self, int phy, int reg)
{
- struct pq3etsec_softc * const sc = device_private(self);
- uint32_t miimcom = etsec_read(sc, MIIMCOM);
+ struct pq3mdio_softc * const mdio = device_private(self);
+ uint32_t miimcom = etsec_mdio_read(mdio, MIIMCOM);
-// int s = splnet();
+ mutex_enter(mdio->mdio_lock);
- etsec_mdio_write(sc, MIIMADD,
+ etsec_mdio_write(mdio, MIIMADD,
__SHIFTIN(phy, MIIMADD_PHY) | __SHIFTIN(reg, MIIMADD_REG));
- etsec_write(sc, IEVENT, IEVENT_MMRD);
- etsec_mdio_write(sc, MIIMCOM, 0); /* clear any past bits */
- etsec_mdio_write(sc, MIIMCOM, MIIMCOM_READ);
-#if 0
- sc->sc_imask |= IEVENT_MMRD;
- etsec_write(sc, IMASK, sc->sc_imask);
-#endif
+ etsec_mdio_write(mdio, MIIMCOM, 0); /* clear any past bits */
+ etsec_mdio_write(mdio, MIIMCOM, MIIMCOM_READ);
- while (etsec_mdio_read(sc, MIIMIND) != 0) {
+ while (etsec_mdio_read(mdio, MIIMIND) != 0) {
delay(1);
}
- int data = etsec_mdio_read(sc, MIIMSTAT);
+ int data = etsec_mdio_read(mdio, MIIMSTAT);
if (miimcom == MIIMCOM_SCAN)
- etsec_mdio_write(sc, MIIMCOM, miimcom);
+ etsec_mdio_write(mdio, MIIMCOM, miimcom);
#if 0
- aprint_normal_dev(sc->sc_dev, "%s: phy %d reg %d: %#x\n",
+ aprint_normal_dev(mdio->mdio_dev, "%s: phy %d reg %d: %#x\n",
__func__, phy, reg, data);
#endif
- etsec_write(sc, IEVENT, IEVENT_MMRD);
-// splx(s);
+ mutex_exit(mdio->mdio_lock);
return data;
}
static void
-pq3etsec_mii_writereg(device_t self, int phy, int reg, int data)
+pq3mdio_mii_writereg(device_t self, int phy, int reg, int data)
{
- struct pq3etsec_softc * const sc = device_private(self);
- uint32_t miimcom = etsec_mdio_read(sc, MIIMCOM);
+ struct pq3mdio_softc * const mdio = device_private(self);
+ uint32_t miimcom = etsec_mdio_read(mdio, MIIMCOM);
#if 0
- aprint_normal_dev(sc->sc_dev, "%s: phy %d reg %d: %#x\n",
+ aprint_normal_dev(mdio->mdio_dev, "%s: phy %d reg %d: %#x\n",
__func__, phy, reg, data);
#endif
-// int s = splnet();
- etsec_write(sc, IEVENT, IEVENT_MMWR);
- etsec_mdio_write(sc, MIIMADD,
- __SHIFTIN(phy, MIIMADD_PHY) | __SHIFTIN(reg, MIIMADD_REG));
- etsec_mdio_write(sc, MIIMCOM, 0); /* clear any past bits */
- etsec_mdio_write(sc, MIIMCON, data);
+ mutex_enter(mdio->mdio_lock);
-#if 0
- sc->sc_imask |= IEVENT_MMWR;
- etsec_write(sc, IMASK, sc->sc_imask);
-#endif
+ etsec_mdio_write(mdio, MIIMADD,
+ __SHIFTIN(phy, MIIMADD_PHY) | __SHIFTIN(reg, MIIMADD_REG));
+ etsec_mdio_write(mdio, MIIMCOM, 0); /* clear any past bits */
+ etsec_mdio_write(mdio, MIIMCON, data);
int timo = 1000; /* 1ms */
- while ((etsec_mdio_read(sc, MIIMIND) & MIIMIND_BUSY) && --timo > 0) {
+ while ((etsec_mdio_read(mdio, MIIMIND) & MIIMIND_BUSY) && --timo > 0) {
delay(1);
}
if (miimcom == MIIMCOM_SCAN)
- etsec_mdio_write(sc, MIIMCOM, miimcom);
- etsec_write(sc, IEVENT, IEVENT_MMWR);
-// splx(s);
+ etsec_mdio_write(mdio, MIIMCOM, miimcom);
+
+ mutex_exit(mdio->mdio_lock);
+}
+
+static inline void
+etsec_write(struct pq3etsec_softc *sc, bus_size_t off, uint32_t data)
+{
+ bus_space_write_4(sc->sc_bst, sc->sc_bsh, off, data);
}
static void
-pq3etsec_mii_statchg(device_t self)
+pq3etsec_mii_statchg(struct ifnet *ifp)
{
- struct pq3etsec_softc * const sc = device_private(self);
+ struct pq3etsec_softc * const sc = ifp->if_softc;
struct mii_data * const mii = &sc->sc_mii;
uint32_t maccfg1 = sc->sc_maccfg1;
@@ -467,48 +533,14 @@ pq3etsec_mediachange(struct ifnet *ifp)
}
#endif
-
-static const struct {
- bus_addr_t reg_base;
- bus_addr_t mdio_base;
-} etsec_mdio_map[] = {
- { ETSEC1_BASE, ETSEC1_BASE },
- { ETSEC2_BASE, ETSEC2_BASE },
- { ETSEC3_BASE, ETSEC3_BASE },
- { ETSEC4_BASE, ETSEC4_BASE },
-#if defined(P1025)
- { ETSEC1_G0_BASE, ETSEC1_BASE },
- { ETSEC1_G1_BASE, ETSEC1_BASE },
- { ETSEC2_G0_BASE, ETSEC2_BASE },
- { ETSEC2_G1_BASE, ETSEC2_BASE },
- { ETSEC3_G0_BASE, ETSEC3_BASE },
- { ETSEC3_G1_BASE, ETSEC3_BASE },
-#endif
-};
-
-static bool
-pq3etsec_mdio_map(struct pq3etsec_softc *sc, bus_addr_t reg_base,
- bus_addr_t *mdio_basep)
+static int
+pq3etsec_match(device_t parent, cfdata_t cf, void *aux)
{
- *mdio_basep = 0;
- for (size_t i = 0; i < __arraycount(etsec_mdio_map); i++) {
- if (etsec_mdio_map[i].reg_base == reg_base) {
- bus_addr_t mdio_base = etsec_mdio_map[i].mdio_base;
- if (mdio_base == reg_base) {
- sc->sc_mdio_bsh = sc->sc_bsh;
- return true;
- }
- if (!bus_space_map(sc->sc_bst,
- mdio_base,
- ETSEC_SIZE, 0, &sc->sc_mdio_bsh)) {
- return true;
- }
- *mdio_basep = mdio_base;
- break;
- }
- }
- return false;
+ if (!e500_cpunode_submatch(parent, cf, cf->cf_name, aux))
+ return 0;
+
+ return 1;
}
static void
@@ -520,7 +552,6 @@ pq3etsec_attach(device_t parent, device_
struct cpunode_locators * const cnl = &cna->cna_locs;
cfdata_t cf = device_cfdata(self);
int error;
- bus_addr_t mdio_base;
psc->sc_children |= cna->cna_childmask;
sc->sc_dev = self;
@@ -528,15 +559,18 @@ pq3etsec_attach(device_t parent, device_
sc->sc_dmat = &booke_bus_dma_tag;
/*
- * If we have a common MDIO bus, if all off instance 1.
+ * Pull out the mdio bus and phy we are supposed to use.
*/
- device_t miiself = (cf->cf_flags & 0x100) ? tsec_cd.cd_devs[0] : self;
+ const int mdio = cf->cf_loc[CPUNODECF_MDIO];
+ const int phy = cf->cf_loc[CPUNODECF_PHY];
+ if (mdio != CPUNODECF_MDIO_DEFAULT)
+ aprint_normal(" mdio %d", mdio);
/*
* See if the phy is in the config file...
*/
- if (cf->cf_flags & 0x3f) {
- sc->sc_phy_addr = (cf->cf_flags & 0x3f) - 1;
+ if (phy != CPUNODECF_PHY_DEFAULT) {
+ sc->sc_phy_addr = phy;
} else {
unsigned char prop_name[20];
snprintf(prop_name, sizeof(prop_name), "tsec%u-phy-addr",
@@ -553,12 +587,6 @@ pq3etsec_attach(device_t parent, device_
return;
}
- if (!pq3etsec_mdio_map(sc, cnl->cnl_addr, &mdio_base)) {
- aprint_error(": error mapping mdio registers @ %#x\n",
- mdio_base);
- return;
- }
-
/*
* Assume firmware has aready set the mac address and fetch it
* before we reinit it.
@@ -655,7 +683,23 @@ pq3etsec_attach(device_t parent, device_
return;
}
- aprint_normal("\n");
+ /*
+ * If there was no MDIO
+ */
+ if (mdio == CPUNODECF_MDIO_DEFAULT) {
+ aprint_normal("\n");
+ cfdata_t mdio_cf = config_search_ia(pq3mdio_find, self, NULL, cna);
+ if (mdio_cf != NULL) {
+ sc->sc_mdio_dev = config_attach(self, mdio_cf, cna, NULL);
+ }
+ } else {
+ sc->sc_mdio_dev = device_find_by_driver_unit("mdio", mdio);
+ if (sc->sc_mdio_dev == NULL) {
+ aprint_error(": failed to locate mdio device\n");
+ return;
+ }
+ aprint_normal("\n");
+ }
etsec_write(sc, ATTR, ATTR_DEFAULT);
etsec_write(sc, ATTRELI, ATTRELI_DEFAULT);
@@ -675,15 +719,15 @@ pq3etsec_attach(device_t parent, device_
ec->ec_mii = &sc->sc_mii;
sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = pq3etsec_mii_readreg;
- sc->sc_mii.mii_writereg = pq3etsec_mii_writereg;
+ sc->sc_mii.mii_readreg = pq3mdio_mii_readreg;
+ sc->sc_mii.mii_writereg = pq3mdio_mii_writereg;
sc->sc_mii.mii_statchg = pq3etsec_mii_statchg;
ifmedia_init(&sc->sc_mii.mii_media, 0, ether_mediachange,
ether_mediastatus);
- if (sc->sc_phy_addr < 32) {
- mii_attach(miiself, &sc->sc_mii, 0xffffffff,
+ if (sc->sc_mdio_dev != NULL && sc->sc_phy_addr < 32) {
+ mii_attach(sc->sc_mdio_dev, &sc->sc_mii, 0xffffffff,
sc->sc_phy_addr, MII_OFFSET_ANY, MIIF_DOPAUSE);
if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
Index: src/sys/arch/powerpc/conf/files.booke
diff -u src/sys/arch/powerpc/conf/files.booke:1.6 src/sys/arch/powerpc/conf/files.booke:1.7
--- src/sys/arch/powerpc/conf/files.booke:1.6 Tue Aug 2 00:27:42 2011
+++ src/sys/arch/powerpc/conf/files.booke Sun Jul 22 23:46:10 2012
@@ -1,4 +1,4 @@
-# $NetBSD: files.booke,v 1.6 2011/08/02 00:27:42 matt Exp $
+# $NetBSD: files.booke,v 1.7 2012/07/22 23:46:10 matt Exp $
#
# PPC BookE specific configuration info
@@ -12,7 +12,7 @@ attach mainbus at root
# Processor Local Bus
#device cpunode {[device = -1], [core = -1]}: gpiobus
-device cpunode {[instance = -1]}: gpiobus
+device cpunode {[instance = -1], [mdio = -1], [phy = -1]}: gpiobus
attach cpunode at mainbus
file arch/powerpc/booke/dev/cpunode.c cpunode
file arch/powerpc/booke/dev/pq3gpio.c cpunode & gpio
@@ -36,9 +36,14 @@ attach diic at cpunode with pq3diic
file arch/powerpc/booke/dev/pq3diic.c pq3diic
# On-chip ethernet device(s)
-device tsec: ether, ifnet, arp, mii
+device tsec { }: ether, ifnet, arp
attach tsec at cpunode with pq3etsec
-file arch/powerpc/booke/dev/pq3etsec.c pq3etsec
+
+device mdio: mii
+attach mdio at tsec with pq3mdio_tsec
+attach mdio at cpunode with pq3mdio_cpunode
+
+file arch/powerpc/booke/dev/pq3etsec.c pq3etsec | mdio
# On-chip EHCI device(s)
attach ehci at cpunode with pq3ehci