usb.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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 = kmemdup(data, size, GFP_KERNEL);
  722. if (buf == NULL)
  723. return -ENOMEM;
  724. }
  725. /* note: if successful returns number of bytes transfered */
  726. ret = usb_control_msg(ar_usb->udev,
  727. usb_sndctrlpipe(ar_usb->udev, 0),
  728. req,
  729. USB_DIR_OUT | USB_TYPE_VENDOR |
  730. USB_RECIP_DEVICE, value, index, buf,
  731. size, 1000);
  732. if (ret < 0) {
  733. ath6kl_warn("Failed to submit usb control message: %d\n", ret);
  734. kfree(buf);
  735. return 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_warn("Failed to read usb control message: %d\n", ret);
  760. kfree(buf);
  761. return ret;
  762. }
  763. memcpy((u8 *) data, buf, size);
  764. kfree(buf);
  765. return 0;
  766. }
  767. static int ath6kl_usb_ctrl_msg_exchange(struct ath6kl_usb *ar_usb,
  768. u8 req_val, u8 *req_buf, u32 req_len,
  769. u8 resp_val, u8 *resp_buf, u32 *resp_len)
  770. {
  771. int ret;
  772. /* send command */
  773. ret = ath6kl_usb_submit_ctrl_out(ar_usb, req_val, 0, 0,
  774. req_buf, req_len);
  775. if (ret != 0)
  776. return ret;
  777. if (resp_buf == NULL) {
  778. /* no expected response */
  779. return ret;
  780. }
  781. /* get response */
  782. ret = ath6kl_usb_submit_ctrl_in(ar_usb, resp_val, 0, 0,
  783. resp_buf, *resp_len);
  784. return ret;
  785. }
  786. static int ath6kl_usb_diag_read32(struct ath6kl *ar, u32 address, u32 *data)
  787. {
  788. struct ath6kl_usb *ar_usb = ar->hif_priv;
  789. struct ath6kl_usb_ctrl_diag_resp_read *resp;
  790. struct ath6kl_usb_ctrl_diag_cmd_read *cmd;
  791. u32 resp_len;
  792. int ret;
  793. cmd = (struct ath6kl_usb_ctrl_diag_cmd_read *) ar_usb->diag_cmd_buffer;
  794. memset(cmd, 0, sizeof(*cmd));
  795. cmd->cmd = ATH6KL_USB_CTRL_DIAG_CC_READ;
  796. cmd->address = cpu_to_le32(address);
  797. resp_len = sizeof(*resp);
  798. ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
  799. ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
  800. (u8 *) cmd,
  801. sizeof(struct ath6kl_usb_ctrl_diag_cmd_write),
  802. ATH6KL_USB_CONTROL_REQ_DIAG_RESP,
  803. ar_usb->diag_resp_buffer, &resp_len);
  804. if (ret) {
  805. ath6kl_warn("diag read32 failed: %d\n", ret);
  806. return ret;
  807. }
  808. resp = (struct ath6kl_usb_ctrl_diag_resp_read *)
  809. ar_usb->diag_resp_buffer;
  810. *data = le32_to_cpu(resp->value);
  811. return ret;
  812. }
  813. static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data)
  814. {
  815. struct ath6kl_usb *ar_usb = ar->hif_priv;
  816. struct ath6kl_usb_ctrl_diag_cmd_write *cmd;
  817. int ret;
  818. cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer;
  819. memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write));
  820. cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE);
  821. cmd->address = cpu_to_le32(address);
  822. cmd->value = data;
  823. ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
  824. ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
  825. (u8 *) cmd,
  826. sizeof(*cmd),
  827. 0, NULL, NULL);
  828. if (ret) {
  829. ath6kl_warn("diag_write32 failed: %d\n", ret);
  830. return ret;
  831. }
  832. return 0;
  833. }
  834. static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
  835. {
  836. struct ath6kl_usb *ar_usb = ar->hif_priv;
  837. int ret;
  838. /* get response */
  839. ret = ath6kl_usb_submit_ctrl_in(ar_usb,
  840. ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP,
  841. 0, 0, buf, len);
  842. if (ret) {
  843. ath6kl_err("Unable to read the bmi data from the device: %d\n",
  844. ret);
  845. return ret;
  846. }
  847. return 0;
  848. }
  849. static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
  850. {
  851. struct ath6kl_usb *ar_usb = ar->hif_priv;
  852. int ret;
  853. /* send command */
  854. ret = ath6kl_usb_submit_ctrl_out(ar_usb,
  855. ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD,
  856. 0, 0, buf, len);
  857. if (ret) {
  858. ath6kl_err("unable to send the bmi data to the device: %d\n",
  859. ret);
  860. return ret;
  861. }
  862. return 0;
  863. }
  864. static int ath6kl_usb_power_on(struct ath6kl *ar)
  865. {
  866. hif_start(ar);
  867. return 0;
  868. }
  869. static int ath6kl_usb_power_off(struct ath6kl *ar)
  870. {
  871. hif_detach_htc(ar);
  872. return 0;
  873. }
  874. static void ath6kl_usb_stop(struct ath6kl *ar)
  875. {
  876. hif_stop(ar);
  877. }
  878. static void ath6kl_usb_cleanup_scatter(struct ath6kl *ar)
  879. {
  880. /*
  881. * USB doesn't support it. Just return.
  882. */
  883. return;
  884. }
  885. static const struct ath6kl_hif_ops ath6kl_usb_ops = {
  886. .diag_read32 = ath6kl_usb_diag_read32,
  887. .diag_write32 = ath6kl_usb_diag_write32,
  888. .bmi_read = ath6kl_usb_bmi_read,
  889. .bmi_write = ath6kl_usb_bmi_write,
  890. .power_on = ath6kl_usb_power_on,
  891. .power_off = ath6kl_usb_power_off,
  892. .stop = ath6kl_usb_stop,
  893. .pipe_send = ath6kl_usb_send,
  894. .pipe_get_default = ath6kl_usb_get_default_pipe,
  895. .pipe_map_service = ath6kl_usb_map_service_pipe,
  896. .pipe_get_free_queue_number = ath6kl_usb_get_free_queue_number,
  897. .cleanup_scatter = ath6kl_usb_cleanup_scatter,
  898. };
  899. /* ath6kl usb driver registered functions */
  900. static int ath6kl_usb_probe(struct usb_interface *interface,
  901. const struct usb_device_id *id)
  902. {
  903. struct usb_device *dev = interface_to_usbdev(interface);
  904. struct ath6kl *ar;
  905. struct ath6kl_usb *ar_usb = NULL;
  906. int vendor_id, product_id;
  907. int ret = 0;
  908. usb_get_dev(dev);
  909. vendor_id = le16_to_cpu(dev->descriptor.idVendor);
  910. product_id = le16_to_cpu(dev->descriptor.idProduct);
  911. ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id);
  912. ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id);
  913. if (interface->cur_altsetting)
  914. ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n",
  915. interface->cur_altsetting->desc.bInterfaceNumber);
  916. if (dev->speed == USB_SPEED_HIGH)
  917. ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n");
  918. else
  919. ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n");
  920. ar_usb = ath6kl_usb_create(interface);
  921. if (ar_usb == NULL) {
  922. ret = -ENOMEM;
  923. goto err_usb_put;
  924. }
  925. ar = ath6kl_core_create(&ar_usb->udev->dev);
  926. if (ar == NULL) {
  927. ath6kl_err("Failed to alloc ath6kl core\n");
  928. ret = -ENOMEM;
  929. goto err_usb_destroy;
  930. }
  931. ar->hif_priv = ar_usb;
  932. ar->hif_type = ATH6KL_HIF_TYPE_USB;
  933. ar->hif_ops = &ath6kl_usb_ops;
  934. ar->mbox_info.block_size = 16;
  935. ar->bmi.max_data_size = 252;
  936. ar_usb->ar = ar;
  937. ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE);
  938. if (ret) {
  939. ath6kl_err("Failed to init ath6kl core: %d\n", ret);
  940. goto err_core_free;
  941. }
  942. return ret;
  943. err_core_free:
  944. ath6kl_core_destroy(ar);
  945. err_usb_destroy:
  946. ath6kl_usb_destroy(ar_usb);
  947. err_usb_put:
  948. usb_put_dev(dev);
  949. return ret;
  950. }
  951. static void ath6kl_usb_remove(struct usb_interface *interface)
  952. {
  953. usb_put_dev(interface_to_usbdev(interface));
  954. ath6kl_usb_device_detached(interface);
  955. }
  956. #ifdef CONFIG_PM
  957. static int ath6kl_usb_suspend(struct usb_interface *interface,
  958. pm_message_t message)
  959. {
  960. struct ath6kl_usb *device;
  961. device = usb_get_intfdata(interface);
  962. ath6kl_usb_flush_all(device);
  963. return 0;
  964. }
  965. static int ath6kl_usb_resume(struct usb_interface *interface)
  966. {
  967. struct ath6kl_usb *device;
  968. device = usb_get_intfdata(interface);
  969. ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA],
  970. ATH6KL_USB_RX_BUFFER_SIZE);
  971. ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA2],
  972. ATH6KL_USB_RX_BUFFER_SIZE);
  973. return 0;
  974. }
  975. static int ath6kl_usb_reset_resume(struct usb_interface *intf)
  976. {
  977. if (usb_get_intfdata(intf))
  978. ath6kl_usb_remove(intf);
  979. return 0;
  980. }
  981. #else
  982. #define ath6kl_usb_suspend NULL
  983. #define ath6kl_usb_resume NULL
  984. #define ath6kl_usb_reset_resume NULL
  985. #endif
  986. /* table of devices that work with this driver */
  987. static struct usb_device_id ath6kl_usb_ids[] = {
  988. {USB_DEVICE(0x0cf3, 0x9374)},
  989. { /* Terminating entry */ },
  990. };
  991. MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
  992. static struct usb_driver ath6kl_usb_driver = {
  993. .name = "ath6kl_usb",
  994. .probe = ath6kl_usb_probe,
  995. .suspend = ath6kl_usb_suspend,
  996. .resume = ath6kl_usb_resume,
  997. .reset_resume = ath6kl_usb_reset_resume,
  998. .disconnect = ath6kl_usb_remove,
  999. .id_table = ath6kl_usb_ids,
  1000. .supports_autosuspend = true,
  1001. .disable_hub_initiated_lpm = 1,
  1002. };
  1003. static int ath6kl_usb_init(void)
  1004. {
  1005. int ret;
  1006. ret = usb_register(&ath6kl_usb_driver);
  1007. if (ret) {
  1008. ath6kl_err("usb registration failed: %d\n", ret);
  1009. return ret;
  1010. }
  1011. return 0;
  1012. }
  1013. static void ath6kl_usb_exit(void)
  1014. {
  1015. usb_deregister(&ath6kl_usb_driver);
  1016. }
  1017. module_init(ath6kl_usb_init);
  1018. module_exit(ath6kl_usb_exit);
  1019. MODULE_AUTHOR("Atheros Communications, Inc.");
  1020. MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices");
  1021. MODULE_LICENSE("Dual BSD/GPL");
  1022. MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE);
  1023. MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE);
  1024. MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE);
  1025. MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE);
  1026. MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE);
  1027. MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE);
  1028. MODULE_FIRMWARE(AR6004_HW_1_2_FIRMWARE_FILE);
  1029. MODULE_FIRMWARE(AR6004_HW_1_2_BOARD_DATA_FILE);
  1030. MODULE_FIRMWARE(AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE);
  1031. MODULE_FIRMWARE(AR6004_HW_1_3_FW_DIR "/" AR6004_HW_1_3_FIRMWARE_FILE);
  1032. MODULE_FIRMWARE(AR6004_HW_1_3_BOARD_DATA_FILE);
  1033. MODULE_FIRMWARE(AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE);