~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/wireless/libertas/if_usb.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
  * This file contains functions used in USB interface module.
3
 
  */
 
1
/*
 
2
 * This file contains functions used in USB interface module.
 
3
 */
 
4
 
 
5
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
6
 
4
7
#include <linux/delay.h>
5
8
#include <linux/moduleparam.h>
6
9
#include <linux/firmware.h>
66
69
 
67
70
/* sysfs hooks */
68
71
 
69
 
/**
 
72
/*
70
73
 *  Set function to write firmware to device's persistent memory
71
74
 */
72
75
static ssize_t if_usb_firmware_set(struct device *dev,
85
88
        return ret;
86
89
}
87
90
 
88
 
/**
 
91
/*
89
92
 * lbs_flash_fw attribute to be exported per ethX interface through sysfs
90
93
 * (/sys/class/net/ethX/lbs_flash_fw).  Use this like so to write firmware to
91
94
 * the device's persistent memory:
94
97
static DEVICE_ATTR(lbs_flash_fw, 0200, NULL, if_usb_firmware_set);
95
98
 
96
99
/**
97
 
 *  Set function to write firmware to device's persistent memory
 
100
 * if_usb_boot2_set - write firmware to device's persistent memory
 
101
 *
 
102
 * @dev: target device
 
103
 * @attr: device attributes
 
104
 * @buf: firmware buffer to write
 
105
 * @count: number of bytes to write
 
106
 *
 
107
 * returns: number of bytes written or negative error code
98
108
 */
99
109
static ssize_t if_usb_boot2_set(struct device *dev,
100
110
                struct device_attribute *attr, const char *buf, size_t count)
112
122
        return ret;
113
123
}
114
124
 
115
 
/**
 
125
/*
116
126
 * lbs_flash_boot2 attribute to be exported per ethX interface through sysfs
117
127
 * (/sys/class/net/ethX/lbs_flash_boot2).  Use this like so to write firmware
118
128
 * to the device's persistent memory:
121
131
static DEVICE_ATTR(lbs_flash_boot2, 0200, NULL, if_usb_boot2_set);
122
132
 
123
133
/**
124
 
 *  @brief  call back function to handle the status of the URB
125
 
 *  @param urb          pointer to urb structure
126
 
 *  @return             N/A
 
134
 * if_usb_write_bulk_callback - callback function to handle the status
 
135
 * of the URB
 
136
 * @urb:        pointer to &urb structure
 
137
 * returns:     N/A
127
138
 */
128
139
static void if_usb_write_bulk_callback(struct urb *urb)
129
140
{
145
156
                        lbs_host_to_card_done(priv);
146
157
        } else {
147
158
                /* print the failure status number for debug */
148
 
                lbs_pr_info("URB in failure status: %d\n", urb->status);
 
159
                pr_info("URB in failure status: %d\n", urb->status);
149
160
        }
150
161
}
151
162
 
152
163
/**
153
 
 *  @brief  free tx/rx urb, skb and rx buffer
154
 
 *  @param cardp        pointer if_usb_card
155
 
 *  @return             N/A
 
164
 * if_usb_free - free tx/rx urb, skb and rx buffer
 
165
 * @cardp:      pointer to &if_usb_card
 
166
 * returns:     N/A
156
167
 */
