25 */ 26#ifndef _USB_USBDI_H_ 27#define _USB_USBDI_H_ 28 29struct usb_fifo; 30struct usb_xfer; 31struct usb_device; 32struct usb_attach_arg; 33struct usb_interface; 34struct usb_endpoint; 35struct usb_page_cache; 36struct usb_page_search; 37struct usb_process; 38struct usb_proc_msg; 39struct usb_mbuf; 40struct mbuf; 41 42typedef enum { /* keep in sync with usb_errstr_table */ 43 USB_ERR_NORMAL_COMPLETION = 0, 44 USB_ERR_PENDING_REQUESTS, /* 1 */ 45 USB_ERR_NOT_STARTED, /* 2 */ 46 USB_ERR_INVAL, /* 3 */ 47 USB_ERR_NOMEM, /* 4 */ 48 USB_ERR_CANCELLED, /* 5 */ 49 USB_ERR_BAD_ADDRESS, /* 6 */ 50 USB_ERR_BAD_BUFSIZE, /* 7 */ 51 USB_ERR_BAD_FLAG, /* 8 */ 52 USB_ERR_NO_CALLBACK, /* 9 */ 53 USB_ERR_IN_USE, /* 10 */ 54 USB_ERR_NO_ADDR, /* 11 */ 55 USB_ERR_NO_PIPE, /* 12 */ 56 USB_ERR_ZERO_NFRAMES, /* 13 */ 57 USB_ERR_ZERO_MAXP, /* 14 */ 58 USB_ERR_SET_ADDR_FAILED, /* 15 */ 59 USB_ERR_NO_POWER, /* 16 */ 60 USB_ERR_TOO_DEEP, /* 17 */ 61 USB_ERR_IOERROR, /* 18 */ 62 USB_ERR_NOT_CONFIGURED, /* 19 */ 63 USB_ERR_TIMEOUT, /* 20 */ 64 USB_ERR_SHORT_XFER, /* 21 */ 65 USB_ERR_STALLED, /* 22 */ 66 USB_ERR_INTERRUPTED, /* 23 */ 67 USB_ERR_DMA_LOAD_FAILED, /* 24 */ 68 USB_ERR_BAD_CONTEXT, /* 25 */ 69 USB_ERR_NO_ROOT_HUB, /* 26 */ 70 USB_ERR_NO_INTR_THREAD, /* 27 */ 71 USB_ERR_NOT_LOCKED, /* 28 */ 72 USB_ERR_MAX 73} usb_error_t; 74 75/* 76 * Flags for transfers 77 */ 78#define USB_FORCE_SHORT_XFER 0x0001 /* force a short transmit last */ 79#define USB_SHORT_XFER_OK 0x0004 /* allow short reads */ 80#define USB_DELAY_STATUS_STAGE 0x0010 /* insert delay before STATUS stage */ 81#define USB_USER_DATA_PTR 0x0020 /* internal flag */ 82#define USB_MULTI_SHORT_OK 0x0040 /* allow multiple short frames */ 83#define USB_MANUAL_STATUS 0x0080 /* manual ctrl status */ 84 85#define USB_NO_TIMEOUT 0 86#define USB_DEFAULT_TIMEOUT 5000 /* 5000 ms = 5 seconds */ 87 88#if defined(_KERNEL) 89/* typedefs */ 90 91typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t); 92typedef void (usb_proc_callback_t)(struct usb_proc_msg *); 93typedef usb_error_t (usb_handle_req_t)(struct usb_device *, 94 struct usb_device_request *, const void **, uint16_t *); 95 96typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags); 97typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags); 98typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags); 99typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo); 100typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m); 101 102 103/* USB events */ 104#include <sys/eventhandler.h> 105typedef void (*usb_dev_configured_t)(void *, struct usb_device *, 106 struct usb_attach_arg *); 107EVENTHANDLER_DECLARE(usb_dev_configured, usb_dev_configured_t); 108 109/* 110 * The following macros are used used to convert milliseconds into 111 * HZ. We use 1024 instead of 1000 milliseconds per second to save a 112 * full division. 113 */ 114#define USB_MS_HZ 1024 115 116#define USB_MS_TO_TICKS(ms) \ 117 (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ) 118 119/* 120 * Common queue structure for USB transfers. 121 */ 122struct usb_xfer_queue { 123 TAILQ_HEAD(, usb_xfer) head; 124 struct usb_xfer *curr; /* current USB transfer processed */ 125 void (*command) (struct usb_xfer_queue *pq); 126 uint8_t recurse_1:1; 127 uint8_t recurse_2:1; 128}; 129 130/* 131 * The following structure defines an USB endpoint 132 * USB endpoint. 133 */ 134struct usb_endpoint { 135 struct usb_xfer_queue endpoint_q; /* queue of USB transfers */ 136 137 struct usb_endpoint_descriptor *edesc; 138 struct usb_endpoint_ss_comp_descriptor *ecomp; 139 struct usb_pipe_methods *methods; /* set by HC driver */ 140 141 uint16_t isoc_next; 142 143 uint8_t toggle_next:1; /* next data toggle value */ 144 uint8_t is_stalled:1; /* set if endpoint is stalled */ 145 uint8_t is_synced:1; /* set if we a synchronised */ 146 uint8_t unused:5; 147 uint8_t iface_index; /* not used by "default endpoint" */ 148 149 uint8_t refcount_alloc; /* allocation refcount */ 150 uint8_t refcount_bw; /* bandwidth refcount */ 151#define USB_EP_REF_MAX 0x3f 152 153 /* High-Speed resource allocation (valid if "refcount_bw" > 0) */ 154 155 uint8_t usb_smask; /* USB start mask */ 156 uint8_t usb_cmask; /* USB complete mask */ 157 uint8_t usb_uframe; /* USB microframe */ 158}; 159 160/* 161 * The following structure defines an USB interface. 162 */ 163struct usb_interface { 164 struct usb_interface_descriptor *idesc; 165 device_t subdev; 166 uint8_t alt_index; 167 uint8_t parent_iface_index; 168 169 /* Linux compat */ 170 struct usb_host_interface *altsetting; 171 struct usb_host_interface *cur_altsetting; 172 struct usb_device *linux_udev; 173 void *bsd_priv_sc; /* device specific information */ 174 char *pnpinfo; /* additional PnP-info for this interface */ 175 uint8_t num_altsetting; /* number of alternate settings */ 176 uint8_t bsd_iface_index; 177}; 178 179/* 180 * The following structure defines a set of USB transfer flags. 181 */ 182struct usb_xfer_flags { 183 uint8_t force_short_xfer:1; /* force a short transmit transfer 184 * last */ 185 uint8_t short_xfer_ok:1; /* allow short receive transfers */ 186 uint8_t short_frames_ok:1; /* allow short frames */ 187 uint8_t pipe_bof:1; /* block pipe on failure */ 188 uint8_t proxy_buffer:1; /* makes buffer size a factor of 189 * "max_frame_size" */ 190 uint8_t ext_buffer:1; /* uses external DMA buffer */ 191 uint8_t manual_status:1; /* non automatic status stage on 192 * control transfers */ 193 uint8_t no_pipe_ok:1; /* set if "USB_ERR_NO_PIPE" error can 194 * be ignored */ 195 uint8_t stall_pipe:1; /* set if the endpoint belonging to 196 * this USB transfer should be stalled 197 * before starting this transfer! */ 198 uint8_t pre_scale_frames:1; /* "usb_config->frames" is 199 * assumed to give the 200 * buffering time in 201 * milliseconds and is 202 * converted into the nearest 203 * number of frames when the 204 * USB transfer is setup. This 205 * option only has effect for 206 * ISOCHRONOUS transfers. 207 */ 208}; 209 210/* 211 * The following structure define an USB configuration, that basically 212 * is used when setting up an USB transfer. 213 */ 214struct usb_config { 215 usb_callback_t *callback; /* USB transfer callback */ 216 usb_frlength_t bufsize; /* total pipe buffer size in bytes */ 217 usb_frcount_t frames; /* maximum number of USB frames */ 218 usb_timeout_t interval; /* interval in milliseconds */ 219#define USB_DEFAULT_INTERVAL 0 220 usb_timeout_t timeout; /* transfer timeout in milliseconds */ 221 struct usb_xfer_flags flags; /* transfer flags */ 222 enum usb_hc_mode usb_mode; /* host or device mode */ 223 uint8_t type; /* pipe type */ 224 uint8_t endpoint; /* pipe number */ 225 uint8_t direction; /* pipe direction */ 226 uint8_t ep_index; /* pipe index match to use */ 227 uint8_t if_index; /* "ifaces" index to use */ 228}; 229 230/* 231 * The following structure is used when looking up an USB driver for 232 * an USB device. It is inspired by the Linux structure called 233 * "usb_device_id". 234 */ 235struct usb_device_id { 236 237 /* Hook for driver specific information */ 238 unsigned long driver_info; 239 240 /* Used for product specific matches; the BCD range is inclusive */ 241 uint16_t idVendor; 242 uint16_t idProduct; 243 uint16_t bcdDevice_lo; 244 uint16_t bcdDevice_hi; 245 246 /* Used for device class matches */ 247 uint8_t bDeviceClass; 248 uint8_t bDeviceSubClass; 249 uint8_t bDeviceProtocol; 250 251 /* Used for interface class matches */ 252 uint8_t bInterfaceClass; 253 uint8_t bInterfaceSubClass; 254 uint8_t bInterfaceProtocol; 255 256 /* Select which fields to match against */ 257 uint8_t match_flag_vendor:1; 258 uint8_t match_flag_product:1; 259 uint8_t match_flag_dev_lo:1; 260 uint8_t match_flag_dev_hi:1; 261 uint8_t match_flag_dev_class:1; 262 uint8_t match_flag_dev_subclass:1; 263 uint8_t match_flag_dev_protocol:1; 264 uint8_t match_flag_int_class:1; 265 uint8_t match_flag_int_subclass:1; 266 uint8_t match_flag_int_protocol:1; 267 268#if USB_HAVE_COMPAT_LINUX 269 /* which fields to match against */ 270 uint16_t match_flags; 271#define USB_DEVICE_ID_MATCH_VENDOR 0x0001 272#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002 273#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004 274#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008 275#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010 276#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020 277#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040 278#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080 279#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100 280#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200 281#endif 282}; 283 284#define USB_VENDOR(vend) \ 285 .match_flag_vendor = 1, .idVendor = (vend) 286 287#define USB_PRODUCT(prod) \ 288 .match_flag_product = 1, .idProduct = (prod) 289 290#define USB_VP(vend,prod) \ 291 USB_VENDOR(vend), USB_PRODUCT(prod) 292 293#define USB_VPI(vend,prod,info) \ 294 USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info) 295 296#define USB_DEV_BCD_GTEQ(lo) /* greater than or equal */ \ 297 .match_flag_dev_lo = 1, .bcdDevice_lo = (lo) 298 299#define USB_DEV_BCD_LTEQ(hi) /* less than or equal */ \ 300 .match_flag_dev_hi = 1, .bcdDevice_hi = (hi) 301 302#define USB_DEV_CLASS(dc) \ 303 .match_flag_dev_class = 1, .bDeviceClass = (dc) 304 305#define USB_DEV_SUBCLASS(dsc) \ 306 .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc) 307 308#define USB_DEV_PROTOCOL(dp) \ 309 .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp) 310 311#define USB_IFACE_CLASS(ic) \ 312 .match_flag_int_class = 1, .bInterfaceClass = (ic) 313 314#define USB_IFACE_SUBCLASS(isc) \ 315 .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc) 316 317#define USB_IFACE_PROTOCOL(ip) \ 318 .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip) 319 320#define USB_IF_CSI(class,subclass,info) \ 321 USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info) 322 323#define USB_DRIVER_INFO(n) \ 324 .driver_info = (n) 325 326#define USB_GET_DRIVER_INFO(did) \ 327 (did)->driver_info 328 329/* 330 * The following structure keeps information that is used to match 331 * against an array of "usb_device_id" elements. 332 */ 333struct usbd_lookup_info { 334 uint16_t idVendor; 335 uint16_t idProduct; 336 uint16_t bcdDevice; 337 uint8_t bDeviceClass; 338 uint8_t bDeviceSubClass; 339 uint8_t bDeviceProtocol; 340 uint8_t bInterfaceClass; 341 uint8_t bInterfaceSubClass; 342 uint8_t bInterfaceProtocol; 343 uint8_t bIfaceIndex; 344 uint8_t bIfaceNum; 345 uint8_t bConfigIndex; 346 uint8_t bConfigNum; 347}; 348 349/* Structure used by probe and attach */ 350 351struct usb_attach_arg { 352 struct usbd_lookup_info info; 353 device_t temp_dev; /* for internal use */ 354 unsigned long driver_info; /* for internal use */ 355 void *driver_ivar; 356 struct usb_device *device; /* current device */ 357 struct usb_interface *iface; /* current interface */ 358 enum usb_hc_mode usb_mode; /* host or device mode */ 359 uint8_t port; 360 uint8_t use_generic; /* hint for generic drivers */ 361 uint8_t dev_state; 362#define UAA_DEV_READY 0 363#define UAA_DEV_DISABLED 1 364#define UAA_DEV_EJECTING 2 365}; 366 367/* 368 * The following is a wrapper for the callout structure to ease 369 * porting the code to other platforms. 370 */ 371struct usb_callout { 372 struct callout co; 373}; 374#define usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f) 375#define usb_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d) 376#define usb_callout_stop(c) callout_stop(&(c)->co) 377#define usb_callout_drain(c) callout_drain(&(c)->co) 378#define usb_callout_pending(c) callout_pending(&(c)->co) 379 380/* USB transfer states */ 381 382#define USB_ST_SETUP 0 383#define USB_ST_TRANSFERRED 1 384#define USB_ST_ERROR 2 385 386/* USB handle request states */ 387#define USB_HR_NOT_COMPLETE 0 388#define USB_HR_COMPLETE_OK 1 389#define USB_HR_COMPLETE_ERR 2 390 391/* 392 * The following macro will return the current state of an USB 393 * transfer like defined by the "USB_ST_XXX" enums. 394 */ 395#define USB_GET_STATE(xfer) (usbd_xfer_state(xfer)) 396 397/* 398 * The following structure defines the USB process message header. 399 */ 400struct usb_proc_msg { 401 TAILQ_ENTRY(usb_proc_msg) pm_qentry; 402 usb_proc_callback_t *pm_callback; 403 usb_size_t pm_num; 404}; 405 406#define USB_FIFO_TX 0 407#define USB_FIFO_RX 1 408 409/* 410 * Locking note for the following functions. All the 411 * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called 412 * locked. The others are called unlocked. 413 */ 414struct usb_fifo_methods { 415 usb_fifo_open_t *f_open; 416 usb_fifo_close_t *f_close; 417 usb_fifo_ioctl_t *f_ioctl; 418 /* 419 * NOTE: The post-ioctl callback is called after the USB reference 420 * gets locked in the IOCTL handler: 421 */ 422 usb_fifo_ioctl_t *f_ioctl_post; 423 usb_fifo_cmd_t *f_start_read; 424 usb_fifo_cmd_t *f_stop_read; 425 usb_fifo_cmd_t *f_start_write; 426 usb_fifo_cmd_t *f_stop_write; 427 usb_fifo_filter_t *f_filter_read; 428 usb_fifo_filter_t *f_filter_write; 429 const char *basename[4]; 430 const char *postfix[4]; 431}; 432 433struct usb_fifo_sc { 434 struct usb_fifo *fp[2]; 435 struct cdev* dev; 436}; 437 438const char *usbd_errstr(usb_error_t error); 439void *usbd_find_descriptor(struct usb_device *udev, void *id, 440 uint8_t iface_index, uint8_t type, uint8_t type_mask, 441 uint8_t subtype, uint8_t subtype_mask); 442struct usb_config_descriptor *usbd_get_config_descriptor( 443 struct usb_device *udev); 444struct usb_device_descriptor *usbd_get_device_descriptor( 445 struct usb_device *udev); 446struct usb_interface *usbd_get_iface(struct usb_device *udev, 447 uint8_t iface_index); 448struct usb_interface_descriptor *usbd_get_interface_descriptor( 449 struct usb_interface *iface); 450struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index, 451 const struct usb_config *setup); 452struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val); 453usb_error_t usbd_interface_count(struct usb_device *udev, uint8_t *count); 454enum usb_hc_mode usbd_get_mode(struct usb_device *udev); 455enum usb_dev_speed usbd_get_speed(struct usb_device *udev); 456void device_set_usb_desc(device_t dev); 457void usb_pause_mtx(struct mtx *mtx, int _ticks); 458usb_error_t usbd_set_pnpinfo(struct usb_device *udev, 459 uint8_t iface_index, const char *pnpinfo); 460 461const struct usb_device_id *usbd_lookup_id_by_info( 462 const struct usb_device_id *id, usb_size_t sizeof_id, 463 const struct usbd_lookup_info *info); 464int usbd_lookup_id_by_uaa(const struct usb_device_id *id, 465 usb_size_t sizeof_id, struct usb_attach_arg *uaa); 466 467usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx, 468 struct usb_device_request *req, void *data, uint16_t flags, 469 uint16_t *actlen, usb_timeout_t timeout); 470#define usbd_do_request(u,m,r,d) \ 471 usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT) 472 473uint8_t usbd_clear_stall_callback(struct usb_xfer *xfer1, 474 struct usb_xfer *xfer2); 475uint8_t usbd_get_interface_altindex(struct usb_interface *iface); 476usb_error_t usbd_set_alt_interface_index(struct usb_device *udev, 477 uint8_t iface_index, uint8_t alt_index); 478uint32_t usbd_get_isoc_fps(struct usb_device *udev); 479usb_error_t usbd_transfer_setup(struct usb_device *udev, 480 const uint8_t *ifaces, struct usb_xfer **pxfer, 481 const struct usb_config *setup_start, uint16_t n_setup, 482 void *priv_sc, struct mtx *priv_mtx); 483void usbd_transfer_submit(struct usb_xfer *xfer); 484void usbd_transfer_clear_stall(struct usb_xfer *xfer); 485void usbd_transfer_drain(struct usb_xfer *xfer); 486uint8_t usbd_transfer_pending(struct usb_xfer *xfer); 487void usbd_transfer_start(struct usb_xfer *xfer); 488void usbd_transfer_stop(struct usb_xfer *xfer); 489void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup); 490void usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max); 491void usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index, 492 uint8_t parent_index); 493uint8_t usbd_get_bus_index(struct usb_device *udev); 494uint8_t usbd_get_device_index(struct usb_device *udev); 495void usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode); 496uint8_t usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode); 497uint8_t usbd_device_attached(struct usb_device *udev); 498
| 25 */ 26#ifndef _USB_USBDI_H_ 27#define _USB_USBDI_H_ 28 29struct usb_fifo; 30struct usb_xfer; 31struct usb_device; 32struct usb_attach_arg; 33struct usb_interface; 34struct usb_endpoint; 35struct usb_page_cache; 36struct usb_page_search; 37struct usb_process; 38struct usb_proc_msg; 39struct usb_mbuf; 40struct mbuf; 41 42typedef enum { /* keep in sync with usb_errstr_table */ 43 USB_ERR_NORMAL_COMPLETION = 0, 44 USB_ERR_PENDING_REQUESTS, /* 1 */ 45 USB_ERR_NOT_STARTED, /* 2 */ 46 USB_ERR_INVAL, /* 3 */ 47 USB_ERR_NOMEM, /* 4 */ 48 USB_ERR_CANCELLED, /* 5 */ 49 USB_ERR_BAD_ADDRESS, /* 6 */ 50 USB_ERR_BAD_BUFSIZE, /* 7 */ 51 USB_ERR_BAD_FLAG, /* 8 */ 52 USB_ERR_NO_CALLBACK, /* 9 */ 53 USB_ERR_IN_USE, /* 10 */ 54 USB_ERR_NO_ADDR, /* 11 */ 55 USB_ERR_NO_PIPE, /* 12 */ 56 USB_ERR_ZERO_NFRAMES, /* 13 */ 57 USB_ERR_ZERO_MAXP, /* 14 */ 58 USB_ERR_SET_ADDR_FAILED, /* 15 */ 59 USB_ERR_NO_POWER, /* 16 */ 60 USB_ERR_TOO_DEEP, /* 17 */ 61 USB_ERR_IOERROR, /* 18 */ 62 USB_ERR_NOT_CONFIGURED, /* 19 */ 63 USB_ERR_TIMEOUT, /* 20 */ 64 USB_ERR_SHORT_XFER, /* 21 */ 65 USB_ERR_STALLED, /* 22 */ 66 USB_ERR_INTERRUPTED, /* 23 */ 67 USB_ERR_DMA_LOAD_FAILED, /* 24 */ 68 USB_ERR_BAD_CONTEXT, /* 25 */ 69 USB_ERR_NO_ROOT_HUB, /* 26 */ 70 USB_ERR_NO_INTR_THREAD, /* 27 */ 71 USB_ERR_NOT_LOCKED, /* 28 */ 72 USB_ERR_MAX 73} usb_error_t; 74 75/* 76 * Flags for transfers 77 */ 78#define USB_FORCE_SHORT_XFER 0x0001 /* force a short transmit last */ 79#define USB_SHORT_XFER_OK 0x0004 /* allow short reads */ 80#define USB_DELAY_STATUS_STAGE 0x0010 /* insert delay before STATUS stage */ 81#define USB_USER_DATA_PTR 0x0020 /* internal flag */ 82#define USB_MULTI_SHORT_OK 0x0040 /* allow multiple short frames */ 83#define USB_MANUAL_STATUS 0x0080 /* manual ctrl status */ 84 85#define USB_NO_TIMEOUT 0 86#define USB_DEFAULT_TIMEOUT 5000 /* 5000 ms = 5 seconds */ 87 88#if defined(_KERNEL) 89/* typedefs */ 90 91typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t); 92typedef void (usb_proc_callback_t)(struct usb_proc_msg *); 93typedef usb_error_t (usb_handle_req_t)(struct usb_device *, 94 struct usb_device_request *, const void **, uint16_t *); 95 96typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags); 97typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags); 98typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags); 99typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo); 100typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m); 101 102 103/* USB events */ 104#include <sys/eventhandler.h> 105typedef void (*usb_dev_configured_t)(void *, struct usb_device *, 106 struct usb_attach_arg *); 107EVENTHANDLER_DECLARE(usb_dev_configured, usb_dev_configured_t); 108 109/* 110 * The following macros are used used to convert milliseconds into 111 * HZ. We use 1024 instead of 1000 milliseconds per second to save a 112 * full division. 113 */ 114#define USB_MS_HZ 1024 115 116#define USB_MS_TO_TICKS(ms) \ 117 (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ) 118 119/* 120 * Common queue structure for USB transfers. 121 */ 122struct usb_xfer_queue { 123 TAILQ_HEAD(, usb_xfer) head; 124 struct usb_xfer *curr; /* current USB transfer processed */ 125 void (*command) (struct usb_xfer_queue *pq); 126 uint8_t recurse_1:1; 127 uint8_t recurse_2:1; 128}; 129 130/* 131 * The following structure defines an USB endpoint 132 * USB endpoint. 133 */ 134struct usb_endpoint { 135 struct usb_xfer_queue endpoint_q; /* queue of USB transfers */ 136 137 struct usb_endpoint_descriptor *edesc; 138 struct usb_endpoint_ss_comp_descriptor *ecomp; 139 struct usb_pipe_methods *methods; /* set by HC driver */ 140 141 uint16_t isoc_next; 142 143 uint8_t toggle_next:1; /* next data toggle value */ 144 uint8_t is_stalled:1; /* set if endpoint is stalled */ 145 uint8_t is_synced:1; /* set if we a synchronised */ 146 uint8_t unused:5; 147 uint8_t iface_index; /* not used by "default endpoint" */ 148 149 uint8_t refcount_alloc; /* allocation refcount */ 150 uint8_t refcount_bw; /* bandwidth refcount */ 151#define USB_EP_REF_MAX 0x3f 152 153 /* High-Speed resource allocation (valid if "refcount_bw" > 0) */ 154 155 uint8_t usb_smask; /* USB start mask */ 156 uint8_t usb_cmask; /* USB complete mask */ 157 uint8_t usb_uframe; /* USB microframe */ 158}; 159 160/* 161 * The following structure defines an USB interface. 162 */ 163struct usb_interface { 164 struct usb_interface_descriptor *idesc; 165 device_t subdev; 166 uint8_t alt_index; 167 uint8_t parent_iface_index; 168 169 /* Linux compat */ 170 struct usb_host_interface *altsetting; 171 struct usb_host_interface *cur_altsetting; 172 struct usb_device *linux_udev; 173 void *bsd_priv_sc; /* device specific information */ 174 char *pnpinfo; /* additional PnP-info for this interface */ 175 uint8_t num_altsetting; /* number of alternate settings */ 176 uint8_t bsd_iface_index; 177}; 178 179/* 180 * The following structure defines a set of USB transfer flags. 181 */ 182struct usb_xfer_flags { 183 uint8_t force_short_xfer:1; /* force a short transmit transfer 184 * last */ 185 uint8_t short_xfer_ok:1; /* allow short receive transfers */ 186 uint8_t short_frames_ok:1; /* allow short frames */ 187 uint8_t pipe_bof:1; /* block pipe on failure */ 188 uint8_t proxy_buffer:1; /* makes buffer size a factor of 189 * "max_frame_size" */ 190 uint8_t ext_buffer:1; /* uses external DMA buffer */ 191 uint8_t manual_status:1; /* non automatic status stage on 192 * control transfers */ 193 uint8_t no_pipe_ok:1; /* set if "USB_ERR_NO_PIPE" error can 194 * be ignored */ 195 uint8_t stall_pipe:1; /* set if the endpoint belonging to 196 * this USB transfer should be stalled 197 * before starting this transfer! */ 198 uint8_t pre_scale_frames:1; /* "usb_config->frames" is 199 * assumed to give the 200 * buffering time in 201 * milliseconds and is 202 * converted into the nearest 203 * number of frames when the 204 * USB transfer is setup. This 205 * option only has effect for 206 * ISOCHRONOUS transfers. 207 */ 208}; 209 210/* 211 * The following structure define an USB configuration, that basically 212 * is used when setting up an USB transfer. 213 */ 214struct usb_config { 215 usb_callback_t *callback; /* USB transfer callback */ 216 usb_frlength_t bufsize; /* total pipe buffer size in bytes */ 217 usb_frcount_t frames; /* maximum number of USB frames */ 218 usb_timeout_t interval; /* interval in milliseconds */ 219#define USB_DEFAULT_INTERVAL 0 220 usb_timeout_t timeout; /* transfer timeout in milliseconds */ 221 struct usb_xfer_flags flags; /* transfer flags */ 222 enum usb_hc_mode usb_mode; /* host or device mode */ 223 uint8_t type; /* pipe type */ 224 uint8_t endpoint; /* pipe number */ 225 uint8_t direction; /* pipe direction */ 226 uint8_t ep_index; /* pipe index match to use */ 227 uint8_t if_index; /* "ifaces" index to use */ 228}; 229 230/* 231 * The following structure is used when looking up an USB driver for 232 * an USB device. It is inspired by the Linux structure called 233 * "usb_device_id". 234 */ 235struct usb_device_id { 236 237 /* Hook for driver specific information */ 238 unsigned long driver_info; 239 240 /* Used for product specific matches; the BCD range is inclusive */ 241 uint16_t idVendor; 242 uint16_t idProduct; 243 uint16_t bcdDevice_lo; 244 uint16_t bcdDevice_hi; 245 246 /* Used for device class matches */ 247 uint8_t bDeviceClass; 248 uint8_t bDeviceSubClass; 249 uint8_t bDeviceProtocol; 250 251 /* Used for interface class matches */ 252 uint8_t bInterfaceClass; 253 uint8_t bInterfaceSubClass; 254 uint8_t bInterfaceProtocol; 255 256 /* Select which fields to match against */ 257 uint8_t match_flag_vendor:1; 258 uint8_t match_flag_product:1; 259 uint8_t match_flag_dev_lo:1; 260 uint8_t match_flag_dev_hi:1; 261 uint8_t match_flag_dev_class:1; 262 uint8_t match_flag_dev_subclass:1; 263 uint8_t match_flag_dev_protocol:1; 264 uint8_t match_flag_int_class:1; 265 uint8_t match_flag_int_subclass:1; 266 uint8_t match_flag_int_protocol:1; 267 268#if USB_HAVE_COMPAT_LINUX 269 /* which fields to match against */ 270 uint16_t match_flags; 271#define USB_DEVICE_ID_MATCH_VENDOR 0x0001 272#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002 273#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004 274#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008 275#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010 276#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020 277#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040 278#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080 279#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100 280#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200 281#endif 282}; 283 284#define USB_VENDOR(vend) \ 285 .match_flag_vendor = 1, .idVendor = (vend) 286 287#define USB_PRODUCT(prod) \ 288 .match_flag_product = 1, .idProduct = (prod) 289 290#define USB_VP(vend,prod) \ 291 USB_VENDOR(vend), USB_PRODUCT(prod) 292 293#define USB_VPI(vend,prod,info) \ 294 USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info) 295 296#define USB_DEV_BCD_GTEQ(lo) /* greater than or equal */ \ 297 .match_flag_dev_lo = 1, .bcdDevice_lo = (lo) 298 299#define USB_DEV_BCD_LTEQ(hi) /* less than or equal */ \ 300 .match_flag_dev_hi = 1, .bcdDevice_hi = (hi) 301 302#define USB_DEV_CLASS(dc) \ 303 .match_flag_dev_class = 1, .bDeviceClass = (dc) 304 305#define USB_DEV_SUBCLASS(dsc) \ 306 .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc) 307 308#define USB_DEV_PROTOCOL(dp) \ 309 .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp) 310 311#define USB_IFACE_CLASS(ic) \ 312 .match_flag_int_class = 1, .bInterfaceClass = (ic) 313 314#define USB_IFACE_SUBCLASS(isc) \ 315 .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc) 316 317#define USB_IFACE_PROTOCOL(ip) \ 318 .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip) 319 320#define USB_IF_CSI(class,subclass,info) \ 321 USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info) 322 323#define USB_DRIVER_INFO(n) \ 324 .driver_info = (n) 325 326#define USB_GET_DRIVER_INFO(did) \ 327 (did)->driver_info 328 329/* 330 * The following structure keeps information that is used to match 331 * against an array of "usb_device_id" elements. 332 */ 333struct usbd_lookup_info { 334 uint16_t idVendor; 335 uint16_t idProduct; 336 uint16_t bcdDevice; 337 uint8_t bDeviceClass; 338 uint8_t bDeviceSubClass; 339 uint8_t bDeviceProtocol; 340 uint8_t bInterfaceClass; 341 uint8_t bInterfaceSubClass; 342 uint8_t bInterfaceProtocol; 343 uint8_t bIfaceIndex; 344 uint8_t bIfaceNum; 345 uint8_t bConfigIndex; 346 uint8_t bConfigNum; 347}; 348 349/* Structure used by probe and attach */ 350 351struct usb_attach_arg { 352 struct usbd_lookup_info info; 353 device_t temp_dev; /* for internal use */ 354 unsigned long driver_info; /* for internal use */ 355 void *driver_ivar; 356 struct usb_device *device; /* current device */ 357 struct usb_interface *iface; /* current interface */ 358 enum usb_hc_mode usb_mode; /* host or device mode */ 359 uint8_t port; 360 uint8_t use_generic; /* hint for generic drivers */ 361 uint8_t dev_state; 362#define UAA_DEV_READY 0 363#define UAA_DEV_DISABLED 1 364#define UAA_DEV_EJECTING 2 365}; 366 367/* 368 * The following is a wrapper for the callout structure to ease 369 * porting the code to other platforms. 370 */ 371struct usb_callout { 372 struct callout co; 373}; 374#define usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f) 375#define usb_callout_reset(c,t,f,d) callout_reset(&(c)->co,t,f,d) 376#define usb_callout_stop(c) callout_stop(&(c)->co) 377#define usb_callout_drain(c) callout_drain(&(c)->co) 378#define usb_callout_pending(c) callout_pending(&(c)->co) 379 380/* USB transfer states */ 381 382#define USB_ST_SETUP 0 383#define USB_ST_TRANSFERRED 1 384#define USB_ST_ERROR 2 385 386/* USB handle request states */ 387#define USB_HR_NOT_COMPLETE 0 388#define USB_HR_COMPLETE_OK 1 389#define USB_HR_COMPLETE_ERR 2 390 391/* 392 * The following macro will return the current state of an USB 393 * transfer like defined by the "USB_ST_XXX" enums. 394 */ 395#define USB_GET_STATE(xfer) (usbd_xfer_state(xfer)) 396 397/* 398 * The following structure defines the USB process message header. 399 */ 400struct usb_proc_msg { 401 TAILQ_ENTRY(usb_proc_msg) pm_qentry; 402 usb_proc_callback_t *pm_callback; 403 usb_size_t pm_num; 404}; 405 406#define USB_FIFO_TX 0 407#define USB_FIFO_RX 1 408 409/* 410 * Locking note for the following functions. All the 411 * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called 412 * locked. The others are called unlocked. 413 */ 414struct usb_fifo_methods { 415 usb_fifo_open_t *f_open; 416 usb_fifo_close_t *f_close; 417 usb_fifo_ioctl_t *f_ioctl; 418 /* 419 * NOTE: The post-ioctl callback is called after the USB reference 420 * gets locked in the IOCTL handler: 421 */ 422 usb_fifo_ioctl_t *f_ioctl_post; 423 usb_fifo_cmd_t *f_start_read; 424 usb_fifo_cmd_t *f_stop_read; 425 usb_fifo_cmd_t *f_start_write; 426 usb_fifo_cmd_t *f_stop_write; 427 usb_fifo_filter_t *f_filter_read; 428 usb_fifo_filter_t *f_filter_write; 429 const char *basename[4]; 430 const char *postfix[4]; 431}; 432 433struct usb_fifo_sc { 434 struct usb_fifo *fp[2]; 435 struct cdev* dev; 436}; 437 438const char *usbd_errstr(usb_error_t error); 439void *usbd_find_descriptor(struct usb_device *udev, void *id, 440 uint8_t iface_index, uint8_t type, uint8_t type_mask, 441 uint8_t subtype, uint8_t subtype_mask); 442struct usb_config_descriptor *usbd_get_config_descriptor( 443 struct usb_device *udev); 444struct usb_device_descriptor *usbd_get_device_descriptor( 445 struct usb_device *udev); 446struct usb_interface *usbd_get_iface(struct usb_device *udev, 447 uint8_t iface_index); 448struct usb_interface_descriptor *usbd_get_interface_descriptor( 449 struct usb_interface *iface); 450struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index, 451 const struct usb_config *setup); 452struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val); 453usb_error_t usbd_interface_count(struct usb_device *udev, uint8_t *count); 454enum usb_hc_mode usbd_get_mode(struct usb_device *udev); 455enum usb_dev_speed usbd_get_speed(struct usb_device *udev); 456void device_set_usb_desc(device_t dev); 457void usb_pause_mtx(struct mtx *mtx, int _ticks); 458usb_error_t usbd_set_pnpinfo(struct usb_device *udev, 459 uint8_t iface_index, const char *pnpinfo); 460 461const struct usb_device_id *usbd_lookup_id_by_info( 462 const struct usb_device_id *id, usb_size_t sizeof_id, 463 const struct usbd_lookup_info *info); 464int usbd_lookup_id_by_uaa(const struct usb_device_id *id, 465 usb_size_t sizeof_id, struct usb_attach_arg *uaa); 466 467usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx, 468 struct usb_device_request *req, void *data, uint16_t flags, 469 uint16_t *actlen, usb_timeout_t timeout); 470#define usbd_do_request(u,m,r,d) \ 471 usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT) 472 473uint8_t usbd_clear_stall_callback(struct usb_xfer *xfer1, 474 struct usb_xfer *xfer2); 475uint8_t usbd_get_interface_altindex(struct usb_interface *iface); 476usb_error_t usbd_set_alt_interface_index(struct usb_device *udev, 477 uint8_t iface_index, uint8_t alt_index); 478uint32_t usbd_get_isoc_fps(struct usb_device *udev); 479usb_error_t usbd_transfer_setup(struct usb_device *udev, 480 const uint8_t *ifaces, struct usb_xfer **pxfer, 481 const struct usb_config *setup_start, uint16_t n_setup, 482 void *priv_sc, struct mtx *priv_mtx); 483void usbd_transfer_submit(struct usb_xfer *xfer); 484void usbd_transfer_clear_stall(struct usb_xfer *xfer); 485void usbd_transfer_drain(struct usb_xfer *xfer); 486uint8_t usbd_transfer_pending(struct usb_xfer *xfer); 487void usbd_transfer_start(struct usb_xfer *xfer); 488void usbd_transfer_stop(struct usb_xfer *xfer); 489void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup); 490void usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max); 491void usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index, 492 uint8_t parent_index); 493uint8_t usbd_get_bus_index(struct usb_device *udev); 494uint8_t usbd_get_device_index(struct usb_device *udev); 495void usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode); 496uint8_t usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode); 497uint8_t usbd_device_attached(struct usb_device *udev); 498
|
499void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, 500 int *aframes, int *nframes); 501struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *xfer, 502 usb_frcount_t frindex); 503void *usbd_xfer_softc(struct usb_xfer *xfer); 504void *usbd_xfer_get_priv(struct usb_xfer *xfer); 505void usbd_xfer_set_priv(struct usb_xfer *xfer, void *); 506void usbd_xfer_set_interval(struct usb_xfer *xfer, int); 507uint8_t usbd_xfer_state(struct usb_xfer *xfer); 508void usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, 509 void *ptr, usb_frlength_t len); 510void usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, 511 void **ptr, int *len); 512void usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset, 513 usb_frcount_t frindex); 514usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer); 515usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer); 516usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer); 517uint8_t usbd_xfer_get_fps_shift(struct usb_xfer *xfer); 518usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer, 519 usb_frcount_t frindex); 520void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, 521 usb_frlength_t len); 522void usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout); 523void usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n); 524void usbd_xfer_set_stall(struct usb_xfer *xfer); 525int usbd_xfer_is_stalled(struct usb_xfer *xfer); 526void usbd_xfer_set_flag(struct usb_xfer *xfer, int flag); 527void usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag); 528uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer); 529 530void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, 531 const void *ptr, usb_frlength_t len); 532int usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset, 533 const void *ptr, usb_frlength_t len); 534void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, 535 void *ptr, usb_frlength_t len); 536int usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset, 537 void *ptr, usb_frlength_t len); 538void usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset, 539 struct usb_page_search *res); 540void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset, 541 struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len); 542void usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset, 543 usb_frlength_t len); 544 545int usb_fifo_attach(struct usb_device *udev, void *priv_sc, 546 struct mtx *priv_mtx, struct usb_fifo_methods *pm, 547 struct usb_fifo_sc *f_sc, uint16_t unit, uint16_t subunit, 548 uint8_t iface_index, uid_t uid, gid_t gid, int mode); 549void usb_fifo_detach(struct usb_fifo_sc *f_sc); 550int usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize, 551 uint16_t nbuf); 552void usb_fifo_free_buffer(struct usb_fifo *f); 553uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo); 554void usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc, 555 usb_frlength_t offset, usb_frlength_t len, uint8_t what); 556void usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr, 557 usb_size_t len, uint8_t what); 558uint8_t usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len); 559void usb_fifo_put_data_error(struct usb_fifo *fifo); 560uint8_t usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc, 561 usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen, 562 uint8_t what); 563uint8_t usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr, 564 usb_size_t len, usb_size_t *actlen, uint8_t what); 565uint8_t usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr, 566 usb_size_t *plen); 567void usb_fifo_reset(struct usb_fifo *f); 568void usb_fifo_wakeup(struct usb_fifo *f); 569void usb_fifo_get_data_error(struct usb_fifo *fifo); 570void *usb_fifo_softc(struct usb_fifo *fifo); 571void usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t); 572void usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t); 573void usb_fifo_free(struct usb_fifo *f); 574#endif /* _KERNEL */ 575#endif /* _USB_USBDI_H_ */
| 501void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, 502 int *aframes, int *nframes); 503struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *xfer, 504 usb_frcount_t frindex); 505void *usbd_xfer_softc(struct usb_xfer *xfer); 506void *usbd_xfer_get_priv(struct usb_xfer *xfer); 507void usbd_xfer_set_priv(struct usb_xfer *xfer, void *); 508void usbd_xfer_set_interval(struct usb_xfer *xfer, int); 509uint8_t usbd_xfer_state(struct usb_xfer *xfer); 510void usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, 511 void *ptr, usb_frlength_t len); 512void usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, 513 void **ptr, int *len); 514void usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset, 515 usb_frcount_t frindex); 516usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer); 517usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer); 518usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer); 519uint8_t usbd_xfer_get_fps_shift(struct usb_xfer *xfer); 520usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer, 521 usb_frcount_t frindex); 522void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, 523 usb_frlength_t len); 524void usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout); 525void usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n); 526void usbd_xfer_set_stall(struct usb_xfer *xfer); 527int usbd_xfer_is_stalled(struct usb_xfer *xfer); 528void usbd_xfer_set_flag(struct usb_xfer *xfer, int flag); 529void usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag); 530uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer); 531 532void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, 533 const void *ptr, usb_frlength_t len); 534int usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset, 535 const void *ptr, usb_frlength_t len); 536void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, 537 void *ptr, usb_frlength_t len); 538int usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset, 539 void *ptr, usb_frlength_t len); 540void usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset, 541 struct usb_page_search *res); 542void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset, 543 struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len); 544void usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset, 545 usb_frlength_t len); 546 547int usb_fifo_attach(struct usb_device *udev, void *priv_sc, 548 struct mtx *priv_mtx, struct usb_fifo_methods *pm, 549 struct usb_fifo_sc *f_sc, uint16_t unit, uint16_t subunit, 550 uint8_t iface_index, uid_t uid, gid_t gid, int mode); 551void usb_fifo_detach(struct usb_fifo_sc *f_sc); 552int usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize, 553 uint16_t nbuf); 554void usb_fifo_free_buffer(struct usb_fifo *f); 555uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo); 556void usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc, 557 usb_frlength_t offset, usb_frlength_t len, uint8_t what); 558void usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr, 559 usb_size_t len, uint8_t what); 560uint8_t usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len); 561void usb_fifo_put_data_error(struct usb_fifo *fifo); 562uint8_t usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc, 563 usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen, 564 uint8_t what); 565uint8_t usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr, 566 usb_size_t len, usb_size_t *actlen, uint8_t what); 567uint8_t usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr, 568 usb_size_t *plen); 569void usb_fifo_reset(struct usb_fifo *f); 570void usb_fifo_wakeup(struct usb_fifo *f); 571void usb_fifo_get_data_error(struct usb_fifo *fifo); 572void *usb_fifo_softc(struct usb_fifo *fifo); 573void usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t); 574void usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t); 575void usb_fifo_free(struct usb_fifo *f); 576#endif /* _KERNEL */ 577#endif /* _USB_USBDI_H_ */
|