xref: /illumos-gate/usr/src/uts/common/sys/dktp/tgdk.h (revision 342440ec)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*342440ecSPrasad Singamsetty  * Common Development and Distribution License (the "License").
6*342440ecSPrasad Singamsetty  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*342440ecSPrasad Singamsetty 
227c478bd9Sstevel@tonic-gate /*
23*342440ecSPrasad Singamsetty  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_DKTP_TGDK_H
287c478bd9Sstevel@tonic-gate #define	_SYS_DKTP_TGDK_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate struct	tgdk_ext {
357c478bd9Sstevel@tonic-gate 	unsigned	tg_rmb	: 1;
367c478bd9Sstevel@tonic-gate 	unsigned	tg_rdonly  : 1;
377c478bd9Sstevel@tonic-gate 	unsigned	tg_flag    : 6;
387c478bd9Sstevel@tonic-gate 	char		*tg_nodetype;
397c478bd9Sstevel@tonic-gate 	char		tg_ctype;
407c478bd9Sstevel@tonic-gate };
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate struct	tgdk_obj {
437c478bd9Sstevel@tonic-gate 	opaque_t		tg_data;
447c478bd9Sstevel@tonic-gate 	struct tgdk_objops	*tg_ops;
457c478bd9Sstevel@tonic-gate 	struct tgdk_ext		*tg_ext;
467c478bd9Sstevel@tonic-gate 	struct tgdk_ext		tg_extblk;	/* extended blk defined	*/
477c478bd9Sstevel@tonic-gate 						/* for easy of alloc	*/
487c478bd9Sstevel@tonic-gate };
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate struct	tgdk_iob {
517c478bd9Sstevel@tonic-gate 	struct	buf *b_bp;
527c478bd9Sstevel@tonic-gate 	daddr_t	b_lblk;
537c478bd9Sstevel@tonic-gate 	ssize_t	b_xfer;
547c478bd9Sstevel@tonic-gate 	daddr_t	b_psec;
557c478bd9Sstevel@tonic-gate 	ssize_t	b_pbytecnt;
567c478bd9Sstevel@tonic-gate 	short	b_pbyteoff;
577c478bd9Sstevel@tonic-gate 	short	b_flag;
587c478bd9Sstevel@tonic-gate };
597c478bd9Sstevel@tonic-gate typedef struct tgdk_iob *tgdk_iob_handle;
607c478bd9Sstevel@tonic-gate #define	IOB_BPALLOC	0x0001
617c478bd9Sstevel@tonic-gate #define	IOB_BPBUFALLOC	0x0002
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate struct	tgdk_geom {
647c478bd9Sstevel@tonic-gate 	int	g_cyl;
657c478bd9Sstevel@tonic-gate 	int	g_acyl;
667c478bd9Sstevel@tonic-gate 	int	g_head;
677c478bd9Sstevel@tonic-gate 	int	g_sec;
687c478bd9Sstevel@tonic-gate 	int	g_secsiz;
69*342440ecSPrasad Singamsetty 	diskaddr_t 	g_cap;
707c478bd9Sstevel@tonic-gate };
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate struct	tgdk_objops {
737c478bd9Sstevel@tonic-gate 	int  (*tg_init)(opaque_t, opaque_t, opaque_t, opaque_t, opaque_t,
747c478bd9Sstevel@tonic-gate 	    void *);
757c478bd9Sstevel@tonic-gate 	int  (*tg_free)(struct tgdk_obj *);
767c478bd9Sstevel@tonic-gate 	int  (*tg_probe)(opaque_t, int);
777c478bd9Sstevel@tonic-gate 	int  (*tg_attach)(opaque_t);
787c478bd9Sstevel@tonic-gate 	int  (*tg_open)(opaque_t, int);
797c478bd9Sstevel@tonic-gate 	int  (*tg_close)(opaque_t);
807c478bd9Sstevel@tonic-gate 	int  (*tg_ioctl)(opaque_t, dev_t, int, intptr_t, int, cred_t *, int *);
817c478bd9Sstevel@tonic-gate 	int  (*tg_strategy)(opaque_t, struct buf *);
827c478bd9Sstevel@tonic-gate 	int  (*tg_setgeom)(opaque_t, struct tgdk_geom *);
837c478bd9Sstevel@tonic-gate 	int  (*tg_getgeom)(opaque_t, struct tgdk_geom *);
847c478bd9Sstevel@tonic-gate 	tgdk_iob_handle	(*tg_iob_alloc)(opaque_t, daddr_t, ssize_t, int);
857c478bd9Sstevel@tonic-gate 	int  (*tg_iob_free)(opaque_t, struct tgdk_iob *);
867c478bd9Sstevel@tonic-gate 	caddr_t	(*tg_iob_htoc)(opaque_t, struct tgdk_iob *);
877c478bd9Sstevel@tonic-gate 	caddr_t	(*tg_iob_xfer)(opaque_t, struct tgdk_iob *, int);
887c478bd9Sstevel@tonic-gate 	int  (*tg_dump)(opaque_t, struct buf *);
897c478bd9Sstevel@tonic-gate 	int  (*tg_getphygeom)(opaque_t, struct tgdk_geom *);
907c478bd9Sstevel@tonic-gate 	int  (*tg_set_bbhobj)(opaque_t, opaque_t);
917c478bd9Sstevel@tonic-gate 	int  (*tg_check_media)(opaque_t, int *);
927c478bd9Sstevel@tonic-gate 	int  (*tg_inquiry)(opaque_t, opaque_t *);
937c478bd9Sstevel@tonic-gate 	void (*tg_cleanup)(struct tgdk_obj *);
947c478bd9Sstevel@tonic-gate 	void *tg_resv[1];
957c478bd9Sstevel@tonic-gate };
967c478bd9Sstevel@tonic-gate 
9743369e13Slclee struct tgdk_obj *dadk_create();
9843369e13Slclee 
997c478bd9Sstevel@tonic-gate #define	TGDK_GETNODETYPE(X) (((struct tgdk_obj *)(X))->tg_ext->tg_nodetype)
1007c478bd9Sstevel@tonic-gate #define	TGDK_SETNODETYPE(X, Y) \
1017c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_ext->tg_nodetype = (char *)(Y))
1027c478bd9Sstevel@tonic-gate #define	TGDK_RMB(X) 	(((struct tgdk_obj *)(X))->tg_ext->tg_rmb)
1037c478bd9Sstevel@tonic-gate #define	TGDK_RDONLY(X) 	(((struct tgdk_obj *)(X))->tg_ext->tg_rdonly)
1047c478bd9Sstevel@tonic-gate #define	TGDK_GETCTYPE(X) (((struct tgdk_obj *)(X))->tg_ext->tg_ctype)
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #define	TGDK_INIT(X, devp, flcobjp, queobjp, bbhobjp, lkarg) \
1087c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_init) \
1097c478bd9Sstevel@tonic-gate 		(((struct tgdk_obj *)(X))->tg_data, (devp), (flcobjp), \
1107c478bd9Sstevel@tonic-gate 		(queobjp), (bbhobjp), (lkarg))
1117c478bd9Sstevel@tonic-gate #define	TGDK_INIT_X(X, devp, flcobjp, queobjp, bbhobjp, lkarg, cbfunc, cbarg) \
1127c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_init) \
1137c478bd9Sstevel@tonic-gate 		(((struct tgdk_obj *)(X))->tg_data, (devp), (flcobjp), \
1147c478bd9Sstevel@tonic-gate 		(queobjp), (bbhobjp), (lkarg), (cbfunc), (cbarg))
1157c478bd9Sstevel@tonic-gate #define	TGDK_FREE(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_free) ((X))
1167c478bd9Sstevel@tonic-gate #define	TGDK_PROBE(X, WAIT) (*((struct tgdk_obj *)(X))->tg_ops->tg_probe) \
1177c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (WAIT))
1187c478bd9Sstevel@tonic-gate #define	TGDK_ATTACH(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_attach) \
1197c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data)
1207c478bd9Sstevel@tonic-gate #define	TGDK_OPEN(X, flag) (*((struct tgdk_obj *)(X))->tg_ops->tg_open) \
1217c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (flag))
1227c478bd9Sstevel@tonic-gate #define	TGDK_CLOSE(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_close) \
1237c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data)
1247c478bd9Sstevel@tonic-gate #define	TGDK_IOCTL(X, dev, cmd, arg, flag, cred_p, rval_p) \
1257c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_ioctl) \
1267c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (dev), (cmd), (arg), (flag), \
1277c478bd9Sstevel@tonic-gate 		(cred_p), (rval_p))
1287c478bd9Sstevel@tonic-gate #define	TGDK_STRATEGY(X, bp) (*((struct tgdk_obj *)(X))->tg_ops->tg_strategy) \
1297c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (bp))
1307c478bd9Sstevel@tonic-gate #define	TGDK_GETGEOM(X, datap) (*((struct tgdk_obj *)(X))->tg_ops->tg_getgeom) \
1317c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (datap))
1327c478bd9Sstevel@tonic-gate #define	TGDK_SETGEOM(X, datap) (*((struct tgdk_obj *)(X))->tg_ops->tg_setgeom) \
1337c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (datap))
1347c478bd9Sstevel@tonic-gate #define	TGDK_IOB_ALLOC(X, logblk, xfer, sleep) \
1357c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_alloc) \
1367c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (logblk), (xfer), (sleep))
1377c478bd9Sstevel@tonic-gate #define	TGDK_IOB_FREE(X, datap) \
1387c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_free) \
1397c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (datap))
1407c478bd9Sstevel@tonic-gate #define	TGDK_IOB_HTOC(X, handle) \
1417c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_htoc) \
1427c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (handle))
1437c478bd9Sstevel@tonic-gate #define	TGDK_IOB_RD(X, handle) \
1447c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_xfer) \
1457c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (handle), B_READ)
1467c478bd9Sstevel@tonic-gate #define	TGDK_IOB_WR(X, handle) \
1477c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_xfer) \
1487c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (handle), B_WRITE)
1497c478bd9Sstevel@tonic-gate #define	TGDK_DUMP(X, bp) (*((struct tgdk_obj *)(X))->tg_ops->tg_dump) \
1507c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (bp))
1517c478bd9Sstevel@tonic-gate #define	TGDK_GETPHYGEOM(X, datap) \
1527c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_getphygeom) \
1537c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (datap))
1547c478bd9Sstevel@tonic-gate #define	TGDK_SET_BBHOBJ(X, objp) \
1557c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_set_bbhobj) \
1567c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (objp))
1577c478bd9Sstevel@tonic-gate #define	TGDK_CHECK_MEDIA(X, state) \
1587c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_check_media) \
1597c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (state))
1607c478bd9Sstevel@tonic-gate #define	TGDK_INQUIRY(X, inqpp) \
1617c478bd9Sstevel@tonic-gate 	(*((struct tgdk_obj *)(X))->tg_ops->tg_inquiry) \
1627c478bd9Sstevel@tonic-gate 	(((struct tgdk_obj *)(X))->tg_data, (inqpp))
1637c478bd9Sstevel@tonic-gate #define	TGDK_CLEANUP(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_cleanup) ((X))
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #define	LBLK2SEC(BLK, SHF) (daddr_t)((BLK) >> (SHF))
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #define	SETBPERR	bioerror
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #define	DK_MAXRECSIZE	(256<<10)	/* maximum io record size 	*/
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate #endif
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #endif	/* _SYS_DKTP_TGDK_H */
176