From 5ca041b97a5c74720ff63132eb6533fe86563e03 Mon Sep 17 00:00:00 2001 From: jhb Date: Tue, 18 Nov 2014 21:58:57 +0000 Subject: [PATCH] Cleanups to pst(4): - Use callout(9) instead of timeout(9). - Don't bother zero'ing the softc. - Destroy mutex on detach. Tested by: no one --- sys/dev/pst/pst-pci.c | 15 +++++++++------ sys/dev/pst/pst-raid.c | 25 ++++++++++++------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/sys/dev/pst/pst-pci.c b/sys/dev/pst/pst-pci.c index 8ed8fed3b8ec..4cc579636ec5 100644 --- a/sys/dev/pst/pst-pci.c +++ b/sys/dev/pst/pst-pci.c @@ -73,15 +73,13 @@ iop_pci_attach(device_t dev) struct iop_softc *sc = device_get_softc(dev); int rid; - bzero(sc, sizeof(struct iop_softc)); - /* get resources */ - rid = 0x10; + rid = PCIR_BAR(0); sc->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (!sc->r_mem) - return 0; + return ENXIO; rid = 0x00; sc->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, @@ -104,11 +102,16 @@ static int iop_pci_detach(device_t dev) { struct iop_softc *sc = device_get_softc(dev); + int error; + error = bus_generic_detach(dev); + if (error) + return (error); bus_teardown_intr(dev, sc->r_irq, sc->handle); bus_release_resource(dev, SYS_RES_IRQ, 0x00, sc->r_irq); - bus_release_resource(dev, SYS_RES_MEMORY, 0x10, sc->r_mem); - return bus_generic_detach(dev); + bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0), sc->r_mem); + mtx_destroy(&sc->mtx); + return (0); } diff --git a/sys/dev/pst/pst-raid.c b/sys/dev/pst/pst-raid.c index e48b1c2f8812..084d32ce0158 100644 --- a/sys/dev/pst/pst-raid.c +++ b/sys/dev/pst/pst-raid.c @@ -63,7 +63,7 @@ struct pst_softc { struct pst_request { struct pst_softc *psc; /* pointer to softc */ u_int32_t mfa; /* frame addreess */ - struct callout_handle timeout_handle; /* handle for untimeout */ + struct callout timeout; /* timeout timer */ struct bio *bp; /* associated bio ptr */ }; @@ -75,7 +75,7 @@ static int pst_shutdown(device_t); static void pst_start(struct pst_softc *); static void pst_done(struct iop_softc *, u_int32_t, struct i2o_single_reply *); static int pst_rw(struct pst_request *); -static void pst_timeout(struct pst_request *); +static void pst_timeout(void *); static void bpack(int8_t *, int8_t *, int); /* local vars */ @@ -97,7 +97,7 @@ pst_add_raid(struct iop_softc *sc, struct i2o_lct_entry *lct) psc->iop = sc; psc->lct = lct; device_set_softc(child, psc); - return bus_generic_attach(sc->dev); + return device_probe_and_attach(child); } static int @@ -224,6 +224,7 @@ pst_start(struct pst_softc *psc) iop_free_mfa(psc->iop, mfa); return; } + callout_init_mtx(&request->timeout, &psc->iop->mtx, 0); psc->iop->outstanding++; request->psc = psc; request->mfa = mfa; @@ -245,7 +246,7 @@ pst_done(struct iop_softc *sc, u_int32_t mfa, struct i2o_single_reply *reply) (struct pst_request *)reply->transaction_context; struct pst_softc *psc = request->psc; - untimeout((timeout_t *)pst_timeout, request, request->timeout_handle); + callout_stop(&request->timeout); request->bp->bio_resid = request->bp->bio_bcount - reply->donecount; biofinish(request->bp, NULL, reply->status ? EIO : 0); free(request, M_PSTRAID); @@ -297,26 +298,25 @@ pst_rw(struct pst_request *request) request->psc->iop->reg->iqueue = request->mfa; - if (dumping) - request->timeout_handle.callout = NULL; - else - request->timeout_handle = - timeout((timeout_t*)pst_timeout, request, 10 * hz); + if (!dumping) + callout_reset(&request->timeout, 10 * hz, pst_timeout, request); return 0; } static void -pst_timeout(struct pst_request *request) +pst_timeout(void *arg) { + struct pst_request *request; + + request = arg; printf("pst: timeout mfa=0x%08x cmd=0x%02x\n", request->mfa, request->bp->bio_cmd); - mtx_lock(&request->psc->iop->mtx); + mtx_assert(&request->psc->iop->mtx, MA_OWNED); iop_free_mfa(request->psc->iop, request->mfa); if ((request->mfa = iop_get_mfa(request->psc->iop)) == 0xffffffff) { printf("pst: timeout no mfa possible\n"); biofinish(request->bp, NULL, EIO); request->psc->iop->outstanding--; - mtx_unlock(&request->psc->iop->mtx); return; } if (pst_rw(request)) { @@ -324,7 +324,6 @@ pst_timeout(struct pst_request *request) biofinish(request->bp, NULL, EIO); request->psc->iop->outstanding--; } - mtx_unlock(&request->psc->iop->mtx); } static void