Home | History | Annotate | Line # | Download | only in scsipi
uk.c revision 1.2
      1  1.1  mycroft 
      2  1.1  mycroft /*
      3  1.1  mycroft  * Dummy driver for a device we can't identify.
      4  1.1  mycroft  * by Julian Elischer (julian (at) tfs.com)
      5  1.1  mycroft  *
      6  1.2  mycroft  *      $Id: uk.c,v 1.2 1993/12/17 08:51:13 mycroft Exp $
      7  1.1  mycroft  */
      8  1.1  mycroft 
      9  1.1  mycroft 
     10  1.1  mycroft #include <sys/types.h>
     11  1.1  mycroft #include <sys/param.h>
     12  1.1  mycroft #include <sys/errno.h>
     13  1.1  mycroft #include <sys/ioctl.h>
     14  1.2  mycroft 
     15  1.1  mycroft #include <scsi/scsi_all.h>
     16  1.1  mycroft #include <scsi/scsiconf.h>
     17  1.2  mycroft 
     18  1.1  mycroft #define NUK 16
     19  1.1  mycroft 
     20  1.1  mycroft /*
     21  1.1  mycroft  * This driver is so simple it uses all the default services
     22  1.1  mycroft  */
     23  1.1  mycroft struct scsi_device uk_switch =
     24  1.1  mycroft {
     25  1.1  mycroft     NULL,
     26  1.1  mycroft     NULL,
     27  1.1  mycroft     NULL,
     28  1.1  mycroft     NULL,
     29  1.1  mycroft     "uk",
     30  1.1  mycroft     0,
     31  1.1  mycroft     0, 0
     32  1.1  mycroft };
     33  1.1  mycroft 
     34  1.1  mycroft struct uk_data {
     35  1.1  mycroft 	u_int32 flags;
     36  1.1  mycroft 	struct scsi_link *sc_link;	/* all the inter level info */
     37  1.1  mycroft } uk_data[NUK];
     38  1.1  mycroft 
     39  1.1  mycroft #define UK_KNOWN	0x02
     40  1.1  mycroft 
     41  1.1  mycroft static u_int32 next_uk_unit = 0;
     42  1.1  mycroft 
     43  1.1  mycroft /*
     44  1.1  mycroft  * The routine called by the low level scsi routine when it discovers
     45  1.1  mycroft  * a device suitable for this driver.
     46  1.1  mycroft  */
     47  1.1  mycroft errval
     48  1.1  mycroft ukattach(sc_link)
     49  1.1  mycroft 	struct scsi_link *sc_link;
     50  1.1  mycroft {
     51  1.1  mycroft 	u_int32 unit, i, stat;
     52  1.1  mycroft 	unsigned char *tbl;
     53  1.1  mycroft 
     54  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
     55  1.1  mycroft 	/*
     56  1.1  mycroft 	 * Check we have the resources for another drive
     57  1.1  mycroft 	 */
     58  1.1  mycroft 	unit = next_uk_unit++;
     59  1.1  mycroft 	if (unit >= NUK) {
     60  1.1  mycroft 		printf("Too many unknown devices..(%d > %d) reconfigure kernel\n",
     61  1.1  mycroft 				(unit + 1), NUK);
     62  1.1  mycroft 		return (0);
     63  1.1  mycroft 	}
     64  1.1  mycroft 	/*
     65  1.1  mycroft 	 * Store information needed to contact our base driver
     66  1.1  mycroft 	 */
     67  1.1  mycroft 	uk_data[unit].sc_link = sc_link;
     68  1.1  mycroft 	sc_link->device = &uk_switch;
     69  1.1  mycroft 	sc_link->dev_unit = unit;
     70  1.1  mycroft 
     71  1.1  mycroft 	printf("uk%d: unknown device\n", unit);
     72  1.1  mycroft 	uk_data[unit].flags = UK_KNOWN;
     73  1.1  mycroft 
     74  1.1  mycroft 	return;
     75  1.1  mycroft 
     76  1.1  mycroft }
     77  1.1  mycroft 
     78  1.1  mycroft /*
     79  1.1  mycroft  *    open the device.
     80  1.1  mycroft  */
     81  1.1  mycroft errval
     82  1.1  mycroft ukopen(dev)
     83  1.1  mycroft {
     84  1.1  mycroft 	errval  errcode = 0;
     85  1.1  mycroft 	u_int32 unit, mode;
     86  1.1  mycroft 	struct scsi_link *sc_link;
     87  1.1  mycroft 	unit = minor(dev);
     88  1.1  mycroft 
     89  1.1  mycroft 	/*
     90  1.1  mycroft 	 * Check the unit is legal
     91  1.1  mycroft 	 */
     92  1.1  mycroft 	if (unit >= NUK) {
     93  1.1  mycroft 		printf("uk%d: uk %d  > %d\n", unit, unit, NUK);
     94  1.1  mycroft 		return ENXIO;
     95  1.1  mycroft 	}
     96  1.1  mycroft 
     97  1.1  mycroft 	/*
     98  1.1  mycroft 	 * Make sure the device has been initialised
     99  1.1  mycroft 	 */
    100  1.1  mycroft 	if((uk_data[unit].flags & UK_KNOWN) == 0) {
    101  1.1  mycroft 		printf("uk%d: not set up\n", unit);
    102  1.1  mycroft 		return ENXIO;
    103  1.1  mycroft 	}
    104  1.1  mycroft 
    105  1.1  mycroft 	/*
    106  1.1  mycroft 	 * Only allow one at a time
    107  1.1  mycroft 	 */
    108  1.1  mycroft 	sc_link = uk_data[unit].sc_link;
    109  1.1  mycroft 	if (sc_link->flags & SDEV_OPEN) {
    110  1.1  mycroft 		printf("uk%d: already open\n", unit);
    111  1.1  mycroft 		return ENXIO;
    112  1.1  mycroft 	}
    113  1.1  mycroft 	sc_link->flags |= SDEV_OPEN;
    114  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB1, ("ukopen: dev=0x%x (unit %d (of %d))\n"
    115  1.1  mycroft 		,dev, unit, NUK));
    116  1.1  mycroft 	/*
    117  1.1  mycroft 	 * Catch any unit attention errors.
    118  1.1  mycroft 	 */
    119  1.1  mycroft 	return 0;
    120  1.1  mycroft }
    121  1.1  mycroft 
    122  1.1  mycroft /*
    123  1.1  mycroft  * close the device.. only called if we are the LAST
    124  1.1  mycroft  * occurence of an open device
    125  1.1  mycroft  */
    126  1.1  mycroft errval
    127  1.1  mycroft ukclose(dev)
    128  1.1  mycroft {
    129  1.1  mycroft 	unsigned char unit, mode;
    130  1.1  mycroft 	struct scsi_link *sc_link;
    131  1.1  mycroft 
    132  1.1  mycroft 	sc_link = uk_data[unit].sc_link;
    133  1.1  mycroft 
    134  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB1, ("Closing device"));
    135  1.1  mycroft 	sc_link->flags &= ~SDEV_OPEN;
    136  1.1  mycroft 	return (0);
    137  1.1  mycroft }
    138  1.1  mycroft 
    139  1.1  mycroft /*
    140  1.1  mycroft  * Perform special action on behalf of the user
    141  1.1  mycroft  * Only does generic scsi ioctls.
    142  1.1  mycroft  */
    143  1.1  mycroft errval
    144  1.1  mycroft ukioctl(dev, cmd, arg, mode)
    145  1.1  mycroft 	dev_t   dev;
    146  1.1  mycroft 	u_int32 cmd;
    147  1.1  mycroft 	caddr_t arg;
    148  1.1  mycroft {
    149  1.1  mycroft 	unsigned char unit;
    150  1.1  mycroft 	struct scsi_link *sc_link;
    151  1.1  mycroft 
    152  1.1  mycroft 	/*
    153  1.1  mycroft 	 * Find the device that the user is talking about
    154  1.1  mycroft 	 */
    155  1.1  mycroft 	unit = minor(dev);
    156  1.1  mycroft 	sc_link = uk_data[unit].sc_link;
    157  1.1  mycroft 	return(scsi_do_ioctl(sc_link,cmd,arg,mode));
    158  1.1  mycroft }
    159  1.1  mycroft 
    160