From owner-p4-projects@FreeBSD.ORG Mon Mar 15 22:43:32 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 692B4106566C; Mon, 15 Mar 2010 22:43:32 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2B6D3106564A for ; Mon, 15 Mar 2010 22:43:32 +0000 (UTC) (envelope-from raj@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 190F98FC1A for ; Mon, 15 Mar 2010 22:43:32 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o2FMhV3w011836 for ; Mon, 15 Mar 2010 22:43:31 GMT (envelope-from raj@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o2FMhViE011834 for perforce@freebsd.org; Mon, 15 Mar 2010 22:43:31 GMT (envelope-from raj@freebsd.org) Date: Mon, 15 Mar 2010 22:43:31 GMT Message-Id: <201003152243.o2FMhViE011834@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to raj@freebsd.org using -f From: Rafal Jaworowski To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 175719 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Mar 2010 22:43:32 -0000 http://p4web.freebsd.org/chv.cgi?CH=175719 Change 175719 by raj@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@004 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mrvl,mdio"; + + phy0: ethernet-phy@0 { + reg = <0x8>; + }; + }; }; serial0: serial@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@004 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "mrvl,mdio"; + + phy0: ethernet-phy@0 { + reg = <0x0>; + }; + }; }; serial0: serial@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 #include + +#include #include #include -#ifndef MII_ADDR_BASE -#define MII_ADDR_BASE 8 -#endif - #include #include #include @@ -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; };