hcd.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763
  1. /*
  2. * (C) Copyright Linus Torvalds 1999
  3. * (C) Copyright Johannes Erdfelt 1999-2001
  4. * (C) Copyright Andreas Gal 1999
  5. * (C) Copyright Gregory P. Smith 1999
  6. * (C) Copyright Deti Fliegl 1999
  7. * (C) Copyright Randy Dunlap 2000
  8. * (C) Copyright David Brownell 2000-2002
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. * for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software Foundation,
  22. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <linux/module.h>
  25. #include <linux/version.h>
  26. #include <linux/kernel.h>
  27. #include <linux/slab.h>
  28. #include <linux/completion.h>
  29. #include <linux/utsname.h>
  30. #include <linux/mm.h>
  31. #include <asm/io.h>
  32. #include <asm/scatterlist.h>
  33. #include <linux/device.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/mutex.h>
  36. #include <asm/irq.h>
  37. #include <asm/byteorder.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/workqueue.h>
  40. #include <linux/usb.h>
  41. #include "usb.h"
  42. #include "hcd.h"
  43. #include "hub.h"
  44. /*-------------------------------------------------------------------------*/
  45. /*
  46. * USB Host Controller Driver framework
  47. *
  48. * Plugs into usbcore (usb_bus) and lets HCDs share code, minimizing
  49. * HCD-specific behaviors/bugs.
  50. *
  51. * This does error checks, tracks devices and urbs, and delegates to a
  52. * "hc_driver" only for code (and data) that really needs to know about
  53. * hardware differences. That includes root hub registers, i/o queues,
  54. * and so on ... but as little else as possible.
  55. *
  56. * Shared code includes most of the "root hub" code (these are emulated,
  57. * though each HC's hardware works differently) and PCI glue, plus request
  58. * tracking overhead. The HCD code should only block on spinlocks or on
  59. * hardware handshaking; blocking on software events (such as other kernel
  60. * threads releasing resources, or completing actions) is all generic.
  61. *
  62. * Happens the USB 2.0 spec says this would be invisible inside the "USBD",
  63. * and includes mostly a "HCDI" (HCD Interface) along with some APIs used
  64. * only by the hub driver ... and that neither should be seen or used by
  65. * usb client device drivers.
  66. *
  67. * Contributors of ideas or unattributed patches include: David Brownell,
  68. * Roman Weissgaerber, Rory Bolt, Greg Kroah-Hartman, ...
  69. *
  70. * HISTORY:
  71. * 2002-02-21 Pull in most of the usb_bus support from usb.c; some
  72. * associated cleanup. "usb_hcd" still != "usb_bus".
  73. * 2001-12-12 Initial patch version for Linux 2.5.1 kernel.
  74. */
  75. /*-------------------------------------------------------------------------*/
  76. /* host controllers we manage */
  77. LIST_HEAD (usb_bus_list);
  78. EXPORT_SYMBOL_GPL (usb_bus_list);
  79. /* used when allocating bus numbers */
  80. #define USB_MAXBUS 64
  81. struct usb_busmap {
  82. unsigned long busmap [USB_MAXBUS / (8*sizeof (unsigned long))];
  83. };
  84. static struct usb_busmap busmap;
  85. /* used when updating list of hcds */
  86. DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */
  87. EXPORT_SYMBOL_GPL (usb_bus_list_lock);
  88. /* used for controlling access to virtual root hubs */
  89. static DEFINE_SPINLOCK(hcd_root_hub_lock);
  90. /* used when updating hcd data */
  91. static DEFINE_SPINLOCK(hcd_data_lock);
  92. /* wait queue for synchronous unlinks */
  93. DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);
  94. /*-------------------------------------------------------------------------*/
  95. /*
  96. * Sharable chunks of root hub code.
  97. */
  98. /*-------------------------------------------------------------------------*/
  99. #define KERNEL_REL ((LINUX_VERSION_CODE >> 16) & 0x0ff)
  100. #define KERNEL_VER ((LINUX_VERSION_CODE >> 8) & 0x0ff)
  101. /* usb 2.0 root hub device descriptor */
  102. static const u8 usb2_rh_dev_descriptor [18] = {
  103. 0x12, /* __u8 bLength; */
  104. 0x01, /* __u8 bDescriptorType; Device */
  105. 0x00, 0x02, /* __le16 bcdUSB; v2.0 */
  106. 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
  107. 0x00, /* __u8 bDeviceSubClass; */
  108. 0x01, /* __u8 bDeviceProtocol; [ usb 2.0 single TT ]*/
  109. 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */
  110. 0x00, 0x00, /* __le16 idVendor; */
  111. 0x00, 0x00, /* __le16 idProduct; */
  112. KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */
  113. 0x03, /* __u8 iManufacturer; */
  114. 0x02, /* __u8 iProduct; */
  115. 0x01, /* __u8 iSerialNumber; */
  116. 0x01 /* __u8 bNumConfigurations; */
  117. };
  118. /* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
  119. /* usb 1.1 root hub device descriptor */
  120. static const u8 usb11_rh_dev_descriptor [18] = {
  121. 0x12, /* __u8 bLength; */
  122. 0x01, /* __u8 bDescriptorType; Device */
  123. 0x10, 0x01, /* __le16 bcdUSB; v1.1 */
  124. 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
  125. 0x00, /* __u8 bDeviceSubClass; */
  126. 0x00, /* __u8 bDeviceProtocol; [ low/full speeds only ] */
  127. 0x40, /* __u8 bMaxPacketSize0; 64 Bytes */
  128. 0x00, 0x00, /* __le16 idVendor; */
  129. 0x00, 0x00, /* __le16 idProduct; */
  130. KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */
  131. 0x03, /* __u8 iManufacturer; */
  132. 0x02, /* __u8 iProduct; */
  133. 0x01, /* __u8 iSerialNumber; */
  134. 0x01 /* __u8 bNumConfigurations; */
  135. };
  136. /*-------------------------------------------------------------------------*/
  137. /* Configuration descriptors for our root hubs */
  138. static const u8 fs_rh_config_descriptor [] = {
  139. /* one configuration */
  140. 0x09, /* __u8 bLength; */
  141. 0x02, /* __u8 bDescriptorType; Configuration */
  142. 0x19, 0x00, /* __le16 wTotalLength; */
  143. 0x01, /* __u8 bNumInterfaces; (1) */
  144. 0x01, /* __u8 bConfigurationValue; */
  145. 0x00, /* __u8 iConfiguration; */
  146. 0xc0, /* __u8 bmAttributes;
  147. Bit 7: must be set,
  148. 6: Self-powered,
  149. 5: Remote wakeup,
  150. 4..0: resvd */
  151. 0x00, /* __u8 MaxPower; */
  152. /* USB 1.1:
  153. * USB 2.0, single TT organization (mandatory):
  154. * one interface, protocol 0
  155. *
  156. * USB 2.0, multiple TT organization (optional):
  157. * two interfaces, protocols 1 (like single TT)
  158. * and 2 (multiple TT mode) ... config is
  159. * sometimes settable
  160. * NOT IMPLEMENTED
  161. */
  162. /* one interface */
  163. 0x09, /* __u8 if_bLength; */
  164. 0x04, /* __u8 if_bDescriptorType; Interface */
  165. 0x00, /* __u8 if_bInterfaceNumber; */
  166. 0x00, /* __u8 if_bAlternateSetting; */
  167. 0x01, /* __u8 if_bNumEndpoints; */
  168. 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
  169. 0x00, /* __u8 if_bInterfaceSubClass; */
  170. 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
  171. 0x00, /* __u8 if_iInterface; */
  172. /* one endpoint (status change endpoint) */
  173. 0x07, /* __u8 ep_bLength; */
  174. 0x05, /* __u8 ep_bDescriptorType; Endpoint */
  175. 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
  176. 0x03, /* __u8 ep_bmAttributes; Interrupt */
  177. 0x02, 0x00, /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
  178. 0xff /* __u8 ep_bInterval; (255ms -- usb 2.0 spec) */
  179. };
  180. static const u8 hs_rh_config_descriptor [] = {
  181. /* one configuration */
  182. 0x09, /* __u8 bLength; */
  183. 0x02, /* __u8 bDescriptorType; Configuration */
  184. 0x19, 0x00, /* __le16 wTotalLength; */
  185. 0x01, /* __u8 bNumInterfaces; (1) */
  186. 0x01, /* __u8 bConfigurationValue; */
  187. 0x00, /* __u8 iConfiguration; */
  188. 0xc0, /* __u8 bmAttributes;
  189. Bit 7: must be set,
  190. 6: Self-powered,
  191. 5: Remote wakeup,
  192. 4..0: resvd */
  193. 0x00, /* __u8 MaxPower; */
  194. /* USB 1.1:
  195. * USB 2.0, single TT organization (mandatory):
  196. * one interface, protocol 0
  197. *
  198. * USB 2.0, multiple TT organization (optional):
  199. * two interfaces, protocols 1 (like single TT)
  200. * and 2 (multiple TT mode) ... config is
  201. * sometimes settable
  202. * NOT IMPLEMENTED
  203. */
  204. /* one interface */
  205. 0x09, /* __u8 if_bLength; */
  206. 0x04, /* __u8 if_bDescriptorType; Interface */
  207. 0x00, /* __u8 if_bInterfaceNumber; */
  208. 0x00, /* __u8 if_bAlternateSetting; */
  209. 0x01, /* __u8 if_bNumEndpoints; */
  210. 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
  211. 0x00, /* __u8 if_bInterfaceSubClass; */
  212. 0x00, /* __u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
  213. 0x00, /* __u8 if_iInterface; */
  214. /* one endpoint (status change endpoint) */
  215. 0x07, /* __u8 ep_bLength; */
  216. 0x05, /* __u8 ep_bDescriptorType; Endpoint */
  217. 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
  218. 0x03, /* __u8 ep_bmAttributes; Interrupt */
  219. /* __le16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8)
  220. * see hub.c:hub_configure() for details. */
  221. (USB_MAXCHILDREN + 1 + 7) / 8, 0x00,
  222. 0x0c /* __u8 ep_bInterval; (256ms -- usb 2.0 spec) */
  223. };
  224. /*-------------------------------------------------------------------------*/
  225. /*
  226. * helper routine for returning string descriptors in UTF-16LE
  227. * input can actually be ISO-8859-1; ASCII is its 7-bit subset
  228. */
  229. static int ascii2utf (char *s, u8 *utf, int utfmax)
  230. {
  231. int retval;
  232. for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) {
  233. *utf++ = *s++;
  234. *utf++ = 0;
  235. }
  236. if (utfmax > 0) {
  237. *utf = *s;
  238. ++retval;
  239. }
  240. return retval;
  241. }
  242. /*
  243. * rh_string - provides manufacturer, product and serial strings for root hub
  244. * @id: the string ID number (1: serial number, 2: product, 3: vendor)
  245. * @hcd: the host controller for this root hub
  246. * @type: string describing our driver
  247. * @data: return packet in UTF-16 LE
  248. * @len: length of the return packet
  249. *
  250. * Produces either a manufacturer, product or serial number string for the
  251. * virtual root hub device.
  252. */
  253. static int rh_string (
  254. int id,
  255. struct usb_hcd *hcd,
  256. u8 *data,
  257. int len
  258. ) {
  259. char buf [100];
  260. // language ids
  261. if (id == 0) {
  262. buf[0] = 4; buf[1] = 3; /* 4 bytes string data */
  263. buf[2] = 0x09; buf[3] = 0x04; /* MSFT-speak for "en-us" */
  264. len = min (len, 4);
  265. memcpy (data, buf, len);
  266. return len;
  267. // serial number
  268. } else if (id == 1) {
  269. strlcpy (buf, hcd->self.bus_name, sizeof buf);
  270. // product description
  271. } else if (id == 2) {
  272. strlcpy (buf, hcd->product_desc, sizeof buf);
  273. // id 3 == vendor description
  274. } else if (id == 3) {
  275. snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname,
  276. init_utsname()->release, hcd->driver->description);
  277. // unsupported IDs --> "protocol stall"
  278. } else
  279. return -EPIPE;
  280. switch (len) { /* All cases fall through */
  281. default:
  282. len = 2 + ascii2utf (buf, data + 2, len - 2);
  283. case 2:
  284. data [1] = 3; /* type == string */
  285. case 1:
  286. data [0] = 2 * (strlen (buf) + 1);
  287. case 0:
  288. ; /* Compiler wants a statement here */
  289. }
  290. return len;
  291. }
  292. /* Root hub control transfers execute synchronously */
  293. static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
  294. {
  295. struct usb_ctrlrequest *cmd;
  296. u16 typeReq, wValue, wIndex, wLength;
  297. u8 *ubuf = urb->transfer_buffer;
  298. u8 tbuf [sizeof (struct usb_hub_descriptor)]
  299. __attribute__((aligned(4)));
  300. const u8 *bufp = tbuf;
  301. int len = 0;
  302. int patch_wakeup = 0;
  303. unsigned long flags;
  304. int status = 0;
  305. int n;
  306. cmd = (struct usb_ctrlrequest *) urb->setup_packet;
  307. typeReq = (cmd->bRequestType << 8) | cmd->bRequest;
  308. wValue = le16_to_cpu (cmd->wValue);
  309. wIndex = le16_to_cpu (cmd->wIndex);
  310. wLength = le16_to_cpu (cmd->wLength);
  311. if (wLength > urb->transfer_buffer_length)
  312. goto error;
  313. urb->actual_length = 0;
  314. switch (typeReq) {
  315. /* DEVICE REQUESTS */
  316. /* The root hub's remote wakeup enable bit is implemented using
  317. * driver model wakeup flags. If this system supports wakeup
  318. * through USB, userspace may change the default "allow wakeup"
  319. * policy through sysfs or these calls.
  320. *
  321. * Most root hubs support wakeup from downstream devices, for
  322. * runtime power management (disabling USB clocks and reducing
  323. * VBUS power usage). However, not all of them do so; silicon,
  324. * board, and BIOS bugs here are not uncommon, so these can't
  325. * be treated quite like external hubs.
  326. *
  327. * Likewise, not all root hubs will pass wakeup events upstream,
  328. * to wake up the whole system. So don't assume root hub and
  329. * controller capabilities are identical.
  330. */
  331. case DeviceRequest | USB_REQ_GET_STATUS:
  332. tbuf [0] = (device_may_wakeup(&hcd->self.root_hub->dev)
  333. << USB_DEVICE_REMOTE_WAKEUP)
  334. | (1 << USB_DEVICE_SELF_POWERED);
  335. tbuf [1] = 0;
  336. len = 2;
  337. break;
  338. case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
  339. if (wValue == USB_DEVICE_REMOTE_WAKEUP)
  340. device_set_wakeup_enable(&hcd->self.root_hub->dev, 0);
  341. else
  342. goto error;
  343. break;
  344. case DeviceOutRequest | USB_REQ_SET_FEATURE:
  345. if (device_can_wakeup(&hcd->self.root_hub->dev)
  346. && wValue == USB_DEVICE_REMOTE_WAKEUP)
  347. device_set_wakeup_enable(&hcd->self.root_hub->dev, 1);
  348. else
  349. goto error;
  350. break;
  351. case DeviceRequest | USB_REQ_GET_CONFIGURATION:
  352. tbuf [0] = 1;
  353. len = 1;
  354. /* FALLTHROUGH */
  355. case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
  356. break;
  357. case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
  358. switch (wValue & 0xff00) {
  359. case USB_DT_DEVICE << 8:
  360. if (hcd->driver->flags & HCD_USB2)
  361. bufp = usb2_rh_dev_descriptor;
  362. else if (hcd->driver->flags & HCD_USB11)
  363. bufp = usb11_rh_dev_descriptor;
  364. else
  365. goto error;
  366. len = 18;
  367. break;
  368. case USB_DT_CONFIG << 8:
  369. if (hcd->driver->flags & HCD_USB2) {
  370. bufp = hs_rh_config_descriptor;
  371. len = sizeof hs_rh_config_descriptor;
  372. } else {
  373. bufp = fs_rh_config_descriptor;
  374. len = sizeof fs_rh_config_descriptor;
  375. }
  376. if (device_can_wakeup(&hcd->self.root_hub->dev))
  377. patch_wakeup = 1;
  378. break;
  379. case USB_DT_STRING << 8:
  380. n = rh_string (wValue & 0xff, hcd, ubuf, wLength);
  381. if (n < 0)
  382. goto error;
  383. urb->actual_length = n;
  384. break;
  385. default:
  386. goto error;
  387. }
  388. break;
  389. case DeviceRequest | USB_REQ_GET_INTERFACE:
  390. tbuf [0] = 0;
  391. len = 1;
  392. /* FALLTHROUGH */
  393. case DeviceOutRequest | USB_REQ_SET_INTERFACE:
  394. break;
  395. case DeviceOutRequest | USB_REQ_SET_ADDRESS:
  396. // wValue == urb->dev->devaddr
  397. dev_dbg (hcd->self.controller, "root hub device address %d\n",
  398. wValue);
  399. break;
  400. /* INTERFACE REQUESTS (no defined feature/status flags) */
  401. /* ENDPOINT REQUESTS */
  402. case EndpointRequest | USB_REQ_GET_STATUS:
  403. // ENDPOINT_HALT flag
  404. tbuf [0] = 0;
  405. tbuf [1] = 0;
  406. len = 2;
  407. /* FALLTHROUGH */
  408. case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
  409. case EndpointOutRequest | USB_REQ_SET_FEATURE:
  410. dev_dbg (hcd->self.controller, "no endpoint features yet\n");
  411. break;
  412. /* CLASS REQUESTS (and errors) */
  413. default:
  414. /* non-generic request */
  415. switch (typeReq) {
  416. case GetHubStatus:
  417. case GetPortStatus:
  418. len = 4;
  419. break;
  420. case GetHubDescriptor:
  421. len = sizeof (struct usb_hub_descriptor);
  422. break;
  423. }
  424. status = hcd->driver->hub_control (hcd,
  425. typeReq, wValue, wIndex,
  426. tbuf, wLength);
  427. break;
  428. error:
  429. /* "protocol stall" on error */
  430. status = -EPIPE;
  431. }
  432. if (status) {
  433. len = 0;
  434. if (status != -EPIPE) {
  435. dev_dbg (hcd->self.controller,
  436. "CTRL: TypeReq=0x%x val=0x%x "
  437. "idx=0x%x len=%d ==> %d\n",
  438. typeReq, wValue, wIndex,
  439. wLength, status);
  440. }
  441. }
  442. if (len) {
  443. if (urb->transfer_buffer_length < len)
  444. len = urb->transfer_buffer_length;
  445. urb->actual_length = len;
  446. // always USB_DIR_IN, toward host
  447. memcpy (ubuf, bufp, len);
  448. /* report whether RH hardware supports remote wakeup */
  449. if (patch_wakeup &&
  450. len > offsetof (struct usb_config_descriptor,
  451. bmAttributes))
  452. ((struct usb_config_descriptor *)ubuf)->bmAttributes
  453. |= USB_CONFIG_ATT_WAKEUP;
  454. }
  455. /* any errors get returned through the urb completion */
  456. local_irq_save (flags);
  457. spin_lock (&urb->lock);
  458. if (urb->status == -EINPROGRESS)
  459. urb->status = status;
  460. spin_unlock (&urb->lock);
  461. usb_hcd_giveback_urb (hcd, urb);
  462. local_irq_restore (flags);
  463. return 0;
  464. }
  465. /*-------------------------------------------------------------------------*/
  466. /*
  467. * Root Hub interrupt transfers are polled using a timer if the
  468. * driver requests it; otherwise the driver is responsible for
  469. * calling usb_hcd_poll_rh_status() when an event occurs.
  470. *
  471. * Completions are called in_interrupt(), but they may or may not
  472. * be in_irq().
  473. */
  474. void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
  475. {
  476. struct urb *urb;
  477. int length;
  478. unsigned long flags;
  479. char buffer[4]; /* Any root hubs with > 31 ports? */
  480. if (unlikely(!hcd->rh_registered))
  481. return;
  482. if (!hcd->uses_new_polling && !hcd->status_urb)
  483. return;
  484. length = hcd->driver->hub_status_data(hcd, buffer);
  485. if (length > 0) {
  486. /* try to complete the status urb */
  487. local_irq_save (flags);
  488. spin_lock(&hcd_root_hub_lock);
  489. urb = hcd->status_urb;
  490. if (urb) {
  491. spin_lock(&urb->lock);
  492. if (urb->status == -EINPROGRESS) {
  493. hcd->poll_pending = 0;
  494. hcd->status_urb = NULL;
  495. urb->status = 0;
  496. urb->hcpriv = NULL;
  497. urb->actual_length = length;
  498. memcpy(urb->transfer_buffer, buffer, length);
  499. } else /* urb has been unlinked */
  500. length = 0;
  501. spin_unlock(&urb->lock);
  502. } else
  503. length = 0;
  504. spin_unlock(&hcd_root_hub_lock);
  505. /* local irqs are always blocked in completions */
  506. if (length > 0)
  507. usb_hcd_giveback_urb (hcd, urb);
  508. else
  509. hcd->poll_pending = 1;
  510. local_irq_restore (flags);
  511. }
  512. /* The USB 2.0 spec says 256 ms. This is close enough and won't
  513. * exceed that limit if HZ is 100. The math is more clunky than
  514. * maybe expected, this is to make sure that all timers for USB devices
  515. * fire at the same time to give the CPU a break inbetween */
  516. if (hcd->uses_new_polling ? hcd->poll_rh :
  517. (length == 0 && hcd->status_urb != NULL))
  518. mod_timer (&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4));
  519. }
  520. EXPORT_SYMBOL_GPL(usb_hcd_poll_rh_status);
  521. /* timer callback */
  522. static void rh_timer_func (unsigned long _hcd)
  523. {
  524. usb_hcd_poll_rh_status((struct usb_hcd *) _hcd);
  525. }
  526. /*-------------------------------------------------------------------------*/
  527. static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
  528. {
  529. int retval;
  530. unsigned long flags;
  531. int len = 1 + (urb->dev->maxchild / 8);
  532. spin_lock_irqsave (&hcd_root_hub_lock, flags);
  533. if (urb->status != -EINPROGRESS) /* already unlinked */
  534. retval = urb->status;
  535. else if (hcd->status_urb || urb->transfer_buffer_length < len) {
  536. dev_dbg (hcd->self.controller, "not queuing rh status urb\n");
  537. retval = -EINVAL;
  538. } else {
  539. hcd->status_urb = urb;
  540. urb->hcpriv = hcd; /* indicate it's queued */
  541. if (!hcd->uses_new_polling)
  542. mod_timer (&hcd->rh_timer,
  543. (jiffies/(HZ/4) + 1) * (HZ/4));
  544. /* If a status change has already occurred, report it ASAP */
  545. else if (hcd->poll_pending)
  546. mod_timer (&hcd->rh_timer, jiffies);
  547. retval = 0;
  548. }
  549. spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
  550. return retval;
  551. }
  552. static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
  553. {
  554. if (usb_pipeint (urb->pipe))
  555. return rh_queue_status (hcd, urb);
  556. if (usb_pipecontrol (urb->pipe))
  557. return rh_call_control (hcd, urb);
  558. return -EINVAL;
  559. }
  560. /*-------------------------------------------------------------------------*/
  561. /* Unlinks of root-hub control URBs are legal, but they don't do anything
  562. * since these URBs always execute synchronously.
  563. */
  564. static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
  565. {
  566. unsigned long flags;
  567. if (usb_pipeendpoint(urb->pipe) == 0) { /* Control URB */
  568. ; /* Do nothing */
  569. } else { /* Status URB */
  570. if (!hcd->uses_new_polling)
  571. del_timer (&hcd->rh_timer);
  572. local_irq_save (flags);
  573. spin_lock (&hcd_root_hub_lock);
  574. if (urb == hcd->status_urb) {
  575. hcd->status_urb = NULL;
  576. urb->hcpriv = NULL;
  577. } else
  578. urb = NULL; /* wasn't fully queued */
  579. spin_unlock (&hcd_root_hub_lock);
  580. if (urb)
  581. usb_hcd_giveback_urb (hcd, urb);
  582. local_irq_restore (flags);
  583. }
  584. return 0;
  585. }
  586. /*-------------------------------------------------------------------------*/
  587. static struct class *usb_host_class;
  588. int usb_host_init(void)
  589. {
  590. int retval = 0;
  591. usb_host_class = class_create(THIS_MODULE, "usb_host");
  592. if (IS_ERR(usb_host_class))
  593. retval = PTR_ERR(usb_host_class);
  594. return retval;
  595. }
  596. void usb_host_cleanup(void)
  597. {
  598. class_destroy(usb_host_class);
  599. }
  600. /**
  601. * usb_bus_init - shared initialization code
  602. * @bus: the bus structure being initialized
  603. *
  604. * This code is used to initialize a usb_bus structure, memory for which is
  605. * separately managed.
  606. */
  607. static void usb_bus_init (struct usb_bus *bus)
  608. {
  609. memset (&bus->devmap, 0, sizeof(struct usb_devmap));
  610. bus->devnum_next = 1;
  611. bus->root_hub = NULL;
  612. bus->busnum = -1;
  613. bus->bandwidth_allocated = 0;
  614. bus->bandwidth_int_reqs = 0;
  615. bus->bandwidth_isoc_reqs = 0;
  616. INIT_LIST_HEAD (&bus->bus_list);
  617. }
  618. /*-------------------------------------------------------------------------*/
  619. /**
  620. * usb_register_bus - registers the USB host controller with the usb core
  621. * @bus: pointer to the bus to register
  622. * Context: !in_interrupt()
  623. *
  624. * Assigns a bus number, and links the controller into usbcore data
  625. * structures so that it can be seen by scanning the bus list.
  626. */
  627. static int usb_register_bus(struct usb_bus *bus)
  628. {
  629. int busnum;
  630. mutex_lock(&usb_bus_list_lock);
  631. busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
  632. if (busnum < USB_MAXBUS) {
  633. set_bit (busnum, busmap.busmap);
  634. bus->busnum = busnum;
  635. } else {
  636. printk (KERN_ERR "%s: too many buses\n", usbcore_name);
  637. mutex_unlock(&usb_bus_list_lock);
  638. return -E2BIG;
  639. }
  640. bus->class_dev = class_device_create(usb_host_class, NULL, MKDEV(0,0),
  641. bus->controller, "usb_host%d", busnum);
  642. if (IS_ERR(bus->class_dev)) {
  643. clear_bit(busnum, busmap.busmap);
  644. mutex_unlock(&usb_bus_list_lock);
  645. return PTR_ERR(bus->class_dev);
  646. }
  647. class_set_devdata(bus->class_dev, bus);
  648. /* Add it to the local list of buses */
  649. list_add (&bus->bus_list, &usb_bus_list);
  650. mutex_unlock(&usb_bus_list_lock);
  651. usb_notify_add_bus(bus);
  652. dev_info (bus->controller, "new USB bus registered, assigned bus number %d\n", bus->busnum);
  653. return 0;
  654. }
  655. /**
  656. * usb_deregister_bus - deregisters the USB host controller
  657. * @bus: pointer to the bus to deregister
  658. * Context: !in_interrupt()
  659. *
  660. * Recycles the bus number, and unlinks the controller from usbcore data
  661. * structures so that it won't be seen by scanning the bus list.
  662. */
  663. static void usb_deregister_bus (struct usb_bus *bus)
  664. {
  665. dev_info (bus->controller, "USB bus %d deregistered\n", bus->busnum);
  666. /*
  667. * NOTE: make sure that all the devices are removed by the
  668. * controller code, as well as having it call this when cleaning
  669. * itself up
  670. */
  671. mutex_lock(&usb_bus_list_lock);
  672. list_del (&bus->bus_list);
  673. mutex_unlock(&usb_bus_list_lock);
  674. usb_notify_remove_bus(bus);
  675. clear_bit (bus->busnum, busmap.busmap);
  676. class_device_unregister(bus->class_dev);
  677. }
  678. /**
  679. * register_root_hub - called by usb_add_hcd() to register a root hub
  680. * @hcd: host controller for this root hub
  681. *
  682. * This function registers the root hub with the USB subsystem. It sets up
  683. * the device properly in the device tree and then calls usb_new_device()
  684. * to register the usb device. It also assigns the root hub's USB address
  685. * (always 1).
  686. */
  687. static int register_root_hub(struct usb_hcd *hcd)
  688. {
  689. struct device *parent_dev = hcd->self.controller;
  690. struct usb_device *usb_dev = hcd->self.root_hub;
  691. const int devnum = 1;
  692. int retval;
  693. usb_dev->devnum = devnum;
  694. usb_dev->bus->devnum_next = devnum + 1;
  695. memset (&usb_dev->bus->devmap.devicemap, 0,
  696. sizeof usb_dev->bus->devmap.devicemap);
  697. set_bit (devnum, usb_dev->bus->devmap.devicemap);
  698. usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
  699. mutex_lock(&usb_bus_list_lock);
  700. usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
  701. retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
  702. if (retval != sizeof usb_dev->descriptor) {
  703. mutex_unlock(&usb_bus_list_lock);
  704. dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
  705. usb_dev->dev.bus_id, retval);
  706. return (retval < 0) ? retval : -EMSGSIZE;
  707. }
  708. retval = usb_new_device (usb_dev);
  709. if (retval) {
  710. dev_err (parent_dev, "can't register root hub for %s, %d\n",
  711. usb_dev->dev.bus_id, retval);
  712. }
  713. mutex_unlock(&usb_bus_list_lock);
  714. if (retval == 0) {
  715. spin_lock_irq (&hcd_root_hub_lock);
  716. hcd->rh_registered = 1;
  717. spin_unlock_irq (&hcd_root_hub_lock);
  718. /* Did the HC die before the root hub was registered? */
  719. if (hcd->state == HC_STATE_HALT)
  720. usb_hc_died (hcd); /* This time clean up */
  721. }
  722. return retval;
  723. }
  724. void usb_enable_root_hub_irq (struct usb_bus *bus)
  725. {
  726. struct usb_hcd *hcd;
  727. hcd = container_of (bus, struct usb_hcd, self);
  728. if (hcd->driver->hub_irq_enable && hcd->state != HC_STATE_HALT)
  729. hcd->driver->hub_irq_enable (hcd);
  730. }
  731. /*-------------------------------------------------------------------------*/
  732. /**
  733. * usb_calc_bus_time - approximate periodic transaction time in nanoseconds
  734. * @speed: from dev->speed; USB_SPEED_{LOW,FULL,HIGH}
  735. * @is_input: true iff the transaction sends data to the host
  736. * @isoc: true for isochronous transactions, false for interrupt ones
  737. * @bytecount: how many bytes in the transaction.
  738. *
  739. * Returns approximate bus time in nanoseconds for a periodic transaction.
  740. * See USB 2.0 spec section 5.11.3; only periodic transfers need to be
  741. * scheduled in software, this function is only used for such scheduling.
  742. */
  743. long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
  744. {
  745. unsigned long tmp;
  746. switch (speed) {
  747. case USB_SPEED_LOW: /* INTR only */
  748. if (is_input) {
  749. tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L;
  750. return (64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp);
  751. } else {
  752. tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L;
  753. return (64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp);
  754. }
  755. case USB_SPEED_FULL: /* ISOC or INTR */
  756. if (isoc) {
  757. tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
  758. return (((is_input) ? 7268L : 6265L) + BW_HOST_DELAY + tmp);
  759. } else {
  760. tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
  761. return (9107L + BW_HOST_DELAY + tmp);
  762. }
  763. case USB_SPEED_HIGH: /* ISOC or INTR */
  764. // FIXME adjust for input vs output
  765. if (isoc)
  766. tmp = HS_NSECS_ISO (bytecount);
  767. else
  768. tmp = HS_NSECS (bytecount);
  769. return tmp;
  770. default:
  771. pr_debug ("%s: bogus device speed!\n", usbcore_name);
  772. return -1;
  773. }
  774. }
  775. EXPORT_SYMBOL (usb_calc_bus_time);
  776. /*-------------------------------------------------------------------------*/
  777. /*
  778. * Generic HC operations.
  779. */
  780. /*-------------------------------------------------------------------------*/
  781. static void urb_unlink(struct usb_hcd *hcd, struct urb *urb)
  782. {
  783. unsigned long flags;
  784. int at_root_hub = (urb->dev == hcd->self.root_hub);
  785. /* clear all state linking urb to this dev (and hcd) */
  786. spin_lock_irqsave (&hcd_data_lock, flags);
  787. list_del_init (&urb->urb_list);
  788. spin_unlock_irqrestore (&hcd_data_lock, flags);
  789. if (hcd->self.uses_dma && !at_root_hub) {
  790. if (usb_pipecontrol (urb->pipe)
  791. && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
  792. dma_unmap_single (hcd->self.controller, urb->setup_dma,
  793. sizeof (struct usb_ctrlrequest),
  794. DMA_TO_DEVICE);
  795. if (urb->transfer_buffer_length != 0
  796. && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP))
  797. dma_unmap_single (hcd->self.controller,
  798. urb->transfer_dma,
  799. urb->transfer_buffer_length,
  800. usb_pipein (urb->pipe)
  801. ? DMA_FROM_DEVICE
  802. : DMA_TO_DEVICE);
  803. }
  804. }
  805. /* may be called in any context with a valid urb->dev usecount
  806. * caller surrenders "ownership" of urb
  807. * expects usb_submit_urb() to have sanity checked and conditioned all
  808. * inputs in the urb
  809. */
  810. int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
  811. {
  812. int status;
  813. struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus);
  814. struct usb_host_endpoint *ep;
  815. unsigned long flags;
  816. if (!hcd)
  817. return -ENODEV;
  818. usbmon_urb_submit(&hcd->self, urb);
  819. /*
  820. * Atomically queue the urb, first to our records, then to the HCD.
  821. * Access to urb->status is controlled by urb->lock ... changes on
  822. * i/o completion (normal or fault) or unlinking.
  823. */
  824. // FIXME: verify that quiescing hc works right (RH cleans up)
  825. spin_lock_irqsave (&hcd_data_lock, flags);
  826. ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out)
  827. [usb_pipeendpoint(urb->pipe)];
  828. if (unlikely (!ep))
  829. status = -ENOENT;
  830. else if (unlikely (urb->reject))
  831. status = -EPERM;
  832. else switch (hcd->state) {
  833. case HC_STATE_RUNNING:
  834. case HC_STATE_RESUMING:
  835. doit:
  836. list_add_tail (&urb->urb_list, &ep->urb_list);
  837. status = 0;
  838. break;
  839. case HC_STATE_SUSPENDED:
  840. /* HC upstream links (register access, wakeup signaling) can work
  841. * even when the downstream links (and DMA etc) are quiesced; let
  842. * usbcore talk to the root hub.
  843. */
  844. if (hcd->self.controller->power.power_state.event == PM_EVENT_ON
  845. && urb->dev->parent == NULL)
  846. goto doit;
  847. /* FALL THROUGH */
  848. default:
  849. status = -ESHUTDOWN;
  850. break;
  851. }
  852. spin_unlock_irqrestore (&hcd_data_lock, flags);
  853. if (status) {
  854. INIT_LIST_HEAD (&urb->urb_list);
  855. usbmon_urb_submit_error(&hcd->self, urb, status);
  856. return status;
  857. }
  858. /* increment urb's reference count as part of giving it to the HCD
  859. * (which now controls it). HCD guarantees that it either returns
  860. * an error or calls giveback(), but not both.
  861. */
  862. urb = usb_get_urb (urb);
  863. atomic_inc (&urb->use_count);
  864. if (urb->dev == hcd->self.root_hub) {
  865. /* NOTE: requirement on hub callers (usbfs and the hub
  866. * driver, for now) that URBs' urb->transfer_buffer be
  867. * valid and usb_buffer_{sync,unmap}() not be needed, since
  868. * they could clobber root hub response data.
  869. */
  870. status = rh_urb_enqueue (hcd, urb);
  871. goto done;
  872. }
  873. /* lower level hcd code should use *_dma exclusively,
  874. * unless it uses pio or talks to another transport.
  875. */
  876. if (hcd->self.uses_dma) {
  877. if (usb_pipecontrol (urb->pipe)
  878. && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
  879. urb->setup_dma = dma_map_single (
  880. hcd->self.controller,
  881. urb->setup_packet,
  882. sizeof (struct usb_ctrlrequest),
  883. DMA_TO_DEVICE);
  884. if (urb->transfer_buffer_length != 0
  885. && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP))
  886. urb->transfer_dma = dma_map_single (
  887. hcd->self.controller,
  888. urb->transfer_buffer,
  889. urb->transfer_buffer_length,
  890. usb_pipein (urb->pipe)
  891. ? DMA_FROM_DEVICE
  892. : DMA_TO_DEVICE);
  893. }
  894. status = hcd->driver->urb_enqueue (hcd, ep, urb, mem_flags);
  895. done:
  896. if (unlikely (status)) {
  897. urb_unlink(hcd, urb);
  898. atomic_dec (&urb->use_count);
  899. if (urb->reject)
  900. wake_up (&usb_kill_urb_queue);
  901. usbmon_urb_submit_error(&hcd->self, urb, status);
  902. usb_put_urb (urb);
  903. }
  904. return status;
  905. }
  906. /*-------------------------------------------------------------------------*/
  907. /* called in any context */
  908. int usb_hcd_get_frame_number (struct usb_device *udev)
  909. {
  910. struct usb_hcd *hcd = bus_to_hcd(udev->bus);
  911. if (!HC_IS_RUNNING (hcd->state))
  912. return -ESHUTDOWN;
  913. return hcd->driver->get_frame_number (hcd);
  914. }
  915. /*-------------------------------------------------------------------------*/
  916. /* this makes the hcd giveback() the urb more quickly, by kicking it
  917. * off hardware queues (which may take a while) and returning it as
  918. * soon as practical. we've already set up the urb's return status,
  919. * but we can't know if the callback completed already.
  920. */
  921. static int
  922. unlink1 (struct usb_hcd *hcd, struct urb *urb)
  923. {
  924. int value;
  925. if (urb->dev == hcd->self.root_hub)
  926. value = usb_rh_urb_dequeue (hcd, urb);
  927. else {
  928. /* The only reason an HCD might fail this call is if
  929. * it has not yet fully queued the urb to begin with.
  930. * Such failures should be harmless. */
  931. value = hcd->driver->urb_dequeue (hcd, urb);
  932. }
  933. if (value != 0)
  934. dev_dbg (hcd->self.controller, "dequeue %p --> %d\n",
  935. urb, value);
  936. return value;
  937. }
  938. /*
  939. * called in any context
  940. *
  941. * caller guarantees urb won't be recycled till both unlink()
  942. * and the urb's completion function return
  943. */
  944. int usb_hcd_unlink_urb (struct urb *urb, int status)
  945. {
  946. struct usb_host_endpoint *ep;
  947. struct usb_hcd *hcd = NULL;
  948. struct device *sys = NULL;
  949. unsigned long flags;
  950. struct list_head *tmp;
  951. int retval;
  952. if (!urb)
  953. return -EINVAL;
  954. if (!urb->dev || !urb->dev->bus)
  955. return -ENODEV;
  956. ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out)
  957. [usb_pipeendpoint(urb->pipe)];
  958. if (!ep)
  959. return -ENODEV;
  960. /*
  961. * we contend for urb->status with the hcd core,
  962. * which changes it while returning the urb.
  963. *
  964. * Caller guaranteed that the urb pointer hasn't been freed, and
  965. * that it was submitted. But as a rule it can't know whether or
  966. * not it's already been unlinked ... so we respect the reversed
  967. * lock sequence needed for the usb_hcd_giveback_urb() code paths
  968. * (urb lock, then hcd_data_lock) in case some other CPU is now
  969. * unlinking it.
  970. */
  971. spin_lock_irqsave (&urb->lock, flags);
  972. spin_lock (&hcd_data_lock);
  973. sys = &urb->dev->dev;
  974. hcd = bus_to_hcd(urb->dev->bus);
  975. if (hcd == NULL) {
  976. retval = -ENODEV;
  977. goto done;
  978. }
  979. /* insist the urb is still queued */
  980. list_for_each(tmp, &ep->urb_list) {
  981. if (tmp == &urb->urb_list)
  982. break;
  983. }
  984. if (tmp != &urb->urb_list) {
  985. retval = -EIDRM;
  986. goto done;
  987. }
  988. /* Any status except -EINPROGRESS means something already started to
  989. * unlink this URB from the hardware. So there's no more work to do.
  990. */
  991. if (urb->status != -EINPROGRESS) {
  992. retval = -EBUSY;
  993. goto done;
  994. }
  995. /* IRQ setup can easily be broken so that USB controllers
  996. * never get completion IRQs ... maybe even the ones we need to
  997. * finish unlinking the initial failed usb_set_address()
  998. * or device descriptor fetch.
  999. */
  1000. if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags)
  1001. && hcd->self.root_hub != urb->dev) {
  1002. dev_warn (hcd->self.controller, "Unlink after no-IRQ? "
  1003. "Controller is probably using the wrong IRQ."
  1004. "\n");
  1005. set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
  1006. }
  1007. urb->status = status;
  1008. spin_unlock (&hcd_data_lock);
  1009. spin_unlock_irqrestore (&urb->lock, flags);
  1010. retval = unlink1 (hcd, urb);
  1011. if (retval == 0)
  1012. retval = -EINPROGRESS;
  1013. return retval;
  1014. done:
  1015. spin_unlock (&hcd_data_lock);
  1016. spin_unlock_irqrestore (&urb->lock, flags);
  1017. if (retval != -EIDRM && sys && sys->driver)
  1018. dev_dbg (sys, "hcd_unlink_urb %p fail %d\n", urb, retval);
  1019. return retval;
  1020. }
  1021. /*-------------------------------------------------------------------------*/
  1022. /* disables the endpoint: cancels any pending urbs, then synchronizes with
  1023. * the hcd to make sure all endpoint state is gone from hardware, and then
  1024. * waits until the endpoint's queue is completely drained. use for
  1025. * set_configuration, set_interface, driver removal, physical disconnect.
  1026. *
  1027. * example: a qh stored in ep->hcpriv, holding state related to endpoint
  1028. * type, maxpacket size, toggle, halt status, and scheduling.
  1029. */
  1030. void usb_hcd_endpoint_disable (struct usb_device *udev,
  1031. struct usb_host_endpoint *ep)
  1032. {
  1033. struct usb_hcd *hcd;
  1034. struct urb *urb;
  1035. hcd = bus_to_hcd(udev->bus);
  1036. local_irq_disable ();
  1037. /* ep is already gone from udev->ep_{in,out}[]; no more submits */
  1038. rescan:
  1039. spin_lock (&hcd_data_lock);
  1040. list_for_each_entry (urb, &ep->urb_list, urb_list) {
  1041. int tmp;
  1042. /* the urb may already have been unlinked */
  1043. if (urb->status != -EINPROGRESS)
  1044. continue;
  1045. usb_get_urb (urb);
  1046. spin_unlock (&hcd_data_lock);
  1047. spin_lock (&urb->lock);
  1048. tmp = urb->status;
  1049. if (tmp == -EINPROGRESS)
  1050. urb->status = -ESHUTDOWN;
  1051. spin_unlock (&urb->lock);
  1052. /* kick hcd unless it's already returning this */
  1053. if (tmp == -EINPROGRESS) {
  1054. tmp = urb->pipe;
  1055. unlink1 (hcd, urb);
  1056. dev_dbg (hcd->self.controller,
  1057. "shutdown urb %p pipe %08x ep%d%s%s\n",
  1058. urb, tmp, usb_pipeendpoint (tmp),
  1059. (tmp & USB_DIR_IN) ? "in" : "out",
  1060. ({ char *s; \
  1061. switch (usb_pipetype (tmp)) { \
  1062. case PIPE_CONTROL: s = ""; break; \
  1063. case PIPE_BULK: s = "-bulk"; break; \
  1064. case PIPE_INTERRUPT: s = "-intr"; break; \
  1065. default: s = "-iso"; break; \
  1066. }; s;}));
  1067. }
  1068. usb_put_urb (urb);
  1069. /* list contents may have changed */
  1070. goto rescan;
  1071. }
  1072. spin_unlock (&hcd_data_lock);
  1073. local_irq_enable ();
  1074. /* synchronize with the hardware, so old configuration state
  1075. * clears out immediately (and will be freed).
  1076. */
  1077. might_sleep ();
  1078. if (hcd->driver->endpoint_disable)
  1079. hcd->driver->endpoint_disable (hcd, ep);
  1080. /* Wait until the endpoint queue is completely empty. Most HCDs
  1081. * will have done this already in their endpoint_disable method,
  1082. * but some might not. And there could be root-hub control URBs
  1083. * still pending since they aren't affected by the HCDs'
  1084. * endpoint_disable methods.
  1085. */
  1086. while (!list_empty (&ep->urb_list)) {
  1087. spin_lock_irq (&hcd_data_lock);
  1088. /* The list may have changed while we acquired the spinlock */
  1089. urb = NULL;
  1090. if (!list_empty (&ep->urb_list)) {
  1091. urb = list_entry (ep->urb_list.prev, struct urb,
  1092. urb_list);
  1093. usb_get_urb (urb);
  1094. }
  1095. spin_unlock_irq (&hcd_data_lock);
  1096. if (urb) {
  1097. usb_kill_urb (urb);
  1098. usb_put_urb (urb);
  1099. }
  1100. }
  1101. }
  1102. /*-------------------------------------------------------------------------*/
  1103. #ifdef CONFIG_PM
  1104. int hcd_bus_suspend(struct usb_device *rhdev)
  1105. {
  1106. struct usb_hcd *hcd = container_of(rhdev->bus, struct usb_hcd, self);
  1107. int status;
  1108. int old_state = hcd->state;
  1109. dev_dbg(&rhdev->dev, "bus %s%s\n",
  1110. rhdev->auto_pm ? "auto-" : "", "suspend");
  1111. if (!hcd->driver->bus_suspend) {
  1112. status = -ENOENT;
  1113. } else {
  1114. hcd->state = HC_STATE_QUIESCING;
  1115. status = hcd->driver->bus_suspend(hcd);
  1116. }
  1117. if (status == 0) {
  1118. usb_set_device_state(rhdev, USB_STATE_SUSPENDED);
  1119. hcd->state = HC_STATE_SUSPENDED;
  1120. } else {
  1121. hcd->state = old_state;
  1122. dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
  1123. "suspend", status);
  1124. }
  1125. return status;
  1126. }
  1127. int hcd_bus_resume(struct usb_device *rhdev)
  1128. {
  1129. struct usb_hcd *hcd = container_of(rhdev->bus, struct usb_hcd, self);
  1130. int status;
  1131. dev_dbg(&rhdev->dev, "usb %s%s\n",
  1132. rhdev->auto_pm ? "auto-" : "", "resume");
  1133. if (!hcd->driver->bus_resume)
  1134. return -ENOENT;
  1135. if (hcd->state == HC_STATE_RUNNING)
  1136. return 0;
  1137. hcd->state = HC_STATE_RESUMING;
  1138. status = hcd->driver->bus_resume(hcd);
  1139. if (status == 0) {
  1140. /* TRSMRCY = 10 msec */
  1141. msleep(10);
  1142. usb_set_device_state(rhdev, rhdev->actconfig
  1143. ? USB_STATE_CONFIGURED
  1144. : USB_STATE_ADDRESS);
  1145. hcd->state = HC_STATE_RUNNING;
  1146. } else {
  1147. dev_dbg(&rhdev->dev, "bus %s fail, err %d\n",
  1148. "resume", status);
  1149. usb_hc_died(hcd);
  1150. }
  1151. return status;
  1152. }
  1153. /* Workqueue routine for root-hub remote wakeup */
  1154. static void hcd_resume_work(struct work_struct *work)
  1155. {
  1156. struct usb_hcd *hcd = container_of(work, struct usb_hcd, wakeup_work);
  1157. struct usb_device *udev = hcd->self.root_hub;
  1158. usb_lock_device(udev);
  1159. usb_mark_last_busy(udev);
  1160. usb_external_resume_device(udev);
  1161. usb_unlock_device(udev);
  1162. }
  1163. /**
  1164. * usb_hcd_resume_root_hub - called by HCD to resume its root hub
  1165. * @hcd: host controller for this root hub
  1166. *
  1167. * The USB host controller calls this function when its root hub is
  1168. * suspended (with the remote wakeup feature enabled) and a remote
  1169. * wakeup request is received. The routine submits a workqueue request
  1170. * to resume the root hub (that is, manage its downstream ports again).
  1171. */
  1172. void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
  1173. {
  1174. unsigned long flags;
  1175. spin_lock_irqsave (&hcd_root_hub_lock, flags);
  1176. if (hcd->rh_registered)
  1177. queue_work(ksuspend_usb_wq, &hcd->wakeup_work);
  1178. spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
  1179. }
  1180. EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub);
  1181. #endif
  1182. /*-------------------------------------------------------------------------*/
  1183. #ifdef CONFIG_USB_OTG
  1184. /**
  1185. * usb_bus_start_enum - start immediate enumeration (for OTG)
  1186. * @bus: the bus (must use hcd framework)
  1187. * @port_num: 1-based number of port; usually bus->otg_port
  1188. * Context: in_interrupt()
  1189. *
  1190. * Starts enumeration, with an immediate reset followed later by
  1191. * khubd identifying and possibly configuring the device.
  1192. * This is needed by OTG controller drivers, where it helps meet
  1193. * HNP protocol timing requirements for starting a port reset.
  1194. */
  1195. int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num)
  1196. {
  1197. struct usb_hcd *hcd;
  1198. int status = -EOPNOTSUPP;
  1199. /* NOTE: since HNP can't start by grabbing the bus's address0_sem,
  1200. * boards with root hubs hooked up to internal devices (instead of
  1201. * just the OTG port) may need more attention to resetting...
  1202. */
  1203. hcd = container_of (bus, struct usb_hcd, self);
  1204. if (port_num && hcd->driver->start_port_reset)
  1205. status = hcd->driver->start_port_reset(hcd, port_num);
  1206. /* run khubd shortly after (first) root port reset finishes;
  1207. * it may issue others, until at least 50 msecs have passed.
  1208. */
  1209. if (status == 0)
  1210. mod_timer(&hcd->rh_timer, jiffies + msecs_to_jiffies(10));
  1211. return status;
  1212. }
  1213. EXPORT_SYMBOL (usb_bus_start_enum);
  1214. #endif
  1215. /*-------------------------------------------------------------------------*/
  1216. /**
  1217. * usb_hcd_giveback_urb - return URB from HCD to device driver
  1218. * @hcd: host controller returning the URB
  1219. * @urb: urb being returned to the USB device driver.
  1220. * Context: in_interrupt()
  1221. *
  1222. * This hands the URB from HCD to its USB device driver, using its
  1223. * completion function. The HCD has freed all per-urb resources
  1224. * (and is done using urb->hcpriv). It also released all HCD locks;
  1225. * the device driver won't cause problems if it frees, modifies,
  1226. * or resubmits this URB.
  1227. */
  1228. void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb)
  1229. {
  1230. urb_unlink(hcd, urb);
  1231. usbmon_urb_complete (&hcd->self, urb);
  1232. usb_unanchor_urb(urb);
  1233. /* pass ownership to the completion handler */
  1234. urb->complete (urb);
  1235. atomic_dec (&urb->use_count);
  1236. if (unlikely (urb->reject))
  1237. wake_up (&usb_kill_urb_queue);
  1238. usb_put_urb (urb);
  1239. }
  1240. EXPORT_SYMBOL (usb_hcd_giveback_urb);
  1241. /*-------------------------------------------------------------------------*/
  1242. /**
  1243. * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
  1244. * @irq: the IRQ being raised
  1245. * @__hcd: pointer to the HCD whose IRQ is being signaled
  1246. * @r: saved hardware registers
  1247. *
  1248. * If the controller isn't HALTed, calls the driver's irq handler.
  1249. * Checks whether the controller is now dead.
  1250. */
  1251. irqreturn_t usb_hcd_irq (int irq, void *__hcd)
  1252. {
  1253. struct usb_hcd *hcd = __hcd;
  1254. int start = hcd->state;
  1255. if (unlikely(start == HC_STATE_HALT ||
  1256. !test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
  1257. return IRQ_NONE;
  1258. if (hcd->driver->irq (hcd) == IRQ_NONE)
  1259. return IRQ_NONE;
  1260. set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
  1261. if (unlikely(hcd->state == HC_STATE_HALT))
  1262. usb_hc_died (hcd);
  1263. return IRQ_HANDLED;
  1264. }
  1265. /*-------------------------------------------------------------------------*/
  1266. /**
  1267. * usb_hc_died - report abnormal shutdown of a host controller (bus glue)
  1268. * @hcd: pointer to the HCD representing the controller
  1269. *
  1270. * This is called by bus glue to report a USB host controller that died
  1271. * while operations may still have been pending. It's called automatically
  1272. * by the PCI glue, so only glue for non-PCI busses should need to call it.
  1273. */
  1274. void usb_hc_died (struct usb_hcd *hcd)
  1275. {
  1276. unsigned long flags;
  1277. dev_err (hcd->self.controller, "HC died; cleaning up\n");
  1278. spin_lock_irqsave (&hcd_root_hub_lock, flags);
  1279. if (hcd->rh_registered) {
  1280. hcd->poll_rh = 0;
  1281. /* make khubd clean up old urbs and devices */
  1282. usb_set_device_state (hcd->self.root_hub,
  1283. USB_STATE_NOTATTACHED);
  1284. usb_kick_khubd (hcd->self.root_hub);
  1285. }
  1286. spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
  1287. }
  1288. EXPORT_SYMBOL_GPL (usb_hc_died);
  1289. /*-------------------------------------------------------------------------*/
  1290. /**
  1291. * usb_create_hcd - create and initialize an HCD structure
  1292. * @driver: HC driver that will use this hcd
  1293. * @dev: device for this HC, stored in hcd->self.controller
  1294. * @bus_name: value to store in hcd->self.bus_name
  1295. * Context: !in_interrupt()
  1296. *
  1297. * Allocate a struct usb_hcd, with extra space at the end for the
  1298. * HC driver's private data. Initialize the generic members of the
  1299. * hcd structure.
  1300. *
  1301. * If memory is unavailable, returns NULL.
  1302. */
  1303. struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
  1304. struct device *dev, char *bus_name)
  1305. {
  1306. struct usb_hcd *hcd;
  1307. hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);
  1308. if (!hcd) {
  1309. dev_dbg (dev, "hcd alloc failed\n");
  1310. return NULL;
  1311. }
  1312. dev_set_drvdata(dev, hcd);
  1313. kref_init(&hcd->kref);
  1314. usb_bus_init(&hcd->self);
  1315. hcd->self.controller = dev;
  1316. hcd->self.bus_name = bus_name;
  1317. hcd->self.uses_dma = (dev->dma_mask != NULL);
  1318. init_timer(&hcd->rh_timer);
  1319. hcd->rh_timer.function = rh_timer_func;
  1320. hcd->rh_timer.data = (unsigned long) hcd;
  1321. #ifdef CONFIG_PM
  1322. INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
  1323. #endif
  1324. hcd->driver = driver;
  1325. hcd->product_desc = (driver->product_desc) ? driver->product_desc :
  1326. "USB Host Controller";
  1327. return hcd;
  1328. }
  1329. EXPORT_SYMBOL (usb_create_hcd);
  1330. static void hcd_release (struct kref *kref)
  1331. {
  1332. struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref);
  1333. kfree(hcd);
  1334. }
  1335. struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd)
  1336. {
  1337. if (hcd)
  1338. kref_get (&hcd->kref);
  1339. return hcd;
  1340. }
  1341. EXPORT_SYMBOL (usb_get_hcd);
  1342. void usb_put_hcd (struct usb_hcd *hcd)
  1343. {
  1344. if (hcd)
  1345. kref_put (&hcd->kref, hcd_release);
  1346. }
  1347. EXPORT_SYMBOL (usb_put_hcd);
  1348. /**
  1349. * usb_add_hcd - finish generic HCD structure initialization and register
  1350. * @hcd: the usb_hcd structure to initialize
  1351. * @irqnum: Interrupt line to allocate
  1352. * @irqflags: Interrupt type flags
  1353. *
  1354. * Finish the remaining parts of generic HCD initialization: allocate the
  1355. * buffers of consistent memory, register the bus, request the IRQ line,
  1356. * and call the driver's reset() and start() routines.
  1357. */
  1358. int usb_add_hcd(struct usb_hcd *hcd,
  1359. unsigned int irqnum, unsigned long irqflags)
  1360. {
  1361. int retval;
  1362. struct usb_device *rhdev;
  1363. dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
  1364. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  1365. /* HC is in reset state, but accessible. Now do the one-time init,
  1366. * bottom up so that hcds can customize the root hubs before khubd
  1367. * starts talking to them. (Note, bus id is assigned early too.)
  1368. */
  1369. if ((retval = hcd_buffer_create(hcd)) != 0) {
  1370. dev_dbg(hcd->self.controller, "pool alloc failed\n");
  1371. return retval;
  1372. }
  1373. if ((retval = usb_register_bus(&hcd->self)) < 0)
  1374. goto err_register_bus;
  1375. if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) {
  1376. dev_err(hcd->self.controller, "unable to allocate root hub\n");
  1377. retval = -ENOMEM;
  1378. goto err_allocate_root_hub;
  1379. }
  1380. rhdev->speed = (hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH :
  1381. USB_SPEED_FULL;
  1382. hcd->self.root_hub = rhdev;
  1383. /* wakeup flag init defaults to "everything works" for root hubs,
  1384. * but drivers can override it in reset() if needed, along with
  1385. * recording the overall controller's system wakeup capability.
  1386. */
  1387. device_init_wakeup(&rhdev->dev, 1);
  1388. /* "reset" is misnamed; its role is now one-time init. the controller
  1389. * should already have been reset (and boot firmware kicked off etc).
  1390. */
  1391. if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {
  1392. dev_err(hcd->self.controller, "can't setup\n");
  1393. goto err_hcd_driver_setup;
  1394. }
  1395. /* NOTE: root hub and controller capabilities may not be the same */
  1396. if (device_can_wakeup(hcd->self.controller)
  1397. && device_can_wakeup(&hcd->self.root_hub->dev))
  1398. dev_dbg(hcd->self.controller, "supports USB remote wakeup\n");
  1399. /* enable irqs just before we start the controller */
  1400. if (hcd->driver->irq) {
  1401. snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
  1402. hcd->driver->description, hcd->self.busnum);
  1403. if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags,
  1404. hcd->irq_descr, hcd)) != 0) {
  1405. dev_err(hcd->self.controller,
  1406. "request interrupt %d failed\n", irqnum);
  1407. goto err_request_irq;
  1408. }
  1409. hcd->irq = irqnum;
  1410. dev_info(hcd->self.controller, "irq %d, %s 0x%08llx\n", irqnum,
  1411. (hcd->driver->flags & HCD_MEMORY) ?
  1412. "io mem" : "io base",
  1413. (unsigned long long)hcd->rsrc_start);
  1414. } else {
  1415. hcd->irq = -1;
  1416. if (hcd->rsrc_start)
  1417. dev_info(hcd->self.controller, "%s 0x%08llx\n",
  1418. (hcd->driver->flags & HCD_MEMORY) ?
  1419. "io mem" : "io base",
  1420. (unsigned long long)hcd->rsrc_start);
  1421. }
  1422. if ((retval = hcd->driver->start(hcd)) < 0) {
  1423. dev_err(hcd->self.controller, "startup error %d\n", retval);
  1424. goto err_hcd_driver_start;
  1425. }
  1426. /* starting here, usbcore will pay attention to this root hub */
  1427. rhdev->bus_mA = min(500u, hcd->power_budget);
  1428. if ((retval = register_root_hub(hcd)) != 0)
  1429. goto err_register_root_hub;
  1430. if (hcd->uses_new_polling && hcd->poll_rh)
  1431. usb_hcd_poll_rh_status(hcd);
  1432. return retval;
  1433. err_register_root_hub:
  1434. hcd->driver->stop(hcd);
  1435. err_hcd_driver_start:
  1436. if (hcd->irq >= 0)
  1437. free_irq(irqnum, hcd);
  1438. err_request_irq:
  1439. err_hcd_driver_setup:
  1440. hcd->self.root_hub = NULL;
  1441. usb_put_dev(rhdev);
  1442. err_allocate_root_hub:
  1443. usb_deregister_bus(&hcd->self);
  1444. err_register_bus:
  1445. hcd_buffer_destroy(hcd);
  1446. return retval;
  1447. }
  1448. EXPORT_SYMBOL (usb_add_hcd);
  1449. /**
  1450. * usb_remove_hcd - shutdown processing for generic HCDs
  1451. * @hcd: the usb_hcd structure to remove
  1452. * Context: !in_interrupt()
  1453. *
  1454. * Disconnects the root hub, then reverses the effects of usb_add_hcd(),
  1455. * invoking the HCD's stop() method.
  1456. */
  1457. void usb_remove_hcd(struct usb_hcd *hcd)
  1458. {
  1459. dev_info(hcd->self.controller, "remove, state %x\n", hcd->state);
  1460. if (HC_IS_RUNNING (hcd->state))
  1461. hcd->state = HC_STATE_QUIESCING;
  1462. dev_dbg(hcd->self.controller, "roothub graceful disconnect\n");
  1463. spin_lock_irq (&hcd_root_hub_lock);
  1464. hcd->rh_registered = 0;
  1465. spin_unlock_irq (&hcd_root_hub_lock);
  1466. #ifdef CONFIG_PM
  1467. cancel_work_sync(&hcd->wakeup_work);
  1468. #endif
  1469. mutex_lock(&usb_bus_list_lock);
  1470. usb_disconnect(&hcd->self.root_hub);
  1471. mutex_unlock(&usb_bus_list_lock);
  1472. hcd->driver->stop(hcd);
  1473. hcd->state = HC_STATE_HALT;
  1474. hcd->poll_rh = 0;
  1475. del_timer_sync(&hcd->rh_timer);
  1476. if (hcd->irq >= 0)
  1477. free_irq(hcd->irq, hcd);
  1478. usb_deregister_bus(&hcd->self);
  1479. hcd_buffer_destroy(hcd);
  1480. }
  1481. EXPORT_SYMBOL (usb_remove_hcd);
  1482. void
  1483. usb_hcd_platform_shutdown(struct platform_device* dev)
  1484. {
  1485. struct usb_hcd *hcd = platform_get_drvdata(dev);
  1486. if (hcd->driver->shutdown)
  1487. hcd->driver->shutdown(hcd);
  1488. }
  1489. EXPORT_SYMBOL (usb_hcd_platform_shutdown);
  1490. /*-------------------------------------------------------------------------*/
  1491. #if defined(CONFIG_USB_MON)
  1492. struct usb_mon_operations *mon_ops;
  1493. /*
  1494. * The registration is unlocked.
  1495. * We do it this way because we do not want to lock in hot paths.
  1496. *
  1497. * Notice that the code is minimally error-proof. Because usbmon needs
  1498. * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
  1499. */
  1500. int usb_mon_register (struct usb_mon_operations *ops)
  1501. {
  1502. if (mon_ops)
  1503. return -EBUSY;
  1504. mon_ops = ops;
  1505. mb();
  1506. return 0;
  1507. }
  1508. EXPORT_SYMBOL_GPL (usb_mon_register);
  1509. void usb_mon_deregister (void)
  1510. {
  1511. if (mon_ops == NULL) {
  1512. printk(KERN_ERR "USB: monitor was not registered\n");
  1513. return;
  1514. }
  1515. mon_ops = NULL;
  1516. mb();
  1517. }
  1518. EXPORT_SYMBOL_GPL (usb_mon_deregister);
  1519. #endif /* CONFIG_USB_MON */