Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.9.3.1
      1      1.1      cgd /*
      2      1.1      cgd  * Written by Julian Elischer (julian (at) tfs.com)
      3      1.5  deraadt  * for TRW Financial Systems for use under the MACH(2.5) operating system.
      4      1.1      cgd  *
      5      1.1      cgd  * TRW Financial Systems, in accordance with their agreement with Carnegie
      6      1.1      cgd  * Mellon University, makes this software available to CMU to distribute
      7      1.1      cgd  * or use in any manner that they see fit as long as this message is kept with
      8      1.1      cgd  * the software. For this reason TFS also grants any other persons or
      9      1.1      cgd  * organisations permission to use or modify this software.
     10      1.1      cgd  *
     11      1.1      cgd  * TFS supplies this software to be publicly redistributed
     12      1.1      cgd  * on the understanding that TFS is not responsible for the correct
     13      1.1      cgd  * functioning of this software in any circumstances.
     14      1.7      cgd  *
     15  1.9.3.1  mycroft  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     16  1.9.3.1  mycroft  *
     17  1.9.3.1  mycroft  *      $Id: scsiconf.c,v 1.9.3.1 1993/11/24 05:03:06 mycroft Exp $
     18      1.1      cgd  */
     19      1.1      cgd 
     20  1.9.3.1  mycroft #include <sys/types.h>
     21  1.9.3.1  mycroft #include <sys/param.h>
     22  1.9.3.1  mycroft #include <sys/systm.h>
     23  1.9.3.1  mycroft #include <sys/malloc.h>
     24  1.9.3.1  mycroft #include <sys/device.h>
     25      1.1      cgd 
     26      1.1      cgd #include "st.h"
     27      1.1      cgd #include "sd.h"
     28      1.1      cgd #include "ch.h"
     29      1.1      cgd #include "cd.h"
     30  1.9.3.1  mycroft #include "uk.h"
     31  1.9.3.1  mycroft #include "su.h"
     32  1.9.3.1  mycroft 
     33  1.9.3.1  mycroft #include <scsi/scsi_all.h>
     34  1.9.3.1  mycroft #include <scsi/scsiconf.h>
     35  1.9.3.1  mycroft 
     36  1.9.3.1  mycroft 
     37  1.9.3.1  mycroft 
     38  1.9.3.1  mycroft #ifdef TFS
     39  1.9.3.1  mycroft #include "bll.h"
     40  1.9.3.1  mycroft #include "cals.h"
     41  1.9.3.1  mycroft #include "kil.h"
     42  1.9.3.1  mycroft #include "scan.h"
     43  1.9.3.1  mycroft #else /* TFS */
     44      1.1      cgd #define	NBLL 0
     45      1.1      cgd #define	NCALS 0
     46      1.1      cgd #define	NKIL 0
     47  1.9.3.1  mycroft #define	NSCAN 0
     48  1.9.3.1  mycroft #endif /* TFS */
     49      1.1      cgd 
     50      1.1      cgd #if NSD > 0
     51  1.9.3.1  mycroft extern  sdattach();
     52  1.9.3.1  mycroft #endif	/* NSD */
     53      1.1      cgd #if NST > 0
     54  1.9.3.1  mycroft extern  stattach();
     55  1.9.3.1  mycroft #endif	/* NST */
     56      1.1      cgd #if NCH > 0
     57  1.9.3.1  mycroft extern  chattach();
     58  1.9.3.1  mycroft #endif	/* NCH */
     59      1.1      cgd #if NCD > 0
     60  1.9.3.1  mycroft extern  cdattach();
     61  1.9.3.1  mycroft #endif	/* NCD */
     62      1.1      cgd #if NBLL > 0
     63  1.9.3.1  mycroft extern  bllattach();
     64  1.9.3.1  mycroft #endif	/* NBLL */
     65      1.1      cgd #if NCALS > 0
     66  1.9.3.1  mycroft extern  calsattach();
     67  1.9.3.1  mycroft #endif	/* NCALS */
     68      1.1      cgd #if NKIL > 0
     69  1.9.3.1  mycroft extern  kil_attach();
     70  1.9.3.1  mycroft #endif	/* NKIL */
     71  1.9.3.1  mycroft #if NUK > 0
     72  1.9.3.1  mycroft extern  ukattach();
     73  1.9.3.1  mycroft #endif	/* NUK */
     74  1.9.3.1  mycroft 
     75  1.9.3.1  mycroft /*
     76  1.9.3.1  mycroft  * The structure of pre-configured devices that might be turned
     77  1.9.3.1  mycroft  * off and therefore may not show up
     78  1.9.3.1  mycroft  */
     79  1.9.3.1  mycroft struct predefined {
     80  1.9.3.1  mycroft 	u_char  scsibus;
     81  1.9.3.1  mycroft 	u_char  dev;
     82  1.9.3.1  mycroft 	u_char  lu;
     83  1.9.3.1  mycroft 	        errval(*attach_rtn) ();
     84  1.9.3.1  mycroft 	char   *devname;
     85  1.9.3.1  mycroft 	char    flags;
     86  1.9.3.1  mycroft } pd[] =
     87  1.9.3.1  mycroft 
     88  1.9.3.1  mycroft {
     89  1.9.3.1  mycroft #ifdef EXAMPLE_PREDEFINE
     90  1.9.3.1  mycroft #if NSD > 0
     91  1.9.3.1  mycroft 	{
     92  1.9.3.1  mycroft 		0, 0, 0, sdattach, "sd", 0
     93  1.9.3.1  mycroft 	},			/* define a disk at scsibus=0 dev=0 lu=0 */
     94  1.9.3.1  mycroft #endif	/* NSD */
     95  1.9.3.1  mycroft #endif	/* EXAMPLE_PREDEFINE */
     96  1.9.3.1  mycroft 	{
     97  1.9.3.1  mycroft 		0, 9, 9
     98  1.9.3.1  mycroft 	} /*illegal dummy end entry */
     99  1.9.3.1  mycroft };
    100      1.1      cgd 
    101  1.9.3.1  mycroft /*
    102  1.9.3.1  mycroft  * The structure of known drivers for autoconfiguration
    103  1.9.3.1  mycroft  */
    104  1.9.3.1  mycroft struct scsidevs {
    105  1.9.3.1  mycroft 	u_int32 type;
    106  1.9.3.1  mycroft 	boolean removable;
    107  1.9.3.1  mycroft 	char   *manufacturer;
    108  1.9.3.1  mycroft 	char   *model;
    109  1.9.3.1  mycroft 	char   *version;
    110  1.9.3.1  mycroft 	        errval(*attach_rtn) ();
    111  1.9.3.1  mycroft 	char   *devname;
    112  1.9.3.1  mycroft 	char    flags;		/* 1 show my comparisons during boot(debug) */
    113  1.9.3.1  mycroft };
    114  1.9.3.1  mycroft 
    115  1.9.3.1  mycroft #define SC_SHOWME	0x01
    116  1.9.3.1  mycroft #define	SC_ONE_LU	0x00
    117  1.9.3.1  mycroft #define	SC_MORE_LUS	0x02
    118  1.9.3.1  mycroft #if	NUK > 0
    119  1.9.3.1  mycroft 
    120  1.9.3.1  mycroft static struct scsidevs unknowndev = {
    121  1.9.3.1  mycroft 	-1, 0, "standard", "any"
    122  1.9.3.1  mycroft 	    ,"any", ukattach, "uk", SC_MORE_LUS
    123  1.9.3.1  mycroft };
    124  1.9.3.1  mycroft #endif 	/*NUK*/
    125  1.9.3.1  mycroft static struct scsidevs knowndevs[] =
    126  1.9.3.1  mycroft {
    127      1.1      cgd #if NSD > 0
    128      1.2  deraadt 	{
    129  1.9.3.1  mycroft 		T_DIRECT, T_FIXED, "standard", "any"
    130  1.9.3.1  mycroft 		    ,"any", sdattach, "sd", SC_ONE_LU
    131      1.2  deraadt 	},
    132      1.2  deraadt 	{
    133  1.9.3.1  mycroft 		T_DIRECT, T_FIXED, "MAXTOR  ", "XT-4170S        "
    134  1.9.3.1  mycroft 		    ,"B5A ", sdattach, "mx1", SC_ONE_LU
    135      1.2  deraadt 	},
    136  1.9.3.1  mycroft #endif	/* NSD */
    137  1.9.3.1  mycroft #if NST > 0
    138      1.2  deraadt 	{
    139  1.9.3.1  mycroft 		T_SEQUENTIAL, T_REMOV, "standard", "any"
    140  1.9.3.1  mycroft 		    ,"any", stattach, "st", SC_ONE_LU
    141      1.2  deraadt 	},
    142  1.9.3.1  mycroft #endif	/* NST */
    143      1.1      cgd #if NCALS > 0
    144      1.2  deraadt 	{
    145  1.9.3.1  mycroft 		T_PROCESSOR, T_FIXED, "standard", "any"
    146  1.9.3.1  mycroft 		    ,"any", calsattach, "cals", SC_MORE_LUS
    147  1.9.3.1  mycroft 	},
    148  1.9.3.1  mycroft #endif	/* NCALS */
    149      1.1      cgd #if NCH > 0
    150      1.2  deraadt 	{
    151  1.9.3.1  mycroft 		T_CHANGER, T_REMOV, "standard", "any"
    152  1.9.3.1  mycroft 		    ,"any", chattach, "ch", SC_ONE_LU
    153      1.2  deraadt 	},
    154  1.9.3.1  mycroft #endif	/* NCH */
    155  1.9.3.1  mycroft #if NCD > 0
    156  1.9.3.1  mycroft #ifndef UKTEST	/* make cdroms unrecognised to test the uk driver */
    157  1.9.3.1  mycroft 	{
    158  1.9.3.1  mycroft 		T_READONLY, T_REMOV, "SONY    ", "CD-ROM CDU-8012 "
    159  1.9.3.1  mycroft 		    ,"3.1a", cdattach, "cd", SC_ONE_LU
    160  1.9.3.1  mycroft 	},
    161  1.9.3.1  mycroft 	{
    162  1.9.3.1  mycroft 		T_READONLY, T_REMOV, "PIONEER ", "CD-ROM DRM-600  "
    163  1.9.3.1  mycroft 		    ,"any", cdattach, "cd", SC_MORE_LUS
    164  1.9.3.1  mycroft 	},
    165  1.9.3.1  mycroft #endif
    166  1.9.3.1  mycroft #endif	/* NCD */
    167      1.1      cgd #if NBLL > 0
    168      1.2  deraadt 	{
    169  1.9.3.1  mycroft 		T_PROCESSOR, T_FIXED, "AEG     ", "READER          "
    170  1.9.3.1  mycroft 		    ,"V1.0", bllattach, "bll", SC_MORE_LUS
    171      1.2  deraadt 	},
    172  1.9.3.1  mycroft #endif	/* NBLL */
    173      1.1      cgd #if NKIL > 0
    174      1.2  deraadt 	{
    175  1.9.3.1  mycroft 		T_SCANNER, T_FIXED, "KODAK   ", "IL Scanner 900  "
    176  1.9.3.1  mycroft 		    ,"any", kil_attach, "kil", SC_ONE_LU
    177      1.2  deraadt 	},
    178  1.9.3.1  mycroft #endif	/* NKIL */
    179  1.9.3.1  mycroft 
    180  1.9.3.1  mycroft 	{
    181  1.9.3.1  mycroft 		0
    182  1.9.3.1  mycroft 	}
    183  1.9.3.1  mycroft };
    184  1.9.3.1  mycroft 
    185  1.9.3.1  mycroft /*
    186  1.9.3.1  mycroft  * Declarations
    187  1.9.3.1  mycroft  */
    188  1.9.3.1  mycroft struct predefined *scsi_get_predef();
    189  1.9.3.1  mycroft struct scsidevs *scsi_probedev();
    190  1.9.3.1  mycroft struct scsidevs *selectdev();
    191  1.9.3.1  mycroft errval scsi_probe_bus __P((int bus, int targ, int lun));
    192  1.9.3.1  mycroft 
    193  1.9.3.1  mycroft struct scsi_device probe_switch =
    194  1.9.3.1  mycroft {
    195  1.9.3.1  mycroft     NULL,
    196  1.9.3.1  mycroft     NULL,
    197  1.9.3.1  mycroft     NULL,
    198  1.9.3.1  mycroft     NULL,
    199  1.9.3.1  mycroft     "probe",
    200  1.9.3.1  mycroft     0,
    201      1.2  deraadt };
    202      1.2  deraadt 
    203  1.9.3.1  mycroft int scsibusmatch __P((struct device *, struct cfdata *, void *));
    204  1.9.3.1  mycroft void scsibusattach __P((struct device *, struct device *, void *));
    205      1.1      cgd 
    206  1.9.3.1  mycroft struct  cfdriver scsibuscd =
    207  1.9.3.1  mycroft {
    208  1.9.3.1  mycroft 	NULL,
    209  1.9.3.1  mycroft 	"scsibus",
    210  1.9.3.1  mycroft 	scsibusmatch,
    211  1.9.3.1  mycroft 	scsibusattach,
    212  1.9.3.1  mycroft 	DV_DULL,
    213  1.9.3.1  mycroft 	sizeof(struct scsibus_data)
    214  1.9.3.1  mycroft };
    215  1.9.3.1  mycroft 
    216  1.9.3.1  mycroft int
    217  1.9.3.1  mycroft scsibusmatch(parent, cf, aux)
    218  1.9.3.1  mycroft         struct device *parent;
    219  1.9.3.1  mycroft         struct cfdata *cf;
    220  1.9.3.1  mycroft         void *aux;
    221  1.9.3.1  mycroft {
    222  1.9.3.1  mycroft 
    223  1.9.3.1  mycroft 	return 1;
    224  1.9.3.1  mycroft }
    225  1.9.3.1  mycroft 
    226  1.9.3.1  mycroft /*
    227  1.9.3.1  mycroft  * The routine called by the adapter boards to get all their
    228  1.9.3.1  mycroft  * devices configured in.
    229  1.9.3.1  mycroft  */
    230  1.9.3.1  mycroft void
    231  1.9.3.1  mycroft scsibusattach(parent, self, aux)
    232  1.9.3.1  mycroft         struct device *parent, *self;
    233  1.9.3.1  mycroft         void *aux;
    234  1.9.3.1  mycroft {
    235  1.9.3.1  mycroft 	struct scsibus_data *sb = (struct scsibus_data *)self;
    236  1.9.3.1  mycroft 	struct scsi_link *sc_link_proto = aux;
    237  1.9.3.1  mycroft 
    238  1.9.3.1  mycroft 	sc_link_proto->scsibus = sb->sc_dev.dv_unit;
    239  1.9.3.1  mycroft 	sb->adapter_link = sc_link_proto;
    240  1.9.3.1  mycroft 	printf("\n");
    241  1.9.3.1  mycroft 
    242  1.9.3.1  mycroft #if defined(SCSI_DELAY) && SCSI_DELAY > 2
    243  1.9.3.1  mycroft 	printf("%s: waiting for scsi devices to settle\n",
    244  1.9.3.1  mycroft 		sb->sc_dev.dv_xname);
    245  1.9.3.1  mycroft #else	/* SCSI_DELAY > 2 */
    246  1.9.3.1  mycroft #undef	SCSI_DELAY
    247  1.9.3.1  mycroft #define SCSI_DELAY 2
    248  1.9.3.1  mycroft #endif	/* SCSI_DELAY */
    249  1.9.3.1  mycroft 	DELAY(1000000 * SCSI_DELAY);
    250  1.9.3.1  mycroft 
    251  1.9.3.1  mycroft 	scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
    252  1.9.3.1  mycroft }
    253  1.9.3.1  mycroft 
    254  1.9.3.1  mycroft /*
    255  1.9.3.1  mycroft  * Probe the requested scsi bus. It must be already set up.
    256  1.9.3.1  mycroft  * -1 requests all set up scsi busses.
    257  1.9.3.1  mycroft  * targ and lun optionally narrow the search if not -1
    258  1.9.3.1  mycroft  */
    259  1.9.3.1  mycroft errval
    260  1.9.3.1  mycroft scsi_probe_busses(bus, targ, lun)
    261  1.9.3.1  mycroft 	int bus, targ, lun;
    262  1.9.3.1  mycroft {
    263  1.9.3.1  mycroft 	if (bus == -1) {
    264  1.9.3.1  mycroft 		for (bus = 0; bus < scsibuscd.cd_ndevs; bus++)
    265  1.9.3.1  mycroft 			if (scsibuscd.cd_devs[bus])
    266  1.9.3.1  mycroft 				scsi_probe_bus(bus, targ, lun);
    267  1.9.3.1  mycroft 		return 0;
    268  1.9.3.1  mycroft 	} else {
    269  1.9.3.1  mycroft 		return scsi_probe_bus(bus, targ, lun);
    270  1.9.3.1  mycroft 	}
    271  1.9.3.1  mycroft }
    272  1.9.3.1  mycroft 
    273  1.9.3.1  mycroft /*
    274  1.9.3.1  mycroft  * Probe the requested scsi bus. It must be already set up.
    275  1.9.3.1  mycroft  * targ and lun optionally narrow the search if not -1
    276  1.9.3.1  mycroft  */
    277  1.9.3.1  mycroft errval
    278  1.9.3.1  mycroft scsi_probe_bus(bus, targ, lun)
    279  1.9.3.1  mycroft 	int bus, targ, lun;
    280  1.9.3.1  mycroft {
    281  1.9.3.1  mycroft 	struct scsibus_data *scsi;
    282  1.9.3.1  mycroft 	int	maxtarg, mintarg, maxlun, minlun;
    283  1.9.3.1  mycroft 	struct scsi_link *sc_link_proto;
    284  1.9.3.1  mycroft 	u_int8  scsi_addr ;
    285  1.9.3.1  mycroft 	struct scsidevs *bestmatch = NULL;
    286  1.9.3.1  mycroft 	struct predefined *predef = NULL;
    287  1.9.3.1  mycroft 	struct scsi_link *sc_link = NULL;
    288  1.9.3.1  mycroft 	boolean maybe_more;
    289  1.9.3.1  mycroft 
    290  1.9.3.1  mycroft 	if (bus < 0 || bus >= scsibuscd.cd_ndevs)
    291  1.9.3.1  mycroft 		return ENXIO;
    292  1.9.3.1  mycroft 	scsi = scsibuscd.cd_devs[bus];
    293  1.9.3.1  mycroft 	if (!scsi)
    294  1.9.3.1  mycroft 		return ENXIO;
    295  1.9.3.1  mycroft 
    296  1.9.3.1  mycroft 	sc_link_proto = scsi->adapter_link;
    297  1.9.3.1  mycroft 	scsi_addr = sc_link_proto->adapter_targ;
    298  1.9.3.1  mycroft 
    299  1.9.3.1  mycroft 	if (targ == -1) {
    300  1.9.3.1  mycroft 		maxtarg = 7;
    301  1.9.3.1  mycroft 		mintarg = 0;
    302  1.9.3.1  mycroft 	} else {
    303  1.9.3.1  mycroft 		if (targ < 0 || targ > 7)
    304  1.9.3.1  mycroft 			return EINVAL;
    305  1.9.3.1  mycroft 		maxtarg = mintarg = targ;
    306  1.9.3.1  mycroft 	}
    307  1.9.3.1  mycroft 
    308  1.9.3.1  mycroft 	if (lun == -1 ){
    309  1.9.3.1  mycroft 		maxlun = 7;
    310  1.9.3.1  mycroft 		minlun = 0;
    311  1.9.3.1  mycroft 	} else {
    312  1.9.3.1  mycroft 		if (lun < 0 || lun > 7)
    313  1.9.3.1  mycroft 			return EINVAL;
    314  1.9.3.1  mycroft 		maxlun = minlun = lun;
    315  1.9.3.1  mycroft 	}
    316  1.9.3.1  mycroft 
    317  1.9.3.1  mycroft 
    318  1.9.3.1  mycroft 	for (targ = mintarg; targ <= maxtarg; targ++) {
    319  1.9.3.1  mycroft 		maybe_more = 0;	/* by default only check 1 lun */
    320  1.9.3.1  mycroft #if 0
    321  1.9.3.1  mycroft 		if (targ == scsi_addr)
    322  1.9.3.1  mycroft 			continue;
    323  1.9.3.1  mycroft #endif
    324  1.9.3.1  mycroft 		for (lun = minlun; lun <= maxlun; lun++) {
    325  1.9.3.1  mycroft 			/*
    326  1.9.3.1  mycroft 			 * The spot appears to already have something
    327  1.9.3.1  mycroft 			 * linked in, skip past it. Must be doing a 'reprobe'
    328  1.9.3.1  mycroft 			 */
    329  1.9.3.1  mycroft 			if (scsi->sc_link[targ][lun]) {
    330  1.9.3.1  mycroft 				/* don't do this one, but check other luns */
    331  1.9.3.1  mycroft 				maybe_more = 1;
    332  1.9.3.1  mycroft 				continue;
    333  1.9.3.1  mycroft 			}
    334  1.9.3.1  mycroft 			/*
    335  1.9.3.1  mycroft 			 * If we presently don't have a link block
    336  1.9.3.1  mycroft 			 * then allocate one to use while probing
    337  1.9.3.1  mycroft 			 */
    338  1.9.3.1  mycroft 			if (!sc_link) {
    339  1.9.3.1  mycroft 				sc_link = malloc(sizeof(*sc_link), M_TEMP, M_NOWAIT);
    340  1.9.3.1  mycroft 				*sc_link = *sc_link_proto;	/* struct copy */
    341  1.9.3.1  mycroft 				sc_link->opennings = 1;
    342  1.9.3.1  mycroft 				sc_link->device = &probe_switch;
    343  1.9.3.1  mycroft 			}
    344  1.9.3.1  mycroft 			sc_link->target = targ;
    345  1.9.3.1  mycroft 			sc_link->lun = lun;
    346  1.9.3.1  mycroft 			predef = scsi_get_predef(sc_link, &maybe_more);
    347  1.9.3.1  mycroft 			bestmatch = scsi_probedev(sc_link, &maybe_more);
    348  1.9.3.1  mycroft 			if (bestmatch && predef) {	/* both exist */
    349  1.9.3.1  mycroft 				if (bestmatch->attach_rtn
    350  1.9.3.1  mycroft 				    != predef->attach_rtn) {
    351  1.9.3.1  mycroft 					printf("Clash in found/expected devices\n");
    352  1.9.3.1  mycroft #if NUK > 0
    353  1.9.3.1  mycroft 					if (bestmatch == &unknowndev) {
    354  1.9.3.1  mycroft 						printf("will link in PREDEFINED\n");
    355  1.9.3.1  mycroft 						(*(predef->attach_rtn)) (sc_link);
    356  1.9.3.1  mycroft 					} else
    357  1.9.3.1  mycroft #endif	/*NUK*/
    358  1.9.3.1  mycroft 					{
    359  1.9.3.1  mycroft 						printf("will link in FOUND\n");
    360  1.9.3.1  mycroft 						(*(bestmatch->attach_rtn)) (sc_link);
    361  1.9.3.1  mycroft 					}
    362  1.9.3.1  mycroft 				} else {
    363  1.9.3.1  mycroft 					(*(bestmatch->attach_rtn)) (sc_link);
    364  1.9.3.1  mycroft 				}
    365  1.9.3.1  mycroft 			}
    366  1.9.3.1  mycroft 			if (bestmatch && !predef)	/* just FOUND */
    367  1.9.3.1  mycroft 				(*(bestmatch->attach_rtn)) (sc_link);
    368  1.9.3.1  mycroft 			if (!bestmatch && predef)	/* just predef */
    369  1.9.3.1  mycroft 				(*(predef->attach_rtn)) (sc_link);
    370  1.9.3.1  mycroft 			if (bestmatch || predef) {	/* one exists */
    371  1.9.3.1  mycroft 				scsi->sc_link[targ][lun] = sc_link;
    372  1.9.3.1  mycroft 				sc_link = NULL;		/* it's been used */
    373  1.9.3.1  mycroft 			}
    374  1.9.3.1  mycroft 			if (!(maybe_more)) {	/* nothing suggests we'll find more */
    375  1.9.3.1  mycroft 				break;	/* nothing here, skip to next targ */
    376  1.9.3.1  mycroft 			}
    377  1.9.3.1  mycroft 			/* otherwise something says we should look further */
    378  1.9.3.1  mycroft 		}
    379  1.9.3.1  mycroft 	}
    380  1.9.3.1  mycroft 	if (sc_link) {
    381  1.9.3.1  mycroft 		free(sc_link, M_TEMP);
    382  1.9.3.1  mycroft 	}
    383  1.9.3.1  mycroft 	return 0;
    384  1.9.3.1  mycroft }
    385  1.9.3.1  mycroft 
    386  1.9.3.1  mycroft /*
    387  1.9.3.1  mycroft  * given a target and lu, check if there is a predefined device for
    388  1.9.3.1  mycroft  * that address
    389  1.9.3.1  mycroft  */
    390  1.9.3.1  mycroft struct predefined *
    391  1.9.3.1  mycroft scsi_get_predef(sc_link, maybe_more)
    392  1.9.3.1  mycroft 	struct scsi_link *sc_link;
    393  1.9.3.1  mycroft 	boolean *maybe_more;
    394  1.9.3.1  mycroft {
    395  1.9.3.1  mycroft 	u_int8  unit = sc_link->scsibus;
    396  1.9.3.1  mycroft 	u_int8  target = sc_link->target;
    397  1.9.3.1  mycroft 	u_int8  lu = sc_link->lun;
    398  1.9.3.1  mycroft 	struct scsi_adapter *scsi_adapter = sc_link->adapter;
    399  1.9.3.1  mycroft 	u_int32 upto, numents;
    400  1.9.3.1  mycroft 
    401  1.9.3.1  mycroft 	numents = (sizeof(pd) / sizeof(struct predefined)) - 1;
    402  1.9.3.1  mycroft 
    403  1.9.3.1  mycroft 	for (upto = 0; upto < numents; upto++) {
    404  1.9.3.1  mycroft 		if (pd[upto].scsibus != unit)
    405  1.9.3.1  mycroft 			continue;
    406  1.9.3.1  mycroft 		if (pd[upto].dev != target)
    407  1.9.3.1  mycroft 			continue;
    408  1.9.3.1  mycroft 		if (pd[upto].lu != lu)
    409  1.9.3.1  mycroft 			continue;
    410  1.9.3.1  mycroft 
    411  1.9.3.1  mycroft 		printf("%s%d targ %d lun %d: <%s> - PRECONFIGURED -\n"
    412  1.9.3.1  mycroft 		    ,scsi_adapter->name
    413  1.9.3.1  mycroft 		    ,unit
    414  1.9.3.1  mycroft 		    ,target
    415  1.9.3.1  mycroft 		    ,lu
    416  1.9.3.1  mycroft 		    ,pd[upto].devname);
    417  1.9.3.1  mycroft 		*maybe_more = pd[upto].flags & SC_MORE_LUS;
    418  1.9.3.1  mycroft 		return &(pd[upto]);
    419  1.9.3.1  mycroft 	}
    420  1.9.3.1  mycroft 	return NULL;
    421  1.9.3.1  mycroft }
    422  1.9.3.1  mycroft 
    423  1.9.3.1  mycroft /*
    424  1.9.3.1  mycroft  * given a target and lu, ask the device what
    425  1.9.3.1  mycroft  * it is, and find the correct driver table
    426  1.9.3.1  mycroft  * entry.
    427  1.9.3.1  mycroft  */
    428      1.2  deraadt struct scsidevs *
    429  1.9.3.1  mycroft scsi_probedev(sc_link, maybe_more)
    430  1.9.3.1  mycroft 	boolean *maybe_more;
    431  1.9.3.1  mycroft 	struct scsi_link *sc_link;
    432      1.1      cgd {
    433  1.9.3.1  mycroft 	u_int8  target = sc_link->target;
    434  1.9.3.1  mycroft 	u_int8  lun = sc_link->lun;
    435  1.9.3.1  mycroft 	struct scsi_adapter *scsi_adapter = sc_link->adapter;
    436  1.9.3.1  mycroft 	struct scsidevs *bestmatch = NULL;
    437  1.9.3.1  mycroft 	char   *dtype = NULL, *desc;
    438  1.9.3.1  mycroft 	char   *qtype;
    439      1.2  deraadt 	static struct scsi_inquiry_data inqbuf;
    440  1.9.3.1  mycroft 	u_int32 len, qualifier, type;
    441  1.9.3.1  mycroft 	boolean remov;
    442  1.9.3.1  mycroft 	char    manu[32];
    443  1.9.3.1  mycroft 	char    model[32];
    444  1.9.3.1  mycroft 	char    version[32];
    445  1.9.3.1  mycroft 
    446  1.9.3.1  mycroft 	bzero(&inqbuf, sizeof(inqbuf));
    447  1.9.3.1  mycroft 	/*
    448  1.9.3.1  mycroft 	 * Ask the device what it is
    449  1.9.3.1  mycroft 	 */
    450  1.9.3.1  mycroft #ifdef	SCSIDEBUG
    451  1.9.3.1  mycroft 	if (target == DEBUGTARG && lu == DEBUGLUN)
    452  1.9.3.1  mycroft 		sc_link->flags |= DEBUGLEVEL;
    453  1.9.3.1  mycroft 	else
    454  1.9.3.1  mycroft 		sc_link->flags &= ~(SDEV_DB1 | SDEV_DB2 | SDEV_DB3 | SDEV_DB4);
    455  1.9.3.1  mycroft #endif	/* SCSIDEBUG */
    456  1.9.3.1  mycroft 	/* catch unit attn */
    457  1.9.3.1  mycroft 	scsi_test_unit_ready(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT);
    458  1.9.3.1  mycroft #ifdef	DOUBTFULL
    459  1.9.3.1  mycroft 	switch (scsi_test_unit_ready(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT)) {
    460  1.9.3.1  mycroft 	case 0:		/* said it WAS ready */
    461  1.9.3.1  mycroft 	case EBUSY:		/* replied 'NOT READY' but WAS present, continue */
    462  1.9.3.1  mycroft 	case ENXIO:
    463  1.9.3.1  mycroft 		break;
    464  1.9.3.1  mycroft 	case EIO:		/* device timed out */
    465  1.9.3.1  mycroft 	case EINVAL:		/* Lun not supported */
    466  1.9.3.1  mycroft 	default:
    467  1.9.3.1  mycroft 		return NULL;
    468      1.2  deraadt 
    469  1.9.3.1  mycroft 	}
    470  1.9.3.1  mycroft #endif	/*DOUBTFULL*/
    471  1.9.3.1  mycroft #ifdef	SCSI_2_DEF
    472  1.9.3.1  mycroft 	/* some devices need to be told to go to SCSI2 */
    473  1.9.3.1  mycroft 	/* However some just explode if you tell them this.. leave it out */
    474  1.9.3.1  mycroft 	scsi_change_def(sc_link, SCSI_NOSLEEP | SCSI_NOMASK | SCSI_SILENT);
    475  1.9.3.1  mycroft #endif /*SCSI_2_DEF */
    476  1.9.3.1  mycroft 
    477  1.9.3.1  mycroft 	/* Now go ask the device all about itself */
    478  1.9.3.1  mycroft 	if (scsi_inquire(sc_link, &inqbuf, SCSI_NOSLEEP | SCSI_NOMASK) != 0)
    479  1.9.3.1  mycroft 		return NULL;
    480  1.9.3.1  mycroft 
    481  1.9.3.1  mycroft 	/*
    482  1.9.3.1  mycroft 	 * note what BASIC type of device it is
    483  1.9.3.1  mycroft 	 */
    484  1.9.3.1  mycroft 	type = inqbuf.device & SID_TYPE;
    485  1.9.3.1  mycroft 	qualifier = inqbuf.device & SID_QUAL;
    486  1.9.3.1  mycroft 	remov = inqbuf.dev_qual2 & SID_REMOVABLE;
    487  1.9.3.1  mycroft 
    488  1.9.3.1  mycroft 	/*
    489  1.9.3.1  mycroft 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    490  1.9.3.1  mycroft 	 * is vendor specific and won't match in this switch.
    491  1.9.3.1  mycroft 	 */
    492  1.9.3.1  mycroft 	switch (qualifier) {
    493  1.9.3.1  mycroft 	case SID_QUAL_LU_OK:
    494      1.2  deraadt 		qtype = "";
    495      1.2  deraadt 		break;
    496  1.9.3.1  mycroft 
    497  1.9.3.1  mycroft 	case SID_QUAL_LU_OFFLINE:
    498  1.9.3.1  mycroft 		qtype = ", Unit not Connected!";
    499      1.2  deraadt 		break;
    500  1.9.3.1  mycroft 
    501  1.9.3.1  mycroft 	case SID_QUAL_RSVD:
    502  1.9.3.1  mycroft 		qtype = ", Reserved Peripheral Qualifier!";
    503  1.9.3.1  mycroft 		*maybe_more = 1;
    504  1.9.3.1  mycroft 		return NULL;
    505      1.2  deraadt 		break;
    506  1.9.3.1  mycroft 
    507  1.9.3.1  mycroft 	case SID_QUAL_BAD_LU:
    508  1.9.3.1  mycroft 		/*
    509  1.9.3.1  mycroft 		 * Check for a non-existent unit.  If the device is returning
    510  1.9.3.1  mycroft 		 * this much, then we must set the flag that has
    511  1.9.3.1  mycroft 		 * the searchers keep looking on other luns.
    512  1.9.3.1  mycroft 		 */
    513      1.2  deraadt 		qtype = ", The Target can't support this Unit!";
    514  1.9.3.1  mycroft 		*maybe_more = 1;
    515  1.9.3.1  mycroft 		return NULL;
    516  1.9.3.1  mycroft 
    517      1.2  deraadt 	default:
    518      1.2  deraadt 		dtype = "vendor specific";
    519      1.2  deraadt 		qtype = "";
    520  1.9.3.1  mycroft 		*maybe_more = 1;
    521      1.2  deraadt 		break;
    522      1.2  deraadt 	}
    523  1.9.3.1  mycroft 	if (dtype == 0) {
    524  1.9.3.1  mycroft 		switch (type) {
    525      1.2  deraadt 		case T_DIRECT:
    526      1.2  deraadt 			dtype = "direct";
    527      1.2  deraadt 			break;
    528      1.2  deraadt 		case T_SEQUENTIAL:
    529  1.9.3.1  mycroft 			dtype = "sequential";
    530      1.2  deraadt 			break;
    531      1.2  deraadt 		case T_PRINTER:
    532  1.9.3.1  mycroft 			dtype = "printer";
    533      1.2  deraadt 			break;
    534      1.2  deraadt 		case T_PROCESSOR:
    535  1.9.3.1  mycroft 			dtype = "processor";
    536      1.2  deraadt 			break;
    537      1.2  deraadt 		case T_READONLY:
    538  1.9.3.1  mycroft 			dtype = "readonly";
    539      1.2  deraadt 			break;
    540      1.2  deraadt 		case T_WORM:
    541      1.2  deraadt 			dtype = "worm";
    542      1.2  deraadt 			break;
    543      1.2  deraadt 		case T_SCANNER:
    544  1.9.3.1  mycroft 			dtype = "scanner";
    545      1.2  deraadt 			break;
    546      1.2  deraadt 		case T_OPTICAL:
    547  1.9.3.1  mycroft 			dtype = "optical";
    548      1.2  deraadt 			break;
    549      1.2  deraadt 		case T_CHANGER:
    550      1.2  deraadt 			dtype = "changer";
    551      1.2  deraadt 			break;
    552      1.2  deraadt 		case T_COMM:
    553  1.9.3.1  mycroft 			dtype = "communication";
    554      1.2  deraadt 			break;
    555  1.9.3.1  mycroft 		case T_NODEVICE:
    556  1.9.3.1  mycroft 			*maybe_more = 1;
    557  1.9.3.1  mycroft 			return NULL;
    558      1.2  deraadt 		default:
    559  1.9.3.1  mycroft 			dtype = NULL;
    560      1.2  deraadt 			break;
    561      1.1      cgd 		}
    562      1.1      cgd 	}
    563      1.2  deraadt 
    564  1.9.3.1  mycroft 	/*
    565  1.9.3.1  mycroft 	 * Then if it's advanced enough, more detailed
    566  1.9.3.1  mycroft 	 * information
    567  1.9.3.1  mycroft 	 */
    568  1.9.3.1  mycroft 	if ((inqbuf.version & SID_ANSII) > 0) {
    569  1.9.3.1  mycroft 		if ((len = inqbuf.additional_length
    570  1.9.3.1  mycroft 			+ ((char *) inqbuf.unused
    571  1.9.3.1  mycroft 			    - (char *) &inqbuf))
    572  1.9.3.1  mycroft 		    > (sizeof(struct scsi_inquiry_data) - 1))
    573  1.9.3.1  mycroft 			        len = sizeof(struct scsi_inquiry_data) - 1;
    574      1.2  deraadt 		desc = inqbuf.vendor;
    575  1.9.3.1  mycroft 		desc[len - (desc - (char *) &inqbuf)] = 0;
    576  1.9.3.1  mycroft 		strncpy(manu, inqbuf.vendor, 8);
    577  1.9.3.1  mycroft 		manu[8] = 0;
    578  1.9.3.1  mycroft 		strncpy(model, inqbuf.product, 16);
    579  1.9.3.1  mycroft 		model[16] = 0;
    580  1.9.3.1  mycroft 		strncpy(version, inqbuf.revision, 4);
    581  1.9.3.1  mycroft 		version[4] = 0;
    582  1.9.3.1  mycroft 	} else
    583  1.9.3.1  mycroft 		/*
    584  1.9.3.1  mycroft 		 * If not advanced enough, use default values
    585  1.9.3.1  mycroft 		 */
    586  1.9.3.1  mycroft 	{
    587      1.2  deraadt 		desc = "early protocol device";
    588  1.9.3.1  mycroft 		strncpy(manu, "unknown", 8);
    589  1.9.3.1  mycroft 		strncpy(model, "unknown", 16);
    590  1.9.3.1  mycroft 		strncpy(version, "????", 4);
    591      1.1      cgd 	}
    592  1.9.3.1  mycroft 	printf("%s targ %d lun %d: <%s%s%s> SCSI%d ",
    593  1.9.3.1  mycroft 		((struct device *)sc_link->adapter_softc)->dv_xname,
    594  1.9.3.1  mycroft 		target, lun, manu, model, version,
    595  1.9.3.1  mycroft 		inqbuf.version & SID_ANSII);
    596  1.9.3.1  mycroft 	if (dtype)
    597  1.9.3.1  mycroft 		printf("%s", dtype);
    598      1.9  deraadt 	else
    599  1.9.3.1  mycroft 		printf("type %d", type);
    600  1.9.3.1  mycroft 	printf(" %s\n", remov ? "removable" : "fixed");
    601  1.9.3.1  mycroft 	if (qtype[0])
    602  1.9.3.1  mycroft 		printf("%s targ %d lun %d: qualifier %d(%s)\n",
    603  1.9.3.1  mycroft 			((struct device *)sc_link->adapter_softc)->dv_xname,
    604  1.9.3.1  mycroft 			target, lun, qualifier, qtype);
    605  1.9.3.1  mycroft 
    606  1.9.3.1  mycroft 	/*
    607  1.9.3.1  mycroft 	 * Try make as good a match as possible with
    608  1.9.3.1  mycroft 	 * available sub drivers
    609  1.9.3.1  mycroft 	 */
    610  1.9.3.1  mycroft 	bestmatch = selectdev(qualifier, type, remov ? T_REMOV : T_FIXED,
    611  1.9.3.1  mycroft 			manu, model, version);
    612  1.9.3.1  mycroft 	if (bestmatch && bestmatch->flags & SC_MORE_LUS)
    613  1.9.3.1  mycroft 		*maybe_more = 1;
    614  1.9.3.1  mycroft 	return bestmatch;
    615      1.1      cgd }
    616      1.2  deraadt /*
    617      1.2  deraadt  * Try make as good a match as possible with
    618  1.9.3.1  mycroft  * available sub drivers
    619      1.2  deraadt  */
    620      1.2  deraadt struct scsidevs *
    621  1.9.3.1  mycroft selectdev(qualifier, type, remov, manu, model, rev)
    622  1.9.3.1  mycroft 	u_int32 qualifier, type;
    623  1.9.3.1  mycroft 	boolean remov;
    624  1.9.3.1  mycroft 	char   *manu, *model, *rev;
    625      1.2  deraadt {
    626  1.9.3.1  mycroft 	u_int32 numents = (sizeof(knowndevs) / sizeof(struct scsidevs)) - 1;
    627  1.9.3.1  mycroft 	u_int32 count = 0;
    628  1.9.3.1  mycroft 	u_int32 bestmatches = 0;
    629  1.9.3.1  mycroft 	struct scsidevs *bestmatch = (struct scsidevs *) 0;
    630  1.9.3.1  mycroft 	struct scsidevs *thisentry = knowndevs;
    631  1.9.3.1  mycroft 
    632  1.9.3.1  mycroft 	type |= qualifier;	/* why? */
    633  1.9.3.1  mycroft 
    634  1.9.3.1  mycroft 	thisentry--;
    635  1.9.3.1  mycroft 	while (count++ < numents) {
    636  1.9.3.1  mycroft 		thisentry++;
    637  1.9.3.1  mycroft 		if (type != thisentry->type)
    638      1.2  deraadt 			continue;
    639  1.9.3.1  mycroft 		if (bestmatches < 1) {
    640  1.9.3.1  mycroft 			bestmatches = 1;
    641  1.9.3.1  mycroft 			bestmatch = thisentry;
    642      1.1      cgd 		}
    643  1.9.3.1  mycroft 		if (remov != thisentry->removable)
    644      1.1      cgd 			continue;
    645  1.9.3.1  mycroft 		if (bestmatches < 2) {
    646  1.9.3.1  mycroft 			bestmatches = 2;
    647  1.9.3.1  mycroft 			bestmatch = thisentry;
    648  1.9.3.1  mycroft 		}
    649  1.9.3.1  mycroft 		if (thisentry->flags & SC_SHOWME)
    650  1.9.3.1  mycroft 			printf("\n%s-\n%s-", thisentry->manufacturer, manu);
    651  1.9.3.1  mycroft 		if (strcmp(thisentry->manufacturer, manu))
    652      1.1      cgd 			continue;
    653  1.9.3.1  mycroft 		if (bestmatches < 3) {
    654  1.9.3.1  mycroft 			bestmatches = 3;
    655  1.9.3.1  mycroft 			bestmatch = thisentry;
    656  1.9.3.1  mycroft 		}
    657  1.9.3.1  mycroft 		if (thisentry->flags & SC_SHOWME)
    658  1.9.3.1  mycroft 			printf("\n%s-\n%s-", thisentry->model, model);
    659  1.9.3.1  mycroft 		if (strcmp(thisentry->model, model))
    660      1.1      cgd 			continue;
    661  1.9.3.1  mycroft 		if (bestmatches < 4) {
    662  1.9.3.1  mycroft 			bestmatches = 4;
    663  1.9.3.1  mycroft 			bestmatch = thisentry;
    664  1.9.3.1  mycroft 		}
    665  1.9.3.1  mycroft 		if (thisentry->flags & SC_SHOWME)
    666  1.9.3.1  mycroft 			printf("\n%s-\n%s-", thisentry->version, rev);
    667  1.9.3.1  mycroft 		if (strcmp(thisentry->version, rev))
    668      1.1      cgd 			continue;
    669  1.9.3.1  mycroft 		if (bestmatches < 5) {
    670  1.9.3.1  mycroft 			bestmatches = 5;
    671  1.9.3.1  mycroft 			bestmatch = thisentry;
    672      1.1      cgd 			break;
    673      1.1      cgd 		}
    674      1.1      cgd 	}
    675  1.9.3.1  mycroft 	if (!bestmatch) {
    676  1.9.3.1  mycroft #if NUK > 0
    677  1.9.3.1  mycroft 		bestmatch = &unknowndev;
    678  1.9.3.1  mycroft #else
    679  1.9.3.1  mycroft 		printf("No explicit device driver match.\n");
    680  1.9.3.1  mycroft #endif
    681      1.1      cgd 	}
    682  1.9.3.1  mycroft 	return bestmatch;
    683      1.1      cgd }
    684