usb.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. /*
  2. * Copyright (c) 2007-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/usb.h>
  19. #include "debug.h"
  20. #include "core.h"
  21. /* constants */
  22. #define TX_URB_COUNT 32
  23. #define RX_URB_COUNT 32
  24. #define ATH6KL_USB_RX_BUFFER_SIZE 1700
  25. /* tx/rx pipes for usb */
  26. enum ATH6KL_USB_PIPE_ID {
  27. ATH6KL_USB_PIPE_TX_CTRL = 0,
  28. ATH6KL_USB_PIPE_TX_DATA_LP,
  29. ATH6KL_USB_PIPE_TX_DATA_MP,
  30. ATH6KL_USB_PIPE_TX_DATA_HP,
  31. ATH6KL_USB_PIPE_RX_CTRL,
  32. ATH6KL_USB_PIPE_RX_DATA,
  33. ATH6KL_USB_PIPE_RX_DATA2,
  34. ATH6KL_USB_PIPE_RX_INT,
  35. ATH6KL_USB_PIPE_MAX
  36. };
  37. #define ATH6KL_USB_PIPE_INVALID ATH6KL_USB_PIPE_MAX
  38. struct ath6kl_usb_pipe {
  39. struct list_head urb_list_head;
  40. struct usb_anchor urb_submitted;
  41. u32 urb_alloc;
  42. u32 urb_cnt;
  43. u32 urb_cnt_thresh;
  44. unsigned int usb_pipe_handle;
  45. u32 flags;
  46. u8 ep_address;
  47. u8 logical_pipe_num;
  48. struct ath6kl_usb *ar_usb;
  49. u16 max_packet_size;
  50. struct work_struct io_complete_work;
  51. struct sk_buff_head io_comp_queue;
  52. struct usb_endpoint_descriptor *ep_desc;
  53. };
  54. #define ATH6KL_USB_PIPE_FLAG_TX (1 << 0)
  55. /* usb device object */
  56. struct ath6kl_usb {
  57. /* protects pipe->urb_list_head and pipe->urb_cnt */
  58. spinlock_t cs_lock;
  59. struct usb_device *udev;
  60. struct usb_interface *interface;
  61. struct ath6kl_usb_pipe pipes[ATH6KL_USB_PIPE_MAX];
  62. u8 *diag_cmd_buffer;
  63. u8 *diag_resp_buffer;
  64. struct ath6kl *ar;
  65. };
  66. /* usb urb object */
  67. struct ath6kl_urb_context {
  68. struct list_head link;
  69. struct ath6kl_usb_pipe *pipe;
  70. struct sk_buff *skb;
  71. struct ath6kl *ar;
  72. };
  73. /* USB endpoint definitions */
  74. #define ATH6KL_USB_EP_ADDR_APP_CTRL_IN 0x81
  75. #define ATH6KL_USB_EP_ADDR_APP_DATA_IN 0x82
  76. #define ATH6KL_USB_EP_ADDR_APP_DATA2_IN 0x83
  77. #define ATH6KL_USB_EP_ADDR_APP_INT_IN 0x84
  78. #define ATH6KL_USB_EP_ADDR_APP_CTRL_OUT 0x01
  79. #define ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT 0x02
  80. #define ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT 0x03
  81. #define ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT 0x04
  82. /* diagnostic command defnitions */
  83. #define ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD 1
  84. #define ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP 2
  85. #define ATH6KL_USB_CONTROL_REQ_DIAG_CMD 3
  86. #define ATH6KL_USB_CONTROL_REQ_DIAG_RESP 4
  87. #define ATH6KL_USB_CTRL_DIAG_CC_READ 0
  88. #define ATH6KL_USB_CTRL_DIAG_CC_WRITE 1
  89. struct ath6kl_usb_ctrl_diag_cmd_write {
  90. __le32 cmd;
  91. __le32 address;
  92. __le32 value;
  93. __le32 _pad[1];
  94. } __packed;
  95. struct ath6kl_usb_ctrl_diag_cmd_read {
  96. __le32 cmd;
  97. __le32 address;
  98. } __packed;
  99. struct ath6kl_usb_ctrl_diag_resp_read {
  100. __le32 value;
  101. } __packed;
  102. /* function declarations */
  103. static void ath6kl_usb_recv_complete(struct urb *urb);
  104. #define ATH6KL_USB_IS_BULK_EP(attr) (((attr) & 3) == 0x02)
  105. #define ATH6KL_USB_IS_INT_EP(attr) (((attr) & 3) == 0x03)
  106. #define ATH6KL_USB_IS_ISOC_EP(attr) (((attr) & 3) == 0x01)
  107. #define ATH6KL_USB_IS_DIR_IN(addr) ((addr) & 0x80)
  108. /* pipe/urb operations */
  109. static struct ath6kl_urb_context *
  110. ath6kl_usb_alloc_urb_from_pipe(struct ath6kl_usb_pipe *pipe)
  111. {
  112. struct ath6kl_urb_context *urb_context = NULL;
  113. unsigned long flags;
  114. spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
  115. if (!list_empty(&pipe->urb_list_head)) {
  116. urb_context =
  117. list_first_entry(&pipe->urb_list_head,
  118. struct ath6kl_urb_context, link);
  119. list_del(&urb_context->link);
  120. pipe->urb_cnt--;
  121. }
  122. spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags);
  123. return urb_context;
  124. }
  125. static void ath6kl_usb_free_urb_to_pipe(struct ath6kl_usb_pipe *pipe,
  126. struct ath6kl_urb_context *urb_context)
  127. {
  128. unsigned long flags;
  129. spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
  130. pipe->urb_cnt++;
  131. list_add(&urb_context->link, &pipe->urb_list_head);
  132. spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags);
  133. }
  134. static void ath6kl_usb_cleanup_recv_urb(struct ath6kl_urb_context *urb_context)
  135. {
  136. dev_kfree_skb(urb_context->skb);
  137. urb_context->skb = NULL;
  138. ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
  139. }
  140. static inline struct ath6kl_usb *ath6kl_usb_priv(struct ath6kl *ar)
  141. {
  142. return ar->hif_priv;
  143. }
  144. /* pipe resource allocation/cleanup */
  145. static int ath6kl_usb_alloc_pipe_resources(struct ath6kl_usb_pipe *pipe,
  146. int urb_cnt)
  147. {
  148. struct ath6kl_urb_context *urb_context;
  149. int status = 0, i;
  150. INIT_LIST_HEAD(&pipe->urb_list_head);
  151. init_usb_anchor(&pipe->urb_submitted);
  152. for (i = 0; i < urb_cnt; i++) {
  153. urb_context = kzalloc(sizeof(struct ath6kl_urb_context),
  154. GFP_KERNEL);
  155. if (urb_context == NULL) {
  156. status = -ENOMEM;
  157. goto fail_alloc_pipe_resources;
  158. }
  159. urb_context->pipe = pipe;
  160. /*
  161. * we are only allocate the urb contexts here, the actual URB
  162. * is allocated from the kernel as needed to do a transaction
  163. */
  164. pipe->urb_alloc++;
  165. ath6kl_usb_free_urb_to_pipe(pipe, urb_context);
  166. }
  167. ath6kl_dbg(ATH6KL_DBG_USB,
  168. "ath6kl usb: alloc resources lpipe:%d hpipe:0x%X urbs:%d\n",
  169. pipe->logical_pipe_num, pipe->usb_pipe_handle,
  170. pipe->urb_alloc);
  171. fail_alloc_pipe_resources:
  172. return status;
  173. }
  174. static void ath6kl_usb_free_pipe_resources(struct ath6kl_usb_pipe *pipe)
  175. {
  176. struct ath6kl_urb_context *urb_context;
  177. if (pipe->ar_usb == NULL) {
  178. /* nothing allocated for this pipe */
  179. return;
  180. }
  181. ath6kl_dbg(ATH6KL_DBG_USB,
  182. "ath6kl usb: free resources lpipe:%d"
  183. "hpipe:0x%X urbs:%d avail:%d\n",
  184. pipe->logical_pipe_num, pipe->usb_pipe_handle,
  185. pipe->urb_alloc, pipe->urb_cnt);
  186. if (pipe->urb_alloc != pipe->urb_cnt) {
  187. ath6kl_dbg(ATH6KL_DBG_USB,
  188. "ath6kl usb: urb leak! lpipe:%d"
  189. "hpipe:0x%X urbs:%d avail:%d\n",
  190. pipe->logical_pipe_num, pipe->usb_pipe_handle,
  191. pipe->urb_alloc, pipe->urb_cnt);
  192. }
  193. while (true) {
  194. urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
  195. if (urb_context == NULL)
  196. break;
  197. kfree(urb_context);
  198. }
  199. }
  200. static void ath6kl_usb_cleanup_pipe_resources(struct ath6kl_usb *ar_usb)
  201. {
  202. int i;
  203. for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++)
  204. ath6kl_usb_free_pipe_resources(&ar_usb->pipes[i]);
  205. }
  206. static u8 ath6kl_usb_get_logical_pipe_num(struct ath6kl_usb *ar_usb,
  207. u8 ep_address, int *urb_count)
  208. {
  209. u8 pipe_num = ATH6KL_USB_PIPE_INVALID;
  210. switch (ep_address) {
  211. case ATH6KL_USB_EP_ADDR_APP_CTRL_IN:
  212. pipe_num = ATH6KL_USB_PIPE_RX_CTRL;
  213. *urb_count = RX_URB_COUNT;
  214. break;
  215. case ATH6KL_USB_EP_ADDR_APP_DATA_IN:
  216. pipe_num = ATH6KL_USB_PIPE_RX_DATA;
  217. *urb_count = RX_URB_COUNT;
  218. break;
  219. case ATH6KL_USB_EP_ADDR_APP_INT_IN:
  220. pipe_num = ATH6KL_USB_PIPE_RX_INT;
  221. *urb_count = RX_URB_COUNT;
  222. break;
  223. case ATH6KL_USB_EP_ADDR_APP_DATA2_IN:
  224. pipe_num = ATH6KL_USB_PIPE_RX_DATA2;
  225. *urb_count = RX_URB_COUNT;
  226. break;
  227. case ATH6KL_USB_EP_ADDR_APP_CTRL_OUT:
  228. pipe_num = ATH6KL_USB_PIPE_TX_CTRL;
  229. *urb_count = TX_URB_COUNT;
  230. break;
  231. case ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT:
  232. pipe_num = ATH6KL_USB_PIPE_TX_DATA_LP;
  233. *urb_count = TX_URB_COUNT;
  234. break;
  235. case ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT:
  236. pipe_num = ATH6KL_USB_PIPE_TX_DATA_MP;
  237. *urb_count = TX_URB_COUNT;
  238. break;
  239. case ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT:
  240. pipe_num = ATH6KL_USB_PIPE_TX_DATA_HP;
  241. *urb_count = TX_URB_COUNT;
  242. break;
  243. default:
  244. /* note: there may be endpoints not currently used */
  245. break;
  246. }
  247. return pipe_num;
  248. }
  249. static int ath6kl_usb_setup_pipe_resources(struct ath6kl_usb *ar_usb)
  250. {
  251. struct usb_interface *interface = ar_usb->interface;
  252. struct usb_host_interface *iface_desc = interface->cur_altsetting;
  253. struct usb_endpoint_descriptor *endpoint;
  254. struct ath6kl_usb_pipe *pipe;
  255. int i, urbcount, status = 0;
  256. u8 pipe_num;
  257. ath6kl_dbg(ATH6KL_DBG_USB, "setting up USB Pipes using interface\n");
  258. /* walk decriptors and setup pipes */
  259. for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
  260. endpoint = &iface_desc->endpoint[i].desc;
  261. if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) {
  262. ath6kl_dbg(ATH6KL_DBG_USB,
  263. "%s Bulk Ep:0x%2.2X maxpktsz:%d\n",
  264. ATH6KL_USB_IS_DIR_IN
  265. (endpoint->bEndpointAddress) ?
  266. "RX" : "TX", endpoint->bEndpointAddress,
  267. le16_to_cpu(endpoint->wMaxPacketSize));
  268. } else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) {
  269. ath6kl_dbg(ATH6KL_DBG_USB,
  270. "%s Int Ep:0x%2.2X maxpktsz:%d interval:%d\n",
  271. ATH6KL_USB_IS_DIR_IN
  272. (endpoint->bEndpointAddress) ?
  273. "RX" : "TX", endpoint->bEndpointAddress,
  274. le16_to_cpu(endpoint->wMaxPacketSize),
  275. endpoint->bInterval);
  276. } else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) {
  277. /* TODO for ISO */
  278. ath6kl_dbg(ATH6KL_DBG_USB,
  279. "%s ISOC Ep:0x%2.2X maxpktsz:%d interval:%d\n",
  280. ATH6KL_USB_IS_DIR_IN
  281. (endpoint->bEndpointAddress) ?
  282. "RX" : "TX", endpoint->bEndpointAddress,
  283. le16_to_cpu(endpoint->wMaxPacketSize),
  284. endpoint->bInterval);
  285. }
  286. urbcount = 0;
  287. pipe_num =
  288. ath6kl_usb_get_logical_pipe_num(ar_usb,
  289. endpoint->bEndpointAddress,
  290. &urbcount);
  291. if (pipe_num == ATH6KL_USB_PIPE_INVALID)
  292. continue;
  293. pipe = &ar_usb->pipes[pipe_num];
  294. if (pipe->ar_usb != NULL) {
  295. /* hmmm..pipe was already setup */
  296. continue;
  297. }
  298. pipe->ar_usb = ar_usb;
  299. pipe->logical_pipe_num = pipe_num;
  300. pipe->ep_address = endpoint->bEndpointAddress;
  301. pipe->max_packet_size = le16_to_cpu(endpoint->wMaxPacketSize);
  302. if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) {
  303. if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
  304. pipe->usb_pipe_handle =
  305. usb_rcvbulkpipe(ar_usb->udev,
  306. pipe->ep_address);
  307. } else {
  308. pipe->usb_pipe_handle =
  309. usb_sndbulkpipe(ar_usb->udev,
  310. pipe->ep_address);
  311. }
  312. } else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) {
  313. if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
  314. pipe->usb_pipe_handle =
  315. usb_rcvintpipe(ar_usb->udev,
  316. pipe->ep_address);
  317. } else {
  318. pipe->usb_pipe_handle =
  319. usb_sndintpipe(ar_usb->udev,
  320. pipe->ep_address);
  321. }
  322. } else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) {
  323. /* TODO for ISO */
  324. if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
  325. pipe->usb_pipe_handle =
  326. usb_rcvisocpipe(ar_usb->udev,
  327. pipe->ep_address);
  328. } else {
  329. pipe->usb_pipe_handle =
  330. usb_sndisocpipe(ar_usb->udev,
  331. pipe->ep_address);
  332. }
  333. }
  334. pipe->ep_desc = endpoint;
  335. if (!ATH6KL_USB_IS_DIR_IN(pipe->ep_address))
  336. pipe->flags |= ATH6KL_USB_PIPE_FLAG_TX;
  337. status = ath6kl_usb_alloc_pipe_resources(pipe, urbcount);
  338. if (status != 0)
  339. break;
  340. }
  341. return status;
  342. }
  343. /* pipe operations */
  344. static void ath6kl_usb_post_recv_transfers(struct ath6kl_usb_pipe *recv_pipe,
  345. int buffer_length)
  346. {
  347. struct ath6kl_urb_context *urb_context;
  348. struct urb *urb;
  349. int usb_status;
  350. while (true) {
  351. urb_context = ath6kl_usb_alloc_urb_from_pipe(recv_pipe);
  352. if (urb_context == NULL)
  353. break;
  354. urb_context->skb = dev_alloc_skb(buffer_length);
  355. if (urb_context->skb == NULL)
  356. goto err_cleanup_urb;
  357. urb = usb_alloc_urb(0, GFP_ATOMIC);
  358. if (urb == NULL)
  359. goto err_cleanup_urb;
  360. usb_fill_bulk_urb(urb,
  361. recv_pipe->ar_usb->udev,
  362. recv_pipe->usb_pipe_handle,
  363. urb_context->skb->data,
  364. buffer_length,
  365. ath6kl_usb_recv_complete, urb_context);
  366. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  367. "ath6kl usb: bulk recv submit:%d, 0x%X (ep:0x%2.2X), %d bytes buf:0x%p\n",
  368. recv_pipe->logical_pipe_num,
  369. recv_pipe->usb_pipe_handle, recv_pipe->ep_address,
  370. buffer_length, urb_context->skb);
  371. usb_anchor_urb(urb, &recv_pipe->urb_submitted);
  372. usb_status = usb_submit_urb(urb, GFP_ATOMIC);
  373. if (usb_status) {
  374. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  375. "ath6kl usb : usb bulk recv failed %d\n",
  376. usb_status);
  377. usb_unanchor_urb(urb);
  378. usb_free_urb(urb);
  379. goto err_cleanup_urb;
  380. }
  381. usb_free_urb(urb);
  382. }
  383. return;
  384. err_cleanup_urb:
  385. ath6kl_usb_cleanup_recv_urb(urb_context);
  386. return;
  387. }
  388. static void ath6kl_usb_flush_all(struct ath6kl_usb *ar_usb)
  389. {
  390. int i;
  391. for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
  392. if (ar_usb->pipes[i].ar_usb != NULL)
  393. usb_kill_anchored_urbs(&ar_usb->pipes[i].urb_submitted);
  394. }
  395. /*
  396. * Flushing any pending I/O may schedule work this call will block
  397. * until all scheduled work runs to completion.
  398. */
  399. flush_scheduled_work();
  400. }
  401. static void ath6kl_usb_start_recv_pipes(struct ath6kl_usb *ar_usb)
  402. {
  403. /*
  404. * note: control pipe is no longer used
  405. * ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_cnt_thresh =
  406. * ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_alloc/2;
  407. * ath6kl_usb_post_recv_transfers(&ar_usb->
  408. * pipes[ATH6KL_USB_PIPE_RX_CTRL],
  409. * ATH6KL_USB_RX_BUFFER_SIZE);
  410. */
  411. ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA].urb_cnt_thresh =
  412. ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA].urb_alloc / 2;
  413. ath6kl_usb_post_recv_transfers(&ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA],
  414. ATH6KL_USB_RX_BUFFER_SIZE);
  415. }
  416. /* hif usb rx/tx completion functions */
  417. static void ath6kl_usb_recv_complete(struct urb *urb)
  418. {
  419. struct ath6kl_urb_context *urb_context = urb->context;
  420. struct ath6kl_usb_pipe *pipe = urb_context->pipe;
  421. struct sk_buff *skb = NULL;
  422. int status = 0;
  423. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  424. "%s: recv pipe: %d, stat:%d, len:%d urb:0x%p\n", __func__,
  425. pipe->logical_pipe_num, urb->status, urb->actual_length,
  426. urb);
  427. if (urb->status != 0) {
  428. status = -EIO;
  429. switch (urb->status) {
  430. case -ECONNRESET:
  431. case -ENOENT:
  432. case -ESHUTDOWN:
  433. /*
  434. * no need to spew these errors when device
  435. * removed or urb killed due to driver shutdown
  436. */
  437. status = -ECANCELED;
  438. break;
  439. default:
  440. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  441. "%s recv pipe: %d (ep:0x%2.2X), failed:%d\n",
  442. __func__, pipe->logical_pipe_num,
  443. pipe->ep_address, urb->status);
  444. break;
  445. }
  446. goto cleanup_recv_urb;
  447. }
  448. if (urb->actual_length == 0)
  449. goto cleanup_recv_urb;
  450. skb = urb_context->skb;
  451. /* we are going to pass it up */
  452. urb_context->skb = NULL;
  453. skb_put(skb, urb->actual_length);
  454. /* note: queue implements a lock */
  455. skb_queue_tail(&pipe->io_comp_queue, skb);
  456. schedule_work(&pipe->io_complete_work);
  457. cleanup_recv_urb:
  458. ath6kl_usb_cleanup_recv_urb(urb_context);
  459. if (status == 0 &&
  460. pipe->urb_cnt >= pipe->urb_cnt_thresh) {
  461. /* our free urbs are piling up, post more transfers */
  462. ath6kl_usb_post_recv_transfers(pipe, ATH6KL_USB_RX_BUFFER_SIZE);
  463. }
  464. }
  465. static void ath6kl_usb_usb_transmit_complete(struct urb *urb)
  466. {
  467. struct ath6kl_urb_context *urb_context = urb->context;
  468. struct ath6kl_usb_pipe *pipe = urb_context->pipe;
  469. struct sk_buff *skb;
  470. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  471. "%s: pipe: %d, stat:%d, len:%d\n",
  472. __func__, pipe->logical_pipe_num, urb->status,
  473. urb->actual_length);
  474. if (urb->status != 0) {
  475. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  476. "%s: pipe: %d, failed:%d\n",
  477. __func__, pipe->logical_pipe_num, urb->status);
  478. }
  479. skb = urb_context->skb;
  480. urb_context->skb = NULL;
  481. ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
  482. /* note: queue implements a lock */
  483. skb_queue_tail(&pipe->io_comp_queue, skb);
  484. schedule_work(&pipe->io_complete_work);
  485. }
  486. static void ath6kl_usb_io_comp_work(struct work_struct *work)
  487. {
  488. struct ath6kl_usb_pipe *pipe = container_of(work,
  489. struct ath6kl_usb_pipe,
  490. io_complete_work);
  491. struct ath6kl_usb *ar_usb;
  492. struct sk_buff *skb;
  493. ar_usb = pipe->ar_usb;
  494. while ((skb = skb_dequeue(&pipe->io_comp_queue))) {
  495. if (pipe->flags & ATH6KL_USB_PIPE_FLAG_TX) {
  496. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  497. "ath6kl usb xmit callback buf:0x%p\n", skb);
  498. ath6kl_core_tx_complete(ar_usb->ar, skb);
  499. } else {
  500. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  501. "ath6kl usb recv callback buf:0x%p\n", skb);
  502. ath6kl_core_rx_complete(ar_usb->ar, skb,
  503. pipe->logical_pipe_num);
  504. }
  505. }
  506. }
  507. #define ATH6KL_USB_MAX_DIAG_CMD (sizeof(struct ath6kl_usb_ctrl_diag_cmd_write))
  508. #define ATH6KL_USB_MAX_DIAG_RESP (sizeof(struct ath6kl_usb_ctrl_diag_resp_read))
  509. static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb)
  510. {
  511. ath6kl_usb_flush_all(ar_usb);
  512. ath6kl_usb_cleanup_pipe_resources(ar_usb);
  513. usb_set_intfdata(ar_usb->interface, NULL);
  514. kfree(ar_usb->diag_cmd_buffer);
  515. kfree(ar_usb->diag_resp_buffer);
  516. kfree(ar_usb);
  517. }
  518. static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface)
  519. {
  520. struct usb_device *dev = interface_to_usbdev(interface);
  521. struct ath6kl_usb *ar_usb;
  522. struct ath6kl_usb_pipe *pipe;
  523. int status = 0;
  524. int i;
  525. ar_usb = kzalloc(sizeof(struct ath6kl_usb), GFP_KERNEL);
  526. if (ar_usb == NULL)
  527. goto fail_ath6kl_usb_create;
  528. usb_set_intfdata(interface, ar_usb);
  529. spin_lock_init(&(ar_usb->cs_lock));
  530. ar_usb->udev = dev;
  531. ar_usb->interface = interface;
  532. for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
  533. pipe = &ar_usb->pipes[i];
  534. INIT_WORK(&pipe->io_complete_work,
  535. ath6kl_usb_io_comp_work);
  536. skb_queue_head_init(&pipe->io_comp_queue);
  537. }
  538. ar_usb->diag_cmd_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_CMD, GFP_KERNEL);
  539. if (ar_usb->diag_cmd_buffer == NULL) {
  540. status = -ENOMEM;
  541. goto fail_ath6kl_usb_create;
  542. }
  543. ar_usb->diag_resp_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_RESP,
  544. GFP_KERNEL);
  545. if (ar_usb->diag_resp_buffer == NULL) {
  546. status = -ENOMEM;
  547. goto fail_ath6kl_usb_create;
  548. }
  549. status = ath6kl_usb_setup_pipe_resources(ar_usb);
  550. fail_ath6kl_usb_create:
  551. if (status != 0) {
  552. ath6kl_usb_destroy(ar_usb);
  553. ar_usb = NULL;
  554. }
  555. return ar_usb;
  556. }
  557. static void ath6kl_usb_device_detached(struct usb_interface *interface)
  558. {
  559. struct ath6kl_usb *ar_usb;
  560. ar_usb = usb_get_intfdata(interface);
  561. if (ar_usb == NULL)
  562. return;
  563. ath6kl_stop_txrx(ar_usb->ar);
  564. /* Delay to wait for the target to reboot */
  565. mdelay(20);
  566. ath6kl_core_cleanup(ar_usb->ar);
  567. ath6kl_usb_destroy(ar_usb);
  568. }
  569. /* exported hif usb APIs for htc pipe */
  570. static void hif_start(struct ath6kl *ar)
  571. {
  572. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  573. int i;
  574. ath6kl_usb_start_recv_pipes(device);
  575. /* set the TX resource avail threshold for each TX pipe */
  576. for (i = ATH6KL_USB_PIPE_TX_CTRL;
  577. i <= ATH6KL_USB_PIPE_TX_DATA_HP; i++) {
  578. device->pipes[i].urb_cnt_thresh =
  579. device->pipes[i].urb_alloc / 2;
  580. }
  581. }
  582. static int ath6kl_usb_send(struct ath6kl *ar, u8 PipeID,
  583. struct sk_buff *hdr_skb, struct sk_buff *skb)
  584. {
  585. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  586. struct ath6kl_usb_pipe *pipe = &device->pipes[PipeID];
  587. struct ath6kl_urb_context *urb_context;
  588. int usb_status, status = 0;
  589. struct urb *urb;
  590. u8 *data;
  591. u32 len;
  592. ath6kl_dbg(ATH6KL_DBG_USB_BULK, "+%s pipe : %d, buf:0x%p\n",
  593. __func__, PipeID, skb);
  594. urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
  595. if (urb_context == NULL) {
  596. /*
  597. * TODO: it is possible to run out of urbs if
  598. * 2 endpoints map to the same pipe ID
  599. */
  600. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  601. "%s pipe:%d no urbs left. URB Cnt : %d\n",
  602. __func__, PipeID, pipe->urb_cnt);
  603. status = -ENOMEM;
  604. goto fail_hif_send;
  605. }
  606. urb_context->skb = skb;
  607. data = skb->data;
  608. len = skb->len;
  609. urb = usb_alloc_urb(0, GFP_ATOMIC);
  610. if (urb == NULL) {
  611. status = -ENOMEM;
  612. ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
  613. urb_context);
  614. goto fail_hif_send;
  615. }
  616. usb_fill_bulk_urb(urb,
  617. device->udev,
  618. pipe->usb_pipe_handle,
  619. data,
  620. len,
  621. ath6kl_usb_usb_transmit_complete, urb_context);
  622. if ((len % pipe->max_packet_size) == 0) {
  623. /* hit a max packet boundary on this pipe */
  624. urb->transfer_flags |= URB_ZERO_PACKET;
  625. }
  626. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  627. "athusb bulk send submit:%d, 0x%X (ep:0x%2.2X), %d bytes\n",
  628. pipe->logical_pipe_num, pipe->usb_pipe_handle,
  629. pipe->ep_address, len);
  630. usb_anchor_urb(urb, &pipe->urb_submitted);
  631. usb_status = usb_submit_urb(urb, GFP_ATOMIC);
  632. if (usb_status) {
  633. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  634. "ath6kl usb : usb bulk transmit failed %d\n",
  635. usb_status);
  636. usb_unanchor_urb(urb);
  637. ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
  638. urb_context);
  639. status = -EINVAL;
  640. }
  641. usb_free_urb(urb);
  642. fail_hif_send:
  643. return status;
  644. }
  645. static void hif_stop(struct ath6kl *ar)
  646. {
  647. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  648. ath6kl_usb_flush_all(device);
  649. }
  650. static void ath6kl_usb_get_default_pipe(struct ath6kl *ar,
  651. u8 *ul_pipe, u8 *dl_pipe)
  652. {
  653. *ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
  654. *dl_pipe = ATH6KL_USB_PIPE_RX_CTRL;
  655. }
  656. static int ath6kl_usb_map_service_pipe(struct ath6kl *ar, u16 svc_id,
  657. u8 *ul_pipe, u8 *dl_pipe)
  658. {
  659. int status = 0;
  660. switch (svc_id) {
  661. case HTC_CTRL_RSVD_SVC:
  662. case WMI_CONTROL_SVC:
  663. *ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
  664. /* due to large control packets, shift to data pipe */
  665. *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
  666. break;
  667. case WMI_DATA_BE_SVC:
  668. case WMI_DATA_BK_SVC:
  669. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
  670. /*
  671. * Disable rxdata2 directly, it will be enabled
  672. * if FW enable rxdata2
  673. */
  674. *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
  675. break;
  676. case WMI_DATA_VI_SVC:
  677. if (ar->hw.flags & ATH6KL_HW_MAP_LP_ENDPOINT)
  678. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
  679. else
  680. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
  681. /*
  682. * Disable rxdata2 directly, it will be enabled
  683. * if FW enable rxdata2
  684. */
  685. *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
  686. break;
  687. case WMI_DATA_VO_SVC:
  688. if (ar->hw.flags & ATH6KL_HW_MAP_LP_ENDPOINT)
  689. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
  690. else
  691. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
  692. /*
  693. * Disable rxdata2 directly, it will be enabled
  694. * if FW enable rxdata2
  695. */
  696. *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
  697. break;
  698. default:
  699. status = -EPERM;
  700. break;
  701. }
  702. return status;
  703. }
  704. static u16 ath6kl_usb_get_free_queue_number(struct ath6kl *ar, u8 pipe_id)
  705. {
  706. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  707. return device->pipes[pipe_id].urb_cnt;
  708. }
  709. static void hif_detach_htc(struct ath6kl *ar)
  710. {
  711. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  712. ath6kl_usb_flush_all(device);
  713. }
  714. static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb,
  715. u8 req, u16 value, u16 index, void *data,
  716. u32 size)
  717. {
  718. u8 *buf = NULL;
  719. int ret;
  720. if (size > 0) {
  721. buf = kmalloc(size, GFP_KERNEL);
  722. if (buf == NULL)
  723. return -ENOMEM;
  724. memcpy(buf, data, size);
  725. }
  726. /* note: if successful returns number of bytes transfered */
  727. ret = usb_control_msg(ar_usb->udev,
  728. usb_sndctrlpipe(ar_usb->udev, 0),
  729. req,
  730. USB_DIR_OUT | USB_TYPE_VENDOR |
  731. USB_RECIP_DEVICE, value, index, buf,
  732. size, 1000);
  733. if (ret < 0) {
  734. ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
  735. __func__, ret);
  736. }
  737. kfree(buf);
  738. return 0;
  739. }
  740. static int ath6kl_usb_submit_ctrl_in(struct ath6kl_usb *ar_usb,
  741. u8 req, u16 value, u16 index, void *data,
  742. u32 size)
  743. {
  744. u8 *buf = NULL;
  745. int ret;
  746. if (size > 0) {
  747. buf = kmalloc(size, GFP_KERNEL);
  748. if (buf == NULL)
  749. return -ENOMEM;
  750. }
  751. /* note: if successful returns number of bytes transfered */
  752. ret = usb_control_msg(ar_usb->udev,
  753. usb_rcvctrlpipe(ar_usb->udev, 0),
  754. req,
  755. USB_DIR_IN | USB_TYPE_VENDOR |
  756. USB_RECIP_DEVICE, value, index, buf,
  757. size, 2 * HZ);
  758. if (ret < 0) {
  759. ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
  760. __func__, ret);
  761. }
  762. memcpy((u8 *) data, buf, size);
  763. kfree(buf);
  764. return 0;
  765. }
  766. static int ath6kl_usb_ctrl_msg_exchange(struct ath6kl_usb *ar_usb,
  767. u8 req_val, u8 *req_buf, u32 req_len,
  768. u8 resp_val, u8 *resp_buf, u32 *resp_len)
  769. {
  770. int ret;
  771. /* send command */
  772. ret = ath6kl_usb_submit_ctrl_out(ar_usb, req_val, 0, 0,
  773. req_buf, req_len);
  774. if (ret != 0)
  775. return ret;
  776. if (resp_buf == NULL) {
  777. /* no expected response */
  778. return ret;
  779. }
  780. /* get response */
  781. ret = ath6kl_usb_submit_ctrl_in(ar_usb, resp_val, 0, 0,
  782. resp_buf, *resp_len);
  783. return ret;
  784. }
  785. static int ath6kl_usb_diag_read32(struct ath6kl *ar, u32 address, u32 *data)
  786. {
  787. struct ath6kl_usb *ar_usb = ar->hif_priv;
  788. struct ath6kl_usb_ctrl_diag_resp_read *resp;
  789. struct ath6kl_usb_ctrl_diag_cmd_read *cmd;
  790. u32 resp_len;
  791. int ret;
  792. cmd = (struct ath6kl_usb_ctrl_diag_cmd_read *) ar_usb->diag_cmd_buffer;
  793. memset(cmd, 0, sizeof(*cmd));
  794. cmd->cmd = ATH6KL_USB_CTRL_DIAG_CC_READ;
  795. cmd->address = cpu_to_le32(address);
  796. resp_len = sizeof(*resp);
  797. ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
  798. ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
  799. (u8 *) cmd,
  800. sizeof(struct ath6kl_usb_ctrl_diag_cmd_write),
  801. ATH6KL_USB_CONTROL_REQ_DIAG_RESP,
  802. ar_usb->diag_resp_buffer, &resp_len);
  803. if (ret)
  804. return ret;
  805. resp = (struct ath6kl_usb_ctrl_diag_resp_read *)
  806. ar_usb->diag_resp_buffer;
  807. *data = le32_to_cpu(resp->value);
  808. return ret;
  809. }
  810. static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data)
  811. {
  812. struct ath6kl_usb *ar_usb = ar->hif_priv;
  813. struct ath6kl_usb_ctrl_diag_cmd_write *cmd;
  814. cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer;
  815. memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write));
  816. cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE);
  817. cmd->address = cpu_to_le32(address);
  818. cmd->value = data;
  819. return ath6kl_usb_ctrl_msg_exchange(ar_usb,
  820. ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
  821. (u8 *) cmd,
  822. sizeof(*cmd),
  823. 0, NULL, NULL);
  824. }
  825. static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
  826. {
  827. struct ath6kl_usb *ar_usb = ar->hif_priv;
  828. int ret;
  829. /* get response */
  830. ret = ath6kl_usb_submit_ctrl_in(ar_usb,
  831. ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP,
  832. 0, 0, buf, len);
  833. if (ret != 0) {
  834. ath6kl_err("Unable to read the bmi data from the device: %d\n",
  835. ret);
  836. return ret;
  837. }
  838. return 0;
  839. }
  840. static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
  841. {
  842. struct ath6kl_usb *ar_usb = ar->hif_priv;
  843. int ret;
  844. /* send command */
  845. ret = ath6kl_usb_submit_ctrl_out(ar_usb,
  846. ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD,
  847. 0, 0, buf, len);
  848. if (ret != 0) {
  849. ath6kl_err("unable to send the bmi data to the device: %d\n",
  850. ret);
  851. return ret;
  852. }
  853. return 0;
  854. }
  855. static int ath6kl_usb_power_on(struct ath6kl *ar)
  856. {
  857. hif_start(ar);
  858. return 0;
  859. }
  860. static int ath6kl_usb_power_off(struct ath6kl *ar)
  861. {
  862. hif_detach_htc(ar);
  863. return 0;
  864. }
  865. static void ath6kl_usb_stop(struct ath6kl *ar)
  866. {
  867. hif_stop(ar);
  868. }
  869. static void ath6kl_usb_cleanup_scatter(struct ath6kl *ar)
  870. {
  871. /*
  872. * USB doesn't support it. Just return.
  873. */
  874. return;
  875. }
  876. static const struct ath6kl_hif_ops ath6kl_usb_ops = {
  877. .diag_read32 = ath6kl_usb_diag_read32,
  878. .diag_write32 = ath6kl_usb_diag_write32,
  879. .bmi_read = ath6kl_usb_bmi_read,
  880. .bmi_write = ath6kl_usb_bmi_write,
  881. .power_on = ath6kl_usb_power_on,
  882. .power_off = ath6kl_usb_power_off,
  883. .stop = ath6kl_usb_stop,
  884. .pipe_send = ath6kl_usb_send,
  885. .pipe_get_default = ath6kl_usb_get_default_pipe,
  886. .pipe_map_service = ath6kl_usb_map_service_pipe,
  887. .pipe_get_free_queue_number = ath6kl_usb_get_free_queue_number,
  888. .cleanup_scatter = ath6kl_usb_cleanup_scatter,
  889. };
  890. /* ath6kl usb driver registered functions */
  891. static int ath6kl_usb_probe(struct usb_interface *interface,
  892. const struct usb_device_id *id)
  893. {
  894. struct usb_device *dev = interface_to_usbdev(interface);
  895. struct ath6kl *ar;
  896. struct ath6kl_usb *ar_usb = NULL;
  897. int vendor_id, product_id;
  898. int ret = 0;
  899. usb_get_dev(dev);
  900. vendor_id = le16_to_cpu(dev->descriptor.idVendor);
  901. product_id = le16_to_cpu(dev->descriptor.idProduct);
  902. ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id);
  903. ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id);
  904. if (interface->cur_altsetting)
  905. ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n",
  906. interface->cur_altsetting->desc.bInterfaceNumber);
  907. if (dev->speed == USB_SPEED_HIGH)
  908. ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n");
  909. else
  910. ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n");
  911. ar_usb = ath6kl_usb_create(interface);
  912. if (ar_usb == NULL) {
  913. ret = -ENOMEM;
  914. goto err_usb_put;
  915. }
  916. ar = ath6kl_core_create(&ar_usb->udev->dev);
  917. if (ar == NULL) {
  918. ath6kl_err("Failed to alloc ath6kl core\n");
  919. ret = -ENOMEM;
  920. goto err_usb_destroy;
  921. }
  922. ar->hif_priv = ar_usb;
  923. ar->hif_type = ATH6KL_HIF_TYPE_USB;
  924. ar->hif_ops = &ath6kl_usb_ops;
  925. ar->mbox_info.block_size = 16;
  926. ar->bmi.max_data_size = 252;
  927. ar_usb->ar = ar;
  928. ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE);
  929. if (ret) {
  930. ath6kl_err("Failed to init ath6kl core: %d\n", ret);
  931. goto err_core_free;
  932. }
  933. return ret;
  934. err_core_free:
  935. ath6kl_core_destroy(ar);
  936. err_usb_destroy:
  937. ath6kl_usb_destroy(ar_usb);
  938. err_usb_put:
  939. usb_put_dev(dev);
  940. return ret;
  941. }
  942. static void ath6kl_usb_remove(struct usb_interface *interface)
  943. {
  944. usb_put_dev(interface_to_usbdev(interface));
  945. ath6kl_usb_device_detached(interface);
  946. }
  947. #ifdef CONFIG_PM
  948. static int ath6kl_usb_suspend(struct usb_interface *interface,
  949. pm_message_t message)
  950. {
  951. struct ath6kl_usb *device;
  952. device = usb_get_intfdata(interface);
  953. ath6kl_usb_flush_all(device);
  954. return 0;
  955. }
  956. static int ath6kl_usb_resume(struct usb_interface *interface)
  957. {
  958. struct ath6kl_usb *device;
  959. device = usb_get_intfdata(interface);
  960. ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA],
  961. ATH6KL_USB_RX_BUFFER_SIZE);
  962. ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA2],
  963. ATH6KL_USB_RX_BUFFER_SIZE);
  964. return 0;
  965. }
  966. static int ath6kl_usb_reset_resume(struct usb_interface *intf)
  967. {
  968. if (usb_get_intfdata(intf))
  969. ath6kl_usb_remove(intf);
  970. return 0;
  971. }
  972. #else
  973. #define ath6kl_usb_suspend NULL
  974. #define ath6kl_usb_resume NULL
  975. #define ath6kl_usb_reset_resume NULL
  976. #endif
  977. /* table of devices that work with this driver */
  978. static struct usb_device_id ath6kl_usb_ids[] = {
  979. {USB_DEVICE(0x0cf3, 0x9374)},
  980. { /* Terminating entry */ },
  981. };
  982. MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
  983. static struct usb_driver ath6kl_usb_driver = {
  984. .name = "ath6kl_usb",
  985. .probe = ath6kl_usb_probe,
  986. .suspend = ath6kl_usb_suspend,
  987. .resume = ath6kl_usb_resume,
  988. .reset_resume = ath6kl_usb_reset_resume,
  989. .disconnect = ath6kl_usb_remove,
  990. .id_table = ath6kl_usb_ids,
  991. .supports_autosuspend = true,
  992. .disable_hub_initiated_lpm = 1,
  993. };
  994. static int ath6kl_usb_init(void)
  995. {
  996. int ret;
  997. ret = usb_register(&ath6kl_usb_driver);
  998. if (ret) {
  999. ath6kl_err("usb registration failed: %d\n", ret);
  1000. return ret;
  1001. }
  1002. return 0;
  1003. }
  1004. static void ath6kl_usb_exit(void)
  1005. {
  1006. usb_deregister(&ath6kl_usb_driver);
  1007. }
  1008. module_init(ath6kl_usb_init);
  1009. module_exit(ath6kl_usb_exit);
  1010. MODULE_AUTHOR("Atheros Communications, Inc.");
  1011. MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices");
  1012. MODULE_LICENSE("Dual BSD/GPL");
  1013. MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE);
  1014. MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE);
  1015. MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE);
  1016. MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE);
  1017. MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE);
  1018. MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE);
  1019. MODULE_FIRMWARE(AR6004_HW_1_2_FIRMWARE_FILE);
  1020. MODULE_FIRMWARE(AR6004_HW_1_2_BOARD_DATA_FILE);
  1021. MODULE_FIRMWARE(AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE);
  1022. MODULE_FIRMWARE(AR6004_HW_1_3_FW_DIR "/" AR6004_HW_1_3_FIRMWARE_FILE);
  1023. MODULE_FIRMWARE(AR6004_HW_1_3_BOARD_DATA_FILE);
  1024. MODULE_FIRMWARE(AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE);