[BACK]Return to scsiconf.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / dev / scsipi

Annotation of src/sys/dev/scsipi/scsiconf.c, Revision 1.9.3.5

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

CVSweb <webmaster@jp.NetBSD.org>