xref: /titanic_41/usr/src/uts/common/sys/dkio.h (revision 8d483882aa3390058094b043f3d62187b5d1de03)
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_DKIO_H
27 #define	_SYS_DKIO_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS-4.0 5.19 */
30 
31 #include <sys/dklabel.h>	/* Needed for NDKMAP define */
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Structures and definitions for disk io control commands
39  */
40 
41 /*
42  * Structures used as data by ioctl calls.
43  */
44 
45 #define	DK_DEVLEN	16		/* device name max length, including */
46 					/* unit # & NULL (ie - "xyc1") */
47 
48 /*
49  * Used for controller info
50  */
51 struct dk_cinfo {
52 	char	dki_cname[DK_DEVLEN];	/* controller name (no unit #) */
53 	ushort_t dki_ctype;		/* controller type */
54 	ushort_t dki_flags;		/* flags */
55 	ushort_t dki_cnum;		/* controller number */
56 	uint_t	dki_addr;		/* controller address */
57 	uint_t	dki_space;		/* controller bus type */
58 	uint_t	dki_prio;		/* interrupt priority */
59 	uint_t	dki_vec;		/* interrupt vector */
60 	char	dki_dname[DK_DEVLEN];	/* drive name (no unit #) */
61 	uint_t	dki_unit;		/* unit number */
62 	uint_t	dki_slave;		/* slave number */
63 	ushort_t dki_partition;		/* partition number */
64 	ushort_t dki_maxtransfer;	/* max. transfer size in DEV_BSIZE */
65 };
66 
67 /*
68  * Controller types
69  */
70 #define	DKC_UNKNOWN	0
71 #define	DKC_CDROM	1	/* CD-ROM, SCSI or otherwise */
72 #define	DKC_WDC2880	2
73 #define	DKC_XXX_0	3	/* unassigned */
74 #define	DKC_XXX_1	4	/* unassigned */
75 #define	DKC_DSD5215	5
76 #define	DKC_ACB4000	7
77 #define	DKC_MD21	8
78 #define	DKC_XXX_2	9	/* unassigned */
79 #define	DKC_NCRFLOPPY	10
80 #define	DKC_SMSFLOPPY	12
81 #define	DKC_SCSI_CCS	13	/* SCSI CCS compatible */
82 #define	DKC_INTEL82072	14	/* native floppy chip */
83 #define	DKC_MD		16	/* meta-disk (virtual-disk) driver */
84 #define	DKC_INTEL82077	19	/* 82077 floppy disk controller */
85 #define	DKC_DIRECT	20	/* Intel direct attached device i.e. IDE */
86 #define	DKC_PCMCIA_MEM	21	/* PCMCIA memory disk-like type */
87 #define	DKC_PCMCIA_ATA	22	/* PCMCIA AT Attached type */
88 #define	DKC_VBD		23	/* virtual block device */
89 
90 /*
91  * Sun reserves up through 1023
92  */
93 
94 #define	DKC_CUSTOMER_BASE	1024
95 
96 /*
97  * Flags
98  */
99 #define	DKI_BAD144	0x01	/* use DEC std 144 bad sector fwding */
100 #define	DKI_MAPTRK	0x02	/* controller does track mapping */
101 #define	DKI_FMTTRK	0x04	/* formats only full track at a time */
102 #define	DKI_FMTVOL	0x08	/* formats only full volume at a time */
103 #define	DKI_FMTCYL	0x10	/* formats only full cylinders at a time */
104 #define	DKI_HEXUNIT	0x20	/* unit number is printed as 3 hex digits */
105 #define	DKI_PCMCIA_PFD	0x40	/* PCMCIA pseudo-floppy memory card */
106 
107 /*
108  * Used for all partitions
109  */
110 struct dk_allmap {
111 	struct dk_map	dka_map[NDKMAP];
112 };
113 
114 #if defined(_SYSCALL32)
115 struct dk_allmap32 {
116 	struct dk_map32	dka_map[NDKMAP];
117 };
118 #endif /* _SYSCALL32 */
119 
120 /*
121  * Definition of a disk's geometry
122  */
123 struct dk_geom {
124 	unsigned short	dkg_ncyl;	/* # of data cylinders */
125 	unsigned short	dkg_acyl;	/* # of alternate cylinders */
126 	unsigned short	dkg_bcyl;	/* cyl offset (for fixed head area) */
127 	unsigned short	dkg_nhead;	/* # of heads */
128 	unsigned short	dkg_obs1;	/* obsolete */
129 	unsigned short	dkg_nsect;	/* # of data sectors per track */
130 	unsigned short	dkg_intrlv;	/* interleave factor */
131 	unsigned short	dkg_obs2;	/* obsolete */
132 	unsigned short	dkg_obs3;	/* obsolete */
133 	unsigned short	dkg_apc;	/* alternates per cyl (SCSI only) */
134 	unsigned short	dkg_rpm;	/* revolutions per minute */
135 	unsigned short	dkg_pcyl;	/* # of physical cylinders */
136 	unsigned short	dkg_write_reinstruct;	/* # sectors to skip, writes */
137 	unsigned short	dkg_read_reinstruct;	/* # sectors to skip, reads */
138 	unsigned short	dkg_extra[7];	/* for compatible expansion */
139 };
140 
141 /*
142  * These defines are for historic compatibility with old drivers.
143  */
144 #define	dkg_bhead	dkg_obs1	/* used to be head offset */
145 #define	dkg_gap1	dkg_obs2	/* used to be gap1 */
146 #define	dkg_gap2	dkg_obs3	/* used to be gap2 */
147 
148 /*
149  * Disk io control commands
150  * Warning: some other ioctls with the DIOC prefix exist elsewhere.
151  * The Generic DKIOC numbers are from	0   -  50.
152  *	The Floppy Driver uses		51  - 100.
153  *	The Hard Disk (except SCSI)	101 - 106.	(these are obsolete)
154  *	The CDROM Driver		151 - 200.
155  *	The USCSI ioctl			201 - 250.
156  */
157 #define	DKIOC		(0x04 << 8)
158 
159 /*
160  * The following ioctls are generic in nature and need to be
161  * suported as appropriate by all disk drivers
162  */
163 #define	DKIOCGGEOM	(DKIOC|1)		/* Get geometry */
164 #define	DKIOCINFO	(DKIOC|3)		/* Get info */
165 #define	DKIOCEJECT	(DKIOC|6)		/* Generic 'eject' */
166 #define	DKIOCGVTOC	(DKIOC|11)		/* Get VTOC */
167 #define	DKIOCSVTOC	(DKIOC|12)		/* Set VTOC & Write to Disk */
168 
169 /*
170  * Disk Cache Controls.  These ioctls should be supported by
171  * all disk drivers.
172  *
173  * DKIOCFLUSHWRITECACHE when used from user-mode ignores the ioctl
174  * argument, but it should be passed as NULL to allow for future
175  * reinterpretation.  From user-mode, this ioctl request is synchronous.
176  *
177  * When invoked from within the kernel, the arg can be NULL to indicate
178  * a synchronous request or can be the address of a struct dk_callback
179  * to request an asynchronous callback when the flush request is complete.
180  * In this case, the flag to the ioctl must include FKIOCTL and the
181  * dkc_callback field of the pointed to struct must be non-null or the
182  * request is made synchronously.
183  *
184  * In the callback case: if the ioctl returns 0, a callback WILL be performed.
185  * If the ioctl returns non-zero, a callback will NOT be performed.
186  * NOTE: In some cases, the callback may be done BEFORE the ioctl call
187  * returns.  The caller's locking strategy should be prepared for this case.
188  */
189 #define	DKIOCFLUSHWRITECACHE	(DKIOC|34)	/* flush cache to phys medium */
190 
191 struct dk_callback {
192 	void (*dkc_callback)(void *dkc_cookie, int error);
193 	void *dkc_cookie;
194 };
195 
196 #define	DKIOCGETWCE		(DKIOC|36)	/* Get current write cache */
197 						/* enablement status */
198 #define	DKIOCSETWCE		(DKIOC|37)	/* Enable/Disable write cache */
199 
200 /*
201  * The following ioctls are used by Sun drivers to communicate
202  * with their associated format routines. Support of these ioctls
203  * is not required of foreign drivers
204  */
205 #define	DKIOCSGEOM	(DKIOC|2)		/* Set geometry */
206 #define	DKIOCSAPART	(DKIOC|4)		/* Set all partitions */
207 #define	DKIOCGAPART	(DKIOC|5)		/* Get all partitions */
208 #define	DKIOCG_PHYGEOM	(DKIOC|32)		/* get physical geometry */
209 #define	DKIOCG_VIRTGEOM	(DKIOC|33)		/* get virtual geometry */
210 
211 /*
212  * The following ioctl's are removable media support
213  */
214 #define	DKIOCLOCK	(DKIOC|7)	/* Generic 'lock' */
215 #define	DKIOCUNLOCK	(DKIOC|8)	/* Generic 'unlock' */
216 #define	DKIOCSTATE	(DKIOC|13)	/* Inquire insert/eject state */
217 #define	DKIOCREMOVABLE	(DKIOC|16)	/* is media removable */
218 
219 
220 /*
221  * ioctl for hotpluggable devices
222  */
223 #define	DKIOCHOTPLUGGABLE	(DKIOC|35)	/* is hotpluggable */
224 
225 /*
226  * Ioctl to force driver to re-read the alternate partition and rebuild
227  * the internal defect map.
228  */
229 #define	DKIOCADDBAD	(DKIOC|20)	/* Re-read the alternate map (IDE) */
230 #define	DKIOCGETDEF	(DKIOC|21)	/* read defect list (IDE)	   */
231 
232 /*
233  * Used by applications to get disk defect information from IDE
234  * drives.
235  */
236 #ifdef _SYSCALL32
237 struct defect_header32 {
238 	int		head;
239 	caddr32_t	buffer;
240 };
241 #endif /* _SYSCALL32 */
242 
243 struct defect_header {
244 	int		head;
245 	caddr_t		buffer;
246 };
247 
248 #define	DKIOCPARTINFO	(DKIOC|22)	/* Get partition or slice parameters */
249 
250 /*
251  * Used by applications to get partition or slice information
252  */
253 #ifdef _SYSCALL32
254 struct part_info32 {
255 	daddr32_t	p_start;
256 	int		p_length;
257 };
258 #endif /* _SYSCALL32 */
259 
260 struct part_info {
261 	daddr_t		p_start;
262 	int		p_length;
263 };
264 
265 /* The following ioctls are for Optical Memory Device */
266 #define	DKIOC_EBP_ENABLE  (DKIOC|40)	/* enable by pass erase on write */
267 #define	DKIOC_EBP_DISABLE (DKIOC|41)	/* disable by pass erase on write */
268 
269 /*
270  * This state enum is the argument passed to the DKIOCSTATE ioctl.
271  */
272 enum dkio_state { DKIO_NONE, DKIO_EJECTED, DKIO_INSERTED, DKIO_DEV_GONE };
273 
274 #define	DKIOCGMEDIAINFO	(DKIOC|42)	/* get information about the media */
275 
276 /*
277  * ioctls to read/write mboot info.
278  */
279 #define	DKIOCGMBOOT	(DKIOC|43)	/* get mboot info */
280 #define	DKIOCSMBOOT	(DKIOC|44)	/* set mboot info */
281 
282 /*
283  * ioctl to get the device temperature.
284  */
285 #define	DKIOCGTEMPERATURE	(DKIOC|45)	/* get temperature */
286 
287 /*
288  * Used for providing the temperature.
289  */
290 
291 struct	dk_temperature	{
292 	uint_t		dkt_flags;	/* Flags */
293 	short		dkt_cur_temp;	/* Current disk temperature */
294 	short		dkt_ref_temp;	/* reference disk temperature */
295 };
296 
297 #define	DKT_BYPASS_PM		0x1
298 #define	DKT_INVALID_TEMP	0xFFFF
299 
300 
301 /*
302  * Used for Media info or the current profile info
303  */
304 struct dk_minfo {
305 	uint_t		dki_media_type;	/* Media type or profile info */
306 	uint_t		dki_lbsize;	/* Logical blocksize of media */
307 	diskaddr_t	dki_capacity;	/* Capacity as # of dki_lbsize blks */
308 };
309 
310 /*
311  * Media types or profiles known
312  */
313 #define	DK_UNKNOWN		0x00	/* Media inserted - type unknown */
314 
315 
316 /*
317  * SFF 8090 Specification Version 3, media types 0x01 - 0xfffe are retained to
318  * maintain compatibility with SFF8090.  The following define the
319  * optical media type.
320  */
321 #define	DK_REMOVABLE_DISK	0x02 /* Removable Disk */
322 #define	DK_MO_ERASABLE		0x03 /* MO Erasable */
323 #define	DK_MO_WRITEONCE		0x04 /* MO Write once */
324 #define	DK_AS_MO		0x05 /* AS MO */
325 #define	DK_CDROM		0x08 /* CDROM */
326 #define	DK_CDR			0x09 /* CD-R */
327 #define	DK_CDRW			0x0A /* CD-RW */
328 #define	DK_DVDROM		0x10 /* DVD-ROM */
329 #define	DK_DVDR			0x11 /* DVD-R */
330 #define	DK_DVDRAM		0x12 /* DVD_RAM or DVD-RW */
331 
332 /*
333  * Media types for other rewritable magnetic media
334  */
335 #define	DK_FIXED_DISK		0x10001	/* Fixed disk SCSI or otherwise */
336 #define	DK_FLOPPY		0x10002 /* Floppy media */
337 #define	DK_ZIP			0x10003 /* IOMEGA ZIP media */
338 #define	DK_JAZ			0x10004 /* IOMEGA JAZ media */
339 
340 #define	DKIOCSETEFI	(DKIOC|17)		/* Set EFI info */
341 #define	DKIOCGETEFI	(DKIOC|18)		/* Get EFI info */
342 
343 #define	DKIOCPARTITION	(DKIOC|9)		/* Get partition info */
344 
345 /*
346  * Ioctls to get/set volume capabilities related to Logical Volume Managers.
347  * They include the ability to get/set capabilities and to issue a read to a
348  * specific underlying device of a replicated device.
349  */
350 
351 #define	DKIOCGETVOLCAP	(DKIOC | 25)	/* Get volume capabilities */
352 #define	DKIOCSETVOLCAP	(DKIOC | 26)	/* Set volume capabilities */
353 #define	DKIOCDMR	(DKIOC | 27)	/* Issue a directed read */
354 
355 typedef uint_t volcapinfo_t;
356 
357 typedef uint_t volcapset_t;
358 
359 #define	DKV_ABR_CAP 0x00000001		/* Support Appl.Based Recovery */
360 #define	DKV_DMR_CAP 0x00000002		/* Support Directed  Mirror Read */
361 
362 typedef struct volcap {
363 	volcapinfo_t vc_info;	/* Capabilities available */
364 	volcapset_t vc_set;	/* Capabilities set */
365 } volcap_t;
366 
367 #define	VOL_SIDENAME 256
368 
369 typedef struct vol_directed_rd {
370 	int		vdr_flags;
371 	offset_t	vdr_offset;
372 	size_t		vdr_nbytes;
373 	size_t		vdr_bytesread;
374 	void		*vdr_data;
375 	int		vdr_side;
376 	char		vdr_side_name[VOL_SIDENAME];
377 } vol_directed_rd_t;
378 
379 #define	DKV_SIDE_INIT		(-1)
380 #define	DKV_DMR_NEXT_SIDE	0x00000001
381 #define	DKV_DMR_DONE		0x00000002
382 #define	DKV_DMR_ERROR		0x00000004
383 #define	DKV_DMR_SUCCESS		0x00000008
384 #define	DKV_DMR_SHORT		0x00000010
385 
386 #ifdef _MULTI_DATAMODEL
387 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
388 #pragma pack(4)
389 #endif
390 typedef struct vol_directed_rd32 {
391 	int32_t		vdr_flags;
392 	offset_t	vdr_offset;	/* 64-bit element on 32-bit alignment */
393 	size32_t	vdr_nbytes;
394 	size32_t	vdr_bytesread;
395 	caddr32_t	vdr_data;
396 	int32_t		vdr_side;
397 	char		vdr_side_name[VOL_SIDENAME];
398 } vol_directed_rd32_t;
399 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
400 #pragma pack()
401 #endif
402 #endif	/* _MULTI_DATAMODEL */
403 
404 /*
405  * The ioctl is used to fetch disk's device type, vendor ID,
406  * model number/product ID, firmware revision and serial number together.
407  *
408  * Currently there are two device types - DKD_ATA_TYPE which means the
409  * disk is driven by cmdk/ata or dad/uata driver, and DKD_SCSI_TYPE
410  * which means the disk is driven by sd/scsi hba driver.
411  */
412 #define	DKIOC_GETDISKID	(DKIOC|46)
413 
414 /* These two labels are for dkd_dtype of dk_disk_id_t */
415 #define	DKD_ATA_TYPE	0x01 /* ATA disk or legacy mode SATA disk */
416 #define	DKD_SCSI_TYPE	0x02 /* SCSI disk or native mode SATA disk */
417 
418 #define	DKD_ATA_MODEL	40	/* model number length */
419 #define	DKD_ATA_FWVER	8	/* firmware revision length */
420 #define	DKD_ATA_SERIAL	20	/* serial number length */
421 
422 #define	DKD_SCSI_VENDOR	8	/* vendor ID length */
423 #define	DKD_SCSI_PRODUCT 16	/* product ID length */
424 #define	DKD_SCSI_REVLEVEL 4	/* revision level length */
425 #define	DKD_SCSI_SERIAL 12	/* serial number length */
426 
427 /*
428  * The argument type for DKIOC_GETDISKID ioctl.
429  */
430 typedef struct dk_disk_id {
431 	uint_t	dkd_dtype;
432 	union {
433 		struct {
434 			char dkd_amodel[DKD_ATA_MODEL];		/* 40 bytes */
435 			char dkd_afwver[DKD_ATA_FWVER];		/* 8 bytes */
436 			char dkd_aserial[DKD_ATA_SERIAL];	/* 20 bytes */
437 		} ata_disk_id;
438 		struct {
439 			char dkd_svendor[DKD_SCSI_VENDOR];	/* 8 bytes */
440 			char dkd_sproduct[DKD_SCSI_PRODUCT];	/* 16 bytes */
441 			char dkd_sfwver[DKD_SCSI_REVLEVEL];	/* 4 bytes */
442 			char dkd_sserial[DKD_SCSI_SERIAL];	/* 12 bytes */
443 		} scsi_disk_id;
444 	} disk_id;
445 } dk_disk_id_t;
446 
447 /*
448  * The ioctl is used to update the firmware of device.
449  */
450 #define	DKIOC_UPDATEFW		(DKIOC|47)
451 
452 /* The argument type for DKIOC_UPDATEFW ioctl */
453 typedef struct dk_updatefw {
454 	caddr_t		dku_ptrbuf;	/* pointer to firmware buf */
455 	uint_t		dku_size;	/* firmware buf length */
456 	uint8_t		dku_type;	/* firmware update type */
457 } dk_updatefw_t;
458 
459 #ifdef _SYSCALL32
460 typedef struct dk_updatefw_32 {
461 	caddr32_t	dku_ptrbuf;	/* pointer to firmware buf */
462 	uint_t		dku_size;	/* firmware buf length */
463 	uint8_t		dku_type;	/* firmware update type */
464 } dk_updatefw_32_t;
465 #endif /* _SYSCALL32 */
466 
467 /*
468  * firmware update type - temporary or permanent use
469  */
470 #define	FW_TYPE_TEMP	0x0		/* temporary use */
471 #define	FW_TYPE_PERM	0x1		/* permanent use */
472 
473 
474 #ifdef	__cplusplus
475 }
476 #endif
477 
478 #endif /* _SYS_DKIO_H */
479