Currently, wdcattach() handles initializing the channel_queue, but
this is technically wrong when a single channel_queue is shared by
multiple channels.

Diff below refactors the malloc+init code into a single function
wdc_alloc_queue(), which the bus-specific attach code can call instead
of malloc(9).  I also made the error messages consistent.

Also, I moved the wdc_xfer_pool init code here, and dropped the
splbio() 'locking' as it doesn't make any sense here.  The pool
initialization still isn't safe against concurrent execution, but
it'll go away completely once wdc is converted to atascsi.

I've sanity checked this on qemu.  Tests on real life wdc/pciide
systems would be appreciated though.  Shouldn't have any functional
changes whatsoever.

ok?


Index: arch/landisk/dev/wdc_obio.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/landisk/dev/wdc_obio.c,v
retrieving revision 1.3
diff -u -p -r1.3 wdc_obio.c
--- arch/landisk/dev/wdc_obio.c 26 Jun 2008 05:42:11 -0000      1.3
+++ arch/landisk/dev/wdc_obio.c 8 May 2011 21:13:29 -0000
@@ -134,10 +134,9 @@ wdc_obio_attach(struct device *parent, s
        chp->channel = 0;
        chp->wdc = &sc->sc_wdcdev;
 
-       chp->ch_queue = malloc(sizeof(struct channel_queue), M_DEVBUF,
-           M_NOWAIT);
+       chp->ch_queue = wdc_alloc_queue();
        if (chp->ch_queue == NULL) {
-               printf("%s: can't allocate memory for command queue\n",
+               printf("%s: cannot allocate channel queue\n",
                    self->dv_xname);
                obio_intr_disestablish(sc->sc_ih);
                return;
Index: arch/macppc/dev/wdc_obio.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/macppc/dev/wdc_obio.c,v
retrieving revision 1.28
diff -u -p -r1.28 wdc_obio.c
--- arch/macppc/dev/wdc_obio.c  29 Aug 2010 23:06:53 -0000      1.28
+++ arch/macppc/dev/wdc_obio.c  8 May 2011 21:13:29 -0000
@@ -217,10 +217,9 @@ wdc_obio_attach(struct device *parent, s
        chp->channel = 0;
        chp->wdc = &sc->sc_wdcdev;
 
-       chp->ch_queue = malloc(sizeof(struct channel_queue), M_DEVBUF,
-           M_NOWAIT);
+       chp->ch_queue = wdc_alloc_queue();
        if (chp->ch_queue == NULL) {
-               printf("%s: can't allocate memory for command queue",
+               printf("%s: cannot allocate channel queue",
                sc->sc_wdcdev.sc_dev.dv_xname);
                return;
        }
Index: arch/palm/dev/palm_hdd.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/palm/dev/palm_hdd.c,v
retrieving revision 1.2
diff -u -p -r1.2 palm_hdd.c
--- arch/palm/dev/palm_hdd.c    9 Sep 2009 11:30:56 -0000       1.2
+++ arch/palm/dev/palm_hdd.c    8 May 2011 21:13:29 -0000
@@ -88,7 +88,7 @@ void palm_hdd_attach(struct device *pare
 
        chp->channel = 0;
        chp->wdc = &sc->sc_wdcdev;
-       chp->ch_queue = malloc(sizeof(struct channel_queue), M_DEVBUF, 
M_NOWAIT);
+       chp->ch_queue = wdc_alloc_queue();
 
        printf("\n");
 
Index: arch/socppc/dev/wdc_mainbus.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/arch/socppc/dev/wdc_mainbus.c,v
retrieving revision 1.1
diff -u -p -r1.1 wdc_mainbus.c
--- arch/socppc/dev/wdc_mainbus.c       6 Sep 2009 20:09:34 -0000       1.1
+++ arch/socppc/dev/wdc_mainbus.c       8 May 2011 21:13:29 -0000
@@ -132,10 +132,9 @@ wdc_mainbus_attach(struct device *parent
        chp->channel = 0;
        chp->wdc = &sc->sc_wdcdev;
 
-       chp->ch_queue = malloc(sizeof(struct channel_queue), M_DEVBUF,
-           M_NOWAIT);
+       chp->ch_queue = wdc_alloc_queue();
        if (chp->ch_queue == NULL) {
-               printf("%s: can't allocate memory for command queue\n",
+               printf("%s: cannot allocate channel queue\n",
                    self->dv_xname);
                /* XXX disestablish interrupt */
                return;
Index: dev/ic/wdc.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/dev/ic/wdc.c,v
retrieving revision 1.113
diff -u -p -r1.113 wdc.c
--- dev/ic/wdc.c        18 Apr 2011 04:16:13 -0000      1.113
+++ dev/ic/wdc.c        8 May 2011 21:19:52 -0000
@@ -697,12 +697,32 @@ wdcprobe(struct channel_softc *chp)
        return (ret_value);
 }
 
+struct channel_queue *
+wdc_alloc_queue(void)
+{
+       static int inited = 0;
+       struct channel_queue *queue;
+
+       /* Initialize global data. */
+       if (inited == 0) {
+               /* Initialize the wdc_xfer pool. */
+               pool_init(&wdc_xfer_pool, sizeof(struct wdc_xfer), 0,
+                   0, 0, "wdcspl", NULL);
+               inited = 1;
+       }
+
+       queue = malloc(sizeof(*queue), M_DEVBUF, M_NOWAIT);
+       if (queue != NULL) {
+               TAILQ_INIT(&queue->sc_xfer);
+       }
+       return (queue);
+}
+
 void
 wdcattach(struct channel_softc *chp)
 {
        int channel_flags, ctrl_flags, i;
        struct ata_atapi_attach aa_link;
-       static int inited = 0, s;
 #ifdef WDCDEBUG
        int    savedmask = wdcdebug_mask;
 #endif
@@ -741,17 +761,6 @@ wdcattach(struct channel_softc *chp)
                wdcdebug_mask = DEBUG_PROBE;
        }
 #endif /* WDCDEBUG */
-
-       /* initialise global data */
-       s = splbio();
-       if (inited == 0) {
-               /* Initialize the wdc_xfer pool. */
-               pool_init(&wdc_xfer_pool, sizeof(struct wdc_xfer), 0,
-                   0, 0, "wdcspl", NULL);
-               inited++;
-       }
-       TAILQ_INIT(&chp->ch_queue->sc_xfer);
-       splx(s);
 
        for (i = 0; i < 2; i++) {
                struct ata_drive_datas *drvp = &chp->ch_drive[i];
Index: dev/ic/wdcvar.h
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/dev/ic/wdcvar.h,v
retrieving revision 1.49
diff -u -p -r1.49 wdcvar.h
--- dev/ic/wdcvar.h     18 Apr 2011 04:16:14 -0000      1.49
+++ dev/ic/wdcvar.h     8 May 2011 21:14:12 -0000
@@ -266,6 +266,7 @@ int   wdcprobe(struct channel_softc *);
 void  wdcattach(struct channel_softc *);
 int   wdcdetach(struct channel_softc *, int);
 int   wdcintr(void *);
+struct channel_queue *wdc_alloc_queue(void);
 void  wdc_exec_xfer(struct channel_softc *, struct wdc_xfer *);
 struct wdc_xfer *wdc_get_xfer(int); /* int = WDC_NOSLEEP/CANSLEEP */
 #define WDC_CANSLEEP   0x00
Index: dev/isa/wdc_isa.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/dev/isa/wdc_isa.c,v
retrieving revision 1.13
diff -u -p -r1.13 wdc_isa.c
--- dev/isa/wdc_isa.c   26 Jun 2008 05:42:16 -0000      1.13
+++ dev/isa/wdc_isa.c   8 May 2011 21:13:29 -0000
@@ -164,10 +164,9 @@ wdc_isa_attach(struct device *parent, st
        sc->sc_wdcdev.nchannels = 1;
        sc->wdc_channel.channel = 0;
        sc->wdc_channel.wdc = &sc->sc_wdcdev;
-       sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
-           M_DEVBUF, M_NOWAIT);
+       sc->wdc_channel.ch_queue = wdc_alloc_queue();
        if (sc->wdc_channel.ch_queue == NULL) {
-               printf("%s: can't allocate memory for command queue",
+               printf("%s: cannot allocate channel queue",
                    sc->sc_wdcdev.sc_dev.dv_xname);
                return;
        }
Index: dev/isa/wdc_isapnp.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/dev/isa/wdc_isapnp.c,v
retrieving revision 1.8
diff -u -p -r1.8 wdc_isapnp.c
--- dev/isa/wdc_isapnp.c        26 Jun 2008 05:42:16 -0000      1.8
+++ dev/isa/wdc_isapnp.c        8 May 2011 21:13:29 -0000
@@ -135,10 +135,9 @@ wdc_isapnp_attach(parent, self, aux)
        sc->sc_wdcdev.nchannels = 1;
        sc->wdc_channel.channel = 0;
        sc->wdc_channel.wdc = &sc->sc_wdcdev;
-       sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
-           M_DEVBUF, M_NOWAIT);
+       sc->wdc_channel.ch_queue = wdc_alloc_queue();
        if (sc->wdc_channel.ch_queue == NULL) {
-               printf(": can't allocate memory for command queue\n");
+               printf(": cannot allocate channel queue\n");
                return;
        }
 
Index: dev/pci/pciide.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/dev/pci/pciide.c,v
retrieving revision 1.328
diff -u -p -r1.328 pciide.c
--- dev/pci/pciide.c    27 Apr 2011 07:55:05 -0000      1.328
+++ dev/pci/pciide.c    8 May 2011 21:27:46 -0000
@@ -2155,11 +2155,10 @@ pciide_chansetup(struct pciide_softc *sc
        cp->name = PCIIDE_CHANNEL_NAME(channel);
        cp->wdc_channel.channel = channel;
        cp->wdc_channel.wdc = &sc->sc_wdcdev;
-       cp->wdc_channel.ch_queue =
-           malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+       cp->wdc_channel.ch_queue = wdc_alloc_queue();
        if (cp->wdc_channel.ch_queue == NULL) {
                printf("%s: %s "
-                   "cannot allocate memory for command queue",
+                   "cannot allocate channel queue",
                    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
                return (0);
        }
@@ -3636,12 +3635,11 @@ cmd_channel_map(struct pci_attach_args *
                cp->wdc_channel.ch_queue =
                    sc->pciide_channels[0].wdc_channel.ch_queue;
        } else {
-               cp->wdc_channel.ch_queue =
-                   malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+               cp->wdc_channel.ch_queue = wdc_alloc_queue();
        }
        if (cp->wdc_channel.ch_queue == NULL) {
                printf(
-                   "%s: %s cannot allocate memory for command queue",
+                   "%s: %s cannot allocate channel queue",
                    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
                return;
        }
@@ -4001,11 +3999,10 @@ cmd680_channel_map(struct pci_attach_arg
        cp->wdc_channel.channel = channel;
        cp->wdc_channel.wdc = &sc->sc_wdcdev;
 
-       cp->wdc_channel.ch_queue =
-           malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+       cp->wdc_channel.ch_queue = wdc_alloc_queue();
        if (cp->wdc_channel.ch_queue == NULL) {
                printf("%s %s: "
-                   "can't allocate memory for command queue",
+                   "cannot allocate channel queue",
                    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
                    return;
        }
@@ -4610,11 +4607,10 @@ sii3114_chansetup(struct pciide_softc *s
        cp->name = channel_names[channel];
        cp->wdc_channel.channel = channel;
        cp->wdc_channel.wdc = &sc->sc_wdcdev;
-       cp->wdc_channel.ch_queue =
-           malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+       cp->wdc_channel.ch_queue = wdc_alloc_queue();
        if (cp->wdc_channel.ch_queue == NULL) {
                printf("%s %s channel: "
-                   "can't allocate memory for command queue",
+                   "cannot allocate channel queue",
                    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);
                return (0);
        }
@@ -4810,10 +4806,9 @@ cy693_chip_map(struct pciide_softc *sc, 
        cp->name = PCIIDE_CHANNEL_NAME(0);
        cp->wdc_channel.channel = 0;
        cp->wdc_channel.wdc = &sc->sc_wdcdev;
-       cp->wdc_channel.ch_queue =
-           malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+       cp->wdc_channel.ch_queue = wdc_alloc_queue();
        if (cp->wdc_channel.ch_queue == NULL) {
-               printf(": cannot allocate memory for command queue\n");
+               printf(": cannot allocate channel queue\n");
                return;
        }
        printf(", %s %s to ", PCIIDE_CHANNEL_NAME(0),
@@ -6810,11 +6805,10 @@ pdcsata_chip_map(struct pciide_softc *sc
                cp->name = NULL;
                cp->wdc_channel.channel = channel;
                cp->wdc_channel.wdc = &sc->sc_wdcdev;
-               cp->wdc_channel.ch_queue =
-                   malloc(sizeof(struct channel_queue), M_DEVBUF, M_NOWAIT);
+               cp->wdc_channel.ch_queue = wdc_alloc_queue();
                if (cp->wdc_channel.ch_queue == NULL) {
                        printf("%s: channel %d: "
-                           "can't allocate memory for command queue\n",
+                           "cannot allocate channel queue\n",
                        sc->sc_wdcdev.sc_dev.dv_xname, channel);
                        continue;
                }
Index: dev/pcmcia/wdc_pcmcia.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/sys/dev/pcmcia/wdc_pcmcia.c,v
retrieving revision 1.25
diff -u -p -r1.25 wdc_pcmcia.c
--- dev/pcmcia/wdc_pcmcia.c     31 Mar 2011 13:05:27 -0000      1.25
+++ dev/pcmcia/wdc_pcmcia.c     8 May 2011 21:13:29 -0000
@@ -343,10 +343,9 @@ wdc_pcmcia_attach(parent, self, aux)
        sc->sc_wdcdev.nchannels = 1;
        sc->wdc_channel.channel = 0;
        sc->wdc_channel.wdc = &sc->sc_wdcdev;
-       sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
-           M_DEVBUF, M_NOWAIT);
+       sc->wdc_channel.ch_queue = wdc_alloc_queue();
        if (sc->wdc_channel.ch_queue == NULL) {
-               printf("can't allocate memory for command queue\n");
+               printf("cannot allocate channel queue\n");
                goto ch_queue_alloc_failed;
        }
        if (quirks & WDC_PCMCIA_NO_EXTRA_RESETS)

Reply via email to