| 1 | /* | 
|---|
| 2 | * Copyright (c) 2011 Jan Vesely | 
|---|
| 3 | * All rights reserved. | 
|---|
| 4 | * | 
|---|
| 5 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 6 | * modification, are permitted provided that the following conditions | 
|---|
| 7 | * are met: | 
|---|
| 8 | * | 
|---|
| 9 | * - Redistributions of source code must retain the above copyright | 
|---|
| 10 | *   notice, this list of conditions and the following disclaimer. | 
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright | 
|---|
| 12 | *   notice, this list of conditions and the following disclaimer in the | 
|---|
| 13 | *   documentation and/or other materials provided with the distribution. | 
|---|
| 14 | * - The name of the author may not be used to endorse or promote products | 
|---|
| 15 | *   derived from this software without specific prior written permission. | 
|---|
| 16 | * | 
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 27 | */ | 
|---|
| 28 | /** @addtogroup usb | 
|---|
| 29 | * @{ | 
|---|
| 30 | */ | 
|---|
| 31 | /** @file | 
|---|
| 32 | * @brief UHCI driver | 
|---|
| 33 | */ | 
|---|
| 34 | #include <errno.h> | 
|---|
| 35 | #include <str_error.h> | 
|---|
| 36 | #include <adt/list.h> | 
|---|
| 37 | #include <libarch/ddi.h> | 
|---|
| 38 |  | 
|---|
| 39 | #include <usb/debug.h> | 
|---|
| 40 | #include <usb/usb.h> | 
|---|
| 41 | #include <usb/ddfiface.h> | 
|---|
| 42 | #include <usb_iface.h> | 
|---|
| 43 |  | 
|---|
| 44 | #include "uhci.h" | 
|---|
| 45 | #include "iface.h" | 
|---|
| 46 |  | 
|---|
| 47 | static irq_cmd_t uhci_cmds[] = { | 
|---|
| 48 | { | 
|---|
| 49 | .cmd = CMD_PIO_READ_16, | 
|---|
| 50 | .addr = (void*)0xc022, | 
|---|
| 51 | .dstarg = 1 | 
|---|
| 52 | }, | 
|---|
| 53 | { | 
|---|
| 54 | .cmd = CMD_PIO_WRITE_16, | 
|---|
| 55 | .addr = (void*)0xc022, | 
|---|
| 56 | .value = 0x1f | 
|---|
| 57 | }, | 
|---|
| 58 | { | 
|---|
| 59 | .cmd = CMD_ACCEPT | 
|---|
| 60 | } | 
|---|
| 61 | }; | 
|---|
| 62 |  | 
|---|
| 63 |  | 
|---|
| 64 | static int usb_iface_get_address(ddf_fun_t *fun, devman_handle_t handle, | 
|---|
| 65 | usb_address_t *address) | 
|---|
| 66 | { | 
|---|
| 67 | assert(fun); | 
|---|
| 68 | uhci_t *hc = fun_to_uhci(fun); | 
|---|
| 69 | assert(hc); | 
|---|
| 70 |  | 
|---|
| 71 | //      usb_address_t addr = usb_address_keeping_find(&hc->address_manager, | 
|---|
| 72 | //          handle); | 
|---|
| 73 | usb_address_t addr = device_keeper_find(&hc->device_manager, | 
|---|
| 74 | handle); | 
|---|
| 75 | if (addr < 0) { | 
|---|
| 76 | return addr; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | if (address != NULL) { | 
|---|
| 80 | *address = addr; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | return EOK; | 
|---|
| 84 | } | 
|---|
| 85 | /*----------------------------------------------------------------------------*/ | 
|---|
| 86 | static usb_iface_t hc_usb_iface = { | 
|---|
| 87 | .get_hc_handle = usb_iface_get_hc_handle_hc_impl, | 
|---|
| 88 | .get_address = usb_iface_get_address | 
|---|
| 89 | }; | 
|---|
| 90 | /*----------------------------------------------------------------------------*/ | 
|---|
| 91 | static ddf_dev_ops_t uhci_ops = { | 
|---|
| 92 | .interfaces[USB_DEV_IFACE] = &hc_usb_iface, | 
|---|
| 93 | .interfaces[USBHC_DEV_IFACE] = &uhci_iface, | 
|---|
| 94 | }; | 
|---|
| 95 |  | 
|---|
| 96 | static int uhci_init_transfer_lists(uhci_t *instance); | 
|---|
| 97 | static int uhci_init_mem_structures(uhci_t *instance); | 
|---|
| 98 | static void uhci_init_hw(uhci_t *instance); | 
|---|
| 99 |  | 
|---|
| 100 | static int uhci_interrupt_emulator(void *arg); | 
|---|
| 101 | static int uhci_debug_checker(void *arg); | 
|---|
| 102 |  | 
|---|
| 103 | static bool allowed_usb_packet( | 
|---|
| 104 | bool low_speed, usb_transfer_type_t, size_t size); | 
|---|
| 105 |  | 
|---|
| 106 | #define CHECK_RET_RETURN(ret, message...) \ | 
|---|
| 107 | if (ret != EOK) { \ | 
|---|
| 108 | usb_log_error(message); \ | 
|---|
| 109 | return ret; \ | 
|---|
| 110 | } else (void) 0 | 
|---|
| 111 |  | 
|---|
| 112 | int uhci_init(uhci_t *instance, ddf_dev_t *dev, void *regs, size_t reg_size) | 
|---|
| 113 | { | 
|---|
| 114 | assert(reg_size >= sizeof(regs_t)); | 
|---|
| 115 | int ret; | 
|---|
| 116 |  | 
|---|
| 117 | /* | 
|---|
| 118 | * Create UHCI function. | 
|---|
| 119 | */ | 
|---|
| 120 | instance->ddf_instance = ddf_fun_create(dev, fun_exposed, "uhci"); | 
|---|
| 121 | if (instance->ddf_instance == NULL) { | 
|---|
| 122 | usb_log_error("Failed to create UHCI device function.\n"); | 
|---|
| 123 | return ENOMEM; | 
|---|
| 124 | } | 
|---|
| 125 | instance->ddf_instance->ops = &uhci_ops; | 
|---|
| 126 | instance->ddf_instance->driver_data = instance; | 
|---|
| 127 |  | 
|---|
| 128 | ret = ddf_fun_bind(instance->ddf_instance); | 
|---|
| 129 | CHECK_RET_RETURN(ret, "Failed to bind UHCI device function: %s.\n", | 
|---|
| 130 | str_error(ret)); | 
|---|
| 131 |  | 
|---|
| 132 | /* allow access to hc control registers */ | 
|---|
| 133 | regs_t *io; | 
|---|
| 134 | ret = pio_enable(regs, reg_size, (void**)&io); | 
|---|
| 135 | CHECK_RET_RETURN(ret, "Failed to gain access to registers at %p.\n", io); | 
|---|
| 136 | instance->registers = io; | 
|---|
| 137 | usb_log_debug("Device registers accessible.\n"); | 
|---|
| 138 |  | 
|---|
| 139 | ret = uhci_init_mem_structures(instance); | 
|---|
| 140 | CHECK_RET_RETURN(ret, "Failed to initialize memory structures.\n"); | 
|---|
| 141 |  | 
|---|
| 142 | uhci_init_hw(instance); | 
|---|
| 143 |  | 
|---|
| 144 | instance->cleaner = fibril_create(uhci_interrupt_emulator, instance); | 
|---|
| 145 | fibril_add_ready(instance->cleaner); | 
|---|
| 146 |  | 
|---|
| 147 | instance->debug_checker = fibril_create(uhci_debug_checker, instance); | 
|---|
| 148 | fibril_add_ready(instance->debug_checker); | 
|---|
| 149 |  | 
|---|
| 150 | return EOK; | 
|---|
| 151 | } | 
|---|
| 152 | /*----------------------------------------------------------------------------*/ | 
|---|
| 153 | void uhci_init_hw(uhci_t *instance) | 
|---|
| 154 | { | 
|---|
| 155 | /* reset everything, who knows what touched it before us */ | 
|---|
| 156 | pio_write_16(&instance->registers->usbcmd, UHCI_CMD_GLOBAL_RESET); | 
|---|
| 157 | async_usleep(10000); /* 10ms according to USB spec */ | 
|---|
| 158 | pio_write_16(&instance->registers->usbcmd, 0); | 
|---|
| 159 |  | 
|---|
| 160 | /* reset hc, all states and counters */ | 
|---|
| 161 | pio_write_16(&instance->registers->usbcmd, UHCI_CMD_HCRESET); | 
|---|
| 162 | while ((pio_read_16(&instance->registers->usbcmd) & UHCI_CMD_HCRESET) != 0) | 
|---|
| 163 | { async_usleep(10); } | 
|---|
| 164 |  | 
|---|
| 165 | /* set framelist pointer */ | 
|---|
| 166 | const uint32_t pa = addr_to_phys(instance->frame_list); | 
|---|
| 167 | pio_write_32(&instance->registers->flbaseadd, pa); | 
|---|
| 168 |  | 
|---|
| 169 | /* enable all interrupts, but resume interrupt */ | 
|---|
| 170 | pio_write_16(&instance->registers->usbintr, | 
|---|
| 171 | UHCI_INTR_CRC | UHCI_INTR_COMPLETE | UHCI_INTR_SHORT_PACKET); | 
|---|
| 172 |  | 
|---|
| 173 | /* Start the hc with large(64B) packet FSBR */ | 
|---|
| 174 | pio_write_16(&instance->registers->usbcmd, | 
|---|
| 175 | UHCI_CMD_RUN_STOP | UHCI_CMD_MAX_PACKET | UHCI_CMD_CONFIGURE); | 
|---|
| 176 | usb_log_debug("Started UHCI HC.\n"); | 
|---|
| 177 | } | 
|---|
| 178 | /*----------------------------------------------------------------------------*/ | 
|---|
| 179 | int uhci_init_mem_structures(uhci_t *instance) | 
|---|
| 180 | { | 
|---|
| 181 | assert(instance); | 
|---|
| 182 |  | 
|---|
| 183 | /* init interrupt code */ | 
|---|
| 184 | irq_cmd_t *interrupt_commands = malloc(sizeof(uhci_cmds)); | 
|---|
| 185 | if (interrupt_commands == NULL) { | 
|---|
| 186 | return ENOMEM; | 
|---|
| 187 | } | 
|---|
| 188 | memcpy(interrupt_commands, uhci_cmds, sizeof(uhci_cmds)); | 
|---|
| 189 | interrupt_commands[0].addr = (void*)&instance->registers->usbsts; | 
|---|
| 190 | interrupt_commands[1].addr = (void*)&instance->registers->usbsts; | 
|---|
| 191 | instance->interrupt_code.cmds = interrupt_commands; | 
|---|
| 192 | instance->interrupt_code.cmdcount = | 
|---|
| 193 | sizeof(uhci_cmds) / sizeof(irq_cmd_t); | 
|---|
| 194 |  | 
|---|
| 195 | /* init transfer lists */ | 
|---|
| 196 | int ret = uhci_init_transfer_lists(instance); | 
|---|
| 197 | CHECK_RET_RETURN(ret, "Failed to initialize transfer lists.\n"); | 
|---|
| 198 | usb_log_debug("Initialized transfer lists.\n"); | 
|---|
| 199 |  | 
|---|
| 200 | /* frame list initialization */ | 
|---|
| 201 | instance->frame_list = get_page(); | 
|---|
| 202 | ret = instance ? EOK : ENOMEM; | 
|---|
| 203 | CHECK_RET_RETURN(ret, "Failed to get frame list page.\n"); | 
|---|
| 204 | usb_log_debug("Initialized frame list.\n"); | 
|---|
| 205 |  | 
|---|
| 206 | /* initialize all frames to point to the first queue head */ | 
|---|
| 207 | const uint32_t queue = | 
|---|
| 208 | instance->transfers_interrupt.queue_head_pa | 
|---|
| 209 | | LINK_POINTER_QUEUE_HEAD_FLAG; | 
|---|
| 210 | unsigned i = 0; | 
|---|
| 211 | for(; i < UHCI_FRAME_LIST_COUNT; ++i) { | 
|---|
| 212 | instance->frame_list[i] = queue; | 
|---|
| 213 | } | 
|---|
| 214 |  | 
|---|
| 215 | /* init address keeper(libusb) */ | 
|---|
| 216 | device_keeper_init(&instance->device_manager); | 
|---|
| 217 | usb_log_debug("Initialized device manager.\n"); | 
|---|
| 218 |  | 
|---|
| 219 | return EOK; | 
|---|
| 220 | } | 
|---|
| 221 | /*----------------------------------------------------------------------------*/ | 
|---|
| 222 | int uhci_init_transfer_lists(uhci_t *instance) | 
|---|
| 223 | { | 
|---|
| 224 | assert(instance); | 
|---|
| 225 |  | 
|---|
| 226 | /* initialize TODO: check errors */ | 
|---|
| 227 | int ret; | 
|---|
| 228 | ret = transfer_list_init(&instance->transfers_bulk_full, "BULK_FULL"); | 
|---|
| 229 | assert(ret == EOK); | 
|---|
| 230 | ret = transfer_list_init(&instance->transfers_control_full, "CONTROL_FULL"); | 
|---|
| 231 | assert(ret == EOK); | 
|---|
| 232 | ret = transfer_list_init(&instance->transfers_control_slow, "CONTROL_SLOW"); | 
|---|
| 233 | assert(ret == EOK); | 
|---|
| 234 | ret = transfer_list_init(&instance->transfers_interrupt, "INTERRUPT"); | 
|---|
| 235 | assert(ret == EOK); | 
|---|
| 236 |  | 
|---|
| 237 | transfer_list_set_next(&instance->transfers_control_full, | 
|---|
| 238 | &instance->transfers_bulk_full); | 
|---|
| 239 | transfer_list_set_next(&instance->transfers_control_slow, | 
|---|
| 240 | &instance->transfers_control_full); | 
|---|
| 241 | transfer_list_set_next(&instance->transfers_interrupt, | 
|---|
| 242 | &instance->transfers_control_slow); | 
|---|
| 243 |  | 
|---|
| 244 | /*FSBR*/ | 
|---|
| 245 | #ifdef FSBR | 
|---|
| 246 | transfer_list_set_next(&instance->transfers_bulk_full, | 
|---|
| 247 | &instance->transfers_control_full); | 
|---|
| 248 | #endif | 
|---|
| 249 |  | 
|---|
| 250 | instance->transfers[0][USB_TRANSFER_INTERRUPT] = | 
|---|
| 251 | &instance->transfers_interrupt; | 
|---|
| 252 | instance->transfers[1][USB_TRANSFER_INTERRUPT] = | 
|---|
| 253 | &instance->transfers_interrupt; | 
|---|
| 254 | instance->transfers[0][USB_TRANSFER_CONTROL] = | 
|---|
| 255 | &instance->transfers_control_full; | 
|---|
| 256 | instance->transfers[1][USB_TRANSFER_CONTROL] = | 
|---|
| 257 | &instance->transfers_control_slow; | 
|---|
| 258 | instance->transfers[0][USB_TRANSFER_BULK] = | 
|---|
| 259 | &instance->transfers_bulk_full; | 
|---|
| 260 |  | 
|---|
| 261 | return EOK; | 
|---|
| 262 | } | 
|---|
| 263 | /*----------------------------------------------------------------------------*/ | 
|---|
| 264 | int uhci_schedule(uhci_t *instance, batch_t *batch) | 
|---|
| 265 | { | 
|---|
| 266 | assert(instance); | 
|---|
| 267 | assert(batch); | 
|---|
| 268 | const int low_speed = (batch->speed == USB_SPEED_LOW); | 
|---|
| 269 | if (!allowed_usb_packet( | 
|---|
| 270 | low_speed, batch->transfer_type, batch->max_packet_size)) { | 
|---|
| 271 | usb_log_warning("Invalid USB packet specified %s SPEED %d %zu.\n", | 
|---|
| 272 | low_speed ? "LOW" : "FULL" , batch->transfer_type, | 
|---|
| 273 | batch->max_packet_size); | 
|---|
| 274 | return ENOTSUP; | 
|---|
| 275 | } | 
|---|
| 276 | /* TODO: check available bandwith here */ | 
|---|
| 277 |  | 
|---|
| 278 | transfer_list_t *list = | 
|---|
| 279 | instance->transfers[low_speed][batch->transfer_type]; | 
|---|
| 280 | assert(list); | 
|---|
| 281 | transfer_list_add_batch(list, batch); | 
|---|
| 282 |  | 
|---|
| 283 | return EOK; | 
|---|
| 284 | } | 
|---|
| 285 | /*----------------------------------------------------------------------------*/ | 
|---|
| 286 | void uhci_interrupt(uhci_t *instance, uint16_t status) | 
|---|
| 287 | { | 
|---|
| 288 | assert(instance); | 
|---|
| 289 | //      if ((status & (UHCI_STATUS_INTERRUPT | UHCI_STATUS_ERROR_INTERRUPT)) == 0) | 
|---|
| 290 | //              return; | 
|---|
| 291 | //      usb_log_debug2("UHCI interrupt: %X.\n", status); | 
|---|
| 292 | transfer_list_remove_finished(&instance->transfers_interrupt); | 
|---|
| 293 | transfer_list_remove_finished(&instance->transfers_control_slow); | 
|---|
| 294 | transfer_list_remove_finished(&instance->transfers_control_full); | 
|---|
| 295 | transfer_list_remove_finished(&instance->transfers_bulk_full); | 
|---|
| 296 | } | 
|---|
| 297 | /*----------------------------------------------------------------------------*/ | 
|---|
| 298 | int uhci_interrupt_emulator(void* arg) | 
|---|
| 299 | { | 
|---|
| 300 | usb_log_debug("Started interrupt emulator.\n"); | 
|---|
| 301 | uhci_t *instance = (uhci_t*)arg; | 
|---|
| 302 | assert(instance); | 
|---|
| 303 |  | 
|---|
| 304 | while (1) { | 
|---|
| 305 | uint16_t status = pio_read_16(&instance->registers->usbsts); | 
|---|
| 306 | if (status != 0) | 
|---|
| 307 | usb_log_debug2("UHCI status: %x.\n", status); | 
|---|
| 308 | status |= 1; | 
|---|
| 309 | uhci_interrupt(instance, status); | 
|---|
| 310 | pio_write_16(&instance->registers->usbsts, 0x1f); | 
|---|
| 311 | async_usleep(UHCI_CLEANER_TIMEOUT * 5); | 
|---|
| 312 | } | 
|---|
| 313 | return EOK; | 
|---|
| 314 | } | 
|---|
| 315 | /*---------------------------------------------------------------------------*/ | 
|---|
| 316 | int uhci_debug_checker(void *arg) | 
|---|
| 317 | { | 
|---|
| 318 | uhci_t *instance = (uhci_t*)arg; | 
|---|
| 319 | assert(instance); | 
|---|
| 320 | while (1) { | 
|---|
| 321 | const uint16_t cmd = pio_read_16(&instance->registers->usbcmd); | 
|---|
| 322 | const uint16_t sts = pio_read_16(&instance->registers->usbsts); | 
|---|
| 323 | const uint16_t intr = pio_read_16(&instance->registers->usbintr); | 
|---|
| 324 | if (((cmd & UHCI_CMD_RUN_STOP) != 1) || (sts != 0)) { | 
|---|
| 325 | usb_log_debug2("Command: %X Status: %X Intr: %x\n", | 
|---|
| 326 | cmd, sts, intr); | 
|---|
| 327 | } | 
|---|
| 328 |  | 
|---|
| 329 | uintptr_t frame_list = | 
|---|
| 330 | pio_read_32(&instance->registers->flbaseadd) & ~0xfff; | 
|---|
| 331 | if (frame_list != addr_to_phys(instance->frame_list)) { | 
|---|
| 332 | usb_log_debug("Framelist address: %p vs. %p.\n", | 
|---|
| 333 | frame_list, addr_to_phys(instance->frame_list)); | 
|---|
| 334 | } | 
|---|
| 335 | int frnum = pio_read_16(&instance->registers->frnum) & 0x3ff; | 
|---|
| 336 | usb_log_debug2("Framelist item: %d \n", frnum ); | 
|---|
| 337 |  | 
|---|
| 338 | queue_head_t* qh = instance->transfers_interrupt.queue_head; | 
|---|
| 339 |  | 
|---|
| 340 | if ((instance->frame_list[frnum] & (~0xf)) != (uintptr_t)addr_to_phys(qh)) { | 
|---|
| 341 | usb_log_debug("Interrupt QH: %p vs. %p.\n", | 
|---|
| 342 | instance->frame_list[frnum] & (~0xf), addr_to_phys(qh)); | 
|---|
| 343 | } | 
|---|
| 344 |  | 
|---|
| 345 | if ((qh->next_queue & (~0xf)) | 
|---|
| 346 | != (uintptr_t)addr_to_phys(instance->transfers_control_slow.queue_head)) { | 
|---|
| 347 | usb_log_debug("Control Slow QH: %p vs. %p.\n", qh->next_queue & (~0xf), | 
|---|
| 348 | addr_to_phys(instance->transfers_control_slow.queue_head)); | 
|---|
| 349 | } | 
|---|
| 350 | qh = instance->transfers_control_slow.queue_head; | 
|---|
| 351 |  | 
|---|
| 352 | if ((qh->next_queue & (~0xf)) | 
|---|
| 353 | != (uintptr_t)addr_to_phys(instance->transfers_control_full.queue_head)) { | 
|---|
| 354 | usb_log_debug("Control Full QH: %p vs. %p.\n", qh->next_queue & (~0xf), | 
|---|
| 355 | addr_to_phys(instance->transfers_control_full.queue_head));\ | 
|---|
| 356 | } | 
|---|
| 357 | qh = instance->transfers_control_full.queue_head; | 
|---|
| 358 |  | 
|---|
| 359 | if ((qh->next_queue & (~0xf)) | 
|---|
| 360 | != (uintptr_t)addr_to_phys(instance->transfers_bulk_full.queue_head)) { | 
|---|
| 361 | usb_log_debug("Bulk QH: %p vs. %p.\n", qh->next_queue & (~0xf), | 
|---|
| 362 | addr_to_phys(instance->transfers_bulk_full.queue_head)); | 
|---|
| 363 | } | 
|---|
| 364 | /* | 
|---|
| 365 | uint16_t cmd = pio_read_16(&instance->registers->usbcmd); | 
|---|
| 366 | cmd |= UHCI_CMD_RUN_STOP; | 
|---|
| 367 | pio_write_16(&instance->registers->usbcmd, cmd); | 
|---|
| 368 | */ | 
|---|
| 369 | async_usleep(UHCI_DEBUGER_TIMEOUT); | 
|---|
| 370 | } | 
|---|
| 371 | return 0; | 
|---|
| 372 | } | 
|---|
| 373 | /*----------------------------------------------------------------------------*/ | 
|---|
| 374 | bool allowed_usb_packet( | 
|---|
| 375 | bool low_speed, usb_transfer_type_t transfer, size_t size) | 
|---|
| 376 | { | 
|---|
| 377 | /* see USB specification chapter 5.5-5.8 for magic numbers used here */ | 
|---|
| 378 | switch(transfer) { | 
|---|
| 379 | case USB_TRANSFER_ISOCHRONOUS: | 
|---|
| 380 | return (!low_speed && size < 1024); | 
|---|
| 381 | case USB_TRANSFER_INTERRUPT: | 
|---|
| 382 | return size <= (low_speed ? 8 : 64); | 
|---|
| 383 | case USB_TRANSFER_CONTROL: /* device specifies its own max size */ | 
|---|
| 384 | return (size <= (low_speed ? 8 : 64)); | 
|---|
| 385 | case USB_TRANSFER_BULK: /* device specifies its own max size */ | 
|---|
| 386 | return (!low_speed && size <= 64); | 
|---|
| 387 | } | 
|---|
| 388 | return false; | 
|---|
| 389 | } | 
|---|
| 390 | /** | 
|---|
| 391 | * @} | 
|---|
| 392 | */ | 
|---|