Home | History | Annotate | Line # | Download | only in scsipi
uk.c revision 1.4
      1  1.1  mycroft /*
      2  1.1  mycroft  * Dummy driver for a device we can't identify.
      3  1.1  mycroft  * by Julian Elischer (julian (at) tfs.com)
      4  1.1  mycroft  *
      5  1.4  mycroft  *      $Id: uk.c,v 1.4 1994/02/16 02:41:10 mycroft Exp $
      6  1.1  mycroft  */
      7  1.1  mycroft 
      8  1.1  mycroft #include <sys/types.h>
      9  1.1  mycroft #include <sys/param.h>
     10  1.1  mycroft #include <sys/errno.h>
     11  1.1  mycroft #include <sys/ioctl.h>
     12  1.4  mycroft #include <sys/device.h>
     13  1.2  mycroft 
     14  1.1  mycroft #include <scsi/scsi_all.h>
     15  1.1  mycroft #include <scsi/scsiconf.h>
     16  1.2  mycroft 
     17  1.4  mycroft #define	UKUNIT(z)	(minor(z))
     18  1.4  mycroft 
     19  1.4  mycroft struct uk_data {
     20  1.4  mycroft 	struct device sc_dev;
     21  1.4  mycroft 
     22  1.4  mycroft 	u_int32 flags;
     23  1.4  mycroft #define UKINIT		0x01
     24  1.4  mycroft 	struct scsi_link *sc_link;	/* all the inter level info */
     25  1.4  mycroft };
     26  1.4  mycroft 
     27  1.4  mycroft void ukattach __P((struct device *, struct device *, void *));
     28  1.4  mycroft 
     29  1.4  mycroft struct cfdriver ukcd =
     30  1.4  mycroft { NULL, "uk", scsi_targmatch, ukattach, DV_DULL, sizeof(struct uk_data) };
     31  1.1  mycroft 
     32  1.1  mycroft /*
     33  1.1  mycroft  * This driver is so simple it uses all the default services
     34  1.1  mycroft  */
     35  1.4  mycroft struct scsi_device uk_switch = {
     36  1.3  mycroft 	NULL,
     37  1.3  mycroft 	NULL,
     38  1.3  mycroft 	NULL,
     39  1.3  mycroft 	NULL,
     40  1.3  mycroft 	"uk",
     41  1.4  mycroft 	0
     42  1.1  mycroft };
     43  1.1  mycroft 
     44  1.1  mycroft /*
     45  1.1  mycroft  * The routine called by the low level scsi routine when it discovers
     46  1.1  mycroft  * a device suitable for this driver.
     47  1.1  mycroft  */
     48  1.4  mycroft void
     49  1.4  mycroft ukattach(parent, self, aux)
     50  1.4  mycroft 	struct device *parent, *self;
     51  1.4  mycroft 	void *aux;
     52  1.1  mycroft {
     53  1.4  mycroft 	struct uk_data *uk = (struct uk_data *)self;
     54  1.4  mycroft 	struct scsi_link *sc_link = aux;
     55  1.1  mycroft 
     56  1.1  mycroft 	SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
     57  1.4  mycroft 
     58  1.1  mycroft 	/*
     59  1.1  mycroft 	 * Store information needed to contact our base driver
     60  1.1  mycroft 	 */
     61  1.4  mycroft 	uk->sc_link = sc_link;
     62  1.1  mycroft 	sc_link->device = &uk_switch;
     63  1.4  mycroft 	sc_link->dev_unit = uk->sc_dev.dv_unit;
     64  1.1  mycroft 
     65  1.4  mycroft 	printf(": unknown device\n");
     66  1.4  mycroft 	uk->flags |= UKINIT;
     67  1.1  mycroft }
     68  1.1  mycroft 
     69  1.1  mycroft /*
     70  1.4  mycroft  * open the device.
     71  1.1  mycroft  */
     72  1.4  mycroft int
     73  1.1  mycroft ukopen(dev)
     74  1.4  mycroft 	dev_t dev;
     75  1.1  mycroft {
     76  1.4  mycroft 	int unit;
     77  1.4  mycroft 	struct uk_data *uk;
     78  1.1  mycroft 	struct scsi_link *sc_link;
     79  1.1  mycroft 
     80  1.4  mycroft 	unit = UKUNIT(dev);
     81  1.4  mycroft 
     82  1.4  mycroft 	if (unit >= ukcd.cd_ndevs)
     83  1.1  mycroft 		return ENXIO;
     84  1.4  mycroft 	uk = ukcd.cd_devs[unit];
     85  1.1  mycroft 	/*
     86  1.1  mycroft 	 * Make sure the device has been initialised
     87  1.1  mycroft 	 */
     88  1.4  mycroft 	if (!uk || !(uk->cflags & UKINIT))
     89  1.1  mycroft 		return ENXIO;
     90  1.1  mycroft 
     91  1.4  mycroft 	sc_link = uk->sc_link;
     92  1.4  mycroft 
     93  1.1  mycroft 	/*
     94  1.1  mycroft 	 * Only allow one at a time
     95  1.1  mycroft 	 */
     96  1.1  mycroft 	if (sc_link->flags & SDEV_OPEN) {
     97  1.4  mycroft 		printf("%s: already open\n", uk->sc_dev.dv_xname);
     98  1.4  mycroft 		return EBUSY;
     99  1.1  mycroft 	}
    100  1.4  mycroft 
    101  1.1  mycroft 	sc_link->flags |= SDEV_OPEN;
    102  1.4  mycroft 	SC_DEBUG(sc_link, SDEV_DB1,
    103  1.4  mycroft 	    ("ukopen: dev=0x%x (unit %d (of %d))\n", unit, ukcd.cd_ndevs));
    104  1.4  mycroft 
    105  1.1  mycroft 	return 0;
    106  1.1  mycroft }
    107  1.1  mycroft 
    108  1.1  mycroft /*
    109  1.1  mycroft  * close the device.. only called if we are the LAST
    110  1.1  mycroft  * occurence of an open device
    111  1.1  mycroft  */
    112  1.4  mycroft int
    113  1.1  mycroft ukclose(dev)
    114  1.4  mycroft 	dev_t dev;
    115  1.1  mycroft {
    116  1.4  mycroft 	int unit;
    117  1.4  mycroft 	struct uk_data *uk;
    118  1.1  mycroft 
    119  1.4  mycroft 	unit = UKUNIT(dev);
    120  1.4  mycroft 	uk = ukcd.cd_devs[unit];
    121  1.4  mycroft 	uk->sc_link->flags &= ~SDEV_OPEN;
    122  1.4  mycroft 	SC_DEBUG(uk->sc_link, SDEV_DB1, ("closed\n"));
    123  1.4  mycroft 	return 0;
    124  1.1  mycroft }
    125  1.1  mycroft 
    126  1.1  mycroft /*
    127  1.1  mycroft  * Perform special action on behalf of the user
    128  1.1  mycroft  * Only does generic scsi ioctls.
    129  1.1  mycroft  */
    130  1.4  mycroft int
    131  1.4  mycroft ukioctl(dev, cmd, addr, flag)
    132  1.4  mycroft 	dev_t dev;
    133  1.4  mycroft 	int cmd;
    134  1.4  mycroft 	caddr_t addr;
    135  1.4  mycroft 	int flag;
    136  1.1  mycroft {
    137  1.4  mycroft 	int unit;
    138  1.4  mycroft 	register struct uk_data *uk;
    139  1.1  mycroft 	struct scsi_link *sc_link;
    140  1.1  mycroft 
    141  1.1  mycroft 	/*
    142  1.1  mycroft 	 * Find the device that the user is talking about
    143  1.1  mycroft 	 */
    144  1.4  mycroft 	unit = UKUNIT(dev);
    145  1.4  mycroft 	uk = ukcd.cd_devs[unit];
    146  1.4  mycroft 	return scsi_do_ioctl(uk->sc_link, cmd, addr, flag));
    147  1.1  mycroft }
    148