2 * Copyright (c) 2011 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #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>
28 #include <linux/uaccess.h>
29 #include <linux/firmware.h>
30 #include <linux/usb.h>
31 #include <linux/vmalloc.h>
32 #include <net/cfg80211.h>
35 #include <brcmu_utils.h>
36 #include <brcmu_wifi.h>
43 #define IOCTL_RESP_TIMEOUT 2000
45 #define BRCMF_USB_DLIMAGE_SPINWAIT 100 /* in unit of ms */
46 #define BRCMF_USB_DLIMAGE_LIMIT 500 /* spinwait limit (ms) */
48 #define BRCMF_POSTBOOT_ID 0xA123 /* ID to detect if dongle
50 #define BRCMF_USB_RESETCFG_SPINWAIT 1 /* wait after resetcfg (ms) */
52 #define BRCMF_USB_NRXQ 50
53 #define BRCMF_USB_NTXQ 50
55 #define CONFIGDESC(usb) (&((usb)->actconfig)->desc)
56 #define IFPTR(usb, idx) ((usb)->actconfig->interface[(idx)])
57 #define IFALTS(usb, idx) (IFPTR((usb), (idx))->altsetting[0])
58 #define IFDESC(usb, idx) IFALTS((usb), (idx)).desc
59 #define IFEPDESC(usb, idx, ep) (IFALTS((usb), (idx)).endpoint[(ep)]).desc
64 #define BRCMF_USB_CBCTL_WRITE 0
65 #define BRCMF_USB_CBCTL_READ 1
66 #define BRCMF_USB_MAX_PKT_SIZE 1600
68 #define BRCMF_USB_43143_FW_NAME "brcm/brcmfmac43143.bin"
69 #define BRCMF_USB_43236_FW_NAME "brcm/brcmfmac43236b.bin"
70 #define BRCMF_USB_43242_FW_NAME "brcm/brcmfmac43242a.bin"
72 enum usbdev_suspend_state
{
73 USBOS_SUSPEND_STATE_DEVICE_ACTIVE
= 0, /* Device is busy, won't allow
75 USBOS_SUSPEND_STATE_SUSPEND_PENDING
, /* Device is idle, can be
76 * suspended. Wating PM to
79 USBOS_SUSPEND_STATE_SUSPENDED
/* Device suspended */
82 struct brcmf_usb_image
{
83 struct list_head list
;
88 static struct list_head fw_image_list
;
90 struct intr_transfer_buf
{
95 struct brcmf_usbdev_info
{
96 struct brcmf_usbdev bus_pub
; /* MUST BE FIRST */
98 struct list_head rx_freeq
;
99 struct list_head rx_postq
;
100 struct list_head tx_freeq
;
101 struct list_head tx_postq
;
102 enum usbdev_suspend_state suspend_state
;
103 uint rx_pipe
, tx_pipe
, intr_pipe
, rx_pipe2
;
106 int rx_low_watermark
;
107 int tx_low_watermark
;
108 int tx_high_watermark
;
112 struct brcmf_usbreq
*tx_reqs
;
113 struct brcmf_usbreq
*rx_reqs
;
115 u8
*image
; /* buffer for combine fw and nvram */
118 struct usb_device
*usbdev
;
121 int ctl_in_pipe
, ctl_out_pipe
;
122 struct urb
*ctl_urb
; /* URB for control endpoint */
123 struct usb_ctrlrequest ctl_write
;
124 struct usb_ctrlrequest ctl_read
;
125 u32 ctl_urb_actual_length
;
128 wait_queue_head_t ioctl_resp_wait
;
131 struct urb
*bulk_urb
; /* used for FW download */
132 struct urb
*intr_urb
; /* URB for interrupt endpoint */
133 int intr_size
; /* Size of interrupt message */
134 int interval
; /* Interrupt polling interval */
135 struct intr_transfer_buf intr
; /* Data buffer for interrupt endpoint */
138 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
139 struct brcmf_usbreq
*req
);
141 MODULE_AUTHOR("Broadcom Corporation");
142 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac usb driver.");
143 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac usb cards");
144 MODULE_LICENSE("Dual BSD/GPL");
146 static struct brcmf_usbdev
*brcmf_usb_get_buspub(struct device
*dev
)
148 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
149 return bus_if
->bus_priv
.usb
;
152 static struct brcmf_usbdev_info
*brcmf_usb_get_businfo(struct device
*dev
)
154 return brcmf_usb_get_buspub(dev
)->devinfo
;
157 static int brcmf_usb_ioctl_resp_wait(struct brcmf_usbdev_info
*devinfo
)
159 return wait_event_timeout(devinfo
->ioctl_resp_wait
,
160 devinfo
->ctl_completed
,
161 msecs_to_jiffies(IOCTL_RESP_TIMEOUT
));
164 static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info
*devinfo
)
166 if (waitqueue_active(&devinfo
->ioctl_resp_wait
))
167 wake_up(&devinfo
->ioctl_resp_wait
);
171 brcmf_usb_ctl_complete(struct brcmf_usbdev_info
*devinfo
, int type
, int status
)
174 if (unlikely(devinfo
== NULL
))
177 if (type
== BRCMF_USB_CBCTL_READ
) {
179 devinfo
->bus_pub
.stats
.rx_ctlpkts
++;
181 devinfo
->bus_pub
.stats
.rx_ctlerrs
++;
182 } else if (type
== BRCMF_USB_CBCTL_WRITE
) {
184 devinfo
->bus_pub
.stats
.tx_ctlpkts
++;
186 devinfo
->bus_pub
.stats
.tx_ctlerrs
++;
189 devinfo
->ctl_urb_status
= status
;
190 devinfo
->ctl_completed
= true;
191 brcmf_usb_ioctl_resp_wake(devinfo
);
195 brcmf_usb_ctlread_complete(struct urb
*urb
)
197 struct brcmf_usbdev_info
*devinfo
=
198 (struct brcmf_usbdev_info
*)urb
->context
;
200 devinfo
->ctl_urb_actual_length
= urb
->actual_length
;
201 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_READ
,
206 brcmf_usb_ctlwrite_complete(struct urb
*urb
)
208 struct brcmf_usbdev_info
*devinfo
=
209 (struct brcmf_usbdev_info
*)urb
->context
;
211 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_WRITE
,
215 static int brcmf_usb_pnp(struct brcmf_usbdev_info
*devinfo
, uint state
)
221 brcmf_usb_send_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
226 if (devinfo
== NULL
|| buf
== NULL
||
227 len
== 0 || devinfo
->ctl_urb
== NULL
)
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");
237 devinfo
->activity
= true;
239 devinfo
->ctl_write
.wLength
= cpu_to_le16p(&size
);
240 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
241 devinfo
->ctl_urb_status
= 0;
242 devinfo
->ctl_urb_actual_length
= 0;
244 usb_fill_control_urb(devinfo
->ctl_urb
,
246 devinfo
->ctl_out_pipe
,
247 (unsigned char *) &devinfo
->ctl_write
,
249 (usb_complete_t
)brcmf_usb_ctlwrite_complete
,
252 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
254 brcmf_dbg(ERROR
, "usb_submit_urb failed %d\n", ret
);
260 brcmf_usb_recv_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
265 if ((devinfo
== NULL
) || (buf
== NULL
) || (len
== 0)
266 || (devinfo
->ctl_urb
== NULL
))
270 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
271 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
273 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
274 | USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
275 devinfo
->ctl_read
.bRequest
= 1;
277 usb_fill_control_urb(devinfo
->ctl_urb
,
279 devinfo
->ctl_in_pipe
,
280 (unsigned char *) &devinfo
->ctl_read
,
282 (usb_complete_t
)brcmf_usb_ctlread_complete
,
285 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
287 brcmf_dbg(ERROR
, "usb_submit_urb failed %d\n", ret
);
292 static int brcmf_usb_tx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
296 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
298 if (devinfo
->bus_pub
.state
!= BCMFMAC_USB_STATE_UP
) {
299 /* TODO: handle suspend/resume */
303 if (test_and_set_bit(0, &devinfo
->ctl_op
))
306 devinfo
->ctl_completed
= false;
307 err
= brcmf_usb_send_ctl(devinfo
, buf
, len
);
309 brcmf_dbg(ERROR
, "fail %d bytes: %d\n", err
, len
);
310 clear_bit(0, &devinfo
->ctl_op
);
313 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
314 clear_bit(0, &devinfo
->ctl_op
);
316 brcmf_dbg(ERROR
, "Txctl wait timed out\n");
322 static int brcmf_usb_rx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
326 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
328 if (devinfo
->bus_pub
.state
!= BCMFMAC_USB_STATE_UP
) {
329 /* TODO: handle suspend/resume */
332 if (test_and_set_bit(0, &devinfo
->ctl_op
))
335 devinfo
->ctl_completed
= false;
336 err
= brcmf_usb_recv_ctl(devinfo
, buf
, len
);
338 brcmf_dbg(ERROR
, "fail %d bytes: %d\n", err
, len
);
339 clear_bit(0, &devinfo
->ctl_op
);
342 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
343 err
= devinfo
->ctl_urb_status
;
344 clear_bit(0, &devinfo
->ctl_op
);
346 brcmf_dbg(ERROR
, "rxctl wait timed out\n");
350 return devinfo
->ctl_urb_actual_length
;
355 static struct brcmf_usbreq
*brcmf_usb_deq(struct brcmf_usbdev_info
*devinfo
,
356 struct list_head
*q
, int *counter
)
359 struct brcmf_usbreq
*req
;
360 spin_lock_irqsave(&devinfo
->qlock
, flags
);
362 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
365 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
366 list_del_init(q
->next
);
369 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
374 static void brcmf_usb_enq(struct brcmf_usbdev_info
*devinfo
,
375 struct list_head
*q
, struct brcmf_usbreq
*req
,
379 spin_lock_irqsave(&devinfo
->qlock
, flags
);
380 list_add_tail(&req
->list
, q
);
383 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
386 static struct brcmf_usbreq
*
387 brcmf_usbdev_qinit(struct list_head
*q
, int qsize
)
390 struct brcmf_usbreq
*req
, *reqs
;
392 reqs
= kzalloc(sizeof(struct brcmf_usbreq
) * qsize
, GFP_ATOMIC
);
394 brcmf_dbg(ERROR
, "fail to allocate memory!\n");
399 for (i
= 0; i
< qsize
; i
++) {
400 req
->urb
= usb_alloc_urb(0, GFP_ATOMIC
);
404 INIT_LIST_HEAD(&req
->list
);
405 list_add_tail(&req
->list
, q
);
410 brcmf_dbg(ERROR
, "fail!\n");
411 while (!list_empty(q
)) {
412 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
414 usb_free_urb(req
->urb
);
421 static void brcmf_usb_free_q(struct list_head
*q
, bool pending
)
423 struct brcmf_usbreq
*req
, *next
;
425 list_for_each_entry_safe(req
, next
, q
, list
) {
427 brcmf_dbg(ERROR
, "bad req\n");
432 usb_kill_urb(req
->urb
);
434 usb_free_urb(req
->urb
);
435 list_del_init(&req
->list
);
440 static void brcmf_usb_del_fromq(struct brcmf_usbdev_info
*devinfo
,
441 struct brcmf_usbreq
*req
)
445 spin_lock_irqsave(&devinfo
->qlock
, flags
);
446 list_del_init(&req
->list
);
447 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
451 static void brcmf_usb_tx_complete(struct urb
*urb
)
453 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
454 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
456 brcmf_usb_del_fromq(devinfo
, req
);
457 if (urb
->status
== 0)
458 devinfo
->bus_pub
.bus
->dstats
.tx_packets
++;
460 devinfo
->bus_pub
.bus
->dstats
.tx_errors
++;
462 brcmf_txcomplete(devinfo
->dev
, req
->skb
, urb
->status
== 0);
464 brcmu_pkt_buf_free_skb(req
->skb
);
466 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
, &devinfo
->tx_freecount
);
467 if (devinfo
->tx_freecount
> devinfo
->tx_high_watermark
&&
468 devinfo
->tx_flowblock
) {
469 brcmf_txflowblock(devinfo
->dev
, false);
470 devinfo
->tx_flowblock
= false;
474 static void brcmf_usb_rx_complete(struct urb
*urb
)
476 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
477 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
481 brcmf_usb_del_fromq(devinfo
, req
);
485 if (urb
->status
== 0) {
486 devinfo
->bus_pub
.bus
->dstats
.rx_packets
++;
488 devinfo
->bus_pub
.bus
->dstats
.rx_errors
++;
489 brcmu_pkt_buf_free_skb(skb
);
490 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
494 if (devinfo
->bus_pub
.state
== BCMFMAC_USB_STATE_UP
) {
495 skb_put(skb
, urb
->actual_length
);
496 if (brcmf_proto_hdrpull(devinfo
->dev
, &ifidx
, skb
) != 0) {
497 brcmf_dbg(ERROR
, "rx protocol error\n");
498 brcmu_pkt_buf_free_skb(skb
);
499 devinfo
->bus_pub
.bus
->dstats
.rx_errors
++;
501 brcmf_rx_packet(devinfo
->dev
, ifidx
, skb
);
502 brcmf_usb_rx_refill(devinfo
, req
);
504 brcmu_pkt_buf_free_skb(skb
);
505 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
511 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
512 struct brcmf_usbreq
*req
)
517 if (!req
|| !devinfo
)
520 skb
= dev_alloc_skb(devinfo
->bus_pub
.bus_mtu
);
522 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
527 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->rx_pipe
,
528 skb
->data
, skb_tailroom(skb
), brcmf_usb_rx_complete
,
530 req
->devinfo
= devinfo
;
531 brcmf_usb_enq(devinfo
, &devinfo
->rx_postq
, req
, NULL
);
533 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
535 brcmf_usb_del_fromq(devinfo
, req
);
536 brcmu_pkt_buf_free_skb(req
->skb
);
538 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
543 static void brcmf_usb_rx_fill_all(struct brcmf_usbdev_info
*devinfo
)
545 struct brcmf_usbreq
*req
;
547 if (devinfo
->bus_pub
.state
!= BCMFMAC_USB_STATE_UP
) {
548 brcmf_dbg(ERROR
, "bus is not up\n");
551 while ((req
= brcmf_usb_deq(devinfo
, &devinfo
->rx_freeq
, NULL
)) != NULL
)
552 brcmf_usb_rx_refill(devinfo
, req
);
556 brcmf_usb_state_change(struct brcmf_usbdev_info
*devinfo
, int state
)
558 struct brcmf_bus
*bcmf_bus
= devinfo
->bus_pub
.bus
;
562 if (devinfo
->bus_pub
.state
== state
)
565 old_state
= devinfo
->bus_pub
.state
;
566 brcmf_dbg(TRACE
, "dbus state change from %d to to %d\n",
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
;
573 if ((old_state
== BCMFMAC_USB_STATE_SLEEP
)
574 && (state
== BCMFMAC_USB_STATE_UP
)) {
575 brcmf_usb_rx_fill_all(devinfo
);
578 /* update state of upper layer */
579 if (state
== BCMFMAC_USB_STATE_DOWN
) {
580 brcmf_dbg(INFO
, "DBUS is down\n");
581 bcmf_bus
->state
= BRCMF_BUS_DOWN
;
583 brcmf_dbg(INFO
, "DBUS current state=%d\n", state
);
588 brcmf_usb_intr_complete(struct urb
*urb
)
590 struct brcmf_usbdev_info
*devinfo
=
591 (struct brcmf_usbdev_info
*)urb
->context
;
597 if (unlikely(urb
->status
)) {
598 if (devinfo
->suspend_state
==
599 USBOS_SUSPEND_STATE_SUSPEND_PENDING
)
602 if ((urb
->status
== -ENOENT
&& (!killed
))
603 || urb
->status
== -ESHUTDOWN
||
604 urb
->status
== -ENODEV
) {
605 brcmf_usb_state_change(devinfo
, BCMFMAC_USB_STATE_DOWN
);
609 if (devinfo
->bus_pub
.state
== BCMFMAC_USB_STATE_DOWN
) {
610 brcmf_dbg(ERROR
, "intr cb when DBUS down, ignoring\n");
614 if (devinfo
->bus_pub
.state
== BCMFMAC_USB_STATE_UP
)
615 usb_submit_urb(devinfo
->intr_urb
, GFP_ATOMIC
);
618 static int brcmf_usb_tx(struct device
*dev
, struct sk_buff
*skb
)
620 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
621 struct brcmf_usbreq
*req
;
624 if (devinfo
->bus_pub
.state
!= BCMFMAC_USB_STATE_UP
) {
625 /* TODO: handle suspend/resume */
629 req
= brcmf_usb_deq(devinfo
, &devinfo
->tx_freeq
,
630 &devinfo
->tx_freecount
);
632 brcmu_pkt_buf_free_skb(skb
);
633 brcmf_dbg(ERROR
, "no req to send\n");
638 req
->devinfo
= devinfo
;
639 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->tx_pipe
,
640 skb
->data
, skb
->len
, brcmf_usb_tx_complete
, req
);
641 req
->urb
->transfer_flags
|= URB_ZERO_PACKET
;
642 brcmf_usb_enq(devinfo
, &devinfo
->tx_postq
, req
, NULL
);
643 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
645 brcmf_dbg(ERROR
, "brcmf_usb_tx usb_submit_urb FAILED\n");
646 brcmf_usb_del_fromq(devinfo
, req
);
647 brcmu_pkt_buf_free_skb(req
->skb
);
649 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
,
650 &devinfo
->tx_freecount
);
652 if (devinfo
->tx_freecount
< devinfo
->tx_low_watermark
&&
653 !devinfo
->tx_flowblock
) {
654 brcmf_txflowblock(dev
, true);
655 devinfo
->tx_flowblock
= true;
663 static int brcmf_usb_up(struct device
*dev
)
665 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
668 if (devinfo
->bus_pub
.state
== BCMFMAC_USB_STATE_UP
)
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");
678 devinfo
->activity
= true;
680 /* Success, indicate devinfo is fully up */
681 brcmf_usb_state_change(devinfo
, BCMFMAC_USB_STATE_UP
);
683 if (devinfo
->intr_urb
) {
686 usb_fill_int_urb(devinfo
->intr_urb
, devinfo
->usbdev
,
690 (usb_complete_t
)brcmf_usb_intr_complete
,
694 ret
= usb_submit_urb(devinfo
->intr_urb
, GFP_ATOMIC
);
696 brcmf_dbg(ERROR
, "USB_SUBMIT_URB failed with status %d\n",
702 if (devinfo
->ctl_urb
) {
703 devinfo
->ctl_in_pipe
= usb_rcvctrlpipe(devinfo
->usbdev
, 0);
704 devinfo
->ctl_out_pipe
= usb_sndctrlpipe(devinfo
->usbdev
, 0);
706 ifnum
= IFDESC(devinfo
->usbdev
, CONTROL_IF
).bInterfaceNumber
;
709 devinfo
->ctl_write
.bRequestType
=
710 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
711 devinfo
->ctl_write
.bRequest
= 0;
712 devinfo
->ctl_write
.wValue
= cpu_to_le16(0);
713 devinfo
->ctl_write
.wIndex
= cpu_to_le16p(&ifnum
);
716 devinfo
->ctl_read
.bRequestType
=
717 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
718 devinfo
->ctl_read
.bRequest
= 1;
719 devinfo
->ctl_read
.wValue
= cpu_to_le16(0);
720 devinfo
->ctl_read
.wIndex
= cpu_to_le16p(&ifnum
);
722 brcmf_usb_rx_fill_all(devinfo
);
726 static void brcmf_usb_down(struct device
*dev
)
728 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
733 brcmf_dbg(TRACE
, "enter\n");
734 if (devinfo
->bus_pub
.state
== BCMFMAC_USB_STATE_DOWN
)
737 brcmf_usb_state_change(devinfo
, BCMFMAC_USB_STATE_DOWN
);
738 if (devinfo
->intr_urb
)
739 usb_kill_urb(devinfo
->intr_urb
);
741 if (devinfo
->ctl_urb
)
742 usb_kill_urb(devinfo
->ctl_urb
);
744 if (devinfo
->bulk_urb
)
745 usb_kill_urb(devinfo
->bulk_urb
);
746 brcmf_usb_free_q(&devinfo
->tx_postq
, true);
748 brcmf_usb_free_q(&devinfo
->rx_postq
, true);
752 brcmf_usb_sync_complete(struct urb
*urb
)
754 struct brcmf_usbdev_info
*devinfo
=
755 (struct brcmf_usbdev_info
*)urb
->context
;
757 devinfo
->ctl_completed
= true;
758 brcmf_usb_ioctl_resp_wake(devinfo
);
761 static bool brcmf_usb_dl_cmd(struct brcmf_usbdev_info
*devinfo
, u8 cmd
,
762 void *buffer
, int buflen
)
768 if ((!devinfo
) || (devinfo
->ctl_urb
== NULL
))
771 tmpbuf
= kmalloc(buflen
, GFP_ATOMIC
);
776 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
778 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
779 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
| USB_TYPE_VENDOR
|
781 devinfo
->ctl_read
.bRequest
= cmd
;
783 usb_fill_control_urb(devinfo
->ctl_urb
,
785 usb_rcvctrlpipe(devinfo
->usbdev
, 0),
786 (unsigned char *) &devinfo
->ctl_read
,
787 (void *) tmpbuf
, size
,
788 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
790 devinfo
->ctl_completed
= false;
791 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
793 brcmf_dbg(ERROR
, "usb_submit_urb failed %d\n", ret
);
798 ret
= brcmf_usb_ioctl_resp_wait(devinfo
);
799 memcpy(buffer
, tmpbuf
, buflen
);
806 brcmf_usb_dlneeded(struct brcmf_usbdev_info
*devinfo
)
808 struct bootrom_id_le id
;
811 brcmf_dbg(TRACE
, "enter\n");
816 /* Check if firmware downloaded already by querying runtime ID */
817 id
.chip
= cpu_to_le32(0xDEAD);
818 brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
,
819 sizeof(struct bootrom_id_le
));
821 chipid
= le32_to_cpu(id
.chip
);
822 chiprev
= le32_to_cpu(id
.chiprev
);
824 if ((chipid
& 0x4300) == 0x4300)
825 brcmf_dbg(INFO
, "chip %x rev 0x%x\n", chipid
, chiprev
);
827 brcmf_dbg(INFO
, "chip %d rev 0x%x\n", chipid
, chiprev
);
828 if (chipid
== BRCMF_POSTBOOT_ID
) {
829 brcmf_dbg(INFO
, "firmware already downloaded\n");
830 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
,
831 sizeof(struct bootrom_id_le
));
834 devinfo
->bus_pub
.devid
= chipid
;
835 devinfo
->bus_pub
.chiprev
= chiprev
;
841 brcmf_usb_resetcfg(struct brcmf_usbdev_info
*devinfo
)
843 struct bootrom_id_le id
;
844 u16 wait
= 0, wait_time
;
846 brcmf_dbg(TRACE
, "enter\n");
851 /* Give dongle chance to boot */
852 wait_time
= BRCMF_USB_DLIMAGE_SPINWAIT
;
853 while (wait
< BRCMF_USB_DLIMAGE_LIMIT
) {
856 id
.chip
= cpu_to_le32(0xDEAD); /* Get the ID */
857 brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
,
858 sizeof(struct bootrom_id_le
));
859 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
))
863 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",
865 wait
, le32_to_cpu(id
.chip
), le32_to_cpu(id
.chiprev
));
867 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
,
868 sizeof(struct bootrom_id_le
));
870 /* XXX this wait may not be necessary */
871 mdelay(BRCMF_USB_RESETCFG_SPINWAIT
);
874 brcmf_dbg(ERROR
, "Cannot talk to Dongle. Firmware is not UP, %d ms\n",
882 brcmf_usb_dl_send_bulk(struct brcmf_usbdev_info
*devinfo
, void *buffer
, int len
)
886 if ((devinfo
== NULL
) || (devinfo
->bulk_urb
== NULL
))
889 /* Prepare the URB */
890 usb_fill_bulk_urb(devinfo
->bulk_urb
, devinfo
->usbdev
,
891 devinfo
->tx_pipe
, buffer
, len
,
892 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
894 devinfo
->bulk_urb
->transfer_flags
|= URB_ZERO_PACKET
;
896 devinfo
->ctl_completed
= false;
897 ret
= usb_submit_urb(devinfo
->bulk_urb
, GFP_ATOMIC
);
899 brcmf_dbg(ERROR
, "usb_submit_urb failed %d\n", ret
);
902 ret
= brcmf_usb_ioctl_resp_wait(devinfo
);
907 brcmf_usb_dl_writeimage(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int fwlen
)
909 unsigned int sendlen
, sent
, dllen
;
910 char *bulkchunk
= NULL
, *dlpos
;
911 struct rdl_state_le state
;
912 u32 rdlstate
, rdlbytes
;
914 brcmf_dbg(TRACE
, "fw %p, len %d\n", fw
, fwlen
);
916 bulkchunk
= kmalloc(RDL_CHUNK
, GFP_ATOMIC
);
917 if (bulkchunk
== NULL
) {
922 /* 1) Prepare USB boot loader for runtime image */
923 brcmf_usb_dl_cmd(devinfo
, DL_START
, &state
,
924 sizeof(struct rdl_state_le
));
926 rdlstate
= le32_to_cpu(state
.state
);
927 rdlbytes
= le32_to_cpu(state
.bytes
);
929 /* 2) Check we are in the Waiting state */
930 if (rdlstate
!= DL_WAITING
) {
931 brcmf_dbg(ERROR
, "Failed to DL_START\n");
939 /* Get chip id and rev */
940 while (rdlbytes
!= dllen
) {
941 /* Wait until the usb device reports it received all
942 * the bytes we sent */
943 if ((rdlbytes
== sent
) && (rdlbytes
!= dllen
)) {
944 if ((dllen
-sent
) < RDL_CHUNK
)
945 sendlen
= dllen
-sent
;
949 /* simply avoid having to send a ZLP by ensuring we
957 memcpy(bulkchunk
, dlpos
, sendlen
);
958 if (brcmf_usb_dl_send_bulk(devinfo
, bulkchunk
,
960 brcmf_dbg(ERROR
, "send_bulk failed\n");
968 if (!brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
,
969 sizeof(struct rdl_state_le
))) {
970 brcmf_dbg(ERROR
, "DL_GETSTATE Failed xxxx\n");
975 rdlstate
= le32_to_cpu(state
.state
);
976 rdlbytes
= le32_to_cpu(state
.bytes
);
978 /* restart if an error is reported */
979 if (rdlstate
== DL_BAD_HDR
|| rdlstate
== DL_BAD_CRC
) {
980 brcmf_dbg(ERROR
, "Bad Hdr or Bad CRC state %d\n",
989 brcmf_dbg(TRACE
, "err=%d\n", err
);
993 static int brcmf_usb_dlstart(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int len
)
997 brcmf_dbg(TRACE
, "enter\n");
1002 if (devinfo
->bus_pub
.devid
== 0xDEAD)
1005 err
= brcmf_usb_dl_writeimage(devinfo
, fw
, len
);
1007 devinfo
->bus_pub
.state
= BCMFMAC_USB_STATE_DL_DONE
;
1009 devinfo
->bus_pub
.state
= BCMFMAC_USB_STATE_DL_PENDING
;
1010 brcmf_dbg(TRACE
, "exit: err=%d\n", err
);
1015 static int brcmf_usb_dlrun(struct brcmf_usbdev_info
*devinfo
)
1017 struct rdl_state_le state
;
1019 brcmf_dbg(TRACE
, "enter\n");
1023 if (devinfo
->bus_pub
.devid
== 0xDEAD)
1026 /* Check we are runnable */
1027 brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
,
1028 sizeof(struct rdl_state_le
));
1030 /* Start the image */
1031 if (state
.state
== cpu_to_le32(DL_RUNNABLE
)) {
1032 if (!brcmf_usb_dl_cmd(devinfo
, DL_GO
, &state
,
1033 sizeof(struct rdl_state_le
)))
1035 if (brcmf_usb_resetcfg(devinfo
))
1037 /* The Dongle may go for re-enumeration. */
1039 brcmf_dbg(ERROR
, "Dongle not runnable\n");
1042 brcmf_dbg(TRACE
, "exit\n");
1046 static bool brcmf_usb_chip_support(int chipid
, int chiprev
)
1054 return (chiprev
== 3);
1064 brcmf_usb_fw_download(struct brcmf_usbdev_info
*devinfo
)
1069 brcmf_dbg(TRACE
, "enter\n");
1070 if (devinfo
== NULL
)
1073 devid
= devinfo
->bus_pub
.devid
;
1074 chiprev
= devinfo
->bus_pub
.chiprev
;
1076 if (!brcmf_usb_chip_support(devid
, chiprev
)) {
1077 brcmf_dbg(ERROR
, "unsupported chip %d rev %d\n",
1082 if (!devinfo
->image
) {
1083 brcmf_dbg(ERROR
, "No firmware!\n");
1087 err
= brcmf_usb_dlstart(devinfo
,
1088 devinfo
->image
, devinfo
->image_len
);
1090 err
= brcmf_usb_dlrun(devinfo
);
1095 static void brcmf_usb_detach(struct brcmf_usbdev_info
*devinfo
)
1097 brcmf_dbg(TRACE
, "devinfo %p\n", devinfo
);
1100 brcmf_usb_free_q(&devinfo
->rx_freeq
, false);
1101 brcmf_usb_free_q(&devinfo
->tx_freeq
, false);
1103 usb_free_urb(devinfo
->intr_urb
);
1104 usb_free_urb(devinfo
->ctl_urb
);
1105 usb_free_urb(devinfo
->bulk_urb
);
1107 kfree(devinfo
->tx_reqs
);
1108 kfree(devinfo
->rx_reqs
);
1111 #define TRX_MAGIC 0x30524448 /* "HDR0" */
1112 #define TRX_VERSION 1 /* Version 1 */
1113 #define TRX_MAX_LEN 0x3B0000 /* Max length */
1114 #define TRX_NO_HEADER 1 /* Do not write TRX header */
1115 #define TRX_MAX_OFFSET 3 /* Max number of individual files */
1116 #define TRX_UNCOMP_IMAGE 0x20 /* Trx contains uncompressed image */
1118 struct trx_header_le
{
1119 __le32 magic
; /* "HDR0" */
1120 __le32 len
; /* Length of file including header */
1121 __le32 crc32
; /* CRC from flag_version to end of file */
1122 __le32 flag_version
; /* 0:15 flags, 16:31 version */
1123 __le32 offsets
[TRX_MAX_OFFSET
]; /* Offsets of partitions from start of
1127 static int check_file(const u8
*headers
)
1129 struct trx_header_le
*trx
;
1130 int actual_len
= -1;
1132 /* Extract trx header */
1133 trx
= (struct trx_header_le
*) headers
;
1134 if (trx
->magic
!= cpu_to_le32(TRX_MAGIC
))
1137 headers
+= sizeof(struct trx_header_le
);
1139 if (le32_to_cpu(trx
->flag_version
) & TRX_UNCOMP_IMAGE
) {
1140 actual_len
= le32_to_cpu(trx
->offsets
[TRX_OFFSETS_DLFWLEN_IDX
]);
1141 return actual_len
+ sizeof(struct trx_header_le
);
1146 static int brcmf_usb_get_fw(struct brcmf_usbdev_info
*devinfo
)
1149 const struct firmware
*fw
;
1150 struct brcmf_usb_image
*fw_image
;
1153 switch (devinfo
->bus_pub
.devid
) {
1155 fwname
= BRCMF_USB_43143_FW_NAME
;
1160 fwname
= BRCMF_USB_43236_FW_NAME
;
1163 fwname
= BRCMF_USB_43242_FW_NAME
;
1170 list_for_each_entry(fw_image
, &fw_image_list
, list
) {
1171 if (fw_image
->fwname
== fwname
) {
1172 devinfo
->image
= fw_image
->image
;
1173 devinfo
->image_len
= fw_image
->image_len
;
1177 /* fw image not yet loaded. Load it now and add to list */
1178 err
= request_firmware(&fw
, fwname
, devinfo
->dev
);
1180 brcmf_dbg(ERROR
, "fail to request firmware %s\n", fwname
);
1183 if (check_file(fw
->data
) < 0) {
1184 brcmf_dbg(ERROR
, "invalid firmware %s\n", fwname
);
1188 fw_image
= kzalloc(sizeof(*fw_image
), GFP_ATOMIC
);
1191 INIT_LIST_HEAD(&fw_image
->list
);
1192 list_add_tail(&fw_image
->list
, &fw_image_list
);
1193 fw_image
->fwname
= fwname
;
1194 fw_image
->image
= vmalloc(fw
->size
);
1195 if (!fw_image
->image
)
1198 memcpy(fw_image
->image
, fw
->data
, fw
->size
);
1199 fw_image
->image_len
= fw
->size
;
1201 release_firmware(fw
);
1203 devinfo
->image
= fw_image
->image
;
1204 devinfo
->image_len
= fw_image
->image_len
;
1211 struct brcmf_usbdev
*brcmf_usb_attach(struct brcmf_usbdev_info
*devinfo
,
1214 devinfo
->bus_pub
.nrxq
= nrxq
;
1215 devinfo
->rx_low_watermark
= nrxq
/ 2;
1216 devinfo
->bus_pub
.devinfo
= devinfo
;
1217 devinfo
->bus_pub
.ntxq
= ntxq
;
1219 /* flow control when too many tx urbs posted */
1220 devinfo
->tx_low_watermark
= ntxq
/ 4;
1221 devinfo
->tx_high_watermark
= devinfo
->tx_low_watermark
* 3;
1222 devinfo
->bus_pub
.bus_mtu
= BRCMF_USB_MAX_PKT_SIZE
;
1224 /* Initialize other structure content */
1225 init_waitqueue_head(&devinfo
->ioctl_resp_wait
);
1227 /* Initialize the spinlocks */
1228 spin_lock_init(&devinfo
->qlock
);
1230 INIT_LIST_HEAD(&devinfo
->rx_freeq
);
1231 INIT_LIST_HEAD(&devinfo
->rx_postq
);
1233 INIT_LIST_HEAD(&devinfo
->tx_freeq
);
1234 INIT_LIST_HEAD(&devinfo
->tx_postq
);
1236 devinfo
->tx_flowblock
= false;
1238 devinfo
->rx_reqs
= brcmf_usbdev_qinit(&devinfo
->rx_freeq
, nrxq
);
1239 if (!devinfo
->rx_reqs
)
1242 devinfo
->tx_reqs
= brcmf_usbdev_qinit(&devinfo
->tx_freeq
, ntxq
);
1243 if (!devinfo
->tx_reqs
)
1245 devinfo
->tx_freecount
= ntxq
;
1247 devinfo
->intr_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1248 if (!devinfo
->intr_urb
) {
1249 brcmf_dbg(ERROR
, "usb_alloc_urb (intr) failed\n");
1252 devinfo
->ctl_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1253 if (!devinfo
->ctl_urb
) {
1254 brcmf_dbg(ERROR
, "usb_alloc_urb (ctl) failed\n");
1257 devinfo
->bulk_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1258 if (!devinfo
->bulk_urb
) {
1259 brcmf_dbg(ERROR
, "usb_alloc_urb (bulk) failed\n");
1263 if (!brcmf_usb_dlneeded(devinfo
))
1264 return &devinfo
->bus_pub
;
1266 brcmf_dbg(TRACE
, "start fw downloading\n");
1267 if (brcmf_usb_get_fw(devinfo
))
1270 if (brcmf_usb_fw_download(devinfo
))
1273 return &devinfo
->bus_pub
;
1276 brcmf_dbg(ERROR
, "failed!\n");
1277 brcmf_usb_detach(devinfo
);
1281 static int brcmf_usb_probe_cb(struct brcmf_usbdev_info
*devinfo
,
1282 const char *desc
, u32 bustype
, u32 hdrlen
)
1284 struct brcmf_bus
*bus
= NULL
;
1285 struct brcmf_usbdev
*bus_pub
= NULL
;
1287 struct device
*dev
= devinfo
->dev
;
1289 bus_pub
= brcmf_usb_attach(devinfo
, BRCMF_USB_NRXQ
, BRCMF_USB_NTXQ
);
1293 bus
= kzalloc(sizeof(struct brcmf_bus
), GFP_ATOMIC
);
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
;
1307 dev_set_drvdata(dev
, bus
);
1309 /* Attach to the common driver interface */
1310 ret
= brcmf_attach(hdrlen
, dev
);
1312 brcmf_dbg(ERROR
, "dhd_attach failed\n");
1316 ret
= brcmf_bus_start(dev
);
1318 brcmf_dbg(ERROR
, "dongle is not responding\n");
1325 /* Release resources in reverse order */
1327 brcmf_usb_detach(devinfo
);
1332 brcmf_usb_disconnect_cb(struct brcmf_usbdev_info
*devinfo
)
1336 brcmf_dbg(TRACE
, "enter: bus_pub %p\n", devinfo
);
1338 brcmf_detach(devinfo
->dev
);
1339 kfree(devinfo
->bus_pub
.bus
);
1340 brcmf_usb_detach(devinfo
);
1344 brcmf_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1347 struct usb_endpoint_descriptor
*endpoint
;
1349 struct usb_device
*usb
= interface_to_usbdev(intf
);
1352 struct brcmf_usbdev_info
*devinfo
;
1354 brcmf_dbg(TRACE
, "enter\n");
1356 devinfo
= kzalloc(sizeof(*devinfo
), GFP_ATOMIC
);
1357 if (devinfo
== NULL
)
1360 devinfo
->usbdev
= usb
;
1361 devinfo
->dev
= &usb
->dev
;
1363 usb_set_intfdata(intf
, devinfo
);
1365 /* Check that the device supports only one configuration */
1366 if (usb
->descriptor
.bNumConfigurations
!= 1) {
1371 if (usb
->descriptor
.bDeviceClass
!= USB_CLASS_VENDOR_SPEC
) {
1377 * Only the BDC interface configuration is supported:
1378 * Device class: USB_CLASS_VENDOR_SPEC
1379 * if0 class: USB_CLASS_VENDOR_SPEC
1382 * if0/ep2: bulk out (ok if swapped with bulk in)
1384 if (CONFIGDESC(usb
)->bNumInterfaces
!= 1) {
1389 /* Check interface */
1390 if (IFDESC(usb
, CONTROL_IF
).bInterfaceClass
!= USB_CLASS_VENDOR_SPEC
||
1391 IFDESC(usb
, CONTROL_IF
).bInterfaceSubClass
!= 2 ||
1392 IFDESC(usb
, CONTROL_IF
).bInterfaceProtocol
!= 0xff) {
1393 brcmf_dbg(ERROR
, "invalid control interface: class %d, subclass %d, proto %d\n",
1394 IFDESC(usb
, CONTROL_IF
).bInterfaceClass
,
1395 IFDESC(usb
, CONTROL_IF
).bInterfaceSubClass
,
1396 IFDESC(usb
, CONTROL_IF
).bInterfaceProtocol
);
1401 /* Check control endpoint */
1402 endpoint
= &IFEPDESC(usb
, CONTROL_IF
, 0);
1403 if ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1404 != USB_ENDPOINT_XFER_INT
) {
1405 brcmf_dbg(ERROR
, "invalid control endpoint %d\n",
1406 endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
);
1411 endpoint_num
= endpoint
->bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
;
1412 devinfo
->intr_pipe
= usb_rcvintpipe(usb
, endpoint_num
);
1414 devinfo
->rx_pipe
= 0;
1415 devinfo
->rx_pipe2
= 0;
1416 devinfo
->tx_pipe
= 0;
1417 num_of_eps
= IFDESC(usb
, BULK_IF
).bNumEndpoints
- 1;
1419 /* Check data endpoints and get pipes */
1420 for (ep
= 1; ep
<= num_of_eps
; ep
++) {
1421 endpoint
= &IFEPDESC(usb
, BULK_IF
, ep
);
1422 if ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) !=
1423 USB_ENDPOINT_XFER_BULK
) {
1424 brcmf_dbg(ERROR
, "invalid data endpoint %d\n", ep
);
1429 endpoint_num
= endpoint
->bEndpointAddress
&
1430 USB_ENDPOINT_NUMBER_MASK
;
1431 if ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1433 if (!devinfo
->rx_pipe
) {
1435 usb_rcvbulkpipe(usb
, endpoint_num
);
1438 usb_rcvbulkpipe(usb
, endpoint_num
);
1441 devinfo
->tx_pipe
= usb_sndbulkpipe(usb
, endpoint_num
);
1445 /* Allocate interrupt URB and data buffer */
1446 /* RNDIS says 8-byte intr, our old drivers used 4-byte */
1447 if (IFEPDESC(usb
, CONTROL_IF
, 0).wMaxPacketSize
== cpu_to_le16(16))
1448 devinfo
->intr_size
= 8;
1450 devinfo
->intr_size
= 4;
1452 devinfo
->interval
= IFEPDESC(usb
, CONTROL_IF
, 0).bInterval
;
1454 if (usb
->speed
== USB_SPEED_HIGH
)
1455 brcmf_dbg(INFO
, "Broadcom high speed USB wireless device detected\n");
1457 brcmf_dbg(INFO
, "Broadcom full speed USB wireless device detected\n");
1459 ret
= brcmf_usb_probe_cb(devinfo
, "", USB_BUS
, 0);
1467 brcmf_dbg(ERROR
, "failed with errno %d\n", ret
);
1469 usb_set_intfdata(intf
, NULL
);
1475 brcmf_usb_disconnect(struct usb_interface
*intf
)
1477 struct brcmf_usbdev_info
*devinfo
;
1479 brcmf_dbg(TRACE
, "enter\n");
1480 devinfo
= (struct brcmf_usbdev_info
*)usb_get_intfdata(intf
);
1481 brcmf_usb_disconnect_cb(devinfo
);
1486 * only need to signal the bus being down and update the suspend state.
1488 static int brcmf_usb_suspend(struct usb_interface
*intf
, pm_message_t state
)
1490 struct usb_device
*usb
= interface_to_usbdev(intf
);
1491 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1493 brcmf_dbg(TRACE
, "enter\n");
1494 devinfo
->bus_pub
.state
= BCMFMAC_USB_STATE_DOWN
;
1495 devinfo
->suspend_state
= USBOS_SUSPEND_STATE_SUSPENDED
;
1500 * mark suspend state active and crank up the bus.
1502 static int brcmf_usb_resume(struct usb_interface
*intf
)
1504 struct usb_device
*usb
= interface_to_usbdev(intf
);
1505 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1507 brcmf_dbg(TRACE
, "enter\n");
1508 devinfo
->suspend_state
= USBOS_SUSPEND_STATE_DEVICE_ACTIVE
;
1509 brcmf_bus_start(&usb
->dev
);
1513 #define BRCMF_USB_VENDOR_ID_BROADCOM 0x0a5c
1514 #define BRCMF_USB_DEVICE_ID_43143 0xbd1e
1515 #define BRCMF_USB_DEVICE_ID_43236 0xbd17
1516 #define BRCMF_USB_DEVICE_ID_43242 0xbd1f
1517 #define BRCMF_USB_DEVICE_ID_BCMFW 0x0bdc
1519 static struct usb_device_id brcmf_usb_devid_table
[] = {
1520 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43143
) },
1521 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43236
) },
1522 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43242
) },
1523 /* special entry for device with firmware loaded and running */
1524 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_BCMFW
) },
1527 MODULE_DEVICE_TABLE(usb
, brcmf_usb_devid_table
);
1528 MODULE_FIRMWARE(BRCMF_USB_43143_FW_NAME
);
1529 MODULE_FIRMWARE(BRCMF_USB_43236_FW_NAME
);
1530 MODULE_FIRMWARE(BRCMF_USB_43242_FW_NAME
);
1532 /* TODO: suspend and resume entries */
1533 static struct usb_driver brcmf_usbdrvr
= {
1534 .name
= KBUILD_MODNAME
,
1535 .probe
= brcmf_usb_probe
,
1536 .disconnect
= brcmf_usb_disconnect
,
1537 .id_table
= brcmf_usb_devid_table
,
1538 .suspend
= brcmf_usb_suspend
,
1539 .resume
= brcmf_usb_resume
,
1540 .supports_autosuspend
= 1,
1541 .disable_hub_initiated_lpm
= 1,
1544 static void brcmf_release_fw(struct list_head
*q
)
1546 struct brcmf_usb_image
*fw_image
, *next
;
1548 list_for_each_entry_safe(fw_image
, next
, q
, list
) {
1549 vfree(fw_image
->image
);
1550 list_del_init(&fw_image
->list
);
1555 void brcmf_usb_exit(void)
1557 usb_deregister(&brcmf_usbdrvr
);
1558 brcmf_release_fw(&fw_image_list
);
1561 void brcmf_usb_init(void)
1563 INIT_LIST_HEAD(&fw_image_list
);
1564 usb_register(&brcmf_usbdrvr
);