Home | History | Annotate | Line # | Download | only in scsipi
atapiconf.c revision 1.12
      1  1.12       cgd /*	$NetBSD: atapiconf.c,v 1.12 1998/08/31 22:28:06 cgd 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.2    bouyer 
     40   1.2    bouyer #include <dev/scsipi/scsipi_all.h>
     41   1.9       cgd #include <dev/scsipi/atapi_all.h>
     42   1.2    bouyer #include <dev/scsipi/scsipiconf.h>
     43   1.2    bouyer #include <dev/scsipi/atapiconf.h>
     44   1.4     enami 
     45   1.2    bouyer #include "locators.h"
     46   1.2    bouyer 
     47   1.2    bouyer #define SILENT_PRINTF(flags,string) if (!(flags & A_SILENT)) printf string
     48   1.2    bouyer 
     49   1.2    bouyer struct atapibus_softc {
     50   1.2    bouyer 	struct device sc_dev;
     51   1.4     enami 	struct scsipi_link *adapter_link;	/* proto supplied by adapter */
     52   1.4     enami 	struct scsipi_link **sc_link;		/* dynamically allocated */
     53   1.2    bouyer };
     54   1.2    bouyer 
     55   1.2    bouyer int	atapibusmatch __P((struct device *, struct cfdata *, void *));
     56   1.2    bouyer int	atapibussubmatch __P((struct device *, struct cfdata *, void *));
     57   1.2    bouyer void	atapibusattach __P((struct device *, struct device *, void *));
     58   1.2    bouyer int	atapiprint __P((void *, const char *));
     59   1.2    bouyer 
     60   1.2    bouyer int	atapi_probe_bus __P((int, int));
     61   1.2    bouyer void	atapi_probedev __P((struct atapibus_softc *, int ));
     62   1.2    bouyer 
     63   1.2    bouyer struct cfattach atapibus_ca = {
     64   1.2    bouyer 	sizeof(struct atapibus_softc), atapibusmatch, atapibusattach
     65   1.2    bouyer };
     66   1.2    bouyer 
     67   1.8   thorpej extern struct cfdriver atapibus_cd;
     68   1.2    bouyer 
     69   1.2    bouyer int atapibusprint __P((void *, const char *));
     70   1.2    bouyer 
     71   1.2    bouyer struct scsi_quirk_inquiry_pattern atapi_quirk_patterns[] = {
     72   1.2    bouyer 	{{T_CDROM, T_REMOV,
     73   1.7    bouyer 	 "GCD-R580B", "", "1.00"},                ADEV_LITTLETOC}, /* Goldstar */
     74   1.2    bouyer 	{{T_CDROM, T_REMOV,
     75   1.4     enami 	 "SANYO CRD-256P", "", "1.02"},           ADEV_NOCAPACITY},
     76   1.2    bouyer 	{{T_CDROM, T_REMOV,
     77   1.4     enami 	 "SANYO CRD-254P", "", "1.02"},           ADEV_NOCAPACITY},
     78   1.6    bouyer 	{{T_CDROM, T_REMOV,
     79   1.6    bouyer 	 "SANYO CRD-S54P", "", "1.08"},           ADEV_NOCAPACITY},
     80   1.3    bouyer 	{{T_CDROM, T_REMOV,
     81   1.7    bouyer 	 "CD-ROM  CDR-S1", "", "1.70"},           ADEV_NOCAPACITY}, /* Sanyo */
     82   1.7    bouyer 	{{T_CDROM, T_REMOV,
     83   1.7    bouyer 	 "CD-ROM  CDR-N16", "", "1.25"},          ADEV_NOCAPACITY}, /* Sanyo */
     84   1.7    bouyer 	{{T_CDROM, T_REMOV,
     85   1.7    bouyer 	 "UJDCD8730", "", "1.14"},                ADEV_NODOORLOCK}, /* Acer */
     86   1.2    bouyer 	{{T_CDROM, T_REMOV,
     87   1.4     enami 	 "ALPS ELECTRIC CO.,LTD. DC544C", "", "SW03D"}, ADEV_NOTUR},
     88   1.2    bouyer 	{{T_CDROM, T_REMOV,
     89   1.4     enami 	 "NEC                 CD-ROM DRIVE:273", "", "4.21"}, ADEV_NOTUR},
     90   1.3    bouyer 	{{T_CDROM, T_REMOV,
     91   1.4     enami 	 "MATSHITA CR-574", "", "1.06"},          ADEV_NOCAPACITY},
     92   1.5    bouyer 	{{T_CDROM, T_REMOV,
     93   1.5    bouyer 	 "MATSHITA CR-574", "", "1.02"},          ADEV_NOCAPACITY},
     94   1.2    bouyer };
     95   1.2    bouyer 
     96   1.2    bouyer int
     97   1.2    bouyer atapibusmatch(parent, cf, aux)
     98   1.2    bouyer 	struct device *parent;
     99   1.2    bouyer 	struct cfdata *cf;
    100   1.2    bouyer 	void *aux;
    101   1.2    bouyer {
    102   1.2    bouyer 	struct scsipi_link *sc_link = aux;
    103   1.2    bouyer 
    104   1.2    bouyer 	if (sc_link == NULL)
    105   1.4     enami 		return (0);
    106   1.2    bouyer 	if (sc_link->type != BUS_ATAPI)
    107   1.4     enami 		return (0);
    108   1.4     enami 	return (1);
    109   1.2    bouyer }
    110   1.2    bouyer 
    111   1.2    bouyer int
    112   1.2    bouyer atapibussubmatch(parent, cf, aux)
    113   1.2    bouyer 	struct device *parent;
    114   1.2    bouyer 	struct cfdata *cf;
    115   1.2    bouyer 	void *aux;
    116   1.2    bouyer {
    117   1.2    bouyer 	struct scsipibus_attach_args *sa = aux;
    118   1.2    bouyer 	struct scsipi_link *sc_link = sa->sa_sc_link;
    119   1.2    bouyer 
    120   1.2    bouyer 	if (cf->cf_loc[ATAPIBUSCF_DRIVE] != ATAPIBUSCF_DRIVE_DEFAULT &&
    121   1.4     enami 	    cf->cf_loc[ATAPIBUSCF_DRIVE] != sc_link->scsipi_atapi.drive)
    122   1.4     enami 		return (0);
    123   1.2    bouyer 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    124   1.2    bouyer }
    125   1.2    bouyer 
    126   1.2    bouyer #if 0
    127   1.2    bouyer void
    128   1.2    bouyer atapi_fixquirk(sc_link)
    129   1.4     enami 	struct scsipi_link *ad_link;
    130   1.2    bouyer {
    131   1.4     enami 	struct atapi_identify *id = &ad_link->id;
    132   1.4     enami 	struct atapi_quirk_inquiry_pattern *quirk;
    133   1.2    bouyer 
    134   1.4     enami 	/*
    135   1.4     enami 	 * Clean up the model name, serial and revision numbers.
    136   1.4     enami 	 */
    137   1.4     enami 	btrim(id->model, sizeof(id->model));
    138   1.4     enami 	btrim(id->serial_number, sizeof(id->serial_number));
    139   1.4     enami 	btrim(id->firmware_revision, sizeof(id->firmware_revision));
    140   1.2    bouyer }
    141   1.2    bouyer #endif
    142   1.2    bouyer 
    143   1.2    bouyer void
    144   1.2    bouyer atapibusattach(parent, self, aux)
    145   1.4     enami 	struct device *parent, *self;
    146   1.4     enami 	void *aux;
    147   1.2    bouyer {
    148   1.2    bouyer 	struct atapibus_softc *ab = (struct atapibus_softc *)self;
    149   1.2    bouyer 	struct scsipi_link *sc_link_proto = aux;
    150   1.2    bouyer 	int nbytes;
    151   1.2    bouyer 
    152   1.2    bouyer 	printf("\n");
    153  1.10   thorpej 
    154  1.10   thorpej 	/* Initialize shared data. */
    155  1.10   thorpej 	scsipi_init();
    156   1.2    bouyer 
    157   1.2    bouyer 	sc_link_proto->scsipi_atapi.atapibus = ab->sc_dev.dv_unit;
    158   1.2    bouyer 	sc_link_proto->scsipi_cmd = atapi_scsipi_cmd;
    159   1.2    bouyer 	sc_link_proto->scsipi_interpret_sense = atapi_interpret_sense;
    160   1.2    bouyer 	sc_link_proto->sc_print_addr = atapi_print_addr;
    161   1.2    bouyer 
    162   1.2    bouyer 	ab->adapter_link = sc_link_proto;
    163   1.2    bouyer 
    164   1.4     enami 	nbytes = 2 * sizeof(struct scsipi_link **);
    165   1.2    bouyer 	ab->sc_link = (struct scsipi_link **)malloc(nbytes, M_DEVBUF,
    166   1.2    bouyer 	    M_NOWAIT);
    167   1.2    bouyer 	if (ab->sc_link == NULL)
    168   1.2    bouyer 		panic("scsibusattach: can't allocate target links");
    169   1.2    bouyer 	bzero(ab->sc_link, nbytes);
    170   1.2    bouyer 	atapi_probe_bus(ab->sc_dev.dv_unit, -1);
    171   1.2    bouyer }
    172   1.2    bouyer 
    173   1.4     enami int
    174   1.2    bouyer atapi_probe_bus(bus, target)
    175   1.4     enami 	int bus, target;
    176   1.2    bouyer {
    177   1.2    bouyer 	int maxtarget, mintarget;
    178   1.2    bouyer 	struct atapibus_softc *atapi;
    179   1.4     enami 
    180   1.2    bouyer 	if (bus < 0 || bus >= atapibus_cd.cd_ndevs)
    181   1.4     enami 		return (ENXIO);
    182   1.2    bouyer 	atapi = atapibus_cd.cd_devs[bus];
    183   1.4     enami 	if (atapi == NULL)
    184   1.4     enami 		return (ENXIO);
    185   1.2    bouyer 
    186   1.2    bouyer 	if (target == -1) {
    187   1.2    bouyer 		maxtarget = 1;
    188   1.2    bouyer 		mintarget = 0;
    189   1.2    bouyer 	} else {
    190   1.2    bouyer 		if (target < 0 || target > 1)
    191   1.4     enami 			return (ENXIO);
    192   1.2    bouyer 		maxtarget = mintarget = target;
    193   1.2    bouyer 	}
    194   1.4     enami 	for (target = mintarget; target <= maxtarget; target++)
    195   1.2    bouyer 		atapi_probedev(atapi, target);
    196   1.4     enami 	return (0);
    197   1.2    bouyer }
    198   1.2    bouyer 
    199   1.2    bouyer void
    200   1.2    bouyer atapi_probedev(atapi, target)
    201   1.2    bouyer 	struct atapibus_softc *atapi;
    202   1.2    bouyer 	int target;
    203   1.2    bouyer {
    204   1.2    bouyer 	struct scsipi_link *sc_link;
    205   1.2    bouyer 	struct scsipibus_attach_args sa;
    206   1.2    bouyer 	struct atapi_identify ids;
    207   1.2    bouyer 	struct atapi_identify *id = &ids;
    208   1.2    bouyer 	struct cfdata *cf;
    209   1.2    bouyer 	struct scsi_quirk_inquiry_pattern *finger;
    210   1.2    bouyer 	int priority;
    211   1.2    bouyer 	char serial_number[20], model[40], firmware_revision[8];
    212   1.2    bouyer 
    213   1.2    bouyer 	/* skip if already attached */
    214   1.2    bouyer 	if (atapi->sc_link[target])
    215   1.2    bouyer 		return;
    216   1.2    bouyer 
    217   1.2    bouyer 	if (wdc_atapi_get_params(atapi->adapter_link, target, id)) {
    218   1.2    bouyer #ifdef ATAPI_DEBUG_PROBE
    219   1.2    bouyer 		printf("%s drive %d: cmdsz 0x%x drqtype 0x%x\n",
    220   1.2    bouyer 		    atapi->sc_dev.dv_xname, target,
    221   1.2    bouyer 		    id->config.cmd_drq_rem & ATAPI_PACKET_SIZE_MASK,
    222   1.2    bouyer 		    id->config.cmd_drq_rem & ATAPI_DRQ_MASK);
    223   1.2    bouyer #endif
    224   1.2    bouyer 		/*
    225   1.2    bouyer 		 * Shuffle string byte order.
    226   1.2    bouyer 		 * Mitsumi and NEC drives don't need this.
    227   1.2    bouyer 		 */
    228   1.2    bouyer 		if (((id->model[0] == 'N' && id->model[1] == 'E') ||
    229   1.2    bouyer 		    (id->model[0] == 'F' && id->model[1] == 'X')) == 0)
    230   1.2    bouyer 			bswap(id->model, sizeof(id->model));
    231   1.2    bouyer 		bswap(id->serial_number, sizeof(id->serial_number));
    232   1.2    bouyer 		bswap(id->firmware_revision, sizeof(id->firmware_revision));
    233   1.2    bouyer 
    234   1.2    bouyer 		/*
    235   1.2    bouyer 		 * Allocate a device link and try and attach
    236   1.2    bouyer 		 * a driver to this device.  If we fail, free
    237   1.2    bouyer 		 * the link.
    238   1.2    bouyer 		 */
    239   1.2    bouyer 		sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
    240   1.2    bouyer 		if (sc_link == NULL) {
    241   1.2    bouyer 			printf("%s: can't allocate link for drive %d\n",
    242   1.2    bouyer 			    atapi->sc_dev.dv_xname, target);
    243   1.2    bouyer 			return;
    244   1.2    bouyer 		}
    245   1.2    bouyer 		/* Fill in link. */
    246   1.2    bouyer 		*sc_link = *atapi->adapter_link;
    247   1.2    bouyer 		sc_link->scsipi_atapi.drive = target;
    248   1.2    bouyer 		sc_link->device = NULL;
    249   1.2    bouyer #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_ATAPI
    250   1.2    bouyer 		if (DEBUGTARGET == -1 || target == DEBUGTARGET)
    251   1.2    bouyer 			sc_link->flags |= DEBUGLEVEL;
    252   1.2    bouyer #endif /* SCSIDEBUG */
    253   1.2    bouyer 		if (id->config.cmd_drq_rem & ATAPI_PACKET_SIZE_16)
    254   1.2    bouyer 			sc_link->scsipi_atapi.cap |= ACAP_LEN;
    255   1.2    bouyer 		sc_link->scsipi_atapi.cap |=
    256   1.2    bouyer 		    (id->config.cmd_drq_rem & ATAPI_DRQ_MASK) << 3;
    257   1.2    bouyer #if 0
    258   1.2    bouyer 		bcopy(id, &ad_link->id, sizeof(*id));
    259   1.2    bouyer 		/* Fix strings and look through the quirk table. */
    260   1.2    bouyer 		atapi_fixquirk(ad_link, id);
    261   1.2    bouyer #endif
    262   1.2    bouyer 		sa.sa_sc_link = sc_link;
    263   1.2    bouyer 		sa.sa_inqbuf.type =  id->config.device_type & SID_TYPE;
    264   1.2    bouyer 		sa.sa_inqbuf.removable =
    265   1.2    bouyer 		    id->config.cmd_drq_rem & ATAPI_REMOVABLE ?
    266   1.2    bouyer 		    T_REMOV : T_FIXED;
    267   1.2    bouyer 		if (sa.sa_inqbuf.removable)
    268   1.2    bouyer 			sc_link->flags |= SDEV_REMOVABLE;
    269  1.11  drochner 		scsipi_strvis(model, 40, id->model, 40);
    270  1.11  drochner 		scsipi_strvis(serial_number, 20, id->serial_number, 20);
    271  1.11  drochner 		scsipi_strvis(firmware_revision, 8, id->firmware_revision, 8);
    272   1.2    bouyer 		sa.sa_inqbuf.vendor = model;
    273   1.2    bouyer 		sa.sa_inqbuf.product = serial_number;
    274   1.2    bouyer 		sa.sa_inqbuf.revision = firmware_revision;
    275   1.2    bouyer 
    276   1.2    bouyer 		finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
    277   1.2    bouyer 		    &sa.sa_inqbuf, (caddr_t)atapi_quirk_patterns,
    278   1.2    bouyer 		    sizeof(atapi_quirk_patterns) /
    279   1.4     enami 		        sizeof(atapi_quirk_patterns[0]),
    280   1.2    bouyer 		    sizeof(atapi_quirk_patterns[0]), &priority);
    281   1.2    bouyer 		if (priority != 0)
    282   1.2    bouyer 			sc_link->quirks |= finger->quirks;
    283   1.2    bouyer 
    284   1.2    bouyer 		if ((cf = config_search(atapibussubmatch, &atapi->sc_dev,
    285   1.2    bouyer 		    &sa)) != 0) {
    286   1.2    bouyer 			atapi->sc_link[target] = sc_link;
    287   1.2    bouyer 			config_attach(&atapi->sc_dev, cf, &sa, atapibusprint);
    288   1.2    bouyer 			return;
    289   1.2    bouyer 		} else {
    290   1.2    bouyer 			atapibusprint(&sa, atapi->sc_dev.dv_xname);
    291   1.2    bouyer 			printf(" not configured\n");
    292   1.2    bouyer 			free(sc_link, M_DEVBUF);
    293   1.2    bouyer 			return;
    294   1.2    bouyer 		}
    295   1.2    bouyer 
    296   1.2    bouyer #if 0 /* WAS: */
    297   1.2    bouyer 		/* Try to find a match. */
    298   1.2    bouyer 		if (config_found(self, ad_link, atapiprint) == NULL)
    299   1.2    bouyer 			free(ad_link, M_DEVBUF);
    300   1.2    bouyer #endif
    301   1.2    bouyer 	}
    302   1.2    bouyer }
    303   1.2    bouyer 
    304   1.2    bouyer int
    305   1.2    bouyer atapibusprint(aux, pnp)
    306   1.2    bouyer 	void *aux;
    307   1.2    bouyer 	const char *pnp;
    308   1.2    bouyer {
    309   1.2    bouyer 	struct scsipibus_attach_args *sa = aux;
    310   1.2    bouyer 	struct scsipi_inquiry_pattern *inqbuf;
    311   1.2    bouyer 	char *dtype;
    312   1.2    bouyer 
    313   1.2    bouyer 	if (pnp != NULL)
    314   1.2    bouyer 		printf("%s", pnp);
    315   1.2    bouyer 
    316   1.2    bouyer 	inqbuf = &sa->sa_inqbuf;
    317   1.2    bouyer 
    318   1.2    bouyer 	dtype = scsipi_dtype(inqbuf->type & SID_TYPE);
    319   1.2    bouyer 	printf(" drive %d: <%s, %s, %s> type %d %s %s",
    320   1.2    bouyer 	    sa->sa_sc_link->scsipi_atapi.drive,inqbuf->vendor,
    321   1.2    bouyer 	    inqbuf->product, inqbuf->revision, inqbuf->type, dtype,
    322   1.2    bouyer 	    inqbuf->removable ? "removable" : "fixed");
    323   1.2    bouyer 	return (UNCONF);
    324   1.2    bouyer }
    325