Annotation of sys/scsi/scsiconf.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: scsiconf.h,v 1.87 2007/06/23 19:19:49 krw Exp $ */
2: /* $NetBSD: scsiconf.h,v 1.35 1997/04/02 02:29:38 mycroft Exp $ */
3:
4: /*
5: * Copyright (c) 1993, 1994, 1995 Charles Hannum. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by Charles Hannum.
18: * 4. The name of the author may not be used to endorse or promote products
19: * derived from this software without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31: */
32:
33: /*
34: * Originally written by Julian Elischer (julian@tfs.com)
35: * for TRW Financial Systems for use under the MACH(2.5) operating system.
36: *
37: * TRW Financial Systems, in accordance with their agreement with Carnegie
38: * Mellon University, makes this software available to CMU to distribute
39: * or use in any manner that they see fit as long as this message is kept with
40: * the software. For this reason TFS also grants any other persons or
41: * organisations permission to use or modify this software.
42: *
43: * TFS supplies this software to be publicly redistributed
44: * on the understanding that TFS is not responsible for the correct
45: * functioning of this software in any circumstances.
46: *
47: * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
48: */
49:
50: #ifndef SCSI_SCSICONF_H
51: #define SCSI_SCSICONF_H 1
52:
53: #include <sys/queue.h>
54: #include <sys/timeout.h>
55: #include <sys/workq.h>
56: #include <machine/cpu.h>
57: #include <scsi/scsi_debug.h>
58:
59: /*
60: * The following documentation tries to describe the relationship between the
61: * various structures defined in this file:
62: *
63: * each adapter type has a scsi_adapter struct. This describes the adapter and
64: * identifies routines that can be called to use the adapter.
65: * each device type has a scsi_device struct. This describes the device and
66: * identifies routines that can be called to use the device.
67: * each existing device position (scsibus + target + lun)
68: * can be described by a scsi_link struct.
69: * Only scsi positions that actually have devices, have a scsi_link
70: * structure assigned. so in effect each device has scsi_link struct.
71: * The scsi_link structure contains information identifying both the
72: * device driver and the adapter driver for that position on that scsi bus,
73: * and can be said to 'link' the two.
74: * each individual scsi bus has an array that points to all the scsi_link
75: * structs associated with that scsi bus. Slots with no device have
76: * a NULL pointer.
77: * each individual device also knows the address of its own scsi_link
78: * structure.
79: *
80: * -------------
81: *
82: * The key to all this is the scsi_link structure which associates all the
83: * other structures with each other in the correct configuration. The
84: * scsi_link is the connecting information that allows each part of the
85: * scsi system to find the associated other parts.
86: */
87:
88: struct buf;
89: struct scsi_xfer;
90: struct scsi_link;
91:
92: /*
93: * Temporary hack
94: */
95: extern int scsi_autoconf;
96:
97: /*
98: * These entrypoints are called by the high-end drivers to get services from
99: * whatever low-end drivers they are attached to. Each adapter type has one
100: * of these statically allocated.
101: */
102: struct scsi_adapter {
103: int (*scsi_cmd)(struct scsi_xfer *);
104: void (*scsi_minphys)(struct buf *);
105: int (*open_target_lu)(void);
106: int (*close_target_lu)(void);
107: int (*ioctl)(struct scsi_link *, u_long, caddr_t, int,
108: struct proc *);
109: };
110:
111: /*
112: * return values for scsi_cmd()
113: */
114: #define SUCCESSFULLY_QUEUED 0
115: #define TRY_AGAIN_LATER 1
116: #define COMPLETE 2
117: #define ESCAPE_NOT_SUPPORTED 3
118: #define NO_CCB 4
119:
120: /*
121: * These entry points are called by the low-end drivers to get services from
122: * whatever high-end drivers they are attached to. Each device type has one
123: * of these statically allocated.
124: */
125: struct scsi_device {
126: int (*err_handler)(struct scsi_xfer *);
127: /* returns -1 to say err processing done */
128: void (*start)(void *);
129:
130: int (*async)(void);
131: void (*done)(struct scsi_xfer *);
132: };
133:
134: /*
135: * This structure describes the connection between an adapter driver and
136: * a device driver, and is used by each to call services provided by
137: * the other, and to allow generic scsi glue code to call these services
138: * as well.
139: */
140: struct scsi_link {
141: u_int8_t scsibus; /* the Nth scsibus */
142: u_int8_t luns;
143: u_int16_t target; /* targ of this dev */
144: u_int16_t lun; /* lun of this dev */
145: u_int16_t openings; /* available operations */
146: u_int64_t port_wwn; /* world wide name of port */
147: u_int64_t node_wwn; /* world wide name of node */
148: u_int16_t adapter_target; /* what are we on the scsi bus */
149: u_int16_t adapter_buswidth; /* 8 (regular) or 16 (wide). (0 becomes 8) */
150: u_int16_t active; /* operations in progress */
151: u_int16_t flags; /* flags that all devices have */
152: #define SDEV_REMOVABLE 0x0001 /* media is removable */
153: #define SDEV_MEDIA_LOADED 0x0002 /* device figures are still valid */
154: #define SDEV_WAITING 0x0004 /* a process is waiting for this */
155: #define SDEV_OPEN 0x0008 /* at least 1 open session */
156: #define SDEV_DBX 0x00f0 /* debugging flags (scsi_debug.h) */
157: #define SDEV_EJECTING 0x0100 /* eject on device close */
158: #define SDEV_ATAPI 0x0200 /* device is ATAPI */
159: #define SDEV_2NDBUS 0x0400 /* device is a 'second' bus device */
160: #define SDEV_UMASS 0x0800 /* device is UMASS SCSI */
161: #define SDEV_VIRTUAL 0x1000 /* device is virtualised on the hba */
162: u_int16_t quirks; /* per-device oddities */
163: #define SDEV_AUTOSAVE 0x0001 /* do implicit SAVEDATAPOINTER on disconnect */
164: #define SDEV_NOSYNC 0x0002 /* does not grok SDTR */
165: #define SDEV_NOWIDE 0x0004 /* does not grok WDTR */
166: #define SDEV_NOTAGS 0x0008 /* lies about having tagged queueing */
167: #define SDEV_NOSYNCCACHE 0x0100 /* no SYNCHRONIZE_CACHE */
168: #define ADEV_NOSENSE 0x0200 /* No request sense - ATAPI */
169: #define ADEV_LITTLETOC 0x0400 /* little-endian TOC - ATAPI */
170: #define ADEV_NOCAPACITY 0x0800 /* no READ CD CAPACITY */
171: #define ADEV_NOTUR 0x1000 /* No TEST UNIT READY */
172: #define ADEV_NODOORLOCK 0x2000 /* can't lock door */
173: #define SDEV_ONLYBIG 0x4000 /* always use READ_BIG and WRITE_BIG */
174: struct scsi_device *device; /* device entry points etc. */
175: void *device_softc; /* needed for call to foo_start */
176: struct scsi_adapter *adapter; /* adapter entry points etc. */
177: void *adapter_softc; /* needed for call to foo_scsi_cmd */
178: struct scsi_inquiry_data inqdata; /* copy of INQUIRY data from probe */
179: };
180:
181: int scsiprint(void *, const char *);
182:
183: /*
184: * This describes matching information for scsi_inqmatch(). The more things
185: * match, the higher the configuration priority.
186: */
187: struct scsi_inquiry_pattern {
188: u_int8_t type;
189: int removable;
190: char *vendor;
191: char *product;
192: char *revision;
193: };
194:
195: struct scsibus_attach_args {
196: struct scsi_link *saa_sc_link;
197: };
198:
199: /*
200: * One of these is allocated and filled in for each scsi bus.
201: * It holds pointers to allow the scsi bus to get to the driver
202: * that is running each LUN on the bus.
203: * It also has a template entry which is the prototype struct
204: * supplied by the adapter driver. This is used to initialise
205: * the others, before they have the rest of the fields filled in.
206: */
207: struct scsibus_softc {
208: struct device sc_dev;
209: struct scsi_link *adapter_link; /* prototype supplied by adapter */
210: struct scsi_link ***sc_link;
211: u_int16_t sc_buswidth;
212: };
213:
214: /*
215: * This is used to pass information from the high-level configuration code
216: * to the device-specific drivers.
217: */
218: struct scsi_attach_args {
219: struct scsi_link *sa_sc_link;
220: struct scsi_inquiry_data *sa_inqbuf;
221: };
222:
223: /*
224: * Each scsi transaction is fully described by one of these structures.
225: * It includes information about the source of the command and also the
226: * device and adapter for which the command is destined.
227: * (via the scsi_link structure)
228: */
229: struct scsi_xfer {
230: LIST_ENTRY(scsi_xfer) free_list;
231: int flags;
232: struct scsi_link *sc_link; /* all about our device and adapter */
233: int retries; /* the number of times to retry */
234: int timeout; /* in milliseconds */
235: struct scsi_generic *cmd; /* The scsi command to execute */
236: int cmdlen; /* how long it is */
237: u_char *data; /* dma address OR a uio address */
238: int datalen; /* data len (blank if uio) */
239: size_t resid; /* how much buffer was not touched */
240: int error; /* an error value */
241: struct buf *bp; /* If we need to associate with a buf */
242: struct scsi_sense_data sense; /* 32 bytes*/
243: /*
244: * Believe it or not, Some targets fall on the ground with
245: * anything but a certain sense length.
246: */
247: int req_sense_length; /* Explicit request sense length */
248: u_int8_t status; /* SCSI status */
249: struct scsi_generic cmdstore; /* stash the command in here */
250: /*
251: * timeout structure for hba's to use for a command
252: */
253: struct timeout stimeout;
254: };
255:
256: /*
257: * Per-request Flag values
258: */
259: #define SCSI_NOSLEEP 0x00001 /* don't sleep */
260: #define SCSI_POLL 0x00002 /* poll for completion */
261: #define SCSI_AUTOCONF 0x00003 /* shorthand for SCSI_POLL | SCSI_NOSLEEP */
262: #define SCSI_USER 0x00004 /* Is a user cmd, call scsi_user_done */
263: #define ITSDONE 0x00008 /* the transfer is as done as it gets */
264: #define SCSI_SILENT 0x00020 /* don't announce NOT READY or MEDIA CHANGE */
265: #define SCSI_IGNORE_NOT_READY 0x00040 /* ignore NOT READY */
266: #define SCSI_IGNORE_MEDIA_CHANGE 0x00080 /* ignore MEDIA CHANGE */
267: #define SCSI_IGNORE_ILLEGAL_REQUEST 0x00100 /* ignore ILLEGAL REQUEST */
268: #define SCSI_RESET 0x00200 /* Reset the device in question */
269: #define SCSI_DATA_UIO 0x00400 /* The data address refers to a UIO */
270: #define SCSI_DATA_IN 0x00800 /* expect data to come INTO memory */
271: #define SCSI_DATA_OUT 0x01000 /* expect data to flow OUT of memory */
272: #define SCSI_TARGET 0x02000 /* This defines a TARGET mode op. */
273: #define SCSI_ESCAPE 0x04000 /* Escape operation */
274: #define SCSI_URGENT 0x08000 /* Urgent operation (e.g., HTAG) */
275: #define SCSI_PRIVATE 0xf0000 /* private to each HBA flags */
276:
277: /*
278: * Escape op-codes. This provides an extensible setup for operations
279: * that are not scsi commands. They are intended for modal operations.
280: */
281:
282: #define SCSI_OP_TARGET 0x0001
283: #define SCSI_OP_RESET 0x0002
284: #define SCSI_OP_BDINFO 0x0003
285:
286: /*
287: * Error values an adapter driver may return
288: */
289: #define XS_NOERROR 0 /* there is no error, (sense is invalid) */
290: #define XS_SENSE 1 /* Check the returned sense for the error */
291: #define XS_DRIVER_STUFFUP 2 /* Driver failed to perform operation */
292: #define XS_SELTIMEOUT 3 /* The device timed out.. turned off? */
293: #define XS_TIMEOUT 4 /* The Timeout reported was caught by SW */
294: #define XS_BUSY 5 /* The device busy, try again later? */
295: #define XS_SHORTSENSE 6 /* Check the ATAPI sense for the error */
296: #define XS_RESET 8 /* bus was reset; possible retry command */
297:
298: /*
299: * Possible retries numbers for scsi_test_unit_ready()
300: */
301: #define TEST_READY_RETRIES 5
302:
303: const void *scsi_inqmatch(struct scsi_inquiry_data *, const void *, int,
304: int, int *);
305:
306: #define scsi_task(_f, _a1, _a2, _fl) \
307: workq_add_task(NULL, (_fl), (_f), (_a1), (_a2))
308:
309: void scsi_init(void);
310: void scsi_deinit(void);
311: struct scsi_xfer *
312: scsi_get_xs(struct scsi_link *, int);
313: void scsi_free_xs(struct scsi_xfer *, int);
314: int scsi_execute_xs(struct scsi_xfer *);
315: daddr64_t scsi_size(struct scsi_link *, int, u_int32_t *);
316: int scsi_test_unit_ready(struct scsi_link *, int, int);
317: int scsi_inquire(struct scsi_link *, struct scsi_inquiry_data *, int);
318: int scsi_inquire_vpd(struct scsi_link *, void *, u_int, u_int8_t, int);
319: int scsi_prevent(struct scsi_link *, int, int);
320: int scsi_start(struct scsi_link *, int, int);
321: int scsi_mode_sense(struct scsi_link *, int, int, struct scsi_mode_header *,
322: size_t, int, int);
323: int scsi_mode_sense_big(struct scsi_link *, int, int,
324: struct scsi_mode_header_big *, size_t, int, int);
325: void * scsi_mode_sense_page(struct scsi_mode_header *, int);
326: void * scsi_mode_sense_big_page(struct scsi_mode_header_big *, int);
327: int scsi_do_mode_sense(struct scsi_link *, int,
328: union scsi_mode_sense_buf *, void **, u_int32_t *, u_int64_t *,
329: u_int32_t *, int, int, int *);
330: int scsi_mode_select(struct scsi_link *, int, struct scsi_mode_header *,
331: int, int);
332: int scsi_mode_select_big(struct scsi_link *, int,
333: struct scsi_mode_header_big *, int, int);
334: void scsi_done(struct scsi_xfer *);
335: void scsi_user_done(struct scsi_xfer *);
336: int scsi_scsi_cmd(struct scsi_link *, struct scsi_generic *,
337: int cmdlen, u_char *data_addr, int datalen, int retries,
338: int timeout, struct buf *bp, int flags);
339: int scsi_do_ioctl(struct scsi_link *, dev_t, u_long, caddr_t,
340: int, struct proc *);
341: void sc_print_addr(struct scsi_link *);
342: int scsi_report_luns(struct scsi_link *, int,
343: struct scsi_report_luns_data *, u_int32_t, int, int);
344:
345: void show_scsi_xs(struct scsi_xfer *);
346: void scsi_print_sense(struct scsi_xfer *);
347: void show_scsi_cmd(struct scsi_xfer *);
348: void show_mem(u_char *, int);
349: void scsi_strvis(u_char *, u_char *, int);
350: int scsi_delay(struct scsi_xfer *, int);
351:
352: int scsi_probe_bus(struct scsibus_softc *);
353: int scsi_probe_target(struct scsibus_softc *, int);
354: int scsi_probe_lun(struct scsibus_softc *, int, int);
355:
356: int scsi_detach_bus(struct scsibus_softc *, int);
357: int scsi_detach_target(struct scsibus_softc *, int, int);
358: int scsi_detach_lun(struct scsibus_softc *, int, int, int);
359:
360: static __inline void _lto2b(u_int32_t val, u_int8_t *bytes);
361: static __inline void _lto3b(u_int32_t val, u_int8_t *bytes);
362: static __inline void _lto4b(u_int32_t val, u_int8_t *bytes);
363: static __inline void _lto8b(u_int64_t val, u_int8_t *bytes);
364: static __inline u_int32_t _2btol(u_int8_t *bytes);
365: static __inline u_int32_t _3btol(u_int8_t *bytes);
366: static __inline u_int32_t _4btol(u_int8_t *bytes);
367: static __inline u_int64_t _5btol(u_int8_t *bytes);
368: static __inline u_int64_t _8btol(u_int8_t *bytes);
369:
370: static __inline void _lto2l(u_int32_t val, u_int8_t *bytes);
371: static __inline void _lto3l(u_int32_t val, u_int8_t *bytes);
372: static __inline void _lto4l(u_int32_t val, u_int8_t *bytes);
373: static __inline u_int32_t _2ltol(u_int8_t *bytes);
374: static __inline u_int32_t _3ltol(u_int8_t *bytes);
375: static __inline u_int32_t _4ltol(u_int8_t *bytes);
376:
377: static __inline void
378: _lto2b(val, bytes)
379: u_int32_t val;
380: u_int8_t *bytes;
381: {
382:
383: bytes[0] = (val >> 8) & 0xff;
384: bytes[1] = val & 0xff;
385: }
386:
387: static __inline void
388: _lto3b(val, bytes)
389: u_int32_t val;
390: u_int8_t *bytes;
391: {
392:
393: bytes[0] = (val >> 16) & 0xff;
394: bytes[1] = (val >> 8) & 0xff;
395: bytes[2] = val & 0xff;
396: }
397:
398: static __inline void
399: _lto4b(val, bytes)
400: u_int32_t val;
401: u_int8_t *bytes;
402: {
403:
404: bytes[0] = (val >> 24) & 0xff;
405: bytes[1] = (val >> 16) & 0xff;
406: bytes[2] = (val >> 8) & 0xff;
407: bytes[3] = val & 0xff;
408: }
409:
410: static __inline void
411: _lto8b(val, bytes)
412: u_int64_t val;
413: u_int8_t *bytes;
414: {
415:
416: bytes[0] = (val >> 56) & 0xff;
417: bytes[1] = (val >> 48) & 0xff;
418: bytes[2] = (val >> 40) & 0xff;
419: bytes[3] = (val >> 32) & 0xff;
420: bytes[4] = (val >> 24) & 0xff;
421: bytes[5] = (val >> 16) & 0xff;
422: bytes[6] = (val >> 8) & 0xff;
423: bytes[7] = val & 0xff;
424: }
425:
426: static __inline u_int32_t
427: _2btol(bytes)
428: u_int8_t *bytes;
429: {
430: u_int32_t rv;
431:
432: rv = (bytes[0] << 8) | bytes[1];
433: return (rv);
434: }
435:
436: static __inline u_int32_t
437: _3btol(bytes)
438: u_int8_t *bytes;
439: {
440: u_int32_t rv;
441:
442: rv = (bytes[0] << 16) | (bytes[1] << 8) | bytes[2];
443: return (rv);
444: }
445:
446: static __inline u_int32_t
447: _4btol(bytes)
448: u_int8_t *bytes;
449: {
450: u_int32_t rv;
451:
452: rv = (bytes[0] << 24) | (bytes[1] << 16) |
453: (bytes[2] << 8) | bytes[3];
454: return (rv);
455: }
456:
457: static __inline u_int64_t
458: _5btol(bytes)
459: u_int8_t *bytes;
460: {
461: u_int64_t rv;
462:
463: rv = ((u_int64_t)bytes[0] << 32) |
464: ((u_int64_t)bytes[1] << 24) |
465: ((u_int64_t)bytes[2] << 16) |
466: ((u_int64_t)bytes[3] << 8) |
467: (u_int64_t)bytes[4];
468: return (rv);
469: }
470:
471: static __inline u_int64_t
472: _8btol(bytes)
473: u_int8_t *bytes;
474: {
475: u_int64_t rv;
476:
477: rv = (((u_int64_t)bytes[0]) << 56) |
478: (((u_int64_t)bytes[1]) << 48) |
479: (((u_int64_t)bytes[2]) << 40) |
480: (((u_int64_t)bytes[3]) << 32) |
481: (((u_int64_t)bytes[4]) << 24) |
482: (((u_int64_t)bytes[5]) << 16) |
483: (((u_int64_t)bytes[6]) << 8) |
484: ((u_int64_t)bytes[7]);
485: return (rv);
486: }
487:
488: static __inline void
489: _lto2l(val, bytes)
490: u_int32_t val;
491: u_int8_t *bytes;
492: {
493:
494: bytes[0] = val & 0xff;
495: bytes[1] = (val >> 8) & 0xff;
496: }
497:
498: static __inline void
499: _lto3l(val, bytes)
500: u_int32_t val;
501: u_int8_t *bytes;
502: {
503:
504: bytes[0] = val & 0xff;
505: bytes[1] = (val >> 8) & 0xff;
506: bytes[2] = (val >> 16) & 0xff;
507: }
508:
509: static __inline void
510: _lto4l(val, bytes)
511: u_int32_t val;
512: u_int8_t *bytes;
513: {
514:
515: bytes[0] = val & 0xff;
516: bytes[1] = (val >> 8) & 0xff;
517: bytes[2] = (val >> 16) & 0xff;
518: bytes[3] = (val >> 24) & 0xff;
519: }
520:
521: static __inline u_int32_t
522: _2ltol(bytes)
523: u_int8_t *bytes;
524: {
525: u_int32_t rv;
526:
527: rv = bytes[0] | (bytes[1] << 8);
528: return (rv);
529: }
530:
531: static __inline u_int32_t
532: _3ltol(bytes)
533: u_int8_t *bytes;
534: {
535: u_int32_t rv;
536:
537: rv = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16);
538: return (rv);
539: }
540:
541: static __inline u_int32_t
542: _4ltol(bytes)
543: u_int8_t *bytes;
544: {
545: u_int32_t rv;
546:
547: rv = bytes[0] | (bytes[1] << 8) |
548: (bytes[2] << 16) | (bytes[3] << 24);
549: return (rv);
550: }
551:
552: extern const u_int8_t version_to_spc [];
553: #define SCSISPC(x)(version_to_spc[(x) & SID_ANSII])
554:
555: #endif /* SCSI_SCSICONF_H */
CVSweb