Home | History | Annotate | Line # | Download | only in scsipi
atapiconf.c revision 1.28.2.5
      1  1.28.2.5  thorpej /*	$NetBSD: atapiconf.c,v 1.28.2.5 2000/02/04 23:01:54 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.3  thorpej 	atapi_kill_pending,
     93  1.28.2.1  thorpej };
     94  1.28.2.1  thorpej 
     95       1.2   bouyer struct scsi_quirk_inquiry_pattern atapi_quirk_patterns[] = {
     96       1.2   bouyer 	{{T_CDROM, T_REMOV,
     97  1.28.2.1  thorpej 	 "ALPS ELECTRIC CO.,LTD. DC544C", "", "SW03D"},	PQUIRK_NOTUR},
     98       1.2   bouyer 	{{T_CDROM, T_REMOV,
     99  1.28.2.1  thorpej 	 "BCD-16X 1997-04-25", "", "VER 2.2"},	PQUIRK_NOSTARTUNIT},
    100      1.26   bouyer 	{{T_CDROM, T_REMOV,
    101  1.28.2.1  thorpej 	 "BCD-24X 1997-06-27", "", "VER 2.0"},	PQUIRK_NOSTARTUNIT},
    102      1.22   bouyer 	{{T_CDROM, T_REMOV,
    103  1.28.2.1  thorpej 	 "CR-2801TE", "", "1.07"},		PQUIRK_NOSENSE},
    104      1.23   bouyer 	{{T_CDROM, T_REMOV,
    105  1.28.2.1  thorpej 	 "CREATIVECD3630E", "", "AC101"},	PQUIRK_NOSENSE},
    106       1.2   bouyer 	{{T_CDROM, T_REMOV,
    107  1.28.2.1  thorpej 	 "FX320S", "", "q01"},			PQUIRK_NOSENSE},
    108      1.21   bouyer 	{{T_CDROM, T_REMOV,
    109  1.28.2.1  thorpej 	 "GCD-R580B", "", "1.00"},		PQUIRK_LITTLETOC},
    110      1.24   bouyer 	{{T_CDROM, T_REMOV,
    111  1.28.2.1  thorpej 	 "MATSHITA CR-574", "", "1.02"},	PQUIRK_NOCAPACITY},
    112       1.3   bouyer 	{{T_CDROM, T_REMOV,
    113  1.28.2.1  thorpej 	 "MATSHITA CR-574", "", "1.06"},	PQUIRK_NOCAPACITY},
    114       1.7   bouyer 	{{T_CDROM, T_REMOV,
    115  1.28.2.1  thorpej 	 "Memorex CRW-2642", "", "1.0g"},	PQUIRK_NOSENSE},
    116       1.7   bouyer 	{{T_CDROM, T_REMOV,
    117  1.28.2.1  thorpej 	 "NEC                 CD-ROM DRIVE:273", "", "4.21"}, PQUIRK_NOTUR},
    118       1.2   bouyer 	{{T_CDROM, T_REMOV,
    119  1.28.2.1  thorpej 	 "SANYO CRD-256P", "", "1.02"},		PQUIRK_NOCAPACITY},
    120       1.2   bouyer 	{{T_CDROM, T_REMOV,
    121  1.28.2.1  thorpej 	 "SANYO CRD-254P", "", "1.02"},		PQUIRK_NOCAPACITY},
    122       1.3   bouyer 	{{T_CDROM, T_REMOV,
    123  1.28.2.1  thorpej 	 "SANYO CRD-S54P", "", "1.08"},		PQUIRK_NOCAPACITY},
    124       1.5   bouyer 	{{T_CDROM, T_REMOV,
    125  1.28.2.1  thorpej 	 "CD-ROM  CDR-S1", "", "1.70"},		PQUIRK_NOCAPACITY}, /* Sanyo */
    126      1.18   bouyer 	{{T_CDROM, T_REMOV,
    127  1.28.2.1  thorpej 	 "CD-ROM  CDR-N16", "", "1.25"},	PQUIRK_NOCAPACITY}, /* Sanyo */
    128      1.20   bouyer 	{{T_CDROM, T_REMOV,
    129  1.28.2.1  thorpej 	 "UJDCD8730", "", "1.14"},		PQUIRK_NODOORLOCK}, /* Acer */
    130       1.2   bouyer };
    131       1.2   bouyer 
    132       1.2   bouyer int
    133       1.2   bouyer atapibusmatch(parent, cf, aux)
    134       1.2   bouyer 	struct device *parent;
    135       1.2   bouyer 	struct cfdata *cf;
    136       1.2   bouyer 	void *aux;
    137       1.2   bouyer {
    138  1.28.2.1  thorpej 	struct ata_atapi_attach *aa = aux;
    139       1.2   bouyer 
    140  1.28.2.1  thorpej 	if (aa == NULL)
    141       1.4    enami 		return (0);
    142  1.28.2.1  thorpej 
    143  1.28.2.1  thorpej 	if (aa->aa_type != T_ATAPI)
    144       1.4    enami 		return (0);
    145  1.28.2.1  thorpej 
    146  1.28.2.1  thorpej 	if (cf->cf_loc[ATAPICF_CHANNEL] != aa->aa_channel &&
    147      1.13   bouyer 	    cf->cf_loc[ATAPICF_CHANNEL] != ATAPICF_CHANNEL_DEFAULT)
    148  1.28.2.1  thorpej 		return (0);
    149  1.28.2.1  thorpej 
    150       1.4    enami 	return (1);
    151       1.2   bouyer }
    152       1.2   bouyer 
    153       1.2   bouyer int
    154       1.2   bouyer atapibussubmatch(parent, cf, aux)
    155       1.2   bouyer 	struct device *parent;
    156       1.2   bouyer 	struct cfdata *cf;
    157       1.2   bouyer 	void *aux;
    158       1.2   bouyer {
    159       1.2   bouyer 	struct scsipibus_attach_args *sa = aux;
    160  1.28.2.1  thorpej 	struct scsipi_periph *periph = sa->sa_periph;
    161       1.2   bouyer 
    162       1.2   bouyer 	if (cf->cf_loc[ATAPIBUSCF_DRIVE] != ATAPIBUSCF_DRIVE_DEFAULT &&
    163  1.28.2.1  thorpej 	    cf->cf_loc[ATAPIBUSCF_DRIVE] != periph->periph_target)
    164       1.4    enami 		return (0);
    165       1.2   bouyer 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    166       1.2   bouyer }
    167       1.2   bouyer 
    168       1.2   bouyer #if 0
    169       1.2   bouyer void
    170  1.28.2.4  thorpej atapi_fixquirk(periph)
    171       1.4    enami 	struct scsipi_link *ad_link;
    172       1.2   bouyer {
    173      1.13   bouyer 	struct ataparams *id = &ad_link->id;
    174       1.4    enami 	struct atapi_quirk_inquiry_pattern *quirk;
    175       1.2   bouyer 
    176       1.4    enami 	/*
    177       1.4    enami 	 * Clean up the model name, serial and revision numbers.
    178       1.4    enami 	 */
    179       1.4    enami 	btrim(id->model, sizeof(id->model));
    180       1.4    enami 	btrim(id->serial_number, sizeof(id->serial_number));
    181       1.4    enami 	btrim(id->firmware_revision, sizeof(id->firmware_revision));
    182       1.2   bouyer }
    183       1.2   bouyer #endif
    184       1.2   bouyer 
    185       1.2   bouyer void
    186       1.2   bouyer atapibusattach(parent, self, aux)
    187       1.4    enami 	struct device *parent, *self;
    188       1.4    enami 	void *aux;
    189       1.2   bouyer {
    190  1.28.2.1  thorpej 	struct atapibus_softc *sc = (void *) self;
    191  1.28.2.1  thorpej 	struct ata_atapi_attach *aa = aux;
    192  1.28.2.1  thorpej 	struct scsipi_channel *chan = aa->aa_bus_private;
    193  1.28.2.1  thorpej 
    194  1.28.2.1  thorpej 	sc->sc_channel = chan;
    195  1.28.2.1  thorpej 	sc->sc_drvs = aa->aa_drv_data;
    196  1.28.2.1  thorpej 
    197  1.28.2.1  thorpej 	/* ATAPI has no LUNs. */
    198  1.28.2.1  thorpej 	chan->chan_nluns = 1;
    199  1.28.2.1  thorpej 	printf(": %d targets\n", chan->chan_ntargets);
    200  1.28.2.1  thorpej 
    201  1.28.2.1  thorpej 	/* Initialize the channel. */
    202  1.28.2.1  thorpej 	scsipi_channel_init(chan);
    203  1.28.2.1  thorpej 
    204  1.28.2.1  thorpej 	/* Probe the bus for devices. */
    205  1.28.2.1  thorpej 	atapi_probe_bus(sc, -1);
    206      1.27    enami }
    207      1.27    enami 
    208      1.27    enami int
    209      1.27    enami atapibusactivate(self, act)
    210      1.27    enami 	struct device *self;
    211      1.27    enami 	enum devact act;
    212      1.27    enami {
    213  1.28.2.1  thorpej 	struct atapibus_softc *sc = (void *) self;
    214  1.28.2.1  thorpej 	struct scsipi_channel *chan = sc->sc_channel;
    215  1.28.2.1  thorpej 	struct scsipi_periph *periph;
    216      1.27    enami 	int target, error = 0, s;
    217      1.27    enami 
    218      1.27    enami 	s = splbio();
    219      1.27    enami 	switch (act) {
    220      1.27    enami 	case DVACT_ACTIVATE:
    221      1.27    enami 		error = EOPNOTSUPP;
    222      1.27    enami 		break;
    223      1.27    enami 
    224      1.27    enami 	case DVACT_DEACTIVATE:
    225  1.28.2.1  thorpej 		for (target = 0; target < chan->chan_ntargets; target++) {
    226  1.28.2.5  thorpej 			periph = scsipi_lookup_periph(chan, target, 0);
    227  1.28.2.1  thorpej 			if (periph == NULL)
    228      1.27    enami 				continue;
    229  1.28.2.1  thorpej 			error = config_deactivate(periph->periph_dev);
    230  1.28.2.1  thorpej 			if (error)
    231      1.27    enami 				goto out;
    232      1.27    enami 		}
    233      1.27    enami 		break;
    234      1.27    enami 	}
    235      1.27    enami  out:
    236      1.27    enami 	splx(s);
    237      1.27    enami 	return (error);
    238      1.27    enami }
    239      1.27    enami 
    240      1.27    enami int
    241      1.27    enami atapibusdetach(self, flags)
    242      1.27    enami 	struct device *self;
    243      1.27    enami 	int flags;
    244      1.27    enami {
    245  1.28.2.1  thorpej 	struct atapibus_softc *sc = (void *)self;
    246  1.28.2.1  thorpej 	struct scsipi_channel *chan = sc->sc_channel;
    247  1.28.2.1  thorpej 	struct scsipi_periph *periph;
    248      1.27    enami 	int target, error;
    249      1.27    enami 
    250  1.28.2.5  thorpej 	/*
    251  1.28.2.5  thorpej 	 * Shut down the channel.
    252  1.28.2.5  thorpej 	 */
    253  1.28.2.5  thorpej 	scsipi_channel_shutdown(chan);
    254  1.28.2.5  thorpej 
    255  1.28.2.5  thorpej 	/*
    256  1.28.2.5  thorpej 	 * Now detach all of the periphs.
    257  1.28.2.5  thorpej 	 */
    258  1.28.2.1  thorpej 	for (target = 0; target < chan->chan_ntargets; target++) {
    259  1.28.2.5  thorpej 		periph = scsipi_lookup_periph(chan, target, 0);
    260  1.28.2.1  thorpej 		if (periph == NULL)
    261      1.27    enami 			continue;
    262  1.28.2.1  thorpej 		error = config_detach(periph->periph_dev, flags);
    263  1.28.2.1  thorpej 		if (error)
    264      1.27    enami 			return (error);
    265      1.27    enami 
    266      1.27    enami 		/*
    267      1.27    enami 		 * We have successfully detached the child.  Drop the
    268      1.27    enami 		 * direct reference for the child so that wdcdetach
    269      1.27    enami 		 * won't call detach routine twice.
    270      1.27    enami 		 */
    271      1.27    enami #ifdef DIAGNOSTIC
    272  1.28.2.1  thorpej 		if (periph->periph_dev != sc->sc_drvs[target].drv_softc)
    273      1.27    enami 			panic("softc mismatch");
    274      1.27    enami #endif
    275      1.27    enami 		sc->sc_drvs[target].drv_softc = NULL;
    276      1.27    enami 
    277  1.28.2.5  thorpej 		scsipi_remove_periph(chan, periph);
    278  1.28.2.1  thorpej 		free(periph, M_DEVBUF);
    279      1.27    enami 	}
    280      1.27    enami 	return (0);
    281       1.2   bouyer }
    282       1.2   bouyer 
    283       1.4    enami int
    284  1.28.2.1  thorpej atapi_probe_bus(sc, target)
    285  1.28.2.1  thorpej 	struct atapibus_softc *sc;
    286  1.28.2.1  thorpej 	int target;
    287       1.2   bouyer {
    288  1.28.2.1  thorpej 	struct scsipi_channel *chan = sc->sc_channel;
    289       1.2   bouyer 	int maxtarget, mintarget;
    290      1.15  thorpej 	int error;
    291       1.4    enami 
    292       1.2   bouyer 	if (target == -1) {
    293       1.2   bouyer 		maxtarget = 1;
    294       1.2   bouyer 		mintarget = 0;
    295       1.2   bouyer 	} else {
    296  1.28.2.1  thorpej 		if (target < 0 || target >= chan->chan_ntargets)
    297       1.4    enami 			return (ENXIO);
    298       1.2   bouyer 		maxtarget = mintarget = target;
    299       1.2   bouyer 	}
    300  1.28.2.1  thorpej 
    301  1.28.2.1  thorpej 	if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
    302      1.15  thorpej 		return (error);
    303       1.4    enami 	for (target = mintarget; target <= maxtarget; target++)
    304  1.28.2.1  thorpej 		atapi_probe_device(sc, target);
    305  1.28.2.1  thorpej 	scsipi_adapter_delref(chan->chan_adapter);
    306       1.4    enami 	return (0);
    307       1.2   bouyer }
    308       1.2   bouyer 
    309       1.2   bouyer void
    310  1.28.2.1  thorpej atapi_probe_device(sc, target)
    311  1.28.2.1  thorpej 	struct atapibus_softc *sc;
    312       1.2   bouyer 	int target;
    313       1.2   bouyer {
    314  1.28.2.1  thorpej 	struct scsipi_channel *chan = sc->sc_channel;
    315  1.28.2.1  thorpej 	struct scsipi_periph *periph;
    316      1.13   bouyer 	struct ataparams ids;
    317      1.13   bouyer 	struct ataparams *id = &ids;
    318  1.28.2.1  thorpej 	struct ata_drive_datas *drvp = &sc->sc_drvs[target];
    319       1.2   bouyer 	struct scsi_quirk_inquiry_pattern *finger;
    320  1.28.2.1  thorpej 	struct scsipibus_attach_args sa;
    321  1.28.2.1  thorpej 	struct cfdata *cf;
    322  1.28.2.1  thorpej 	int priority, quirks;
    323      1.17   bouyer 	char serial_number[21], model[41], firmware_revision[9];
    324       1.2   bouyer 
    325       1.2   bouyer 	/* skip if already attached */
    326  1.28.2.5  thorpej 	if (scsipi_lookup_periph(chan, target, 0) != NULL)
    327       1.2   bouyer 		return;
    328       1.2   bouyer 
    329  1.28.2.1  thorpej 	if (wdc_atapi_get_params(chan, target,
    330  1.28.2.1  thorpej 	    XS_CTL_POLL|XS_CTL_NOSLEEP, id) == 0) {
    331       1.2   bouyer #ifdef ATAPI_DEBUG_PROBE
    332       1.2   bouyer 		printf("%s drive %d: cmdsz 0x%x drqtype 0x%x\n",
    333  1.28.2.2    enami 		    sc->sc_dev.dv_xname, target,
    334      1.14    enami 		    id->atap_config & ATAPI_CFG_CMD_MASK,
    335      1.14    enami 		    id->atap_config & ATAPI_CFG_DRQ_MASK);
    336       1.2   bouyer #endif
    337  1.28.2.1  thorpej 		periph = malloc(sizeof(*periph), M_DEVBUF, M_NOWAIT);
    338  1.28.2.1  thorpej 		if (periph == NULL) {
    339  1.28.2.1  thorpej 			printf("%s: unable to allocate periph for drive %d\n",
    340  1.28.2.1  thorpej 			    sc->sc_dev.dv_xname, target);
    341       1.2   bouyer 			return;
    342       1.2   bouyer 		}
    343  1.28.2.1  thorpej 		memset(periph, 0, sizeof(*periph));
    344  1.28.2.1  thorpej 
    345  1.28.2.1  thorpej 		periph->periph_dev = NULL;
    346  1.28.2.1  thorpej 		periph->periph_channel = chan;
    347  1.28.2.1  thorpej 		periph->periph_switch = &atapi_probe_periphsw;
    348  1.28.2.1  thorpej 
    349  1.28.2.1  thorpej 		/*
    350  1.28.2.1  thorpej 		 * Start with one command opening.  The periph
    351  1.28.2.1  thorpej 		 * driver will grow this if it knows it can
    352  1.28.2.1  thorpej 		 * take advantage of it.
    353  1.28.2.1  thorpej 		 */
    354  1.28.2.1  thorpej 		periph->periph_openings = 1;
    355  1.28.2.1  thorpej 		periph->periph_active = 0;
    356  1.28.2.1  thorpej 
    357  1.28.2.1  thorpej 		periph->periph_target = target;
    358  1.28.2.1  thorpej 		periph->periph_lun = 0;
    359  1.28.2.1  thorpej 
    360  1.28.2.1  thorpej 		TAILQ_INIT(&periph->periph_xferq);
    361  1.28.2.1  thorpej 
    362  1.28.2.4  thorpej #ifdef SCSIPI_DEBUG
    363  1.28.2.4  thorpej 		if (SCSIPI_DEBUG_TYPE == SCSIPI_BUSTYPE_ATAPI &&
    364  1.28.2.4  thorpej 		    SCSIPI_DEBUG_TARGET == target)
    365  1.28.2.4  thorpej 			periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS;
    366  1.28.2.4  thorpej #endif
    367  1.28.2.1  thorpej 
    368  1.28.2.1  thorpej 		periph->periph_type = ATAPI_CFG_TYPE(id->atap_config);
    369  1.28.2.1  thorpej 		if (id->atap_config & ATAPI_CFG_REMOV)
    370  1.28.2.1  thorpej 			periph->periph_flags |= PERIPH_REMOVABLE;
    371  1.28.2.1  thorpej 
    372  1.28.2.1  thorpej 		sa.sa_periph = periph;
    373      1.13   bouyer 		sa.sa_inqbuf.type =  ATAPI_CFG_TYPE(id->atap_config);
    374  1.28.2.1  thorpej 		sa.sa_inqbuf.removable = id->atap_config & ATAPI_CFG_REMOV ?
    375  1.28.2.1  thorpej 		    T_REMOV : T_FIXED;
    376      1.13   bouyer 		scsipi_strvis(model, 40, id->atap_model, 40);
    377      1.13   bouyer 		scsipi_strvis(serial_number, 20, id->atap_serial, 20);
    378      1.13   bouyer 		scsipi_strvis(firmware_revision, 8, id->atap_revision, 8);
    379       1.2   bouyer 		sa.sa_inqbuf.vendor = model;
    380       1.2   bouyer 		sa.sa_inqbuf.product = serial_number;
    381       1.2   bouyer 		sa.sa_inqbuf.revision = firmware_revision;
    382       1.2   bouyer 
    383       1.2   bouyer 		finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
    384       1.2   bouyer 		    &sa.sa_inqbuf, (caddr_t)atapi_quirk_patterns,
    385       1.2   bouyer 		    sizeof(atapi_quirk_patterns) /
    386       1.4    enami 		        sizeof(atapi_quirk_patterns[0]),
    387       1.2   bouyer 		    sizeof(atapi_quirk_patterns[0]), &priority);
    388       1.2   bouyer 
    389  1.28.2.1  thorpej 		if (finger != NULL)
    390  1.28.2.1  thorpej 			quirks = finger->quirks;
    391  1.28.2.1  thorpej 		else
    392  1.28.2.1  thorpej 			quirks = 0;
    393  1.28.2.1  thorpej 
    394  1.28.2.1  thorpej 		/*
    395  1.28.2.1  thorpej 		 * Determine the operating mode capabilities of the device.
    396  1.28.2.1  thorpej 		 */
    397  1.28.2.1  thorpej 		if ((id->atap_config & ATAPI_CFG_CMD_MASK) == ATAPI_CFG_CMD_16)
    398  1.28.2.1  thorpej 			periph->periph_cap |= PERIPH_CAP_CMD16;
    399  1.28.2.1  thorpej 		/* XXX This is gross. */
    400  1.28.2.1  thorpej 		periph->periph_cap |= (id->atap_config & ATAPI_CFG_DRQ_MASK);
    401  1.28.2.1  thorpej 
    402  1.28.2.1  thorpej 		/*
    403  1.28.2.1  thorpej 		 * Now apply any quirks from the table.
    404  1.28.2.1  thorpej 		 */
    405  1.28.2.1  thorpej 		periph->periph_quirks |= quirks;
    406  1.28.2.1  thorpej 
    407  1.28.2.1  thorpej 		if ((cf = config_search(atapibussubmatch, &sc->sc_dev,
    408       1.2   bouyer 		    &sa)) != 0) {
    409  1.28.2.5  thorpej 			scsipi_insert_periph(chan, periph);
    410  1.28.2.1  thorpej 			/*
    411  1.28.2.1  thorpej 			 * XXX Can't assign periph_dev here, because we'll
    412  1.28.2.1  thorpej 			 * XXX need it before config_attach() returns.  Must
    413  1.28.2.1  thorpej 			 * XXX assign it in periph driver.
    414  1.28.2.1  thorpej 			 */
    415  1.28.2.1  thorpej 			drvp->drv_softc = config_attach(&sc->sc_dev, cf, &sa,
    416  1.28.2.1  thorpej 			    atapibusprint);
    417      1.13   bouyer 			wdc_probe_caps(drvp);
    418       1.2   bouyer 			return;
    419       1.2   bouyer 		} else {
    420  1.28.2.1  thorpej 			atapibusprint(&sa, sc->sc_dev.dv_xname);
    421       1.2   bouyer 			printf(" not configured\n");
    422  1.28.2.1  thorpej 			free(periph, M_DEVBUF);
    423       1.2   bouyer 			return;
    424       1.2   bouyer 		}
    425       1.2   bouyer 	}
    426       1.2   bouyer }
    427       1.2   bouyer 
    428       1.2   bouyer int
    429       1.2   bouyer atapibusprint(aux, pnp)
    430       1.2   bouyer 	void *aux;
    431       1.2   bouyer 	const char *pnp;
    432       1.2   bouyer {
    433       1.2   bouyer 	struct scsipibus_attach_args *sa = aux;
    434       1.2   bouyer 	struct scsipi_inquiry_pattern *inqbuf;
    435       1.2   bouyer 	char *dtype;
    436       1.2   bouyer 
    437       1.2   bouyer 	if (pnp != NULL)
    438       1.2   bouyer 		printf("%s", pnp);
    439       1.2   bouyer 
    440       1.2   bouyer 	inqbuf = &sa->sa_inqbuf;
    441       1.2   bouyer 
    442       1.2   bouyer 	dtype = scsipi_dtype(inqbuf->type & SID_TYPE);
    443       1.2   bouyer 	printf(" drive %d: <%s, %s, %s> type %d %s %s",
    444  1.28.2.1  thorpej 	    sa->sa_periph->periph_target ,inqbuf->vendor,
    445       1.2   bouyer 	    inqbuf->product, inqbuf->revision, inqbuf->type, dtype,
    446       1.2   bouyer 	    inqbuf->removable ? "removable" : "fixed");
    447       1.2   bouyer 	return (UNCONF);
    448       1.2   bouyer }
    449