Home | History | Annotate | Line # | Download | only in scsipi
atapiconf.c revision 1.36.2.4
      1  1.36.2.4   nathanw /*	$NetBSD: atapiconf.c,v 1.36.2.4 2001/11/14 19:16:00 nathanw 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.36.2.4   nathanw 
     32  1.36.2.4   nathanw #include <sys/cdefs.h>
     33  1.36.2.4   nathanw __KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.36.2.4 2001/11/14 19:16:00 nathanw Exp $");
     34       1.2    bouyer 
     35       1.2    bouyer #include <sys/types.h>
     36       1.2    bouyer #include <sys/param.h>
     37       1.2    bouyer #include <sys/systm.h>
     38       1.2    bouyer #include <sys/malloc.h>
     39       1.2    bouyer #include <sys/device.h>
     40       1.2    bouyer #include <sys/buf.h>
     41       1.4     enami #include <sys/proc.h>
     42  1.36.2.2   nathanw #include <sys/kthread.h>
     43       1.2    bouyer 
     44      1.13    bouyer #include <dev/ata/atavar.h>
     45       1.2    bouyer #include <dev/scsipi/scsipi_all.h>
     46  1.36.2.2   nathanw #include <dev/scsipi/scsipiconf.h>
     47       1.2    bouyer #include <dev/scsipi/atapiconf.h>
     48       1.4     enami 
     49       1.2    bouyer #include "locators.h"
     50       1.2    bouyer 
     51       1.2    bouyer #define SILENT_PRINTF(flags,string) if (!(flags & A_SILENT)) printf string
     52      1.27     enami #define MAX_TARGET 1
     53       1.2    bouyer 
     54  1.36.2.2   nathanw const struct scsipi_periphsw atapi_probe_periphsw = {
     55  1.36.2.2   nathanw 	NULL,
     56  1.36.2.2   nathanw 	NULL,
     57  1.36.2.2   nathanw 	NULL,
     58  1.36.2.2   nathanw 	NULL,
     59  1.36.2.2   nathanw };
     60  1.36.2.2   nathanw 
     61       1.2    bouyer int	atapibusmatch __P((struct device *, struct cfdata *, void *));
     62       1.2    bouyer void	atapibusattach __P((struct device *, struct device *, void *));
     63      1.27     enami int	atapibusactivate __P((struct device *, enum devact));
     64      1.27     enami int	atapibusdetach __P((struct device *, int flags));
     65       1.2    bouyer 
     66  1.36.2.2   nathanw int	atapibussubmatch __P((struct device *, struct cfdata *, void *));
     67  1.36.2.2   nathanw 
     68  1.36.2.2   nathanw int	atapi_probe_bus __P((struct atapibus_softc *, int));
     69       1.2    bouyer 
     70       1.2    bouyer struct cfattach atapibus_ca = {
     71      1.27     enami 	sizeof(struct atapibus_softc), atapibusmatch, atapibusattach,
     72      1.27     enami 	atapibusdetach, atapibusactivate,
     73       1.2    bouyer };
     74       1.2    bouyer 
     75       1.8   thorpej extern struct cfdriver atapibus_cd;
     76       1.2    bouyer 
     77       1.2    bouyer int atapibusprint __P((void *, const char *));
     78       1.2    bouyer 
     79      1.36  jdolecek const struct scsi_quirk_inquiry_pattern atapi_quirk_patterns[] = {
     80       1.2    bouyer 	{{T_CDROM, T_REMOV,
     81  1.36.2.2   nathanw 	 "ALPS ELECTRIC CO.,LTD. DC544C", "", "SW03D"},	PQUIRK_NOTUR},
     82       1.2    bouyer 	{{T_CDROM, T_REMOV,
     83  1.36.2.2   nathanw 	 "BCD-16X 1997-04-25", "", "VER 2.2"},	PQUIRK_NOSTARTUNIT},
     84      1.26    bouyer 	{{T_CDROM, T_REMOV,
     85  1.36.2.2   nathanw 	 "BCD-24X 1997-06-27", "", "VER 2.0"},	PQUIRK_NOSTARTUNIT},
     86      1.22    bouyer 	{{T_CDROM, T_REMOV,
     87  1.36.2.2   nathanw 	 "CR-2801TE", "", "1.07"},		PQUIRK_NOSENSE},
     88      1.23    bouyer 	{{T_CDROM, T_REMOV,
     89  1.36.2.2   nathanw 	 "CREATIVECD3630E", "", "AC101"},	PQUIRK_NOSENSE},
     90       1.2    bouyer 	{{T_CDROM, T_REMOV,
     91  1.36.2.2   nathanw 	 "FX320S", "", "q01"},			PQUIRK_NOSENSE},
     92      1.21    bouyer 	{{T_CDROM, T_REMOV,
     93  1.36.2.2   nathanw 	 "GCD-R580B", "", "1.00"},		PQUIRK_LITTLETOC},
     94      1.31  jdolecek 	{{T_CDROM, T_REMOV,
     95  1.36.2.2   nathanw 	 "HITACHI CDR-7730", "", "0008a"},      PQUIRK_NOSENSE},
     96      1.24    bouyer 	{{T_CDROM, T_REMOV,
     97  1.36.2.2   nathanw 	 "MATSHITA CR-574", "", "1.02"},	PQUIRK_NOCAPACITY},
     98       1.3    bouyer 	{{T_CDROM, T_REMOV,
     99  1.36.2.2   nathanw 	 "MATSHITA CR-574", "", "1.06"},	PQUIRK_NOCAPACITY},
    100       1.7    bouyer 	{{T_CDROM, T_REMOV,
    101  1.36.2.2   nathanw 	 "Memorex CRW-2642", "", "1.0g"},	PQUIRK_NOSENSE},
    102       1.7    bouyer 	{{T_CDROM, T_REMOV,
    103  1.36.2.2   nathanw 	 "NEC                 CD-ROM DRIVE:273", "", "4.21"}, PQUIRK_NOTUR},
    104       1.2    bouyer 	{{T_CDROM, T_REMOV,
    105  1.36.2.2   nathanw 	 "SANYO CRD-256P", "", "1.02"},		PQUIRK_NOCAPACITY},
    106       1.2    bouyer 	{{T_CDROM, T_REMOV,
    107  1.36.2.2   nathanw 	 "SANYO CRD-254P", "", "1.02"},		PQUIRK_NOCAPACITY},
    108       1.3    bouyer 	{{T_CDROM, T_REMOV,
    109  1.36.2.2   nathanw 	 "SANYO CRD-S54P", "", "1.08"},		PQUIRK_NOCAPACITY},
    110       1.5    bouyer 	{{T_CDROM, T_REMOV,
    111  1.36.2.2   nathanw 	 "CD-ROM  CDR-S1", "", "1.70"},		PQUIRK_NOCAPACITY}, /* Sanyo */
    112      1.18    bouyer 	{{T_CDROM, T_REMOV,
    113  1.36.2.2   nathanw 	 "CD-ROM  CDR-N16", "", "1.25"},	PQUIRK_NOCAPACITY}, /* Sanyo */
    114      1.20    bouyer 	{{T_CDROM, T_REMOV,
    115  1.36.2.2   nathanw 	 "UJDCD8730", "", "1.14"},		PQUIRK_NODOORLOCK}, /* Acer */
    116  1.36.2.1   nathanw 	{{T_DIRECT, T_REMOV,		/* Panasonic MultiMediaCard */
    117  1.36.2.2   nathanw 	  "04DA", "1B00", "0010"},		PQUIRK_BYTE5_ZERO |
    118  1.36.2.2   nathanw 	 					PQUIRK_NO_FLEX_PAGE },
    119  1.36.2.1   nathanw 	{{T_DIRECT, T_REMOV,		/* ZiO! MultiMediaCard */
    120  1.36.2.2   nathanw 	  "eUSB", "MultiMediaCard", ""},	PQUIRK_NO_FLEX_PAGE },
    121       1.2    bouyer };
    122       1.2    bouyer 
    123       1.2    bouyer int
    124       1.2    bouyer atapibusmatch(parent, cf, aux)
    125       1.2    bouyer 	struct device *parent;
    126       1.2    bouyer 	struct cfdata *cf;
    127       1.2    bouyer 	void *aux;
    128       1.2    bouyer {
    129  1.36.2.2   nathanw 	struct ata_atapi_attach *aa = aux;
    130       1.2    bouyer 
    131  1.36.2.2   nathanw 	if (aa == NULL)
    132       1.4     enami 		return (0);
    133  1.36.2.2   nathanw 
    134  1.36.2.2   nathanw 	if (aa->aa_type != T_ATAPI)
    135       1.4     enami 		return (0);
    136  1.36.2.2   nathanw 
    137  1.36.2.2   nathanw 	if (cf->cf_loc[ATAPICF_CHANNEL] != aa->aa_channel &&
    138      1.13    bouyer 	    cf->cf_loc[ATAPICF_CHANNEL] != ATAPICF_CHANNEL_DEFAULT)
    139  1.36.2.2   nathanw 		return (0);
    140  1.36.2.2   nathanw 
    141       1.4     enami 	return (1);
    142       1.2    bouyer }
    143       1.2    bouyer 
    144       1.2    bouyer int
    145       1.2    bouyer atapibussubmatch(parent, cf, aux)
    146       1.2    bouyer 	struct device *parent;
    147       1.2    bouyer 	struct cfdata *cf;
    148       1.2    bouyer 	void *aux;
    149       1.2    bouyer {
    150       1.2    bouyer 	struct scsipibus_attach_args *sa = aux;
    151  1.36.2.2   nathanw 	struct scsipi_periph *periph = sa->sa_periph;
    152       1.2    bouyer 
    153       1.2    bouyer 	if (cf->cf_loc[ATAPIBUSCF_DRIVE] != ATAPIBUSCF_DRIVE_DEFAULT &&
    154  1.36.2.2   nathanw 	    cf->cf_loc[ATAPIBUSCF_DRIVE] != periph->periph_target)
    155       1.4     enami 		return (0);
    156       1.2    bouyer 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    157       1.2    bouyer }
    158       1.2    bouyer 
    159       1.2    bouyer void
    160       1.2    bouyer atapibusattach(parent, self, aux)
    161       1.4     enami 	struct device *parent, *self;
    162       1.4     enami 	void *aux;
    163       1.2    bouyer {
    164  1.36.2.2   nathanw 	struct atapibus_softc *sc = (void *) self;
    165  1.36.2.2   nathanw 	struct ata_atapi_attach *aa = aux;
    166  1.36.2.2   nathanw 	struct scsipi_channel *chan = aa->aa_bus_private;
    167  1.36.2.2   nathanw 
    168  1.36.2.2   nathanw 	sc->sc_channel = chan;
    169  1.36.2.2   nathanw 	sc->sc_drvs = aa->aa_drv_data;
    170  1.36.2.2   nathanw 
    171  1.36.2.2   nathanw 	/* ATAPI has no LUNs. */
    172  1.36.2.2   nathanw 	chan->chan_nluns = 1;
    173  1.36.2.2   nathanw 	printf(": %d targets\n", chan->chan_ntargets);
    174  1.36.2.2   nathanw 
    175  1.36.2.2   nathanw 	/* Initialize the channel. */
    176  1.36.2.2   nathanw 	scsipi_channel_init(chan);
    177  1.36.2.2   nathanw 
    178  1.36.2.2   nathanw 	/* Probe the bus for devices. */
    179  1.36.2.2   nathanw 	atapi_probe_bus(sc, -1);
    180      1.27     enami }
    181      1.27     enami 
    182      1.27     enami int
    183      1.27     enami atapibusactivate(self, act)
    184      1.27     enami 	struct device *self;
    185      1.27     enami 	enum devact act;
    186      1.27     enami {
    187  1.36.2.2   nathanw 	struct atapibus_softc *sc = (void *) self;
    188  1.36.2.2   nathanw 	struct scsipi_channel *chan = sc->sc_channel;
    189  1.36.2.2   nathanw 	struct scsipi_periph *periph;
    190      1.27     enami 	int target, error = 0, s;
    191      1.27     enami 
    192      1.27     enami 	s = splbio();
    193      1.27     enami 	switch (act) {
    194      1.27     enami 	case DVACT_ACTIVATE:
    195      1.27     enami 		error = EOPNOTSUPP;
    196      1.27     enami 		break;
    197      1.27     enami 
    198      1.27     enami 	case DVACT_DEACTIVATE:
    199  1.36.2.2   nathanw 		for (target = 0; target < chan->chan_ntargets; target++) {
    200  1.36.2.2   nathanw 			periph = scsipi_lookup_periph(chan, target, 0);
    201  1.36.2.2   nathanw 			if (periph == NULL)
    202      1.27     enami 				continue;
    203  1.36.2.2   nathanw 			error = config_deactivate(periph->periph_dev);
    204  1.36.2.2   nathanw 			if (error)
    205      1.27     enami 				goto out;
    206      1.27     enami 		}
    207      1.27     enami 		break;
    208      1.27     enami 	}
    209      1.27     enami  out:
    210      1.27     enami 	splx(s);
    211      1.27     enami 	return (error);
    212      1.27     enami }
    213      1.27     enami 
    214      1.27     enami int
    215      1.27     enami atapibusdetach(self, flags)
    216      1.27     enami 	struct device *self;
    217      1.27     enami 	int flags;
    218      1.27     enami {
    219  1.36.2.2   nathanw 	struct atapibus_softc *sc = (void *)self;
    220  1.36.2.2   nathanw 	struct scsipi_channel *chan = sc->sc_channel;
    221  1.36.2.2   nathanw 	struct scsipi_periph *periph;
    222      1.27     enami 	int target, error;
    223      1.27     enami 
    224  1.36.2.2   nathanw 	/*
    225  1.36.2.2   nathanw 	 * Shut down the channel.
    226  1.36.2.2   nathanw 	 */
    227  1.36.2.2   nathanw 	scsipi_channel_shutdown(chan);
    228  1.36.2.2   nathanw 
    229  1.36.2.2   nathanw 	/*
    230  1.36.2.2   nathanw 	 * Now detach all of the periphs.
    231  1.36.2.2   nathanw 	 */
    232  1.36.2.2   nathanw 	for (target = 0; target < chan->chan_ntargets; target++) {
    233  1.36.2.2   nathanw 		periph = scsipi_lookup_periph(chan, target, 0);
    234  1.36.2.2   nathanw 		if (periph == NULL)
    235      1.27     enami 			continue;
    236  1.36.2.2   nathanw 		error = config_detach(periph->periph_dev, flags);
    237  1.36.2.2   nathanw 		if (error)
    238      1.27     enami 			return (error);
    239      1.27     enami 
    240      1.27     enami 		/*
    241      1.27     enami 		 * We have successfully detached the child.  Drop the
    242      1.27     enami 		 * direct reference for the child so that wdcdetach
    243      1.27     enami 		 * won't call detach routine twice.
    244      1.27     enami 		 */
    245      1.27     enami #ifdef DIAGNOSTIC
    246  1.36.2.2   nathanw 		if (periph->periph_dev != sc->sc_drvs[target].drv_softc)
    247      1.27     enami 			panic("softc mismatch");
    248      1.27     enami #endif
    249      1.27     enami 		sc->sc_drvs[target].drv_softc = NULL;
    250      1.27     enami 
    251  1.36.2.2   nathanw 		scsipi_remove_periph(chan, periph);
    252  1.36.2.2   nathanw 		free(periph, M_DEVBUF);
    253      1.27     enami 	}
    254      1.27     enami 	return (0);
    255       1.2    bouyer }
    256       1.2    bouyer 
    257       1.4     enami int
    258  1.36.2.2   nathanw atapi_probe_bus(sc, target)
    259  1.36.2.2   nathanw 	struct atapibus_softc *sc;
    260  1.36.2.2   nathanw 	int target;
    261       1.2    bouyer {
    262  1.36.2.2   nathanw 	struct scsipi_channel *chan = sc->sc_channel;
    263       1.2    bouyer 	int maxtarget, mintarget;
    264      1.15   thorpej 	int error;
    265      1.34    bouyer 	struct atapi_adapter *atapi_adapter;
    266       1.4     enami 
    267       1.2    bouyer 	if (target == -1) {
    268       1.2    bouyer 		maxtarget = 1;
    269       1.2    bouyer 		mintarget = 0;
    270       1.2    bouyer 	} else {
    271  1.36.2.2   nathanw 		if (target < 0 || target >= chan->chan_ntargets)
    272       1.4     enami 			return (ENXIO);
    273       1.2    bouyer 		maxtarget = mintarget = target;
    274       1.2    bouyer 	}
    275  1.36.2.2   nathanw 
    276  1.36.2.2   nathanw 	if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
    277      1.15   thorpej 		return (error);
    278  1.36.2.2   nathanw 	atapi_adapter = (struct atapi_adapter*)chan->chan_adapter;
    279       1.4     enami 	for (target = mintarget; target <= maxtarget; target++)
    280  1.36.2.2   nathanw 		atapi_adapter->atapi_probe_device(sc, target);
    281  1.36.2.2   nathanw 	scsipi_adapter_delref(chan->chan_adapter);
    282       1.4     enami 	return (0);
    283       1.2    bouyer }
    284       1.2    bouyer 
    285      1.34    bouyer void *
    286  1.36.2.2   nathanw atapi_probe_device(sc, target, periph, sa)
    287  1.36.2.2   nathanw 	struct atapibus_softc *sc;
    288       1.2    bouyer 	int target;
    289  1.36.2.2   nathanw 	struct scsipi_periph *periph;
    290      1.34    bouyer 	struct scsipibus_attach_args *sa;
    291       1.2    bouyer {
    292  1.36.2.2   nathanw 	struct scsipi_channel *chan = sc->sc_channel;
    293       1.2    bouyer 	struct scsi_quirk_inquiry_pattern *finger;
    294  1.36.2.2   nathanw 	struct cfdata *cf;
    295  1.36.2.2   nathanw 	int priority, quirks;
    296       1.2    bouyer 
    297      1.34    bouyer 	finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
    298      1.34    bouyer 	    &sa->sa_inqbuf, (caddr_t)atapi_quirk_patterns,
    299      1.34    bouyer 	    sizeof(atapi_quirk_patterns) /
    300      1.34    bouyer 	        sizeof(atapi_quirk_patterns[0]),
    301      1.34    bouyer 	    sizeof(atapi_quirk_patterns[0]), &priority);
    302      1.34    bouyer 
    303  1.36.2.2   nathanw 	if (finger != NULL)
    304  1.36.2.2   nathanw 		quirks = finger->quirks;
    305  1.36.2.2   nathanw 	else
    306  1.36.2.2   nathanw 		quirks = 0;
    307  1.36.2.2   nathanw 
    308  1.36.2.2   nathanw 	/*
    309  1.36.2.2   nathanw 	 * Now apply any quirks from the table.
    310  1.36.2.2   nathanw 	 */
    311  1.36.2.2   nathanw 	periph->periph_quirks |= quirks;
    312  1.36.2.2   nathanw 
    313  1.36.2.2   nathanw 	if ((cf = config_search(atapibussubmatch, &sc->sc_dev,
    314      1.34    bouyer 	    sa)) != 0) {
    315  1.36.2.2   nathanw 		scsipi_insert_periph(chan, periph);
    316  1.36.2.2   nathanw 		/*
    317  1.36.2.2   nathanw 		 * XXX Can't assign periph_dev here, because we'll
    318  1.36.2.2   nathanw 		 * XXX need it before config_attach() returns.  Must
    319  1.36.2.2   nathanw 		 * XXX assign it in periph driver.
    320  1.36.2.2   nathanw 		 */
    321  1.36.2.2   nathanw 		return config_attach(&sc->sc_dev, cf, sa,
    322  1.36.2.2   nathanw 		    atapibusprint);
    323      1.34    bouyer 	} else {
    324  1.36.2.3   nathanw 		atapibusprint(sa, sc->sc_dev.dv_xname);
    325      1.34    bouyer 		printf(" not configured\n");
    326  1.36.2.2   nathanw 		free(periph, M_DEVBUF);
    327  1.36.2.2   nathanw 		return NULL;
    328       1.2    bouyer 	}
    329       1.2    bouyer }
    330       1.2    bouyer 
    331       1.2    bouyer int
    332       1.2    bouyer atapibusprint(aux, pnp)
    333       1.2    bouyer 	void *aux;
    334       1.2    bouyer 	const char *pnp;
    335       1.2    bouyer {
    336       1.2    bouyer 	struct scsipibus_attach_args *sa = aux;
    337       1.2    bouyer 	struct scsipi_inquiry_pattern *inqbuf;
    338       1.2    bouyer 	char *dtype;
    339       1.2    bouyer 
    340       1.2    bouyer 	if (pnp != NULL)
    341       1.2    bouyer 		printf("%s", pnp);
    342       1.2    bouyer 
    343       1.2    bouyer 	inqbuf = &sa->sa_inqbuf;
    344       1.2    bouyer 
    345       1.2    bouyer 	dtype = scsipi_dtype(inqbuf->type & SID_TYPE);
    346       1.2    bouyer 	printf(" drive %d: <%s, %s, %s> type %d %s %s",
    347  1.36.2.2   nathanw 	    sa->sa_periph->periph_target ,inqbuf->vendor,
    348       1.2    bouyer 	    inqbuf->product, inqbuf->revision, inqbuf->type, dtype,
    349       1.2    bouyer 	    inqbuf->removable ? "removable" : "fixed");
    350       1.2    bouyer 	return (UNCONF);
    351       1.2    bouyer }
    352