Date: Tue, 16 Mar 2010 21:24:18 GMT From: Rafal Jaworowski <raj@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 175744 for review Message-ID: <201003162124.o2GLOIHR098046@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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; };
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003162124.o2GLOIHR098046>