xref: /titanic_44/usr/src/uts/common/avs/ns/sdbc/sd_iob.h (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 
27 #ifndef	_SD_IOB_H
28 #define	_SD_IOB_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #define	MAX_HOOK_LOCKS	32
35 typedef int (*dcb_t)(struct buf *);	/* driver callback type */
36 
37 /*
38  * order of end action calls:
39  * driver callback (iob_drv_iodone) is stuffed in b_iodone and called by
40  * the device driver when i/o completes.  It calls the hook end action
41  * (iob_hook_iodone) which maintains the completion count (iob_hook.count)
42  * and calls the clients end action (iob_hook.func) when the chain is complete.
43  */
44 typedef struct iob_hook {
45 		struct iob_hook *next_hook;
46 		struct buf	*chain;	/* all the buffers for this iob */
47 		struct buf	*tail;	/* tail of buffer chain */
48 		int	count;		/* number of bufs on the chain */
49 		nsc_off_t start_fba;	/* initial disk block for the xfer */
50 		nsc_off_t last_fba;	/* last disk block for the xfer */
51 		nsc_size_t size;	/* # bytes for entire transfer */
52 		unsigned char *last_vaddr; /* ending addr of last i/o request */
53 		sdbc_ea_fn_t func;	/* clients end action routine */
54 		int	(* iob_hook_iodone)(struct buf *, struct iob_hook *);
55 		dcb_t	iob_drv_iodone; /* driver call back */
56 		blind_t	param;		/* param for clnt end action routine */
57 		int	flags;		/* flags for each buffer */
58 		int	error;		/* any error */
59 		int	skipped;	/* this iob used sd_add_mem */
60 		kmutex_t *lockp;	/* mutex for releasing buffers */
61 		kcondvar_t wait;	/* sync for sleeping on synch i/o */
62 #ifdef _SD_BIO_STATS
63 		int	PAGE_IO, NORM_IO, SKIP_IO;
64 		int	PAGE_COMBINED;
65 		nsc_size_t NORM_IO_SIZE;
66 #endif /* _SD_BIO_STATS */
67 	} iob_hook_t;
68 
69 typedef struct _sd_buf_list {
70 	iob_hook_t	*hooks;		/* all of the iob hooks */
71 	iob_hook_t	*hook_head;	/* free iob hook */
72 	int		bl_init_count;  /* total count */
73 	int		bl_hooks_avail;  /* monitor available hook count */
74 	int 		bl_hook_lowmark; /* record if ever run out of hooks */
75 	int		hook_waiters;	/* count of waiters */
76 	int		max_hook_waiters; /* record max ever waiters */
77 	kcondvar_t	hook_wait;	/* sync for sleeping on synch i/o */
78 	kmutex_t	hook_locks[MAX_HOOK_LOCKS];
79 } _sd_buf_list_t;
80 
81 /*
82  * NOTE: if you change this, then also make changes to the generation
83  * of sd_iob_impl*.c in src/uts/common/Makefile.files and Makefile.rules!
84  */
85 #define	_SD_DEFAULT_IOBUFS 4096
86 
87 /* define driver callback and driver callback function table */
88 
89 #define	IOB_DCBP(i) (sd_iob_dcb ## i)
90 
91 #define	IOB_DCB(i)	\
92 	int	\
93 	IOB_DCBP(i)(struct buf *bp)	\
94 	{		\
95 		return ((*_sd_buflist.hooks[i].iob_hook_iodone)	\
96 				(bp, &_sd_buflist.hooks[i]));	\
97 	}
98 
99 extern _sd_buf_list_t _sd_buflist;
100 
101 #ifdef	__cplusplus
102 }
103 #endif
104 
105 #endif	/* _SD_IOB_H */
106