xref: /titanic_50/usr/src/uts/common/xen/io/xdb.h (revision 24fe0b3bf671e123467ce1df0b67cadd3614c8e4)
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 	/* sector size if existed */
117 	uint_t		xs_sec_size;
118 	/* blkif I/O request ring buffer */
119 	xendev_ring_t	*xs_ring;
120 	/* handle to access the ring buffer */
121 	ddi_acc_handle_t xs_ring_hdl;
122 	ldi_ident_t	xs_ldi_li;
123 	ldi_handle_t	xs_ldi_hdl;
124 	/* base kva for mapped-in I/O page from frontend domain */
125 	caddr_t		xs_iopage_va;
126 	/* mutex lock for I/O related code path */
127 	kmutex_t	xs_iomutex;
128 	/*
129 	 * mutex lock for event handling related code path
130 	 * need to be grabbed before xs_iomutex
131 	 */
132 	kmutex_t	xs_cbmutex;
133 	/* # of on-going I/O buf in backend domain */
134 	uint_t		xs_ionum;
135 	/* task thread for pushing buf to underlying target driver */
136 	ddi_taskq_t	*xs_iotaskq;
137 	/* cv used in I/O code path, protected by xs_iomutex */
138 	kcondvar_t	xs_iocv;
139 	kcondvar_t	xs_ionumcv;
140 	/*
141 	 * head and tail of linked list for I/O bufs need to be pushed to
142 	 * underlying target driver
143 	 */
144 	buf_t		*xs_f_iobuf;
145 	buf_t		*xs_l_iobuf;
146 	/* head of free list of xdb_request_t */
147 	int		xs_free_req;
148 	/* pre-allocated xdb_request_t pool */
149 	xdb_request_t	*xs_req;
150 	kstat_t		*xs_kstats;
151 	uint64_t	xs_stat_req_reads;
152 	uint64_t	xs_stat_req_writes;
153 	uint64_t	xs_stat_req_barriers;
154 	uint64_t	xs_stat_req_flushes;
155 	enum blkif_protocol xs_blk_protocol;
156 	size_t		xs_nentry;
157 	size_t		xs_entrysize;
158 
159 	/* Protected by xs_cbmutex */
160 	boolean_t	xs_hp_connected;	/* hot plug scripts have run */
161 	boolean_t	xs_fe_initialised;	/* frontend is initialized */
162 	char			*xs_lofi_path;
163 	char			*xs_params_path;
164 	struct xenbus_watch	*xs_watch_params;
165 	struct xenbus_watch	*xs_watch_media_req;
166 	ddi_taskq_t		*xs_watch_taskq;
167 	int			xs_watch_taskq_count;
168 
169 	/* Protected by xs_cbmutex and xs_iomutex */
170 	boolean_t	xs_if_connected;	/* connected to frontend */
171 
172 	/* Protected by xs_iomutex */
173 	boolean_t	xs_send_buf;
174 
175 #ifdef DEBUG
176 	uint64_t *page_addrs; /* for debug aid */
177 #endif /* DEBUG */
178 };
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif	/* _SYS_XDB_H */
185