* Written by Julian Elischer (julian@tfs.com)
* for TRW Financial Systems for use under the MACH(2.5) operating system.
* TRW Financial Systems, in accordance with their agreement with Carnegie
* Mellon University, makes this software available to CMU to distribute
* or use in any manner that they see fit as long as this message is kept with
* the software. For this reason TFS also grants any other persons or
* organisations permission to use or modify this software.
* TFS supplies this software to be publicly redistributed
* on the understanding that TFS is not responsible for the correct
* functioning of this software in any circumstances.
* Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
* $Id: scsiconf.c,v 1.7 1993/11/18 05:02:58 rgrimes Exp $
#include <scsi/scsi_all.h>
#include <scsi/scsiconf.h>
* One of these is allocated and filled in for each scsi bus.
* it holds pointers to allow the scsi bus to get to the driver
* That is running each LUN on the bus
* it also has a template entry which is the prototype struct
* supplied by the adapter driver, this is used to initialise
* the others, before they have the rest of the fields filled in
struct scsibus_data
*scbus_data
[NSCBUS
];
* The structure of pre-configured devices that might be turned
* off and therefore may not show up
0, 0, 0, sdattach
, "sd", 0
}, /* define a disk at scsibus=0 dev=0 lu=0 */
#endif /* EXAMPLE_PREDEFINE */
} /*illegal dummy end entry */
* The structure of known drivers for autoconfiguration
char flags
; /* 1 show my comparisons during boot(debug) */
static struct scsidevs unknowndev
= {
,"any", ukattach
, "uk", SC_MORE_LUS
static struct scsidevs knowndevs
[] =
T_DIRECT
, T_FIXED
, "standard", "any"
,"any", sdattach
, "sd", SC_ONE_LU
T_DIRECT
, T_FIXED
, "MAXTOR ", "XT-4170S "
,"B5A ", sdattach
, "mx1", SC_ONE_LU
T_SEQUENTIAL
, T_REMOV
, "standard", "any"
,"any", stattach
, "st", SC_ONE_LU
T_PROCESSOR
, T_FIXED
, "standard", "any"
,"any", calsattach
, "cals", SC_MORE_LUS
T_CHANGER
, T_REMOV
, "standard", "any"
,"any", chattach
, "ch", SC_ONE_LU
#ifndef UKTEST /* make cdroms unrecognised to test the uk driver */
T_READONLY
, T_REMOV
, "SONY ", "CD-ROM CDU-8012 "
,"3.1a", cdattach
, "cd", SC_ONE_LU
T_READONLY
, T_REMOV
, "PIONEER ", "CD-ROM DRM-600 "
,"any", cdattach
, "cd", SC_MORE_LUS
T_PROCESSOR
, T_FIXED
, "AEG ", "READER "
,"V1.0", bllattach
, "bll", SC_MORE_LUS
T_SCANNER
, T_FIXED
, "KODAK ", "IL Scanner 900 "
,"any", kil_attach
, "kil", SC_ONE_LU
struct predefined
*scsi_get_predef();
struct scsidevs
*scsi_probedev();
struct scsidevs
*selectdev();
errval scsi_probe_bus
__P((int bus
, int targ
, int lun
));
struct scsi_device probe_switch
=
* controls debug level within the scsi subsystem -
* see scsiconf.h for values
int32 scsibus
= 0x0; /* This is the Nth scsibus we've seen */
* The routine called by the adapter boards to get all their
scsi_attachdevs(sc_link_proto
)
struct scsi_link
*sc_link_proto
;
printf("too many scsi busses, reconfigure the kernel\n");
sc_link_proto
->scsibus
= scsibus
;
scbus_data
[scsibus
] = malloc(sizeof(struct scsibus_data
), M_TEMP
, M_NOWAIT
);
if(!scbus_data
[scsibus
]) {
panic("scsi_attachdevs: malloc\n");
bzero(scbus_data
[scsibus
], sizeof(struct scsibus_data
));
scbus_data
[scsibus
]->adapter_link
= sc_link_proto
;
#if defined(SCSI_DELAY) && SCSI_DELAY > 2
printf("%s%d waiting for scsi devices to settle\n",
sc_link_proto
->adapter
->name
, sc_link_proto
->adapter_unit
);
#else /* SCSI_DELAY > 2 */
DELAY(1000000 * SCSI_DELAY
);
scsi_probe_bus(scsibus
- 1,-1,-1);
* Probe the requested scsi bus. It must be already set up.
* -1 requests all set up scsi busses.
* targ and lun optionally narrow the search if not -1
scsi_probe_busses(int bus
, int targ
, int lun
)
for(bus
= 0; bus
< scsibus
; bus
++) {
scsi_probe_bus(bus
, targ
, lun
);
return scsi_probe_bus(bus
, targ
, lun
);
* Probe the requested scsi bus. It must be already set up.
* targ and lun optionally narrow the search if not -1
scsi_probe_bus(int bus
, int targ
, int lun
)
struct scsibus_data
*scsi
;
int maxtarg
,mintarg
,maxlun
,minlun
;
struct scsi_link
*sc_link_proto
;
struct scsidevs
*bestmatch
= NULL
;
struct predefined
*predef
= NULL
;
struct scsi_link
*sc_link
= NULL
;
if ((bus
< 0 ) || ( bus
>= scsibus
)) {
sc_link_proto
= scsi
->adapter_link
;
scsi_addr
= sc_link_proto
->adapter_targ
;
if((targ
< 0 ) || (targ
> 7)) return EINVAL
;
maxtarg
= mintarg
= targ
;
if((lun
< 0 ) || (lun
> 7)) return EINVAL
;
for ( targ
= mintarg
;targ
<= maxtarg
; targ
++) {
maybe_more
= 0; /* by default only check 1 lun */
for ( lun
= minlun
; lun
<= maxlun
;lun
++) {
* The spot appears to already have something
* linked in, skip past it. Must be doing a 'reprobe'
if(scsi
->sc_link
[targ
][lun
])
{/* don't do this one, but check other luns */
* If we presently don't have a link block
* then allocate one to use while probing
sc_link
= malloc(sizeof(*sc_link
), M_TEMP
, M_NOWAIT
);
*sc_link
= *sc_link_proto
; /* struct copy */
sc_link
->device
= &probe_switch
;
predef
= scsi_get_predef(sc_link
, &maybe_more
);
bestmatch
= scsi_probedev(sc_link
, &maybe_more
);
if ((bestmatch
) && (predef
)) { /* both exist */
if (bestmatch
->attach_rtn
printf("Clash in found/expected devices\n");
if(bestmatch
== &unknowndev
) {
printf("will link in PREDEFINED\n");
(*(predef
->attach_rtn
)) (sc_link
);
printf("will link in FOUND\n");
(*(bestmatch
->attach_rtn
)) (sc_link
);
(*(bestmatch
->attach_rtn
)) (sc_link
);
if ((bestmatch
) && (!predef
)) { /* just FOUND */
(*(bestmatch
->attach_rtn
)) (sc_link
);
if ((!bestmatch
) && (predef
)) { /* just predef */
(*(predef
->attach_rtn
)) (sc_link
);
if ((bestmatch
) || (predef
)) { /* one exists */
scsi
->sc_link
[targ
][lun
] = sc_link
;
sc_link
= NULL
; /* it's been used */
if (!(maybe_more
)) { /* nothing suggests we'll find more */
break; /* nothing here, skip to next targ */
/* otherwise something says we should look further */
* given a target and lu, check if there is a predefined device for
scsi_get_predef(sc_link
, maybe_more
)
struct scsi_link
*sc_link
;
u_int8 unit
= sc_link
->scsibus
;
u_int8 target
= sc_link
->target
;
u_int8 lu
= sc_link
->lun
;
struct scsi_adapter
*scsi_adapter
= sc_link
->adapter
;
numents
= (sizeof(pd
) / sizeof(struct predefined
)) - 1;
for (upto
= 0; upto
< numents
; upto
++) {
if (pd
[upto
].scsibus
!= unit
)
if (pd
[upto
].dev
!= target
)
printf("%s%d targ %d lun %d: <%s> - PRECONFIGURED -\n"
*maybe_more
= pd
[upto
].flags
& SC_MORE_LUS
;
return ((struct predefined
*) 0);
* given a target and lu, ask the device what
* it is, and find the correct driver table
scsi_probedev(sc_link
, maybe_more
)
struct scsi_link
*sc_link
;
u_int8 unit
= sc_link
->adapter_unit
;
u_int8 target
= sc_link
->target
;
u_int8 lu
= sc_link
->lun
;
struct scsi_adapter
*scsi_adapter
= sc_link
->adapter
;
struct scsidevs
*bestmatch
= (struct scsidevs
*) 0;
char *dtype
= (char *) 0, *desc
;
static struct scsi_inquiry_data inqbuf
;
u_int32 len
, qualifier
, type
;
bzero(&inqbuf
, sizeof(inqbuf
));
* Ask the device what it is
if ((target
== DEBUGTARG
) && (lu
== DEBUGLUN
))
sc_link
->flags
|= (DEBUGLEVEL
);
sc_link
->flags
&= ~(SDEV_DB1
| SDEV_DB2
| SDEV_DB3
| SDEV_DB4
);
scsi_test_unit_ready(sc_link
, SCSI_NOSLEEP
| SCSI_NOMASK
| SCSI_SILENT
);
switch (scsi_test_unit_ready(sc_link
, SCSI_NOSLEEP
| SCSI_NOMASK
| SCSI_SILENT
)) {
case 0: /* said it WAS ready */
case EBUSY
: /* replied 'NOT READY' but WAS present, continue */
case EIO
: /* device timed out */
case EINVAL
: /* Lun not supported */
return (struct scsidevs
*) 0;
/* some devices need to be told to go to SCSI2 */
/* However some just explode if you tell them this.. leave it out */
scsi_change_def(sc_link
, SCSI_NOSLEEP
| SCSI_NOMASK
| SCSI_SILENT
);
/* Now go ask the device all about itself */
if (scsi_inquire(sc_link
, &inqbuf
, SCSI_NOSLEEP
| SCSI_NOMASK
) != 0) {
return (struct scsidevs
*) 0;
* note what BASIC type of device it is
type
= inqbuf
.device
& SID_TYPE
;
qualifier
= inqbuf
.device
& SID_QUAL
;
remov
= inqbuf
.dev_qual2
& SID_REMOVABLE
;
* Any device qualifier that has the top bit set (qualifier&4 != 0)
* is vendor specific and won't match in this switch.
switch ((int)qualifier
) {
case SID_QUAL_LU_OFFLINE
:
qtype
= ", Unit not Connected!";
qtype
= ", Reserved Peripheral Qualifier!";
return (struct scsidevs
*) 0;
* Check for a non-existent unit. If the device is returning
* this much, then we must set the flag that has
* the searchers keep looking on other luns.
qtype
= ", The Target can't support this Unit!";
return (struct scsidevs
*) 0;
dtype
= "vendor specific";
return (struct scsidevs
*) 0;
* Then if it's advanced enough, more detailed
if ((inqbuf
.version
& SID_ANSII
) > 0) {
if ((len
= inqbuf
.additional_length
+ ((char *) inqbuf
.unused
> (sizeof(struct scsi_inquiry_data
) - 1))
len
= sizeof(struct scsi_inquiry_data
) - 1;
desc
[len
- (desc
- (char *) &inqbuf
)] = 0;
strncpy(manu
, inqbuf
.vendor
, 8);
strncpy(model
, inqbuf
.product
, 16);
strncpy(version
, inqbuf
.revision
, 4);
* If not advanced enough, use default values
desc
= "early protocol device";
strncpy(manu
, "unknown", 8);
strncpy(model
, "unknown", 16);
strncpy(version
, "????", 4);
printf("%s%d targ %d lun %d: type %d(%s) %s SCSI%d\n"
,remov
? "removable" : "fixed"
,inqbuf
.version
& SID_ANSII
printf("%s%d targ %d lun %d: <%s%s%s>\n"
printf("%s%d targ %d lun %d: qualifier %d(%s)\n"
* Try make as good a match as possible with
qualifier
, type
, remov
? T_REMOV
: T_FIXED
, manu
, model
, version
));
if ((bestmatch
) && (bestmatch
->flags
& SC_MORE_LUS
)) {
* Try make as good a match as possible with
selectdev(qualifier
, type
, remov
, manu
, model
, rev
)
char *manu
, *model
, *rev
;
u_int32 numents
= (sizeof(knowndevs
) / sizeof(struct scsidevs
)) - 1;
struct scsidevs
*bestmatch
= (struct scsidevs
*) 0;
struct scsidevs
*thisentry
= knowndevs
;
type
|= qualifier
; /* why? */
while (count
++ < numents
) {
if (type
!= thisentry
->type
) {
if (remov
!= thisentry
->removable
) {
if (thisentry
->flags
& SC_SHOWME
)
printf("\n%s-\n%s-", thisentry
->manufacturer
, manu
);
if (strcmp(thisentry
->manufacturer
, manu
)) {
if (thisentry
->flags
& SC_SHOWME
)
printf("\n%s-\n%s-", thisentry
->model
, model
);
if (strcmp(thisentry
->model
, model
)) {
if (thisentry
->flags
& SC_SHOWME
)
printf("\n%s-\n%s-", thisentry
->version
, rev
);
if (strcmp(thisentry
->version
, rev
)) {
if (bestmatch
== (struct scsidevs
*) 0) {
printf("No explicit device driver match.\n");