18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/slab.h>
23 #include <linux/netdevice.h>
25 #include <linux/ethtool.h>
26 #include <linux/fcntl.h>
43 #define IOCTL_RESP_TIMEOUT 2000
45 #define BRCMF_USB_SYNC_TIMEOUT 300
46 #define BRCMF_USB_DLIMAGE_SPINWAIT 100
47 #define BRCMF_USB_DLIMAGE_LIMIT 500
49 #define BRCMF_POSTBOOT_ID 0xA123
51 #define BRCMF_USB_RESETCFG_SPINWAIT 1
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"
160 return brcmf_usb_get_buspub(dev)->devinfo;
185 devinfo->
bus_pub.stats.rx_ctlpkts++;
187 devinfo->
bus_pub.stats.rx_ctlerrs++;
190 devinfo->
bus_pub.stats.tx_ctlpkts++;
192 devinfo->
bus_pub.stats.tx_ctlerrs++;
197 brcmf_usb_ioctl_resp_wake(devinfo);
201 brcmf_usb_ctlread_complete(
struct urb *
urb)
212 brcmf_usb_ctlwrite_complete(
struct urb *urb)
232 if (devinfo ==
NULL || buf ==
NULL ||
250 usb_fill_control_urb(devinfo->
ctl_urb,
255 (usb_complete_t)brcmf_usb_ctlwrite_complete,
271 if ((devinfo ==
NULL) || (buf ==
NULL) || (len == 0)
283 usb_fill_control_urb(devinfo->
ctl_urb,
286 (
unsigned char *) &devinfo->
ctl_read,
288 (usb_complete_t)brcmf_usb_ctlread_complete,
298 static int brcmf_usb_tx_ctlpkt(
struct device *
dev,
u8 *buf,
u32 len)
313 err = brcmf_usb_send_ctl(devinfo, buf, len);
319 timeout = brcmf_usb_ioctl_resp_wait(devinfo);
328 static int brcmf_usb_rx_ctlpkt(
struct device *dev,
u8 *buf,
u32 len)
342 err = brcmf_usb_recv_ctl(devinfo, buf, len);
348 timeout = brcmf_usb_ioctl_resp_wait(devinfo);
368 spin_unlock_irqrestore(&devinfo->
qlock, flags);
372 list_del_init(q->
next);
375 spin_unlock_irqrestore(&devinfo->
qlock, flags);
389 spin_unlock_irqrestore(&devinfo->
qlock, flags);
393 brcmf_usbdev_qinit(
struct list_head *q,
int qsize)
405 for (i = 0; i < qsize; i++) {
410 INIT_LIST_HEAD(&req->
list);
417 while (!list_empty(q)) {
427 static void brcmf_usb_free_q(
struct list_head *q,
bool pending)
441 list_del_init(&req->
list);
452 list_del_init(&req->
list);
453 spin_unlock_irqrestore(&devinfo->
qlock, flags);
457 static void brcmf_usb_tx_complete(
struct urb *urb)
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++;
480 static void brcmf_usb_rx_complete(
struct urb *urb)
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++;
505 devinfo->
bus_pub.bus->dstats.rx_errors++;
507 brcmf_rx_packet(devinfo->
dev, ifidx,
skb);
508 brcmf_usb_rx_refill(devinfo, req);
523 if (!req || !devinfo)
526 skb = dev_alloc_skb(devinfo->
bus_pub.bus_mtu);
534 skb->
data, skb_tailroom(skb), brcmf_usb_rx_complete,
541 brcmf_usb_del_fromq(devinfo, req);
558 brcmf_usb_rx_refill(devinfo, req);
568 if (devinfo->
bus_pub.state == state)
571 old_state = devinfo->
bus_pub.state;
581 brcmf_usb_rx_fill_all(devinfo);
594 brcmf_usb_intr_complete(
struct urb *urb)
608 if ((urb->status == -
ENOENT && (!killed))
624 static int brcmf_usb_tx(
struct device *dev,
struct sk_buff *skb)
635 req = brcmf_usb_deq(devinfo, &devinfo->
tx_freeq,
646 skb->
data, skb->
len, brcmf_usb_tx_complete, req);
647 req->
urb->transfer_flags |= URB_ZERO_PACKET;
652 brcmf_usb_del_fromq(devinfo, req);
655 brcmf_usb_enq(devinfo, &devinfo->
tx_freeq, req,
669 static int brcmf_usb_up(
struct device *dev)
696 (usb_complete_t)brcmf_usb_intr_complete,
728 brcmf_usb_rx_fill_all(devinfo);
732 static void brcmf_usb_down(
struct device *dev)
752 brcmf_usb_free_q(&devinfo->
tx_postq,
true);
754 brcmf_usb_free_q(&devinfo->
rx_postq,
true);
777 brcmf_usb_sync_complete(
struct urb *urb)
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);
824 memcpy(buffer, tmpbuf, buflen);
843 brcmf_usb_dl_cmd(devinfo,
DL_GETVER, &
id,
849 if ((chipid & 0x4300) == 0x4300)
882 brcmf_usb_dl_cmd(devinfo,
DL_GETVER, &
id,
889 brcmf_dbg(
INFO,
"download done %d ms postboot chip 0x%x/rev 0x%x\n",
899 brcmf_dbg(
ERROR,
"Cannot talk to Dongle. Firmware is not UP, %d ms\n",
917 (usb_complete_t)brcmf_usb_sync_complete, devinfo);
919 devinfo->
bulk_urb->transfer_flags |= URB_ZERO_PACKET;
933 unsigned int sendlen, sent, dllen;
934 char *bulkchunk =
NULL, *dlpos;
936 u32 rdlstate, rdlbytes;
941 if (bulkchunk ==
NULL) {
947 brcmf_usb_dl_cmd(devinfo,
DL_START, &state,
964 while (rdlbytes != dllen) {
967 if ((rdlbytes == sent) && (rdlbytes != dllen)) {
969 sendlen = dllen-sent;
981 memcpy(bulkchunk, dlpos, sendlen);
982 if (brcmf_usb_dl_send_bulk(devinfo, bulkchunk,
992 if (!brcmf_usb_dl_cmd(devinfo,
DL_GETSTATE, &state,
1023 if (devinfo ==
NULL)
1026 if (devinfo->
bus_pub.devid == 0xDEAD)
1029 err = brcmf_usb_dl_writeimage(devinfo, fw, len);
1047 if (devinfo->
bus_pub.devid == 0xDEAD)
1056 if (!brcmf_usb_dl_cmd(devinfo,
DL_GO, &state,
1059 if (brcmf_usb_resetcfg(devinfo))
1070 static bool brcmf_usb_chip_support(
int chipid,
int chiprev)
1078 return (chiprev == 3);
1094 if (devinfo ==
NULL)
1097 devid = devinfo->
bus_pub.devid;
1098 chiprev = devinfo->
bus_pub.chiprev;
1100 if (!brcmf_usb_chip_support(devid, chiprev)) {
1106 if (!devinfo->
image) {
1111 err = brcmf_usb_dlstart(devinfo,
1114 err = brcmf_usb_dlrun(devinfo);
1124 brcmf_usb_free_q(&devinfo->
rx_freeq,
false);
1125 brcmf_usb_free_q(&devinfo->
tx_freeq,
false);
1135 #define TRX_MAGIC 0x30524448
1136 #define TRX_VERSION 1
1137 #define TRX_MAX_LEN 0x3B0000
1138 #define TRX_NO_HEADER 1
1139 #define TRX_MAX_OFFSET 3
1140 #define TRX_UNCOMP_IMAGE 0x20
1151 static int check_file(
const u8 *headers)
1154 int actual_len = -1;
1177 switch (devinfo->
bus_pub.devid) {
1195 if (fw_image->
fwname == fwname) {
1207 if (check_file(fw->
data) < 0) {
1212 fw_image = kzalloc(
sizeof(*fw_image),
GFP_ATOMIC);
1215 INIT_LIST_HEAD(&fw_image->
list);
1219 if (!fw_image->
image)
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);
1288 if (!brcmf_usb_dlneeded(devinfo))
1292 if (brcmf_usb_get_fw(devinfo))
1295 if (brcmf_usb_fw_download(devinfo))
1302 brcmf_usb_detach(devinfo);
1330 bus->
type = bustype;
1352 brcmf_usb_detach(devinfo);
1365 brcmf_usb_detach(devinfo);
1374 struct usb_device *
usb = interface_to_usbdev(intf);
1381 devinfo = kzalloc(
sizeof(*devinfo),
GFP_ATOMIC);
1382 if (devinfo ==
NULL)
1386 devinfo->
dev = &usb->dev;
1388 usb_set_intfdata(intf, devinfo);
1391 if (usb->descriptor.bNumConfigurations != 1) {
1418 brcmf_dbg(
ERROR,
"invalid control interface: class %d, subclass %d, proto %d\n",
1437 devinfo->
intr_pipe = usb_rcvintpipe(usb, endpoint_num);
1445 for (ep = 1; ep <= num_of_eps; ep++) {
1460 usb_rcvbulkpipe(usb, endpoint_num);
1463 usb_rcvbulkpipe(usb, endpoint_num);
1466 devinfo->
tx_pipe = usb_sndbulkpipe(usb, endpoint_num);
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);
1494 usb_set_intfdata(intf,
NULL);
1506 brcmf_usb_disconnect_cb(devinfo);
1515 struct usb_device *usb = interface_to_usbdev(intf);
1529 struct usb_device *usb = interface_to_usbdev(intf);
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
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)
1575 list_del_init(&fw_image->
list);
1583 brcmf_release_fw(&fw_image_list);
1588 INIT_LIST_HEAD(&fw_image_list);
1589 usb_register(&brcmf_usbdrvr);