New version of scsi code from Julian
[unix-history] / sys / scsi / scsiconf.h
CommitLineData
15637ed4
RG
1/*
2 * Written by Julian Elischer (julian@tfs.com)
3 * for TRW Financial Systems for use under the MACH(2.5) operating system.
4 *
5 * TRW Financial Systems, in accordance with their agreement with Carnegie
6 * Mellon University, makes this software available to CMU to distribute
7 * or use in any manner that they see fit as long as this message is kept with
8 * the software. For this reason TFS also grants any other persons or
9 * organisations permission to use or modify this software.
10 *
11 * TFS supplies this software to be publicly redistributed
12 * on the understanding that TFS is not responsible for the correct
13 * functioning of this software in any circumstances.
14 *
15637ed4 15 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
98639498 16 *
519fb2b7 17 * $Id: scsiconf.h,v 2.4 93/10/16 00:59:13 julian Exp Locker: julian $
15637ed4 18 */
519fb2b7
RG
19#ifndef SCSI_SCSICONF_H
20#define SCSI_SCSICONF_H 1
21typedef int boolean;
22typedef int errval;
23typedef long int int32;
24typedef short int int16;
25typedef char int8;
26typedef unsigned long int u_int32;
27typedef unsigned short int u_int16;
28typedef unsigned char u_int8;
15637ed4 29
519fb2b7 30#include <scsi/scsi_debug.h>
bbc3f849 31
519fb2b7
RG
32/*
33 * The following documentation tries to describe the relationship between the
34 * various structures defined in this file:
35 *
36 * each adapter type has a scsi_adapter struct. This describes the adapter and
37 * identifies routines that can be called to use the adapter.
38 * each device type has a scsi_device struct. This describes the device and
39 * identifies routines that can be called to use the device.
40 * each existing device position (scsibus + target + lun)
41 * can be described by a scsi_link struct.
42 * Only scsi positions that actually have devices, have a scsi_link
43 * structure assigned. so in effect each device has scsi_link struct.
44 * The scsi_link structure contains information identifying both the
45 * device driver and the adapter driver for that position on that scsi bus,
46 * and can be said to 'link' the two.
47 * each individual scsi bus has an array that points to all the scsi_link
48 * structs associated with that scsi bus. Slots with no device have
49 * a NULL pointer.
50 * each individual device also knows the address of it's own scsi_link
51 * structure.
52 *
53 * -------------
54 *
55 * The key to all this is the scsi_link structure which associates all the
56 * other structures with each other in the correct configuration. The
57 * scsi_link is the connecting information that allows each part of the
58 * scsi system to find the associated other parts.
59 */
60
61
62/*
63 * These entrypoints are called by the high-end drivers to get services from
64 * whatever low-end drivers they are attached to each adapter type has one of
65 * these statically allocated.
66 */
67struct scsi_adapter
15637ed4 68{
519fb2b7
RG
69/* 04*/ int32 (*scsi_cmd)();
70/* 08*/ void (*scsi_minphys)();
71/* 12*/ int32 (*open_target_lu)();
72/* 16*/ int32 (*close_target_lu)();
73/* 20*/ u_int32 (*adapter_info)(); /* see definitions below */
74/* 24*/ char *name; /* name of scsi bus controller */
75/* 32*/ u_long spare[2];
15637ed4 76};
15637ed4 77
519fb2b7
RG
78/*
79 * return values for scsi_cmd()
80 */
15637ed4
RG
81#define SUCCESSFULLY_QUEUED 0
82#define TRY_AGAIN_LATER 1
83#define COMPLETE 2
519fb2b7 84#define HAD_ERROR 3 /* do not use this, use COMPLETE */
d4284689 85#define ESCAPE_NOT_SUPPORTED 4
15637ed4 86
519fb2b7
RG
87/*
88 * Format of adapter_info() response data
89 * e.g. maximum number of entries queuable to a device by the adapter
90 */
91#define AD_INF_MAX_CMDS 0x000000FF
92/* 24 bits of other adapter characteristics go here */
93
94/*
95 * These entry points are called by the low-end drivers to get services from
96 * whatever high-end drivers they are attached to. Each device type has one
97 * of these statically allocated.
98 */
99struct scsi_device
100{
101/* 4*/ errval (*err_handler)(); /* returns -1 to say err processing complete */
102/* 8*/ void (*start)();
103/* 12*/ int32 (*async)();
104/* 16*/ int32 (*done)(); /* returns -1 to say done processing complete */
105/* 20*/ char *name; /* name of device type */
106/* 24*/ u_int32 flags; /* device type dependent flags */
107/* 32*/ int32 spare[2];
108};
109
110/*
111 * This structure describes the connection between an adapter driver and
112 * a device driver, and is used by each to call services provided by
113 * the other, and to allow generic scsi glue code to call these services
114 * as well.
115 */
116struct scsi_link
117{
118/* 1*/ u_int8 target; /* targ of this dev */
119/* 2*/ u_int8 lun; /* lun of this dev */
120/* 3*/ u_int8 adapter_targ; /* what are we on the scsi bus */
121/* 4*/ u_int8 adapter_unit; /* e.g. the 0 in aha0 */
122/* 5*/ u_int8 scsibus; /* the Nth scsibus */
123/* 6*/ u_int8 dev_unit; /* e.g. the 0 in sd0 */
124/* 7*/ u_int8 opennings; /* available operations */
125/* 8*/ u_int8 active; /* operations in progress */
126/* 10*/ u_int16 flags; /* flags that all devices have */
127/* 12*/ u_int8 spareb[2]; /* unused */
128/* 16*/ struct scsi_adapter *adapter; /* adapter entry points etc. */
129/* 20*/ struct scsi_device *device; /* device entry points etc. */
130/* 24*/ struct scsi_xfer *active_xs; /* operations under way */
131/* 28*/ void * fordriver; /* for private use by the driver */
132/* 32*/ u_int32 spare;
133};
134#define SDEV_MEDIA_LOADED 0x01 /* device figures are still valid */
135#define SDEV_WAITING 0x02 /* a process is waiting for this */
136#define SDEV_OPEN 0x04 /* at least 1 open session */
137#define SDEV_DBX 0xF0 /* debuging flags (scsi_debug.h) */
138
139/*
140 * One of these is allocated and filled in for each scsi bus.
141 * it holds pointers to allow the scsi bus to get to the driver
142 * That is running each LUN on the bus
143 * it also has a template entry which is the prototype struct
144 * supplied by the adapter driver, this is used to initialise
145 * the others, before they have the rest of the fields filled in
146 */
147struct scsibus_data {
148 struct scsi_link *adapter_link; /* prototype supplied by adapter */
149 struct scsi_link *sc_link[8][8];
150};
151
152/*
153 * Each scsi transaction is fully described by one of these structures
154 * It includes information about the source of the command and also the
155 * device and adapter for which the command is destined.
156 * (via the scsi_link structure) *
157 */
15637ed4
RG
158struct scsi_xfer
159{
519fb2b7
RG
160/*04*/ struct scsi_xfer *next; /* when free */
161/*08*/ u_int32 flags;
162/*12*/ struct scsi_link *sc_link; /* all about our device and adapter */
163/*13*/ u_int8 retries; /* the number of times to retry */
164/*16*/ u_int8 spare[3];
165/*20*/ int32 timeout; /* in milliseconds */
166/*24*/ struct scsi_generic *cmd; /* The scsi command to execute */
167/*28*/ int32 cmdlen; /* how long it is */
168/*32*/ u_char *data; /* dma address OR a uio address */
169/*36*/ int32 datalen; /* data len (blank if uio) */
170/*40*/ int32 resid; /* how much buffer was not touched */
171/*44*/ int32 error; /* an error value */
172/*48*/ struct buf *bp; /* If we need to associate with a buf */
173/*80*/ struct scsi_sense_data sense; /* 32 bytes*/
174 /*
175 * Believe it or not, Some targets fall on the ground with
d4284689
RG
176 * anything but a certain sense length.
177 */
519fb2b7
RG
178/*84*/ int32 req_sense_length; /* Explicit request sense length */
179/*88*/ int32 status; /* SCSI status */
180/*100*/ struct scsi_generic cmdstore; /* stash the command in here */
15637ed4 181};
519fb2b7
RG
182
183/*
184 * Per-request Flag values
185 */
15637ed4
RG
186#define SCSI_NOSLEEP 0x01 /* Not a user... don't sleep */
187#define SCSI_NOMASK 0x02 /* dont allow interrupts.. booting */
188#define SCSI_NOSTART 0x04 /* left over from ancient history */
519fb2b7 189#define SCSI_USER 0x08 /* Is a user cmd, call scsi_user_done */
15637ed4
RG
190#define ITSDONE 0x10 /* the transfer is as done as it gets */
191#define INUSE 0x20 /* The scsi_xfer block is in use */
192#define SCSI_SILENT 0x40 /* Don't report errors to console */
193#define SCSI_ERR_OK 0x80 /* An error on this operation is OK. */
194#define SCSI_RESET 0x100 /* Reset the device in question */
195#define SCSI_DATA_UIO 0x200 /* The data address refers to a UIO */
196#define SCSI_DATA_IN 0x400 /* expect data to come INTO memory */
197#define SCSI_DATA_OUT 0x800 /* expect data to flow OUT of memory */
198#define SCSI_TARGET 0x1000 /* This defines a TARGET mode op. */
d4284689
RG
199#define SCSI_ESCAPE 0x2000 /* Escape operation */
200
519fb2b7
RG
201/*
202 * Escape op codes. This provides an extensible setup for operations
203 * that are not scsi commands. They are intended for modal operations.
204 */
d4284689
RG
205
206#define SCSI_OP_TARGET 0x0001
207#define SCSI_OP_RESET 0x0002
208#define SCSI_OP_BDINFO 0x0003
209
519fb2b7
RG
210/*
211 * Error values an adapter driver may return
212 */
15637ed4
RG
213#define XS_NOERROR 0x0 /* there is no error, (sense is invalid) */
214#define XS_SENSE 0x1 /* Check the returned sense for the error */
215#define XS_DRIVER_STUFFUP 0x2 /* Driver failed to perform operation */
216#define XS_TIMEOUT 0x03 /* The device timed out.. turned off? */
217#define XS_SWTIMEOUT 0x04 /* The Timeout reported was caught by SW */
218#define XS_BUSY 0x08 /* The device busy, try again later? */
219
519fb2b7
RG
220void scsi_attachdevs __P((struct scsi_link *sc_link_proto));
221struct scsi_xfer *get_xs( struct scsi_link *sc_link, u_int32 flags);
222void free_xs(struct scsi_xfer *xs, struct scsi_link *sc_link,u_int32 flags);
223u_int32 scsi_size( struct scsi_link *sc_link,u_int32 flags);
224errval scsi_test_unit_ready( struct scsi_link *sc_link, u_int32 flags);
225errval scsi_change_def( struct scsi_link *sc_link, u_int32 flags);
226errval scsi_inquire( struct scsi_link *sc_link,
227 struct scsi_inquiry_data *inqbuf, u_int32 flags);
228errval scsi_prevent( struct scsi_link *sc_link, u_int32 type,u_int32 flags);
229errval scsi_start_unit( struct scsi_link *sc_link, u_int32 flags);
230void scsi_done(struct scsi_xfer *xs);
231errval scsi_scsi_cmd( struct scsi_link *sc_link, struct scsi_generic *scsi_cmd,
232 u_int32 cmdlen, u_char *data_addr,
233 u_int32 datalen, u_int32 retries,
234 u_int32 timeout, struct buf *bp,
235 u_int32 flags);
236errval scsi_do_ioctl __P((struct scsi_link *sc_link, int cmd, caddr_t addr, int f));
237
238void show_scsi_xs(struct scsi_xfer *xs);
239void show_scsi_cmd(struct scsi_xfer *xs);
240void show_mem(unsigned char * , u_int32);
241
242void lto3b __P((int val, u_char *bytes));
243int _3btol __P((u_char *bytes));
244
245#endif /*SCSI_SCSICONF_H*/
246/* END OF FILE */