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 <brcm_hw_ids.h>
25 #include <brcmu_wifi.h>
35 #define IOCTL_RESP_TIMEOUT msecs_to_jiffies(2000)
37 #define BRCMF_USB_RESET_GETVER_SPINWAIT 100 /* in unit of ms */
38 #define BRCMF_USB_RESET_GETVER_LOOP_CNT 10
40 #define BRCMF_POSTBOOT_ID 0xA123 /* ID to detect if dongle
42 #define BRCMF_USB_NRXQ 50
43 #define BRCMF_USB_NTXQ 50
45 #define BRCMF_USB_CBCTL_WRITE 0
46 #define BRCMF_USB_CBCTL_READ 1
47 #define BRCMF_USB_MAX_PKT_SIZE 1600
49 BRCMF_FW_DEF(43143, "brcmfmac43143");
50 BRCMF_FW_DEF(43236B
, "brcmfmac43236b");
51 BRCMF_FW_DEF(43242A
, "brcmfmac43242a");
52 BRCMF_FW_DEF(43569, "brcmfmac43569");
53 BRCMF_FW_DEF(4373, "brcmfmac4373");
55 static const struct brcmf_firmware_mapping brcmf_usb_fwnames
[] = {
56 BRCMF_FW_ENTRY(BRCM_CC_43143_CHIP_ID
, 0xFFFFFFFF, 43143),
57 BRCMF_FW_ENTRY(BRCM_CC_43235_CHIP_ID
, 0x00000008, 43236B
),
58 BRCMF_FW_ENTRY(BRCM_CC_43236_CHIP_ID
, 0x00000008, 43236B
),
59 BRCMF_FW_ENTRY(BRCM_CC_43238_CHIP_ID
, 0x00000008, 43236B
),
60 BRCMF_FW_ENTRY(BRCM_CC_43242_CHIP_ID
, 0xFFFFFFFF, 43242A
),
61 BRCMF_FW_ENTRY(BRCM_CC_43566_CHIP_ID
, 0xFFFFFFFF, 43569),
62 BRCMF_FW_ENTRY(BRCM_CC_43569_CHIP_ID
, 0xFFFFFFFF, 43569),
63 BRCMF_FW_ENTRY(CY_CC_4373_CHIP_ID
, 0xFFFFFFFF, 4373)
66 #define TRX_MAGIC 0x30524448 /* "HDR0" */
67 #define TRX_MAX_OFFSET 3 /* Max number of file offsets */
68 #define TRX_UNCOMP_IMAGE 0x20 /* Trx holds uncompressed img */
69 #define TRX_RDL_CHUNK 1500 /* size of each dl transfer */
70 #define TRX_OFFSETS_DLFWLEN_IDX 0
72 /* Control messages: bRequest values */
73 #define DL_GETSTATE 0 /* returns the rdl_state_t struct */
74 #define DL_CHECK_CRC 1 /* currently unused */
75 #define DL_GO 2 /* execute downloaded image */
76 #define DL_START 3 /* initialize dl state */
77 #define DL_REBOOT 4 /* reboot the device in 2 seconds */
78 #define DL_GETVER 5 /* returns the bootrom_id_t struct */
79 #define DL_GO_PROTECTED 6 /* execute the downloaded code and set reset
80 * event to occur in 2 seconds. It is the
81 * responsibility of the downloaded code to
84 #define DL_EXEC 7 /* jump to a supplied address */
85 #define DL_RESETCFG 8 /* To support single enum on dongle
86 * - Not used by bootloader
88 #define DL_DEFER_RESP_OK 9 /* Potentially defer the response to setup
93 #define DL_WAITING 0 /* waiting to rx first pkt */
94 #define DL_READY 1 /* hdr was good, waiting for more of the
97 #define DL_BAD_HDR 2 /* hdr was corrupted */
98 #define DL_BAD_CRC 3 /* compressed image was corrupted */
99 #define DL_RUNNABLE 4 /* download was successful,waiting for go cmd */
100 #define DL_START_FAIL 5 /* failed to initialize correctly */
101 #define DL_NVRAM_TOOBIG 6 /* host specified nvram data exceeds DL_NVRAM
104 #define DL_IMAGE_TOOBIG 7 /* firmware image too big */
107 struct trx_header_le
{
108 __le32 magic
; /* "HDR0" */
109 __le32 len
; /* Length of file including header */
110 __le32 crc32
; /* CRC from flag_version to end of file */
111 __le32 flag_version
; /* 0:15 flags, 16:31 version */
112 __le32 offsets
[TRX_MAX_OFFSET
]; /* Offsets of partitions from start of
117 struct rdl_state_le
{
122 struct bootrom_id_le
{
123 __le32 chip
; /* Chip id */
124 __le32 chiprev
; /* Chip rev */
125 __le32 ramsize
; /* Size of RAM */
126 __le32 remapbase
; /* Current remap base address */
127 __le32 boardtype
; /* Type of board */
128 __le32 boardrev
; /* Board revision */
131 struct brcmf_usb_image
{
132 struct list_head list
;
138 struct brcmf_usbdev_info
{
139 struct brcmf_usbdev bus_pub
; /* MUST BE FIRST */
141 struct list_head rx_freeq
;
142 struct list_head rx_postq
;
143 struct list_head tx_freeq
;
144 struct list_head tx_postq
;
145 uint rx_pipe
, tx_pipe
;
147 int rx_low_watermark
;
148 int tx_low_watermark
;
149 int tx_high_watermark
;
152 spinlock_t tx_flowblock_lock
;
154 struct brcmf_usbreq
*tx_reqs
;
155 struct brcmf_usbreq
*rx_reqs
;
157 char fw_name
[BRCMF_FW_NAME_LEN
];
158 const u8
*image
; /* buffer for combine fw and nvram */
161 struct usb_device
*usbdev
;
163 struct completion dev_init_done
;
165 int ctl_in_pipe
, ctl_out_pipe
;
166 struct urb
*ctl_urb
; /* URB for control endpoint */
167 struct usb_ctrlrequest ctl_write
;
168 struct usb_ctrlrequest ctl_read
;
169 u32 ctl_urb_actual_length
;
172 wait_queue_head_t ioctl_resp_wait
;
176 struct urb
*bulk_urb
; /* used for FW download */
179 struct brcmf_mp_device
*settings
;
182 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
183 struct brcmf_usbreq
*req
);
185 static struct brcmf_usbdev
*brcmf_usb_get_buspub(struct device
*dev
)
187 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
188 return bus_if
->bus_priv
.usb
;
191 static struct brcmf_usbdev_info
*brcmf_usb_get_businfo(struct device
*dev
)
193 return brcmf_usb_get_buspub(dev
)->devinfo
;
196 static int brcmf_usb_ioctl_resp_wait(struct brcmf_usbdev_info
*devinfo
)
198 return wait_event_timeout(devinfo
->ioctl_resp_wait
,
199 devinfo
->ctl_completed
, IOCTL_RESP_TIMEOUT
);
202 static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info
*devinfo
)
204 wake_up(&devinfo
->ioctl_resp_wait
);
208 brcmf_usb_ctl_complete(struct brcmf_usbdev_info
*devinfo
, int type
, int status
)
210 brcmf_dbg(USB
, "Enter, status=%d\n", status
);
212 if (unlikely(devinfo
== NULL
))
215 if (type
== BRCMF_USB_CBCTL_READ
) {
217 devinfo
->bus_pub
.stats
.rx_ctlpkts
++;
219 devinfo
->bus_pub
.stats
.rx_ctlerrs
++;
220 } else if (type
== BRCMF_USB_CBCTL_WRITE
) {
222 devinfo
->bus_pub
.stats
.tx_ctlpkts
++;
224 devinfo
->bus_pub
.stats
.tx_ctlerrs
++;
227 devinfo
->ctl_urb_status
= status
;
228 devinfo
->ctl_completed
= true;
229 brcmf_usb_ioctl_resp_wake(devinfo
);
233 brcmf_usb_ctlread_complete(struct urb
*urb
)
235 struct brcmf_usbdev_info
*devinfo
=
236 (struct brcmf_usbdev_info
*)urb
->context
;
238 brcmf_dbg(USB
, "Enter\n");
239 devinfo
->ctl_urb_actual_length
= urb
->actual_length
;
240 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_READ
,
245 brcmf_usb_ctlwrite_complete(struct urb
*urb
)
247 struct brcmf_usbdev_info
*devinfo
=
248 (struct brcmf_usbdev_info
*)urb
->context
;
250 brcmf_dbg(USB
, "Enter\n");
251 brcmf_usb_ctl_complete(devinfo
, BRCMF_USB_CBCTL_WRITE
,
256 brcmf_usb_send_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
261 brcmf_dbg(USB
, "Enter\n");
262 if (devinfo
== NULL
|| buf
== NULL
||
263 len
== 0 || devinfo
->ctl_urb
== NULL
)
267 devinfo
->ctl_write
.wLength
= cpu_to_le16p(&size
);
268 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
269 devinfo
->ctl_urb_status
= 0;
270 devinfo
->ctl_urb_actual_length
= 0;
272 usb_fill_control_urb(devinfo
->ctl_urb
,
274 devinfo
->ctl_out_pipe
,
275 (unsigned char *) &devinfo
->ctl_write
,
277 (usb_complete_t
)brcmf_usb_ctlwrite_complete
,
280 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
282 brcmf_err("usb_submit_urb failed %d\n", ret
);
288 brcmf_usb_recv_ctl(struct brcmf_usbdev_info
*devinfo
, u8
*buf
, int len
)
293 brcmf_dbg(USB
, "Enter\n");
294 if ((devinfo
== NULL
) || (buf
== NULL
) || (len
== 0)
295 || (devinfo
->ctl_urb
== NULL
))
299 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
300 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
302 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
303 | USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
304 devinfo
->ctl_read
.bRequest
= 1;
306 usb_fill_control_urb(devinfo
->ctl_urb
,
308 devinfo
->ctl_in_pipe
,
309 (unsigned char *) &devinfo
->ctl_read
,
311 (usb_complete_t
)brcmf_usb_ctlread_complete
,
314 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
316 brcmf_err("usb_submit_urb failed %d\n", ret
);
321 static int brcmf_usb_tx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
325 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
327 brcmf_dbg(USB
, "Enter\n");
328 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
)
331 if (test_and_set_bit(0, &devinfo
->ctl_op
))
334 devinfo
->ctl_completed
= false;
335 err
= brcmf_usb_send_ctl(devinfo
, buf
, len
);
337 brcmf_err("fail %d bytes: %d\n", err
, len
);
338 clear_bit(0, &devinfo
->ctl_op
);
341 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
342 clear_bit(0, &devinfo
->ctl_op
);
344 brcmf_err("Txctl wait timed out\n");
350 static int brcmf_usb_rx_ctlpkt(struct device
*dev
, u8
*buf
, u32 len
)
354 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
356 brcmf_dbg(USB
, "Enter\n");
357 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
)
360 if (test_and_set_bit(0, &devinfo
->ctl_op
))
363 devinfo
->ctl_completed
= false;
364 err
= brcmf_usb_recv_ctl(devinfo
, buf
, len
);
366 brcmf_err("fail %d bytes: %d\n", err
, len
);
367 clear_bit(0, &devinfo
->ctl_op
);
370 timeout
= brcmf_usb_ioctl_resp_wait(devinfo
);
371 err
= devinfo
->ctl_urb_status
;
372 clear_bit(0, &devinfo
->ctl_op
);
374 brcmf_err("rxctl wait timed out\n");
378 return devinfo
->ctl_urb_actual_length
;
383 static struct brcmf_usbreq
*brcmf_usb_deq(struct brcmf_usbdev_info
*devinfo
,
384 struct list_head
*q
, int *counter
)
387 struct brcmf_usbreq
*req
;
388 spin_lock_irqsave(&devinfo
->qlock
, flags
);
390 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
393 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
394 list_del_init(q
->next
);
397 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
402 static void brcmf_usb_enq(struct brcmf_usbdev_info
*devinfo
,
403 struct list_head
*q
, struct brcmf_usbreq
*req
,
407 spin_lock_irqsave(&devinfo
->qlock
, flags
);
408 list_add_tail(&req
->list
, q
);
411 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
414 static struct brcmf_usbreq
*
415 brcmf_usbdev_qinit(struct list_head
*q
, int qsize
)
418 struct brcmf_usbreq
*req
, *reqs
;
420 reqs
= kcalloc(qsize
, sizeof(struct brcmf_usbreq
), GFP_ATOMIC
);
426 for (i
= 0; i
< qsize
; i
++) {
427 req
->urb
= usb_alloc_urb(0, GFP_ATOMIC
);
431 INIT_LIST_HEAD(&req
->list
);
432 list_add_tail(&req
->list
, q
);
437 brcmf_err("fail!\n");
438 while (!list_empty(q
)) {
439 req
= list_entry(q
->next
, struct brcmf_usbreq
, list
);
441 usb_free_urb(req
->urb
);
449 static void brcmf_usb_free_q(struct list_head
*q
, bool pending
)
451 struct brcmf_usbreq
*req
, *next
;
453 list_for_each_entry_safe(req
, next
, q
, list
) {
455 brcmf_err("bad req\n");
460 usb_kill_urb(req
->urb
);
462 usb_free_urb(req
->urb
);
463 list_del_init(&req
->list
);
468 static void brcmf_usb_del_fromq(struct brcmf_usbdev_info
*devinfo
,
469 struct brcmf_usbreq
*req
)
473 spin_lock_irqsave(&devinfo
->qlock
, flags
);
474 list_del_init(&req
->list
);
475 spin_unlock_irqrestore(&devinfo
->qlock
, flags
);
479 static void brcmf_usb_tx_complete(struct urb
*urb
)
481 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
482 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
485 brcmf_dbg(USB
, "Enter, urb->status=%d, skb=%p\n", urb
->status
,
487 brcmf_usb_del_fromq(devinfo
, req
);
489 brcmf_proto_bcdc_txcomplete(devinfo
->dev
, req
->skb
, urb
->status
== 0);
491 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
, &devinfo
->tx_freecount
);
492 spin_lock_irqsave(&devinfo
->tx_flowblock_lock
, flags
);
493 if (devinfo
->tx_freecount
> devinfo
->tx_high_watermark
&&
494 devinfo
->tx_flowblock
) {
495 brcmf_proto_bcdc_txflowblock(devinfo
->dev
, false);
496 devinfo
->tx_flowblock
= false;
498 spin_unlock_irqrestore(&devinfo
->tx_flowblock_lock
, flags
);
501 static void brcmf_usb_rx_complete(struct urb
*urb
)
503 struct brcmf_usbreq
*req
= (struct brcmf_usbreq
*)urb
->context
;
504 struct brcmf_usbdev_info
*devinfo
= req
->devinfo
;
507 brcmf_dbg(USB
, "Enter, urb->status=%d\n", urb
->status
);
508 brcmf_usb_del_fromq(devinfo
, req
);
512 /* zero lenght packets indicate usb "failure". Do not refill */
513 if (urb
->status
!= 0 || !urb
->actual_length
) {
514 brcmu_pkt_buf_free_skb(skb
);
515 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
519 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
) {
520 skb_put(skb
, urb
->actual_length
);
521 brcmf_rx_frame(devinfo
->dev
, skb
, true);
522 brcmf_usb_rx_refill(devinfo
, req
);
524 brcmu_pkt_buf_free_skb(skb
);
525 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
531 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info
*devinfo
,
532 struct brcmf_usbreq
*req
)
537 if (!req
|| !devinfo
)
540 skb
= dev_alloc_skb(devinfo
->bus_pub
.bus_mtu
);
542 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
547 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->rx_pipe
,
548 skb
->data
, skb_tailroom(skb
), brcmf_usb_rx_complete
,
550 req
->devinfo
= devinfo
;
551 brcmf_usb_enq(devinfo
, &devinfo
->rx_postq
, req
, NULL
);
553 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
555 brcmf_usb_del_fromq(devinfo
, req
);
556 brcmu_pkt_buf_free_skb(req
->skb
);
558 brcmf_usb_enq(devinfo
, &devinfo
->rx_freeq
, req
, NULL
);
563 static void brcmf_usb_rx_fill_all(struct brcmf_usbdev_info
*devinfo
)
565 struct brcmf_usbreq
*req
;
567 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
568 brcmf_err("bus is not up=%d\n", devinfo
->bus_pub
.state
);
571 while ((req
= brcmf_usb_deq(devinfo
, &devinfo
->rx_freeq
, NULL
)) != NULL
)
572 brcmf_usb_rx_refill(devinfo
, req
);
576 brcmf_usb_state_change(struct brcmf_usbdev_info
*devinfo
, int state
)
578 struct brcmf_bus
*bcmf_bus
= devinfo
->bus_pub
.bus
;
581 brcmf_dbg(USB
, "Enter, current state=%d, new state=%d\n",
582 devinfo
->bus_pub
.state
, state
);
584 if (devinfo
->bus_pub
.state
== state
)
587 old_state
= devinfo
->bus_pub
.state
;
588 devinfo
->bus_pub
.state
= state
;
590 /* update state of upper layer */
591 if (state
== BRCMFMAC_USB_STATE_DOWN
) {
592 brcmf_dbg(USB
, "DBUS is down\n");
593 brcmf_bus_change_state(bcmf_bus
, BRCMF_BUS_DOWN
);
594 } else if (state
== BRCMFMAC_USB_STATE_UP
) {
595 brcmf_dbg(USB
, "DBUS is up\n");
596 brcmf_bus_change_state(bcmf_bus
, BRCMF_BUS_UP
);
598 brcmf_dbg(USB
, "DBUS current state=%d\n", state
);
602 static int brcmf_usb_tx(struct device
*dev
, struct sk_buff
*skb
)
604 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
605 struct brcmf_usbreq
*req
;
609 brcmf_dbg(USB
, "Enter, skb=%p\n", skb
);
610 if (devinfo
->bus_pub
.state
!= BRCMFMAC_USB_STATE_UP
) {
615 req
= brcmf_usb_deq(devinfo
, &devinfo
->tx_freeq
,
616 &devinfo
->tx_freecount
);
618 brcmf_err("no req to send\n");
624 req
->devinfo
= devinfo
;
625 usb_fill_bulk_urb(req
->urb
, devinfo
->usbdev
, devinfo
->tx_pipe
,
626 skb
->data
, skb
->len
, brcmf_usb_tx_complete
, req
);
627 req
->urb
->transfer_flags
|= URB_ZERO_PACKET
;
628 brcmf_usb_enq(devinfo
, &devinfo
->tx_postq
, req
, NULL
);
629 ret
= usb_submit_urb(req
->urb
, GFP_ATOMIC
);
631 brcmf_err("brcmf_usb_tx usb_submit_urb FAILED\n");
632 brcmf_usb_del_fromq(devinfo
, req
);
634 brcmf_usb_enq(devinfo
, &devinfo
->tx_freeq
, req
,
635 &devinfo
->tx_freecount
);
639 spin_lock_irqsave(&devinfo
->tx_flowblock_lock
, flags
);
640 if (devinfo
->tx_freecount
< devinfo
->tx_low_watermark
&&
641 !devinfo
->tx_flowblock
) {
642 brcmf_proto_bcdc_txflowblock(dev
, true);
643 devinfo
->tx_flowblock
= true;
645 spin_unlock_irqrestore(&devinfo
->tx_flowblock_lock
, flags
);
653 static int brcmf_usb_up(struct device
*dev
)
655 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
657 brcmf_dbg(USB
, "Enter\n");
658 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_UP
)
661 /* Success, indicate devinfo is fully up */
662 brcmf_usb_state_change(devinfo
, BRCMFMAC_USB_STATE_UP
);
664 if (devinfo
->ctl_urb
) {
665 devinfo
->ctl_in_pipe
= usb_rcvctrlpipe(devinfo
->usbdev
, 0);
666 devinfo
->ctl_out_pipe
= usb_sndctrlpipe(devinfo
->usbdev
, 0);
669 devinfo
->ctl_write
.bRequestType
=
670 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
671 devinfo
->ctl_write
.bRequest
= 0;
672 devinfo
->ctl_write
.wValue
= cpu_to_le16(0);
673 devinfo
->ctl_write
.wIndex
= cpu_to_le16(devinfo
->ifnum
);
676 devinfo
->ctl_read
.bRequestType
=
677 USB_DIR_IN
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
678 devinfo
->ctl_read
.bRequest
= 1;
679 devinfo
->ctl_read
.wValue
= cpu_to_le16(0);
680 devinfo
->ctl_read
.wIndex
= cpu_to_le16(devinfo
->ifnum
);
682 brcmf_usb_rx_fill_all(devinfo
);
686 static void brcmf_cancel_all_urbs(struct brcmf_usbdev_info
*devinfo
)
690 if (devinfo
->ctl_urb
)
691 usb_kill_urb(devinfo
->ctl_urb
);
692 if (devinfo
->bulk_urb
)
693 usb_kill_urb(devinfo
->bulk_urb
);
694 if (devinfo
->tx_reqs
)
695 for (i
= 0; i
< devinfo
->bus_pub
.ntxq
; i
++)
696 usb_kill_urb(devinfo
->tx_reqs
[i
].urb
);
697 if (devinfo
->rx_reqs
)
698 for (i
= 0; i
< devinfo
->bus_pub
.nrxq
; i
++)
699 usb_kill_urb(devinfo
->rx_reqs
[i
].urb
);
702 static void brcmf_usb_down(struct device
*dev
)
704 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
706 brcmf_dbg(USB
, "Enter\n");
710 if (devinfo
->bus_pub
.state
== BRCMFMAC_USB_STATE_DOWN
)
713 brcmf_usb_state_change(devinfo
, BRCMFMAC_USB_STATE_DOWN
);
715 brcmf_cancel_all_urbs(devinfo
);
719 brcmf_usb_sync_complete(struct urb
*urb
)
721 struct brcmf_usbdev_info
*devinfo
=
722 (struct brcmf_usbdev_info
*)urb
->context
;
724 devinfo
->ctl_completed
= true;
725 brcmf_usb_ioctl_resp_wake(devinfo
);
728 static int brcmf_usb_dl_cmd(struct brcmf_usbdev_info
*devinfo
, u8 cmd
,
729 void *buffer
, int buflen
)
735 if ((!devinfo
) || (devinfo
->ctl_urb
== NULL
))
738 tmpbuf
= kmalloc(buflen
, GFP_ATOMIC
);
743 devinfo
->ctl_urb
->transfer_buffer_length
= size
;
745 devinfo
->ctl_read
.wLength
= cpu_to_le16p(&size
);
746 devinfo
->ctl_read
.bRequestType
= USB_DIR_IN
| USB_TYPE_VENDOR
|
748 devinfo
->ctl_read
.bRequest
= cmd
;
750 usb_fill_control_urb(devinfo
->ctl_urb
,
752 usb_rcvctrlpipe(devinfo
->usbdev
, 0),
753 (unsigned char *) &devinfo
->ctl_read
,
754 (void *) tmpbuf
, size
,
755 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
757 devinfo
->ctl_completed
= false;
758 ret
= usb_submit_urb(devinfo
->ctl_urb
, GFP_ATOMIC
);
760 brcmf_err("usb_submit_urb failed %d\n", ret
);
764 if (!brcmf_usb_ioctl_resp_wait(devinfo
)) {
765 usb_kill_urb(devinfo
->ctl_urb
);
768 memcpy(buffer
, tmpbuf
, buflen
);
777 brcmf_usb_dlneeded(struct brcmf_usbdev_info
*devinfo
)
779 struct bootrom_id_le id
;
782 brcmf_dbg(USB
, "Enter\n");
787 /* Check if firmware downloaded already by querying runtime ID */
788 id
.chip
= cpu_to_le32(0xDEAD);
789 brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
, sizeof(id
));
791 chipid
= le32_to_cpu(id
.chip
);
792 chiprev
= le32_to_cpu(id
.chiprev
);
794 if ((chipid
& 0x4300) == 0x4300)
795 brcmf_dbg(USB
, "chip %x rev 0x%x\n", chipid
, chiprev
);
797 brcmf_dbg(USB
, "chip %d rev 0x%x\n", chipid
, chiprev
);
798 if (chipid
== BRCMF_POSTBOOT_ID
) {
799 brcmf_dbg(USB
, "firmware already downloaded\n");
800 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
, sizeof(id
));
803 devinfo
->bus_pub
.devid
= chipid
;
804 devinfo
->bus_pub
.chiprev
= chiprev
;
810 brcmf_usb_resetcfg(struct brcmf_usbdev_info
*devinfo
)
812 struct bootrom_id_le id
;
816 brcmf_dbg(USB
, "Enter\n");
820 mdelay(BRCMF_USB_RESET_GETVER_SPINWAIT
);
822 id
.chip
= cpu_to_le32(0xDEAD); /* Get the ID */
823 err
= brcmf_usb_dl_cmd(devinfo
, DL_GETVER
, &id
, sizeof(id
));
824 if ((err
) && (err
!= -ETIMEDOUT
))
826 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
))
828 } while (loop_cnt
< BRCMF_USB_RESET_GETVER_LOOP_CNT
);
830 if (id
.chip
== cpu_to_le32(BRCMF_POSTBOOT_ID
)) {
831 brcmf_dbg(USB
, "postboot chip 0x%x/rev 0x%x\n",
832 le32_to_cpu(id
.chip
), le32_to_cpu(id
.chiprev
));
834 brcmf_usb_dl_cmd(devinfo
, DL_RESETCFG
, &id
, sizeof(id
));
837 brcmf_err("Cannot talk to Dongle. Firmware is not UP, %d ms\n",
838 BRCMF_USB_RESET_GETVER_SPINWAIT
* loop_cnt
);
845 brcmf_usb_dl_send_bulk(struct brcmf_usbdev_info
*devinfo
, void *buffer
, int len
)
849 if ((devinfo
== NULL
) || (devinfo
->bulk_urb
== NULL
))
852 /* Prepare the URB */
853 usb_fill_bulk_urb(devinfo
->bulk_urb
, devinfo
->usbdev
,
854 devinfo
->tx_pipe
, buffer
, len
,
855 (usb_complete_t
)brcmf_usb_sync_complete
, devinfo
);
857 devinfo
->bulk_urb
->transfer_flags
|= URB_ZERO_PACKET
;
859 devinfo
->ctl_completed
= false;
860 ret
= usb_submit_urb(devinfo
->bulk_urb
, GFP_ATOMIC
);
862 brcmf_err("usb_submit_urb failed %d\n", ret
);
865 ret
= brcmf_usb_ioctl_resp_wait(devinfo
);
870 brcmf_usb_dl_writeimage(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int fwlen
)
872 unsigned int sendlen
, sent
, dllen
;
873 char *bulkchunk
= NULL
, *dlpos
;
874 struct rdl_state_le state
;
875 u32 rdlstate
, rdlbytes
;
878 brcmf_dbg(USB
, "Enter, fw %p, len %d\n", fw
, fwlen
);
880 bulkchunk
= kmalloc(TRX_RDL_CHUNK
, GFP_ATOMIC
);
881 if (bulkchunk
== NULL
) {
886 /* 1) Prepare USB boot loader for runtime image */
887 brcmf_usb_dl_cmd(devinfo
, DL_START
, &state
, sizeof(state
));
889 rdlstate
= le32_to_cpu(state
.state
);
890 rdlbytes
= le32_to_cpu(state
.bytes
);
892 /* 2) Check we are in the Waiting state */
893 if (rdlstate
!= DL_WAITING
) {
894 brcmf_err("Failed to DL_START\n");
902 /* Get chip id and rev */
903 while (rdlbytes
!= dllen
) {
904 /* Wait until the usb device reports it received all
905 * the bytes we sent */
906 if ((rdlbytes
== sent
) && (rdlbytes
!= dllen
)) {
907 if ((dllen
-sent
) < TRX_RDL_CHUNK
)
908 sendlen
= dllen
-sent
;
910 sendlen
= TRX_RDL_CHUNK
;
912 /* simply avoid having to send a ZLP by ensuring we
920 memcpy(bulkchunk
, dlpos
, sendlen
);
921 if (brcmf_usb_dl_send_bulk(devinfo
, bulkchunk
,
923 brcmf_err("send_bulk failed\n");
931 err
= brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
,
934 brcmf_err("DL_GETSTATE Failed\n");
938 rdlstate
= le32_to_cpu(state
.state
);
939 rdlbytes
= le32_to_cpu(state
.bytes
);
941 /* restart if an error is reported */
942 if (rdlstate
== DL_BAD_HDR
|| rdlstate
== DL_BAD_CRC
) {
943 brcmf_err("Bad Hdr or Bad CRC state %d\n",
952 brcmf_dbg(USB
, "Exit, err=%d\n", err
);
956 static int brcmf_usb_dlstart(struct brcmf_usbdev_info
*devinfo
, u8
*fw
, int len
)
960 brcmf_dbg(USB
, "Enter\n");
965 if (devinfo
->bus_pub
.devid
== 0xDEAD)
968 err
= brcmf_usb_dl_writeimage(devinfo
, fw
, len
);
970 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DL_DONE
;
972 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DL_FAIL
;
973 brcmf_dbg(USB
, "Exit, err=%d\n", err
);
978 static int brcmf_usb_dlrun(struct brcmf_usbdev_info
*devinfo
)
980 struct rdl_state_le state
;
982 brcmf_dbg(USB
, "Enter\n");
986 if (devinfo
->bus_pub
.devid
== 0xDEAD)
989 /* Check we are runnable */
991 brcmf_usb_dl_cmd(devinfo
, DL_GETSTATE
, &state
, sizeof(state
));
993 /* Start the image */
994 if (state
.state
== cpu_to_le32(DL_RUNNABLE
)) {
995 if (brcmf_usb_dl_cmd(devinfo
, DL_GO
, &state
, sizeof(state
)))
997 if (brcmf_usb_resetcfg(devinfo
))
999 /* The Dongle may go for re-enumeration. */
1001 brcmf_err("Dongle not runnable\n");
1004 brcmf_dbg(USB
, "Exit\n");
1009 brcmf_usb_fw_download(struct brcmf_usbdev_info
*devinfo
)
1013 brcmf_dbg(USB
, "Enter\n");
1014 if (devinfo
== NULL
)
1017 if (!devinfo
->image
) {
1018 brcmf_err("No firmware!\n");
1022 err
= brcmf_usb_dlstart(devinfo
,
1023 (u8
*)devinfo
->image
, devinfo
->image_len
);
1025 err
= brcmf_usb_dlrun(devinfo
);
1030 static void brcmf_usb_detach(struct brcmf_usbdev_info
*devinfo
)
1032 brcmf_dbg(USB
, "Enter, devinfo %p\n", devinfo
);
1035 brcmf_usb_free_q(&devinfo
->rx_freeq
, false);
1036 brcmf_usb_free_q(&devinfo
->tx_freeq
, false);
1038 usb_free_urb(devinfo
->ctl_urb
);
1039 usb_free_urb(devinfo
->bulk_urb
);
1041 kfree(devinfo
->tx_reqs
);
1042 kfree(devinfo
->rx_reqs
);
1044 if (devinfo
->settings
)
1045 brcmf_release_module_param(devinfo
->settings
);
1049 static int check_file(const u8
*headers
)
1051 struct trx_header_le
*trx
;
1052 int actual_len
= -1;
1054 brcmf_dbg(USB
, "Enter\n");
1055 /* Extract trx header */
1056 trx
= (struct trx_header_le
*) headers
;
1057 if (trx
->magic
!= cpu_to_le32(TRX_MAGIC
))
1060 headers
+= sizeof(struct trx_header_le
);
1062 if (le32_to_cpu(trx
->flag_version
) & TRX_UNCOMP_IMAGE
) {
1063 actual_len
= le32_to_cpu(trx
->offsets
[TRX_OFFSETS_DLFWLEN_IDX
]);
1064 return actual_len
+ sizeof(struct trx_header_le
);
1071 struct brcmf_usbdev
*brcmf_usb_attach(struct brcmf_usbdev_info
*devinfo
,
1074 brcmf_dbg(USB
, "Enter\n");
1076 devinfo
->bus_pub
.nrxq
= nrxq
;
1077 devinfo
->rx_low_watermark
= nrxq
/ 2;
1078 devinfo
->bus_pub
.devinfo
= devinfo
;
1079 devinfo
->bus_pub
.ntxq
= ntxq
;
1080 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_DOWN
;
1082 /* flow control when too many tx urbs posted */
1083 devinfo
->tx_low_watermark
= ntxq
/ 4;
1084 devinfo
->tx_high_watermark
= devinfo
->tx_low_watermark
* 3;
1085 devinfo
->bus_pub
.bus_mtu
= BRCMF_USB_MAX_PKT_SIZE
;
1087 /* Initialize other structure content */
1088 init_waitqueue_head(&devinfo
->ioctl_resp_wait
);
1090 /* Initialize the spinlocks */
1091 spin_lock_init(&devinfo
->qlock
);
1092 spin_lock_init(&devinfo
->tx_flowblock_lock
);
1094 INIT_LIST_HEAD(&devinfo
->rx_freeq
);
1095 INIT_LIST_HEAD(&devinfo
->rx_postq
);
1097 INIT_LIST_HEAD(&devinfo
->tx_freeq
);
1098 INIT_LIST_HEAD(&devinfo
->tx_postq
);
1100 devinfo
->tx_flowblock
= false;
1102 devinfo
->rx_reqs
= brcmf_usbdev_qinit(&devinfo
->rx_freeq
, nrxq
);
1103 if (!devinfo
->rx_reqs
)
1106 devinfo
->tx_reqs
= brcmf_usbdev_qinit(&devinfo
->tx_freeq
, ntxq
);
1107 if (!devinfo
->tx_reqs
)
1109 devinfo
->tx_freecount
= ntxq
;
1111 devinfo
->ctl_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1112 if (!devinfo
->ctl_urb
)
1114 devinfo
->bulk_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
1115 if (!devinfo
->bulk_urb
)
1118 return &devinfo
->bus_pub
;
1121 brcmf_err("failed!\n");
1122 brcmf_usb_detach(devinfo
);
1126 static void brcmf_usb_wowl_config(struct device
*dev
, bool enabled
)
1128 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(dev
);
1130 brcmf_dbg(USB
, "Configuring WOWL, enabled=%d\n", enabled
);
1131 devinfo
->wowl_enabled
= enabled
;
1133 device_set_wakeup_enable(devinfo
->dev
, true);
1135 device_set_wakeup_enable(devinfo
->dev
, false);
1139 int brcmf_usb_get_fwname(struct device
*dev
, const char *ext
, u8
*fw_name
)
1141 struct brcmf_bus
*bus
= dev_get_drvdata(dev
);
1142 struct brcmf_fw_request
*fwreq
;
1143 struct brcmf_fw_name fwnames
[] = {
1147 fwreq
= brcmf_fw_alloc_request(bus
->chip
, bus
->chiprev
,
1149 ARRAY_SIZE(brcmf_usb_fwnames
),
1150 fwnames
, ARRAY_SIZE(fwnames
));
1158 static const struct brcmf_bus_ops brcmf_usb_bus_ops
= {
1159 .preinit
= brcmf_usb_up
,
1160 .stop
= brcmf_usb_down
,
1161 .txdata
= brcmf_usb_tx
,
1162 .txctl
= brcmf_usb_tx_ctlpkt
,
1163 .rxctl
= brcmf_usb_rx_ctlpkt
,
1164 .wowl_config
= brcmf_usb_wowl_config
,
1165 .get_fwname
= brcmf_usb_get_fwname
,
1168 #define BRCMF_USB_FW_CODE 0
1170 static void brcmf_usb_probe_phase2(struct device
*dev
, int ret
,
1171 struct brcmf_fw_request
*fwreq
)
1173 struct brcmf_bus
*bus
= dev_get_drvdata(dev
);
1174 struct brcmf_usbdev_info
*devinfo
= bus
->bus_priv
.usb
->devinfo
;
1175 const struct firmware
*fw
;
1180 brcmf_dbg(USB
, "Start fw downloading\n");
1182 fw
= fwreq
->items
[BRCMF_USB_FW_CODE
].binary
;
1185 ret
= check_file(fw
->data
);
1187 brcmf_err("invalid firmware\n");
1188 release_firmware(fw
);
1192 devinfo
->image
= fw
->data
;
1193 devinfo
->image_len
= fw
->size
;
1195 ret
= brcmf_usb_fw_download(devinfo
);
1196 release_firmware(fw
);
1200 /* Attach to the common driver interface */
1201 ret
= brcmf_attach(devinfo
->dev
, devinfo
->settings
);
1205 complete(&devinfo
->dev_init_done
);
1208 brcmf_dbg(TRACE
, "failed: dev=%s, err=%d\n", dev_name(dev
), ret
);
1209 complete(&devinfo
->dev_init_done
);
1210 device_release_driver(dev
);
1213 static struct brcmf_fw_request
*
1214 brcmf_usb_prepare_fw_request(struct brcmf_usbdev_info
*devinfo
)
1216 struct brcmf_fw_request
*fwreq
;
1217 struct brcmf_fw_name fwnames
[] = {
1218 { ".bin", devinfo
->fw_name
},
1221 fwreq
= brcmf_fw_alloc_request(devinfo
->bus_pub
.devid
,
1222 devinfo
->bus_pub
.chiprev
,
1224 ARRAY_SIZE(brcmf_usb_fwnames
),
1225 fwnames
, ARRAY_SIZE(fwnames
));
1229 fwreq
->items
[BRCMF_USB_FW_CODE
].type
= BRCMF_FW_TYPE_BINARY
;
1234 static int brcmf_usb_probe_cb(struct brcmf_usbdev_info
*devinfo
)
1236 struct brcmf_bus
*bus
= NULL
;
1237 struct brcmf_usbdev
*bus_pub
= NULL
;
1238 struct device
*dev
= devinfo
->dev
;
1239 struct brcmf_fw_request
*fwreq
;
1242 brcmf_dbg(USB
, "Enter\n");
1243 bus_pub
= brcmf_usb_attach(devinfo
, BRCMF_USB_NRXQ
, BRCMF_USB_NTXQ
);
1247 bus
= kzalloc(sizeof(struct brcmf_bus
), GFP_ATOMIC
);
1255 bus
->bus_priv
.usb
= bus_pub
;
1256 dev_set_drvdata(dev
, bus
);
1257 bus
->ops
= &brcmf_usb_bus_ops
;
1258 bus
->proto_type
= BRCMF_PROTO_BCDC
;
1259 bus
->always_use_fws_queue
= true;
1261 bus
->wowl_supported
= true;
1264 devinfo
->settings
= brcmf_get_module_param(bus
->dev
, BRCMF_BUSTYPE_USB
,
1267 if (!devinfo
->settings
) {
1272 if (!brcmf_usb_dlneeded(devinfo
)) {
1273 ret
= brcmf_attach(devinfo
->dev
, devinfo
->settings
);
1277 complete(&devinfo
->dev_init_done
);
1280 bus
->chip
= bus_pub
->devid
;
1281 bus
->chiprev
= bus_pub
->chiprev
;
1283 fwreq
= brcmf_usb_prepare_fw_request(devinfo
);
1289 /* request firmware here */
1290 ret
= brcmf_fw_get_firmwares(dev
, fwreq
, brcmf_usb_probe_phase2
);
1292 brcmf_err("firmware request failed: %d\n", ret
);
1300 /* Release resources in reverse order */
1302 brcmf_usb_detach(devinfo
);
1307 brcmf_usb_disconnect_cb(struct brcmf_usbdev_info
*devinfo
)
1311 brcmf_dbg(USB
, "Enter, bus_pub %p\n", devinfo
);
1313 brcmf_detach(devinfo
->dev
);
1314 kfree(devinfo
->bus_pub
.bus
);
1315 brcmf_usb_detach(devinfo
);
1319 brcmf_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1321 struct usb_device
*usb
= interface_to_usbdev(intf
);
1322 struct brcmf_usbdev_info
*devinfo
;
1323 struct usb_interface_descriptor
*desc
;
1324 struct usb_endpoint_descriptor
*endpoint
;
1327 u8 endpoint_num
, ep
;
1329 brcmf_dbg(USB
, "Enter 0x%04x:0x%04x\n", id
->idVendor
, id
->idProduct
);
1331 devinfo
= kzalloc(sizeof(*devinfo
), GFP_ATOMIC
);
1332 if (devinfo
== NULL
)
1335 devinfo
->usbdev
= usb
;
1336 devinfo
->dev
= &usb
->dev
;
1337 /* Init completion, to protect for disconnect while still loading.
1338 * Necessary because of the asynchronous firmware load construction
1340 init_completion(&devinfo
->dev_init_done
);
1342 usb_set_intfdata(intf
, devinfo
);
1344 /* Check that the device supports only one configuration */
1345 if (usb
->descriptor
.bNumConfigurations
!= 1) {
1346 brcmf_err("Number of configurations: %d not supported\n",
1347 usb
->descriptor
.bNumConfigurations
);
1352 if ((usb
->descriptor
.bDeviceClass
!= USB_CLASS_VENDOR_SPEC
) &&
1353 (usb
->descriptor
.bDeviceClass
!= USB_CLASS_MISC
) &&
1354 (usb
->descriptor
.bDeviceClass
!= USB_CLASS_WIRELESS_CONTROLLER
)) {
1355 brcmf_err("Device class: 0x%x not supported\n",
1356 usb
->descriptor
.bDeviceClass
);
1361 desc
= &intf
->cur_altsetting
->desc
;
1362 if ((desc
->bInterfaceClass
!= USB_CLASS_VENDOR_SPEC
) ||
1363 (desc
->bInterfaceSubClass
!= 2) ||
1364 (desc
->bInterfaceProtocol
!= 0xff)) {
1365 brcmf_err("non WLAN interface %d: 0x%x:0x%x:0x%x\n",
1366 desc
->bInterfaceNumber
, desc
->bInterfaceClass
,
1367 desc
->bInterfaceSubClass
, desc
->bInterfaceProtocol
);
1372 num_of_eps
= desc
->bNumEndpoints
;
1373 for (ep
= 0; ep
< num_of_eps
; ep
++) {
1374 endpoint
= &intf
->cur_altsetting
->endpoint
[ep
].desc
;
1375 endpoint_num
= usb_endpoint_num(endpoint
);
1376 if (!usb_endpoint_xfer_bulk(endpoint
))
1378 if (usb_endpoint_dir_in(endpoint
)) {
1379 if (!devinfo
->rx_pipe
)
1381 usb_rcvbulkpipe(usb
, endpoint_num
);
1383 if (!devinfo
->tx_pipe
)
1385 usb_sndbulkpipe(usb
, endpoint_num
);
1388 if (devinfo
->rx_pipe
== 0) {
1389 brcmf_err("No RX (in) Bulk EP found\n");
1393 if (devinfo
->tx_pipe
== 0) {
1394 brcmf_err("No TX (out) Bulk EP found\n");
1399 devinfo
->ifnum
= desc
->bInterfaceNumber
;
1401 if (usb
->speed
== USB_SPEED_SUPER_PLUS
)
1402 brcmf_dbg(USB
, "Broadcom super speed plus USB WLAN interface detected\n");
1403 else if (usb
->speed
== USB_SPEED_SUPER
)
1404 brcmf_dbg(USB
, "Broadcom super speed USB WLAN interface detected\n");
1405 else if (usb
->speed
== USB_SPEED_HIGH
)
1406 brcmf_dbg(USB
, "Broadcom high speed USB WLAN interface detected\n");
1408 brcmf_dbg(USB
, "Broadcom full speed USB WLAN interface detected\n");
1410 ret
= brcmf_usb_probe_cb(devinfo
);
1418 complete(&devinfo
->dev_init_done
);
1420 usb_set_intfdata(intf
, NULL
);
1425 brcmf_usb_disconnect(struct usb_interface
*intf
)
1427 struct brcmf_usbdev_info
*devinfo
;
1429 brcmf_dbg(USB
, "Enter\n");
1430 devinfo
= (struct brcmf_usbdev_info
*)usb_get_intfdata(intf
);
1433 wait_for_completion(&devinfo
->dev_init_done
);
1434 /* Make sure that devinfo still exists. Firmware probe routines
1435 * may have released the device and cleared the intfdata.
1437 if (!usb_get_intfdata(intf
))
1440 brcmf_usb_disconnect_cb(devinfo
);
1444 brcmf_dbg(USB
, "Exit\n");
1448 * only need to signal the bus being down and update the state.
1450 static int brcmf_usb_suspend(struct usb_interface
*intf
, pm_message_t state
)
1452 struct usb_device
*usb
= interface_to_usbdev(intf
);
1453 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1455 brcmf_dbg(USB
, "Enter\n");
1456 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_SLEEP
;
1457 if (devinfo
->wowl_enabled
)
1458 brcmf_cancel_all_urbs(devinfo
);
1460 brcmf_detach(&usb
->dev
);
1465 * (re-) start the bus.
1467 static int brcmf_usb_resume(struct usb_interface
*intf
)
1469 struct usb_device
*usb
= interface_to_usbdev(intf
);
1470 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1472 brcmf_dbg(USB
, "Enter\n");
1473 if (!devinfo
->wowl_enabled
)
1474 return brcmf_attach(devinfo
->dev
, devinfo
->settings
);
1476 devinfo
->bus_pub
.state
= BRCMFMAC_USB_STATE_UP
;
1477 brcmf_usb_rx_fill_all(devinfo
);
1481 static int brcmf_usb_reset_resume(struct usb_interface
*intf
)
1483 struct usb_device
*usb
= interface_to_usbdev(intf
);
1484 struct brcmf_usbdev_info
*devinfo
= brcmf_usb_get_businfo(&usb
->dev
);
1485 struct brcmf_fw_request
*fwreq
;
1488 brcmf_dbg(USB
, "Enter\n");
1490 fwreq
= brcmf_usb_prepare_fw_request(devinfo
);
1494 ret
= brcmf_fw_get_firmwares(&usb
->dev
, fwreq
, brcmf_usb_probe_phase2
);
1501 #define BRCMF_USB_DEVICE(dev_id) \
1502 { USB_DEVICE(BRCM_USB_VENDOR_ID_BROADCOM, dev_id) }
1504 #define LINKSYS_USB_DEVICE(dev_id) \
1505 { USB_DEVICE(BRCM_USB_VENDOR_ID_LINKSYS, dev_id) }
1507 #define CYPRESS_USB_DEVICE(dev_id) \
1508 { USB_DEVICE(CY_USB_VENDOR_ID_CYPRESS, dev_id) }
1510 static const struct usb_device_id brcmf_usb_devid_table
[] = {
1511 BRCMF_USB_DEVICE(BRCM_USB_43143_DEVICE_ID
),
1512 BRCMF_USB_DEVICE(BRCM_USB_43236_DEVICE_ID
),
1513 BRCMF_USB_DEVICE(BRCM_USB_43242_DEVICE_ID
),
1514 BRCMF_USB_DEVICE(BRCM_USB_43569_DEVICE_ID
),
1515 LINKSYS_USB_DEVICE(BRCM_USB_43235_LINKSYS_DEVICE_ID
),
1516 CYPRESS_USB_DEVICE(CY_USB_4373_DEVICE_ID
),
1517 { USB_DEVICE(BRCM_USB_VENDOR_ID_LG
, BRCM_USB_43242_LG_DEVICE_ID
) },
1518 /* special entry for device with firmware loaded and running */
1519 BRCMF_USB_DEVICE(BRCM_USB_BCMFW_DEVICE_ID
),
1520 CYPRESS_USB_DEVICE(BRCM_USB_BCMFW_DEVICE_ID
),
1521 { /* end: all zeroes */ }
1524 MODULE_DEVICE_TABLE(usb
, brcmf_usb_devid_table
);
1526 static struct usb_driver brcmf_usbdrvr
= {
1527 .name
= KBUILD_MODNAME
,
1528 .probe
= brcmf_usb_probe
,
1529 .disconnect
= brcmf_usb_disconnect
,
1530 .id_table
= brcmf_usb_devid_table
,
1531 .suspend
= brcmf_usb_suspend
,
1532 .resume
= brcmf_usb_resume
,
1533 .reset_resume
= brcmf_usb_reset_resume
,
1534 .disable_hub_initiated_lpm
= 1,
1537 static int brcmf_usb_reset_device(struct device
*dev
, void *notused
)
1539 /* device past is the usb interface so we
1540 * need to use parent here.
1542 brcmf_dev_reset(dev
->parent
);
1546 void brcmf_usb_exit(void)
1548 struct device_driver
*drv
= &brcmf_usbdrvr
.drvwrap
.driver
;
1551 brcmf_dbg(USB
, "Enter\n");
1552 ret
= driver_for_each_device(drv
, NULL
, NULL
,
1553 brcmf_usb_reset_device
);
1554 usb_deregister(&brcmf_usbdrvr
);
1557 void brcmf_usb_register(void)
1559 brcmf_dbg(USB
, "Enter\n");
1560 usb_register(&brcmf_usbdrvr
);