157
168
static void if_usb_free(struct if_usb_card *cardp)
158
169
{
195
206
        wake_method.hdr.size = cpu_to_le16(sizeof(wake_method));
196
207
        wake_method.action = cpu_to_le16(CMD_ACT_GET);
197
208
        if (lbs_cmd_with_response(priv, CMD_802_11_FW_WAKE_METHOD, &wake_method)) {
198
 
                lbs_pr_info("Firmware does not seem to support PS mode\n");
 
209
                netdev_info(priv->dev, "Firmware does not seem to support PS mode\n");
199
210
                priv->fwcapinfo &= ~FW_CAPINFO_PS;
200
211
        } else {
201
212
                if (le16_to_cpu(wake_method.method) == CMD_WAKE_METHOD_COMMAND_INT) {
204
215
                        /* The versions which boot up this way don't seem to
205
216
                           work even if we set it to the command interrupt */
206
217
                        priv->fwcapinfo &= ~FW_CAPINFO_PS;
207
 
                        lbs_pr_info("Firmware doesn't wake via command interrupt; disabling PS mode\n");
 
218
                        netdev_info(priv->dev,
 
219
                                    "Firmware doesn't wake via command interrupt; disabling PS mode\n");
208
220
                }
209
221
        }
210
222
}
216
228
        if (cardp->fwdnldover) {
217
229
                lbs_deb_usb("Download complete, no event. Assuming success\n");
218
230
        } else {
219
 
                lbs_pr_err("Download timed out\n");
 
231
                pr_err("Download timed out\n");
220
232
                cardp->surprise_removed = 1;
221
233
        }
222
234
        wake_up(&cardp->fw_wq);
231
243
#endif
232
244
 
233
245
/**
234
 
 *  @brief sets the configuration values
235
 
 *  @param ifnum        interface number
236
 
 *  @param id           pointer to usb_device_id
237
 
 *  @return             0 on success, error code on failure
 
246
 * if_usb_probe - sets the configuration values
 
247
 * @intf:       &usb_interface pointer
 
248
 * @id: pointer to usb_device_id
 
249
 * returns:     0 on success, error code on failure
238
250
 */
239
251
static int if_usb_probe(struct usb_interface *intf,
240
252
                        const struct usb_device_id *id)
250
262
 
251
263
        cardp = kzalloc(sizeof(struct if_usb_card), GFP_KERNEL);
252
264
        if (!cardp) {
253
 
                lbs_pr_err("Out of memory allocating private data.\n");
 
265
                pr_err("Out of memory allocating private data\n");
254
266
                goto error;
255
267
        }
256
268
 
340
352
        usb_set_intfdata(intf, cardp);
341
353
 
342
354
        if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_fw))
343
 
                lbs_pr_err("cannot register lbs_flash_fw attribute\n");
 
355
                netdev_err(priv->dev,
 
356
                           "cannot register lbs_flash_fw attribute\n");
344
357
 
345
358
        if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_boot2))
346
 
                lbs_pr_err("cannot register lbs_flash_boot2 attribute\n");
 
359
                netdev_err(priv->dev,
 
360
                           "cannot register lbs_flash_boot2 attribute\n");
347
361
 
348
362
        /*
349
363
         * EHS_REMOVE_WAKEUP is not supported on all versions of the firmware.
366
380
}
367
381
 
368
382
/**
369
 
 *  @brief free resource and cleanup
370
 
 *  @param intf         USB interface structure
371
 
 *  @return             N/A
 
383
 * if_usb_disconnect - free resource and cleanup
 
384
 * @intf:       USB interface structure
 
385
 * returns:     N/A
372
386
 */
373
387
static void if_usb_disconnect(struct usb_interface *intf)
374
388
{
398
412
}
399
413
 
400
414
/**
401
 
 *  @brief  This function download FW
402
 
 *  @param priv         pointer to struct lbs_private
403
 
 *  @return             0
 
415
 * if_usb_send_fw_pkt - download FW
 
416
 * @cardp:      pointer to &struct if_usb_card
 
417
 * returns:     0
404
418
 */
405
419
static int if_usb_send_fw_pkt(struct if_usb_card *cardp)
406
420
{
486
500
}
487
501
 
488
502
/**
489
 
 *  @brief This function transfer the data to the device.
490
 
 *  @param priv         pointer to struct lbs_private
491
 
 *  @param payload      pointer to payload data
492
 
 *  @param nb           data length
493
 
 *  @return             0 or -1
 
503
 *  usb_tx_block - transfer the data to the device
 
504
 *  @cardp:     pointer to &struct if_usb_card
 
505
 *  @payload:   pointer to payload data
 
506
 *  @nb:        data length
 
507
 *  returns:    0 for success or negative error code
494
508
 */
