scsireg.h revision 1.1 1 /* $NetBSD: scsireg.h,v 1.1 2013/01/05 17:44:24 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1990, 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Van Jacobson of Lawrence Berkeley Laboratory.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)scsireg.h 8.1 (Berkeley) 6/10/93
35 */
36
37 /*
38 * MB89352 SCSI Protocol Controller Hardware Description.
39 */
40
41 struct scsidevice {
42 volatile u_char scsi_bdid, p0, p1, p2; /* 000 */
43 volatile u_char scsi_sctl, p3, p4, p5; /* 004 */
44 #define SCTL_DISABLE 0x80
45 #define SCTL_CTRLRST 0x40
46 #define SCTL_DIAG 0x20
47 #define SCTL_ABRT_ENAB 0x10
48 #define SCTL_PARITY_ENAB 0x08
49 #define SCTL_SEL_ENAB 0x04
50 #define SCTL_RESEL_ENAB 0x02
51 #define SCTL_INTR_ENAB 0x01
52 volatile u_char scsi_scmd, p6, p7, p8; /* 008 */
53 #define SCMD_RST 0x10
54 #define SCMD_ICPT_XFR 0x08
55 #define SCMD_PROG_XFR 0x04
56 #define SCMD_PAD 0x01 /* if initiator */
57 #define SCMD_PERR_STOP 0x01 /* if target */
58 /* command codes */
59 #define SCMD_BUS_REL 0x00
60 #define SCMD_SELECT 0x20
61 #define SCMD_RST_ATN 0x40
62 #define SCMD_SET_ATN 0x60
63 #define SCMD_XFR 0x80
64 #define SCMD_XFR_PAUSE 0xa0
65 #define SCMD_RST_ACK 0xc0
66 #define SCMD_SET_ACK 0xe0
67 volatile u_char scsi_tmod, p9, p10, p11; /* 00C */
68 #define TMOD_SYNC 0x80
69 volatile u_char scsi_ints, p12, p13, p14; /* 010 */
70 #define INTS_SEL 0x80
71 #define INTS_RESEL 0x40
72 #define INTS_DISCON 0x20
73 #define INTS_CMD_DONE 0x10
74 #define INTS_SRV_REQ 0x08
75 #define INTS_TIMEOUT 0x04
76 #define INTS_HARD_ERR 0x02
77 #define INTS_RST 0x01
78 volatile u_char scsi_psns, p15, p16, p17; /* 014 */
79 #define PSNS_REQ 0x80
80 #define PSNS_ACK 0x40
81 #define PSNS_ATN 0x20
82 #define PSNS_SEL 0x10
83 #define PSNS_BSY 0x08
84 #define scsi_sdgc scsi_psns
85 #define SDGC_XFER_ENAB 0x20
86 volatile u_char scsi_ssts, p18, p19, p20; /* 018 */
87 #define SSTS_INITIATOR 0x80
88 #define SSTS_TARGET 0x40
89 #define SSTS_BUSY 0x20
90 #define SSTS_XFR 0x10
91 #define SSTS_ACTIVE (SSTS_INITIATOR|SSTS_XFR)
92 #define SSTS_RST 0x08
93 #define SSTS_TCZERO 0x04
94 #define SSTS_DREG_FULL 0x02
95 #define SSTS_DREG_EMPTY 0x01
96 volatile u_char scsi_serr, p21, p22, p23; /* 01C */
97 #define SERR_SCSI_PAR 0x80
98 #define SERR_SPC_PAR 0x40
99 #define SERR_XFER_OUT 0x20
100 #define SERR_TC_PAR 0x08
101 #define SERR_PHASE_ERR 0x04
102 #define SERR_SHORT_XFR 0x02
103 #define SERR_OFFSET 0x01
104 volatile u_char scsi_pctl, p24, p25, p26; /* 020 */
105 #define PCTL_BFINT_ENAB 0x80
106 volatile u_char scsi_mbc, p27, p28, p29; /* 024 */
107 volatile u_char scsi_dreg, p30, p31, p32; /* 028 */
108 volatile u_char scsi_temp, p33, p34, p35; /* 02C */
109 volatile u_char scsi_tch, p36, p37, p38; /* 030 */
110 volatile u_char scsi_tcm, p39, p40, p41; /* 034 */
111 volatile u_char scsi_tcl, p42, p43, p44; /* 038 */
112 volatile u_char scsi_exbf, p45, p46, p47; /* 03C */
113 };
114
115 /* psns/pctl phase lines as bits */
116 #define PHASE_MSG 0x04
117 #define PHASE_CD 0x02 /* =1 if 'command' */
118 #define PHASE_IO 0x01 /* =1 if data inbound */
119 /* Phase lines as values */
120 #define PHASE 0x07 /* mask for psns/pctl phase */
121 #define DATA_OUT_PHASE 0x00
122 #define DATA_IN_PHASE 0x01
123 #define CMD_PHASE 0x02
124 #define STATUS_PHASE 0x03
125 #define BUS_FREE_PHASE 0x04
126 #define ARB_SEL_PHASE 0x05 /* Fuji chip combines arbitration with sel. */
127 #define MESG_OUT_PHASE 0x06
128 #define MESG_IN_PHASE 0x07
129
130 /* SCSI Messages */
131
132 #define MSG_CMD_COMPLETE 0x00
133 #define MSG_EXT_MESSAGE 0x01
134 #define MSG_SAVE_DATA_PTR 0x02
135 #define MSG_RESTORE_PTR 0x03
136 #define MSG_DISCONNECT 0x04
137 #define MSG_INIT_DETECT_ERROR 0x05
138 #define MSG_ABORT 0x06
139 #define MSG_REJECT 0x07
140 #define MSG_NOOP 0x08
141 #define MSG_PARITY_ERROR 0x09
142 #define MSG_BUS_DEVICE_RESET 0x0C
143 #define MSG_IDENTIFY 0x80
144 #define MSG_IDENTIFY_DR 0xc0 /* (disconnect/reconnect allowed) */
145 #define MSG_SYNC_REQ 0x01
146
147 /* SCSI Commands */
148
149 #define CMD_TEST_UNIT_READY 0x00
150 #define CMD_REQUEST_SENSE 0x03
151 #define CMD_INQUIRY 0x12
152 #define CMD_SEND_DIAGNOSTIC 0x1D
153
154 #define CMD_REWIND 0x01
155 #define CMD_FORMAT_UNIT 0x04
156 #define CMD_READ_BLOCK_LIMITS 0x05
157 #define CMD_REASSIGN_BLOCKS 0x07
158 #define CMD_READ 0x08
159 #define CMD_WRITE 0x0A
160 #define CMD_WRITE_FILEMARK 0x10
161 #define CMD_SPACE 0x11
162 #define CMD_MODE_SELECT 0x15
163 #define CMD_RELEASE_UNIT 0x17
164 #define CMD_ERASE 0x19
165 #define CMD_MODE_SENSE 0x1A
166 #define CMD_LOADUNLOAD 0x1B
167 #define CMD_RECEIVE_DIAG 0x1C
168 #define CMD_SEND_DIAG 0x1D
169 #define CMD_P_A_MEDIA_REMOVAL 0x1E
170 #define CMD_READ_CAPACITY 0x25
171 #define CMD_READ_EXT 0x28
172 #define CMD_WRITE_EXT 0x2A
173 #define CMD_READ_DEFECT_DATA 0x37
174 #define SD_MANUFAC_DEFECTS 0x14000000
175 #define SD_GROWN_DEFECTS 0x0c000000
176 #define CMD_READ_BUFFER 0x3B
177 #define CMD_WRITE_BUFFER 0x3C
178 #define CMD_READ_FULL 0xF0
179 #define CMD_MEDIA_TEST 0xF1
180 #define CMD_ACCESS_LOG 0xF2
181 #define CMD_WRITE_FULL 0xFC
182 #define CMD_MANAGE_PRIMARY 0xFD
183 #define CMD_EXECUTE_DATA 0xFE
184
185 /* SCSI status bits */
186
187 #define STS_CHECKCOND 0x02 /* Check Condition (ie., read sense) */
188 #define STS_CONDMET 0x04 /* Condition Met (ie., search worked) */
189 #define STS_BUSY 0x08
190 #define STS_INTERMED 0x10 /* Intermediate status sent */
191 #define STS_EXT 0x80 /* Extended status valid */
192
193 /* command descriptor blocks */
194
195 struct scsi_cdb6 {
196 u_char cmd; /* command code */
197 u_char lun: 3, /* logical unit on ctlr */
198 lbah: 5; /* msb of read/write logical block addr */
199 u_char lbam; /* middle byte of l.b.a. */
200 u_char lbal; /* lsb of l.b.a. */
201 u_char len; /* transfer length */
202 u_char xtra;
203 };
204
205 struct scsi_cdb10 {
206 u_char cmd; /* command code */
207 u_char lun: 3, /* logical unit on ctlr */
208 : 4,
209 rel: 1; /* l.b.a. is relative addr if =1 */
210 u_char lbah; /* msb of read/write logical block addr */
211 u_char lbahm; /* high middle byte of l.b.a. */
212 u_char lbalm; /* low middle byte of l.b.a. */
213 u_char lbal; /* lsb of l.b.a. */
214 u_char reserved;
215 u_char lenh; /* msb transfer length */
216 u_char lenl; /* lsb transfer length */
217 u_char xtra;
218 };
219
220 /* basic sense data */
221
222 struct scsi_sense {
223 u_char valid: 1, /* l.b.a. is valid */
224 class: 3,
225 code: 4;
226 u_char vu: 4, /* vendor unique */
227 lbah: 4;
228 u_char lbam;
229 u_char lbal;
230 };
231
232 struct scsi_xsense {
233 u_char valid: 1, /* l.b.a. is valid */
234 class: 3,
235 code: 4;
236 u_char segment;
237 u_char filemark: 1,
238 eom: 1,
239 ili: 1, /* illegal length indicator */
240 rsvd: 1,
241 key: 4;
242 u_char info1;
243 u_char info2;
244 u_char info3;
245 u_char info4;
246 u_char len; /* additional sense length */
247 };
248
249 /* inquiry data */
250 struct scsi_inquiry {
251 u_char type;
252 u_char qual;
253 u_char version;
254 u_char rsvd;
255 u_char len;
256 char class[3];
257 char vendor_id[8];
258 char product_id[16];
259 char rev[4];
260 };
261
262 struct scsi_format_parms { /* physical BFI format */
263 u_short reserved;
264 u_short list_len;
265 struct defect {
266 unsigned cyl : 24;
267 unsigned head : 8;
268 long bytes_from_index;
269 } defect[127];
270 } format_parms;
271
272 struct scsi_reassign_parms {
273 u_short reserved;
274 u_short list_len; /* length in bytes of defects only */
275 struct new_defect {
276 unsigned lba; /* logical block address */
277 } new_defect[2];
278 } reassign_parms;
279
280 struct scsi_modesel_hdr {
281 u_char rsvd1;
282 u_char media_type;
283 u_char rsvd2;
284 u_char block_desc_len;
285 u_int density : 8;
286 u_int number_blocks :24;
287 u_int rsvd3 : 8;
288 u_int block_length :24;
289 };
290
291 struct scsi_modesense_hdr {
292 u_char len;
293 u_char media_type;
294 u_char wp : 1;
295 u_char rsvd1 : 7;
296 u_char block_desc_len;
297 u_int density : 8;
298 u_int number_blocks :24;
299 u_int rsvd2 : 8;
300 u_int block_length :24;
301 };
302
303 /*
304 * Mode Select / Mode sense "pages"
305 */
306
307 /*
308 * Page One - Error Recovery Parameters
309 */
310 struct scsi_err_recovery {
311 u_char page_savable : 1; /* save parameters */
312 u_char reserved : 1;
313 u_char page_code : 6; /* = 0x01 */
314 u_char page_length; /* = 6 */
315 u_char awre : 1; /* auto write realloc enabled */
316 u_char arre : 1; /* auto read realloc enabled */
317 u_char tb : 1; /* transfer block */
318 u_char rc : 1; /* read continuous */
319 u_char eec : 1; /* enable early correction */
320 u_char per : 1; /* post error */
321 u_char dte : 1; /* disable transfer on error */
322 u_char dcr : 1; /* disable correction */
323 u_char retry_count;
324 u_char correction_span;
325 u_char head_offset_count;
326 u_char strobe_offset_count;
327 u_char recovery_time_limit;
328 };
329
330 /*
331 * Page Two - Disconnect / Reconnect Control Parameters
332 */
333 struct scsi_disco_reco {
334 u_char page_savable : 1; /* save parameters */
335 u_char rsvd : 1;
336 u_char page_code : 6; /* = 0x02 */
337 u_char page_length; /* = 10 */
338 u_char buffer_full_ratio; /* write, how full before reconnect? */
339 u_char buffer_empty_ratio; /* read, how full before reconnect? */
340
341 u_short bus_inactivity_limit; /* how much bus time for busy */
342 u_short disconnect_time_limit; /* min to remain disconnected */
343 u_short connect_time_limit; /* min to remain connected */
344 u_short reserved_1;
345 };
346
347 /*
348 * Page Three - Direct Access Device Format Parameters
349 */
350 struct scsi_format {
351 u_char page_savable : 1; /* save parameters */
352 u_char rsvd : 1;
353 u_char page_code : 6; /* = 0x03 */
354 u_char page_length; /* = 22 */
355 u_short tracks_per_zone; /* Handling of Defects Fields */
356 u_short alt_sect_zone;
357 u_short alt_tracks_zone;
358 u_short alt_tracks_vol;
359 u_short sect_track; /* Track Format Field */
360 u_short data_sect; /* Sector Format Fields */
361 u_short interleave;
362 u_short track_skew_factor;
363 u_short cyl_skew_factor;
364 u_char ssec : 1; /* Drive Type Field */
365 u_char hsec : 1;
366 u_char rmb : 1;
367 u_char surf : 1;
368 u_char ins : 1;
369 u_char reserved_1 : 3;
370 u_char reserved_2;
371 u_char reserved_3;
372 u_char reserved_4;
373 };
374
375 /*
376 * Page Four - Rigid Disk Drive Geometry Parameters
377 */
378 struct scsi_geometry {
379 u_char page_savable : 1; /* save parameters */
380 u_char rsvd : 1;
381 u_char page_code : 6; /* = 0x04 */
382 u_char page_length; /* = 18 */
383 u_char cyl_ub; /* number of cylinders */
384 u_char cyl_mb;
385 u_char cyl_lb;
386 u_char heads; /* number of heads */
387 u_char precomp_cyl_ub; /* cylinder to start precomp */
388 u_char precomp_cyl_mb;
389 u_char precomp_cyl_lb;
390 u_char current_cyl_ub; /* cyl to start reduced current */
391 u_char current_cyl_mb;
392 u_char current_cyl_lb;
393 u_short step_rate; /* drive step rate */
394 u_char landing_cyl_ub; /* landing zone cylinder */
395 u_char landing_cyl_mb;
396 u_char landing_cyl_lb;
397 u_char reserved_1;
398 u_char reserved_2;
399 u_char reserved_3;
400 };
401
402 /*
403 * Page 0x38 - Cache Control Parameters
404 */
405 struct scsi_cache {
406 u_char page_savable : 1; /* save parameters */
407 u_char rsvd : 1;
408 u_char page_code : 6; /* = 0x38 */
409 u_char page_length; /* = 14 */
410 u_char rsvd_1 : 1;
411 u_char wie : 1; /* write index enable */
412 u_char rsvd_2 : 1;
413 u_char ce : 1; /* cache enable */
414 u_char table_size : 4;
415 u_char prefetch_threshold;
416 u_char maximum_threshold;
417 u_char maximumprefetch_multiplier;
418 u_char minimum_threshold;
419 u_char minimum_prefetch_multiplier;
420 u_char reserved[8];
421 };
422
423 /*
424 * Driver ioctl's for various scsi operations.
425 */
426 #ifndef _IOCTL_
427 #if 0
428 #include <sys/ioctl.h>
429 #endif
430 #endif
431
432 /*
433 * Control for SCSI "format" mode.
434 *
435 * "Format" mode allows a privileged process to issue direct SCSI
436 * commands to a drive (it is intended primarily to allow on-line
437 * formatting). SDIOCSFORMAT with a non-zero arg will put the drive
438 * into format mode; a zero arg will take it out. When in format
439 * mode, only the process that issued the SDIOCFORMAT can read or
440 * write the drive.
441 *
442 * In format mode, process is expected to
443 * - do SDIOCSCSICOMMAND to supply cdb for next SCSI op
444 * - do read or write as appropriate for cdb
445 * - if i/o error, optionally do SDIOCSENSE to get completion
446 * status and sense data from last scsi operation.
447 */
448
449 struct scsi_fmt_cdb {
450 int len; /* cdb length (in bytes) */
451 u_char cdb[28]; /* cdb to use on next read/write */
452 };
453
454 struct scsi_fmt_sense {
455 u_int status; /* completion status of last op */
456 u_char sense[28]; /* sense data (if any) from last op */
457 };
458
459 #define SDIOCSFORMAT _IOW('S', 0x1, int)
460 #define SDIOCGFORMAT _IOR('S', 0x2, int)
461 #define SDIOCSCSICOMMAND _IOW('S', 0x3, struct scsi_fmt_cdb)
462 #define SDIOCSENSE _IOR('S', 0x4, struct scsi_fmt_sense)
463