Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [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 | |
| 17 | #define __UNDEF_NO_VERSION__ |
| 18 | |
| 19 | #include <typedefs.h> |
| 20 | #include <linuxver.h> |
| 21 | #include <osl.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/netdevice.h> |
| 29 | #include <linux/etherdevice.h> |
| 30 | #include <linux/skbuff.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/string.h> |
| 33 | #include <linux/ethtool.h> |
| 34 | #include <linux/completion.h> |
| 35 | #include <linux/pci_ids.h> |
| 36 | #define WLC_MAXBSSCFG 1 /* single BSS configs */ |
| 37 | |
| 38 | #include <asm/system.h> |
| 39 | #include <asm/io.h> |
| 40 | #include <asm/irq.h> |
| 41 | #include <asm/pgtable.h> |
| 42 | #include <asm/uaccess.h> |
| 43 | #include <asm/unaligned.h> |
| 44 | #include <wlc_cfg.h> |
| 45 | #include <net/mac80211.h> |
| 46 | #include <epivers.h> |
| 47 | #ifndef WLC_HIGH_ONLY |
| 48 | #include <phy_version.h> |
| 49 | #endif |
| 50 | #include <bcmendian.h> |
| 51 | #include <bcmutils.h> |
| 52 | #include <pcicfg.h> |
| 53 | #include <wlioctl.h> |
| 54 | #include <wlc_key.h> |
| 55 | #include <proto/802.1d.h> /* NUMPRIO & BE */ |
| 56 | #include <linux/proc_fs.h> |
| 57 | #include <linux/vmalloc.h> |
| 58 | #include <wlc_channel.h> |
| 59 | #include <wlc_pub.h> |
| 60 | #include <wlc_scb.h> |
| 61 | #include <wl_dbg.h> |
| 62 | #ifdef BCMSDIO |
| 63 | #include <bcmsdh.h> |
| 64 | #endif |
| 65 | #include <wl_export.h> |
| 66 | #ifdef WLC_HIGH_ONLY |
| 67 | #include "dbus.h" |
| 68 | #include "bcm_rpc_tp.h" |
| 69 | #include "bcm_rpc.h" |
| 70 | #include "bcm_xdr.h" |
| 71 | #include "wlc_rpc.h" |
| 72 | #endif |
| 73 | |
| 74 | #include <wl_mac80211.h> |
| 75 | #include <linux/firmware.h> |
| 76 | #ifndef WLC_HIGH_ONLY |
| 77 | #include <wl_ucode.h> |
| 78 | #include <d11ucode_ext.h> |
| 79 | #endif |
| 80 | |
| 81 | #ifdef BCMSDIO |
| 82 | extern struct device *sdiommc_dev; |
| 83 | #endif |
| 84 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 85 | extern void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 86 | bool suspend); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 87 | bool wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw); |
| 88 | void wlc_mac_bcn_promisc_change(wlc_info_t *wlc, bool promisc); |
| 89 | void wlc_set_addrmatch(wlc_info_t *wlc, int match_reg_offset, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 90 | const struct ether_addr *addr); |
| 91 | |
| 92 | static void wl_timer(ulong data); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 93 | static void _wl_timer(wl_timer_t *t); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 94 | |
| 95 | /* proc fs */ |
| 96 | static int wl_proc_read(char *buffer, char **start, off_t offset, int length, |
| 97 | int *eof, void *data); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 98 | static int wl_proc_write(struct file *filp, const char __user *buff, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 99 | unsigned long len, void *data); |
| 100 | |
| 101 | #ifdef WLC_HIGH_ONLY |
| 102 | #define RPCQ_LOCK(_wl, _flags) spin_lock_irqsave(&(_wl)->rpcq_lock, (_flags)) |
| 103 | #define RPCQ_UNLOCK(_wl, _flags) spin_unlock_irqrestore(&(_wl)->rpcq_lock, (_flags)) |
| 104 | #define TXQ_LOCK(_wl, _flags) spin_lock_irqsave(&(_wl)->txq_lock, (_flags)) |
| 105 | #define TXQ_UNLOCK(_wl, _flags) spin_unlock_irqrestore(&(_wl)->txq_lock, (_flags)) |
| 106 | static void wl_rpc_down(void *wlh); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 107 | static void wl_rpcq_free(wl_info_t *wl); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 108 | static void wl_rpcq_dispatch(struct wl_task *task); |
| 109 | static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf); |
| 110 | static void wl_start_txqwork(struct wl_task *task); |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 111 | static void wl_txq_free(wl_info_t *wl); |
| 112 | static void wl_timer_task(wl_task_t *task); |
| 113 | static int wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 114 | void *context); |
| 115 | #endif /* WLC_HIGH_ONLY */ |
| 116 | |
| 117 | static int ieee_hw_init(struct ieee80211_hw *hw); |
| 118 | static int ieee_hw_rate_init(struct ieee80211_hw *hw); |
| 119 | |
| 120 | static int wl_linux_watchdog(void *ctx); |
| 121 | |
| 122 | /* Flags we support */ |
| 123 | #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \ |
| 124 | FIF_ALLMULTI | \ |
| 125 | FIF_FCSFAIL | \ |
| 126 | FIF_PLCPFAIL | \ |
| 127 | FIF_CONTROL | \ |
| 128 | FIF_OTHER_BSS | \ |
| 129 | FIF_BCN_PRBRESP_PROMISC) |
| 130 | |
| 131 | static int wl_found = 0; |
| 132 | |
| 133 | struct ieee80211_tkip_data { |
| 134 | #define TKIP_KEY_LEN 32 |
| 135 | u8 key[TKIP_KEY_LEN]; |
| 136 | int key_set; |
| 137 | |
| 138 | u32 tx_iv32; |
| 139 | u16 tx_iv16; |
| 140 | u16 tx_ttak[5]; |
| 141 | int tx_phase1_done; |
| 142 | |
| 143 | u32 rx_iv32; |
| 144 | u16 rx_iv16; |
| 145 | u16 rx_ttak[5]; |
| 146 | int rx_phase1_done; |
| 147 | u32 rx_iv32_new; |
| 148 | u16 rx_iv16_new; |
| 149 | |
| 150 | u32 dot11RSNAStatsTKIPReplays; |
| 151 | u32 dot11RSNAStatsTKIPICVErrors; |
| 152 | u32 dot11RSNAStatsTKIPLocalMICFailures; |
| 153 | |
| 154 | int key_idx; |
| 155 | |
| 156 | struct crypto_tfm *tfm_arc4; |
| 157 | struct crypto_tfm *tfm_michael; |
| 158 | |
| 159 | /* scratch buffers for virt_to_page() (crypto API) */ |
| 160 | u8 rx_hdr[16], tx_hdr[16]; |
| 161 | }; |
| 162 | |
| 163 | #ifndef WLC_HIGH_ONLY |
| 164 | #define WL_INFO(dev) ((wl_info_t*)(WL_DEV_IF(dev)->wl)) /* points to wl */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 165 | static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev); |
| 166 | static void wl_release_fw(wl_info_t *wl); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 167 | #endif |
| 168 | |
| 169 | /* local prototypes */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 170 | static int wl_start(struct sk_buff *skb, wl_info_t *wl); |
| 171 | static int wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 172 | struct sk_buff *skb); |
| 173 | static void wl_dpc(ulong data); |
| 174 | |
| 175 | MODULE_AUTHOR("Broadcom Corporation"); |
| 176 | MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver."); |
| 177 | MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards"); |
| 178 | MODULE_LICENSE("Dual BSD/GPL"); |
| 179 | |
| 180 | #ifndef BCMSDIO |
| 181 | /* recognized PCI IDs */ |
| 182 | static struct pci_device_id wl_id_table[] = { |
| 183 | {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */ |
| 184 | {PCI_VENDOR_ID_BROADCOM, 0x4353, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43224 DUAL */ |
| 185 | {PCI_VENDOR_ID_BROADCOM, 0x4727, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 4313 DUAL */ |
| 186 | {0} |
| 187 | }; |
| 188 | |
| 189 | MODULE_DEVICE_TABLE(pci, wl_id_table); |
| 190 | #endif /* !BCMSDIO */ |
| 191 | |
| 192 | #ifdef BCMSDIO |
| 193 | static uint sd_drivestrength = 6; |
| 194 | module_param(sd_drivestrength, uint, 0); |
| 195 | #endif |
| 196 | |
| 197 | #ifdef BCMDBG |
| 198 | static int msglevel = 0xdeadbeef; |
| 199 | module_param(msglevel, int, 0); |
| 200 | #ifndef WLC_HIGH_ONLY |
| 201 | static int phymsglevel = 0xdeadbeef; |
| 202 | module_param(phymsglevel, int, 0); |
| 203 | #endif /* WLC_HIGH_ONLY */ |
| 204 | #endif /* BCMDBG */ |
| 205 | |
| 206 | static int oneonly = 0; |
| 207 | module_param(oneonly, int, 0); |
| 208 | |
| 209 | static int piomode = 0; |
| 210 | module_param(piomode, int, 0); |
| 211 | |
| 212 | static int instance_base = 0; /* Starting instance number */ |
| 213 | module_param(instance_base, int, 0); |
| 214 | |
| 215 | #if defined(BCMDBG) |
| 216 | static char *macaddr = NULL; |
| 217 | module_param(macaddr, charp, S_IRUGO); |
| 218 | #endif |
| 219 | |
| 220 | static int nompc = 1; |
| 221 | module_param(nompc, int, 0); |
| 222 | |
| 223 | static char name[IFNAMSIZ] = "eth%d"; |
| 224 | module_param_string(name, name, IFNAMSIZ, 0); |
| 225 | |
| 226 | #ifndef SRCBASE |
| 227 | #define SRCBASE "." |
| 228 | #endif |
| 229 | |
| 230 | #define WL_MAGIC 0xdeadbeef |
| 231 | |
| 232 | #define HW_TO_WL(hw) hw->priv |
| 233 | #define WL_TO_HW(wl) wl->pub->ieee_hw |
| 234 | #ifdef WLC_HIGH_ONLY |
| 235 | static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb); |
| 236 | #else |
| 237 | static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb); |
| 238 | #endif |
| 239 | static int wl_ops_start(struct ieee80211_hw *hw); |
| 240 | static void wl_ops_stop(struct ieee80211_hw *hw); |
| 241 | static int wl_ops_add_interface(struct ieee80211_hw *hw, |
| 242 | struct ieee80211_vif *vif); |
| 243 | static void wl_ops_remove_interface(struct ieee80211_hw *hw, |
| 244 | struct ieee80211_vif *vif); |
| 245 | static int wl_ops_config(struct ieee80211_hw *hw, u32 changed); |
| 246 | static void wl_ops_bss_info_changed(struct ieee80211_hw *hw, |
| 247 | struct ieee80211_vif *vif, |
| 248 | struct ieee80211_bss_conf *info, |
| 249 | u32 changed); |
| 250 | static void wl_ops_configure_filter(struct ieee80211_hw *hw, |
| 251 | unsigned int changed_flags, |
| 252 | unsigned int *total_flags, u64 multicast); |
| 253 | static int wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, |
| 254 | bool set); |
| 255 | static void wl_ops_sw_scan_start(struct ieee80211_hw *hw); |
| 256 | static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw); |
| 257 | static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf); |
| 258 | static int wl_ops_get_stats(struct ieee80211_hw *hw, |
| 259 | struct ieee80211_low_level_stats *stats); |
| 260 | static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value); |
| 261 | static void wl_ops_sta_notify(struct ieee80211_hw *hw, |
| 262 | struct ieee80211_vif *vif, |
| 263 | enum sta_notify_cmd cmd, |
| 264 | struct ieee80211_sta *sta); |
| 265 | static int wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue, |
| 266 | const struct ieee80211_tx_queue_params *params); |
| 267 | static u64 wl_ops_get_tsf(struct ieee80211_hw *hw); |
| 268 | static int wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 269 | struct ieee80211_sta *sta); |
| 270 | static int wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 271 | struct ieee80211_sta *sta); |
| 272 | static int wl_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 273 | enum ieee80211_ampdu_mlme_action action, |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 274 | struct ieee80211_sta *sta, u16 tid, u16 *ssn); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 275 | |
| 276 | #ifdef WLC_HIGH_ONLY |
| 277 | static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 278 | { |
| 279 | int status; |
| 280 | wl_info_t *wl = hw->priv; |
| 281 | if (!wl->pub->up) { |
| 282 | WL_ERROR(("ops->tx called while down\n")); |
| 283 | status = -ENETDOWN; |
| 284 | goto done; |
| 285 | } |
| 286 | status = wl_start(skb, wl); |
| 287 | done: |
| 288 | return status; |
| 289 | } |
| 290 | #else |
| 291 | static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 292 | { |
| 293 | int status; |
| 294 | wl_info_t *wl = hw->priv; |
| 295 | WL_LOCK(wl); |
| 296 | if (!wl->pub->up) { |
| 297 | WL_ERROR(("ops->tx called while down\n")); |
| 298 | status = -ENETDOWN; |
| 299 | goto done; |
| 300 | } |
| 301 | status = wl_start(skb, wl); |
| 302 | done: |
| 303 | WL_UNLOCK(wl); |
| 304 | return status; |
| 305 | } |
| 306 | #endif /* WLC_HIGH_ONLY */ |
| 307 | |
| 308 | static int wl_ops_start(struct ieee80211_hw *hw) |
| 309 | { |
| 310 | wl_info_t *wl = hw->priv; |
| 311 | /* struct ieee80211_channel *curchan = hw->conf.channel; */ |
| 312 | WL_NONE(("%s : Initial channel: %d\n", __func__, curchan->hw_value)); |
| 313 | |
| 314 | WL_LOCK(wl); |
| 315 | ieee80211_wake_queues(hw); |
| 316 | WL_UNLOCK(wl); |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static void wl_ops_stop(struct ieee80211_hw *hw) |
| 322 | { |
| 323 | wl_info_t *wl = hw->priv; |
| 324 | ASSERT(wl); |
| 325 | WL_LOCK(wl); |
| 326 | wl_down(wl); |
| 327 | ieee80211_stop_queues(hw); |
| 328 | WL_UNLOCK(wl); |
| 329 | |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | static int |
| 334 | wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 335 | { |
| 336 | wl_info_t *wl; |
| 337 | int err; |
| 338 | |
| 339 | /* Just STA for now */ |
| 340 | if (vif->type != NL80211_IFTYPE_AP && |
| 341 | vif->type != NL80211_IFTYPE_MESH_POINT && |
| 342 | vif->type != NL80211_IFTYPE_STATION && |
| 343 | vif->type != NL80211_IFTYPE_WDS && |
| 344 | vif->type != NL80211_IFTYPE_ADHOC) { |
| 345 | WL_ERROR(("%s: Attempt to add type %d, only STA for now\n", |
| 346 | __func__, vif->type)); |
| 347 | return -EOPNOTSUPP; |
| 348 | } |
| 349 | |
| 350 | wl = HW_TO_WL(hw); |
| 351 | WL_LOCK(wl); |
| 352 | err = wl_up(wl); |
| 353 | WL_UNLOCK(wl); |
| 354 | |
| 355 | if (err != 0) |
| 356 | WL_ERROR(("%s: wl_up() returned %d\n", __func__, err)); |
| 357 | return err; |
| 358 | } |
| 359 | |
| 360 | static void |
| 361 | wl_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 362 | { |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | static int |
| 367 | ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan, |
| 368 | enum nl80211_channel_type type) |
| 369 | { |
| 370 | wl_info_t *wl = HW_TO_WL(hw); |
| 371 | int err = 0; |
| 372 | |
| 373 | switch (type) { |
| 374 | case NL80211_CHAN_HT20: |
| 375 | case NL80211_CHAN_NO_HT: |
| 376 | WL_LOCK(wl); |
| 377 | err = wlc_set(wl->wlc, WLC_SET_CHANNEL, chan->hw_value); |
| 378 | WL_UNLOCK(wl); |
| 379 | break; |
| 380 | case NL80211_CHAN_HT40MINUS: |
| 381 | case NL80211_CHAN_HT40PLUS: |
| 382 | WL_ERROR(("%s: Need to implement 40 Mhz Channels!\n", |
| 383 | __func__)); |
| 384 | break; |
| 385 | } |
| 386 | |
| 387 | if (err) |
| 388 | return -EIO; |
| 389 | return err; |
| 390 | } |
| 391 | |
| 392 | static int wl_ops_config(struct ieee80211_hw *hw, u32 changed) |
| 393 | { |
| 394 | struct ieee80211_conf *conf = &hw->conf; |
| 395 | wl_info_t *wl = HW_TO_WL(hw); |
| 396 | int err = 0; |
| 397 | int new_int; |
| 398 | |
| 399 | if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { |
| 400 | WL_NONE(("%s: Setting listen interval to %d\n", |
| 401 | __func__, conf->listen_interval)); |
| 402 | if (wlc_iovar_setint |
| 403 | (wl->wlc, "bcn_li_bcn", conf->listen_interval)) { |
| 404 | WL_ERROR(("%s: Error setting listen_interval\n", |
| 405 | __func__)); |
| 406 | err = -EIO; |
| 407 | goto config_out; |
| 408 | } |
| 409 | wlc_iovar_getint(wl->wlc, "bcn_li_bcn", &new_int); |
| 410 | ASSERT(new_int == conf->listen_interval); |
| 411 | } |
| 412 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) |
| 413 | WL_NONE(("Need to set monitor mode\n")); |
| 414 | if (changed & IEEE80211_CONF_CHANGE_PS) |
| 415 | WL_NONE(("Need to set Power-save mode\n")); |
| 416 | |
| 417 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 418 | WL_NONE(("%s: Setting tx power to %d dbm\n", __func__, |
| 419 | conf->power_level)); |
| 420 | if (wlc_iovar_setint |
| 421 | (wl->wlc, "qtxpower", conf->power_level * 4)) { |
| 422 | WL_ERROR(("%s: Error setting power_level\n", __func__)); |
| 423 | err = -EIO; |
| 424 | goto config_out; |
| 425 | } |
| 426 | wlc_iovar_getint(wl->wlc, "qtxpower", &new_int); |
| 427 | if (new_int != (conf->power_level * 4)) |
| 428 | WL_ERROR(("%s: Power level req != actual, %d %d\n", |
| 429 | __func__, conf->power_level * 4, new_int)); |
| 430 | } |
| 431 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 432 | err = ieee_set_channel(hw, conf->channel, conf->channel_type); |
| 433 | } |
| 434 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { |
| 435 | WL_NONE(("%s: srl %d, lrl %d\n", __func__, |
| 436 | conf->short_frame_max_tx_count, |
| 437 | conf->long_frame_max_tx_count)); |
| 438 | if (wlc_set |
| 439 | (wl->wlc, WLC_SET_SRL, |
| 440 | conf->short_frame_max_tx_count) < 0) { |
| 441 | WL_ERROR(("%s: Error setting srl\n", __func__)); |
| 442 | err = -EIO; |
| 443 | goto config_out; |
| 444 | } |
| 445 | if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count) |
| 446 | < 0) { |
| 447 | WL_ERROR(("%s: Error setting lrl\n", __func__)); |
| 448 | err = -EIO; |
| 449 | goto config_out; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | config_out: |
| 454 | return err; |
| 455 | } |
| 456 | |
| 457 | static void |
| 458 | wl_ops_bss_info_changed(struct ieee80211_hw *hw, |
| 459 | struct ieee80211_vif *vif, |
| 460 | struct ieee80211_bss_conf *info, u32 changed) |
| 461 | { |
| 462 | wl_info_t *wl = HW_TO_WL(hw); |
| 463 | int val; |
| 464 | |
| 465 | #ifdef WLC_HIGH_ONLY |
| 466 | WL_LOCK(wl); |
| 467 | #endif |
| 468 | |
| 469 | if (changed & BSS_CHANGED_ASSOC) { |
| 470 | WL_ERROR(("Associated:\t%s\n", info->assoc ? "True" : "False")); |
| 471 | /* association status changed (associated/disassociated) |
| 472 | * also implies a change in the AID. |
| 473 | */ |
| 474 | } |
| 475 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 476 | WL_NONE(("Use_cts_prot:\t%s Implement me\n", |
| 477 | info->use_cts_prot ? "True" : "False")); |
| 478 | /* CTS protection changed */ |
| 479 | } |
| 480 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 481 | WL_NONE(("Short preamble:\t%s Implement me\n", |
| 482 | info->use_short_preamble ? "True" : "False")); |
| 483 | /* preamble changed */ |
| 484 | } |
| 485 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 486 | WL_NONE(("Changing short slot:\t%s\n", |
| 487 | info->use_short_slot ? "True" : "False")); |
| 488 | if (info->use_short_slot) |
| 489 | val = 1; |
| 490 | else |
| 491 | val = 0; |
| 492 | wlc_set(wl->wlc, WLC_SET_SHORTSLOT_OVERRIDE, val); |
| 493 | /* slot timing changed */ |
| 494 | } |
| 495 | |
| 496 | if (changed & BSS_CHANGED_HT) { |
| 497 | WL_NONE(("%s: HT mode - Implement me\n", __func__)); |
| 498 | /* 802.11n parameters changed */ |
| 499 | } |
| 500 | if (changed & BSS_CHANGED_BASIC_RATES) { |
| 501 | WL_NONE(("Need to change Basic Rates:\t0x%x! Implement me\n", |
| 502 | (uint32) info->basic_rates)); |
| 503 | /* Basic rateset changed */ |
| 504 | } |
| 505 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 506 | WL_NONE(("Beacon Interval:\t%d Implement me\n", |
| 507 | info->beacon_int)); |
| 508 | /* Beacon interval changed */ |
| 509 | } |
| 510 | if (changed & BSS_CHANGED_BSSID) { |
| 511 | /* char eabuf[ETHER_ADDR_STR_LEN]; */ |
| 512 | WL_NONE(("new BSSID:\taid %d bss:%s\n", |
| 513 | info->aid, |
| 514 | bcm_ether_ntoa((struct ether_addr *)info->bssid, |
| 515 | eabuf))); |
| 516 | /* BSSID changed, for whatever reason (IBSS and managed mode) */ |
| 517 | /* FIXME: need to store bssid in bsscfg */ |
| 518 | wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, |
| 519 | (struct ether_addr *)info->bssid); |
| 520 | } |
| 521 | if (changed & BSS_CHANGED_BEACON) { |
| 522 | WL_ERROR(("BSS_CHANGED_BEACON\n")); |
| 523 | /* Beacon data changed, retrieve new beacon (beaconing modes) */ |
| 524 | } |
| 525 | if (changed & BSS_CHANGED_BEACON_ENABLED) { |
| 526 | WL_ERROR(("Beacon enabled:\t%s\n", |
| 527 | info->enable_beacon ? "True" : "False")); |
| 528 | /* Beaconing should be enabled/disabled (beaconing modes) */ |
| 529 | } |
| 530 | #ifdef WLC_HIGH_ONLY |
| 531 | WL_UNLOCK(wl); |
| 532 | #endif |
| 533 | return; |
| 534 | } |
| 535 | |
| 536 | static void |
| 537 | wl_ops_configure_filter(struct ieee80211_hw *hw, |
| 538 | unsigned int changed_flags, |
| 539 | unsigned int *total_flags, u64 multicast) |
| 540 | { |
| 541 | #ifndef WLC_HIGH_ONLY |
| 542 | wl_info_t *wl = hw->priv; |
| 543 | #endif |
| 544 | |
| 545 | changed_flags &= MAC_FILTERS; |
| 546 | *total_flags &= MAC_FILTERS; |
| 547 | if (changed_flags & FIF_PROMISC_IN_BSS) |
| 548 | WL_ERROR(("FIF_PROMISC_IN_BSS\n")); |
| 549 | if (changed_flags & FIF_ALLMULTI) |
| 550 | WL_ERROR(("FIF_ALLMULTI\n")); |
| 551 | if (changed_flags & FIF_FCSFAIL) |
| 552 | WL_ERROR(("FIF_FCSFAIL\n")); |
| 553 | if (changed_flags & FIF_PLCPFAIL) |
| 554 | WL_ERROR(("FIF_PLCPFAIL\n")); |
| 555 | if (changed_flags & FIF_CONTROL) |
| 556 | WL_ERROR(("FIF_CONTROL\n")); |
| 557 | if (changed_flags & FIF_OTHER_BSS) |
| 558 | WL_ERROR(("FIF_OTHER_BSS\n")); |
| 559 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 560 | WL_NONE(("FIF_BCN_PRBRESP_PROMISC\n")); |
| 561 | #ifndef WLC_HIGH_ONLY |
| 562 | WL_LOCK(wl); |
| 563 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 564 | wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS; |
| 565 | wlc_mac_bcn_promisc_change(wl->wlc, 1); |
| 566 | } else { |
| 567 | wlc_mac_bcn_promisc_change(wl->wlc, 0); |
| 568 | wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS; |
| 569 | } |
| 570 | WL_UNLOCK(wl); |
| 571 | #endif |
| 572 | } |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | static int |
| 577 | wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set) |
| 578 | { |
| 579 | WL_ERROR(("%s: Enter\n", __func__)); |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | static void wl_ops_sw_scan_start(struct ieee80211_hw *hw) |
| 584 | { |
| 585 | WL_NONE(("Scan Start\n")); |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw) |
| 590 | { |
| 591 | WL_NONE(("Scan Complete\n")); |
| 592 | return; |
| 593 | } |
| 594 | |
| 595 | static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf) |
| 596 | { |
| 597 | WL_ERROR(("%s: Enter\n", __func__)); |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | static int |
| 602 | wl_ops_get_stats(struct ieee80211_hw *hw, |
| 603 | struct ieee80211_low_level_stats *stats) |
| 604 | { |
| 605 | WL_ERROR(("%s: Enter\n", __func__)); |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 610 | { |
| 611 | WL_ERROR(("%s: Enter\n", __func__)); |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | static void |
| 616 | wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 617 | enum sta_notify_cmd cmd, struct ieee80211_sta *sta) |
| 618 | { |
| 619 | WL_NONE(("%s: Enter\n", __func__)); |
| 620 | switch (cmd) { |
| 621 | default: |
| 622 | WL_ERROR(("%s: Uknown cmd = %d\n", __func__, cmd)); |
| 623 | break; |
| 624 | } |
| 625 | return; |
| 626 | } |
| 627 | |
| 628 | static int |
| 629 | wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue, |
| 630 | const struct ieee80211_tx_queue_params *params) |
| 631 | { |
| 632 | wl_info_t *wl = hw->priv; |
| 633 | |
| 634 | WL_NONE(("%s: Enter (WME config)\n", __func__)); |
| 635 | WL_NONE(("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue, |
| 636 | params->txop, params->cw_min, params->cw_max, params->aifs)); |
| 637 | |
| 638 | WL_LOCK(wl); |
| 639 | wlc_wme_setparams(wl->wlc, queue, (void *)params, TRUE); |
| 640 | WL_UNLOCK(wl); |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | static u64 wl_ops_get_tsf(struct ieee80211_hw *hw) |
| 646 | { |
| 647 | WL_ERROR(("%s: Enter\n", __func__)); |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | static int |
| 652 | wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 653 | struct ieee80211_sta *sta) |
| 654 | { |
| 655 | struct scb *scb; |
| 656 | |
| 657 | int i; |
| 658 | wl_info_t *wl = hw->priv; |
| 659 | |
| 660 | /* Init the scb */ |
| 661 | scb = (struct scb *)sta->drv_priv; |
| 662 | bzero(scb, sizeof(struct scb)); |
| 663 | for (i = 0; i < NUMPRIO; i++) |
| 664 | scb->seqctl[i] = 0xFFFF; |
| 665 | scb->seqctl_nonqos = 0xFFFF; |
| 666 | scb->magic = SCB_MAGIC; |
| 667 | |
| 668 | wl->pub->global_scb = scb; |
| 669 | wl->pub->global_ampdu = &(scb->scb_ampdu); |
| 670 | wl->pub->global_ampdu->scb = scb; |
| 671 | #ifdef WLC_HIGH_ONLY |
| 672 | wl->pub->global_ampdu->max_pdu = AMPDU_NUM_MPDU; |
| 673 | #else |
| 674 | wl->pub->global_ampdu->max_pdu = 16; |
| 675 | #endif |
| 676 | pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID, |
| 677 | AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT); |
| 678 | |
| 679 | sta->ht_cap.ht_supported = TRUE; |
| 680 | #ifdef WLC_HIGH_ONLY |
| 681 | sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_16K; |
| 682 | #else |
| 683 | sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K; |
| 684 | #endif |
| 685 | sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY; |
| 686 | sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD | |
| 687 | IEEE80211_HT_CAP_SGI_20 | |
| 688 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT; |
| 689 | |
| 690 | /* minstrel_ht initiates addBA on our behalf by calling ieee80211_start_tx_ba_session() */ |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | static int |
| 695 | wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 696 | struct ieee80211_sta *sta) |
| 697 | { |
| 698 | WL_NONE(("%s: Enter\n", __func__)); |
| 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | static int |
| 703 | wl_ampdu_action(struct ieee80211_hw *hw, |
| 704 | struct ieee80211_vif *vif, |
| 705 | enum ieee80211_ampdu_mlme_action action, |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 706 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 707 | { |
| 708 | #if defined(BCMDBG) |
| 709 | struct scb *scb = (struct scb *)sta->drv_priv; |
| 710 | #endif |
| 711 | wl_info_t *wl = hw->priv; |
| 712 | |
| 713 | ASSERT(scb->magic == SCB_MAGIC); |
| 714 | switch (action) { |
| 715 | case IEEE80211_AMPDU_RX_START: |
| 716 | WL_NONE(("%s: action = IEEE80211_AMPDU_RX_START\n", __func__)); |
| 717 | break; |
| 718 | case IEEE80211_AMPDU_RX_STOP: |
| 719 | WL_NONE(("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__)); |
| 720 | break; |
| 721 | case IEEE80211_AMPDU_TX_START: |
| 722 | if (!wlc_aggregatable(wl->wlc, tid)) { |
| 723 | /* WL_ERROR(("START: tid %d is not agg' able, return FAILURE to stack\n", tid)); */ |
| 724 | return -1; |
| 725 | } |
| 726 | /* XXX: Use the starting sequence number provided ... */ |
| 727 | *ssn = 0; |
| 728 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 729 | break; |
| 730 | |
| 731 | case IEEE80211_AMPDU_TX_STOP: |
| 732 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 733 | break; |
| 734 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 735 | /* Not sure what to do here */ |
| 736 | /* Power save wakeup */ |
| 737 | WL_NONE(("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n", |
| 738 | __func__)); |
| 739 | break; |
| 740 | default: |
| 741 | WL_ERROR(("%s: Invalid command, ignoring\n", __func__)); |
| 742 | } |
| 743 | |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | static const struct ieee80211_ops wl_ops = { |
| 748 | #ifdef WLC_HIGH_ONLY |
| 749 | .tx = wl_ops_tx_nl, |
| 750 | #else |
| 751 | .tx = wl_ops_tx, |
| 752 | #endif |
| 753 | .start = wl_ops_start, |
| 754 | .stop = wl_ops_stop, |
| 755 | .add_interface = wl_ops_add_interface, |
| 756 | .remove_interface = wl_ops_remove_interface, |
| 757 | .config = wl_ops_config, |
| 758 | .bss_info_changed = wl_ops_bss_info_changed, |
| 759 | .configure_filter = wl_ops_configure_filter, |
| 760 | .set_tim = wl_ops_set_tim, |
| 761 | .sw_scan_start = wl_ops_sw_scan_start, |
| 762 | .sw_scan_complete = wl_ops_sw_scan_complete, |
| 763 | .set_tsf = wl_ops_set_tsf, |
| 764 | .get_stats = wl_ops_get_stats, |
| 765 | .set_rts_threshold = wl_ops_set_rts_threshold, |
| 766 | .sta_notify = wl_ops_sta_notify, |
| 767 | .conf_tx = wl_ops_conf_tx, |
| 768 | .get_tsf = wl_ops_get_tsf, |
| 769 | .sta_add = wl_sta_add, |
| 770 | .sta_remove = wl_sta_remove, |
| 771 | .ampdu_action = wl_ampdu_action, |
| 772 | }; |
| 773 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 774 | static int wl_set_hint(wl_info_t *wl, char *abbrev) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 775 | { |
| 776 | WL_ERROR(("%s: Sending country code %c%c to MAC80211\n", __func__, |
| 777 | abbrev[0], abbrev[1])); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 778 | return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /** |
| 782 | * attach to the WL device. |
| 783 | * |
| 784 | * Attach to the WL device identified by vendor and device parameters. |
| 785 | * regs is a host accessible memory address pointing to WL device registers. |
| 786 | * |
| 787 | * wl_attach is not defined as static because in the case where no bus |
| 788 | * is defined, wl_attach will never be called, and thus, gcc will issue |
| 789 | * a warning that this function is defined but not used if we declare |
| 790 | * it as static. |
| 791 | */ |
| 792 | static wl_info_t *wl_attach(uint16 vendor, uint16 device, ulong regs, |
| 793 | uint bustype, void *btparam, uint irq) |
| 794 | { |
| 795 | wl_info_t *wl; |
| 796 | osl_t *osh; |
| 797 | int unit, err; |
| 798 | |
| 799 | ulong base_addr; |
| 800 | struct ieee80211_hw *hw; |
| 801 | uint8 perm[ETH_ALEN]; |
| 802 | |
| 803 | unit = wl_found + instance_base; |
| 804 | err = 0; |
| 805 | |
| 806 | if (unit < 0) { |
| 807 | WL_ERROR(("wl%d: unit number overflow, exiting\n", unit)); |
| 808 | return NULL; |
| 809 | } |
| 810 | |
| 811 | if (oneonly && (unit != instance_base)) { |
| 812 | WL_ERROR(("wl%d: wl_attach: oneonly is set, exiting\n", unit)); |
| 813 | return NULL; |
| 814 | } |
| 815 | |
| 816 | /* Requires pkttag feature */ |
| 817 | osh = osl_attach(btparam, bustype, TRUE); |
| 818 | ASSERT(osh); |
| 819 | |
| 820 | #ifdef WLC_HIGH_ONLY |
| 821 | hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops); |
| 822 | if (!hw) { |
| 823 | WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__)); |
| 824 | ASSERT(0); |
| 825 | } |
| 826 | |
| 827 | bzero(hw->priv, sizeof(*wl)); |
| 828 | wl = hw->priv; |
| 829 | #else |
| 830 | /* allocate private info */ |
| 831 | hw = pci_get_drvdata(btparam); /* btparam == pdev */ |
| 832 | wl = hw->priv; |
| 833 | #endif |
| 834 | ASSERT(wl); |
| 835 | |
| 836 | wl->magic = WL_MAGIC; |
| 837 | wl->osh = osh; |
| 838 | atomic_set(&wl->callbacks, 0); |
| 839 | |
Ben Hutchings | eb4764c | 2010-09-10 01:38:18 +0100 | [diff] [blame] | 840 | /* setup the bottom half handler */ |
| 841 | tasklet_init(&wl->tasklet, wl_dpc, (ulong) wl); |
| 842 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 843 | #ifdef WLC_HIGH_ONLY |
| 844 | wl->rpc_th = bcm_rpc_tp_attach(osh, NULL); |
| 845 | if (wl->rpc_th == NULL) { |
| 846 | WL_ERROR(("wl%d: %s: bcm_rpc_tp_attach failed!\n", unit, |
| 847 | __func__)); |
| 848 | goto fail; |
| 849 | } |
| 850 | |
| 851 | wl->rpc = bcm_rpc_attach(NULL, osh, wl->rpc_th); |
| 852 | if (wl->rpc == NULL) { |
| 853 | WL_ERROR(("wl%d: %s: bcm_rpc_attach failed!\n", unit, |
| 854 | __func__)); |
| 855 | goto fail; |
| 856 | } |
| 857 | |
| 858 | /* init tx work queue for wl_start/send pkt; no need to destroy workitem */ |
| 859 | MY_INIT_WORK(&wl->txq_task.work, (work_func_t) wl_start_txqwork); |
| 860 | wl->txq_task.context = wl; |
| 861 | #endif /* WLC_HIGH_ONLY */ |
| 862 | |
| 863 | #ifdef BCMSDIO |
| 864 | SET_IEEE80211_DEV(hw, sdiommc_dev); |
| 865 | #endif |
| 866 | |
| 867 | base_addr = regs; |
| 868 | |
| 869 | if (bustype == PCI_BUS) { |
| 870 | /* piomode can be overwritten by command argument */ |
| 871 | wl->piomode = piomode; |
| 872 | WL_TRACE(("PCI/%s\n", wl->piomode ? "PIO" : "DMA")); |
| 873 | } else if (bustype == RPC_BUS) { |
| 874 | /* Do nothing */ |
| 875 | } else { |
| 876 | bustype = PCI_BUS; |
| 877 | WL_TRACE(("force to PCI\n")); |
| 878 | } |
| 879 | wl->bcm_bustype = bustype; |
| 880 | |
| 881 | #ifdef WLC_HIGH_ONLY |
| 882 | if (wl->bcm_bustype == RPC_BUS) { |
| 883 | wl->regsva = (void *)0; |
| 884 | btparam = wl->rpc; |
| 885 | } else |
| 886 | #endif |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 887 | wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ); |
| 888 | if (wl->regsva == NULL) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 889 | WL_ERROR(("wl%d: ioremap() failed\n", unit)); |
| 890 | goto fail; |
| 891 | } |
| 892 | #ifdef WLC_HIGH_ONLY |
| 893 | spin_lock_init(&wl->rpcq_lock); |
| 894 | spin_lock_init(&wl->txq_lock); |
| 895 | |
| 896 | init_MUTEX(&wl->sem); |
| 897 | #else |
| 898 | spin_lock_init(&wl->lock); |
| 899 | spin_lock_init(&wl->isr_lock); |
| 900 | #endif |
| 901 | |
| 902 | #ifndef WLC_HIGH_ONLY |
| 903 | /* prepare ucode */ |
| 904 | if (wl_request_fw(wl, (struct pci_dev *)btparam)) { |
| 905 | printf("%s: %s driver failed\n", KBUILD_MODNAME, |
| 906 | EPI_VERSION_STR); |
| 907 | goto fail; |
| 908 | } |
| 909 | #endif |
| 910 | |
| 911 | /* common load-time initialization */ |
Ben Hutchings | eb4764c | 2010-09-10 01:38:18 +0100 | [diff] [blame] | 912 | wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh, |
| 913 | wl->regsva, wl->bcm_bustype, btparam, &err); |
| 914 | #ifndef WLC_HIGH_ONLY |
| 915 | wl_release_fw(wl); |
| 916 | #endif |
| 917 | if (!wl->wlc) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 918 | printf("%s: %s driver failed with code %d\n", KBUILD_MODNAME, |
| 919 | EPI_VERSION_STR, err); |
| 920 | goto fail; |
| 921 | } |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 922 | wl->pub = wlc_pub(wl->wlc); |
| 923 | |
| 924 | wl->pub->ieee_hw = hw; |
| 925 | ASSERT(wl->pub->ieee_hw); |
| 926 | ASSERT(wl->pub->ieee_hw->priv == wl); |
| 927 | |
| 928 | #ifdef WLC_HIGH_ONLY |
| 929 | REGOPSSET(osh, (osl_rreg_fn_t) wlc_reg_read, |
| 930 | (osl_wreg_fn_t) wlc_reg_write, wl->wlc); |
| 931 | wl->rpc_dispatch_ctx.rpc = wl->rpc; |
| 932 | wl->rpc_dispatch_ctx.wlc = wl->wlc; |
| 933 | bcm_rpc_rxcb_init(wl->rpc, wl, wl_rpc_dispatch_schedule, wl, |
| 934 | wl_rpc_down, NULL, NULL); |
| 935 | #endif /* WLC_HIGH_ONLY */ |
| 936 | |
| 937 | if (nompc) { |
| 938 | if (wlc_iovar_setint(wl->wlc, "mpc", 0)) { |
| 939 | WL_ERROR(("wl%d: Error setting MPC variable to 0\n", |
| 940 | unit)); |
| 941 | } |
| 942 | } |
| 943 | #ifdef BCMSDIO |
| 944 | /* Set SDIO drive strength */ |
| 945 | wlc_iovar_setint(wl->wlc, "sd_drivestrength", sd_drivestrength); |
| 946 | #endif |
| 947 | |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 948 | #ifdef WLC_LOW |
| 949 | /* register our interrupt handler */ |
| 950 | if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) { |
| 951 | WL_ERROR(("wl%d: request_irq() failed\n", unit)); |
| 952 | goto fail; |
| 953 | } |
| 954 | wl->irq = irq; |
| 955 | #endif /* WLC_LOW */ |
| 956 | |
| 957 | /* register module */ |
| 958 | wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog, |
| 959 | NULL); |
| 960 | |
| 961 | if (ieee_hw_init(hw)) { |
| 962 | WL_ERROR(("wl%d: %s: ieee_hw_init failed!\n", unit, __func__)); |
| 963 | goto fail; |
| 964 | } |
| 965 | |
| 966 | bcopy(&wl->pub->cur_etheraddr, perm, ETHER_ADDR_LEN); |
| 967 | ASSERT(is_valid_ether_addr(perm)); |
| 968 | SET_IEEE80211_PERM_ADDR(hw, perm); |
| 969 | |
| 970 | err = ieee80211_register_hw(hw); |
| 971 | if (err) { |
| 972 | WL_ERROR(("%s: ieee80211_register_hw failed, status %d\n", |
| 973 | __func__, err)); |
| 974 | } |
| 975 | |
| 976 | if (wl->pub->srom_ccode[0]) |
| 977 | err = wl_set_hint(wl, wl->pub->srom_ccode); |
| 978 | else |
| 979 | err = wl_set_hint(wl, "US"); |
| 980 | if (err) { |
| 981 | WL_ERROR(("%s: regulatory_hint failed, status %d\n", __func__, |
| 982 | err)); |
| 983 | } |
| 984 | #ifndef WLC_HIGH_ONLY |
| 985 | WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver " |
| 986 | EPI_VERSION_STR " (" PHY_VERSION_STR ")", unit)); |
| 987 | #else |
| 988 | WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver " |
| 989 | EPI_VERSION_STR, unit)); |
| 990 | #endif |
| 991 | |
| 992 | #ifdef BCMDBG |
| 993 | printf(" (Compiled in " SRCBASE " at " __TIME__ " on " __DATE__ ")"); |
| 994 | #endif /* BCMDBG */ |
| 995 | printf("\n"); |
| 996 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 997 | wl->proc_entry = create_proc_entry(PROC_ENTRY_NAME, 0644, NULL); |
| 998 | if (wl->proc_entry == NULL) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 999 | WL_ERROR(("create_proc_entry failed *******\n")); |
| 1000 | ASSERT(0); |
| 1001 | } else { |
| 1002 | wl->proc_entry->read_proc = wl_proc_read; |
| 1003 | wl->proc_entry->write_proc = wl_proc_write; |
| 1004 | wl->proc_entry->data = wl; |
| 1005 | /* wl->proc_entry->owner = THIS_MODULE; */ |
| 1006 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 1007 | wl->ioctlbuf = (char *)vmalloc(PAGE_SIZE); |
| 1008 | if (wl->ioctlbuf == NULL) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1009 | WL_ERROR(("%s: Vmalloc failed\n", __func__)); |
| 1010 | } |
| 1011 | wl->ioctlbuf_sz = PAGE_SIZE; |
| 1012 | memset(wl->ioctlbuf, 0, PAGE_SIZE); |
| 1013 | wl->ioctlbuf[0] = '!'; |
| 1014 | } |
| 1015 | |
| 1016 | wl_found++; |
| 1017 | return wl; |
| 1018 | |
| 1019 | fail: |
| 1020 | wl_free(wl); |
| 1021 | return NULL; |
| 1022 | } |
| 1023 | |
| 1024 | #define PROC_MESSAGE "Broadcom driver debugger access only. Requires matching 'wl' app\n" |
| 1025 | |
| 1026 | /* OS Entry point when app attempts to read */ |
| 1027 | static int |
| 1028 | wl_proc_read(char *buffer, char **start, off_t offset, int length, int *eof, |
| 1029 | void *data) |
| 1030 | { |
| 1031 | wl_info_t *wl = (wl_info_t *) data; |
| 1032 | |
| 1033 | switch (wl->proc_state) { |
| 1034 | |
| 1035 | case WL_PROC_IDLE: |
| 1036 | return 0; |
| 1037 | |
| 1038 | case WL_PROC_HAVE_IOC: |
| 1039 | /* Give the processed buffer back to userland */ |
| 1040 | if (!wl->ioctl_in_progress) { |
| 1041 | WL_ERROR(("%s: No ioctl in progress nothing to read, 2\n", __func__)); |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | if (wl->ioc.len > wl->ioctlbuf_sz) { |
| 1046 | } |
| 1047 | bcopy(wl->ioctlbuf, buffer + offset, wl->ioc.len); |
| 1048 | wl->proc_state--; |
| 1049 | wl->ioctl_in_progress = 0; |
| 1050 | return wl->ioc.len + offset; |
| 1051 | |
| 1052 | case WL_PROC_HAVE_BUF: |
| 1053 | /* Give the processed IOC back to userland */ |
| 1054 | if (!wl->ioctl_in_progress) { |
| 1055 | WL_ERROR(("%s: No ioctl in progress nothing to read, 1\n", __func__)); |
| 1056 | return 0; |
| 1057 | } |
| 1058 | if (length != sizeof(wl_ioctl_t)) { |
| 1059 | WL_ERROR(("%s: Reading ioc but len != sizeof(wl_ioctl_t)\n", __func__)); |
| 1060 | return 0; |
| 1061 | } |
| 1062 | bcopy(&wl->ioc, buffer + offset, length); |
| 1063 | wl->proc_state--; |
| 1064 | return length + offset; |
| 1065 | |
| 1066 | default: |
| 1067 | WL_ERROR(("%s: Proc read out of sync. proc_state %d, ioctl_in_progress %d\n", __func__, wl->proc_state, wl->ioctl_in_progress)); |
| 1068 | } |
| 1069 | |
| 1070 | WL_ERROR(("%s: Invalid ioctl!!!\n", __func__)); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | /* OS Entry point when app attempts to write */ |
| 1075 | static int |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1076 | wl_proc_write(struct file *filp, const char __user *buff, unsigned long length, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1077 | void *data) |
| 1078 | { |
| 1079 | wl_info_t *wl = (wl_info_t *) data; |
| 1080 | int bcmerror; |
| 1081 | |
| 1082 | switch (wl->proc_state) { |
| 1083 | |
| 1084 | case WL_PROC_IDLE: |
| 1085 | if (wl->ioctl_in_progress) { |
| 1086 | WL_ERROR(("%s: ioctl still in progress\n", __func__)); |
| 1087 | return -EIO; |
| 1088 | } |
| 1089 | if (length != sizeof(wl_ioctl_t)) { |
| 1090 | WL_ERROR(("%s: Expecting ioctl sized buf\n", __func__)); |
| 1091 | return -EIO; |
| 1092 | } |
| 1093 | if (copy_from_user(&wl->ioc, buff, sizeof(wl_ioctl_t))) { |
| 1094 | WL_ERROR(("%s: copy from user failed\n", __func__)); |
| 1095 | return -EIO; |
| 1096 | } |
| 1097 | wl->proc_state++; |
| 1098 | wl->ioctl_in_progress++; |
| 1099 | return sizeof(wl_ioctl_t); |
| 1100 | |
| 1101 | case WL_PROC_HAVE_IOC: |
| 1102 | if (!wl->ioctl_in_progress) { |
| 1103 | WL_ERROR(("%s: Ioctl not ready yet 1\n", __func__)); |
| 1104 | return -EIO; |
| 1105 | } |
| 1106 | if (wl->ioctlbuf_sz < length) { |
| 1107 | WL_ERROR(("%s: Buf write, ioctl buf %d not big enough too hold buffer %d\n", __func__, (int)sizeof(wl->ioctlbuf), (int)length)); |
| 1108 | WL_ERROR(("Shortening input\n")); |
| 1109 | length = wl->ioctlbuf_sz; |
| 1110 | } |
| 1111 | if (length != wl->ioc.len) { |
| 1112 | WL_ERROR(("%s: ioc.len %d != length param %d\n", |
| 1113 | __func__, wl->ioc.len, (int)length)); |
| 1114 | return -EIO; |
| 1115 | } |
| 1116 | if (copy_from_user(wl->ioctlbuf, buff, length)) { |
| 1117 | WL_ERROR(("%s: copy from user of %d bytes failed\n", |
| 1118 | __func__, (int)length)); |
| 1119 | return -EIO; |
| 1120 | } |
| 1121 | wl->proc_state++; |
| 1122 | |
| 1123 | WL_LOCK(wl); |
| 1124 | bcmerror = |
| 1125 | wlc_ioctl(wl->wlc, wl->ioc.cmd, wl->ioctlbuf, wl->ioc.len, |
| 1126 | NULL); |
| 1127 | WL_UNLOCK(wl); |
| 1128 | |
| 1129 | if (bcmerror < 0) |
| 1130 | return bcmerror; |
| 1131 | |
| 1132 | return length; |
| 1133 | |
| 1134 | case WL_PROC_HAVE_BUF: |
| 1135 | WL_ERROR(("%s: Illegal write. Rejecting.\n", __func__)); |
| 1136 | return 0; |
| 1137 | default: |
| 1138 | WL_ERROR(("%s: Proc write out of sync. proc_state %d, ioctl_in_progress %d\n", __func__, wl->proc_state, wl->ioctl_in_progress)); |
| 1139 | } |
| 1140 | return 0; |
| 1141 | } |
| 1142 | |
| 1143 | #ifdef WLC_HIGH_ONLY |
| 1144 | static void *wl_dbus_probe_cb(void *arg, const char *desc, uint32 bustype, |
| 1145 | uint32 hdrlen) |
| 1146 | { |
| 1147 | wl_info_t *wl; |
| 1148 | WL_ERROR(("%s:\n", __func__)); |
| 1149 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 1150 | wl = wl_attach(BCM_DNGL_VID, BCM_DNGL_BDC_PID, (ulong) NULL, RPC_BUS, |
| 1151 | NULL, 0); |
| 1152 | if (!wl) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1153 | WL_ERROR(("%s: wl_attach failed\n", __func__)); |
| 1154 | } |
| 1155 | |
| 1156 | /* This is later passed to wl_dbus_disconnect_cb */ |
| 1157 | return wl; |
| 1158 | } |
| 1159 | |
| 1160 | static void wl_dbus_disconnect_cb(void *arg) |
| 1161 | { |
| 1162 | wl_info_t *wl = arg; |
| 1163 | |
| 1164 | WL_ERROR(("%s:\n", __func__)); |
| 1165 | |
| 1166 | if (wl) { |
| 1167 | #ifdef WLC_HIGH_ONLY |
| 1168 | if (wl->pub->ieee_hw) { |
| 1169 | ieee80211_unregister_hw(wl->pub->ieee_hw); |
| 1170 | WL_ERROR(("%s: Back from down\n", __func__)); |
| 1171 | } |
| 1172 | wlc_device_removed(wl->wlc); |
| 1173 | wlc_bmac_dngl_reboot(wl->rpc); |
| 1174 | bcm_rpc_down(wl->rpc); |
| 1175 | #endif |
| 1176 | WL_LOCK(wl); |
| 1177 | wl_down(wl); |
| 1178 | WL_UNLOCK(wl); |
| 1179 | #ifdef WLC_HIGH_ONLY |
| 1180 | if (wl->pub->ieee_hw) { |
| 1181 | ieee80211_free_hw(wl->pub->ieee_hw); |
| 1182 | WL_ERROR(("%s: Back from ieee80211_free_hw\n", |
| 1183 | __func__)); |
| 1184 | wl->pub->ieee_hw = NULL; |
| 1185 | } |
| 1186 | #endif |
| 1187 | wl_free(wl); |
| 1188 | } |
| 1189 | } |
| 1190 | #endif /* WLC_HIGH_ONLY */ |
| 1191 | |
| 1192 | #ifndef BCMSDIO |
| 1193 | static void __devexit wl_remove(struct pci_dev *pdev); |
| 1194 | #endif |
| 1195 | |
| 1196 | #define CHAN2GHZ(channel, freqency, chflags) { \ |
| 1197 | .band = IEEE80211_BAND_2GHZ, \ |
| 1198 | .center_freq = (freqency), \ |
| 1199 | .hw_value = (channel), \ |
| 1200 | .flags = chflags, \ |
| 1201 | .max_antenna_gain = 0, \ |
| 1202 | .max_power = 19, \ |
| 1203 | } |
| 1204 | |
| 1205 | static struct ieee80211_channel wl_2ghz_chantable[] = { |
| 1206 | CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS), |
| 1207 | CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS), |
| 1208 | CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS), |
| 1209 | CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS), |
| 1210 | CHAN2GHZ(5, 2432, 0), |
| 1211 | CHAN2GHZ(6, 2437, 0), |
| 1212 | CHAN2GHZ(7, 2442, 0), |
| 1213 | CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS), |
| 1214 | CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS), |
| 1215 | CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS), |
| 1216 | CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS), |
| 1217 | CHAN2GHZ(12, 2467, |
| 1218 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS | |
| 1219 | IEEE80211_CHAN_NO_HT40PLUS), |
| 1220 | CHAN2GHZ(13, 2472, |
| 1221 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS | |
| 1222 | IEEE80211_CHAN_NO_HT40PLUS), |
| 1223 | CHAN2GHZ(14, 2484, |
| 1224 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS | |
| 1225 | IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS) |
| 1226 | }; |
| 1227 | |
| 1228 | #define CHAN5GHZ(channel, chflags) { \ |
| 1229 | .band = IEEE80211_BAND_5GHZ, \ |
| 1230 | .center_freq = 5000 + 5*(channel), \ |
| 1231 | .hw_value = (channel), \ |
| 1232 | .flags = chflags, \ |
| 1233 | .max_antenna_gain = 0, \ |
| 1234 | .max_power = 21, \ |
| 1235 | } |
| 1236 | |
| 1237 | static struct ieee80211_channel wl_5ghz_nphy_chantable[] = { |
| 1238 | /* UNII-1 */ |
| 1239 | CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS), |
| 1240 | CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS), |
| 1241 | CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS), |
| 1242 | CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS), |
| 1243 | /* UNII-2 */ |
| 1244 | CHAN5GHZ(52, |
| 1245 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1246 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS), |
| 1247 | CHAN5GHZ(56, |
| 1248 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1249 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS), |
| 1250 | CHAN5GHZ(60, |
| 1251 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1252 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS), |
| 1253 | CHAN5GHZ(64, |
| 1254 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1255 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS), |
| 1256 | /* MID */ |
| 1257 | CHAN5GHZ(100, |
| 1258 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1259 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS), |
| 1260 | CHAN5GHZ(104, |
| 1261 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1262 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS), |
| 1263 | CHAN5GHZ(108, |
| 1264 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1265 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS), |
| 1266 | CHAN5GHZ(112, |
| 1267 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1268 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS), |
| 1269 | CHAN5GHZ(116, |
| 1270 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1271 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS), |
| 1272 | CHAN5GHZ(120, |
| 1273 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1274 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS), |
| 1275 | CHAN5GHZ(124, |
| 1276 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1277 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS), |
| 1278 | CHAN5GHZ(128, |
| 1279 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1280 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS), |
| 1281 | CHAN5GHZ(132, |
| 1282 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1283 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS), |
| 1284 | CHAN5GHZ(136, |
| 1285 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1286 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS), |
| 1287 | CHAN5GHZ(140, |
| 1288 | IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS | |
| 1289 | IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS | |
| 1290 | IEEE80211_CHAN_NO_HT40MINUS), |
| 1291 | /* UNII-3 */ |
| 1292 | CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS), |
| 1293 | CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS), |
| 1294 | CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS), |
| 1295 | CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS), |
| 1296 | CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS) |
| 1297 | }; |
| 1298 | |
| 1299 | #define RATE(rate100m, _flags) { \ |
| 1300 | .bitrate = (rate100m), \ |
| 1301 | .flags = (_flags), \ |
| 1302 | .hw_value = (rate100m / 5), \ |
| 1303 | } |
| 1304 | |
| 1305 | static struct ieee80211_rate wl_legacy_ratetable[] = { |
| 1306 | RATE(10, 0), |
| 1307 | RATE(20, IEEE80211_RATE_SHORT_PREAMBLE), |
| 1308 | RATE(55, IEEE80211_RATE_SHORT_PREAMBLE), |
| 1309 | RATE(110, IEEE80211_RATE_SHORT_PREAMBLE), |
| 1310 | RATE(60, 0), |
| 1311 | RATE(90, 0), |
| 1312 | RATE(120, 0), |
| 1313 | RATE(180, 0), |
| 1314 | RATE(240, 0), |
| 1315 | RATE(360, 0), |
| 1316 | RATE(480, 0), |
| 1317 | RATE(540, 0), |
| 1318 | }; |
| 1319 | |
| 1320 | static struct ieee80211_supported_band wl_band_2GHz_nphy = { |
| 1321 | .band = IEEE80211_BAND_2GHZ, |
| 1322 | .channels = wl_2ghz_chantable, |
| 1323 | .n_channels = ARRAY_SIZE(wl_2ghz_chantable), |
| 1324 | .bitrates = wl_legacy_ratetable, |
| 1325 | .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable), |
| 1326 | .ht_cap = { |
| 1327 | /* from include/linux/ieee80211.h */ |
| 1328 | .cap = IEEE80211_HT_CAP_GRN_FLD | |
| 1329 | IEEE80211_HT_CAP_SGI_20 | |
| 1330 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT, |
| 1331 | #ifdef WLC_HIGH_ONLY |
| 1332 | .ht_supported = true, |
| 1333 | .ampdu_factor = AMPDU_RX_FACTOR_16K, |
| 1334 | #else |
| 1335 | .ht_supported = true, |
| 1336 | .ampdu_factor = AMPDU_RX_FACTOR_64K, |
| 1337 | #endif |
| 1338 | .ampdu_density = AMPDU_DEF_MPDU_DENSITY, |
| 1339 | .mcs = { |
| 1340 | /* placeholders for now */ |
| 1341 | #ifdef WLC_HIGH_ONLY |
| 1342 | /* |
| 1343 | * rx_mask[0] = 0xff by default |
| 1344 | * rx_mask[1] = 0xff if number of rx chain >=2 |
| 1345 | * rx_mask[2] = 0xff if number of rx chain >=3 |
| 1346 | * rx_mask[4] = 1 if 40Mhz is supported |
| 1347 | */ |
| 1348 | .rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
| 1349 | .rx_highest = 72, /* max rate of single stream */ |
| 1350 | #else |
| 1351 | .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0}, |
| 1352 | .rx_highest = 500, |
| 1353 | #endif |
| 1354 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED} |
| 1355 | } |
| 1356 | }; |
| 1357 | |
| 1358 | static struct ieee80211_supported_band wl_band_5GHz_nphy = { |
| 1359 | .band = IEEE80211_BAND_5GHZ, |
| 1360 | .channels = wl_5ghz_nphy_chantable, |
| 1361 | .n_channels = ARRAY_SIZE(wl_5ghz_nphy_chantable), |
| 1362 | .bitrates = wl_legacy_ratetable + 4, |
| 1363 | .n_bitrates = ARRAY_SIZE(wl_legacy_ratetable) - 4, |
| 1364 | .ht_cap = { |
| 1365 | /* use IEEE80211_HT_CAP_* from include/linux/ieee80211.h */ |
| 1366 | .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT, /* No 40 mhz yet */ |
| 1367 | .ht_supported = true, |
| 1368 | .ampdu_factor = AMPDU_RX_FACTOR_64K, |
| 1369 | .ampdu_density = AMPDU_DEF_MPDU_DENSITY, |
| 1370 | .mcs = { |
| 1371 | /* placeholders for now */ |
| 1372 | .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0}, |
| 1373 | .rx_highest = 500, |
| 1374 | .tx_params = IEEE80211_HT_MCS_TX_DEFINED} |
| 1375 | } |
| 1376 | }; |
| 1377 | |
| 1378 | static int ieee_hw_rate_init(struct ieee80211_hw *hw) |
| 1379 | { |
| 1380 | wl_info_t *wl = HW_TO_WL(hw); |
| 1381 | int has_5g; |
| 1382 | char phy_list[4]; |
| 1383 | |
| 1384 | has_5g = 0; |
| 1385 | |
| 1386 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL; |
| 1387 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL; |
| 1388 | |
| 1389 | if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) { |
| 1390 | WL_ERROR(("Phy list failed\n")); |
| 1391 | } |
| 1392 | WL_NONE(("%s: phylist = %c\n", __func__, phy_list[0])); |
| 1393 | |
| 1394 | #ifndef WLC_HIGH_ONLY |
| 1395 | if (phy_list[0] == 'n' || phy_list[0] == 'c') { |
| 1396 | if (phy_list[0] == 'c') { |
| 1397 | /* Single stream */ |
| 1398 | wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0; |
| 1399 | wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72; |
| 1400 | } |
| 1401 | #else |
| 1402 | if (phy_list[0] == 's') { |
| 1403 | #endif |
| 1404 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy; |
| 1405 | } else { |
| 1406 | BUG(); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1407 | return -1; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | /* Assume all bands use the same phy. True for 11n devices. */ |
| 1411 | if (NBANDS_PUB(wl->pub) > 1) { |
| 1412 | has_5g++; |
| 1413 | #ifndef WLC_HIGH_ONLY |
| 1414 | if (phy_list[0] == 'n' || phy_list[0] == 'c') { |
| 1415 | #else |
| 1416 | if (phy_list[0] == 's') { |
| 1417 | #endif |
| 1418 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 1419 | &wl_band_5GHz_nphy; |
| 1420 | } else { |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1421 | return -1; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | WL_NONE(("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g)); |
| 1426 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1427 | return 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | static int ieee_hw_init(struct ieee80211_hw *hw) |
| 1431 | { |
| 1432 | hw->flags = IEEE80211_HW_SIGNAL_DBM |
| 1433 | /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */ |
| 1434 | | IEEE80211_HW_REPORTS_TX_ACK_STATUS |
| 1435 | | IEEE80211_HW_AMPDU_AGGREGATION; |
| 1436 | |
| 1437 | hw->extra_tx_headroom = wlc_get_header_len(); |
| 1438 | /* FIXME: should get this from wlc->machwcap */ |
| 1439 | hw->queues = 4; |
| 1440 | /* FIXME: this doesn't seem to be used properly in minstrel_ht. |
| 1441 | * mac80211/status.c:ieee80211_tx_status() checks this value, |
| 1442 | * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate() |
| 1443 | * appears to always set 3 rates |
| 1444 | */ |
| 1445 | hw->max_rates = 2; /* Primary rate and 1 fallback rate */ |
| 1446 | |
| 1447 | hw->channel_change_time = 7 * 1000; /* channel change time is dependant on chip and band */ |
| 1448 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); |
| 1449 | |
| 1450 | hw->rate_control_algorithm = "minstrel_ht"; |
| 1451 | |
| 1452 | hw->sta_data_size = sizeof(struct scb); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1453 | return ieee_hw_rate_init(hw); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | #ifndef BCMSDIO |
| 1457 | /** |
| 1458 | * determines if a device is a WL device, and if so, attaches it. |
| 1459 | * |
| 1460 | * This function determines if a device pointed to by pdev is a WL device, |
| 1461 | * and if so, performs a wl_attach() on it. |
| 1462 | * |
| 1463 | */ |
| 1464 | int __devinit |
| 1465 | wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 1466 | { |
| 1467 | int rc; |
| 1468 | wl_info_t *wl; |
| 1469 | struct ieee80211_hw *hw; |
| 1470 | uint32 val; |
| 1471 | |
| 1472 | ASSERT(pdev); |
| 1473 | |
| 1474 | WL_TRACE(("%s: bus %d slot %d func %d irq %d\n", __func__, |
| 1475 | pdev->bus->number, PCI_SLOT(pdev->devfn), |
| 1476 | PCI_FUNC(pdev->devfn), pdev->irq)); |
| 1477 | |
| 1478 | if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) || |
| 1479 | (((pdev->device & 0xff00) != 0x4300) && |
| 1480 | ((pdev->device & 0xff00) != 0x4700) && |
| 1481 | ((pdev->device < 43000) || (pdev->device > 43999)))) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1482 | return -ENODEV; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1483 | |
| 1484 | rc = pci_enable_device(pdev); |
| 1485 | if (rc) { |
| 1486 | WL_ERROR(("%s: Cannot enable device %d-%d_%d\n", __func__, |
| 1487 | pdev->bus->number, PCI_SLOT(pdev->devfn), |
| 1488 | PCI_FUNC(pdev->devfn))); |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1489 | return -ENODEV; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1490 | } |
| 1491 | pci_set_master(pdev); |
| 1492 | |
| 1493 | pci_read_config_dword(pdev, 0x40, &val); |
| 1494 | if ((val & 0x0000ff00) != 0) |
| 1495 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 1496 | |
| 1497 | hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops); |
| 1498 | if (!hw) { |
| 1499 | WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__)); |
| 1500 | rc = -ENOMEM; |
| 1501 | goto err_1; |
| 1502 | } |
| 1503 | |
| 1504 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 1505 | |
| 1506 | pci_set_drvdata(pdev, hw); |
| 1507 | |
| 1508 | bzero(hw->priv, sizeof(*wl)); |
| 1509 | |
| 1510 | wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0), |
| 1511 | PCI_BUS, pdev, pdev->irq); |
| 1512 | |
| 1513 | return 0; |
| 1514 | err_1: |
| 1515 | WL_ERROR(("%s: err_1: Major hoarkage\n", __func__)); |
| 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | #ifdef LINUXSTA_PS |
| 1520 | static int wl_suspend(struct pci_dev *pdev, DRV_SUSPEND_STATE_TYPE state) |
| 1521 | { |
| 1522 | wl_info_t *wl; |
| 1523 | struct ieee80211_hw *hw; |
| 1524 | |
| 1525 | WL_TRACE(("wl: wl_suspend\n")); |
| 1526 | |
| 1527 | hw = pci_get_drvdata(pdev); |
| 1528 | wl = HW_TO_WL(hw); |
| 1529 | if (!wl) { |
| 1530 | WL_ERROR(("wl: wl_suspend: pci_get_drvdata failed\n")); |
| 1531 | return -ENODEV; |
| 1532 | } |
| 1533 | |
| 1534 | WL_LOCK(wl); |
| 1535 | wl_down(wl); |
| 1536 | wl->pub->hw_up = FALSE; |
| 1537 | WL_UNLOCK(wl); |
| 1538 | PCI_SAVE_STATE(pdev, wl->pci_psstate); |
| 1539 | pci_disable_device(pdev); |
| 1540 | return pci_set_power_state(pdev, PCI_D3hot); |
| 1541 | } |
| 1542 | |
| 1543 | static int wl_resume(struct pci_dev *pdev) |
| 1544 | { |
| 1545 | wl_info_t *wl; |
| 1546 | struct ieee80211_hw *hw; |
| 1547 | int err = 0; |
| 1548 | uint32 val; |
| 1549 | |
| 1550 | WL_TRACE(("wl: wl_resume\n")); |
| 1551 | hw = pci_get_drvdata(pdev); |
| 1552 | wl = HW_TO_WL(hw); |
| 1553 | if (!wl) { |
| 1554 | WL_ERROR(("wl: wl_resume: pci_get_drvdata failed\n")); |
| 1555 | return -ENODEV; |
| 1556 | } |
| 1557 | |
| 1558 | err = pci_set_power_state(pdev, PCI_D0); |
| 1559 | if (err) |
| 1560 | return err; |
| 1561 | |
| 1562 | PCI_RESTORE_STATE(pdev, wl->pci_psstate); |
| 1563 | |
| 1564 | err = pci_enable_device(pdev); |
| 1565 | if (err) |
| 1566 | return err; |
| 1567 | |
| 1568 | pci_set_master(pdev); |
| 1569 | |
| 1570 | pci_read_config_dword(pdev, 0x40, &val); |
| 1571 | if ((val & 0x0000ff00) != 0) |
| 1572 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 1573 | |
| 1574 | WL_LOCK(wl); |
| 1575 | err = wl_up(wl); |
| 1576 | WL_UNLOCK(wl); |
| 1577 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1578 | return err; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1579 | } |
| 1580 | #endif /* LINUXSTA_PS */ |
| 1581 | |
| 1582 | static void __devexit wl_remove(struct pci_dev *pdev) |
| 1583 | { |
| 1584 | wl_info_t *wl; |
| 1585 | struct ieee80211_hw *hw; |
| 1586 | |
| 1587 | hw = pci_get_drvdata(pdev); |
| 1588 | wl = HW_TO_WL(hw); |
| 1589 | if (!wl) { |
| 1590 | WL_ERROR(("wl: wl_remove: pci_get_drvdata failed\n")); |
| 1591 | return; |
| 1592 | } |
| 1593 | if (!wlc_chipmatch(pdev->vendor, pdev->device)) { |
| 1594 | WL_ERROR(("wl: wl_remove: wlc_chipmatch failed\n")); |
| 1595 | return; |
| 1596 | } |
| 1597 | |
| 1598 | ieee80211_unregister_hw(hw); |
| 1599 | |
| 1600 | WL_LOCK(wl); |
| 1601 | wl_down(wl); |
| 1602 | WL_UNLOCK(wl); |
| 1603 | WL_NONE(("%s: Down\n", __func__)); |
| 1604 | |
| 1605 | pci_disable_device(pdev); |
| 1606 | |
| 1607 | wl_free(wl); |
| 1608 | |
| 1609 | pci_set_drvdata(pdev, NULL); |
| 1610 | ieee80211_free_hw(hw); |
| 1611 | } |
| 1612 | |
| 1613 | static struct pci_driver wl_pci_driver = { |
| 1614 | name: "brcm80211", |
| 1615 | probe:wl_pci_probe, |
| 1616 | #ifdef LINUXSTA_PS |
| 1617 | suspend:wl_suspend, |
| 1618 | resume:wl_resume, |
| 1619 | #endif /* LINUXSTA_PS */ |
| 1620 | remove:__devexit_p(wl_remove), |
| 1621 | id_table:wl_id_table, |
| 1622 | }; |
| 1623 | #endif /* !BCMSDIO */ |
| 1624 | |
| 1625 | /** |
| 1626 | * This is the main entry point for the WL driver. |
| 1627 | * |
| 1628 | * This function determines if a device pointed to by pdev is a WL device, |
| 1629 | * and if so, performs a wl_attach() on it. |
| 1630 | * |
| 1631 | */ |
| 1632 | static int __init wl_module_init(void) |
| 1633 | { |
| 1634 | int error = -ENODEV; |
| 1635 | |
| 1636 | #ifdef BCMDBG |
| 1637 | if (msglevel != 0xdeadbeef) |
| 1638 | wl_msg_level = msglevel; |
| 1639 | else { |
| 1640 | char *var = getvar(NULL, "wl_msglevel"); |
| 1641 | if (var) |
| 1642 | wl_msg_level = bcm_strtoul(var, NULL, 0); |
| 1643 | } |
| 1644 | #ifndef WLC_HIGH_ONLY |
| 1645 | { |
| 1646 | extern uint32 phyhal_msg_level; |
| 1647 | |
| 1648 | if (phymsglevel != 0xdeadbeef) |
| 1649 | phyhal_msg_level = phymsglevel; |
| 1650 | else { |
| 1651 | char *var = getvar(NULL, "phy_msglevel"); |
| 1652 | if (var) |
| 1653 | phyhal_msg_level = bcm_strtoul(var, NULL, 0); |
| 1654 | } |
| 1655 | } |
| 1656 | #endif /* WLC_HIGH_ONLY */ |
| 1657 | #endif /* BCMDBG */ |
| 1658 | |
| 1659 | #ifndef BCMSDIO |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 1660 | error = pci_module_init(&wl_pci_driver); |
| 1661 | if (!error) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1662 | return 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1663 | |
| 1664 | #endif /* !BCMSDIO */ |
| 1665 | |
| 1666 | #ifdef WLC_HIGH_ONLY |
| 1667 | /* BMAC_NOTE: define hardcode number, why NODEVICE is ok ? */ |
| 1668 | error = |
| 1669 | dbus_register(BCM_DNGL_VID, 0, wl_dbus_probe_cb, |
| 1670 | wl_dbus_disconnect_cb, NULL, NULL, NULL); |
| 1671 | if (error == DBUS_ERR_NODEVICE) { |
| 1672 | error = DBUS_OK; |
| 1673 | } |
| 1674 | #endif /* WLC_HIGH_ONLY */ |
| 1675 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1676 | return error; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | /** |
| 1680 | * This function unloads the WL driver from the system. |
| 1681 | * |
| 1682 | * This function unconditionally unloads the WL driver module from the |
| 1683 | * system. |
| 1684 | * |
| 1685 | */ |
| 1686 | static void __exit wl_module_exit(void) |
| 1687 | { |
| 1688 | #ifndef BCMSDIO |
| 1689 | pci_unregister_driver(&wl_pci_driver); |
| 1690 | #endif /* !BCMSDIO */ |
| 1691 | |
| 1692 | #ifdef WLC_HIGH_ONLY |
| 1693 | dbus_deregister(); |
| 1694 | #endif /* WLC_HIGH_ONLY */ |
| 1695 | } |
| 1696 | |
| 1697 | module_init(wl_module_init); |
| 1698 | module_exit(wl_module_exit); |
| 1699 | |
| 1700 | /** |
| 1701 | * This function frees the WL per-device resources. |
| 1702 | * |
| 1703 | * This function frees resources owned by the WL device pointed to |
| 1704 | * by the wl parameter. |
| 1705 | * |
| 1706 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1707 | void wl_free(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1708 | { |
| 1709 | wl_timer_t *t, *next; |
| 1710 | osl_t *osh; |
| 1711 | |
| 1712 | ASSERT(wl); |
| 1713 | #ifndef WLC_HIGH_ONLY |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1714 | /* free ucode data */ |
| 1715 | if (wl->fw.fw_cnt) |
| 1716 | wl_ucode_data_free(); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1717 | if (wl->irq) |
| 1718 | free_irq(wl->irq, wl); |
| 1719 | #endif |
| 1720 | |
| 1721 | /* kill dpc */ |
| 1722 | tasklet_kill(&wl->tasklet); |
| 1723 | |
| 1724 | if (wl->pub) { |
| 1725 | wlc_module_unregister(wl->pub, "linux", wl); |
| 1726 | } |
| 1727 | |
| 1728 | /* free common resources */ |
| 1729 | if (wl->wlc) { |
| 1730 | wlc_detach(wl->wlc); |
| 1731 | wl->wlc = NULL; |
| 1732 | wl->pub = NULL; |
| 1733 | } |
| 1734 | |
| 1735 | /* virtual interface deletion is deferred so we cannot spinwait */ |
| 1736 | |
| 1737 | /* wait for all pending callbacks to complete */ |
| 1738 | while (atomic_read(&wl->callbacks) > 0) |
| 1739 | schedule(); |
| 1740 | |
| 1741 | /* free timers */ |
| 1742 | for (t = wl->timers; t; t = next) { |
| 1743 | next = t->next; |
| 1744 | #ifdef BCMDBG |
| 1745 | if (t->name) |
| 1746 | MFREE(wl->osh, t->name, strlen(t->name) + 1); |
| 1747 | #endif |
| 1748 | MFREE(wl->osh, t, sizeof(wl_timer_t)); |
| 1749 | } |
| 1750 | |
| 1751 | if (wl->ioctlbuf_sz) { |
| 1752 | remove_proc_entry(PROC_ENTRY_NAME, NULL); |
| 1753 | vfree(wl->ioctlbuf); |
| 1754 | wl->ioctlbuf_sz = 0; |
| 1755 | } |
| 1756 | |
| 1757 | osh = wl->osh; |
| 1758 | |
| 1759 | /* |
| 1760 | * unregister_netdev() calls get_stats() which may read chip registers |
| 1761 | * so we cannot unmap the chip registers until after calling unregister_netdev() . |
| 1762 | */ |
| 1763 | if (wl->regsva && BUSTYPE(wl->bcm_bustype) != SDIO_BUS && |
| 1764 | BUSTYPE(wl->bcm_bustype) != JTAG_BUS) { |
| 1765 | iounmap((void *)wl->regsva); |
| 1766 | } |
| 1767 | wl->regsva = NULL; |
| 1768 | |
| 1769 | #ifdef WLC_HIGH_ONLY |
| 1770 | wl_rpcq_free(wl); |
| 1771 | |
| 1772 | wl_txq_free(wl); |
| 1773 | |
| 1774 | if (wl->rpc) { |
| 1775 | bcm_rpc_detach(wl->rpc); |
| 1776 | wl->rpc = NULL; |
| 1777 | } |
| 1778 | |
| 1779 | if (wl->rpc_th) { |
| 1780 | bcm_rpc_tp_detach(wl->rpc_th); |
| 1781 | wl->rpc_th = NULL; |
| 1782 | } |
| 1783 | #endif /* WLC_HIGH_ONLY */ |
| 1784 | |
| 1785 | if (osl_malloced(osh)) { |
| 1786 | printf("**** Memory leak of bytes %d\n", osl_malloced(osh)); |
| 1787 | ASSERT(0 && "Memory Leak"); |
| 1788 | } |
| 1789 | |
| 1790 | osl_detach(osh); |
| 1791 | } |
| 1792 | |
| 1793 | #ifdef WLC_LOW |
| 1794 | /* transmit a packet */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1795 | static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1796 | { |
| 1797 | if (!wl) |
| 1798 | return -ENETDOWN; |
| 1799 | |
| 1800 | return wl_start_int(wl, WL_TO_HW(wl), skb); |
| 1801 | } |
| 1802 | #endif /* WLC_LOW */ |
| 1803 | |
| 1804 | static int BCMFASTPATH |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1805 | wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw, struct sk_buff *skb) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1806 | { |
| 1807 | #ifdef WLC_HIGH_ONLY |
| 1808 | WL_LOCK(wl); |
| 1809 | #endif |
| 1810 | wlc_sendpkt_mac80211(wl->wlc, skb, hw); |
| 1811 | #ifdef WLC_HIGH_ONLY |
| 1812 | WL_UNLOCK(wl); |
| 1813 | #endif |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1814 | return NETDEV_TX_OK; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1817 | void wl_txflowcontrol(wl_info_t *wl, struct wl_if *wlif, bool state, int prio) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1818 | { |
| 1819 | WL_ERROR(("Shouldn't be here %s\n", __func__)); |
| 1820 | } |
| 1821 | |
| 1822 | #if defined(WLC_HIGH_ONLY) |
| 1823 | /* Schedule a completion handler to run at safe time */ |
| 1824 | static int |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1825 | wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *task), |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1826 | void *context) |
| 1827 | { |
| 1828 | wl_task_t *task; |
| 1829 | |
| 1830 | WL_TRACE(("wl%d: wl_schedule_task\n", wl->pub->unit)); |
| 1831 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 1832 | task = osl_malloc(wl->osh, sizeof(wl_task_t)); |
| 1833 | if (!task) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1834 | WL_ERROR(("wl%d: wl_schedule_task: out of memory, malloced %d bytes\n", wl->pub->unit, osl_malloced(wl->osh))); |
| 1835 | return -ENOMEM; |
| 1836 | } |
| 1837 | |
| 1838 | MY_INIT_WORK(&task->work, (work_func_t) fn); |
| 1839 | task->context = context; |
| 1840 | |
| 1841 | if (!schedule_work(&task->work)) { |
| 1842 | WL_ERROR(("wl%d: schedule_work() failed\n", wl->pub->unit)); |
| 1843 | MFREE(wl->osh, task, sizeof(wl_task_t)); |
| 1844 | return -ENOMEM; |
| 1845 | } |
| 1846 | |
| 1847 | atomic_inc(&wl->callbacks); |
| 1848 | |
| 1849 | return 0; |
| 1850 | } |
| 1851 | #endif /* defined(WLC_HIGH_ONLY) */ |
| 1852 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1853 | void wl_init(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1854 | { |
| 1855 | WL_TRACE(("wl%d: wl_init\n", wl->pub->unit)); |
| 1856 | |
| 1857 | wl_reset(wl); |
| 1858 | |
| 1859 | wlc_init(wl->wlc); |
| 1860 | } |
| 1861 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1862 | uint wl_reset(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1863 | { |
| 1864 | WL_TRACE(("wl%d: wl_reset\n", wl->pub->unit)); |
| 1865 | |
| 1866 | wlc_reset(wl->wlc); |
| 1867 | |
| 1868 | /* dpc will not be rescheduled */ |
| 1869 | wl->resched = 0; |
| 1870 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1871 | return 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | /* |
| 1875 | * These are interrupt on/off entry points. Disable interrupts |
| 1876 | * during interrupt state transition. |
| 1877 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1878 | void BCMFASTPATH wl_intrson(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1879 | { |
| 1880 | #if defined(WLC_LOW) |
| 1881 | unsigned long flags; |
| 1882 | |
| 1883 | INT_LOCK(wl, flags); |
| 1884 | wlc_intrson(wl->wlc); |
| 1885 | INT_UNLOCK(wl, flags); |
| 1886 | #endif /* WLC_LOW */ |
| 1887 | } |
| 1888 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1889 | bool wl_alloc_dma_resources(wl_info_t *wl, uint addrwidth) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1890 | { |
| 1891 | return TRUE; |
| 1892 | } |
| 1893 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1894 | uint32 BCMFASTPATH wl_intrsoff(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1895 | { |
| 1896 | #if defined(WLC_LOW) |
| 1897 | unsigned long flags; |
| 1898 | uint32 status; |
| 1899 | |
| 1900 | INT_LOCK(wl, flags); |
| 1901 | status = wlc_intrsoff(wl->wlc); |
| 1902 | INT_UNLOCK(wl, flags); |
| 1903 | return status; |
| 1904 | #else |
| 1905 | return 0; |
| 1906 | #endif /* WLC_LOW */ |
| 1907 | } |
| 1908 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1909 | void wl_intrsrestore(wl_info_t *wl, uint32 macintmask) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1910 | { |
| 1911 | #if defined(WLC_LOW) |
| 1912 | unsigned long flags; |
| 1913 | |
| 1914 | INT_LOCK(wl, flags); |
| 1915 | wlc_intrsrestore(wl->wlc, macintmask); |
| 1916 | INT_UNLOCK(wl, flags); |
| 1917 | #endif /* WLC_LOW */ |
| 1918 | } |
| 1919 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1920 | int wl_up(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1921 | { |
| 1922 | int error = 0; |
| 1923 | |
| 1924 | if (wl->pub->up) |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1925 | return 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1926 | |
| 1927 | error = wlc_up(wl->wlc); |
| 1928 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 1929 | return error; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 1932 | void wl_down(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1933 | { |
| 1934 | uint callbacks, ret_val = 0; |
| 1935 | |
| 1936 | /* call common down function */ |
| 1937 | ret_val = wlc_down(wl->wlc); |
| 1938 | callbacks = atomic_read(&wl->callbacks) - ret_val; |
| 1939 | |
| 1940 | /* wait for down callbacks to complete */ |
| 1941 | WL_UNLOCK(wl); |
| 1942 | |
| 1943 | #ifndef WLC_HIGH_ONLY |
| 1944 | /* For HIGH_only driver, it's important to actually schedule other work, |
| 1945 | * not just spin wait since everything runs at schedule level |
| 1946 | */ |
| 1947 | SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000); |
| 1948 | #endif /* WLC_HIGH_ONLY */ |
| 1949 | |
| 1950 | WL_LOCK(wl); |
| 1951 | } |
| 1952 | |
| 1953 | irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id) |
| 1954 | { |
| 1955 | #if defined(WLC_LOW) |
| 1956 | wl_info_t *wl; |
| 1957 | bool ours, wantdpc; |
| 1958 | unsigned long flags; |
| 1959 | |
| 1960 | wl = (wl_info_t *) dev_id; |
| 1961 | |
| 1962 | WL_ISRLOCK(wl, flags); |
| 1963 | |
| 1964 | /* call common first level interrupt handler */ |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 1965 | ours = wlc_isr(wl->wlc, &wantdpc); |
| 1966 | if (ours) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 1967 | /* if more to do... */ |
| 1968 | if (wantdpc) { |
| 1969 | |
| 1970 | /* ...and call the second level interrupt handler */ |
| 1971 | /* schedule dpc */ |
| 1972 | ASSERT(wl->resched == FALSE); |
| 1973 | tasklet_schedule(&wl->tasklet); |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | WL_ISRUNLOCK(wl, flags); |
| 1978 | |
| 1979 | return IRQ_RETVAL(ours); |
| 1980 | #else |
| 1981 | return IRQ_RETVAL(0); |
| 1982 | #endif /* WLC_LOW */ |
| 1983 | } |
| 1984 | |
| 1985 | static void BCMFASTPATH wl_dpc(ulong data) |
| 1986 | { |
| 1987 | #ifdef WLC_LOW |
| 1988 | wl_info_t *wl; |
| 1989 | |
| 1990 | wl = (wl_info_t *) data; |
| 1991 | |
| 1992 | WL_LOCK(wl); |
| 1993 | |
| 1994 | /* call the common second level interrupt handler */ |
| 1995 | if (wl->pub->up) { |
| 1996 | if (wl->resched) { |
| 1997 | unsigned long flags; |
| 1998 | |
| 1999 | INT_LOCK(wl, flags); |
| 2000 | wlc_intrsupd(wl->wlc); |
| 2001 | INT_UNLOCK(wl, flags); |
| 2002 | } |
| 2003 | |
| 2004 | wl->resched = wlc_dpc(wl->wlc, TRUE); |
| 2005 | } |
| 2006 | |
| 2007 | /* wlc_dpc() may bring the driver down */ |
| 2008 | if (!wl->pub->up) |
| 2009 | goto done; |
| 2010 | |
| 2011 | /* re-schedule dpc */ |
| 2012 | if (wl->resched) |
| 2013 | tasklet_schedule(&wl->tasklet); |
| 2014 | else { |
| 2015 | /* re-enable interrupts */ |
| 2016 | wl_intrson(wl); |
| 2017 | } |
| 2018 | |
| 2019 | done: |
| 2020 | WL_UNLOCK(wl); |
| 2021 | #endif /* WLC_LOW */ |
| 2022 | } |
| 2023 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2024 | static void wl_link_up(wl_info_t *wl, char *ifname) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2025 | { |
| 2026 | WL_ERROR(("wl%d: link up (%s)\n", wl->pub->unit, ifname)); |
| 2027 | } |
| 2028 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2029 | static void wl_link_down(wl_info_t *wl, char *ifname) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2030 | { |
| 2031 | WL_ERROR(("wl%d: link down (%s)\n", wl->pub->unit, ifname)); |
| 2032 | } |
| 2033 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2034 | void wl_event(wl_info_t *wl, char *ifname, wlc_event_t *e) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2035 | { |
| 2036 | |
| 2037 | switch (e->event.event_type) { |
| 2038 | case WLC_E_LINK: |
| 2039 | case WLC_E_NDIS_LINK: |
| 2040 | if (e->event.flags & WLC_EVENT_MSG_LINK) |
| 2041 | wl_link_up(wl, ifname); |
| 2042 | else |
| 2043 | wl_link_down(wl, ifname); |
| 2044 | break; |
| 2045 | case WLC_E_RADIO: |
| 2046 | break; |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | static void wl_timer(ulong data) |
| 2051 | { |
| 2052 | #ifndef WLC_HIGH_ONLY |
| 2053 | _wl_timer((wl_timer_t *) data); |
| 2054 | #else |
| 2055 | wl_timer_t *t = (wl_timer_t *) data; |
| 2056 | wl_schedule_task(t->wl, wl_timer_task, t); |
| 2057 | #endif /* WLC_HIGH_ONLY */ |
| 2058 | } |
| 2059 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2060 | static void _wl_timer(wl_timer_t *t) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2061 | { |
| 2062 | WL_LOCK(t->wl); |
| 2063 | |
| 2064 | if (t->set) { |
| 2065 | if (t->periodic) { |
| 2066 | t->timer.expires = jiffies + t->ms * HZ / 1000; |
| 2067 | atomic_inc(&t->wl->callbacks); |
| 2068 | add_timer(&t->timer); |
| 2069 | t->set = TRUE; |
| 2070 | } else |
| 2071 | t->set = FALSE; |
| 2072 | |
| 2073 | t->fn(t->arg); |
| 2074 | } |
| 2075 | |
| 2076 | atomic_dec(&t->wl->callbacks); |
| 2077 | |
| 2078 | WL_UNLOCK(t->wl); |
| 2079 | } |
| 2080 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2081 | wl_timer_t *wl_init_timer(wl_info_t *wl, void (*fn) (void *arg), void *arg, |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2082 | const char *name) |
| 2083 | { |
| 2084 | wl_timer_t *t; |
| 2085 | |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 2086 | t = osl_malloc(wl->osh, sizeof(wl_timer_t)); |
| 2087 | if (!t) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2088 | WL_ERROR(("wl%d: wl_init_timer: out of memory, malloced %d bytes\n", wl->pub->unit, osl_malloced(wl->osh))); |
| 2089 | return 0; |
| 2090 | } |
| 2091 | |
| 2092 | bzero(t, sizeof(wl_timer_t)); |
| 2093 | |
| 2094 | init_timer(&t->timer); |
| 2095 | t->timer.data = (ulong) t; |
| 2096 | t->timer.function = wl_timer; |
| 2097 | t->wl = wl; |
| 2098 | t->fn = fn; |
| 2099 | t->arg = arg; |
| 2100 | t->next = wl->timers; |
| 2101 | wl->timers = t; |
| 2102 | |
| 2103 | #ifdef BCMDBG |
Jason Cooper | ca8c1e5 | 2010-09-14 09:45:33 -0400 | [diff] [blame^] | 2104 | t->name = osl_malloc(wl->osh, strlen(name) + 1); |
| 2105 | if (t->name) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2106 | strcpy(t->name, name); |
| 2107 | #endif |
| 2108 | |
| 2109 | return t; |
| 2110 | } |
| 2111 | |
| 2112 | /* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate |
| 2113 | * as well as it's easier to make it periodic |
| 2114 | */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2115 | void wl_add_timer(wl_info_t *wl, wl_timer_t *t, uint ms, int periodic) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2116 | { |
| 2117 | #ifdef BCMDBG |
| 2118 | if (t->set) { |
| 2119 | WL_ERROR(("%s: Already set. Name: %s, per %d\n", |
| 2120 | __func__, t->name, periodic)); |
| 2121 | } |
| 2122 | #endif |
| 2123 | ASSERT(!t->set); |
| 2124 | |
| 2125 | t->ms = ms; |
| 2126 | t->periodic = (bool) periodic; |
| 2127 | t->set = TRUE; |
| 2128 | t->timer.expires = jiffies + ms * HZ / 1000; |
| 2129 | |
| 2130 | atomic_inc(&wl->callbacks); |
| 2131 | add_timer(&t->timer); |
| 2132 | } |
| 2133 | |
| 2134 | /* return TRUE if timer successfully deleted, FALSE if still pending */ |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2135 | bool wl_del_timer(wl_info_t *wl, wl_timer_t *t) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2136 | { |
| 2137 | if (t->set) { |
| 2138 | t->set = FALSE; |
| 2139 | if (!del_timer(&t->timer)) { |
| 2140 | return FALSE; |
| 2141 | } |
| 2142 | atomic_dec(&wl->callbacks); |
| 2143 | } |
| 2144 | |
| 2145 | return TRUE; |
| 2146 | } |
| 2147 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2148 | void wl_free_timer(wl_info_t *wl, wl_timer_t *t) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2149 | { |
| 2150 | wl_timer_t *tmp; |
| 2151 | |
| 2152 | /* delete the timer in case it is active */ |
| 2153 | wl_del_timer(wl, t); |
| 2154 | |
| 2155 | if (wl->timers == t) { |
| 2156 | wl->timers = wl->timers->next; |
| 2157 | #ifdef BCMDBG |
| 2158 | if (t->name) |
| 2159 | MFREE(wl->osh, t->name, strlen(t->name) + 1); |
| 2160 | #endif |
| 2161 | MFREE(wl->osh, t, sizeof(wl_timer_t)); |
| 2162 | return; |
| 2163 | |
| 2164 | } |
| 2165 | |
| 2166 | tmp = wl->timers; |
| 2167 | while (tmp) { |
| 2168 | if (tmp->next == t) { |
| 2169 | tmp->next = t->next; |
| 2170 | #ifdef BCMDBG |
| 2171 | if (t->name) |
| 2172 | MFREE(wl->osh, t->name, strlen(t->name) + 1); |
| 2173 | #endif |
| 2174 | MFREE(wl->osh, t, sizeof(wl_timer_t)); |
| 2175 | return; |
| 2176 | } |
| 2177 | tmp = tmp->next; |
| 2178 | } |
| 2179 | |
| 2180 | } |
| 2181 | |
| 2182 | static int wl_linux_watchdog(void *ctx) |
| 2183 | { |
| 2184 | wl_info_t *wl = (wl_info_t *) ctx; |
| 2185 | struct net_device_stats *stats = NULL; |
| 2186 | uint id; |
| 2187 | /* refresh stats */ |
| 2188 | if (wl->pub->up) { |
| 2189 | ASSERT(wl->stats_id < 2); |
| 2190 | |
| 2191 | id = 1 - wl->stats_id; |
| 2192 | |
| 2193 | stats = &wl->stats_watchdog[id]; |
| 2194 | stats->rx_packets = WLCNTVAL(wl->pub->_cnt->rxframe); |
| 2195 | stats->tx_packets = WLCNTVAL(wl->pub->_cnt->txframe); |
| 2196 | stats->rx_bytes = WLCNTVAL(wl->pub->_cnt->rxbyte); |
| 2197 | stats->tx_bytes = WLCNTVAL(wl->pub->_cnt->txbyte); |
| 2198 | stats->rx_errors = WLCNTVAL(wl->pub->_cnt->rxerror); |
| 2199 | stats->tx_errors = WLCNTVAL(wl->pub->_cnt->txerror); |
| 2200 | stats->collisions = 0; |
| 2201 | |
| 2202 | stats->rx_length_errors = 0; |
| 2203 | stats->rx_over_errors = WLCNTVAL(wl->pub->_cnt->rxoflo); |
| 2204 | stats->rx_crc_errors = WLCNTVAL(wl->pub->_cnt->rxcrc); |
| 2205 | stats->rx_frame_errors = 0; |
| 2206 | stats->rx_fifo_errors = WLCNTVAL(wl->pub->_cnt->rxoflo); |
| 2207 | stats->rx_missed_errors = 0; |
| 2208 | |
| 2209 | stats->tx_fifo_errors = WLCNTVAL(wl->pub->_cnt->txuflo); |
| 2210 | |
| 2211 | wl->stats_id = id; |
| 2212 | |
| 2213 | } |
| 2214 | |
| 2215 | return 0; |
| 2216 | } |
| 2217 | |
| 2218 | struct wl_fw_hdr { |
| 2219 | uint32 offset; |
| 2220 | uint32 len; |
| 2221 | uint32 idx; |
| 2222 | }; |
| 2223 | |
| 2224 | #ifdef WLC_HIGH_ONLY |
| 2225 | static void wl_rpc_down(void *wlh) |
| 2226 | { |
| 2227 | wl_info_t *wl = (wl_info_t *) (wlh); |
| 2228 | |
| 2229 | wlc_device_removed(wl->wlc); |
| 2230 | |
| 2231 | wl_rpcq_free(wl); |
| 2232 | } |
| 2233 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2234 | static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2235 | { |
| 2236 | |
| 2237 | ulong flags; |
| 2238 | |
| 2239 | skb->prev = NULL; |
| 2240 | |
| 2241 | /* Lock the queue as tasklet could be running at this time */ |
| 2242 | TXQ_LOCK(wl, flags); |
| 2243 | if (wl->txq_head == NULL) |
| 2244 | wl->txq_head = skb; |
| 2245 | else { |
| 2246 | wl->txq_tail->prev = skb; |
| 2247 | } |
| 2248 | wl->txq_tail = skb; |
| 2249 | |
| 2250 | if (wl->txq_dispatched == FALSE) { |
| 2251 | wl->txq_dispatched = TRUE; |
| 2252 | |
| 2253 | if (schedule_work(&wl->txq_task.work)) { |
| 2254 | atomic_inc(&wl->callbacks); |
| 2255 | } else { |
| 2256 | WL_ERROR(("wl%d: wl_start/schedule_work failed\n", |
| 2257 | wl->pub->unit)); |
| 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | TXQ_UNLOCK(wl, flags); |
| 2262 | |
Jason Cooper | 90ea229 | 2010-09-14 09:45:32 -0400 | [diff] [blame] | 2263 | return 0; |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2264 | |
| 2265 | } |
| 2266 | |
| 2267 | static void wl_start_txqwork(struct wl_task *task) |
| 2268 | { |
| 2269 | wl_info_t *wl = (wl_info_t *) task->context; |
| 2270 | struct sk_buff *skb; |
| 2271 | ulong flags; |
| 2272 | uint count = 0; |
| 2273 | |
| 2274 | WL_TRACE(("wl%d: wl_start_txqwork\n", wl->pub->unit)); |
| 2275 | |
| 2276 | /* First remove an entry then go for execution */ |
| 2277 | TXQ_LOCK(wl, flags); |
| 2278 | while (wl->txq_head) { |
| 2279 | skb = wl->txq_head; |
| 2280 | wl->txq_head = skb->prev; |
| 2281 | skb->prev = NULL; |
| 2282 | if (wl->txq_head == NULL) |
| 2283 | wl->txq_tail = NULL; |
| 2284 | TXQ_UNLOCK(wl, flags); |
| 2285 | |
| 2286 | /* it has WL_LOCK/WL_UNLOCK inside */ |
| 2287 | wl_start_int(wl, WL_TO_HW(wl), skb); |
| 2288 | |
| 2289 | /* bounded our execution, reshedule ourself next */ |
| 2290 | if (++count >= 10) |
| 2291 | break; |
| 2292 | |
| 2293 | TXQ_LOCK(wl, flags); |
| 2294 | } |
| 2295 | |
| 2296 | if (count >= 10) { |
| 2297 | if (!schedule_work(&wl->txq_task.work)) { |
| 2298 | WL_ERROR(("wl%d: wl_start/schedule_work failed\n", |
| 2299 | wl->pub->unit)); |
| 2300 | atomic_dec(&wl->callbacks); |
| 2301 | } |
| 2302 | } else { |
| 2303 | wl->txq_dispatched = FALSE; |
| 2304 | TXQ_UNLOCK(wl, flags); |
| 2305 | atomic_dec(&wl->callbacks); |
| 2306 | } |
| 2307 | |
| 2308 | return; |
| 2309 | } |
| 2310 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2311 | static void wl_txq_free(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2312 | { |
| 2313 | struct sk_buff *skb; |
| 2314 | |
| 2315 | if (wl->txq_head == NULL) { |
| 2316 | ASSERT(wl->txq_tail == NULL); |
| 2317 | return; |
| 2318 | } |
| 2319 | |
| 2320 | while (wl->txq_head) { |
| 2321 | skb = wl->txq_head; |
| 2322 | wl->txq_head = skb->prev; |
| 2323 | PKTFREE(wl->osh, skb, TRUE); |
| 2324 | } |
| 2325 | |
| 2326 | wl->txq_tail = NULL; |
| 2327 | } |
| 2328 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2329 | static void wl_rpcq_free(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2330 | { |
| 2331 | rpc_buf_t *buf; |
| 2332 | |
| 2333 | if (wl->rpcq_head == NULL) { |
| 2334 | ASSERT(wl->rpcq_tail == NULL); |
| 2335 | return; |
| 2336 | } |
| 2337 | |
| 2338 | while (wl->rpcq_head) { |
| 2339 | buf = wl->rpcq_head; |
| 2340 | wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf); |
| 2341 | bcm_rpc_buf_free(wl->rpc_dispatch_ctx.rpc, buf); |
| 2342 | } |
| 2343 | |
| 2344 | wl->rpcq_tail = NULL; |
| 2345 | } |
| 2346 | |
| 2347 | static void wl_rpcq_dispatch(struct wl_task *task) |
| 2348 | { |
| 2349 | wl_info_t *wl = (wl_info_t *) task->context; |
| 2350 | rpc_buf_t *buf; |
| 2351 | ulong flags; |
| 2352 | |
| 2353 | /* First remove an entry then go for execution */ |
| 2354 | RPCQ_LOCK(wl, flags); |
| 2355 | while (wl->rpcq_head) { |
| 2356 | buf = wl->rpcq_head; |
| 2357 | wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf); |
| 2358 | |
| 2359 | if (wl->rpcq_head == NULL) |
| 2360 | wl->rpcq_tail = NULL; |
| 2361 | RPCQ_UNLOCK(wl, flags); |
| 2362 | |
| 2363 | WL_LOCK(wl); |
| 2364 | wlc_rpc_high_dispatch(&wl->rpc_dispatch_ctx, buf); |
| 2365 | WL_UNLOCK(wl); |
| 2366 | |
| 2367 | RPCQ_LOCK(wl, flags); |
| 2368 | } |
| 2369 | |
| 2370 | wl->rpcq_dispatched = FALSE; |
| 2371 | |
| 2372 | RPCQ_UNLOCK(wl, flags); |
| 2373 | |
| 2374 | MFREE(wl->osh, task, sizeof(wl_task_t)); |
| 2375 | atomic_dec(&wl->callbacks); |
| 2376 | } |
| 2377 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2378 | static void wl_rpcq_add(wl_info_t *wl, rpc_buf_t *buf) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2379 | { |
| 2380 | ulong flags; |
| 2381 | |
| 2382 | bcm_rpc_buf_next_set(wl->rpc_th, buf, NULL); |
| 2383 | |
| 2384 | /* Lock the queue as tasklet could be running at this time */ |
| 2385 | RPCQ_LOCK(wl, flags); |
| 2386 | if (wl->rpcq_head == NULL) |
| 2387 | wl->rpcq_head = buf; |
| 2388 | else |
| 2389 | bcm_rpc_buf_next_set(wl->rpc_th, wl->rpcq_tail, buf); |
| 2390 | |
| 2391 | wl->rpcq_tail = buf; |
| 2392 | |
| 2393 | if (wl->rpcq_dispatched == FALSE) { |
| 2394 | wl->rpcq_dispatched = TRUE; |
| 2395 | wl_schedule_task(wl, wl_rpcq_dispatch, wl); |
| 2396 | } |
| 2397 | |
| 2398 | RPCQ_UNLOCK(wl, flags); |
| 2399 | } |
| 2400 | |
| 2401 | #if defined(BCMDBG) |
| 2402 | static const struct name_entry rpc_name_tbl[] = RPC_ID_TABLE; |
| 2403 | #endif /* BCMDBG */ |
| 2404 | |
| 2405 | /* dongle-side rpc dispatch routine */ |
| 2406 | static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf) |
| 2407 | { |
| 2408 | bcm_xdr_buf_t b; |
| 2409 | wl_info_t *wl = (wl_info_t *) ctx; |
| 2410 | wlc_rpc_id_t rpc_id; |
| 2411 | int err; |
| 2412 | |
| 2413 | bcm_xdr_buf_init(&b, bcm_rpc_buf_data(wl->rpc_th, buf), |
| 2414 | bcm_rpc_buf_len_get(wl->rpc_th, buf)); |
| 2415 | |
| 2416 | err = bcm_xdr_unpack_uint32(&b, &rpc_id); |
| 2417 | ASSERT(!err); |
| 2418 | WL_TRACE(("%s: Dispatch id %s\n", __func__, |
| 2419 | WLC_RPC_ID_LOOKUP(rpc_name_tbl, rpc_id))); |
| 2420 | |
| 2421 | /* Handle few emergency ones */ |
| 2422 | switch (rpc_id) { |
| 2423 | default: |
| 2424 | wl_rpcq_add(wl, buf); |
| 2425 | break; |
| 2426 | } |
| 2427 | } |
| 2428 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2429 | static void wl_timer_task(wl_task_t *task) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2430 | { |
| 2431 | wl_timer_t *t = (wl_timer_t *) task->context; |
| 2432 | |
| 2433 | _wl_timer(t); |
| 2434 | MFREE(t->wl->osh, task, sizeof(wl_task_t)); |
| 2435 | |
| 2436 | /* This dec is for the task_schedule. The timer related |
| 2437 | * callback is decremented in _wl_timer |
| 2438 | */ |
| 2439 | atomic_dec(&t->wl->callbacks); |
| 2440 | } |
| 2441 | #endif /* WLC_HIGH_ONLY */ |
| 2442 | |
| 2443 | #ifndef WLC_HIGH_ONLY |
| 2444 | char *wl_firmwares[WL_MAX_FW] = { |
| 2445 | "brcm/bcm43xx", |
| 2446 | NULL |
| 2447 | }; |
| 2448 | |
| 2449 | #ifdef WLC_LOW |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2450 | int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, uint32 idx) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2451 | { |
| 2452 | int i, entry; |
| 2453 | const uint8 *pdata; |
| 2454 | struct wl_fw_hdr *hdr; |
| 2455 | for (i = 0; i < wl->fw.fw_cnt; i++) { |
| 2456 | hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data; |
| 2457 | for (entry = 0; entry < wl->fw.hdr_num_entries[i]; |
| 2458 | entry++, hdr++) { |
| 2459 | if (hdr->idx == idx) { |
| 2460 | pdata = wl->fw.fw_bin[i]->data + hdr->offset; |
| 2461 | *pbuf = kmalloc(hdr->len, GFP_ATOMIC); |
| 2462 | if (*pbuf == NULL) { |
| 2463 | printf("fail to alloc %d bytes\n", |
| 2464 | hdr->len); |
| 2465 | } |
| 2466 | bcopy(pdata, *pbuf, hdr->len); |
| 2467 | return 0; |
| 2468 | } |
| 2469 | } |
| 2470 | } |
| 2471 | printf("ERROR: ucode buf tag:%d can not be found!\n", idx); |
| 2472 | *pbuf = NULL; |
| 2473 | return -1; |
| 2474 | } |
| 2475 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2476 | int wl_ucode_init_uint(wl_info_t *wl, uint32 *data, uint32 idx) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2477 | { |
| 2478 | int i, entry; |
| 2479 | const uint8 *pdata; |
| 2480 | struct wl_fw_hdr *hdr; |
| 2481 | for (i = 0; i < wl->fw.fw_cnt; i++) { |
| 2482 | hdr = (struct wl_fw_hdr *)wl->fw.fw_hdr[i]->data; |
| 2483 | for (entry = 0; entry < wl->fw.hdr_num_entries[i]; |
| 2484 | entry++, hdr++) { |
| 2485 | if (hdr->idx == idx) { |
| 2486 | pdata = wl->fw.fw_bin[i]->data + hdr->offset; |
| 2487 | ASSERT(hdr->len == 4); |
| 2488 | *data = *((uint32 *) pdata); |
| 2489 | return 0; |
| 2490 | } |
| 2491 | } |
| 2492 | } |
| 2493 | printf("ERROR: ucode tag:%d can not be found!\n", idx); |
| 2494 | return -1; |
| 2495 | } |
| 2496 | #endif /* WLC_LOW */ |
| 2497 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2498 | static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2499 | { |
| 2500 | int status; |
| 2501 | struct device *device = &pdev->dev; |
| 2502 | char fw_name[100]; |
| 2503 | int i; |
| 2504 | |
| 2505 | bzero((void *)&wl->fw, sizeof(struct wl_firmware)); |
| 2506 | for (i = 0; i < WL_MAX_FW; i++) { |
| 2507 | if (wl_firmwares[i] == NULL) |
| 2508 | break; |
| 2509 | sprintf(fw_name, "%s-%d.fw", wl_firmwares[i], |
| 2510 | UCODE_LOADER_API_VER); |
| 2511 | WL_NONE(("request fw %s\n", fw_name)); |
| 2512 | status = request_firmware(&wl->fw.fw_bin[i], fw_name, device); |
| 2513 | if (status) { |
| 2514 | printf("fail to request firmware %s\n", fw_name); |
Ben Hutchings | eb4764c | 2010-09-10 01:38:18 +0100 | [diff] [blame] | 2515 | wl_release_fw(wl); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2516 | return status; |
| 2517 | } |
| 2518 | WL_NONE(("request fw %s\n", fw_name)); |
| 2519 | sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i], |
| 2520 | UCODE_LOADER_API_VER); |
| 2521 | status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device); |
| 2522 | if (status) { |
| 2523 | printf("fail to request firmware %s\n", fw_name); |
Ben Hutchings | eb4764c | 2010-09-10 01:38:18 +0100 | [diff] [blame] | 2524 | wl_release_fw(wl); |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2525 | return status; |
| 2526 | } |
| 2527 | wl->fw.hdr_num_entries[i] = |
| 2528 | wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr)); |
| 2529 | WL_NONE(("request fw %s find: %d entries\n", fw_name, |
| 2530 | wl->fw.hdr_num_entries[i])); |
| 2531 | } |
| 2532 | wl->fw.fw_cnt = i; |
| 2533 | wl_ucode_data_init(wl); |
| 2534 | return 0; |
| 2535 | } |
| 2536 | |
| 2537 | #ifdef WLC_LOW |
| 2538 | void wl_ucode_free_buf(void *p) |
| 2539 | { |
| 2540 | kfree(p); |
| 2541 | } |
| 2542 | #endif /* WLC_LOW */ |
| 2543 | |
Jason Cooper | 7cc4a4c | 2010-09-14 09:45:30 -0400 | [diff] [blame] | 2544 | static void wl_release_fw(wl_info_t *wl) |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2545 | { |
| 2546 | int i; |
Ben Hutchings | eb4764c | 2010-09-10 01:38:18 +0100 | [diff] [blame] | 2547 | for (i = 0; i < WL_MAX_FW; i++) { |
Henry Ptasinski | a9533e7 | 2010-09-08 21:04:42 -0700 | [diff] [blame] | 2548 | release_firmware(wl->fw.fw_bin[i]); |
| 2549 | release_firmware(wl->fw.fw_hdr[i]); |
| 2550 | } |
| 2551 | } |
| 2552 | #endif /* WLC_HIGH_ONLY */ |