2 * Copyright (c) 2011 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/kthread.h>
21 #include <linux/slab.h>
22 #include <linux/skbuff.h>
23 #include <linux/netdevice.h>
24 #include <linux/spinlock.h>
25 #include <linux/ethtool.h>
26 #include <linux/fcntl.h>
28 #include <linux/uaccess.h>
29 #include <linux/firmware.h>
30 #include <linux/usb.h>
31 #include <linux/vmalloc.h>
32 #include <net/cfg80211.h>
35 #include <brcmu_utils.h>
36 #include <brcmu_wifi.h>
43 #define IOCTL_RESP_TIMEOUT 2000
45 #define BRCMF_USB_SYNC_TIMEOUT 300 /* ms */
46 #define BRCMF_USB_DLIMAGE_SPINWAIT 100 /* in unit of ms */
47 #define BRCMF_USB_DLIMAGE_LIMIT 500 /* spinwait limit (ms) */
49 #define BRCMF_POSTBOOT_ID 0xA123 /* ID to detect if dongle
51 #define BRCMF_USB_RESETCFG_SPINWAIT 1 /* wait after resetcfg (ms) */
53 #define BRCMF_USB_NRXQ 50
54 #define BRCMF_USB_NTXQ 50
56 #define CONFIGDESC(usb) (&((usb)->actconfig)->desc)
57 #define IFPTR(usb, idx) ((usb)->actconfig->interface[(idx)])
58 #define IFALTS(usb, idx) (IFPTR((usb), (idx))->altsetting[0])
59 #define IFDESC(usb, idx) IFALTS((usb), (idx)).desc
60 #define IFEPDESC(usb, idx, ep) (IFALTS((usb), (idx)).endpoint[(ep)]).desc
65 #define BRCMF_USB_CBCTL_WRITE 0
66 #define BRCMF_USB_CBCTL_READ 1
67 #define BRCMF_USB_MAX_PKT_SIZE 1600
69 #define BRCMF_USB_43143_FW_NAME "brcm/brcmfmac43143.bin"
70 #define BRCMF_USB_43236_FW_NAME "brcm/brcmfmac43236b.bin"
71 #define BRCMF_USB_43242_FW_NAME "brcm/brcmfmac43242a.bin"
73 enum usbdev_suspend_state {
74 USBOS_SUSPEND_STATE_DEVICE_ACTIVE = 0, /* Device is busy, won't allow
76 USBOS_SUSPEND_STATE_SUSPEND_PENDING, /* Device is idle, can be
77 * suspended. Wating PM to
80 USBOS_SUSPEND_STATE_SUSPENDED /* Device suspended */
83 struct brcmf_usb_image {
84 struct list_head list;
89 static struct list_head fw_image_list;
91 struct intr_transfer_buf {
96 struct brcmf_usbdev_info {
97 struct brcmf_usbdev bus_pub; /* MUST BE FIRST */
99 struct list_head rx_freeq;
100 struct list_head rx_postq;
101 struct list_head tx_freeq;
102 struct list_head tx_postq;
103 enum usbdev_suspend_state suspend_state;
104 uint rx_pipe, tx_pipe, intr_pipe, rx_pipe2;
107 int rx_low_watermark;
108 int tx_low_watermark;
109 int tx_high_watermark;
113 struct brcmf_usbreq *tx_reqs;
114 struct brcmf_usbreq *rx_reqs;
116 u8 *image; /* buffer for combine fw and nvram */
119 wait_queue_head_t wait;
123 struct usb_device *usbdev;
126 int ctl_in_pipe, ctl_out_pipe;
127 struct urb *ctl_urb; /* URB for control endpoint */
128 struct usb_ctrlrequest ctl_write;
129 struct usb_ctrlrequest ctl_read;
130 u32 ctl_urb_actual_length;
133 wait_queue_head_t ioctl_resp_wait;
134 wait_queue_head_t ctrl_wait;
137 struct urb *bulk_urb; /* used for FW download */
138 struct urb *intr_urb; /* URB for interrupt endpoint */
139 int intr_size; /* Size of interrupt message */
140 int interval; /* Interrupt polling interval */
141 struct intr_transfer_buf intr; /* Data buffer for interrupt endpoint */
144 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo,
145 struct brcmf_usbreq *req);
147 MODULE_AUTHOR("Broadcom Corporation");
148 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac usb driver.");
149 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac usb cards");
150 MODULE_LICENSE("Dual BSD/GPL");
152 static struct brcmf_usbdev *brcmf_usb_get_buspub(struct device *dev)
154 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
155 return bus_if->bus_priv.usb;
158 static struct brcmf_usbdev_info *brcmf_usb_get_businfo(struct device *dev)
160 return brcmf_usb_get_buspub(dev)->devinfo;
163 static int brcmf_usb_ioctl_resp_wait(struct brcmf_usbdev_info *devinfo)
165 return wait_event_timeout(devinfo->ioctl_resp_wait,
166 devinfo->ctl_completed,
167 msecs_to_jiffies(IOCTL_RESP_TIMEOUT));
170 static void brcmf_usb_ioctl_resp_wake(struct brcmf_usbdev_info *devinfo)
172 if (waitqueue_active(&devinfo->ioctl_resp_wait))
173 wake_up(&devinfo->ioctl_resp_wait);
177 brcmf_usb_ctl_complete(struct brcmf_usbdev_info *devinfo, int type, int status)
180 if (unlikely(devinfo == NULL))
183 if (type == BRCMF_USB_CBCTL_READ) {
185 devinfo->bus_pub.stats.rx_ctlpkts++;
187 devinfo->bus_pub.stats.rx_ctlerrs++;
188 } else if (type == BRCMF_USB_CBCTL_WRITE) {
190 devinfo->bus_pub.stats.tx_ctlpkts++;
192 devinfo->bus_pub.stats.tx_ctlerrs++;
195 devinfo->ctl_urb_status = status;
196 devinfo->ctl_completed = true;
197 brcmf_usb_ioctl_resp_wake(devinfo);
201 brcmf_usb_ctlread_complete(struct urb *urb)
203 struct brcmf_usbdev_info *devinfo =
204 (struct brcmf_usbdev_info *)urb->context;
206 devinfo->ctl_urb_actual_length = urb->actual_length;
207 brcmf_usb_ctl_complete(devinfo, BRCMF_USB_CBCTL_READ,
212 brcmf_usb_ctlwrite_complete(struct urb *urb)
214 struct brcmf_usbdev_info *devinfo =
215 (struct brcmf_usbdev_info *)urb->context;
217 brcmf_usb_ctl_complete(devinfo, BRCMF_USB_CBCTL_WRITE,
221 static int brcmf_usb_pnp(struct brcmf_usbdev_info *devinfo, uint state)
227 brcmf_usb_send_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len)
232 if (devinfo == NULL || buf == NULL ||
233 len == 0 || devinfo->ctl_urb == NULL)
236 /* If the USB/HSIC bus in sleep state, wake it up */
237 if (devinfo->suspend_state == USBOS_SUSPEND_STATE_SUSPENDED)
238 if (brcmf_usb_pnp(devinfo, BCMFMAC_USB_PNP_RESUME) != 0) {
239 brcmf_dbg(ERROR, "Could not Resume the bus!\n");
243 devinfo->activity = true;
245 devinfo->ctl_write.wLength = cpu_to_le16p(&size);
246 devinfo->ctl_urb->transfer_buffer_length = size;
247 devinfo->ctl_urb_status = 0;
248 devinfo->ctl_urb_actual_length = 0;
250 usb_fill_control_urb(devinfo->ctl_urb,
252 devinfo->ctl_out_pipe,
253 (unsigned char *) &devinfo->ctl_write,
255 (usb_complete_t)brcmf_usb_ctlwrite_complete,
258 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC);
260 brcmf_dbg(ERROR, "usb_submit_urb failed %d\n", ret);
266 brcmf_usb_recv_ctl(struct brcmf_usbdev_info *devinfo, u8 *buf, int len)
271 if ((devinfo == NULL) || (buf == NULL) || (len == 0)
272 || (devinfo->ctl_urb == NULL))
276 devinfo->ctl_read.wLength = cpu_to_le16p(&size);
277 devinfo->ctl_urb->transfer_buffer_length = size;
279 devinfo->ctl_read.bRequestType = USB_DIR_IN
280 | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
281 devinfo->ctl_read.bRequest = 1;
283 usb_fill_control_urb(devinfo->ctl_urb,
285 devinfo->ctl_in_pipe,
286 (unsigned char *) &devinfo->ctl_read,
288 (usb_complete_t)brcmf_usb_ctlread_complete,
291 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC);
293 brcmf_dbg(ERROR, "usb_submit_urb failed %d\n", ret);
298 static int brcmf_usb_tx_ctlpkt(struct device *dev, u8 *buf, u32 len)
302 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
304 if (devinfo->bus_pub.state != BCMFMAC_USB_STATE_UP) {
305 /* TODO: handle suspend/resume */
309 if (test_and_set_bit(0, &devinfo->ctl_op))
312 devinfo->ctl_completed = false;
313 err = brcmf_usb_send_ctl(devinfo, buf, len);
315 brcmf_dbg(ERROR, "fail %d bytes: %d\n", err, len);
316 clear_bit(0, &devinfo->ctl_op);
319 timeout = brcmf_usb_ioctl_resp_wait(devinfo);
320 clear_bit(0, &devinfo->ctl_op);
322 brcmf_dbg(ERROR, "Txctl wait timed out\n");
328 static int brcmf_usb_rx_ctlpkt(struct device *dev, u8 *buf, u32 len)
332 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
334 if (devinfo->bus_pub.state != BCMFMAC_USB_STATE_UP) {
335 /* TODO: handle suspend/resume */
338 if (test_and_set_bit(0, &devinfo->ctl_op))
341 devinfo->ctl_completed = false;
342 err = brcmf_usb_recv_ctl(devinfo, buf, len);
344 brcmf_dbg(ERROR, "fail %d bytes: %d\n", err, len);
345 clear_bit(0, &devinfo->ctl_op);
348 timeout = brcmf_usb_ioctl_resp_wait(devinfo);
349 err = devinfo->ctl_urb_status;
350 clear_bit(0, &devinfo->ctl_op);
352 brcmf_dbg(ERROR, "rxctl wait timed out\n");
356 return devinfo->ctl_urb_actual_length;
361 static struct brcmf_usbreq *brcmf_usb_deq(struct brcmf_usbdev_info *devinfo,
362 struct list_head *q, int *counter)
365 struct brcmf_usbreq *req;
366 spin_lock_irqsave(&devinfo->qlock, flags);
368 spin_unlock_irqrestore(&devinfo->qlock, flags);
371 req = list_entry(q->next, struct brcmf_usbreq, list);
372 list_del_init(q->next);
375 spin_unlock_irqrestore(&devinfo->qlock, flags);
380 static void brcmf_usb_enq(struct brcmf_usbdev_info *devinfo,
381 struct list_head *q, struct brcmf_usbreq *req,
385 spin_lock_irqsave(&devinfo->qlock, flags);
386 list_add_tail(&req->list, q);
389 spin_unlock_irqrestore(&devinfo->qlock, flags);
392 static struct brcmf_usbreq *
393 brcmf_usbdev_qinit(struct list_head *q, int qsize)
396 struct brcmf_usbreq *req, *reqs;
398 reqs = kzalloc(sizeof(struct brcmf_usbreq) * qsize, GFP_ATOMIC);
400 brcmf_dbg(ERROR, "fail to allocate memory!\n");
405 for (i = 0; i < qsize; i++) {
406 req->urb = usb_alloc_urb(0, GFP_ATOMIC);
410 INIT_LIST_HEAD(&req->list);
411 list_add_tail(&req->list, q);
416 brcmf_dbg(ERROR, "fail!\n");
417 while (!list_empty(q)) {
418 req = list_entry(q->next, struct brcmf_usbreq, list);
420 usb_free_urb(req->urb);
427 static void brcmf_usb_free_q(struct list_head *q, bool pending)
429 struct brcmf_usbreq *req, *next;
431 list_for_each_entry_safe(req, next, q, list) {
433 brcmf_dbg(ERROR, "bad req\n");
438 usb_kill_urb(req->urb);
440 usb_free_urb(req->urb);
441 list_del_init(&req->list);
446 static void brcmf_usb_del_fromq(struct brcmf_usbdev_info *devinfo,
447 struct brcmf_usbreq *req)
451 spin_lock_irqsave(&devinfo->qlock, flags);
452 list_del_init(&req->list);
453 spin_unlock_irqrestore(&devinfo->qlock, flags);
457 static void brcmf_usb_tx_complete(struct urb *urb)
459 struct brcmf_usbreq *req = (struct brcmf_usbreq *)urb->context;
460 struct brcmf_usbdev_info *devinfo = req->devinfo;
462 brcmf_usb_del_fromq(devinfo, req);
463 if (urb->status == 0)
464 devinfo->bus_pub.bus->dstats.tx_packets++;
466 devinfo->bus_pub.bus->dstats.tx_errors++;
468 brcmf_txcomplete(devinfo->dev, req->skb, urb->status == 0);
470 brcmu_pkt_buf_free_skb(req->skb);
472 brcmf_usb_enq(devinfo, &devinfo->tx_freeq, req, &devinfo->tx_freecount);
473 if (devinfo->tx_freecount > devinfo->tx_high_watermark &&
474 devinfo->tx_flowblock) {
475 brcmf_txflowblock(devinfo->dev, false);
476 devinfo->tx_flowblock = false;
480 static void brcmf_usb_rx_complete(struct urb *urb)
482 struct brcmf_usbreq *req = (struct brcmf_usbreq *)urb->context;
483 struct brcmf_usbdev_info *devinfo = req->devinfo;
487 brcmf_usb_del_fromq(devinfo, req);
491 if (urb->status == 0) {
492 devinfo->bus_pub.bus->dstats.rx_packets++;
494 devinfo->bus_pub.bus->dstats.rx_errors++;
495 brcmu_pkt_buf_free_skb(skb);
496 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req, NULL);
500 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_UP) {
501 skb_put(skb, urb->actual_length);
502 if (brcmf_proto_hdrpull(devinfo->dev, &ifidx, skb) != 0) {
503 brcmf_dbg(ERROR, "rx protocol error\n");
504 brcmu_pkt_buf_free_skb(skb);
505 devinfo->bus_pub.bus->dstats.rx_errors++;
507 brcmf_rx_packet(devinfo->dev, ifidx, skb);
508 brcmf_usb_rx_refill(devinfo, req);
510 brcmu_pkt_buf_free_skb(skb);
511 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req, NULL);
517 static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo,
518 struct brcmf_usbreq *req)
523 if (!req || !devinfo)
526 skb = dev_alloc_skb(devinfo->bus_pub.bus_mtu);
528 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req, NULL);
533 usb_fill_bulk_urb(req->urb, devinfo->usbdev, devinfo->rx_pipe,
534 skb->data, skb_tailroom(skb), brcmf_usb_rx_complete,
536 req->devinfo = devinfo;
537 brcmf_usb_enq(devinfo, &devinfo->rx_postq, req, NULL);
539 ret = usb_submit_urb(req->urb, GFP_ATOMIC);
541 brcmf_usb_del_fromq(devinfo, req);
542 brcmu_pkt_buf_free_skb(req->skb);
544 brcmf_usb_enq(devinfo, &devinfo->rx_freeq, req, NULL);
549 static void brcmf_usb_rx_fill_all(struct brcmf_usbdev_info *devinfo)
551 struct brcmf_usbreq *req;
553 if (devinfo->bus_pub.state != BCMFMAC_USB_STATE_UP) {
554 brcmf_dbg(ERROR, "bus is not up\n");
557 while ((req = brcmf_usb_deq(devinfo, &devinfo->rx_freeq, NULL)) != NULL)
558 brcmf_usb_rx_refill(devinfo, req);
562 brcmf_usb_state_change(struct brcmf_usbdev_info *devinfo, int state)
564 struct brcmf_bus *bcmf_bus = devinfo->bus_pub.bus;
568 if (devinfo->bus_pub.state == state)
571 old_state = devinfo->bus_pub.state;
572 brcmf_dbg(TRACE, "dbus state change from %d to to %d\n",
575 /* Don't update state if it's PnP firmware re-download */
576 if (state != BCMFMAC_USB_STATE_PNP_FWDL) /* TODO */
577 devinfo->bus_pub.state = state;
579 if ((old_state == BCMFMAC_USB_STATE_SLEEP)
580 && (state == BCMFMAC_USB_STATE_UP)) {
581 brcmf_usb_rx_fill_all(devinfo);
584 /* update state of upper layer */
585 if (state == BCMFMAC_USB_STATE_DOWN) {
586 brcmf_dbg(INFO, "DBUS is down\n");
587 bcmf_bus->state = BRCMF_BUS_DOWN;
589 brcmf_dbg(INFO, "DBUS current state=%d\n", state);
594 brcmf_usb_intr_complete(struct urb *urb)
596 struct brcmf_usbdev_info *devinfo =
597 (struct brcmf_usbdev_info *)urb->context;
603 if (unlikely(urb->status)) {
604 if (devinfo->suspend_state ==
605 USBOS_SUSPEND_STATE_SUSPEND_PENDING)
608 if ((urb->status == -ENOENT && (!killed))
609 || urb->status == -ESHUTDOWN ||
610 urb->status == -ENODEV) {
611 brcmf_usb_state_change(devinfo, BCMFMAC_USB_STATE_DOWN);
615 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_DOWN) {
616 brcmf_dbg(ERROR, "intr cb when DBUS down, ignoring\n");
620 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_UP)
621 usb_submit_urb(devinfo->intr_urb, GFP_ATOMIC);
624 static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb)
626 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
627 struct brcmf_usbreq *req;
630 if (devinfo->bus_pub.state != BCMFMAC_USB_STATE_UP) {
631 /* TODO: handle suspend/resume */
635 req = brcmf_usb_deq(devinfo, &devinfo->tx_freeq,
636 &devinfo->tx_freecount);
638 brcmu_pkt_buf_free_skb(skb);
639 brcmf_dbg(ERROR, "no req to send\n");
644 req->devinfo = devinfo;
645 usb_fill_bulk_urb(req->urb, devinfo->usbdev, devinfo->tx_pipe,
646 skb->data, skb->len, brcmf_usb_tx_complete, req);
647 req->urb->transfer_flags |= URB_ZERO_PACKET;
648 brcmf_usb_enq(devinfo, &devinfo->tx_postq, req, NULL);
649 ret = usb_submit_urb(req->urb, GFP_ATOMIC);
651 brcmf_dbg(ERROR, "brcmf_usb_tx usb_submit_urb FAILED\n");
652 brcmf_usb_del_fromq(devinfo, req);
653 brcmu_pkt_buf_free_skb(req->skb);
655 brcmf_usb_enq(devinfo, &devinfo->tx_freeq, req,
656 &devinfo->tx_freecount);
658 if (devinfo->tx_freecount < devinfo->tx_low_watermark &&
659 !devinfo->tx_flowblock) {
660 brcmf_txflowblock(dev, true);
661 devinfo->tx_flowblock = true;
669 static int brcmf_usb_up(struct device *dev)
671 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
674 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_UP)
677 /* If the USB/HSIC bus in sleep state, wake it up */
678 if (devinfo->suspend_state == USBOS_SUSPEND_STATE_SUSPENDED) {
679 if (brcmf_usb_pnp(devinfo, BCMFMAC_USB_PNP_RESUME) != 0) {
680 brcmf_dbg(ERROR, "Could not Resume the bus!\n");
684 devinfo->activity = true;
686 /* Success, indicate devinfo is fully up */
687 brcmf_usb_state_change(devinfo, BCMFMAC_USB_STATE_UP);
689 if (devinfo->intr_urb) {
692 usb_fill_int_urb(devinfo->intr_urb, devinfo->usbdev,
696 (usb_complete_t)brcmf_usb_intr_complete,
700 ret = usb_submit_urb(devinfo->intr_urb, GFP_ATOMIC);
702 brcmf_dbg(ERROR, "USB_SUBMIT_URB failed with status %d\n",
708 if (devinfo->ctl_urb) {
709 devinfo->ctl_in_pipe = usb_rcvctrlpipe(devinfo->usbdev, 0);
710 devinfo->ctl_out_pipe = usb_sndctrlpipe(devinfo->usbdev, 0);
712 ifnum = IFDESC(devinfo->usbdev, CONTROL_IF).bInterfaceNumber;
715 devinfo->ctl_write.bRequestType =
716 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
717 devinfo->ctl_write.bRequest = 0;
718 devinfo->ctl_write.wValue = cpu_to_le16(0);
719 devinfo->ctl_write.wIndex = cpu_to_le16p(&ifnum);
722 devinfo->ctl_read.bRequestType =
723 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
724 devinfo->ctl_read.bRequest = 1;
725 devinfo->ctl_read.wValue = cpu_to_le16(0);
726 devinfo->ctl_read.wIndex = cpu_to_le16p(&ifnum);
728 brcmf_usb_rx_fill_all(devinfo);
732 static void brcmf_usb_down(struct device *dev)
734 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
739 brcmf_dbg(TRACE, "enter\n");
740 if (devinfo->bus_pub.state == BCMFMAC_USB_STATE_DOWN)
743 brcmf_usb_state_change(devinfo, BCMFMAC_USB_STATE_DOWN);
744 if (devinfo->intr_urb)
745 usb_kill_urb(devinfo->intr_urb);
747 if (devinfo->ctl_urb)
748 usb_kill_urb(devinfo->ctl_urb);
750 if (devinfo->bulk_urb)
751 usb_kill_urb(devinfo->bulk_urb);
752 brcmf_usb_free_q(&devinfo->tx_postq, true);
754 brcmf_usb_free_q(&devinfo->rx_postq, true);
758 brcmf_usb_sync_wait(struct brcmf_usbdev_info *devinfo, u16 time)
764 ret = wait_event_interruptible_timeout(devinfo->wait,
765 devinfo->waitdone == true, (ms * HZ / 1000));
767 if ((devinfo->waitdone == false) || (devinfo->sync_urb_status)) {
768 brcmf_dbg(ERROR, "timeout(%d) or urb err=%d\n",
769 ret, devinfo->sync_urb_status);
772 devinfo->waitdone = false;
777 brcmf_usb_sync_complete(struct urb *urb)
779 struct brcmf_usbdev_info *devinfo =
780 (struct brcmf_usbdev_info *)urb->context;
782 devinfo->waitdone = true;
783 wake_up_interruptible(&devinfo->wait);
784 devinfo->sync_urb_status = urb->status;
787 static bool brcmf_usb_dl_cmd(struct brcmf_usbdev_info *devinfo, u8 cmd,
788 void *buffer, int buflen)
794 if ((!devinfo) || (devinfo->ctl_urb == NULL))
797 tmpbuf = kmalloc(buflen, GFP_ATOMIC);
802 devinfo->ctl_urb->transfer_buffer_length = size;
804 devinfo->ctl_read.wLength = cpu_to_le16p(&size);
805 devinfo->ctl_read.bRequestType = USB_DIR_IN | USB_TYPE_VENDOR |
807 devinfo->ctl_read.bRequest = cmd;
809 usb_fill_control_urb(devinfo->ctl_urb,
811 usb_rcvctrlpipe(devinfo->usbdev, 0),
812 (unsigned char *) &devinfo->ctl_read,
813 (void *) tmpbuf, size,
814 (usb_complete_t)brcmf_usb_sync_complete, devinfo);
816 ret = usb_submit_urb(devinfo->ctl_urb, GFP_ATOMIC);
818 brcmf_dbg(ERROR, "usb_submit_urb failed %d\n", ret);
823 ret = brcmf_usb_sync_wait(devinfo, BRCMF_USB_SYNC_TIMEOUT);
824 memcpy(buffer, tmpbuf, buflen);
831 brcmf_usb_dlneeded(struct brcmf_usbdev_info *devinfo)
833 struct bootrom_id_le id;
836 brcmf_dbg(TRACE, "enter\n");
841 /* Check if firmware downloaded already by querying runtime ID */
842 id.chip = cpu_to_le32(0xDEAD);
843 brcmf_usb_dl_cmd(devinfo, DL_GETVER, &id,
844 sizeof(struct bootrom_id_le));
846 chipid = le32_to_cpu(id.chip);
847 chiprev = le32_to_cpu(id.chiprev);
849 if ((chipid & 0x4300) == 0x4300)
850 brcmf_dbg(INFO, "chip %x rev 0x%x\n", chipid, chiprev);
852 brcmf_dbg(INFO, "chip %d rev 0x%x\n", chipid, chiprev);
853 if (chipid == BRCMF_POSTBOOT_ID) {
854 brcmf_dbg(INFO, "firmware already downloaded\n");
855 brcmf_usb_dl_cmd(devinfo, DL_RESETCFG, &id,
856 sizeof(struct bootrom_id_le));
859 devinfo->bus_pub.devid = chipid;
860 devinfo->bus_pub.chiprev = chiprev;
866 brcmf_usb_resetcfg(struct brcmf_usbdev_info *devinfo)
868 struct bootrom_id_le id;
869 u16 wait = 0, wait_time;
871 brcmf_dbg(TRACE, "enter\n");
876 /* Give dongle chance to boot */
877 wait_time = BRCMF_USB_DLIMAGE_SPINWAIT;
878 while (wait < BRCMF_USB_DLIMAGE_LIMIT) {
881 id.chip = cpu_to_le32(0xDEAD); /* Get the ID */
882 brcmf_usb_dl_cmd(devinfo, DL_GETVER, &id,
883 sizeof(struct bootrom_id_le));
884 if (id.chip == cpu_to_le32(BRCMF_POSTBOOT_ID))
888 if (id.chip == cpu_to_le32(BRCMF_POSTBOOT_ID)) {
889 brcmf_dbg(INFO, "download done %d ms postboot chip 0x%x/rev 0x%x\n",
890 wait, le32_to_cpu(id.chip), le32_to_cpu(id.chiprev));
892 brcmf_usb_dl_cmd(devinfo, DL_RESETCFG, &id,
893 sizeof(struct bootrom_id_le));
895 /* XXX this wait may not be necessary */
896 mdelay(BRCMF_USB_RESETCFG_SPINWAIT);
899 brcmf_dbg(ERROR, "Cannot talk to Dongle. Firmware is not UP, %d ms\n",
907 brcmf_usb_dl_send_bulk(struct brcmf_usbdev_info *devinfo, void *buffer, int len)
911 if ((devinfo == NULL) || (devinfo->bulk_urb == NULL))
914 /* Prepare the URB */
915 usb_fill_bulk_urb(devinfo->bulk_urb, devinfo->usbdev,
916 devinfo->tx_pipe, buffer, len,
917 (usb_complete_t)brcmf_usb_sync_complete, devinfo);
919 devinfo->bulk_urb->transfer_flags |= URB_ZERO_PACKET;
921 ret = usb_submit_urb(devinfo->bulk_urb, GFP_ATOMIC);
923 brcmf_dbg(ERROR, "usb_submit_urb failed %d\n", ret);
926 ret = brcmf_usb_sync_wait(devinfo, BRCMF_USB_SYNC_TIMEOUT);
931 brcmf_usb_dl_writeimage(struct brcmf_usbdev_info *devinfo, u8 *fw, int fwlen)
933 unsigned int sendlen, sent, dllen;
934 char *bulkchunk = NULL, *dlpos;
935 struct rdl_state_le state;
936 u32 rdlstate, rdlbytes;
938 brcmf_dbg(TRACE, "fw %p, len %d\n", fw, fwlen);
940 bulkchunk = kmalloc(RDL_CHUNK, GFP_ATOMIC);
941 if (bulkchunk == NULL) {
946 /* 1) Prepare USB boot loader for runtime image */
947 brcmf_usb_dl_cmd(devinfo, DL_START, &state,
948 sizeof(struct rdl_state_le));
950 rdlstate = le32_to_cpu(state.state);
951 rdlbytes = le32_to_cpu(state.bytes);
953 /* 2) Check we are in the Waiting state */
954 if (rdlstate != DL_WAITING) {
955 brcmf_dbg(ERROR, "Failed to DL_START\n");
963 /* Get chip id and rev */
964 while (rdlbytes != dllen) {
965 /* Wait until the usb device reports it received all
966 * the bytes we sent */
967 if ((rdlbytes == sent) && (rdlbytes != dllen)) {
968 if ((dllen-sent) < RDL_CHUNK)
969 sendlen = dllen-sent;
973 /* simply avoid having to send a ZLP by ensuring we
981 memcpy(bulkchunk, dlpos, sendlen);
982 if (brcmf_usb_dl_send_bulk(devinfo, bulkchunk,
984 brcmf_dbg(ERROR, "send_bulk failed\n");
992 if (!brcmf_usb_dl_cmd(devinfo, DL_GETSTATE, &state,
993 sizeof(struct rdl_state_le))) {
994 brcmf_dbg(ERROR, "DL_GETSTATE Failed xxxx\n");
999 rdlstate = le32_to_cpu(state.state);
1000 rdlbytes = le32_to_cpu(state.bytes);
1002 /* restart if an error is reported */
1003 if (rdlstate == DL_BAD_HDR || rdlstate == DL_BAD_CRC) {
1004 brcmf_dbg(ERROR, "Bad Hdr or Bad CRC state %d\n",
1013 brcmf_dbg(TRACE, "err=%d\n", err);
1017 static int brcmf_usb_dlstart(struct brcmf_usbdev_info *devinfo, u8 *fw, int len)
1021 brcmf_dbg(TRACE, "enter\n");
1023 if (devinfo == NULL)
1026 if (devinfo->bus_pub.devid == 0xDEAD)
1029 err = brcmf_usb_dl_writeimage(devinfo, fw, len);
1031 devinfo->bus_pub.state = BCMFMAC_USB_STATE_DL_DONE;
1033 devinfo->bus_pub.state = BCMFMAC_USB_STATE_DL_PENDING;
1034 brcmf_dbg(TRACE, "exit: err=%d\n", err);
1039 static int brcmf_usb_dlrun(struct brcmf_usbdev_info *devinfo)
1041 struct rdl_state_le state;
1043 brcmf_dbg(TRACE, "enter\n");
1047 if (devinfo->bus_pub.devid == 0xDEAD)
1050 /* Check we are runnable */
1051 brcmf_usb_dl_cmd(devinfo, DL_GETSTATE, &state,
1052 sizeof(struct rdl_state_le));
1054 /* Start the image */
1055 if (state.state == cpu_to_le32(DL_RUNNABLE)) {
1056 if (!brcmf_usb_dl_cmd(devinfo, DL_GO, &state,
1057 sizeof(struct rdl_state_le)))
1059 if (brcmf_usb_resetcfg(devinfo))
1061 /* The Dongle may go for re-enumeration. */
1063 brcmf_dbg(ERROR, "Dongle not runnable\n");
1066 brcmf_dbg(TRACE, "exit\n");
1070 static bool brcmf_usb_chip_support(int chipid, int chiprev)
1078 return (chiprev == 3);
1088 brcmf_usb_fw_download(struct brcmf_usbdev_info *devinfo)
1093 brcmf_dbg(TRACE, "enter\n");
1094 if (devinfo == NULL)
1097 devid = devinfo->bus_pub.devid;
1098 chiprev = devinfo->bus_pub.chiprev;
1100 if (!brcmf_usb_chip_support(devid, chiprev)) {
1101 brcmf_dbg(ERROR, "unsupported chip %d rev %d\n",
1106 if (!devinfo->image) {
1107 brcmf_dbg(ERROR, "No firmware!\n");
1111 err = brcmf_usb_dlstart(devinfo,
1112 devinfo->image, devinfo->image_len);
1114 err = brcmf_usb_dlrun(devinfo);
1119 static void brcmf_usb_detach(struct brcmf_usbdev_info *devinfo)
1121 brcmf_dbg(TRACE, "devinfo %p\n", devinfo);
1124 brcmf_usb_free_q(&devinfo->rx_freeq, false);
1125 brcmf_usb_free_q(&devinfo->tx_freeq, false);
1127 usb_free_urb(devinfo->intr_urb);
1128 usb_free_urb(devinfo->ctl_urb);
1129 usb_free_urb(devinfo->bulk_urb);
1131 kfree(devinfo->tx_reqs);
1132 kfree(devinfo->rx_reqs);
1135 #define TRX_MAGIC 0x30524448 /* "HDR0" */
1136 #define TRX_VERSION 1 /* Version 1 */
1137 #define TRX_MAX_LEN 0x3B0000 /* Max length */
1138 #define TRX_NO_HEADER 1 /* Do not write TRX header */
1139 #define TRX_MAX_OFFSET 3 /* Max number of individual files */
1140 #define TRX_UNCOMP_IMAGE 0x20 /* Trx contains uncompressed image */
1142 struct trx_header_le {
1143 __le32 magic; /* "HDR0" */
1144 __le32 len; /* Length of file including header */
1145 __le32 crc32; /* CRC from flag_version to end of file */
1146 __le32 flag_version; /* 0:15 flags, 16:31 version */
1147 __le32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of
1151 static int check_file(const u8 *headers)
1153 struct trx_header_le *trx;
1154 int actual_len = -1;
1156 /* Extract trx header */
1157 trx = (struct trx_header_le *) headers;
1158 if (trx->magic != cpu_to_le32(TRX_MAGIC))
1161 headers += sizeof(struct trx_header_le);
1163 if (le32_to_cpu(trx->flag_version) & TRX_UNCOMP_IMAGE) {
1164 actual_len = le32_to_cpu(trx->offsets[TRX_OFFSETS_DLFWLEN_IDX]);
1165 return actual_len + sizeof(struct trx_header_le);
1170 static int brcmf_usb_get_fw(struct brcmf_usbdev_info *devinfo)
1173 const struct firmware *fw;
1174 struct brcmf_usb_image *fw_image;
1177 switch (devinfo->bus_pub.devid) {
1179 fwname = BRCMF_USB_43143_FW_NAME;
1184 fwname = BRCMF_USB_43236_FW_NAME;
1187 fwname = BRCMF_USB_43242_FW_NAME;
1194 list_for_each_entry(fw_image, &fw_image_list, list) {
1195 if (fw_image->fwname == fwname) {
1196 devinfo->image = fw_image->image;
1197 devinfo->image_len = fw_image->image_len;
1201 /* fw image not yet loaded. Load it now and add to list */
1202 err = request_firmware(&fw, fwname, devinfo->dev);
1204 brcmf_dbg(ERROR, "fail to request firmware %s\n", fwname);
1207 if (check_file(fw->data) < 0) {
1208 brcmf_dbg(ERROR, "invalid firmware %s\n", fwname);
1212 fw_image = kzalloc(sizeof(*fw_image), GFP_ATOMIC);
1215 INIT_LIST_HEAD(&fw_image->list);
1216 list_add_tail(&fw_image->list, &fw_image_list);
1217 fw_image->fwname = fwname;
1218 fw_image->image = vmalloc(fw->size);
1219 if (!fw_image->image)
1222 memcpy(fw_image->image, fw->data, fw->size);
1223 fw_image->image_len = fw->size;
1225 release_firmware(fw);
1227 devinfo->image = fw_image->image;
1228 devinfo->image_len = fw_image->image_len;
1235 struct brcmf_usbdev *brcmf_usb_attach(struct brcmf_usbdev_info *devinfo,
1238 devinfo->bus_pub.nrxq = nrxq;
1239 devinfo->rx_low_watermark = nrxq / 2;
1240 devinfo->bus_pub.devinfo = devinfo;
1241 devinfo->bus_pub.ntxq = ntxq;
1243 /* flow control when too many tx urbs posted */
1244 devinfo->tx_low_watermark = ntxq / 4;
1245 devinfo->tx_high_watermark = devinfo->tx_low_watermark * 3;
1246 devinfo->bus_pub.bus_mtu = BRCMF_USB_MAX_PKT_SIZE;
1248 /* Initialize other structure content */
1249 init_waitqueue_head(&devinfo->ioctl_resp_wait);
1251 /* Initialize the spinlocks */
1252 spin_lock_init(&devinfo->qlock);
1254 INIT_LIST_HEAD(&devinfo->rx_freeq);
1255 INIT_LIST_HEAD(&devinfo->rx_postq);
1257 INIT_LIST_HEAD(&devinfo->tx_freeq);
1258 INIT_LIST_HEAD(&devinfo->tx_postq);
1260 devinfo->tx_flowblock = false;
1262 devinfo->rx_reqs = brcmf_usbdev_qinit(&devinfo->rx_freeq, nrxq);
1263 if (!devinfo->rx_reqs)
1266 devinfo->tx_reqs = brcmf_usbdev_qinit(&devinfo->tx_freeq, ntxq);
1267 if (!devinfo->tx_reqs)
1269 devinfo->tx_freecount = ntxq;
1271 devinfo->intr_urb = usb_alloc_urb(0, GFP_ATOMIC);
1272 if (!devinfo->intr_urb) {
1273 brcmf_dbg(ERROR, "usb_alloc_urb (intr) failed\n");
1276 devinfo->ctl_urb = usb_alloc_urb(0, GFP_ATOMIC);
1277 if (!devinfo->ctl_urb) {
1278 brcmf_dbg(ERROR, "usb_alloc_urb (ctl) failed\n");
1281 devinfo->bulk_urb = usb_alloc_urb(0, GFP_ATOMIC);
1282 if (!devinfo->bulk_urb) {
1283 brcmf_dbg(ERROR, "usb_alloc_urb (bulk) failed\n");
1287 init_waitqueue_head(&devinfo->wait);
1288 if (!brcmf_usb_dlneeded(devinfo))
1289 return &devinfo->bus_pub;
1291 brcmf_dbg(TRACE, "start fw downloading\n");
1292 if (brcmf_usb_get_fw(devinfo))
1295 if (brcmf_usb_fw_download(devinfo))
1298 return &devinfo->bus_pub;
1301 brcmf_dbg(ERROR, "failed!\n");
1302 brcmf_usb_detach(devinfo);
1306 static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo,
1307 const char *desc, u32 bustype, u32 hdrlen)
1309 struct brcmf_bus *bus = NULL;
1310 struct brcmf_usbdev *bus_pub = NULL;
1312 struct device *dev = devinfo->dev;
1314 bus_pub = brcmf_usb_attach(devinfo, BRCMF_USB_NRXQ, BRCMF_USB_NTXQ);
1318 bus = kzalloc(sizeof(struct brcmf_bus), GFP_ATOMIC);
1325 bus->brcmf_bus_txdata = brcmf_usb_tx;
1326 bus->brcmf_bus_init = brcmf_usb_up;
1327 bus->brcmf_bus_stop = brcmf_usb_down;
1328 bus->brcmf_bus_txctl = brcmf_usb_tx_ctlpkt;
1329 bus->brcmf_bus_rxctl = brcmf_usb_rx_ctlpkt;
1330 bus->type = bustype;
1331 bus->bus_priv.usb = bus_pub;
1332 dev_set_drvdata(dev, bus);
1334 /* Attach to the common driver interface */
1335 ret = brcmf_attach(hdrlen, dev);
1337 brcmf_dbg(ERROR, "dhd_attach failed\n");
1341 ret = brcmf_bus_start(dev);
1342 if (ret == -ENOLINK) {
1343 brcmf_dbg(ERROR, "dongle is not responding\n");
1350 /* Release resources in reverse order */
1352 brcmf_usb_detach(devinfo);
1357 brcmf_usb_disconnect_cb(struct brcmf_usbdev_info *devinfo)
1361 brcmf_dbg(TRACE, "enter: bus_pub %p\n", devinfo);
1363 brcmf_detach(devinfo->dev);
1364 kfree(devinfo->bus_pub.bus);
1365 brcmf_usb_detach(devinfo);
1369 brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1372 struct usb_endpoint_descriptor *endpoint;
1374 struct usb_device *usb = interface_to_usbdev(intf);
1377 struct brcmf_usbdev_info *devinfo;
1379 brcmf_dbg(TRACE, "enter\n");
1381 devinfo = kzalloc(sizeof(*devinfo), GFP_ATOMIC);
1382 if (devinfo == NULL)
1385 devinfo->usbdev = usb;
1386 devinfo->dev = &usb->dev;
1388 usb_set_intfdata(intf, devinfo);
1390 /* Check that the device supports only one configuration */
1391 if (usb->descriptor.bNumConfigurations != 1) {
1396 if (usb->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) {
1402 * Only the BDC interface configuration is supported:
1403 * Device class: USB_CLASS_VENDOR_SPEC
1404 * if0 class: USB_CLASS_VENDOR_SPEC
1407 * if0/ep2: bulk out (ok if swapped with bulk in)
1409 if (CONFIGDESC(usb)->bNumInterfaces != 1) {
1414 /* Check interface */
1415 if (IFDESC(usb, CONTROL_IF).bInterfaceClass != USB_CLASS_VENDOR_SPEC ||
1416 IFDESC(usb, CONTROL_IF).bInterfaceSubClass != 2 ||
1417 IFDESC(usb, CONTROL_IF).bInterfaceProtocol != 0xff) {
1418 brcmf_dbg(ERROR, "invalid control interface: class %d, subclass %d, proto %d\n",
1419 IFDESC(usb, CONTROL_IF).bInterfaceClass,
1420 IFDESC(usb, CONTROL_IF).bInterfaceSubClass,
1421 IFDESC(usb, CONTROL_IF).bInterfaceProtocol);
1426 /* Check control endpoint */
1427 endpoint = &IFEPDESC(usb, CONTROL_IF, 0);
1428 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
1429 != USB_ENDPOINT_XFER_INT) {
1430 brcmf_dbg(ERROR, "invalid control endpoint %d\n",
1431 endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK);
1436 endpoint_num = endpoint->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
1437 devinfo->intr_pipe = usb_rcvintpipe(usb, endpoint_num);
1439 devinfo->rx_pipe = 0;
1440 devinfo->rx_pipe2 = 0;
1441 devinfo->tx_pipe = 0;
1442 num_of_eps = IFDESC(usb, BULK_IF).bNumEndpoints - 1;
1444 /* Check data endpoints and get pipes */
1445 for (ep = 1; ep <= num_of_eps; ep++) {
1446 endpoint = &IFEPDESC(usb, BULK_IF, ep);
1447 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
1448 USB_ENDPOINT_XFER_BULK) {
1449 brcmf_dbg(ERROR, "invalid data endpoint %d\n", ep);
1454 endpoint_num = endpoint->bEndpointAddress &
1455 USB_ENDPOINT_NUMBER_MASK;
1456 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
1458 if (!devinfo->rx_pipe) {
1460 usb_rcvbulkpipe(usb, endpoint_num);
1463 usb_rcvbulkpipe(usb, endpoint_num);
1466 devinfo->tx_pipe = usb_sndbulkpipe(usb, endpoint_num);
1470 /* Allocate interrupt URB and data buffer */
1471 /* RNDIS says 8-byte intr, our old drivers used 4-byte */
1472 if (IFEPDESC(usb, CONTROL_IF, 0).wMaxPacketSize == cpu_to_le16(16))
1473 devinfo->intr_size = 8;
1475 devinfo->intr_size = 4;
1477 devinfo->interval = IFEPDESC(usb, CONTROL_IF, 0).bInterval;
1479 if (usb->speed == USB_SPEED_HIGH)
1480 brcmf_dbg(INFO, "Broadcom high speed USB wireless device detected\n");
1482 brcmf_dbg(INFO, "Broadcom full speed USB wireless device detected\n");
1484 ret = brcmf_usb_probe_cb(devinfo, "", USB_BUS, 0);
1492 brcmf_dbg(ERROR, "failed with errno %d\n", ret);
1494 usb_set_intfdata(intf, NULL);
1500 brcmf_usb_disconnect(struct usb_interface *intf)
1502 struct brcmf_usbdev_info *devinfo;
1504 brcmf_dbg(TRACE, "enter\n");
1505 devinfo = (struct brcmf_usbdev_info *)usb_get_intfdata(intf);
1506 brcmf_usb_disconnect_cb(devinfo);
1511 * only need to signal the bus being down and update the suspend state.
1513 static int brcmf_usb_suspend(struct usb_interface *intf, pm_message_t state)
1515 struct usb_device *usb = interface_to_usbdev(intf);
1516 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
1518 brcmf_dbg(TRACE, "enter\n");
1519 devinfo->bus_pub.state = BCMFMAC_USB_STATE_DOWN;
1520 devinfo->suspend_state = USBOS_SUSPEND_STATE_SUSPENDED;
1525 * mark suspend state active and crank up the bus.
1527 static int brcmf_usb_resume(struct usb_interface *intf)
1529 struct usb_device *usb = interface_to_usbdev(intf);
1530 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
1532 brcmf_dbg(TRACE, "enter\n");
1533 devinfo->suspend_state = USBOS_SUSPEND_STATE_DEVICE_ACTIVE;
1534 brcmf_bus_start(&usb->dev);
1538 #define BRCMF_USB_VENDOR_ID_BROADCOM 0x0a5c
1539 #define BRCMF_USB_DEVICE_ID_43143 0xbd1e
1540 #define BRCMF_USB_DEVICE_ID_43236 0xbd17
1541 #define BRCMF_USB_DEVICE_ID_43242 0xbd1f
1542 #define BRCMF_USB_DEVICE_ID_BCMFW 0x0bdc
1544 static struct usb_device_id brcmf_usb_devid_table[] = {
1545 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM, BRCMF_USB_DEVICE_ID_43143) },
1546 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM, BRCMF_USB_DEVICE_ID_43236) },
1547 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM, BRCMF_USB_DEVICE_ID_43242) },
1548 /* special entry for device with firmware loaded and running */
1549 { USB_DEVICE(BRCMF_USB_VENDOR_ID_BROADCOM, BRCMF_USB_DEVICE_ID_BCMFW) },
1552 MODULE_DEVICE_TABLE(usb, brcmf_usb_devid_table);
1553 MODULE_FIRMWARE(BRCMF_USB_43143_FW_NAME);
1554 MODULE_FIRMWARE(BRCMF_USB_43236_FW_NAME);
1555 MODULE_FIRMWARE(BRCMF_USB_43242_FW_NAME);
1557 /* TODO: suspend and resume entries */
1558 static struct usb_driver brcmf_usbdrvr = {
1559 .name = KBUILD_MODNAME,
1560 .probe = brcmf_usb_probe,
1561 .disconnect = brcmf_usb_disconnect,
1562 .id_table = brcmf_usb_devid_table,
1563 .suspend = brcmf_usb_suspend,
1564 .resume = brcmf_usb_resume,
1565 .supports_autosuspend = 1,
1566 .disable_hub_initiated_lpm = 1,
1569 static void brcmf_release_fw(struct list_head *q)
1571 struct brcmf_usb_image *fw_image, *next;
1573 list_for_each_entry_safe(fw_image, next, q, list) {
1574 vfree(fw_image->image);
1575 list_del_init(&fw_image->list);
1580 void brcmf_usb_exit(void)
1582 usb_deregister(&brcmf_usbdrvr);
1583 brcmf_release_fw(&fw_image_list);
1586 void brcmf_usb_init(void)
1588 INIT_LIST_HEAD(&fw_image_list);
1589 usb_register(&brcmf_usbdrvr);