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>
10 #define DRV_NAME "usb8xxx"
20 #define lbs_deb_usb2(...) do { if (INSANEDEBUG) lbs_deb_usbd(__VA_ARGS__); } while (0)
22 #define MESSAGE_HEADER_LEN 4
24 static char *lbs_fw_name = "usb8388.bin";
25 module_param_named(fw_name, lbs_fw_name, charp, 0644);
27 static struct usb_device_id if_usb_table[] = {
28 /* Enter the device signature inside */
29 { USB_DEVICE(0x1286, 0x2001) },
30 { USB_DEVICE(0x05a3, 0x8388) },
31 {} /* Terminating entry */
34 MODULE_DEVICE_TABLE(usb, if_usb_table);
36 static void if_usb_receive(struct urb *urb);
37 static void if_usb_receive_fwload(struct urb *urb);
38 static int if_usb_prog_firmware(struct if_usb_card *cardp);
39 static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
40 uint8_t *payload, uint16_t nb);
41 static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload,
43 static void if_usb_free(struct if_usb_card *cardp);
44 static int if_usb_submit_rx_urb(struct if_usb_card *cardp);
45 static int if_usb_reset_device(struct if_usb_card *cardp);
48 * @brief call back function to handle the status of the URB
49 * @param urb pointer to urb structure
52 static void if_usb_write_bulk_callback(struct urb *urb)
54 struct if_usb_card *cardp = (struct if_usb_card *) urb->context;
56 /* handle the transmission complete validations */
58 if (urb->status == 0) {
59 struct lbs_private *priv = cardp->priv;
61 lbs_deb_usb2(&urb->dev->dev, "URB status is successful\n");
62 lbs_deb_usb2(&urb->dev->dev, "Actual length transmitted %d\n",
65 /* Used for both firmware TX and regular TX. priv isn't
66 * valid at firmware load time.
69 lbs_host_to_card_done(priv);
71 /* print the failure status number for debug */
72 lbs_pr_info("URB in failure status: %d\n", urb->status);
79 * @brief free tx/rx urb, skb and rx buffer
80 * @param cardp pointer if_usb_card
83 static void if_usb_free(struct if_usb_card *cardp)
85 lbs_deb_enter(LBS_DEB_USB);
87 /* Unlink tx & rx urb */
88 usb_kill_urb(cardp->tx_urb);
89 usb_kill_urb(cardp->rx_urb);
91 usb_free_urb(cardp->tx_urb);
94 usb_free_urb(cardp->rx_urb);
97 kfree(cardp->ep_out_buf);
98 cardp->ep_out_buf = NULL;
100 lbs_deb_leave(LBS_DEB_USB);
103 static void if_usb_setup_firmware(struct lbs_private *priv)
105 struct if_usb_card *cardp = priv->card;
106 struct cmd_ds_set_boot2_ver b2_cmd;
107 struct cmd_ds_802_11_fw_wake_method wake_method;
109 b2_cmd.hdr.size = cpu_to_le16(sizeof(b2_cmd));
111 b2_cmd.version = cardp->boot2_version;
113 if (lbs_cmd_with_response(priv, CMD_SET_BOOT2_VER, &b2_cmd))
114 lbs_deb_usb("Setting boot2 version failed\n");
116 priv->wol_gpio = 2; /* Wake via GPIO2... */
117 priv->wol_gap = 20; /* ... after 20ms */
118 lbs_host_sleep_cfg(priv, EHS_WAKE_ON_UNICAST_DATA);
120 wake_method.hdr.size = cpu_to_le16(sizeof(wake_method));
121 wake_method.action = cpu_to_le16(CMD_ACT_GET);
122 if (lbs_cmd_with_response(priv, CMD_802_11_FW_WAKE_METHOD, &wake_method)) {
123 lbs_pr_info("Firmware does not seem to support PS mode\n");
125 if (le16_to_cpu(wake_method.method) == CMD_WAKE_METHOD_COMMAND_INT) {
126 lbs_deb_usb("Firmware seems to support PS with wake-via-command\n");
127 priv->ps_supported = 1;
129 /* The versions which boot up this way don't seem to
130 work even if we set it to the command interrupt */
131 lbs_pr_info("Firmware doesn't wake via command interrupt; disabling PS mode\n");
136 static void if_usb_fw_timeo(unsigned long priv)
138 struct if_usb_card *cardp = (void *)priv;
140 if (cardp->fwdnldover) {
141 lbs_deb_usb("Download complete, no event. Assuming success\n");
143 lbs_pr_err("Download timed out\n");
144 cardp->surprise_removed = 1;
146 wake_up(&cardp->fw_wq);
150 * @brief sets the configuration values
151 * @param ifnum interface number
152 * @param id pointer to usb_device_id
153 * @return 0 on success, error code on failure
155 static int if_usb_probe(struct usb_interface *intf,
156 const struct usb_device_id *id)
158 struct usb_device *udev;
159 struct usb_host_interface *iface_desc;
160 struct usb_endpoint_descriptor *endpoint;
161 struct lbs_private *priv;
162 struct if_usb_card *cardp;
165 udev = interface_to_usbdev(intf);
167 cardp = kzalloc(sizeof(struct if_usb_card), GFP_KERNEL);
169 lbs_pr_err("Out of memory allocating private data.\n");
173 setup_timer(&cardp->fw_timeout, if_usb_fw_timeo, (unsigned long)cardp);
174 init_waitqueue_head(&cardp->fw_wq);
177 iface_desc = intf->cur_altsetting;
179 lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X"
180 " bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n",
181 le16_to_cpu(udev->descriptor.bcdUSB),
182 udev->descriptor.bDeviceClass,
183 udev->descriptor.bDeviceSubClass,
184 udev->descriptor.bDeviceProtocol);
186 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
187 endpoint = &iface_desc->endpoint[i].desc;
188 if (usb_endpoint_is_bulk_in(endpoint)) {
189 cardp->ep_in_size = le16_to_cpu(endpoint->wMaxPacketSize);
190 cardp->ep_in = usb_endpoint_num(endpoint);
192 lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n", cardp->ep_in);
193 lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n", cardp->ep_in_size);
195 } else if (usb_endpoint_is_bulk_out(endpoint)) {
196 cardp->ep_out_size = le16_to_cpu(endpoint->wMaxPacketSize);
197 cardp->ep_out = usb_endpoint_num(endpoint);
199 lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n", cardp->ep_out);
200 lbs_deb_usbd(&udev->dev, "Bulk out size is %d\n", cardp->ep_out_size);
203 if (!cardp->ep_out_size || !cardp->ep_in_size) {
204 lbs_deb_usbd(&udev->dev, "Endpoints not found\n");
207 if (!(cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
208 lbs_deb_usbd(&udev->dev, "Rx URB allocation failed\n");
211 if (!(cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL))) {
212 lbs_deb_usbd(&udev->dev, "Tx URB allocation failed\n");
215 cardp->ep_out_buf = kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE, GFP_KERNEL);
216 if (!cardp->ep_out_buf) {
217 lbs_deb_usbd(&udev->dev, "Could not allocate buffer\n");
221 /* Upload firmware */
222 if (if_usb_prog_firmware(cardp)) {
223 lbs_deb_usbd(&udev->dev, "FW upload failed\n");
224 goto err_prog_firmware;
227 if (!(priv = lbs_add_card(cardp, &udev->dev)))
228 goto err_prog_firmware;
231 cardp->priv->fw_ready = 1;
233 priv->hw_host_to_card = if_usb_host_to_card;
234 cardp->boot2_version = udev->descriptor.bcdDevice;
236 if_usb_submit_rx_urb(cardp);
238 if (lbs_start_card(priv))
241 if_usb_setup_firmware(priv);
244 usb_set_intfdata(intf, cardp);
249 lbs_remove_card(priv);
251 if_usb_reset_device(cardp);
260 * @brief free resource and cleanup
261 * @param intf USB interface structure
264 static void if_usb_disconnect(struct usb_interface *intf)
266 struct if_usb_card *cardp = usb_get_intfdata(intf);
267 struct lbs_private *priv = (struct lbs_private *) cardp->priv;
269 lbs_deb_enter(LBS_DEB_MAIN);
271 cardp->surprise_removed = 1;
274 priv->surpriseremoved = 1;
276 lbs_remove_card(priv);
279 /* Unlink and free urb */
282 usb_set_intfdata(intf, NULL);
283 usb_put_dev(interface_to_usbdev(intf));
285 lbs_deb_leave(LBS_DEB_MAIN);
289 * @brief This function download FW
290 * @param priv pointer to struct lbs_private
293 static int if_usb_send_fw_pkt(struct if_usb_card *cardp)
295 struct fwdata *fwdata = cardp->ep_out_buf;
296 uint8_t *firmware = cardp->fw->data;
298 /* If we got a CRC failure on the last block, back
300 if (!cardp->CRC_OK) {
301 cardp->totalbytes = cardp->fwlastblksent;
305 lbs_deb_usb2(&cardp->udev->dev, "totalbytes = %d\n",
308 /* struct fwdata (which we sent to the card) has an
309 extra __le32 field in between the header and the data,
310 which is not in the struct fwheader in the actual
311 firmware binary. Insert the seqnum in the middle... */
312 memcpy(&fwdata->hdr, &firmware[cardp->totalbytes],
313 sizeof(struct fwheader));
315 cardp->fwlastblksent = cardp->totalbytes;
316 cardp->totalbytes += sizeof(struct fwheader);
318 memcpy(fwdata->data, &firmware[cardp->totalbytes],
319 le32_to_cpu(fwdata->hdr.datalength));
321 lbs_deb_usb2(&cardp->udev->dev, "Data length = %d\n",
322 le32_to_cpu(fwdata->hdr.datalength));
324 fwdata->seqnum = cpu_to_le32(++cardp->fwseqnum);
325 cardp->totalbytes += le32_to_cpu(fwdata->hdr.datalength);
327 usb_tx_block(cardp, cardp->ep_out_buf, sizeof(struct fwdata) +
328 le32_to_cpu(fwdata->hdr.datalength));
330 if (fwdata->hdr.dnldcmd == cpu_to_le32(FW_HAS_DATA_TO_RECV)) {
331 lbs_deb_usb2(&cardp->udev->dev, "There are data to follow\n");
332 lbs_deb_usb2(&cardp->udev->dev, "seqnum = %d totalbytes = %d\n",
333 cardp->fwseqnum, cardp->totalbytes);
334 } else if (fwdata->hdr.dnldcmd == cpu_to_le32(FW_HAS_LAST_BLOCK)) {
335 lbs_deb_usb2(&cardp->udev->dev, "Host has finished FW downloading\n");
336 lbs_deb_usb2(&cardp->udev->dev, "Donwloading FW JUMP BLOCK\n");
338 cardp->fwfinalblk = 1;
341 lbs_deb_usb2(&cardp->udev->dev, "Firmware download done; size %d\n",
347 static int if_usb_reset_device(struct if_usb_card *cardp)
349 struct cmd_ds_command *cmd = cardp->ep_out_buf + 4;
352 lbs_deb_enter(LBS_DEB_USB);
354 *(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_REQUEST);
356 cmd->command = cpu_to_le16(CMD_802_11_RESET);
357 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
358 cmd->result = cpu_to_le16(0);
359 cmd->seqnum = cpu_to_le16(0x5a5a);
360 cmd->params.reset.action = cpu_to_le16(CMD_ACT_HALT);
361 usb_tx_block(cardp, cardp->ep_out_buf, 4 + S_DS_GEN + sizeof(struct cmd_ds_802_11_reset));
364 ret = usb_reset_device(cardp->udev);
367 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
373 * @brief This function transfer the data to the device.
374 * @param priv pointer to struct lbs_private
375 * @param payload pointer to payload data
376 * @param nb data length
379 static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload, uint16_t nb)
383 /* check if device is removed */
384 if (cardp->surprise_removed) {
385 lbs_deb_usbd(&cardp->udev->dev, "Device removed\n");
389 usb_fill_bulk_urb(cardp->tx_urb, cardp->udev,
390 usb_sndbulkpipe(cardp->udev,
392 payload, nb, if_usb_write_bulk_callback, cardp);
394 cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET;
396 if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
397 lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed: %d\n", ret);
400 lbs_deb_usb2(&cardp->udev->dev, "usb_submit_urb success\n");
408 static int __if_usb_submit_rx_urb(struct if_usb_card *cardp,
409 void (*callbackfn)(struct urb *urb))
414 if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
415 lbs_pr_err("No free skb\n");
421 /* Fill the receive configuration URB and initialise the Rx call back */
422 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
423 usb_rcvbulkpipe(cardp->udev, cardp->ep_in),
424 (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET),
425 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn,
428 cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
430 lbs_deb_usb2(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb);
431 if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) {
432 lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed: %d\n", ret);
434 cardp->rx_skb = NULL;
437 lbs_deb_usb2(&cardp->udev->dev, "Submit Rx URB success\n");
445 static int if_usb_submit_rx_urb_fwload(struct if_usb_card *cardp)
447 return __if_usb_submit_rx_urb(cardp, &if_usb_receive_fwload);
450 static int if_usb_submit_rx_urb(struct if_usb_card *cardp)
452 return __if_usb_submit_rx_urb(cardp, &if_usb_receive);
455 static void if_usb_receive_fwload(struct urb *urb)
457 struct if_usb_card *cardp = urb->context;
458 struct sk_buff *skb = cardp->rx_skb;
459 struct fwsyncheader *syncfwheader;
460 struct bootcmdresp bootcmdresp;
463 lbs_deb_usbd(&cardp->udev->dev,
464 "URB status is failed during fw load\n");
469 if (cardp->fwdnldover) {
470 __le32 *tmp = (__le32 *)(skb->data + IPFIELD_ALIGN_OFFSET);
472 if (tmp[0] == cpu_to_le32(CMD_TYPE_INDICATION) &&
473 tmp[1] == cpu_to_le32(MACREG_INT_CODE_FIRMWARE_READY)) {
474 lbs_pr_info("Firmware ready event received\n");
475 wake_up(&cardp->fw_wq);
477 lbs_deb_usb("Waiting for confirmation; got %x %x\n",
478 le32_to_cpu(tmp[0]), le32_to_cpu(tmp[1]));
479 if_usb_submit_rx_urb_fwload(cardp);
484 if (cardp->bootcmdresp <= 0) {
485 memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET,
486 sizeof(bootcmdresp));
488 if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) {
490 if_usb_submit_rx_urb_fwload(cardp);
491 cardp->bootcmdresp = 1;
492 lbs_deb_usbd(&cardp->udev->dev,
493 "Received valid boot command response\n");
496 if (bootcmdresp.magic != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) {
497 if (bootcmdresp.magic == cpu_to_le32(CMD_TYPE_REQUEST) ||
498 bootcmdresp.magic == cpu_to_le32(CMD_TYPE_DATA) ||
499 bootcmdresp.magic == cpu_to_le32(CMD_TYPE_INDICATION)) {
500 if (!cardp->bootcmdresp)
501 lbs_pr_info("Firmware already seems alive; resetting\n");
502 cardp->bootcmdresp = -1;
504 lbs_pr_info("boot cmd response wrong magic number (0x%x)\n",
505 le32_to_cpu(bootcmdresp.magic));
507 } else if (bootcmdresp.cmd != BOOT_CMD_FW_BY_USB) {
508 lbs_pr_info("boot cmd response cmd_tag error (%d)\n",
510 } else if (bootcmdresp.result != BOOT_CMD_RESP_OK) {
511 lbs_pr_info("boot cmd response result error (%d)\n",
514 cardp->bootcmdresp = 1;
515 lbs_deb_usbd(&cardp->udev->dev,
516 "Received valid boot command response\n");
519 if_usb_submit_rx_urb_fwload(cardp);
523 syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
525 lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
530 memcpy(syncfwheader, skb->data + IPFIELD_ALIGN_OFFSET,
531 sizeof(struct fwsyncheader));
533 if (!syncfwheader->cmd) {
534 lbs_deb_usb2(&cardp->udev->dev, "FW received Blk with correct CRC\n");
535 lbs_deb_usb2(&cardp->udev->dev, "FW received Blk seqnum = %d\n",
536 le32_to_cpu(syncfwheader->seqnum));
539 lbs_deb_usbd(&cardp->udev->dev, "FW received Blk with CRC error\n");
545 /* reschedule timer for 200ms hence */
546 mod_timer(&cardp->fw_timeout, jiffies + (HZ/5));
548 if (cardp->fwfinalblk) {
549 cardp->fwdnldover = 1;
553 if_usb_send_fw_pkt(cardp);
556 if_usb_submit_rx_urb_fwload(cardp);
563 #define MRVDRV_MIN_PKT_LEN 30
565 static inline void process_cmdtypedata(int recvlength, struct sk_buff *skb,
566 struct if_usb_card *cardp,
567 struct lbs_private *priv)
569 if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + MESSAGE_HEADER_LEN
570 || recvlength < MRVDRV_MIN_PKT_LEN) {
571 lbs_deb_usbd(&cardp->udev->dev, "Packet length is Invalid\n");
576 skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
577 skb_put(skb, recvlength);
578 skb_pull(skb, MESSAGE_HEADER_LEN);
580 lbs_process_rxed_packet(priv, skb);
583 static inline void process_cmdrequest(int recvlength, uint8_t *recvbuff,
585 struct if_usb_card *cardp,
586 struct lbs_private *priv)
590 if (recvlength > LBS_CMD_BUFFER_SIZE) {
591 lbs_deb_usbd(&cardp->udev->dev,
592 "The receive buffer is too large\n");
600 spin_lock(&priv->driver_lock);
602 i = (priv->resp_idx == 0) ? 1 : 0;
603 BUG_ON(priv->resp_len[i]);
604 priv->resp_len[i] = (recvlength - MESSAGE_HEADER_LEN);
605 memcpy(priv->resp_buf[i], recvbuff + MESSAGE_HEADER_LEN,
608 lbs_notify_command_response(priv, i);
610 spin_unlock(&priv->driver_lock);
612 lbs_deb_usbd(&cardp->udev->dev,
613 "Wake up main thread to handle cmd response\n");
617 * @brief This function reads of the packet into the upload buff,
618 * wake up the main thread and initialise the Rx callack.
620 * @param urb pointer to struct urb
623 static void if_usb_receive(struct urb *urb)
625 struct if_usb_card *cardp = urb->context;
626 struct sk_buff *skb = cardp->rx_skb;
627 struct lbs_private *priv = cardp->priv;
628 int recvlength = urb->actual_length;
629 uint8_t *recvbuff = NULL;
630 uint32_t recvtype = 0;
631 __le32 *pkt = (__le32 *)(skb->data + IPFIELD_ALIGN_OFFSET);
634 lbs_deb_enter(LBS_DEB_USB);
638 lbs_deb_usbd(&cardp->udev->dev, "RX URB failed: %d\n",
644 recvbuff = skb->data + IPFIELD_ALIGN_OFFSET;
645 recvtype = le32_to_cpu(pkt[0]);
646 lbs_deb_usbd(&cardp->udev->dev,
647 "Recv length = 0x%x, Recv type = 0x%X\n",
648 recvlength, recvtype);
649 } else if (urb->status) {
656 process_cmdtypedata(recvlength, skb, cardp, priv);
659 case CMD_TYPE_REQUEST:
660 process_cmdrequest(recvlength, recvbuff, skb, cardp, priv);
663 case CMD_TYPE_INDICATION:
665 event = le32_to_cpu(pkt[1]);
666 lbs_deb_usbd(&cardp->udev->dev, "**EVENT** 0x%X\n", event);
669 /* Icky undocumented magic special case */
670 if (event & 0xffff0000) {
671 u32 trycount = (event & 0xffff0000) >> 16;
673 lbs_send_tx_feedback(priv, trycount);
675 lbs_queue_event(priv, event & 0xFF);
679 lbs_deb_usbd(&cardp->udev->dev, "Unknown command type 0x%X\n",
686 if_usb_submit_rx_urb(cardp);
688 lbs_deb_leave(LBS_DEB_USB);
692 * @brief This function downloads data to FW
693 * @param priv pointer to struct lbs_private structure
694 * @param type type of data
695 * @param buf pointer to data buffer
696 * @param len number of bytes
699 static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
700 uint8_t *payload, uint16_t nb)
702 struct if_usb_card *cardp = priv->card;
704 lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type);
705 lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb);
707 if (type == MVMS_CMD) {
708 *(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_REQUEST);
709 priv->dnld_sent = DNLD_CMD_SENT;
711 *(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_DATA);
712 priv->dnld_sent = DNLD_DATA_SENT;
715 memcpy((cardp->ep_out_buf + MESSAGE_HEADER_LEN), payload, nb);
717 return usb_tx_block(cardp, cardp->ep_out_buf, nb + MESSAGE_HEADER_LEN);
721 * @brief This function issues Boot command to the Boot2 code
722 * @param ivalue 1:Boot from FW by USB-Download
723 * 2:Boot from FW in EEPROM
726 static int if_usb_issue_boot_command(struct if_usb_card *cardp, int ivalue)
728 struct bootcmd *bootcmd = cardp->ep_out_buf;
730 /* Prepare command */
731 bootcmd->magic = cpu_to_le32(BOOT_CMD_MAGIC_NUMBER);
732 bootcmd->cmd = ivalue;
733 memset(bootcmd->pad, 0, sizeof(bootcmd->pad));
736 usb_tx_block(cardp, cardp->ep_out_buf, sizeof(*bootcmd));
743 * @brief This function checks the validity of Boot2/FW image.
745 * @param data pointer to image
749 static int check_fwfile_format(uint8_t *data, uint32_t totlen)
751 uint32_t bincmd, exit;
752 uint32_t blksize, offset, len;
759 struct fwheader *fwh = (void *)data;
761 bincmd = le32_to_cpu(fwh->dnldcmd);
762 blksize = le32_to_cpu(fwh->datalength);
764 case FW_HAS_DATA_TO_RECV:
765 offset = sizeof(struct fwheader) + blksize;
771 case FW_HAS_LAST_BLOCK:
782 lbs_pr_err("firmware file format check FAIL\n");
784 lbs_deb_fw("firmware file format check PASS\n");
790 static int if_usb_prog_firmware(struct if_usb_card *cardp)
793 static int reset_count = 10;
796 lbs_deb_enter(LBS_DEB_USB);
798 if ((ret = request_firmware(&cardp->fw, lbs_fw_name,
799 &cardp->udev->dev)) < 0) {
800 lbs_pr_err("request_firmware() failed with %#x\n", ret);
801 lbs_pr_err("firmware %s not found\n", lbs_fw_name);
805 if (check_fwfile_format(cardp->fw->data, cardp->fw->size))
809 if (if_usb_submit_rx_urb_fwload(cardp) < 0) {
810 lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n");
815 cardp->bootcmdresp = 0;
819 /* Issue Boot command = 1, Boot from Download-FW */
820 if_usb_issue_boot_command(cardp, BOOT_CMD_FW_BY_USB);
821 /* wait for command response */
824 msleep_interruptible(100);
825 } while (cardp->bootcmdresp == 0 && j < 10);
826 } while (cardp->bootcmdresp == 0 && i < 5);
828 if (cardp->bootcmdresp <= 0) {
829 if (--reset_count >= 0) {
830 if_usb_reset_device(cardp);
838 cardp->totalbytes = 0;
839 cardp->fwlastblksent = 0;
841 cardp->fwdnldover = 0;
842 cardp->fwseqnum = -1;
843 cardp->totalbytes = 0;
844 cardp->fwfinalblk = 0;
846 /* Send the first firmware packet... */
847 if_usb_send_fw_pkt(cardp);
849 /* ... and wait for the process to complete */
850 wait_event_interruptible(cardp->fw_wq, cardp->surprise_removed || cardp->fwdnldover);
852 del_timer_sync(&cardp->fw_timeout);
853 usb_kill_urb(cardp->rx_urb);
855 if (!cardp->fwdnldover) {
856 lbs_pr_info("failed to load fw, resetting device!\n");
857 if (--reset_count >= 0) {
858 if_usb_reset_device(cardp);
862 lbs_pr_info("FW download failure, time = %d ms\n", i * 100);
868 release_firmware(cardp->fw);
872 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
878 static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
880 struct if_usb_card *cardp = usb_get_intfdata(intf);
881 struct lbs_private *priv = cardp->priv;
884 lbs_deb_enter(LBS_DEB_USB);
886 if (priv->psstate != PS_STATE_FULL_POWER)
889 ret = lbs_suspend(priv);
893 /* Unlink tx & rx urb */
894 usb_kill_urb(cardp->tx_urb);
895 usb_kill_urb(cardp->rx_urb);
898 lbs_deb_leave(LBS_DEB_USB);
902 static int if_usb_resume(struct usb_interface *intf)
904 struct if_usb_card *cardp = usb_get_intfdata(intf);
905 struct lbs_private *priv = cardp->priv;
907 lbs_deb_enter(LBS_DEB_USB);
909 if_usb_submit_rx_urb(cardp);
913 lbs_deb_leave(LBS_DEB_USB);
917 #define if_usb_suspend NULL
918 #define if_usb_resume NULL
921 static struct usb_driver if_usb_driver = {
923 .probe = if_usb_probe,
924 .disconnect = if_usb_disconnect,
925 .id_table = if_usb_table,
926 .suspend = if_usb_suspend,
927 .resume = if_usb_resume,
930 static int __init if_usb_init_module(void)
934 lbs_deb_enter(LBS_DEB_MAIN);
936 ret = usb_register(&if_usb_driver);
938 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
942 static void __exit if_usb_exit_module(void)
944 lbs_deb_enter(LBS_DEB_MAIN);
946 usb_deregister(&if_usb_driver);
948 lbs_deb_leave(LBS_DEB_MAIN);
951 module_init(if_usb_init_module);
952 module_exit(if_usb_exit_module);
954 MODULE_DESCRIPTION("8388 USB WLAN Driver");
955 MODULE_AUTHOR("Marvell International Ltd. and Red Hat, Inc.");
956 MODULE_LICENSE("GPL");