Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 2 | * This file contains functions used in USB interface module. |
| 3 | */ |
| 4 | #include <linux/delay.h> |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 5 | #include <linux/moduleparam.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 6 | #include <linux/firmware.h> |
| 7 | #include <linux/netdevice.h> |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 8 | #include <linux/list.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 9 | #include <linux/usb.h> |
| 10 | |
Holger Schurig | ec3eef2 | 2007-05-25 12:49:10 -0400 | [diff] [blame] | 11 | #define DRV_NAME "usb8xxx" |
| 12 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 13 | #include "host.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 14 | #include "decl.h" |
| 15 | #include "defs.h" |
| 16 | #include "dev.h" |
| 17 | #include "if_usb.h" |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 18 | #include "decl.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 19 | |
| 20 | #define MESSAGE_HEADER_LEN 4 |
| 21 | |
| 22 | static const char usbdriver_name[] = "usb8xxx"; |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 23 | static u8 *default_fw_name = "usb8388.bin"; |
| 24 | |
| 25 | char *libertas_fw_name = NULL; |
| 26 | module_param_named(fw_name, libertas_fw_name, charp, 0644); |
| 27 | |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 28 | /* |
| 29 | * We need to send a RESET command to all USB devices before |
| 30 | * we tear down the USB connection. Otherwise we would not |
| 31 | * be able to re-init device the device if the module gets |
| 32 | * loaded again. This is a list of all initialized USB devices, |
| 33 | * for the reset code see if_usb_reset_device() |
| 34 | */ |
| 35 | static LIST_HEAD(usb_devices); |
Holger Schurig | 3874d0f | 2007-05-25 12:01:42 -0400 | [diff] [blame] | 36 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 37 | static struct usb_device_id if_usb_table[] = { |
| 38 | /* Enter the device signature inside */ |
Holger Schurig | 66fcc55 | 2007-05-25 00:11:58 -0400 | [diff] [blame] | 39 | { USB_DEVICE(0x1286, 0x2001) }, |
| 40 | { USB_DEVICE(0x05a3, 0x8388) }, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 41 | {} /* Terminating entry */ |
| 42 | }; |
| 43 | |
| 44 | MODULE_DEVICE_TABLE(usb, if_usb_table); |
| 45 | |
| 46 | static void if_usb_receive(struct urb *urb); |
| 47 | static void if_usb_receive_fwload(struct urb *urb); |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 48 | static int if_usb_register_dev(wlan_private * priv); |
| 49 | static int if_usb_unregister_dev(wlan_private *); |
| 50 | static int if_usb_prog_firmware(wlan_private *); |
| 51 | static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb); |
| 52 | static int if_usb_get_int_status(wlan_private * priv, u8 *); |
| 53 | static int if_usb_read_event_cause(wlan_private *); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 54 | |
| 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 | */ |
| 60 | static 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 Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 64 | struct net_device *dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 65 | |
| 66 | /* handle the transmission complete validations */ |
| 67 | |
| 68 | if (urb->status != 0) { |
| 69 | /* print the failure status number for debug */ |
Luis Carlos Cobo | b46794d | 2007-05-25 13:10:18 -0400 | [diff] [blame] | 70 | lbs_pr_info("URB in failure status: %d\n", urb->status); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 71 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 72 | /* |
| 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 Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 75 | urb->actual_length); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 76 | */ |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 77 | priv->dnld_sent = DNLD_RES_RECEIVED; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 78 | /* Wake main thread if commands are pending */ |
| 79 | if (!adapter->cur_cmd) |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 80 | wake_up_interruptible(&priv->waitq); |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 81 | if ((adapter->connect_status == LIBERTAS_CONNECTED)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 82 | netif_wake_queue(dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 83 | netif_wake_queue(priv->mesh_dev); |
| 84 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 85 | } |
| 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 | */ |
| 95 | void if_usb_free(struct usb_card_rec *cardp) |
| 96 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 97 | lbs_deb_enter(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 98 | |
| 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 Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 112 | lbs_deb_leave(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 113 | } |
| 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 | */ |
| 121 | static 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 Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 127 | wlan_private *priv; |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 128 | struct usb_card_rec *cardp; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 129 | int i; |
| 130 | |
| 131 | udev = interface_to_usbdev(intf); |
| 132 | |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 133 | cardp = kzalloc(sizeof(struct usb_card_rec), GFP_KERNEL); |
| 134 | if (!cardp) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 135 | lbs_pr_err("Out of memory allocating private data.\n"); |
| 136 | goto error; |
| 137 | } |
| 138 | |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 139 | cardp->udev = udev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 140 | iface_desc = intf->cur_altsetting; |
| 141 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 142 | lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 143 | " bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n", |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 144 | le16_to_cpu(udev->descriptor.bcdUSB), |
| 145 | udev->descriptor.bDeviceClass, |
| 146 | udev->descriptor.bDeviceSubClass, |
| 147 | udev->descriptor.bDeviceProtocol); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 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 Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 155 | lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n", |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 156 | le16_to_cpu(endpoint->wMaxPacketSize)); |
| 157 | if (!(cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 158 | lbs_deb_usbd(&udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 159 | "Rx URB allocation failed\n"); |
| 160 | goto dealloc; |
| 161 | } |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 162 | cardp->rx_urb_recall = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 163 | |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 164 | cardp->bulk_in_size = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 165 | le16_to_cpu(endpoint->wMaxPacketSize); |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 166 | cardp->bulk_in_endpointAddr = |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 167 | (endpoint-> |
| 168 | bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 169 | lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 170 | endpoint->bEndpointAddress); |
| 171 | } |
| 172 | |
| 173 | if (((endpoint-> |
| 174 | bEndpointAddress & USB_ENDPOINT_DIR_MASK) == |
| 175 | USB_DIR_OUT) |
| 176 | && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == |
| 177 | USB_ENDPOINT_XFER_BULK)) { |
| 178 | /* We found bulk out endpoint */ |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 179 | if (!(cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 180 | lbs_deb_usbd(&udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 181 | "Tx URB allocation failed\n"); |
| 182 | goto dealloc; |
| 183 | } |
| 184 | |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 185 | cardp->bulk_out_size = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 186 | le16_to_cpu(endpoint->wMaxPacketSize); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 187 | lbs_deb_usbd(&udev->dev, |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 188 | "Bulk out size is %d\n", |
| 189 | le16_to_cpu(endpoint->wMaxPacketSize)); |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 190 | cardp->bulk_out_endpointAddr = |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 191 | endpoint->bEndpointAddress; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 192 | lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 193 | endpoint->bEndpointAddress); |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 194 | cardp->bulk_out_buffer = |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 195 | kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE, |
| 196 | GFP_KERNEL); |
| 197 | |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 198 | if (!cardp->bulk_out_buffer) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 199 | lbs_deb_usbd(&udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 200 | "Could not allocate buffer\n"); |
| 201 | goto dealloc; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame] | 206 | if (!(priv = libertas_add_card(cardp, &udev->dev))) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 207 | goto dealloc; |
Holger Schurig | 3874d0f | 2007-05-25 12:01:42 -0400 | [diff] [blame] | 208 | |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame] | 209 | if (libertas_add_mesh(priv, &udev->dev)) |
Marcelo Tosatti | 6a81215 | 2007-05-25 12:09:13 -0400 | [diff] [blame] | 210 | goto err_add_mesh; |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 211 | |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 212 | priv->hw_register_dev = if_usb_register_dev; |
| 213 | priv->hw_unregister_dev = if_usb_unregister_dev; |
| 214 | priv->hw_prog_firmware = if_usb_prog_firmware; |
| 215 | priv->hw_host_to_card = if_usb_host_to_card; |
| 216 | priv->hw_get_int_status = if_usb_get_int_status; |
| 217 | priv->hw_read_event_cause = if_usb_read_event_cause; |
| 218 | |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame^] | 219 | if (libertas_activate_card(priv)) |
Marcelo Tosatti | 6a81215 | 2007-05-25 12:09:13 -0400 | [diff] [blame] | 220 | goto err_activate_card; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 221 | |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 222 | list_add_tail(&cardp->list, &usb_devices); |
Holger Schurig | 3874d0f | 2007-05-25 12:01:42 -0400 | [diff] [blame] | 223 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 224 | usb_get_dev(udev); |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 225 | usb_set_intfdata(intf, cardp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 226 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 227 | return 0; |
| 228 | |
Marcelo Tosatti | 6a81215 | 2007-05-25 12:09:13 -0400 | [diff] [blame] | 229 | err_activate_card: |
Dan Williams | c723683 | 2007-05-25 13:35:23 -0400 | [diff] [blame] | 230 | libertas_remove_mesh(priv); |
Marcelo Tosatti | 6a81215 | 2007-05-25 12:09:13 -0400 | [diff] [blame] | 231 | err_add_mesh: |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 232 | free_netdev(priv->dev); |
Marcelo Tosatti | 6a81215 | 2007-05-25 12:09:13 -0400 | [diff] [blame] | 233 | kfree(priv->adapter); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 234 | dealloc: |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 235 | if_usb_free(cardp); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 236 | |
| 237 | error: |
| 238 | return -ENOMEM; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * @brief free resource and cleanup |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 243 | * @param intf USB interface structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 244 | * @return N/A |
| 245 | */ |
| 246 | static void if_usb_disconnect(struct usb_interface *intf) |
| 247 | { |
| 248 | struct usb_card_rec *cardp = usb_get_intfdata(intf); |
| 249 | wlan_private *priv = (wlan_private *) cardp->priv; |
| 250 | wlan_adapter *adapter = NULL; |
| 251 | |
| 252 | adapter = priv->adapter; |
| 253 | |
| 254 | /* |
| 255 | * Update Surprise removed to TRUE |
| 256 | */ |
| 257 | adapter->surpriseremoved = 1; |
| 258 | |
Holger Schurig | 435a1ac | 2007-05-25 12:41:52 -0400 | [diff] [blame] | 259 | list_del(&cardp->list); |
Holger Schurig | 3874d0f | 2007-05-25 12:01:42 -0400 | [diff] [blame] | 260 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 261 | /* card is removed and we can call wlan_remove_card */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 262 | lbs_deb_usbd(&cardp->udev->dev, "call remove card\n"); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 263 | libertas_remove_mesh(priv); |
| 264 | libertas_remove_card(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 265 | |
| 266 | /* Unlink and free urb */ |
| 267 | if_usb_free(cardp); |
| 268 | |
| 269 | usb_set_intfdata(intf, NULL); |
| 270 | usb_put_dev(interface_to_usbdev(intf)); |
| 271 | |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * @brief This function download FW |
| 277 | * @param priv pointer to wlan_private |
| 278 | * @return 0 |
| 279 | */ |
| 280 | static int if_prog_firmware(wlan_private * priv) |
| 281 | { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 282 | struct usb_card_rec *cardp = priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 283 | struct FWData *fwdata; |
| 284 | struct fwheader *fwheader; |
| 285 | u8 *firmware = priv->firmware->data; |
| 286 | |
| 287 | fwdata = kmalloc(sizeof(struct FWData), GFP_ATOMIC); |
| 288 | |
| 289 | if (!fwdata) |
| 290 | return -1; |
| 291 | |
| 292 | fwheader = &fwdata->fwheader; |
| 293 | |
| 294 | if (!cardp->CRC_OK) { |
| 295 | cardp->totalbytes = cardp->fwlastblksent; |
| 296 | cardp->fwseqnum = cardp->lastseqnum - 1; |
| 297 | } |
| 298 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 299 | /* |
| 300 | lbs_deb_usbd(&cardp->udev->dev, "totalbytes = %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 301 | cardp->totalbytes); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 302 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 303 | |
| 304 | memcpy(fwheader, &firmware[cardp->totalbytes], |
| 305 | sizeof(struct fwheader)); |
| 306 | |
| 307 | cardp->fwlastblksent = cardp->totalbytes; |
| 308 | cardp->totalbytes += sizeof(struct fwheader); |
| 309 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 310 | /* lbs_deb_usbd(&cardp->udev->dev,"Copy Data\n"); */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 311 | memcpy(fwdata->data, &firmware[cardp->totalbytes], |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 312 | le32_to_cpu(fwdata->fwheader.datalength)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 313 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 314 | /* |
| 315 | lbs_deb_usbd(&cardp->udev->dev, |
David Woodhouse | bb793e2 | 2007-05-25 23:38:14 -0400 | [diff] [blame] | 316 | "Data length = %d\n", le32_to_cpu(fwdata->fwheader.datalength)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 317 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 318 | |
| 319 | cardp->fwseqnum = cardp->fwseqnum + 1; |
| 320 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 321 | fwdata->seqnum = cpu_to_le32(cardp->fwseqnum); |
| 322 | cardp->lastseqnum = cardp->fwseqnum; |
| 323 | cardp->totalbytes += le32_to_cpu(fwdata->fwheader.datalength); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 324 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 325 | if (fwheader->dnldcmd == cpu_to_le32(FW_HAS_DATA_TO_RECV)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 326 | /* |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 327 | lbs_deb_usbd(&cardp->udev->dev, "There are data to follow\n"); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 328 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 329 | "seqnum = %d totalbytes = %d\n", cardp->fwseqnum, |
| 330 | cardp->totalbytes); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 331 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 332 | memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE); |
| 333 | usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE); |
| 334 | |
David Woodhouse | bb793e2 | 2007-05-25 23:38:14 -0400 | [diff] [blame] | 335 | } else if (fwdata->fwheader.dnldcmd == cpu_to_le32(FW_HAS_LAST_BLOCK)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 336 | /* |
| 337 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 338 | "Host has finished FW downloading\n"); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 339 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 340 | "Donwloading FW JUMP BLOCK\n"); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 341 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 342 | memcpy(cardp->bulk_out_buffer, fwheader, FW_DATA_XMIT_SIZE); |
| 343 | usb_tx_block(priv, cardp->bulk_out_buffer, FW_DATA_XMIT_SIZE); |
| 344 | cardp->fwfinalblk = 1; |
| 345 | } |
| 346 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 347 | /* |
| 348 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 349 | "The firmware download is done size is %d\n", |
| 350 | cardp->totalbytes); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 351 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 352 | |
| 353 | kfree(fwdata); |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 358 | static int if_usb_reset_device(wlan_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 359 | { |
| 360 | int ret; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 361 | struct usb_card_rec *cardp = priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 362 | |
Holger Schurig | 3874d0f | 2007-05-25 12:01:42 -0400 | [diff] [blame] | 363 | lbs_deb_enter(LBS_DEB_USB); |
| 364 | |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 365 | /* Try a USB port reset first, if that fails send the reset |
| 366 | * command to the firmware. |
| 367 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 368 | ret = usb_reset_device(cardp->udev); |
| 369 | if (!ret) { |
| 370 | msleep(10); |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 371 | ret = libertas_reset_device(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 372 | msleep(10); |
| 373 | } |
Holger Schurig | 3874d0f | 2007-05-25 12:01:42 -0400 | [diff] [blame] | 374 | |
| 375 | lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret); |
| 376 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 377 | return ret; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * @brief This function transfer the data to the device. |
| 382 | * @param priv pointer to wlan_private |
| 383 | * @param payload pointer to payload data |
| 384 | * @param nb data length |
| 385 | * @return 0 or -1 |
| 386 | */ |
| 387 | int usb_tx_block(wlan_private * priv, u8 * payload, u16 nb) |
| 388 | { |
| 389 | /* pointer to card structure */ |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 390 | struct usb_card_rec *cardp = priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 391 | int ret = -1; |
| 392 | |
| 393 | /* check if device is removed */ |
| 394 | if (priv->adapter->surpriseremoved) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 395 | lbs_deb_usbd(&cardp->udev->dev, "Device removed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 396 | goto tx_ret; |
| 397 | } |
| 398 | |
| 399 | usb_fill_bulk_urb(cardp->tx_urb, cardp->udev, |
| 400 | usb_sndbulkpipe(cardp->udev, |
| 401 | cardp->bulk_out_endpointAddr), |
| 402 | payload, nb, if_usb_write_bulk_callback, priv); |
| 403 | |
| 404 | cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET; |
| 405 | |
| 406 | if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) { |
| 407 | /* transfer failed */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 408 | lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 409 | ret = -1; |
| 410 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 411 | /* lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb success\n"); */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 412 | ret = 0; |
| 413 | } |
| 414 | |
| 415 | tx_ret: |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | static int __if_usb_submit_rx_urb(wlan_private * priv, |
| 420 | void (*callbackfn) |
| 421 | (struct urb *urb)) |
| 422 | { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 423 | struct usb_card_rec *cardp = priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 424 | struct sk_buff *skb; |
| 425 | struct read_cb_info *rinfo = &cardp->rinfo; |
| 426 | int ret = -1; |
| 427 | |
| 428 | if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) { |
| 429 | lbs_pr_err("No free skb\n"); |
| 430 | goto rx_ret; |
| 431 | } |
| 432 | |
| 433 | rinfo->skb = skb; |
| 434 | |
| 435 | /* Fill the receive configuration URB and initialise the Rx call back */ |
| 436 | usb_fill_bulk_urb(cardp->rx_urb, cardp->udev, |
| 437 | usb_rcvbulkpipe(cardp->udev, |
| 438 | cardp->bulk_in_endpointAddr), |
Dan Williams | 4269e2a | 2007-05-10 23:10:18 -0400 | [diff] [blame] | 439 | (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET), |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 440 | MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn, |
| 441 | rinfo); |
| 442 | |
| 443 | cardp->rx_urb->transfer_flags |= URB_ZERO_PACKET; |
| 444 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 445 | /* lbs_deb_usbd(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb); */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 446 | if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) { |
| 447 | /* handle failure conditions */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 448 | lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 449 | ret = -1; |
| 450 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 451 | /* lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB success\n"); */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 452 | ret = 0; |
| 453 | } |
| 454 | |
| 455 | rx_ret: |
| 456 | return ret; |
| 457 | } |
| 458 | |
| 459 | static inline int if_usb_submit_rx_urb_fwload(wlan_private * priv) |
| 460 | { |
| 461 | return __if_usb_submit_rx_urb(priv, &if_usb_receive_fwload); |
| 462 | } |
| 463 | |
| 464 | static inline int if_usb_submit_rx_urb(wlan_private * priv) |
| 465 | { |
| 466 | return __if_usb_submit_rx_urb(priv, &if_usb_receive); |
| 467 | } |
| 468 | |
| 469 | static void if_usb_receive_fwload(struct urb *urb) |
| 470 | { |
| 471 | struct read_cb_info *rinfo = (struct read_cb_info *)urb->context; |
| 472 | wlan_private *priv = rinfo->priv; |
| 473 | struct sk_buff *skb = rinfo->skb; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 474 | struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 475 | struct fwsyncheader *syncfwheader; |
| 476 | struct bootcmdrespStr bootcmdresp; |
| 477 | |
| 478 | if (urb->status) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 479 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 480 | "URB status is failed during fw load\n"); |
| 481 | kfree_skb(skb); |
| 482 | return; |
| 483 | } |
| 484 | |
| 485 | if (cardp->bootcmdresp == 0) { |
| 486 | memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET, |
| 487 | sizeof(bootcmdresp)); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 488 | if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 489 | kfree_skb(skb); |
| 490 | if_usb_submit_rx_urb_fwload(priv); |
| 491 | cardp->bootcmdresp = 1; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 492 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 493 | "Received valid boot command response\n"); |
| 494 | return; |
| 495 | } |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 496 | if (bootcmdresp.u32magicnumber != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 497 | lbs_pr_info( |
| 498 | "boot cmd response wrong magic number (0x%x)\n", |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 499 | le32_to_cpu(bootcmdresp.u32magicnumber)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 500 | } else if (bootcmdresp.u8cmd_tag != BOOT_CMD_FW_BY_USB) { |
| 501 | lbs_pr_info( |
| 502 | "boot cmd response cmd_tag error (%d)\n", |
| 503 | bootcmdresp.u8cmd_tag); |
| 504 | } else if (bootcmdresp.u8result != BOOT_CMD_RESP_OK) { |
| 505 | lbs_pr_info( |
| 506 | "boot cmd response result error (%d)\n", |
| 507 | bootcmdresp.u8result); |
| 508 | } else { |
| 509 | cardp->bootcmdresp = 1; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 510 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 511 | "Received valid boot command response\n"); |
| 512 | } |
| 513 | kfree_skb(skb); |
| 514 | if_usb_submit_rx_urb_fwload(priv); |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC); |
| 519 | if (!syncfwheader) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 520 | lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 521 | kfree_skb(skb); |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | memcpy(syncfwheader, skb->data + IPFIELD_ALIGN_OFFSET, |
| 526 | sizeof(struct fwsyncheader)); |
| 527 | |
| 528 | if (!syncfwheader->cmd) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 529 | /* |
| 530 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 531 | "FW received Blk with correct CRC\n"); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 532 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 533 | "FW received Blk seqnum = %d\n", |
| 534 | syncfwheader->seqnum); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 535 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 536 | cardp->CRC_OK = 1; |
| 537 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 538 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 539 | "FW received Blk with CRC error\n"); |
| 540 | cardp->CRC_OK = 0; |
| 541 | } |
| 542 | |
| 543 | kfree_skb(skb); |
| 544 | |
| 545 | if (cardp->fwfinalblk) { |
| 546 | cardp->fwdnldover = 1; |
| 547 | goto exit; |
| 548 | } |
| 549 | |
| 550 | if_prog_firmware(priv); |
| 551 | |
| 552 | if_usb_submit_rx_urb_fwload(priv); |
| 553 | exit: |
| 554 | kfree(syncfwheader); |
| 555 | |
| 556 | return; |
| 557 | |
| 558 | } |
| 559 | |
| 560 | #define MRVDRV_MIN_PKT_LEN 30 |
| 561 | |
| 562 | static inline void process_cmdtypedata(int recvlength, struct sk_buff *skb, |
| 563 | struct usb_card_rec *cardp, |
| 564 | wlan_private *priv) |
| 565 | { |
| 566 | if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + |
| 567 | MESSAGE_HEADER_LEN || recvlength < MRVDRV_MIN_PKT_LEN) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 568 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 569 | "Packet length is Invalid\n"); |
| 570 | kfree_skb(skb); |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | skb_reserve(skb, IPFIELD_ALIGN_OFFSET); |
| 575 | skb_put(skb, recvlength); |
| 576 | skb_pull(skb, MESSAGE_HEADER_LEN); |
| 577 | libertas_process_rxed_packet(priv, skb); |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 578 | priv->upld_len = (recvlength - MESSAGE_HEADER_LEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static inline void process_cmdrequest(int recvlength, u8 *recvbuff, |
| 582 | struct sk_buff *skb, |
| 583 | struct usb_card_rec *cardp, |
| 584 | wlan_private *priv) |
| 585 | { |
| 586 | u8 *cmdbuf; |
| 587 | if (recvlength > MRVDRV_SIZE_OF_CMD_BUFFER) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 588 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 589 | "The receive buffer is too large\n"); |
| 590 | kfree_skb(skb); |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | if (!in_interrupt()) |
| 595 | BUG(); |
| 596 | |
| 597 | spin_lock(&priv->adapter->driver_lock); |
| 598 | /* take care of cur_cmd = NULL case by reading the |
| 599 | * data to clear the interrupt */ |
| 600 | if (!priv->adapter->cur_cmd) { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 601 | cmdbuf = priv->upld_buf; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 602 | priv->adapter->hisregcpy &= ~his_cmdupldrdy; |
| 603 | } else |
| 604 | cmdbuf = priv->adapter->cur_cmd->bufvirtualaddr; |
| 605 | |
| 606 | cardp->usb_int_cause |= his_cmdupldrdy; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 607 | priv->upld_len = (recvlength - MESSAGE_HEADER_LEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 608 | memcpy(cmdbuf, recvbuff + MESSAGE_HEADER_LEN, |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 609 | priv->upld_len); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 610 | |
| 611 | kfree_skb(skb); |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 612 | libertas_interrupt(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 613 | spin_unlock(&priv->adapter->driver_lock); |
| 614 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 615 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 616 | "Wake up main thread to handle cmd response\n"); |
| 617 | |
| 618 | return; |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * @brief This function reads of the packet into the upload buff, |
| 623 | * wake up the main thread and initialise the Rx callack. |
| 624 | * |
| 625 | * @param urb pointer to struct urb |
| 626 | * @return N/A |
| 627 | */ |
| 628 | static void if_usb_receive(struct urb *urb) |
| 629 | { |
| 630 | struct read_cb_info *rinfo = (struct read_cb_info *)urb->context; |
| 631 | wlan_private *priv = rinfo->priv; |
| 632 | struct sk_buff *skb = rinfo->skb; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 633 | struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 634 | |
| 635 | int recvlength = urb->actual_length; |
| 636 | u8 *recvbuff = NULL; |
| 637 | u32 recvtype; |
| 638 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 639 | lbs_deb_enter(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 640 | |
| 641 | if (recvlength) { |
| 642 | if (urb->status) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 643 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 644 | "URB status is failed\n"); |
| 645 | kfree_skb(skb); |
| 646 | goto setup_for_next; |
| 647 | } |
| 648 | |
| 649 | recvbuff = skb->data + IPFIELD_ALIGN_OFFSET; |
| 650 | memcpy(&recvtype, recvbuff, sizeof(u32)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 651 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 652 | "Recv length = 0x%x\n", recvlength); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 653 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 654 | "Receive type = 0x%X\n", recvtype); |
| 655 | recvtype = le32_to_cpu(recvtype); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 656 | lbs_deb_usbd(&cardp->udev->dev, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 657 | "Receive type after = 0x%X\n", recvtype); |
| 658 | } else if (urb->status) |
| 659 | goto rx_exit; |
| 660 | |
| 661 | |
| 662 | switch (recvtype) { |
| 663 | case CMD_TYPE_DATA: |
| 664 | process_cmdtypedata(recvlength, skb, cardp, priv); |
| 665 | break; |
| 666 | |
| 667 | case CMD_TYPE_REQUEST: |
| 668 | process_cmdrequest(recvlength, recvbuff, skb, cardp, priv); |
| 669 | break; |
| 670 | |
| 671 | case CMD_TYPE_INDICATION: |
| 672 | /* Event cause handling */ |
| 673 | spin_lock(&priv->adapter->driver_lock); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 674 | cardp->usb_event_cause = le32_to_cpu(*(__le32 *) (recvbuff + MESSAGE_HEADER_LEN)); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 675 | lbs_deb_usbd(&cardp->udev->dev,"**EVENT** 0x%X\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 676 | cardp->usb_event_cause); |
| 677 | if (cardp->usb_event_cause & 0xffff0000) { |
| 678 | libertas_send_tx_feedback(priv); |
Dan Williams | 12a4d26 | 2007-05-10 23:08:54 -0400 | [diff] [blame] | 679 | spin_unlock(&priv->adapter->driver_lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 680 | break; |
| 681 | } |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 682 | cardp->usb_event_cause <<= 3; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 683 | cardp->usb_int_cause |= his_cardevent; |
| 684 | kfree_skb(skb); |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 685 | libertas_interrupt(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 686 | spin_unlock(&priv->adapter->driver_lock); |
| 687 | goto rx_exit; |
| 688 | default: |
| 689 | kfree_skb(skb); |
| 690 | break; |
| 691 | } |
| 692 | |
| 693 | setup_for_next: |
| 694 | if_usb_submit_rx_urb(priv); |
| 695 | rx_exit: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 696 | lbs_deb_leave(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /** |
| 700 | * @brief This function downloads data to FW |
| 701 | * @param priv pointer to wlan_private structure |
| 702 | * @param type type of data |
| 703 | * @param buf pointer to data buffer |
| 704 | * @param len number of bytes |
| 705 | * @return 0 or -1 |
| 706 | */ |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 707 | static int if_usb_host_to_card(wlan_private * priv, u8 type, u8 * payload, u16 nb) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 708 | { |
| 709 | int ret = -1; |
| 710 | u32 tmp; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 711 | struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 712 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 713 | lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type); |
| 714 | lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 715 | |
| 716 | if (type == MVMS_CMD) { |
| 717 | tmp = cpu_to_le32(CMD_TYPE_REQUEST); |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 718 | priv->dnld_sent = DNLD_CMD_SENT; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 719 | memcpy(cardp->bulk_out_buffer, (u8 *) & tmp, |
| 720 | MESSAGE_HEADER_LEN); |
| 721 | |
| 722 | } else { |
| 723 | tmp = cpu_to_le32(CMD_TYPE_DATA); |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 724 | priv->dnld_sent = DNLD_DATA_SENT; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 725 | memcpy(cardp->bulk_out_buffer, (u8 *) & tmp, |
| 726 | MESSAGE_HEADER_LEN); |
| 727 | } |
| 728 | |
| 729 | memcpy((cardp->bulk_out_buffer + MESSAGE_HEADER_LEN), payload, nb); |
| 730 | |
| 731 | ret = |
| 732 | usb_tx_block(priv, cardp->bulk_out_buffer, nb + MESSAGE_HEADER_LEN); |
| 733 | |
| 734 | return ret; |
| 735 | } |
| 736 | |
| 737 | /* called with adapter->driver_lock held */ |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 738 | static int if_usb_get_int_status(wlan_private * priv, u8 * ireg) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 739 | { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 740 | struct usb_card_rec *cardp = priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 741 | |
| 742 | *ireg = cardp->usb_int_cause; |
| 743 | cardp->usb_int_cause = 0; |
| 744 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 745 | lbs_deb_usbd(&cardp->udev->dev,"Int cause is 0x%X\n", *ireg); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 746 | |
| 747 | return 0; |
| 748 | } |
| 749 | |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 750 | static int if_usb_read_event_cause(wlan_private * priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 751 | { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 752 | struct usb_card_rec *cardp = priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 753 | priv->adapter->eventcause = cardp->usb_event_cause; |
| 754 | /* Re-submit rx urb here to avoid event lost issue */ |
| 755 | if_usb_submit_rx_urb(priv); |
| 756 | return 0; |
| 757 | } |
| 758 | |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 759 | static int if_usb_unregister_dev(wlan_private * priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 760 | { |
| 761 | int ret = 0; |
| 762 | |
| 763 | /* Need to send a Reset command to device before USB resources freed |
| 764 | * and wlan_remove_card() called, then device can handle FW download |
| 765 | * again. |
| 766 | */ |
| 767 | if (priv) |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 768 | libertas_reset_device(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 769 | |
| 770 | return ret; |
| 771 | } |
| 772 | |
| 773 | |
| 774 | /** |
| 775 | * @brief This function register usb device and initialize parameter |
| 776 | * @param priv pointer to wlan_private |
| 777 | * @return 0 or -1 |
| 778 | */ |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 779 | static int if_usb_register_dev(wlan_private * priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 780 | { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 781 | struct usb_card_rec *cardp = (struct usb_card_rec *)priv->card; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 782 | |
| 783 | lbs_deb_enter(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 784 | |
| 785 | cardp->priv = priv; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 786 | cardp->eth_dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 787 | priv->hotplug_device = &(cardp->udev->dev); |
| 788 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 789 | lbs_deb_usbd(&cardp->udev->dev, "udev pointer is at %p\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 790 | cardp->udev); |
| 791 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 792 | lbs_deb_leave(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 793 | return 0; |
| 794 | } |
| 795 | |
Dan Williams | 9e22cb6 | 2007-08-02 11:14:49 -0400 | [diff] [blame] | 796 | /** |
| 797 | * @brief This function issues Boot command to the Boot2 code |
| 798 | * @param ivalue 1:Boot from FW by USB-Download |
| 799 | * 2:Boot from FW in EEPROM |
| 800 | * @return 0 |
| 801 | */ |
| 802 | static int if_usb_issue_boot_command(wlan_private *priv, int ivalue) |
| 803 | { |
| 804 | struct usb_card_rec *cardp = priv->card; |
| 805 | struct bootcmdstr sbootcmd; |
| 806 | int i; |
| 807 | |
| 808 | /* Prepare command */ |
| 809 | sbootcmd.u32magicnumber = cpu_to_le32(BOOT_CMD_MAGIC_NUMBER); |
| 810 | sbootcmd.u8cmd_tag = ivalue; |
| 811 | for (i=0; i<11; i++) |
| 812 | sbootcmd.au8dumy[i]=0x00; |
| 813 | memcpy(cardp->bulk_out_buffer, &sbootcmd, sizeof(struct bootcmdstr)); |
| 814 | |
| 815 | /* Issue command */ |
| 816 | usb_tx_block(priv, cardp->bulk_out_buffer, sizeof(struct bootcmdstr)); |
| 817 | |
| 818 | return 0; |
| 819 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 820 | |
| 821 | |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame^] | 822 | static int if_usb_do_prog_firmware(wlan_private * priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 823 | { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 824 | struct usb_card_rec *cardp = priv->card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 825 | int i = 0; |
| 826 | static int reset_count = 10; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 827 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 828 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 829 | lbs_deb_enter(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 830 | |
| 831 | cardp->rinfo.priv = priv; |
| 832 | |
| 833 | restart: |
| 834 | if (if_usb_submit_rx_urb_fwload(priv) < 0) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 835 | lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n"); |
| 836 | ret = -1; |
| 837 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 838 | } |
| 839 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 840 | cardp->bootcmdresp = 0; |
| 841 | do { |
| 842 | int j = 0; |
| 843 | i++; |
| 844 | /* Issue Boot command = 1, Boot from Download-FW */ |
| 845 | if_usb_issue_boot_command(priv, BOOT_CMD_FW_BY_USB); |
| 846 | /* wait for command response */ |
| 847 | do { |
| 848 | j++; |
| 849 | msleep_interruptible(100); |
| 850 | } while (cardp->bootcmdresp == 0 && j < 10); |
| 851 | } while (cardp->bootcmdresp == 0 && i < 5); |
| 852 | |
| 853 | if (cardp->bootcmdresp == 0) { |
| 854 | if (--reset_count >= 0) { |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 855 | if_usb_reset_device(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 856 | goto restart; |
| 857 | } |
| 858 | return -1; |
| 859 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 860 | |
| 861 | i = 0; |
| 862 | priv->adapter->fw_ready = 0; |
| 863 | |
| 864 | cardp->totalbytes = 0; |
| 865 | cardp->fwlastblksent = 0; |
| 866 | cardp->CRC_OK = 1; |
| 867 | cardp->fwdnldover = 0; |
| 868 | cardp->fwseqnum = -1; |
| 869 | cardp->totalbytes = 0; |
| 870 | cardp->fwfinalblk = 0; |
| 871 | |
| 872 | if_prog_firmware(priv); |
| 873 | |
| 874 | do { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 875 | lbs_deb_usbd(&cardp->udev->dev,"Wlan sched timeout\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 876 | i++; |
| 877 | msleep_interruptible(100); |
| 878 | if (priv->adapter->surpriseremoved || i >= 20) |
| 879 | break; |
| 880 | } while (!cardp->fwdnldover); |
| 881 | |
| 882 | if (!cardp->fwdnldover) { |
| 883 | lbs_pr_info("failed to load fw, resetting device!\n"); |
| 884 | if (--reset_count >= 0) { |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 885 | if_usb_reset_device(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 886 | goto restart; |
| 887 | } |
| 888 | |
| 889 | lbs_pr_info("FW download failure, time = %d ms\n", i * 100); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 890 | ret = -1; |
| 891 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | if_usb_submit_rx_urb(priv); |
| 895 | |
| 896 | /* Delay 200 ms to waiting for the FW ready */ |
| 897 | msleep_interruptible(200); |
| 898 | |
| 899 | priv->adapter->fw_ready = 1; |
| 900 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 901 | done: |
| 902 | lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret); |
| 903 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 904 | } |
| 905 | |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame^] | 906 | /** |
| 907 | * @brief This function checks the validity of Boot2/FW image. |
| 908 | * |
| 909 | * @param data pointer to image |
| 910 | * len image length |
| 911 | * @return 0 or -1 |
| 912 | */ |
| 913 | static int check_fwfile_format(u8 *data, u32 totlen) |
| 914 | { |
| 915 | u32 bincmd, exit; |
| 916 | u32 blksize, offset, len; |
| 917 | int ret; |
| 918 | |
| 919 | ret = 1; |
| 920 | exit = len = 0; |
| 921 | |
| 922 | do { |
| 923 | struct fwheader *fwh = (void *)data; |
| 924 | |
| 925 | bincmd = le32_to_cpu(fwh->dnldcmd); |
| 926 | blksize = le32_to_cpu(fwh->datalength); |
| 927 | switch (bincmd) { |
| 928 | case FW_HAS_DATA_TO_RECV: |
| 929 | offset = sizeof(struct fwheader) + blksize; |
| 930 | data += offset; |
| 931 | len += offset; |
| 932 | if (len >= totlen) |
| 933 | exit = 1; |
| 934 | break; |
| 935 | case FW_HAS_LAST_BLOCK: |
| 936 | exit = 1; |
| 937 | ret = 0; |
| 938 | break; |
| 939 | default: |
| 940 | exit = 1; |
| 941 | break; |
| 942 | } |
| 943 | } while (!exit); |
| 944 | |
| 945 | if (ret) |
| 946 | lbs_pr_err("firmware file format check FAIL\n"); |
| 947 | else |
| 948 | lbs_deb_fw("firmware file format check PASS\n"); |
| 949 | |
| 950 | return ret; |
| 951 | } |
| 952 | |
| 953 | |
| 954 | static int if_usb_prog_firmware(wlan_private *priv) |
| 955 | { |
| 956 | int ret = -1; |
| 957 | |
| 958 | lbs_deb_enter(LBS_DEB_FW); |
| 959 | |
| 960 | if ((ret = request_firmware(&priv->firmware, libertas_fw_name, |
| 961 | priv->hotplug_device)) < 0) { |
| 962 | lbs_pr_err("request_firmware() failed with %#x\n", ret); |
| 963 | lbs_pr_err("firmware %s not found\n", libertas_fw_name); |
| 964 | goto done; |
| 965 | } |
| 966 | |
| 967 | if (check_fwfile_format(priv->firmware->data, priv->firmware->size)) { |
| 968 | release_firmware(priv->firmware); |
| 969 | goto done; |
| 970 | } |
| 971 | |
| 972 | ret = if_usb_do_prog_firmware(priv); |
| 973 | |
| 974 | release_firmware(priv->firmware); |
| 975 | done: |
| 976 | return ret; |
| 977 | } |
| 978 | |
| 979 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 980 | #ifdef CONFIG_PM |
| 981 | static int if_usb_suspend(struct usb_interface *intf, pm_message_t message) |
| 982 | { |
| 983 | struct usb_card_rec *cardp = usb_get_intfdata(intf); |
| 984 | wlan_private *priv = cardp->priv; |
| 985 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 986 | lbs_deb_enter(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 987 | |
| 988 | if (priv->adapter->psstate != PS_STATE_FULL_POWER) |
| 989 | return -1; |
| 990 | |
| 991 | netif_device_detach(cardp->eth_dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 992 | netif_device_detach(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 993 | |
| 994 | /* Unlink tx & rx urb */ |
| 995 | usb_kill_urb(cardp->tx_urb); |
| 996 | usb_kill_urb(cardp->rx_urb); |
| 997 | |
| 998 | cardp->rx_urb_recall = 1; |
| 999 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1000 | lbs_deb_leave(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | static int if_usb_resume(struct usb_interface *intf) |
| 1005 | { |
| 1006 | struct usb_card_rec *cardp = usb_get_intfdata(intf); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 1007 | wlan_private *priv = cardp->priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1008 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1009 | lbs_deb_enter(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1010 | |
| 1011 | cardp->rx_urb_recall = 0; |
| 1012 | |
| 1013 | if_usb_submit_rx_urb(cardp->priv); |
| 1014 | |
| 1015 | netif_device_attach(cardp->eth_dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 1016 | netif_device_attach(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1017 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1018 | lbs_deb_leave(LBS_DEB_USB); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1019 | return 0; |
| 1020 | } |
| 1021 | #else |
| 1022 | #define if_usb_suspend NULL |
| 1023 | #define if_usb_resume NULL |
| 1024 | #endif |
| 1025 | |
| 1026 | static struct usb_driver if_usb_driver = { |
| 1027 | /* driver name */ |
| 1028 | .name = usbdriver_name, |
| 1029 | /* probe function name */ |
| 1030 | .probe = if_usb_probe, |
| 1031 | /* disconnect function name */ |
| 1032 | .disconnect = if_usb_disconnect, |
| 1033 | /* device signature table */ |
| 1034 | .id_table = if_usb_table, |
| 1035 | .suspend = if_usb_suspend, |
| 1036 | .resume = if_usb_resume, |
| 1037 | }; |
| 1038 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1039 | static int if_usb_init_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1040 | { |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1041 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1042 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1043 | lbs_deb_enter(LBS_DEB_MAIN); |
| 1044 | |
| 1045 | if (libertas_fw_name == NULL) { |
| 1046 | libertas_fw_name = default_fw_name; |
| 1047 | } |
| 1048 | |
| 1049 | ret = usb_register(&if_usb_driver); |
| 1050 | |
| 1051 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
| 1052 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1053 | } |
| 1054 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1055 | static void if_usb_exit_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1056 | { |
Marcelo Tosatti | d43fb8e | 2007-05-25 16:28:20 -0400 | [diff] [blame] | 1057 | struct usb_card_rec *cardp, *cardp_temp; |
Holger Schurig | 3874d0f | 2007-05-25 12:01:42 -0400 | [diff] [blame] | 1058 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1059 | lbs_deb_enter(LBS_DEB_MAIN); |
| 1060 | |
Marcelo Tosatti | d43fb8e | 2007-05-25 16:28:20 -0400 | [diff] [blame] | 1061 | list_for_each_entry_safe(cardp, cardp_temp, &usb_devices, list) |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 1062 | libertas_reset_device((wlan_private *) cardp->priv); |
Holger Schurig | 3874d0f | 2007-05-25 12:01:42 -0400 | [diff] [blame] | 1063 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1064 | /* API unregisters the driver from USB subsystem */ |
| 1065 | usb_deregister(&if_usb_driver); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1066 | |
| 1067 | lbs_deb_leave(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1068 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1069 | |
| 1070 | module_init(if_usb_init_module); |
| 1071 | module_exit(if_usb_exit_module); |
| 1072 | |
| 1073 | MODULE_DESCRIPTION("8388 USB WLAN Driver"); |
| 1074 | MODULE_AUTHOR("Marvell International Ltd."); |
| 1075 | MODULE_LICENSE("GPL"); |