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 <net/mac80211.h>
27 #include "phy/phy_int.h"
32 #include "ucode_loader.h"
33 #include "mac80211_if.h"
36 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
38 /* Flags we support */
39 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
45 FIF_BCN_PRBRESP_PROMISC)
47 #define CHAN2GHZ(channel, freqency, chflags) { \
48 .band = IEEE80211_BAND_2GHZ, \
49 .center_freq = (freqency), \
50 .hw_value = (channel), \
52 .max_antenna_gain = 0, \
56 #define CHAN5GHZ(channel, chflags) { \
57 .band = IEEE80211_BAND_5GHZ, \
58 .center_freq = 5000 + 5*(channel), \
59 .hw_value = (channel), \
61 .max_antenna_gain = 0, \
65 #define RATE(rate100m, _flags) { \
66 .bitrate = (rate100m), \
68 .hw_value = (rate100m / 5), \
77 static const char * const brcms_firmwares[MAX_FW_IMAGES] = {
82 static int n_adapters_found;
84 MODULE_AUTHOR("Broadcom Corporation");
85 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
86 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
87 MODULE_LICENSE("Dual BSD/GPL");
89 /* recognized PCI IDs */
90 static DEFINE_PCI_DEVICE_TABLE(brcms_pci_id_table) = {
91 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4357) }, /* 43225 2G */
92 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4353) }, /* 43224 DUAL */
93 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4727) }, /* 4313 DUAL */
94 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x0576) }, /* 43224 Ven */
98 MODULE_DEVICE_TABLE(pci, brcms_pci_id_table);
101 static int msglevel = 0xdeadbeef;
102 module_param(msglevel, int, 0);
105 static struct ieee80211_channel brcms_2ghz_chantable[] = {
106 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
107 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
108 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
109 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
110 CHAN2GHZ(5, 2432, 0),
111 CHAN2GHZ(6, 2437, 0),
112 CHAN2GHZ(7, 2442, 0),
113 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
114 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
115 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
116 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
118 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
119 IEEE80211_CHAN_NO_HT40PLUS),
121 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
122 IEEE80211_CHAN_NO_HT40PLUS),
124 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
125 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
128 static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
130 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
131 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
132 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
133 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
136 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
137 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
139 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
140 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
142 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
143 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
145 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
146 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
149 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
150 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
152 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
153 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
155 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
156 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
158 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
159 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
161 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
162 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
164 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
165 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
167 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
168 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
170 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
171 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
173 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
174 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
176 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
177 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
179 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
180 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
181 IEEE80211_CHAN_NO_HT40MINUS),
183 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
184 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
185 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
186 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
187 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
191 * The rate table is used for both 2.4G and 5G rates. The
192 * latter being a subset as it does not support CCK rates.
194 static struct ieee80211_rate legacy_ratetable[] = {
196 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
197 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
198 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
209 static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template = {
210 .band = IEEE80211_BAND_2GHZ,
211 .channels = brcms_2ghz_chantable,
212 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
213 .bitrates = legacy_ratetable,
214 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
216 /* from include/linux/ieee80211.h */
217 .cap = IEEE80211_HT_CAP_GRN_FLD |
218 IEEE80211_HT_CAP_SGI_20 |
219 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
220 .ht_supported = true,
221 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
222 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
224 /* placeholders for now */
225 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
226 .rx_highest = cpu_to_le16(500),
227 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
231 static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template = {
232 .band = IEEE80211_BAND_5GHZ,
233 .channels = brcms_5ghz_nphy_chantable,
234 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
235 .bitrates = legacy_ratetable + BRCMS_LEGACY_5G_RATE_OFFSET,
236 .n_bitrates = ARRAY_SIZE(legacy_ratetable) -
237 BRCMS_LEGACY_5G_RATE_OFFSET,
239 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
240 IEEE80211_HT_CAP_SGI_40 |
241 IEEE80211_HT_CAP_40MHZ_INTOLERANT, /* No 40 mhz yet */
242 .ht_supported = true,
243 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
244 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
246 /* placeholders for now */
247 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
248 .rx_highest = cpu_to_le16(500),
249 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
253 /* flags the given rate in rateset as requested */
254 static void brcms_set_basic_rate(struct brcm_rateset *rs, u16 rate, bool is_br)
258 for (i = 0; i < rs->count; i++) {
259 if (rate != (rs->rates[i] & 0x7f))
263 rs->rates[i] |= BRCMS_RATE_FLAG;
265 rs->rates[i] &= BRCMS_RATE_MASK;
270 static void brcms_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
272 struct brcms_info *wl = hw->priv;
274 spin_lock_bh(&wl->lock);
276 wiphy_err(wl->wiphy, "ops->tx called while down\n");
280 brcms_c_sendpkt_mac80211(wl->wlc, skb, hw);
282 spin_unlock_bh(&wl->lock);
285 static int brcms_ops_start(struct ieee80211_hw *hw)
287 struct brcms_info *wl = hw->priv;
290 ieee80211_wake_queues(hw);
291 spin_lock_bh(&wl->lock);
292 blocked = brcms_rfkill_set_hw_state(wl);
293 spin_unlock_bh(&wl->lock);
295 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
300 static void brcms_ops_stop(struct ieee80211_hw *hw)
302 ieee80211_stop_queues(hw);
306 brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
308 struct brcms_info *wl;
311 /* Just STA for now */
312 if (vif->type != NL80211_IFTYPE_AP &&
313 vif->type != NL80211_IFTYPE_MESH_POINT &&
314 vif->type != NL80211_IFTYPE_STATION &&
315 vif->type != NL80211_IFTYPE_WDS &&
316 vif->type != NL80211_IFTYPE_ADHOC) {
317 wiphy_err(hw->wiphy, "%s: Attempt to add type %d, only"
318 " STA for now\n", __func__, vif->type);
323 spin_lock_bh(&wl->lock);
328 spin_unlock_bh(&wl->lock);
331 wiphy_err(hw->wiphy, "%s: brcms_up() returned %d\n", __func__,
338 brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
340 struct brcms_info *wl;
344 /* put driver in down state */
345 spin_lock_bh(&wl->lock);
347 spin_unlock_bh(&wl->lock);
350 static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
352 struct ieee80211_conf *conf = &hw->conf;
353 struct brcms_info *wl = hw->priv;
356 struct wiphy *wiphy = hw->wiphy;
358 spin_lock_bh(&wl->lock);
359 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
360 brcms_c_set_beacon_listen_interval(wl->wlc,
361 conf->listen_interval);
363 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
364 wiphy_err(wiphy, "%s: change monitor mode: %s (implement)\n",
365 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
367 if (changed & IEEE80211_CONF_CHANGE_PS)
368 wiphy_err(wiphy, "%s: change power-save mode: %s (implement)\n",
369 __func__, conf->flags & IEEE80211_CONF_PS ?
372 if (changed & IEEE80211_CONF_CHANGE_POWER) {
373 err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
375 wiphy_err(wiphy, "%s: Error setting power_level\n",
379 new_int = brcms_c_get_tx_power(wl->wlc);
380 if (new_int != conf->power_level)
381 wiphy_err(wiphy, "%s: Power level req != actual, %d %d"
382 "\n", __func__, conf->power_level,
385 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
386 if (conf->channel_type == NL80211_CHAN_HT20 ||
387 conf->channel_type == NL80211_CHAN_NO_HT)
388 err = brcms_c_set_channel(wl->wlc,
389 conf->channel->hw_value);
393 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
394 err = brcms_c_set_rate_limit(wl->wlc,
395 conf->short_frame_max_tx_count,
396 conf->long_frame_max_tx_count);
399 spin_unlock_bh(&wl->lock);
404 brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
405 struct ieee80211_vif *vif,
406 struct ieee80211_bss_conf *info, u32 changed)
408 struct brcms_info *wl = hw->priv;
409 struct wiphy *wiphy = hw->wiphy;
411 if (changed & BSS_CHANGED_ASSOC) {
412 /* association status changed (associated/disassociated)
413 * also implies a change in the AID.
415 wiphy_err(wiphy, "%s: %s: %sassociated\n", KBUILD_MODNAME,
416 __func__, info->assoc ? "" : "dis");
417 spin_lock_bh(&wl->lock);
418 brcms_c_associate_upd(wl->wlc, info->assoc);
419 spin_unlock_bh(&wl->lock);
421 if (changed & BSS_CHANGED_ERP_SLOT) {
424 /* slot timing changed */
425 if (info->use_short_slot)
429 spin_lock_bh(&wl->lock);
430 brcms_c_set_shortslot_override(wl->wlc, val);
431 spin_unlock_bh(&wl->lock);
434 if (changed & BSS_CHANGED_HT) {
435 /* 802.11n parameters changed */
436 u16 mode = info->ht_operation_mode;
438 spin_lock_bh(&wl->lock);
439 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
440 mode & IEEE80211_HT_OP_MODE_PROTECTION);
441 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
442 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
443 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
444 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
445 spin_unlock_bh(&wl->lock);
447 if (changed & BSS_CHANGED_BASIC_RATES) {
448 struct ieee80211_supported_band *bi;
451 struct brcm_rateset rs;
454 /* retrieve the current rates */
455 spin_lock_bh(&wl->lock);
456 brcms_c_get_current_rateset(wl->wlc, &rs);
457 spin_unlock_bh(&wl->lock);
459 br_mask = info->basic_rates;
460 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
461 for (i = 0; i < bi->n_bitrates; i++) {
462 /* convert to internal rate value */
463 rate = (bi->bitrates[i].bitrate << 1) / 10;
465 /* set/clear basic rate flag */
466 brcms_set_basic_rate(&rs, rate, br_mask & 1);
470 /* update the rate set */
471 spin_lock_bh(&wl->lock);
472 error = brcms_c_set_rateset(wl->wlc, &rs);
473 spin_unlock_bh(&wl->lock);
475 wiphy_err(wiphy, "changing basic rates failed: %d\n",
478 if (changed & BSS_CHANGED_BEACON_INT) {
479 /* Beacon interval changed */
480 spin_lock_bh(&wl->lock);
481 brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
482 spin_unlock_bh(&wl->lock);
484 if (changed & BSS_CHANGED_BSSID) {
485 /* BSSID changed, for whatever reason (IBSS and managed mode) */
486 spin_lock_bh(&wl->lock);
487 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
488 spin_unlock_bh(&wl->lock);
490 if (changed & BSS_CHANGED_BEACON)
491 /* Beacon data changed, retrieve new beacon (beaconing modes) */
492 wiphy_err(wiphy, "%s: beacon changed\n", __func__);
494 if (changed & BSS_CHANGED_BEACON_ENABLED) {
495 /* Beaconing should be enabled/disabled (beaconing modes) */
496 wiphy_err(wiphy, "%s: Beacon enabled: %s\n", __func__,
497 info->enable_beacon ? "true" : "false");
500 if (changed & BSS_CHANGED_CQM) {
501 /* Connection quality monitor config changed */
502 wiphy_err(wiphy, "%s: cqm change: threshold %d, hys %d "
503 " (implement)\n", __func__, info->cqm_rssi_thold,
504 info->cqm_rssi_hyst);
507 if (changed & BSS_CHANGED_IBSS) {
508 /* IBSS join status changed */
509 wiphy_err(wiphy, "%s: IBSS joined: %s (implement)\n", __func__,
510 info->ibss_joined ? "true" : "false");
513 if (changed & BSS_CHANGED_ARP_FILTER) {
514 /* Hardware ARP filter address list or state changed */
515 wiphy_err(wiphy, "%s: arp filtering: enabled %s, count %d"
516 " (implement)\n", __func__, info->arp_filter_enabled ?
517 "true" : "false", info->arp_addr_cnt);
520 if (changed & BSS_CHANGED_QOS) {
522 * QoS for this association was enabled/disabled.
523 * Note that it is only ever disabled for station mode.
525 wiphy_err(wiphy, "%s: qos enabled: %s (implement)\n", __func__,
526 info->qos ? "true" : "false");
532 brcms_ops_configure_filter(struct ieee80211_hw *hw,
533 unsigned int changed_flags,
534 unsigned int *total_flags, u64 multicast)
536 struct brcms_info *wl = hw->priv;
537 struct wiphy *wiphy = hw->wiphy;
539 changed_flags &= MAC_FILTERS;
540 *total_flags &= MAC_FILTERS;
541 if (changed_flags & FIF_PROMISC_IN_BSS)
542 wiphy_err(wiphy, "FIF_PROMISC_IN_BSS\n");
543 if (changed_flags & FIF_ALLMULTI)
544 wiphy_err(wiphy, "FIF_ALLMULTI\n");
545 if (changed_flags & FIF_FCSFAIL)
546 wiphy_err(wiphy, "FIF_FCSFAIL\n");
547 if (changed_flags & FIF_PLCPFAIL)
548 wiphy_err(wiphy, "FIF_PLCPFAIL\n");
549 if (changed_flags & FIF_CONTROL)
550 wiphy_err(wiphy, "FIF_CONTROL\n");
551 if (changed_flags & FIF_OTHER_BSS)
552 wiphy_err(wiphy, "FIF_OTHER_BSS\n");
553 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
554 spin_lock_bh(&wl->lock);
555 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
556 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
557 brcms_c_mac_bcn_promisc_change(wl->wlc, 1);
559 brcms_c_mac_bcn_promisc_change(wl->wlc, 0);
560 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
562 spin_unlock_bh(&wl->lock);
567 static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
569 struct brcms_info *wl = hw->priv;
570 spin_lock_bh(&wl->lock);
571 brcms_c_scan_start(wl->wlc);
572 spin_unlock_bh(&wl->lock);
576 static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
578 struct brcms_info *wl = hw->priv;
579 spin_lock_bh(&wl->lock);
580 brcms_c_scan_stop(wl->wlc);
581 spin_unlock_bh(&wl->lock);
586 brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
587 const struct ieee80211_tx_queue_params *params)
589 struct brcms_info *wl = hw->priv;
591 spin_lock_bh(&wl->lock);
592 brcms_c_wme_setparams(wl->wlc, queue, params, true);
593 spin_unlock_bh(&wl->lock);
599 brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
600 struct ieee80211_sta *sta)
602 struct brcms_info *wl = hw->priv;
603 struct scb *scb = &wl->wlc->pri_scb;
605 brcms_c_init_scb(scb);
607 wl->pub->global_ampdu = &(scb->scb_ampdu);
608 wl->pub->global_ampdu->scb = scb;
609 wl->pub->global_ampdu->max_pdu = 16;
611 sta->ht_cap.ht_supported = true;
612 sta->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
613 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
614 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
615 IEEE80211_HT_CAP_SGI_20 |
616 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT;
619 * minstrel_ht initiates addBA on our behalf by calling
620 * ieee80211_start_tx_ba_session()
626 brcms_ops_ampdu_action(struct ieee80211_hw *hw,
627 struct ieee80211_vif *vif,
628 enum ieee80211_ampdu_mlme_action action,
629 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
632 struct brcms_info *wl = hw->priv;
633 struct scb *scb = &wl->wlc->pri_scb;
636 if (WARN_ON(scb->magic != SCB_MAGIC))
639 case IEEE80211_AMPDU_RX_START:
641 case IEEE80211_AMPDU_RX_STOP:
643 case IEEE80211_AMPDU_TX_START:
644 spin_lock_bh(&wl->lock);
645 status = brcms_c_aggregatable(wl->wlc, tid);
646 spin_unlock_bh(&wl->lock);
648 wiphy_err(wl->wiphy, "START: tid %d is not agg\'able\n",
652 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
655 case IEEE80211_AMPDU_TX_STOP:
656 spin_lock_bh(&wl->lock);
657 brcms_c_ampdu_flush(wl->wlc, sta, tid);
658 spin_unlock_bh(&wl->lock);
659 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
661 case IEEE80211_AMPDU_TX_OPERATIONAL:
663 * BA window size from ADDBA response ('buf_size') defines how
664 * many outstanding MPDUs are allowed for the BA stream by
665 * recipient and traffic class. 'ampdu_factor' gives maximum
668 spin_lock_bh(&wl->lock);
669 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
670 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
671 sta->ht_cap.ampdu_factor)) - 1);
672 spin_unlock_bh(&wl->lock);
673 /* Power save wakeup */
676 wiphy_err(wl->wiphy, "%s: Invalid command, ignoring\n",
683 static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
685 struct brcms_info *wl = hw->priv;
688 spin_lock_bh(&wl->lock);
689 blocked = brcms_c_check_radio_disabled(wl->wlc);
690 spin_unlock_bh(&wl->lock);
692 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
695 static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
697 struct brcms_info *wl = hw->priv;
699 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
701 /* wait for packet queue and dma fifos to run empty */
702 spin_lock_bh(&wl->lock);
703 brcms_c_wait_for_tx_completion(wl->wlc, drop);
704 spin_unlock_bh(&wl->lock);
707 static const struct ieee80211_ops brcms_ops = {
709 .start = brcms_ops_start,
710 .stop = brcms_ops_stop,
711 .add_interface = brcms_ops_add_interface,
712 .remove_interface = brcms_ops_remove_interface,
713 .config = brcms_ops_config,
714 .bss_info_changed = brcms_ops_bss_info_changed,
715 .configure_filter = brcms_ops_configure_filter,
716 .sw_scan_start = brcms_ops_sw_scan_start,
717 .sw_scan_complete = brcms_ops_sw_scan_complete,
718 .conf_tx = brcms_ops_conf_tx,
719 .sta_add = brcms_ops_sta_add,
720 .ampdu_action = brcms_ops_ampdu_action,
721 .rfkill_poll = brcms_ops_rfkill_poll,
722 .flush = brcms_ops_flush,
726 * is called in brcms_pci_probe() context, therefore no locking required.
728 static int brcms_set_hint(struct brcms_info *wl, char *abbrev)
730 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
733 void brcms_dpc(unsigned long data)
735 struct brcms_info *wl;
737 wl = (struct brcms_info *) data;
739 spin_lock_bh(&wl->lock);
741 /* call the common second level interrupt handler */
746 spin_lock_irqsave(&wl->isr_lock, flags);
747 brcms_c_intrsupd(wl->wlc);
748 spin_unlock_irqrestore(&wl->isr_lock, flags);
751 wl->resched = brcms_c_dpc(wl->wlc, true);
754 /* brcms_c_dpc() may bring the driver down */
758 /* re-schedule dpc */
760 tasklet_schedule(&wl->tasklet);
762 /* re-enable interrupts */
766 spin_unlock_bh(&wl->lock);
770 * Precondition: Since this function is called in brcms_pci_probe() context,
771 * no locking is required.
773 static int brcms_request_fw(struct brcms_info *wl, struct pci_dev *pdev)
776 struct device *device = &pdev->dev;
780 memset(&wl->fw, 0, sizeof(struct brcms_firmware));
781 for (i = 0; i < MAX_FW_IMAGES; i++) {
782 if (brcms_firmwares[i] == NULL)
784 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
785 UCODE_LOADER_API_VER);
786 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
788 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
789 KBUILD_MODNAME, fw_name);
792 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
793 UCODE_LOADER_API_VER);
794 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
796 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
797 KBUILD_MODNAME, fw_name);
800 wl->fw.hdr_num_entries[i] =
801 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
804 return brcms_ucode_data_init(wl, &wl->ucode);
808 * Precondition: Since this function is called in brcms_pci_probe() context,
809 * no locking is required.
811 static void brcms_release_fw(struct brcms_info *wl)
814 for (i = 0; i < MAX_FW_IMAGES; i++) {
815 release_firmware(wl->fw.fw_bin[i]);
816 release_firmware(wl->fw.fw_hdr[i]);
821 * This function frees the WL per-device resources.
823 * This function frees resources owned by the WL device pointed to
824 * by the wl parameter.
826 * precondition: can both be called locked and unlocked
829 static void brcms_free(struct brcms_info *wl)
831 struct brcms_timer *t, *next;
833 /* free ucode data */
835 brcms_ucode_data_free(&wl->ucode);
837 free_irq(wl->irq, wl);
840 tasklet_kill(&wl->tasklet);
843 brcms_c_module_unregister(wl->pub, "linux", wl);
845 /* free common resources */
847 brcms_c_detach(wl->wlc);
852 /* virtual interface deletion is deferred so we cannot spinwait */
854 /* wait for all pending callbacks to complete */
855 while (atomic_read(&wl->callbacks) > 0)
859 for (t = wl->timers; t; t = next) {
868 * unregister_netdev() calls get_stats() which may read chip
869 * registers so we cannot unmap the chip registers until
870 * after calling unregister_netdev() .
879 * called from both kernel as from this kernel module.
880 * precondition: perimeter lock is not acquired.
882 static void brcms_remove(struct pci_dev *pdev)
884 struct brcms_info *wl;
885 struct ieee80211_hw *hw;
888 hw = pci_get_drvdata(pdev);
891 pr_err("wl: brcms_remove: pci_get_drvdata failed\n");
895 spin_lock_bh(&wl->lock);
896 status = brcms_c_chipmatch(pdev->vendor, pdev->device);
897 spin_unlock_bh(&wl->lock);
899 wiphy_err(wl->wiphy, "wl: brcms_remove: chipmatch "
904 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
905 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
906 ieee80211_unregister_hw(hw);
907 spin_lock_bh(&wl->lock);
909 spin_unlock_bh(&wl->lock);
911 pci_disable_device(pdev);
915 pci_set_drvdata(pdev, NULL);
916 ieee80211_free_hw(hw);
919 static irqreturn_t brcms_isr(int irq, void *dev_id)
921 struct brcms_info *wl;
924 wl = (struct brcms_info *) dev_id;
926 spin_lock(&wl->isr_lock);
928 /* call common first level interrupt handler */
929 ours = brcms_c_isr(wl->wlc, &wantdpc);
931 /* if more to do... */
934 /* ...and call the second level interrupt handler */
936 tasklet_schedule(&wl->tasklet);
940 spin_unlock(&wl->isr_lock);
942 return IRQ_RETVAL(ours);
946 * is called in brcms_pci_probe() context, therefore no locking required.
948 static int ieee_hw_rate_init(struct ieee80211_hw *hw)
950 struct brcms_info *wl = hw->priv;
951 struct brcms_c_info *wlc = wl->wlc;
952 struct ieee80211_supported_band *band;
956 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
957 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
959 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
960 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
961 band = &wlc->bandstate[BAND_2G_INDEX]->band;
962 *band = brcms_band_2GHz_nphy_template;
963 if (phy_type == PHY_TYPE_LCN) {
965 band->ht_cap.mcs.rx_mask[1] = 0;
966 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
968 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
973 /* Assume all bands use the same phy. True for 11n devices. */
974 if (wl->pub->_nbands > 1) {
976 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
977 band = &wlc->bandstate[BAND_5G_INDEX]->band;
978 *band = brcms_band_5GHz_nphy_template;
979 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
988 * is called in brcms_pci_probe() context, therefore no locking required.
990 static int ieee_hw_init(struct ieee80211_hw *hw)
992 hw->flags = IEEE80211_HW_SIGNAL_DBM
993 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
994 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
995 | IEEE80211_HW_AMPDU_AGGREGATION;
997 hw->extra_tx_headroom = brcms_c_get_header_len();
998 hw->queues = N_TX_QUEUES;
999 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
1001 /* channel change time is dependent on chip and band */
1002 hw->channel_change_time = 7 * 1000;
1003 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
1005 hw->rate_control_algorithm = "minstrel_ht";
1007 hw->sta_data_size = 0;
1008 return ieee_hw_rate_init(hw);
1012 * attach to the WL device.
1014 * Attach to the WL device identified by vendor and device parameters.
1015 * regs is a host accessible memory address pointing to WL device registers.
1017 * brcms_attach is not defined as static because in the case where no bus
1018 * is defined, wl_attach will never be called, and thus, gcc will issue
1019 * a warning that this function is defined but not used if we declare
1023 * is called in brcms_pci_probe() context, therefore no locking required.
1025 static struct brcms_info *brcms_attach(u16 vendor, u16 device,
1026 resource_size_t regs,
1027 struct pci_dev *btparam, uint irq)
1029 struct brcms_info *wl = NULL;
1031 struct ieee80211_hw *hw;
1034 unit = n_adapters_found;
1040 /* allocate private info */
1041 hw = pci_get_drvdata(btparam); /* btparam == pdev */
1044 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1046 wl->wiphy = hw->wiphy;
1048 atomic_set(&wl->callbacks, 0);
1050 /* setup the bottom half handler */
1051 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1053 wl->regsva = ioremap_nocache(regs, PCI_BAR0_WINSZ);
1054 if (wl->regsva == NULL) {
1055 wiphy_err(wl->wiphy, "wl%d: ioremap() failed\n", unit);
1058 spin_lock_init(&wl->lock);
1059 spin_lock_init(&wl->isr_lock);
1062 if (brcms_request_fw(wl, btparam) < 0) {
1063 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
1064 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
1065 brcms_release_fw(wl);
1066 brcms_remove(btparam);
1070 /* common load-time initialization */
1071 wl->wlc = brcms_c_attach(wl, vendor, device, unit, false,
1072 wl->regsva, btparam, &err);
1073 brcms_release_fw(wl);
1075 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1076 KBUILD_MODNAME, err);
1079 wl->pub = brcms_c_pub(wl->wlc);
1081 wl->pub->ieee_hw = hw;
1084 brcms_c_set_radio_mpc(wl->wlc, false);
1086 /* register our interrupt handler */
1087 if (request_irq(irq, brcms_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
1088 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1093 /* register module */
1094 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1096 if (ieee_hw_init(hw)) {
1097 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1102 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1103 if (WARN_ON(!is_valid_ether_addr(perm)))
1105 SET_IEEE80211_PERM_ADDR(hw, perm);
1107 err = ieee80211_register_hw(hw);
1109 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1110 "%d\n", __func__, err);
1112 if (wl->pub->srom_ccode[0])
1113 err = brcms_set_hint(wl, wl->pub->srom_ccode);
1115 err = brcms_set_hint(wl, "US");
1117 wiphy_err(wl->wiphy, "%s: regulatory_hint failed, status %d\n",
1131 * determines if a device is a WL device, and if so, attaches it.
1133 * This function determines if a device pointed to by pdev is a WL device,
1134 * and if so, performs a brcms_attach() on it.
1136 * Perimeter lock is initialized in the course of this function.
1138 static int __devinit
1139 brcms_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1142 struct brcms_info *wl;
1143 struct ieee80211_hw *hw;
1146 dev_info(&pdev->dev, "bus %d slot %d func %d irq %d\n",
1147 pdev->bus->number, PCI_SLOT(pdev->devfn),
1148 PCI_FUNC(pdev->devfn), pdev->irq);
1150 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1151 ((pdev->device != 0x0576) &&
1152 ((pdev->device & 0xff00) != 0x4300) &&
1153 ((pdev->device & 0xff00) != 0x4700) &&
1154 ((pdev->device < 43000) || (pdev->device > 43999))))
1157 rc = pci_enable_device(pdev);
1159 pr_err("%s: Cannot enable device %d-%d_%d\n",
1160 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1161 PCI_FUNC(pdev->devfn));
1164 pci_set_master(pdev);
1166 pci_read_config_dword(pdev, 0x40, &val);
1167 if ((val & 0x0000ff00) != 0)
1168 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1170 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1172 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1176 SET_IEEE80211_DEV(hw, &pdev->dev);
1178 pci_set_drvdata(pdev, hw);
1180 memset(hw->priv, 0, sizeof(*wl));
1182 wl = brcms_attach(pdev->vendor, pdev->device,
1183 pci_resource_start(pdev, 0), pdev,
1187 pr_err("%s: %s: brcms_attach failed!\n", KBUILD_MODNAME,
1194 static int brcms_suspend(struct pci_dev *pdev, pm_message_t state)
1196 struct brcms_info *wl;
1197 struct ieee80211_hw *hw;
1199 hw = pci_get_drvdata(pdev);
1202 wiphy_err(wl->wiphy,
1203 "brcms_suspend: pci_get_drvdata failed\n");
1207 /* only need to flag hw is down for proper resume */
1208 spin_lock_bh(&wl->lock);
1209 wl->pub->hw_up = false;
1210 spin_unlock_bh(&wl->lock);
1212 pci_save_state(pdev);
1213 pci_disable_device(pdev);
1214 return pci_set_power_state(pdev, PCI_D3hot);
1217 static int brcms_resume(struct pci_dev *pdev)
1219 struct brcms_info *wl;
1220 struct ieee80211_hw *hw;
1224 hw = pci_get_drvdata(pdev);
1227 wiphy_err(wl->wiphy,
1228 "wl: brcms_resume: pci_get_drvdata failed\n");
1232 err = pci_set_power_state(pdev, PCI_D0);
1236 pci_restore_state(pdev);
1238 err = pci_enable_device(pdev);
1242 pci_set_master(pdev);
1244 pci_read_config_dword(pdev, 0x40, &val);
1245 if ((val & 0x0000ff00) != 0)
1246 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1249 * done. driver will be put in up state
1250 * in brcms_ops_add_interface() call.
1255 static struct pci_driver brcms_pci_driver = {
1256 .name = KBUILD_MODNAME,
1257 .probe = brcms_pci_probe,
1258 .suspend = brcms_suspend,
1259 .resume = brcms_resume,
1260 .remove = __devexit_p(brcms_remove),
1261 .id_table = brcms_pci_id_table,
1265 * This is the main entry point for the WL driver.
1267 * This function determines if a device pointed to by pdev is a WL device,
1268 * and if so, performs a brcms_attach() on it.
1271 static int __init brcms_module_init(void)
1273 int error = -ENODEV;
1276 if (msglevel != 0xdeadbeef)
1277 brcm_msg_level = msglevel;
1280 error = pci_register_driver(&brcms_pci_driver);
1290 * This function unloads the WL driver from the system.
1292 * This function unconditionally unloads the WL driver module from the
1296 static void __exit brcms_module_exit(void)
1298 pci_unregister_driver(&brcms_pci_driver);
1302 module_init(brcms_module_init);
1303 module_exit(brcms_module_exit);
1306 * precondition: perimeter lock has been acquired
1308 void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1309 bool state, int prio)
1311 wiphy_err(wl->wiphy, "Shouldn't be here %s\n", __func__);
1315 * precondition: perimeter lock has been acquired
1317 void brcms_init(struct brcms_info *wl)
1319 BCMMSG(wl->pub->ieee_hw->wiphy, "wl%d\n", wl->pub->unit);
1322 brcms_c_init(wl->wlc);
1326 * precondition: perimeter lock has been acquired
1328 uint brcms_reset(struct brcms_info *wl)
1330 BCMMSG(wl->pub->ieee_hw->wiphy, "wl%d\n", wl->pub->unit);
1331 brcms_c_reset(wl->wlc);
1333 /* dpc will not be rescheduled */
1340 * These are interrupt on/off entry points. Disable interrupts
1341 * during interrupt state transition.
1343 void brcms_intrson(struct brcms_info *wl)
1345 unsigned long flags;
1347 spin_lock_irqsave(&wl->isr_lock, flags);
1348 brcms_c_intrson(wl->wlc);
1349 spin_unlock_irqrestore(&wl->isr_lock, flags);
1352 u32 brcms_intrsoff(struct brcms_info *wl)
1354 unsigned long flags;
1357 spin_lock_irqsave(&wl->isr_lock, flags);
1358 status = brcms_c_intrsoff(wl->wlc);
1359 spin_unlock_irqrestore(&wl->isr_lock, flags);
1363 void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1365 unsigned long flags;
1367 spin_lock_irqsave(&wl->isr_lock, flags);
1368 brcms_c_intrsrestore(wl->wlc, macintmask);
1369 spin_unlock_irqrestore(&wl->isr_lock, flags);
1373 * precondition: perimeter lock has been acquired
1375 int brcms_up(struct brcms_info *wl)
1382 error = brcms_c_up(wl->wlc);
1388 * precondition: perimeter lock has been acquired
1390 void brcms_down(struct brcms_info *wl)
1392 uint callbacks, ret_val = 0;
1394 /* call common down function */
1395 ret_val = brcms_c_down(wl->wlc);
1396 callbacks = atomic_read(&wl->callbacks) - ret_val;
1398 /* wait for down callbacks to complete */
1399 spin_unlock_bh(&wl->lock);
1401 /* For HIGH_only driver, it's important to actually schedule other work,
1402 * not just spin wait since everything runs at schedule level
1404 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1406 spin_lock_bh(&wl->lock);
1410 * precondition: perimeter lock is not acquired
1412 static void _brcms_timer(struct work_struct *work)
1414 struct brcms_timer *t = container_of(work, struct brcms_timer,
1417 spin_lock_bh(&t->wl->lock);
1421 atomic_inc(&t->wl->callbacks);
1422 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1424 msecs_to_jiffies(t->ms));
1432 atomic_dec(&t->wl->callbacks);
1434 spin_unlock_bh(&t->wl->lock);
1438 * Adds a timer to the list. Caller supplies a timer function.
1439 * Is called from wlc.
1441 * precondition: perimeter lock has been acquired
1443 struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1444 void (*fn) (void *arg),
1445 void *arg, const char *name)
1447 struct brcms_timer *t;
1449 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1453 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
1457 t->next = wl->timers;
1461 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1463 strcpy(t->name, name);
1470 * adds only the kernel timer since it's going to be more accurate
1471 * as well as it's easier to make it periodic
1473 * precondition: perimeter lock has been acquired
1475 void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
1477 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1481 wiphy_err(hw->wiphy, "%s: Already set. Name: %s, per %d\n",
1482 __func__, t->name, periodic);
1485 t->periodic = (bool) periodic;
1488 atomic_inc(&t->wl->callbacks);
1490 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
1494 * return true if timer successfully deleted, false if still pending
1496 * precondition: perimeter lock has been acquired
1498 bool brcms_del_timer(struct brcms_timer *t)
1502 if (!cancel_delayed_work(&t->dly_wrk))
1505 atomic_dec(&t->wl->callbacks);
1512 * precondition: perimeter lock has been acquired
1514 void brcms_free_timer(struct brcms_timer *t)
1516 struct brcms_info *wl = t->wl;
1517 struct brcms_timer *tmp;
1519 /* delete the timer in case it is active */
1522 if (wl->timers == t) {
1523 wl->timers = wl->timers->next;
1534 if (tmp->next == t) {
1535 tmp->next = t->next;
1548 * precondition: perimeter lock has been acquired
1550 int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1554 struct firmware_hdr *hdr;
1555 for (i = 0; i < wl->fw.fw_cnt; i++) {
1556 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1557 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1559 u32 len = le32_to_cpu(hdr->len);
1560 if (le32_to_cpu(hdr->idx) == idx) {
1561 pdata = wl->fw.fw_bin[i]->data +
1562 le32_to_cpu(hdr->offset);
1563 *pbuf = kmalloc(len, GFP_ATOMIC);
1567 memcpy(*pbuf, pdata, len);
1572 wiphy_err(wl->wiphy, "ERROR: ucode buf tag:%d can not be found!\n",
1580 * Precondition: Since this function is called in brcms_pci_probe() context,
1581 * no locking is required.
1583 int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1587 struct firmware_hdr *hdr;
1588 for (i = 0; i < wl->fw.fw_cnt; i++) {
1589 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1590 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1592 if (le32_to_cpu(hdr->idx) == idx) {
1593 pdata = wl->fw.fw_bin[i]->data +
1594 le32_to_cpu(hdr->offset);
1595 if (le32_to_cpu(hdr->len) != 4) {
1596 wiphy_err(wl->wiphy,
1597 "ERROR: fw hdr len\n");
1600 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1605 wiphy_err(wl->wiphy, "ERROR: ucode tag:%d can not be found!\n", idx);
1610 * precondition: can both be called locked and unlocked
1612 void brcms_ucode_free_buf(void *p)
1618 * checks validity of all firmware images loaded from user space
1620 * Precondition: Since this function is called in brcms_pci_probe() context,
1621 * no locking is required.
1623 int brcms_check_firmwares(struct brcms_info *wl)
1628 const struct firmware *fw;
1629 const struct firmware *fw_hdr;
1630 struct firmware_hdr *ucode_hdr;
1631 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1632 fw = wl->fw.fw_bin[i];
1633 fw_hdr = wl->fw.fw_hdr[i];
1634 if (fw == NULL && fw_hdr == NULL) {
1636 } else if (fw == NULL || fw_hdr == NULL) {
1637 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1640 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1641 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1642 "size %zu/%zu\n", __func__, fw_hdr->size,
1643 sizeof(struct firmware_hdr));
1645 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1646 wiphy_err(wl->wiphy, "%s: out of bounds fw file size "
1647 "%zu\n", __func__, fw->size);
1650 /* check if ucode section overruns firmware image */
1651 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1652 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1653 !rc; entry++, ucode_hdr++) {
1654 if (le32_to_cpu(ucode_hdr->offset) +
1655 le32_to_cpu(ucode_hdr->len) >
1657 wiphy_err(wl->wiphy,
1658 "%s: conflicting bin/hdr\n",
1665 if (rc == 0 && wl->fw.fw_cnt != i) {
1666 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1674 * precondition: perimeter lock has been acquired
1676 bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1678 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1680 spin_unlock_bh(&wl->lock);
1681 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1683 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1684 spin_lock_bh(&wl->lock);
1689 * precondition: perimeter lock has been acquired
1691 void brcms_msleep(struct brcms_info *wl, uint ms)
1693 spin_unlock_bh(&wl->lock);
1695 spin_lock_bh(&wl->lock);