NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

port-arm/49621: Add detach function to if_cpsw



>Number:         49621
>Category:       port-arm
>Synopsis:       Add detach function to if_cpsw
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-arm-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 01 09:35:00 +0000 2015
>Originator:     Robert Sprowson
>Release:        
>Organization:
>Environment:
>Description:
The if_cpsw network driver has no detach function, so can't be hot swapped. This patch adds said function, as a diff against revision 1.6 of src/sys/arch/arm/omap/if_cpsw.c

Tested with a little loop to 30 that attach/detaches, and manually inspecting that no resources leaked overall.
>How-To-Repeat:

>Fix:
--- if_cpsw_1.6.c	2014-10-31 17:12:48 +0000
+++ if_cpsw_new.c	2015-02-01 09:24:24 +0000
@@ -144,8 +144,9 @@
 };
 
 static int cpsw_match(device_t, cfdata_t, void *);
 static void cpsw_attach(device_t, device_t, void *);
+static int cpsw_detach(device_t, int);
 
 static void cpsw_start(struct ifnet *);
 static int cpsw_ioctl(struct ifnet *, u_long, void *);
 static void cpsw_watchdog(struct ifnet *);
@@ -169,9 +170,9 @@
 
 static int cpsw_ale_update_addresses(struct cpsw_softc *, int purge);
 
 CFATTACH_DECL_NEW(cpsw, sizeof(struct cpsw_softc),
-    cpsw_match, cpsw_attach, NULL, NULL);
+    cpsw_match, cpsw_attach, cpsw_detach, NULL);
 
 #undef KERNHIST
 #include <sys/kernhist.h>
 KERNHIST_DEFINE(cpswhist);
@@ -335,8 +336,36 @@
 	}
 	return false;
 }
 
+static int
+cpsw_detach(device_t self, int flags)
+{
+	struct cpsw_softc * const sc = device_private(self);
+	u_int i;
+
+	/* Let go of the interrupts */
+	intr_disestablish(sc->sc_rxthih);
+	intr_disestablish(sc->sc_rxih);
+	intr_disestablish(sc->sc_txih);
+	intr_disestablish(sc->sc_miscih);
+
+	/* Free the packet padding buffer */
+	kmem_free(sc->sc_txpad, ETHER_MIN_LEN);
+	bus_dmamap_destroy(sc->sc_bdt, sc->sc_txpad_dm);
+
+	/* Destroy all the descriptors */
+	for (i = 0; i < CPSW_NTXDESCS; i++)
+		bus_dmamap_destroy(sc->sc_bdt, sc->sc_rdp->tx_dm[i]);
+	for (i = 0; i < CPSW_NRXDESCS; i++)
+		bus_dmamap_destroy(sc->sc_bdt, sc->sc_rdp->rx_dm[i]);
+	kmem_free(sc->sc_rdp, sizeof(*sc->sc_rdp));
+
+	aprint_normal_dev("detached CPSW driver\n");
+
+	return 0;
+}
+
 static void
 cpsw_attach(device_t parent, device_t self, void *aux)
 {
 	struct obio_attach_args * const oa = aux;



Home | Main Index | Thread Index | Old Index