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 le16_to_cpu(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 le16_to_cpu(endpoint->wMaxPacketSize));
157 if (!(cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
158 lbs_deb_usbd(&udev->dev,
159 "Rx URB allocation failed\n");
162 cardp->rx_urb_recall = 0;
164 cardp->bulk_in_size =
165 le16_to_cpu(endpoint->wMaxPacketSize);
166 cardp->bulk_in_endpointAddr =
168 bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
169 lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n",
170 endpoint->bEndpointAddress);
174 bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
176 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
177 USB_ENDPOINT_XFER_BULK)) {
178 /* We found bulk out endpoint */
179 if (!(cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
180 lbs_deb_usbd(&udev->dev,
181 "Tx URB allocation failed\n");
185 cardp->bulk_out_size =
186 le16_to_cpu(endpoint->wMaxPacketSize);
187 lbs_deb_usbd(&udev->dev,
188 "Bulk out size is %d\n",
189 le16_to_cpu(endpoint->wMaxPacketSize));
190 cardp->bulk_out_endpointAddr =
191 endpoint->bEndpointAddress;
192 lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n",
193 endpoint->bEndpointAddress);
194 cardp->bulk_out_buffer =
195 kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE,
198 if (!cardp->bulk_out_buffer) {
199 lbs_deb_usbd(&udev->dev,
200 "Could not allocate buffer\n");
206 if (!(priv = libertas_add_card(cardp, &udev->dev)))
209 if (libertas_add_mesh(priv, &udev->dev))
212 priv->hw_register_dev = if_usb_register_dev;
213 priv->hw_unregister_dev = if_usb_unregister_dev;
214 priv->hw_prog_firmware = if_usb_prog_firmware;
215 priv->hw_host_to_card = if_usb_host_to_card;
216 priv->hw_get_int_status = if_usb_get_int_status;
217 priv->hw_read_event_cause = if_usb_read_event_cause;
219 if (libertas_activate_card(priv, libertas_fw_name))
220 goto err_activate_card;
222 list_add_tail(&cardp->list, &usb_devices);
225 usb_set_intfdata(intf, cardp);
230 libertas_remove_mesh(priv);
232 free_netdev(priv->dev);
233 kfree(priv->adapter);
242 * @brief free resource and cleanup
243 * @param intf USB interface structure
246 static void if_usb_disconnect(struct usb_interface *intf)
248 struct usb_card_rec *cardp = usb_get_intfdata(intf);
249 wlan_private *priv = (wlan_private *) cardp->priv;
250 wlan_adapter *adapter = NULL;
252 adapter = priv->adapter;
255 * Update Surprise removed to TRUE
257 adapter->surpriseremoved = 1;
259 list_del(&cardp->list);
261 /* card is removed and we can call wlan_remove_card */
262 lbs_deb_usbd(&cardp->udev->dev, "call remove card\n");
263 libertas_remove_mesh(priv);
264 libertas_remove_card(priv);
266 /* Unlink and free urb */
269 usb_set_intfdata(intf, NULL);
270 usb_put_dev(interface_to_usbdev(intf));
276 * @brief This function download FW
277 * @param priv pointer to wlan_private
280 static int if_prog_firmware(wlan_private * priv)
282 struct usb_card_rec *cardp = priv->card;
283 struct FWData *fwdata;
284 struct fwheader *fwheader;
285 u8 *firmware = priv->firmware->data;
287 fwdata = kmalloc(sizeof(struct FWData), GFP_ATOMIC);
292 fwheader = &fwdata->fwheader;
294 if (!cardp->CRC_OK) {
295 cardp->totalbytes = cardp->fwlastblksent;
296 cardp->fwseqnum = cardp->lastseqnum - 1;
300 lbs_deb_usbd(&cardp->udev->dev, "totalbytes = %d\n",
304 memcpy(fwheader, &firmware[cardp->totalbytes],
305 sizeof(struct fwheader));
307 cardp->fwlastblksent = cardp->totalbytes;
308 cardp->totalbytes += sizeof(struct fwheader);
310 /* lbs_deb_usbd(&cardp->udev->dev,"Copy Data\n"); */
311 memcpy(fwdata->data, &firmware[cardp->totalbytes],
312 le32_to_cpu(fwdata->fwheader.datalength));
315 lbs_deb_usbd(&cardp->udev->dev,
316 "Data length = %d\n", le32_to_cpu(fwdata->fwheader.datalength));
319 cardp->fwseqnum = cardp->fwseqnum + 1;
321 fwdata->seqnum = cpu_to_le32(cardp->fwseqnum);
322 cardp->lastseqnum = cardp->fwseqnum;
323 cardp->totalbytes += le32_to_cpu(fwdata->fwheader.datalength);
325 if (fwheader->dnldcmd == cpu_to_le32(FW_HAS_DATA_TO_RECV)) {
327 lbs_deb_usbd(&cardp->udev->dev, "There are data to follow\n");
328 lbs_deb_usbd(&cardp->udev->dev,
329 "seqnum = %d totalbytes = %d\n", cardp->fwseqnum,
332 memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
333 usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
335 } else if (fwdata->fwheader.dnldcmd == cpu_to_le32(FW_HAS_LAST_BLOCK)) {
337 lbs_deb_usbd(&cardp->udev->dev,
338 "Host has finished FW downloading\n");
339 lbs_deb_usbd(&cardp->udev->dev,
340 "Donwloading FW JUMP BLOCK\n");
342 memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
343 usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
344 cardp->fwfinalblk = 1;
348 lbs_deb_usbd(&cardp->udev->dev,
349 "The firmware download is done size is %d\n",
358 static int libertas_do_reset(wlan_private *priv)
361 struct usb_card_rec *cardp = priv->card;
363 lbs_deb_enter(LBS_DEB_USB);
365 ret = usb_reset_device(cardp->udev);
368 if_usb_reset_device(priv);
372 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
378 * @brief This function transfer the data to the device.
379 * @param priv pointer to wlan_private
380 * @param payload pointer to payload data
381 * @param nb data length
384 int usb_tx_block(wlan_private * priv, u8 * payload, u16 nb)
386 /* pointer to card structure */
387 struct usb_card_rec *cardp = priv->card;
390 /* check if device is removed */
391 if (priv->adapter->surpriseremoved) {
392 lbs_deb_usbd(&cardp->udev->dev, "Device removed\n");
396 usb_fill_bulk_urb(cardp->tx_urb, cardp->udev,
397 usb_sndbulkpipe(cardp->udev,
398 cardp->bulk_out_endpointAddr),
399 payload, nb, if_usb_write_bulk_callback, priv);
401 cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET;
403 if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
404 /* transfer failed */
405 lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed\n");
408 /* lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb success\n"); */
416 static int __if_usb_submit_rx_urb(wlan_private * priv,
420 struct usb_card_rec *cardp = priv->card;
422 struct read_cb_info *rinfo = &cardp->rinfo;
425 if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
426 lbs_pr_err("No free skb\n");
432 /* Fill the receive configuration URB and initialise the Rx call back */
433 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
434 usb_rcvbulkpipe(cardp->udev,
435 cardp->bulk_in_endpointAddr),
436 (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET),
437 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn,
440 cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
442 /* lbs_deb_usbd(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb); */
443 if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) {
444 /* handle failure conditions */
445 lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed\n");
448 /* lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB success\n"); */
456 static inline int if_usb_submit_rx_urb_fwload(wlan_private * priv)
458 return __if_usb_submit_rx_urb(priv, &if_usb_receive_fwload);
461 static inline int if_usb_submit_rx_urb(wlan_private * priv)
463 return __if_usb_submit_rx_urb(priv, &if_usb_receive);
466 static void if_usb_receive_fwload(struct urb *urb)
468 struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
469 wlan_private *priv = rinfo->priv;
470 struct sk_buff *skb = rinfo->skb;
471 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
472 struct fwsyncheader *syncfwheader;
473 struct bootcmdrespStr bootcmdresp;
476 lbs_deb_usbd(&cardp->udev->dev,
477 "URB status is failed during fw load\n");
482 if (cardp->bootcmdresp == 0) {
483 memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET,
484 sizeof(bootcmdresp));
485 if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) {
487 if_usb_submit_rx_urb_fwload(priv);
488 cardp->bootcmdresp = 1;
489 lbs_deb_usbd(&cardp->udev->dev,
490 "Received valid boot command response\n");
493 if (bootcmdresp.u32magicnumber != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) {
495 "boot cmd response wrong magic number (0x%x)\n",
496 le32_to_cpu(bootcmdresp.u32magicnumber));
497 } else if (bootcmdresp.u8cmd_tag != BOOT_CMD_FW_BY_USB) {
499 "boot cmd response cmd_tag error (%d)\n",
500 bootcmdresp.u8cmd_tag);
501 } else if (bootcmdresp.u8result != BOOT_CMD_RESP_OK) {
503 "boot cmd response result error (%d)\n",
504 bootcmdresp.u8result);
506 cardp->bootcmdresp = 1;
507 lbs_deb_usbd(&cardp->udev->dev,
508 "Received valid boot command response\n");
511 if_usb_submit_rx_urb_fwload(priv);
515 syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
517 lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
522 memcpy(syncfwheader, skb->data + IPFIELD_ALIGN_OFFSET,
523 sizeof(struct fwsyncheader));
525 if (!syncfwheader->cmd) {
527 lbs_deb_usbd(&cardp->udev->dev,
528 "FW received Blk with correct CRC\n");
529 lbs_deb_usbd(&cardp->udev->dev,
530 "FW received Blk seqnum = %d\n",
531 syncfwheader->seqnum);
535 lbs_deb_usbd(&cardp->udev->dev,
536 "FW received Blk with CRC error\n");
542 if (cardp->fwfinalblk) {
543 cardp->fwdnldover = 1;
547 if_prog_firmware(priv);
549 if_usb_submit_rx_urb_fwload(priv);
557 #define MRVDRV_MIN_PKT_LEN 30
559 static inline void process_cmdtypedata(int recvlength, struct sk_buff *skb,
560 struct usb_card_rec *cardp,
563 if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE +
564 MESSAGE_HEADER_LEN || recvlength < MRVDRV_MIN_PKT_LEN) {
565 lbs_deb_usbd(&cardp->udev->dev,
566 "Packet length is Invalid\n");
571 skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
572 skb_put(skb, recvlength);
573 skb_pull(skb, MESSAGE_HEADER_LEN);
574 libertas_process_rxed_packet(priv, skb);
575 priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
578 static inline void process_cmdrequest(int recvlength, u8 *recvbuff,
580 struct usb_card_rec *cardp,
584 if (recvlength > MRVDRV_SIZE_OF_CMD_BUFFER) {
585 lbs_deb_usbd(&cardp->udev->dev,
586 "The receive buffer is too large\n");
594 spin_lock(&priv->adapter->driver_lock);
595 /* take care of cur_cmd = NULL case by reading the
596 * data to clear the interrupt */
597 if (!priv->adapter->cur_cmd) {
598 cmdbuf = priv->upld_buf;
599 priv->adapter->hisregcpy &= ~his_cmdupldrdy;
601 cmdbuf = priv->adapter->cur_cmd->bufvirtualaddr;
603 cardp->usb_int_cause |= his_cmdupldrdy;
604 priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
605 memcpy(cmdbuf, recvbuff + MESSAGE_HEADER_LEN,
609 libertas_interrupt(priv->dev);
610 spin_unlock(&priv->adapter->driver_lock);
612 lbs_deb_usbd(&cardp->udev->dev,
613 "Wake up main thread to handle cmd response\n");
619 * @brief This function reads of the packet into the upload buff,
620 * wake up the main thread and initialise the Rx callack.
622 * @param urb pointer to struct urb
625 static void if_usb_receive(struct urb *urb)
627 struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
628 wlan_private *priv = rinfo->priv;
629 struct sk_buff *skb = rinfo->skb;
630 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
632 int recvlength = urb->actual_length;
636 lbs_deb_enter(LBS_DEB_USB);
640 lbs_deb_usbd(&cardp->udev->dev,
641 "URB status is failed\n");
646 recvbuff = skb->data + IPFIELD_ALIGN_OFFSET;
647 memcpy(&recvtype, recvbuff, sizeof(u32));
648 lbs_deb_usbd(&cardp->udev->dev,
649 "Recv length = 0x%x\n", recvlength);
650 lbs_deb_usbd(&cardp->udev->dev,
651 "Receive type = 0x%X\n", recvtype);
652 recvtype = le32_to_cpu(recvtype);
653 lbs_deb_usbd(&cardp->udev->dev,
654 "Receive type after = 0x%X\n", recvtype);
655 } else if (urb->status)
661 process_cmdtypedata(recvlength, skb, cardp, priv);
664 case CMD_TYPE_REQUEST:
665 process_cmdrequest(recvlength, recvbuff, skb, cardp, priv);
668 case CMD_TYPE_INDICATION:
669 /* Event cause handling */
670 spin_lock(&priv->adapter->driver_lock);
671 cardp->usb_event_cause = le32_to_cpu(*(__le32 *) (recvbuff + MESSAGE_HEADER_LEN));
672 lbs_deb_usbd(&cardp->udev->dev,"**EVENT** 0x%X\n",
673 cardp->usb_event_cause);
674 if (cardp->usb_event_cause & 0xffff0000) {
675 libertas_send_tx_feedback(priv);
676 spin_unlock(&priv->adapter->driver_lock);
679 cardp->usb_event_cause <<= 3;
680 cardp->usb_int_cause |= his_cardevent;
682 libertas_interrupt(priv->dev);
683 spin_unlock(&priv->adapter->driver_lock);
691 if_usb_submit_rx_urb(priv);
693 lbs_deb_leave(LBS_DEB_USB);
697 * @brief This function downloads data to FW
698 * @param priv pointer to wlan_private structure
699 * @param type type of data
700 * @param buf pointer to data buffer
701 * @param len number of bytes
704 static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb)
708 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
710 lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type);
711 lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb);
713 if (type == MVMS_CMD) {
714 tmp = cpu_to_le32(CMD_TYPE_REQUEST);
715 priv->dnld_sent = DNLD_CMD_SENT;
716 memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
720 tmp = cpu_to_le32(CMD_TYPE_DATA);
721 priv->dnld_sent = DNLD_DATA_SENT;
722 memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
726 memcpy((cardp->bulk_out_buffer + MESSAGE_HEADER_LEN), payload, nb);
729 usb_tx_block(priv, cardp->bulk_out_buffer, nb + MESSAGE_HEADER_LEN);
734 /* called with adapter->driver_lock held */
735 static int if_usb_get_int_status(wlan_private * priv, u8 * ireg)
737 struct usb_card_rec *cardp = priv->card;
739 *ireg = cardp->usb_int_cause;
740 cardp->usb_int_cause = 0;
742 lbs_deb_usbd(&cardp->udev->dev,"Int cause is 0x%X\n", *ireg);
747 static int if_usb_read_event_cause(wlan_private * priv)
749 struct usb_card_rec *cardp = priv->card;
750 priv->adapter->eventcause = cardp->usb_event_cause;
751 /* Re-submit rx urb here to avoid event lost issue */
752 if_usb_submit_rx_urb(priv);
756 static int if_usb_reset_device(wlan_private *priv)
760 lbs_deb_enter(LBS_DEB_USB);
761 ret = libertas_prepare_and_send_command(priv, cmd_802_11_reset,
762 cmd_act_halt, 0, 0, NULL);
763 msleep_interruptible(10);
765 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
769 static int if_usb_unregister_dev(wlan_private * priv)
773 /* Need to send a Reset command to device before USB resources freed
774 * and wlan_remove_card() called, then device can handle FW download
778 if_usb_reset_device(priv);
785 * @brief This function register usb device and initialize parameter
786 * @param priv pointer to wlan_private
789 static int if_usb_register_dev(wlan_private * priv)
791 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
793 lbs_deb_enter(LBS_DEB_USB);
796 cardp->eth_dev = priv->dev;
797 priv->hotplug_device = &(cardp->udev->dev);
799 lbs_deb_usbd(&cardp->udev->dev, "udev pointer is at %p\n",
802 lbs_deb_leave(LBS_DEB_USB);
808 static int if_usb_prog_firmware(wlan_private * priv)
810 struct usb_card_rec *cardp = priv->card;
812 static int reset_count = 10;
815 lbs_deb_enter(LBS_DEB_USB);
817 cardp->rinfo.priv = priv;
820 if (if_usb_submit_rx_urb_fwload(priv) < 0) {
821 lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n");
826 cardp->bootcmdresp = 0;
830 /* Issue Boot command = 1, Boot from Download-FW */
831 if_usb_issue_boot_command(priv, BOOT_CMD_FW_BY_USB);
832 /* wait for command response */
835 msleep_interruptible(100);
836 } while (cardp->bootcmdresp == 0 && j < 10);
837 } while (cardp->bootcmdresp == 0 && i < 5);
839 if (cardp->bootcmdresp == 0) {
840 if (--reset_count >= 0) {
841 libertas_do_reset(priv);
848 priv->adapter->fw_ready = 0;
850 cardp->totalbytes = 0;
851 cardp->fwlastblksent = 0;
853 cardp->fwdnldover = 0;
854 cardp->fwseqnum = -1;
855 cardp->totalbytes = 0;
856 cardp->fwfinalblk = 0;
858 if_prog_firmware(priv);
861 lbs_deb_usbd(&cardp->udev->dev,"Wlan sched timeout\n");
863 msleep_interruptible(100);
864 if (priv->adapter->surpriseremoved || i >= 20)
866 } while (!cardp->fwdnldover);
868 if (!cardp->fwdnldover) {
869 lbs_pr_info("failed to load fw, resetting device!\n");
870 if (--reset_count >= 0) {
871 libertas_do_reset(priv);
875 lbs_pr_info("FW download failure, time = %d ms\n", i * 100);
880 if_usb_submit_rx_urb(priv);
882 /* Delay 200 ms to waiting for the FW ready */
883 msleep_interruptible(200);
885 priv->adapter->fw_ready = 1;
888 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
893 static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
895 struct usb_card_rec *cardp = usb_get_intfdata(intf);
896 wlan_private *priv = cardp->priv;
898 lbs_deb_enter(LBS_DEB_USB);
900 if (priv->adapter->psstate != PS_STATE_FULL_POWER)
903 netif_device_detach(cardp->eth_dev);
904 netif_device_detach(priv->mesh_dev);
906 /* Unlink tx & rx urb */
907 usb_kill_urb(cardp->tx_urb);
908 usb_kill_urb(cardp->rx_urb);
910 cardp->rx_urb_recall = 1;
912 lbs_deb_leave(LBS_DEB_USB);
916 static int if_usb_resume(struct usb_interface *intf)
918 struct usb_card_rec *cardp = usb_get_intfdata(intf);
919 wlan_private *priv = cardp->priv;
921 lbs_deb_enter(LBS_DEB_USB);
923 cardp->rx_urb_recall = 0;
925 if_usb_submit_rx_urb(cardp->priv);
927 netif_device_attach(cardp->eth_dev);
928 netif_device_attach(priv->mesh_dev);
930 lbs_deb_leave(LBS_DEB_USB);
934 #define if_usb_suspend NULL
935 #define if_usb_resume NULL
938 static struct usb_driver if_usb_driver = {
940 .name = usbdriver_name,
941 /* probe function name */
942 .probe = if_usb_probe,
943 /* disconnect function name */
944 .disconnect = if_usb_disconnect,
945 /* device signature table */
946 .id_table = if_usb_table,
947 .suspend = if_usb_suspend,
948 .resume = if_usb_resume,
951 static int if_usb_init_module(void)
955 lbs_deb_enter(LBS_DEB_MAIN);
957 if (libertas_fw_name == NULL) {
958 libertas_fw_name = default_fw_name;
961 ret = usb_register(&if_usb_driver);
963 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
967 static void if_usb_exit_module(void)
969 struct usb_card_rec *cardp, *cardp_temp;
971 lbs_deb_enter(LBS_DEB_MAIN);
973 list_for_each_entry_safe(cardp, cardp_temp, &usb_devices, list)
974 if_usb_reset_device((wlan_private *) cardp->priv);
976 /* API unregisters the driver from USB subsystem */
977 usb_deregister(&if_usb_driver);
979 lbs_deb_leave(LBS_DEB_MAIN);
982 module_init(if_usb_init_module);
983 module_exit(if_usb_exit_module);
985 MODULE_DESCRIPTION("8388 USB WLAN Driver");
986 MODULE_AUTHOR("Marvell International Ltd.");
987 MODULE_LICENSE("GPL");