2 * Copyright (c) 2010 Broadcom Corporation
3 * Copyright (c) 2013 Hauke Mehrtens <hauke@hauke-m.de>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #define __UNDEF_NO_VERSION__
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/etherdevice.h>
22 #include <linux/sched.h>
23 #include <linux/firmware.h>
24 #include <linux/interrupt.h>
25 #include <linux/module.h>
26 #include <linux/bcma/bcma.h>
27 #include <net/mac80211.h>
29 #include "phy/phy_int.h"
34 #include "ucode_loader.h"
35 #include "mac80211_if.h"
40 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
41 #define BRCMS_FLUSH_TIMEOUT 500 /* msec */
43 /* Flags we support */
44 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
49 FIF_BCN_PRBRESP_PROMISC | \
52 #define CHAN2GHZ(channel, freqency, chflags) { \
53 .band = IEEE80211_BAND_2GHZ, \
54 .center_freq = (freqency), \
55 .hw_value = (channel), \
57 .max_antenna_gain = 0, \
61 #define CHAN5GHZ(channel, chflags) { \
62 .band = IEEE80211_BAND_5GHZ, \
63 .center_freq = 5000 + 5*(channel), \
64 .hw_value = (channel), \
66 .max_antenna_gain = 0, \
70 #define RATE(rate100m, _flags) { \
71 .bitrate = (rate100m), \
73 .hw_value = (rate100m / 5), \
82 static const char * const brcms_firmwares[MAX_FW_IMAGES] = {
87 static int n_adapters_found;
89 MODULE_AUTHOR("Broadcom Corporation");
90 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
91 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
92 MODULE_LICENSE("Dual BSD/GPL");
93 /* This needs to be adjusted when brcms_firmwares changes */
94 MODULE_FIRMWARE("brcm/bcm43xx-0.fw");
95 MODULE_FIRMWARE("brcm/bcm43xx_hdr-0.fw");
97 /* recognized BCMA Core IDs */
98 static struct bcma_device_id brcms_coreid_table[] = {
99 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 17, BCMA_ANY_CLASS),
100 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 23, BCMA_ANY_CLASS),
101 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 24, BCMA_ANY_CLASS),
104 MODULE_DEVICE_TABLE(bcma, brcms_coreid_table);
106 #if defined(CONFIG_BRCMDBG)
108 * Module parameter for setting the debug message level. Available
109 * flags are specified by the BRCM_DL_* macros in
110 * drivers/net/wireless/brcm80211/include/defs.h.
112 module_param_named(debug, brcm_msg_level, uint, S_IRUGO | S_IWUSR);
115 static struct ieee80211_channel brcms_2ghz_chantable[] = {
116 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
117 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
118 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
119 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
120 CHAN2GHZ(5, 2432, 0),
121 CHAN2GHZ(6, 2437, 0),
122 CHAN2GHZ(7, 2442, 0),
123 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
124 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
125 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
126 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
128 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
129 IEEE80211_CHAN_NO_HT40PLUS),
131 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
132 IEEE80211_CHAN_NO_HT40PLUS),
134 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
135 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS |
136 IEEE80211_CHAN_NO_OFDM)
139 static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
141 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
142 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
143 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
144 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
147 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
148 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
150 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
151 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
153 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
154 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
156 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
157 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
160 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
161 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
163 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
164 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
166 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
167 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
169 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
170 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
172 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
173 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
175 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
176 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
178 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
179 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
181 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
182 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
184 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
185 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
187 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
188 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
190 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
191 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
192 IEEE80211_CHAN_NO_HT40MINUS),
194 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
195 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
196 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
197 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
198 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
202 * The rate table is used for both 2.4G and 5G rates. The
203 * latter being a subset as it does not support CCK rates.
205 static struct ieee80211_rate legacy_ratetable[] = {
207 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
208 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
209 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
220 static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template = {
221 .band = IEEE80211_BAND_2GHZ,
222 .channels = brcms_2ghz_chantable,
223 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
224 .bitrates = legacy_ratetable,
225 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
227 /* from include/linux/ieee80211.h */
228 .cap = IEEE80211_HT_CAP_GRN_FLD |
229 IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40,
230 .ht_supported = true,
231 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
232 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
234 /* placeholders for now */
235 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
236 .rx_highest = cpu_to_le16(500),
237 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
241 static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template = {
242 .band = IEEE80211_BAND_5GHZ,
243 .channels = brcms_5ghz_nphy_chantable,
244 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
245 .bitrates = legacy_ratetable + BRCMS_LEGACY_5G_RATE_OFFSET,
246 .n_bitrates = ARRAY_SIZE(legacy_ratetable) -
247 BRCMS_LEGACY_5G_RATE_OFFSET,
249 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
250 IEEE80211_HT_CAP_SGI_40,
251 .ht_supported = true,
252 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
253 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
255 /* placeholders for now */
256 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
257 .rx_highest = cpu_to_le16(500),
258 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
262 /* flags the given rate in rateset as requested */
263 static void brcms_set_basic_rate(struct brcm_rateset *rs, u16 rate, bool is_br)
267 for (i = 0; i < rs->count; i++) {
268 if (rate != (rs->rates[i] & 0x7f))
272 rs->rates[i] |= BRCMS_RATE_FLAG;
274 rs->rates[i] &= BRCMS_RATE_MASK;
280 * This function frees the WL per-device resources.
282 * This function frees resources owned by the WL device pointed to
283 * by the wl parameter.
285 * precondition: can both be called locked and unlocked
288 static void brcms_free(struct brcms_info *wl)
290 struct brcms_timer *t, *next;
292 /* free ucode data */
294 brcms_ucode_data_free(&wl->ucode);
296 free_irq(wl->irq, wl);
299 tasklet_kill(&wl->tasklet);
302 brcms_debugfs_detach(wl->pub);
303 brcms_c_module_unregister(wl->pub, "linux", wl);
306 /* free common resources */
308 brcms_c_detach(wl->wlc);
313 /* virtual interface deletion is deferred so we cannot spinwait */
315 /* wait for all pending callbacks to complete */
316 while (atomic_read(&wl->callbacks) > 0)
320 for (t = wl->timers; t; t = next) {
330 * called from both kernel as from this kernel module (error flow on attach)
331 * precondition: perimeter lock is not acquired.
333 static void brcms_remove(struct bcma_device *pdev)
335 struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
336 struct brcms_info *wl = hw->priv;
339 brcms_led_unregister(wl);
340 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
341 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
342 ieee80211_unregister_hw(hw);
347 bcma_set_drvdata(pdev, NULL);
348 ieee80211_free_hw(hw);
352 * Precondition: Since this function is called in brcms_pci_probe() context,
353 * no locking is required.
355 static void brcms_release_fw(struct brcms_info *wl)
358 for (i = 0; i < MAX_FW_IMAGES; i++) {
359 release_firmware(wl->fw.fw_bin[i]);
360 release_firmware(wl->fw.fw_hdr[i]);
365 * Precondition: Since this function is called in brcms_pci_probe() context,
366 * no locking is required.
368 static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
371 struct device *device = &pdev->dev;
375 memset(&wl->fw, 0, sizeof(struct brcms_firmware));
376 for (i = 0; i < MAX_FW_IMAGES; i++) {
377 if (brcms_firmwares[i] == NULL)
379 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
380 UCODE_LOADER_API_VER);
381 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
383 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
384 KBUILD_MODNAME, fw_name);
387 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
388 UCODE_LOADER_API_VER);
389 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
391 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
392 KBUILD_MODNAME, fw_name);
395 wl->fw.hdr_num_entries[i] =
396 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
399 status = brcms_ucode_data_init(wl, &wl->ucode);
400 brcms_release_fw(wl);
404 static void brcms_ops_tx(struct ieee80211_hw *hw,
405 struct ieee80211_tx_control *control,
408 struct brcms_info *wl = hw->priv;
409 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
411 spin_lock_bh(&wl->lock);
413 brcms_err(wl->wlc->hw->d11core, "ops->tx called while down\n");
417 if (brcms_c_sendpkt_mac80211(wl->wlc, skb, hw))
418 tx_info->rate_driver_data[0] = control->sta;
420 spin_unlock_bh(&wl->lock);
423 static int brcms_ops_start(struct ieee80211_hw *hw)
425 struct brcms_info *wl = hw->priv;
429 if (!wl->ucode.bcm43xx_bomminor) {
430 err = brcms_request_fw(wl, wl->wlc->hw->d11core);
435 ieee80211_wake_queues(hw);
436 spin_lock_bh(&wl->lock);
437 blocked = brcms_rfkill_set_hw_state(wl);
438 spin_unlock_bh(&wl->lock);
440 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
442 spin_lock_bh(&wl->lock);
443 /* avoid acknowledging frames before a non-monitor device is added */
453 spin_unlock_bh(&wl->lock);
456 brcms_err(wl->wlc->hw->d11core, "%s: brcms_up() returned %d\n",
461 static void brcms_ops_stop(struct ieee80211_hw *hw)
463 struct brcms_info *wl = hw->priv;
466 ieee80211_stop_queues(hw);
471 spin_lock_bh(&wl->lock);
472 status = brcms_c_chipmatch(wl->wlc->hw->d11core);
473 spin_unlock_bh(&wl->lock);
475 brcms_err(wl->wlc->hw->d11core,
476 "wl: brcms_ops_stop: chipmatch failed\n");
480 /* put driver in down state */
481 spin_lock_bh(&wl->lock);
483 spin_unlock_bh(&wl->lock);
487 brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
489 struct brcms_info *wl = hw->priv;
491 /* Just STA, AP and ADHOC for now */
492 if (vif->type != NL80211_IFTYPE_STATION &&
493 vif->type != NL80211_IFTYPE_AP &&
494 vif->type != NL80211_IFTYPE_ADHOC) {
495 brcms_err(wl->wlc->hw->d11core,
496 "%s: Attempt to add type %d, only STA, AP and AdHoc for now\n",
497 __func__, vif->type);
501 spin_lock_bh(&wl->lock);
503 brcms_c_mute(wl->wlc, false);
504 if (vif->type == NL80211_IFTYPE_STATION)
505 brcms_c_start_station(wl->wlc, vif->addr);
506 else if (vif->type == NL80211_IFTYPE_AP)
507 brcms_c_start_ap(wl->wlc, vif->addr, vif->bss_conf.bssid,
508 vif->bss_conf.ssid, vif->bss_conf.ssid_len);
509 else if (vif->type == NL80211_IFTYPE_ADHOC)
510 brcms_c_start_adhoc(wl->wlc, vif->addr);
511 spin_unlock_bh(&wl->lock);
517 brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
521 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
523 struct ieee80211_conf *conf = &hw->conf;
524 struct brcms_info *wl = hw->priv;
525 struct bcma_device *core = wl->wlc->hw->d11core;
529 spin_lock_bh(&wl->lock);
530 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
531 brcms_c_set_beacon_listen_interval(wl->wlc,
532 conf->listen_interval);
534 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
535 brcms_dbg_info(core, "%s: change monitor mode: %s\n",
536 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
538 if (changed & IEEE80211_CONF_CHANGE_PS)
539 brcms_err(core, "%s: change power-save mode: %s (implement)\n",
540 __func__, conf->flags & IEEE80211_CONF_PS ?
543 if (changed & IEEE80211_CONF_CHANGE_POWER) {
544 err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
546 brcms_err(core, "%s: Error setting power_level\n",
550 new_int = brcms_c_get_tx_power(wl->wlc);
551 if (new_int != conf->power_level)
553 "%s: Power level req != actual, %d %d\n",
554 __func__, conf->power_level,
557 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
558 if (conf->chandef.width == NL80211_CHAN_WIDTH_20 ||
559 conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
560 err = brcms_c_set_channel(wl->wlc,
561 conf->chandef.chan->hw_value);
565 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
566 err = brcms_c_set_rate_limit(wl->wlc,
567 conf->short_frame_max_tx_count,
568 conf->long_frame_max_tx_count);
571 spin_unlock_bh(&wl->lock);
576 brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
577 struct ieee80211_vif *vif,
578 struct ieee80211_bss_conf *info, u32 changed)
580 struct brcms_info *wl = hw->priv;
581 struct bcma_device *core = wl->wlc->hw->d11core;
583 if (changed & BSS_CHANGED_ASSOC) {
584 /* association status changed (associated/disassociated)
585 * also implies a change in the AID.
587 brcms_err(core, "%s: %s: %sassociated\n", KBUILD_MODNAME,
588 __func__, info->assoc ? "" : "dis");
589 spin_lock_bh(&wl->lock);
590 brcms_c_associate_upd(wl->wlc, info->assoc);
591 spin_unlock_bh(&wl->lock);
593 if (changed & BSS_CHANGED_ERP_SLOT) {
596 /* slot timing changed */
597 if (info->use_short_slot)
601 spin_lock_bh(&wl->lock);
602 brcms_c_set_shortslot_override(wl->wlc, val);
603 spin_unlock_bh(&wl->lock);
606 if (changed & BSS_CHANGED_HT) {
607 /* 802.11n parameters changed */
608 u16 mode = info->ht_operation_mode;
610 spin_lock_bh(&wl->lock);
611 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
612 mode & IEEE80211_HT_OP_MODE_PROTECTION);
613 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
614 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
615 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
616 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
617 spin_unlock_bh(&wl->lock);
619 if (changed & BSS_CHANGED_BASIC_RATES) {
620 struct ieee80211_supported_band *bi;
623 struct brcm_rateset rs;
626 /* retrieve the current rates */
627 spin_lock_bh(&wl->lock);
628 brcms_c_get_current_rateset(wl->wlc, &rs);
629 spin_unlock_bh(&wl->lock);
631 br_mask = info->basic_rates;
632 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
633 for (i = 0; i < bi->n_bitrates; i++) {
634 /* convert to internal rate value */
635 rate = (bi->bitrates[i].bitrate << 1) / 10;
637 /* set/clear basic rate flag */
638 brcms_set_basic_rate(&rs, rate, br_mask & 1);
642 /* update the rate set */
643 spin_lock_bh(&wl->lock);
644 error = brcms_c_set_rateset(wl->wlc, &rs);
645 spin_unlock_bh(&wl->lock);
647 brcms_err(core, "changing basic rates failed: %d\n",
650 if (changed & BSS_CHANGED_BEACON_INT) {
651 /* Beacon interval changed */
652 spin_lock_bh(&wl->lock);
653 brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
654 spin_unlock_bh(&wl->lock);
656 if (changed & BSS_CHANGED_BSSID) {
657 /* BSSID changed, for whatever reason (IBSS and managed mode) */
658 spin_lock_bh(&wl->lock);
659 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
660 spin_unlock_bh(&wl->lock);
662 if (changed & BSS_CHANGED_SSID) {
663 /* BSSID changed, for whatever reason (IBSS and managed mode) */
664 spin_lock_bh(&wl->lock);
665 brcms_c_set_ssid(wl->wlc, info->ssid, info->ssid_len);
666 spin_unlock_bh(&wl->lock);
668 if (changed & BSS_CHANGED_BEACON) {
669 /* Beacon data changed, retrieve new beacon (beaconing modes) */
670 struct sk_buff *beacon;
673 spin_lock_bh(&wl->lock);
674 beacon = ieee80211_beacon_get_tim(hw, vif, &tim_offset, NULL);
675 brcms_c_set_new_beacon(wl->wlc, beacon, tim_offset,
677 spin_unlock_bh(&wl->lock);
680 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
681 struct sk_buff *probe_resp;
683 spin_lock_bh(&wl->lock);
684 probe_resp = ieee80211_proberesp_get(hw, vif);
685 brcms_c_set_new_probe_resp(wl->wlc, probe_resp);
686 spin_unlock_bh(&wl->lock);
689 if (changed & BSS_CHANGED_BEACON_ENABLED) {
690 /* Beaconing should be enabled/disabled (beaconing modes) */
691 brcms_err(core, "%s: Beacon enabled: %s\n", __func__,
692 info->enable_beacon ? "true" : "false");
693 if (info->enable_beacon &&
694 hw->wiphy->flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) {
695 brcms_c_enable_probe_resp(wl->wlc, true);
697 brcms_c_enable_probe_resp(wl->wlc, false);
701 if (changed & BSS_CHANGED_CQM) {
702 /* Connection quality monitor config changed */
703 brcms_err(core, "%s: cqm change: threshold %d, hys %d "
704 " (implement)\n", __func__, info->cqm_rssi_thold,
705 info->cqm_rssi_hyst);
708 if (changed & BSS_CHANGED_IBSS) {
709 /* IBSS join status changed */
710 brcms_err(core, "%s: IBSS joined: %s (implement)\n",
711 __func__, info->ibss_joined ? "true" : "false");
714 if (changed & BSS_CHANGED_ARP_FILTER) {
715 /* Hardware ARP filter address list or state changed */
716 brcms_err(core, "%s: arp filtering: %d addresses"
717 " (implement)\n", __func__, info->arp_addr_cnt);
720 if (changed & BSS_CHANGED_QOS) {
722 * QoS for this association was enabled/disabled.
723 * Note that it is only ever disabled for station mode.
725 brcms_err(core, "%s: qos enabled: %s (implement)\n",
726 __func__, info->qos ? "true" : "false");
732 brcms_ops_configure_filter(struct ieee80211_hw *hw,
733 unsigned int changed_flags,
734 unsigned int *total_flags, u64 multicast)
736 struct brcms_info *wl = hw->priv;
737 struct bcma_device *core = wl->wlc->hw->d11core;
739 changed_flags &= MAC_FILTERS;
740 *total_flags &= MAC_FILTERS;
742 if (changed_flags & FIF_PROMISC_IN_BSS)
743 brcms_dbg_info(core, "FIF_PROMISC_IN_BSS\n");
744 if (changed_flags & FIF_ALLMULTI)
745 brcms_dbg_info(core, "FIF_ALLMULTI\n");
746 if (changed_flags & FIF_FCSFAIL)
747 brcms_dbg_info(core, "FIF_FCSFAIL\n");
748 if (changed_flags & FIF_CONTROL)
749 brcms_dbg_info(core, "FIF_CONTROL\n");
750 if (changed_flags & FIF_OTHER_BSS)
751 brcms_dbg_info(core, "FIF_OTHER_BSS\n");
752 if (changed_flags & FIF_PSPOLL)
753 brcms_dbg_info(core, "FIF_PSPOLL\n");
754 if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
755 brcms_dbg_info(core, "FIF_BCN_PRBRESP_PROMISC\n");
757 spin_lock_bh(&wl->lock);
758 brcms_c_mac_promisc(wl->wlc, *total_flags);
759 spin_unlock_bh(&wl->lock);
763 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
765 struct brcms_info *wl = hw->priv;
766 spin_lock_bh(&wl->lock);
767 brcms_c_scan_start(wl->wlc);
768 spin_unlock_bh(&wl->lock);
772 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
774 struct brcms_info *wl = hw->priv;
775 spin_lock_bh(&wl->lock);
776 brcms_c_scan_stop(wl->wlc);
777 spin_unlock_bh(&wl->lock);
782 brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
783 const struct ieee80211_tx_queue_params *params)
785 struct brcms_info *wl = hw->priv;
787 spin_lock_bh(&wl->lock);
788 brcms_c_wme_setparams(wl->wlc, queue, params, true);
789 spin_unlock_bh(&wl->lock);
795 brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
796 struct ieee80211_sta *sta)
798 struct brcms_info *wl = hw->priv;
799 struct scb *scb = &wl->wlc->pri_scb;
801 brcms_c_init_scb(scb);
803 wl->pub->global_ampdu = &(scb->scb_ampdu);
804 wl->pub->global_ampdu->scb = scb;
805 wl->pub->global_ampdu->max_pdu = 16;
808 * minstrel_ht initiates addBA on our behalf by calling
809 * ieee80211_start_tx_ba_session()
815 brcms_ops_ampdu_action(struct ieee80211_hw *hw,
816 struct ieee80211_vif *vif,
817 enum ieee80211_ampdu_mlme_action action,
818 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
821 struct brcms_info *wl = hw->priv;
822 struct scb *scb = &wl->wlc->pri_scb;
825 if (WARN_ON(scb->magic != SCB_MAGIC))
828 case IEEE80211_AMPDU_RX_START:
830 case IEEE80211_AMPDU_RX_STOP:
832 case IEEE80211_AMPDU_TX_START:
833 spin_lock_bh(&wl->lock);
834 status = brcms_c_aggregatable(wl->wlc, tid);
835 spin_unlock_bh(&wl->lock);
837 brcms_err(wl->wlc->hw->d11core,
838 "START: tid %d is not agg\'able\n", tid);
841 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
844 case IEEE80211_AMPDU_TX_STOP_CONT:
845 case IEEE80211_AMPDU_TX_STOP_FLUSH:
846 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
847 spin_lock_bh(&wl->lock);
848 brcms_c_ampdu_flush(wl->wlc, sta, tid);
849 spin_unlock_bh(&wl->lock);
850 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
852 case IEEE80211_AMPDU_TX_OPERATIONAL:
854 * BA window size from ADDBA response ('buf_size') defines how
855 * many outstanding MPDUs are allowed for the BA stream by
856 * recipient and traffic class. 'ampdu_factor' gives maximum
859 spin_lock_bh(&wl->lock);
860 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
861 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
862 sta->ht_cap.ampdu_factor)) - 1);
863 spin_unlock_bh(&wl->lock);
864 /* Power save wakeup */
867 brcms_err(wl->wlc->hw->d11core,
868 "%s: Invalid command, ignoring\n", __func__);
874 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
876 struct brcms_info *wl = hw->priv;
879 spin_lock_bh(&wl->lock);
880 blocked = brcms_c_check_radio_disabled(wl->wlc);
881 spin_unlock_bh(&wl->lock);
883 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
886 static bool brcms_tx_flush_completed(struct brcms_info *wl)
890 spin_lock_bh(&wl->lock);
891 result = brcms_c_tx_flush_completed(wl->wlc);
892 spin_unlock_bh(&wl->lock);
896 static void brcms_ops_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
898 struct brcms_info *wl = hw->priv;
901 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
903 ret = wait_event_timeout(wl->tx_flush_wq,
904 brcms_tx_flush_completed(wl),
905 msecs_to_jiffies(BRCMS_FLUSH_TIMEOUT));
907 brcms_dbg_mac80211(wl->wlc->hw->d11core,
908 "ret=%d\n", jiffies_to_msecs(ret));
911 static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
913 struct brcms_info *wl = hw->priv;
916 spin_lock_bh(&wl->lock);
917 tsf = brcms_c_tsf_get(wl->wlc);
918 spin_unlock_bh(&wl->lock);
923 static void brcms_ops_set_tsf(struct ieee80211_hw *hw,
924 struct ieee80211_vif *vif, u64 tsf)
926 struct brcms_info *wl = hw->priv;
928 spin_lock_bh(&wl->lock);
929 brcms_c_tsf_set(wl->wlc, tsf);
930 spin_unlock_bh(&wl->lock);
933 static const struct ieee80211_ops brcms_ops = {
935 .start = brcms_ops_start,
936 .stop = brcms_ops_stop,
937 .add_interface = brcms_ops_add_interface,
938 .remove_interface = brcms_ops_remove_interface,
939 .config = brcms_ops_config,
940 .bss_info_changed = brcms_ops_bss_info_changed,
941 .configure_filter = brcms_ops_configure_filter,
942 .sw_scan_start = brcms_ops_sw_scan_start,
943 .sw_scan_complete = brcms_ops_sw_scan_complete,
944 .conf_tx = brcms_ops_conf_tx,
945 .sta_add = brcms_ops_sta_add,
946 .ampdu_action = brcms_ops_ampdu_action,
947 .rfkill_poll = brcms_ops_rfkill_poll,
948 .flush = brcms_ops_flush,
949 .get_tsf = brcms_ops_get_tsf,
950 .set_tsf = brcms_ops_set_tsf,
953 void brcms_dpc(unsigned long data)
955 struct brcms_info *wl;
957 wl = (struct brcms_info *) data;
959 spin_lock_bh(&wl->lock);
961 /* call the common second level interrupt handler */
966 spin_lock_irqsave(&wl->isr_lock, flags);
967 brcms_c_intrsupd(wl->wlc);
968 spin_unlock_irqrestore(&wl->isr_lock, flags);
971 wl->resched = brcms_c_dpc(wl->wlc, true);
974 /* brcms_c_dpc() may bring the driver down */
978 /* re-schedule dpc */
980 tasklet_schedule(&wl->tasklet);
982 /* re-enable interrupts */
986 spin_unlock_bh(&wl->lock);
987 wake_up(&wl->tx_flush_wq);
990 static irqreturn_t brcms_isr(int irq, void *dev_id)
992 struct brcms_info *wl;
993 irqreturn_t ret = IRQ_NONE;
995 wl = (struct brcms_info *) dev_id;
997 spin_lock(&wl->isr_lock);
999 /* call common first level interrupt handler */
1000 if (brcms_c_isr(wl->wlc)) {
1001 /* schedule second level handler */
1002 tasklet_schedule(&wl->tasklet);
1006 spin_unlock(&wl->isr_lock);
1012 * is called in brcms_pci_probe() context, therefore no locking required.
1014 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1016 struct brcms_info *wl = hw->priv;
1017 struct brcms_c_info *wlc = wl->wlc;
1018 struct ieee80211_supported_band *band;
1022 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1023 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1025 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
1026 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
1027 band = &wlc->bandstate[BAND_2G_INDEX]->band;
1028 *band = brcms_band_2GHz_nphy_template;
1029 if (phy_type == PHY_TYPE_LCN) {
1031 band->ht_cap.mcs.rx_mask[1] = 0;
1032 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
1034 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
1039 /* Assume all bands use the same phy. True for 11n devices. */
1040 if (wl->pub->_nbands > 1) {
1042 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
1043 band = &wlc->bandstate[BAND_5G_INDEX]->band;
1044 *band = brcms_band_5GHz_nphy_template;
1045 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
1054 * is called in brcms_pci_probe() context, therefore no locking required.
1056 static int ieee_hw_init(struct ieee80211_hw *hw)
1058 hw->flags = IEEE80211_HW_SIGNAL_DBM
1059 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
1060 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
1061 | IEEE80211_HW_AMPDU_AGGREGATION;
1063 hw->extra_tx_headroom = brcms_c_get_header_len();
1064 hw->queues = N_TX_QUEUES;
1065 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1067 /* channel change time is dependent on chip and band */
1068 hw->channel_change_time = 7 * 1000;
1069 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1070 BIT(NL80211_IFTYPE_AP) |
1071 BIT(NL80211_IFTYPE_ADHOC);
1074 * deactivate sending probe responses by ucude, because this will
1075 * cause problems when WPS is used.
1077 * hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1080 hw->rate_control_algorithm = "minstrel_ht";
1082 hw->sta_data_size = 0;
1083 return ieee_hw_rate_init(hw);
1087 * attach to the WL device.
1089 * Attach to the WL device identified by vendor and device parameters.
1090 * regs is a host accessible memory address pointing to WL device registers.
1092 * brcms_attach is not defined as static because in the case where no bus
1093 * is defined, wl_attach will never be called, and thus, gcc will issue
1094 * a warning that this function is defined but not used if we declare
1098 * is called in brcms_bcma_probe() context, therefore no locking required.
1100 static struct brcms_info *brcms_attach(struct bcma_device *pdev)
1102 struct brcms_info *wl = NULL;
1104 struct ieee80211_hw *hw;
1107 unit = n_adapters_found;
1113 /* allocate private info */
1114 hw = bcma_get_drvdata(pdev);
1117 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1119 wl->wiphy = hw->wiphy;
1121 atomic_set(&wl->callbacks, 0);
1123 init_waitqueue_head(&wl->tx_flush_wq);
1125 /* setup the bottom half handler */
1126 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1128 spin_lock_init(&wl->lock);
1129 spin_lock_init(&wl->isr_lock);
1131 /* common load-time initialization */
1132 wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
1134 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1135 KBUILD_MODNAME, err);
1138 wl->pub = brcms_c_pub(wl->wlc);
1140 wl->pub->ieee_hw = hw;
1142 /* register our interrupt handler */
1143 if (request_irq(pdev->irq, brcms_isr,
1144 IRQF_SHARED, KBUILD_MODNAME, wl)) {
1145 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1148 wl->irq = pdev->irq;
1150 /* register module */
1151 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1153 if (ieee_hw_init(hw)) {
1154 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1159 brcms_c_regd_init(wl->wlc);
1161 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1162 if (WARN_ON(!is_valid_ether_addr(perm)))
1164 SET_IEEE80211_PERM_ADDR(hw, perm);
1166 err = ieee80211_register_hw(hw);
1168 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1169 "%d\n", __func__, err);
1171 if (wl->pub->srom_ccode[0] &&
1172 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1173 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
1175 brcms_debugfs_attach(wl->pub);
1176 brcms_debugfs_create_files(wl->pub);
1188 * determines if a device is a WL device, and if so, attaches it.
1190 * This function determines if a device pointed to by pdev is a WL device,
1191 * and if so, performs a brcms_attach() on it.
1193 * Perimeter lock is initialized in the course of this function.
1195 static int brcms_bcma_probe(struct bcma_device *pdev)
1197 struct brcms_info *wl;
1198 struct ieee80211_hw *hw;
1200 dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
1201 pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
1204 if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
1205 (pdev->id.id != BCMA_CORE_80211))
1208 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1210 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1214 SET_IEEE80211_DEV(hw, &pdev->dev);
1216 bcma_set_drvdata(pdev, hw);
1218 memset(hw->priv, 0, sizeof(*wl));
1220 wl = brcms_attach(pdev);
1222 pr_err("%s: brcms_attach failed!\n", __func__);
1225 brcms_led_register(wl);
1230 static int brcms_suspend(struct bcma_device *pdev)
1232 struct brcms_info *wl;
1233 struct ieee80211_hw *hw;
1235 hw = bcma_get_drvdata(pdev);
1238 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
1243 /* only need to flag hw is down for proper resume */
1244 spin_lock_bh(&wl->lock);
1245 wl->pub->hw_up = false;
1246 spin_unlock_bh(&wl->lock);
1248 brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
1253 static int brcms_resume(struct bcma_device *pdev)
1258 static struct bcma_driver brcms_bcma_driver = {
1259 .name = KBUILD_MODNAME,
1260 .probe = brcms_bcma_probe,
1261 .suspend = brcms_suspend,
1262 .resume = brcms_resume,
1263 .remove = brcms_remove,
1264 .id_table = brcms_coreid_table,
1268 * This is the main entry point for the brcmsmac driver.
1270 * This function is scheduled upon module initialization and
1271 * does the driver registration, which result in brcms_bcma_probe()
1272 * call resulting in the driver bringup.
1274 static void brcms_driver_init(struct work_struct *work)
1278 error = bcma_driver_register(&brcms_bcma_driver);
1280 pr_err("%s: register returned %d\n", __func__, error);
1283 static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
1285 static int __init brcms_module_init(void)
1287 brcms_debugfs_init();
1288 if (!schedule_work(&brcms_driver_work))
1295 * This function unloads the brcmsmac driver from the system.
1297 * This function unconditionally unloads the brcmsmac driver module from the
1301 static void __exit brcms_module_exit(void)
1303 cancel_work_sync(&brcms_driver_work);
1304 bcma_driver_unregister(&brcms_bcma_driver);
1305 brcms_debugfs_exit();
1308 module_init(brcms_module_init);
1309 module_exit(brcms_module_exit);
1312 * precondition: perimeter lock has been acquired
1314 void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1315 bool state, int prio)
1317 brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
1321 * precondition: perimeter lock has been acquired
1323 void brcms_init(struct brcms_info *wl)
1325 brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
1328 brcms_c_init(wl->wlc, wl->mute_tx);
1332 * precondition: perimeter lock has been acquired
1334 uint brcms_reset(struct brcms_info *wl)
1336 brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
1337 brcms_c_reset(wl->wlc);
1339 /* dpc will not be rescheduled */
1340 wl->resched = false;
1342 /* inform publicly that interface is down */
1343 wl->pub->up = false;
1348 void brcms_fatal_error(struct brcms_info *wl)
1350 brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
1351 wl->wlc->pub->unit);
1353 ieee80211_restart_hw(wl->pub->ieee_hw);
1357 * These are interrupt on/off entry points. Disable interrupts
1358 * during interrupt state transition.
1360 void brcms_intrson(struct brcms_info *wl)
1362 unsigned long flags;
1364 spin_lock_irqsave(&wl->isr_lock, flags);
1365 brcms_c_intrson(wl->wlc);
1366 spin_unlock_irqrestore(&wl->isr_lock, flags);
1369 u32 brcms_intrsoff(struct brcms_info *wl)
1371 unsigned long flags;
1374 spin_lock_irqsave(&wl->isr_lock, flags);
1375 status = brcms_c_intrsoff(wl->wlc);
1376 spin_unlock_irqrestore(&wl->isr_lock, flags);
1380 void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1382 unsigned long flags;
1384 spin_lock_irqsave(&wl->isr_lock, flags);
1385 brcms_c_intrsrestore(wl->wlc, macintmask);
1386 spin_unlock_irqrestore(&wl->isr_lock, flags);
1390 * precondition: perimeter lock has been acquired
1392 int brcms_up(struct brcms_info *wl)
1399 error = brcms_c_up(wl->wlc);
1405 * precondition: perimeter lock has been acquired
1407 void brcms_down(struct brcms_info *wl)
1409 uint callbacks, ret_val = 0;
1411 /* call common down function */
1412 ret_val = brcms_c_down(wl->wlc);
1413 callbacks = atomic_read(&wl->callbacks) - ret_val;
1415 /* wait for down callbacks to complete */
1416 spin_unlock_bh(&wl->lock);
1418 /* For HIGH_only driver, it's important to actually schedule other work,
1419 * not just spin wait since everything runs at schedule level
1421 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1423 spin_lock_bh(&wl->lock);
1427 * precondition: perimeter lock is not acquired
1429 static void _brcms_timer(struct work_struct *work)
1431 struct brcms_timer *t = container_of(work, struct brcms_timer,
1434 spin_lock_bh(&t->wl->lock);
1438 atomic_inc(&t->wl->callbacks);
1439 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1441 msecs_to_jiffies(t->ms));
1449 atomic_dec(&t->wl->callbacks);
1451 spin_unlock_bh(&t->wl->lock);
1455 * Adds a timer to the list. Caller supplies a timer function.
1456 * Is called from wlc.
1458 * precondition: perimeter lock has been acquired
1460 struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1461 void (*fn) (void *arg),
1462 void *arg, const char *name)
1464 struct brcms_timer *t;
1466 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1470 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
1474 t->next = wl->timers;
1478 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1480 strcpy(t->name, name);
1487 * adds only the kernel timer since it's going to be more accurate
1488 * as well as it's easier to make it periodic
1490 * precondition: perimeter lock has been acquired
1492 void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
1494 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1498 brcms_dbg_info(t->wl->wlc->hw->d11core,
1499 "%s: Already set. Name: %s, per %d\n",
1500 __func__, t->name, periodic);
1503 t->periodic = (bool) periodic;
1506 atomic_inc(&t->wl->callbacks);
1509 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
1513 * return true if timer successfully deleted, false if still pending
1515 * precondition: perimeter lock has been acquired
1517 bool brcms_del_timer(struct brcms_timer *t)
1521 if (!cancel_delayed_work(&t->dly_wrk))
1524 atomic_dec(&t->wl->callbacks);
1531 * precondition: perimeter lock has been acquired
1533 void brcms_free_timer(struct brcms_timer *t)
1535 struct brcms_info *wl = t->wl;
1536 struct brcms_timer *tmp;
1538 /* delete the timer in case it is active */
1541 if (wl->timers == t) {
1542 wl->timers = wl->timers->next;
1553 if (tmp->next == t) {
1554 tmp->next = t->next;
1567 * precondition: perimeter lock has been acquired
1569 int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1573 struct firmware_hdr *hdr;
1574 for (i = 0; i < wl->fw.fw_cnt; i++) {
1575 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1576 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1578 u32 len = le32_to_cpu(hdr->len);
1579 if (le32_to_cpu(hdr->idx) == idx) {
1580 pdata = wl->fw.fw_bin[i]->data +
1581 le32_to_cpu(hdr->offset);
1582 *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
1590 brcms_err(wl->wlc->hw->d11core,
1591 "ERROR: ucode buf tag:%d can not be found!\n", idx);
1598 * Precondition: Since this function is called in brcms_bcma_probe() context,
1599 * no locking is required.
1601 int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1605 struct firmware_hdr *hdr;
1606 for (i = 0; i < wl->fw.fw_cnt; i++) {
1607 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1608 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1610 if (le32_to_cpu(hdr->idx) == idx) {
1611 pdata = wl->fw.fw_bin[i]->data +
1612 le32_to_cpu(hdr->offset);
1613 if (le32_to_cpu(hdr->len) != 4) {
1614 brcms_err(wl->wlc->hw->d11core,
1615 "ERROR: fw hdr len\n");
1618 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1623 brcms_err(wl->wlc->hw->d11core,
1624 "ERROR: ucode tag:%d can not be found!\n", idx);
1629 * precondition: can both be called locked and unlocked
1631 void brcms_ucode_free_buf(void *p)
1637 * checks validity of all firmware images loaded from user space
1639 * Precondition: Since this function is called in brcms_bcma_probe() context,
1640 * no locking is required.
1642 int brcms_check_firmwares(struct brcms_info *wl)
1647 const struct firmware *fw;
1648 const struct firmware *fw_hdr;
1649 struct firmware_hdr *ucode_hdr;
1650 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1651 fw = wl->fw.fw_bin[i];
1652 fw_hdr = wl->fw.fw_hdr[i];
1653 if (fw == NULL && fw_hdr == NULL) {
1655 } else if (fw == NULL || fw_hdr == NULL) {
1656 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1659 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1660 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1661 "size %zu/%zu\n", __func__, fw_hdr->size,
1662 sizeof(struct firmware_hdr));
1664 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1665 wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
1666 __func__, fw->size);
1669 /* check if ucode section overruns firmware image */
1670 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1671 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1672 !rc; entry++, ucode_hdr++) {
1673 if (le32_to_cpu(ucode_hdr->offset) +
1674 le32_to_cpu(ucode_hdr->len) >
1676 wiphy_err(wl->wiphy,
1677 "%s: conflicting bin/hdr\n",
1684 if (rc == 0 && wl->fw.fw_cnt != i) {
1685 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1693 * precondition: perimeter lock has been acquired
1695 bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1697 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1699 spin_unlock_bh(&wl->lock);
1700 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1702 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1703 spin_lock_bh(&wl->lock);