ohci-q.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. *
  7. * This file is licenced under the GPL.
  8. */
  9. #include <linux/irq.h>
  10. #include <linux/slab.h>
  11. static void urb_free_priv (struct ohci_hcd *hc, urb_priv_t *urb_priv)
  12. {
  13. int last = urb_priv->length - 1;
  14. if (last >= 0) {
  15. int i;
  16. struct td *td;
  17. for (i = 0; i <= last; i++) {
  18. td = urb_priv->td [i];
  19. if (td)
  20. td_free (hc, td);
  21. }
  22. }
  23. list_del (&urb_priv->pending);
  24. kfree (urb_priv);
  25. }
  26. /*-------------------------------------------------------------------------*/
  27. /*
  28. * URB goes back to driver, and isn't reissued.
  29. * It's completely gone from HC data structures.
  30. * PRECONDITION: ohci lock held, irqs blocked.
  31. */
  32. static void
  33. finish_urb(struct ohci_hcd *ohci, struct urb *urb, int status)
  34. __releases(ohci->lock)
  35. __acquires(ohci->lock)
  36. {
  37. struct device *dev = ohci_to_hcd(ohci)->self.controller;
  38. struct usb_host_endpoint *ep = urb->ep;
  39. struct urb_priv *urb_priv;
  40. // ASSERT (urb->hcpriv != 0);
  41. restart:
  42. urb_free_priv (ohci, urb->hcpriv);
  43. urb->hcpriv = NULL;
  44. if (likely(status == -EINPROGRESS))
  45. status = 0;
  46. switch (usb_pipetype (urb->pipe)) {
  47. case PIPE_ISOCHRONOUS:
  48. ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--;
  49. if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
  50. if (quirk_amdiso(ohci))
  51. usb_amd_quirk_pll_enable();
  52. if (quirk_amdprefetch(ohci))
  53. sb800_prefetch(dev, 0);
  54. }
  55. break;
  56. case PIPE_INTERRUPT:
  57. ohci_to_hcd(ohci)->self.bandwidth_int_reqs--;
  58. break;
  59. }
  60. /* urb->complete() can reenter this HCD */
  61. usb_hcd_unlink_urb_from_ep(ohci_to_hcd(ohci), urb);
  62. spin_unlock (&ohci->lock);
  63. usb_hcd_giveback_urb(ohci_to_hcd(ohci), urb, status);
  64. spin_lock (&ohci->lock);
  65. /* stop periodic dma if it's not needed */
  66. if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0
  67. && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0) {
  68. ohci->hc_control &= ~(OHCI_CTRL_PLE|OHCI_CTRL_IE);
  69. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  70. }
  71. /*
  72. * An isochronous URB that is sumitted too late won't have any TDs
  73. * (marked by the fact that the td_cnt value is larger than the
  74. * actual number of TDs). If the next URB on this endpoint is like
  75. * that, give it back now.
  76. */
  77. if (!list_empty(&ep->urb_list)) {
  78. urb = list_first_entry(&ep->urb_list, struct urb, urb_list);
  79. urb_priv = urb->hcpriv;
  80. if (urb_priv->td_cnt > urb_priv->length) {
  81. status = 0;
  82. goto restart;
  83. }
  84. }
  85. }
  86. /*-------------------------------------------------------------------------*
  87. * ED handling functions
  88. *-------------------------------------------------------------------------*/
  89. /* search for the right schedule branch to use for a periodic ed.
  90. * does some load balancing; returns the branch, or negative errno.
  91. */
  92. static int balance (struct ohci_hcd *ohci, int interval, int load)
  93. {
  94. int i, branch = -ENOSPC;
  95. /* iso periods can be huge; iso tds specify frame numbers */
  96. if (interval > NUM_INTS)
  97. interval = NUM_INTS;
  98. /* search for the least loaded schedule branch of that period
  99. * that has enough bandwidth left unreserved.
  100. */
  101. for (i = 0; i < interval ; i++) {
  102. if (branch < 0 || ohci->load [branch] > ohci->load [i]) {
  103. int j;
  104. /* usb 1.1 says 90% of one frame */
  105. for (j = i; j < NUM_INTS; j += interval) {
  106. if ((ohci->load [j] + load) > 900)
  107. break;
  108. }
  109. if (j < NUM_INTS)
  110. continue;
  111. branch = i;
  112. }
  113. }
  114. return branch;
  115. }
  116. /*-------------------------------------------------------------------------*/
  117. /* both iso and interrupt requests have periods; this routine puts them
  118. * into the schedule tree in the apppropriate place. most iso devices use
  119. * 1msec periods, but that's not required.
  120. */
  121. static void periodic_link (struct ohci_hcd *ohci, struct ed *ed)
  122. {
  123. unsigned i;
  124. ohci_dbg(ohci, "link %sed %p branch %d [%dus.], interval %d\n",
  125. (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "",
  126. ed, ed->branch, ed->load, ed->interval);
  127. for (i = ed->branch; i < NUM_INTS; i += ed->interval) {
  128. struct ed **prev = &ohci->periodic [i];
  129. __hc32 *prev_p = &ohci->hcca->int_table [i];
  130. struct ed *here = *prev;
  131. /* sorting each branch by period (slow before fast)
  132. * lets us share the faster parts of the tree.
  133. * (plus maybe: put interrupt eds before iso)
  134. */
  135. while (here && ed != here) {
  136. if (ed->interval > here->interval)
  137. break;
  138. prev = &here->ed_next;
  139. prev_p = &here->hwNextED;
  140. here = *prev;
  141. }
  142. if (ed != here) {
  143. ed->ed_next = here;
  144. if (here)
  145. ed->hwNextED = *prev_p;
  146. wmb ();
  147. *prev = ed;
  148. *prev_p = cpu_to_hc32(ohci, ed->dma);
  149. wmb();
  150. }
  151. ohci->load [i] += ed->load;
  152. }
  153. ohci_to_hcd(ohci)->self.bandwidth_allocated += ed->load / ed->interval;
  154. }
  155. /* link an ed into one of the HC chains */
  156. static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
  157. {
  158. int branch;
  159. ed->ed_prev = NULL;
  160. ed->ed_next = NULL;
  161. ed->hwNextED = 0;
  162. wmb ();
  163. /* we care about rm_list when setting CLE/BLE in case the HC was at
  164. * work on some TD when CLE/BLE was turned off, and isn't quiesced
  165. * yet. finish_unlinks() restarts as needed, some upcoming INTR_SF.
  166. *
  167. * control and bulk EDs are doubly linked (ed_next, ed_prev), but
  168. * periodic ones are singly linked (ed_next). that's because the
  169. * periodic schedule encodes a tree like figure 3-5 in the ohci
  170. * spec: each qh can have several "previous" nodes, and the tree
  171. * doesn't have unused/idle descriptors.
  172. */
  173. switch (ed->type) {
  174. case PIPE_CONTROL:
  175. if (ohci->ed_controltail == NULL) {
  176. WARN_ON (ohci->hc_control & OHCI_CTRL_CLE);
  177. ohci_writel (ohci, ed->dma,
  178. &ohci->regs->ed_controlhead);
  179. } else {
  180. ohci->ed_controltail->ed_next = ed;
  181. ohci->ed_controltail->hwNextED = cpu_to_hc32 (ohci,
  182. ed->dma);
  183. }
  184. ed->ed_prev = ohci->ed_controltail;
  185. if (!ohci->ed_controltail && !ohci->ed_rm_list) {
  186. wmb();
  187. ohci->hc_control |= OHCI_CTRL_CLE;
  188. ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent);
  189. ohci_writel (ohci, ohci->hc_control,
  190. &ohci->regs->control);
  191. }
  192. ohci->ed_controltail = ed;
  193. break;
  194. case PIPE_BULK:
  195. if (ohci->ed_bulktail == NULL) {
  196. WARN_ON (ohci->hc_control & OHCI_CTRL_BLE);
  197. ohci_writel (ohci, ed->dma, &ohci->regs->ed_bulkhead);
  198. } else {
  199. ohci->ed_bulktail->ed_next = ed;
  200. ohci->ed_bulktail->hwNextED = cpu_to_hc32 (ohci,
  201. ed->dma);
  202. }
  203. ed->ed_prev = ohci->ed_bulktail;
  204. if (!ohci->ed_bulktail && !ohci->ed_rm_list) {
  205. wmb();
  206. ohci->hc_control |= OHCI_CTRL_BLE;
  207. ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent);
  208. ohci_writel (ohci, ohci->hc_control,
  209. &ohci->regs->control);
  210. }
  211. ohci->ed_bulktail = ed;
  212. break;
  213. // case PIPE_INTERRUPT:
  214. // case PIPE_ISOCHRONOUS:
  215. default:
  216. branch = balance (ohci, ed->interval, ed->load);
  217. if (branch < 0) {
  218. ohci_dbg (ohci,
  219. "ERR %d, interval %d msecs, load %d\n",
  220. branch, ed->interval, ed->load);
  221. // FIXME if there are TDs queued, fail them!
  222. return branch;
  223. }
  224. ed->branch = branch;
  225. periodic_link (ohci, ed);
  226. }
  227. /* the HC may not see the schedule updates yet, but if it does
  228. * then they'll be properly ordered.
  229. */
  230. ed->state = ED_OPER;
  231. return 0;
  232. }
  233. /*-------------------------------------------------------------------------*/
  234. /* scan the periodic table to find and unlink this ED */
  235. static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
  236. {
  237. int i;
  238. for (i = ed->branch; i < NUM_INTS; i += ed->interval) {
  239. struct ed *temp;
  240. struct ed **prev = &ohci->periodic [i];
  241. __hc32 *prev_p = &ohci->hcca->int_table [i];
  242. while (*prev && (temp = *prev) != ed) {
  243. prev_p = &temp->hwNextED;
  244. prev = &temp->ed_next;
  245. }
  246. if (*prev) {
  247. *prev_p = ed->hwNextED;
  248. *prev = ed->ed_next;
  249. }
  250. ohci->load [i] -= ed->load;
  251. }
  252. ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval;
  253. ohci_dbg(ohci, "unlink %sed %p branch %d [%dus.], interval %d\n",
  254. (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "",
  255. ed, ed->branch, ed->load, ed->interval);
  256. }
  257. /* unlink an ed from one of the HC chains.
  258. * just the link to the ed is unlinked.
  259. * the link from the ed still points to another operational ed or 0
  260. * so the HC can eventually finish the processing of the unlinked ed
  261. * (assuming it already started that, which needn't be true).
  262. *
  263. * ED_UNLINK is a transient state: the HC may still see this ED, but soon
  264. * it won't. ED_SKIP means the HC will finish its current transaction,
  265. * but won't start anything new. The TD queue may still grow; device
  266. * drivers don't know about this HCD-internal state.
  267. *
  268. * When the HC can't see the ED, something changes ED_UNLINK to one of:
  269. *
  270. * - ED_OPER: when there's any request queued, the ED gets rescheduled
  271. * immediately. HC should be working on them.
  272. *
  273. * - ED_IDLE: when there's no TD queue or the HC isn't running.
  274. *
  275. * When finish_unlinks() runs later, after SOF interrupt, it will often
  276. * complete one or more URB unlinks before making that state change.
  277. */
  278. static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed)
  279. {
  280. ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
  281. wmb ();
  282. ed->state = ED_UNLINK;
  283. /* To deschedule something from the control or bulk list, just
  284. * clear CLE/BLE and wait. There's no safe way to scrub out list
  285. * head/current registers until later, and "later" isn't very
  286. * tightly specified. Figure 6-5 and Section 6.4.2.2 show how
  287. * the HC is reading the ED queues (while we modify them).
  288. *
  289. * For now, ed_schedule() is "later". It might be good paranoia
  290. * to scrub those registers in finish_unlinks(), in case of bugs
  291. * that make the HC try to use them.
  292. */
  293. switch (ed->type) {
  294. case PIPE_CONTROL:
  295. /* remove ED from the HC's list: */
  296. if (ed->ed_prev == NULL) {
  297. if (!ed->hwNextED) {
  298. ohci->hc_control &= ~OHCI_CTRL_CLE;
  299. ohci_writel (ohci, ohci->hc_control,
  300. &ohci->regs->control);
  301. // a ohci_readl() later syncs CLE with the HC
  302. } else
  303. ohci_writel (ohci,
  304. hc32_to_cpup (ohci, &ed->hwNextED),
  305. &ohci->regs->ed_controlhead);
  306. } else {
  307. ed->ed_prev->ed_next = ed->ed_next;
  308. ed->ed_prev->hwNextED = ed->hwNextED;
  309. }
  310. /* remove ED from the HCD's list: */
  311. if (ohci->ed_controltail == ed) {
  312. ohci->ed_controltail = ed->ed_prev;
  313. if (ohci->ed_controltail)
  314. ohci->ed_controltail->ed_next = NULL;
  315. } else if (ed->ed_next) {
  316. ed->ed_next->ed_prev = ed->ed_prev;
  317. }
  318. break;
  319. case PIPE_BULK:
  320. /* remove ED from the HC's list: */
  321. if (ed->ed_prev == NULL) {
  322. if (!ed->hwNextED) {
  323. ohci->hc_control &= ~OHCI_CTRL_BLE;
  324. ohci_writel (ohci, ohci->hc_control,
  325. &ohci->regs->control);
  326. // a ohci_readl() later syncs BLE with the HC
  327. } else
  328. ohci_writel (ohci,
  329. hc32_to_cpup (ohci, &ed->hwNextED),
  330. &ohci->regs->ed_bulkhead);
  331. } else {
  332. ed->ed_prev->ed_next = ed->ed_next;
  333. ed->ed_prev->hwNextED = ed->hwNextED;
  334. }
  335. /* remove ED from the HCD's list: */
  336. if (ohci->ed_bulktail == ed) {
  337. ohci->ed_bulktail = ed->ed_prev;
  338. if (ohci->ed_bulktail)
  339. ohci->ed_bulktail->ed_next = NULL;
  340. } else if (ed->ed_next) {
  341. ed->ed_next->ed_prev = ed->ed_prev;
  342. }
  343. break;
  344. // case PIPE_INTERRUPT:
  345. // case PIPE_ISOCHRONOUS:
  346. default:
  347. periodic_unlink (ohci, ed);
  348. break;
  349. }
  350. }
  351. /*-------------------------------------------------------------------------*/
  352. /* get and maybe (re)init an endpoint. init _should_ be done only as part
  353. * of enumeration, usb_set_configuration() or usb_set_interface().
  354. */
  355. static struct ed *ed_get (
  356. struct ohci_hcd *ohci,
  357. struct usb_host_endpoint *ep,
  358. struct usb_device *udev,
  359. unsigned int pipe,
  360. int interval
  361. ) {
  362. struct ed *ed;
  363. unsigned long flags;
  364. spin_lock_irqsave (&ohci->lock, flags);
  365. ed = ep->hcpriv;
  366. if (!ed) {
  367. struct td *td;
  368. int is_out;
  369. u32 info;
  370. ed = ed_alloc (ohci, GFP_ATOMIC);
  371. if (!ed) {
  372. /* out of memory */
  373. goto done;
  374. }
  375. /* dummy td; end of td list for ed */
  376. td = td_alloc (ohci, GFP_ATOMIC);
  377. if (!td) {
  378. /* out of memory */
  379. ed_free (ohci, ed);
  380. ed = NULL;
  381. goto done;
  382. }
  383. ed->dummy = td;
  384. ed->hwTailP = cpu_to_hc32 (ohci, td->td_dma);
  385. ed->hwHeadP = ed->hwTailP; /* ED_C, ED_H zeroed */
  386. ed->state = ED_IDLE;
  387. is_out = !(ep->desc.bEndpointAddress & USB_DIR_IN);
  388. /* FIXME usbcore changes dev->devnum before SET_ADDRESS
  389. * succeeds ... otherwise we wouldn't need "pipe".
  390. */
  391. info = usb_pipedevice (pipe);
  392. ed->type = usb_pipetype(pipe);
  393. info |= (ep->desc.bEndpointAddress & ~USB_DIR_IN) << 7;
  394. info |= usb_endpoint_maxp(&ep->desc) << 16;
  395. if (udev->speed == USB_SPEED_LOW)
  396. info |= ED_LOWSPEED;
  397. /* only control transfers store pids in tds */
  398. if (ed->type != PIPE_CONTROL) {
  399. info |= is_out ? ED_OUT : ED_IN;
  400. if (ed->type != PIPE_BULK) {
  401. /* periodic transfers... */
  402. if (ed->type == PIPE_ISOCHRONOUS)
  403. info |= ED_ISO;
  404. else if (interval > 32) /* iso can be bigger */
  405. interval = 32;
  406. ed->interval = interval;
  407. ed->load = usb_calc_bus_time (
  408. udev->speed, !is_out,
  409. ed->type == PIPE_ISOCHRONOUS,
  410. usb_endpoint_maxp(&ep->desc))
  411. / 1000;
  412. }
  413. }
  414. ed->hwINFO = cpu_to_hc32(ohci, info);
  415. ep->hcpriv = ed;
  416. }
  417. done:
  418. spin_unlock_irqrestore (&ohci->lock, flags);
  419. return ed;
  420. }
  421. /*-------------------------------------------------------------------------*/
  422. /* request unlinking of an endpoint from an operational HC.
  423. * put the ep on the rm_list
  424. * real work is done at the next start frame (SF) hardware interrupt
  425. * caller guarantees HCD is running, so hardware access is safe,
  426. * and that ed->state is ED_OPER
  427. */
  428. static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed)
  429. {
  430. ed->hwINFO |= cpu_to_hc32 (ohci, ED_DEQUEUE);
  431. ed_deschedule (ohci, ed);
  432. /* rm_list is just singly linked, for simplicity */
  433. ed->ed_next = ohci->ed_rm_list;
  434. ed->ed_prev = NULL;
  435. ohci->ed_rm_list = ed;
  436. /* enable SOF interrupt */
  437. ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus);
  438. ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
  439. // flush those writes, and get latest HCCA contents
  440. (void) ohci_readl (ohci, &ohci->regs->control);
  441. /* SF interrupt might get delayed; record the frame counter value that
  442. * indicates when the HC isn't looking at it, so concurrent unlinks
  443. * behave. frame_no wraps every 2^16 msec, and changes right before
  444. * SF is triggered.
  445. */
  446. ed->tick = ohci_frame_no(ohci) + 1;
  447. }
  448. /*-------------------------------------------------------------------------*
  449. * TD handling functions
  450. *-------------------------------------------------------------------------*/
  451. /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
  452. static void
  453. td_fill (struct ohci_hcd *ohci, u32 info,
  454. dma_addr_t data, int len,
  455. struct urb *urb, int index)
  456. {
  457. struct td *td, *td_pt;
  458. struct urb_priv *urb_priv = urb->hcpriv;
  459. int is_iso = info & TD_ISO;
  460. int hash;
  461. // ASSERT (index < urb_priv->length);
  462. /* aim for only one interrupt per urb. mostly applies to control
  463. * and iso; other urbs rarely need more than one TD per urb.
  464. * this way, only final tds (or ones with an error) cause IRQs.
  465. * at least immediately; use DI=6 in case any control request is
  466. * tempted to die part way through. (and to force the hc to flush
  467. * its donelist soonish, even on unlink paths.)
  468. *
  469. * NOTE: could delay interrupts even for the last TD, and get fewer
  470. * interrupts ... increasing per-urb latency by sharing interrupts.
  471. * Drivers that queue bulk urbs may request that behavior.
  472. */
  473. if (index != (urb_priv->length - 1)
  474. || (urb->transfer_flags & URB_NO_INTERRUPT))
  475. info |= TD_DI_SET (6);
  476. /* use this td as the next dummy */
  477. td_pt = urb_priv->td [index];
  478. /* fill the old dummy TD */
  479. td = urb_priv->td [index] = urb_priv->ed->dummy;
  480. urb_priv->ed->dummy = td_pt;
  481. td->ed = urb_priv->ed;
  482. td->next_dl_td = NULL;
  483. td->index = index;
  484. td->urb = urb;
  485. td->data_dma = data;
  486. if (!len)
  487. data = 0;
  488. td->hwINFO = cpu_to_hc32 (ohci, info);
  489. if (is_iso) {
  490. td->hwCBP = cpu_to_hc32 (ohci, data & 0xFFFFF000);
  491. *ohci_hwPSWp(ohci, td, 0) = cpu_to_hc16 (ohci,
  492. (data & 0x0FFF) | 0xE000);
  493. } else {
  494. td->hwCBP = cpu_to_hc32 (ohci, data);
  495. }
  496. if (data)
  497. td->hwBE = cpu_to_hc32 (ohci, data + len - 1);
  498. else
  499. td->hwBE = 0;
  500. td->hwNextTD = cpu_to_hc32 (ohci, td_pt->td_dma);
  501. /* append to queue */
  502. list_add_tail (&td->td_list, &td->ed->td_list);
  503. /* hash it for later reverse mapping */
  504. hash = TD_HASH_FUNC (td->td_dma);
  505. td->td_hash = ohci->td_hash [hash];
  506. ohci->td_hash [hash] = td;
  507. /* HC might read the TD (or cachelines) right away ... */
  508. wmb ();
  509. td->ed->hwTailP = td->hwNextTD;
  510. }
  511. /*-------------------------------------------------------------------------*/
  512. /* Prepare all TDs of a transfer, and queue them onto the ED.
  513. * Caller guarantees HC is active.
  514. * Usually the ED is already on the schedule, so TDs might be
  515. * processed as soon as they're queued.
  516. */
  517. static void td_submit_urb (
  518. struct ohci_hcd *ohci,
  519. struct urb *urb
  520. ) {
  521. struct urb_priv *urb_priv = urb->hcpriv;
  522. struct device *dev = ohci_to_hcd(ohci)->self.controller;
  523. dma_addr_t data;
  524. int data_len = urb->transfer_buffer_length;
  525. int cnt = 0;
  526. u32 info = 0;
  527. int is_out = usb_pipeout (urb->pipe);
  528. int periodic = 0;
  529. int i, this_sg_len, n;
  530. struct scatterlist *sg;
  531. /* OHCI handles the bulk/interrupt data toggles itself. We just
  532. * use the device toggle bits for resetting, and rely on the fact
  533. * that resetting toggle is meaningless if the endpoint is active.
  534. */
  535. if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
  536. usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
  537. is_out, 1);
  538. urb_priv->ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_C);
  539. }
  540. list_add (&urb_priv->pending, &ohci->pending);
  541. i = urb->num_mapped_sgs;
  542. if (data_len > 0 && i > 0) {
  543. sg = urb->sg;
  544. data = sg_dma_address(sg);
  545. /*
  546. * urb->transfer_buffer_length may be smaller than the
  547. * size of the scatterlist (or vice versa)
  548. */
  549. this_sg_len = min_t(int, sg_dma_len(sg), data_len);
  550. } else {
  551. sg = NULL;
  552. if (data_len)
  553. data = urb->transfer_dma;
  554. else
  555. data = 0;
  556. this_sg_len = data_len;
  557. }
  558. /* NOTE: TD_CC is set so we can tell which TDs the HC processed by
  559. * using TD_CC_GET, as well as by seeing them on the done list.
  560. * (CC = NotAccessed ... 0x0F, or 0x0E in PSWs for ISO.)
  561. */
  562. switch (urb_priv->ed->type) {
  563. /* Bulk and interrupt are identical except for where in the schedule
  564. * their EDs live.
  565. */
  566. case PIPE_INTERRUPT:
  567. /* ... and periodic urbs have extra accounting */
  568. periodic = ohci_to_hcd(ohci)->self.bandwidth_int_reqs++ == 0
  569. && ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0;
  570. /* FALLTHROUGH */
  571. case PIPE_BULK:
  572. info = is_out
  573. ? TD_T_TOGGLE | TD_CC | TD_DP_OUT
  574. : TD_T_TOGGLE | TD_CC | TD_DP_IN;
  575. /* TDs _could_ transfer up to 8K each */
  576. for (;;) {
  577. n = min(this_sg_len, 4096);
  578. /* maybe avoid ED halt on final TD short read */
  579. if (n >= data_len || (i == 1 && n >= this_sg_len)) {
  580. if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
  581. info |= TD_R;
  582. }
  583. td_fill(ohci, info, data, n, urb, cnt);
  584. this_sg_len -= n;
  585. data_len -= n;
  586. data += n;
  587. cnt++;
  588. if (this_sg_len <= 0) {
  589. if (--i <= 0 || data_len <= 0)
  590. break;
  591. sg = sg_next(sg);
  592. data = sg_dma_address(sg);
  593. this_sg_len = min_t(int, sg_dma_len(sg),
  594. data_len);
  595. }
  596. }
  597. if ((urb->transfer_flags & URB_ZERO_PACKET)
  598. && cnt < urb_priv->length) {
  599. td_fill (ohci, info, 0, 0, urb, cnt);
  600. cnt++;
  601. }
  602. /* maybe kickstart bulk list */
  603. if (urb_priv->ed->type == PIPE_BULK) {
  604. wmb ();
  605. ohci_writel (ohci, OHCI_BLF, &ohci->regs->cmdstatus);
  606. }
  607. break;
  608. /* control manages DATA0/DATA1 toggle per-request; SETUP resets it,
  609. * any DATA phase works normally, and the STATUS ack is special.
  610. */
  611. case PIPE_CONTROL:
  612. info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
  613. td_fill (ohci, info, urb->setup_dma, 8, urb, cnt++);
  614. if (data_len > 0) {
  615. info = TD_CC | TD_R | TD_T_DATA1;
  616. info |= is_out ? TD_DP_OUT : TD_DP_IN;
  617. /* NOTE: mishandles transfers >8K, some >4K */
  618. td_fill (ohci, info, data, data_len, urb, cnt++);
  619. }
  620. info = (is_out || data_len == 0)
  621. ? TD_CC | TD_DP_IN | TD_T_DATA1
  622. : TD_CC | TD_DP_OUT | TD_T_DATA1;
  623. td_fill (ohci, info, data, 0, urb, cnt++);
  624. /* maybe kickstart control list */
  625. wmb ();
  626. ohci_writel (ohci, OHCI_CLF, &ohci->regs->cmdstatus);
  627. break;
  628. /* ISO has no retransmit, so no toggle; and it uses special TDs.
  629. * Each TD could handle multiple consecutive frames (interval 1);
  630. * we could often reduce the number of TDs here.
  631. */
  632. case PIPE_ISOCHRONOUS:
  633. for (cnt = urb_priv->td_cnt; cnt < urb->number_of_packets;
  634. cnt++) {
  635. int frame = urb->start_frame;
  636. // FIXME scheduling should handle frame counter
  637. // roll-around ... exotic case (and OHCI has
  638. // a 2^16 iso range, vs other HCs max of 2^10)
  639. frame += cnt * urb->interval;
  640. frame &= 0xffff;
  641. td_fill (ohci, TD_CC | TD_ISO | frame,
  642. data + urb->iso_frame_desc [cnt].offset,
  643. urb->iso_frame_desc [cnt].length, urb, cnt);
  644. }
  645. if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
  646. if (quirk_amdiso(ohci))
  647. usb_amd_quirk_pll_disable();
  648. if (quirk_amdprefetch(ohci))
  649. sb800_prefetch(dev, 1);
  650. }
  651. periodic = ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs++ == 0
  652. && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0;
  653. break;
  654. }
  655. /* start periodic dma if needed */
  656. if (periodic) {
  657. wmb ();
  658. ohci->hc_control |= OHCI_CTRL_PLE|OHCI_CTRL_IE;
  659. ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
  660. }
  661. // ASSERT (urb_priv->length == cnt);
  662. }
  663. /*-------------------------------------------------------------------------*
  664. * Done List handling functions
  665. *-------------------------------------------------------------------------*/
  666. /* calculate transfer length/status and update the urb */
  667. static int td_done(struct ohci_hcd *ohci, struct urb *urb, struct td *td)
  668. {
  669. u32 tdINFO = hc32_to_cpup (ohci, &td->hwINFO);
  670. int cc = 0;
  671. int status = -EINPROGRESS;
  672. list_del (&td->td_list);
  673. /* ISO ... drivers see per-TD length/status */
  674. if (tdINFO & TD_ISO) {
  675. u16 tdPSW = ohci_hwPSW(ohci, td, 0);
  676. int dlen = 0;
  677. /* NOTE: assumes FC in tdINFO == 0, and that
  678. * only the first of 0..MAXPSW psws is used.
  679. */
  680. cc = (tdPSW >> 12) & 0xF;
  681. if (tdINFO & TD_CC) /* hc didn't touch? */
  682. return status;
  683. if (usb_pipeout (urb->pipe))
  684. dlen = urb->iso_frame_desc [td->index].length;
  685. else {
  686. /* short reads are always OK for ISO */
  687. if (cc == TD_DATAUNDERRUN)
  688. cc = TD_CC_NOERROR;
  689. dlen = tdPSW & 0x3ff;
  690. }
  691. urb->actual_length += dlen;
  692. urb->iso_frame_desc [td->index].actual_length = dlen;
  693. urb->iso_frame_desc [td->index].status = cc_to_error [cc];
  694. if (cc != TD_CC_NOERROR)
  695. ohci_dbg(ohci,
  696. "urb %p iso td %p (%d) len %d cc %d\n",
  697. urb, td, 1 + td->index, dlen, cc);
  698. /* BULK, INT, CONTROL ... drivers see aggregate length/status,
  699. * except that "setup" bytes aren't counted and "short" transfers
  700. * might not be reported as errors.
  701. */
  702. } else {
  703. int type = usb_pipetype (urb->pipe);
  704. u32 tdBE = hc32_to_cpup (ohci, &td->hwBE);
  705. cc = TD_CC_GET (tdINFO);
  706. /* update packet status if needed (short is normally ok) */
  707. if (cc == TD_DATAUNDERRUN
  708. && !(urb->transfer_flags & URB_SHORT_NOT_OK))
  709. cc = TD_CC_NOERROR;
  710. if (cc != TD_CC_NOERROR && cc < 0x0E)
  711. status = cc_to_error[cc];
  712. /* count all non-empty packets except control SETUP packet */
  713. if ((type != PIPE_CONTROL || td->index != 0) && tdBE != 0) {
  714. if (td->hwCBP == 0)
  715. urb->actual_length += tdBE - td->data_dma + 1;
  716. else
  717. urb->actual_length +=
  718. hc32_to_cpup (ohci, &td->hwCBP)
  719. - td->data_dma;
  720. }
  721. if (cc != TD_CC_NOERROR && cc < 0x0E)
  722. ohci_dbg(ohci,
  723. "urb %p td %p (%d) cc %d, len=%d/%d\n",
  724. urb, td, 1 + td->index, cc,
  725. urb->actual_length,
  726. urb->transfer_buffer_length);
  727. }
  728. return status;
  729. }
  730. /*-------------------------------------------------------------------------*/
  731. static void ed_halted(struct ohci_hcd *ohci, struct td *td, int cc)
  732. {
  733. struct urb *urb = td->urb;
  734. urb_priv_t *urb_priv = urb->hcpriv;
  735. struct ed *ed = td->ed;
  736. struct list_head *tmp = td->td_list.next;
  737. __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C);
  738. /* clear ed halt; this is the td that caused it, but keep it inactive
  739. * until its urb->complete() has a chance to clean up.
  740. */
  741. ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
  742. wmb ();
  743. ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H);
  744. /* Get rid of all later tds from this urb. We don't have
  745. * to be careful: no errors and nothing was transferred.
  746. * Also patch the ed so it looks as if those tds completed normally.
  747. */
  748. while (tmp != &ed->td_list) {
  749. struct td *next;
  750. next = list_entry (tmp, struct td, td_list);
  751. tmp = next->td_list.next;
  752. if (next->urb != urb)
  753. break;
  754. /* NOTE: if multi-td control DATA segments get supported,
  755. * this urb had one of them, this td wasn't the last td
  756. * in that segment (TD_R clear), this ed halted because
  757. * of a short read, _and_ URB_SHORT_NOT_OK is clear ...
  758. * then we need to leave the control STATUS packet queued
  759. * and clear ED_SKIP.
  760. */
  761. list_del(&next->td_list);
  762. urb_priv->td_cnt++;
  763. ed->hwHeadP = next->hwNextTD | toggle;
  764. }
  765. /* help for troubleshooting: report anything that
  766. * looks odd ... that doesn't include protocol stalls
  767. * (or maybe some other things)
  768. */
  769. switch (cc) {
  770. case TD_DATAUNDERRUN:
  771. if ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)
  772. break;
  773. /* fallthrough */
  774. case TD_CC_STALL:
  775. if (usb_pipecontrol (urb->pipe))
  776. break;
  777. /* fallthrough */
  778. default:
  779. ohci_dbg (ohci,
  780. "urb %p path %s ep%d%s %08x cc %d --> status %d\n",
  781. urb, urb->dev->devpath,
  782. usb_pipeendpoint (urb->pipe),
  783. usb_pipein (urb->pipe) ? "in" : "out",
  784. hc32_to_cpu (ohci, td->hwINFO),
  785. cc, cc_to_error [cc]);
  786. }
  787. }
  788. /* Add a TD to the done list */
  789. static void add_to_done_list(struct ohci_hcd *ohci, struct td *td)
  790. {
  791. struct td *td2, *td_prev;
  792. struct ed *ed;
  793. if (td->next_dl_td)
  794. return; /* Already on the list */
  795. /* Add all the TDs going back until we reach one that's on the list */
  796. ed = td->ed;
  797. td2 = td_prev = td;
  798. list_for_each_entry_continue_reverse(td2, &ed->td_list, td_list) {
  799. if (td2->next_dl_td)
  800. break;
  801. td2->next_dl_td = td_prev;
  802. td_prev = td2;
  803. }
  804. if (ohci->dl_end)
  805. ohci->dl_end->next_dl_td = td_prev;
  806. else
  807. ohci->dl_start = td_prev;
  808. /*
  809. * Make td->next_dl_td point to td itself, to mark the fact
  810. * that td is on the done list.
  811. */
  812. ohci->dl_end = td->next_dl_td = td;
  813. /* Did we just add the latest pending TD? */
  814. td2 = ed->pending_td;
  815. if (td2 && td2->next_dl_td)
  816. ed->pending_td = NULL;
  817. }
  818. /* Get the entries on the hardware done queue and put them on our list */
  819. static void update_done_list(struct ohci_hcd *ohci)
  820. {
  821. u32 td_dma;
  822. struct td *td = NULL;
  823. td_dma = hc32_to_cpup (ohci, &ohci->hcca->done_head);
  824. ohci->hcca->done_head = 0;
  825. wmb();
  826. /* get TD from hc's singly linked list, and
  827. * add to ours. ed->td_list changes later.
  828. */
  829. while (td_dma) {
  830. int cc;
  831. td = dma_to_td (ohci, td_dma);
  832. if (!td) {
  833. ohci_err (ohci, "bad entry %8x\n", td_dma);
  834. break;
  835. }
  836. td->hwINFO |= cpu_to_hc32 (ohci, TD_DONE);
  837. cc = TD_CC_GET (hc32_to_cpup (ohci, &td->hwINFO));
  838. /* Non-iso endpoints can halt on error; un-halt,
  839. * and dequeue any other TDs from this urb.
  840. * No other TD could have caused the halt.
  841. */
  842. if (cc != TD_CC_NOERROR
  843. && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
  844. ed_halted(ohci, td, cc);
  845. td_dma = hc32_to_cpup (ohci, &td->hwNextTD);
  846. add_to_done_list(ohci, td);
  847. }
  848. }
  849. /*-------------------------------------------------------------------------*/
  850. /* there are some urbs/eds to unlink; called in_irq(), with HCD locked */
  851. static void finish_unlinks(struct ohci_hcd *ohci)
  852. {
  853. unsigned tick = ohci_frame_no(ohci);
  854. struct ed *ed, **last;
  855. rescan_all:
  856. for (last = &ohci->ed_rm_list, ed = *last; ed != NULL; ed = *last) {
  857. struct list_head *entry, *tmp;
  858. int completed, modified;
  859. __hc32 *prev;
  860. /* only take off EDs that the HC isn't using, accounting for
  861. * frame counter wraps and EDs with partially retired TDs
  862. */
  863. if (likely(ohci->rh_state == OHCI_RH_RUNNING) &&
  864. tick_before(tick, ed->tick)) {
  865. skip_ed:
  866. last = &ed->ed_next;
  867. continue;
  868. }
  869. if (!list_empty(&ed->td_list)) {
  870. struct td *td;
  871. u32 head;
  872. td = list_first_entry(&ed->td_list, struct td, td_list);
  873. /* INTR_WDH may need to clean up first */
  874. head = hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK;
  875. if (td->td_dma != head &&
  876. ohci->rh_state == OHCI_RH_RUNNING)
  877. goto skip_ed;
  878. /* Don't mess up anything already on the done list */
  879. if (td->next_dl_td)
  880. goto skip_ed;
  881. }
  882. /* ED's now officially unlinked, hc doesn't see */
  883. ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H);
  884. ed->hwNextED = 0;
  885. wmb();
  886. ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE);
  887. /* reentrancy: if we drop the schedule lock, someone might
  888. * have modified this list. normally it's just prepending
  889. * entries (which we'd ignore), but paranoia won't hurt.
  890. */
  891. modified = 0;
  892. /* unlink urbs as requested, but rescan the list after
  893. * we call a completion since it might have unlinked
  894. * another (earlier) urb
  895. *
  896. * When we get here, the HC doesn't see this ed. But it
  897. * must not be rescheduled until all completed URBs have
  898. * been given back to the driver.
  899. */
  900. rescan_this:
  901. completed = 0;
  902. prev = &ed->hwHeadP;
  903. list_for_each_safe (entry, tmp, &ed->td_list) {
  904. struct td *td;
  905. struct urb *urb;
  906. urb_priv_t *urb_priv;
  907. __hc32 savebits;
  908. u32 tdINFO;
  909. td = list_entry (entry, struct td, td_list);
  910. urb = td->urb;
  911. urb_priv = td->urb->hcpriv;
  912. if (!urb->unlinked) {
  913. prev = &td->hwNextTD;
  914. continue;
  915. }
  916. /* patch pointer hc uses */
  917. savebits = *prev & ~cpu_to_hc32 (ohci, TD_MASK);
  918. *prev = td->hwNextTD | savebits;
  919. /* If this was unlinked, the TD may not have been
  920. * retired ... so manually save the data toggle.
  921. * The controller ignores the value we save for
  922. * control and ISO endpoints.
  923. */
  924. tdINFO = hc32_to_cpup(ohci, &td->hwINFO);
  925. if ((tdINFO & TD_T) == TD_T_DATA0)
  926. ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_C);
  927. else if ((tdINFO & TD_T) == TD_T_DATA1)
  928. ed->hwHeadP |= cpu_to_hc32(ohci, ED_C);
  929. /* HC may have partly processed this TD */
  930. td_done (ohci, urb, td);
  931. urb_priv->td_cnt++;
  932. /* if URB is done, clean up */
  933. if (urb_priv->td_cnt >= urb_priv->length) {
  934. modified = completed = 1;
  935. finish_urb(ohci, urb, 0);
  936. }
  937. }
  938. if (completed && !list_empty (&ed->td_list))
  939. goto rescan_this;
  940. /*
  941. * If no TDs are queued, take ED off the ed_rm_list.
  942. * Otherwise, if the HC is running, reschedule.
  943. * If not, leave it on the list for further dequeues.
  944. */
  945. if (list_empty(&ed->td_list)) {
  946. *last = ed->ed_next;
  947. ed->ed_next = NULL;
  948. ed->state = ED_IDLE;
  949. list_del(&ed->in_use_list);
  950. } else if (ohci->rh_state == OHCI_RH_RUNNING) {
  951. *last = ed->ed_next;
  952. ed->ed_next = NULL;
  953. ed_schedule(ohci, ed);
  954. } else {
  955. last = &ed->ed_next;
  956. }
  957. if (modified)
  958. goto rescan_all;
  959. }
  960. /* maybe reenable control and bulk lists */
  961. if (ohci->rh_state == OHCI_RH_RUNNING && !ohci->ed_rm_list) {
  962. u32 command = 0, control = 0;
  963. if (ohci->ed_controltail) {
  964. command |= OHCI_CLF;
  965. if (quirk_zfmicro(ohci))
  966. mdelay(1);
  967. if (!(ohci->hc_control & OHCI_CTRL_CLE)) {
  968. control |= OHCI_CTRL_CLE;
  969. ohci_writel (ohci, 0,
  970. &ohci->regs->ed_controlcurrent);
  971. }
  972. }
  973. if (ohci->ed_bulktail) {
  974. command |= OHCI_BLF;
  975. if (quirk_zfmicro(ohci))
  976. mdelay(1);
  977. if (!(ohci->hc_control & OHCI_CTRL_BLE)) {
  978. control |= OHCI_CTRL_BLE;
  979. ohci_writel (ohci, 0,
  980. &ohci->regs->ed_bulkcurrent);
  981. }
  982. }
  983. /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */
  984. if (control) {
  985. ohci->hc_control |= control;
  986. if (quirk_zfmicro(ohci))
  987. mdelay(1);
  988. ohci_writel (ohci, ohci->hc_control,
  989. &ohci->regs->control);
  990. }
  991. if (command) {
  992. if (quirk_zfmicro(ohci))
  993. mdelay(1);
  994. ohci_writel (ohci, command, &ohci->regs->cmdstatus);
  995. }
  996. }
  997. }
  998. /*-------------------------------------------------------------------------*/
  999. /* Take back a TD from the host controller */
  1000. static void takeback_td(struct ohci_hcd *ohci, struct td *td)
  1001. {
  1002. struct urb *urb = td->urb;
  1003. urb_priv_t *urb_priv = urb->hcpriv;
  1004. struct ed *ed = td->ed;
  1005. int status;
  1006. /* update URB's length and status from TD */
  1007. status = td_done(ohci, urb, td);
  1008. urb_priv->td_cnt++;
  1009. /* If all this urb's TDs are done, call complete() */
  1010. if (urb_priv->td_cnt >= urb_priv->length)
  1011. finish_urb(ohci, urb, status);
  1012. /* clean schedule: unlink EDs that are no longer busy */
  1013. if (list_empty(&ed->td_list)) {
  1014. if (ed->state == ED_OPER)
  1015. start_ed_unlink(ohci, ed);
  1016. /* ... reenabling halted EDs only after fault cleanup */
  1017. } else if ((ed->hwINFO & cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE))
  1018. == cpu_to_hc32(ohci, ED_SKIP)) {
  1019. td = list_entry(ed->td_list.next, struct td, td_list);
  1020. if (!(td->hwINFO & cpu_to_hc32(ohci, TD_DONE))) {
  1021. ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP);
  1022. /* ... hc may need waking-up */
  1023. switch (ed->type) {
  1024. case PIPE_CONTROL:
  1025. ohci_writel(ohci, OHCI_CLF,
  1026. &ohci->regs->cmdstatus);
  1027. break;
  1028. case PIPE_BULK:
  1029. ohci_writel(ohci, OHCI_BLF,
  1030. &ohci->regs->cmdstatus);
  1031. break;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. /*
  1037. * Process normal completions (error or success) and clean the schedules.
  1038. *
  1039. * This is the main path for handing urbs back to drivers. The only other
  1040. * normal path is finish_unlinks(), which unlinks URBs using ed_rm_list,
  1041. * instead of scanning the (re-reversed) donelist as this does.
  1042. */
  1043. static void process_done_list(struct ohci_hcd *ohci)
  1044. {
  1045. struct td *td;
  1046. while (ohci->dl_start) {
  1047. td = ohci->dl_start;
  1048. if (td == ohci->dl_end)
  1049. ohci->dl_start = ohci->dl_end = NULL;
  1050. else
  1051. ohci->dl_start = td->next_dl_td;
  1052. takeback_td(ohci, td);
  1053. }
  1054. }
  1055. /*
  1056. * TD takeback and URB giveback must be single-threaded.
  1057. * This routine takes care of it all.
  1058. */
  1059. static void ohci_work(struct ohci_hcd *ohci)
  1060. {
  1061. if (ohci->working) {
  1062. ohci->restart_work = 1;
  1063. return;
  1064. }
  1065. ohci->working = 1;
  1066. restart:
  1067. process_done_list(ohci);
  1068. if (ohci->ed_rm_list)
  1069. finish_unlinks(ohci);
  1070. if (ohci->restart_work) {
  1071. ohci->restart_work = 0;
  1072. goto restart;
  1073. }
  1074. ohci->working = 0;
  1075. }