2 * This file contains functions used in USB interface module.
4 #include <linux/delay.h>
5 #include <linux/moduleparam.h>
6 #include <linux/firmware.h>
7 #include <linux/netdevice.h>
8 #include <linux/list.h>
11 #define DRV_NAME "usb8xxx"
19 #define MESSAGE_HEADER_LEN 4
21 static const char usbdriver_name[] = "usb8xxx";
22 static u8 *default_fw_name = "usb8388.bin";
24 char *libertas_fw_name = NULL;
25 module_param_named(fw_name, libertas_fw_name, charp, 0644);
28 * We need to send a RESET command to all USB devices before
29 * we tear down the USB connection. Otherwise we would not
30 * be able to re-init device the device if the module gets
31 * loaded again. This is a list of all initialized USB devices,
32 * for the reset code see if_usb_reset_device()
34 static LIST_HEAD(usb_devices);
36 static struct usb_device_id if_usb_table[] = {
37 /* Enter the device signature inside */
38 { USB_DEVICE(0x1286, 0x2001) },
39 { USB_DEVICE(0x05a3, 0x8388) },
40 {} /* Terminating entry */
43 MODULE_DEVICE_TABLE(usb, if_usb_table);
45 static void if_usb_receive(struct urb *urb);
46 static void if_usb_receive_fwload(struct urb *urb);
47 static int if_usb_reset_device(wlan_private *priv);
48 static int if_usb_register_dev(wlan_private * priv);
49 static int if_usb_unregister_dev(wlan_private *);
50 static int if_usb_prog_firmware(wlan_private *);
51 static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb);
52 static int if_usb_get_int_status(wlan_private * priv, u8 *);
53 static int if_usb_read_event_cause(wlan_private *);
56 * @brief call back function to handle the status of the URB
57 * @param urb pointer to urb structure
60 static void if_usb_write_bulk_callback(struct urb *urb)
62 wlan_private *priv = (wlan_private *) (urb->context);
63 wlan_adapter *adapter = priv->adapter;
64 struct net_device *dev = priv->dev;
66 /* handle the transmission complete validations */
68 if (urb->status != 0) {
69 /* print the failure status number for debug */
70 lbs_pr_info("URB in failure status: %d\n", urb->status);
73 lbs_deb_usbd(&urb->dev->dev, "URB status is successfull\n");
74 lbs_deb_usbd(&urb->dev->dev, "Actual length transmitted %d\n",
77 priv->dnld_sent = DNLD_RES_RECEIVED;
78 /* Wake main thread if commands are pending */
79 if (!adapter->cur_cmd)
80 wake_up_interruptible(&priv->mainthread.waitq);
81 if ((adapter->connect_status == libertas_connected)) {
82 netif_wake_queue(dev);
83 netif_wake_queue(priv->mesh_dev);
91 * @brief free tx/rx urb, skb and rx buffer
92 * @param cardp pointer usb_card_rec
95 void if_usb_free(struct usb_card_rec *cardp)
97 lbs_deb_enter(LBS_DEB_USB);
99 /* Unlink tx & rx urb */
100 usb_kill_urb(cardp->tx_urb);
101 usb_kill_urb(cardp->rx_urb);
103 usb_free_urb(cardp->tx_urb);
104 cardp->tx_urb = NULL;
106 usb_free_urb(cardp->rx_urb);
107 cardp->rx_urb = NULL;
109 kfree(cardp->bulk_out_buffer);
110 cardp->bulk_out_buffer = NULL;
112 lbs_deb_leave(LBS_DEB_USB);
116 * @brief sets the configuration values
117 * @param ifnum interface number
118 * @param id pointer to usb_device_id
119 * @return 0 on success, error code on failure
121 static int if_usb_probe(struct usb_interface *intf,
122 const struct usb_device_id *id)
124 struct usb_device *udev;
125 struct usb_host_interface *iface_desc;
126 struct usb_endpoint_descriptor *endpoint;
128 struct usb_card_rec *cardp;
131 udev = interface_to_usbdev(intf);
133 cardp = kzalloc(sizeof(struct usb_card_rec), GFP_KERNEL);
135 lbs_pr_err("Out of memory allocating private data.\n");
140 iface_desc = intf->cur_altsetting;
142 lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X"
143 " bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n",
144 udev->descriptor.bcdUSB,
145 udev->descriptor.bDeviceClass,
146 udev->descriptor.bDeviceSubClass,
147 udev->descriptor.bDeviceProtocol);
149 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
150 endpoint = &iface_desc->endpoint[i].desc;
151 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
152 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
153 USB_ENDPOINT_XFER_BULK)) {
154 /* we found a bulk in endpoint */
155 lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n",
156 endpoint->wMaxPacketSize);
159 usb_alloc_urb(0, GFP_KERNEL))) {
160 lbs_deb_usbd(&udev->dev,
161 "Rx URB allocation failed\n");
164 cardp->rx_urb_recall = 0;
166 cardp->bulk_in_size =
167 endpoint->wMaxPacketSize;
168 cardp->bulk_in_endpointAddr =
170 bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
171 lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n",
172 endpoint->bEndpointAddress);
176 bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
178 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
179 USB_ENDPOINT_XFER_BULK)) {
180 /* We found bulk out endpoint */
183 usb_alloc_urb(0, GFP_KERNEL))) {
184 lbs_deb_usbd(&udev->dev,
185 "Tx URB allocation failed\n");
189 cardp->bulk_out_size =
190 endpoint->wMaxPacketSize;
191 lbs_deb_usbd(&udev->dev,
192 "Bulk out size is %d\n",
193 endpoint->wMaxPacketSize);
194 cardp->bulk_out_endpointAddr =
195 endpoint->bEndpointAddress;
196 lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n",
197 endpoint->bEndpointAddress);
198 cardp->bulk_out_buffer =
199 kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE,
202 if (!cardp->bulk_out_buffer) {
203 lbs_deb_usbd(&udev->dev,
204 "Could not allocate buffer\n");
210 if (!(priv = libertas_add_card(cardp, &udev->dev)))
213 if (libertas_add_mesh(priv, &udev->dev))
216 priv->hw_register_dev = if_usb_register_dev;
217 priv->hw_unregister_dev = if_usb_unregister_dev;
218 priv->hw_prog_firmware = if_usb_prog_firmware;
219 priv->hw_host_to_card = if_usb_host_to_card;
220 priv->hw_get_int_status = if_usb_get_int_status;
221 priv->hw_read_event_cause = if_usb_read_event_cause;
223 if (libertas_activate_card(priv, libertas_fw_name))
224 goto err_activate_card;
226 list_add_tail(&cardp->list, &usb_devices);
229 usb_set_intfdata(intf, cardp);
234 libertas_remove_mesh(priv);
236 free_netdev(priv->dev);
237 kfree(priv->adapter);
246 * @brief free resource and cleanup
247 * @param intf USB interface structure
250 static void if_usb_disconnect(struct usb_interface *intf)
252 struct usb_card_rec *cardp = usb_get_intfdata(intf);
253 wlan_private *priv = (wlan_private *) cardp->priv;
254 wlan_adapter *adapter = NULL;
256 adapter = priv->adapter;
259 * Update Surprise removed to TRUE
261 adapter->surpriseremoved = 1;
263 list_del(&cardp->list);
265 /* card is removed and we can call wlan_remove_card */
266 lbs_deb_usbd(&cardp->udev->dev, "call remove card\n");
267 libertas_remove_mesh(priv);
268 libertas_remove_card(priv);
270 /* Unlink and free urb */
273 usb_set_intfdata(intf, NULL);
274 usb_put_dev(interface_to_usbdev(intf));
280 * @brief This function download FW
281 * @param priv pointer to wlan_private
284 static int if_prog_firmware(wlan_private * priv)
286 struct usb_card_rec *cardp = priv->card;
287 struct FWData *fwdata;
288 struct fwheader *fwheader;
289 u8 *firmware = priv->firmware->data;
291 fwdata = kmalloc(sizeof(struct FWData), GFP_ATOMIC);
296 fwheader = &fwdata->fwheader;
298 if (!cardp->CRC_OK) {
299 cardp->totalbytes = cardp->fwlastblksent;
300 cardp->fwseqnum = cardp->lastseqnum - 1;
304 lbs_deb_usbd(&cardp->udev->dev, "totalbytes = %d\n",
308 memcpy(fwheader, &firmware[cardp->totalbytes],
309 sizeof(struct fwheader));
311 cardp->fwlastblksent = cardp->totalbytes;
312 cardp->totalbytes += sizeof(struct fwheader);
314 /* lbs_deb_usbd(&cardp->udev->dev,"Copy Data\n"); */
315 memcpy(fwdata->data, &firmware[cardp->totalbytes],
316 fwdata->fwheader.datalength);
319 lbs_deb_usbd(&cardp->udev->dev,
320 "Data length = %d\n", fwdata->fwheader.datalength);
323 cardp->fwseqnum = cardp->fwseqnum + 1;
325 fwdata->seqnum = cardp->fwseqnum;
326 cardp->lastseqnum = fwdata->seqnum;
327 cardp->totalbytes += fwdata->fwheader.datalength;
329 if (fwheader->dnldcmd == FW_HAS_DATA_TO_RECV) {
331 lbs_deb_usbd(&cardp->udev->dev, "There is data to follow\n");
332 lbs_deb_usbd(&cardp->udev->dev,
333 "seqnum = %d totalbytes = %d\n", cardp->fwseqnum,
336 memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
337 usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
339 } else if (fwdata->fwheader.dnldcmd == FW_HAS_LAST_BLOCK) {
341 lbs_deb_usbd(&cardp->udev->dev,
342 "Host has finished FW downloading\n");
343 lbs_deb_usbd(&cardp->udev->dev,
344 "Donwloading FW JUMP BLOCK\n");
346 memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
347 usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
348 cardp->fwfinalblk = 1;
352 lbs_deb_usbd(&cardp->udev->dev,
353 "The firmware download is done size is %d\n",
362 static int libertas_do_reset(wlan_private *priv)
365 struct usb_card_rec *cardp = priv->card;
367 lbs_deb_enter(LBS_DEB_USB);
369 ret = usb_reset_device(cardp->udev);
372 if_usb_reset_device(priv);
376 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
382 * @brief This function transfer the data to the device.
383 * @param priv pointer to wlan_private
384 * @param payload pointer to payload data
385 * @param nb data length
388 int usb_tx_block(wlan_private * priv, u8 * payload, u16 nb)
390 /* pointer to card structure */
391 struct usb_card_rec *cardp = priv->card;
394 /* check if device is removed */
395 if (priv->adapter->surpriseremoved) {
396 lbs_deb_usbd(&cardp->udev->dev, "Device removed\n");
400 usb_fill_bulk_urb(cardp->tx_urb, cardp->udev,
401 usb_sndbulkpipe(cardp->udev,
402 cardp->bulk_out_endpointAddr),
403 payload, nb, if_usb_write_bulk_callback, priv);
405 cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET;
407 if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
408 /* transfer failed */
409 lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed\n");
412 /* lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb success\n"); */
420 static int __if_usb_submit_rx_urb(wlan_private * priv,
424 struct usb_card_rec *cardp = priv->card;
426 struct read_cb_info *rinfo = &cardp->rinfo;
429 if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
430 lbs_pr_err("No free skb\n");
436 /* Fill the receive configuration URB and initialise the Rx call back */
437 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
438 usb_rcvbulkpipe(cardp->udev,
439 cardp->bulk_in_endpointAddr),
440 (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET),
441 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn,
444 cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
446 /* lbs_deb_usbd(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb); */
447 if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) {
448 /* handle failure conditions */
449 lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed\n");
452 /* lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB success\n"); */
460 static inline int if_usb_submit_rx_urb_fwload(wlan_private * priv)
462 return __if_usb_submit_rx_urb(priv, &if_usb_receive_fwload);
465 static inline int if_usb_submit_rx_urb(wlan_private * priv)
467 return __if_usb_submit_rx_urb(priv, &if_usb_receive);
470 static void if_usb_receive_fwload(struct urb *urb)
472 struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
473 wlan_private *priv = rinfo->priv;
474 struct sk_buff *skb = rinfo->skb;
475 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
476 struct fwsyncheader *syncfwheader;
477 struct bootcmdrespStr bootcmdresp;
480 lbs_deb_usbd(&cardp->udev->dev,
481 "URB status is failed during fw load\n");
486 if (cardp->bootcmdresp == 0) {
487 memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET,
488 sizeof(bootcmdresp));
489 if (cardp->udev->descriptor.bcdDevice < 0x3106) {
491 if_usb_submit_rx_urb_fwload(priv);
492 cardp->bootcmdresp = 1;
493 lbs_deb_usbd(&cardp->udev->dev,
494 "Received valid boot command response\n");
497 if (bootcmdresp.u32magicnumber != BOOT_CMD_MAGIC_NUMBER) {
499 "boot cmd response wrong magic number (0x%x)\n",
500 bootcmdresp.u32magicnumber);
501 } else if (bootcmdresp.u8cmd_tag != BOOT_CMD_FW_BY_USB) {
503 "boot cmd response cmd_tag error (%d)\n",
504 bootcmdresp.u8cmd_tag);
505 } else if (bootcmdresp.u8result != BOOT_CMD_RESP_OK) {
507 "boot cmd response result error (%d)\n",
508 bootcmdresp.u8result);
510 cardp->bootcmdresp = 1;
511 lbs_deb_usbd(&cardp->udev->dev,
512 "Received valid boot command response\n");
515 if_usb_submit_rx_urb_fwload(priv);
519 syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
521 lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
526 memcpy(syncfwheader, skb->data + IPFIELD_ALIGN_OFFSET,
527 sizeof(struct fwsyncheader));
529 if (!syncfwheader->cmd) {
531 lbs_deb_usbd(&cardp->udev->dev,
532 "FW received Blk with correct CRC\n");
533 lbs_deb_usbd(&cardp->udev->dev,
534 "FW received Blk seqnum = %d\n",
535 syncfwheader->seqnum);
539 lbs_deb_usbd(&cardp->udev->dev,
540 "FW received Blk with CRC error\n");
546 if (cardp->fwfinalblk) {
547 cardp->fwdnldover = 1;
551 if_prog_firmware(priv);
553 if_usb_submit_rx_urb_fwload(priv);
561 #define MRVDRV_MIN_PKT_LEN 30
563 static inline void process_cmdtypedata(int recvlength, struct sk_buff *skb,
564 struct usb_card_rec *cardp,
567 if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE +
568 MESSAGE_HEADER_LEN || recvlength < MRVDRV_MIN_PKT_LEN) {
569 lbs_deb_usbd(&cardp->udev->dev,
570 "Packet length is Invalid\n");
575 skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
576 skb_put(skb, recvlength);
577 skb_pull(skb, MESSAGE_HEADER_LEN);
578 libertas_process_rxed_packet(priv, skb);
579 priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
582 static inline void process_cmdrequest(int recvlength, u8 *recvbuff,
584 struct usb_card_rec *cardp,
588 if (recvlength > MRVDRV_SIZE_OF_CMD_BUFFER) {
589 lbs_deb_usbd(&cardp->udev->dev,
590 "The receive buffer is too large\n");
598 spin_lock(&priv->adapter->driver_lock);
599 /* take care of cur_cmd = NULL case by reading the
600 * data to clear the interrupt */
601 if (!priv->adapter->cur_cmd) {
602 cmdbuf = priv->upld_buf;
603 priv->adapter->hisregcpy &= ~his_cmdupldrdy;
605 cmdbuf = priv->adapter->cur_cmd->bufvirtualaddr;
607 cardp->usb_int_cause |= his_cmdupldrdy;
608 priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
609 memcpy(cmdbuf, recvbuff + MESSAGE_HEADER_LEN,
613 libertas_interrupt(priv->dev);
614 spin_unlock(&priv->adapter->driver_lock);
616 lbs_deb_usbd(&cardp->udev->dev,
617 "Wake up main thread to handle cmd response\n");
623 * @brief This function reads of the packet into the upload buff,
624 * wake up the main thread and initialise the Rx callack.
626 * @param urb pointer to struct urb
629 static void if_usb_receive(struct urb *urb)
631 struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
632 wlan_private *priv = rinfo->priv;
633 struct sk_buff *skb = rinfo->skb;
634 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
636 int recvlength = urb->actual_length;
640 lbs_deb_enter(LBS_DEB_USB);
644 lbs_deb_usbd(&cardp->udev->dev,
645 "URB status is failed\n");
650 recvbuff = skb->data + IPFIELD_ALIGN_OFFSET;
651 memcpy(&recvtype, recvbuff, sizeof(u32));
652 lbs_deb_usbd(&cardp->udev->dev,
653 "Recv length = 0x%x\n", recvlength);
654 lbs_deb_usbd(&cardp->udev->dev,
655 "Receive type = 0x%X\n", recvtype);
656 recvtype = le32_to_cpu(recvtype);
657 lbs_deb_usbd(&cardp->udev->dev,
658 "Receive type after = 0x%X\n", recvtype);
659 } else if (urb->status)
665 process_cmdtypedata(recvlength, skb, cardp, priv);
668 case CMD_TYPE_REQUEST:
669 process_cmdrequest(recvlength, recvbuff, skb, cardp, priv);
672 case CMD_TYPE_INDICATION:
673 /* Event cause handling */
674 spin_lock(&priv->adapter->driver_lock);
675 cardp->usb_event_cause = *(u32 *) (recvbuff + MESSAGE_HEADER_LEN);
676 lbs_deb_usbd(&cardp->udev->dev,"**EVENT** 0x%X\n",
677 cardp->usb_event_cause);
678 if (cardp->usb_event_cause & 0xffff0000) {
679 libertas_send_tx_feedback(priv);
680 spin_unlock(&priv->adapter->driver_lock);
683 cardp->usb_event_cause = le32_to_cpu(cardp->usb_event_cause) << 3;
684 cardp->usb_int_cause |= his_cardevent;
686 libertas_interrupt(priv->dev);
687 spin_unlock(&priv->adapter->driver_lock);
695 if_usb_submit_rx_urb(priv);
697 lbs_deb_leave(LBS_DEB_USB);
701 * @brief This function downloads data to FW
702 * @param priv pointer to wlan_private structure
703 * @param type type of data
704 * @param buf pointer to data buffer
705 * @param len number of bytes
708 static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb)
712 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
714 lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type);
715 lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb);
717 if (type == MVMS_CMD) {
718 tmp = cpu_to_le32(CMD_TYPE_REQUEST);
719 priv->dnld_sent = DNLD_CMD_SENT;
720 memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
724 tmp = cpu_to_le32(CMD_TYPE_DATA);
725 priv->dnld_sent = DNLD_DATA_SENT;
726 memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
730 memcpy((cardp->bulk_out_buffer + MESSAGE_HEADER_LEN), payload, nb);
733 usb_tx_block(priv, cardp->bulk_out_buffer, nb + MESSAGE_HEADER_LEN);
738 /* called with adapter->driver_lock held */
739 static int if_usb_get_int_status(wlan_private * priv, u8 * ireg)
741 struct usb_card_rec *cardp = priv->card;
743 *ireg = cardp->usb_int_cause;
744 cardp->usb_int_cause = 0;
746 lbs_deb_usbd(&cardp->udev->dev,"Int cause is 0x%X\n", *ireg);
751 static int if_usb_read_event_cause(wlan_private * priv)
753 struct usb_card_rec *cardp = priv->card;
754 priv->adapter->eventcause = cardp->usb_event_cause;
755 /* Re-submit rx urb here to avoid event lost issue */
756 if_usb_submit_rx_urb(priv);
760 static int if_usb_reset_device(wlan_private *priv)
764 lbs_deb_enter(LBS_DEB_USB);
765 ret = libertas_prepare_and_send_command(priv, cmd_802_11_reset,
766 cmd_act_halt, 0, 0, NULL);
767 msleep_interruptible(10);
769 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
773 static int if_usb_unregister_dev(wlan_private * priv)
777 /* Need to send a Reset command to device before USB resources freed
778 * and wlan_remove_card() called, then device can handle FW download
782 if_usb_reset_device(priv);
789 * @brief This function register usb device and initialize parameter
790 * @param priv pointer to wlan_private
793 static int if_usb_register_dev(wlan_private * priv)
795 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
797 lbs_deb_enter(LBS_DEB_USB);
800 cardp->eth_dev = priv->dev;
801 priv->hotplug_device = &(cardp->udev->dev);
803 lbs_deb_usbd(&cardp->udev->dev, "udev pointer is at %p\n",
806 lbs_deb_leave(LBS_DEB_USB);
812 static int if_usb_prog_firmware(wlan_private * priv)
814 struct usb_card_rec *cardp = priv->card;
816 static int reset_count = 10;
819 lbs_deb_enter(LBS_DEB_USB);
821 cardp->rinfo.priv = priv;
824 if (if_usb_submit_rx_urb_fwload(priv) < 0) {
825 lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n");
830 cardp->bootcmdresp = 0;
834 /* Issue Boot command = 1, Boot from Download-FW */
835 if_usb_issue_boot_command(priv, BOOT_CMD_FW_BY_USB);
836 /* wait for command response */
839 msleep_interruptible(100);
840 } while (cardp->bootcmdresp == 0 && j < 10);
841 } while (cardp->bootcmdresp == 0 && i < 5);
843 if (cardp->bootcmdresp == 0) {
844 if (--reset_count >= 0) {
845 libertas_do_reset(priv);
852 priv->adapter->fw_ready = 0;
854 cardp->totalbytes = 0;
855 cardp->fwlastblksent = 0;
857 cardp->fwdnldover = 0;
858 cardp->fwseqnum = -1;
859 cardp->totalbytes = 0;
860 cardp->fwfinalblk = 0;
862 if_prog_firmware(priv);
865 lbs_deb_usbd(&cardp->udev->dev,"Wlan sched timeout\n");
867 msleep_interruptible(100);
868 if (priv->adapter->surpriseremoved || i >= 20)
870 } while (!cardp->fwdnldover);
872 if (!cardp->fwdnldover) {
873 lbs_pr_info("failed to load fw, resetting device!\n");
874 if (--reset_count >= 0) {
875 libertas_do_reset(priv);
879 lbs_pr_info("FW download failure, time = %d ms\n", i * 100);
884 if_usb_submit_rx_urb(priv);
886 /* Delay 200 ms to waiting for the FW ready */
887 msleep_interruptible(200);
889 priv->adapter->fw_ready = 1;
892 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
897 static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
899 struct usb_card_rec *cardp = usb_get_intfdata(intf);
900 wlan_private *priv = cardp->priv;
902 lbs_deb_enter(LBS_DEB_USB);
904 if (priv->adapter->psstate != PS_STATE_FULL_POWER)
907 netif_device_detach(cardp->eth_dev);
908 netif_device_detach(priv->mesh_dev);
910 /* Unlink tx & rx urb */
911 usb_kill_urb(cardp->tx_urb);
912 usb_kill_urb(cardp->rx_urb);
914 cardp->rx_urb_recall = 1;
916 lbs_deb_leave(LBS_DEB_USB);
920 static int if_usb_resume(struct usb_interface *intf)
922 struct usb_card_rec *cardp = usb_get_intfdata(intf);
923 wlan_private *priv = cardp->priv;
925 lbs_deb_enter(LBS_DEB_USB);
927 cardp->rx_urb_recall = 0;
929 if_usb_submit_rx_urb(cardp->priv);
931 netif_device_attach(cardp->eth_dev);
932 netif_device_attach(priv->mesh_dev);
934 lbs_deb_leave(LBS_DEB_USB);
938 #define if_usb_suspend NULL
939 #define if_usb_resume NULL
942 static struct usb_driver if_usb_driver = {
944 .name = usbdriver_name,
945 /* probe function name */
946 .probe = if_usb_probe,
947 /* disconnect function name */
948 .disconnect = if_usb_disconnect,
949 /* device signature table */
950 .id_table = if_usb_table,
951 .suspend = if_usb_suspend,
952 .resume = if_usb_resume,
955 static int if_usb_init_module(void)
959 lbs_deb_enter(LBS_DEB_MAIN);
961 if (libertas_fw_name == NULL) {
962 libertas_fw_name = default_fw_name;
965 ret = usb_register(&if_usb_driver);
967 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
971 static void if_usb_exit_module(void)
973 struct usb_card_rec *cardp, *cardp_temp;
975 lbs_deb_enter(LBS_DEB_MAIN);
977 list_for_each_entry_safe(cardp, cardp_temp, &usb_devices, list)
978 if_usb_reset_device((wlan_private *) cardp->priv);
980 /* API unregisters the driver from USB subsystem */
981 usb_deregister(&if_usb_driver);
983 lbs_deb_leave(LBS_DEB_MAIN);
986 module_init(if_usb_init_module);
987 module_exit(if_usb_exit_module);
989 MODULE_DESCRIPTION("8388 USB WLAN Driver");
990 MODULE_AUTHOR("Marvell International Ltd.");
991 MODULE_LICENSE("GPL");