From owner-p4-projects@FreeBSD.ORG Tue Mar 16 21:24:19 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 558DB1065670; Tue, 16 Mar 2010 21:24:19 +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 19D371065676 for ; Tue, 16 Mar 2010 21:24:19 +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 07AA38FC13 for ; Tue, 16 Mar 2010 21:24:19 +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 o2GLOIFr098048 for ; Tue, 16 Mar 2010 21:24:18 GMT (envelope-from raj@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o2GLOIHR098046 for perforce@freebsd.org; Tue, 16 Mar 2010 21:24:18 GMT (envelope-from raj@freebsd.org) Date: Tue, 16 Mar 2010 21:24:18 GMT Message-Id: <201003162124.o2GLOIHR098046@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 175744 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: Tue, 16 Mar 2010 21:24:19 -0000 http://p4web.freebsd.org/chv.cgi?CH=175744 Change 175744 by raj@raj_fdt on 2010/03/16 21:24:15 Refactor PHY address processing area. o Make the main routine shared accross plaforms o Improve validation Affected files ... .. //depot/projects/fdt/sys/dev/fdt/fdt_common.c#11 edit .. //depot/projects/fdt/sys/dev/fdt/fdt_common.h#9 edit .. //depot/projects/fdt/sys/dev/mge/if_mge.c#7 edit .. //depot/projects/fdt/sys/dev/mge/if_mgevar.h#3 edit Differences ... ==== //depot/projects/fdt/sys/dev/fdt/fdt_common.c#11 (text+ko) ==== @@ -462,3 +462,26 @@ free(intr, M_OFWPROP); return (rv); } + +int +fdt_get_phyaddr(phandle_t node, int *phy_addr) +{ + phandle_t phy_node; + ihandle_t phy_ihandle; + pcell_t phy_handle, phy_reg; + + if (OF_getprop(node, "phy-handle", (void *)&phy_handle, + sizeof(phy_handle)) <= 0) + return (ENXIO); + + phy_ihandle = (ihandle_t)phy_handle; + phy_ihandle = fdt32_to_cpu(phy_ihandle); + phy_node = OF_instance_to_package(phy_ihandle); + + if (OF_getprop(phy_node, "reg", (void *)&phy_reg, + sizeof(phy_reg)) <= 0) + return (ENXIO); + + *phy_addr = fdt32_to_cpu(phy_reg); + return (0); +} ==== //depot/projects/fdt/sys/dev/fdt/fdt_common.h#9 (text+ko) ==== @@ -58,16 +58,17 @@ int fdt_addrsize_cells(phandle_t, int *, int *); u_long fdt_data_get(void *, int); -int fdt_parent_addr_cells(phandle_t); -void fdt_ranges_dump(pcell_t *, int, int, int, int); -int fdt_ranges_verify(pcell_t *, int, int, int, int); +int fdt_data_to_res(pcell_t *, int, int, u_long *, u_long *); +phandle_t fdt_find_compatible(phandle_t, const char *, int); +int fdt_get_phyaddr(phandle_t node, int *); int fdt_get_regsize(phandle_t, u_long *, u_long *); -int fdt_reg_to_rl(phandle_t, struct resource_list *, u_long); int fdt_intr_to_rl(phandle_t, struct resource_list *, struct sense_level *); -int fdt_data_to_res(pcell_t *, int, int, u_long *, u_long *); int fdt_is_compatible(phandle_t, const char *); int fdt_is_compatible_strict(phandle_t, const char *); int fdt_is_enabled(phandle_t); -phandle_t fdt_find_compatible(phandle_t, const char *, int); +int fdt_parent_addr_cells(phandle_t); +void fdt_ranges_dump(pcell_t *, int, int, int, int); +int fdt_ranges_verify(pcell_t *, int, int, int, int); +int fdt_reg_to_rl(phandle_t, struct resource_list *, u_long); #endif /* _FDT_COMMON_H_ */ ==== //depot/projects/fdt/sys/dev/mge/if_mge.c#7 (text+ko) ==== @@ -190,48 +190,29 @@ { 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; + int i, valid; /* * 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; + valid = 0; + for (i = 0; i < 6; i++) + if (lmac[i] != 0) { + valid = 1; + break; + } + + if (valid) { + bcopy(lmac, addr, 6); + return; + } } /* @@ -660,8 +641,8 @@ /* Set chip version-dependent parameters */ mge_ver_params(sc); - /* Get phy address from fdt*/ - if (mge_phyaddr_from_dt(sc) != 0) + /* Get phy address from fdt */ + if (fdt_get_phyaddr(sc->node, &sc->phyaddr) != 0) return (ENXIO); /* Initialize mutexes */ @@ -1312,7 +1293,7 @@ sc = device_get_softc(dev); - if (sc->phy_addr != phy) + if (sc->phyaddr != phy) return (0); MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff & @@ -1336,7 +1317,7 @@ sc = device_get_softc(dev); - if (sc->phy_addr != phy) + if (sc->phyaddr != phy) return (0); MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff & ==== //depot/projects/fdt/sys/dev/mge/if_mgevar.h#3 (text+ko) ==== @@ -66,7 +66,6 @@ struct ifnet *ifp; /* per-interface network data */ phandle_t node; - phandle_t phy_node; device_t dev; device_t miibus; @@ -105,7 +104,7 @@ uint16_t mge_mtu; int mge_ver; - int phy_addr; + int phyaddr; };