Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / libusal / usal / usalcmd.h
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* @(#)usalcmd.h        2.22 04/09/04 Copyright 1986 J. Schilling */
14 /*
15  *      Definitions for the SCSI 'usal_cmd' structure that has been created
16  *      for the SCSI general driver 'usal' for SunOS and Solaris but
17  *      now is used for wrapping general libusal SCSI transport requests.
18  *
19  *      Copyright (c) 1986 J. Schilling
20  */
21 /*
22  * This program is free software; you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License version 2
24  * as published by the Free Software Foundation.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License along with
32  * this program; see the file COPYING.  If not, write to the Free Software
33  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34  */
35
36 #ifndef _SCG_SCGCMD_H
37 #define _SCG_SCGCMD_H
38
39 #include <utypes.h>
40 #include <btorder.h>
41
42 #if     defined(_BIT_FIELDS_LTOH)       /* Intel byteorder */
43 #else
44 # if    defined(_BIT_FIELDS_HTOL)       /* Motorola byteorder */
45 # else
46 /*
47  * #error will not work for all compilers (e.g. sunos4)
48  * The following line will abort compilation on all compilers
49  * if none of the above is defines. And that's  what we want.
50  */
51 error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
52 # endif
53 #endif
54
55 #include <usal/scsisense.h>
56 #include <usal/scsicdb.h>
57 #include <intcvt.h>
58
59 #ifdef  __cplusplus
60 extern "C" {
61 #endif
62
63 /*
64  * Leave these definitions here if possible to avoid the need to
65  * include scsireg.h which makes problems on some OS because these
66  * OS define the same types as in scsireg.h
67  */
68
69 /*
70  * SCSI status bits.
71  */
72 #define ST_VU_00        0x01    /* Vendor unique                */
73 #define ST_CHK_COND     0x02    /* Check condition              */
74 #define ST_COND_MET     0x04    /* Condition met                */
75 #define ST_BUSY         0x08    /* Busy                         */
76 #define ST_IS_SEND      0x10    /* Intermediate status send     */
77 #define ST_VU_05        0x20    /* Vendor unique                */
78 #define ST_VU_06        0x40    /* Vendor unique                */
79 #define ST_RSVD_07      0x80    /* Reserved                     */
80
81 /*
82  * Sense key values for extended sense.
83  */
84 #define SC_NO_SENSE             0x00
85 #define SC_RECOVERABLE_ERROR    0x01
86 #define SC_NOT_READY            0x02
87 #define SC_MEDIUM_ERROR         0x03
88 #define SC_HARDWARE_ERROR       0x04
89 #define SC_ILLEGAL_REQUEST      0x05
90 #define SC_UNIT_ATTENTION       0x06
91 #define SC_WRITE_PROTECT        0x07
92 #define SC_BLANK_CHECK          0x08
93 #define SC_VENDOR_UNIQUE        0x09
94 #define SC_COPY_ABORTED         0x0A
95 #define SC_ABORTED_COMMAND      0x0B
96 #define SC_EQUAL                0x0C
97 #define SC_VOLUME_OVERFLOW      0x0D
98 #define SC_MISCOMPARE           0x0E
99 #define SC_RESERVED             0x0F
100
101 /*
102  * Messages that SCSI can send.
103  */
104 #define SC_COMMAND_COMPLETE     0x00
105 #define SC_SYNCHRONOUS          0x01
106 #define SC_SAVE_DATA_PTR        0x02
107 #define SC_RESTORE_PTRS         0x03
108 #define SC_DISCONNECT           0x04
109 #define SC_ABORT                0x06
110 #define SC_MSG_REJECT           0x07
111 #define SC_NO_OP                0x08
112 #define SC_PARITY               0x09
113 #define SC_IDENTIFY             0x80
114 #define SC_DR_IDENTIFY          0xc0
115 #define SC_DEVICE_RESET         0x0c
116
117 #define SC_G0_CDBLEN    6       /* Len of Group 0 commands */
118 #define SC_G1_CDBLEN    10      /* Len of Group 1 commands */
119 #define SC_G5_CDBLEN    12      /* Len of Group 5 commands */
120
121 #define SCG_MAX_CMD     24      /* 24 bytes max. size is supported */
122 #define SCG_MAX_STATUS  3       /* XXX (sollte 4 allign.) Mamimum Status Len */
123 #define SCG_MAX_SENSE   32      /* Mamimum Sense Len for auto Req. Sense */
124
125 #define DEF_SENSE_LEN   16      /* Default Sense Len */
126 #define CCS_SENSE_LEN   18      /* Sense Len for CCS compatible devices */
127
128 struct  usal_cmd {
129         caddr_t addr;                   /* Address of data in user space */
130         int     size;                   /* DMA count for data transfer */
131         int     flags;                  /* see below for definition */
132         int     cdb_len;                /* Size of SCSI command in bytes */
133                                         /* NOTE: rel 4 uses this field only */
134                                         /* with commands not in group 1 or 2*/
135         int     sense_len;              /* for intr() if -1 don't get sense */
136         int     timeout;                /* timeout in seconds */
137                                         /* NOTE: actual resolution depends */
138                                         /* on driver implementation */
139         int     kdebug;                 /* driver kernel debug level */
140         int     resid;                  /* Bytes not transfered */
141         int     error;                  /* Error code from usalintr() */
142         int     ux_errno;               /* UNIX error code */
143 #ifdef  comment
144 XXX     struct  scsi_status scb; ???    /* Status returnd by command */
145 #endif
146         union {
147                 struct  scsi_status Scb; /* Status returnd by command */
148                 Uchar   cmd_scb[SCG_MAX_STATUS];
149         } u_scb;
150 #define scb     u_scb.Scb
151 #ifdef  comment
152 XXX     struct  scsi_sense sense; ???   /* Sense bytes from command */
153 #endif
154         union {
155                 struct  scsi_sense Sense; /* Sense bytes from command */
156                 Uchar   cmd_sense[SCG_MAX_SENSE];
157         } u_sense;
158 #define sense   u_sense.Sense
159         int     sense_count;            /* Number of bytes valid in sense */
160         int     target;                 /* SCSI target id */
161                                         /* NOTE: The SCSI target id field   */
162                                         /* does not need to be filled unless */
163                                         /* the low level transport is a real */
164                                         /* usal driver. In this case the low */
165                                         /* level transport routine of libusal */
166                                         /* will fill in the needed value    */
167         union {                         /* SCSI command descriptor block */
168                 struct  scsi_g0cdb g0_cdb;
169                 struct  scsi_g1cdb g1_cdb;
170                 struct  scsi_g5cdb g5_cdb;
171                 Uchar   cmd_cdb[SCG_MAX_CMD];
172         } cdb;                          /* 24 bytes max. size is supported */
173 };
174
175 #define dma_read        flags           /* 1 if DMA to Sun, 0 otherwise */
176
177 /*
178  * definition for flags field in usal_cmd struct
179  */
180 #define SCG_RECV_DATA   0x0001          /* DMA direction to Sun */
181 #define SCG_DISRE_ENA   0x0002          /* enable disconnect/reconnect */
182 #define SCG_SILENT      0x0004          /* be silent on errors */
183 #define SCG_CMD_RETRY   0x0008          /* enable retries */
184 #define SCG_NOPARITY    0x0010          /* disable parity for this command */
185
186 /*
187  * definition for error field in usal_cmd struct
188  *
189  * The codes refer to SCSI general errors, not to device
190  * specific errors.  Device specific errors are discovered
191  * by checking the sense data.
192  * The distinction between retryable and fatal is somewhat ad hoc.
193  */
194 #define SCG_NO_ERROR    0               /* cdb transported without error    */
195                                         /* SCG_NO_ERROR incudes all commands */
196                                         /* where the SCSI status is valid   */
197
198 #define SCG_RETRYABLE   1               /* any other case e.g. SCSI bus busy */
199                                         /* SCSI cdb could not be send,      */
200                                         /* includes DMA errors other than   */
201                                         /* DMA underrun                     */
202
203 #define SCG_FATAL       2               /* could not select target          */
204 #define SCG_TIMEOUT     3               /* driver timed out                 */
205
206
207 #ifdef  __cplusplus
208 }
209 #endif
210
211 #endif  /* _SCG_SCGCMD_H */