FreeBSD/Linux Kernel Cross Reference
sys/scsi/scsi_defs.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993-1989 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: scsi_defs.h,v $
29 * Revision 2.16 93/08/03 12:34:39 mrt
30 * Added hooks for multi-LUN devices.
31 * Addeddefs for COMM devices.
32 * [93/07/29 23:39:53 af]
33 *
34 * Added rewriting of label where we found it.
35 * [93/05/06 10:05:31 af]
36 *
37 * Revision 2.15 93/05/10 21:23:07 rvb
38 * Added rewriting of label where we found it.
39 * [93/05/06 10:05:31 af]
40 *
41 * Revision 2.14 93/03/26 18:01:32 mrt
42 * Use a pointer (to a list of alternate operations) to
43 * mark CDROM drives that are non-standard.
44 * [93/03/22 af]
45 *
46 * Command is unsigned.
47 * [93/03/17 af]
48 *
49 * Revision 2.13 93/03/09 10:58:18 danner
50 * Merge botch, oops. So I did enough to get a clean build
51 * under GCC on alpha.
52 * [93/03/07 13:24:00 af]
53 *
54 * Added cdrom status keeping. Lint.
55 * [93/03/06 af]
56 *
57 * Change type of optimize to void in scsi_devsw_t to match usage.
58 * [93/02/17 jeffreyh]
59 *
60 * Revision 2.12 93/01/14 17:55:51 danner
61 * Define SCSI_{OPTIMIZE,OPEN,CLOSE}_NULL.
62 * Expanded scsi_devsw_t function prototypes.
63 * [93/01/14 danner]
64 *
65 * Revision 2.11 92/05/21 17:24:24 jfriedl
66 * Appended 'U' to constants that would otherwise be signed.
67 * wakeup() is void.
68 * Other changes to quiet gcc warnings.
69 * [92/05/16 jfriedl]
70 *
71 * Revision 2.10 92/02/23 22:44:55 elf
72 * Changed unused field into masterno in target descriptor.
73 * [92/02/22 19:31:54 af]
74 *
75 * Revision 2.9 91/08/24 12:28:38 af
76 * Added processor_type infos, definition of an opaque type,
77 * multiP locking.
78 * [91/08/02 03:55:05 af]
79 *
80 * Revision 2.8 91/07/09 23:22:53 danner
81 * Added include of <scsi/rz_labels.h>
82 * [91/07/09 11:16:30 danner]
83 *
84 * Revision 2.7 91/06/19 11:57:43 rvb
85 * File moved here from mips/PMAX since it is now "MI" code, also
86 * used by Vax3100 and soon -- the omron luna88k.
87 * [91/06/04 rvb]
88 *
89 * Revision 2.6 91/05/14 17:30:18 mrt
90 * Correcting copyright
91 *
92 * Revision 2.5 91/05/13 06:05:34 af
93 * Made counters unsigned, added copy_count for use by HBAs
94 * that do unlimited DMA via double buffering. Made explicit
95 * two padding bytes, and let them be HBA-specific (e.g. used
96 * for odd-byte-boundary conditions on some).
97 * Made max_dma_data unsigned, a value of -1 means unlimited.
98 * Removed unsed residue field.
99 *
100 * Defined tape-specific information fields to target structure.
101 * Added tape-specific flags and flag for targets that require
102 * the long form of various scsi commands.
103 * Added disconnected-state information to target structure.
104 * Added watchdog field to adapter structure.
105 * [91/05/12 16:24:10 af]
106 *
107 * Revision 2.4.1.2 91/04/05 13:13:29 af
108 * Made counters unsigned, added copy_count for use by HBAs
109 * that do unlimited DMA via double buffering. Made explicit
110 * two padding bytes, and let them be HBA-specific (e.g. used
111 * for odd-byte-boundary conditions on some).
112 * Made max_dma_data unsigned, a value of -1 means unlimited.
113 * Removed unsed residue field.
114 *
115 * Revision 2.4.1.1 91/03/29 17:06:09 af
116 * Defined tape-specific information fields to target structure.
117 * Added tape-specific flags and flag for targets that require
118 * the long form of various scsi commands.
119 * Added disconnected-state information to target structure.
120 * Added watchdog field to adapter structure.
121 *
122 * Revision 2.4 91/02/05 17:45:43 mrt
123 * Added author notices
124 * [91/02/04 11:19:29 mrt]
125 *
126 * Changed to use new Mach copyright
127 * [91/02/02 12:18:11 mrt]
128 *
129 * Revision 2.3 90/12/05 23:35:12 af
130 * Cleanups, use BSD labels internally.
131 * [90/12/03 23:47:29 af]
132 *
133 * Revision 2.1.1.1 90/11/01 03:39:55 af
134 * Created.
135 * [90/09/03 af]
136 */
137 /*
138 * File: scsi_defs.h
139 * Author: Alessandro Forin, Carnegie Mellon University
140 * Date: 9/90
141 *
142 * Controller-independent definitions for the SCSI driver
143 */
144
145 #ifndef _SCSI_SCSI_DEFS_H_
146 #define _SCSI_SCSI_DEFS_H_
147
148 #include <kern/queue.h>
149 #include <kern/lock.h>
150
151 #define await(event) sleep(event,0)
152 extern void wakeup();
153
154 typedef vm_offset_t opaque_t; /* should be elsewhere */
155
156 /*
157 * Internal error codes, and return values
158 * XXX use the mach/error.h scheme XXX
159 */
160 typedef unsigned int scsi_ret_t;
161
162 #define SCSI_ERR_GRAVITY(x) ((unsigned)(x)&0xf0000000U)
163 #define SCSI_ERR_GRAVE 0x80000000U
164 #define SCSI_ERR_BAD 0x40000000
165
166 #define SCSI_ERR_CLASS(x) ((unsigned)(x)&0x0fffffffU)
167 #define SCSI_ERR_STATUS 0x00000001
168 #define SCSI_ERR_SENSE 0x00000002
169 #define SCSI_ERR_MSEL 0x00000004
170
171 extern void scsi_error(/* target_info_t *, unsigned, unsigned */);
172
173 #define SCSI_RET_IN_PROGRESS 0x00
174 #define SCSI_RET_SUCCESS 0x01
175 #define SCSI_RET_RETRY 0x02
176 #define SCSI_RET_NEED_SENSE 0x04
177 #define SCSI_RET_ABORTED 0x08
178 #define SCSI_RET_DEVICE_DOWN 0x10
179
180 /*
181 * Device-specific information kept by driver
182 */
183 typedef struct {
184 struct disklabel l;
185 struct {
186 unsigned int badblockno;
187 unsigned int save_rec;
188 char *save_addr;
189 int save_count;
190 int save_resid;
191 int retry_count;
192 } b;
193 int labelsector;
194 int labeloffset;
195 } scsi_disk_info_t;
196
197 typedef struct {
198 boolean_t read_only;
199 unsigned int speed;
200 unsigned int density;
201 unsigned int maxreclen;
202 boolean_t fixed_size;
203 } scsi_tape_info_t;
204
205 typedef struct {
206 char req_pending;
207 char req_id;
208 char req_lun;
209 char req_cmd;
210 unsigned int req_len;
211 /* more later */
212 } scsi_processor_info_t;
213
214 typedef struct {
215 void *result;
216 boolean_t result_available;
217 int result_size;
218 struct red_list *violates_standards;
219 } scsi_cdrom_info_t;
220
221 typedef struct {
222 # define SCSI_MAX_COMM_TTYS 16
223 struct tty *tty[SCSI_MAX_COMM_TTYS];
224 io_req_t ior;
225 } scsi_comm_info_t;
226
227 /*
228 * Device descriptor
229 */
230
231 #define SCSI_TARGET_NAME_LEN 8+16+4+8 /* our way to keep it */
232
233 typedef struct target_info {
234 queue_chain_t links; /* to queue for bus */
235 io_req_t ior; /* what we are doing */
236
237 unsigned int flags;
238 #define TGT_DID_SYNCH 0x00000001 /* finished the synch neg */
239 #define TGT_TRY_SYNCH 0x00000002 /* do the synch negotiation */
240 #define TGT_FULLY_PROBED 0x00000004 /* can sleep to wait */
241 #define TGT_ONLINE 0x00000008 /* did the once-only stuff */
242 #define TGT_ALIVE 0x00000010
243 #define TGT_BBR_ACTIVE 0x00000020 /* bad block replc in progress */
244 #define TGT_DISCONNECTED 0x00000040 /* waiting for reconnect */
245 #define TGT_WRITTEN_TO 0x00000080 /* tapes: needs a filemark on close */
246 #define TGT_REWIND_ON_CLOSE 0x00000100 /* tapes: rewind */
247 #define TGT_BIG 0x00000200 /* disks: > 1Gb, use long R/W */
248 #define TGT_REMOVABLE_MEDIA 0x00000400 /* e.g. floppy, cd-rom,.. */
249 #define TGT_READONLY 0x00000800 /* cd-rom, scanner, .. */
250 #define TGT_OPTIONAL_CMD 0x00001000 /* optional cmd, ignore errors */
251 #define TGT_WRITE_LABEL 0x00002000 /* disks: enable overwriting of label */
252 #define TGT_US 0x00004000 /* our desc, when target role */
253
254 #define TGT_HW_SPECIFIC_BITS 0xffff0000U /* see specific HBA */
255 char *hw_state; /* opaque */
256 char *dma_ptr;
257 char *cmd_ptr;
258 struct scsi_devsw_struct *dev_ops; /* circularity */
259 struct target_info *next_lun; /* if multi-LUN */
260 char target_id;
261 char unit_no;
262 unsigned char sync_period;
263 unsigned char sync_offset;
264 decl_simple_lock_data(,target_lock)
265 #ifdef MACH_KERNEL
266 #else /*MACH_KERNEL*/
267 struct fdma fdma;
268 #endif /*MACH_KERNEL*/
269 /*
270 * State info kept while waiting to seize bus, either for first
271 * selection or while in disconnected state
272 */
273 struct {
274 struct script *script;
275 int (*handler)();
276 unsigned int out_count;
277 unsigned int in_count;
278 unsigned int copy_count; /* optional */
279 unsigned int dma_offset;
280 unsigned char identify;
281 unsigned char cmd_count;
282 unsigned char hba_dep[2];
283 } transient_state;
284 unsigned int block_size;
285 volatile char done;
286 unsigned char cur_cmd;
287 unsigned char lun;
288 char masterno;
289 char tgt_name[SCSI_TARGET_NAME_LEN];
290 union {
291 scsi_disk_info_t disk;
292 scsi_tape_info_t tape;
293 scsi_cdrom_info_t cdrom;
294 scsi_processor_info_t cpu;
295 scsi_comm_info_t comm;
296 } dev_info;
297 } target_info_t;
298
299
300 /*
301 * Device-specific operations
302 */
303 typedef struct scsi_devsw_struct {
304 char *(*driver_name)(boolean_t); /* my driver's name */
305 void (*optimize)(target_info_t *); /* tune up internal params */
306 scsi_ret_t (*open)(target_info_t *,io_req_t);/* open time ops */
307 scsi_ret_t (*close)(target_info_t *); /* close time ops */
308 int (*strategy)(io_req_t); /* sort/start routine */
309 void (*restart)(target_info_t *,
310 boolean_t); /* completion routine */
311 io_return_t (*get_status)(int,
312 target_info_t *,
313 dev_flavor_t,
314 dev_status_t,
315 natural_t *); /* specialization */
316 io_return_t (*set_status)(int,
317 target_info_t *,
318 dev_flavor_t,
319 dev_status_t,
320 natural_t); /* specialization */
321 } scsi_devsw_t;
322
323 #define SCSI_OPTIMIZE_NULL ((void (*)(target_info_t *)) 0)
324 #define SCSI_OPEN_NULL ((scsi_ret_t (*)(target_info_t *,io_req_t)) 0)
325 #define SCSI_CLOSE_NULL ((scsi_ret_t (*)(target_info_t *)) 0)
326
327 extern scsi_devsw_t scsi_devsw[];
328
329 /*
330 * HBA descriptor
331 */
332
333 typedef struct {
334 /* initiator (us) state */
335 unsigned char initiator_id;
336 unsigned char masterno;
337 unsigned int max_dma_data;
338 char *hw_state; /* opaque */
339 int (*go)();
340 void (*watchdog)();
341 boolean_t (*probe)();
342 /* per-target state */
343 target_info_t *target[8];
344 } scsi_softc_t;
345
346 extern scsi_softc_t *scsi_softc[];
347 extern scsi_softc_t *scsi_master_alloc(/* int unit */);
348 extern target_info_t *scsi_slave_alloc(/* int unit, int slave, char *hw */);
349
350 #define BGET(d,mid,id) (d[mid] & (1 << id)) /* bitmap ops */
351 #define BSET(d,mid,id) d[mid] |= (1 << id)
352 #define BCLR(d,mid,id) d[mid] &= ~(1 << id)
353
354 extern unsigned char scsi_no_synchronous_xfer[]; /* one bitmap per ctlr */
355 extern unsigned char scsi_use_long_form[]; /* one bitmap per ctlr */
356 extern unsigned char scsi_might_disconnect[]; /* one bitmap per ctlr */
357 extern unsigned char scsi_should_disconnect[]; /* one bitmap per ctlr */
358 extern unsigned char scsi_initiator_id[]; /* one id per ctlr */
359
360 extern boolean_t scsi_exabyte_filemarks;
361 extern boolean_t scsi_no_automatic_bbr;
362 extern int scsi_bbr_retries;
363 extern int scsi_watchdog_period;
364 extern int scsi_delay_after_reset;
365 extern unsigned int scsi_per_target_virtual; /* 2.5 only */
366
367 extern int scsi_debug;
368
369 /*
370 * HBA-independent Watchdog
371 */
372 typedef struct {
373
374 unsigned short reset_count;
375 char nactive;
376
377 char watchdog_state;
378
379 #define SCSI_WD_INACTIVE 0
380 #define SCSI_WD_ACTIVE 1
381 #define SCSI_WD_EXPIRED 2
382
383 int (*reset)();
384
385 } watchdog_t;
386
387 extern void scsi_watchdog( watchdog_t* );
388
389 #endif _SCSI_SCSI_DEFS_H_
Cache object: d83beed42843a382415f0b643f4bd107
|