brintos

brintos / linux-shallow public Read only

0
0
Text · 16.5 KiB · a70e0b9 Raw
406 lines · c
1/* SPDX-License-Identifier: MIT */2 3/*4 * usbif.h5 *6 * USB I/O interface for Xen guest OSes.7 *8 * Copyright (C) 2009, FUJITSU LABORATORIES LTD.9 * Author: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>10 */11 12#ifndef __XEN_PUBLIC_IO_USBIF_H__13#define __XEN_PUBLIC_IO_USBIF_H__14 15#include "ring.h"16#include "../grant_table.h"17 18/*19 * Detailed Interface Description20 * ==============================21 * The pvUSB interface is using a split driver design: a frontend driver in22 * the guest and a backend driver in a driver domain (normally dom0) having23 * access to the physical USB device(s) being passed to the guest.24 *25 * The frontend and backend drivers use XenStore to initiate the connection26 * between them, the I/O activity is handled via two shared ring pages and an27 * event channel. As the interface between frontend and backend is at the USB28 * host connector level, multiple (up to 31) physical USB devices can be29 * handled by a single connection.30 *31 * The Xen pvUSB device name is "qusb", so the frontend's XenStore entries are32 * to be found under "device/qusb", while the backend's XenStore entries are33 * under "backend/<guest-dom-id>/qusb".34 *35 * When a new pvUSB connection is established, the frontend needs to setup the36 * two shared ring pages for communication and the event channel. The ring37 * pages need to be made available to the backend via the grant table38 * interface.39 *40 * One of the shared ring pages is used by the backend to inform the frontend41 * about USB device plug events (device to be added or removed). This is the42 * "conn-ring".43 *44 * The other ring page is used for USB I/O communication (requests and45 * responses). This is the "urb-ring".46 *47 * Feature and Parameter Negotiation48 * =================================49 * The two halves of a Xen pvUSB driver utilize nodes within the XenStore to50 * communicate capabilities and to negotiate operating parameters. This51 * section enumerates these nodes which reside in the respective front and52 * backend portions of the XenStore, following the XenBus convention.53 *54 * Any specified default value is in effect if the corresponding XenBus node55 * is not present in the XenStore.56 *57 * XenStore nodes in sections marked "PRIVATE" are solely for use by the58 * driver side whose XenBus tree contains them.59 *60 *****************************************************************************61 *                            Backend XenBus Nodes62 *****************************************************************************63 *64 *------------------ Backend Device Identification (PRIVATE) ------------------65 *66 * num-ports67 *      Values:         unsigned [1...31]68 *69 *      Number of ports for this (virtual) USB host connector.70 *71 * usb-ver72 *      Values:         unsigned [1...2]73 *74 *      USB version of this host connector: 1 = USB 1.1, 2 = USB 2.0.75 *76 * port/[1...31]77 *      Values:         string78 *79 *      Physical USB device connected to the given port, e.g. "3-1.5".80 *81 *****************************************************************************82 *                            Frontend XenBus Nodes83 *****************************************************************************84 *85 *----------------------- Request Transport Parameters -----------------------86 *87 * event-channel88 *      Values:         unsigned89 *90 *      The identifier of the Xen event channel used to signal activity91 *      in the ring buffer.92 *93 * urb-ring-ref94 *      Values:         unsigned95 *96 *      The Xen grant reference granting permission for the backend to map97 *      the sole page in a single page sized ring buffer. This is the ring98 *      buffer for urb requests.99 *100 * conn-ring-ref101 *      Values:         unsigned102 *103 *      The Xen grant reference granting permission for the backend to map104 *      the sole page in a single page sized ring buffer. This is the ring105 *      buffer for connection/disconnection requests.106 *107 * protocol108 *      Values:         string (XEN_IO_PROTO_ABI_*)109 *      Default Value:  XEN_IO_PROTO_ABI_NATIVE110 *111 *      The machine ABI rules governing the format of all ring request and112 *      response structures.113 *114 * Protocol Description115 * ====================116 *117 *-------------------------- USB device plug events --------------------------118 *119 * USB device plug events are send via the "conn-ring" shared page. As only120 * events are being sent, the respective requests from the frontend to the121 * backend are just dummy ones.122 * The events sent to the frontend have the following layout:123 *         0                1                 2               3        octet124 * +----------------+----------------+----------------+----------------+125 * |               id                |    portnum     |     speed      | 4126 * +----------------+----------------+----------------+----------------+127 *   id - uint16_t, event id (taken from the actual frontend dummy request)128 *   portnum - uint8_t, port number (1 ... 31)129 *   speed - uint8_t, device XENUSB_SPEED_*, XENUSB_SPEED_NONE == unplug130 *131 * The dummy request:132 *         0                1        octet133 * +----------------+----------------+134 * |               id                | 2135 * +----------------+----------------+136 *   id - uint16_t, guest supplied value (no need for being unique)137 *138 *-------------------------- USB I/O request ---------------------------------139 *140 * A single USB I/O request on the "urb-ring" has the following layout:141 *         0                1                 2               3        octet142 * +----------------+----------------+----------------+----------------+143 * |               id                |         nr_buffer_segs          | 4144 * +----------------+----------------+----------------+----------------+145 * |                               pipe                                | 8146 * +----------------+----------------+----------------+----------------+147 * |         transfer_flags          |          buffer_length          | 12148 * +----------------+----------------+----------------+----------------+149 * |                       request type specific                       | 16150 * |                               data                                | 20151 * +----------------+----------------+----------------+----------------+152 * |                              seg[0]                               | 24153 * |                               data                                | 28154 * +----------------+----------------+----------------+----------------+155 * |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|156 * +----------------+----------------+----------------+----------------+157 * |             seg[XENUSB_MAX_SEGMENTS_PER_REQUEST - 1]              | 144158 * |                               data                                | 148159 * +----------------+----------------+----------------+----------------+160 * Bit field bit number 0 is always least significant bit, undefined bits must161 * be zero.162 *   id - uint16_t, guest supplied value163 *   nr_buffer_segs - uint16_t, number of segment entries in seg[] array164 *   pipe - uint32_t, bit field with multiple information:165 *     bits 0-4: port request to send to166 *     bit 5: unlink request with specified id (cancel I/O) if set (see below)167 *     bit 7: direction (1 = read from device)168 *     bits 8-14: device number on port169 *     bits 15-18: endpoint of device170 *     bits 30-31: request type: 00 = isochronous, 01 = interrupt,171 *                               10 = control, 11 = bulk172 *   transfer_flags - uint16_t, bit field with processing flags:173 *     bit 0: less data than specified allowed174 *   buffer_length - uint16_t, total length of data175 *   request type specific data - 8 bytes, see below176 *   seg[] - array with 8 byte elements, see below177 *178 * Request type specific data for isochronous request:179 *         0                1                 2               3        octet180 * +----------------+----------------+----------------+----------------+181 * |            interval             |           start_frame           | 4182 * +----------------+----------------+----------------+----------------+183 * |       number_of_packets         |       nr_frame_desc_segs        | 8184 * +----------------+----------------+----------------+----------------+185 *   interval - uint16_t, time interval in msecs between frames186 *   start_frame - uint16_t, start frame number187 *   number_of_packets - uint16_t, number of packets to transfer188 *   nr_frame_desc_segs - uint16_t number of seg[] frame descriptors elements189 *190 * Request type specific data for interrupt request:191 *         0                1                 2               3        octet192 * +----------------+----------------+----------------+----------------+193 * |            interval             |                0                | 4194 * +----------------+----------------+----------------+----------------+195 * |                                 0                                 | 8196 * +----------------+----------------+----------------+----------------+197 *   interval - uint16_t, time in msecs until interruption198 *199 * Request type specific data for control request:200 *         0                1                 2               3        octet201 * +----------------+----------------+----------------+----------------+202 * |                      data of setup packet                         | 4203 * |                                                                   | 8204 * +----------------+----------------+----------------+----------------+205 *206 * Request type specific data for bulk request:207 *         0                1                 2               3        octet208 * +----------------+----------------+----------------+----------------+209 * |                                 0                                 | 4210 * |                                 0                                 | 8211 * +----------------+----------------+----------------+----------------+212 *213 * Request type specific data for unlink request:214 *         0                1                 2               3        octet215 * +----------------+----------------+----------------+----------------+216 * |           unlink_id             |                0                | 4217 * +----------------+----------------+----------------+----------------+218 * |                                 0                                 | 8219 * +----------------+----------------+----------------+----------------+220 *   unlink_id - uint16_t, request id of request to terminate221 *222 * seg[] array element layout:223 *         0                1                 2               3        octet224 * +----------------+----------------+----------------+----------------+225 * |                               gref                                | 4226 * +----------------+----------------+----------------+----------------+227 * |             offset              |             length              | 8228 * +----------------+----------------+----------------+----------------+229 *   gref - uint32_t, grant reference of buffer page230 *   offset - uint16_t, offset of buffer start in page231 *   length - uint16_t, length of buffer in page232 *233 *-------------------------- USB I/O response --------------------------------234 *235 *         0                1                 2               3        octet236 * +----------------+----------------+----------------+----------------+237 * |               id                |          start_frame            | 4238 * +----------------+----------------+----------------+----------------+239 * |                              status                               | 8240 * +----------------+----------------+----------------+----------------+241 * |                          actual_length                            | 12242 * +----------------+----------------+----------------+----------------+243 * |                           error_count                             | 16244 * +----------------+----------------+----------------+----------------+245 *   id - uint16_t, id of the request this response belongs to246 *   start_frame - uint16_t, start_frame this response (iso requests only)247 *   status - int32_t, XENUSB_STATUS_* (non-iso requests)248 *   actual_length - uint32_t, actual size of data transferred249 *   error_count - uint32_t, number of errors (iso requests)250 */251 252enum xenusb_spec_version {253	XENUSB_VER_UNKNOWN = 0,254	XENUSB_VER_USB11,255	XENUSB_VER_USB20,256	XENUSB_VER_USB30,	/* not supported yet */257};258 259/*260 *  USB pipe in xenusb_request261 *262 *  - port number:      bits 0-4263 *                              (USB_MAXCHILDREN is 31)264 *265 *  - operation flag:   bit 5266 *                              (0 = submit urb,267 *                               1 = unlink urb)268 *269 *  - direction:        bit 7270 *                              (0 = Host-to-Device [Out]271 *                               1 = Device-to-Host [In])272 *273 *  - device address:   bits 8-14274 *275 *  - endpoint:         bits 15-18276 *277 *  - pipe type:        bits 30-31278 *                              (00 = isochronous, 01 = interrupt,279 *                               10 = control, 11 = bulk)280 */281 282#define XENUSB_PIPE_PORT_MASK	0x0000001f283#define XENUSB_PIPE_UNLINK	0x00000020284#define XENUSB_PIPE_DIR		0x00000080285#define XENUSB_PIPE_DEV_MASK	0x0000007f286#define XENUSB_PIPE_DEV_SHIFT	8287#define XENUSB_PIPE_EP_MASK	0x0000000f288#define XENUSB_PIPE_EP_SHIFT	15289#define XENUSB_PIPE_TYPE_MASK	0x00000003290#define XENUSB_PIPE_TYPE_SHIFT	30291#define XENUSB_PIPE_TYPE_ISOC	0292#define XENUSB_PIPE_TYPE_INT	1293#define XENUSB_PIPE_TYPE_CTRL	2294#define XENUSB_PIPE_TYPE_BULK	3295 296#define xenusb_pipeportnum(pipe)		((pipe) & XENUSB_PIPE_PORT_MASK)297#define xenusb_setportnum_pipe(pipe, portnum)	((pipe) | (portnum))298 299#define xenusb_pipeunlink(pipe)			((pipe) & XENUSB_PIPE_UNLINK)300#define xenusb_pipesubmit(pipe)			(!xenusb_pipeunlink(pipe))301#define xenusb_setunlink_pipe(pipe)		((pipe) | XENUSB_PIPE_UNLINK)302 303#define xenusb_pipein(pipe)			((pipe) & XENUSB_PIPE_DIR)304#define xenusb_pipeout(pipe)			(!xenusb_pipein(pipe))305 306#define xenusb_pipedevice(pipe)			\307	(((pipe) >> XENUSB_PIPE_DEV_SHIFT) & XENUSB_PIPE_DEV_MASK)308 309#define xenusb_pipeendpoint(pipe)		\310	(((pipe) >> XENUSB_PIPE_EP_SHIFT) & XENUSB_PIPE_EP_MASK)311 312#define xenusb_pipetype(pipe)			\313	(((pipe) >> XENUSB_PIPE_TYPE_SHIFT) & XENUSB_PIPE_TYPE_MASK)314#define xenusb_pipeisoc(pipe)	(xenusb_pipetype(pipe) == XENUSB_PIPE_TYPE_ISOC)315#define xenusb_pipeint(pipe)	(xenusb_pipetype(pipe) == XENUSB_PIPE_TYPE_INT)316#define xenusb_pipectrl(pipe)	(xenusb_pipetype(pipe) == XENUSB_PIPE_TYPE_CTRL)317#define xenusb_pipebulk(pipe)	(xenusb_pipetype(pipe) == XENUSB_PIPE_TYPE_BULK)318 319#define XENUSB_MAX_SEGMENTS_PER_REQUEST (16)320#define XENUSB_MAX_PORTNR		31321#define XENUSB_RING_SIZE		4096322 323/*324 * RING for transferring urbs.325 */326struct xenusb_request_segment {327	grant_ref_t gref;328	uint16_t offset;329	uint16_t length;330};331 332struct xenusb_urb_request {333	uint16_t id;			/* request id */334	uint16_t nr_buffer_segs;	/* number of urb->transfer_buffer segments */335 336	/* basic urb parameter */337	uint32_t pipe;338	uint16_t transfer_flags;339#define XENUSB_SHORT_NOT_OK	0x0001340	uint16_t buffer_length;341	union {342		uint8_t ctrl[8];	/* setup_packet (Ctrl) */343 344		struct {345			uint16_t interval;	/* maximum (1024*8) in usb core */346			uint16_t start_frame;	/* start frame */347			uint16_t number_of_packets;	/* number of ISO packet */348			uint16_t nr_frame_desc_segs;	/* number of iso_frame_desc segments */349		} isoc;350 351		struct {352			uint16_t interval;	/* maximum (1024*8) in usb core */353			uint16_t pad[3];354		} intr;355 356		struct {357			uint16_t unlink_id;	/* unlink request id */358			uint16_t pad[3];359		} unlink;360 361	} u;362 363	/* urb data segments */364	struct xenusb_request_segment seg[XENUSB_MAX_SEGMENTS_PER_REQUEST];365};366 367struct xenusb_urb_response {368	uint16_t id;		/* request id */369	uint16_t start_frame;	/* start frame (ISO) */370	int32_t status;		/* status (non-ISO) */371#define XENUSB_STATUS_OK	0372#define XENUSB_STATUS_NODEV	(-19)373#define XENUSB_STATUS_INVAL	(-22)374#define XENUSB_STATUS_STALL	(-32)375#define XENUSB_STATUS_IOERROR	(-71)376#define XENUSB_STATUS_BABBLE	(-75)377#define XENUSB_STATUS_SHUTDOWN	(-108)378	int32_t actual_length;	/* actual transfer length */379	int32_t error_count;	/* number of ISO errors */380};381 382DEFINE_RING_TYPES(xenusb_urb, struct xenusb_urb_request, struct xenusb_urb_response);383#define XENUSB_URB_RING_SIZE __CONST_RING_SIZE(xenusb_urb, XENUSB_RING_SIZE)384 385/*386 * RING for notifying connect/disconnect events to frontend387 */388struct xenusb_conn_request {389	uint16_t id;390};391 392struct xenusb_conn_response {393	uint16_t id;		/* request id */394	uint8_t portnum;	/* port number */395	uint8_t speed;		/* usb_device_speed */396#define XENUSB_SPEED_NONE	0397#define XENUSB_SPEED_LOW	1398#define XENUSB_SPEED_FULL	2399#define XENUSB_SPEED_HIGH	3400};401 402DEFINE_RING_TYPES(xenusb_conn, struct xenusb_conn_request, struct xenusb_conn_response);403#define XENUSB_CONN_RING_SIZE __CONST_RING_SIZE(xenusb_conn, XENUSB_RING_SIZE)404 405#endif /* __XEN_PUBLIC_IO_USBIF_H__ */406