495
509
static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload, uint16_t nb)
496
510
{
528
542
        int ret = -1;
529
543
 
530
544
        if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
531
 
                lbs_pr_err("No free skb\n");
 
545
                pr_err("No free skb\n");
532
546
                goto rx_ret;
533
547
        }
534
548
 
587
601
 
588
602
                if (tmp[0] == cpu_to_le32(CMD_TYPE_INDICATION) &&
589
603
                    tmp[1] == cpu_to_le32(MACREG_INT_CODE_FIRMWARE_READY)) {
590
 
                        lbs_pr_info("Firmware ready event received\n");
 
604
                        pr_info("Firmware ready event received\n");
591
605
                        wake_up(&cardp->fw_wq);
592
606
                } else {
593
607
                        lbs_deb_usb("Waiting for confirmation; got %x %x\n",
614
628
                            bootcmdresp.magic == cpu_to_le32(CMD_TYPE_DATA) ||
615
629
                            bootcmdresp.magic == cpu_to_le32(CMD_TYPE_INDICATION)) {
616
630
                                if (!cardp->bootcmdresp)
617
 
                                        lbs_pr_info("Firmware already seems alive; resetting\n");
 
631
                                        pr_info("Firmware already seems alive; resetting\n");
618
632
                                cardp->bootcmdresp = -1;
619
633
                        } else {
620
 
                                lbs_pr_info("boot cmd response wrong magic number (0x%x)\n",
 
634
                                pr_info("boot cmd response wrong magic number (0x%x)\n",
621
635
                                            le32_to_cpu(bootcmdresp.magic));
622
636
                        }
623
637
                } else if ((bootcmdresp.cmd != BOOT_CMD_FW_BY_USB) &&
624
638
                           (bootcmdresp.cmd != BOOT_CMD_UPDATE_FW) &&
625
639
                           (bootcmdresp.cmd != BOOT_CMD_UPDATE_BOOT2)) {
626
 
                        lbs_pr_info("boot cmd response cmd_tag error (%d)\n",
627
 
                                    bootcmdresp.cmd);
 
640
                        pr_info("boot cmd response cmd_tag error (%d)\n",
 
641
                                bootcmdresp.cmd);
628
642
                } else if (bootcmdresp.result != BOOT_CMD_RESP_OK) {
629
 
                        lbs_pr_info("boot cmd response result error (%d)\n",
630
 
                                    bootcmdresp.result);
 
643
                        pr_info("boot cmd response result error (%d)\n",
 
644
                                bootcmdresp.result);
631
645
                } else {
632
646
                        cardp->bootcmdresp = 1;
633
647
                        lbs_deb_usbd(&cardp->udev->dev,
727
741
}
728
742
 
729
743
/**
730
 
 *  @brief This function reads of the packet into the upload buff,
731
 
 *  wake up the main thread and initialise the Rx callack.
 
744
 *  if_usb_receive - read the packet into the upload buffer,
 
745
 *  wake up the main thread and initialise the Rx callack
732
746
 *
733
 
 *  @param urb          pointer to struct urb
734
 
 *  @return             N/A
 
747
 *  @urb:       pointer to &struct urb
 
748
 *  returns:    N/A
735
749
 */
736
750
static void if_usb_receive(struct urb *urb)
737
751
{
802
816
}
803
817
 
804
818
/**
805
 
 *  @brief This function downloads data to FW
806
 
 *  @param priv         pointer to struct lbs_private structure
807
 
 *  @param type         type of data
808
 
 *  @param buf          pointer to data buffer
809
 
 *  @param len          number of bytes
810
 
 *  @return             0 or -1
 
819
 *  if_usb_host_to_card - downloads data to FW
 
820
 *  @priv:      pointer to &struct lbs_private structure
 
821
 *  @type:      type of data
 
822
 *  @payload:   pointer to data buffer
 
823
 *  @nb:        number of bytes
 
824
 *  returns:    0 for success or negative error code
811
825
 */
812
826
static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
813
827
                               uint8_t *payload, uint16_t nb)
831
845
}
832
846
 
