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
;
86 struct brcmf_usbreq
*tx_reqs
;
87 struct brcmf_usbreq
*rx_reqs
;
89 u8
*image
; /* buffer for combine fw and nvram */
92 struct usb_device
*usbdev
;
95 int ctl_in_pipe
, ctl_out_pipe
;
96 struct urb
*ctl_urb
; /* URB for control endpoint */
97 struct usb_ctrlrequest ctl_write
;
98 struct usb_ctrlrequest ctl_read
;
99 u32 ctl_urb_actual_length
;
102 wait_queue_head_t ioctl_resp_wait
;
105 struct urb
*bulk_urb
; /* used for FW download */
106 struct urb
*intr_urb
; /* URB for interrupt endpoint */
107 int intr_size
; /* Size of interrupt message */
108 int interval
; /* Interrupt polling interval */
109 struct intr_transfer_buf intr
; /* Data buffer for interrupt endpoint */
112 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
113 struct brcmf_usbreq
*req
);
115 MODULE_AUTHOR("Broadcom Corporation");
116 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac usb driver.");
117 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac usb cards");
118 MODULE_LICENSE("Dual BSD/GPL");
120 static struct brcmf_usbdev
*brcmf_usb_get_buspub(struct device
*dev
)
122 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
123 return bus_if
->bus_priv
.usb
;
126 static struct brcmf_usbdev_info
*brcmf_usb_get_businfo(struct device
*dev
)
128 return brcmf_usb_get_buspub(dev
)->devinfo
;
131 static int brcmf_usb_ioctl_resp_wait(struct brcmf_usbdev_info
*devinfo
)
133 return wait_event_timeout(devinfo
->ioctl_resp_wait
,
134 devinfo
->ctl_completed
,
135 msecs_to_jiffies(IOCTL_RESP_TIMEOUT
));
138 static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info
*devinfo
)
140 if (waitqueue_active(&devinfo
->ioctl_resp_wait
))
141 wake_up(&devinfo
->ioctl_resp_wait
);
145 brcmf_usb_ctl_complete(struct brcmf_usbdev_info
*devinfo
, int type
, int status
)
147 brcmf_dbg(USB
, "Enter, status=%d\n", status
);
149 if (unlikely(devinfo
== NULL
))
152 if (type
== BRCMF_USB_CBCTL_READ
) {
154 devinfo
->bus_pub
.stats
.rx_ctlpkts
++;
156 devinfo
->bus_pub
.stats
.rx_ctlerrs
++;
157 } else if (type
== BRCMF_USB_CBCTL_WRITE
) {
159 devinfo
->bus_pub
.stats
.tx_ctlpkts
++;
161 devinfo
->bus_pub
.stats
.tx_ctlerrs
++;
164 devinfo
->ctl_urb_status
= status
;
165 devinfo
->ctl_completed
= true;
166 brcmf_usb_ioctl_resp_wake(devinfo
);
170 brcmf_usb_ctlread_complete(struct urb
*urb
)
172 struct brcmf_usbdev_info
*devinfo
=
173 (struct brcmf_usbdev_info
*)urb
->context
;
175 brcmf_dbg(USB
, "Enter\n");
176 devinfo
->ctl_urb_actual_length
= urb
->actual_length
;
177 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_READ
,
182 brcmf_usb_ctlwrite_complete(struct urb
*urb
)
184 struct brcmf_usbdev_info
*devinfo
=
185 (struct brcmf_usbdev_info
*)urb
->context
;
187 brcmf_dbg(USB
, "Enter\n");
188 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_WRITE
,
193 brcmf_usb_send_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
198 brcmf_dbg(USB
, "Enter\n");
199 if (devinfo
== NULL
|| buf
== NULL
||
200 len
== 0 || devinfo
->ctl_urb
== NULL
)
204 devinfo
->ctl_write
.wLength
= cpu_to_le16p(&size
);
205 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
206 devinfo
->ctl_urb_status
= 0;
207 devinfo
->ctl_urb_actual_length
= 0;
209 usb_fill_control_urb(devinfo
->ctl_urb
,
211 devinfo
->ctl_out_pipe
,
212 (unsigned char *) &devinfo
->ctl_write
,
214 (usb_complete_t
)brcmf_usb_ctlwrite_complete
,
217 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
219 brcmf_err("usb_submit_urb failed %d\n", ret
);
225 brcmf_usb_recv_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
230 brcmf_dbg(USB
, "Enter\n");
231 if ((devinfo
== NULL
) || (buf
== NULL
) || (len
== 0)
232 || (devinfo
->ctl_urb
== NULL
))
236 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
237 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
239 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
240 | USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
241 devinfo
->ctl_read
.bRequest
= 1;
243 usb_fill_control_urb(devinfo
->ctl_urb
,
245 devinfo
->ctl_in_pipe
,
246 (unsigned char *) &devinfo
->ctl_read
,
248 (usb_complete_t
)brcmf_usb_ctlread_complete
,
251 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
253 brcmf_err("usb_submit_urb failed %d\n", ret
);
258 static int brcmf_usb_tx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
262 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
264 brcmf_dbg(USB
, "Enter\n");
265 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
)
268 if (test_and_set_bit(0, &devinfo
->ctl_op
))
271 devinfo
->ctl_completed
= false;
272 err
= brcmf_usb_send_ctl(devinfo
, buf
, len
);
274 brcmf_err("fail %d bytes: %d\n", err
, len
);
275 clear_bit(0, &devinfo
->ctl_op
);
278 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
279 clear_bit(0, &devinfo
->ctl_op
);
281 brcmf_err("Txctl wait timed out\n");
287 static int brcmf_usb_rx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
291 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
293 brcmf_dbg(USB
, "Enter\n");
294 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
)
297 if (test_and_set_bit(0, &devinfo
->ctl_op
))
300 devinfo
->ctl_completed
= false;
301 err
= brcmf_usb_recv_ctl(devinfo
, buf
, len
);
303 brcmf_err("fail %d bytes: %d\n", err
, len
);
304 clear_bit(0, &devinfo
->ctl_op
);
307 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
308 err
= devinfo
->ctl_urb_status
;
309 clear_bit(0, &devinfo
->ctl_op
);
311 brcmf_err("rxctl wait timed out\n");
315 return devinfo
->ctl_urb_actual_length
;
320 static struct brcmf_usbreq
*brcmf_usb_deq(struct brcmf_usbdev_info
*devinfo
,
321 struct list_head
*q
, int *counter
)
324 struct brcmf_usbreq
*req
;
325 spin_lock_irqsave(&devinfo
->qlock
, flags
);
327 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
330 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
331 list_del_init(q
->next
);
334 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
339 static void brcmf_usb_enq(struct brcmf_usbdev_info
*devinfo
,
340 struct list_head
*q
, struct brcmf_usbreq
*req
,
344 spin_lock_irqsave(&devinfo
->qlock
, flags
);
345 list_add_tail(&req
->list
, q
);
348 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
351 static struct brcmf_usbreq
*
352 brcmf_usbdev_qinit(struct list_head
*q
, int qsize
)
355 struct brcmf_usbreq
*req
, *reqs
;
357 reqs
= kcalloc(qsize
, sizeof(struct brcmf_usbreq
), GFP_ATOMIC
);
363 for (i
= 0; i
< qsize
; i
++) {
364 req
->urb
= usb_alloc_urb(0, GFP_ATOMIC
);
368 INIT_LIST_HEAD(&req
->list
);
369 list_add_tail(&req
->list
, q
);
374 brcmf_err("fail!\n");
375 while (!list_empty(q
)) {
376 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
378 usb_free_urb(req
->urb
);
385 static void brcmf_usb_free_q(struct list_head
*q
, bool pending
)
387 struct brcmf_usbreq
*req
, *next
;
389 list_for_each_entry_safe(req
, next
, q
, list
) {
391 brcmf_err("bad req\n");
396 usb_kill_urb(req
->urb
);
398 usb_free_urb(req
->urb
);
399 list_del_init(&req
->list
);
404 static void brcmf_usb_del_fromq(struct brcmf_usbdev_info
*devinfo
,
405 struct brcmf_usbreq
*req
)
409 spin_lock_irqsave(&devinfo
->qlock
, flags
);
410 list_del_init(&req
->list
);
411 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
415 static void brcmf_usb_tx_complete(struct urb
*urb
)
417 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
418 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
420 brcmf_dbg(USB
, "Enter, urb->status=%d, skb=%p\n", urb
->status
,
422 brcmf_usb_del_fromq(devinfo
, req
);
423 if (urb
->status
== 0)
424 devinfo
->bus_pub
.bus
->dstats
.tx_packets
++;
426 devinfo
->bus_pub
.bus
->dstats
.tx_errors
++;
428 brcmf_txcomplete(devinfo
->dev
, req
->skb
, urb
->status
== 0);
430 brcmu_pkt_buf_free_skb(req
->skb
);
432 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
, &devinfo
->tx_freecount
);
433 if (devinfo
->tx_freecount
> devinfo
->tx_high_watermark
&&
434 devinfo
->tx_flowblock
) {
435 brcmf_txflowblock(devinfo
->dev
, false);
436 devinfo
->tx_flowblock
= false;
440 static void brcmf_usb_rx_complete(struct urb
*urb
)
442 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
443 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
445 struct sk_buff_head skbq
;
447 brcmf_dbg(USB
, "Enter, urb->status=%d\n", urb
->status
);
448 brcmf_usb_del_fromq(devinfo
, req
);
452 /* zero lenght packets indicate usb "failure". Do not refill */
453 if (urb
->status
== 0 && urb
->actual_length
) {
454 devinfo
->bus_pub
.bus
->dstats
.rx_packets
++;
456 devinfo
->bus_pub
.bus
->dstats
.rx_errors
++;
457 brcmu_pkt_buf_free_skb(skb
);
458 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
462 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
) {
463 skb_queue_head_init(&skbq
);
464 skb_queue_tail(&skbq
, skb
);
465 skb_put(skb
, urb
->actual_length
);
466 brcmf_rx_frames(devinfo
->dev
, &skbq
);
467 brcmf_usb_rx_refill(devinfo
, req
);
469 brcmu_pkt_buf_free_skb(skb
);
470 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
476 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
477 struct brcmf_usbreq
*req
)
482 if (!req
|| !devinfo
)
485 skb
= dev_alloc_skb(devinfo
->bus_pub
.bus_mtu
);
487 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
492 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->rx_pipe
,
493 skb
->data
, skb_tailroom(skb
), brcmf_usb_rx_complete
,
495 req
->devinfo
= devinfo
;
496 brcmf_usb_enq(devinfo
, &devinfo
->rx_postq
, req
, NULL
);
498 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
500 brcmf_usb_del_fromq(devinfo
, req
);
501 brcmu_pkt_buf_free_skb(req
->skb
);
503 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
508 static void brcmf_usb_rx_fill_all(struct brcmf_usbdev_info
*devinfo
)
510 struct brcmf_usbreq
*req
;
512 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
513 brcmf_err("bus is not up=%d\n", devinfo
->bus_pub
.state
);
516 while ((req
= brcmf_usb_deq(devinfo
, &devinfo
->rx_freeq
, NULL
)) != NULL
)
517 brcmf_usb_rx_refill(devinfo
, req
);
521 brcmf_usb_state_change(struct brcmf_usbdev_info
*devinfo
, int state
)
523 struct brcmf_bus
*bcmf_bus
= devinfo
->bus_pub
.bus
;
526 brcmf_dbg(USB
, "Enter, current state=%d, new state=%d\n",
527 devinfo
->bus_pub
.state
, state
);
529 if (devinfo
->bus_pub
.state
== state
)
532 old_state
= devinfo
->bus_pub
.state
;
533 devinfo
->bus_pub
.state
= state
;
535 /* update state of upper layer */
536 if (state
== BRCMFMAC_USB_STATE_DOWN
) {
537 brcmf_dbg(USB
, "DBUS is down\n");
538 bcmf_bus
->state
= BRCMF_BUS_DOWN
;
539 } else if (state
== BRCMFMAC_USB_STATE_UP
) {
540 brcmf_dbg(USB
, "DBUS is up\n");
541 bcmf_bus
->state
= BRCMF_BUS_DATA
;
543 brcmf_dbg(USB
, "DBUS current state=%d\n", state
);
548 brcmf_usb_intr_complete(struct urb
*urb
)
550 struct brcmf_usbdev_info
*devinfo
=
551 (struct brcmf_usbdev_info
*)urb
->context
;
554 brcmf_dbg(USB
, "Enter, urb->status=%d\n", urb
->status
);
559 if (unlikely(urb
->status
)) {
560 if (urb
->status
== -ENOENT
||
561 urb
->status
== -ESHUTDOWN
||
562 urb
->status
== -ENODEV
) {
563 brcmf_usb_state_change(devinfo
,
564 BRCMFMAC_USB_STATE_DOWN
);
568 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_DOWN
) {
569 brcmf_err("intr cb when DBUS down, ignoring\n");
573 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
) {
574 err
= usb_submit_urb(devinfo
->intr_urb
, GFP_ATOMIC
);
576 brcmf_err("usb_submit_urb, err=%d\n", err
);
580 static int brcmf_usb_tx(struct device
*dev
, struct sk_buff
*skb
)
582 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
583 struct brcmf_usbreq
*req
;
586 brcmf_dbg(USB
, "Enter, skb=%p\n", skb
);
587 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
)
590 req
= brcmf_usb_deq(devinfo
, &devinfo
->tx_freeq
,
591 &devinfo
->tx_freecount
);
593 brcmu_pkt_buf_free_skb(skb
);
594 brcmf_err("no req to send\n");
599 req
->devinfo
= devinfo
;
600 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->tx_pipe
,
601 skb
->data
, skb
->len
, brcmf_usb_tx_complete
, req
);
602 req
->urb
->transfer_flags
|= URB_ZERO_PACKET
;
603 brcmf_usb_enq(devinfo
, &devinfo
->tx_postq
, req
, NULL
);
604 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
606 brcmf_err("brcmf_usb_tx usb_submit_urb FAILED\n");
607 brcmf_usb_del_fromq(devinfo
, req
);
608 brcmu_pkt_buf_free_skb(req
->skb
);
610 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
,
611 &devinfo
->tx_freecount
);
613 if (devinfo
->tx_freecount
< devinfo
->tx_low_watermark
&&
614 !devinfo
->tx_flowblock
) {
615 brcmf_txflowblock(dev
, true);
616 devinfo
->tx_flowblock
= true;
624 static int brcmf_usb_up(struct device
*dev
)
626 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
630 brcmf_dbg(USB
, "Enter\n");
631 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
)
634 /* Success, indicate devinfo is fully up */
635 brcmf_usb_state_change(devinfo
, BRCMFMAC_USB_STATE_UP
);
637 if (devinfo
->intr_urb
) {
638 usb_fill_int_urb(devinfo
->intr_urb
, devinfo
->usbdev
,
642 (usb_complete_t
)brcmf_usb_intr_complete
,
646 ret
= usb_submit_urb(devinfo
->intr_urb
, GFP_ATOMIC
);
648 brcmf_err("USB_SUBMIT_URB failed with status %d\n",
654 if (devinfo
->ctl_urb
) {
655 devinfo
->ctl_in_pipe
= usb_rcvctrlpipe(devinfo
->usbdev
, 0);
656 devinfo
->ctl_out_pipe
= usb_sndctrlpipe(devinfo
->usbdev
, 0);
658 ifnum
= IFDESC(devinfo
->usbdev
, CONTROL_IF
).bInterfaceNumber
;
661 devinfo
->ctl_write
.bRequestType
=
662 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
663 devinfo
->ctl_write
.bRequest
= 0;
664 devinfo
->ctl_write
.wValue
= cpu_to_le16(0);
665 devinfo
->ctl_write
.wIndex
= cpu_to_le16p(&ifnum
);
668 devinfo
->ctl_read
.bRequestType
=
669 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
670 devinfo
->ctl_read
.bRequest
= 1;
671 devinfo
->ctl_read
.wValue
= cpu_to_le16(0);
672 devinfo
->ctl_read
.wIndex
= cpu_to_le16p(&ifnum
);
674 brcmf_usb_rx_fill_all(devinfo
);
678 static void brcmf_usb_down(struct device
*dev
)
680 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
682 brcmf_dbg(USB
, "Enter\n");
686 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_DOWN
)
689 brcmf_usb_state_change(devinfo
, BRCMFMAC_USB_STATE_DOWN
);
690 if (devinfo
->intr_urb
)
691 usb_kill_urb(devinfo
->intr_urb
);
693 if (devinfo
->ctl_urb
)
694 usb_kill_urb(devinfo
->ctl_urb
);
696 if (devinfo
->bulk_urb
)
697 usb_kill_urb(devinfo
->bulk_urb
);
698 brcmf_usb_free_q(&devinfo
->tx_postq
, true);
700 brcmf_usb_free_q(&devinfo
->rx_postq
, true);
704 brcmf_usb_sync_complete(struct urb
*urb
)
706 struct brcmf_usbdev_info
*devinfo
=
707 (struct brcmf_usbdev_info
*)urb
->context
;
709 devinfo
->ctl_completed
= true;
710 brcmf_usb_ioctl_resp_wake(devinfo
);
713 static bool brcmf_usb_dl_cmd(struct brcmf_usbdev_info
*devinfo
, u8 cmd
,
714 void *buffer
, int buflen
)
720 if ((!devinfo
) || (devinfo
->ctl_urb
== NULL
))
723 tmpbuf
= kmalloc(buflen
, GFP_ATOMIC
);
728 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
730 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
731 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
| USB_TYPE_VENDOR
|
733 devinfo
->ctl_read
.bRequest
= cmd
;
735 usb_fill_control_urb(devinfo
->ctl_urb
,
737 usb_rcvctrlpipe(devinfo
->usbdev
, 0),
738 (unsigned char *) &devinfo
->ctl_read
,
739 (void *) tmpbuf
, size
,
740 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
742 devinfo
->ctl_completed
= false;
743 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
745 brcmf_err("usb_submit_urb failed %d\n", ret
);
750 ret
= brcmf_usb_ioctl_resp_wait(devinfo
);
751 memcpy(buffer
, tmpbuf
, buflen
);
758 brcmf_usb_dlneeded(struct brcmf_usbdev_info
*devinfo
)
760 struct bootrom_id_le id
;
763 brcmf_dbg(USB
, "Enter\n");
768 /* Check if firmware downloaded already by querying runtime ID */
769 id
.chip
= cpu_to_le32(0xDEAD);
770 brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
, sizeof(id
));
772 chipid
= le32_to_cpu(id
.chip
);
773 chiprev
= le32_to_cpu(id
.chiprev
);
775 if ((chipid
& 0x4300) == 0x4300)
776 brcmf_dbg(USB
, "chip %x rev 0x%x\n", chipid
, chiprev
);
778 brcmf_dbg(USB
, "chip %d rev 0x%x\n", chipid
, chiprev
);
779 if (chipid
== BRCMF_POSTBOOT_ID
) {
780 brcmf_dbg(USB
, "firmware already downloaded\n");
781 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
, sizeof(id
));
784 devinfo
->bus_pub
.devid
= chipid
;
785 devinfo
->bus_pub
.chiprev
= chiprev
;
791 brcmf_usb_resetcfg(struct brcmf_usbdev_info
*devinfo
)
793 struct bootrom_id_le id
;
796 brcmf_dbg(USB
, "Enter\n");
800 mdelay(BRCMF_USB_RESET_GETVER_SPINWAIT
);
802 id
.chip
= cpu_to_le32(0xDEAD); /* Get the ID */
803 brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
, sizeof(id
));
804 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
))
806 } while (loop_cnt
< BRCMF_USB_RESET_GETVER_LOOP_CNT
);
808 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
)) {
809 brcmf_dbg(USB
, "postboot chip 0x%x/rev 0x%x\n",
810 le32_to_cpu(id
.chip
), le32_to_cpu(id
.chiprev
));
812 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
, sizeof(id
));
815 brcmf_err("Cannot talk to Dongle. Firmware is not UP, %d ms\n",
816 BRCMF_USB_RESET_GETVER_SPINWAIT
* loop_cnt
);
823 brcmf_usb_dl_send_bulk(struct brcmf_usbdev_info
*devinfo
, void *buffer
, int len
)
827 if ((devinfo
== NULL
) || (devinfo
->bulk_urb
== NULL
))
830 /* Prepare the URB */
831 usb_fill_bulk_urb(devinfo
->bulk_urb
, devinfo
->usbdev
,
832 devinfo
->tx_pipe
, buffer
, len
,
833 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
835 devinfo
->bulk_urb
->transfer_flags
|= URB_ZERO_PACKET
;
837 devinfo
->ctl_completed
= false;
838 ret
= usb_submit_urb(devinfo
->bulk_urb
, GFP_ATOMIC
);
840 brcmf_err("usb_submit_urb failed %d\n", ret
);
843 ret
= brcmf_usb_ioctl_resp_wait(devinfo
);
848 brcmf_usb_dl_writeimage(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int fwlen
)
850 unsigned int sendlen
, sent
, dllen
;
851 char *bulkchunk
= NULL
, *dlpos
;
852 struct rdl_state_le state
;
853 u32 rdlstate
, rdlbytes
;
856 brcmf_dbg(USB
, "Enter, fw %p, len %d\n", fw
, fwlen
);
858 bulkchunk
= kmalloc(RDL_CHUNK
, GFP_ATOMIC
);
859 if (bulkchunk
== NULL
) {
864 /* 1) Prepare USB boot loader for runtime image */
865 brcmf_usb_dl_cmd(devinfo
, DL_START
, &state
,
866 sizeof(struct rdl_state_le
));
868 rdlstate
= le32_to_cpu(state
.state
);
869 rdlbytes
= le32_to_cpu(state
.bytes
);
871 /* 2) Check we are in the Waiting state */
872 if (rdlstate
!= DL_WAITING
) {
873 brcmf_err("Failed to DL_START\n");
881 /* Get chip id and rev */
882 while (rdlbytes
!= dllen
) {
883 /* Wait until the usb device reports it received all
884 * the bytes we sent */
885 if ((rdlbytes
== sent
) && (rdlbytes
!= dllen
)) {
886 if ((dllen
-sent
) < RDL_CHUNK
)
887 sendlen
= dllen
-sent
;
891 /* simply avoid having to send a ZLP by ensuring we
899 memcpy(bulkchunk
, dlpos
, sendlen
);
900 if (brcmf_usb_dl_send_bulk(devinfo
, bulkchunk
,
902 brcmf_err("send_bulk failed\n");
910 if (!brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
,
911 sizeof(struct rdl_state_le
))) {
912 brcmf_err("DL_GETSTATE Failed xxxx\n");
917 rdlstate
= le32_to_cpu(state
.state
);
918 rdlbytes
= le32_to_cpu(state
.bytes
);
920 /* restart if an error is reported */
921 if (rdlstate
== DL_BAD_HDR
|| rdlstate
== DL_BAD_CRC
) {
922 brcmf_err("Bad Hdr or Bad CRC state %d\n",
931 brcmf_dbg(USB
, "Exit, err=%d\n", err
);
935 static int brcmf_usb_dlstart(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int len
)
939 brcmf_dbg(USB
, "Enter\n");
944 if (devinfo
->bus_pub
.devid
== 0xDEAD)
947 err
= brcmf_usb_dl_writeimage(devinfo
, fw
, len
);
949 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DL_DONE
;
951 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DL_FAIL
;
952 brcmf_dbg(USB
, "Exit, err=%d\n", err
);
957 static int brcmf_usb_dlrun(struct brcmf_usbdev_info
*devinfo
)
959 struct rdl_state_le state
;
961 brcmf_dbg(USB
, "Enter\n");
965 if (devinfo
->bus_pub
.devid
== 0xDEAD)
968 /* Check we are runnable */
969 brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
,
970 sizeof(struct rdl_state_le
));
972 /* Start the image */
973 if (state
.state
== cpu_to_le32(DL_RUNNABLE
)) {
974 if (!brcmf_usb_dl_cmd(devinfo
, DL_GO
, &state
,
975 sizeof(struct rdl_state_le
)))
977 if (brcmf_usb_resetcfg(devinfo
))
979 /* The Dongle may go for re-enumeration. */
981 brcmf_err("Dongle not runnable\n");
984 brcmf_dbg(USB
, "Exit\n");
988 static bool brcmf_usb_chip_support(int chipid
, int chiprev
)
996 return (chiprev
== 3);
1006 brcmf_usb_fw_download(struct brcmf_usbdev_info
*devinfo
)
1011 brcmf_dbg(USB
, "Enter\n");
1012 if (devinfo
== NULL
)
1015 devid
= devinfo
->bus_pub
.devid
;
1016 chiprev
= devinfo
->bus_pub
.chiprev
;
1018 if (!brcmf_usb_chip_support(devid
, chiprev
)) {
1019 brcmf_err("unsupported chip %d rev %d\n",
1024 if (!devinfo
->image
) {
1025 brcmf_err("No firmware!\n");
1029 err
= brcmf_usb_dlstart(devinfo
,
1030 devinfo
->image
, devinfo
->image_len
);
1032 err
= brcmf_usb_dlrun(devinfo
);
1037 static void brcmf_usb_detach(struct brcmf_usbdev_info
*devinfo
)
1039 brcmf_dbg(USB
, "Enter, devinfo %p\n", devinfo
);
1042 brcmf_usb_free_q(&devinfo
->rx_freeq
, false);
1043 brcmf_usb_free_q(&devinfo
->tx_freeq
, false);
1045 usb_free_urb(devinfo
->intr_urb
);
1046 usb_free_urb(devinfo
->ctl_urb
);
1047 usb_free_urb(devinfo
->bulk_urb
);
1049 kfree(devinfo
->tx_reqs
);
1050 kfree(devinfo
->rx_reqs
);
1053 #define TRX_MAGIC 0x30524448 /* "HDR0" */
1054 #define TRX_VERSION 1 /* Version 1 */
1055 #define TRX_MAX_LEN 0x3B0000 /* Max length */
1056 #define TRX_NO_HEADER 1 /* Do not write TRX header */
1057 #define TRX_MAX_OFFSET 3 /* Max number of individual files */
1058 #define TRX_UNCOMP_IMAGE 0x20 /* Trx contains uncompressed image */
1060 struct trx_header_le
{
1061 __le32 magic
; /* "HDR0" */
1062 __le32 len
; /* Length of file including header */
1063 __le32 crc32
; /* CRC from flag_version to end of file */
1064 __le32 flag_version
; /* 0:15 flags, 16:31 version */
1065 __le32 offsets
[TRX_MAX_OFFSET
]; /* Offsets of partitions from start of
1069 static int check_file(const u8
*headers
)
1071 struct trx_header_le
*trx
;
1072 int actual_len
= -1;
1074 brcmf_dbg(USB
, "Enter\n");
1075 /* Extract trx header */
1076 trx
= (struct trx_header_le
*) headers
;
1077 if (trx
->magic
!= cpu_to_le32(TRX_MAGIC
))
1080 headers
+= sizeof(struct trx_header_le
);
1082 if (le32_to_cpu(trx
->flag_version
) & TRX_UNCOMP_IMAGE
) {
1083 actual_len
= le32_to_cpu(trx
->offsets
[TRX_OFFSETS_DLFWLEN_IDX
]);
1084 return actual_len
+ sizeof(struct trx_header_le
);
1089 static int brcmf_usb_get_fw(struct brcmf_usbdev_info
*devinfo
)
1092 const struct firmware
*fw
;
1093 struct brcmf_usb_image
*fw_image
;
1096 brcmf_dbg(USB
, "Enter\n");
1097 switch (devinfo
->bus_pub
.devid
) {
1099 fwname
= BRCMF_USB_43143_FW_NAME
;
1104 fwname
= BRCMF_USB_43236_FW_NAME
;
1107 fwname
= BRCMF_USB_43242_FW_NAME
;
1113 brcmf_dbg(USB
, "Loading FW %s\n", fwname
);
1114 list_for_each_entry(fw_image
, &fw_image_list
, list
) {
1115 if (fw_image
->fwname
== fwname
) {
1116 devinfo
->image
= fw_image
->image
;
1117 devinfo
->image_len
= fw_image
->image_len
;
1121 /* fw image not yet loaded. Load it now and add to list */
1122 err
= request_firmware(&fw
, fwname
, devinfo
->dev
);
1124 brcmf_err("fail to request firmware %s\n", fwname
);
1127 if (check_file(fw
->data
) < 0) {
1128 brcmf_err("invalid firmware %s\n", fwname
);
1132 fw_image
= kzalloc(sizeof(*fw_image
), GFP_ATOMIC
);
1135 INIT_LIST_HEAD(&fw_image
->list
);
1136 list_add_tail(&fw_image
->list
, &fw_image_list
);
1137 fw_image
->fwname
= fwname
;
1138 fw_image
->image
= vmalloc(fw
->size
);
1139 if (!fw_image
->image
)
1142 memcpy(fw_image
->image
, fw
->data
, fw
->size
);
1143 fw_image
->image_len
= fw
->size
;
1145 release_firmware(fw
);
1147 devinfo
->image
= fw_image
->image
;
1148 devinfo
->image_len
= fw_image
->image_len
;
1155 struct brcmf_usbdev
*brcmf_usb_attach(struct brcmf_usbdev_info
*devinfo
,
1158 brcmf_dbg(USB
, "Enter\n");
1160 devinfo
->bus_pub
.nrxq
= nrxq
;
1161 devinfo
->rx_low_watermark
= nrxq
/ 2;
1162 devinfo
->bus_pub
.devinfo
= devinfo
;
1163 devinfo
->bus_pub
.ntxq
= ntxq
;
1164 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DOWN
;
1166 /* flow control when too many tx urbs posted */
1167 devinfo
->tx_low_watermark
= ntxq
/ 4;
1168 devinfo
->tx_high_watermark
= devinfo
->tx_low_watermark
* 3;
1169 devinfo
->bus_pub
.bus_mtu
= BRCMF_USB_MAX_PKT_SIZE
;
1171 /* Initialize other structure content */
1172 init_waitqueue_head(&devinfo
->ioctl_resp_wait
);
1174 /* Initialize the spinlocks */
1175 spin_lock_init(&devinfo
->qlock
);
1177 INIT_LIST_HEAD(&devinfo
->rx_freeq
);
1178 INIT_LIST_HEAD(&devinfo
->rx_postq
);
1180 INIT_LIST_HEAD(&devinfo
->tx_freeq
);
1181 INIT_LIST_HEAD(&devinfo
->tx_postq
);
1183 devinfo
->tx_flowblock
= false;
1185 devinfo
->rx_reqs
= brcmf_usbdev_qinit(&devinfo
->rx_freeq
, nrxq
);
1186 if (!devinfo
->rx_reqs
)
1189 devinfo
->tx_reqs
= brcmf_usbdev_qinit(&devinfo
->tx_freeq
, ntxq
);
1190 if (!devinfo
->tx_reqs
)
1192 devinfo
->tx_freecount
= ntxq
;
1194 devinfo
->intr_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1195 if (!devinfo
->intr_urb
) {
1196 brcmf_err("usb_alloc_urb (intr) failed\n");
1199 devinfo
->ctl_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1200 if (!devinfo
->ctl_urb
) {
1201 brcmf_err("usb_alloc_urb (ctl) failed\n");
1204 devinfo
->bulk_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1205 if (!devinfo
->bulk_urb
) {
1206 brcmf_err("usb_alloc_urb (bulk) failed\n");
1210 if (!brcmf_usb_dlneeded(devinfo
))
1211 return &devinfo
->bus_pub
;
1213 brcmf_dbg(USB
, "Start fw downloading\n");
1214 if (brcmf_usb_get_fw(devinfo
))
1217 if (brcmf_usb_fw_download(devinfo
))
1220 return &devinfo
->bus_pub
;
1223 brcmf_err("failed!\n");
1224 brcmf_usb_detach(devinfo
);
1228 static struct brcmf_bus_ops brcmf_usb_bus_ops
= {
1229 .txdata
= brcmf_usb_tx
,
1230 .init
= brcmf_usb_up
,
1231 .stop
= brcmf_usb_down
,
1232 .txctl
= brcmf_usb_tx_ctlpkt
,
1233 .rxctl
= brcmf_usb_rx_ctlpkt
,
1236 static int brcmf_usb_probe_cb(struct brcmf_usbdev_info
*devinfo
)
1238 struct brcmf_bus
*bus
= NULL
;
1239 struct brcmf_usbdev
*bus_pub
= NULL
;
1241 struct device
*dev
= devinfo
->dev
;
1243 brcmf_dbg(USB
, "Enter\n");
1244 bus_pub
= brcmf_usb_attach(devinfo
, BRCMF_USB_NRXQ
, BRCMF_USB_NTXQ
);
1248 bus
= kzalloc(sizeof(struct brcmf_bus
), GFP_ATOMIC
);
1256 bus
->bus_priv
.usb
= bus_pub
;
1257 dev_set_drvdata(dev
, bus
);
1258 bus
->ops
= &brcmf_usb_bus_ops
;
1260 /* Attach to the common driver interface */
1261 ret
= brcmf_attach(0, dev
);
1263 brcmf_err("brcmf_attach failed\n");
1267 ret
= brcmf_bus_start(dev
);
1269 brcmf_err("dongle is not responding\n");
1276 /* Release resources in reverse order */
1278 brcmf_usb_detach(devinfo
);
1283 brcmf_usb_disconnect_cb(struct brcmf_usbdev_info
*devinfo
)
1287 brcmf_dbg(USB
, "Enter, bus_pub %p\n", devinfo
);
1289 brcmf_detach(devinfo
->dev
);
1290 kfree(devinfo
->bus_pub
.bus
);
1291 brcmf_usb_detach(devinfo
);
1295 brcmf_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1298 struct usb_endpoint_descriptor
*endpoint
;
1300 struct usb_device
*usb
= interface_to_usbdev(intf
);
1303 struct brcmf_usbdev_info
*devinfo
;
1305 brcmf_dbg(USB
, "Enter\n");
1307 devinfo
= kzalloc(sizeof(*devinfo
), GFP_ATOMIC
);
1308 if (devinfo
== NULL
)
1311 devinfo
->usbdev
= usb
;
1312 devinfo
->dev
= &usb
->dev
;
1314 usb_set_intfdata(intf
, devinfo
);
1316 /* Check that the device supports only one configuration */
1317 if (usb
->descriptor
.bNumConfigurations
!= 1) {
1322 if (usb
->descriptor
.bDeviceClass
!= USB_CLASS_VENDOR_SPEC
) {
1328 * Only the BDC interface configuration is supported:
1329 * Device class: USB_CLASS_VENDOR_SPEC
1330 * if0 class: USB_CLASS_VENDOR_SPEC
1333 * if0/ep2: bulk out (ok if swapped with bulk in)
1335 if (CONFIGDESC(usb
)->bNumInterfaces
!= 1) {
1340 /* Check interface */
1341 if (IFDESC(usb
, CONTROL_IF
).bInterfaceClass
!= USB_CLASS_VENDOR_SPEC
||
1342 IFDESC(usb
, CONTROL_IF
).bInterfaceSubClass
!= 2 ||
1343 IFDESC(usb
, CONTROL_IF
).bInterfaceProtocol
!= 0xff) {
1344 brcmf_err("invalid control interface: class %d, subclass %d, proto %d\n",
1345 IFDESC(usb
, CONTROL_IF
).bInterfaceClass
,
1346 IFDESC(usb
, CONTROL_IF
).bInterfaceSubClass
,
1347 IFDESC(usb
, CONTROL_IF
).bInterfaceProtocol
);
1352 /* Check control endpoint */
1353 endpoint
= &IFEPDESC(usb
, CONTROL_IF
, 0);
1354 if ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1355 != USB_ENDPOINT_XFER_INT
) {
1356 brcmf_err("invalid control endpoint %d\n",
1357 endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
);
1362 endpoint_num
= endpoint
->bEndpointAddress
& USB_ENDPOINT_NUMBER_MASK
;
1363 devinfo
->intr_pipe
= usb_rcvintpipe(usb
, endpoint_num
);
1365 devinfo
->rx_pipe
= 0;
1366 devinfo
->rx_pipe2
= 0;
1367 devinfo
->tx_pipe
= 0;
1368 num_of_eps
= IFDESC(usb
, BULK_IF
).bNumEndpoints
- 1;
1370 /* Check data endpoints and get pipes */
1371 for (ep
= 1; ep
<= num_of_eps
; ep
++) {
1372 endpoint
= &IFEPDESC(usb
, BULK_IF
, ep
);
1373 if ((endpoint
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
) !=
1374 USB_ENDPOINT_XFER_BULK
) {
1375 brcmf_err("invalid data endpoint %d\n", ep
);
1380 endpoint_num
= endpoint
->bEndpointAddress
&
1381 USB_ENDPOINT_NUMBER_MASK
;
1382 if ((endpoint
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1384 if (!devinfo
->rx_pipe
) {
1386 usb_rcvbulkpipe(usb
, endpoint_num
);
1389 usb_rcvbulkpipe(usb
, endpoint_num
);
1392 devinfo
->tx_pipe
= usb_sndbulkpipe(usb
, endpoint_num
);
1396 /* Allocate interrupt URB and data buffer */
1397 /* RNDIS says 8-byte intr, our old drivers used 4-byte */
1398 if (IFEPDESC(usb
, CONTROL_IF
, 0).wMaxPacketSize
== cpu_to_le16(16))
1399 devinfo
->intr_size
= 8;
1401 devinfo
->intr_size
= 4;
1403 devinfo
->interval
= IFEPDESC(usb
, CONTROL_IF
, 0).bInterval
;
1405 if (usb
->speed
== USB_SPEED_HIGH
)
1406 brcmf_dbg(USB
, "Broadcom high speed USB wireless device detected\n");
1408 brcmf_dbg(USB
, "Broadcom full speed USB wireless device detected\n");
1410 ret
= brcmf_usb_probe_cb(devinfo
);
1418 brcmf_err("failed with errno %d\n", ret
);
1420 usb_set_intfdata(intf
, NULL
);
1426 brcmf_usb_disconnect(struct usb_interface
*intf
)
1428 struct brcmf_usbdev_info
*devinfo
;
1430 brcmf_dbg(USB
, "Enter\n");
1431 devinfo
= (struct brcmf_usbdev_info
*)usb_get_intfdata(intf
);
1432 brcmf_usb_disconnect_cb(devinfo
);
1434 brcmf_dbg(USB
, "Exit\n");
1438 * only need to signal the bus being down and update the state.
1440 static int brcmf_usb_suspend(struct usb_interface
*intf
, pm_message_t state
)
1442 struct usb_device
*usb
= interface_to_usbdev(intf
);
1443 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1445 brcmf_dbg(USB
, "Enter\n");
1446 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_SLEEP
;
1447 brcmf_detach(&usb
->dev
);
1452 * (re-) start the bus.
1454 static int brcmf_usb_resume(struct usb_interface
*intf
)
1456 struct usb_device
*usb
= interface_to_usbdev(intf
);
1457 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1459 brcmf_dbg(USB
, "Enter\n");
1460 if (!brcmf_attach(0, devinfo
->dev
))
1461 return brcmf_bus_start(&usb
->dev
);
1466 static int brcmf_usb_reset_resume(struct usb_interface
*intf
)
1468 struct usb_device
*usb
= interface_to_usbdev(intf
);
1469 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1471 brcmf_dbg(USB
, "Enter\n");
1473 if (!brcmf_usb_fw_download(devinfo
))
1474 return brcmf_usb_resume(intf
);
1479 #define BRCMF_USB_VENDOR_ID_BROADCOM 0x0a5c
1480 #define BRCMF_USB_DEVICE_ID_43143 0xbd1e
1481 #define BRCMF_USB_DEVICE_ID_43236 0xbd17
1482 #define BRCMF_USB_DEVICE_ID_43242 0xbd1f
1483 #define BRCMF_USB_DEVICE_ID_BCMFW 0x0bdc
1485 static struct usb_device_id brcmf_usb_devid_table
[] = {
1486 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43143
) },
1487 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43236
) },
1488 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_43242
) },
1489 /* special entry for device with firmware loaded and running */
1490 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM
, BRCMF_USB_DEVICE_ID_BCMFW
) },
1493 MODULE_DEVICE_TABLE(usb
, brcmf_usb_devid_table
);
1494 MODULE_FIRMWARE(BRCMF_USB_43143_FW_NAME
);
1495 MODULE_FIRMWARE(BRCMF_USB_43236_FW_NAME
);
1496 MODULE_FIRMWARE(BRCMF_USB_43242_FW_NAME
);
1498 static struct usb_driver brcmf_usbdrvr
= {
1499 .name
= KBUILD_MODNAME
,
1500 .probe
= brcmf_usb_probe
,
1501 .disconnect
= brcmf_usb_disconnect
,
1502 .id_table
= brcmf_usb_devid_table
,
1503 .suspend
= brcmf_usb_suspend
,
1504 .resume
= brcmf_usb_resume
,
1505 .reset_resume
= brcmf_usb_reset_resume
,
1506 .supports_autosuspend
= 1,
1507 .disable_hub_initiated_lpm
= 1,
1510 static void brcmf_release_fw(struct list_head
*q
)
1512 struct brcmf_usb_image
*fw_image
, *next
;
1514 list_for_each_entry_safe(fw_image
, next
, q
, list
) {
1515 vfree(fw_image
->image
);
1516 list_del_init(&fw_image
->list
);
1520 static int brcmf_usb_reset_device(struct device
*dev
, void *notused
)
1522 /* device past is the usb interface so we
1523 * need to use parent here.
1525 brcmf_dev_reset(dev
->parent
);
1529 void brcmf_usb_exit(void)
1531 struct device_driver
*drv
= &brcmf_usbdrvr
.drvwrap
.driver
;
1534 brcmf_dbg(USB
, "Enter\n");
1535 ret
= driver_for_each_device(drv
, NULL
, NULL
,
1536 brcmf_usb_reset_device
);
1537 usb_deregister(&brcmf_usbdrvr
);
1538 brcmf_release_fw(&fw_image_list
);
1541 void brcmf_usb_init(void)
1543 brcmf_dbg(USB
, "Enter\n");
1544 INIT_LIST_HEAD(&fw_image_list
);
1545 usb_register(&brcmf_usbdrvr
);