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/kernel.h>
18 #include <linux/module.h>
19 #include <linux/firmware.h>
20 #include <linux/usb.h>
21 #include <linux/vmalloc.h>
23 #include <brcmu_utils.h>
24 #include <brcmu_wifi.h>
31 #define IOCTL_RESP_TIMEOUT 2000
33 #define BRCMF_USB_RESET_GETVER_SPINWAIT 100 /* in unit of ms */
34 #define BRCMF_USB_RESET_GETVER_LOOP_CNT 10
36 #define BRCMF_POSTBOOT_ID 0xA123 /* ID to detect if dongle
38 #define BRCMF_USB_NRXQ 50
39 #define BRCMF_USB_NTXQ 50
41 #define CONFIGDESC(usb) (&((usb)->actconfig)->desc)
42 #define IFPTR(usb, idx) ((usb)->actconfig->interface[(idx)])
43 #define IFALTS(usb, idx) (IFPTR((usb), (idx))->altsetting[0])
44 #define IFDESC(usb, idx) IFALTS((usb), (idx)).desc
45 #define IFEPDESC(usb, idx, ep) (IFALTS((usb), (idx)).endpoint[(ep)]).desc
50 #define BRCMF_USB_CBCTL_WRITE 0
51 #define BRCMF_USB_CBCTL_READ 1
52 #define BRCMF_USB_MAX_PKT_SIZE 1600
54 #define BRCMF_USB_43143_FW_NAME "brcm/brcmfmac43143.bin"
55 #define BRCMF_USB_43236_FW_NAME "brcm/brcmfmac43236b.bin"
56 #define BRCMF_USB_43242_FW_NAME "brcm/brcmfmac43242a.bin"
58 struct brcmf_usb_image
{
59 struct list_head list
;
64 static struct list_head fw_image_list
;
66 struct intr_transfer_buf
{
71 struct brcmf_usbdev_info
{
72 struct brcmf_usbdev bus_pub
; /* MUST BE FIRST */
74 struct list_head rx_freeq
;
75 struct list_head rx_postq
;
76 struct list_head tx_freeq
;
77 struct list_head tx_postq
;
78 uint rx_pipe
, tx_pipe
, intr_pipe
, rx_pipe2
;
82 int tx_high_watermark
;
85 spinlock_t tx_flowblock_lock
;
87 struct brcmf_usbreq
*tx_reqs
;
88 struct brcmf_usbreq
*rx_reqs
;
90 u8
*image
; /* buffer for combine fw and nvram */
93 struct usb_device
*usbdev
;
96 int ctl_in_pipe
, ctl_out_pipe
;
97 struct urb
*ctl_urb
; /* URB for control endpoint */
98 struct usb_ctrlrequest ctl_write
;
99 struct usb_ctrlrequest ctl_read
;
100 u32 ctl_urb_actual_length
;
103 wait_queue_head_t ioctl_resp_wait
;
106 struct urb
*bulk_urb
; /* used for FW download */
107 struct urb
*intr_urb
; /* URB for interrupt endpoint */
108 int intr_size
; /* Size of interrupt message */
109 int interval
; /* Interrupt polling interval */
110 struct intr_transfer_buf intr
; /* Data buffer for interrupt endpoint */
113 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
114 struct brcmf_usbreq
*req
);
116 static struct brcmf_usbdev
*brcmf_usb_get_buspub(struct device
*dev
)
118 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
119 return bus_if
->bus_priv
.usb
;
122 static struct brcmf_usbdev_info
*brcmf_usb_get_businfo(struct device
*dev
)
124 return brcmf_usb_get_buspub(dev
)->devinfo
;
127 static int brcmf_usb_ioctl_resp_wait(struct brcmf_usbdev_info
*devinfo
)
129 return wait_event_timeout(devinfo
->ioctl_resp_wait
,
130 devinfo
->ctl_completed
,
131 msecs_to_jiffies(IOCTL_RESP_TIMEOUT
));
134 static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info
*devinfo
)
136 if (waitqueue_active(&devinfo
->ioctl_resp_wait
))
137 wake_up(&devinfo
->ioctl_resp_wait
);
141 brcmf_usb_ctl_complete(struct brcmf_usbdev_info
*devinfo
, int type
, int status
)
143 brcmf_dbg(USB
, "Enter, status=%d\n", status
);
145 if (unlikely(devinfo
== NULL
))
148 if (type
== BRCMF_USB_CBCTL_READ
) {
150 devinfo
->bus_pub
.stats
.rx_ctlpkts
++;
152 devinfo
->bus_pub
.stats
.rx_ctlerrs
++;
153 } else if (type
== BRCMF_USB_CBCTL_WRITE
) {
155 devinfo
->bus_pub
.stats
.tx_ctlpkts
++;
157 devinfo
->bus_pub
.stats
.tx_ctlerrs
++;
160 devinfo
->ctl_urb_status
= status
;
161 devinfo
->ctl_completed
= true;
162 brcmf_usb_ioctl_resp_wake(devinfo
);
166 brcmf_usb_ctlread_complete(struct urb
*urb
)
168 struct brcmf_usbdev_info
*devinfo
=
169 (struct brcmf_usbdev_info
*)urb
->context
;
171 brcmf_dbg(USB
, "Enter\n");
172 devinfo
->ctl_urb_actual_length
= urb
->actual_length
;
173 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_READ
,
178 brcmf_usb_ctlwrite_complete(struct urb
*urb
)
180 struct brcmf_usbdev_info
*devinfo
=
181 (struct brcmf_usbdev_info
*)urb
->context
;
183 brcmf_dbg(USB
, "Enter\n");
184 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_WRITE
,
189 brcmf_usb_send_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
194 brcmf_dbg(USB
, "Enter\n");
195 if (devinfo
== NULL
|| buf
== NULL
||
196 len
== 0 || devinfo
->ctl_urb
== NULL
)
200 devinfo
->ctl_write
.wLength
= cpu_to_le16p(&size
);
201 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
202 devinfo
->ctl_urb_status
= 0;
203 devinfo
->ctl_urb_actual_length
= 0;
205 usb_fill_control_urb(devinfo
->ctl_urb
,
207 devinfo
->ctl_out_pipe
,
208 (unsigned char *) &devinfo
->ctl_write
,
210 (usb_complete_t
)brcmf_usb_ctlwrite_complete
,
213 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
215 brcmf_err("usb_submit_urb failed %d\n", ret
);
221 brcmf_usb_recv_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
226 brcmf_dbg(USB
, "Enter\n");
227 if ((devinfo
== NULL
) || (buf
== NULL
) || (len
== 0)
228 || (devinfo
->ctl_urb
== NULL
))
232 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
233 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
235 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
236 | USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
237 devinfo
->ctl_read
.bRequest
= 1;
239 usb_fill_control_urb(devinfo
->ctl_urb
,
241 devinfo
->ctl_in_pipe
,
242 (unsigned char *) &devinfo
->ctl_read
,
244 (usb_complete_t
)brcmf_usb_ctlread_complete
,
247 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
249 brcmf_err("usb_submit_urb failed %d\n", ret
);
254 static int brcmf_usb_tx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
258 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
260 brcmf_dbg(USB
, "Enter\n");
261 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
)
264 if (test_and_set_bit(0, &devinfo
->ctl_op
))
267 devinfo
->ctl_completed
= false;
268 err
= brcmf_usb_send_ctl(devinfo
, buf
, len
);
270 brcmf_err("fail %d bytes: %d\n", err
, len
);
271 clear_bit(0, &devinfo
->ctl_op
);
274 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
275 clear_bit(0, &devinfo
->ctl_op
);
277 brcmf_err("Txctl wait timed out\n");
283 static int brcmf_usb_rx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
287 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
289 brcmf_dbg(USB
, "Enter\n");
290 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
)
293 if (test_and_set_bit(0, &devinfo
->ctl_op
))
296 devinfo
->ctl_completed
= false;
297 err
= brcmf_usb_recv_ctl(devinfo
, buf
, len
);
299 brcmf_err("fail %d bytes: %d\n", err
, len
);
300 clear_bit(0, &devinfo
->ctl_op
);
303 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
304 err
= devinfo
->ctl_urb_status
;
305 clear_bit(0, &devinfo
->ctl_op
);
307 brcmf_err("rxctl wait timed out\n");
311 return devinfo
->ctl_urb_actual_length
;
316 static struct brcmf_usbreq
*brcmf_usb_deq(struct brcmf_usbdev_info
*devinfo
,
317 struct list_head
*q
, int *counter
)
320 struct brcmf_usbreq
*req
;
321 spin_lock_irqsave(&devinfo
->qlock
, flags
);
323 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
326 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
327 list_del_init(q
->next
);
330 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
335 static void brcmf_usb_enq(struct brcmf_usbdev_info
*devinfo
,
336 struct list_head
*q
, struct brcmf_usbreq
*req
,
340 spin_lock_irqsave(&devinfo
->qlock
, flags
);
341 list_add_tail(&req
->list
, q
);
344 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
347 static struct brcmf_usbreq
*
348 brcmf_usbdev_qinit(struct list_head
*q
, int qsize
)
351 struct brcmf_usbreq
*req
, *reqs
;
353 reqs
= kcalloc(qsize
, sizeof(struct brcmf_usbreq
), GFP_ATOMIC
);
359 for (i
= 0; i
< qsize
; i
++) {
360 req
->urb
= usb_alloc_urb(0, GFP_ATOMIC
);
364 INIT_LIST_HEAD(&req
->list
);
365 list_add_tail(&req
->list
, q
);
370 brcmf_err("fail!\n");
371 while (!list_empty(q
)) {
372 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
374 usb_free_urb(req
->urb
);
381 static void brcmf_usb_free_q(struct list_head
*q
, bool pending
)
383 struct brcmf_usbreq
*req
, *next
;
385 list_for_each_entry_safe(req
, next
, q
, list
) {
387 brcmf_err("bad req\n");
392 usb_kill_urb(req
->urb
);
394 usb_free_urb(req
->urb
);
395 list_del_init(&req
->list
);
400 static void brcmf_usb_del_fromq(struct brcmf_usbdev_info
*devinfo
,
401 struct brcmf_usbreq
*req
)
405 spin_lock_irqsave(&devinfo
->qlock
, flags
);
406 list_del_init(&req
->list
);
407 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
411 static void brcmf_usb_tx_complete(struct urb
*urb
)
413 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
414 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
417 brcmf_dbg(USB
, "Enter, urb->status=%d, skb=%p\n", urb
->status
,
419 brcmf_usb_del_fromq(devinfo
, req
);
421 brcmf_txcomplete(devinfo
->dev
, req
->skb
, urb
->status
== 0);
423 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
, &devinfo
->tx_freecount
);
424 spin_lock_irqsave(&devinfo
->tx_flowblock_lock
, flags
);
425 if (devinfo
->tx_freecount
> devinfo
->tx_high_watermark
&&
426 devinfo
->tx_flowblock
) {
427 brcmf_txflowblock(devinfo
->dev
, false);
428 devinfo
->tx_flowblock
= false;
430 spin_unlock_irqrestore(&devinfo
->tx_flowblock_lock
, flags
);
433 static void brcmf_usb_rx_complete(struct urb
*urb
)
435 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
436 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
439 brcmf_dbg(USB
, "Enter, urb->status=%d\n", urb
->status
);
440 brcmf_usb_del_fromq(devinfo
, req
);
444 /* zero lenght packets indicate usb "failure". Do not refill */
445 if (urb
->status
!= 0 || !urb
->actual_length
) {
446 brcmu_pkt_buf_free_skb(skb
);
447 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
451 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
) {
452 skb_put(skb
, urb
->actual_length
);
453 brcmf_rx_frame(devinfo
->dev
, skb
);
454 brcmf_usb_rx_refill(devinfo
, req
);
456 brcmu_pkt_buf_free_skb(skb
);
457 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
463 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
464 struct brcmf_usbreq
*req
)
469 if (!req
|| !devinfo
)
472 skb
= dev_alloc_skb(devinfo
->bus_pub
.bus_mtu
);
474 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
479 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->rx_pipe
,
480 skb
->data
, skb_tailroom(skb
), brcmf_usb_rx_complete
,
482 req
->devinfo
= devinfo
;
483 brcmf_usb_enq(devinfo
, &devinfo
->rx_postq
, req
, NULL
);
485 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
487 brcmf_usb_del_fromq(devinfo
, req
);
488 brcmu_pkt_buf_free_skb(req
->skb
);
490 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
495 static void brcmf_usb_rx_fill_all(struct brcmf_usbdev_info
*devinfo
)
497 struct brcmf_usbreq
*req
;
499 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
500 brcmf_err("bus is not up=%d\n", devinfo
->bus_pub
.state
);
503 while ((req
= brcmf_usb_deq(devinfo
, &devinfo
->rx_freeq
, NULL
)) != NULL
)
504 brcmf_usb_rx_refill(devinfo
, req
);
508 brcmf_usb_state_change(struct brcmf_usbdev_info
*devinfo
, int state
)
510 struct brcmf_bus
*bcmf_bus
= devinfo
->bus_pub
.bus
;
513 brcmf_dbg(USB
, "Enter, current state=%d, new state=%d\n",
514 devinfo
->bus_pub
.state
, state
);
516 if (devinfo
->bus_pub
.state
== state
)
519 old_state
= devinfo
->bus_pub
.state
;
520 devinfo
->bus_pub
.state
= state
;
522 /* update state of upper layer */
523 if (state
== BRCMFMAC_USB_STATE_DOWN
) {
524 brcmf_dbg(USB
, "DBUS is down\n");
525 brcmf_bus_change_state(bcmf_bus
, BRCMF_BUS_DOWN
);
526 } else if (state
== BRCMFMAC_USB_STATE_UP
) {
527 brcmf_dbg(USB
, "DBUS is up\n");
528 brcmf_bus_change_state(bcmf_bus
, BRCMF_BUS_DATA
);
530 brcmf_dbg(USB
, "DBUS current state=%d\n", state
);
535 brcmf_usb_intr_complete(struct urb
*urb
)
537 struct brcmf_usbdev_info
*devinfo
=
538 (struct brcmf_usbdev_info
*)urb
->context
;
541 brcmf_dbg(USB
, "Enter, urb->status=%d\n", urb
->status
);
546 if (unlikely(urb
->status
)) {
547 if (urb
->status
== -ENOENT
||
548 urb
->status
== -ESHUTDOWN
||
549 urb
->status
== -ENODEV
) {
550 brcmf_usb_state_change(devinfo
,
551 BRCMFMAC_USB_STATE_DOWN
);
555 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_DOWN
) {
556 brcmf_err("intr cb when DBUS down, ignoring\n");
560 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
) {
561 err
= usb_submit_urb(devinfo
->intr_urb
, GFP_ATOMIC
);
563 brcmf_err("usb_submit_urb, err=%d\n", err
);
567 static int brcmf_usb_tx(struct device
*dev
, struct sk_buff
*skb
)
569 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
570 struct brcmf_usbreq
*req
;
574 brcmf_dbg(USB
, "Enter, skb=%p\n", skb
);
575 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
580 req
= brcmf_usb_deq(devinfo
, &devinfo
->tx_freeq
,
581 &devinfo
->tx_freecount
);
583 brcmf_err("no req to send\n");
589 req
->devinfo
= devinfo
;
590 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->tx_pipe
,
591 skb
->data
, skb
->len
, brcmf_usb_tx_complete
, req
);
592 req
->urb
->transfer_flags
|= URB_ZERO_PACKET
;
593 brcmf_usb_enq(devinfo
, &devinfo
->tx_postq
, req
, NULL
);
594 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
596 brcmf_err("brcmf_usb_tx usb_submit_urb FAILED\n");
597 brcmf_usb_del_fromq(devinfo
, req
);
599 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
,
600 &devinfo
->tx_freecount
);
604 spin_lock_irqsave(&devinfo
->tx_flowblock_lock
, flags
);
605 if (devinfo
->tx_freecount
< devinfo
->tx_low_watermark
&&
606 !devinfo
->tx_flowblock
) {
607 brcmf_txflowblock(dev
, true);
608 devinfo
->tx_flowblock
= true;
610 spin_unlock_irqrestore(&devinfo
->tx_flowblock_lock
, flags
);
618 static int brcmf_usb_up(struct device
*dev
)
620 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
624 brcmf_dbg(USB
, "Enter\n");
625 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
)
628 /* Success, indicate devinfo is fully up */
629 brcmf_usb_state_change(devinfo
, BRCMFMAC_USB_STATE_UP
);
631 if (devinfo
->intr_urb
) {
632 usb_fill_int_urb(devinfo
->intr_urb
, devinfo
->usbdev
,
636 (usb_complete_t
)brcmf_usb_intr_complete
,
640 ret
= usb_submit_urb(devinfo
->intr_urb
, GFP_ATOMIC
);
642 brcmf_err("USB_SUBMIT_URB failed with status %d\n",
648 if (devinfo
->ctl_urb
) {
649 devinfo
->ctl_in_pipe
= usb_rcvctrlpipe(devinfo
->usbdev
, 0);
650 devinfo
->ctl_out_pipe
= usb_sndctrlpipe(devinfo
->usbdev
, 0);
652 ifnum
= IFDESC(devinfo
->usbdev
, CONTROL_IF
).bInterfaceNumber
;
655 devinfo
->ctl_write
.bRequestType
=
656 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
657 devinfo
->ctl_write
.bRequest
= 0;
658 devinfo
->ctl_write
.wValue
= cpu_to_le16(0);
659 devinfo
->ctl_write
.wIndex
= cpu_to_le16p(&ifnum
);
662 devinfo
->ctl_read
.bRequestType
=
663 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
664 devinfo
->ctl_read
.bRequest
= 1;
665 devinfo
->ctl_read
.wValue
= cpu_to_le16(0);
666 devinfo
->ctl_read
.wIndex
= cpu_to_le16p(&ifnum
);
668 brcmf_usb_rx_fill_all(devinfo
);
672 static void brcmf_usb_down(struct device
*dev
)
674 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
676 brcmf_dbg(USB
, "Enter\n");
680 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_DOWN
)
683 brcmf_usb_state_change(devinfo
, BRCMFMAC_USB_STATE_DOWN
);
684 if (devinfo
->intr_urb
)
685 usb_kill_urb(devinfo
->intr_urb
);
687 if (devinfo
->ctl_urb
)
688 usb_kill_urb(devinfo
->ctl_urb
);
690 if (devinfo
->bulk_urb
)
691 usb_kill_urb(devinfo
->bulk_urb
);
692 brcmf_usb_free_q(&devinfo
->tx_postq
, true);
694 brcmf_usb_free_q(&devinfo
->rx_postq
, true);
698 brcmf_usb_sync_complete(struct urb
*urb
)
700 struct brcmf_usbdev_info
*devinfo
=
701 (struct brcmf_usbdev_info
*)urb
->context
;
703 devinfo
->ctl_completed
= true;
704 brcmf_usb_ioctl_resp_wake(devinfo
);
707 static bool brcmf_usb_dl_cmd(struct brcmf_usbdev_info
*devinfo
, u8 cmd
,
708 void *buffer
, int buflen
)
714 if ((!devinfo
) || (devinfo
->ctl_urb
== NULL
))
717 tmpbuf
= kmalloc(buflen
, GFP_ATOMIC
);
722 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
724 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
725 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
| USB_TYPE_VENDOR
|
727 devinfo
->ctl_read
.bRequest
= cmd
;
729 usb_fill_control_urb(devinfo
->ctl_urb
,
731 usb_rcvctrlpipe(devinfo
->usbdev
, 0),
732 (unsigned char *) &devinfo
->ctl_read
,
733 (void *) tmpbuf
, size
,
734 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
736 devinfo
->ctl_completed
= false;
737 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
739 brcmf_err("usb_submit_urb failed %d\n", ret
);
744 ret
= brcmf_usb_ioctl_resp_wait(devinfo
);
745 memcpy(buffer
, tmpbuf
, buflen
);
752 brcmf_usb_dlneeded(struct brcmf_usbdev_info
*devinfo
)
754 struct bootrom_id_le id
;
757 brcmf_dbg(USB
, "Enter\n");
762 /* Check if firmware downloaded already by querying runtime ID */
763 id
.chip
= cpu_to_le32(0xDEAD);
764 brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
, sizeof(id
));
766 chipid
= le32_to_cpu(id
.chip
);
767 chiprev
= le32_to_cpu(id
.chiprev
);
769 if ((chipid
& 0x4300) == 0x4300)
770 brcmf_dbg(USB
, "chip %x rev 0x%x\n", chipid
, chiprev
);
772 brcmf_dbg(USB
, "chip %d rev 0x%x\n", chipid
, chiprev
);
773 if (chipid
== BRCMF_POSTBOOT_ID
) {
774 brcmf_dbg(USB
, "firmware already downloaded\n");
775 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
, sizeof(id
));
778 devinfo
->bus_pub
.devid
= chipid
;
779 devinfo
->bus_pub
.chiprev
= chiprev
;
785 brcmf_usb_resetcfg(struct brcmf_usbdev_info
*devinfo
)
787 struct bootrom_id_le id
;
790 brcmf_dbg(USB
, "Enter\n");
794 mdelay(BRCMF_USB_RESET_GETVER_SPINWAIT
);
796 id
.chip
= cpu_to_le32(0xDEAD); /* Get the ID */
797 brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
, sizeof(id
));
798 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
))
800 } while (loop_cnt
< BRCMF_USB_RESET_GETVER_LOOP_CNT
);
802 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
)) {
803 brcmf_dbg(USB
, "postboot chip 0x%x/rev 0x%x\n",
804 le32_to_cpu(id
.chip
), le32_to_cpu(id
.chiprev
));
806 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
, sizeof(id
));
809 brcmf_err("Cannot talk to Dongle. Firmware is not UP, %d ms\n",
810 BRCMF_USB_RESET_GETVER_SPINWAIT
* loop_cnt
);
817 brcmf_usb_dl_send_bulk(struct brcmf_usbdev_info
*devinfo
, void *buffer
, int len
)
821 if ((devinfo
== NULL
) || (devinfo
->bulk_urb
== NULL
))
824 /* Prepare the URB */
825 usb_fill_bulk_urb(devinfo
->bulk_urb
, devinfo
->usbdev
,
826 devinfo
->tx_pipe
, buffer
, len
,
827 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
829 devinfo
->bulk_urb
->transfer_flags
|= URB_ZERO_PACKET
;
831 devinfo
->ctl_completed
= false;
832 ret
= usb_submit_urb(devinfo
->bulk_urb
, GFP_ATOMIC
);
834 brcmf_err("usb_submit_urb failed %d\n", ret
);
837 ret
= brcmf_usb_ioctl_resp_wait(devinfo
);
842 brcmf_usb_dl_writeimage(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int fwlen
)
844 unsigned int sendlen
, sent
, dllen
;
845 char *bulkchunk
= NULL
, *dlpos
;
846 struct rdl_state_le state
;
847 u32 rdlstate
, rdlbytes
;
850 brcmf_dbg(USB
, "Enter, fw %p, len %d\n", fw
, fwlen
);
852 bulkchunk
= kmalloc(RDL_CHUNK
, GFP_ATOMIC
);
853 if (bulkchunk
== NULL
) {
858 /* 1) Prepare USB boot loader for runtime image */
859 brcmf_usb_dl_cmd(devinfo
, DL_START
, &state
,
860 sizeof(struct rdl_state_le
));
862 rdlstate
= le32_to_cpu(state
.state
);
863 rdlbytes
= le32_to_cpu(state
.bytes
);
865 /* 2) Check we are in the Waiting state */
866 if (rdlstate
!= DL_WAITING
) {
867 brcmf_err("Failed to DL_START\n");
875 /* Get chip id and rev */
876 while (rdlbytes
!= dllen
) {
877 /* Wait until the usb device reports it received all
878 * the bytes we sent */
879 if ((rdlbytes
== sent
) && (rdlbytes
!= dllen
)) {
880 if ((dllen
-sent
) < RDL_CHUNK
)
881 sendlen
= dllen
-sent
;
885 /* simply avoid having to send a ZLP by ensuring we
893 memcpy(bulkchunk
, dlpos
, sendlen
);
894 if (brcmf_usb_dl_send_bulk(devinfo
, bulkchunk
,
896 brcmf_err("send_bulk failed\n");
904 if (!brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
,
905 sizeof(struct rdl_state_le
))) {
906 brcmf_err("DL_GETSTATE Failed xxxx\n");
911 rdlstate
= le32_to_cpu(state
.state
);
912 rdlbytes
= le32_to_cpu(state
.bytes
);
914 /* restart if an error is reported */
915 if (rdlstate
== DL_BAD_HDR
|| rdlstate
== DL_BAD_CRC
) {
916 brcmf_err("Bad Hdr or Bad CRC state %d\n",
925 brcmf_dbg(USB
, "Exit, err=%d\n", err
);
929 static int brcmf_usb_dlstart(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int len
)
933 brcmf_dbg(USB
, "Enter\n");
938 if (devinfo
->bus_pub
.devid
== 0xDEAD)
941 err
= brcmf_usb_dl_writeimage(devinfo
, fw
, len
);
943 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DL_DONE
;
945 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DL_FAIL
;
946 brcmf_dbg(USB
, "Exit, err=%d\n", err
);
951 static int brcmf_usb_dlrun(struct brcmf_usbdev_info
*devinfo
)
953 struct rdl_state_le state
;
955 brcmf_dbg(USB
, "Enter\n");
959 if (devinfo
->bus_pub
.devid
== 0xDEAD)
962 /* Check we are runnable */
963 brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
,
964 sizeof(struct rdl_state_le
));
966 /* Start the image */
967 if (state
.state
== cpu_to_le32(DL_RUNNABLE
)) {
968 if (!brcmf_usb_dl_cmd(devinfo
, DL_GO
, &state
,
969 sizeof(struct rdl_state_le
)))
971 if (brcmf_usb_resetcfg(devinfo
))
973 /* The Dongle may go for re-enumeration. */
975 brcmf_err("Dongle not runnable\n");
978 brcmf_dbg(USB
, "Exit\n");
982 static bool brcmf_usb_chip_support(int chipid
, int chiprev
)
990 return (chiprev
== 3);
1000 brcmf_usb_fw_download(struct brcmf_usbdev_info
*devinfo
)
1005 brcmf_dbg(USB
, "Enter\n");
1006 if (devinfo
== NULL
)
1009 devid
= devinfo
->bus_pub
.devid
;
1010 chiprev
= devinfo
->bus_pub
.chiprev
;
1012 if (!brcmf_usb_chip_support(devid
, chiprev
)) {
1013 brcmf_err("unsupported chip %d rev %d\n",
1018 if (!devinfo
->image
) {
1019 brcmf_err("No firmware!\n");
1023 err
= brcmf_usb_dlstart(devinfo
,
1024 devinfo
->image
, devinfo
->image_len
);
1026 err
= brcmf_usb_dlrun(devinfo
);
1031 static void brcmf_usb_detach(struct brcmf_usbdev_info
*devinfo
)
1033 brcmf_dbg(USB
, "Enter, devinfo %p\n", devinfo
);
1036 brcmf_usb_free_q(&devinfo
->rx_freeq
, false);
1037 brcmf_usb_free_q(&devinfo
->tx_freeq
, false);
1039 usb_free_urb(devinfo
->intr_urb
);
1040 usb_free_urb(devinfo
->ctl_urb
);
1041 usb_free_urb(devinfo
->bulk_urb
);
1043 kfree(devinfo
->tx_reqs
);
1044 kfree(devinfo
->rx_reqs
);
1047 #define TRX_MAGIC 0x30524448 /* "HDR0" */
1048 #define TRX_VERSION 1 /* Version 1 */
1049 #define TRX_MAX_LEN 0x3B0000 /* Max length */
1050 #define TRX_NO_HEADER 1 /* Do not write TRX header */
1051 #define TRX_MAX_OFFSET 3 /* Max number of individual files */
1052 #define TRX_UNCOMP_IMAGE 0x20 /* Trx contains uncompressed image */
1054 struct trx_header_le
{
1055 __le32 magic
; /* "HDR0" */
1056 __le32 len
; /* Length of file including header */
1057 __le32 crc32
; /* CRC from flag_version to end of file */
1058 __le32 flag_version
; /* 0:15 flags, 16:31 version */
1059 __le32 offsets
[TRX_MAX_OFFSET
]; /* Offsets of partitions from start of
1063 static int check_file(const u8
*headers
)
1065 struct trx_header_le
*trx
;
1066 int actual_len
= -1;
1068 brcmf_dbg(USB
, "Enter\n");
1069 /* Extract trx header */
1070 trx
= (struct trx_header_le
*) headers
;
1071 if (trx
->magic
!= cpu_to_le32(TRX_MAGIC
))
1074 headers
+= sizeof(struct trx_header_le
);
1076 if (le32_to_cpu(trx
->flag_version
) & TRX_UNCOMP_IMAGE
) {
1077 actual_len
= le32_to_cpu(trx
->offsets
[TRX_OFFSETS_DLFWLEN_IDX
]);
1078 return actual_len
+ sizeof(struct trx_header_le
);
1083 static int brcmf_usb_get_fw(struct brcmf_usbdev_info
*devinfo
)
1086 const struct firmware
*fw
;
1087 struct brcmf_usb_image
*fw_image
;
1090 brcmf_dbg(USB
, "Enter\n");
1091 switch (devinfo
->bus_pub
.devid
) {
1093 fwname
= BRCMF_USB_43143_FW_NAME
;
1098 fwname
= BRCMF_USB_43236_FW_NAME
;
1101 fwname
= BRCMF_USB_43242_FW_NAME
;
1107 brcmf_dbg(USB
, "Loading FW %s\n", fwname
);
1108 list_for_each_entry(fw_image
, &fw_image_list
, list
) {
1109 if (fw_image
->fwname
== fwname
) {
1110 devinfo
->image
= fw_image
->image
;
1111 devinfo
->image_len
= fw_image
->image_len
;
1115 /* fw image not yet loaded. Load it now and add to list */
1116 err
= request_firmware(&fw
, fwname
, devinfo
->dev
);
1118 brcmf_err("fail to request firmware %s\n", fwname
);
1121 if (check_file(fw
->data
) < 0) {
1122 brcmf_err("invalid firmware %s\n", fwname
);
1126 fw_image
= kzalloc(sizeof(*fw_image
), GFP_ATOMIC
);
1129 INIT_LIST_HEAD(&fw_image
->list
);
1130 list_add_tail(&fw_image
->list
, &fw_image_list
);
1131 fw_image
->fwname
= fwname
;
1132 fw_image
->image
= vmalloc(fw
->size
);
1133 if (!fw_image
->image
)
1136 memcpy(fw_image
->image
, fw
->data
, fw
->size
);
1137 fw_image
->image_len
= fw
->size
;
1139 release_firmware(fw
);
1141 devinfo
->image
= fw_image
->image
;
1142 devinfo
->image_len
= fw_image
->image_len
;
1149 struct brcmf_usbdev
*brcmf_usb_attach(struct brcmf_usbdev_info
*devinfo
,
1152 brcmf_dbg(USB
, "Enter\n");
1154 devinfo
->bus_pub
.nrxq
= nrxq
;
1155 devinfo
->rx_low_watermark
= nrxq
/ 2;
1156 devinfo
->bus_pub
.devinfo
= devinfo
;
1157 devinfo
->bus_pub
.ntxq
= ntxq
;
1158 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DOWN
;
1160 /* flow control when too many tx urbs posted */
1161 devinfo
->tx_low_watermark
= ntxq
/ 4;
1162 devinfo
->tx_high_watermark
= devinfo
->tx_low_watermark
* 3;
1163 devinfo
->bus_pub
.bus_mtu
= BRCMF_USB_MAX_PKT_SIZE
;
1165 /* Initialize other structure content */
1166 init_waitqueue_head(&devinfo
->ioctl_resp_wait
);
1168 /* Initialize the spinlocks */
1169 spin_lock_init(&devinfo
->qlock
);
1170 spin_lock_init(&devinfo
->tx_flowblock_lock
);
1172 INIT_LIST_HEAD(&devinfo
->rx_freeq
);
1173 INIT_LIST_HEAD(&devinfo
->rx_postq
);
1175 INIT_LIST_HEAD(&devinfo
->tx_freeq
);
1176 INIT_LIST_HEAD(&devinfo
->tx_postq
);
1178 devinfo
->tx_flowblock
= false;
1180 devinfo
->rx_reqs
= brcmf_usbdev_qinit(&devinfo
->rx_freeq
, nrxq
);
1181 if (!devinfo
->rx_reqs
)
1184 devinfo
->tx_reqs
= brcmf_usbdev_qinit(&devinfo
->tx_freeq
, ntxq
);
1185 if (!devinfo
->tx_reqs
)
1187 devinfo
->tx_freecount
= ntxq
;
1189 devinfo
->intr_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1190 if (!devinfo
->intr_urb
) {
1191 brcmf_err("usb_alloc_urb (intr) failed\n");
1194 devinfo
->ctl_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1195 if (!devinfo
->ctl_urb
) {
1196 brcmf_err("usb_alloc_urb (ctl) failed\n");
1199 devinfo
->bulk_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1200 if (!devinfo
->bulk_urb
) {
1201 brcmf_err("usb_alloc_urb (bulk) failed\n");
1205 if (!brcmf_usb_dlneeded(devinfo
))
1206 return &devinfo
->bus_pub
;
1208 brcmf_dbg(USB
, "Start fw downloading\n");
1209 if (brcmf_usb_get_fw(devinfo
))
1212 if (brcmf_usb_fw_download(devinfo
))
1215 return &devinfo
->bus_pub
;
1218 brcmf_err("failed!\n");
1219 brcmf_usb_detach(devinfo
);
1223 static struct brcmf_bus_ops brcmf_usb_bus_ops
= {
1224 .txdata
= brcmf_usb_tx
,
1225 .init
= brcmf_usb_up
,
1226 .stop
= brcmf_usb_down
,
1227 .txctl
= brcmf_usb_tx_ctlpkt
,
1228 .rxctl
= brcmf_usb_rx_ctlpkt
,
1231 static int brcmf_usb_probe_cb(struct brcmf_usbdev_info
*devinfo
)
1233 struct brcmf_bus
*bus
= NULL
;
1234 struct brcmf_usbdev
*bus_pub
= NULL
;
1236 struct device
*dev
= devinfo
->dev
;
1238 brcmf_dbg(USB
, "Enter\n");
1239 bus_pub
= brcmf_usb_attach(devinfo
, BRCMF_USB_NRXQ
, BRCMF_USB_NTXQ
);
1243 bus
= kzalloc(sizeof(struct brcmf_bus
), GFP_ATOMIC
);
1251 bus
->bus_priv
.usb
= bus_pub
;
1252 dev_set_drvdata(dev
, bus
);
1253 bus
->ops
= &brcmf_usb_bus_ops
;
1254 bus
->chip
= bus_pub
->devid
;
1255 bus
->chiprev
= bus_pub
->chiprev
;
1256 bus
->proto_type
= BRCMF_PROTO_BCDC
;
1258 /* Attach to the common driver interface */
1259 ret
= brcmf_attach(dev
);
1261 brcmf_err("brcmf_attach failed\n");
1265 ret
= brcmf_bus_start(dev
);
1267 brcmf_err("dongle is not responding\n");
1274 /* Release resources in reverse order */
1276 brcmf_usb_detach(devinfo
);
1281 brcmf_usb_disconnect_cb(struct brcmf_usbdev_info
*devinfo
)
1285 brcmf_dbg(USB
, "Enter, bus_pub %p\n", devinfo
);
1287 brcmf_detach(devinfo
->dev
);
1288 kfree(devinfo
->bus_pub
.bus
);
1289 brcmf_usb_detach(devinfo
);
1293 brcmf_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1296 struct usb_endpoint_descriptor
*endpoint
;
1298 struct usb_device
*usb
= interface_to_usbdev(intf
);
1301 struct brcmf_usbdev_info
*devinfo
;
1303 brcmf_dbg(USB
, "Enter\n");
1305 devinfo
= kzalloc(sizeof(*devinfo
), GFP_ATOMIC
);
1306 if (devinfo
== NULL
)
1309 devinfo
->usbdev
= usb
;
1310 devinfo
->dev
= &usb
->dev
;
1312 usb_set_intfdata(intf
, devinfo
);
1314 /* Check that the device supports only one configuration */
1315 if (usb
->descriptor
.bNumConfigurations
!= 1) {
1320 if (usb
->descriptor
.bDeviceClass
!= USB_CLASS_VENDOR_SPEC
) {
1326 * Only the BDC interface configuration is supported:
1327 * Device class: USB_CLASS_VENDOR_SPEC
1328 * if0 class: USB_CLASS_VENDOR_SPEC
1331 * if0/ep2: bulk out (ok if swapped with bulk in)
1333 if (CONFIGDESC(usb
)->bNumInterfaces
!= 1) {
1338 /* Check interface */
1339 if (IFDESC(usb
, CONTROL_IF
).bInterfaceClass
!= USB_CLASS_VENDOR_SPEC
||
1340 IFDESC(usb
, CONTROL_IF
).bInterfaceSubClass
!= 2 ||
1341 IFDESC(usb
, CONTROL_IF
).bInterfaceProtocol
!= 0xff) {
1342 brcmf_err("invalid control interface: class %d, subclass %d, proto %d\n",
1343 IFDESC(usb
, CONTROL_IF
).bInterfaceClass
,
1344 IFDESC(usb
, CONTROL_IF
).bInterfaceSubClass
,
1345 IFDESC(usb
, CONTROL_IF
).bInterfaceProtocol
);
1350 /* Check control endpoint */
1351 endpoint
= &IFEPDESC(usb
, CONTROL_IF
, 0);
1352 if ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1353 != USB_ENDPOINT_XFER_INT
) {
1354 brcmf_err("invalid control endpoint %d\n",
1355 endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
);
1360 endpoint_num
= endpoint
->bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
;
1361 devinfo
->intr_pipe
= usb_rcvintpipe(usb
, endpoint_num
);
1363 devinfo
->rx_pipe
= 0;
1364 devinfo
->rx_pipe2
= 0;
1365 devinfo
->tx_pipe
= 0;
1366 num_of_eps
= IFDESC(usb
, BULK_IF
).bNumEndpoints
- 1;
1368 /* Check data endpoints and get pipes */
1369 for (ep
= 1; ep
<= num_of_eps
; ep
++) {
1370 endpoint
= &IFEPDESC(usb
, BULK_IF
, ep
);
1371 if ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) !=
1372 USB_ENDPOINT_XFER_BULK
) {
1373 brcmf_err("invalid data endpoint %d\n", ep
);
1378 endpoint_num
= endpoint
->bEndpointAddress
&
1379 USB_ENDPOINT_NUMBER_MASK
;
1380 if ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1382 if (!devinfo
->rx_pipe
) {
1384 usb_rcvbulkpipe(usb
, endpoint_num
);
1387 usb_rcvbulkpipe(usb
, endpoint_num
);
1390 devinfo
->tx_pipe
= usb_sndbulkpipe(usb
, endpoint_num
);
1394 /* Allocate interrupt URB and data buffer */
1395 /* RNDIS says 8-byte intr, our old drivers used 4-byte */
1396 if (IFEPDESC(usb
, CONTROL_IF
, 0).wMaxPacketSize
== cpu_to_le16(16))
1397 devinfo
->intr_size
= 8;
1399 devinfo
->intr_size
= 4;
1401 devinfo
->interval
= IFEPDESC(usb
, CONTROL_IF
, 0).bInterval
;
1403 if (usb
->speed
== USB_SPEED_HIGH
)
1404 brcmf_dbg(USB
, "Broadcom high speed USB wireless device detected\n");
1406 brcmf_dbg(USB
, "Broadcom full speed USB wireless device detected\n");
1408 ret
= brcmf_usb_probe_cb(devinfo
);
1416 brcmf_err("failed with errno %d\n", ret
);
1418 usb_set_intfdata(intf
, NULL
);
1424 brcmf_usb_disconnect(struct usb_interface
*intf
)
1426 struct brcmf_usbdev_info
*devinfo
;
1428 brcmf_dbg(USB
, "Enter\n");
1429 devinfo
= (struct brcmf_usbdev_info
*)usb_get_intfdata(intf
);
1430 brcmf_usb_disconnect_cb(devinfo
);
1432 brcmf_dbg(USB
, "Exit\n");
1436 * only need to signal the bus being down and update the state.
1438 static int brcmf_usb_suspend(struct usb_interface
*intf
, pm_message_t state
)
1440 struct usb_device
*usb
= interface_to_usbdev(intf
);
1441 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1443 brcmf_dbg(USB
, "Enter\n");
1444 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_SLEEP
;
1445 brcmf_detach(&usb
->dev
);
1450 * (re-) start the bus.
1452 static int brcmf_usb_resume(struct usb_interface
*intf
)
1454 struct usb_device
*usb
= interface_to_usbdev(intf
);
1455 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1457 brcmf_dbg(USB
, "Enter\n");
1458 if (!brcmf_attach(devinfo
->dev
))
1459 return brcmf_bus_start(&usb
->dev
);
1464 static int brcmf_usb_reset_resume(struct usb_interface
*intf
)
1466 struct usb_device
*usb
= interface_to_usbdev(intf
);
1467 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1469 brcmf_dbg(USB
, "Enter\n");
1471 if (!brcmf_usb_fw_download(devinfo
))
1472 return brcmf_usb_resume(intf
);
1477 #define BRCMF_USB_VENDOR_ID_BROADCOM 0x0a5c
1478 #define BRCMF_USB_DEVICE_ID_43143 0xbd1e
1479 #define BRCMF_USB_DEVICE_ID_43236 0xbd17
1480 #define BRCMF_USB_DEVICE_ID_43242 0xbd1f
1481 #define BRCMF_USB_DEVICE_ID_BCMFW 0x0bdc
1483 static struct usb_device_id brcmf_usb_devid_table
[] = {
1484 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43143
) },
1485 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43236
) },
1486 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43242
) },
1487 /* special entry for device with firmware loaded and running */
1488 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_BCMFW
) },
1492 MODULE_DEVICE_TABLE(usb
, brcmf_usb_devid_table
);
1493 MODULE_FIRMWARE(BRCMF_USB_43143_FW_NAME
);
1494 MODULE_FIRMWARE(BRCMF_USB_43236_FW_NAME
);
1495 MODULE_FIRMWARE(BRCMF_USB_43242_FW_NAME
);
1497 static struct usb_driver brcmf_usbdrvr
= {
1498 .name
= KBUILD_MODNAME
,
1499 .probe
= brcmf_usb_probe
,
1500 .disconnect
= brcmf_usb_disconnect
,
1501 .id_table
= brcmf_usb_devid_table
,
1502 .suspend
= brcmf_usb_suspend
,
1503 .resume
= brcmf_usb_resume
,
1504 .reset_resume
= brcmf_usb_reset_resume
,
1505 .supports_autosuspend
= 1,
1506 .disable_hub_initiated_lpm
= 1,
1509 static void brcmf_release_fw(struct list_head
*q
)
1511 struct brcmf_usb_image
*fw_image
, *next
;
1513 list_for_each_entry_safe(fw_image
, next
, q
, list
) {
1514 vfree(fw_image
->image
);
1515 list_del_init(&fw_image
->list
);
1519 static int brcmf_usb_reset_device(struct device
*dev
, void *notused
)
1521 /* device past is the usb interface so we
1522 * need to use parent here.
1524 brcmf_dev_reset(dev
->parent
);
1528 void brcmf_usb_exit(void)
1530 struct device_driver
*drv
= &brcmf_usbdrvr
.drvwrap
.driver
;
1533 brcmf_dbg(USB
, "Enter\n");
1534 ret
= driver_for_each_device(drv
, NULL
, NULL
,
1535 brcmf_usb_reset_device
);
1536 usb_deregister(&brcmf_usbdrvr
);
1537 brcmf_release_fw(&fw_image_list
);
1540 void brcmf_usb_register(void)
1542 brcmf_dbg(USB
, "Enter\n");
1543 INIT_LIST_HEAD(&fw_image_list
);
1544 usb_register(&brcmf_usbdrvr
);