blob: de7a2e2babe656f9264196a7e8ec4e1c6f445eb9 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains functions used in USB interface module.
3 */
4#include <linux/delay.h>
Holger Schurig084708b2007-05-25 12:37:58 -04005#include <linux/moduleparam.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02006#include <linux/firmware.h>
7#include <linux/netdevice.h>
Holger Schurig435a1ac2007-05-25 12:41:52 -04008#include <linux/list.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009#include <linux/usb.h>
10
Holger Schurigec3eef22007-05-25 12:49:10 -040011#define DRV_NAME "usb8xxx"
12
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020013#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020014#include "decl.h"
15#include "defs.h"
16#include "dev.h"
17#include "if_usb.h"
18
19#define MESSAGE_HEADER_LEN 4
20
21static const char usbdriver_name[] = "usb8xxx";
Holger Schurig084708b2007-05-25 12:37:58 -040022static u8 *default_fw_name = "usb8388.bin";
23
24char *libertas_fw_name = NULL;
25module_param_named(fw_name, libertas_fw_name, charp, 0644);
26
Holger Schurig435a1ac2007-05-25 12:41:52 -040027/*
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()
33*/
34static LIST_HEAD(usb_devices);
Holger Schurig3874d0f2007-05-25 12:01:42 -040035
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020036static struct usb_device_id if_usb_table[] = {
37 /* Enter the device signature inside */
Holger Schurig66fcc552007-05-25 00:11:58 -040038 { USB_DEVICE(0x1286, 0x2001) },
39 { USB_DEVICE(0x05a3, 0x8388) },
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020040 {} /* Terminating entry */
41};
42
43MODULE_DEVICE_TABLE(usb, if_usb_table);
44
45static void if_usb_receive(struct urb *urb);
46static void if_usb_receive_fwload(struct urb *urb);
Holger Schurig435a1ac2007-05-25 12:41:52 -040047static int if_usb_reset_device(wlan_private *priv);
Holger Schurig208fdd22007-05-25 12:17:06 -040048static int if_usb_register_dev(wlan_private * priv);
49static int if_usb_unregister_dev(wlan_private *);
50static int if_usb_prog_firmware(wlan_private *);
51static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb);
52static int if_usb_get_int_status(wlan_private * priv, u8 *);
53static int if_usb_read_event_cause(wlan_private *);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020054
55/**
56 * @brief call back function to handle the status of the URB
57 * @param urb pointer to urb structure
58 * @return N/A
59 */
60static void if_usb_write_bulk_callback(struct urb *urb)
61{
62 wlan_private *priv = (wlan_private *) (urb->context);
63 wlan_adapter *adapter = priv->adapter;
Holger Schurig634b8f42007-05-25 13:05:16 -040064 struct net_device *dev = priv->dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020065
66 /* handle the transmission complete validations */
67
68 if (urb->status != 0) {
69 /* print the failure status number for debug */
Luis Carlos Cobob46794d2007-05-25 13:10:18 -040070 lbs_pr_info("URB in failure status: %d\n", urb->status);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020071 } else {
Holger Schurig9012b282007-05-25 11:27:16 -040072 /*
73 lbs_deb_usbd(&urb->dev->dev, "URB status is successfull\n");
74 lbs_deb_usbd(&urb->dev->dev, "Actual length transmitted %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 urb->actual_length);
Holger Schurig9012b282007-05-25 11:27:16 -040076 */
Holger Schurig634b8f42007-05-25 13:05:16 -040077 priv->dnld_sent = DNLD_RES_RECEIVED;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020078 /* Wake main thread if commands are pending */
79 if (!adapter->cur_cmd)
80 wake_up_interruptible(&priv->mainthread.waitq);
Javier Cardona51d84f52007-05-25 12:06:56 -040081 if ((adapter->connect_status == libertas_connected)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020082 netif_wake_queue(dev);
Javier Cardona51d84f52007-05-25 12:06:56 -040083 netif_wake_queue(priv->mesh_dev);
84 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085 }
86
87 return;
88}
89
90/**
91 * @brief free tx/rx urb, skb and rx buffer
92 * @param cardp pointer usb_card_rec
93 * @return N/A
94 */
95void if_usb_free(struct usb_card_rec *cardp)
96{
Holger Schurig9012b282007-05-25 11:27:16 -040097 lbs_deb_enter(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020098
99 /* Unlink tx & rx urb */
100 usb_kill_urb(cardp->tx_urb);
101 usb_kill_urb(cardp->rx_urb);
102
103 usb_free_urb(cardp->tx_urb);
104 cardp->tx_urb = NULL;
105
106 usb_free_urb(cardp->rx_urb);
107 cardp->rx_urb = NULL;
108
109 kfree(cardp->bulk_out_buffer);
110 cardp->bulk_out_buffer = NULL;
111
Holger Schurig9012b282007-05-25 11:27:16 -0400112 lbs_deb_leave(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200113}
114
115/**
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
120 */
121static int if_usb_probe(struct usb_interface *intf,
122 const struct usb_device_id *id)
123{
124 struct usb_device *udev;
125 struct usb_host_interface *iface_desc;
126 struct usb_endpoint_descriptor *endpoint;
Holger Schurig78523da2007-05-25 11:49:19 -0400127 wlan_private *priv;
Holger Schurig435a1ac2007-05-25 12:41:52 -0400128 struct usb_card_rec *cardp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129 int i;
130
131 udev = interface_to_usbdev(intf);
132
Holger Schurig435a1ac2007-05-25 12:41:52 -0400133 cardp = kzalloc(sizeof(struct usb_card_rec), GFP_KERNEL);
134 if (!cardp) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135 lbs_pr_err("Out of memory allocating private data.\n");
136 goto error;
137 }
138
Holger Schurig435a1ac2007-05-25 12:41:52 -0400139 cardp->udev = udev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140 iface_desc = intf->cur_altsetting;
141
Holger Schurig9012b282007-05-25 11:27:16 -0400142 lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200143 " bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n",
144 udev->descriptor.bcdUSB,
145 udev->descriptor.bDeviceClass,
146 udev->descriptor.bDeviceSubClass,
147 udev->descriptor.bDeviceProtocol);
148
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 */
Holger Schurig9012b282007-05-25 11:27:16 -0400155 lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156 endpoint->wMaxPacketSize);
157 if (!
Holger Schurig435a1ac2007-05-25 12:41:52 -0400158 (cardp->rx_urb =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200159 usb_alloc_urb(0, GFP_KERNEL))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400160 lbs_deb_usbd(&udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161 "Rx URB allocation failed\n");
162 goto dealloc;
163 }
Holger Schurig435a1ac2007-05-25 12:41:52 -0400164 cardp->rx_urb_recall = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200165
Holger Schurig435a1ac2007-05-25 12:41:52 -0400166 cardp->bulk_in_size =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200167 endpoint->wMaxPacketSize;
Holger Schurig435a1ac2007-05-25 12:41:52 -0400168 cardp->bulk_in_endpointAddr =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169 (endpoint->
170 bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
Holger Schurig9012b282007-05-25 11:27:16 -0400171 lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200172 endpoint->bEndpointAddress);
173 }
174
175 if (((endpoint->
176 bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
177 USB_DIR_OUT)
178 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
179 USB_ENDPOINT_XFER_BULK)) {
180 /* We found bulk out endpoint */
181 if (!
Holger Schurig435a1ac2007-05-25 12:41:52 -0400182 (cardp->tx_urb =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183 usb_alloc_urb(0, GFP_KERNEL))) {
Holger Schurig9012b282007-05-25 11:27:16 -0400184 lbs_deb_usbd(&udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 "Tx URB allocation failed\n");
186 goto dealloc;
187 }
188
Holger Schurig435a1ac2007-05-25 12:41:52 -0400189 cardp->bulk_out_size =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190 endpoint->wMaxPacketSize;
Holger Schurig9012b282007-05-25 11:27:16 -0400191 lbs_deb_usbd(&udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200192 "Bulk out size is %d\n",
193 endpoint->wMaxPacketSize);
Holger Schurig435a1ac2007-05-25 12:41:52 -0400194 cardp->bulk_out_endpointAddr =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195 endpoint->bEndpointAddress;
Holger Schurig9012b282007-05-25 11:27:16 -0400196 lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200197 endpoint->bEndpointAddress);
Holger Schurig435a1ac2007-05-25 12:41:52 -0400198 cardp->bulk_out_buffer =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200199 kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE,
200 GFP_KERNEL);
201
Holger Schurig435a1ac2007-05-25 12:41:52 -0400202 if (!cardp->bulk_out_buffer) {
Holger Schurig9012b282007-05-25 11:27:16 -0400203 lbs_deb_usbd(&udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204 "Could not allocate buffer\n");
205 goto dealloc;
206 }
207 }
208 }
209
Dan Williams7732ca42007-05-25 13:13:25 -0400210 if (!(priv = libertas_add_card(cardp, &udev->dev)))
Holger Schurig78523da2007-05-25 11:49:19 -0400211 goto dealloc;
Holger Schurig3874d0f2007-05-25 12:01:42 -0400212
Dan Williams7732ca42007-05-25 13:13:25 -0400213 if (libertas_add_mesh(priv, &udev->dev))
Marcelo Tosatti6a812152007-05-25 12:09:13 -0400214 goto err_add_mesh;
Javier Cardona51d84f52007-05-25 12:06:56 -0400215
Holger Schurig208fdd22007-05-25 12:17:06 -0400216 priv->hw_register_dev = if_usb_register_dev;
217 priv->hw_unregister_dev = if_usb_unregister_dev;
218 priv->hw_prog_firmware = if_usb_prog_firmware;
219 priv->hw_host_to_card = if_usb_host_to_card;
220 priv->hw_get_int_status = if_usb_get_int_status;
221 priv->hw_read_event_cause = if_usb_read_event_cause;
222
Holger Schurig084708b2007-05-25 12:37:58 -0400223 if (libertas_activate_card(priv, libertas_fw_name))
Marcelo Tosatti6a812152007-05-25 12:09:13 -0400224 goto err_activate_card;
Holger Schurig32a74b72007-05-25 12:04:31 -0400225
Holger Schurig435a1ac2007-05-25 12:41:52 -0400226 list_add_tail(&cardp->list, &usb_devices);
Holger Schurig3874d0f2007-05-25 12:01:42 -0400227
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228 usb_get_dev(udev);
Holger Schurig435a1ac2007-05-25 12:41:52 -0400229 usb_set_intfdata(intf, cardp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200230
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231 return 0;
232
Marcelo Tosatti6a812152007-05-25 12:09:13 -0400233err_activate_card:
Dan Williamsc7236832007-05-25 13:35:23 -0400234 libertas_remove_mesh(priv);
Marcelo Tosatti6a812152007-05-25 12:09:13 -0400235err_add_mesh:
Holger Schurig634b8f42007-05-25 13:05:16 -0400236 free_netdev(priv->dev);
Marcelo Tosatti6a812152007-05-25 12:09:13 -0400237 kfree(priv->adapter);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200238dealloc:
Holger Schurig435a1ac2007-05-25 12:41:52 -0400239 if_usb_free(cardp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240
241error:
242 return -ENOMEM;
243}
244
245/**
246 * @brief free resource and cleanup
Holger Schurig435a1ac2007-05-25 12:41:52 -0400247 * @param intf USB interface structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200248 * @return N/A
249 */
250static void if_usb_disconnect(struct usb_interface *intf)
251{
252 struct usb_card_rec *cardp = usb_get_intfdata(intf);
253 wlan_private *priv = (wlan_private *) cardp->priv;
254 wlan_adapter *adapter = NULL;
255
256 adapter = priv->adapter;
257
258 /*
259 * Update Surprise removed to TRUE
260 */
261 adapter->surpriseremoved = 1;
262
Holger Schurig435a1ac2007-05-25 12:41:52 -0400263 list_del(&cardp->list);
Holger Schurig3874d0f2007-05-25 12:01:42 -0400264
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200265 /* card is removed and we can call wlan_remove_card */
Holger Schurig9012b282007-05-25 11:27:16 -0400266 lbs_deb_usbd(&cardp->udev->dev, "call remove card\n");
Holger Schurig084708b2007-05-25 12:37:58 -0400267 libertas_remove_mesh(priv);
268 libertas_remove_card(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269
270 /* Unlink and free urb */
271 if_usb_free(cardp);
272
273 usb_set_intfdata(intf, NULL);
274 usb_put_dev(interface_to_usbdev(intf));
275
276 return;
277}
278
279/**
280 * @brief This function download FW
281 * @param priv pointer to wlan_private
282 * @return 0
283 */
284static int if_prog_firmware(wlan_private * priv)
285{
Holger Schurig634b8f42007-05-25 13:05:16 -0400286 struct usb_card_rec *cardp = priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287 struct FWData *fwdata;
288 struct fwheader *fwheader;
289 u8 *firmware = priv->firmware->data;
290
291 fwdata = kmalloc(sizeof(struct FWData), GFP_ATOMIC);
292
293 if (!fwdata)
294 return -1;
295
296 fwheader = &fwdata->fwheader;
297
298 if (!cardp->CRC_OK) {
299 cardp->totalbytes = cardp->fwlastblksent;
300 cardp->fwseqnum = cardp->lastseqnum - 1;
301 }
302
Holger Schurig9012b282007-05-25 11:27:16 -0400303 /*
304 lbs_deb_usbd(&cardp->udev->dev, "totalbytes = %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305 cardp->totalbytes);
Holger Schurig9012b282007-05-25 11:27:16 -0400306 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307
308 memcpy(fwheader, &firmware[cardp->totalbytes],
309 sizeof(struct fwheader));
310
311 cardp->fwlastblksent = cardp->totalbytes;
312 cardp->totalbytes += sizeof(struct fwheader);
313
Holger Schurig9012b282007-05-25 11:27:16 -0400314 /* lbs_deb_usbd(&cardp->udev->dev,"Copy Data\n"); */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200315 memcpy(fwdata->data, &firmware[cardp->totalbytes],
316 fwdata->fwheader.datalength);
317
Holger Schurig9012b282007-05-25 11:27:16 -0400318 /*
319 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 "Data length = %d\n", fwdata->fwheader.datalength);
Holger Schurig9012b282007-05-25 11:27:16 -0400321 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200322
323 cardp->fwseqnum = cardp->fwseqnum + 1;
324
325 fwdata->seqnum = cardp->fwseqnum;
326 cardp->lastseqnum = fwdata->seqnum;
327 cardp->totalbytes += fwdata->fwheader.datalength;
328
329 if (fwheader->dnldcmd == FW_HAS_DATA_TO_RECV) {
Holger Schurig9012b282007-05-25 11:27:16 -0400330 /*
331 lbs_deb_usbd(&cardp->udev->dev, "There is data to follow\n");
332 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333 "seqnum = %d totalbytes = %d\n", cardp->fwseqnum,
334 cardp->totalbytes);
Holger Schurig9012b282007-05-25 11:27:16 -0400335 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200336 memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
337 usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
338
339 } else if (fwdata->fwheader.dnldcmd == FW_HAS_LAST_BLOCK) {
Holger Schurig9012b282007-05-25 11:27:16 -0400340 /*
341 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342 "Host has finished FW downloading\n");
Holger Schurig9012b282007-05-25 11:27:16 -0400343 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344 "Donwloading FW JUMP BLOCK\n");
Holger Schurig9012b282007-05-25 11:27:16 -0400345 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200346 memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE);
347 usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE);
348 cardp->fwfinalblk = 1;
349 }
350
Holger Schurig9012b282007-05-25 11:27:16 -0400351 /*
352 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353 "The firmware download is done size is %d\n",
354 cardp->totalbytes);
Holger Schurig9012b282007-05-25 11:27:16 -0400355 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356
357 kfree(fwdata);
358
359 return 0;
360}
361
362static int libertas_do_reset(wlan_private *priv)
363{
364 int ret;
Holger Schurig634b8f42007-05-25 13:05:16 -0400365 struct usb_card_rec *cardp = priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366
Holger Schurig3874d0f2007-05-25 12:01:42 -0400367 lbs_deb_enter(LBS_DEB_USB);
368
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200369 ret = usb_reset_device(cardp->udev);
370 if (!ret) {
371 msleep(10);
Holger Schurig435a1ac2007-05-25 12:41:52 -0400372 if_usb_reset_device(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373 msleep(10);
374 }
Holger Schurig3874d0f2007-05-25 12:01:42 -0400375
376 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
377
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200378 return ret;
379}
380
381/**
382 * @brief This function transfer the data to the device.
383 * @param priv pointer to wlan_private
384 * @param payload pointer to payload data
385 * @param nb data length
386 * @return 0 or -1
387 */
388int usb_tx_block(wlan_private * priv, u8 * payload, u16 nb)
389{
390 /* pointer to card structure */
Holger Schurig634b8f42007-05-25 13:05:16 -0400391 struct usb_card_rec *cardp = priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392 int ret = -1;
393
394 /* check if device is removed */
395 if (priv->adapter->surpriseremoved) {
Holger Schurig9012b282007-05-25 11:27:16 -0400396 lbs_deb_usbd(&cardp->udev->dev, "Device removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200397 goto tx_ret;
398 }
399
400 usb_fill_bulk_urb(cardp->tx_urb, cardp->udev,
401 usb_sndbulkpipe(cardp->udev,
402 cardp->bulk_out_endpointAddr),
403 payload, nb, if_usb_write_bulk_callback, priv);
404
405 cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET;
406
407 if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) {
408 /* transfer failed */
Holger Schurig9012b282007-05-25 11:27:16 -0400409 lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200410 ret = -1;
411 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400412 /* lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb success\n"); */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413 ret = 0;
414 }
415
416tx_ret:
417 return ret;
418}
419
420static int __if_usb_submit_rx_urb(wlan_private * priv,
421 void (*callbackfn)
422 (struct urb *urb))
423{
Holger Schurig634b8f42007-05-25 13:05:16 -0400424 struct usb_card_rec *cardp = priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425 struct sk_buff *skb;
426 struct read_cb_info *rinfo = &cardp->rinfo;
427 int ret = -1;
428
429 if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) {
430 lbs_pr_err("No free skb\n");
431 goto rx_ret;
432 }
433
434 rinfo->skb = skb;
435
436 /* Fill the receive configuration URB and initialise the Rx call back */
437 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
438 usb_rcvbulkpipe(cardp->udev,
439 cardp->bulk_in_endpointAddr),
Dan Williams4269e2a2007-05-10 23:10:18 -0400440 (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET),
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200441 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn,
442 rinfo);
443
444 cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET;
445
Holger Schurig9012b282007-05-25 11:27:16 -0400446 /* lbs_deb_usbd(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb); */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200447 if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) {
448 /* handle failure conditions */
Holger Schurig9012b282007-05-25 11:27:16 -0400449 lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200450 ret = -1;
451 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400452 /* lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB success\n"); */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200453 ret = 0;
454 }
455
456rx_ret:
457 return ret;
458}
459
460static inline int if_usb_submit_rx_urb_fwload(wlan_private * priv)
461{
462 return __if_usb_submit_rx_urb(priv, &if_usb_receive_fwload);
463}
464
465static inline int if_usb_submit_rx_urb(wlan_private * priv)
466{
467 return __if_usb_submit_rx_urb(priv, &if_usb_receive);
468}
469
470static void if_usb_receive_fwload(struct urb *urb)
471{
472 struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
473 wlan_private *priv = rinfo->priv;
474 struct sk_buff *skb = rinfo->skb;
Holger Schurig634b8f42007-05-25 13:05:16 -0400475 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 struct fwsyncheader *syncfwheader;
477 struct bootcmdrespStr bootcmdresp;
478
479 if (urb->status) {
Holger Schurig9012b282007-05-25 11:27:16 -0400480 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481 "URB status is failed during fw load\n");
482 kfree_skb(skb);
483 return;
484 }
485
486 if (cardp->bootcmdresp == 0) {
487 memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET,
488 sizeof(bootcmdresp));
489 if (cardp->udev->descriptor.bcdDevice < 0x3106) {
490 kfree_skb(skb);
491 if_usb_submit_rx_urb_fwload(priv);
492 cardp->bootcmdresp = 1;
Holger Schurig9012b282007-05-25 11:27:16 -0400493 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200494 "Received valid boot command response\n");
495 return;
496 }
497 if (bootcmdresp.u32magicnumber != BOOT_CMD_MAGIC_NUMBER) {
498 lbs_pr_info(
499 "boot cmd response wrong magic number (0x%x)\n",
500 bootcmdresp.u32magicnumber);
501 } else if (bootcmdresp.u8cmd_tag != BOOT_CMD_FW_BY_USB) {
502 lbs_pr_info(
503 "boot cmd response cmd_tag error (%d)\n",
504 bootcmdresp.u8cmd_tag);
505 } else if (bootcmdresp.u8result != BOOT_CMD_RESP_OK) {
506 lbs_pr_info(
507 "boot cmd response result error (%d)\n",
508 bootcmdresp.u8result);
509 } else {
510 cardp->bootcmdresp = 1;
Holger Schurig9012b282007-05-25 11:27:16 -0400511 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200512 "Received valid boot command response\n");
513 }
514 kfree_skb(skb);
515 if_usb_submit_rx_urb_fwload(priv);
516 return;
517 }
518
519 syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
520 if (!syncfwheader) {
Holger Schurig9012b282007-05-25 11:27:16 -0400521 lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200522 kfree_skb(skb);
523 return;
524 }
525
526 memcpy(syncfwheader, skb->data + IPFIELD_ALIGN_OFFSET,
527 sizeof(struct fwsyncheader));
528
529 if (!syncfwheader->cmd) {
Holger Schurig9012b282007-05-25 11:27:16 -0400530 /*
531 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532 "FW received Blk with correct CRC\n");
Holger Schurig9012b282007-05-25 11:27:16 -0400533 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200534 "FW received Blk seqnum = %d\n",
535 syncfwheader->seqnum);
Holger Schurig9012b282007-05-25 11:27:16 -0400536 */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200537 cardp->CRC_OK = 1;
538 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400539 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200540 "FW received Blk with CRC error\n");
541 cardp->CRC_OK = 0;
542 }
543
544 kfree_skb(skb);
545
546 if (cardp->fwfinalblk) {
547 cardp->fwdnldover = 1;
548 goto exit;
549 }
550
551 if_prog_firmware(priv);
552
553 if_usb_submit_rx_urb_fwload(priv);
554exit:
555 kfree(syncfwheader);
556
557 return;
558
559}
560
561#define MRVDRV_MIN_PKT_LEN 30
562
563static inline void process_cmdtypedata(int recvlength, struct sk_buff *skb,
564 struct usb_card_rec *cardp,
565 wlan_private *priv)
566{
567 if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE +
568 MESSAGE_HEADER_LEN || recvlength < MRVDRV_MIN_PKT_LEN) {
Holger Schurig9012b282007-05-25 11:27:16 -0400569 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200570 "Packet length is Invalid\n");
571 kfree_skb(skb);
572 return;
573 }
574
575 skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
576 skb_put(skb, recvlength);
577 skb_pull(skb, MESSAGE_HEADER_LEN);
578 libertas_process_rxed_packet(priv, skb);
Holger Schurig634b8f42007-05-25 13:05:16 -0400579 priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200580}
581
582static inline void process_cmdrequest(int recvlength, u8 *recvbuff,
583 struct sk_buff *skb,
584 struct usb_card_rec *cardp,
585 wlan_private *priv)
586{
587 u8 *cmdbuf;
588 if (recvlength > MRVDRV_SIZE_OF_CMD_BUFFER) {
Holger Schurig9012b282007-05-25 11:27:16 -0400589 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200590 "The receive buffer is too large\n");
591 kfree_skb(skb);
592 return;
593 }
594
595 if (!in_interrupt())
596 BUG();
597
598 spin_lock(&priv->adapter->driver_lock);
599 /* take care of cur_cmd = NULL case by reading the
600 * data to clear the interrupt */
601 if (!priv->adapter->cur_cmd) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400602 cmdbuf = priv->upld_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200603 priv->adapter->hisregcpy &= ~his_cmdupldrdy;
604 } else
605 cmdbuf = priv->adapter->cur_cmd->bufvirtualaddr;
606
607 cardp->usb_int_cause |= his_cmdupldrdy;
Holger Schurig634b8f42007-05-25 13:05:16 -0400608 priv->upld_len = (recvlength - MESSAGE_HEADER_LEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200609 memcpy(cmdbuf, recvbuff + MESSAGE_HEADER_LEN,
Holger Schurig634b8f42007-05-25 13:05:16 -0400610 priv->upld_len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611
612 kfree_skb(skb);
Holger Schurig634b8f42007-05-25 13:05:16 -0400613 libertas_interrupt(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614 spin_unlock(&priv->adapter->driver_lock);
615
Holger Schurig9012b282007-05-25 11:27:16 -0400616 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200617 "Wake up main thread to handle cmd response\n");
618
619 return;
620}
621
622/**
623 * @brief This function reads of the packet into the upload buff,
624 * wake up the main thread and initialise the Rx callack.
625 *
626 * @param urb pointer to struct urb
627 * @return N/A
628 */
629static void if_usb_receive(struct urb *urb)
630{
631 struct read_cb_info *rinfo = (struct read_cb_info *)urb->context;
632 wlan_private *priv = rinfo->priv;
633 struct sk_buff *skb = rinfo->skb;
Holger Schurig634b8f42007-05-25 13:05:16 -0400634 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200635
636 int recvlength = urb->actual_length;
637 u8 *recvbuff = NULL;
638 u32 recvtype;
639
Holger Schurig9012b282007-05-25 11:27:16 -0400640 lbs_deb_enter(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200641
642 if (recvlength) {
643 if (urb->status) {
Holger Schurig9012b282007-05-25 11:27:16 -0400644 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200645 "URB status is failed\n");
646 kfree_skb(skb);
647 goto setup_for_next;
648 }
649
650 recvbuff = skb->data + IPFIELD_ALIGN_OFFSET;
651 memcpy(&recvtype, recvbuff, sizeof(u32));
Holger Schurig9012b282007-05-25 11:27:16 -0400652 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200653 "Recv length = 0x%x\n", recvlength);
Holger Schurig9012b282007-05-25 11:27:16 -0400654 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200655 "Receive type = 0x%X\n", recvtype);
656 recvtype = le32_to_cpu(recvtype);
Holger Schurig9012b282007-05-25 11:27:16 -0400657 lbs_deb_usbd(&cardp->udev->dev,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200658 "Receive type after = 0x%X\n", recvtype);
659 } else if (urb->status)
660 goto rx_exit;
661
662
663 switch (recvtype) {
664 case CMD_TYPE_DATA:
665 process_cmdtypedata(recvlength, skb, cardp, priv);
666 break;
667
668 case CMD_TYPE_REQUEST:
669 process_cmdrequest(recvlength, recvbuff, skb, cardp, priv);
670 break;
671
672 case CMD_TYPE_INDICATION:
673 /* Event cause handling */
674 spin_lock(&priv->adapter->driver_lock);
675 cardp->usb_event_cause = *(u32 *) (recvbuff + MESSAGE_HEADER_LEN);
Holger Schurig9012b282007-05-25 11:27:16 -0400676 lbs_deb_usbd(&cardp->udev->dev,"**EVENT** 0x%X\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200677 cardp->usb_event_cause);
678 if (cardp->usb_event_cause & 0xffff0000) {
679 libertas_send_tx_feedback(priv);
Dan Williams12a4d262007-05-10 23:08:54 -0400680 spin_unlock(&priv->adapter->driver_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200681 break;
682 }
683 cardp->usb_event_cause = le32_to_cpu(cardp->usb_event_cause) << 3;
684 cardp->usb_int_cause |= his_cardevent;
685 kfree_skb(skb);
Holger Schurig634b8f42007-05-25 13:05:16 -0400686 libertas_interrupt(priv->dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200687 spin_unlock(&priv->adapter->driver_lock);
688 goto rx_exit;
689 default:
690 kfree_skb(skb);
691 break;
692 }
693
694setup_for_next:
695 if_usb_submit_rx_urb(priv);
696rx_exit:
Holger Schurig9012b282007-05-25 11:27:16 -0400697 lbs_deb_leave(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698}
699
700/**
701 * @brief This function downloads data to FW
702 * @param priv pointer to wlan_private structure
703 * @param type type of data
704 * @param buf pointer to data buffer
705 * @param len number of bytes
706 * @return 0 or -1
707 */
Holger Schurig208fdd22007-05-25 12:17:06 -0400708static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200709{
710 int ret = -1;
711 u32 tmp;
Holger Schurig634b8f42007-05-25 13:05:16 -0400712 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713
Holger Schurig9012b282007-05-25 11:27:16 -0400714 lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type);
715 lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200716
717 if (type == MVMS_CMD) {
718 tmp = cpu_to_le32(CMD_TYPE_REQUEST);
Holger Schurig634b8f42007-05-25 13:05:16 -0400719 priv->dnld_sent = DNLD_CMD_SENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200720 memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
721 MESSAGE_HEADER_LEN);
722
723 } else {
724 tmp = cpu_to_le32(CMD_TYPE_DATA);
Holger Schurig634b8f42007-05-25 13:05:16 -0400725 priv->dnld_sent = DNLD_DATA_SENT;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200726 memcpy(cardp->bulk_out_buffer, (u8 *) & tmp,
727 MESSAGE_HEADER_LEN);
728 }
729
730 memcpy((cardp->bulk_out_buffer + MESSAGE_HEADER_LEN), payload, nb);
731
732 ret =
733 usb_tx_block(priv, cardp->bulk_out_buffer, nb + MESSAGE_HEADER_LEN);
734
735 return ret;
736}
737
738/* called with adapter->driver_lock held */
Holger Schurig208fdd22007-05-25 12:17:06 -0400739static int if_usb_get_int_status(wlan_private * priv, u8 * ireg)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200740{
Holger Schurig634b8f42007-05-25 13:05:16 -0400741 struct usb_card_rec *cardp = priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200742
743 *ireg = cardp->usb_int_cause;
744 cardp->usb_int_cause = 0;
745
Holger Schurig9012b282007-05-25 11:27:16 -0400746 lbs_deb_usbd(&cardp->udev->dev,"Int cause is 0x%X\n", *ireg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747
748 return 0;
749}
750
Holger Schurig208fdd22007-05-25 12:17:06 -0400751static int if_usb_read_event_cause(wlan_private * priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200752{
Holger Schurig634b8f42007-05-25 13:05:16 -0400753 struct usb_card_rec *cardp = priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200754 priv->adapter->eventcause = cardp->usb_event_cause;
755 /* Re-submit rx urb here to avoid event lost issue */
756 if_usb_submit_rx_urb(priv);
757 return 0;
758}
759
Holger Schurig435a1ac2007-05-25 12:41:52 -0400760static int if_usb_reset_device(wlan_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761{
762 int ret;
763
Holger Schurig3874d0f2007-05-25 12:01:42 -0400764 lbs_deb_enter(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200765 ret = libertas_prepare_and_send_command(priv, cmd_802_11_reset,
766 cmd_act_halt, 0, 0, NULL);
767 msleep_interruptible(10);
768
Holger Schurig3874d0f2007-05-25 12:01:42 -0400769 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200770 return ret;
771}
772
Holger Schurig208fdd22007-05-25 12:17:06 -0400773static int if_usb_unregister_dev(wlan_private * priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200774{
775 int ret = 0;
776
777 /* Need to send a Reset command to device before USB resources freed
778 * and wlan_remove_card() called, then device can handle FW download
779 * again.
780 */
781 if (priv)
Holger Schurig435a1ac2007-05-25 12:41:52 -0400782 if_usb_reset_device(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200783
784 return ret;
785}
786
787
788/**
789 * @brief This function register usb device and initialize parameter
790 * @param priv pointer to wlan_private
791 * @return 0 or -1
792 */
Holger Schurig208fdd22007-05-25 12:17:06 -0400793static int if_usb_register_dev(wlan_private * priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200794{
Holger Schurig634b8f42007-05-25 13:05:16 -0400795 struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card;
Holger Schurig9012b282007-05-25 11:27:16 -0400796
797 lbs_deb_enter(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200798
799 cardp->priv = priv;
Holger Schurig634b8f42007-05-25 13:05:16 -0400800 cardp->eth_dev = priv->dev;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801 priv->hotplug_device = &(cardp->udev->dev);
802
Holger Schurig9012b282007-05-25 11:27:16 -0400803 lbs_deb_usbd(&cardp->udev->dev, "udev pointer is at %p\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200804 cardp->udev);
805
Holger Schurig9012b282007-05-25 11:27:16 -0400806 lbs_deb_leave(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200807 return 0;
808}
809
810
811
Holger Schurig208fdd22007-05-25 12:17:06 -0400812static int if_usb_prog_firmware(wlan_private * priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813{
Holger Schurig634b8f42007-05-25 13:05:16 -0400814 struct usb_card_rec *cardp = priv->card;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200815 int i = 0;
816 static int reset_count = 10;
Holger Schurig9012b282007-05-25 11:27:16 -0400817 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200818
Holger Schurig9012b282007-05-25 11:27:16 -0400819 lbs_deb_enter(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200820
821 cardp->rinfo.priv = priv;
822
823restart:
824 if (if_usb_submit_rx_urb_fwload(priv) < 0) {
Holger Schurig9012b282007-05-25 11:27:16 -0400825 lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n");
826 ret = -1;
827 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200828 }
829
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200830 cardp->bootcmdresp = 0;
831 do {
832 int j = 0;
833 i++;
834 /* Issue Boot command = 1, Boot from Download-FW */
835 if_usb_issue_boot_command(priv, BOOT_CMD_FW_BY_USB);
836 /* wait for command response */
837 do {
838 j++;
839 msleep_interruptible(100);
840 } while (cardp->bootcmdresp == 0 && j < 10);
841 } while (cardp->bootcmdresp == 0 && i < 5);
842
843 if (cardp->bootcmdresp == 0) {
844 if (--reset_count >= 0) {
845 libertas_do_reset(priv);
846 goto restart;
847 }
848 return -1;
849 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200850
851 i = 0;
852 priv->adapter->fw_ready = 0;
853
854 cardp->totalbytes = 0;
855 cardp->fwlastblksent = 0;
856 cardp->CRC_OK = 1;
857 cardp->fwdnldover = 0;
858 cardp->fwseqnum = -1;
859 cardp->totalbytes = 0;
860 cardp->fwfinalblk = 0;
861
862 if_prog_firmware(priv);
863
864 do {
Holger Schurig9012b282007-05-25 11:27:16 -0400865 lbs_deb_usbd(&cardp->udev->dev,"Wlan sched timeout\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866 i++;
867 msleep_interruptible(100);
868 if (priv->adapter->surpriseremoved || i >= 20)
869 break;
870 } while (!cardp->fwdnldover);
871
872 if (!cardp->fwdnldover) {
873 lbs_pr_info("failed to load fw, resetting device!\n");
874 if (--reset_count >= 0) {
875 libertas_do_reset(priv);
876 goto restart;
877 }
878
879 lbs_pr_info("FW download failure, time = %d ms\n", i * 100);
Holger Schurig9012b282007-05-25 11:27:16 -0400880 ret = -1;
881 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200882 }
883
884 if_usb_submit_rx_urb(priv);
885
886 /* Delay 200 ms to waiting for the FW ready */
887 msleep_interruptible(200);
888
889 priv->adapter->fw_ready = 1;
890
Holger Schurig9012b282007-05-25 11:27:16 -0400891done:
892 lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
893 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200894}
895
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200896#ifdef CONFIG_PM
897static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
898{
899 struct usb_card_rec *cardp = usb_get_intfdata(intf);
900 wlan_private *priv = cardp->priv;
901
Holger Schurig9012b282007-05-25 11:27:16 -0400902 lbs_deb_enter(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200903
904 if (priv->adapter->psstate != PS_STATE_FULL_POWER)
905 return -1;
906
907 netif_device_detach(cardp->eth_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400908 netif_device_detach(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200909
910 /* Unlink tx & rx urb */
911 usb_kill_urb(cardp->tx_urb);
912 usb_kill_urb(cardp->rx_urb);
913
914 cardp->rx_urb_recall = 1;
915
Holger Schurig9012b282007-05-25 11:27:16 -0400916 lbs_deb_leave(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200917 return 0;
918}
919
920static int if_usb_resume(struct usb_interface *intf)
921{
922 struct usb_card_rec *cardp = usb_get_intfdata(intf);
Javier Cardona51d84f52007-05-25 12:06:56 -0400923 wlan_private *priv = cardp->priv;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200924
Holger Schurig9012b282007-05-25 11:27:16 -0400925 lbs_deb_enter(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200926
927 cardp->rx_urb_recall = 0;
928
929 if_usb_submit_rx_urb(cardp->priv);
930
931 netif_device_attach(cardp->eth_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400932 netif_device_attach(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200933
Holger Schurig9012b282007-05-25 11:27:16 -0400934 lbs_deb_leave(LBS_DEB_USB);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200935 return 0;
936}
937#else
938#define if_usb_suspend NULL
939#define if_usb_resume NULL
940#endif
941
942static struct usb_driver if_usb_driver = {
943 /* driver name */
944 .name = usbdriver_name,
945 /* probe function name */
946 .probe = if_usb_probe,
947 /* disconnect function name */
948 .disconnect = if_usb_disconnect,
949 /* device signature table */
950 .id_table = if_usb_table,
951 .suspend = if_usb_suspend,
952 .resume = if_usb_resume,
953};
954
Holger Schurig084708b2007-05-25 12:37:58 -0400955static int if_usb_init_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200956{
Holger Schurig084708b2007-05-25 12:37:58 -0400957 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200958
Holger Schurig084708b2007-05-25 12:37:58 -0400959 lbs_deb_enter(LBS_DEB_MAIN);
960
961 if (libertas_fw_name == NULL) {
962 libertas_fw_name = default_fw_name;
963 }
964
965 ret = usb_register(&if_usb_driver);
966
967 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret);
968 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200969}
970
Holger Schurig084708b2007-05-25 12:37:58 -0400971static void if_usb_exit_module(void)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200972{
Marcelo Tosattid43fb8e2007-05-25 16:28:20 -0400973 struct usb_card_rec *cardp, *cardp_temp;
Holger Schurig3874d0f2007-05-25 12:01:42 -0400974
Holger Schurig084708b2007-05-25 12:37:58 -0400975 lbs_deb_enter(LBS_DEB_MAIN);
976
Marcelo Tosattid43fb8e2007-05-25 16:28:20 -0400977 list_for_each_entry_safe(cardp, cardp_temp, &usb_devices, list)
Holger Schurig435a1ac2007-05-25 12:41:52 -0400978 if_usb_reset_device((wlan_private *) cardp->priv);
Holger Schurig3874d0f2007-05-25 12:01:42 -0400979
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200980 /* API unregisters the driver from USB subsystem */
981 usb_deregister(&if_usb_driver);
Holger Schurig084708b2007-05-25 12:37:58 -0400982
983 lbs_deb_leave(LBS_DEB_MAIN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200984}
Holger Schurig084708b2007-05-25 12:37:58 -0400985
986module_init(if_usb_init_module);
987module_exit(if_usb_exit_module);
988
989MODULE_DESCRIPTION("8388 USB WLAN Driver");
990MODULE_AUTHOR("Marvell International Ltd.");
991MODULE_LICENSE("GPL");