usb.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. /*
  2. * Copyright (c) 2007-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/usb.h>
  19. #include "debug.h"
  20. #include "core.h"
  21. /* constants */
  22. #define TX_URB_COUNT 32
  23. #define RX_URB_COUNT 32
  24. #define ATH6KL_USB_RX_BUFFER_SIZE 4096
  25. /* tx/rx pipes for usb */
  26. enum ATH6KL_USB_PIPE_ID {
  27. ATH6KL_USB_PIPE_TX_CTRL = 0,
  28. ATH6KL_USB_PIPE_TX_DATA_LP,
  29. ATH6KL_USB_PIPE_TX_DATA_MP,
  30. ATH6KL_USB_PIPE_TX_DATA_HP,
  31. ATH6KL_USB_PIPE_RX_CTRL,
  32. ATH6KL_USB_PIPE_RX_DATA,
  33. ATH6KL_USB_PIPE_RX_DATA2,
  34. ATH6KL_USB_PIPE_RX_INT,
  35. ATH6KL_USB_PIPE_MAX
  36. };
  37. #define ATH6KL_USB_PIPE_INVALID ATH6KL_USB_PIPE_MAX
  38. struct ath6kl_usb_pipe {
  39. struct list_head urb_list_head;
  40. struct usb_anchor urb_submitted;
  41. u32 urb_alloc;
  42. u32 urb_cnt;
  43. u32 urb_cnt_thresh;
  44. unsigned int usb_pipe_handle;
  45. u32 flags;
  46. u8 ep_address;
  47. u8 logical_pipe_num;
  48. struct ath6kl_usb *ar_usb;
  49. u16 max_packet_size;
  50. struct work_struct io_complete_work;
  51. struct sk_buff_head io_comp_queue;
  52. struct usb_endpoint_descriptor *ep_desc;
  53. };
  54. #define ATH6KL_USB_PIPE_FLAG_TX (1 << 0)
  55. /* usb device object */
  56. struct ath6kl_usb {
  57. /* protects pipe->urb_list_head and pipe->urb_cnt */
  58. spinlock_t cs_lock;
  59. struct usb_device *udev;
  60. struct usb_interface *interface;
  61. struct ath6kl_usb_pipe pipes[ATH6KL_USB_PIPE_MAX];
  62. u8 *diag_cmd_buffer;
  63. u8 *diag_resp_buffer;
  64. struct ath6kl *ar;
  65. };
  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 = 1;
  412. ath6kl_usb_post_recv_transfers(&ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA],
  413. ATH6KL_USB_RX_BUFFER_SIZE);
  414. }
  415. /* hif usb rx/tx completion functions */
  416. static void ath6kl_usb_recv_complete(struct urb *urb)
  417. {
  418. struct ath6kl_urb_context *urb_context = urb->context;
  419. struct ath6kl_usb_pipe *pipe = urb_context->pipe;
  420. struct sk_buff *skb = NULL;
  421. int status = 0;
  422. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  423. "%s: recv pipe: %d, stat:%d, len:%d urb:0x%p\n", __func__,
  424. pipe->logical_pipe_num, urb->status, urb->actual_length,
  425. urb);
  426. if (urb->status != 0) {
  427. status = -EIO;
  428. switch (urb->status) {
  429. case -ECONNRESET:
  430. case -ENOENT:
  431. case -ESHUTDOWN:
  432. /*
  433. * no need to spew these errors when device
  434. * removed or urb killed due to driver shutdown
  435. */
  436. status = -ECANCELED;
  437. break;
  438. default:
  439. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  440. "%s recv pipe: %d (ep:0x%2.2X), failed:%d\n",
  441. __func__, pipe->logical_pipe_num,
  442. pipe->ep_address, urb->status);
  443. break;
  444. }
  445. goto cleanup_recv_urb;
  446. }
  447. if (urb->actual_length == 0)
  448. goto cleanup_recv_urb;
  449. skb = urb_context->skb;
  450. /* we are going to pass it up */
  451. urb_context->skb = NULL;
  452. skb_put(skb, urb->actual_length);
  453. /* note: queue implements a lock */
  454. skb_queue_tail(&pipe->io_comp_queue, skb);
  455. schedule_work(&pipe->io_complete_work);
  456. cleanup_recv_urb:
  457. ath6kl_usb_cleanup_recv_urb(urb_context);
  458. if (status == 0 &&
  459. pipe->urb_cnt >= pipe->urb_cnt_thresh) {
  460. /* our free urbs are piling up, post more transfers */
  461. ath6kl_usb_post_recv_transfers(pipe, ATH6KL_USB_RX_BUFFER_SIZE);
  462. }
  463. }
  464. static void ath6kl_usb_usb_transmit_complete(struct urb *urb)
  465. {
  466. struct ath6kl_urb_context *urb_context = urb->context;
  467. struct ath6kl_usb_pipe *pipe = urb_context->pipe;
  468. struct sk_buff *skb;
  469. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  470. "%s: pipe: %d, stat:%d, len:%d\n",
  471. __func__, pipe->logical_pipe_num, urb->status,
  472. urb->actual_length);
  473. if (urb->status != 0) {
  474. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  475. "%s: pipe: %d, failed:%d\n",
  476. __func__, pipe->logical_pipe_num, urb->status);
  477. }
  478. skb = urb_context->skb;
  479. urb_context->skb = NULL;
  480. ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
  481. /* note: queue implements a lock */
  482. skb_queue_tail(&pipe->io_comp_queue, skb);
  483. schedule_work(&pipe->io_complete_work);
  484. }
  485. static void ath6kl_usb_io_comp_work(struct work_struct *work)
  486. {
  487. struct ath6kl_usb_pipe *pipe = container_of(work,
  488. struct ath6kl_usb_pipe,
  489. io_complete_work);
  490. struct ath6kl_usb *ar_usb;
  491. struct sk_buff *skb;
  492. ar_usb = pipe->ar_usb;
  493. while ((skb = skb_dequeue(&pipe->io_comp_queue))) {
  494. if (pipe->flags & ATH6KL_USB_PIPE_FLAG_TX) {
  495. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  496. "ath6kl usb xmit callback buf:0x%p\n", skb);
  497. ath6kl_core_tx_complete(ar_usb->ar, skb);
  498. } else {
  499. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  500. "ath6kl usb recv callback buf:0x%p\n", skb);
  501. ath6kl_core_rx_complete(ar_usb->ar, skb,
  502. pipe->logical_pipe_num);
  503. }
  504. }
  505. }
  506. #define ATH6KL_USB_MAX_DIAG_CMD (sizeof(struct ath6kl_usb_ctrl_diag_cmd_write))
  507. #define ATH6KL_USB_MAX_DIAG_RESP (sizeof(struct ath6kl_usb_ctrl_diag_resp_read))
  508. static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb)
  509. {
  510. ath6kl_usb_flush_all(ar_usb);
  511. ath6kl_usb_cleanup_pipe_resources(ar_usb);
  512. usb_set_intfdata(ar_usb->interface, NULL);
  513. kfree(ar_usb->diag_cmd_buffer);
  514. kfree(ar_usb->diag_resp_buffer);
  515. kfree(ar_usb);
  516. }
  517. static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface)
  518. {
  519. struct usb_device *dev = interface_to_usbdev(interface);
  520. struct ath6kl_usb *ar_usb;
  521. struct ath6kl_usb_pipe *pipe;
  522. int status = 0;
  523. int i;
  524. ar_usb = kzalloc(sizeof(struct ath6kl_usb), GFP_KERNEL);
  525. if (ar_usb == NULL)
  526. goto fail_ath6kl_usb_create;
  527. usb_set_intfdata(interface, ar_usb);
  528. spin_lock_init(&(ar_usb->cs_lock));
  529. ar_usb->udev = dev;
  530. ar_usb->interface = interface;
  531. for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
  532. pipe = &ar_usb->pipes[i];
  533. INIT_WORK(&pipe->io_complete_work,
  534. ath6kl_usb_io_comp_work);
  535. skb_queue_head_init(&pipe->io_comp_queue);
  536. }
  537. ar_usb->diag_cmd_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_CMD, GFP_KERNEL);
  538. if (ar_usb->diag_cmd_buffer == NULL) {
  539. status = -ENOMEM;
  540. goto fail_ath6kl_usb_create;
  541. }
  542. ar_usb->diag_resp_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_RESP,
  543. GFP_KERNEL);
  544. if (ar_usb->diag_resp_buffer == NULL) {
  545. status = -ENOMEM;
  546. goto fail_ath6kl_usb_create;
  547. }
  548. status = ath6kl_usb_setup_pipe_resources(ar_usb);
  549. fail_ath6kl_usb_create:
  550. if (status != 0) {
  551. ath6kl_usb_destroy(ar_usb);
  552. ar_usb = NULL;
  553. }
  554. return ar_usb;
  555. }
  556. static void ath6kl_usb_device_detached(struct usb_interface *interface)
  557. {
  558. struct ath6kl_usb *ar_usb;
  559. ar_usb = usb_get_intfdata(interface);
  560. if (ar_usb == NULL)
  561. return;
  562. ath6kl_stop_txrx(ar_usb->ar);
  563. /* Delay to wait for the target to reboot */
  564. mdelay(20);
  565. ath6kl_core_cleanup(ar_usb->ar);
  566. ath6kl_usb_destroy(ar_usb);
  567. }
  568. /* exported hif usb APIs for htc pipe */
  569. static void hif_start(struct ath6kl *ar)
  570. {
  571. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  572. int i;
  573. ath6kl_usb_start_recv_pipes(device);
  574. /* set the TX resource avail threshold for each TX pipe */
  575. for (i = ATH6KL_USB_PIPE_TX_CTRL;
  576. i <= ATH6KL_USB_PIPE_TX_DATA_HP; i++) {
  577. device->pipes[i].urb_cnt_thresh =
  578. device->pipes[i].urb_alloc / 2;
  579. }
  580. }
  581. static int ath6kl_usb_send(struct ath6kl *ar, u8 PipeID,
  582. struct sk_buff *hdr_skb, struct sk_buff *skb)
  583. {
  584. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  585. struct ath6kl_usb_pipe *pipe = &device->pipes[PipeID];
  586. struct ath6kl_urb_context *urb_context;
  587. int usb_status, status = 0;
  588. struct urb *urb;
  589. u8 *data;
  590. u32 len;
  591. ath6kl_dbg(ATH6KL_DBG_USB_BULK, "+%s pipe : %d, buf:0x%p\n",
  592. __func__, PipeID, skb);
  593. urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
  594. if (urb_context == NULL) {
  595. /*
  596. * TODO: it is possible to run out of urbs if
  597. * 2 endpoints map to the same pipe ID
  598. */
  599. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  600. "%s pipe:%d no urbs left. URB Cnt : %d\n",
  601. __func__, PipeID, pipe->urb_cnt);
  602. status = -ENOMEM;
  603. goto fail_hif_send;
  604. }
  605. urb_context->skb = skb;
  606. data = skb->data;
  607. len = skb->len;
  608. urb = usb_alloc_urb(0, GFP_ATOMIC);
  609. if (urb == NULL) {
  610. status = -ENOMEM;
  611. ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
  612. urb_context);
  613. goto fail_hif_send;
  614. }
  615. usb_fill_bulk_urb(urb,
  616. device->udev,
  617. pipe->usb_pipe_handle,
  618. data,
  619. len,
  620. ath6kl_usb_usb_transmit_complete, urb_context);
  621. if ((len % pipe->max_packet_size) == 0) {
  622. /* hit a max packet boundary on this pipe */
  623. urb->transfer_flags |= URB_ZERO_PACKET;
  624. }
  625. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  626. "athusb bulk send submit:%d, 0x%X (ep:0x%2.2X), %d bytes\n",
  627. pipe->logical_pipe_num, pipe->usb_pipe_handle,
  628. pipe->ep_address, len);
  629. usb_anchor_urb(urb, &pipe->urb_submitted);
  630. usb_status = usb_submit_urb(urb, GFP_ATOMIC);
  631. if (usb_status) {
  632. ath6kl_dbg(ATH6KL_DBG_USB_BULK,
  633. "ath6kl usb : usb bulk transmit failed %d\n",
  634. usb_status);
  635. usb_unanchor_urb(urb);
  636. ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
  637. urb_context);
  638. status = -EINVAL;
  639. }
  640. usb_free_urb(urb);
  641. fail_hif_send:
  642. return status;
  643. }
  644. static void hif_stop(struct ath6kl *ar)
  645. {
  646. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  647. ath6kl_usb_flush_all(device);
  648. }
  649. static void ath6kl_usb_get_default_pipe(struct ath6kl *ar,
  650. u8 *ul_pipe, u8 *dl_pipe)
  651. {
  652. *ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
  653. *dl_pipe = ATH6KL_USB_PIPE_RX_CTRL;
  654. }
  655. static int ath6kl_usb_map_service_pipe(struct ath6kl *ar, u16 svc_id,
  656. u8 *ul_pipe, u8 *dl_pipe)
  657. {
  658. int status = 0;
  659. switch (svc_id) {
  660. case HTC_CTRL_RSVD_SVC:
  661. case WMI_CONTROL_SVC:
  662. *ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
  663. /* due to large control packets, shift to data pipe */
  664. *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
  665. break;
  666. case WMI_DATA_BE_SVC:
  667. case WMI_DATA_BK_SVC:
  668. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
  669. /*
  670. * Disable rxdata2 directly, it will be enabled
  671. * if FW enable rxdata2
  672. */
  673. *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
  674. break;
  675. case WMI_DATA_VI_SVC:
  676. if (test_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
  677. ar->fw_capabilities))
  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 (test_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
  689. ar->fw_capabilities))
  690. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
  691. else
  692. *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
  693. /*
  694. * Disable rxdata2 directly, it will be enabled
  695. * if FW enable rxdata2
  696. */
  697. *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
  698. break;
  699. default:
  700. status = -EPERM;
  701. break;
  702. }
  703. return status;
  704. }
  705. static u16 ath6kl_usb_get_free_queue_number(struct ath6kl *ar, u8 pipe_id)
  706. {
  707. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  708. return device->pipes[pipe_id].urb_cnt;
  709. }
  710. static void hif_detach_htc(struct ath6kl *ar)
  711. {
  712. struct ath6kl_usb *device = ath6kl_usb_priv(ar);
  713. ath6kl_usb_flush_all(device);
  714. }
  715. static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb,
  716. u8 req, u16 value, u16 index, void *data,
  717. u32 size)
  718. {
  719. u8 *buf = NULL;
  720. int ret;
  721. if (size > 0) {
  722. buf = kmemdup(data, size, GFP_KERNEL);
  723. if (buf == NULL)
  724. return -ENOMEM;
  725. }
  726. /* note: if successful returns number of bytes transfered */
  727. ret = usb_control_msg(ar_usb->udev,
  728. usb_sndctrlpipe(ar_usb->udev, 0),
  729. req,
  730. USB_DIR_OUT | USB_TYPE_VENDOR |
  731. USB_RECIP_DEVICE, value, index, buf,
  732. size, 1000);
  733. if (ret < 0) {
  734. ath6kl_warn("Failed to submit usb control message: %d\n", ret);
  735. kfree(buf);
  736. return ret;
  737. }
  738. kfree(buf);
  739. return 0;
  740. }
  741. static int ath6kl_usb_submit_ctrl_in(struct ath6kl_usb *ar_usb,
  742. u8 req, u16 value, u16 index, void *data,
  743. u32 size)
  744. {
  745. u8 *buf = NULL;
  746. int ret;
  747. if (size > 0) {
  748. buf = kmalloc(size, GFP_KERNEL);
  749. if (buf == NULL)
  750. return -ENOMEM;
  751. }
  752. /* note: if successful returns number of bytes transfered */
  753. ret = usb_control_msg(ar_usb->udev,
  754. usb_rcvctrlpipe(ar_usb->udev, 0),
  755. req,
  756. USB_DIR_IN | USB_TYPE_VENDOR |
  757. USB_RECIP_DEVICE, value, index, buf,
  758. size, 2 * HZ);
  759. if (ret < 0) {
  760. ath6kl_warn("Failed to read usb control message: %d\n", ret);
  761. kfree(buf);
  762. return 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. ath6kl_warn("diag read32 failed: %d\n", ret);
  807. return ret;
  808. }
  809. resp = (struct ath6kl_usb_ctrl_diag_resp_read *)
  810. ar_usb->diag_resp_buffer;
  811. *data = le32_to_cpu(resp->value);
  812. return ret;
  813. }
  814. static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data)
  815. {
  816. struct ath6kl_usb *ar_usb = ar->hif_priv;
  817. struct ath6kl_usb_ctrl_diag_cmd_write *cmd;
  818. int ret;
  819. cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer;
  820. memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write));
  821. cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE);
  822. cmd->address = cpu_to_le32(address);
  823. cmd->value = data;
  824. ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
  825. ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
  826. (u8 *) cmd,
  827. sizeof(*cmd),
  828. 0, NULL, NULL);
  829. if (ret) {
  830. ath6kl_warn("diag_write32 failed: %d\n", ret);
  831. return ret;
  832. }
  833. return 0;
  834. }
  835. static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
  836. {
  837. struct ath6kl_usb *ar_usb = ar->hif_priv;
  838. int ret;
  839. /* get response */
  840. ret = ath6kl_usb_submit_ctrl_in(ar_usb,
  841. ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP,
  842. 0, 0, buf, len);
  843. if (ret) {
  844. ath6kl_err("Unable to read the bmi data from the device: %d\n",
  845. ret);
  846. return ret;
  847. }
  848. return 0;
  849. }
  850. static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
  851. {
  852. struct ath6kl_usb *ar_usb = ar->hif_priv;
  853. int ret;
  854. /* send command */
  855. ret = ath6kl_usb_submit_ctrl_out(ar_usb,
  856. ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD,
  857. 0, 0, buf, len);
  858. if (ret) {
  859. ath6kl_err("unable to send the bmi data to the device: %d\n",
  860. ret);
  861. return ret;
  862. }
  863. return 0;
  864. }
  865. static int ath6kl_usb_power_on(struct ath6kl *ar)
  866. {
  867. hif_start(ar);
  868. return 0;
  869. }
  870. static int ath6kl_usb_power_off(struct ath6kl *ar)
  871. {
  872. hif_detach_htc(ar);
  873. return 0;
  874. }
  875. static void ath6kl_usb_stop(struct ath6kl *ar)
  876. {
  877. hif_stop(ar);
  878. }
  879. static void ath6kl_usb_cleanup_scatter(struct ath6kl *ar)
  880. {
  881. /*
  882. * USB doesn't support it. Just return.
  883. */
  884. return;
  885. }
  886. static int ath6kl_usb_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
  887. {
  888. /*
  889. * cfg80211 suspend/WOW currently not supported for USB.
  890. */
  891. return 0;
  892. }
  893. static int ath6kl_usb_resume(struct ath6kl *ar)
  894. {
  895. /*
  896. * cfg80211 resume currently not supported for USB.
  897. */
  898. return 0;
  899. }
  900. static const struct ath6kl_hif_ops ath6kl_usb_ops = {
  901. .diag_read32 = ath6kl_usb_diag_read32,
  902. .diag_write32 = ath6kl_usb_diag_write32,
  903. .bmi_read = ath6kl_usb_bmi_read,
  904. .bmi_write = ath6kl_usb_bmi_write,
  905. .power_on = ath6kl_usb_power_on,
  906. .power_off = ath6kl_usb_power_off,
  907. .stop = ath6kl_usb_stop,
  908. .pipe_send = ath6kl_usb_send,
  909. .pipe_get_default = ath6kl_usb_get_default_pipe,
  910. .pipe_map_service = ath6kl_usb_map_service_pipe,
  911. .pipe_get_free_queue_number = ath6kl_usb_get_free_queue_number,
  912. .cleanup_scatter = ath6kl_usb_cleanup_scatter,
  913. .suspend = ath6kl_usb_suspend,
  914. .resume = ath6kl_usb_resume,
  915. };
  916. /* ath6kl usb driver registered functions */
  917. static int ath6kl_usb_probe(struct usb_interface *interface,
  918. const struct usb_device_id *id)
  919. {
  920. struct usb_device *dev = interface_to_usbdev(interface);
  921. struct ath6kl *ar;
  922. struct ath6kl_usb *ar_usb = NULL;
  923. int vendor_id, product_id;
  924. int ret = 0;
  925. usb_get_dev(dev);
  926. vendor_id = le16_to_cpu(dev->descriptor.idVendor);
  927. product_id = le16_to_cpu(dev->descriptor.idProduct);
  928. ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id);
  929. ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id);
  930. if (interface->cur_altsetting)
  931. ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n",
  932. interface->cur_altsetting->desc.bInterfaceNumber);
  933. if (dev->speed == USB_SPEED_HIGH)
  934. ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n");
  935. else
  936. ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n");
  937. ar_usb = ath6kl_usb_create(interface);
  938. if (ar_usb == NULL) {
  939. ret = -ENOMEM;
  940. goto err_usb_put;
  941. }
  942. ar = ath6kl_core_create(&ar_usb->udev->dev);
  943. if (ar == NULL) {
  944. ath6kl_err("Failed to alloc ath6kl core\n");
  945. ret = -ENOMEM;
  946. goto err_usb_destroy;
  947. }
  948. ar->hif_priv = ar_usb;
  949. ar->hif_type = ATH6KL_HIF_TYPE_USB;
  950. ar->hif_ops = &ath6kl_usb_ops;
  951. ar->mbox_info.block_size = 16;
  952. ar->bmi.max_data_size = 252;
  953. ar_usb->ar = ar;
  954. ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE);
  955. if (ret) {
  956. ath6kl_err("Failed to init ath6kl core: %d\n", ret);
  957. goto err_core_free;
  958. }
  959. return ret;
  960. err_core_free:
  961. ath6kl_core_destroy(ar);
  962. err_usb_destroy:
  963. ath6kl_usb_destroy(ar_usb);
  964. err_usb_put:
  965. usb_put_dev(dev);
  966. return ret;
  967. }
  968. static void ath6kl_usb_remove(struct usb_interface *interface)
  969. {
  970. usb_put_dev(interface_to_usbdev(interface));
  971. ath6kl_usb_device_detached(interface);
  972. }
  973. #ifdef CONFIG_PM
  974. static int ath6kl_usb_pm_suspend(struct usb_interface *interface,
  975. pm_message_t message)
  976. {
  977. struct ath6kl_usb *device;
  978. device = usb_get_intfdata(interface);
  979. ath6kl_usb_flush_all(device);
  980. return 0;
  981. }
  982. static int ath6kl_usb_pm_resume(struct usb_interface *interface)
  983. {
  984. struct ath6kl_usb *device;
  985. device = usb_get_intfdata(interface);
  986. ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA],
  987. ATH6KL_USB_RX_BUFFER_SIZE);
  988. ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA2],
  989. ATH6KL_USB_RX_BUFFER_SIZE);
  990. return 0;
  991. }
  992. #else
  993. #define ath6kl_usb_pm_suspend NULL
  994. #define ath6kl_usb_pm_resume NULL
  995. #endif
  996. /* table of devices that work with this driver */
  997. static struct usb_device_id ath6kl_usb_ids[] = {
  998. {USB_DEVICE(0x0cf3, 0x9375)},
  999. {USB_DEVICE(0x0cf3, 0x9374)},
  1000. { /* Terminating entry */ },
  1001. };
  1002. MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
  1003. static struct usb_driver ath6kl_usb_driver = {
  1004. .name = "ath6kl_usb",
  1005. .probe = ath6kl_usb_probe,
  1006. .suspend = ath6kl_usb_pm_suspend,
  1007. .resume = ath6kl_usb_pm_resume,
  1008. .disconnect = ath6kl_usb_remove,
  1009. .id_table = ath6kl_usb_ids,
  1010. .supports_autosuspend = true,
  1011. .disable_hub_initiated_lpm = 1,
  1012. };
  1013. module_usb_driver(ath6kl_usb_driver);
  1014. MODULE_AUTHOR("Atheros Communications, Inc.");
  1015. MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices");
  1016. MODULE_LICENSE("Dual BSD/GPL");
  1017. MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE);
  1018. MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE);
  1019. MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE);
  1020. MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE);
  1021. MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE);
  1022. MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE);
  1023. MODULE_FIRMWARE(AR6004_HW_1_2_FIRMWARE_FILE);
  1024. MODULE_FIRMWARE(AR6004_HW_1_2_BOARD_DATA_FILE);
  1025. MODULE_FIRMWARE(AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE);
  1026. MODULE_FIRMWARE(AR6004_HW_1_3_FW_DIR "/" AR6004_HW_1_3_FIRMWARE_FILE);
  1027. MODULE_FIRMWARE(AR6004_HW_1_3_BOARD_DATA_FILE);
  1028. MODULE_FIRMWARE(AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE);