usbif.h revision 288917
1/*
2 * usbif.h
3 *
4 * USB I/O interface for Xen guest OSes.
5 *
6 * Copyright (C) 2009, FUJITSU LABORATORIES LTD.
7 * Author: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to
11 * deal in the Software without restriction, including without limitation the
12 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13 * sell copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 */
27
28#ifndef __XEN_PUBLIC_IO_USBIF_H__
29#define __XEN_PUBLIC_IO_USBIF_H__
30
31#include "ring.h"
32#include "../grant_table.h"
33
34/*
35 * Feature and Parameter Negotiation
36 * =================================
37 * The two halves of a Xen pvUSB driver utilize nodes within the XenStore to
38 * communicate capabilities and to negotiate operating parameters. This
39 * section enumerates these nodes which reside in the respective front and
40 * backend portions of the XenStore, following the XenBus convention.
41 *
42 * Any specified default value is in effect if the corresponding XenBus node
43 * is not present in the XenStore.
44 *
45 * XenStore nodes in sections marked "PRIVATE" are solely for use by the
46 * driver side whose XenBus tree contains them.
47 *
48 *****************************************************************************
49 *                            Backend XenBus Nodes
50 *****************************************************************************
51 *
52 *------------------ Backend Device Identification (PRIVATE) ------------------
53 *
54 * num-ports
55 *      Values:         unsigned [1...31]
56 *
57 *      Number of ports for this (virtual) USB host connector.
58 *
59 * usb-ver
60 *      Values:         unsigned [1...2]
61 *
62 *      USB version of this host connector: 1 = USB 1.1, 2 = USB 2.0.
63 *
64 * port/[1...31]
65 *      Values:         string
66 *
67 *      Physical USB device connected to the given port, e.g. "3-1.5".
68 *
69 *****************************************************************************
70 *                            Frontend XenBus Nodes
71 *****************************************************************************
72 *
73 *----------------------- Request Transport Parameters -----------------------
74 *
75 * event-channel
76 *      Values:         unsigned
77 *
78 *      The identifier of the Xen event channel used to signal activity
79 *      in the ring buffer.
80 *
81 * urb-ring-ref
82 *      Values:         unsigned
83 *
84 *      The Xen grant reference granting permission for the backend to map
85 *      the sole page in a single page sized ring buffer. This is the ring
86 *      buffer for urb requests.
87 *
88 * conn-ring-ref
89 *      Values:         unsigned
90 *
91 *      The Xen grant reference granting permission for the backend to map
92 *      the sole page in a single page sized ring buffer. This is the ring
93 *      buffer for connection/disconnection requests.
94 *
95 * protocol
96 *      Values:         string (XEN_IO_PROTO_ABI_*)
97 *      Default Value:  XEN_IO_PROTO_ABI_NATIVE
98 *
99 *      The machine ABI rules governing the format of all ring request and
100 *      response structures.
101 *
102 */
103
104enum usb_spec_version {
105	USB_VER_UNKNOWN = 0,
106	USB_VER_USB11,
107	USB_VER_USB20,
108	USB_VER_USB30,	/* not supported yet */
109};
110
111/*
112 *  USB pipe in usbif_request
113 *
114 *  - port number:	bits 0-4
115 *				(USB_MAXCHILDREN is 31)
116 *
117 *  - operation flag:	bit 5
118 *				(0 = submit urb,
119 *				 1 = unlink urb)
120 *
121 *  - direction:		bit 7
122 *				(0 = Host-to-Device [Out]
123 *				 1 = Device-to-Host [In])
124 *
125 *  - device address:	bits 8-14
126 *
127 *  - endpoint:		bits 15-18
128 *
129 *  - pipe type:	bits 30-31
130 *				(00 = isochronous, 01 = interrupt,
131 *				 10 = control, 11 = bulk)
132 */
133
134#define USBIF_PIPE_PORT_MASK	0x0000001f
135#define USBIF_PIPE_UNLINK	0x00000020
136#define USBIF_PIPE_DIR		0x00000080
137#define USBIF_PIPE_DEV_MASK	0x0000007f
138#define USBIF_PIPE_DEV_SHIFT	8
139#define USBIF_PIPE_EP_MASK	0x0000000f
140#define USBIF_PIPE_EP_SHIFT	15
141#define USBIF_PIPE_TYPE_MASK	0x00000003
142#define USBIF_PIPE_TYPE_SHIFT	30
143#define USBIF_PIPE_TYPE_ISOC	0
144#define USBIF_PIPE_TYPE_INT	1
145#define USBIF_PIPE_TYPE_CTRL	2
146#define USBIF_PIPE_TYPE_BULK	3
147
148#define usbif_pipeportnum(pipe)			((pipe) & USBIF_PIPE_PORT_MASK)
149#define usbif_setportnum_pipe(pipe, portnum)	((pipe) | (portnum))
150
151#define usbif_pipeunlink(pipe)			((pipe) & USBIF_PIPE_UNLINK)
152#define usbif_pipesubmit(pipe)			(!usbif_pipeunlink(pipe))
153#define usbif_setunlink_pipe(pipe)		((pipe) | USBIF_PIPE_UNLINK)
154
155#define usbif_pipein(pipe)			((pipe) & USBIF_PIPE_DIR)
156#define usbif_pipeout(pipe)			(!usbif_pipein(pipe))
157
158#define usbif_pipedevice(pipe)			\
159		(((pipe) >> USBIF_PIPE_DEV_SHIFT) & USBIF_PIPE_DEV_MASK)
160
161#define usbif_pipeendpoint(pipe)		\
162		(((pipe) >> USBIF_PIPE_EP_SHIFT) & USBIF_PIPE_EP_MASK)
163
164#define usbif_pipetype(pipe)			\
165		(((pipe) >> USBIF_PIPE_TYPE_SHIFT) & USBIF_PIPE_TYPE_MASK)
166#define usbif_pipeisoc(pipe)	(usbif_pipetype(pipe) == USBIF_PIPE_TYPE_ISOC)
167#define usbif_pipeint(pipe)	(usbif_pipetype(pipe) == USBIF_PIPE_TYPE_INT)
168#define usbif_pipectrl(pipe)	(usbif_pipetype(pipe) == USBIF_PIPE_TYPE_CTRL)
169#define usbif_pipebulk(pipe)	(usbif_pipetype(pipe) == USBIF_PIPE_TYPE_BULK)
170
171#define USBIF_MAX_SEGMENTS_PER_REQUEST (16)
172#define USBIF_MAX_PORTNR	31
173
174/*
175 * RING for transferring urbs.
176 */
177struct usbif_request_segment {
178	grant_ref_t gref;
179	uint16_t offset;
180	uint16_t length;
181};
182
183struct usbif_urb_request {
184	uint16_t id; /* request id */
185	uint16_t nr_buffer_segs; /* number of urb->transfer_buffer segments */
186
187	/* basic urb parameter */
188	uint32_t pipe;
189	uint16_t transfer_flags;
190	uint16_t buffer_length;
191	union {
192		uint8_t ctrl[8]; /* setup_packet (Ctrl) */
193
194		struct {
195			uint16_t interval; /* maximum (1024*8) in usb core */
196			uint16_t start_frame; /* start frame */
197			uint16_t number_of_packets; /* number of ISO packet */
198			uint16_t nr_frame_desc_segs; /* number of iso_frame_desc segments */
199		} isoc;
200
201		struct {
202			uint16_t interval; /* maximum (1024*8) in usb core */
203			uint16_t pad[3];
204		} intr;
205
206		struct {
207			uint16_t unlink_id; /* unlink request id */
208			uint16_t pad[3];
209		} unlink;
210
211	} u;
212
213	/* urb data segments */
214	struct usbif_request_segment seg[USBIF_MAX_SEGMENTS_PER_REQUEST];
215};
216typedef struct usbif_urb_request usbif_urb_request_t;
217
218struct usbif_urb_response {
219	uint16_t id; /* request id */
220	uint16_t start_frame;  /* start frame (ISO) */
221	int32_t status; /* status (non-ISO) */
222	int32_t actual_length; /* actual transfer length */
223	int32_t error_count; /* number of ISO errors */
224};
225typedef struct usbif_urb_response usbif_urb_response_t;
226
227DEFINE_RING_TYPES(usbif_urb, struct usbif_urb_request, struct usbif_urb_response);
228#define USB_URB_RING_SIZE __CONST_RING_SIZE(usbif_urb, PAGE_SIZE)
229
230/*
231 * RING for notifying connect/disconnect events to frontend
232 */
233struct usbif_conn_request {
234	uint16_t id;
235};
236typedef struct usbif_conn_request usbif_conn_request_t;
237
238struct usbif_conn_response {
239	uint16_t id; /* request id */
240	uint8_t portnum; /* port number */
241	uint8_t speed; /* usb_device_speed */
242#define USBIF_SPEED_NONE	0
243#define USBIF_SPEED_LOW		1
244#define USBIF_SPEED_FULL	2
245#define USBIF_SPEED_HIGH	3
246};
247typedef struct usbif_conn_response usbif_conn_response_t;
248
249DEFINE_RING_TYPES(usbif_conn, struct usbif_conn_request, struct usbif_conn_response);
250#define USB_CONN_RING_SIZE __CONST_RING_SIZE(usbif_conn, PAGE_SIZE)
251
252#endif /* __XEN_PUBLIC_IO_USBIF_H__ */
253