Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.h revision 1.9
      1 /*
      2  * Copyright (c) 1993, 1994 Charles Hannum.  All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  * 3. All advertising materials mentioning features or use of this software
     13  *    must display the following acknowledgement:
     14  *	This product includes software developed by Charles Hannum.
     15  * 4. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  *
     29  *	$Id: scsiconf.h,v 1.9 1994/04/20 22:13:35 mycroft Exp $
     30  */
     31 
     32 /*
     33  * Originally written by Julian Elischer (julian (at) tfs.com)
     34  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     35  *
     36  * TRW Financial Systems, in accordance with their agreement with Carnegie
     37  * Mellon University, makes this software available to CMU to distribute
     38  * or use in any manner that they see fit as long as this message is kept with
     39  * the software. For this reason TFS also grants any other persons or
     40  * organisations permission to use or modify this software.
     41  *
     42  * TFS supplies this software to be publicly redistributed
     43  * on the understanding that TFS is not responsible for the correct
     44  * functioning of this software in any circumstances.
     45  *
     46  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     47  */
     48 
     49 #ifndef	SCSI_SCSICONF_H
     50 #define SCSI_SCSICONF_H 1
     51 typedef	int			boolean;
     52 typedef	long int		int32;
     53 typedef	short int		int16;
     54 typedef	char 			int8;
     55 typedef	unsigned long int	u_int32;
     56 typedef	unsigned short int	u_int16;
     57 typedef	unsigned char 		u_int8;
     58 
     59 #include <sys/queue.h>
     60 #include <machine/cpu.h>
     61 #include <scsi/scsi_debug.h>
     62 
     63 /*
     64  * The following documentation tries to describe the relationship between the
     65  * various structures defined in this file:
     66  *
     67  * each adapter type has a scsi_adapter struct. This describes the adapter and
     68  *    identifies routines that can be called to use the adapter.
     69  * each device type has a scsi_device struct. This describes the device and
     70  *    identifies routines that can be called to use the device.
     71  * each existing device position (scsibus + target + lun)
     72  *    can be described by a scsi_link struct.
     73  *    Only scsi positions that actually have devices, have a scsi_link
     74  *    structure assigned. so in effect each device has scsi_link struct.
     75  *    The scsi_link structure contains information identifying both the
     76  *    device driver and the adapter driver for that position on that scsi bus,
     77  *    and can be said to 'link' the two.
     78  * each individual scsi bus has an array that points to all the scsi_link
     79  *    structs associated with that scsi bus. Slots with no device have
     80  *    a NULL pointer.
     81  * each individual device also knows the address of it's own scsi_link
     82  *    structure.
     83  *
     84  *				-------------
     85  *
     86  * The key to all this is the scsi_link structure which associates all the
     87  * other structures with each other in the correct configuration.  The
     88  * scsi_link is the connecting information that allows each part of the
     89  * scsi system to find the associated other parts.
     90  */
     91 
     92 
     93 /*
     94  * These entrypoints are called by the high-end drivers to get services from
     95  * whatever low-end drivers they are attached to each adapter type has one of
     96  * these statically allocated.
     97  */
     98 struct scsi_adapter {
     99 /* 4*/	int		(*scsi_cmd)();
    100 /* 8*/	void		(*scsi_minphys)();
    101 /*12*/	int32		(*open_target_lu)();
    102 /*16*/	int32		(*close_target_lu)();
    103 /*20*/	u_int		(*adapter_info)(); /* see definitions below */
    104 /*24*/	char		*name; /* name of scsi bus controller */
    105 /*32*/	u_long	spare[2];
    106 };
    107 
    108 /*
    109  * return values for scsi_cmd()
    110  */
    111 #define SUCCESSFULLY_QUEUED	0
    112 #define TRY_AGAIN_LATER		1
    113 #define	COMPLETE		2
    114 #define	HAD_ERROR		3 /* do not use this, use COMPLETE */
    115 #define	ESCAPE_NOT_SUPPORTED	4
    116 
    117 /*
    118  * Format of adapter_info() response data
    119  * e.g. maximum number of entries queuable to a device by the adapter
    120  */
    121 #define	AD_INF_MAX_CMDS		0x000000FF
    122 /* 24 bits of other adapter characteristics go here */
    123 
    124 /*
    125  * These entry points are called by the low-end drivers to get services from
    126  * whatever high-end drivers they are attached to.  Each device type has one
    127  * of these statically allocated.
    128  */
    129 struct scsi_device {
    130 /*  4*/	int	(*err_handler)(); /* returns -1 to say err processing complete */
    131 /*  8*/	void	(*start)();
    132 /* 12*/	int32	(*async)();
    133 /* 16*/	int32	(*done)();	/* returns -1 to say done processing complete */
    134 /* 20*/	char	*name;		/* name of device type */
    135 /* 24*/	int	flags;		/* device type dependent flags */
    136 /* 32*/	int32	spare[2];
    137 };
    138 
    139 /*
    140  * This structure describes the connection between an adapter driver and
    141  * a device driver, and is used by each to call services provided by
    142  * the other, and to allow generic scsi glue code to call these services
    143  * as well.
    144  */
    145 struct scsi_link {
    146 /*  1*/	u_int8	scsibus;		/* the Nth scsibus */
    147 /*  2*/	u_int8	target;			/* targ of this dev */
    148 /*  3*/	u_int8	lun;			/* lun of this dev */
    149 /*  4*/	u_int8	adapter_targ;		/* what are we on the scsi bus */
    150 /*  5*/	u_int8	dev_unit;		/* e.g. the 0 in sd0 */
    151 /*  6*/	u_int8	opennings;		/* available operations */
    152 /*  7*/	u_int8	active;			/* operations in progress */
    153 /*  8*/ u_int8	sparea[1];
    154 /* 10*/	int	flags;			/* flags that all devices have */
    155 /* 12*/	u_int8	spareb[2];
    156 /* 16*/	struct	scsi_adapter *adapter;	/* adapter entry points etc. */
    157 /* 20*/	struct	scsi_device *device;	/* device entry points etc. */
    158 /* 24*/	void	*adapter_softc;		/* needed for call to foo_scsi_cmd */
    159 /* 28*/	void	*fordriver;		/* for private use by the driver */
    160 };
    161 #define	SDEV_MEDIA_LOADED 	0x01	/* device figures are still valid */
    162 #define	SDEV_WAITING	 	0x02	/* a process is waiting for this */
    163 #define	SDEV_OPEN	 	0x04	/* at least 1 open session */
    164 #define	SDEV_DBX		0xF0	/* debuging flags (scsi_debug.h) */
    165 
    166 /*
    167  * One of these is allocated and filled in for each scsi bus.
    168  * it holds pointers to allow the scsi bus to get to the driver
    169  * That is running each LUN on the bus
    170  * it also has a template entry which is the prototype struct
    171  * supplied by the adapter driver, this is used to initialise
    172  * the others, before they have the rest of the fields filled in
    173  */
    174 struct scsibus_data {
    175 	struct device sc_dev;
    176 	struct scsi_link *adapter_link;		/* prototype supplied by adapter */
    177 	struct scsi_link *sc_link[8][8];
    178 };
    179 
    180 /*
    181  * Each scsi transaction is fully described by one of these structures
    182  * It includes information about the source of the command and also the
    183  * device and adapter for which the command is destined.
    184  * (via the scsi_link structure)
    185  */
    186 struct scsi_xfer {
    187 /* 4*/	LIST_ENTRY(scsi_xfer) free_list;
    188 /*12*/	int	flags;
    189 /*16*/	struct	scsi_link *sc_link;	/* all about our device and adapter */
    190 /*20*/	int	retries;		/* the number of times to retry */
    191 /*24*/	int	timeout;		/* in milliseconds */
    192 /*28*/	struct	scsi_generic *cmd;	/* The scsi command to execute */
    193 /*32*/	int32	cmdlen;			/* how long it is */
    194 /*36*/	u_char	*data;			/* dma address OR a uio address */
    195 /*40*/	int32	datalen;		/* data len (blank if uio)    */
    196 /*44*/	int32	resid;			/* how much buffer was not touched */
    197 /*48*/	int	error;			/* an error value	*/
    198 /*52*/	struct	buf *bp;		/* If we need to associate with a buf */
    199 /*84*/	struct	scsi_sense_data	sense; /* 32 bytes*/
    200 	/*
    201 	 * Believe it or not, Some targets fall on the ground with
    202 	 * anything but a certain sense length.
    203 	 */
    204 /*88*/	int32 req_sense_length;		/* Explicit request sense length */
    205 /*92*/	int32 status;			/* SCSI status */
    206 /*104*/	struct	scsi_generic cmdstore;	/* stash the command in here */
    207 };
    208 
    209 /*
    210  * Per-request Flag values
    211  */
    212 #define	SCSI_NOSLEEP	0x01	/* Not a user... don't sleep		*/
    213 #define	SCSI_NOMASK	0x02	/* dont allow interrupts.. booting	*/
    214 #define	SCSI_NOSTART	0x04	/* left over from ancient history	*/
    215 #define	SCSI_USER	0x08	/* Is a user cmd, call scsi_user_done	*/
    216 #define	ITSDONE		0x10	/* the transfer is as done as it gets	*/
    217 #define	INUSE		0x20	/* The scsi_xfer block is in use	*/
    218 #define	SCSI_SILENT	0x40	/* Don't report errors to console	*/
    219 #define SCSI_ERR_OK	0x80	/* An error on this operation is OK.	*/
    220 #define	SCSI_RESET	0x100	/* Reset the device in question		*/
    221 #define	SCSI_DATA_UIO	0x200	/* The data address refers to a UIO	*/
    222 #define	SCSI_DATA_IN	0x400	/* expect data to come INTO memory	*/
    223 #define	SCSI_DATA_OUT	0x800	/* expect data to flow OUT of memory	*/
    224 #define	SCSI_TARGET	0x1000	/* This defines a TARGET mode op.	*/
    225 #define	SCSI_ESCAPE	0x2000	/* Escape operation			*/
    226 
    227 /*
    228  * Escape op codes.  This provides an extensible setup for operations
    229  * that are not scsi commands.  They are intended for modal operations.
    230  */
    231 
    232 #define SCSI_OP_TARGET	0x0001
    233 #define	SCSI_OP_RESET	0x0002
    234 #define	SCSI_OP_BDINFO	0x0003
    235 
    236 /*
    237  * Error values an adapter driver may return
    238  */
    239 #define XS_NOERROR	0x0	/* there is no error, (sense is invalid)  */
    240 #define XS_SENSE	0x1	/* Check the returned sense for the error */
    241 #define	XS_DRIVER_STUFFUP 0x2	/* Driver failed to perform operation	  */
    242 #define XS_TIMEOUT	0x03	/* The device timed out.. turned off?	  */
    243 #define XS_SWTIMEOUT	0x04	/* The Timeout reported was caught by SW  */
    244 #define XS_BUSY		0x08	/* The device busy, try again later?	  */
    245 
    246 #if !defined(i386) || defined(NEWCONFIG)
    247 int scsi_targmatch __P((struct device *, struct cfdata *, void *));
    248 #else
    249 int scsi_targmatch();
    250 #endif
    251 
    252 struct scsi_xfer *get_xs __P((struct scsi_link *, int));
    253 void free_xs __P((struct scsi_xfer *, struct scsi_link *, int));
    254 void sc_print_addr __P((struct scsi_link *sc_link));
    255 u_int32 scsi_size __P((struct scsi_link *, int));
    256 int scsi_test_unit_ready __P((struct scsi_link *, int));
    257 int scsi_change_def __P((struct scsi_link *, int));
    258 int scsi_inquire __P((struct scsi_link *, struct scsi_inquiry_data *, int));
    259 int scsi_prevent __P((struct scsi_link *, int, int));
    260 int scsi_start __P((struct scsi_link *, int, int));
    261 void scsi_done __P((struct scsi_xfer *));
    262 int scsi_scsi_cmd __P((struct scsi_link *, struct scsi_generic *,
    263 			u_int32 cmdlen, u_char *data_addr,
    264 			u_int32 datalen, int retries,
    265 			int timeout, struct buf *bp,
    266 			int flags));
    267 int scsi_do_ioctl __P((struct scsi_link *, int, caddr_t, int));
    268 
    269 void show_scsi_xs __P((struct scsi_xfer *));
    270 void show_scsi_cmd __P((struct scsi_xfer *));
    271 void show_mem __P((unsigned char *, u_int32));
    272 
    273 void	lto3b __P((int val, u_char *bytes));
    274 int	_3btol __P((u_char *bytes));
    275 
    276 #endif /*SCSI_SCSICONF_H*/
    277 /* END OF FILE */
    278