1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2011 Broadcom Corporation
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/firmware.h>
10 #include <linux/vmalloc.h>
12 #include <brcmu_utils.h>
13 #include <brcm_hw_ids.h>
14 #include <brcmu_wifi.h>
24 #define IOCTL_RESP_TIMEOUT msecs_to_jiffies(2000)
26 #define BRCMF_USB_RESET_GETVER_SPINWAIT 100 /* in unit of ms */
27 #define BRCMF_USB_RESET_GETVER_LOOP_CNT 10
29 #define BRCMF_POSTBOOT_ID 0xA123 /* ID to detect if dongle
31 #define BRCMF_USB_NRXQ 50
32 #define BRCMF_USB_NTXQ 50
34 #define BRCMF_USB_CBCTL_WRITE 0
35 #define BRCMF_USB_CBCTL_READ 1
36 #define BRCMF_USB_MAX_PKT_SIZE 1600
38 BRCMF_FW_DEF(43143, "brcmfmac43143");
39 BRCMF_FW_DEF(43236B
, "brcmfmac43236b");
40 BRCMF_FW_DEF(43242A
, "brcmfmac43242a");
41 BRCMF_FW_DEF(43569, "brcmfmac43569");
42 BRCMF_FW_DEF(4373, "brcmfmac4373");
44 static const struct brcmf_firmware_mapping brcmf_usb_fwnames
[] = {
45 BRCMF_FW_ENTRY(BRCM_CC_43143_CHIP_ID
, 0xFFFFFFFF, 43143),
46 BRCMF_FW_ENTRY(BRCM_CC_43235_CHIP_ID
, 0x00000008, 43236B
),
47 BRCMF_FW_ENTRY(BRCM_CC_43236_CHIP_ID
, 0x00000008, 43236B
),
48 BRCMF_FW_ENTRY(BRCM_CC_43238_CHIP_ID
, 0x00000008, 43236B
),
49 BRCMF_FW_ENTRY(BRCM_CC_43242_CHIP_ID
, 0xFFFFFFFF, 43242A
),
50 BRCMF_FW_ENTRY(BRCM_CC_43566_CHIP_ID
, 0xFFFFFFFF, 43569),
51 BRCMF_FW_ENTRY(BRCM_CC_43569_CHIP_ID
, 0xFFFFFFFF, 43569),
52 BRCMF_FW_ENTRY(CY_CC_4373_CHIP_ID
, 0xFFFFFFFF, 4373)
55 #define TRX_MAGIC 0x30524448 /* "HDR0" */
56 #define TRX_MAX_OFFSET 3 /* Max number of file offsets */
57 #define TRX_UNCOMP_IMAGE 0x20 /* Trx holds uncompressed img */
58 #define TRX_RDL_CHUNK 1500 /* size of each dl transfer */
59 #define TRX_OFFSETS_DLFWLEN_IDX 0
61 /* Control messages: bRequest values */
62 #define DL_GETSTATE 0 /* returns the rdl_state_t struct */
63 #define DL_CHECK_CRC 1 /* currently unused */
64 #define DL_GO 2 /* execute downloaded image */
65 #define DL_START 3 /* initialize dl state */
66 #define DL_REBOOT 4 /* reboot the device in 2 seconds */
67 #define DL_GETVER 5 /* returns the bootrom_id_t struct */
68 #define DL_GO_PROTECTED 6 /* execute the downloaded code and set reset
69 * event to occur in 2 seconds. It is the
70 * responsibility of the downloaded code to
73 #define DL_EXEC 7 /* jump to a supplied address */
74 #define DL_RESETCFG 8 /* To support single enum on dongle
75 * - Not used by bootloader
77 #define DL_DEFER_RESP_OK 9 /* Potentially defer the response to setup
82 #define DL_WAITING 0 /* waiting to rx first pkt */
83 #define DL_READY 1 /* hdr was good, waiting for more of the
86 #define DL_BAD_HDR 2 /* hdr was corrupted */
87 #define DL_BAD_CRC 3 /* compressed image was corrupted */
88 #define DL_RUNNABLE 4 /* download was successful,waiting for go cmd */
89 #define DL_START_FAIL 5 /* failed to initialize correctly */
90 #define DL_NVRAM_TOOBIG 6 /* host specified nvram data exceeds DL_NVRAM
93 #define DL_IMAGE_TOOBIG 7 /* firmware image too big */
96 struct trx_header_le
{
97 __le32 magic
; /* "HDR0" */
98 __le32 len
; /* Length of file including header */
99 __le32 crc32
; /* CRC from flag_version to end of file */
100 __le32 flag_version
; /* 0:15 flags, 16:31 version */
101 __le32 offsets
[TRX_MAX_OFFSET
]; /* Offsets of partitions from start of
106 struct rdl_state_le
{
111 struct bootrom_id_le
{
112 __le32 chip
; /* Chip id */
113 __le32 chiprev
; /* Chip rev */
114 __le32 ramsize
; /* Size of RAM */
115 __le32 remapbase
; /* Current remap base address */
116 __le32 boardtype
; /* Type of board */
117 __le32 boardrev
; /* Board revision */
120 struct brcmf_usb_image
{
121 struct list_head list
;
127 struct brcmf_usbdev_info
{
128 struct brcmf_usbdev bus_pub
; /* MUST BE FIRST */
130 struct list_head rx_freeq
;
131 struct list_head rx_postq
;
132 struct list_head tx_freeq
;
133 struct list_head tx_postq
;
134 uint rx_pipe
, tx_pipe
;
136 int rx_low_watermark
;
137 int tx_low_watermark
;
138 int tx_high_watermark
;
141 spinlock_t tx_flowblock_lock
;
143 struct brcmf_usbreq
*tx_reqs
;
144 struct brcmf_usbreq
*rx_reqs
;
146 char fw_name
[BRCMF_FW_NAME_LEN
];
147 const u8
*image
; /* buffer for combine fw and nvram */
150 struct usb_device
*usbdev
;
152 struct completion dev_init_done
;
154 int ctl_in_pipe
, ctl_out_pipe
;
155 struct urb
*ctl_urb
; /* URB for control endpoint */
156 struct usb_ctrlrequest ctl_write
;
157 struct usb_ctrlrequest ctl_read
;
158 u32 ctl_urb_actual_length
;
161 wait_queue_head_t ioctl_resp_wait
;
165 struct urb
*bulk_urb
; /* used for FW download */
167 struct brcmf_mp_device
*settings
;
170 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
171 struct brcmf_usbreq
*req
);
173 static struct brcmf_usbdev
*brcmf_usb_get_buspub(struct device
*dev
)
175 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
176 return bus_if
->bus_priv
.usb
;
179 static struct brcmf_usbdev_info
*brcmf_usb_get_businfo(struct device
*dev
)
181 return brcmf_usb_get_buspub(dev
)->devinfo
;
184 static int brcmf_usb_ioctl_resp_wait(struct brcmf_usbdev_info
*devinfo
)
186 return wait_event_timeout(devinfo
->ioctl_resp_wait
,
187 devinfo
->ctl_completed
, IOCTL_RESP_TIMEOUT
);
190 static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info
*devinfo
)
192 wake_up(&devinfo
->ioctl_resp_wait
);
196 brcmf_usb_ctl_complete(struct brcmf_usbdev_info
*devinfo
, int type
, int status
)
198 brcmf_dbg(USB
, "Enter, status=%d\n", status
);
200 if (unlikely(devinfo
== NULL
))
203 if (type
== BRCMF_USB_CBCTL_READ
) {
205 devinfo
->bus_pub
.stats
.rx_ctlpkts
++;
207 devinfo
->bus_pub
.stats
.rx_ctlerrs
++;
208 } else if (type
== BRCMF_USB_CBCTL_WRITE
) {
210 devinfo
->bus_pub
.stats
.tx_ctlpkts
++;
212 devinfo
->bus_pub
.stats
.tx_ctlerrs
++;
215 devinfo
->ctl_urb_status
= status
;
216 devinfo
->ctl_completed
= true;
217 brcmf_usb_ioctl_resp_wake(devinfo
);
221 brcmf_usb_ctlread_complete(struct urb
*urb
)
223 struct brcmf_usbdev_info
*devinfo
=
224 (struct brcmf_usbdev_info
*)urb
->context
;
226 brcmf_dbg(USB
, "Enter\n");
227 devinfo
->ctl_urb_actual_length
= urb
->actual_length
;
228 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_READ
,
233 brcmf_usb_ctlwrite_complete(struct urb
*urb
)
235 struct brcmf_usbdev_info
*devinfo
=
236 (struct brcmf_usbdev_info
*)urb
->context
;
238 brcmf_dbg(USB
, "Enter\n");
239 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_WRITE
,
244 brcmf_usb_send_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
249 brcmf_dbg(USB
, "Enter\n");
250 if (devinfo
== NULL
|| buf
== NULL
||
251 len
== 0 || devinfo
->ctl_urb
== NULL
)
255 devinfo
->ctl_write
.wLength
= cpu_to_le16p(&size
);
256 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
257 devinfo
->ctl_urb_status
= 0;
258 devinfo
->ctl_urb_actual_length
= 0;
260 usb_fill_control_urb(devinfo
->ctl_urb
,
262 devinfo
->ctl_out_pipe
,
263 (unsigned char *) &devinfo
->ctl_write
,
265 (usb_complete_t
)brcmf_usb_ctlwrite_complete
,
268 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
270 brcmf_err("usb_submit_urb failed %d\n", ret
);
276 brcmf_usb_recv_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
281 brcmf_dbg(USB
, "Enter\n");
282 if ((devinfo
== NULL
) || (buf
== NULL
) || (len
== 0)
283 || (devinfo
->ctl_urb
== NULL
))
287 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
288 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
290 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
291 | USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
292 devinfo
->ctl_read
.bRequest
= 1;
294 usb_fill_control_urb(devinfo
->ctl_urb
,
296 devinfo
->ctl_in_pipe
,
297 (unsigned char *) &devinfo
->ctl_read
,
299 (usb_complete_t
)brcmf_usb_ctlread_complete
,
302 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
304 brcmf_err("usb_submit_urb failed %d\n", ret
);
309 static int brcmf_usb_tx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
313 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
314 struct usb_interface
*intf
= to_usb_interface(dev
);
316 brcmf_dbg(USB
, "Enter\n");
318 err
= usb_autopm_get_interface(intf
);
322 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
327 if (test_and_set_bit(0, &devinfo
->ctl_op
)) {
332 devinfo
->ctl_completed
= false;
333 err
= brcmf_usb_send_ctl(devinfo
, buf
, len
);
335 brcmf_err("fail %d bytes: %d\n", err
, len
);
336 clear_bit(0, &devinfo
->ctl_op
);
339 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
341 brcmf_err("Txctl wait timed out\n");
342 usb_kill_urb(devinfo
->ctl_urb
);
346 clear_bit(0, &devinfo
->ctl_op
);
349 usb_autopm_put_interface(intf
);
354 static int brcmf_usb_rx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
358 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
359 struct usb_interface
*intf
= to_usb_interface(dev
);
361 brcmf_dbg(USB
, "Enter\n");
363 err
= usb_autopm_get_interface(intf
);
367 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
372 if (test_and_set_bit(0, &devinfo
->ctl_op
)) {
377 devinfo
->ctl_completed
= false;
378 err
= brcmf_usb_recv_ctl(devinfo
, buf
, len
);
380 brcmf_err("fail %d bytes: %d\n", err
, len
);
381 clear_bit(0, &devinfo
->ctl_op
);
384 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
385 err
= devinfo
->ctl_urb_status
;
387 brcmf_err("rxctl wait timed out\n");
388 usb_kill_urb(devinfo
->ctl_urb
);
392 clear_bit(0, &devinfo
->ctl_op
);
394 usb_autopm_put_interface(intf
);
396 return devinfo
->ctl_urb_actual_length
;
401 static struct brcmf_usbreq
*brcmf_usb_deq(struct brcmf_usbdev_info
*devinfo
,
402 struct list_head
*q
, int *counter
)
405 struct brcmf_usbreq
*req
;
406 spin_lock_irqsave(&devinfo
->qlock
, flags
);
408 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
411 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
412 list_del_init(q
->next
);
415 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
420 static void brcmf_usb_enq(struct brcmf_usbdev_info
*devinfo
,
421 struct list_head
*q
, struct brcmf_usbreq
*req
,
425 spin_lock_irqsave(&devinfo
->qlock
, flags
);
426 list_add_tail(&req
->list
, q
);
429 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
432 static struct brcmf_usbreq
*
433 brcmf_usbdev_qinit(struct list_head
*q
, int qsize
)
436 struct brcmf_usbreq
*req
, *reqs
;
438 reqs
= kcalloc(qsize
, sizeof(struct brcmf_usbreq
), GFP_ATOMIC
);
444 for (i
= 0; i
< qsize
; i
++) {
445 req
->urb
= usb_alloc_urb(0, GFP_ATOMIC
);
449 INIT_LIST_HEAD(&req
->list
);
450 list_add_tail(&req
->list
, q
);
455 brcmf_err("fail!\n");
456 while (!list_empty(q
)) {
457 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
459 usb_free_urb(req
->urb
);
467 static void brcmf_usb_free_q(struct list_head
*q
)
469 struct brcmf_usbreq
*req
, *next
;
471 list_for_each_entry_safe(req
, next
, q
, list
) {
473 brcmf_err("bad req\n");
476 usb_free_urb(req
->urb
);
477 list_del_init(&req
->list
);
481 static void brcmf_usb_del_fromq(struct brcmf_usbdev_info
*devinfo
,
482 struct brcmf_usbreq
*req
)
486 spin_lock_irqsave(&devinfo
->qlock
, flags
);
487 list_del_init(&req
->list
);
488 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
492 static void brcmf_usb_tx_complete(struct urb
*urb
)
494 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
495 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
498 brcmf_dbg(USB
, "Enter, urb->status=%d, skb=%p\n", urb
->status
,
500 brcmf_usb_del_fromq(devinfo
, req
);
502 brcmf_proto_bcdc_txcomplete(devinfo
->dev
, req
->skb
, urb
->status
== 0);
504 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
, &devinfo
->tx_freecount
);
505 spin_lock_irqsave(&devinfo
->tx_flowblock_lock
, flags
);
506 if (devinfo
->tx_freecount
> devinfo
->tx_high_watermark
&&
507 devinfo
->tx_flowblock
) {
508 brcmf_proto_bcdc_txflowblock(devinfo
->dev
, false);
509 devinfo
->tx_flowblock
= false;
511 spin_unlock_irqrestore(&devinfo
->tx_flowblock_lock
, flags
);
514 static void brcmf_usb_rx_complete(struct urb
*urb
)
516 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
517 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
520 brcmf_dbg(USB
, "Enter, urb->status=%d\n", urb
->status
);
521 brcmf_usb_del_fromq(devinfo
, req
);
525 /* zero length packets indicate usb "failure". Do not refill */
526 if (urb
->status
!= 0 || !urb
->actual_length
) {
527 brcmu_pkt_buf_free_skb(skb
);
528 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
532 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
||
533 devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_SLEEP
) {
534 skb_put(skb
, urb
->actual_length
);
535 brcmf_rx_frame(devinfo
->dev
, skb
, true, true);
536 brcmf_usb_rx_refill(devinfo
, req
);
537 usb_mark_last_busy(urb
->dev
);
539 brcmu_pkt_buf_free_skb(skb
);
540 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
546 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
547 struct brcmf_usbreq
*req
)
552 if (!req
|| !devinfo
)
555 skb
= dev_alloc_skb(devinfo
->bus_pub
.bus_mtu
);
557 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
562 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->rx_pipe
,
563 skb
->data
, skb_tailroom(skb
), brcmf_usb_rx_complete
,
565 req
->devinfo
= devinfo
;
566 brcmf_usb_enq(devinfo
, &devinfo
->rx_postq
, req
, NULL
);
568 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
570 brcmf_usb_del_fromq(devinfo
, req
);
571 brcmu_pkt_buf_free_skb(req
->skb
);
573 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
578 static void brcmf_usb_rx_fill_all(struct brcmf_usbdev_info
*devinfo
)
580 struct brcmf_usbreq
*req
;
582 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
583 brcmf_err("bus is not up=%d\n", devinfo
->bus_pub
.state
);
586 while ((req
= brcmf_usb_deq(devinfo
, &devinfo
->rx_freeq
, NULL
)) != NULL
)
587 brcmf_usb_rx_refill(devinfo
, req
);
591 brcmf_usb_state_change(struct brcmf_usbdev_info
*devinfo
, int state
)
593 struct brcmf_bus
*bcmf_bus
= devinfo
->bus_pub
.bus
;
595 brcmf_dbg(USB
, "Enter, current state=%d, new state=%d\n",
596 devinfo
->bus_pub
.state
, state
);
598 if (devinfo
->bus_pub
.state
== state
)
601 devinfo
->bus_pub
.state
= state
;
603 /* update state of upper layer */
604 if (state
== BRCMFMAC_USB_STATE_DOWN
) {
605 brcmf_dbg(USB
, "DBUS is down\n");
606 brcmf_bus_change_state(bcmf_bus
, BRCMF_BUS_DOWN
);
607 } else if (state
== BRCMFMAC_USB_STATE_UP
) {
608 brcmf_dbg(USB
, "DBUS is up\n");
609 brcmf_bus_change_state(bcmf_bus
, BRCMF_BUS_UP
);
611 brcmf_dbg(USB
, "DBUS current state=%d\n", state
);
615 static int brcmf_usb_tx(struct device
*dev
, struct sk_buff
*skb
)
617 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
618 struct brcmf_usbreq
*req
;
621 struct usb_interface
*intf
= to_usb_interface(dev
);
623 ret
= usb_autopm_get_interface(intf
);
627 brcmf_dbg(USB
, "Enter, skb=%p\n", skb
);
628 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
633 req
= brcmf_usb_deq(devinfo
, &devinfo
->tx_freeq
,
634 &devinfo
->tx_freecount
);
636 brcmf_err("no req to send\n");
642 req
->devinfo
= devinfo
;
643 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->tx_pipe
,
644 skb
->data
, skb
->len
, brcmf_usb_tx_complete
, req
);
645 req
->urb
->transfer_flags
|= URB_ZERO_PACKET
;
646 brcmf_usb_enq(devinfo
, &devinfo
->tx_postq
, req
, NULL
);
647 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
649 brcmf_err("brcmf_usb_tx usb_submit_urb FAILED\n");
650 brcmf_usb_del_fromq(devinfo
, req
);
652 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
,
653 &devinfo
->tx_freecount
);
657 spin_lock_irqsave(&devinfo
->tx_flowblock_lock
, flags
);
658 if (devinfo
->tx_freecount
< devinfo
->tx_low_watermark
&&
659 !devinfo
->tx_flowblock
) {
660 brcmf_proto_bcdc_txflowblock(dev
, true);
661 devinfo
->tx_flowblock
= true;
663 spin_unlock_irqrestore(&devinfo
->tx_flowblock_lock
, flags
);
666 usb_autopm_put_interface(intf
);
672 static int brcmf_usb_up(struct device
*dev
)
674 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
676 brcmf_dbg(USB
, "Enter\n");
677 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
)
680 /* Success, indicate devinfo is fully up */
681 brcmf_usb_state_change(devinfo
, BRCMFMAC_USB_STATE_UP
);
683 if (devinfo
->ctl_urb
) {
684 devinfo
->ctl_in_pipe
= usb_rcvctrlpipe(devinfo
->usbdev
, 0);
685 devinfo
->ctl_out_pipe
= usb_sndctrlpipe(devinfo
->usbdev
, 0);
688 devinfo
->ctl_write
.bRequestType
=
689 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
690 devinfo
->ctl_write
.bRequest
= 0;
691 devinfo
->ctl_write
.wValue
= cpu_to_le16(0);
692 devinfo
->ctl_write
.wIndex
= cpu_to_le16(devinfo
->ifnum
);
695 devinfo
->ctl_read
.bRequestType
=
696 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
697 devinfo
->ctl_read
.bRequest
= 1;
698 devinfo
->ctl_read
.wValue
= cpu_to_le16(0);
699 devinfo
->ctl_read
.wIndex
= cpu_to_le16(devinfo
->ifnum
);
701 brcmf_usb_rx_fill_all(devinfo
);
705 static void brcmf_cancel_all_urbs(struct brcmf_usbdev_info
*devinfo
)
709 if (devinfo
->ctl_urb
)
710 usb_kill_urb(devinfo
->ctl_urb
);
711 if (devinfo
->bulk_urb
)
712 usb_kill_urb(devinfo
->bulk_urb
);
713 if (devinfo
->tx_reqs
)
714 for (i
= 0; i
< devinfo
->bus_pub
.ntxq
; i
++)
715 usb_kill_urb(devinfo
->tx_reqs
[i
].urb
);
716 if (devinfo
->rx_reqs
)
717 for (i
= 0; i
< devinfo
->bus_pub
.nrxq
; i
++)
718 usb_kill_urb(devinfo
->rx_reqs
[i
].urb
);
721 static void brcmf_usb_down(struct device
*dev
)
723 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
725 brcmf_dbg(USB
, "Enter\n");
729 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_DOWN
)
732 brcmf_usb_state_change(devinfo
, BRCMFMAC_USB_STATE_DOWN
);
734 brcmf_cancel_all_urbs(devinfo
);
738 brcmf_usb_sync_complete(struct urb
*urb
)
740 struct brcmf_usbdev_info
*devinfo
=
741 (struct brcmf_usbdev_info
*)urb
->context
;
743 devinfo
->ctl_completed
= true;
744 brcmf_usb_ioctl_resp_wake(devinfo
);
747 static int brcmf_usb_dl_cmd(struct brcmf_usbdev_info
*devinfo
, u8 cmd
,
748 void *buffer
, int buflen
)
754 if ((!devinfo
) || (devinfo
->ctl_urb
== NULL
))
757 tmpbuf
= kmalloc(buflen
, GFP_ATOMIC
);
762 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
764 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
765 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
| USB_TYPE_VENDOR
|
767 devinfo
->ctl_read
.bRequest
= cmd
;
769 usb_fill_control_urb(devinfo
->ctl_urb
,
771 usb_rcvctrlpipe(devinfo
->usbdev
, 0),
772 (unsigned char *) &devinfo
->ctl_read
,
773 (void *) tmpbuf
, size
,
774 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
776 devinfo
->ctl_completed
= false;
777 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
779 brcmf_err("usb_submit_urb failed %d\n", ret
);
783 if (!brcmf_usb_ioctl_resp_wait(devinfo
)) {
784 usb_kill_urb(devinfo
->ctl_urb
);
787 memcpy(buffer
, tmpbuf
, buflen
);
796 brcmf_usb_dlneeded(struct brcmf_usbdev_info
*devinfo
)
798 struct bootrom_id_le id
;
801 brcmf_dbg(USB
, "Enter\n");
806 /* Check if firmware downloaded already by querying runtime ID */
807 id
.chip
= cpu_to_le32(0xDEAD);
808 brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
, sizeof(id
));
810 chipid
= le32_to_cpu(id
.chip
);
811 chiprev
= le32_to_cpu(id
.chiprev
);
813 if ((chipid
& 0x4300) == 0x4300)
814 brcmf_dbg(USB
, "chip %x rev 0x%x\n", chipid
, chiprev
);
816 brcmf_dbg(USB
, "chip %d rev 0x%x\n", chipid
, chiprev
);
817 if (chipid
== BRCMF_POSTBOOT_ID
) {
818 brcmf_dbg(USB
, "firmware already downloaded\n");
819 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
, sizeof(id
));
822 devinfo
->bus_pub
.devid
= chipid
;
823 devinfo
->bus_pub
.chiprev
= chiprev
;
829 brcmf_usb_resetcfg(struct brcmf_usbdev_info
*devinfo
)
831 struct bootrom_id_le id
;
835 brcmf_dbg(USB
, "Enter\n");
839 mdelay(BRCMF_USB_RESET_GETVER_SPINWAIT
);
841 id
.chip
= cpu_to_le32(0xDEAD); /* Get the ID */
842 err
= brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
, sizeof(id
));
843 if ((err
) && (err
!= -ETIMEDOUT
))
845 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
))
847 } while (loop_cnt
< BRCMF_USB_RESET_GETVER_LOOP_CNT
);
849 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
)) {
850 brcmf_dbg(USB
, "postboot chip 0x%x/rev 0x%x\n",
851 le32_to_cpu(id
.chip
), le32_to_cpu(id
.chiprev
));
853 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
, sizeof(id
));
856 brcmf_err("Cannot talk to Dongle. Firmware is not UP, %d ms\n",
857 BRCMF_USB_RESET_GETVER_SPINWAIT
* loop_cnt
);
864 brcmf_usb_dl_send_bulk(struct brcmf_usbdev_info
*devinfo
, void *buffer
, int len
)
868 if ((devinfo
== NULL
) || (devinfo
->bulk_urb
== NULL
))
871 /* Prepare the URB */
872 usb_fill_bulk_urb(devinfo
->bulk_urb
, devinfo
->usbdev
,
873 devinfo
->tx_pipe
, buffer
, len
,
874 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
876 devinfo
->bulk_urb
->transfer_flags
|= URB_ZERO_PACKET
;
878 devinfo
->ctl_completed
= false;
879 ret
= usb_submit_urb(devinfo
->bulk_urb
, GFP_ATOMIC
);
881 brcmf_err("usb_submit_urb failed %d\n", ret
);
884 ret
= brcmf_usb_ioctl_resp_wait(devinfo
);
889 brcmf_usb_dl_writeimage(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int fwlen
)
891 unsigned int sendlen
, sent
, dllen
;
892 char *bulkchunk
= NULL
, *dlpos
;
893 struct rdl_state_le state
;
894 u32 rdlstate
, rdlbytes
;
897 brcmf_dbg(USB
, "Enter, fw %p, len %d\n", fw
, fwlen
);
899 bulkchunk
= kmalloc(TRX_RDL_CHUNK
, GFP_ATOMIC
);
900 if (bulkchunk
== NULL
) {
905 /* 1) Prepare USB boot loader for runtime image */
906 brcmf_usb_dl_cmd(devinfo
, DL_START
, &state
, sizeof(state
));
908 rdlstate
= le32_to_cpu(state
.state
);
909 rdlbytes
= le32_to_cpu(state
.bytes
);
911 /* 2) Check we are in the Waiting state */
912 if (rdlstate
!= DL_WAITING
) {
913 brcmf_err("Failed to DL_START\n");
921 /* Get chip id and rev */
922 while (rdlbytes
!= dllen
) {
923 /* Wait until the usb device reports it received all
924 * the bytes we sent */
925 if ((rdlbytes
== sent
) && (rdlbytes
!= dllen
)) {
926 if ((dllen
-sent
) < TRX_RDL_CHUNK
)
927 sendlen
= dllen
-sent
;
929 sendlen
= TRX_RDL_CHUNK
;
931 /* simply avoid having to send a ZLP by ensuring we
939 memcpy(bulkchunk
, dlpos
, sendlen
);
940 if (brcmf_usb_dl_send_bulk(devinfo
, bulkchunk
,
942 brcmf_err("send_bulk failed\n");
950 err
= brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
,
953 brcmf_err("DL_GETSTATE Failed\n");
957 rdlstate
= le32_to_cpu(state
.state
);
958 rdlbytes
= le32_to_cpu(state
.bytes
);
960 /* restart if an error is reported */
961 if (rdlstate
== DL_BAD_HDR
|| rdlstate
== DL_BAD_CRC
) {
962 brcmf_err("Bad Hdr or Bad CRC state %d\n",
971 brcmf_dbg(USB
, "Exit, err=%d\n", err
);
975 static int brcmf_usb_dlstart(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int len
)
979 brcmf_dbg(USB
, "Enter\n");
984 if (devinfo
->bus_pub
.devid
== 0xDEAD)
987 err
= brcmf_usb_dl_writeimage(devinfo
, fw
, len
);
989 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DL_DONE
;
991 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DL_FAIL
;
992 brcmf_dbg(USB
, "Exit, err=%d\n", err
);
997 static int brcmf_usb_dlrun(struct brcmf_usbdev_info
*devinfo
)
999 struct rdl_state_le state
;
1001 brcmf_dbg(USB
, "Enter\n");
1005 if (devinfo
->bus_pub
.devid
== 0xDEAD)
1008 /* Check we are runnable */
1010 brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
, sizeof(state
));
1012 /* Start the image */
1013 if (state
.state
== cpu_to_le32(DL_RUNNABLE
)) {
1014 if (brcmf_usb_dl_cmd(devinfo
, DL_GO
, &state
, sizeof(state
)))
1016 if (brcmf_usb_resetcfg(devinfo
))
1018 /* The Dongle may go for re-enumeration. */
1020 brcmf_err("Dongle not runnable\n");
1023 brcmf_dbg(USB
, "Exit\n");
1028 brcmf_usb_fw_download(struct brcmf_usbdev_info
*devinfo
)
1031 struct usb_interface
*intf
;
1033 brcmf_dbg(USB
, "Enter\n");
1039 if (!devinfo
->image
) {
1040 brcmf_err("No firmware!\n");
1045 intf
= to_usb_interface(devinfo
->dev
);
1046 err
= usb_autopm_get_interface(intf
);
1050 err
= brcmf_usb_dlstart(devinfo
,
1051 (u8
*)devinfo
->image
, devinfo
->image_len
);
1053 err
= brcmf_usb_dlrun(devinfo
);
1055 usb_autopm_put_interface(intf
);
1061 static void brcmf_usb_detach(struct brcmf_usbdev_info
*devinfo
)
1063 brcmf_dbg(USB
, "Enter, devinfo %p\n", devinfo
);
1066 brcmf_usb_free_q(&devinfo
->rx_freeq
);
1067 brcmf_usb_free_q(&devinfo
->tx_freeq
);
1069 usb_free_urb(devinfo
->ctl_urb
);
1070 usb_free_urb(devinfo
->bulk_urb
);
1072 kfree(devinfo
->tx_reqs
);
1073 kfree(devinfo
->rx_reqs
);
1075 if (devinfo
->settings
)
1076 brcmf_release_module_param(devinfo
->settings
);
1080 static int check_file(const u8
*headers
)
1082 struct trx_header_le
*trx
;
1083 int actual_len
= -1;
1085 brcmf_dbg(USB
, "Enter\n");
1086 /* Extract trx header */
1087 trx
= (struct trx_header_le
*) headers
;
1088 if (trx
->magic
!= cpu_to_le32(TRX_MAGIC
))
1091 headers
+= sizeof(struct trx_header_le
);
1093 if (le32_to_cpu(trx
->flag_version
) & TRX_UNCOMP_IMAGE
) {
1094 actual_len
= le32_to_cpu(trx
->offsets
[TRX_OFFSETS_DLFWLEN_IDX
]);
1095 return actual_len
+ sizeof(struct trx_header_le
);
1102 struct brcmf_usbdev
*brcmf_usb_attach(struct brcmf_usbdev_info
*devinfo
,
1105 brcmf_dbg(USB
, "Enter\n");
1107 devinfo
->bus_pub
.nrxq
= nrxq
;
1108 devinfo
->rx_low_watermark
= nrxq
/ 2;
1109 devinfo
->bus_pub
.devinfo
= devinfo
;
1110 devinfo
->bus_pub
.ntxq
= ntxq
;
1111 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DOWN
;
1113 /* flow control when too many tx urbs posted */
1114 devinfo
->tx_low_watermark
= ntxq
/ 4;
1115 devinfo
->tx_high_watermark
= devinfo
->tx_low_watermark
* 3;
1116 devinfo
->bus_pub
.bus_mtu
= BRCMF_USB_MAX_PKT_SIZE
;
1118 /* Initialize other structure content */
1119 init_waitqueue_head(&devinfo
->ioctl_resp_wait
);
1121 /* Initialize the spinlocks */
1122 spin_lock_init(&devinfo
->qlock
);
1123 spin_lock_init(&devinfo
->tx_flowblock_lock
);
1125 INIT_LIST_HEAD(&devinfo
->rx_freeq
);
1126 INIT_LIST_HEAD(&devinfo
->rx_postq
);
1128 INIT_LIST_HEAD(&devinfo
->tx_freeq
);
1129 INIT_LIST_HEAD(&devinfo
->tx_postq
);
1131 devinfo
->tx_flowblock
= false;
1133 devinfo
->rx_reqs
= brcmf_usbdev_qinit(&devinfo
->rx_freeq
, nrxq
);
1134 if (!devinfo
->rx_reqs
)
1137 devinfo
->tx_reqs
= brcmf_usbdev_qinit(&devinfo
->tx_freeq
, ntxq
);
1138 if (!devinfo
->tx_reqs
)
1140 devinfo
->tx_freecount
= ntxq
;
1142 devinfo
->ctl_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1143 if (!devinfo
->ctl_urb
)
1145 devinfo
->bulk_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1146 if (!devinfo
->bulk_urb
)
1149 return &devinfo
->bus_pub
;
1152 brcmf_err("failed!\n");
1153 brcmf_usb_detach(devinfo
);
1158 int brcmf_usb_get_fwname(struct device
*dev
, const char *ext
, u8
*fw_name
)
1160 struct brcmf_bus
*bus
= dev_get_drvdata(dev
);
1161 struct brcmf_fw_request
*fwreq
;
1162 struct brcmf_fw_name fwnames
[] = {
1166 fwreq
= brcmf_fw_alloc_request(bus
->chip
, bus
->chiprev
,
1168 ARRAY_SIZE(brcmf_usb_fwnames
),
1169 fwnames
, ARRAY_SIZE(fwnames
));
1177 static const struct brcmf_bus_ops brcmf_usb_bus_ops
= {
1178 .preinit
= brcmf_usb_up
,
1179 .stop
= brcmf_usb_down
,
1180 .txdata
= brcmf_usb_tx
,
1181 .txctl
= brcmf_usb_tx_ctlpkt
,
1182 .rxctl
= brcmf_usb_rx_ctlpkt
,
1183 .get_fwname
= brcmf_usb_get_fwname
,
1186 #define BRCMF_USB_FW_CODE 0
1188 static void brcmf_usb_probe_phase2(struct device
*dev
, int ret
,
1189 struct brcmf_fw_request
*fwreq
)
1191 struct brcmf_bus
*bus
= dev_get_drvdata(dev
);
1192 struct brcmf_usbdev_info
*devinfo
= bus
->bus_priv
.usb
->devinfo
;
1193 const struct firmware
*fw
;
1198 brcmf_dbg(USB
, "Start fw downloading\n");
1200 fw
= fwreq
->items
[BRCMF_USB_FW_CODE
].binary
;
1203 ret
= check_file(fw
->data
);
1205 brcmf_err("invalid firmware\n");
1206 release_firmware(fw
);
1210 devinfo
->image
= fw
->data
;
1211 devinfo
->image_len
= fw
->size
;
1213 ret
= brcmf_usb_fw_download(devinfo
);
1214 release_firmware(fw
);
1218 ret
= brcmf_alloc(devinfo
->dev
, devinfo
->settings
);
1222 /* Attach to the common driver interface */
1223 ret
= brcmf_attach(devinfo
->dev
);
1227 complete(&devinfo
->dev_init_done
);
1230 brcmf_dbg(TRACE
, "failed: dev=%s, err=%d\n", dev_name(dev
), ret
);
1231 complete(&devinfo
->dev_init_done
);
1232 device_release_driver(dev
);
1235 static struct brcmf_fw_request
*
1236 brcmf_usb_prepare_fw_request(struct brcmf_usbdev_info
*devinfo
)
1238 struct brcmf_fw_request
*fwreq
;
1239 struct brcmf_fw_name fwnames
[] = {
1240 { ".bin", devinfo
->fw_name
},
1243 fwreq
= brcmf_fw_alloc_request(devinfo
->bus_pub
.devid
,
1244 devinfo
->bus_pub
.chiprev
,
1246 ARRAY_SIZE(brcmf_usb_fwnames
),
1247 fwnames
, ARRAY_SIZE(fwnames
));
1251 fwreq
->items
[BRCMF_USB_FW_CODE
].type
= BRCMF_FW_TYPE_BINARY
;
1256 static int brcmf_usb_probe_cb(struct brcmf_usbdev_info
*devinfo
)
1258 struct brcmf_bus
*bus
= NULL
;
1259 struct brcmf_usbdev
*bus_pub
= NULL
;
1260 struct device
*dev
= devinfo
->dev
;
1261 struct brcmf_fw_request
*fwreq
;
1264 brcmf_dbg(USB
, "Enter\n");
1265 bus_pub
= brcmf_usb_attach(devinfo
, BRCMF_USB_NRXQ
, BRCMF_USB_NTXQ
);
1269 bus
= kzalloc(sizeof(struct brcmf_bus
), GFP_ATOMIC
);
1277 bus
->bus_priv
.usb
= bus_pub
;
1278 dev_set_drvdata(dev
, bus
);
1279 bus
->ops
= &brcmf_usb_bus_ops
;
1280 bus
->proto_type
= BRCMF_PROTO_BCDC
;
1281 bus
->always_use_fws_queue
= true;
1283 bus
->wowl_supported
= true;
1286 devinfo
->settings
= brcmf_get_module_param(bus
->dev
, BRCMF_BUSTYPE_USB
,
1289 if (!devinfo
->settings
) {
1294 if (!brcmf_usb_dlneeded(devinfo
)) {
1295 ret
= brcmf_alloc(devinfo
->dev
, devinfo
->settings
);
1298 ret
= brcmf_attach(devinfo
->dev
);
1302 complete(&devinfo
->dev_init_done
);
1305 bus
->chip
= bus_pub
->devid
;
1306 bus
->chiprev
= bus_pub
->chiprev
;
1308 fwreq
= brcmf_usb_prepare_fw_request(devinfo
);
1314 /* request firmware here */
1315 ret
= brcmf_fw_get_firmwares(dev
, fwreq
, brcmf_usb_probe_phase2
);
1317 brcmf_err("firmware request failed: %d\n", ret
);
1325 /* Release resources in reverse order */
1326 brcmf_free(devinfo
->dev
);
1328 brcmf_usb_detach(devinfo
);
1333 brcmf_usb_disconnect_cb(struct brcmf_usbdev_info
*devinfo
)
1337 brcmf_dbg(USB
, "Enter, bus_pub %p\n", devinfo
);
1339 brcmf_detach(devinfo
->dev
);
1340 brcmf_free(devinfo
->dev
);
1341 kfree(devinfo
->bus_pub
.bus
);
1342 brcmf_usb_detach(devinfo
);
1346 brcmf_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1348 struct usb_device
*usb
= interface_to_usbdev(intf
);
1349 struct brcmf_usbdev_info
*devinfo
;
1350 struct usb_interface_descriptor
*desc
;
1351 struct usb_endpoint_descriptor
*endpoint
;
1354 u8 endpoint_num
, ep
;
1356 brcmf_dbg(USB
, "Enter 0x%04x:0x%04x\n", id
->idVendor
, id
->idProduct
);
1358 devinfo
= kzalloc(sizeof(*devinfo
), GFP_ATOMIC
);
1359 if (devinfo
== NULL
)
1362 devinfo
->usbdev
= usb
;
1363 devinfo
->dev
= &usb
->dev
;
1364 /* Init completion, to protect for disconnect while still loading.
1365 * Necessary because of the asynchronous firmware load construction
1367 init_completion(&devinfo
->dev_init_done
);
1369 usb_set_intfdata(intf
, devinfo
);
1371 intf
->needs_remote_wakeup
= 1;
1373 /* Check that the device supports only one configuration */
1374 if (usb
->descriptor
.bNumConfigurations
!= 1) {
1375 brcmf_err("Number of configurations: %d not supported\n",
1376 usb
->descriptor
.bNumConfigurations
);
1381 if ((usb
->descriptor
.bDeviceClass
!= USB_CLASS_VENDOR_SPEC
) &&
1382 (usb
->descriptor
.bDeviceClass
!= USB_CLASS_MISC
) &&
1383 (usb
->descriptor
.bDeviceClass
!= USB_CLASS_WIRELESS_CONTROLLER
)) {
1384 brcmf_err("Device class: 0x%x not supported\n",
1385 usb
->descriptor
.bDeviceClass
);
1390 desc
= &intf
->cur_altsetting
->desc
;
1391 if ((desc
->bInterfaceClass
!= USB_CLASS_VENDOR_SPEC
) ||
1392 (desc
->bInterfaceSubClass
!= 2) ||
1393 (desc
->bInterfaceProtocol
!= 0xff)) {
1394 brcmf_err("non WLAN interface %d: 0x%x:0x%x:0x%x\n",
1395 desc
->bInterfaceNumber
, desc
->bInterfaceClass
,
1396 desc
->bInterfaceSubClass
, desc
->bInterfaceProtocol
);
1401 num_of_eps
= desc
->bNumEndpoints
;
1402 for (ep
= 0; ep
< num_of_eps
; ep
++) {
1403 endpoint
= &intf
->cur_altsetting
->endpoint
[ep
].desc
;
1404 endpoint_num
= usb_endpoint_num(endpoint
);
1405 if (!usb_endpoint_xfer_bulk(endpoint
))
1407 if (usb_endpoint_dir_in(endpoint
)) {
1408 if (!devinfo
->rx_pipe
)
1410 usb_rcvbulkpipe(usb
, endpoint_num
);
1412 if (!devinfo
->tx_pipe
)
1414 usb_sndbulkpipe(usb
, endpoint_num
);
1417 if (devinfo
->rx_pipe
== 0) {
1418 brcmf_err("No RX (in) Bulk EP found\n");
1422 if (devinfo
->tx_pipe
== 0) {
1423 brcmf_err("No TX (out) Bulk EP found\n");
1428 devinfo
->ifnum
= desc
->bInterfaceNumber
;
1430 if (usb
->speed
== USB_SPEED_SUPER_PLUS
)
1431 brcmf_dbg(USB
, "Broadcom super speed plus USB WLAN interface detected\n");
1432 else if (usb
->speed
== USB_SPEED_SUPER
)
1433 brcmf_dbg(USB
, "Broadcom super speed USB WLAN interface detected\n");
1434 else if (usb
->speed
== USB_SPEED_HIGH
)
1435 brcmf_dbg(USB
, "Broadcom high speed USB WLAN interface detected\n");
1437 brcmf_dbg(USB
, "Broadcom full speed USB WLAN interface detected\n");
1439 ret
= brcmf_usb_probe_cb(devinfo
);
1447 complete(&devinfo
->dev_init_done
);
1449 usb_set_intfdata(intf
, NULL
);
1454 brcmf_usb_disconnect(struct usb_interface
*intf
)
1456 struct brcmf_usbdev_info
*devinfo
;
1458 brcmf_dbg(USB
, "Enter\n");
1459 devinfo
= (struct brcmf_usbdev_info
*)usb_get_intfdata(intf
);
1462 wait_for_completion(&devinfo
->dev_init_done
);
1463 /* Make sure that devinfo still exists. Firmware probe routines
1464 * may have released the device and cleared the intfdata.
1466 if (!usb_get_intfdata(intf
))
1469 brcmf_usb_disconnect_cb(devinfo
);
1473 brcmf_dbg(USB
, "Exit\n");
1477 * only need to signal the bus being down and update the state.
1479 static int brcmf_usb_suspend(struct usb_interface
*intf
, pm_message_t state
)
1481 struct usb_device
*usb
= interface_to_usbdev(intf
);
1482 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1484 brcmf_dbg(USB
, "Enter\n");
1485 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_SLEEP
;
1486 brcmf_cancel_all_urbs(devinfo
);
1487 device_set_wakeup_enable(devinfo
->dev
, true);
1492 * (re-) start the bus.
1494 static int brcmf_usb_resume(struct usb_interface
*intf
)
1496 struct usb_device
*usb
= interface_to_usbdev(intf
);
1497 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1499 brcmf_dbg(USB
, "Enter\n");
1501 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_UP
;
1502 brcmf_usb_rx_fill_all(devinfo
);
1503 device_set_wakeup_enable(devinfo
->dev
, false);
1507 static int brcmf_usb_reset_resume(struct usb_interface
*intf
)
1509 struct usb_device
*usb
= interface_to_usbdev(intf
);
1510 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1511 struct brcmf_fw_request
*fwreq
;
1514 brcmf_dbg(USB
, "Enter\n");
1516 fwreq
= brcmf_usb_prepare_fw_request(devinfo
);
1520 ret
= brcmf_fw_get_firmwares(&usb
->dev
, fwreq
, brcmf_usb_probe_phase2
);
1527 #define BRCMF_USB_DEVICE(dev_id) \
1528 { USB_DEVICE(BRCM_USB_VENDOR_ID_BROADCOM, dev_id) }
1530 #define LINKSYS_USB_DEVICE(dev_id) \
1531 { USB_DEVICE(BRCM_USB_VENDOR_ID_LINKSYS, dev_id) }
1533 #define CYPRESS_USB_DEVICE(dev_id) \
1534 { USB_DEVICE(CY_USB_VENDOR_ID_CYPRESS, dev_id) }
1536 static const struct usb_device_id brcmf_usb_devid_table
[] = {
1537 BRCMF_USB_DEVICE(BRCM_USB_43143_DEVICE_ID
),
1538 BRCMF_USB_DEVICE(BRCM_USB_43236_DEVICE_ID
),
1539 BRCMF_USB_DEVICE(BRCM_USB_43242_DEVICE_ID
),
1540 BRCMF_USB_DEVICE(BRCM_USB_43569_DEVICE_ID
),
1541 LINKSYS_USB_DEVICE(BRCM_USB_43235_LINKSYS_DEVICE_ID
),
1542 CYPRESS_USB_DEVICE(CY_USB_4373_DEVICE_ID
),
1543 { USB_DEVICE(BRCM_USB_VENDOR_ID_LG
, BRCM_USB_43242_LG_DEVICE_ID
) },
1544 /* special entry for device with firmware loaded and running */
1545 BRCMF_USB_DEVICE(BRCM_USB_BCMFW_DEVICE_ID
),
1546 CYPRESS_USB_DEVICE(BRCM_USB_BCMFW_DEVICE_ID
),
1547 { /* end: all zeroes */ }
1550 MODULE_DEVICE_TABLE(usb
, brcmf_usb_devid_table
);
1552 static struct usb_driver brcmf_usbdrvr
= {
1553 .name
= KBUILD_MODNAME
,
1554 .probe
= brcmf_usb_probe
,
1555 .disconnect
= brcmf_usb_disconnect
,
1556 .id_table
= brcmf_usb_devid_table
,
1557 .suspend
= brcmf_usb_suspend
,
1558 .resume
= brcmf_usb_resume
,
1559 .reset_resume
= brcmf_usb_reset_resume
,
1560 .supports_autosuspend
= true,
1561 .disable_hub_initiated_lpm
= 1,
1564 static int brcmf_usb_reset_device(struct device
*dev
, void *notused
)
1566 /* device past is the usb interface so we
1567 * need to use parent here.
1569 brcmf_dev_reset(dev
->parent
);
1573 void brcmf_usb_exit(void)
1575 struct device_driver
*drv
= &brcmf_usbdrvr
.drvwrap
.driver
;
1578 brcmf_dbg(USB
, "Enter\n");
1579 ret
= driver_for_each_device(drv
, NULL
, NULL
,
1580 brcmf_usb_reset_device
);
1582 brcmf_err("failed to reset all usb devices %d\n", ret
);
1584 usb_deregister(&brcmf_usbdrvr
);
1587 void brcmf_usb_register(void)
1591 brcmf_dbg(USB
, "Enter\n");
1592 ret
= usb_register(&brcmf_usbdrvr
);
1594 brcmf_err("usb_register failed %d\n", ret
);