Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Universal Host Controller Interface driver for USB. |
| 3 | * |
| 4 | * Maintainer: Alan Stern <stern@rowland.harvard.edu> |
| 5 | * |
| 6 | * (C) Copyright 1999 Linus Torvalds |
| 7 | * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com |
| 8 | * (C) Copyright 1999 Randy Dunlap |
| 9 | * (C) Copyright 1999 Georg Acher, acher@in.tum.de |
| 10 | * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de |
| 11 | * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch |
| 12 | * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at |
| 13 | * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface |
| 14 | * support from usb-ohci.c by Adam Richter, adam@yggdrasil.com). |
| 15 | * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c) |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 16 | * (C) Copyright 2004-2005 Alan Stern, stern@rowland.harvard.edu |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | static void uhci_free_pending_tds(struct uhci_hcd *uhci); |
| 20 | |
| 21 | /* |
| 22 | * Technically, updating td->status here is a race, but it's not really a |
| 23 | * problem. The worst that can happen is that we set the IOC bit again |
| 24 | * generating a spurious interrupt. We could fix this by creating another |
| 25 | * QH and leaving the IOC bit always set, but then we would have to play |
| 26 | * games with the FSBR code to make sure we get the correct order in all |
| 27 | * the cases. I don't think it's worth the effort |
| 28 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 29 | static void uhci_set_next_interrupt(struct uhci_hcd *uhci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
Alan Stern | 6c1b445 | 2005-04-21 16:04:58 -0400 | [diff] [blame] | 31 | if (uhci->is_stopped) |
Alan Stern | 1f09df8 | 2005-09-05 13:59:51 -0400 | [diff] [blame] | 32 | mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC); |
| 34 | } |
| 35 | |
| 36 | static inline void uhci_clear_next_interrupt(struct uhci_hcd *uhci) |
| 37 | { |
| 38 | uhci->term_td->status &= ~cpu_to_le32(TD_CTRL_IOC); |
| 39 | } |
| 40 | |
Alan Stern | 2532178 | 2005-04-25 11:14:31 -0400 | [diff] [blame] | 41 | static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
| 43 | dma_addr_t dma_handle; |
| 44 | struct uhci_td *td; |
| 45 | |
| 46 | td = dma_pool_alloc(uhci->td_pool, GFP_ATOMIC, &dma_handle); |
| 47 | if (!td) |
| 48 | return NULL; |
| 49 | |
| 50 | td->dma_handle = dma_handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | td->frame = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | INIT_LIST_HEAD(&td->list); |
| 54 | INIT_LIST_HEAD(&td->remove_list); |
| 55 | INIT_LIST_HEAD(&td->fl_list); |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | return td; |
| 58 | } |
| 59 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 60 | static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td) |
| 61 | { |
| 62 | if (!list_empty(&td->list)) |
| 63 | 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)) |
| 67 | dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td); |
| 68 | |
| 69 | dma_pool_free(uhci->td_pool, td, td->dma_handle); |
| 70 | } |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static inline void uhci_fill_td(struct uhci_td *td, u32 status, |
| 73 | u32 token, u32 buffer) |
| 74 | { |
| 75 | td->status = cpu_to_le32(status); |
| 76 | td->token = cpu_to_le32(token); |
| 77 | td->buffer = cpu_to_le32(buffer); |
| 78 | } |
| 79 | |
| 80 | /* |
Alan Stern | 687f5f3 | 2005-11-30 17:16:19 -0500 | [diff] [blame] | 81 | * We insert Isochronous URBs directly into the frame list at the beginning |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 83 | static inline void uhci_insert_td_in_frame_list(struct uhci_hcd *uhci, |
| 84 | struct uhci_td *td, unsigned framenum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
| 86 | framenum &= (UHCI_NUMFRAMES - 1); |
| 87 | |
| 88 | td->frame = framenum; |
| 89 | |
| 90 | /* Is there a TD already mapped there? */ |
Alan Stern | a1d59ce | 2005-09-16 14:22:51 -0400 | [diff] [blame] | 91 | if (uhci->frame_cpu[framenum]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | struct uhci_td *ftd, *ltd; |
| 93 | |
Alan Stern | a1d59ce | 2005-09-16 14:22:51 -0400 | [diff] [blame] | 94 | ftd = uhci->frame_cpu[framenum]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | ltd = list_entry(ftd->fl_list.prev, struct uhci_td, fl_list); |
| 96 | |
| 97 | list_add_tail(&td->fl_list, &ftd->fl_list); |
| 98 | |
| 99 | td->link = ltd->link; |
| 100 | wmb(); |
| 101 | ltd->link = cpu_to_le32(td->dma_handle); |
| 102 | } else { |
Alan Stern | a1d59ce | 2005-09-16 14:22:51 -0400 | [diff] [blame] | 103 | td->link = uhci->frame[framenum]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | wmb(); |
Alan Stern | a1d59ce | 2005-09-16 14:22:51 -0400 | [diff] [blame] | 105 | uhci->frame[framenum] = cpu_to_le32(td->dma_handle); |
| 106 | uhci->frame_cpu[framenum] = td; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 110 | static inline void uhci_remove_td_from_frame_list(struct uhci_hcd *uhci, |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 111 | struct uhci_td *td) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
| 113 | /* If it's not inserted, don't remove it */ |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 114 | if (td->frame == -1) { |
| 115 | WARN_ON(!list_empty(&td->fl_list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return; |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 119 | if (uhci->frame_cpu[td->frame] == td) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | if (list_empty(&td->fl_list)) { |
Alan Stern | a1d59ce | 2005-09-16 14:22:51 -0400 | [diff] [blame] | 121 | uhci->frame[td->frame] = td->link; |
| 122 | uhci->frame_cpu[td->frame] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } else { |
| 124 | struct uhci_td *ntd; |
| 125 | |
| 126 | ntd = list_entry(td->fl_list.next, struct uhci_td, fl_list); |
Alan Stern | a1d59ce | 2005-09-16 14:22:51 -0400 | [diff] [blame] | 127 | uhci->frame[td->frame] = cpu_to_le32(ntd->dma_handle); |
| 128 | uhci->frame_cpu[td->frame] = ntd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | } else { |
| 131 | struct uhci_td *ptd; |
| 132 | |
| 133 | ptd = list_entry(td->fl_list.prev, struct uhci_td, fl_list); |
| 134 | ptd->link = td->link; |
| 135 | } |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | list_del_init(&td->fl_list); |
| 138 | td->frame = -1; |
| 139 | } |
| 140 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 141 | /* |
| 142 | * Remove all the TDs for an Isochronous URB from the frame list |
| 143 | */ |
| 144 | static void uhci_unlink_isochronous_tds(struct uhci_hcd *uhci, struct urb *urb) |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 145 | { |
| 146 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; |
| 147 | struct uhci_td *td; |
| 148 | |
| 149 | list_for_each_entry(td, &urbp->td_list, list) |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 150 | uhci_remove_td_from_frame_list(uhci, td); |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 151 | wmb(); |
| 152 | } |
| 153 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 154 | static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, |
| 155 | struct usb_device *udev, struct usb_host_endpoint *hep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
| 157 | dma_addr_t dma_handle; |
| 158 | struct uhci_qh *qh; |
| 159 | |
| 160 | qh = dma_pool_alloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle); |
| 161 | if (!qh) |
| 162 | return NULL; |
| 163 | |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 164 | memset(qh, 0, sizeof(*qh)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | qh->dma_handle = dma_handle; |
| 166 | |
| 167 | qh->element = UHCI_PTR_TERM; |
| 168 | qh->link = UHCI_PTR_TERM; |
| 169 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 170 | INIT_LIST_HEAD(&qh->queue); |
| 171 | INIT_LIST_HEAD(&qh->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 173 | if (udev) { /* Normal QH */ |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 174 | qh->dummy_td = uhci_alloc_td(uhci); |
| 175 | if (!qh->dummy_td) { |
| 176 | dma_pool_free(uhci->qh_pool, qh, dma_handle); |
| 177 | return NULL; |
| 178 | } |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 179 | qh->state = QH_STATE_IDLE; |
| 180 | qh->hep = hep; |
| 181 | qh->udev = udev; |
| 182 | hep->hcpriv = qh; |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 183 | qh->type = hep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 185 | } else { /* Skeleton QH */ |
| 186 | qh->state = QH_STATE_ACTIVE; |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 187 | qh->type = -1; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 188 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return qh; |
| 190 | } |
| 191 | |
| 192 | static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) |
| 193 | { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 194 | WARN_ON(qh->state != QH_STATE_IDLE && qh->udev); |
| 195 | if (!list_empty(&qh->queue)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | dev_warn(uhci_dev(uhci), "qh %p list not empty!\n", qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 198 | list_del(&qh->node); |
| 199 | if (qh->udev) { |
| 200 | qh->hep->hcpriv = NULL; |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 201 | uhci_free_td(uhci, qh->dummy_td); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 202 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | dma_pool_free(uhci->qh_pool, qh, qh->dma_handle); |
| 204 | } |
| 205 | |
| 206 | /* |
Alan Stern | a0b458b | 2006-05-12 11:23:19 -0400 | [diff] [blame^] | 207 | * When a queue is stopped and a dequeued URB is given back, adjust |
| 208 | * the previous TD link (if the URB isn't first on the queue) or |
| 209 | * save its toggle value (if it is first and is currently executing). |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 210 | */ |
Alan Stern | a0b458b | 2006-05-12 11:23:19 -0400 | [diff] [blame^] | 211 | static void uhci_cleanup_queue(struct uhci_qh *qh, |
| 212 | struct urb *urb) |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 213 | { |
Alan Stern | a0b458b | 2006-05-12 11:23:19 -0400 | [diff] [blame^] | 214 | struct urb_priv *urbp = urb->hcpriv; |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 215 | struct uhci_td *td; |
| 216 | |
Alan Stern | a0b458b | 2006-05-12 11:23:19 -0400 | [diff] [blame^] | 217 | /* Isochronous pipes don't use toggles and their TD link pointers |
| 218 | * get adjusted during uhci_urb_dequeue(). */ |
| 219 | if (qh->type == USB_ENDPOINT_XFER_ISOC) |
| 220 | return; |
| 221 | |
| 222 | /* If the URB isn't first on its queue, adjust the link pointer |
| 223 | * of the last TD in the previous URB. The toggle doesn't need |
| 224 | * to be saved since this URB can't be executing yet. */ |
| 225 | if (qh->queue.next != &urbp->node) { |
| 226 | struct urb_priv *purbp; |
| 227 | struct uhci_td *ptd; |
| 228 | |
| 229 | purbp = list_entry(urbp->node.prev, struct urb_priv, node); |
| 230 | WARN_ON(list_empty(&purbp->td_list)); |
| 231 | ptd = list_entry(purbp->td_list.prev, struct uhci_td, |
| 232 | list); |
| 233 | td = list_entry(urbp->td_list.prev, struct uhci_td, |
| 234 | list); |
| 235 | ptd->link = td->link; |
| 236 | return; |
| 237 | } |
| 238 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 239 | /* If the QH element pointer is UHCI_PTR_TERM then then currently |
| 240 | * executing URB has already been unlinked, so this one isn't it. */ |
Alan Stern | a0b458b | 2006-05-12 11:23:19 -0400 | [diff] [blame^] | 241 | if (qh_element(qh) == UHCI_PTR_TERM) |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 242 | return; |
| 243 | qh->element = UHCI_PTR_TERM; |
| 244 | |
Alan Stern | a0b458b | 2006-05-12 11:23:19 -0400 | [diff] [blame^] | 245 | /* Control pipes have to worry about toggles */ |
| 246 | if (qh->type == USB_ENDPOINT_XFER_CONTROL) |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 247 | return; |
| 248 | |
Alan Stern | a0b458b | 2006-05-12 11:23:19 -0400 | [diff] [blame^] | 249 | /* Save the next toggle value */ |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 250 | WARN_ON(list_empty(&urbp->td_list)); |
| 251 | td = list_entry(urbp->td_list.next, struct uhci_td, list); |
| 252 | qh->needs_fixup = 1; |
| 253 | qh->initial_toggle = uhci_toggle(td_token(td)); |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /* |
| 257 | * Fix up the data toggles for URBs in a queue, when one of them |
| 258 | * terminates early (short transfer, error, or dequeued). |
| 259 | */ |
| 260 | static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first) |
| 261 | { |
| 262 | struct urb_priv *urbp = NULL; |
| 263 | struct uhci_td *td; |
| 264 | unsigned int toggle = qh->initial_toggle; |
| 265 | unsigned int pipe; |
| 266 | |
| 267 | /* Fixups for a short transfer start with the second URB in the |
| 268 | * queue (the short URB is the first). */ |
| 269 | if (skip_first) |
| 270 | urbp = list_entry(qh->queue.next, struct urb_priv, node); |
| 271 | |
| 272 | /* When starting with the first URB, if the QH element pointer is |
| 273 | * still valid then we know the URB's toggles are okay. */ |
| 274 | else if (qh_element(qh) != UHCI_PTR_TERM) |
| 275 | toggle = 2; |
| 276 | |
| 277 | /* Fix up the toggle for the URBs in the queue. Normally this |
| 278 | * loop won't run more than once: When an error or short transfer |
| 279 | * occurs, the queue usually gets emptied. */ |
Alan Stern | 1393adb | 2006-01-31 10:02:55 -0500 | [diff] [blame] | 280 | urbp = list_prepare_entry(urbp, &qh->queue, node); |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 281 | list_for_each_entry_continue(urbp, &qh->queue, node) { |
| 282 | |
| 283 | /* If the first TD has the right toggle value, we don't |
| 284 | * need to change any toggles in this URB */ |
| 285 | td = list_entry(urbp->td_list.next, struct uhci_td, list); |
| 286 | if (toggle > 1 || uhci_toggle(td_token(td)) == toggle) { |
| 287 | td = list_entry(urbp->td_list.next, struct uhci_td, |
| 288 | list); |
| 289 | toggle = uhci_toggle(td_token(td)) ^ 1; |
| 290 | |
| 291 | /* Otherwise all the toggles in the URB have to be switched */ |
| 292 | } else { |
| 293 | list_for_each_entry(td, &urbp->td_list, list) { |
| 294 | td->token ^= __constant_cpu_to_le32( |
| 295 | TD_TOKEN_TOGGLE); |
| 296 | toggle ^= 1; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | wmb(); |
| 302 | pipe = list_entry(qh->queue.next, struct urb_priv, node)->urb->pipe; |
| 303 | usb_settoggle(qh->udev, usb_pipeendpoint(pipe), |
| 304 | usb_pipeout(pipe), toggle); |
| 305 | qh->needs_fixup = 0; |
| 306 | } |
| 307 | |
| 308 | /* |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 309 | * Put a QH on the schedule in both hardware and software |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 311 | static void uhci_activate_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 313 | struct uhci_qh *pqh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 315 | WARN_ON(list_empty(&qh->queue)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 317 | /* Set the element pointer if it isn't set already. |
| 318 | * This isn't needed for Isochronous queues, but it doesn't hurt. */ |
| 319 | if (qh_element(qh) == UHCI_PTR_TERM) { |
| 320 | struct urb_priv *urbp = list_entry(qh->queue.next, |
| 321 | struct urb_priv, node); |
| 322 | struct uhci_td *td = list_entry(urbp->td_list.next, |
| 323 | struct uhci_td, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 325 | qh->element = cpu_to_le32(td->dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 328 | if (qh->state == QH_STATE_ACTIVE) |
| 329 | return; |
| 330 | qh->state = QH_STATE_ACTIVE; |
| 331 | |
| 332 | /* Move the QH from its old list to the end of the appropriate |
| 333 | * skeleton's list */ |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 334 | if (qh == uhci->next_qh) |
| 335 | uhci->next_qh = list_entry(qh->node.next, struct uhci_qh, |
| 336 | node); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 337 | list_move_tail(&qh->node, &qh->skel->node); |
| 338 | |
| 339 | /* Link it into the schedule */ |
| 340 | pqh = list_entry(qh->node.prev, struct uhci_qh, node); |
| 341 | qh->link = pqh->link; |
| 342 | wmb(); |
| 343 | pqh->link = UHCI_PTR_QH | cpu_to_le32(qh->dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 347 | * Take a QH off the hardware schedule |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 349 | static void uhci_unlink_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | { |
| 351 | struct uhci_qh *pqh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 353 | if (qh->state == QH_STATE_UNLINKING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 355 | WARN_ON(qh->state != QH_STATE_ACTIVE || !qh->udev); |
| 356 | qh->state = QH_STATE_UNLINKING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 358 | /* Unlink the QH from the schedule and record when we did it */ |
| 359 | pqh = list_entry(qh->node.prev, struct uhci_qh, node); |
| 360 | pqh->link = qh->link; |
| 361 | mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | uhci_get_current_frame_number(uhci); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 364 | qh->unlink_frame = uhci->frame_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 366 | /* Force an interrupt so we know when the QH is fully unlinked */ |
| 367 | if (list_empty(&uhci->skel_unlink_qh->node)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | uhci_set_next_interrupt(uhci); |
| 369 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 370 | /* Move the QH from its old list to the end of the unlinking list */ |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 371 | if (qh == uhci->next_qh) |
| 372 | uhci->next_qh = list_entry(qh->node.next, struct uhci_qh, |
| 373 | node); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 374 | list_move_tail(&qh->node, &uhci->skel_unlink_qh->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 377 | /* |
| 378 | * When we and the controller are through with a QH, it becomes IDLE. |
| 379 | * This happens when a QH has been off the schedule (on the unlinking |
| 380 | * list) for more than one frame, or when an error occurs while adding |
| 381 | * the first URB onto a new QH. |
| 382 | */ |
| 383 | static void uhci_make_qh_idle(struct uhci_hcd *uhci, struct uhci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 385 | WARN_ON(qh->state == QH_STATE_ACTIVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 387 | if (qh == uhci->next_qh) |
| 388 | uhci->next_qh = list_entry(qh->node.next, struct uhci_qh, |
| 389 | node); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 390 | list_move(&qh->node, &uhci->idle_qh_list); |
| 391 | qh->state = QH_STATE_IDLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 393 | /* Now that the QH is idle, its post_td isn't being used */ |
| 394 | if (qh->post_td) { |
| 395 | uhci_free_td(uhci, qh->post_td); |
| 396 | qh->post_td = NULL; |
| 397 | } |
| 398 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 399 | /* If anyone is waiting for a QH to become idle, wake them up */ |
| 400 | if (uhci->num_waiting) |
| 401 | wake_up_all(&uhci->waitqh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 404 | static inline struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci, |
| 405 | struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | { |
| 407 | struct urb_priv *urbp; |
| 408 | |
| 409 | urbp = kmem_cache_alloc(uhci_up_cachep, SLAB_ATOMIC); |
| 410 | if (!urbp) |
| 411 | return NULL; |
| 412 | |
| 413 | memset((void *)urbp, 0, sizeof(*urbp)); |
| 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | urbp->urb = urb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | urb->hcpriv = urbp; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 417 | |
| 418 | INIT_LIST_HEAD(&urbp->node); |
| 419 | INIT_LIST_HEAD(&urbp->td_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | return urbp; |
| 422 | } |
| 423 | |
| 424 | static void uhci_add_td_to_urb(struct urb *urb, struct uhci_td *td) |
| 425 | { |
| 426 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | list_add_tail(&td->list, &urbp->td_list); |
| 429 | } |
| 430 | |
| 431 | static void uhci_remove_td_from_urb(struct uhci_td *td) |
| 432 | { |
| 433 | if (list_empty(&td->list)) |
| 434 | return; |
| 435 | |
| 436 | list_del_init(&td->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 439 | static void uhci_free_urb_priv(struct uhci_hcd *uhci, |
| 440 | struct urb_priv *urbp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | { |
| 442 | struct uhci_td *td, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 444 | if (!list_empty(&urbp->node)) |
| 445 | dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n", |
| 446 | urbp->urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | uhci_get_current_frame_number(uhci); |
| 449 | if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) { |
| 450 | uhci_free_pending_tds(uhci); |
| 451 | uhci->td_remove_age = uhci->frame_number; |
| 452 | } |
| 453 | |
| 454 | /* Check to see if the remove list is empty. Set the IOC bit */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 455 | /* to force an interrupt so we can remove the TDs. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | if (list_empty(&uhci->td_remove_list)) |
| 457 | uhci_set_next_interrupt(uhci); |
| 458 | |
| 459 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { |
| 460 | uhci_remove_td_from_urb(td); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | list_add(&td->remove_list, &uhci->td_remove_list); |
| 462 | } |
| 463 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 464 | urbp->urb->hcpriv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | kmem_cache_free(uhci_up_cachep, urbp); |
| 466 | } |
| 467 | |
| 468 | static void uhci_inc_fsbr(struct uhci_hcd *uhci, struct urb *urb) |
| 469 | { |
| 470 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; |
| 471 | |
| 472 | if ((!(urb->transfer_flags & URB_NO_FSBR)) && !urbp->fsbr) { |
| 473 | urbp->fsbr = 1; |
| 474 | if (!uhci->fsbr++ && !uhci->fsbrtimeout) |
| 475 | uhci->skel_term_qh->link = cpu_to_le32(uhci->skel_fs_control_qh->dma_handle) | UHCI_PTR_QH; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | static void uhci_dec_fsbr(struct uhci_hcd *uhci, struct urb *urb) |
| 480 | { |
| 481 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; |
| 482 | |
| 483 | if ((!(urb->transfer_flags & URB_NO_FSBR)) && urbp->fsbr) { |
| 484 | urbp->fsbr = 0; |
| 485 | if (!--uhci->fsbr) |
| 486 | uhci->fsbrtimeout = jiffies + FSBR_DELAY; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /* |
| 491 | * Map status to standard result codes |
| 492 | * |
| 493 | * <status> is (td_status(td) & 0xF60000), a.k.a. |
| 494 | * uhci_status_bits(td_status(td)). |
| 495 | * Note: <status> does not include the TD_CTRL_NAK bit. |
| 496 | * <dir_out> is True for output TDs and False for input TDs. |
| 497 | */ |
| 498 | static int uhci_map_status(int status, int dir_out) |
| 499 | { |
| 500 | if (!status) |
| 501 | return 0; |
| 502 | if (status & TD_CTRL_BITSTUFF) /* Bitstuff error */ |
| 503 | return -EPROTO; |
| 504 | if (status & TD_CTRL_CRCTIMEO) { /* CRC/Timeout */ |
| 505 | if (dir_out) |
| 506 | return -EPROTO; |
| 507 | else |
| 508 | return -EILSEQ; |
| 509 | } |
| 510 | if (status & TD_CTRL_BABBLE) /* Babble */ |
| 511 | return -EOVERFLOW; |
| 512 | if (status & TD_CTRL_DBUFERR) /* Buffer error */ |
| 513 | return -ENOSR; |
| 514 | if (status & TD_CTRL_STALLED) /* Stalled */ |
| 515 | return -EPIPE; |
| 516 | WARN_ON(status & TD_CTRL_ACTIVE); /* Active */ |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * Control transfers |
| 522 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 523 | static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, |
| 524 | struct uhci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | struct uhci_td *td; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | unsigned long destination, status; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 528 | int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | int len = urb->transfer_buffer_length; |
| 530 | dma_addr_t data = urb->transfer_dma; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 531 | __le32 *plink; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | /* The "pipe" thing contains the destination in bits 8--18 */ |
| 534 | destination = (urb->pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP; |
| 535 | |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 536 | /* 3 errors, dummy TD remains inactive */ |
| 537 | status = uhci_maxerr(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | if (urb->dev->speed == USB_SPEED_LOW) |
| 539 | status |= TD_CTRL_LS; |
| 540 | |
| 541 | /* |
| 542 | * Build the TD for the control request setup packet |
| 543 | */ |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 544 | td = qh->dummy_td; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | uhci_add_td_to_urb(urb, td); |
Alan Stern | fa34656 | 2005-11-30 11:57:51 -0500 | [diff] [blame] | 546 | uhci_fill_td(td, status, destination | uhci_explen(8), |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 547 | urb->setup_dma); |
| 548 | plink = &td->link; |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 549 | status |= TD_CTRL_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | /* |
| 552 | * If direction is "send", change the packet ID from SETUP (0x2D) |
| 553 | * to OUT (0xE1). Else change it from SETUP to IN (0x69) and |
| 554 | * set Short Packet Detect (SPD) for all data packets. |
| 555 | */ |
| 556 | if (usb_pipeout(urb->pipe)) |
| 557 | destination ^= (USB_PID_SETUP ^ USB_PID_OUT); |
| 558 | else { |
| 559 | destination ^= (USB_PID_SETUP ^ USB_PID_IN); |
| 560 | status |= TD_CTRL_SPD; |
| 561 | } |
| 562 | |
| 563 | /* |
Alan Stern | 687f5f3 | 2005-11-30 17:16:19 -0500 | [diff] [blame] | 564 | * Build the DATA TDs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | */ |
| 566 | while (len > 0) { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 567 | int pktsze = min(len, maxsze); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
Alan Stern | 2532178 | 2005-04-25 11:14:31 -0400 | [diff] [blame] | 569 | td = uhci_alloc_td(uhci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | if (!td) |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 571 | goto nomem; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 572 | *plink = cpu_to_le32(td->dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
| 574 | /* Alternate Data0/1 (start with Data1) */ |
| 575 | destination ^= TD_TOKEN_TOGGLE; |
| 576 | |
| 577 | uhci_add_td_to_urb(urb, td); |
Alan Stern | fa34656 | 2005-11-30 11:57:51 -0500 | [diff] [blame] | 578 | uhci_fill_td(td, status, destination | uhci_explen(pktsze), |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 579 | data); |
| 580 | plink = &td->link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | data += pktsze; |
| 583 | len -= pktsze; |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Build the final TD for control status |
| 588 | */ |
Alan Stern | 2532178 | 2005-04-25 11:14:31 -0400 | [diff] [blame] | 589 | td = uhci_alloc_td(uhci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | if (!td) |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 591 | goto nomem; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 592 | *plink = cpu_to_le32(td->dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | /* |
| 595 | * It's IN if the pipe is an output pipe or we're not expecting |
| 596 | * data back. |
| 597 | */ |
| 598 | destination &= ~TD_TOKEN_PID_MASK; |
| 599 | if (usb_pipeout(urb->pipe) || !urb->transfer_buffer_length) |
| 600 | destination |= USB_PID_IN; |
| 601 | else |
| 602 | destination |= USB_PID_OUT; |
| 603 | |
| 604 | destination |= TD_TOKEN_TOGGLE; /* End in Data1 */ |
| 605 | |
| 606 | status &= ~TD_CTRL_SPD; |
| 607 | |
| 608 | uhci_add_td_to_urb(urb, td); |
| 609 | uhci_fill_td(td, status | TD_CTRL_IOC, |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 610 | destination | uhci_explen(0), 0); |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 611 | plink = &td->link; |
| 612 | |
| 613 | /* |
| 614 | * Build the new dummy TD and activate the old one |
| 615 | */ |
| 616 | td = uhci_alloc_td(uhci); |
| 617 | if (!td) |
| 618 | goto nomem; |
| 619 | *plink = cpu_to_le32(td->dma_handle); |
| 620 | |
| 621 | uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); |
| 622 | wmb(); |
| 623 | qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE); |
| 624 | qh->dummy_td = td; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 626 | /* Low-speed transfers get a different queue, and won't hog the bus. |
| 627 | * Also, some devices enumerate better without FSBR; the easiest way |
| 628 | * to do that is to put URBs on the low-speed queue while the device |
Alan Stern | 630aa3c | 2006-01-23 17:17:21 -0500 | [diff] [blame] | 629 | * isn't in the CONFIGURED state. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | if (urb->dev->speed == USB_SPEED_LOW || |
Alan Stern | 630aa3c | 2006-01-23 17:17:21 -0500 | [diff] [blame] | 631 | urb->dev->state != USB_STATE_CONFIGURED) |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 632 | qh->skel = uhci->skel_ls_control_qh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | else { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 634 | qh->skel = uhci->skel_fs_control_qh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | uhci_inc_fsbr(uhci, urb); |
| 636 | } |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 637 | |
| 638 | urb->actual_length = -8; /* Account for the SETUP packet */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 639 | return 0; |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 640 | |
| 641 | nomem: |
| 642 | /* Remove the dummy TD from the td_list so it doesn't get freed */ |
| 643 | uhci_remove_td_from_urb(qh->dummy_td); |
| 644 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | * Common submit for bulk and interrupt |
| 649 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 650 | static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, |
| 651 | struct uhci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { |
| 653 | struct uhci_td *td; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | unsigned long destination, status; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 655 | int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | int len = urb->transfer_buffer_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | dma_addr_t data = urb->transfer_dma; |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 658 | __le32 *plink; |
| 659 | unsigned int toggle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | if (len < 0) |
| 662 | return -EINVAL; |
| 663 | |
| 664 | /* The "pipe" thing contains the destination in bits 8--18 */ |
| 665 | destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe); |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 666 | toggle = usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), |
| 667 | usb_pipeout(urb->pipe)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 669 | /* 3 errors, dummy TD remains inactive */ |
| 670 | status = uhci_maxerr(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | if (urb->dev->speed == USB_SPEED_LOW) |
| 672 | status |= TD_CTRL_LS; |
| 673 | if (usb_pipein(urb->pipe)) |
| 674 | status |= TD_CTRL_SPD; |
| 675 | |
| 676 | /* |
Alan Stern | 687f5f3 | 2005-11-30 17:16:19 -0500 | [diff] [blame] | 677 | * Build the DATA TDs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | */ |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 679 | plink = NULL; |
| 680 | td = qh->dummy_td; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | do { /* Allow zero length packets */ |
| 682 | int pktsze = maxsze; |
| 683 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 684 | if (len <= pktsze) { /* The last packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | pktsze = len; |
| 686 | if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) |
| 687 | status &= ~TD_CTRL_SPD; |
| 688 | } |
| 689 | |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 690 | if (plink) { |
| 691 | td = uhci_alloc_td(uhci); |
| 692 | if (!td) |
| 693 | goto nomem; |
| 694 | *plink = cpu_to_le32(td->dma_handle); |
| 695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | uhci_add_td_to_urb(urb, td); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 697 | uhci_fill_td(td, status, |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 698 | destination | uhci_explen(pktsze) | |
| 699 | (toggle << TD_TOKEN_TOGGLE_SHIFT), |
| 700 | data); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 701 | plink = &td->link; |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 702 | status |= TD_CTRL_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | data += pktsze; |
| 705 | len -= maxsze; |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 706 | toggle ^= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } while (len > 0); |
| 708 | |
| 709 | /* |
| 710 | * URB_ZERO_PACKET means adding a 0-length packet, if direction |
| 711 | * is OUT and the transfer_length was an exact multiple of maxsze, |
| 712 | * hence (len = transfer_length - N * maxsze) == 0 |
| 713 | * however, if transfer_length == 0, the zero packet was already |
| 714 | * prepared above. |
| 715 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 716 | if ((urb->transfer_flags & URB_ZERO_PACKET) && |
| 717 | usb_pipeout(urb->pipe) && len == 0 && |
| 718 | urb->transfer_buffer_length > 0) { |
Alan Stern | 2532178 | 2005-04-25 11:14:31 -0400 | [diff] [blame] | 719 | td = uhci_alloc_td(uhci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | if (!td) |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 721 | goto nomem; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 722 | *plink = cpu_to_le32(td->dma_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | uhci_add_td_to_urb(urb, td); |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 725 | uhci_fill_td(td, status, |
| 726 | destination | uhci_explen(0) | |
| 727 | (toggle << TD_TOKEN_TOGGLE_SHIFT), |
| 728 | data); |
| 729 | plink = &td->link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 731 | toggle ^= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /* Set the interrupt-on-completion flag on the last packet. |
| 735 | * A more-or-less typical 4 KB URB (= size of one memory page) |
| 736 | * will require about 3 ms to transfer; that's a little on the |
| 737 | * fast side but not enough to justify delaying an interrupt |
| 738 | * more than 2 or 3 URBs, so we will ignore the URB_NO_INTERRUPT |
| 739 | * flag setting. */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 740 | td->status |= __constant_cpu_to_le32(TD_CTRL_IOC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 742 | /* |
| 743 | * Build the new dummy TD and activate the old one |
| 744 | */ |
| 745 | td = uhci_alloc_td(uhci); |
| 746 | if (!td) |
| 747 | goto nomem; |
| 748 | *plink = cpu_to_le32(td->dma_handle); |
| 749 | |
| 750 | uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); |
| 751 | wmb(); |
| 752 | qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE); |
| 753 | qh->dummy_td = td; |
| 754 | |
| 755 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), |
| 756 | usb_pipeout(urb->pipe), toggle); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 757 | return 0; |
Alan Stern | af0bb59 | 2005-12-17 18:00:12 -0500 | [diff] [blame] | 758 | |
| 759 | nomem: |
| 760 | /* Remove the dummy TD from the td_list so it doesn't get freed */ |
| 761 | uhci_remove_td_from_urb(qh->dummy_td); |
| 762 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 765 | static inline int uhci_submit_bulk(struct uhci_hcd *uhci, struct urb *urb, |
| 766 | struct uhci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | { |
| 768 | int ret; |
| 769 | |
| 770 | /* Can't have low-speed bulk transfers */ |
| 771 | if (urb->dev->speed == USB_SPEED_LOW) |
| 772 | return -EINVAL; |
| 773 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 774 | qh->skel = uhci->skel_bulk_qh; |
| 775 | ret = uhci_submit_common(uhci, urb, qh); |
| 776 | if (ret == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | uhci_inc_fsbr(uhci, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | return ret; |
| 779 | } |
| 780 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 781 | static inline int uhci_submit_interrupt(struct uhci_hcd *uhci, struct urb *urb, |
| 782 | struct uhci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 784 | /* USB 1.1 interrupt transfers only involve one packet per interval. |
| 785 | * Drivers can submit URBs of any length, but longer ones will need |
| 786 | * multiple intervals to complete. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 788 | qh->skel = uhci->skelqh[__interval_to_skel(urb->interval)]; |
| 789 | return uhci_submit_common(uhci, urb, qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | /* |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 793 | * Fix up the data structures following a short transfer |
| 794 | */ |
| 795 | static int uhci_fixup_short_transfer(struct uhci_hcd *uhci, |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 796 | struct uhci_qh *qh, struct urb_priv *urbp) |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 797 | { |
| 798 | struct uhci_td *td; |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 799 | struct list_head *tmp; |
| 800 | int ret; |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 801 | |
| 802 | td = list_entry(urbp->td_list.prev, struct uhci_td, list); |
| 803 | if (qh->type == USB_ENDPOINT_XFER_CONTROL) { |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 804 | |
| 805 | /* When a control transfer is short, we have to restart |
| 806 | * the queue at the status stage transaction, which is |
| 807 | * the last TD. */ |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 808 | WARN_ON(list_empty(&urbp->td_list)); |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 809 | qh->element = cpu_to_le32(td->dma_handle); |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 810 | tmp = td->list.prev; |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 811 | ret = -EINPROGRESS; |
| 812 | |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 813 | } else { |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 814 | |
| 815 | /* When a bulk/interrupt transfer is short, we have to |
| 816 | * fix up the toggles of the following URBs on the queue |
| 817 | * before restarting the queue at the next URB. */ |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 818 | qh->initial_toggle = uhci_toggle(td_token(qh->post_td)) ^ 1; |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 819 | uhci_fixup_toggles(qh, 1); |
| 820 | |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 821 | if (list_empty(&urbp->td_list)) |
| 822 | td = qh->post_td; |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 823 | qh->element = td->link; |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 824 | tmp = urbp->td_list.prev; |
| 825 | ret = 0; |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 826 | } |
| 827 | |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 828 | /* Remove all the TDs we skipped over, from tmp back to the start */ |
| 829 | while (tmp != &urbp->td_list) { |
| 830 | td = list_entry(tmp, struct uhci_td, list); |
| 831 | tmp = tmp->prev; |
| 832 | |
| 833 | uhci_remove_td_from_urb(td); |
| 834 | list_add(&td->remove_list, &uhci->td_remove_list); |
| 835 | } |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 836 | return ret; |
| 837 | } |
| 838 | |
| 839 | /* |
| 840 | * Common result for control, bulk, and interrupt |
| 841 | */ |
| 842 | static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb) |
| 843 | { |
| 844 | struct urb_priv *urbp = urb->hcpriv; |
| 845 | struct uhci_qh *qh = urbp->qh; |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 846 | struct uhci_td *td, *tmp; |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 847 | unsigned status; |
| 848 | int ret = 0; |
| 849 | |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 850 | list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 851 | unsigned int ctrlstat; |
| 852 | int len; |
| 853 | |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 854 | ctrlstat = td_status(td); |
| 855 | status = uhci_status_bits(ctrlstat); |
| 856 | if (status & TD_CTRL_ACTIVE) |
| 857 | return -EINPROGRESS; |
| 858 | |
| 859 | len = uhci_actual_length(ctrlstat); |
| 860 | urb->actual_length += len; |
| 861 | |
| 862 | if (status) { |
| 863 | ret = uhci_map_status(status, |
| 864 | uhci_packetout(td_token(td))); |
| 865 | if ((debug == 1 && ret != -EPIPE) || debug > 1) { |
| 866 | /* Some debugging code */ |
| 867 | dev_dbg(uhci_dev(uhci), |
| 868 | "%s: failed with status %x\n", |
| 869 | __FUNCTION__, status); |
| 870 | |
| 871 | if (debug > 1 && errbuf) { |
| 872 | /* Print the chain for debugging */ |
| 873 | uhci_show_qh(urbp->qh, errbuf, |
| 874 | ERRBUF_LEN, 0); |
| 875 | lprintk(errbuf); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | } else if (len < uhci_expected_length(td_token(td))) { |
| 880 | |
| 881 | /* We received a short packet */ |
| 882 | if (urb->transfer_flags & URB_SHORT_NOT_OK) |
| 883 | ret = -EREMOTEIO; |
| 884 | else if (ctrlstat & TD_CTRL_SPD) |
| 885 | ret = 1; |
| 886 | } |
| 887 | |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 888 | uhci_remove_td_from_urb(td); |
| 889 | if (qh->post_td) |
| 890 | list_add(&qh->post_td->remove_list, |
| 891 | &uhci->td_remove_list); |
| 892 | qh->post_td = td; |
| 893 | |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 894 | if (ret != 0) |
| 895 | goto err; |
| 896 | } |
| 897 | return ret; |
| 898 | |
| 899 | err: |
| 900 | if (ret < 0) { |
| 901 | /* In case a control transfer gets an error |
| 902 | * during the setup stage */ |
| 903 | urb->actual_length = max(urb->actual_length, 0); |
| 904 | |
| 905 | /* Note that the queue has stopped and save |
| 906 | * the next toggle value */ |
| 907 | qh->element = UHCI_PTR_TERM; |
| 908 | qh->is_stopped = 1; |
| 909 | qh->needs_fixup = (qh->type != USB_ENDPOINT_XFER_CONTROL); |
| 910 | qh->initial_toggle = uhci_toggle(td_token(td)) ^ |
| 911 | (ret == -EREMOTEIO); |
| 912 | |
| 913 | } else /* Short packet received */ |
Alan Stern | 59e29ed | 2006-05-12 11:19:19 -0400 | [diff] [blame] | 914 | ret = uhci_fixup_short_transfer(uhci, qh, urbp); |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 915 | return ret; |
| 916 | } |
| 917 | |
| 918 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | * Isochronous transfers |
| 920 | */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 921 | static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb, |
| 922 | struct uhci_qh *qh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 924 | struct uhci_td *td = NULL; /* Since urb->number_of_packets > 0 */ |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 925 | int i, frame; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 926 | unsigned long destination, status; |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 927 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 929 | if (urb->number_of_packets > 900) /* 900? Why? */ |
| 930 | return -EFBIG; |
| 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | status = TD_CTRL_ACTIVE | TD_CTRL_IOS; |
| 933 | destination = (urb->pipe & PIPE_DEVEP_MASK) | usb_packetid(urb->pipe); |
| 934 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 935 | /* Figure out the starting frame number */ |
| 936 | if (urb->transfer_flags & URB_ISO_ASAP) { |
| 937 | if (list_empty(&qh->queue)) { |
| 938 | uhci_get_current_frame_number(uhci); |
| 939 | urb->start_frame = (uhci->frame_number + 10); |
| 940 | |
| 941 | } else { /* Go right after the last one */ |
| 942 | struct urb *last_urb; |
| 943 | |
| 944 | last_urb = list_entry(qh->queue.prev, |
| 945 | struct urb_priv, node)->urb; |
| 946 | urb->start_frame = (last_urb->start_frame + |
| 947 | last_urb->number_of_packets * |
| 948 | last_urb->interval); |
| 949 | } |
| 950 | } else { |
| 951 | /* FIXME: Sanity check */ |
| 952 | } |
| 953 | urb->start_frame &= (UHCI_NUMFRAMES - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 955 | for (i = 0; i < urb->number_of_packets; i++) { |
Alan Stern | 2532178 | 2005-04-25 11:14:31 -0400 | [diff] [blame] | 956 | td = uhci_alloc_td(uhci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | if (!td) |
| 958 | return -ENOMEM; |
| 959 | |
| 960 | uhci_add_td_to_urb(urb, td); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 961 | uhci_fill_td(td, status, destination | |
| 962 | uhci_explen(urb->iso_frame_desc[i].length), |
| 963 | urb->transfer_dma + |
| 964 | urb->iso_frame_desc[i].offset); |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 967 | /* Set the interrupt-on-completion flag on the last packet. */ |
| 968 | td->status |= __constant_cpu_to_le32(TD_CTRL_IOC); |
| 969 | |
| 970 | qh->skel = uhci->skel_iso_qh; |
| 971 | |
| 972 | /* Add the TDs to the frame list */ |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 973 | frame = urb->start_frame; |
| 974 | list_for_each_entry(td, &urbp->td_list, list) { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 975 | uhci_insert_td_in_frame_list(uhci, td, frame); |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 976 | frame += urb->interval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 979 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb) |
| 983 | { |
| 984 | struct uhci_td *td; |
| 985 | struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv; |
| 986 | int status; |
| 987 | int i, ret = 0; |
| 988 | |
Alan Stern | b81d343 | 2005-10-13 17:00:24 -0400 | [diff] [blame] | 989 | urb->actual_length = urb->error_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
| 991 | i = 0; |
| 992 | list_for_each_entry(td, &urbp->td_list, list) { |
| 993 | int actlength; |
| 994 | unsigned int ctrlstat = td_status(td); |
| 995 | |
| 996 | if (ctrlstat & TD_CTRL_ACTIVE) |
| 997 | return -EINPROGRESS; |
| 998 | |
| 999 | actlength = uhci_actual_length(ctrlstat); |
| 1000 | urb->iso_frame_desc[i].actual_length = actlength; |
| 1001 | urb->actual_length += actlength; |
| 1002 | |
| 1003 | status = uhci_map_status(uhci_status_bits(ctrlstat), |
| 1004 | usb_pipeout(urb->pipe)); |
| 1005 | urb->iso_frame_desc[i].status = status; |
| 1006 | if (status) { |
| 1007 | urb->error_count++; |
| 1008 | ret = status; |
| 1009 | } |
| 1010 | |
| 1011 | i++; |
| 1012 | } |
| 1013 | |
| 1014 | return ret; |
| 1015 | } |
| 1016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | static int uhci_urb_enqueue(struct usb_hcd *hcd, |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1018 | struct usb_host_endpoint *hep, |
Al Viro | 55016f1 | 2005-10-21 03:21:58 -0400 | [diff] [blame] | 1019 | struct urb *urb, gfp_t mem_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
| 1021 | int ret; |
| 1022 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
| 1023 | unsigned long flags; |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1024 | struct urb_priv *urbp; |
| 1025 | struct uhci_qh *qh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | int bustime; |
| 1027 | |
| 1028 | spin_lock_irqsave(&uhci->lock, flags); |
| 1029 | |
| 1030 | ret = urb->status; |
| 1031 | if (ret != -EINPROGRESS) /* URB already unlinked! */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1032 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1034 | ret = -ENOMEM; |
| 1035 | urbp = uhci_alloc_urb_priv(uhci, urb); |
| 1036 | if (!urbp) |
| 1037 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1039 | if (hep->hcpriv) |
| 1040 | qh = (struct uhci_qh *) hep->hcpriv; |
| 1041 | else { |
| 1042 | qh = uhci_alloc_qh(uhci, urb->dev, hep); |
| 1043 | if (!qh) |
| 1044 | goto err_no_qh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1046 | urbp->qh = qh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 1048 | switch (qh->type) { |
| 1049 | case USB_ENDPOINT_XFER_CONTROL: |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1050 | ret = uhci_submit_control(uhci, urb, qh); |
| 1051 | break; |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 1052 | case USB_ENDPOINT_XFER_BULK: |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1053 | ret = uhci_submit_bulk(uhci, urb, qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | break; |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 1055 | case USB_ENDPOINT_XFER_INT: |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1056 | if (list_empty(&qh->queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | bustime = usb_check_bandwidth(urb->dev, urb); |
| 1058 | if (bustime < 0) |
| 1059 | ret = bustime; |
| 1060 | else { |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1061 | ret = uhci_submit_interrupt(uhci, urb, qh); |
| 1062 | if (ret == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | usb_claim_bandwidth(urb->dev, urb, bustime, 0); |
| 1064 | } |
| 1065 | } else { /* inherit from parent */ |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1066 | struct urb_priv *eurbp; |
| 1067 | |
| 1068 | eurbp = list_entry(qh->queue.prev, struct urb_priv, |
| 1069 | node); |
| 1070 | urb->bandwidth = eurbp->urb->bandwidth; |
| 1071 | ret = uhci_submit_interrupt(uhci, urb, qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | } |
| 1073 | break; |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 1074 | case USB_ENDPOINT_XFER_ISOC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | bustime = usb_check_bandwidth(urb->dev, urb); |
| 1076 | if (bustime < 0) { |
| 1077 | ret = bustime; |
| 1078 | break; |
| 1079 | } |
| 1080 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1081 | ret = uhci_submit_isochronous(uhci, urb, qh); |
| 1082 | if (ret == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | usb_claim_bandwidth(urb->dev, urb, bustime, 1); |
| 1084 | break; |
| 1085 | } |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1086 | if (ret != 0) |
| 1087 | goto err_submit_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1089 | /* Add this URB to the QH */ |
| 1090 | urbp->qh = qh; |
| 1091 | list_add_tail(&urbp->node, &qh->queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1093 | /* If the new URB is the first and only one on this QH then either |
| 1094 | * the QH is new and idle or else it's unlinked and waiting to |
Alan Stern | 2775562 | 2006-05-05 16:32:02 -0400 | [diff] [blame] | 1095 | * become idle, so we can activate it right away. But only if the |
| 1096 | * queue isn't stopped. */ |
| 1097 | if (qh->queue.next == &urbp->node && !qh->is_stopped) |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1098 | uhci_activate_qh(uhci, qh); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1099 | goto done; |
| 1100 | |
| 1101 | err_submit_failed: |
| 1102 | if (qh->state == QH_STATE_IDLE) |
| 1103 | uhci_make_qh_idle(uhci, qh); /* Reclaim unused QH */ |
| 1104 | |
| 1105 | err_no_qh: |
| 1106 | uhci_free_urb_priv(uhci, urbp); |
| 1107 | |
| 1108 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | spin_unlock_irqrestore(&uhci->lock, flags); |
| 1110 | return ret; |
| 1111 | } |
| 1112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) |
| 1114 | { |
| 1115 | struct uhci_hcd *uhci = hcd_to_uhci(hcd); |
| 1116 | unsigned long flags; |
| 1117 | struct urb_priv *urbp; |
| 1118 | |
| 1119 | spin_lock_irqsave(&uhci->lock, flags); |
| 1120 | urbp = urb->hcpriv; |
| 1121 | if (!urbp) /* URB was never linked! */ |
| 1122 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1124 | /* Remove Isochronous TDs from the frame list ASAP */ |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 1125 | if (urbp->qh->type == USB_ENDPOINT_XFER_ISOC) |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1126 | uhci_unlink_isochronous_tds(uhci, urb); |
| 1127 | uhci_unlink_qh(uhci, urbp->qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
| 1129 | done: |
| 1130 | spin_unlock_irqrestore(&uhci->lock, flags); |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1134 | /* |
| 1135 | * Finish unlinking an URB and give it back |
| 1136 | */ |
| 1137 | static void uhci_giveback_urb(struct uhci_hcd *uhci, struct uhci_qh *qh, |
| 1138 | struct urb *urb, struct pt_regs *regs) |
| 1139 | __releases(uhci->lock) |
| 1140 | __acquires(uhci->lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | { |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1142 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1144 | /* Isochronous TDs get unlinked directly from the frame list */ |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 1145 | if (qh->type == USB_ENDPOINT_XFER_ISOC) |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1146 | uhci_unlink_isochronous_tds(uhci, urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1148 | /* Take the URB off the QH's queue. If the queue is now empty, |
| 1149 | * this is a perfect time for a toggle fixup. */ |
| 1150 | list_del_init(&urbp->node); |
| 1151 | if (list_empty(&qh->queue) && qh->needs_fixup) { |
| 1152 | usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), |
| 1153 | usb_pipeout(urb->pipe), qh->initial_toggle); |
| 1154 | qh->needs_fixup = 0; |
| 1155 | } |
| 1156 | |
| 1157 | uhci_dec_fsbr(uhci, urb); /* Safe since it checks */ |
| 1158 | uhci_free_urb_priv(uhci, urbp); |
| 1159 | |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 1160 | switch (qh->type) { |
| 1161 | case USB_ENDPOINT_XFER_ISOC: |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1162 | /* Release bandwidth for Interrupt or Isoc. transfers */ |
| 1163 | if (urb->bandwidth) |
| 1164 | usb_release_bandwidth(urb->dev, urb, 1); |
| 1165 | break; |
Alan Stern | 4de7d2c | 2006-05-05 16:26:58 -0400 | [diff] [blame] | 1166 | case USB_ENDPOINT_XFER_INT: |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1167 | /* Release bandwidth for Interrupt or Isoc. transfers */ |
| 1168 | /* Make sure we don't release if we have a queued URB */ |
| 1169 | if (list_empty(&qh->queue) && urb->bandwidth) |
| 1170 | usb_release_bandwidth(urb->dev, urb, 0); |
| 1171 | else |
| 1172 | /* bandwidth was passed on to queued URB, */ |
| 1173 | /* so don't let usb_unlink_urb() release it */ |
| 1174 | urb->bandwidth = 0; |
| 1175 | break; |
| 1176 | } |
| 1177 | |
| 1178 | spin_unlock(&uhci->lock); |
| 1179 | usb_hcd_giveback_urb(uhci_to_hcd(uhci), urb, regs); |
| 1180 | spin_lock(&uhci->lock); |
| 1181 | |
| 1182 | /* If the queue is now empty, we can unlink the QH and give up its |
| 1183 | * reserved bandwidth. */ |
| 1184 | if (list_empty(&qh->queue)) { |
| 1185 | uhci_unlink_qh(uhci, qh); |
| 1186 | |
| 1187 | /* Bandwidth stuff not yet implemented */ |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | /* |
| 1192 | * Scan the URBs in a QH's queue |
| 1193 | */ |
| 1194 | #define QH_FINISHED_UNLINKING(qh) \ |
| 1195 | (qh->state == QH_STATE_UNLINKING && \ |
| 1196 | uhci->frame_number + uhci->is_stopped != qh->unlink_frame) |
| 1197 | |
| 1198 | static void uhci_scan_qh(struct uhci_hcd *uhci, struct uhci_qh *qh, |
| 1199 | struct pt_regs *regs) |
| 1200 | { |
| 1201 | struct urb_priv *urbp; |
| 1202 | struct urb *urb; |
| 1203 | int status; |
| 1204 | |
| 1205 | while (!list_empty(&qh->queue)) { |
| 1206 | urbp = list_entry(qh->queue.next, struct urb_priv, node); |
| 1207 | urb = urbp->urb; |
| 1208 | |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 1209 | if (qh->type == USB_ENDPOINT_XFER_ISOC) |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1210 | status = uhci_result_isochronous(uhci, urb); |
Alan Stern | b186900 | 2006-05-12 11:14:25 -0400 | [diff] [blame] | 1211 | else |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1212 | status = uhci_result_common(uhci, urb); |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1213 | if (status == -EINPROGRESS) |
| 1214 | break; |
| 1215 | |
| 1216 | spin_lock(&urb->lock); |
| 1217 | if (urb->status == -EINPROGRESS) /* Not dequeued */ |
| 1218 | urb->status = status; |
| 1219 | else |
Alan Stern | 2775562 | 2006-05-05 16:32:02 -0400 | [diff] [blame] | 1220 | status = ECONNRESET; /* Not -ECONNRESET */ |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1221 | spin_unlock(&urb->lock); |
| 1222 | |
| 1223 | /* Dequeued but completed URBs can't be given back unless |
| 1224 | * the QH is stopped or has finished unlinking. */ |
Alan Stern | 2775562 | 2006-05-05 16:32:02 -0400 | [diff] [blame] | 1225 | if (status == ECONNRESET) { |
| 1226 | if (QH_FINISHED_UNLINKING(qh)) |
| 1227 | qh->is_stopped = 1; |
| 1228 | else if (!qh->is_stopped) |
| 1229 | return; |
| 1230 | } |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1231 | |
| 1232 | uhci_giveback_urb(uhci, qh, urb, regs); |
Alan Stern | 2775562 | 2006-05-05 16:32:02 -0400 | [diff] [blame] | 1233 | if (status < 0) |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1234 | break; |
| 1235 | } |
| 1236 | |
| 1237 | /* If the QH is neither stopped nor finished unlinking (normal case), |
| 1238 | * our work here is done. */ |
Alan Stern | 2775562 | 2006-05-05 16:32:02 -0400 | [diff] [blame] | 1239 | if (QH_FINISHED_UNLINKING(qh)) |
| 1240 | qh->is_stopped = 1; |
| 1241 | else if (!qh->is_stopped) |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1242 | return; |
| 1243 | |
| 1244 | /* Otherwise give back each of the dequeued URBs */ |
Alan Stern | 2775562 | 2006-05-05 16:32:02 -0400 | [diff] [blame] | 1245 | restart: |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1246 | list_for_each_entry(urbp, &qh->queue, node) { |
| 1247 | urb = urbp->urb; |
| 1248 | if (urb->status != -EINPROGRESS) { |
Alan Stern | a0b458b | 2006-05-12 11:23:19 -0400 | [diff] [blame^] | 1249 | uhci_cleanup_queue(qh, urb); |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1250 | uhci_giveback_urb(uhci, qh, urb, regs); |
| 1251 | goto restart; |
| 1252 | } |
| 1253 | } |
| 1254 | qh->is_stopped = 0; |
| 1255 | |
| 1256 | /* There are no more dequeued URBs. If there are still URBs on the |
| 1257 | * queue, the QH can now be re-activated. */ |
| 1258 | if (!list_empty(&qh->queue)) { |
| 1259 | if (qh->needs_fixup) |
| 1260 | uhci_fixup_toggles(qh, 0); |
| 1261 | uhci_activate_qh(uhci, qh); |
| 1262 | } |
| 1263 | |
| 1264 | /* The queue is empty. The QH can become idle if it is fully |
| 1265 | * unlinked. */ |
| 1266 | else if (QH_FINISHED_UNLINKING(qh)) |
| 1267 | uhci_make_qh_idle(uhci, qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | static void uhci_free_pending_tds(struct uhci_hcd *uhci) |
| 1271 | { |
| 1272 | struct uhci_td *td, *tmp; |
| 1273 | |
| 1274 | list_for_each_entry_safe(td, tmp, &uhci->td_remove_list, remove_list) { |
| 1275 | list_del_init(&td->remove_list); |
| 1276 | |
| 1277 | uhci_free_td(uhci, td); |
| 1278 | } |
| 1279 | } |
| 1280 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1281 | /* |
| 1282 | * Process events in the schedule, but only in one thread at a time |
| 1283 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | static void uhci_scan_schedule(struct uhci_hcd *uhci, struct pt_regs *regs) |
| 1285 | { |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1286 | int i; |
| 1287 | struct uhci_qh *qh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
| 1289 | /* Don't allow re-entrant calls */ |
| 1290 | if (uhci->scan_in_progress) { |
| 1291 | uhci->need_rescan = 1; |
| 1292 | return; |
| 1293 | } |
| 1294 | uhci->scan_in_progress = 1; |
| 1295 | rescan: |
| 1296 | uhci->need_rescan = 0; |
| 1297 | |
Alan Stern | 6c1b445 | 2005-04-21 16:04:58 -0400 | [diff] [blame] | 1298 | uhci_clear_next_interrupt(uhci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | uhci_get_current_frame_number(uhci); |
| 1300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | if (uhci->frame_number + uhci->is_stopped != uhci->td_remove_age) |
| 1302 | uhci_free_pending_tds(uhci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1304 | /* Go through all the QH queues and process the URBs in each one */ |
| 1305 | for (i = 0; i < UHCI_NUM_SKELQH - 1; ++i) { |
| 1306 | uhci->next_qh = list_entry(uhci->skelqh[i]->node.next, |
| 1307 | struct uhci_qh, node); |
| 1308 | while ((qh = uhci->next_qh) != uhci->skelqh[i]) { |
| 1309 | uhci->next_qh = list_entry(qh->node.next, |
| 1310 | struct uhci_qh, node); |
| 1311 | uhci_scan_qh(uhci, qh, regs); |
| 1312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
| 1315 | if (uhci->need_rescan) |
| 1316 | goto rescan; |
| 1317 | uhci->scan_in_progress = 0; |
| 1318 | |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1319 | /* If the controller is stopped, we can finish these off right now */ |
| 1320 | if (uhci->is_stopped) |
| 1321 | uhci_free_pending_tds(uhci); |
Alan Stern | dccf4a4 | 2005-12-17 17:58:46 -0500 | [diff] [blame] | 1322 | |
| 1323 | if (list_empty(&uhci->td_remove_list) && |
| 1324 | list_empty(&uhci->skel_unlink_qh->node)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | uhci_clear_next_interrupt(uhci); |
| 1326 | else |
| 1327 | uhci_set_next_interrupt(uhci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | } |
Alan Stern | f5946f8 | 2005-04-09 17:26:00 -0400 | [diff] [blame] | 1329 | |
| 1330 | static void check_fsbr(struct uhci_hcd *uhci) |
| 1331 | { |
Alan Stern | 0ed8fee | 2005-12-17 18:02:38 -0500 | [diff] [blame] | 1332 | /* For now, don't scan URBs for FSBR timeouts. |
| 1333 | * Add it back in later... */ |
Alan Stern | f5946f8 | 2005-04-09 17:26:00 -0400 | [diff] [blame] | 1334 | |
| 1335 | /* Really disable FSBR */ |
| 1336 | if (!uhci->fsbr && uhci->fsbrtimeout && time_after_eq(jiffies, uhci->fsbrtimeout)) { |
| 1337 | uhci->fsbrtimeout = 0; |
| 1338 | uhci->skel_term_qh->link = UHCI_PTR_TERM; |
| 1339 | } |
| 1340 | } |