diff options
author | dufault <dufault@FreeBSD.org> | 1995-05-03 18:09:20 +0000 |
---|---|---|
committer | dufault <dufault@FreeBSD.org> | 1995-05-03 18:09:20 +0000 |
commit | 9d5087634af5b60fb1b35e627b1e09dd5c178413 (patch) | |
tree | 1681cda3a482fda605182f6fe8d420efbc5839e6 /sys/scsi | |
parent | da1f0a96f4ab656828dada409b64a653945a70cb (diff) | |
download | FreeBSD-src-9d5087634af5b60fb1b35e627b1e09dd5c178413.zip FreeBSD-src-9d5087634af5b60fb1b35e627b1e09dd5c178413.tar.gz |
Moved unit definitions out of scsiconf.h;
Added CONTROL device that only does user-ioctl and nothing else;
Added protection so user-ioctl requires write access;
Clean up scsiconf.h a little. It needs more work.
Diffstat (limited to 'sys/scsi')
-rw-r--r-- | sys/scsi/cd.c | 7 | ||||
-rw-r--r-- | sys/scsi/ch.c | 5 | ||||
-rw-r--r-- | sys/scsi/pt.c | 4 | ||||
-rw-r--r-- | sys/scsi/scsi_driver.c | 82 | ||||
-rw-r--r-- | sys/scsi/scsi_ioctl.c | 16 | ||||
-rw-r--r-- | sys/scsi/scsiconf.c | 68 | ||||
-rw-r--r-- | sys/scsi/scsiconf.h | 183 | ||||
-rw-r--r-- | sys/scsi/sctarg.c | 4 | ||||
-rw-r--r-- | sys/scsi/sd.c | 4 | ||||
-rw-r--r-- | sys/scsi/ssc.c | 7 | ||||
-rw-r--r-- | sys/scsi/st.c | 7 | ||||
-rw-r--r-- | sys/scsi/su.c | 15 |
12 files changed, 188 insertions, 214 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index e1721a8..cb6b010 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -14,7 +14,7 @@ * * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 * - * $Id: cd.c,v 1.38 1995/04/14 15:10:24 dufault Exp $ + * $Id: cd.c,v 1.39 1995/04/23 22:07:48 gibbs Exp $ */ #define SPLCD splbio @@ -58,6 +58,9 @@ static errval cd_getdisklabel __P((u_int8)); int32 cdstrats, cdqueues; +#define CDUNIT(DEV) ((minor(DEV)&0xF8) >> 3) /* 5 bit unit */ +#define CDSETUNIT(DEV, U) makedev(major(DEV), ((U) << 3)) + #define PAGESIZ 4096 #define SECSIZE 2048 /* XXX */ /* default only */ #define CDOUTSTANDING 2 @@ -872,7 +875,7 @@ struct scsi_link *sc_link) return (cd_reset(unit)); break; default: - if(part == RAW_PART || SCSI_SUPER(dev)) + if(part == RAW_PART) error = scsi_do_ioctl(dev, cmd, addr, flag, p, sc_link); else error = ENOTTY; diff --git a/sys/scsi/ch.c b/sys/scsi/ch.c index ae71850..4806ed2 100644 --- a/sys/scsi/ch.c +++ b/sys/scsi/ch.c @@ -2,7 +2,7 @@ * Written by grefen@????? * Based on scsi drivers by Julian Elischer (julian@tfs.com) * - * $Id: ch.c,v 1.17 1995/03/28 07:57:22 bde Exp $ + * $Id: ch.c,v 1.18 1995/04/14 15:10:26 dufault Exp $ */ #include <sys/types.h> @@ -34,6 +34,9 @@ errval ch_position __P((u_int32 unit, short *stat, u_int32 chm, u_int32 to, #define CHRETRIES 2 +#define CHUNIT(DEV) ((minor(DEV)&0xF0) >> 4) /* 4 bit unit. */ +#define CHSETUNIT(DEV, U) makedev(major(DEV), ((U) << 4)) + #define MODE(z) ( (minor(z) & 0x0F) ) #define ESUCCESS 0 diff --git a/sys/scsi/pt.c b/sys/scsi/pt.c index 2d23d28..3194cd8 100644 --- a/sys/scsi/pt.c +++ b/sys/scsi/pt.c @@ -37,7 +37,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: pt.c,v 1.2 1995/04/14 15:10:28 dufault Exp $ + * $Id: pt.c,v 1.3 1995/04/23 22:07:49 gibbs Exp $ */ /* @@ -178,7 +178,7 @@ pt_strategy(struct buf *bp, struct scsi_link *sc_link) u_int32 opri; struct scsi_data *pt; - unit = STUNIT((bp->b_dev)); + unit = minor((bp->b_dev)); pt = sc_link->sd; opri = splbio(); diff --git a/sys/scsi/scsi_driver.c b/sys/scsi/scsi_driver.c index e44c081..40b8559 100644 --- a/sys/scsi/scsi_driver.c +++ b/sys/scsi/scsi_driver.c @@ -35,7 +35,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: scsi_driver.c,v 1.7 1995/03/21 11:21:02 dufault Exp $ + * $Id: scsi_driver.c,v 1.8 1995/04/14 15:10:33 dufault Exp $ * */ #include <sys/types.h> @@ -45,6 +45,7 @@ #include <sys/buf.h> #include <sys/devconf.h> #include <sys/malloc.h> +#include <sys/fcntl.h> #include <machine/cpu.h> /* XXX For bootverbose (funny place) */ @@ -75,9 +76,8 @@ int scsi_device_attach(struct scsi_link *sc_link) dev_t dev; struct scsi_device *device = sc_link->device; - if (bootverbose) { + if (bootverbose) sc_link->flags |= SDEV_BOOTVERBOSE; - } SC_DEBUG(sc_link, SDEV_DB2, ("%s%dattach: ", device->name, sc_link->dev_unit)); @@ -122,20 +122,20 @@ struct scsi_device *device) if (sc_link == 0 || sc_link->sd == 0) return ENXIO; - errcode = (device->dev_open) ? - (*device->dev_open)(dev, flags, fmt, p, sc_link) : 0; + /* If it is a "once only" device that is already open return EBUSY. + */ + if ((sc_link->flags & SDEV_ONCE_ONLY) && (sc_link->flags & SDEV_IS_OPEN)) + return EBUSY; - if (errcode == 0 && (sc_link->flags & SDEV_ONCE_ONLY)) { - /* - * Only allow one at a time - */ - if (sc_link->flags & SDEV_OPEN) { - errcode = EBUSY; - } - else { - sc_link->flags |= SDEV_OPEN; - } - } + /* For the control device (user ioctl's only) don't call the open + * entry. + */ + if (SCSI_CONTROL(dev) || (device->dev_open == 0)) + errcode = 0; + else + errcode = (*device->dev_open)(dev, flags, fmt, p, sc_link); + + sc_link->flags |= SDEV_IS_OPEN; SC_DEBUG(sc_link, SDEV_DB1, ("%sopen: dev=0x%lx (unit %ld) result %d\n", device->name, dev, unit, errcode)); @@ -143,38 +143,36 @@ struct scsi_device *device) return errcode; } -/* - * close the device.. only called if we are the LAST - * occurence of an open device - */ int scsi_close(dev_t dev, int flags, int fmt, struct proc *p, struct scsi_device *device) { errval errcode; - struct scsi_link *scsi_link = SCSI_LINK(device, GETUNIT(device, dev)); + struct scsi_link *sc_link = SCSI_LINK(device, GETUNIT(device, dev)); - SC_DEBUG(scsi_link, SDEV_DB1, ("%sclose: Closing device\n", device->name)); + SC_DEBUG(sc_link, SDEV_DB1, ("%sclose: Closing device\n", device->name)); - errcode = (device->dev_close) ? - (*device->dev_close)(dev, flags, fmt, p, scsi_link) : 0; + if (SCSI_CONTROL(dev) || (device->dev_close == 0)) + errcode = 0; + else + errcode = (*device->dev_close)(dev, flags, fmt, p, sc_link); - if (scsi_link->flags & SDEV_ONCE_ONLY) - scsi_link->flags &= ~SDEV_OPEN; + sc_link->flags &= ~SDEV_IS_OPEN; return errcode; } int -scsi_ioctl(dev_t dev, u_int32 cmd, caddr_t arg, int mode, struct proc *p, +scsi_ioctl(dev_t dev, u_int32 cmd, caddr_t arg, int flags, struct proc *p, struct scsi_device *device) { errval errcode; - struct scsi_link *scsi_link = SCSI_LINK(device, GETUNIT(device, dev)); + struct scsi_link *sc_link = SCSI_LINK(device, GETUNIT(device, dev)); - errcode = (device->dev_ioctl) ? - (*device->dev_ioctl)(dev, cmd, arg, mode, p, scsi_link) - : scsi_do_ioctl(dev, cmd, arg, mode, p, scsi_link); + if (SCSI_CONTROL(dev) || (device->dev_ioctl == 0)) + errcode = scsi_do_ioctl(dev, cmd, arg, flags, p, sc_link); + else + errcode = (*device->dev_ioctl)(dev, cmd, arg, flags, p, sc_link); return errcode; } @@ -196,16 +194,24 @@ scsi_strategy(struct buf *bp, struct scsi_device *device) SC_DEBUG(sc_link, SDEV_DB1, ("%ld bytes @ blk%ld\n", bp->b_bcount, bp->b_blkno)); - bp->b_resid = 0; - bp->b_error = 0; - - if (bp->b_bcount == 0) + if (SCSI_CONTROL(bp->b_dev) || (device->dev_strategy == 0)) { + bp->b_resid = bp->b_bcount; + bp->b_error = EIO; + bp->b_flags |= B_ERROR; biodone(bp); } - else if (device->dev_strategy) + else { - (*sc_link->adapter->scsi_minphys)(bp); - (*device->dev_strategy)(bp, sc_link); + bp->b_resid = 0; + bp->b_error = 0; + + if (bp->b_bcount == 0) + biodone(bp); + else + { + (*sc_link->adapter->scsi_minphys)(bp); + (*device->dev_strategy)(bp, sc_link); + } } } diff --git a/sys/scsi/scsi_ioctl.c b/sys/scsi/scsi_ioctl.c index c34fe59..06d89cc 100644 --- a/sys/scsi/scsi_ioctl.c +++ b/sys/scsi/scsi_ioctl.c @@ -1,6 +1,4 @@ /* - *Begin copyright - * * Copyright (C) 1992, 1993, 1994, HD Associates, Inc. * PO Box 276 * Pepperell, MA 01463 @@ -38,7 +36,7 @@ * SUCH DAMAGE. *End copyright * - * $Id: scsi_ioctl.c,v 1.12 1995/03/04 20:50:55 dufault Exp $ + * $Id: scsi_ioctl.c,v 1.13 1995/04/14 15:10:35 dufault Exp $ * * */ @@ -47,8 +45,11 @@ #include <sys/errno.h> #include <sys/malloc.h> #include <sys/buf.h> + #define b_screq b_driver1 /* a patch in buf.h */ #define b_sc_link b_driver2 /* a patch in buf.h */ + +#include <sys/fcntl.h> #include <sys/proc.h> #include <vm/vm.h> @@ -245,11 +246,17 @@ void scsiminphys(struct buf *bp) * If user-level type command, we must still be running * in the context of the calling process */ -errval scsi_do_ioctl(dev_t dev, int cmd, caddr_t addr, int f, +errval scsi_do_ioctl(dev_t dev, int cmd, caddr_t addr, int flags, struct proc *p, struct scsi_link *sc_link) { errval ret = 0; + /* If we can't write the device we can't permit much: + */ + + if (cmd != SCIOCIDENTIFY && !(flags & FWRITE)) + return EACCES; + SC_DEBUG(sc_link,SDEV_DB2,("scsi_do_ioctl(0x%x)\n",cmd)); switch(cmd) { @@ -345,6 +352,7 @@ struct proc *p, struct scsi_link *sc_link) case SCIOCDECONFIG: ret = EINVAL; break; + case SCIOCIDENTIFY: { struct scsi_addr *sca = (struct scsi_addr *) addr; diff --git a/sys/scsi/scsiconf.c b/sys/scsi/scsiconf.c index c1050e2..d551ccb 100644 --- a/sys/scsi/scsiconf.c +++ b/sys/scsi/scsiconf.c @@ -16,7 +16,7 @@ * * New configuration setup: dufault@hda.com * - * $Id: scsiconf.c,v 1.27 1995/04/14 15:10:37 dufault Exp $ + * $Id: scsiconf.c,v 1.28 1995/04/23 07:47:10 bde Exp $ */ #include <sys/types.h> @@ -70,13 +70,20 @@ static void *extend_alloc(size_t s) static void extend_free(void *p) { free(p, M_DEVBUF); } -#define EXTEND_CHUNK 8 +/* EXTEND_CHUNK: Number of extend slots to allocate whenever we need a new + * one. + */ +#ifndef EXTEND_CHUNK + #define EXTEND_CHUNK 8 +#endif struct extend_array *extend_new(void) { struct extend_array *p = extend_alloc(sizeof(*p)); - p->nelem = 0; - p->ps = 0; + if (p) { + p->nelem = 0; + p->ps = 0; + } return p; } @@ -126,7 +133,7 @@ void extend_release(struct extend_array *ea, int index) * This extend_array holds an array of "scsibus_data" pointers. * One of these is allocated and filled in for each scsi bus. * it holds pointers to allow the scsi bus to get to the driver - * That is running each LUN on the bus + * that is running each LUN on the bus * it also has a template entry which is the prototype struct * supplied by the adapter driver, this is used to initialise * the others, before they have the rest of the fields filled in @@ -588,8 +595,8 @@ void scsi_configure_finish(void) } /* - * The routine called by the adapter boards to get all their - * devices configured in. + * scsi_attachdevs is the routine called by the adapter boards + * to get all their devices configured in. */ void scsi_attachdevs(sc_link_proto) @@ -971,7 +978,8 @@ scsi_probedev(sc_link, maybe_more, type_p) u_int8 target = sc_link->target; u_int8 lu = sc_link->lun; struct scsidevs *bestmatch = (struct scsidevs *) 0; - char *dtype = (char *) 0, *desc; + int dtype = 0; + char *desc; char *qtype; struct scsi_inquiry_data *inqbuf; u_int32 len, qualifier, type; @@ -1053,7 +1061,7 @@ scsi_probedev(sc_link, maybe_more, type_p) return (struct scsidevs *) 0; default: - dtype = ""; + dtype = 1; qtype = "Vendor specific peripheral qualifier"; *maybe_more = 1; break; @@ -1064,7 +1072,7 @@ scsi_probedev(sc_link, maybe_more, type_p) *maybe_more = 1; return (struct scsidevs *) 0; } - dtype = scsi_type_long_name(type); + dtype = 1; } /* * Then if it's advanced enough, more detailed @@ -1288,43 +1296,3 @@ scsi_externalize(struct scsi_link *sl, void *userp, size_t *lenp) return copyout(sl, userp, sizeof *sl); } - -/* XXX dufault@hda.com: - * having this table of names conflicts with our decision - * that all type information be contained in a type driver. - */ -static struct {char *name; char *long_name; } types[] = { - { "sd", "direct" }, - { "st", "sequential" }, - { "prn", "printer" }, - { "proc", "processor" }, - { "worm", "worm" }, - { "cd", "readonly" }, - { "scan", "scanner" }, - { "opmem", "optical" }, - { "ch", "changer" }, - { "comm", "communication" }, - { "asc0", "ASC-0" }, - { "asc1", "ASC-1" }, - { "uk", "unknown" }, - { "inval", "invalid" }, -}; - -char * -scsi_type_name(int type) -{ - if (type >= 0 && type < (sizeof(types) / sizeof(types[0]))) - return types[type].name; - - return "inval"; -} - -char * -scsi_type_long_name(int type) -{ - if (type >= 0 && type < (sizeof(types) / sizeof(types[0]))) - return types[type].long_name; - - return "invalid"; -} - diff --git a/sys/scsi/scsiconf.h b/sys/scsi/scsiconf.h index 3899983..1a9765e 100644 --- a/sys/scsi/scsiconf.h +++ b/sys/scsi/scsiconf.h @@ -14,7 +14,7 @@ * * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 * - * $Id: scsiconf.h,v 1.23 1995/04/23 07:47:12 bde Exp $ + * $Id: scsiconf.h,v 1.24 1995/04/23 22:07:51 gibbs Exp $ */ #ifndef SCSI_SCSICONF_H #define SCSI_SCSICONF_H 1 @@ -31,46 +31,6 @@ typedef unsigned char u_int8; #include <scsi/scsi_all.h> #include <scsi/scsi_driver.h> -/* Minor number fields: - * - * NON-FIXED SCSI devices: - * - * ???? ???? ???? ???N MMMMMMMM mmmmmmmm - * - * ?: Don't know; those bits didn't use to exist, currently always 0. - * N: New style device: must be zero. - * M: Major device number. - * m: old style minor device number. - * - * FIXED SCSI devices: - * - * ???? SBBB LLLI IIIN MMMMMMMM mmmmmmmm - * - * ?: Not used yet. - * S: "Super" device; reserved for things like resetting the SCSI bus. - * B: Scsi bus - * L: Logical unit - * I: Scsi target (XXX: Why 16? Why that many in scsiconf.h?) - * N: New style device; must be one. - * M: Major device number - * m: Old style minor device number. - */ - -#define SCSI_SUPER(DEV) (((DEV) & 0x08000000) >> 27) -#define SCSI_MKSUPER(DEV) ((DEV) | 0x08000000) - -#define SCSI_BUS(DEV) (((DEV) & 0x07000000) >> 24) -#define SCSI_LUN(DEV) (((DEV) & 0x00E00000) >> 21) -#define SCSI_ID(DEV) (((DEV) & 0x001E0000) >> 17) -#define SCSI_FIXED(DEV) (((DEV) & 0x00010000) >> 16) - - -#define SCSI_MKDEV(B, L, I) ( \ - ((B) << 24) | \ - ((L) << 21) | \ - ((I) << 17) | \ - ( 1 << 16) ) - /* * The following documentation tries to describe the relationship between the * various structures defined in this file: @@ -143,11 +103,11 @@ struct scsi_adapter * driver has its own definition for it. */ struct scsi_data; - struct scsi_link; /* scsi_link refers to scsi_device and vice-versa */ struct scsi_xfer; struct proc; +struct buf; /* * These entry points are called by the low-end drivers to get services from @@ -162,21 +122,21 @@ struct proc; struct scsi_device { -/* 4*/ errval (*err_handler)(struct scsi_xfer *xs); /* return -1 to say - * err processing complete */ -/* 8*/ void (*start)(u_int32 unit, u_int32 flags); +/* 4*/ errval (*err_handler)(struct scsi_xfer *xs); /* return -1 to say + * err processing complete */ +/* 8*/ void (*start)(u_int32 unit, u_int32 flags); /* 12*/ int32 (*async)(); /* 16*/ int32 (*done)(); /* returns -1 to say done processing complete */ /* 20*/ char *name; /* name of device type */ /* 24*/ u_int32 flags; /* device type dependent flags */ /* 32*/ int32 spare[2]; -/* 36*/ int32 link_flags; /* Flags OR'd into sc_link at attach time */ +/* 36*/ int32 link_flags; /* Flags OR'd into sc_link at attach time */ /* 40*/ errval (*attach)(struct scsi_link *sc_link); /* 44*/ char *desc; /* Description of device */ /* 48*/ int (*open)(dev_t dev, int flags, int fmt, struct proc *p); /* 52*/ int sizeof_scsi_data; -/* 56*/ int type; /* Type of device this supports */ +/* 56*/ int type; /* Type of device this supports */ /* 60*/ int (*getunit)(dev_t dev); /* 64*/ dev_t (*setunit)(dev_t dev, int unit); @@ -209,32 +169,26 @@ struct scsi_device /* SCSI_DEVICE_ENTRIES: A macro to generate all the entry points from the * name. */ -#define SCSI_DEVICE_ENTRIES(NAME) \ -errval NAME##attach(struct scsi_link *sc_link); \ -extern struct scsi_device NAME##_switch; \ -void NAME##init(void) \ -{ \ - scsi_device_register(&NAME##_switch); \ -} \ -int NAME##open(dev_t dev, int flags, int fmt, struct proc *p) \ -{ \ - return scsi_open(dev, flags, fmt, p, &NAME##_switch); \ -} \ -int NAME##ioctl(dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p) \ -{ \ - return scsi_ioctl(dev, cmd, addr, flag, p, &NAME##_switch); \ -} \ -int NAME##close(dev_t dev, int flag, int fmt, struct proc *p) \ -{ \ - return scsi_close(dev, flag, fmt, p, &NAME##_switch); \ -} \ -void NAME##minphys(struct buf *bp) \ -{ \ - scsi_minphys(bp, &NAME##_switch); \ +#define SCSI_DEVICE_ENTRIES(NAME) \ +errval NAME##attach(struct scsi_link *sc_link); \ +extern struct scsi_device NAME##_switch; \ +void NAME##init(void) { \ + scsi_device_register(&NAME##_switch); \ +} \ +int NAME##open(dev_t dev, int flags, int fmt, struct proc *p) { \ + return scsi_open(dev, flags, fmt, p, &NAME##_switch); \ +} \ +int NAME##ioctl(dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p) { \ + return scsi_ioctl(dev, cmd, addr, flag, p, &NAME##_switch); \ } \ -void NAME##strategy(struct buf *bp) \ -{ \ - scsi_strategy(bp, &NAME##_switch); \ +int NAME##close(dev_t dev, int flag, int fmt, struct proc *p) { \ + return scsi_close(dev, flag, fmt, p, &NAME##_switch); \ +} \ +void NAME##minphys(struct buf *bp) { \ + scsi_minphys(bp, &NAME##_switch); \ +} \ +void NAME##strategy(struct buf *bp) { \ + scsi_strategy(bp, &NAME##_switch); \ } #ifdef KERNEL @@ -348,6 +302,11 @@ struct scsi_link * adapter driver. * XXX-HA And I added the "supports residuals properly" flag that ALSO goes * in an adapter structure. I figure I'll fix both at once. + * + * XXX SDEV_OPEN is used for two things: To prevent more than one + * open and to make unit attentions errors be logged on the console. + * These should be split up; I'm adding SDEV_IS_OPEN to enforce one + * open only. */ #define SDEV_MEDIA_LOADED 0x0001 /* device figures are still valid */ @@ -359,6 +318,7 @@ struct scsi_link #define SDEV_BOOTVERBOSE 0x0200 /* be noisy during boot */ #define SDEV_RESIDS_WORK 0x0400 /* XXX-HA: Residuals work */ #define SDEV_TARGET_OPS 0x0800 /* XXX-HA: Supports target ops */ +#define SDEV_IS_OPEN 0x1000 /* at least 1 open session */ /* * One of these is allocated and filled in for each scsi bus. @@ -448,8 +408,6 @@ struct scsi_xfer #ifdef KERNEL void *extend_get(struct extend_array *ea, int index); -char * scsi_type_long_name(int type); -char * scsi_type_name(int type); void scsi_attachdevs __P((struct scsi_link *sc_link_proto)); struct scsi_xfer *get_xs( struct scsi_link *sc_link, u_int32 flags); void free_xs(struct scsi_xfer *xs, struct scsi_link *sc_link,u_int32 flags); @@ -516,6 +474,10 @@ void scsi_configure_finish __P((void)); #define SCSI_EXTERNALLEN (sizeof(struct scsi_link)) #ifdef NEW_SCSICONF + +/* XXX This belongs in a tape file. + */ + /********************************************************************** from the scsi2 spec Value Tracks Density(bpi) Code Type Reference Note @@ -578,43 +540,52 @@ void scsi_configure_finish __P((void)); #define DAT_1 0x13 #endif /* NEW_SCSICONF */ -/* Macros for getting and setting the unit numbers in the original - * (not fixed device name) device numbers. +/* XXX (dufault@hda.com) This is used only by "su" and "sctarg". + * The minor number field conflicts with the disk slice code, + * and so it is tough to access the disks through the "su" device. */ -#define SH0_UNIT(DEV) (minor(DEV)&0xFF) /* 8 bit unit */ -#define SH0SETUNIT(DEV, U) makedev(major(DEV), (U)) - -#define SH3_UNIT(DEV) ((minor(DEV)&0xF8) >> 3) /* 5 bit unit */ -#define SH3SETUNIT(DEV, U) makedev(major(DEV), ((U) << 3)) - -#define SH4_UNIT(DEV) ((minor(DEV)&0xF0) >> 4) /* 4 bit unit. */ -#define SH4SETUNIT(DEV, U) makedev(major(DEV), ((U) << 4)) - -#define CDUNITSHIFT 3 -#define CDUNIT(DEV) SH3_UNIT(DEV) -#define CDSETUNIT(DEV, U) SH3SETUNIT((DEV), (U)) - -#define CHUNIT(DEV) SH4_UNIT(DEV) -#define CHSETUNIT(DEV, U) SH4SETUNIT((DEV), (U)) - -#define STUNIT(DEV) SH4_UNIT(DEV) -#define STSETUNIT(DEV, U) SH4SETUNIT((DEV), (U)) -#define UKUNIT(DEV) SH0_UNIT(DEV) -#define UKSETUNIT(DEV, U) SH0SETUNIT((DEV), (U)) - -/* Build an old style device number (unit encoded in the minor number) - * from a base old one (no flag bits) and a full new one - * (BUS, LUN, TARG in the minor number, and flag bits). +/* Device number fields: + * + * NON-FIXED SCSI devices: + * + * ?FC? ???? ???? ???? MMMMMMMM mmmmmmmm + * + * F: Fixed device (nexus in number): must be 0. + * C: Control device; only user mode ioctl is supported. + * ?: Don't know; those bits didn't use to exist, currently always 0. + * M: Major device number. + * m: Old style minor device number. + * + * FIXED SCSI devices: * - * OLDDEV has the major number and device unit only. It was constructed - * at attach time and is stored in the scsi_link structure. + * XXX Conflicts with the slice code. Maybe the slice code can be + * changed to respect the F bit? * - * NEWDEV can have whatever in it, but only the old control flags and the - * super bit are present. IT CAN'T HAVE ANY UNIT INFORMATION or you'll - * wind up with the wrong unit. + * ?FC? ?BBB TTTT ?LLL MMMMMMMM mmmmmmmm + * + * F: Fixed device (nexus in number); must be 1. + * C: Control device; only user mode ioctl is supported. + * B: SCSI bus + * T: SCSI target ID + * L: Logical unit + * M: Major device number + * m: Old style minor device number. */ -#define OLD_DEV(NEWDEV, OLDDEV) ((OLDDEV) | ((NEWDEV) & 0x080000FF)) + +#define SCSI_FIXED(DEV) (((DEV) & SCSI_FIXED_MASK)) +#define SCSI_FIXED_MASK 0x40000000 +#define SCSI_CONTROL(DEV) (((DEV) & 0x20000000)) + +#define SCSI_BUS(DEV) (((DEV) & 0x07000000) >> 24) +#define SCSI_ID(DEV) (((DEV) & 0x00F00000) >> 20) +#define SCSI_LUN(DEV) (((DEV) & 0x00070000) >> 16) + +#define SCSI_MKFIXED(B, T, L) ( \ + ((B) << 24) | \ + ((T) << 20) | \ + ((L) << 16) | \ + SCSI_FIXED_MASK ) #endif /*SCSI_SCSICONF_H*/ /* END OF FILE */ diff --git a/sys/scsi/sctarg.c b/sys/scsi/sctarg.c index 9824f9b..d7513db 100644 --- a/sys/scsi/sctarg.c +++ b/sys/scsi/sctarg.c @@ -37,7 +37,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: sctarg.c,v 1.1 1995/03/04 20:50:46 dufault Exp $ + * $Id: sctarg.c,v 1.1 1995/04/14 15:10:41 dufault Exp $ */ /* @@ -236,7 +236,7 @@ sctarg_strategy(struct buf *bp, struct scsi_link *sc_link) u_int32 opri; struct scsi_data *sctarg; - unit = STUNIT((bp->b_dev)); + unit = minor((bp->b_dev)); sctarg = sc_link->sd; opri = splbio(); diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index 338c48b..b66381a 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -14,7 +14,7 @@ * * Ported to run under 386BSD by Julian Elischer (julian@dialix.oz.au) Sept 1992 * - * $Id: sd.c,v 1.61 1995/04/29 17:52:44 dufault Exp $ + * $Id: sd.c,v 1.62 1995/04/30 15:14:34 bde Exp $ */ #define SPLSD splbio @@ -579,7 +579,7 @@ sd_ioctl(dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p, sdstrategy1, (ds_setgeom_t *)NULL); if (error != -1) return (error); - if (PARTITION(dev) != RAW_PART && !SCSI_SUPER(dev)) + if (PARTITION(dev) != RAW_PART) return (ENOTTY); return (scsi_do_ioctl(dev, cmd, addr, flag, p, sc_link)); } diff --git a/sys/scsi/ssc.c b/sys/scsi/ssc.c index 270ba8a..df7fbb6 100644 --- a/sys/scsi/ssc.c +++ b/sys/scsi/ssc.c @@ -1,4 +1,4 @@ -/* "superscsi" pseudo device. This requires options SCSISUPER. +/* "superscsi" pseudo device. * "superscsi" supports general SCSI utilities that can iterate * over all SCSI targets, including those without device entry * points. @@ -49,7 +49,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *End copyright - * $Id:$ + * $Id: ssc.c,v 1.2 1995/01/08 15:56:09 dufault Exp $ */ #include <sys/types.h> @@ -85,8 +85,7 @@ int sscioctl(dev_t dev, int cmd, caddr_t data, int fflag, struct proc *p) if (cmd == SCIOCADDR) { struct scsi_addr *sca = (struct scsi_addr *) data; - dev_t newdev = - SCSI_MKSUPER(SCSI_MKDEV(sca->scbus,sca->lun,sca->target)); + dev_t newdev = SCSI_MKFIXED(sca->scbus,sca->target,sca->lun); int ret; if (sscdev != NODEV) diff --git a/sys/scsi/st.c b/sys/scsi/st.c index b43f0c5..f8c168f 100644 --- a/sys/scsi/st.c +++ b/sys/scsi/st.c @@ -12,7 +12,7 @@ * on the understanding that TFS is not responsible for the correct * functioning of this software in any circumstances. * - * $Id: st.c,v 1.33 1995/04/23 22:07:54 gibbs Exp $ + * $Id: st.c,v 1.34 1995/04/29 21:30:29 joerg Exp $ */ /* @@ -53,11 +53,14 @@ u_int32 ststrats, stqueues; #define DEF_FIXED_BSIZE 512 #define ST_RETRIES 4 /* only on non IO commands */ +#define STUNIT(DEV) ((minor(DEV)&0xF0) >> 4) /* 4 bit unit. */ +#define STSETUNIT(DEV, U) makedev(major(DEV), ((U) << 4)) + #define MODE(z) ( (minor(z) & 0x03) ) #define DSTY(z) ( ((minor(z) >> 2) & 0x03) ) #define CTLMODE 3 -#define IS_CTLMODE(DEV) (MODE(DEV) == CTLMODE || SCSI_SUPER(DEV)) +#define IS_CTLMODE(DEV) (MODE(DEV) == CTLMODE) #define SCSI_2_MAX_DENSITY_CODE 0x17 /* maximum density code specified * in SCSI II spec. */ diff --git a/sys/scsi/su.c b/sys/scsi/su.c index 0211295..dd73c2b 100644 --- a/sys/scsi/su.c +++ b/sys/scsi/su.c @@ -44,7 +44,7 @@ * SUCH DAMAGE. *End copyright * - * $Id: su.c,v 1.3 1995/01/08 15:56:10 dufault Exp $ + * $Id: su.c,v 1.4 1995/03/04 20:51:07 dufault Exp $ * * Tabstops 4 */ @@ -58,6 +58,19 @@ #include <sys/buf.h> #include <sys/systm.h> +/* Build an old style device number (unit encoded in the minor number) + * from a base old one (no flag bits) and a full new one + * (BUS, LUN, TARG in the minor number, and flag bits). + * + * OLDDEV has the major number and device unit only. It was constructed + * at attach time and is stored in the scsi_link structure. + * + * NEWDEV can have whatever in it, but only the old control flags and the + * super bit are present. IT CAN'T HAVE ANY UNIT INFORMATION or you'll + * wind up with the wrong unit. + */ +#define OLD_DEV(NEWDEV, OLDDEV) ((OLDDEV) | ((NEWDEV) & 0x080000FF)) + /* XXX: These are taken from, and perhaps belong in, conf.c */ #define nxopen (d_open_t *)enxio |