xref: /titanic_41/usr/src/uts/common/xen/io/xdb.h (revision 2dd2efa5a06a9befe46075cf41e16f57533c9f98)
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 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 
28 #ifndef _SYS_XDB_H
29 #define	_SYS_XDB_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define	XDB_DBG_ALL	0xf
38 #define	XDB_DBG_IO	0x1
39 #define	XDB_DBG_INFO	0x2
40 #define	XDB_DBPRINT(lvl, fmt) { if (xdb_debug & lvl) cmn_err fmt; }
41 
42 /*
43  * Info of the exported blk device
44  */
45 #define	XDB_DEV_RO	(1)	/* read-only or writable */
46 #define	XDB_IS_RO(vdp)	((vdp)->xs_type & XDB_DEV_RO)
47 #define	XDB_DEV_LOFI	(1 << 1) /* lofi device or physical device */
48 #define	XDB_IS_LOFI(vdp)	((vdp)->xs_type & XDB_DEV_LOFI)
49 #define	XDB_DEV_CD	(1 << 2) /* cdrom disc */
50 #define	XDB_IS_CD(vdp)	((vdp)->xs_type & XDB_DEV_CD)
51 #define	XDB_DEV_RMB	(1 << 3) /* removable device */
52 #define	XDB_IS_RMB(vdp)	((vdp)->xs_type & XDB_DEV_RMB)
53 
54 /*
55  * Xdb interface status
56  */
57 enum xdb_state {
58 	/*
59 	 * initial state
60 	 */
61 	XDB_UNKNOWN,
62 	/*
63 	 * frontend xenbus state changed to XenbusStateConnected,
64 	 * we finally connect
65 	 */
66 	XDB_CONNECTED,
67 	/*
68 	 * frontend xenbus state changed to XenbusStateClosed,
69 	 * interface disconnected
70 	 */
71 	XDB_DISCONNECTED
72 };
73 
74 /*
75  * backend device status
76  */
77 enum xdb_dev_state {
78 	/* initial state */
79 	XDB_DEV_UNKNOWN,
80 	/* backend device is ready (hotplug script finishes successfully) */
81 	XDB_DEV_READY
82 };
83 
84 /*
85  * frontend status
86  */
87 enum xdb_fe_state {
88 	/* initial state */
89 	XDB_FE_UNKNOWN,
90 	/*
91 	 * frontend's xenbus state has changed to
92 	 * XenbusStateInitialised, is ready for connecting
93 	 */
94 	XDB_FE_READY
95 };
96 
97 /*
98  * Other handy macrosx
99  */
100 #define	XDB_MINOR2INST(m)	(int)(m)
101 #define	XDB_INST2MINOR(i)	(minor_t)(i)
102 #define	XDB_INST2SOFTS(instance)			\
103 	((xdb_t *)ddi_get_soft_state(xdb_statep, (instance)))
104 #define	XDB_MAX_IO_PAGES BLKIF_RING_SIZE * BLKIF_MAX_SEGMENTS_PER_REQUEST
105 /* get kva of a mapped-in page coresponding to (xreq-index, seg) pair */
106 #define	XDB_IOPAGE_VA(_pagebase, _xreqidx, _seg)	\
107 	((_pagebase) + ((_xreqidx)			\
108 	* BLKIF_MAX_SEGMENTS_PER_REQUEST		\
109 	+ (_seg)) * PAGESIZE)
110 #define	XDB_XREQ2BP(xreq) (&(xreq)->xr_buf)
111 #define	XDB_BP2XREQ(bp) \
112 	((xdb_request_t *)((char *)(bp) - offsetof(xdb_request_t, xr_buf)))
113 
114 /* describe one blkif segment */
115 typedef struct xdb_seg {
116 	uint8_t fs; /* start sector # within this page (segment) */
117 	uint8_t ls; /* end sector # within this page (segment) */
118 } xdb_seg_t;
119 
120 typedef struct xdb xdb_t;
121 
122 /* one blkif_request_t matches one xdb_request_t */
123 typedef struct xdb_request {
124 	/* buf associated with this I/O request */
125 	buf_t		xr_buf;
126 	/* softstate instance associated with this I/O request */
127 	xdb_t		*xr_vdp;
128 	/* the next segment we're going to process */
129 	int		xr_curseg;
130 	/* index of this xdb_request_t in vdp->xs_req */
131 	int		xr_idx;
132 	/* next index for a statical linked list */
133 	int		xr_next;
134 	/* 'id' copied from blkif_request_t */
135 	uint64_t	xr_id;
136 	/* 'operation' copied from blkif_request_t */
137 	uint8_t		xr_op;
138 	/* how many pages(segments) in this I/O request */
139 	uint8_t		xr_buf_pages;
140 	/* all segments of this I/O request */
141 	xdb_seg_t	xr_segs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
142 	/* all grant table handles used in this I/O request */
143 	grant_handle_t	xr_page_hdls[BLKIF_MAX_SEGMENTS_PER_REQUEST];
144 	struct page	xr_plist[BLKIF_MAX_SEGMENTS_PER_REQUEST];
145 	struct page	*xr_pplist[BLKIF_MAX_SEGMENTS_PER_REQUEST];
146 } xdb_request_t;
147 
148 /* Soft state data structure for each backend vbd */
149 struct xdb {
150 	/* devinfo node pointer of this xdb */
151 	dev_info_t	*xs_dip;
152 	/* coresponding frontend domain id */
153 	domid_t		xs_peer;
154 	/* read-only, removable, cdrom? */
155 	uint32_t	xs_type;
156 	/* # of total sectors */
157 	uint64_t	xs_sectors;
158 	/* blkif I/O request ring buffer */
159 	xendev_ring_t	*xs_ring;
160 	/* handle to access the ring buffer */
161 	ddi_acc_handle_t xs_ring_hdl;
162 	ldi_ident_t	xs_ldi_li;
163 	ldi_handle_t	xs_ldi_hdl;
164 	/* base kva for mapped-in I/O page from frontend domain */
165 	caddr_t		xs_iopage_va;
166 	/* mutex lock for I/O related code path */
167 	kmutex_t	xs_iomutex;
168 	/*
169 	 * mutex lock for event handling related code path
170 	 * need to be grabbed before xs_iomutex
171 	 */
172 	kmutex_t	xs_cbmutex;
173 	/* # of on-going I/O buf in backend domain */
174 	uint_t		xs_ionum;
175 	/* task thread for pushing buf to underlying target driver */
176 	ddi_taskq_t	*xs_iotaskq;
177 	/* cv used in I/O code path, protected by xs_iomutex */
178 	kcondvar_t	xs_iocv;
179 	kcondvar_t	xs_ionumcv;
180 	/*
181 	 * head and tail of linked list for I/O bufs need to be pushed to
182 	 * underlying target driver
183 	 */
184 	buf_t		*xs_f_iobuf;
185 	buf_t		*xs_l_iobuf;
186 	/* xdb interface status */
187 	enum xdb_state	xs_if_status;
188 	/* backend device status */
189 	enum xdb_dev_state xs_dev_status;
190 	/* frontend status */
191 	enum xdb_fe_state xs_fe_status;
192 	/* head of free list of xdb_request_t */
193 	int		xs_free_req;
194 	/* pre-allocated xdb_request_t pool */
195 	xdb_request_t	xs_req[BLKIF_RING_SIZE];
196 	kstat_t		*xs_kstats;
197 	uint64_t	xs_stat_req_reads;
198 	uint64_t	xs_stat_req_writes;
199 	uint64_t	xs_stat_req_barriers;
200 	uint64_t	xs_stat_req_flushes;
201 #ifdef DEBUG
202 	uint64_t page_addrs[XDB_MAX_IO_PAGES]; /* for debug aid */
203 #endif /* DEBUG */
204 };
205 
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 #endif	/* _SYS_XDB_H */
211