Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 3 | * |
| 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. |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | |
Joe Perches | 02f7719 | 2012-01-15 00:38:44 -0800 | [diff] [blame] | 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 18 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 19 | #include <linux/init.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/kthread.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/skbuff.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/etherdevice.h> |
| 26 | #include <linux/mmc/sdio_func.h> |
| 27 | #include <linux/random.h> |
| 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/ethtool.h> |
| 30 | #include <linux/fcntl.h> |
| 31 | #include <linux/fs.h> |
| 32 | #include <linux/uaccess.h> |
| 33 | #include <linux/hardirq.h> |
| 34 | #include <linux/mutex.h> |
| 35 | #include <linux/wait.h> |
Stephen Rothwell | b7a57e7 | 2011-10-12 21:35:07 +0200 | [diff] [blame] | 36 | #include <linux/module.h> |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 37 | #include <net/cfg80211.h> |
| 38 | #include <net/rtnetlink.h> |
| 39 | #include <defs.h> |
| 40 | #include <brcmu_utils.h> |
| 41 | #include <brcmu_wifi.h> |
| 42 | |
| 43 | #include "dhd.h" |
| 44 | #include "dhd_bus.h" |
| 45 | #include "dhd_proto.h" |
| 46 | #include "dhd_dbg.h" |
| 47 | #include "wl_cfg80211.h" |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 48 | |
| 49 | MODULE_AUTHOR("Broadcom Corporation"); |
| 50 | MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver."); |
| 51 | MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards"); |
| 52 | MODULE_LICENSE("Dual BSD/GPL"); |
| 53 | |
| 54 | |
| 55 | /* Interface control information */ |
| 56 | struct brcmf_if { |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 57 | struct brcmf_pub *drvr; /* back pointer to brcmf_pub */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 58 | /* OS/stack specifics */ |
| 59 | struct net_device *ndev; |
| 60 | struct net_device_stats stats; |
| 61 | int idx; /* iface idx in dongle */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 62 | u8 mac_addr[ETH_ALEN]; /* assigned MAC address */ |
| 63 | }; |
| 64 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 65 | /* Error bits */ |
Franky Lin | 4f96bf1 | 2011-11-22 17:21:48 -0800 | [diff] [blame] | 66 | int brcmf_msg_level = BRCMF_ERROR_VAL; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 67 | module_param(brcmf_msg_level, int, 0); |
| 68 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 69 | int brcmf_ifname2idx(struct brcmf_pub *drvr, char *name) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 70 | { |
| 71 | int i = BRCMF_MAX_IFS; |
| 72 | struct brcmf_if *ifp; |
| 73 | |
| 74 | if (name == NULL || *name == '\0') |
| 75 | return 0; |
| 76 | |
| 77 | while (--i > 0) { |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 78 | ifp = drvr->iflist[i]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 79 | if (ifp && !strncmp(ifp->ndev->name, name, IFNAMSIZ)) |
| 80 | break; |
| 81 | } |
| 82 | |
| 83 | brcmf_dbg(TRACE, "return idx %d for \"%s\"\n", i, name); |
| 84 | |
| 85 | return i; /* default - the primary interface */ |
| 86 | } |
| 87 | |
| 88 | char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx) |
| 89 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 90 | if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) { |
| 91 | brcmf_dbg(ERROR, "ifidx %d out of range\n", ifidx); |
| 92 | return "<if_bad>"; |
| 93 | } |
| 94 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 95 | if (drvr->iflist[ifidx] == NULL) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 96 | brcmf_dbg(ERROR, "null i/f %d\n", ifidx); |
| 97 | return "<if_null>"; |
| 98 | } |
| 99 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 100 | if (drvr->iflist[ifidx]->ndev) |
| 101 | return drvr->iflist[ifidx]->ndev->name; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 102 | |
| 103 | return "<if_none>"; |
| 104 | } |
| 105 | |
| 106 | static void _brcmf_set_multicast_list(struct work_struct *work) |
| 107 | { |
| 108 | struct net_device *ndev; |
| 109 | struct netdev_hw_addr *ha; |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 110 | u32 dcmd_value, cnt; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 111 | __le32 cnt_le; |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 112 | __le32 dcmd_le_value; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 113 | |
| 114 | struct brcmf_dcmd dcmd; |
| 115 | char *buf, *bufp; |
| 116 | uint buflen; |
| 117 | int ret; |
| 118 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 119 | struct brcmf_pub *drvr = container_of(work, struct brcmf_pub, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 120 | multicast_work); |
| 121 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 122 | ndev = drvr->iflist[0]->ndev; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 123 | cnt = netdev_mc_count(ndev); |
| 124 | |
| 125 | /* Determine initial value of allmulti flag */ |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 126 | dcmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 127 | |
| 128 | /* Send down the multicast list first. */ |
| 129 | |
| 130 | buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN); |
| 131 | bufp = buf = kmalloc(buflen, GFP_ATOMIC); |
| 132 | if (!bufp) |
| 133 | return; |
| 134 | |
| 135 | strcpy(bufp, "mcast_list"); |
| 136 | bufp += strlen("mcast_list") + 1; |
| 137 | |
| 138 | cnt_le = cpu_to_le32(cnt); |
| 139 | memcpy(bufp, &cnt_le, sizeof(cnt)); |
| 140 | bufp += sizeof(cnt_le); |
| 141 | |
| 142 | netdev_for_each_mc_addr(ha, ndev) { |
| 143 | if (!cnt) |
| 144 | break; |
| 145 | memcpy(bufp, ha->addr, ETH_ALEN); |
| 146 | bufp += ETH_ALEN; |
| 147 | cnt--; |
| 148 | } |
| 149 | |
| 150 | memset(&dcmd, 0, sizeof(dcmd)); |
| 151 | dcmd.cmd = BRCMF_C_SET_VAR; |
| 152 | dcmd.buf = buf; |
| 153 | dcmd.len = buflen; |
| 154 | dcmd.set = true; |
| 155 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 156 | ret = brcmf_proto_dcmd(drvr, 0, &dcmd, dcmd.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 157 | if (ret < 0) { |
| 158 | brcmf_dbg(ERROR, "%s: set mcast_list failed, cnt %d\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 159 | brcmf_ifname(drvr, 0), cnt); |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 160 | dcmd_value = cnt ? true : dcmd_value; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | kfree(buf); |
| 164 | |
| 165 | /* Now send the allmulti setting. This is based on the setting in the |
| 166 | * net_device flags, but might be modified above to be turned on if we |
| 167 | * were trying to set some addresses and dongle rejected it... |
| 168 | */ |
| 169 | |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 170 | buflen = sizeof("allmulti") + sizeof(dcmd_value); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 171 | buf = kmalloc(buflen, GFP_ATOMIC); |
| 172 | if (!buf) |
| 173 | return; |
| 174 | |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 175 | dcmd_le_value = cpu_to_le32(dcmd_value); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 176 | |
Alwin Beukers | 53a2277 | 2011-10-12 20:51:30 +0200 | [diff] [blame] | 177 | if (!brcmf_c_mkiovar |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 178 | ("allmulti", (void *)&dcmd_le_value, |
| 179 | sizeof(dcmd_le_value), buf, buflen)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 180 | brcmf_dbg(ERROR, "%s: mkiovar failed for allmulti, datalen %d buflen %u\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 181 | brcmf_ifname(drvr, 0), |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 182 | (int)sizeof(dcmd_value), buflen); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 183 | kfree(buf); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | memset(&dcmd, 0, sizeof(dcmd)); |
| 188 | dcmd.cmd = BRCMF_C_SET_VAR; |
| 189 | dcmd.buf = buf; |
| 190 | dcmd.len = buflen; |
| 191 | dcmd.set = true; |
| 192 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 193 | ret = brcmf_proto_dcmd(drvr, 0, &dcmd, dcmd.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 194 | if (ret < 0) { |
| 195 | brcmf_dbg(ERROR, "%s: set allmulti %d failed\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 196 | brcmf_ifname(drvr, 0), |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 197 | le32_to_cpu(dcmd_le_value)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | kfree(buf); |
| 201 | |
| 202 | /* Finally, pick up the PROMISC flag as well, like the NIC |
| 203 | driver does */ |
| 204 | |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 205 | dcmd_value = (ndev->flags & IFF_PROMISC) ? true : false; |
| 206 | dcmd_le_value = cpu_to_le32(dcmd_value); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 207 | |
| 208 | memset(&dcmd, 0, sizeof(dcmd)); |
| 209 | dcmd.cmd = BRCMF_C_SET_PROMISC; |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 210 | dcmd.buf = &dcmd_le_value; |
| 211 | dcmd.len = sizeof(dcmd_le_value); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 212 | dcmd.set = true; |
| 213 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 214 | ret = brcmf_proto_dcmd(drvr, 0, &dcmd, dcmd.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 215 | if (ret < 0) { |
| 216 | brcmf_dbg(ERROR, "%s: set promisc %d failed\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 217 | brcmf_ifname(drvr, 0), |
Arend van Spriel | b503624 | 2011-10-12 20:51:17 +0200 | [diff] [blame] | 218 | le32_to_cpu(dcmd_le_value)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | static void |
| 223 | _brcmf_set_mac_address(struct work_struct *work) |
| 224 | { |
| 225 | char buf[32]; |
| 226 | struct brcmf_dcmd dcmd; |
| 227 | int ret; |
| 228 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 229 | struct brcmf_pub *drvr = container_of(work, struct brcmf_pub, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 230 | setmacaddr_work); |
| 231 | |
| 232 | brcmf_dbg(TRACE, "enter\n"); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 233 | if (!brcmf_c_mkiovar("cur_etheraddr", (char *)drvr->macvalue, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 234 | ETH_ALEN, buf, 32)) { |
| 235 | brcmf_dbg(ERROR, "%s: mkiovar failed for cur_etheraddr\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 236 | brcmf_ifname(drvr, 0)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 237 | return; |
| 238 | } |
| 239 | memset(&dcmd, 0, sizeof(dcmd)); |
| 240 | dcmd.cmd = BRCMF_C_SET_VAR; |
| 241 | dcmd.buf = buf; |
| 242 | dcmd.len = 32; |
| 243 | dcmd.set = true; |
| 244 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 245 | ret = brcmf_proto_dcmd(drvr, 0, &dcmd, dcmd.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 246 | if (ret < 0) |
| 247 | brcmf_dbg(ERROR, "%s: set cur_etheraddr failed\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 248 | brcmf_ifname(drvr, 0)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 249 | else |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 250 | memcpy(drvr->iflist[0]->ndev->dev_addr, |
| 251 | drvr->macvalue, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 252 | |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr) |
| 257 | { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 258 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 259 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 260 | struct sockaddr *sa = (struct sockaddr *)addr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 261 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 262 | memcpy(&drvr->macvalue, sa->sa_data, ETH_ALEN); |
| 263 | schedule_work(&drvr->setmacaddr_work); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static void brcmf_netdev_set_multicast_list(struct net_device *ndev) |
| 268 | { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 269 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 270 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 271 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 272 | schedule_work(&drvr->multicast_work); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf) |
| 276 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 277 | /* Reject if down */ |
Franky Lin | 3fb1d8d | 2011-12-16 18:37:04 -0800 | [diff] [blame] | 278 | if (!drvr->bus_if->drvr_up || (drvr->bus_if->state == BRCMF_BUS_DOWN)) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 279 | return -ENODEV; |
| 280 | |
| 281 | /* Update multicast statistic */ |
| 282 | if (pktbuf->len >= ETH_ALEN) { |
| 283 | u8 *pktdata = (u8 *) (pktbuf->data); |
| 284 | struct ethhdr *eh = (struct ethhdr *)pktdata; |
| 285 | |
| 286 | if (is_multicast_ether_addr(eh->h_dest)) |
| 287 | drvr->tx_multicast++; |
| 288 | if (ntohs(eh->h_proto) == ETH_P_PAE) |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 289 | atomic_inc(&drvr->pend_8021x_cnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /* If the protocol uses a data header, apply it */ |
| 293 | brcmf_proto_hdrpush(drvr, ifidx, pktbuf); |
| 294 | |
| 295 | /* Use bus module to send data frame */ |
Franky Lin | b9692d1 | 2011-12-16 18:37:15 -0800 | [diff] [blame] | 296 | return drvr->bus_if->brcmf_bus_txdata(drvr->dev, pktbuf); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *ndev) |
| 300 | { |
| 301 | int ret; |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 302 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 303 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 304 | |
| 305 | brcmf_dbg(TRACE, "Enter\n"); |
| 306 | |
| 307 | /* Reject if down */ |
Franky Lin | 3fb1d8d | 2011-12-16 18:37:04 -0800 | [diff] [blame] | 308 | if (!drvr->bus_if->drvr_up || |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 309 | (drvr->bus_if->state == BRCMF_BUS_DOWN)) { |
Franky Lin | 3fb1d8d | 2011-12-16 18:37:04 -0800 | [diff] [blame] | 310 | brcmf_dbg(ERROR, "xmit rejected drvup=%d state=%d\n", |
| 311 | drvr->bus_if->drvr_up, |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 312 | drvr->bus_if->state); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 313 | netif_stop_queue(ndev); |
| 314 | return -ENODEV; |
| 315 | } |
| 316 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 317 | if (!drvr->iflist[ifp->idx]) { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 318 | brcmf_dbg(ERROR, "bad ifidx %d\n", ifp->idx); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 319 | netif_stop_queue(ndev); |
| 320 | return -ENODEV; |
| 321 | } |
| 322 | |
| 323 | /* Make sure there's enough room for any header */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 324 | if (skb_headroom(skb) < drvr->hdrlen) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 325 | struct sk_buff *skb2; |
| 326 | |
| 327 | brcmf_dbg(INFO, "%s: insufficient headroom\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 328 | brcmf_ifname(drvr, ifp->idx)); |
Franky Lin | 9c1a043 | 2011-12-16 18:37:07 -0800 | [diff] [blame] | 329 | drvr->bus_if->tx_realloc++; |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 330 | skb2 = skb_realloc_headroom(skb, drvr->hdrlen); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 331 | dev_kfree_skb(skb); |
| 332 | skb = skb2; |
| 333 | if (skb == NULL) { |
| 334 | brcmf_dbg(ERROR, "%s: skb_realloc_headroom failed\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 335 | brcmf_ifname(drvr, ifp->idx)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 336 | ret = -ENOMEM; |
| 337 | goto done; |
| 338 | } |
| 339 | } |
| 340 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 341 | ret = brcmf_sendpkt(drvr, ifp->idx, skb); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 342 | |
| 343 | done: |
| 344 | if (ret) |
Franky Lin | 719f273 | 2011-12-16 18:37:06 -0800 | [diff] [blame] | 345 | drvr->bus_if->dstats.tx_dropped++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 346 | else |
Franky Lin | 719f273 | 2011-12-16 18:37:06 -0800 | [diff] [blame] | 347 | drvr->bus_if->dstats.tx_packets++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 348 | |
| 349 | /* Return ok: we always eat the packet */ |
| 350 | return 0; |
| 351 | } |
| 352 | |
Franky Lin | 2b45905 | 2011-12-16 18:36:57 -0800 | [diff] [blame] | 353 | void brcmf_txflowcontrol(struct device *dev, int ifidx, bool state) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 354 | { |
| 355 | struct net_device *ndev; |
Franky Lin | 2b45905 | 2011-12-16 18:36:57 -0800 | [diff] [blame] | 356 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 357 | struct brcmf_pub *drvr = bus_if->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 358 | |
| 359 | brcmf_dbg(TRACE, "Enter\n"); |
| 360 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 361 | ndev = drvr->iflist[ifidx]->ndev; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 362 | if (state == ON) |
| 363 | netif_stop_queue(ndev); |
| 364 | else |
| 365 | netif_wake_queue(ndev); |
| 366 | } |
| 367 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 368 | static int brcmf_host_event(struct brcmf_pub *drvr, int *ifidx, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 369 | void *pktdata, struct brcmf_event_msg *event, |
| 370 | void **data) |
| 371 | { |
| 372 | int bcmerror = 0; |
| 373 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 374 | bcmerror = brcmf_c_host_event(drvr, ifidx, pktdata, event, data); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 375 | if (bcmerror != 0) |
| 376 | return bcmerror; |
| 377 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 378 | if (drvr->iflist[*ifidx]->ndev) |
| 379 | brcmf_cfg80211_event(drvr->iflist[*ifidx]->ndev, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 380 | event, *data); |
| 381 | |
| 382 | return bcmerror; |
| 383 | } |
| 384 | |
Franky Lin | 228bb43 | 2011-12-16 18:37:00 -0800 | [diff] [blame] | 385 | void brcmf_rx_frame(struct device *dev, int ifidx, |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 386 | struct sk_buff_head *skb_list) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 387 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 388 | unsigned char *eth; |
| 389 | uint len; |
| 390 | void *data; |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 391 | struct sk_buff *skb, *pnext; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 392 | struct brcmf_if *ifp; |
| 393 | struct brcmf_event_msg event; |
Franky Lin | 228bb43 | 2011-12-16 18:37:00 -0800 | [diff] [blame] | 394 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 395 | struct brcmf_pub *drvr = bus_if->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 396 | |
| 397 | brcmf_dbg(TRACE, "Enter\n"); |
| 398 | |
Arend van Spriel | 0b45bf7 | 2011-11-22 17:21:36 -0800 | [diff] [blame] | 399 | skb_queue_walk_safe(skb_list, skb, pnext) { |
| 400 | skb_unlink(skb, skb_list); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 401 | |
| 402 | /* Get the protocol, maintain skb around eth_type_trans() |
| 403 | * The main reason for this hack is for the limitation of |
| 404 | * Linux 2.4 where 'eth_type_trans' uses the |
| 405 | * 'net->hard_header_len' |
| 406 | * to perform skb_pull inside vs ETH_HLEN. Since to avoid |
| 407 | * coping of the packet coming from the network stack to add |
| 408 | * BDC, Hardware header etc, during network interface |
| 409 | * registration |
| 410 | * we set the 'net->hard_header_len' to ETH_HLEN + extra space |
| 411 | * required |
| 412 | * for BDC, Hardware header etc. and not just the ETH_HLEN |
| 413 | */ |
| 414 | eth = skb->data; |
| 415 | len = skb->len; |
| 416 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 417 | ifp = drvr->iflist[ifidx]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 418 | if (ifp == NULL) |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 419 | ifp = drvr->iflist[0]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 420 | |
Franky Lin | 0c094c7 | 2011-11-22 17:21:46 -0800 | [diff] [blame] | 421 | if (!ifp || !ifp->ndev || |
| 422 | ifp->ndev->reg_state != NETREG_REGISTERED) { |
| 423 | brcmu_pkt_buf_free_skb(skb); |
| 424 | continue; |
| 425 | } |
| 426 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 427 | skb->dev = ifp->ndev; |
| 428 | skb->protocol = eth_type_trans(skb, skb->dev); |
| 429 | |
| 430 | if (skb->pkt_type == PACKET_MULTICAST) |
Franky Lin | 719f273 | 2011-12-16 18:37:06 -0800 | [diff] [blame] | 431 | bus_if->dstats.multicast++; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 432 | |
| 433 | skb->data = eth; |
| 434 | skb->len = len; |
| 435 | |
| 436 | /* Strip header, count, deliver upward */ |
| 437 | skb_pull(skb, ETH_HLEN); |
| 438 | |
| 439 | /* Process special event packets and then discard them */ |
| 440 | if (ntohs(skb->protocol) == ETH_P_LINK_CTL) |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 441 | brcmf_host_event(drvr, &ifidx, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 442 | skb_mac_header(skb), |
| 443 | &event, &data); |
| 444 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 445 | if (drvr->iflist[ifidx]) { |
| 446 | ifp = drvr->iflist[ifidx]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 447 | ifp->ndev->last_rx = jiffies; |
Franky Lin | d1a5b6f | 2011-10-21 16:16:34 +0200 | [diff] [blame] | 448 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 449 | |
Franky Lin | 719f273 | 2011-12-16 18:37:06 -0800 | [diff] [blame] | 450 | bus_if->dstats.rx_bytes += skb->len; |
| 451 | bus_if->dstats.rx_packets++; /* Local count */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 452 | |
| 453 | if (in_interrupt()) |
| 454 | netif_rx(skb); |
| 455 | else |
| 456 | /* If the receive is not processed inside an ISR, |
| 457 | * the softirqd must be woken explicitly to service |
| 458 | * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled |
| 459 | * by netif_rx_ni(), but in earlier kernels, we need |
| 460 | * to do it manually. |
| 461 | */ |
| 462 | netif_rx_ni(skb); |
| 463 | } |
| 464 | } |
| 465 | |
Franky Lin | c995788 | 2011-12-16 18:36:58 -0800 | [diff] [blame] | 466 | void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 467 | { |
| 468 | uint ifidx; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 469 | struct ethhdr *eh; |
| 470 | u16 type; |
Franky Lin | c995788 | 2011-12-16 18:36:58 -0800 | [diff] [blame] | 471 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 472 | struct brcmf_pub *drvr = bus_if->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 473 | |
Franky Lin | d5625ee | 2011-12-16 18:37:01 -0800 | [diff] [blame] | 474 | brcmf_proto_hdrpull(dev, &ifidx, txp); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 475 | |
| 476 | eh = (struct ethhdr *)(txp->data); |
| 477 | type = ntohs(eh->h_proto); |
| 478 | |
| 479 | if (type == ETH_P_PAE) |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 480 | atomic_dec(&drvr->pend_8021x_cnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 481 | |
| 482 | } |
| 483 | |
| 484 | static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev) |
| 485 | { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 486 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | 719f273 | 2011-12-16 18:37:06 -0800 | [diff] [blame] | 487 | struct brcmf_bus *bus_if = ifp->drvr->bus_if; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 488 | |
| 489 | brcmf_dbg(TRACE, "Enter\n"); |
| 490 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 491 | /* Copy dongle stats to net device stats */ |
Franky Lin | 719f273 | 2011-12-16 18:37:06 -0800 | [diff] [blame] | 492 | ifp->stats.rx_packets = bus_if->dstats.rx_packets; |
| 493 | ifp->stats.tx_packets = bus_if->dstats.tx_packets; |
| 494 | ifp->stats.rx_bytes = bus_if->dstats.rx_bytes; |
| 495 | ifp->stats.tx_bytes = bus_if->dstats.tx_bytes; |
| 496 | ifp->stats.rx_errors = bus_if->dstats.rx_errors; |
| 497 | ifp->stats.tx_errors = bus_if->dstats.tx_errors; |
| 498 | ifp->stats.rx_dropped = bus_if->dstats.rx_dropped; |
| 499 | ifp->stats.tx_dropped = bus_if->dstats.tx_dropped; |
| 500 | ifp->stats.multicast = bus_if->dstats.multicast; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 501 | |
| 502 | return &ifp->stats; |
| 503 | } |
| 504 | |
| 505 | /* Retrieve current toe component enables, which are kept |
| 506 | as a bitmap in toe_ol iovar */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 507 | static int brcmf_toe_get(struct brcmf_pub *drvr, int ifidx, u32 *toe_ol) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 508 | { |
| 509 | struct brcmf_dcmd dcmd; |
Arend van Spriel | 1062904 | 2011-10-12 20:51:18 +0200 | [diff] [blame] | 510 | __le32 toe_le; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 511 | char buf[32]; |
| 512 | int ret; |
| 513 | |
| 514 | memset(&dcmd, 0, sizeof(dcmd)); |
| 515 | |
| 516 | dcmd.cmd = BRCMF_C_GET_VAR; |
| 517 | dcmd.buf = buf; |
| 518 | dcmd.len = (uint) sizeof(buf); |
| 519 | dcmd.set = false; |
| 520 | |
| 521 | strcpy(buf, "toe_ol"); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 522 | ret = brcmf_proto_dcmd(drvr, ifidx, &dcmd, dcmd.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 523 | if (ret < 0) { |
| 524 | /* Check for older dongle image that doesn't support toe_ol */ |
| 525 | if (ret == -EIO) { |
| 526 | brcmf_dbg(ERROR, "%s: toe not supported by device\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 527 | brcmf_ifname(drvr, ifidx)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 528 | return -EOPNOTSUPP; |
| 529 | } |
| 530 | |
| 531 | brcmf_dbg(INFO, "%s: could not get toe_ol: ret=%d\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 532 | brcmf_ifname(drvr, ifidx), ret); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 533 | return ret; |
| 534 | } |
| 535 | |
Arend van Spriel | 1062904 | 2011-10-12 20:51:18 +0200 | [diff] [blame] | 536 | memcpy(&toe_le, buf, sizeof(u32)); |
| 537 | *toe_ol = le32_to_cpu(toe_le); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | /* Set current toe component enables in toe_ol iovar, |
| 542 | and set toe global enable iovar */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 543 | static int brcmf_toe_set(struct brcmf_pub *drvr, int ifidx, u32 toe_ol) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 544 | { |
| 545 | struct brcmf_dcmd dcmd; |
| 546 | char buf[32]; |
Arend van Spriel | 1062904 | 2011-10-12 20:51:18 +0200 | [diff] [blame] | 547 | int ret; |
| 548 | __le32 toe_le = cpu_to_le32(toe_ol); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 549 | |
| 550 | memset(&dcmd, 0, sizeof(dcmd)); |
| 551 | |
| 552 | dcmd.cmd = BRCMF_C_SET_VAR; |
| 553 | dcmd.buf = buf; |
| 554 | dcmd.len = (uint) sizeof(buf); |
| 555 | dcmd.set = true; |
| 556 | |
| 557 | /* Set toe_ol as requested */ |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 558 | strcpy(buf, "toe_ol"); |
Arend van Spriel | 1062904 | 2011-10-12 20:51:18 +0200 | [diff] [blame] | 559 | memcpy(&buf[sizeof("toe_ol")], &toe_le, sizeof(u32)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 560 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 561 | ret = brcmf_proto_dcmd(drvr, ifidx, &dcmd, dcmd.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 562 | if (ret < 0) { |
| 563 | brcmf_dbg(ERROR, "%s: could not set toe_ol: ret=%d\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 564 | brcmf_ifname(drvr, ifidx), ret); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 565 | return ret; |
| 566 | } |
| 567 | |
| 568 | /* Enable toe globally only if any components are enabled. */ |
Arend van Spriel | 1062904 | 2011-10-12 20:51:18 +0200 | [diff] [blame] | 569 | toe_le = cpu_to_le32(toe_ol != 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 570 | |
| 571 | strcpy(buf, "toe"); |
Arend van Spriel | 1062904 | 2011-10-12 20:51:18 +0200 | [diff] [blame] | 572 | memcpy(&buf[sizeof("toe")], &toe_le, sizeof(u32)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 573 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 574 | ret = brcmf_proto_dcmd(drvr, ifidx, &dcmd, dcmd.len); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 575 | if (ret < 0) { |
| 576 | brcmf_dbg(ERROR, "%s: could not set toe: ret=%d\n", |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 577 | brcmf_ifname(drvr, ifidx), ret); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 578 | return ret; |
| 579 | } |
| 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static void brcmf_ethtool_get_drvinfo(struct net_device *ndev, |
| 585 | struct ethtool_drvinfo *info) |
| 586 | { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 587 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 588 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 589 | |
| 590 | sprintf(info->driver, KBUILD_MODNAME); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 591 | sprintf(info->version, "%lu", drvr->drv_version); |
| 592 | sprintf(info->bus_info, "%s", dev_name(drvr->dev)); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 593 | } |
| 594 | |
Stephen Hemminger | 3eb1fa7 | 2012-01-04 14:52:51 -0800 | [diff] [blame] | 595 | static const struct ethtool_ops brcmf_ethtool_ops = { |
| 596 | .get_drvinfo = brcmf_ethtool_get_drvinfo, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 597 | }; |
| 598 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 599 | static int brcmf_ethtool(struct brcmf_pub *drvr, void __user *uaddr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 600 | { |
| 601 | struct ethtool_drvinfo info; |
| 602 | char drvname[sizeof(info.driver)]; |
| 603 | u32 cmd; |
| 604 | struct ethtool_value edata; |
| 605 | u32 toe_cmpnt, csum_dir; |
| 606 | int ret; |
| 607 | |
| 608 | brcmf_dbg(TRACE, "Enter\n"); |
| 609 | |
| 610 | /* all ethtool calls start with a cmd word */ |
| 611 | if (copy_from_user(&cmd, uaddr, sizeof(u32))) |
| 612 | return -EFAULT; |
| 613 | |
| 614 | switch (cmd) { |
| 615 | case ETHTOOL_GDRVINFO: |
| 616 | /* Copy out any request driver name */ |
| 617 | if (copy_from_user(&info, uaddr, sizeof(info))) |
| 618 | return -EFAULT; |
| 619 | strncpy(drvname, info.driver, sizeof(info.driver)); |
| 620 | drvname[sizeof(info.driver) - 1] = '\0'; |
| 621 | |
| 622 | /* clear struct for return */ |
| 623 | memset(&info, 0, sizeof(info)); |
| 624 | info.cmd = cmd; |
| 625 | |
| 626 | /* if requested, identify ourselves */ |
| 627 | if (strcmp(drvname, "?dhd") == 0) { |
| 628 | sprintf(info.driver, "dhd"); |
| 629 | strcpy(info.version, BRCMF_VERSION_STR); |
| 630 | } |
| 631 | |
| 632 | /* otherwise, require dongle to be up */ |
Franky Lin | 3fb1d8d | 2011-12-16 18:37:04 -0800 | [diff] [blame] | 633 | else if (!drvr->bus_if->drvr_up) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 634 | brcmf_dbg(ERROR, "dongle is not up\n"); |
| 635 | return -ENODEV; |
| 636 | } |
| 637 | |
| 638 | /* finally, report dongle driver type */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 639 | else if (drvr->iswl) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 640 | sprintf(info.driver, "wl"); |
| 641 | else |
| 642 | sprintf(info.driver, "xx"); |
| 643 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 644 | sprintf(info.version, "%lu", drvr->drv_version); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 645 | if (copy_to_user(uaddr, &info, sizeof(info))) |
| 646 | return -EFAULT; |
| 647 | brcmf_dbg(CTL, "given %*s, returning %s\n", |
| 648 | (int)sizeof(drvname), drvname, info.driver); |
| 649 | break; |
| 650 | |
| 651 | /* Get toe offload components from dongle */ |
| 652 | case ETHTOOL_GRXCSUM: |
| 653 | case ETHTOOL_GTXCSUM: |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 654 | ret = brcmf_toe_get(drvr, 0, &toe_cmpnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 655 | if (ret < 0) |
| 656 | return ret; |
| 657 | |
| 658 | csum_dir = |
| 659 | (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL; |
| 660 | |
| 661 | edata.cmd = cmd; |
| 662 | edata.data = (toe_cmpnt & csum_dir) ? 1 : 0; |
| 663 | |
| 664 | if (copy_to_user(uaddr, &edata, sizeof(edata))) |
| 665 | return -EFAULT; |
| 666 | break; |
| 667 | |
| 668 | /* Set toe offload components in dongle */ |
| 669 | case ETHTOOL_SRXCSUM: |
| 670 | case ETHTOOL_STXCSUM: |
| 671 | if (copy_from_user(&edata, uaddr, sizeof(edata))) |
| 672 | return -EFAULT; |
| 673 | |
| 674 | /* Read the current settings, update and write back */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 675 | ret = brcmf_toe_get(drvr, 0, &toe_cmpnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 676 | if (ret < 0) |
| 677 | return ret; |
| 678 | |
| 679 | csum_dir = |
| 680 | (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL; |
| 681 | |
| 682 | if (edata.data != 0) |
| 683 | toe_cmpnt |= csum_dir; |
| 684 | else |
| 685 | toe_cmpnt &= ~csum_dir; |
| 686 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 687 | ret = brcmf_toe_set(drvr, 0, toe_cmpnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 688 | if (ret < 0) |
| 689 | return ret; |
| 690 | |
| 691 | /* If setting TX checksum mode, tell Linux the new mode */ |
| 692 | if (cmd == ETHTOOL_STXCSUM) { |
| 693 | if (edata.data) |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 694 | drvr->iflist[0]->ndev->features |= |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 695 | NETIF_F_IP_CSUM; |
| 696 | else |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 697 | drvr->iflist[0]->ndev->features &= |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 698 | ~NETIF_F_IP_CSUM; |
| 699 | } |
| 700 | |
| 701 | break; |
| 702 | |
| 703 | default: |
| 704 | return -EOPNOTSUPP; |
| 705 | } |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr, |
| 711 | int cmd) |
| 712 | { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 713 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 714 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 715 | |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 716 | brcmf_dbg(TRACE, "ifidx %d, cmd 0x%04x\n", ifp->idx, cmd); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 717 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 718 | if (!drvr->iflist[ifp->idx]) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 719 | return -1; |
| 720 | |
| 721 | if (cmd == SIOCETHTOOL) |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 722 | return brcmf_ethtool(drvr, ifr->ifr_data); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 723 | |
| 724 | return -EOPNOTSUPP; |
| 725 | } |
| 726 | |
| 727 | /* called only from within this driver. Sends a command to the dongle. */ |
| 728 | s32 brcmf_exec_dcmd(struct net_device *ndev, u32 cmd, void *arg, u32 len) |
| 729 | { |
| 730 | struct brcmf_dcmd dcmd; |
| 731 | s32 err = 0; |
| 732 | int buflen = 0; |
| 733 | bool is_set_key_cmd; |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 734 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 735 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 736 | |
| 737 | memset(&dcmd, 0, sizeof(dcmd)); |
| 738 | dcmd.cmd = cmd; |
| 739 | dcmd.buf = arg; |
| 740 | dcmd.len = len; |
| 741 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 742 | if (dcmd.buf != NULL) |
| 743 | buflen = min_t(uint, dcmd.len, BRCMF_DCMD_MAXLEN); |
| 744 | |
| 745 | /* send to dongle (must be up, and wl) */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 746 | if ((drvr->bus_if->state != BRCMF_BUS_DATA)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 747 | brcmf_dbg(ERROR, "DONGLE_DOWN\n"); |
| 748 | err = -EIO; |
| 749 | goto done; |
| 750 | } |
| 751 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 752 | if (!drvr->iswl) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 753 | err = -EIO; |
| 754 | goto done; |
| 755 | } |
| 756 | |
| 757 | /* |
| 758 | * Intercept BRCMF_C_SET_KEY CMD - serialize M4 send and |
| 759 | * set key CMD to prevent M4 encryption. |
| 760 | */ |
| 761 | is_set_key_cmd = ((dcmd.cmd == BRCMF_C_SET_KEY) || |
| 762 | ((dcmd.cmd == BRCMF_C_SET_VAR) && |
| 763 | !(strncmp("wsec_key", dcmd.buf, 9))) || |
| 764 | ((dcmd.cmd == BRCMF_C_SET_VAR) && |
| 765 | !(strncmp("bsscfg:wsec_key", dcmd.buf, 15)))); |
| 766 | if (is_set_key_cmd) |
| 767 | brcmf_netdev_wait_pend8021x(ndev); |
| 768 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 769 | err = brcmf_proto_dcmd(drvr, ifp->idx, &dcmd, buflen); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 770 | |
| 771 | done: |
| 772 | if (err > 0) |
| 773 | err = 0; |
| 774 | |
| 775 | return err; |
| 776 | } |
| 777 | |
| 778 | static int brcmf_netdev_stop(struct net_device *ndev) |
| 779 | { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 780 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 781 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 782 | |
| 783 | brcmf_dbg(TRACE, "Enter\n"); |
| 784 | brcmf_cfg80211_down(drvr->config); |
Franky Lin | 3fb1d8d | 2011-12-16 18:37:04 -0800 | [diff] [blame] | 785 | if (drvr->bus_if->drvr_up == 0) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 786 | return 0; |
| 787 | |
| 788 | /* Set state and stop OS transmissions */ |
John W. Linville | 57adc1f | 2012-01-03 15:16:34 -0500 | [diff] [blame] | 789 | drvr->bus_if->drvr_up = false; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 790 | netif_stop_queue(ndev); |
| 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | static int brcmf_netdev_open(struct net_device *ndev) |
| 796 | { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 797 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 798 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 1bb1f38 | 2012-02-09 21:09:05 +0100 | [diff] [blame] | 799 | struct brcmf_bus *bus_if = drvr->bus_if; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 800 | u32 toe_ol; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 801 | s32 ret = 0; |
Franky Lin | 3338084 | 2012-04-11 11:52:47 +0200 | [diff] [blame] | 802 | uint up = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 803 | |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 804 | brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 805 | |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 806 | if (ifp->idx == 0) { /* do it only for primary eth0 */ |
Arend van Spriel | 1bb1f38 | 2012-02-09 21:09:05 +0100 | [diff] [blame] | 807 | /* If bus is not ready, can't continue */ |
| 808 | if (bus_if->state != BRCMF_BUS_DATA) { |
| 809 | brcmf_dbg(ERROR, "failed bus is not ready\n"); |
| 810 | return -EAGAIN; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 811 | } |
Arend van Spriel | 1bb1f38 | 2012-02-09 21:09:05 +0100 | [diff] [blame] | 812 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 813 | atomic_set(&drvr->pend_8021x_cnt, 0); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 814 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 815 | memcpy(ndev->dev_addr, drvr->mac, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 816 | |
| 817 | /* Get current TOE mode from dongle */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 818 | if (brcmf_toe_get(drvr, ifp->idx, &toe_ol) >= 0 |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 819 | && (toe_ol & TOE_TX_CSUM_OL) != 0) |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 820 | drvr->iflist[ifp->idx]->ndev->features |= |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 821 | NETIF_F_IP_CSUM; |
| 822 | else |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 823 | drvr->iflist[ifp->idx]->ndev->features &= |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 824 | ~NETIF_F_IP_CSUM; |
| 825 | } |
Franky Lin | 3338084 | 2012-04-11 11:52:47 +0200 | [diff] [blame] | 826 | |
| 827 | /* make sure RF is ready for work */ |
| 828 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_UP, (char *)&up, sizeof(up)); |
| 829 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 830 | /* Allow transmit calls */ |
| 831 | netif_start_queue(ndev); |
John W. Linville | 57adc1f | 2012-01-03 15:16:34 -0500 | [diff] [blame] | 832 | drvr->bus_if->drvr_up = true; |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 833 | if (brcmf_cfg80211_up(drvr->config)) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 834 | brcmf_dbg(ERROR, "failed to bring up cfg80211\n"); |
| 835 | return -1; |
| 836 | } |
| 837 | |
| 838 | return ret; |
| 839 | } |
| 840 | |
Franky Lin | dfded55 | 2011-10-21 16:16:20 +0200 | [diff] [blame] | 841 | static const struct net_device_ops brcmf_netdev_ops_pri = { |
| 842 | .ndo_open = brcmf_netdev_open, |
| 843 | .ndo_stop = brcmf_netdev_stop, |
| 844 | .ndo_get_stats = brcmf_netdev_get_stats, |
| 845 | .ndo_do_ioctl = brcmf_netdev_ioctl_entry, |
| 846 | .ndo_start_xmit = brcmf_netdev_start_xmit, |
| 847 | .ndo_set_mac_address = brcmf_netdev_set_mac_address, |
| 848 | .ndo_set_rx_mode = brcmf_netdev_set_multicast_list |
| 849 | }; |
| 850 | |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 851 | static int brcmf_net_attach(struct brcmf_if *ifp) |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 852 | { |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 853 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 854 | struct net_device *ndev; |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 855 | u8 temp_addr[ETH_ALEN]; |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 856 | |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 857 | brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx); |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 858 | |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 859 | ndev = drvr->iflist[ifp->idx]->ndev; |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 860 | ndev->netdev_ops = &brcmf_netdev_ops_pri; |
| 861 | |
| 862 | /* |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 863 | * determine mac address to use |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 864 | */ |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 865 | if (is_valid_ether_addr(ifp->mac_addr)) |
| 866 | memcpy(temp_addr, ifp->mac_addr, ETH_ALEN); |
| 867 | else |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 868 | memcpy(temp_addr, drvr->mac, ETH_ALEN); |
| 869 | |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 870 | if (ifp->idx == 1) { |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 871 | brcmf_dbg(TRACE, "ACCESS POINT MAC:\n"); |
| 872 | /* ACCESSPOINT INTERFACE CASE */ |
| 873 | temp_addr[0] |= 0X02; /* set bit 2 , |
| 874 | - Locally Administered address */ |
| 875 | |
| 876 | } |
| 877 | ndev->hard_header_len = ETH_HLEN + drvr->hdrlen; |
| 878 | ndev->ethtool_ops = &brcmf_ethtool_ops; |
| 879 | |
| 880 | drvr->rxsz = ndev->mtu + ndev->hard_header_len + |
| 881 | drvr->hdrlen; |
| 882 | |
| 883 | memcpy(ndev->dev_addr, temp_addr, ETH_ALEN); |
| 884 | |
| 885 | /* attach to cfg80211 for primary interface */ |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 886 | if (!ifp->idx) { |
Arend van Spriel | 75c4990 | 2012-04-11 11:52:43 +0200 | [diff] [blame] | 887 | drvr->config = brcmf_cfg80211_attach(ndev, drvr->dev, drvr); |
| 888 | if (drvr->config == NULL) { |
| 889 | brcmf_dbg(ERROR, "wl_cfg80211_attach failed\n"); |
| 890 | goto fail; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | if (register_netdev(ndev) != 0) { |
| 895 | brcmf_dbg(ERROR, "couldn't register the net device\n"); |
| 896 | goto fail; |
| 897 | } |
| 898 | |
| 899 | brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name); |
| 900 | |
| 901 | return 0; |
| 902 | |
| 903 | fail: |
| 904 | ndev->netdev_ops = NULL; |
| 905 | return -EBADE; |
| 906 | } |
| 907 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 908 | int |
Franky Lin | 55a63bc | 2011-12-16 18:36:54 -0800 | [diff] [blame] | 909 | brcmf_add_if(struct device *dev, int ifidx, char *name, u8 *mac_addr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 910 | { |
| 911 | struct brcmf_if *ifp; |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 912 | struct net_device *ndev; |
Franky Lin | 55a63bc | 2011-12-16 18:36:54 -0800 | [diff] [blame] | 913 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 914 | struct brcmf_pub *drvr = bus_if->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 915 | |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 916 | brcmf_dbg(TRACE, "idx %d\n", ifidx); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 917 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 918 | ifp = drvr->iflist[ifidx]; |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 919 | /* |
| 920 | * Delete the existing interface before overwriting it |
| 921 | * in case we missed the BRCMF_E_IF_DEL event. |
| 922 | */ |
| 923 | if (ifp) { |
| 924 | brcmf_dbg(ERROR, "ERROR: netdev:%s already exists, try free & unregister\n", |
| 925 | ifp->ndev->name); |
| 926 | netif_stop_queue(ifp->ndev); |
| 927 | unregister_netdev(ifp->ndev); |
| 928 | free_netdev(ifp->ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 929 | drvr->iflist[ifidx] = NULL; |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 930 | } |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 931 | |
| 932 | /* Allocate netdev, including space for private structure */ |
| 933 | ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup); |
| 934 | if (!ndev) { |
| 935 | brcmf_dbg(ERROR, "OOM - alloc_netdev\n"); |
| 936 | return -ENOMEM; |
| 937 | } |
| 938 | |
| 939 | ifp = netdev_priv(ndev); |
| 940 | ifp->ndev = ndev; |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 941 | ifp->drvr = drvr; |
| 942 | drvr->iflist[ifidx] = ifp; |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 943 | ifp->idx = ifidx; |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 944 | if (mac_addr != NULL) |
| 945 | memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 946 | |
Arend van Spriel | 3625c14 | 2012-04-11 11:52:44 +0200 | [diff] [blame] | 947 | if (brcmf_net_attach(ifp)) { |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 948 | brcmf_dbg(ERROR, "brcmf_net_attach failed"); |
| 949 | free_netdev(ifp->ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 950 | drvr->iflist[ifidx] = NULL; |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 951 | return -EOPNOTSUPP; |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 952 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 953 | |
Franky Lin | 15d45b6 | 2011-10-21 16:16:32 +0200 | [diff] [blame] | 954 | brcmf_dbg(TRACE, " ==== pid:%x, net_device for if:%s created ===\n", |
| 955 | current->pid, ifp->ndev->name); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 956 | |
| 957 | return 0; |
| 958 | } |
| 959 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 960 | void brcmf_del_if(struct brcmf_pub *drvr, int ifidx) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 961 | { |
| 962 | struct brcmf_if *ifp; |
| 963 | |
| 964 | brcmf_dbg(TRACE, "idx %d\n", ifidx); |
| 965 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 966 | ifp = drvr->iflist[ifidx]; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 967 | if (!ifp) { |
| 968 | brcmf_dbg(ERROR, "Null interface\n"); |
| 969 | return; |
| 970 | } |
Franky Lin | dfded55 | 2011-10-21 16:16:20 +0200 | [diff] [blame] | 971 | if (ifp->ndev) { |
| 972 | if (ifidx == 0) { |
| 973 | if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) { |
| 974 | rtnl_lock(); |
| 975 | brcmf_netdev_stop(ifp->ndev); |
| 976 | rtnl_unlock(); |
| 977 | } |
| 978 | } else { |
| 979 | netif_stop_queue(ifp->ndev); |
| 980 | } |
| 981 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 982 | unregister_netdev(ifp->ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 983 | drvr->iflist[ifidx] = NULL; |
Franky Lin | dfded55 | 2011-10-21 16:16:20 +0200 | [diff] [blame] | 984 | if (ifidx == 0) |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 985 | brcmf_cfg80211_detach(drvr->config); |
Franky Lin | dfded55 | 2011-10-21 16:16:20 +0200 | [diff] [blame] | 986 | free_netdev(ifp->ndev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | |
Franky Lin | 2447ffb | 2011-12-16 18:37:10 -0800 | [diff] [blame] | 990 | int brcmf_attach(uint bus_hdrlen, struct device *dev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 991 | { |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 992 | struct brcmf_pub *drvr = NULL; |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 993 | int ret = 0; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 994 | |
| 995 | brcmf_dbg(TRACE, "Enter\n"); |
| 996 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 997 | /* Allocate primary brcmf_info */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 998 | drvr = kzalloc(sizeof(struct brcmf_pub), GFP_ATOMIC); |
| 999 | if (!drvr) |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 1000 | return -ENOMEM; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1001 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1002 | mutex_init(&drvr->proto_block); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1003 | |
| 1004 | /* Link to bus module */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1005 | drvr->hdrlen = bus_hdrlen; |
| 1006 | drvr->bus_if = dev_get_drvdata(dev); |
Franky Lin | 55a63bc | 2011-12-16 18:36:54 -0800 | [diff] [blame] | 1007 | drvr->bus_if->drvr = drvr; |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1008 | drvr->dev = dev; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1009 | |
Arend van Spriel | d319a7c | 2012-06-09 22:51:43 +0200 | [diff] [blame] | 1010 | /* create device debugfs folder */ |
| 1011 | brcmf_debugfs_attach(drvr); |
| 1012 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1013 | /* Attach and link in the protocol */ |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 1014 | ret = brcmf_proto_attach(drvr); |
| 1015 | if (ret != 0) { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1016 | brcmf_dbg(ERROR, "brcmf_prot_attach failed\n"); |
| 1017 | goto fail; |
| 1018 | } |
| 1019 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1020 | INIT_WORK(&drvr->setmacaddr_work, _brcmf_set_mac_address); |
| 1021 | INIT_WORK(&drvr->multicast_work, _brcmf_set_multicast_list); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1022 | |
Franky Lin | 135e4c6 | 2012-06-26 21:26:34 +0200 | [diff] [blame] | 1023 | INIT_LIST_HEAD(&drvr->bus_if->dcmd_list); |
| 1024 | |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 1025 | return ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1026 | |
| 1027 | fail: |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 1028 | brcmf_detach(dev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1029 | |
Franky Lin | 712ac5b | 2011-12-16 18:37:09 -0800 | [diff] [blame] | 1030 | return ret; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1031 | } |
| 1032 | |
Franky Lin | ed683c9 | 2011-12-16 18:36:55 -0800 | [diff] [blame] | 1033 | int brcmf_bus_start(struct device *dev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1034 | { |
| 1035 | int ret = -1; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1036 | /* Room for "event_msgs" + '\0' + bitvec */ |
| 1037 | char iovbuf[BRCMF_EVENTING_MASK_LEN + 12]; |
Franky Lin | ed683c9 | 2011-12-16 18:36:55 -0800 | [diff] [blame] | 1038 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1039 | struct brcmf_pub *drvr = bus_if->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1040 | |
| 1041 | brcmf_dbg(TRACE, "\n"); |
| 1042 | |
| 1043 | /* Bring up the bus */ |
Franky Lin | 99a0b8f | 2011-12-16 18:37:14 -0800 | [diff] [blame] | 1044 | ret = bus_if->brcmf_bus_init(dev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1045 | if (ret != 0) { |
| 1046 | brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret); |
| 1047 | return ret; |
| 1048 | } |
| 1049 | |
Alwin Beukers | 53a2277 | 2011-10-12 20:51:30 +0200 | [diff] [blame] | 1050 | brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN, |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1051 | iovbuf, sizeof(iovbuf)); |
| 1052 | brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, iovbuf, |
| 1053 | sizeof(iovbuf)); |
| 1054 | memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN); |
| 1055 | |
| 1056 | setbit(drvr->eventmask, BRCMF_E_SET_SSID); |
| 1057 | setbit(drvr->eventmask, BRCMF_E_PRUNE); |
| 1058 | setbit(drvr->eventmask, BRCMF_E_AUTH); |
| 1059 | setbit(drvr->eventmask, BRCMF_E_REASSOC); |
| 1060 | setbit(drvr->eventmask, BRCMF_E_REASSOC_IND); |
| 1061 | setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND); |
| 1062 | setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND); |
| 1063 | setbit(drvr->eventmask, BRCMF_E_DISASSOC); |
| 1064 | setbit(drvr->eventmask, BRCMF_E_JOIN); |
| 1065 | setbit(drvr->eventmask, BRCMF_E_ASSOC_IND); |
| 1066 | setbit(drvr->eventmask, BRCMF_E_PSK_SUP); |
| 1067 | setbit(drvr->eventmask, BRCMF_E_LINK); |
| 1068 | setbit(drvr->eventmask, BRCMF_E_NDIS_LINK); |
| 1069 | setbit(drvr->eventmask, BRCMF_E_MIC_ERROR); |
| 1070 | setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE); |
| 1071 | setbit(drvr->eventmask, BRCMF_E_TXFAIL); |
| 1072 | setbit(drvr->eventmask, BRCMF_E_JOIN_START); |
| 1073 | setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE); |
| 1074 | |
| 1075 | /* enable dongle roaming event */ |
| 1076 | |
| 1077 | drvr->pktfilter_count = 1; |
| 1078 | /* Setup filter to allow only unicast */ |
| 1079 | drvr->pktfilter[0] = "100 0 0 0 0x01 0x00"; |
| 1080 | |
| 1081 | /* Bus is ready, do any protocol initialization */ |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1082 | ret = brcmf_proto_init(drvr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1083 | if (ret < 0) |
| 1084 | return ret; |
| 1085 | |
Arend van Spriel | 474a64c | 2012-04-11 11:52:45 +0200 | [diff] [blame] | 1086 | /* add primary networking interface */ |
| 1087 | ret = brcmf_add_if(dev, 0, "wlan%d", drvr->mac); |
| 1088 | if (ret < 0) |
| 1089 | return ret; |
| 1090 | |
Arend van Spriel | 1bb1f38 | 2012-02-09 21:09:05 +0100 | [diff] [blame] | 1091 | /* signal bus ready */ |
| 1092 | bus_if->state = BRCMF_BUS_DATA; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1093 | return 0; |
| 1094 | } |
| 1095 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1096 | static void brcmf_bus_detach(struct brcmf_pub *drvr) |
| 1097 | { |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1098 | brcmf_dbg(TRACE, "Enter\n"); |
| 1099 | |
| 1100 | if (drvr) { |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1101 | /* Stop the protocol module */ |
| 1102 | brcmf_proto_stop(drvr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1103 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1104 | /* Stop the bus module */ |
Franky Lin | a9ffda8 | 2011-12-16 18:37:12 -0800 | [diff] [blame] | 1105 | drvr->bus_if->brcmf_bus_stop(drvr->dev); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | |
Franky Lin | 5f947ad | 2011-12-16 18:36:56 -0800 | [diff] [blame] | 1109 | void brcmf_detach(struct device *dev) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1110 | { |
Franky Lin | 5f947ad | 2011-12-16 18:36:56 -0800 | [diff] [blame] | 1111 | int i; |
| 1112 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); |
| 1113 | struct brcmf_pub *drvr = bus_if->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1114 | |
| 1115 | brcmf_dbg(TRACE, "Enter\n"); |
| 1116 | |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1117 | |
Franky Lin | 5f947ad | 2011-12-16 18:36:56 -0800 | [diff] [blame] | 1118 | /* make sure primary interface removed last */ |
| 1119 | for (i = BRCMF_MAX_IFS-1; i > -1; i--) |
| 1120 | if (drvr->iflist[i]) |
| 1121 | brcmf_del_if(drvr, i); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1122 | |
Franky Lin | 5f947ad | 2011-12-16 18:36:56 -0800 | [diff] [blame] | 1123 | brcmf_bus_detach(drvr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1124 | |
Franky Lin | 89fdb46 | 2012-02-09 21:09:01 +0100 | [diff] [blame] | 1125 | if (drvr->prot) { |
| 1126 | cancel_work_sync(&drvr->setmacaddr_work); |
| 1127 | cancel_work_sync(&drvr->multicast_work); |
Franky Lin | 5f947ad | 2011-12-16 18:36:56 -0800 | [diff] [blame] | 1128 | brcmf_proto_detach(drvr); |
Franky Lin | 89fdb46 | 2012-02-09 21:09:01 +0100 | [diff] [blame] | 1129 | } |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1130 | |
Arend van Spriel | d319a7c | 2012-06-09 22:51:43 +0200 | [diff] [blame] | 1131 | brcmf_debugfs_detach(drvr); |
Franky Lin | 5f947ad | 2011-12-16 18:36:56 -0800 | [diff] [blame] | 1132 | bus_if->drvr = NULL; |
| 1133 | kfree(drvr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1134 | } |
| 1135 | |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1136 | static int brcmf_get_pend_8021x_cnt(struct brcmf_pub *drvr) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1137 | { |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1138 | return atomic_read(&drvr->pend_8021x_cnt); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | #define MAX_WAIT_FOR_8021X_TX 10 |
| 1142 | |
| 1143 | int brcmf_netdev_wait_pend8021x(struct net_device *ndev) |
| 1144 | { |
Franky Lin | e1b8358 | 2011-10-21 16:16:33 +0200 | [diff] [blame] | 1145 | struct brcmf_if *ifp = netdev_priv(ndev); |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1146 | struct brcmf_pub *drvr = ifp->drvr; |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1147 | int timeout = 10 * HZ / 1000; |
| 1148 | int ntimes = MAX_WAIT_FOR_8021X_TX; |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1149 | int pend = brcmf_get_pend_8021x_cnt(drvr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1150 | |
| 1151 | while (ntimes && pend) { |
| 1152 | if (pend) { |
| 1153 | set_current_state(TASK_INTERRUPTIBLE); |
| 1154 | schedule_timeout(timeout); |
| 1155 | set_current_state(TASK_RUNNING); |
| 1156 | ntimes--; |
| 1157 | } |
Franky Lin | d08b6a3 | 2011-12-16 18:36:51 -0800 | [diff] [blame] | 1158 | pend = brcmf_get_pend_8021x_cnt(drvr); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1159 | } |
| 1160 | return pend; |
| 1161 | } |
| 1162 | |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 1163 | #ifdef DEBUG |
Arend van Spriel | af53495 | 2011-10-12 20:51:14 +0200 | [diff] [blame] | 1164 | int brcmf_write_to_file(struct brcmf_pub *drvr, const u8 *buf, int size) |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1165 | { |
| 1166 | int ret = 0; |
| 1167 | struct file *fp; |
| 1168 | mm_segment_t old_fs; |
| 1169 | loff_t pos = 0; |
| 1170 | |
| 1171 | /* change to KERNEL_DS address limit */ |
| 1172 | old_fs = get_fs(); |
| 1173 | set_fs(KERNEL_DS); |
| 1174 | |
| 1175 | /* open file to write */ |
| 1176 | fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640); |
| 1177 | if (!fp) { |
| 1178 | brcmf_dbg(ERROR, "open file error\n"); |
| 1179 | ret = -1; |
| 1180 | goto exit; |
| 1181 | } |
| 1182 | |
| 1183 | /* Write buf to file */ |
Arend van Spriel | af53495 | 2011-10-12 20:51:14 +0200 | [diff] [blame] | 1184 | fp->f_op->write(fp, (char __user *)buf, size, &pos); |
Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame] | 1185 | |
| 1186 | exit: |
| 1187 | /* free buf before return */ |
| 1188 | kfree(buf); |
| 1189 | /* close file before return */ |
| 1190 | if (fp) |
| 1191 | filp_close(fp, current->files); |
| 1192 | /* restore previous address limit */ |
| 1193 | set_fs(old_fs); |
| 1194 | |
| 1195 | return ret; |
| 1196 | } |
Joe Perches | 8ae7465 | 2012-01-15 00:38:38 -0800 | [diff] [blame] | 1197 | #endif /* DEBUG */ |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 1198 | |
Arend van Spriel | e64a4b7 | 2012-03-02 22:55:49 +0100 | [diff] [blame] | 1199 | static void brcmf_driver_init(struct work_struct *work) |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 1200 | { |
Arend van Spriel | d319a7c | 2012-06-09 22:51:43 +0200 | [diff] [blame] | 1201 | brcmf_debugfs_init(); |
| 1202 | |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 1203 | #ifdef CONFIG_BRCMFMAC_SDIO |
Arend van Spriel | 549040a | 2012-03-02 22:55:48 +0100 | [diff] [blame] | 1204 | brcmf_sdio_init(); |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 1205 | #endif |
Arend van Spriel | 71bb244 | 2012-02-09 21:09:08 +0100 | [diff] [blame] | 1206 | #ifdef CONFIG_BRCMFMAC_USB |
Arend van Spriel | 549040a | 2012-03-02 22:55:48 +0100 | [diff] [blame] | 1207 | brcmf_usb_init(); |
Arend van Spriel | 71bb244 | 2012-02-09 21:09:08 +0100 | [diff] [blame] | 1208 | #endif |
Arend van Spriel | e64a4b7 | 2012-03-02 22:55:49 +0100 | [diff] [blame] | 1209 | } |
| 1210 | static DECLARE_WORK(brcmf_driver_work, brcmf_driver_init); |
| 1211 | |
| 1212 | static int __init brcmfmac_module_init(void) |
| 1213 | { |
| 1214 | if (!schedule_work(&brcmf_driver_work)) |
| 1215 | return -EBUSY; |
| 1216 | |
Arend van Spriel | 549040a | 2012-03-02 22:55:48 +0100 | [diff] [blame] | 1217 | return 0; |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 1218 | } |
| 1219 | |
Arend van Spriel | e64a4b7 | 2012-03-02 22:55:49 +0100 | [diff] [blame] | 1220 | static void __exit brcmfmac_module_exit(void) |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 1221 | { |
Arend van Spriel | e64a4b7 | 2012-03-02 22:55:49 +0100 | [diff] [blame] | 1222 | cancel_work_sync(&brcmf_driver_work); |
| 1223 | |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 1224 | #ifdef CONFIG_BRCMFMAC_SDIO |
| 1225 | brcmf_sdio_exit(); |
| 1226 | #endif |
Arend van Spriel | 71bb244 | 2012-02-09 21:09:08 +0100 | [diff] [blame] | 1227 | #ifdef CONFIG_BRCMFMAC_USB |
| 1228 | brcmf_usb_exit(); |
| 1229 | #endif |
Arend van Spriel | d319a7c | 2012-06-09 22:51:43 +0200 | [diff] [blame] | 1230 | brcmf_debugfs_exit(); |
Arend van Spriel | f3d7cdc | 2012-02-09 21:09:03 +0100 | [diff] [blame] | 1231 | } |
| 1232 | |
Arend van Spriel | e64a4b7 | 2012-03-02 22:55:49 +0100 | [diff] [blame] | 1233 | module_init(brcmfmac_module_init); |
| 1234 | module_exit(brcmfmac_module_exit); |