usb.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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. if (urb_context->skb != NULL) {
  137. dev_kfree_skb(urb_context->skb);
  138. urb_context->skb = NULL;
  139. }
  140. ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
  141. }
  142. static inline struct ath6kl_usb *ath6kl_usb_priv(struct ath6kl *ar)
  143. {
  144. return ar->hif_priv;
  145. }
  146. /* pipe resource allocation/cleanup */
  147. static int ath6kl_usb_alloc_pipe_resources(struct ath6kl_usb_pipe *pipe,
  148. int urb_cnt)
  149. {
  150. struct ath6kl_urb_context *urb_context;
  151. int status = 0, i;
  152. INIT_LIST_HEAD(&pipe->urb_list_head);
  153. init_usb_anchor(&pipe->urb_submitted);
  154. for (i = 0; i < urb_cnt; i++) {
  155. urb_context = kzalloc(sizeof(struct ath6kl_urb_context),
  156. GFP_KERNEL);
  157. if (urb_context == NULL)
  158. /* FIXME: set status to -ENOMEM */
  159. break;
  160. urb_context->pipe = pipe;
  161. /*
  162. * we are only allocate the urb contexts here, the actual URB
  163. * is allocated from the kernel as needed to do a transaction
  164. */
  165. pipe->urb_alloc++;
  166. ath6kl_usb_free_urb_to_pipe(pipe, urb_context);
  167. }
  168. ath6kl_dbg(ATH6KL_DBG_USB,
  169. "ath6kl usb: alloc resources lpipe:%d hpipe:0x%X urbs:%d\n",
  170. pipe->logical_pipe_num, pipe->usb_pipe_handle,
  171. pipe->urb_alloc);
  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. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
  678. /*
  679. * Disable rxdata2 directly, it will be enabled
  680. * if FW enable rxdata2
  681. */
  682. *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
  683. break;
  684. case WMI_DATA_VO_SVC:
  685. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_HP;
  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. default:
  693. status = -EPERM;
  694. break;
  695. }
  696. return status;
  697. }
  698. static u16 ath6kl_usb_get_free_queue_number(struct ath6kl *ar, u8 pipe_id)
  699. {
  700. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  701. return device->pipes[pipe_id].urb_cnt;
  702. }
  703. static void hif_detach_htc(struct ath6kl *ar)
  704. {
  705. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  706. ath6kl_usb_flush_all(device);
  707. }
  708. static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb,
  709. u8 req, u16 value, u16 index, void *data,
  710. u32 size)
  711. {
  712. u8 *buf = NULL;
  713. int ret;
  714. if (size > 0) {
  715. buf = kmalloc(size, GFP_KERNEL);
  716. if (buf == NULL)
  717. return -ENOMEM;
  718. memcpy(buf, data, size);
  719. }
  720. /* note: if successful returns number of bytes transfered */
  721. ret = usb_control_msg(ar_usb->udev,
  722. usb_sndctrlpipe(ar_usb->udev, 0),
  723. req,
  724. USB_DIR_OUT | USB_TYPE_VENDOR |
  725. USB_RECIP_DEVICE, value, index, buf,
  726. size, 1000);
  727. if (ret < 0) {
  728. ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
  729. __func__, ret);
  730. }
  731. kfree(buf);
  732. return 0;
  733. }
  734. static int ath6kl_usb_submit_ctrl_in(struct ath6kl_usb *ar_usb,
  735. u8 req, u16 value, u16 index, void *data,
  736. u32 size)
  737. {
  738. u8 *buf = NULL;
  739. int ret;
  740. if (size > 0) {
  741. buf = kmalloc(size, GFP_KERNEL);
  742. if (buf == NULL)
  743. return -ENOMEM;
  744. }
  745. /* note: if successful returns number of bytes transfered */
  746. ret = usb_control_msg(ar_usb->udev,
  747. usb_rcvctrlpipe(ar_usb->udev, 0),
  748. req,
  749. USB_DIR_IN | USB_TYPE_VENDOR |
  750. USB_RECIP_DEVICE, value, index, buf,
  751. size, 2 * HZ);
  752. if (ret < 0) {
  753. ath6kl_dbg(ATH6KL_DBG_USB, "%s failed,result = %d\n",
  754. __func__, ret);
  755. }
  756. memcpy((u8 *) data, buf, size);
  757. kfree(buf);
  758. return 0;
  759. }
  760. static int ath6kl_usb_ctrl_msg_exchange(struct ath6kl_usb *ar_usb,
  761. u8 req_val, u8 *req_buf, u32 req_len,
  762. u8 resp_val, u8 *resp_buf, u32 *resp_len)
  763. {
  764. int ret;
  765. /* send command */
  766. ret = ath6kl_usb_submit_ctrl_out(ar_usb, req_val, 0, 0,
  767. req_buf, req_len);
  768. if (ret != 0)
  769. return ret;
  770. if (resp_buf == NULL) {
  771. /* no expected response */
  772. return ret;
  773. }
  774. /* get response */
  775. ret = ath6kl_usb_submit_ctrl_in(ar_usb, resp_val, 0, 0,
  776. resp_buf, *resp_len);
  777. return ret;
  778. }
  779. static int ath6kl_usb_diag_read32(struct ath6kl *ar, u32 address, u32 *data)
  780. {
  781. struct ath6kl_usb *ar_usb = ar->hif_priv;
  782. struct ath6kl_usb_ctrl_diag_resp_read *resp;
  783. struct ath6kl_usb_ctrl_diag_cmd_read *cmd;
  784. u32 resp_len;
  785. int ret;
  786. cmd = (struct ath6kl_usb_ctrl_diag_cmd_read *) ar_usb->diag_cmd_buffer;
  787. memset(cmd, 0, sizeof(*cmd));
  788. cmd->cmd = ATH6KL_USB_CTRL_DIAG_CC_READ;
  789. cmd->address = cpu_to_le32(address);
  790. resp_len = sizeof(*resp);
  791. ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
  792. ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
  793. (u8 *) cmd,
  794. sizeof(struct ath6kl_usb_ctrl_diag_cmd_write),
  795. ATH6KL_USB_CONTROL_REQ_DIAG_RESP,
  796. ar_usb->diag_resp_buffer, &resp_len);
  797. if (ret)
  798. return ret;
  799. resp = (struct ath6kl_usb_ctrl_diag_resp_read *)
  800. ar_usb->diag_resp_buffer;
  801. *data = le32_to_cpu(resp->value);
  802. return ret;
  803. }
  804. static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data)
  805. {
  806. struct ath6kl_usb *ar_usb = ar->hif_priv;
  807. struct ath6kl_usb_ctrl_diag_cmd_write *cmd;
  808. cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer;
  809. memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write));
  810. cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE);
  811. cmd->address = cpu_to_le32(address);
  812. cmd->value = data;
  813. return ath6kl_usb_ctrl_msg_exchange(ar_usb,
  814. ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
  815. (u8 *) cmd,
  816. sizeof(*cmd),
  817. 0, NULL, NULL);
  818. }
  819. static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
  820. {
  821. struct ath6kl_usb *ar_usb = ar->hif_priv;
  822. int ret;
  823. /* get response */
  824. ret = ath6kl_usb_submit_ctrl_in(ar_usb,
  825. ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP,
  826. 0, 0, buf, len);
  827. if (ret != 0) {
  828. ath6kl_err("Unable to read the bmi data from the device: %d\n",
  829. ret);
  830. return ret;
  831. }
  832. return 0;
  833. }
  834. static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
  835. {
  836. struct ath6kl_usb *ar_usb = ar->hif_priv;
  837. int ret;
  838. /* send command */
  839. ret = ath6kl_usb_submit_ctrl_out(ar_usb,
  840. ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD,
  841. 0, 0, buf, len);
  842. if (ret != 0) {
  843. ath6kl_err("unable to send the bmi data to the device: %d\n",
  844. ret);
  845. return ret;
  846. }
  847. return 0;
  848. }
  849. static int ath6kl_usb_power_on(struct ath6kl *ar)
  850. {
  851. hif_start(ar);
  852. return 0;
  853. }
  854. static int ath6kl_usb_power_off(struct ath6kl *ar)
  855. {
  856. hif_detach_htc(ar);
  857. return 0;
  858. }
  859. static void ath6kl_usb_stop(struct ath6kl *ar)
  860. {
  861. hif_stop(ar);
  862. }
  863. static const struct ath6kl_hif_ops ath6kl_usb_ops = {
  864. .diag_read32 = ath6kl_usb_diag_read32,
  865. .diag_write32 = ath6kl_usb_diag_write32,
  866. .bmi_read = ath6kl_usb_bmi_read,
  867. .bmi_write = ath6kl_usb_bmi_write,
  868. .power_on = ath6kl_usb_power_on,
  869. .power_off = ath6kl_usb_power_off,
  870. .stop = ath6kl_usb_stop,
  871. .pipe_send = ath6kl_usb_send,
  872. .pipe_get_default = ath6kl_usb_get_default_pipe,
  873. .pipe_map_service = ath6kl_usb_map_service_pipe,
  874. .pipe_get_free_queue_number = ath6kl_usb_get_free_queue_number,
  875. };
  876. /* ath6kl usb driver registered functions */
  877. static int ath6kl_usb_probe(struct usb_interface *interface,
  878. const struct usb_device_id *id)
  879. {
  880. struct usb_device *dev = interface_to_usbdev(interface);
  881. struct ath6kl *ar;
  882. struct ath6kl_usb *ar_usb = NULL;
  883. int vendor_id, product_id;
  884. int ret = 0;
  885. usb_get_dev(dev);
  886. vendor_id = le16_to_cpu(dev->descriptor.idVendor);
  887. product_id = le16_to_cpu(dev->descriptor.idProduct);
  888. ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id);
  889. ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id);
  890. if (interface->cur_altsetting)
  891. ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n",
  892. interface->cur_altsetting->desc.bInterfaceNumber);
  893. if (dev->speed == USB_SPEED_HIGH)
  894. ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n");
  895. else
  896. ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n");
  897. ar_usb = ath6kl_usb_create(interface);
  898. if (ar_usb == NULL) {
  899. ret = -ENOMEM;
  900. goto err_usb_put;
  901. }
  902. ar = ath6kl_core_create(&ar_usb->udev->dev);
  903. if (ar == NULL) {
  904. ath6kl_err("Failed to alloc ath6kl core\n");
  905. ret = -ENOMEM;
  906. goto err_usb_destroy;
  907. }
  908. ar->hif_priv = ar_usb;
  909. ar->hif_type = ATH6KL_HIF_TYPE_USB;
  910. ar->hif_ops = &ath6kl_usb_ops;
  911. ar->mbox_info.block_size = 16;
  912. ar->bmi.max_data_size = 252;
  913. ar_usb->ar = ar;
  914. ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE);
  915. if (ret) {
  916. ath6kl_err("Failed to init ath6kl core: %d\n", ret);
  917. goto err_core_free;
  918. }
  919. return ret;
  920. err_core_free:
  921. ath6kl_core_destroy(ar);
  922. err_usb_destroy:
  923. ath6kl_usb_destroy(ar_usb);
  924. err_usb_put:
  925. usb_put_dev(dev);
  926. return ret;
  927. }
  928. static void ath6kl_usb_remove(struct usb_interface *interface)
  929. {
  930. usb_put_dev(interface_to_usbdev(interface));
  931. ath6kl_usb_device_detached(interface);
  932. }
  933. #ifdef CONFIG_PM
  934. static int ath6kl_usb_suspend(struct usb_interface *interface,
  935. pm_message_t message)
  936. {
  937. struct ath6kl_usb *device;
  938. device = usb_get_intfdata(interface);
  939. ath6kl_usb_flush_all(device);
  940. return 0;
  941. }
  942. static int ath6kl_usb_resume(struct usb_interface *interface)
  943. {
  944. struct ath6kl_usb *device;
  945. device = usb_get_intfdata(interface);
  946. ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA],
  947. ATH6KL_USB_RX_BUFFER_SIZE);
  948. ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA2],
  949. ATH6KL_USB_RX_BUFFER_SIZE);
  950. return 0;
  951. }
  952. static int ath6kl_usb_reset_resume(struct usb_interface *intf)
  953. {
  954. if (usb_get_intfdata(intf))
  955. ath6kl_usb_remove(intf);
  956. return 0;
  957. }
  958. #else
  959. #define ath6kl_usb_suspend NULL
  960. #define ath6kl_usb_resume NULL
  961. #define ath6kl_usb_reset_resume NULL
  962. #endif
  963. /* table of devices that work with this driver */
  964. static struct usb_device_id ath6kl_usb_ids[] = {
  965. {USB_DEVICE(0x0cf3, 0x9374)},
  966. { /* Terminating entry */ },
  967. };
  968. MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
  969. static struct usb_driver ath6kl_usb_driver = {
  970. .name = "ath6kl_usb",
  971. .probe = ath6kl_usb_probe,
  972. .suspend = ath6kl_usb_suspend,
  973. .resume = ath6kl_usb_resume,
  974. .reset_resume = ath6kl_usb_reset_resume,
  975. .disconnect = ath6kl_usb_remove,
  976. .id_table = ath6kl_usb_ids,
  977. .supports_autosuspend = true,
  978. };
  979. static int ath6kl_usb_init(void)
  980. {
  981. usb_register(&ath6kl_usb_driver);
  982. return 0;
  983. }
  984. static void ath6kl_usb_exit(void)
  985. {
  986. usb_deregister(&ath6kl_usb_driver);
  987. }
  988. module_init(ath6kl_usb_init);
  989. module_exit(ath6kl_usb_exit);
  990. MODULE_AUTHOR("Atheros Communications, Inc.");
  991. MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices");
  992. MODULE_LICENSE("Dual BSD/GPL");
  993. MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE);
  994. MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE);
  995. MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE);
  996. MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE);
  997. MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE);
  998. MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE);
  999. MODULE_FIRMWARE(AR6004_HW_1_2_FIRMWARE_FILE);
  1000. MODULE_FIRMWARE(AR6004_HW_1_2_BOARD_DATA_FILE);
  1001. MODULE_FIRMWARE(AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE);