usb.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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 u8 user_rmmod;
  23. static struct mwifiex_if_ops usb_ops;
  24. static struct semaphore add_remove_card_sem;
  25. static struct usb_device_id mwifiex_usb_table[] = {
  26. /* 8766 */
  27. {USB_DEVICE(USB8XXX_VID, USB8766_PID_1)},
  28. {USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8766_PID_2,
  29. USB_CLASS_VENDOR_SPEC,
  30. USB_SUBCLASS_VENDOR_SPEC, 0xff)},
  31. /* 8797 */
  32. {USB_DEVICE(USB8XXX_VID, USB8797_PID_1)},
  33. {USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8797_PID_2,
  34. USB_CLASS_VENDOR_SPEC,
  35. USB_SUBCLASS_VENDOR_SPEC, 0xff)},
  36. /* 8801 */
  37. {USB_DEVICE(USB8XXX_VID, USB8801_PID_1)},
  38. {USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8801_PID_2,
  39. USB_CLASS_VENDOR_SPEC,
  40. USB_SUBCLASS_VENDOR_SPEC, 0xff)},
  41. /* 8997 */
  42. {USB_DEVICE(USB8XXX_VID, USB8997_PID_1)},
  43. {USB_DEVICE_AND_INTERFACE_INFO(USB8XXX_VID, USB8997_PID_2,
  44. USB_CLASS_VENDOR_SPEC,
  45. USB_SUBCLASS_VENDOR_SPEC, 0xff)},
  46. { } /* Terminating entry */
  47. };
  48. MODULE_DEVICE_TABLE(usb, mwifiex_usb_table);
  49. static int mwifiex_usb_submit_rx_urb(struct urb_context *ctx, int size);
  50. /* This function handles received packet. Necessary action is taken based on
  51. * cmd/event/data.
  52. */
  53. static int mwifiex_usb_recv(struct mwifiex_adapter *adapter,
  54. struct sk_buff *skb, u8 ep)
  55. {
  56. u32 recv_type;
  57. __le32 tmp;
  58. int ret;
  59. if (adapter->hs_activated)
  60. mwifiex_process_hs_config(adapter);
  61. if (skb->len < INTF_HEADER_LEN) {
  62. mwifiex_dbg(adapter, ERROR,
  63. "%s: invalid skb->len\n", __func__);
  64. return -1;
  65. }
  66. switch (ep) {
  67. case MWIFIEX_USB_EP_CMD_EVENT:
  68. mwifiex_dbg(adapter, EVENT,
  69. "%s: EP_CMD_EVENT\n", __func__);
  70. skb_copy_from_linear_data(skb, &tmp, INTF_HEADER_LEN);
  71. recv_type = le32_to_cpu(tmp);
  72. skb_pull(skb, INTF_HEADER_LEN);
  73. switch (recv_type) {
  74. case MWIFIEX_USB_TYPE_CMD:
  75. if (skb->len > MWIFIEX_SIZE_OF_CMD_BUFFER) {
  76. mwifiex_dbg(adapter, ERROR,
  77. "CMD: skb->len too large\n");
  78. ret = -1;
  79. goto exit_restore_skb;
  80. } else if (!adapter->curr_cmd) {
  81. mwifiex_dbg(adapter, WARN, "CMD: no curr_cmd\n");
  82. if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
  83. mwifiex_process_sleep_confirm_resp(
  84. adapter, skb->data,
  85. skb->len);
  86. ret = 0;
  87. goto exit_restore_skb;
  88. }
  89. ret = -1;
  90. goto exit_restore_skb;
  91. }
  92. adapter->curr_cmd->resp_skb = skb;
  93. adapter->cmd_resp_received = true;
  94. break;
  95. case MWIFIEX_USB_TYPE_EVENT:
  96. if (skb->len < sizeof(u32)) {
  97. mwifiex_dbg(adapter, ERROR,
  98. "EVENT: skb->len too small\n");
  99. ret = -1;
  100. goto exit_restore_skb;
  101. }
  102. skb_copy_from_linear_data(skb, &tmp, sizeof(u32));
  103. adapter->event_cause = le32_to_cpu(tmp);
  104. mwifiex_dbg(adapter, EVENT,
  105. "event_cause %#x\n", adapter->event_cause);
  106. if (skb->len > MAX_EVENT_SIZE) {
  107. mwifiex_dbg(adapter, ERROR,
  108. "EVENT: event body too large\n");
  109. ret = -1;
  110. goto exit_restore_skb;
  111. }
  112. memcpy(adapter->event_body, skb->data +
  113. MWIFIEX_EVENT_HEADER_LEN, skb->len);
  114. adapter->event_received = true;
  115. adapter->event_skb = skb;
  116. break;
  117. default:
  118. mwifiex_dbg(adapter, ERROR,
  119. "unknown recv_type %#x\n", recv_type);
  120. return -1;
  121. }
  122. break;
  123. case MWIFIEX_USB_EP_DATA:
  124. mwifiex_dbg(adapter, DATA, "%s: EP_DATA\n", __func__);
  125. if (skb->len > MWIFIEX_RX_DATA_BUF_SIZE) {
  126. mwifiex_dbg(adapter, ERROR,
  127. "DATA: skb->len too large\n");
  128. return -1;
  129. }
  130. skb_queue_tail(&adapter->rx_data_q, skb);
  131. adapter->data_received = true;
  132. atomic_inc(&adapter->rx_pending);
  133. break;
  134. default:
  135. mwifiex_dbg(adapter, ERROR,
  136. "%s: unknown endport %#x\n", __func__, ep);
  137. return -1;
  138. }
  139. return -EINPROGRESS;
  140. exit_restore_skb:
  141. /* The buffer will be reused for further cmds/events */
  142. skb_push(skb, INTF_HEADER_LEN);
  143. return ret;
  144. }
  145. static void mwifiex_usb_rx_complete(struct urb *urb)
  146. {
  147. struct urb_context *context = (struct urb_context *)urb->context;
  148. struct mwifiex_adapter *adapter = context->adapter;
  149. struct sk_buff *skb = context->skb;
  150. struct usb_card_rec *card;
  151. int recv_length = urb->actual_length;
  152. int size, status;
  153. if (!adapter || !adapter->card) {
  154. pr_err("mwifiex adapter or card structure is not valid\n");
  155. return;
  156. }
  157. card = (struct usb_card_rec *)adapter->card;
  158. if (card->rx_cmd_ep == context->ep)
  159. atomic_dec(&card->rx_cmd_urb_pending);
  160. else
  161. atomic_dec(&card->rx_data_urb_pending);
  162. if (recv_length) {
  163. if (urb->status || (adapter->surprise_removed)) {
  164. mwifiex_dbg(adapter, ERROR,
  165. "URB status is failed: %d\n", urb->status);
  166. /* Do not free skb in case of command ep */
  167. if (card->rx_cmd_ep != context->ep)
  168. dev_kfree_skb_any(skb);
  169. goto setup_for_next;
  170. }
  171. if (skb->len > recv_length)
  172. skb_trim(skb, recv_length);
  173. else
  174. skb_put(skb, recv_length - skb->len);
  175. status = mwifiex_usb_recv(adapter, skb, context->ep);
  176. mwifiex_dbg(adapter, INFO,
  177. "info: recv_length=%d, status=%d\n",
  178. recv_length, status);
  179. if (status == -EINPROGRESS) {
  180. mwifiex_queue_main_work(adapter);
  181. /* urb for data_ep is re-submitted now;
  182. * urb for cmd_ep will be re-submitted in callback
  183. * mwifiex_usb_recv_complete
  184. */
  185. if (card->rx_cmd_ep == context->ep)
  186. return;
  187. } else {
  188. if (status == -1)
  189. mwifiex_dbg(adapter, ERROR,
  190. "received data processing failed!\n");
  191. /* Do not free skb in case of command ep */
  192. if (card->rx_cmd_ep != context->ep)
  193. dev_kfree_skb_any(skb);
  194. }
  195. } else if (urb->status) {
  196. if (!adapter->is_suspended) {
  197. mwifiex_dbg(adapter, FATAL,
  198. "Card is removed: %d\n", urb->status);
  199. adapter->surprise_removed = true;
  200. }
  201. dev_kfree_skb_any(skb);
  202. return;
  203. } else {
  204. /* Do not free skb in case of command ep */
  205. if (card->rx_cmd_ep != context->ep)
  206. dev_kfree_skb_any(skb);
  207. /* fall through setup_for_next */
  208. }
  209. setup_for_next:
  210. if (card->rx_cmd_ep == context->ep)
  211. size = MWIFIEX_RX_CMD_BUF_SIZE;
  212. else
  213. size = MWIFIEX_RX_DATA_BUF_SIZE;
  214. if (card->rx_cmd_ep == context->ep) {
  215. mwifiex_usb_submit_rx_urb(context, size);
  216. } else {
  217. if (atomic_read(&adapter->rx_pending) <= HIGH_RX_PENDING){
  218. mwifiex_usb_submit_rx_urb(context, size);
  219. }else{
  220. context->skb = NULL;
  221. }
  222. }
  223. return;
  224. }
  225. static void mwifiex_usb_tx_complete(struct urb *urb)
  226. {
  227. struct urb_context *context = (struct urb_context *)(urb->context);
  228. struct mwifiex_adapter *adapter = context->adapter;
  229. struct usb_card_rec *card = adapter->card;
  230. struct usb_tx_data_port *port;
  231. int i;
  232. mwifiex_dbg(adapter, INFO,
  233. "%s: status: %d\n", __func__, urb->status);
  234. if (context->ep == card->tx_cmd_ep) {
  235. mwifiex_dbg(adapter, CMD,
  236. "%s: CMD\n", __func__);
  237. atomic_dec(&card->tx_cmd_urb_pending);
  238. adapter->cmd_sent = false;
  239. } else {
  240. mwifiex_dbg(adapter, DATA,
  241. "%s: DATA\n", __func__);
  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. mwifiex_write_data_complete(adapter, context->skb, 0,
  252. urb->status ? -1 : 0);
  253. }
  254. if (card->mc_resync_flag)
  255. mwifiex_multi_chan_resync(adapter);
  256. mwifiex_queue_main_work(adapter);
  257. return;
  258. }
  259. static int mwifiex_usb_submit_rx_urb(struct urb_context *ctx, int size)
  260. {
  261. struct mwifiex_adapter *adapter = ctx->adapter;
  262. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  263. if (card->rx_cmd_ep != ctx->ep) {
  264. ctx->skb = dev_alloc_skb(size);
  265. if (!ctx->skb) {
  266. mwifiex_dbg(adapter, ERROR,
  267. "%s: dev_alloc_skb failed\n", __func__);
  268. return -ENOMEM;
  269. }
  270. }
  271. usb_fill_bulk_urb(ctx->urb, card->udev,
  272. usb_rcvbulkpipe(card->udev, ctx->ep), ctx->skb->data,
  273. size, mwifiex_usb_rx_complete, (void *)ctx);
  274. if (card->rx_cmd_ep == ctx->ep)
  275. atomic_inc(&card->rx_cmd_urb_pending);
  276. else
  277. atomic_inc(&card->rx_data_urb_pending);
  278. if (usb_submit_urb(ctx->urb, GFP_ATOMIC)) {
  279. mwifiex_dbg(adapter, ERROR, "usb_submit_urb failed\n");
  280. dev_kfree_skb_any(ctx->skb);
  281. ctx->skb = NULL;
  282. if (card->rx_cmd_ep == ctx->ep)
  283. atomic_dec(&card->rx_cmd_urb_pending);
  284. else
  285. atomic_dec(&card->rx_data_urb_pending);
  286. return -1;
  287. }
  288. return 0;
  289. }
  290. static void mwifiex_usb_free(struct usb_card_rec *card)
  291. {
  292. struct usb_tx_data_port *port;
  293. int i, j;
  294. if (atomic_read(&card->rx_cmd_urb_pending) && card->rx_cmd.urb)
  295. usb_kill_urb(card->rx_cmd.urb);
  296. usb_free_urb(card->rx_cmd.urb);
  297. card->rx_cmd.urb = NULL;
  298. if (atomic_read(&card->rx_data_urb_pending))
  299. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
  300. if (card->rx_data_list[i].urb)
  301. usb_kill_urb(card->rx_data_list[i].urb);
  302. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
  303. usb_free_urb(card->rx_data_list[i].urb);
  304. card->rx_data_list[i].urb = NULL;
  305. }
  306. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  307. port = &card->port[i];
  308. for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
  309. usb_free_urb(port->tx_data_list[j].urb);
  310. port->tx_data_list[j].urb = NULL;
  311. }
  312. }
  313. usb_free_urb(card->tx_cmd.urb);
  314. card->tx_cmd.urb = NULL;
  315. return;
  316. }
  317. /* This function probes an mwifiex device and registers it. It allocates
  318. * the card structure, initiates the device registration and initialization
  319. * procedure by adding a logical interface.
  320. */
  321. static int mwifiex_usb_probe(struct usb_interface *intf,
  322. const struct usb_device_id *id)
  323. {
  324. struct usb_device *udev = interface_to_usbdev(intf);
  325. struct usb_host_interface *iface_desc = intf->cur_altsetting;
  326. struct usb_endpoint_descriptor *epd;
  327. int ret, i;
  328. struct usb_card_rec *card;
  329. u16 id_vendor, id_product, bcd_device, bcd_usb;
  330. card = kzalloc(sizeof(struct usb_card_rec), GFP_KERNEL);
  331. if (!card)
  332. return -ENOMEM;
  333. id_vendor = le16_to_cpu(udev->descriptor.idVendor);
  334. id_product = le16_to_cpu(udev->descriptor.idProduct);
  335. bcd_device = le16_to_cpu(udev->descriptor.bcdDevice);
  336. bcd_usb = le16_to_cpu(udev->descriptor.bcdUSB);
  337. pr_debug("info: VID/PID = %X/%X, Boot2 version = %X\n",
  338. id_vendor, id_product, bcd_device);
  339. /* PID_1 is used for firmware downloading only */
  340. switch (id_product) {
  341. case USB8766_PID_1:
  342. case USB8797_PID_1:
  343. case USB8801_PID_1:
  344. case USB8997_PID_1:
  345. card->usb_boot_state = USB8XXX_FW_DNLD;
  346. break;
  347. case USB8766_PID_2:
  348. case USB8797_PID_2:
  349. case USB8801_PID_2:
  350. case USB8997_PID_2:
  351. card->usb_boot_state = USB8XXX_FW_READY;
  352. break;
  353. default:
  354. pr_warn("unknown id_product %#x\n", id_product);
  355. card->usb_boot_state = USB8XXX_FW_DNLD;
  356. break;
  357. }
  358. card->udev = udev;
  359. card->intf = intf;
  360. pr_debug("info: bcdUSB=%#x Device Class=%#x SubClass=%#x Protocol=%#x\n",
  361. udev->descriptor.bcdUSB, udev->descriptor.bDeviceClass,
  362. udev->descriptor.bDeviceSubClass,
  363. udev->descriptor.bDeviceProtocol);
  364. for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
  365. epd = &iface_desc->endpoint[i].desc;
  366. if (usb_endpoint_dir_in(epd) &&
  367. usb_endpoint_num(epd) == MWIFIEX_USB_EP_CMD_EVENT &&
  368. usb_endpoint_xfer_bulk(epd)) {
  369. pr_debug("info: bulk IN: max pkt size: %d, addr: %d\n",
  370. le16_to_cpu(epd->wMaxPacketSize),
  371. epd->bEndpointAddress);
  372. card->rx_cmd_ep = usb_endpoint_num(epd);
  373. atomic_set(&card->rx_cmd_urb_pending, 0);
  374. }
  375. if (usb_endpoint_dir_in(epd) &&
  376. usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA &&
  377. usb_endpoint_xfer_bulk(epd)) {
  378. pr_debug("info: bulk IN: max pkt size: %d, addr: %d\n",
  379. le16_to_cpu(epd->wMaxPacketSize),
  380. epd->bEndpointAddress);
  381. card->rx_data_ep = usb_endpoint_num(epd);
  382. atomic_set(&card->rx_data_urb_pending, 0);
  383. }
  384. if (usb_endpoint_dir_out(epd) &&
  385. usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA &&
  386. usb_endpoint_xfer_bulk(epd)) {
  387. pr_debug("info: bulk OUT: max pkt size: %d, addr: %d\n",
  388. le16_to_cpu(epd->wMaxPacketSize),
  389. epd->bEndpointAddress);
  390. card->port[0].tx_data_ep = usb_endpoint_num(epd);
  391. atomic_set(&card->port[0].tx_data_urb_pending, 0);
  392. }
  393. if (usb_endpoint_dir_out(epd) &&
  394. usb_endpoint_num(epd) == MWIFIEX_USB_EP_DATA_CH2 &&
  395. usb_endpoint_xfer_bulk(epd)) {
  396. pr_debug("info: bulk OUT chan2:\t"
  397. "max pkt size: %d, addr: %d\n",
  398. le16_to_cpu(epd->wMaxPacketSize),
  399. epd->bEndpointAddress);
  400. card->port[1].tx_data_ep = usb_endpoint_num(epd);
  401. atomic_set(&card->port[1].tx_data_urb_pending, 0);
  402. }
  403. if (usb_endpoint_dir_out(epd) &&
  404. usb_endpoint_num(epd) == MWIFIEX_USB_EP_CMD_EVENT &&
  405. usb_endpoint_xfer_bulk(epd)) {
  406. pr_debug("info: bulk OUT: max pkt size: %d, addr: %d\n",
  407. le16_to_cpu(epd->wMaxPacketSize),
  408. epd->bEndpointAddress);
  409. card->tx_cmd_ep = usb_endpoint_num(epd);
  410. atomic_set(&card->tx_cmd_urb_pending, 0);
  411. card->bulk_out_maxpktsize =
  412. le16_to_cpu(epd->wMaxPacketSize);
  413. }
  414. }
  415. usb_set_intfdata(intf, card);
  416. ret = mwifiex_add_card(card, &add_remove_card_sem, &usb_ops,
  417. MWIFIEX_USB);
  418. if (ret) {
  419. pr_err("%s: mwifiex_add_card failed: %d\n", __func__, ret);
  420. usb_reset_device(udev);
  421. kfree(card);
  422. return ret;
  423. }
  424. usb_get_dev(udev);
  425. return 0;
  426. }
  427. /* Kernel needs to suspend all functions separately. Therefore all
  428. * registered functions must have drivers with suspend and resume
  429. * methods. Failing that the kernel simply removes the whole card.
  430. *
  431. * If already not suspended, this function allocates and sends a
  432. * 'host sleep activate' request to the firmware and turns off the traffic.
  433. */
  434. static int mwifiex_usb_suspend(struct usb_interface *intf, pm_message_t message)
  435. {
  436. struct usb_card_rec *card = usb_get_intfdata(intf);
  437. struct mwifiex_adapter *adapter;
  438. struct usb_tx_data_port *port;
  439. int i, j;
  440. if (!card || !card->adapter) {
  441. pr_err("%s: card or card->adapter is NULL\n", __func__);
  442. return 0;
  443. }
  444. adapter = card->adapter;
  445. if (unlikely(adapter->is_suspended))
  446. mwifiex_dbg(adapter, WARN,
  447. "Device already suspended\n");
  448. mwifiex_enable_hs(adapter);
  449. /* 'is_suspended' flag indicates device is suspended.
  450. * It must be set here before the usb_kill_urb() calls. Reason
  451. * is in the complete handlers, urb->status(= -ENOENT) and
  452. * this flag is used in combination to distinguish between a
  453. * 'suspended' state and a 'disconnect' one.
  454. */
  455. adapter->is_suspended = true;
  456. adapter->hs_enabling = false;
  457. if (atomic_read(&card->rx_cmd_urb_pending) && card->rx_cmd.urb)
  458. usb_kill_urb(card->rx_cmd.urb);
  459. if (atomic_read(&card->rx_data_urb_pending))
  460. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
  461. if (card->rx_data_list[i].urb)
  462. usb_kill_urb(card->rx_data_list[i].urb);
  463. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  464. port = &card->port[i];
  465. for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
  466. if (port->tx_data_list[j].urb)
  467. usb_kill_urb(port->tx_data_list[j].urb);
  468. }
  469. }
  470. if (card->tx_cmd.urb)
  471. usb_kill_urb(card->tx_cmd.urb);
  472. return 0;
  473. }
  474. /* Kernel needs to suspend all functions separately. Therefore all
  475. * registered functions must have drivers with suspend and resume
  476. * methods. Failing that the kernel simply removes the whole card.
  477. *
  478. * If already not resumed, this function turns on the traffic and
  479. * sends a 'host sleep cancel' request to the firmware.
  480. */
  481. static int mwifiex_usb_resume(struct usb_interface *intf)
  482. {
  483. struct usb_card_rec *card = usb_get_intfdata(intf);
  484. struct mwifiex_adapter *adapter;
  485. int i;
  486. if (!card || !card->adapter) {
  487. pr_err("%s: card or card->adapter is NULL\n", __func__);
  488. return 0;
  489. }
  490. adapter = card->adapter;
  491. if (unlikely(!adapter->is_suspended)) {
  492. mwifiex_dbg(adapter, WARN,
  493. "Device already resumed\n");
  494. return 0;
  495. }
  496. /* Indicate device resumed. The netdev queue will be resumed only
  497. * after the urbs have been re-submitted
  498. */
  499. adapter->is_suspended = false;
  500. if (!atomic_read(&card->rx_data_urb_pending))
  501. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++)
  502. mwifiex_usb_submit_rx_urb(&card->rx_data_list[i],
  503. MWIFIEX_RX_DATA_BUF_SIZE);
  504. if (!atomic_read(&card->rx_cmd_urb_pending)) {
  505. card->rx_cmd.skb = dev_alloc_skb(MWIFIEX_RX_CMD_BUF_SIZE);
  506. if (card->rx_cmd.skb)
  507. mwifiex_usb_submit_rx_urb(&card->rx_cmd,
  508. MWIFIEX_RX_CMD_BUF_SIZE);
  509. }
  510. /* Disable Host Sleep */
  511. if (adapter->hs_activated)
  512. mwifiex_cancel_hs(mwifiex_get_priv(adapter,
  513. MWIFIEX_BSS_ROLE_ANY),
  514. MWIFIEX_ASYNC_CMD);
  515. return 0;
  516. }
  517. static void mwifiex_usb_disconnect(struct usb_interface *intf)
  518. {
  519. struct usb_card_rec *card = usb_get_intfdata(intf);
  520. struct mwifiex_adapter *adapter;
  521. if (!card || !card->adapter) {
  522. pr_err("%s: card or card->adapter is NULL\n", __func__);
  523. return;
  524. }
  525. adapter = card->adapter;
  526. if (!adapter->priv_num)
  527. return;
  528. if (user_rmmod) {
  529. #ifdef CONFIG_PM
  530. if (adapter->is_suspended)
  531. mwifiex_usb_resume(intf);
  532. #endif
  533. mwifiex_deauthenticate_all(adapter);
  534. mwifiex_init_shutdown_fw(mwifiex_get_priv(adapter,
  535. MWIFIEX_BSS_ROLE_ANY),
  536. MWIFIEX_FUNC_SHUTDOWN);
  537. }
  538. if (adapter->workqueue)
  539. flush_workqueue(adapter->workqueue);
  540. mwifiex_usb_free(card);
  541. mwifiex_dbg(adapter, FATAL,
  542. "%s: removing card\n", __func__);
  543. mwifiex_remove_card(adapter, &add_remove_card_sem);
  544. usb_set_intfdata(intf, NULL);
  545. usb_put_dev(interface_to_usbdev(intf));
  546. kfree(card);
  547. return;
  548. }
  549. static struct usb_driver mwifiex_usb_driver = {
  550. .name = "mwifiex_usb",
  551. .probe = mwifiex_usb_probe,
  552. .disconnect = mwifiex_usb_disconnect,
  553. .id_table = mwifiex_usb_table,
  554. .suspend = mwifiex_usb_suspend,
  555. .resume = mwifiex_usb_resume,
  556. .soft_unbind = 1,
  557. };
  558. static int mwifiex_usb_tx_init(struct mwifiex_adapter *adapter)
  559. {
  560. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  561. struct usb_tx_data_port *port;
  562. int i, j;
  563. card->tx_cmd.adapter = adapter;
  564. card->tx_cmd.ep = card->tx_cmd_ep;
  565. card->tx_cmd.urb = usb_alloc_urb(0, GFP_KERNEL);
  566. if (!card->tx_cmd.urb) {
  567. mwifiex_dbg(adapter, ERROR,
  568. "tx_cmd.urb allocation failed\n");
  569. return -ENOMEM;
  570. }
  571. for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
  572. port = &card->port[i];
  573. if (!port->tx_data_ep)
  574. continue;
  575. port->tx_data_ix = 0;
  576. if (port->tx_data_ep == MWIFIEX_USB_EP_DATA)
  577. port->block_status = false;
  578. else
  579. port->block_status = true;
  580. for (j = 0; j < MWIFIEX_TX_DATA_URB; j++) {
  581. port->tx_data_list[j].adapter = adapter;
  582. port->tx_data_list[j].ep = port->tx_data_ep;
  583. port->tx_data_list[j].urb =
  584. usb_alloc_urb(0, GFP_KERNEL);
  585. if (!port->tx_data_list[j].urb) {
  586. mwifiex_dbg(adapter, ERROR,
  587. "urb allocation failed\n");
  588. return -ENOMEM;
  589. }
  590. }
  591. }
  592. return 0;
  593. }
  594. static int mwifiex_usb_rx_init(struct mwifiex_adapter *adapter)
  595. {
  596. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  597. int i;
  598. card->rx_cmd.adapter = adapter;
  599. card->rx_cmd.ep = card->rx_cmd_ep;
  600. card->rx_cmd.urb = usb_alloc_urb(0, GFP_KERNEL);
  601. if (!card->rx_cmd.urb) {
  602. mwifiex_dbg(adapter, ERROR, "rx_cmd.urb allocation failed\n");
  603. return -ENOMEM;
  604. }
  605. card->rx_cmd.skb = dev_alloc_skb(MWIFIEX_RX_CMD_BUF_SIZE);
  606. if (!card->rx_cmd.skb)
  607. return -ENOMEM;
  608. if (mwifiex_usb_submit_rx_urb(&card->rx_cmd, MWIFIEX_RX_CMD_BUF_SIZE))
  609. return -1;
  610. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
  611. card->rx_data_list[i].adapter = adapter;
  612. card->rx_data_list[i].ep = card->rx_data_ep;
  613. card->rx_data_list[i].urb = usb_alloc_urb(0, GFP_KERNEL);
  614. if (!card->rx_data_list[i].urb) {
  615. mwifiex_dbg(adapter, ERROR,
  616. "rx_data_list[] urb allocation failed\n");
  617. return -1;
  618. }
  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;
  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. ret = -EBUSY;
  754. goto done;
  755. }
  756. if (port->tx_data_ix >= MWIFIEX_TX_DATA_URB)
  757. port->tx_data_ix = 0;
  758. context =
  759. &port->tx_data_list[port->tx_data_ix++];
  760. break;
  761. }
  762. }
  763. if (!port) {
  764. mwifiex_dbg(adapter, ERROR, "Wrong usb tx data port\n");
  765. return -1;
  766. }
  767. }
  768. context->adapter = adapter;
  769. context->ep = ep;
  770. context->skb = skb;
  771. tx_urb = context->urb;
  772. usb_fill_bulk_urb(tx_urb, card->udev, usb_sndbulkpipe(card->udev, ep),
  773. data, skb->len, mwifiex_usb_tx_complete,
  774. (void *)context);
  775. tx_urb->transfer_flags |= URB_ZERO_PACKET;
  776. if (ep == card->tx_cmd_ep)
  777. atomic_inc(&card->tx_cmd_urb_pending);
  778. else
  779. atomic_inc(&port->tx_data_urb_pending);
  780. if (usb_submit_urb(tx_urb, GFP_ATOMIC)) {
  781. mwifiex_dbg(adapter, ERROR,
  782. "%s: usb_submit_urb failed\n", __func__);
  783. if (ep == card->tx_cmd_ep) {
  784. atomic_dec(&card->tx_cmd_urb_pending);
  785. } else {
  786. atomic_dec(&port->tx_data_urb_pending);
  787. port->block_status = false;
  788. if (port->tx_data_ix)
  789. port->tx_data_ix--;
  790. else
  791. port->tx_data_ix = MWIFIEX_TX_DATA_URB;
  792. }
  793. return -1;
  794. } else {
  795. if (ep != card->tx_cmd_ep &&
  796. atomic_read(&port->tx_data_urb_pending) ==
  797. MWIFIEX_TX_DATA_URB) {
  798. port->block_status = true;
  799. ret = -ENOSR;
  800. goto done;
  801. }
  802. }
  803. return -EINPROGRESS;
  804. done:
  805. if (ep != card->tx_cmd_ep)
  806. adapter->data_sent = mwifiex_usb_data_sent(adapter);
  807. return ret;
  808. }
  809. /* This function register usb device and initialize parameter. */
  810. static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
  811. {
  812. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  813. card->adapter = adapter;
  814. adapter->dev = &card->udev->dev;
  815. switch (le16_to_cpu(card->udev->descriptor.idProduct)) {
  816. case USB8997_PID_1:
  817. case USB8997_PID_2:
  818. adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_4K;
  819. strcpy(adapter->fw_name, USB8997_DEFAULT_FW_NAME);
  820. adapter->ext_scan = true;
  821. break;
  822. case USB8766_PID_1:
  823. case USB8766_PID_2:
  824. adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  825. strcpy(adapter->fw_name, USB8766_DEFAULT_FW_NAME);
  826. adapter->ext_scan = true;
  827. break;
  828. case USB8801_PID_1:
  829. case USB8801_PID_2:
  830. adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  831. strcpy(adapter->fw_name, USB8801_DEFAULT_FW_NAME);
  832. adapter->ext_scan = false;
  833. break;
  834. case USB8797_PID_1:
  835. case USB8797_PID_2:
  836. default:
  837. adapter->tx_buf_size = MWIFIEX_TX_DATA_BUF_SIZE_2K;
  838. strcpy(adapter->fw_name, USB8797_DEFAULT_FW_NAME);
  839. break;
  840. }
  841. adapter->usb_mc_status = false;
  842. adapter->usb_mc_setup = false;
  843. return 0;
  844. }
  845. static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
  846. {
  847. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  848. card->adapter = NULL;
  849. }
  850. static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
  851. struct mwifiex_fw_image *fw)
  852. {
  853. int ret = 0;
  854. u8 *firmware = fw->fw_buf, *recv_buff;
  855. u32 retries = USB8XXX_FW_MAX_RETRY, dlen;
  856. u32 fw_seqnum = 0, tlen = 0, dnld_cmd = 0;
  857. struct fw_data *fwdata;
  858. struct fw_sync_header sync_fw;
  859. u8 check_winner = 1;
  860. if (!firmware) {
  861. mwifiex_dbg(adapter, ERROR,
  862. "No firmware image found! Terminating download\n");
  863. ret = -1;
  864. goto fw_exit;
  865. }
  866. /* Allocate memory for transmit */
  867. fwdata = kzalloc(FW_DNLD_TX_BUF_SIZE, GFP_KERNEL);
  868. if (!fwdata) {
  869. ret = -ENOMEM;
  870. goto fw_exit;
  871. }
  872. /* Allocate memory for receive */
  873. recv_buff = kzalloc(FW_DNLD_RX_BUF_SIZE, GFP_KERNEL);
  874. if (!recv_buff)
  875. goto cleanup;
  876. do {
  877. /* Send pseudo data to check winner status first */
  878. if (check_winner) {
  879. memset(&fwdata->fw_hdr, 0, sizeof(struct fw_header));
  880. dlen = 0;
  881. } else {
  882. /* copy the header of the fw_data to get the length */
  883. memcpy(&fwdata->fw_hdr, &firmware[tlen],
  884. sizeof(struct fw_header));
  885. dlen = le32_to_cpu(fwdata->fw_hdr.data_len);
  886. dnld_cmd = le32_to_cpu(fwdata->fw_hdr.dnld_cmd);
  887. tlen += sizeof(struct fw_header);
  888. memcpy(fwdata->data, &firmware[tlen], dlen);
  889. fwdata->seq_num = cpu_to_le32(fw_seqnum);
  890. tlen += dlen;
  891. }
  892. /* If the send/receive fails or CRC occurs then retry */
  893. while (retries--) {
  894. u8 *buf = (u8 *)fwdata;
  895. u32 len = FW_DATA_XMIT_SIZE;
  896. /* send the firmware block */
  897. ret = mwifiex_write_data_sync(adapter, buf, &len,
  898. MWIFIEX_USB_EP_CMD_EVENT,
  899. MWIFIEX_USB_TIMEOUT);
  900. if (ret) {
  901. mwifiex_dbg(adapter, ERROR,
  902. "write_data_sync: failed: %d\n",
  903. ret);
  904. continue;
  905. }
  906. buf = recv_buff;
  907. len = FW_DNLD_RX_BUF_SIZE;
  908. /* Receive the firmware block response */
  909. ret = mwifiex_read_data_sync(adapter, buf, &len,
  910. MWIFIEX_USB_EP_CMD_EVENT,
  911. MWIFIEX_USB_TIMEOUT);
  912. if (ret) {
  913. mwifiex_dbg(adapter, ERROR,
  914. "read_data_sync: failed: %d\n",
  915. ret);
  916. continue;
  917. }
  918. memcpy(&sync_fw, recv_buff,
  919. sizeof(struct fw_sync_header));
  920. /* check 1st firmware block resp for highest bit set */
  921. if (check_winner) {
  922. if (le32_to_cpu(sync_fw.cmd) & 0x80000000) {
  923. mwifiex_dbg(adapter, WARN,
  924. "USB is not the winner %#x\n",
  925. sync_fw.cmd);
  926. /* returning success */
  927. ret = 0;
  928. goto cleanup;
  929. }
  930. mwifiex_dbg(adapter, MSG,
  931. "start to download FW...\n");
  932. check_winner = 0;
  933. break;
  934. }
  935. /* check the firmware block response for CRC errors */
  936. if (sync_fw.cmd) {
  937. mwifiex_dbg(adapter, ERROR,
  938. "FW received block with CRC %#x\n",
  939. sync_fw.cmd);
  940. ret = -1;
  941. continue;
  942. }
  943. retries = USB8XXX_FW_MAX_RETRY;
  944. break;
  945. }
  946. fw_seqnum++;
  947. } while ((dnld_cmd != FW_HAS_LAST_BLOCK) && retries);
  948. cleanup:
  949. mwifiex_dbg(adapter, MSG,
  950. "info: FW download over, size %d bytes\n", tlen);
  951. kfree(recv_buff);
  952. kfree(fwdata);
  953. if (retries)
  954. ret = 0;
  955. fw_exit:
  956. return ret;
  957. }
  958. static int mwifiex_usb_dnld_fw(struct mwifiex_adapter *adapter,
  959. struct mwifiex_fw_image *fw)
  960. {
  961. int ret;
  962. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  963. if (card->usb_boot_state == USB8XXX_FW_DNLD) {
  964. ret = mwifiex_prog_fw_w_helper(adapter, fw);
  965. if (ret)
  966. return -1;
  967. /* Boot state changes after successful firmware download */
  968. if (card->usb_boot_state == USB8XXX_FW_DNLD)
  969. return -1;
  970. }
  971. ret = mwifiex_usb_rx_init(adapter);
  972. if (!ret)
  973. ret = mwifiex_usb_tx_init(adapter);
  974. return ret;
  975. }
  976. static void mwifiex_submit_rx_urb(struct mwifiex_adapter *adapter, u8 ep)
  977. {
  978. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  979. skb_push(card->rx_cmd.skb, INTF_HEADER_LEN);
  980. if ((ep == card->rx_cmd_ep) &&
  981. (!atomic_read(&card->rx_cmd_urb_pending)))
  982. mwifiex_usb_submit_rx_urb(&card->rx_cmd,
  983. MWIFIEX_RX_CMD_BUF_SIZE);
  984. return;
  985. }
  986. static int mwifiex_usb_cmd_event_complete(struct mwifiex_adapter *adapter,
  987. struct sk_buff *skb)
  988. {
  989. mwifiex_submit_rx_urb(adapter, MWIFIEX_USB_EP_CMD_EVENT);
  990. return 0;
  991. }
  992. /* This function wakes up the card. */
  993. static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
  994. {
  995. /* Simulation of HS_AWAKE event */
  996. adapter->pm_wakeup_fw_try = false;
  997. del_timer(&adapter->wakeup_timer);
  998. adapter->pm_wakeup_card_req = false;
  999. adapter->ps_state = PS_STATE_AWAKE;
  1000. return 0;
  1001. }
  1002. static void mwifiex_usb_submit_rem_rx_urbs(struct mwifiex_adapter *adapter)
  1003. {
  1004. struct usb_card_rec *card = (struct usb_card_rec *)adapter->card;
  1005. int i;
  1006. struct urb_context *ctx;
  1007. for (i = 0; i < MWIFIEX_RX_DATA_URB; i++) {
  1008. if (card->rx_data_list[i].skb)
  1009. continue;
  1010. ctx = &card->rx_data_list[i];
  1011. mwifiex_usb_submit_rx_urb(ctx, MWIFIEX_RX_DATA_BUF_SIZE);
  1012. }
  1013. }
  1014. /* This function is called after the card has woken up. */
  1015. static inline int
  1016. mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
  1017. {
  1018. return 0;
  1019. }
  1020. static struct mwifiex_if_ops usb_ops = {
  1021. .register_dev = mwifiex_register_dev,
  1022. .unregister_dev = mwifiex_unregister_dev,
  1023. .wakeup = mwifiex_pm_wakeup_card,
  1024. .wakeup_complete = mwifiex_pm_wakeup_card_complete,
  1025. /* USB specific */
  1026. .dnld_fw = mwifiex_usb_dnld_fw,
  1027. .cmdrsp_complete = mwifiex_usb_cmd_event_complete,
  1028. .event_complete = mwifiex_usb_cmd_event_complete,
  1029. .host_to_card = mwifiex_usb_host_to_card,
  1030. .submit_rem_rx_urbs = mwifiex_usb_submit_rem_rx_urbs,
  1031. .multi_port_resync = mwifiex_usb_port_resync,
  1032. .is_port_ready = mwifiex_usb_is_port_ready,
  1033. };
  1034. /* This function initializes the USB driver module.
  1035. *
  1036. * This initiates the semaphore and registers the device with
  1037. * USB bus.
  1038. */
  1039. static int mwifiex_usb_init_module(void)
  1040. {
  1041. int ret;
  1042. pr_debug("Marvell USB8797 Driver\n");
  1043. sema_init(&add_remove_card_sem, 1);
  1044. ret = usb_register(&mwifiex_usb_driver);
  1045. if (ret)
  1046. pr_err("Driver register failed!\n");
  1047. else
  1048. pr_debug("info: Driver registered successfully!\n");
  1049. return ret;
  1050. }
  1051. /* This function cleans up the USB driver.
  1052. *
  1053. * The following major steps are followed in .disconnect for cleanup:
  1054. * - Resume the device if its suspended
  1055. * - Disconnect the device if connected
  1056. * - Shutdown the firmware
  1057. * - Unregister the device from USB bus.
  1058. */
  1059. static void mwifiex_usb_cleanup_module(void)
  1060. {
  1061. if (!down_interruptible(&add_remove_card_sem))
  1062. up(&add_remove_card_sem);
  1063. /* set the flag as user is removing this module */
  1064. user_rmmod = 1;
  1065. usb_deregister(&mwifiex_usb_driver);
  1066. }
  1067. module_init(mwifiex_usb_init_module);
  1068. module_exit(mwifiex_usb_cleanup_module);
  1069. MODULE_AUTHOR("Marvell International Ltd.");
  1070. MODULE_DESCRIPTION("Marvell WiFi-Ex USB Driver version" USB_VERSION);
  1071. MODULE_VERSION(USB_VERSION);
  1072. MODULE_LICENSE("GPL v2");
  1073. MODULE_FIRMWARE(USB8766_DEFAULT_FW_NAME);
  1074. MODULE_FIRMWARE(USB8797_DEFAULT_FW_NAME);
  1075. MODULE_FIRMWARE(USB8801_DEFAULT_FW_NAME);
  1076. MODULE_FIRMWARE(USB8997_DEFAULT_FW_NAME);