From 86bc62030ca9b1efe173754d4c80e44b23d735d9 Mon Sep 17 00:00:00 2001 From: krw Date: Wed, 3 Aug 2016 13:44:49 +0000 Subject: [PATCH] Fold umass_atapi_attach() and umass_scsi_setup() into umass_scsi_attach() to shorten and simplify code. No intentional functional change. --- sys/dev/usb/umass.c | 7 +--- sys/dev/usb/umass_scsi.c | 84 ++++++++++++++-------------------------- sys/dev/usb/umass_scsi.h | 3 +- 3 files changed, 32 insertions(+), 62 deletions(-) diff --git a/sys/dev/usb/umass.c b/sys/dev/usb/umass.c index 11c91072c41..d03b6eb71e8 100644 --- a/sys/dev/usb/umass.c +++ b/sys/dev/usb/umass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: umass.c,v 1.72 2015/12/17 10:21:22 mpi Exp $ */ +/* $OpenBSD: umass.c,v 1.73 2016/08/03 13:44:49 krw Exp $ */ /* $NetBSD: umass.c,v 1.116 2004/06/30 05:53:46 mycroft Exp $ */ /* @@ -585,12 +585,9 @@ umass_attach(struct device *parent, struct device *self, void *aux) switch (sc->sc_cmd) { case UMASS_CPROTO_RBC: case UMASS_CPROTO_SCSI: - error = umass_scsi_attach(sc); - break; - case UMASS_CPROTO_UFI: case UMASS_CPROTO_ATAPI: - error = umass_atapi_attach(sc); + error = umass_scsi_attach(sc); break; case UMASS_CPROTO_ISD_ATA: diff --git a/sys/dev/usb/umass_scsi.c b/sys/dev/usb/umass_scsi.c index a7e691262ed..b7757027136 100644 --- a/sys/dev/usb/umass_scsi.c +++ b/sys/dev/usb/umass_scsi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: umass_scsi.c,v 1.44 2016/08/01 10:56:31 krw Exp $ */ +/* $OpenBSD: umass_scsi.c,v 1.45 2016/08/03 13:44:49 krw Exp $ */ /* $NetBSD: umass_scsipi.c,v 1.9 2003/02/16 23:14:08 augustss Exp $ */ /* * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -78,8 +78,6 @@ void umass_scsi_cb(struct umass_softc *sc, void *priv, int residue, int status); void umass_scsi_sense_cb(struct umass_softc *sc, void *priv, int residue, int status); -struct umass_scsi_softc *umass_scsi_setup(struct umass_softc *); - void *umass_io_get(void *); void umass_io_put(void *, void *); @@ -89,45 +87,43 @@ umass_scsi_attach(struct umass_softc *sc) struct scsibus_attach_args saa; struct umass_scsi_softc *scbus; - scbus = umass_scsi_setup(sc); - scbus->sc_link.adapter_target = UMASS_SCSIID_HOST; - scbus->sc_link.luns = sc->maxlun + 1; - scbus->sc_link.flags &= ~SDEV_ATAPI; - scbus->sc_link.flags |= SDEV_UMASS; - - bzero(&saa, sizeof(saa)); - saa.saa_sc_link = &scbus->sc_link; - - DPRINTF(UDMASS_USB, ("%s: umass_attach_bus: SCSI\n" - "sc = 0x%p, scbus = 0x%p\n", - sc->sc_dev.dv_xname, sc, scbus)); - - sc->sc_refcnt++; - scbus->sc_child = config_found((struct device *)sc, &saa, scsiprint); - if (--sc->sc_refcnt < 0) - usb_detach_wakeup(&sc->sc_dev); + scbus = malloc(sizeof(*scbus), M_DEVBUF, M_WAITOK | M_ZERO); - return (0); -} + sc->bus = scbus; -int -umass_atapi_attach(struct umass_softc *sc) -{ - struct scsibus_attach_args saa; - struct umass_scsi_softc *scbus; + scsi_iopool_init(&scbus->sc_iopool, scbus, umass_io_get, umass_io_put); - scbus = umass_scsi_setup(sc); + /* Fill in the link. */ + scbus->sc_link.adapter_buswidth = 2; + scbus->sc_link.adapter = &umass_scsi_switch; + scbus->sc_link.adapter_softc = sc; scbus->sc_link.adapter_target = UMASS_SCSIID_HOST; - scbus->sc_link.luns = sc->maxlun + 1; scbus->sc_link.openings = 1; - scbus->sc_link.flags |= SDEV_UMASS | SDEV_ATAPI; + scbus->sc_link.quirks = SDEV_ONLYBIG | sc->sc_busquirks; + scbus->sc_link.pool = &scbus->sc_iopool; + scbus->sc_link.luns = sc->maxlun + 1; + scbus->sc_link.flags = SDEV_UMASS; bzero(&saa, sizeof(saa)); saa.saa_sc_link = &scbus->sc_link; - DPRINTF(UDMASS_USB, ("%s: umass_attach_bus: ATAPI\n" - "sc = 0x%p, scbus = 0x%p\n", - sc->sc_dev.dv_xname, sc, scbus)); + switch (sc->sc_cmd) { + case UMASS_CPROTO_RBC: + case UMASS_CPROTO_SCSI: + DPRINTF(UDMASS_USB, ("%s: umass_attach_bus: SCSI\n" + "sc = 0x%p, scbus = 0x%p\n", + sc->sc_dev.dv_xname, sc, scbus)); + break; + case UMASS_CPROTO_UFI: + case UMASS_CPROTO_ATAPI: + scbus->sc_link.flags |= SDEV_ATAPI; + DPRINTF(UDMASS_USB, ("%s: umass_attach_bus: ATAPI\n" + "sc = 0x%p, scbus = 0x%p\n", + sc->sc_dev.dv_xname, sc, scbus)); + break; + default: + break; + } sc->sc_refcnt++; scbus->sc_child = config_found((struct device *)sc, &saa, scsiprint); @@ -137,28 +133,6 @@ umass_atapi_attach(struct umass_softc *sc) return (0); } -struct umass_scsi_softc * -umass_scsi_setup(struct umass_softc *sc) -{ - struct umass_scsi_softc *scbus; - - scbus = malloc(sizeof(*scbus), M_DEVBUF, M_WAITOK | M_ZERO); - - sc->bus = scbus; - - scsi_iopool_init(&scbus->sc_iopool, scbus, umass_io_get, umass_io_put); - - /* Fill in the link. */ - scbus->sc_link.adapter_buswidth = 2; - scbus->sc_link.adapter = &umass_scsi_switch; - scbus->sc_link.adapter_softc = sc; - scbus->sc_link.openings = 1; - scbus->sc_link.quirks |= SDEV_ONLYBIG | sc->sc_busquirks; - scbus->sc_link.pool = &scbus->sc_iopool; - - return (scbus); -} - int umass_scsi_detach(struct umass_softc *sc, int flags) { diff --git a/sys/dev/usb/umass_scsi.h b/sys/dev/usb/umass_scsi.h index 321eb675e3b..293e2aa5efb 100644 --- a/sys/dev/usb/umass_scsi.h +++ b/sys/dev/usb/umass_scsi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: umass_scsi.h,v 1.5 2015/12/16 14:50:26 mpi Exp $ */ +/* $OpenBSD: umass_scsi.h,v 1.6 2016/08/03 13:44:49 krw Exp $ */ /* $NetBSD: umass_scsipi.h,v 1.1 2001/12/24 13:25:53 augustss Exp $ */ /* @@ -32,5 +32,4 @@ */ int umass_scsi_attach(struct umass_softc *sc); -int umass_atapi_attach(struct umass_softc *sc); int umass_scsi_detach(struct umass_softc *sc, int flags); -- 2.20.1