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_ALLMULTI | \
48 FIF_BCN_PRBRESP_PROMISC | \
51 #define CHAN2GHZ(channel, freqency, chflags) { \
52 .band = IEEE80211_BAND_2GHZ, \
53 .center_freq = (freqency), \
54 .hw_value = (channel), \
56 .max_antenna_gain = 0, \
60 #define CHAN5GHZ(channel, chflags) { \
61 .band = IEEE80211_BAND_5GHZ, \
62 .center_freq = 5000 + 5*(channel), \
63 .hw_value = (channel), \
65 .max_antenna_gain = 0, \
69 #define RATE(rate100m, _flags) { \
70 .bitrate = (rate100m), \
72 .hw_value = (rate100m / 5), \
81 static const char * const brcms_firmwares[MAX_FW_IMAGES] = {
86 static int n_adapters_found;
88 MODULE_AUTHOR("Broadcom Corporation");
89 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
90 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
91 MODULE_LICENSE("Dual BSD/GPL");
92 /* This needs to be adjusted when brcms_firmwares changes */
93 MODULE_FIRMWARE("brcm/bcm43xx-0.fw");
94 MODULE_FIRMWARE("brcm/bcm43xx_hdr-0.fw");
96 /* recognized BCMA Core IDs */
97 static struct bcma_device_id brcms_coreid_table[] = {
98 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 17, BCMA_ANY_CLASS),
99 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 23, BCMA_ANY_CLASS),
100 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 24, BCMA_ANY_CLASS),
103 MODULE_DEVICE_TABLE(bcma, brcms_coreid_table);
105 #if defined(CONFIG_BRCMDBG)
107 * Module parameter for setting the debug message level. Available
108 * flags are specified by the BRCM_DL_* macros in
109 * drivers/net/wireless/brcm80211/include/defs.h.
111 module_param_named(debug, brcm_msg_level, uint, S_IRUGO | S_IWUSR);
114 static struct ieee80211_channel brcms_2ghz_chantable[] = {
115 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
116 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
117 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
118 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
119 CHAN2GHZ(5, 2432, 0),
120 CHAN2GHZ(6, 2437, 0),
121 CHAN2GHZ(7, 2442, 0),
122 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
123 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
124 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
125 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
127 IEEE80211_CHAN_NO_IR |
128 IEEE80211_CHAN_NO_HT40PLUS),
130 IEEE80211_CHAN_NO_IR |
131 IEEE80211_CHAN_NO_HT40PLUS),
133 IEEE80211_CHAN_NO_IR |
134 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS |
135 IEEE80211_CHAN_NO_OFDM)
138 static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
140 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
141 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
142 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
143 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
146 IEEE80211_CHAN_RADAR |
147 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
149 IEEE80211_CHAN_RADAR |
150 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
152 IEEE80211_CHAN_RADAR |
153 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
155 IEEE80211_CHAN_RADAR |
156 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
159 IEEE80211_CHAN_RADAR |
160 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
162 IEEE80211_CHAN_RADAR |
163 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
165 IEEE80211_CHAN_RADAR |
166 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
168 IEEE80211_CHAN_RADAR |
169 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
171 IEEE80211_CHAN_RADAR |
172 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
174 IEEE80211_CHAN_RADAR |
175 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
177 IEEE80211_CHAN_RADAR |
178 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
180 IEEE80211_CHAN_RADAR |
181 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
183 IEEE80211_CHAN_RADAR |
184 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40MINUS),
186 IEEE80211_CHAN_RADAR |
187 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS),
189 IEEE80211_CHAN_RADAR |
190 IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_NO_HT40PLUS |
191 IEEE80211_CHAN_NO_HT40MINUS),
193 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
194 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
195 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
196 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
197 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
201 * The rate table is used for both 2.4G and 5G rates. The
202 * latter being a subset as it does not support CCK rates.
204 static struct ieee80211_rate legacy_ratetable[] = {
206 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
207 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
208 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
219 static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template = {
220 .band = IEEE80211_BAND_2GHZ,
221 .channels = brcms_2ghz_chantable,
222 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
223 .bitrates = legacy_ratetable,
224 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
226 /* from include/linux/ieee80211.h */
227 .cap = IEEE80211_HT_CAP_GRN_FLD |
228 IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40,
229 .ht_supported = true,
230 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
231 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
233 /* placeholders for now */
234 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
235 .rx_highest = cpu_to_le16(500),
236 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
240 static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template = {
241 .band = IEEE80211_BAND_5GHZ,
242 .channels = brcms_5ghz_nphy_chantable,
243 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
244 .bitrates = legacy_ratetable + BRCMS_LEGACY_5G_RATE_OFFSET,
245 .n_bitrates = ARRAY_SIZE(legacy_ratetable) -
246 BRCMS_LEGACY_5G_RATE_OFFSET,
248 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
249 IEEE80211_HT_CAP_SGI_40,
250 .ht_supported = true,
251 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
252 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
254 /* placeholders for now */
255 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
256 .rx_highest = cpu_to_le16(500),
257 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
261 /* flags the given rate in rateset as requested */
262 static void brcms_set_basic_rate(struct brcm_rateset *rs, u16 rate, bool is_br)
266 for (i = 0; i < rs->count; i++) {
267 if (rate != (rs->rates[i] & 0x7f))
271 rs->rates[i] |= BRCMS_RATE_FLAG;
273 rs->rates[i] &= BRCMS_RATE_MASK;
279 * This function frees the WL per-device resources.
281 * This function frees resources owned by the WL device pointed to
282 * by the wl parameter.
284 * precondition: can both be called locked and unlocked
287 static void brcms_free(struct brcms_info *wl)
289 struct brcms_timer *t, *next;
291 /* free ucode data */
293 brcms_ucode_data_free(&wl->ucode);
295 free_irq(wl->irq, wl);
298 tasklet_kill(&wl->tasklet);
301 brcms_debugfs_detach(wl->pub);
302 brcms_c_module_unregister(wl->pub, "linux", wl);
305 /* free common resources */
307 brcms_c_detach(wl->wlc);
312 /* virtual interface deletion is deferred so we cannot spinwait */
314 /* wait for all pending callbacks to complete */
315 while (atomic_read(&wl->callbacks) > 0)
319 for (t = wl->timers; t; t = next) {
329 * called from both kernel as from this kernel module (error flow on attach)
330 * precondition: perimeter lock is not acquired.
332 static void brcms_remove(struct bcma_device *pdev)
334 struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
335 struct brcms_info *wl = hw->priv;
338 brcms_led_unregister(wl);
339 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
340 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
341 ieee80211_unregister_hw(hw);
346 bcma_set_drvdata(pdev, NULL);
347 ieee80211_free_hw(hw);
351 * Precondition: Since this function is called in brcms_pci_probe() context,
352 * no locking is required.
354 static void brcms_release_fw(struct brcms_info *wl)
357 for (i = 0; i < MAX_FW_IMAGES; i++) {
358 release_firmware(wl->fw.fw_bin[i]);
359 release_firmware(wl->fw.fw_hdr[i]);
364 * Precondition: Since this function is called in brcms_pci_probe() context,
365 * no locking is required.
367 static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
370 struct device *device = &pdev->dev;
374 memset(&wl->fw, 0, sizeof(struct brcms_firmware));
375 for (i = 0; i < MAX_FW_IMAGES; i++) {
376 if (brcms_firmwares[i] == NULL)
378 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
379 UCODE_LOADER_API_VER);
380 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
382 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
383 KBUILD_MODNAME, fw_name);
386 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
387 UCODE_LOADER_API_VER);
388 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
390 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
391 KBUILD_MODNAME, fw_name);
394 wl->fw.hdr_num_entries[i] =
395 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
398 status = brcms_ucode_data_init(wl, &wl->ucode);
399 brcms_release_fw(wl);
403 static void brcms_ops_tx(struct ieee80211_hw *hw,
404 struct ieee80211_tx_control *control,
407 struct brcms_info *wl = hw->priv;
408 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
410 spin_lock_bh(&wl->lock);
412 brcms_err(wl->wlc->hw->d11core, "ops->tx called while down\n");
416 if (brcms_c_sendpkt_mac80211(wl->wlc, skb, hw))
417 tx_info->rate_driver_data[0] = control->sta;
419 spin_unlock_bh(&wl->lock);
422 static int brcms_ops_start(struct ieee80211_hw *hw)
424 struct brcms_info *wl = hw->priv;
428 if (!wl->ucode.bcm43xx_bomminor) {
429 err = brcms_request_fw(wl, wl->wlc->hw->d11core);
434 ieee80211_wake_queues(hw);
435 spin_lock_bh(&wl->lock);
436 blocked = brcms_rfkill_set_hw_state(wl);
437 spin_unlock_bh(&wl->lock);
439 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
441 spin_lock_bh(&wl->lock);
442 /* avoid acknowledging frames before a non-monitor device is added */
452 spin_unlock_bh(&wl->lock);
455 brcms_err(wl->wlc->hw->d11core, "%s: brcms_up() returned %d\n",
458 bcma_core_pci_power_save(wl->wlc->hw->d11core->bus, true);
462 static void brcms_ops_stop(struct ieee80211_hw *hw)
464 struct brcms_info *wl = hw->priv;
467 ieee80211_stop_queues(hw);
472 spin_lock_bh(&wl->lock);
473 status = brcms_c_chipmatch(wl->wlc->hw->d11core);
474 spin_unlock_bh(&wl->lock);
476 brcms_err(wl->wlc->hw->d11core,
477 "wl: brcms_ops_stop: chipmatch failed\n");
481 bcma_core_pci_power_save(wl->wlc->hw->d11core->bus, false);
483 /* put driver in down state */
484 spin_lock_bh(&wl->lock);
486 spin_unlock_bh(&wl->lock);
490 brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
492 struct brcms_info *wl = hw->priv;
494 /* Just STA, AP and ADHOC for now */
495 if (vif->type != NL80211_IFTYPE_STATION &&
496 vif->type != NL80211_IFTYPE_AP &&
497 vif->type != NL80211_IFTYPE_ADHOC) {
498 brcms_err(wl->wlc->hw->d11core,
499 "%s: Attempt to add type %d, only STA, AP and AdHoc for now\n",
500 __func__, vif->type);
504 spin_lock_bh(&wl->lock);
506 brcms_c_mute(wl->wlc, false);
507 if (vif->type == NL80211_IFTYPE_STATION)
508 brcms_c_start_station(wl->wlc, vif->addr);
509 else if (vif->type == NL80211_IFTYPE_AP)
510 brcms_c_start_ap(wl->wlc, vif->addr, vif->bss_conf.bssid,
511 vif->bss_conf.ssid, vif->bss_conf.ssid_len);
512 else if (vif->type == NL80211_IFTYPE_ADHOC)
513 brcms_c_start_adhoc(wl->wlc, vif->addr);
514 spin_unlock_bh(&wl->lock);
520 brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
524 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
526 struct ieee80211_conf *conf = &hw->conf;
527 struct brcms_info *wl = hw->priv;
528 struct bcma_device *core = wl->wlc->hw->d11core;
532 spin_lock_bh(&wl->lock);
533 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
534 brcms_c_set_beacon_listen_interval(wl->wlc,
535 conf->listen_interval);
537 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
538 brcms_dbg_info(core, "%s: change monitor mode: %s\n",
539 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
541 if (changed & IEEE80211_CONF_CHANGE_PS)
542 brcms_err(core, "%s: change power-save mode: %s (implement)\n",
543 __func__, conf->flags & IEEE80211_CONF_PS ?
546 if (changed & IEEE80211_CONF_CHANGE_POWER) {
547 err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
549 brcms_err(core, "%s: Error setting power_level\n",
553 new_int = brcms_c_get_tx_power(wl->wlc);
554 if (new_int != conf->power_level)
556 "%s: Power level req != actual, %d %d\n",
557 __func__, conf->power_level,
560 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
561 if (conf->chandef.width == NL80211_CHAN_WIDTH_20 ||
562 conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
563 err = brcms_c_set_channel(wl->wlc,
564 conf->chandef.chan->hw_value);
568 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
569 err = brcms_c_set_rate_limit(wl->wlc,
570 conf->short_frame_max_tx_count,
571 conf->long_frame_max_tx_count);
574 spin_unlock_bh(&wl->lock);
579 brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
580 struct ieee80211_vif *vif,
581 struct ieee80211_bss_conf *info, u32 changed)
583 struct brcms_info *wl = hw->priv;
584 struct bcma_device *core = wl->wlc->hw->d11core;
586 if (changed & BSS_CHANGED_ASSOC) {
587 /* association status changed (associated/disassociated)
588 * also implies a change in the AID.
590 brcms_err(core, "%s: %s: %sassociated\n", KBUILD_MODNAME,
591 __func__, info->assoc ? "" : "dis");
592 spin_lock_bh(&wl->lock);
593 brcms_c_associate_upd(wl->wlc, info->assoc);
594 spin_unlock_bh(&wl->lock);
596 if (changed & BSS_CHANGED_ERP_SLOT) {
599 /* slot timing changed */
600 if (info->use_short_slot)
604 spin_lock_bh(&wl->lock);
605 brcms_c_set_shortslot_override(wl->wlc, val);
606 spin_unlock_bh(&wl->lock);
609 if (changed & BSS_CHANGED_HT) {
610 /* 802.11n parameters changed */
611 u16 mode = info->ht_operation_mode;
613 spin_lock_bh(&wl->lock);
614 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
615 mode & IEEE80211_HT_OP_MODE_PROTECTION);
616 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
617 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
618 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
619 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
620 spin_unlock_bh(&wl->lock);
622 if (changed & BSS_CHANGED_BASIC_RATES) {
623 struct ieee80211_supported_band *bi;
626 struct brcm_rateset rs;
629 /* retrieve the current rates */
630 spin_lock_bh(&wl->lock);
631 brcms_c_get_current_rateset(wl->wlc, &rs);
632 spin_unlock_bh(&wl->lock);
634 br_mask = info->basic_rates;
635 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
636 for (i = 0; i < bi->n_bitrates; i++) {
637 /* convert to internal rate value */
638 rate = (bi->bitrates[i].bitrate << 1) / 10;
640 /* set/clear basic rate flag */
641 brcms_set_basic_rate(&rs, rate, br_mask & 1);
645 /* update the rate set */
646 spin_lock_bh(&wl->lock);
647 error = brcms_c_set_rateset(wl->wlc, &rs);
648 spin_unlock_bh(&wl->lock);
650 brcms_err(core, "changing basic rates failed: %d\n",
653 if (changed & BSS_CHANGED_BEACON_INT) {
654 /* Beacon interval changed */
655 spin_lock_bh(&wl->lock);
656 brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
657 spin_unlock_bh(&wl->lock);
659 if (changed & BSS_CHANGED_BSSID) {
660 /* BSSID changed, for whatever reason (IBSS and managed mode) */
661 spin_lock_bh(&wl->lock);
662 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
663 spin_unlock_bh(&wl->lock);
665 if (changed & BSS_CHANGED_SSID) {
666 /* BSSID changed, for whatever reason (IBSS and managed mode) */
667 spin_lock_bh(&wl->lock);
668 brcms_c_set_ssid(wl->wlc, info->ssid, info->ssid_len);
669 spin_unlock_bh(&wl->lock);
671 if (changed & BSS_CHANGED_BEACON) {
672 /* Beacon data changed, retrieve new beacon (beaconing modes) */
673 struct sk_buff *beacon;
676 spin_lock_bh(&wl->lock);
677 beacon = ieee80211_beacon_get_tim(hw, vif, &tim_offset, NULL);
678 brcms_c_set_new_beacon(wl->wlc, beacon, tim_offset,
680 spin_unlock_bh(&wl->lock);
683 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
684 struct sk_buff *probe_resp;
686 spin_lock_bh(&wl->lock);
687 probe_resp = ieee80211_proberesp_get(hw, vif);
688 brcms_c_set_new_probe_resp(wl->wlc, probe_resp);
689 spin_unlock_bh(&wl->lock);
692 if (changed & BSS_CHANGED_BEACON_ENABLED) {
693 /* Beaconing should be enabled/disabled (beaconing modes) */
694 brcms_err(core, "%s: Beacon enabled: %s\n", __func__,
695 info->enable_beacon ? "true" : "false");
696 if (info->enable_beacon &&
697 hw->wiphy->flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) {
698 brcms_c_enable_probe_resp(wl->wlc, true);
700 brcms_c_enable_probe_resp(wl->wlc, false);
704 if (changed & BSS_CHANGED_CQM) {
705 /* Connection quality monitor config changed */
706 brcms_err(core, "%s: cqm change: threshold %d, hys %d "
707 " (implement)\n", __func__, info->cqm_rssi_thold,
708 info->cqm_rssi_hyst);
711 if (changed & BSS_CHANGED_IBSS) {
712 /* IBSS join status changed */
713 brcms_err(core, "%s: IBSS joined: %s (implement)\n",
714 __func__, info->ibss_joined ? "true" : "false");
717 if (changed & BSS_CHANGED_ARP_FILTER) {
718 /* Hardware ARP filter address list or state changed */
719 brcms_err(core, "%s: arp filtering: %d addresses"
720 " (implement)\n", __func__, info->arp_addr_cnt);
723 if (changed & BSS_CHANGED_QOS) {
725 * QoS for this association was enabled/disabled.
726 * Note that it is only ever disabled for station mode.
728 brcms_err(core, "%s: qos enabled: %s (implement)\n",
729 __func__, info->qos ? "true" : "false");
735 brcms_ops_configure_filter(struct ieee80211_hw *hw,
736 unsigned int changed_flags,
737 unsigned int *total_flags, u64 multicast)
739 struct brcms_info *wl = hw->priv;
740 struct bcma_device *core = wl->wlc->hw->d11core;
742 changed_flags &= MAC_FILTERS;
743 *total_flags &= MAC_FILTERS;
745 if (changed_flags & FIF_ALLMULTI)
746 brcms_dbg_info(core, "FIF_ALLMULTI\n");
747 if (changed_flags & FIF_FCSFAIL)
748 brcms_dbg_info(core, "FIF_FCSFAIL\n");
749 if (changed_flags & FIF_CONTROL)
750 brcms_dbg_info(core, "FIF_CONTROL\n");
751 if (changed_flags & FIF_OTHER_BSS)
752 brcms_dbg_info(core, "FIF_OTHER_BSS\n");
753 if (changed_flags & FIF_PSPOLL)
754 brcms_dbg_info(core, "FIF_PSPOLL\n");
755 if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
756 brcms_dbg_info(core, "FIF_BCN_PRBRESP_PROMISC\n");
758 spin_lock_bh(&wl->lock);
759 brcms_c_mac_promisc(wl->wlc, *total_flags);
760 spin_unlock_bh(&wl->lock);
764 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw,
765 struct ieee80211_vif *vif,
768 struct brcms_info *wl = hw->priv;
769 spin_lock_bh(&wl->lock);
770 brcms_c_scan_start(wl->wlc);
771 spin_unlock_bh(&wl->lock);
775 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw,
776 struct ieee80211_vif *vif)
778 struct brcms_info *wl = hw->priv;
779 spin_lock_bh(&wl->lock);
780 brcms_c_scan_stop(wl->wlc);
781 spin_unlock_bh(&wl->lock);
786 brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
787 const struct ieee80211_tx_queue_params *params)
789 struct brcms_info *wl = hw->priv;
791 spin_lock_bh(&wl->lock);
792 brcms_c_wme_setparams(wl->wlc, queue, params, true);
793 spin_unlock_bh(&wl->lock);
799 brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
800 struct ieee80211_sta *sta)
802 struct brcms_info *wl = hw->priv;
803 struct scb *scb = &wl->wlc->pri_scb;
805 brcms_c_init_scb(scb);
807 wl->pub->global_ampdu = &(scb->scb_ampdu);
808 wl->pub->global_ampdu->scb = scb;
809 wl->pub->global_ampdu->max_pdu = 16;
812 * minstrel_ht initiates addBA on our behalf by calling
813 * ieee80211_start_tx_ba_session()
819 brcms_ops_ampdu_action(struct ieee80211_hw *hw,
820 struct ieee80211_vif *vif,
821 enum ieee80211_ampdu_mlme_action action,
822 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
823 u8 buf_size, bool amsdu)
825 struct brcms_info *wl = hw->priv;
826 struct scb *scb = &wl->wlc->pri_scb;
829 if (WARN_ON(scb->magic != SCB_MAGIC))
832 case IEEE80211_AMPDU_RX_START:
834 case IEEE80211_AMPDU_RX_STOP:
836 case IEEE80211_AMPDU_TX_START:
837 spin_lock_bh(&wl->lock);
838 status = brcms_c_aggregatable(wl->wlc, tid);
839 spin_unlock_bh(&wl->lock);
841 brcms_err(wl->wlc->hw->d11core,
842 "START: tid %d is not agg\'able\n", tid);
845 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
848 case IEEE80211_AMPDU_TX_STOP_CONT:
849 case IEEE80211_AMPDU_TX_STOP_FLUSH:
850 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
851 spin_lock_bh(&wl->lock);
852 brcms_c_ampdu_flush(wl->wlc, sta, tid);
853 spin_unlock_bh(&wl->lock);
854 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
856 case IEEE80211_AMPDU_TX_OPERATIONAL:
858 * BA window size from ADDBA response ('buf_size') defines how
859 * many outstanding MPDUs are allowed for the BA stream by
860 * recipient and traffic class. 'ampdu_factor' gives maximum
863 spin_lock_bh(&wl->lock);
864 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
865 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
866 sta->ht_cap.ampdu_factor)) - 1);
867 spin_unlock_bh(&wl->lock);
868 /* Power save wakeup */
871 brcms_err(wl->wlc->hw->d11core,
872 "%s: Invalid command, ignoring\n", __func__);
878 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
880 struct brcms_info *wl = hw->priv;
883 spin_lock_bh(&wl->lock);
884 blocked = brcms_c_check_radio_disabled(wl->wlc);
885 spin_unlock_bh(&wl->lock);
887 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
890 static bool brcms_tx_flush_completed(struct brcms_info *wl)
894 spin_lock_bh(&wl->lock);
895 result = brcms_c_tx_flush_completed(wl->wlc);
896 spin_unlock_bh(&wl->lock);
900 static void brcms_ops_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
901 u32 queues, bool drop)
903 struct brcms_info *wl = hw->priv;
906 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
908 ret = wait_event_timeout(wl->tx_flush_wq,
909 brcms_tx_flush_completed(wl),
910 msecs_to_jiffies(BRCMS_FLUSH_TIMEOUT));
912 brcms_dbg_mac80211(wl->wlc->hw->d11core,
913 "ret=%d\n", jiffies_to_msecs(ret));
916 static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
918 struct brcms_info *wl = hw->priv;
921 spin_lock_bh(&wl->lock);
922 tsf = brcms_c_tsf_get(wl->wlc);
923 spin_unlock_bh(&wl->lock);
928 static void brcms_ops_set_tsf(struct ieee80211_hw *hw,
929 struct ieee80211_vif *vif, u64 tsf)
931 struct brcms_info *wl = hw->priv;
933 spin_lock_bh(&wl->lock);
934 brcms_c_tsf_set(wl->wlc, tsf);
935 spin_unlock_bh(&wl->lock);
938 static const struct ieee80211_ops brcms_ops = {
940 .start = brcms_ops_start,
941 .stop = brcms_ops_stop,
942 .add_interface = brcms_ops_add_interface,
943 .remove_interface = brcms_ops_remove_interface,
944 .config = brcms_ops_config,
945 .bss_info_changed = brcms_ops_bss_info_changed,
946 .configure_filter = brcms_ops_configure_filter,
947 .sw_scan_start = brcms_ops_sw_scan_start,
948 .sw_scan_complete = brcms_ops_sw_scan_complete,
949 .conf_tx = brcms_ops_conf_tx,
950 .sta_add = brcms_ops_sta_add,
951 .ampdu_action = brcms_ops_ampdu_action,
952 .rfkill_poll = brcms_ops_rfkill_poll,
953 .flush = brcms_ops_flush,
954 .get_tsf = brcms_ops_get_tsf,
955 .set_tsf = brcms_ops_set_tsf,
958 void brcms_dpc(unsigned long data)
960 struct brcms_info *wl;
962 wl = (struct brcms_info *) data;
964 spin_lock_bh(&wl->lock);
966 /* call the common second level interrupt handler */
971 spin_lock_irqsave(&wl->isr_lock, flags);
972 brcms_c_intrsupd(wl->wlc);
973 spin_unlock_irqrestore(&wl->isr_lock, flags);
976 wl->resched = brcms_c_dpc(wl->wlc, true);
979 /* brcms_c_dpc() may bring the driver down */
983 /* re-schedule dpc */
985 tasklet_schedule(&wl->tasklet);
987 /* re-enable interrupts */
991 spin_unlock_bh(&wl->lock);
992 wake_up(&wl->tx_flush_wq);
995 static irqreturn_t brcms_isr(int irq, void *dev_id)
997 struct brcms_info *wl;
998 irqreturn_t ret = IRQ_NONE;
1000 wl = (struct brcms_info *) dev_id;
1002 spin_lock(&wl->isr_lock);
1004 /* call common first level interrupt handler */
1005 if (brcms_c_isr(wl->wlc)) {
1006 /* schedule second level handler */
1007 tasklet_schedule(&wl->tasklet);
1011 spin_unlock(&wl->isr_lock);
1017 * is called in brcms_pci_probe() context, therefore no locking required.
1019 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1021 struct brcms_info *wl = hw->priv;
1022 struct brcms_c_info *wlc = wl->wlc;
1023 struct ieee80211_supported_band *band;
1027 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
1028 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1030 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
1031 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
1032 band = &wlc->bandstate[BAND_2G_INDEX]->band;
1033 *band = brcms_band_2GHz_nphy_template;
1034 if (phy_type == PHY_TYPE_LCN) {
1036 band->ht_cap.mcs.rx_mask[1] = 0;
1037 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
1039 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
1044 /* Assume all bands use the same phy. True for 11n devices. */
1045 if (wl->pub->_nbands > 1) {
1047 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
1048 band = &wlc->bandstate[BAND_5G_INDEX]->band;
1049 *band = brcms_band_5GHz_nphy_template;
1050 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
1059 * is called in brcms_pci_probe() context, therefore no locking required.
1061 static int ieee_hw_init(struct ieee80211_hw *hw)
1063 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
1064 ieee80211_hw_set(hw, SIGNAL_DBM);
1065 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
1067 hw->extra_tx_headroom = brcms_c_get_header_len();
1068 hw->queues = N_TX_QUEUES;
1069 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1071 /* channel change time is dependent on chip and band */
1072 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1073 BIT(NL80211_IFTYPE_AP) |
1074 BIT(NL80211_IFTYPE_ADHOC);
1077 * deactivate sending probe responses by ucude, because this will
1078 * cause problems when WPS is used.
1080 * hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1083 hw->rate_control_algorithm = "minstrel_ht";
1085 hw->sta_data_size = 0;
1086 return ieee_hw_rate_init(hw);
1090 * attach to the WL device.
1092 * Attach to the WL device identified by vendor and device parameters.
1093 * regs is a host accessible memory address pointing to WL device registers.
1095 * is called in brcms_bcma_probe() context, therefore no locking required.
1097 static struct brcms_info *brcms_attach(struct bcma_device *pdev)
1099 struct brcms_info *wl = NULL;
1101 struct ieee80211_hw *hw;
1104 unit = n_adapters_found;
1110 /* allocate private info */
1111 hw = bcma_get_drvdata(pdev);
1114 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1116 wl->wiphy = hw->wiphy;
1118 atomic_set(&wl->callbacks, 0);
1120 init_waitqueue_head(&wl->tx_flush_wq);
1122 /* setup the bottom half handler */
1123 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1125 spin_lock_init(&wl->lock);
1126 spin_lock_init(&wl->isr_lock);
1128 /* common load-time initialization */
1129 wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
1131 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1132 KBUILD_MODNAME, err);
1135 wl->pub = brcms_c_pub(wl->wlc);
1137 wl->pub->ieee_hw = hw;
1139 /* register our interrupt handler */
1140 if (request_irq(pdev->irq, brcms_isr,
1141 IRQF_SHARED, KBUILD_MODNAME, wl)) {
1142 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1145 wl->irq = pdev->irq;
1147 /* register module */
1148 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1150 if (ieee_hw_init(hw)) {
1151 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1156 brcms_c_regd_init(wl->wlc);
1158 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1159 if (WARN_ON(!is_valid_ether_addr(perm)))
1161 SET_IEEE80211_PERM_ADDR(hw, perm);
1163 err = ieee80211_register_hw(hw);
1165 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1166 "%d\n", __func__, err);
1168 if (wl->pub->srom_ccode[0] &&
1169 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1170 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
1172 brcms_debugfs_attach(wl->pub);
1173 brcms_debugfs_create_files(wl->pub);
1185 * determines if a device is a WL device, and if so, attaches it.
1187 * This function determines if a device pointed to by pdev is a WL device,
1188 * and if so, performs a brcms_attach() on it.
1190 * Perimeter lock is initialized in the course of this function.
1192 static int brcms_bcma_probe(struct bcma_device *pdev)
1194 struct brcms_info *wl;
1195 struct ieee80211_hw *hw;
1197 dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
1198 pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
1201 if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
1202 (pdev->id.id != BCMA_CORE_80211))
1205 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1207 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1211 SET_IEEE80211_DEV(hw, &pdev->dev);
1213 bcma_set_drvdata(pdev, hw);
1215 memset(hw->priv, 0, sizeof(*wl));
1217 wl = brcms_attach(pdev);
1219 pr_err("%s: brcms_attach failed!\n", __func__);
1222 brcms_led_register(wl);
1227 static int brcms_suspend(struct bcma_device *pdev)
1229 struct brcms_info *wl;
1230 struct ieee80211_hw *hw;
1232 hw = bcma_get_drvdata(pdev);
1235 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
1240 /* only need to flag hw is down for proper resume */
1241 spin_lock_bh(&wl->lock);
1242 wl->pub->hw_up = false;
1243 spin_unlock_bh(&wl->lock);
1245 brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
1250 static int brcms_resume(struct bcma_device *pdev)
1255 static struct bcma_driver brcms_bcma_driver = {
1256 .name = KBUILD_MODNAME,
1257 .probe = brcms_bcma_probe,
1258 .suspend = brcms_suspend,
1259 .resume = brcms_resume,
1260 .remove = brcms_remove,
1261 .id_table = brcms_coreid_table,
1265 * This is the main entry point for the brcmsmac driver.
1267 * This function is scheduled upon module initialization and
1268 * does the driver registration, which result in brcms_bcma_probe()
1269 * call resulting in the driver bringup.
1271 static void brcms_driver_init(struct work_struct *work)
1275 error = bcma_driver_register(&brcms_bcma_driver);
1277 pr_err("%s: register returned %d\n", __func__, error);
1280 static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
1282 static int __init brcms_module_init(void)
1284 brcms_debugfs_init();
1285 if (!schedule_work(&brcms_driver_work))
1292 * This function unloads the brcmsmac driver from the system.
1294 * This function unconditionally unloads the brcmsmac driver module from the
1298 static void __exit brcms_module_exit(void)
1300 cancel_work_sync(&brcms_driver_work);
1301 bcma_driver_unregister(&brcms_bcma_driver);
1302 brcms_debugfs_exit();
1305 module_init(brcms_module_init);
1306 module_exit(brcms_module_exit);
1309 * precondition: perimeter lock has been acquired
1311 void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1312 bool state, int prio)
1314 brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
1318 * precondition: perimeter lock has been acquired
1320 void brcms_init(struct brcms_info *wl)
1322 brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
1325 brcms_c_init(wl->wlc, wl->mute_tx);
1329 * precondition: perimeter lock has been acquired
1331 uint brcms_reset(struct brcms_info *wl)
1333 brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
1334 brcms_c_reset(wl->wlc);
1336 /* dpc will not be rescheduled */
1337 wl->resched = false;
1339 /* inform publicly that interface is down */
1340 wl->pub->up = false;
1345 void brcms_fatal_error(struct brcms_info *wl)
1347 brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
1348 wl->wlc->pub->unit);
1350 ieee80211_restart_hw(wl->pub->ieee_hw);
1354 * These are interrupt on/off entry points. Disable interrupts
1355 * during interrupt state transition.
1357 void brcms_intrson(struct brcms_info *wl)
1359 unsigned long flags;
1361 spin_lock_irqsave(&wl->isr_lock, flags);
1362 brcms_c_intrson(wl->wlc);
1363 spin_unlock_irqrestore(&wl->isr_lock, flags);
1366 u32 brcms_intrsoff(struct brcms_info *wl)
1368 unsigned long flags;
1371 spin_lock_irqsave(&wl->isr_lock, flags);
1372 status = brcms_c_intrsoff(wl->wlc);
1373 spin_unlock_irqrestore(&wl->isr_lock, flags);
1377 void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1379 unsigned long flags;
1381 spin_lock_irqsave(&wl->isr_lock, flags);
1382 brcms_c_intrsrestore(wl->wlc, macintmask);
1383 spin_unlock_irqrestore(&wl->isr_lock, flags);
1387 * precondition: perimeter lock has been acquired
1389 int brcms_up(struct brcms_info *wl)
1396 error = brcms_c_up(wl->wlc);
1402 * precondition: perimeter lock has been acquired
1404 void brcms_down(struct brcms_info *wl)
1406 uint callbacks, ret_val = 0;
1408 /* call common down function */
1409 ret_val = brcms_c_down(wl->wlc);
1410 callbacks = atomic_read(&wl->callbacks) - ret_val;
1412 /* wait for down callbacks to complete */
1413 spin_unlock_bh(&wl->lock);
1415 /* For HIGH_only driver, it's important to actually schedule other work,
1416 * not just spin wait since everything runs at schedule level
1418 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1420 spin_lock_bh(&wl->lock);
1424 * precondition: perimeter lock is not acquired
1426 static void _brcms_timer(struct work_struct *work)
1428 struct brcms_timer *t = container_of(work, struct brcms_timer,
1431 spin_lock_bh(&t->wl->lock);
1435 atomic_inc(&t->wl->callbacks);
1436 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1438 msecs_to_jiffies(t->ms));
1446 atomic_dec(&t->wl->callbacks);
1448 spin_unlock_bh(&t->wl->lock);
1452 * Adds a timer to the list. Caller supplies a timer function.
1453 * Is called from wlc.
1455 * precondition: perimeter lock has been acquired
1457 struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1458 void (*fn) (void *arg),
1459 void *arg, const char *name)
1461 struct brcms_timer *t;
1463 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1467 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
1471 t->next = wl->timers;
1475 t->name = kstrdup(name, GFP_ATOMIC);
1482 * adds only the kernel timer since it's going to be more accurate
1483 * as well as it's easier to make it periodic
1485 * precondition: perimeter lock has been acquired
1487 void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
1489 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1493 brcms_dbg_info(t->wl->wlc->hw->d11core,
1494 "%s: Already set. Name: %s, per %d\n",
1495 __func__, t->name, periodic);
1498 t->periodic = (bool) periodic;
1501 atomic_inc(&t->wl->callbacks);
1504 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
1508 * return true if timer successfully deleted, false if still pending
1510 * precondition: perimeter lock has been acquired
1512 bool brcms_del_timer(struct brcms_timer *t)
1516 if (!cancel_delayed_work(&t->dly_wrk))
1519 atomic_dec(&t->wl->callbacks);
1526 * precondition: perimeter lock has been acquired
1528 void brcms_free_timer(struct brcms_timer *t)
1530 struct brcms_info *wl = t->wl;
1531 struct brcms_timer *tmp;
1533 /* delete the timer in case it is active */
1536 if (wl->timers == t) {
1537 wl->timers = wl->timers->next;
1548 if (tmp->next == t) {
1549 tmp->next = t->next;
1562 * precondition: perimeter lock has been acquired
1564 int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1568 struct firmware_hdr *hdr;
1569 for (i = 0; i < wl->fw.fw_cnt; i++) {
1570 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1571 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1573 u32 len = le32_to_cpu(hdr->len);
1574 if (le32_to_cpu(hdr->idx) == idx) {
1575 pdata = wl->fw.fw_bin[i]->data +
1576 le32_to_cpu(hdr->offset);
1577 *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
1585 brcms_err(wl->wlc->hw->d11core,
1586 "ERROR: ucode buf tag:%d can not be found!\n", idx);
1593 * Precondition: Since this function is called in brcms_bcma_probe() context,
1594 * no locking is required.
1596 int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1600 struct firmware_hdr *hdr;
1601 for (i = 0; i < wl->fw.fw_cnt; i++) {
1602 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1603 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1605 if (le32_to_cpu(hdr->idx) == idx) {
1606 pdata = wl->fw.fw_bin[i]->data +
1607 le32_to_cpu(hdr->offset);
1608 if (le32_to_cpu(hdr->len) != 4) {
1609 brcms_err(wl->wlc->hw->d11core,
1610 "ERROR: fw hdr len\n");
1613 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1618 brcms_err(wl->wlc->hw->d11core,
1619 "ERROR: ucode tag:%d can not be found!\n", idx);
1624 * precondition: can both be called locked and unlocked
1626 void brcms_ucode_free_buf(void *p)
1632 * checks validity of all firmware images loaded from user space
1634 * Precondition: Since this function is called in brcms_bcma_probe() context,
1635 * no locking is required.
1637 int brcms_check_firmwares(struct brcms_info *wl)
1642 const struct firmware *fw;
1643 const struct firmware *fw_hdr;
1644 struct firmware_hdr *ucode_hdr;
1645 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1646 fw = wl->fw.fw_bin[i];
1647 fw_hdr = wl->fw.fw_hdr[i];
1648 if (fw == NULL && fw_hdr == NULL) {
1650 } else if (fw == NULL || fw_hdr == NULL) {
1651 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1654 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1655 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1656 "size %zu/%zu\n", __func__, fw_hdr->size,
1657 sizeof(struct firmware_hdr));
1659 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1660 wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
1661 __func__, fw->size);
1664 /* check if ucode section overruns firmware image */
1665 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1666 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1667 !rc; entry++, ucode_hdr++) {
1668 if (le32_to_cpu(ucode_hdr->offset) +
1669 le32_to_cpu(ucode_hdr->len) >
1671 wiphy_err(wl->wiphy,
1672 "%s: conflicting bin/hdr\n",
1679 if (rc == 0 && wl->fw.fw_cnt != i) {
1680 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1688 * precondition: perimeter lock has been acquired
1690 bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1692 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1694 spin_unlock_bh(&wl->lock);
1695 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1697 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1698 spin_lock_bh(&wl->lock);