1998-12-08 03:14:41 +03:00
|
|
|
/* $NetBSD: atapiconf.c,v 1.16 1998/12/08 00:14:41 thorpej Exp $ */
|
1997-08-27 15:22:52 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Manuel Bouyer. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Manuel Bouyer.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/buf.h>
|
1997-10-01 05:18:38 +04:00
|
|
|
#include <sys/proc.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
#include <dev/ata/atareg.h>
|
|
|
|
#include <dev/ata/atavar.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsipi_all.h>
|
1998-01-15 05:21:27 +03:00
|
|
|
#include <dev/scsipi/atapi_all.h>
|
1997-08-27 15:22:52 +04:00
|
|
|
#include <dev/scsipi/scsipiconf.h>
|
|
|
|
#include <dev/scsipi/atapiconf.h>
|
1997-10-01 05:18:38 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
#include "locators.h"
|
|
|
|
|
|
|
|
#define SILENT_PRINTF(flags,string) if (!(flags & A_SILENT)) printf string
|
|
|
|
|
|
|
|
struct atapibus_softc {
|
|
|
|
struct device sc_dev;
|
1997-10-01 05:18:38 +04:00
|
|
|
struct scsipi_link *adapter_link; /* proto supplied by adapter */
|
|
|
|
struct scsipi_link **sc_link; /* dynamically allocated */
|
1998-10-12 20:09:10 +04:00
|
|
|
struct ata_drive_datas *sc_drvs; /* array supplied by adapter */
|
1997-08-27 15:22:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
int atapibusmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
int atapibussubmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
void atapibusattach __P((struct device *, struct device *, void *));
|
|
|
|
int atapiprint __P((void *, const char *));
|
|
|
|
|
|
|
|
int atapi_probe_bus __P((int, int));
|
|
|
|
void atapi_probedev __P((struct atapibus_softc *, int ));
|
|
|
|
|
|
|
|
struct cfattach atapibus_ca = {
|
|
|
|
sizeof(struct atapibus_softc), atapibusmatch, atapibusattach
|
|
|
|
};
|
|
|
|
|
1998-01-12 12:49:10 +03:00
|
|
|
extern struct cfdriver atapibus_cd;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
|
|
|
int atapibusprint __P((void *, const char *));
|
|
|
|
|
|
|
|
struct scsi_quirk_inquiry_pattern atapi_quirk_patterns[] = {
|
|
|
|
{{T_CDROM, T_REMOV,
|
1998-01-06 20:03:15 +03:00
|
|
|
"GCD-R580B", "", "1.00"}, ADEV_LITTLETOC}, /* Goldstar */
|
1997-08-27 15:22:52 +04:00
|
|
|
{{T_CDROM, T_REMOV,
|
1997-10-01 05:18:38 +04:00
|
|
|
"SANYO CRD-256P", "", "1.02"}, ADEV_NOCAPACITY},
|
1997-08-28 18:02:31 +04:00
|
|
|
{{T_CDROM, T_REMOV,
|
1997-10-01 05:18:38 +04:00
|
|
|
"SANYO CRD-254P", "", "1.02"}, ADEV_NOCAPACITY},
|
1997-11-06 01:02:41 +03:00
|
|
|
{{T_CDROM, T_REMOV,
|
|
|
|
"SANYO CRD-S54P", "", "1.08"}, ADEV_NOCAPACITY},
|
1997-08-27 15:22:52 +04:00
|
|
|
{{T_CDROM, T_REMOV,
|
1998-01-06 20:03:15 +03:00
|
|
|
"CD-ROM CDR-S1", "", "1.70"}, ADEV_NOCAPACITY}, /* Sanyo */
|
|
|
|
{{T_CDROM, T_REMOV,
|
|
|
|
"CD-ROM CDR-N16", "", "1.25"}, ADEV_NOCAPACITY}, /* Sanyo */
|
|
|
|
{{T_CDROM, T_REMOV,
|
|
|
|
"UJDCD8730", "", "1.14"}, ADEV_NODOORLOCK}, /* Acer */
|
1997-08-27 15:22:52 +04:00
|
|
|
{{T_CDROM, T_REMOV,
|
1997-10-01 05:18:38 +04:00
|
|
|
"ALPS ELECTRIC CO.,LTD. DC544C", "", "SW03D"}, ADEV_NOTUR},
|
1997-08-27 15:22:52 +04:00
|
|
|
{{T_CDROM, T_REMOV,
|
1997-10-01 05:18:38 +04:00
|
|
|
"NEC CD-ROM DRIVE:273", "", "4.21"}, ADEV_NOTUR},
|
1997-08-28 18:02:31 +04:00
|
|
|
{{T_CDROM, T_REMOV,
|
1997-10-01 05:18:38 +04:00
|
|
|
"MATSHITA CR-574", "", "1.06"}, ADEV_NOCAPACITY},
|
1997-10-31 12:11:06 +03:00
|
|
|
{{T_CDROM, T_REMOV,
|
|
|
|
"MATSHITA CR-574", "", "1.02"}, ADEV_NOCAPACITY},
|
1997-08-27 15:22:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
atapibusmatch(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct ata_atapi_attach *aa_link = aux;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
if (aa_link == NULL)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
1998-10-12 20:09:10 +04:00
|
|
|
if (aa_link->aa_type != T_ATAPI)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
1998-10-12 20:09:10 +04:00
|
|
|
if (cf->cf_loc[ATAPICF_CHANNEL] != aa_link->aa_channel &&
|
|
|
|
cf->cf_loc[ATAPICF_CHANNEL] != ATAPICF_CHANNEL_DEFAULT)
|
|
|
|
return 0;
|
1997-10-01 05:18:38 +04:00
|
|
|
return (1);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
atapibussubmatch(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct scsipibus_attach_args *sa = aux;
|
|
|
|
struct scsipi_link *sc_link = sa->sa_sc_link;
|
|
|
|
|
|
|
|
if (cf->cf_loc[ATAPIBUSCF_DRIVE] != ATAPIBUSCF_DRIVE_DEFAULT &&
|
1997-10-01 05:18:38 +04:00
|
|
|
cf->cf_loc[ATAPIBUSCF_DRIVE] != sc_link->scsipi_atapi.drive)
|
|
|
|
return (0);
|
1997-08-27 15:22:52 +04:00
|
|
|
return ((*cf->cf_attach->ca_match)(parent, cf, aux));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void
|
|
|
|
atapi_fixquirk(sc_link)
|
1997-10-01 05:18:38 +04:00
|
|
|
struct scsipi_link *ad_link;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct ataparams *id = &ad_link->id;
|
1997-10-01 05:18:38 +04:00
|
|
|
struct atapi_quirk_inquiry_pattern *quirk;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up the model name, serial and revision numbers.
|
|
|
|
*/
|
|
|
|
btrim(id->model, sizeof(id->model));
|
|
|
|
btrim(id->serial_number, sizeof(id->serial_number));
|
|
|
|
btrim(id->firmware_revision, sizeof(id->firmware_revision));
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
atapibusattach(parent, self, aux)
|
1997-10-01 05:18:38 +04:00
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
1998-10-12 20:09:10 +04:00
|
|
|
struct atapibus_softc *sc_ab = (struct atapibus_softc *)self;
|
|
|
|
struct ata_atapi_attach *aa_link = aux;
|
|
|
|
struct scsipi_link *sc_link_proto;
|
1997-08-27 15:22:52 +04:00
|
|
|
int nbytes;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
1998-07-31 07:00:51 +04:00
|
|
|
/* Initialize shared data. */
|
|
|
|
scsipi_init();
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
sc_link_proto = malloc(sizeof(struct scsipi_link),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sc_link_proto == NULL)
|
|
|
|
printf("atapibusattach : can't allocate scsipi link proto\n");
|
|
|
|
memset(sc_link_proto, 0, sizeof(struct scsipi_link));
|
|
|
|
|
|
|
|
sc_link_proto->type = BUS_ATAPI;
|
|
|
|
sc_link_proto->openings = aa_link->aa_openings;
|
|
|
|
sc_link_proto->scsipi_atapi.channel = aa_link->aa_channel;
|
|
|
|
sc_link_proto->adapter_softc = parent;
|
|
|
|
sc_link_proto->adapter = aa_link->aa_bus_private;
|
|
|
|
sc_link_proto->scsipi_atapi.atapibus = sc_ab->sc_dev.dv_unit;
|
1997-08-27 15:22:52 +04:00
|
|
|
sc_link_proto->scsipi_cmd = atapi_scsipi_cmd;
|
|
|
|
sc_link_proto->scsipi_interpret_sense = atapi_interpret_sense;
|
|
|
|
sc_link_proto->sc_print_addr = atapi_print_addr;
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
|
|
|
|
sc_ab->adapter_link = sc_link_proto;
|
|
|
|
sc_ab->sc_drvs = aa_link->aa_drv_data;
|
1997-08-27 15:22:52 +04:00
|
|
|
|
1997-10-01 05:18:38 +04:00
|
|
|
nbytes = 2 * sizeof(struct scsipi_link **);
|
1998-10-12 20:09:10 +04:00
|
|
|
sc_ab->sc_link = (struct scsipi_link **)malloc(nbytes, M_DEVBUF,
|
1997-08-27 15:22:52 +04:00
|
|
|
M_NOWAIT);
|
1998-10-12 20:09:10 +04:00
|
|
|
if (sc_ab->sc_link == NULL)
|
1997-08-27 15:22:52 +04:00
|
|
|
panic("scsibusattach: can't allocate target links");
|
1998-10-12 20:09:10 +04:00
|
|
|
memset(sc_ab->sc_link, 0, nbytes);
|
|
|
|
atapi_probe_bus(sc_ab->sc_dev.dv_unit, -1);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
1997-10-01 05:18:38 +04:00
|
|
|
int
|
1997-08-27 15:22:52 +04:00
|
|
|
atapi_probe_bus(bus, target)
|
1997-10-01 05:18:38 +04:00
|
|
|
int bus, target;
|
1997-08-27 15:22:52 +04:00
|
|
|
{
|
|
|
|
int maxtarget, mintarget;
|
|
|
|
struct atapibus_softc *atapi;
|
1998-11-20 01:25:56 +03:00
|
|
|
int error;
|
1997-10-01 05:18:38 +04:00
|
|
|
|
1997-08-27 15:22:52 +04:00
|
|
|
if (bus < 0 || bus >= atapibus_cd.cd_ndevs)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (ENXIO);
|
1997-08-27 15:22:52 +04:00
|
|
|
atapi = atapibus_cd.cd_devs[bus];
|
1997-10-01 05:18:38 +04:00
|
|
|
if (atapi == NULL)
|
|
|
|
return (ENXIO);
|
1997-08-27 15:22:52 +04:00
|
|
|
|
|
|
|
if (target == -1) {
|
|
|
|
maxtarget = 1;
|
|
|
|
mintarget = 0;
|
|
|
|
} else {
|
|
|
|
if (target < 0 || target > 1)
|
1997-10-01 05:18:38 +04:00
|
|
|
return (ENXIO);
|
1997-08-27 15:22:52 +04:00
|
|
|
maxtarget = mintarget = target;
|
|
|
|
}
|
1998-11-20 01:25:56 +03:00
|
|
|
if ((error = scsipi_adapter_addref(atapi->adapter_link)) != 0)
|
|
|
|
return (error);
|
1997-10-01 05:18:38 +04:00
|
|
|
for (target = mintarget; target <= maxtarget; target++)
|
1997-08-27 15:22:52 +04:00
|
|
|
atapi_probedev(atapi, target);
|
1998-11-20 01:25:56 +03:00
|
|
|
scsipi_adapter_delref(atapi->adapter_link);
|
1997-10-01 05:18:38 +04:00
|
|
|
return (0);
|
1997-08-27 15:22:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
atapi_probedev(atapi, target)
|
|
|
|
struct atapibus_softc *atapi;
|
|
|
|
int target;
|
|
|
|
{
|
|
|
|
struct scsipi_link *sc_link;
|
|
|
|
struct scsipibus_attach_args sa;
|
1998-10-12 20:09:10 +04:00
|
|
|
struct ataparams ids;
|
|
|
|
struct ataparams *id = &ids;
|
|
|
|
struct ata_drive_datas *drvp = &atapi->sc_drvs[target];
|
1997-08-27 15:22:52 +04:00
|
|
|
struct cfdata *cf;
|
|
|
|
struct scsi_quirk_inquiry_pattern *finger;
|
|
|
|
int priority;
|
|
|
|
char serial_number[20], model[40], firmware_revision[8];
|
|
|
|
|
|
|
|
/* skip if already attached */
|
|
|
|
if (atapi->sc_link[target])
|
|
|
|
return;
|
|
|
|
|
1998-10-12 20:09:10 +04:00
|
|
|
if (wdc_atapi_get_params(atapi->adapter_link, target,
|
|
|
|
SCSI_POLL|SCSI_NOSLEEP, id) == COMPLETE) {
|
1997-08-27 15:22:52 +04:00
|
|
|
#ifdef ATAPI_DEBUG_PROBE
|
|
|
|
printf("%s drive %d: cmdsz 0x%x drqtype 0x%x\n",
|
|
|
|
atapi->sc_dev.dv_xname, target,
|
1998-10-13 06:09:47 +04:00
|
|
|
id->atap_config & ATAPI_CFG_CMD_MASK,
|
|
|
|
id->atap_config & ATAPI_CFG_DRQ_MASK);
|
1997-08-27 15:22:52 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Allocate a device link and try and attach
|
|
|
|
* a driver to this device. If we fail, free
|
|
|
|
* the link.
|
|
|
|
*/
|
|
|
|
sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sc_link == NULL) {
|
|
|
|
printf("%s: can't allocate link for drive %d\n",
|
|
|
|
atapi->sc_dev.dv_xname, target);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Fill in link. */
|
|
|
|
*sc_link = *atapi->adapter_link;
|
|
|
|
sc_link->scsipi_atapi.drive = target;
|
|
|
|
sc_link->device = NULL;
|
1998-12-08 03:14:41 +03:00
|
|
|
TAILQ_INIT(&sc_link->pending_xfers);
|
1997-08-27 15:22:52 +04:00
|
|
|
#if defined(SCSIDEBUG) && DEBUGTYPE == BUS_ATAPI
|
|
|
|
if (DEBUGTARGET == -1 || target == DEBUGTARGET)
|
|
|
|
sc_link->flags |= DEBUGLEVEL;
|
|
|
|
#endif /* SCSIDEBUG */
|
1998-10-12 20:09:10 +04:00
|
|
|
if ((id->atap_config & ATAPI_CFG_CMD_MASK) == ATAPI_CFG_CMD_16)
|
1997-08-27 15:22:52 +04:00
|
|
|
sc_link->scsipi_atapi.cap |= ACAP_LEN;
|
|
|
|
sc_link->scsipi_atapi.cap |=
|
1998-10-12 20:09:10 +04:00
|
|
|
(id->atap_config & ATAPI_CFG_DRQ_MASK);
|
1997-08-27 15:22:52 +04:00
|
|
|
sa.sa_sc_link = sc_link;
|
1998-10-12 20:09:10 +04:00
|
|
|
sa.sa_inqbuf.type = ATAPI_CFG_TYPE(id->atap_config);
|
1997-08-27 15:22:52 +04:00
|
|
|
sa.sa_inqbuf.removable =
|
1998-10-12 20:09:10 +04:00
|
|
|
id->atap_config & ATAPI_CFG_REMOV ? T_REMOV : T_FIXED;
|
1997-08-27 15:22:52 +04:00
|
|
|
if (sa.sa_inqbuf.removable)
|
|
|
|
sc_link->flags |= SDEV_REMOVABLE;
|
1998-10-12 20:09:10 +04:00
|
|
|
scsipi_strvis(model, 40, id->atap_model, 40);
|
|
|
|
scsipi_strvis(serial_number, 20, id->atap_serial, 20);
|
|
|
|
scsipi_strvis(firmware_revision, 8, id->atap_revision, 8);
|
1997-08-27 15:22:52 +04:00
|
|
|
sa.sa_inqbuf.vendor = model;
|
|
|
|
sa.sa_inqbuf.product = serial_number;
|
|
|
|
sa.sa_inqbuf.revision = firmware_revision;
|
|
|
|
|
|
|
|
finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
|
|
|
|
&sa.sa_inqbuf, (caddr_t)atapi_quirk_patterns,
|
|
|
|
sizeof(atapi_quirk_patterns) /
|
1997-10-01 05:18:38 +04:00
|
|
|
sizeof(atapi_quirk_patterns[0]),
|
1997-08-27 15:22:52 +04:00
|
|
|
sizeof(atapi_quirk_patterns[0]), &priority);
|
|
|
|
if (priority != 0)
|
|
|
|
sc_link->quirks |= finger->quirks;
|
|
|
|
|
|
|
|
if ((cf = config_search(atapibussubmatch, &atapi->sc_dev,
|
|
|
|
&sa)) != 0) {
|
|
|
|
atapi->sc_link[target] = sc_link;
|
1998-10-12 20:09:10 +04:00
|
|
|
drvp->drv_softc = config_attach(&atapi->sc_dev, cf,
|
|
|
|
&sa, atapibusprint);
|
|
|
|
wdc_probe_caps(drvp);
|
1997-08-27 15:22:52 +04:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
atapibusprint(&sa, atapi->sc_dev.dv_xname);
|
|
|
|
printf(" not configured\n");
|
|
|
|
free(sc_link, M_DEVBUF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
atapibusprint(aux, pnp)
|
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
|
|
|
{
|
|
|
|
struct scsipibus_attach_args *sa = aux;
|
|
|
|
struct scsipi_inquiry_pattern *inqbuf;
|
|
|
|
char *dtype;
|
|
|
|
|
|
|
|
if (pnp != NULL)
|
|
|
|
printf("%s", pnp);
|
|
|
|
|
|
|
|
inqbuf = &sa->sa_inqbuf;
|
|
|
|
|
|
|
|
dtype = scsipi_dtype(inqbuf->type & SID_TYPE);
|
|
|
|
printf(" drive %d: <%s, %s, %s> type %d %s %s",
|
|
|
|
sa->sa_sc_link->scsipi_atapi.drive,inqbuf->vendor,
|
|
|
|
inqbuf->product, inqbuf->revision, inqbuf->type, dtype,
|
|
|
|
inqbuf->removable ? "removable" : "fixed");
|
|
|
|
return (UNCONF);
|
|
|
|
}
|