From owner-svn-src-stable-10@FreeBSD.ORG Fri Jan 9 02:51:07 2015 Return-Path: Delivered-To: svn-src-stable-10@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C86713E7; Fri, 9 Jan 2015 02:51:07 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 99C3EFBC; Fri, 9 Jan 2015 02:51:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t092p7hT064869; Fri, 9 Jan 2015 02:51:07 GMT (envelope-from loos@FreeBSD.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t092p79Z064868; Fri, 9 Jan 2015 02:51:07 GMT (envelope-from loos@FreeBSD.org) Message-Id: <201501090251.t092p79Z064868@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: loos set sender to loos@FreeBSD.org using -f From: Luiz Otavio O Souza Date: Fri, 9 Jan 2015 02:51:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r276875 - stable/10/sys/arm/ti/cpsw X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jan 2015 02:51:07 -0000 Author: loos Date: Fri Jan 9 02:51:06 2015 New Revision: 276875 URL: https://svnweb.freebsd.org/changeset/base/276875 Log: MFC r273606: Fix cpsw_detach() to not panic when called from cpsw_attach(). For an unkown reason (at moment), sometimes if_cpsw cannot read from PHY and fails to attach calling cpsw_detach() which end up in a panic. Fix it by doing the proper check before detach the miibus and also fix the leak of few variables. And to actually make it work, ether_ifattach() has to be moved to the end of cpsw_attach() to avoid a race where calling ether_ifdetach() before domain_init() (which will only run later on) would make it crash at INP_INFO_RLOCK() on in_pcbpurgeif0(). Tested on: BBB (am335x) Modified: stable/10/sys/arm/ti/cpsw/if_cpsw.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/arm/ti/cpsw/if_cpsw.c ============================================================================== --- stable/10/sys/arm/ti/cpsw/if_cpsw.c Fri Jan 9 02:47:57 2015 (r276874) +++ stable/10/sys/arm/ti/cpsw/if_cpsw.c Fri Jan 9 02:51:06 2015 (r276875) @@ -666,9 +666,6 @@ cpsw_attach(device_t dev) sc->mac_addr[4] = reg & 0xFF; sc->mac_addr[5] = (reg >> 8) & 0xFF; - ether_ifattach(ifp, sc->mac_addr); - callout_init(&sc->watchdog.callout, 0); - /* Initialze MDIO - ENABLE, PREAMBLE=0, FAULTENB, CLKDIV=0xFF */ /* TODO Calculate MDCLK=CLK/(CLKDIV+1) */ cpsw_write_4(sc, MDIOCONTROL, 1 << 30 | 1 << 18 | 0xFF); @@ -703,6 +700,9 @@ cpsw_attach(device_t dev) return (ENXIO); } + ether_ifattach(ifp, sc->mac_addr); + callout_init(&sc->watchdog.callout, 0); + return (0); } @@ -740,15 +740,21 @@ cpsw_detach(device_t dev) } bus_generic_detach(dev); - device_delete_child(dev, sc->miibus); + if (sc->miibus) + device_delete_child(dev, sc->miibus); /* Stop and release all interrupts */ cpsw_detach_interrupts(sc); /* Free dmamaps and mbufs */ - for (i = 0; i < sizeof(sc->_slots) / sizeof(sc->_slots[0]); ++i) { + for (i = 0; i < sizeof(sc->_slots) / sizeof(sc->_slots[0]); ++i) cpsw_free_slot(sc, &sc->_slots[i]); + if (sc->null_mbuf_dmamap) { + error = bus_dmamap_destroy(sc->mbuf_dtag, sc->null_mbuf_dmamap); + KASSERT(error == 0, ("Mapping still active")); } + if (sc->null_mbuf) + m_freem(sc->null_mbuf); /* Free DMA tag */ error = bus_dma_tag_destroy(sc->mbuf_dtag); @@ -757,6 +763,9 @@ cpsw_detach(device_t dev) /* Free IO memory handler */ bus_release_resources(dev, res_spec, sc->res); + if (sc->ifp != NULL) + if_free(sc->ifp); + /* Destroy mutexes */ mtx_destroy(&sc->rx.lock); mtx_destroy(&sc->tx.lock);