xref: /titanic_50/usr/src/uts/sun/sys/dada/targets/daddef.h (revision e07d9cb85217949d497b02d7211de8a197d2f2eb)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DADA_TARGETS_DADDF_H
27 #define	_SYS_DADA_TARGETS_DADDF_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 #include <sys/note.h>
31 #include <sys/cmlb.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Defines for SCSI direct access devices
39  */
40 
41 #define	FIXEDFIRMWARE	/* fixed firmware for volume control */
42 
43 #if	defined(_KERNEL) || defined(_KMEMUSER)
44 
45 
46 /*
47  * Local definitions, for clarity of code
48  */
49 #define	DCD_DCD_DEVP	(un->un_dcd)
50 #define	DCD_DEVINFO	(DCD_DCD_DEVP->dcd_dev)
51 #define	DCD_IDENTIFY	(DCD_DCD_DEVP->dcd_ident)
52 #define	DCD_MUTEX	(&DCD_DCD_DEVP->dcd_mutex)
53 #define	ROUTE		(DCD_DCD_DEVP->dcd_address)
54 #define	SECDIV		(un->un_secdiv)
55 #define	SECSIZE		(un->un_secsize)
56 #define	SCBP(pkt)	((struct dcd_status *)(pkt)->pkt_scbp)
57 #define	SCBP_C(pkt)	((*(pkt)->pkt_scbp) & STATUS_ATA_MASK)
58 #define	CDBP(pkt)	((union scsi_cdb *)(pkt)->pkt_cdbp)
59 #define	NO_PKT_ALLOCATED ((struct buf *)0)
60 #define	ALLOCATING_PKT	((struct buf *)-1)
61 #define	BP_PKT(bp)	((struct dcd_pkt *)bp->av_back)
62 #define	BP_HAS_NO_PKT(bp) (bp->av_back == NO_PKT_ALLOCATED)
63 #define	MAX_ATA_XFER_SIZE (256*DEV_BSIZE)
64 
65 #define	STATUS_SCBP_C(statusp)	(*(uchar_t *)(statusp) & STATUS_ATA_MASK)
66 
67 #define	Tgt(devp)	(devp->dcd_address->a_target)
68 #define	Lun(devp)	(devp->dcd_address->a_lun)
69 
70 #define	New_state(un, s)	\
71 	(un)->un_last_state = (un)->un_state,  (un)->un_state = (s)
72 #define	Restore_state(un)	\
73 	{ uchar_t tmp = (un)->un_last_state; New_state((un), tmp); }
74 
75 
76 #define	CTYPE_DISK	 2
77 /*
78  * Structure for recording whether a device is fully open or closed.
79  * Assumptions:
80  *
81  *	+ There are only 8 partitions possible.
82  *	+ BLK, MNT, CHR, SWP don't change in some future release!
83  *
84  */
85 
86 #define	DCDUNIT_SHIFT	3
87 #define	DCDPART_MASK	7
88 #define	DCDUNIT(dev)	(getminor((dev))>>DCDUNIT_SHIFT)
89 #define	DCDPART(dev)	(getminor((dev)) & DCDPART_MASK)
90 
91 struct ocinfo {
92 	/*
93 	 * Types BLK, MNT, CHR, SWP,
94 	 * assumed to be types 0-3.
95 	 */
96 	ulong_t  lyr_open[NDKMAP];
97 	uchar_t  reg_open[OTYPCNT - 1];
98 };
99 #define	OCSIZE  sizeof (struct ocinfo)
100 union ocmap {
101 	uchar_t chkd[OCSIZE];
102 	struct ocinfo rinfo;
103 };
104 #define	lyropen rinfo.lyr_open
105 #define	regopen rinfo.reg_open
106 
107 /*
108  * Private info for dcd disks.
109  *
110  * Pointed to by the un_private pointer
111  * of one of the dcd_device structures.
112  */
113 
114 struct dcd_disk {
115 	struct dcd_device *un_dcd;	/* back pointer to dcd_device */
116 	struct dcd_drivetype *un_dp;	/* drive type table */
117 	struct	buf *un_sbufp;		/* for use in special io */
118 	char		*un_srqbufp;	/* sense buffer for special io */
119 	kcondvar_t	un_sbuf_cv;	/* Conditional Variable on sbufp */
120 	kcondvar_t	un_state_cv;	/* Conditional variable for state */
121 	union	ocmap un_ocmap;		/* open partition map, block && char */
122 	uchar_t	un_last_pkt_reason;	/* used for suppressing multiple msgs */
123 	struct	diskhd un_utab;		/* for queuing */
124 	struct	kstat *un_stats;	/* for statistics */
125 	struct	kstat *un_pstats[NDKMAP]; /* for partition statistics */
126 	ksema_t	un_semoclose;		/* lock for serializing opens/closes */
127 	uint_t	un_err_blkno;		/* disk block where error occurred */
128 	int	un_diskcapacity;	/* capacity as returned by drive */
129 	int	un_lbasize;		/* logical (i.e. device) block size */
130 	int	un_lbadiv;		/* log2 of lbasize */
131 	int	un_blknoshift;		/* log2 of multiple of DEV_BSIZE */
132 					/* blocks making up a logical block */
133 	int	un_secsize;		/* sector size (allow request on */
134 					/* this boundry) */
135 	int	un_secdiv;		/* log2 of secsize */
136 	uchar_t	un_exclopen;		/* exclusive open bits */
137 	uchar_t	un_mediastate;		/* Is it really needed  XXX */
138 	uchar_t	un_state;		/* current state */
139 	uchar_t	un_last_state;		/* last state */
140 	uchar_t	un_format_in_progress;	/* disk is formatting currently */
141 	uchar_t un_flush_not_supported;	/* disk doesn't support flush cmd */
142 	uchar_t	un_write_cache_enabled;	/* disk has write caching enabled */
143 	clock_t un_timestamp;		/* Time of last device access */
144 	short	un_ncmds;		/* number of cmds in transport */
145 	short	un_throttle;		/* This is used for throttling if */
146 					/* HBA has queuing		  */
147 	short	un_sbuf_busy;		/* Busy wait flag for the sbuf */
148 	int	un_cmd_flags;		/* cache some frequently used values */
149 	int	un_cmd_stat_size;	/* in make_sd_cmd */
150 	int	un_dcvb_timeid;		/* timeout id for dlyd cv broadcast */
151 	void 	*un_devid;		/* device id */
152 	uint_t	un_max_xfer_size;	/* max transfer size */
153 	uchar_t	un_bus_master;		/* Indicates that the HBA  enables  */
154 					/* Bus master capability */
155 	timeout_id_t	un_reissued_timeid;
156 					/* This is used in busy handler */
157 	kstat_t	*un_errstats;		/* For Error statsistics */
158 	kcondvar_t	un_suspend_cv;	/* Cond Var on power management */
159 	kcondvar_t	un_disk_busy_cv; /* Cond var to wait for IO */
160 	short	un_power_level;		/* Power Level */
161 	short	un_save_state;		/* Save the state for suspend/resume */
162 	cmlb_handle_t   un_dklbhandle;  /* Handle for disk label */
163 	tg_attribute_t un_tgattribute;
164 };
165 
166 /*
167  * device error statistics
168  */
169 struct dcd_errstats {
170 	struct kstat_named	dcd_softerrs;	/* Collecting Softerrs */
171 	struct kstat_named	dcd_harderrs;	/* Collecting harderrs */
172 	struct kstat_named	dcd_transerrs;	/* Collecting Transfer errs */
173 	struct kstat_named	dcd_model;	/* model # of the disk */
174 	struct kstat_named	dcd_revision;	/* The disk revision */
175 	struct kstat_named	dcd_serial;	/* The disk serial number */
176 	struct kstat_named	dcd_capacity;	/* Capacity of the disk */
177 	struct kstat_named	dcd_rq_media_err; /* Any media err seen */
178 	struct kstat_named	dcd_rq_ntrdy_err; /* Not ready errs */
179 	struct kstat_named	dcd_rq_nodev_err; /* No device errs */
180 	struct kstat_named	dcd_rq_recov_err; /* Recovered errs */
181 	struct kstat_named	dcd_rq_illrq_err; /* Illegal requests */
182 };
183 #define	DCD_MAX_XFER_SIZE	(1 * 512)
184 
185 _NOTE(MUTEX_PROTECTS_DATA(dcd_device::dcd_mutex, dcd_disk))
186 _NOTE(READ_ONLY_DATA(dcd_disk::un_dcd))
187 _NOTE(READ_ONLY_DATA(dcd_disk::un_cmd_stat_size))
188 _NOTE(SCHEME_PROTECTS_DATA("Save Sharing",
189 	dcd_disk::un_state
190 	dcd_disk::un_dklbhandle
191 	dcd_disk::un_format_in_progress))
192 
193 _NOTE(SCHEME_PROTECTS_DATA("stable data",
194 	dcd_disk::un_max_xfer_size
195 	dcd_disk::un_secdiv
196 	dcd_disk::un_secsize
197 	dcd_disk::un_cmd_flags
198 	dcd_disk::un_cmd_stat_size))
199 
200 _NOTE(SCHEME_PROTECTS_DATA("cv",
201 	dcd_disk::un_sbufp
202 	dcd_disk::un_srqbufp
203 	dcd_disk::un_sbuf_busy))
204 
205 _NOTE(SCHEME_PROTECTS_DATA("Unshared data",
206 	dk_cinfo
207 	uio
208 	buf
209 	dcd_pkt
210 	udcd_cmd
211 	dcd_capacity
212 	dcd_cmd
213 	dk_label
214 	dk_map32))
215 
216 _NOTE(SCHEME_PROTECTS_DATA("stable data", dcd_device))
217 _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", dcd_cmd))
218 
219 #endif	/* defined(_KERNEL) || defined(_KMEMUSER) */
220 
221 
222 /*
223  * Disk driver states
224  */
225 
226 #define	DCD_STATE_NORMAL	0
227 #define	DCD_STATE_OFFLINE	1
228 #define	DCD_STATE_RWAIT		2
229 #define	DCD_STATE_DUMPING	3
230 #define	DCD_STATE_SUSPENDED	4
231 #define	DCD_STATE_FATAL		5
232 #define	DCD_STATE_PM_SUSPENDED	6
233 
234 /*
235  * Disk power levels.
236  */
237 #define	DCD_DEVICE_ACTIVE	0x2
238 #define	DCD_DEVICE_IDLE		0x1
239 #define	DCD_DEVICE_STANDBY	0x0
240 
241 /*
242  * Macros used in obtaining the device ID for the disk.
243  */
244 #define	DCD_SERIAL_NUMBER_LENGTH	20
245 #define	DCD_MODEL_NUMBER_LENGTH		40
246 
247 /*
248  * The table is to be interpreted as follows: The rows lists all the states
249  * and each column is a state that a state in each row *can* reach. The entries
250  * in the table list the event that cause that transition to take place.
251  * For e.g.: To go from state RWAIT to SUSPENDED, event (d)-- which is the
252  * invocation of DDI_SUSPEND-- has to take place. Note the same event could
253  * cause the transition from one state to two different states. e.g., from
254  * state SUSPENDED, when we get a DDI_RESUME, we just go back to the *last
255  * state* whatever that might be. (NORMAL or OFFLINE).
256  *
257  *
258  * State Transition Table:
259  *
260  *			NORMAL  OFFLINE  RWAIT  DUMPING  SUSPENDED
261  *
262  *	NORMAL		-	(a)	(b)	(c)	(d)
263  *
264  *	OFFLINE		(e)	-	(e)	(c)	(d)
265  *
266  *	RWAIT		(f)	NP	-	(c)	(d)
267  *
268  *	DUMPING		NP	NP	NP	-	NP
269  *
270  *	SUSPENDED	(g)	(g)	(b)	NP*	-
271  *
272  *
273  *	NP:	Not Possible.
274  *	(a):	Disk does not respond.
275  *	(b):	Packet Allocation Fails
276  *	(c):	Panic - Crash dump
277  *	(d):	DDI_SUSPEND is called.
278  *	(e):	Disk has a successful I/O completed.
279  *	(f):	sdrunout() calls sdstart() which sets it NORMAL
280  *	(g):	DDI_RESUME is called.
281  *	* :	When suspended, we dont change state during panic dump
282  */
283 
284 
285 /*
286  * Error levels
287  */
288 
289 #define	DCDERR_ALL		0
290 #define	DCDERR_UNKNOWN		1
291 #define	DCDERR_INFORMATIONAL	2
292 #define	DCDERR_RECOVERED	3
293 #define	DCDERR_RETRYABLE	4
294 #define	DCDERR_FATAL		5
295 
296 /*
297  * Parameters
298  */
299 
300 /*
301  * 60 seconds is a *very* reasonable amount of time for most slow CD
302  * operations.
303  */
304 
305 #define	DCD_IO_TIME	60
306 
307 /*
308  * Timeout value for ATA_FLUSH_CACHE used in DKIOCFLUSHWRITECACHE
309  */
310 #define	DCD_FLUSH_TIME	60
311 
312 /*
313  * 2 hours is an excessively reasonable amount of time for format operations.
314  */
315 
316 #define	DCD_FMT_TIME	120*60
317 
318 /*
319  * 5 seconds is what we'll wait if we get a Busy Status back
320  */
321 
322 #define	DCD_BSY_TIMEOUT		(drv_usectohz(5 * 1000000))
323 
324 /*
325  * Number of times we'll retry a normal operation.
326  *
327  * This includes retries due to transport failure
328  * (need to distinguish between Target and Transport failure)
329  */
330 
331 #define	DCD_RETRY_COUNT		5
332 
333 
334 /*
335  * Maximum number of units we can support
336  * (controlled by room in minor device byte)
337  * XXX: this is out of date!
338  */
339 #define	DCD_MAXUNIT		32
340 
341 /*
342  * 30 seconds is what we will wait for the IO to finish
343  * before we fail the DDI_SUSPEND
344  */
345 #define	DCD_WAIT_CMDS_COMPLETE	30
346 
347 /*
348  * dcdintr action codes
349  */
350 
351 #define	COMMAND_DONE		0
352 #define	COMMAND_DONE_ERROR	1
353 #define	QUE_COMMAND		2
354 #define	QUE_SENSE		3
355 #define	JUST_RETURN		4
356 
357 /*
358  * Indicator for Soft and hard errors
359  */
360 #define	COMMAND_SOFT_ERROR	1
361 #define	COMMAND_HARD_ERROR	2
362 
363 /*
364  * Drive Types (and characteristics)
365  */
366 #define	VIDMAX 8
367 #define	PIDMAX 16
368 
369 struct dcd_drivetype {
370 	char 	*name;		/* for debug purposes */
371 	char	ctype;		/* controller type */
372 	char	options;	/* drive options */
373 	ushort_t block_factor;	/* Block mode factor */
374 	char	pio_mode;	/* This the Pio mode number */
375 	char 	dma_mode;	/* Multi word dma mode */
376 };
377 
378 /*
379  * The options values
380  */
381 #define	DMA_SUPPORTTED	0x01
382 #define	BLOCK_MODE	0x02
383 
384 #ifndef	LOG_EMERG
385 #define	LOG_WARNING	CE_NOTE
386 #define	LOG_NOTICE	CE_NOTE
387 #define	LOG_CRIT	CE_WARN
388 #define	LOG_ERR		CE_WARN
389 #define	LOG_INFO	CE_NOTE
390 #define	log	cmn_err
391 #endif
392 
393 /*
394  * Some internal error codes for driver functions.
395  */
396 #define	DCD_EACCES	1
397 
398 /*
399  * Error returns from sd_validate_geometry()
400  */
401 #define	DCD_BAD_LABEL		-1
402 #define	DCD_NO_MEM_FOR_LABEL	-2
403 
404 #ifdef	__cplusplus
405 }
406 #endif
407 
408 #endif	/* _SYS_DADA_TARGETS_DADDF_H */
409