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__
19 #include <linux/etherdevice.h>
20 #include <linux/pci.h>
21 #include <linux/sched.h>
22 #include <linux/firmware.h>
23 #include <linux/interrupt.h>
24 #include <linux/module.h>
25 #include <net/mac80211.h>
28 #include "phy/phy_int.h"
33 #include "ucode_loader.h"
34 #include "mac80211_if.h"
37 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
39 /* Flags we support */
40 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
46 FIF_BCN_PRBRESP_PROMISC)
48 #define CHAN2GHZ(channel, freqency, chflags) { \
49 .band = IEEE80211_BAND_2GHZ, \
50 .center_freq = (freqency), \
51 .hw_value = (channel), \
53 .max_antenna_gain = 0, \
57 #define CHAN5GHZ(channel, chflags) { \
58 .band = IEEE80211_BAND_5GHZ, \
59 .center_freq = 5000 + 5*(channel), \
60 .hw_value = (channel), \
62 .max_antenna_gain = 0, \
66 #define RATE(rate100m, _flags) { \
67 .bitrate = (rate100m), \
69 .hw_value = (rate100m / 5), \
78 static const char * const brcms_firmwares[MAX_FW_IMAGES] = {
83 static int n_adapters_found;
85 MODULE_AUTHOR("Broadcom Corporation");
86 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
87 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
88 MODULE_LICENSE("Dual BSD/GPL");
90 /* recognized PCI IDs */
91 static DEFINE_PCI_DEVICE_TABLE(brcms_pci_id_table) = {
92 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4357) }, /* 43225 2G */
93 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) }, /* 43224 DUAL */
94 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) }, /* 4313 DUAL */
95 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) }, /* 43224 Ven */
99 MODULE_DEVICE_TABLE(pci, brcms_pci_id_table);
102 static int msglevel = 0xdeadbeef;
103 module_param(msglevel, int, 0);
106 static struct ieee80211_channel brcms_2ghz_chantable[] = {
107 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
108 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
109 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
110 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
111 CHAN2GHZ(5, 2432, 0),
112 CHAN2GHZ(6, 2437, 0),
113 CHAN2GHZ(7, 2442, 0),
114 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
115 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
116 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
117 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
119 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
120 IEEE80211_CHAN_NO_HT40PLUS),
122 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
123 IEEE80211_CHAN_NO_HT40PLUS),
125 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
126 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
129 static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
131 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
132 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
133 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
134 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
137 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
138 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
140 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
141 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
143 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
144 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
146 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
147 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
150 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
151 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
153 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
154 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
156 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
157 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
159 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
160 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
162 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
163 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
165 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
166 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
168 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
169 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
171 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
172 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
174 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
175 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
177 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
178 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
180 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
181 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
182 IEEE80211_CHAN_NO_HT40MINUS),
184 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
185 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
186 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
187 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
188 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
192 * The rate table is used for both 2.4G and 5G rates. The
193 * latter being a subset as it does not support CCK rates.
195 static struct ieee80211_rate legacy_ratetable[] = {
197 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
198 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
199 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
210 static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template = {
211 .band = IEEE80211_BAND_2GHZ,
212 .channels = brcms_2ghz_chantable,
213 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
214 .bitrates = legacy_ratetable,
215 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
217 /* from include/linux/ieee80211.h */
218 .cap = IEEE80211_HT_CAP_GRN_FLD |
219 IEEE80211_HT_CAP_SGI_20 |
220 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
221 .ht_supported = true,
222 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
223 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
225 /* placeholders for now */
226 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
227 .rx_highest = cpu_to_le16(500),
228 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
232 static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template = {
233 .band = IEEE80211_BAND_5GHZ,
234 .channels = brcms_5ghz_nphy_chantable,
235 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
236 .bitrates = legacy_ratetable + BRCMS_LEGACY_5G_RATE_OFFSET,
237 .n_bitrates = ARRAY_SIZE(legacy_ratetable) -
238 BRCMS_LEGACY_5G_RATE_OFFSET,
240 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
241 IEEE80211_HT_CAP_SGI_40 |
242 IEEE80211_HT_CAP_40MHZ_INTOLERANT, /* No 40 mhz yet */
243 .ht_supported = true,
244 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
245 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
247 /* placeholders for now */
248 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
249 .rx_highest = cpu_to_le16(500),
250 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
254 /* flags the given rate in rateset as requested */
255 static void brcms_set_basic_rate(struct brcm_rateset *rs, u16 rate, bool is_br)
259 for (i = 0; i < rs->count; i++) {
260 if (rate != (rs->rates[i] & 0x7f))
264 rs->rates[i] |= BRCMS_RATE_FLAG;
266 rs->rates[i] &= BRCMS_RATE_MASK;
271 static void brcms_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
273 struct brcms_info *wl = hw->priv;
275 spin_lock_bh(&wl->lock);
277 wiphy_err(wl->wiphy, "ops->tx called while down\n");
281 brcms_c_sendpkt_mac80211(wl->wlc, skb, hw);
283 spin_unlock_bh(&wl->lock);
286 static int brcms_ops_start(struct ieee80211_hw *hw)
288 struct brcms_info *wl = hw->priv;
291 ieee80211_wake_queues(hw);
292 spin_lock_bh(&wl->lock);
293 blocked = brcms_rfkill_set_hw_state(wl);
294 spin_unlock_bh(&wl->lock);
296 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
301 static void brcms_ops_stop(struct ieee80211_hw *hw)
303 ieee80211_stop_queues(hw);
307 brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
309 struct brcms_info *wl;
312 /* Just STA for now */
313 if (vif->type != NL80211_IFTYPE_AP &&
314 vif->type != NL80211_IFTYPE_MESH_POINT &&
315 vif->type != NL80211_IFTYPE_STATION &&
316 vif->type != NL80211_IFTYPE_WDS &&
317 vif->type != NL80211_IFTYPE_ADHOC) {
318 wiphy_err(hw->wiphy, "%s: Attempt to add type %d, only"
319 " STA for now\n", __func__, vif->type);
324 spin_lock_bh(&wl->lock);
329 spin_unlock_bh(&wl->lock);
332 wiphy_err(hw->wiphy, "%s: brcms_up() returned %d\n", __func__,
339 brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
341 struct brcms_info *wl;
345 /* put driver in down state */
346 spin_lock_bh(&wl->lock);
348 spin_unlock_bh(&wl->lock);
351 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
353 struct ieee80211_conf *conf = &hw->conf;
354 struct brcms_info *wl = hw->priv;
357 struct wiphy *wiphy = hw->wiphy;
359 spin_lock_bh(&wl->lock);
360 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
361 brcms_c_set_beacon_listen_interval(wl->wlc,
362 conf->listen_interval);
364 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
365 wiphy_err(wiphy, "%s: change monitor mode: %s (implement)\n",
366 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
368 if (changed & IEEE80211_CONF_CHANGE_PS)
369 wiphy_err(wiphy, "%s: change power-save mode: %s (implement)\n",
370 __func__, conf->flags & IEEE80211_CONF_PS ?
373 if (changed & IEEE80211_CONF_CHANGE_POWER) {
374 err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
376 wiphy_err(wiphy, "%s: Error setting power_level\n",
380 new_int = brcms_c_get_tx_power(wl->wlc);
381 if (new_int != conf->power_level)
382 wiphy_err(wiphy, "%s: Power level req != actual, %d %d"
383 "\n", __func__, conf->power_level,
386 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
387 if (conf->channel_type == NL80211_CHAN_HT20 ||
388 conf->channel_type == NL80211_CHAN_NO_HT)
389 err = brcms_c_set_channel(wl->wlc,
390 conf->channel->hw_value);
394 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
395 err = brcms_c_set_rate_limit(wl->wlc,
396 conf->short_frame_max_tx_count,
397 conf->long_frame_max_tx_count);
400 spin_unlock_bh(&wl->lock);
405 brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
406 struct ieee80211_vif *vif,
407 struct ieee80211_bss_conf *info, u32 changed)
409 struct brcms_info *wl = hw->priv;
410 struct wiphy *wiphy = hw->wiphy;
412 if (changed & BSS_CHANGED_ASSOC) {
413 /* association status changed (associated/disassociated)
414 * also implies a change in the AID.
416 wiphy_err(wiphy, "%s: %s: %sassociated\n", KBUILD_MODNAME,
417 __func__, info->assoc ? "" : "dis");
418 spin_lock_bh(&wl->lock);
419 brcms_c_associate_upd(wl->wlc, info->assoc);
420 spin_unlock_bh(&wl->lock);
422 if (changed & BSS_CHANGED_ERP_SLOT) {
425 /* slot timing changed */
426 if (info->use_short_slot)
430 spin_lock_bh(&wl->lock);
431 brcms_c_set_shortslot_override(wl->wlc, val);
432 spin_unlock_bh(&wl->lock);
435 if (changed & BSS_CHANGED_HT) {
436 /* 802.11n parameters changed */
437 u16 mode = info->ht_operation_mode;
439 spin_lock_bh(&wl->lock);
440 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
441 mode & IEEE80211_HT_OP_MODE_PROTECTION);
442 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
443 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
444 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
445 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
446 spin_unlock_bh(&wl->lock);
448 if (changed & BSS_CHANGED_BASIC_RATES) {
449 struct ieee80211_supported_band *bi;
452 struct brcm_rateset rs;
455 /* retrieve the current rates */
456 spin_lock_bh(&wl->lock);
457 brcms_c_get_current_rateset(wl->wlc, &rs);
458 spin_unlock_bh(&wl->lock);
460 br_mask = info->basic_rates;
461 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
462 for (i = 0; i < bi->n_bitrates; i++) {
463 /* convert to internal rate value */
464 rate = (bi->bitrates[i].bitrate << 1) / 10;
466 /* set/clear basic rate flag */
467 brcms_set_basic_rate(&rs, rate, br_mask & 1);
471 /* update the rate set */
472 spin_lock_bh(&wl->lock);
473 error = brcms_c_set_rateset(wl->wlc, &rs);
474 spin_unlock_bh(&wl->lock);
476 wiphy_err(wiphy, "changing basic rates failed: %d\n",
479 if (changed & BSS_CHANGED_BEACON_INT) {
480 /* Beacon interval changed */
481 spin_lock_bh(&wl->lock);
482 brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
483 spin_unlock_bh(&wl->lock);
485 if (changed & BSS_CHANGED_BSSID) {
486 /* BSSID changed, for whatever reason (IBSS and managed mode) */
487 spin_lock_bh(&wl->lock);
488 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
489 spin_unlock_bh(&wl->lock);
491 if (changed & BSS_CHANGED_BEACON)
492 /* Beacon data changed, retrieve new beacon (beaconing modes) */
493 wiphy_err(wiphy, "%s: beacon changed\n", __func__);
495 if (changed & BSS_CHANGED_BEACON_ENABLED) {
496 /* Beaconing should be enabled/disabled (beaconing modes) */
497 wiphy_err(wiphy, "%s: Beacon enabled: %s\n", __func__,
498 info->enable_beacon ? "true" : "false");
501 if (changed & BSS_CHANGED_CQM) {
502 /* Connection quality monitor config changed */
503 wiphy_err(wiphy, "%s: cqm change: threshold %d, hys %d "
504 " (implement)\n", __func__, info->cqm_rssi_thold,
505 info->cqm_rssi_hyst);
508 if (changed & BSS_CHANGED_IBSS) {
509 /* IBSS join status changed */
510 wiphy_err(wiphy, "%s: IBSS joined: %s (implement)\n", __func__,
511 info->ibss_joined ? "true" : "false");
514 if (changed & BSS_CHANGED_ARP_FILTER) {
515 /* Hardware ARP filter address list or state changed */
516 wiphy_err(wiphy, "%s: arp filtering: enabled %s, count %d"
517 " (implement)\n", __func__, info->arp_filter_enabled ?
518 "true" : "false", info->arp_addr_cnt);
521 if (changed & BSS_CHANGED_QOS) {
523 * QoS for this association was enabled/disabled.
524 * Note that it is only ever disabled for station mode.
526 wiphy_err(wiphy, "%s: qos enabled: %s (implement)\n", __func__,
527 info->qos ? "true" : "false");
533 brcms_ops_configure_filter(struct ieee80211_hw *hw,
534 unsigned int changed_flags,
535 unsigned int *total_flags, u64 multicast)
537 struct brcms_info *wl = hw->priv;
538 struct wiphy *wiphy = hw->wiphy;
540 changed_flags &= MAC_FILTERS;
541 *total_flags &= MAC_FILTERS;
542 if (changed_flags & FIF_PROMISC_IN_BSS)
543 wiphy_err(wiphy, "FIF_PROMISC_IN_BSS\n");
544 if (changed_flags & FIF_ALLMULTI)
545 wiphy_err(wiphy, "FIF_ALLMULTI\n");
546 if (changed_flags & FIF_FCSFAIL)
547 wiphy_err(wiphy, "FIF_FCSFAIL\n");
548 if (changed_flags & FIF_PLCPFAIL)
549 wiphy_err(wiphy, "FIF_PLCPFAIL\n");
550 if (changed_flags & FIF_CONTROL)
551 wiphy_err(wiphy, "FIF_CONTROL\n");
552 if (changed_flags & FIF_OTHER_BSS)
553 wiphy_err(wiphy, "FIF_OTHER_BSS\n");
554 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
555 spin_lock_bh(&wl->lock);
556 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
557 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
558 brcms_c_mac_bcn_promisc_change(wl->wlc, 1);
560 brcms_c_mac_bcn_promisc_change(wl->wlc, 0);
561 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
563 spin_unlock_bh(&wl->lock);
568 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
570 struct brcms_info *wl = hw->priv;
571 spin_lock_bh(&wl->lock);
572 brcms_c_scan_start(wl->wlc);
573 spin_unlock_bh(&wl->lock);
577 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
579 struct brcms_info *wl = hw->priv;
580 spin_lock_bh(&wl->lock);
581 brcms_c_scan_stop(wl->wlc);
582 spin_unlock_bh(&wl->lock);
587 brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
588 const struct ieee80211_tx_queue_params *params)
590 struct brcms_info *wl = hw->priv;
592 spin_lock_bh(&wl->lock);
593 brcms_c_wme_setparams(wl->wlc, queue, params, true);
594 spin_unlock_bh(&wl->lock);
600 brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
601 struct ieee80211_sta *sta)
603 struct brcms_info *wl = hw->priv;
604 struct scb *scb = &wl->wlc->pri_scb;
606 brcms_c_init_scb(scb);
608 wl->pub->global_ampdu = &(scb->scb_ampdu);
609 wl->pub->global_ampdu->scb = scb;
610 wl->pub->global_ampdu->max_pdu = 16;
612 sta->ht_cap.ht_supported = true;
613 sta->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
614 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
615 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
616 IEEE80211_HT_CAP_SGI_20 |
617 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
620 * minstrel_ht initiates addBA on our behalf by calling
621 * ieee80211_start_tx_ba_session()
627 brcms_ops_ampdu_action(struct ieee80211_hw *hw,
628 struct ieee80211_vif *vif,
629 enum ieee80211_ampdu_mlme_action action,
630 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
633 struct brcms_info *wl = hw->priv;
634 struct scb *scb = &wl->wlc->pri_scb;
637 if (WARN_ON(scb->magic != SCB_MAGIC))
640 case IEEE80211_AMPDU_RX_START:
642 case IEEE80211_AMPDU_RX_STOP:
644 case IEEE80211_AMPDU_TX_START:
645 spin_lock_bh(&wl->lock);
646 status = brcms_c_aggregatable(wl->wlc, tid);
647 spin_unlock_bh(&wl->lock);
649 wiphy_err(wl->wiphy, "START: tid %d is not agg\'able\n",
653 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
656 case IEEE80211_AMPDU_TX_STOP:
657 spin_lock_bh(&wl->lock);
658 brcms_c_ampdu_flush(wl->wlc, sta, tid);
659 spin_unlock_bh(&wl->lock);
660 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
662 case IEEE80211_AMPDU_TX_OPERATIONAL:
664 * BA window size from ADDBA response ('buf_size') defines how
665 * many outstanding MPDUs are allowed for the BA stream by
666 * recipient and traffic class. 'ampdu_factor' gives maximum
669 spin_lock_bh(&wl->lock);
670 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
671 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
672 sta->ht_cap.ampdu_factor)) - 1);
673 spin_unlock_bh(&wl->lock);
674 /* Power save wakeup */
677 wiphy_err(wl->wiphy, "%s: Invalid command, ignoring\n",
684 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
686 struct brcms_info *wl = hw->priv;
689 spin_lock_bh(&wl->lock);
690 blocked = brcms_c_check_radio_disabled(wl->wlc);
691 spin_unlock_bh(&wl->lock);
693 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
696 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
698 struct brcms_info *wl = hw->priv;
700 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
702 /* wait for packet queue and dma fifos to run empty */
703 spin_lock_bh(&wl->lock);
704 brcms_c_wait_for_tx_completion(wl->wlc, drop);
705 spin_unlock_bh(&wl->lock);
708 static const struct ieee80211_ops brcms_ops = {
710 .start = brcms_ops_start,
711 .stop = brcms_ops_stop,
712 .add_interface = brcms_ops_add_interface,
713 .remove_interface = brcms_ops_remove_interface,
714 .config = brcms_ops_config,
715 .bss_info_changed = brcms_ops_bss_info_changed,
716 .configure_filter = brcms_ops_configure_filter,
717 .sw_scan_start = brcms_ops_sw_scan_start,
718 .sw_scan_complete = brcms_ops_sw_scan_complete,
719 .conf_tx = brcms_ops_conf_tx,
720 .sta_add = brcms_ops_sta_add,
721 .ampdu_action = brcms_ops_ampdu_action,
722 .rfkill_poll = brcms_ops_rfkill_poll,
723 .flush = brcms_ops_flush,
727 * is called in brcms_pci_probe() context, therefore no locking required.
729 static int brcms_set_hint(struct brcms_info *wl, char *abbrev)
731 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
734 void brcms_dpc(unsigned long data)
736 struct brcms_info *wl;
738 wl = (struct brcms_info *) data;
740 spin_lock_bh(&wl->lock);
742 /* call the common second level interrupt handler */
747 spin_lock_irqsave(&wl->isr_lock, flags);
748 brcms_c_intrsupd(wl->wlc);
749 spin_unlock_irqrestore(&wl->isr_lock, flags);
752 wl->resched = brcms_c_dpc(wl->wlc, true);
755 /* brcms_c_dpc() may bring the driver down */
759 /* re-schedule dpc */
761 tasklet_schedule(&wl->tasklet);
763 /* re-enable interrupts */
767 spin_unlock_bh(&wl->lock);
771 * Precondition: Since this function is called in brcms_pci_probe() context,
772 * no locking is required.
774 static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev)
777 struct device *device = &pdev->dev;
781 memset(&wl->fw, 0, sizeof(struct brcms_firmware));
782 for (i = 0; i < MAX_FW_IMAGES; i++) {
783 if (brcms_firmwares[i] == NULL)
785 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
786 UCODE_LOADER_API_VER);
787 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
789 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
790 KBUILD_MODNAME, fw_name);
793 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
794 UCODE_LOADER_API_VER);
795 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
797 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
798 KBUILD_MODNAME, fw_name);
801 wl->fw.hdr_num_entries[i] =
802 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
805 return brcms_ucode_data_init(wl, &wl->ucode);
809 * Precondition: Since this function is called in brcms_pci_probe() context,
810 * no locking is required.
812 static void brcms_release_fw(struct brcms_info *wl)
815 for (i = 0; i < MAX_FW_IMAGES; i++) {
816 release_firmware(wl->fw.fw_bin[i]);
817 release_firmware(wl->fw.fw_hdr[i]);
822 * This function frees the WL per-device resources.
824 * This function frees resources owned by the WL device pointed to
825 * by the wl parameter.
827 * precondition: can both be called locked and unlocked
830 static void brcms_free(struct brcms_info *wl)
832 struct brcms_timer *t, *next;
834 /* free ucode data */
836 brcms_ucode_data_free(&wl->ucode);
838 free_irq(wl->irq, wl);
841 tasklet_kill(&wl->tasklet);
844 brcms_c_module_unregister(wl->pub, "linux", wl);
846 /* free common resources */
848 brcms_c_detach(wl->wlc);
853 /* virtual interface deletion is deferred so we cannot spinwait */
855 /* wait for all pending callbacks to complete */
856 while (atomic_read(&wl->callbacks) > 0)
860 for (t = wl->timers; t; t = next) {
869 * unregister_netdev() calls get_stats() which may read chip
870 * registers so we cannot unmap the chip registers until
871 * after calling unregister_netdev() .
880 * called from both kernel as from this kernel module.
881 * precondition: perimeter lock is not acquired.
883 static void brcms_remove(struct pci_dev *pdev)
885 struct brcms_info *wl;
886 struct ieee80211_hw *hw;
889 hw = pci_get_drvdata(pdev);
892 pr_err("wl: brcms_remove: pci_get_drvdata failed\n");
896 spin_lock_bh(&wl->lock);
897 status = brcms_c_chipmatch(pdev->vendor, pdev->device);
898 spin_unlock_bh(&wl->lock);
900 wiphy_err(wl->wiphy, "wl: brcms_remove: chipmatch "
905 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
906 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
907 ieee80211_unregister_hw(hw);
908 spin_lock_bh(&wl->lock);
910 spin_unlock_bh(&wl->lock);
912 pci_disable_device(pdev);
916 pci_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;
925 wl = (struct brcms_info *) dev_id;
927 spin_lock(&wl->isr_lock);
929 /* call common first level interrupt handler */
930 ours = brcms_c_isr(wl->wlc, &wantdpc);
932 /* if more to do... */
935 /* ...and call the second level interrupt handler */
937 tasklet_schedule(&wl->tasklet);
941 spin_unlock(&wl->isr_lock);
943 return IRQ_RETVAL(ours);
947 * is called in brcms_pci_probe() context, therefore no locking required.
949 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
951 struct brcms_info *wl = hw->priv;
952 struct brcms_c_info *wlc = wl->wlc;
953 struct ieee80211_supported_band *band;
957 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
958 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
960 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
961 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
962 band = &wlc->bandstate[BAND_2G_INDEX]->band;
963 *band = brcms_band_2GHz_nphy_template;
964 if (phy_type == PHY_TYPE_LCN) {
966 band->ht_cap.mcs.rx_mask[1] = 0;
967 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
969 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
974 /* Assume all bands use the same phy. True for 11n devices. */
975 if (wl->pub->_nbands > 1) {
977 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
978 band = &wlc->bandstate[BAND_5G_INDEX]->band;
979 *band = brcms_band_5GHz_nphy_template;
980 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
989 * is called in brcms_pci_probe() context, therefore no locking required.
991 static int ieee_hw_init(struct ieee80211_hw *hw)
993 hw->flags = IEEE80211_HW_SIGNAL_DBM
994 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
995 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
996 | IEEE80211_HW_AMPDU_AGGREGATION;
998 hw->extra_tx_headroom = brcms_c_get_header_len();
999 hw->queues = N_TX_QUEUES;
1000 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1002 /* channel change time is dependent on chip and band */
1003 hw->channel_change_time = 7 * 1000;
1004 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1006 hw->rate_control_algorithm = "minstrel_ht";
1008 hw->sta_data_size = 0;
1009 return ieee_hw_rate_init(hw);
1013 * attach to the WL device.
1015 * Attach to the WL device identified by vendor and device parameters.
1016 * regs is a host accessible memory address pointing to WL device registers.
1018 * brcms_attach is not defined as static because in the case where no bus
1019 * is defined, wl_attach will never be called, and thus, gcc will issue
1020 * a warning that this function is defined but not used if we declare
1024 * is called in brcms_pci_probe() context, therefore no locking required.
1026 static struct brcms_info *brcms_attach(u16 vendor, u16 device,
1027 resource_size_t regs,
1028 struct pci_dev *btparam, uint irq)
1030 struct brcms_info *wl = NULL;
1032 struct ieee80211_hw *hw;
1035 unit = n_adapters_found;
1041 /* allocate private info */
1042 hw = pci_get_drvdata(btparam); /* btparam == pdev */
1045 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1047 wl->wiphy = hw->wiphy;
1049 atomic_set(&wl->callbacks, 0);
1051 /* setup the bottom half handler */
1052 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1054 wl->regsva = ioremap_nocache(regs, PCI_BAR0_WINSZ);
1055 if (wl->regsva == NULL) {
1056 wiphy_err(wl->wiphy, "wl%d: ioremap() failed\n", unit);
1059 spin_lock_init(&wl->lock);
1060 spin_lock_init(&wl->isr_lock);
1063 if (brcms_request_fw(wl, btparam) < 0) {
1064 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
1065 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
1066 brcms_release_fw(wl);
1067 brcms_remove(btparam);
1071 /* common load-time initialization */
1072 wl->wlc = brcms_c_attach(wl, vendor, device, unit, false,
1073 wl->regsva, btparam, &err);
1074 brcms_release_fw(wl);
1076 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1077 KBUILD_MODNAME, err);
1080 wl->pub = brcms_c_pub(wl->wlc);
1082 wl->pub->ieee_hw = hw;
1085 brcms_c_set_radio_mpc(wl->wlc, false);
1087 /* register our interrupt handler */
1088 if (request_irq(irq, brcms_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
1089 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1094 /* register module */
1095 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1097 if (ieee_hw_init(hw)) {
1098 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1103 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1104 if (WARN_ON(!is_valid_ether_addr(perm)))
1106 SET_IEEE80211_PERM_ADDR(hw, perm);
1108 err = ieee80211_register_hw(hw);
1110 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1111 "%d\n", __func__, err);
1113 if (wl->pub->srom_ccode[0])
1114 err = brcms_set_hint(wl, wl->pub->srom_ccode);
1116 err = brcms_set_hint(wl, "US");
1118 wiphy_err(wl->wiphy, "%s: regulatory_hint failed, status %d\n",
1132 * determines if a device is a WL device, and if so, attaches it.
1134 * This function determines if a device pointed to by pdev is a WL device,
1135 * and if so, performs a brcms_attach() on it.
1137 * Perimeter lock is initialized in the course of this function.
1139 static int __devinit
1140 brcms_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1143 struct brcms_info *wl;
1144 struct ieee80211_hw *hw;
1147 dev_info(&pdev->dev, "bus %d slot %d func %d irq %d\n",
1148 pdev->bus->number, PCI_SLOT(pdev->devfn),
1149 PCI_FUNC(pdev->devfn), pdev->irq);
1151 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1152 ((pdev->device != 0x0576) &&
1153 ((pdev->device & 0xff00) != 0x4300) &&
1154 ((pdev->device & 0xff00) != 0x4700) &&
1155 ((pdev->device < 43000) || (pdev->device > 43999))))
1158 rc = pci_enable_device(pdev);
1160 pr_err("%s: Cannot enable device %d-%d_%d\n",
1161 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1162 PCI_FUNC(pdev->devfn));
1165 pci_set_master(pdev);
1167 pci_read_config_dword(pdev, 0x40, &val);
1168 if ((val & 0x0000ff00) != 0)
1169 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1171 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1173 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1177 SET_IEEE80211_DEV(hw, &pdev->dev);
1179 pci_set_drvdata(pdev, hw);
1181 memset(hw->priv, 0, sizeof(*wl));
1183 wl = brcms_attach(pdev->vendor, pdev->device,
1184 pci_resource_start(pdev, 0), pdev,
1188 pr_err("%s: %s: brcms_attach failed!\n", KBUILD_MODNAME,
1195 static int brcms_suspend(struct pci_dev *pdev, pm_message_t state)
1197 struct brcms_info *wl;
1198 struct ieee80211_hw *hw;
1200 hw = pci_get_drvdata(pdev);
1203 wiphy_err(wl->wiphy,
1204 "brcms_suspend: pci_get_drvdata failed\n");
1208 /* only need to flag hw is down for proper resume */
1209 spin_lock_bh(&wl->lock);
1210 wl->pub->hw_up = false;
1211 spin_unlock_bh(&wl->lock);
1213 pci_save_state(pdev);
1214 pci_disable_device(pdev);
1215 return pci_set_power_state(pdev, PCI_D3hot);
1218 static int brcms_resume(struct pci_dev *pdev)
1220 struct brcms_info *wl;
1221 struct ieee80211_hw *hw;
1225 hw = pci_get_drvdata(pdev);
1228 wiphy_err(wl->wiphy,
1229 "wl: brcms_resume: pci_get_drvdata failed\n");
1233 err = pci_set_power_state(pdev, PCI_D0);
1237 pci_restore_state(pdev);
1239 err = pci_enable_device(pdev);
1243 pci_set_master(pdev);
1245 pci_read_config_dword(pdev, 0x40, &val);
1246 if ((val & 0x0000ff00) != 0)
1247 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1250 * done. driver will be put in up state
1251 * in brcms_ops_add_interface() call.
1256 static struct pci_driver brcms_pci_driver = {
1257 .name = KBUILD_MODNAME,
1258 .probe = brcms_pci_probe,
1259 .suspend = brcms_suspend,
1260 .resume = brcms_resume,
1261 .remove = __devexit_p(brcms_remove),
1262 .id_table = brcms_pci_id_table,
1266 * This is the main entry point for the WL driver.
1268 * This function determines if a device pointed to by pdev is a WL device,
1269 * and if so, performs a brcms_attach() on it.
1272 static int __init brcms_module_init(void)
1274 int error = -ENODEV;
1277 if (msglevel != 0xdeadbeef)
1278 brcm_msg_level = msglevel;
1281 error = pci_register_driver(&brcms_pci_driver);
1291 * This function unloads the WL driver from the system.
1293 * This function unconditionally unloads the WL driver module from the
1297 static void __exit brcms_module_exit(void)
1299 pci_unregister_driver(&brcms_pci_driver);
1303 module_init(brcms_module_init);
1304 module_exit(brcms_module_exit);
1307 * precondition: perimeter lock has been acquired
1309 void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1310 bool state, int prio)
1312 wiphy_err(wl->wiphy, "Shouldn't be here %s\n", __func__);
1316 * precondition: perimeter lock has been acquired
1318 void brcms_init(struct brcms_info *wl)
1320 BCMMSG(wl->pub->ieee_hw->wiphy, "wl%d\n", wl->pub->unit);
1323 brcms_c_init(wl->wlc);
1327 * precondition: perimeter lock has been acquired
1329 uint brcms_reset(struct brcms_info *wl)
1331 BCMMSG(wl->pub->ieee_hw->wiphy, "wl%d\n", wl->pub->unit);
1332 brcms_c_reset(wl->wlc);
1334 /* dpc will not be rescheduled */
1341 * These are interrupt on/off entry points. Disable interrupts
1342 * during interrupt state transition.
1344 void brcms_intrson(struct brcms_info *wl)
1346 unsigned long flags;
1348 spin_lock_irqsave(&wl->isr_lock, flags);
1349 brcms_c_intrson(wl->wlc);
1350 spin_unlock_irqrestore(&wl->isr_lock, flags);
1353 u32 brcms_intrsoff(struct brcms_info *wl)
1355 unsigned long flags;
1358 spin_lock_irqsave(&wl->isr_lock, flags);
1359 status = brcms_c_intrsoff(wl->wlc);
1360 spin_unlock_irqrestore(&wl->isr_lock, flags);
1364 void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1366 unsigned long flags;
1368 spin_lock_irqsave(&wl->isr_lock, flags);
1369 brcms_c_intrsrestore(wl->wlc, macintmask);
1370 spin_unlock_irqrestore(&wl->isr_lock, flags);
1374 * precondition: perimeter lock has been acquired
1376 int brcms_up(struct brcms_info *wl)
1383 error = brcms_c_up(wl->wlc);
1389 * precondition: perimeter lock has been acquired
1391 void brcms_down(struct brcms_info *wl)
1393 uint callbacks, ret_val = 0;
1395 /* call common down function */
1396 ret_val = brcms_c_down(wl->wlc);
1397 callbacks = atomic_read(&wl->callbacks) - ret_val;
1399 /* wait for down callbacks to complete */
1400 spin_unlock_bh(&wl->lock);
1402 /* For HIGH_only driver, it's important to actually schedule other work,
1403 * not just spin wait since everything runs at schedule level
1405 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1407 spin_lock_bh(&wl->lock);
1411 * precondition: perimeter lock is not acquired
1413 static void _brcms_timer(struct work_struct *work)
1415 struct brcms_timer *t = container_of(work, struct brcms_timer,
1418 spin_lock_bh(&t->wl->lock);
1422 atomic_inc(&t->wl->callbacks);
1423 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1425 msecs_to_jiffies(t->ms));
1433 atomic_dec(&t->wl->callbacks);
1435 spin_unlock_bh(&t->wl->lock);
1439 * Adds a timer to the list. Caller supplies a timer function.
1440 * Is called from wlc.
1442 * precondition: perimeter lock has been acquired
1444 struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1445 void (*fn) (void *arg),
1446 void *arg, const char *name)
1448 struct brcms_timer *t;
1450 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1454 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
1458 t->next = wl->timers;
1462 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1464 strcpy(t->name, name);
1471 * adds only the kernel timer since it's going to be more accurate
1472 * as well as it's easier to make it periodic
1474 * precondition: perimeter lock has been acquired
1476 void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
1478 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1482 wiphy_err(hw->wiphy, "%s: Already set. Name: %s, per %d\n",
1483 __func__, t->name, periodic);
1486 t->periodic = (bool) periodic;
1489 atomic_inc(&t->wl->callbacks);
1491 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
1495 * return true if timer successfully deleted, false if still pending
1497 * precondition: perimeter lock has been acquired
1499 bool brcms_del_timer(struct brcms_timer *t)
1503 if (!cancel_delayed_work(&t->dly_wrk))
1506 atomic_dec(&t->wl->callbacks);
1513 * precondition: perimeter lock has been acquired
1515 void brcms_free_timer(struct brcms_timer *t)
1517 struct brcms_info *wl = t->wl;
1518 struct brcms_timer *tmp;
1520 /* delete the timer in case it is active */
1523 if (wl->timers == t) {
1524 wl->timers = wl->timers->next;
1535 if (tmp->next == t) {
1536 tmp->next = t->next;
1549 * precondition: perimeter lock has been acquired
1551 int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1555 struct firmware_hdr *hdr;
1556 for (i = 0; i < wl->fw.fw_cnt; i++) {
1557 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1558 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1560 u32 len = le32_to_cpu(hdr->len);
1561 if (le32_to_cpu(hdr->idx) == idx) {
1562 pdata = wl->fw.fw_bin[i]->data +
1563 le32_to_cpu(hdr->offset);
1564 *pbuf = kmalloc(len, GFP_ATOMIC);
1568 memcpy(*pbuf, pdata, len);
1573 wiphy_err(wl->wiphy, "ERROR: ucode buf tag:%d can not be found!\n",
1581 * Precondition: Since this function is called in brcms_pci_probe() context,
1582 * no locking is required.
1584 int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1588 struct firmware_hdr *hdr;
1589 for (i = 0; i < wl->fw.fw_cnt; i++) {
1590 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1591 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1593 if (le32_to_cpu(hdr->idx) == idx) {
1594 pdata = wl->fw.fw_bin[i]->data +
1595 le32_to_cpu(hdr->offset);
1596 if (le32_to_cpu(hdr->len) != 4) {
1597 wiphy_err(wl->wiphy,
1598 "ERROR: fw hdr len\n");
1601 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1606 wiphy_err(wl->wiphy, "ERROR: ucode tag:%d can not be found!\n", idx);
1611 * precondition: can both be called locked and unlocked
1613 void brcms_ucode_free_buf(void *p)
1619 * checks validity of all firmware images loaded from user space
1621 * Precondition: Since this function is called in brcms_pci_probe() context,
1622 * no locking is required.
1624 int brcms_check_firmwares(struct brcms_info *wl)
1629 const struct firmware *fw;
1630 const struct firmware *fw_hdr;
1631 struct firmware_hdr *ucode_hdr;
1632 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1633 fw = wl->fw.fw_bin[i];
1634 fw_hdr = wl->fw.fw_hdr[i];
1635 if (fw == NULL && fw_hdr == NULL) {
1637 } else if (fw == NULL || fw_hdr == NULL) {
1638 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1641 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1642 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1643 "size %zu/%zu\n", __func__, fw_hdr->size,
1644 sizeof(struct firmware_hdr));
1646 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1647 wiphy_err(wl->wiphy, "%s: out of bounds fw file size "
1648 "%zu\n", __func__, fw->size);
1651 /* check if ucode section overruns firmware image */
1652 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1653 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1654 !rc; entry++, ucode_hdr++) {
1655 if (le32_to_cpu(ucode_hdr->offset) +
1656 le32_to_cpu(ucode_hdr->len) >
1658 wiphy_err(wl->wiphy,
1659 "%s: conflicting bin/hdr\n",
1666 if (rc == 0 && wl->fw.fw_cnt != i) {
1667 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1675 * precondition: perimeter lock has been acquired
1677 bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1679 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1681 spin_unlock_bh(&wl->lock);
1682 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1684 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1685 spin_lock_bh(&wl->lock);
1690 * precondition: perimeter lock has been acquired
1692 void brcms_msleep(struct brcms_info *wl, uint ms)
1694 spin_unlock_bh(&wl->lock);
1696 spin_lock_bh(&wl->lock);