Home | History | Annotate | Line # | Download | only in ata
ld_ataraid.c revision 1.48
      1  1.48  jdolecek /*	$NetBSD: ld_ataraid.c,v 1.48 2018/10/23 22:05:01 jdolecek Exp $ */
      2   1.1   thorpej 
      3   1.1   thorpej /*
      4   1.1   thorpej  * Copyright (c) 2003 Wasabi Systems, Inc.
      5   1.1   thorpej  * All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8   1.1   thorpej  *
      9   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     10   1.1   thorpej  * modification, are permitted provided that the following conditions
     11   1.1   thorpej  * are met:
     12   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     13   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     14   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     16   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     17   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     18   1.1   thorpej  *    must display the following acknowledgement:
     19   1.1   thorpej  *	This product includes software developed for the NetBSD Project by
     20   1.1   thorpej  *	Wasabi Systems, Inc.
     21   1.1   thorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22   1.1   thorpej  *    or promote products derived from this software without specific prior
     23   1.1   thorpej  *    written permission.
     24   1.1   thorpej  *
     25   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26   1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27   1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28   1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29   1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30   1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31   1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32   1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33   1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34   1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35   1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     36   1.1   thorpej  */
     37   1.1   thorpej 
     38   1.1   thorpej /*
     39   1.1   thorpej  * Support for ATA RAID logical disks.
     40   1.1   thorpej  *
     41   1.1   thorpej  * Note that all the RAID happens in software here; the ATA RAID
     42   1.1   thorpej  * controllers we're dealing with (Promise, etc.) only support
     43   1.1   thorpej  * configuration data on the component disks, with the BIOS supporting
     44   1.1   thorpej  * booting from the RAID volumes.
     45  1.45    martin  *
     46  1.30      tron  * bio(4) support was written by Juan Romero Pardines <xtraeme (at) gmail.com>.
     47   1.1   thorpej  */
     48   1.8     lukem 
     49   1.8     lukem #include <sys/cdefs.h>
     50  1.48  jdolecek __KERNEL_RCSID(0, "$NetBSD: ld_ataraid.c,v 1.48 2018/10/23 22:05:01 jdolecek Exp $");
     51   1.1   thorpej 
     52  1.43  pgoyette #if defined(_KERNEL_OPT)
     53  1.30      tron #include "bio.h"
     54  1.43  pgoyette #endif
     55   1.1   thorpej 
     56   1.1   thorpej #include <sys/param.h>
     57   1.1   thorpej #include <sys/systm.h>
     58   1.1   thorpej #include <sys/conf.h>
     59   1.1   thorpej #include <sys/kernel.h>
     60   1.1   thorpej #include <sys/device.h>
     61   1.1   thorpej #include <sys/buf.h>
     62  1.13      yamt #include <sys/bufq.h>
     63   1.1   thorpej #include <sys/dkio.h>
     64   1.1   thorpej #include <sys/disk.h>
     65   1.1   thorpej #include <sys/disklabel.h>
     66   1.1   thorpej #include <sys/fcntl.h>
     67   1.1   thorpej #include <sys/vnode.h>
     68  1.16      elad #include <sys/kauth.h>
     69  1.43  pgoyette #include <sys/module.h>
     70  1.30      tron #if NBIO > 0
     71  1.30      tron #include <dev/ata/atavar.h>
     72  1.30      tron #include <dev/ata/atareg.h>
     73  1.30      tron #include <dev/ata/wdvar.h>
     74  1.30      tron #include <dev/biovar.h>
     75  1.30      tron #include <dev/scsipi/scsipiconf.h> /* for scsipi_strvis() */
     76  1.30      tron #endif
     77   1.1   thorpej 
     78   1.1   thorpej #include <miscfs/specfs/specdev.h>
     79   1.1   thorpej 
     80   1.1   thorpej #include <dev/ldvar.h>
     81   1.1   thorpej 
     82   1.1   thorpej #include <dev/ata/ata_raidvar.h>
     83   1.1   thorpej 
     84  1.43  pgoyette #include "ioconf.h"
     85  1.43  pgoyette 
     86   1.1   thorpej struct ld_ataraid_softc {
     87   1.1   thorpej 	struct ld_softc sc_ld;
     88   1.1   thorpej 
     89   1.1   thorpej 	struct ataraid_array_info *sc_aai;
     90   1.1   thorpej 	struct vnode *sc_vnodes[ATA_RAID_MAX_DISKS];
     91   1.1   thorpej 
     92   1.1   thorpej 	void	(*sc_iodone)(struct buf *);
     93  1.36       bsh 
     94  1.45    martin 	pool_cache_t sc_cbufpool;
     95  1.36       bsh 
     96  1.45    martin 	SIMPLEQ_HEAD(, cbuf) sc_cbufq;
     97  1.36       bsh 
     98  1.45    martin 	void	*sc_sih_cookie;
     99   1.1   thorpej };
    100   1.1   thorpej 
    101  1.35    cegger static int	ld_ataraid_match(device_t, cfdata_t, void *);
    102  1.35    cegger static void	ld_ataraid_attach(device_t, device_t, void *);
    103   1.1   thorpej 
    104   1.1   thorpej static int	ld_ataraid_dump(struct ld_softc *, void *, int, int);
    105  1.48  jdolecek static int	ld_ataraid_ioctl(struct ld_softc *, u_long, void *, int32_t,
    106  1.48  jdolecek     bool);
    107   1.1   thorpej 
    108  1.36       bsh static int     cbufpool_ctor(void *, void *, int);
    109  1.36       bsh static void    cbufpool_dtor(void *, void *);
    110  1.36       bsh 
    111  1.36       bsh static void    ld_ataraid_start_vstrategy(void *);
    112   1.1   thorpej static int	ld_ataraid_start_span(struct ld_softc *, struct buf *);
    113   1.1   thorpej 
    114   1.1   thorpej static int	ld_ataraid_start_raid0(struct ld_softc *, struct buf *);
    115   1.1   thorpej static void	ld_ataraid_iodone_raid0(struct buf *);
    116   1.1   thorpej 
    117  1.30      tron #if NBIO > 0
    118  1.30      tron static int	ld_ataraid_bioctl(device_t, u_long, void *);
    119  1.30      tron static int	ld_ataraid_bioinq(struct ld_ataraid_softc *, struct bioc_inq *);
    120  1.30      tron static int	ld_ataraid_biovol(struct ld_ataraid_softc *, struct bioc_vol *);
    121  1.30      tron static int	ld_ataraid_biodisk(struct ld_ataraid_softc *,
    122  1.30      tron 				   struct bioc_disk *);
    123  1.30      tron #endif
    124  1.30      tron 
    125  1.27   xtraeme CFATTACH_DECL_NEW(ld_ataraid, sizeof(struct ld_ataraid_softc),
    126   1.1   thorpej     ld_ataraid_match, ld_ataraid_attach, NULL, NULL);
    127   1.1   thorpej 
    128   1.1   thorpej struct cbuf {
    129  1.45    martin 	struct buf	cb_buf; 	/* new I/O buf */
    130   1.1   thorpej 	struct buf	*cb_obp;	/* ptr. to original I/O buf */
    131  1.45    martin 	struct ld_ataraid_softc *cb_sc; /* pointer to ld softc */
    132   1.1   thorpej 	u_int		cb_comp;	/* target component */
    133   1.1   thorpej 	SIMPLEQ_ENTRY(cbuf) cb_q;	/* fifo of component buffers */
    134  1.12     enami 	struct cbuf	*cb_other;	/* other cbuf in case of mirror */
    135  1.12     enami 	int		cb_flags;
    136  1.45    martin #define CBUF_IODONE	0x00000001	/* I/O is already successfully done */
    137   1.1   thorpej };
    138   1.1   thorpej 
    139  1.36       bsh #define        CBUF_GET()      pool_cache_get(sc->sc_cbufpool, PR_NOWAIT);
    140  1.36       bsh #define        CBUF_PUT(cbp)   pool_cache_put(sc->sc_cbufpool, (cbp))
    141   1.1   thorpej 
    142   1.1   thorpej static int
    143  1.27   xtraeme ld_ataraid_match(device_t parent, cfdata_t match, void *aux)
    144   1.1   thorpej {
    145   1.1   thorpej 
    146   1.1   thorpej 	return (1);
    147   1.1   thorpej }
    148   1.1   thorpej 
    149   1.1   thorpej static void
    150  1.27   xtraeme ld_ataraid_attach(device_t parent, device_t self, void *aux)
    151   1.1   thorpej {
    152  1.27   xtraeme 	struct ld_ataraid_softc *sc = device_private(self);
    153   1.1   thorpej 	struct ld_softc *ld = &sc->sc_ld;
    154   1.1   thorpej 	struct ataraid_array_info *aai = aux;
    155  1.32      tron 	struct ataraid_disk_info *adi = NULL;
    156   1.1   thorpej 	const char *level;
    157   1.1   thorpej 	struct vnode *vp;
    158   1.1   thorpej 	char unklev[32];
    159   1.1   thorpej 	u_int i;
    160   1.1   thorpej 
    161  1.29      tron 	ld->sc_dv = self;
    162  1.29      tron 
    163  1.45    martin 	sc->sc_cbufpool = pool_cache_init(sizeof(struct cbuf), 0,
    164  1.45    martin 	    0, 0, "ldcbuf", NULL, IPL_BIO, cbufpool_ctor, cbufpool_dtor, sc);
    165  1.45    martin 	sc->sc_sih_cookie = softint_establish(SOFTINT_BIO,
    166  1.45    martin 	    ld_ataraid_start_vstrategy, sc);
    167   1.1   thorpej 
    168   1.1   thorpej 	sc->sc_aai = aai;	/* this data persists */
    169   1.1   thorpej 
    170   1.1   thorpej 	ld->sc_maxxfer = MAXPHYS * aai->aai_width;	/* XXX */
    171   1.1   thorpej 	ld->sc_secperunit = aai->aai_capacity;
    172   1.1   thorpej 	ld->sc_secsize = 512;				/* XXX */
    173   1.1   thorpej 	ld->sc_maxqueuecnt = 128;			/* XXX */
    174   1.1   thorpej 	ld->sc_dump = ld_ataraid_dump;
    175  1.48  jdolecek 	ld->sc_ioctl = ld_ataraid_ioctl;
    176   1.1   thorpej 
    177   1.1   thorpej 	switch (aai->aai_level) {
    178   1.1   thorpej 	case AAI_L_SPAN:
    179   1.1   thorpej 		level = "SPAN";
    180   1.1   thorpej 		ld->sc_start = ld_ataraid_start_span;
    181   1.1   thorpej 		sc->sc_iodone = ld_ataraid_iodone_raid0;
    182   1.1   thorpej 		break;
    183   1.1   thorpej 
    184   1.1   thorpej 	case AAI_L_RAID0:
    185   1.9   thorpej 		level = "RAID-0";
    186   1.1   thorpej 		ld->sc_start = ld_ataraid_start_raid0;
    187   1.1   thorpej 		sc->sc_iodone = ld_ataraid_iodone_raid0;
    188   1.1   thorpej 		break;
    189   1.1   thorpej 
    190   1.1   thorpej 	case AAI_L_RAID1:
    191   1.9   thorpej 		level = "RAID-1";
    192  1.12     enami 		ld->sc_start = ld_ataraid_start_raid0;
    193  1.12     enami 		sc->sc_iodone = ld_ataraid_iodone_raid0;
    194   1.1   thorpej 		break;
    195   1.1   thorpej 
    196   1.1   thorpej 	case AAI_L_RAID0 | AAI_L_RAID1:
    197   1.9   thorpej 		level = "RAID-10";
    198  1.12     enami 		ld->sc_start = ld_ataraid_start_raid0;
    199  1.12     enami 		sc->sc_iodone = ld_ataraid_iodone_raid0;
    200   1.1   thorpej 		break;
    201   1.1   thorpej 
    202   1.1   thorpej 	default:
    203  1.11    itojun 		snprintf(unklev, sizeof(unklev), "<unknown level 0x%x>",
    204  1.11    itojun 		    aai->aai_level);
    205   1.1   thorpej 		level = unklev;
    206   1.1   thorpej 	}
    207   1.1   thorpej 
    208   1.1   thorpej 	aprint_naive(": ATA %s array\n", level);
    209   1.1   thorpej 	aprint_normal(": %s ATA %s array\n",
    210   1.1   thorpej 	    ata_raid_type_name(aai->aai_type), level);
    211   1.1   thorpej 
    212   1.1   thorpej 	if (ld->sc_start == NULL) {
    213  1.29      tron 		aprint_error_dev(ld->sc_dv, "unsupported array type\n");
    214   1.1   thorpej 		return;
    215   1.1   thorpej 	}
    216   1.1   thorpej 
    217   1.1   thorpej 	/*
    218   1.1   thorpej 	 * We get a geometry from the device; use it.
    219   1.1   thorpej 	 */
    220   1.1   thorpej 	ld->sc_nheads = aai->aai_heads;
    221   1.1   thorpej 	ld->sc_nsectors = aai->aai_sectors;
    222   1.1   thorpej 	ld->sc_ncylinders = aai->aai_cylinders;
    223   1.1   thorpej 
    224   1.1   thorpej 	/*
    225   1.1   thorpej 	 * Configure all the component disks.
    226   1.1   thorpej 	 */
    227   1.1   thorpej 	for (i = 0; i < aai->aai_ndisks; i++) {
    228  1.32      tron 		adi = &aai->aai_disks[i];
    229  1.32      tron 		vp = ata_raid_disk_vnode_find(adi);
    230  1.32      tron 		if (vp == NULL) {
    231   1.1   thorpej 			/*
    232   1.1   thorpej 			 * XXX This is bogus.  We should just mark the
    233   1.1   thorpej 			 * XXX component as FAILED, and write-back new
    234   1.1   thorpej 			 * XXX config blocks.
    235   1.1   thorpej 			 */
    236   1.3   thorpej 			break;
    237   1.1   thorpej 		}
    238   1.1   thorpej 		sc->sc_vnodes[i] = vp;
    239   1.1   thorpej 	}
    240   1.3   thorpej 	if (i == aai->aai_ndisks) {
    241   1.3   thorpej 		ld->sc_flags = LDF_ENABLED;
    242   1.3   thorpej 		goto finish;
    243   1.3   thorpej 	}
    244   1.1   thorpej 
    245   1.1   thorpej 	for (i = 0; i < aai->aai_ndisks; i++) {
    246   1.1   thorpej 		vp = sc->sc_vnodes[i];
    247   1.1   thorpej 		sc->sc_vnodes[i] = NULL;
    248   1.3   thorpej 		if (vp != NULL)
    249  1.25        ad 			(void) vn_close(vp, FREAD|FWRITE, NOCRED);
    250   1.1   thorpej 	}
    251   1.3   thorpej 
    252   1.3   thorpej  finish:
    253  1.30      tron #if NBIO > 0
    254  1.30      tron 	if (bio_register(self, ld_ataraid_bioctl) != 0)
    255  1.30      tron 		panic("%s: bioctl registration failed\n",
    256  1.30      tron 		    device_xname(ld->sc_dv));
    257  1.30      tron #endif
    258  1.42  jdolecek 	SIMPLEQ_INIT(&sc->sc_cbufq);
    259  1.42  jdolecek 	ldattach(ld, BUFQ_DISK_DEFAULT_STRAT);
    260   1.1   thorpej }
    261   1.1   thorpej 
    262  1.36       bsh static int
    263  1.36       bsh cbufpool_ctor(void *arg, void *obj, int flags)
    264  1.36       bsh {
    265  1.45    martin 	struct ld_ataraid_softc *sc = arg;
    266  1.45    martin 	struct ld_softc *ld = &sc->sc_ld;
    267  1.45    martin 	struct cbuf *cbp = obj;
    268  1.45    martin 
    269  1.45    martin 	/* We release/reacquire the spinlock before calling buf_init() */
    270  1.45    martin 	mutex_exit(&ld->sc_mutex);
    271  1.45    martin 	buf_init(&cbp->cb_buf);
    272  1.45    martin 	mutex_enter(&ld->sc_mutex);
    273  1.36       bsh 
    274  1.45    martin 	return 0;
    275  1.36       bsh }
    276  1.36       bsh 
    277  1.36       bsh static void
    278  1.36       bsh cbufpool_dtor(void *arg, void *obj)
    279  1.36       bsh {
    280  1.45    martin 	struct cbuf *cbp = obj;
    281  1.36       bsh 
    282  1.45    martin 	buf_destroy(&cbp->cb_buf);
    283  1.36       bsh }
    284  1.36       bsh 
    285   1.1   thorpej static struct cbuf *
    286   1.1   thorpej ld_ataraid_make_cbuf(struct ld_ataraid_softc *sc, struct buf *bp,
    287  1.19  christos     u_int comp, daddr_t bn, void *addr, long bcount)
    288   1.1   thorpej {
    289   1.1   thorpej 	struct cbuf *cbp;
    290   1.1   thorpej 
    291   1.1   thorpej 	cbp = CBUF_GET();
    292   1.1   thorpej 	if (cbp == NULL)
    293  1.45    martin 		return NULL;
    294  1.23        ad 	cbp->cb_buf.b_flags = bp->b_flags;
    295  1.23        ad 	cbp->cb_buf.b_oflags = bp->b_oflags;
    296  1.23        ad 	cbp->cb_buf.b_cflags = bp->b_cflags;
    297   1.1   thorpej 	cbp->cb_buf.b_iodone = sc->sc_iodone;
    298   1.1   thorpej 	cbp->cb_buf.b_proc = bp->b_proc;
    299   1.1   thorpej 	cbp->cb_buf.b_vp = sc->sc_vnodes[comp];
    300  1.38     rmind 	cbp->cb_buf.b_objlock = sc->sc_vnodes[comp]->v_interlock;
    301   1.1   thorpej 	cbp->cb_buf.b_blkno = bn + sc->sc_aai->aai_offset;
    302   1.1   thorpej 	cbp->cb_buf.b_data = addr;
    303   1.1   thorpej 	cbp->cb_buf.b_bcount = bcount;
    304   1.1   thorpej 
    305   1.1   thorpej 	/* Context for iodone */
    306   1.1   thorpej 	cbp->cb_obp = bp;
    307   1.1   thorpej 	cbp->cb_sc = sc;
    308   1.1   thorpej 	cbp->cb_comp = comp;
    309  1.12     enami 	cbp->cb_other = NULL;
    310  1.12     enami 	cbp->cb_flags = 0;
    311   1.1   thorpej 
    312  1.45    martin 	return cbp;
    313  1.36       bsh }
    314  1.36       bsh 
    315  1.36       bsh static void
    316  1.36       bsh ld_ataraid_start_vstrategy(void *arg)
    317  1.36       bsh {
    318  1.45    martin 	struct ld_ataraid_softc *sc = arg;
    319  1.45    martin 	struct cbuf *cbp;
    320  1.36       bsh 
    321  1.45    martin 	while ((cbp = SIMPLEQ_FIRST(&sc->sc_cbufq)) != NULL) {
    322  1.45    martin 	    SIMPLEQ_REMOVE_HEAD(&sc->sc_cbufq, cb_q);
    323  1.45    martin 		if ((cbp->cb_buf.b_flags & B_READ) == 0) {
    324  1.45    martin 			mutex_enter(cbp->cb_buf.b_vp->v_interlock);
    325  1.45    martin 			cbp->cb_buf.b_vp->v_numoutput++;
    326  1.45    martin 			mutex_exit(cbp->cb_buf.b_vp->v_interlock);
    327  1.45    martin 		}
    328  1.45    martin 		VOP_STRATEGY(cbp->cb_buf.b_vp, &cbp->cb_buf);
    329  1.45    martin 	}
    330   1.1   thorpej }
    331   1.1   thorpej 
    332   1.1   thorpej static int
    333   1.1   thorpej ld_ataraid_start_span(struct ld_softc *ld, struct buf *bp)
    334   1.1   thorpej {
    335   1.1   thorpej 	struct ld_ataraid_softc *sc = (void *) ld;
    336   1.1   thorpej 	struct ataraid_array_info *aai = sc->sc_aai;
    337   1.1   thorpej 	struct ataraid_disk_info *adi;
    338   1.1   thorpej 	struct cbuf *cbp;
    339  1.19  christos 	char *addr;
    340   1.1   thorpej 	daddr_t bn;
    341   1.1   thorpej 	long bcount, rcount;
    342   1.1   thorpej 	u_int comp;
    343   1.1   thorpej 
    344   1.1   thorpej 	/* Allocate component buffers. */
    345   1.1   thorpej 	addr = bp->b_data;
    346   1.1   thorpej 
    347   1.1   thorpej 	/* Find the first component. */
    348   1.1   thorpej 	comp = 0;
    349   1.1   thorpej 	adi = &aai->aai_disks[comp];
    350   1.1   thorpej 	bn = bp->b_rawblkno;
    351   1.1   thorpej 	while (bn >= adi->adi_compsize) {
    352   1.1   thorpej 		bn -= adi->adi_compsize;
    353   1.1   thorpej 		adi = &aai->aai_disks[++comp];
    354   1.1   thorpej 	}
    355   1.1   thorpej 
    356   1.1   thorpej 	bp->b_resid = bp->b_bcount;
    357   1.1   thorpej 
    358   1.1   thorpej 	for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) {
    359   1.1   thorpej 		rcount = bp->b_bcount;
    360   1.1   thorpej 		if ((adi->adi_compsize - bn) < btodb(rcount))
    361   1.1   thorpej 			rcount = dbtob(adi->adi_compsize - bn);
    362   1.1   thorpej 
    363   1.1   thorpej 		cbp = ld_ataraid_make_cbuf(sc, bp, comp, bn, addr, rcount);
    364   1.1   thorpej 		if (cbp == NULL) {
    365   1.1   thorpej 			/* Free the already allocated component buffers. */
    366  1.45    martin 		       while ((cbp = SIMPLEQ_FIRST(&sc->sc_cbufq)) != NULL) {
    367  1.45    martin 			       SIMPLEQ_REMOVE_HEAD(&sc->sc_cbufq, cb_q);
    368   1.1   thorpej 				CBUF_PUT(cbp);
    369   1.1   thorpej 			}
    370  1.45    martin 		       return EAGAIN;
    371   1.1   thorpej 		}
    372   1.1   thorpej 
    373   1.1   thorpej 		/*
    374   1.1   thorpej 		 * For a span, we always know we advance to the next disk,
    375   1.1   thorpej 		 * and always start at offset 0 on that disk.
    376   1.1   thorpej 		 */
    377   1.1   thorpej 		adi = &aai->aai_disks[++comp];
    378   1.1   thorpej 		bn = 0;
    379   1.1   thorpej 
    380  1.45    martin 	       SIMPLEQ_INSERT_TAIL(&sc->sc_cbufq, cbp, cb_q);
    381   1.1   thorpej 		addr += rcount;
    382   1.1   thorpej 	}
    383   1.1   thorpej 
    384   1.1   thorpej 	/* Now fire off the requests. */
    385  1.45    martin 	softint_schedule(sc->sc_sih_cookie);
    386   1.1   thorpej 
    387  1.45    martin 	return 0;
    388   1.1   thorpej }
    389   1.1   thorpej 
    390   1.1   thorpej static int
    391   1.1   thorpej ld_ataraid_start_raid0(struct ld_softc *ld, struct buf *bp)
    392   1.1   thorpej {
    393  1.45    martin 	struct ld_ataraid_softc *sc = (void *)ld;
    394   1.1   thorpej 	struct ataraid_array_info *aai = sc->sc_aai;
    395  1.12     enami 	struct ataraid_disk_info *adi;
    396  1.12     enami 	struct cbuf *cbp, *other_cbp;
    397  1.19  christos 	char *addr;
    398   1.1   thorpej 	daddr_t bn, cbn, tbn, off;
    399   1.1   thorpej 	long bcount, rcount;
    400   1.1   thorpej 	u_int comp;
    401  1.12     enami 	const int read = bp->b_flags & B_READ;
    402  1.12     enami 	const int mirror = aai->aai_level & AAI_L_RAID1;
    403  1.45    martin 	int error = 0;
    404   1.1   thorpej 
    405   1.1   thorpej 	/* Allocate component buffers. */
    406   1.1   thorpej 	addr = bp->b_data;
    407   1.1   thorpej 	bn = bp->b_rawblkno;
    408   1.1   thorpej 
    409   1.1   thorpej 	bp->b_resid = bp->b_bcount;
    410   1.1   thorpej 
    411   1.1   thorpej 	for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) {
    412   1.1   thorpej 		tbn = bn / aai->aai_interleave;
    413   1.1   thorpej 		off = bn % aai->aai_interleave;
    414   1.1   thorpej 
    415   1.1   thorpej 		if (__predict_false(tbn == aai->aai_capacity /
    416   1.1   thorpej 					   aai->aai_interleave)) {
    417   1.1   thorpej 			/* Last stripe. */
    418   1.1   thorpej 			daddr_t sz = (aai->aai_capacity -
    419   1.1   thorpej 				      (tbn * aai->aai_interleave)) /
    420   1.1   thorpej 				     aai->aai_width;
    421   1.1   thorpej 			comp = off / sz;
    422   1.1   thorpej 			cbn = ((tbn / aai->aai_width) * aai->aai_interleave) +
    423   1.1   thorpej 			    (off % sz);
    424  1.46  riastrad 			rcount = uimin(bcount, dbtob(sz));
    425   1.1   thorpej 		} else {
    426   1.1   thorpej 			comp = tbn % aai->aai_width;
    427   1.1   thorpej 			cbn = ((tbn / aai->aai_width) * aai->aai_interleave) +
    428   1.1   thorpej 			    off;
    429  1.46  riastrad 			rcount = uimin(bcount, dbtob(aai->aai_interleave - off));
    430   1.1   thorpej 		}
    431   1.1   thorpej 
    432  1.12     enami 		/*
    433  1.12     enami 		 * See if a component is valid.
    434  1.12     enami 		 */
    435  1.12     enami try_mirror:
    436  1.12     enami 		adi = &aai->aai_disks[comp];
    437  1.12     enami 		if ((adi->adi_status & ADI_S_ONLINE) == 0) {
    438  1.12     enami 			if (mirror && comp < aai->aai_width) {
    439  1.12     enami 				comp += aai->aai_width;
    440  1.12     enami 				goto try_mirror;
    441  1.12     enami 			}
    442  1.12     enami 
    443  1.12     enami 			/*
    444  1.12     enami 			 * No component available.
    445  1.12     enami 			 */
    446  1.12     enami 			error = EIO;
    447  1.12     enami 			goto free_and_exit;
    448  1.12     enami 		}
    449  1.12     enami 
    450   1.1   thorpej 		cbp = ld_ataraid_make_cbuf(sc, bp, comp, cbn, addr, rcount);
    451   1.1   thorpej 		if (cbp == NULL) {
    452  1.12     enami resource_shortage:
    453  1.12     enami 			error = EAGAIN;
    454  1.12     enami free_and_exit:
    455   1.1   thorpej 			/* Free the already allocated component buffers. */
    456  1.45    martin 		       while ((cbp = SIMPLEQ_FIRST(&sc->sc_cbufq)) != NULL) {
    457  1.45    martin 			       SIMPLEQ_REMOVE_HEAD(&sc->sc_cbufq, cb_q);
    458   1.1   thorpej 				CBUF_PUT(cbp);
    459   1.1   thorpej 			}
    460  1.45    martin 		       return error;
    461   1.1   thorpej 		}
    462  1.45    martin 	       SIMPLEQ_INSERT_TAIL(&sc->sc_cbufq, cbp, cb_q);
    463  1.12     enami 		if (mirror && !read && comp < aai->aai_width) {
    464  1.12     enami 			comp += aai->aai_width;
    465  1.12     enami 			adi = &aai->aai_disks[comp];
    466  1.12     enami 			if (adi->adi_status & ADI_S_ONLINE) {
    467  1.12     enami 				other_cbp = ld_ataraid_make_cbuf(sc, bp,
    468  1.12     enami 				    comp, cbn, addr, rcount);
    469  1.12     enami 				if (other_cbp == NULL)
    470  1.12     enami 					goto resource_shortage;
    471  1.45    martin 			       SIMPLEQ_INSERT_TAIL(&sc->sc_cbufq,
    472  1.45    martin 				   other_cbp, cb_q);
    473  1.12     enami 				other_cbp->cb_other = cbp;
    474  1.12     enami 				cbp->cb_other = other_cbp;
    475  1.12     enami 			}
    476  1.12     enami 		}
    477   1.1   thorpej 		bn += btodb(rcount);
    478   1.1   thorpej 		addr += rcount;
    479   1.1   thorpej 	}
    480   1.1   thorpej 
    481   1.1   thorpej 	/* Now fire off the requests. */
    482  1.45    martin 	softint_schedule(sc->sc_sih_cookie);
    483   1.1   thorpej 
    484  1.45    martin 	return error;
    485   1.1   thorpej }
    486   1.1   thorpej 
    487   1.1   thorpej /*
    488   1.1   thorpej  * Called at interrupt time.  Mark the component as done and if all
    489   1.1   thorpej  * components are done, take an "interrupt".
    490   1.1   thorpej  */
    491   1.1   thorpej static void
    492   1.1   thorpej ld_ataraid_iodone_raid0(struct buf *vbp)
    493   1.1   thorpej {
    494  1.12     enami 	struct cbuf *cbp = (struct cbuf *) vbp, *other_cbp;
    495   1.1   thorpej 	struct buf *bp = cbp->cb_obp;
    496   1.1   thorpej 	struct ld_ataraid_softc *sc = cbp->cb_sc;
    497  1.12     enami 	struct ataraid_array_info *aai = sc->sc_aai;
    498  1.12     enami 	struct ataraid_disk_info *adi;
    499   1.1   thorpej 	long count;
    500  1.12     enami 	int s, iodone;
    501   1.1   thorpej 
    502   1.1   thorpej 	s = splbio();
    503   1.1   thorpej 
    504  1.12     enami 	iodone = cbp->cb_flags & CBUF_IODONE;
    505  1.12     enami 	other_cbp = cbp->cb_other;
    506  1.12     enami 	if (other_cbp != NULL)
    507  1.12     enami 		/* You are alone */
    508  1.12     enami 		other_cbp->cb_other = NULL;
    509  1.12     enami 
    510  1.21        ad 	if (cbp->cb_buf.b_error != 0) {
    511  1.12     enami 		/*
    512  1.12     enami 		 * Mark this component broken.
    513  1.12     enami 		 */
    514  1.12     enami 		adi = &aai->aai_disks[cbp->cb_comp];
    515  1.12     enami 		adi->adi_status &= ~ADI_S_ONLINE;
    516  1.12     enami 
    517  1.12     enami 		printf("%s: error %d on component %d (%s)\n",
    518  1.29      tron 		    device_xname(sc->sc_ld.sc_dv), bp->b_error, cbp->cb_comp,
    519  1.26    cegger 		    device_xname(adi->adi_dev));
    520  1.12     enami 
    521  1.12     enami 		/*
    522  1.12     enami 		 * If we didn't see an error yet and we are reading
    523  1.12     enami 		 * RAID1 disk, try another component.
    524  1.12     enami 		 */
    525  1.21        ad 		if (bp->b_error == 0 &&
    526  1.12     enami 		    (cbp->cb_buf.b_flags & B_READ) != 0 &&
    527  1.12     enami 		    (aai->aai_level & AAI_L_RAID1) != 0 &&
    528  1.12     enami 		    cbp->cb_comp < aai->aai_width) {
    529  1.12     enami 			cbp->cb_comp += aai->aai_width;
    530  1.12     enami 			adi = &aai->aai_disks[cbp->cb_comp];
    531  1.12     enami 			if (adi->adi_status & ADI_S_ONLINE) {
    532  1.21        ad 				cbp->cb_buf.b_error = 0;
    533  1.12     enami 				VOP_STRATEGY(cbp->cb_buf.b_vp, &cbp->cb_buf);
    534  1.12     enami 				goto out;
    535  1.12     enami 			}
    536  1.12     enami 		}
    537  1.12     enami 
    538  1.12     enami 		if (iodone || other_cbp != NULL)
    539  1.12     enami 			/*
    540  1.12     enami 			 * If I/O on other component successfully done
    541  1.12     enami 			 * or the I/O is still in progress, no need
    542  1.12     enami 			 * to tell an error to upper layer.
    543  1.12     enami 			 */
    544  1.12     enami 			;
    545  1.12     enami 		else {
    546  1.12     enami 			bp->b_error = cbp->cb_buf.b_error ?
    547  1.12     enami 			    cbp->cb_buf.b_error : EIO;
    548  1.12     enami 		}
    549   1.1   thorpej 
    550   1.1   thorpej 		/* XXX Update component config blocks. */
    551   1.1   thorpej 
    552  1.12     enami 	} else {
    553  1.12     enami 		/*
    554  1.12     enami 		 * If other I/O is still in progress, tell it that
    555  1.12     enami 		 * our I/O is successfully done.
    556  1.12     enami 		 */
    557  1.12     enami 		if (other_cbp != NULL)
    558  1.12     enami 			other_cbp->cb_flags |= CBUF_IODONE;
    559   1.1   thorpej 	}
    560   1.1   thorpej 	count = cbp->cb_buf.b_bcount;
    561   1.1   thorpej 	CBUF_PUT(cbp);
    562   1.1   thorpej 
    563  1.12     enami 	if (other_cbp != NULL)
    564  1.12     enami 		goto out;
    565  1.12     enami 
    566   1.1   thorpej 	/* If all done, "interrupt". */
    567   1.1   thorpej 	bp->b_resid -= count;
    568   1.1   thorpej 	if (bp->b_resid < 0)
    569   1.1   thorpej 		panic("ld_ataraid_iodone_raid0: count");
    570   1.1   thorpej 	if (bp->b_resid == 0)
    571   1.1   thorpej 		lddone(&sc->sc_ld, bp);
    572  1.12     enami 
    573  1.12     enami out:
    574   1.1   thorpej 	splx(s);
    575   1.1   thorpej }
    576   1.1   thorpej 
    577   1.1   thorpej static int
    578  1.18  christos ld_ataraid_dump(struct ld_softc *sc, void *data,
    579  1.18  christos     int blkno, int blkcnt)
    580   1.1   thorpej {
    581   1.1   thorpej 
    582   1.1   thorpej 	return (EIO);
    583   1.1   thorpej }
    584  1.30      tron 
    585  1.30      tron #if NBIO > 0
    586  1.30      tron static int
    587  1.30      tron ld_ataraid_bioctl(device_t self, u_long cmd, void *addr)
    588  1.30      tron {
    589  1.30      tron 	struct ld_ataraid_softc *sc = device_private(self);
    590  1.30      tron 	int error = 0;
    591  1.30      tron 
    592  1.30      tron 	switch (cmd) {
    593  1.30      tron 	case BIOCINQ:
    594  1.30      tron 		error = ld_ataraid_bioinq(sc, (struct bioc_inq *)addr);
    595  1.30      tron 		break;
    596  1.30      tron 	case BIOCVOL:
    597  1.30      tron 		error = ld_ataraid_biovol(sc, (struct bioc_vol *)addr);
    598  1.30      tron 		break;
    599  1.30      tron 	case BIOCDISK:
    600  1.30      tron 		error = ld_ataraid_biodisk(sc, (struct bioc_disk *)addr);
    601  1.30      tron 		break;
    602  1.30      tron 	default:
    603  1.30      tron 		error = ENOTTY;
    604  1.30      tron 		break;
    605  1.30      tron 	}
    606  1.30      tron 
    607  1.30      tron 	return error;
    608  1.30      tron }
    609  1.30      tron 
    610  1.30      tron static int
    611  1.30      tron ld_ataraid_bioinq(struct ld_ataraid_softc *sc, struct bioc_inq *bi)
    612  1.30      tron {
    613  1.30      tron 	struct ataraid_array_info *aai = sc->sc_aai;
    614  1.30      tron 
    615  1.30      tron 	/* there's always one volume per ld device */
    616  1.30      tron 	bi->bi_novol = 1;
    617  1.30      tron 	bi->bi_nodisk = aai->aai_ndisks;
    618  1.30      tron 
    619  1.30      tron 	return 0;
    620  1.30      tron }
    621  1.30      tron 
    622  1.30      tron static int
    623  1.30      tron ld_ataraid_biovol(struct ld_ataraid_softc *sc, struct bioc_vol *bv)
    624  1.30      tron {
    625  1.30      tron 	struct ataraid_array_info *aai = sc->sc_aai;
    626  1.30      tron 	struct ld_softc *ld = &sc->sc_ld;
    627  1.45    martin #define to_kibytes(ld,s)	(ld->sc_secsize*(s)/1024)
    628  1.30      tron 
    629  1.30      tron 	/* Fill in data for _this_ volume */
    630  1.30      tron 	bv->bv_percent = -1;
    631  1.30      tron 	bv->bv_seconds = 0;
    632  1.30      tron 
    633  1.30      tron 	switch (aai->aai_status) {
    634  1.30      tron 	case AAI_S_READY:
    635  1.30      tron 		bv->bv_status = BIOC_SVONLINE;
    636  1.30      tron 		break;
    637  1.30      tron 	case AAI_S_DEGRADED:
    638  1.30      tron 		bv->bv_status = BIOC_SVDEGRADED;
    639  1.30      tron 		break;
    640  1.30      tron 	}
    641  1.30      tron 
    642  1.30      tron 	bv->bv_size = ld->sc_secsize * ld->sc_secperunit;
    643  1.30      tron 
    644  1.30      tron 	switch (aai->aai_level) {
    645  1.30      tron 	case AAI_L_SPAN:
    646  1.30      tron 	case AAI_L_RAID0:
    647  1.37       bsh 		bv->bv_stripe_size = to_kibytes(ld, aai->aai_interleave);
    648  1.30      tron 		bv->bv_level = 0;
    649  1.30      tron 		break;
    650  1.30      tron 	case AAI_L_RAID1:
    651  1.30      tron 		bv->bv_stripe_size = 0;
    652  1.30      tron 		bv->bv_level = 1;
    653  1.30      tron 		break;
    654  1.30      tron 	case AAI_L_RAID5:
    655  1.37       bsh 		bv->bv_stripe_size = to_kibytes(ld, aai->aai_interleave);
    656  1.30      tron 		bv->bv_level = 5;
    657  1.30      tron 		break;
    658  1.30      tron 	}
    659  1.30      tron 
    660  1.30      tron 	bv->bv_nodisk = aai->aai_ndisks;
    661  1.30      tron 	strlcpy(bv->bv_dev, device_xname(ld->sc_dv), sizeof(bv->bv_dev));
    662  1.31      tron 	if (aai->aai_name[0] != '\0')
    663  1.31      tron 		strlcpy(bv->bv_vendor, aai->aai_name, sizeof(bv->bv_vendor));
    664  1.30      tron 
    665  1.30      tron 	return 0;
    666  1.30      tron }
    667  1.30      tron 
    668  1.30      tron static int
    669  1.30      tron ld_ataraid_biodisk(struct ld_ataraid_softc *sc, struct bioc_disk *bd)
    670  1.30      tron {
    671  1.30      tron 	struct ataraid_array_info *aai = sc->sc_aai;
    672  1.30      tron 	struct ataraid_disk_info *adi;
    673  1.30      tron 	struct ld_softc *ld = &sc->sc_ld;
    674  1.30      tron 	struct atabus_softc *atabus;
    675  1.30      tron 	struct wd_softc *wd;
    676  1.30      tron 	char model[81], serial[41], rev[17];
    677  1.30      tron 
    678  1.30      tron 	/* sanity check */
    679  1.30      tron 	if (bd->bd_diskid > aai->aai_ndisks)
    680  1.30      tron 		return EINVAL;
    681  1.30      tron 
    682  1.30      tron 	adi = &aai->aai_disks[bd->bd_diskid];
    683  1.30      tron 	atabus = device_private(device_parent(adi->adi_dev));
    684  1.30      tron 	wd = device_private(adi->adi_dev);
    685  1.30      tron 
    686  1.30      tron 	/* fill in data for _this_ disk */
    687  1.30      tron 	switch (adi->adi_status) {
    688  1.30      tron 	case ADI_S_ONLINE | ADI_S_ASSIGNED:
    689  1.30      tron 		bd->bd_status = BIOC_SDONLINE;
    690  1.30      tron 		break;
    691  1.30      tron 	case ADI_S_SPARE:
    692  1.30      tron 		bd->bd_status = BIOC_SDHOTSPARE;
    693  1.30      tron 		break;
    694  1.30      tron 	default:
    695  1.30      tron 		bd->bd_status = BIOC_SDOFFLINE;
    696  1.30      tron 		break;
    697  1.30      tron 	}
    698  1.30      tron 
    699  1.30      tron 	bd->bd_channel = 0;
    700  1.30      tron 	bd->bd_target = atabus->sc_chan->ch_channel;
    701  1.30      tron 	bd->bd_lun = 0;
    702  1.30      tron 	bd->bd_size = (wd->sc_capacity * ld->sc_secsize) - aai->aai_reserved;
    703  1.30      tron 
    704  1.30      tron 	strlcpy(bd->bd_procdev, device_xname(adi->adi_dev),
    705  1.30      tron 	    sizeof(bd->bd_procdev));
    706  1.30      tron 
    707  1.41  christos 	strnvisx(serial, sizeof(serial), wd->sc_params.atap_serial,
    708  1.41  christos 	    sizeof(wd->sc_params.atap_serial), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
    709  1.41  christos 	strnvisx(model, sizeof(model), wd->sc_params.atap_model,
    710  1.41  christos 	    sizeof(wd->sc_params.atap_model), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
    711  1.41  christos 	strnvisx(rev, sizeof(rev), wd->sc_params.atap_revision,
    712  1.41  christos 	    sizeof(wd->sc_params.atap_revision), VIS_TRIM|VIS_SAFE|VIS_OCTAL);
    713  1.30      tron 
    714  1.30      tron 	snprintf(bd->bd_vendor, sizeof(bd->bd_vendor), "%s %s", model, rev);
    715  1.30      tron 	strlcpy(bd->bd_serial, serial, sizeof(bd->bd_serial));
    716  1.30      tron 
    717  1.30      tron 	return 0;
    718  1.30      tron }
    719  1.30      tron #endif /* NBIO > 0 */
    720  1.43  pgoyette 
    721  1.48  jdolecek static int
    722  1.48  jdolecek ld_ataraid_ioctl(struct ld_softc *ld, u_long cmd, void *addr, int32_t flag,
    723  1.48  jdolecek     bool poll)
    724  1.48  jdolecek {
    725  1.48  jdolecek 	struct ld_ataraid_softc *sc = (void *)ld;
    726  1.48  jdolecek 	int error, i, j;
    727  1.48  jdolecek 	kauth_cred_t uc;
    728  1.48  jdolecek 
    729  1.48  jdolecek 	uc = kauth_cred_get();
    730  1.48  jdolecek 
    731  1.48  jdolecek 	switch (cmd) {
    732  1.48  jdolecek 	case DIOCGCACHE:
    733  1.48  jdolecek 	    {
    734  1.48  jdolecek 		int dkcache = 0;
    735  1.48  jdolecek 
    736  1.48  jdolecek 		/*
    737  1.48  jdolecek 		 * We pass this call down to all components and report
    738  1.48  jdolecek 		 * intersection of the flags returned by the components.
    739  1.48  jdolecek 		 * If any errors out, we return error. ATA RAID components
    740  1.48  jdolecek 		 * can only change via BIOS, device feature flags will remain
    741  1.48  jdolecek 		 * static. RCE/WCE can change if set directly on underlying
    742  1.48  jdolecek 		 * device.
    743  1.48  jdolecek 		 */
    744  1.48  jdolecek 		for (error = 0, i = 0; i < sc->sc_aai->aai_ndisks; i++) {
    745  1.48  jdolecek 			KASSERT(sc->sc_vnodes[i] != NULL);
    746  1.48  jdolecek 
    747  1.48  jdolecek 			error = VOP_IOCTL(sc->sc_vnodes[i], cmd, &j,
    748  1.48  jdolecek 				      flag, uc);
    749  1.48  jdolecek 			if (error)
    750  1.48  jdolecek 				break;
    751  1.48  jdolecek 
    752  1.48  jdolecek 			if (i == 0)
    753  1.48  jdolecek 				dkcache = j;
    754  1.48  jdolecek 			else
    755  1.48  jdolecek 				dkcache = DKCACHE_COMBINE(dkcache, j);
    756  1.48  jdolecek 		}
    757  1.48  jdolecek 
    758  1.48  jdolecek 		*((int *)addr) = dkcache;
    759  1.48  jdolecek 		break;
    760  1.48  jdolecek 	    }
    761  1.48  jdolecek 
    762  1.48  jdolecek 	case DIOCCACHESYNC:
    763  1.48  jdolecek 	    {
    764  1.48  jdolecek 		/*
    765  1.48  jdolecek 		 * We pass this call down to all components and report
    766  1.48  jdolecek 		 * the first error we encounter.
    767  1.48  jdolecek 		 */
    768  1.48  jdolecek 		for (error = 0, i = 0; i < sc->sc_aai->aai_ndisks; i++) {
    769  1.48  jdolecek 			KASSERT(sc->sc_vnodes[i] != NULL);
    770  1.48  jdolecek 
    771  1.48  jdolecek 			j = VOP_IOCTL(sc->sc_vnodes[i], cmd, addr,
    772  1.48  jdolecek 				      flag, uc);
    773  1.48  jdolecek 			if (j != 0 && error == 0)
    774  1.48  jdolecek 				error = j;
    775  1.48  jdolecek 		}
    776  1.48  jdolecek 		break;
    777  1.48  jdolecek 	    }
    778  1.48  jdolecek 
    779  1.48  jdolecek 	default:
    780  1.48  jdolecek 		error = EPASSTHROUGH;
    781  1.48  jdolecek 		break;
    782  1.48  jdolecek 	}
    783  1.48  jdolecek 
    784  1.48  jdolecek 	return error;
    785  1.48  jdolecek }
    786  1.48  jdolecek 
    787  1.43  pgoyette MODULE(MODULE_CLASS_DRIVER, ld_ataraid, "ld,ataraid");
    788  1.43  pgoyette 
    789  1.43  pgoyette #ifdef _MODULE
    790  1.43  pgoyette /*
    791  1.43  pgoyette  * XXX Don't allow ioconf.c to redefine the "struct cfdriver ld_ataraid"
    792  1.43  pgoyette  * XXX it will be defined in the common-code module
    793  1.43  pgoyette  */
    794  1.45    martin #undef	CFDRIVER_DECL
    795  1.43  pgoyette #define CFDRIVER_DECL(name, class, attr)
    796  1.43  pgoyette #include "ioconf.c"
    797  1.43  pgoyette #endif
    798  1.43  pgoyette 
    799  1.43  pgoyette static int
    800  1.43  pgoyette ld_ataraid_modcmd(modcmd_t cmd, void *opaque)
    801  1.43  pgoyette {
    802  1.43  pgoyette #ifdef _MODULE
    803  1.43  pgoyette 	/*
    804  1.43  pgoyette 	 * We ignore the cfdriver_vec[] that ioconf provides, since
    805  1.43  pgoyette 	 * the cfdrivers are attached already.
    806  1.43  pgoyette 	 */
    807  1.43  pgoyette 	static struct cfdriver * const no_cfdriver_vec[] = { NULL };
    808  1.43  pgoyette #endif
    809  1.43  pgoyette 	int error = 0;
    810  1.43  pgoyette 
    811  1.43  pgoyette #ifdef _MODULE
    812  1.43  pgoyette 	switch (cmd) {
    813  1.43  pgoyette 	case MODULE_CMD_INIT:
    814  1.43  pgoyette 		error = config_init_component(no_cfdriver_vec,
    815  1.43  pgoyette 		    cfattach_ioconf_ld_ataraid, cfdata_ioconf_ld_ataraid);
    816  1.43  pgoyette 		break;
    817  1.43  pgoyette 	case MODULE_CMD_FINI:
    818  1.43  pgoyette 		error = config_fini_component(no_cfdriver_vec,
    819  1.43  pgoyette 		    cfattach_ioconf_ld_ataraid, cfdata_ioconf_ld_ataraid);
    820  1.43  pgoyette 		break;
    821  1.43  pgoyette 	default:
    822  1.43  pgoyette 		error = ENOTTY;
    823  1.43  pgoyette 	break;
    824  1.43  pgoyette 	}
    825  1.43  pgoyette #endif
    826  1.43  pgoyette 
    827  1.43  pgoyette 	return error;
    828  1.43  pgoyette }
    829