diff options
Diffstat (limited to 'drivers/usb/host/uhci-q.c')
| -rw-r--r-- | drivers/usb/host/uhci-q.c | 947 |
1 files changed, 539 insertions, 408 deletions
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c index a06d84c19e13..c9d72ac0a1d7 100644 --- a/drivers/usb/host/uhci-q.c +++ b/drivers/usb/host/uhci-q.c | |||
| @@ -13,10 +13,9 @@ | |||
| 13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface | 13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface |
| 14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). | 14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). |
| 15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) | 15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) |
| 16 | * (C) Copyright 2004-2005 Alan Stern, stern@rowland.harvard.edu | 16 | * (C) Copyright 2004-2006 Alan Stern, stern@rowland.harvard.edu |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| 19 | static void uhci_free_pending_tds(struct uhci_hcd *uhci); | ||
| 20 | 19 | ||
| 21 | /* | 20 | /* |
| 22 | * Technically, updating td->status here is a race, but it's not really a | 21 | * Technically, updating td->status here is a race, but it's not really a |
| @@ -38,6 +37,60 @@ static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci) | |||
| 38 | uhci->term_td->status &= ~cpu_to_le32(TD_CTRL_IOC); | 37 | uhci->term_td->status &= ~cpu_to_le32(TD_CTRL_IOC); |
| 39 | } | 38 | } |
| 40 | 39 | ||
| 40 | |||
| 41 | /* | ||
| 42 | * Full-Speed Bandwidth Reclamation (FSBR). | ||
| 43 | * We turn on FSBR whenever a queue that wants it is advancing, | ||
| 44 | * and leave it on for a short time thereafter. | ||
| 45 | */ | ||
| 46 | static void uhci_fsbr_on(struct uhci_hcd *uhci) | ||
| 47 | { | ||
| 48 | uhci->fsbr_is_on = 1; | ||
| 49 | uhci->skel_term_qh->link = cpu_to_le32( | ||
| 50 | uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; | ||
| 51 | } | ||
| 52 | |||
| 53 | static void uhci_fsbr_off(struct uhci_hcd *uhci) | ||
| 54 | { | ||
| 55 | uhci->fsbr_is_on = 0; | ||
| 56 | uhci->skel_term_qh->link = UHCI_PTR_TERM; | ||
| 57 | } | ||
| 58 | |||
| 59 | static void uhci_add_fsbr(struct uhci_hcd *uhci, struct urb *urb) | ||
| 60 | { | ||
| 61 | struct urb_priv *urbp = urb->hcpriv; | ||
| 62 | |||
| 63 | if (!(urb->transfer_flags & URB_NO_FSBR)) | ||
| 64 | urbp->fsbr = 1; | ||
| 65 | } | ||
| 66 | |||
| 67 | static void uhci_urbp_wants_fsbr(struct uhci_hcd *uhci, struct urb_priv *urbp) | ||
| 68 | { | ||
| 69 | if (urbp->fsbr) { | ||
| 70 | uhci->fsbr_is_wanted = 1; | ||
| 71 | if (!uhci->fsbr_is_on) | ||
| 72 | uhci_fsbr_on(uhci); | ||
| 73 | else if (uhci->fsbr_expiring) { | ||
| 74 | uhci->fsbr_expiring = 0; | ||
| 75 | del_timer(&uhci->fsbr_timer); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | static void uhci_fsbr_timeout(unsigned long _uhci) | ||
| 81 | { | ||
| 82 | struct uhci_hcd *uhci = (struct uhci_hcd *) _uhci; | ||
| 83 | unsigned long flags; | ||
| 84 | |||
| 85 | spin_lock_irqsave(&uhci->lock, flags); | ||
| 86 | if (uhci->fsbr_expiring) { | ||
| 87 | uhci->fsbr_expiring = 0; | ||
| 88 | uhci_fsbr_off(uhci); | ||
| 89 | } | ||
| 90 | spin_unlock_irqrestore(&uhci->lock, flags); | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 41 | static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) | 94 | static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) |
| 42 | { | 95 | { |
| 43 | dma_addr_t dma_handle; | 96 | dma_addr_t dma_handle; |
| @@ -51,7 +104,6 @@ static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) | |||
| 51 | td->frame = -1; | 104 | td->frame = -1; |
| 52 | 105 | ||
| 53 | INIT_LIST_HEAD(&td->list); | 106 | INIT_LIST_HEAD(&td->list); |
| 54 | INIT_LIST_HEAD(&td->remove_list); | ||
| 55 | INIT_LIST_HEAD(&td->fl_list); | 107 | INIT_LIST_HEAD(&td->fl_list); |
| 56 | 108 | ||
| 57 | return td; | 109 | return td; |
| @@ -61,8 +113,6 @@ static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td) | |||
| 61 | { | 113 | { |
| 62 | if (!list_empty(&td->list)) | 114 | if (!list_empty(&td->list)) |
| 63 | dev_warn(uhci_dev(uhci), "td %p still in list!\n", td); | 115 | dev_warn(uhci_dev(uhci), "td %p still in list!\n", td); |
| 64 | if (!list_empty(&td->remove_list)) | ||
| 65 | dev_warn(uhci_dev(uhci), "td %p still in remove_list!\n", td); | ||
| 66 | if (!list_empty(&td->fl_list)) | 116 | if (!list_empty(&td->fl_list)) |
| 67 | dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); | 117 | dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); |
| 68 | 118 | ||
| @@ -77,6 +127,16 @@ static inline void uhci_fill_td(struct uhci_td *td, u32 status, | |||
| 77 | td->buffer = cpu_to_le32(buffer); | 127 | td->buffer = cpu_to_le32(buffer); |
| 78 | } | 128 | } |
| 79 | 129 | ||
| 130 | static void uhci_add_td_to_urbp(struct uhci_td *td, struct urb_priv *urbp) | ||
| 131 | { | ||
| 132 | list_add_tail(&td->list, &urbp->td_list); | ||
| 133 | } | ||
| 134 | |||
| 135 | static void uhci_remove_td_from_urbp(struct uhci_td *td) | ||
| 136 | { | ||
| 137 | list_del_init(&td->list); | ||
| 138 | } | ||
| 139 | |||
| 80 | /* | 140 | /* |
| 81 | * We insert Isochronous URBs directly into the frame list at the beginning | 141 | * We insert Isochronous URBs directly into the frame list at the beginning |
| 82 | */ | 142 | */ |
| @@ -138,6 +198,24 @@ static inline void uhci_remove_td_from_frame_list(struct uhci_hcd *uhci, | |||
| 138 | td->frame = -1; | 198 | td->frame = -1; |
| 139 | } | 199 | } |
| 140 | 200 | ||
| 201 | static inline void uhci_remove_tds_from_frame(struct uhci_hcd *uhci, | ||
| 202 | unsigned int framenum) | ||
| 203 | { | ||
| 204 | struct uhci_td *ftd, *ltd; | ||
| 205 | |||
| 206 | framenum &= (UHCI_NUMFRAMES - 1); | ||
| 207 | |||
| 208 | ftd = uhci->frame_cpu[framenum]; | ||
| 209 | if (ftd) { | ||
| 210 | ltd = list_entry(ftd->fl_list.prev, struct uhci_td, fl_list); | ||
| 211 | uhci->frame[framenum] = ltd->link; | ||
| 212 | uhci->frame_cpu[framenum] = NULL; | ||
| 213 | |||
| 214 | while (!list_empty(&ftd->fl_list)) | ||
| 215 | list_del_init(ftd->fl_list.prev); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 141 | /* | 219 | /* |
| 142 | * Remove all the TDs for an Isochronous URB from the frame list | 220 | * Remove all the TDs for an Isochronous URB from the frame list |
| 143 | */ | 221 | */ |
| @@ -148,7 +226,6 @@ static void uhci_unlink_isochronous_tds(struct uhci_hcd *uhci, struct urb *urb) | |||
| 148 | 226 | ||
| 149 | list_for_each_entry(td, &urbp->td_list, list) | 227 | list_for_each_entry(td, &urbp->td_list, list) |
| 150 | uhci_remove_td_from_frame_list(uhci, td); | 228 | uhci_remove_td_from_frame_list(uhci, td); |
| 151 | wmb(); | ||
| 152 | } | 229 | } |
| 153 | 230 | ||
| 154 | static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, | 231 | static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, |
| @@ -161,6 +238,7 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, | |||
| 161 | if (!qh) | 238 | if (!qh) |
| 162 | return NULL; | 239 | return NULL; |
| 163 | 240 | ||
| 241 | memset(qh, 0, sizeof(*qh)); | ||
| 164 | qh->dma_handle = dma_handle; | 242 | qh->dma_handle = dma_handle; |
| 165 | 243 | ||
| 166 | qh->element = UHCI_PTR_TERM; | 244 | qh->element = UHCI_PTR_TERM; |
| @@ -179,10 +257,11 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, | |||
| 179 | qh->hep = hep; | 257 | qh->hep = hep; |
| 180 | qh->udev = udev; | 258 | qh->udev = udev; |
| 181 | hep->hcpriv = qh; | 259 | hep->hcpriv = qh; |
| 260 | qh->type = hep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | ||
| 182 | 261 | ||
| 183 | } else { /* Skeleton QH */ | 262 | } else { /* Skeleton QH */ |
| 184 | qh->state = QH_STATE_ACTIVE; | 263 | qh->state = QH_STATE_ACTIVE; |
| 185 | qh->udev = NULL; | 264 | qh->type = -1; |
| 186 | } | 265 | } |
| 187 | return qh; | 266 | return qh; |
| 188 | } | 267 | } |
| @@ -202,35 +281,64 @@ static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
| 202 | } | 281 | } |
| 203 | 282 | ||
| 204 | /* | 283 | /* |
| 205 | * When the currently executing URB is dequeued, save its current toggle value | 284 | * When a queue is stopped and a dequeued URB is given back, adjust |
| 285 | * the previous TD link (if the URB isn't first on the queue) or | ||
| 286 | * save its toggle value (if it is first and is currently executing). | ||
| 287 | * | ||
| 288 | * Returns 0 if the URB should not yet be given back, 1 otherwise. | ||
| 206 | */ | 289 | */ |
| 207 | static void uhci_save_toggle(struct uhci_qh *qh, struct urb *urb) | 290 | static int uhci_cleanup_queue(struct uhci_hcd *uhci, struct uhci_qh *qh, |
| 291 | struct urb *urb) | ||
| 208 | { | 292 | { |
| 209 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; | 293 | struct urb_priv *urbp = urb->hcpriv; |
| 210 | struct uhci_td *td; | 294 | struct uhci_td *td; |
| 295 | int ret = 1; | ||
| 296 | |||
| 297 | /* Isochronous pipes don't use toggles and their TD link pointers | ||
| 298 | * get adjusted during uhci_urb_dequeue(). But since their queues | ||
| 299 | * cannot truly be stopped, we have to watch out for dequeues | ||
| 300 | * occurring after the nominal unlink frame. */ | ||
| 301 | if (qh->type == USB_ENDPOINT_XFER_ISOC) { | ||
| 302 | ret = (uhci->frame_number + uhci->is_stopped != | ||
| 303 | qh->unlink_frame); | ||
| 304 | goto done; | ||
| 305 | } | ||
| 306 | |||
| 307 | /* If the URB isn't first on its queue, adjust the link pointer | ||
| 308 | * of the last TD in the previous URB. The toggle doesn't need | ||
| 309 | * to be saved since this URB can't be executing yet. */ | ||
| 310 | if (qh->queue.next != &urbp->node) { | ||
| 311 | struct urb_priv *purbp; | ||
| 312 | struct uhci_td *ptd; | ||
| 313 | |||
| 314 | purbp = list_entry(urbp->node.prev, struct urb_priv, node); | ||
| 315 | WARN_ON(list_empty(&purbp->td_list)); | ||
| 316 | ptd = list_entry(purbp->td_list.prev, struct uhci_td, | ||
| 317 | list); | ||
| 318 | td = list_entry(urbp->td_list.prev, struct uhci_td, | ||
| 319 | list); | ||
| 320 | ptd->link = td->link; | ||
| 321 | goto done; | ||
| 322 | } | ||
| 211 | 323 | ||
| 212 | /* If the QH element pointer is UHCI_PTR_TERM then then currently | 324 | /* If the QH element pointer is UHCI_PTR_TERM then then currently |
| 213 | * executing URB has already been unlinked, so this one isn't it. */ | 325 | * executing URB has already been unlinked, so this one isn't it. */ |
| 214 | if (qh_element(qh) == UHCI_PTR_TERM || | 326 | if (qh_element(qh) == UHCI_PTR_TERM) |
| 215 | qh->queue.next != &urbp->node) | 327 | goto done; |
| 216 | return; | ||
| 217 | qh->element = UHCI_PTR_TERM; | 328 | qh->element = UHCI_PTR_TERM; |
| 218 | 329 | ||
| 219 | /* Only bulk and interrupt pipes have to worry about toggles */ | 330 | /* Control pipes have to worry about toggles */ |
| 220 | if (!(usb_pipetype(urb->pipe) == PIPE_BULK || | 331 | if (qh->type == USB_ENDPOINT_XFER_CONTROL) |
| 221 | usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) | 332 | goto done; |
| 222 | return; | ||
| 223 | 333 | ||
| 224 | /* Find the first active TD; that's the device's toggle state */ | 334 | /* Save the next toggle value */ |
| 225 | list_for_each_entry(td, &urbp->td_list, list) { | 335 | WARN_ON(list_empty(&urbp->td_list)); |
| 226 | if (td_status(td) & TD_CTRL_ACTIVE) { | 336 | td = list_entry(urbp->td_list.next, struct uhci_td, list); |
| 227 | qh->needs_fixup = 1; | 337 | qh->needs_fixup = 1; |
| 228 | qh->initial_toggle = uhci_toggle(td_token(td)); | 338 | qh->initial_toggle = uhci_toggle(td_token(td)); |
| 229 | return; | ||
| 230 | } | ||
| 231 | } | ||
| 232 | 339 | ||
| 233 | WARN_ON(1); | 340 | done: |
| 341 | return ret; | ||
| 234 | } | 342 | } |
| 235 | 343 | ||
| 236 | /* | 344 | /* |
| @@ -305,6 +413,10 @@ static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
| 305 | qh->element = cpu_to_le32(td->dma_handle); | 413 | qh->element = cpu_to_le32(td->dma_handle); |
| 306 | } | 414 | } |
| 307 | 415 | ||
| 416 | /* Treat the queue as if it has just advanced */ | ||
| 417 | qh->wait_expired = 0; | ||
| 418 | qh->advance_jiffies = jiffies; | ||
| 419 | |||
| 308 | if (qh->state == QH_STATE_ACTIVE) | 420 | if (qh->state == QH_STATE_ACTIVE) |
| 309 | return; | 421 | return; |
| 310 | qh->state = QH_STATE_ACTIVE; | 422 | qh->state = QH_STATE_ACTIVE; |
| @@ -370,6 +482,12 @@ static void uhci_make_qh_idle(struct uhci_hcd *uhci, struct uhci_qh *qh) | |||
| 370 | list_move(&qh->node, &uhci->idle_qh_list); | 482 | list_move(&qh->node, &uhci->idle_qh_list); |
| 371 | qh->state = QH_STATE_IDLE; | 483 | qh->state = QH_STATE_IDLE; |
| 372 | 484 | ||
| 485 | /* Now that the QH is idle, its post_td isn't being used */ | ||
| 486 | if (qh->post_td) { | ||
| 487 | uhci_free_td(uhci, qh->post_td); | ||
| 488 | qh->post_td = NULL; | ||
| 489 | } | ||
| 490 | |||
| 373 | /* If anyone is waiting for a QH to become idle, wake them up */ | 491 | /* If anyone is waiting for a QH to become idle, wake them up */ |
| 374 | if (uhci->num_waiting) | 492 | if (uhci->num_waiting) |
| 375 | wake_up_all(&uhci->waitqh); | 493 | wake_up_all(&uhci->waitqh); |
| @@ -395,21 +513,6 @@ static inline struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci, | |||
| 395 | return urbp; | 513 | return urbp; |
| 396 | } | 514 | } |
| 397 | 515 | ||
| 398 | static void uhci_add_td_to_urb(struct urb *urb, struct uhci_td *td) | ||
| 399 | { | ||
| 400 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | ||
| 401 | |||
| 402 | list_add_tail(&td->list, &urbp->td_list); | ||
| 403 | } | ||
| 404 | |||
| 405 | static void uhci_remove_td_from_urb(struct uhci_td *td) | ||
| 406 | { | ||
| 407 | if (list_empty(&td->list)) | ||
| 408 | return; | ||
| 409 | |||
| 410 | list_del_init(&td->list); | ||
| 411 | } | ||
| 412 | |||
| 413 | static void uhci_free_urb_priv(struct uhci_hcd *uhci, | 516 | static void uhci_free_urb_priv(struct uhci_hcd *uhci, |
| 414 | struct urb_priv *urbp) | 517 | struct urb_priv *urbp) |
| 415 | { | 518 | { |
| @@ -419,48 +522,15 @@ static void uhci_free_urb_priv(struct uhci_hcd *uhci, | |||
| 419 | dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n", | 522 | dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n", |
| 420 | urbp->urb); | 523 | urbp->urb); |
| 421 | 524 | ||
| 422 | uhci_get_current_frame_number(uhci); | ||
| 423 | if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) { | ||
| 424 | uhci_free_pending_tds(uhci); | ||
| 425 | uhci->td_remove_age = uhci->frame_number; | ||
| 426 | } | ||
| 427 | |||
| 428 | /* Check to see if the remove list is empty. Set the IOC bit */ | ||
| 429 | /* to force an interrupt so we can remove the TDs. */ | ||
| 430 | if (list_empty(&uhci->td_remove_list)) | ||
| 431 | uhci_set_next_interrupt(uhci); | ||
| 432 | |||
| 433 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { | 525 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { |
| 434 | uhci_remove_td_from_urb(td); | 526 | uhci_remove_td_from_urbp(td); |
| 435 | list_add(&td->remove_list, &uhci->td_remove_list); | 527 | uhci_free_td(uhci, td); |
| 436 | } | 528 | } |
| 437 | 529 | ||
| 438 | urbp->urb->hcpriv = NULL; | 530 | urbp->urb->hcpriv = NULL; |
| 439 | kmem_cache_free(uhci_up_cachep, urbp); | 531 | kmem_cache_free(uhci_up_cachep, urbp); |
| 440 | } | 532 | } |
| 441 | 533 | ||
| 442 | static void uhci_inc_fsbr(struct uhci_hcd *uhci, struct urb *urb) | ||
| 443 | { | ||
| 444 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | ||
| 445 | |||
| 446 | if ((!(urb->transfer_flags & URB_NO_FSBR)) && !urbp->fsbr) { | ||
| 447 | urbp->fsbr = 1; | ||
| 448 | if (!uhci->fsbr++ && !uhci->fsbrtimeout) | ||
| 449 | uhci->skel_term_qh->link = cpu_to_le32(uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; | ||
| 450 | } | ||
| 451 | } | ||
| 452 | |||
| 453 | static void uhci_dec_fsbr(struct uhci_hcd *uhci, struct urb *urb) | ||
| 454 | { | ||
| 455 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | ||
| 456 | |||
| 457 | if ((!(urb->transfer_flags & URB_NO_FSBR)) && urbp->fsbr) { | ||
| 458 | urbp->fsbr = 0; | ||
| 459 | if (!--uhci->fsbr) | ||
| 460 | uhci->fsbrtimeout = jiffies + FSBR_DELAY; | ||
| 461 | } | ||
| 462 | } | ||
| 463 | |||
| 464 | /* | 534 | /* |
| 465 | * Map status to standard result codes | 535 | * Map status to standard result codes |
| 466 | * | 536 | * |
| @@ -487,7 +557,6 @@ static int uhci_map_status(int status, int dir_out) | |||
| 487 | return -ENOSR; | 557 | return -ENOSR; |
| 488 | if (status & TD_CTRL_STALLED) /* Stalled */ | 558 | if (status & TD_CTRL_STALLED) /* Stalled */ |
| 489 | return -EPIPE; | 559 | return -EPIPE; |
| 490 | WARN_ON(status & TD_CTRL_ACTIVE); /* Active */ | ||
| 491 | return 0; | 560 | return 0; |
| 492 | } | 561 | } |
| 493 | 562 | ||
| @@ -503,6 +572,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
| 503 | int len = urb->transfer_buffer_length; | 572 | int len = urb->transfer_buffer_length; |
| 504 | dma_addr_t data = urb->transfer_dma; | 573 | dma_addr_t data = urb->transfer_dma; |
| 505 | __le32 *plink; | 574 | __le32 *plink; |
| 575 | struct urb_priv *urbp = urb->hcpriv; | ||
| 506 | 576 | ||
| 507 | /* The "pipe" thing contains the destination in bits 8--18 */ | 577 | /* The "pipe" thing contains the destination in bits 8--18 */ |
| 508 | destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; | 578 | destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; |
| @@ -516,7 +586,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
| 516 | * Build the TD for the control request setup packet | 586 | * Build the TD for the control request setup packet |
| 517 | */ | 587 | */ |
| 518 | td = qh->dummy_td; | 588 | td = qh->dummy_td; |
| 519 | uhci_add_td_to_urb(urb, td); | 589 | uhci_add_td_to_urbp(td, urbp); |
| 520 | uhci_fill_td(td, status, destination | uhci_explen(8), | 590 | uhci_fill_td(td, status, destination | uhci_explen(8), |
| 521 | urb->setup_dma); | 591 | urb->setup_dma); |
| 522 | plink = &td->link; | 592 | plink = &td->link; |
| @@ -548,7 +618,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
| 548 | /* Alternate Data0/1 (start with Data1) */ | 618 | /* Alternate Data0/1 (start with Data1) */ |
| 549 | destination ^= TD_TOKEN_TOGGLE; | 619 | destination ^= TD_TOKEN_TOGGLE; |
| 550 | 620 | ||
| 551 | uhci_add_td_to_urb(urb, td); | 621 | uhci_add_td_to_urbp(td, urbp); |
| 552 | uhci_fill_td(td, status, destination | uhci_explen(pktsze), | 622 | uhci_fill_td(td, status, destination | uhci_explen(pktsze), |
| 553 | data); | 623 | data); |
| 554 | plink = &td->link; | 624 | plink = &td->link; |
| @@ -579,7 +649,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
| 579 | 649 | ||
| 580 | status &= ~TD_CTRL_SPD; | 650 | status &= ~TD_CTRL_SPD; |
| 581 | 651 | ||
| 582 | uhci_add_td_to_urb(urb, td); | 652 | uhci_add_td_to_urbp(td, urbp); |
| 583 | uhci_fill_td(td, status | TD_CTRL_IOC, | 653 | uhci_fill_td(td, status | TD_CTRL_IOC, |
| 584 | destination | uhci_explen(0), 0); | 654 | destination | uhci_explen(0), 0); |
| 585 | plink = &td->link; | 655 | plink = &td->link; |
| @@ -606,145 +676,19 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
| 606 | qh->skel = uhci->skel_ls_control_qh; | 676 | qh->skel = uhci->skel_ls_control_qh; |
| 607 | else { | 677 | else { |
| 608 | qh->skel = uhci->skel_fs_control_qh; | 678 | qh->skel = uhci->skel_fs_control_qh; |
| 609 | uhci_inc_fsbr(uhci, urb); | 679 | uhci_add_fsbr(uhci, urb); |
| 610 | } | 680 | } |
| 681 | |||
| 682 | urb->actual_length = -8; /* Account for the SETUP packet */ | ||
| 611 | return 0; | 683 | return 0; |
| 612 | 684 | ||
| 613 | nomem: | 685 | nomem: |
| 614 | /* Remove the dummy TD from the td_list so it doesn't get freed */ | 686 | /* Remove the dummy TD from the td_list so it doesn't get freed */ |
| 615 | uhci_remove_td_from_urb(qh->dummy_td); | 687 | uhci_remove_td_from_urbp(qh->dummy_td); |
| 616 | return -ENOMEM; | 688 | return -ENOMEM; |
| 617 | } | 689 | } |
| 618 | 690 | ||
| 619 | /* | 691 | /* |
| 620 | * If control-IN transfer was short, the status packet wasn't sent. | ||
| 621 | * This routine changes the element pointer in the QH to point at the | ||
| 622 | * status TD. It's safe to do this even while the QH is live, because | ||
| 623 | * the hardware only updates the element pointer following a successful | ||
| 624 | * transfer. The inactive TD for the short packet won't cause an update, | ||
| 625 | * so the pointer won't get overwritten. The next time the controller | ||
| 626 | * sees this QH, it will send the status packet. | ||
| 627 | */ | ||
| 628 | static int usb_control_retrigger_status(struct uhci_hcd *uhci, struct urb *urb) | ||
| 629 | { | ||
| 630 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | ||
| 631 | struct uhci_td *td; | ||
| 632 | |||
| 633 | urbp->short_transfer = 1; | ||
| 634 | |||
| 635 | td = list_entry(urbp->td_list.prev, struct uhci_td, list); | ||
| 636 | urbp->qh->element = cpu_to_le32(td->dma_handle); | ||
| 637 | |||
| 638 | return -EINPROGRESS; | ||
| 639 | } | ||
| 640 | |||
| 641 | |||
| 642 | static int uhci_result_control(struct uhci_hcd *uhci, struct urb *urb) | ||
| 643 | { | ||
| 644 | struct list_head *tmp, *head; | ||
| 645 | struct urb_priv *urbp = urb->hcpriv; | ||
| 646 | struct uhci_td *td; | ||
| 647 | unsigned int status; | ||
| 648 | int ret = 0; | ||
| 649 | |||
| 650 | head = &urbp->td_list; | ||
| 651 | if (urbp->short_transfer) { | ||
| 652 | tmp = head->prev; | ||
| 653 | goto status_stage; | ||
| 654 | } | ||
| 655 | |||
| 656 | urb->actual_length = 0; | ||
| 657 | |||
| 658 | tmp = head->next; | ||
| 659 | td = list_entry(tmp, struct uhci_td, list); | ||
| 660 | |||
| 661 | /* The first TD is the SETUP stage, check the status, but skip */ | ||
| 662 | /* the count */ | ||
| 663 | status = uhci_status_bits(td_status(td)); | ||
| 664 | if (status & TD_CTRL_ACTIVE) | ||
| 665 | return -EINPROGRESS; | ||
| 666 | |||
| 667 | if (status) | ||
| 668 | goto td_error; | ||
| 669 | |||
| 670 | /* The rest of the TDs (but the last) are data */ | ||
| 671 | tmp = tmp->next; | ||
| 672 | while (tmp != head && tmp->next != head) { | ||
| 673 | unsigned int ctrlstat; | ||
| 674 | |||
| 675 | td = list_entry(tmp, struct uhci_td, list); | ||
| 676 | tmp = tmp->next; | ||
| 677 | |||
| 678 | ctrlstat = td_status(td); | ||
| 679 | status = uhci_status_bits(ctrlstat); | ||
| 680 | if (status & TD_CTRL_ACTIVE) | ||
| 681 | return -EINPROGRESS; | ||
| 682 | |||
| 683 | urb->actual_length += uhci_actual_length(ctrlstat); | ||
| 684 | |||
| 685 | if (status) | ||
| 686 | goto td_error; | ||
| 687 | |||
| 688 | /* Check to see if we received a short packet */ | ||
| 689 | if (uhci_actual_length(ctrlstat) < | ||
| 690 | uhci_expected_length(td_token(td))) { | ||
| 691 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | ||
| 692 | ret = -EREMOTEIO; | ||
| 693 | goto err; | ||
| 694 | } | ||
| 695 | |||
| 696 | return usb_control_retrigger_status(uhci, urb); | ||
| 697 | } | ||
| 698 | } | ||
| 699 | |||
| 700 | status_stage: | ||
| 701 | td = list_entry(tmp, struct uhci_td, list); | ||
| 702 | |||
| 703 | /* Control status stage */ | ||
| 704 | status = td_status(td); | ||
| 705 | |||
| 706 | #ifdef I_HAVE_BUGGY_APC_BACKUPS | ||
| 707 | /* APC BackUPS Pro kludge */ | ||
| 708 | /* It tries to send all of the descriptor instead of the amount */ | ||
| 709 | /* we requested */ | ||
| 710 | if (status & TD_CTRL_IOC && /* IOC is masked out by uhci_status_bits */ | ||
| 711 | status & TD_CTRL_ACTIVE && | ||
| 712 | status & TD_CTRL_NAK) | ||
| 713 | return 0; | ||
| 714 | #endif | ||
| 715 | |||
| 716 | status = uhci_status_bits(status); | ||
| 717 | if (status & TD_CTRL_ACTIVE) | ||
| 718 | return -EINPROGRESS; | ||
| 719 | |||
| 720 | if (status) | ||
| 721 | goto td_error; | ||
| 722 | |||
| 723 | return 0; | ||
| 724 | |||
| 725 | td_error: | ||
| 726 | ret = uhci_map_status(status, uhci_packetout(td_token(td))); | ||
| 727 | |||
| 728 | err: | ||
| 729 | if ((debug == 1 && ret != -EPIPE) || debug > 1) { | ||
| 730 | /* Some debugging code */ | ||
| 731 | dev_dbg(uhci_dev(uhci), "%s: failed with status %x\n", | ||
| 732 | __FUNCTION__, status); | ||
| 733 | |||
| 734 | if (errbuf) { | ||
| 735 | /* Print the chain for debugging purposes */ | ||
| 736 | uhci_show_qh(urbp->qh, errbuf, ERRBUF_LEN, 0); | ||
| 737 | lprintk(errbuf); | ||
| 738 | } | ||
| 739 | } | ||
| 740 | |||
| 741 | /* Note that the queue has stopped */ | ||
| 742 | urbp->qh->element = UHCI_PTR_TERM; | ||
| 743 | urbp->qh->is_stopped = 1; | ||
| 744 | return ret; | ||
| 745 | } | ||
| 746 | |||
| 747 | /* | ||
| 748 | * Common submit for bulk and interrupt | 692 | * Common submit for bulk and interrupt |
| 749 | */ | 693 | */ |
| 750 | static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | 694 | static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, |
| @@ -756,6 +700,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
| 756 | int len = urb->transfer_buffer_length; | 700 | int len = urb->transfer_buffer_length; |
| 757 | dma_addr_t data = urb->transfer_dma; | 701 | dma_addr_t data = urb->transfer_dma; |
| 758 | __le32 *plink; | 702 | __le32 *plink; |
| 703 | struct urb_priv *urbp = urb->hcpriv; | ||
| 759 | unsigned int toggle; | 704 | unsigned int toggle; |
| 760 | 705 | ||
| 761 | if (len < 0) | 706 | if (len < 0) |
| @@ -793,7 +738,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
| 793 | goto nomem; | 738 | goto nomem; |
| 794 | *plink = cpu_to_le32(td->dma_handle); | 739 | *plink = cpu_to_le32(td->dma_handle); |
| 795 | } | 740 | } |
| 796 | uhci_add_td_to_urb(urb, td); | 741 | uhci_add_td_to_urbp(td, urbp); |
| 797 | uhci_fill_td(td, status, | 742 | uhci_fill_td(td, status, |
| 798 | destination | uhci_explen(pktsze) | | 743 | destination | uhci_explen(pktsze) | |
| 799 | (toggle << TD_TOKEN_TOGGLE_SHIFT), | 744 | (toggle << TD_TOKEN_TOGGLE_SHIFT), |
| @@ -821,7 +766,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
| 821 | goto nomem; | 766 | goto nomem; |
| 822 | *plink = cpu_to_le32(td->dma_handle); | 767 | *plink = cpu_to_le32(td->dma_handle); |
| 823 | 768 | ||
| 824 | uhci_add_td_to_urb(urb, td); | 769 | uhci_add_td_to_urbp(td, urbp); |
| 825 | uhci_fill_td(td, status, | 770 | uhci_fill_td(td, status, |
| 826 | destination | uhci_explen(0) | | 771 | destination | uhci_explen(0) | |
| 827 | (toggle << TD_TOKEN_TOGGLE_SHIFT), | 772 | (toggle << TD_TOKEN_TOGGLE_SHIFT), |
| @@ -851,6 +796,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
| 851 | wmb(); | 796 | wmb(); |
| 852 | qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE); | 797 | qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE); |
| 853 | qh->dummy_td = td; | 798 | qh->dummy_td = td; |
| 799 | qh->period = urb->interval; | ||
| 854 | 800 | ||
| 855 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), | 801 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), |
| 856 | usb_pipeout(urb->pipe), toggle); | 802 | usb_pipeout(urb->pipe), toggle); |
| @@ -858,90 +804,10 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
| 858 | 804 | ||
| 859 | nomem: | 805 | nomem: |
| 860 | /* Remove the dummy TD from the td_list so it doesn't get freed */ | 806 | /* Remove the dummy TD from the td_list so it doesn't get freed */ |
| 861 | uhci_remove_td_from_urb(qh->dummy_td); | 807 | uhci_remove_td_from_urbp(qh->dummy_td); |
| 862 | return -ENOMEM; | 808 | return -ENOMEM; |
| 863 | } | 809 | } |
| 864 | 810 | ||
| 865 | /* | ||
| 866 | * Common result for bulk and interrupt | ||
| 867 | */ | ||
| 868 | static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb) | ||
| 869 | { | ||
| 870 | struct urb_priv *urbp = urb->hcpriv; | ||
| 871 | struct uhci_td *td; | ||
| 872 | unsigned int status = 0; | ||
| 873 | int ret = 0; | ||
| 874 | |||
| 875 | urb->actual_length = 0; | ||
| 876 | |||
| 877 | list_for_each_entry(td, &urbp->td_list, list) { | ||
| 878 | unsigned int ctrlstat = td_status(td); | ||
| 879 | |||
| 880 | status = uhci_status_bits(ctrlstat); | ||
| 881 | if (status & TD_CTRL_ACTIVE) | ||
| 882 | return -EINPROGRESS; | ||
| 883 | |||
| 884 | urb->actual_length += uhci_actual_length(ctrlstat); | ||
| 885 | |||
| 886 | if (status) | ||
| 887 | goto td_error; | ||
| 888 | |||
| 889 | if (uhci_actual_length(ctrlstat) < | ||
| 890 | uhci_expected_length(td_token(td))) { | ||
| 891 | if (urb->transfer_flags & URB_SHORT_NOT_OK) { | ||
| 892 | ret = -EREMOTEIO; | ||
| 893 | goto err; | ||
| 894 | } | ||
| 895 | |||
| 896 | /* | ||
| 897 | * This URB stopped short of its end. We have to | ||
| 898 | * fix up the toggles of the following URBs on the | ||
| 899 | * queue and restart the queue. | ||
| 900 | * | ||
| 901 | * Do this only the first time we encounter the | ||
| 902 | * short URB. | ||
| 903 | */ | ||
| 904 | if (!urbp->short_transfer) { | ||
| 905 | urbp->short_transfer = 1; | ||
| 906 | urbp->qh->initial_toggle = | ||
| 907 | uhci_toggle(td_token(td)) ^ 1; | ||
| 908 | uhci_fixup_toggles(urbp->qh, 1); | ||
| 909 | |||
| 910 | td = list_entry(urbp->td_list.prev, | ||
| 911 | struct uhci_td, list); | ||
| 912 | urbp->qh->element = td->link; | ||
| 913 | } | ||
| 914 | break; | ||
| 915 | } | ||
| 916 | } | ||
| 917 | |||
| 918 | return 0; | ||
| 919 | |||
| 920 | td_error: | ||
| 921 | ret = uhci_map_status(status, uhci_packetout(td_token(td))); | ||
| 922 | |||
| 923 | if ((debug == 1 && ret != -EPIPE) || debug > 1) { | ||
| 924 | /* Some debugging code */ | ||
| 925 | dev_dbg(uhci_dev(uhci), "%s: failed with status %x\n", | ||
| 926 | __FUNCTION__, status); | ||
| 927 | |||
| 928 | if (debug > 1 && errbuf) { | ||
| 929 | /* Print the chain for debugging purposes */ | ||
| 930 | uhci_show_qh(urbp->qh, errbuf, ERRBUF_LEN, 0); | ||
| 931 | lprintk(errbuf); | ||
| 932 | } | ||
| 933 | } | ||
| 934 | err: | ||
| 935 | |||
| 936 | /* Note that the queue has stopped and save the next toggle value */ | ||
| 937 | urbp->qh->element = UHCI_PTR_TERM; | ||
| 938 | urbp->qh->is_stopped = 1; | ||
| 939 | urbp->qh->needs_fixup = 1; | ||
| 940 | urbp->qh->initial_toggle = uhci_toggle(td_token(td)) ^ | ||
| 941 | (ret == -EREMOTEIO); | ||
| 942 | return ret; | ||
| 943 | } | ||
| 944 | |||
| 945 | static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, | 811 | static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, |
| 946 | struct uhci_qh *qh) | 812 | struct uhci_qh *qh) |
| 947 | { | 813 | { |
| @@ -954,22 +820,163 @@ static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, | |||
| 954 | qh->skel = uhci->skel_bulk_qh; | 820 | qh->skel = uhci->skel_bulk_qh; |
| 955 | ret = uhci_submit_common(uhci, urb, qh); | 821 | ret = uhci_submit_common(uhci, urb, qh); |
| 956 | if (ret == 0) | 822 | if (ret == 0) |
| 957 | uhci_inc_fsbr(uhci, urb); | 823 | uhci_add_fsbr(uhci, urb); |
| 958 | return ret; | 824 | return ret; |
| 959 | } | 825 | } |
| 960 | 826 | ||
| 961 | static inline int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb, | 827 | static int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb, |
| 962 | struct uhci_qh *qh) | 828 | struct uhci_qh *qh) |
| 963 | { | 829 | { |
| 830 | int exponent; | ||
| 831 | |||
| 964 | /* USB 1.1 interrupt transfers only involve one packet per interval. | 832 | /* USB 1.1 interrupt transfers only involve one packet per interval. |
| 965 | * Drivers can submit URBs of any length, but longer ones will need | 833 | * Drivers can submit URBs of any length, but longer ones will need |
| 966 | * multiple intervals to complete. | 834 | * multiple intervals to complete. |
| 967 | */ | 835 | */ |
| 968 | qh->skel = uhci->skelqh[__interval_to_skel(urb->interval)]; | 836 | |
| 837 | /* Figure out which power-of-two queue to use */ | ||
| 838 | for (exponent = 7; exponent >= 0; --exponent) { | ||
| 839 | if ((1 << exponent) <= urb->interval) | ||
| 840 | break; | ||
| 841 | } | ||
| 842 | if (exponent < 0) | ||
| 843 | return -EINVAL; | ||
| 844 | urb->interval = 1 << exponent; | ||
| 845 | |||
| 846 | if (qh->period == 0) | ||
| 847 | qh->skel = uhci->skelqh[UHCI_SKEL_INDEX(exponent)]; | ||
| 848 | else if (qh->period != urb->interval) | ||
| 849 | return -EINVAL; /* Can't change the period */ | ||
| 850 | |||
| 969 | return uhci_submit_common(uhci, urb, qh); | 851 | return uhci_submit_common(uhci, urb, qh); |
| 970 | } | 852 | } |
| 971 | 853 | ||
| 972 | /* | 854 | /* |
| 855 | * Fix up the data structures following a short transfer | ||
| 856 | */ | ||
| 857 | static int uhci_fixup_short_transfer(struct uhci_hcd *uhci, | ||
| 858 | struct uhci_qh *qh, struct urb_priv *urbp) | ||
| 859 | { | ||
| 860 | struct uhci_td *td; | ||
| 861 | struct list_head *tmp; | ||
| 862 | int ret; | ||
| 863 | |||
| 864 | td = list_entry(urbp->td_list.prev, struct uhci_td, list); | ||
| 865 | if (qh->type == USB_ENDPOINT_XFER_CONTROL) { | ||
| 866 | |||
| 867 | /* When a control transfer is short, we have to restart | ||
| 868 | * the queue at the status stage transaction, which is | ||
| 869 | * the last TD. */ | ||
| 870 | WARN_ON(list_empty(&urbp->td_list)); | ||
| 871 | qh->element = cpu_to_le32(td->dma_handle); | ||
| 872 | tmp = td->list.prev; | ||
| 873 | ret = -EINPROGRESS; | ||
| 874 | |||
| 875 | } else { | ||
| 876 | |||
| 877 | /* When a bulk/interrupt transfer is short, we have to | ||
| 878 | * fix up the toggles of the following URBs on the queue | ||
| 879 | * before restarting the queue at the next URB. */ | ||
| 880 | qh->initial_toggle = uhci_toggle(td_token(qh->post_td)) ^ 1; | ||
| 881 | uhci_fixup_toggles(qh, 1); | ||
| 882 | |||
| 883 | if (list_empty(&urbp->td_list)) | ||
| 884 | td = qh->post_td; | ||
| 885 | qh->element = td->link; | ||
| 886 | tmp = urbp->td_list.prev; | ||
| 887 | ret = 0; | ||
| 888 | } | ||
| 889 | |||
| 890 | /* Remove all the TDs we skipped over, from tmp back to the start */ | ||
| 891 | while (tmp != &urbp->td_list) { | ||
| 892 | td = list_entry(tmp, struct uhci_td, list); | ||
| 893 | tmp = tmp->prev; | ||
| 894 | |||
| 895 | uhci_remove_td_from_urbp(td); | ||
| 896 | uhci_free_td(uhci, td); | ||
| 897 | } | ||
| 898 | return ret; | ||
| 899 | } | ||
| 900 | |||
| 901 | /* | ||
| 902 | * Common result for control, bulk, and interrupt | ||
| 903 | */ | ||
| 904 | static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb) | ||
| 905 | { | ||
| 906 | struct urb_priv *urbp = urb->hcpriv; | ||
| 907 | struct uhci_qh *qh = urbp->qh; | ||
| 908 | struct uhci_td *td, *tmp; | ||
| 909 | unsigned status; | ||
| 910 | int ret = 0; | ||
| 911 | |||
| 912 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { | ||
| 913 | unsigned int ctrlstat; | ||
| 914 | int len; | ||
| 915 | |||
| 916 | ctrlstat = td_status(td); | ||
| 917 | status = uhci_status_bits(ctrlstat); | ||
| 918 | if (status & TD_CTRL_ACTIVE) | ||
| 919 | return -EINPROGRESS; | ||
| 920 | |||
| 921 | len = uhci_actual_length(ctrlstat); | ||
| 922 | urb->actual_length += len; | ||
| 923 | |||
| 924 | if (status) { | ||
| 925 | ret = uhci_map_status(status, | ||
| 926 | uhci_packetout(td_token(td))); | ||
| 927 | if ((debug == 1 && ret != -EPIPE) || debug > 1) { | ||
| 928 | /* Some debugging code */ | ||
| 929 | dev_dbg(&urb->dev->dev, | ||
| 930 | "%s: failed with status %x\n", | ||
| 931 | __FUNCTION__, status); | ||
| 932 | |||
| 933 | if (debug > 1 && errbuf) { | ||
| 934 | /* Print the chain for debugging */ | ||
| 935 | uhci_show_qh(urbp->qh, errbuf, | ||
| 936 | ERRBUF_LEN, 0); | ||
| 937 | lprintk(errbuf); | ||
| 938 | } | ||
| 939 | } | ||
| 940 | |||
| 941 | } else if (len < uhci_expected_length(td_token(td))) { | ||
| 942 | |||
| 943 | /* We received a short packet */ | ||
| 944 | if (urb->transfer_flags & URB_SHORT_NOT_OK) | ||
| 945 | ret = -EREMOTEIO; | ||
| 946 | else if (ctrlstat & TD_CTRL_SPD) | ||
| 947 | ret = 1; | ||
| 948 | } | ||
| 949 | |||
| 950 | uhci_remove_td_from_urbp(td); | ||
| 951 | if (qh->post_td) | ||
| 952 | uhci_free_td(uhci, qh->post_td); | ||
| 953 | qh->post_td = td; | ||
| 954 | |||
| 955 | if (ret != 0) | ||
| 956 | goto err; | ||
| 957 | } | ||
| 958 | return ret; | ||
| 959 | |||
| 960 | err: | ||
| 961 | if (ret < 0) { | ||
| 962 | /* In case a control transfer gets an error | ||
| 963 | * during the setup stage */ | ||
| 964 | urb->actual_length = max(urb->actual_length, 0); | ||
| 965 | |||
| 966 | /* Note that the queue has stopped and save | ||
| 967 | * the next toggle value */ | ||
| 968 | qh->element = UHCI_PTR_TERM; | ||
| 969 | qh->is_stopped = 1; | ||
| 970 | qh->needs_fixup = (qh->type != USB_ENDPOINT_XFER_CONTROL); | ||
| 971 | qh->initial_toggle = uhci_toggle(td_token(td)) ^ | ||
| 972 | (ret == -EREMOTEIO); | ||
| 973 | |||
| 974 | } else /* Short packet received */ | ||
| 975 | ret = uhci_fixup_short_transfer(uhci, qh, urbp); | ||
| 976 | return ret; | ||
| 977 | } | ||
| 978 | |||
| 979 | /* | ||
| 973 | * Isochronous transfers | 980 | * Isochronous transfers |
| 974 | */ | 981 | */ |
| 975 | static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | 982 | static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, |
| @@ -980,38 +987,57 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | |||
| 980 | unsigned long destination, status; | 987 | unsigned long destination, status; |
| 981 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; | 988 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; |
| 982 | 989 | ||
| 983 | if (urb->number_of_packets > 900) /* 900? Why? */ | 990 | /* Values must not be too big (could overflow below) */ |
| 991 | if (urb->interval >= UHCI_NUMFRAMES || | ||
| 992 | urb->number_of_packets >= UHCI_NUMFRAMES) | ||
| 984 | return -EFBIG; | 993 | return -EFBIG; |
| 985 | 994 | ||
| 986 | status = TD_CTRL_ACTIVE | TD_CTRL_IOS; | 995 | /* Check the period and figure out the starting frame number */ |
| 987 | destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe); | 996 | if (qh->period == 0) { |
| 988 | 997 | if (urb->transfer_flags & URB_ISO_ASAP) { | |
| 989 | /* Figure out the starting frame number */ | ||
| 990 | if (urb->transfer_flags & URB_ISO_ASAP) { | ||
| 991 | if (list_empty(&qh->queue)) { | ||
| 992 | uhci_get_current_frame_number(uhci); | 998 | uhci_get_current_frame_number(uhci); |
| 993 | urb->start_frame = (uhci->frame_number + 10); | 999 | urb->start_frame = uhci->frame_number + 10; |
| 1000 | } else { | ||
| 1001 | i = urb->start_frame - uhci->last_iso_frame; | ||
| 1002 | if (i <= 0 || i >= UHCI_NUMFRAMES) | ||
| 1003 | return -EINVAL; | ||
| 1004 | } | ||
| 1005 | } else if (qh->period != urb->interval) { | ||
| 1006 | return -EINVAL; /* Can't change the period */ | ||
| 994 | 1007 | ||
| 995 | } else { /* Go right after the last one */ | 1008 | } else { /* Pick up where the last URB leaves off */ |
| 996 | struct urb *last_urb; | 1009 | if (list_empty(&qh->queue)) { |
| 1010 | frame = qh->iso_frame; | ||
| 1011 | } else { | ||
| 1012 | struct urb *lurb; | ||
| 997 | 1013 | ||
| 998 | last_urb = list_entry(qh->queue.prev, | 1014 | lurb = list_entry(qh->queue.prev, |
| 999 | struct urb_priv, node)->urb; | 1015 | struct urb_priv, node)->urb; |
| 1000 | urb->start_frame = (last_urb->start_frame + | 1016 | frame = lurb->start_frame + |
| 1001 | last_urb->number_of_packets * | 1017 | lurb->number_of_packets * |
| 1002 | last_urb->interval); | 1018 | lurb->interval; |
| 1003 | } | 1019 | } |
| 1004 | } else { | 1020 | if (urb->transfer_flags & URB_ISO_ASAP) |
| 1005 | /* FIXME: Sanity check */ | 1021 | urb->start_frame = frame; |
| 1022 | else if (urb->start_frame != frame) | ||
| 1023 | return -EINVAL; | ||
| 1006 | } | 1024 | } |
| 1007 | urb->start_frame &= (UHCI_NUMFRAMES - 1); | 1025 | |
| 1026 | /* Make sure we won't have to go too far into the future */ | ||
| 1027 | if (uhci_frame_before_eq(uhci->last_iso_frame + UHCI_NUMFRAMES, | ||
| 1028 | urb->start_frame + urb->number_of_packets * | ||
| 1029 | urb->interval)) | ||
| 1030 | return -EFBIG; | ||
| 1031 | |||
| 1032 | status = TD_CTRL_ACTIVE | TD_CTRL_IOS; | ||
| 1033 | destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe); | ||
| 1008 | 1034 | ||
| 1009 | for (i = 0; i < urb->number_of_packets; i++) { | 1035 | for (i = 0; i < urb->number_of_packets; i++) { |
| 1010 | td = uhci_alloc_td(uhci); | 1036 | td = uhci_alloc_td(uhci); |
| 1011 | if (!td) | 1037 | if (!td) |
| 1012 | return -ENOMEM; | 1038 | return -ENOMEM; |
| 1013 | 1039 | ||
| 1014 | uhci_add_td_to_urb(urb, td); | 1040 | uhci_add_td_to_urbp(td, urbp); |
| 1015 | uhci_fill_td(td, status, destination | | 1041 | uhci_fill_td(td, status, destination | |
| 1016 | uhci_explen(urb->iso_frame_desc[i].length), | 1042 | uhci_explen(urb->iso_frame_desc[i].length), |
| 1017 | urb->transfer_dma + | 1043 | urb->transfer_dma + |
| @@ -1022,12 +1048,19 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | |||
| 1022 | td->status |= __constant_cpu_to_le32(TD_CTRL_IOC); | 1048 | td->status |= __constant_cpu_to_le32(TD_CTRL_IOC); |
| 1023 | 1049 | ||
| 1024 | qh->skel = uhci->skel_iso_qh; | 1050 | qh->skel = uhci->skel_iso_qh; |
| 1051 | qh->period = urb->interval; | ||
| 1025 | 1052 | ||
| 1026 | /* Add the TDs to the frame list */ | 1053 | /* Add the TDs to the frame list */ |
| 1027 | frame = urb->start_frame; | 1054 | frame = urb->start_frame; |
| 1028 | list_for_each_entry(td, &urbp->td_list, list) { | 1055 | list_for_each_entry(td, &urbp->td_list, list) { |
| 1029 | uhci_insert_td_in_frame_list(uhci, td, frame); | 1056 | uhci_insert_td_in_frame_list(uhci, td, frame); |
| 1030 | frame += urb->interval; | 1057 | frame += qh->period; |
| 1058 | } | ||
| 1059 | |||
| 1060 | if (list_empty(&qh->queue)) { | ||
| 1061 | qh->iso_packet_desc = &urb->iso_frame_desc[0]; | ||
| 1062 | qh->iso_frame = urb->start_frame; | ||
| 1063 | qh->iso_status = 0; | ||
| 1031 | } | 1064 | } |
| 1032 | 1065 | ||
| 1033 | return 0; | 1066 | return 0; |
| @@ -1035,37 +1068,44 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, | |||
| 1035 | 1068 | ||
| 1036 | static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb) | 1069 | static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb) |
| 1037 | { | 1070 | { |
| 1038 | struct uhci_td *td; | 1071 | struct uhci_td *td, *tmp; |
| 1039 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; | 1072 | struct urb_priv *urbp = urb->hcpriv; |
| 1040 | int status; | 1073 | struct uhci_qh *qh = urbp->qh; |
| 1041 | int i, ret = 0; | ||
| 1042 | |||
| 1043 | urb->actual_length = urb->error_count = 0; | ||
| 1044 | 1074 | ||
| 1045 | i = 0; | 1075 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { |
| 1046 | list_for_each_entry(td, &urbp->td_list, list) { | 1076 | unsigned int ctrlstat; |
| 1077 | int status; | ||
| 1047 | int actlength; | 1078 | int actlength; |
| 1048 | unsigned int ctrlstat = td_status(td); | ||
| 1049 | 1079 | ||
| 1050 | if (ctrlstat & TD_CTRL_ACTIVE) | 1080 | if (uhci_frame_before_eq(uhci->cur_iso_frame, qh->iso_frame)) |
| 1051 | return -EINPROGRESS; | 1081 | return -EINPROGRESS; |
| 1052 | 1082 | ||
| 1053 | actlength = uhci_actual_length(ctrlstat); | 1083 | uhci_remove_tds_from_frame(uhci, qh->iso_frame); |
| 1054 | urb->iso_frame_desc[i].actual_length = actlength; | 1084 | |
| 1055 | urb->actual_length += actlength; | 1085 | ctrlstat = td_status(td); |
| 1086 | if (ctrlstat & TD_CTRL_ACTIVE) { | ||
| 1087 | status = -EXDEV; /* TD was added too late? */ | ||
| 1088 | } else { | ||
| 1089 | status = uhci_map_status(uhci_status_bits(ctrlstat), | ||
| 1090 | usb_pipeout(urb->pipe)); | ||
| 1091 | actlength = uhci_actual_length(ctrlstat); | ||
| 1092 | |||
| 1093 | urb->actual_length += actlength; | ||
| 1094 | qh->iso_packet_desc->actual_length = actlength; | ||
| 1095 | qh->iso_packet_desc->status = status; | ||
| 1096 | } | ||
| 1056 | 1097 | ||
| 1057 | status = uhci_map_status(uhci_status_bits(ctrlstat), | ||
| 1058 | usb_pipeout(urb->pipe)); | ||
| 1059 | urb->iso_frame_desc[i].status = status; | ||
| 1060 | if (status) { | 1098 | if (status) { |
| 1061 | urb->error_count++; | 1099 | urb->error_count++; |
| 1062 | ret = status; | 1100 | qh->iso_status = status; |
| 1063 | } | 1101 | } |
| 1064 | 1102 | ||
| 1065 | i++; | 1103 | uhci_remove_td_from_urbp(td); |
| 1104 | uhci_free_td(uhci, td); | ||
| 1105 | qh->iso_frame += qh->period; | ||
| 1106 | ++qh->iso_packet_desc; | ||
| 1066 | } | 1107 | } |
| 1067 | 1108 | return qh->iso_status; | |
| 1068 | return ret; | ||
| 1069 | } | 1109 | } |
| 1070 | 1110 | ||
| 1071 | static int uhci_urb_enqueue(struct usb_hcd *hcd, | 1111 | static int uhci_urb_enqueue(struct usb_hcd *hcd, |
| @@ -1099,14 +1139,14 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd, | |||
| 1099 | } | 1139 | } |
| 1100 | urbp->qh = qh; | 1140 | urbp->qh = qh; |
| 1101 | 1141 | ||
| 1102 | switch (usb_pipetype(urb->pipe)) { | 1142 | switch (qh->type) { |
| 1103 | case PIPE_CONTROL: | 1143 | case USB_ENDPOINT_XFER_CONTROL: |
| 1104 | ret = uhci_submit_control(uhci, urb, qh); | 1144 | ret = uhci_submit_control(uhci, urb, qh); |
| 1105 | break; | 1145 | break; |
| 1106 | case PIPE_BULK: | 1146 | case USB_ENDPOINT_XFER_BULK: |
| 1107 | ret = uhci_submit_bulk(uhci, urb, qh); | 1147 | ret = uhci_submit_bulk(uhci, urb, qh); |
| 1108 | break; | 1148 | break; |
| 1109 | case PIPE_INTERRUPT: | 1149 | case USB_ENDPOINT_XFER_INT: |
| 1110 | if (list_empty(&qh->queue)) { | 1150 | if (list_empty(&qh->queue)) { |
| 1111 | bustime = usb_check_bandwidth(urb->dev, urb); | 1151 | bustime = usb_check_bandwidth(urb->dev, urb); |
| 1112 | if (bustime < 0) | 1152 | if (bustime < 0) |
| @@ -1125,7 +1165,8 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd, | |||
| 1125 | ret = uhci_submit_interrupt(uhci, urb, qh); | 1165 | ret = uhci_submit_interrupt(uhci, urb, qh); |
| 1126 | } | 1166 | } |
| 1127 | break; | 1167 | break; |
| 1128 | case PIPE_ISOCHRONOUS: | 1168 | case USB_ENDPOINT_XFER_ISOC: |
| 1169 | urb->error_count = 0; | ||
| 1129 | bustime = usb_check_bandwidth(urb->dev, urb); | 1170 | bustime = usb_check_bandwidth(urb->dev, urb); |
| 1130 | if (bustime < 0) { | 1171 | if (bustime < 0) { |
| 1131 | ret = bustime; | 1172 | ret = bustime; |
| @@ -1146,9 +1187,12 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd, | |||
| 1146 | 1187 | ||
| 1147 | /* If the new URB is the first and only one on this QH then either | 1188 | /* If the new URB is the first and only one on this QH then either |
| 1148 | * the QH is new and idle or else it's unlinked and waiting to | 1189 | * the QH is new and idle or else it's unlinked and waiting to |
| 1149 | * become idle, so we can activate it right away. */ | 1190 | * become idle, so we can activate it right away. But only if the |
| 1150 | if (qh->queue.next == &urbp->node) | 1191 | * queue isn't stopped. */ |
| 1192 | if (qh->queue.next == &urbp->node && !qh->is_stopped) { | ||
| 1151 | uhci_activate_qh(uhci, qh); | 1193 | uhci_activate_qh(uhci, qh); |
| 1194 | uhci_urbp_wants_fsbr(uhci, urbp); | ||
| 1195 | } | ||
| 1152 | goto done; | 1196 | goto done; |
| 1153 | 1197 | ||
| 1154 | err_submit_failed: | 1198 | err_submit_failed: |
| @@ -1168,16 +1212,26 @@ static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) | |||
| 1168 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); | 1212 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
| 1169 | unsigned long flags; | 1213 | unsigned long flags; |
| 1170 | struct urb_priv *urbp; | 1214 | struct urb_priv *urbp; |
| 1215 | struct uhci_qh *qh; | ||
| 1171 | 1216 | ||
| 1172 | spin_lock_irqsave(&uhci->lock, flags); | 1217 | spin_lock_irqsave(&uhci->lock, flags); |
| 1173 | urbp = urb->hcpriv; | 1218 | urbp = urb->hcpriv; |
| 1174 | if (!urbp) /* URB was never linked! */ | 1219 | if (!urbp) /* URB was never linked! */ |
| 1175 | goto done; | 1220 | goto done; |
| 1221 | qh = urbp->qh; | ||
| 1176 | 1222 | ||
| 1177 | /* Remove Isochronous TDs from the frame list ASAP */ | 1223 | /* Remove Isochronous TDs from the frame list ASAP */ |
| 1178 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) | 1224 | if (qh->type == USB_ENDPOINT_XFER_ISOC) { |
| 1179 | uhci_unlink_isochronous_tds(uhci, urb); | 1225 | uhci_unlink_isochronous_tds(uhci, urb); |
| 1180 | uhci_unlink_qh(uhci, urbp->qh); | 1226 | mb(); |
| 1227 | |||
| 1228 | /* If the URB has already started, update the QH unlink time */ | ||
| 1229 | uhci_get_current_frame_number(uhci); | ||
| 1230 | if (uhci_frame_before_eq(urb->start_frame, uhci->frame_number)) | ||
| 1231 | qh->unlink_frame = uhci->frame_number; | ||
| 1232 | } | ||
| 1233 | |||
| 1234 | uhci_unlink_qh(uhci, qh); | ||
| 1181 | 1235 | ||
| 1182 | done: | 1236 | done: |
| 1183 | spin_unlock_irqrestore(&uhci->lock, flags); | 1237 | spin_unlock_irqrestore(&uhci->lock, flags); |
| @@ -1194,22 +1248,17 @@ __acquires(uhci->lock) | |||
| 1194 | { | 1248 | { |
| 1195 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; | 1249 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; |
| 1196 | 1250 | ||
| 1197 | /* Isochronous TDs get unlinked directly from the frame list */ | 1251 | /* When giving back the first URB in an Isochronous queue, |
| 1198 | if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) | 1252 | * reinitialize the QH's iso-related members for the next URB. */ |
| 1199 | uhci_unlink_isochronous_tds(uhci, urb); | 1253 | if (qh->type == USB_ENDPOINT_XFER_ISOC && |
| 1200 | 1254 | urbp->node.prev == &qh->queue && | |
| 1201 | /* If the URB isn't first on its queue, adjust the link pointer | 1255 | urbp->node.next != &qh->queue) { |
| 1202 | * of the last TD in the previous URB. */ | 1256 | struct urb *nurb = list_entry(urbp->node.next, |
| 1203 | else if (qh->queue.next != &urbp->node) { | 1257 | struct urb_priv, node)->urb; |
| 1204 | struct urb_priv *purbp; | 1258 | |
| 1205 | struct uhci_td *ptd, *ltd; | 1259 | qh->iso_packet_desc = &nurb->iso_frame_desc[0]; |
| 1206 | 1260 | qh->iso_frame = nurb->start_frame; | |
| 1207 | purbp = list_entry(urbp->node.prev, struct urb_priv, node); | 1261 | qh->iso_status = 0; |
| 1208 | ptd = list_entry(purbp->td_list.prev, struct uhci_td, | ||
| 1209 | list); | ||
| 1210 | ltd = list_entry(urbp->td_list.prev, struct uhci_td, | ||
| 1211 | list); | ||
| 1212 | ptd->link = ltd->link; | ||
| 1213 | } | 1262 | } |
| 1214 | 1263 | ||
| 1215 | /* Take the URB off the QH's queue. If the queue is now empty, | 1264 | /* Take the URB off the QH's queue. If the queue is now empty, |
| @@ -1221,16 +1270,15 @@ __acquires(uhci->lock) | |||
| 1221 | qh->needs_fixup = 0; | 1270 | qh->needs_fixup = 0; |
| 1222 | } | 1271 | } |
| 1223 | 1272 | ||
| 1224 | uhci_dec_fsbr(uhci, urb); /* Safe since it checks */ | ||
| 1225 | uhci_free_urb_priv(uhci, urbp); | 1273 | uhci_free_urb_priv(uhci, urbp); |
| 1226 | 1274 | ||
| 1227 | switch (usb_pipetype(urb->pipe)) { | 1275 | switch (qh->type) { |
| 1228 | case PIPE_ISOCHRONOUS: | 1276 | case USB_ENDPOINT_XFER_ISOC: |
| 1229 | /* Release bandwidth for Interrupt or Isoc. transfers */ | 1277 | /* Release bandwidth for Interrupt or Isoc. transfers */ |
| 1230 | if (urb->bandwidth) | 1278 | if (urb->bandwidth) |
| 1231 | usb_release_bandwidth(urb->dev, urb, 1); | 1279 | usb_release_bandwidth(urb->dev, urb, 1); |
| 1232 | break; | 1280 | break; |
| 1233 | case PIPE_INTERRUPT: | 1281 | case USB_ENDPOINT_XFER_INT: |
| 1234 | /* Release bandwidth for Interrupt or Isoc. transfers */ | 1282 | /* Release bandwidth for Interrupt or Isoc. transfers */ |
| 1235 | /* Make sure we don't release if we have a queued URB */ | 1283 | /* Make sure we don't release if we have a queued URB */ |
| 1236 | if (list_empty(&qh->queue) && urb->bandwidth) | 1284 | if (list_empty(&qh->queue) && urb->bandwidth) |
| @@ -1252,6 +1300,7 @@ __acquires(uhci->lock) | |||
| 1252 | uhci_unlink_qh(uhci, qh); | 1300 | uhci_unlink_qh(uhci, qh); |
| 1253 | 1301 | ||
| 1254 | /* Bandwidth stuff not yet implemented */ | 1302 | /* Bandwidth stuff not yet implemented */ |
| 1303 | qh->period = 0; | ||
| 1255 | } | 1304 | } |
| 1256 | } | 1305 | } |
| 1257 | 1306 | ||
| @@ -1273,17 +1322,10 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, | |||
| 1273 | urbp = list_entry(qh->queue.next, struct urb_priv, node); | 1322 | urbp = list_entry(qh->queue.next, struct urb_priv, node); |
| 1274 | urb = urbp->urb; | 1323 | urb = urbp->urb; |
| 1275 | 1324 | ||
| 1276 | switch (usb_pipetype(urb->pipe)) { | 1325 | if (qh->type == USB_ENDPOINT_XFER_ISOC) |
| 1277 | case PIPE_CONTROL: | ||
| 1278 | status = uhci_result_control(uhci, urb); | ||
| 1279 | break; | ||
| 1280 | case PIPE_ISOCHRONOUS: | ||
| 1281 | status = uhci_result_isochronous(uhci, urb); | 1326 | status = uhci_result_isochronous(uhci, urb); |
| 1282 | break; | 1327 | else |
| 1283 | default: /* PIPE_BULK or PIPE_INTERRUPT */ | ||
| 1284 | status = uhci_result_common(uhci, urb); | 1328 | status = uhci_result_common(uhci, urb); |
| 1285 | break; | ||
| 1286 | } | ||
| 1287 | if (status == -EINPROGRESS) | 1329 | if (status == -EINPROGRESS) |
| 1288 | break; | 1330 | break; |
| 1289 | 1331 | ||
| @@ -1291,31 +1333,43 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, | |||
| 1291 | if (urb->status == -EINPROGRESS) /* Not dequeued */ | 1333 | if (urb->status == -EINPROGRESS) /* Not dequeued */ |
| 1292 | urb->status = status; | 1334 | urb->status = status; |
| 1293 | else | 1335 | else |
| 1294 | status = -ECONNRESET; | 1336 | status = ECONNRESET; /* Not -ECONNRESET */ |
| 1295 | spin_unlock(&urb->lock); | 1337 | spin_unlock(&urb->lock); |
| 1296 | 1338 | ||
| 1297 | /* Dequeued but completed URBs can't be given back unless | 1339 | /* Dequeued but completed URBs can't be given back unless |
| 1298 | * the QH is stopped or has finished unlinking. */ | 1340 | * the QH is stopped or has finished unlinking. */ |
| 1299 | if (status == -ECONNRESET && | 1341 | if (status == ECONNRESET) { |
| 1300 | !(qh->is_stopped || QH_FINISHED_UNLINKING(qh))) | 1342 | if (QH_FINISHED_UNLINKING(qh)) |
| 1301 | return; | 1343 | qh->is_stopped = 1; |
| 1344 | else if (!qh->is_stopped) | ||
| 1345 | return; | ||
| 1346 | } | ||
| 1302 | 1347 | ||
| 1303 | uhci_giveback_urb(uhci, qh, urb, regs); | 1348 | uhci_giveback_urb(uhci, qh, urb, regs); |
| 1304 | if (qh->is_stopped) | 1349 | if (status < 0) |
| 1305 | break; | 1350 | break; |
| 1306 | } | 1351 | } |
| 1307 | 1352 | ||
| 1308 | /* If the QH is neither stopped nor finished unlinking (normal case), | 1353 | /* If the QH is neither stopped nor finished unlinking (normal case), |
| 1309 | * our work here is done. */ | 1354 | * our work here is done. */ |
| 1310 | restart: | 1355 | if (QH_FINISHED_UNLINKING(qh)) |
| 1311 | if (!(qh->is_stopped || QH_FINISHED_UNLINKING(qh))) | 1356 | qh->is_stopped = 1; |
| 1357 | else if (!qh->is_stopped) | ||
| 1312 | return; | 1358 | return; |
| 1313 | 1359 | ||
| 1314 | /* Otherwise give back each of the dequeued URBs */ | 1360 | /* Otherwise give back each of the dequeued URBs */ |
| 1361 | restart: | ||
| 1315 | list_for_each_entry(urbp, &qh->queue, node) { | 1362 | list_for_each_entry(urbp, &qh->queue, node) { |
| 1316 | urb = urbp->urb; | 1363 | urb = urbp->urb; |
| 1317 | if (urb->status != -EINPROGRESS) { | 1364 | if (urb->status != -EINPROGRESS) { |
| 1318 | uhci_save_toggle(qh, urb); | 1365 | |
| 1366 | /* Fix up the TD links and save the toggles for | ||
| 1367 | * non-Isochronous queues. For Isochronous queues, | ||
| 1368 | * test for too-recent dequeues. */ | ||
| 1369 | if (!uhci_cleanup_queue(uhci, qh, urb)) { | ||
| 1370 | qh->is_stopped = 0; | ||
| 1371 | return; | ||
| 1372 | } | ||
| 1319 | uhci_giveback_urb(uhci, qh, urb, regs); | 1373 | uhci_giveback_urb(uhci, qh, urb, regs); |
| 1320 | goto restart; | 1374 | goto restart; |
| 1321 | } | 1375 | } |
| @@ -1327,6 +1381,18 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, | |||
| 1327 | if (!list_empty(&qh->queue)) { | 1381 | if (!list_empty(&qh->queue)) { |
| 1328 | if (qh->needs_fixup) | 1382 | if (qh->needs_fixup) |
| 1329 | uhci_fixup_toggles(qh, 0); | 1383 | uhci_fixup_toggles(qh, 0); |
| 1384 | |||
| 1385 | /* If the first URB on the queue wants FSBR but its time | ||
| 1386 | * limit has expired, set the next TD to interrupt on | ||
| 1387 | * completion before reactivating the QH. */ | ||
| 1388 | urbp = list_entry(qh->queue.next, struct urb_priv, node); | ||
| 1389 | if (urbp->fsbr && qh->wait_expired) { | ||
| 1390 | struct uhci_td *td = list_entry(urbp->td_list.next, | ||
| 1391 | struct uhci_td, list); | ||
| 1392 | |||
| 1393 | td->status |= __cpu_to_le32(TD_CTRL_IOC); | ||
| 1394 | } | ||
| 1395 | |||
| 1330 | uhci_activate_qh(uhci, qh); | 1396 | uhci_activate_qh(uhci, qh); |
| 1331 | } | 1397 | } |
| 1332 | 1398 | ||
| @@ -1336,15 +1402,84 @@ static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, | |||
| 1336 | uhci_make_qh_idle(uhci, qh); | 1402 | uhci_make_qh_idle(uhci, qh); |
| 1337 | } | 1403 | } |
| 1338 | 1404 | ||
| 1339 | static void uhci_free_pending_tds(struct uhci_hcd *uhci) | 1405 | /* |
| 1406 | * Check for queues that have made some forward progress. | ||
| 1407 | * Returns 0 if the queue is not Isochronous, is ACTIVE, and | ||
| 1408 | * has not advanced since last examined; 1 otherwise. | ||
| 1409 | * | ||
| 1410 | * Early Intel controllers have a bug which causes qh->element sometimes | ||
| 1411 | * not to advance when a TD completes successfully. The queue remains | ||
| 1412 | * stuck on the inactive completed TD. We detect such cases and advance | ||
| 1413 | * the element pointer by hand. | ||
| 1414 | */ | ||
| 1415 | static int uhci_advance_check(struct uhci_hcd *uhci, struct uhci_qh *qh) | ||
| 1340 | { | 1416 | { |
| 1341 | struct uhci_td *td, *tmp; | 1417 | struct urb_priv *urbp = NULL; |
| 1418 | struct uhci_td *td; | ||
| 1419 | int ret = 1; | ||
| 1420 | unsigned status; | ||
| 1342 | 1421 | ||
| 1343 | list_for_each_entry_safe(td, tmp, &uhci->td_remove_list, remove_list) { | 1422 | if (qh->type == USB_ENDPOINT_XFER_ISOC) |
| 1344 | list_del_init(&td->remove_list); | 1423 | goto done; |
| 1345 | 1424 | ||
| 1346 | uhci_free_td(uhci, td); | 1425 | /* Treat an UNLINKING queue as though it hasn't advanced. |
| 1426 | * This is okay because reactivation will treat it as though | ||
| 1427 | * it has advanced, and if it is going to become IDLE then | ||
| 1428 | * this doesn't matter anyway. Furthermore it's possible | ||
| 1429 | * for an UNLINKING queue not to have any URBs at all, or | ||
| 1430 | * for its first URB not to have any TDs (if it was dequeued | ||
| 1431 | * just as it completed). So it's not easy in any case to | ||
| 1432 | * test whether such queues have advanced. */ | ||
| 1433 | if (qh->state != QH_STATE_ACTIVE) { | ||
| 1434 | urbp = NULL; | ||
| 1435 | status = 0; | ||
| 1436 | |||
| 1437 | } else { | ||
| 1438 | urbp = list_entry(qh->queue.next, struct urb_priv, node); | ||
| 1439 | td = list_entry(urbp->td_list.next, struct uhci_td, list); | ||
| 1440 | status = td_status(td); | ||
| 1441 | if (!(status & TD_CTRL_ACTIVE)) { | ||
| 1442 | |||
| 1443 | /* We're okay, the queue has advanced */ | ||
| 1444 | qh->wait_expired = 0; | ||
| 1445 | qh->advance_jiffies = jiffies; | ||
| 1446 | goto done; | ||
| 1447 | } | ||
| 1448 | ret = 0; | ||
| 1449 | } | ||
| 1450 | |||
| 1451 | /* The queue hasn't advanced; check for timeout */ | ||
| 1452 | if (qh->wait_expired) | ||
| 1453 | goto done; | ||
| 1454 | |||
| 1455 | if (time_after(jiffies, qh->advance_jiffies + QH_WAIT_TIMEOUT)) { | ||
| 1456 | |||
| 1457 | /* Detect the Intel bug and work around it */ | ||
| 1458 | if (qh->post_td && qh_element(qh) == | ||
| 1459 | cpu_to_le32(qh->post_td->dma_handle)) { | ||
| 1460 | qh->element = qh->post_td->link; | ||
| 1461 | qh->advance_jiffies = jiffies; | ||
| 1462 | ret = 1; | ||
| 1463 | goto done; | ||
| 1464 | } | ||
| 1465 | |||
| 1466 | qh->wait_expired = 1; | ||
| 1467 | |||
| 1468 | /* If the current URB wants FSBR, unlink it temporarily | ||
| 1469 | * so that we can safely set the next TD to interrupt on | ||
| 1470 | * completion. That way we'll know as soon as the queue | ||
| 1471 | * starts moving again. */ | ||
| 1472 | if (urbp && urbp->fsbr && !(status & TD_CTRL_IOC)) | ||
| 1473 | uhci_unlink_qh(uhci, qh); | ||
| 1474 | |||
| 1475 | } else { | ||
| 1476 | /* Unmoving but not-yet-expired queues keep FSBR alive */ | ||
| 1477 | if (urbp) | ||
| 1478 | uhci_urbp_wants_fsbr(uhci, urbp); | ||
| 1347 | } | 1479 | } |
| 1480 | |||
| 1481 | done: | ||
| 1482 | return ret; | ||
| 1348 | } | 1483 | } |
| 1349 | 1484 | ||
| 1350 | /* | 1485 | /* |
| @@ -1361,14 +1496,13 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs) | |||
| 1361 | return; | 1496 | return; |
| 1362 | } | 1497 | } |
| 1363 | uhci->scan_in_progress = 1; | 1498 | uhci->scan_in_progress = 1; |
| 1364 | rescan: | 1499 | rescan: |
| 1365 | uhci->need_rescan = 0; | 1500 | uhci->need_rescan = 0; |
| 1501 | uhci->fsbr_is_wanted = 0; | ||
| 1366 | 1502 | ||
| 1367 | uhci_clear_next_interrupt(uhci); | 1503 | uhci_clear_next_interrupt(uhci); |
| 1368 | uhci_get_current_frame_number(uhci); | 1504 | uhci_get_current_frame_number(uhci); |
| 1369 | 1505 | uhci->cur_iso_frame = uhci->frame_number; | |
| 1370 | if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) | ||
| 1371 | uhci_free_pending_tds(uhci); | ||
| 1372 | 1506 | ||
| 1373 | /* Go through all the QH queues and process the URBs in each one */ | 1507 | /* Go through all the QH queues and process the URBs in each one */ |
| 1374 | for (i = 0; i < UHCI_NUM_SKELQH - 1; ++i) { | 1508 | for (i = 0; i < UHCI_NUM_SKELQH - 1; ++i) { |
| @@ -1377,33 +1511,30 @@ static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs) | |||
| 1377 | while ((qh = uhci->next_qh) != uhci->skelqh[i]) { | 1511 | while ((qh = uhci->next_qh) != uhci->skelqh[i]) { |
| 1378 | uhci->next_qh = list_entry(qh->node.next, | 1512 | uhci->next_qh = list_entry(qh->node.next, |
| 1379 | struct uhci_qh, node); | 1513 | struct uhci_qh, node); |
| 1380 | uhci_scan_qh(uhci, qh, regs); | 1514 | |
| 1515 | if (uhci_advance_check(uhci, qh)) { | ||
| 1516 | uhci_scan_qh(uhci, qh, regs); | ||
| 1517 | if (qh->state == QH_STATE_ACTIVE) { | ||
| 1518 | uhci_urbp_wants_fsbr(uhci, | ||
| 1519 | list_entry(qh->queue.next, struct urb_priv, node)); | ||
| 1520 | } | ||
| 1521 | } | ||
| 1381 | } | 1522 | } |
| 1382 | } | 1523 | } |
| 1383 | 1524 | ||
| 1525 | uhci->last_iso_frame = uhci->cur_iso_frame; | ||
| 1384 | if (uhci->need_rescan) | 1526 | if (uhci->need_rescan) |
| 1385 | goto rescan; | 1527 | goto rescan; |
| 1386 | uhci->scan_in_progress = 0; | 1528 | uhci->scan_in_progress = 0; |
| 1387 | 1529 | ||
| 1388 | /* If the controller is stopped, we can finish these off right now */ | 1530 | if (uhci->fsbr_is_on && !uhci->fsbr_is_wanted && |
| 1389 | if (uhci->is_stopped) | 1531 | !uhci->fsbr_expiring) { |
| 1390 | uhci_free_pending_tds(uhci); | 1532 | uhci->fsbr_expiring = 1; |
| 1533 | mod_timer(&uhci->fsbr_timer, jiffies + FSBR_OFF_DELAY); | ||
| 1534 | } | ||
| 1391 | 1535 | ||
| 1392 | if (list_empty(&uhci->td_remove_list) && | 1536 | if (list_empty(&uhci->skel_unlink_qh->node)) |
| 1393 | list_empty(&uhci->skel_unlink_qh->node)) | ||
| 1394 | uhci_clear_next_interrupt(uhci); | 1537 | uhci_clear_next_interrupt(uhci); |
| 1395 | else | 1538 | else |
| 1396 | uhci_set_next_interrupt(uhci); | 1539 | uhci_set_next_interrupt(uhci); |
| 1397 | } | 1540 | } |
| 1398 | |||
| 1399 | static void check_fsbr(struct uhci_hcd *uhci) | ||
| 1400 | { | ||
| 1401 | /* For now, don't scan URBs for FSBR timeouts. | ||
| 1402 | * Add it back in later... */ | ||
| 1403 | |||
| 1404 | /* Really disable FSBR */ | ||
| 1405 | if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) { | ||
| 1406 | uhci->fsbrtimeout = 0; | ||
| 1407 | uhci->skel_term_qh->link = UHCI_PTR_TERM; | ||
| 1408 | } | ||
| 1409 | } | ||
