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