2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #define __UNDEF_NO_VERSION__
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/etherdevice.h>
21 #include <linux/sched.h>
22 #include <linux/firmware.h>
23 #include <linux/interrupt.h>
24 #include <linux/module.h>
25 #include <linux/bcma/bcma.h>
26 #include <net/mac80211.h>
28 #include "phy/phy_int.h"
33 #include "ucode_loader.h"
34 #include "mac80211_if.h"
39 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
40 #define BRCMS_FLUSH_TIMEOUT 500 /* msec */
42 /* Flags we support */
43 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
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_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
128 IEEE80211_CHAN_NO_HT40PLUS),
130 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
131 IEEE80211_CHAN_NO_HT40PLUS),
133 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
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 | IEEE80211_CHAN_NO_IBSS |
147 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
149 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
150 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
152 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
153 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
155 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
156 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
159 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
160 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
162 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
163 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
165 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
166 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
168 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
169 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
171 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
172 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
174 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
175 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
177 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
178 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
180 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
181 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
183 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
184 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
186 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
187 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
189 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
190 IEEE80211_CHAN_PASSIVE_SCAN | 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;
278 static void brcms_ops_tx(struct ieee80211_hw *hw,
279 struct ieee80211_tx_control *control,
282 struct brcms_info *wl = hw->priv;
283 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
285 spin_lock_bh(&wl->lock);
287 brcms_err(wl->wlc->hw->d11core, "ops->tx called while down\n");
291 if (brcms_c_sendpkt_mac80211(wl->wlc, skb, hw))
292 tx_info->rate_driver_data[0] = control->sta;
294 spin_unlock_bh(&wl->lock);
297 static int brcms_ops_start(struct ieee80211_hw *hw)
299 struct brcms_info *wl = hw->priv;
303 ieee80211_wake_queues(hw);
304 spin_lock_bh(&wl->lock);
305 blocked = brcms_rfkill_set_hw_state(wl);
306 spin_unlock_bh(&wl->lock);
308 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
310 spin_lock_bh(&wl->lock);
311 /* avoid acknowledging frames before a non-monitor device is added */
321 spin_unlock_bh(&wl->lock);
324 brcms_err(wl->wlc->hw->d11core, "%s: brcms_up() returned %d\n",
329 static void brcms_ops_stop(struct ieee80211_hw *hw)
331 struct brcms_info *wl = hw->priv;
334 ieee80211_stop_queues(hw);
339 spin_lock_bh(&wl->lock);
340 status = brcms_c_chipmatch(wl->wlc->hw->d11core);
341 spin_unlock_bh(&wl->lock);
343 brcms_err(wl->wlc->hw->d11core,
344 "wl: brcms_ops_stop: chipmatch failed\n");
348 /* put driver in down state */
349 spin_lock_bh(&wl->lock);
351 spin_unlock_bh(&wl->lock);
355 brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
357 struct brcms_info *wl = hw->priv;
359 /* Just STA for now */
360 if (vif->type != NL80211_IFTYPE_STATION) {
361 brcms_err(wl->wlc->hw->d11core,
362 "%s: Attempt to add type %d, only STA for now\n",
363 __func__, vif->type);
367 spin_lock_bh(&wl->lock);
368 memcpy(wl->pub->cur_etheraddr, vif->addr, sizeof(vif->addr));
370 brcms_c_mute(wl->wlc, false);
371 spin_unlock_bh(&wl->lock);
377 brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
381 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
383 struct ieee80211_conf *conf = &hw->conf;
384 struct brcms_info *wl = hw->priv;
385 struct bcma_device *core = wl->wlc->hw->d11core;
389 spin_lock_bh(&wl->lock);
390 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
391 brcms_c_set_beacon_listen_interval(wl->wlc,
392 conf->listen_interval);
394 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
395 brcms_dbg_info(core, "%s: change monitor mode: %s\n",
396 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
398 if (changed & IEEE80211_CONF_CHANGE_PS)
399 brcms_err(core, "%s: change power-save mode: %s (implement)\n",
400 __func__, conf->flags & IEEE80211_CONF_PS ?
403 if (changed & IEEE80211_CONF_CHANGE_POWER) {
404 err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
406 brcms_err(core, "%s: Error setting power_level\n",
410 new_int = brcms_c_get_tx_power(wl->wlc);
411 if (new_int != conf->power_level)
413 "%s: Power level req != actual, %d %d\n",
414 __func__, conf->power_level,
417 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
418 if (conf->channel_type == NL80211_CHAN_HT20 ||
419 conf->channel_type == NL80211_CHAN_NO_HT)
420 err = brcms_c_set_channel(wl->wlc,
421 conf->channel->hw_value);
425 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
426 err = brcms_c_set_rate_limit(wl->wlc,
427 conf->short_frame_max_tx_count,
428 conf->long_frame_max_tx_count);
431 spin_unlock_bh(&wl->lock);
436 brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
437 struct ieee80211_vif *vif,
438 struct ieee80211_bss_conf *info, u32 changed)
440 struct brcms_info *wl = hw->priv;
441 struct bcma_device *core = wl->wlc->hw->d11core;
443 if (changed & BSS_CHANGED_ASSOC) {
444 /* association status changed (associated/disassociated)
445 * also implies a change in the AID.
447 brcms_err(core, "%s: %s: %sassociated\n", KBUILD_MODNAME,
448 __func__, info->assoc ? "" : "dis");
449 spin_lock_bh(&wl->lock);
450 brcms_c_associate_upd(wl->wlc, info->assoc);
451 spin_unlock_bh(&wl->lock);
453 if (changed & BSS_CHANGED_ERP_SLOT) {
456 /* slot timing changed */
457 if (info->use_short_slot)
461 spin_lock_bh(&wl->lock);
462 brcms_c_set_shortslot_override(wl->wlc, val);
463 spin_unlock_bh(&wl->lock);
466 if (changed & BSS_CHANGED_HT) {
467 /* 802.11n parameters changed */
468 u16 mode = info->ht_operation_mode;
470 spin_lock_bh(&wl->lock);
471 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
472 mode & IEEE80211_HT_OP_MODE_PROTECTION);
473 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
474 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
475 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
476 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
477 spin_unlock_bh(&wl->lock);
479 if (changed & BSS_CHANGED_BASIC_RATES) {
480 struct ieee80211_supported_band *bi;
483 struct brcm_rateset rs;
486 /* retrieve the current rates */
487 spin_lock_bh(&wl->lock);
488 brcms_c_get_current_rateset(wl->wlc, &rs);
489 spin_unlock_bh(&wl->lock);
491 br_mask = info->basic_rates;
492 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
493 for (i = 0; i < bi->n_bitrates; i++) {
494 /* convert to internal rate value */
495 rate = (bi->bitrates[i].bitrate << 1) / 10;
497 /* set/clear basic rate flag */
498 brcms_set_basic_rate(&rs, rate, br_mask & 1);
502 /* update the rate set */
503 spin_lock_bh(&wl->lock);
504 error = brcms_c_set_rateset(wl->wlc, &rs);
505 spin_unlock_bh(&wl->lock);
507 brcms_err(core, "changing basic rates failed: %d\n",
510 if (changed & BSS_CHANGED_BEACON_INT) {
511 /* Beacon interval changed */
512 spin_lock_bh(&wl->lock);
513 brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
514 spin_unlock_bh(&wl->lock);
516 if (changed & BSS_CHANGED_BSSID) {
517 /* BSSID changed, for whatever reason (IBSS and managed mode) */
518 spin_lock_bh(&wl->lock);
519 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
520 spin_unlock_bh(&wl->lock);
522 if (changed & BSS_CHANGED_BEACON)
523 /* Beacon data changed, retrieve new beacon (beaconing modes) */
524 brcms_err(core, "%s: beacon changed\n", __func__);
526 if (changed & BSS_CHANGED_BEACON_ENABLED) {
527 /* Beaconing should be enabled/disabled (beaconing modes) */
528 brcms_err(core, "%s: Beacon enabled: %s\n", __func__,
529 info->enable_beacon ? "true" : "false");
532 if (changed & BSS_CHANGED_CQM) {
533 /* Connection quality monitor config changed */
534 brcms_err(core, "%s: cqm change: threshold %d, hys %d "
535 " (implement)\n", __func__, info->cqm_rssi_thold,
536 info->cqm_rssi_hyst);
539 if (changed & BSS_CHANGED_IBSS) {
540 /* IBSS join status changed */
541 brcms_err(core, "%s: IBSS joined: %s (implement)\n",
542 __func__, info->ibss_joined ? "true" : "false");
545 if (changed & BSS_CHANGED_ARP_FILTER) {
546 /* Hardware ARP filter address list or state changed */
547 brcms_err(core, "%s: arp filtering: %d addresses"
548 " (implement)\n", __func__, info->arp_addr_cnt);
551 if (changed & BSS_CHANGED_QOS) {
553 * QoS for this association was enabled/disabled.
554 * Note that it is only ever disabled for station mode.
556 brcms_err(core, "%s: qos enabled: %s (implement)\n",
557 __func__, info->qos ? "true" : "false");
563 brcms_ops_configure_filter(struct ieee80211_hw *hw,
564 unsigned int changed_flags,
565 unsigned int *total_flags, u64 multicast)
567 struct brcms_info *wl = hw->priv;
568 struct bcma_device *core = wl->wlc->hw->d11core;
570 changed_flags &= MAC_FILTERS;
571 *total_flags &= MAC_FILTERS;
573 if (changed_flags & FIF_PROMISC_IN_BSS)
574 brcms_dbg_info(core, "FIF_PROMISC_IN_BSS\n");
575 if (changed_flags & FIF_ALLMULTI)
576 brcms_dbg_info(core, "FIF_ALLMULTI\n");
577 if (changed_flags & FIF_FCSFAIL)
578 brcms_dbg_info(core, "FIF_FCSFAIL\n");
579 if (changed_flags & FIF_CONTROL)
580 brcms_dbg_info(core, "FIF_CONTROL\n");
581 if (changed_flags & FIF_OTHER_BSS)
582 brcms_dbg_info(core, "FIF_OTHER_BSS\n");
583 if (changed_flags & FIF_PSPOLL)
584 brcms_dbg_info(core, "FIF_PSPOLL\n");
585 if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
586 brcms_dbg_info(core, "FIF_BCN_PRBRESP_PROMISC\n");
588 spin_lock_bh(&wl->lock);
589 brcms_c_mac_promisc(wl->wlc, *total_flags);
590 spin_unlock_bh(&wl->lock);
594 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
596 struct brcms_info *wl = hw->priv;
597 spin_lock_bh(&wl->lock);
598 brcms_c_scan_start(wl->wlc);
599 spin_unlock_bh(&wl->lock);
603 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
605 struct brcms_info *wl = hw->priv;
606 spin_lock_bh(&wl->lock);
607 brcms_c_scan_stop(wl->wlc);
608 spin_unlock_bh(&wl->lock);
613 brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
614 const struct ieee80211_tx_queue_params *params)
616 struct brcms_info *wl = hw->priv;
618 spin_lock_bh(&wl->lock);
619 brcms_c_wme_setparams(wl->wlc, queue, params, true);
620 spin_unlock_bh(&wl->lock);
626 brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
627 struct ieee80211_sta *sta)
629 struct brcms_info *wl = hw->priv;
630 struct scb *scb = &wl->wlc->pri_scb;
632 brcms_c_init_scb(scb);
634 wl->pub->global_ampdu = &(scb->scb_ampdu);
635 wl->pub->global_ampdu->scb = scb;
636 wl->pub->global_ampdu->max_pdu = 16;
639 * minstrel_ht initiates addBA on our behalf by calling
640 * ieee80211_start_tx_ba_session()
646 brcms_ops_ampdu_action(struct ieee80211_hw *hw,
647 struct ieee80211_vif *vif,
648 enum ieee80211_ampdu_mlme_action action,
649 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
652 struct brcms_info *wl = hw->priv;
653 struct scb *scb = &wl->wlc->pri_scb;
656 if (WARN_ON(scb->magic != SCB_MAGIC))
659 case IEEE80211_AMPDU_RX_START:
661 case IEEE80211_AMPDU_RX_STOP:
663 case IEEE80211_AMPDU_TX_START:
664 spin_lock_bh(&wl->lock);
665 status = brcms_c_aggregatable(wl->wlc, tid);
666 spin_unlock_bh(&wl->lock);
668 brcms_err(wl->wlc->hw->d11core,
669 "START: tid %d is not agg\'able\n", tid);
672 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
675 case IEEE80211_AMPDU_TX_STOP_CONT:
676 case IEEE80211_AMPDU_TX_STOP_FLUSH:
677 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
678 spin_lock_bh(&wl->lock);
679 brcms_c_ampdu_flush(wl->wlc, sta, tid);
680 spin_unlock_bh(&wl->lock);
681 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
683 case IEEE80211_AMPDU_TX_OPERATIONAL:
685 * BA window size from ADDBA response ('buf_size') defines how
686 * many outstanding MPDUs are allowed for the BA stream by
687 * recipient and traffic class. 'ampdu_factor' gives maximum
690 spin_lock_bh(&wl->lock);
691 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
692 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
693 sta->ht_cap.ampdu_factor)) - 1);
694 spin_unlock_bh(&wl->lock);
695 /* Power save wakeup */
698 brcms_err(wl->wlc->hw->d11core,
699 "%s: Invalid command, ignoring\n", __func__);
705 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
707 struct brcms_info *wl = hw->priv;
710 spin_lock_bh(&wl->lock);
711 blocked = brcms_c_check_radio_disabled(wl->wlc);
712 spin_unlock_bh(&wl->lock);
714 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
717 static bool brcms_tx_flush_completed(struct brcms_info *wl)
721 spin_lock_bh(&wl->lock);
722 result = brcms_c_tx_flush_completed(wl->wlc);
723 spin_unlock_bh(&wl->lock);
727 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
729 struct brcms_info *wl = hw->priv;
732 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
734 ret = wait_event_timeout(wl->tx_flush_wq,
735 brcms_tx_flush_completed(wl),
736 msecs_to_jiffies(BRCMS_FLUSH_TIMEOUT));
738 brcms_dbg_mac80211(wl->wlc->hw->d11core,
739 "ret=%d\n", jiffies_to_msecs(ret));
742 static const struct ieee80211_ops brcms_ops = {
744 .start = brcms_ops_start,
745 .stop = brcms_ops_stop,
746 .add_interface = brcms_ops_add_interface,
747 .remove_interface = brcms_ops_remove_interface,
748 .config = brcms_ops_config,
749 .bss_info_changed = brcms_ops_bss_info_changed,
750 .configure_filter = brcms_ops_configure_filter,
751 .sw_scan_start = brcms_ops_sw_scan_start,
752 .sw_scan_complete = brcms_ops_sw_scan_complete,
753 .conf_tx = brcms_ops_conf_tx,
754 .sta_add = brcms_ops_sta_add,
755 .ampdu_action = brcms_ops_ampdu_action,
756 .rfkill_poll = brcms_ops_rfkill_poll,
757 .flush = brcms_ops_flush,
760 void brcms_dpc(unsigned long data)
762 struct brcms_info *wl;
764 wl = (struct brcms_info *) data;
766 spin_lock_bh(&wl->lock);
768 /* call the common second level interrupt handler */
773 spin_lock_irqsave(&wl->isr_lock, flags);
774 brcms_c_intrsupd(wl->wlc);
775 spin_unlock_irqrestore(&wl->isr_lock, flags);
778 wl->resched = brcms_c_dpc(wl->wlc, true);
781 /* brcms_c_dpc() may bring the driver down */
785 /* re-schedule dpc */
787 tasklet_schedule(&wl->tasklet);
789 /* re-enable interrupts */
793 spin_unlock_bh(&wl->lock);
794 wake_up(&wl->tx_flush_wq);
798 * Precondition: Since this function is called in brcms_pci_probe() context,
799 * no locking is required.
801 static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
804 struct device *device = &pdev->dev;
808 memset(&wl->fw, 0, sizeof(struct brcms_firmware));
809 for (i = 0; i < MAX_FW_IMAGES; i++) {
810 if (brcms_firmwares[i] == NULL)
812 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
813 UCODE_LOADER_API_VER);
814 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
816 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
817 KBUILD_MODNAME, fw_name);
820 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
821 UCODE_LOADER_API_VER);
822 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
824 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
825 KBUILD_MODNAME, fw_name);
828 wl->fw.hdr_num_entries[i] =
829 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
832 return brcms_ucode_data_init(wl, &wl->ucode);
836 * Precondition: Since this function is called in brcms_pci_probe() context,
837 * no locking is required.
839 static void brcms_release_fw(struct brcms_info *wl)
842 for (i = 0; i < MAX_FW_IMAGES; i++) {
843 release_firmware(wl->fw.fw_bin[i]);
844 release_firmware(wl->fw.fw_hdr[i]);
849 * This function frees the WL per-device resources.
851 * This function frees resources owned by the WL device pointed to
852 * by the wl parameter.
854 * precondition: can both be called locked and unlocked
857 static void brcms_free(struct brcms_info *wl)
859 struct brcms_timer *t, *next;
861 /* free ucode data */
863 brcms_ucode_data_free(&wl->ucode);
865 free_irq(wl->irq, wl);
868 tasklet_kill(&wl->tasklet);
871 brcms_debugfs_detach(wl->pub);
872 brcms_c_module_unregister(wl->pub, "linux", wl);
875 /* free common resources */
877 brcms_c_detach(wl->wlc);
882 /* virtual interface deletion is deferred so we cannot spinwait */
884 /* wait for all pending callbacks to complete */
885 while (atomic_read(&wl->callbacks) > 0)
889 for (t = wl->timers; t; t = next) {
899 * called from both kernel as from this kernel module (error flow on attach)
900 * precondition: perimeter lock is not acquired.
902 static void brcms_remove(struct bcma_device *pdev)
904 struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
905 struct brcms_info *wl = hw->priv;
908 brcms_led_unregister(wl);
909 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
910 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
911 ieee80211_unregister_hw(hw);
916 bcma_set_drvdata(pdev, NULL);
917 ieee80211_free_hw(hw);
920 static irqreturn_t brcms_isr(int irq, void *dev_id)
922 struct brcms_info *wl;
923 irqreturn_t ret = IRQ_NONE;
925 wl = (struct brcms_info *) dev_id;
927 spin_lock(&wl->isr_lock);
929 /* call common first level interrupt handler */
930 if (brcms_c_isr(wl->wlc)) {
931 /* schedule second level handler */
932 tasklet_schedule(&wl->tasklet);
936 spin_unlock(&wl->isr_lock);
942 * is called in brcms_pci_probe() context, therefore no locking required.
944 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
946 struct brcms_info *wl = hw->priv;
947 struct brcms_c_info *wlc = wl->wlc;
948 struct ieee80211_supported_band *band;
952 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
953 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
955 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
956 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
957 band = &wlc->bandstate[BAND_2G_INDEX]->band;
958 *band = brcms_band_2GHz_nphy_template;
959 if (phy_type == PHY_TYPE_LCN) {
961 band->ht_cap.mcs.rx_mask[1] = 0;
962 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
964 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
969 /* Assume all bands use the same phy. True for 11n devices. */
970 if (wl->pub->_nbands > 1) {
972 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
973 band = &wlc->bandstate[BAND_5G_INDEX]->band;
974 *band = brcms_band_5GHz_nphy_template;
975 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
984 * is called in brcms_pci_probe() context, therefore no locking required.
986 static int ieee_hw_init(struct ieee80211_hw *hw)
988 hw->flags = IEEE80211_HW_SIGNAL_DBM
989 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
990 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
991 | IEEE80211_HW_AMPDU_AGGREGATION;
993 hw->extra_tx_headroom = brcms_c_get_header_len();
994 hw->queues = N_TX_QUEUES;
995 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
997 /* channel change time is dependent on chip and band */
998 hw->channel_change_time = 7 * 1000;
999 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1001 hw->rate_control_algorithm = "minstrel_ht";
1003 hw->sta_data_size = 0;
1004 return ieee_hw_rate_init(hw);
1008 * attach to the WL device.
1010 * Attach to the WL device identified by vendor and device parameters.
1011 * regs is a host accessible memory address pointing to WL device registers.
1013 * brcms_attach is not defined as static because in the case where no bus
1014 * is defined, wl_attach will never be called, and thus, gcc will issue
1015 * a warning that this function is defined but not used if we declare
1019 * is called in brcms_bcma_probe() context, therefore no locking required.
1021 static struct brcms_info *brcms_attach(struct bcma_device *pdev)
1023 struct brcms_info *wl = NULL;
1025 struct ieee80211_hw *hw;
1028 unit = n_adapters_found;
1034 /* allocate private info */
1035 hw = bcma_get_drvdata(pdev);
1038 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1040 wl->wiphy = hw->wiphy;
1042 atomic_set(&wl->callbacks, 0);
1044 init_waitqueue_head(&wl->tx_flush_wq);
1046 /* setup the bottom half handler */
1047 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1049 spin_lock_init(&wl->lock);
1050 spin_lock_init(&wl->isr_lock);
1053 if (brcms_request_fw(wl, pdev) < 0) {
1054 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
1055 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
1056 brcms_release_fw(wl);
1061 /* common load-time initialization */
1062 wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
1063 brcms_release_fw(wl);
1065 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1066 KBUILD_MODNAME, err);
1069 wl->pub = brcms_c_pub(wl->wlc);
1071 wl->pub->ieee_hw = hw;
1073 /* register our interrupt handler */
1074 if (request_irq(pdev->irq, brcms_isr,
1075 IRQF_SHARED, KBUILD_MODNAME, wl)) {
1076 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1079 wl->irq = pdev->irq;
1081 /* register module */
1082 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1084 if (ieee_hw_init(hw)) {
1085 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1090 brcms_c_regd_init(wl->wlc);
1092 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1093 if (WARN_ON(!is_valid_ether_addr(perm)))
1095 SET_IEEE80211_PERM_ADDR(hw, perm);
1097 err = ieee80211_register_hw(hw);
1099 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1100 "%d\n", __func__, err);
1102 if (wl->pub->srom_ccode[0] &&
1103 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1104 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
1106 brcms_debugfs_attach(wl->pub);
1107 brcms_debugfs_create_files(wl->pub);
1119 * determines if a device is a WL device, and if so, attaches it.
1121 * This function determines if a device pointed to by pdev is a WL device,
1122 * and if so, performs a brcms_attach() on it.
1124 * Perimeter lock is initialized in the course of this function.
1126 static int brcms_bcma_probe(struct bcma_device *pdev)
1128 struct brcms_info *wl;
1129 struct ieee80211_hw *hw;
1131 dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
1132 pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
1135 if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
1136 (pdev->id.id != BCMA_CORE_80211))
1139 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1141 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1145 SET_IEEE80211_DEV(hw, &pdev->dev);
1147 bcma_set_drvdata(pdev, hw);
1149 memset(hw->priv, 0, sizeof(*wl));
1151 wl = brcms_attach(pdev);
1153 pr_err("%s: brcms_attach failed!\n", __func__);
1156 brcms_led_register(wl);
1161 static int brcms_suspend(struct bcma_device *pdev)
1163 struct brcms_info *wl;
1164 struct ieee80211_hw *hw;
1166 hw = bcma_get_drvdata(pdev);
1169 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
1174 /* only need to flag hw is down for proper resume */
1175 spin_lock_bh(&wl->lock);
1176 wl->pub->hw_up = false;
1177 spin_unlock_bh(&wl->lock);
1179 brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
1184 static int brcms_resume(struct bcma_device *pdev)
1189 static struct bcma_driver brcms_bcma_driver = {
1190 .name = KBUILD_MODNAME,
1191 .probe = brcms_bcma_probe,
1192 .suspend = brcms_suspend,
1193 .resume = brcms_resume,
1194 .remove = brcms_remove,
1195 .id_table = brcms_coreid_table,
1199 * This is the main entry point for the brcmsmac driver.
1201 * This function is scheduled upon module initialization and
1202 * does the driver registration, which result in brcms_bcma_probe()
1203 * call resulting in the driver bringup.
1205 static void brcms_driver_init(struct work_struct *work)
1209 error = bcma_driver_register(&brcms_bcma_driver);
1211 pr_err("%s: register returned %d\n", __func__, error);
1214 static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
1216 static int __init brcms_module_init(void)
1218 brcms_debugfs_init();
1219 if (!schedule_work(&brcms_driver_work))
1226 * This function unloads the brcmsmac driver from the system.
1228 * This function unconditionally unloads the brcmsmac driver module from the
1232 static void __exit brcms_module_exit(void)
1234 cancel_work_sync(&brcms_driver_work);
1235 bcma_driver_unregister(&brcms_bcma_driver);
1236 brcms_debugfs_exit();
1239 module_init(brcms_module_init);
1240 module_exit(brcms_module_exit);
1243 * precondition: perimeter lock has been acquired
1245 void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1246 bool state, int prio)
1248 brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
1252 * precondition: perimeter lock has been acquired
1254 void brcms_init(struct brcms_info *wl)
1256 brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
1259 brcms_c_init(wl->wlc, wl->mute_tx);
1263 * precondition: perimeter lock has been acquired
1265 uint brcms_reset(struct brcms_info *wl)
1267 brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
1268 brcms_c_reset(wl->wlc);
1270 /* dpc will not be rescheduled */
1271 wl->resched = false;
1273 /* inform publicly that interface is down */
1274 wl->pub->up = false;
1279 void brcms_fatal_error(struct brcms_info *wl)
1281 brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
1282 wl->wlc->pub->unit);
1284 ieee80211_restart_hw(wl->pub->ieee_hw);
1288 * These are interrupt on/off entry points. Disable interrupts
1289 * during interrupt state transition.
1291 void brcms_intrson(struct brcms_info *wl)
1293 unsigned long flags;
1295 spin_lock_irqsave(&wl->isr_lock, flags);
1296 brcms_c_intrson(wl->wlc);
1297 spin_unlock_irqrestore(&wl->isr_lock, flags);
1300 u32 brcms_intrsoff(struct brcms_info *wl)
1302 unsigned long flags;
1305 spin_lock_irqsave(&wl->isr_lock, flags);
1306 status = brcms_c_intrsoff(wl->wlc);
1307 spin_unlock_irqrestore(&wl->isr_lock, flags);
1311 void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1313 unsigned long flags;
1315 spin_lock_irqsave(&wl->isr_lock, flags);
1316 brcms_c_intrsrestore(wl->wlc, macintmask);
1317 spin_unlock_irqrestore(&wl->isr_lock, flags);
1321 * precondition: perimeter lock has been acquired
1323 int brcms_up(struct brcms_info *wl)
1330 error = brcms_c_up(wl->wlc);
1336 * precondition: perimeter lock has been acquired
1338 void brcms_down(struct brcms_info *wl)
1340 uint callbacks, ret_val = 0;
1342 /* call common down function */
1343 ret_val = brcms_c_down(wl->wlc);
1344 callbacks = atomic_read(&wl->callbacks) - ret_val;
1346 /* wait for down callbacks to complete */
1347 spin_unlock_bh(&wl->lock);
1349 /* For HIGH_only driver, it's important to actually schedule other work,
1350 * not just spin wait since everything runs at schedule level
1352 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1354 spin_lock_bh(&wl->lock);
1358 * precondition: perimeter lock is not acquired
1360 static void _brcms_timer(struct work_struct *work)
1362 struct brcms_timer *t = container_of(work, struct brcms_timer,
1365 spin_lock_bh(&t->wl->lock);
1369 atomic_inc(&t->wl->callbacks);
1370 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1372 msecs_to_jiffies(t->ms));
1380 atomic_dec(&t->wl->callbacks);
1382 spin_unlock_bh(&t->wl->lock);
1386 * Adds a timer to the list. Caller supplies a timer function.
1387 * Is called from wlc.
1389 * precondition: perimeter lock has been acquired
1391 struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1392 void (*fn) (void *arg),
1393 void *arg, const char *name)
1395 struct brcms_timer *t;
1397 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1401 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
1405 t->next = wl->timers;
1409 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1411 strcpy(t->name, name);
1418 * adds only the kernel timer since it's going to be more accurate
1419 * as well as it's easier to make it periodic
1421 * precondition: perimeter lock has been acquired
1423 void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
1425 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1429 brcms_dbg_info(t->wl->wlc->hw->d11core,
1430 "%s: Already set. Name: %s, per %d\n",
1431 __func__, t->name, periodic);
1434 t->periodic = (bool) periodic;
1437 atomic_inc(&t->wl->callbacks);
1440 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
1444 * return true if timer successfully deleted, false if still pending
1446 * precondition: perimeter lock has been acquired
1448 bool brcms_del_timer(struct brcms_timer *t)
1452 if (!cancel_delayed_work(&t->dly_wrk))
1455 atomic_dec(&t->wl->callbacks);
1462 * precondition: perimeter lock has been acquired
1464 void brcms_free_timer(struct brcms_timer *t)
1466 struct brcms_info *wl = t->wl;
1467 struct brcms_timer *tmp;
1469 /* delete the timer in case it is active */
1472 if (wl->timers == t) {
1473 wl->timers = wl->timers->next;
1484 if (tmp->next == t) {
1485 tmp->next = t->next;
1498 * precondition: perimeter lock has been acquired
1500 int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1504 struct firmware_hdr *hdr;
1505 for (i = 0; i < wl->fw.fw_cnt; i++) {
1506 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1507 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1509 u32 len = le32_to_cpu(hdr->len);
1510 if (le32_to_cpu(hdr->idx) == idx) {
1511 pdata = wl->fw.fw_bin[i]->data +
1512 le32_to_cpu(hdr->offset);
1513 *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
1521 brcms_err(wl->wlc->hw->d11core,
1522 "ERROR: ucode buf tag:%d can not be found!\n", idx);
1529 * Precondition: Since this function is called in brcms_bcma_probe() context,
1530 * no locking is required.
1532 int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1536 struct firmware_hdr *hdr;
1537 for (i = 0; i < wl->fw.fw_cnt; i++) {
1538 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1539 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1541 if (le32_to_cpu(hdr->idx) == idx) {
1542 pdata = wl->fw.fw_bin[i]->data +
1543 le32_to_cpu(hdr->offset);
1544 if (le32_to_cpu(hdr->len) != 4) {
1545 brcms_err(wl->wlc->hw->d11core,
1546 "ERROR: fw hdr len\n");
1549 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1554 brcms_err(wl->wlc->hw->d11core,
1555 "ERROR: ucode tag:%d can not be found!\n", idx);
1560 * precondition: can both be called locked and unlocked
1562 void brcms_ucode_free_buf(void *p)
1568 * checks validity of all firmware images loaded from user space
1570 * Precondition: Since this function is called in brcms_bcma_probe() context,
1571 * no locking is required.
1573 int brcms_check_firmwares(struct brcms_info *wl)
1578 const struct firmware *fw;
1579 const struct firmware *fw_hdr;
1580 struct firmware_hdr *ucode_hdr;
1581 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1582 fw = wl->fw.fw_bin[i];
1583 fw_hdr = wl->fw.fw_hdr[i];
1584 if (fw == NULL && fw_hdr == NULL) {
1586 } else if (fw == NULL || fw_hdr == NULL) {
1587 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1590 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1591 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1592 "size %zu/%zu\n", __func__, fw_hdr->size,
1593 sizeof(struct firmware_hdr));
1595 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1596 wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
1597 __func__, fw->size);
1600 /* check if ucode section overruns firmware image */
1601 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1602 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1603 !rc; entry++, ucode_hdr++) {
1604 if (le32_to_cpu(ucode_hdr->offset) +
1605 le32_to_cpu(ucode_hdr->len) >
1607 wiphy_err(wl->wiphy,
1608 "%s: conflicting bin/hdr\n",
1615 if (rc == 0 && wl->fw.fw_cnt != i) {
1616 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1624 * precondition: perimeter lock has been acquired
1626 bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1628 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1630 spin_unlock_bh(&wl->lock);
1631 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1633 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1634 spin_lock_bh(&wl->lock);