usb.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. /*
  2. * Marvell Wireless LAN device driver: USB specific handling
  3. *
  4. * Copyright (C) 2012-2014, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include "main.h"
  20. #include "usb.h"
  21. #define USB_VERSION "1.0"
  22. static struct mwifiex_if_ops usb_ops;
  23. static struct usb_device_id mwifiex_usb_table[] = {
  24. /* 8766 */
  25. {USB_DEVICE(USB8XXX_VID, USB8766_PID_1)},
  26. {USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8766_PID_2,
  27. USB_CLASS_VENDOR_SPEC,
  28. USB_SUBCLASS_VENDOR_SPEC, 0xff)},
  29. /* 8797 */
  30. {USB_DEVICE(USB8XXX_VID, USB8797_PID_1)},
  31. {USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8797_PID_2,
  32. USB_CLASS_VENDOR_SPEC,
  33. USB_SUBCLASS_VENDOR_SPEC, 0xff)},
  34. /* 8801 */
  35. {USB_DEVICE(USB8XXX_VID, USB8801_PID_1)},
  36. {USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8801_PID_2,
  37. USB_CLASS_VENDOR_SPEC,
  38. USB_SUBCLASS_VENDOR_SPEC, 0xff)},
  39. /* 8997 */
  40. {USB_DEVICE(USB8XXX_VID, USB8997_PID_1)},
  41. {USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8997_PID_2,
  42. USB_CLASS_VENDOR_SPEC,
  43. USB_SUBCLASS_VENDOR_SPEC, 0xff)},
  44. { } /* Terminating entry */
  45. };
  46. MODULE_DEVICE_TABLE(usb, mwifiex_usb_table);
  47. static int mwifiex_usb_submit_rx_urb(struct urb_context *ctx, int size);
  48. /* This function handles received packet. Necessary action is taken based on
  49. * cmd/event/data.
  50. */
  51. static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
  52. struct sk_buff *skb, u8 ep)
  53. {
  54. u32 recv_type;
  55. __le32 tmp;
  56. int ret;
  57. if (adapter->hs_activated)
  58. mwifiex_process_hs_config(adapter);
  59. if (skb->len < INTF_HEADER_LEN) {
  60. mwifiex_dbg(adapter, ERROR,
  61. "%s: invalid skb->len\n", __func__);
  62. return -1;
  63. }
  64. switch (ep) {
  65. case MWIFIEX_USB_EP_CMD_EVENT:
  66. mwifiex_dbg(adapter, EVENT,
  67. "%s: EP_CMD_EVENT\n", __func__);
  68. skb_copy_from_linear_data(skb, &tmp, INTF_HEADER_LEN);
  69. recv_type = le32_to_cpu(tmp);
  70. skb_pull(skb, INTF_HEADER_LEN);
  71. switch (recv_type) {
  72. case MWIFIEX_USB_TYPE_CMD:
  73. if (skb->len > MWIFIEX_SIZE_OF_CMD_BUFFER) {
  74. mwifiex_dbg(adapter, ERROR,
  75. "CMD: skb->len too large\n");
  76. ret = -1;
  77. goto exit_restore_skb;
  78. } else if (!adapter->curr_cmd) {
  79. mwifiex_dbg(adapter, WARN, "CMD: no curr_cmd\n");
  80. if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
  81. mwifiex_process_sleep_confirm_resp(
  82. adapter, skb->data,
  83. skb->len);
  84. ret = 0;
  85. goto exit_restore_skb;
  86. }
  87. ret = -1;
  88. goto exit_restore_skb;
  89. }
  90. adapter->curr_cmd->resp_skb = skb;
  91. adapter->cmd_resp_received = true;
  92. break;
  93. case MWIFIEX_USB_TYPE_EVENT:
  94. if (skb->len < sizeof(u32)) {
  95. mwifiex_dbg(adapter, ERROR,
  96. "EVENT: skb->len too small\n");
  97. ret = -1;
  98. goto exit_restore_skb;
  99. }
  100. skb_copy_from_linear_data(skb, &tmp, sizeof(u32));
  101. adapter->event_cause = le32_to_cpu(tmp);
  102. mwifiex_dbg(adapter, EVENT,
  103. "event_cause %#x\n", adapter->event_cause);
  104. if (skb->len > MAX_EVENT_SIZE) {
  105. mwifiex_dbg(adapter, ERROR,
  106. "EVENT: event body too large\n");
  107. ret = -1;
  108. goto exit_restore_skb;
  109. }
  110. memcpy(adapter->event_body, skb->data +
  111. MWIFIEX_EVENT_HEADER_LEN, skb->len);
  112. adapter->event_received = true;
  113. adapter->event_skb = skb;
  114. break;
  115. default:
  116. mwifiex_dbg(adapter, ERROR,
  117. "unknown recv_type %#x\n", recv_type);
  118. return -1;
  119. }
  120. break;
  121. case MWIFIEX_USB_EP_DATA:
  122. mwifiex_dbg(adapter, DATA, "%s: EP_DATA\n", __func__);
  123. if (skb->len > MWIFIEX_RX_DATA_BUF_SIZE) {
  124. mwifiex_dbg(adapter, ERROR,
  125. "DATA: skb->len too large\n");
  126. return -1;
  127. }
  128. skb_queue_tail(&adapter->rx_data_q, skb);
  129. adapter->data_received = true;
  130. atomic_inc(&adapter->rx_pending);
  131. break;
  132. default:
  133. mwifiex_dbg(adapter, ERROR,
  134. "%s: unknown endport %#x\n", __func__, ep);
  135. return -1;
  136. }
  137. return -EINPROGRESS;
  138. exit_restore_skb:
  139. /* The buffer will be reused for further cmds/events */
  140. skb_push(skb, INTF_HEADER_LEN);
  141. return ret;
  142. }
  143. static void mwifiex_usb_rx_complete(struct urb *urb)
  144. {
  145. struct urb_context *context = (struct urb_context *)urb->context;
  146. struct mwifiex_adapter *adapter = context->adapter;
  147. struct sk_buff *skb = context->skb;
  148. struct usb_card_rec *card;
  149. int recv_length = urb->actual_length;
  150. int size, status;
  151. if (!adapter || !adapter->card) {
  152. pr_err("mwifiex adapter or card structure is not valid\n");
  153. return;
  154. }
  155. card = (struct usb_card_rec *)adapter->card;
  156. if (card->rx_cmd_ep == context->ep)
  157. atomic_dec(&card->rx_cmd_urb_pending);
  158. else
  159. atomic_dec(&card->rx_data_urb_pending);
  160. if (recv_length) {
  161. if (urb->status || (adapter->surprise_removed)) {
  162. mwifiex_dbg(adapter, ERROR,
  163. "URB status is failed: %d\n", urb->status);
  164. /* Do not free skb in case of command ep */
  165. if (card->rx_cmd_ep != context->ep)
  166. dev_kfree_skb_any(skb);
  167. goto setup_for_next;
  168. }
  169. if (skb->len > recv_length)
  170. skb_trim(skb, recv_length);
  171. else
  172. skb_put(skb, recv_length - skb->len);
  173. status = mwifiex_usb_recv(adapter, skb, context->ep);
  174. mwifiex_dbg(adapter, INFO,
  175. "info: recv_length=%d, status=%d\n",
  176. recv_length, status);
  177. if (status == -EINPROGRESS) {
  178. mwifiex_queue_main_work(adapter);
  179. /* urb for data_ep is re-submitted now;
  180. * urb for cmd_ep will be re-submitted in callback
  181. * mwifiex_usb_recv_complete
  182. */
  183. if (card->rx_cmd_ep == context->ep)
  184. return;
  185. } else {
  186. if (status == -1)
  187. mwifiex_dbg(adapter, ERROR,
  188. "received data processing failed!\n");
  189. /* Do not free skb in case of command ep */
  190. if (card->rx_cmd_ep != context->ep)
  191. dev_kfree_skb_any(skb);
  192. }
  193. } else if (urb->status) {
  194. if (!adapter->is_suspended) {
  195. mwifiex_dbg(adapter, FATAL,
  196. "Card is removed: %d\n", urb->status);
  197. adapter->surprise_removed = true;
  198. }
  199. dev_kfree_skb_any(skb);
  200. return;
  201. } else {
  202. /* Do not free skb in case of command ep */
  203. if (card->rx_cmd_ep != context->ep)
  204. dev_kfree_skb_any(skb);
  205. /* fall through setup_for_next */
  206. }
  207. setup_for_next:
  208. if (card->rx_cmd_ep == context->ep)
  209. size = MWIFIEX_RX_CMD_BUF_SIZE;
  210. else
  211. size = MWIFIEX_RX_DATA_BUF_SIZE;
  212. if (card->rx_cmd_ep == context->ep) {
  213. mwifiex_usb_submit_rx_urb(context, size);
  214. } else {
  215. if (atomic_read(&adapter->rx_pending) <= HIGH_RX_PENDING) {
  216. mwifiex_usb_submit_rx_urb(context, size);
  217. } else {
  218. context->skb = NULL;
  219. }
  220. }
  221. return;
  222. }
  223. static void mwifiex_usb_tx_complete(struct urb *urb)
  224. {
  225. struct urb_context *context = (struct urb_context *)(urb->context);
  226. struct mwifiex_adapter *adapter = context->adapter;
  227. struct usb_card_rec *card = adapter->card;
  228. struct usb_tx_data_port *port;
  229. int i;
  230. mwifiex_dbg(adapter, INFO,
  231. "%s: status: %d\n", __func__, urb->status);
  232. if (context->ep == card->tx_cmd_ep) {
  233. mwifiex_dbg(adapter, CMD,
  234. "%s: CMD\n", __func__);
  235. atomic_dec(&card->tx_cmd_urb_pending);
  236. adapter->cmd_sent = false;
  237. } else {
  238. mwifiex_dbg(adapter, DATA,
  239. "%s: DATA\n", __func__);
  240. mwifiex_write_data_complete(adapter, context->skb, 0,
  241. urb->status ? -1 : 0);
  242. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  243. port = &card->port[i];
  244. if (context->ep == port->tx_data_ep) {
  245. atomic_dec(&port->tx_data_urb_pending);
  246. port->block_status = false;
  247. break;
  248. }
  249. }
  250. adapter->data_sent = false;
  251. }
  252. if (card->mc_resync_flag)
  253. mwifiex_multi_chan_resync(adapter);
  254. mwifiex_queue_main_work(adapter);
  255. return;
  256. }
  257. static int mwifiex_usb_submit_rx_urb(struct urb_context *ctx, int size)
  258. {
  259. struct mwifiex_adapter *adapter = ctx->adapter;
  260. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  261. if (card->rx_cmd_ep != ctx->ep) {
  262. ctx->skb = dev_alloc_skb(size);
  263. if (!ctx->skb) {
  264. mwifiex_dbg(adapter, ERROR,
  265. "%s: dev_alloc_skb failed\n", __func__);
  266. return -ENOMEM;
  267. }
  268. }
  269. if (card->rx_cmd_ep == ctx->ep &&
  270. card->rx_cmd_ep_type == USB_ENDPOINT_XFER_INT)
  271. usb_fill_int_urb(ctx->urb, card->udev,
  272. usb_rcvintpipe(card->udev, ctx->ep),
  273. ctx->skb->data, size, mwifiex_usb_rx_complete,
  274. (void *)ctx, card->rx_cmd_interval);
  275. else
  276. usb_fill_bulk_urb(ctx->urb, card->udev,
  277. usb_rcvbulkpipe(card->udev, ctx->ep),
  278. ctx->skb->data, size, mwifiex_usb_rx_complete,
  279. (void *)ctx);
  280. if (card->rx_cmd_ep == ctx->ep)
  281. atomic_inc(&card->rx_cmd_urb_pending);
  282. else
  283. atomic_inc(&card->rx_data_urb_pending);
  284. if (usb_submit_urb(ctx->urb, GFP_ATOMIC)) {
  285. mwifiex_dbg(adapter, ERROR, "usb_submit_urb failed\n");
  286. dev_kfree_skb_any(ctx->skb);
  287. ctx->skb = NULL;
  288. if (card->rx_cmd_ep == ctx->ep)
  289. atomic_dec(&card->rx_cmd_urb_pending);
  290. else
  291. atomic_dec(&card->rx_data_urb_pending);
  292. return -1;
  293. }
  294. return 0;
  295. }
  296. static void mwifiex_usb_free(struct usb_card_rec *card)
  297. {
  298. struct usb_tx_data_port *port;
  299. int i, j;
  300. if (atomic_read(&card->rx_cmd_urb_pending) && card->rx_cmd.urb)
  301. usb_kill_urb(card->rx_cmd.urb);
  302. usb_free_urb(card->rx_cmd.urb);
  303. card->rx_cmd.urb = NULL;
  304. if (atomic_read(&card->rx_data_urb_pending))
  305. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
  306. if (card->rx_data_list[i].urb)
  307. usb_kill_urb(card->rx_data_list[i].urb);
  308. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
  309. usb_free_urb(card->rx_data_list[i].urb);
  310. card->rx_data_list[i].urb = NULL;
  311. }
  312. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  313. port = &card->port[i];
  314. for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
  315. usb_free_urb(port->tx_data_list[j].urb);
  316. port->tx_data_list[j].urb = NULL;
  317. }
  318. }
  319. usb_free_urb(card->tx_cmd.urb);
  320. card->tx_cmd.urb = NULL;
  321. return;
  322. }
  323. /* This function probes an mwifiex device and registers it. It allocates
  324. * the card structure, initiates the device registration and initialization
  325. * procedure by adding a logical interface.
  326. */
  327. static int mwifiex_usb_probe(struct usb_interface *intf,
  328. const struct usb_device_id *id)
  329. {
  330. struct usb_device *udev = interface_to_usbdev(intf);
  331. struct usb_host_interface *iface_desc = intf->cur_altsetting;
  332. struct usb_endpoint_descriptor *epd;
  333. int ret, i;
  334. struct usb_card_rec *card;
  335. u16 id_vendor, id_product, bcd_device;
  336. card = devm_kzalloc(&intf->dev, sizeof(*card), GFP_KERNEL);
  337. if (!card)
  338. return -ENOMEM;
  339. init_completion(&card->fw_done);
  340. id_vendor = le16_to_cpu(udev->descriptor.idVendor);
  341. id_product = le16_to_cpu(udev->descriptor.idProduct);
  342. bcd_device = le16_to_cpu(udev->descriptor.bcdDevice);
  343. pr_debug("info: VID/PID = %X/%X, Boot2 version = %X\n",
  344. id_vendor, id_product, bcd_device);
  345. /* PID_1 is used for firmware downloading only */
  346. switch (id_product) {
  347. case USB8766_PID_1:
  348. case USB8797_PID_1:
  349. case USB8801_PID_1:
  350. case USB8997_PID_1:
  351. card->usb_boot_state = USB8XXX_FW_DNLD;
  352. break;
  353. case USB8766_PID_2:
  354. case USB8797_PID_2:
  355. case USB8801_PID_2:
  356. case USB8997_PID_2:
  357. card->usb_boot_state = USB8XXX_FW_READY;
  358. break;
  359. default:
  360. pr_warn("unknown id_product %#x\n", id_product);
  361. card->usb_boot_state = USB8XXX_FW_DNLD;
  362. break;
  363. }
  364. card->udev = udev;
  365. card->intf = intf;
  366. pr_debug("info: bcdUSB=%#x Device Class=%#x SubClass=%#x Protocol=%#x\n",
  367. udev->descriptor.bcdUSB, udev->descriptor.bDeviceClass,
  368. udev->descriptor.bDeviceSubClass,
  369. udev->descriptor.bDeviceProtocol);
  370. for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
  371. epd = &iface_desc->endpoint[i].desc;
  372. if (usb_endpoint_dir_in(epd) &&
  373. usb_endpoint_num(epd) == MWIFIEX_USB_EP_CMD_EVENT &&
  374. (usb_endpoint_xfer_bulk(epd) ||
  375. usb_endpoint_xfer_int(epd))) {
  376. card->rx_cmd_ep_type = usb_endpoint_type(epd);
  377. card->rx_cmd_interval = epd->bInterval;
  378. pr_debug("info: Rx CMD/EVT:: max pkt size: %d, addr: %d, ep_type: %d\n",
  379. le16_to_cpu(epd->wMaxPacketSize),
  380. epd->bEndpointAddress, card->rx_cmd_ep_type);
  381. card->rx_cmd_ep = usb_endpoint_num(epd);
  382. atomic_set(&card->rx_cmd_urb_pending, 0);
  383. }
  384. if (usb_endpoint_dir_in(epd) &&
  385. usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA &&
  386. usb_endpoint_xfer_bulk(epd)) {
  387. pr_debug("info: bulk IN: max pkt size: %d, addr: %d\n",
  388. le16_to_cpu(epd->wMaxPacketSize),
  389. epd->bEndpointAddress);
  390. card->rx_data_ep = usb_endpoint_num(epd);
  391. atomic_set(&card->rx_data_urb_pending, 0);
  392. }
  393. if (usb_endpoint_dir_out(epd) &&
  394. usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA &&
  395. usb_endpoint_xfer_bulk(epd)) {
  396. pr_debug("info: bulk OUT: max pkt size: %d, addr: %d\n",
  397. le16_to_cpu(epd->wMaxPacketSize),
  398. epd->bEndpointAddress);
  399. card->port[0].tx_data_ep = usb_endpoint_num(epd);
  400. atomic_set(&card->port[0].tx_data_urb_pending, 0);
  401. }
  402. if (usb_endpoint_dir_out(epd) &&
  403. usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA_CH2 &&
  404. usb_endpoint_xfer_bulk(epd)) {
  405. pr_debug("info: bulk OUT chan2:\t"
  406. "max pkt size: %d, addr: %d\n",
  407. le16_to_cpu(epd->wMaxPacketSize),
  408. epd->bEndpointAddress);
  409. card->port[1].tx_data_ep = usb_endpoint_num(epd);
  410. atomic_set(&card->port[1].tx_data_urb_pending, 0);
  411. }
  412. if (usb_endpoint_dir_out(epd) &&
  413. usb_endpoint_num(epd) == MWIFIEX_USB_EP_CMD_EVENT &&
  414. (usb_endpoint_xfer_bulk(epd) ||
  415. usb_endpoint_xfer_int(epd))) {
  416. card->tx_cmd_ep_type = usb_endpoint_type(epd);
  417. card->tx_cmd_interval = epd->bInterval;
  418. pr_debug("info: bulk OUT: max pkt size: %d, addr: %d\n",
  419. le16_to_cpu(epd->wMaxPacketSize),
  420. epd->bEndpointAddress);
  421. pr_debug("info: Tx CMD:: max pkt size: %d, addr: %d, ep_type: %d\n",
  422. le16_to_cpu(epd->wMaxPacketSize),
  423. epd->bEndpointAddress, card->tx_cmd_ep_type);
  424. card->tx_cmd_ep = usb_endpoint_num(epd);
  425. atomic_set(&card->tx_cmd_urb_pending, 0);
  426. card->bulk_out_maxpktsize =
  427. le16_to_cpu(epd->wMaxPacketSize);
  428. }
  429. }
  430. usb_set_intfdata(intf, card);
  431. ret = mwifiex_add_card(card, &card->fw_done, &usb_ops,
  432. MWIFIEX_USB, &card->udev->dev);
  433. if (ret) {
  434. pr_err("%s: mwifiex_add_card failed: %d\n", __func__, ret);
  435. usb_reset_device(udev);
  436. return ret;
  437. }
  438. usb_get_dev(udev);
  439. return 0;
  440. }
  441. /* Kernel needs to suspend all functions separately. Therefore all
  442. * registered functions must have drivers with suspend and resume
  443. * methods. Failing that the kernel simply removes the whole card.
  444. *
  445. * If already not suspended, this function allocates and sends a
  446. * 'host sleep activate' request to the firmware and turns off the traffic.
  447. */
  448. static int mwifiex_usb_suspend(struct usb_interface *intf, pm_message_t message)
  449. {
  450. struct usb_card_rec *card = usb_get_intfdata(intf);
  451. struct mwifiex_adapter *adapter;
  452. struct usb_tx_data_port *port;
  453. int i, j;
  454. /* Might still be loading firmware */
  455. wait_for_completion(&card->fw_done);
  456. adapter = card->adapter;
  457. if (!adapter) {
  458. dev_err(&intf->dev, "card is not valid\n");
  459. return 0;
  460. }
  461. if (unlikely(adapter->is_suspended))
  462. mwifiex_dbg(adapter, WARN,
  463. "Device already suspended\n");
  464. /* Enable the Host Sleep */
  465. if (!mwifiex_enable_hs(adapter)) {
  466. mwifiex_dbg(adapter, ERROR,
  467. "cmd: failed to suspend\n");
  468. adapter->hs_enabling = false;
  469. return -EFAULT;
  470. }
  471. /* 'is_suspended' flag indicates device is suspended.
  472. * It must be set here before the usb_kill_urb() calls. Reason
  473. * is in the complete handlers, urb->status(= -ENOENT) and
  474. * this flag is used in combination to distinguish between a
  475. * 'suspended' state and a 'disconnect' one.
  476. */
  477. adapter->is_suspended = true;
  478. adapter->hs_enabling = false;
  479. if (atomic_read(&card->rx_cmd_urb_pending) && card->rx_cmd.urb)
  480. usb_kill_urb(card->rx_cmd.urb);
  481. if (atomic_read(&card->rx_data_urb_pending))
  482. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
  483. if (card->rx_data_list[i].urb)
  484. usb_kill_urb(card->rx_data_list[i].urb);
  485. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  486. port = &card->port[i];
  487. for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
  488. if (port->tx_data_list[j].urb)
  489. usb_kill_urb(port->tx_data_list[j].urb);
  490. }
  491. }
  492. if (card->tx_cmd.urb)
  493. usb_kill_urb(card->tx_cmd.urb);
  494. return 0;
  495. }
  496. /* Kernel needs to suspend all functions separately. Therefore all
  497. * registered functions must have drivers with suspend and resume
  498. * methods. Failing that the kernel simply removes the whole card.
  499. *
  500. * If already not resumed, this function turns on the traffic and
  501. * sends a 'host sleep cancel' request to the firmware.
  502. */
  503. static int mwifiex_usb_resume(struct usb_interface *intf)
  504. {
  505. struct usb_card_rec *card = usb_get_intfdata(intf);
  506. struct mwifiex_adapter *adapter;
  507. int i;
  508. if (!card->adapter) {
  509. dev_err(&intf->dev, "%s: card->adapter is NULL\n",
  510. __func__);
  511. return 0;
  512. }
  513. adapter = card->adapter;
  514. if (unlikely(!adapter->is_suspended)) {
  515. mwifiex_dbg(adapter, WARN,
  516. "Device already resumed\n");
  517. return 0;
  518. }
  519. /* Indicate device resumed. The netdev queue will be resumed only
  520. * after the urbs have been re-submitted
  521. */
  522. adapter->is_suspended = false;
  523. if (!atomic_read(&card->rx_data_urb_pending))
  524. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
  525. mwifiex_usb_submit_rx_urb(&card->rx_data_list[i],
  526. MWIFIEX_RX_DATA_BUF_SIZE);
  527. if (!atomic_read(&card->rx_cmd_urb_pending)) {
  528. card->rx_cmd.skb = dev_alloc_skb(MWIFIEX_RX_CMD_BUF_SIZE);
  529. if (card->rx_cmd.skb)
  530. mwifiex_usb_submit_rx_urb(&card->rx_cmd,
  531. MWIFIEX_RX_CMD_BUF_SIZE);
  532. }
  533. /* Disable Host Sleep */
  534. if (adapter->hs_activated)
  535. mwifiex_cancel_hs(mwifiex_get_priv(adapter,
  536. MWIFIEX_BSS_ROLE_ANY),
  537. MWIFIEX_ASYNC_CMD);
  538. return 0;
  539. }
  540. static void mwifiex_usb_disconnect(struct usb_interface *intf)
  541. {
  542. struct usb_card_rec *card = usb_get_intfdata(intf);
  543. struct mwifiex_adapter *adapter;
  544. wait_for_completion(&card->fw_done);
  545. adapter = card->adapter;
  546. if (!adapter || !adapter->priv_num)
  547. return;
  548. if (card->udev->state != USB_STATE_NOTATTACHED && !adapter->mfg_mode) {
  549. mwifiex_deauthenticate_all(adapter);
  550. mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
  551. MWIFIEX_BSS_ROLE_ANY),
  552. MWIFIEX_FUNC_SHUTDOWN);
  553. }
  554. mwifiex_usb_free(card);
  555. mwifiex_dbg(adapter, FATAL,
  556. "%s: removing card\n", __func__);
  557. mwifiex_remove_card(adapter);
  558. usb_put_dev(interface_to_usbdev(intf));
  559. }
  560. static struct usb_driver mwifiex_usb_driver = {
  561. .name = "mwifiex_usb",
  562. .probe = mwifiex_usb_probe,
  563. .disconnect = mwifiex_usb_disconnect,
  564. .id_table = mwifiex_usb_table,
  565. .suspend = mwifiex_usb_suspend,
  566. .resume = mwifiex_usb_resume,
  567. .soft_unbind = 1,
  568. };
  569. static int mwifiex_usb_tx_init(struct mwifiex_adapter *adapter)
  570. {
  571. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  572. struct usb_tx_data_port *port;
  573. int i, j;
  574. card->tx_cmd.adapter = adapter;
  575. card->tx_cmd.ep = card->tx_cmd_ep;
  576. card->tx_cmd.urb = usb_alloc_urb(0, GFP_KERNEL);
  577. if (!card->tx_cmd.urb)
  578. return -ENOMEM;
  579. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  580. port = &card->port[i];
  581. if (!port->tx_data_ep)
  582. continue;
  583. port->tx_data_ix = 0;
  584. if (port->tx_data_ep == MWIFIEX_USB_EP_DATA)
  585. port->block_status = false;
  586. else
  587. port->block_status = true;
  588. for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
  589. port->tx_data_list[j].adapter = adapter;
  590. port->tx_data_list[j].ep = port->tx_data_ep;
  591. port->tx_data_list[j].urb =
  592. usb_alloc_urb(0, GFP_KERNEL);
  593. if (!port->tx_data_list[j].urb)
  594. return -ENOMEM;
  595. }
  596. }
  597. return 0;
  598. }
  599. static int mwifiex_usb_rx_init(struct mwifiex_adapter *adapter)
  600. {
  601. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  602. int i;
  603. card->rx_cmd.adapter = adapter;
  604. card->rx_cmd.ep = card->rx_cmd_ep;
  605. card->rx_cmd.urb = usb_alloc_urb(0, GFP_KERNEL);
  606. if (!card->rx_cmd.urb)
  607. return -ENOMEM;
  608. card->rx_cmd.skb = dev_alloc_skb(MWIFIEX_RX_CMD_BUF_SIZE);
  609. if (!card->rx_cmd.skb)
  610. return -ENOMEM;
  611. if (mwifiex_usb_submit_rx_urb(&card->rx_cmd, MWIFIEX_RX_CMD_BUF_SIZE))
  612. return -1;
  613. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
  614. card->rx_data_list[i].adapter = adapter;
  615. card->rx_data_list[i].ep = card->rx_data_ep;
  616. card->rx_data_list[i].urb = usb_alloc_urb(0, GFP_KERNEL);
  617. if (!card->rx_data_list[i].urb)
  618. return -1;
  619. if (mwifiex_usb_submit_rx_urb(&card->rx_data_list[i],
  620. MWIFIEX_RX_DATA_BUF_SIZE))
  621. return -1;
  622. }
  623. return 0;
  624. }
  625. static int mwifiex_write_data_sync(struct mwifiex_adapter *adapter, u8 *pbuf,
  626. u32 *len, u8 ep, u32 timeout)
  627. {
  628. struct usb_card_rec *card = adapter->card;
  629. int actual_length, ret;
  630. if (!(*len % card->bulk_out_maxpktsize))
  631. (*len)++;
  632. /* Send the data block */
  633. ret = usb_bulk_msg(card->udev, usb_sndbulkpipe(card->udev, ep), pbuf,
  634. *len, &actual_length, timeout);
  635. if (ret) {
  636. mwifiex_dbg(adapter, ERROR,
  637. "usb_bulk_msg for tx failed: %d\n", ret);
  638. return ret;
  639. }
  640. *len = actual_length;
  641. return ret;
  642. }
  643. static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *pbuf,
  644. u32 *len, u8 ep, u32 timeout)
  645. {
  646. struct usb_card_rec *card = adapter->card;
  647. int actual_length, ret;
  648. /* Receive the data response */
  649. ret = usb_bulk_msg(card->udev, usb_rcvbulkpipe(card->udev, ep), pbuf,
  650. *len, &actual_length, timeout);
  651. if (ret) {
  652. mwifiex_dbg(adapter, ERROR,
  653. "usb_bulk_msg for rx failed: %d\n", ret);
  654. return ret;
  655. }
  656. *len = actual_length;
  657. return ret;
  658. }
  659. static void mwifiex_usb_port_resync(struct mwifiex_adapter *adapter)
  660. {
  661. struct usb_card_rec *card = adapter->card;
  662. u8 active_port = MWIFIEX_USB_EP_DATA;
  663. struct mwifiex_private *priv = NULL;
  664. int i;
  665. if (adapter->usb_mc_status) {
  666. for (i = 0; i < adapter->priv_num; i++) {
  667. priv = adapter->priv[i];
  668. if (!priv)
  669. continue;
  670. if ((priv->bss_role == MWIFIEX_BSS_ROLE_UAP &&
  671. !priv->bss_started) ||
  672. (priv->bss_role == MWIFIEX_BSS_ROLE_STA &&
  673. !priv->media_connected))
  674. priv->usb_port = MWIFIEX_USB_EP_DATA;
  675. }
  676. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++)
  677. card->port[i].block_status = false;
  678. } else {
  679. for (i = 0; i < adapter->priv_num; i++) {
  680. priv = adapter->priv[i];
  681. if (!priv)
  682. continue;
  683. if ((priv->bss_role == MWIFIEX_BSS_ROLE_UAP &&
  684. priv->bss_started) ||
  685. (priv->bss_role == MWIFIEX_BSS_ROLE_STA &&
  686. priv->media_connected)) {
  687. active_port = priv->usb_port;
  688. break;
  689. }
  690. }
  691. for (i = 0; i < adapter->priv_num; i++) {
  692. priv = adapter->priv[i];
  693. if (priv)
  694. priv->usb_port = active_port;
  695. }
  696. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  697. if (active_port == card->port[i].tx_data_ep)
  698. card->port[i].block_status = false;
  699. else
  700. card->port[i].block_status = true;
  701. }
  702. }
  703. }
  704. static bool mwifiex_usb_is_port_ready(struct mwifiex_private *priv)
  705. {
  706. struct usb_card_rec *card = priv->adapter->card;
  707. int idx;
  708. for (idx = 0; idx < MWIFIEX_TX_DATA_PORT; idx++) {
  709. if (priv->usb_port == card->port[idx].tx_data_ep)
  710. return !card->port[idx].block_status;
  711. }
  712. return false;
  713. }
  714. static inline u8 mwifiex_usb_data_sent(struct mwifiex_adapter *adapter)
  715. {
  716. struct usb_card_rec *card = adapter->card;
  717. int i;
  718. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++)
  719. if (!card->port[i].block_status)
  720. return false;
  721. return true;
  722. }
  723. /* This function write a command/data packet to card. */
  724. static int mwifiex_usb_host_to_card(struct mwifiex_adapter *adapter, u8 ep,
  725. struct sk_buff *skb,
  726. struct mwifiex_tx_param *tx_param)
  727. {
  728. struct usb_card_rec *card = adapter->card;
  729. struct urb_context *context = NULL;
  730. struct usb_tx_data_port *port = NULL;
  731. u8 *data = (u8 *)skb->data;
  732. struct urb *tx_urb;
  733. int idx, ret = -EINPROGRESS;
  734. if (adapter->is_suspended) {
  735. mwifiex_dbg(adapter, ERROR,
  736. "%s: not allowed while suspended\n", __func__);
  737. return -1;
  738. }
  739. if (adapter->surprise_removed) {
  740. mwifiex_dbg(adapter, ERROR, "%s: device removed\n", __func__);
  741. return -1;
  742. }
  743. mwifiex_dbg(adapter, INFO, "%s: ep=%d\n", __func__, ep);
  744. if (ep == card->tx_cmd_ep) {
  745. context = &card->tx_cmd;
  746. } else {
  747. for (idx = 0; idx < MWIFIEX_TX_DATA_PORT; idx++) {
  748. if (ep == card->port[idx].tx_data_ep) {
  749. port = &card->port[idx];
  750. if (atomic_read(&port->tx_data_urb_pending)
  751. >= MWIFIEX_TX_DATA_URB) {
  752. port->block_status = true;
  753. adapter->data_sent =
  754. mwifiex_usb_data_sent(adapter);
  755. return -EBUSY;
  756. }
  757. if (port->tx_data_ix >= MWIFIEX_TX_DATA_URB)
  758. port->tx_data_ix = 0;
  759. context =
  760. &port->tx_data_list[port->tx_data_ix++];
  761. break;
  762. }
  763. }
  764. if (!port) {
  765. mwifiex_dbg(adapter, ERROR, "Wrong usb tx data port\n");
  766. return -1;
  767. }
  768. }
  769. context->adapter = adapter;
  770. context->ep = ep;
  771. context->skb = skb;
  772. tx_urb = context->urb;
  773. if (ep == card->tx_cmd_ep &&
  774. card->tx_cmd_ep_type == USB_ENDPOINT_XFER_INT)
  775. usb_fill_int_urb(tx_urb, card->udev,
  776. usb_sndintpipe(card->udev, ep), data,
  777. skb->len, mwifiex_usb_tx_complete,
  778. (void *)context, card->tx_cmd_interval);
  779. else
  780. usb_fill_bulk_urb(tx_urb, card->udev,
  781. usb_sndbulkpipe(card->udev, ep), data,
  782. skb->len, mwifiex_usb_tx_complete,
  783. (void *)context);
  784. tx_urb->transfer_flags |= URB_ZERO_PACKET;
  785. if (ep == card->tx_cmd_ep)
  786. atomic_inc(&card->tx_cmd_urb_pending);
  787. else
  788. atomic_inc(&port->tx_data_urb_pending);
  789. if (ep != card->tx_cmd_ep &&
  790. atomic_read(&port->tx_data_urb_pending) ==
  791. MWIFIEX_TX_DATA_URB) {
  792. port->block_status = true;
  793. adapter->data_sent = mwifiex_usb_data_sent(adapter);
  794. ret = -ENOSR;
  795. }
  796. if (usb_submit_urb(tx_urb, GFP_ATOMIC)) {
  797. mwifiex_dbg(adapter, ERROR,
  798. "%s: usb_submit_urb failed\n", __func__);
  799. if (ep == card->tx_cmd_ep) {
  800. atomic_dec(&card->tx_cmd_urb_pending);
  801. } else {
  802. atomic_dec(&port->tx_data_urb_pending);
  803. port->block_status = false;
  804. adapter->data_sent = false;
  805. if (port->tx_data_ix)
  806. port->tx_data_ix--;
  807. else
  808. port->tx_data_ix = MWIFIEX_TX_DATA_URB;
  809. }
  810. ret = -1;
  811. }
  812. return ret;
  813. }
  814. /* This function register usb device and initialize parameter. */
  815. static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
  816. {
  817. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  818. card->adapter = adapter;
  819. switch (le16_to_cpu(card->udev->descriptor.idProduct)) {
  820. case USB8997_PID_1:
  821. case USB8997_PID_2:
  822. adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
  823. strcpy(adapter->fw_name, USB8997_DEFAULT_FW_NAME);
  824. adapter->ext_scan = true;
  825. break;
  826. case USB8766_PID_1:
  827. case USB8766_PID_2:
  828. adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  829. strcpy(adapter->fw_name, USB8766_DEFAULT_FW_NAME);
  830. adapter->ext_scan = true;
  831. break;
  832. case USB8801_PID_1:
  833. case USB8801_PID_2:
  834. adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  835. strcpy(adapter->fw_name, USB8801_DEFAULT_FW_NAME);
  836. adapter->ext_scan = false;
  837. break;
  838. case USB8797_PID_1:
  839. case USB8797_PID_2:
  840. default:
  841. adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  842. strcpy(adapter->fw_name, USB8797_DEFAULT_FW_NAME);
  843. break;
  844. }
  845. adapter->usb_mc_status = false;
  846. adapter->usb_mc_setup = false;
  847. return 0;
  848. }
  849. static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
  850. {
  851. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  852. card->adapter = NULL;
  853. }
  854. static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
  855. struct mwifiex_fw_image *fw)
  856. {
  857. int ret = 0;
  858. u8 *firmware = fw->fw_buf, *recv_buff;
  859. u32 retries = USB8XXX_FW_MAX_RETRY + 1;
  860. u32 dlen;
  861. u32 fw_seqnum = 0, tlen = 0, dnld_cmd = 0;
  862. struct fw_data *fwdata;
  863. struct fw_sync_header sync_fw;
  864. u8 check_winner = 1;
  865. if (!firmware) {
  866. mwifiex_dbg(adapter, ERROR,
  867. "No firmware image found! Terminating download\n");
  868. ret = -1;
  869. goto fw_exit;
  870. }
  871. /* Allocate memory for transmit */
  872. fwdata = kzalloc(FW_DNLD_TX_BUF_SIZE, GFP_KERNEL);
  873. if (!fwdata) {
  874. ret = -ENOMEM;
  875. goto fw_exit;
  876. }
  877. /* Allocate memory for receive */
  878. recv_buff = kzalloc(FW_DNLD_RX_BUF_SIZE, GFP_KERNEL);
  879. if (!recv_buff) {
  880. ret = -ENOMEM;
  881. goto cleanup;
  882. }
  883. do {
  884. /* Send pseudo data to check winner status first */
  885. if (check_winner) {
  886. memset(&fwdata->fw_hdr, 0, sizeof(struct fw_header));
  887. dlen = 0;
  888. } else {
  889. /* copy the header of the fw_data to get the length */
  890. memcpy(&fwdata->fw_hdr, &firmware[tlen],
  891. sizeof(struct fw_header));
  892. dlen = le32_to_cpu(fwdata->fw_hdr.data_len);
  893. dnld_cmd = le32_to_cpu(fwdata->fw_hdr.dnld_cmd);
  894. tlen += sizeof(struct fw_header);
  895. /* Command 7 doesn't have data length field */
  896. if (dnld_cmd == FW_CMD_7)
  897. dlen = 0;
  898. memcpy(fwdata->data, &firmware[tlen], dlen);
  899. fwdata->seq_num = cpu_to_le32(fw_seqnum);
  900. tlen += dlen;
  901. }
  902. /* If the send/receive fails or CRC occurs then retry */
  903. while (--retries) {
  904. u8 *buf = (u8 *)fwdata;
  905. u32 len = FW_DATA_XMIT_SIZE;
  906. /* send the firmware block */
  907. ret = mwifiex_write_data_sync(adapter, buf, &len,
  908. MWIFIEX_USB_EP_CMD_EVENT,
  909. MWIFIEX_USB_TIMEOUT);
  910. if (ret) {
  911. mwifiex_dbg(adapter, ERROR,
  912. "write_data_sync: failed: %d\n",
  913. ret);
  914. continue;
  915. }
  916. buf = recv_buff;
  917. len = FW_DNLD_RX_BUF_SIZE;
  918. /* Receive the firmware block response */
  919. ret = mwifiex_read_data_sync(adapter, buf, &len,
  920. MWIFIEX_USB_EP_CMD_EVENT,
  921. MWIFIEX_USB_TIMEOUT);
  922. if (ret) {
  923. mwifiex_dbg(adapter, ERROR,
  924. "read_data_sync: failed: %d\n",
  925. ret);
  926. continue;
  927. }
  928. memcpy(&sync_fw, recv_buff,
  929. sizeof(struct fw_sync_header));
  930. /* check 1st firmware block resp for highest bit set */
  931. if (check_winner) {
  932. if (le32_to_cpu(sync_fw.cmd) & 0x80000000) {
  933. mwifiex_dbg(adapter, WARN,
  934. "USB is not the winner %#x\n",
  935. sync_fw.cmd);
  936. /* returning success */
  937. ret = 0;
  938. goto cleanup;
  939. }
  940. mwifiex_dbg(adapter, MSG,
  941. "start to download FW...\n");
  942. check_winner = 0;
  943. break;
  944. }
  945. /* check the firmware block response for CRC errors */
  946. if (sync_fw.cmd) {
  947. mwifiex_dbg(adapter, ERROR,
  948. "FW received block with CRC %#x\n",
  949. sync_fw.cmd);
  950. ret = -1;
  951. continue;
  952. }
  953. retries = USB8XXX_FW_MAX_RETRY + 1;
  954. break;
  955. }
  956. fw_seqnum++;
  957. } while ((dnld_cmd != FW_HAS_LAST_BLOCK) && retries);
  958. cleanup:
  959. mwifiex_dbg(adapter, MSG,
  960. "info: FW download over, size %d bytes\n", tlen);
  961. kfree(recv_buff);
  962. kfree(fwdata);
  963. if (retries)
  964. ret = 0;
  965. fw_exit:
  966. return ret;
  967. }
  968. static int mwifiex_usb_dnld_fw(struct mwifiex_adapter *adapter,
  969. struct mwifiex_fw_image *fw)
  970. {
  971. int ret;
  972. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  973. if (card->usb_boot_state == USB8XXX_FW_DNLD) {
  974. ret = mwifiex_prog_fw_w_helper(adapter, fw);
  975. if (ret)
  976. return -1;
  977. /* Boot state changes after successful firmware download */
  978. if (card->usb_boot_state == USB8XXX_FW_DNLD)
  979. return -1;
  980. }
  981. ret = mwifiex_usb_rx_init(adapter);
  982. if (!ret)
  983. ret = mwifiex_usb_tx_init(adapter);
  984. return ret;
  985. }
  986. static void mwifiex_submit_rx_urb(struct mwifiex_adapter *adapter, u8 ep)
  987. {
  988. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  989. skb_push(card->rx_cmd.skb, INTF_HEADER_LEN);
  990. if ((ep == card->rx_cmd_ep) &&
  991. (!atomic_read(&card->rx_cmd_urb_pending)))
  992. mwifiex_usb_submit_rx_urb(&card->rx_cmd,
  993. MWIFIEX_RX_CMD_BUF_SIZE);
  994. return;
  995. }
  996. static int mwifiex_usb_cmd_event_complete(struct mwifiex_adapter *adapter,
  997. struct sk_buff *skb)
  998. {
  999. mwifiex_submit_rx_urb(adapter, MWIFIEX_USB_EP_CMD_EVENT);
  1000. return 0;
  1001. }
  1002. /* This function wakes up the card. */
  1003. static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
  1004. {
  1005. /* Simulation of HS_AWAKE event */
  1006. adapter->pm_wakeup_fw_try = false;
  1007. del_timer(&adapter->wakeup_timer);
  1008. adapter->pm_wakeup_card_req = false;
  1009. adapter->ps_state = PS_STATE_AWAKE;
  1010. return 0;
  1011. }
  1012. static void mwifiex_usb_submit_rem_rx_urbs(struct mwifiex_adapter *adapter)
  1013. {
  1014. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  1015. int i;
  1016. struct urb_context *ctx;
  1017. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
  1018. if (card->rx_data_list[i].skb)
  1019. continue;
  1020. ctx = &card->rx_data_list[i];
  1021. mwifiex_usb_submit_rx_urb(ctx, MWIFIEX_RX_DATA_BUF_SIZE);
  1022. }
  1023. }
  1024. /* This function is called after the card has woken up. */
  1025. static inline int
  1026. mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
  1027. {
  1028. return 0;
  1029. }
  1030. static struct mwifiex_if_ops usb_ops = {
  1031. .register_dev = mwifiex_register_dev,
  1032. .unregister_dev = mwifiex_unregister_dev,
  1033. .wakeup = mwifiex_pm_wakeup_card,
  1034. .wakeup_complete = mwifiex_pm_wakeup_card_complete,
  1035. /* USB specific */
  1036. .dnld_fw = mwifiex_usb_dnld_fw,
  1037. .cmdrsp_complete = mwifiex_usb_cmd_event_complete,
  1038. .event_complete = mwifiex_usb_cmd_event_complete,
  1039. .host_to_card = mwifiex_usb_host_to_card,
  1040. .submit_rem_rx_urbs = mwifiex_usb_submit_rem_rx_urbs,
  1041. .multi_port_resync = mwifiex_usb_port_resync,
  1042. .is_port_ready = mwifiex_usb_is_port_ready,
  1043. };
  1044. module_usb_driver(mwifiex_usb_driver);
  1045. MODULE_AUTHOR("Marvell International Ltd.");
  1046. MODULE_DESCRIPTION("Marvell WiFi-Ex USB Driver version" USB_VERSION);
  1047. MODULE_VERSION(USB_VERSION);
  1048. MODULE_LICENSE("GPL v2");
  1049. MODULE_FIRMWARE(USB8766_DEFAULT_FW_NAME);
  1050. MODULE_FIRMWARE(USB8797_DEFAULT_FW_NAME);
  1051. MODULE_FIRMWARE(USB8801_DEFAULT_FW_NAME);
  1052. MODULE_FIRMWARE(USB8997_DEFAULT_FW_NAME);