xref: /titanic_51/usr/src/uts/common/xen/io/xdb.h (revision dcda19f50b2b80bfc622fff718ac04fb0e1cb670)
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 
28 #ifndef _SYS_XDB_H
29 #define	_SYS_XDB_H
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define	XDB_DBG_ALL	0xf
36 #define	XDB_DBG_IO	0x1
37 #define	XDB_DBG_INFO	0x2
38 #define	XDB_DBPRINT(lvl, fmt) { if (xdb_debug & lvl) cmn_err fmt; }
39 
40 /*
41  * Info of the exported blk device
42  */
43 #define	XDB_DEV_RO	(1 << 0) /* backend and frontend are read-only */
44 #define	XDB_DEV_BE_LOFI	(1 << 1) /* backend device is a lofi device */
45 #define	XDB_DEV_BE_RMB	(1 << 2) /* backend device is removable */
46 #define	XDB_DEV_BE_CD	(1 << 3) /* backend device is cdrom */
47 #define	XDB_DEV_FE_CD	(1 << 4) /* frontend device is cdrom */
48 
49 #define	XDB_IS_RO(vdp)		((vdp)->xs_type & XDB_DEV_RO)
50 #define	XDB_IS_BE_LOFI(vdp)	((vdp)->xs_type & XDB_DEV_BE_LOFI)
51 #define	XDB_IS_BE_RMB(vdp)	((vdp)->xs_type & XDB_DEV_BE_RMB)
52 #define	XDB_IS_BE_CD(vdp)	((vdp)->xs_type & XDB_DEV_BE_CD)
53 #define	XDB_IS_FE_CD(vdp)	((vdp)->xs_type & XDB_DEV_FE_CD)
54 
55 /*
56  * Other handy macrosx
57  */
58 #define	XDB_MINOR2INST(m)	(int)(m)
59 #define	XDB_INST2MINOR(i)	(minor_t)(i)
60 #define	XDB_INST2SOFTS(instance)			\
61 	((xdb_t *)ddi_get_soft_state(xdb_statep, (instance)))
62 #define	XDB_MAX_IO_PAGES(v) ((v)->xs_nentry * BLKIF_MAX_SEGMENTS_PER_REQUEST)
63 /* get kva of a mapped-in page coresponding to (xreq-index, seg) pair */
64 #define	XDB_IOPAGE_VA(_pagebase, _xreqidx, _seg)	\
65 	((_pagebase) + ((_xreqidx)			\
66 	* BLKIF_MAX_SEGMENTS_PER_REQUEST		\
67 	+ (_seg)) * PAGESIZE)
68 #define	XDB_XREQ2BP(xreq) (&(xreq)->xr_buf)
69 #define	XDB_BP2XREQ(bp) \
70 	((xdb_request_t *)((char *)(bp) - offsetof(xdb_request_t, xr_buf)))
71 
72 /* describe one blkif segment */
73 typedef struct xdb_seg {
74 	uint8_t fs; /* start sector # within this page (segment) */
75 	uint8_t ls; /* end sector # within this page (segment) */
76 } xdb_seg_t;
77 
78 typedef struct xdb xdb_t;
79 
80 /* one blkif_request_t matches one xdb_request_t */
81 typedef struct xdb_request {
82 	/* buf associated with this I/O request */
83 	buf_t		xr_buf;
84 	/* softstate instance associated with this I/O request */
85 	xdb_t		*xr_vdp;
86 	/* the next segment we're going to process */
87 	int		xr_curseg;
88 	/* index of this xdb_request_t in vdp->xs_req */
89 	int		xr_idx;
90 	/* next index for a statical linked list */
91 	int		xr_next;
92 	/* 'id' copied from blkif_request_t */
93 	uint64_t	xr_id;
94 	/* 'operation' copied from blkif_request_t */
95 	uint8_t		xr_op;
96 	/* how many pages(segments) in this I/O request */
97 	uint8_t		xr_buf_pages;
98 	/* all segments of this I/O request */
99 	xdb_seg_t	xr_segs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
100 	/* all grant table handles used in this I/O request */
101 	grant_handle_t	xr_page_hdls[BLKIF_MAX_SEGMENTS_PER_REQUEST];
102 	struct page	xr_plist[BLKIF_MAX_SEGMENTS_PER_REQUEST];
103 	struct page	*xr_pplist[BLKIF_MAX_SEGMENTS_PER_REQUEST];
104 } xdb_request_t;
105 
106 /* Soft state data structure for each backend vbd */
107 struct xdb {
108 	/* devinfo node pointer of this xdb */
109 	dev_info_t	*xs_dip;
110 	/* coresponding frontend domain id */
111 	domid_t		xs_peer;
112 	/* read-only, removable, cdrom? */
113 	uint32_t	xs_type;
114 	/* # of total sectors */
115 	uint64_t	xs_sectors;
116 	/* blkif I/O request ring buffer */
117 	xendev_ring_t	*xs_ring;
118 	/* handle to access the ring buffer */
119 	ddi_acc_handle_t xs_ring_hdl;
120 	ldi_ident_t	xs_ldi_li;
121 	ldi_handle_t	xs_ldi_hdl;
122 	/* base kva for mapped-in I/O page from frontend domain */
123 	caddr_t		xs_iopage_va;
124 	/* mutex lock for I/O related code path */
125 	kmutex_t	xs_iomutex;
126 	/*
127 	 * mutex lock for event handling related code path
128 	 * need to be grabbed before xs_iomutex
129 	 */
130 	kmutex_t	xs_cbmutex;
131 	/* # of on-going I/O buf in backend domain */
132 	uint_t		xs_ionum;
133 	/* task thread for pushing buf to underlying target driver */
134 	ddi_taskq_t	*xs_iotaskq;
135 	/* cv used in I/O code path, protected by xs_iomutex */
136 	kcondvar_t	xs_iocv;
137 	kcondvar_t	xs_ionumcv;
138 	/*
139 	 * head and tail of linked list for I/O bufs need to be pushed to
140 	 * underlying target driver
141 	 */
142 	buf_t		*xs_f_iobuf;
143 	buf_t		*xs_l_iobuf;
144 	/* head of free list of xdb_request_t */
145 	int		xs_free_req;
146 	/* pre-allocated xdb_request_t pool */
147 	xdb_request_t	*xs_req;
148 	kstat_t		*xs_kstats;
149 	uint64_t	xs_stat_req_reads;
150 	uint64_t	xs_stat_req_writes;
151 	uint64_t	xs_stat_req_barriers;
152 	uint64_t	xs_stat_req_flushes;
153 	enum blkif_protocol xs_blk_protocol;
154 	size_t		xs_nentry;
155 	size_t		xs_entrysize;
156 
157 	/* Protected by xs_cbmutex */
158 	boolean_t	xs_hp_connected;	/* hot plug scripts have run */
159 	boolean_t	xs_fe_initialised;	/* frontend is initialized */
160 	char			*xs_lofi_path;
161 	char			*xs_params_path;
162 	struct xenbus_watch	*xs_watch_params;
163 	struct xenbus_watch	*xs_watch_media_req;
164 	ddi_taskq_t		*xs_watch_taskq;
165 	int			xs_watch_taskq_count;
166 
167 	/* Protected by xs_cbmutex and xs_iomutex */
168 	boolean_t	xs_if_connected;	/* connected to frontend */
169 
170 	/* Protected by xs_iomutex */
171 	boolean_t	xs_send_buf;
172 
173 #ifdef DEBUG
174 	uint64_t *page_addrs; /* for debug aid */
175 #endif /* DEBUG */
176 };
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif	/* _SYS_XDB_H */
183