833
847
/**
834
 
 *  @brief This function issues Boot command to the Boot2 code
835
 
 *  @param ivalue   1:Boot from FW by USB-Download
836
 
 *                  2:Boot from FW in EEPROM
837
 
 *  @return             0
 
848
 *  if_usb_issue_boot_command - issues Boot command to the Boot2 code
 
849
 *  @cardp:     pointer to &if_usb_card
 
850
 *  @ivalue:    1:Boot from FW by USB-Download
 
851
 *              2:Boot from FW in EEPROM
 
852
 *  returns:    0 for success or negative error code
838
853
 */
839
854
static int if_usb_issue_boot_command(struct if_usb_card *cardp, int ivalue)
840
855
{
853
868
 
854
869
 
855
870
/**
856
 
 *  @brief This function checks the validity of Boot2/FW image.
 
871
 *  check_fwfile_format - check the validity of Boot2/FW image
857
872
 *
858
 
 *  @param data              pointer to image
859
 
 *         len               image length
860
 
 *  @return     0 or -1
 
873
 *  @data:      pointer to image
 
874
 *  @totlen:    image length
 
875
 *  returns:     0 (good) or 1 (failure)
861
876
 */
862
877
static int check_fwfile_format(const uint8_t *data, uint32_t totlen)
863
878
{
892
907
        } while (!exit);
893
908
 
894
909
        if (ret)
895
 
                lbs_pr_err("firmware file format check FAIL\n");
 
910
                pr_err("firmware file format check FAIL\n");
896
911
        else
897
912
                lbs_deb_fw("firmware file format check PASS\n");
898
913
 
901
916
 
902
917
 
903
918
/**
904
 
*  @brief This function programs the firmware subject to cmd
 
919
*  if_usb_prog_firmware - programs the firmware subject to cmd
905
920
*
906
 
*  @param cardp             the if_usb_card descriptor
907
 
*         fwname            firmware or boot2 image file name
908
 
*         cmd               either BOOT_CMD_FW_BY_USB, BOOT_CMD_UPDATE_FW,
909
 
*                           or BOOT_CMD_UPDATE_BOOT2.
910
 
*  @return     0 or error code
 
921
*  @cardp:      the if_usb_card descriptor
 
922
*  @fwname:     firmware or boot2 image file name
 
923
*  @cmd:        either BOOT_CMD_FW_BY_USB, BOOT_CMD_UPDATE_FW,
 
924
*               or BOOT_CMD_UPDATE_BOOT2.
 
925
*  returns:     0 or error code
911
926
*/
912
927
static int if_usb_prog_firmware(struct if_usb_card *cardp,
913
928
                                const char *fwname, int cmd)
989
1004
 
990
1005
        ret = get_fw(cardp, fwname);
991
1006
        if (ret) {
992
 
                lbs_pr_err("failed to find firmware (%d)\n", ret);
 
1007
                pr_err("failed to find firmware (%d)\n", ret);
993
1008
                goto done;
994
1009
        }
995
1010
 
1064
1079
        usb_kill_urb(cardp->rx_urb);
1065
1080
 
1066
1081
        if (!cardp->fwdnldover) {
1067
 
                lbs_pr_info("failed to load fw, resetting device!\n");
 
1082
                pr_info("failed to load fw, resetting device!\n");
1068
1083
                if (--reset_count >= 0) {
1069
1084
                        if_usb_reset_device(cardp);
1070
1085
                        goto restart;
1071
1086
                }
1072
1087
 
1073
 
                lbs_pr_info("FW download failure, time = %d ms\n", i * 100);
 
1088
                pr_info("FW download failure, time = %d ms\n", i * 100);
1074
1089
                ret = -EIO;
1075
1090
                goto release_fw;
1076
1091
        }