PERFORCE change 175719 for review

Rafal Jaworowski raj at FreeBSD.org
Mon Mar 15 22:43:32 UTC 2010


http://p4web.freebsd.org/chv.cgi?CH=175719

Change 175719 by raj at raj_fdt on 2010/03/15 22:42:38

	Extend mge(4) to retrieve PHY address from the device tree (instead of
	hard coded assumptions). Get rid of MII_ADDR_BASE option.
	
	Update DTS files for DB-88F6281 and SHEEVAPLUG accordingly.

Affected files ...

.. //depot/projects/fdt/sys/arm/mv/kirkwood/std.sheevaplug#2 edit
.. //depot/projects/fdt/sys/boot/fdt/dts/db88f6281.dts#5 edit
.. //depot/projects/fdt/sys/boot/fdt/dts/sheevaplug.dts#3 edit
.. //depot/projects/fdt/sys/conf/options.arm#4 edit
.. //depot/projects/fdt/sys/dev/mge/if_mge.c#6 edit
.. //depot/projects/fdt/sys/dev/mge/if_mgevar.h#2 edit

Differences ...

==== //depot/projects/fdt/sys/arm/mv/kirkwood/std.sheevaplug#2 (text+ko) ====

@@ -5,4 +5,3 @@
 files	"../mv/kirkwood/files.sheevaplug"
 
 options		PHYSMEM_SIZE=0x20000000
-options		MII_ADDR_BASE=0

==== //depot/projects/fdt/sys/boot/fdt/dts/db88f6281.dts#5 (text+ko) ====

@@ -200,6 +200,17 @@
 			local-mac-address = [ 00 00 00 00 00 00 ];
 			interrupts = <12 13 14 11 46>;
 			interrupt-parent = <&PIC>;
+			phy-handle = <&phy0>;
+
+			mdio at 004 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				compatible = "mrvl,mdio";
+
+				phy0: ethernet-phy at 0 {
+					reg = <0x8>;
+				};
+			};
 		};
 
 		serial0: serial at 12000 {

==== //depot/projects/fdt/sys/boot/fdt/dts/sheevaplug.dts#3 (text+ko) ====

@@ -198,6 +198,17 @@
 			local-mac-address = [ 00 00 00 00 00 00 ];
 			interrupts = <12 13 14 11 46>;
 			interrupt-parent = <&PIC>;
+			phy-handle = <&phy0>;
+
+			mdio at 004 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				compatible = "mrvl,mdio";
+
+				phy0: ethernet-phy at 0 {
+					reg = <0x0>;
+				};
+			};
 		};
 
 		serial0: serial at 12000 {

==== //depot/projects/fdt/sys/conf/options.arm#4 (text+ko) ====

@@ -25,7 +25,6 @@
 LOADERRAMADDR		opt_global.h
 PHYSADDR		opt_global.h
 PHYSMEM_SIZE		opt_global.h
-MII_ADDR_BASE		opt_global.h
 SKYEYE_WORKAROUNDS	opt_global.h
 SOC_MV_DISCOVERY	opt_global.h
 SOC_MV_KIRKWOOD		opt_global.h

==== //depot/projects/fdt/sys/dev/mge/if_mge.c#6 (text+ko) ====

@@ -68,13 +68,11 @@
 
 #include <dev/mii/mii.h>
 #include <dev/mii/miivar.h>
+
+#include <dev/fdt/fdt_common.h>
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
 
-#ifndef MII_ADDR_BASE
-#define MII_ADDR_BASE 8
-#endif
-
 #include <dev/mge/if_mgevar.h>
 #include <arm/mv/mvreg.h>
 #include <arm/mv/mvvar.h>
@@ -192,14 +190,53 @@
 	{ mge_intr_err,	"GbE error interrupt" },
 };
 
