Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / usr / src / cmd / smserverd / smserver.h
blob91004fbea59816909898b8ca5933da254800f2db
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SMSERVER_H_
27 #define _SMSERVER_H_
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #include <door.h>
34 #include <thread.h>
35 #include <synch.h>
36 #include <sys/dkio.h>
38 #define RQ_LEN 18
39 #define MAX_RQ_LEN 32
40 #define MAX_CDB_LEN 32
42 #define smedia_service "/var/run/smedia_svc"
43 #define DEFAULT_SMEDIAD_DEVDIR "/usr/lib/smedia"
45 #define INIT_NOT_DONE 0
46 #define INIT_DONE 1
47 #define INIT_IN_PROGRESS 2
49 /* SCSI FORMAT UNIT cdb[1] #defines */
50 #define FMTDATA 0x10
51 #define CMPLIST 0x08
53 /* Defect list header data[1] #defines */
55 #define VS 0x1
56 #define IMMED 0x2
57 #define DSP 0x4
58 #define IP 0x8
59 #define STPF 0x10
60 #define DCRT 0x20
61 #define DPRY 0x40
62 #define FOV 0x80
64 #define DEFERRED_ERROR 0x71
65 #define AWRE 0x80
67 #define MODE_SENSE_PARAM_HDR_LEN 4
68 #define MODE_PARAM_BLOCK_LEN 8
69 #define AWRE_OFFSET (MODE_SENSE_PARAM_HDR_LEN + MODE_PARAM_BLOCK_LEN + 2)
70 #define BLOCK_LEN_OFFSET (MODE_SENSE_PARAM_HDR_LEN + 5)
71 #define SKSV_FIELD 0x80
72 #define SKSV_OFFSET 15
73 #define FORMAT_PROGRESS_INDICATOR_OFFSET_0 16
74 #define FORMAT_PROGRESS_INDICATOR_OFFSET_1 17
76 /* #defines for protect medode field */
78 #define UNLOCK_MODE 0x0
79 #define WRITE_PROTECT_MODE 0x2
80 #define PASSWD_WRITE_PROTECT_MODE 0x3
81 #define READ_WRITE_PROTECT_MODE 0x5
82 #define TEMP_UNLOCK_MODE 0x8
84 /* #defines for CARTRIDGE STATUS PAGE */
86 #define CARTRIDGE_STATUS_PAGE 2
87 #define NON_SENSE_HDR_LEN 0x2
88 #define PROTECT_MODE_OFFSET 19
89 #define DISK_STATUS_OFFSET 1
92 /* error reporting mechanism */
93 void fatal(const char *, ...);
94 void info(const char *, ...);
95 void warning(const char *, ...);
96 void debug(uint_t, const char *, ...);
97 void setlog(const char *);
98 void flushlog();
99 void quit(const char *, ...);
100 void noise(const char *, ...);
102 typedef struct server_data {
103 char sd_init_state;
104 mutex_t sd_init_lock;
105 cond_t sd_init_cv;
106 int sd_door;
107 int sd_fd;
108 } server_data_t;
110 typedef enum {
111 SMEDIA_SUCCESS = 0x0,
112 SMEDIA_FAILURE /* general failure */
113 } smedia_errno_t;
115 typedef struct door_data {
116 mutex_t dd_lock; /* lock to protect entire structure */
117 mutex_t dd_threadlock; /* lock to protect dd_thread field */
118 sigset_t dd_newset; /* signal set handled by the server */
119 cond_t dd_cv; /* client_door_descriptor cv */
120 cond_t dd_cv_bind; /* client door descriptor bind cv */
121 int32_t dd_id; /* for future use. To store unique id */
122 door_desc_t dd_desc[2]; /* [0] : Client Door descriptor */
123 /* [1] : Death Door decriptor */
124 thread_t dd_thread; /* thread bound to the client door */
125 door_cred_t dd_cred; /* credentials of client */
126 int32_t dd_fd; /* device file descriptor */
127 void *dd_buf; /* mmapped buffer of client */
128 int32_t dd_buf_len; /* size of the mmapped buffer */
129 int32_t dd_buffd; /* mmapped file descriptor */
130 int32_t dd_sector_size; /* sector size of the device */
131 struct stat dd_stat; /* stat of the dd_fd */
132 struct dk_cinfo dd_dkinfo;
133 } door_data_t;
135 /* Symbols to simplify access of door_data_t */
136 #define dd_cdoor dd_desc[0] /* Client Door descriptor */
137 #define dd_ddoor dd_desc[1] /* Death Door descriptor */
138 #define dd_cdoor_descriptor dd_cdoor.d_data.d_desc.d_descriptor
139 #define dd_ddoor_descriptor dd_ddoor.d_data.d_desc.d_descriptor
141 typedef enum {
142 SMEDIA_CNUM_OPEN_FD = 0x1,
143 SMEDIA_CNUM_GET_DEVICE_INFO,
144 SMEDIA_CNUM_GET_MEDIUM_PROPERTY,
145 SMEDIA_CNUM_GET_PROTECTION_STATUS,
146 SMEDIA_CNUM_SET_PROTECTION_STATUS,
147 SMEDIA_CNUM_RAW_READ,
148 SMEDIA_CNUM_RAW_WRITE,
149 SMEDIA_CNUM_FORMAT,
150 SMEDIA_CNUM_CHECK_FORMAT_STATUS,
151 SMEDIA_CNUM_EJECT,
152 SMEDIA_CNUM_REASSIGN_BLOCK,
153 SMEDIA_CNUM_ERROR,
154 SMEDIA_CNUM_CLOSE,
155 SMEDIA_CNUM_SET_SHFD,
156 SMEDIA_CNUM_PING,
157 SMEDIA_CNUM_USCSI_CMD
158 } smedia_callnumber_t;
160 typedef struct {
161 smedia_callnumber_t cnum; /* service call number */
162 char buf[1]; /* buffer containing input arguments */
163 } smedia_req_t;
165 typedef struct {
166 smedia_callnumber_t cnum; /* service call number */
167 char buf[1]; /* buffer containing the results */
168 } smedia_ret_t;
170 typedef struct smedia_reqping {
171 smedia_callnumber_t cnum; /* SMEDIA_CNUM_PING */
172 } smedia_reqping_t;
174 typedef struct smedia_retping {
175 smedia_callnumber_t cnum; /* SMEDIA_CNUM_PING */
176 } smedia_retping_t;
179 * SMEDIA open device
181 typedef struct smedia_reqopen {
182 smedia_callnumber_t cnum; /* SMEDIA_CNUM_OPEN */
183 int oflag;
184 int omode;
185 } smedia_reqopen_t;
187 typedef struct smedia_retopen {
188 smedia_callnumber_t cnum; /* SMEDIA_CNUM_OPEN */
189 } smedia_retopen_t;
191 typedef struct smedia_requscsi_cmd {
192 smedia_callnumber_t cnum; /* SMEDIA_CNUM_USCSI_CMD */
193 int32_t uscsi_flags;
194 short uscsi_timeout;
195 char uscsi_cdb[MAX_CDB_LEN];
196 int32_t uscsi_buflen;
197 uchar_t uscsi_cdblen;
198 uchar_t uscsi_rqlen;
199 } smedia_requscsi_cmd_t;
201 typedef struct smedia_retuscsi_cmd {
202 smedia_callnumber_t cnum; /* SMEDIA_CNUM_USCSI_CMD */
203 int32_t uscsi_retval;
204 int32_t uscsi_errno;
205 short uscsi_status;
206 int32_t uscsi_resid;
207 uchar_t uscsi_rqstatus;
208 uchar_t uscsi_rqresid;
209 char uscsi_rqbuf[MAX_RQ_LEN];
210 } smedia_retuscsi_cmd_t;
212 typedef struct smedia_reqget_device_info {
213 smedia_callnumber_t cnum; /* SMEDIA_CNUM_GET_DEVICE_INFO */
214 } smedia_reqget_device_info_t;
216 typedef struct smedia_reqset_shfd {
217 smedia_callnumber_t cnum; /* SMEDIA_CNUM_SET_SHFD */
218 int32_t fdbuf_len;
219 } smedia_reqset_shfd_t;
221 typedef struct smedia_retget_device_info {
222 smedia_callnumber_t cnum; /* SMEDIA_CNUM_GET_DEVICE_INFO */
223 smdevice_info_t smdevinfo;
224 uchar_t sm_version;
225 int32_t sm_interface_type;
226 char sm_vendor_name[32];
227 char sm_product_name[32];
228 char sm_firmware_version[32];
229 } smedia_retget_device_info_t;
231 typedef struct smedia_reqget_medium_property {
232 smedia_callnumber_t cnum; /* SMEDIA_CNUM_GET_MEDIUM_PROPERTY */
233 } smedia_reqget_medium_property_t;
235 typedef struct smedia_retget_medium_property {
236 smedia_callnumber_t cnum; /* SMEDIA_CNUM_GET_MEDIUM_PROPERTY */
237 smmedium_prop_t smprop;
238 } smedia_retget_medium_property_t;
240 typedef struct smedia_reqget_protection_status {
241 smedia_callnumber_t cnum; /* SMEDIA_CNUM_GET_PROTECTION_STATUS */
242 } smedia_reqget_protection_status_t;
244 typedef struct smedia_retget_protection_status {
245 smedia_callnumber_t cnum; /* SMEDIA_CNUM_GET_PROTECTION_STATUS */
246 smwp_state_t prot_state;
247 } smedia_retget_protection_status_t;
249 typedef struct smedia_reqset_protection_status {
250 smedia_callnumber_t cnum; /* SMEDIA_CNUM_SET_PROTECTION_STATUS */
251 smwp_state_t prot_state;
252 } smedia_reqset_protection_status_t;
254 typedef struct smedia_retset_protection_status {
255 smedia_callnumber_t cnum; /* SMEDIA_CNUM_SET_PROTECTION_STATUS */
256 } smedia_retset_protection_status_t;
258 typedef struct smedia_reqraw_read {
259 smedia_callnumber_t cnum; /* SMEDIA_CNUM_RAW_READ */
260 diskaddr_t blockno;
261 int32_t nbytes;
262 } smedia_reqraw_read_t;
264 typedef struct smedia_retraw_read {
265 smedia_callnumber_t cnum; /* SMEDIA_CNUM_RAW_READ */
266 int32_t nbytes; /* bytes read */
267 char buf[1]; /* buffer size is nbytes long */
268 } smedia_retraw_read_t;
270 typedef struct smedia_reqraw_write {
271 smedia_callnumber_t cnum; /* SMEDIA_CNUM_RAW_WRITE */
272 diskaddr_t blockno;
273 int32_t nbytes;
274 char buf[1]; /* buffer size is nbytes long */
275 } smedia_reqraw_write_t;
277 typedef struct smedia_retraw_write {
278 smedia_callnumber_t cnum; /* SMEDIA_CNUM_RAW_WRITE */
279 int32_t nbytes; /* bytes written */
280 } smedia_retraw_write_t;
282 typedef struct smedia_reqformat {
283 smedia_callnumber_t cnum; /* SMEDIA_CNUM_FORMAT */
284 uint_t flavor;
285 uint_t mode;
286 } smedia_reqformat_t;
288 typedef struct smedia_retformat {
289 smedia_callnumber_t cnum; /* SMEDIA_CNUM_FORMAT */
290 } smedia_retformat_t;
292 typedef struct smedia_reqcheck_format_status {
293 smedia_callnumber_t cnum; /* SMEDIA_CNUM_CHECK_FORMAT_STATUS */
294 } smedia_reqcheck_format_status_t;
296 typedef struct smedia_retcheck_format_status {
297 smedia_callnumber_t cnum; /* SMEDIA_CNUM_CHECK_FORMAT_STATUS */
298 int percent_complete;
299 } smedia_retcheck_format_status_t;
301 typedef struct smedia_reqreassign_block {
302 smedia_callnumber_t cnum; /* SMEDIA_CNUM_REASSIGN_BLOCK */
303 diskaddr_t blockno;
304 } smedia_reqreassign_block_t;
306 typedef struct smedia_retreassign_block {
307 smedia_callnumber_t cnum; /* SMEDIA_CNUM_REASSIGN_BLOCK */
308 } smedia_retreassign_block_t;
310 typedef struct {
311 smedia_callnumber_t cnum; /* SMEDIA_CNUM_ERROR */
312 smedia_callnumber_t in_cnum; /* requested service number */
313 smedia_errno_t errnum;
314 } smedia_reterror_t;
316 typedef union {
317 smedia_req_t in; /* req arguments */
318 smedia_ret_t out; /* out results */
319 smedia_reqping_t reqping;
320 smedia_retping_t retping;
321 smedia_reqopen_t reqopen;
322 smedia_retopen_t retopen;
323 smedia_reqget_device_info_t reqget_device_info;
324 smedia_retget_device_info_t retget_device_info;
325 smedia_reqget_medium_property_t reqget_medium_property;
326 smedia_retget_medium_property_t retget_medium_property;
327 smedia_reqget_protection_status_t reqget_protection_status;
328 smedia_retget_protection_status_t retget_protection_status;
329 smedia_reqset_protection_status_t reqset_protection_status;
330 smedia_retset_protection_status_t retset_protection_status;
331 smedia_reqraw_read_t reqraw_read;
332 smedia_retraw_read_t retraw_read;
333 smedia_reqraw_write_t reqraw_write;
334 smedia_retraw_write_t retraw_write;
335 smedia_reqformat_t reqformat;
336 smedia_retformat_t retformat;
337 smedia_reqcheck_format_status_t reqcheck_format_status;
338 smedia_retcheck_format_status_t retcheck_format_status;
339 smedia_reqreassign_block_t reqreassign_block;
340 smedia_retreassign_block_t retreassign_block;
341 smedia_reterror_t reterror;
342 smedia_reqset_shfd_t reqset_shfd;
343 smedia_requscsi_cmd_t requscsi_cmd;
344 smedia_retuscsi_cmd_t retuscsi_cmd;
345 } smedia_services_t;
347 #define SCSI_GENERIC 1
348 #define SCSI_IOMEGA 2
349 #define SCSI_FLOPPY 3
352 * Crude algorithm for calculating format timeout.
353 * 30min + 5min/100MB =>
354 * 35min for 100MB ZIP
355 * 42.5 min for 250MB ZIP
356 * 127 min for 2GB Jaz
357 * It is OK for now as this is just an upper limit by which the
358 * format should complete.
361 #define FORMAT_TIMEOUT(n) (1800 + ((n)/682))
363 #define WA_BIT 0x10 /* The word align bit for ATAPI devices */
365 * Non sense data length for catridge status page.
366 * Should be 63, but IDE driver panics with a non-aligned
367 * data transfer.
370 #define ND_LENGTH 64
373 * Vendor specific commands from Iomega
376 #define IOMEGA_NONSENSE_CMD 0x6
377 #define IOMEGA_CATRIDGE_PROTECT 0xC
379 #ifdef __cplusplus
381 #endif
383 #endif /* _SMSERVER_H_ */