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"
20 #define MESSAGE_HEADER_LEN 4
22 static const char usbdriver_name[] = "usb8xxx";
23 static u8 *default_fw_name = "usb8388.bin";
25 static char *libertas_fw_name = NULL;
26 module_param_named(fw_name, libertas_fw_name, charp, 0644);
29 * We need to send a RESET command to all USB devices before
30 * we tear down the USB connection. Otherwise we would not
31 * be able to re-init device the device if the module gets
32 * loaded again. This is a list of all initialized USB devices,
33 * for the reset code see if_usb_reset_device()
35 static LIST_HEAD(usb_devices);
37 static struct usb_device_id if_usb_table[] = {
38 /* Enter the device signature inside */
39 { USB_DEVICE(0x1286, 0x2001) },
40 { USB_DEVICE(0x05a3, 0x8388) },
41 {} /* Terminating entry */
44 MODULE_DEVICE_TABLE(usb, if_usb_table);
46 static void if_usb_receive(struct urb *urb);
47 static void if_usb_receive_fwload(struct urb *urb);
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 *);
54 static int usb_tx_block(wlan_private *priv, u8 *payload, u16 nb);
55 static void if_usb_free(struct usb_card_rec *cardp);
58 * @brief call back function to handle the status of the URB
59 * @param urb pointer to urb structure
62 static void if_usb_write_bulk_callback(struct urb *urb)
64 wlan_private *priv = (wlan_private *) (urb->context);
65 wlan_adapter *adapter = priv->adapter;
66 struct net_device *dev = priv->dev;
68 /* handle the transmission complete validations */
70 if (urb->status != 0) {
71 /* print the failure status number for debug */
72 lbs_pr_info("URB in failure status: %d\n", urb->status);
75 lbs_deb_usbd(&urb->dev->dev, "URB status is successfull\n");
76 lbs_deb_usbd(&urb->dev->dev, "Actual length transmitted %d\n",
79 priv->dnld_sent = DNLD_RES_RECEIVED;
80 /* Wake main thread if commands are pending */
81 if (!adapter->cur_cmd)
82 wake_up_interruptible(&priv->waitq);
83 if ((adapter->connect_status == LIBERTAS_CONNECTED)) {
84 netif_wake_queue(dev);
85 netif_wake_queue(priv->mesh_dev);
93 * @brief free tx/rx urb, skb and rx buffer
94 * @param cardp pointer usb_card_rec
97 static void if_usb_free(struct usb_card_rec *cardp)
99 lbs_deb_enter(LBS_DEB_USB);
101 /* Unlink tx & rx urb */
102 usb_kill_urb(cardp->tx_urb);
103 usb_kill_urb(cardp->rx_urb);
105 usb_free_urb(cardp->tx_urb);
106 cardp->tx_urb = NULL;
108 usb_free_urb(cardp->rx_urb);
109 cardp->rx_urb = NULL;
111 kfree(cardp->bulk_out_buffer);
112 cardp->bulk_out_buffer = NULL;
114 lbs_deb_leave(LBS_DEB_USB);
118 * @brief sets the configuration values
119 * @param ifnum interface number
120 * @param id pointer to usb_device_id
121 * @return 0 on success, error code on failure
123 static int if_usb_probe(struct usb_interface *intf,
124 const struct usb_device_id *id)
126 struct usb_device *udev;
127 struct usb_host_interface *iface_desc;
128 struct usb_endpoint_descriptor *endpoint;
130 struct usb_card_rec *cardp;
133 udev = interface_to_usbdev(intf);
135 cardp = kzalloc(sizeof(struct usb_card_rec), GFP_KERNEL);
137 lbs_pr_err("Out of memory allocating private data.\n");
142 iface_desc = intf->cur_altsetting;
144 lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X"
145 " bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n",
146 le16_to_cpu(udev->descriptor.bcdUSB),
147 udev->descriptor.bDeviceClass,
148 udev->descriptor.bDeviceSubClass,
149 udev->descriptor.bDeviceProtocol);
151 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
152 endpoint = &iface_desc->endpoint[i].desc;
153 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
154 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
155 USB_ENDPOINT_XFER_BULK)) {
156 /* we found a bulk in endpoint */
157 lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n",
158 le16_to_cpu(endpoint->wMaxPacketSize));
159 if (!(cardp->rx_urb = 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 le16_to_cpu(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 */
181 if (!(cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
182 lbs_deb_usbd(&udev->dev,
183 "Tx URB allocation failed\n");
187 cardp->bulk_out_size =
188 le16_to_cpu(endpoint->wMaxPacketSize);
189 lbs_deb_usbd(&udev->dev,
190 "Bulk out size is %d\n",
191 le16_to_cpu(endpoint->wMaxPacketSize));
192 cardp->bulk_out_endpointAddr =
193 endpoint->bEndpointAddress;
194 lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n",
195 endpoint->bEndpointAddress);
196 cardp->bulk_out_buffer =
197 kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE,
200 if (!cardp->bulk_out_buffer) {
201 lbs_deb_usbd(&udev->dev,
202 "Could not allocate buffer\n");
208 if (!(priv = libertas_add_card(cardp, &udev->dev)))
211 if (libertas_add_mesh(priv, &udev->dev))
214 priv->hw_register_dev = if_usb_register_dev;
215 priv->hw_unregister_dev = if_usb_unregister_dev;
216 priv->hw_prog_firmware = if_usb_prog_firmware;
217 priv->hw_host_to_card = if_usb_host_to_card;
218 priv->hw_get_int_status = if_usb_get_int_status;
219 priv->hw_read_event_cause = if_usb_read_event_cause;
221 if (libertas_activate_card(priv))
222 goto err_activate_card;
224 list_add_tail(&cardp->list, &usb_devices);
227 usb_set_intfdata(intf, cardp);
232 libertas_remove_mesh(priv);
234 free_netdev(priv->dev);
235 kfree(priv->adapter);
244 * @brief free resource and cleanup
245 * @param intf USB interface structure
248 static void if_usb_disconnect(struct usb_interface *intf)
250 struct usb_card_rec *cardp = usb_get_intfdata(intf);
251 wlan_private *priv = (wlan_private *) cardp->priv;
252 wlan_adapter *adapter = NULL;
254 adapter = priv->adapter;
257 * Update Surprise removed to TRUE
259 adapter->surpriseremoved = 1;
261 list_del(&cardp->list);
263 /* card is removed and we can call wlan_remove_card */
264 lbs_deb_usbd(&cardp->udev->dev, "call remove card\n");
265 libertas_remove_mesh(priv);
266 libertas_remove_card(priv);
268 /* Unlink and free urb */
271 usb_set_intfdata(intf, NULL);
272 usb_put_dev(interface_to_usbdev(intf));
278 * @brief This function download FW
279 * @param priv pointer to wlan_private
282 static int if_prog_firmware(wlan_private * priv)
284 struct usb_card_rec *cardp = priv->card;
285 struct FWData *fwdata;
286 struct fwheader *fwheader;
287 u8 *firmware = priv->firmware->data;
289 fwdata = kmalloc(sizeof(struct FWData), GFP_ATOMIC);
294 fwheader = &fwdata->fwheader;
296 if (!cardp->CRC_OK) {
297 cardp->totalbytes = cardp->fwlastblksent;
298 cardp->fwseqnum = cardp->lastseqnum - 1;
302 lbs_deb_usbd(&cardp->udev->dev, "totalbytes = %d\n",
306 memcpy(fwheader, &firmware[cardp->totalbytes],
307 sizeof(struct fwheader));
309 cardp->fwlastblksent = cardp->totalbytes;
310 cardp->totalbytes += sizeof(struct fwheader);
312 /* lbs_deb_usbd(&cardp->udev->dev,"Copy Data\n"); */
313 memcpy(fwdata->data, &firmware[cardp->totalbytes],
314 le32_to_cpu(fwdata->fwheader.datalength));
317 lbs_deb_usbd(&cardp->udev->dev,
318 "Data length = %d\n", le32_to_cpu(fwdata->fwheader.datalength));
321 cardp->fwseqnum = cardp->fwseqnum + 1;
323 fwdata->seqnum = cpu_to_le32(cardp->fwseqnum);
324 cardp->lastseqnum = cardp->fwseqnum;
325 cardp->totalbytes += le32_to_cpu(fwdata->fwheader.datalength);
327 if (fwheader->dnldcmd == cpu_to_le32(FW_HAS_DATA_TO_RECV)) {
329 lbs_deb_usbd(&cardp->udev->dev, "There are data to follow\n");
330 lbs_deb_usbd(&cardp->udev->dev,
331 "seqnum = %d totalbytes = %d\n", cardp->fwseqnum,
334 memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
335 usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
337 } else if (fwdata->fwheader.dnldcmd == cpu_to_le32(FW_HAS_LAST_BLOCK)) {
339 lbs_deb_usbd(&cardp->udev->dev,
340 "Host has finished FW downloading\n");
341 lbs_deb_usbd(&cardp->udev->dev,
342 "Donwloading FW JUMP BLOCK\n");
344 memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
345 usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
346 cardp->fwfinalblk = 1;
350 lbs_deb_usbd(&cardp->udev->dev,
351 "The firmware download is done size is %d\n",
360 static int if_usb_reset_device(wlan_private *priv)
363 struct usb_card_rec *cardp = priv->card;
365 lbs_deb_enter(LBS_DEB_USB);
367 /* Try a USB port reset first, if that fails send the reset
368 * command to the firmware.
370 ret = usb_reset_device(cardp->udev);
373 ret = libertas_reset_device(priv);
377 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
383 * @brief This function transfer the data to the device.
384 * @param priv pointer to wlan_private
385 * @param payload pointer to payload data
386 * @param nb data length
389 static int usb_tx_block(wlan_private * priv, u8 * payload, u16 nb)
391 /* pointer to card structure */
392 struct usb_card_rec *cardp = priv->card;
395 /* check if device is removed */
396 if (priv->adapter->surpriseremoved) {
397 lbs_deb_usbd(&cardp->udev->dev, "Device removed\n");
401 usb_fill_bulk_urb(cardp->tx_urb, cardp->udev,
402 usb_sndbulkpipe(cardp->udev,
403 cardp->bulk_out_endpointAddr),
404 payload, nb, if_usb_write_bulk_callback, priv);
406 cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET;
408 if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
409 /* transfer failed */
410 lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed\n");
413 /* lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb success\n"); */
421 static int __if_usb_submit_rx_urb(wlan_private * priv,
425 struct usb_card_rec *cardp = priv->card;
427 struct read_cb_info *rinfo = &cardp->rinfo;
430 if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
431 lbs_pr_err("No free skb\n");
437 /* Fill the receive configuration URB and initialise the Rx call back */
438 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
439 usb_rcvbulkpipe(cardp->udev,
440 cardp->bulk_in_endpointAddr),
441 (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET),
442 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn,
445 cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
447 /* lbs_deb_usbd(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb); */
448 if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) {
449 /* handle failure conditions */
450 lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed\n");
453 /* lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB success\n"); */
461 static inline int if_usb_submit_rx_urb_fwload(wlan_private * priv)
463 return __if_usb_submit_rx_urb(priv, &if_usb_receive_fwload);
466 static inline int if_usb_submit_rx_urb(wlan_private * priv)
468 return __if_usb_submit_rx_urb(priv, &if_usb_receive);
471 static void if_usb_receive_fwload(struct urb *urb)
473 struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
474 wlan_private *priv = rinfo->priv;
475 struct sk_buff *skb = rinfo->skb;
476 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
477 struct fwsyncheader *syncfwheader;
478 struct bootcmdrespStr bootcmdresp;
481 lbs_deb_usbd(&cardp->udev->dev,
482 "URB status is failed during fw load\n");
487 if (cardp->bootcmdresp == 0) {
488 memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET,
489 sizeof(bootcmdresp));
490 if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) {
492 if_usb_submit_rx_urb_fwload(priv);
493 cardp->bootcmdresp = 1;
494 lbs_deb_usbd(&cardp->udev->dev,
495 "Received valid boot command response\n");
498 if (bootcmdresp.u32magicnumber != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) {
500 "boot cmd response wrong magic number (0x%x)\n",
501 le32_to_cpu(bootcmdresp.u32magicnumber));
502 } else if (bootcmdresp.u8cmd_tag != BOOT_CMD_FW_BY_USB) {
504 "boot cmd response cmd_tag error (%d)\n",
505 bootcmdresp.u8cmd_tag);
506 } else if (bootcmdresp.u8result != BOOT_CMD_RESP_OK) {
508 "boot cmd response result error (%d)\n",
509 bootcmdresp.u8result);
511 cardp->bootcmdresp = 1;
512 lbs_deb_usbd(&cardp->udev->dev,
513 "Received valid boot command response\n");
516 if_usb_submit_rx_urb_fwload(priv);
520 syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
522 lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
527 memcpy(syncfwheader, skb->data + IPFIELD_ALIGN_OFFSET,
528 sizeof(struct fwsyncheader));
530 if (!syncfwheader->cmd) {
532 lbs_deb_usbd(&cardp->udev->dev,
533 "FW received Blk with correct CRC\n");
534 lbs_deb_usbd(&cardp->udev->dev,
535 "FW received Blk seqnum = %d\n",
536 syncfwheader->seqnum);
540 lbs_deb_usbd(&cardp->udev->dev,
541 "FW received Blk with CRC error\n");
547 if (cardp->fwfinalblk) {
548 cardp->fwdnldover = 1;
552 if_prog_firmware(priv);
554 if_usb_submit_rx_urb_fwload(priv);
562 #define MRVDRV_MIN_PKT_LEN 30
564 static inline void process_cmdtypedata(int recvlength, struct sk_buff *skb,
565 struct usb_card_rec *cardp,
568 if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE +
569 MESSAGE_HEADER_LEN || recvlength < MRVDRV_MIN_PKT_LEN) {
570 lbs_deb_usbd(&cardp->udev->dev,
571 "Packet length is Invalid\n");
576 skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
577 skb_put(skb, recvlength);
578 skb_pull(skb, MESSAGE_HEADER_LEN);
579 libertas_process_rxed_packet(priv, skb);
580 priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
583 static inline void process_cmdrequest(int recvlength, u8 *recvbuff,
585 struct usb_card_rec *cardp,
589 if (recvlength > MRVDRV_SIZE_OF_CMD_BUFFER) {
590 lbs_deb_usbd(&cardp->udev->dev,
591 "The receive buffer is too large\n");
599 spin_lock(&priv->adapter->driver_lock);
600 /* take care of cur_cmd = NULL case by reading the
601 * data to clear the interrupt */
602 if (!priv->adapter->cur_cmd) {
603 cmdbuf = priv->upld_buf;
604 priv->adapter->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY;
606 cmdbuf = priv->adapter->cur_cmd->bufvirtualaddr;
608 cardp->usb_int_cause |= MRVDRV_CMD_UPLD_RDY;
609 priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
610 memcpy(cmdbuf, recvbuff + MESSAGE_HEADER_LEN,
614 libertas_interrupt(priv->dev);
615 spin_unlock(&priv->adapter->driver_lock);
617 lbs_deb_usbd(&cardp->udev->dev,
618 "Wake up main thread to handle cmd response\n");
624 * @brief This function reads of the packet into the upload buff,
625 * wake up the main thread and initialise the Rx callack.
627 * @param urb pointer to struct urb
630 static void if_usb_receive(struct urb *urb)
632 struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
633 wlan_private *priv = rinfo->priv;
634 struct sk_buff *skb = rinfo->skb;
635 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
637 int recvlength = urb->actual_length;
641 lbs_deb_enter(LBS_DEB_USB);
645 lbs_deb_usbd(&cardp->udev->dev,
646 "URB status is failed\n");
651 recvbuff = skb->data + IPFIELD_ALIGN_OFFSET;
652 memcpy(&recvtype, recvbuff, sizeof(u32));
653 lbs_deb_usbd(&cardp->udev->dev,
654 "Recv length = 0x%x\n", recvlength);
655 lbs_deb_usbd(&cardp->udev->dev,
656 "Receive type = 0x%X\n", recvtype);
657 recvtype = le32_to_cpu(recvtype);
658 lbs_deb_usbd(&cardp->udev->dev,
659 "Receive type after = 0x%X\n", recvtype);
660 } else if (urb->status)
666 process_cmdtypedata(recvlength, skb, cardp, priv);
669 case CMD_TYPE_REQUEST:
670 process_cmdrequest(recvlength, recvbuff, skb, cardp, priv);
673 case CMD_TYPE_INDICATION:
674 /* Event cause handling */
675 spin_lock(&priv->adapter->driver_lock);
676 cardp->usb_event_cause = le32_to_cpu(*(__le32 *) (recvbuff + MESSAGE_HEADER_LEN));
677 lbs_deb_usbd(&cardp->udev->dev,"**EVENT** 0x%X\n",
678 cardp->usb_event_cause);
679 if (cardp->usb_event_cause & 0xffff0000) {
680 libertas_send_tx_feedback(priv);
681 spin_unlock(&priv->adapter->driver_lock);
684 cardp->usb_event_cause <<= 3;
685 cardp->usb_int_cause |= MRVDRV_CARDEVENT;
687 libertas_interrupt(priv->dev);
688 spin_unlock(&priv->adapter->driver_lock);
696 if_usb_submit_rx_urb(priv);
698 lbs_deb_leave(LBS_DEB_USB);
702 * @brief This function downloads data to FW
703 * @param priv pointer to wlan_private structure
704 * @param type type of data
705 * @param buf pointer to data buffer
706 * @param len number of bytes
709 static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb)
713 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
715 lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type);
716 lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb);
718 if (type == MVMS_CMD) {
719 tmp = cpu_to_le32(CMD_TYPE_REQUEST);
720 priv->dnld_sent = DNLD_CMD_SENT;
721 memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
725 tmp = cpu_to_le32(CMD_TYPE_DATA);
726 priv->dnld_sent = DNLD_DATA_SENT;
727 memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
731 memcpy((cardp->bulk_out_buffer + MESSAGE_HEADER_LEN), payload, nb);
734 usb_tx_block(priv, cardp->bulk_out_buffer, nb + MESSAGE_HEADER_LEN);
739 /* called with adapter->driver_lock held */
740 static int if_usb_get_int_status(wlan_private * priv, u8 * ireg)
742 struct usb_card_rec *cardp = priv->card;
744 *ireg = cardp->usb_int_cause;
745 cardp->usb_int_cause = 0;
747 lbs_deb_usbd(&cardp->udev->dev,"Int cause is 0x%X\n", *ireg);
752 static int if_usb_read_event_cause(wlan_private * priv)
754 struct usb_card_rec *cardp = priv->card;
755 priv->adapter->eventcause = cardp->usb_event_cause;
756 /* Re-submit rx urb here to avoid event lost issue */
757 if_usb_submit_rx_urb(priv);
761 static int if_usb_unregister_dev(wlan_private * priv)
765 /* Need to send a Reset command to device before USB resources freed
766 * and wlan_remove_card() called, then device can handle FW download
770 libertas_reset_device(priv);
777 * @brief This function register usb device and initialize parameter
778 * @param priv pointer to wlan_private
781 static int if_usb_register_dev(wlan_private * priv)
783 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
785 lbs_deb_enter(LBS_DEB_USB);
788 cardp->eth_dev = priv->dev;
789 priv->hotplug_device = &(cardp->udev->dev);
791 lbs_deb_usbd(&cardp->udev->dev, "udev pointer is at %p\n",
794 lbs_deb_leave(LBS_DEB_USB);
799 * @brief This function issues Boot command to the Boot2 code
800 * @param ivalue 1:Boot from FW by USB-Download
801 * 2:Boot from FW in EEPROM
804 static int if_usb_issue_boot_command(wlan_private *priv, int ivalue)
806 struct usb_card_rec *cardp = priv->card;
807 struct bootcmdstr sbootcmd;
810 /* Prepare command */
811 sbootcmd.u32magicnumber = cpu_to_le32(BOOT_CMD_MAGIC_NUMBER);
812 sbootcmd.u8cmd_tag = ivalue;
814 sbootcmd.au8dumy[i]=0x00;
815 memcpy(cardp->bulk_out_buffer, &sbootcmd, sizeof(struct bootcmdstr));
818 usb_tx_block(priv, cardp->bulk_out_buffer, sizeof(struct bootcmdstr));
824 static int if_usb_do_prog_firmware(wlan_private * priv)
826 struct usb_card_rec *cardp = priv->card;
828 static int reset_count = 10;
831 lbs_deb_enter(LBS_DEB_USB);
833 cardp->rinfo.priv = priv;
836 if (if_usb_submit_rx_urb_fwload(priv) < 0) {
837 lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n");
842 cardp->bootcmdresp = 0;
846 /* Issue Boot command = 1, Boot from Download-FW */
847 if_usb_issue_boot_command(priv, BOOT_CMD_FW_BY_USB);
848 /* wait for command response */
851 msleep_interruptible(100);
852 } while (cardp->bootcmdresp == 0 && j < 10);
853 } while (cardp->bootcmdresp == 0 && i < 5);
855 if (cardp->bootcmdresp == 0) {
856 if (--reset_count >= 0) {
857 if_usb_reset_device(priv);
864 priv->adapter->fw_ready = 0;
866 cardp->totalbytes = 0;
867 cardp->fwlastblksent = 0;
869 cardp->fwdnldover = 0;
870 cardp->fwseqnum = -1;
871 cardp->totalbytes = 0;
872 cardp->fwfinalblk = 0;
874 if_prog_firmware(priv);
877 lbs_deb_usbd(&cardp->udev->dev,"Wlan sched timeout\n");
879 msleep_interruptible(100);
880 if (priv->adapter->surpriseremoved || i >= 20)
882 } while (!cardp->fwdnldover);
884 if (!cardp->fwdnldover) {
885 lbs_pr_info("failed to load fw, resetting device!\n");
886 if (--reset_count >= 0) {
887 if_usb_reset_device(priv);
891 lbs_pr_info("FW download failure, time = %d ms\n", i * 100);
896 if_usb_submit_rx_urb(priv);
898 /* Delay 200 ms to waiting for the FW ready */
899 msleep_interruptible(200);
901 priv->adapter->fw_ready = 1;
904 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
909 * @brief This function checks the validity of Boot2/FW image.
911 * @param data pointer to image
915 static int check_fwfile_format(u8 *data, u32 totlen)
918 u32 blksize, offset, len;
925 struct fwheader *fwh = (void *)data;
927 bincmd = le32_to_cpu(fwh->dnldcmd);
928 blksize = le32_to_cpu(fwh->datalength);
930 case FW_HAS_DATA_TO_RECV:
931 offset = sizeof(struct fwheader) + blksize;
937 case FW_HAS_LAST_BLOCK:
948 lbs_pr_err("firmware file format check FAIL\n");
950 lbs_deb_fw("firmware file format check PASS\n");
956 static int if_usb_prog_firmware(wlan_private *priv)
960 lbs_deb_enter(LBS_DEB_FW);
962 if ((ret = request_firmware(&priv->firmware, libertas_fw_name,
963 priv->hotplug_device)) < 0) {
964 lbs_pr_err("request_firmware() failed with %#x\n", ret);
965 lbs_pr_err("firmware %s not found\n", libertas_fw_name);
969 if (check_fwfile_format(priv->firmware->data, priv->firmware->size)) {
970 release_firmware(priv->firmware);
974 ret = if_usb_do_prog_firmware(priv);
976 release_firmware(priv->firmware);
983 static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
985 struct usb_card_rec *cardp = usb_get_intfdata(intf);
986 wlan_private *priv = cardp->priv;
988 lbs_deb_enter(LBS_DEB_USB);
990 if (priv->adapter->psstate != PS_STATE_FULL_POWER)
993 netif_device_detach(cardp->eth_dev);
994 netif_device_detach(priv->mesh_dev);
996 /* Unlink tx & rx urb */
997 usb_kill_urb(cardp->tx_urb);
998 usb_kill_urb(cardp->rx_urb);
1000 cardp->rx_urb_recall = 1;
1002 lbs_deb_leave(LBS_DEB_USB);
1006 static int if_usb_resume(struct usb_interface *intf)
1008 struct usb_card_rec *cardp = usb_get_intfdata(intf);
1009 wlan_private *priv = cardp->priv;
1011 lbs_deb_enter(LBS_DEB_USB);
1013 cardp->rx_urb_recall = 0;
1015 if_usb_submit_rx_urb(cardp->priv);
1017 netif_device_attach(cardp->eth_dev);
1018 netif_device_attach(priv->mesh_dev);
1020 lbs_deb_leave(LBS_DEB_USB);
1024 #define if_usb_suspend NULL
1025 #define if_usb_resume NULL
1028 static struct usb_driver if_usb_driver = {
1030 .name = usbdriver_name,
1031 /* probe function name */
1032 .probe = if_usb_probe,
1033 /* disconnect function name */
1034 .disconnect = if_usb_disconnect,
1035 /* device signature table */
1036 .id_table = if_usb_table,
1037 .suspend = if_usb_suspend,
1038 .resume = if_usb_resume,
1041 static int if_usb_init_module(void)
1045 lbs_deb_enter(LBS_DEB_MAIN);
1047 if (libertas_fw_name == NULL) {
1048 libertas_fw_name = default_fw_name;
1051 ret = usb_register(&if_usb_driver);
1053 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
1057 static void if_usb_exit_module(void)
1059 struct usb_card_rec *cardp, *cardp_temp;
1061 lbs_deb_enter(LBS_DEB_MAIN);
1063 list_for_each_entry_safe(cardp, cardp_temp, &usb_devices, list)
1064 libertas_reset_device((wlan_private *) cardp->priv);
1066 /* API unregisters the driver from USB subsystem */
1067 usb_deregister(&if_usb_driver);
1069 lbs_deb_leave(LBS_DEB_MAIN);
1072 module_init(if_usb_init_module);
1073 module_exit(if_usb_exit_module);
1075 MODULE_DESCRIPTION("8388 USB WLAN Driver");
1076 MODULE_AUTHOR("Marvell International Ltd.");
1077 MODULE_LICENSE("GPL");