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
)
127 static struct ieee80211_channel brcms_5ghz_nphy_chantable
[] = {
129 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS
),
130 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS
),
131 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS
),
132 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS
),
135 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
136 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
138 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
139 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
141 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
142 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
144 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
145 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
148 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
149 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
151 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
152 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
154 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
155 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
157 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
158 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
160 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
161 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
163 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
164 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
166 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
167 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
169 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
170 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
172 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
173 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
175 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
176 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
178 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
179 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
|
180 IEEE80211_CHAN_NO_HT40MINUS
),
182 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS
),
183 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS
),
184 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS
),
185 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS
),
186 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS
| IEEE80211_CHAN_NO_HT40MINUS
)
190 * The rate table is used for both 2.4G and 5G rates. The
191 * latter being a subset as it does not support CCK rates.
193 static struct ieee80211_rate legacy_ratetable
[] = {
195 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE
),
196 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE
),
197 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE
),
208 static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template
= {
209 .band
= IEEE80211_BAND_2GHZ
,
210 .channels
= brcms_2ghz_chantable
,
211 .n_channels
= ARRAY_SIZE(brcms_2ghz_chantable
),
212 .bitrates
= legacy_ratetable
,
213 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
),
215 /* from include/linux/ieee80211.h */
216 .cap
= IEEE80211_HT_CAP_GRN_FLD
|
217 IEEE80211_HT_CAP_SGI_20
| IEEE80211_HT_CAP_SGI_40
,
218 .ht_supported
= true,
219 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
220 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
222 /* placeholders for now */
223 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
224 .rx_highest
= cpu_to_le16(500),
225 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
229 static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template
= {
230 .band
= IEEE80211_BAND_5GHZ
,
231 .channels
= brcms_5ghz_nphy_chantable
,
232 .n_channels
= ARRAY_SIZE(brcms_5ghz_nphy_chantable
),
233 .bitrates
= legacy_ratetable
+ BRCMS_LEGACY_5G_RATE_OFFSET
,
234 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
) -
235 BRCMS_LEGACY_5G_RATE_OFFSET
,
237 .cap
= IEEE80211_HT_CAP_GRN_FLD
| IEEE80211_HT_CAP_SGI_20
|
238 IEEE80211_HT_CAP_SGI_40
,
239 .ht_supported
= true,
240 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
241 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
243 /* placeholders for now */
244 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
245 .rx_highest
= cpu_to_le16(500),
246 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
250 /* flags the given rate in rateset as requested */
251 static void brcms_set_basic_rate(struct brcm_rateset
*rs
, u16 rate
, bool is_br
)
255 for (i
= 0; i
< rs
->count
; i
++) {
256 if (rate
!= (rs
->rates
[i
] & 0x7f))
260 rs
->rates
[i
] |= BRCMS_RATE_FLAG
;
262 rs
->rates
[i
] &= BRCMS_RATE_MASK
;
267 static void brcms_ops_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
269 struct brcms_info
*wl
= hw
->priv
;
271 spin_lock_bh(&wl
->lock
);
273 wiphy_err(wl
->wiphy
, "ops->tx called while down\n");
277 brcms_c_sendpkt_mac80211(wl
->wlc
, skb
, hw
);
279 spin_unlock_bh(&wl
->lock
);
282 static int brcms_ops_start(struct ieee80211_hw
*hw
)
284 struct brcms_info
*wl
= hw
->priv
;
288 ieee80211_wake_queues(hw
);
289 spin_lock_bh(&wl
->lock
);
290 blocked
= brcms_rfkill_set_hw_state(wl
);
291 spin_unlock_bh(&wl
->lock
);
293 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
295 spin_lock_bh(&wl
->lock
);
296 /* avoid acknowledging frames before a non-monitor device is added */
303 spin_unlock_bh(&wl
->lock
);
306 wiphy_err(hw
->wiphy
, "%s: brcms_up() returned %d\n", __func__
,
311 static void brcms_ops_stop(struct ieee80211_hw
*hw
)
313 struct brcms_info
*wl
= hw
->priv
;
316 ieee80211_stop_queues(hw
);
321 spin_lock_bh(&wl
->lock
);
322 status
= brcms_c_chipmatch(wl
->wlc
->hw
->vendorid
,
323 wl
->wlc
->hw
->deviceid
);
324 spin_unlock_bh(&wl
->lock
);
327 "wl: brcms_ops_stop: chipmatch failed\n");
331 /* put driver in down state */
332 spin_lock_bh(&wl
->lock
);
334 spin_unlock_bh(&wl
->lock
);
338 brcms_ops_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
340 struct brcms_info
*wl
= hw
->priv
;
342 /* Just STA for now */
343 if (vif
->type
!= NL80211_IFTYPE_STATION
) {
344 wiphy_err(hw
->wiphy
, "%s: Attempt to add type %d, only"
345 " STA for now\n", __func__
, vif
->type
);
350 brcms_c_mute(wl
->wlc
, false);
356 brcms_ops_remove_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
360 static int brcms_ops_config(struct ieee80211_hw
*hw
, u32 changed
)
362 struct ieee80211_conf
*conf
= &hw
->conf
;
363 struct brcms_info
*wl
= hw
->priv
;
366 struct wiphy
*wiphy
= hw
->wiphy
;
368 spin_lock_bh(&wl
->lock
);
369 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
370 brcms_c_set_beacon_listen_interval(wl
->wlc
,
371 conf
->listen_interval
);
373 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
)
374 wiphy_dbg(wiphy
, "%s: change monitor mode: %s\n",
375 __func__
, conf
->flags
& IEEE80211_CONF_MONITOR
?
377 if (changed
& IEEE80211_CONF_CHANGE_PS
)
378 wiphy_err(wiphy
, "%s: change power-save mode: %s (implement)\n",
379 __func__
, conf
->flags
& IEEE80211_CONF_PS
?
382 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
383 err
= brcms_c_set_tx_power(wl
->wlc
, conf
->power_level
);
385 wiphy_err(wiphy
, "%s: Error setting power_level\n",
389 new_int
= brcms_c_get_tx_power(wl
->wlc
);
390 if (new_int
!= conf
->power_level
)
391 wiphy_err(wiphy
, "%s: Power level req != actual, %d %d"
392 "\n", __func__
, conf
->power_level
,
395 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
396 if (conf
->channel_type
== NL80211_CHAN_HT20
||
397 conf
->channel_type
== NL80211_CHAN_NO_HT
)
398 err
= brcms_c_set_channel(wl
->wlc
,
399 conf
->channel
->hw_value
);
403 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
)
404 err
= brcms_c_set_rate_limit(wl
->wlc
,
405 conf
->short_frame_max_tx_count
,
406 conf
->long_frame_max_tx_count
);
409 spin_unlock_bh(&wl
->lock
);
414 brcms_ops_bss_info_changed(struct ieee80211_hw
*hw
,
415 struct ieee80211_vif
*vif
,
416 struct ieee80211_bss_conf
*info
, u32 changed
)
418 struct brcms_info
*wl
= hw
->priv
;
419 struct wiphy
*wiphy
= hw
->wiphy
;
421 if (changed
& BSS_CHANGED_ASSOC
) {
422 /* association status changed (associated/disassociated)
423 * also implies a change in the AID.
425 wiphy_err(wiphy
, "%s: %s: %sassociated\n", KBUILD_MODNAME
,
426 __func__
, info
->assoc
? "" : "dis");
427 spin_lock_bh(&wl
->lock
);
428 brcms_c_associate_upd(wl
->wlc
, info
->assoc
);
429 spin_unlock_bh(&wl
->lock
);
431 if (changed
& BSS_CHANGED_ERP_SLOT
) {
434 /* slot timing changed */
435 if (info
->use_short_slot
)
439 spin_lock_bh(&wl
->lock
);
440 brcms_c_set_shortslot_override(wl
->wlc
, val
);
441 spin_unlock_bh(&wl
->lock
);
444 if (changed
& BSS_CHANGED_HT
) {
445 /* 802.11n parameters changed */
446 u16 mode
= info
->ht_operation_mode
;
448 spin_lock_bh(&wl
->lock
);
449 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_CFG
,
450 mode
& IEEE80211_HT_OP_MODE_PROTECTION
);
451 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_NONGF
,
452 mode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
453 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_OBSS
,
454 mode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
);
455 spin_unlock_bh(&wl
->lock
);
457 if (changed
& BSS_CHANGED_BASIC_RATES
) {
458 struct ieee80211_supported_band
*bi
;
461 struct brcm_rateset rs
;
464 /* retrieve the current rates */
465 spin_lock_bh(&wl
->lock
);
466 brcms_c_get_current_rateset(wl
->wlc
, &rs
);
467 spin_unlock_bh(&wl
->lock
);
469 br_mask
= info
->basic_rates
;
470 bi
= hw
->wiphy
->bands
[brcms_c_get_curband(wl
->wlc
)];
471 for (i
= 0; i
< bi
->n_bitrates
; i
++) {
472 /* convert to internal rate value */
473 rate
= (bi
->bitrates
[i
].bitrate
<< 1) / 10;
475 /* set/clear basic rate flag */
476 brcms_set_basic_rate(&rs
, rate
, br_mask
& 1);
480 /* update the rate set */
481 spin_lock_bh(&wl
->lock
);
482 error
= brcms_c_set_rateset(wl
->wlc
, &rs
);
483 spin_unlock_bh(&wl
->lock
);
485 wiphy_err(wiphy
, "changing basic rates failed: %d\n",
488 if (changed
& BSS_CHANGED_BEACON_INT
) {
489 /* Beacon interval changed */
490 spin_lock_bh(&wl
->lock
);
491 brcms_c_set_beacon_period(wl
->wlc
, info
->beacon_int
);
492 spin_unlock_bh(&wl
->lock
);
494 if (changed
& BSS_CHANGED_BSSID
) {
495 /* BSSID changed, for whatever reason (IBSS and managed mode) */
496 spin_lock_bh(&wl
->lock
);
497 brcms_c_set_addrmatch(wl
->wlc
, RCM_BSSID_OFFSET
, info
->bssid
);
498 spin_unlock_bh(&wl
->lock
);
500 if (changed
& BSS_CHANGED_BEACON
)
501 /* Beacon data changed, retrieve new beacon (beaconing modes) */
502 wiphy_err(wiphy
, "%s: beacon changed\n", __func__
);
504 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
505 /* Beaconing should be enabled/disabled (beaconing modes) */
506 wiphy_err(wiphy
, "%s: Beacon enabled: %s\n", __func__
,
507 info
->enable_beacon
? "true" : "false");
510 if (changed
& BSS_CHANGED_CQM
) {
511 /* Connection quality monitor config changed */
512 wiphy_err(wiphy
, "%s: cqm change: threshold %d, hys %d "
513 " (implement)\n", __func__
, info
->cqm_rssi_thold
,
514 info
->cqm_rssi_hyst
);
517 if (changed
& BSS_CHANGED_IBSS
) {
518 /* IBSS join status changed */
519 wiphy_err(wiphy
, "%s: IBSS joined: %s (implement)\n", __func__
,
520 info
->ibss_joined
? "true" : "false");
523 if (changed
& BSS_CHANGED_ARP_FILTER
) {
524 /* Hardware ARP filter address list or state changed */
525 wiphy_err(wiphy
, "%s: arp filtering: enabled %s, count %d"
526 " (implement)\n", __func__
, info
->arp_filter_enabled
?
527 "true" : "false", info
->arp_addr_cnt
);
530 if (changed
& BSS_CHANGED_QOS
) {
532 * QoS for this association was enabled/disabled.
533 * Note that it is only ever disabled for station mode.
535 wiphy_err(wiphy
, "%s: qos enabled: %s (implement)\n", __func__
,
536 info
->qos
? "true" : "false");
542 brcms_ops_configure_filter(struct ieee80211_hw
*hw
,
543 unsigned int changed_flags
,
544 unsigned int *total_flags
, u64 multicast
)
546 struct brcms_info
*wl
= hw
->priv
;
547 struct wiphy
*wiphy
= hw
->wiphy
;
549 changed_flags
&= MAC_FILTERS
;
550 *total_flags
&= MAC_FILTERS
;
552 if (changed_flags
& FIF_PROMISC_IN_BSS
)
553 wiphy_dbg(wiphy
, "FIF_PROMISC_IN_BSS\n");
554 if (changed_flags
& FIF_ALLMULTI
)
555 wiphy_dbg(wiphy
, "FIF_ALLMULTI\n");
556 if (changed_flags
& FIF_FCSFAIL
)
557 wiphy_dbg(wiphy
, "FIF_FCSFAIL\n");
558 if (changed_flags
& FIF_CONTROL
)
559 wiphy_dbg(wiphy
, "FIF_CONTROL\n");
560 if (changed_flags
& FIF_OTHER_BSS
)
561 wiphy_dbg(wiphy
, "FIF_OTHER_BSS\n");
562 if (changed_flags
& FIF_PSPOLL
)
563 wiphy_dbg(wiphy
, "FIF_PSPOLL\n");
564 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
)
565 wiphy_dbg(wiphy
, "FIF_BCN_PRBRESP_PROMISC\n");
567 spin_lock_bh(&wl
->lock
);
568 brcms_c_mac_promisc(wl
->wlc
, *total_flags
);
569 spin_unlock_bh(&wl
->lock
);
573 static void brcms_ops_sw_scan_start(struct ieee80211_hw
*hw
)
575 struct brcms_info
*wl
= hw
->priv
;
576 spin_lock_bh(&wl
->lock
);
577 brcms_c_scan_start(wl
->wlc
);
578 spin_unlock_bh(&wl
->lock
);
582 static void brcms_ops_sw_scan_complete(struct ieee80211_hw
*hw
)
584 struct brcms_info
*wl
= hw
->priv
;
585 spin_lock_bh(&wl
->lock
);
586 brcms_c_scan_stop(wl
->wlc
);
587 spin_unlock_bh(&wl
->lock
);
592 brcms_ops_conf_tx(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
, u16 queue
,
593 const struct ieee80211_tx_queue_params
*params
)
595 struct brcms_info
*wl
= hw
->priv
;
597 spin_lock_bh(&wl
->lock
);
598 brcms_c_wme_setparams(wl
->wlc
, queue
, params
, true);
599 spin_unlock_bh(&wl
->lock
);
605 brcms_ops_sta_add(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
606 struct ieee80211_sta
*sta
)
608 struct brcms_info
*wl
= hw
->priv
;
609 struct scb
*scb
= &wl
->wlc
->pri_scb
;
611 brcms_c_init_scb(scb
);
613 wl
->pub
->global_ampdu
= &(scb
->scb_ampdu
);
614 wl
->pub
->global_ampdu
->scb
= scb
;
615 wl
->pub
->global_ampdu
->max_pdu
= 16;
618 * minstrel_ht initiates addBA on our behalf by calling
619 * ieee80211_start_tx_ba_session()
625 brcms_ops_ampdu_action(struct ieee80211_hw
*hw
,
626 struct ieee80211_vif
*vif
,
627 enum ieee80211_ampdu_mlme_action action
,
628 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
631 struct brcms_info
*wl
= hw
->priv
;
632 struct scb
*scb
= &wl
->wlc
->pri_scb
;
635 if (WARN_ON(scb
->magic
!= SCB_MAGIC
))
638 case IEEE80211_AMPDU_RX_START
:
640 case IEEE80211_AMPDU_RX_STOP
:
642 case IEEE80211_AMPDU_TX_START
:
643 spin_lock_bh(&wl
->lock
);
644 status
= brcms_c_aggregatable(wl
->wlc
, tid
);
645 spin_unlock_bh(&wl
->lock
);
647 wiphy_err(wl
->wiphy
, "START: tid %d is not agg\'able\n",
651 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
654 case IEEE80211_AMPDU_TX_STOP
:
655 spin_lock_bh(&wl
->lock
);
656 brcms_c_ampdu_flush(wl
->wlc
, sta
, tid
);
657 spin_unlock_bh(&wl
->lock
);
658 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
660 case IEEE80211_AMPDU_TX_OPERATIONAL
:
662 * BA window size from ADDBA response ('buf_size') defines how
663 * many outstanding MPDUs are allowed for the BA stream by
664 * recipient and traffic class. 'ampdu_factor' gives maximum
667 spin_lock_bh(&wl
->lock
);
668 brcms_c_ampdu_tx_operational(wl
->wlc
, tid
, buf_size
,
669 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
670 sta
->ht_cap
.ampdu_factor
)) - 1);
671 spin_unlock_bh(&wl
->lock
);
672 /* Power save wakeup */
675 wiphy_err(wl
->wiphy
, "%s: Invalid command, ignoring\n",
682 static void brcms_ops_rfkill_poll(struct ieee80211_hw
*hw
)
684 struct brcms_info
*wl
= hw
->priv
;
687 spin_lock_bh(&wl
->lock
);
688 blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
689 spin_unlock_bh(&wl
->lock
);
691 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
694 static void brcms_ops_flush(struct ieee80211_hw
*hw
, bool drop
)
696 struct brcms_info
*wl
= hw
->priv
;
698 no_printk("%s: drop = %s\n", __func__
, drop
? "true" : "false");
700 /* wait for packet queue and dma fifos to run empty */
701 spin_lock_bh(&wl
->lock
);
702 brcms_c_wait_for_tx_completion(wl
->wlc
, drop
);
703 spin_unlock_bh(&wl
->lock
);
706 static const struct ieee80211_ops brcms_ops
= {
708 .start
= brcms_ops_start
,
709 .stop
= brcms_ops_stop
,
710 .add_interface
= brcms_ops_add_interface
,
711 .remove_interface
= brcms_ops_remove_interface
,
712 .config
= brcms_ops_config
,
713 .bss_info_changed
= brcms_ops_bss_info_changed
,
714 .configure_filter
= brcms_ops_configure_filter
,
715 .sw_scan_start
= brcms_ops_sw_scan_start
,
716 .sw_scan_complete
= brcms_ops_sw_scan_complete
,
717 .conf_tx
= brcms_ops_conf_tx
,
718 .sta_add
= brcms_ops_sta_add
,
719 .ampdu_action
= brcms_ops_ampdu_action
,
720 .rfkill_poll
= brcms_ops_rfkill_poll
,
721 .flush
= brcms_ops_flush
,
724 void brcms_dpc(unsigned long data
)
726 struct brcms_info
*wl
;
728 wl
= (struct brcms_info
*) data
;
730 spin_lock_bh(&wl
->lock
);
732 /* call the common second level interrupt handler */
737 spin_lock_irqsave(&wl
->isr_lock
, flags
);
738 brcms_c_intrsupd(wl
->wlc
);
739 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
742 wl
->resched
= brcms_c_dpc(wl
->wlc
, true);
745 /* brcms_c_dpc() may bring the driver down */
749 /* re-schedule dpc */
751 tasklet_schedule(&wl
->tasklet
);
753 /* re-enable interrupts */
757 spin_unlock_bh(&wl
->lock
);
761 * Precondition: Since this function is called in brcms_pci_probe() context,
762 * no locking is required.
764 static int brcms_request_fw(struct brcms_info
*wl
, struct bcma_device
*pdev
)
767 struct device
*device
= &pdev
->dev
;
771 memset(&wl
->fw
, 0, sizeof(struct brcms_firmware
));
772 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
773 if (brcms_firmwares
[i
] == NULL
)
775 sprintf(fw_name
, "%s-%d.fw", brcms_firmwares
[i
],
776 UCODE_LOADER_API_VER
);
777 status
= request_firmware(&wl
->fw
.fw_bin
[i
], fw_name
, device
);
779 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
780 KBUILD_MODNAME
, fw_name
);
783 sprintf(fw_name
, "%s_hdr-%d.fw", brcms_firmwares
[i
],
784 UCODE_LOADER_API_VER
);
785 status
= request_firmware(&wl
->fw
.fw_hdr
[i
], fw_name
, device
);
787 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
788 KBUILD_MODNAME
, fw_name
);
791 wl
->fw
.hdr_num_entries
[i
] =
792 wl
->fw
.fw_hdr
[i
]->size
/ (sizeof(struct firmware_hdr
));
795 return brcms_ucode_data_init(wl
, &wl
->ucode
);
799 * Precondition: Since this function is called in brcms_pci_probe() context,
800 * no locking is required.
802 static void brcms_release_fw(struct brcms_info
*wl
)
805 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
806 release_firmware(wl
->fw
.fw_bin
[i
]);
807 release_firmware(wl
->fw
.fw_hdr
[i
]);
812 * This function frees the WL per-device resources.
814 * This function frees resources owned by the WL device pointed to
815 * by the wl parameter.
817 * precondition: can both be called locked and unlocked
820 static void brcms_free(struct brcms_info
*wl
)
822 struct brcms_timer
*t
, *next
;
824 /* free ucode data */
826 brcms_ucode_data_free(&wl
->ucode
);
828 free_irq(wl
->irq
, wl
);
831 tasklet_kill(&wl
->tasklet
);
834 brcms_c_module_unregister(wl
->pub
, "linux", wl
);
836 /* free common resources */
838 brcms_c_detach(wl
->wlc
);
843 /* virtual interface deletion is deferred so we cannot spinwait */
845 /* wait for all pending callbacks to complete */
846 while (atomic_read(&wl
->callbacks
) > 0)
850 for (t
= wl
->timers
; t
; t
= next
) {
860 * called from both kernel as from this kernel module (error flow on attach)
861 * precondition: perimeter lock is not acquired.
863 static void brcms_remove(struct bcma_device
*pdev
)
865 struct ieee80211_hw
*hw
= bcma_get_drvdata(pdev
);
866 struct brcms_info
*wl
= hw
->priv
;
869 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, false);
870 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
871 ieee80211_unregister_hw(hw
);
876 bcma_set_drvdata(pdev
, NULL
);
877 ieee80211_free_hw(hw
);
880 static irqreturn_t
brcms_isr(int irq
, void *dev_id
)
882 struct brcms_info
*wl
;
885 wl
= (struct brcms_info
*) dev_id
;
887 spin_lock(&wl
->isr_lock
);
889 /* call common first level interrupt handler */
890 ours
= brcms_c_isr(wl
->wlc
, &wantdpc
);
892 /* if more to do... */
895 /* ...and call the second level interrupt handler */
897 tasklet_schedule(&wl
->tasklet
);
901 spin_unlock(&wl
->isr_lock
);
903 return IRQ_RETVAL(ours
);
907 * is called in brcms_pci_probe() context, therefore no locking required.
909 static int ieee_hw_rate_init(struct ieee80211_hw
*hw
)
911 struct brcms_info
*wl
= hw
->priv
;
912 struct brcms_c_info
*wlc
= wl
->wlc
;
913 struct ieee80211_supported_band
*band
;
917 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = NULL
;
918 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = NULL
;
920 phy_type
= brcms_c_get_phy_type(wl
->wlc
, 0);
921 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
922 band
= &wlc
->bandstate
[BAND_2G_INDEX
]->band
;
923 *band
= brcms_band_2GHz_nphy_template
;
924 if (phy_type
== PHY_TYPE_LCN
) {
926 band
->ht_cap
.mcs
.rx_mask
[1] = 0;
927 band
->ht_cap
.mcs
.rx_highest
= cpu_to_le16(72);
929 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
934 /* Assume all bands use the same phy. True for 11n devices. */
935 if (wl
->pub
->_nbands
> 1) {
937 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
938 band
= &wlc
->bandstate
[BAND_5G_INDEX
]->band
;
939 *band
= brcms_band_5GHz_nphy_template
;
940 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
949 * is called in brcms_pci_probe() context, therefore no locking required.
951 static int ieee_hw_init(struct ieee80211_hw
*hw
)
953 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
954 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
955 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
956 | IEEE80211_HW_AMPDU_AGGREGATION
;
958 hw
->extra_tx_headroom
= brcms_c_get_header_len();
959 hw
->queues
= N_TX_QUEUES
;
960 hw
->max_rates
= 2; /* Primary rate and 1 fallback rate */
962 /* channel change time is dependent on chip and band */
963 hw
->channel_change_time
= 7 * 1000;
964 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
966 hw
->rate_control_algorithm
= "minstrel_ht";
968 hw
->sta_data_size
= 0;
969 return ieee_hw_rate_init(hw
);
973 * attach to the WL device.
975 * Attach to the WL device identified by vendor and device parameters.
976 * regs is a host accessible memory address pointing to WL device registers.
978 * brcms_attach is not defined as static because in the case where no bus
979 * is defined, wl_attach will never be called, and thus, gcc will issue
980 * a warning that this function is defined but not used if we declare
984 * is called in brcms_bcma_probe() context, therefore no locking required.
986 static struct brcms_info
*brcms_attach(struct bcma_device
*pdev
)
988 struct brcms_info
*wl
= NULL
;
990 struct ieee80211_hw
*hw
;
993 unit
= n_adapters_found
;
999 /* allocate private info */
1000 hw
= bcma_get_drvdata(pdev
);
1003 if (WARN_ON(hw
== NULL
) || WARN_ON(wl
== NULL
))
1005 wl
->wiphy
= hw
->wiphy
;
1007 atomic_set(&wl
->callbacks
, 0);
1009 /* setup the bottom half handler */
1010 tasklet_init(&wl
->tasklet
, brcms_dpc
, (unsigned long) wl
);
1012 spin_lock_init(&wl
->lock
);
1013 spin_lock_init(&wl
->isr_lock
);
1016 if (brcms_request_fw(wl
, pdev
) < 0) {
1017 wiphy_err(wl
->wiphy
, "%s: Failed to find firmware usually in "
1018 "%s\n", KBUILD_MODNAME
, "/lib/firmware/brcm");
1019 brcms_release_fw(wl
);
1024 /* common load-time initialization */
1025 wl
->wlc
= brcms_c_attach((void *)wl
, pdev
, unit
, false, &err
);
1026 brcms_release_fw(wl
);
1028 wiphy_err(wl
->wiphy
, "%s: attach() failed with code %d\n",
1029 KBUILD_MODNAME
, err
);
1032 wl
->pub
= brcms_c_pub(wl
->wlc
);
1034 wl
->pub
->ieee_hw
= hw
;
1036 /* register our interrupt handler */
1037 if (request_irq(pdev
->irq
, brcms_isr
,
1038 IRQF_SHARED
, KBUILD_MODNAME
, wl
)) {
1039 wiphy_err(wl
->wiphy
, "wl%d: request_irq() failed\n", unit
);
1042 wl
->irq
= pdev
->irq
;
1044 /* register module */
1045 brcms_c_module_register(wl
->pub
, "linux", wl
, NULL
);
1047 if (ieee_hw_init(hw
)) {
1048 wiphy_err(wl
->wiphy
, "wl%d: %s: ieee_hw_init failed!\n", unit
,
1053 brcms_c_regd_init(wl
->wlc
);
1055 memcpy(perm
, &wl
->pub
->cur_etheraddr
, ETH_ALEN
);
1056 if (WARN_ON(!is_valid_ether_addr(perm
)))
1058 SET_IEEE80211_PERM_ADDR(hw
, perm
);
1060 err
= ieee80211_register_hw(hw
);
1062 wiphy_err(wl
->wiphy
, "%s: ieee80211_register_hw failed, status"
1063 "%d\n", __func__
, err
);
1065 if (wl
->pub
->srom_ccode
[0] &&
1066 regulatory_hint(wl
->wiphy
, wl
->pub
->srom_ccode
))
1067 wiphy_err(wl
->wiphy
, "%s: regulatory hint failed\n", __func__
);
1080 * determines if a device is a WL device, and if so, attaches it.
1082 * This function determines if a device pointed to by pdev is a WL device,
1083 * and if so, performs a brcms_attach() on it.
1085 * Perimeter lock is initialized in the course of this function.
1087 static int __devinit
brcms_bcma_probe(struct bcma_device
*pdev
)
1089 struct brcms_info
*wl
;
1090 struct ieee80211_hw
*hw
;
1092 dev_info(&pdev
->dev
, "mfg %x core %x rev %d class %d irq %d\n",
1093 pdev
->id
.manuf
, pdev
->id
.id
, pdev
->id
.rev
, pdev
->id
.class,
1096 if ((pdev
->id
.manuf
!= BCMA_MANUF_BCM
) ||
1097 (pdev
->id
.id
!= BCMA_CORE_80211
))
1100 hw
= ieee80211_alloc_hw(sizeof(struct brcms_info
), &brcms_ops
);
1102 pr_err("%s: ieee80211_alloc_hw failed\n", __func__
);
1106 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1108 bcma_set_drvdata(pdev
, hw
);
1110 memset(hw
->priv
, 0, sizeof(*wl
));
1112 wl
= brcms_attach(pdev
);
1114 pr_err("%s: brcms_attach failed!\n", __func__
);
1120 static int brcms_suspend(struct bcma_device
*pdev
)
1122 struct brcms_info
*wl
;
1123 struct ieee80211_hw
*hw
;
1125 hw
= bcma_get_drvdata(pdev
);
1128 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME
,
1133 /* only need to flag hw is down for proper resume */
1134 spin_lock_bh(&wl
->lock
);
1135 wl
->pub
->hw_up
= false;
1136 spin_unlock_bh(&wl
->lock
);
1138 pr_debug("brcms_suspend ok\n");
1143 static int brcms_resume(struct bcma_device
*pdev
)
1145 pr_debug("brcms_resume ok\n");
1149 static struct bcma_driver brcms_bcma_driver
= {
1150 .name
= KBUILD_MODNAME
,
1151 .probe
= brcms_bcma_probe
,
1152 .suspend
= brcms_suspend
,
1153 .resume
= brcms_resume
,
1154 .remove
= __devexit_p(brcms_remove
),
1155 .id_table
= brcms_coreid_table
,
1159 * This is the main entry point for the brcmsmac driver.
1161 * This function is scheduled upon module initialization and
1162 * does the driver registration, which result in brcms_bcma_probe()
1163 * call resulting in the driver bringup.
1165 static void brcms_driver_init(struct work_struct
*work
)
1169 error
= bcma_driver_register(&brcms_bcma_driver
);
1171 pr_err("%s: register returned %d\n", __func__
, error
);
1174 static DECLARE_WORK(brcms_driver_work
, brcms_driver_init
);
1176 static int __init
brcms_module_init(void)
1179 if (msglevel
!= 0xdeadbeef)
1180 brcm_msg_level
= msglevel
;
1182 if (!schedule_work(&brcms_driver_work
))
1189 * This function unloads the brcmsmac driver from the system.
1191 * This function unconditionally unloads the brcmsmac driver module from the
1195 static void __exit
brcms_module_exit(void)
1197 cancel_work_sync(&brcms_driver_work
);
1198 bcma_driver_unregister(&brcms_bcma_driver
);
1201 module_init(brcms_module_init
);
1202 module_exit(brcms_module_exit
);
1205 * precondition: perimeter lock has been acquired
1207 void brcms_txflowcontrol(struct brcms_info
*wl
, struct brcms_if
*wlif
,
1208 bool state
, int prio
)
1210 wiphy_err(wl
->wiphy
, "Shouldn't be here %s\n", __func__
);
1214 * precondition: perimeter lock has been acquired
1216 void brcms_init(struct brcms_info
*wl
)
1218 BCMMSG(wl
->pub
->ieee_hw
->wiphy
, "wl%d\n", wl
->pub
->unit
);
1220 brcms_c_init(wl
->wlc
, wl
->mute_tx
);
1224 * precondition: perimeter lock has been acquired
1226 uint
brcms_reset(struct brcms_info
*wl
)
1228 BCMMSG(wl
->pub
->ieee_hw
->wiphy
, "wl%d\n", wl
->pub
->unit
);
1229 brcms_c_reset(wl
->wlc
);
1231 /* dpc will not be rescheduled */
1232 wl
->resched
= false;
1237 void brcms_fatal_error(struct brcms_info
*wl
)
1239 wiphy_err(wl
->wlc
->wiphy
, "wl%d: fatal error, reinitializing\n",
1240 wl
->wlc
->pub
->unit
);
1242 ieee80211_restart_hw(wl
->pub
->ieee_hw
);
1246 * These are interrupt on/off entry points. Disable interrupts
1247 * during interrupt state transition.
1249 void brcms_intrson(struct brcms_info
*wl
)
1251 unsigned long flags
;
1253 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1254 brcms_c_intrson(wl
->wlc
);
1255 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1258 u32
brcms_intrsoff(struct brcms_info
*wl
)
1260 unsigned long flags
;
1263 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1264 status
= brcms_c_intrsoff(wl
->wlc
);
1265 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1269 void brcms_intrsrestore(struct brcms_info
*wl
, u32 macintmask
)
1271 unsigned long flags
;
1273 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1274 brcms_c_intrsrestore(wl
->wlc
, macintmask
);
1275 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1279 * precondition: perimeter lock has been acquired
1281 int brcms_up(struct brcms_info
*wl
)
1288 error
= brcms_c_up(wl
->wlc
);
1294 * precondition: perimeter lock has been acquired
1296 void brcms_down(struct brcms_info
*wl
)
1298 uint callbacks
, ret_val
= 0;
1300 /* call common down function */
1301 ret_val
= brcms_c_down(wl
->wlc
);
1302 callbacks
= atomic_read(&wl
->callbacks
) - ret_val
;
1304 /* wait for down callbacks to complete */
1305 spin_unlock_bh(&wl
->lock
);
1307 /* For HIGH_only driver, it's important to actually schedule other work,
1308 * not just spin wait since everything runs at schedule level
1310 SPINWAIT((atomic_read(&wl
->callbacks
) > callbacks
), 100 * 1000);
1312 spin_lock_bh(&wl
->lock
);
1316 * precondition: perimeter lock is not acquired
1318 static void _brcms_timer(struct work_struct
*work
)
1320 struct brcms_timer
*t
= container_of(work
, struct brcms_timer
,
1323 spin_lock_bh(&t
->wl
->lock
);
1327 atomic_inc(&t
->wl
->callbacks
);
1328 ieee80211_queue_delayed_work(t
->wl
->pub
->ieee_hw
,
1330 msecs_to_jiffies(t
->ms
));
1338 atomic_dec(&t
->wl
->callbacks
);
1340 spin_unlock_bh(&t
->wl
->lock
);
1344 * Adds a timer to the list. Caller supplies a timer function.
1345 * Is called from wlc.
1347 * precondition: perimeter lock has been acquired
1349 struct brcms_timer
*brcms_init_timer(struct brcms_info
*wl
,
1350 void (*fn
) (void *arg
),
1351 void *arg
, const char *name
)
1353 struct brcms_timer
*t
;
1355 t
= kzalloc(sizeof(struct brcms_timer
), GFP_ATOMIC
);
1359 INIT_DELAYED_WORK(&t
->dly_wrk
, _brcms_timer
);
1363 t
->next
= wl
->timers
;
1367 t
->name
= kmalloc(strlen(name
) + 1, GFP_ATOMIC
);
1369 strcpy(t
->name
, name
);
1376 * adds only the kernel timer since it's going to be more accurate
1377 * as well as it's easier to make it periodic
1379 * precondition: perimeter lock has been acquired
1381 void brcms_add_timer(struct brcms_timer
*t
, uint ms
, int periodic
)
1383 struct ieee80211_hw
*hw
= t
->wl
->pub
->ieee_hw
;
1387 wiphy_err(hw
->wiphy
, "%s: Already set. Name: %s, per %d\n",
1388 __func__
, t
->name
, periodic
);
1391 t
->periodic
= (bool) periodic
;
1394 atomic_inc(&t
->wl
->callbacks
);
1396 ieee80211_queue_delayed_work(hw
, &t
->dly_wrk
, msecs_to_jiffies(ms
));
1400 * return true if timer successfully deleted, false if still pending
1402 * precondition: perimeter lock has been acquired
1404 bool brcms_del_timer(struct brcms_timer
*t
)
1408 if (!cancel_delayed_work(&t
->dly_wrk
))
1411 atomic_dec(&t
->wl
->callbacks
);
1418 * precondition: perimeter lock has been acquired
1420 void brcms_free_timer(struct brcms_timer
*t
)
1422 struct brcms_info
*wl
= t
->wl
;
1423 struct brcms_timer
*tmp
;
1425 /* delete the timer in case it is active */
1428 if (wl
->timers
== t
) {
1429 wl
->timers
= wl
->timers
->next
;
1440 if (tmp
->next
== t
) {
1441 tmp
->next
= t
->next
;
1454 * precondition: perimeter lock has been acquired
1456 int brcms_ucode_init_buf(struct brcms_info
*wl
, void **pbuf
, u32 idx
)
1460 struct firmware_hdr
*hdr
;
1461 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1462 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1463 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1465 u32 len
= le32_to_cpu(hdr
->len
);
1466 if (le32_to_cpu(hdr
->idx
) == idx
) {
1467 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1468 le32_to_cpu(hdr
->offset
);
1469 *pbuf
= kmemdup(pdata
, len
, GFP_ATOMIC
);
1477 wiphy_err(wl
->wiphy
, "ERROR: ucode buf tag:%d can not be found!\n",
1485 * Precondition: Since this function is called in brcms_bcma_probe() context,
1486 * no locking is required.
1488 int brcms_ucode_init_uint(struct brcms_info
*wl
, size_t *n_bytes
, u32 idx
)
1492 struct firmware_hdr
*hdr
;
1493 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1494 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1495 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1497 if (le32_to_cpu(hdr
->idx
) == idx
) {
1498 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1499 le32_to_cpu(hdr
->offset
);
1500 if (le32_to_cpu(hdr
->len
) != 4) {
1501 wiphy_err(wl
->wiphy
,
1502 "ERROR: fw hdr len\n");
1505 *n_bytes
= le32_to_cpu(*((__le32
*) pdata
));
1510 wiphy_err(wl
->wiphy
, "ERROR: ucode tag:%d can not be found!\n", idx
);
1515 * precondition: can both be called locked and unlocked
1517 void brcms_ucode_free_buf(void *p
)
1523 * checks validity of all firmware images loaded from user space
1525 * Precondition: Since this function is called in brcms_bcma_probe() context,
1526 * no locking is required.
1528 int brcms_check_firmwares(struct brcms_info
*wl
)
1533 const struct firmware
*fw
;
1534 const struct firmware
*fw_hdr
;
1535 struct firmware_hdr
*ucode_hdr
;
1536 for (i
= 0; i
< MAX_FW_IMAGES
&& rc
== 0; i
++) {
1537 fw
= wl
->fw
.fw_bin
[i
];
1538 fw_hdr
= wl
->fw
.fw_hdr
[i
];
1539 if (fw
== NULL
&& fw_hdr
== NULL
) {
1541 } else if (fw
== NULL
|| fw_hdr
== NULL
) {
1542 wiphy_err(wl
->wiphy
, "%s: invalid bin/hdr fw\n",
1545 } else if (fw_hdr
->size
% sizeof(struct firmware_hdr
)) {
1546 wiphy_err(wl
->wiphy
, "%s: non integral fw hdr file "
1547 "size %zu/%zu\n", __func__
, fw_hdr
->size
,
1548 sizeof(struct firmware_hdr
));
1550 } else if (fw
->size
< MIN_FW_SIZE
|| fw
->size
> MAX_FW_SIZE
) {
1551 wiphy_err(wl
->wiphy
, "%s: out of bounds fw file size "
1552 "%zu\n", __func__
, fw
->size
);
1555 /* check if ucode section overruns firmware image */
1556 ucode_hdr
= (struct firmware_hdr
*)fw_hdr
->data
;
1557 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
] &&
1558 !rc
; entry
++, ucode_hdr
++) {
1559 if (le32_to_cpu(ucode_hdr
->offset
) +
1560 le32_to_cpu(ucode_hdr
->len
) >
1562 wiphy_err(wl
->wiphy
,
1563 "%s: conflicting bin/hdr\n",
1570 if (rc
== 0 && wl
->fw
.fw_cnt
!= i
) {
1571 wiphy_err(wl
->wiphy
, "%s: invalid fw_cnt=%d\n", __func__
,
1579 * precondition: perimeter lock has been acquired
1581 bool brcms_rfkill_set_hw_state(struct brcms_info
*wl
)
1583 bool blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
1585 spin_unlock_bh(&wl
->lock
);
1586 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
1588 wiphy_rfkill_start_polling(wl
->pub
->ieee_hw
->wiphy
);
1589 spin_lock_bh(&wl
->lock
);
1594 * precondition: perimeter lock has been acquired
1596 void brcms_msleep(struct brcms_info
*wl
, uint ms
)
1598 spin_unlock_bh(&wl
->lock
);
1600 spin_lock_bh(&wl
->lock
);