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