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");
89 /* This needs to be adjusted when brcms_firmwares changes */
90 MODULE_FIRMWARE("brcm/bcm43xx-0.fw");
91 MODULE_FIRMWARE("brcm/bcm43xx_hdr-0.fw");
93 /* recognized BCMA Core IDs */
94 static struct bcma_device_id brcms_coreid_table
[] = {
95 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 23, BCMA_ANY_CLASS
),
96 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 24, BCMA_ANY_CLASS
),
99 MODULE_DEVICE_TABLE(bcma
, brcms_coreid_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
| IEEE80211_HT_CAP_SGI_40
,
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 .ht_supported
= true,
242 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
243 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
245 /* placeholders for now */
246 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
247 .rx_highest
= cpu_to_le16(500),
248 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
252 /* flags the given rate in rateset as requested */
253 static void brcms_set_basic_rate(struct brcm_rateset
*rs
, u16 rate
, bool is_br
)
257 for (i
= 0; i
< rs
->count
; i
++) {
258 if (rate
!= (rs
->rates
[i
] & 0x7f))
262 rs
->rates
[i
] |= BRCMS_RATE_FLAG
;
264 rs
->rates
[i
] &= BRCMS_RATE_MASK
;
269 static void brcms_ops_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
271 struct brcms_info
*wl
= hw
->priv
;
272 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
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
);
281 tx_info
->rate_driver_data
[0] = tx_info
->control
.sta
;
283 spin_unlock_bh(&wl
->lock
);
286 static int brcms_ops_start(struct ieee80211_hw
*hw
)
288 struct brcms_info
*wl
= hw
->priv
;
292 ieee80211_wake_queues(hw
);
293 spin_lock_bh(&wl
->lock
);
294 blocked
= brcms_rfkill_set_hw_state(wl
);
295 spin_unlock_bh(&wl
->lock
);
297 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
299 spin_lock_bh(&wl
->lock
);
300 /* avoid acknowledging frames before a non-monitor device is added */
307 spin_unlock_bh(&wl
->lock
);
310 wiphy_err(hw
->wiphy
, "%s: brcms_up() returned %d\n", __func__
,
315 static void brcms_ops_stop(struct ieee80211_hw
*hw
)
317 struct brcms_info
*wl
= hw
->priv
;
320 ieee80211_stop_queues(hw
);
325 spin_lock_bh(&wl
->lock
);
326 status
= brcms_c_chipmatch(wl
->wlc
->hw
->d11core
);
327 spin_unlock_bh(&wl
->lock
);
330 "wl: brcms_ops_stop: chipmatch failed\n");
334 /* put driver in down state */
335 spin_lock_bh(&wl
->lock
);
337 spin_unlock_bh(&wl
->lock
);
341 brcms_ops_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
343 struct brcms_info
*wl
= hw
->priv
;
345 /* Just STA for now */
346 if (vif
->type
!= NL80211_IFTYPE_STATION
) {
347 wiphy_err(hw
->wiphy
, "%s: Attempt to add type %d, only"
348 " STA for now\n", __func__
, vif
->type
);
353 brcms_c_mute(wl
->wlc
, false);
359 brcms_ops_remove_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
363 static int brcms_ops_config(struct ieee80211_hw
*hw
, u32 changed
)
365 struct ieee80211_conf
*conf
= &hw
->conf
;
366 struct brcms_info
*wl
= hw
->priv
;
369 struct wiphy
*wiphy
= hw
->wiphy
;
371 spin_lock_bh(&wl
->lock
);
372 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
373 brcms_c_set_beacon_listen_interval(wl
->wlc
,
374 conf
->listen_interval
);
376 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
)
377 wiphy_dbg(wiphy
, "%s: change monitor mode: %s\n",
378 __func__
, conf
->flags
& IEEE80211_CONF_MONITOR
?
380 if (changed
& IEEE80211_CONF_CHANGE_PS
)
381 wiphy_err(wiphy
, "%s: change power-save mode: %s (implement)\n",
382 __func__
, conf
->flags
& IEEE80211_CONF_PS
?
385 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
386 err
= brcms_c_set_tx_power(wl
->wlc
, conf
->power_level
);
388 wiphy_err(wiphy
, "%s: Error setting power_level\n",
392 new_int
= brcms_c_get_tx_power(wl
->wlc
);
393 if (new_int
!= conf
->power_level
)
394 wiphy_err(wiphy
, "%s: Power level req != actual, %d %d"
395 "\n", __func__
, conf
->power_level
,
398 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
399 if (conf
->channel_type
== NL80211_CHAN_HT20
||
400 conf
->channel_type
== NL80211_CHAN_NO_HT
)
401 err
= brcms_c_set_channel(wl
->wlc
,
402 conf
->channel
->hw_value
);
406 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
)
407 err
= brcms_c_set_rate_limit(wl
->wlc
,
408 conf
->short_frame_max_tx_count
,
409 conf
->long_frame_max_tx_count
);
412 spin_unlock_bh(&wl
->lock
);
417 brcms_ops_bss_info_changed(struct ieee80211_hw
*hw
,
418 struct ieee80211_vif
*vif
,
419 struct ieee80211_bss_conf
*info
, u32 changed
)
421 struct brcms_info
*wl
= hw
->priv
;
422 struct wiphy
*wiphy
= hw
->wiphy
;
424 if (changed
& BSS_CHANGED_ASSOC
) {
425 /* association status changed (associated/disassociated)
426 * also implies a change in the AID.
428 wiphy_err(wiphy
, "%s: %s: %sassociated\n", KBUILD_MODNAME
,
429 __func__
, info
->assoc
? "" : "dis");
430 spin_lock_bh(&wl
->lock
);
431 brcms_c_associate_upd(wl
->wlc
, info
->assoc
);
432 spin_unlock_bh(&wl
->lock
);
434 if (changed
& BSS_CHANGED_ERP_SLOT
) {
437 /* slot timing changed */
438 if (info
->use_short_slot
)
442 spin_lock_bh(&wl
->lock
);
443 brcms_c_set_shortslot_override(wl
->wlc
, val
);
444 spin_unlock_bh(&wl
->lock
);
447 if (changed
& BSS_CHANGED_HT
) {
448 /* 802.11n parameters changed */
449 u16 mode
= info
->ht_operation_mode
;
451 spin_lock_bh(&wl
->lock
);
452 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_CFG
,
453 mode
& IEEE80211_HT_OP_MODE_PROTECTION
);
454 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_NONGF
,
455 mode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
456 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_OBSS
,
457 mode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
);
458 spin_unlock_bh(&wl
->lock
);
460 if (changed
& BSS_CHANGED_BASIC_RATES
) {
461 struct ieee80211_supported_band
*bi
;
464 struct brcm_rateset rs
;
467 /* retrieve the current rates */
468 spin_lock_bh(&wl
->lock
);
469 brcms_c_get_current_rateset(wl
->wlc
, &rs
);
470 spin_unlock_bh(&wl
->lock
);
472 br_mask
= info
->basic_rates
;
473 bi
= hw
->wiphy
->bands
[brcms_c_get_curband(wl
->wlc
)];
474 for (i
= 0; i
< bi
->n_bitrates
; i
++) {
475 /* convert to internal rate value */
476 rate
= (bi
->bitrates
[i
].bitrate
<< 1) / 10;
478 /* set/clear basic rate flag */
479 brcms_set_basic_rate(&rs
, rate
, br_mask
& 1);
483 /* update the rate set */
484 spin_lock_bh(&wl
->lock
);
485 error
= brcms_c_set_rateset(wl
->wlc
, &rs
);
486 spin_unlock_bh(&wl
->lock
);
488 wiphy_err(wiphy
, "changing basic rates failed: %d\n",
491 if (changed
& BSS_CHANGED_BEACON_INT
) {
492 /* Beacon interval changed */
493 spin_lock_bh(&wl
->lock
);
494 brcms_c_set_beacon_period(wl
->wlc
, info
->beacon_int
);
495 spin_unlock_bh(&wl
->lock
);
497 if (changed
& BSS_CHANGED_BSSID
) {
498 /* BSSID changed, for whatever reason (IBSS and managed mode) */
499 spin_lock_bh(&wl
->lock
);
500 brcms_c_set_addrmatch(wl
->wlc
, RCM_BSSID_OFFSET
, info
->bssid
);
501 spin_unlock_bh(&wl
->lock
);
503 if (changed
& BSS_CHANGED_BEACON
)
504 /* Beacon data changed, retrieve new beacon (beaconing modes) */
505 wiphy_err(wiphy
, "%s: beacon changed\n", __func__
);
507 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
508 /* Beaconing should be enabled/disabled (beaconing modes) */
509 wiphy_err(wiphy
, "%s: Beacon enabled: %s\n", __func__
,
510 info
->enable_beacon
? "true" : "false");
513 if (changed
& BSS_CHANGED_CQM
) {
514 /* Connection quality monitor config changed */
515 wiphy_err(wiphy
, "%s: cqm change: threshold %d, hys %d "
516 " (implement)\n", __func__
, info
->cqm_rssi_thold
,
517 info
->cqm_rssi_hyst
);
520 if (changed
& BSS_CHANGED_IBSS
) {
521 /* IBSS join status changed */
522 wiphy_err(wiphy
, "%s: IBSS joined: %s (implement)\n", __func__
,
523 info
->ibss_joined
? "true" : "false");
526 if (changed
& BSS_CHANGED_ARP_FILTER
) {
527 /* Hardware ARP filter address list or state changed */
528 wiphy_err(wiphy
, "%s: arp filtering: enabled %s, count %d"
529 " (implement)\n", __func__
, info
->arp_filter_enabled
?
530 "true" : "false", info
->arp_addr_cnt
);
533 if (changed
& BSS_CHANGED_QOS
) {
535 * QoS for this association was enabled/disabled.
536 * Note that it is only ever disabled for station mode.
538 wiphy_err(wiphy
, "%s: qos enabled: %s (implement)\n", __func__
,
539 info
->qos
? "true" : "false");
545 brcms_ops_configure_filter(struct ieee80211_hw
*hw
,
546 unsigned int changed_flags
,
547 unsigned int *total_flags
, u64 multicast
)
549 struct brcms_info
*wl
= hw
->priv
;
550 struct wiphy
*wiphy
= hw
->wiphy
;
552 changed_flags
&= MAC_FILTERS
;
553 *total_flags
&= MAC_FILTERS
;
555 if (changed_flags
& FIF_PROMISC_IN_BSS
)
556 wiphy_dbg(wiphy
, "FIF_PROMISC_IN_BSS\n");
557 if (changed_flags
& FIF_ALLMULTI
)
558 wiphy_dbg(wiphy
, "FIF_ALLMULTI\n");
559 if (changed_flags
& FIF_FCSFAIL
)
560 wiphy_dbg(wiphy
, "FIF_FCSFAIL\n");
561 if (changed_flags
& FIF_CONTROL
)
562 wiphy_dbg(wiphy
, "FIF_CONTROL\n");
563 if (changed_flags
& FIF_OTHER_BSS
)
564 wiphy_dbg(wiphy
, "FIF_OTHER_BSS\n");
565 if (changed_flags
& FIF_PSPOLL
)
566 wiphy_dbg(wiphy
, "FIF_PSPOLL\n");
567 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
)
568 wiphy_dbg(wiphy
, "FIF_BCN_PRBRESP_PROMISC\n");
570 spin_lock_bh(&wl
->lock
);
571 brcms_c_mac_promisc(wl
->wlc
, *total_flags
);
572 spin_unlock_bh(&wl
->lock
);
576 static void brcms_ops_sw_scan_start(struct ieee80211_hw
*hw
)
578 struct brcms_info
*wl
= hw
->priv
;
579 spin_lock_bh(&wl
->lock
);
580 brcms_c_scan_start(wl
->wlc
);
581 spin_unlock_bh(&wl
->lock
);
585 static void brcms_ops_sw_scan_complete(struct ieee80211_hw
*hw
)
587 struct brcms_info
*wl
= hw
->priv
;
588 spin_lock_bh(&wl
->lock
);
589 brcms_c_scan_stop(wl
->wlc
);
590 spin_unlock_bh(&wl
->lock
);
595 brcms_ops_conf_tx(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
, u16 queue
,
596 const struct ieee80211_tx_queue_params
*params
)
598 struct brcms_info
*wl
= hw
->priv
;
600 spin_lock_bh(&wl
->lock
);
601 brcms_c_wme_setparams(wl
->wlc
, queue
, params
, true);
602 spin_unlock_bh(&wl
->lock
);
608 brcms_ops_sta_add(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
609 struct ieee80211_sta
*sta
)
611 struct brcms_info
*wl
= hw
->priv
;
612 struct scb
*scb
= &wl
->wlc
->pri_scb
;
614 brcms_c_init_scb(scb
);
616 wl
->pub
->global_ampdu
= &(scb
->scb_ampdu
);
617 wl
->pub
->global_ampdu
->scb
= scb
;
618 wl
->pub
->global_ampdu
->max_pdu
= 16;
621 * minstrel_ht initiates addBA on our behalf by calling
622 * ieee80211_start_tx_ba_session()
628 brcms_ops_ampdu_action(struct ieee80211_hw
*hw
,
629 struct ieee80211_vif
*vif
,
630 enum ieee80211_ampdu_mlme_action action
,
631 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
634 struct brcms_info
*wl
= hw
->priv
;
635 struct scb
*scb
= &wl
->wlc
->pri_scb
;
638 if (WARN_ON(scb
->magic
!= SCB_MAGIC
))
641 case IEEE80211_AMPDU_RX_START
:
643 case IEEE80211_AMPDU_RX_STOP
:
645 case IEEE80211_AMPDU_TX_START
:
646 spin_lock_bh(&wl
->lock
);
647 status
= brcms_c_aggregatable(wl
->wlc
, tid
);
648 spin_unlock_bh(&wl
->lock
);
650 wiphy_err(wl
->wiphy
, "START: tid %d is not agg\'able\n",
654 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
657 case IEEE80211_AMPDU_TX_STOP
:
658 spin_lock_bh(&wl
->lock
);
659 brcms_c_ampdu_flush(wl
->wlc
, sta
, tid
);
660 spin_unlock_bh(&wl
->lock
);
661 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
663 case IEEE80211_AMPDU_TX_OPERATIONAL
:
665 * BA window size from ADDBA response ('buf_size') defines how
666 * many outstanding MPDUs are allowed for the BA stream by
667 * recipient and traffic class. 'ampdu_factor' gives maximum
670 spin_lock_bh(&wl
->lock
);
671 brcms_c_ampdu_tx_operational(wl
->wlc
, tid
, buf_size
,
672 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
673 sta
->ht_cap
.ampdu_factor
)) - 1);
674 spin_unlock_bh(&wl
->lock
);
675 /* Power save wakeup */
678 wiphy_err(wl
->wiphy
, "%s: Invalid command, ignoring\n",
685 static void brcms_ops_rfkill_poll(struct ieee80211_hw
*hw
)
687 struct brcms_info
*wl
= hw
->priv
;
690 spin_lock_bh(&wl
->lock
);
691 blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
692 spin_unlock_bh(&wl
->lock
);
694 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
697 static void brcms_ops_flush(struct ieee80211_hw
*hw
, bool drop
)
699 struct brcms_info
*wl
= hw
->priv
;
701 no_printk("%s: drop = %s\n", __func__
, drop
? "true" : "false");
703 /* wait for packet queue and dma fifos to run empty */
704 spin_lock_bh(&wl
->lock
);
705 brcms_c_wait_for_tx_completion(wl
->wlc
, drop
);
706 spin_unlock_bh(&wl
->lock
);
709 static const struct ieee80211_ops brcms_ops
= {
711 .start
= brcms_ops_start
,
712 .stop
= brcms_ops_stop
,
713 .add_interface
= brcms_ops_add_interface
,
714 .remove_interface
= brcms_ops_remove_interface
,
715 .config
= brcms_ops_config
,
716 .bss_info_changed
= brcms_ops_bss_info_changed
,
717 .configure_filter
= brcms_ops_configure_filter
,
718 .sw_scan_start
= brcms_ops_sw_scan_start
,
719 .sw_scan_complete
= brcms_ops_sw_scan_complete
,
720 .conf_tx
= brcms_ops_conf_tx
,
721 .sta_add
= brcms_ops_sta_add
,
722 .ampdu_action
= brcms_ops_ampdu_action
,
723 .rfkill_poll
= brcms_ops_rfkill_poll
,
724 .flush
= brcms_ops_flush
,
727 void brcms_dpc(unsigned long data
)
729 struct brcms_info
*wl
;
731 wl
= (struct brcms_info
*) data
;
733 spin_lock_bh(&wl
->lock
);
735 /* call the common second level interrupt handler */
740 spin_lock_irqsave(&wl
->isr_lock
, flags
);
741 brcms_c_intrsupd(wl
->wlc
);
742 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
745 wl
->resched
= brcms_c_dpc(wl
->wlc
, true);
748 /* brcms_c_dpc() may bring the driver down */
752 /* re-schedule dpc */
754 tasklet_schedule(&wl
->tasklet
);
756 /* re-enable interrupts */
760 spin_unlock_bh(&wl
->lock
);
764 * Precondition: Since this function is called in brcms_pci_probe() context,
765 * no locking is required.
767 static int brcms_request_fw(struct brcms_info
*wl
, struct bcma_device
*pdev
)
770 struct device
*device
= &pdev
->dev
;
774 memset(&wl
->fw
, 0, sizeof(struct brcms_firmware
));
775 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
776 if (brcms_firmwares
[i
] == NULL
)
778 sprintf(fw_name
, "%s-%d.fw", brcms_firmwares
[i
],
779 UCODE_LOADER_API_VER
);
780 status
= request_firmware(&wl
->fw
.fw_bin
[i
], fw_name
, device
);
782 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
783 KBUILD_MODNAME
, fw_name
);
786 sprintf(fw_name
, "%s_hdr-%d.fw", brcms_firmwares
[i
],
787 UCODE_LOADER_API_VER
);
788 status
= request_firmware(&wl
->fw
.fw_hdr
[i
], fw_name
, device
);
790 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
791 KBUILD_MODNAME
, fw_name
);
794 wl
->fw
.hdr_num_entries
[i
] =
795 wl
->fw
.fw_hdr
[i
]->size
/ (sizeof(struct firmware_hdr
));
798 return brcms_ucode_data_init(wl
, &wl
->ucode
);
802 * Precondition: Since this function is called in brcms_pci_probe() context,
803 * no locking is required.
805 static void brcms_release_fw(struct brcms_info
*wl
)
808 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
809 release_firmware(wl
->fw
.fw_bin
[i
]);
810 release_firmware(wl
->fw
.fw_hdr
[i
]);
815 * This function frees the WL per-device resources.
817 * This function frees resources owned by the WL device pointed to
818 * by the wl parameter.
820 * precondition: can both be called locked and unlocked
823 static void brcms_free(struct brcms_info
*wl
)
825 struct brcms_timer
*t
, *next
;
827 /* free ucode data */
829 brcms_ucode_data_free(&wl
->ucode
);
831 free_irq(wl
->irq
, wl
);
834 tasklet_kill(&wl
->tasklet
);
837 brcms_c_module_unregister(wl
->pub
, "linux", wl
);
839 /* free common resources */
841 brcms_c_detach(wl
->wlc
);
846 /* virtual interface deletion is deferred so we cannot spinwait */
848 /* wait for all pending callbacks to complete */
849 while (atomic_read(&wl
->callbacks
) > 0)
853 for (t
= wl
->timers
; t
; t
= next
) {
863 * called from both kernel as from this kernel module (error flow on attach)
864 * precondition: perimeter lock is not acquired.
866 static void brcms_remove(struct bcma_device
*pdev
)
868 struct ieee80211_hw
*hw
= bcma_get_drvdata(pdev
);
869 struct brcms_info
*wl
= hw
->priv
;
872 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, false);
873 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
874 ieee80211_unregister_hw(hw
);
879 bcma_set_drvdata(pdev
, NULL
);
880 ieee80211_free_hw(hw
);
883 static irqreturn_t
brcms_isr(int irq
, void *dev_id
)
885 struct brcms_info
*wl
;
888 wl
= (struct brcms_info
*) dev_id
;
890 spin_lock(&wl
->isr_lock
);
892 /* call common first level interrupt handler */
893 ours
= brcms_c_isr(wl
->wlc
, &wantdpc
);
895 /* if more to do... */
898 /* ...and call the second level interrupt handler */
900 tasklet_schedule(&wl
->tasklet
);
904 spin_unlock(&wl
->isr_lock
);
906 return IRQ_RETVAL(ours
);
910 * is called in brcms_pci_probe() context, therefore no locking required.
912 static int ieee_hw_rate_init(struct ieee80211_hw
*hw
)
914 struct brcms_info
*wl
= hw
->priv
;
915 struct brcms_c_info
*wlc
= wl
->wlc
;
916 struct ieee80211_supported_band
*band
;
920 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = NULL
;
921 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = NULL
;
923 phy_type
= brcms_c_get_phy_type(wl
->wlc
, 0);
924 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
925 band
= &wlc
->bandstate
[BAND_2G_INDEX
]->band
;
926 *band
= brcms_band_2GHz_nphy_template
;
927 if (phy_type
== PHY_TYPE_LCN
) {
929 band
->ht_cap
.mcs
.rx_mask
[1] = 0;
930 band
->ht_cap
.mcs
.rx_highest
= cpu_to_le16(72);
932 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
937 /* Assume all bands use the same phy. True for 11n devices. */
938 if (wl
->pub
->_nbands
> 1) {
940 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
941 band
= &wlc
->bandstate
[BAND_5G_INDEX
]->band
;
942 *band
= brcms_band_5GHz_nphy_template
;
943 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
952 * is called in brcms_pci_probe() context, therefore no locking required.
954 static int ieee_hw_init(struct ieee80211_hw
*hw
)
956 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
957 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
958 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
959 | IEEE80211_HW_AMPDU_AGGREGATION
;
961 hw
->extra_tx_headroom
= brcms_c_get_header_len();
962 hw
->queues
= N_TX_QUEUES
;
963 hw
->max_rates
= 2; /* Primary rate and 1 fallback rate */
965 /* channel change time is dependent on chip and band */
966 hw
->channel_change_time
= 7 * 1000;
967 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
969 hw
->rate_control_algorithm
= "minstrel_ht";
971 hw
->sta_data_size
= 0;
972 return ieee_hw_rate_init(hw
);
976 * attach to the WL device.
978 * Attach to the WL device identified by vendor and device parameters.
979 * regs is a host accessible memory address pointing to WL device registers.
981 * brcms_attach is not defined as static because in the case where no bus
982 * is defined, wl_attach will never be called, and thus, gcc will issue
983 * a warning that this function is defined but not used if we declare
987 * is called in brcms_bcma_probe() context, therefore no locking required.
989 static struct brcms_info
*brcms_attach(struct bcma_device
*pdev
)
991 struct brcms_info
*wl
= NULL
;
993 struct ieee80211_hw
*hw
;
996 unit
= n_adapters_found
;
1002 /* allocate private info */
1003 hw
= bcma_get_drvdata(pdev
);
1006 if (WARN_ON(hw
== NULL
) || WARN_ON(wl
== NULL
))
1008 wl
->wiphy
= hw
->wiphy
;
1010 atomic_set(&wl
->callbacks
, 0);
1012 /* setup the bottom half handler */
1013 tasklet_init(&wl
->tasklet
, brcms_dpc
, (unsigned long) wl
);
1015 spin_lock_init(&wl
->lock
);
1016 spin_lock_init(&wl
->isr_lock
);
1019 if (brcms_request_fw(wl
, pdev
) < 0) {
1020 wiphy_err(wl
->wiphy
, "%s: Failed to find firmware usually in "
1021 "%s\n", KBUILD_MODNAME
, "/lib/firmware/brcm");
1022 brcms_release_fw(wl
);
1027 /* common load-time initialization */
1028 wl
->wlc
= brcms_c_attach((void *)wl
, pdev
, unit
, false, &err
);
1029 brcms_release_fw(wl
);
1031 wiphy_err(wl
->wiphy
, "%s: attach() failed with code %d\n",
1032 KBUILD_MODNAME
, err
);
1035 wl
->pub
= brcms_c_pub(wl
->wlc
);
1037 wl
->pub
->ieee_hw
= hw
;
1039 /* register our interrupt handler */
1040 if (request_irq(pdev
->irq
, brcms_isr
,
1041 IRQF_SHARED
, KBUILD_MODNAME
, wl
)) {
1042 wiphy_err(wl
->wiphy
, "wl%d: request_irq() failed\n", unit
);
1045 wl
->irq
= pdev
->irq
;
1047 /* register module */
1048 brcms_c_module_register(wl
->pub
, "linux", wl
, NULL
);
1050 if (ieee_hw_init(hw
)) {
1051 wiphy_err(wl
->wiphy
, "wl%d: %s: ieee_hw_init failed!\n", unit
,
1056 brcms_c_regd_init(wl
->wlc
);
1058 memcpy(perm
, &wl
->pub
->cur_etheraddr
, ETH_ALEN
);
1059 if (WARN_ON(!is_valid_ether_addr(perm
)))
1061 SET_IEEE80211_PERM_ADDR(hw
, perm
);
1063 err
= ieee80211_register_hw(hw
);
1065 wiphy_err(wl
->wiphy
, "%s: ieee80211_register_hw failed, status"
1066 "%d\n", __func__
, err
);
1068 if (wl
->pub
->srom_ccode
[0] &&
1069 regulatory_hint(wl
->wiphy
, wl
->pub
->srom_ccode
))
1070 wiphy_err(wl
->wiphy
, "%s: regulatory hint failed\n", __func__
);
1083 * determines if a device is a WL device, and if so, attaches it.
1085 * This function determines if a device pointed to by pdev is a WL device,
1086 * and if so, performs a brcms_attach() on it.
1088 * Perimeter lock is initialized in the course of this function.
1090 static int __devinit
brcms_bcma_probe(struct bcma_device
*pdev
)
1092 struct brcms_info
*wl
;
1093 struct ieee80211_hw
*hw
;
1095 dev_info(&pdev
->dev
, "mfg %x core %x rev %d class %d irq %d\n",
1096 pdev
->id
.manuf
, pdev
->id
.id
, pdev
->id
.rev
, pdev
->id
.class,
1099 if ((pdev
->id
.manuf
!= BCMA_MANUF_BCM
) ||
1100 (pdev
->id
.id
!= BCMA_CORE_80211
))
1103 hw
= ieee80211_alloc_hw(sizeof(struct brcms_info
), &brcms_ops
);
1105 pr_err("%s: ieee80211_alloc_hw failed\n", __func__
);
1109 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1111 bcma_set_drvdata(pdev
, hw
);
1113 memset(hw
->priv
, 0, sizeof(*wl
));
1115 wl
= brcms_attach(pdev
);
1117 pr_err("%s: brcms_attach failed!\n", __func__
);
1123 static int brcms_suspend(struct bcma_device
*pdev
)
1125 struct brcms_info
*wl
;
1126 struct ieee80211_hw
*hw
;
1128 hw
= bcma_get_drvdata(pdev
);
1131 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME
,
1136 /* only need to flag hw is down for proper resume */
1137 spin_lock_bh(&wl
->lock
);
1138 wl
->pub
->hw_up
= false;
1139 spin_unlock_bh(&wl
->lock
);
1141 pr_debug("brcms_suspend ok\n");
1146 static int brcms_resume(struct bcma_device
*pdev
)
1148 pr_debug("brcms_resume ok\n");
1152 static struct bcma_driver brcms_bcma_driver
= {
1153 .name
= KBUILD_MODNAME
,
1154 .probe
= brcms_bcma_probe
,
1155 .suspend
= brcms_suspend
,
1156 .resume
= brcms_resume
,
1157 .remove
= __devexit_p(brcms_remove
),
1158 .id_table
= brcms_coreid_table
,
1162 * This is the main entry point for the brcmsmac driver.
1164 * This function is scheduled upon module initialization and
1165 * does the driver registration, which result in brcms_bcma_probe()
1166 * call resulting in the driver bringup.
1168 static void brcms_driver_init(struct work_struct
*work
)
1172 error
= bcma_driver_register(&brcms_bcma_driver
);
1174 pr_err("%s: register returned %d\n", __func__
, error
);
1177 static DECLARE_WORK(brcms_driver_work
, brcms_driver_init
);
1179 static int __init
brcms_module_init(void)
1182 if (msglevel
!= 0xdeadbeef)
1183 brcm_msg_level
= msglevel
;
1185 if (!schedule_work(&brcms_driver_work
))
1192 * This function unloads the brcmsmac driver from the system.
1194 * This function unconditionally unloads the brcmsmac driver module from the
1198 static void __exit
brcms_module_exit(void)
1200 cancel_work_sync(&brcms_driver_work
);
1201 bcma_driver_unregister(&brcms_bcma_driver
);
1204 module_init(brcms_module_init
);
1205 module_exit(brcms_module_exit
);
1208 * precondition: perimeter lock has been acquired
1210 void brcms_txflowcontrol(struct brcms_info
*wl
, struct brcms_if
*wlif
,
1211 bool state
, int prio
)
1213 wiphy_err(wl
->wiphy
, "Shouldn't be here %s\n", __func__
);
1217 * precondition: perimeter lock has been acquired
1219 void brcms_init(struct brcms_info
*wl
)
1221 BCMMSG(wl
->pub
->ieee_hw
->wiphy
, "wl%d\n", wl
->pub
->unit
);
1223 brcms_c_init(wl
->wlc
, wl
->mute_tx
);
1227 * precondition: perimeter lock has been acquired
1229 uint
brcms_reset(struct brcms_info
*wl
)
1231 BCMMSG(wl
->pub
->ieee_hw
->wiphy
, "wl%d\n", wl
->pub
->unit
);
1232 brcms_c_reset(wl
->wlc
);
1234 /* dpc will not be rescheduled */
1235 wl
->resched
= false;
1240 void brcms_fatal_error(struct brcms_info
*wl
)
1242 wiphy_err(wl
->wlc
->wiphy
, "wl%d: fatal error, reinitializing\n",
1243 wl
->wlc
->pub
->unit
);
1245 ieee80211_restart_hw(wl
->pub
->ieee_hw
);
1249 * These are interrupt on/off entry points. Disable interrupts
1250 * during interrupt state transition.
1252 void brcms_intrson(struct brcms_info
*wl
)
1254 unsigned long flags
;
1256 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1257 brcms_c_intrson(wl
->wlc
);
1258 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1261 u32
brcms_intrsoff(struct brcms_info
*wl
)
1263 unsigned long flags
;
1266 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1267 status
= brcms_c_intrsoff(wl
->wlc
);
1268 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1272 void brcms_intrsrestore(struct brcms_info
*wl
, u32 macintmask
)
1274 unsigned long flags
;
1276 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1277 brcms_c_intrsrestore(wl
->wlc
, macintmask
);
1278 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1282 * precondition: perimeter lock has been acquired
1284 int brcms_up(struct brcms_info
*wl
)
1291 error
= brcms_c_up(wl
->wlc
);
1297 * precondition: perimeter lock has been acquired
1299 void brcms_down(struct brcms_info
*wl
)
1301 uint callbacks
, ret_val
= 0;
1303 /* call common down function */
1304 ret_val
= brcms_c_down(wl
->wlc
);
1305 callbacks
= atomic_read(&wl
->callbacks
) - ret_val
;
1307 /* wait for down callbacks to complete */
1308 spin_unlock_bh(&wl
->lock
);
1310 /* For HIGH_only driver, it's important to actually schedule other work,
1311 * not just spin wait since everything runs at schedule level
1313 SPINWAIT((atomic_read(&wl
->callbacks
) > callbacks
), 100 * 1000);
1315 spin_lock_bh(&wl
->lock
);
1319 * precondition: perimeter lock is not acquired
1321 static void _brcms_timer(struct work_struct
*work
)
1323 struct brcms_timer
*t
= container_of(work
, struct brcms_timer
,
1326 spin_lock_bh(&t
->wl
->lock
);
1330 atomic_inc(&t
->wl
->callbacks
);
1331 ieee80211_queue_delayed_work(t
->wl
->pub
->ieee_hw
,
1333 msecs_to_jiffies(t
->ms
));
1341 atomic_dec(&t
->wl
->callbacks
);
1343 spin_unlock_bh(&t
->wl
->lock
);
1347 * Adds a timer to the list. Caller supplies a timer function.
1348 * Is called from wlc.
1350 * precondition: perimeter lock has been acquired
1352 struct brcms_timer
*brcms_init_timer(struct brcms_info
*wl
,
1353 void (*fn
) (void *arg
),
1354 void *arg
, const char *name
)
1356 struct brcms_timer
*t
;
1358 t
= kzalloc(sizeof(struct brcms_timer
), GFP_ATOMIC
);
1362 INIT_DELAYED_WORK(&t
->dly_wrk
, _brcms_timer
);
1366 t
->next
= wl
->timers
;
1370 t
->name
= kmalloc(strlen(name
) + 1, GFP_ATOMIC
);
1372 strcpy(t
->name
, name
);
1379 * adds only the kernel timer since it's going to be more accurate
1380 * as well as it's easier to make it periodic
1382 * precondition: perimeter lock has been acquired
1384 void brcms_add_timer(struct brcms_timer
*t
, uint ms
, int periodic
)
1386 struct ieee80211_hw
*hw
= t
->wl
->pub
->ieee_hw
;
1390 wiphy_err(hw
->wiphy
, "%s: Already set. Name: %s, per %d\n",
1391 __func__
, t
->name
, periodic
);
1394 t
->periodic
= (bool) periodic
;
1397 atomic_inc(&t
->wl
->callbacks
);
1399 ieee80211_queue_delayed_work(hw
, &t
->dly_wrk
, msecs_to_jiffies(ms
));
1403 * return true if timer successfully deleted, false if still pending
1405 * precondition: perimeter lock has been acquired
1407 bool brcms_del_timer(struct brcms_timer
*t
)
1411 if (!cancel_delayed_work(&t
->dly_wrk
))
1414 atomic_dec(&t
->wl
->callbacks
);
1421 * precondition: perimeter lock has been acquired
1423 void brcms_free_timer(struct brcms_timer
*t
)
1425 struct brcms_info
*wl
= t
->wl
;
1426 struct brcms_timer
*tmp
;
1428 /* delete the timer in case it is active */
1431 if (wl
->timers
== t
) {
1432 wl
->timers
= wl
->timers
->next
;
1443 if (tmp
->next
== t
) {
1444 tmp
->next
= t
->next
;
1457 * precondition: perimeter lock has been acquired
1459 int brcms_ucode_init_buf(struct brcms_info
*wl
, void **pbuf
, u32 idx
)
1463 struct firmware_hdr
*hdr
;
1464 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1465 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1466 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1468 u32 len
= le32_to_cpu(hdr
->len
);
1469 if (le32_to_cpu(hdr
->idx
) == idx
) {
1470 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1471 le32_to_cpu(hdr
->offset
);
1472 *pbuf
= kmemdup(pdata
, len
, GFP_ATOMIC
);
1480 wiphy_err(wl
->wiphy
, "ERROR: ucode buf tag:%d can not be found!\n",
1488 * Precondition: Since this function is called in brcms_bcma_probe() context,
1489 * no locking is required.
1491 int brcms_ucode_init_uint(struct brcms_info
*wl
, size_t *n_bytes
, u32 idx
)
1495 struct firmware_hdr
*hdr
;
1496 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1497 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1498 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1500 if (le32_to_cpu(hdr
->idx
) == idx
) {
1501 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1502 le32_to_cpu(hdr
->offset
);
1503 if (le32_to_cpu(hdr
->len
) != 4) {
1504 wiphy_err(wl
->wiphy
,
1505 "ERROR: fw hdr len\n");
1508 *n_bytes
= le32_to_cpu(*((__le32
*) pdata
));
1513 wiphy_err(wl
->wiphy
, "ERROR: ucode tag:%d can not be found!\n", idx
);
1518 * precondition: can both be called locked and unlocked
1520 void brcms_ucode_free_buf(void *p
)
1526 * checks validity of all firmware images loaded from user space
1528 * Precondition: Since this function is called in brcms_bcma_probe() context,
1529 * no locking is required.
1531 int brcms_check_firmwares(struct brcms_info
*wl
)
1536 const struct firmware
*fw
;
1537 const struct firmware
*fw_hdr
;
1538 struct firmware_hdr
*ucode_hdr
;
1539 for (i
= 0; i
< MAX_FW_IMAGES
&& rc
== 0; i
++) {
1540 fw
= wl
->fw
.fw_bin
[i
];
1541 fw_hdr
= wl
->fw
.fw_hdr
[i
];
1542 if (fw
== NULL
&& fw_hdr
== NULL
) {
1544 } else if (fw
== NULL
|| fw_hdr
== NULL
) {
1545 wiphy_err(wl
->wiphy
, "%s: invalid bin/hdr fw\n",
1548 } else if (fw_hdr
->size
% sizeof(struct firmware_hdr
)) {
1549 wiphy_err(wl
->wiphy
, "%s: non integral fw hdr file "
1550 "size %zu/%zu\n", __func__
, fw_hdr
->size
,
1551 sizeof(struct firmware_hdr
));
1553 } else if (fw
->size
< MIN_FW_SIZE
|| fw
->size
> MAX_FW_SIZE
) {
1554 wiphy_err(wl
->wiphy
, "%s: out of bounds fw file size "
1555 "%zu\n", __func__
, fw
->size
);
1558 /* check if ucode section overruns firmware image */
1559 ucode_hdr
= (struct firmware_hdr
*)fw_hdr
->data
;
1560 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
] &&
1561 !rc
; entry
++, ucode_hdr
++) {
1562 if (le32_to_cpu(ucode_hdr
->offset
) +
1563 le32_to_cpu(ucode_hdr
->len
) >
1565 wiphy_err(wl
->wiphy
,
1566 "%s: conflicting bin/hdr\n",
1573 if (rc
== 0 && wl
->fw
.fw_cnt
!= i
) {
1574 wiphy_err(wl
->wiphy
, "%s: invalid fw_cnt=%d\n", __func__
,
1582 * precondition: perimeter lock has been acquired
1584 bool brcms_rfkill_set_hw_state(struct brcms_info
*wl
)
1586 bool blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
1588 spin_unlock_bh(&wl
->lock
);
1589 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
1591 wiphy_rfkill_start_polling(wl
->pub
->ieee_hw
->wiphy
);
1592 spin_lock_bh(&wl
->lock
);
1597 * precondition: perimeter lock has been acquired
1599 void brcms_msleep(struct brcms_info
*wl
, uint ms
)
1601 spin_unlock_bh(&wl
->lock
);
1603 spin_lock_bh(&wl
->lock
);