Home | History | Annotate | Line # | Download | only in scsipi
scsipiconf.c revision 1.7
      1  1.7   mycroft /*	$NetBSD: scsipiconf.c,v 1.7 1998/08/17 00:49:02 mycroft Exp $	*/
      2  1.2    bouyer 
      3  1.7   mycroft /*-
      4  1.7   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.7   mycroft  * All rights reserved.
      6  1.7   mycroft  *
      7  1.7   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8  1.7   mycroft  * by Charles M. Hannum.
      9  1.2    bouyer  *
     10  1.2    bouyer  * Redistribution and use in source and binary forms, with or without
     11  1.2    bouyer  * modification, are permitted provided that the following conditions
     12  1.2    bouyer  * are met:
     13  1.2    bouyer  * 1. Redistributions of source code must retain the above copyright
     14  1.2    bouyer  *    notice, this list of conditions and the following disclaimer.
     15  1.2    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2    bouyer  *    notice, this list of conditions and the following disclaimer in the
     17  1.2    bouyer  *    documentation and/or other materials provided with the distribution.
     18  1.2    bouyer  * 3. All advertising materials mentioning features or use of this software
     19  1.2    bouyer  *    must display the following acknowledgement:
     20  1.7   mycroft  *        This product includes software developed by the NetBSD
     21  1.7   mycroft  *        Foundation, Inc. and its contributors.
     22  1.7   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.7   mycroft  *    contributors may be used to endorse or promote products derived
     24  1.7   mycroft  *    from this software without specific prior written permission.
     25  1.2    bouyer  *
     26  1.7   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.7   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.7   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.7   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.7   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.7   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.7   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.7   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.7   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.7   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.7   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2    bouyer  */
     38  1.2    bouyer 
     39  1.2    bouyer /*
     40  1.2    bouyer  * Originally written by Julian Elischer (julian (at) tfs.com)
     41  1.2    bouyer  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     42  1.2    bouyer  *
     43  1.2    bouyer  * TRW Financial Systems, in accordance with their agreement with Carnegie
     44  1.2    bouyer  * Mellon University, makes this software available to CMU to distribute
     45  1.2    bouyer  * or use in any manner that they see fit as long as this message is kept with
     46  1.2    bouyer  * the software. For this reason TFS also grants any other persons or
     47  1.2    bouyer  * organisations permission to use or modify this software.
     48  1.2    bouyer  *
     49  1.2    bouyer  * TFS supplies this software to be publicly redistributed
     50  1.2    bouyer  * on the understanding that TFS is not responsible for the correct
     51  1.2    bouyer  * functioning of this software in any circumstances.
     52  1.2    bouyer  *
     53  1.2    bouyer  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     54  1.2    bouyer  */
     55  1.2    bouyer 
     56  1.2    bouyer #include <sys/types.h>
     57  1.2    bouyer #include <sys/param.h>
     58  1.2    bouyer #include <sys/systm.h>
     59  1.2    bouyer #include <sys/malloc.h>
     60  1.2    bouyer #include <sys/device.h>
     61  1.2    bouyer 
     62  1.2    bouyer #include <dev/scsipi/scsipi_all.h>
     63  1.2    bouyer #include <dev/scsipi/scsi_all.h>
     64  1.2    bouyer #include <dev/scsipi/scsipiconf.h>
     65  1.2    bouyer 
     66  1.2    bouyer /*
     67  1.2    bouyer  * Return a priority based on how much of the inquiry data matches
     68  1.2    bouyer  * the patterns for the particular driver.
     69  1.2    bouyer  */
     70  1.2    bouyer caddr_t
     71  1.2    bouyer scsipi_inqmatch(inqbuf, base, nmatches, matchsize, bestpriority)
     72  1.2    bouyer 	struct scsipi_inquiry_pattern *inqbuf;
     73  1.2    bouyer 	caddr_t base;
     74  1.2    bouyer 	int nmatches, matchsize;
     75  1.2    bouyer 	int *bestpriority;
     76  1.2    bouyer {
     77  1.2    bouyer 	u_int8_t type;
     78  1.2    bouyer 	caddr_t bestmatch;
     79  1.2    bouyer 
     80  1.2    bouyer 	/* Include the qualifier to catch vendor-unique types. */
     81  1.2    bouyer 	type = inqbuf->type;
     82  1.2    bouyer 
     83  1.2    bouyer 	for (*bestpriority = 0, bestmatch = 0; nmatches--; base += matchsize) {
     84  1.2    bouyer 		struct scsipi_inquiry_pattern *match = (void *)base;
     85  1.2    bouyer 		int priority, len;
     86  1.2    bouyer 
     87  1.2    bouyer 		if (type != match->type)
     88  1.2    bouyer 			continue;
     89  1.2    bouyer 		if (inqbuf->removable != match->removable)
     90  1.2    bouyer 			continue;
     91  1.2    bouyer 		priority = 2;
     92  1.2    bouyer 		len = strlen(match->vendor);
     93  1.2    bouyer 		if (bcmp(inqbuf->vendor, match->vendor, len))
     94  1.2    bouyer 			continue;
     95  1.2    bouyer 		priority += len;
     96  1.2    bouyer 		len = strlen(match->product);
     97  1.2    bouyer 		if (bcmp(inqbuf->product, match->product, len))
     98  1.2    bouyer 			continue;
     99  1.2    bouyer 		priority += len;
    100  1.2    bouyer 		len = strlen(match->revision);
    101  1.2    bouyer 		if (bcmp(inqbuf->revision, match->revision, len))
    102  1.2    bouyer 			continue;
    103  1.2    bouyer 		priority += len;
    104  1.2    bouyer 
    105  1.2    bouyer #ifdef SCSIDEBUG
    106  1.2    bouyer 		printf("scsipi_inqmatch: %d/%d/%d <%s, %s, %s>\n",
    107  1.2    bouyer 		    priority, match->type, match->removable,
    108  1.2    bouyer 		    match->vendor, match->product, match->revision);
    109  1.2    bouyer #endif
    110  1.2    bouyer 		if (priority > *bestpriority) {
    111  1.2    bouyer 			*bestpriority = priority;
    112  1.2    bouyer 			bestmatch = base;
    113  1.2    bouyer 		}
    114  1.2    bouyer 	}
    115  1.2    bouyer 
    116  1.2    bouyer 	return (bestmatch);
    117  1.2    bouyer }
    118  1.2    bouyer 
    119  1.2    bouyer char *
    120  1.2    bouyer scsipi_dtype(type)
    121  1.2    bouyer 	int type;
    122  1.2    bouyer {
    123  1.2    bouyer 	char *dtype;
    124  1.3     enami 
    125  1.2    bouyer 	switch (type) {
    126  1.2    bouyer 	case T_DIRECT:
    127  1.2    bouyer 		dtype = "direct";
    128  1.4   thorpej 		break;
    129  1.2    bouyer 	case T_SEQUENTIAL:
    130  1.2    bouyer 		dtype = "sequential";
    131  1.2    bouyer 		break;
    132  1.2    bouyer 	case T_PRINTER:
    133  1.2    bouyer 		dtype = "printer";
    134  1.2    bouyer 		break;
    135  1.2    bouyer 	case T_PROCESSOR:
    136  1.2    bouyer 		dtype = "processor";
    137  1.2    bouyer 		break;
    138  1.4   thorpej 	case T_WORM:
    139  1.4   thorpej 		dtype = "worm";
    140  1.4   thorpej 		break;
    141  1.2    bouyer 	case T_CDROM:
    142  1.2    bouyer 		dtype = "cdrom";
    143  1.2    bouyer 		break;
    144  1.2    bouyer 	case T_SCANNER:
    145  1.2    bouyer 		dtype = "scanner";
    146  1.2    bouyer 		break;
    147  1.2    bouyer 	case T_OPTICAL:
    148  1.2    bouyer 		dtype = "optical";
    149  1.2    bouyer 		break;
    150  1.2    bouyer 	case T_CHANGER:
    151  1.2    bouyer 		dtype = "changer";
    152  1.2    bouyer 		break;
    153  1.2    bouyer 	case T_COMM:
    154  1.2    bouyer 		dtype = "communication";
    155  1.4   thorpej 		break;
    156  1.4   thorpej 	case T_IT8_1:
    157  1.4   thorpej 	case T_IT8_2:
    158  1.4   thorpej 		dtype = "it8";		/* ??? */
    159  1.4   thorpej 		break;
    160  1.4   thorpej 	case T_STORARRAY:
    161  1.4   thorpej 		dtype = "storage array";
    162  1.4   thorpej 		break;
    163  1.4   thorpej 	case T_ENCLOSURE:
    164  1.4   thorpej 		dtype = "enclosure services";
    165  1.2    bouyer 		break;
    166  1.2    bouyer 	case T_NODEVICE:
    167  1.2    bouyer 		panic("scsipi_dtype: impossible device type");
    168  1.2    bouyer 	default:
    169  1.2    bouyer 		dtype = "unknown";
    170  1.2    bouyer 		break;
    171  1.2    bouyer 	}
    172  1.3     enami 	return (dtype);
    173  1.2    bouyer }
    174  1.2    bouyer 
    175  1.2    bouyer void
    176  1.5  drochner scsipi_strvis(dst, dlen, src, slen)
    177  1.2    bouyer 	u_char *dst, *src;
    178  1.5  drochner 	int dlen, slen;
    179  1.2    bouyer {
    180  1.2    bouyer 
    181  1.2    bouyer 	/* Trim leading and trailing blanks and NULs. */
    182  1.5  drochner 	while (slen > 0 && (src[0] == ' ' || src[0] == '\0'))
    183  1.5  drochner 		++src, --slen;
    184  1.5  drochner 	while (slen > 0 && (src[slen-1] == ' ' || src[slen-1] == '\0'))
    185  1.5  drochner 		--slen;
    186  1.2    bouyer 
    187  1.5  drochner 	while (slen > 0) {
    188  1.2    bouyer 		if (*src < 0x20 || *src >= 0x80) {
    189  1.2    bouyer 			/* non-printable characters */
    190  1.5  drochner 			dlen -= 4;
    191  1.5  drochner 			if (dlen < 1)
    192  1.5  drochner 				break;
    193  1.2    bouyer 			*dst++ = '\\';
    194  1.2    bouyer 			*dst++ = ((*src & 0300) >> 6) + '0';
    195  1.2    bouyer 			*dst++ = ((*src & 0070) >> 3) + '0';
    196  1.2    bouyer 			*dst++ = ((*src & 0007) >> 0) + '0';
    197  1.2    bouyer 		} else if (*src == '\\') {
    198  1.2    bouyer 			/* quote characters */
    199  1.5  drochner 			dlen -= 2;
    200  1.5  drochner 			if (dlen < 1)
    201  1.5  drochner 				break;
    202  1.2    bouyer 			*dst++ = '\\';
    203  1.2    bouyer 			*dst++ = '\\';
    204  1.2    bouyer 		} else {
    205  1.2    bouyer 			/* normal characters */
    206  1.5  drochner 			if (--dlen < 1)
    207  1.5  drochner 				break;
    208  1.2    bouyer 			*dst++ = *src;
    209  1.2    bouyer 		}
    210  1.5  drochner 		++src, --slen;
    211  1.2    bouyer 	}
    212  1.2    bouyer 
    213  1.2    bouyer 	*dst++ = 0;
    214  1.2    bouyer }
    215