+static __inline int
+mge_phyaddr_from_dt(struct mge_softc *sc)
+{
+	ihandle_t phy_ihandle;
+	pcell_t phy_handle;
+	pcell_t phy_reg;
+
+	if (OF_getprop(sc->node, "phy-handle", (void *)&phy_handle,
+	    sizeof(phy_handle)) <= 0) {
+		device_printf(sc->dev, "Could not get phy-handle\n");
+		return (ENXIO);
+	}
+
+	phy_ihandle = (ihandle_t)phy_handle;
+	phy_ihandle = fdt32_to_cpu(phy_ihandle);
+	sc->phy_node = OF_instance_to_package(phy_ihandle);
+
+	if (OF_getprop(sc->phy_node, "reg", (void *)&phy_reg,
+	    sizeof(phy_reg)) <= 0) {
+		device_printf(sc->dev, "Could not get 'reg' property "
+		    "from phy node\n");
+		return (ENXIO);
+	}
+	sc->phy_addr = phy_reg;
+
+	return (0);
+}
+
 static void
 mge_get_mac_address(struct mge_softc *sc, uint8_t *addr)
 {
 	uint32_t mac_l, mac_h;
+	uint8_t lmac[6];
+	int i;
 
-	/* XXX use currently programmed MAC address; eventually this info will
-	 * be provided by the loader */
+	/*
+	 * Retrieve hw address from the device tree.
+	 */
+	i = OF_getprop(sc->node, "local-mac-address", (void *)lmac, 6);
+	if (i == 6) {
+		bcopy(lmac, addr, 6);
+		return;
+	}
 
+	/*
+	 * Fall back -- use the currently programmed address.
+	 */
 	mac_l = MGE_READ(sc, MGE_MAC_ADDR_L);
 	mac_h = MGE_READ(sc, MGE_MAC_ADDR_H);
 
@@ -615,6 +652,7 @@
 
 	sc = device_get_softc(dev);
 	sc->dev = dev;
+	sc->node = ofw_bus_get_node(dev);
 
 	if (device_get_unit(dev) == 0)
 		sc_mge0 = sc;
@@ -622,6 +660,10 @@
 	/* Set chip version-dependent parameters */
 	mge_ver_params(sc);
 
+	/* Get phy address from fdt*/
+	if (mge_phyaddr_from_dt(sc) != 0)
+		return (ENXIO);
+
 	/* Initialize mutexes */
 	mtx_init(&sc->transmit_lock, device_get_nameunit(dev), "mge TX lock", MTX_DEF);
 	mtx_init(&sc->receive_lock, device_get_nameunit(dev), "mge RX lock", MTX_DEF);
@@ -1265,19 +1307,12 @@
 static int
 mge_miibus_readreg(device_t dev, int phy, int reg)
 {
+	struct mge_softc *sc;
 	uint32_t retries;
 
-	/*
-	 * We assume static PHY address <=> device unit mapping:
-	 * PHY Address = MII_ADDR_BASE + devce unit.
-	 * This is true for most Marvell boards.
-	 * 
-	 * Code below grants proper PHY detection on each device
-	 * unit.
-	 */
+	sc = device_get_softc(dev);
 
-	
-	if ((MII_ADDR_BASE + device_get_unit(dev)) != phy)
+	if (sc->phy_addr != phy)
 		return (0);
 
 	MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff &
@@ -1296,9 +1331,12 @@
 static int
 mge_miibus_writereg(device_t dev, int phy, int reg, int value)
 {
+	struct mge_softc *sc;
 	uint32_t retries;
 
-	if ((MII_ADDR_BASE + device_get_unit(dev)) != phy)
+	sc = device_get_softc(dev);
+
+	if (sc->phy_addr != phy)
 		return (0);
 
 	MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff &

==== //depot/projects/fdt/sys/dev/mge/if_mgevar.h#2 (text+ko) ====

@@ -64,8 +64,13 @@
 
 struct mge_softc {
 	struct ifnet	*ifp;		/* per-interface network data */
+
+	phandle_t	node;
+	phandle_t	phy_node;
+
 	device_t	dev;
 	device_t	miibus;
+
 	struct mii_data	*mii;
 	struct resource	*res[1 + MGE_INTR_COUNT];	/* resources */
 	void		*ih_cookie[MGE_INTR_COUNT];	/* interrupt handlers cookies */
@@ -99,6 +104,8 @@
 	uint32_t	mge_tx_tok_cnt;
 	uint16_t	mge_mtu;
 	int		mge_ver;
+
+	int		phy_addr;
 };
 
 


More information about the p4-projects mailing list