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