xref: /titanic_50/usr/src/uts/common/sys/dktp/dadk.h (revision abc79d9dd51e98eafb6fc25b4a0b4f66bef40b00)
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_DKTP_DADK_H
27 #define	_SYS_DKTP_DADK_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/dktp/tgcom.h>
36 
37 struct	dadk {
38 	struct tgdk_ext	*dad_extp;	/* back pointer to ext data	*/
39 	struct scsi_device *dad_sd;	/* back pointer to SCSI_DEVICE 	*/
40 
41 	struct  tgdk_geom dad_logg;	/* logical disk geometry 	*/
42 	struct  tgdk_geom dad_phyg;	/* physical disk geometry 	*/
43 
44 	unsigned dad_rmb : 1;		/* removable device		*/
45 	unsigned dad_rdonly : 1;	/* read only device		*/
46 	unsigned dad_cdrom : 1;		/* cdrom device			*/
47 	unsigned dad_noflush : 1;	/* flush cmd unsupported	*/
48 	unsigned dad_wce : 1;		/* disk write cache enabled	*/
49 	unsigned dad_resv : 3;
50 	unsigned char dad_type;		/* device type			*/
51 	unsigned char dad_ctype;	/* controller type 		*/
52 
53 	short	 dad_secshf;
54 	short	 dad_blkshf;
55 
56 	opaque_t dad_bbhobjp;		/* bbh object ptr		*/
57 	opaque_t dad_flcobjp;		/* flow control object ptr	*/
58 	opaque_t dad_ctlobjp;		/* controller object ptr	*/
59 	struct	tgcom_obj dad_com;	/* com object for flowctrl	*/
60 	enum dkio_state dad_iostate;	/* ejected/inserted		*/
61 	kmutex_t	dad_mutex;	/* protect dad_state		*/
62 	kcondvar_t	dad_state_cv;	/* condition variable for state */
63 	uchar_t		dad_thread_cnt;	/* reference count on removable	*/
64 					/* - disk state watcher thread	*/
65 	kstat_t		*dad_errstats;	/* error stats			*/
66 	kmutex_t	dad_cmd_mutex;
67 	int		dad_cmd_count;
68 };
69 
70 #define	DAD_SECSIZ	dad_phyg.g_secsiz
71 
72 /*
73  * Local definitions, for clarity of code
74  */
75 
76 /*
77  * Parameters
78  */
79 #define	DADK_BSY_TIMEOUT	(drv_usectohz(5 * 1000000))
80 #define	DADK_IO_TIME		35
81 #define	DADK_FLUSH_CACHE_TIME	60
82 #define	DADK_RETRY_COUNT	5
83 #define	DADK_SILENT		1
84 
85 #define	PKT2DADK(pktp)	((struct dadk *)(pktp)->cp_dev_private)
86 
87 /*
88  * packet action codes
89  */
90 #define	COMMAND_DONE		0
91 #define	COMMAND_DONE_ERROR	1
92 #define	QUE_COMMAND		2
93 #define	QUE_SENSE		3
94 #define	JUST_RETURN		4
95 
96 typedef	struct	dadk_errstats {
97 	kstat_named_t dadk_softerrs;		/* Collecting Softerrs */
98 	kstat_named_t dadk_harderrs;		/* Collecting harderrs */
99 	kstat_named_t dadk_transerrs;		/* Collecting Transfer errs */
100 	kstat_named_t dadk_model;		/* model # of the disk */
101 	kstat_named_t dadk_revision;		/* The disk revision */
102 	kstat_named_t dadk_serial;		/* The disk serial number */
103 	kstat_named_t dadk_capacity;		/* Capacity of the disk */
104 	kstat_named_t dadk_rq_media_err;	/* Any media err seen */
105 	kstat_named_t dadk_rq_ntrdy_err;	/* Not ready errs */
106 	kstat_named_t dadk_rq_nodev_err;	/* No device errs */
107 	kstat_named_t dadk_rq_recov_err;	/* Recovered errs */
108 	kstat_named_t dadk_rq_illrq_err;	/* Illegal requests */
109 } dadk_errstats_t;
110 
111 int dadk_init(opaque_t objp, opaque_t devp, opaque_t flcobjp,
112     opaque_t queobjp, opaque_t bbhobjp, void *lkarg);
113 int dadk_free(struct tgdk_obj *dkobjp);
114 int dadk_probe(opaque_t objp, int kmsflg);
115 int dadk_attach(opaque_t objp);
116 int dadk_open(opaque_t objp, int flag);
117 int dadk_close(opaque_t objp);
118 int dadk_ioctl(opaque_t objp, dev_t dev, int cmd, intptr_t arg,
119     int flag, cred_t *cred_p, int *rval_p);
120 int dadk_flushdone(struct buf *bp);
121 int dadk_strategy(opaque_t objp, struct buf *bp);
122 int dadk_setgeom(opaque_t objp, struct tgdk_geom *dkgeom_p);
123 int dadk_getgeom(opaque_t objp, struct tgdk_geom *dkgeom_p);
124 struct tgdk_iob *dadk_iob_alloc(opaque_t objp, daddr_t blkno,
125     ssize_t xfer, int kmsflg);
126 int dadk_iob_free(opaque_t objp, struct tgdk_iob *iobp);
127 caddr_t dadk_iob_htoc(opaque_t objp, struct tgdk_iob *iobp);
128 caddr_t dadk_iob_xfer(opaque_t objp, struct tgdk_iob *iobp, int rw);
129 int dadk_dump(opaque_t objp, struct buf *bp);
130 int dadk_getphygeom(opaque_t objp, struct tgdk_geom *dkgeom_p);
131 int dadk_set_bbhobj(opaque_t objp, opaque_t bbhobjp);
132 int dadk_check_media(opaque_t objp, int *state);
133 static void dadk_watch_thread(struct dadk *dadkp);
134 int dadk_inquiry(opaque_t objp, opaque_t *inqpp);
135 void dadk_cleanup(struct tgdk_obj *dkobjp);
136 
137 int dadk_getcmds(opaque_t objp);
138 
139 #ifdef	__cplusplus
140 }
141 #endif
142 
143 #endif	/* _SYS_DKTP_DADK_H */
144