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>
14 #define DRV_NAME "usb8xxx"
24 #define lbs_deb_usb2(...) do { if (INSANEDEBUG) lbs_deb_usbd(__VA_ARGS__); } while (0)
26 #define MESSAGE_HEADER_LEN 4
28 static char *lbs_fw_name = "usb8388.bin";
29 module_param_named(fw_name, lbs_fw_name, charp, 0644);
31 static struct usb_device_id if_usb_table[] = {
32 /* Enter the device signature inside */
33 { USB_DEVICE(0x1286, 0x2001) },
34 { USB_DEVICE(0x05a3, 0x8388) },
35 {} /* Terminating entry */
38 MODULE_DEVICE_TABLE(usb, if_usb_table);
40 static void if_usb_receive(struct urb *urb);
41 static void if_usb_receive_fwload(struct urb *urb);
42 static int if_usb_prog_firmware(struct if_usb_card *cardp);
43 static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
44 uint8_t *payload, uint16_t nb);
45 static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload,
47 static void if_usb_free(struct if_usb_card *cardp);
48 static int if_usb_submit_rx_urb(struct if_usb_card *cardp);
49 static int if_usb_reset_device(struct if_usb_card *cardp);
52 * @brief call back function to handle the status of the URB
53 * @param urb pointer to urb structure
56 static void if_usb_write_bulk_callback(struct urb *urb)
58 struct if_usb_card *cardp = (struct if_usb_card *) urb->context;
60 /* handle the transmission complete validations */
62 if (urb->status == 0) {
63 struct lbs_private *priv = cardp->priv;
65 lbs_deb_usb2(&urb->dev->dev, "URB status is successful\n");
66 lbs_deb_usb2(&urb->dev->dev, "Actual length transmitted %d\n",
69 /* Used for both firmware TX and regular TX. priv isn't
70 * valid at firmware load time.
73 lbs_host_to_card_done(priv);
75 /* print the failure status number for debug */
76 lbs_pr_info("URB in failure status: %d\n", urb->status);
83 * @brief free tx/rx urb, skb and rx buffer
84 * @param cardp pointer if_usb_card
87 static void if_usb_free(struct if_usb_card *cardp)
89 lbs_deb_enter(LBS_DEB_USB);
91 /* Unlink tx & rx urb */
92 usb_kill_urb(cardp->tx_urb);
93 usb_kill_urb(cardp->rx_urb);
95 usb_free_urb(cardp->tx_urb);
98 usb_free_urb(cardp->rx_urb);
101 kfree(cardp->ep_out_buf);
102 cardp->ep_out_buf = NULL;
104 lbs_deb_leave(LBS_DEB_USB);
107 static void if_usb_setup_firmware(struct lbs_private *priv)
109 struct if_usb_card *cardp = priv->card;
110 struct cmd_ds_set_boot2_ver b2_cmd;
111 struct cmd_ds_802_11_fw_wake_method wake_method;
113 b2_cmd.hdr.size = cpu_to_le16(sizeof(b2_cmd));
115 b2_cmd.version = cardp->boot2_version;
117 if (lbs_cmd_with_response(priv, CMD_SET_BOOT2_VER, &b2_cmd))
118 lbs_deb_usb("Setting boot2 version failed\n");
120 priv->wol_gpio = 2; /* Wake via GPIO2... */
121 priv->wol_gap = 20; /* ... after 20ms */
122 lbs_host_sleep_cfg(priv, EHS_WAKE_ON_UNICAST_DATA);
124 wake_method.hdr.size = cpu_to_le16(sizeof(wake_method));
125 wake_method.action = cpu_to_le16(CMD_ACT_GET);
126 if (lbs_cmd_with_response(priv, CMD_802_11_FW_WAKE_METHOD, &wake_method)) {
127 lbs_pr_info("Firmware does not seem to support PS mode\n");
129 if (le16_to_cpu(wake_method.method) == CMD_WAKE_METHOD_COMMAND_INT) {
130 lbs_deb_usb("Firmware seems to support PS with wake-via-command\n");
131 priv->ps_supported = 1;
133 /* The versions which boot up this way don't seem to
134 work even if we set it to the command interrupt */
135 lbs_pr_info("Firmware doesn't wake via command interrupt; disabling PS mode\n");
140 static void if_usb_fw_timeo(unsigned long priv)
142 struct if_usb_card *cardp = (void *)priv;
144 if (cardp->fwdnldover) {
145 lbs_deb_usb("Download complete, no event. Assuming success\n");
147 lbs_pr_err("Download timed out\n");
148 cardp->surprise_removed = 1;
150 wake_up(&cardp->fw_wq);
154 static void if_usb_reset_olpc_card(struct lbs_private *priv)
156 printk(KERN_CRIT "Resetting OLPC wireless via EC...\n");
157 olpc_ec_cmd(0x25, NULL, 0, NULL, 0);
162 * @brief sets the configuration values
163 * @param ifnum interface number
164 * @param id pointer to usb_device_id
165 * @return 0 on success, error code on failure
167 static int if_usb_probe(struct usb_interface *intf,
168 const struct usb_device_id *id)
170 struct usb_device *udev;
171 struct usb_host_interface *iface_desc;
172 struct usb_endpoint_descriptor *endpoint;
173 struct lbs_private *priv;
174 struct if_usb_card *cardp;
177 udev = interface_to_usbdev(intf);
179 cardp = kzalloc(sizeof(struct if_usb_card), GFP_KERNEL);
181 lbs_pr_err("Out of memory allocating private data.\n");
185 setup_timer(&cardp->fw_timeout, if_usb_fw_timeo, (unsigned long)cardp);
186 init_waitqueue_head(&cardp->fw_wq);
189 iface_desc = intf->cur_altsetting;
191 lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X"
192 " bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n",
193 le16_to_cpu(udev->descriptor.bcdUSB),
194 udev->descriptor.bDeviceClass,
195 udev->descriptor.bDeviceSubClass,
196 udev->descriptor.bDeviceProtocol);
198 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
199 endpoint = &iface_desc->endpoint[i].desc;
200 if (usb_endpoint_is_bulk_in(endpoint)) {
201 cardp->ep_in_size = le16_to_cpu(endpoint->wMaxPacketSize);
202 cardp->ep_in = usb_endpoint_num(endpoint);
204 lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n", cardp->ep_in);
205 lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n", cardp->ep_in_size);
207 } else if (usb_endpoint_is_bulk_out(endpoint)) {
208 cardp->ep_out_size = le16_to_cpu(endpoint->wMaxPacketSize);
209 cardp->ep_out = usb_endpoint_num(endpoint);
211 lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n", cardp->ep_out);
212 lbs_deb_usbd(&udev->dev, "Bulk out size is %d\n", cardp->ep_out_size);
215 if (!cardp->ep_out_size || !cardp->ep_in_size) {
216 lbs_deb_usbd(&udev->dev, "Endpoints not found\n");
219 if (!(cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
220 lbs_deb_usbd(&udev->dev, "Rx URB allocation failed\n");
223 if (!(cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
224 lbs_deb_usbd(&udev->dev, "Tx URB allocation failed\n");
227 cardp->ep_out_buf = kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE, GFP_KERNEL);
228 if (!cardp->ep_out_buf) {
229 lbs_deb_usbd(&udev->dev, "Could not allocate buffer\n");
233 /* Upload firmware */
234 if (if_usb_prog_firmware(cardp)) {
235 lbs_deb_usbd(&udev->dev, "FW upload failed\n");
236 goto err_prog_firmware;
239 if (!(priv = lbs_add_card(cardp, &udev->dev)))
240 goto err_prog_firmware;
243 cardp->priv->fw_ready = 1;
245 priv->hw_host_to_card = if_usb_host_to_card;
247 if (machine_is_olpc())
248 priv->reset_card = if_usb_reset_olpc_card;
251 cardp->boot2_version = udev->descriptor.bcdDevice;
253 if_usb_submit_rx_urb(cardp);
255 if (lbs_start_card(priv))
258 if_usb_setup_firmware(priv);
261 usb_set_intfdata(intf, cardp);
266 lbs_remove_card(priv);
268 if_usb_reset_device(cardp);
277 * @brief free resource and cleanup
278 * @param intf USB interface structure
281 static void if_usb_disconnect(struct usb_interface *intf)
283 struct if_usb_card *cardp = usb_get_intfdata(intf);
284 struct lbs_private *priv = (struct lbs_private *) cardp->priv;
286 lbs_deb_enter(LBS_DEB_MAIN);
288 cardp->surprise_removed = 1;
291 priv->surpriseremoved = 1;
293 lbs_remove_card(priv);
296 /* Unlink and free urb */
299 usb_set_intfdata(intf, NULL);
300 usb_put_dev(interface_to_usbdev(intf));
302 lbs_deb_leave(LBS_DEB_MAIN);
306 * @brief This function download FW
307 * @param priv pointer to struct lbs_private
310 static int if_usb_send_fw_pkt(struct if_usb_card *cardp)
312 struct fwdata *fwdata = cardp->ep_out_buf;
313 const uint8_t *firmware = cardp->fw->data;
315 /* If we got a CRC failure on the last block, back
317 if (!cardp->CRC_OK) {
318 cardp->totalbytes = cardp->fwlastblksent;
322 lbs_deb_usb2(&cardp->udev->dev, "totalbytes = %d\n",
325 /* struct fwdata (which we sent to the card) has an
326 extra __le32 field in between the header and the data,
327 which is not in the struct fwheader in the actual
328 firmware binary. Insert the seqnum in the middle... */
329 memcpy(&fwdata->hdr, &firmware[cardp->totalbytes],
330 sizeof(struct fwheader));
332 cardp->fwlastblksent = cardp->totalbytes;
333 cardp->totalbytes += sizeof(struct fwheader);
335 memcpy(fwdata->data, &firmware[cardp->totalbytes],
336 le32_to_cpu(fwdata->hdr.datalength));
338 lbs_deb_usb2(&cardp->udev->dev, "Data length = %d\n",
339 le32_to_cpu(fwdata->hdr.datalength));
341 fwdata->seqnum = cpu_to_le32(++cardp->fwseqnum);
342 cardp->totalbytes += le32_to_cpu(fwdata->hdr.datalength);
344 usb_tx_block(cardp, cardp->ep_out_buf, sizeof(struct fwdata) +
345 le32_to_cpu(fwdata->hdr.datalength));
347 if (fwdata->hdr.dnldcmd == cpu_to_le32(FW_HAS_DATA_TO_RECV)) {
348 lbs_deb_usb2(&cardp->udev->dev, "There are data to follow\n");
349 lbs_deb_usb2(&cardp->udev->dev, "seqnum = %d totalbytes = %d\n",
350 cardp->fwseqnum, cardp->totalbytes);
351 } else if (fwdata->hdr.dnldcmd == cpu_to_le32(FW_HAS_LAST_BLOCK)) {
352 lbs_deb_usb2(&cardp->udev->dev, "Host has finished FW downloading\n");
353 lbs_deb_usb2(&cardp->udev->dev, "Donwloading FW JUMP BLOCK\n");
355 cardp->fwfinalblk = 1;
358 lbs_deb_usb2(&cardp->udev->dev, "Firmware download done; size %d\n",
364 static int if_usb_reset_device(struct if_usb_card *cardp)
366 struct cmd_ds_command *cmd = cardp->ep_out_buf + 4;
369 lbs_deb_enter(LBS_DEB_USB);
371 *(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_REQUEST);
373 cmd->command = cpu_to_le16(CMD_802_11_RESET);
374 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
375 cmd->result = cpu_to_le16(0);
376 cmd->seqnum = cpu_to_le16(0x5a5a);
377 cmd->params.reset.action = cpu_to_le16(CMD_ACT_HALT);
378 usb_tx_block(cardp, cardp->ep_out_buf, 4 + S_DS_GEN + sizeof(struct cmd_ds_802_11_reset));
381 ret = usb_reset_device(cardp->udev);
385 if (ret && machine_is_olpc())
386 if_usb_reset_olpc_card(NULL);
389 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
395 * @brief This function transfer the data to the device.
396 * @param priv pointer to struct lbs_private
397 * @param payload pointer to payload data
398 * @param nb data length
401 static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload, uint16_t nb)
405 /* check if device is removed */
406 if (cardp->surprise_removed) {
407 lbs_deb_usbd(&cardp->udev->dev, "Device removed\n");
411 usb_fill_bulk_urb(cardp->tx_urb, cardp->udev,
412 usb_sndbulkpipe(cardp->udev,
414 payload, nb, if_usb_write_bulk_callback, cardp);
416 cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET;
418 if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
419 lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed: %d\n", ret);
422 lbs_deb_usb2(&cardp->udev->dev, "usb_submit_urb success\n");
430 static int __if_usb_submit_rx_urb(struct if_usb_card *cardp,
431 void (*callbackfn)(struct urb *urb))
436 if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
437 lbs_pr_err("No free skb\n");
443 /* Fill the receive configuration URB and initialise the Rx call back */
444 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
445 usb_rcvbulkpipe(cardp->udev, cardp->ep_in),
446 (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET),
447 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn,
450 cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
452 lbs_deb_usb2(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb);
453 if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) {
454 lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed: %d\n", ret);
456 cardp->rx_skb = NULL;
459 lbs_deb_usb2(&cardp->udev->dev, "Submit Rx URB success\n");
467 static int if_usb_submit_rx_urb_fwload(struct if_usb_card *cardp)
469 return __if_usb_submit_rx_urb(cardp, &if_usb_receive_fwload);
472 static int if_usb_submit_rx_urb(struct if_usb_card *cardp)
474 return __if_usb_submit_rx_urb(cardp, &if_usb_receive);
477 static void if_usb_receive_fwload(struct urb *urb)
479 struct if_usb_card *cardp = urb->context;
480 struct sk_buff *skb = cardp->rx_skb;
481 struct fwsyncheader *syncfwheader;
482 struct bootcmdresp bootcmdresp;
485 lbs_deb_usbd(&cardp->udev->dev,
486 "URB status is failed during fw load\n");
491 if (cardp->fwdnldover) {
492 __le32 *tmp = (__le32 *)(skb->data + IPFIELD_ALIGN_OFFSET);
494 if (tmp[0] == cpu_to_le32(CMD_TYPE_INDICATION) &&
495 tmp[1] == cpu_to_le32(MACREG_INT_CODE_FIRMWARE_READY)) {
496 lbs_pr_info("Firmware ready event received\n");
497 wake_up(&cardp->fw_wq);
499 lbs_deb_usb("Waiting for confirmation; got %x %x\n",
500 le32_to_cpu(tmp[0]), le32_to_cpu(tmp[1]));
501 if_usb_submit_rx_urb_fwload(cardp);
506 if (cardp->bootcmdresp <= 0) {
507 memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET,
508 sizeof(bootcmdresp));
510 if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) {
512 if_usb_submit_rx_urb_fwload(cardp);
513 cardp->bootcmdresp = 1;
514 lbs_deb_usbd(&cardp->udev->dev,
515 "Received valid boot command response\n");
518 if (bootcmdresp.magic != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) {
519 if (bootcmdresp.magic == cpu_to_le32(CMD_TYPE_REQUEST) ||
520 bootcmdresp.magic == cpu_to_le32(CMD_TYPE_DATA) ||
521 bootcmdresp.magic == cpu_to_le32(CMD_TYPE_INDICATION)) {
522 if (!cardp->bootcmdresp)
523 lbs_pr_info("Firmware already seems alive; resetting\n");
524 cardp->bootcmdresp = -1;
526 lbs_pr_info("boot cmd response wrong magic number (0x%x)\n",
527 le32_to_cpu(bootcmdresp.magic));
529 } else if (bootcmdresp.cmd != BOOT_CMD_FW_BY_USB) {
530 lbs_pr_info("boot cmd response cmd_tag error (%d)\n",
532 } else if (bootcmdresp.result != BOOT_CMD_RESP_OK) {
533 lbs_pr_info("boot cmd response result error (%d)\n",
536 cardp->bootcmdresp = 1;
537 lbs_deb_usbd(&cardp->udev->dev,
538 "Received valid boot command response\n");
541 if_usb_submit_rx_urb_fwload(cardp);
545 syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
547 lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
552 memcpy(syncfwheader, skb->data + IPFIELD_ALIGN_OFFSET,
553 sizeof(struct fwsyncheader));
555 if (!syncfwheader->cmd) {
556 lbs_deb_usb2(&cardp->udev->dev, "FW received Blk with correct CRC\n");
557 lbs_deb_usb2(&cardp->udev->dev, "FW received Blk seqnum = %d\n",
558 le32_to_cpu(syncfwheader->seqnum));
561 lbs_deb_usbd(&cardp->udev->dev, "FW received Blk with CRC error\n");
567 /* reschedule timer for 200ms hence */
568 mod_timer(&cardp->fw_timeout, jiffies + (HZ/5));
570 if (cardp->fwfinalblk) {
571 cardp->fwdnldover = 1;
575 if_usb_send_fw_pkt(cardp);
578 if_usb_submit_rx_urb_fwload(cardp);
585 #define MRVDRV_MIN_PKT_LEN 30
587 static inline void process_cmdtypedata(int recvlength, struct sk_buff *skb,
588 struct if_usb_card *cardp,
589 struct lbs_private *priv)
591 if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + MESSAGE_HEADER_LEN
592 || recvlength < MRVDRV_MIN_PKT_LEN) {
593 lbs_deb_usbd(&cardp->udev->dev, "Packet length is Invalid\n");
598 skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
599 skb_put(skb, recvlength);
600 skb_pull(skb, MESSAGE_HEADER_LEN);
602 lbs_process_rxed_packet(priv, skb);
605 static inline void process_cmdrequest(int recvlength, uint8_t *recvbuff,
607 struct if_usb_card *cardp,
608 struct lbs_private *priv)
612 if (recvlength > LBS_CMD_BUFFER_SIZE) {
613 lbs_deb_usbd(&cardp->udev->dev,
614 "The receive buffer is too large\n");
622 spin_lock(&priv->driver_lock);
624 i = (priv->resp_idx == 0) ? 1 : 0;
625 BUG_ON(priv->resp_len[i]);
626 priv->resp_len[i] = (recvlength - MESSAGE_HEADER_LEN);
627 memcpy(priv->resp_buf[i], recvbuff + MESSAGE_HEADER_LEN,
630 lbs_notify_command_response(priv, i);
632 spin_unlock(&priv->driver_lock);
634 lbs_deb_usbd(&cardp->udev->dev,
635 "Wake up main thread to handle cmd response\n");
639 * @brief This function reads of the packet into the upload buff,
640 * wake up the main thread and initialise the Rx callack.
642 * @param urb pointer to struct urb
645 static void if_usb_receive(struct urb *urb)
647 struct if_usb_card *cardp = urb->context;
648 struct sk_buff *skb = cardp->rx_skb;
649 struct lbs_private *priv = cardp->priv;
650 int recvlength = urb->actual_length;
651 uint8_t *recvbuff = NULL;
652 uint32_t recvtype = 0;
653 __le32 *pkt = (__le32 *)(skb->data + IPFIELD_ALIGN_OFFSET);
656 lbs_deb_enter(LBS_DEB_USB);
660 lbs_deb_usbd(&cardp->udev->dev, "RX URB failed: %d\n",
666 recvbuff = skb->data + IPFIELD_ALIGN_OFFSET;
667 recvtype = le32_to_cpu(pkt[0]);
668 lbs_deb_usbd(&cardp->udev->dev,
669 "Recv length = 0x%x, Recv type = 0x%X\n",
670 recvlength, recvtype);
671 } else if (urb->status) {
678 process_cmdtypedata(recvlength, skb, cardp, priv);
681 case CMD_TYPE_REQUEST:
682 process_cmdrequest(recvlength, recvbuff, skb, cardp, priv);
685 case CMD_TYPE_INDICATION:
687 event = le32_to_cpu(pkt[1]);
688 lbs_deb_usbd(&cardp->udev->dev, "**EVENT** 0x%X\n", event);
691 /* Icky undocumented magic special case */
692 if (event & 0xffff0000) {
693 u32 trycount = (event & 0xffff0000) >> 16;
695 lbs_send_tx_feedback(priv, trycount);
697 lbs_queue_event(priv, event & 0xFF);
701 lbs_deb_usbd(&cardp->udev->dev, "Unknown command type 0x%X\n",
708 if_usb_submit_rx_urb(cardp);
710 lbs_deb_leave(LBS_DEB_USB);
714 * @brief This function downloads data to FW
715 * @param priv pointer to struct lbs_private structure
716 * @param type type of data
717 * @param buf pointer to data buffer
718 * @param len number of bytes
721 static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
722 uint8_t *payload, uint16_t nb)
724 struct if_usb_card *cardp = priv->card;
726 lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type);
727 lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb);
729 if (type == MVMS_CMD) {
730 *(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_REQUEST);
731 priv->dnld_sent = DNLD_CMD_SENT;
733 *(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_DATA);
734 priv->dnld_sent = DNLD_DATA_SENT;
737 memcpy((cardp->ep_out_buf + MESSAGE_HEADER_LEN), payload, nb);
739 return usb_tx_block(cardp, cardp->ep_out_buf, nb + MESSAGE_HEADER_LEN);
743 * @brief This function issues Boot command to the Boot2 code
744 * @param ivalue 1:Boot from FW by USB-Download
745 * 2:Boot from FW in EEPROM
748 static int if_usb_issue_boot_command(struct if_usb_card *cardp, int ivalue)
750 struct bootcmd *bootcmd = cardp->ep_out_buf;
752 /* Prepare command */
753 bootcmd->magic = cpu_to_le32(BOOT_CMD_MAGIC_NUMBER);
754 bootcmd->cmd = ivalue;
755 memset(bootcmd->pad, 0, sizeof(bootcmd->pad));
758 usb_tx_block(cardp, cardp->ep_out_buf, sizeof(*bootcmd));
765 * @brief This function checks the validity of Boot2/FW image.
767 * @param data pointer to image
771 static int check_fwfile_format(const uint8_t *data, uint32_t totlen)
773 uint32_t bincmd, exit;
774 uint32_t blksize, offset, len;
781 struct fwheader *fwh = (void *)data;
783 bincmd = le32_to_cpu(fwh->dnldcmd);
784 blksize = le32_to_cpu(fwh->datalength);
786 case FW_HAS_DATA_TO_RECV:
787 offset = sizeof(struct fwheader) + blksize;
793 case FW_HAS_LAST_BLOCK:
804 lbs_pr_err("firmware file format check FAIL\n");
806 lbs_deb_fw("firmware file format check PASS\n");
812 static int if_usb_prog_firmware(struct if_usb_card *cardp)
815 static int reset_count = 10;
818 lbs_deb_enter(LBS_DEB_USB);
820 if ((ret = request_firmware(&cardp->fw, lbs_fw_name,
821 &cardp->udev->dev)) < 0) {
822 lbs_pr_err("request_firmware() failed with %#x\n", ret);
823 lbs_pr_err("firmware %s not found\n", lbs_fw_name);
827 if (check_fwfile_format(cardp->fw->data, cardp->fw->size))
831 if (if_usb_submit_rx_urb_fwload(cardp) < 0) {
832 lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n");
837 cardp->bootcmdresp = 0;
841 /* Issue Boot command = 1, Boot from Download-FW */
842 if_usb_issue_boot_command(cardp, BOOT_CMD_FW_BY_USB);
843 /* wait for command response */
846 msleep_interruptible(100);
847 } while (cardp->bootcmdresp == 0 && j < 10);
848 } while (cardp->bootcmdresp == 0 && i < 5);
850 if (cardp->bootcmdresp <= 0) {
851 if (--reset_count >= 0) {
852 if_usb_reset_device(cardp);
860 cardp->totalbytes = 0;
861 cardp->fwlastblksent = 0;
863 cardp->fwdnldover = 0;
864 cardp->fwseqnum = -1;
865 cardp->totalbytes = 0;
866 cardp->fwfinalblk = 0;
868 /* Send the first firmware packet... */
869 if_usb_send_fw_pkt(cardp);
871 /* ... and wait for the process to complete */
872 wait_event_interruptible(cardp->fw_wq, cardp->surprise_removed || cardp->fwdnldover);
874 del_timer_sync(&cardp->fw_timeout);
875 usb_kill_urb(cardp->rx_urb);
877 if (!cardp->fwdnldover) {
878 lbs_pr_info("failed to load fw, resetting device!\n");
879 if (--reset_count >= 0) {
880 if_usb_reset_device(cardp);
884 lbs_pr_info("FW download failure, time = %d ms\n", i * 100);
890 release_firmware(cardp->fw);
894 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
900 static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
902 struct if_usb_card *cardp = usb_get_intfdata(intf);
903 struct lbs_private *priv = cardp->priv;
906 lbs_deb_enter(LBS_DEB_USB);
908 if (priv->psstate != PS_STATE_FULL_POWER)
911 ret = lbs_suspend(priv);
915 /* Unlink tx & rx urb */
916 usb_kill_urb(cardp->tx_urb);
917 usb_kill_urb(cardp->rx_urb);
920 lbs_deb_leave(LBS_DEB_USB);
924 static int if_usb_resume(struct usb_interface *intf)
926 struct if_usb_card *cardp = usb_get_intfdata(intf);
927 struct lbs_private *priv = cardp->priv;
929 lbs_deb_enter(LBS_DEB_USB);
931 if_usb_submit_rx_urb(cardp);
935 lbs_deb_leave(LBS_DEB_USB);
939 #define if_usb_suspend NULL
940 #define if_usb_resume NULL
943 static struct usb_driver if_usb_driver = {
945 .probe = if_usb_probe,
946 .disconnect = if_usb_disconnect,
947 .id_table = if_usb_table,
948 .suspend = if_usb_suspend,
949 .resume = if_usb_resume,
950 .reset_resume = if_usb_resume,
953 static int __init if_usb_init_module(void)
957 lbs_deb_enter(LBS_DEB_MAIN);
959 ret = usb_register(&if_usb_driver);
961 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
965 static void __exit if_usb_exit_module(void)
967 lbs_deb_enter(LBS_DEB_MAIN);
969 usb_deregister(&if_usb_driver);
971 lbs_deb_leave(LBS_DEB_MAIN);
974 module_init(if_usb_init_module);
975 module_exit(if_usb_exit_module);
977 MODULE_DESCRIPTION("8388 USB WLAN Driver");
978 MODULE_AUTHOR("Marvell International Ltd. and Red Hat, Inc.");
979 MODULE_LICENSE("GPL");