usb.c 31 KB

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