btusb.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. /*
  2. *
  3. * Generic Bluetooth USB driver
  4. *
  5. * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/usb.h>
  25. #include <net/bluetooth/bluetooth.h>
  26. #include <net/bluetooth/hci_core.h>
  27. #define VERSION "0.6"
  28. static bool ignore_dga;
  29. static bool ignore_csr;
  30. static bool ignore_sniffer;
  31. static bool disable_scofix;
  32. static bool force_scofix;
  33. static bool reset = 1;
  34. static struct usb_driver btusb_driver;
  35. #define BTUSB_IGNORE 0x01
  36. #define BTUSB_DIGIANSWER 0x02
  37. #define BTUSB_CSR 0x04
  38. #define BTUSB_SNIFFER 0x08
  39. #define BTUSB_BCM92035 0x10
  40. #define BTUSB_BROKEN_ISOC 0x20
  41. #define BTUSB_WRONG_SCO_MTU 0x40
  42. #define BTUSB_ATH3012 0x80
  43. static struct usb_device_id btusb_table[] = {
  44. /* Generic Bluetooth USB device */
  45. { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
  46. /* Apple-specific (Broadcom) devices */
  47. { USB_VENDOR_AND_INTERFACE_INFO(0x05ac, 0xff, 0x01, 0x01) },
  48. /* Broadcom SoftSailing reporting vendor specific */
  49. { USB_DEVICE(0x0a5c, 0x21e1) },
  50. /* Apple MacBookPro 7,1 */
  51. { USB_DEVICE(0x05ac, 0x8213) },
  52. /* Apple iMac11,1 */
  53. { USB_DEVICE(0x05ac, 0x8215) },
  54. /* Apple MacBookPro6,2 */
  55. { USB_DEVICE(0x05ac, 0x8218) },
  56. /* Apple MacBookAir3,1, MacBookAir3,2 */
  57. { USB_DEVICE(0x05ac, 0x821b) },
  58. /* Apple MacBookAir4,1 */
  59. { USB_DEVICE(0x05ac, 0x821f) },
  60. /* Apple MacBookPro8,2 */
  61. { USB_DEVICE(0x05ac, 0x821a) },
  62. /* Apple MacMini5,1 */
  63. { USB_DEVICE(0x05ac, 0x8281) },
  64. /* AVM BlueFRITZ! USB v2.0 */
  65. { USB_DEVICE(0x057c, 0x3800) },
  66. /* Bluetooth Ultraport Module from IBM */
  67. { USB_DEVICE(0x04bf, 0x030a) },
  68. /* ALPS Modules with non-standard id */
  69. { USB_DEVICE(0x044e, 0x3001) },
  70. { USB_DEVICE(0x044e, 0x3002) },
  71. /* Ericsson with non-standard id */
  72. { USB_DEVICE(0x0bdb, 0x1002) },
  73. /* Canyon CN-BTU1 with HID interfaces */
  74. { USB_DEVICE(0x0c10, 0x0000) },
  75. /* Broadcom BCM20702A0 */
  76. { USB_DEVICE(0x0b05, 0x17b5) },
  77. { USB_DEVICE(0x04ca, 0x2003) },
  78. { USB_DEVICE(0x0489, 0xe042) },
  79. { USB_DEVICE(0x413c, 0x8197) },
  80. /* Foxconn - Hon Hai */
  81. { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) },
  82. /*Broadcom devices with vendor specific id */
  83. { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01) },
  84. { } /* Terminating entry */
  85. };
  86. MODULE_DEVICE_TABLE(usb, btusb_table);
  87. static struct usb_device_id blacklist_table[] = {
  88. /* CSR BlueCore devices */
  89. { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
  90. /* Broadcom BCM2033 without firmware */
  91. { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
  92. /* Atheros 3011 with sflash firmware */
  93. { USB_DEVICE(0x0cf3, 0x3002), .driver_info = BTUSB_IGNORE },
  94. { USB_DEVICE(0x0cf3, 0xe019), .driver_info = BTUSB_IGNORE },
  95. { USB_DEVICE(0x13d3, 0x3304), .driver_info = BTUSB_IGNORE },
  96. { USB_DEVICE(0x0930, 0x0215), .driver_info = BTUSB_IGNORE },
  97. { USB_DEVICE(0x0489, 0xe03d), .driver_info = BTUSB_IGNORE },
  98. { USB_DEVICE(0x0489, 0xe027), .driver_info = BTUSB_IGNORE },
  99. /* Atheros AR9285 Malbec with sflash firmware */
  100. { USB_DEVICE(0x03f0, 0x311d), .driver_info = BTUSB_IGNORE },
  101. /* Atheros 3012 with sflash firmware */
  102. { USB_DEVICE(0x0cf3, 0x0036), .driver_info = BTUSB_ATH3012 },
  103. { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
  104. { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
  105. { USB_DEVICE(0x0cf3, 0x311d), .driver_info = BTUSB_ATH3012 },
  106. { USB_DEVICE(0x0cf3, 0x817a), .driver_info = BTUSB_ATH3012 },
  107. { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
  108. { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
  109. { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
  110. { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
  111. { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
  112. { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
  113. { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
  114. { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
  115. { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
  116. { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
  117. { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
  118. { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
  119. { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
  120. /* Atheros AR5BBU12 with sflash firmware */
  121. { USB_DEVICE(0x0489, 0xe02c), .driver_info = BTUSB_IGNORE },
  122. /* Atheros AR5BBU12 with sflash firmware */
  123. { USB_DEVICE(0x0489, 0xe03c), .driver_info = BTUSB_ATH3012 },
  124. { USB_DEVICE(0x0489, 0xe036), .driver_info = BTUSB_ATH3012 },
  125. /* Broadcom BCM2035 */
  126. { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_WRONG_SCO_MTU },
  127. { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
  128. { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
  129. /* Broadcom BCM2045 */
  130. { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
  131. { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
  132. /* IBM/Lenovo ThinkPad with Broadcom chip */
  133. { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
  134. { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
  135. /* HP laptop with Broadcom chip */
  136. { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
  137. /* Dell laptop with Broadcom chip */
  138. { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
  139. /* Dell Wireless 370 and 410 devices */
  140. { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
  141. { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
  142. /* Belkin F8T012 and F8T013 devices */
  143. { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
  144. { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
  145. /* Asus WL-BTD202 device */
  146. { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
  147. /* Kensington Bluetooth USB adapter */
  148. { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
  149. /* RTX Telecom based adapters with buggy SCO support */
  150. { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
  151. { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
  152. /* CONWISE Technology based adapters with buggy SCO support */
  153. { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
  154. /* Digianswer devices */
  155. { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
  156. { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
  157. /* CSR BlueCore Bluetooth Sniffer */
  158. { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER },
  159. /* Frontline ComProbe Bluetooth Sniffer */
  160. { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
  161. { } /* Terminating entry */
  162. };
  163. #define BTUSB_MAX_ISOC_FRAMES 10
  164. #define BTUSB_INTR_RUNNING 0
  165. #define BTUSB_BULK_RUNNING 1
  166. #define BTUSB_ISOC_RUNNING 2
  167. #define BTUSB_SUSPENDING 3
  168. #define BTUSB_DID_ISO_RESUME 4
  169. struct btusb_data {
  170. struct hci_dev *hdev;
  171. struct usb_device *udev;
  172. struct usb_interface *intf;
  173. struct usb_interface *isoc;
  174. spinlock_t lock;
  175. unsigned long flags;
  176. struct work_struct work;
  177. struct work_struct waker;
  178. struct usb_anchor tx_anchor;
  179. struct usb_anchor intr_anchor;
  180. struct usb_anchor bulk_anchor;
  181. struct usb_anchor isoc_anchor;
  182. struct usb_anchor deferred;
  183. int tx_in_flight;
  184. spinlock_t txlock;
  185. struct usb_endpoint_descriptor *intr_ep;
  186. struct usb_endpoint_descriptor *bulk_tx_ep;
  187. struct usb_endpoint_descriptor *bulk_rx_ep;
  188. struct usb_endpoint_descriptor *isoc_tx_ep;
  189. struct usb_endpoint_descriptor *isoc_rx_ep;
  190. __u8 cmdreq_type;
  191. unsigned int sco_num;
  192. int isoc_altsetting;
  193. int suspend_count;
  194. };
  195. static int inc_tx(struct btusb_data *data)
  196. {
  197. unsigned long flags;
  198. int rv;
  199. spin_lock_irqsave(&data->txlock, flags);
  200. rv = test_bit(BTUSB_SUSPENDING, &data->flags);
  201. if (!rv)
  202. data->tx_in_flight++;
  203. spin_unlock_irqrestore(&data->txlock, flags);
  204. return rv;
  205. }
  206. static void btusb_intr_complete(struct urb *urb)
  207. {
  208. struct hci_dev *hdev = urb->context;
  209. struct btusb_data *data = hci_get_drvdata(hdev);
  210. int err;
  211. BT_DBG("%s urb %p status %d count %d", hdev->name,
  212. urb, urb->status, urb->actual_length);
  213. if (!test_bit(HCI_RUNNING, &hdev->flags))
  214. return;
  215. if (urb->status == 0) {
  216. hdev->stat.byte_rx += urb->actual_length;
  217. if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
  218. urb->transfer_buffer,
  219. urb->actual_length) < 0) {
  220. BT_ERR("%s corrupted event packet", hdev->name);
  221. hdev->stat.err_rx++;
  222. }
  223. }
  224. if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
  225. return;
  226. usb_mark_last_busy(data->udev);
  227. usb_anchor_urb(urb, &data->intr_anchor);
  228. err = usb_submit_urb(urb, GFP_ATOMIC);
  229. if (err < 0) {
  230. /* -EPERM: urb is being killed;
  231. * -ENODEV: device got disconnected */
  232. if (err != -EPERM && err != -ENODEV)
  233. BT_ERR("%s urb %p failed to resubmit (%d)",
  234. hdev->name, urb, -err);
  235. usb_unanchor_urb(urb);
  236. }
  237. }
  238. static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
  239. {
  240. struct btusb_data *data = hci_get_drvdata(hdev);
  241. struct urb *urb;
  242. unsigned char *buf;
  243. unsigned int pipe;
  244. int err, size;
  245. BT_DBG("%s", hdev->name);
  246. if (!data->intr_ep)
  247. return -ENODEV;
  248. urb = usb_alloc_urb(0, mem_flags);
  249. if (!urb)
  250. return -ENOMEM;
  251. size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
  252. buf = kmalloc(size, mem_flags);
  253. if (!buf) {
  254. usb_free_urb(urb);
  255. return -ENOMEM;
  256. }
  257. pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
  258. usb_fill_int_urb(urb, data->udev, pipe, buf, size,
  259. btusb_intr_complete, hdev,
  260. data->intr_ep->bInterval);
  261. urb->transfer_flags |= URB_FREE_BUFFER;
  262. usb_anchor_urb(urb, &data->intr_anchor);
  263. err = usb_submit_urb(urb, mem_flags);
  264. if (err < 0) {
  265. if (err != -EPERM && err != -ENODEV)
  266. BT_ERR("%s urb %p submission failed (%d)",
  267. hdev->name, urb, -err);
  268. usb_unanchor_urb(urb);
  269. }
  270. usb_free_urb(urb);
  271. return err;
  272. }
  273. static void btusb_bulk_complete(struct urb *urb)
  274. {
  275. struct hci_dev *hdev = urb->context;
  276. struct btusb_data *data = hci_get_drvdata(hdev);
  277. int err;
  278. BT_DBG("%s urb %p status %d count %d", hdev->name,
  279. urb, urb->status, urb->actual_length);
  280. if (!test_bit(HCI_RUNNING, &hdev->flags))
  281. return;
  282. if (urb->status == 0) {
  283. hdev->stat.byte_rx += urb->actual_length;
  284. if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
  285. urb->transfer_buffer,
  286. urb->actual_length) < 0) {
  287. BT_ERR("%s corrupted ACL packet", hdev->name);
  288. hdev->stat.err_rx++;
  289. }
  290. }
  291. if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
  292. return;
  293. usb_anchor_urb(urb, &data->bulk_anchor);
  294. usb_mark_last_busy(data->udev);
  295. err = usb_submit_urb(urb, GFP_ATOMIC);
  296. if (err < 0) {
  297. /* -EPERM: urb is being killed;
  298. * -ENODEV: device got disconnected */
  299. if (err != -EPERM && err != -ENODEV)
  300. BT_ERR("%s urb %p failed to resubmit (%d)",
  301. hdev->name, urb, -err);
  302. usb_unanchor_urb(urb);
  303. }
  304. }
  305. static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
  306. {
  307. struct btusb_data *data = hci_get_drvdata(hdev);
  308. struct urb *urb;
  309. unsigned char *buf;
  310. unsigned int pipe;
  311. int err, size = HCI_MAX_FRAME_SIZE;
  312. BT_DBG("%s", hdev->name);
  313. if (!data->bulk_rx_ep)
  314. return -ENODEV;
  315. urb = usb_alloc_urb(0, mem_flags);
  316. if (!urb)
  317. return -ENOMEM;
  318. buf = kmalloc(size, mem_flags);
  319. if (!buf) {
  320. usb_free_urb(urb);
  321. return -ENOMEM;
  322. }
  323. pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
  324. usb_fill_bulk_urb(urb, data->udev, pipe,
  325. buf, size, btusb_bulk_complete, hdev);
  326. urb->transfer_flags |= URB_FREE_BUFFER;
  327. usb_mark_last_busy(data->udev);
  328. usb_anchor_urb(urb, &data->bulk_anchor);
  329. err = usb_submit_urb(urb, mem_flags);
  330. if (err < 0) {
  331. if (err != -EPERM && err != -ENODEV)
  332. BT_ERR("%s urb %p submission failed (%d)",
  333. hdev->name, urb, -err);
  334. usb_unanchor_urb(urb);
  335. }
  336. usb_free_urb(urb);
  337. return err;
  338. }
  339. static void btusb_isoc_complete(struct urb *urb)
  340. {
  341. struct hci_dev *hdev = urb->context;
  342. struct btusb_data *data = hci_get_drvdata(hdev);
  343. int i, err;
  344. BT_DBG("%s urb %p status %d count %d", hdev->name,
  345. urb, urb->status, urb->actual_length);
  346. if (!test_bit(HCI_RUNNING, &hdev->flags))
  347. return;
  348. if (urb->status == 0) {
  349. for (i = 0; i < urb->number_of_packets; i++) {
  350. unsigned int offset = urb->iso_frame_desc[i].offset;
  351. unsigned int length = urb->iso_frame_desc[i].actual_length;
  352. if (urb->iso_frame_desc[i].status)
  353. continue;
  354. hdev->stat.byte_rx += length;
  355. if (hci_recv_fragment(hdev, HCI_SCODATA_PKT,
  356. urb->transfer_buffer + offset,
  357. length) < 0) {
  358. BT_ERR("%s corrupted SCO packet", hdev->name);
  359. hdev->stat.err_rx++;
  360. }
  361. }
  362. }
  363. if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
  364. return;
  365. usb_anchor_urb(urb, &data->isoc_anchor);
  366. err = usb_submit_urb(urb, GFP_ATOMIC);
  367. if (err < 0) {
  368. /* -EPERM: urb is being killed;
  369. * -ENODEV: device got disconnected */
  370. if (err != -EPERM && err != -ENODEV)
  371. BT_ERR("%s urb %p failed to resubmit (%d)",
  372. hdev->name, urb, -err);
  373. usb_unanchor_urb(urb);
  374. }
  375. }
  376. static inline void __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
  377. {
  378. int i, offset = 0;
  379. BT_DBG("len %d mtu %d", len, mtu);
  380. for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
  381. i++, offset += mtu, len -= mtu) {
  382. urb->iso_frame_desc[i].offset = offset;
  383. urb->iso_frame_desc[i].length = mtu;
  384. }
  385. if (len && i < BTUSB_MAX_ISOC_FRAMES) {
  386. urb->iso_frame_desc[i].offset = offset;
  387. urb->iso_frame_desc[i].length = len;
  388. i++;
  389. }
  390. urb->number_of_packets = i;
  391. }
  392. static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
  393. {
  394. struct btusb_data *data = hci_get_drvdata(hdev);
  395. struct urb *urb;
  396. unsigned char *buf;
  397. unsigned int pipe;
  398. int err, size;
  399. BT_DBG("%s", hdev->name);
  400. if (!data->isoc_rx_ep)
  401. return -ENODEV;
  402. urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
  403. if (!urb)
  404. return -ENOMEM;
  405. size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
  406. BTUSB_MAX_ISOC_FRAMES;
  407. buf = kmalloc(size, mem_flags);
  408. if (!buf) {
  409. usb_free_urb(urb);
  410. return -ENOMEM;
  411. }
  412. pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
  413. usb_fill_int_urb(urb, data->udev, pipe, buf, size, btusb_isoc_complete,
  414. hdev, data->isoc_rx_ep->bInterval);
  415. urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
  416. __fill_isoc_descriptor(urb, size,
  417. le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
  418. usb_anchor_urb(urb, &data->isoc_anchor);
  419. err = usb_submit_urb(urb, mem_flags);
  420. if (err < 0) {
  421. if (err != -EPERM && err != -ENODEV)
  422. BT_ERR("%s urb %p submission failed (%d)",
  423. hdev->name, urb, -err);
  424. usb_unanchor_urb(urb);
  425. }
  426. usb_free_urb(urb);
  427. return err;
  428. }
  429. static void btusb_tx_complete(struct urb *urb)
  430. {
  431. struct sk_buff *skb = urb->context;
  432. struct hci_dev *hdev = (struct hci_dev *) skb->dev;
  433. struct btusb_data *data = hci_get_drvdata(hdev);
  434. BT_DBG("%s urb %p status %d count %d", hdev->name,
  435. urb, urb->status, urb->actual_length);
  436. if (!test_bit(HCI_RUNNING, &hdev->flags))
  437. goto done;
  438. if (!urb->status)
  439. hdev->stat.byte_tx += urb->transfer_buffer_length;
  440. else
  441. hdev->stat.err_tx++;
  442. done:
  443. spin_lock(&data->txlock);
  444. data->tx_in_flight--;
  445. spin_unlock(&data->txlock);
  446. kfree(urb->setup_packet);
  447. kfree_skb(skb);
  448. }
  449. static void btusb_isoc_tx_complete(struct urb *urb)
  450. {
  451. struct sk_buff *skb = urb->context;
  452. struct hci_dev *hdev = (struct hci_dev *) skb->dev;
  453. BT_DBG("%s urb %p status %d count %d", hdev->name,
  454. urb, urb->status, urb->actual_length);
  455. if (!test_bit(HCI_RUNNING, &hdev->flags))
  456. goto done;
  457. if (!urb->status)
  458. hdev->stat.byte_tx += urb->transfer_buffer_length;
  459. else
  460. hdev->stat.err_tx++;
  461. done:
  462. kfree(urb->setup_packet);
  463. kfree_skb(skb);
  464. }
  465. static int btusb_open(struct hci_dev *hdev)
  466. {
  467. struct btusb_data *data = hci_get_drvdata(hdev);
  468. int err;
  469. BT_DBG("%s", hdev->name);
  470. err = usb_autopm_get_interface(data->intf);
  471. if (err < 0)
  472. return err;
  473. data->intf->needs_remote_wakeup = 1;
  474. if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
  475. goto done;
  476. if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
  477. goto done;
  478. err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
  479. if (err < 0)
  480. goto failed;
  481. err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
  482. if (err < 0) {
  483. usb_kill_anchored_urbs(&data->intr_anchor);
  484. goto failed;
  485. }
  486. set_bit(BTUSB_BULK_RUNNING, &data->flags);
  487. btusb_submit_bulk_urb(hdev, GFP_KERNEL);
  488. done:
  489. usb_autopm_put_interface(data->intf);
  490. return 0;
  491. failed:
  492. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  493. clear_bit(HCI_RUNNING, &hdev->flags);
  494. usb_autopm_put_interface(data->intf);
  495. return err;
  496. }
  497. static void btusb_stop_traffic(struct btusb_data *data)
  498. {
  499. usb_kill_anchored_urbs(&data->intr_anchor);
  500. usb_kill_anchored_urbs(&data->bulk_anchor);
  501. usb_kill_anchored_urbs(&data->isoc_anchor);
  502. }
  503. static int btusb_close(struct hci_dev *hdev)
  504. {
  505. struct btusb_data *data = hci_get_drvdata(hdev);
  506. int err;
  507. BT_DBG("%s", hdev->name);
  508. if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
  509. return 0;
  510. cancel_work_sync(&data->work);
  511. cancel_work_sync(&data->waker);
  512. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  513. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  514. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  515. btusb_stop_traffic(data);
  516. err = usb_autopm_get_interface(data->intf);
  517. if (err < 0)
  518. goto failed;
  519. data->intf->needs_remote_wakeup = 0;
  520. usb_autopm_put_interface(data->intf);
  521. failed:
  522. usb_scuttle_anchored_urbs(&data->deferred);
  523. return 0;
  524. }
  525. static int btusb_flush(struct hci_dev *hdev)
  526. {
  527. struct btusb_data *data = hci_get_drvdata(hdev);
  528. BT_DBG("%s", hdev->name);
  529. usb_kill_anchored_urbs(&data->tx_anchor);
  530. return 0;
  531. }
  532. static int btusb_send_frame(struct sk_buff *skb)
  533. {
  534. struct hci_dev *hdev = (struct hci_dev *) skb->dev;
  535. struct btusb_data *data = hci_get_drvdata(hdev);
  536. struct usb_ctrlrequest *dr;
  537. struct urb *urb;
  538. unsigned int pipe;
  539. int err;
  540. BT_DBG("%s", hdev->name);
  541. if (!test_bit(HCI_RUNNING, &hdev->flags))
  542. return -EBUSY;
  543. switch (bt_cb(skb)->pkt_type) {
  544. case HCI_COMMAND_PKT:
  545. urb = usb_alloc_urb(0, GFP_ATOMIC);
  546. if (!urb)
  547. return -ENOMEM;
  548. dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
  549. if (!dr) {
  550. usb_free_urb(urb);
  551. return -ENOMEM;
  552. }
  553. dr->bRequestType = data->cmdreq_type;
  554. dr->bRequest = 0;
  555. dr->wIndex = 0;
  556. dr->wValue = 0;
  557. dr->wLength = __cpu_to_le16(skb->len);
  558. pipe = usb_sndctrlpipe(data->udev, 0x00);
  559. usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
  560. skb->data, skb->len, btusb_tx_complete, skb);
  561. hdev->stat.cmd_tx++;
  562. break;
  563. case HCI_ACLDATA_PKT:
  564. if (!data->bulk_tx_ep)
  565. return -ENODEV;
  566. urb = usb_alloc_urb(0, GFP_ATOMIC);
  567. if (!urb)
  568. return -ENOMEM;
  569. pipe = usb_sndbulkpipe(data->udev,
  570. data->bulk_tx_ep->bEndpointAddress);
  571. usb_fill_bulk_urb(urb, data->udev, pipe,
  572. skb->data, skb->len, btusb_tx_complete, skb);
  573. hdev->stat.acl_tx++;
  574. break;
  575. case HCI_SCODATA_PKT:
  576. if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1)
  577. return -ENODEV;
  578. urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);
  579. if (!urb)
  580. return -ENOMEM;
  581. pipe = usb_sndisocpipe(data->udev,
  582. data->isoc_tx_ep->bEndpointAddress);
  583. usb_fill_int_urb(urb, data->udev, pipe,
  584. skb->data, skb->len, btusb_isoc_tx_complete,
  585. skb, data->isoc_tx_ep->bInterval);
  586. urb->transfer_flags = URB_ISO_ASAP;
  587. __fill_isoc_descriptor(urb, skb->len,
  588. le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
  589. hdev->stat.sco_tx++;
  590. goto skip_waking;
  591. default:
  592. return -EILSEQ;
  593. }
  594. err = inc_tx(data);
  595. if (err) {
  596. usb_anchor_urb(urb, &data->deferred);
  597. schedule_work(&data->waker);
  598. err = 0;
  599. goto done;
  600. }
  601. skip_waking:
  602. usb_anchor_urb(urb, &data->tx_anchor);
  603. err = usb_submit_urb(urb, GFP_ATOMIC);
  604. if (err < 0) {
  605. if (err != -EPERM && err != -ENODEV)
  606. BT_ERR("%s urb %p submission failed (%d)",
  607. hdev->name, urb, -err);
  608. kfree(urb->setup_packet);
  609. usb_unanchor_urb(urb);
  610. } else {
  611. usb_mark_last_busy(data->udev);
  612. }
  613. done:
  614. usb_free_urb(urb);
  615. return err;
  616. }
  617. static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
  618. {
  619. struct btusb_data *data = hci_get_drvdata(hdev);
  620. BT_DBG("%s evt %d", hdev->name, evt);
  621. if (hdev->conn_hash.sco_num != data->sco_num) {
  622. data->sco_num = hdev->conn_hash.sco_num;
  623. schedule_work(&data->work);
  624. }
  625. }
  626. static inline int __set_isoc_interface(struct hci_dev *hdev, int altsetting)
  627. {
  628. struct btusb_data *data = hci_get_drvdata(hdev);
  629. struct usb_interface *intf = data->isoc;
  630. struct usb_endpoint_descriptor *ep_desc;
  631. int i, err;
  632. if (!data->isoc)
  633. return -ENODEV;
  634. err = usb_set_interface(data->udev, 1, altsetting);
  635. if (err < 0) {
  636. BT_ERR("%s setting interface failed (%d)", hdev->name, -err);
  637. return err;
  638. }
  639. data->isoc_altsetting = altsetting;
  640. data->isoc_tx_ep = NULL;
  641. data->isoc_rx_ep = NULL;
  642. for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
  643. ep_desc = &intf->cur_altsetting->endpoint[i].desc;
  644. if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
  645. data->isoc_tx_ep = ep_desc;
  646. continue;
  647. }
  648. if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
  649. data->isoc_rx_ep = ep_desc;
  650. continue;
  651. }
  652. }
  653. if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
  654. BT_ERR("%s invalid SCO descriptors", hdev->name);
  655. return -ENODEV;
  656. }
  657. return 0;
  658. }
  659. static void btusb_work(struct work_struct *work)
  660. {
  661. struct btusb_data *data = container_of(work, struct btusb_data, work);
  662. struct hci_dev *hdev = data->hdev;
  663. int new_alts;
  664. int err;
  665. if (hdev->conn_hash.sco_num > 0) {
  666. if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
  667. err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
  668. if (err < 0) {
  669. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  670. usb_kill_anchored_urbs(&data->isoc_anchor);
  671. return;
  672. }
  673. set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
  674. }
  675. if (hdev->voice_setting & 0x0020) {
  676. static const int alts[3] = { 2, 4, 5 };
  677. new_alts = alts[hdev->conn_hash.sco_num - 1];
  678. } else {
  679. new_alts = hdev->conn_hash.sco_num;
  680. }
  681. if (data->isoc_altsetting != new_alts) {
  682. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  683. usb_kill_anchored_urbs(&data->isoc_anchor);
  684. if (__set_isoc_interface(hdev, new_alts) < 0)
  685. return;
  686. }
  687. if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
  688. if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
  689. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  690. else
  691. btusb_submit_isoc_urb(hdev, GFP_KERNEL);
  692. }
  693. } else {
  694. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  695. usb_kill_anchored_urbs(&data->isoc_anchor);
  696. __set_isoc_interface(hdev, 0);
  697. if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
  698. usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
  699. }
  700. }
  701. static void btusb_waker(struct work_struct *work)
  702. {
  703. struct btusb_data *data = container_of(work, struct btusb_data, waker);
  704. int err;
  705. err = usb_autopm_get_interface(data->intf);
  706. if (err < 0)
  707. return;
  708. usb_autopm_put_interface(data->intf);
  709. }
  710. static int btusb_setup_bcm92035(struct hci_dev *hdev)
  711. {
  712. struct sk_buff *skb;
  713. u8 val = 0x00;
  714. BT_DBG("%s", hdev->name);
  715. skb = __hci_cmd_sync(hdev, 0xfc3b, 1, &val, HCI_INIT_TIMEOUT);
  716. if (IS_ERR(skb))
  717. BT_ERR("BCM92035 command failed (%ld)", -PTR_ERR(skb));
  718. else
  719. kfree_skb(skb);
  720. return 0;
  721. }
  722. static int btusb_probe(struct usb_interface *intf,
  723. const struct usb_device_id *id)
  724. {
  725. struct usb_endpoint_descriptor *ep_desc;
  726. struct btusb_data *data;
  727. struct hci_dev *hdev;
  728. int i, err;
  729. BT_DBG("intf %p id %p", intf, id);
  730. /* interface numbers are hardcoded in the spec */
  731. if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
  732. return -ENODEV;
  733. if (!id->driver_info) {
  734. const struct usb_device_id *match;
  735. match = usb_match_id(intf, blacklist_table);
  736. if (match)
  737. id = match;
  738. }
  739. if (id->driver_info == BTUSB_IGNORE)
  740. return -ENODEV;
  741. if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER)
  742. return -ENODEV;
  743. if (ignore_csr && id->driver_info & BTUSB_CSR)
  744. return -ENODEV;
  745. if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER)
  746. return -ENODEV;
  747. if (id->driver_info & BTUSB_ATH3012) {
  748. struct usb_device *udev = interface_to_usbdev(intf);
  749. /* Old firmware would otherwise let ath3k driver load
  750. * patch and sysconfig files */
  751. if (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x0001)
  752. return -ENODEV;
  753. }
  754. data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
  755. if (!data)
  756. return -ENOMEM;
  757. for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
  758. ep_desc = &intf->cur_altsetting->endpoint[i].desc;
  759. if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
  760. data->intr_ep = ep_desc;
  761. continue;
  762. }
  763. if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
  764. data->bulk_tx_ep = ep_desc;
  765. continue;
  766. }
  767. if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
  768. data->bulk_rx_ep = ep_desc;
  769. continue;
  770. }
  771. }
  772. if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep)
  773. return -ENODEV;
  774. data->cmdreq_type = USB_TYPE_CLASS;
  775. data->udev = interface_to_usbdev(intf);
  776. data->intf = intf;
  777. spin_lock_init(&data->lock);
  778. INIT_WORK(&data->work, btusb_work);
  779. INIT_WORK(&data->waker, btusb_waker);
  780. spin_lock_init(&data->txlock);
  781. init_usb_anchor(&data->tx_anchor);
  782. init_usb_anchor(&data->intr_anchor);
  783. init_usb_anchor(&data->bulk_anchor);
  784. init_usb_anchor(&data->isoc_anchor);
  785. init_usb_anchor(&data->deferred);
  786. hdev = hci_alloc_dev();
  787. if (!hdev)
  788. return -ENOMEM;
  789. hdev->bus = HCI_USB;
  790. hci_set_drvdata(hdev, data);
  791. data->hdev = hdev;
  792. SET_HCIDEV_DEV(hdev, &intf->dev);
  793. hdev->open = btusb_open;
  794. hdev->close = btusb_close;
  795. hdev->flush = btusb_flush;
  796. hdev->send = btusb_send_frame;
  797. hdev->notify = btusb_notify;
  798. if (id->driver_info & BTUSB_BCM92035)
  799. hdev->setup = btusb_setup_bcm92035;
  800. /* Interface numbers are hardcoded in the specification */
  801. data->isoc = usb_ifnum_to_if(data->udev, 1);
  802. if (!reset)
  803. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  804. if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
  805. if (!disable_scofix)
  806. set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
  807. }
  808. if (id->driver_info & BTUSB_BROKEN_ISOC)
  809. data->isoc = NULL;
  810. if (id->driver_info & BTUSB_DIGIANSWER) {
  811. data->cmdreq_type = USB_TYPE_VENDOR;
  812. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  813. }
  814. if (id->driver_info & BTUSB_CSR) {
  815. struct usb_device *udev = data->udev;
  816. /* Old firmware would otherwise execute USB reset */
  817. if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117)
  818. set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
  819. }
  820. if (id->driver_info & BTUSB_SNIFFER) {
  821. struct usb_device *udev = data->udev;
  822. /* New sniffer firmware has crippled HCI interface */
  823. if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
  824. set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
  825. data->isoc = NULL;
  826. }
  827. if (data->isoc) {
  828. err = usb_driver_claim_interface(&btusb_driver,
  829. data->isoc, data);
  830. if (err < 0) {
  831. hci_free_dev(hdev);
  832. return err;
  833. }
  834. }
  835. err = hci_register_dev(hdev);
  836. if (err < 0) {
  837. hci_free_dev(hdev);
  838. return err;
  839. }
  840. usb_set_intfdata(intf, data);
  841. return 0;
  842. }
  843. static void btusb_disconnect(struct usb_interface *intf)
  844. {
  845. struct btusb_data *data = usb_get_intfdata(intf);
  846. struct hci_dev *hdev;
  847. BT_DBG("intf %p", intf);
  848. if (!data)
  849. return;
  850. hdev = data->hdev;
  851. usb_set_intfdata(data->intf, NULL);
  852. if (data->isoc)
  853. usb_set_intfdata(data->isoc, NULL);
  854. hci_unregister_dev(hdev);
  855. if (intf == data->isoc)
  856. usb_driver_release_interface(&btusb_driver, data->intf);
  857. else if (data->isoc)
  858. usb_driver_release_interface(&btusb_driver, data->isoc);
  859. hci_free_dev(hdev);
  860. }
  861. #ifdef CONFIG_PM
  862. static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
  863. {
  864. struct btusb_data *data = usb_get_intfdata(intf);
  865. BT_DBG("intf %p", intf);
  866. if (data->suspend_count++)
  867. return 0;
  868. spin_lock_irq(&data->txlock);
  869. if (!(PMSG_IS_AUTO(message) && data->tx_in_flight)) {
  870. set_bit(BTUSB_SUSPENDING, &data->flags);
  871. spin_unlock_irq(&data->txlock);
  872. } else {
  873. spin_unlock_irq(&data->txlock);
  874. data->suspend_count--;
  875. return -EBUSY;
  876. }
  877. cancel_work_sync(&data->work);
  878. btusb_stop_traffic(data);
  879. usb_kill_anchored_urbs(&data->tx_anchor);
  880. return 0;
  881. }
  882. static void play_deferred(struct btusb_data *data)
  883. {
  884. struct urb *urb;
  885. int err;
  886. while ((urb = usb_get_from_anchor(&data->deferred))) {
  887. err = usb_submit_urb(urb, GFP_ATOMIC);
  888. if (err < 0)
  889. break;
  890. data->tx_in_flight++;
  891. }
  892. usb_scuttle_anchored_urbs(&data->deferred);
  893. }
  894. static int btusb_resume(struct usb_interface *intf)
  895. {
  896. struct btusb_data *data = usb_get_intfdata(intf);
  897. struct hci_dev *hdev = data->hdev;
  898. int err = 0;
  899. BT_DBG("intf %p", intf);
  900. if (--data->suspend_count)
  901. return 0;
  902. if (!test_bit(HCI_RUNNING, &hdev->flags))
  903. goto done;
  904. if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
  905. err = btusb_submit_intr_urb(hdev, GFP_NOIO);
  906. if (err < 0) {
  907. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  908. goto failed;
  909. }
  910. }
  911. if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
  912. err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
  913. if (err < 0) {
  914. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  915. goto failed;
  916. }
  917. btusb_submit_bulk_urb(hdev, GFP_NOIO);
  918. }
  919. if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
  920. if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
  921. clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
  922. else
  923. btusb_submit_isoc_urb(hdev, GFP_NOIO);
  924. }
  925. spin_lock_irq(&data->txlock);
  926. play_deferred(data);
  927. clear_bit(BTUSB_SUSPENDING, &data->flags);
  928. spin_unlock_irq(&data->txlock);
  929. schedule_work(&data->work);
  930. return 0;
  931. failed:
  932. usb_scuttle_anchored_urbs(&data->deferred);
  933. done:
  934. spin_lock_irq(&data->txlock);
  935. clear_bit(BTUSB_SUSPENDING, &data->flags);
  936. spin_unlock_irq(&data->txlock);
  937. return err;
  938. }
  939. #endif
  940. static struct usb_driver btusb_driver = {
  941. .name = "btusb",
  942. .probe = btusb_probe,
  943. .disconnect = btusb_disconnect,
  944. #ifdef CONFIG_PM
  945. .suspend = btusb_suspend,
  946. .resume = btusb_resume,
  947. #endif
  948. .id_table = btusb_table,
  949. .supports_autosuspend = 1,
  950. .disable_hub_initiated_lpm = 1,
  951. };
  952. module_usb_driver(btusb_driver);
  953. module_param(ignore_dga, bool, 0644);
  954. MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
  955. module_param(ignore_csr, bool, 0644);
  956. MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
  957. module_param(ignore_sniffer, bool, 0644);
  958. MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
  959. module_param(disable_scofix, bool, 0644);
  960. MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
  961. module_param(force_scofix, bool, 0644);
  962. MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
  963. module_param(reset, bool, 0644);
  964. MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
  965. MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
  966. MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
  967. MODULE_VERSION(VERSION);
  968. MODULE_LICENSE("GPL");