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