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