Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Oct 2014 21:08:03 +0000 (UTC)
From:      Luiz Otavio O Souza <loos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r273606 - head/sys/arm/ti/cpsw
Message-ID:  <201410242108.s9OL83v2047419@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: loos
Date: Fri Oct 24 21:08:02 2014
New Revision: 273606
URL: https://svnweb.freebsd.org/changeset/base/273606

Log:
  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)
  MFC after:	1 week

Modified:
  head/sys/arm/ti/cpsw/if_cpsw.c

Modified: head/sys/arm/ti/cpsw/if_cpsw.c
==============================================================================
--- head/sys/arm/ti/cpsw/if_cpsw.c	Fri Oct 24 20:29:14 2014	(r273605)
+++ head/sys/arm/ti/cpsw/if_cpsw.c	Fri Oct 24 21:08:02 2014	(r273606)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410242108.s9OL83v2047419>