Home | History | Annotate | Line # | Download | only in scsipi
atapiconf.c revision 1.28.2.1
      1  1.28.2.1  thorpej /*	$NetBSD: atapiconf.c,v 1.28.2.1 1999/10/19 17:39:26 thorpej Exp $	*/
      2       1.2   bouyer 
      3       1.2   bouyer /*
      4       1.2   bouyer  * Copyright (c) 1996 Manuel Bouyer.  All rights reserved.
      5       1.2   bouyer  *
      6       1.2   bouyer  * Redistribution and use in source and binary forms, with or without
      7       1.2   bouyer  * modification, are permitted provided that the following conditions
      8       1.2   bouyer  * are met:
      9       1.2   bouyer  * 1. Redistributions of source code must retain the above copyright
     10       1.2   bouyer  *    notice, this list of conditions and the following disclaimer.
     11       1.2   bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.2   bouyer  *    notice, this list of conditions and the following disclaimer in the
     13       1.2   bouyer  *    documentation and/or other materials provided with the distribution.
     14       1.2   bouyer  * 3. All advertising materials mentioning features or use of this software
     15       1.2   bouyer  *    must display the following acknowledgement:
     16       1.2   bouyer  *	This product includes software developed by Manuel Bouyer.
     17       1.2   bouyer  * 4. The name of the author may not be used to endorse or promote products
     18       1.2   bouyer  *    derived from this software without specific prior written permission.
     19       1.2   bouyer  *
     20       1.2   bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21       1.2   bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22       1.2   bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23       1.2   bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24       1.2   bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25       1.2   bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26       1.2   bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27       1.2   bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28       1.2   bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29       1.2   bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30       1.2   bouyer  */
     31       1.2   bouyer 
     32       1.2   bouyer #include <sys/types.h>
     33       1.2   bouyer #include <sys/param.h>
     34       1.2   bouyer #include <sys/systm.h>
     35       1.2   bouyer #include <sys/malloc.h>
     36       1.2   bouyer #include <sys/device.h>
     37       1.2   bouyer #include <sys/buf.h>
     38       1.4    enami #include <sys/proc.h>
     39  1.28.2.1  thorpej #include <sys/kthread.h>
     40       1.2   bouyer 
     41      1.13   bouyer #include <dev/ata/atareg.h>
     42      1.13   bouyer #include <dev/ata/atavar.h>
     43       1.2   bouyer #include <dev/scsipi/scsipi_all.h>
     44       1.9      cgd #include <dev/scsipi/atapi_all.h>
     45       1.2   bouyer #include <dev/scsipi/scsipiconf.h>
     46       1.2   bouyer #include <dev/scsipi/atapiconf.h>
     47       1.4    enami 
     48       1.2   bouyer #include "locators.h"
     49       1.2   bouyer 
     50       1.2   bouyer #define SILENT_PRINTF(flags,string) if (!(flags & A_SILENT)) printf string
     51      1.27    enami #define MAX_TARGET 1
     52       1.2   bouyer 
     53  1.28.2.1  thorpej const struct scsipi_periphsw atapi_probe_periphsw = {
     54  1.28.2.1  thorpej 	NULL,
     55  1.28.2.1  thorpej 	NULL,
     56  1.28.2.1  thorpej 	NULL,
     57  1.28.2.1  thorpej 	NULL,
     58  1.28.2.1  thorpej };
     59  1.28.2.1  thorpej 
     60       1.2   bouyer struct atapibus_softc {
     61       1.2   bouyer 	struct device sc_dev;
     62  1.28.2.1  thorpej 	struct scsipi_channel *sc_channel;	/* our scsipi_channel */
     63      1.13   bouyer 	struct ata_drive_datas *sc_drvs;	/* array supplied by adapter */
     64       1.2   bouyer };
     65       1.2   bouyer 
     66       1.2   bouyer int	atapibusmatch __P((struct device *, struct cfdata *, void *));
     67       1.2   bouyer void	atapibusattach __P((struct device *, struct device *, void *));
     68      1.27    enami int	atapibusactivate __P((struct device *, enum devact));
     69      1.27    enami int	atapibusdetach __P((struct device *, int flags));
     70      1.27    enami 
     71  1.28.2.1  thorpej int	atapibussubmatch __P((struct device *, struct cfdata *, void *));
     72  1.28.2.1  thorpej 
     73       1.2   bouyer int	atapiprint __P((void *, const char *));
     74       1.2   bouyer 
     75  1.28.2.1  thorpej int	atapi_probe_bus __P((struct atapibus_softc *, int));
     76  1.28.2.1  thorpej void	atapi_probe_device __P((struct atapibus_softc *, int ));
     77       1.2   bouyer 
     78       1.2   bouyer struct cfattach atapibus_ca = {
     79      1.27    enami 	sizeof(struct atapibus_softc), atapibusmatch, atapibusattach,
     80      1.27    enami 	atapibusdetach, atapibusactivate,
     81       1.2   bouyer };
     82       1.2   bouyer 
     83       1.8  thorpej extern struct cfdriver atapibus_cd;
     84       1.2   bouyer 
     85       1.2   bouyer int atapibusprint __P((void *, const char *));
     86       1.2   bouyer 
     87  1.28.2.1  thorpej const struct scsipi_bustype atapi_bustype = {
     88  1.28.2.1  thorpej 	SCSIPI_BUSTYPE_ATAPI,
     89  1.28.2.1  thorpej 	atapi_scsipi_cmd,
     90  1.28.2.1  thorpej 	atapi_interpret_sense,
     91  1.28.2.1  thorpej 	atapi_print_addr,
     92  1.28.2.1  thorpej };
     93  1.28.2.1  thorpej 
     94       1.2   bouyer struct scsi_quirk_inquiry_pattern atapi_quirk_patterns[] = {
     95       1.2   bouyer 	{{T_CDROM, T_REMOV,
     96  1.28.2.1  thorpej 	 "ALPS ELECTRIC CO.,LTD. DC544C", "", "SW03D"},	PQUIRK_NOTUR},
     97       1.2   bouyer 	{{T_CDROM, T_REMOV,
     98  1.28.2.1  thorpej 	 "BCD-16X 1997-04-25", "", "VER 2.2"},	PQUIRK_NOSTARTUNIT},
     99      1.26   bouyer 	{{T_CDROM, T_REMOV,
    100  1.28.2.1  thorpej 	 "BCD-24X 1997-06-27", "", "VER 2.0"},	PQUIRK_NOSTARTUNIT},
    101      1.22   bouyer 	{{T_CDROM, T_REMOV,
    102  1.28.2.1  thorpej 	 "CR-2801TE", "", "1.07"},		PQUIRK_NOSENSE},
    103      1.23   bouyer 	{{T_CDROM, T_REMOV,
    104  1.28.2.1  thorpej 	 "CREATIVECD3630E", "", "AC101"},	PQUIRK_NOSENSE},
    105       1.2   bouyer 	{{T_CDROM, T_REMOV,
    106  1.28.2.1  thorpej 	 "FX320S", "", "q01"},			PQUIRK_NOSENSE},
    107      1.21   bouyer 	{{T_CDROM, T_REMOV,
    108  1.28.2.1  thorpej 	 "GCD-R580B", "", "1.00"},		PQUIRK_LITTLETOC},
    109      1.24   bouyer 	{{T_CDROM, T_REMOV,
    110  1.28.2.1  thorpej 	 "MATSHITA CR-574", "", "1.02"},	PQUIRK_NOCAPACITY},
    111       1.3   bouyer 	{{T_CDROM, T_REMOV,
    112  1.28.2.1  thorpej 	 "MATSHITA CR-574", "", "1.06"},	PQUIRK_NOCAPACITY},
    113       1.7   bouyer 	{{T_CDROM, T_REMOV,
    114  1.28.2.1  thorpej 	 "Memorex CRW-2642", "", "1.0g"},	PQUIRK_NOSENSE},
    115       1.7   bouyer 	{{T_CDROM, T_REMOV,
    116  1.28.2.1  thorpej 	 "NEC                 CD-ROM DRIVE:273", "", "4.21"}, PQUIRK_NOTUR},
    117       1.2   bouyer 	{{T_CDROM, T_REMOV,
    118  1.28.2.1  thorpej 	 "SANYO CRD-256P", "", "1.02"},		PQUIRK_NOCAPACITY},
    119       1.2   bouyer 	{{T_CDROM, T_REMOV,
    120  1.28.2.1  thorpej 	 "SANYO CRD-254P", "", "1.02"},		PQUIRK_NOCAPACITY},
    121       1.3   bouyer 	{{T_CDROM, T_REMOV,
    122  1.28.2.1  thorpej 	 "SANYO CRD-S54P", "", "1.08"},		PQUIRK_NOCAPACITY},
    123       1.5   bouyer 	{{T_CDROM, T_REMOV,
    124  1.28.2.1  thorpej 	 "CD-ROM  CDR-S1", "", "1.70"},		PQUIRK_NOCAPACITY}, /* Sanyo */
    125      1.18   bouyer 	{{T_CDROM, T_REMOV,
    126  1.28.2.1  thorpej 	 "CD-ROM  CDR-N16", "", "1.25"},	PQUIRK_NOCAPACITY}, /* Sanyo */
    127      1.20   bouyer 	{{T_CDROM, T_REMOV,
    128  1.28.2.1  thorpej 	 "UJDCD8730", "", "1.14"},		PQUIRK_NODOORLOCK}, /* Acer */
    129       1.2   bouyer };
    130       1.2   bouyer 
    131       1.2   bouyer int
    132       1.2   bouyer atapibusmatch(parent, cf, aux)
    133       1.2   bouyer 	struct device *parent;
    134       1.2   bouyer 	struct cfdata *cf;
    135       1.2   bouyer 	void *aux;
    136       1.2   bouyer {
    137  1.28.2.1  thorpej 	struct ata_atapi_attach *aa = aux;
    138       1.2   bouyer 
    139  1.28.2.1  thorpej 	if (aa == NULL)
    140       1.4    enami 		return (0);
    141  1.28.2.1  thorpej 
    142  1.28.2.1  thorpej 	if (aa->aa_type != T_ATAPI)
    143       1.4    enami 		return (0);
    144  1.28.2.1  thorpej 
    145  1.28.2.1  thorpej 	if (cf->cf_loc[ATAPICF_CHANNEL] != aa->aa_channel &&
    146      1.13   bouyer 	    cf->cf_loc[ATAPICF_CHANNEL] != ATAPICF_CHANNEL_DEFAULT)
    147  1.28.2.1  thorpej 		return (0);
    148  1.28.2.1  thorpej 
    149       1.4    enami 	return (1);
    150       1.2   bouyer }
    151       1.2   bouyer 
    152       1.2   bouyer int
    153       1.2   bouyer atapibussubmatch(parent, cf, aux)
    154       1.2   bouyer 	struct device *parent;
    155       1.2   bouyer 	struct cfdata *cf;
    156       1.2   bouyer 	void *aux;
    157       1.2   bouyer {
    158       1.2   bouyer 	struct scsipibus_attach_args *sa = aux;
    159  1.28.2.1  thorpej 	struct scsipi_periph *periph = sa->sa_periph;
    160       1.2   bouyer 
    161       1.2   bouyer 	if (cf->cf_loc[ATAPIBUSCF_DRIVE] != ATAPIBUSCF_DRIVE_DEFAULT &&
    162  1.28.2.1  thorpej 	    cf->cf_loc[ATAPIBUSCF_DRIVE] != periph->periph_target)
    163       1.4    enami 		return (0);
    164       1.2   bouyer 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    165       1.2   bouyer }
    166       1.2   bouyer 
    167       1.2   bouyer #if 0
    168       1.2   bouyer void
    169       1.2   bouyer atapi_fixquirk(sc_link)
    170       1.4    enami 	struct scsipi_link *ad_link;
    171       1.2   bouyer {
    172      1.13   bouyer 	struct ataparams *id = &ad_link->id;
    173       1.4    enami 	struct atapi_quirk_inquiry_pattern *quirk;
    174       1.2   bouyer 
    175       1.4    enami 	/*
    176       1.4    enami 	 * Clean up the model name, serial and revision numbers.
    177       1.4    enami 	 */
    178       1.4    enami 	btrim(id->model, sizeof(id->model));
    179       1.4    enami 	btrim(id->serial_number, sizeof(id->serial_number));
    180       1.4    enami 	btrim(id->firmware_revision, sizeof(id->firmware_revision));
    181       1.2   bouyer }
    182       1.2   bouyer #endif
    183       1.2   bouyer 
    184       1.2   bouyer void
    185       1.2   bouyer atapibusattach(parent, self, aux)
    186       1.4    enami 	struct device *parent, *self;
    187       1.4    enami 	void *aux;
    188       1.2   bouyer {
    189  1.28.2.1  thorpej 	struct atapibus_softc *sc = (void *) self;
    190  1.28.2.1  thorpej 	struct ata_atapi_attach *aa = aux;
    191  1.28.2.1  thorpej 	struct scsipi_channel *chan = aa->aa_bus_private;
    192  1.28.2.1  thorpej 
    193  1.28.2.1  thorpej 	sc->sc_channel = chan;
    194  1.28.2.1  thorpej 	sc->sc_drvs = aa->aa_drv_data;
    195  1.28.2.1  thorpej 
    196  1.28.2.1  thorpej 	/* ATAPI has no LUNs. */
    197  1.28.2.1  thorpej 	chan->chan_nluns = 1;
    198  1.28.2.1  thorpej 	printf(": %d targets\n", chan->chan_ntargets);
    199  1.28.2.1  thorpej 
    200  1.28.2.1  thorpej 	/* Initialize the channel. */
    201  1.28.2.1  thorpej 	scsipi_channel_init(chan);
    202  1.28.2.1  thorpej 
    203  1.28.2.1  thorpej 	/* Probe the bus for devices. */
    204  1.28.2.1  thorpej 	atapi_probe_bus(sc, -1);
    205      1.27    enami }
    206      1.27    enami 
    207      1.27    enami int
    208      1.27    enami atapibusactivate(self, act)
    209      1.27    enami 	struct device *self;
    210      1.27    enami 	enum devact act;
    211      1.27    enami {
    212  1.28.2.1  thorpej 	struct atapibus_softc *sc = (void *) self;
    213  1.28.2.1  thorpej 	struct scsipi_channel *chan = sc->sc_channel;
    214  1.28.2.1  thorpej 	struct scsipi_periph *periph;
    215      1.27    enami 	int target, error = 0, s;
    216      1.27    enami 
    217      1.27    enami 	s = splbio();
    218      1.27    enami 	switch (act) {
    219      1.27    enami 	case DVACT_ACTIVATE:
    220      1.27    enami 		error = EOPNOTSUPP;
    221      1.27    enami 		break;
    222      1.27    enami 
    223      1.27    enami 	case DVACT_DEACTIVATE:
    224  1.28.2.1  thorpej 		for (target = 0; target < chan->chan_ntargets; target++) {
    225  1.28.2.1  thorpej 			periph = chan->chan_periphs[target][0];
    226  1.28.2.1  thorpej 			if (periph == NULL)
    227      1.27    enami 				continue;
    228  1.28.2.1  thorpej 			error = config_deactivate(periph->periph_dev);
    229  1.28.2.1  thorpej 			if (error)
    230      1.27    enami 				goto out;
    231      1.27    enami 		}
    232      1.27    enami 		break;
    233      1.27    enami 	}
    234      1.27    enami  out:
    235      1.27    enami 	splx(s);
    236      1.27    enami 	return (error);
    237      1.27    enami }
    238      1.27    enami 
    239      1.27    enami int
    240      1.27    enami atapibusdetach(self, flags)
    241      1.27    enami 	struct device *self;
    242      1.27    enami 	int flags;
    243      1.27    enami {
    244  1.28.2.1  thorpej 	struct atapibus_softc *sc = (void *)self;
    245  1.28.2.1  thorpej 	struct scsipi_channel *chan = sc->sc_channel;
    246  1.28.2.1  thorpej 	struct scsipi_periph *periph;
    247      1.27    enami 	int target, error;
    248      1.27    enami 
    249  1.28.2.1  thorpej 	for (target = 0; target < chan->chan_ntargets; target++) {
    250  1.28.2.1  thorpej 		periph = chan->chan_periphs[target][0];
    251  1.28.2.1  thorpej 		if (periph == NULL)
    252      1.27    enami 			continue;
    253  1.28.2.1  thorpej 		error = config_detach(periph->periph_dev, flags);
    254  1.28.2.1  thorpej 		if (error)
    255      1.27    enami 			return (error);
    256      1.27    enami 
    257      1.27    enami 		/*
    258      1.27    enami 		 * We have successfully detached the child.  Drop the
    259      1.27    enami 		 * direct reference for the child so that wdcdetach
    260      1.27    enami 		 * won't call detach routine twice.
    261      1.27    enami 		 */
    262      1.27    enami #ifdef DIAGNOSTIC
    263  1.28.2.1  thorpej 		if (periph->periph_dev != sc->sc_drvs[target].drv_softc)
    264      1.27    enami 			panic("softc mismatch");
    265      1.27    enami #endif
    266      1.27    enami 		sc->sc_drvs[target].drv_softc = NULL;
    267      1.27    enami 
    268  1.28.2.1  thorpej 		free(periph, M_DEVBUF);
    269  1.28.2.1  thorpej 		chan->chan_periphs[target][0] = NULL;
    270      1.27    enami 	}
    271      1.27    enami 	return (0);
    272       1.2   bouyer }
    273       1.2   bouyer 
    274       1.4    enami int
    275  1.28.2.1  thorpej atapi_probe_bus(sc, target)
    276  1.28.2.1  thorpej 	struct atapibus_softc *sc;
    277  1.28.2.1  thorpej 	int target;
    278       1.2   bouyer {
    279  1.28.2.1  thorpej 	struct scsipi_channel *chan = sc->sc_channel;
    280       1.2   bouyer 	int maxtarget, mintarget;
    281      1.15  thorpej 	int error;
    282       1.4    enami 
    283       1.2   bouyer 	if (target == -1) {
    284       1.2   bouyer 		maxtarget = 1;
    285       1.2   bouyer 		mintarget = 0;
    286       1.2   bouyer 	} else {
    287  1.28.2.1  thorpej 		if (target < 0 || target >= chan->chan_ntargets)
    288       1.4    enami 			return (ENXIO);
    289       1.2   bouyer 		maxtarget = mintarget = target;
    290       1.2   bouyer 	}
    291  1.28.2.1  thorpej 
    292  1.28.2.1  thorpej 	if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
    293      1.15  thorpej 		return (error);
    294       1.4    enami 	for (target = mintarget; target <= maxtarget; target++)
    295  1.28.2.1  thorpej 		atapi_probe_device(sc, target);
    296  1.28.2.1  thorpej 	scsipi_adapter_delref(chan->chan_adapter);
    297       1.4    enami 	return (0);
    298       1.2   bouyer }
    299       1.2   bouyer 
    300       1.2   bouyer void
    301  1.28.2.1  thorpej atapi_probe_device(sc, target)
    302  1.28.2.1  thorpej 	struct atapibus_softc *sc;
    303       1.2   bouyer 	int target;
    304       1.2   bouyer {
    305  1.28.2.1  thorpej 	struct scsipi_channel *chan = sc->sc_channel;
    306  1.28.2.1  thorpej 	struct scsipi_periph *periph;
    307      1.13   bouyer 	struct ataparams ids;
    308      1.13   bouyer 	struct ataparams *id = &ids;
    309  1.28.2.1  thorpej 	struct ata_drive_datas *drvp = &sc->sc_drvs[target];
    310       1.2   bouyer 	struct scsi_quirk_inquiry_pattern *finger;
    311  1.28.2.1  thorpej 	struct scsipibus_attach_args sa;
    312  1.28.2.1  thorpej 	struct cfdata *cf;
    313  1.28.2.1  thorpej 	int priority, quirks;
    314      1.17   bouyer 	char serial_number[21], model[41], firmware_revision[9];
    315       1.2   bouyer 
    316       1.2   bouyer 	/* skip if already attached */
    317  1.28.2.1  thorpej 	if (chan->chan_periphs[target][0] != NULL)
    318       1.2   bouyer 		return;
    319       1.2   bouyer 
    320  1.28.2.1  thorpej 	if (wdc_atapi_get_params(chan, target,
    321  1.28.2.1  thorpej 	    XS_CTL_POLL|XS_CTL_NOSLEEP, id) == 0) {
    322       1.2   bouyer #ifdef ATAPI_DEBUG_PROBE
    323       1.2   bouyer 		printf("%s drive %d: cmdsz 0x%x drqtype 0x%x\n",
    324       1.2   bouyer 		    atapi->sc_dev.dv_xname, target,
    325      1.14    enami 		    id->atap_config & ATAPI_CFG_CMD_MASK,
    326      1.14    enami 		    id->atap_config & ATAPI_CFG_DRQ_MASK);
    327       1.2   bouyer #endif
    328  1.28.2.1  thorpej 		periph = malloc(sizeof(*periph), M_DEVBUF, M_NOWAIT);
    329  1.28.2.1  thorpej 		if (periph == NULL) {
    330  1.28.2.1  thorpej 			printf("%s: unable to allocate periph for drive %d\n",
    331  1.28.2.1  thorpej 			    sc->sc_dev.dv_xname, target);
    332       1.2   bouyer 			return;
    333       1.2   bouyer 		}
    334  1.28.2.1  thorpej 		memset(periph, 0, sizeof(*periph));
    335  1.28.2.1  thorpej 
    336  1.28.2.1  thorpej 		periph->periph_dev = NULL;
    337  1.28.2.1  thorpej 		periph->periph_channel = chan;
    338  1.28.2.1  thorpej 		periph->periph_switch = &atapi_probe_periphsw;
    339  1.28.2.1  thorpej 
    340  1.28.2.1  thorpej 		/*
    341  1.28.2.1  thorpej 		 * Start with one command opening.  The periph
    342  1.28.2.1  thorpej 		 * driver will grow this if it knows it can
    343  1.28.2.1  thorpej 		 * take advantage of it.
    344  1.28.2.1  thorpej 		 */
    345  1.28.2.1  thorpej 		periph->periph_openings = 1;
    346  1.28.2.1  thorpej 		periph->periph_active = 0;
    347  1.28.2.1  thorpej 
    348  1.28.2.1  thorpej 		periph->periph_target = target;
    349  1.28.2.1  thorpej 		periph->periph_lun = 0;
    350  1.28.2.1  thorpej 
    351  1.28.2.1  thorpej 		TAILQ_INIT(&periph->periph_xferq);
    352  1.28.2.1  thorpej 
    353       1.2   bouyer #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_ATAPI
    354       1.2   bouyer 		if (DEBUGTARGET == -1 || target == DEBUGTARGET)
    355       1.2   bouyer 			sc_link->flags |= DEBUGLEVEL;
    356       1.2   bouyer #endif /* SCSIDEBUG */
    357  1.28.2.1  thorpej 
    358  1.28.2.1  thorpej 		periph->periph_type = ATAPI_CFG_TYPE(id->atap_config);
    359  1.28.2.1  thorpej 		if (id->atap_config & ATAPI_CFG_REMOV)
    360  1.28.2.1  thorpej 			periph->periph_flags |= PERIPH_REMOVABLE;
    361  1.28.2.1  thorpej 
    362  1.28.2.1  thorpej 		sa.sa_periph = periph;
    363      1.13   bouyer 		sa.sa_inqbuf.type =  ATAPI_CFG_TYPE(id->atap_config);
    364  1.28.2.1  thorpej 		sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
    365  1.28.2.1  thorpej 		    T_REMOV : T_FIXED;
    366      1.13   bouyer 		scsipi_strvis(model, 40, id->atap_model, 40);
    367      1.13   bouyer 		scsipi_strvis(serial_number, 20, id->atap_serial, 20);
    368      1.13   bouyer 		scsipi_strvis(firmware_revision, 8, id->atap_revision, 8);
    369       1.2   bouyer 		sa.sa_inqbuf.vendor = model;
    370       1.2   bouyer 		sa.sa_inqbuf.product = serial_number;
    371       1.2   bouyer 		sa.sa_inqbuf.revision = firmware_revision;
    372       1.2   bouyer 
    373       1.2   bouyer 		finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
    374       1.2   bouyer 		    &sa.sa_inqbuf, (caddr_t)atapi_quirk_patterns,
    375       1.2   bouyer 		    sizeof(atapi_quirk_patterns) /
    376       1.4    enami 		        sizeof(atapi_quirk_patterns[0]),
    377       1.2   bouyer 		    sizeof(atapi_quirk_patterns[0]), &priority);
    378       1.2   bouyer 
    379  1.28.2.1  thorpej 		if (finger != NULL)
    380  1.28.2.1  thorpej 			quirks = finger->quirks;
    381  1.28.2.1  thorpej 		else
    382  1.28.2.1  thorpej 			quirks = 0;
    383  1.28.2.1  thorpej 
    384  1.28.2.1  thorpej 		/*
    385  1.28.2.1  thorpej 		 * Determine the operating mode capabilities of the device.
    386  1.28.2.1  thorpej 		 */
    387  1.28.2.1  thorpej 		if ((id->atap_config & ATAPI_CFG_CMD_MASK) == ATAPI_CFG_CMD_16)
    388  1.28.2.1  thorpej 			periph->periph_cap |= PERIPH_CAP_CMD16;
    389  1.28.2.1  thorpej 		/* XXX This is gross. */
    390  1.28.2.1  thorpej 		periph->periph_cap |= (id->atap_config & ATAPI_CFG_DRQ_MASK);
    391  1.28.2.1  thorpej 
    392  1.28.2.1  thorpej 		/*
    393  1.28.2.1  thorpej 		 * Now apply any quirks from the table.
    394  1.28.2.1  thorpej 		 */
    395  1.28.2.1  thorpej 		periph->periph_quirks |= quirks;
    396  1.28.2.1  thorpej 
    397  1.28.2.1  thorpej 		if ((cf = config_search(atapibussubmatch, &sc->sc_dev,
    398       1.2   bouyer 		    &sa)) != 0) {
    399  1.28.2.1  thorpej 			chan->chan_periphs[target][0] = periph;
    400  1.28.2.1  thorpej 			/*
    401  1.28.2.1  thorpej 			 * XXX Can't assign periph_dev here, because we'll
    402  1.28.2.1  thorpej 			 * XXX need it before config_attach() returns.  Must
    403  1.28.2.1  thorpej 			 * XXX assign it in periph driver.
    404  1.28.2.1  thorpej 			 */
    405  1.28.2.1  thorpej 			drvp->drv_softc = config_attach(&sc->sc_dev, cf, &sa,
    406  1.28.2.1  thorpej 			    atapibusprint);
    407      1.13   bouyer 			wdc_probe_caps(drvp);
    408       1.2   bouyer 			return;
    409       1.2   bouyer 		} else {
    410  1.28.2.1  thorpej 			atapibusprint(&sa, sc->sc_dev.dv_xname);
    411       1.2   bouyer 			printf(" not configured\n");
    412  1.28.2.1  thorpej 			free(periph, M_DEVBUF);
    413       1.2   bouyer 			return;
    414       1.2   bouyer 		}
    415       1.2   bouyer 	}
    416       1.2   bouyer }
    417       1.2   bouyer 
    418       1.2   bouyer int
    419       1.2   bouyer atapibusprint(aux, pnp)
    420       1.2   bouyer 	void *aux;
    421       1.2   bouyer 	const char *pnp;
    422       1.2   bouyer {
    423       1.2   bouyer 	struct scsipibus_attach_args *sa = aux;
    424       1.2   bouyer 	struct scsipi_inquiry_pattern *inqbuf;
    425       1.2   bouyer 	char *dtype;
    426       1.2   bouyer 
    427       1.2   bouyer 	if (pnp != NULL)
    428       1.2   bouyer 		printf("%s", pnp);
    429       1.2   bouyer 
    430       1.2   bouyer 	inqbuf = &sa->sa_inqbuf;
    431       1.2   bouyer 
    432       1.2   bouyer 	dtype = scsipi_dtype(inqbuf->type & SID_TYPE);
    433       1.2   bouyer 	printf(" drive %d: <%s, %s, %s> type %d %s %s",
    434  1.28.2.1  thorpej 	    sa->sa_periph->periph_target ,inqbuf->vendor,
    435       1.2   bouyer 	    inqbuf->product, inqbuf->revision, inqbuf->type, dtype,
    436       1.2   bouyer 	    inqbuf->removable ? "removable" : "fixed");
    437       1.2   bouyer 	return (UNCONF);
    438       1.2   bouyer }
    439