usb.c 31 KB

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