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"
38 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
39 #define BRCMS_FLUSH_TIMEOUT 500 /* msec */
41 /* Flags we support */
42 #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
47 FIF_BCN_PRBRESP_PROMISC | \
50 #define CHAN2GHZ(channel, freqency, chflags) { \
51 .band = IEEE80211_BAND_2GHZ, \
52 .center_freq = (freqency), \
53 .hw_value = (channel), \
55 .max_antenna_gain = 0, \
59 #define CHAN5GHZ(channel, chflags) { \
60 .band = IEEE80211_BAND_5GHZ, \
61 .center_freq = 5000 + 5*(channel), \
62 .hw_value = (channel), \
64 .max_antenna_gain = 0, \
68 #define RATE(rate100m, _flags) { \
69 .bitrate = (rate100m), \
71 .hw_value = (rate100m / 5), \
80 static const char * const brcms_firmwares
[MAX_FW_IMAGES
] = {
85 static int n_adapters_found
;
87 MODULE_AUTHOR("Broadcom Corporation");
88 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
89 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
90 MODULE_LICENSE("Dual BSD/GPL");
91 /* This needs to be adjusted when brcms_firmwares changes */
92 MODULE_FIRMWARE("brcm/bcm43xx-0.fw");
93 MODULE_FIRMWARE("brcm/bcm43xx_hdr-0.fw");
95 /* recognized BCMA Core IDs */
96 static struct bcma_device_id brcms_coreid_table
[] = {
97 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 17, BCMA_ANY_CLASS
),
98 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 23, BCMA_ANY_CLASS
),
99 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 24, BCMA_ANY_CLASS
),
102 MODULE_DEVICE_TABLE(bcma
, brcms_coreid_table
);
104 #if defined(CONFIG_BRCMDBG)
106 * Module parameter for setting the debug message level. Available
107 * flags are specified by the BRCM_DL_* macros in
108 * drivers/net/wireless/brcm80211/include/defs.h.
110 module_param_named(debug
, brcm_msg_level
, uint
, S_IRUGO
| S_IWUSR
);
113 static struct ieee80211_channel brcms_2ghz_chantable
[] = {
114 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS
),
115 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS
),
116 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS
),
117 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS
),
118 CHAN2GHZ(5, 2432, 0),
119 CHAN2GHZ(6, 2437, 0),
120 CHAN2GHZ(7, 2442, 0),
121 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS
),
122 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS
),
123 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS
),
124 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS
),
126 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
127 IEEE80211_CHAN_NO_HT40PLUS
),
129 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
130 IEEE80211_CHAN_NO_HT40PLUS
),
132 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_IBSS
|
133 IEEE80211_CHAN_NO_HT40PLUS
| IEEE80211_CHAN_NO_HT40MINUS
|
134 IEEE80211_CHAN_NO_OFDM
)
137 static struct ieee80211_channel brcms_5ghz_nphy_chantable
[] = {
139 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS
),
140 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS
),
141 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS
),
142 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS
),
145 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
146 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
148 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
149 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
151 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
152 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
154 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
155 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
158 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
159 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
161 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
162 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
164 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
165 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
167 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
168 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
170 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
171 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
173 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
174 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
176 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
177 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
179 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
180 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
182 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
183 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40MINUS
),
185 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
186 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
),
188 IEEE80211_CHAN_RADAR
| IEEE80211_CHAN_NO_IBSS
|
189 IEEE80211_CHAN_PASSIVE_SCAN
| IEEE80211_CHAN_NO_HT40PLUS
|
190 IEEE80211_CHAN_NO_HT40MINUS
),
192 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS
),
193 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS
),
194 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS
),
195 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS
),
196 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS
| IEEE80211_CHAN_NO_HT40MINUS
)
200 * The rate table is used for both 2.4G and 5G rates. The
201 * latter being a subset as it does not support CCK rates.
203 static struct ieee80211_rate legacy_ratetable
[] = {
205 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE
),
206 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE
),
207 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE
),
218 static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template
= {
219 .band
= IEEE80211_BAND_2GHZ
,
220 .channels
= brcms_2ghz_chantable
,
221 .n_channels
= ARRAY_SIZE(brcms_2ghz_chantable
),
222 .bitrates
= legacy_ratetable
,
223 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
),
225 /* from include/linux/ieee80211.h */
226 .cap
= IEEE80211_HT_CAP_GRN_FLD
|
227 IEEE80211_HT_CAP_SGI_20
| IEEE80211_HT_CAP_SGI_40
,
228 .ht_supported
= true,
229 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
230 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
232 /* placeholders for now */
233 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
234 .rx_highest
= cpu_to_le16(500),
235 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
239 static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template
= {
240 .band
= IEEE80211_BAND_5GHZ
,
241 .channels
= brcms_5ghz_nphy_chantable
,
242 .n_channels
= ARRAY_SIZE(brcms_5ghz_nphy_chantable
),
243 .bitrates
= legacy_ratetable
+ BRCMS_LEGACY_5G_RATE_OFFSET
,
244 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
) -
245 BRCMS_LEGACY_5G_RATE_OFFSET
,
247 .cap
= IEEE80211_HT_CAP_GRN_FLD
| IEEE80211_HT_CAP_SGI_20
|
248 IEEE80211_HT_CAP_SGI_40
,
249 .ht_supported
= true,
250 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
251 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
253 /* placeholders for now */
254 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
255 .rx_highest
= cpu_to_le16(500),
256 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
260 /* flags the given rate in rateset as requested */
261 static void brcms_set_basic_rate(struct brcm_rateset
*rs
, u16 rate
, bool is_br
)
265 for (i
= 0; i
< rs
->count
; i
++) {
266 if (rate
!= (rs
->rates
[i
] & 0x7f))
270 rs
->rates
[i
] |= BRCMS_RATE_FLAG
;
272 rs
->rates
[i
] &= BRCMS_RATE_MASK
;
277 static void brcms_ops_tx(struct ieee80211_hw
*hw
,
278 struct ieee80211_tx_control
*control
,
281 struct brcms_info
*wl
= hw
->priv
;
282 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
284 spin_lock_bh(&wl
->lock
);
286 brcms_err(wl
->wlc
->hw
->d11core
, "ops->tx called while down\n");
290 if (brcms_c_sendpkt_mac80211(wl
->wlc
, skb
, hw
))
291 tx_info
->rate_driver_data
[0] = control
->sta
;
293 spin_unlock_bh(&wl
->lock
);
296 static int brcms_ops_start(struct ieee80211_hw
*hw
)
298 struct brcms_info
*wl
= hw
->priv
;
302 ieee80211_wake_queues(hw
);
303 spin_lock_bh(&wl
->lock
);
304 blocked
= brcms_rfkill_set_hw_state(wl
);
305 spin_unlock_bh(&wl
->lock
);
307 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
309 spin_lock_bh(&wl
->lock
);
310 /* avoid acknowledging frames before a non-monitor device is added */
320 spin_unlock_bh(&wl
->lock
);
323 brcms_err(wl
->wlc
->hw
->d11core
, "%s: brcms_up() returned %d\n",
328 static void brcms_ops_stop(struct ieee80211_hw
*hw
)
330 struct brcms_info
*wl
= hw
->priv
;
333 ieee80211_stop_queues(hw
);
338 spin_lock_bh(&wl
->lock
);
339 status
= brcms_c_chipmatch(wl
->wlc
->hw
->d11core
);
340 spin_unlock_bh(&wl
->lock
);
342 brcms_err(wl
->wlc
->hw
->d11core
,
343 "wl: brcms_ops_stop: chipmatch failed\n");
347 /* put driver in down state */
348 spin_lock_bh(&wl
->lock
);
350 spin_unlock_bh(&wl
->lock
);
354 brcms_ops_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
356 struct brcms_info
*wl
= hw
->priv
;
358 /* Just STA for now */
359 if (vif
->type
!= NL80211_IFTYPE_STATION
) {
360 brcms_err(wl
->wlc
->hw
->d11core
,
361 "%s: Attempt to add type %d, only STA for now\n",
362 __func__
, vif
->type
);
366 spin_lock_bh(&wl
->lock
);
367 memcpy(wl
->pub
->cur_etheraddr
, vif
->addr
, sizeof(vif
->addr
));
369 brcms_c_mute(wl
->wlc
, false);
370 spin_unlock_bh(&wl
->lock
);
376 brcms_ops_remove_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
380 static int brcms_ops_config(struct ieee80211_hw
*hw
, u32 changed
)
382 struct ieee80211_conf
*conf
= &hw
->conf
;
383 struct brcms_info
*wl
= hw
->priv
;
384 struct bcma_device
*core
= wl
->wlc
->hw
->d11core
;
388 spin_lock_bh(&wl
->lock
);
389 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
390 brcms_c_set_beacon_listen_interval(wl
->wlc
,
391 conf
->listen_interval
);
393 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
)
394 brcms_dbg_info(core
, "%s: change monitor mode: %s\n",
395 __func__
, conf
->flags
& IEEE80211_CONF_MONITOR
?
397 if (changed
& IEEE80211_CONF_CHANGE_PS
)
398 brcms_err(core
, "%s: change power-save mode: %s (implement)\n",
399 __func__
, conf
->flags
& IEEE80211_CONF_PS
?
402 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
403 err
= brcms_c_set_tx_power(wl
->wlc
, conf
->power_level
);
405 brcms_err(core
, "%s: Error setting power_level\n",
409 new_int
= brcms_c_get_tx_power(wl
->wlc
);
410 if (new_int
!= conf
->power_level
)
412 "%s: Power level req != actual, %d %d\n",
413 __func__
, conf
->power_level
,
416 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
417 if (conf
->channel_type
== NL80211_CHAN_HT20
||
418 conf
->channel_type
== NL80211_CHAN_NO_HT
)
419 err
= brcms_c_set_channel(wl
->wlc
,
420 conf
->channel
->hw_value
);
424 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
)
425 err
= brcms_c_set_rate_limit(wl
->wlc
,
426 conf
->short_frame_max_tx_count
,
427 conf
->long_frame_max_tx_count
);
430 spin_unlock_bh(&wl
->lock
);
435 brcms_ops_bss_info_changed(struct ieee80211_hw
*hw
,
436 struct ieee80211_vif
*vif
,
437 struct ieee80211_bss_conf
*info
, u32 changed
)
439 struct brcms_info
*wl
= hw
->priv
;
440 struct bcma_device
*core
= wl
->wlc
->hw
->d11core
;
442 if (changed
& BSS_CHANGED_ASSOC
) {
443 /* association status changed (associated/disassociated)
444 * also implies a change in the AID.
446 brcms_err(core
, "%s: %s: %sassociated\n", KBUILD_MODNAME
,
447 __func__
, info
->assoc
? "" : "dis");
448 spin_lock_bh(&wl
->lock
);
449 brcms_c_associate_upd(wl
->wlc
, info
->assoc
);
450 spin_unlock_bh(&wl
->lock
);
452 if (changed
& BSS_CHANGED_ERP_SLOT
) {
455 /* slot timing changed */
456 if (info
->use_short_slot
)
460 spin_lock_bh(&wl
->lock
);
461 brcms_c_set_shortslot_override(wl
->wlc
, val
);
462 spin_unlock_bh(&wl
->lock
);
465 if (changed
& BSS_CHANGED_HT
) {
466 /* 802.11n parameters changed */
467 u16 mode
= info
->ht_operation_mode
;
469 spin_lock_bh(&wl
->lock
);
470 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_CFG
,
471 mode
& IEEE80211_HT_OP_MODE_PROTECTION
);
472 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_NONGF
,
473 mode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
474 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_OBSS
,
475 mode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
);
476 spin_unlock_bh(&wl
->lock
);
478 if (changed
& BSS_CHANGED_BASIC_RATES
) {
479 struct ieee80211_supported_band
*bi
;
482 struct brcm_rateset rs
;
485 /* retrieve the current rates */
486 spin_lock_bh(&wl
->lock
);
487 brcms_c_get_current_rateset(wl
->wlc
, &rs
);
488 spin_unlock_bh(&wl
->lock
);
490 br_mask
= info
->basic_rates
;
491 bi
= hw
->wiphy
->bands
[brcms_c_get_curband(wl
->wlc
)];
492 for (i
= 0; i
< bi
->n_bitrates
; i
++) {
493 /* convert to internal rate value */
494 rate
= (bi
->bitrates
[i
].bitrate
<< 1) / 10;
496 /* set/clear basic rate flag */
497 brcms_set_basic_rate(&rs
, rate
, br_mask
& 1);
501 /* update the rate set */
502 spin_lock_bh(&wl
->lock
);
503 error
= brcms_c_set_rateset(wl
->wlc
, &rs
);
504 spin_unlock_bh(&wl
->lock
);
506 brcms_err(core
, "changing basic rates failed: %d\n",
509 if (changed
& BSS_CHANGED_BEACON_INT
) {
510 /* Beacon interval changed */
511 spin_lock_bh(&wl
->lock
);
512 brcms_c_set_beacon_period(wl
->wlc
, info
->beacon_int
);
513 spin_unlock_bh(&wl
->lock
);
515 if (changed
& BSS_CHANGED_BSSID
) {
516 /* BSSID changed, for whatever reason (IBSS and managed mode) */
517 spin_lock_bh(&wl
->lock
);
518 brcms_c_set_addrmatch(wl
->wlc
, RCM_BSSID_OFFSET
, info
->bssid
);
519 spin_unlock_bh(&wl
->lock
);
521 if (changed
& BSS_CHANGED_BEACON
)
522 /* Beacon data changed, retrieve new beacon (beaconing modes) */
523 brcms_err(core
, "%s: beacon changed\n", __func__
);
525 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
526 /* Beaconing should be enabled/disabled (beaconing modes) */
527 brcms_err(core
, "%s: Beacon enabled: %s\n", __func__
,
528 info
->enable_beacon
? "true" : "false");
531 if (changed
& BSS_CHANGED_CQM
) {
532 /* Connection quality monitor config changed */
533 brcms_err(core
, "%s: cqm change: threshold %d, hys %d "
534 " (implement)\n", __func__
, info
->cqm_rssi_thold
,
535 info
->cqm_rssi_hyst
);
538 if (changed
& BSS_CHANGED_IBSS
) {
539 /* IBSS join status changed */
540 brcms_err(core
, "%s: IBSS joined: %s (implement)\n",
541 __func__
, info
->ibss_joined
? "true" : "false");
544 if (changed
& BSS_CHANGED_ARP_FILTER
) {
545 /* Hardware ARP filter address list or state changed */
546 brcms_err(core
, "%s: arp filtering: %d addresses"
547 " (implement)\n", __func__
, info
->arp_addr_cnt
);
550 if (changed
& BSS_CHANGED_QOS
) {
552 * QoS for this association was enabled/disabled.
553 * Note that it is only ever disabled for station mode.
555 brcms_err(core
, "%s: qos enabled: %s (implement)\n",
556 __func__
, info
->qos
? "true" : "false");
562 brcms_ops_configure_filter(struct ieee80211_hw
*hw
,
563 unsigned int changed_flags
,
564 unsigned int *total_flags
, u64 multicast
)
566 struct brcms_info
*wl
= hw
->priv
;
567 struct bcma_device
*core
= wl
->wlc
->hw
->d11core
;
569 changed_flags
&= MAC_FILTERS
;
570 *total_flags
&= MAC_FILTERS
;
572 if (changed_flags
& FIF_PROMISC_IN_BSS
)
573 brcms_dbg_info(core
, "FIF_PROMISC_IN_BSS\n");
574 if (changed_flags
& FIF_ALLMULTI
)
575 brcms_dbg_info(core
, "FIF_ALLMULTI\n");
576 if (changed_flags
& FIF_FCSFAIL
)
577 brcms_dbg_info(core
, "FIF_FCSFAIL\n");
578 if (changed_flags
& FIF_CONTROL
)
579 brcms_dbg_info(core
, "FIF_CONTROL\n");
580 if (changed_flags
& FIF_OTHER_BSS
)
581 brcms_dbg_info(core
, "FIF_OTHER_BSS\n");
582 if (changed_flags
& FIF_PSPOLL
)
583 brcms_dbg_info(core
, "FIF_PSPOLL\n");
584 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
)
585 brcms_dbg_info(core
, "FIF_BCN_PRBRESP_PROMISC\n");
587 spin_lock_bh(&wl
->lock
);
588 brcms_c_mac_promisc(wl
->wlc
, *total_flags
);
589 spin_unlock_bh(&wl
->lock
);
593 static void brcms_ops_sw_scan_start(struct ieee80211_hw
*hw
)
595 struct brcms_info
*wl
= hw
->priv
;
596 spin_lock_bh(&wl
->lock
);
597 brcms_c_scan_start(wl
->wlc
);
598 spin_unlock_bh(&wl
->lock
);
602 static void brcms_ops_sw_scan_complete(struct ieee80211_hw
*hw
)
604 struct brcms_info
*wl
= hw
->priv
;
605 spin_lock_bh(&wl
->lock
);
606 brcms_c_scan_stop(wl
->wlc
);
607 spin_unlock_bh(&wl
->lock
);
612 brcms_ops_conf_tx(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
, u16 queue
,
613 const struct ieee80211_tx_queue_params
*params
)
615 struct brcms_info
*wl
= hw
->priv
;
617 spin_lock_bh(&wl
->lock
);
618 brcms_c_wme_setparams(wl
->wlc
, queue
, params
, true);
619 spin_unlock_bh(&wl
->lock
);
625 brcms_ops_sta_add(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
626 struct ieee80211_sta
*sta
)
628 struct brcms_info
*wl
= hw
->priv
;
629 struct scb
*scb
= &wl
->wlc
->pri_scb
;
631 brcms_c_init_scb(scb
);
633 wl
->pub
->global_ampdu
= &(scb
->scb_ampdu
);
634 wl
->pub
->global_ampdu
->scb
= scb
;
635 wl
->pub
->global_ampdu
->max_pdu
= 16;
638 * minstrel_ht initiates addBA on our behalf by calling
639 * ieee80211_start_tx_ba_session()
645 brcms_ops_ampdu_action(struct ieee80211_hw
*hw
,
646 struct ieee80211_vif
*vif
,
647 enum ieee80211_ampdu_mlme_action action
,
648 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
651 struct brcms_info
*wl
= hw
->priv
;
652 struct scb
*scb
= &wl
->wlc
->pri_scb
;
655 if (WARN_ON(scb
->magic
!= SCB_MAGIC
))
658 case IEEE80211_AMPDU_RX_START
:
660 case IEEE80211_AMPDU_RX_STOP
:
662 case IEEE80211_AMPDU_TX_START
:
663 spin_lock_bh(&wl
->lock
);
664 status
= brcms_c_aggregatable(wl
->wlc
, tid
);
665 spin_unlock_bh(&wl
->lock
);
667 brcms_err(wl
->wlc
->hw
->d11core
,
668 "START: tid %d is not agg\'able\n", tid
);
671 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
674 case IEEE80211_AMPDU_TX_STOP_CONT
:
675 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
676 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
677 spin_lock_bh(&wl
->lock
);
678 brcms_c_ampdu_flush(wl
->wlc
, sta
, tid
);
679 spin_unlock_bh(&wl
->lock
);
680 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
682 case IEEE80211_AMPDU_TX_OPERATIONAL
:
684 * BA window size from ADDBA response ('buf_size') defines how
685 * many outstanding MPDUs are allowed for the BA stream by
686 * recipient and traffic class. 'ampdu_factor' gives maximum
689 spin_lock_bh(&wl
->lock
);
690 brcms_c_ampdu_tx_operational(wl
->wlc
, tid
, buf_size
,
691 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
692 sta
->ht_cap
.ampdu_factor
)) - 1);
693 spin_unlock_bh(&wl
->lock
);
694 /* Power save wakeup */
697 brcms_err(wl
->wlc
->hw
->d11core
,
698 "%s: Invalid command, ignoring\n", __func__
);
704 static void brcms_ops_rfkill_poll(struct ieee80211_hw
*hw
)
706 struct brcms_info
*wl
= hw
->priv
;
709 spin_lock_bh(&wl
->lock
);
710 blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
711 spin_unlock_bh(&wl
->lock
);
713 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
716 static bool brcms_tx_flush_completed(struct brcms_info
*wl
)
720 spin_lock_bh(&wl
->lock
);
721 result
= brcms_c_tx_flush_completed(wl
->wlc
);
722 spin_unlock_bh(&wl
->lock
);
726 static void brcms_ops_flush(struct ieee80211_hw
*hw
, bool drop
)
728 struct brcms_info
*wl
= hw
->priv
;
731 no_printk("%s: drop = %s\n", __func__
, drop
? "true" : "false");
733 ret
= wait_event_timeout(wl
->tx_flush_wq
,
734 brcms_tx_flush_completed(wl
),
735 msecs_to_jiffies(BRCMS_FLUSH_TIMEOUT
));
737 brcms_dbg_mac80211(wl
->wlc
->hw
->d11core
,
738 "ret=%d\n", jiffies_to_msecs(ret
));
741 static const struct ieee80211_ops brcms_ops
= {
743 .start
= brcms_ops_start
,
744 .stop
= brcms_ops_stop
,
745 .add_interface
= brcms_ops_add_interface
,
746 .remove_interface
= brcms_ops_remove_interface
,
747 .config
= brcms_ops_config
,
748 .bss_info_changed
= brcms_ops_bss_info_changed
,
749 .configure_filter
= brcms_ops_configure_filter
,
750 .sw_scan_start
= brcms_ops_sw_scan_start
,
751 .sw_scan_complete
= brcms_ops_sw_scan_complete
,
752 .conf_tx
= brcms_ops_conf_tx
,
753 .sta_add
= brcms_ops_sta_add
,
754 .ampdu_action
= brcms_ops_ampdu_action
,
755 .rfkill_poll
= brcms_ops_rfkill_poll
,
756 .flush
= brcms_ops_flush
,
759 void brcms_dpc(unsigned long data
)
761 struct brcms_info
*wl
;
763 wl
= (struct brcms_info
*) data
;
765 spin_lock_bh(&wl
->lock
);
767 /* call the common second level interrupt handler */
772 spin_lock_irqsave(&wl
->isr_lock
, flags
);
773 brcms_c_intrsupd(wl
->wlc
);
774 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
777 wl
->resched
= brcms_c_dpc(wl
->wlc
, true);
780 /* brcms_c_dpc() may bring the driver down */
784 /* re-schedule dpc */
786 tasklet_schedule(&wl
->tasklet
);
788 /* re-enable interrupts */
792 spin_unlock_bh(&wl
->lock
);
793 wake_up(&wl
->tx_flush_wq
);
797 * Precondition: Since this function is called in brcms_pci_probe() context,
798 * no locking is required.
800 static int brcms_request_fw(struct brcms_info
*wl
, struct bcma_device
*pdev
)
803 struct device
*device
= &pdev
->dev
;
807 memset(&wl
->fw
, 0, sizeof(struct brcms_firmware
));
808 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
809 if (brcms_firmwares
[i
] == NULL
)
811 sprintf(fw_name
, "%s-%d.fw", brcms_firmwares
[i
],
812 UCODE_LOADER_API_VER
);
813 status
= request_firmware(&wl
->fw
.fw_bin
[i
], fw_name
, device
);
815 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
816 KBUILD_MODNAME
, fw_name
);
819 sprintf(fw_name
, "%s_hdr-%d.fw", brcms_firmwares
[i
],
820 UCODE_LOADER_API_VER
);
821 status
= request_firmware(&wl
->fw
.fw_hdr
[i
], fw_name
, device
);
823 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
824 KBUILD_MODNAME
, fw_name
);
827 wl
->fw
.hdr_num_entries
[i
] =
828 wl
->fw
.fw_hdr
[i
]->size
/ (sizeof(struct firmware_hdr
));
831 return brcms_ucode_data_init(wl
, &wl
->ucode
);
835 * Precondition: Since this function is called in brcms_pci_probe() context,
836 * no locking is required.
838 static void brcms_release_fw(struct brcms_info
*wl
)
841 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
842 release_firmware(wl
->fw
.fw_bin
[i
]);
843 release_firmware(wl
->fw
.fw_hdr
[i
]);
848 * This function frees the WL per-device resources.
850 * This function frees resources owned by the WL device pointed to
851 * by the wl parameter.
853 * precondition: can both be called locked and unlocked
856 static void brcms_free(struct brcms_info
*wl
)
858 struct brcms_timer
*t
, *next
;
860 /* free ucode data */
862 brcms_ucode_data_free(&wl
->ucode
);
864 free_irq(wl
->irq
, wl
);
867 tasklet_kill(&wl
->tasklet
);
870 brcms_debugfs_detach(wl
->pub
);
871 brcms_c_module_unregister(wl
->pub
, "linux", wl
);
874 /* free common resources */
876 brcms_c_detach(wl
->wlc
);
881 /* virtual interface deletion is deferred so we cannot spinwait */
883 /* wait for all pending callbacks to complete */
884 while (atomic_read(&wl
->callbacks
) > 0)
888 for (t
= wl
->timers
; t
; t
= next
) {
898 * called from both kernel as from this kernel module (error flow on attach)
899 * precondition: perimeter lock is not acquired.
901 static void brcms_remove(struct bcma_device
*pdev
)
903 struct ieee80211_hw
*hw
= bcma_get_drvdata(pdev
);
904 struct brcms_info
*wl
= hw
->priv
;
907 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, false);
908 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
909 ieee80211_unregister_hw(hw
);
914 bcma_set_drvdata(pdev
, NULL
);
915 ieee80211_free_hw(hw
);
918 static irqreturn_t
brcms_isr(int irq
, void *dev_id
)
920 struct brcms_info
*wl
;
921 irqreturn_t ret
= IRQ_NONE
;
923 wl
= (struct brcms_info
*) dev_id
;
925 spin_lock(&wl
->isr_lock
);
927 /* call common first level interrupt handler */
928 if (brcms_c_isr(wl
->wlc
)) {
929 /* schedule second level handler */
930 tasklet_schedule(&wl
->tasklet
);
934 spin_unlock(&wl
->isr_lock
);
940 * is called in brcms_pci_probe() context, therefore no locking required.
942 static int ieee_hw_rate_init(struct ieee80211_hw
*hw
)
944 struct brcms_info
*wl
= hw
->priv
;
945 struct brcms_c_info
*wlc
= wl
->wlc
;
946 struct ieee80211_supported_band
*band
;
950 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = NULL
;
951 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = NULL
;
953 phy_type
= brcms_c_get_phy_type(wl
->wlc
, 0);
954 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
955 band
= &wlc
->bandstate
[BAND_2G_INDEX
]->band
;
956 *band
= brcms_band_2GHz_nphy_template
;
957 if (phy_type
== PHY_TYPE_LCN
) {
959 band
->ht_cap
.mcs
.rx_mask
[1] = 0;
960 band
->ht_cap
.mcs
.rx_highest
= cpu_to_le16(72);
962 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
967 /* Assume all bands use the same phy. True for 11n devices. */
968 if (wl
->pub
->_nbands
> 1) {
970 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
971 band
= &wlc
->bandstate
[BAND_5G_INDEX
]->band
;
972 *band
= brcms_band_5GHz_nphy_template
;
973 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
982 * is called in brcms_pci_probe() context, therefore no locking required.
984 static int ieee_hw_init(struct ieee80211_hw
*hw
)
986 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
987 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
988 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
989 | IEEE80211_HW_AMPDU_AGGREGATION
;
991 hw
->extra_tx_headroom
= brcms_c_get_header_len();
992 hw
->queues
= N_TX_QUEUES
;
993 hw
->max_rates
= 2; /* Primary rate and 1 fallback rate */
995 /* channel change time is dependent on chip and band */
996 hw
->channel_change_time
= 7 * 1000;
997 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
);
999 hw
->rate_control_algorithm
= "minstrel_ht";
1001 hw
->sta_data_size
= 0;
1002 return ieee_hw_rate_init(hw
);
1006 * attach to the WL device.
1008 * Attach to the WL device identified by vendor and device parameters.
1009 * regs is a host accessible memory address pointing to WL device registers.
1011 * brcms_attach is not defined as static because in the case where no bus
1012 * is defined, wl_attach will never be called, and thus, gcc will issue
1013 * a warning that this function is defined but not used if we declare
1017 * is called in brcms_bcma_probe() context, therefore no locking required.
1019 static struct brcms_info
*brcms_attach(struct bcma_device
*pdev
)
1021 struct brcms_info
*wl
= NULL
;
1023 struct ieee80211_hw
*hw
;
1026 unit
= n_adapters_found
;
1032 /* allocate private info */
1033 hw
= bcma_get_drvdata(pdev
);
1036 if (WARN_ON(hw
== NULL
) || WARN_ON(wl
== NULL
))
1038 wl
->wiphy
= hw
->wiphy
;
1040 atomic_set(&wl
->callbacks
, 0);
1042 init_waitqueue_head(&wl
->tx_flush_wq
);
1044 /* setup the bottom half handler */
1045 tasklet_init(&wl
->tasklet
, brcms_dpc
, (unsigned long) wl
);
1047 spin_lock_init(&wl
->lock
);
1048 spin_lock_init(&wl
->isr_lock
);
1051 if (brcms_request_fw(wl
, pdev
) < 0) {
1052 wiphy_err(wl
->wiphy
, "%s: Failed to find firmware usually in "
1053 "%s\n", KBUILD_MODNAME
, "/lib/firmware/brcm");
1054 brcms_release_fw(wl
);
1059 /* common load-time initialization */
1060 wl
->wlc
= brcms_c_attach((void *)wl
, pdev
, unit
, false, &err
);
1061 brcms_release_fw(wl
);
1063 wiphy_err(wl
->wiphy
, "%s: attach() failed with code %d\n",
1064 KBUILD_MODNAME
, err
);
1067 wl
->pub
= brcms_c_pub(wl
->wlc
);
1069 wl
->pub
->ieee_hw
= hw
;
1071 /* register our interrupt handler */
1072 if (request_irq(pdev
->irq
, brcms_isr
,
1073 IRQF_SHARED
, KBUILD_MODNAME
, wl
)) {
1074 wiphy_err(wl
->wiphy
, "wl%d: request_irq() failed\n", unit
);
1077 wl
->irq
= pdev
->irq
;
1079 /* register module */
1080 brcms_c_module_register(wl
->pub
, "linux", wl
, NULL
);
1082 if (ieee_hw_init(hw
)) {
1083 wiphy_err(wl
->wiphy
, "wl%d: %s: ieee_hw_init failed!\n", unit
,
1088 brcms_c_regd_init(wl
->wlc
);
1090 memcpy(perm
, &wl
->pub
->cur_etheraddr
, ETH_ALEN
);
1091 if (WARN_ON(!is_valid_ether_addr(perm
)))
1093 SET_IEEE80211_PERM_ADDR(hw
, perm
);
1095 err
= ieee80211_register_hw(hw
);
1097 wiphy_err(wl
->wiphy
, "%s: ieee80211_register_hw failed, status"
1098 "%d\n", __func__
, err
);
1100 if (wl
->pub
->srom_ccode
[0] &&
1101 regulatory_hint(wl
->wiphy
, wl
->pub
->srom_ccode
))
1102 wiphy_err(wl
->wiphy
, "%s: regulatory hint failed\n", __func__
);
1104 brcms_debugfs_attach(wl
->pub
);
1105 brcms_debugfs_create_files(wl
->pub
);
1117 * determines if a device is a WL device, and if so, attaches it.
1119 * This function determines if a device pointed to by pdev is a WL device,
1120 * and if so, performs a brcms_attach() on it.
1122 * Perimeter lock is initialized in the course of this function.
1124 static int brcms_bcma_probe(struct bcma_device
*pdev
)
1126 struct brcms_info
*wl
;
1127 struct ieee80211_hw
*hw
;
1129 dev_info(&pdev
->dev
, "mfg %x core %x rev %d class %d irq %d\n",
1130 pdev
->id
.manuf
, pdev
->id
.id
, pdev
->id
.rev
, pdev
->id
.class,
1133 if ((pdev
->id
.manuf
!= BCMA_MANUF_BCM
) ||
1134 (pdev
->id
.id
!= BCMA_CORE_80211
))
1137 hw
= ieee80211_alloc_hw(sizeof(struct brcms_info
), &brcms_ops
);
1139 pr_err("%s: ieee80211_alloc_hw failed\n", __func__
);
1143 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1145 bcma_set_drvdata(pdev
, hw
);
1147 memset(hw
->priv
, 0, sizeof(*wl
));
1149 wl
= brcms_attach(pdev
);
1151 pr_err("%s: brcms_attach failed!\n", __func__
);
1157 static int brcms_suspend(struct bcma_device
*pdev
)
1159 struct brcms_info
*wl
;
1160 struct ieee80211_hw
*hw
;
1162 hw
= bcma_get_drvdata(pdev
);
1165 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME
,
1170 /* only need to flag hw is down for proper resume */
1171 spin_lock_bh(&wl
->lock
);
1172 wl
->pub
->hw_up
= false;
1173 spin_unlock_bh(&wl
->lock
);
1175 brcms_dbg_info(wl
->wlc
->hw
->d11core
, "brcms_suspend ok\n");
1180 static int brcms_resume(struct bcma_device
*pdev
)
1185 static struct bcma_driver brcms_bcma_driver
= {
1186 .name
= KBUILD_MODNAME
,
1187 .probe
= brcms_bcma_probe
,
1188 .suspend
= brcms_suspend
,
1189 .resume
= brcms_resume
,
1190 .remove
= brcms_remove
,
1191 .id_table
= brcms_coreid_table
,
1195 * This is the main entry point for the brcmsmac driver.
1197 * This function is scheduled upon module initialization and
1198 * does the driver registration, which result in brcms_bcma_probe()
1199 * call resulting in the driver bringup.
1201 static void brcms_driver_init(struct work_struct
*work
)
1205 error
= bcma_driver_register(&brcms_bcma_driver
);
1207 pr_err("%s: register returned %d\n", __func__
, error
);
1210 static DECLARE_WORK(brcms_driver_work
, brcms_driver_init
);
1212 static int __init
brcms_module_init(void)
1214 brcms_debugfs_init();
1215 if (!schedule_work(&brcms_driver_work
))
1222 * This function unloads the brcmsmac driver from the system.
1224 * This function unconditionally unloads the brcmsmac driver module from the
1228 static void __exit
brcms_module_exit(void)
1230 cancel_work_sync(&brcms_driver_work
);
1231 bcma_driver_unregister(&brcms_bcma_driver
);
1232 brcms_debugfs_exit();
1235 module_init(brcms_module_init
);
1236 module_exit(brcms_module_exit
);
1239 * precondition: perimeter lock has been acquired
1241 void brcms_txflowcontrol(struct brcms_info
*wl
, struct brcms_if
*wlif
,
1242 bool state
, int prio
)
1244 brcms_err(wl
->wlc
->hw
->d11core
, "Shouldn't be here %s\n", __func__
);
1248 * precondition: perimeter lock has been acquired
1250 void brcms_init(struct brcms_info
*wl
)
1252 brcms_dbg_info(wl
->wlc
->hw
->d11core
, "Initializing wl%d\n",
1255 brcms_c_init(wl
->wlc
, wl
->mute_tx
);
1259 * precondition: perimeter lock has been acquired
1261 uint
brcms_reset(struct brcms_info
*wl
)
1263 brcms_dbg_info(wl
->wlc
->hw
->d11core
, "Resetting wl%d\n", wl
->pub
->unit
);
1264 brcms_c_reset(wl
->wlc
);
1266 /* dpc will not be rescheduled */
1267 wl
->resched
= false;
1269 /* inform publicly that interface is down */
1270 wl
->pub
->up
= false;
1275 void brcms_fatal_error(struct brcms_info
*wl
)
1277 brcms_err(wl
->wlc
->hw
->d11core
, "wl%d: fatal error, reinitializing\n",
1278 wl
->wlc
->pub
->unit
);
1280 ieee80211_restart_hw(wl
->pub
->ieee_hw
);
1284 * These are interrupt on/off entry points. Disable interrupts
1285 * during interrupt state transition.
1287 void brcms_intrson(struct brcms_info
*wl
)
1289 unsigned long flags
;
1291 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1292 brcms_c_intrson(wl
->wlc
);
1293 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1296 u32
brcms_intrsoff(struct brcms_info
*wl
)
1298 unsigned long flags
;
1301 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1302 status
= brcms_c_intrsoff(wl
->wlc
);
1303 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1307 void brcms_intrsrestore(struct brcms_info
*wl
, u32 macintmask
)
1309 unsigned long flags
;
1311 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1312 brcms_c_intrsrestore(wl
->wlc
, macintmask
);
1313 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1317 * precondition: perimeter lock has been acquired
1319 int brcms_up(struct brcms_info
*wl
)
1326 error
= brcms_c_up(wl
->wlc
);
1332 * precondition: perimeter lock has been acquired
1334 void brcms_down(struct brcms_info
*wl
)
1336 uint callbacks
, ret_val
= 0;
1338 /* call common down function */
1339 ret_val
= brcms_c_down(wl
->wlc
);
1340 callbacks
= atomic_read(&wl
->callbacks
) - ret_val
;
1342 /* wait for down callbacks to complete */
1343 spin_unlock_bh(&wl
->lock
);
1345 /* For HIGH_only driver, it's important to actually schedule other work,
1346 * not just spin wait since everything runs at schedule level
1348 SPINWAIT((atomic_read(&wl
->callbacks
) > callbacks
), 100 * 1000);
1350 spin_lock_bh(&wl
->lock
);
1354 * precondition: perimeter lock is not acquired
1356 static void _brcms_timer(struct work_struct
*work
)
1358 struct brcms_timer
*t
= container_of(work
, struct brcms_timer
,
1361 spin_lock_bh(&t
->wl
->lock
);
1365 atomic_inc(&t
->wl
->callbacks
);
1366 ieee80211_queue_delayed_work(t
->wl
->pub
->ieee_hw
,
1368 msecs_to_jiffies(t
->ms
));
1376 atomic_dec(&t
->wl
->callbacks
);
1378 spin_unlock_bh(&t
->wl
->lock
);
1382 * Adds a timer to the list. Caller supplies a timer function.
1383 * Is called from wlc.
1385 * precondition: perimeter lock has been acquired
1387 struct brcms_timer
*brcms_init_timer(struct brcms_info
*wl
,
1388 void (*fn
) (void *arg
),
1389 void *arg
, const char *name
)
1391 struct brcms_timer
*t
;
1393 t
= kzalloc(sizeof(struct brcms_timer
), GFP_ATOMIC
);
1397 INIT_DELAYED_WORK(&t
->dly_wrk
, _brcms_timer
);
1401 t
->next
= wl
->timers
;
1405 t
->name
= kmalloc(strlen(name
) + 1, GFP_ATOMIC
);
1407 strcpy(t
->name
, name
);
1414 * adds only the kernel timer since it's going to be more accurate
1415 * as well as it's easier to make it periodic
1417 * precondition: perimeter lock has been acquired
1419 void brcms_add_timer(struct brcms_timer
*t
, uint ms
, int periodic
)
1421 struct ieee80211_hw
*hw
= t
->wl
->pub
->ieee_hw
;
1425 brcms_dbg_info(t
->wl
->wlc
->hw
->d11core
,
1426 "%s: Already set. Name: %s, per %d\n",
1427 __func__
, t
->name
, periodic
);
1430 t
->periodic
= (bool) periodic
;
1433 atomic_inc(&t
->wl
->callbacks
);
1436 ieee80211_queue_delayed_work(hw
, &t
->dly_wrk
, msecs_to_jiffies(ms
));
1440 * return true if timer successfully deleted, false if still pending
1442 * precondition: perimeter lock has been acquired
1444 bool brcms_del_timer(struct brcms_timer
*t
)
1448 if (!cancel_delayed_work(&t
->dly_wrk
))
1451 atomic_dec(&t
->wl
->callbacks
);
1458 * precondition: perimeter lock has been acquired
1460 void brcms_free_timer(struct brcms_timer
*t
)
1462 struct brcms_info
*wl
= t
->wl
;
1463 struct brcms_timer
*tmp
;
1465 /* delete the timer in case it is active */
1468 if (wl
->timers
== t
) {
1469 wl
->timers
= wl
->timers
->next
;
1480 if (tmp
->next
== t
) {
1481 tmp
->next
= t
->next
;
1494 * precondition: perimeter lock has been acquired
1496 int brcms_ucode_init_buf(struct brcms_info
*wl
, void **pbuf
, u32 idx
)
1500 struct firmware_hdr
*hdr
;
1501 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1502 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1503 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1505 u32 len
= le32_to_cpu(hdr
->len
);
1506 if (le32_to_cpu(hdr
->idx
) == idx
) {
1507 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1508 le32_to_cpu(hdr
->offset
);
1509 *pbuf
= kmemdup(pdata
, len
, GFP_ATOMIC
);
1517 brcms_err(wl
->wlc
->hw
->d11core
,
1518 "ERROR: ucode buf tag:%d can not be found!\n", idx
);
1525 * Precondition: Since this function is called in brcms_bcma_probe() context,
1526 * no locking is required.
1528 int brcms_ucode_init_uint(struct brcms_info
*wl
, size_t *n_bytes
, u32 idx
)
1532 struct firmware_hdr
*hdr
;
1533 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1534 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1535 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1537 if (le32_to_cpu(hdr
->idx
) == idx
) {
1538 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1539 le32_to_cpu(hdr
->offset
);
1540 if (le32_to_cpu(hdr
->len
) != 4) {
1541 brcms_err(wl
->wlc
->hw
->d11core
,
1542 "ERROR: fw hdr len\n");
1545 *n_bytes
= le32_to_cpu(*((__le32
*) pdata
));
1550 brcms_err(wl
->wlc
->hw
->d11core
,
1551 "ERROR: ucode tag:%d can not be found!\n", idx
);
1556 * precondition: can both be called locked and unlocked
1558 void brcms_ucode_free_buf(void *p
)
1564 * checks validity of all firmware images loaded from user space
1566 * Precondition: Since this function is called in brcms_bcma_probe() context,
1567 * no locking is required.
1569 int brcms_check_firmwares(struct brcms_info
*wl
)
1574 const struct firmware
*fw
;
1575 const struct firmware
*fw_hdr
;
1576 struct firmware_hdr
*ucode_hdr
;
1577 for (i
= 0; i
< MAX_FW_IMAGES
&& rc
== 0; i
++) {
1578 fw
= wl
->fw
.fw_bin
[i
];
1579 fw_hdr
= wl
->fw
.fw_hdr
[i
];
1580 if (fw
== NULL
&& fw_hdr
== NULL
) {
1582 } else if (fw
== NULL
|| fw_hdr
== NULL
) {
1583 wiphy_err(wl
->wiphy
, "%s: invalid bin/hdr fw\n",
1586 } else if (fw_hdr
->size
% sizeof(struct firmware_hdr
)) {
1587 wiphy_err(wl
->wiphy
, "%s: non integral fw hdr file "
1588 "size %zu/%zu\n", __func__
, fw_hdr
->size
,
1589 sizeof(struct firmware_hdr
));
1591 } else if (fw
->size
< MIN_FW_SIZE
|| fw
->size
> MAX_FW_SIZE
) {
1592 wiphy_err(wl
->wiphy
, "%s: out of bounds fw file size %zu\n",
1593 __func__
, fw
->size
);
1596 /* check if ucode section overruns firmware image */
1597 ucode_hdr
= (struct firmware_hdr
*)fw_hdr
->data
;
1598 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
] &&
1599 !rc
; entry
++, ucode_hdr
++) {
1600 if (le32_to_cpu(ucode_hdr
->offset
) +
1601 le32_to_cpu(ucode_hdr
->len
) >
1603 wiphy_err(wl
->wiphy
,
1604 "%s: conflicting bin/hdr\n",
1611 if (rc
== 0 && wl
->fw
.fw_cnt
!= i
) {
1612 wiphy_err(wl
->wiphy
, "%s: invalid fw_cnt=%d\n", __func__
,
1620 * precondition: perimeter lock has been acquired
1622 bool brcms_rfkill_set_hw_state(struct brcms_info
*wl
)
1624 bool blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
1626 spin_unlock_bh(&wl
->lock
);
1627 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
1629 wiphy_rfkill_start_polling(wl
->pub
->ieee_hw
->wiphy
);
1630 spin_lock_bh(&wl
->lock
);