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