usb.c 31 KB

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