blob: a5edebeb0b4f7f748155551df76396602885078e [file] [log] [blame]
Arend van Spriel5b435de2011-10-05 13:19:03 +02001/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
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.
7 *
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.
15 */
16
17#define __UNDEF_NO_VERSION__
Joe Perches02f77192012-01-15 00:38:44 -080018#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Arend van Spriel5b435de2011-10-05 13:19:03 +020019
20#include <linux/etherdevice.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020021#include <linux/sched.h>
22#include <linux/firmware.h>
23#include <linux/interrupt.h>
Paul Gortmaker45296232011-08-30 17:50:46 -040024#include <linux/module.h>
Arend van Spriel2e7565602011-12-08 15:06:46 -080025#include <linux/bcma/bcma.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020026#include <net/mac80211.h>
27#include <defs.h>
Arend van Spriel5b435de2011-10-05 13:19:03 +020028#include "phy/phy_int.h"
29#include "d11.h"
30#include "channel.h"
31#include "scb.h"
32#include "pub.h"
33#include "ucode_loader.h"
34#include "mac80211_if.h"
35#include "main.h"
36
37#define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
38
39/* Flags we support */
40#define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
41 FIF_ALLMULTI | \
42 FIF_FCSFAIL | \
Arend van Spriel5b435de2011-10-05 13:19:03 +020043 FIF_CONTROL | \
44 FIF_OTHER_BSS | \
Alwin Beukersbe667662011-11-22 17:21:43 -080045 FIF_BCN_PRBRESP_PROMISC | \
46 FIF_PSPOLL)
Arend van Spriel5b435de2011-10-05 13:19:03 +020047
48#define CHAN2GHZ(channel, freqency, chflags) { \
49 .band = IEEE80211_BAND_2GHZ, \
50 .center_freq = (freqency), \
51 .hw_value = (channel), \
52 .flags = chflags, \
53 .max_antenna_gain = 0, \
54 .max_power = 19, \
55}
56
57#define CHAN5GHZ(channel, chflags) { \
58 .band = IEEE80211_BAND_5GHZ, \
59 .center_freq = 5000 + 5*(channel), \
60 .hw_value = (channel), \
61 .flags = chflags, \
62 .max_antenna_gain = 0, \
63 .max_power = 21, \
64}
65
66#define RATE(rate100m, _flags) { \
67 .bitrate = (rate100m), \
68 .flags = (_flags), \
69 .hw_value = (rate100m / 5), \
70}
71
72struct firmware_hdr {
73 __le32 offset;
74 __le32 len;
75 __le32 idx;
76};
77
78static const char * const brcms_firmwares[MAX_FW_IMAGES] = {
79 "brcm/bcm43xx",
80 NULL
81};
82
83static int n_adapters_found;
84
85MODULE_AUTHOR("Broadcom Corporation");
86MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
87MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
88MODULE_LICENSE("Dual BSD/GPL");
89
Arend van Spriel5b435de2011-10-05 13:19:03 +020090
Arend van Spriel2e7565602011-12-08 15:06:46 -080091/* recognized BCMA Core IDs */
92static struct bcma_device_id brcms_coreid_table[] = {
Arend van Sprieleb032f02011-12-12 15:15:12 -080093 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),
Arend van Spriel2e7565602011-12-08 15:06:46 -080095 BCMA_CORETABLE_END
96};
97MODULE_DEVICE_TABLE(bcma, brcms_coreid_table);
Arend van Spriel5b435de2011-10-05 13:19:03 +020098
Joe Perches8ae74652012-01-15 00:38:38 -080099#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +0200100static int msglevel = 0xdeadbeef;
101module_param(msglevel, int, 0);
Joe Perches8ae74652012-01-15 00:38:38 -0800102#endif /* DEBUG */
Arend van Spriel5b435de2011-10-05 13:19:03 +0200103
104static 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),
116 CHAN2GHZ(12, 2467,
117 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
118 IEEE80211_CHAN_NO_HT40PLUS),
119 CHAN2GHZ(13, 2472,
120 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
121 IEEE80211_CHAN_NO_HT40PLUS),
122 CHAN2GHZ(14, 2484,
123 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
Seth Forshee7f38e5b2012-08-01 15:58:43 -0500124 IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS |
125 IEEE80211_CHAN_NO_OFDM)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200126};
127
128static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
129 /* UNII-1 */
130 CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
131 CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
132 CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
133 CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
134 /* UNII-2 */
135 CHAN5GHZ(52,
136 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
137 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
138 CHAN5GHZ(56,
139 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
140 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
141 CHAN5GHZ(60,
142 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
143 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
144 CHAN5GHZ(64,
145 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
146 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
147 /* MID */
148 CHAN5GHZ(100,
149 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
150 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
151 CHAN5GHZ(104,
152 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
153 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
154 CHAN5GHZ(108,
155 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
156 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
157 CHAN5GHZ(112,
158 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
159 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
160 CHAN5GHZ(116,
161 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
162 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
163 CHAN5GHZ(120,
164 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
165 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
166 CHAN5GHZ(124,
167 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
168 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
169 CHAN5GHZ(128,
170 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
171 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
172 CHAN5GHZ(132,
173 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
174 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
175 CHAN5GHZ(136,
176 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
177 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
178 CHAN5GHZ(140,
179 IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
180 IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
181 IEEE80211_CHAN_NO_HT40MINUS),
182 /* UNII-3 */
183 CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
184 CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
185 CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
186 CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
187 CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
188};
189
190/*
191 * The rate table is used for both 2.4G and 5G rates. The
192 * latter being a subset as it does not support CCK rates.
193 */
194static struct ieee80211_rate legacy_ratetable[] = {
195 RATE(10, 0),
196 RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
197 RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
198 RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
199 RATE(60, 0),
200 RATE(90, 0),
201 RATE(120, 0),
202 RATE(180, 0),
203 RATE(240, 0),
204 RATE(360, 0),
205 RATE(480, 0),
206 RATE(540, 0),
207};
208
209static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template = {
210 .band = IEEE80211_BAND_2GHZ,
211 .channels = brcms_2ghz_chantable,
212 .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
213 .bitrates = legacy_ratetable,
214 .n_bitrates = ARRAY_SIZE(legacy_ratetable),
215 .ht_cap = {
216 /* from include/linux/ieee80211.h */
217 .cap = IEEE80211_HT_CAP_GRN_FLD |
Arend van Spriel6b1a89a2011-10-18 14:02:59 +0200218 IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200219 .ht_supported = true,
220 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
221 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
222 .mcs = {
223 /* placeholders for now */
224 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
225 .rx_highest = cpu_to_le16(500),
226 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
227 }
228};
229
230static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template = {
231 .band = IEEE80211_BAND_5GHZ,
232 .channels = brcms_5ghz_nphy_chantable,
233 .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
234 .bitrates = legacy_ratetable + BRCMS_LEGACY_5G_RATE_OFFSET,
235 .n_bitrates = ARRAY_SIZE(legacy_ratetable) -
236 BRCMS_LEGACY_5G_RATE_OFFSET,
237 .ht_cap = {
238 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
Arend van Spriel6b1a89a2011-10-18 14:02:59 +0200239 IEEE80211_HT_CAP_SGI_40,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200240 .ht_supported = true,
241 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
242 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
243 .mcs = {
244 /* placeholders for now */
245 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
246 .rx_highest = cpu_to_le16(500),
247 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
248 }
249};
250
251/* flags the given rate in rateset as requested */
252static void brcms_set_basic_rate(struct brcm_rateset *rs, u16 rate, bool is_br)
253{
254 u32 i;
255
256 for (i = 0; i < rs->count; i++) {
257 if (rate != (rs->rates[i] & 0x7f))
258 continue;
259
260 if (is_br)
261 rs->rates[i] |= BRCMS_RATE_FLAG;
262 else
263 rs->rates[i] &= BRCMS_RATE_MASK;
264 return;
265 }
266}
267
268static void brcms_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
269{
270 struct brcms_info *wl = hw->priv;
Thomas Huehn644e8c02012-07-10 14:01:37 +0200271 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200272
273 spin_lock_bh(&wl->lock);
274 if (!wl->pub->up) {
275 wiphy_err(wl->wiphy, "ops->tx called while down\n");
276 kfree_skb(skb);
277 goto done;
278 }
279 brcms_c_sendpkt_mac80211(wl->wlc, skb, hw);
Thomas Huehn644e8c02012-07-10 14:01:37 +0200280 tx_info->rate_driver_data[0] = tx_info->control.sta;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200281 done:
282 spin_unlock_bh(&wl->lock);
283}
284
285static int brcms_ops_start(struct ieee80211_hw *hw)
286{
287 struct brcms_info *wl = hw->priv;
288 bool blocked;
Roland Vossen2646c462011-10-21 16:16:27 +0200289 int err;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200290
291 ieee80211_wake_queues(hw);
292 spin_lock_bh(&wl->lock);
293 blocked = brcms_rfkill_set_hw_state(wl);
294 spin_unlock_bh(&wl->lock);
295 if (!blocked)
296 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
297
Roland Vossen2646c462011-10-21 16:16:27 +0200298 spin_lock_bh(&wl->lock);
Roland Vossendc460122011-10-21 16:16:28 +0200299 /* avoid acknowledging frames before a non-monitor device is added */
300 wl->mute_tx = true;
301
Roland Vossen2646c462011-10-21 16:16:27 +0200302 if (!wl->pub->up)
303 err = brcms_up(wl);
304 else
305 err = -ENODEV;
306 spin_unlock_bh(&wl->lock);
307
308 if (err != 0)
309 wiphy_err(hw->wiphy, "%s: brcms_up() returned %d\n", __func__,
310 err);
311 return err;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200312}
313
314static void brcms_ops_stop(struct ieee80211_hw *hw)
315{
Roland Vossen2646c462011-10-21 16:16:27 +0200316 struct brcms_info *wl = hw->priv;
317 int status;
318
Arend van Spriel5b435de2011-10-05 13:19:03 +0200319 ieee80211_stop_queues(hw);
Roland Vossen2646c462011-10-21 16:16:27 +0200320
321 if (wl->wlc == NULL)
322 return;
323
324 spin_lock_bh(&wl->lock);
Hauke Mehrtenscacaa642012-06-30 15:16:19 +0200325 status = brcms_c_chipmatch(wl->wlc->hw->d11core);
Roland Vossen2646c462011-10-21 16:16:27 +0200326 spin_unlock_bh(&wl->lock);
327 if (!status) {
328 wiphy_err(wl->wiphy,
329 "wl: brcms_ops_stop: chipmatch failed\n");
330 return;
331 }
332
333 /* put driver in down state */
334 spin_lock_bh(&wl->lock);
335 brcms_down(wl);
336 spin_unlock_bh(&wl->lock);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200337}
338
339static int
340brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
341{
Roland Vossendc460122011-10-21 16:16:28 +0200342 struct brcms_info *wl = hw->priv;
343
Arend van Spriel5b435de2011-10-05 13:19:03 +0200344 /* Just STA for now */
Roland Vossen15256622011-10-21 16:16:29 +0200345 if (vif->type != NL80211_IFTYPE_STATION) {
Arend van Spriel5b435de2011-10-05 13:19:03 +0200346 wiphy_err(hw->wiphy, "%s: Attempt to add type %d, only"
347 " STA for now\n", __func__, vif->type);
348 return -EOPNOTSUPP;
349 }
350
Roland Vossendc460122011-10-21 16:16:28 +0200351 wl->mute_tx = false;
352 brcms_c_mute(wl->wlc, false);
353
Roland Vossen2646c462011-10-21 16:16:27 +0200354 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200355}
356
357static void
358brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
359{
Arend van Spriel5b435de2011-10-05 13:19:03 +0200360}
361
362static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
363{
364 struct ieee80211_conf *conf = &hw->conf;
365 struct brcms_info *wl = hw->priv;
366 int err = 0;
367 int new_int;
368 struct wiphy *wiphy = hw->wiphy;
369
370 spin_lock_bh(&wl->lock);
371 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
372 brcms_c_set_beacon_listen_interval(wl->wlc,
373 conf->listen_interval);
374 }
375 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
Alwin Beukersbe667662011-11-22 17:21:43 -0800376 wiphy_dbg(wiphy, "%s: change monitor mode: %s\n",
Arend van Spriel5b435de2011-10-05 13:19:03 +0200377 __func__, conf->flags & IEEE80211_CONF_MONITOR ?
378 "true" : "false");
379 if (changed & IEEE80211_CONF_CHANGE_PS)
380 wiphy_err(wiphy, "%s: change power-save mode: %s (implement)\n",
381 __func__, conf->flags & IEEE80211_CONF_PS ?
382 "true" : "false");
383
384 if (changed & IEEE80211_CONF_CHANGE_POWER) {
385 err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
386 if (err < 0) {
387 wiphy_err(wiphy, "%s: Error setting power_level\n",
388 __func__);
389 goto config_out;
390 }
391 new_int = brcms_c_get_tx_power(wl->wlc);
392 if (new_int != conf->power_level)
393 wiphy_err(wiphy, "%s: Power level req != actual, %d %d"
394 "\n", __func__, conf->power_level,
395 new_int);
396 }
397 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
398 if (conf->channel_type == NL80211_CHAN_HT20 ||
399 conf->channel_type == NL80211_CHAN_NO_HT)
400 err = brcms_c_set_channel(wl->wlc,
401 conf->channel->hw_value);
402 else
403 err = -ENOTSUPP;
404 }
405 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
406 err = brcms_c_set_rate_limit(wl->wlc,
407 conf->short_frame_max_tx_count,
408 conf->long_frame_max_tx_count);
409
410 config_out:
411 spin_unlock_bh(&wl->lock);
412 return err;
413}
414
415static void
416brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
417 struct ieee80211_vif *vif,
418 struct ieee80211_bss_conf *info, u32 changed)
419{
420 struct brcms_info *wl = hw->priv;
421 struct wiphy *wiphy = hw->wiphy;
422
423 if (changed & BSS_CHANGED_ASSOC) {
424 /* association status changed (associated/disassociated)
425 * also implies a change in the AID.
426 */
427 wiphy_err(wiphy, "%s: %s: %sassociated\n", KBUILD_MODNAME,
428 __func__, info->assoc ? "" : "dis");
429 spin_lock_bh(&wl->lock);
430 brcms_c_associate_upd(wl->wlc, info->assoc);
431 spin_unlock_bh(&wl->lock);
432 }
433 if (changed & BSS_CHANGED_ERP_SLOT) {
434 s8 val;
435
436 /* slot timing changed */
437 if (info->use_short_slot)
438 val = 1;
439 else
440 val = 0;
441 spin_lock_bh(&wl->lock);
442 brcms_c_set_shortslot_override(wl->wlc, val);
443 spin_unlock_bh(&wl->lock);
444 }
445
446 if (changed & BSS_CHANGED_HT) {
447 /* 802.11n parameters changed */
448 u16 mode = info->ht_operation_mode;
449
450 spin_lock_bh(&wl->lock);
451 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
452 mode & IEEE80211_HT_OP_MODE_PROTECTION);
453 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
454 mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
455 brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
456 mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
457 spin_unlock_bh(&wl->lock);
458 }
459 if (changed & BSS_CHANGED_BASIC_RATES) {
460 struct ieee80211_supported_band *bi;
461 u32 br_mask, i;
462 u16 rate;
463 struct brcm_rateset rs;
464 int error;
465
466 /* retrieve the current rates */
467 spin_lock_bh(&wl->lock);
468 brcms_c_get_current_rateset(wl->wlc, &rs);
469 spin_unlock_bh(&wl->lock);
470
471 br_mask = info->basic_rates;
472 bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
473 for (i = 0; i < bi->n_bitrates; i++) {
474 /* convert to internal rate value */
475 rate = (bi->bitrates[i].bitrate << 1) / 10;
476
477 /* set/clear basic rate flag */
478 brcms_set_basic_rate(&rs, rate, br_mask & 1);
479 br_mask >>= 1;
480 }
481
482 /* update the rate set */
483 spin_lock_bh(&wl->lock);
484 error = brcms_c_set_rateset(wl->wlc, &rs);
485 spin_unlock_bh(&wl->lock);
486 if (error)
487 wiphy_err(wiphy, "changing basic rates failed: %d\n",
488 error);
489 }
490 if (changed & BSS_CHANGED_BEACON_INT) {
491 /* Beacon interval changed */
492 spin_lock_bh(&wl->lock);
493 brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
494 spin_unlock_bh(&wl->lock);
495 }
496 if (changed & BSS_CHANGED_BSSID) {
497 /* BSSID changed, for whatever reason (IBSS and managed mode) */
498 spin_lock_bh(&wl->lock);
499 brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
500 spin_unlock_bh(&wl->lock);
501 }
502 if (changed & BSS_CHANGED_BEACON)
503 /* Beacon data changed, retrieve new beacon (beaconing modes) */
504 wiphy_err(wiphy, "%s: beacon changed\n", __func__);
505
506 if (changed & BSS_CHANGED_BEACON_ENABLED) {
507 /* Beaconing should be enabled/disabled (beaconing modes) */
508 wiphy_err(wiphy, "%s: Beacon enabled: %s\n", __func__,
509 info->enable_beacon ? "true" : "false");
510 }
511
512 if (changed & BSS_CHANGED_CQM) {
513 /* Connection quality monitor config changed */
514 wiphy_err(wiphy, "%s: cqm change: threshold %d, hys %d "
515 " (implement)\n", __func__, info->cqm_rssi_thold,
516 info->cqm_rssi_hyst);
517 }
518
519 if (changed & BSS_CHANGED_IBSS) {
520 /* IBSS join status changed */
521 wiphy_err(wiphy, "%s: IBSS joined: %s (implement)\n", __func__,
522 info->ibss_joined ? "true" : "false");
523 }
524
525 if (changed & BSS_CHANGED_ARP_FILTER) {
526 /* Hardware ARP filter address list or state changed */
527 wiphy_err(wiphy, "%s: arp filtering: enabled %s, count %d"
528 " (implement)\n", __func__, info->arp_filter_enabled ?
529 "true" : "false", info->arp_addr_cnt);
530 }
531
532 if (changed & BSS_CHANGED_QOS) {
533 /*
534 * QoS for this association was enabled/disabled.
535 * Note that it is only ever disabled for station mode.
536 */
537 wiphy_err(wiphy, "%s: qos enabled: %s (implement)\n", __func__,
538 info->qos ? "true" : "false");
539 }
540 return;
541}
542
543static void
544brcms_ops_configure_filter(struct ieee80211_hw *hw,
545 unsigned int changed_flags,
546 unsigned int *total_flags, u64 multicast)
547{
548 struct brcms_info *wl = hw->priv;
549 struct wiphy *wiphy = hw->wiphy;
550
551 changed_flags &= MAC_FILTERS;
552 *total_flags &= MAC_FILTERS;
Alwin Beukersbe667662011-11-22 17:21:43 -0800553
Arend van Spriel5b435de2011-10-05 13:19:03 +0200554 if (changed_flags & FIF_PROMISC_IN_BSS)
Alwin Beukersbe667662011-11-22 17:21:43 -0800555 wiphy_dbg(wiphy, "FIF_PROMISC_IN_BSS\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200556 if (changed_flags & FIF_ALLMULTI)
Alwin Beukersbe667662011-11-22 17:21:43 -0800557 wiphy_dbg(wiphy, "FIF_ALLMULTI\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200558 if (changed_flags & FIF_FCSFAIL)
Alwin Beukersbe667662011-11-22 17:21:43 -0800559 wiphy_dbg(wiphy, "FIF_FCSFAIL\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200560 if (changed_flags & FIF_CONTROL)
Alwin Beukersbe667662011-11-22 17:21:43 -0800561 wiphy_dbg(wiphy, "FIF_CONTROL\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +0200562 if (changed_flags & FIF_OTHER_BSS)
Alwin Beukersbe667662011-11-22 17:21:43 -0800563 wiphy_dbg(wiphy, "FIF_OTHER_BSS\n");
564 if (changed_flags & FIF_PSPOLL)
565 wiphy_dbg(wiphy, "FIF_PSPOLL\n");
566 if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
567 wiphy_dbg(wiphy, "FIF_BCN_PRBRESP_PROMISC\n");
568
569 spin_lock_bh(&wl->lock);
570 brcms_c_mac_promisc(wl->wlc, *total_flags);
571 spin_unlock_bh(&wl->lock);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200572 return;
573}
574
575static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
576{
577 struct brcms_info *wl = hw->priv;
578 spin_lock_bh(&wl->lock);
579 brcms_c_scan_start(wl->wlc);
580 spin_unlock_bh(&wl->lock);
581 return;
582}
583
584static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
585{
586 struct brcms_info *wl = hw->priv;
587 spin_lock_bh(&wl->lock);
588 brcms_c_scan_stop(wl->wlc);
589 spin_unlock_bh(&wl->lock);
590 return;
591}
592
593static int
594brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
595 const struct ieee80211_tx_queue_params *params)
596{
597 struct brcms_info *wl = hw->priv;
598
599 spin_lock_bh(&wl->lock);
600 brcms_c_wme_setparams(wl->wlc, queue, params, true);
601 spin_unlock_bh(&wl->lock);
602
603 return 0;
604}
605
606static int
607brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
608 struct ieee80211_sta *sta)
609{
610 struct brcms_info *wl = hw->priv;
611 struct scb *scb = &wl->wlc->pri_scb;
612
613 brcms_c_init_scb(scb);
614
615 wl->pub->global_ampdu = &(scb->scb_ampdu);
616 wl->pub->global_ampdu->scb = scb;
617 wl->pub->global_ampdu->max_pdu = 16;
618
Arend van Spriel5b435de2011-10-05 13:19:03 +0200619 /*
620 * minstrel_ht initiates addBA on our behalf by calling
621 * ieee80211_start_tx_ba_session()
622 */
623 return 0;
624}
625
626static int
627brcms_ops_ampdu_action(struct ieee80211_hw *hw,
628 struct ieee80211_vif *vif,
629 enum ieee80211_ampdu_mlme_action action,
630 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
631 u8 buf_size)
632{
633 struct brcms_info *wl = hw->priv;
634 struct scb *scb = &wl->wlc->pri_scb;
635 int status;
636
637 if (WARN_ON(scb->magic != SCB_MAGIC))
638 return -EIDRM;
639 switch (action) {
640 case IEEE80211_AMPDU_RX_START:
641 break;
642 case IEEE80211_AMPDU_RX_STOP:
643 break;
644 case IEEE80211_AMPDU_TX_START:
645 spin_lock_bh(&wl->lock);
646 status = brcms_c_aggregatable(wl->wlc, tid);
647 spin_unlock_bh(&wl->lock);
648 if (!status) {
649 wiphy_err(wl->wiphy, "START: tid %d is not agg\'able\n",
650 tid);
651 return -EINVAL;
652 }
653 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
654 break;
655
656 case IEEE80211_AMPDU_TX_STOP:
657 spin_lock_bh(&wl->lock);
658 brcms_c_ampdu_flush(wl->wlc, sta, tid);
659 spin_unlock_bh(&wl->lock);
660 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
661 break;
662 case IEEE80211_AMPDU_TX_OPERATIONAL:
663 /*
664 * BA window size from ADDBA response ('buf_size') defines how
665 * many outstanding MPDUs are allowed for the BA stream by
666 * recipient and traffic class. 'ampdu_factor' gives maximum
667 * AMPDU size.
668 */
669 spin_lock_bh(&wl->lock);
670 brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
671 (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
672 sta->ht_cap.ampdu_factor)) - 1);
673 spin_unlock_bh(&wl->lock);
674 /* Power save wakeup */
675 break;
676 default:
677 wiphy_err(wl->wiphy, "%s: Invalid command, ignoring\n",
678 __func__);
679 }
680
681 return 0;
682}
683
684static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
685{
686 struct brcms_info *wl = hw->priv;
687 bool blocked;
688
689 spin_lock_bh(&wl->lock);
690 blocked = brcms_c_check_radio_disabled(wl->wlc);
691 spin_unlock_bh(&wl->lock);
692
693 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
694}
695
696static void brcms_ops_flush(struct ieee80211_hw *hw, bool drop)
697{
698 struct brcms_info *wl = hw->priv;
699
700 no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
701
702 /* wait for packet queue and dma fifos to run empty */
703 spin_lock_bh(&wl->lock);
704 brcms_c_wait_for_tx_completion(wl->wlc, drop);
705 spin_unlock_bh(&wl->lock);
706}
707
708static const struct ieee80211_ops brcms_ops = {
709 .tx = brcms_ops_tx,
710 .start = brcms_ops_start,
711 .stop = brcms_ops_stop,
712 .add_interface = brcms_ops_add_interface,
713 .remove_interface = brcms_ops_remove_interface,
714 .config = brcms_ops_config,
715 .bss_info_changed = brcms_ops_bss_info_changed,
716 .configure_filter = brcms_ops_configure_filter,
717 .sw_scan_start = brcms_ops_sw_scan_start,
718 .sw_scan_complete = brcms_ops_sw_scan_complete,
719 .conf_tx = brcms_ops_conf_tx,
720 .sta_add = brcms_ops_sta_add,
721 .ampdu_action = brcms_ops_ampdu_action,
722 .rfkill_poll = brcms_ops_rfkill_poll,
723 .flush = brcms_ops_flush,
724};
725
Arend van Spriel5b435de2011-10-05 13:19:03 +0200726void brcms_dpc(unsigned long data)
727{
728 struct brcms_info *wl;
729
730 wl = (struct brcms_info *) data;
731
732 spin_lock_bh(&wl->lock);
733
734 /* call the common second level interrupt handler */
735 if (wl->pub->up) {
736 if (wl->resched) {
737 unsigned long flags;
738
739 spin_lock_irqsave(&wl->isr_lock, flags);
740 brcms_c_intrsupd(wl->wlc);
741 spin_unlock_irqrestore(&wl->isr_lock, flags);
742 }
743
744 wl->resched = brcms_c_dpc(wl->wlc, true);
745 }
746
747 /* brcms_c_dpc() may bring the driver down */
748 if (!wl->pub->up)
749 goto done;
750
751 /* re-schedule dpc */
752 if (wl->resched)
753 tasklet_schedule(&wl->tasklet);
754 else
755 /* re-enable interrupts */
756 brcms_intrson(wl);
757
758 done:
759 spin_unlock_bh(&wl->lock);
760}
761
762/*
763 * Precondition: Since this function is called in brcms_pci_probe() context,
764 * no locking is required.
765 */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +0200766static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200767{
768 int status;
769 struct device *device = &pdev->dev;
770 char fw_name[100];
771 int i;
772
773 memset(&wl->fw, 0, sizeof(struct brcms_firmware));
774 for (i = 0; i < MAX_FW_IMAGES; i++) {
775 if (brcms_firmwares[i] == NULL)
776 break;
777 sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
778 UCODE_LOADER_API_VER);
779 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
780 if (status) {
781 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
782 KBUILD_MODNAME, fw_name);
783 return status;
784 }
785 sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
786 UCODE_LOADER_API_VER);
787 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
788 if (status) {
789 wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
790 KBUILD_MODNAME, fw_name);
791 return status;
792 }
793 wl->fw.hdr_num_entries[i] =
794 wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
795 }
796 wl->fw.fw_cnt = i;
797 return brcms_ucode_data_init(wl, &wl->ucode);
798}
799
800/*
801 * Precondition: Since this function is called in brcms_pci_probe() context,
802 * no locking is required.
803 */
804static void brcms_release_fw(struct brcms_info *wl)
805{
806 int i;
807 for (i = 0; i < MAX_FW_IMAGES; i++) {
808 release_firmware(wl->fw.fw_bin[i]);
809 release_firmware(wl->fw.fw_hdr[i]);
810 }
811}
812
813/**
814 * This function frees the WL per-device resources.
815 *
816 * This function frees resources owned by the WL device pointed to
817 * by the wl parameter.
818 *
819 * precondition: can both be called locked and unlocked
820 *
821 */
822static void brcms_free(struct brcms_info *wl)
823{
824 struct brcms_timer *t, *next;
825
826 /* free ucode data */
827 if (wl->fw.fw_cnt)
828 brcms_ucode_data_free(&wl->ucode);
829 if (wl->irq)
830 free_irq(wl->irq, wl);
831
832 /* kill dpc */
833 tasklet_kill(&wl->tasklet);
834
835 if (wl->pub)
836 brcms_c_module_unregister(wl->pub, "linux", wl);
837
838 /* free common resources */
839 if (wl->wlc) {
840 brcms_c_detach(wl->wlc);
841 wl->wlc = NULL;
842 wl->pub = NULL;
843 }
844
845 /* virtual interface deletion is deferred so we cannot spinwait */
846
847 /* wait for all pending callbacks to complete */
848 while (atomic_read(&wl->callbacks) > 0)
849 schedule();
850
851 /* free timers */
852 for (t = wl->timers; t; t = next) {
853 next = t->next;
Joe Perches8ae74652012-01-15 00:38:38 -0800854#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +0200855 kfree(t->name);
856#endif
857 kfree(t);
858 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200859}
860
861/*
Roland Vossen2646c462011-10-21 16:16:27 +0200862* called from both kernel as from this kernel module (error flow on attach)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200863* precondition: perimeter lock is not acquired.
864*/
Arend van Spriel2e7565602011-12-08 15:06:46 -0800865static void brcms_remove(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200866{
Arend van Spriel2e7565602011-12-08 15:06:46 -0800867 struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
Roland Vossen2646c462011-10-21 16:16:27 +0200868 struct brcms_info *wl = hw->priv;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200869
Arend van Spriel5b435de2011-10-05 13:19:03 +0200870 if (wl->wlc) {
871 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
872 wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
873 ieee80211_unregister_hw(hw);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200874 }
Arend van Spriel5b435de2011-10-05 13:19:03 +0200875
876 brcms_free(wl);
877
Arend van Spriel2e7565602011-12-08 15:06:46 -0800878 bcma_set_drvdata(pdev, NULL);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200879 ieee80211_free_hw(hw);
880}
881
882static irqreturn_t brcms_isr(int irq, void *dev_id)
883{
884 struct brcms_info *wl;
885 bool ours, wantdpc;
886
887 wl = (struct brcms_info *) dev_id;
888
889 spin_lock(&wl->isr_lock);
890
891 /* call common first level interrupt handler */
892 ours = brcms_c_isr(wl->wlc, &wantdpc);
893 if (ours) {
894 /* if more to do... */
895 if (wantdpc) {
896
897 /* ...and call the second level interrupt handler */
898 /* schedule dpc */
899 tasklet_schedule(&wl->tasklet);
900 }
901 }
902
903 spin_unlock(&wl->isr_lock);
904
905 return IRQ_RETVAL(ours);
906}
907
908/*
909 * is called in brcms_pci_probe() context, therefore no locking required.
910 */
911static int ieee_hw_rate_init(struct ieee80211_hw *hw)
912{
913 struct brcms_info *wl = hw->priv;
914 struct brcms_c_info *wlc = wl->wlc;
915 struct ieee80211_supported_band *band;
916 int has_5g = 0;
917 u16 phy_type;
918
919 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
920 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
921
922 phy_type = brcms_c_get_phy_type(wl->wlc, 0);
923 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
924 band = &wlc->bandstate[BAND_2G_INDEX]->band;
925 *band = brcms_band_2GHz_nphy_template;
926 if (phy_type == PHY_TYPE_LCN) {
927 /* Single stream */
928 band->ht_cap.mcs.rx_mask[1] = 0;
Arend van Sprieldf4492f2011-10-12 20:51:15 +0200929 band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200930 }
931 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
932 } else {
933 return -EPERM;
934 }
935
936 /* Assume all bands use the same phy. True for 11n devices. */
937 if (wl->pub->_nbands > 1) {
938 has_5g++;
939 if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
940 band = &wlc->bandstate[BAND_5G_INDEX]->band;
941 *band = brcms_band_5GHz_nphy_template;
942 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
943 } else {
944 return -EPERM;
945 }
946 }
947 return 0;
948}
949
950/*
951 * is called in brcms_pci_probe() context, therefore no locking required.
952 */
953static int ieee_hw_init(struct ieee80211_hw *hw)
954{
955 hw->flags = IEEE80211_HW_SIGNAL_DBM
956 /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
957 | IEEE80211_HW_REPORTS_TX_ACK_STATUS
958 | IEEE80211_HW_AMPDU_AGGREGATION;
959
960 hw->extra_tx_headroom = brcms_c_get_header_len();
961 hw->queues = N_TX_QUEUES;
962 hw->max_rates = 2; /* Primary rate and 1 fallback rate */
963
964 /* channel change time is dependent on chip and band */
965 hw->channel_change_time = 7 * 1000;
966 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
967
968 hw->rate_control_algorithm = "minstrel_ht";
969
970 hw->sta_data_size = 0;
971 return ieee_hw_rate_init(hw);
972}
973
974/**
975 * attach to the WL device.
976 *
977 * Attach to the WL device identified by vendor and device parameters.
978 * regs is a host accessible memory address pointing to WL device registers.
979 *
980 * brcms_attach is not defined as static because in the case where no bus
981 * is defined, wl_attach will never be called, and thus, gcc will issue
982 * a warning that this function is defined but not used if we declare
983 * it as static.
984 *
985 *
Arend van Spriel2e7565602011-12-08 15:06:46 -0800986 * is called in brcms_bcma_probe() context, therefore no locking required.
Arend van Spriel5b435de2011-10-05 13:19:03 +0200987 */
Arend van Spriel2e7565602011-12-08 15:06:46 -0800988static struct brcms_info *brcms_attach(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +0200989{
990 struct brcms_info *wl = NULL;
991 int unit, err;
992 struct ieee80211_hw *hw;
993 u8 perm[ETH_ALEN];
994
995 unit = n_adapters_found;
996 err = 0;
997
998 if (unit < 0)
999 return NULL;
1000
1001 /* allocate private info */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001002 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001003 if (hw != NULL)
1004 wl = hw->priv;
1005 if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
1006 return NULL;
1007 wl->wiphy = hw->wiphy;
1008
1009 atomic_set(&wl->callbacks, 0);
1010
1011 /* setup the bottom half handler */
1012 tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
1013
Arend van Spriel5b435de2011-10-05 13:19:03 +02001014 spin_lock_init(&wl->lock);
1015 spin_lock_init(&wl->isr_lock);
1016
1017 /* prepare ucode */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001018 if (brcms_request_fw(wl, pdev) < 0) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001019 wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
1020 "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
1021 brcms_release_fw(wl);
Arend van Spriel2e7565602011-12-08 15:06:46 -08001022 brcms_remove(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001023 return NULL;
1024 }
1025
1026 /* common load-time initialization */
Arend van Sprielb63337a2011-12-08 15:06:47 -08001027 wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001028 brcms_release_fw(wl);
1029 if (!wl->wlc) {
1030 wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
1031 KBUILD_MODNAME, err);
1032 goto fail;
1033 }
1034 wl->pub = brcms_c_pub(wl->wlc);
1035
1036 wl->pub->ieee_hw = hw;
1037
Arend van Spriel5b435de2011-10-05 13:19:03 +02001038 /* register our interrupt handler */
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001039 if (request_irq(pdev->irq, brcms_isr,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001040 IRQF_SHARED, KBUILD_MODNAME, wl)) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001041 wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
1042 goto fail;
1043 }
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001044 wl->irq = pdev->irq;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001045
1046 /* register module */
1047 brcms_c_module_register(wl->pub, "linux", wl, NULL);
1048
1049 if (ieee_hw_init(hw)) {
1050 wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
1051 __func__);
1052 goto fail;
1053 }
1054
Seth Forsheecf03c5d2012-06-16 07:47:52 -05001055 brcms_c_regd_init(wl->wlc);
1056
Arend van Spriel5b435de2011-10-05 13:19:03 +02001057 memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
1058 if (WARN_ON(!is_valid_ether_addr(perm)))
1059 goto fail;
1060 SET_IEEE80211_PERM_ADDR(hw, perm);
1061
1062 err = ieee80211_register_hw(hw);
1063 if (err)
1064 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1065 "%d\n", __func__, err);
1066
Arend van Sprield597ee72012-06-09 22:51:41 +02001067 if (wl->pub->srom_ccode[0] &&
1068 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1069 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001070
1071 n_adapters_found++;
1072 return wl;
1073
1074fail:
1075 brcms_free(wl);
1076 return NULL;
1077}
1078
1079
1080
1081/**
1082 * determines if a device is a WL device, and if so, attaches it.
1083 *
1084 * This function determines if a device pointed to by pdev is a WL device,
1085 * and if so, performs a brcms_attach() on it.
1086 *
1087 * Perimeter lock is initialized in the course of this function.
1088 */
Arend van Spriel2e7565602011-12-08 15:06:46 -08001089static int __devinit brcms_bcma_probe(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001090{
Arend van Spriel5b435de2011-10-05 13:19:03 +02001091 struct brcms_info *wl;
1092 struct ieee80211_hw *hw;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001093
Arend van Spriel2e7565602011-12-08 15:06:46 -08001094 dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
1095 pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
Hauke Mehrtens00bcda42012-04-29 02:50:41 +02001096 pdev->irq);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001097
Arend van Spriel2e7565602011-12-08 15:06:46 -08001098 if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
1099 (pdev->id.id != BCMA_CORE_80211))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001100 return -ENODEV;
1101
Arend van Spriel5b435de2011-10-05 13:19:03 +02001102 hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
1103 if (!hw) {
1104 pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
1105 return -ENOMEM;
1106 }
1107
1108 SET_IEEE80211_DEV(hw, &pdev->dev);
1109
Arend van Spriel2e7565602011-12-08 15:06:46 -08001110 bcma_set_drvdata(pdev, hw);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001111
1112 memset(hw->priv, 0, sizeof(*wl));
1113
Arend van Spriel2e7565602011-12-08 15:06:46 -08001114 wl = brcms_attach(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001115 if (!wl) {
Joe Perches02f77192012-01-15 00:38:44 -08001116 pr_err("%s: brcms_attach failed!\n", __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001117 return -ENODEV;
1118 }
1119 return 0;
1120}
1121
Linus Torvalds7d5869e2012-01-13 23:58:41 +01001122static int brcms_suspend(struct bcma_device *pdev)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001123{
1124 struct brcms_info *wl;
1125 struct ieee80211_hw *hw;
1126
Arend van Spriel2e7565602011-12-08 15:06:46 -08001127 hw = bcma_get_drvdata(pdev);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001128 wl = hw->priv;
1129 if (!wl) {
Arend van Spriel137dabe2012-02-09 21:08:59 +01001130 pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
1131 __func__);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001132 return -ENODEV;
1133 }
1134
1135 /* only need to flag hw is down for proper resume */
1136 spin_lock_bh(&wl->lock);
1137 wl->pub->hw_up = false;
1138 spin_unlock_bh(&wl->lock);
1139
Linus Torvalds7e9e7fa2012-01-13 23:58:42 +01001140 pr_debug("brcms_suspend ok\n");
Arend van Spriel5b435de2011-10-05 13:19:03 +02001141
Arend van Spriel2e7565602011-12-08 15:06:46 -08001142 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001143}
1144
Arend van Spriel2e7565602011-12-08 15:06:46 -08001145static int brcms_resume(struct bcma_device *pdev)
1146{
Linus Torvalds7e9e7fa2012-01-13 23:58:42 +01001147 pr_debug("brcms_resume ok\n");
1148 return 0;
Arend van Spriel2e7565602011-12-08 15:06:46 -08001149}
1150
1151static struct bcma_driver brcms_bcma_driver = {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001152 .name = KBUILD_MODNAME,
Arend van Spriel2e7565602011-12-08 15:06:46 -08001153 .probe = brcms_bcma_probe,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001154 .suspend = brcms_suspend,
1155 .resume = brcms_resume,
1156 .remove = __devexit_p(brcms_remove),
Arend van Spriel2e7565602011-12-08 15:06:46 -08001157 .id_table = brcms_coreid_table,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001158};
1159
1160/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001161 * This is the main entry point for the brcmsmac driver.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001162 *
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001163 * This function is scheduled upon module initialization and
1164 * does the driver registration, which result in brcms_bcma_probe()
1165 * call resulting in the driver bringup.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001166 */
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001167static void brcms_driver_init(struct work_struct *work)
1168{
1169 int error;
1170
1171 error = bcma_driver_register(&brcms_bcma_driver);
1172 if (error)
1173 pr_err("%s: register returned %d\n", __func__, error);
1174}
1175
1176static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
1177
Arend van Spriel5b435de2011-10-05 13:19:03 +02001178static int __init brcms_module_init(void)
1179{
Joe Perches8ae74652012-01-15 00:38:38 -08001180#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001181 if (msglevel != 0xdeadbeef)
1182 brcm_msg_level = msglevel;
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001183#endif
1184 if (!schedule_work(&brcms_driver_work))
1185 return -EBUSY;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001186
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001187 return 0;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001188}
1189
1190/**
Arend van Spriel2e7565602011-12-08 15:06:46 -08001191 * This function unloads the brcmsmac driver from the system.
Arend van Spriel5b435de2011-10-05 13:19:03 +02001192 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001193 * This function unconditionally unloads the brcmsmac driver module from the
Arend van Spriel5b435de2011-10-05 13:19:03 +02001194 * system.
1195 *
1196 */
1197static void __exit brcms_module_exit(void)
1198{
Arend van Sprielb0c359b2012-03-02 22:55:50 +01001199 cancel_work_sync(&brcms_driver_work);
Arend van Spriel2e7565602011-12-08 15:06:46 -08001200 bcma_driver_unregister(&brcms_bcma_driver);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001201}
1202
1203module_init(brcms_module_init);
1204module_exit(brcms_module_exit);
1205
1206/*
1207 * precondition: perimeter lock has been acquired
1208 */
1209void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
1210 bool state, int prio)
1211{
1212 wiphy_err(wl->wiphy, "Shouldn't be here %s\n", __func__);
1213}
1214
1215/*
1216 * precondition: perimeter lock has been acquired
1217 */
1218void brcms_init(struct brcms_info *wl)
1219{
1220 BCMMSG(wl->pub->ieee_hw->wiphy, "wl%d\n", wl->pub->unit);
1221 brcms_reset(wl);
Roland Vossendc460122011-10-21 16:16:28 +02001222 brcms_c_init(wl->wlc, wl->mute_tx);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001223}
1224
1225/*
1226 * precondition: perimeter lock has been acquired
1227 */
1228uint brcms_reset(struct brcms_info *wl)
1229{
1230 BCMMSG(wl->pub->ieee_hw->wiphy, "wl%d\n", wl->pub->unit);
1231 brcms_c_reset(wl->wlc);
1232
1233 /* dpc will not be rescheduled */
Rusty Russell3db1cd52011-12-19 13:56:45 +00001234 wl->resched = false;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001235
Vladimir Zapolskiyea2d2182012-08-05 00:29:07 +03001236 /* inform publicly that interface is down */
1237 wl->pub->up = false;
1238
Arend van Spriel5b435de2011-10-05 13:19:03 +02001239 return 0;
1240}
1241
Roland Vossenc261bdf2011-10-18 14:03:04 +02001242void brcms_fatal_error(struct brcms_info *wl)
1243{
1244 wiphy_err(wl->wlc->wiphy, "wl%d: fatal error, reinitializing\n",
1245 wl->wlc->pub->unit);
1246 brcms_reset(wl);
1247 ieee80211_restart_hw(wl->pub->ieee_hw);
1248}
1249
Arend van Spriel5b435de2011-10-05 13:19:03 +02001250/*
1251 * These are interrupt on/off entry points. Disable interrupts
1252 * during interrupt state transition.
1253 */
1254void brcms_intrson(struct brcms_info *wl)
1255{
1256 unsigned long flags;
1257
1258 spin_lock_irqsave(&wl->isr_lock, flags);
1259 brcms_c_intrson(wl->wlc);
1260 spin_unlock_irqrestore(&wl->isr_lock, flags);
1261}
1262
1263u32 brcms_intrsoff(struct brcms_info *wl)
1264{
1265 unsigned long flags;
1266 u32 status;
1267
1268 spin_lock_irqsave(&wl->isr_lock, flags);
1269 status = brcms_c_intrsoff(wl->wlc);
1270 spin_unlock_irqrestore(&wl->isr_lock, flags);
1271 return status;
1272}
1273
1274void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
1275{
1276 unsigned long flags;
1277
1278 spin_lock_irqsave(&wl->isr_lock, flags);
1279 brcms_c_intrsrestore(wl->wlc, macintmask);
1280 spin_unlock_irqrestore(&wl->isr_lock, flags);
1281}
1282
1283/*
1284 * precondition: perimeter lock has been acquired
1285 */
1286int brcms_up(struct brcms_info *wl)
1287{
1288 int error = 0;
1289
1290 if (wl->pub->up)
1291 return 0;
1292
1293 error = brcms_c_up(wl->wlc);
1294
1295 return error;
1296}
1297
1298/*
1299 * precondition: perimeter lock has been acquired
1300 */
1301void brcms_down(struct brcms_info *wl)
1302{
1303 uint callbacks, ret_val = 0;
1304
1305 /* call common down function */
1306 ret_val = brcms_c_down(wl->wlc);
1307 callbacks = atomic_read(&wl->callbacks) - ret_val;
1308
1309 /* wait for down callbacks to complete */
1310 spin_unlock_bh(&wl->lock);
1311
1312 /* For HIGH_only driver, it's important to actually schedule other work,
1313 * not just spin wait since everything runs at schedule level
1314 */
1315 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1316
1317 spin_lock_bh(&wl->lock);
1318}
1319
1320/*
1321* precondition: perimeter lock is not acquired
1322 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001323static void _brcms_timer(struct work_struct *work)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001324{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001325 struct brcms_timer *t = container_of(work, struct brcms_timer,
1326 dly_wrk.work);
1327
Arend van Spriel5b435de2011-10-05 13:19:03 +02001328 spin_lock_bh(&t->wl->lock);
1329
1330 if (t->set) {
1331 if (t->periodic) {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001332 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001333 ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
1334 &t->dly_wrk,
1335 msecs_to_jiffies(t->ms));
1336 } else {
Arend van Spriel5b435de2011-10-05 13:19:03 +02001337 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001338 }
Arend van Spriel5b435de2011-10-05 13:19:03 +02001339
1340 t->fn(t->arg);
1341 }
1342
1343 atomic_dec(&t->wl->callbacks);
1344
1345 spin_unlock_bh(&t->wl->lock);
1346}
1347
1348/*
Arend van Spriel5b435de2011-10-05 13:19:03 +02001349 * Adds a timer to the list. Caller supplies a timer function.
1350 * Is called from wlc.
1351 *
1352 * precondition: perimeter lock has been acquired
1353 */
1354struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
1355 void (*fn) (void *arg),
1356 void *arg, const char *name)
1357{
1358 struct brcms_timer *t;
1359
1360 t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
1361 if (!t)
1362 return NULL;
1363
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001364 INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001365 t->wl = wl;
1366 t->fn = fn;
1367 t->arg = arg;
1368 t->next = wl->timers;
1369 wl->timers = t;
1370
Joe Perches8ae74652012-01-15 00:38:38 -08001371#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001372 t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
1373 if (t->name)
1374 strcpy(t->name, name);
1375#endif
1376
1377 return t;
1378}
1379
1380/*
1381 * adds only the kernel timer since it's going to be more accurate
1382 * as well as it's easier to make it periodic
1383 *
1384 * precondition: perimeter lock has been acquired
1385 */
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001386void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001387{
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001388 struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
1389
Joe Perches8ae74652012-01-15 00:38:38 -08001390#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001391 if (t->set)
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001392 wiphy_err(hw->wiphy, "%s: Already set. Name: %s, per %d\n",
Arend van Spriel5b435de2011-10-05 13:19:03 +02001393 __func__, t->name, periodic);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001394#endif
1395 t->ms = ms;
1396 t->periodic = (bool) periodic;
1397 t->set = true;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001398
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001399 atomic_inc(&t->wl->callbacks);
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001400
1401 ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
Arend van Spriel5b435de2011-10-05 13:19:03 +02001402}
1403
1404/*
1405 * return true if timer successfully deleted, false if still pending
1406 *
1407 * precondition: perimeter lock has been acquired
1408 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001409bool brcms_del_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001410{
1411 if (t->set) {
1412 t->set = false;
Roland Vossen2a7fc5b2011-10-12 20:51:12 +02001413 if (!cancel_delayed_work(&t->dly_wrk))
Arend van Spriel5b435de2011-10-05 13:19:03 +02001414 return false;
1415
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001416 atomic_dec(&t->wl->callbacks);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001417 }
1418
1419 return true;
1420}
1421
1422/*
1423 * precondition: perimeter lock has been acquired
1424 */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001425void brcms_free_timer(struct brcms_timer *t)
Arend van Spriel5b435de2011-10-05 13:19:03 +02001426{
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001427 struct brcms_info *wl = t->wl;
Arend van Spriel5b435de2011-10-05 13:19:03 +02001428 struct brcms_timer *tmp;
1429
1430 /* delete the timer in case it is active */
Roland Vossenbe69c4e2011-10-12 20:51:11 +02001431 brcms_del_timer(t);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001432
1433 if (wl->timers == t) {
1434 wl->timers = wl->timers->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001435#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001436 kfree(t->name);
1437#endif
1438 kfree(t);
1439 return;
1440
1441 }
1442
1443 tmp = wl->timers;
1444 while (tmp) {
1445 if (tmp->next == t) {
1446 tmp->next = t->next;
Joe Perches8ae74652012-01-15 00:38:38 -08001447#ifdef DEBUG
Arend van Spriel5b435de2011-10-05 13:19:03 +02001448 kfree(t->name);
1449#endif
1450 kfree(t);
1451 return;
1452 }
1453 tmp = tmp->next;
1454 }
1455
1456}
1457
1458/*
1459 * precondition: perimeter lock has been acquired
1460 */
1461int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
1462{
1463 int i, entry;
1464 const u8 *pdata;
1465 struct firmware_hdr *hdr;
1466 for (i = 0; i < wl->fw.fw_cnt; i++) {
1467 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1468 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1469 entry++, hdr++) {
1470 u32 len = le32_to_cpu(hdr->len);
1471 if (le32_to_cpu(hdr->idx) == idx) {
1472 pdata = wl->fw.fw_bin[i]->data +
1473 le32_to_cpu(hdr->offset);
Thomas Meyer1f1d52892011-11-17 23:43:40 +01001474 *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
Arend van Spriel5b435de2011-10-05 13:19:03 +02001475 if (*pbuf == NULL)
1476 goto fail;
1477
Arend van Spriel5b435de2011-10-05 13:19:03 +02001478 return 0;
1479 }
1480 }
1481 }
1482 wiphy_err(wl->wiphy, "ERROR: ucode buf tag:%d can not be found!\n",
1483 idx);
1484 *pbuf = NULL;
1485fail:
1486 return -ENODATA;
1487}
1488
1489/*
Arend van Spriel2e7565602011-12-08 15:06:46 -08001490 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001491 * no locking is required.
1492 */
1493int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
1494{
1495 int i, entry;
1496 const u8 *pdata;
1497 struct firmware_hdr *hdr;
1498 for (i = 0; i < wl->fw.fw_cnt; i++) {
1499 hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
1500 for (entry = 0; entry < wl->fw.hdr_num_entries[i];
1501 entry++, hdr++) {
1502 if (le32_to_cpu(hdr->idx) == idx) {
1503 pdata = wl->fw.fw_bin[i]->data +
1504 le32_to_cpu(hdr->offset);
1505 if (le32_to_cpu(hdr->len) != 4) {
1506 wiphy_err(wl->wiphy,
1507 "ERROR: fw hdr len\n");
1508 return -ENOMSG;
1509 }
1510 *n_bytes = le32_to_cpu(*((__le32 *) pdata));
1511 return 0;
1512 }
1513 }
1514 }
1515 wiphy_err(wl->wiphy, "ERROR: ucode tag:%d can not be found!\n", idx);
1516 return -ENOMSG;
1517}
1518
1519/*
1520 * precondition: can both be called locked and unlocked
1521 */
1522void brcms_ucode_free_buf(void *p)
1523{
1524 kfree(p);
1525}
1526
1527/*
1528 * checks validity of all firmware images loaded from user space
1529 *
Arend van Spriel2e7565602011-12-08 15:06:46 -08001530 * Precondition: Since this function is called in brcms_bcma_probe() context,
Arend van Spriel5b435de2011-10-05 13:19:03 +02001531 * no locking is required.
1532 */
1533int brcms_check_firmwares(struct brcms_info *wl)
1534{
1535 int i;
1536 int entry;
1537 int rc = 0;
1538 const struct firmware *fw;
1539 const struct firmware *fw_hdr;
1540 struct firmware_hdr *ucode_hdr;
1541 for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
1542 fw = wl->fw.fw_bin[i];
1543 fw_hdr = wl->fw.fw_hdr[i];
1544 if (fw == NULL && fw_hdr == NULL) {
1545 break;
1546 } else if (fw == NULL || fw_hdr == NULL) {
1547 wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
1548 __func__);
1549 rc = -EBADF;
1550 } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
1551 wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
1552 "size %zu/%zu\n", __func__, fw_hdr->size,
1553 sizeof(struct firmware_hdr));
1554 rc = -EBADF;
1555 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1556 wiphy_err(wl->wiphy, "%s: out of bounds fw file size "
1557 "%zu\n", __func__, fw->size);
1558 rc = -EBADF;
1559 } else {
1560 /* check if ucode section overruns firmware image */
1561 ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
1562 for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
1563 !rc; entry++, ucode_hdr++) {
1564 if (le32_to_cpu(ucode_hdr->offset) +
1565 le32_to_cpu(ucode_hdr->len) >
1566 fw->size) {
1567 wiphy_err(wl->wiphy,
1568 "%s: conflicting bin/hdr\n",
1569 __func__);
1570 rc = -EBADF;
1571 }
1572 }
1573 }
1574 }
1575 if (rc == 0 && wl->fw.fw_cnt != i) {
1576 wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
1577 wl->fw.fw_cnt);
1578 rc = -EBADF;
1579 }
1580 return rc;
1581}
1582
1583/*
1584 * precondition: perimeter lock has been acquired
1585 */
1586bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
1587{
1588 bool blocked = brcms_c_check_radio_disabled(wl->wlc);
1589
1590 spin_unlock_bh(&wl->lock);
1591 wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
1592 if (blocked)
1593 wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
1594 spin_lock_bh(&wl->lock);
1595 return blocked;
1596}
1597
1598/*
1599 * precondition: perimeter lock has been acquired
1600 */
1601void brcms_msleep(struct brcms_info *wl, uint ms)
1602{
1603 spin_unlock_bh(&wl->lock);
1604 msleep(ms);
1605 spin_lock_bh(&wl->lock);
1606}