Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci fix detach code and do it on shutdown
details: https://anonhg.NetBSD.org/src/rev/e28b14452b9c
branches: trunk
changeset: 320381:e28b14452b9c
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Tue Jul 03 19:56:01 2018 +0000
description:
fix detach code and do it on shutdown
diffstat:
sys/dev/pci/if_msk.c | 47 ++++++++++++++++++++++++++++++++---------------
sys/dev/pci/if_mskvar.h | 4 +++-
2 files changed, 35 insertions(+), 16 deletions(-)
diffs (140 lines):
diff -r 874d0a2c6871 -r e28b14452b9c sys/dev/pci/if_msk.c
--- a/sys/dev/pci/if_msk.c Tue Jul 03 18:09:28 2018 +0000
+++ b/sys/dev/pci/if_msk.c Tue Jul 03 19:56:01 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_msk.c,v 1.69 2018/07/03 18:07:36 jdolecek Exp $ */
+/* $NetBSD: if_msk.c,v 1.70 2018/07/03 19:56:01 jdolecek Exp $ */
/* $OpenBSD: if_msk.c,v 1.79 2009/10/15 17:54:56 deraadt Exp $ */
/*
@@ -52,7 +52,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_msk.c,v 1.69 2018/07/03 18:07:36 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_msk.c,v 1.70 2018/07/03 19:56:01 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -539,22 +539,23 @@
{
struct sk_softc *sc = sc_if->sk_softc;
char *ptr, *kva;
- bus_dma_segment_t seg;
- int i, rseg, state, error;
+ int i, state, error;
struct sk_jpool_entry *entry;
state = error = 0;
/* Grab a big chunk o' storage. */
if (bus_dmamem_alloc(sc->sc_dmatag, MSK_JMEM, PAGE_SIZE, 0,
- &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
+ &sc_if->sk_cdata.sk_jumbo_seg, 1, &sc_if->sk_cdata.sk_jumbo_nseg,
+ BUS_DMA_NOWAIT)) {
aprint_error(": can't alloc rx buffers");
return (ENOBUFS);
}
state = 1;
- if (bus_dmamem_map(sc->sc_dmatag, &seg, rseg, MSK_JMEM, (void **)&kva,
- BUS_DMA_NOWAIT)) {
+ if (bus_dmamem_map(sc->sc_dmatag, &sc_if->sk_cdata.sk_jumbo_seg,
+ sc_if->sk_cdata.sk_jumbo_nseg, MSK_JMEM, (void **)&kva,
+ BUS_DMA_NOWAIT)) {
aprint_error(": can't map dma buffers (%d bytes)", MSK_JMEM);
error = ENOBUFS;
goto out;
@@ -616,7 +617,9 @@
case 2:
bus_dmamem_unmap(sc->sc_dmatag, kva, MSK_JMEM);
case 1:
- bus_dmamem_free(sc->sc_dmatag, &seg, rseg);
+ bus_dmamem_free(sc->sc_dmatag,
+ &sc_if->sk_cdata.sk_jumbo_seg,
+ sc_if->sk_cdata.sk_jumbo_nseg);
break;
default:
break;
@@ -626,6 +629,18 @@
return error;
}
+static void
+msk_free_jumbo_mem(struct sk_if_softc *sc_if)
+{
+ struct sk_softc *sc = sc_if->sk_softc;
+
+ bus_dmamap_unload(sc->sc_dmatag, sc_if->sk_cdata.sk_rx_jumbo_map);
+ bus_dmamap_destroy(sc->sc_dmatag, sc_if->sk_cdata.sk_rx_jumbo_map);
+ bus_dmamem_unmap(sc->sc_dmatag, sc_if->sk_cdata.sk_jumbo_buf, MSK_JMEM);
+ bus_dmamem_free(sc->sc_dmatag, &sc_if->sk_cdata.sk_jumbo_seg,
+ sc_if->sk_cdata.sk_jumbo_nseg);
+}
+
/*
* Allocate a jumbo buffer.
*/
@@ -1220,7 +1235,7 @@
int
msk_detach(device_t self, int flags)
{
- struct sk_if_softc *sc_if = (struct sk_if_softc *)self;
+ struct sk_if_softc *sc_if = device_private(self);
struct sk_softc *sc = sc_if->sk_softc;
struct ifnet *ifp = &sc_if->sk_ethercom.ec_if;
@@ -1247,6 +1262,8 @@
ether_ifdetach(ifp);
if_detach(ifp);
+ msk_free_jumbo_mem(sc_if);
+
bus_dmamem_unmap(sc->sc_dmatag, sc_if->sk_rdata,
sizeof(struct msk_ring_data));
bus_dmamem_free(sc->sc_dmatag,
@@ -1670,7 +1687,7 @@
int
mskc_detach(device_t self, int flags)
{
- struct sk_softc *sc = (struct sk_softc *)self;
+ struct sk_softc *sc = device_private(self);
int rv;
if (sc->sk_intrhand)
@@ -2518,11 +2535,11 @@
#endif
}
-CFATTACH_DECL_NEW(mskc, sizeof(struct sk_softc), mskc_probe, mskc_attach,
- mskc_detach, NULL);
-
-CFATTACH_DECL_NEW(msk, sizeof(struct sk_if_softc), msk_probe, msk_attach,
- msk_detach, NULL);
+CFATTACH_DECL3_NEW(mskc, sizeof(struct sk_softc), mskc_probe, mskc_attach,
+ mskc_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
+
+CFATTACH_DECL3_NEW(msk, sizeof(struct sk_if_softc), msk_probe, msk_attach,
+ msk_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
#ifdef MSK_DEBUG
void
diff -r 874d0a2c6871 -r e28b14452b9c sys/dev/pci/if_mskvar.h
--- a/sys/dev/pci/if_mskvar.h Tue Jul 03 18:09:28 2018 +0000
+++ b/sys/dev/pci/if_mskvar.h Tue Jul 03 19:56:01 2018 +0000
@@ -1,5 +1,5 @@
/* $OpenBSD: if_mskvar.h,v 1.3 2006/12/28 16:34:42 kettenis Exp $ */
-/* $NetBSD: if_mskvar.h,v 1.16 2018/07/03 18:07:36 jdolecek Exp $ */
+/* $NetBSD: if_mskvar.h,v 1.17 2018/07/03 19:56:01 jdolecek Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -123,6 +123,8 @@
/* Stick the jumbo mem management stuff here too. */
void * sk_jslots[MSK_JSLOTS];
void *sk_jumbo_buf;
+ bus_dma_segment_t sk_jumbo_seg;
+ int sk_jumbo_nseg;
};
struct msk_ring_data {
Home |
Main Index |
Thread Index |
Old Index