2 * Copyright (c) 2010 Broadcom Corporation
3 * Copyright (c) 2013 Hauke Mehrtens <hauke@hauke-m.de>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #define __UNDEF_NO_VERSION__
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/etherdevice.h>
22 #include <linux/sched.h>
23 #include <linux/firmware.h>
24 #include <linux/interrupt.h>
25 #include <linux/module.h>
26 #include <linux/bcma/bcma.h>
27 #include <net/mac80211.h>
29 #include "phy/phy_int.h"
34 #include "ucode_loader.h"
35 #include "mac80211_if.h"
40 #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
41 #define BRCMS_FLUSH_TIMEOUT 500 /* msec */
43 /* Flags we support */
44 #define MAC_FILTERS (FIF_ALLMULTI | \
48 FIF_BCN_PRBRESP_PROMISC | \
51 #define CHAN2GHZ(channel, freqency, chflags) { \
52 .band = NL80211_BAND_2GHZ, \
53 .center_freq = (freqency), \
54 .hw_value = (channel), \
56 .max_antenna_gain = 0, \
60 #define CHAN5GHZ(channel, chflags) { \
61 .band = NL80211_BAND_5GHZ, \
62 .center_freq = 5000 + 5*(channel), \
63 .hw_value = (channel), \
65 .max_antenna_gain = 0, \
69 #define RATE(rate100m, _flags) { \
70 .bitrate = (rate100m), \
72 .hw_value = (rate100m / 5), \
81 static const char * const brcms_firmwares
[MAX_FW_IMAGES
] = {
86 static int n_adapters_found
;
88 MODULE_AUTHOR("Broadcom Corporation");
89 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
90 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
91 MODULE_LICENSE("Dual BSD/GPL");
92 /* This needs to be adjusted when brcms_firmwares changes */
93 MODULE_FIRMWARE("brcm/bcm43xx-0.fw");
94 MODULE_FIRMWARE("brcm/bcm43xx_hdr-0.fw");
96 /* recognized BCMA Core IDs */
97 static struct bcma_device_id brcms_coreid_table
[] = {
98 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 17, BCMA_ANY_CLASS
),
99 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 23, BCMA_ANY_CLASS
),
100 BCMA_CORE(BCMA_MANUF_BCM
, BCMA_CORE_80211
, 24, BCMA_ANY_CLASS
),
103 MODULE_DEVICE_TABLE(bcma
, brcms_coreid_table
);
105 #if defined(CONFIG_BRCMDBG)
107 * Module parameter for setting the debug message level. Available
108 * flags are specified by the BRCM_DL_* macros in
109 * drivers/net/wireless/brcm80211/include/defs.h.
111 module_param_named(debug
, brcm_msg_level
, uint
, 0644);
114 static struct ieee80211_channel brcms_2ghz_chantable
[] = {
115 CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS
),
116 CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS
),
117 CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS
),
118 CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS
),
119 CHAN2GHZ(5, 2432, 0),
120 CHAN2GHZ(6, 2437, 0),
121 CHAN2GHZ(7, 2442, 0),
122 CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS
),
123 CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS
),
124 CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS
),
125 CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS
),
127 IEEE80211_CHAN_NO_IR
|
128 IEEE80211_CHAN_NO_HT40PLUS
),
130 IEEE80211_CHAN_NO_IR
|
131 IEEE80211_CHAN_NO_HT40PLUS
),
133 IEEE80211_CHAN_NO_IR
|
134 IEEE80211_CHAN_NO_HT40PLUS
| IEEE80211_CHAN_NO_HT40MINUS
|
135 IEEE80211_CHAN_NO_OFDM
)
138 static struct ieee80211_channel brcms_5ghz_nphy_chantable
[] = {
140 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS
),
141 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS
),
142 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS
),
143 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS
),
146 IEEE80211_CHAN_RADAR
|
147 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40MINUS
),
149 IEEE80211_CHAN_RADAR
|
150 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40PLUS
),
152 IEEE80211_CHAN_RADAR
|
153 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40MINUS
),
155 IEEE80211_CHAN_RADAR
|
156 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40PLUS
),
159 IEEE80211_CHAN_RADAR
|
160 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40MINUS
),
162 IEEE80211_CHAN_RADAR
|
163 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40PLUS
),
165 IEEE80211_CHAN_RADAR
|
166 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40MINUS
),
168 IEEE80211_CHAN_RADAR
|
169 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40PLUS
),
171 IEEE80211_CHAN_RADAR
|
172 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40MINUS
),
174 IEEE80211_CHAN_RADAR
|
175 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40PLUS
),
177 IEEE80211_CHAN_RADAR
|
178 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40MINUS
),
180 IEEE80211_CHAN_RADAR
|
181 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40PLUS
),
183 IEEE80211_CHAN_RADAR
|
184 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40MINUS
),
186 IEEE80211_CHAN_RADAR
|
187 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40PLUS
),
189 IEEE80211_CHAN_RADAR
|
190 IEEE80211_CHAN_NO_IR
| IEEE80211_CHAN_NO_HT40PLUS
|
191 IEEE80211_CHAN_NO_HT40MINUS
),
193 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS
),
194 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS
),
195 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS
),
196 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS
),
197 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS
| IEEE80211_CHAN_NO_HT40MINUS
)
201 * The rate table is used for both 2.4G and 5G rates. The
202 * latter being a subset as it does not support CCK rates.
204 static struct ieee80211_rate legacy_ratetable
[] = {
206 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE
),
207 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE
),
208 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE
),
219 static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template
= {
220 .band
= NL80211_BAND_2GHZ
,
221 .channels
= brcms_2ghz_chantable
,
222 .n_channels
= ARRAY_SIZE(brcms_2ghz_chantable
),
223 .bitrates
= legacy_ratetable
,
224 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
),
226 /* from include/linux/ieee80211.h */
227 .cap
= IEEE80211_HT_CAP_GRN_FLD
|
228 IEEE80211_HT_CAP_SGI_20
| IEEE80211_HT_CAP_SGI_40
,
229 .ht_supported
= true,
230 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
231 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
233 /* placeholders for now */
234 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
235 .rx_highest
= cpu_to_le16(500),
236 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
240 static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template
= {
241 .band
= NL80211_BAND_5GHZ
,
242 .channels
= brcms_5ghz_nphy_chantable
,
243 .n_channels
= ARRAY_SIZE(brcms_5ghz_nphy_chantable
),
244 .bitrates
= legacy_ratetable
+ BRCMS_LEGACY_5G_RATE_OFFSET
,
245 .n_bitrates
= ARRAY_SIZE(legacy_ratetable
) -
246 BRCMS_LEGACY_5G_RATE_OFFSET
,
248 .cap
= IEEE80211_HT_CAP_GRN_FLD
| IEEE80211_HT_CAP_SGI_20
|
249 IEEE80211_HT_CAP_SGI_40
,
250 .ht_supported
= true,
251 .ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
,
252 .ampdu_density
= AMPDU_DEF_MPDU_DENSITY
,
254 /* placeholders for now */
255 .rx_mask
= {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
256 .rx_highest
= cpu_to_le16(500),
257 .tx_params
= IEEE80211_HT_MCS_TX_DEFINED
}
261 /* flags the given rate in rateset as requested */
262 static void brcms_set_basic_rate(struct brcm_rateset
*rs
, u16 rate
, bool is_br
)
266 for (i
= 0; i
< rs
->count
; i
++) {
267 if (rate
!= (rs
->rates
[i
] & 0x7f))
271 rs
->rates
[i
] |= BRCMS_RATE_FLAG
;
273 rs
->rates
[i
] &= BRCMS_RATE_MASK
;
279 * This function frees the WL per-device resources.
281 * This function frees resources owned by the WL device pointed to
282 * by the wl parameter.
284 * precondition: can both be called locked and unlocked
286 static void brcms_free(struct brcms_info
*wl
)
288 struct brcms_timer
*t
, *next
;
290 /* free ucode data */
292 brcms_ucode_data_free(&wl
->ucode
);
294 free_irq(wl
->irq
, wl
);
297 tasklet_kill(&wl
->tasklet
);
300 brcms_debugfs_detach(wl
->pub
);
301 brcms_c_module_unregister(wl
->pub
, "linux", wl
);
304 /* free common resources */
306 brcms_c_detach(wl
->wlc
);
311 /* virtual interface deletion is deferred so we cannot spinwait */
313 /* wait for all pending callbacks to complete */
314 while (atomic_read(&wl
->callbacks
) > 0)
318 for (t
= wl
->timers
; t
; t
= next
) {
328 * called from both kernel as from this kernel module (error flow on attach)
329 * precondition: perimeter lock is not acquired.
331 static void brcms_remove(struct bcma_device
*pdev
)
333 struct ieee80211_hw
*hw
= bcma_get_drvdata(pdev
);
334 struct brcms_info
*wl
= hw
->priv
;
337 brcms_led_unregister(wl
);
338 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, false);
339 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
340 ieee80211_unregister_hw(hw
);
345 bcma_set_drvdata(pdev
, NULL
);
346 ieee80211_free_hw(hw
);
350 * Precondition: Since this function is called in brcms_pci_probe() context,
351 * no locking is required.
353 static void brcms_release_fw(struct brcms_info
*wl
)
356 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
357 release_firmware(wl
->fw
.fw_bin
[i
]);
358 release_firmware(wl
->fw
.fw_hdr
[i
]);
363 * Precondition: Since this function is called in brcms_pci_probe() context,
364 * no locking is required.
366 static int brcms_request_fw(struct brcms_info
*wl
, struct bcma_device
*pdev
)
369 struct device
*device
= &pdev
->dev
;
373 memset(&wl
->fw
, 0, sizeof(struct brcms_firmware
));
374 for (i
= 0; i
< MAX_FW_IMAGES
; i
++) {
375 if (brcms_firmwares
[i
] == NULL
)
377 sprintf(fw_name
, "%s-%d.fw", brcms_firmwares
[i
],
378 UCODE_LOADER_API_VER
);
379 status
= request_firmware(&wl
->fw
.fw_bin
[i
], fw_name
, device
);
381 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
382 KBUILD_MODNAME
, fw_name
);
385 sprintf(fw_name
, "%s_hdr-%d.fw", brcms_firmwares
[i
],
386 UCODE_LOADER_API_VER
);
387 status
= request_firmware(&wl
->fw
.fw_hdr
[i
], fw_name
, device
);
389 wiphy_err(wl
->wiphy
, "%s: fail to load firmware %s\n",
390 KBUILD_MODNAME
, fw_name
);
393 wl
->fw
.hdr_num_entries
[i
] =
394 wl
->fw
.fw_hdr
[i
]->size
/ (sizeof(struct firmware_hdr
));
397 status
= brcms_ucode_data_init(wl
, &wl
->ucode
);
398 brcms_release_fw(wl
);
402 static void brcms_ops_tx(struct ieee80211_hw
*hw
,
403 struct ieee80211_tx_control
*control
,
406 struct brcms_info
*wl
= hw
->priv
;
407 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
409 spin_lock_bh(&wl
->lock
);
411 brcms_err(wl
->wlc
->hw
->d11core
, "ops->tx called while down\n");
415 if (brcms_c_sendpkt_mac80211(wl
->wlc
, skb
, hw
))
416 tx_info
->rate_driver_data
[0] = control
->sta
;
418 spin_unlock_bh(&wl
->lock
);
421 static int brcms_ops_start(struct ieee80211_hw
*hw
)
423 struct brcms_info
*wl
= hw
->priv
;
427 if (!wl
->ucode
.bcm43xx_bomminor
) {
428 err
= brcms_request_fw(wl
, wl
->wlc
->hw
->d11core
);
433 ieee80211_wake_queues(hw
);
434 spin_lock_bh(&wl
->lock
);
435 blocked
= brcms_rfkill_set_hw_state(wl
);
436 spin_unlock_bh(&wl
->lock
);
438 wiphy_rfkill_stop_polling(wl
->pub
->ieee_hw
->wiphy
);
440 spin_lock_bh(&wl
->lock
);
441 /* avoid acknowledging frames before a non-monitor device is added */
451 spin_unlock_bh(&wl
->lock
);
454 brcms_err(wl
->wlc
->hw
->d11core
, "%s: brcms_up() returned %d\n",
457 bcma_core_pci_power_save(wl
->wlc
->hw
->d11core
->bus
, true);
461 static void brcms_ops_stop(struct ieee80211_hw
*hw
)
463 struct brcms_info
*wl
= hw
->priv
;
466 ieee80211_stop_queues(hw
);
471 spin_lock_bh(&wl
->lock
);
472 status
= brcms_c_chipmatch(wl
->wlc
->hw
->d11core
);
473 spin_unlock_bh(&wl
->lock
);
475 brcms_err(wl
->wlc
->hw
->d11core
,
476 "wl: brcms_ops_stop: chipmatch failed\n");
480 bcma_core_pci_power_save(wl
->wlc
->hw
->d11core
->bus
, false);
482 /* put driver in down state */
483 spin_lock_bh(&wl
->lock
);
485 spin_unlock_bh(&wl
->lock
);
489 brcms_ops_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
491 struct brcms_info
*wl
= hw
->priv
;
493 /* Just STA, AP and ADHOC for now */
494 if (vif
->type
!= NL80211_IFTYPE_STATION
&&
495 vif
->type
!= NL80211_IFTYPE_AP
&&
496 vif
->type
!= NL80211_IFTYPE_ADHOC
) {
497 brcms_err(wl
->wlc
->hw
->d11core
,
498 "%s: Attempt to add type %d, only STA, AP and AdHoc for now\n",
499 __func__
, vif
->type
);
503 spin_lock_bh(&wl
->lock
);
506 brcms_c_mute(wl
->wlc
, false);
507 if (vif
->type
== NL80211_IFTYPE_STATION
)
508 brcms_c_start_station(wl
->wlc
, vif
->addr
);
509 else if (vif
->type
== NL80211_IFTYPE_AP
)
510 brcms_c_start_ap(wl
->wlc
, vif
->addr
, vif
->bss_conf
.bssid
,
511 vif
->bss_conf
.ssid
, vif
->bss_conf
.ssid_len
);
512 else if (vif
->type
== NL80211_IFTYPE_ADHOC
)
513 brcms_c_start_adhoc(wl
->wlc
, vif
->addr
);
514 spin_unlock_bh(&wl
->lock
);
520 brcms_ops_remove_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
522 struct brcms_info
*wl
= hw
->priv
;
524 spin_lock_bh(&wl
->lock
);
526 spin_unlock_bh(&wl
->lock
);
529 static int brcms_ops_config(struct ieee80211_hw
*hw
, u32 changed
)
531 struct ieee80211_conf
*conf
= &hw
->conf
;
532 struct brcms_info
*wl
= hw
->priv
;
533 struct bcma_device
*core
= wl
->wlc
->hw
->d11core
;
537 spin_lock_bh(&wl
->lock
);
538 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) {
539 brcms_c_set_beacon_listen_interval(wl
->wlc
,
540 conf
->listen_interval
);
542 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
)
543 brcms_dbg_info(core
, "%s: change monitor mode: %s\n",
544 __func__
, conf
->flags
& IEEE80211_CONF_MONITOR
?
546 if (changed
& IEEE80211_CONF_CHANGE_PS
)
547 brcms_err(core
, "%s: change power-save mode: %s (implement)\n",
548 __func__
, conf
->flags
& IEEE80211_CONF_PS
?
551 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
552 err
= brcms_c_set_tx_power(wl
->wlc
, conf
->power_level
);
554 brcms_err(core
, "%s: Error setting power_level\n",
558 new_int
= brcms_c_get_tx_power(wl
->wlc
);
559 if (new_int
!= conf
->power_level
)
561 "%s: Power level req != actual, %d %d\n",
562 __func__
, conf
->power_level
,
565 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
566 if (conf
->chandef
.width
== NL80211_CHAN_WIDTH_20
||
567 conf
->chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
568 err
= brcms_c_set_channel(wl
->wlc
,
569 conf
->chandef
.chan
->hw_value
);
573 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
)
574 err
= brcms_c_set_rate_limit(wl
->wlc
,
575 conf
->short_frame_max_tx_count
,
576 conf
->long_frame_max_tx_count
);
579 spin_unlock_bh(&wl
->lock
);
584 brcms_ops_bss_info_changed(struct ieee80211_hw
*hw
,
585 struct ieee80211_vif
*vif
,
586 struct ieee80211_bss_conf
*info
, u32 changed
)
588 struct brcms_info
*wl
= hw
->priv
;
589 struct bcma_device
*core
= wl
->wlc
->hw
->d11core
;
591 if (changed
& BSS_CHANGED_ASSOC
) {
592 /* association status changed (associated/disassociated)
593 * also implies a change in the AID.
595 brcms_err(core
, "%s: %s: %sassociated\n", KBUILD_MODNAME
,
596 __func__
, info
->assoc
? "" : "dis");
597 spin_lock_bh(&wl
->lock
);
598 brcms_c_associate_upd(wl
->wlc
, info
->assoc
);
599 spin_unlock_bh(&wl
->lock
);
601 if (changed
& BSS_CHANGED_ERP_SLOT
) {
604 /* slot timing changed */
605 if (info
->use_short_slot
)
609 spin_lock_bh(&wl
->lock
);
610 brcms_c_set_shortslot_override(wl
->wlc
, val
);
611 spin_unlock_bh(&wl
->lock
);
614 if (changed
& BSS_CHANGED_HT
) {
615 /* 802.11n parameters changed */
616 u16 mode
= info
->ht_operation_mode
;
618 spin_lock_bh(&wl
->lock
);
619 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_CFG
,
620 mode
& IEEE80211_HT_OP_MODE_PROTECTION
);
621 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_NONGF
,
622 mode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
623 brcms_c_protection_upd(wl
->wlc
, BRCMS_PROT_N_OBSS
,
624 mode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
);
625 spin_unlock_bh(&wl
->lock
);
627 if (changed
& BSS_CHANGED_BASIC_RATES
) {
628 struct ieee80211_supported_band
*bi
;
631 struct brcm_rateset rs
;
634 /* retrieve the current rates */
635 spin_lock_bh(&wl
->lock
);
636 brcms_c_get_current_rateset(wl
->wlc
, &rs
);
637 spin_unlock_bh(&wl
->lock
);
639 br_mask
= info
->basic_rates
;
640 bi
= hw
->wiphy
->bands
[brcms_c_get_curband(wl
->wlc
)];
641 for (i
= 0; i
< bi
->n_bitrates
; i
++) {
642 /* convert to internal rate value */
643 rate
= (bi
->bitrates
[i
].bitrate
<< 1) / 10;
645 /* set/clear basic rate flag */
646 brcms_set_basic_rate(&rs
, rate
, br_mask
& 1);
650 /* update the rate set */
651 spin_lock_bh(&wl
->lock
);
652 error
= brcms_c_set_rateset(wl
->wlc
, &rs
);
653 spin_unlock_bh(&wl
->lock
);
655 brcms_err(core
, "changing basic rates failed: %d\n",
658 if (changed
& BSS_CHANGED_BEACON_INT
) {
659 /* Beacon interval changed */
660 spin_lock_bh(&wl
->lock
);
661 brcms_c_set_beacon_period(wl
->wlc
, info
->beacon_int
);
662 spin_unlock_bh(&wl
->lock
);
664 if (changed
& BSS_CHANGED_BSSID
) {
665 /* BSSID changed, for whatever reason (IBSS and managed mode) */
666 spin_lock_bh(&wl
->lock
);
667 brcms_c_set_addrmatch(wl
->wlc
, RCM_BSSID_OFFSET
, info
->bssid
);
668 spin_unlock_bh(&wl
->lock
);
670 if (changed
& BSS_CHANGED_SSID
) {
671 /* BSSID changed, for whatever reason (IBSS and managed mode) */
672 spin_lock_bh(&wl
->lock
);
673 brcms_c_set_ssid(wl
->wlc
, info
->ssid
, info
->ssid_len
);
674 spin_unlock_bh(&wl
->lock
);
676 if (changed
& BSS_CHANGED_BEACON
) {
677 /* Beacon data changed, retrieve new beacon (beaconing modes) */
678 struct sk_buff
*beacon
;
681 spin_lock_bh(&wl
->lock
);
682 beacon
= ieee80211_beacon_get_tim(hw
, vif
, &tim_offset
, NULL
);
683 brcms_c_set_new_beacon(wl
->wlc
, beacon
, tim_offset
,
685 spin_unlock_bh(&wl
->lock
);
688 if (changed
& BSS_CHANGED_AP_PROBE_RESP
) {
689 struct sk_buff
*probe_resp
;
691 spin_lock_bh(&wl
->lock
);
692 probe_resp
= ieee80211_proberesp_get(hw
, vif
);
693 brcms_c_set_new_probe_resp(wl
->wlc
, probe_resp
);
694 spin_unlock_bh(&wl
->lock
);
697 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
698 /* Beaconing should be enabled/disabled (beaconing modes) */
699 brcms_err(core
, "%s: Beacon enabled: %s\n", __func__
,
700 info
->enable_beacon
? "true" : "false");
701 if (info
->enable_beacon
&&
702 hw
->wiphy
->flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) {
703 brcms_c_enable_probe_resp(wl
->wlc
, true);
705 brcms_c_enable_probe_resp(wl
->wlc
, false);
709 if (changed
& BSS_CHANGED_CQM
) {
710 /* Connection quality monitor config changed */
711 brcms_err(core
, "%s: cqm change: threshold %d, hys %d "
712 " (implement)\n", __func__
, info
->cqm_rssi_thold
,
713 info
->cqm_rssi_hyst
);
716 if (changed
& BSS_CHANGED_IBSS
) {
717 /* IBSS join status changed */
718 brcms_err(core
, "%s: IBSS joined: %s (implement)\n",
719 __func__
, info
->ibss_joined
? "true" : "false");
722 if (changed
& BSS_CHANGED_ARP_FILTER
) {
723 /* Hardware ARP filter address list or state changed */
724 brcms_err(core
, "%s: arp filtering: %d addresses"
725 " (implement)\n", __func__
, info
->arp_addr_cnt
);
728 if (changed
& BSS_CHANGED_QOS
) {
730 * QoS for this association was enabled/disabled.
731 * Note that it is only ever disabled for station mode.
733 brcms_err(core
, "%s: qos enabled: %s (implement)\n",
734 __func__
, info
->qos
? "true" : "false");
740 brcms_ops_configure_filter(struct ieee80211_hw
*hw
,
741 unsigned int changed_flags
,
742 unsigned int *total_flags
, u64 multicast
)
744 struct brcms_info
*wl
= hw
->priv
;
745 struct bcma_device
*core
= wl
->wlc
->hw
->d11core
;
747 changed_flags
&= MAC_FILTERS
;
748 *total_flags
&= MAC_FILTERS
;
750 if (changed_flags
& FIF_ALLMULTI
)
751 brcms_dbg_info(core
, "FIF_ALLMULTI\n");
752 if (changed_flags
& FIF_FCSFAIL
)
753 brcms_dbg_info(core
, "FIF_FCSFAIL\n");
754 if (changed_flags
& FIF_CONTROL
)
755 brcms_dbg_info(core
, "FIF_CONTROL\n");
756 if (changed_flags
& FIF_OTHER_BSS
)
757 brcms_dbg_info(core
, "FIF_OTHER_BSS\n");
758 if (changed_flags
& FIF_PSPOLL
)
759 brcms_dbg_info(core
, "FIF_PSPOLL\n");
760 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
)
761 brcms_dbg_info(core
, "FIF_BCN_PRBRESP_PROMISC\n");
763 spin_lock_bh(&wl
->lock
);
764 brcms_c_mac_promisc(wl
->wlc
, *total_flags
);
765 spin_unlock_bh(&wl
->lock
);
769 static void brcms_ops_sw_scan_start(struct ieee80211_hw
*hw
,
770 struct ieee80211_vif
*vif
,
773 struct brcms_info
*wl
= hw
->priv
;
774 spin_lock_bh(&wl
->lock
);
775 brcms_c_scan_start(wl
->wlc
);
776 spin_unlock_bh(&wl
->lock
);
780 static void brcms_ops_sw_scan_complete(struct ieee80211_hw
*hw
,
781 struct ieee80211_vif
*vif
)
783 struct brcms_info
*wl
= hw
->priv
;
784 spin_lock_bh(&wl
->lock
);
785 brcms_c_scan_stop(wl
->wlc
);
786 spin_unlock_bh(&wl
->lock
);
791 brcms_ops_conf_tx(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
, u16 queue
,
792 const struct ieee80211_tx_queue_params
*params
)
794 struct brcms_info
*wl
= hw
->priv
;
796 spin_lock_bh(&wl
->lock
);
797 brcms_c_wme_setparams(wl
->wlc
, queue
, params
, true);
798 spin_unlock_bh(&wl
->lock
);
804 brcms_ops_sta_add(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
805 struct ieee80211_sta
*sta
)
807 struct brcms_info
*wl
= hw
->priv
;
808 struct scb
*scb
= &wl
->wlc
->pri_scb
;
810 brcms_c_init_scb(scb
);
812 wl
->pub
->global_ampdu
= &(scb
->scb_ampdu
);
813 wl
->pub
->global_ampdu
->scb
= scb
;
814 wl
->pub
->global_ampdu
->max_pdu
= 16;
817 * minstrel_ht initiates addBA on our behalf by calling
818 * ieee80211_start_tx_ba_session()
824 brcms_ops_ampdu_action(struct ieee80211_hw
*hw
,
825 struct ieee80211_vif
*vif
,
826 struct ieee80211_ampdu_params
*params
)
828 struct brcms_info
*wl
= hw
->priv
;
829 struct scb
*scb
= &wl
->wlc
->pri_scb
;
831 struct ieee80211_sta
*sta
= params
->sta
;
832 enum ieee80211_ampdu_mlme_action action
= params
->action
;
833 u16 tid
= params
->tid
;
834 u8 buf_size
= params
->buf_size
;
836 if (WARN_ON(scb
->magic
!= SCB_MAGIC
))
839 case IEEE80211_AMPDU_RX_START
:
841 case IEEE80211_AMPDU_RX_STOP
:
843 case IEEE80211_AMPDU_TX_START
:
844 spin_lock_bh(&wl
->lock
);
845 status
= brcms_c_aggregatable(wl
->wlc
, tid
);
846 spin_unlock_bh(&wl
->lock
);
848 brcms_dbg_ht(wl
->wlc
->hw
->d11core
,
849 "START: tid %d is not agg\'able\n", tid
);
852 return IEEE80211_AMPDU_TX_START_IMMEDIATE
;
854 case IEEE80211_AMPDU_TX_STOP_CONT
:
855 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
856 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
857 spin_lock_bh(&wl
->lock
);
858 brcms_c_ampdu_flush(wl
->wlc
, sta
, tid
);
859 spin_unlock_bh(&wl
->lock
);
860 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
862 case IEEE80211_AMPDU_TX_OPERATIONAL
:
864 * BA window size from ADDBA response ('buf_size') defines how
865 * many outstanding MPDUs are allowed for the BA stream by
866 * recipient and traffic class. 'ampdu_factor' gives maximum
869 spin_lock_bh(&wl
->lock
);
870 brcms_c_ampdu_tx_operational(wl
->wlc
, tid
, buf_size
,
871 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
872 sta
->ht_cap
.ampdu_factor
)) - 1);
873 spin_unlock_bh(&wl
->lock
);
874 /* Power save wakeup */
877 brcms_err(wl
->wlc
->hw
->d11core
,
878 "%s: Invalid command, ignoring\n", __func__
);
884 static void brcms_ops_rfkill_poll(struct ieee80211_hw
*hw
)
886 struct brcms_info
*wl
= hw
->priv
;
889 spin_lock_bh(&wl
->lock
);
890 blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
891 spin_unlock_bh(&wl
->lock
);
893 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
896 static bool brcms_tx_flush_completed(struct brcms_info
*wl
)
900 spin_lock_bh(&wl
->lock
);
901 result
= brcms_c_tx_flush_completed(wl
->wlc
);
902 spin_unlock_bh(&wl
->lock
);
906 static void brcms_ops_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
907 u32 queues
, bool drop
)
909 struct brcms_info
*wl
= hw
->priv
;
912 no_printk("%s: drop = %s\n", __func__
, drop
? "true" : "false");
914 ret
= wait_event_timeout(wl
->tx_flush_wq
,
915 brcms_tx_flush_completed(wl
),
916 msecs_to_jiffies(BRCMS_FLUSH_TIMEOUT
));
918 brcms_dbg_mac80211(wl
->wlc
->hw
->d11core
,
919 "ret=%d\n", jiffies_to_msecs(ret
));
922 static u64
brcms_ops_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
924 struct brcms_info
*wl
= hw
->priv
;
927 spin_lock_bh(&wl
->lock
);
928 tsf
= brcms_c_tsf_get(wl
->wlc
);
929 spin_unlock_bh(&wl
->lock
);
934 static void brcms_ops_set_tsf(struct ieee80211_hw
*hw
,
935 struct ieee80211_vif
*vif
, u64 tsf
)
937 struct brcms_info
*wl
= hw
->priv
;
939 spin_lock_bh(&wl
->lock
);
940 brcms_c_tsf_set(wl
->wlc
, tsf
);
941 spin_unlock_bh(&wl
->lock
);
944 static int brcms_ops_beacon_set_tim(struct ieee80211_hw
*hw
,
945 struct ieee80211_sta
*sta
, bool set
)
947 struct brcms_info
*wl
= hw
->priv
;
948 struct sk_buff
*beacon
= NULL
;
951 spin_lock_bh(&wl
->lock
);
953 beacon
= ieee80211_beacon_get_tim(hw
, wl
->wlc
->vif
,
956 brcms_c_set_new_beacon(wl
->wlc
, beacon
, tim_offset
,
957 wl
->wlc
->vif
->bss_conf
.dtim_period
);
958 spin_unlock_bh(&wl
->lock
);
963 static const struct ieee80211_ops brcms_ops
= {
965 .start
= brcms_ops_start
,
966 .stop
= brcms_ops_stop
,
967 .add_interface
= brcms_ops_add_interface
,
968 .remove_interface
= brcms_ops_remove_interface
,
969 .config
= brcms_ops_config
,
970 .bss_info_changed
= brcms_ops_bss_info_changed
,
971 .configure_filter
= brcms_ops_configure_filter
,
972 .sw_scan_start
= brcms_ops_sw_scan_start
,
973 .sw_scan_complete
= brcms_ops_sw_scan_complete
,
974 .conf_tx
= brcms_ops_conf_tx
,
975 .sta_add
= brcms_ops_sta_add
,
976 .ampdu_action
= brcms_ops_ampdu_action
,
977 .rfkill_poll
= brcms_ops_rfkill_poll
,
978 .flush
= brcms_ops_flush
,
979 .get_tsf
= brcms_ops_get_tsf
,
980 .set_tsf
= brcms_ops_set_tsf
,
981 .set_tim
= brcms_ops_beacon_set_tim
,
984 void brcms_dpc(struct tasklet_struct
*t
)
986 struct brcms_info
*wl
;
988 wl
= from_tasklet(wl
, t
, tasklet
);
990 spin_lock_bh(&wl
->lock
);
992 /* call the common second level interrupt handler */
997 spin_lock_irqsave(&wl
->isr_lock
, flags
);
998 brcms_c_intrsupd(wl
->wlc
);
999 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1002 wl
->resched
= brcms_c_dpc(wl
->wlc
, true);
1005 /* brcms_c_dpc() may bring the driver down */
1009 /* re-schedule dpc */
1011 tasklet_schedule(&wl
->tasklet
);
1013 /* re-enable interrupts */
1017 spin_unlock_bh(&wl
->lock
);
1018 wake_up(&wl
->tx_flush_wq
);
1021 static irqreturn_t
brcms_isr(int irq
, void *dev_id
)
1023 struct brcms_info
*wl
;
1024 irqreturn_t ret
= IRQ_NONE
;
1026 wl
= (struct brcms_info
*) dev_id
;
1028 spin_lock(&wl
->isr_lock
);
1030 /* call common first level interrupt handler */
1031 if (brcms_c_isr(wl
->wlc
)) {
1032 /* schedule second level handler */
1033 tasklet_schedule(&wl
->tasklet
);
1037 spin_unlock(&wl
->isr_lock
);
1043 * is called in brcms_pci_probe() context, therefore no locking required.
1045 static int ieee_hw_rate_init(struct ieee80211_hw
*hw
)
1047 struct brcms_info
*wl
= hw
->priv
;
1048 struct brcms_c_info
*wlc
= wl
->wlc
;
1049 struct ieee80211_supported_band
*band
;
1053 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = NULL
;
1054 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = NULL
;
1056 phy_type
= brcms_c_get_phy_type(wl
->wlc
, 0);
1057 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
1058 band
= &wlc
->bandstate
[BAND_2G_INDEX
]->band
;
1059 *band
= brcms_band_2GHz_nphy_template
;
1060 if (phy_type
== PHY_TYPE_LCN
) {
1062 band
->ht_cap
.mcs
.rx_mask
[1] = 0;
1063 band
->ht_cap
.mcs
.rx_highest
= cpu_to_le16(72);
1065 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = band
;
1070 /* Assume all bands use the same phy. True for 11n devices. */
1071 if (wl
->pub
->_nbands
> 1) {
1073 if (phy_type
== PHY_TYPE_N
|| phy_type
== PHY_TYPE_LCN
) {
1074 band
= &wlc
->bandstate
[BAND_5G_INDEX
]->band
;
1075 *band
= brcms_band_5GHz_nphy_template
;
1076 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] = band
;
1085 * is called in brcms_pci_probe() context, therefore no locking required.
1087 static int ieee_hw_init(struct ieee80211_hw
*hw
)
1089 ieee80211_hw_set(hw
, AMPDU_AGGREGATION
);
1090 ieee80211_hw_set(hw
, SIGNAL_DBM
);
1091 ieee80211_hw_set(hw
, REPORTS_TX_ACK_STATUS
);
1093 hw
->extra_tx_headroom
= brcms_c_get_header_len();
1094 hw
->queues
= N_TX_QUEUES
;
1095 hw
->max_rates
= 2; /* Primary rate and 1 fallback rate */
1097 /* channel change time is dependent on chip and band */
1098 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
1099 BIT(NL80211_IFTYPE_AP
) |
1100 BIT(NL80211_IFTYPE_ADHOC
);
1103 * deactivate sending probe responses by ucude, because this will
1104 * cause problems when WPS is used.
1106 * hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
1109 wiphy_ext_feature_set(hw
->wiphy
, NL80211_EXT_FEATURE_CQM_RSSI_LIST
);
1111 hw
->rate_control_algorithm
= "minstrel_ht";
1113 hw
->sta_data_size
= 0;
1114 return ieee_hw_rate_init(hw
);
1118 * attach to the WL device.
1120 * Attach to the WL device identified by vendor and device parameters.
1121 * regs is a host accessible memory address pointing to WL device registers.
1123 * is called in brcms_bcma_probe() context, therefore no locking required.
1125 static struct brcms_info
*brcms_attach(struct bcma_device
*pdev
)
1127 struct brcms_info
*wl
= NULL
;
1129 struct ieee80211_hw
*hw
;
1132 unit
= n_adapters_found
;
1138 /* allocate private info */
1139 hw
= bcma_get_drvdata(pdev
);
1142 if (WARN_ON(hw
== NULL
) || WARN_ON(wl
== NULL
))
1144 wl
->wiphy
= hw
->wiphy
;
1146 atomic_set(&wl
->callbacks
, 0);
1148 init_waitqueue_head(&wl
->tx_flush_wq
);
1150 /* setup the bottom half handler */
1151 tasklet_setup(&wl
->tasklet
, brcms_dpc
);
1153 spin_lock_init(&wl
->lock
);
1154 spin_lock_init(&wl
->isr_lock
);
1156 /* common load-time initialization */
1157 wl
->wlc
= brcms_c_attach((void *)wl
, pdev
, unit
, false, &err
);
1159 wiphy_err(wl
->wiphy
, "%s: attach() failed with code %d\n",
1160 KBUILD_MODNAME
, err
);
1163 wl
->pub
= brcms_c_pub(wl
->wlc
);
1165 wl
->pub
->ieee_hw
= hw
;
1167 /* register our interrupt handler */
1168 if (request_irq(pdev
->irq
, brcms_isr
,
1169 IRQF_SHARED
, KBUILD_MODNAME
, wl
)) {
1170 wiphy_err(wl
->wiphy
, "wl%d: request_irq() failed\n", unit
);
1173 wl
->irq
= pdev
->irq
;
1175 /* register module */
1176 brcms_c_module_register(wl
->pub
, "linux", wl
, NULL
);
1178 if (ieee_hw_init(hw
)) {
1179 wiphy_err(wl
->wiphy
, "wl%d: %s: ieee_hw_init failed!\n", unit
,
1184 brcms_c_regd_init(wl
->wlc
);
1186 memcpy(perm
, &wl
->pub
->cur_etheraddr
, ETH_ALEN
);
1187 if (WARN_ON(!is_valid_ether_addr(perm
)))
1189 SET_IEEE80211_PERM_ADDR(hw
, perm
);
1191 err
= ieee80211_register_hw(hw
);
1193 wiphy_err(wl
->wiphy
, "%s: ieee80211_register_hw failed, status"
1194 "%d\n", __func__
, err
);
1196 if (wl
->pub
->srom_ccode
[0] &&
1197 regulatory_hint(wl
->wiphy
, wl
->pub
->srom_ccode
))
1198 wiphy_err(wl
->wiphy
, "%s: regulatory hint failed\n", __func__
);
1200 brcms_debugfs_attach(wl
->pub
);
1201 brcms_debugfs_create_files(wl
->pub
);
1213 * determines if a device is a WL device, and if so, attaches it.
1215 * This function determines if a device pointed to by pdev is a WL device,
1216 * and if so, performs a brcms_attach() on it.
1218 * Perimeter lock is initialized in the course of this function.
1220 static int brcms_bcma_probe(struct bcma_device
*pdev
)
1222 struct brcms_info
*wl
;
1223 struct ieee80211_hw
*hw
;
1225 dev_info(&pdev
->dev
, "mfg %x core %x rev %d class %d irq %d\n",
1226 pdev
->id
.manuf
, pdev
->id
.id
, pdev
->id
.rev
, pdev
->id
.class,
1229 if ((pdev
->id
.manuf
!= BCMA_MANUF_BCM
) ||
1230 (pdev
->id
.id
!= BCMA_CORE_80211
))
1233 hw
= ieee80211_alloc_hw(sizeof(struct brcms_info
), &brcms_ops
);
1235 pr_err("%s: ieee80211_alloc_hw failed\n", __func__
);
1239 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
1241 bcma_set_drvdata(pdev
, hw
);
1243 memset(hw
->priv
, 0, sizeof(*wl
));
1245 wl
= brcms_attach(pdev
);
1247 pr_err("%s: brcms_attach failed!\n", __func__
);
1250 brcms_led_register(wl
);
1255 static int brcms_suspend(struct bcma_device
*pdev
)
1257 struct brcms_info
*wl
;
1258 struct ieee80211_hw
*hw
;
1260 hw
= bcma_get_drvdata(pdev
);
1263 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME
,
1268 /* only need to flag hw is down for proper resume */
1269 spin_lock_bh(&wl
->lock
);
1270 wl
->pub
->hw_up
= false;
1271 spin_unlock_bh(&wl
->lock
);
1273 brcms_dbg_info(wl
->wlc
->hw
->d11core
, "brcms_suspend ok\n");
1278 static int brcms_resume(struct bcma_device
*pdev
)
1283 static struct bcma_driver brcms_bcma_driver
= {
1284 .name
= KBUILD_MODNAME
,
1285 .probe
= brcms_bcma_probe
,
1286 .suspend
= brcms_suspend
,
1287 .resume
= brcms_resume
,
1288 .remove
= brcms_remove
,
1289 .id_table
= brcms_coreid_table
,
1293 * This is the main entry point for the brcmsmac driver.
1295 * This function is scheduled upon module initialization and
1296 * does the driver registration, which result in brcms_bcma_probe()
1297 * call resulting in the driver bringup.
1299 static void brcms_driver_init(struct work_struct
*work
)
1303 error
= bcma_driver_register(&brcms_bcma_driver
);
1305 pr_err("%s: register returned %d\n", __func__
, error
);
1308 static DECLARE_WORK(brcms_driver_work
, brcms_driver_init
);
1310 static int __init
brcms_module_init(void)
1312 brcms_debugfs_init();
1313 if (!schedule_work(&brcms_driver_work
))
1320 * This function unloads the brcmsmac driver from the system.
1322 * This function unconditionally unloads the brcmsmac driver module from the
1326 static void __exit
brcms_module_exit(void)
1328 cancel_work_sync(&brcms_driver_work
);
1329 bcma_driver_unregister(&brcms_bcma_driver
);
1330 brcms_debugfs_exit();
1333 module_init(brcms_module_init
);
1334 module_exit(brcms_module_exit
);
1337 * precondition: perimeter lock has been acquired
1339 void brcms_txflowcontrol(struct brcms_info
*wl
, struct brcms_if
*wlif
,
1340 bool state
, int prio
)
1342 brcms_err(wl
->wlc
->hw
->d11core
, "Shouldn't be here %s\n", __func__
);
1346 * precondition: perimeter lock has been acquired
1348 void brcms_init(struct brcms_info
*wl
)
1350 brcms_dbg_info(wl
->wlc
->hw
->d11core
, "Initializing wl%d\n",
1353 brcms_c_init(wl
->wlc
, wl
->mute_tx
);
1357 * precondition: perimeter lock has been acquired
1359 uint
brcms_reset(struct brcms_info
*wl
)
1361 brcms_dbg_info(wl
->wlc
->hw
->d11core
, "Resetting wl%d\n", wl
->pub
->unit
);
1362 brcms_c_reset(wl
->wlc
);
1364 /* dpc will not be rescheduled */
1365 wl
->resched
= false;
1367 /* inform publicly that interface is down */
1368 wl
->pub
->up
= false;
1373 void brcms_fatal_error(struct brcms_info
*wl
)
1375 brcms_err(wl
->wlc
->hw
->d11core
, "wl%d: fatal error, reinitializing\n",
1376 wl
->wlc
->pub
->unit
);
1378 ieee80211_restart_hw(wl
->pub
->ieee_hw
);
1382 * These are interrupt on/off entry points. Disable interrupts
1383 * during interrupt state transition.
1385 void brcms_intrson(struct brcms_info
*wl
)
1387 unsigned long flags
;
1389 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1390 brcms_c_intrson(wl
->wlc
);
1391 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1394 u32
brcms_intrsoff(struct brcms_info
*wl
)
1396 unsigned long flags
;
1399 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1400 status
= brcms_c_intrsoff(wl
->wlc
);
1401 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1405 void brcms_intrsrestore(struct brcms_info
*wl
, u32 macintmask
)
1407 unsigned long flags
;
1409 spin_lock_irqsave(&wl
->isr_lock
, flags
);
1410 brcms_c_intrsrestore(wl
->wlc
, macintmask
);
1411 spin_unlock_irqrestore(&wl
->isr_lock
, flags
);
1415 * precondition: perimeter lock has been acquired
1417 int brcms_up(struct brcms_info
*wl
)
1424 error
= brcms_c_up(wl
->wlc
);
1430 * precondition: perimeter lock has been acquired
1432 void brcms_down(struct brcms_info
*wl
)
1433 __must_hold(&wl
->lock
)
1435 uint callbacks
, ret_val
= 0;
1437 /* call common down function */
1438 ret_val
= brcms_c_down(wl
->wlc
);
1439 callbacks
= atomic_read(&wl
->callbacks
) - ret_val
;
1441 /* wait for down callbacks to complete */
1442 spin_unlock_bh(&wl
->lock
);
1444 /* For HIGH_only driver, it's important to actually schedule other work,
1445 * not just spin wait since everything runs at schedule level
1447 SPINWAIT((atomic_read(&wl
->callbacks
) > callbacks
), 100 * 1000);
1449 spin_lock_bh(&wl
->lock
);
1453 * precondition: perimeter lock is not acquired
1455 static void _brcms_timer(struct work_struct
*work
)
1457 struct brcms_timer
*t
= container_of(work
, struct brcms_timer
,
1460 spin_lock_bh(&t
->wl
->lock
);
1464 atomic_inc(&t
->wl
->callbacks
);
1465 ieee80211_queue_delayed_work(t
->wl
->pub
->ieee_hw
,
1467 msecs_to_jiffies(t
->ms
));
1475 atomic_dec(&t
->wl
->callbacks
);
1477 spin_unlock_bh(&t
->wl
->lock
);
1481 * Adds a timer to the list. Caller supplies a timer function.
1482 * Is called from wlc.
1484 * precondition: perimeter lock has been acquired
1486 struct brcms_timer
*brcms_init_timer(struct brcms_info
*wl
,
1487 void (*fn
) (void *arg
),
1488 void *arg
, const char *name
)
1490 struct brcms_timer
*t
;
1492 t
= kzalloc(sizeof(struct brcms_timer
), GFP_ATOMIC
);
1496 INIT_DELAYED_WORK(&t
->dly_wrk
, _brcms_timer
);
1500 t
->next
= wl
->timers
;
1504 t
->name
= kstrdup(name
, GFP_ATOMIC
);
1511 * adds only the kernel timer since it's going to be more accurate
1512 * as well as it's easier to make it periodic
1514 * precondition: perimeter lock has been acquired
1516 void brcms_add_timer(struct brcms_timer
*t
, uint ms
, int periodic
)
1518 struct ieee80211_hw
*hw
= t
->wl
->pub
->ieee_hw
;
1522 brcms_dbg_info(t
->wl
->wlc
->hw
->d11core
,
1523 "%s: Already set. Name: %s, per %d\n",
1524 __func__
, t
->name
, periodic
);
1527 t
->periodic
= (bool) periodic
;
1530 atomic_inc(&t
->wl
->callbacks
);
1533 ieee80211_queue_delayed_work(hw
, &t
->dly_wrk
, msecs_to_jiffies(ms
));
1537 * return true if timer successfully deleted, false if still pending
1539 * precondition: perimeter lock has been acquired
1541 bool brcms_del_timer(struct brcms_timer
*t
)
1545 if (!cancel_delayed_work(&t
->dly_wrk
))
1548 atomic_dec(&t
->wl
->callbacks
);
1555 * precondition: perimeter lock has been acquired
1557 void brcms_free_timer(struct brcms_timer
*t
)
1559 struct brcms_info
*wl
= t
->wl
;
1560 struct brcms_timer
*tmp
;
1562 /* delete the timer in case it is active */
1565 if (wl
->timers
== t
) {
1566 wl
->timers
= wl
->timers
->next
;
1577 if (tmp
->next
== t
) {
1578 tmp
->next
= t
->next
;
1591 * precondition: no locking required
1593 int brcms_ucode_init_buf(struct brcms_info
*wl
, void **pbuf
, u32 idx
)
1597 struct firmware_hdr
*hdr
;
1598 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1599 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1600 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1602 u32 len
= le32_to_cpu(hdr
->len
);
1603 if (le32_to_cpu(hdr
->idx
) == idx
) {
1604 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1605 le32_to_cpu(hdr
->offset
);
1606 *pbuf
= kvmalloc(len
, GFP_KERNEL
);
1609 memcpy(*pbuf
, pdata
, len
);
1614 brcms_err(wl
->wlc
->hw
->d11core
,
1615 "ERROR: ucode buf tag:%d can not be found!\n", idx
);
1622 * Precondition: Since this function is called in brcms_bcma_probe() context,
1623 * no locking is required.
1625 int brcms_ucode_init_uint(struct brcms_info
*wl
, size_t *n_bytes
, u32 idx
)
1629 struct firmware_hdr
*hdr
;
1630 for (i
= 0; i
< wl
->fw
.fw_cnt
; i
++) {
1631 hdr
= (struct firmware_hdr
*)wl
->fw
.fw_hdr
[i
]->data
;
1632 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
];
1634 if (le32_to_cpu(hdr
->idx
) == idx
) {
1635 pdata
= wl
->fw
.fw_bin
[i
]->data
+
1636 le32_to_cpu(hdr
->offset
);
1637 if (le32_to_cpu(hdr
->len
) != 4) {
1638 brcms_err(wl
->wlc
->hw
->d11core
,
1639 "ERROR: fw hdr len\n");
1642 *n_bytes
= le32_to_cpu(*((__le32
*) pdata
));
1647 brcms_err(wl
->wlc
->hw
->d11core
,
1648 "ERROR: ucode tag:%d can not be found!\n", idx
);
1653 * precondition: can both be called locked and unlocked
1655 void brcms_ucode_free_buf(void *p
)
1661 * checks validity of all firmware images loaded from user space
1663 * Precondition: Since this function is called in brcms_bcma_probe() context,
1664 * no locking is required.
1666 int brcms_check_firmwares(struct brcms_info
*wl
)
1671 const struct firmware
*fw
;
1672 const struct firmware
*fw_hdr
;
1673 struct firmware_hdr
*ucode_hdr
;
1674 for (i
= 0; i
< MAX_FW_IMAGES
&& rc
== 0; i
++) {
1675 fw
= wl
->fw
.fw_bin
[i
];
1676 fw_hdr
= wl
->fw
.fw_hdr
[i
];
1677 if (fw
== NULL
&& fw_hdr
== NULL
) {
1679 } else if (fw
== NULL
|| fw_hdr
== NULL
) {
1680 wiphy_err(wl
->wiphy
, "%s: invalid bin/hdr fw\n",
1683 } else if (fw_hdr
->size
% sizeof(struct firmware_hdr
)) {
1684 wiphy_err(wl
->wiphy
, "%s: non integral fw hdr file "
1685 "size %zu/%zu\n", __func__
, fw_hdr
->size
,
1686 sizeof(struct firmware_hdr
));
1688 } else if (fw
->size
< MIN_FW_SIZE
|| fw
->size
> MAX_FW_SIZE
) {
1689 wiphy_err(wl
->wiphy
, "%s: out of bounds fw file size %zu\n",
1690 __func__
, fw
->size
);
1693 /* check if ucode section overruns firmware image */
1694 ucode_hdr
= (struct firmware_hdr
*)fw_hdr
->data
;
1695 for (entry
= 0; entry
< wl
->fw
.hdr_num_entries
[i
] &&
1696 !rc
; entry
++, ucode_hdr
++) {
1697 if (le32_to_cpu(ucode_hdr
->offset
) +
1698 le32_to_cpu(ucode_hdr
->len
) >
1700 wiphy_err(wl
->wiphy
,
1701 "%s: conflicting bin/hdr\n",
1708 if (rc
== 0 && wl
->fw
.fw_cnt
!= i
) {
1709 wiphy_err(wl
->wiphy
, "%s: invalid fw_cnt=%d\n", __func__
,
1717 * precondition: perimeter lock has been acquired
1719 bool brcms_rfkill_set_hw_state(struct brcms_info
*wl
)
1720 __must_hold(&wl
->lock
)
1722 bool blocked
= brcms_c_check_radio_disabled(wl
->wlc
);
1724 spin_unlock_bh(&wl
->lock
);
1725 wiphy_rfkill_set_hw_state(wl
->pub
->ieee_hw
->wiphy
, blocked
);
1727 wiphy_rfkill_start_polling(wl
->pub
->ieee_hw
->wiphy
);
1728 spin_lock_bh(&wl
->lock
);