23 #define USB_VERSION "1.0"
25 static const char usbdriver_name[] =
"usb8797";
29 static struct semaphore add_remove_card_sem;
58 dev_err(dev,
"%s: invalid skb->len\n", __func__);
64 dev_dbg(dev,
"%s: EP_CMD_EVENT\n", __func__);
72 dev_err(dev,
"CMD: skb->len too large\n");
74 goto exit_restore_skb;
76 dev_dbg(dev,
"CMD: no curr_cmd\n");
82 goto exit_restore_skb;
85 goto exit_restore_skb;
92 if (skb->
len <
sizeof(
u32)) {
93 dev_err(dev,
"EVENT: skb->len too small\n");
95 goto exit_restore_skb;
97 skb_copy_from_linear_data(skb, &tmp,
sizeof(
u32));
102 dev_err(dev,
"EVENT: event body too large\n");
104 goto exit_restore_skb;
114 dev_err(dev,
"unknown recv_type %#x\n", recv_type);
119 dev_dbg(dev,
"%s: EP_DATA\n", __func__);
121 dev_err(dev,
"DATA: skb->len too large\n");
128 dev_err(dev,
"%s: unknown endport %#x\n", __func__, ep);
141 static void mwifiex_usb_rx_complete(
struct urb *
urb)
147 int recv_length = urb->actual_length;
150 if (!adapter || !adapter->
card) {
151 pr_err(
"mwifiex adapter or card structure is not valid\n");
164 "URB status is failed: %d\n", urb->status);
166 if (
card->rx_cmd_ep != context->
ep)
170 if (skb->
len > recv_length)
176 status = mwifiex_usb_recv(adapter, skb, context->
ep);
178 dev_dbg(adapter->
dev,
"info: recv_length=%d, status=%d\n",
187 if (
card->rx_cmd_ep == context->
ep)
193 "received data processing failed!\n");
196 if (
card->rx_cmd_ep != context->
ep)
199 }
else if (urb->status) {
202 "Card is removed: %d\n", urb->status);
209 if (
card->rx_cmd_ep != context->
ep)
216 if (
card->rx_cmd_ep == context->
ep)
221 mwifiex_usb_submit_rx_urb(context, size);
226 static void mwifiex_usb_tx_complete(
struct urb *urb)
232 dev_dbg(adapter->
dev,
"%s: status: %d\n", __func__, urb->status);
239 dev_dbg(adapter->
dev,
"%s: DATA\n", __func__);
242 urb->status ? -1 : 0);
250 static int mwifiex_usb_submit_rx_urb(
struct urb_context *
ctx,
int size)
256 ctx->
skb = dev_alloc_skb(size);
259 "%s: dev_alloc_skb failed\n", __func__);
264 usb_fill_bulk_urb(ctx->
urb, card->
udev,
265 usb_rcvbulkpipe(card->
udev, ctx->
ep), ctx->
skb->data,
266 size, mwifiex_usb_rx_complete, (
void *)ctx);
274 dev_err(adapter->
dev,
"usb_submit_urb failed\n");
327 struct usb_device *
udev = interface_to_usbdev(intf);
328 struct usb_host_interface *iface_desc = intf->cur_altsetting;
332 u16 id_vendor, id_product, bcd_device, bcd_usb;
338 id_vendor =
le16_to_cpu(udev->descriptor.idVendor);
339 id_product =
le16_to_cpu(udev->descriptor.idProduct);
340 bcd_device =
le16_to_cpu(udev->descriptor.bcdDevice);
342 pr_debug(
"info: VID/PID = %X/%X, Boot2 version = %X\n",
343 id_vendor, id_product, bcd_device);
354 pr_debug(
"info: bcdUSB=%#x Device Class=%#x SubClass=%#x Protocl=%#x\n",
355 udev->descriptor.bcdUSB, udev->descriptor.bDeviceClass,
356 udev->descriptor.bDeviceSubClass,
357 udev->descriptor.bDeviceProtocol);
359 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++
i) {
360 epd = &iface_desc->endpoint[
i].desc;
361 if (usb_endpoint_dir_in(epd) &&
363 usb_endpoint_xfer_bulk(epd)) {
364 pr_debug(
"info: bulk IN: max pkt size: %d, addr: %d\n",
370 if (usb_endpoint_dir_in(epd) &&
372 usb_endpoint_xfer_bulk(epd)) {
373 pr_debug(
"info: bulk IN: max pkt size: %d, addr: %d\n",
379 if (usb_endpoint_dir_out(epd) &&
381 usb_endpoint_xfer_bulk(epd)) {
382 pr_debug(
"info: bulk OUT: max pkt size: %d, addr: %d\n",
388 if (usb_endpoint_dir_out(epd) &&
390 usb_endpoint_xfer_bulk(epd)) {
391 pr_debug(
"info: bulk OUT: max pkt size: %d, addr: %d\n",
401 usb_set_intfdata(intf, card);
406 pr_err(
"%s: mwifiex_add_card failed: %d\n", __func__, ret);
431 pr_err(
"%s: card or card->adapter is NULL\n", __func__);
437 dev_warn(adapter->
dev,
"Device already suspended\n");
449 for (i = 0; i < adapter->
priv_num; i++)
484 pr_err(
"%s: card or card->adapter is NULL\n", __func__);
490 dev_warn(adapter->
dev,
"Device already resumed\n");
507 mwifiex_usb_submit_rx_urb(&card->
rx_cmd,
511 for (i = 0; i < adapter->
priv_num; i++)
512 if (adapter->
priv[i]->media_connected)
525 usb_disable_autosuspend(card->
udev);
531 static void mwifiex_usb_disconnect(
struct usb_interface *intf)
538 pr_err(
"%s: card or card->adapter is NULL\n", __func__);
554 mwifiex_usb_resume(intf);
556 for (i = 0; i < adapter->
priv_num; i++)
559 adapter->
priv[i]->media_connected)
567 mwifiex_usb_free(card);
569 dev_dbg(adapter->
dev,
"%s: removing card\n", __func__);
572 usb_set_intfdata(intf,
NULL);
579 static struct usb_driver mwifiex_usb_driver = {
580 .name = usbdriver_name,
581 .probe = mwifiex_usb_probe,
582 .disconnect = mwifiex_usb_disconnect,
583 .id_table = mwifiex_usb_table,
584 .suspend = mwifiex_usb_suspend,
585 .resume = mwifiex_usb_resume,
586 .supports_autosuspend = 1,
594 card->
tx_cmd.adapter = adapter;
599 dev_err(adapter->
dev,
"tx_cmd.urb allocation failed\n");
612 "tx_data_list[] urb allocation failed\n");
625 card->
rx_cmd.adapter = adapter;
630 dev_err(adapter->
dev,
"rx_cmd.urb allocation failed\n");
636 dev_err(adapter->
dev,
"rx_cmd.skb allocation failed\n");
650 "rx_data_list[] urb allocation failed\n");
665 int actual_length,
ret;
672 *len, &actual_length, timeout);
674 dev_err(adapter->
dev,
"usb_bulk_msg for tx failed: %d\n", ret);
678 *len = actual_length;
687 int actual_length,
ret;
691 *len, &actual_length, timeout);
693 dev_err(adapter->
dev,
"usb_bulk_msg for rx failed: %d\n", ret);
697 *len = actual_length;
714 "%s: not allowed while suspended\n", __func__);
719 dev_err(adapter->
dev,
"%s: device removed\n", __func__);
728 dev_dbg(adapter->
dev,
"%s: ep=%d\n", __func__, ep);
741 tx_urb = context->
urb;
743 usb_fill_bulk_urb(tx_urb, card->
udev, usb_sndbulkpipe(card->
udev, ep),
744 data, skb->
len, mwifiex_usb_tx_complete,
747 tx_urb->transfer_flags |= URB_ZERO_PACKET;
755 dev_err(adapter->
dev,
"%s: usb_submit_urb failed\n", __func__);
783 adapter->
dev = &card->
udev->dev;
796 if (offset + len > adapter->
firmware->size)
810 u32 fw_seqnum = 0, tlen = 0, dnld_cmd = 0;
817 "No firmware image found! Terminating download\n");
843 mwifiex_get_fw_data(adapter, tlen,
854 mwifiex_get_fw_data(adapter, tlen, dlen,
863 u8 *buf = (
u8 *)fwdata;
867 ret = mwifiex_write_data_sync(adapter, buf, &len,
872 "write_data_sync: failed: %d\n", ret);
880 ret = mwifiex_read_data_sync(adapter, buf, &len,
885 "read_data_sync: failed: %d\n", ret);
889 memcpy(&sync_fw, recv_buff,
896 "USB is not the winner %#x\n",
905 "USB is the winner, start to download FW\n");
914 "FW received block with CRC %#x\n",
927 dev_dbg(adapter->
dev,
"%s: %d bytes downloaded\n", __func__, tlen);
945 ret = mwifiex_prog_fw_w_helper(adapter, fw);
954 ret = mwifiex_usb_rx_init(adapter);
956 ret = mwifiex_usb_tx_init(adapter);
968 mwifiex_usb_submit_rx_urb(&card->
rx_cmd,
974 static int mwifiex_usb_cmd_event_complete(
struct mwifiex_adapter *adapter,
1004 .register_dev = mwifiex_register_dev,
1005 .wakeup = mwifiex_pm_wakeup_card,
1006 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
1009 .dnld_fw = mwifiex_usb_dnld_fw,
1010 .cmdrsp_complete = mwifiex_usb_cmd_event_complete,
1011 .event_complete = mwifiex_usb_cmd_event_complete,
1012 .data_complete = mwifiex_usb_data_complete,
1013 .host_to_card = mwifiex_usb_host_to_card,
1021 static int mwifiex_usb_init_module(
void)
1025 pr_debug(
"Marvell USB8797 Driver\n");
1027 sema_init(&add_remove_card_sem, 1);
1029 ret = usb_register(&mwifiex_usb_driver);
1031 pr_err(
"Driver register failed!\n");
1033 pr_debug(
"info: Driver registered successfully!\n");
1046 static void mwifiex_usb_cleanup_module(
void)
1049 up(&add_remove_card_sem);