| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* This file contains functions used in USB interface module. |
| 4 |
*/ |
| 5 |
|
| 6 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 7 |
|
| 8 |
#include <linux/delay.h> |
| 9 |
#include <linux/module.h> |
| 10 |
#include <linux/firmware.h> |
| 11 |
#include <linux/netdevice.h> |
| 12 |
#include <linux/slab.h> |
| 13 |
#include <linux/usb.h> |
| 14 |
#include <linux/olpc-ec.h> |
| 15 |
|
| 16 |
#ifdef CONFIG_OLPC |
| 17 |
#include <asm/olpc.h> |
| 18 |
#endif |
| 19 |
|
| 20 |
#define DRV_NAME "usb8xxx" |
| 21 |
|
| 22 |
#include "host.h" |
| 23 |
#include "decl.h" |
| 24 |
#include "defs.h" |
| 25 |
#include "dev.h" |
| 26 |
#include "cmd.h" |
| 27 |
#include "if_usb.h" |
| 28 |
|
| 29 |
#define INSANEDEBUG 0 |
| 30 |
#define lbs_deb_usb2(...) do { if (INSANEDEBUG) lbs_deb_usbd(__VA_ARGS__); } while (0) |
| 31 |
|
| 32 |
#define MESSAGE_HEADER_LEN 4 |
| 33 |
|
| 34 |
MODULE_FIRMWARE("libertas/usb8388_v9.bin"); |
| 35 |
MODULE_FIRMWARE("libertas/usb8388_v5.bin"); |
| 36 |
MODULE_FIRMWARE("libertas/usb8388.bin"); |
| 37 |
MODULE_FIRMWARE("libertas/usb8682.bin"); |
| 38 |
MODULE_FIRMWARE("usb8388.bin"); |
| 39 |
|
| 40 |
enum { |
| 41 |
MODEL_UNKNOWN = 0x0, |
| 42 |
MODEL_8388 = 0x1, |
| 43 |
MODEL_8682 = 0x2 |
| 44 |
}; |
| 45 |
|
| 46 |
/* table of firmware file names */ |
| 47 |
static const struct lbs_fw_table fw_table[] = { |
| 48 |
{ MODEL_8388, "libertas/usb8388_olpc.bin", NULL }, |
| 49 |
{ MODEL_8388, "libertas/usb8388_v9.bin", NULL }, |
| 50 |
{ MODEL_8388, "libertas/usb8388_v5.bin", NULL }, |
| 51 |
{ MODEL_8388, "libertas/usb8388.bin", NULL }, |
| 52 |
{ MODEL_8388, "usb8388.bin", NULL }, |
| 53 |
{ MODEL_8682, "libertas/usb8682.bin", NULL }, |
| 54 |
{ 0, NULL, NULL } |
| 55 |
}; |
| 56 |
|
| 57 |
static const struct usb_device_id if_usb_table[] = { |
| 58 |
/* Enter the device signature inside */ |
| 59 |
{ USB_DEVICE(0x1286, 0x2001), .driver_info = MODEL_8388 }, |
| 60 |
{ USB_DEVICE(0x05a3, 0x8388), .driver_info = MODEL_8388 }, |
| 61 |
{} /* Terminating entry */ |
| 62 |
}; |
| 63 |
|
| 64 |
MODULE_DEVICE_TABLE(usb, if_usb_table); |
| 65 |
|
| 66 |
static void if_usb_receive(struct urb *urb); |
| 67 |
static void if_usb_receive_fwload(struct urb *urb); |
| 68 |
static void if_usb_prog_firmware(struct lbs_private *priv, int ret, |
| 69 |
const struct firmware *fw, |
| 70 |
const struct firmware *unused); |
| 71 |
static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type, |
| 72 |
uint8_t *payload, uint16_t nb); |
| 73 |
static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload, |
| 74 |
uint16_t nb); |
| 75 |
static void if_usb_free(struct if_usb_card *cardp); |
| 76 |
static int if_usb_submit_rx_urb(struct if_usb_card *cardp); |
| 77 |
static int if_usb_reset_device(struct if_usb_card *cardp); |
| 78 |
|
| 79 |
/** |
| 80 |
* if_usb_write_bulk_callback - callback function to handle the status |
| 81 |
* of the URB |
| 82 |
* @urb: pointer to &urb structure |
| 83 |
* returns: N/A |
| 84 |
*/ |
| 85 |
static void if_usb_write_bulk_callback(struct urb *urb) |
| 86 |
{ |
| 87 |
struct if_usb_card *cardp = (struct if_usb_card *) urb->context; |
| 88 |
|
| 89 |
/* handle the transmission complete validations */ |
| 90 |
|
| 91 |
if (urb->status == 0) { |
| 92 |
struct lbs_private *priv = cardp->priv; |
| 93 |
|
| 94 |
lbs_deb_usb2(&urb->dev->dev, "URB status is successful\n"); |
| 95 |
lbs_deb_usb2(&urb->dev->dev, "Actual length transmitted %d\n", |
| 96 |
urb->actual_length); |
| 97 |
|
| 98 |
/* Boot commands such as UPDATE_FW and UPDATE_BOOT2 are not |
| 99 |
* passed up to the lbs level. |
| 100 |
*/ |
| 101 |
if (priv && priv->dnld_sent != DNLD_BOOTCMD_SENT) |
| 102 |
lbs_host_to_card_done(priv); |
| 103 |
} else { |
| 104 |
/* print the failure status number for debug */ |
| 105 |
pr_info("URB in failure status: %d\n", urb->status); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* if_usb_free - free tx/rx urb, skb and rx buffer |
| 111 |
* @cardp: pointer to &if_usb_card |
| 112 |
* returns: N/A |
| 113 |
*/ |
| 114 |
static void if_usb_free(struct if_usb_card *cardp) |
| 115 |
{ |
| 116 |
/* Unlink tx & rx urb */ |
| 117 |
usb_kill_anchored_urbs(&cardp->tx_submitted); |
| 118 |
usb_kill_anchored_urbs(&cardp->rx_submitted); |
| 119 |
|
| 120 |
usb_free_urb(cardp->tx_urb); |
| 121 |
cardp->tx_urb = NULL; |
| 122 |
|
| 123 |
usb_free_urb(cardp->rx_urb); |
| 124 |
cardp->rx_urb = NULL; |
| 125 |
|
| 126 |
kfree(cardp->ep_out_buf); |
| 127 |
cardp->ep_out_buf = NULL; |
| 128 |
} |
| 129 |
|
| 130 |
static void if_usb_setup_firmware(struct lbs_private *priv) |
| 131 |
{ |
| 132 |
struct if_usb_card *cardp = priv->card; |
| 133 |
struct cmd_ds_set_boot2_ver b2_cmd; |
| 134 |
struct cmd_ds_802_11_fw_wake_method wake_method; |
| 135 |
|
| 136 |
b2_cmd.hdr.size = cpu_to_le16(sizeof(b2_cmd)); |
| 137 |
b2_cmd.action = 0; |
| 138 |
b2_cmd.version = cardp->boot2_version; |
| 139 |
|
| 140 |
if (lbs_cmd_with_response(priv, CMD_SET_BOOT2_VER, &b2_cmd)) |
| 141 |
lbs_deb_usb("Setting boot2 version failed\n"); |
| 142 |
|
| 143 |
priv->wol_gpio = 2; /* Wake via GPIO2... */ |
| 144 |
priv->wol_gap = 20; /* ... after 20ms */ |
| 145 |
lbs_host_sleep_cfg(priv, EHS_WAKE_ON_UNICAST_DATA, |
| 146 |
(struct wol_config *) NULL); |
| 147 |
|
| 148 |
wake_method.hdr.size = cpu_to_le16(sizeof(wake_method)); |
| 149 |
wake_method.action = cpu_to_le16(CMD_ACT_GET); |
| 150 |
if (lbs_cmd_with_response(priv, CMD_802_11_FW_WAKE_METHOD, &wake_method)) { |
| 151 |
netdev_info(priv->dev, "Firmware does not seem to support PS mode\n"); |
| 152 |
priv->fwcapinfo &= ~FW_CAPINFO_PS; |
| 153 |
} else { |
| 154 |
if (le16_to_cpu(wake_method.method) == CMD_WAKE_METHOD_COMMAND_INT) { |
| 155 |
lbs_deb_usb("Firmware seems to support PS with wake-via-command\n"); |
| 156 |
} else { |
| 157 |
/* The versions which boot up this way don't seem to |
| 158 |
work even if we set it to the command interrupt */ |
| 159 |
priv->fwcapinfo &= ~FW_CAPINFO_PS; |
| 160 |
netdev_info(priv->dev, |
| 161 |
"Firmware doesn't wake via command interrupt; disabling PS mode\n"); |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
static void if_usb_fw_timeo(struct timer_list *t) |
| 167 |
{ |
| 168 |
struct if_usb_card *cardp = timer_container_of(cardp, t, fw_timeout); |
| 169 |
|
| 170 |
if (cardp->fwdnldover) { |
| 171 |
lbs_deb_usb("Download complete, no event. Assuming success\n"); |
| 172 |
} else { |
| 173 |
pr_err("Download timed out\n"); |
| 174 |
cardp->surprise_removed = 1; |
| 175 |
} |
| 176 |
wake_up(&cardp->fw_wq); |
| 177 |
} |
| 178 |
|
| 179 |
#ifdef CONFIG_OLPC |
| 180 |
static void if_usb_reset_olpc_card(struct lbs_private *priv) |
| 181 |
{ |
| 182 |
printk(KERN_CRIT "Resetting OLPC wireless via EC...\n"); |
| 183 |
olpc_ec_cmd(0x25, NULL, 0, NULL, 0); |
| 184 |
} |
| 185 |
#endif |
| 186 |
|
| 187 |
/** |
| 188 |
* if_usb_probe - sets the configuration values |
| 189 |
* @intf: &usb_interface pointer |
| 190 |
* @id: pointer to usb_device_id |
| 191 |
* returns: 0 on success, error code on failure |
| 192 |
*/ |
| 193 |
static int if_usb_probe(struct usb_interface *intf, |
| 194 |
const struct usb_device_id *id) |
| 195 |
{ |
| 196 |
struct usb_device *udev; |
| 197 |
struct usb_host_interface *iface_desc; |
| 198 |
struct usb_endpoint_descriptor *endpoint; |
| 199 |
struct lbs_private *priv; |
| 200 |
struct if_usb_card *cardp; |
| 201 |
int r = -ENOMEM; |
| 202 |
int i; |
| 203 |
|
| 204 |
udev = interface_to_usbdev(intf); |
| 205 |
|
| 206 |
cardp = kzalloc_obj(struct if_usb_card); |
| 207 |
if (!cardp) |
| 208 |
goto error; |
| 209 |
|
| 210 |
timer_setup(&cardp->fw_timeout, if_usb_fw_timeo, 0); |
| 211 |
init_waitqueue_head(&cardp->fw_wq); |
| 212 |
|
| 213 |
cardp->udev = udev; |
| 214 |
cardp->model = (uint32_t) id->driver_info; |
| 215 |
iface_desc = intf->cur_altsetting; |
| 216 |
|
| 217 |
lbs_deb_usbd(&udev->dev, "bcdUSB = 0x%X bDeviceClass = 0x%X" |
| 218 |
" bDeviceSubClass = 0x%X, bDeviceProtocol = 0x%X\n", |
| 219 |
le16_to_cpu(udev->descriptor.bcdUSB), |
| 220 |
udev->descriptor.bDeviceClass, |
| 221 |
udev->descriptor.bDeviceSubClass, |
| 222 |
udev->descriptor.bDeviceProtocol); |
| 223 |
|
| 224 |
init_usb_anchor(&cardp->rx_submitted); |
| 225 |
init_usb_anchor(&cardp->tx_submitted); |
| 226 |
|
| 227 |
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { |
| 228 |
endpoint = &iface_desc->endpoint[i].desc; |
| 229 |
if (usb_endpoint_is_bulk_in(endpoint)) { |
| 230 |
cardp->ep_in_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 231 |
cardp->ep_in = usb_endpoint_num(endpoint); |
| 232 |
|
| 233 |
lbs_deb_usbd(&udev->dev, "in_endpoint = %d\n", cardp->ep_in); |
| 234 |
lbs_deb_usbd(&udev->dev, "Bulk in size is %d\n", cardp->ep_in_size); |
| 235 |
|
| 236 |
} else if (usb_endpoint_is_bulk_out(endpoint)) { |
| 237 |
cardp->ep_out_size = le16_to_cpu(endpoint->wMaxPacketSize); |
| 238 |
cardp->ep_out = usb_endpoint_num(endpoint); |
| 239 |
|
| 240 |
lbs_deb_usbd(&udev->dev, "out_endpoint = %d\n", cardp->ep_out); |
| 241 |
lbs_deb_usbd(&udev->dev, "Bulk out size is %d\n", cardp->ep_out_size); |
| 242 |
} |
| 243 |
} |
| 244 |
if (!cardp->ep_out_size || !cardp->ep_in_size) { |
| 245 |
lbs_deb_usbd(&udev->dev, "Endpoints not found\n"); |
| 246 |
goto dealloc; |
| 247 |
} |
| 248 |
if (!(cardp->rx_urb = usb_alloc_urb(0, GFP_KERNEL))) { |
| 249 |
lbs_deb_usbd(&udev->dev, "Rx URB allocation failed\n"); |
| 250 |
goto dealloc; |
| 251 |
} |
| 252 |
if (!(cardp->tx_urb = usb_alloc_urb(0, GFP_KERNEL))) { |
| 253 |
lbs_deb_usbd(&udev->dev, "Tx URB allocation failed\n"); |
| 254 |
goto dealloc; |
| 255 |
} |
| 256 |
cardp->ep_out_buf = kmalloc(MRVDRV_ETH_TX_PACKET_BUFFER_SIZE, GFP_KERNEL); |
| 257 |
if (!cardp->ep_out_buf) { |
| 258 |
lbs_deb_usbd(&udev->dev, "Could not allocate buffer\n"); |
| 259 |
goto dealloc; |
| 260 |
} |
| 261 |
|
| 262 |
priv = lbs_add_card(cardp, &intf->dev); |
| 263 |
if (IS_ERR(priv)) { |
| 264 |
r = PTR_ERR(priv); |
| 265 |
goto err_add_card; |
| 266 |
} |
| 267 |
|
| 268 |
cardp->priv = priv; |
| 269 |
|
| 270 |
priv->hw_host_to_card = if_usb_host_to_card; |
| 271 |
priv->enter_deep_sleep = NULL; |
| 272 |
priv->exit_deep_sleep = NULL; |
| 273 |
priv->reset_deep_sleep_wakeup = NULL; |
| 274 |
priv->is_polling = false; |
| 275 |
#ifdef CONFIG_OLPC |
| 276 |
if (machine_is_olpc()) |
| 277 |
priv->reset_card = if_usb_reset_olpc_card; |
| 278 |
#endif |
| 279 |
|
| 280 |
cardp->boot2_version = udev->descriptor.bcdDevice; |
| 281 |
|
| 282 |
usb_get_dev(udev); |
| 283 |
usb_set_intfdata(intf, cardp); |
| 284 |
|
| 285 |
r = lbs_get_firmware_async(priv, &udev->dev, cardp->model, |
| 286 |
fw_table, if_usb_prog_firmware); |
| 287 |
if (r) |
| 288 |
goto err_get_fw; |
| 289 |
|
| 290 |
return 0; |
| 291 |
|
| 292 |
err_get_fw: |
| 293 |
usb_put_dev(udev); |
| 294 |
lbs_remove_card(priv); |
| 295 |
err_add_card: |
| 296 |
if_usb_reset_device(cardp); |
| 297 |
dealloc: |
| 298 |
if_usb_free(cardp); |
| 299 |
kfree(cardp); |
| 300 |
|
| 301 |
error: |
| 302 |
return r; |
| 303 |
} |
| 304 |
|
| 305 |
/** |
| 306 |
* if_usb_disconnect - free resource and cleanup |
| 307 |
* @intf: USB interface structure |
| 308 |
* returns: N/A |
| 309 |
*/ |
| 310 |
static void if_usb_disconnect(struct usb_interface *intf) |
| 311 |
{ |
| 312 |
struct if_usb_card *cardp = usb_get_intfdata(intf); |
| 313 |
struct lbs_private *priv = cardp->priv; |
| 314 |
|
| 315 |
cardp->surprise_removed = 1; |
| 316 |
|
| 317 |
if (priv) { |
| 318 |
lbs_stop_card(priv); |
| 319 |
lbs_remove_card(priv); |
| 320 |
} |
| 321 |
|
| 322 |
/* Unlink and free urb */ |
| 323 |
if_usb_free(cardp); |
| 324 |
kfree(cardp); |
| 325 |
|
| 326 |
usb_set_intfdata(intf, NULL); |
| 327 |
usb_put_dev(interface_to_usbdev(intf)); |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* if_usb_send_fw_pkt - download FW |
| 332 |
* @cardp: pointer to &struct if_usb_card |
| 333 |
* returns: 0 |
| 334 |
*/ |
| 335 |
static int if_usb_send_fw_pkt(struct if_usb_card *cardp) |
| 336 |
{ |
| 337 |
struct fwdata *fwdata = cardp->ep_out_buf; |
| 338 |
const uint8_t *firmware = cardp->fw->data; |
| 339 |
|
| 340 |
/* If we got a CRC failure on the last block, back |
| 341 |
up and retry it */ |
| 342 |
if (!cardp->CRC_OK) { |
| 343 |
cardp->totalbytes = cardp->fwlastblksent; |
| 344 |
cardp->fwseqnum--; |
| 345 |
} |
| 346 |
|
| 347 |
lbs_deb_usb2(&cardp->udev->dev, "totalbytes = %d\n", |
| 348 |
cardp->totalbytes); |
| 349 |
|
| 350 |
/* struct fwdata (which we sent to the card) has an |
| 351 |
extra __le32 field in between the header and the data, |
| 352 |
which is not in the struct fwheader in the actual |
| 353 |
firmware binary. Insert the seqnum in the middle... */ |
| 354 |
memcpy(&fwdata->hdr, &firmware[cardp->totalbytes], |
| 355 |
sizeof(struct fwheader)); |
| 356 |
|
| 357 |
cardp->fwlastblksent = cardp->totalbytes; |
| 358 |
cardp->totalbytes += sizeof(struct fwheader); |
| 359 |
|
| 360 |
memcpy(fwdata->data, &firmware[cardp->totalbytes], |
| 361 |
le32_to_cpu(fwdata->hdr.datalength)); |
| 362 |
|
| 363 |
lbs_deb_usb2(&cardp->udev->dev, "Data length = %d\n", |
| 364 |
le32_to_cpu(fwdata->hdr.datalength)); |
| 365 |
|
| 366 |
fwdata->seqnum = cpu_to_le32(++cardp->fwseqnum); |
| 367 |
cardp->totalbytes += le32_to_cpu(fwdata->hdr.datalength); |
| 368 |
|
| 369 |
usb_tx_block(cardp, cardp->ep_out_buf, sizeof(struct fwdata) + |
| 370 |
le32_to_cpu(fwdata->hdr.datalength)); |
| 371 |
|
| 372 |
if (fwdata->hdr.dnldcmd == cpu_to_le32(FW_HAS_DATA_TO_RECV)) { |
| 373 |
lbs_deb_usb2(&cardp->udev->dev, "There are data to follow\n"); |
| 374 |
lbs_deb_usb2(&cardp->udev->dev, "seqnum = %d totalbytes = %d\n", |
| 375 |
cardp->fwseqnum, cardp->totalbytes); |
| 376 |
} else if (fwdata->hdr.dnldcmd == cpu_to_le32(FW_HAS_LAST_BLOCK)) { |
| 377 |
lbs_deb_usb2(&cardp->udev->dev, "Host has finished FW downloading\n"); |
| 378 |
lbs_deb_usb2(&cardp->udev->dev, "Downloading FW JUMP BLOCK\n"); |
| 379 |
|
| 380 |
cardp->fwfinalblk = 1; |
| 381 |
} |
| 382 |
|
| 383 |
lbs_deb_usb2(&cardp->udev->dev, "Firmware download done; size %d\n", |
| 384 |
cardp->totalbytes); |
| 385 |
|
| 386 |
return 0; |
| 387 |
} |
| 388 |
|
| 389 |
static int if_usb_reset_device(struct if_usb_card *cardp) |
| 390 |
{ |
| 391 |
struct cmd_header *cmd = cardp->ep_out_buf + 4; |
| 392 |
int ret; |
| 393 |
|
| 394 |
*(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_REQUEST); |
| 395 |
|
| 396 |
cmd->command = cpu_to_le16(CMD_802_11_RESET); |
| 397 |
cmd->size = cpu_to_le16(sizeof(cmd)); |
| 398 |
cmd->result = cpu_to_le16(0); |
| 399 |
cmd->seqnum = cpu_to_le16(0x5a5a); |
| 400 |
usb_tx_block(cardp, cardp->ep_out_buf, 4 + sizeof(struct cmd_header)); |
| 401 |
|
| 402 |
msleep(100); |
| 403 |
ret = usb_reset_device(cardp->udev); |
| 404 |
msleep(100); |
| 405 |
|
| 406 |
#ifdef CONFIG_OLPC |
| 407 |
if (ret && machine_is_olpc()) |
| 408 |
if_usb_reset_olpc_card(NULL); |
| 409 |
#endif |
| 410 |
|
| 411 |
return ret; |
| 412 |
} |
| 413 |
|
| 414 |
/** |
| 415 |
* usb_tx_block - transfer the data to the device |
| 416 |
* @cardp: pointer to &struct if_usb_card |
| 417 |
* @payload: pointer to payload data |
| 418 |
* @nb: data length |
| 419 |
* returns: 0 for success or negative error code |
| 420 |
*/ |
| 421 |
static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload, uint16_t nb) |
| 422 |
{ |
| 423 |
int ret; |
| 424 |
|
| 425 |
/* check if device is removed */ |
| 426 |
if (cardp->surprise_removed) { |
| 427 |
lbs_deb_usbd(&cardp->udev->dev, "Device removed\n"); |
| 428 |
ret = -ENODEV; |
| 429 |
goto tx_ret; |
| 430 |
} |
| 431 |
|
| 432 |
/* check if there are pending URBs */ |
| 433 |
if (!usb_anchor_empty(&cardp->tx_submitted)) { |
| 434 |
lbs_deb_usbd(&cardp->udev->dev, "%s failed: pending URB\n", __func__); |
| 435 |
ret = -EBUSY; |
| 436 |
goto tx_ret; |
| 437 |
} |
| 438 |
|
| 439 |
usb_fill_bulk_urb(cardp->tx_urb, cardp->udev, |
| 440 |
usb_sndbulkpipe(cardp->udev, |
| 441 |
cardp->ep_out), |
| 442 |
payload, nb, if_usb_write_bulk_callback, cardp); |
| 443 |
|
| 444 |
cardp->tx_urb->transfer_flags |= URB_ZERO_PACKET; |
| 445 |
|
| 446 |
usb_anchor_urb(cardp->tx_urb, &cardp->tx_submitted); |
| 447 |
if ((ret = usb_submit_urb(cardp->tx_urb, GFP_ATOMIC))) { |
| 448 |
lbs_deb_usbd(&cardp->udev->dev, "usb_submit_urb failed: %d\n", ret); |
| 449 |
usb_unanchor_urb(cardp->tx_urb); |
| 450 |
} else { |
| 451 |
lbs_deb_usb2(&cardp->udev->dev, "usb_submit_urb success\n"); |
| 452 |
ret = 0; |
| 453 |
} |
| 454 |
|
| 455 |
tx_ret: |
| 456 |
return ret; |
| 457 |
} |
| 458 |
|
| 459 |
static int __if_usb_submit_rx_urb(struct if_usb_card *cardp, |
| 460 |
void (*callbackfn)(struct urb *urb)) |
| 461 |
{ |
| 462 |
struct sk_buff *skb; |
| 463 |
int ret = -1; |
| 464 |
|
| 465 |
if (!(skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE))) { |
| 466 |
pr_err("No free skb\n"); |
| 467 |
goto rx_ret; |
| 468 |
} |
| 469 |
|
| 470 |
cardp->rx_skb = skb; |
| 471 |
|
| 472 |
/* Fill the receive configuration URB and initialise the Rx call back */ |
| 473 |
usb_fill_bulk_urb(cardp->rx_urb, cardp->udev, |
| 474 |
usb_rcvbulkpipe(cardp->udev, cardp->ep_in), |
| 475 |
skb->data + IPFIELD_ALIGN_OFFSET, |
| 476 |
MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn, |
| 477 |
cardp); |
| 478 |
|
| 479 |
lbs_deb_usb2(&cardp->udev->dev, "Pointer for rx_urb %p\n", cardp->rx_urb); |
| 480 |
usb_anchor_urb(cardp->rx_urb, &cardp->rx_submitted); |
| 481 |
if ((ret = usb_submit_urb(cardp->rx_urb, GFP_ATOMIC))) { |
| 482 |
lbs_deb_usbd(&cardp->udev->dev, "Submit Rx URB failed: %d\n", ret); |
| 483 |
usb_unanchor_urb(cardp->rx_urb); |
| 484 |
kfree_skb(skb); |
| 485 |
cardp->rx_skb = NULL; |
| 486 |
ret = -1; |
| 487 |
} else { |
| 488 |
lbs_deb_usb2(&cardp->udev->dev, "Submit Rx URB success\n"); |
| 489 |
ret = 0; |
| 490 |
} |
| 491 |
|
| 492 |
rx_ret: |
| 493 |
return ret; |
| 494 |
} |
| 495 |
|
| 496 |
static int if_usb_submit_rx_urb_fwload(struct if_usb_card *cardp) |
| 497 |
{ |
| 498 |
return __if_usb_submit_rx_urb(cardp, &if_usb_receive_fwload); |
| 499 |
} |
| 500 |
|
| 501 |
static int if_usb_submit_rx_urb(struct if_usb_card *cardp) |
| 502 |
{ |
| 503 |
return __if_usb_submit_rx_urb(cardp, &if_usb_receive); |
| 504 |
} |
| 505 |
|
| 506 |
static void if_usb_receive_fwload(struct urb *urb) |
| 507 |
{ |
| 508 |
struct if_usb_card *cardp = urb->context; |
| 509 |
struct sk_buff *skb = cardp->rx_skb; |
| 510 |
struct fwsyncheader *syncfwheader; |
| 511 |
struct bootcmdresp bootcmdresp; |
| 512 |
|
| 513 |
if (urb->status) { |
| 514 |
lbs_deb_usbd(&cardp->udev->dev, |
| 515 |
"URB status is failed during fw load\n"); |
| 516 |
kfree_skb(skb); |
| 517 |
return; |
| 518 |
} |
| 519 |
|
| 520 |
if (cardp->fwdnldover) { |
| 521 |
__le32 *tmp = (__le32 *)(skb->data + IPFIELD_ALIGN_OFFSET); |
| 522 |
|
| 523 |
if (tmp[0] == cpu_to_le32(CMD_TYPE_INDICATION) && |
| 524 |
tmp[1] == cpu_to_le32(MACREG_INT_CODE_FIRMWARE_READY)) { |
| 525 |
pr_info("Firmware ready event received\n"); |
| 526 |
wake_up(&cardp->fw_wq); |
| 527 |
} else { |
| 528 |
lbs_deb_usb("Waiting for confirmation; got %x %x\n", |
| 529 |
le32_to_cpu(tmp[0]), le32_to_cpu(tmp[1])); |
| 530 |
if_usb_submit_rx_urb_fwload(cardp); |
| 531 |
} |
| 532 |
kfree_skb(skb); |
| 533 |
return; |
| 534 |
} |
| 535 |
if (cardp->bootcmdresp <= 0) { |
| 536 |
memcpy (&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET, |
| 537 |
sizeof(bootcmdresp)); |
| 538 |
|
| 539 |
if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) { |
| 540 |
kfree_skb(skb); |
| 541 |
if_usb_submit_rx_urb_fwload(cardp); |
| 542 |
cardp->bootcmdresp = BOOT_CMD_RESP_OK; |
| 543 |
lbs_deb_usbd(&cardp->udev->dev, |
| 544 |
"Received valid boot command response\n"); |
| 545 |
return; |
| 546 |
} |
| 547 |
if (bootcmdresp.magic != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) { |
| 548 |
if (bootcmdresp.magic == cpu_to_le32(CMD_TYPE_REQUEST) || |
| 549 |
bootcmdresp.magic == cpu_to_le32(CMD_TYPE_DATA) || |
| 550 |
bootcmdresp.magic == cpu_to_le32(CMD_TYPE_INDICATION)) { |
| 551 |
if (!cardp->bootcmdresp) |
| 552 |
pr_info("Firmware already seems alive; resetting\n"); |
| 553 |
cardp->bootcmdresp = -1; |
| 554 |
} else { |
| 555 |
pr_info("boot cmd response wrong magic number (0x%x)\n", |
| 556 |
le32_to_cpu(bootcmdresp.magic)); |
| 557 |
} |
| 558 |
} else if ((bootcmdresp.cmd != BOOT_CMD_FW_BY_USB) && |
| 559 |
(bootcmdresp.cmd != BOOT_CMD_UPDATE_FW) && |
| 560 |
(bootcmdresp.cmd != BOOT_CMD_UPDATE_BOOT2)) { |
| 561 |
pr_info("boot cmd response cmd_tag error (%d)\n", |
| 562 |
bootcmdresp.cmd); |
| 563 |
} else if (bootcmdresp.result != BOOT_CMD_RESP_OK) { |
| 564 |
pr_info("boot cmd response result error (%d)\n", |
| 565 |
bootcmdresp.result); |
| 566 |
} else { |
| 567 |
cardp->bootcmdresp = 1; |
| 568 |
lbs_deb_usbd(&cardp->udev->dev, |
| 569 |
"Received valid boot command response\n"); |
| 570 |
} |
| 571 |
kfree_skb(skb); |
| 572 |
if_usb_submit_rx_urb_fwload(cardp); |
| 573 |
return; |
| 574 |
} |
| 575 |
|
| 576 |
syncfwheader = kmemdup(skb->data + IPFIELD_ALIGN_OFFSET, |
| 577 |
sizeof(struct fwsyncheader), GFP_ATOMIC); |
| 578 |
if (!syncfwheader) { |
| 579 |
lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n"); |
| 580 |
kfree_skb(skb); |
| 581 |
return; |
| 582 |
} |
| 583 |
|
| 584 |
if (!syncfwheader->cmd) { |
| 585 |
lbs_deb_usb2(&cardp->udev->dev, "FW received Blk with correct CRC\n"); |
| 586 |
lbs_deb_usb2(&cardp->udev->dev, "FW received Blk seqnum = %d\n", |
| 587 |
le32_to_cpu(syncfwheader->seqnum)); |
| 588 |
cardp->CRC_OK = 1; |
| 589 |
} else { |
| 590 |
lbs_deb_usbd(&cardp->udev->dev, "FW received Blk with CRC error\n"); |
| 591 |
cardp->CRC_OK = 0; |
| 592 |
} |
| 593 |
|
| 594 |
kfree_skb(skb); |
| 595 |
|
| 596 |
/* Give device 5s to either write firmware to its RAM or eeprom */ |
| 597 |
mod_timer(&cardp->fw_timeout, jiffies + (HZ*5)); |
| 598 |
|
| 599 |
if (cardp->fwfinalblk) { |
| 600 |
cardp->fwdnldover = 1; |
| 601 |
goto exit; |
| 602 |
} |
| 603 |
|
| 604 |
if_usb_send_fw_pkt(cardp); |
| 605 |
|
| 606 |
exit: |
| 607 |
if_usb_submit_rx_urb_fwload(cardp); |
| 608 |
|
| 609 |
kfree(syncfwheader); |
| 610 |
} |
| 611 |
|
| 612 |
#define MRVDRV_MIN_PKT_LEN 30 |
| 613 |
|
| 614 |
static inline void process_cmdtypedata(int recvlength, struct sk_buff *skb, |
| 615 |
struct if_usb_card *cardp, |
| 616 |
struct lbs_private *priv) |
| 617 |
{ |
| 618 |
if (recvlength > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + MESSAGE_HEADER_LEN |
| 619 |
|| recvlength < MRVDRV_MIN_PKT_LEN) { |
| 620 |
lbs_deb_usbd(&cardp->udev->dev, "Packet length is Invalid\n"); |
| 621 |
kfree_skb(skb); |
| 622 |
return; |
| 623 |
} |
| 624 |
|
| 625 |
skb_reserve(skb, IPFIELD_ALIGN_OFFSET); |
| 626 |
skb_put(skb, recvlength); |
| 627 |
skb_pull(skb, MESSAGE_HEADER_LEN); |
| 628 |
|
| 629 |
lbs_process_rxed_packet(priv, skb); |
| 630 |
} |
| 631 |
|
| 632 |
static inline void process_cmdrequest(int recvlength, uint8_t *recvbuff, |
| 633 |
struct sk_buff *skb, |
| 634 |
struct if_usb_card *cardp, |
| 635 |
struct lbs_private *priv) |
| 636 |
{ |
| 637 |
unsigned long flags; |
| 638 |
u8 i; |
| 639 |
|
| 640 |
if (recvlength > LBS_CMD_BUFFER_SIZE) { |
| 641 |
lbs_deb_usbd(&cardp->udev->dev, |
| 642 |
"The receive buffer is too large\n"); |
| 643 |
kfree_skb(skb); |
| 644 |
return; |
| 645 |
} |
| 646 |
|
| 647 |
spin_lock_irqsave(&priv->driver_lock, flags); |
| 648 |
|
| 649 |
i = (priv->resp_idx == 0) ? 1 : 0; |
| 650 |
BUG_ON(priv->resp_len[i]); |
| 651 |
priv->resp_len[i] = (recvlength - MESSAGE_HEADER_LEN); |
| 652 |
memcpy(priv->resp_buf[i], recvbuff + MESSAGE_HEADER_LEN, |
| 653 |
priv->resp_len[i]); |
| 654 |
dev_kfree_skb_irq(skb); |
| 655 |
lbs_notify_command_response(priv, i); |
| 656 |
|
| 657 |
spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 658 |
|
| 659 |
lbs_deb_usbd(&cardp->udev->dev, |
| 660 |
"Wake up main thread to handle cmd response\n"); |
| 661 |
} |
| 662 |
|
| 663 |
/** |
| 664 |
* if_usb_receive - read the packet into the upload buffer, |
| 665 |
* wake up the main thread and initialise the Rx callack |
| 666 |
* |
| 667 |
* @urb: pointer to &struct urb |
| 668 |
* returns: N/A |
| 669 |
*/ |
| 670 |
static void if_usb_receive(struct urb *urb) |
| 671 |
{ |
| 672 |
struct if_usb_card *cardp = urb->context; |
| 673 |
struct sk_buff *skb = cardp->rx_skb; |
| 674 |
struct lbs_private *priv = cardp->priv; |
| 675 |
int recvlength = urb->actual_length; |
| 676 |
uint8_t *recvbuff = NULL; |
| 677 |
uint32_t recvtype = 0; |
| 678 |
__le32 *pkt = (__le32 *)(skb->data + IPFIELD_ALIGN_OFFSET); |
| 679 |
uint32_t event; |
| 680 |
|
| 681 |
if (recvlength) { |
| 682 |
if (urb->status) { |
| 683 |
lbs_deb_usbd(&cardp->udev->dev, "RX URB failed: %d\n", |
| 684 |
urb->status); |
| 685 |
kfree_skb(skb); |
| 686 |
goto setup_for_next; |
| 687 |
} |
| 688 |
|
| 689 |
recvbuff = skb->data + IPFIELD_ALIGN_OFFSET; |
| 690 |
recvtype = le32_to_cpu(pkt[0]); |
| 691 |
lbs_deb_usbd(&cardp->udev->dev, |
| 692 |
"Recv length = 0x%x, Recv type = 0x%X\n", |
| 693 |
recvlength, recvtype); |
| 694 |
} else if (urb->status) { |
| 695 |
kfree_skb(skb); |
| 696 |
return; |
| 697 |
} |
| 698 |
|
| 699 |
switch (recvtype) { |
| 700 |
case CMD_TYPE_DATA: |
| 701 |
process_cmdtypedata(recvlength, skb, cardp, priv); |
| 702 |
break; |
| 703 |
|
| 704 |
case CMD_TYPE_REQUEST: |
| 705 |
process_cmdrequest(recvlength, recvbuff, skb, cardp, priv); |
| 706 |
break; |
| 707 |
|
| 708 |
case CMD_TYPE_INDICATION: |
| 709 |
/* Event handling */ |
| 710 |
event = le32_to_cpu(pkt[1]); |
| 711 |
lbs_deb_usbd(&cardp->udev->dev, "**EVENT** 0x%X\n", event); |
| 712 |
kfree_skb(skb); |
| 713 |
|
| 714 |
/* Icky undocumented magic special case */ |
| 715 |
if (event & 0xffff0000) { |
| 716 |
u32 trycount = (event & 0xffff0000) >> 16; |
| 717 |
|
| 718 |
lbs_send_tx_feedback(priv, trycount); |
| 719 |
} else |
| 720 |
lbs_queue_event(priv, event & 0xFF); |
| 721 |
break; |
| 722 |
|
| 723 |
default: |
| 724 |
lbs_deb_usbd(&cardp->udev->dev, "Unknown command type 0x%X\n", |
| 725 |
recvtype); |
| 726 |
kfree_skb(skb); |
| 727 |
break; |
| 728 |
} |
| 729 |
|
| 730 |
setup_for_next: |
| 731 |
if_usb_submit_rx_urb(cardp); |
| 732 |
} |
| 733 |
|
| 734 |
/** |
| 735 |
* if_usb_host_to_card - downloads data to FW |
| 736 |
* @priv: pointer to &struct lbs_private structure |
| 737 |
* @type: type of data |
| 738 |
* @payload: pointer to data buffer |
| 739 |
* @nb: number of bytes |
| 740 |
* returns: 0 for success or negative error code |
| 741 |
*/ |
| 742 |
static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type, |
| 743 |
uint8_t *payload, uint16_t nb) |
| 744 |
{ |
| 745 |
struct if_usb_card *cardp = priv->card; |
| 746 |
|
| 747 |
lbs_deb_usbd(&cardp->udev->dev,"*** type = %u\n", type); |
| 748 |
lbs_deb_usbd(&cardp->udev->dev,"size after = %d\n", nb); |
| 749 |
|
| 750 |
if (type == MVMS_CMD) { |
| 751 |
*(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_REQUEST); |
| 752 |
priv->dnld_sent = DNLD_CMD_SENT; |
| 753 |
} else { |
| 754 |
*(__le32 *)cardp->ep_out_buf = cpu_to_le32(CMD_TYPE_DATA); |
| 755 |
priv->dnld_sent = DNLD_DATA_SENT; |
| 756 |
} |
| 757 |
|
| 758 |
memcpy((cardp->ep_out_buf + MESSAGE_HEADER_LEN), payload, nb); |
| 759 |
|
| 760 |
return usb_tx_block(cardp, cardp->ep_out_buf, nb + MESSAGE_HEADER_LEN); |
| 761 |
} |
| 762 |
|
| 763 |
/** |
| 764 |
* if_usb_issue_boot_command - issues Boot command to the Boot2 code |
| 765 |
* @cardp: pointer to &if_usb_card |
| 766 |
* @ivalue: 1:Boot from FW by USB-Download |
| 767 |
* 2:Boot from FW in EEPROM |
| 768 |
* returns: 0 for success or negative error code |
| 769 |
*/ |
| 770 |
static int if_usb_issue_boot_command(struct if_usb_card *cardp, int ivalue) |
| 771 |
{ |
| 772 |
struct bootcmd *bootcmd = cardp->ep_out_buf; |
| 773 |
|
| 774 |
/* Prepare command */ |
| 775 |
bootcmd->magic = cpu_to_le32(BOOT_CMD_MAGIC_NUMBER); |
| 776 |
bootcmd->cmd = ivalue; |
| 777 |
memset(bootcmd->pad, 0, sizeof(bootcmd->pad)); |
| 778 |
|
| 779 |
/* Issue command */ |
| 780 |
usb_tx_block(cardp, cardp->ep_out_buf, sizeof(*bootcmd)); |
| 781 |
|
| 782 |
return 0; |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
/** |
| 787 |
* check_fwfile_format - check the validity of Boot2/FW image |
| 788 |
* |
| 789 |
* @data: pointer to image |
| 790 |
* @totlen: image length |
| 791 |
* returns: 0 (good) or 1 (failure) |
| 792 |
*/ |
| 793 |
static int check_fwfile_format(const uint8_t *data, uint32_t totlen) |
| 794 |
{ |
| 795 |
uint32_t bincmd, exit; |
| 796 |
uint32_t blksize, offset, len; |
| 797 |
int ret; |
| 798 |
|
| 799 |
ret = 1; |
| 800 |
exit = len = 0; |
| 801 |
|
| 802 |
do { |
| 803 |
struct fwheader *fwh = (void *)data; |
| 804 |
|
| 805 |
bincmd = le32_to_cpu(fwh->dnldcmd); |
| 806 |
blksize = le32_to_cpu(fwh->datalength); |
| 807 |
switch (bincmd) { |
| 808 |
case FW_HAS_DATA_TO_RECV: |
| 809 |
offset = sizeof(struct fwheader) + blksize; |
| 810 |
data += offset; |
| 811 |
len += offset; |
| 812 |
if (len >= totlen) |
| 813 |
exit = 1; |
| 814 |
break; |
| 815 |
case FW_HAS_LAST_BLOCK: |
| 816 |
exit = 1; |
| 817 |
ret = 0; |
| 818 |
break; |
| 819 |
default: |
| 820 |
exit = 1; |
| 821 |
break; |
| 822 |
} |
| 823 |
} while (!exit); |
| 824 |
|
| 825 |
if (ret) |
| 826 |
pr_err("firmware file format check FAIL\n"); |
| 827 |
else |
| 828 |
lbs_deb_fw("firmware file format check PASS\n"); |
| 829 |
|
| 830 |
return ret; |
| 831 |
} |
| 832 |
|
| 833 |
static void if_usb_prog_firmware(struct lbs_private *priv, int ret, |
| 834 |
const struct firmware *fw, |
| 835 |
const struct firmware *unused) |
| 836 |
{ |
| 837 |
struct if_usb_card *cardp = priv->card; |
| 838 |
int i = 0; |
| 839 |
static int reset_count = 10; |
| 840 |
|
| 841 |
if (ret) { |
| 842 |
pr_err("failed to find firmware (%d)\n", ret); |
| 843 |
goto done; |
| 844 |
} |
| 845 |
|
| 846 |
cardp->fw = fw; |
| 847 |
if (check_fwfile_format(cardp->fw->data, cardp->fw->size)) { |
| 848 |
ret = -EINVAL; |
| 849 |
goto done; |
| 850 |
} |
| 851 |
|
| 852 |
/* Cancel any pending usb business */ |
| 853 |
usb_kill_anchored_urbs(&cardp->rx_submitted); |
| 854 |
usb_kill_anchored_urbs(&cardp->tx_submitted); |
| 855 |
|
| 856 |
cardp->fwlastblksent = 0; |
| 857 |
cardp->fwdnldover = 0; |
| 858 |
cardp->totalbytes = 0; |
| 859 |
cardp->fwfinalblk = 0; |
| 860 |
cardp->bootcmdresp = 0; |
| 861 |
|
| 862 |
restart: |
| 863 |
if (if_usb_submit_rx_urb_fwload(cardp) < 0) { |
| 864 |
lbs_deb_usbd(&cardp->udev->dev, "URB submission is failed\n"); |
| 865 |
ret = -EIO; |
| 866 |
goto done; |
| 867 |
} |
| 868 |
|
| 869 |
cardp->bootcmdresp = 0; |
| 870 |
do { |
| 871 |
int j = 0; |
| 872 |
i++; |
| 873 |
if_usb_issue_boot_command(cardp, BOOT_CMD_FW_BY_USB); |
| 874 |
/* wait for command response */ |
| 875 |
do { |
| 876 |
j++; |
| 877 |
msleep_interruptible(100); |
| 878 |
} while (cardp->bootcmdresp == 0 && j < 10); |
| 879 |
} while (cardp->bootcmdresp == 0 && i < 5); |
| 880 |
|
| 881 |
if (cardp->bootcmdresp == BOOT_CMD_RESP_NOT_SUPPORTED) { |
| 882 |
/* Return to normal operation */ |
| 883 |
ret = -EOPNOTSUPP; |
| 884 |
usb_kill_anchored_urbs(&cardp->rx_submitted); |
| 885 |
usb_kill_anchored_urbs(&cardp->tx_submitted); |
| 886 |
if (if_usb_submit_rx_urb(cardp) < 0) |
| 887 |
ret = -EIO; |
| 888 |
goto done; |
| 889 |
} else if (cardp->bootcmdresp <= 0) { |
| 890 |
if (--reset_count >= 0) { |
| 891 |
if_usb_reset_device(cardp); |
| 892 |
goto restart; |
| 893 |
} |
| 894 |
ret = -EIO; |
| 895 |
goto done; |
| 896 |
} |
| 897 |
|
| 898 |
i = 0; |
| 899 |
|
| 900 |
cardp->totalbytes = 0; |
| 901 |
cardp->fwlastblksent = 0; |
| 902 |
cardp->CRC_OK = 1; |
| 903 |
cardp->fwdnldover = 0; |
| 904 |
cardp->fwseqnum = -1; |
| 905 |
cardp->totalbytes = 0; |
| 906 |
cardp->fwfinalblk = 0; |
| 907 |
|
| 908 |
/* Send the first firmware packet... */ |
| 909 |
if_usb_send_fw_pkt(cardp); |
| 910 |
|
| 911 |
/* ... and wait for the process to complete */ |
| 912 |
wait_event_interruptible(cardp->fw_wq, cardp->surprise_removed || cardp->fwdnldover); |
| 913 |
|
| 914 |
timer_delete_sync(&cardp->fw_timeout); |
| 915 |
usb_kill_anchored_urbs(&cardp->rx_submitted); |
| 916 |
|
| 917 |
if (!cardp->fwdnldover) { |
| 918 |
pr_info("failed to load fw, resetting device!\n"); |
| 919 |
if (--reset_count >= 0) { |
| 920 |
if_usb_reset_device(cardp); |
| 921 |
goto restart; |
| 922 |
} |
| 923 |
|
| 924 |
pr_info("FW download failure, time = %d ms\n", i * 100); |
| 925 |
ret = -EIO; |
| 926 |
goto done; |
| 927 |
} |
| 928 |
|
| 929 |
cardp->priv->fw_ready = 1; |
| 930 |
if_usb_submit_rx_urb(cardp); |
| 931 |
|
| 932 |
if (lbs_start_card(priv)) |
| 933 |
goto done; |
| 934 |
|
| 935 |
if_usb_setup_firmware(priv); |
| 936 |
|
| 937 |
/* |
| 938 |
* EHS_REMOVE_WAKEUP is not supported on all versions of the firmware. |
| 939 |
*/ |
| 940 |
priv->wol_criteria = EHS_REMOVE_WAKEUP; |
| 941 |
if (lbs_host_sleep_cfg(priv, priv->wol_criteria, NULL)) |
| 942 |
priv->ehs_remove_supported = false; |
| 943 |
|
| 944 |
done: |
| 945 |
cardp->fw = NULL; |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
#ifdef CONFIG_PM |
| 950 |
static int if_usb_suspend(struct usb_interface *intf, pm_message_t message) |
| 951 |
{ |
| 952 |
struct if_usb_card *cardp = usb_get_intfdata(intf); |
| 953 |
struct lbs_private *priv = cardp->priv; |
| 954 |
int ret; |
| 955 |
|
| 956 |
if (priv->psstate != PS_STATE_FULL_POWER) { |
| 957 |
ret = -1; |
| 958 |
goto out; |
| 959 |
} |
| 960 |
|
| 961 |
#ifdef CONFIG_OLPC |
| 962 |
if (machine_is_olpc()) { |
| 963 |
if (priv->wol_criteria == EHS_REMOVE_WAKEUP) |
| 964 |
olpc_ec_wakeup_clear(EC_SCI_SRC_WLAN); |
| 965 |
else |
| 966 |
olpc_ec_wakeup_set(EC_SCI_SRC_WLAN); |
| 967 |
} |
| 968 |
#endif |
| 969 |
|
| 970 |
ret = lbs_suspend(priv); |
| 971 |
if (ret) |
| 972 |
goto out; |
| 973 |
|
| 974 |
/* Unlink tx & rx urb */ |
| 975 |
usb_kill_anchored_urbs(&cardp->tx_submitted); |
| 976 |
usb_kill_anchored_urbs(&cardp->rx_submitted); |
| 977 |
|
| 978 |
out: |
| 979 |
return ret; |
| 980 |
} |
| 981 |
|
| 982 |
static int if_usb_resume(struct usb_interface *intf) |
| 983 |
{ |
| 984 |
struct if_usb_card *cardp = usb_get_intfdata(intf); |
| 985 |
struct lbs_private *priv = cardp->priv; |
| 986 |
|
| 987 |
if_usb_submit_rx_urb(cardp); |
| 988 |
|
| 989 |
lbs_resume(priv); |
| 990 |
|
| 991 |
return 0; |
| 992 |
} |
| 993 |
#else |
| 994 |
#define if_usb_suspend NULL |
| 995 |
#define if_usb_resume NULL |
| 996 |
#endif |
| 997 |
|
| 998 |
static struct usb_driver if_usb_driver = { |
| 999 |
.name = DRV_NAME, |
| 1000 |
.probe = if_usb_probe, |
| 1001 |
.disconnect = if_usb_disconnect, |
| 1002 |
.id_table = if_usb_table, |
| 1003 |
.suspend = if_usb_suspend, |
| 1004 |
.resume = if_usb_resume, |
| 1005 |
.reset_resume = if_usb_resume, |
| 1006 |
.disable_hub_initiated_lpm = 1, |
| 1007 |
}; |
| 1008 |
|
| 1009 |
module_usb_driver(if_usb_driver); |
| 1010 |
|
| 1011 |
MODULE_DESCRIPTION("8388 USB WLAN Driver"); |
| 1012 |
MODULE_AUTHOR("Marvell International Ltd. and Red Hat, Inc."); |
| 1013 |
MODULE_LICENSE("GPL"); |