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"
37 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
39 /* Flags we support */
40 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
45 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");
91 /* recognized BCMA Core IDs */
92 static struct bcma_device_id brcms_coreid_table
[] = {
93 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 23, BCMA_ANY_CLASS
),
94 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 24, BCMA_ANY_CLASS
),
97 MODULE_DEVICE_TABLE(bcma
, brcms_coreid_table
);
100 static int msglevel
= 0xdeadbeef;
101 module_param(msglevel
, int, 0);
104 static struct ieee80211_channel brcms_2ghz_chantable
[] = {
105 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS
),
106 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS
),
107 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS
),
108 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS
),
109 CHAN2GHZ(5, 2432, 0),
110 CHAN2GHZ(6, 2437, 0),
111 CHAN2GHZ(7, 2442, 0),
112 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS
),
113 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS
),
114 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS
),
115 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS
),
117 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
118 IEEE80211_CHAN_NO_HT40PLUS
),
120 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
121 IEEE80211_CHAN_NO_HT40PLUS
),
123 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
124 IEEE80211_CHAN_NO_HT40PLUS
| IEEE80211_CHAN_NO_HT40MINUS
|
125 IEEE80211_CHAN_NO_OFDM
)
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
| IEEE80211_HT_CAP_SGI_40
,
219 .ht_supported
= true,
220 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
221 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
223 /* placeholders for now */
224 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
225 .rx_highest
= cpu_to_le16(500),
226 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
230 static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template
= {
231 .band
= IEEE80211_BAND_5GHZ
,
232 .channels
= brcms_5ghz_nphy_chantable
,
233 .n_channels
= ARRAY_SIZE(brcms_5ghz_nphy_chantable
),
234 .bitrates
= legacy_ratetable
+ BRCMS_LEGACY_5G_RATE_OFFSET
,
235 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
) -
236 BRCMS_LEGACY_5G_RATE_OFFSET
,
238 .cap
= IEEE80211_HT_CAP_GRN_FLD
| IEEE80211_HT_CAP_SGI_20
|
239 IEEE80211_HT_CAP_SGI_40
,
240 .ht_supported
= true,
241 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
242 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
244 /* placeholders for now */
245 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
246 .rx_highest
= cpu_to_le16(500),
247 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
251 /* flags the given rate in rateset as requested */
252 static void brcms_set_basic_rate(struct brcm_rateset
*rs
, u16 rate
, bool is_br
)
256 for (i
= 0; i
< rs
->count
; i
++) {
257 if (rate
!= (rs
->rates
[i
] & 0x7f))
261 rs
->rates
[i
] |= BRCMS_RATE_FLAG
;
263 rs
->rates
[i
] &= BRCMS_RATE_MASK
;
268 static void brcms_ops_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
270 struct brcms_info
*wl
= hw
->priv
;
271 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
273 spin_lock_bh(&wl
->lock
);
275 wiphy_err(wl
->wiphy
, "ops->tx called while down\n");
279 brcms_c_sendpkt_mac80211(wl
->wlc
, skb
, hw
);
280 tx_info
->rate_driver_data
[0] = tx_info
->control
.sta
;
282 spin_unlock_bh(&wl
->lock
);
285 static int brcms_ops_start(struct ieee80211_hw
*hw
)
287 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
);
298 spin_lock_bh(&wl
->lock
);
299 /* avoid acknowledging frames before a non-monitor device is added */
306 spin_unlock_bh(&wl
->lock
);
309 wiphy_err(hw
->wiphy
, "%s: brcms_up() returned %d\n", __func__
,
314 static void brcms_ops_stop(struct ieee80211_hw
*hw
)
316 struct brcms_info
*wl
= hw
->priv
;
319 ieee80211_stop_queues(hw
);
324 spin_lock_bh(&wl
->lock
);
325 status
= brcms_c_chipmatch(wl
->wlc
->hw
->d11core
);
326 spin_unlock_bh(&wl
->lock
);
329 "wl: brcms_ops_stop: chipmatch failed\n");
333 /* put driver in down state */
334 spin_lock_bh(&wl
->lock
);
336 spin_unlock_bh(&wl
->lock
);
340 brcms_ops_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
342 struct brcms_info
*wl
= hw
->priv
;
344 /* Just STA for now */
345 if (vif
->type
!= NL80211_IFTYPE_STATION
) {
346 wiphy_err(hw
->wiphy
, "%s: Attempt to add type %d, only"
347 " STA for now\n", __func__
, vif
->type
);
352 brcms_c_mute(wl
->wlc
, false);
358 brcms_ops_remove_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
362 static int brcms_ops_config(struct ieee80211_hw
*hw
, u32 changed
)
364 struct ieee80211_conf
*conf
= &hw
->conf
;
365 struct brcms_info
*wl
= hw
->priv
;
368 struct wiphy
*wiphy
= hw
->wiphy
;
370 spin_lock_bh(&wl
->lock
);
371 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
372 brcms_c_set_beacon_listen_interval(wl
->wlc
,
373 conf
->listen_interval
);
375 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
)
376 wiphy_dbg(wiphy
, "%s: change monitor mode: %s\n",
377 __func__
, conf
->flags
& IEEE80211_CONF_MONITOR
?
379 if (changed
& IEEE80211_CONF_CHANGE_PS
)
380 wiphy_err(wiphy
, "%s: change power-save mode: %s (implement)\n",
381 __func__
, conf
->flags
& IEEE80211_CONF_PS
?
384 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
385 err
= brcms_c_set_tx_power(wl
->wlc
, conf
->power_level
);
387 wiphy_err(wiphy
, "%s: Error setting power_level\n",
391 new_int
= brcms_c_get_tx_power(wl
->wlc
);
392 if (new_int
!= conf
->power_level
)
393 wiphy_err(wiphy
, "%s: Power level req != actual, %d %d"
394 "\n", __func__
, conf
->power_level
,
397 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
398 if (conf
->channel_type
== NL80211_CHAN_HT20
||
399 conf
->channel_type
== NL80211_CHAN_NO_HT
)
400 err
= brcms_c_set_channel(wl
->wlc
,
401 conf
->channel
->hw_value
);
405 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
)
406 err
= brcms_c_set_rate_limit(wl
->wlc
,
407 conf
->short_frame_max_tx_count
,
408 conf
->long_frame_max_tx_count
);
411 spin_unlock_bh(&wl
->lock
);
416 brcms_ops_bss_info_changed(struct ieee80211_hw
*hw
,
417 struct ieee80211_vif
*vif
,
418 struct ieee80211_bss_conf
*info
, u32 changed
)
420 struct brcms_info
*wl
= hw
->priv
;
421 struct wiphy
*wiphy
= hw
->wiphy
;
423 if (changed
& BSS_CHANGED_ASSOC
) {
424 /* association status changed (associated/disassociated)
425 * also implies a change in the AID.
427 wiphy_err(wiphy
, "%s: %s: %sassociated\n", KBUILD_MODNAME
,
428 __func__
, info
->assoc
? "" : "dis");
429 spin_lock_bh(&wl
->lock
);
430 brcms_c_associate_upd(wl
->wlc
, info
->assoc
);
431 spin_unlock_bh(&wl
->lock
);
433 if (changed
& BSS_CHANGED_ERP_SLOT
) {
436 /* slot timing changed */
437 if (info
->use_short_slot
)
441 spin_lock_bh(&wl
->lock
);
442 brcms_c_set_shortslot_override(wl
->wlc
, val
);
443 spin_unlock_bh(&wl
->lock
);
446 if (changed
& BSS_CHANGED_HT
) {
447 /* 802.11n parameters changed */
448 u16 mode
= info
->ht_operation_mode
;
450 spin_lock_bh(&wl
->lock
);
451 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_CFG
,
452 mode
& IEEE80211_HT_OP_MODE_PROTECTION
);
453 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_NONGF
,
454 mode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
455 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_OBSS
,
456 mode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
);
457 spin_unlock_bh(&wl
->lock
);
459 if (changed
& BSS_CHANGED_BASIC_RATES
) {
460 struct ieee80211_supported_band
*bi
;
463 struct brcm_rateset rs
;
466 /* retrieve the current rates */
467 spin_lock_bh(&wl
->lock
);
468 brcms_c_get_current_rateset(wl
->wlc
, &rs
);
469 spin_unlock_bh(&wl
->lock
);
471 br_mask
= info
->basic_rates
;
472 bi
= hw
->wiphy
->bands
[brcms_c_get_curband(wl
->wlc
)];
473 for (i
= 0; i
< bi
->n_bitrates
; i
++) {
474 /* convert to internal rate value */
475 rate
= (bi
->bitrates
[i
].bitrate
<< 1) / 10;
477 /* set/clear basic rate flag */
478 brcms_set_basic_rate(&rs
, rate
, br_mask
& 1);
482 /* update the rate set */
483 spin_lock_bh(&wl
->lock
);
484 error
= brcms_c_set_rateset(wl
->wlc
, &rs
);
485 spin_unlock_bh(&wl
->lock
);
487 wiphy_err(wiphy
, "changing basic rates failed: %d\n",
490 if (changed
& BSS_CHANGED_BEACON_INT
) {
491 /* Beacon interval changed */
492 spin_lock_bh(&wl
->lock
);
493 brcms_c_set_beacon_period(wl
->wlc
, info
->beacon_int
);
494 spin_unlock_bh(&wl
->lock
);
496 if (changed
& BSS_CHANGED_BSSID
) {
497 /* BSSID changed, for whatever reason (IBSS and managed mode) */
498 spin_lock_bh(&wl
->lock
);
499 brcms_c_set_addrmatch(wl
->wlc
, RCM_BSSID_OFFSET
, info
->bssid
);
500 spin_unlock_bh(&wl
->lock
);
502 if (changed
& BSS_CHANGED_BEACON
)
503 /* Beacon data changed, retrieve new beacon (beaconing modes) */
504 wiphy_err(wiphy
, "%s: beacon changed\n", __func__
);
506 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
507 /* Beaconing should be enabled/disabled (beaconing modes) */
508 wiphy_err(wiphy
, "%s: Beacon enabled: %s\n", __func__
,
509 info
->enable_beacon
? "true" : "false");
512 if (changed
& BSS_CHANGED_CQM
) {
513 /* Connection quality monitor config changed */
514 wiphy_err(wiphy
, "%s: cqm change: threshold %d, hys %d "
515 " (implement)\n", __func__
, info
->cqm_rssi_thold
,
516 info
->cqm_rssi_hyst
);
519 if (changed
& BSS_CHANGED_IBSS
) {
520 /* IBSS join status changed */
521 wiphy_err(wiphy
, "%s: IBSS joined: %s (implement)\n", __func__
,
522 info
->ibss_joined
? "true" : "false");
525 if (changed
& BSS_CHANGED_ARP_FILTER
) {
526 /* Hardware ARP filter address list or state changed */
527 wiphy_err(wiphy
, "%s: arp filtering: enabled %s, count %d"
528 " (implement)\n", __func__
, info
->arp_filter_enabled
?
529 "true" : "false", info
->arp_addr_cnt
);
532 if (changed
& BSS_CHANGED_QOS
) {
534 * QoS for this association was enabled/disabled.
535 * Note that it is only ever disabled for station mode.
537 wiphy_err(wiphy
, "%s: qos enabled: %s (implement)\n", __func__
,
538 info
->qos
? "true" : "false");
544 brcms_ops_configure_filter(struct ieee80211_hw
*hw
,
545 unsigned int changed_flags
,
546 unsigned int *total_flags
, u64 multicast
)
548 struct brcms_info
*wl
= hw
->priv
;
549 struct wiphy
*wiphy
= hw
->wiphy
;
551 changed_flags
&= MAC_FILTERS
;
552 *total_flags
&= MAC_FILTERS
;
554 if (changed_flags
& FIF_PROMISC_IN_BSS
)
555 wiphy_dbg(wiphy
, "FIF_PROMISC_IN_BSS\n");
556 if (changed_flags
& FIF_ALLMULTI
)
557 wiphy_dbg(wiphy
, "FIF_ALLMULTI\n");
558 if (changed_flags
& FIF_FCSFAIL
)
559 wiphy_dbg(wiphy
, "FIF_FCSFAIL\n");
560 if (changed_flags
& FIF_CONTROL
)
561 wiphy_dbg(wiphy
, "FIF_CONTROL\n");
562 if (changed_flags
& FIF_OTHER_BSS
)
563 wiphy_dbg(wiphy
, "FIF_OTHER_BSS\n");
564 if (changed_flags
& FIF_PSPOLL
)
565 wiphy_dbg(wiphy
, "FIF_PSPOLL\n");
566 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
)
567 wiphy_dbg(wiphy
, "FIF_BCN_PRBRESP_PROMISC\n");
569 spin_lock_bh(&wl
->lock
);
570 brcms_c_mac_promisc(wl
->wlc
, *total_flags
);
571 spin_unlock_bh(&wl
->lock
);
575 static void brcms_ops_sw_scan_start(struct ieee80211_hw
*hw
)
577 struct brcms_info
*wl
= hw
->priv
;
578 spin_lock_bh(&wl
->lock
);
579 brcms_c_scan_start(wl
->wlc
);
580 spin_unlock_bh(&wl
->lock
);
584 static void brcms_ops_sw_scan_complete(struct ieee80211_hw
*hw
)
586 struct brcms_info
*wl
= hw
->priv
;
587 spin_lock_bh(&wl
->lock
);
588 brcms_c_scan_stop(wl
->wlc
);
589 spin_unlock_bh(&wl
->lock
);
594 brcms_ops_conf_tx(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
, u16 queue
,
595 const struct ieee80211_tx_queue_params
*params
)
597 struct brcms_info
*wl
= hw
->priv
;
599 spin_lock_bh(&wl
->lock
);
600 brcms_c_wme_setparams(wl
->wlc
, queue
, params
, true);
601 spin_unlock_bh(&wl
->lock
);
607 brcms_ops_sta_add(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
608 struct ieee80211_sta
*sta
)
610 struct brcms_info
*wl
= hw
->priv
;
611 struct scb
*scb
= &wl
->wlc
->pri_scb
;
613 brcms_c_init_scb(scb
);
615 wl
->pub
->global_ampdu
= &(scb
->scb_ampdu
);
616 wl
->pub
->global_ampdu
->scb
= scb
;
617 wl
->pub
->global_ampdu
->max_pdu
= 16;
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
,
726 void brcms_dpc(unsigned long data
)
728 struct brcms_info
*wl
;
730 wl
= (struct brcms_info
*) data
;
732 spin_lock_bh(&wl
->lock
);
734 /* call the common second level interrupt handler */
739 spin_lock_irqsave(&wl
->isr_lock
, flags
);
740 brcms_c_intrsupd(wl
->wlc
);
741 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
744 wl
->resched
= brcms_c_dpc(wl
->wlc
, true);
747 /* brcms_c_dpc() may bring the driver down */
751 /* re-schedule dpc */
753 tasklet_schedule(&wl
->tasklet
);
755 /* re-enable interrupts */
759 spin_unlock_bh(&wl
->lock
);
763 * Precondition: Since this function is called in brcms_pci_probe() context,
764 * no locking is required.
766 static int brcms_request_fw(struct brcms_info
*wl
, struct bcma_device
*pdev
)
769 struct device
*device
= &pdev
->dev
;
773 memset(&wl
->fw
, 0, sizeof(struct brcms_firmware
));
774 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
775 if (brcms_firmwares
[i
] == NULL
)
777 sprintf(fw_name
, "%s-%d.fw", brcms_firmwares
[i
],
778 UCODE_LOADER_API_VER
);
779 status
= request_firmware(&wl
->fw
.fw_bin
[i
], fw_name
, device
);
781 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
782 KBUILD_MODNAME
, fw_name
);
785 sprintf(fw_name
, "%s_hdr-%d.fw", brcms_firmwares
[i
],
786 UCODE_LOADER_API_VER
);
787 status
= request_firmware(&wl
->fw
.fw_hdr
[i
], fw_name
, device
);
789 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
790 KBUILD_MODNAME
, fw_name
);
793 wl
->fw
.hdr_num_entries
[i
] =
794 wl
->fw
.fw_hdr
[i
]->size
/ (sizeof(struct firmware_hdr
));
797 return brcms_ucode_data_init(wl
, &wl
->ucode
);
801 * Precondition: Since this function is called in brcms_pci_probe() context,
802 * no locking is required.
804 static void brcms_release_fw(struct brcms_info
*wl
)
807 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
808 release_firmware(wl
->fw
.fw_bin
[i
]);
809 release_firmware(wl
->fw
.fw_hdr
[i
]);
814 * This function frees the WL per-device resources.
816 * This function frees resources owned by the WL device pointed to
817 * by the wl parameter.
819 * precondition: can both be called locked and unlocked
822 static void brcms_free(struct brcms_info
*wl
)
824 struct brcms_timer
*t
, *next
;
826 /* free ucode data */
828 brcms_ucode_data_free(&wl
->ucode
);
830 free_irq(wl
->irq
, wl
);
833 tasklet_kill(&wl
->tasklet
);
836 brcms_c_module_unregister(wl
->pub
, "linux", wl
);
838 /* free common resources */
840 brcms_c_detach(wl
->wlc
);
845 /* virtual interface deletion is deferred so we cannot spinwait */
847 /* wait for all pending callbacks to complete */
848 while (atomic_read(&wl
->callbacks
) > 0)
852 for (t
= wl
->timers
; t
; t
= next
) {
862 * called from both kernel as from this kernel module (error flow on attach)
863 * precondition: perimeter lock is not acquired.
865 static void brcms_remove(struct bcma_device
*pdev
)
867 struct ieee80211_hw
*hw
= bcma_get_drvdata(pdev
);
868 struct brcms_info
*wl
= hw
->priv
;
871 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, false);
872 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
873 ieee80211_unregister_hw(hw
);
878 bcma_set_drvdata(pdev
, NULL
);
879 ieee80211_free_hw(hw
);
882 static irqreturn_t
brcms_isr(int irq
, void *dev_id
)
884 struct brcms_info
*wl
;
887 wl
= (struct brcms_info
*) dev_id
;
889 spin_lock(&wl
->isr_lock
);
891 /* call common first level interrupt handler */
892 ours
= brcms_c_isr(wl
->wlc
, &wantdpc
);
894 /* if more to do... */
897 /* ...and call the second level interrupt handler */
899 tasklet_schedule(&wl
->tasklet
);
903 spin_unlock(&wl
->isr_lock
);
905 return IRQ_RETVAL(ours
);
909 * is called in brcms_pci_probe() context, therefore no locking required.
911 static int ieee_hw_rate_init(struct ieee80211_hw
*hw
)
913 struct brcms_info
*wl
= hw
->priv
;
914 struct brcms_c_info
*wlc
= wl
->wlc
;
915 struct ieee80211_supported_band
*band
;
919 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = NULL
;
920 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = NULL
;
922 phy_type
= brcms_c_get_phy_type(wl
->wlc
, 0);
923 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
924 band
= &wlc
->bandstate
[BAND_2G_INDEX
]->band
;
925 *band
= brcms_band_2GHz_nphy_template
;
926 if (phy_type
== PHY_TYPE_LCN
) {
928 band
->ht_cap
.mcs
.rx_mask
[1] = 0;
929 band
->ht_cap
.mcs
.rx_highest
= cpu_to_le16(72);
931 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
936 /* Assume all bands use the same phy. True for 11n devices. */
937 if (wl
->pub
->_nbands
> 1) {
939 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
940 band
= &wlc
->bandstate
[BAND_5G_INDEX
]->band
;
941 *band
= brcms_band_5GHz_nphy_template
;
942 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
951 * is called in brcms_pci_probe() context, therefore no locking required.
953 static int ieee_hw_init(struct ieee80211_hw
*hw
)
955 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
956 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
957 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
958 | IEEE80211_HW_AMPDU_AGGREGATION
;
960 hw
->extra_tx_headroom
= brcms_c_get_header_len();
961 hw
->queues
= N_TX_QUEUES
;
962 hw
->max_rates
= 2; /* Primary rate and 1 fallback rate */
964 /* channel change time is dependent on chip and band */
965 hw
->channel_change_time
= 7 * 1000;
966 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
968 hw
->rate_control_algorithm
= "minstrel_ht";
970 hw
->sta_data_size
= 0;
971 return ieee_hw_rate_init(hw
);
975 * attach to the WL device.
977 * Attach to the WL device identified by vendor and device parameters.
978 * regs is a host accessible memory address pointing to WL device registers.
980 * brcms_attach is not defined as static because in the case where no bus
981 * is defined, wl_attach will never be called, and thus, gcc will issue
982 * a warning that this function is defined but not used if we declare
986 * is called in brcms_bcma_probe() context, therefore no locking required.
988 static struct brcms_info
*brcms_attach(struct bcma_device
*pdev
)
990 struct brcms_info
*wl
= NULL
;
992 struct ieee80211_hw
*hw
;
995 unit
= n_adapters_found
;
1001 /* allocate private info */
1002 hw
= bcma_get_drvdata(pdev
);
1005 if (WARN_ON(hw
== NULL
) || WARN_ON(wl
== NULL
))
1007 wl
->wiphy
= hw
->wiphy
;
1009 atomic_set(&wl
->callbacks
, 0);
1011 /* setup the bottom half handler */
1012 tasklet_init(&wl
->tasklet
, brcms_dpc
, (unsigned long) wl
);
1014 spin_lock_init(&wl
->lock
);
1015 spin_lock_init(&wl
->isr_lock
);
1018 if (brcms_request_fw(wl
, pdev
) < 0) {
1019 wiphy_err(wl
->wiphy
, "%s: Failed to find firmware usually in "
1020 "%s\n", KBUILD_MODNAME
, "/lib/firmware/brcm");
1021 brcms_release_fw(wl
);
1026 /* common load-time initialization */
1027 wl
->wlc
= brcms_c_attach((void *)wl
, pdev
, unit
, false, &err
);
1028 brcms_release_fw(wl
);
1030 wiphy_err(wl
->wiphy
, "%s: attach() failed with code %d\n",
1031 KBUILD_MODNAME
, err
);
1034 wl
->pub
= brcms_c_pub(wl
->wlc
);
1036 wl
->pub
->ieee_hw
= hw
;
1038 /* register our interrupt handler */
1039 if (request_irq(pdev
->irq
, brcms_isr
,
1040 IRQF_SHARED
, KBUILD_MODNAME
, wl
)) {
1041 wiphy_err(wl
->wiphy
, "wl%d: request_irq() failed\n", unit
);
1044 wl
->irq
= pdev
->irq
;
1046 /* register module */
1047 brcms_c_module_register(wl
->pub
, "linux", wl
, NULL
);
1049 if (ieee_hw_init(hw
)) {
1050 wiphy_err(wl
->wiphy
, "wl%d: %s: ieee_hw_init failed!\n", unit
,
1055 brcms_c_regd_init(wl
->wlc
);
1057 memcpy(perm
, &wl
->pub
->cur_etheraddr
, ETH_ALEN
);
1058 if (WARN_ON(!is_valid_ether_addr(perm
)))
1060 SET_IEEE80211_PERM_ADDR(hw
, perm
);
1062 err
= ieee80211_register_hw(hw
);
1064 wiphy_err(wl
->wiphy
, "%s: ieee80211_register_hw failed, status"
1065 "%d\n", __func__
, err
);
1067 if (wl
->pub
->srom_ccode
[0] &&
1068 regulatory_hint(wl
->wiphy
, wl
->pub
->srom_ccode
))
1069 wiphy_err(wl
->wiphy
, "%s: regulatory hint failed\n", __func__
);
1082 * determines if a device is a WL device, and if so, attaches it.
1084 * This function determines if a device pointed to by pdev is a WL device,
1085 * and if so, performs a brcms_attach() on it.
1087 * Perimeter lock is initialized in the course of this function.
1089 static int __devinit
brcms_bcma_probe(struct bcma_device
*pdev
)
1091 struct brcms_info
*wl
;
1092 struct ieee80211_hw
*hw
;
1094 dev_info(&pdev
->dev
, "mfg %x core %x rev %d class %d irq %d\n",
1095 pdev
->id
.manuf
, pdev
->id
.id
, pdev
->id
.rev
, pdev
->id
.class,
1098 if ((pdev
->id
.manuf
!= BCMA_MANUF_BCM
) ||
1099 (pdev
->id
.id
!= BCMA_CORE_80211
))
1102 hw
= ieee80211_alloc_hw(sizeof(struct brcms_info
), &brcms_ops
);
1104 pr_err("%s: ieee80211_alloc_hw failed\n", __func__
);
1108 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1110 bcma_set_drvdata(pdev
, hw
);
1112 memset(hw
->priv
, 0, sizeof(*wl
));
1114 wl
= brcms_attach(pdev
);
1116 pr_err("%s: brcms_attach failed!\n", __func__
);
1122 static int brcms_suspend(struct bcma_device
*pdev
)
1124 struct brcms_info
*wl
;
1125 struct ieee80211_hw
*hw
;
1127 hw
= bcma_get_drvdata(pdev
);
1130 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME
,
1135 /* only need to flag hw is down for proper resume */
1136 spin_lock_bh(&wl
->lock
);
1137 wl
->pub
->hw_up
= false;
1138 spin_unlock_bh(&wl
->lock
);
1140 pr_debug("brcms_suspend ok\n");
1145 static int brcms_resume(struct bcma_device
*pdev
)
1147 pr_debug("brcms_resume ok\n");
1151 static struct bcma_driver brcms_bcma_driver
= {
1152 .name
= KBUILD_MODNAME
,
1153 .probe
= brcms_bcma_probe
,
1154 .suspend
= brcms_suspend
,
1155 .resume
= brcms_resume
,
1156 .remove
= __devexit_p(brcms_remove
),
1157 .id_table
= brcms_coreid_table
,
1161 * This is the main entry point for the brcmsmac driver.
1163 * This function is scheduled upon module initialization and
1164 * does the driver registration, which result in brcms_bcma_probe()
1165 * call resulting in the driver bringup.
1167 static void brcms_driver_init(struct work_struct
*work
)
1171 error
= bcma_driver_register(&brcms_bcma_driver
);
1173 pr_err("%s: register returned %d\n", __func__
, error
);
1176 static DECLARE_WORK(brcms_driver_work
, brcms_driver_init
);
1178 static int __init
brcms_module_init(void)
1181 if (msglevel
!= 0xdeadbeef)
1182 brcm_msg_level
= msglevel
;
1184 if (!schedule_work(&brcms_driver_work
))
1191 * This function unloads the brcmsmac driver from the system.
1193 * This function unconditionally unloads the brcmsmac driver module from the
1197 static void __exit
brcms_module_exit(void)
1199 cancel_work_sync(&brcms_driver_work
);
1200 bcma_driver_unregister(&brcms_bcma_driver
);
1203 module_init(brcms_module_init
);
1204 module_exit(brcms_module_exit
);
1207 * precondition: perimeter lock has been acquired
1209 void brcms_txflowcontrol(struct brcms_info
*wl
, struct brcms_if
*wlif
,
1210 bool state
, int prio
)
1212 wiphy_err(wl
->wiphy
, "Shouldn't be here %s\n", __func__
);
1216 * precondition: perimeter lock has been acquired
1218 void brcms_init(struct brcms_info
*wl
)
1220 BCMMSG(wl
->pub
->ieee_hw
->wiphy
, "wl%d\n", wl
->pub
->unit
);
1222 brcms_c_init(wl
->wlc
, wl
->mute_tx
);
1226 * precondition: perimeter lock has been acquired
1228 uint
brcms_reset(struct brcms_info
*wl
)
1230 BCMMSG(wl
->pub
->ieee_hw
->wiphy
, "wl%d\n", wl
->pub
->unit
);
1231 brcms_c_reset(wl
->wlc
);
1233 /* dpc will not be rescheduled */
1234 wl
->resched
= false;
1236 /* inform publicly that interface is down */
1237 wl
->pub
->up
= false;
1242 void brcms_fatal_error(struct brcms_info
*wl
)
1244 wiphy_err(wl
->wlc
->wiphy
, "wl%d: fatal error, reinitializing\n",
1245 wl
->wlc
->pub
->unit
);
1247 ieee80211_restart_hw(wl
->pub
->ieee_hw
);
1251 * These are interrupt on/off entry points. Disable interrupts
1252 * during interrupt state transition.
1254 void brcms_intrson(struct brcms_info
*wl
)
1256 unsigned long flags
;
1258 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1259 brcms_c_intrson(wl
->wlc
);
1260 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1263 u32
brcms_intrsoff(struct brcms_info
*wl
)
1265 unsigned long flags
;
1268 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1269 status
= brcms_c_intrsoff(wl
->wlc
);
1270 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1274 void brcms_intrsrestore(struct brcms_info
*wl
, u32 macintmask
)
1276 unsigned long flags
;
1278 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1279 brcms_c_intrsrestore(wl
->wlc
, macintmask
);
1280 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1284 * precondition: perimeter lock has been acquired
1286 int brcms_up(struct brcms_info
*wl
)
1293 error
= brcms_c_up(wl
->wlc
);
1299 * precondition: perimeter lock has been acquired
1301 void brcms_down(struct brcms_info
*wl
)
1303 uint callbacks
, ret_val
= 0;
1305 /* call common down function */
1306 ret_val
= brcms_c_down(wl
->wlc
);
1307 callbacks
= atomic_read(&wl
->callbacks
) - ret_val
;
1309 /* wait for down callbacks to complete */
1310 spin_unlock_bh(&wl
->lock
);
1312 /* For HIGH_only driver, it's important to actually schedule other work,
1313 * not just spin wait since everything runs at schedule level
1315 SPINWAIT((atomic_read(&wl
->callbacks
) > callbacks
), 100 * 1000);
1317 spin_lock_bh(&wl
->lock
);
1321 * precondition: perimeter lock is not acquired
1323 static void _brcms_timer(struct work_struct
*work
)
1325 struct brcms_timer
*t
= container_of(work
, struct brcms_timer
,
1328 spin_lock_bh(&t
->wl
->lock
);
1332 atomic_inc(&t
->wl
->callbacks
);
1333 ieee80211_queue_delayed_work(t
->wl
->pub
->ieee_hw
,
1335 msecs_to_jiffies(t
->ms
));
1343 atomic_dec(&t
->wl
->callbacks
);
1345 spin_unlock_bh(&t
->wl
->lock
);
1349 * Adds a timer to the list. Caller supplies a timer function.
1350 * Is called from wlc.
1352 * precondition: perimeter lock has been acquired
1354 struct brcms_timer
*brcms_init_timer(struct brcms_info
*wl
,
1355 void (*fn
) (void *arg
),
1356 void *arg
, const char *name
)
1358 struct brcms_timer
*t
;
1360 t
= kzalloc(sizeof(struct brcms_timer
), GFP_ATOMIC
);
1364 INIT_DELAYED_WORK(&t
->dly_wrk
, _brcms_timer
);
1368 t
->next
= wl
->timers
;
1372 t
->name
= kmalloc(strlen(name
) + 1, GFP_ATOMIC
);
1374 strcpy(t
->name
, name
);
1381 * adds only the kernel timer since it's going to be more accurate
1382 * as well as it's easier to make it periodic
1384 * precondition: perimeter lock has been acquired
1386 void brcms_add_timer(struct brcms_timer
*t
, uint ms
, int periodic
)
1388 struct ieee80211_hw
*hw
= t
->wl
->pub
->ieee_hw
;
1392 wiphy_err(hw
->wiphy
, "%s: Already set. Name: %s, per %d\n",
1393 __func__
, t
->name
, periodic
);
1396 t
->periodic
= (bool) periodic
;
1399 atomic_inc(&t
->wl
->callbacks
);
1401 ieee80211_queue_delayed_work(hw
, &t
->dly_wrk
, msecs_to_jiffies(ms
));
1405 * return true if timer successfully deleted, false if still pending
1407 * precondition: perimeter lock has been acquired
1409 bool brcms_del_timer(struct brcms_timer
*t
)
1413 if (!cancel_delayed_work(&t
->dly_wrk
))
1416 atomic_dec(&t
->wl
->callbacks
);
1423 * precondition: perimeter lock has been acquired
1425 void brcms_free_timer(struct brcms_timer
*t
)
1427 struct brcms_info
*wl
= t
->wl
;
1428 struct brcms_timer
*tmp
;
1430 /* delete the timer in case it is active */
1433 if (wl
->timers
== t
) {
1434 wl
->timers
= wl
->timers
->next
;
1445 if (tmp
->next
== t
) {
1446 tmp
->next
= t
->next
;
1459 * precondition: perimeter lock has been acquired
1461 int brcms_ucode_init_buf(struct brcms_info
*wl
, void **pbuf
, u32 idx
)
1465 struct firmware_hdr
*hdr
;
1466 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1467 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1468 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1470 u32 len
= le32_to_cpu(hdr
->len
);
1471 if (le32_to_cpu(hdr
->idx
) == idx
) {
1472 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1473 le32_to_cpu(hdr
->offset
);
1474 *pbuf
= kmemdup(pdata
, len
, GFP_ATOMIC
);
1482 wiphy_err(wl
->wiphy
, "ERROR: ucode buf tag:%d can not be found!\n",
1490 * Precondition: Since this function is called in brcms_bcma_probe() context,
1491 * no locking is required.
1493 int brcms_ucode_init_uint(struct brcms_info
*wl
, size_t *n_bytes
, u32 idx
)
1497 struct firmware_hdr
*hdr
;
1498 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1499 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1500 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1502 if (le32_to_cpu(hdr
->idx
) == idx
) {
1503 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1504 le32_to_cpu(hdr
->offset
);
1505 if (le32_to_cpu(hdr
->len
) != 4) {
1506 wiphy_err(wl
->wiphy
,
1507 "ERROR: fw hdr len\n");
1510 *n_bytes
= le32_to_cpu(*((__le32
*) pdata
));
1515 wiphy_err(wl
->wiphy
, "ERROR: ucode tag:%d can not be found!\n", idx
);
1520 * precondition: can both be called locked and unlocked
1522 void brcms_ucode_free_buf(void *p
)
1528 * checks validity of all firmware images loaded from user space
1530 * Precondition: Since this function is called in brcms_bcma_probe() context,
1531 * no locking is required.
1533 int brcms_check_firmwares(struct brcms_info
*wl
)
1538 const struct firmware
*fw
;
1539 const struct firmware
*fw_hdr
;
1540 struct firmware_hdr
*ucode_hdr
;
1541 for (i
= 0; i
< MAX_FW_IMAGES
&& rc
== 0; i
++) {
1542 fw
= wl
->fw
.fw_bin
[i
];
1543 fw_hdr
= wl
->fw
.fw_hdr
[i
];
1544 if (fw
== NULL
&& fw_hdr
== NULL
) {
1546 } else if (fw
== NULL
|| fw_hdr
== NULL
) {
1547 wiphy_err(wl
->wiphy
, "%s: invalid bin/hdr fw\n",
1550 } else if (fw_hdr
->size
% sizeof(struct firmware_hdr
)) {
1551 wiphy_err(wl
->wiphy
, "%s: non integral fw hdr file "
1552 "size %zu/%zu\n", __func__
, fw_hdr
->size
,
1553 sizeof(struct firmware_hdr
));
1555 } else if (fw
->size
< MIN_FW_SIZE
|| fw
->size
> MAX_FW_SIZE
) {
1556 wiphy_err(wl
->wiphy
, "%s: out of bounds fw file size "
1557 "%zu\n", __func__
, fw
->size
);
1560 /* check if ucode section overruns firmware image */
1561 ucode_hdr
= (struct firmware_hdr
*)fw_hdr
->data
;
1562 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
] &&
1563 !rc
; entry
++, ucode_hdr
++) {
1564 if (le32_to_cpu(ucode_hdr
->offset
) +
1565 le32_to_cpu(ucode_hdr
->len
) >
1567 wiphy_err(wl
->wiphy
,
1568 "%s: conflicting bin/hdr\n",
1575 if (rc
== 0 && wl
->fw
.fw_cnt
!= i
) {
1576 wiphy_err(wl
->wiphy
, "%s: invalid fw_cnt=%d\n", __func__
,
1584 * precondition: perimeter lock has been acquired
1586 bool brcms_rfkill_set_hw_state(struct brcms_info
*wl
)
1588 bool blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
1590 spin_unlock_bh(&wl
->lock
);
1591 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
1593 wiphy_rfkill_start_polling(wl
->pub
->ieee_hw
->wiphy
);
1594 spin_lock_bh(&wl
->lock
);
1599 * precondition: perimeter lock has been acquired
1601 void brcms_msleep(struct brcms_info
*wl
, uint ms
)
1603 spin_unlock_bh(&wl
->lock
);
1605 spin_lock_bh(&wl
->lock
);