Imported Upstream version 2.5.1
[debian/amanda] / contrib / sst / sst_def.h
1 /*
2  * Copyright (c) 1997, by Sun Microsystems, Inc.
3  * All Rights Reserved
4  */
5
6 /*
7  * This file is a product of Sun Microsystems, Inc. and is provided for
8  * unrestricted use provided that this legend is included on all tape
9  * media and as a part of the software program in whole or part.  Users
10  * may copy or modify this file without charge, but are not authorized to
11  * license or distribute it to anyone else except as part of a product
12  * or program developed by the user.
13  *
14  * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
15  * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
17  *
18  * This file is provided with no support and without any obligation on the
19  * part of Sun Microsystems, Inc. to assist in its use, correction,
20  * modification or enhancement.
21  *
22  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
23  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
24  * OR ANY PART THEREOF.
25  *
26  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
27  * or profits or other special, indirect and consequential damages, even
28  * if Sun has been advised of the possibility of such damages.
29  *
30  * Sun Microsystems, Inc.
31  * 2550 Garcia Avenue
32  * Mountain View, California  94043
33  */
34
35 /*
36  * Defines and structures used only within the driver, sst.c
37  */
38
39 #ifndef _SST_DEF_H
40 #define _SST_DEF_H
41
42 #pragma ident   "@(#)sst_def.h  1.13    97/10/02 SMI"
43
44 #ifdef  __cplusplus
45 extern "C" {
46 #endif
47
48 #if     defined(_KERNEL) || defined(_KMEMUSER)
49
50 #include <sys/note.h>
51
52 /*
53  * Driver compile options
54  */
55
56 /*
57  * This driver does not reset the SCSI bus. Instead we just give up
58  * and complain if the target hangs. If the bus is really stuck, one
59  * of the Sun drivers (e.g. sd) will reset it. If you decide that
60  * your device is critical and you should in fact reset the bus in
61  * this driver, turn on this define below:
62 #define SCSI_BUS_RESET
63  */
64
65 /*
66  * Local definitions, for clarity of code
67  */
68 #define SST_DEVINFO(t)  (((t)->targ_devp)->sd_dev)
69 #define SST_MUTEX(t)    (&((t)->targ_devp)->sd_mutex)
70 #define ROUTE(t)        (&((t)->targ_devp)->sd_address)
71
72 #define SCBP(pkt)       ((struct scsi_status *)(pkt)->pkt_scbp)
73 #define SCBP_C(pkt)     ((*(pkt)->pkt_scbp) & STATUS_MASK)
74 #define CDBP(pkt)       ((union scsi_cdb *)(pkt)->pkt_cdbp)
75
76 #define SST_CE_DEBUG1   ((1 << 8) | CE_CONT)
77 #define SST_CE_DEBUG2   ((2 << 8) | CE_CONT)
78 #define SST_CE_DEBUG3   ((3 << 8) | CE_CONT)
79 #define SST_CE_DEBUG4   ((4 << 8) | CE_CONT)
80 #define SST_LOG         if (sst_debug) sst_log
81 #define SST_DEBUG_ENTER if (sst_debug) debug_enter
82
83
84 /*
85  * Private info for scsi targets.
86  *
87  * Pointed to by the un_private pointer
88  * of one of the SCSI_DEVICE structures.
89  */
90 struct scsi_target {
91         struct scsi_pkt *targ_rqs;      /* ptr to request sense command pkt */
92         struct scsi_pkt *targ_pkt;      /* ptr to current command pkt */
93         struct  buf     *targ_sbufp;    /* for use in special io */
94         kcondvar_t      targ_sbuf_cv;   /* conditional variable for sbufp */
95         kcondvar_t      targ_pkt_cv;    /* conditional variable for pkt */
96         kcondvar_t      targ_suspend_cv; /* conditional variable for  */
97                                         /* suspended state */
98         int             targ_sbuf_busy; /* Wait Variable */
99         int             targ_pkt_busy;  /* Wait Variable */
100         int             targ_retry_ct;  /* retry count */
101         u_int           targ_state;     /* current state */
102         u_int           targ_arq;       /* ARQ mode on this tgt */
103         struct scsi_device *targ_devp; /* back pointer to SCSI_DEVICE */
104         struct buf      *targ_rqbp;     /* buf for Request Sense packet */
105         int             targ_suspended; /* suspend/resume */
106         int             targ_pm_suspended; /* power management suspend */
107         int             targ_power_level; /* PM power level */
108 };
109
110 _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, scsi_target))
111
112 struct sst_private {
113         struct buf      *priv_bp;       /* bp associated with this packet */
114         /*
115          * To handle partial DMA mappings, target may need several
116          * SCSI commands to satisfy packet.  Keep track of remaining
117          * data in this packet in the following two fields.
118          */
119         u_int           priv_amt;       /* bytes requested in this chunk */
120         u_int           priv_amtdone;   /* bytes done so far in current pkt */
121 };
122
123 _NOTE(DATA_READABLE_WITHOUT_LOCK(scsi_target::{targ_devp targ_rqs
124         targ_state targ_sbufp targ_arq}))
125
126 _NOTE(SCHEME_PROTECTS_DATA("stable data",
127         scsi_device))
128
129 _NOTE(SCHEME_PROTECTS_DATA("Unshared data",
130         scsi_target::targ_pkt scsi_arq_status scsi_status
131         buf scsi_pkt sst_private uio uscsi_cmd scsi_cdb))
132
133 /*
134  * Driver states
135  */
136 #define SST_STATE_NIL           0
137 #define SST_STATE_CLOSED        1
138 #define SST_STATE_OPEN          2
139
140 /*
141  * Parameters
142  */
143
144 #define SST_IO_TIME     30      /* default command timeout, 30sec */
145
146 /*
147  * 5 seconds is what we'll wait if we get a Busy Status back
148  */
149 #define SST_BSY_TIMEOUT         (drv_usectohz(5 * 1000000))
150
151 /*
152  * Number of times we'll retry a normal operation.
153  *
154  * This includes retries due to transport failure
155  * (need to distinguish between Target and Transport failure)
156  */
157 #define SST_RETRY_COUNT         30
158
159 /*
160  * sst_callback action codes
161  */
162 #define COMMAND_DONE            0
163 #define COMMAND_DONE_ERROR      1
164 #define QUE_COMMAND             2
165 #define QUE_SENSE               3
166 #define JUST_RETURN             4
167 #define CONTINUE_PKT            5
168
169 /*
170  * Special pkt flag just for this driver.
171  * NB: Other pkt_flags defines are in scsi_pkt.h.
172  */
173 #define FLAG_SENSING    0x0400  /* Running request sense for failed pkt */
174
175 #endif  /* defined(_KERNEL) || defined(_KMEMUSER) */
176
177 /*
178  * Ioctl commands
179  */
180 #define SSTIOC          ('S' << 8)
181 #define SSTIOC_READY    (SSTIOC|0)      /* Send a Test Unit Ready command */
182 #define SSTIOC_ERRLEV   (SSTIOC|1)      /* Set Error Reporting level */
183
184
185
186 #if defined(_SYSCALL32)
187
188 /*
189  * This is an example of how to support a 32-bit application issuing
190  * an ILP32 ioctl into a 64-bit driver.  Using fixed data-size
191  * types, define a 32-bit version of the data structure as used
192  * by the ioctl, along with functions or macros to convert between
193  * the ILP32 and LP64 models.  The LP64 driver can then use
194  * ddi_copyin/ddi_copyout to access the application's copy of
195  * the data structure, but internally use the usual ILP32 or
196  * LP64 model, as compiled.
197  */
198 struct sst_uscsi_cmd32 {
199         int             uscsi_flags;    /* read, write, etc. see below */
200         short           uscsi_status;   /* resulting status  */
201         short           uscsi_timeout;  /* Command Timeout */
202         caddr32_t       uscsi_cdb;      /* cdb to send to target */
203         caddr32_t       uscsi_bufaddr;  /* i/o source/destination */
204         size32_t        uscsi_buflen;   /* size of i/o to take place */
205         size32_t        uscsi_resid;    /* resid from i/o operation */
206         u_char          uscsi_cdblen;   /* # of valid cdb bytes */
207         u_char          uscsi_rqlen;    /* size of uscsi_rqbuf */
208         u_char          uscsi_rqstatus; /* status of request sense cmd */
209         u_char          uscsi_rqresid;  /* resid of request sense cmd */
210         caddr32_t       uscsi_rqbuf;    /* request sense buffer */
211         caddr32_t       uscsi_reserved_5;       /* Reserved for Future Use */
212 };
213
214
215 /*
216  * Convert application's ILP32 uscsi_cmd to LP64
217  */
218 #define sst_uscsi_cmd32touscsi_cmd(u32, ucmd)                           \
219         ucmd->uscsi_flags       = u32->uscsi_flags;                     \
220         ucmd->uscsi_status      = u32->uscsi_status;                    \
221         ucmd->uscsi_timeout     = u32->uscsi_timeout;                   \
222         ucmd->uscsi_cdb         = (caddr_t)u32->uscsi_cdb;              \
223         ucmd->uscsi_bufaddr     = (caddr_t)u32->uscsi_bufaddr;          \
224         ucmd->uscsi_buflen      = (size_t)u32->uscsi_buflen;            \
225         ucmd->uscsi_resid       = (size_t)u32->uscsi_resid;             \
226         ucmd->uscsi_cdblen      = u32->uscsi_cdblen;                    \
227         ucmd->uscsi_rqlen       = u32->uscsi_rqlen;                     \
228         ucmd->uscsi_rqstatus    = u32->uscsi_rqstatus;                  \
229         ucmd->uscsi_rqresid     = u32->uscsi_rqresid;                   \
230         ucmd->uscsi_rqbuf       = (caddr_t)u32->uscsi_rqbuf;            \
231         ucmd->uscsi_reserved_5  = (void *)u32->uscsi_reserved_5;
232
233
234 /*
235  * Convert drivers's LP64 uscsi_cmd back to IPL32
236  */
237 #define sst_uscsi_cmdtouscsi_cmd32(ucmd, u32)                           \
238         u32->uscsi_flags        = ucmd->uscsi_flags;                    \
239         u32->uscsi_status       = ucmd->uscsi_status;                   \
240         u32->uscsi_timeout      = ucmd->uscsi_timeout;                  \
241         u32->uscsi_cdb          = (caddr32_t)ucmd->uscsi_cdb;           \
242         u32->uscsi_bufaddr      = (caddr32_t)ucmd->uscsi_bufaddr;       \
243         u32->uscsi_buflen       = (size32_t)ucmd->uscsi_buflen;         \
244         u32->uscsi_resid        = (size32_t)ucmd->uscsi_resid;          \
245         u32->uscsi_cdblen       = ucmd->uscsi_cdblen;                   \
246         u32->uscsi_rqlen        = ucmd->uscsi_rqlen;                    \
247         u32->uscsi_rqstatus     = ucmd->uscsi_rqstatus;                 \
248         u32->uscsi_rqresid      = ucmd->uscsi_rqresid;                  \
249         u32->uscsi_rqbuf        = (caddr32_t)ucmd->uscsi_rqbuf;         \
250         u32->uscsi_reserved_5   = (caddr32_t)ucmd->uscsi_reserved_5;
251
252 #endif /* _SYSCALL32 */
253
254 #ifdef  __cplusplus
255 }
256 #endif
257
258 #endif  /* _SST_DEF_H */