aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/brcm80211/brcmfmac/usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/brcm80211/brcmfmac/usb.c')
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb.c363
1 files changed, 167 insertions, 196 deletions
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index 484a6e4f23a2..914c56fe6c5f 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -14,24 +14,12 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/init.h>
18#include <linux/kernel.h> 17#include <linux/kernel.h>
19#include <linux/module.h> 18#include <linux/module.h>
20#include <linux/kthread.h>
21#include <linux/slab.h>
22#include <linux/skbuff.h>
23#include <linux/netdevice.h>
24#include <linux/spinlock.h>
25#include <linux/ethtool.h>
26#include <linux/fcntl.h>
27#include <linux/fs.h>
28#include <linux/uaccess.h>
29#include <linux/firmware.h> 19#include <linux/firmware.h>
30#include <linux/usb.h> 20#include <linux/usb.h>
31#include <linux/vmalloc.h> 21#include <linux/vmalloc.h>
32#include <net/cfg80211.h>
33 22
34#include <defs.h>
35#include <brcmu_utils.h> 23#include <brcmu_utils.h>
36#include <brcmu_wifi.h> 24#include <brcmu_wifi.h>
37#include <dhd_bus.h> 25#include <dhd_bus.h>
@@ -42,13 +30,11 @@
42 30
43#define IOCTL_RESP_TIMEOUT 2000 31#define IOCTL_RESP_TIMEOUT 2000
44 32
45#define BRCMF_USB_DLIMAGE_SPINWAIT 100 /* in unit of ms */ 33#define BRCMF_USB_RESET_GETVER_SPINWAIT 100 /* in unit of ms */
46#define BRCMF_USB_DLIMAGE_LIMIT 500 /* spinwait limit (ms) */ 34#define BRCMF_USB_RESET_GETVER_LOOP_CNT 10
47 35
48#define BRCMF_POSTBOOT_ID 0xA123 /* ID to detect if dongle 36#define BRCMF_POSTBOOT_ID 0xA123 /* ID to detect if dongle
49 has boot up */ 37 has boot up */
50#define BRCMF_USB_RESETCFG_SPINWAIT 1 /* wait after resetcfg (ms) */
51
52#define BRCMF_USB_NRXQ 50 38#define BRCMF_USB_NRXQ 50
53#define BRCMF_USB_NTXQ 50 39#define BRCMF_USB_NTXQ 50
54 40
@@ -69,16 +55,6 @@
69#define BRCMF_USB_43236_FW_NAME "brcm/brcmfmac43236b.bin" 55#define BRCMF_USB_43236_FW_NAME "brcm/brcmfmac43236b.bin"
70#define BRCMF_USB_43242_FW_NAME "brcm/brcmfmac43242a.bin" 56#define BRCMF_USB_43242_FW_NAME "brcm/brcmfmac43242a.bin"
71 57
72enum usbdev_suspend_state {
73 USBOS_SUSPEND_STATE_DEVICE_ACTIVE = 0, /* Device is busy, won't allow
74 suspend */
75 USBOS_SUSPEND_STATE_SUSPEND_PENDING, /* Device is idle, can be
76 * suspended. Wating PM to
77 * suspend the device
78 */
79 USBOS_SUSPEND_STATE_SUSPENDED /* Device suspended */
80};
81
82struct brcmf_usb_image { 58struct brcmf_usb_image {
83 struct list_head list; 59 struct list_head list;
84 s8 *fwname; 60 s8 *fwname;
@@ -99,10 +75,8 @@ struct brcmf_usbdev_info {
99 struct list_head rx_postq; 75 struct list_head rx_postq;
100 struct list_head tx_freeq; 76 struct list_head tx_freeq;
101 struct list_head tx_postq; 77 struct list_head tx_postq;
102 enum usbdev_suspend_state suspend_state;
103 uint rx_pipe, tx_pipe, intr_pipe, rx_pipe2; 78 uint rx_pipe, tx_pipe, intr_pipe, rx_pipe2;
104 79
105 bool activity;
106 int rx_low_watermark; 80 int rx_low_watermark;
107 int tx_low_watermark; 81 int tx_low_watermark;
108 int tx_high_watermark; 82 int tx_high_watermark;
@@ -170,6 +144,7 @@ static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info *devinfo)
170static void 144static void
171brcmf_usb_ctl_complete(struct brcmf_usbdev_info *devinfo, int type, int status) 145brcmf_usb_ctl_complete(struct brcmf_usbdev_info *devinfo, int type, int status)
172{ 146{
147 brcmf_dbg(USB, "Enter, status=%d\n", status);
173 148
174 if (unlikely(devinfo == NULL)) 149 if (unlikely(devinfo == NULL))
175 return; 150 return;
@@ -197,6 +172,7 @@ brcmf_usb_ctlread_complete(struct urb *urb)
197 struct brcmf_usbdev_info *devinfo = 172 struct brcmf_usbdev_info *devinfo =
198 (struct brcmf_usbdev_info *)urb->context; 173 (struct brcmf_usbdev_info *)urb->context;
199 174
175 brcmf_dbg(USB, "Enter\n");
200 devinfo->ctl_urb_actual_length = urb->actual_length; 176 devinfo->ctl_urb_actual_length = urb->actual_length;
201 brcmf_usb_ctl_complete(devinfo, BRCMF_USB_CBCTL_READ, 177 brcmf_usb_ctl_complete(devinfo, BRCMF_USB_CBCTL_READ,
202 urb->status); 178 urb->status);
@@ -208,33 +184,22 @@ brcmf_usb_ctlwrite_complete(struct urb *urb)
208 struct brcmf_usbdev_info *devinfo = 184 struct brcmf_usbdev_info *devinfo =
209 (struct brcmf_usbdev_info *)urb->context; 185 (struct brcmf_usbdev_info *)urb->context;
210 186
187 brcmf_dbg(USB, "Enter\n");
211 brcmf_usb_ctl_complete(devinfo, BRCMF_USB_CBCTL_WRITE, 188 brcmf_usb_ctl_complete(devinfo, BRCMF_USB_CBCTL_WRITE,
212 urb->status); 189 urb->status);
213} 190}
214 191
215static int brcmf_usb_pnp(struct brcmf_usbdev_info *devinfo, uint state)
216{
217 return 0;
218}
219
220static int 192static int
221brcmf_usb_send_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len) 193brcmf_usb_send_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len)
222{ 194{
223 int ret; 195 int ret;
224 u16 size; 196 u16 size;
225 197
198 brcmf_dbg(USB, "Enter\n");
226 if (devinfo == NULL || buf == NULL || 199 if (devinfo == NULL || buf == NULL ||
227 len == 0 || devinfo->ctl_urb == NULL) 200 len == 0 || devinfo->ctl_urb == NULL)
228 return -EINVAL; 201 return -EINVAL;
229 202
230 /* If the USB/HSIC bus in sleep state, wake it up */
231 if (devinfo->suspend_state == USBOS_SUSPEND_STATE_SUSPENDED)
232 if (brcmf_usb_pnp(devinfo, BCMFMAC_USB_PNP_RESUME) != 0) {
233 brcmf_dbg(ERROR, "Could not Resume the bus!\n");
234 return -EIO;
235 }
236
237 devinfo->activity = true;
238 size = len; 203 size = len;
239 devinfo->ctl_write.wLength = cpu_to_le16p(&size); 204 devinfo->ctl_write.wLength = cpu_to_le16p(&size);
240 devinfo->ctl_urb->transfer_buffer_length = size; 205 devinfo->ctl_urb->transfer_buffer_length = size;
@@ -251,7 +216,7 @@ brcmf_usb_send_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len)
251 216
252 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC); 217 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC);
253 if (ret < 0) 218 if (ret < 0)
254 brcmf_dbg(ERROR, "usb_submit_urb failed %d\n", ret); 219 brcmf_err("usb_submit_urb failed %d\n", ret);
255 220
256 return ret; 221 return ret;
257} 222}
@@ -262,6 +227,7 @@ brcmf_usb_recv_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len)
262 int ret; 227 int ret;
263 u16 size; 228 u16 size;
264 229
230 brcmf_dbg(USB, "Enter\n");
265 if ((devinfo == NULL) || (buf == NULL) || (len == 0) 231 if ((devinfo == NULL) || (buf == NULL) || (len == 0)
266 || (devinfo->ctl_urb == NULL)) 232 || (devinfo->ctl_urb == NULL))
267 return -EINVAL; 233 return -EINVAL;
@@ -284,7 +250,7 @@ brcmf_usb_recv_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len)
284 250
285 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC); 251 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC);
286 if (ret < 0) 252 if (ret < 0)
287 brcmf_dbg(ERROR, "usb_submit_urb failed %d\n", ret); 253 brcmf_err("usb_submit_urb failed %d\n", ret);
288 254
289 return ret; 255 return ret;
290} 256}
@@ -295,10 +261,9 @@ static int brcmf_usb_tx_ctlpkt(struct device *dev, u8 *buf, u32 len)
295 int timeout = 0; 261 int timeout = 0;
296 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); 262 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
297 263
298 if (devinfo->bus_pub.state != BCMFMAC_USB_STATE_UP) { 264 brcmf_dbg(USB, "Enter\n");
299 /* TODO: handle suspend/resume */ 265 if (devinfo->bus_pub.state != BRCMFMAC_USB_STATE_UP)
300 return -EIO; 266 return -EIO;
301 }
302 267
303 if (test_and_set_bit(0, &devinfo->ctl_op)) 268 if (test_and_set_bit(0, &devinfo->ctl_op))
304 return -EIO; 269 return -EIO;
@@ -306,14 +271,14 @@ static int brcmf_usb_tx_ctlpkt(struct device *dev, u8 *buf, u32 len)
306 devinfo->ctl_completed = false; 271 devinfo->ctl_completed = false;
307 err = brcmf_usb_send_ctl(devinfo, buf, len); 272 err = brcmf_usb_send_ctl(devinfo, buf, len);
308 if (err) { 273 if (err) {
309 brcmf_dbg(ERROR, "fail %d bytes: %d\n", err, len); 274 brcmf_err("fail %d bytes: %d\n", err, len);
310 clear_bit(0, &devinfo->ctl_op); 275 clear_bit(0, &devinfo->ctl_op);
311 return err; 276 return err;
312 } 277 }
313 timeout = brcmf_usb_ioctl_resp_wait(devinfo); 278 timeout = brcmf_usb_ioctl_resp_wait(devinfo);
314 clear_bit(0, &devinfo->ctl_op); 279 clear_bit(0, &devinfo->ctl_op);
315 if (!timeout) { 280 if (!timeout) {
316 brcmf_dbg(ERROR, "Txctl wait timed out\n"); 281 brcmf_err("Txctl wait timed out\n");
317 err = -EIO; 282 err = -EIO;
318 } 283 }
319 return err; 284 return err;
@@ -325,17 +290,17 @@ static int brcmf_usb_rx_ctlpkt(struct device *dev, u8 *buf, u32 len)
325 int timeout = 0; 290 int timeout = 0;
326 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); 291 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
327 292
328 if (devinfo->bus_pub.state != BCMFMAC_USB_STATE_UP) { 293 brcmf_dbg(USB, "Enter\n");
329 /* TODO: handle suspend/resume */ 294 if (devinfo->bus_pub.state != BRCMFMAC_USB_STATE_UP)
330 return -EIO; 295 return -EIO;
331 } 296
332 if (test_and_set_bit(0, &devinfo->ctl_op)) 297 if (test_and_set_bit(0, &devinfo->ctl_op))
333 return -EIO; 298 return -EIO;
334 299
335 devinfo->ctl_completed = false; 300 devinfo->ctl_completed = false;
336 err = brcmf_usb_recv_ctl(devinfo, buf, len); 301 err = brcmf_usb_recv_ctl(devinfo, buf, len);
337 if (err) { 302 if (err) {
338 brcmf_dbg(ERROR, "fail %d bytes: %d\n", err, len); 303 brcmf_err("fail %d bytes: %d\n", err, len);
339 clear_bit(0, &devinfo->ctl_op); 304 clear_bit(0, &devinfo->ctl_op);
340 return err; 305 return err;
341 } 306 }
@@ -343,7 +308,7 @@ static int brcmf_usb_rx_ctlpkt(struct device *dev, u8 *buf, u32 len)
343 err = devinfo->ctl_urb_status; 308 err = devinfo->ctl_urb_status;
344 clear_bit(0, &devinfo->ctl_op); 309 clear_bit(0, &devinfo->ctl_op);
345 if (!timeout) { 310 if (!timeout) {
346 brcmf_dbg(ERROR, "rxctl wait timed out\n"); 311 brcmf_err("rxctl wait timed out\n");
347 err = -EIO; 312 err = -EIO;
348 } 313 }
349 if (!err) 314 if (!err)
@@ -391,7 +356,7 @@ brcmf_usbdev_qinit(struct list_head *q, int qsize)
391 356
392 reqs = kzalloc(sizeof(struct brcmf_usbreq) * qsize, GFP_ATOMIC); 357 reqs = kzalloc(sizeof(struct brcmf_usbreq) * qsize, GFP_ATOMIC);
393 if (reqs == NULL) { 358 if (reqs == NULL) {
394 brcmf_dbg(ERROR, "fail to allocate memory!\n"); 359 brcmf_err("fail to allocate memory!\n");
395 return NULL; 360 return NULL;
396 } 361 }
397 req = reqs; 362 req = reqs;
@@ -407,7 +372,7 @@ brcmf_usbdev_qinit(struct list_head *q, int qsize)
407 } 372 }
408 return reqs; 373 return reqs;
409fail: 374fail:
410 brcmf_dbg(ERROR, "fail!\n"); 375 brcmf_err("fail!\n");
411 while (!list_empty(q)) { 376 while (!list_empty(q)) {
412 req = list_entry(q->next, struct brcmf_usbreq, list); 377 req = list_entry(q->next, struct brcmf_usbreq, list);
413 if (req && req->urb) 378 if (req && req->urb)
@@ -424,7 +389,7 @@ static void brcmf_usb_free_q(struct list_head *q, bool pending)
424 int i = 0; 389 int i = 0;
425 list_for_each_entry_safe(req, next, q, list) { 390 list_for_each_entry_safe(req, next, q, list) {
426 if (!req->urb) { 391 if (!req->urb) {
427 brcmf_dbg(ERROR, "bad req\n"); 392 brcmf_err("bad req\n");
428 break; 393 break;
429 } 394 }
430 i++; 395 i++;
@@ -453,6 +418,8 @@ static void brcmf_usb_tx_complete(struct urb *urb)
453 struct brcmf_usbreq *req = (struct brcmf_usbreq *)urb->context; 418 struct brcmf_usbreq *req = (struct brcmf_usbreq *)urb->context;
454 struct brcmf_usbdev_info *devinfo = req->devinfo; 419 struct brcmf_usbdev_info *devinfo = req->devinfo;
455 420
421 brcmf_dbg(USB, "Enter, urb->status=%d, skb=%p\n", urb->status,
422 req->skb);
456 brcmf_usb_del_fromq(devinfo, req); 423 brcmf_usb_del_fromq(devinfo, req);
457 if (urb->status == 0) 424 if (urb->status == 0)
458 devinfo->bus_pub.bus->dstats.tx_packets++; 425 devinfo->bus_pub.bus->dstats.tx_packets++;
@@ -478,6 +445,7 @@ static void brcmf_usb_rx_complete(struct urb *urb)
478 struct sk_buff *skb; 445 struct sk_buff *skb;
479 int ifidx = 0; 446 int ifidx = 0;
480 447
448 brcmf_dbg(USB, "Enter, urb->status=%d\n", urb->status);
481 brcmf_usb_del_fromq(devinfo, req); 449 brcmf_usb_del_fromq(devinfo, req);
482 skb = req->skb; 450 skb = req->skb;
483 req->skb = NULL; 451 req->skb = NULL;
@@ -491,10 +459,10 @@ static void brcmf_usb_rx_complete(struct urb *urb)
491 return; 459 return;
492 } 460 }
493 461
494 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_UP) { 462 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP) {
495 skb_put(skb, urb->actual_length); 463 skb_put(skb, urb->actual_length);
496 if (brcmf_proto_hdrpull(devinfo->dev, &ifidx, skb) != 0) { 464 if (brcmf_proto_hdrpull(devinfo->dev, &ifidx, skb) != 0) {
497 brcmf_dbg(ERROR, "rx protocol error\n"); 465 brcmf_err("rx protocol error\n");
498 brcmu_pkt_buf_free_skb(skb); 466 brcmu_pkt_buf_free_skb(skb);
499 devinfo->bus_pub.bus->dstats.rx_errors++; 467 devinfo->bus_pub.bus->dstats.rx_errors++;
500 } else 468 } else
@@ -544,8 +512,8 @@ static void brcmf_usb_rx_fill_all(struct brcmf_usbdev_info *devinfo)
544{ 512{
545 struct brcmf_usbreq *req; 513 struct brcmf_usbreq *req;
546 514
547 if (devinfo->bus_pub.state != BCMFMAC_USB_STATE_UP) { 515 if (devinfo->bus_pub.state != BRCMFMAC_USB_STATE_UP) {
548 brcmf_dbg(ERROR, "bus is not up\n"); 516 brcmf_err("bus is not up=%d\n", devinfo->bus_pub.state);
549 return; 517 return;
550 } 518 }
551 while ((req = brcmf_usb_deq(devinfo, &devinfo->rx_freeq, NULL)) != NULL) 519 while ((req = brcmf_usb_deq(devinfo, &devinfo->rx_freeq, NULL)) != NULL)
@@ -558,29 +526,24 @@ brcmf_usb_state_change(struct brcmf_usbdev_info *devinfo, int state)
558 struct brcmf_bus *bcmf_bus = devinfo->bus_pub.bus; 526 struct brcmf_bus *bcmf_bus = devinfo->bus_pub.bus;
559 int old_state; 527 int old_state;
560 528
529 brcmf_dbg(USB, "Enter, current state=%d, new state=%d\n",
530 devinfo->bus_pub.state, state);
561 531
562 if (devinfo->bus_pub.state == state) 532 if (devinfo->bus_pub.state == state)
563 return; 533 return;
564 534
565 old_state = devinfo->bus_pub.state; 535 old_state = devinfo->bus_pub.state;
566 brcmf_dbg(TRACE, "dbus state change from %d to to %d\n", 536 devinfo->bus_pub.state = state;
567 old_state, state);
568
569 /* Don't update state if it's PnP firmware re-download */
570 if (state != BCMFMAC_USB_STATE_PNP_FWDL) /* TODO */
571 devinfo->bus_pub.state = state;
572
573 if ((old_state == BCMFMAC_USB_STATE_SLEEP)
574 && (state == BCMFMAC_USB_STATE_UP)) {
575 brcmf_usb_rx_fill_all(devinfo);
576 }
577 537
578 /* update state of upper layer */ 538 /* update state of upper layer */
579 if (state == BCMFMAC_USB_STATE_DOWN) { 539 if (state == BRCMFMAC_USB_STATE_DOWN) {
580 brcmf_dbg(INFO, "DBUS is down\n"); 540 brcmf_dbg(USB, "DBUS is down\n");
581 bcmf_bus->state = BRCMF_BUS_DOWN; 541 bcmf_bus->state = BRCMF_BUS_DOWN;
542 } else if (state == BRCMFMAC_USB_STATE_UP) {
543 brcmf_dbg(USB, "DBUS is up\n");
544 bcmf_bus->state = BRCMF_BUS_DATA;
582 } else { 545 } else {
583 brcmf_dbg(INFO, "DBUS current state=%d\n", state); 546 brcmf_dbg(USB, "DBUS current state=%d\n", state);
584 } 547 }
585} 548}
586 549
@@ -589,30 +552,32 @@ brcmf_usb_intr_complete(struct urb *urb)
589{ 552{
590 struct brcmf_usbdev_info *devinfo = 553 struct brcmf_usbdev_info *devinfo =
591 (struct brcmf_usbdev_info *)urb->context; 554 (struct brcmf_usbdev_info *)urb->context;
592 bool killed; 555 int err;
556
557 brcmf_dbg(USB, "Enter, urb->status=%d\n", urb->status);
593 558
594 if (devinfo == NULL) 559 if (devinfo == NULL)
595 return; 560 return;
596 561
597 if (unlikely(urb->status)) { 562 if (unlikely(urb->status)) {
598 if (devinfo->suspend_state == 563 if (urb->status == -ENOENT ||
599 USBOS_SUSPEND_STATE_SUSPEND_PENDING) 564 urb->status == -ESHUTDOWN ||
600 killed = true; 565 urb->status == -ENODEV) {
601 566 brcmf_usb_state_change(devinfo,
602 if ((urb->status == -ENOENT && (!killed)) 567 BRCMFMAC_USB_STATE_DOWN);
603 || urb->status == -ESHUTDOWN ||
604 urb->status == -ENODEV) {
605 brcmf_usb_state_change(devinfo, BCMFMAC_USB_STATE_DOWN);
606 } 568 }
607 } 569 }
608 570
609 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_DOWN) { 571 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_DOWN) {
610 brcmf_dbg(ERROR, "intr cb when DBUS down, ignoring\n"); 572 brcmf_err("intr cb when DBUS down, ignoring\n");
611 return; 573 return;
612 } 574 }
613 575
614 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_UP) 576 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP) {
615 usb_submit_urb(devinfo->intr_urb, GFP_ATOMIC); 577 err = usb_submit_urb(devinfo->intr_urb, GFP_ATOMIC);
578 if (err)
579 brcmf_err("usb_submit_urb, err=%d\n", err);
580 }
616} 581}
617 582
618static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb) 583static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb)
@@ -621,16 +586,15 @@ static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb)
621 struct brcmf_usbreq *req; 586 struct brcmf_usbreq *req;
622 int ret; 587 int ret;
623 588
624 if (devinfo->bus_pub.state != BCMFMAC_USB_STATE_UP) { 589 brcmf_dbg(USB, "Enter, skb=%p\n", skb);
625 /* TODO: handle suspend/resume */ 590 if (devinfo->bus_pub.state != BRCMFMAC_USB_STATE_UP)
626 return -EIO; 591 return -EIO;
627 }
628 592
629 req = brcmf_usb_deq(devinfo, &devinfo->tx_freeq, 593 req = brcmf_usb_deq(devinfo, &devinfo->tx_freeq,
630 &devinfo->tx_freecount); 594 &devinfo->tx_freecount);
631 if (!req) { 595 if (!req) {
632 brcmu_pkt_buf_free_skb(skb); 596 brcmu_pkt_buf_free_skb(skb);
633 brcmf_dbg(ERROR, "no req to send\n"); 597 brcmf_err("no req to send\n");
634 return -ENOMEM; 598 return -ENOMEM;
635 } 599 }
636 600
@@ -642,7 +606,7 @@ static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb)
642 brcmf_usb_enq(devinfo, &devinfo->tx_postq, req, NULL); 606 brcmf_usb_enq(devinfo, &devinfo->tx_postq, req, NULL);
643 ret = usb_submit_urb(req->urb, GFP_ATOMIC); 607 ret = usb_submit_urb(req->urb, GFP_ATOMIC);
644 if (ret) { 608 if (ret) {
645 brcmf_dbg(ERROR, "brcmf_usb_tx usb_submit_urb FAILED\n"); 609 brcmf_err("brcmf_usb_tx usb_submit_urb FAILED\n");
646 brcmf_usb_del_fromq(devinfo, req); 610 brcmf_usb_del_fromq(devinfo, req);
647 brcmu_pkt_buf_free_skb(req->skb); 611 brcmu_pkt_buf_free_skb(req->skb);
648 req->skb = NULL; 612 req->skb = NULL;
@@ -664,25 +628,16 @@ static int brcmf_usb_up(struct device *dev)
664{ 628{
665 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); 629 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
666 u16 ifnum; 630 u16 ifnum;
631 int ret;
667 632
668 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_UP) 633 brcmf_dbg(USB, "Enter\n");
634 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP)
669 return 0; 635 return 0;
670 636
671 /* If the USB/HSIC bus in sleep state, wake it up */
672 if (devinfo->suspend_state == USBOS_SUSPEND_STATE_SUSPENDED) {
673 if (brcmf_usb_pnp(devinfo, BCMFMAC_USB_PNP_RESUME) != 0) {
674 brcmf_dbg(ERROR, "Could not Resume the bus!\n");
675 return -EIO;
676 }
677 }
678 devinfo->activity = true;
679
680 /* Success, indicate devinfo is fully up */ 637 /* Success, indicate devinfo is fully up */
681 brcmf_usb_state_change(devinfo, BCMFMAC_USB_STATE_UP); 638 brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_UP);
682 639
683 if (devinfo->intr_urb) { 640 if (devinfo->intr_urb) {
684 int ret;
685
686 usb_fill_int_urb(devinfo->intr_urb, devinfo->usbdev, 641 usb_fill_int_urb(devinfo->intr_urb, devinfo->usbdev,
687 devinfo->intr_pipe, 642 devinfo->intr_pipe,
688 &devinfo->intr, 643 &devinfo->intr,
@@ -693,7 +648,7 @@ static int brcmf_usb_up(struct device *dev)
693 648
694 ret = usb_submit_urb(devinfo->intr_urb, GFP_ATOMIC); 649 ret = usb_submit_urb(devinfo->intr_urb, GFP_ATOMIC);
695 if (ret) { 650 if (ret) {
696 brcmf_dbg(ERROR, "USB_SUBMIT_URB failed with status %d\n", 651 brcmf_err("USB_SUBMIT_URB failed with status %d\n",
697 ret); 652 ret);
698 return -EINVAL; 653 return -EINVAL;
699 } 654 }
@@ -727,14 +682,14 @@ static void brcmf_usb_down(struct device *dev)
727{ 682{
728 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); 683 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
729 684
685 brcmf_dbg(USB, "Enter\n");
730 if (devinfo == NULL) 686 if (devinfo == NULL)
731 return; 687 return;
732 688
733 brcmf_dbg(TRACE, "enter\n"); 689 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_DOWN)
734 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_DOWN)
735 return; 690 return;
736 691
737 brcmf_usb_state_change(devinfo, BCMFMAC_USB_STATE_DOWN); 692 brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_DOWN);
738 if (devinfo->intr_urb) 693 if (devinfo->intr_urb)
739 usb_kill_urb(devinfo->intr_urb); 694 usb_kill_urb(devinfo->intr_urb);
740 695
@@ -790,7 +745,7 @@ static bool brcmf_usb_dl_cmd(struct brcmf_usbdev_info *devinfo, u8 cmd,
790 devinfo->ctl_completed = false; 745 devinfo->ctl_completed = false;
791 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC); 746 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC);
792 if (ret < 0) { 747 if (ret < 0) {
793 brcmf_dbg(ERROR, "usb_submit_urb failed %d\n", ret); 748 brcmf_err("usb_submit_urb failed %d\n", ret);
794 kfree(tmpbuf); 749 kfree(tmpbuf);
795 return false; 750 return false;
796 } 751 }
@@ -808,27 +763,25 @@ brcmf_usb_dlneeded(struct brcmf_usbdev_info *devinfo)
808 struct bootrom_id_le id; 763 struct bootrom_id_le id;
809 u32 chipid, chiprev; 764 u32 chipid, chiprev;
810 765
811 brcmf_dbg(TRACE, "enter\n"); 766 brcmf_dbg(USB, "Enter\n");
812 767
813 if (devinfo == NULL) 768 if (devinfo == NULL)
814 return false; 769 return false;
815 770
816 /* Check if firmware downloaded already by querying runtime ID */ 771 /* Check if firmware downloaded already by querying runtime ID */
817 id.chip = cpu_to_le32(0xDEAD); 772 id.chip = cpu_to_le32(0xDEAD);
818 brcmf_usb_dl_cmd(devinfo, DL_GETVER, &id, 773 brcmf_usb_dl_cmd(devinfo, DL_GETVER, &id, sizeof(id));
819 sizeof(struct bootrom_id_le));
820 774
821 chipid = le32_to_cpu(id.chip); 775 chipid = le32_to_cpu(id.chip);
822 chiprev = le32_to_cpu(id.chiprev); 776 chiprev = le32_to_cpu(id.chiprev);
823 777
824 if ((chipid & 0x4300) == 0x4300) 778 if ((chipid & 0x4300) == 0x4300)
825 brcmf_dbg(INFO, "chip %x rev 0x%x\n", chipid, chiprev); 779 brcmf_dbg(USB, "chip %x rev 0x%x\n", chipid, chiprev);
826 else 780 else
827 brcmf_dbg(INFO, "chip %d rev 0x%x\n", chipid, chiprev); 781 brcmf_dbg(USB, "chip %d rev 0x%x\n", chipid, chiprev);
828 if (chipid == BRCMF_POSTBOOT_ID) { 782 if (chipid == BRCMF_POSTBOOT_ID) {
829 brcmf_dbg(INFO, "firmware already downloaded\n"); 783 brcmf_dbg(USB, "firmware already downloaded\n");
830 brcmf_usb_dl_cmd(devinfo, DL_RESETCFG, &id, 784 brcmf_usb_dl_cmd(devinfo, DL_RESETCFG, &id, sizeof(id));
831 sizeof(struct bootrom_id_le));
832 return false; 785 return false;
833 } else { 786 } else {
834 devinfo->bus_pub.devid = chipid; 787 devinfo->bus_pub.devid = chipid;
@@ -841,38 +794,29 @@ static int
841brcmf_usb_resetcfg(struct brcmf_usbdev_info *devinfo) 794brcmf_usb_resetcfg(struct brcmf_usbdev_info *devinfo)
842{ 795{
843 struct bootrom_id_le id; 796 struct bootrom_id_le id;
844 u16 wait = 0, wait_time; 797 u32 loop_cnt;
845
846 brcmf_dbg(TRACE, "enter\n");
847 798
848 if (devinfo == NULL) 799 brcmf_dbg(USB, "Enter\n");
849 return -EINVAL;
850 800
851 /* Give dongle chance to boot */ 801 loop_cnt = 0;
852 wait_time = BRCMF_USB_DLIMAGE_SPINWAIT; 802 do {
853 while (wait < BRCMF_USB_DLIMAGE_LIMIT) { 803 mdelay(BRCMF_USB_RESET_GETVER_SPINWAIT);
854 mdelay(wait_time); 804 loop_cnt++;
855 wait += wait_time;
856 id.chip = cpu_to_le32(0xDEAD); /* Get the ID */ 805 id.chip = cpu_to_le32(0xDEAD); /* Get the ID */
857 brcmf_usb_dl_cmd(devinfo, DL_GETVER, &id, 806 brcmf_usb_dl_cmd(devinfo, DL_GETVER, &id, sizeof(id));
858 sizeof(struct bootrom_id_le));
859 if (id.chip == cpu_to_le32(BRCMF_POSTBOOT_ID)) 807 if (id.chip == cpu_to_le32(BRCMF_POSTBOOT_ID))
860 break; 808 break;
861 } 809 } while (loop_cnt < BRCMF_USB_RESET_GETVER_LOOP_CNT);
862 810
863 if (id.chip == cpu_to_le32(BRCMF_POSTBOOT_ID)) { 811 if (id.chip == cpu_to_le32(BRCMF_POSTBOOT_ID)) {
864 brcmf_dbg(INFO, "download done %d ms postboot chip 0x%x/rev 0x%x\n", 812 brcmf_dbg(USB, "postboot chip 0x%x/rev 0x%x\n",
865 wait, le32_to_cpu(id.chip), le32_to_cpu(id.chiprev)); 813 le32_to_cpu(id.chip), le32_to_cpu(id.chiprev));
866 814
867 brcmf_usb_dl_cmd(devinfo, DL_RESETCFG, &id, 815 brcmf_usb_dl_cmd(devinfo, DL_RESETCFG, &id, sizeof(id));
868 sizeof(struct bootrom_id_le));
869
870 /* XXX this wait may not be necessary */
871 mdelay(BRCMF_USB_RESETCFG_SPINWAIT);
872 return 0; 816 return 0;
873 } else { 817 } else {
874 brcmf_dbg(ERROR, "Cannot talk to Dongle. Firmware is not UP, %d ms\n", 818 brcmf_err("Cannot talk to Dongle. Firmware is not UP, %d ms\n",
875 wait); 819 BRCMF_USB_RESET_GETVER_SPINWAIT * loop_cnt);
876 return -EINVAL; 820 return -EINVAL;
877 } 821 }
878} 822}
@@ -896,7 +840,7 @@ brcmf_usb_dl_send_bulk(struct brcmf_usbdev_info *devinfo, void *buffer, int len)
896 devinfo->ctl_completed = false; 840 devinfo->ctl_completed = false;
897 ret = usb_submit_urb(devinfo->bulk_urb, GFP_ATOMIC); 841 ret = usb_submit_urb(devinfo->bulk_urb, GFP_ATOMIC);
898 if (ret) { 842 if (ret) {
899 brcmf_dbg(ERROR, "usb_submit_urb failed %d\n", ret); 843 brcmf_err("usb_submit_urb failed %d\n", ret);
900 return ret; 844 return ret;
901 } 845 }
902 ret = brcmf_usb_ioctl_resp_wait(devinfo); 846 ret = brcmf_usb_ioctl_resp_wait(devinfo);
@@ -911,7 +855,8 @@ brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
911 struct rdl_state_le state; 855 struct rdl_state_le state;
912 u32 rdlstate, rdlbytes; 856 u32 rdlstate, rdlbytes;
913 int err = 0; 857 int err = 0;
914 brcmf_dbg(TRACE, "fw %p, len %d\n", fw, fwlen); 858
859 brcmf_dbg(USB, "Enter, fw %p, len %d\n", fw, fwlen);
915 860
916 bulkchunk = kmalloc(RDL_CHUNK, GFP_ATOMIC); 861 bulkchunk = kmalloc(RDL_CHUNK, GFP_ATOMIC);
917 if (bulkchunk == NULL) { 862 if (bulkchunk == NULL) {
@@ -928,7 +873,7 @@ brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
928 873
929 /* 2) Check we are in the Waiting state */ 874 /* 2) Check we are in the Waiting state */
930 if (rdlstate != DL_WAITING) { 875 if (rdlstate != DL_WAITING) {
931 brcmf_dbg(ERROR, "Failed to DL_START\n"); 876 brcmf_err("Failed to DL_START\n");
932 err = -EINVAL; 877 err = -EINVAL;
933 goto fail; 878 goto fail;
934 } 879 }
@@ -957,7 +902,7 @@ brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
957 memcpy(bulkchunk, dlpos, sendlen); 902 memcpy(bulkchunk, dlpos, sendlen);
958 if (brcmf_usb_dl_send_bulk(devinfo, bulkchunk, 903 if (brcmf_usb_dl_send_bulk(devinfo, bulkchunk,
959 sendlen)) { 904 sendlen)) {
960 brcmf_dbg(ERROR, "send_bulk failed\n"); 905 brcmf_err("send_bulk failed\n");
961 err = -EINVAL; 906 err = -EINVAL;
962 goto fail; 907 goto fail;
963 } 908 }
@@ -967,7 +912,7 @@ brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
967 } 912 }
968 if (!brcmf_usb_dl_cmd(devinfo, DL_GETSTATE, &state, 913 if (!brcmf_usb_dl_cmd(devinfo, DL_GETSTATE, &state,
969 sizeof(struct rdl_state_le))) { 914 sizeof(struct rdl_state_le))) {
970 brcmf_dbg(ERROR, "DL_GETSTATE Failed xxxx\n"); 915 brcmf_err("DL_GETSTATE Failed xxxx\n");
971 err = -EINVAL; 916 err = -EINVAL;
972 goto fail; 917 goto fail;
973 } 918 }
@@ -977,7 +922,7 @@ brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
977 922
978 /* restart if an error is reported */ 923 /* restart if an error is reported */
979 if (rdlstate == DL_BAD_HDR || rdlstate == DL_BAD_CRC) { 924 if (rdlstate == DL_BAD_HDR || rdlstate == DL_BAD_CRC) {
980 brcmf_dbg(ERROR, "Bad Hdr or Bad CRC state %d\n", 925 brcmf_err("Bad Hdr or Bad CRC state %d\n",
981 rdlstate); 926 rdlstate);
982 err = -EINVAL; 927 err = -EINVAL;
983 goto fail; 928 goto fail;
@@ -986,7 +931,7 @@ brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
986 931
987fail: 932fail:
988 kfree(bulkchunk); 933 kfree(bulkchunk);
989 brcmf_dbg(TRACE, "err=%d\n", err); 934 brcmf_dbg(USB, "Exit, err=%d\n", err);
990 return err; 935 return err;
991} 936}
992 937
@@ -994,7 +939,7 @@ static int brcmf_usb_dlstart(struct brcmf_usbdev_info *devinfo, u8 *fw, int len)
994{ 939{
995 int err; 940 int err;
996 941
997 brcmf_dbg(TRACE, "enter\n"); 942 brcmf_dbg(USB, "Enter\n");
998 943
999 if (devinfo == NULL) 944 if (devinfo == NULL)
1000 return -EINVAL; 945 return -EINVAL;
@@ -1004,10 +949,10 @@ static int brcmf_usb_dlstart(struct brcmf_usbdev_info *devinfo, u8 *fw, int len)
1004 949
1005 err = brcmf_usb_dl_writeimage(devinfo, fw, len); 950 err = brcmf_usb_dl_writeimage(devinfo, fw, len);
1006 if (err == 0) 951 if (err == 0)
1007 devinfo->bus_pub.state = BCMFMAC_USB_STATE_DL_DONE; 952 devinfo->bus_pub.state = BRCMFMAC_USB_STATE_DL_DONE;
1008 else 953 else
1009 devinfo->bus_pub.state = BCMFMAC_USB_STATE_DL_PENDING; 954 devinfo->bus_pub.state = BRCMFMAC_USB_STATE_DL_FAIL;
1010 brcmf_dbg(TRACE, "exit: err=%d\n", err); 955 brcmf_dbg(USB, "Exit, err=%d\n", err);
1011 956
1012 return err; 957 return err;
1013} 958}
@@ -1016,7 +961,7 @@ static int brcmf_usb_dlrun(struct brcmf_usbdev_info *devinfo)
1016{ 961{
1017 struct rdl_state_le state; 962 struct rdl_state_le state;
1018 963
1019 brcmf_dbg(TRACE, "enter\n"); 964 brcmf_dbg(USB, "Enter\n");
1020 if (!devinfo) 965 if (!devinfo)
1021 return -EINVAL; 966 return -EINVAL;
1022 967
@@ -1036,10 +981,10 @@ static int brcmf_usb_dlrun(struct brcmf_usbdev_info *devinfo)
1036 return -ENODEV; 981 return -ENODEV;
1037 /* The Dongle may go for re-enumeration. */ 982 /* The Dongle may go for re-enumeration. */
1038 } else { 983 } else {
1039 brcmf_dbg(ERROR, "Dongle not runnable\n"); 984 brcmf_err("Dongle not runnable\n");
1040 return -EINVAL; 985 return -EINVAL;
1041 } 986 }
1042 brcmf_dbg(TRACE, "exit\n"); 987 brcmf_dbg(USB, "Exit\n");
1043 return 0; 988 return 0;
1044} 989}
1045 990
@@ -1066,7 +1011,7 @@ brcmf_usb_fw_download(struct brcmf_usbdev_info *devinfo)
1066 int devid, chiprev; 1011 int devid, chiprev;
1067 int err; 1012 int err;
1068 1013
1069 brcmf_dbg(TRACE, "enter\n"); 1014 brcmf_dbg(USB, "Enter\n");
1070 if (devinfo == NULL) 1015 if (devinfo == NULL)
1071 return -ENODEV; 1016 return -ENODEV;
1072 1017
@@ -1074,13 +1019,13 @@ brcmf_usb_fw_download(struct brcmf_usbdev_info *devinfo)
1074 chiprev = devinfo->bus_pub.chiprev; 1019 chiprev = devinfo->bus_pub.chiprev;
1075 1020
1076 if (!brcmf_usb_chip_support(devid, chiprev)) { 1021 if (!brcmf_usb_chip_support(devid, chiprev)) {
1077 brcmf_dbg(ERROR, "unsupported chip %d rev %d\n", 1022 brcmf_err("unsupported chip %d rev %d\n",
1078 devid, chiprev); 1023 devid, chiprev);
1079 return -EINVAL; 1024 return -EINVAL;
1080 } 1025 }
1081 1026
1082 if (!devinfo->image) { 1027 if (!devinfo->image) {
1083 brcmf_dbg(ERROR, "No firmware!\n"); 1028 brcmf_err("No firmware!\n");
1084 return -ENOENT; 1029 return -ENOENT;
1085 } 1030 }
1086 1031
@@ -1094,7 +1039,7 @@ brcmf_usb_fw_download(struct brcmf_usbdev_info *devinfo)
1094 1039
1095static void brcmf_usb_detach(struct brcmf_usbdev_info *devinfo) 1040static void brcmf_usb_detach(struct brcmf_usbdev_info *devinfo)
1096{ 1041{
1097 brcmf_dbg(TRACE, "devinfo %p\n", devinfo); 1042 brcmf_dbg(USB, "Enter, devinfo %p\n", devinfo);
1098 1043
1099 /* free the URBS */ 1044 /* free the URBS */
1100 brcmf_usb_free_q(&devinfo->rx_freeq, false); 1045 brcmf_usb_free_q(&devinfo->rx_freeq, false);
@@ -1129,6 +1074,7 @@ static int check_file(const u8 *headers)
1129 struct trx_header_le *trx; 1074 struct trx_header_le *trx;
1130 int actual_len = -1; 1075 int actual_len = -1;
1131 1076
1077 brcmf_dbg(USB, "Enter\n");
1132 /* Extract trx header */ 1078 /* Extract trx header */
1133 trx = (struct trx_header_le *) headers; 1079 trx = (struct trx_header_le *) headers;
1134 if (trx->magic != cpu_to_le32(TRX_MAGIC)) 1080 if (trx->magic != cpu_to_le32(TRX_MAGIC))
@@ -1150,6 +1096,7 @@ static int brcmf_usb_get_fw(struct brcmf_usbdev_info *devinfo)
1150 struct brcmf_usb_image *fw_image; 1096 struct brcmf_usb_image *fw_image;
1151 int err; 1097 int err;
1152 1098
1099 brcmf_dbg(USB, "Enter\n");
1153 switch (devinfo->bus_pub.devid) { 1100 switch (devinfo->bus_pub.devid) {
1154 case 43143: 1101 case 43143:
1155 fwname = BRCMF_USB_43143_FW_NAME; 1102 fwname = BRCMF_USB_43143_FW_NAME;
@@ -1166,7 +1113,7 @@ static int brcmf_usb_get_fw(struct brcmf_usbdev_info *devinfo)
1166 return -EINVAL; 1113 return -EINVAL;
1167 break; 1114 break;
1168 } 1115 }
1169 1116 brcmf_dbg(USB, "Loading FW %s\n", fwname);
1170 list_for_each_entry(fw_image, &fw_image_list, list) { 1117 list_for_each_entry(fw_image, &fw_image_list, list) {
1171 if (fw_image->fwname == fwname) { 1118 if (fw_image->fwname == fwname) {
1172 devinfo->image = fw_image->image; 1119 devinfo->image = fw_image->image;
@@ -1177,11 +1124,11 @@ static int brcmf_usb_get_fw(struct brcmf_usbdev_info *devinfo)
1177 /* fw image not yet loaded. Load it now and add to list */ 1124 /* fw image not yet loaded. Load it now and add to list */
1178 err = request_firmware(&fw, fwname, devinfo->dev); 1125 err = request_firmware(&fw, fwname, devinfo->dev);
1179 if (!fw) { 1126 if (!fw) {
1180 brcmf_dbg(ERROR, "fail to request firmware %s\n", fwname); 1127 brcmf_err("fail to request firmware %s\n", fwname);
1181 return err; 1128 return err;
1182 } 1129 }
1183 if (check_file(fw->data) < 0) { 1130 if (check_file(fw->data) < 0) {
1184 brcmf_dbg(ERROR, "invalid firmware %s\n", fwname); 1131 brcmf_err("invalid firmware %s\n", fwname);
1185 return -EINVAL; 1132 return -EINVAL;
1186 } 1133 }
1187 1134
@@ -1211,10 +1158,13 @@ static
1211struct brcmf_usbdev *brcmf_usb_attach(struct brcmf_usbdev_info *devinfo, 1158struct brcmf_usbdev *brcmf_usb_attach(struct brcmf_usbdev_info *devinfo,
1212 int nrxq, int ntxq) 1159 int nrxq, int ntxq)
1213{ 1160{
1161 brcmf_dbg(USB, "Enter\n");
1162
1214 devinfo->bus_pub.nrxq = nrxq; 1163 devinfo->bus_pub.nrxq = nrxq;
1215 devinfo->rx_low_watermark = nrxq / 2; 1164 devinfo->rx_low_watermark = nrxq / 2;
1216 devinfo->bus_pub.devinfo = devinfo; 1165 devinfo->bus_pub.devinfo = devinfo;
1217 devinfo->bus_pub.ntxq = ntxq; 1166 devinfo->bus_pub.ntxq = ntxq;
1167 devinfo->bus_pub.state = BRCMFMAC_USB_STATE_DOWN;
1218 1168
1219 /* flow control when too many tx urbs posted */ 1169 /* flow control when too many tx urbs posted */
1220 devinfo->tx_low_watermark = ntxq / 4; 1170 devinfo->tx_low_watermark = ntxq / 4;
@@ -1246,24 +1196,24 @@ struct brcmf_usbdev *brcmf_usb_attach(struct brcmf_usbdev_info *devinfo,
1246 1196
1247 devinfo->intr_urb = usb_alloc_urb(0, GFP_ATOMIC); 1197 devinfo->intr_urb = usb_alloc_urb(0, GFP_ATOMIC);
1248 if (!devinfo->intr_urb) { 1198 if (!devinfo->intr_urb) {
1249 brcmf_dbg(ERROR, "usb_alloc_urb (intr) failed\n"); 1199 brcmf_err("usb_alloc_urb (intr) failed\n");
1250 goto error; 1200 goto error;
1251 } 1201 }
1252 devinfo->ctl_urb = usb_alloc_urb(0, GFP_ATOMIC); 1202 devinfo->ctl_urb = usb_alloc_urb(0, GFP_ATOMIC);
1253 if (!devinfo->ctl_urb) { 1203 if (!devinfo->ctl_urb) {
1254 brcmf_dbg(ERROR, "usb_alloc_urb (ctl) failed\n"); 1204 brcmf_err("usb_alloc_urb (ctl) failed\n");
1255 goto error; 1205 goto error;
1256 } 1206 }
1257 devinfo->bulk_urb = usb_alloc_urb(0, GFP_ATOMIC); 1207 devinfo->bulk_urb = usb_alloc_urb(0, GFP_ATOMIC);
1258 if (!devinfo->bulk_urb) { 1208 if (!devinfo->bulk_urb) {
1259 brcmf_dbg(ERROR, "usb_alloc_urb (bulk) failed\n"); 1209 brcmf_err("usb_alloc_urb (bulk) failed\n");
1260 goto error; 1210 goto error;
1261 } 1211 }
1262 1212
1263 if (!brcmf_usb_dlneeded(devinfo)) 1213 if (!brcmf_usb_dlneeded(devinfo))
1264 return &devinfo->bus_pub; 1214 return &devinfo->bus_pub;
1265 1215
1266 brcmf_dbg(TRACE, "start fw downloading\n"); 1216 brcmf_dbg(USB, "Start fw downloading\n");
1267 if (brcmf_usb_get_fw(devinfo)) 1217 if (brcmf_usb_get_fw(devinfo))
1268 goto error; 1218 goto error;
1269 1219
@@ -1273,19 +1223,27 @@ struct brcmf_usbdev *brcmf_usb_attach(struct brcmf_usbdev_info *devinfo,
1273 return &devinfo->bus_pub; 1223 return &devinfo->bus_pub;
1274 1224
1275error: 1225error:
1276 brcmf_dbg(ERROR, "failed!\n"); 1226 brcmf_err("failed!\n");
1277 brcmf_usb_detach(devinfo); 1227 brcmf_usb_detach(devinfo);
1278 return NULL; 1228 return NULL;
1279} 1229}
1280 1230
1281static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo, 1231static struct brcmf_bus_ops brcmf_usb_bus_ops = {
1282 const char *desc, u32 bustype, u32 hdrlen) 1232 .txdata = brcmf_usb_tx,
1233 .init = brcmf_usb_up,
1234 .stop = brcmf_usb_down,
1235 .txctl = brcmf_usb_tx_ctlpkt,
1236 .rxctl = brcmf_usb_rx_ctlpkt,
1237};
1238
1239static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo)
1283{ 1240{
1284 struct brcmf_bus *bus = NULL; 1241 struct brcmf_bus *bus = NULL;
1285 struct brcmf_usbdev *bus_pub = NULL; 1242 struct brcmf_usbdev *bus_pub = NULL;
1286 int ret; 1243 int ret;
1287 struct device *dev = devinfo->dev; 1244 struct device *dev = devinfo->dev;
1288 1245
1246 brcmf_dbg(USB, "Enter\n");
1289 bus_pub = brcmf_usb_attach(devinfo, BRCMF_USB_NRXQ, BRCMF_USB_NTXQ); 1247 bus_pub = brcmf_usb_attach(devinfo, BRCMF_USB_NRXQ, BRCMF_USB_NTXQ);
1290 if (!bus_pub) 1248 if (!bus_pub)
1291 return -ENODEV; 1249 return -ENODEV;
@@ -1296,26 +1254,22 @@ static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo,
1296 goto fail; 1254 goto fail;
1297 } 1255 }
1298 1256
1257 bus->dev = dev;
1299 bus_pub->bus = bus; 1258 bus_pub->bus = bus;
1300 bus->brcmf_bus_txdata = brcmf_usb_tx;
1301 bus->brcmf_bus_init = brcmf_usb_up;
1302 bus->brcmf_bus_stop = brcmf_usb_down;
1303 bus->brcmf_bus_txctl = brcmf_usb_tx_ctlpkt;
1304 bus->brcmf_bus_rxctl = brcmf_usb_rx_ctlpkt;
1305 bus->type = bustype;
1306 bus->bus_priv.usb = bus_pub; 1259 bus->bus_priv.usb = bus_pub;
1307 dev_set_drvdata(dev, bus); 1260 dev_set_drvdata(dev, bus);
1261 bus->ops = &brcmf_usb_bus_ops;
1308 1262
1309 /* Attach to the common driver interface */ 1263 /* Attach to the common driver interface */
1310 ret = brcmf_attach(hdrlen, dev); 1264 ret = brcmf_attach(0, dev);
1311 if (ret) { 1265 if (ret) {
1312 brcmf_dbg(ERROR, "dhd_attach failed\n"); 1266 brcmf_err("brcmf_attach failed\n");
1313 goto fail; 1267 goto fail;
1314 } 1268 }
1315 1269
1316 ret = brcmf_bus_start(dev); 1270 ret = brcmf_bus_start(dev);
1317 if (ret) { 1271 if (ret) {
1318 brcmf_dbg(ERROR, "dongle is not responding\n"); 1272 brcmf_err("dongle is not responding\n");
1319 brcmf_detach(dev); 1273 brcmf_detach(dev);
1320 goto fail; 1274 goto fail;
1321 } 1275 }
@@ -1333,7 +1287,7 @@ brcmf_usb_disconnect_cb(struct brcmf_usbdev_info *devinfo)
1333{ 1287{
1334 if (!devinfo) 1288 if (!devinfo)
1335 return; 1289 return;
1336 brcmf_dbg(TRACE, "enter: bus_pub %p\n", devinfo); 1290 brcmf_dbg(USB, "Enter, bus_pub %p\n", devinfo);
1337 1291
1338 brcmf_detach(devinfo->dev); 1292 brcmf_detach(devinfo->dev);
1339 kfree(devinfo->bus_pub.bus); 1293 kfree(devinfo->bus_pub.bus);
@@ -1351,7 +1305,7 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1351 u8 endpoint_num; 1305 u8 endpoint_num;
1352 struct brcmf_usbdev_info *devinfo; 1306 struct brcmf_usbdev_info *devinfo;
1353 1307
1354 brcmf_dbg(TRACE, "enter\n"); 1308 brcmf_dbg(USB, "Enter\n");
1355 1309
1356 devinfo = kzalloc(sizeof(*devinfo), GFP_ATOMIC); 1310 devinfo = kzalloc(sizeof(*devinfo), GFP_ATOMIC);
1357 if (devinfo == NULL) 1311 if (devinfo == NULL)
@@ -1390,7 +1344,7 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1390 if (IFDESC(usb, CONTROL_IF).bInterfaceClass != USB_CLASS_VENDOR_SPEC || 1344 if (IFDESC(usb, CONTROL_IF).bInterfaceClass != USB_CLASS_VENDOR_SPEC ||
1391 IFDESC(usb, CONTROL_IF).bInterfaceSubClass != 2 || 1345 IFDESC(usb, CONTROL_IF).bInterfaceSubClass != 2 ||
1392 IFDESC(usb, CONTROL_IF).bInterfaceProtocol != 0xff) { 1346 IFDESC(usb, CONTROL_IF).bInterfaceProtocol != 0xff) {
1393 brcmf_dbg(ERROR, "invalid control interface: class %d, subclass %d, proto %d\n", 1347 brcmf_err("invalid control interface: class %d, subclass %d, proto %d\n",
1394 IFDESC(usb, CONTROL_IF).bInterfaceClass, 1348 IFDESC(usb, CONTROL_IF).bInterfaceClass,
1395 IFDESC(usb, CONTROL_IF).bInterfaceSubClass, 1349 IFDESC(usb, CONTROL_IF).bInterfaceSubClass,
1396 IFDESC(usb, CONTROL_IF).bInterfaceProtocol); 1350 IFDESC(usb, CONTROL_IF).bInterfaceProtocol);
@@ -1402,7 +1356,7 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1402 endpoint = &IFEPDESC(usb, CONTROL_IF, 0); 1356 endpoint = &IFEPDESC(usb, CONTROL_IF, 0);
1403 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 1357 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
1404 != USB_ENDPOINT_XFER_INT) { 1358 != USB_ENDPOINT_XFER_INT) {
1405 brcmf_dbg(ERROR, "invalid control endpoint %d\n", 1359 brcmf_err("invalid control endpoint %d\n",
1406 endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); 1360 endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
1407 ret = -1; 1361 ret = -1;
1408 goto fail; 1362 goto fail;
@@ -1421,7 +1375,7 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1421 endpoint = &IFEPDESC(usb, BULK_IF, ep); 1375 endpoint = &IFEPDESC(usb, BULK_IF, ep);
1422 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 1376 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
1423 USB_ENDPOINT_XFER_BULK) { 1377 USB_ENDPOINT_XFER_BULK) {
1424 brcmf_dbg(ERROR, "invalid data endpoint %d\n", ep); 1378 brcmf_err("invalid data endpoint %d\n", ep);
1425 ret = -1; 1379 ret = -1;
1426 goto fail; 1380 goto fail;
1427 } 1381 }
@@ -1452,11 +1406,11 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1452 devinfo->interval = IFEPDESC(usb, CONTROL_IF, 0).bInterval; 1406 devinfo->interval = IFEPDESC(usb, CONTROL_IF, 0).bInterval;
1453 1407
1454 if (usb->speed == USB_SPEED_HIGH) 1408 if (usb->speed == USB_SPEED_HIGH)
1455 brcmf_dbg(INFO, "Broadcom high speed USB wireless device detected\n"); 1409 brcmf_dbg(USB, "Broadcom high speed USB wireless device detected\n");
1456 else 1410 else
1457 brcmf_dbg(INFO, "Broadcom full speed USB wireless device detected\n"); 1411 brcmf_dbg(USB, "Broadcom full speed USB wireless device detected\n");
1458 1412
1459 ret = brcmf_usb_probe_cb(devinfo, "", USB_BUS, 0); 1413 ret = brcmf_usb_probe_cb(devinfo);
1460 if (ret) 1414 if (ret)
1461 goto fail; 1415 goto fail;
1462 1416
@@ -1464,7 +1418,7 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1464 return 0; 1418 return 0;
1465 1419
1466fail: 1420fail:
1467 brcmf_dbg(ERROR, "failed with errno %d\n", ret); 1421 brcmf_err("failed with errno %d\n", ret);
1468 kfree(devinfo); 1422 kfree(devinfo);
1469 usb_set_intfdata(intf, NULL); 1423 usb_set_intfdata(intf, NULL);
1470 return ret; 1424 return ret;
@@ -1476,40 +1430,55 @@ brcmf_usb_disconnect(struct usb_interface *intf)
1476{ 1430{
1477 struct brcmf_usbdev_info *devinfo; 1431 struct brcmf_usbdev_info *devinfo;
1478 1432
1479 brcmf_dbg(TRACE, "enter\n"); 1433 brcmf_dbg(USB, "Enter\n");
1480 devinfo = (struct brcmf_usbdev_info *)usb_get_intfdata(intf); 1434 devinfo = (struct brcmf_usbdev_info *)usb_get_intfdata(intf);
1481 brcmf_usb_disconnect_cb(devinfo); 1435 brcmf_usb_disconnect_cb(devinfo);
1482 kfree(devinfo); 1436 kfree(devinfo);
1437 brcmf_dbg(USB, "Exit\n");
1483} 1438}
1484 1439
1485/* 1440/*
1486 * only need to signal the bus being down and update the suspend state. 1441 * only need to signal the bus being down and update the state.
1487 */ 1442 */
1488static int brcmf_usb_suspend(struct usb_interface *intf, pm_message_t state) 1443static int brcmf_usb_suspend(struct usb_interface *intf, pm_message_t state)
1489{ 1444{
1490 struct usb_device *usb = interface_to_usbdev(intf); 1445 struct usb_device *usb = interface_to_usbdev(intf);
1491 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev); 1446 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
1492 1447
1493 brcmf_dbg(TRACE, "enter\n"); 1448 brcmf_dbg(USB, "Enter\n");
1494 devinfo->bus_pub.state = BCMFMAC_USB_STATE_DOWN; 1449 devinfo->bus_pub.state = BRCMFMAC_USB_STATE_SLEEP;
1495 devinfo->suspend_state = USBOS_SUSPEND_STATE_SUSPENDED; 1450 brcmf_detach(&usb->dev);
1496 return 0; 1451 return 0;
1497} 1452}
1498 1453
1499/* 1454/*
1500 * mark suspend state active and crank up the bus. 1455 * (re-) start the bus.
1501 */ 1456 */
1502static int brcmf_usb_resume(struct usb_interface *intf) 1457static int brcmf_usb_resume(struct usb_interface *intf)
1503{ 1458{
1504 struct usb_device *usb = interface_to_usbdev(intf); 1459 struct usb_device *usb = interface_to_usbdev(intf);
1505 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev); 1460 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
1506 1461
1507 brcmf_dbg(TRACE, "enter\n"); 1462 brcmf_dbg(USB, "Enter\n");
1508 devinfo->suspend_state = USBOS_SUSPEND_STATE_DEVICE_ACTIVE; 1463 if (!brcmf_attach(0, devinfo->dev))
1509 brcmf_bus_start(&usb->dev); 1464 return brcmf_bus_start(&usb->dev);
1465
1510 return 0; 1466 return 0;
1511} 1467}
1512 1468
1469static int brcmf_usb_reset_resume(struct usb_interface *intf)
1470{
1471 struct usb_device *usb = interface_to_usbdev(intf);
1472 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
1473
1474 brcmf_dbg(USB, "Enter\n");
1475
1476 if (!brcmf_usb_fw_download(devinfo))
1477 return brcmf_usb_resume(intf);
1478
1479 return -EIO;
1480}
1481
1513#define BRCMF_USB_VENDOR_ID_BROADCOM 0x0a5c 1482#define BRCMF_USB_VENDOR_ID_BROADCOM 0x0a5c
1514#define BRCMF_USB_DEVICE_ID_43143 0xbd1e 1483#define BRCMF_USB_DEVICE_ID_43143 0xbd1e
1515#define BRCMF_USB_DEVICE_ID_43236 0xbd17 1484#define BRCMF_USB_DEVICE_ID_43236 0xbd17
@@ -1529,7 +1498,6 @@ MODULE_FIRMWARE(BRCMF_USB_43143_FW_NAME);
1529MODULE_FIRMWARE(BRCMF_USB_43236_FW_NAME); 1498MODULE_FIRMWARE(BRCMF_USB_43236_FW_NAME);
1530MODULE_FIRMWARE(BRCMF_USB_43242_FW_NAME); 1499MODULE_FIRMWARE(BRCMF_USB_43242_FW_NAME);
1531 1500
1532/* TODO: suspend and resume entries */
1533static struct usb_driver brcmf_usbdrvr = { 1501static struct usb_driver brcmf_usbdrvr = {
1534 .name = KBUILD_MODNAME, 1502 .name = KBUILD_MODNAME,
1535 .probe = brcmf_usb_probe, 1503 .probe = brcmf_usb_probe,
@@ -1537,6 +1505,7 @@ static struct usb_driver brcmf_usbdrvr = {
1537 .id_table = brcmf_usb_devid_table, 1505 .id_table = brcmf_usb_devid_table,
1538 .suspend = brcmf_usb_suspend, 1506 .suspend = brcmf_usb_suspend,
1539 .resume = brcmf_usb_resume, 1507 .resume = brcmf_usb_resume,
1508 .reset_resume = brcmf_usb_reset_resume,
1540 .supports_autosuspend = 1, 1509 .supports_autosuspend = 1,
1541 .disable_hub_initiated_lpm = 1, 1510 .disable_hub_initiated_lpm = 1,
1542}; 1511};
@@ -1554,12 +1523,14 @@ static void brcmf_release_fw(struct list_head *q)
1554 1523
1555void brcmf_usb_exit(void) 1524void brcmf_usb_exit(void)
1556{ 1525{
1526 brcmf_dbg(USB, "Enter\n");
1557 usb_deregister(&brcmf_usbdrvr); 1527 usb_deregister(&brcmf_usbdrvr);
1558 brcmf_release_fw(&fw_image_list); 1528 brcmf_release_fw(&fw_image_list);
1559} 1529}
1560 1530
1561void brcmf_usb_init(void) 1531void brcmf_usb_init(void)
1562{ 1532{
1533 brcmf_dbg(USB, "Enter\n");
1563 INIT_LIST_HEAD(&fw_image_list); 1534 INIT_LIST_HEAD(&fw_image_list);
1564 usb_register(&brcmf_usbdrvr); 1535 usb_register(&brcmf_usbdrvr);
1565} 1536}