| 1 |
// SPDX-License-Identifier: ISC |
| 2 |
/* |
| 3 |
* Copyright (c) 2011 Broadcom Corporation |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <linux/kernel.h> |
| 7 |
#include <linux/module.h> |
| 8 |
#include <linux/firmware.h> |
| 9 |
#include <linux/usb.h> |
| 10 |
#include <linux/vmalloc.h> |
| 11 |
|
| 12 |
#include <brcmu_utils.h> |
| 13 |
#include <brcm_hw_ids.h> |
| 14 |
#include <brcmu_wifi.h> |
| 15 |
#include "bus.h" |
| 16 |
#include "debug.h" |
| 17 |
#include "firmware.h" |
| 18 |
#include "usb.h" |
| 19 |
#include "core.h" |
| 20 |
#include "common.h" |
| 21 |
#include "bcdc.h" |
| 22 |
|
| 23 |
|
| 24 |
#define IOCTL_RESP_TIMEOUT msecs_to_jiffies(2000) |
| 25 |
|
| 26 |
#define BRCMF_USB_RESET_GETVER_SPINWAIT 100 /* in unit of ms */ |
| 27 |
#define BRCMF_USB_RESET_GETVER_LOOP_CNT 10 |
| 28 |
|
| 29 |
#define BRCMF_POSTBOOT_ID 0xA123 /* ID to detect if dongle |
| 30 |
has boot up */ |
| 31 |
#define BRCMF_USB_NRXQ 50 |
| 32 |
#define BRCMF_USB_NTXQ 50 |
| 33 |
|
| 34 |
#define BRCMF_USB_CBCTL_WRITE 0 |
| 35 |
#define BRCMF_USB_CBCTL_READ 1 |
| 36 |
#define BRCMF_USB_MAX_PKT_SIZE 1600 |
| 37 |
|
| 38 |
BRCMF_FW_DEF(43143, "brcmfmac43143"); |
| 39 |
BRCMF_FW_DEF(43236B, "brcmfmac43236b"); |
| 40 |
BRCMF_FW_DEF(43242A, "brcmfmac43242a"); |
| 41 |
BRCMF_FW_DEF(43569, "brcmfmac43569"); |
| 42 |
BRCMF_FW_DEF(4373, "brcmfmac4373"); |
| 43 |
|
| 44 |
static const struct brcmf_firmware_mapping brcmf_usb_fwnames[] = { |
| 45 |
BRCMF_FW_ENTRY(BRCM_CC_43143_CHIP_ID, 0xFFFFFFFF, 43143), |
| 46 |
BRCMF_FW_ENTRY(BRCM_CC_43235_CHIP_ID, 0x00000008, 43236B), |
| 47 |
BRCMF_FW_ENTRY(BRCM_CC_43236_CHIP_ID, 0x00000008, 43236B), |
| 48 |
BRCMF_FW_ENTRY(BRCM_CC_43238_CHIP_ID, 0x00000008, 43236B), |
| 49 |
BRCMF_FW_ENTRY(BRCM_CC_43242_CHIP_ID, 0xFFFFFFFF, 43242A), |
| 50 |
BRCMF_FW_ENTRY(BRCM_CC_43566_CHIP_ID, 0xFFFFFFFF, 43569), |
| 51 |
BRCMF_FW_ENTRY(BRCM_CC_43569_CHIP_ID, 0xFFFFFFFF, 43569), |
| 52 |
BRCMF_FW_ENTRY(CY_CC_4373_CHIP_ID, 0xFFFFFFFF, 4373) |
| 53 |
}; |
| 54 |
|
| 55 |
#define TRX_MAGIC 0x30524448 /* "HDR0" */ |
| 56 |
#define TRX_MAX_OFFSET 3 /* Max number of file offsets */ |
| 57 |
#define TRX_UNCOMP_IMAGE 0x20 /* Trx holds uncompressed img */ |
| 58 |
#define TRX_RDL_CHUNK 1500 /* size of each dl transfer */ |
| 59 |
#define TRX_OFFSETS_DLFWLEN_IDX 0 |
| 60 |
|
| 61 |
/* Control messages: bRequest values */ |
| 62 |
#define DL_GETSTATE 0 /* returns the rdl_state_t struct */ |
| 63 |
#define DL_CHECK_CRC 1 /* currently unused */ |
| 64 |
#define DL_GO 2 /* execute downloaded image */ |
| 65 |
#define DL_START 3 /* initialize dl state */ |
| 66 |
#define DL_REBOOT 4 /* reboot the device in 2 seconds */ |
| 67 |
#define DL_GETVER 5 /* returns the bootrom_id_t struct */ |
| 68 |
#define DL_GO_PROTECTED 6 /* execute the downloaded code and set reset |
| 69 |
* event to occur in 2 seconds. It is the |
| 70 |
* responsibility of the downloaded code to |
| 71 |
* clear this event |
| 72 |
*/ |
| 73 |
#define DL_EXEC 7 /* jump to a supplied address */ |
| 74 |
#define DL_RESETCFG 8 /* To support single enum on dongle |
| 75 |
* - Not used by bootloader |
| 76 |
*/ |
| 77 |
#define DL_DEFER_RESP_OK 9 /* Potentially defer the response to setup |
| 78 |
* if resp unavailable |
| 79 |
*/ |
| 80 |
|
| 81 |
/* states */ |
| 82 |
#define DL_WAITING 0 /* waiting to rx first pkt */ |
| 83 |
#define DL_READY 1 /* hdr was good, waiting for more of the |
| 84 |
* compressed image |
| 85 |
*/ |
| 86 |
#define DL_BAD_HDR 2 /* hdr was corrupted */ |
| 87 |
#define DL_BAD_CRC 3 /* compressed image was corrupted */ |
| 88 |
#define DL_RUNNABLE 4 /* download was successful,waiting for go cmd */ |
| 89 |
#define DL_START_FAIL 5 /* failed to initialize correctly */ |
| 90 |
#define DL_NVRAM_TOOBIG 6 /* host specified nvram data exceeds DL_NVRAM |
| 91 |
* value |
| 92 |
*/ |
| 93 |
#define DL_IMAGE_TOOBIG 7 /* firmware image too big */ |
| 94 |
|
| 95 |
|
| 96 |
struct trx_header_le { |
| 97 |
__le32 magic; /* "HDR0" */ |
| 98 |
__le32 len; /* Length of file including header */ |
| 99 |
__le32 crc32; /* CRC from flag_version to end of file */ |
| 100 |
__le32 flag_version; /* 0:15 flags, 16:31 version */ |
| 101 |
__le32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of |
| 102 |
* header |
| 103 |
*/ |
| 104 |
}; |
| 105 |
|
| 106 |
struct rdl_state_le { |
| 107 |
__le32 state; |
| 108 |
__le32 bytes; |
| 109 |
}; |
| 110 |
|
| 111 |
struct bootrom_id_le { |
| 112 |
__le32 chip; /* Chip id */ |
| 113 |
__le32 chiprev; /* Chip rev */ |
| 114 |
__le32 ramsize; /* Size of RAM */ |
| 115 |
__le32 remapbase; /* Current remap base address */ |
| 116 |
__le32 boardtype; /* Type of board */ |
| 117 |
__le32 boardrev; /* Board revision */ |
| 118 |
}; |
| 119 |
|
| 120 |
struct brcmf_usbdev_info { |
| 121 |
struct brcmf_usbdev bus_pub; /* MUST BE FIRST */ |
| 122 |
spinlock_t qlock; |
| 123 |
struct list_head rx_freeq; |
| 124 |
struct list_head rx_postq; |
| 125 |
struct list_head tx_freeq; |
| 126 |
struct list_head tx_postq; |
| 127 |
uint rx_pipe, tx_pipe; |
| 128 |
|
| 129 |
int rx_low_watermark; |
| 130 |
int tx_low_watermark; |
| 131 |
int tx_high_watermark; |
| 132 |
int tx_freecount; |
| 133 |
bool tx_flowblock; |
| 134 |
spinlock_t tx_flowblock_lock; |
| 135 |
|
| 136 |
struct brcmf_usbreq *tx_reqs; |
| 137 |
struct brcmf_usbreq *rx_reqs; |
| 138 |
|
| 139 |
char fw_name[BRCMF_FW_NAME_LEN]; |
| 140 |
const u8 *image; /* buffer for combine fw and nvram */ |
| 141 |
int image_len; |
| 142 |
|
| 143 |
struct usb_device *usbdev; |
| 144 |
struct device *dev; |
| 145 |
struct completion dev_init_done; |
| 146 |
|
| 147 |
int ctl_in_pipe, ctl_out_pipe; |
| 148 |
struct urb *ctl_urb; /* URB for control endpoint */ |
| 149 |
struct usb_ctrlrequest ctl_write; |
| 150 |
struct usb_ctrlrequest ctl_read; |
| 151 |
u32 ctl_urb_actual_length; |
| 152 |
int ctl_urb_status; |
| 153 |
int ctl_completed; |
| 154 |
wait_queue_head_t ioctl_resp_wait; |
| 155 |
ulong ctl_op; |
| 156 |
u8 ifnum; |
| 157 |
|
| 158 |
struct urb *bulk_urb; /* used for FW download */ |
| 159 |
|
| 160 |
struct brcmf_mp_device *settings; |
| 161 |
}; |
| 162 |
|
| 163 |
static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo, |
| 164 |
struct brcmf_usbreq *req); |
| 165 |
|
| 166 |
static struct brcmf_usbdev *brcmf_usb_get_buspub(struct device *dev) |
| 167 |
{ |
| 168 |
struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 169 |
return bus_if->bus_priv.usb; |
| 170 |
} |
| 171 |
|
| 172 |
static struct brcmf_usbdev_info *brcmf_usb_get_businfo(struct device *dev) |
| 173 |
{ |
| 174 |
return brcmf_usb_get_buspub(dev)->devinfo; |
| 175 |
} |
| 176 |
|
| 177 |
static int brcmf_usb_ioctl_resp_wait(struct brcmf_usbdev_info *devinfo) |
| 178 |
{ |
| 179 |
return wait_event_timeout(devinfo->ioctl_resp_wait, |
| 180 |
devinfo->ctl_completed, IOCTL_RESP_TIMEOUT); |
| 181 |
} |
| 182 |
|
| 183 |
static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info *devinfo) |
| 184 |
{ |
| 185 |
wake_up(&devinfo->ioctl_resp_wait); |
| 186 |
} |
| 187 |
|
| 188 |
static void |
| 189 |
brcmf_usb_ctl_complete(struct brcmf_usbdev_info *devinfo, int type, int status) |
| 190 |
{ |
| 191 |
brcmf_dbg(USB, "Enter, status=%d\n", status); |
| 192 |
|
| 193 |
if (unlikely(devinfo == NULL)) |
| 194 |
return; |
| 195 |
|
| 196 |
if (type == BRCMF_USB_CBCTL_READ) { |
| 197 |
if (status == 0) |
| 198 |
devinfo->bus_pub.stats.rx_ctlpkts++; |
| 199 |
else |
| 200 |
devinfo->bus_pub.stats.rx_ctlerrs++; |
| 201 |
} else if (type == BRCMF_USB_CBCTL_WRITE) { |
| 202 |
if (status == 0) |
| 203 |
devinfo->bus_pub.stats.tx_ctlpkts++; |
| 204 |
else |
| 205 |
devinfo->bus_pub.stats.tx_ctlerrs++; |
| 206 |
} |
| 207 |
|
| 208 |
devinfo->ctl_urb_status = status; |
| 209 |
devinfo->ctl_completed = true; |
| 210 |
brcmf_usb_ioctl_resp_wake(devinfo); |
| 211 |
} |
| 212 |
|
| 213 |
static void |
| 214 |
brcmf_usb_ctlread_complete(struct urb *urb) |
| 215 |
{ |
| 216 |
struct brcmf_usbdev_info *devinfo = |
| 217 |
(struct brcmf_usbdev_info *)urb->context; |
| 218 |
|
| 219 |
brcmf_dbg(USB, "Enter\n"); |
| 220 |
devinfo->ctl_urb_actual_length = urb->actual_length; |
| 221 |
brcmf_usb_ctl_complete(devinfo, BRCMF_USB_CBCTL_READ, |
| 222 |
urb->status); |
| 223 |
} |
| 224 |
|
| 225 |
static void |
| 226 |
brcmf_usb_ctlwrite_complete(struct urb *urb) |
| 227 |
{ |
| 228 |
struct brcmf_usbdev_info *devinfo = |
| 229 |
(struct brcmf_usbdev_info *)urb->context; |
| 230 |
|
| 231 |
brcmf_dbg(USB, "Enter\n"); |
| 232 |
brcmf_usb_ctl_complete(devinfo, BRCMF_USB_CBCTL_WRITE, |
| 233 |
urb->status); |
| 234 |
} |
| 235 |
|
| 236 |
static int |
| 237 |
brcmf_usb_send_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len) |
| 238 |
{ |
| 239 |
int ret; |
| 240 |
u16 size; |
| 241 |
|
| 242 |
brcmf_dbg(USB, "Enter\n"); |
| 243 |
if (devinfo == NULL || buf == NULL || |
| 244 |
len == 0 || devinfo->ctl_urb == NULL) |
| 245 |
return -EINVAL; |
| 246 |
|
| 247 |
size = len; |
| 248 |
devinfo->ctl_write.wLength = cpu_to_le16p(&size); |
| 249 |
devinfo->ctl_urb->transfer_buffer_length = size; |
| 250 |
devinfo->ctl_urb_status = 0; |
| 251 |
devinfo->ctl_urb_actual_length = 0; |
| 252 |
|
| 253 |
usb_fill_control_urb(devinfo->ctl_urb, |
| 254 |
devinfo->usbdev, |
| 255 |
devinfo->ctl_out_pipe, |
| 256 |
(unsigned char *) &devinfo->ctl_write, |
| 257 |
buf, size, |
| 258 |
(usb_complete_t)brcmf_usb_ctlwrite_complete, |
| 259 |
devinfo); |
| 260 |
|
| 261 |
ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC); |
| 262 |
if (ret < 0) |
| 263 |
brcmf_err("usb_submit_urb failed %d\n", ret); |
| 264 |
|
| 265 |
return ret; |
| 266 |
} |
| 267 |
|
| 268 |
static int |
| 269 |
brcmf_usb_recv_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len) |
| 270 |
{ |
| 271 |
int ret; |
| 272 |
u16 size; |
| 273 |
|
| 274 |
brcmf_dbg(USB, "Enter\n"); |
| 275 |
if ((devinfo == NULL) || (buf == NULL) || (len == 0) |
| 276 |
|| (devinfo->ctl_urb == NULL)) |
| 277 |
return -EINVAL; |
| 278 |
|
| 279 |
size = len; |
| 280 |
devinfo->ctl_read.wLength = cpu_to_le16p(&size); |
| 281 |
devinfo->ctl_urb->transfer_buffer_length = size; |
| 282 |
|
| 283 |
devinfo->ctl_read.bRequestType = USB_DIR_IN |
| 284 |
| USB_TYPE_CLASS | USB_RECIP_INTERFACE; |
| 285 |
devinfo->ctl_read.bRequest = 1; |
| 286 |
|
| 287 |
usb_fill_control_urb(devinfo->ctl_urb, |
| 288 |
devinfo->usbdev, |
| 289 |
devinfo->ctl_in_pipe, |
| 290 |
(unsigned char *) &devinfo->ctl_read, |
| 291 |
buf, size, |
| 292 |
(usb_complete_t)brcmf_usb_ctlread_complete, |
| 293 |
devinfo); |
| 294 |
|
| 295 |
ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC); |
| 296 |
if (ret < 0) |
| 297 |
brcmf_err("usb_submit_urb failed %d\n", ret); |
| 298 |
|
| 299 |
return ret; |
| 300 |
} |
| 301 |
|
| 302 |
static int brcmf_usb_tx_ctlpkt(struct device *dev, u8 *buf, u32 len) |
| 303 |
{ |
| 304 |
int err = 0; |
| 305 |
int timeout = 0; |
| 306 |
struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); |
| 307 |
struct usb_interface *intf = to_usb_interface(dev); |
| 308 |
|
| 309 |
brcmf_dbg(USB, "Enter\n"); |
| 310 |
|
| 311 |
err = usb_autopm_get_interface(intf); |
| 312 |
if (err) |
| 313 |
goto out; |
| 314 |
|
| 315 |
if (devinfo->bus_pub.state != BRCMFMAC_USB_STATE_UP) { |
| 316 |
err = -EIO; |
| 317 |
goto fail; |
| 318 |
} |
| 319 |
|
| 320 |
if (test_and_set_bit(0, &devinfo->ctl_op)) { |
| 321 |
err = -EIO; |
| 322 |
goto fail; |
| 323 |
} |
| 324 |
|
| 325 |
devinfo->ctl_completed = false; |
| 326 |
err = brcmf_usb_send_ctl(devinfo, buf, len); |
| 327 |
if (err) { |
| 328 |
brcmf_err("fail %d bytes: %d\n", err, len); |
| 329 |
clear_bit(0, &devinfo->ctl_op); |
| 330 |
goto fail; |
| 331 |
} |
| 332 |
timeout = brcmf_usb_ioctl_resp_wait(devinfo); |
| 333 |
if (!timeout) { |
| 334 |
brcmf_err("Txctl wait timed out\n"); |
| 335 |
usb_kill_urb(devinfo->ctl_urb); |
| 336 |
err = -EIO; |
| 337 |
goto fail; |
| 338 |
} |
| 339 |
clear_bit(0, &devinfo->ctl_op); |
| 340 |
|
| 341 |
fail: |
| 342 |
usb_autopm_put_interface(intf); |
| 343 |
out: |
| 344 |
return err; |
| 345 |
} |
| 346 |
|
| 347 |
static int brcmf_usb_rx_ctlpkt(struct device *dev, u8 *buf, u32 len) |
| 348 |
{ |
| 349 |
int err = 0; |
| 350 |
int timeout = 0; |
| 351 |
struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); |
| 352 |
struct usb_interface *intf = to_usb_interface(dev); |
| 353 |
|
| 354 |
brcmf_dbg(USB, "Enter\n"); |
| 355 |
|
| 356 |
err = usb_autopm_get_interface(intf); |
| 357 |
if (err) |
| 358 |
goto out; |
| 359 |
|
| 360 |
if (devinfo->bus_pub.state != BRCMFMAC_USB_STATE_UP) { |
| 361 |
err = -EIO; |
| 362 |
goto fail; |
| 363 |
} |
| 364 |
|
| 365 |
if (test_and_set_bit(0, &devinfo->ctl_op)) { |
| 366 |
err = -EIO; |
| 367 |
goto fail; |
| 368 |
} |
| 369 |
|
| 370 |
devinfo->ctl_completed = false; |
| 371 |
err = brcmf_usb_recv_ctl(devinfo, buf, len); |
| 372 |
if (err) { |
| 373 |
brcmf_err("fail %d bytes: %d\n", err, len); |
| 374 |
clear_bit(0, &devinfo->ctl_op); |
| 375 |
goto fail; |
| 376 |
} |
| 377 |
timeout = brcmf_usb_ioctl_resp_wait(devinfo); |
| 378 |
err = devinfo->ctl_urb_status; |
| 379 |
if (!timeout) { |
| 380 |
brcmf_err("rxctl wait timed out\n"); |
| 381 |
usb_kill_urb(devinfo->ctl_urb); |
| 382 |
err = -EIO; |
| 383 |
goto fail; |
| 384 |
} |
| 385 |
clear_bit(0, &devinfo->ctl_op); |
| 386 |
fail: |
| 387 |
usb_autopm_put_interface(intf); |
| 388 |
if (!err) |
| 389 |
return devinfo->ctl_urb_actual_length; |
| 390 |
out: |
| 391 |
return err; |
| 392 |
} |
| 393 |
|
| 394 |
static struct brcmf_usbreq *brcmf_usb_deq(struct brcmf_usbdev_info *devinfo, |
| 395 |
struct list_head *q, int *counter) |
| 396 |
{ |
| 397 |
unsigned long flags; |
| 398 |
struct brcmf_usbreq *req; |
| 399 |
spin_lock_irqsave(&devinfo->qlock, flags); |
| 400 |
if (list_empty(q)) { |
| 401 |
spin_unlock_irqrestore(&devinfo->qlock, flags); |
| 402 |
return NULL; |
| 403 |
} |
| 404 |
req = list_entry(q->next, struct brcmf_usbreq, list); |
| 405 |
list_del_init(q->next); |
| 406 |
if (counter) |
| 407 |
(*counter)--; |
| 408 |
spin_unlock_irqrestore(&devinfo->qlock, flags); |
| 409 |
return req; |
| 410 |
|
| 411 |
} |
| 412 |
|
| 413 |
static void brcmf_usb_enq(struct brcmf_usbdev_info *devinfo, |
| 414 |
struct list_head *q, struct brcmf_usbreq *req, |
| 415 |
int *counter) |
| 416 |
{ |
| 417 |
unsigned long flags; |
| 418 |
spin_lock_irqsave(&devinfo->qlock, flags); |
| 419 |
list_add_tail(&req->list, q); |
| 420 |
if (counter) |
| 421 |
(*counter)++; |
| 422 |
spin_unlock_irqrestore(&devinfo->qlock, flags); |
| 423 |
} |
| 424 |
|
| 425 |
static struct brcmf_usbreq * |
| 426 |
brcmf_usbdev_qinit(struct list_head *q, int qsize) |
| 427 |
{ |
| 428 |
int i; |
| 429 |
struct brcmf_usbreq *req, *reqs; |
| 430 |
|
| 431 |
reqs = kzalloc_objs(struct brcmf_usbreq, qsize, GFP_ATOMIC); |
| 432 |
if (reqs == NULL) |
| 433 |
return NULL; |
| 434 |
|
| 435 |
req = reqs; |
| 436 |
|
| 437 |
for (i = 0; i < qsize; i++) { |
| 438 |
req->urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 439 |
if (!req->urb) |
| 440 |
goto fail; |
| 441 |
|
| 442 |
INIT_LIST_HEAD(&req->list); |
| 443 |
list_add_tail(&req->list, q); |
| 444 |
req++; |
| 445 |
} |
| 446 |
return reqs; |
| 447 |
fail: |
| 448 |
brcmf_err("fail!\n"); |
| 449 |
while (!list_empty(q)) { |
| 450 |
req = list_entry(q->next, struct brcmf_usbreq, list); |
| 451 |
if (req) |
| 452 |
usb_free_urb(req->urb); |
| 453 |
list_del(q->next); |
| 454 |
} |
| 455 |
kfree(reqs); |
| 456 |
return NULL; |
| 457 |
|
| 458 |
} |
| 459 |
|
| 460 |
static void brcmf_usb_free_q(struct list_head *q) |
| 461 |
{ |
| 462 |
struct brcmf_usbreq *req, *next; |
| 463 |
|
| 464 |
list_for_each_entry_safe(req, next, q, list) { |
| 465 |
if (!req->urb) { |
| 466 |
brcmf_err("bad req\n"); |
| 467 |
break; |
| 468 |
} |
| 469 |
usb_free_urb(req->urb); |
| 470 |
list_del_init(&req->list); |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
static void brcmf_usb_del_fromq(struct brcmf_usbdev_info *devinfo, |
| 475 |
struct brcmf_usbreq *req) |
| 476 |
{ |
| 477 |
unsigned long flags; |
| 478 |
|
| 479 |
spin_lock_irqsave(&devinfo->qlock, flags); |
| 480 |
list_del_init(&req->list); |
| 481 |
spin_unlock_irqrestore(&devinfo->qlock, flags); |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
static void brcmf_usb_tx_complete(struct urb *urb) |
| 486 |
{ |
| 487 |
struct brcmf_usbreq *req = (struct brcmf_usbreq *)urb->context; |
| 488 |
struct brcmf_usbdev_info *devinfo = req->devinfo; |
| 489 |
unsigned long flags; |
| 490 |
|
| 491 |
brcmf_dbg(USB, "Enter, urb->status=%d, skb=%p\n", urb->status, |
| 492 |
req->skb); |
| 493 |
brcmf_usb_del_fromq(devinfo, req); |
| 494 |
|
| 495 |
brcmf_proto_bcdc_txcomplete(devinfo->dev, req->skb, urb->status == 0); |
| 496 |
req->skb = NULL; |
| 497 |
brcmf_usb_enq(devinfo, &devinfo->tx_freeq, req, &devinfo->tx_freecount); |
| 498 |
spin_lock_irqsave(&devinfo->tx_flowblock_lock, flags); |
| 499 |
if (devinfo->tx_freecount > devinfo->tx_high_watermark && |
| 500 |
devinfo->tx_flowblock) { |
| 501 |
brcmf_proto_bcdc_txflowblock(devinfo->dev, false); |
| 502 |
devinfo->tx_flowblock = false; |
| 503 |
} |
| 504 |
spin_unlock_irqrestore(&devinfo->tx_flowblock_lock, flags); |
| 505 |
} |
| 506 |
|
| 507 |
static void brcmf_usb_rx_complete(struct urb *urb) |
| 508 |
{ |
| 509 |
struct brcmf_usbreq *req = (struct brcmf_usbreq *)urb->context; |
| 510 |
struct brcmf_usbdev_info *devinfo = req->devinfo; |
| 511 |
struct sk_buff *skb; |
| 512 |
|
| 513 |
brcmf_dbg(USB, "Enter, urb->status=%d\n", urb->status); |
| 514 |
brcmf_usb_del_fromq(devinfo, req); |
| 515 |
skb = req->skb; |
| 516 |
req->skb = NULL; |
| 517 |
|
| 518 |
/* zero length packets indicate usb "failure". Do not refill */ |
| 519 |
if (urb->status != 0 || !urb->actual_length) { |
| 520 |
brcmu_pkt_buf_free_skb(skb); |
| 521 |
brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req, NULL); |
| 522 |
return; |
| 523 |
} |
| 524 |
|
| 525 |
if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP || |
| 526 |
devinfo->bus_pub.state == BRCMFMAC_USB_STATE_SLEEP) { |
| 527 |
skb_put(skb, urb->actual_length); |
| 528 |
brcmf_rx_frame(devinfo->dev, skb, true, true); |
| 529 |
brcmf_usb_rx_refill(devinfo, req); |
| 530 |
usb_mark_last_busy(urb->dev); |
| 531 |
} else { |
| 532 |
brcmu_pkt_buf_free_skb(skb); |
| 533 |
brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req, NULL); |
| 534 |
} |
| 535 |
return; |
| 536 |
|
| 537 |
} |
| 538 |
|
| 539 |
static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo, |
| 540 |
struct brcmf_usbreq *req) |
| 541 |
{ |
| 542 |
struct sk_buff *skb; |
| 543 |
int ret; |
| 544 |
|
| 545 |
if (!req || !devinfo) |
| 546 |
return; |
| 547 |
|
| 548 |
skb = dev_alloc_skb(devinfo->bus_pub.bus_mtu); |
| 549 |
if (!skb) { |
| 550 |
brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req, NULL); |
| 551 |
return; |
| 552 |
} |
| 553 |
req->skb = skb; |
| 554 |
|
| 555 |
usb_fill_bulk_urb(req->urb, devinfo->usbdev, devinfo->rx_pipe, |
| 556 |
skb->data, skb_tailroom(skb), brcmf_usb_rx_complete, |
| 557 |
req); |
| 558 |
req->devinfo = devinfo; |
| 559 |
brcmf_usb_enq(devinfo, &devinfo->rx_postq, req, NULL); |
| 560 |
|
| 561 |
ret = usb_submit_urb(req->urb, GFP_ATOMIC); |
| 562 |
if (ret) { |
| 563 |
brcmf_usb_del_fromq(devinfo, req); |
| 564 |
brcmu_pkt_buf_free_skb(req->skb); |
| 565 |
req->skb = NULL; |
| 566 |
brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req, NULL); |
| 567 |
} |
| 568 |
return; |
| 569 |
} |
| 570 |
|
| 571 |
static void brcmf_usb_rx_fill_all(struct brcmf_usbdev_info *devinfo) |
| 572 |
{ |
| 573 |
struct brcmf_usbreq *req; |
| 574 |
|
| 575 |
if (devinfo->bus_pub.state != BRCMFMAC_USB_STATE_UP) { |
| 576 |
brcmf_err("bus is not up=%d\n", devinfo->bus_pub.state); |
| 577 |
return; |
| 578 |
} |
| 579 |
while ((req = brcmf_usb_deq(devinfo, &devinfo->rx_freeq, NULL)) != NULL) |
| 580 |
brcmf_usb_rx_refill(devinfo, req); |
| 581 |
} |
| 582 |
|
| 583 |
static void |
| 584 |
brcmf_usb_state_change(struct brcmf_usbdev_info *devinfo, int state) |
| 585 |
{ |
| 586 |
struct brcmf_bus *bcmf_bus = devinfo->bus_pub.bus; |
| 587 |
|
| 588 |
brcmf_dbg(USB, "Enter, current state=%d, new state=%d\n", |
| 589 |
devinfo->bus_pub.state, state); |
| 590 |
|
| 591 |
if (devinfo->bus_pub.state == state) |
| 592 |
return; |
| 593 |
|
| 594 |
devinfo->bus_pub.state = state; |
| 595 |
|
| 596 |
/* update state of upper layer */ |
| 597 |
if (state == BRCMFMAC_USB_STATE_DOWN) { |
| 598 |
brcmf_dbg(USB, "DBUS is down\n"); |
| 599 |
brcmf_bus_change_state(bcmf_bus, BRCMF_BUS_DOWN); |
| 600 |
} else if (state == BRCMFMAC_USB_STATE_UP) { |
| 601 |
brcmf_dbg(USB, "DBUS is up\n"); |
| 602 |
brcmf_bus_change_state(bcmf_bus, BRCMF_BUS_UP); |
| 603 |
} else { |
| 604 |
brcmf_dbg(USB, "DBUS current state=%d\n", state); |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb) |
| 609 |
{ |
| 610 |
struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); |
| 611 |
struct brcmf_usbreq *req; |
| 612 |
int ret; |
| 613 |
unsigned long flags; |
| 614 |
struct usb_interface *intf = to_usb_interface(dev); |
| 615 |
|
| 616 |
ret = usb_autopm_get_interface(intf); |
| 617 |
if (ret) |
| 618 |
goto out; |
| 619 |
|
| 620 |
brcmf_dbg(USB, "Enter, skb=%p\n", skb); |
| 621 |
if (devinfo->bus_pub.state != BRCMFMAC_USB_STATE_UP) { |
| 622 |
ret = -EIO; |
| 623 |
goto fail; |
| 624 |
} |
| 625 |
|
| 626 |
req = brcmf_usb_deq(devinfo, &devinfo->tx_freeq, |
| 627 |
&devinfo->tx_freecount); |
| 628 |
if (!req) { |
| 629 |
brcmf_err("no req to send\n"); |
| 630 |
ret = -ENOMEM; |
| 631 |
goto fail; |
| 632 |
} |
| 633 |
|
| 634 |
req->skb = skb; |
| 635 |
req->devinfo = devinfo; |
| 636 |
usb_fill_bulk_urb(req->urb, devinfo->usbdev, devinfo->tx_pipe, |
| 637 |
skb->data, skb->len, brcmf_usb_tx_complete, req); |
| 638 |
req->urb->transfer_flags |= URB_ZERO_PACKET; |
| 639 |
brcmf_usb_enq(devinfo, &devinfo->tx_postq, req, NULL); |
| 640 |
ret = usb_submit_urb(req->urb, GFP_ATOMIC); |
| 641 |
if (ret) { |
| 642 |
brcmf_err("brcmf_usb_tx usb_submit_urb FAILED\n"); |
| 643 |
brcmf_usb_del_fromq(devinfo, req); |
| 644 |
req->skb = NULL; |
| 645 |
brcmf_usb_enq(devinfo, &devinfo->tx_freeq, req, |
| 646 |
&devinfo->tx_freecount); |
| 647 |
goto fail; |
| 648 |
} |
| 649 |
|
| 650 |
spin_lock_irqsave(&devinfo->tx_flowblock_lock, flags); |
| 651 |
if (devinfo->tx_freecount < devinfo->tx_low_watermark && |
| 652 |
!devinfo->tx_flowblock) { |
| 653 |
brcmf_proto_bcdc_txflowblock(dev, true); |
| 654 |
devinfo->tx_flowblock = true; |
| 655 |
} |
| 656 |
spin_unlock_irqrestore(&devinfo->tx_flowblock_lock, flags); |
| 657 |
|
| 658 |
fail: |
| 659 |
usb_autopm_put_interface(intf); |
| 660 |
out: |
| 661 |
return ret; |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
static int brcmf_usb_up(struct device *dev) |
| 666 |
{ |
| 667 |
struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); |
| 668 |
|
| 669 |
brcmf_dbg(USB, "Enter\n"); |
| 670 |
if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP) |
| 671 |
return 0; |
| 672 |
|
| 673 |
/* Success, indicate devinfo is fully up */ |
| 674 |
brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_UP); |
| 675 |
|
| 676 |
if (devinfo->ctl_urb) { |
| 677 |
devinfo->ctl_in_pipe = usb_rcvctrlpipe(devinfo->usbdev, 0); |
| 678 |
devinfo->ctl_out_pipe = usb_sndctrlpipe(devinfo->usbdev, 0); |
| 679 |
|
| 680 |
/* CTL Write */ |
| 681 |
devinfo->ctl_write.bRequestType = |
| 682 |
USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE; |
| 683 |
devinfo->ctl_write.bRequest = 0; |
| 684 |
devinfo->ctl_write.wValue = cpu_to_le16(0); |
| 685 |
devinfo->ctl_write.wIndex = cpu_to_le16(devinfo->ifnum); |
| 686 |
|
| 687 |
/* CTL Read */ |
| 688 |
devinfo->ctl_read.bRequestType = |
| 689 |
USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; |
| 690 |
devinfo->ctl_read.bRequest = 1; |
| 691 |
devinfo->ctl_read.wValue = cpu_to_le16(0); |
| 692 |
devinfo->ctl_read.wIndex = cpu_to_le16(devinfo->ifnum); |
| 693 |
} |
| 694 |
brcmf_usb_rx_fill_all(devinfo); |
| 695 |
return 0; |
| 696 |
} |
| 697 |
|
| 698 |
static void brcmf_cancel_all_urbs(struct brcmf_usbdev_info *devinfo) |
| 699 |
{ |
| 700 |
int i; |
| 701 |
|
| 702 |
if (devinfo->ctl_urb) |
| 703 |
usb_kill_urb(devinfo->ctl_urb); |
| 704 |
if (devinfo->bulk_urb) |
| 705 |
usb_kill_urb(devinfo->bulk_urb); |
| 706 |
if (devinfo->tx_reqs) |
| 707 |
for (i = 0; i < devinfo->bus_pub.ntxq; i++) |
| 708 |
usb_kill_urb(devinfo->tx_reqs[i].urb); |
| 709 |
if (devinfo->rx_reqs) |
| 710 |
for (i = 0; i < devinfo->bus_pub.nrxq; i++) |
| 711 |
usb_kill_urb(devinfo->rx_reqs[i].urb); |
| 712 |
} |
| 713 |
|
| 714 |
static void brcmf_usb_down(struct device *dev) |
| 715 |
{ |
| 716 |
struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); |
| 717 |
|
| 718 |
brcmf_dbg(USB, "Enter\n"); |
| 719 |
if (devinfo == NULL) |
| 720 |
return; |
| 721 |
|
| 722 |
if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_DOWN) |
| 723 |
return; |
| 724 |
|
| 725 |
brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_DOWN); |
| 726 |
|
| 727 |
brcmf_cancel_all_urbs(devinfo); |
| 728 |
} |
| 729 |
|
| 730 |
static void |
| 731 |
brcmf_usb_sync_complete(struct urb *urb) |
| 732 |
{ |
| 733 |
struct brcmf_usbdev_info *devinfo = |
| 734 |
(struct brcmf_usbdev_info *)urb->context; |
| 735 |
|
| 736 |
devinfo->ctl_completed = true; |
| 737 |
brcmf_usb_ioctl_resp_wake(devinfo); |
| 738 |
} |
| 739 |
|
| 740 |
static int brcmf_usb_dl_cmd(struct brcmf_usbdev_info *devinfo, u8 cmd, |
| 741 |
void *buffer, int buflen) |
| 742 |
{ |
| 743 |
int ret; |
| 744 |
char *tmpbuf = NULL; |
| 745 |
u16 size; |
| 746 |
|
| 747 |
if (!devinfo || !devinfo->ctl_urb) { |
| 748 |
ret = -EINVAL; |
| 749 |
goto err; |
| 750 |
} |
| 751 |
|
| 752 |
tmpbuf = kmalloc(buflen, GFP_ATOMIC); |
| 753 |
if (!tmpbuf) { |
| 754 |
ret = -ENOMEM; |
| 755 |
goto err; |
| 756 |
} |
| 757 |
|
| 758 |
size = buflen; |
| 759 |
devinfo->ctl_urb->transfer_buffer_length = size; |
| 760 |
|
| 761 |
devinfo->ctl_read.wLength = cpu_to_le16p(&size); |
| 762 |
devinfo->ctl_read.bRequestType = USB_DIR_IN | USB_TYPE_VENDOR | |
| 763 |
USB_RECIP_INTERFACE; |
| 764 |
devinfo->ctl_read.bRequest = cmd; |
| 765 |
|
| 766 |
usb_fill_control_urb(devinfo->ctl_urb, |
| 767 |
devinfo->usbdev, |
| 768 |
usb_rcvctrlpipe(devinfo->usbdev, 0), |
| 769 |
(unsigned char *) &devinfo->ctl_read, |
| 770 |
(void *) tmpbuf, size, |
| 771 |
(usb_complete_t)brcmf_usb_sync_complete, devinfo); |
| 772 |
|
| 773 |
devinfo->ctl_completed = false; |
| 774 |
ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC); |
| 775 |
if (ret < 0) { |
| 776 |
brcmf_err("usb_submit_urb failed %d\n", ret); |
| 777 |
goto err; |
| 778 |
} |
| 779 |
|
| 780 |
if (!brcmf_usb_ioctl_resp_wait(devinfo)) { |
| 781 |
usb_kill_urb(devinfo->ctl_urb); |
| 782 |
ret = -ETIMEDOUT; |
| 783 |
goto err; |
| 784 |
} else { |
| 785 |
memcpy(buffer, tmpbuf, buflen); |
| 786 |
} |
| 787 |
|
| 788 |
kfree(tmpbuf); |
| 789 |
return 0; |
| 790 |
|
| 791 |
err: |
| 792 |
kfree(tmpbuf); |
| 793 |
brcmf_err("dl cmd %u failed: err=%d\n", cmd, ret); |
| 794 |
return ret; |
| 795 |
} |
| 796 |
|
| 797 |
static bool |
| 798 |
brcmf_usb_dlneeded(struct brcmf_usbdev_info *devinfo) |
| 799 |
{ |
| 800 |
struct bootrom_id_le id; |
| 801 |
u32 chipid, chiprev; |
| 802 |
|
| 803 |
brcmf_dbg(USB, "Enter\n"); |
| 804 |
|
| 805 |
if (devinfo == NULL) |
| 806 |
return false; |
| 807 |
|
| 808 |
/* Check if firmware downloaded already by querying runtime ID */ |
| 809 |
id.chip = cpu_to_le32(0xDEAD); |
| 810 |
brcmf_usb_dl_cmd(devinfo, DL_GETVER, &id, sizeof(id)); |
| 811 |
|
| 812 |
chipid = le32_to_cpu(id.chip); |
| 813 |
chiprev = le32_to_cpu(id.chiprev); |
| 814 |
|
| 815 |
if ((chipid & 0x4300) == 0x4300) |
| 816 |
brcmf_dbg(USB, "chip %x rev 0x%x\n", chipid, chiprev); |
| 817 |
else |
| 818 |
brcmf_dbg(USB, "chip %d rev 0x%x\n", chipid, chiprev); |
| 819 |
if (chipid == BRCMF_POSTBOOT_ID) { |
| 820 |
brcmf_dbg(USB, "firmware already downloaded\n"); |
| 821 |
brcmf_usb_dl_cmd(devinfo, DL_RESETCFG, &id, sizeof(id)); |
| 822 |
return false; |
| 823 |
} else { |
| 824 |
devinfo->bus_pub.devid = chipid; |
| 825 |
devinfo->bus_pub.chiprev = chiprev; |
| 826 |
} |
| 827 |
return true; |
| 828 |
} |
| 829 |
|
| 830 |
static int |
| 831 |
brcmf_usb_resetcfg(struct brcmf_usbdev_info *devinfo) |
| 832 |
{ |
| 833 |
struct bootrom_id_le id; |
| 834 |
u32 loop_cnt; |
| 835 |
int err; |
| 836 |
|
| 837 |
brcmf_dbg(USB, "Enter\n"); |
| 838 |
|
| 839 |
loop_cnt = 0; |
| 840 |
do { |
| 841 |
mdelay(BRCMF_USB_RESET_GETVER_SPINWAIT); |
| 842 |
loop_cnt++; |
| 843 |
id.chip = cpu_to_le32(0xDEAD); /* Get the ID */ |
| 844 |
err = brcmf_usb_dl_cmd(devinfo, DL_GETVER, &id, sizeof(id)); |
| 845 |
if ((err) && (err != -ETIMEDOUT)) |
| 846 |
return err; |
| 847 |
if (id.chip == cpu_to_le32(BRCMF_POSTBOOT_ID)) |
| 848 |
break; |
| 849 |
} while (loop_cnt < BRCMF_USB_RESET_GETVER_LOOP_CNT); |
| 850 |
|
| 851 |
if (id.chip == cpu_to_le32(BRCMF_POSTBOOT_ID)) { |
| 852 |
brcmf_dbg(USB, "postboot chip 0x%x/rev 0x%x\n", |
| 853 |
le32_to_cpu(id.chip), le32_to_cpu(id.chiprev)); |
| 854 |
|
| 855 |
brcmf_usb_dl_cmd(devinfo, DL_RESETCFG, &id, sizeof(id)); |
| 856 |
return 0; |
| 857 |
} else { |
| 858 |
brcmf_err("Cannot talk to Dongle. Firmware is not UP, %d ms\n", |
| 859 |
BRCMF_USB_RESET_GETVER_SPINWAIT * loop_cnt); |
| 860 |
return -EINVAL; |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
static int |
| 866 |
brcmf_usb_dl_send_bulk(struct brcmf_usbdev_info *devinfo, void *buffer, int len) |
| 867 |
{ |
| 868 |
int ret; |
| 869 |
|
| 870 |
if ((devinfo == NULL) || (devinfo->bulk_urb == NULL)) |
| 871 |
return -EINVAL; |
| 872 |
|
| 873 |
/* Prepare the URB */ |
| 874 |
usb_fill_bulk_urb(devinfo->bulk_urb, devinfo->usbdev, |
| 875 |
devinfo->tx_pipe, buffer, len, |
| 876 |
(usb_complete_t)brcmf_usb_sync_complete, devinfo); |
| 877 |
|
| 878 |
devinfo->bulk_urb->transfer_flags |= URB_ZERO_PACKET; |
| 879 |
|
| 880 |
devinfo->ctl_completed = false; |
| 881 |
ret = usb_submit_urb(devinfo->bulk_urb, GFP_ATOMIC); |
| 882 |
if (ret) { |
| 883 |
brcmf_err("usb_submit_urb failed %d\n", ret); |
| 884 |
return ret; |
| 885 |
} |
| 886 |
ret = brcmf_usb_ioctl_resp_wait(devinfo); |
| 887 |
return (ret == 0); |
| 888 |
} |
| 889 |
|
| 890 |
static int |
| 891 |
brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen) |
| 892 |
{ |
| 893 |
unsigned int sendlen, sent, dllen; |
| 894 |
char *bulkchunk = NULL, *dlpos; |
| 895 |
struct rdl_state_le state; |
| 896 |
u32 rdlstate, rdlbytes; |
| 897 |
int err = 0; |
| 898 |
|
| 899 |
brcmf_dbg(USB, "Enter, fw %p, len %d\n", fw, fwlen); |
| 900 |
|
| 901 |
bulkchunk = kmalloc(TRX_RDL_CHUNK, GFP_ATOMIC); |
| 902 |
if (bulkchunk == NULL) { |
| 903 |
err = -ENOMEM; |
| 904 |
goto fail; |
| 905 |
} |
| 906 |
|
| 907 |
/* 1) Prepare USB boot loader for runtime image */ |
| 908 |
err = brcmf_usb_dl_cmd(devinfo, DL_START, &state, sizeof(state)); |
| 909 |
if (err) |
| 910 |
goto fail; |
| 911 |
|
| 912 |
rdlstate = le32_to_cpu(state.state); |
| 913 |
rdlbytes = le32_to_cpu(state.bytes); |
| 914 |
|
| 915 |
/* 2) Check we are in the Waiting state */ |
| 916 |
if (rdlstate != DL_WAITING) { |
| 917 |
brcmf_err("Invalid DL state: %u\n", rdlstate); |
| 918 |
err = -EINVAL; |
| 919 |
goto fail; |
| 920 |
} |
| 921 |
sent = 0; |
| 922 |
dlpos = fw; |
| 923 |
dllen = fwlen; |
| 924 |
|
| 925 |
/* Get chip id and rev */ |
| 926 |
while (rdlbytes != dllen) { |
| 927 |
/* Wait until the usb device reports it received all |
| 928 |
* the bytes we sent */ |
| 929 |
if ((rdlbytes == sent) && (rdlbytes != dllen)) { |
| 930 |
sendlen = min(dllen - sent, TRX_RDL_CHUNK); |
| 931 |
|
| 932 |
/* simply avoid having to send a ZLP by ensuring we |
| 933 |
* never have an even |
| 934 |
* multiple of 64 |
| 935 |
*/ |
| 936 |
if (!(sendlen % 64)) |
| 937 |
sendlen -= 4; |
| 938 |
|
| 939 |
/* send data */ |
| 940 |
memcpy(bulkchunk, dlpos, sendlen); |
| 941 |
if (brcmf_usb_dl_send_bulk(devinfo, bulkchunk, |
| 942 |
sendlen)) { |
| 943 |
brcmf_err("send_bulk failed\n"); |
| 944 |
err = -EINVAL; |
| 945 |
goto fail; |
| 946 |
} |
| 947 |
|
| 948 |
dlpos += sendlen; |
| 949 |
sent += sendlen; |
| 950 |
} |
| 951 |
err = brcmf_usb_dl_cmd(devinfo, DL_GETSTATE, &state, |
| 952 |
sizeof(state)); |
| 953 |
if (err) { |
| 954 |
brcmf_err("DL_GETSTATE Failed\n"); |
| 955 |
goto fail; |
| 956 |
} |
| 957 |
|
| 958 |
rdlstate = le32_to_cpu(state.state); |
| 959 |
rdlbytes = le32_to_cpu(state.bytes); |
| 960 |
|
| 961 |
/* restart if an error is reported */ |
| 962 |
if (rdlstate == DL_BAD_HDR || rdlstate == DL_BAD_CRC) { |
| 963 |
brcmf_err("Bad Hdr or Bad CRC state %d\n", |
| 964 |
rdlstate); |
| 965 |
err = -EINVAL; |
| 966 |
goto fail; |
| 967 |
} |
| 968 |
} |
| 969 |
|
| 970 |
fail: |
| 971 |
kfree(bulkchunk); |
| 972 |
brcmf_dbg(USB, "Exit, err=%d\n", err); |
| 973 |
return err; |
| 974 |
} |
| 975 |
|
| 976 |
static int brcmf_usb_dlstart(struct brcmf_usbdev_info *devinfo, u8 *fw, int len) |
| 977 |
{ |
| 978 |
int err; |
| 979 |
|
| 980 |
brcmf_dbg(USB, "Enter\n"); |
| 981 |
|
| 982 |
if (devinfo == NULL) |
| 983 |
return -EINVAL; |
| 984 |
|
| 985 |
if (devinfo->bus_pub.devid == 0xDEAD) |
| 986 |
return -EINVAL; |
| 987 |
|
| 988 |
err = brcmf_usb_dl_writeimage(devinfo, fw, len); |
| 989 |
if (err == 0) |
| 990 |
devinfo->bus_pub.state = BRCMFMAC_USB_STATE_DL_DONE; |
| 991 |
else |
| 992 |
devinfo->bus_pub.state = BRCMFMAC_USB_STATE_DL_FAIL; |
| 993 |
brcmf_dbg(USB, "Exit, err=%d\n", err); |
| 994 |
|
| 995 |
return err; |
| 996 |
} |
| 997 |
|
| 998 |
static int brcmf_usb_dlrun(struct brcmf_usbdev_info *devinfo) |
| 999 |
{ |
| 1000 |
struct rdl_state_le state; |
| 1001 |
|
| 1002 |
brcmf_dbg(USB, "Enter\n"); |
| 1003 |
if (!devinfo) |
| 1004 |
return -EINVAL; |
| 1005 |
|
| 1006 |
if (devinfo->bus_pub.devid == 0xDEAD) |
| 1007 |
return -EINVAL; |
| 1008 |
|
| 1009 |
/* Check we are runnable */ |
| 1010 |
state.state = 0; |
| 1011 |
brcmf_usb_dl_cmd(devinfo, DL_GETSTATE, &state, sizeof(state)); |
| 1012 |
|
| 1013 |
/* Start the image */ |
| 1014 |
if (state.state == cpu_to_le32(DL_RUNNABLE)) { |
| 1015 |
if (brcmf_usb_dl_cmd(devinfo, DL_GO, &state, sizeof(state))) |
| 1016 |
return -ENODEV; |
| 1017 |
if (brcmf_usb_resetcfg(devinfo)) |
| 1018 |
return -ENODEV; |
| 1019 |
/* The Dongle may go for re-enumeration. */ |
| 1020 |
} else { |
| 1021 |
brcmf_err("Dongle not runnable\n"); |
| 1022 |
return -EINVAL; |
| 1023 |
} |
| 1024 |
brcmf_dbg(USB, "Exit\n"); |
| 1025 |
return 0; |
| 1026 |
} |
| 1027 |
|
| 1028 |
static int |
| 1029 |
brcmf_usb_fw_download(struct brcmf_usbdev_info *devinfo) |
| 1030 |
{ |
| 1031 |
int err; |
| 1032 |
struct usb_interface *intf; |
| 1033 |
|
| 1034 |
brcmf_dbg(USB, "Enter\n"); |
| 1035 |
if (!devinfo) { |
| 1036 |
err = -ENODEV; |
| 1037 |
goto out; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if (!devinfo->image) { |
| 1041 |
brcmf_err("No firmware!\n"); |
| 1042 |
err = -ENOENT; |
| 1043 |
goto out; |
| 1044 |
} |
| 1045 |
|
| 1046 |
intf = to_usb_interface(devinfo->dev); |
| 1047 |
err = usb_autopm_get_interface(intf); |
| 1048 |
if (err) |
| 1049 |
goto out; |
| 1050 |
|
| 1051 |
err = brcmf_usb_dlstart(devinfo, |
| 1052 |
(u8 *)devinfo->image, devinfo->image_len); |
| 1053 |
if (err == 0) |
| 1054 |
err = brcmf_usb_dlrun(devinfo); |
| 1055 |
|
| 1056 |
usb_autopm_put_interface(intf); |
| 1057 |
out: |
| 1058 |
return err; |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
static void brcmf_usb_detach(struct brcmf_usbdev_info *devinfo) |
| 1063 |
{ |
| 1064 |
brcmf_dbg(USB, "Enter, devinfo %p\n", devinfo); |
| 1065 |
|
| 1066 |
/* free the URBS */ |
| 1067 |
brcmf_usb_free_q(&devinfo->rx_freeq); |
| 1068 |
brcmf_usb_free_q(&devinfo->tx_freeq); |
| 1069 |
|
| 1070 |
usb_free_urb(devinfo->ctl_urb); |
| 1071 |
usb_free_urb(devinfo->bulk_urb); |
| 1072 |
|
| 1073 |
kfree(devinfo->tx_reqs); |
| 1074 |
kfree(devinfo->rx_reqs); |
| 1075 |
|
| 1076 |
if (devinfo->settings) |
| 1077 |
brcmf_release_module_param(devinfo->settings); |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
static int check_file(const u8 *headers) |
| 1082 |
{ |
| 1083 |
struct trx_header_le *trx; |
| 1084 |
int actual_len = -1; |
| 1085 |
|
| 1086 |
brcmf_dbg(USB, "Enter\n"); |
| 1087 |
/* Extract trx header */ |
| 1088 |
trx = (struct trx_header_le *) headers; |
| 1089 |
if (trx->magic != cpu_to_le32(TRX_MAGIC)) |
| 1090 |
return -1; |
| 1091 |
|
| 1092 |
headers += sizeof(struct trx_header_le); |
| 1093 |
|
| 1094 |
if (le32_to_cpu(trx->flag_version) & TRX_UNCOMP_IMAGE) { |
| 1095 |
actual_len = le32_to_cpu(trx->offsets[TRX_OFFSETS_DLFWLEN_IDX]); |
| 1096 |
return actual_len + sizeof(struct trx_header_le); |
| 1097 |
} |
| 1098 |
return -1; |
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
static |
| 1103 |
struct brcmf_usbdev *brcmf_usb_attach(struct brcmf_usbdev_info *devinfo, |
| 1104 |
int nrxq, int ntxq) |
| 1105 |
{ |
| 1106 |
brcmf_dbg(USB, "Enter\n"); |
| 1107 |
|
| 1108 |
devinfo->bus_pub.nrxq = nrxq; |
| 1109 |
devinfo->rx_low_watermark = nrxq / 2; |
| 1110 |
devinfo->bus_pub.devinfo = devinfo; |
| 1111 |
devinfo->bus_pub.ntxq = ntxq; |
| 1112 |
devinfo->bus_pub.state = BRCMFMAC_USB_STATE_DOWN; |
| 1113 |
|
| 1114 |
/* flow control when too many tx urbs posted */ |
| 1115 |
devinfo->tx_low_watermark = ntxq / 4; |
| 1116 |
devinfo->tx_high_watermark = devinfo->tx_low_watermark * 3; |
| 1117 |
devinfo->bus_pub.bus_mtu = BRCMF_USB_MAX_PKT_SIZE; |
| 1118 |
|
| 1119 |
/* Initialize other structure content */ |
| 1120 |
init_waitqueue_head(&devinfo->ioctl_resp_wait); |
| 1121 |
|
| 1122 |
/* Initialize the spinlocks */ |
| 1123 |
spin_lock_init(&devinfo->qlock); |
| 1124 |
spin_lock_init(&devinfo->tx_flowblock_lock); |
| 1125 |
|
| 1126 |
INIT_LIST_HEAD(&devinfo->rx_freeq); |
| 1127 |
INIT_LIST_HEAD(&devinfo->rx_postq); |
| 1128 |
|
| 1129 |
INIT_LIST_HEAD(&devinfo->tx_freeq); |
| 1130 |
INIT_LIST_HEAD(&devinfo->tx_postq); |
| 1131 |
|
| 1132 |
devinfo->tx_flowblock = false; |
| 1133 |
|
| 1134 |
devinfo->rx_reqs = brcmf_usbdev_qinit(&devinfo->rx_freeq, nrxq); |
| 1135 |
if (!devinfo->rx_reqs) |
| 1136 |
goto error; |
| 1137 |
|
| 1138 |
devinfo->tx_reqs = brcmf_usbdev_qinit(&devinfo->tx_freeq, ntxq); |
| 1139 |
if (!devinfo->tx_reqs) |
| 1140 |
goto error; |
| 1141 |
devinfo->tx_freecount = ntxq; |
| 1142 |
|
| 1143 |
devinfo->ctl_urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 1144 |
if (!devinfo->ctl_urb) |
| 1145 |
goto error; |
| 1146 |
devinfo->bulk_urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 1147 |
if (!devinfo->bulk_urb) |
| 1148 |
goto error; |
| 1149 |
|
| 1150 |
return &devinfo->bus_pub; |
| 1151 |
|
| 1152 |
error: |
| 1153 |
brcmf_err("failed!\n"); |
| 1154 |
brcmf_usb_detach(devinfo); |
| 1155 |
return NULL; |
| 1156 |
} |
| 1157 |
|
| 1158 |
static int brcmf_usb_get_blob(struct device *dev, const struct firmware **fw, |
| 1159 |
enum brcmf_blob_type type) |
| 1160 |
{ |
| 1161 |
/* No blobs for USB devices... */ |
| 1162 |
return -ENOENT; |
| 1163 |
} |
| 1164 |
|
| 1165 |
static const struct brcmf_bus_ops brcmf_usb_bus_ops = { |
| 1166 |
.preinit = brcmf_usb_up, |
| 1167 |
.stop = brcmf_usb_down, |
| 1168 |
.txdata = brcmf_usb_tx, |
| 1169 |
.txctl = brcmf_usb_tx_ctlpkt, |
| 1170 |
.rxctl = brcmf_usb_rx_ctlpkt, |
| 1171 |
.get_blob = brcmf_usb_get_blob, |
| 1172 |
}; |
| 1173 |
|
| 1174 |
#define BRCMF_USB_FW_CODE 0 |
| 1175 |
|
| 1176 |
static void brcmf_usb_probe_phase2(struct device *dev, int ret, |
| 1177 |
struct brcmf_fw_request *fwreq) |
| 1178 |
{ |
| 1179 |
struct brcmf_bus *bus = dev_get_drvdata(dev); |
| 1180 |
struct brcmf_usbdev_info *devinfo = bus->bus_priv.usb->devinfo; |
| 1181 |
const struct firmware *fw; |
| 1182 |
|
| 1183 |
if (ret) |
| 1184 |
goto error; |
| 1185 |
|
| 1186 |
brcmf_dbg(USB, "Start fw downloading\n"); |
| 1187 |
|
| 1188 |
fw = fwreq->items[BRCMF_USB_FW_CODE].binary; |
| 1189 |
kfree(fwreq); |
| 1190 |
|
| 1191 |
ret = check_file(fw->data); |
| 1192 |
if (ret < 0) { |
| 1193 |
brcmf_err("invalid firmware\n"); |
| 1194 |
release_firmware(fw); |
| 1195 |
goto error; |
| 1196 |
} |
| 1197 |
|
| 1198 |
devinfo->image = fw->data; |
| 1199 |
devinfo->image_len = fw->size; |
| 1200 |
|
| 1201 |
ret = brcmf_usb_fw_download(devinfo); |
| 1202 |
release_firmware(fw); |
| 1203 |
if (ret) |
| 1204 |
goto error; |
| 1205 |
|
| 1206 |
ret = brcmf_alloc(devinfo->dev, devinfo->settings); |
| 1207 |
if (ret) |
| 1208 |
goto error; |
| 1209 |
|
| 1210 |
/* Attach to the common driver interface */ |
| 1211 |
ret = brcmf_attach(devinfo->dev); |
| 1212 |
if (ret) |
| 1213 |
goto error; |
| 1214 |
|
| 1215 |
complete(&devinfo->dev_init_done); |
| 1216 |
return; |
| 1217 |
error: |
| 1218 |
brcmf_dbg(TRACE, "failed: dev=%s, err=%d\n", dev_name(dev), ret); |
| 1219 |
complete(&devinfo->dev_init_done); |
| 1220 |
device_release_driver(dev); |
| 1221 |
} |
| 1222 |
|
| 1223 |
static struct brcmf_fw_request * |
| 1224 |
brcmf_usb_prepare_fw_request(struct brcmf_usbdev_info *devinfo) |
| 1225 |
{ |
| 1226 |
struct brcmf_fw_request *fwreq; |
| 1227 |
struct brcmf_fw_name fwnames[] = { |
| 1228 |
{ ".bin", devinfo->fw_name }, |
| 1229 |
}; |
| 1230 |
|
| 1231 |
fwreq = brcmf_fw_alloc_request(devinfo->bus_pub.devid, |
| 1232 |
devinfo->bus_pub.chiprev, |
| 1233 |
brcmf_usb_fwnames, |
| 1234 |
ARRAY_SIZE(brcmf_usb_fwnames), |
| 1235 |
fwnames, ARRAY_SIZE(fwnames)); |
| 1236 |
if (!fwreq) |
| 1237 |
return NULL; |
| 1238 |
|
| 1239 |
fwreq->items[BRCMF_USB_FW_CODE].type = BRCMF_FW_TYPE_BINARY; |
| 1240 |
|
| 1241 |
return fwreq; |
| 1242 |
} |
| 1243 |
|
| 1244 |
static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo, |
| 1245 |
enum brcmf_fwvendor fwvid) |
| 1246 |
{ |
| 1247 |
struct brcmf_bus *bus; |
| 1248 |
struct brcmf_usbdev *bus_pub; |
| 1249 |
struct device *dev = devinfo->dev; |
| 1250 |
struct brcmf_fw_request *fwreq; |
| 1251 |
int ret; |
| 1252 |
|
| 1253 |
brcmf_dbg(USB, "Enter\n"); |
| 1254 |
bus_pub = brcmf_usb_attach(devinfo, BRCMF_USB_NRXQ, BRCMF_USB_NTXQ); |
| 1255 |
if (!bus_pub) |
| 1256 |
return -ENODEV; |
| 1257 |
|
| 1258 |
bus = kzalloc_obj(*bus, GFP_ATOMIC); |
| 1259 |
if (!bus) { |
| 1260 |
ret = -ENOMEM; |
| 1261 |
goto fail; |
| 1262 |
} |
| 1263 |
|
| 1264 |
bus->dev = dev; |
| 1265 |
bus_pub->bus = bus; |
| 1266 |
bus->bus_priv.usb = bus_pub; |
| 1267 |
dev_set_drvdata(dev, bus); |
| 1268 |
bus->ops = &brcmf_usb_bus_ops; |
| 1269 |
bus->proto_type = BRCMF_PROTO_BCDC; |
| 1270 |
bus->fwvid = fwvid; |
| 1271 |
bus->always_use_fws_queue = true; |
| 1272 |
#ifdef CONFIG_PM |
| 1273 |
bus->wowl_supported = true; |
| 1274 |
#endif |
| 1275 |
|
| 1276 |
devinfo->settings = brcmf_get_module_param(bus->dev, BRCMF_BUSTYPE_USB, |
| 1277 |
bus_pub->devid, |
| 1278 |
bus_pub->chiprev); |
| 1279 |
if (!devinfo->settings) { |
| 1280 |
ret = -ENOMEM; |
| 1281 |
goto fail; |
| 1282 |
} |
| 1283 |
ret = PTR_ERR_OR_ZERO(devinfo->settings); |
| 1284 |
if (ret < 0) |
| 1285 |
goto fail; |
| 1286 |
|
| 1287 |
if (!brcmf_usb_dlneeded(devinfo)) { |
| 1288 |
ret = brcmf_alloc(devinfo->dev, devinfo->settings); |
| 1289 |
if (ret) |
| 1290 |
goto fail; |
| 1291 |
ret = brcmf_attach(devinfo->dev); |
| 1292 |
if (ret) |
| 1293 |
goto fail; |
| 1294 |
/* we are done */ |
| 1295 |
complete(&devinfo->dev_init_done); |
| 1296 |
return 0; |
| 1297 |
} |
| 1298 |
bus->chip = bus_pub->devid; |
| 1299 |
bus->chiprev = bus_pub->chiprev; |
| 1300 |
|
| 1301 |
fwreq = brcmf_usb_prepare_fw_request(devinfo); |
| 1302 |
if (!fwreq) { |
| 1303 |
ret = -ENOMEM; |
| 1304 |
goto fail; |
| 1305 |
} |
| 1306 |
|
| 1307 |
/* request firmware here */ |
| 1308 |
ret = brcmf_fw_get_firmwares(dev, fwreq, brcmf_usb_probe_phase2); |
| 1309 |
if (ret) { |
| 1310 |
brcmf_err("firmware request failed: %d\n", ret); |
| 1311 |
kfree(fwreq); |
| 1312 |
goto fail; |
| 1313 |
} |
| 1314 |
|
| 1315 |
return 0; |
| 1316 |
|
| 1317 |
fail: |
| 1318 |
/* Release resources in reverse order */ |
| 1319 |
brcmf_free(devinfo->dev); |
| 1320 |
kfree(bus); |
| 1321 |
brcmf_usb_detach(devinfo); |
| 1322 |
return ret; |
| 1323 |
} |
| 1324 |
|
| 1325 |
static void |
| 1326 |
brcmf_usb_disconnect_cb(struct brcmf_usbdev_info *devinfo) |
| 1327 |
{ |
| 1328 |
if (!devinfo) |
| 1329 |
return; |
| 1330 |
brcmf_dbg(USB, "Enter, bus_pub %p\n", devinfo); |
| 1331 |
|
| 1332 |
brcmf_detach(devinfo->dev); |
| 1333 |
brcmf_free(devinfo->dev); |
| 1334 |
kfree(devinfo->bus_pub.bus); |
| 1335 |
brcmf_usb_detach(devinfo); |
| 1336 |
} |
| 1337 |
|
| 1338 |
/* Forward declaration for usb_match_id() call */ |
| 1339 |
static const struct usb_device_id brcmf_usb_devid_table[]; |
| 1340 |
|
| 1341 |
static int |
| 1342 |
brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 1343 |
{ |
| 1344 |
struct usb_device *usb = interface_to_usbdev(intf); |
| 1345 |
struct brcmf_usbdev_info *devinfo; |
| 1346 |
struct usb_interface_descriptor *desc; |
| 1347 |
struct usb_endpoint_descriptor *endpoint; |
| 1348 |
int ret = 0; |
| 1349 |
u32 num_of_eps; |
| 1350 |
u8 endpoint_num, ep; |
| 1351 |
|
| 1352 |
if (!id) { |
| 1353 |
id = usb_match_id(intf, brcmf_usb_devid_table); |
| 1354 |
if (!id) { |
| 1355 |
dev_err(&intf->dev, "Error could not find matching usb_device_id\n"); |
| 1356 |
return -ENODEV; |
| 1357 |
} |
| 1358 |
} |
| 1359 |
|
| 1360 |
brcmf_dbg(USB, "Enter 0x%04x:0x%04x\n", id->idVendor, id->idProduct); |
| 1361 |
|
| 1362 |
devinfo = kzalloc_obj(*devinfo, GFP_ATOMIC); |
| 1363 |
if (devinfo == NULL) |
| 1364 |
return -ENOMEM; |
| 1365 |
|
| 1366 |
devinfo->usbdev = usb; |
| 1367 |
devinfo->dev = &usb->dev; |
| 1368 |
/* Init completion, to protect for disconnect while still loading. |
| 1369 |
* Necessary because of the asynchronous firmware load construction |
| 1370 |
*/ |
| 1371 |
init_completion(&devinfo->dev_init_done); |
| 1372 |
|
| 1373 |
usb_set_intfdata(intf, devinfo); |
| 1374 |
|
| 1375 |
intf->needs_remote_wakeup = 1; |
| 1376 |
|
| 1377 |
/* Check that the device supports only one configuration */ |
| 1378 |
if (usb->descriptor.bNumConfigurations != 1) { |
| 1379 |
brcmf_err("Number of configurations: %d not supported\n", |
| 1380 |
usb->descriptor.bNumConfigurations); |
| 1381 |
ret = -ENODEV; |
| 1382 |
goto fail; |
| 1383 |
} |
| 1384 |
|
| 1385 |
if ((usb->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) && |
| 1386 |
(usb->descriptor.bDeviceClass != USB_CLASS_MISC) && |
| 1387 |
(usb->descriptor.bDeviceClass != USB_CLASS_WIRELESS_CONTROLLER)) { |
| 1388 |
brcmf_err("Device class: 0x%x not supported\n", |
| 1389 |
usb->descriptor.bDeviceClass); |
| 1390 |
ret = -ENODEV; |
| 1391 |
goto fail; |
| 1392 |
} |
| 1393 |
|
| 1394 |
desc = &intf->cur_altsetting->desc; |
| 1395 |
if ((desc->bInterfaceClass != USB_CLASS_VENDOR_SPEC) || |
| 1396 |
(desc->bInterfaceSubClass != 2) || |
| 1397 |
(desc->bInterfaceProtocol != 0xff)) { |
| 1398 |
brcmf_err("non WLAN interface %d: 0x%x:0x%x:0x%x\n", |
| 1399 |
desc->bInterfaceNumber, desc->bInterfaceClass, |
| 1400 |
desc->bInterfaceSubClass, desc->bInterfaceProtocol); |
| 1401 |
ret = -ENODEV; |
| 1402 |
goto fail; |
| 1403 |
} |
| 1404 |
|
| 1405 |
num_of_eps = desc->bNumEndpoints; |
| 1406 |
for (ep = 0; ep < num_of_eps; ep++) { |
| 1407 |
endpoint = &intf->cur_altsetting->endpoint[ep].desc; |
| 1408 |
endpoint_num = usb_endpoint_num(endpoint); |
| 1409 |
if (!usb_endpoint_xfer_bulk(endpoint)) |
| 1410 |
continue; |
| 1411 |
if (usb_endpoint_dir_in(endpoint)) { |
| 1412 |
if (!devinfo->rx_pipe) |
| 1413 |
devinfo->rx_pipe = |
| 1414 |
usb_rcvbulkpipe(usb, endpoint_num); |
| 1415 |
} else { |
| 1416 |
if (!devinfo->tx_pipe) |
| 1417 |
devinfo->tx_pipe = |
| 1418 |
usb_sndbulkpipe(usb, endpoint_num); |
| 1419 |
} |
| 1420 |
} |
| 1421 |
if (devinfo->rx_pipe == 0) { |
| 1422 |
brcmf_err("No RX (in) Bulk EP found\n"); |
| 1423 |
ret = -ENODEV; |
| 1424 |
goto fail; |
| 1425 |
} |
| 1426 |
if (devinfo->tx_pipe == 0) { |
| 1427 |
brcmf_err("No TX (out) Bulk EP found\n"); |
| 1428 |
ret = -ENODEV; |
| 1429 |
goto fail; |
| 1430 |
} |
| 1431 |
|
| 1432 |
devinfo->ifnum = desc->bInterfaceNumber; |
| 1433 |
|
| 1434 |
if (usb->speed == USB_SPEED_SUPER_PLUS) |
| 1435 |
brcmf_dbg(USB, "Broadcom super speed plus USB WLAN interface detected\n"); |
| 1436 |
else if (usb->speed == USB_SPEED_SUPER) |
| 1437 |
brcmf_dbg(USB, "Broadcom super speed USB WLAN interface detected\n"); |
| 1438 |
else if (usb->speed == USB_SPEED_HIGH) |
| 1439 |
brcmf_dbg(USB, "Broadcom high speed USB WLAN interface detected\n"); |
| 1440 |
else |
| 1441 |
brcmf_dbg(USB, "Broadcom full speed USB WLAN interface detected\n"); |
| 1442 |
|
| 1443 |
ret = brcmf_usb_probe_cb(devinfo, id->driver_info); |
| 1444 |
if (ret) |
| 1445 |
goto fail; |
| 1446 |
|
| 1447 |
/* Success */ |
| 1448 |
return 0; |
| 1449 |
|
| 1450 |
fail: |
| 1451 |
complete(&devinfo->dev_init_done); |
| 1452 |
kfree(devinfo); |
| 1453 |
usb_set_intfdata(intf, NULL); |
| 1454 |
return ret; |
| 1455 |
} |
| 1456 |
|
| 1457 |
static void |
| 1458 |
brcmf_usb_disconnect(struct usb_interface *intf) |
| 1459 |
{ |
| 1460 |
struct brcmf_usbdev_info *devinfo; |
| 1461 |
|
| 1462 |
brcmf_dbg(USB, "Enter\n"); |
| 1463 |
devinfo = (struct brcmf_usbdev_info *)usb_get_intfdata(intf); |
| 1464 |
|
| 1465 |
if (devinfo) { |
| 1466 |
wait_for_completion(&devinfo->dev_init_done); |
| 1467 |
/* Make sure that devinfo still exists. Firmware probe routines |
| 1468 |
* may have released the device and cleared the intfdata. |
| 1469 |
*/ |
| 1470 |
if (!usb_get_intfdata(intf)) |
| 1471 |
goto done; |
| 1472 |
|
| 1473 |
brcmf_usb_disconnect_cb(devinfo); |
| 1474 |
kfree(devinfo); |
| 1475 |
} |
| 1476 |
done: |
| 1477 |
brcmf_dbg(USB, "Exit\n"); |
| 1478 |
} |
| 1479 |
|
| 1480 |
/* |
| 1481 |
* only need to signal the bus being down and update the state. |
| 1482 |
*/ |
| 1483 |
static int brcmf_usb_suspend(struct usb_interface *intf, pm_message_t state) |
| 1484 |
{ |
| 1485 |
struct usb_device *usb = interface_to_usbdev(intf); |
| 1486 |
struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev); |
| 1487 |
|
| 1488 |
brcmf_dbg(USB, "Enter\n"); |
| 1489 |
devinfo->bus_pub.state = BRCMFMAC_USB_STATE_SLEEP; |
| 1490 |
brcmf_cancel_all_urbs(devinfo); |
| 1491 |
device_set_wakeup_enable(devinfo->dev, true); |
| 1492 |
return 0; |
| 1493 |
} |
| 1494 |
|
| 1495 |
/* |
| 1496 |
* (re-) start the bus. |
| 1497 |
*/ |
| 1498 |
static int brcmf_usb_resume(struct usb_interface *intf) |
| 1499 |
{ |
| 1500 |
struct usb_device *usb = interface_to_usbdev(intf); |
| 1501 |
struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev); |
| 1502 |
|
| 1503 |
brcmf_dbg(USB, "Enter\n"); |
| 1504 |
|
| 1505 |
devinfo->bus_pub.state = BRCMFMAC_USB_STATE_UP; |
| 1506 |
brcmf_usb_rx_fill_all(devinfo); |
| 1507 |
device_set_wakeup_enable(devinfo->dev, false); |
| 1508 |
return 0; |
| 1509 |
} |
| 1510 |
|
| 1511 |
static int brcmf_usb_reset_resume(struct usb_interface *intf) |
| 1512 |
{ |
| 1513 |
struct usb_device *usb = interface_to_usbdev(intf); |
| 1514 |
struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev); |
| 1515 |
struct brcmf_fw_request *fwreq; |
| 1516 |
int ret; |
| 1517 |
|
| 1518 |
brcmf_dbg(USB, "Enter\n"); |
| 1519 |
|
| 1520 |
fwreq = brcmf_usb_prepare_fw_request(devinfo); |
| 1521 |
if (!fwreq) |
| 1522 |
return -ENOMEM; |
| 1523 |
|
| 1524 |
ret = brcmf_fw_get_firmwares(&usb->dev, fwreq, brcmf_usb_probe_phase2); |
| 1525 |
if (ret < 0) |
| 1526 |
kfree(fwreq); |
| 1527 |
|
| 1528 |
return ret; |
| 1529 |
} |
| 1530 |
|
| 1531 |
#define BRCMF_USB_DEVICE(dev_id) \ |
| 1532 |
{ \ |
| 1533 |
USB_DEVICE(BRCM_USB_VENDOR_ID_BROADCOM, dev_id), \ |
| 1534 |
.driver_info = BRCMF_FWVENDOR_WCC \ |
| 1535 |
} |
| 1536 |
|
| 1537 |
#define LINKSYS_USB_DEVICE(dev_id) \ |
| 1538 |
{ \ |
| 1539 |
USB_DEVICE(BRCM_USB_VENDOR_ID_LINKSYS, dev_id), \ |
| 1540 |
.driver_info = BRCMF_FWVENDOR_WCC \ |
| 1541 |
} |
| 1542 |
|
| 1543 |
#define CYPRESS_USB_DEVICE(dev_id) \ |
| 1544 |
{ \ |
| 1545 |
USB_DEVICE(CY_USB_VENDOR_ID_CYPRESS, dev_id), \ |
| 1546 |
.driver_info = BRCMF_FWVENDOR_WCC \ |
| 1547 |
} |
| 1548 |
|
| 1549 |
static const struct usb_device_id brcmf_usb_devid_table[] = { |
| 1550 |
BRCMF_USB_DEVICE(BRCM_USB_43143_DEVICE_ID), |
| 1551 |
BRCMF_USB_DEVICE(BRCM_USB_43236_DEVICE_ID), |
| 1552 |
BRCMF_USB_DEVICE(BRCM_USB_43242_DEVICE_ID), |
| 1553 |
BRCMF_USB_DEVICE(BRCM_USB_43569_DEVICE_ID), |
| 1554 |
LINKSYS_USB_DEVICE(BRCM_USB_43235_LINKSYS_DEVICE_ID), |
| 1555 |
CYPRESS_USB_DEVICE(CY_USB_4373_DEVICE_ID), |
| 1556 |
{ USB_DEVICE(BRCM_USB_VENDOR_ID_LG, BRCM_USB_43242_LG_DEVICE_ID) }, |
| 1557 |
/* special entry for device with firmware loaded and running */ |
| 1558 |
BRCMF_USB_DEVICE(BRCM_USB_BCMFW_DEVICE_ID), |
| 1559 |
CYPRESS_USB_DEVICE(BRCM_USB_BCMFW_DEVICE_ID), |
| 1560 |
{ /* end: all zeroes */ } |
| 1561 |
}; |
| 1562 |
|
| 1563 |
MODULE_DEVICE_TABLE(usb, brcmf_usb_devid_table); |
| 1564 |
|
| 1565 |
static struct usb_driver brcmf_usbdrvr = { |
| 1566 |
.name = KBUILD_MODNAME, |
| 1567 |
.probe = brcmf_usb_probe, |
| 1568 |
.disconnect = brcmf_usb_disconnect, |
| 1569 |
.id_table = brcmf_usb_devid_table, |
| 1570 |
.suspend = brcmf_usb_suspend, |
| 1571 |
.resume = brcmf_usb_resume, |
| 1572 |
.reset_resume = brcmf_usb_reset_resume, |
| 1573 |
.supports_autosuspend = true, |
| 1574 |
.disable_hub_initiated_lpm = 1, |
| 1575 |
}; |
| 1576 |
|
| 1577 |
static int brcmf_usb_reset_device(struct device *dev, void *notused) |
| 1578 |
{ |
| 1579 |
/* device past is the usb interface so we |
| 1580 |
* need to use parent here. |
| 1581 |
*/ |
| 1582 |
brcmf_dev_reset(dev->parent); |
| 1583 |
return 0; |
| 1584 |
} |
| 1585 |
|
| 1586 |
void brcmf_usb_exit(void) |
| 1587 |
{ |
| 1588 |
struct device_driver *drv = &brcmf_usbdrvr.driver; |
| 1589 |
int ret; |
| 1590 |
|
| 1591 |
brcmf_dbg(USB, "Enter\n"); |
| 1592 |
ret = driver_for_each_device(drv, NULL, NULL, |
| 1593 |
brcmf_usb_reset_device); |
| 1594 |
if (ret) |
| 1595 |
brcmf_err("failed to reset all usb devices %d\n", ret); |
| 1596 |
|
| 1597 |
usb_deregister(&brcmf_usbdrvr); |
| 1598 |
} |
| 1599 |
|
| 1600 |
int brcmf_usb_register(void) |
| 1601 |
{ |
| 1602 |
brcmf_dbg(USB, "Enter\n"); |
| 1603 |
return usb_register(&brcmf_usbdrvr); |
| 1604 |
} |